OpenFn / openfn-lime-pilot

MSF LIME Project - OpenFn Workflows for Iraq Pilot
1 stars 0 forks source link

wf1: before we `create patient`, check if patient existing #18

Closed aleksa-krolls closed 2 weeks ago

aleksa-krolls commented 2 months ago

Background, context, and business value

Ref #1 for original WF1 specs.

Right now WF1 is sometimes failing bc test data has already been synced from DHIS2 to OMRS - see example run with error "Identifier already in use by another patient". Let's implement an "upsert" pattern to check if that OMRS patient already exists.

The specific request, in as few words as possible

Please make sure this feedback is implemented so that address is always mapped.

Then, let's replace the create Patient() step with an "upsert Patient" step, where we should...

  1. GET /patient?q=${patientNumber} to look up existing patients using the dhis2 patientNumber
  2. If found, update the patient `PUT /patient/${patient.uuid}
  3. If not found, create the patient (as we currently do) https://github.com/OpenFn/openfn-lime-pilot/blob/739077a97fb36cdc353708f619d8a2a9121fbc45/workflows/wf1/2-create-patients.js#L105-L111

Expected data volumes

We might expected a couple dozen of patients in the initial migration

API Documentation

Input

Credentials

Data

Run wf-1-1 to get TEIs from DHIS2

Output

If DHIS2 returns X patients, then X number of patients should be created in OpenMRS. See example output payload: https://github.com/OpenFn/openfn-lime-pilot/blob/main/sample-data/pilot/openmrs_postPatientBody.json

Testing guidance

Run WF1 with input {"manualCursor": "2024-09-13T10:00:00.00"}

Toggl

MSF 2024

mtuchi commented 2 months ago

Getting this error, i will investigate further tomorrow

POST http://msf-ocg-openmrs3-dev.westeurope.cloudapp.azure.com/openmrs/ws/rest/v1/patient/cd8f0b8c-af5c-41c8-b3c8-b2b727710bb5 - 200 in 693ms
Successfully updated patient
[R/T] ✘ Failed step create-patients after 2.363s
[R/T] ✘ {
  "source": "runtime",
  "name": "RuntimeError",
  "severity": "fail",
  "subtype": "TypeError",
  "message": "TypeError: Cannot read properties of undefined (reading 'uuid')"
}
mtuchi commented 2 months ago

Carry over to next sprint, I couldn't get to this today.

aleksa-krolls commented 2 weeks ago

Old issue - upsert pattern was implemented on next-staging and is in QA. Closing this issue. https://github.com/OpenFn/openfn-lime-pilot/blob/next-staging/workflows/wf1/3-create-patients.js#L141-L146