Search in sources :

Example 11 with Group

use of ca.uhn.hl7v2.model.Group in project hl7v2-fhir-converter by LinuxForHealth.

the class SegmentUtilTest method test_repeating_primary_segment_with_repeating_parent_group.

@Test
void test_repeating_primary_segment_with_repeating_parent_group() throws HL7Exception {
    String message = "MSH|^~\\\\&|SendTest1|Sendfac1|Receiveapp1|Receivefac1|200603081747|security|ORU^R01|MSGID000005|T|2.6\r" + "PID||45483|45483||SMITH^SUZIE^||20160813|M|||123 MAIN STREET^^SCHENECTADY^NY^12345||(123)456-7890|||||^^^T||||||||||||\r" + "OBR|1||986^IA PHIMS Stage^2.16.840.1.114222.4.3.3.5.1.2^ISO|112^Final Echocardiogram Report|||20151009173644|||||||||||||002|||||F|||2740^Tsadok^Janetary~2913^Merrit^Darren^F~3065^Mahoney^Paul^J~4723^Loh^Robert^L~9052^Winter^Oscar^||||3068^JOHN^Paul^J|\r" + "OBX|1|ST|TS-F-01-007^Endocrine Disorders 7^L||obs report||||||F\r" + "OBX|2|ST|TS-F-01-008^Endocrine Disorders 8^L||ECHOCARDIOGRAPHIC REPORT||||||F\r" + "OBR|1||98^IA PHIMS Stage^2.16.840.1.114222.4.3.3.5.1.2^ISO|113^Echocardiogram Report|||20151009173644|||||||||||||002|||||F|||2740^Tsadok^Janetary~2913^Merrit^Darren^F~3065^Mahoney^Paul^J~4723^Loh^Robert^L~9052^Winter^Oscar^||||3065^Mahoney^Paul^J|\r" + "OBX|1|CWE|625-4^Bacteria identified in Stool by Culture^LN^^^^2.33^^result1|1|27268008^Salmonella^SCT^^^^20090731^^Salmonella species|||A^A^HL70078^^^^2.5|||P|||20120301|||^^^^^^^^Bacterial Culture||201203140957||||||\r" + "OBX|2|ST|TS-F-01-002^Endocrine Disorders^L||ECHOCARDIOGRAPHIC REPORT Group 2||||||F\r";
    Message hl7message = getMessage(message);
    HL7DataExtractor hl7DTE = new HL7DataExtractor(hl7message);
    List<String> orderGroupList = Lists.newArrayList("PATIENT_RESULT", "ORDER_OBSERVATION");
    List<String> observationGroupList = Lists.newArrayList("PATIENT_RESULT", "ORDER_OBSERVATION", "OBSERVATION");
    List<String> specimenGroupList = Lists.newArrayList("PATIENT_RESULT", "ORDER_OBSERVATION", "SPECIMEN");
    List<HL7Segment> additionalSegments = Lists.newArrayList(new HL7Segment(orderGroupList, "OBR", true), new HL7Segment(observationGroupList, "NTE", true), new HL7Segment(specimenGroupList, "SPM", true), new HL7Segment(orderGroupList, "MSH", false));
    List<SegmentGroup> segmentGroups = SegmentExtractorUtil.extractSegmentGroups(observationGroupList, "OBX", additionalSegments, hl7DTE, Lists.newArrayList("PATIENT_RESULT", "ORDER_OBSERVATION"));
    assertThat(segmentGroups).isNotEmpty().hasSize(4);
    List<String> firstGroupIds = Lists.newArrayList(segmentGroups.get(0).getGroupId(), segmentGroups.get(1).getGroupId());
    List<String> secondGroupIds = Lists.newArrayList(segmentGroups.get(2).getGroupId(), segmentGroups.get(3).getGroupId());
    // The first two OBX should have the same group ID
    assertThat(firstGroupIds).containsOnly(firstGroupIds.get(0));
    // The second two OBX should have the same group ID
    assertThat(secondGroupIds).containsOnly(secondGroupIds.get(0));
    // The parent should be the ORDER_OBSERVATION group
    assertThat(firstGroupIds.get(0)).contains("ORDER_OBSERVATION");
    assertThat(secondGroupIds.get(0)).contains("ORDER_OBSERVATION");
    // The first group of OBX should have a different ID than the second group of OBX.
    assertThat(firstGroupIds.get(0)).isNotEqualTo(secondGroupIds.get(0));
}
Also used : Message(ca.uhn.hl7v2.model.Message) HL7DataExtractor(io.github.linuxforhealth.hl7.parsing.HL7DataExtractor) SegmentGroup(io.github.linuxforhealth.hl7.message.util.SegmentGroup) Test(org.junit.jupiter.api.Test)

Example 12 with Group

use of ca.uhn.hl7v2.model.Group in project hl7v2-fhir-converter by LinuxForHealth.

the class SegmentUtilTest method test_parent_repeat_additional_segment_under_group_with_group_name.

@Test
void test_parent_repeat_additional_segment_under_group_with_group_name() throws HL7Exception {
    Message hl7message = getMessage(messageRepeatMultiplePRB);
    HL7DataExtractor hl7DTE = new HL7DataExtractor(hl7message);
    List<SegmentGroup> segmentGroups = SegmentExtractorUtil.extractSegmentGroups(ORDER_GROUP_LIST, "OBX", Lists.newArrayList(new HL7Segment(ORDER_GROUP_LIST, "NTE", true)), hl7DTE, Lists.newArrayList("PROBLEM"));
    assertThat(segmentGroups).isNotEmpty().hasSize(5);
    validateEachGroupAdditionalSegment(hl7DTE, segmentGroups.get(0), 1, 1, ECHOCARDIOGRAPHIC_REPORT, "NTE");
    validateEachGroupAdditionalSegment(hl7DTE, segmentGroups.get(1), 1, 1, NORMAL_LV_CHAMBER_SIZE_WITH_MILD_CONCENTRIC_LVH, "NTE");
    validateEachGroup(hl7DTE, segmentGroups.get(2), 1, 0, "ECHOCARDIOGRAPHIC REPORT2");
    validateEachGroup(hl7DTE, segmentGroups.get(3), 1, 0, "NORMAL LV CHAMBER SIZE WITH MILD CONCENTRIC LVH 3");
    validateEachGroup(hl7DTE, segmentGroups.get(4), 1, 0, "ECHOCARDIOGRAPHIC REPORT new group");
    List<String> sameGroup = Lists.newArrayList(segmentGroups.get(0).getGroupId(), segmentGroups.get(1).getGroupId(), segmentGroups.get(2).getGroupId(), segmentGroups.get(3).getGroupId());
    assertThat(sameGroup).containsOnly(segmentGroups.get(0).getGroupId());
    assertThat(segmentGroups.get(4).getGroupId()).isNotEqualTo(segmentGroups.get(0).getGroupId());
}
Also used : Message(ca.uhn.hl7v2.model.Message) HL7DataExtractor(io.github.linuxforhealth.hl7.parsing.HL7DataExtractor) SegmentGroup(io.github.linuxforhealth.hl7.message.util.SegmentGroup) Test(org.junit.jupiter.api.Test)

Example 13 with Group

use of ca.uhn.hl7v2.model.Group in project hl7v2-fhir-converter by LinuxForHealth.

the class SegmentUtilTest method test_get_segments.

// Test for extracting segments outside of group
@Test
void test_get_segments() throws HL7Exception {
    Message hl7message = getMessage(hl7ADTmessage);
    HL7DataExtractor hl7DTE = new HL7DataExtractor(hl7message);
    List<SegmentGroup> segmentGroups = SegmentExtractorUtil.extractSegmentNonGroups("OBX", new ArrayList<>(), hl7DTE);
    assertThat(segmentGroups).isNotEmpty().hasSize(1);
    assertThat(segmentGroups.get(0).getSegments()).hasSize(2);
    Segment s = (Segment) segmentGroups.get(0).getSegments().get(0);
    ParsingResult<Type> type = hl7DTE.getType(s, 5, 0);
    assertThat(Hl7DataHandlerUtil.getStringValue(type.getValue())).isEqualTo(ECHOCARDIOGRAPHIC_REPORT);
    assertThat(segmentGroups.get(0).getAdditionalSegments()).isEmpty();
    s = (Segment) segmentGroups.get(0).getSegments().get(1);
    type = hl7DTE.getType(s, 5, 0);
    assertThat(Hl7DataHandlerUtil.getStringValue(type.getValue())).isEqualTo(NORMAL_LV_CHAMBER_SIZE_WITH_MILD_CONCENTRIC_LVH);
}
Also used : Type(ca.uhn.hl7v2.model.Type) Message(ca.uhn.hl7v2.model.Message) HL7DataExtractor(io.github.linuxforhealth.hl7.parsing.HL7DataExtractor) SegmentGroup(io.github.linuxforhealth.hl7.message.util.SegmentGroup) Segment(ca.uhn.hl7v2.model.Segment) Test(org.junit.jupiter.api.Test)

Example 14 with Group

use of ca.uhn.hl7v2.model.Group in project hl7v2-fhir-converter by LinuxForHealth.

the class SegmentExtractorUtil method getParentGroup.

private static Structure getParentGroup(Structure struct, String group) {
    boolean parentMatchFound = false;
    Structure parent = struct;
    boolean noMoreParent = false;
    while (!parentMatchFound && !noMoreParent) {
        if (parent != null && StringUtils.endsWith(parent.getName(), group)) {
            parentMatchFound = true;
        } else if (parent == null || parent.getName().equalsIgnoreCase(parent.getMessage().getName())) {
            noMoreParent = true;
        } else {
            parent = parent.getParent();
        }
    }
    if (parentMatchFound) {
        return parent;
    } else {
        return null;
    }
}
Also used : Structure(ca.uhn.hl7v2.model.Structure)

Example 15 with Group

use of ca.uhn.hl7v2.model.Group in project hl7v2-fhir-converter by LinuxForHealth.

the class SegmentExtractorUtil method extractEachAdditionalSegment.

private static List<Structure> extractEachAdditionalSegment(Structure primaryStruct, List<String> primaryGroups, HL7Segment seg, HL7DataExtractor dataExtractor) {
    List<Structure> values = null;
    List<String> groups = seg.getGroup();
    if (groups.isEmpty()) {
        values = getStructures(seg.getSegment(), dataExtractor);
    } else if (primaryGroups.isEmpty()) {
        // extract without parent
        List<Structure> parentSegments = getChildStructures(seg.getGroup(), dataExtractor);
        values = new ArrayList<>();
        for (Structure par : parentSegments) {
            values.addAll(getStructures(par, seg.getSegment(), dataExtractor));
        }
    } else if (CollectionUtils.containsAll(primaryGroups, groups)) {
        String commonParentGroup = getCommonParent(groups, primaryGroups);
        Structure commonParent = getParentGroup(primaryStruct, commonParentGroup);
        values = getStructures(commonParent, seg.getSegment(), dataExtractor);
    } else if (getCommonParent(groups, primaryGroups) != null) {
        String commonParentGroup = getCommonParent(groups, primaryGroups);
        Structure commonParent = getParentGroup(primaryStruct, commonParentGroup);
        List<String> relativeGroupsToCommonParent = new ArrayList<>(groups);
        relativeGroupsToCommonParent.removeAll(primaryGroups);
        values = getChildStructures(commonParent, relativeGroupsToCommonParent, seg.getSegment(), dataExtractor);
    } else {
        // extracts data from segment that is in a group outside of the primary group for that specific resource
        List<Structure> parentSegments = getChildStructures(seg.getGroup(), dataExtractor);
        values = new ArrayList<>();
        for (Structure par : parentSegments) {
            values.addAll(getStructures(par, seg.getSegment(), dataExtractor));
        }
    }
    return values;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Structure(ca.uhn.hl7v2.model.Structure)

Aggregations

ArrayList (java.util.ArrayList)16 Structure (ca.uhn.hl7v2.model.Structure)13 Group (ca.uhn.hl7v2.model.Group)12 HL7Exception (ca.uhn.hl7v2.HL7Exception)11 Message (ca.uhn.hl7v2.model.Message)10 Segment (ca.uhn.hl7v2.model.Segment)8 List (java.util.List)6 Type (ca.uhn.hl7v2.model.Type)5 Group (org.hl7.fhir.r4.model.Group)5 Test (org.junit.jupiter.api.Test)5 SegmentModel (org.talend.designer.hl7.model.SegmentModel)5 SegmentGroup (io.github.linuxforhealth.hl7.message.util.SegmentGroup)4 HL7DataExtractor (io.github.linuxforhealth.hl7.parsing.HL7DataExtractor)4 TypeModel (org.talend.designer.hl7.model.TypeModel)4 Hl7ParsingStructureResult (io.github.linuxforhealth.hl7.parsing.result.Hl7ParsingStructureResult)3 Date (java.util.Date)3 ApplicationException (ca.uhn.hl7v2.app.ApplicationException)2 FT (ca.uhn.hl7v2.model.v25.datatype.FT)2 Group (org.apache.manifoldcf.crawler.connectors.confluence.v6.model.Group)2 Reference (org.hl7.fhir.r4.model.Reference)2