DHIS2 export json cannot be imported

Hi @diana
I finally uninstall the muso config and reinstall the CHT-core. I did the config and now I can download the file. But I found another problem, the json schema of the file does not allow us to do the import in DHIS2.
Current scheme in the cht :

{
    "dataSet": "tRVpRURUVJD",
    "completeDate": "2021-12-14",
    "period": "202112",
    "dataValues": [
        {
            "dataElement": "kB0ZBFisE0e",
            "categoryOptionCombo": "HllvX50cXC0",
            "attributeOptionCombo": "HllvX50cXC0",
            "orgUnit": "DiszpKrYNg8",
            "value": 0
        },
        {
            "dataElement": "ZKhnpUL0Z2f",
            "categoryOptionCombo": "HllvX50cXC0",
            "attributeOptionCombo": "HllvX50cXC0",
            "orgUnit": "DiszpKrYNg8",
            "value": 0
        },
        {
            "dataElement": "Bj5lBm6iU0r",
            "categoryOptionCombo": "HllvX50cXC0",
            "attributeOptionCombo": "HllvX50cXC0",
            "orgUnit": "DiszpKrYNg8",
            "value": 0
        }
    ]
}

Current scheme that we should have:

{
    "dataValues": [
        {
            "dataElement": "kB0ZBFisE0e",
            "period": "202112",
            "orgUnit": "DiszpKrYNg8",
            "categoryOptionCombo": "HllvX50cXC0",
            "attributeOptionCombo": "HllvX50cXC0",
            "value": 0
        },
        {
            "dataElement": "ZKhnpUL0Z2f",
            "period": "202112",
            "orgUnit": "DiszpKrYNg8",
            "categoryOptionCombo": "HllvX50cXC0",
            "attributeOptionCombo": "HllvX50cXC0",
            "value": 0
        },
        {
            "dataElement": "Bj5lBm6iU0r",
            "period": "202112",
            "orgUnit": "DiszpKrYNg8",
            "categoryOptionCombo": "HllvX50cXC0",
            "attributeOptionCombo": "HllvX50cXC0",
            "value": 0
        }
    ]
}

NB: 1. The order of the metadata is important
2. We can put the name of the dataset only in the name of the file to export
Thanks for your support.

Hi @Justinho

Are you getting an error when trying to import? What does it say?
Where are you getting the sample correct scheme from?

Hi @diana
I have been working a lot on DHIS2, and I have done some import tests on a DHIS2 instance.
attached is an example of the error this makes.


By the way, if you want to export the data of all the organizational units, the schema I provided is more suitable. The correct schema was made by me.
Here is another example that works if only one org-unit is selected.

{
    "dataSet": "tRVpRURUVJD",
    "completeDate": "2021-12-14",
    "period": "202111",
	"orgUnit": "DiszpKrYNg8",
    "dataValues": [
        {
            "dataElement": "Bj5lBm6iU0r",
            "categoryOptionCombo": "HllvX50cXC0",
            "attributeOptionCombo": "HllvX50cXC0",
            "value": 2
        },
        {
            "dataElement": "ZKhnpUL0Z2f",
            "categoryOptionCombo": "HllvX50cXC0",
            "attributeOptionCombo": "HllvX50cXC0",
            "value": 10
        }
    ]
}

So, the exported JSONs, either when an org unit is selected or not, can never be imported into DHIS2?

Yes, with the current schema, we can never imported into DHIS2.
I share with you a documentation about sending data values in DHIS2.

Thanks for the link and references @Justinho .
As far as I’m aware, no changes were made to the dhis export schema since it was added 2 years ago, so I’m wondering if this is a compatibility issue where DHIS2 changed the approved schema.

Looking at the original issue: Format data for sending to DHIS2 · Issue #6002 · medic/cht-core · GitHub the schema described there is the one that we should implement.

{
  "dataSet": "pBOMPrpg1QX",
  "completeDate": "2019-10-03",
  "period": "201909",
  "orgUnit": "DiszpKrYNg8",
  "dataValues": [
    { "dataElement": "f7n9E0hX8qk", "value": 21 },
    { "dataElement": "Ix2HsbDMLea", "value": 17 },
    { "dataElement": "eY5ehpbEsB7", "value": 14 }
  ]
}

@diana
Unfortunately, this is not the format I got in the exported file.

Ok, from what I can tell (but haven’t gotten to testing yet), the schema that dhis2 supports:

  1. When exporting for a single orgUnit, both orgUnit and period should be outside dataValues elements
  2. When exporting for multiple orgUnits, both orgUnit and period need to be part of each dataValues element

In contrast we always export the period outside the dataValues elements, but we export the orgUnit in the dataValues elements.

I’m going to try to check this today, but it would be helpful to get confirmation from you as well @Justinho (I don’t have a dhis2 instance ready for testing).
As soon as I have confirmation, I’ll open an issue in cht-core so we fix this asap.

Thanks a lot!

1 Like

@diana
I confirm the two points (1 and 2) you mentioned.
I’m available for testing if you manage to correct the problem.
And thanks again for your support.

I’ve been experimenting a bit with the dhis2 play server and I noticed that removing the completeDate property fixes the conflict and import succeeds.

Could you please also check if, once you export from cht-core, remove completeDate and try to import into dhis2, import works?

Thanks!

Created an issue to track this.
Thanks for reporting!

Yes, it works, I didn’t think of that.
Thanks a lot @diana

I think the conflict also doesn’t stop data from actually being imported …
I just tried an import and entries were actually imported, even with the conflict.