From 73d9757885c67a5bf6697394d41d05ea127c88be Mon Sep 17 00:00:00 2001 From: Piotr Mankowski Date: Tue, 4 Apr 2023 16:23:01 -0700 Subject: [PATCH] BW workflow HL7 translation updates (#2) * Fixes * ORM messaging updates and fixes * OCL path fix --- data/templates/fhir/ADT_A04_TO_IPMS.hbs | 4 +- data/templates/fhir/ORM_O01_TO_IPMS.hbs | 6 +- debug.docker-compose.yml | 4 +- deploy/debug.sh | 0 package.json | 2 +- src/lib/fhir/fhir.js | 91 +++++++++++++++++-------- 6 files changed, 70 insertions(+), 37 deletions(-) mode change 100644 => 100755 deploy/debug.sh diff --git a/data/templates/fhir/ADT_A04_TO_IPMS.hbs b/data/templates/fhir/ADT_A04_TO_IPMS.hbs index 98a61a03a..91d82a670 100644 --- a/data/templates/fhir/ADT_A04_TO_IPMS.hbs +++ b/data/templates/fhir/ADT_A04_TO_IPMS.hbs @@ -1,7 +1,7 @@ {{#with msg.fhir}} MSH|^~\&|DM||||{{date}}||ADT^A04|{{controlId}}|D|2.4|||AL|NE| EVN||{{date}}|||ZZHGGMMO^Healthpost^Mmopane|{{date}}| -PID|1||NEW||{{patientFamilyName}}^{{patientFirstName}}^^^^^F||{{patientDob}}|{{patientSex}}||CT|{{patientStreetAddress}}^^{{patientCity}}^{{patientProvince}}^{{patientPostalCode}}||{{patientHomePhoneNumber}}^^^{{patientEmail}}|{{patientBusinessPhoneNumber}}||{{patientMaritalStatus}}|AC||{{patientOmang}}| +PID|1||NEW||{{patientFamilyName}}^{{patientFirstName.[0]}}^^^^^F||{{patientDob}}|{{patientSex}}||CT|{{patientStreetAddress}}^^{{patientCity}}^{{patientProvince}}^{{patientPostalCode}}||{{patientHomePhoneNumber}}^^^{{patientEmail}}|{{patientBusinessPhoneNumber}}||{{patientMaritalStatus}}|AC||{{patientOmang}}| PV1|1|O|HGGMMO||||ZZHGGMMO^Healthpost^Mmopane^^^^^^^^^^XX|||||||||||POV||U|||||||||||||||||||GGC||REG|||{{date}}| -ROL|1|AD|AT|{{providerId}}^{{providerLastName}}^{{providerFirstName}}| +ROL|1|AD|AT|{{providerId}}^{{providerLastName}}^{{providerFirstName.[0]}}| {{/with}} diff --git a/data/templates/fhir/ORM_O01_TO_IPMS.hbs b/data/templates/fhir/ORM_O01_TO_IPMS.hbs index 03337f6c9..f4fed59bd 100644 --- a/data/templates/fhir/ORM_O01_TO_IPMS.hbs +++ b/data/templates/fhir/ORM_O01_TO_IPMS.hbs @@ -1,6 +1,6 @@ {{#with msg.fhir}} MSH|^~\&|LAB||LAB||{{date}}||ORM^O01|{{controlId}}|D|2.4|||AL|NE| -PID|1||{{medicalRecordNumber}}^^^^MR^GGC~{{patientOmang}}^^^^SS^GGC~{{patientIdentifier}}^^^^PI^GGC~{{unknownIdentifier}}^^^^HUB^GGC||{{patientLastName}}^{{patientFirstName}}^^^^^L||{{patientDoB}}|{{sex}}||CT|{{patientStreetAddress}}^^{{patientCity}}^{{patientProvince}}^{{patientPostalCode}}||{{patientBusinessPhoneNumber}}|||{{maritalStatus}}||{{patientAccountNumber}}| -ORC|NW|{{labOrderId}}^LAB|{{medicalRecordNumber}}||||^^^^^R||{{labOrderDatetime}}||| -OBR|1|{{labOrderId}}^LAB||{{labOrderType}}| +PID|1||{{medicalRecordNumber}}^^^^MR^GGC~{{patientOmang}}^^^^SS^GGC~{{patientIdentifier}}^^^^PI^GGC~{{unknownIdentifier}}^^^^HUB^GGC||{{patientFamilyName}}^{{patientFirstName.[0]}}^^^^^L||{{patientDoB}}|{{sex}}||CT|{{patientStreetAddress}}^^{{patientCity}}^{{patientProvince}}^{{patientPostalCode}}||{{patientBusinessPhoneNumber}}|||{{maritalStatus}}||{{patientAccountNumber}}| +ORC|NW|{{labOrderId}}^LAB|{{medicalRecordNumber}}||FINAL||^^^^^R^||{{labOrderDatetime}}||| +OBR|1|{{labOrderId}}^LAB||{{labOrderMnemonic}}^{{labOrderName}}|R|{{labOrderDatetime}}|{{labOrderDatetime}}|||||||^^|{{providerId}}^{{providerLastName}}^{{providerFirstName.[0]}}^^^^^|| {{/with}} \ No newline at end of file diff --git a/debug.docker-compose.yml b/debug.docker-compose.yml index ec78f788d..d99fc36c0 100644 --- a/debug.docker-compose.yml +++ b/debug.docker-compose.yml @@ -21,8 +21,8 @@ services: - 9229:9229 volumes: - ./config.json:/app/config.json - - ./data/templates:/app/data/service-templates - # entrypoint: ./deploy/debug.sh + - ./package.json:/app/package.json + entrypoint: /app/deploy/debug.sh networks: - hie # tty: true diff --git a/deploy/debug.sh b/deploy/debug.sh old mode 100644 new mode 100755 diff --git a/package.json b/package.json index 4fcb34d73..f26054cea 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "pretest": "node --experimental-worker dist/init-service.js", "prestart": "node --experimental-worker dist/init-service.js", "start": "node --experimental-worker dist/index.js", - "debug": "node --experimental-worker --inspect-brk=0.0.0.0:9229 dist/index.js", + "debug": "node --experimental-worker --inspect=0.0.0.0:9229 dist/index.js", "eslint": "eslint {src,test}/**/*.js" }, "eslintConfig": { diff --git a/src/lib/fhir/fhir.js b/src/lib/fhir/fhir.js index 500c99e8d..b6bfb7027 100644 --- a/src/lib/fhir/fhir.js +++ b/src/lib/fhir/fhir.js @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------------------------------------------- +const { now } = require("fp-ts/lib/Date"); const uuid_1 = require("uuid"); let dataHandler = require('../dataHandler/dataHandler'); @@ -50,26 +51,25 @@ module.exports = class fhir extends dataHandler { return super.getConversionResultMetadata(context); } + getResource(bundle, resourceName) { + try { + let entry = bundle.entry.find(e => e.resource.resourceType == resourceName) + return (entry && entry.resource) ? entry.resource : null + } catch (e) { + logger.error(`Can't get ${resourceName} from \n${JSON.stringify(bundle)}`) + return null + } + } + parseAdt(bundle) { let res = {}; - let patient = (bundle.entry.find(e => e.resource.resourceType == "Patient")).resource; - let provider = (bundle.entry.find(e => e.resource.resourceType == "Practitioner")).resource; - let sourceLocation = (bundle.entry.find(e => e.resource.resourceType == "Location")).resource; - let targetLocation = (bundle.entry.reverse().find(e => e.resource.resourceType == "Location")).resource; - let sourceOrganization = (bundle.entry.find(e => e.resource.resourceType == "Organization")).resource; - let targetOrganization = (bundle.entry.reverse().find(e => e.resource.resourceType == "Organization")).resource; - - res = this.setPatientData(patient, res); + let patient = this.getResource(bundle, "Patient"); + let sourceLocation = this.getResource(bundle, "Location"); + let provider = this.getResource(bundle, "Practitioner");; - let q; + res = this.setPatientData(patient, res); + res = this.setProviderData(provider, res); - if(provider.name) { - q = provider.name.find(n => n.use == 'official'); - res.providerLastName = q ? q.family : ""; - res.providerFirstName = q && q.given.length > 0 ? q.given[0] : ""; - } - - res.providerId = provider ? provider.id : ""; res.facilityId = sourceLocation ? sourceLocation.id : ""; res.kinFamilyName = ""; res.kinFirstName = ""; @@ -83,17 +83,32 @@ module.exports = class fhir extends dataHandler { } parseOrm(bundle) { let res = {}; - let patient = (bundle.entry.find(e => e.resource.resourceType == "Patient")).resource; - let serviceRequest = (bundle.entry.find(e => e.resource.resourceType == "ServiceRequest" && e.resource.basedOn)).resource; - let task = (bundle.entry.find(e => e.resource.resourceType == "Task")).resource; - let org = (bundle.entry.find(e => e.resource.resourceType == "Organization")).resource; + let patient = this.getResource(bundle, "Patient"); + let provider = this.getResource(bundle, "Practitioner");; + + let serviceRequest = this.getResource(bundle, "ServiceRequest"); + let task = this.getResource(bundle, "Task"); + let org = this.getResource(bundle, "Organization"); + let sourceLocation = this.getResource(bundle, "Location"); res = this.setPatientData(patient, res); + res = this.setProviderData(provider, res); + + res.facilityId = sourceLocation ? sourceLocation.id : ""; res.labOrderId = task.identifier ? task.identifier[0].value : ""; - res.labOrderDatetime = serviceRequest.authoredOn ? serviceRequest.authoredOn.split('-').join('') : ""; + let orderDateTime = new Date() + try { + orderDateTime = serviceRequest.authoredOn ? new Date(serviceRequest.authoredOn) : (task.authoredOn ? new Date(task.authoredOn) : orderDateTime) + res.labOrderDatetime = orderDateTime ? orderDateTime.getFullYear().toString()+(orderDateTime.getMonth()+1).toString().padStart(2, '0')+orderDateTime.getDate().toString().padStart(2, '0')+orderDateTime.getHours().toString().padStart(2, '0')+orderDateTime.getMinutes().toString().padStart(2, '0')+orderDateTime.getSeconds().toString().padStart(2, '0') : ""; + } catch(e) { + console.error(e); + res.labOrderDatetime = "" + } + if(serviceRequest.code && serviceRequest.code.coding && serviceRequest.code.coding.length > 0) { - let ipmsCode = serviceRequest.code.coding.find(e => e.system == "https://api.openconceptlab.org/orgs/B-TECHBW/sources/IPMS-LAB-TEST/") - res.labOrderType = ipmsCode && ipmsCode.code ? ipmsCode.code : ""; + let ipmsCode = serviceRequest.code.coding.find(e => e.system == "https://api.openconceptlab.org/orgs/I-TECH-UW/sources/IPMSLAB/") + res.labOrderMnemonic = ipmsCode && ipmsCode.code ? ipmsCode.code : ""; + res.labOrderName = ipmsCode && ipmsCode.display ? ipmsCode.display : ""; } return res; @@ -139,17 +154,35 @@ module.exports = class fhir extends dataHandler { res.unknownIdentifier = q ? q.value : ""; } - if(patient.name) { + res.patientFirstName = [""] + res.patientFamilyName = "" + if(patient && patient.name && patient.name.length > 0) { q = patient.name.find(n => n.use == 'official'); - res.patientFirstName = q && q.given.length > 0 ? q.given[0] : ""; + if(!q) { + q = patient.name[0] + } + res.patientFirstName = q && q.given.length > 0 ? q.given : [""]; res.patientFamilyName = q ? q.family : ""; } - res.patientFirstName = patient.name[0].given[0]; - res.patientLastName = patient.name[0].family; - res.patientDoB = patient.birthDate.split('-').join(''); - res.sex = patient.gender; + res.patientDoB = patient.birthDate ? patient.birthDate.split('-').join('') : ""; + res.sex = patient.gender ? patient.gender : ""; + + return res; + } + + setProviderData(provider, res) { + let q; + + if(provider && provider.name) { + q = provider.name.find(n => n.use == 'official'); + res.providerLastName = q ? q.family : ""; + res.providerFirstNames = q && q.given.length > 0 ? q.given : [""]; + } + + res.providerId = provider ? provider.id : ""; return res; } + }; \ No newline at end of file