OpenFn/unicef-cambodia

Primero -> Oscar flow: Update 'f2-j2-upsertCasesToPrimero' job to include syncing of referral decision from flow 1

Closed this issue · 4 comments

Feature Request

Background, context, and business value

The Primero and Oscar teams have agreed to include a decision flow in the solution. So we will now be syncing referral decisions back and forth between the two systems. This is similar to the decision flow we implemented for the Primero - Progres project where we (1) get the matching referral, and (2) update the referral with the decision status.

See the data flow diagram here.

The specific request, in as few words as possible

Make updates in the f2-j2-upsertCasesToPrimero job to sync the decisions recieved from the parent job.

1) Referral update:

  1. Parse the decision JSON from Oscar to find the external_id (Primero case_id) & services[].name (Primero service type)
  2. Get referrals for that case: GET /cases/:id/referrals. See sample JSON response.
  3. If no referrals are found, log an error: No matching Oscar referral found
  4. If they are found, loop through these referrals until we find the referral where service_record_id = services[].uuid from the Oscar decision
  5. Once we find the matching referral record to update, pass the id onto the next operation...
    updateReferral(...) to PATCH an update to the Primero status field with what is in the referral_status field from the Oscar response.
    PATCH /cases/:record_id/referrals/:id
    See sample JSON payload for request body

2) Add mapping to cases-level update on the services subform:

  1. add a services_section[] mapping for Primero referral_status_5fe9c1a here. The source field is the referral_status field from the Oscar response. See mappings below.

state.json

Primero:

{
  "configuration": "Primero V2 Cambodia Demo API user",
  "data": "Run F2-J1 to generate state"
}

Oscar (to generate state):

{
  "configuration": "Oscar Staging (api only user)",
  "data": "Data will be generated from this job"
}

adaptor

Primero adaptor
Primero API Docs

expression

All changes should be made in the V2 folder
f2-j2-upsertCasesToPrimero

@daissatou2 let's talk through this one in our call tomorrow.

  1. Referral update - overall looking good, but let's discuss about how we can be more specific on the mappings.
  2. Case level update - the existing job uses upsertCase(...). We need to ask to add a services_section[] mapping for referral_status here: https://github.com/OpenFn/unicef-cambodia/blob/master/jobs/f2-j2-upsertCasesToPrimero.js#L282-L291
  3. Do we have data flow diagrams we can link to? This is always helpful for Mamadou.

@daissatou2 this is done for the referral update. We might need more data to be able to test

@lakhassane I am testing syncing only the oscar_number from Oscar to Primero for case with case_id = "55647191-e544-4fda-87d8-bd118b21ed32" (so no decision has been made on this case which originated in Primero yet). But this job is failing after completing the upsert: https://www.openfn.org/projects/primero-oscar-cambodia-io-staging/runs/0620bbcf-1c14-7492-8edf-c60f7f6c399e

Note: I am seeing the new oscar_number in Primero after this sync. But why is the job failing?