API shows enrollment; Tracker Capture shows no enrollments

The Tracker API documentation says that I can create an enrollment by using a PUT request to update a tracked entity instance:

It is also possible to create (and update) a tracked entity instance,
at the same time enroll into a program and create an event.

Here is the request I am sending to update an existing tracked entity instance:

PUT https://play.dhis2.org/2.33.1/api/trackedEntityInstances/txD6XDiVG2p
{
  "attributes": [
    {
      "attribute": "w75KJ2mc4zz",
      "code": "MMD_PER_NAM",
      "created": "2020-02-11T23:10:54.776",
      "displayName": "First name",
      "lastUpdated": "2020-02-11T23:10:54.776",
      "storedBy": "admin",
      "value": "Alice",
      "valueType": "TEXT"
    },
    {
      "attribute": "zDhUuAYrxNC",
      "created": "2020-02-11T23:10:54.777",
      "displayName": "Last name",
      "lastUpdated": "2020-02-11T23:10:54.777",
      "storedBy": "admin",
      "value": "Apple",
      "valueType": "TEXT"
    },
    {
      "attribute": "lZGmxYbs97q",
      "code": "MMD_PER_ID",
      "created": "2020-02-11T23:10:54.778",
      "displayName": "Unique ID",
      "lastUpdated": "2020-02-11T23:10:54.778",
      "storedBy": "admin",
      "value": "2635263",
      "valueType": "NUMBER"
    },
    {
      "attribute": "iESIqZ0R0R0",
      "value": "1990-02-12"
    }
  ],
  "created": "2020-02-11T23:10:54.774",
  "createdAtClient": "2020-02-11T23:10:54.774",
  "deleted": false,
  "enrollments": [
    {
      "enrollmentDate": "2020-01-12T00:00:00.000",
      "events": [
        {
          "dataValues": [
            {
              "dataElement": "OuJ6sgPyAbC",
              "value": "ANC1: LMP: Jan 12, 2020"
            }
          ],
          "eventDate": "2020-01-12",
          "orgUnit": "g8upMTyEZGZ",
          "program": "uy2gU8kT1jF",
          "programStage": "eaDHS084uMp",
          "status": "ACTIVE"
        }
      ],
      "incidentDate": "2020-01-12T00:00:00.000",
      "program": "uy2gU8kT1jF"
    }
  ],
  "featureType": "NONE",
  "inactive": false,
  "lastUpdated": "2020-02-11T23:10:54.774",
  "lastUpdatedAtClient": "2020-02-11T23:10:54.774",
  "orgUnit": "g8upMTyEZGZ",
  "programOwners": [],
  "relationships": [],
  "trackedEntityInstance": "txD6XDiVG2p",
  "trackedEntityType": "nEenWmSyUEp"
}

I have not been able to set the date of birth for the tracked entity instance (topic posted here), so I edited the program (“RMNCH/PNC”), and set date of birth as not a mandatory attribute.

After that I can create an enrollment using the API. Here is an API response showing the enrollment with an event:

GET https://play.dhis2.org/2.33.1/api/trackedEntityInstances/txD6XDiVG2p?fields=*
{
  "attributes": [
    {
      "attribute": "w75KJ2mc4zz",
      "code": "MMD_PER_NAM",
      "created": "2020-02-11T23:10:54.776",
      "displayName": "First name",
      "lastUpdated": "2020-02-11T23:10:54.776",
      "storedBy": "admin",
      "value": "Alice",
      "valueType": "TEXT"
    },
    {
      "attribute": "zDhUuAYrxNC",
      "created": "2020-02-11T23:10:54.777",
      "displayName": "Last name",
      "lastUpdated": "2020-02-11T23:10:54.777",
      "storedBy": "admin",
      "value": "Apple",
      "valueType": "TEXT"
    },
    {
      "attribute": "lZGmxYbs97q",
      "code": "MMD_PER_ID",
      "created": "2020-02-11T23:10:54.778",
      "displayName": "Unique ID",
      "lastUpdated": "2020-02-11T23:10:54.778",
      "storedBy": "admin",
      "value": "2635263",
      "valueType": "NUMBER"
    }
  ],
  "created": "2020-02-11T23:10:54.774",
  "createdAtClient": "2020-02-11T23:10:54.774",
  "deleted": false,
  "enrollments": [
    {
      "attributes": [],
      "created": "2020-02-11T23:32:10.479",
      "createdAtClient": "2020-02-11T23:32:10.485",
      "deleted": false,
      "enrollment": "iQfSAZAf6Eu",
      "enrollmentDate": "2020-01-12T00:00:00.000",
      "events": [
        {
          "attributeCategoryOptions": "xYerKDKCefk",
          "attributeOptionCombo": "HllvX50cXC0",
          "created": "2020-02-11T23:32:10.666",
          "createdAtClient": "2020-02-11T23:32:10.666",
          "dataValues": [
            {
              "created": "2020-02-11T23:32:10.688",
              "dataElement": "OuJ6sgPyAbC",
              "lastUpdated": "2020-02-11T23:32:10.688",
              "providedElsewhere": false,
              "storedBy": "admin",
              "value": "ANC1: LMP: Jan 12, 2020"
            }
          ],
          "deleted": false,
          "dueDate": "2020-02-11T23:32:10.636",
          "enrollment": "iQfSAZAf6Eu",
          "enrollmentStatus": "ACTIVE",
          "event": "mVHTWLdSJAi",
          "eventDate": "2020-01-12T00:00:00.000",
          "lastUpdated": "2020-02-11T23:32:10.689",
          "lastUpdatedAtClient": "2020-02-11T23:32:10.689",
          "notes": [],
          "orgUnit": "g8upMTyEZGZ",
          "orgUnitName": "Njandama MCHP",
          "program": "uy2gU8kT1jF",
          "programStage": "eaDHS084uMp",
          "relationships": [],
          "status": "ACTIVE",
          "storedBy": "admin",
          "trackedEntityInstance": "txD6XDiVG2p"
        }
      ],
      "incidentDate": "2020-01-12T00:00:00.000",
      "lastUpdated": "2020-02-11T23:32:10.485",
      "lastUpdatedAtClient": "2020-02-11T23:32:10.485",
      "notes": [],
      "program": "uy2gU8kT1jF",
      "relationships": [],
      "status": "ACTIVE",
      "storedBy": "admin",
      "trackedEntityInstance": "txD6XDiVG2p",
      "trackedEntityType": "nEenWmSyUEp"
    }
  ],
  "featureType": "NONE",
  "inactive": false,
  "lastUpdated": "2020-02-11T23:32:10.689",
  "lastUpdatedAtClient": "2020-02-11T23:10:54.774",
  "orgUnit": "g8upMTyEZGZ",
  "programOwners": [],
  "relationships": [],
  "trackedEntityInstance": "txD6XDiVG2p",
  "trackedEntityType": "nEenWmSyUEp"
}

BUT when I open the tracked entity instance in Tracker Capture, and select the MNCH/PNC program, it appears that they are NOT enrolled:

It gets a little weirder. If I then select a program they are not enrolled in, it says, actually, they are enrolled in the MNCH/PNC program:

How can I use a PUT request to update the entity, as the Tracker API documentation suggests, in such a way that Tracker Capture will show the enrollment when the program is selected?

2 Likes

Hi @nhooper,

Thanks for being an active member in DHIS2 community! :slight_smile:

Generally, adding enrolment through /trackedEntityInstances endpoint should work and it seems you are doing it correctly. However, I think your payload is missing an org unit in enrolment object; could you please try adding it?

Gintare

1 Like

@Gintare! You are spot on! Thank you so much. Enrollments created with the API are now appearing in Tracker Capture as normal.

2 Likes