From 718a4898bd217a8d2e97927d03a3296010ca195c Mon Sep 17 00:00:00 2001 From: Piotr Mankowski Date: Sun, 22 May 2022 22:31:03 -0700 Subject: [PATCH] Fixes and updates for BW IPMS lab workflows (#53) * Updates * Fix * Small translation fix --- config/config_docker.json | 8 +-- config/config_test.json | 2 +- debug.docker-compose.yml | 3 +- package.json | 2 +- src/workflows/hl7WorkflowsBw.ts | 2 +- src/workflows/labWorkflowsBw.ts | 103 +++++++++++++++++--------------- 6 files changed, 64 insertions(+), 56 deletions(-) diff --git a/config/config_docker.json b/config/config_docker.json index 89e0ab4..e12f80f 100644 --- a/config/config_docker.json +++ b/config/config_docker.json @@ -30,14 +30,14 @@ "pimsSystemUrl": "https://api.openconceptlab.org/orgs/B-TECHBW/sources/PIMS-LAB-TEST-DICT/", "omangSystemUrl": "http://moh.bw.org/ext/identifier/omang", "oclUrl": "https://api.openconceptlab.org", - "requestTimeout": 5000, + "requestTimeout": 10000, "toIpmsAdtTemplate": "ADT_A04_TO_IPMS.hbs", "fromIpmsAdtTemplate": "ADT_A04_FROM_IPMS.hbs", "toIpmsOrmTemplate": "ORM_O01_TO_IPMS.hbs", - "fromIpmsOruTemplate": "ORU_R01_FROM_IPMS", + "fromIpmsOruTemplate": "ORU_R01_FROM_IPMS.hbs", "mllp": { - "targetIp": "shr", - "targetPort": 3001 + "targetIp": "172.17.0.1", + "targetPort": 2100 } } } \ No newline at end of file diff --git a/config/config_test.json b/config/config_test.json index 89e0ab4..fcbb4b6 100644 --- a/config/config_test.json +++ b/config/config_test.json @@ -34,7 +34,7 @@ "toIpmsAdtTemplate": "ADT_A04_TO_IPMS.hbs", "fromIpmsAdtTemplate": "ADT_A04_FROM_IPMS.hbs", "toIpmsOrmTemplate": "ORM_O01_TO_IPMS.hbs", - "fromIpmsOruTemplate": "ORU_R01_FROM_IPMS", + "fromIpmsOruTemplate": "ORU_R01_FROM_IPMS.hbs", "mllp": { "targetIp": "shr", "targetPort": 3001 diff --git a/debug.docker-compose.yml b/debug.docker-compose.yml index 68739b0..6bd8dbd 100644 --- a/debug.docker-compose.yml +++ b/debug.docker-compose.yml @@ -20,13 +20,14 @@ services: - NODE_AUTH_TOKEN ports: - 3000:3000 + - 3001:3001 - '9229:9229' environment: - NODE_ENV=docker volumes: - ./config/config_docker.json:/app/config/config_docker.json # - ./config/mediator_ci.json:/app/config/mediator_docker.json - entrypoint: node --inspect-brk=0.0.0.0:9229 ./dist/app.js + entrypoint: node --inspect=0.0.0.0:9229 ./dist/app.js # tty: true # stdin_open: true # entrypoint: bash diff --git a/package.json b/package.json index f87ffa9..0179504 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "@b-techbw/mllp": ">=3.1.0", "@types/got": "^9.6.12", "acorn": ">=7.1.1", - "async": "^3.1.0", + "async": "^3.2.1", "axios": "^0.21.1", "cookie-parser": "^1.4.5", "damerau-levenshtein": "^1.0.5", diff --git a/src/workflows/hl7WorkflowsBw.ts b/src/workflows/hl7WorkflowsBw.ts index d26ac40..06cc2bc 100644 --- a/src/workflows/hl7WorkflowsBw.ts +++ b/src/workflows/hl7WorkflowsBw.ts @@ -79,7 +79,7 @@ export default class Hl7WorkflowsBw { headers: { 'content-type': 'text/plain', }, - body: hl7Message, + body: hl7Message.replace(/\r/g, '\n'), method: 'POST', https: { rejectUnauthorized: false, diff --git a/src/workflows/labWorkflowsBw.ts b/src/workflows/labWorkflowsBw.ts index 3bb3997..8326016 100644 --- a/src/workflows/labWorkflowsBw.ts +++ b/src/workflows/labWorkflowsBw.ts @@ -318,66 +318,73 @@ export class LabWorkflowsBw extends LabWorkflows { } public static async handleAdtFromIpms(registrationBundle: R4.IBundle): Promise { - let options = { - timeout: config.get('bwConfig:requestTimeout'), - searchParams: {}, - } + try { + let options = { + timeout: config.get('bwConfig:requestTimeout'), + searchParams: {}, + } - let patient: IPatient, omang: String - let patEntry = registrationBundle.entry!.find(entry => { - return entry.resource && entry.resource.resourceType == 'Patient' - }) + let patient: IPatient, omang: String + let patEntry = registrationBundle.entry!.find(entry => { + return entry.resource && entry.resource.resourceType == 'Patient' + }) - if (patEntry) { - patient = patEntry + if (patEntry) { + patient = patEntry - let omangEntry = patient.identifier?.find( - i => i.system && i.system == config.get('bwConfig:omangSystemUrl'), - ) + let omangEntry = patient.identifier?.find( + i => i.system && i.system == config.get('bwConfig:omangSystemUrl'), + ) - if (omangEntry) { - omang = omangEntry.value! - } else { - omang = '' - } + if (omangEntry) { + omang = omangEntry.value! + } else { + omang = '' + } - // Find all patients with this Omang. - options.searchParams = { - identifier: `${config.get('bwConfig:omangSystemUrl')}|${omang}`, - _revinclude: 'Task:patient', - } + // Find all patients with this Omang. + options.searchParams = { + identifier: `${config.get('bwConfig:omangSystemUrl')}|${omang}`, + _revinclude: 'Task:patient', + } - let patientTasks: IBundle - try { - patientTasks = await got.get(`${config.get('fhirServer:baseURL')}/Patient`, options).json() - } catch (e) { - patientTasks = { resourceType: 'Bundle' } - logger.error(e) - } + let patientTasks: IBundle + try { + patientTasks = await got + .get(`${config.get('fhirServer:baseURL')}/Patient`, options) + .json() + } catch (e) { + patientTasks = { resourceType: 'Bundle' } + logger.error(e) + } - if (patientTasks && patientTasks.entry) { - // Get all Tasks with `requested` status - for (const e of patientTasks.entry!) { - if ( - e.resource && - e.resource.resourceType == 'Task' && - e.resource.status == TaskStatusKind._requested - ) { - // Grab bundle for task: - options.searchParams = { - _include: '*', - _id: e.resource.id, + if (patientTasks && patientTasks.entry) { + // Get all Tasks with `requested` status + for (const e of patientTasks.entry!) { + if ( + e.resource && + e.resource.resourceType == 'Task' && + e.resource.status == TaskStatusKind._requested + ) { + // Grab bundle for task: + options.searchParams = { + _include: '*', + _id: e.resource.id, + } + + let taskBundle: IBundle = await got + .get(`${config.get('fhirServer:baseURL')}/Task`, options) + .json() + + sendPayload(taskBundle, topicList.SEND_ORM_TO_IPMS) } - - let taskBundle: IBundle = await got - .get(`${config.get('fhirServer:baseURL')}/Task`, options) - .json() - - sendPayload(taskBundle, topicList.SEND_ORM_TO_IPMS) } } } + } catch (e) { + logger.error(e) } + // let obrMessage = await Hl7WorkflowsBw.getFhirTranslation(labBundle, 'OBR.hbs') // let obrResult = await sender.send(obrMessage)