Examples of Terser


Examples of ca.uhn.hl7v2.util.Terser

   
    /**
     * Returns the first Application that has been bound to messages of this type. 
     */
    private ReceivingApplication findApplication(Message theMessage) throws HL7Exception {
        Terser t = new Terser(theMessage);
        AppRoutingData msgData =
            new AppRoutingDataImpl(t.get("/MSH-9-1"), t.get("/MSH-9-2"), t.get("/MSH-11-1"), t.get("/MSH-12"));
           
        ReceivingApplication app = findDestination(msgData);
       
        //have to send back an application reject if no apps available to process
        if (app == null)

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

    public boolean validate(Message message) throws HL7Exception {
      if (message == null) {
        throw new NullPointerException("Message may not be null");
      }
     
        Terser t = new Terser(message);
       
        MessageRule[] rules = EMPTY_MESSAGE_RULES_ARRAY;
        if (myContext != null) {
          rules = myContext.getMessageRules(message.getVersion(), t.get("MSH-9-1"), t.get("MSH-9-2"));
        }
       
        ValidationException toThrow = null;
        boolean result = true;
        for (int i = 0; i < rules.length; i++) {

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

            out = DefaultApplication.makeACK(header);
        } catch (IOException e) {
            throw new HL7Exception(e);
        }
       
        Terser t = new Terser(out);
        t.set("/MSA-1", theAckCode);

        //TODO: when 2.5 is available, use 2.5 fields for remaining problems
        if (theErrorCode != HL7Exception.MESSAGE_ACCEPTED) {
            t.set("/MSA-3", theDescription.substring(0, Math.min(80, theDescription.length())));           
            t.set("/ERR-1-4-1", String.valueOf(theErrorCode));
            t.set("/ERR-1-4-3", "HL70357");
        }
       
        String originalEncoding = ourParser.getEncoding(theMessage.getMessage());
        String ackText = ourParser.encode(out, originalEncoding);
        return new TransportableImpl(ackText);

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

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

      String version = inbound.getVersion();
      if (version == null)
        version = "2.4"; // TODO: This should be set dynamically based on available HL7 version
      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", e);
    }

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