Skip to content

Commit

Permalink
Add mhpssFollowup form (#23)
Browse files Browse the repository at this point in the history
* mappings, edge conditions for MHPSS Followup form

* code formatting and cleanup

* add formsMap and improve mapping
  • Loading branch information
mtuchi authored Sep 19, 2024
1 parent 243c68f commit 38597a5
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 153 deletions.
42 changes: 20 additions & 22 deletions workflows/wf2/1-get-patients.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// here we define the date cursor
fn(state => {
//manualCursor at beggining of the project 2023-05-20T06:01:24.000+0000
const manualCursor = '2023-07-27T07:16:24.544Z';

state.cursor = state.lastRunDateTime || manualCursor;

console.log(
'Date cursor to filter & get only recent OMRS records ::',
state.cursor
);
const clear = (state, keys) => {
if (keys?.length > 0) {
keys.forEach(key => {
delete state[key];
});
}

return state;
};
//Here we define the date cursor
//$.cursor at beggining of the project 2023-05-20T06:01:24.000+0000
cursor($.lastRunDateTime || $.manualCursor || '2023-05-20T06:01:24.000+0000');
// Update the lastRunDateTime for the next run
cursor('today', {
key: 'lastRunDateTime',
format: c => dateFns.format(new Date(c), "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"),
});

searchPatient({ q: 'Katrina', v: 'full', limit: '100' });
Expand All @@ -26,14 +29,12 @@ fn(state => {
//console.log('dateCreated for patient uuid ...2c6dbfc5acc8',getPatientByUuid("31b4d9c8-f7cc-4c26-ae61-2c6dbfc5acc8"))
//console.log(JSON.stringify(state.data, null, 2));

console.log('Filtering patients to only sync most recent records...');
console.log('Filtering patients since:', state.cursor);

state.patients = results.filter(
patient =>
(patient.auditInfo.dateChanged === null
? patient.auditInfo.dateCreated
: patient.auditInfo.dateChanged) > state.cursor
);
state.patients = results.filter(({ auditInfo }) => {
const lastModified = auditInfo?.dateChanged || auditInfo?.dateCreated;
return lastModified > state.cursor;
});
console.log('# of patients to sync to dhis2 ::', state.patients.length);
console.log(
'uuids of patients to sync to dhis2 ::',
Expand All @@ -43,8 +44,5 @@ fn(state => {
state.lastRunDateTime = new Date().toISOString();
console.log('Updating cursor; next sync start date:', state.lastRunDateTime);

state.data = {};
state.response = {};
state.references = [];
return state;
return clear(state, ['data', 'response', 'references']);
});
70 changes: 30 additions & 40 deletions workflows/wf2/2-upsert-teis.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,6 @@ fn(state => {
return matchingIdentifier ? matchingIdentifier.identifier : undefined;
}

const calculateDOB = age => {
const currentDate = new Date();
const currentYear = currentDate.getFullYear();
const birthYear = currentYear - age;

const birthday = new Date(
birthYear,
currentDate.getMonth(),
currentDate.getDay()
);

return birthday.toISOString().replace(/\.\d+Z$/, '+0000');
};

const enrollments = [
{
orgUnit: 'OPjuJMZFLop',
Expand Down Expand Up @@ -98,31 +84,33 @@ fn(state => {
a =>
a.attributeType.uuid ===
'24d1fa23-9778-4a8e-9f7b-93f694fc25e2'
)?.value.uuid
)?.value?.uuid
], //input.attributeType = "24d1fa23-9778-4a8e-9f7b-93f694fc25e2"
},
{
attribute: 'YUIQIA2ClN6', //current status
value:
statusMap[
patient.person.attributes.find(
a =>
a.attributeType.uuid ===
'e0b6ed99-72c4-4847-a442-e9929eac4a0f'
)?.value.uuid
], //input.attributeType = "e0b6ed99-72c4-4847-a442-e9929eac4a0f"
},
{
attribute: 'Qq6xQ2s6LO8', //legal status
value:
statusMap[
patient.person.attributes.find(
a =>
a.attributeType.uuid ===
'a9b2c642-097f-43f8-b96b-4d2f50ffd9b1'
)?.value.uuid
], //input.attributeType = "a9b2c642-097f-43f8-b96b-4d2f50ffd9b1"
},
// TODO: YUIQIA2ClN6 has an error, Aleksa to ask the client,
// {
// attribute: 'YUIQIA2ClN6', //current status
// value:
// statusMap[
// patient.person.attributes.find(
// a =>
// a.attributeType.uuid ===
// 'e0b6ed99-72c4-4847-a442-e9929eac4a0f'
// )?.value?.uuid
// ], //input.attributeType = "e0b6ed99-72c4-4847-a442-e9929eac4a0f"
// },
// TODO: Qq6xQ2s6LO8 has an error, Aleksa to ask the client
// {
// attribute: 'Qq6xQ2s6LO8', //legal status
// value:
// statusMap[
// patient.person.attributes.find(
// a =>
// a.attributeType.uuid ===
// 'a9b2c642-097f-43f8-b96b-4d2f50ffd9b1'
// )?.value?.uuid
// ], //input.attributeType = "a9b2c642-097f-43f8-b96b-4d2f50ffd9b1"
// },
{
attribute: 'FpuGAOu6itZ', //marital status
value:
Expand All @@ -131,7 +119,7 @@ fn(state => {
a =>
a.attributeType.uuid ===
'3884dc76-c271-4bcb-8df8-81c6fb897f53'
)?.value.uuid
)?.value?.uuid
], //input.attributeType = "3884dc76-c271-4bcb-8df8-81c6fb897f53"
},
{
Expand All @@ -142,7 +130,7 @@ fn(state => {
a =>
a.attributeType.uuid ===
'dd1f7f0f-ccea-4228-9aa8-a8c3b0ea4c3e'
)?.value.uuid
)?.value?.uuid
], //input.attributeType = "dd1f7f0f-ccea-4228-9aa8-a8c3b0ea4c3e"
},
{
Expand All @@ -165,12 +153,14 @@ fn(state => {

return patientsUpsert.push(payload);
};
// const patients = state.patients.slice(0, 1);

return {
...state,
genderOptions,
patientsUpsert,
buildPatientsUpsert,
references: [],
};
});

Expand Down Expand Up @@ -206,7 +196,7 @@ each(
'tracker/trackedEntities',
{
orgUnit: 'OPjuJMZFLop',
filter: [`AYbfTPYMNJH:Eq:${$.data.uuid}`],
filter: [`AYbfTPYMNJH:Eq:${$.data?.uuid}`],
program: 'w9MSPn5oSqp',
},
{},
Expand Down
1 change: 1 addition & 0 deletions workflows/wf2/3-get-encounters.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ fn(state => {
state.formUuids = [
'82db23a1-4eb1-3f3c-bb65-b7ebfe95b19b',
'6a3e1e0e-dd13-3465-b8f5-ee2d42691fe5',
'be8c12f9-e6fd-369a-9bc7-46a191866f15',
];

console.log('cursor datetime::', state.cursor);
Expand Down
42 changes: 42 additions & 0 deletions workflows/wf2/4-get-options-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,49 @@ fn(state => {
state.mhgapMap = {
f6FhkzfZ5j3: '4dae5b12-070f-4153-b1ca-fbec906106e1', //Admission type
R3g94vJ2yFR: '22809b19-54ca-4d88-8d26-9577637c184e', //Clinical diagnosis
Yt4NhxZU5Vo: '819f79e7-b9af-4afd-85d4-2ab677223113', //Clinical diagnosis - If other, specify
pHoZYTrR7N0: '2be92591-da1b-4418-ba49-43b3fc0e4ce5', //Pregnant / breastfeeding
hMcCdEkhhjZ: 'f6cefc80-506a-44b0-ab5f-d6f5908cf7a5', //Child / adolescent
VnXwFYqHNqM: '15748787-7372-4022-b5d4-81ff8d6887ca', //Older adult
xRuC0NQRqZk: '99a8b512-17f9-4a5d-9fd4-80c27500995b', //Patient already on psychotropic / psychiatric medication (not prescribed by MSF)?
DCEJHFQvPWa: '5f3d618e-5c89-43bd-8c79-07e4e98c2f23', //PHQ-9 score
CcA8pc2YqWz: 'd9454e9c-6e3c-45ab-8a9a-834a9353ae11', //Session number
TZGKlSVIsN8: '5f6e245c-83fc-421b-8d46-061ac773ae71', //Follow-up required
};

state.mhpssFollowup = {
CcA8pc2YqWz: 'd9454e9c-6e3c-45ab-8a9a-834a9353ae11', //Session number
d8Dok4D8Fl4: '1a8bf24f-4f36-4971-aad9-ae77f3525738', //Type of consultation
E7MVMTTdvPi: 'b87a93ff-a4a1-4601-b35d-1e42bfa7e194', //Total number of beneficiaries in family consultation
aCTIvKSNndK: '722dd83a-c1cf-48ad-ac99-45ac131ccc96', //Consultation done by
UlSJrSD78HS: '82978311-bef9-46f9-9a9a-cc62254b00a6', //Location of intervention
sGEOde9q9p9: '0a0c70d2-2ba5-4cb3-941f-b4a9a4a7ec6d', //Location of intervention - If Health Facility, specify
LCdm2xe86ln: '41e68dee-a2a3-4e6c-9d96-53def5caff52', //Location of intervention - If MSF Health Facility, specify
rGS6S4jyKu3: '08cd4b4a-4b0b-4391-987b-b5b3d770d30f', //Location of intervention - If Mobile Clinic, specify
L6Jj7Tppr5q: 'e08d532b-e56c-43dc-b831-af705654d2dc', //Location of intervention - If other, specify
vWWl7izQpqd: '82978311-bef9-46f9-9a9a-cc62254b00a6', //Type of intervention
G0hLyxqgcO7: '54e8c1b6-6397-4822-89a4-cf81fbc68ce9', //The patient did not come
tloy0Bd9qDf: 'd7410cd3-29be-4f8b-93d6-eb4de005db29', //Number of appointments missed
AZUFlZzPN6V: '278d3d1e-c02a-4db1-8ab3-8db3b82eb9b5', //Patient rescheduled
HNZHetAtowR: 'd34d5e93-03d6-494e-8f4c-2d7221227162', //Reason for missed appointment
t4HoHWCYdvm: '790b41ce-e1e7-11e8-b02f-0242ac130002', //Reason for missed appointment - If other, specify
MF3RML0HLbP: 'b2c5b6e0-66f0-4b9d-8576-b6f48e0a06df', //MHOS score
tsFOVnlc6lz: '5f3d618e-5c89-43bd-8c79-07e4e98c2f23', //PHQ-9 score
C5XtlggtVmd: 'a1a75011-0fef-460a-b666-dda2d171f39b', //CGI-S score
yTFUtaFJ1QU: 'f94de17e-9771-4711-aabb-c5bb0c022be2', //CGI-I score
F6q03Gan7Ro: '22809b19-54ca-4d88-8d26-9577637c184e', //Clinical diagnosis
OeA71vAyGZV: '819f79e7-b9af-4afd-85d4-2ab677223113', //Clinical diagnosis - If other, specify
OZViJk8FPVd: 'c2664992-8a5a-4a6d-9238-5df591307d55', //Has the patient had thoughts of death or suicide?
piKsOVnFIXO: 'a6c5188c-29f0-4d3d-8cf5-7852998df86f', //Has the patient attempted suicide or tried to kill themselves?
llBTRwwM94C: 'abede172-ba87-4ebe-8054-3afadb181ea3', //Is the patient currently at risk of hurting himself/herself or attempting suicide?
j8IYwKvxK4q: 'ccc4f06c-b76a-440d-9b7e-c48ba2c4a0ab', //Is the patient currently at risk of hurting others?
Lw2Kkl2y6mj: 'd516de07-979b-411c-b7e4-bd09cf7d9d91', //Does the patient regularly use alcohol / substances to become intoxicated?
a9J7luvOwhF: '3e97c2d0-15c1-4cfd-884f-7a4721079217', //Has the patient experienced an act of aggression or violence?
EM4ouSS9Kxe: 'd8c84af2-bd9b-4bf3-a815-81652cb0b0bc', //Patient experienced an act of aggression or violence - What type(s) of violence?
KjOAmUFJJgs: 'aae000c3-5242-4e3c-bd1f-7e922a6d3d34', //Patient experienced an act of aggression or violence - Time between violence event and consultation
GVTXoz0VrAd: '5f6e245c-83fc-421b-8d46-061ac773ae71', //Follow up session required?
N6GYmCjAhfh: '6d3876be-0a27-466d-ad58-92edcc8c31fb', //Referral done
wvVn2LfmNDO: '8fb3bb7d-c935-4b57-8444-1b953470e109', //Type of referral
};
return state;
});
Loading

0 comments on commit 38597a5

Please sign in to comment.