Java Code Examples for ca.uhn.hl7v2.model.Message

The following are top voted examples for showing how to use ca.uhn.hl7v2.model.Message. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: HL7Receiver   File: PSQLReader.java   View source code 6 votes vote down vote up
@Override
public Message next() throws IOException, HL7Exception {
    Message ret = null;

    while (psqlReaderNextmsg != null && ret == null) {
        Message nextMsg = psqlReaderNextmsg;
        readNextPsqlMessage();

        if (skipMessages) {
            Terser nextMsgTerser = new Terser(nextMsg);
            String currMSH10 = nextMsgTerser.get("/MSH-10");
            if (lastSuccessSendMsgId.compareTo(currMSH10) == 0) {
                LOG.info("Skip message (for the last time):" + currMSH10);
                skipMessages = false;
            } else {
                LOG.info("Skip message:" + currMSH10);
            }
        } else {
            ret = nextMsg;
        }
    }

    return ret;
}
 
Example 2
Project: HL7Receiver   File: HAPIReader.java   View source code 6 votes vote down vote up
@Override
public Message next() throws HL7Exception {
    Message ret = null;

    while (hapiIter.hasNext() && ret == null) {
        Message nextMsg = hapiIter.next();
        if (skipMessages) {
            Terser nextMsgTerser = new Terser(nextMsg);
            String currMSH10 = nextMsgTerser.get("/MSH-10");
            if (lastSuccessSendMsgId.compareTo(currMSH10) == 0) {
                LOG.info("Skip message (for the last time):" + currMSH10);
                skipMessages = false;
            } else {
                LOG.info("Skip message:" + currMSH10);
            }
        } else {
            ret = nextMsg;
        }
    }

    return ret;
}
 
Example 3
Project: hapi-spring-integration   File: HL7v24InboundMessageServiceImpl.java   View source code 6 votes vote down vote up
@Override
public Message processMessage(Message hapiMsg) {
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("I got a HAPI v2.4 message");
    ADT_A01 adtMsg = (ADT_A01) hapiMsg;
    MSH msh = adtMsg.getMSH();

    XPN[] xpns = adtMsg.getPID().getPatientName();

    for (XPN xpn : xpns) {
        System.out.println(xpn.toString());
    }
    return null;
}
 
Example 4
Project: hapi-spring-integration   File: HL7v23InboundMessageServiceImpl.java   View source code 6 votes vote down vote up
@Override
public Message processMessage(Message hapiMsg) {
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("I got a HAPI 2.3 message");
    ADT_A01 adtMsg = (ADT_A01)hapiMsg;

    PID pID = adtMsg.getPID();

    XPN xpn[] = pID.getPatientName();

    System.out.println(xpn[0].getGivenName().toString() + " " + xpn[0].getFamilyName().toString());
    return null;
}
 
Example 5
Project: hapi-spring-integration   File: HL7v25InboundMessageServiceImpl.java   View source code 6 votes vote down vote up
@Override
public Message processMessage(Message hapiMsg) {
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("#################################");
    System.out.println("I got a v25 HAPI message");
    ADT_A01 adtMsg = (ADT_A01)hapiMsg;
    MSH msh = adtMsg.getMSH();


    XPN[] xpns = adtMsg.getPID().getPatientName();

    for (XPN xpn : xpns ) {
        System.out.println(xpn.toString());
    }
    return null;
}
 
Example 6
Project: product-ei   File: SampleApp.java   View source code 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Message processMessage(Message theIn) throws ApplicationException, HL7Exception {

    String encodedMessage = new PipeParser().encode(theIn);
    System.out.println("Received message:\n" + encodedMessage + "\n\n");

    // Now we need to generate a message to return. This will generally be an ACK message.
    Segment msh = (Segment) theIn.get("MSH");
    Message retVal;
    try {
        // This method takes in the MSH segment of an incoming message, and generates an
        // appropriate ACK
        retVal = DefaultApplication.makeACK(msh);
    } catch (IOException e) {
        throw new HL7Exception(e);
    }

    return retVal;
}
 
Example 7
Project: Camel   File: HL7MLLPNettyEncoder.java   View source code 6 votes vote down vote up
@Override
protected void encode(ChannelHandlerContext channelHandlerContext, Object message, ByteBuf byteBuf) throws Exception {
    if (message == null) {
        throw new IllegalArgumentException("Message to be encoded is null");
    } else if (message instanceof Exception) {
        // we cannot handle exceptions
        throw (Exception) message;
    }

    byte[] body;
    if (message instanceof Message) {
        body = ((Message) message).encode().getBytes(config.getCharset());
    } else if (message instanceof String) {
        body = ((String) message).getBytes(config.getCharset());
    } else if (message instanceof byte[]) {
        body = (byte[]) message;
    } else {
        throw new IllegalArgumentException("The message to encode is not a supported type: "
                + message.getClass().getCanonicalName());
    }
    byteBuf.writeByte(config.getStartByte());
    byteBuf.writeBytes(body);
    byteBuf.writeByte(config.getEndByte1());
    byteBuf.writeByte(config.getEndByte2());
}
 
Example 8
Project: Camel   File: TerserLanguage.java   View source code 6 votes vote down vote up
public static Expression terser(final String expression) {
    ObjectHelper.notNull(expression, "expression");
    return new ExpressionAdapter() {

        @Override
        public Object evaluate(Exchange exchange) {
            Message message = exchange.getIn().getBody(Message.class);
            try {
                return new Terser(message).get(expression.trim());
            } catch (HL7Exception e) {
                throw ObjectHelper.wrapRuntimeCamelException(e);
            }
        }

        @Override
        public String toString() {
            return "terser(" + expression + ")";
        }

    };
}
 
Example 9
Project: Camel   File: HL7MLLPCodecLongTest.java   View source code 6 votes vote down vote up
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            from("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec").process(new Processor() {
                public void process(Exchange exchange) throws Exception {
                    assertEquals(70010, exchange.getIn().getBody(byte[].class).length);
                    MDM_T02 input = (MDM_T02)exchange.getIn().getBody(Message.class);
                    assertEquals("2.5", input.getVersion());
                    MSH msh = input.getMSH();
                    assertEquals("20071129144629", msh.getDateTimeOfMessage().getTime().getValue());
                    exchange.getOut().setBody("some response");
                }
            }).to("mock:result");
        }
    };
}
 
Example 10
Project: Camel   File: HL7MLLPNettyRouteToTest.java   View source code 6 votes vote down vote up
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            from("direct:start")
                .to("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&decoder=#hl7decoder&encoder=#hl7encoder")
                // because HL7 message contains a bunch of control chars then the logger do not log all of the data
                .log("HL7 message: ${body}")
                .to("mock:result");

            from("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&decoder=#hl7decoder&encoder=#hl7encoder")
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        Message input = exchange.getIn().getBody(Message.class);

                        assertEquals("2.4", input.getVersion());
                        QRD qrd = (QRD)input.get("QRD");
                        assertEquals("0101701234", qrd.getWhoSubjectFilter(0).getIDNumber().getValue());

                        Message response = createHL7AsMessage();
                        exchange.getOut().setBody(response);
                    }
                });
        }
    };
}
 
Example 11
Project: Camel   File: HL7MLLPNettyRouteToTest.java   View source code 6 votes vote down vote up
private static Message createHL7AsMessage() throws Exception {
    ADR_A19 adr = new ADR_A19();
    adr.initQuickstart("ADR", "A19", "P");

    // Populate the MSH Segment
    MSH mshSegment = adr.getMSH();
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getMessageControlID().setValue("456");

    // Populate the PID Segment
    MSA msa = adr.getMSA();
    msa.getAcknowledgementCode().setValue("AA");
    msa.getMessageControlID().setValue("123");

    QRD qrd = adr.getQRD();
    qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");

    return adr;
}
 
Example 12
Project: Camel   File: HL7MLLPCodecStandAndEndBytesTest.java   View source code 6 votes vote down vote up
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            from("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec")
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        Message input = exchange.getIn().getBody(Message.class);

                        assertEquals("2.4", input.getVersion());
                        QRD qrd = (QRD)input.get("QRD");
                        assertEquals("0101701234", qrd.getWhoSubjectFilter(0).getIDNumber().getValue());

                        Message response = createHL7AsMessage();
                        exchange.getOut().setBody(response);
                    }
                })
                .to("mock:result");
        }
    };
}
 
Example 13
Project: Camel   File: HL7MLLPCodecStandAndEndBytesTest.java   View source code 6 votes vote down vote up
private static Message createHL7AsMessage() throws Exception {
    ADR_A19 adr = new ADR_A19();

    // Populate the MSH Segment
    MSH mshSegment = adr.getMSH();
    mshSegment.getFieldSeparator().setValue("|");
    mshSegment.getEncodingCharacters().setValue("^~\\&");
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getSequenceNumber().setValue("123");
    mshSegment.getMessageType().getMessageType().setValue("ADR");
    mshSegment.getMessageType().getTriggerEvent().setValue("A19");

    // Populate the PID Segment
    MSA msa = adr.getMSA();
    msa.getAcknowledgementCode().setValue("AA");
    msa.getMessageControlID().setValue("123");

    QRD qrd = adr.getQRD();
    qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");

    return adr;
}
 
Example 14
Project: Camel   File: HL7RouteTest.java   View source code 6 votes vote down vote up
@Test
public void testSendA19() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:a19");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||QRY^A19|1234|P|2.4";
    String line2 = "QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    String out = template.requestBody("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec", in.toString(), String.class);

    String[] lines = out.split("\r");
    assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADR^A19||||123", lines[0]);
    assertEquals("MSA|AA|123", lines[1]);

    assertMockEndpointsSatisfied();
}
 
Example 15
Project: Camel   File: HL7RouteTest.java   View source code 6 votes vote down vote up
@Test
public void testSendA01() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:a01");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||ADT^A01|123|P|2.4";
    String line2 = "PID|||123456||Doe^John";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    String out = template.requestBody("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec", in.toString(), String.class);
    String[] lines = out.split("\r");
    assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADT^A01||||123", lines[0]);
    assertEquals("PID|||123||Doe^John", lines[1]);

    assertMockEndpointsSatisfied();
}
 
Example 16
Project: Camel   File: HL7RouteTest.java   View source code 6 votes vote down vote up
@Test
public void testSendUnknown() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:unknown");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||ADT^A02|1234|P|2.4";
    String line2 = "PID|||123456||Doe^John";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    template.requestBody("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec", in.toString());

    assertMockEndpointsSatisfied();
}
 
Example 17
Project: Camel   File: HL7RouteTest.java   View source code 6 votes vote down vote up
private static Message createADR19Message() throws Exception {
    ADR_A19 adr = new ADR_A19();

    // Populate the MSH Segment
    MSH mshSegment = adr.getMSH();
    mshSegment.getFieldSeparator().setValue("|");
    mshSegment.getEncodingCharacters().setValue("^~\\&");
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getSequenceNumber().setValue("123");
    mshSegment.getMessageType().getMessageType().setValue("ADR");
    mshSegment.getMessageType().getTriggerEvent().setValue("A19");

    // Populate the PID Segment
    MSA msa = adr.getMSA();
    msa.getAcknowledgementCode().setValue("AA");
    msa.getMessageControlID().setValue("123");

    QRD qrd = adr.getQRD();
    qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");

    return adr.getMessage();
}
 
Example 18
Project: Camel   File: HL7RouteTest.java   View source code 6 votes vote down vote up
private static Message createADT01Message(String msgId) throws Exception {
    ADT_A01 adt = new ADT_A01();

    // Populate the MSH Segment
    MSH mshSegment = adt.getMSH();
    mshSegment.getFieldSeparator().setValue("|");
    mshSegment.getEncodingCharacters().setValue("^~\\&");
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getSequenceNumber().setValue("123");
    mshSegment.getMessageType().getMessageType().setValue("ADT");
    mshSegment.getMessageType().getTriggerEvent().setValue("A01");

    // Populate the PID Segment
    PID pid = adt.getPID();
    pid.getPatientName(0).getFamilyName().getSurname().setValue("Doe");
    pid.getPatientName(0).getGivenName().setValue("John");
    pid.getPatientIdentifierList(0).getID().setValue(msgId);

    return adt;
}
 
Example 19
Project: Camel   File: HL7MLLPNettyCodecByteArrayRouteTest.java   View source code 6 votes vote down vote up
@Test
public void testSendA19() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:a19");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||QRY^A19|1234|P|2.4";
    String line2 = "QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    String out = template.requestBody("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&encoder=#hl7encoder&decoder=#hl7decoder", in.toString(), String.class);

    String[] lines = out.split("\r");
    assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADR^A19||||123|||||UNICODE UTF-8", lines[0]);
    assertEquals("MSA|AA|123", lines[1]);

    assertMockEndpointsSatisfied();
}
 
Example 20
Project: Camel   File: HL7MLLPNettyCodecByteArrayRouteTest.java   View source code 6 votes vote down vote up
@Test
public void testSendA01() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:a01");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||ADT^A01|123|P|2.4||||||UNICODE UTF-8";
    String line2 = "PID|||123456||Döe^John";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    String out = template.requestBody("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&encoder=#hl7encoder&decoder=#hl7decoder", in.toString(), String.class);
    String[] lines = out.split("\r");
    assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADT^A01||||123|||||UNICODE UTF-8", lines[0]);
    assertEquals("PID|||123||Döe^John", lines[1]);

    assertMockEndpointsSatisfied();
}
 
Example 21
Project: Camel   File: HL7MLLPNettyCodecByteArrayRouteTest.java   View source code 6 votes vote down vote up
@Test
public void testSendUnknown() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:unknown");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||ADT^A02|1234|P|2.4";
    String line2 = "PID|||123456||Döe^John";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    template.requestBody("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&encoder=#hl7encoder&decoder=#hl7decoder", in.toString());

    assertMockEndpointsSatisfied();
}
 
Example 22
Project: Camel   File: HL7MLLPNettyCodecByteArrayRouteTest.java   View source code 6 votes vote down vote up
private static Message createADR19Message() throws Exception {
    ADR_A19 adr = new ADR_A19();

    // Populate the MSH Segment
    MSH mshSegment = adr.getMSH();
    mshSegment.getFieldSeparator().setValue("|");
    mshSegment.getEncodingCharacters().setValue("^~\\&");
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getSequenceNumber().setValue("123");
    mshSegment.getMessageType().getMessageType().setValue("ADR");
    mshSegment.getMessageType().getTriggerEvent().setValue("A19");
    mshSegment.getCharacterSet(0).setValue("UNICODE UTF-8");

    // Populate the PID Segment
    MSA msa = adr.getMSA();
    msa.getAcknowledgementCode().setValue("AA");
    msa.getMessageControlID().setValue("123");

    QRD qrd = adr.getQRD();
    qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");

    return adr.getMessage();
}
 
Example 23
Project: Camel   File: HL7MLLPNettyCodecByteArrayRouteTest.java   View source code 6 votes vote down vote up
private static Message createADT01Message(String msgId) throws Exception {
    ADT_A01 adt = new ADT_A01();

    // Populate the MSH Segment
    MSH mshSegment = adt.getMSH();
    mshSegment.getFieldSeparator().setValue("|");
    mshSegment.getEncodingCharacters().setValue("^~\\&");
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getSequenceNumber().setValue("123");
    mshSegment.getMessageType().getMessageType().setValue("ADT");
    mshSegment.getMessageType().getTriggerEvent().setValue("A01");
    mshSegment.getCharacterSet(0).setValue("UNICODE UTF-8");

    // Populate the PID Segment
    PID pid = adt.getPID();
    pid.getPatientName(0).getFamilyName().getSurname().setValue("Döe");
    pid.getPatientName(0).getGivenName().setValue("John");
    pid.getPatientIdentifierList(0).getID().setValue(msgId);

    return adt;
}
 
Example 24
Project: Camel   File: HL7ValidateTest.java   View source code 6 votes vote down vote up
@Test
public void testMarshalWithValidation() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:end");
    mock.expectedMessageCount(0);

    Message message = createADT01Message();
    try {
        template.sendBody("direct:start1", message);
        fail("Should have thrown exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(HL7Exception.class, e.getCause());
        assertIsInstanceOf(ValidationException.class, e.getCause().getCause());
        System.out.println(e.getCause().getCause().getMessage());
        assertTrue("Should be a validation error message", e.getCause().getCause().getMessage().startsWith("Validation failed:"));
    }

    assertMockEndpointsSatisfied();
}
 
Example 25
Project: Camel   File: HL7MLLPNettyCodecTest.java   View source code 6 votes vote down vote up
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            from("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&decoder=#hl7decoder&encoder=#hl7encoder")
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        Message input = exchange.getIn().getBody(Message.class);

                        assertEquals("2.4", input.getVersion());
                        QRD qrd = (QRD)input.get("QRD");
                        assertEquals("0101701234", qrd.getWhoSubjectFilter(0).getIDNumber().getValue());

                        Message response = createHL7AsMessage();
                        exchange.getOut().setBody(response);
                    }
                })
                .to("mock:result");
        }
    };
}
 
Example 26
Project: Camel   File: HL7MLLPNettyCodecTest.java   View source code 6 votes vote down vote up
private static Message createHL7AsMessage() throws Exception {
    ADR_A19 adr = new ADR_A19();
    adr.initQuickstart("ADR", "A19", "P");

    // Populate the MSH Segment
    MSH mshSegment = adr.getMSH();
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getMessageControlID().setValue("456");

    // Populate the PID Segment
    MSA msa = adr.getMSA();
    msa.getAcknowledgementCode().setValue("AA");
    msa.getMessageControlID().setValue("123");

    QRD qrd = adr.getQRD();
    qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");

    return adr;
}
 
Example 27
Project: Camel   File: HL7NettyRouteTest.java   View source code 6 votes vote down vote up
@Test
public void testSendA19() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:a19");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||QRY^A19|1234|P|2.4";
    String line2 = "QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    String out = template.requestBody("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&decoder=#hl7decoder&encoder=#hl7encoder", in.toString(), String.class);

    String[] lines = out.split("\r");
    assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADR^A19||||123", lines[0]);
    assertEquals("MSA|AA|123", lines[1]);

    assertMockEndpointsSatisfied();
}
 
Example 28
Project: Camel   File: HL7NettyRouteTest.java   View source code 6 votes vote down vote up
@Test
public void testSendA01() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:a01");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||ADT^A01|123|P|2.4";
    String line2 = "PID|||123456||Doe^John";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    String out = template.requestBody("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&decoder=#hl7decoder&encoder=#hl7encoder", in.toString(), String.class);
    String[] lines = out.split("\r");
    assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADT^A01||||123", lines[0]);
    assertEquals("PID|||123||Doe^John", lines[1]);

    assertMockEndpointsSatisfied();
}
 
Example 29
Project: Camel   File: HL7NettyRouteTest.java   View source code 6 votes vote down vote up
@Test
public void testSendUnknown() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:unknown");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||ADT^A02|1234|P|2.4";
    String line2 = "PID|||123456||Doe^John";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    template.requestBody("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&decoder=#hl7decoder&encoder=#hl7encoder", in.toString());

    assertMockEndpointsSatisfied();
}
 
Example 30
Project: Camel   File: HL7NettyRouteTest.java   View source code 6 votes vote down vote up
private static Message createADR19Message() throws Exception {
    ADR_A19 adr = new ADR_A19();

    // Populate the MSH Segment
    MSH mshSegment = adr.getMSH();
    mshSegment.getFieldSeparator().setValue("|");
    mshSegment.getEncodingCharacters().setValue("^~\\&");
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getSequenceNumber().setValue("123");
    mshSegment.getMessageType().getMessageType().setValue("ADR");
    mshSegment.getMessageType().getTriggerEvent().setValue("A19");

    // Populate the PID Segment
    MSA msa = adr.getMSA();
    msa.getAcknowledgementCode().setValue("AA");
    msa.getMessageControlID().setValue("123");

    QRD qrd = adr.getQRD();
    qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");

    return adr.getMessage();
}
 
Example 31
Project: Camel   File: HL7MLLPNettyCodecStandAndEndBytesTest.java   View source code 6 votes vote down vote up
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            from("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&decoder=#hl7decoder&encoder=#hl7encoder")
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        Message input = exchange.getIn().getBody(Message.class);

                        assertEquals("2.4", input.getVersion());
                        QRD qrd = (QRD)input.get("QRD");
                        assertEquals("0101701234", qrd.getWhoSubjectFilter(0).getIDNumber().getValue());

                        Message response = createHL7AsMessage();
                        exchange.getOut().setBody(response);
                    }
                })
                .to("mock:result");
        }
    };
}
 
Example 32
Project: Camel   File: HL7MLLPNettyCodecStandAndEndBytesTest.java   View source code 6 votes vote down vote up
private static Message createHL7AsMessage() throws Exception {
    ADR_A19 adr = new ADR_A19();

    // Populate the MSH Segment
    MSH mshSegment = adr.getMSH();
    mshSegment.getFieldSeparator().setValue("|");
    mshSegment.getEncodingCharacters().setValue("^~\\&");
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getSequenceNumber().setValue("123");
    mshSegment.getMessageType().getMessageType().setValue("ADR");
    mshSegment.getMessageType().getTriggerEvent().setValue("A19");

    // Populate the PID Segment
    MSA msa = adr.getMSA();
    msa.getAcknowledgementCode().setValue("AA");
    msa.getMessageControlID().setValue("123");

    QRD qrd = adr.getQRD();
    qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");

    return adr;
}
 
Example 33
Project: Camel   File: HL7MLLPCodecTest.java   View source code 6 votes vote down vote up
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            from("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec")
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        Message input = exchange.getIn().getBody(Message.class);

                        assertEquals("2.4", input.getVersion());
                        QRD qrd = (QRD)input.get("QRD");
                        assertEquals("0101701234", qrd.getWhoSubjectFilter(0).getIDNumber().getValue());

                        Message response = createHL7AsMessage();
                        exchange.getOut().setBody(response);
                    }
                })
                .to("mock:result");
        }
    };
}
 
Example 34
Project: Camel   File: HL7MLLPCodecTest.java   View source code 6 votes vote down vote up
private static Message createHL7AsMessage() throws Exception {
    ADR_A19 adr = new ADR_A19();
    adr.initQuickstart("ADR", "A19", "P");

    // Populate the MSH Segment
    MSH mshSegment = adr.getMSH();
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getMessageControlID().setValue("456");

    // Populate the PID Segment
    MSA msa = adr.getMSA();
    msa.getAcknowledgementCode().setValue("AA");
    msa.getMessageControlID().setValue("123");

    QRD qrd = adr.getQRD();
    qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");

    return adr;
}
 
Example 35
Project: Camel   File: HL7ByteArrayRouteTest.java   View source code 6 votes vote down vote up
@Test
public void testSendA19() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:a19");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||QRY^A19|1234|P|2.4";
    String line2 = "QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    String out = template.requestBody("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec", in.toString(), String.class);

    String[] lines = out.split("\r");
    assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADR^A19||||123|||||UNICODE UTF-8", lines[0]);
    assertEquals("MSA|AA|123", lines[1]);

    assertMockEndpointsSatisfied();
}
 
Example 36
Project: Camel   File: HL7ByteArrayRouteTest.java   View source code 6 votes vote down vote up
@Test
public void testSendA01() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:a01");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||ADT^A01|123|P|2.4||||||UNICODE UTF-8";
    String line2 = "PID|||123456||Döe^John";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    String out = template.requestBody("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec", in.toString(), String.class);
    String[] lines = out.split("\r");
    assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADT^A01||||123|||||UNICODE UTF-8", lines[0]);
    assertEquals("PID|||123||Döe^John", lines[1]);

    assertMockEndpointsSatisfied();
}
 
Example 37
Project: Camel   File: HL7ByteArrayRouteTest.java   View source code 6 votes vote down vote up
@Test
public void testSendUnknown() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:unknown");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||ADT^A02|1234|P|2.4";
    String line2 = "PID|||123456||Döe^John";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    template.requestBody("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec", in.toString());

    assertMockEndpointsSatisfied();
}
 
Example 38
Project: Camel   File: HL7ByteArrayRouteTest.java   View source code 6 votes vote down vote up
private static Message createADR19Message() throws Exception {
    ADR_A19 adr = new ADR_A19();

    // Populate the MSH Segment
    MSH mshSegment = adr.getMSH();
    mshSegment.getFieldSeparator().setValue("|");
    mshSegment.getEncodingCharacters().setValue("^~\\&");
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getSequenceNumber().setValue("123");
    mshSegment.getMessageType().getMessageType().setValue("ADR");
    mshSegment.getMessageType().getTriggerEvent().setValue("A19");
    mshSegment.getCharacterSet(0).setValue("UNICODE UTF-8");

    // Populate the PID Segment
    MSA msa = adr.getMSA();
    msa.getAcknowledgementCode().setValue("AA");
    msa.getMessageControlID().setValue("123");

    QRD qrd = adr.getQRD();
    qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");

    return adr.getMessage();
}
 
Example 39
Project: Camel   File: HL7ByteArrayRouteTest.java   View source code 6 votes vote down vote up
private static Message createADT01Message(String msgId) throws Exception {
    ADT_A01 adt = new ADT_A01();

    // Populate the MSH Segment
    MSH mshSegment = adt.getMSH();
    mshSegment.getFieldSeparator().setValue("|");
    mshSegment.getEncodingCharacters().setValue("^~\\&");
    mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
    mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
    mshSegment.getSequenceNumber().setValue("123");
    mshSegment.getMessageType().getMessageType().setValue("ADT");
    mshSegment.getMessageType().getTriggerEvent().setValue("A01");
    mshSegment.getCharacterSet(0).setValue("UNICODE UTF-8");

    // Populate the PID Segment
    PID pid = adt.getPID();
    pid.getPatientName(0).getFamilyName().getSurname().setValue("Döe");
    pid.getPatientName(0).getGivenName().setValue("John");
    pid.getPatientIdentifierList(0).getID().setValue(msgId);

    return adt;
}
 
Example 40
Project: Camel   File: HL7MLLPNettyCodecLongTest.java   View source code 6 votes vote down vote up
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            from("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&encoder=#hl7encoder&decoder=#hl7decoder").process(new Processor() {
                public void process(Exchange exchange) throws Exception {
                    assertEquals(70010, exchange.getIn().getBody(byte[].class).length);
                    MDM_T02 input = (MDM_T02)exchange.getIn().getBody(Message.class);
                    assertEquals("2.5", input.getVersion());
                    MSH msh = input.getMSH();
                    assertEquals("20071129144629", msh.getDateTimeOfMessage().getTime().getValue());
                    exchange.getOut().setBody("some response");
                }
            }).to("mock:result");
        }
    };
}