Skip to content

Commit

Permalink
fix encounters mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
mtuchi committed Nov 8, 2024
1 parent 5e0cf7f commit d348f15
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions workflows/wf2/6-create-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,31 @@ const dataValuesMapping = (data, dataValueMap, optsMap) => {

// Prepare DHIS2 data model for create events
fn(state => {
state.encountersMapping = state.encounters.map(data => {
const form = state.formMaps[data.form.uuid];
const eventDate = data.encounterDatetime.replace('+0000', '');
const { trackedEntity, enrollment } = state.TEIs[data.patient.uuid];

const event = {
program: state.program,
orgUnit: state.orgUnit,
trackedEntityInstance: trackedEntity,
enrollment,
eventDate,
};
if (form) {
return {
...event,
programStage: form.programStage,
dataValues: dataValuesMapping(data, form.dataValueMap, state.optsMap),
state.encountersMapping = state.encounters
.map(data => {
const form = state.formMaps[data.form.uuid];
const occurredAt = data.encounterDatetime.replace('+0000', '');
const { trackedEntity, enrollment } = state.TEIs[data.patient.uuid] || {};

const event = {
program: state.program,
orgUnit: state.orgUnit,
trackedEntity,
enrollment,
occurredAt,
};
}
});
if (!form.dataValueMap) {
console.log(data.patient);
}
if (form && form.dataValueMap) {
return {
...event,
programStage: form.programStage,
dataValues: dataValuesMapping(data, form.dataValueMap, state.optsMap),
};
}
})
.filter(e => e);

return state;
});
Expand All @@ -103,16 +108,7 @@ fn(state => {
create(
'tracker',
{
events: state => {
const events = state.encountersMapping.map(
({ eventDate, trackedEntityInstance, ...e }) => ({
...e,
occurredAt: eventDate,
trackedEntity: trackedEntityInstance,
})
);
return events;
},
events: $.encountersMapping,
},
{
params: {
Expand Down

0 comments on commit d348f15

Please sign in to comment.