simple-hl7
simple-hl7 copied to clipboard
Last segment has no segment separation character
When I create a message like this:
`var msg = new hl7.Message( "EPIC", "EPICADT", "SMS", "199912271408", "CHARRIS", ["ADT", "A04"], //This field has 2 components );
msg.addSegment( "PID", "", //Blank field ["0493575", "", "", "2", "", "ID 1"], //Multiple components "454721", "", ["DOE", "JOHN", "", "", "", ""], "19480203", // new hl7.Field("First", "Second") //REPEATING FIELD //Keep adding arguments to add more fields ); msg.addSegment("OBX", 1, //Blank field ["JHDL", "HDL Cholesterol (CAD)"], //Multiple components 1, 62, ["CD:289", "mg/dL"], [">40", "40"] );
msg.addSegment("OBX",
1, //Blank field
["JTRIG", "Triglyceride (CAD)"], //Multiple components
1,
15,
["CD:289", "mg/dL"],
["35-150", "35", "150"]
)
`
I got an error of "Last segment has no segment separation character" in HL7 inspector tool.
By the way, thanks, for this useful library.
thanks, after reviewing the docs I think I agree that the library should terminate the the last segment. since this might be a breaking change it will have to be a new major version. i'll close this when that happens.
Thanks for your reply.
Bob Rupp @.***>, 17 May 2021 Pzt, 21:28 tarihinde şunu yazdı:
thanks, after reviewing the docs I think I agree that the library should terminate the the last segment. since this might be a breaking change it will have to be a new major version. i'll close this when that happens.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hitgeek/simple-hl7/issues/56#issuecomment-842539284, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEMTFIZKJUO3GHSVPX4AL3DTOFN6PANCNFSM43WUPSHA .
-- Hasan ERKEN
The library is working fine while parsing the incoming messages. It's just having trouble while sending out messages.
I got it working by creating message with overriding toString method to add a segment separator in the end:
function(msg) {
var ack = new Message(
msg.header.getField(3),
msg.header.getField(4),
msg.header.getField(1),
msg.header.getField(2),
moment().format('YYYYMMDDHHmmss'),
'',
["ACK"],
'ACK' + moment().format('YYYYMMDDHHmmss'),
'P',
'2.3')
ack.addSegment("MSA", "AA", msg.header.getField(8))
// override toString method of ACK message to add a segment separator in the end which simple-hl7 library has missed
ack.toString = function() {
let returnString = this.header.toString() + this.header.delimiters.segmentSeperator;
for (let i = 0; i < this.segments.length; i++) {
returnString += this.segments[i].toString(this.header.delimiters);
if (i != this.segments.length - 1) returnString += this.header.delimiters.segmentSeperator;
}
returnString = returnString.replace(/^\s+|\s+$/g, '');
returnString += this.header.delimiters.segmentSeperator;
return returnString;
}
return ack;
}