Skip to content

Commit

Permalink
Update second workflow (#5)
Browse files Browse the repository at this point in the history
* add program

* code format

* wip: update mappings for create encounter

* cereate-events

* Update workflow file path

* remove ocl mapping
  • Loading branch information
mtuchi authored Sep 6, 2024
1 parent b21c20a commit e17ba94
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 222 deletions.
37 changes: 12 additions & 25 deletions openfn-cd92dd57-9a3c-4318-bdcb-f57a386cf811-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,42 @@ workflows:
name: Get Patients
adaptor: '@openfn/language-openmrs@latest'
credential: null
body: |
// Check out the Job Writing Guide for help getting started:
// https://docs.openfn.org/documentation/jobs/job-writing-guide
body:
path: workflows/wf2/1-get-patients.js

Upsert-TEIs:
name: Upsert TEIs
adaptor: '@openfn/language-dhis2@latest'
credential: null
body: |
// Check out the Job Writing Guide for help getting started:
// https://docs.openfn.org/documentation/jobs/job-writing-guide
body:
path: workflows/wf2/2-upsert-teis.js
Get-Encounters:
name: Get Encounters
adaptor: '@openfn/language-openmrs@latest'
credential: null
body: |
// Check out the Job Writing Guide for help getting started:
// https://docs.openfn.org/documentation/jobs/job-writing-guide
body:
path: workflows/wf2/3-get-encounters.js

Get-Options-Map:
name: Get Options Map
adaptor: '@openfn/language-http@latest'
credential: null
body: |
// Check out the Job Writing Guide for help getting started:
// https://docs.openfn.org/documentation/jobs/job-writing-guide
body:
path: workflows/wf2/4-get-options-map.js

Get-TEIs:
name: Get TEIs
adaptor: '@openfn/language-dhis2@latest'
credential: null
body: |
// Check out the Job Writing Guide for help getting started:
// https://docs.openfn.org/documentation/jobs/job-writing-guide
body:
path: workflows/wf2/5-get-teis.js

Create-Events:
name: Create Events
adaptor: '@openfn/language-dhis2@latest'
credential: null
body: |
// Check out the Job Writing Guide for help getting started:
// https://docs.openfn.org/documentation/jobs/job-writing-guide
body:
path: workflows/wf2/6-create-events.js

triggers:
webhook:
Expand Down
10 changes: 5 additions & 5 deletions workflows/wf2/1-get-patients.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ fn(state => {
return state;
});

searchPatient({ q: 'Patient', v: 'full', limit: '100' });
searchPatient({ q: 'Aisha', v: 'full', limit: '1' });
// searchPatient({ q: 'Patient', v: 'full', limit: '100' });
//Query all patients (q=all) not supported on demo OpenMRS; needs to be configured
//...so we query all Patients with name "Patient" instead

fn(state => {
const { results } = state.data;

const getPatientByUuid = uuid => {
return results.find(patient => patient.uuid === uuid);
};
// console.log('dateCreated for patient uuid ...2c6dbfc5acc8',getPatientByUuid("31b4d9c8-f7cc-4c26-ae61-2c6dbfc5acc8").auditInfo.dateCreated)
const getPatientByUuid = uuid =>
results.find(patient => patient.uuid === uuid).auditInfo.dateCreated;

// console.log('dateCreated for patient uuid ...2c6dbfc5acc8',getPatientByUuid("31b4d9c8-f7cc-4c26-ae61-2c6dbfc5acc8"))
//console.log(JSON.stringify(state.data, null, 2));

console.log('Filtering patients to only sync most recent records...');
Expand Down
12 changes: 5 additions & 7 deletions workflows/wf2/2-upsert-teis.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fn(state => {
const payload = {
query: {
ou: 'OPjuJMZFLop',
program: 'w9MSPn5oSqp',
filter: [`AYbfTPYMNJH:Eq:${patient.uuid}`],
},
data: {
Expand Down Expand Up @@ -83,7 +84,8 @@ fn(async state => {
'trackedEntityInstances',
{
ou: 'OPjuJMZFLop',
filter: [`jGNhqEeXy2L:Eq:${patient.uuid}`],
filter: [`AYbfTPYMNJH:Eq:${patient.uuid}`],
program: 'w9MSPn5oSqp',
},
{},
state => {
Expand All @@ -106,12 +108,8 @@ fn(async state => {
// Upsert TEIs to DHIS2
each(
'patientsUpsert[*]',
upsert(
'trackedEntityInstances',
state => state.data.query,
state => state.data.data
)
upsert('trackedEntityInstances', $.data.query, $.data.data)
);

// Clean up state
fn(state => ({ ...state, data: {} }));
fn(({ data, ...state }) => state);
20 changes: 13 additions & 7 deletions workflows/wf2/3-get-encounters.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
// Fetch encounters from the date of cursor
// OpenMRS demo instance does not support querying ALL records (q=all)
getEncounters({ q: 'Patient', v: 'full', limit: 100 });
// getEncounters({ q: 'Patient', v: 'full', limit: 100 });
getEncounters({
q: 'Aisha',
v: 'full',
limit: 1,
encounterType: '95d68645-1b72-4290-be0b-ec1fb64bc067',
});

// Update cursor and return encounters
fn(state => {
const { cursor, data } = state;
console.log("cursor datetime::", cursor);
console.log('cursor datetime::', cursor);

console.log('Filtering encounters to only get recent records...');
console.log(
'Encounters returned before we filter for most recent ::',
JSON.stringify(data, null, 2)
);
const encounters = data.body.results.filter(
// console.log(
// 'Encounters returned before we filter for most recent ::',
// JSON.stringify(data, null, 2)
// );
const encounters = data.results.filter(
encounter => encounter.encounterDatetime >= cursor
);
console.log('# of new encounters to sync to dhis2 ::', encounters.length);
Expand Down
65 changes: 0 additions & 65 deletions workflows/wf2/4-get-oclmap.js

This file was deleted.

60 changes: 60 additions & 0 deletions workflows/wf2/4-get-options-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
get(
'https://gist.githubusercontent.com/aleksa-krolls/b22987f7569bc069e963973401832349/raw/ccc21979aab33e8b5caa931d648698753516011b/msf_mhBaseline_optionsMap.json'
);

fn(state => {
state.optsMap = state.data;
// console.log(JSON.stringify(state.optsMap, null, 2), 'Options Map');
delete state.data;
delete state.references;
delete state.response;
return state;
});

fn(state => {
state.mhpssMap = {
dfdv3SkeXKe: 'a6c5188c-29f0-4d3d-8cf5-7852998df86f',
hWMBCCA2yy1: 'abede172-ba87-4ebe-8054-3afadb181ea3',
TWuCY5r2wx7: 'ccc4f06c-b76a-440d-9b7e-c48ba2c4a0ab',
QHrIUMhjZlO: 'd516de07-979b-411c-b7e4-bd09cf7d9d91',
H1fMCaOzr8F: '3e97c2d0-15c1-4cfd-884f-7a4721079217',
yCwuZ0htrlH: '5f6e245c-83fc-421b-8d46-061ac773ae71',
RiiH9A53rvG: '6d3876be-0a27-466d-ad58-92edcc8c31fb',
pN4iQH4AEzk: '722dd83a-c1cf-48ad-ac99-45ac131ccc96',
qgfKPlIHjcD: 'd8c84af2-bd9b-4bf3-a815-81652cb0b0bc',
rSIazMFEBjD: '4dae5b12-070f-4153-b1ca-fbec906106e1',
qptKDiv9uPl: 'ec42d68d-3e23-43de-b8c5-a03bb538e7c7',
KSBMR1BDGwx: '1a8bf24f-4f36-4971-aad9-ae77f3525738',
WDY6MkQWyHb: '722dd83a-c1cf-48ad-ac99-45ac131ccc96',
AuDPJg6gZE7: '82978311-bef9-46f9-9a9a-cc62254b00a6',
KeyiEPc4pII: '82978311-bef9-46f9-9a9a-cc62254b00a6',
qfYPXP76j8g: 'c3c86c1b-07be-4506-ab25-8f35f4389b19',
PCGI7EnvCQS: '45b39cbf-0fb2-4682-8544-8aaf3e07a744',
RnbiVrrSFdm: 'ee1b7973-e931-494e-a9cb-22b814b4d8ed',
CUdI1BJ5W8G: '92a92f62-3ff6-4944-9ea9-a7af23949bad',
YfcNA5bvkxT: '9a8204ca-d908-4157-9285-7c970dbb5287',
vC3bg9NwJ78: '3edcfddb-7988-4ce5-97a0-d4c46b267a04',
RqsvaPH9vHt: '22809b19-54ca-4d88-8d26-9577637c184e',
qacGXlyyQOS: 'a1a75011-0fef-460a-b666-dda2d171f39b',
S22iy8o0iLg: 'aae000c3-5242-4e3c-bd1f-7e922a6d3d34',
v0qFX0qv1tX: 'd5e3d927-f7ce-4fdd-ac4e-6ad0b510b608',
SsQqwDBGxjh: '54a9b20e-bce5-4d4a-8c9c-e0248a182586',
FLIlRjAwn4G: 'e0d4e006-85b5-41cb-8a21-e013b1978b8b',
JUabDHhT1wJ: 'c1a3ed2d-6d9a-453d-9d93-749164a76413',
DlqJSA5VApl: '8fb3bb7d-c935-4b57-8444-1b953470e109',
DMaLm9u4GCq: 'b87a93ff-a4a1-4601-b35d-1e42bfa7e194',
CLGnlnFqqnk: '0a0c70d2-2ba5-4cb3-941f-b4a9a4a7ec6d',
f64XCwzJW02: '41e68dee-a2a3-4e6c-9d96-53def5caff52',
YeaUNruqmca: '08cd4b4a-4b0b-4391-987b-b5b3d770d30f',
KjgDauY9v4J: 'e08d532b-e56c-43dc-b831-af705654d2dc',
pj5hIE6iyAR: 'e08d532b-e56c-43dc-b831-af705654d2dc',
pj5hIE6iyAR: 'e08d532b-e56c-43dc-b831-af705654d2dc',
W7cPAi8iXLZ: '819f79e7-b9af-4afd-85d4-2ab677223113',
MF3RML0HLbP: 'b2c5b6e0-66f0-4b9d-8576-b6f48e0a06df',
m8qis4iUOTo: '790b41ce-e1e7-11e8-b02f-0242ac130002',
// tsFOVnlc6lz: '5f3d618e-5c89-43bd-8c79-07e4e98c2f23',
// OZViJk8FPVd: 'c2664992-8a5a-4a6d-9238-5df591307d55',
};

return state;
});
107 changes: 0 additions & 107 deletions workflows/wf2/5-create-events.js

This file was deleted.

Loading

0 comments on commit e17ba94

Please sign in to comment.