OpenFn / primero-progres

Interoperability solution for UNICEF <> UNHCR interagency referrals between Primero and Progres v4 systems.
https://openfn.github.io/primero-progres/
0 stars 2 forks source link

Flow2 issue upserting cases with decision status in Primero - update logs & check for bug #10

Closed aleksa-krolls closed 3 years ago

aleksa-krolls commented 3 years ago

Describe the bug

See issue #5 for original Flow 2 specs.

In this run (https://www.openfn.org/projects/p5am6e/runs/r6grxemw) DTP has sent OpenFn a referral decision (see related Message: https://www.openfn.org/projects/p5am6e/messages/mk5a53qn) that we want to send back to Primero and upsert cases with.

I can see the run succeeded, but I'm very confused by what I see in the logs. Does this mean there are 8 cases in Primero that have the same id? (This might be an issue with test data, not something we expect in real life... however, at least according to the logs, I can't tell if we're successfully updating cases in Primero.... it just says "8 cases retrieved"... and then "Finished"... so did we update cases in Primero?)

Decision to send back to Primero: []
Primero says: '200 OK'
8 cases retrieved from request: {
  "uri": {
    "protocol": "https:",
    "slashes": true,
    "auth": null,
    "host": "demo-cpims-dadaab.primero.org",
    "port": null,
    "hostname": "demo-cpims-dadaab.primero.org",
    "hash": null,
    "search": "?remote=true",
    "query": "remote=true",
    "pathname": "/api/v2/cases",
    "path": "/api/v2/cases?remote=true",
    "href": "https://demo-cpims-dadaab.primero.org/api/v2/cases?remote=true"
  },
  "method": "GET",
  "headers": {
    "Authorization": "Basic b3Blbl9mdW5jdGlvbjpwcmlIa1RKNXZxd1MxUzg="
  }
}.
Finished.

If we are successfully performing actions in Primero, can you please update the logs to reflect this? If we are not... can you please help to troubleshoot to figure out why we are not updating the Primero case with the referral decision? (If we get multiple Primero cases back with the same id, and we're not sure how to map to Primero... we should force the run to fail with the error message More than 1 matching Primero case found for this referral. Please contact the administrator.)

To Reproduce

Feel free to re-run this on prod: https://www.openfn.org/projects/p5am6e/runs/r6grxemw

expression.js

https://github.com/OpenFn/primero-progres/blob/master/jobs/2.c.uploadDecisions.js

state.json

https://www.openfn.org/projects/p5am6e/messages/mk5a53qn See LP for Primero Dadaab

aleksa-krolls commented 3 years ago

@lakhassane For every item in the Intervention array, we should upsert 1 case in Primero (and therefore send a separate GET request to search for each). When searching for existing Primero cases, the Primero case_id: progres_interoperabilityreferralid.

For the updated decision mappings, please use this:

      module_id: 'primero-cp', //Keep; TO CONFIRM WITH UNHCR
      case_id: progres_orgreferralid //New mapping for case_id
      progres_interventionnumber: data.progres_interoperabilityreferralnumber, //New mapping; to confirm if this is same as inter no
      unhcr_individual_no: data.progres_individualid, //New mapping
      unhcr_id_no: data.progres_interoperabilityreferralid, //New mapping
      status: data.progres_reviewdecision, //TODO: add tansformation so if DTP sends '125080000', return the string 'Accepted'
      //closure_reason: data.progres_comments_nonrestrictedstore, //comment out for now;TO CONFIRM WITH UNHCR
      //service_referral_notes: data.progres_comments_nonrestrictedstore, //comment out for now; TO CONFIRM WITH UNHCR
      //service_type: data.progres_interventiontype2, //comment out for now; TO CONFIRM
lakhassane commented 3 years ago

@aleksa-krolls I updated accordingly.

aleksa-krolls commented 3 years ago

@lakhassane Cool... so I re-ran this Message and I see 0 cases retrieved: https://www.openfn.org/projects/p5am6e/runs/r9wxmbbp

If that's the case, can we force this to fail... No cases found. Decision update failed.

aleksa-krolls commented 3 years ago

@lakhassane actually case_id: progres_orgreferralid

aleksa-krolls commented 3 years ago

@lakhassane If we're trying to update a case in Primero with a decision, and no matching case is found... we throw an error. See example: https://www.openfn.org/projects/p5am6e/runs/rj5zynr7

Can you please add a log that says No case found in Primero for id X and include the id case_id: data.progres_orgreferralid

And also when successful run, please include the case_id in the logs: https://www.openfn.org/projects/p5am6e/runs/rn578p5a

lakhassane commented 3 years ago

@aleksa-krolls logs done for both. For the second one I assume it's a copied job and is not actually linked to any github job.