Examples of Terser


Examples of ca.uhn.hl7v2.util.Terser

    // create error message ...
    String errorMessage = null;
    try {
      Message out = DefaultApplication.makeACK(inHeader);
      Terser t = new Terser(out);

      // copy required data from incoming message ...
      try {
        t.set("/MSH-10", MessageIDGenerator.getInstance().getNewID());
      } catch (IOException ioe) {
        throw new HL7Exception("Problem creating error message ID: "
            + ioe.getMessage());
      }

      // populate MSA ...
      t.set("/MSA-1", "AE"); // should this come from HL7Exception
                  // constructor?
      t.set("/MSA-2", Terser.get(inHeader, 10, 0, 1, 1));
      String excepMessage = e.getMessage();
      if (excepMessage != null)
        t.set("/MSA-3",
            excepMessage.substring(0,
                Math.min(80, excepMessage.length())));

      /*
       * Some earlier ACKs don't have ERRs, but I think we'll change this
       * within HAPI so that there is a single ACK for each version (with
       * an ERR).
       */
      // see if it's an HL7Exception (so we can get specific information)
      // ...
      if (e.getClass().equals(HL7Exception.class)) {
        Segment err = (Segment) out.get("ERR");
        // ((HL7Exception) e).populate(err); // FIXME: this is broken,
        // it relies on the database in a place where it's not available
      } else {
        t.set("/ERR-1-4-1", "207");
        t.set("/ERR-1-4-2", "Application Internal Error");
        t.set("/ERR-1-4-3", "HL70357");
      }

      if (encoding != null) {
        errorMessage = p.encode(out, encoding);
      } else {

Examples of ca.uhn.hl7v2.util.Terser

            out = ackClass.newInstance();
        }
        catch (Exception e) {
            throw new HL7Exception("Can't instantiate ACK of class " + ackClassName + ": " + e.getClass().getName());
        }
        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", "ACK");
        terser.set("/MSH-12", version);
        terser.set("/MSA-1", "AA");
        terser.set("/MSA-2", Terser.get(inboundHeader, 10, 0, 1, 1));

        return out;
    }

Examples of ca.uhn.hl7v2.util.Terser

   * the type and trigger event of the given message, or null if there are
   * none.
   */
  private Application getMatchingApplication(Message message)
      throws HL7Exception {
    Terser t = new Terser(message);
    String messageType = t.get("/MSH-9-1");
    String triggerEvent = t.get("/MSH-9-2");
    return this.getMatchingApplication(messageType, triggerEvent);
  }

Examples of ca.uhn.hl7v2.util.Terser

      throw new HL7Exception("Can't encode null message",
          HL7Exception.REQUIRED_FIELD_MISSING);
    }

    // register message with response Receiver(s) (by message ID)
    Terser t = new Terser(out);
    String messID = t.get("/MSH-10");

    if (messID == null || messID.length() == 0) {
      throw new HL7Exception(
          "MSH segment missing required field Control ID (MSH-10)",
          HL7Exception.REQUIRED_FIELD_MISSING);

Examples of ca.uhn.hl7v2.util.Terser

            try {
              // get message ID
              String ID = MessageIDGenerator.getInstance()
                  .getNewID();
              Message out = parser.parse(outText);
              Terser tOut = new Terser(out);
              tOut.set("/MSH-10", ID);

              // send, get response
              Message in = initiator.sendAndReceive(out);
              // get ACK ID
              Terser tIn = new Terser(in);
              String ackID = tIn.get("/MSA-2");
              if (ID.equals(ackID)) {
                System.out.println("OK - ack ID matches");
              } else {
                throw new RuntimeException(
                    "Ack ID for message " + ID + " is "

Examples of ca.uhn.hl7v2.util.Terser

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

        // add MSH fields as message out headers
        Terser terser = new Terser(message);
        exchange.getOut().setHeader(HL7Constants.HL7_SENDING_APPLICATION, terser.get("MSH-3"));
        exchange.getOut().setHeader(HL7Constants.HL7_SENDING_FACILITY, terser.get("MSH-4"));
        exchange.getOut().setHeader(HL7Constants.HL7_RECEIVING_APPLICATION, terser.get("MSH-5"));
        exchange.getOut().setHeader(HL7Constants.HL7_RECEIVING_FACILITY, terser.get("MSH-6"));
        exchange.getOut().setHeader(HL7Constants.HL7_TIMESTAMP, terser.get("MSH-7"));
        exchange.getOut().setHeader(HL7Constants.HL7_SECURITY, terser.get("MSH-8"));
        exchange.getOut().setHeader(HL7Constants.HL7_MESSAGE_TYPE, terser.get("MSH-9-1"));
        exchange.getOut().setHeader(HL7Constants.HL7_TRIGGER_EVENT, terser.get("MSH-9-2"));
        exchange.getOut().setHeader(HL7Constants.HL7_MESSAGE_CONTROL, terser.get("MSH-10"));
        exchange.getOut().setHeader(HL7Constants.HL7_PROCESSING_ID, terser.get("MSH-11"));
        exchange.getOut().setHeader(HL7Constants.HL7_VERSION_ID, terser.get("MSH-12"));
        return message;
    }

Examples of ca.uhn.hl7v2.util.Terser

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

        // add MSH fields as message out headers
        Terser terser = new Terser(message);
        exchange.getOut().setHeader(HL7Constants.HL7_SENDING_APPLICATION, terser.get("MSH-3"));
        exchange.getOut().setHeader(HL7Constants.HL7_SENDING_FACILITY, terser.get("MSH-4"));
        exchange.getOut().setHeader(HL7Constants.HL7_RECEIVING_APPLICATION, terser.get("MSH-5"));
        exchange.getOut().setHeader(HL7Constants.HL7_RECEIVING_FACILITY, terser.get("MSH-6"));
        exchange.getOut().setHeader(HL7Constants.HL7_TIMESTAMP, terser.get("MSH-7"));
        exchange.getOut().setHeader(HL7Constants.HL7_SECURITY, terser.get("MSH-8"));
        exchange.getOut().setHeader(HL7Constants.HL7_MESSAGE_TYPE, terser.get("MSH-9-1"));
        exchange.getOut().setHeader(HL7Constants.HL7_TRIGGER_EVENT, terser.get("MSH-9-2"));
        exchange.getOut().setHeader(HL7Constants.HL7_MESSAGE_CONTROL, terser.get("MSH-10"));
        exchange.getOut().setHeader(HL7Constants.HL7_PROCESSING_ID, terser.get("MSH-11"));
        exchange.getOut().setHeader(HL7Constants.HL7_VERSION_ID, terser.get("MSH-12"));
        return message;
    }

Examples of ca.uhn.hl7v2.util.Terser

      throw new NullPointerException("Message may not be null");
    }
    if (handler == null) {
      throw new NullPointerException("ValidationExceptionHandler may not be null");
    }
    Terser t = new Terser(message);
    MessageRule[] rules = EMPTY_MESSAGE_RULES_ARRAY;
    if (context != null) {
      rules = context.getMessageRules(message.getVersion(), t.get("MSH-9-1"),
          t.get("MSH-9-2"));
    }
    LOG.debug("Validating message against {} message rules", rules.length);
    for (MessageRule rule : rules) {
      ValidationException[] ex = rule.test(message);
      if (ex != null && ex.length > 0) {

Examples of ca.uhn.hl7v2.util.Terser

    // create error message ...
    String errorMessage = null;
    try {
      Message out = DefaultApplication.makeACK(inHeader);
      Terser t = new Terser(out);

      // copy required data from incoming message ...
      try {
        t.set("/MSH-10", out.getParser().getParserConfiguration().getIdGenerator().getID());
      } catch (IOException ioe) {
        throw new HL7Exception("Problem creating error message ID: "
            + ioe.getMessage());
      }

      // populate MSA ...
      t.set("/MSA-1", "AE"); // should this come from HL7Exception
                  // constructor?
      t.set("/MSA-2", Terser.get(inHeader, 10, 0, 1, 1));
      String excepMessage = e.getMessage();
      if (excepMessage != null)
        t.set("/MSA-3",
            excepMessage.substring(0,
                Math.min(80, excepMessage.length())));

      /*
       * Some earlier ACKs don't have ERRs, but I think we'll change this
       * within HAPI so that there is a single ACK for each version (with
       * an ERR).
       */
      // see if it's an HL7Exception (so we can get specific information)
      // ...
      if (e.getClass().equals(HL7Exception.class)) {
//        Segment err = (Segment) out.get("ERR");
        // ((HL7Exception) e).populate(err); // FIXME: this is broken,
        // it relies on the database in a place where it's not available
      } else {
        t.set("/ERR-1-4-1", "207");
        t.set("/ERR-1-4-2", "Application Internal Error");
        t.set("/ERR-1-4-3", "HL70357");
      }

      if (encoding != null) {
        errorMessage = p.encode(out, encoding);
      } else {

Examples of ca.uhn.hl7v2.util.Terser

      throw new HL7Exception("Can't encode null message",
          HL7Exception.REQUIRED_FIELD_MISSING);
    }

    // register message with response Receiver(s) (by message ID)
    Terser t = new Terser(out);
    String messID = t.get("/MSH-10");

    if (messID == null || messID.length() == 0) {
      throw new HL7Exception(
          "MSH segment missing required field Control ID (MSH-10)",
          HL7Exception.REQUIRED_FIELD_MISSING);
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.