Program Enrollment via Web API

Hey all
I am trying to copy data from a third party app to DHIS2 using Tracker Data Capture. But I am confused regarding the flow.
I have a Program, say Family Registration. This program has a child program, set via Relations, Members Registered. Family Registration uses Family Entity Type and Members Registered use Family Member Entity Type.
Now I can create a new registration using UI, but I have more than 10K rows for these forms/programs doing them via UI is not possible. Also that app has new data every few days so my bridge (between App and DHIS) will run every other day.

This is what I understand regading the flow for new enrollment.

I am to make a new enrollment so I understand I’ll make a POST request to /api/enrollments,
but what will be my parameters?
What I understand is I might need to generate a POST request to /api/trackedEntityInstances using attributes from GET request to /api/trackedEntityTypes and use UID from these two in enrollment, but again what will be my parameters.

After filling Family Registration I have to add a Relation (Family Member Program). I’ll most probably will be doing same as above and then create a relation? ( I am asking, as I am lost with this part).

If someone can help me understand this it would be great or if someone can guide me to the right material that would be great too.

Thanks & Regards

1 Like

Hi Salik,
This is an interesting use case and I can tell you the essentials for tracker data import in bulk could certainly be documented in more detail…

A few questions…

  1. Which version of DHIS2 are you using? This may affect what API endpoints are available for your import strategy.
  2. Are the enrollments repeatable* for a single TEI, i.e. would you need to check if an enrollment already exists for a given TEI before importing?

In general the following should be set up first…

  • org units
  • tracked entity type
  • tracked entity attributes
  • program
  • programStages
  • relationShip type

Then your application imports…

  • tracked entity instance (with attributes)
  • enrollment, using the tei uid above
  • events, using the tei and enrollment uids

In v2.29 and above, it is possible to create a tei and enroll it into a program, in a single request with one JSON payload. See here:

*IF enrollment is repeatable you may want to first search for the TEI using GET request to the api/trackedEntityInstances endpoint, e.g. to queyr based on name:
https://play.dhis2.org/2.32.2/api/29/trackedEntityInstances.json?ou=DiszpKrYNg8&filter=dv3nChNSIxy:eq:Scott

I am not sure if you can import without the TEI value, but if you need a UID, you can fetch a new UID from GET api/system/id. https://play.dhis2.org/2.32.2/api/system/id

So in your application, you can also fetch the UIDs for the org unit, program, tracked entity type, tracked entity attribute, and your new TEI to construct the payload for each POST request.

When you have the TEI IDs for the family TEI and “child” members TEI, you can import relationships to the relationships resource, from v2.32 (and maybe as early as v2.30, but its not documented) .Home - DHIS2 Documentation

I hope this is enough info to get you started. Good luck!

Brian

3 Likes

Thanks. I am going to look more into your solution and try it out.

2 Likes

Hi Salik,

I am battling with the same problem, Did you eventually win? Would you mind sharing the approach you eventually used?

Regards,

Macdonald