3

我有一条不包含 PV2 段的SIU S12 消息。但是,当我从 NHAPI 获得解析的消息时,PV2 的父组SIU_S12_PATIENT组为currentReps ("PV2")返回 1 ,这意味着 PV2 存在。

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

我试图避免编写代码来评估段中的每个字段。PV2 只是一个示例 - 消息源中可能缺少更多段。

我正在使用最新版本的 NHAPI v 2.4。

更新:根据泰森的建议,我想出了这个方法;</p>

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

2 回答 2

2

我发现做的最简单的事情是确定一个段是否在消息中是在消息的实际字符串中搜索段名称和管道。所以,例如

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

    }

根据我的经验,要么就是这样,要么检查细分下的每个子字段以查看是否有值。

编辑

我找到了另一种检查方法,它可能会更好一些。PipeParser 类有几个静态方法,它们接受 ISegment、IGroup 和 IType 对象,这些对象将返回对象NHapi 引用的字符串表示。

示例代码:

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

输出:

PV1|1|I|||||TEST^TEST^TEST
TEST^TEST^TEST

如果没有段或项目为空,则 PiperParser 将返回一个空字符串。

于 2013-07-11T20:53:31.747 回答
1

您可以逐行读取段到文件中并添加 hl7 记录对象并检查段是否存在。

包 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;
    }
}
于 2014-06-27T12:03:35.770 回答