Last active
January 17, 2023 02:27
-
-
Save haftamuk/67abbe8f91ee8ef143a72615a2c9fb0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This job fetches patients record from an EMR and transforms records to DHIS2 TrackedEntityInstances and writes the output in to output.json. | |
Run the job with the following command | |
openfn .\getEMRPatientData.js -a http --no-strict-output | |
Look in to the output.json (scroll down till you see userByUserId as a key). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Extract data from an EMR API | |
get('https://jsonplaceholder.typicode.com/users'); | |
// Initialize a mapping variable | |
// Iterate over the extracted EMR data and map data to new data elements | |
// User by userId | |
fn(state => { | |
const users = state.data; | |
// Collect user by userId | |
// r is an accumulator, a is a currentValue | |
const patientsRecord = []; | |
const mappedPatientsData = users.reduce((r, a) => { | |
//Initialize TrackedEntiryRecord and map attributes | |
const trackedEntity = {}; | |
// Set static ID values of DHIS2 trackedEntityInstances(Puting such information in state.json would be good practice!) | |
trackedEntity["orgUnit"] = "g8upMTyEZGZ"; | |
trackedEntity["trackedEntityType"] = "nEenWmSyUEp"; | |
// This is the dynamic part of the trackedEntityInstances record | |
trackedEntity["attributes"] = []; | |
// Initialize array entries for each Tracked entity attributes(Static attribute ID and dynamic value extracted from patient data) | |
// This is were we do the attribute mapping | |
// In this demonstration only Name and Email are used | |
var trackedEntityGenderAttributeValue = | |
{ attribute: "cejWyOfXge6", value: "Male" }; | |
var trackedEntityUniqueIdAttributeValue = | |
{ attribute: "lZGmxYbs97q", value: a.phone }; | |
var trackedEntityFisrtNameAttributeValue = | |
{ attribute: "w75KJ2mc4zz", value: a.name }; | |
var trackedEntityLastNameAttributeValue = | |
{ attribute: "zDhUuAYrxNC", value: a.name }; | |
trackedEntity["attributes"].push(trackedEntityGenderAttributeValue); | |
trackedEntity["attributes"].push(trackedEntityUniqueIdAttributeValue); | |
trackedEntity["attributes"].push(trackedEntityFisrtNameAttributeValue); | |
trackedEntity["attributes"].push(trackedEntityLastNameAttributeValue); | |
patientsRecord.push(trackedEntity); | |
return patientsRecord; | |
}, {}); | |
return { ...state, mappedPatientsData }; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This job recieves output.json from previous job as an input | |
// data elements mapping and transformation tookplace in the previous job. | |
// In order to run this job makesure DHIS2 credentials are set properly | |
each("mappedPatientsData[*]", state => { | |
// state.data will contain values of each iteration | |
create('trackedEntityInstances', state.data); | |
return state; | |
}); |
Kindly adjust access of the shared excel document!
Mapping spec
@haftamuk here is the mappingSpec
, I also adjusted the access restriction See the mapping spec
Kindly adjust access of the shared excel document!
Mapping spec
@haftamuk here is the
mappingSpec
, I also adjusted the access restriction See the mapping spec
Thanks I have updated the mapping information of the first job.
I have also added the second job(tiny code!)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kindly adjust access of the shared excel document!