Closed aleksa-krolls closed 3 years ago
@aleksa-krolls , see changes here: https://github.com/OpenFn/unicef-cambodia/commit/3dd3d6cb8b400a377c68dc26eaa4b57bd697c9b9
Please take a full look through that particular link; I tried to make it fairly comprehensible.
Right now, everything works except update_links
at the end. We get a 500
from Oscar, despite matching the API docs provided for that endpoint. See Slack for details: https://openfn.slack.com/archives/G2LJCFFDW/p1605598940004500?thread_ts=1605594473.001000&cid=G2LJCFFDW
@taylordowns2000 Resolved by adding the data
attribute to the PUT
request body. Thanks for the help, will keep you posted as we resume testing today.
Background, context, and business value
In Flow 2 (OSCaR cases --> Primero) we sync 2 types of cases...
Supporting case type # 1 has been a more recent change. For these cases, when we run Flow 1 to sync Primero data back to --> Oscar, we only want to sync the Primero
case_id
(akaexternal_id
in Oscar)... we do not want any other fields from Primero to sync back to Oscar for these cases to ensure no mistaken overwriting of data.For this sync back to Oscar in Flow 1, currently we leverage the Oscar endpoint
/organizations/clients/upsert/
. However, we've learned that doesn't support true upsert operations and cannot be used to update cases originally registered in the Oscar system... it can only be leveraged to upsert referrals. If we try to update cases only (no referrals) via this endpoint, we will therefore create false referrals.So to update cases only (with no referrals) that already exist in Oscar, we must leverage the Oscar endpoint
/organizations/clients/update_links/
(see LP for Oscar API Docs swaggerhub).The specific request, in as few words as possible
Update
f1-j2-casesToOscar.js
to determine which cases fetched from Primero (f1-j1) have services where"service_response_type": "referral_to_oscar"
. Then..."service_response_type": "referral_to_oscar"
--> keep the flow as is, leveraging the Oscar endpointPOST '/organizations/clients/upsert/'
to sync the full case payload received from Primero"referral_to_oscar"
services --> then use the casecase_id
,case_id_display
, andoscar_number
to send a different request toPUT '/organizations/clients/update_links/'
. The request body should look like the below snippet.state.json
For Oscar: See LP for
Oscar Production Demo API user
For Primero: See LP forUNICEF Primero Alpha API User Login
For state, use
sample_data/getPrimeroOutput.json
. This payload is the output of runningf1-j1-getPrimeroCases.js
and includes 3 cases:39b7d2e
that is a case with no services and NO referralse22fae1
that is a case with services but NO referrals1913226
that is a case with 1 referral to Oscaradaptor
language-http
when accessing OscarSee API docs: https://app.swaggerhub.com/apis/Ro51/OSCaRInterop/1.0.0#/client%20links/updateClientLinks
expression.js
f1-j2-casesToOscar.js
output.json
For state
sample_data/getPrimeroOutput.json
, the cases should trigger the following actions:39b7d2e
that is a case with no services and NO referrals --> we accessPUT '/organizations/clients/update_links/'
to update the Oscar case with the Primero Idse22fae1
that is a case with services but NO referrals --> we accessPUT '/organizations/clients/update_links/'
to update the Oscar case with the Primero Ids1913226
that is a case with 1 referral to Oscar --> we follow the existing flow andPOST '/organizations/clients/upsert/'
to create this referral in Oscar