Search in sources :

Example 76 with Message

use of bind.feature.generichierarchy.case1.model.Message in project tdi-studio-se by Talend.

the class HL7PublicUtil method getChildList.

public Object[] getChildList(Object parentElement) {
    List values = new ArrayList();
    if (parentElement instanceof Message) {
        Message messParent = (Message) parentElement;
        String[] childNames = messParent.getNames();
        if (!values.isEmpty()) {
            values.clear();
        }
        for (int i = 0; i < childNames.length; i++) {
            try {
                Structure[] childReps = messParent.getAll(childNames[i]);
                for (int j = 0; j < childReps.length; j++) {
                    if (childReps[j] instanceof Message) {
                        values.add(childReps[j]);
                    }
                    if (childReps[j] instanceof Group) {
                        allSegmentFromGroup.clear();
                        getAllSegmentsFromGroup((Group) childReps[j]);
                        if (allSegmentFromGroup.size() > 0) {
                            values.addAll(Arrays.asList(allSegmentFromGroup.toArray(new SegmentModel[0])));
                        }
                    }
                    if (childReps[j] instanceof Segment) {
                        SegmentModel sModel = new SegmentModel((Segment) childReps[j], messParent, i, j);
                        if (sModel.getTypes() != null && sModel.getTypes().length > 0) {
                            values.add(sModel);
                            if (!allSegmentsForMessage.contains(sModel)) {
                                allSegmentsForMessage.add(sModel);
                            }
                        }
                    }
                }
            // values.addAll(Arrays.asList(childReps));
            } catch (HL7Exception e) {
                e.printStackTrace();
            }
        }
        return values.toArray();
    }
    if (parentElement instanceof Segment) {
        values.clear();
        Segment segment = (Segment) parentElement;
        SegmentModel sm = new SegmentModel(segment, segment, 0, 0);
        return sm.getTypes();
    }
    if (parentElement instanceof SegmentModel) {
        SegmentModel sm = (SegmentModel) parentElement;
        return sm.getTypes();
    }
    if (parentElement instanceof TypeModel) {
        TypeModel tm = (TypeModel) parentElement;
        return tm.getPrimitives();
    }
    if (parentElement instanceof Group) {
        values.clear();
        Group group = (Group) parentElement;
        String[] childNames = group.getNames();
        for (int i = 0; i < childNames.length; i++) {
            try {
                Structure[] childReps = group.getAll(childNames[i]);
                for (int j = 0; j < childReps.length; j++) {
                    if (childReps[j] instanceof Segment) {
                        SegmentModel sm = new SegmentModel((Segment) childReps[j], group, i, j);
                        if (sm.getTypes() != null && sm.getTypes().length > 0) {
                            values.add(sm);
                        }
                    } else {
                        values.add(childReps[j]);
                    }
                }
            // values.addAll(Arrays.asList(childReps));
            } catch (HL7Exception e) {
                e.printStackTrace();
            }
        }
        return values.toArray();
    }
    return new Object[0];
}
Also used : Group(ca.uhn.hl7v2.model.Group) Message(ca.uhn.hl7v2.model.Message) ArrayList(java.util.ArrayList) TypeModel(org.talend.designer.hl7.model.TypeModel) Segment(ca.uhn.hl7v2.model.Segment) HL7Exception(ca.uhn.hl7v2.HL7Exception) ArrayList(java.util.ArrayList) List(java.util.List) Structure(ca.uhn.hl7v2.model.Structure) SegmentModel(org.talend.designer.hl7.model.SegmentModel)

Example 77 with Message

use of bind.feature.generichierarchy.case1.model.Message in project nifi by apache.

the class ExtractHL7Attributes 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 Boolean useSegmentNames = context.getProperty(USE_SEGMENT_NAMES).asBoolean();
    final Boolean parseSegmentFields = context.getProperty(PARSE_SEGMENT_FIELDS).asBoolean();
    final Boolean skipValidation = context.getProperty(SKIP_VALIDATION).asBoolean();
    final String inputVersion = context.getProperty(HL7_INPUT_VERSION).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();
    if (!inputVersion.equals("autodetect")) {
        hapiContext.setModelClassFactory(new CanonicalModelClassFactory(inputVersion));
    }
    if (skipValidation) {
        hapiContext.setValidationContext((ValidationContext) ValidationContextFactory.noValidation());
    }
    final PipeParser parser = hapiContext.getPipeParser();
    final String hl7Text = new String(buffer, charset);
    try {
        final Message message = parser.parse(hl7Text);
        final Map<String, String> attributes = getAttributes(message, useSegmentNames, parseSegmentFields);
        flowFile = session.putAllAttributes(flowFile, attributes);
        getLogger().debug("Added the following attributes for {}: {}", new Object[] { flowFile, attributes });
    } catch (final HL7Exception e) {
        getLogger().error("Failed to extract attributes from {} due to {}", new Object[] { flowFile, e });
        session.transfer(flowFile, REL_FAILURE);
        return;
    }
    session.transfer(flowFile, REL_SUCCESS);
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) PipeParser(ca.uhn.hl7v2.parser.PipeParser) Message(ca.uhn.hl7v2.model.Message) InputStream(java.io.InputStream) Charset(java.nio.charset.Charset) IOException(java.io.IOException) CanonicalModelClassFactory(ca.uhn.hl7v2.parser.CanonicalModelClassFactory) DefaultHapiContext(ca.uhn.hl7v2.DefaultHapiContext) InputStreamCallback(org.apache.nifi.processor.io.InputStreamCallback) HL7Exception(ca.uhn.hl7v2.HL7Exception) DefaultHapiContext(ca.uhn.hl7v2.DefaultHapiContext) HapiContext(ca.uhn.hl7v2.HapiContext)

Example 78 with Message

use of bind.feature.generichierarchy.case1.model.Message in project camel by apache.

the class AckExpression method evaluate.

@Override
public Object evaluate(Exchange exchange) {
    Throwable t = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
    Message msg = exchange.getIn().getBody(Message.class);
    try {
        HL7Exception hl7e = generateHL7Exception(t);
        AcknowledgmentCode code = acknowledgementCode;
        if (t != null && code == null) {
            code = AcknowledgmentCode.AE;
        }
        return msg.generateACK(code == null ? AcknowledgmentCode.AA : code, hl7e);
    } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
}
Also used : Message(ca.uhn.hl7v2.model.Message) HL7Exception(ca.uhn.hl7v2.HL7Exception) AcknowledgmentCode(ca.uhn.hl7v2.AcknowledgmentCode) HL7Exception(ca.uhn.hl7v2.HL7Exception)

Example 79 with Message

use of bind.feature.generichierarchy.case1.model.Message in project camel by apache.

the class HL7DataFormat method marshal.

public void marshal(Exchange exchange, Object body, OutputStream outputStream) throws Exception {
    Message message = ExchangeHelper.convertToMandatoryType(exchange, Message.class, body);
    String charsetName = HL7Charset.getCharsetName(message, exchange);
    String encoded = HL7Converter.encode(message, parser);
    outputStream.write(encoded.getBytes(charsetName));
}
Also used : Message(ca.uhn.hl7v2.model.Message)

Example 80 with Message

use of bind.feature.generichierarchy.case1.model.Message in project camel by apache.

the class HL7DataFormat method unmarshal.

public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception {
    byte[] body = ExchangeHelper.convertToMandatoryType(exchange, byte[].class, inputStream);
    String charsetName = HL7Charset.getCharsetName(body, guessCharsetName(body, exchange));
    String bodyAsString = new String(body, charsetName);
    Message message = HL7Converter.parse(bodyAsString, parser);
    // add MSH fields as message out headers
    Terser terser = new Terser(message);
    for (Map.Entry<String, String> entry : HEADER_MAP.entrySet()) {
        exchange.getOut().setHeader(entry.getKey(), terser.get(entry.getValue()));
    }
    exchange.getOut().setHeader(HL7_CONTEXT, hapiContext);
    exchange.getOut().setHeader(Exchange.CHARSET_NAME, charsetName);
    return message;
}
Also used : Message(ca.uhn.hl7v2.model.Message) Terser(ca.uhn.hl7v2.util.Terser) HashMap(java.util.HashMap) Map(java.util.Map)

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