Examples of Terser


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.toMessage(body);

        // add MSH fields as message out headers
        Terser terser = new Terser(message);
        exchange.getOut().setHeader("hl7.msh.sendingApplication", terser.get("MSH-3"));
        exchange.getOut().setHeader("hl7.msh.sendingFacility", terser.get("MSH-4"));
        exchange.getOut().setHeader("hl7.msh.receivingApplication", terser.get("MSH-5"));
        exchange.getOut().setHeader("hl7.msh.receivingFacility", terser.get("MSH-6"));
        exchange.getOut().setHeader("hl7.msh.timestamp", terser.get("MSH-7"));
        exchange.getOut().setHeader("hl7.msh.security", terser.get("MSH-8"));
        exchange.getOut().setHeader("hl7.msh.messageType", terser.get("MSH-9-1"));
        exchange.getOut().setHeader("hl7.msh.triggerEvent", terser.get("MSH-9-2"));
        exchange.getOut().setHeader("hl7.msh.messageControl", terser.get("MSH-10"));
        exchange.getOut().setHeader("hl7.msh.processingId", terser.get("MSH-11"));
        exchange.getOut().setHeader("hl7.msh.versionId", 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.toMessage(body);

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

    super();
    this.expression = expression;
  }

  public Object evaluate(Message msg) throws HL7Exception {
    return new Terser(msg).get(expression);
  }

Examples of ca.uhn.hl7v2.util.Terser

    }
   
    private void parse(StringTokenizer tok, Message message, StructRef root, EncodingCharacters ec)
            throws HL7Exception {
       
        Terser t = new Terser(message);
       
        synchronized (root) {
            StructRef ref = root.getSuccessor("MSH");           
           
            int field = 0;
            Segment segment = null;
            int[] fields = new int[0];
           
            while (tok.hasMoreTokens()) {
                String token = tok.nextToken();
                if (token.charAt(0) == ec.getFieldSeparator()) {
                    field++;
                } else if (token.charAt(0) == ourSegmentSeparator) {
                    field = 0;
                } else if (field == 0) {
                    StructRef newref = drill(ref, token);
                    if (newref == null) {
                        segment = null;
                        fields = new int[0];
                    } else {
                        ref = newref;
                        ourLog.debug("Parsing into segment {}", ref.getFullPath());
                        segment = t.getSegment(ref.getFullPath());
                        fields = ref.getFields();
                    }
                } else if (segment != null && Arrays.binarySearch(fields, field) >= 0) {
                    parse(token, segment, field, ec);
                }

Examples of ca.uhn.hl7v2.util.Terser

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

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(theMessage, msgData);

        //have to send back an application reject if no apps available to process
        if (app == null) {

Examples of ca.uhn.hl7v2.util.Terser

  }
 
  protected void applySuperStructureName(Message theMessage) throws HL7Exception {
        if (theMessage instanceof AbstractSuperMessage) {
          if (theMessage.getName() == null) {
            Terser t = new Terser(theMessage);
            String name = null;
        try {
          name = t.get("/MSH-9-3");
        } catch (HL7Exception e) {
          // ignore
        }
       
        if (StringUtil.isBlank(name)) {
          name = t.get("/MSH-9-1") + "_" + t.get("/MSH-9-2");
        }
       
        ((AbstractSuperMessage)theMessage).setName(name);
          }
        }

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

     *      form required by <code>Terser</code>. 
     * @return a Map from Terser paths to field values
     */
    public static Map getFields(Message theMessage, List theTerserPaths) throws HL7Exception {
        Map fields = new HashMap();
        Terser terser = new Terser(theMessage);
        for (int i = 0; i < theTerserPaths.size(); i++) {
            String path = (String) theTerserPaths.get(i);
            String fieldValue = terser.get(path);
            fields.put(path, fieldValue);
        }
        return fields;
    }

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