Search in sources :

Example 6 with Message

use of com.google.api.services.healthcare.v1.model.Message in project tdi-studio-se by Talend.

the class ImportHL7StructureAction method treeNodeAdapt.

private List treeNodeAdapt() {
    List<HL7TreeNode> treeData = new ArrayList<HL7TreeNode>();
    FileDialog f = null;
    if (hl7ui != null) {
        f = new FileDialog(hl7ui.getHl7UIParent().getShell());
    } else if (form != null) {
        f = new FileDialog(form.getShell());
    }
    String file = f.open();
    if (file == null) {
        return treeData;
    }
    HL7Parse hl7Parse = new HL7Parse();
    List<String> msgContentList = new ArrayList<String>();
    List<Message> messageList = hl7Parse.doParse(file, "'\\u000b'", "'\\u001c'");
    List<HL7TreeNode> nodeList = hl7Util.getHL7TreeNodes(messageList);
    if (!nodeList.isEmpty()) {
        HL7TreeNode hl7TreeNode = nodeList.get(0);
        List<HL7FileNode> table = new ArrayList<HL7FileNode>();
        if (hl7Connection != null) {
            EList root = hl7Connection.getRoot();
            root.clear();
            if (hl7TreeNode != null) {
                hl7Util.initNodeOrder(hl7TreeNode, orderMap);
                hl7Util.tableLoader((Element) hl7TreeNode, "", root, hl7TreeNode.getDefaultValue(), orderMap);
            }
            table.addAll(root);
        } else {
            if (hl7TreeNode != null) {
                hl7Util.initNodeOrder(hl7TreeNode, orderMap);
                hl7Util.tableLoader((Element) hl7TreeNode, "", table, hl7TreeNode.getDefaultValue(), orderMap);
            }
        }
        List<String> schemaList = new ArrayList<String>();
        for (HL7FileNode node : table) {
            String columnName = node.getRelatedColumn();
            if (columnName.contains(":")) {
                columnName = columnName.substring(0, columnName.indexOf(":"));
            }
            if (!schemaList.contains(columnName) && !"".equals(columnName)) {
                schemaList.add(columnName);
            }
        }
        initXmlTreeData(schemaList, table, treeData);
    }
    return treeData;
}
Also used : EList(org.eclipse.emf.common.util.EList) Message(ca.uhn.hl7v2.model.Message) HL7FileNode(org.talend.core.model.metadata.builder.connection.HL7FileNode) ArrayList(java.util.ArrayList) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode) FileDialog(org.eclipse.swt.widgets.FileDialog) HL7Parse(org.talend.designer.hl7.ui.header.HL7Parse)

Example 7 with Message

use of com.google.api.services.healthcare.v1.model.Message in project tdi-studio-se by Talend.

the class HL7PublicUtil method getChildren.

public Set getChildren(Object parentElement) {
    // List values = new ArrayList();
    Set values = new HashSet();
    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 (getChildren(childReps[j]).size() > 0) {
                            values.addAll(getChildren(childReps[j]));
                        }
                    }
                    if (childReps[j] instanceof Group) {
                        values.add(childReps[j]);
                        allSegmentFromGroup.clear();
                        getAllSegmentsFromGroup((Group) childReps[j]);
                    }
                    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 (getChildren(sModel).size() > 0) {
                                values.addAll(getChildren(sModel));
                            }
                            if (!allSegmentsForMessage.contains(sModel)) {
                                allSegmentsForMessage.add(sModel);
                            }
                        }
                    }
                }
            // values.addAll(Arrays.asList(childReps));
            } catch (HL7Exception e) {
                e.printStackTrace();
            }
        }
        return values;
    }
    if (parentElement instanceof Segment) {
        values.clear();
        Segment segment = (Segment) parentElement;
        SegmentModel sm = new SegmentModel(segment, segment, 0, 0);
        TypeModel[] models = sm.getTypes();
        for (TypeModel model : models) {
            values.add(model);
            if (getChildren(model).size() > 0) {
                values.addAll(getChildren(model));
            }
        }
        return values;
    }
    if (parentElement instanceof SegmentModel) {
        SegmentModel sm = (SegmentModel) parentElement;
        TypeModel[] models = sm.getTypes();
        for (TypeModel model : models) {
            values.add(model);
            if (getChildren(model).size() > 0) {
                values.addAll(getChildren(model));
            }
        }
        return values;
    }
    if (parentElement instanceof TypeModel) {
        TypeModel tm = (TypeModel) parentElement;
        PrimitiveModel[] models = tm.getPrimitives();
        for (PrimitiveModel model : models) {
            values.add(model);
            if (getChildren(model).size() > 0) {
                values.addAll(getChildren(model));
            }
        }
        return values;
    // 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);
                            if (getChildren(sm).size() > 0) {
                                values.addAll(getChildren(sm));
                            }
                        }
                    } else {
                        values.add(childReps[j]);
                        if (getChildren(childReps[j]).size() > 0) {
                            values.addAll(getChildren(childReps[j]));
                        }
                    }
                }
            // values.addAll(Arrays.asList(childReps));
            } catch (HL7Exception e) {
                e.printStackTrace();
            }
        }
        return values;
    }
    return values;
}
Also used : Group(ca.uhn.hl7v2.model.Group) Set(java.util.Set) HashSet(java.util.HashSet) Message(ca.uhn.hl7v2.model.Message) TypeModel(org.talend.designer.hl7.model.TypeModel) PrimitiveModel(org.talend.designer.hl7.model.PrimitiveModel) Segment(ca.uhn.hl7v2.model.Segment) HL7Exception(ca.uhn.hl7v2.HL7Exception) Structure(ca.uhn.hl7v2.model.Structure) SegmentModel(org.talend.designer.hl7.model.SegmentModel) HashSet(java.util.HashSet)

Example 8 with Message

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

the class HL7DataFormatTest method testUnmarshalWithImplicitBig5Charset.

@Test
public void testUnmarshalWithImplicitBig5Charset() throws Exception {
    String charset = "Big5";
    MockEndpoint mock = getMockEndpoint("mock:unmarshalBig5");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);
    mock.expectedHeaderReceived(HL7Constants.HL7_CHARSET, null);
    mock.expectedHeaderReceived(Exchange.CHARSET_NAME, charset);
    // Message without explicit encoding in MSH-18, but the unmarshaller "guesses"
    // this time that it is Big5
    byte[] body = createHL7AsString().getBytes(Charset.forName(charset));
    template.sendBody("direct:unmarshalBig5", new ByteArrayInputStream(body));
    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 9 with Message

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

the class HL7MLLPCodecStandAndEndBytesTest method createRouteBuilder.

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");
        }
    };
}
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 10 with Message

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

the class ValidationContextPredicate method matches.

@Override
public boolean matches(Exchange exchange) {
    try {
        Message message = exchange.getIn().getBody(Message.class);
        ValidationContext context = validatorExpression != null ? validatorExpression.evaluate(exchange, ValidationContext.class) : dynamicValidationContext(message, exchange.getIn().getHeader(HL7Constants.HL7_CONTEXT, HapiContext.class));
        MessageValidator validator = new MessageValidator(context, false);
        return validator.validate(message);
    } catch (HL7Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
}
Also used : Message(ca.uhn.hl7v2.model.Message) HL7Exception(ca.uhn.hl7v2.HL7Exception) MessageValidator(ca.uhn.hl7v2.validation.MessageValidator) ValidationContext(ca.uhn.hl7v2.validation.ValidationContext)

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