diff --git a/openfn-69066751-5f2c-459c-b42e-feba1c802383-spec.yaml b/openfn-69066751-5f2c-459c-b42e-feba1c802383-spec.yaml index 8e6574b..522bc91 100644 --- a/openfn-69066751-5f2c-459c-b42e-feba1c802383-spec.yaml +++ b/openfn-69066751-5f2c-459c-b42e-feba1c802383-spec.yaml @@ -13,6 +13,9 @@ credentials: mtuchi@openfn.org-OpenMRS-Demo: name: OpenMRS Demo owner: mtuchi@openfn.org + "mtuchi@openfn.org-OpenMRS-Demo-(HTTP)": + name: 'OpenMRS Demo (HTTP)' + owner: mtuchi@openfn.org "mtuchi@openfn.org-googlesheets-(mtuchi@openfn.org)-2": name: 'googlesheets (mtuchi@openfn.org)-2' owner: mtuchi@openfn.org @@ -256,7 +259,7 @@ workflows: adaptor: '@openfn/language-googlesheets@latest' credential: null body: | - + getValues('1OuR7laA7Oc2QnoiT8S3Thhf-HNh7uFY8ILLEu-idXuk', 'optionsets_oct1') @@ -324,27 +327,28 @@ workflows: adaptor: '@openfn/language-http@latest' credential: null body: - path: 'workflows/wf1/1-fetch-metadata.js' + path: workflows/wf1/1-fetch-metadata.js + Get-Teis-and-Locations: name: Get Teis and Locations adaptor: '@openfn/language-dhis2@latest' credential: null body: - path: 'workflows/wf1/2-get-teis-and-locations.js' + path: workflows/wf1/2-get-teis-and-locations.js Create-Patients: name: Create Patients adaptor: '@openfn/language-openmrs@latest' credential: null body: - path: 'workflows/wf1/3-create-patients.js' + path: workflows/wf1/3-create-patients.js Update-Teis: name: Update Teis adaptor: '@openfn/language-dhis2@5.0.1' credential: null body: - path: 'workflows/wf1/4-update-teis.js' + path: workflows/wf1/4-update-teis.js triggers: cron: @@ -356,6 +360,15 @@ workflows: source_trigger: cron target_job: Fetch-Metadata condition_type: always + enabled: true + Get-Teis-and-Locations->Create-Patients: + source_job: Get-Teis-and-Locations + target_job: Create-Patients + condition_type: js_expression + condition_label: has-teis + condition_expression: | + state.teis.length > 0 && !state.errors + enabled: true Fetch-Metadata->Get-Teis-and-Locations: source_job: Fetch-Metadata @@ -366,15 +379,6 @@ workflows: source_job: Create-Patients target_job: Update-Teis condition_type: on_job_success - enabled: true - Get-Teis-and-Locations->Create-Patients: - source_job: Get-Teis-and-Locations - target_job: Create-Patients - condition_type: js_expression - condition_label: has-teis - condition_expression: | - state.teis.length > 0 && !state.errors - enabled: true wf2-omrs-dhis2: name: wf2-omrs-dhis2 @@ -395,8 +399,8 @@ workflows: Get-Encounters: name: Get Encounters - adaptor: '@openfn/language-openmrs@4.0.0' - credential: mtuchi@openfn.org-OpenMRS-Demo + adaptor: '@openfn/language-http@latest' + credential: 'mtuchi@openfn.org-OpenMRS-Demo-(HTTP)' body: path: workflows/wf2/3-get-encounters.js @@ -461,15 +465,6 @@ workflows: condition_expression: | state.patients.length > 0 && !state.errors - enabled: true - Create-Events->Update-TEIs: - source_job: Create-Events - target_job: Update-TEIs - condition_type: js_expression - condition_label: has-gender-updated - condition_expression: | - state?.genderUpdated?.length > 0 && !state.errors - enabled: true Get-TEIs->Create-Events: source_job: Get-TEIs @@ -479,6 +474,15 @@ workflows: condition_expression: | state.TEIs && !state.errors + enabled: true + Create-Events->Update-TEIs: + source_job: Create-Events + target_job: Update-TEIs + condition_type: js_expression + condition_label: has-gender-updated + condition_expression: | + state?.genderUpdated?.length > 0 && !state.errors + enabled: true Get-Encounters->Get-TEIs: source_job: Get-Encounters diff --git a/openfn-69066751-5f2c-459c-b42e-feba1c802383-state.json b/openfn-69066751-5f2c-459c-b42e-feba1c802383-state.json index a9af11c..0cf4e4f 100644 --- a/openfn-69066751-5f2c-459c-b42e-feba1c802383-state.json +++ b/openfn-69066751-5f2c-459c-b42e-feba1c802383-state.json @@ -34,42 +34,31 @@ "id": "113aca80-30f8-4137-a27b-f0d9be8b1910", "name": "AK Sharepoint", "owner": "aleksa@openfn.org" + }, + "mtuchi@openfn.org-OpenMRS-Demo-(HTTP)": { + "id": "dbf83c2e-f97d-4bc0-888a-7842b965ca21", + "name": "OpenMRS Demo (HTTP)", + "owner": "mtuchi@openfn.org" } }, "scheduled_deletion": null, "history_retention_period": null, "dataclip_retention_period": null, "retention_policy": "retain_all", + "requires_mfa": false, "workflows": { "fetch-metadata-and-generate-opts-json": { "id": "182c38b7-fa91-4bc3-82ed-ebd92e26be8f", "name": "fetch-metadata-and-generate-opts-json", - "edges": { - "Get-metadata-file-from-Sharepoint->Map-metadata-file-to-option-set-Json-format": { - "enabled": true, - "id": "4ec86a4d-17b0-447c-a816-42f1d95d7f25", - "source_job_id": "aab663a0-6bcc-42fa-9f53-146d8fa44061", - "condition_type": "on_job_success", - "target_job_id": "b5743b64-3250-4dbf-8d74-256a1c7e9623" - }, - "Map-metadata-file-to-option-set-Json-format->Save-option-set-json-to-github": { - "enabled": true, - "id": "820d203a-1e9c-494d-8fba-c7c962209de7", - "source_job_id": "b5743b64-3250-4dbf-8d74-256a1c7e9623", - "condition_type": "on_job_success", - "target_job_id": "b224b966-35f4-43ea-90e9-1f5dfcb56416" - }, - "webhook->Get-metadata-file-from-Sharepoint": { + "inserted_at": "2024-10-30T12:02:03.305779Z", + "lock_version": 1, + "triggers": { + "webhook": { "enabled": true, - "id": "441b595b-441a-4938-be44-be49c32f5cc4", - "source_trigger_id": "654e0bc2-22ae-4033-9090-18760ab28ea2", - "condition_type": "always", - "target_job_id": "aab663a0-6bcc-42fa-9f53-146d8fa44061" + "id": "654e0bc2-22ae-4033-9090-18760ab28ea2", + "type": "webhook" } }, - "concurrency": null, - "inserted_at": "2024-10-30T12:02:03Z", - "updated_at": "2024-10-30T12:02:03Z", "jobs": { "Get-metadata-file-from-Sharepoint": { "id": "aab663a0-6bcc-42fa-9f53-146d8fa44061", @@ -93,38 +82,42 @@ "project_credential_id": null } }, - "triggers": { - "webhook": { + "edges": { + "Get-metadata-file-from-Sharepoint->Map-metadata-file-to-option-set-Json-format": { "enabled": true, - "id": "654e0bc2-22ae-4033-9090-18760ab28ea2", - "type": "webhook" + "id": "4ec86a4d-17b0-447c-a816-42f1d95d7f25", + "source_job_id": "aab663a0-6bcc-42fa-9f53-146d8fa44061", + "condition_type": "on_job_success", + "target_job_id": "b5743b64-3250-4dbf-8d74-256a1c7e9623" + }, + "Map-metadata-file-to-option-set-Json-format->Save-option-set-json-to-github": { + "enabled": true, + "id": "820d203a-1e9c-494d-8fba-c7c962209de7", + "source_job_id": "b5743b64-3250-4dbf-8d74-256a1c7e9623", + "condition_type": "on_job_success", + "target_job_id": "b224b966-35f4-43ea-90e9-1f5dfcb56416" + }, + "webhook->Get-metadata-file-from-Sharepoint": { + "enabled": true, + "id": "441b595b-441a-4938-be44-be49c32f5cc4", + "source_trigger_id": "654e0bc2-22ae-4033-9090-18760ab28ea2", + "condition_type": "always", + "target_job_id": "aab663a0-6bcc-42fa-9f53-146d8fa44061" } - }, - "deleted_at": null, - "lock_version": 1 + } }, "wf-3-generate-optsmap": { "id": "c9d7d47a-5502-4f52-bc30-950746a8b473", "name": "wf-3-generate-optsmap", - "edges": { - "webhook->Fetch-OptionSets-Metadata": { - "enabled": true, - "id": "f0c1f4e9-2619-46da-b7d6-595bf8ea249a", - "source_trigger_id": "e62241ef-84ef-4ca7-9fec-c350e849390e", - "condition_type": "always", - "target_job_id": "ed90907f-3ba3-4a08-ae52-7425e584dae6" - }, - "Fetch-OptionSets-Metadata->Key-Value-Pair": { - "enabled": true, - "id": "fa1fc60a-b2b4-48ef-b4b4-a47eb93d58f6", - "source_job_id": "ed90907f-3ba3-4a08-ae52-7425e584dae6", - "condition_type": "on_job_success", - "target_job_id": "6f832249-fc16-4bab-8ed2-cbaa832611f0" + "inserted_at": "2024-10-30T12:02:03.315657Z", + "lock_version": 1, + "triggers": { + "webhook": { + "enabled": false, + "id": "e62241ef-84ef-4ca7-9fec-c350e849390e", + "type": "webhook" } }, - "concurrency": null, - "inserted_at": "2024-10-30T12:02:03Z", - "updated_at": "2024-10-30T12:02:03Z", "jobs": { "Fetch-OptionSets-Metadata": { "id": "ed90907f-3ba3-4a08-ae52-7425e584dae6", @@ -141,55 +134,36 @@ "project_credential_id": null } }, - "triggers": { - "webhook": { - "enabled": false, - "id": "e62241ef-84ef-4ca7-9fec-c350e849390e", - "type": "webhook" - } - }, - "deleted_at": null, - "lock_version": 1 - }, - "wf1-dhis2-omrs-migration": { - "id": "73fda9b2-2555-4764-b0f9-388a99583532", - "name": "wf1-dhis2-omrs-migration", "edges": { - "cron->Fetch-Metadata": { - "enabled": true, - "id": "85b3b59f-90c1-434a-a9a6-1c09dd86ccff", - "source_trigger_id": "f982cc7a-6c9e-4778-9a08-6ddf8469509d", - "condition_type": "always", - "target_job_id": "d7c373f4-a503-4fa6-bfdd-ab456860ae78" - }, - "Get-Teis-and-Locations->Create-Patients": { - "enabled": true, - "id": "c2122c54-8ddf-4ed1-9e6a-ff86adc4b7d8", - "source_job_id": "d30561c9-1e9d-467c-b37b-985bcdf1a55c", - "condition_expression": "state.teis.length > 0 && !state.errors\n", - "condition_type": "js_expression", - "condition_label": "has-teis", - "target_job_id": "fe6cdd41-491d-44fd-80af-0ac8891dd766" - }, - "Fetch-Metadata->Get-Teis-and-Locations": { + "Fetch-OptionSets-Metadata->Key-Value-Pair": { "enabled": true, - "id": "cfa7784e-6a3e-4f6f-8578-4dfb410f4a41", - "source_job_id": "d7c373f4-a503-4fa6-bfdd-ab456860ae78", - "condition_expression": "state.trackedEntityInstances.length > 0\n", + "id": "fa1fc60a-b2b4-48ef-b4b4-a47eb93d58f6", + "source_job_id": "ed90907f-3ba3-4a08-ae52-7425e584dae6", "condition_type": "on_job_success", - "target_job_id": "d30561c9-1e9d-467c-b37b-985bcdf1a55c" + "target_job_id": "6f832249-fc16-4bab-8ed2-cbaa832611f0" }, - "Create-Patients->Update-Teis": { + "webhook->Fetch-OptionSets-Metadata": { "enabled": true, - "id": "22aa79eb-9f8d-404d-9880-09c866470085", - "source_job_id": "fe6cdd41-491d-44fd-80af-0ac8891dd766", - "condition_type": "on_job_success", - "target_job_id": "df3ec9f2-6913-4742-8898-44734deed649" + "id": "f0c1f4e9-2619-46da-b7d6-595bf8ea249a", + "source_trigger_id": "e62241ef-84ef-4ca7-9fec-c350e849390e", + "condition_type": "always", + "target_job_id": "ed90907f-3ba3-4a08-ae52-7425e584dae6" + } + } + }, + "wf1-dhis2-omrs-migration": { + "id": "73fda9b2-2555-4764-b0f9-388a99583532", + "name": "wf1-dhis2-omrs-migration", + "inserted_at": "2024-11-07T07:35:48.656212Z", + "lock_version": 16, + "triggers": { + "cron": { + "enabled": false, + "id": "f982cc7a-6c9e-4778-9a08-6ddf8469509d", + "type": "cron", + "cron_expression": "0 0 * * *" } }, - "concurrency": null, - "inserted_at": "2024-10-30T12:02:03Z", - "updated_at": "2024-11-07T07:35:48Z", "jobs": { "Fetch-Metadata": { "id": "d7c373f4-a503-4fa6-bfdd-ab456860ae78", @@ -220,82 +194,53 @@ "project_credential_id": null } }, - "triggers": { - "cron": { - "enabled": false, - "id": "f982cc7a-6c9e-4778-9a08-6ddf8469509d", - "type": "cron", - "cron_expression": "0 0 * * *" - } - }, - "deleted_at": null, - "lock_version": 16 - }, - "wf2-omrs-dhis2": { - "id": "c886121c-0a91-45b5-ae30-7d0922b693be", - "name": "wf2-omrs-dhis2", "edges": { - "Get-Patients->Mappings": { - "enabled": true, - "id": "ff6aff74-ffd9-48cc-8441-94a77f847418", - "source_job_id": "ecaf53cc-fbde-4703-827b-7b8a5126fb82", - "condition_expression": "state.patients.length > 0 && !state.errors\n", - "condition_type": "js_expression", - "condition_label": "has-patients", - "target_job_id": "f022ca80-7da0-4fdb-9728-38e34280c516" - }, - "Get-TEIs->Create-Events": { - "enabled": true, - "id": "5384f7c8-7b38-44cd-8055-e3f6c46932e7", - "source_job_id": "793f4fe1-d717-4caa-a617-2b5e2b19880d", - "condition_expression": "state.TEIs && !state.errors\n", - "condition_type": "js_expression", - "condition_label": "has-teis", - "target_job_id": "a1176a6e-cdee-4ddc-9fe1-e49aa7b719cd" - }, - "Create-Events->Update-TEIs": { - "enabled": true, - "id": "63cd0a29-5d94-489e-9ba0-8a6690a555bc", - "source_job_id": "a1176a6e-cdee-4ddc-9fe1-e49aa7b719cd", - "condition_expression": "state?.genderUpdated?.length > 0 && !state.errors\n", - "condition_type": "js_expression", - "condition_label": "has-gender-updated", - "target_job_id": "abe0d282-5209-47b5-9272-4cba048a5ba8" - }, - "cron->Get-Patients": { + "cron->Fetch-Metadata": { "enabled": true, - "id": "60f8f83d-7e0d-402f-90ee-8d8d85488097", - "source_trigger_id": "a38c8cfb-8fad-46b3-b69c-a7f6108a0d8c", + "id": "85b3b59f-90c1-434a-a9a6-1c09dd86ccff", + "source_trigger_id": "f982cc7a-6c9e-4778-9a08-6ddf8469509d", "condition_type": "always", - "target_job_id": "ecaf53cc-fbde-4703-827b-7b8a5126fb82" + "target_job_id": "d7c373f4-a503-4fa6-bfdd-ab456860ae78" }, - "Upsert-TEIs->Get-Encounters": { + "Get-Teis-and-Locations->Create-Patients": { "enabled": true, - "id": "0075ae81-bef3-4fe9-969a-847f8bcde8fa", - "source_job_id": "5f3d2b64-435a-4df5-9d99-9fc37728d0b8", - "condition_expression": "state.patientUuids.length > 0 && !state.errors\n", + "id": "c2122c54-8ddf-4ed1-9e6a-ff86adc4b7d8", + "source_job_id": "d30561c9-1e9d-467c-b37b-985bcdf1a55c", + "condition_expression": "state.teis.length > 0 && !state.errors\n", "condition_type": "js_expression", - "condition_label": "has-patient-uuids", - "target_job_id": "a5c005be-2d95-4809-ad77-fd62f93dc976" + "condition_label": "has-teis", + "target_job_id": "fe6cdd41-491d-44fd-80af-0ac8891dd766" }, - "Mappings->Upsert-TEIs": { + "Fetch-Metadata->Get-Teis-and-Locations": { "enabled": true, - "id": "e45c7204-ae45-438f-ad71-4c663bc72850", - "source_job_id": "f022ca80-7da0-4fdb-9728-38e34280c516", + "id": "cfa7784e-6a3e-4f6f-8578-4dfb410f4a41", + "source_job_id": "d7c373f4-a503-4fa6-bfdd-ab456860ae78", + "condition_expression": "state.trackedEntityInstances.length > 0\n", "condition_type": "on_job_success", - "target_job_id": "5f3d2b64-435a-4df5-9d99-9fc37728d0b8" + "target_job_id": "d30561c9-1e9d-467c-b37b-985bcdf1a55c" }, - "Get-Encounters->Get-TEIs": { + "Create-Patients->Update-Teis": { "enabled": true, - "id": "2332a5e2-aa7b-4646-8193-958923e235f3", - "source_job_id": "a5c005be-2d95-4809-ad77-fd62f93dc976", + "id": "22aa79eb-9f8d-404d-9880-09c866470085", + "source_job_id": "fe6cdd41-491d-44fd-80af-0ac8891dd766", "condition_type": "on_job_success", - "target_job_id": "793f4fe1-d717-4caa-a617-2b5e2b19880d" + "target_job_id": "df3ec9f2-6913-4742-8898-44734deed649" + } + } + }, + "wf2-omrs-dhis2": { + "id": "c886121c-0a91-45b5-ae30-7d0922b693be", + "name": "wf2-omrs-dhis2", + "inserted_at": "2024-11-07T16:41:41.148511Z", + "lock_version": 29, + "triggers": { + "cron": { + "enabled": false, + "id": "a38c8cfb-8fad-46b3-b69c-a7f6108a0d8c", + "type": "cron", + "cron_expression": "0 0 * * *" } }, - "concurrency": null, - "inserted_at": "2024-10-30T12:02:03Z", - "updated_at": "2024-11-07T16:27:10Z", "jobs": { "Get-Patients": { "id": "ecaf53cc-fbde-4703-827b-7b8a5126fb82", @@ -315,8 +260,8 @@ "id": "a5c005be-2d95-4809-ad77-fd62f93dc976", "name": "Get Encounters", "body": "// Fetch all encounters\nget(\n '/ws/fhir2/R4/Encounter',\n { query: { _count: 100, _lastUpdated: `ge${$.cursor}` }, parseAs: 'json' },\n state => {\n const { link, total } = state.data;\n state.nextUrl = link\n .find(l => l.relation === 'next')\n ?.url.replace(/(_count=)\\d+/, `$1${total}`);\n\n state.allResponse = state.data;\n return state;\n }\n);\n\nfnIf(\n $.nextUrl,\n get($.nextUrl, { parseAs: 'json' }, state => {\n delete state.allResponse.link;\n state.allResponse.entry.push(...state.data.entry);\n console.log(state.allResponse.entry.length);\n return state;\n })\n);\n\nfn(state => {\n state.encounterUuids = state.allResponse.entry.map(p => p.resource.id);\n state.patientUuids = [\n ...new Set(\n state.allResponse.entry.map(p =>\n p.resource.subject.reference.replace('Patient/', '')\n )\n ),\n ];\n\n return state;\n});\n\n// Fetch patient encounters\neach(\n $.patientUuids,\n get(\n '/ws/rest/v1/encounter/',\n { query: { patient: $.data, v: 'full' }, parseAs: 'json' },\n state => {\n const patientUuid = state.references.at(-1);\n const filteredEncounters = state.formUuids.map(formUuid =>\n state.data.results.filter(\n e => e.encounterDatetime >= state.cursor && e?.form?.uuid === formUuid\n )\n );\n\n const encounters = filteredEncounters.map(e => e[0]).filter(e => e);\n state.encounters ??= [];\n state.encounters.push(...encounters);\n\n console.log(\n encounters.length,\n `# of filtered encounters found in OMRS for ${patientUuid}`\n );\n\n return state;\n }\n )\n);\n\n// Log filtered encounters\nfn(state => {\n const {\n data,\n index,\n response,\n references,\n allResponse,\n patientUuids,\n ...next\n } = state;\n console.log(next.encounters.length, '# of new encounters to sync to dhis2');\n\n return next;\n});\n", - "adaptor": "@openfn/language-openmrs@4.0.0", - "project_credential_id": "45634fcb-d146-4a0f-930c-77300393a3c2" + "adaptor": "@openfn/language-http@latest", + "project_credential_id": "dbf83c2e-f97d-4bc0-888a-7842b965ca21" }, "Get-TEIs": { "id": "793f4fe1-d717-4caa-a617-2b5e2b19880d", @@ -347,17 +292,65 @@ "project_credential_id": "9716980f-1b35-4295-adde-b05bc47002da" } }, - "triggers": { - "cron": { - "enabled": false, - "id": "a38c8cfb-8fad-46b3-b69c-a7f6108a0d8c", - "type": "cron", - "cron_expression": "0 0 * * *" + "edges": { + "cron->Get-Patients": { + "enabled": true, + "id": "60f8f83d-7e0d-402f-90ee-8d8d85488097", + "source_trigger_id": "a38c8cfb-8fad-46b3-b69c-a7f6108a0d8c", + "condition_type": "always", + "target_job_id": "ecaf53cc-fbde-4703-827b-7b8a5126fb82" + }, + "Upsert-TEIs->Get-Encounters": { + "enabled": true, + "id": "0075ae81-bef3-4fe9-969a-847f8bcde8fa", + "source_job_id": "5f3d2b64-435a-4df5-9d99-9fc37728d0b8", + "condition_expression": "state.patientUuids.length > 0 && !state.errors\n", + "condition_type": "js_expression", + "condition_label": "has-patient-uuids", + "target_job_id": "a5c005be-2d95-4809-ad77-fd62f93dc976" + }, + "Mappings->Upsert-TEIs": { + "enabled": true, + "id": "e45c7204-ae45-438f-ad71-4c663bc72850", + "source_job_id": "f022ca80-7da0-4fdb-9728-38e34280c516", + "condition_type": "on_job_success", + "target_job_id": "5f3d2b64-435a-4df5-9d99-9fc37728d0b8" + }, + "Get-Patients->Mappings": { + "enabled": true, + "id": "ff6aff74-ffd9-48cc-8441-94a77f847418", + "source_job_id": "ecaf53cc-fbde-4703-827b-7b8a5126fb82", + "condition_expression": "state.patients.length > 0 && !state.errors\n", + "condition_type": "js_expression", + "condition_label": "has-patients", + "target_job_id": "f022ca80-7da0-4fdb-9728-38e34280c516" + }, + "Get-TEIs->Create-Events": { + "enabled": true, + "id": "5384f7c8-7b38-44cd-8055-e3f6c46932e7", + "source_job_id": "793f4fe1-d717-4caa-a617-2b5e2b19880d", + "condition_expression": "state.TEIs && !state.errors\n", + "condition_type": "js_expression", + "condition_label": "has-teis", + "target_job_id": "a1176a6e-cdee-4ddc-9fe1-e49aa7b719cd" + }, + "Create-Events->Update-TEIs": { + "enabled": true, + "id": "63cd0a29-5d94-489e-9ba0-8a6690a555bc", + "source_job_id": "a1176a6e-cdee-4ddc-9fe1-e49aa7b719cd", + "condition_expression": "state?.genderUpdated?.length > 0 && !state.errors\n", + "condition_type": "js_expression", + "condition_label": "has-gender-updated", + "target_job_id": "abe0d282-5209-47b5-9272-4cba048a5ba8" + }, + "Get-Encounters->Get-TEIs": { + "enabled": true, + "id": "2332a5e2-aa7b-4646-8193-958923e235f3", + "source_job_id": "a5c005be-2d95-4809-ad77-fd62f93dc976", + "condition_type": "on_job_success", + "target_job_id": "793f4fe1-d717-4caa-a617-2b5e2b19880d" } - }, - "deleted_at": null, - "lock_version": 20 + } } - }, - "requires_mfa": false + } } \ No newline at end of file