Package ca.uhn.hl7v2.util

Examples of ca.uhn.hl7v2.util.Terser


            @Override
            public Object evaluate(Exchange exchange) {
                Message message = exchange.getIn().getBody(Message.class);
                try {
                    return new Terser(message).get(expression.trim());
                } catch (HL7Exception e) {
                    throw ObjectHelper.wrapRuntimeCamelException(e);
                }
            }


        assertTrue(xml.contains("<ORM_O01"));
        template.sendBody("direct:unmarshalOkXml", xml);

        assertMockEndpointsSatisfied();
        Message received = mock.getReceivedExchanges().get(0).getIn().getMandatoryBody(Message.class);
        assertEquals("O01", new Terser(received).get("MSH-9-2"));
    }   

      }
   
      break;
    }
   
    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();
  }

    public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception {
        String body = ExchangeHelper.convertToMandatoryType(exchange, String.class, inputStream);
        Message message = HL7Converter.parse(body, parser);

        // add MSH fields as message out headers
        Terser terser = new Terser(message);
        for (Map.Entry<String, String> entry : HEADER_MAP.entrySet()) {
            exchange.getOut().setHeader(entry.getKey(), terser.get(entry.getValue()));
        }
        return message;
    }

        assertTrue(xml.contains("<ORM_O01"));
        template.sendBody("direct:unmarshalOkXml", xml);

        assertMockEndpointsSatisfied();
        Message received = mock.getReceivedExchanges().get(0).getIn().getMandatoryBody(Message.class);
        assertEquals("O01", new Terser(received).get("MSH-9-2"));
    }   

        // 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"));
       
  }

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

        // 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"));
       
  }

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

      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);

TOP

Related Classes of ca.uhn.hl7v2.util.Terser

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.