Package ca.uhn.hl7v2.util

Examples of ca.uhn.hl7v2.util.MessageIterator$Position


    @Converter
    public static Message toMessage(String body) throws HL7Exception {
        // replace \n with \r as HL7 uses 0x0d = \r as segment terminators and HAPI only parses with \r
        body = body.replace('\n', '\r');

        Parser parser = new PipeParser();
        Message message = parser.parse(body);
        return message;
    }
View Full Code Here


        }

        // convert to string
        String body;
        if (message instanceof Message) {
            Parser parser = new PipeParser();
            body = parser.encode((Message)message);
        } else if (message instanceof String) {
            body = (String)message;
        } else if (message instanceof byte[]) {
            body = new String((byte[])message);
        } else {
View Full Code Here

        throw new UnsupportedOperationException("Not supported yet.");
  }
   
    public void parse(Message message, String string) throws HL7Exception {
        //MessagePointer ptr = new MessagePointer(this, m, getEncodingChars(message));
        MessageIterator messageIter = new MessageIterator(message, "MSH", true);
        FilterIterator.Predicate segmentsOnly = new FilterIterator.Predicate() {
            public boolean evaluate(Object obj) {
                if (Segment.class.isAssignableFrom(obj.getClass())) {
                    return true;
                } else {
                    return false;
                }
            }
        };
        FilterIterator segmentIter = new FilterIterator(messageIter, segmentsOnly);

        String[] segments = split(string, segDelim);

        char delim = '|';
        for (int i = 0; i < segments.length; i++) {

            //get rid of any leading whitespace characters ...
            if (segments[i] != null && segments[i].length() > 0 && Character.isWhitespace(segments[i].charAt(0)))
                segments[i] = stripLeadingWhitespace(segments[i]);

            //sometimes people put extra segment delimiters at end of msg ...
            if (segments[i] != null && segments[i].length() >= 3) {
                final String name;
                if (i == 0) {
                    name = segments[i].substring(0, 3);
                    delim = segments[i].charAt(3);
                } else {
                    if (segments[i].indexOf(delim) >= 0 ) {
                        name = segments[i].substring(0, segments[i].indexOf(delim));
                      } else {
                        name = segments[i];
                      }
                 }

                log.debug("Parsing segment {}", name);

                messageIter.setDirection(name);
                FilterIterator.Predicate byDirection = new FilterIterator.Predicate() {
                    public boolean evaluate(Object obj) {
                        Structure s = (Structure) obj;
                        log.debug("PipeParser iterating message in direction {} at {} ", name, s.getName());
                        return s.getName().matches(name + "\\d*");
 
View Full Code Here

        throw new UnsupportedOperationException("Not supported yet.");
  }
   
    public void parse(Message message, String string) throws HL7Exception {
        //MessagePointer ptr = new MessagePointer(this, m, getEncodingChars(message));
        MessageIterator messageIter = new MessageIterator(message, "MSH", true);
        FilterIterator.Predicate<Structure> segmentsOnly = new FilterIterator.Predicate<Structure>() {
            public boolean evaluate(Structure obj) {
                if (Segment.class.isAssignableFrom(obj.getClass())) {
                    return true;
                } else {
                    return false;
                }
            }
        };
        FilterIterator<Structure> segmentIter = new FilterIterator<Structure>(messageIter, segmentsOnly);

        String[] segments = split(string, segDelim);

        char delim = '|';
        for (int i = 0; i < segments.length; i++) {

            //get rid of any leading whitespace characters ...
            if (segments[i] != null && segments[i].length() > 0 && Character.isWhitespace(segments[i].charAt(0)))
                segments[i] = stripLeadingWhitespace(segments[i]);

            //sometimes people put extra segment delimiters at end of msg ...
            if (segments[i] != null && segments[i].length() >= 3) {
                final String name;
                if (i == 0) {
                    name = segments[i].substring(0, 3);
                    delim = segments[i].charAt(3);
                } else {
                    if (segments[i].indexOf(delim) >= 0 ) {
                        name = segments[i].substring(0, segments[i].indexOf(delim));
                      } else {
                        name = segments[i];
                      }
                 }

                log.debug("Parsing segment {}", name);

                messageIter.setDirection(name);
                FilterIterator.Predicate<Structure> byDirection = new FilterIterator.Predicate<Structure>() {
                    public boolean evaluate(Structure obj) {
                        Structure s = (Structure) obj;
                        log.debug("PipeParser iterating message in direction {} at {} ", name, s.getName());
                        return s.getName().matches(name + "\\d*");
 
View Full Code Here

        throw new UnsupportedOperationException("Not supported yet.");
  }
   
    public void parse(Message message, String string) throws HL7Exception {
        //MessagePointer ptr = new MessagePointer(this, m, getEncodingChars(message));
        MessageIterator messageIter = new MessageIterator(message, "MSH", true);
        FilterIterator.Predicate<Structure> segmentsOnly = new FilterIterator.Predicate<Structure>() {
            public boolean evaluate(Structure obj) {
                if (Segment.class.isAssignableFrom(obj.getClass())) {
                    return true;
                } else {
                    return false;
                }
            }
        };
        FilterIterator<Structure> segmentIter = new FilterIterator<Structure>(messageIter, segmentsOnly);

        String[] segments = split(string, segDelim);

        char delim = '|';
        for (int i = 0; i < segments.length; i++) {

            //get rid of any leading whitespace characters ...
            if (segments[i] != null && segments[i].length() > 0 && Character.isWhitespace(segments[i].charAt(0)))
                segments[i] = stripLeadingWhitespace(segments[i]);

            //sometimes people put extra segment delimiters at end of msg ...
            if (segments[i] != null && segments[i].length() >= 3) {
                final String name;
                if (i == 0) {
                    name = segments[i].substring(0, 3);
                    delim = segments[i].charAt(3);
                } else {
                    if (segments[i].indexOf(delim) >= 0 ) {
                        name = segments[i].substring(0, segments[i].indexOf(delim));
                      } else {
                        name = segments[i];
                      }
                 }

                log.debug("Parsing segment {}", name);

                messageIter.setDirection(name);
                FilterIterator.Predicate<Structure> byDirection = new FilterIterator.Predicate<Structure>() {
                    public boolean evaluate(Structure obj) {
                        Structure s = (Structure) obj;
                        log.debug("PipeParser iterating message in direction {} at {} ", name, s.getName());
                        return s.getName().matches(name + "\\d*");
 
View Full Code Here

        throw new UnsupportedOperationException("Not supported yet.");
  }
   
    public void parse(Message message, String string) throws HL7Exception {
        //MessagePointer ptr = new MessagePointer(this, m, getEncodingChars(message));
        MessageIterator messageIter = new MessageIterator(message, "MSH", true);
        FilterIterator.Predicate<Structure> segmentsOnly = new FilterIterator.Predicate<Structure>() {
            public boolean evaluate(Structure obj) {
                if (Segment.class.isAssignableFrom(obj.getClass())) {
                    return true;
                } else {
                    return false;
                }
            }
        };
        FilterIterator<Structure> segmentIter = new FilterIterator<Structure>(messageIter, segmentsOnly);

        String[] segments = split(string, segDelim);

        char delim = '|';
        for (int i = 0; i < segments.length; i++) {

            //get rid of any leading whitespace characters ...
            if (segments[i] != null && segments[i].length() > 0 && Character.isWhitespace(segments[i].charAt(0)))
                segments[i] = stripLeadingWhitespace(segments[i]);

            //sometimes people put extra segment delimiters at end of msg ...
            if (segments[i] != null && segments[i].length() >= 3) {
                final String name;
                if (i == 0) {
                    name = segments[i].substring(0, 3);
                    delim = segments[i].charAt(3);
                } else {
                    if (segments[i].indexOf(delim) >= 0 ) {
                        name = segments[i].substring(0, segments[i].indexOf(delim));
                      } else {
                        name = segments[i];
                      }
                 }

                log.debug("Parsing segment {}", name);

                messageIter.setDirection(name);
                FilterIterator.Predicate<Structure> byDirection = new FilterIterator.Predicate<Structure>() {
                    public boolean evaluate(Structure obj) {
                        Structure s = (Structure) obj;
                        log.debug("PipeParser iterating message in direction {} at {} ", name, s.getName());
                        return s.getName().matches(name + "\\d*");
 
View Full Code Here

        return encode(type, encodingCharacters);
    }

    public void parse(Message message, String string) throws HL7Exception {
        //MessagePointer ptr = new MessagePointer(this, m, getEncodingChars(message));
        MessageIterator messageIter = new MessageIterator(message, "MSH", true);
        FilterIterator.Predicate segmentsOnly = new FilterIterator.Predicate() {
            public boolean evaluate(Object obj) {
                if (Segment.class.isAssignableFrom(obj.getClass())) {
                    return true;
                } else {
                    return false;
                }
            }
        };
        FilterIterator segmentIter = new FilterIterator(messageIter, segmentsOnly);

        String[] segments = split(string, segDelim);

        char delim = '|';
        for (int i = 0; i < segments.length; i++) {

            //get rid of any leading whitespace characters ...
            if (segments[i] != null && segments[i].length() > 0 && Character.isWhitespace(segments[i].charAt(0)))
                segments[i] = stripLeadingWhitespace(segments[i]);

            //sometimes people put extra segment delimiters at end of msg ...
            if (segments[i] != null && segments[i].length() >= 3) {
                final String name;
                if (i == 0) {
                    name = segments[i].substring(0, 3);
                    delim = segments[i].charAt(3);
                } else {
                    if (segments[i].indexOf(delim) >= 0 ) {
                        name = segments[i].substring(0, segments[i].indexOf(delim));
                      } else {
                        name = segments[i];
                      }
                 }

                log.debug("Parsing segment " + name);

                messageIter.setDirection(name);
                FilterIterator.Predicate byDirection = new FilterIterator.Predicate() {
                    public boolean evaluate(Object obj) {
                        Structure s = (Structure) obj;
                        log.debug("PipeParser iterating message in direction " + name + " at " + s.getName());
                        if (s.getName().matches(name + "\\d*")) {
View Full Code Here

  protected Message doParseForSpecificPackage(String theMessage, String theVersion, String thePackageName) throws HL7Exception, EncodingNotSupportedException {
        throw new UnsupportedOperationException("Not supported yet.");
  }
   
    public void parse(Message message, String string) throws HL7Exception {
        MessageIterator messageIter = new MessageIterator(message, "MSH", true);
        FilterIterator.Predicate<Structure> segmentsOnly = new FilterIterator.Predicate<Structure>() {
            public boolean evaluate(Structure obj) {
                if (Segment.class.isAssignableFrom(obj.getClass())) {
                    return true;
                } else {
                    return false;
                }
            }
        };
        FilterIterator<Structure> segmentIter = new FilterIterator<Structure>(messageIter, segmentsOnly);

        String[] segments = split(string, segDelim);

        char delim = '|';
        for (int i = 0; i < segments.length; i++) {

            //get rid of any leading whitespace characters ...
            if (segments[i] != null && segments[i].length() > 0 && Character.isWhitespace(segments[i].charAt(0)))
                segments[i] = stripLeadingWhitespace(segments[i]);

            //sometimes people put extra segment delimiters at end of msg ...
            if (segments[i] != null && segments[i].length() >= 3) {
                final String name;
                if (i == 0) {
                    name = segments[i].substring(0, 3);
                    delim = segments[i].charAt(3);
                } else {
                    if (segments[i].indexOf(delim) >= 0 ) {
                        name = segments[i].substring(0, segments[i].indexOf(delim));
                      } else {
                        name = segments[i];
                      }
                 }

                log.debug("Parsing segment {}", name);

                messageIter.setDirection(name);
                FilterIterator.Predicate<Structure> byDirection = new FilterIterator.Predicate<Structure>() {
                    public boolean evaluate(Structure obj) {
                        Structure s = (Structure) obj;
                        log.debug("PipeParser iterating message in direction {} at {} ", name, s.getName());
                        return s.getName().matches(name + "\\d*");
 
View Full Code Here

    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;
    }
View Full Code Here

    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;
    }
View Full Code Here

TOP

Related Classes of ca.uhn.hl7v2.util.MessageIterator$Position

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.