Skip to content

Instantly share code, notes, and snippets.

@mtuchi
Last active January 30, 2023 11:08
Show Gist options
  • Save mtuchi/a03657bcf42cc7b1296a05083be1ec0a to your computer and use it in GitHub Desktop.
Save mtuchi/a03657bcf42cc7b1296a05083be1ec0a to your computer and use it in GitHub Desktop.
Job writing Training Homework

Challenge

Your organization is collecting patient data in a custom EMR application.

Your government partner wants you to start sending newly registered patient records from your EMR to its national DHIS2 system on a weekly basis.

You’ve been asked to design a workflow to:

  • extract data from your app (which has a REST API that returns data in JSON)
  • map the data elements to the DHIS2 data model, and
  • sync patient records as “Tracked Entity Instance” records to DHIS2

Request

Job 1: Get users from this endpoint https://jsonplaceholder.typicode.com/users

Job 2: For each user, create 1 tracked entity instance in DHIS2.

See mapping spec here and sample output linked below

State

Job 1: Sample Users Data http adaptor

Job 2: I use the following to access via the web UI. Not sure that URL is required for the API. (Note this is DHIS2 v2.39.0.1) https://play.dhis2.org/2.39.0.1/ (UN: admin, PW: district

See the latest DHIS2 Adaptor docs here: https://docs.openfn.org/adaptors/packages/dhis2-docs

Output

I think this is what the final DHIS2 payload needs to look like: DHIS2 Sample Payload

FYI - To create tracked entity instance, using the lates version of language-dhis2

create("trackedEntityInstances", {
  orgUnit: "TSyzvBiovKh",
  trackedEntityType: "nEenWmSyUEp",
  attributes: [
    {
      attribute: "w75KJ2mc4zz",
      value: "Gigiwe",
    },
  ],
});

see here

@mtuchi
Copy link
Author

mtuchi commented Jan 5, 2023

Mapping spec

Destination Attribute
(label)
Destination Attribute
(ID)
Source Value
(column name)
Transformation Comments Output Data Type Output Sample Input Data Type Input Sample Suggested Mapping Sample Code Snippet Expose in OpenFn run logs? Personally Identifiable Information?
First Name w75KJ2mc4zz name Split at ' ' and take the 1st string string Aleksa string Aleksa Krolls Yes Yes
Gender cejWyOfXge6 'Male' see mapping table in gender tab This is required in DHIS2, but not in the sample data... so let's hard code this. string Male not in sample data not in sample data Yes No
Last Name zDhUuAYrxNC name Split at ' ' and take the 2nd string string Krolls string Aleksa Krolls Yes Yes
Unique ID lZGmxYbs97q phone Take substring of the last 7 digits on the phone number Must be integer number 1234447 phone 1-463-123-4447 Yes No
orgUnit orgUnit 'g8upMTyEZGZ' Hardcode value:
g8upMTyEZGZ
This is the ID for the health facility "Njandama MCHP" registed in the DHIS2 play instance string g8upMTyEZGZ string g8upMTyEZGZ Yes No
trackedEntityInstance
trackedEntityInstance.attributes[*]
trackedEntityType trackedEntityType 'nEenWmSyUEp' Hardcode value: nEenWmSyUEp DHIS2 system-generated ID string nEenWmSyUEp string nEenWmSyUEp Yes No

@mtuchi
Copy link
Author

mtuchi commented Jan 6, 2023

Simple workflow diagram we want to write job code for, and later link the job expression files to the OpenFn platform job configuration.

Simple workflow diagram we want to write job code for, and later link the job expression files to the OpenFn platform job configuration.

@mtuchi
Copy link
Author

mtuchi commented Jan 11, 2023

@mtuchi
Copy link
Author

mtuchi commented Jan 13, 2023

Day 2 Challenge

After syncing patient records as “Tracked Entity Instance” records to DHIS2, we realized that there are too many records being sync at once hence causing the DHIS to have performance issues.

You been asked to modified Job 2 -> sync patient records as “Tracked Entity Instance” records to DHIS2 to only sync 5 patients records at a time

@haftamuk
Copy link

https://gist.github.com/mtuchi/a03657bcf42cc7b1296a05083be1ec0a?permalink_comment_id=4425254#gistcomment-4425254

In order to actually test the second job, can you provide me the correct API URL of DHIS2. I can't seem to get that URL!

@mtuchi
Copy link
Author

mtuchi commented Jan 17, 2023

In order to actually test the second job, can you provide me the correct API URL of DHIS2. I can't seem to get that URL!

@haftamuk here is how to setup the credentials for the DHIS2, as mentioned in the State section of the challenge

"configuration": {
   "hostUrl": "https://play.dhis2.org/2.39.0.1",
   "username": "admin",
   "password": "district"
 },

If you want to learn more about the configuration schema for DHIS2 here is the link https://docs.openfn.org/adaptors/packages/dhis2-readme#sample-state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment