从HL7标准消息中读取患者信息

时间:2017-02-27 10:15:31

标签: java hapi hl7-v2

对于HL7(健康等级7)我正在使用Hapi

写操作: -

     ADT_A01 adt = new ADT_A01();
     adt.initQuickstart("ADT", "A01", "P");

      // Populate the MSH Segment
      MSH mshSegment = adt.getMSH();
      mshSegment.getSendingApplication().getNamespaceID().setValue("TestSendingSystem");
      mshSegment.getSequenceNumber().setValue("123");

      // Populate the PID Segment
      PID pid = adt.getPID(); 
      pid.getPatientName(0).getFamilyName().getSurname().setValue("Doe");
      pid.getPatientName(0).getGivenName().setValue("John");
      pid.getPatientIdentifierList(0).getID().setValue("123456");

      pid.getAdministrativeSex().setValue("M");

      pid.getPhoneNumberHome(0).getPhoneNumber().setValue("90000000000");

      pid.getPatientAddress(0).getStreetAddress().getStreetName().setValue("B201, Abc street");
      pid.getPatientAddress(0).getCity().setValue("Noida");
      pid.getPatientAddress(0).getStateOrProvince().setValue("UP");
      pid.getPatientAddress(0).getCountry().setValue("India");

      // Now, let's encode the message and look at the output
      HapiContext context = new DefaultHapiContext();
      Parser parser = context.getPipeParser();
      String encodedMessage = parser.encode(adt);
      System.out.println("Printing ER7 Encoded Message:");
      System.out.println(encodedMessage);

输出:

  

打印ER7编码消息:   MSH | ^〜\&安培; | |||| TestSendingSystem + 20170227154106.754 0530 || ADT ^ A01 ^ ADT_A01 | 1301 | P | 2.4 | 123   PID ||| 123456 || Doe ^ John ||| M |||& B201,Abc street ^^ Noida ^ UP ^^ India || ^^^^^^ 90000000000

阅读操作:

       HapiContext context2 = new DefaultHapiContext();
       Parser p = context2.getGenericParser();
       Message hapiMsg;

        try {
          hapiMsg = p.parse(encodedMessage);
        } catch (EncodingNotSupportedException e) {
          return;
        } catch (HL7Exception e) {
          return;
        }

      ADT_A01 adtMsg = (ADT_A01)hapiMsg;
      MSH msh = adtMsg.getMSH();

     // Retrieve some data from the MSH segment
     String msgType = msh.getMessageType().getMessageType().getValue();
     String msgTrigger = msh.getMessageType().getTriggerEvent().getValue();

     System.out.println("Decode : ");
     System.out.println(msgType + " " + msgTrigger);

输出:

  

解码:   ADT A01

我如何获得患者信息来自此消息。 请建议我!! 感谢

1 个答案:

答案 0 :(得分:1)

我解决了!!!
这是我的解决方案:

     PID pid1 = adtMsg.getPID();
     String id = pid.getPatientIdentifierList(0).getID().getValue();
     System.out.println("PID : "+id);
     String last = pid1.getPatientName(0).getFamilyName().getSurname().getValue();
     String first = pid1.getPatientName(0).getGivenName().getValue();
     System.out.println("Patient Name : "+first+" "+last);

<强>输出

Decode : 
------------------
Message Type : ADT
Message Trigger : A01
PID : 123456
Patient Name : John Doe