Search in sources :

Example 96 with StructureDefinition

use of org.hl7.fhir.dstu3.model.StructureDefinition in project kindling by HL7.

the class ReviewSpreadsheetGenerator method processRows.

private int processRows(HSSFWorkbook workbook, String path, StructureDefinition profile, List<ElementDefinition> list, int i, HSSFSheet sheet, String indent) throws FHIRException {
    ElementDefinition ed = list.get(i);
    HSSFFont font = workbook.createFont();
    font.setFontName("Calibri");
    HSSFCellStyle style = workbook.createCellStyle();
    style.setFont(font);
    while (i < list.size() && ed.getPath().startsWith(path + ".")) {
        HSSFRow row = sheet.createRow(sheet.getPhysicalNumberOfRows());
        int c = 0;
        HSSFRichTextString richString;
        if (ed.getType().size() == 0) {
            richString = new HSSFRichTextString(indent + ed.getPath().substring(path.length() + 1) + " [" + describeCardinality(ed) + "]");
        } else if (ed.getType().size() == 1) {
            richString = new HSSFRichTextString(indent + ed.getPath().substring(path.length() + 1) + " : " + ed.getType().get(0).getWorkingCode() + " [" + describeCardinality(ed) + "]");
            HSSFFont fontBlue = workbook.createFont();
            fontBlue.setFontName("Calibri");
            fontBlue.setColor(IndexedColors.DARK_BLUE.getIndex());
            richString.applyFont(indent.length() + ed.getPath().length() - (path.length() + 1), richString.length() - describeCardinality(ed).length() - 3, fontBlue);
        } else {
            richString = new HSSFRichTextString(indent + ed.getPath().substring(path.length() + 1) + " : * [" + describeCardinality(ed) + "]");
        }
        HSSFCell cell = row.createCell(c++);
        cell.setCellStyle(style);
        cell.setCellValue(richString);
        if (ed.getType().size() == 0) {
            cell = row.createCell(c++);
            cell.setCellStyle(style);
            cell.setCellValue(ed.getSliceName());
            cell = row.createCell(c++);
            cell.setCellStyle(style);
            cell.setCellValue("");
            i++;
            if (i < list.size())
                i = processRows(workbook, ed.getPath(), profile, list, i, sheet, indent + "  ");
        } else if (ed.getType().size() == 1) {
            cell = row.createCell(c++);
            cell.setCellStyle(style);
            if (ed.getType().get(0).hasProfile())
                cell.setCellValue(ed.getType().get(0).getProfile().get(0).getValue());
            if (ed.getType().get(0).hasTargetProfile())
                cell.setCellValue(ed.getType().get(0).getTargetProfile().get(0).getValue());
            cell = row.createCell(c++);
            cell.setCellStyle(style);
            cell.setCellValue(describeBinding(profile, ed));
            i++;
        } else {
            cell = row.createCell(c++);
            cell.setCellStyle(style);
            cell.setCellValue(ed.getSliceName());
            cell = row.createCell(c++);
            cell.setCellStyle(style);
            cell.setCellValue(describeBinding(profile, ed));
            i++;
        }
        cell = row.createCell(c++);
        cell.setCellStyle(style);
        cell = row.createCell(c++);
        cell.setCellStyle(style);
        cell.setCellValue("");
        if (i < list.size())
            ed = list.get(i);
    }
    return i;
}
Also used : HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFFont(org.apache.poi.hssf.usermodel.HSSFFont) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition)

Example 97 with StructureDefinition

use of org.hl7.fhir.dstu3.model.StructureDefinition in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7EncounterFHIRConversionTest method testEncounterModeOfArrival.

@Test
void testEncounterModeOfArrival() {
    String hl7message = "MSH|^~\\&|PROSOLV|SENTARA|WHIA|IBM|20151008111200|S1|ADT^A01^ADT_A01|MSGID000001|T|2.6|10092|PRPA008|AL|AL|100|8859/1|ENGLISH|ARM|ARM5007\n" + "EVN|A04|20151008111200|20171013152901|O|OID1006|20171013153621|EVN1009\n" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + "PV1|1|E|SAN JOSE|A|10089|MILPITAS|2740^Torres^Callie|2913^Grey^Meredith^F|3065^Sloan^Mark^J|CAR|FOSTER CITY|AD|R|1|A4|VI|9052^Shepeard^Derek^|AH|10019181|FIC1002|IC|CC|CR|CO|20161012034052|60000|6|AC|GHBR|20160926054052|AC5678|45000|15000|D|20161016154413|DCD|SAN FRANCISCO|VEG|RE|O|AV|FREMONT|CALIFORNIA|20161013154626|20161014154634|10000|14000|2000|4000|POL8009|V|PHY6007\n" + "PV2|SAN BRUNO|AC4567|vomits|less equipped|purse|SAN MATEO|HO|20171014154626|20171018154634|4|3|DIAHHOREA|RSA456|20161013154626|Y|D|20191026001640|O|Y|1|F|Y|KAISER|AI|2|20161013154626|ED|20171018001900|20161013154626|10000|RR|Y|20171108002129|Y|Y|N|N|C^Car^HL70430\n";
    Encounter encounter = ResourceUtils.getEncounter(ftv, hl7message);
    List<Extension> extensionList = encounter.getExtension();
    assertNotNull(extensionList);
    assertThat(extensionList).hasSize(1);
    boolean extFound = false;
    for (Extension ext : extensionList) {
        if (ext.getUrl().equals("http://hl7.org/fhir/StructureDefinition/encounter-modeOfArrival")) {
            extFound = true;
            assertTrue(ext.getValue() instanceof Coding);
            Coding valueCoding = (Coding) ext.getValue();
            assertThat(valueCoding.getCode()).isEqualTo("C");
            assertThat(valueCoding.getDisplay()).isEqualTo("Car");
            assertThat(valueCoding.getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/v2-0430");
            break;
        }
    }
    assertTrue(extFound, "modeOfArrival extension not found");
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Coding(org.hl7.fhir.r4.model.Coding) Encounter(org.hl7.fhir.r4.model.Encounter) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 98 with StructureDefinition

use of org.hl7.fhir.dstu3.model.StructureDefinition in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7EncounterFHIRConversionTest method test_encounter_modeOfarrival_invalid_with_system.

@Test
void test_encounter_modeOfarrival_invalid_with_system() {
    String hl7message = "MSH|^~\\&|WHI_LOAD_GENERATOR|IBM_TORONTO_LAB||IBM|20210330144208|8078780|ADT^A01|MSGID_4e1c575f-6c6d-47b2-ab9f-829f20c96db2|T|2.3\n" + "EVN||20210330144208||ADT_EVENT|007|20210309140700\n" + "PID|1||0a8a1752-e336-43e1-bf7f-0c8f6f437ca3^^^MRN||Patient^Load^Generator||19690720|M|Patient^Alias^Generator|AA|9999^^CITY^STATE^ZIP^CAN|COUNTY|(866)845-0900||ENGLISH^ENGLISH|SIN|NONE|Account_0a8a1752-e336-43e1-bf7f-0c8f6f437ca3|123-456-7890|||N|BIRTH PLACE|N||||||N\n" + "PV1||I|^^^Toronto^^5642 Hilly Av||||2905^Doctor^Attending^M^IV^^M.D|5755^Doctor^Referring^^Sr|770542^Doctor^Consulting^Jr||||||||59367^Doctor^Admitting||Visit_0a3be81e-144b-4885-9b4e-c5cd33c8f038|||||||||||||||||||||||||20210407191342\n" + "PV2||TEL||||X-5546||20210330144208|20210309||||||||||||n|N|South Shore Hosptial Weymouth^SSHW^^^^^^SSH-WEYMOUTH|||||||||N||||||AMB^AMBULATORY^FUNKY\n";
    Encounter encounter = ResourceUtils.getEncounter(ftv, hl7message);
    List<Extension> extensionList = encounter.getExtension();
    assertNotNull(extensionList);
    assertThat(extensionList).isNotEmpty();
    boolean extFound = false;
    for (Extension ext : extensionList) {
        if (ext.getUrl().equals("http://hl7.org/fhir/StructureDefinition/encounter-modeOfArrival")) {
            extFound = true;
            assertTrue(ext.getValue() instanceof Coding);
            Coding valueCoding = (Coding) ext.getValue();
            assertThat(valueCoding.getCode()).isEqualTo("AMB");
            assertThat(valueCoding.getDisplay()).isEqualTo("AMBULATORY");
            assertThat(valueCoding.getSystem()).isEqualTo("urn:id:FUNKY");
            break;
        }
    }
    assertTrue(extFound, "modeOfArrival extension not found");
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Coding(org.hl7.fhir.r4.model.Coding) Encounter(org.hl7.fhir.r4.model.Encounter) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 99 with StructureDefinition

use of org.hl7.fhir.dstu3.model.StructureDefinition in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7EncounterFHIRConversionTest method test_encounter_modeOfarrival_invalid_singlevalue.

@Test
void test_encounter_modeOfarrival_invalid_singlevalue() {
    String hl7message = "MSH|^~\\&|WHI_LOAD_GENERATOR|IBM_TORONTO_LAB||IBM|20210330144208|8078780|ADT^A01|MSGID_4e1c575f-6c6d-47b2-ab9f-829f20c96db2|T|2.3\n" + "EVN||20210330144208||ADT_EVENT|007|20210309140700\n" + "PID|1||0a8a1752-e336-43e1-bf7f-0c8f6f437ca3^^^MRN||Patient^Load^Generator||19690720|M|Patient^Alias^Generator|AA|9999^^CITY^STATE^ZIP^CAN|COUNTY|(866)845-0900||ENGLISH^ENGLISH|SIN|NONE|Account_0a8a1752-e336-43e1-bf7f-0c8f6f437ca3|123-456-7890|||N|BIRTH PLACE|N||||||N\n" + "PV1||I|^^^Toronto^^5642 Hilly Av||||2905^Doctor^Attending^M^IV^^M.D|5755^Doctor^Referring^^Sr|770542^Doctor^Consulting^Jr||||||||59367^Doctor^Admitting||Visit_0a3be81e-144b-4885-9b4e-c5cd33c8f038|||||||||||||||||||||||||20210407191342\n" + "PV2||TEL||||X-5546||20210330144208|20210309||||||||||||n|N|South Shore Hosptial Weymouth^SSHW^^^^^^SSH-WEYMOUTH|||||||||N||||||AMBULATORY\n";
    Encounter encounter = ResourceUtils.getEncounter(ftv, hl7message);
    List<Extension> extensionList = encounter.getExtension();
    assertNotNull(extensionList);
    assertThat(extensionList).isNotEmpty();
    boolean extFound = false;
    for (Extension ext : extensionList) {
        if (ext.getUrl().equals("http://hl7.org/fhir/StructureDefinition/encounter-modeOfArrival")) {
            extFound = true;
            assertTrue(ext.getValue() instanceof Coding);
            Coding valueCoding = (Coding) ext.getValue();
            assertThat(valueCoding.getCode()).isEqualTo("AMBULATORY");
            assertThat(valueCoding.getDisplay()).isNull();
            assertThat(valueCoding.getSystem()).isNull();
            break;
        }
    }
    assertTrue(extFound, "modeOfArrival extension not found");
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Coding(org.hl7.fhir.r4.model.Coding) Encounter(org.hl7.fhir.r4.model.Encounter) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 100 with StructureDefinition

use of org.hl7.fhir.dstu3.model.StructureDefinition in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7NoteFHIRConverterTest method testMedicationRequestNoteCreation.

// Suppress warnings about too many assertions in a test.  Justification: creating a FHIR message is very costly; we need to check many asserts per creation for efficiency.
@java.lang.SuppressWarnings("squid:S5961")
@ParameterizedTest
@MethodSource("parmsTestMedicationRequestNoteCreation")
void testMedicationRequestNoteCreation(String message, String medicalRequestSegments) {
    // Minimal valid ORC message.  Requires RXO and RXR segments.
    String hl7message = "MSH|^~\\&||||IBM|20210101000000||" + message + "|MSGID|T|2.6\n" + "PID|||1234||DOE^JANE^|||F||||||||||||||||||||||\n" + "PV1||I||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|OP|1234|1234|0827||||||||||||||||||||\n" + // May be RXO or RXO+RXE values from parmsTestMedicationRequestNoteCreation
    medicalRequestSegments + "NTE|1|O|TEST MedReq NOTE AA line 1||Pract1ID^Pract1Last^Pract1First|\n" + "NTE|2|O|TEST NOTE AA line 2|\n" + "NTE|3|O|TEST NOTE AA line 3|\n" + "OBX|1|NM|17985^GLYCOHEMOGLOBIN HGB A1C^LRR^^^^^^GLYCOHEMOGLOBIN HGB A1C||5.6|%|<6.0||||F||||||||||||||\n" + // GLYCOHEMOGLOBIN Observation NTE has a practitioner reference in NTE.5.  Note in second NTE. The first valid NTE.5 is used.
    "NTE|1|L|TEST OBXa NOTE BB line 1|\n" + "NTE|2|L|TEST NOTE BB line 2||Pract2ID^Pract2Last^Pract2First|\n" + "NTE|3|L|TEST NOTE BB line 3|\n" + "OBX|2|NM|17853^MEAN BLOOD GLUCOSE^LRR^^^^^^MEAN BLOOD GLUCOSE||114.02|mg/dL|||||F||||||||||||||\n" + // Glucose Observation NTE has no practitioner reference in NTE.5
    "NTE|1|L|TEST OBXb NOTE CC line 1|\n" + "NTE|2|L|TEST NOTE CC line 2|\n" + // Test that blank lines are preserved.
    "NTE|3|L| |\n" + "NTE|4|L|TEST NOTE CC line 4|\n";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    // Expect MedicationRequest containing NTE for RXO or RXE
    List<Resource> medicationRequests = ResourceUtils.getResourceList(e, ResourceType.MedicationRequest);
    assertThat(medicationRequests).hasSize(1);
    MedicationRequest medicationRequest = ResourceUtils.getResourceMedicationRequest(medicationRequests.get(0), ResourceUtils.context);
    assertThat(medicationRequest.hasNote()).isTrue();
    assertThat(medicationRequest.getNote()).hasSize(1);
    // NOTE: the note contains an Annotation, which contains a MarkdownType that has the string.
    // Must use getTextElement().getValueAsString() to see untrimmed contents.
    assertThat(medicationRequest.getNote().get(0).getTextElement().getValueAsString()).isEqualTo("TEST MedReq NOTE AA line 1  \nTEST NOTE AA line 2  \nTEST NOTE AA line 3");
    assertThat(medicationRequest.getNote().get(0).hasAuthorReference()).isTrue();
    String practitionerServReqRefId = medicationRequest.getNote().get(0).getAuthorReference().getReference();
    // Two observations.  One has GLYCOHEMOGLOBIN and notes BB, One has GLUCOSE and notes CC
    List<Resource> observations = ResourceUtils.getResourceList(e, ResourceType.Observation);
    // Should be 2 for ORU and ORM
    assertThat(observations).hasSize(2);
    Observation obsGlucose = ResourceUtils.getResourceObservation(observations.get(0), ResourceUtils.context);
    Observation obsHemoglobin = ResourceUtils.getResourceObservation(observations.get(1), ResourceUtils.context);
    // Figure out which is first and reassign if needed for testing
    if (obsGlucose.getCode().getText() != "MEAN BLOOD GLUCOSE") {
        Observation temp = obsGlucose;
        obsGlucose = obsHemoglobin;
        obsHemoglobin = temp;
    }
    // Validate the note contents and references
    assertThat(obsHemoglobin.hasNote()).isTrue();
    assertThat(obsHemoglobin.getNote()).hasSize(1);
    assertThat(obsHemoglobin.getNote().get(0).getTextElement().getValueAsString()).isEqualTo("TEST OBXa NOTE BB line 1  \nTEST NOTE BB line 2  \nTEST NOTE BB line 3");
    assertThat(obsHemoglobin.getNote().get(0).hasAuthorReference()).isTrue();
    String practitionerObsHemoglobinRefId = obsHemoglobin.getNote().get(0).getAuthorReference().getReference();
    assertThat(obsGlucose.hasNote()).isTrue();
    assertThat(obsGlucose.getNote()).hasSize(1);
    assertThat(obsGlucose.getNote().get(0).getTextElement().getValueAsString()).isEqualTo(// Test that blank lines are preserved.
    "TEST OBXb NOTE CC line 1  \nTEST NOTE CC line 2  \n   \nTEST NOTE CC line 4");
    assertThat(obsGlucose.getNote().get(0).hasAuthorReference()).isFalse();
    // Two Practitioners, one for the serviceRequest, one for the GLYCOHEMOGLOBIN Observation
    List<Resource> practitioners = ResourceUtils.getResourceList(e, ResourceType.Practitioner);
    assertThat(practitioners).hasSize(2);
    Practitioner practitionerServReq = ResourceUtils.getResourcePractitioner(practitioners.get(0), ResourceUtils.context);
    Practitioner practitionerObsHemoglobin = ResourceUtils.getResourcePractitioner(practitioners.get(1), ResourceUtils.context);
    // Adjust to correct practitioner if needed
    if (!practitionerServReq.getIdentifierFirstRep().getValue().contentEquals("Pract1ID")) {
        Practitioner temp = practitionerObsHemoglobin;
        practitionerObsHemoglobin = practitionerServReq;
        practitionerServReq = temp;
    }
    // Check the values for the Practitioners and validate match to references.
    assertThat(practitionerServReq.getIdentifier()).hasSize(1);
    assertThat(practitionerServReq.getIdentifierFirstRep().getValue()).isEqualTo("Pract1ID");
    assertThat(practitionerServReq.getName()).hasSize(1);
    assertThat(practitionerServReq.getNameFirstRep().getText()).isEqualTo("Pract1First Pract1Last");
    // Check the cross-reference
    assertThat(practitionerServReq.getId()).isEqualTo(practitionerServReqRefId);
    // Sanity check to confirm data corruption in meta content has not returned.
    CodeableConcept ccSourceEventTrigger = (CodeableConcept) practitionerServReq.getMeta().getExtensionByUrl("http://ibm.com/fhir/cdm/StructureDefinition/source-event-trigger").getValue();
    assertThat(ccSourceEventTrigger.hasText()).isFalse();
    assertThat(practitionerObsHemoglobin.getIdentifier()).hasSize(1);
    assertThat(practitionerObsHemoglobin.getIdentifierFirstRep().getValue()).isEqualTo("Pract2ID");
    assertThat(practitionerObsHemoglobin.getName()).hasSize(1);
    assertThat(practitionerObsHemoglobin.getNameFirstRep().getText()).isEqualTo("Pract2First Pract2Last");
    // Check the cross-reference
    assertThat(practitionerObsHemoglobin.getId()).isEqualTo(practitionerObsHemoglobinRefId);
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) Observation(org.hl7.fhir.r4.model.Observation) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ArrayList (java.util.ArrayList)307 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)241 FHIRException (org.hl7.fhir.exceptions.FHIRException)226 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)158 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)144 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)105 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)98 IOException (java.io.IOException)91 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)91 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)87 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)83 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)70 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)69 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)67 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)58 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)56 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)50 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)49 ProfileUtilities (org.hl7.fhir.r5.conformance.ProfileUtilities)46 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)46