Event import

Happy New Year!. I am trying various methods for importing simple/single events in 2.37.2, but run into issues with all of them:

  1. In the Import/Export module, there is an option for Event import, which says:
    “Import events for programs, stages and tracked entities using the DXF 2 format.” Where is the description of the DXF 2 format (could be good to include a link on that page)

When I try the following JSON, I am told I need an event date, which I thought is now replaced by occurredAt?

{
    "programStage": "r4XQEm9hvn6",
    "orgUnit": "ao5Ou7NSXhR",
    "occurredAt": "2022-01-01T00:00:00.000",
    "dataValues": [
        {
            "dataElement": "d7UrMiDmRVR",
            "value": "16"
        },
        {
            "dataElement": "zbQEgLc29M2",
            "value": "17"
        }
    ]
}
  1. If I rather try to use the command line with the same payload, nothing much seems to happen, but I also don’t see any error messages:
curl -d @event_test.json "localhost:8080/dhis/api/tracker?async=TRUE" -H "Content-Type:application/json" -u admin:district
{"httpStatus":"OK","httpStatusCode":200,"status":"OK","message":"Tracker job added","response":{"responseType":"TrackerJob","id":"BnDN0yooWBU","location":"http://localhost:8080/dhis/api/tracker/jobs/BnDN0yooWBU"}}
  1. curl does work with the old /api/events endpoint, but when I try to use CODE as idScheme, it starts complaining about my dataElements not being assigned to the programStage. (BTW, is there a way to access the programStage for a single event program through the GUI? I had to find the UID and set the CODE for the programStage directly in the database).
curl -d @event_test.json "localhost:8080/dhis/api/events?idScheme=CODE" -H "Content-Type:application/json" -u admin:district

Hey @Knut_Staring ,

  1. You can find the format here. Note that this is the old format that is accepted by /events endpoint. The new tracker endpoint requires a slightly different payload, which you can find here.

The import/export app still uses the old tracker endpoints, so eventDate would be the correct property name.

  1. You don’t see any error messages because you use async=true. If you change the async to false, you will get the report immediately. If you wish to use asynchronous import, you will have to follow the location URL from the response. Appending /report to the end will return you the import summaries.

  2. Do you send the CODE of your data elements in the payload instead of uids? If not, you could also use dataElementIdScheme query param and set it to UID.

Gintare

2 Likes

Thanks a lot, @Gintare. I have finally made it work with the new /tracker endpoint, i.e. this command:

curl -d @event_test1.json "localhost:8080/dhis/api/tracker?idScheme=CODE&dataElementIdScheme=UID&categoryOptionComboIdScheme=CODE&async=false" -H "Content-Type:application/json" -u admin:district

with this minimal payload in the event_test1.json file:

{
    "events": [
        {
            "program":"LEARNING",
            "orgUnit": "52_3",
            "occurredAt": "2019-08-01T00:00:00.000",
            "attributeOptionCombo": "gTrrZZzTBgx",
            "dataValues": [
                {
                    "dataElement": "zbQEgLc29M2",
                    "value": "44"
                }
            ]
        }
    ]
}

I understand the Import/Export app in 2.37 still uses the older /events endpoint. We should probably replace the mention of “DXF 2” with the link you provided to the old tracker format (and change it to the other link as the app gets updated).

There are now two remaining problems:

  1. It does not seem to work to use CODE for DataElements (using UID is not great for interop).
  2. More seriously, it completely ignores attempts at using CODE for attributeOptionCombo by adding &categoryOptionComboIdScheme=CODE

I have begun a JIRA issue for these two here.

1 Like