Examples of Terser


Examples of ca.uhn.hl7v2.util.Terser

        // 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
         * message definitions are backwards compatible, some group names
         * change between versions. If you are accessing a group within
         * a complex message structure, this can cause issues.
         *
         * This is less of an issue for some message types where groups are
         * not used much (e.g. ADT)
         */

        // This works and prints "Test Value"
        System.out.println(t23.get("/RESPONSE/ORDER_OBSERVATION/OBSERVATION(0)/OBX-5"));

        // This fails...
        // System.out.println(t25.get("/RESPONSE/ORDER_OBSERVATION/OBSERVATION(0)/OBX-5"));
       
        // ...because this would be required to extract the OBX-5 value from a v2.5 message
        System.out.println(t25.get("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(0)/OBX-5"));
       
  }

Examples of ca.uhn.hl7v2.util.Terser

        /*
         * Another way of reading messages is to use a Terser. The terser
         * accepts a particular syntax to retrieve segments. See the API
         * documentation for the Terser for more information.
         */
        Terser terser = new Terser(hapiMsg);
       
        /*
         * Sending Application is in MSH-3-1 (the first component of the third
         * field of the MSH segment)
         */
        String sendingApplication = terser.get("/.MSH-3-1");
        System.out.println(sendingApplication);
        // HIS
       
        /*
         * We can use brackets to get particular repetitions
         */
        String secondAllergyType = terser.get("/AL1(1)-3-2");
        System.out.println(secondAllergyType);
        // DUST
       
        // We can also use the terser to set values
        terser.set("/.MSH-3-1", "new_sending_app");
       
        // Let's try something more complicated, adding values to an OBX in an ORU^R01
        ORU_R01 oru = new ORU_R01();
        oru.getMSH().getEncodingCharacters().setValue("^~\\&");
        oru.getMSH().getFieldSeparator().setValue("|");
        oru.getMSH().getMessageType().getMessageCode().setValue("ORU");
        oru.getMSH().getMessageType().getTriggerEvent().setValue("R01");
        oru.getMSH().getVersionID().getVersionID().setValue("2.5");
       
        terser = new Terser(oru);
        for (int i = 0; i < 5; i++) {
            terser.set("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(" + i + ")/OBX-1", "" + (i + 1));
            terser.set("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(" + i + ")/OBX-3", "ST");
            terser.set("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(" + i + ")/OBX-5", "This is the value for rep " + i);
        }
       
        System.out.println(p.encode(oru));
       
        /*
 

Examples of ca.uhn.hl7v2.util.Terser

        // 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
         * message definitions are backwards compatible, some group names
         * change between versions. If you are accessing a group within
         * a complex message structure, this can cause issues.
         *
         * This is less of an issue for some message types where groups are
         * not used much (e.g. ADT)
         */

        // This works and prints "Test Value"
        System.out.println(t23.get("/RESPONSE/ORDER_OBSERVATION/OBSERVATION(0)/OBX-5"));

        // This fails...
        // System.out.println(t25.get("/RESPONSE/ORDER_OBSERVATION/OBSERVATION(0)/OBX-5"));
       
        // ...because this would be required to extract the OBX-5 value from a v2.5 message
        System.out.println(t25.get("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(0)/OBX-5"));
       
  }

Examples of ca.uhn.hl7v2.util.Terser

        /*
         * Another way of reading messages is to use a Terser. The terser
         * accepts a particular syntax to retrieve segments. See the API
         * documentation for the Terser for more information.
         */
        Terser terser = new Terser(hapiMsg);
       
        /*
         * Sending Application is in MSH-3-1 (the first component of the third
         * field of the MSH segment)
         */
        String sendingApplication = terser.get("/.MSH-3-1");
        System.out.println(sendingApplication);
        // HIS
       
        /*
         * We can use brackets to get particular repetitions
         */
        String secondAllergyType = terser.get("/AL1(1)-3-2");
        System.out.println(secondAllergyType);
        // DUST
       
        // We can also use the terser to set values
        terser.set("/.MSH-3-1", "new_sending_app");
       
        // Let's try something more complicated, adding values to an OBX in an ORU^R01
        ORU_R01 oru = new ORU_R01();
        oru.getMSH().getEncodingCharacters().setValue("^~\\&");
        oru.getMSH().getFieldSeparator().setValue("|");
        oru.getMSH().getMessageType().getMessageCode().setValue("ORU");
        oru.getMSH().getMessageType().getTriggerEvent().setValue("R01");
        oru.getMSH().getVersionID().getVersionID().setValue("2.5");
       
        terser = new Terser(oru);
        for (int i = 0; i < 5; i++) {
            terser.set("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(" + i + ")/OBX-1", "" + (i + 1));
            terser.set("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(" + i + ")/OBX-3", "ST");
            terser.set("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(" + i + ")/OBX-5", "This is the value for rep " + i);
        }
       
        System.out.println(p.encode(oru));
       
        /*
 

Examples of ca.uhn.hl7v2.util.Terser

      String version = inbound.getVersion();
      if (version == null)
        version = "2.4";
      clazz = mcf.getMessageClass("ACK", version, false);
      Message out = clazz.newInstance();
      Terser terser = new Terser(out);

      // populate outbound MSH using data from inbound message ...
      Segment outHeader = (Segment) out.get("MSH");
      fillResponseHeader(inboundHeader, outHeader);

      terser.set("/MSH-9-1", "ACK");
      terser.set("/MSH-9-2", Terser.get(inboundHeader, 9, 0, 2, 1));
      terser.set("/MSH-12", Terser.get(inboundHeader, 12, 0, 1, 1));
      terser.set("/MSA-1", "AA");
      terser.set("/MSA-2", Terser.get(inboundHeader, 10, 0, 1, 1));
      return out;

    } catch (Exception e) {
      throw new HL7Exception("Can't instantiate ACK of class "
          + clazz.getName(), e);

Examples of ca.uhn.hl7v2.util.Terser

            LoggerFactory.getLogger(logName).error("message validation failure", problems[i]);
        }
    }
   
    private void addProblemsToACK(Message ack, HL7Exception[] problems) throws HL7Exception {
        Terser t = new Terser(ack);
       
        if (problems.length > 0) {
            t.set("MSA-1", "AE");       
            t.set("MSA-3", "Errors were encountered while testing the message");
        }
        /*
        Segment err = (Segment) ack.get("ERR");
        for (int i = 0; i < problems.length; i++) {
            // problems[i].populate(err); FIXME: broken! needs database

Examples of ca.uhn.hl7v2.util.Terser

    /**
     * @see Validator#validate
     */
    public HL7Exception[] validate(Message message, StaticDef profile) throws ProfileException, HL7Exception {
        ArrayList<HL7Exception> exList = new ArrayList<HL7Exception>(20);
        Terser t = new Terser(message);
       
        //check msg type, event type, msg struct ID
        String msgType = t.get("/MSH-9-1");
        if (!msgType.equals(profile.getMsgType())) {
            HL7Exception e =
                new ProfileNotFollowedException("Message type " + msgType + " doesn't match profile type of " + profile.getMsgType());
            exList.add(e);
        }
       
        String evType = t.get("/MSH-9-2");
        if (!evType.equals(profile.getEventType()) && !profile.getEventType().equalsIgnoreCase("ALL")) {
            HL7Exception e =
                new ProfileNotFollowedException("Event type " + evType + " doesn't match profile type of " + profile.getEventType());
            exList.add(e);
        }
       
        String msgStruct = t.get("/MSH-9-3");
        if (msgStruct == null || !msgStruct.equals(profile.getMsgStructID())) {
            HL7Exception e =
                new ProfileNotFollowedException("Message structure " + msgStruct + " doesn't match profile type of " + profile.getMsgStructID());
            exList.add(e);
        }

Examples of ca.uhn.hl7v2.util.Terser

      throw new HL7Exception(e);
    } catch (EncodeException e) {
      throw new HL7Exception(e);
    }
   
    String responseControlId = new Terser(response.getMessage()).get("/MSH-10");
    ourLog.info("Received response to ID {} with ID {} in {} ms", new Object[] {controlId, responseControlId, delay});
   
    return response.getMessage();
  }

Examples of ca.uhn.hl7v2.util.Terser

  }

  public ResponseCode getResponseCode() {
    if (myResponseCode == null) {
      try {
        myResponseCode = ResponseCode.detect(new Terser(myMessage).get("/MSA-2"));
        if (myResponseCode == null) {
          throw new HL7Exception("No response code in message, this is probably an error");
        }
      } catch (HL7Exception e) {
        ourLog.info("Could not detect response code in message", e);

Examples of ca.uhn.hl7v2.util.Terser

                Message response = app.processMessage(incomingMessageObject, theMetadata);
               
                //Here we explicitly use the same encoding as that of the inbound message - this is important with GenericParser, which might use a different encoding by default
                outgoingMessageString = myParser.encode(response, myParser.getEncoding(incomingMessageString));
               
                Terser t = new Terser(response);
                outgoingMessageCharset = t.get("MSH-18");
            }
            catch (Exception e) {
                outgoingMessageString = Responder.logAndMakeErrorMessage(e, (Segment) incomingMessageObject.get("MSH"), myParser, myParser.getEncoding(incomingMessageString));
            }
        }
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.