Search in sources :

Example 81 with Message

use of com.google.api.services.healthcare.v1.model.Message in project camel by apache.

the class HL7MLLPEncoder method encode.

public void encode(IoSession session, Object message, ProtocolEncoderOutput out) 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());
    }
    // put the data into the byte buffer
    IoBuffer buf = IoBuffer.allocate(body.length + 3).setAutoExpand(true);
    buf.put((byte) config.getStartByte());
    buf.put(body);
    buf.put((byte) config.getEndByte1());
    buf.put((byte) config.getEndByte2());
    // flip the buffer so we can use it to write to the out stream
    buf.flip();
    LOG.debug("Encoded HL7 from {} to byte stream", message.getClass().getCanonicalName());
    out.write(buf);
}
Also used : Message(ca.uhn.hl7v2.model.Message) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Example 82 with Message

use of com.google.api.services.healthcare.v1.model.Message in project camel by apache.

the class HL7ValidateTest method testMarshalWithoutValidation.

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

Example 83 with Message

use of com.google.api.services.healthcare.v1.model.Message in project camel by apache.

the class HL7ValidateTest method testMarshalWithValidation.

@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();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) ValidationException(ca.uhn.hl7v2.validation.ValidationException) Message(ca.uhn.hl7v2.model.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) HL7Exception(ca.uhn.hl7v2.HL7Exception) Test(org.junit.Test)

Example 84 with Message

use of com.google.api.services.healthcare.v1.model.Message in project camel by apache.

the class MessageValidatorTest method testDynamicCustomValidationContext.

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

Example 85 with Message

use of com.google.api.services.healthcare.v1.model.Message in project camel by apache.

the class MessageValidatorTest method testCustomValidationContext.

@Test(expected = CamelExecutionException.class)
public void testCustomValidationContext() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:test2");
    mock.expectedMessageCount(0);
    Message msg = createADT01Message();
    template.sendBody("direct:test2", 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)114 Test (org.junit.Test)81 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)60 ORU_R01 (ca.uhn.hl7v2.model.v25.message.ORU_R01)30 NK1 (ca.uhn.hl7v2.model.v25.segment.NK1)21 Patient (org.openmrs.Patient)21 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)17 ORUR01Handler (org.openmrs.hl7.handler.ORUR01Handler)15 Person (org.openmrs.Person)14 ArrayList (java.util.ArrayList)13 HL7Exception (ca.uhn.hl7v2.HL7Exception)12 Concept (org.openmrs.Concept)12 Obs (org.openmrs.Obs)12 ObsService (org.openmrs.api.ObsService)11 QRD (ca.uhn.hl7v2.model.v24.segment.QRD)9 IOException (java.io.IOException)8 Encounter (org.openmrs.Encounter)8 RouteBuilder (org.apache.camel.builder.RouteBuilder)7 Structure (ca.uhn.hl7v2.model.Structure)5 CX (ca.uhn.hl7v2.model.v25.datatype.CX)5