OpenFn / unicef-cambodia

UNICEF Cambodia - Primero Interoperability
https://openfn.github.io/unicef-cambodia/
1 stars 2 forks source link

Update the f1-j2-casesToOscar job to use a new endpoint for Oscar decisions #116

Closed daissatou2 closed 2 years ago

daissatou2 commented 2 years ago

Feature Request

Background, context, and business value

The f1-j2-casesToOscar job currently sends Oscar decisions, (oscarDecisions in the job) and new Oscar referrals (oscarRefs in the job) to the same endpoint after merging them into one referrals array.

Update this job to use a separate endpoint for oscarDecisions. No changes should be made to how we are sending data for oscarRefs to Oscar.

The specific request, in as few words as possible

For each item in the oscarDecisions array, the job should do the following: Send data to this new endpoint: /api/v1/organizations/referrals/update_statuses

With the mappings below: external_id: c.case_id, external_id_display: c.case_id_display, client_global_id: c.oscar_number, referral_status: (referral status mapping should not change. See line here.) referral_id: s.oscar_referral_id_a4ac8a5

Sample payload:

{
    "data": [
        {
            "external_id": "39051cfc-a2fe-4f97-8323-e7c52a07441a",
            "external_id_display": "a07441a",
            "client_global_id": "01FYNQMK4AAS1JGVV72XZRHXMA",
            "referral_status": "Accepted",
            "referral_id": 654
        },
        {
            "external_id": "39051cfc-a2fe-4f97-8323-e7c52a074411",
            "external_id_display": "a074411",
            "client_global_id": "01FYNQMK4AAS1JGVV72XZRHXMM",
            "referral_status": "Accepted",
            "referral_id": 123
        }
    ]
}

state.json

f1-j1-getPrimeroCasesV2.js

{
  "configuration": ["SEE LAST PASS: 'Primero V2 Cambodia Demo (openfn_cp_user)'"],
}

f1-j2-casesToOscar.js

{
  "configuration": ["SEE LAST PASS: 'Oscar Staging (api only user)'"],
  "data": "Data generated from F1-J1 job run",
}

expression.js

f1-j1-getPrimeroCasesV2.js f1-j2-casesToOscar.js

daissatou2 commented 2 years ago

@aleksa-krolls please take a look at this issue. The only other change to be made after this issue is complete is removing the referral_status mapping from the /api/v1/organizations/clients/upsert/ endpoint. Let me know your thoughts.

aleksa-krolls commented 2 years ago

@daissatou2 I implemented the changes per Kiry's request, but I am not convinced it working as described... however I don't know if maybe there is an issue with the older test data I'm using and referrals that might have already been accepted/rejected in Oscar. Can you please run a test for the below steps to confirm?

  1. In Oscar, create referral, sync to Primero
  2. In Primero, accept/reject this referral
  3. Sync decision back to Oscar and share the run link
daissatou2 commented 2 years ago

This is pending response from Kiry. Seeing the same 404 Not Found error.

daissatou2 commented 2 years ago

see slack for latest @aleksa-krolls.

aleksa-krolls commented 2 years ago

@daissatou2 I'm reviewing your Slack post and the open issues for this repo. Below I've pasted the new payload format you shared. Can you confirm this be sent to the new endpoint /api/v1/organizations/referrals/update_statuses? Or should we plan to confirm this with Kiry on the call tomorrow? (I ask because I know he mentioned going back to using the old existing endpoint again...)

{

    "data": [

      {

        "external_id": "9de500c0-e818-4ded-86db-d0efa7d8d606",

        "external_id_display": "7d8d606",

        "client_global_id": "01G927042YKTRANTSTSTNK9YT9",

        "referral_status": "Referred",

        "referral_id": "1191"

      }

    ]
daissatou2 commented 2 years ago

@aleksa-krolls this should be sent to the new endpoint: /api/v1/organizations/referrals/update_statuses

daissatou2 commented 2 years ago

@aleksa-krolls use PUT /api/v1/organizations/referrals/update_statuses instead of POST

aleksa-krolls commented 2 years ago

@daissatou2 I think my most recent commits have implemented the PUT request and cleaned up the logic to map decisions for every oscar referral with a Primero decision (accept/reject). Can you pls test to provide feedback?