Search in sources :

Example 6 with Message

use of ca.uhn.hl7v2.model.Message in project camel by apache.

the class HL7ByteArrayRouteTest method createADR19Message.

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();
}
Also used : QRD(ca.uhn.hl7v2.model.v24.segment.QRD) MSH(ca.uhn.hl7v2.model.v24.segment.MSH) ADR_A19(ca.uhn.hl7v2.model.v24.message.ADR_A19) MSA(ca.uhn.hl7v2.model.v24.segment.MSA)

Example 7 with Message

use of ca.uhn.hl7v2.model.Message in project camel by apache.

the class HL7DataFormatTest method testUnmarshalWithExplicitUTF16Charset.

@Test
public void testUnmarshalWithExplicitUTF16Charset() throws Exception {
    String charset = "UTF-16";
    MockEndpoint mock = getMockEndpoint("mock:unmarshal");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);
    mock.expectedHeaderReceived(HL7Constants.HL7_CHARSET, HL7Charset.getHL7Charset(charset).getHL7CharsetName());
    mock.expectedHeaderReceived(Exchange.CHARSET_NAME, charset);
    // Message with explicit encoding in MSH-18
    byte[] body = createHL7WithCharsetAsString(HL7Charset.UTF_16).getBytes(Charset.forName(charset));
    template.sendBodyAndHeader("direct:unmarshal", new ByteArrayInputStream(body), Exchange.CHARSET_NAME, charset);
    assertMockEndpointsSatisfied();
    Message msg = mock.getExchanges().get(0).getIn().getBody(Message.class);
    assertEquals("2.4", msg.getVersion());
    QRD qrd = (QRD) msg.get("QRD");
    assertEquals("0101701234", qrd.getWhoSubjectFilter(0).getIDNumber().getValue());
}
Also used : QRD(ca.uhn.hl7v2.model.v24.segment.QRD) Message(ca.uhn.hl7v2.model.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 8 with Message

use of ca.uhn.hl7v2.model.Message in project camel by apache.

the class HL7DataFormatTest method testMarshal.

@Test
public void testMarshal() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:marshal");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(byte[].class);
    mock.message(0).body(String.class).contains("MSA|AA|123");
    mock.message(0).body(String.class).contains("QRD|20080805120000");
    Message message = createHL7AsMessage();
    template.sendBody("direct:marshal", message);
    assertMockEndpointsSatisfied();
}
Also used : Message(ca.uhn.hl7v2.model.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 9 with Message

use of ca.uhn.hl7v2.model.Message in project camel by apache.

the class MessageValidatorTest method testDefaultHapiContext.

@Test
public void testDefaultHapiContext() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:test4");
    mock.expectedMessageCount(1);
    Message msg = createADT01Message();
    template.sendBody("direct:test4", msg);
    assertMockEndpointsSatisfied();
}
Also used : Message(ca.uhn.hl7v2.model.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 10 with Message

use of ca.uhn.hl7v2.model.Message in project camel by apache.

the class MessageValidatorTest method testCustomHapiContext.

@Test(expected = CamelExecutionException.class)
public void testCustomHapiContext() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:test5");
    mock.expectedMessageCount(0);
    Message msg = createADT01Message();
    template.sendBody("direct:test5", msg);
    assertMockEndpointsSatisfied();
}
Also used : Message(ca.uhn.hl7v2.model.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Aggregations

Message (ca.uhn.hl7v2.model.Message)44 QRD (ca.uhn.hl7v2.model.v24.segment.QRD)19 Test (org.junit.Test)19 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)18 MSH (ca.uhn.hl7v2.model.v24.segment.MSH)13 ArrayList (java.util.ArrayList)12 HL7Exception (ca.uhn.hl7v2.HL7Exception)11 ADR_A19 (ca.uhn.hl7v2.model.v24.message.ADR_A19)9 MSA (ca.uhn.hl7v2.model.v24.segment.MSA)9 ADT_A01 (ca.uhn.hl7v2.model.v24.message.ADT_A01)7 PID (ca.uhn.hl7v2.model.v24.segment.PID)7 Exchange (org.apache.camel.Exchange)7 Processor (org.apache.camel.Processor)7 RouteBuilder (org.apache.camel.builder.RouteBuilder)7 Structure (ca.uhn.hl7v2.model.Structure)5 IOException (java.io.IOException)5 Group (ca.uhn.hl7v2.model.Group)4 Segment (ca.uhn.hl7v2.model.Segment)4 File (java.io.File)4 SegmentModel (org.talend.designer.hl7.model.SegmentModel)4