forked from OpenFn/openfn-lime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes accepted by Lightning; updated current project state
- Loading branch information
1 parent
f1f8541
commit 507ce01
Showing
1 changed file
with
7 additions
and
7 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 |
---|---|---|
|
@@ -3,11 +3,8 @@ | |
"name": "msf-lime-iraq", | ||
"description": null, | ||
"inserted_at": "2024-09-05T06:59:05Z", | ||
"updated_at": "2024-10-01T11:42:17Z", | ||
"updated_at": "2024-10-01T11:55:25Z", | ||
"scheduled_deletion": null, | ||
"history_retention_period": null, | ||
"dataclip_retention_period": null, | ||
"retention_policy": "retain_all", | ||
"project_credentials": { | ||
"[email protected]": { | ||
"id": "3141d874-5456-4168-9680-ce04efb1089c", | ||
|
@@ -25,6 +22,9 @@ | |
"owner": "[email protected]" | ||
} | ||
}, | ||
"history_retention_period": null, | ||
"dataclip_retention_period": null, | ||
"retention_policy": "retain_all", | ||
"workflows": { | ||
"wf2-omrs-dhis2": { | ||
"id": "0f8ec062-1a2d-4f13-a8c5-b8298004512c", | ||
|
@@ -91,7 +91,7 @@ | |
}, | ||
"concurrency": null, | ||
"inserted_at": "2024-09-06T11:58:48Z", | ||
"updated_at": "2024-10-01T11:42:17Z", | ||
"updated_at": "2024-10-01T11:55:25Z", | ||
"jobs": { | ||
"Get-Patients": { | ||
"id": "ab326112-9cdd-4449-8611-b5abc659d4ca", | ||
|
@@ -103,7 +103,7 @@ | |
"Upsert-TEIs": { | ||
"id": "6973c510-b36d-4c42-82f5-b26d8cd36a57", | ||
"name": "Upsert TEIs", | ||
"body": "const buildPatientsUpsert = (state, patient, isNewPatient) => {\n const { nationalityMap, statusMap, placeOflivingMap, genderOptions } = state;\n const DHIS2_PATIENT_NUMBER = '8d79403a-c2cc-11de-8d13-0010c6dffd0f'; //DHIS2 ID or DHIS2 Patient Number\n const OPENMRS_AUTO_ID = '05a29f94-c0ed-11e2-94be-8c13b969e334'; //MSF ID or OpenMRS Patient Number\n const dateCreated = patient.auditInfo.dateCreated.substring(0, 10);\n const findIdentifierByUuid = (identifiers, targetUuid) =>\n identifiers.find(i => i.identifierType.uuid === targetUuid)?.identifier;\n\n const enrollments = [\n {\n orgUnit: 'OPjuJMZFLop',\n program: 'w9MSPn5oSqp',\n programStage: 'MdTtRixaC1B',\n enrollmentDate: dateCreated,\n },\n ];\n\n const payload = {\n query: {\n ou: 'OPjuJMZFLop',\n program: 'w9MSPn5oSqp',\n filter: [`AYbfTPYMNJH:Eq:${patient.uuid}`], //upsert on omrs.patient.uid\n },\n data: {\n program: 'w9MSPn5oSqp',\n orgUnit: 'OPjuJMZFLop',\n trackedEntityType: 'cHlzCA2MuEF',\n attributes: [\n {\n attribute: 'fa7uwpCKIwa',\n value: patient.person?.names[0]?.givenName,\n },\n {\n attribute: 'Jt9BhFZkvP2',\n value: patient.person?.names[0]?.familyName,\n },\n {\n attribute: 'P4wdYGkldeG', //DHIS2 ID ==> \"Patient Number\"\n value:\n findIdentifierByUuid(patient.identifiers, DHIS2_PATIENT_NUMBER) ||\n findIdentifierByUuid(patient.identifiers, OPENMRS_AUTO_ID), //map OMRS ID if no DHIS2 id\n },\n {\n attribute: 'ZBoxuExmxcZ', //MSF ID ==> \"OpenMRS Patient Number\"\n value: findIdentifierByUuid(patient.identifiers, OPENMRS_AUTO_ID),\n },\n {\n attribute: 'AYbfTPYMNJH', //\"OpenMRS Patient UID\"\n value: patient.uuid,\n },\n {\n attribute: 'qptKDiv9uPl',\n value: genderOptions[patient.person.gender],\n },\n {\n attribute: 'Rv8WM2mTuS5',\n value: patient.person.age,\n },\n {\n attribute: 'WDp4nVor9Z7',\n value: patient.person.birthdate.slice(0, 10),\n },\n {\n attribute: 'rBtrjV1Mqkz', //Place of living\n value: placeOflivingMap[patient.person?.addresses[0]?.cityVillage],\n },\n {\n attribute: 'Xvzc9e0JJmp', //nationality\n value:\n nationalityMap[\n patient.person.attributes.find(\n a =>\n a.attributeType.uuid ===\n '24d1fa23-9778-4a8e-9f7b-93f694fc25e2'\n )?.value?.uuid\n ], //input.attributeType = \"24d1fa23-9778-4a8e-9f7b-93f694fc25e2\"\n },\n {\n attribute: 'YUIQIA2ClN6', //current status\n value:\n statusMap[\n patient.person.attributes.find(\n a =>\n a.attributeType.uuid ===\n 'e0b6ed99-72c4-4847-a442-e9929eac4a0f'\n )?.value?.uuid\n ], //input.attributeType = \"e0b6ed99-72c4-4847-a442-e9929eac4a0f\"\n },\n // TODO: Qq6xQ2s6LO8 has an error, Aleksa to ask the client\n {\n attribute: 'Qq6xQ2s6LO8', //legal status\n value:\n statusMap[\n patient.person.attributes.find(\n a =>\n a.attributeType.uuid ===\n 'a9b2c642-097f-43f8-b96b-4d2f50ffd9b1'\n )?.value?.uuid\n ], //input.attributeType = \"a9b2c642-097f-43f8-b96b-4d2f50ffd9b1\"\n },\n {\n attribute: 'FpuGAOu6itZ', //marital status\n value:\n statusMap[\n patient.person.attributes.find(\n a =>\n a.attributeType.uuid ===\n '3884dc76-c271-4bcb-8df8-81c6fb897f53'\n )?.value?.uuid\n ], //input.attributeType = \"3884dc76-c271-4bcb-8df8-81c6fb897f53\"\n },\n {\n attribute: 'v7k4OcXrWR8', //employment status\n value:\n statusMap[\n patient.person.attributes.find(\n a =>\n a.attributeType.uuid ===\n 'dd1f7f0f-ccea-4228-9aa8-a8c3b0ea4c3e'\n )?.value?.uuid\n ], //input.attributeType = \"dd1f7f0f-ccea-4228-9aa8-a8c3b0ea4c3e\"\n },\n {\n attribute: 'SVoT2cVLd5O', //Number of children\n value: patient.person.attributes.find(\n a => a.attributeType.uuid === 'e363161a-9d5c-4331-8463-238938f018ed'\n )?.value, //input.attributeType = \"e363161a-9d5c-4331-8463-238938f018ed\"\n },\n ],\n },\n };\n\n console.log('mapped dhis2 payloads:: ', JSON.stringify(payload, null, 2));\n\n if (isNewPatient) {\n console.log('create enrollment');\n payload.data.enrollments = enrollments;\n }\n\n return payload;\n};\n\nconst delay = ms => new Promise(resolve => setTimeout(resolve, ms));\n\n// Upsert TEIs to DHIS2\neach(\n '$.patients[*]',\n get(\n 'tracker/trackedEntities',\n {\n orgUnit: 'OPjuJMZFLop',\n filter: [`AYbfTPYMNJH:Eq:${$.data?.uuid}`],\n program: 'w9MSPn5oSqp',\n },\n {},\n async state => {\n const patient = state.references.at(-1);\n console.log(patient.uuid, 'patient uuid');\n\n const isNewPatient = state.data.instances.length === 0;\n\n state.patientsUpsert ??= [];\n state.patientsUpsert.push(\n buildPatientsUpsert(state, patient, isNewPatient)\n );\n await delay(2000);\n return state;\n }\n )\n);\n\n// Upsert TEIs to DHIS2\neach(\n 'patientsToUpsert[*]',\n upsert('trackedEntityInstances', $.data.query, $.data.data)\n);\nfn(state => {\n const {\n data,\n response,\n references,\n patients,\n statusMap,\n patientsUpsert,\n nationalityMap,\n placeOflivingMap,\n genderOptions,\n ...next\n } = state;\n\n next.patientUuids = patients.map(p => p.uuid);\n return next;\n});\n", | ||
"body": "const buildPatientsUpsert = (state, patient, isNewPatient) => {\n const { nationalityMap, statusMap, placeOflivingMap, genderOptions } = state;\n const DHIS2_PATIENT_NUMBER = '8d79403a-c2cc-11de-8d13-0010c6dffd0f'; //DHIS2 ID or DHIS2 Patient Number\n const OPENMRS_AUTO_ID = '05a29f94-c0ed-11e2-94be-8c13b969e334'; //MSF ID or OpenMRS Patient Number\n const dateCreated = patient.auditInfo.dateCreated.substring(0, 10);\n const findIdentifierByUuid = (identifiers, targetUuid) =>\n identifiers.find(i => i.identifierType.uuid === targetUuid)?.identifier;\n\n const enrollments = [\n {\n orgUnit: 'OPjuJMZFLop',\n program: 'w9MSPn5oSqp',\n programStage: 'MdTtRixaC1B',\n enrollmentDate: dateCreated,\n },\n ];\n\n const payload = {\n query: {\n ou: 'OPjuJMZFLop',\n program: 'w9MSPn5oSqp',\n filter: [`AYbfTPYMNJH:Eq:${patient.uuid}`], //upsert on omrs.patient.uid\n },\n data: {\n program: 'w9MSPn5oSqp',\n orgUnit: 'OPjuJMZFLop',\n trackedEntityType: 'cHlzCA2MuEF',\n attributes: [\n {\n attribute: 'fa7uwpCKIwa',\n value: patient.person?.names[0]?.givenName,\n },\n {\n attribute: 'Jt9BhFZkvP2',\n value: patient.person?.names[0]?.familyName,\n },\n {\n attribute: 'P4wdYGkldeG', //DHIS2 ID ==> \"Patient Number\"\n value:\n findIdentifierByUuid(patient.identifiers, DHIS2_PATIENT_NUMBER) ||\n findIdentifierByUuid(patient.identifiers, OPENMRS_AUTO_ID), //map OMRS ID if no DHIS2 id\n },\n {\n attribute: 'ZBoxuExmxcZ', //MSF ID ==> \"OpenMRS Patient Number\"\n value: findIdentifierByUuid(patient.identifiers, OPENMRS_AUTO_ID),\n },\n {\n attribute: 'AYbfTPYMNJH', //\"OpenMRS Patient UID\"\n value: patient.uuid,\n },\n {\n attribute: 'qptKDiv9uPl',\n value: genderOptions[patient.person.gender],\n },\n {\n attribute: 'Rv8WM2mTuS5',\n value: patient.person.age,\n },\n {\n attribute: 'WDp4nVor9Z7',\n value: patient.person.birthdate.slice(0, 10),\n },\n {\n attribute: 'rBtrjV1Mqkz', //Place of living\n value: placeOflivingMap[patient.person?.addresses[0]?.cityVillage],\n },\n {\n attribute: 'Xvzc9e0JJmp', //nationality\n value:\n nationalityMap[\n patient.person.attributes.find(\n a =>\n a.attributeType.uuid ===\n '24d1fa23-9778-4a8e-9f7b-93f694fc25e2'\n )?.value?.uuid\n ], //input.attributeType = \"24d1fa23-9778-4a8e-9f7b-93f694fc25e2\"\n },\n {\n attribute: 'YUIQIA2ClN6', //current status\n value:\n statusMap[\n patient.person.attributes.find(\n a =>\n a.attributeType.uuid ===\n 'e0b6ed99-72c4-4847-a442-e9929eac4a0f'\n )?.value?.uuid\n ], //input.attributeType = \"e0b6ed99-72c4-4847-a442-e9929eac4a0f\"\n },\n // TODO: Qq6xQ2s6LO8 has an error, Aleksa to ask the client\n {\n attribute: 'Qq6xQ2s6LO8', //legal status\n value:\n statusMap[\n patient.person.attributes.find(\n a =>\n a.attributeType.uuid ===\n 'a9b2c642-097f-43f8-b96b-4d2f50ffd9b1'\n )?.value?.uuid\n ], //input.attributeType = \"a9b2c642-097f-43f8-b96b-4d2f50ffd9b1\"\n },\n {\n attribute: 'FpuGAOu6itZ', //marital status\n value:\n statusMap[\n patient.person.attributes.find(\n a =>\n a.attributeType.uuid ===\n '3884dc76-c271-4bcb-8df8-81c6fb897f53'\n )?.value?.uuid\n ], //input.attributeType = \"3884dc76-c271-4bcb-8df8-81c6fb897f53\"\n },\n {\n attribute: 'v7k4OcXrWR8', //employment status\n value:\n statusMap[\n patient.person.attributes.find(\n a =>\n a.attributeType.uuid ===\n 'dd1f7f0f-ccea-4228-9aa8-a8c3b0ea4c3e'\n )?.value?.uuid\n ], //input.attributeType = \"dd1f7f0f-ccea-4228-9aa8-a8c3b0ea4c3e\"\n },\n {\n attribute: 'SVoT2cVLd5O', //Number of children\n value: patient.person.attributes.find(\n a => a.attributeType.uuid === 'e363161a-9d5c-4331-8463-238938f018ed'\n )?.value, //input.attributeType = \"e363161a-9d5c-4331-8463-238938f018ed\"\n },\n ],\n },\n };\n\n console.log('mapped dhis2 payloads:: ', JSON.stringify(payload, null, 2));\n\n if (isNewPatient) {\n console.log('create enrollment');\n payload.data.enrollments = enrollments;\n }\n\n return payload;\n};\n\nconst delay = ms => new Promise(resolve => setTimeout(resolve, ms));\n\neach(\n '$.patients[*]',\n get(\n 'tracker/trackedEntities',\n {\n orgUnit: 'OPjuJMZFLop',\n filter: [`AYbfTPYMNJH:Eq:${$.data?.uuid}`],\n program: 'w9MSPn5oSqp',\n },\n {},\n async state => {\n const patient = state.references.at(-1);\n console.log(patient.uuid, 'patient uuid');\n\n const isNewPatient = state.data.instances.length === 0;\n\n state.patientsUpsert ??= [];\n state.patientsUpsert.push(\n buildPatientsUpsert(state, patient, isNewPatient)\n );\n await delay(2000);\n return state;\n }\n )\n);\nfn(state => {\n console.log('patientsToUpsert:: ', state.patientsUpsert);\n return state;\n});\n// Upsert TEIs to DHIS2\neach(\n 'patientsToUpsert[*]',\n upsert('trackedEntityInstances', $.data.query, $.data.data)\n);\nfn(state => {\n const {\n data,\n response,\n references,\n patients,\n statusMap,\n patientsUpsert,\n nationalityMap,\n placeOflivingMap,\n genderOptions,\n ...next\n } = state;\n\n next.patientUuids = patients.map(p => p.uuid);\n return next;\n});\n", | ||
"adaptor": "@openfn/[email protected]", | ||
"project_credential_id": "8a5ead9b-5f9e-49b1-9e9a-9dc3c4ccf72d" | ||
}, | ||
|
@@ -144,7 +144,7 @@ | |
} | ||
}, | ||
"deleted_at": null, | ||
"lock_version": 168, | ||
"lock_version": 169, | ||
"triggers": { | ||
"cron": { | ||
"enabled": false, | ||
|