simple-hl7 icon indicating copy to clipboard operation
simple-hl7 copied to clipboard

Last segment has no segment separation character

Open hasanerken opened this issue 3 years ago • 3 comments

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. Ekran Resmi 2021-04-28 12 03 17

By the way, thanks, for this useful library.

hasanerken avatar Apr 28 '21 09:04 hasanerken

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.

hitgeek avatar May 17 '21 18:05 hitgeek

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

hasanerken avatar May 29 '21 18:05 hasanerken

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;
}

dthesiya avatar Apr 05 '23 22:04 dthesiya