Skip to content

Commit

Permalink
check if trackedEntity is found for a person
Browse files Browse the repository at this point in the history
  • Loading branch information
mtuchi committed Nov 12, 2024
1 parent 3dad166 commit 132bb7e
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions workflows/wf2/7-update-teis.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,32 @@ fn(state => {
return acc;
}, {});

state.teisToUpdate = genderUpdated.map(answer => {
const { trackedEntity } = TEIs[answer.person.uuid];
return {
trackedEntity,
program: state.program,
orgUnit: state.orgUnit,
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,
},
],
};
});
state.teisToUpdate = genderUpdated
.map(answer => {
const { trackedEntity } = TEIs[answer.person.uuid] || {};
if (!trackedEntity) {
console.log('No TEI found for person', answer.person.uuid);
}
if (trackedEntity) {
return {
trackedEntity,
program: state.program,
orgUnit: state.orgUnit,
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,
},
],
};
}
})
.filter(Boolean);
return state;
});

Expand Down

0 comments on commit 132bb7e

Please sign in to comment.