Package ca.uhn.hl7v2.model

Examples of ca.uhn.hl7v2.model.Message


       
        DefaultValidator val = new DefaultValidator();
        try {
            String msgString = loadFile(args[0]);
            Parser parser = new GenericParser();
            Message message = parser.parse(msgString);
           
            String profileString = loadFile(args[1]);
            ProfileParser profParser = new ProfileParser(true);
            RuntimeProfile profile = profParser.parse(profileString);
           
View Full Code Here


      in.read(cbuf, 0, fileLength);
      String messageString = new String(cbuf);

      // parse inbound message ...
      final Parser parser = new PipeParser();
      Message inMessage = null;
      try {
        inMessage = parser.parse(messageString);
      } catch (HL7Exception e) {
        e.printStackTrace();
      }
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

     * @return acknowledgment to the request
     * @throws HL7Exception
     */
    protected Message generateResponseMessage(Object request) throws HL7Exception {
        try {
            Message in;
            if (request instanceof String) {
                Segment s = getHapiContext().getGenericParser().getCriticalResponseData(
                        (String)request);
                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

        // invoke it any time something goes wrong

        log.debug("ApplicationRouterImpl got message: {}", incomingMessageString);
        rawInbound.debug(incomingMessageString);

        Message incomingMessageObject = null;
        String outgoingMessageString = null;
        String outgoingMessageCharset = null;
        try {
            incomingMessageObject = myParser.parse(incomingMessageString);

            Terser inTerser = new Terser(incomingMessageObject);
            theMetadata.put(MetadataKeys.IN_MESSAGE_CONTROL_ID, inTerser.get("/.MSH-10"));

        } catch (HL7Exception e) {
            try {
                outgoingMessageString = logAndMakeErrorMessage(e, myParser.getCriticalResponseData(incomingMessageString), myParser, myParser.getEncoding(incomingMessageString));
            } catch (HL7Exception e2) {
                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);
View Full Code Here

        HL7Exception hl7e = e instanceof HL7Exception ?
                (HL7Exception) e :
                new HL7Exception(e.getMessage(), e);

        try {
            Message out = hl7e.getResponseMessage();
            if (out == null) {
                Message in = getInMessage(inHeader);
                out = in.generateACK(DEFAULT_EXCEPTION_ACKNOWLEDGEMENT_CODE, hl7e);
            }
            return encoding != null ? p.encode(out, encoding) : p.encode(out);

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

        }

    }

    private Message getInMessage(Segment inHeader) throws HL7Exception, IOException {
        Message in;
        if (inHeader != null) {
            in = inHeader.getMessage();
            // the message may be a dummy message, whose MSH segment is incomplete
            DeepCopy.copy(inHeader, (Segment) in.get("MSH"));
        } else {
            in = Version.highestAvailableVersionOrDefault().newGenericMessage(myParser.getFactory());
            ((GenericMessage) in).initQuickstart("ACK", "", "");
        }
        return in;
View Full Code Here

    if (!getParserConfiguration().isAllowUnknownVersions()) {
      assertVersionExists(version);
    }

    assertMessageValidates(message, encoding, version);
    Message result = doParse(message, version);
    assertMessageValidates(result);

    result.setParser(this);

    applySuperStructureName(result);
   
    return result;
  }
View Full Code Here

    String version = getVersion(message);
    assertVersionExists(version);

    assertMessageValidates(message, encoding, version);
    Message result = doParseForSpecificPackage(message, version, packageName);
    assertMessageValidates(result);

    result.setParser(this);
    return result;
  }
View Full Code Here

    try {
      Class<? extends Message> genericMessageClass;
      genericMessageClass = GenericMessage.getGenericMessageClass(version);
     
      Message dummy = genericMessageClass
          .getConstructor(new Class[] { ModelClassFactory.class })
          .newInstance(factory);

      Class<? extends Segment> c = null;
     
View Full Code Here

TOP

Related Classes of ca.uhn.hl7v2.model.Message

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.