Package ca.uhn.hl7v2

Examples of ca.uhn.hl7v2.HL7Exception


                    String elementName = makeGroupElementName(messageName, childNames[i]);
          Element childElement;
          try {
            childElement = groupElement.getOwnerDocument().createElement(elementName);
              } catch (DOMException e) {
                  throw new HL7Exception(
                      "Can't encode element " + elementName + " in group " + groupObject.getClass().getName(),
                      HL7Exception.APPLICATION_INTERNAL_ERROR,
                      e);
              }
                    groupElement.appendChild(childElement);
                    if (reps[j] instanceof Group) {
                        encode((Group) reps[j], childElement);
                    }
                    else if (reps[j] instanceof Segment) {
                        encode((Segment) reps[j], childElement);
                    }
                }
            }
        } catch (DOMException e) {
            throw new HL7Exception(
                "Can't encode group " + groupObject.getClass().getName(),
                HL7Exception.APPLICATION_INTERNAL_ERROR,
                e);
        }
    }
View Full Code Here


     * @param rep the repetition of the segment to return
     */
    public Segment getSegment(String namePattern, int rep) throws HL7Exception {
        Structure s = getStructure(namePattern, rep);
        if (!Segment.class.isAssignableFrom(s.getClass())) {
            throw new HL7Exception(s.getName() + " is not a segment", HL7Exception.APPLICATION_INTERNAL_ERROR);
        }
        return (Segment) s;
    }
View Full Code Here

     * As getSegment() but will only return a group.
     */
    public Group getGroup(String namePattern, int rep) throws HL7Exception {
        Structure s = getStructure(namePattern, rep);
        if (!Group.class.isAssignableFrom(s.getClass())) {
            throw new HL7Exception(s.getName() + " is not a group", HL7Exception.APPLICATION_INTERNAL_ERROR);
        }
        return (Group) s;
    }
View Full Code Here

                s = getCurrentStructure(rep);
            }
        }
       
        if (s == null)
            throw new HL7Exception("Can't find " + namePattern + " as a direct child", HL7Exception.APPLICATION_INTERNAL_ERROR);
       
        return s;
    }
View Full Code Here

        } else {
            ps.find = false;
        }

        if (spec.length() == 0) {
            throw new HL7Exception("Invalid path (some path element is either empty or contains only a dot)");
        }
        StringTokenizer tok = new StringTokenizer(spec, "()", false);
        ps.pattern = tok.nextToken();
        if (tok.hasMoreTokens()) {
            String repString = tok.nextToken();
            try {
                ps.rep = Integer.parseInt(repString);
            } catch (NumberFormatException e) {
                throw new HL7Exception(repString + " is not a valid rep #");
            }
        } else {
            ps.rep = 0;
        }
        return ps;
View Full Code Here

     */
    public static int[] getIndices(String spec) throws HL7Exception {
        StringTokenizer tok = new StringTokenizer(spec, "-", false);
        tok.nextToken(); // skip over segment
        if (!tok.hasMoreTokens())
            throw new HL7Exception("Must specify field in spec " + spec);
        try {
            StringTokenizer fieldSpec = new StringTokenizer(tok.nextToken(), "()", false);
            int fieldNum = Integer.parseInt(fieldSpec.nextToken());
            int fieldRep = fieldSpec.hasMoreTokens() ?
                    Integer.parseInt(fieldSpec.nextToken()) : 0;
            int component = tok.hasMoreTokens() ?
                    Integer.parseInt(tok.nextToken()) : 1;
            int subcomponent = tok.hasMoreTokens() ?
                    Integer.parseInt(tok.nextToken()) : 1;
            return new int[] { fieldNum, fieldRep, component, subcomponent };
        } catch (NumberFormatException e) {
            throw new HL7Exception("Invalid integer in spec " + spec);
        }
    }
View Full Code Here

     *
     */
    public final Message result() throws HL7Exception {
        Object validationSubject = getValidationSubject();
        if (validationSubject == null) {
            throw new HL7Exception("Need non-null validation subject");
        }
        Message response = generateResponseMessage(validationSubject);
        populateResponseMessage(response);
        return response;
    }
View Full Code Here

                in = s.getMessage();
                DeepCopy.copy(s, (Segment) in.get("MSH"));
            } else if (request instanceof Message) {
                in = (Message) request;
            } else {
                throw new HL7Exception("Validated message must be either Message or String");
            }
            return in.generateACK(getSuccessAcknowledgementCode(), null);

        } catch (IOException e) {
            throw new HL7Exception(e);
        }
    }
View Full Code Here

  protected Message instantiateMessageInASpecificPackage(String theName, String theVersion,
    boolean isExplicit, String packageName) throws HL7Exception {
    Class<? extends Message> messageClass = getFactory().getMessageClassInASpecificPackage(
        theName, theVersion, isExplicit, packageName);
    if (messageClass == null) {
      throw new HL7Exception("Can't find message class in current package list: " + theName);
    }
      return ReflectionUtil.instantiateMessage(messageClass, getFactory());
  }
View Full Code Here

                outgoingMessageString = null;
            }
            if (myExceptionHandler != null) {
                outgoingMessageString = myExceptionHandler.processException(incomingMessageString, theMetadata, outgoingMessageString, e);
                if (outgoingMessageString == null) {
                    throw new HL7Exception("Application exception handler may not return null");
                }
            }
        }

        // At this point, no exception has occurred and the message is processed normally
        if (outgoingMessageString == null) {
            try {
                //optionally check integrity of parse
                String check = System.getProperty("ca.uhn.hl7v2.protocol.impl.check_parse");
                if (check != null && check.equals("TRUE")) {
                    ParseChecker.checkParse(incomingMessageString, incomingMessageObject, myParser);
                }

                //message validation (in terms of optionality, cardinality) would go here ***

                ReceivingApplication app = findApplication(incomingMessageObject);
                theMetadata.put(RAW_MESSAGE_KEY, incomingMessageString);

                log.debug("Sending message to application: {}", app.toString());
                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(METADATA_KEY_MESSAGE_CHARSET);
            } catch (Exception e) {
                outgoingMessageString = handleProcessMessageException(incomingMessageString, theMetadata, incomingMessageObject, e);
            } catch (Error e) {
                log.debug("Caught runtime exception of type {}, going to wrap it as HL7Exception and handle it", e.getClass());
                HL7Exception wrapped = new HL7Exception(e);
                outgoingMessageString = handleProcessMessageException(incomingMessageString, theMetadata, incomingMessageObject, wrapped);
            }
        }

        log.debug("ApplicationRouterImpl sending message: {}", outgoingMessageString);
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.