Issue creating a tracked entity instance with a generated UID via API

Hello everyone,

I have been trying to create a tracked entity via the API with a generated UID. The problem is that the tracked entity instance is created but with a UID that I did not provide. I am not sure if this is a bug or there is a change I am not aware of. I am wiery of upgrading to any new version as this is an important feature in our implementation.

I have tried this on almost all the instances on play.dhis2.org but seem to be getting the same issue.

The sample endpoint is:

https://play.dhis2.org/2.37dev/api/trackedEntityInstances

Sample payload:

{
			"trackedEntityType": "nEenWmSyUEp",
			"orgUnit": "DiszpKrYNg8",
			"trackedEntityInstance": "5tk563ewXQC",
			"attributes": [
				{
					"attribute": "cejWyOfXge6",
					"value": "Female"
				},
				{
					"attribute": "w75KJ2mc4zz",
					"value": "Andrea"
				},
				{
					"attribute": "zDhUuAYrxNC",
					"value": "Burton"
				}
			],
			"enrollments": [
				{
					"orgUnit": "DiszpKrYNg8",
					"trackedEntityType": "nEenWmSyUEp",
					"trackedEntityInstance":"5tk563ewXQC",
					"program": "IpHINAT79UW",
					"enrollmentDate": "2023-12-29T12:05:00.000",
					"incidentDate": "2023-12-29T12:05:00.000"
				}
			]
		}

Any help will be appreciated.

Cheers,

5 Likes

Hi @vincentminde,
Welcome to the community and thanks for your first post! (:

Please see the docs here: Identifier schemes - Metadata | Using the API - DHIS2 Documentation
It mentions that the default UID is automatically generated unless overridden by any of the other idSchemes. In your case you’ll be using trackedEntityIdScheme=CODE (CODE is an example change it with any of the other scheme you find suitable for your case)

I hope this helps! Good luck with your app! (:

Hello @Gassim ,

I am surprised by the quick response. Thanks for that.
I have tried what you suggested unfortunately it is still not responding with the UID that I have generated. Keep in mind that I need the UID that I generated to be the one that is used on the tracked entity instance that I POSTed

Here is the URL that I changed to accommodate the idScheme:

https://play.dhis2.org/2.37.2/api/trackedEntityInstances?trackedEntityIdScheme=UID

Here is the sample payload(I tried playing around with the identifier fields i.e trackedEntityInstance,id,uid)

{
			"trackedEntityType": "nEenWmSyUEp",
			"orgUnit": "DiszpKrYNg8",
			"trackedEntityInstance": "5tk563ewXQC",
			"uid": "5tk563ewXQC",
			"id": "5tk563ewXQC",
			"attributes": [
				{
					"attribute": "cejWyOfXge6",
					"value": "Female"
				},
				{
					"attribute": "w75KJ2mc4zz",
					"value": "Andrea"
				},
				{
					"attribute": "zDhUuAYrxNC",
					"value": "Burton"
				}
			],
			"enrollments": [
				{
					"orgUnit": "DiszpKrYNg8",
					"trackedEntityType": "nEenWmSyUEp",
					"trackedEntityInstance":"5tk563ewXQC",
					"program": "IpHINAT79UW",
					"enrollmentDate": "2023-12-29T12:05:00.000",
					"incidentDate": "2023-12-29T12:05:00.000"
				}
			]
		}

Cheers,

Hi @vincentminde,
Thanks!

The UID is generated by the system so that’s why you have the other idShemes like CODE. Maybe use the ‘id’ or generate a CODE?

@vincentminde, maybe if you please explain more what the algorithm is?

  1. You are creating TEI
  2. The System generates a UID – because you can’t generate your own UID (you can override it as mentioned above)
  3. You are trying to update the TEI

Hello @Gassim ,

Just for context. There are applications in production right now that generate the UID in the client side and when saved the System does not generate the UID but instead uses the client generated UID.

To the question of my algorithm:

I am trying to create TEI offline and save them on a database(Offline). The TEI that is offline also has enrollments and events associated with it. With this in mind, I want to sync all of the data to the server, and given these associations, I have to create the UID at the client-side. So you see I have no other choice but to create the UID on the client-side.

Not to mention there are already implementations where this was working but to my surprise that does not seem to be the case now. Something tells me it is a bug but I need to be sure it is not an implementation change on the part of the DHIS2 Software itself.

3 Likes

Hello Vincent,

There must be an issue with the generated UID from offline.

The UID should not start with a number. Try for UIDs not starting with number and provide feedback.

Cheers!

4 Likes

Hello @josephatjulius,

Just tested that and it seems to be perfect. I don’t know how I missed that.

Thanks very much

1 Like