2013-05-13 42 views
2

我有一个SIU S12 message不包含PV2段。但是,当我从NHAPI获得解析的消息时,PV2的父组SIU_S12_PATIENT组返回1,表示存在PV2,即currentReps ("PV2")如何通过NHAPI知道段是否实际存在于HL7消息中?

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,最新版本。

更新:下面泰森的建议,我想出这个方法,

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; 

回答

2
,我发现这样做

最简单的办法是,以确定是否一个段是在消息是搜索消息的实际字符串为段名称加一个管道。因此,例如

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

    } 

从我的经验,这是要么,或检查该段下的每个子场,看看是否有一个值。

编辑

我找到了另一种方式来检查可能工作好一点。 PipeParser类有几个静态方法,它们接收ISegment,IGroup和IType对象,它们将返回对象NHapi reference的字符串表示形式。

示例代码:

 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会返回一个空字符串。

+0

PiperParser不返回空字符串,但返回段名称。但是,仍然可以用来检查段是否为空,谢谢。 – 2013-07-12 22:18:35

1

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

package [email protected];

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 [email protected]; 

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; 
    } 
} 
相关问题