-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2ecd0f
commit e3b9bd8
Showing
3 changed files
with
316 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,155 @@ | ||
name: cdr-ndr | ||
# description: | ||
# credentials: | ||
# globals: | ||
workflows: | ||
cdr-to-ndr: | ||
name: cdr-to-ndr | ||
jobs: | ||
Analyze-Data: | ||
name: Analyze Data | ||
adaptor: '@openfn/language-common@latest' | ||
# credential: | ||
# globals: | ||
body: | | ||
fn(state => { | ||
const parsedData = JSON.parse(state.data.body); | ||
console.log(parsedData); | ||
state.resource = parsedData.entry[0].resource; | ||
console.log('show only the resource:: ', state.resource); | ||
return state; | ||
}) | ||
Clean-data-and-PII: | ||
name: Clean data and PII | ||
adaptor: '@openfn/language-common@latest' | ||
# credential: | ||
# globals: | ||
body: | | ||
fn(state=> { | ||
//Removig PII here before sending it to NDR | ||
delete state.resource.name; | ||
delete state.resource.telecom; | ||
delete state.resource.contact; | ||
delete state.resource.extension; //contains religion, occupation, education level, target pop group | ||
delete state.resource.maritalStatus; | ||
//only keeping birthdate and gender | ||
return state; | ||
}) | ||
Map-Data: | ||
name: Map Data | ||
adaptor: '@openfn/language-common@latest' | ||
# credential: | ||
# globals: | ||
body: | | ||
fn(state=> { | ||
//Map CDR data to NDR FHIR IG | ||
const cdrData = state.resource; | ||
var mapped_resource = { | ||
resourceType: cdrData.resourceType, | ||
id: cdrData.id, | ||
identifier: cdrData.identifier?.map(id => ({ | ||
type: id.system == "http://cdr.aacahb.gov.et/MRN"? { | ||
"coding": [ | ||
{ | ||
"code": "MR", | ||
"display": "Medical record number", | ||
"system": "http://terminology.hl7.org/CodeSystem/v2-0203" | ||
} | ||
], | ||
"text": "Medical record number" | ||
} : undefined, | ||
system: id.system, | ||
value: id.value, | ||
})), | ||
active: cdrData.active, | ||
gender: cdrData.gender, | ||
birthDate: cdrData.birthDate, | ||
address: cdrData.address, | ||
managingOrganization: cdrData.managingOrganization, | ||
deceasedBoolean: cdrData.deceasedBoolean, | ||
text: cdrData.text | ||
}; | ||
// mapped_resource = {} | ||
// returned the mapped fhir resource | ||
return {...state, mapped_resource} | ||
}) | ||
Create-FHIR-Resource: | ||
name: Create FHIR Resource | ||
adaptor: '@openfn/language-http@latest' | ||
# credential: | ||
# globals: | ||
body: | | ||
post($.resource.resourceType, | ||
{ | ||
body: $.mapped_resource, | ||
errors: { 400: false }, | ||
headers: {'content-type': 'application/json'}, | ||
parseAs: 'json' | ||
}, | ||
state => { | ||
state.data.response = state.response; | ||
return state; | ||
}) | ||
Log-Error: | ||
name: Log Error | ||
adaptor: '@openfn/language-postgresql@latest' | ||
# credential: | ||
# globals: | ||
body: | | ||
fn(state => { | ||
state.errorLog = { | ||
resource_id: state.data.id, | ||
resource_type: state.references[0].resourceType, | ||
issue_code: state.data.issue[0].code, | ||
issue_detail: state.data.issue[0].details.text, | ||
issue_diagnostics: state.data.issue[0].diagnostics, | ||
issue_location: state.data.issue[0].location, | ||
last_updated: state.data.meta.lastUpdated, | ||
status_code: state.data.response.statusCode, | ||
status_message: state.data.response.statusMessage, | ||
failure_type: 'validation error', | ||
//data: state.references[0], //data we tried to create | ||
} | ||
console.log('Error to log:: ', JSON.stringify(state.errorLog,null,2)); | ||
return state; | ||
}); | ||
insert('errors', | ||
state => state.errorLog, | ||
{ logValues: true } | ||
); | ||
triggers: | ||
webhook: | ||
type: webhook | ||
enabled: true | ||
edges: | ||
webhook->Analyze-Data: | ||
source_trigger: webhook | ||
target_job: Analyze-Data | ||
condition_type: always | ||
enabled: true | ||
Analyze-Data->Clean-data-and-PII: | ||
source_job: Analyze-Data | ||
target_job: Clean-data-and-PII | ||
condition_type: on_job_success | ||
enabled: true | ||
Clean-data-and-PII->Map-Data: | ||
source_job: Clean-data-and-PII | ||
target_job: Map-Data | ||
condition_type: on_job_success | ||
enabled: true | ||
Create-FHIR-Resource->Log-Error: | ||
source_job: Create-FHIR-Resource | ||
target_job: Log-Error | ||
condition_type: js_expression | ||
condition_label: failed? | ||
condition_expression: state.data.response.statusCode==400 | ||
enabled: true | ||
Map-Data->Create-FHIR-Resource: | ||
source_job: Map-Data | ||
target_job: Create-FHIR-Resource | ||
condition_type: on_job_success | ||
enabled: true |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"specPath": "cdr-ndr.yaml", | ||
"statePath": "state.json", | ||
"apiKey": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJKb2tlbiIsImlhdCI6MTY4ODAzNzE4NSwiaXNzIjoiSm9rZW4iLCJqdGkiOiIydG1ocG8zYm0xdmR0MDZvZDgwMDAwdTEiLCJuYmYiOjE2ODgwMzcxODUsInVzZXJfaWQiOiIzZjM3OGU2Yy02NjBhLTRiOTUtYWI5Ni02YmQwZGMyNjNkMzMifQ.J1FnACGpqtQbmXNvyUCwCY4mS5S6CohRU3Ey-N0prP4", | ||
"endpoint": "http://openfn:4000" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,155 @@ | ||
name: cdr-ndr | ||
# description: | ||
# credentials: | ||
# globals: | ||
workflows: | ||
cdr-to-ndr: | ||
name: cdr-to-ndr | ||
jobs: | ||
Analyze-Data: | ||
name: Analyze Data | ||
adaptor: '@openfn/language-common@latest' | ||
# credential: | ||
# globals: | ||
body: | | ||
fn(state => { | ||
const parsedData = JSON.parse(state.data.body); | ||
console.log(parsedData); | ||
state.resource = parsedData.entry[0].resource; | ||
console.log('show only the resource:: ', state.resource); | ||
return state; | ||
}) | ||
Clean-data-and-PII: | ||
name: Clean data and PII | ||
adaptor: '@openfn/language-common@latest' | ||
# credential: | ||
# globals: | ||
body: | | ||
fn(state=> { | ||
//Removig PII here before sending it to NDR | ||
delete state.resource.name; | ||
delete state.resource.telecom; | ||
delete state.resource.contact; | ||
delete state.resource.extension; //contains religion, occupation, education level, target pop group | ||
delete state.resource.maritalStatus; | ||
//only keeping birthdate and gender | ||
return state; | ||
}) | ||
Map-Data: | ||
name: Map Data | ||
adaptor: '@openfn/language-common@latest' | ||
# credential: | ||
# globals: | ||
body: | | ||
fn(state=> { | ||
//Map CDR data to NDR FHIR IG | ||
const cdrData = state.resource; | ||
var mapped_resource = { | ||
resourceType: cdrData.resourceType, | ||
id: cdrData.id, | ||
identifier: cdrData.identifier?.map(id => ({ | ||
type: id.system == "http://cdr.aacahb.gov.et/MRN"? { | ||
"coding": [ | ||
{ | ||
"code": "MR", | ||
"display": "Medical record number", | ||
"system": "http://terminology.hl7.org/CodeSystem/v2-0203" | ||
} | ||
], | ||
"text": "Medical record number" | ||
} : undefined, | ||
system: id.system, | ||
value: id.value, | ||
})), | ||
active: cdrData.active, | ||
gender: cdrData.gender, | ||
birthDate: cdrData.birthDate, | ||
address: cdrData.address, | ||
managingOrganization: cdrData.managingOrganization, | ||
deceasedBoolean: cdrData.deceasedBoolean, | ||
text: cdrData.text | ||
}; | ||
// mapped_resource = {} | ||
// returned the mapped fhir resource | ||
return {...state, mapped_resource} | ||
}) | ||
Create-FHIR-Resource: | ||
name: Create FHIR Resource | ||
adaptor: '@openfn/language-http@latest' | ||
# credential: | ||
# globals: | ||
body: | | ||
post($.resource.resourceType, | ||
{ | ||
body: $.mapped_resource, | ||
errors: { 400: false }, | ||
headers: {'content-type': 'application/json'}, | ||
parseAs: 'json' | ||
}, | ||
state => { | ||
state.data.response = state.response; | ||
return state; | ||
}) | ||
Log-Error: | ||
name: Log Error | ||
adaptor: '@openfn/language-postgresql@latest' | ||
# credential: | ||
# globals: | ||
body: | | ||
fn(state => { | ||
state.errorLog = { | ||
resource_id: state.data.id, | ||
resource_type: state.references[0].resourceType, | ||
issue_code: state.data.issue[0].code, | ||
issue_detail: state.data.issue[0].details.text, | ||
issue_diagnostics: state.data.issue[0].diagnostics, | ||
issue_location: state.data.issue[0].location, | ||
last_updated: state.data.meta.lastUpdated, | ||
status_code: state.data.response.statusCode, | ||
status_message: state.data.response.statusMessage, | ||
failure_type: 'validation error', | ||
//data: state.references[0], //data we tried to create | ||
} | ||
console.log('Error to log:: ', JSON.stringify(state.errorLog,null,2)); | ||
return state; | ||
}); | ||
insert('errors', | ||
state => state.errorLog, | ||
{ logValues: true } | ||
); | ||
triggers: | ||
webhook: | ||
type: webhook | ||
enabled: true | ||
edges: | ||
webhook->Analyze-Data: | ||
source_trigger: webhook | ||
target_job: Analyze-Data | ||
condition_type: always | ||
enabled: true | ||
Analyze-Data->Clean-data-and-PII: | ||
source_job: Analyze-Data | ||
target_job: Clean-data-and-PII | ||
condition_type: on_job_success | ||
enabled: true | ||
Clean-data-and-PII->Map-Data: | ||
source_job: Clean-data-and-PII | ||
target_job: Map-Data | ||
condition_type: on_job_success | ||
enabled: true | ||
Create-FHIR-Resource->Log-Error: | ||
source_job: Create-FHIR-Resource | ||
target_job: Log-Error | ||
condition_type: js_expression | ||
condition_label: failed? | ||
condition_expression: state.data.response.statusCode==400 | ||
enabled: true | ||
Map-Data->Create-FHIR-Resource: | ||
source_job: Map-Data | ||
target_job: Create-FHIR-Resource | ||
condition_type: on_job_success | ||
enabled: true |