Examples of PipeParser


Examples of ca.uhn.hl7v2.parser.PipeParser

        tx.setValue("MICROSCOPIC EXAM SHOWS HISTOLOGICALLY NORMAL GALLBLADDER TISSUE");
        value = obx.getObservationValue(0);
        value.setData(tx);

        // Print the message (remember, the MSH segment was not fully or correctly populated)
        System.out.append(new PipeParser().encode(message));

        /*
         * MSH|^~\&
         * OBR|1||1234^LAB|88304
         * OBX|1|CE|88304|1|T57000^GALLBLADDER^SNM
 
View Full Code Here

Examples of ca.uhn.hl7v2.parser.PipeParser

    /*
     * Let's start by constructing a parser using default settings. By
     * default, a parser has certain validation settings, as defined by the
     * DefaultValidation class.
     */
    PipeParser parser = new PipeParser();

    /*
     * These two lines are actually redundant, since this is the default
     * validator. The default validation includes a number of sensible
     * defaults including maximum lengths on string types, formats for
     * telephone numbers and timestamps, etc.
     */
    DefaultValidation defaultValidation = new DefaultValidation();
    parser.setValidationContext(defaultValidation);

    // Let's try parsing the valid message:
    try {
      parser.parse(validMessage);
      System.out.println("Successfully parsed valid message");
    } catch (HL7Exception e) {
      // This shouldn't happen!
      System.out.println("Something went wrong!");
      System.exit(-1);
    }

    // Next, let's set EVN-2 to a string that is longer than 200 chars.
    // DefaultValidation specified that ID datatypes must not exceed this
    // length
    String invalidMessage = "MSH|^~\\&|MedSeries|CAISI_1-2|PLS|3910|200903230934||ADT^A31^ADT_A05|75535037-1237815294895|P^T|2.4\r\n"
        + "EVN|0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789|200903230934\r\n"
        + "PID|1||29^^CAISI_1-2^PI~\"\"||Test300^Leticia^^^^^L||19770202|M||||||||||||||||||||||";

    // Let's try parsing the valid message:
    try {
      parser.parse(invalidMessage);
      // This shouldn't happen!
      System.out.println("Something went wrong!");
      System.exit(-1);
    } catch (HL7Exception e) {
      // This time, we are expecing an exception, because the message
      // should fail validation.
      System.out.println("As expected, the message did not validate: "
          + e.getMessage());
      /*
       * Prints:
       * As expected, the message did not validate: Failed validation rule: Maxumim size <= 200 characters: Segment: EVN (rep 0) Field #1
       */

    }

    /*
     * Now, suppose we want to throw caution to the wind, and not do
     * any validation. This is fairly common practice in the real
     * world, since sending systems don't always behave as nicely as
     * we might want.
     */
    NoValidation noValidation = new NoValidation();
    parser.setValidationContext(noValidation);
   
    try {
      parser.parse(invalidMessage);
      System.out.println("Successfully parsed invalid message");
    } catch (HL7Exception e) {
      // This shouldn't happen!
      System.out.println("Something went wrong!");
      System.exit(-1);
    }
   
    /*
     * One important thing to note is that NoValidation still includes one
     * rule: A rule which strips leading space from FT, ST, and TX fields.
     *
     * Let's add some leading space to MSH-10 (this isn't something you would
     * want to do normally, but it does demonstrate leading space trimming from
     * ST datatypes)
     */
    invalidMessage = "MSH|^~\\&|MedSeries|CAISI_1-2|PLS|3910|200903230934||ADT^A31^ADT_A05|             CONTROLID|P^T|2.4\r\n"
      + "EVN|A03|200903230934\r\n"
      + "PID|1||29^^CAISI_1-2^PI~\"\"||Test300^Leticia^^^^^L||19770202|M||||||||||||||||||||||";
    try {
      Message parsedMessage = parser.parse(invalidMessage);
     
      // Print the mesage back out
      System.out.println(new PipeParser().encode(parsedMessage));
     
      /*
       * MSH|^~\&|MedSeries|CAISI_1-2|PLS|3910|200903230934||ADT^A31^ADT_A05|CONTROLID|P^T|2.4
             * EVN|A03|200903230934
       * PID|1||29^^CAISI_1-2^PI~""||Test300^Leticia^^^^^L||19770202|M
 
View Full Code Here

Examples of ca.uhn.hl7v2.parser.PipeParser

        // Create the MCF. We want all parsed messages to be for HL7 version 2.5,
        // despite what MSH-12 says.
        CanonicalModelClassFactory mcf = new CanonicalModelClassFactory("2.5");

        // Pass the MCF to the parser in its constructor
        PipeParser parser = new PipeParser(mcf);
       
        // The parser parses the v2.3 message to a "v25" structure
        ca.uhn.hl7v2.model.v25.message.ORU_R01 msg = (ORU_R01) parser.parse(v23message);
       
        // 20169838-v23
        System.out.println(msg.getMSH().getMessageControlID().getValue());

        // The parser also parses the v2.5 message to a "v25" structure
        msg = (ORU_R01) parser.parse(v25message);
       
        // 20169838-v23
        System.out.println(msg.getMSH().getMessageControlID().getValue());
       
        /*
         * The second technique is to use the Terser. The Terser allows you
         * to access field values using a path-like notation. For more information
         * on the Terser, see the example here:
         * http://hl7api.sourceforge.net/xref/ca/uhn/hl7v2/examples/ExampleUseTerser.html
         */

        // This time we just use a normal ModelClassFactory, which means we will be
        // using the standard version-specific model classes
        parser = new PipeParser();

        // 20169838-v23
        Message v23Message = parser.parse(v23message);
        Terser t23 = new Terser(v23Message);
        System.out.println(t23.get("/MSH-10"));

        // 20169838-v25
        Message v25Message = parser.parse(v25message);
        Terser t25 = new Terser(v25Message);
        System.out.println(t25.get("/MSH-10"));
       
        /*
         * Note that this second technique has one major drawback: Although
View Full Code Here

Examples of ca.uhn.hl7v2.parser.PipeParser

        /*
         * In a real situation, of course, many more segments and fields would be populated
         */
               
        // Now, let's encode the message and look at the output
        Parser parser = new PipeParser();
        String encodedMessage = parser.encode(adt);
        System.out.println("Printing ER7 Encoded Message:");
        System.out.println(encodedMessage);
       
        /*
         * Prints:
         *
         * MSH|^~\&|TestSendingSystem||||200701011539||ADT^A01^ADT A01||||123
         * PID|||123456||Doe^John
         */

        // Next, let's use the XML parser to encode as XML
        parser = new DefaultXMLParser();
        encodedMessage = parser.encode(adt);
        System.out.println("Printing XML Encoded Message:");
        System.out.println(encodedMessage);
       
        /*
         * Prints:
 
View Full Code Here

Examples of ca.uhn.hl7v2.parser.PipeParser

         * Create a server to listen for incoming messages
         */

        int port = 1011; // The port to listen on
        LowerLayerProtocol llp = LowerLayerProtocol.makeLLP(); // The transport protocol
        PipeParser parser = new PipeParser(); // The message parser
        SimpleServer server = new SimpleServer(port, llp, parser);

        /*
         * The server may have any number of "application" objects registered to handle messages. We
         * are going to create an application to listen to ADT^A01 messages.
         */
        Application handler = new ExampleReceiverApplication();
        server.registerApplication("ADT", "A01", handler);

        /*
         * We are going to register the same application to handle ADT^A02 messages. Of course, we
         * coud just as easily have specified a different handler.
         */
        server.registerApplication("ADT", "A02", handler);

        /*
         * Another option would be to specify a single application to handle all messages, like
         * this:
         *
         * server.registerApplication("*", "*", handler);
         */

        // Start the server listening for messages
        server.start();

        /*
         * Now, create a connection to that server, and send a message
         */

        // Create a message to send
        String msg = "MSH|^~\\&|HIS|RIH|EKG|EKG|199904140038||ADT^A01|12345|P|2.2\r"
                + "PID|0001|00009874|00001122|A00977|SMITH^JOHN^M|MOM|19581119|F|NOTREAL^LINDA^M|C|564 SPRING ST^^NEEDHAM^MA^02494^US|0002|(818)565-1551|(425)828-3344|E|S|C|0000444444|252-00-4414||||SA|||SA||||NONE|V1|0001|I|D.ER^50A^M110^01|ER|P00055|11B^M011^02|070615^BATMAN^GEORGE^L|555888^NOTREAL^BOB^K^DR^MD|777889^NOTREAL^SAM^T^DR^MD^PHD|ER|D.WT^1A^M010^01|||ER|AMB|02|070615^NOTREAL^BILL^L|ER|000001916994|D||||||||||||||||GDD|WA|NORM|02|O|02|E.IN^02D^M090^01|E.IN^01D^M080^01|199904072124|199904101200|199904101200||||5555112333|||666097^NOTREAL^MANNY^P\r"
                + "NK1|0222555|NOTREAL^JAMES^R|FA|STREET^OTHER STREET^CITY^ST^55566|(222)111-3333|(888)999-0000|||||||ORGANIZATION\r"
                + "PV1|0001|I|D.ER^1F^M950^01|ER|P000998|11B^M011^02|070615^BATMAN^GEORGE^L|555888^OKNEL^BOB^K^DR^MD|777889^NOTREAL^SAM^T^DR^MD^PHD|ER|D.WT^1A^M010^01|||ER|AMB|02|070615^VOICE^BILL^L|ER|000001916994|D||||||||||||||||GDD|WA|NORM|02|O|02|E.IN^02D^M090^01|E.IN^01D^M080^01|199904072124|199904101200|||||5555112333|||666097^DNOTREAL^MANNY^P\r"
                + "PV2|||0112^TESTING|55555^PATIENT IS NORMAL|NONE|||19990225|19990226|1|1|TESTING|555888^NOTREAL^BOB^K^DR^MD||||||||||PROD^003^099|02|ER||NONE|19990225|19990223|19990316|NONE\r"
                + "AL1||SEV|001^POLLEN\r"
                + "GT1||0222PL|NOTREAL^BOB^B||STREET^OTHER STREET^CITY^ST^77787|(444)999-3333|(222)777-5555||||MO|111-33-5555||||NOTREAL GILL N|STREET^OTHER STREET^CITY^ST^99999|(111)222-3333\r"
                + "IN1||022254P|4558PD|BLUE CROSS|STREET^OTHER STREET^CITY^ST^00990||(333)333-6666||221K|LENIX|||19980515|19990515|||PATIENT01 TEST D||||||||||||||||||02LL|022LP554";
        Parser p = new GenericParser();
        Message adt = p.parse(msg);

        // The connection hub connects to listening servers
        ConnectionHub connectionHub = ConnectionHub.getInstance();

        // A connection object represents a socket attached to an HL7 server
        Connection connection = connectionHub
                .attach("localhost", port, new PipeParser(), MinLowerLayerProtocol.class);

        // The initiator is used to transmit unsolicited messages
        Initiator initiator = connection.getInitiator();
        Message response = initiator.sendAndReceive(adt);

        String responseString = parser.encode(response);
        System.out.println("Received response:\n" + responseString);

        /*
         * MSH|^~\&|||||20070218200627.515-0500||ACK|54|P|2.2 MSA|AA|12345
         */
 
View Full Code Here

Examples of ca.uhn.hl7v2.parser.PipeParser

     * PID|1||29^^CAISI_1-2^PI~""||Test300^Leticia^^^^^L||19770202|M||||||||||||||||||||||
     */
    String validMessageString = "MSH|^~\\&|MedSeries|CAISI_1-2|PLS|3910|200903230934||ADT^A31^ADT_A05|75535037-1237815294895|P^T|2.4\r\n"
        + "EVN|A31|200903230934\r\n"
        + "PID|1||29^^CAISI_1-2^PI~\"\"||Test300^Leticia^^^^^L||19770202|M||||||||||||||||||||||";
    Message validMessage = new PipeParser().parse(validMessageString);

    // Load a conformance profile
    ProfileParser profileParser = new ProfileParser(false);
    RuntimeProfile profile = profileParser.parseClasspath("ca/uhn/hl7v2/examples/profiles/ADT_A31.xml");

View Full Code Here

Examples of ca.uhn.hl7v2.parser.PipeParser

            + "AL1||SEV|001^POLLEN\r"
            + "GT1||0222PL|NOTREAL^BOB^B||STREET^OTHER STREET^CITY^ST^77787|(444)999-3333|(222)777-5555||||MO|111-33-5555||||NOTREAL GILL N|STREET^OTHER STREET^CITY^ST^99999|(111)222-3333\r"
            + "IN1||022254P|4558PD|BLUE CROSS|STREET^OTHER STREET^CITY^ST^00990||(333)333-6666||221K|LENIX|||19980515|19990515|||PATIENT01 TEST D||||||||||||||||||02LL|022LP554";

        // Let's create a special parser to handle this:
        Parser parser = new PipeParser() {

            // We override the parse method to correct issues
            public Message parse(String theMessage) throws HL7Exception, EncodingNotSupportedException {
                theMessage = theMessage.replace("\rPI|", "\rPID|");
                return super.parse(theMessage);
            }};
       
        Message message = parser.parse(msg);
       
        System.out.println(parser.encode(message));
       
        /* PI has been fixed:
        
            MSH|^~\&|HIS|RIH|EKG|EKG|199904140038||ADT^A01||P|2.2
            PID|0001|00009874|00001122|A00977|SMITH^JOHN^M|MOM|19581119|F|NOTREAL^LINDA^M|C|564 SPRING ST^^NEEDHAM^MA^02494^US|0002|(818)565-1551|(425)828-3344|E|S|C|0000444444|252-00-4414||||SA|||SA||||NONE|V1|0001|I|D.ER^50A^M110^01|ER|P00055|11B^M011^02|070615^BATMAN^GEORGE^L|555888^NOTREAL^BOB^K^DR^MD|777889^NOTREAL^SAM^T^DR^MD^PHD|ER|D.WT^1A^M010^01|||ER|AMB|02|070615^NOTREAL^BILL^L|ER|000001916994|D||||||||||||||||GDD|WA|NORM|02|O|02|E.IN^02D^M090^01|E.IN^01D^M080^01|199904072124|199904101200|199904101200||||5555112333|||666097^NOTREAL^MANNY^P
View Full Code Here

Examples of ca.uhn.hl7v2.parser.PipeParser

        tx.setValue("MICROSCOPIC EXAM SHOWS HISTOLOGICALLY NORMAL GALLBLADDER TISSUE");
        value = obx.getObservationValue(0);
        value.setData(tx);

        // Print the message (remember, the MSH segment was not fully or correctly populated)
        System.out.append(new PipeParser().encode(message));

        /*
         * MSH|^~\&|||||20111102082111.435-0500||ORU^R01^ORU_R01|305|T|2.5
         * OBR|1||1234^LAB|88304
         * OBX|1|CE|88304|1|T57000^GALLBLADDER^SNM
 
View Full Code Here

Examples of ca.uhn.hl7v2.parser.PipeParser

    /*
     * Let's start by constructing a parser using default settings. By
     * default, a parser has certain validation settings, as defined by the
     * DefaultValidation class.
     */
    PipeParser parser = new PipeParser();

    /*
     * These two lines are actually redundant, since this is the default
     * validator. The default validation includes a number of sensible
     * defaults including maximum lengths on string types, formats for
     * telephone numbers and timestamps, etc.
     */
    DefaultValidation defaultValidation = new DefaultValidation();
    parser.setValidationContext(defaultValidation);

    // Let's try parsing the valid message:
    try {
      parser.parse(validMessage);
      System.out.println("Successfully parsed valid message");
    } catch (HL7Exception e) {
      // This shouldn't happen!
      System.out.println("Something went wrong!");
      System.exit(-1);
    }

    // Next, let's set EVN-2 to a string that is longer than 200 chars.
    // DefaultValidation specified that ID datatypes must not exceed this
    // length
    String invalidMessage = "MSH|^~\\&|MedSeries|CAISI_1-2|PLS|3910|200903230934||ADT^A31^ADT_A05|75535037-1237815294895|P^T|2.4\r\n"
        + "EVN|0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789|200903230934\r\n"
        + "PID|1||29^^CAISI_1-2^PI~\"\"||Test300^Leticia^^^^^L||19770202|M||||||||||||||||||||||";

    // Let's try parsing the valid message:
    try {
      parser.parse(invalidMessage);
      // This shouldn't happen!
      System.out.println("Something went wrong!");
      System.exit(-1);
    } catch (HL7Exception e) {
      // This time, we are expecing an exception, because the message
      // should fail validation.
      System.out.println("As expected, the message did not validate: "
          + e.getMessage());
      /*
       * Prints:
       * As expected, the message did not validate: Failed validation rule: Maxumim size <= 200 characters: Segment: EVN (rep 0) Field #1
       */

    }

    /*
     * Now, suppose we want to throw caution to the wind, and not do
     * any validation. This is fairly common practice in the real
     * world, since sending systems don't always behave as nicely as
     * we might want.
     */
    NoValidation noValidation = new NoValidation();
    parser.setValidationContext(noValidation);
   
    try {
      parser.parse(invalidMessage);
      System.out.println("Successfully parsed invalid message");
    } catch (HL7Exception e) {
      // This shouldn't happen!
      System.out.println("Something went wrong!");
      System.exit(-1);
    }
   
    /*
     * One important thing to note is that NoValidation still includes one
     * rule: A rule which strips leading space from FT, ST, and TX fields.
     *
     * Let's add some leading space to MSH-10 (this isn't something you would
     * want to do normally, but it does demonstrate leading space trimming from
     * ST datatypes)
     */
    invalidMessage = "MSH|^~\\&|MedSeries|CAISI_1-2|PLS|3910|200903230934||ADT^A31^ADT_A05|             CONTROLID|P^T|2.4\r\n"
      + "EVN|A03|200903230934\r\n"
      + "PID|1||29^^CAISI_1-2^PI~\"\"||Test300^Leticia^^^^^L||19770202|M||||||||||||||||||||||";
    try {
      Message parsedMessage = parser.parse(invalidMessage);
     
      // Print the mesage back out
      System.out.println(new PipeParser().encode(parsedMessage));
     
      /*
       * MSH|^~\&|MedSeries|CAISI_1-2|PLS|3910|200903230934||ADT^A31^ADT_A05|CONTROLID|P^T|2.4
             * EVN|A03|200903230934
       * PID|1||29^^CAISI_1-2^PI~""||Test300^Leticia^^^^^L||19770202|M
 
View Full Code Here

Examples of ca.uhn.hl7v2.parser.PipeParser

        // Create the MCF. We want all parsed messages to be for HL7 version 2.5,
        // despite what MSH-12 says.
        CanonicalModelClassFactory mcf = new CanonicalModelClassFactory("2.5");

        // Pass the MCF to the parser in its constructor
        PipeParser parser = new PipeParser(mcf);
       
        // The parser parses the v2.3 message to a "v25" structure
        ca.uhn.hl7v2.model.v25.message.ORU_R01 msg = (ORU_R01) parser.parse(v23message);
       
        // 20169838-v23
        System.out.println(msg.getMSH().getMessageControlID().getValue());

        // The parser also parses the v2.5 message to a "v25" structure
        msg = (ORU_R01) parser.parse(v25message);
       
        // 20169838-v23
        System.out.println(msg.getMSH().getMessageControlID().getValue());
       
        /*
         * The second technique is to use the Terser. The Terser allows you
         * to access field values using a path-like notation. For more information
         * on the Terser, see the example here:
         * http://hl7api.sourceforge.net/xref/ca/uhn/hl7v2/examples/ExampleUseTerser.html
         */

        // This time we just use a normal ModelClassFactory, which means we will be
        // using the standard version-specific model classes
        parser = new PipeParser();

        // 20169838-v23
        Message v23Message = parser.parse(v23message);
        Terser t23 = new Terser(v23Message);
        System.out.println(t23.get("/MSH-10"));

        // 20169838-v25
        Message v25Message = parser.parse(v25message);
        Terser t25 = new Terser(v25Message);
        System.out.println(t25.get("/MSH-10"));
       
        /*
         * Note that this second technique has one major drawback: Although
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.