f1-j2: Add logic to `organization_name` mapping to assign case in Oscar
aleksa-krolls opened this issue · 1 comments
Request
Change the Oscar organization_name
mapping. We've been hardcoding this to demo
for testing, but now are preparing for go-live and want to change this mapping to determine how referrals are assigned in Oscar.
- First check if
services_section
contains a service record whereservice_response_type: 'referral_from_oscar'
--> if yes, maporganization_name: c.services_section[*].oscar_referring_organization
, but only return agency name substring (e.g.,agency-demo
-->demo
). Stop flow. - If not, then check if
services_section
contains a service record whereservice_response_type: 'referral_to_oscar'
--> if yes, maporganization_name: c.services_section[*].service_implementing_agency
, but only return agency name substring (e.g.,agency-demo
-->demo
). Stop flow. - If not, (which could happen if no services or different response type selected), default to mapping
organization_name: c.owned_by_agency
, but only return agency name substring (e.g.,agency-demo
-->demo
).
Consider that services_section
might have multiple records, so please follow the order of operations above.
state
Oscar creds: Oscar Production Demo
(api.user...)
Use this state file to test each scenario (it has 3 cases): https://github.com/OpenFn/unicef-cambodia/blob/master/sample_data/state-f1-j2.json
expression
unicef-cambodia/jobs/f1-j2-casesToOscar.js
Lines 192 to 194 in 4e0546c
adaptor
language-http
output
- See snippet below for sample
service_implementing_agency
received from Primero. This should outputorganization_name: demo
when upserting cases in Oscar.
"services_section": [
{
"unique_id": "758d390b-fdda-4167-80ed-a1bfef86ca5e",
"service_response_type": "referral_to_oscar",
"service_type": "social_work_case_work",
"service_subtype": [
"social_work_case_work_generalist"
],
"service_response_day_time": "2020/11/10 08:57:00 +0000",
"service_implementing_agency": "agency-demo",
"service_implementing_agency_individual": "agency-demo-user",
"service_status_referred": true,
"service_implemented": "not_implemented"
}
- Below snippet is for syncing the Primero Id for Oscar referrals back to Oscar, so we only have
oscar_referring_organization
. This should outputorganization_name: demo
when upserting cases in Oscar.
"services_section": [
{
"unique_id": "1f9219fd-39fb-4f78-be49-6d49e65e3a82",
"service_response_type": "service_being_provided_by_oscar_partner_47618",
"service_type": "family_based_care",
"service_subtype": [
"family_based_care_family_preservation",
"family_based_care_independent_living"
],
"service_type_text": "family_based_care",
"service_implemented": "not_implemented",
"service_type_details_text": "n/a",
"oscar_case_worker_name": "ABLE Test",
"oscar_referring_organization": "agency-demo",
"oscar_case_worker_telephone": "+61433736766"
}
- Below snippet has no
services_section
--> still returnsdemo
because we mapowned_by_agency
.
{
"owned_by": "agency-demo-user",
"owned_by_agency": "agency-demo",
"module_id": "primeromodule-cp",
"created_at": "2020/11/16 08:20:30 +0000",
"case_id_display": "39b7d2e",
"oscar_number": "01ED6NGKY1NVK3VDWXKR0S2XX5",
"oscar_short_id": "iqm-893",
"name_last": "Ith",
"name_first": "kunthea",
"sex": "male",
"date_of_birth": "2020/09/01",
"age": 0,
"_id": "7d4b1afdc516606a92e57d4ed1a7e781",
"case_id": "bc3eafab-b4b6-4fe3-9e5e-eb08f39b7d2e"
}
```
@taylordowns2000 since our last changes, I'm seeing some failures with the error TypeError [Error]: Cannot read property 'substring' of undefined
.
See run failure in f1-j2
: https://www.openfn.org/projects/pdngk6/runs/rbgb4p7b
See triggering run of job f1-j1
: https://www.openfn.org/projects/pdngk6/runs/r89jray9
To replicate
Run f1-j1
: https://www.openfn.org/projects/pdngk6/jobs/jyazq6
Credentials:
Use Primero Alpha Cambodia
and Oscar Production Demo
.