Pergunta

I have an SIU S12 message that does not contain a PV2 segment. However, when I get the parsed message from NHAPI, the parent group for PV2, the SIU_S12_PATIENT group, return 1 for currentReps ("PV2"), which means the PV2 is present.

var parser = new NHapi.Base.Parser.PipeParser();
var parsedMessage = parser.Parse(message) as NHapi.Model.V231.Message.SIU_S12;
var patientGroup=parsedMessage.GetPATIENT(0);
// This call should not create the segment if it does not exist
int pv2Count=patientGroup.currentReps("PV2");
//pv2Count is 1 here despite no PV2 segment exists in the message
//also Both GetAll("PV2") and SegmentFinder say the PV2 segment is present
//DG1RepetitionsUsed is also 1 despite no DG1 segment is present in the message

I am trying to avoid writing code to evaluate every field in the segment. PV2 is just an example - there are a lot more segments that could be missing from the message source.

I am using NHAPI v 2.4, the latest version.

Update: following Tyson's suggestion I come up with this method;

var parser = new NHapi.Base.Parser.PipeParser();
var parsedMessage = parser.Parse(message) as 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;
Foi útil?

Solução

easiest thing that I have found to do is to determine if a segment is in a message is to search the actual string of the message for the segment name plus a pipe. So, for example

    if(message.Contains("PV2|"))
    {
        //do something neat

    }

From my experience, it is either that, or examining every sub-field under the segment to see if there is a value.

EDIT

I found another way to check that might work a little better. The PipeParser class has a couple of static methods on it that takes in ISegment, IGroup, and IType objects that will return a string representation of the 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 is no segment or the item is empty, then the PiperParser will return an empty string.

Outras dicas

You can read segment line by line to a file and add in hl7 Record object and check segment exist or not.

package com.sachan.ranvijay@gmail.com.hl7.msg;

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import org.nule.lighthl7lib.hl7.Hl7Record;
    import org.nule.lighthl7lib.hl7.Hl7Segment;
    import com.stpl.hl7.dto.HL7PatientInfoDTO;

    /**
     * This class will parse the hl7 message. it can accept message  file in the format of java.io.file
     * as well as String. Its Uses org.nule.lighthl7lib.hl7.Hl7Record 
     * as a main component.
     * @author Ranvijay.Singh
     *
     */
    public class PrepareHL7Message {
        StringBuilder hl7Msg = new StringBuilder();
        Hl7Record record = null;
        public PrepareHL7Message(File file) throws Exception {

            BufferedReader reader = new BufferedReader(
                    new FileReader(file));
            String str = reader.readLine();
            while (str != null) {
                hl7Msg.append(str).append("\r");
                str = reader.readLine();
            }
            reader.close();
            try{
             record = new Hl7Record(hl7Msg.toString());
            }catch (Exception e) {
                throw e; 
            }
        }

        public PrepareHL7Message(String msg) throws Exception {

            try{
             record = new Hl7Record(msg);
            }catch (Exception e) {
                throw e; 
            }
        }
    private HL7PatientInfoDTO getPatientOrderingPhysician(HL7PatientInfoDTO padto) {
        Hl7Segment seg = record.getSegment("PV1");
        if(seg!=null)
        padto.setOrderingPhysician(seg.field(7).toString());
        return padto;
    }
    }

//DTO.............

package com.sachan.ranvijay@gmail.com.hl7.dto;

public class HL7PatientInfoDTO {

    /**
     * maped with PV1-7
     */
    private String orderingPhysician;

    /**
     * @return the orderingPhysician
     */
    public String getOrderingPhysician() {
        return orderingPhysician;
    }

    /**
     * @param orderingPhysician the orderingPhysician to set
     */
    public void setOrderingPhysician(String orderingPhysician) {
        this.orderingPhysician = orderingPhysician;
    }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top