如何使用 HAPI 框架工作解析 HL7 多段(ORC/OBR/OBX)?

How to parse HL7 multiple segments(ORC/OBR/OBX) using HAPI Frame work?

如何使用 HAPI 框架解析 HL7 多段(ORC/OBR/OBX)。

我还面临与解析多个实验室订单相关的问题,还面临与特殊字符 (MSH|^~\&#|) 编码相关的问题。

 MSH|^~\&|NIST Test Lab APP|NIST Lab Facility||NIST EHR Facility|20110531140551-0500||ORU^R01^ORU_R01|NIST-LRI-NG-RN-005.01|T|2.5.1|||AL|NE|||||LRI_Common_Component^^2.16.840.1.113883.9.16^ISO~LRI_NG_Component^^2.16.840.1.113883.9.13^ISO~LRI_RN_Component^^2.16.840.1.113883.9.15^ISO
        PID|1||PATID1239^^^NIST MPI^MR||Smirnoff^Peggy^^^^^M||19750401|F||2106-3^White^HL70005^wh^white^L
        ORC|RE|ORD448811^NIST EHR|R-511^NIST Lab Filler|||||||||1234567890^Fine^Larry^^^Dr.^^^NIST-AA-1^L^^^NPI
        OBR|1|ORD448811^NIST EHR|R-511^NIST Lab Filler|HepABC Panel^Hepatitis A B C Panel^L|||20120628070100|||||||||1234567890^Fine^Larry^^^Dr.^^^NIST-AA-1^L^^^NPI||||||20120629132900-0500|||F
        OBX|1|CWE|22314-9^Hepatitis A virus IgM Ab [Presence] in Serum^LN^HAVM^Hepatitis A IgM antibodies (IgM anti-HAV)^L||260385009^Negative (qualifier value)^SCT^NEG^NEGATIVE^L^^^Negative (qualifier value)||Negative|N|||F|||20120628070100|||||20120628100500||||Princeton Hospital Laboratory^^^^^NIST HCAA-1^XX^^^34D4567890|123 High Street^^Princeton^NJ^08540^USA^O^^34021|^Martin^Steven^M^^Dr.
        OBX|2|CWE|20575-7^Hepatitis A virus Ab [Presence] in Serum^LN^HAVAB^Hepatitis A antibodies (anti-HAV)^L||260385009^Negative (qualifier value)^SCT^NEG^NEGATIVE^L^^^Negative (qualifier value)||Negative|N|||F|||20120628070100|||||20120628100500||||Princeton Hospital Laboratory^^^^^NIST HCAA-1^XX^^^34D4567890|123 High Street^^Princeton^NJ^08540^USA^O^^34021|^Martin^Steven^M^^Dr.
        OBX|3|CWE|16933-4^Hepatitis B virus core Ab [Presence] in Serum^LN^HBVcAB^Hepatitis B core antibodies (anti-HBVc)^L||260385009^Negative (qualifier value)^SCT^NEG^NEGATIVE^L^^^Negative (qualifier value)||Negative|N|||F|||20120628070100|||||20120628100500||||Princeton Hospital Laboratory^^^^^NIST HCAA-1^XX^^^34D4567890|123 High Street^^Princeton^NJ^08540^USA^O^^34021|^Martin^Steven^M^^Dr.
        OBX|4|SN|22316-4^Hepatitis B virus core Ab [Units/volume] in Serum^LN^HBcAbQ^Hepatitis B core antibodies (anti-HBVc) Quant^L||^0.40|[IU]/mL^international unit per milliliter^UCUM^IU/ml^^L|<0.50 IU/mL|N|||F|||20120628070100|||||20120628100500||||Princeton Hospital Laboratory^^^^^NIST HCAA-1^XX^^^34D4567890|123 High Street^^Princeton^NJ^08540^USA^O^^34021|^Martin^Steven^M^^Dr.
        OBX|5|CWE|22320-6^Hepatitis B virus e Ab [Presence] in Serum^LN^HBVeAB^Hepatitis B e antibodies (anti-HBVe)^L||260385009^Negative (qualifier value)^SCT^NEG^NEGATIVE^L^^^Negative (qualifier value)||Negative|N|||F|||20120628070100|||||20120628100500||||Princeton Hospital Laboratory^^^^^NIST HCAA-1^XX^^^34D4567890|123 High Street^^Princeton^NJ^08540^USA^O^^34021|^Martin^Steven^M^^Dr.
        OBX|6|CWE|5195-3^Hepatitis B virus surface Ag [Presence] in Serum^LN^HBVsAG^Hepatitis B surface antigen (HBsAg)^L||260385009^Negative (qualifier value)^SCT^NEG^NEGATIVE^L^^^Negative (qualifier value)||Negative|N|||F|||20120628070100|||||20120628100500||||Princeton Hospital Laboratory^^^^^NIST HCAA-1^XX^^^34D4567890|123 High Street^^Princeton^NJ^08540^USA^O^^34021|^Martin^Steven^M^^Dr.
        OBX|7|CWE|22322-2^Hepatitis B virus surface Ab [Presence] in Serum^LN^HBVSAB^Hepatitis B surface antibody (anti-HBVs)^L||260385009^Negative (qualifier value)^SCT^NEG^NEGATIVE^L^^^Negative (qualifier value)||Negative|N|||F|||20120628070100|||||20120628100500||||Princeton Hospital Laboratory^^^^^NIST HCAA-1^XX^^^34D4567890|123 High Street^^Princeton^NJ^08540^USA^O^^34021|^Martin^Steven^M^^Dr.
        OBX|8|CWE|16128-1^Hepatitis C virus Ab [Presence] in Serum^LN^HCVAB^Hepatitis C antibody screen  (anti-HCV)^L||10828004^Positive (qualifier value)^SCT^POS^POSITIVE^L^^^Positive (qualifier value)||Negative|A|||F|||20120628070100|||||20120628100500||||Princeton Hospital Laboratory^^^^^NIST HCAA-1^XX^^^34D4567890|123 High Street^^Princeton^NJ^08540^USA^O^^34021|^Martin^Steven^M^^Dr.
        OBX|9|SN|48159-8^Hepatitis C virus Ab Signal/Cutoff in Serum or Plasma by Immunoassay^LN^HCVSCO^Hepatitis C antibodies Signal to Cut-off Ratio^L||^10.8|{s_co_ratio}^Signal to cutoff ratio^UCUM^s/co^^L|0.0-0.9 s/co|H|||F|||20120628070100|||||20120628100500||||Princeton Hospital Laboratory^^^^^NIST HCAA-1^XX^^^34D4567890|123 High Street^^Princeton^NJ^08540^USA^O^^34021|^Martin^Steven^M^^Dr.
        NTE|1||Negative:   < 0.8; Indeterminate 0.8 - 0.9; Positive:  > 0.9.  In order to reduce the incidence of a false positive result, the CDC recommends that all s/co ratios between 1.0 and 10.9 be confirmed with additional Verification or PCR testing.
        SPM|1|||119364003^Serum specimen (specimen)^SCT^SER^Serum^L|||||||||||||20120628070100
        ORC|RE||R-511^NIST Lab Filler|||||||||1234567890^Fine^Larry^^^Dr.^^^NIST-AA-1^L^^^NPI|||||||||||||||||||HepABC Panel^Hepatitis A B C Panel^L
        OBR|2||R-511^NIST Lab Filler|11011-4^Hepatitis C virus RNA [Units/volume] (viral load) in Serum or Plasma by Probe and target amplification method^LN^HCVRNA^Hepatitis C RNA PCR^L|||20120628070100||||G|||||1234567890^Fine^Larry^^^Dr.^^^NIST-AA-1^L^^^NPI||||||20120629132900-0500|||F|16128-1&Hepatitis C virus Ab [Presence] in Serum&LN&HCVAB&Hepatitis C antibody screen  (anti-HCV)&L|||ORD448811&NIST EHR^R-511&NIST Lab Filler|||||||||||||||||||||HepABC Panel^Hepatitis A B C Panel^L
        OBX|1|SN|11011-4^Hepatitis C virus RNA [Units/volume] (viral load) in Serum or Plasma by Probe and target amplification method^LN^HCVRNA^Hepatitis C RNA PCR^L||^7611200|[IU]/mL^international unit per milliliter^UCUM^IU/ml^^L|<43 IU/mL|H|||F|||20120628070100|||||20120629092700||||Princeton Hospital Laboratory^^^^^NIST HCAA-1^XX^^^34D4567890|123 High Street^^Princeton^NJ^08540^USA^O^^34021|^Martin^Steven^M^^Dr.

代码片段:

package HAPIHL7Parser.HAPIHL7Parser;

import java.io.FileReader;

import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.HapiContext;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.parser.Parser;
import ca.uhn.hl7v2.util.Hl7InputStreamMessageIterator;
import ca.uhn.hl7v2.util.Terser;
import ca.uhn.hl7v2.validation.impl.NoValidation;

/**
 * 40 * Example code for using the {@link Terser} 41 * 42 * @author
 * <a href="Sitansu:swainsitansu@gmail.com">Sitansu</a> 43 * @version $Revision:
 * 1.3 $ updated on $Date: 2009-08-06 22:43:33 $ by $Author: Sitansu $ 44
 */
public class ExampleUseTerser {

    /**
     * 49 * A simple example of parsing a message 50 * 51 * @throws HL7Exception
     * 52 * @throws EncodingNotSupportedException 53
     */
    public static void main(String[] args) throws Exception {

        // TODO Auto-generated method stub
        FileReader reader = new FileReader("src\main\resource\LRI_5.1-NG-RN_Reflex_Hepatitis_Parent_Child_Message.txt");
        // Create an iterator to iterate over all the messages
        Hl7InputStreamMessageIterator iter = new Hl7InputStreamMessageIterator(reader);

        HapiContext context = new DefaultHapiContext();
        context.setValidationContext(new NoValidation());

        Parser p = context.getGenericParser();
        String msg = null;
        while (iter.hasNext()) {

            /*
             * If we don't already have a connection, create one. 42 * Note that
             * unless something goes wrong, it's very common 43 * to keep
             * reusing the same connection until we are done 44 * sending
             * messages. Many systems keep a connection open 45 * even if a long
             * period will pass between messages being 46 * sent. This is good
             * practice, as it is much faster than 47 * creating a new
             * connection each time. 48
             */

            msg = iter.next().toString();
            System.out.println("Sent message. Response was " + msg);

        }

        Message hapiMsg = p.parse(msg);

        // Message hapiMsg = p.parse(next);

        /*
         * 70 * Another way of reading messages is to use a Terser. The terser
         * 71 * accepts a particular syntax to retrieve segments. See the API 72
         * * documentation for the Terser for more information. 73
         */
        Terser terser = new Terser(hapiMsg);

        /*
         * 77 * Sending Application is in MSH-3-1 (the first component of the
         * third 78 * field of the MSH segment) 79
         */
        String sendingApplication = terser.get("/.MSH-3");
        System.out.println("Sending Application:" + sendingApplication);

        String sendingfacility = terser.get("/.MSH-4");
        System.out.println("Sending Facility:" + sendingfacility);

        String timeofdate = terser.get("/.MSH-7");
        System.out.println("Date/time of the message:" + timeofdate);

        String messagetype = terser.get("/.MSH-9");
        System.out.println("Message Type:" + messagetype);

        String messageControlID = terser.get("/.MSH-10");
        System.out.println("Message Control ID:" + messageControlID);

        String patientIDTypeCode = terser.get("/.PID-3-5");
        System.out.println("Patient ID Type Code:" + patientIDTypeCode);

        String dateOfBirth = terser.get("/.PID-7");
        System.out.println("Date of Birth:" + dateOfBirth);

        String placerGroupNumber = terser.get("/.ORC-4-1");
        System.out.println("Placer Group Number:" + placerGroupNumber);

        String placerOrderNo = terser.get("/.ORC-2-1");
        System.out.println("Placer Order Number:" + placerOrderNo);

        String fillerOrderNo = terser.get("/.ORC-3-1");
        System.out.println("Filler Order Number:" + fillerOrderNo);

        String orderProviderID = terser.get("/.ORC-12-1");
        System.out.println("Ordering Provider ID:" + orderProviderID);

        String orderProviderIDType = terser.get("/.ORC-12-13");
        System.out.println("Ordering Provider ID Type:" + orderProviderIDType);

        String plcOrderNO = terser.get("/.OBR-2-1");
        System.out.println("Placer Order Number:" + plcOrderNO);

        String fillrOrdNo = terser.get("/.OBR-3-1");
        System.out.println("Filler Order Number:" + fillrOrdNo);

        String testCode = terser.get("/.OBR-4-1");
        System.out.println("Test Code:" + testCode);

        String testDesc = terser.get("/.OBR-4-2");
        System.out.println("Test Description:" + testDesc);

        String testALTDesc = terser.get("/.OBR-4-9");
        System.out.println("Test alternative Description:" + testALTDesc);

        String obsDateTime = terser.get("/.OBR-7-1");
        System.out.println("Observation Date Time:" + obsDateTime);

        String speciActionCode = terser.get("/.OBR-11");
        System.out.println("Specimen Action Code:" + speciActionCode);

        String relevantClinicInfo = terser.get("/.OBR-13-1");
        System.out.println("Relevant Clinical Information:" + relevantClinicInfo);

        String relevantClinicInfo2 = terser.get("/.OBR-13-2");
        System.out.println("Relevant Clinical Information:" + relevantClinicInfo2);

        String resultStatus = terser.get("/.OBR-25");
        System.out.println("Result Status:" + resultStatus);

        String test = terser.get("/.OBSERVATION(0)/OBX-3-1");
        System.out.println("Result Status:" + test);

        String test1 = terser.get("/.OBSERVATION(2)/OBX-3-1");
        System.out.println("Result Status:" + test1);

        String test2 = terser.get("/.OBSERVATION(3)/OBX-3-1");
        System.out.println("Result Status:" + test2);


        String test3 = terser.get("/.OBSERVATION(4)/OBX-3-1");
        System.out.println("Result Status:" + test3);


        //terser.getFinder().iterate(, true);
        String testNotes = terser.get("/.NTE");
        System.out.println("Test Notes:" + testNotes);

        String speType = terser.get("/.SPM-4-9");
        System.out.println("Specimen Type:" + speType);

        String speciRejReason = terser.get("/.SPM-21-9");
        System.out.println("Specimen Reject reason:" + speciRejReason);

        String specCond = terser.get("/.SPM-24-9");
        System.out.println("Specimen condition:" + specCond);

        String specCollStartDateTime = terser.get("/.SPM-17-1-1");
        System.out.println("Speciment Collection Start Date Time:" + specCollStartDateTime);

        String notesCommts = terser.get("/.NTE-3");
        System.out.println("Notes and Comments:" + notesCommts);

        String obxID = terser.get("/.OBX-3-1");
        System.out.println("Observation ID:" + obxID);

        String obxText = terser.get("/.OBX-3-2");
        System.out.println("Observation Text:" + obxText);

        String obxText2 = terser.get("/.OBX-3-9");
        System.out.println("Observation Text:" + obxText2);

        String obxValue = terser.get("/.OBX-5-1");
        System.out.println("Observation Value:" + obxValue);

        String obxUnits = terser.get("/.OBX-6-1");
        System.out.println("Observation Units:" + obxUnits);

        String refRange = terser.get("/.OBX-7");
        System.out.println("Reference Range:" + refRange);

        String abnormalFlags = terser.get("/.OBX-8");
        System.out.println("Abnormal Flags:" + abnormalFlags);

        String obXResultStatus = terser.get("/.OBX-11");
        System.out.println("Observation Result Status:" + obXResultStatus);

        String dateOfObservation = terser.get("/.OBX-14-1");
        System.out.println("Date/Time of the Observation:" + dateOfObservation);

        String perOrgName = terser.get("/.OBX-23-1");
        System.out.println("Performing Organization Name:" + perOrgName);

        String perOrgAdd1 = terser.get("/.OBX-24-1");
        System.out.println("Performing Organization address Line 1:" + perOrgAdd1);

        String perOrgAdd2 = terser.get("/.OBX-24-2");
        System.out.println("Performing Organization address Line 2:" + perOrgAdd2);

        String perOrgCity = terser.get("/.OBX-24-3");
        System.out.println("Performing Organization City:" + perOrgCity);

        String perOrgState = terser.get("/.OBX-24-4");
        System.out.println("Performing Organization State:" + perOrgState);

        String perOrgZipCode = terser.get("/.OBX-24-5");
        System.out.println("Performing Organization Zip code:" + perOrgZipCode);

        // HIS

        /*
         * 85 * We can use brackets to get particular repetitions 86
         */

        /*
         * 108 * MSH|^~\&|||||||ORU^R01|||2.5 109 * OBX|1||ST||This is the value
         * for rep 0 110 * OBX|2||ST||This is the value for rep 1 111 *
         * OBX|3||ST||This is the value for rep 2 112 * OBX|4||ST||This is the
         * value for rep 3 113 * OBX|5||ST||This is the value for rep 4
         */

    }

}

您可以在 get 调用时指定索引,如下所示:

String perOrgCity = terser.get("/.OBX1-24-3");

注意上面代码中OBX1中的1。索引从零开始。如果您想读取多个循环计数器,只需将 1 替换为循环计数器即可。

这是类似的question