Skip to content

Commit

Permalink
Filter patient gender observation to latest only (#46)
Browse files Browse the repository at this point in the history
* update gist url

* filter patient latest gender update

* revert gist url changes
  • Loading branch information
mtuchi authored Oct 7, 2024
1 parent 03e69e7 commit 0d4e2cd
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions workflows/wf2/6-create-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,23 @@ each(
);

fn(state => {
state.genderUpdated = state.encounters.reduce((acc, e) => {
const latestGenderUpdate = state.encounters.reduce((acc, e) => {
const answer = e.obs.find(
o => o.concept.uuid === 'ec42d68d-3e23-43de-b8c5-a03bb538e7c7'
);
if (answer) {
acc.push(answer);
const personUuid = answer.person.uuid;
if (
!acc[personUuid] ||
new Date(answer.obsDatetime) > new Date(acc[personUuid].obsDatetime)
) {
acc[personUuid] = answer;
}
}
return acc;
}, []);
}, {});

state.genderUpdated = Object.values(latestGenderUpdate);

return state;
});
Expand Down

0 comments on commit 0d4e2cd

Please sign in to comment.