Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last segment has no segment separation character #56

Open
hasanerken opened this issue Apr 28, 2021 · 3 comments
Open

Last segment has no segment separation character #56

hasanerken opened this issue Apr 28, 2021 · 3 comments

Comments

@hasanerken
Copy link

hasanerken commented Apr 28, 2021

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.

@hitgeek
Copy link
Owner

hitgeek commented May 17, 2021

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.

@hasanerken
Copy link
Author

hasanerken commented May 29, 2021 via email

@dthesiya
Copy link

dthesiya commented Apr 5, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants