Closed bryan-rigsby closed 7 months ago
Hi @bryan-rigsby,
If you can share with us an example of your code that is having issues we can help you out. It sounds like you are possibly overwriting the same OBX inside your loop.
Here is a simple example of creating OBX segments:
'use strict'
const fs = require('fs')
const template = fs.readFileSync(__dirname + '/template.hl7', 'utf-8')
const HL7 = require('hl7-standard');
var msg = new HL7(template)
msg.transform(err => {
if (err) throw err
const observations = [{
'OBX.1': '1',
'OBX.2': 'CE',
'OBX.3': 'data from 1',
'OBX.4': '',
'OBX.5': ''
}, {
'OBX.1': '2',
'OBX.2': 'CE',
'OBX.3': 'data from 2',
'OBX.4': '',
'OBX.5': ''
}, {
'OBX.1': '3',
'OBX.2': 'CE',
'OBX.3': 'data from 3',
'OBX.4': '',
'OBX.5': ''
}]
for (let observation of observations) {
let obx = msg.createSegment('OBX')
obx.set('OBX', observation)
}
console.log(msg.build());
})
Output:
MSH|^~\&|SomeSystem|SomeFacility|X|HHIC|20110329082006||ORU^R01|201103290820062979|T|2.3| ... OBX|1|CE|data from 1||| OBX|2|CE|data from 2||| OBX|3|CE|data from 3|||
thank you so much for your quick response. works like a glove! i think i was trying to set the hl7 file instead of the segment in my code
obxSegments.forEach((segment, index) => { console.log('segment in foreach', segment) let keys = Object.keys(segment); keys.forEach(key => { hl7.set(key, segment[key]) })
I cannot seem to create multiple OBX segements. I have tried looping through and object and also manually creating them, but it only creates the last one.