Search in sources :

Example 21 with Message

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

the class HL7MLLPNettyRouteToTest method createRouteBuilder.

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").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);
                }
            });
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) QRD(ca.uhn.hl7v2.model.v24.segment.QRD) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Message(ca.uhn.hl7v2.model.Message)

Example 22 with Message

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

the class HL7XmlDataFormatTest method testUnmarshalOkXml.

@Test
public void testUnmarshalOkXml() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:unmarshal");
    mock.expectedMessageCount(1);
    String body = createHL7AsString();
    Message msg = hl7.getParser().parse(body);
    String xml = hl7.getParser().encode(msg, "XML");
    assertTrue(xml.contains("<ORM_O01"));
    template.sendBody("direct:unmarshalOkXml", xml);
    assertMockEndpointsSatisfied();
    Message received = mock.getReceivedExchanges().get(0).getIn().getMandatoryBody(Message.class);
    assertEquals("O01", new Terser(received).get("MSH-9-2"));
}
Also used : Message(ca.uhn.hl7v2.model.Message) Terser(ca.uhn.hl7v2.util.Terser) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 23 with Message

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

the class TestHL7Query method createMessage.

private HL7Message createMessage(final String msgText) throws HL7Exception, IOException {
    final HapiContext hapiContext = new DefaultHapiContext();
    hapiContext.setValidationContext(ValidationContextFactory.noValidation());
    final PipeParser parser = hapiContext.getPipeParser();
    final Message message = parser.parse(msgText);
    return new HapiMessage(message);
}
Also used : HapiMessage(org.apache.nifi.hl7.hapi.HapiMessage) PipeParser(ca.uhn.hl7v2.parser.PipeParser) HapiMessage(org.apache.nifi.hl7.hapi.HapiMessage) Message(ca.uhn.hl7v2.model.Message) HL7Message(org.apache.nifi.hl7.model.HL7Message) DefaultHapiContext(ca.uhn.hl7v2.DefaultHapiContext) HapiContext(ca.uhn.hl7v2.HapiContext) DefaultHapiContext(ca.uhn.hl7v2.DefaultHapiContext)

Example 24 with Message

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

the class RouteHL7 method onTrigger.

@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
    FlowFile flowFile = session.get();
    if (flowFile == null) {
        return;
    }
    final Charset charset = Charset.forName(context.getProperty(CHARACTER_SET).evaluateAttributeExpressions(flowFile).getValue());
    final byte[] buffer = new byte[(int) flowFile.getSize()];
    session.read(flowFile, new InputStreamCallback() {

        @Override
        public void process(final InputStream in) throws IOException {
            StreamUtils.fillBuffer(in, buffer);
        }
    });
    @SuppressWarnings("resource") final HapiContext hapiContext = new DefaultHapiContext();
    hapiContext.setValidationContext((ca.uhn.hl7v2.validation.ValidationContext) ValidationContextFactory.noValidation());
    final PipeParser parser = hapiContext.getPipeParser();
    final String hl7Text = new String(buffer, charset);
    final HL7Message message;
    try {
        final Message hapiMessage = parser.parse(hl7Text);
        message = new HapiMessage(hapiMessage);
    } catch (final Exception e) {
        getLogger().error("Failed to parse {} as HL7 due to {}; routing to failure", new Object[] { flowFile, e });
        session.transfer(flowFile, REL_FAILURE);
        return;
    }
    final Set<String> matchingRels = new HashSet<>();
    final Map<Relationship, HL7Query> queryMap = queries;
    for (final Map.Entry<Relationship, HL7Query> entry : queryMap.entrySet()) {
        final Relationship relationship = entry.getKey();
        final HL7Query query = entry.getValue();
        final QueryResult result = query.evaluate(message);
        if (result.isMatch()) {
            FlowFile clone = session.clone(flowFile);
            clone = session.putAttribute(clone, "RouteHL7.Route", relationship.getName());
            session.transfer(clone, relationship);
            session.getProvenanceReporter().route(clone, relationship);
            matchingRels.add(relationship.getName());
        }
    }
    session.transfer(flowFile, REL_ORIGINAL);
    getLogger().info("Routed a copy of {} to {} relationships: {}", new Object[] { flowFile, matchingRels.size(), matchingRels });
}
Also used : HapiMessage(org.apache.nifi.hl7.hapi.HapiMessage) HapiMessage(org.apache.nifi.hl7.hapi.HapiMessage) Message(ca.uhn.hl7v2.model.Message) HL7Message(org.apache.nifi.hl7.model.HL7Message) QueryResult(org.apache.nifi.hl7.query.QueryResult) DefaultHapiContext(ca.uhn.hl7v2.DefaultHapiContext) HapiContext(ca.uhn.hl7v2.HapiContext) HashSet(java.util.HashSet) FlowFile(org.apache.nifi.flowfile.FlowFile) HL7Query(org.apache.nifi.hl7.query.HL7Query) PipeParser(ca.uhn.hl7v2.parser.PipeParser) InputStream(java.io.InputStream) Charset(java.nio.charset.Charset) HL7Message(org.apache.nifi.hl7.model.HL7Message) IOException(java.io.IOException) ProcessException(org.apache.nifi.processor.exception.ProcessException) IOException(java.io.IOException) HL7QueryParsingException(org.apache.nifi.hl7.query.exception.HL7QueryParsingException) DefaultHapiContext(ca.uhn.hl7v2.DefaultHapiContext) Relationship(org.apache.nifi.processor.Relationship) InputStreamCallback(org.apache.nifi.processor.io.InputStreamCallback) HashMap(java.util.HashMap) Map(java.util.Map)

Example 25 with Message

use of com.google.api.services.healthcare.v1.model.Message in project streamsx.health by IBMStreams.

the class AdtIngest method run.

@Override
public void run() {
    Topology topology = new Topology("AdtIngest");
    AdtToModelMapper mapper = new AdtToModelMapper();
    addDependencies(topology);
    HapiMessageSupplier supplier = new HapiMessageSupplier(getPort());
    supplier.setMessageClass(ADT_AXX.class);
    TStream<Message> messages = topology.endlessSource(supplier);
    // transform message to ADTEvent object
    TStream<ADTEvent> adtEvents = messages.multiTransform(message -> {
        return mapper.messageToModel(message);
    });
    // publish data as JSON
    PublishAdtEvent.publish(adtEvents, getTopic());
    try {
        StreamsContextFactory.getStreamsContext(StreamsContext.Type.DISTRIBUTED).submit(topology);
    } catch (Exception e) {
        TRACE.error("Unable to submit topology", e);
    }
}
Also used : Message(ca.uhn.hl7v2.model.Message) AdtToModelMapper(com.ibm.streamsx.health.hapi.mapper.AdtToModelMapper) ADTEvent(com.ibm.streamsx.health.ingest.types.model.ADTEvent) Topology(com.ibm.streamsx.topology.Topology) HapiMessageSupplier(com.ibm.streamsx.health.hapi.internal.HapiMessageSupplier)

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