OpenFn / openfn-lime-pilot

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

wf2 - link events to existing enrollment to avoid failures #24

Open aleksa-krolls opened 1 day ago

aleksa-krolls commented 1 day ago

Background, context, and business value

Currently run is failing when we try to create 2 events (each belonging to different programStage): "Tracked entity instance: TbBCJzZbPuA has multiple active enrollments in program: w9MSPn5oSqp"

The specific request, in as few words as possible

We need to make sure to link events to existing enrollments to avoid this error. Please:

  1. Update the Get TEIs step to ensure enrollments are returned when we query existing TEIs. Adding this parameter works on postman: ?fields=*,enrollments[*]

    get(
    'trackedEntityInstances',
    {
      ou: 'OPjuJMZFLop',
      program: 'w9MSPn5oSqp',
      filter: [`AYbfTPYMNJH:Eq:${$.data.patient.uuid}`],
      //fields: '*,enrollments[*]' //is this right?  --> TODO: Add parameter ?fields=*,enrollments[*]
    },
  2. If this works, then find the trackedEntityInstance.enrollments[x].enrollment id where enrollments[x].program == 'w9MSPn5oSqp' to map in the next step

    Screenshot 2024-09-18 at 10 45 59 AM
  3. Update the Create events step to add this enrollment id to the main payload

    const event = {
      program: 'w9MSPn5oSqp',
      orgUnit: 'OPjuJMZFLop',
      trackedEntityInstance: TEIs[data.patient.uuid],
      //enrollment: "existing_enrollment_id", //TODO to update existing enrollment
      eventDate,
    };

Input

Run WF2 with { "lastRunDateTime": "2024-09-16T00:00:00.000Z" } to generate data. See #2 for credentials.

Try testing for patient Katrina... so you can update your Get Encounters step to use this query for the time being: encounters?q=Katrina

Toggl

MSF 2024

aleksa-krolls commented 1 day ago

@mtuchi priority issue to work on following our call

mtuchi commented 19 hours ago

EOD Update This was fixed on #26 and tested locally, @aleksa-krolls you can proceed testing on app the PR is already merged to staging