Package ca.uhn.hl7v2.parser

Examples of ca.uhn.hl7v2.parser.PipeParser


                    for (int i = 0; i < nextStructureList.size(); i++) {
                        if (i > 0) {
                            indent(theStringBuilder, currentIndent + structurePrefix.length());
                        }
                        Segment nextSegment = (Segment) nextStructureList.get(i);
                        theStringBuilder.append(new PipeParser().doEncode(nextSegment,
                                EncodingCharacters.getInstance(getMessage())));
                        theStringBuilder.append(lineSeparator);

                    }
                }
View Full Code Here


        /*
         * 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

       * even if a long period will pass between messages being
       * sent. This is good practice, as it is much faster than
       * creating a new connection each time.
       */
      if (conn == null) {
        conn = connectionHub.attach("localhost", 8888, new PipeParser(), MinLowerLayerProtocol.class);
      }
     
      Message response;
      try {
        response = conn.getInitiator().sendAndReceive(next);
View Full Code Here

         * 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

    obx.getObservationIdentifier().getIdentifier().setValue("1");
    obx.getValueType().setValue("CE");
    obx.getObservationValue(0).setData(encapsuledData);
   
    // Print the message out
    System.out.println(new PipeParser().encode(mdmMessage));
   
    /*
      The following output is produced. Note that the newlines are unix newlines (\n)
      and not (\r), so they are OK to use within a segment.

View Full Code Here

    /**
     * {@inheritDoc}
     */
    public Message processMessage(Message theIn) throws ApplicationException, HL7Exception {

        String encodedMessage = new PipeParser().encode(theIn);
        System.out.println("Received message:\n" + encodedMessage + "\n\n");

        // Now we need to generate a message to return. This will generally be an ACK message.
        MSH msh = (MSH)theIn.get("MSH");
        ACK retVal;
View Full Code Here

        + "ZPI|Fido~Fred|13\r"
        + "PV1||I|6402DH^^^^^^^^MED. 1 - ONCOLOGIA^^OSPEDALE MAGGIORE DI LODI&LODI|||^^^^^^^^^^OSPEDALE MAGGIORE DI LODI&LODI|13936^TEST^TEST||||||||||5068^TEST2^TEST2||2008003369||||||||||||||||||||||||||200803031508\r"
        + "PR1|1||1111^Mastoplastica|Protesi|20090224|02|";

        // HAPI will still parse this message fine
        ADT_A01 message = (ADT_A01) new PipeParser().parse(messageText);
       
        // If we want to access the data in the ZPI segment, it's pretty easy
        Segment zpiGenericSegment = (Segment) message.get("ZPI");

        String firstPetName  = zpiGenericSegment.getField(1, 0).encode();
        String secondPetName = zpiGenericSegment.getField(1, 1).encode();
        System.out.println(firstPetName); // Fido
        System.out.println(secondPetName); // Fred

        String shoeSize = zpiGenericSegment.getField(2, 0).encode();
        System.out.println(shoeSize); // 13


        // Now, suppose our message is actually called ZDT^A01, and we plan on
        // using it frequently, so we want to explicitly define a class to
        // handle it. That can be done as well.

        // Here is a segment class we have created (click to view):
        ZPI zpi;

        // Here is a message class we have created (click to view):
        ZDT_A01 zdtA01;

        // These classes are both in the package ca.uhn.hl7v2.examples.custommodel.[version].[type]
        // We can create a parser with a custom model class factory to use it
        ModelClassFactory cmf = new CustomModelClassFactory("ca.uhn.hl7v2.examples.custommodel");

        // We then pass the model class factory to the parser
        Parser parser = new PipeParser(cmf);

        // The resulting message will be an instance of our custom type (this time, MSH-9 says ZDT^A01)
    messageText = "MSH|^~\\&|IRIS|SANTER|AMB_R|SANTER|200803051508||ZDT^A01|263206|P|2.5\r"
        + "EVN||200803051509||||200803031508\r"
        + "PID|||5520255^^^PK^PK~ZZZZZZ83M64Z148R^^^CF^CF~ZZZZZZ83M64Z148R^^^SSN^SSN^^20070103^99991231~^^^^TEAM||ZZZ^ZZZ||19830824|F||||||||||||||||||||||N\r"
        + "ZPI|Fido~Fred|13\r"
        + "PV1||I|6402DH^^^^^^^^MED. 1 - ONCOLOGIA^^OSPEDALE MAGGIORE DI LODI&LODI|||^^^^^^^^^^OSPEDALE MAGGIORE DI LODI&LODI|13936^TEST^TEST||||||||||5068^TEST2^TEST2||2008003369||||||||||||||||||||||||||200803031508\r"
        + "PR1|1||1111^Mastoplastica|Protesi|20090224|02|";
        zdtA01 = (ZDT_A01) parser.parse(messageText);

        // Now we have easy access to our new segment and fields
        zpi = zdtA01.getZPI();

        System.out.println(zpi.getPetName()[0].encode()); // Fido
View Full Code Here

     *
     * By default, MinLowerLayerProtocol uses the "US-ASCII" character set, which is not likely
     * what you are looking for if you want to process accents or characters that don't
     * appear in the English alphabet.
     */
    SimpleServer s = new SimpleServer(123, new MinLowerLayerProtocol(), new PipeParser());

    /*
     * Using MinLowerLayerProtocol, it is possible to set the use of a specific character set
     * by using a system property. For example, if you wanted to receive Central and Eastern
     * European characters, you probably need the ISO-8859-2 charset. Setting the following
     * system property before using MinLowerLayerProtocol tells the LLP that incoming
     * messages should be received using this encoding. Note that you can not change this
     * value after a connection is established.
     */
    System.setProperty(MinLLPReader.CHARSET_KEY, "ISO-8859-2");
    s = new SimpleServer(123, new MinLowerLayerProtocol(), new PipeParser());
   
    /*
     * If the systems sending you messages are correctly
     * populating MSH-18, as in the following message which specified "8859/1", or
     * ISO-8859-1 encoding, you have another option.
     *
     * MSH|^~\&|4265-ADT|4265|eReferral|eReferral|201004141020||ADT^A45^ADT_A45|102416|T^|2.5^^|||NE|AL|CAN|8859/1
     * EVN|A45|201004141020|
     * PID|1||7010226^^^4265^MR~0000000000^^^CANON^JHN^^^^^^GP~1736465^^^4265^VN||Park^Green^^^MS.^^L||19890812|F|||123 TestingLane^^TORONTO^CA-ON^M5G2C2^CAN^H^~^^^^^^^||^PRN^PH^^1^416^2525252^|^^^^^^^||||||||||||||||N
     * PV1|1|I||||^^^WP^1469^^^^^^^^|||||||||||^Derkach^Peter.^^^Dr.||20913000131|||||||||||||||||||||||||201004011340|201004141018
     *
     * Another possibility (only available in HAPI 1.3+) is to read the value from MSH-18
     * and use that to identify the character set. This can be advantageous if you want
     * to be able to receive multiple CharSets. To do this, you need to use the
     * ExtendedMinLowerLayerProtocol.
     */
    s = new SimpleServer(123, new ExtendedMinLowerLayerProtocol(), new PipeParser());
   
    /*
     * The same LLP implementations may be also be used for transmitting messages.
     *
     * If you want to transmit using the same encoding all of the time, you may use
     * MinLowerLayerProtocol. In the example below, messages will be sent out using
     * ISO-8859-2
     */
    System.setProperty(MinLLPReader.CHARSET_KEY, "ISO-8859-2");
    Connection c = ConnectionHub.getInstance().attach("localhost", 8888, new PipeParser(), MinLowerLayerProtocol.class);

    /*
     * You may also use ExtendedMinLowerLayerProtocol to send out messages using
     * the value you have placed in MSH-18.
     */
    c = ConnectionHub.getInstance().attach("localhost", 8888, new PipeParser(), ExtendedMinLowerLayerProtocol.class);
   
  }
View Full Code Here

     * 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

            + "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

TOP

Related Classes of ca.uhn.hl7v2.parser.PipeParser

Copyright © 2018 www.massapicom. 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.