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

Flow1-2: Send 1 referral `decision` for each 1 service that matches criteria #38

Closed aleksa-krolls closed 3 years ago

aleksa-krolls commented 3 years ago

Background, context, and business value

Related to Flow 1 where Progres sends a referral to Primero --> this upserts a case and individual service. (1 Progres referral = 1 Primero service)

Primero users will review the referral and update the individual service's "unhcr_referral_status" to accept/reject. We then need to send this decision back to Progres.

The specific request, in as few words as possible

Update Flow1-2 to ensure the decision mappings map to the service with the unhcr_referral_status referral decision. (It looks like decision is mapping case-level data only instead of service-level)

Currently the job correctly fetches case id: f0b43ee6-bedc-42be-b785-86929bc603c9 that looks like this... (see run L97: https://www.openfn.org/projects/p5am6e/runs/061644bc-8480-7d03-a3c3-d751a86f315e)

{
    "id": "f0b43ee6-bedc-42be-b785-86929bc603c9",
    "services_section": [
      {
        "unique_id": "eed9217b-901b-41de-b4f7-35efd4f8338a",
        "service_type": "alternative_care",
        "service_referral": "external_referral",
        "service_implemented": "not_implemented",
        "service_request_email": "test@test.com",
        "service_request_phone": "9999999999",
        "service_request_title": "Mr",
        "service_response_type": "service_provision",
        "unhcr_referral_status": "rejected",
        "service_referral_notes": "test",
        "service_request_agency": "DAD-17-PNR-00011",
        "service_request_external": true,
        "service_response_day_time": "2021-10-06T00:00:00.000Z",
        "progres_interventionnumber": "612-21-PRTITV-0000001",
        "service_implementing_agency": "UNICEF"
      }

However, this service isn't recognized as a decision to send to UNHCR even though "unhcr_referral_status": "rejected".

MAKE SURE: For every 1 service in the service_section that meets the criteria below... send 1 decision notification to DTP. So if there are multiple services that match this criteria, send 1 request to DTP to each matching service. https://github.com/OpenFn/primero-progres/blob/e5e365803d8e0d72eac9ecc7a717500cfbf2ceb5/jobs/1.b.sendReferrals.js#L18-L29

state.json

See LP for Primero Gambella open_function Run job Flow1-2 to extract from Primero (manual cursor is set to today): https://www.openfn.org/projects/p5am6e/jobs/jv89rx

adaptor

http

expression.js

L48 and L49 should map from the individual service... not case-level. https://github.com/OpenFn/primero-progres/blob/7c75818e9f259c65ba4244d532e97e646b89cfac/jobs/1.b.sendReferrals.js#L43-L52

output.json

Send decision to DTP endpoint.

aleksa-krolls commented 3 years ago

@lakhassane please prioritize this today... we hope to use in a testing session @ 2p

lakhassane commented 3 years ago

@aleksa-krolls I changed the mapping at service level. For line 48 it was already the case because inside the each, whatever was in services_section is now inside state.data

aleksa-krolls commented 3 years ago

@lakhassane quick feedback re: https://github.com/OpenFn/primero-progres/blob/master/jobs/1.b.sendReferrals.js#L52

case_id (see L596 in run log) needs to have the substring last 12 digits of the service uid appended after a hashtag... like we do in this job here.

lakhassane commented 3 years ago

@aleksa-krolls I updated the case_id. see L185 and 194

aleksa-krolls commented 3 years ago

@lakhassane For Monday... if I look at this run log (https://www.openfn.org/projects/p5am6e/runs/0616911c-28d4-70d4-a9d2-fd81c2088f3b), it appears we're sending pending decisions (when we should only send accepted or rejected. Is that the case?

Decision to send to DTP:  {
  "case_id": "9acf68e3-3adc-45b9-91cb-61dc902d0aaa#59a817caacfb",
  "primero_user": "unhcr_cw",
  "progres_interventionnumber": "612-21-PRTITV-0000009",
  "status": "pending",
  "closure_reason": "No reason specified.",
  "request_type": "ReceiveDecisionOutgoingReferral"
}

This log Number of matching referrals: 2 looks correct... I see 2 rejected referrals, but want to make sure that's indeed what is being sent to DTP. Please update the logs accordingly.

lakhassane commented 3 years ago

@aleksa-krolls feedback here: From what I see there are multiple services_section that matched the filter we did. And for 2 of them we have unhcr_referral_status: rejected and for the others it is equal to pending. However, since we use unhcr_referral_status to map status, that's why we are seeing pending.

Should we ignore values that are different from accepted/rejected?

lakhassane commented 3 years ago

@aleksa-krolls correction done! I re-run but no match for now: https://www.openfn.org/projects/p5am6e/runs/0616d4d6-bf3c-7374-a381-910506b1ab04