Search in sources :

Example 26 with Message

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

the class HL7ValidateTest method createADT01Message.

private static Message createADT01Message() throws Exception {
    ADT_A01 adt = new ADT_A01();
    adt.initQuickstart("ADT", "A01", "P");
    // Populate the PID Segment
    PID pid = adt.getPID();
    pid.getPatientName(0).getFamilyName().getSurname().setValue("Doe");
    pid.getPatientName(0).getGivenName().setValue("John");
    pid.getPhoneNumberBusiness(0).getPhoneNumber().setValue("333123456");
    pid.getPatientIdentifierList(0).getID().setValue("123456");
    return adt;
}
Also used : PID(ca.uhn.hl7v2.model.v24.segment.PID) ADT_A01(ca.uhn.hl7v2.model.v24.message.ADT_A01)

Example 27 with Message

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

the class HL7ValidateTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() throws Exception {
    HapiContext hapiContext = new DefaultHapiContext();
    hapiContext.setValidationContext(new NoValidation());
    Parser p = new GenericParser(hapiContext);
    hl7 = new HL7DataFormat();
    hl7.setParser(p);
    /*
         * Let's start by adding a validation rule to the default validation
         * that disallows PID-2 to be empty.
         */
    ValidationRuleBuilder builder = new ValidationRuleBuilder() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void configure() {
            forVersion(Version.V24).message("ADT", "*").terser("PID-2", not(empty()));
        }
    };
    ValidationContext customValidationContext = ValidationContextFactory.fromBuilder(builder);
    HapiContext customContext = new DefaultHapiContext(customValidationContext);
    final Parser customParser = new GenericParser(customContext);
    return new RouteBuilder() {

        public void configure() throws Exception {
            from("direct:unmarshalFailed").unmarshal().hl7().to("mock:unmarshal");
            from("direct:unmarshalOk").unmarshal().hl7(false).to("mock:unmarshal");
            from("direct:unmarshalOkCustom").unmarshal(hl7).to("mock:unmarshal");
            from("direct:start1").marshal().hl7(customParser).to("mock:end");
            from("direct:start2").marshal().hl7(true).to("mock:end");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) DefaultHapiContext(ca.uhn.hl7v2.DefaultHapiContext) NoValidation(ca.uhn.hl7v2.validation.impl.NoValidation) HapiContext(ca.uhn.hl7v2.HapiContext) DefaultHapiContext(ca.uhn.hl7v2.DefaultHapiContext) ValidationRuleBuilder(ca.uhn.hl7v2.validation.builder.ValidationRuleBuilder) Parser(ca.uhn.hl7v2.parser.Parser) GenericParser(ca.uhn.hl7v2.parser.GenericParser) GenericParser(ca.uhn.hl7v2.parser.GenericParser) ValidationContext(ca.uhn.hl7v2.validation.ValidationContext)

Example 28 with Message

use of ca.uhn.hl7v2.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 29 with Message

use of ca.uhn.hl7v2.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 30 with Message

use of ca.uhn.hl7v2.model.Message in project tdi-studio-se by Talend.

the class TypeModel method getComponent.

private Type getComponent(Type type, int comp) {
    Type ret = null;
    if (Varies.class.isAssignableFrom(type.getClass())) {
        Varies v = (Varies) type;
        try {
            if (comp > 1 && GenericPrimitive.class.isAssignableFrom(v.getData().getClass())) {
                v.setData(new GenericComposite(v.getMessage()));
            }
        } catch (DataTypeException de) {
            String message = "Unexpected exception copying data to generic composite: " + de.getMessage();
            throw new Error(message);
        }
        ret = getComponent(v.getData(), comp);
    } else {
        if (Primitive.class.isAssignableFrom(type.getClass()) && comp == 1) {
            ret = type;
        } else if (GenericComposite.class.isAssignableFrom(type.getClass()) || (Composite.class.isAssignableFrom(type.getClass()) && comp <= numStandardComponents(type))) {
            try {
                ret = ((Composite) type).getComponent(comp - 1);
            } catch (Exception e) {
                throw new Error("Internal error: HL7Exception thrown on getComponent(x) where x < # standard components.", e);
            }
        } else {
            ret = type.getExtraComponents().getComponent(comp - numStandardComponents(type) - 1);
        }
    }
    return ret;
}
Also used : Type(ca.uhn.hl7v2.model.Type) Primitive(ca.uhn.hl7v2.model.Primitive) GenericPrimitive(ca.uhn.hl7v2.model.GenericPrimitive) DataTypeException(ca.uhn.hl7v2.model.DataTypeException) GenericComposite(ca.uhn.hl7v2.model.GenericComposite) Composite(ca.uhn.hl7v2.model.Composite) GenericComposite(ca.uhn.hl7v2.model.GenericComposite) GenericPrimitive(ca.uhn.hl7v2.model.GenericPrimitive) Varies(ca.uhn.hl7v2.model.Varies) DataTypeException(ca.uhn.hl7v2.model.DataTypeException) HL7Exception(ca.uhn.hl7v2.HL7Exception)

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