OpenFn / unicef-cambodia

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

Add a second Primero GET request to f1-j1 #60

Closed aleksa-krolls closed 3 years ago

aleksa-krolls commented 3 years ago

Background

Previously we were asked to only fetch cases tagged with oscar referrals from Primero. Now that some of the Oscar cases synced will not have referrals, we need to change how we are going to request data from Primero... only now has Primero confirmed that what we need must be achieved by 2 GET requests rather than only 1 request.

Change request

Modify f1-j1-getPrimeroCases.js to send 2 getCases(...) requests to Primero to fetch services with referral_to_oscar as well as any oscar cases that might not have referrals (oscar_number: 'range||*.*'). We then need to combine the response to pass all cases returned to f1-j2-casesToOscar.js.

// #1 - Request oscar referrals only
getCases(
  {
    remote: true,
    scope: {
      or: {
        transitions_created_at: `or_op||date_range||${
          state.lastCreated || '25-09-2020' // TEST CURSOR
        }.01-01-4020`,
        transitions_changed_at: `or_op||date_range||${
          state.lastUpdated || '25-09-2020 00:00' // TEST CURSOR
        }.01-01-4020 00:00`,
      },
      service_response_types: 'list||referral_to_oscar', //only pulls cases with referral services

    },
    per: 1000,
  },
// #2 - Request all oscar cases
getCases(
  {
    remote: true,
    scope: {
      or: {
        transitions_created_at: `or_op||date_range||${
          state.lastCreated || '25-09-2020' // TEST CURSOR
        }.01-01-4020`,
        transitions_changed_at: `or_op||date_range||${
          state.lastUpdated || '25-09-2020 00:00' // TEST CURSOR
        }.01-01-4020 00:00`,
      },
      oscar_number: 'range||*.*', //pulls all oscar cases that might not have referrals

    },
    per: 1000,
  },

state.json

Use Primero Alpha staging.

{
  "configuration": {
    "url": "https://cpims-kh-alpha.primero.org",
    "user": "oscar-user",
    "password": "pwd"
  },
  "data": {}
}

adaptor

language-primero

expression.js

f1-j1-getPrimeroCases.js

side effects

The flow 1 should work just as it did before... only now it will have more cases as inputs now that we're requesting more info from Primero. To test... run the full flow 1 end-to-end.