How to tell if a segment actually exists in a HL7 message via NHAPI? -
i have siu s12 message not contain pv2 segment. however, when parsed message nhapi, parent group pv2, siu_s12_patient group, return 1 currentreps ("pv2"), means pv2 present.
var parser = new nhapi.base.parser.pipeparser(); var parsedmessage = parser.parse(message) nhapi.model.v231.message.siu_s12; var patientgroup=parsedmessage.getpatient(0); // call should not create segment if not exist int pv2count=patientgroup.currentreps("pv2"); //pv2count 1 here despite no pv2 segment exists in message //also both getall("pv2") , segmentfinder pv2 segment present //dg1repetitionsused is 1 despite no dg1 segment present in message
i trying avoid writing code evaluate every field in segment. pv2 example - there lot more segments missing message source.
i using nhapi v 2.4, latest version.
update: following tyson's suggestion come method;
var parser = new nhapi.base.parser.pipeparser(); var parsedmessage = parser.parse(message) nhapi.model.v231.message.siu_s12; var encodingchars = new nhapi.base.parser.encodingcharacters('|', null); var patientgroup = parsedmessage.getpatient(0); var dg1 = (nhapi.model.v231.segment.dg1) (patientgroup.getstructure("dg1")); string encodeddg1 = nhapi.base.parser.pipeparser.encode(dg1, encodingchars); bool dg1exists = string.compare(encodeddg1, "dg1", stringcomparison.invariantcultureignorecase)==0;
easiest thing have found determine if segment in message search actual string of message segment name plus pipe. so, example
if(message.contains("pv2|")) { //do neat }
from experience, either that, or examining every sub-field under segment see if there value.
edit
i found way check might work little better. pipeparser class has couple of static methods on takes in isegment, igroup, , itype objects return string representation of object nhapi reference.
sample code:
string validtestmessages = "msh|^~\\&|adt1|mcm|labadt|mcm|198808181126|security|adt^a01|msg00001|p|2.6\r" + "evn|a01-|198808181123\r" + "pid|||pid1234^5^m11^hboc^cpi^hv||jones^william^a^iii||19610615000000|m||2106-3|1200 n elm street^^greensboro^nc^27401-1020|gl||||s||s|123456789|9-87654^nc\r" + "pv1|1|i|||||test^test^test||||||||||||||||||||||||||||||||||||||||||||\r"; var encodingchars = new encodingcharacters('|', null); pipeparser parser = new pipeparser(); var message = parser.parse(validtestmessages); pv1 pv1 = (pv1)message.getstructure("pv1"); var doctor = pv1.getattendingdoctor(0); string encodedmessage = pipeparser.encode(pv1, encodingchars); console.writeline(encodedmessage); encodedmessage = pipeparser.encode(doctor, encodingchars); console.writeline(encodedmessage);
output:
pv1|1|i|||||test^test^test test^test^test
if there no segment or item empty, piperparser return empty string.
Comments
Post a Comment