OpenFn / unicef-cambodia

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

Update logs tracking lastCreated and lastUpdated dates to anticipate different response types #34

Closed aleksa-krolls closed 4 years ago

aleksa-krolls commented 4 years ago

When OpenFn sends a GET request to Primero, there are 3 potential responses:

  1. New Primero referral (response includes transitions object - standard response we've been expecting)
  2. No cases to sync
  3. New Primero case created (only case data sent, no transitions object included; in this scenario only transitions_changed_at may be sent - see below)
{
  owned_by: 'primero',
  owned_by_agency: 'agency-unicef',
  owned_by_phone: '12345676867867876',
  module_id: 'primeromodule-cp',
  created_at: '2020/06/23 08:59:18 +0000',
  case_id_display: '0ae445f',
  name_first: 'Pedro',
  name_last: 'test',
  sex: 'female',
  date_of_birth: '2015/01/01',
  services_section: [ [Object], [Object] ],
  _id: '20cddfa26b10a439d5f2e3203cf99d10',
  case_id: '875303e6-840c-4bfa-af5f-293ed0ae445f',
  transitions_changed_at: '2020/06/28 22:22:48 +0000'
}

Before we wrongly assumed that there would always be a transitions object which is not the case for response type 3. Can you please update these logs to either show transitions_changed_at AND/OR transitions.created_at (if it exists)? https://github.com/OpenFn/unicef-cambodia/blob/05077d36e99ebfce2c004bee757213049a50d2e5/jobs/f1-j1-getPrimeroCases.js#L36-L67