generated from OpenFn/project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
user [email protected] initiated a sync from Lightning
- Loading branch information
1 parent
06b17f1
commit d39dd13
Showing
2 changed files
with
180 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,121 @@ | ||
name: cht-sandbox | ||
description: null | ||
credentials: null | ||
credentials: | ||
[email protected]: | ||
name: DHIS2 2-40-6 | ||
owner: [email protected] | ||
[email protected]: | ||
name: DHIS2 Dev | ||
owner: [email protected] | ||
workflows: | ||
CHT-webhook: | ||
name: CHT webhook | ||
jobs: | ||
DHIS2-mapping: | ||
name: DHIS2 mapping | ||
adaptor: '@openfn/language-common@latest' | ||
credential: null | ||
body: | | ||
const facilities = { | ||
"712526f6-f826-45a7-a80b-6546ad9fde9d": "DiszpKrYNg8", //corresponding_on_DHIS2, | ||
}; | ||
const convertToBool = (val) => { | ||
if (typeof val === 'boolean') return val; | ||
if (typeof val === 'string') { | ||
val = val.toLowerCase().trim(); | ||
return val === '1' || val === 'true' || val === 'yes'; | ||
} | ||
return !!val; | ||
}; | ||
const safeGet = (obj, path, defaultValue = undefined) => { | ||
return path.split('.').reduce((acc, part) => acc && acc[part], obj) ?? defaultValue; | ||
}; | ||
const genderMap = (value) => { | ||
if (!value) return undefined; | ||
return value.toLowerCase().trim().startsWith('f') ? 'Female' : 'Male'; | ||
}; | ||
const convertToNumeric = (value) => { | ||
return value | ||
} | ||
const mapReport = (report) => { | ||
const dataElements = [ | ||
// { dataElement: "EuiLnVQP7fz", path: 'fever_detected' }, | ||
// { dataElement: "c7DB86yPCPw", path: 'danger_signs' }, | ||
// { dataElement: "pUQ3PxCLBGW", path: 'symptoms_severity_level' }, | ||
// { dataElement: "UkSorKPBQKp", path: 'd_diarrhoea' }, | ||
{ dataElement: "mQfnNz6HAxg", path: "properties.d_disease_severe_malaria_possible" }, | ||
{ dataElement: "rUiCXLuXe0D", path: "data.closed.doc.fields.g_registration.p_id" }, | ||
{ dataElement: "L9FyeXeKysL", path: "properties.p_gender", transform: genderMap }, | ||
{ dataElement: "sRViHZrNOOi", path: "properties.p_age" }, | ||
{ dataElement: "zWAPsDC96SK", path: "properties.p_weight" }, | ||
{ dataElement: "nrsvTZKdAxD", path: "properties.p_temp" }, | ||
{ dataElement: "f8AiyAoBmQZ", path: "properties.d_pneumonia", transform: convertToBool }, | ||
{ dataElement: "nOqH46e5VmP", path: "data.closed.doc.d_malaria" }, | ||
{ dataElement: "S6XCvAD6uv6", path: "properties.d_scabies_infected", transform: convertToBool }, | ||
{ dataElement: "Vg8aEzNouYb", path: "properties.d_measles", transform: convertToBool }, | ||
{ dataElement: "Ofyvm4Ynqh7", path: "data.closed.doc.fields.ds_amoxicillin" }, | ||
{ dataElement: "EijcDbR4oWL", path: "data.closed.doc.fields.ds_paracetamol", transform: convertToNumeric }, | ||
{ dataElement: "DsiPa2sGoEe", path: "data.closed.doc.fields.ds_erythromycin" }, | ||
{ dataElement: "xpWPRlZlN7b", path: "data.closed.doc.fields.d_deworming_needed", transform: convertToBool }, | ||
{ dataElement: "tgUaWBaAIag", path: "data.closed.doc.fields.dur_amoxicillin" }, | ||
]; | ||
return { | ||
dataValues: dataElements.map(({ dataElement, path, transform }) => ({ | ||
dataElement, | ||
value: transform ? transform(safeGet(report, path)) : safeGet(report, path), | ||
})), | ||
notes: [{ | ||
value: safeGet(report, 'data.closed.doc.contact.notes'), | ||
storedBy: safeGet(report, 'data.closed.doc.contact.name'), | ||
storedDate: report.reported_date, | ||
}], | ||
}; | ||
}; | ||
fn((state) => { | ||
const { report } = state.data; | ||
state.dhis2Mapping = { | ||
orgUnit: "DiszpKrYNg8", | ||
occurredAt: report.reported_date, | ||
programStage: "", | ||
program: "wNRmGnc1t11", | ||
status: "COMPLETED", | ||
...mapReport(report) | ||
}; | ||
console.log(state.dhis2Mapping); | ||
return state; | ||
}); | ||
Create-Event-Program: | ||
name: Create Event Program | ||
adaptor: '@openfn/language-dhis2@latest' | ||
credential: [email protected] | ||
body: | | ||
// Create events | ||
create("events", $.dhis2Mapping); | ||
triggers: | ||
webhook: | ||
type: webhook | ||
enabled: true | ||
edges: | ||
webhook->DHIS2-mapping: | ||
source_trigger: webhook | ||
target_job: DHIS2-mapping | ||
condition_type: always | ||
enabled: true | ||
DHIS2-mapping->Create-Event-Program: | ||
source_job: DHIS2-mapping | ||
target_job: Create-Event-Program | ||
condition_type: on_job_success | ||
enabled: true | ||
Sample-Workflow: | ||
name: Sample Workflow | ||
jobs: | ||
|
@@ -26,7 +140,7 @@ workflows: | |
Load-to-DHIS2: | ||
name: Load to DHIS2 | ||
adaptor: '@openfn/language-dhis2@latest' | ||
credential: null | ||
credential: [email protected] | ||
body: | | ||
// Check out the Job Writing Guide for help getting started: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,19 +3,29 @@ | |
"name": "cht-sandbox", | ||
"description": null, | ||
"inserted_at": "2024-11-07T11:32:07Z", | ||
"updated_at": "2024-11-07T11:32:07Z", | ||
"project_credentials": {}, | ||
"updated_at": "2024-11-28T12:41:57Z", | ||
"scheduled_deletion": null, | ||
"history_retention_period": null, | ||
"project_credentials": { | ||
"[email protected]": { | ||
"id": "929e63c8-77d0-4859-85d0-e138fabbb963", | ||
"name": "DHIS2 Dev", | ||
"owner": "[email protected]" | ||
}, | ||
"[email protected]": { | ||
"id": "752324bf-1765-4b45-8bdc-478317f8b362", | ||
"name": "DHIS2 2-40-6", | ||
"owner": "[email protected]" | ||
} | ||
}, | ||
"history_retention_period": 365, | ||
"dataclip_retention_period": null, | ||
"retention_policy": "retain_all", | ||
"requires_mfa": false, | ||
"workflows": { | ||
"Sample-Workflow": { | ||
"id": "c80ea84e-4a5b-44db-b863-9305d5e225e2", | ||
"name": "Sample Workflow", | ||
"inserted_at": "2024-11-07T12:49:44.252128Z", | ||
"lock_version": 2, | ||
"inserted_at": "2024-12-01T19:03:34.011860Z", | ||
"lock_version": 3, | ||
"triggers": { | ||
"cron": { | ||
"enabled": true, | ||
|
@@ -44,7 +54,7 @@ | |
"name": "Load to DHIS2", | ||
"body": "\n// Check out the Job Writing Guide for help getting started:\n// https://docs.openfn.org/documentation/jobs/job-writing-guide\n", | ||
"adaptor": "@openfn/language-dhis2@latest", | ||
"project_credential_id": null | ||
"project_credential_id": "929e63c8-77d0-4859-85d0-e138fabbb963" | ||
} | ||
}, | ||
"edges": { | ||
|
@@ -70,6 +80,52 @@ | |
"target_job_id": "9af97a93-22c5-4bf4-8f69-86ac2d6e6af7" | ||
} | ||
} | ||
}, | ||
"CHT-webhook": { | ||
"id": "6cdd641d-6087-414b-8193-d01d71d3240e", | ||
"name": "CHT webhook", | ||
"inserted_at": "2024-12-18T18:19:49.271343Z", | ||
"lock_version": 46, | ||
"triggers": { | ||
"webhook": { | ||
"enabled": true, | ||
"id": "7bf6c1bc-f16f-40c0-89a5-184ae6ae742f", | ||
"type": "webhook" | ||
} | ||
}, | ||
"jobs": { | ||
"DHIS2-mapping": { | ||
"id": "0f2bd9fa-1f44-4152-8c0c-9fbca0e75f04", | ||
"name": "DHIS2 mapping", | ||
"body": "const facilities = {\n \"712526f6-f826-45a7-a80b-6546ad9fde9d\": \"DiszpKrYNg8\", //corresponding_on_DHIS2,\n};\n\nconst convertToBool = (val) => {\n if (typeof val === 'boolean') return val;\n if (typeof val === 'string') {\n val = val.toLowerCase().trim();\n return val === '1' || val === 'true' || val === 'yes';\n }\n return !!val;\n};\n\nconst safeGet = (obj, path, defaultValue = undefined) => {\n return path.split('.').reduce((acc, part) => acc && acc[part], obj) ?? defaultValue;\n};\n\nconst genderMap = (value) => {\n if (!value) return undefined;\n return value.toLowerCase().trim().startsWith('f') ? 'Female' : 'Male';\n};\n\nconst convertToNumeric = (value) => {\n return value\n}\n\nconst mapReport = (report) => {\n const dataElements = [\n // { dataElement: \"EuiLnVQP7fz\", path: 'fever_detected' },\n // { dataElement: \"c7DB86yPCPw\", path: 'danger_signs' },\n // { dataElement: \"pUQ3PxCLBGW\", path: 'symptoms_severity_level' },\n // { dataElement: \"UkSorKPBQKp\", path: 'd_diarrhoea' },\n { dataElement: \"mQfnNz6HAxg\", path: \"properties.d_disease_severe_malaria_possible\" },\n { dataElement: \"rUiCXLuXe0D\", path: \"data.closed.doc.fields.g_registration.p_id\" },\n { dataElement: \"L9FyeXeKysL\", path: \"properties.p_gender\", transform: genderMap },\n { dataElement: \"sRViHZrNOOi\", path: \"properties.p_age\" },\n { dataElement: \"zWAPsDC96SK\", path: \"properties.p_weight\" },\n { dataElement: \"nrsvTZKdAxD\", path: \"properties.p_temp\" },\n { dataElement: \"f8AiyAoBmQZ\", path: \"properties.d_pneumonia\", transform: convertToBool },\n { dataElement: \"nOqH46e5VmP\", path: \"data.closed.doc.d_malaria\" },\n { dataElement: \"S6XCvAD6uv6\", path: \"properties.d_scabies_infected\", transform: convertToBool },\n { dataElement: \"Vg8aEzNouYb\", path: \"properties.d_measles\", transform: convertToBool },\n { dataElement: \"Ofyvm4Ynqh7\", path: \"data.closed.doc.fields.ds_amoxicillin\" },\n { dataElement: \"EijcDbR4oWL\", path: \"data.closed.doc.fields.ds_paracetamol\", transform: convertToNumeric },\n { dataElement: \"DsiPa2sGoEe\", path: \"data.closed.doc.fields.ds_erythromycin\" },\n { dataElement: \"xpWPRlZlN7b\", path: \"data.closed.doc.fields.d_deworming_needed\", transform: convertToBool },\n { dataElement: \"tgUaWBaAIag\", path: \"data.closed.doc.fields.dur_amoxicillin\" },\n ];\n\n return {\n dataValues: dataElements.map(({ dataElement, path, transform }) => ({\n dataElement,\n value: transform ? transform(safeGet(report, path)) : safeGet(report, path),\n })),\n notes: [{\n value: safeGet(report, 'data.closed.doc.contact.notes'),\n storedBy: safeGet(report, 'data.closed.doc.contact.name'),\n storedDate: report.reported_date,\n }],\n };\n};\n\nfn((state) => {\n const { report } = state.data;\n\n state.dhis2Mapping = {\n orgUnit: \"DiszpKrYNg8\",\n occurredAt: report.reported_date,\n programStage: \"\",\n program: \"wNRmGnc1t11\",\n status: \"COMPLETED\",\n ...mapReport(report)\n };\n\n console.log(state.dhis2Mapping);\n return state;\n});\n", | ||
"adaptor": "@openfn/language-common@latest", | ||
"project_credential_id": null | ||
}, | ||
"Create-Event-Program": { | ||
"id": "5c26c910-7f0d-4cd7-8a71-22eba3d5db3c", | ||
"name": "Create Event Program", | ||
"body": "// Create events\ncreate(\"events\", $.dhis2Mapping);", | ||
"adaptor": "@openfn/language-dhis2@latest", | ||
"project_credential_id": "752324bf-1765-4b45-8bdc-478317f8b362" | ||
} | ||
}, | ||
"edges": { | ||
"webhook->DHIS2-mapping": { | ||
"enabled": true, | ||
"id": "a80a7125-32af-4159-8684-d014c07e6cfd", | ||
"source_trigger_id": "7bf6c1bc-f16f-40c0-89a5-184ae6ae742f", | ||
"condition_type": "always", | ||
"target_job_id": "0f2bd9fa-1f44-4152-8c0c-9fbca0e75f04" | ||
}, | ||
"DHIS2-mapping->Create-Event-Program": { | ||
"enabled": true, | ||
"id": "bc96b14e-af1e-48d8-884a-51d2fc018684", | ||
"source_job_id": "0f2bd9fa-1f44-4152-8c0c-9fbca0e75f04", | ||
"condition_type": "on_job_success", | ||
"target_job_id": "5c26c910-7f0d-4cd7-8a71-22eba3d5db3c" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"requires_mfa": false | ||
} |