Package ca.uhn.hl7v2

Examples of ca.uhn.hl7v2.HL7Exception


        for (int i = 0; i < errors.length; i++) {
            Throwable t = errors[i].getCause();
            if ((t != null) && (t instanceof HL7Exception)) {
                result[i] = (HL7Exception) t;
            } else {
                result[i] = new HL7Exception(errors[i]);
            }           
        }
       
        return result;
    }
View Full Code Here


        Application app = findApplication(incomingMessageObject);
        Message response = app.processMessage(incomingMessageObject);

        if (response == null) {
          throw new HL7Exception("Application of type " + app.getClass().getName() + " failed to return a response message from 'processMessage'");
        }
       
        // 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
View Full Code Here

      // 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 {
        errorMessage = p.encode(out);
      }

    } catch (IOException ioe) {
      throw new HL7Exception(
          "IOException creating error response message: "
              + ioe.getMessage(),
          HL7Exception.APPLICATION_INTERNAL_ERROR);
    }
    return errorMessage;
View Full Code Here

        try {
          type = tok.nextToken();
          event = tok.nextToken();
          className = tok.nextToken();
        } catch (NoSuchElementException ne) {
          throw new HL7Exception(
              "Can't register applications from file "
                  + f.getName()
                  + ". The line '"
                  + line
                  + "' is not of the form: message_type [tab] trigger_event [tab] application_class.",
              HL7Exception.APPLICATION_INTERNAL_ERROR);
        }

        try {
          @SuppressWarnings("unchecked")
          Class<? extends Application> appClass = (Class<? extends Application>) Class
              .forName(className); // may throw
                          // ClassNotFoundException
          Application app = appClass.newInstance();
          registerApplication(type, event, app);
        } catch (ClassCastException cce) {
          throw new HL7Exception("The specified class, " + className
              + ", doesn't implement Application.",
              HL7Exception.APPLICATION_INTERNAL_ERROR);
        }

      }
View Full Code Here

     * @throws IOException if there is a problem reading or writing the message ID file
     * @throws DataTypeException if there is a problem setting ACK values
     */
    public static Message makeACK(Segment inboundHeader) throws HL7Exception, IOException {
        if (!inboundHeader.getName().equals("MSH"))
            throw new HL7Exception(
                "Need an MSH segment to create a response ACK (got " + inboundHeader.getName() + ")");

        //make ACK of correct version
        String version = null;
        try {
            version = Terser.get(inboundHeader, 12, 0, 1, 1);
        }
        catch (HL7Exception e) { /* proceed with null */
        }
        if (version == null) version = "2.4";

        String ackClassName = DefaultModelClassFactory.getVersionPackageName(version) + "message.ACK";

        Message out = null;
        try {
            @SuppressWarnings("unchecked")
      Class<? extends Message> ackClass = (Class<? extends Message>) Class.forName(ackClassName);
            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");
View Full Code Here

     * used to create a unique message ID.  Version and message type fields are
     * not populated. 
     */
    public static void fillResponseHeader(Segment inbound, Segment outbound) throws HL7Exception, IOException {
        if (!inbound.getName().equals("MSH") || !outbound.getName().equals("MSH"))
            throw new HL7Exception("Need MSH segments.  Got " + inbound.getName() + " and " + outbound.getName());

        //get MSH data from incoming message ...       
        String encChars = Terser.get(inbound, 2, 0, 1, 1);
        String fieldSep = Terser.get(inbound, 1, 0, 1, 1);
        String procID = Terser.get(inbound, 11, 0, 1, 1);
View Full Code Here

   * returned to the calling thread on the basis of message ID.
   */
  public Message sendAndReceive(Message out) throws HL7Exception,
      LLPException, IOException {
    if (out == null) {
      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);
    }

    // log and send message
    String outbound = conn.getParser().encode(out);
    rawOutbound.debug(outbound);
    Future<String> inbound = null;
    try {
      String message = null;
      inbound = conn.waitForResponse(messID, timeoutMillis);
      conn.getSendWriter().writeMessage(outbound);
      if (inbound != null && (message = inbound.get()) != null) {
        // log that we got the message
        log.debug("Initiator received message: {}", message);
        rawInbound.debug(message);
        Message response = conn.getParser().parse(message);
        log.debug("response parsed");
        return response;
      }
    } catch (IOException e) {
      if (inbound != null)
        inbound.cancel(true);
      conn.close();
      throw e;
    } catch (InterruptedException e) {
    } catch (ExecutionException e) {
    }

    throw new HL7Exception(
        "Timeout waiting for response to message with control ID "
            + messID);
  }
View Full Code Here

        if (comps.length < 3) {
          buf.append(" HINT: there are only ");
          buf.append(comps.length);
          buf.append(" of 3 components present");
        }
        throw new HL7Exception(buf.toString(), ErrorCode.UNSUPPORTED_MESSAGE_TYPE);
      }
    } catch (IndexOutOfBoundsException e) {
      throw new HL7Exception("Can't find message structure (MSH-9-3): " + e.getMessage(), ErrorCode.UNSUPPORTED_MESSAGE_TYPE);
    }

    return new MessageStructure(messageStructure, explicityDefined);
  }
View Full Code Here

   *
   * @throws HL7Exception
   */
  private static EncodingCharacters getEncodingChars(String message) throws HL7Exception {
    if (message.length() < 8) {
      throw new HL7Exception("Invalid message content: \"" + message + "\"");
    }
    return new EncodingCharacters(message.charAt(3), message.substring(4, 8));
  }
View Full Code Here

    }

    if (theMessage instanceof SuperStructure) {
      Set<String> appliesTo = ((SuperStructure) theMessage).getStructuresWhichChildAppliesTo("MSH");
      if (!appliesTo.contains(theMessage.getName())) {
        throw new HL7Exception("Superstructure " + theMessage.getClass().getSimpleName() + " does not apply to message " + theMessage.getName() + ", can not parse.");
      }
    }
   
    if (clazz.isAnnotationPresent(DoNotCacheStructure.class)) {
      Holder<StructureDefinition> previousLeaf = new Holder<StructureDefinition>();
View Full Code Here

TOP

Related Classes of ca.uhn.hl7v2.HL7Exception

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.