forked from OpenFn/openfn-lime
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add update trackedEntities step (#44)
* update gist url * add gender updated mappings and update TEIs to address #38 * update lastRunDateTime * add update-teis step * commented out G0hLyxqgcO7 * add log when creating an event * update optionsMap gist link latest optionSets --------- Co-authored-by: Aleksa Krolls <[email protected]>
- Loading branch information
1 parent
2cbe86a
commit 10a6f83
Showing
5 changed files
with
95 additions
and
14 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,6 +182,13 @@ workflows: | |
credential: [email protected] | ||
body: | ||
path: workflows/wf2/6-create-events.js | ||
|
||
Update-TEIs: | ||
name: Update TEIs | ||
adaptor: '@openfn/[email protected]' | ||
credential: [email protected] | ||
body: | ||
path: workflows/wf2/7-update-teis.js | ||
|
||
Mappings: | ||
name: Mappings | ||
|
@@ -227,6 +234,13 @@ workflows: | |
condition_label: has-teis | ||
condition_expression: state.TEIs && !state.errors | ||
enabled: true | ||
Create-Events->Update-TEIs: | ||
source_job: Create-Events | ||
target_job: Update-TEIs | ||
condition_type: js_expression | ||
condition_label: has-gender-updated | ||
condition_expression: state.genderUpdated.length > 0 && !state.errors | ||
enabled: true | ||
Mappings->Upsert-TEIs: | ||
source_job: Mappings | ||
target_job: Upsert-TEIs | ||
|
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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
fn(state => { | ||
const { optsMap, genderUpdated, TEIs } = state; | ||
const genderMap = optsMap | ||
.filter(o => o['DHIS2 DE UID'] === 'qptKDiv9uPl') | ||
.reduce((acc, obj) => { | ||
acc[obj['value.display - Answers']] = obj['DHIS2 Option Code']; | ||
return acc; | ||
}, {}); | ||
|
||
state.teisToUpdate = genderUpdated.map(answer => { | ||
const { trackedEntity } = TEIs[answer.person.uuid]; | ||
return { | ||
trackedEntity, | ||
program: 'w9MSPn5oSqp', | ||
orgUnit: 'OPjuJMZFLop', | ||
trackedEntityType: 'cHlzCA2MuEF', | ||
attributes: [ | ||
{ | ||
attribute: 'qptKDiv9uPl', //gender | ||
value: genderMap[answer.value.display], | ||
}, | ||
{ | ||
attribute: 'AYbfTPYMNJH', //OpenMRS Patient UID to use to upsert TEI | ||
value: answer.person.uuid, | ||
}, | ||
], | ||
}; | ||
}); | ||
return state; | ||
}); | ||
|
||
// Update TEIs | ||
create( | ||
'tracker', | ||
{ trackedEntities: $.teisToUpdate }, | ||
{ params: { async: false, importStrategy: 'UPDATE' } } | ||
); | ||
// Return only lastRunDateTime | ||
fn(({ lastRunDateTime }) => ({ lastRunDateTime })); |
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