Skip to content

Commit

Permalink
BW workflow HL7 translation updates (#2)
Browse files Browse the repository at this point in the history
* Fixes

* ORM messaging updates and fixes

* OCL path fix
  • Loading branch information
pmanko authored Apr 4, 2023
1 parent d64c297 commit 73d9757
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 37 deletions.
4 changes: 2 additions & 2 deletions data/templates/fhir/ADT_A04_TO_IPMS.hbs
Original file line number Diff line number Diff line change
@@ -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}}
6 changes: 3 additions & 3 deletions data/templates/fhir/ORM_O01_TO_IPMS.hbs
Original file line number Diff line number Diff line change
@@ -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}}
4 changes: 2 additions & 2 deletions debug.docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file modified deploy/debug.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
91 changes: 62 additions & 29 deletions src/lib/fhir/fhir.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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 = "";
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

};

0 comments on commit 73d9757

Please sign in to comment.