OpenFn / unicef-cambodia

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

Set owned_by to matching Province user #50

Closed aleksa-krolls closed 4 years ago

aleksa-krolls commented 4 years ago

https://github.com/OpenFn/unicef-cambodia/blob/96318275dbe2b0abaa175bfef28529caf9ad3b02/jobs/f2-j2-upsertCasesToPrimero.js#L417-L419

To remove Agency User Map --> replace with new Province User Map. The new requirement is we want to assign the owned_by user based on the case's current location.

To implement:

  1. Preserve the logic where we first check if this case has an external_id. If yes, return null. If not, proceed to step 2. owned_by: oscarValue(c.external_id) ? null : provinceMap

  2. Identify the province location code (2 digits).

    • First determine location based on c.location_current_village_code. Use the first 2 digits to determine the province code (e.g., if location is 12345201 then province code = 12).
    • If not defined, check organization_address_code (new field added to API response) to determine the province code.
    • If both are not defined --> do not upload the case to Primero and log that this didn't sync (to discuss).
  3. Use this Province User Map to assign the appropriate owned_by user based on the province code determined above.

aleksa-krolls commented 4 years ago

Re: #2 - consider the concept of a Maintenance Job going forward @aleksa-krolls