OpenFn / unicef-cambodia

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

Add `enrollment_date` mapping to Services array #49

Closed aleksa-krolls closed 4 years ago

aleksa-krolls commented 4 years ago

We need to add a new service_implemented_day_time mapping when we upload Primero service data.... https://github.com/OpenFn/unicef-cambodia/blob/2ad697d0e35eb8fd4bbc38832b6085d17cd4b2c3/jobs/f2-j2-upsertCasesToPrimero.js#L280-L306

Oscar will respond to f2-j1 with this state where enrollment_date will be added to Services.

{
  "enrollment_date": "2020-07-12",
  "uuid": "fad739ec-b0ab-47f3-8f1c-1a17c09a6287",
  "name": "Social Work / Case Work",
},

Update Primero mappings so that the enrollment_date is converted to the Primero format dd-mmm-yyyy hh:mm:

.map(s => { 
     return { 
       unique_id: s.uuid, 
       service_implemented_day_time: s.enrollment_date,  //convert data format & check that not undefined or empty string

*Keep in mind that Oscar is still implementing enrollment_date, so I'm not confident it will be included in historical data... so please handle for this key not existing or returning undefined or empty string.

taylordowns2000 commented 4 years ago

hey @aleksa-krolls , i see a lot of datetimes in primero that use this format:

registration_date: oscarValue(c.external_id)
          ? null
          : now.toISOString().split('T')[0].replace(/-/g, '/'),

that's an ISO string '2020-07-22T22:59:41.420Z' with the T pulled out and then the -'s turned to /s. Do we want that, or that dd-mmm-yyyy hh:mm format?

aleksa-krolls commented 4 years ago

@taylordowns2000 Alberto says dd-mmm-yyyy hh:mm so let's go with that.

taylordowns2000 commented 4 years ago

OK, happy to do this, but are they asking us to forge the hh:mm part if it's not present in the source data? If so, what time do they want us to pretend the case was enrolled? I'll assume 00:00 for now. (This raises so many red flags, but nothing we haven't warned them repeatedly about thus far.)

taylordowns2000 commented 4 years ago

image

taylordowns2000 commented 4 years ago

oh wow, sorry, just realizing that they want month spelled out as a three letter abbreviation. reopening this to work on it.

taylordowns2000 commented 4 years ago

I've changed this to use lower-case-only three letter abbreviations for the month, per Alberto's request: image

aleksa-krolls commented 4 years ago

@taylordowns2000 OpenFn jobs are sometimes returning "service_implemented_day_time": "NaN-undefined-NaN 00:00",. See run failure here.

Looks like this is happening in scenarios where we do not receive anything from Oscar... see below where enrollment_date key is not included. Please handle for these scenarios as Oscar is still implementing enrollment_date.


Data provided by Oscar (ON: 01EDT83PVP3FNVT9DK67QHGZ2W / extId: d137d491-e0e9-483b-9d9d-d416a9211e90) : {
  "oscar_short_id": "jvxu-1778",
  "address_current_village_code": "",
  "external_case_worker_id": "",
  "external_case_worker_name": "primero",
  "external_id": "d137d491-e0e9-483b-9d9d-d416a9211e90",
  "external_id_display": "9211e90",
  "global_id": "01EDT83PVP3FNVT9DK67QHGZ2W",
  "is_referred": false,
  "location_current_village_code": "",
  "mosvy_number": "",
  "organization_id": 46,
  "organization_name": "cif",
  "services": [
    {
      "uuid": "11226c6d-d7b8-4272-b45e-85cf635b9fba"
    },
    {
      "uuid": "21905571-81c2-4870-ab33-db6cde56bbbe"
    }
  ],
  "status": "Active"
}
aleksa-krolls commented 4 years ago

@taylordowns2000 I think is was resolved, no related errors recently popping up. Please confirm no outstanding questions? See my last comment above.

taylordowns2000 commented 4 years ago

This is now handled in convertDate lines 278-301... if Oscar does not send a date (by oscarValue standards) we return null rather than trying to parse the date string and returning those NaNs

https://github.com/OpenFn/unicef-cambodia/blob/0902e3642377a890033a42c16e39afc11dd6eafb/jobs/f2-j2-upsertCasesToPrimero.js#L278-L301