Package model

Examples of model.Message


* @see org.apache.camel.component.hl7.HL7MLLPCodec
*/
public class HL7DataFormat implements DataFormat {

    public void marshal(Exchange exchange, Object body, OutputStream outputStream) throws Exception {
        Message message = ExchangeHelper.convertToMandatoryType(exchange, Message.class, body);
        String encoded = HL7Converter.toString(message);
        outputStream.write(encoded.getBytes());
    }
View Full Code Here


        outputStream.write(encoded.getBytes());
    }

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

    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

    /**
     * @see ca.uhn.hl7v2.parser.Parser#doParse(java.lang.String, java.lang.String)
     */
    protected Message doParse(String message, String version) throws HL7Exception, EncodingNotSupportedException {
        Message result = null;
       
        char fieldSep = message.charAt(3);
        EncodingCharacters ec = new EncodingCharacters(fieldSep, message.substring(4, 8));
       
        StringTokenizer tok = new StringTokenizer(message.substring(4),
                String.valueOf(new char[]{fieldSep, ourSegmentSeparator}), true);
       
        String[] mshFields = getMSHFields(tok, fieldSep);
        Object[] structure = getStructure(mshFields[8], ec.getComponentSeparator());
       
        StructRef root = (StructRef) myEventGuideMap.get(structure[0]);
        if (root == null) {
            ourLog.debug("FastParser delegating to PipeParser because no metadata available for event {}",
                    structure[0]);
            result = myPipeParser.parse(message);
        } else {
            int csIndex = mshFields[11].indexOf(ec.getComponentSeparator());
            result = instantiateMessage((String) structure[1], version, ((Boolean) structure[2]).booleanValue());
               
            StructRef mshRef = null;
            synchronized (root) {
                mshRef = root.getSuccessor("MSH");
                root.reset();
            }
            Segment msh = (Segment) result.get("MSH");
            for (int i = 0; i < mshRef.getFields().length; i++) {
                int fieldNum = mshRef.getFields()[i];
                parse(mshFields[fieldNum-1], msh, fieldNum, ec);
            }           
           
View Full Code Here

            FileReader r = new FileReader(messageFile);
            char[] cbuf = new char[(int)fileLength];
            System.out.println("Reading message file ... " + r.read(cbuf) + " of " + fileLength + " chars");
            r.close();
            String messString = String.valueOf(cbuf);
            Message mess = parser.parse(messString);
            System.out.println("Got message of type " + mess.getClass().getName());
            showInNewWindow(mess);
           
            //write message to console ...
            System.out.println(parser.encode(mess, "VB"));
        } catch (Exception e) {
View Full Code Here

     * @return null if it parses correctly, an HL7Exception otherwise
     */
    public static HL7Exception parsesCorrectly(String context, String message) {
        HL7Exception problem = null;
        try {
            Message m = parser.parse(message);
            String encoding = parser.getEncoding(message);
            String result = parser.encode(m, encoding);
            if (!EncodedMessageComparator.equivalent(message, result)) {
                problem = new HL7Exception(context + ": Original differs semantically from parsed/encoded message.\r\n-----Original:------------\r\n"
                    + message + " \r\n------ Parsed/Encoded: ----------\r\n" + result + " \r\n-----Original Standardized: ---------\r\n"
View Full Code Here

     * object.  This method checks that the given message string is XML encoded, creates an
     * XML Document object (using Xerces) from the given String, and calls the abstract
     * method <code>parse(Document XMLMessage)</code></p>
     */
    protected Message doParse(String message, String version) throws HL7Exception, EncodingNotSupportedException {
        Message m = null;

        //parse message string into a DOM document
        try {
            Document doc = null;
            synchronized (this) {
View Full Code Here

            FileReader r = new FileReader(messageFile);
            char[] cbuf = new char[(int) fileLength];
            System.out.println("Reading message file ... " + r.read(cbuf) + " of " + fileLength + " chars");
            r.close();
            String messString = String.valueOf(cbuf);
            Message mess = parser.parse(messString);
            System.out.println("Got message of type " + mess.getClass().getName());

            ca.uhn.hl7v2.parser.XMLParser xp = new XMLParser() {
                public Message parseDocument(Document XMLMessage, String version) throws HL7Exception {
                    return null;
                }
                public Document encodeDocument(Message source) throws HL7Exception {
                    return null;
                }
                public String getVersion(String message) throws HL7Exception {
                    return null;
                }

                @Override
                public String doEncode(Segment structure, EncodingCharacters encodingCharacters) throws HL7Exception {
                    throw new UnsupportedOperationException("Not supported yet.");
                }

                @Override
                public String doEncode(Type type, EncodingCharacters encodingCharacters) throws HL7Exception {
                    throw new UnsupportedOperationException("Not supported yet.");
                }

                @Override
                public void parse(Type type, String string, EncodingCharacters encodingCharacters) throws HL7Exception {
                    throw new UnsupportedOperationException("Not supported yet.");
                }

                @Override
                public void parse(Segment segment, String string, EncodingCharacters encodingCharacters) throws HL7Exception {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
        @Override
        protected Message doParseForSpecificPackage(String theMessage, String theVersion, String thePackageName) throws HL7Exception, EncodingNotSupportedException {
                    throw new UnsupportedOperationException("Not supported yet.");
        }
            };

            //loop through segment children of message, encode, print to console
            String[] structNames = mess.getNames();
            for (int i = 0; i < structNames.length; i++) {
                Structure[] reps = mess.getAll(structNames[i]);
                for (int j = 0; j < reps.length; j++) {
                    if (Segment.class.isAssignableFrom(reps[j].getClass())) { //ignore groups
                        DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                        Document doc = docBuilder.newDocument(); //new doc for each segment
                        Element root = doc.createElement(reps[j].getClass().getName());
View Full Code Here

     * @throws EncodingNotSupportedException if the message encoded
     *     is not supported by this parser.
     */
    public Message parseDocument(org.w3c.dom.Document XMLMessage, String version) throws HL7Exception {
        String messageName = XMLMessage.getDocumentElement().getTagName();
        Message message = instantiateMessage(messageName, version, true);
        parse(message, XMLMessage.getDocumentElement());
        return message;
    }
View Full Code Here

            else if (xp.getEncoding(messString) != null) {
                inParser = xp;
                outParser = pp;
            }

            Message mess = inParser.parse(messString);
            System.out.println("Got message of type " + mess.getClass().getName());

            String otherEncoding = outParser.encode(mess);
            System.out.println(otherEncoding);
        }
        catch (Exception e) {
View Full Code Here

TOP

Related Classes of 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.