Search in sources :

Example 76 with Extension

use of org.hl7.fhir.r4.model.Extension in project hl7v2-fhir-converter by LinuxForHealth.

the class CodeableConceptTest method testSimilarCWEToCodeableConcepts.

@ParameterizedTest
@MethodSource("parmsTestSimilarCWEInputs")
void testSimilarCWEToCodeableConcepts(String cwe, String code, String display, String system, String text) {
    // See inputs and test explanation above
    String patientWithCodeableConcept = "MSH|^~\\&|MIICEHRApplication|MIIC|MIIC|MIIC|201705130822||VXU^V04^VXU_V04|test1100|P|2.5.1|||AL|AL|||||Z22^CDCPHINVS|^^^^^MIIC^SR^^^MIIC|MIIC\n" + // Test text only race
    "PID|1||12345678^^^^MR||TestPatientLastName^Jane^|||||" + cwe + "\n";
    Patient patient = PatientUtils.createPatientFromHl7Segment(ftv, patientWithCodeableConcept);
    assertThat(patient.hasExtension()).isTrue();
    List<Extension> extensions = patient.getExtensionsByUrl(UrlLookup.getExtensionUrl("race"));
    assertThat(extensions).isNotNull();
    assertThat(extensions.size()).isEqualTo(1);
    assertThat(extensions.get(0).hasValue()).isTrue();
    CodeableConcept ccW = (CodeableConcept) extensions.get(0).getValue();
    DatatypeUtils.checkCommonCodeableConceptAssertions(ccW, code, display, system, text);
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Patient(org.hl7.fhir.r4.model.Patient) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 77 with Extension

use of org.hl7.fhir.r4.model.Extension in project hl7v2-fhir-converter by LinuxForHealth.

the class CodeableConceptTest method testCodeableConceptDoubleRaceWithVersionAndAlternate.

@Test
void testCodeableConceptDoubleRaceWithVersionAndAlternate() {
    // This has both a known and an unknown system.
    // "valueCodeableConcept": {
    // "coding": [ {
    // "system": <known-to-FHIR>,  << FIRST CODING
    // "display": <original-display-value>
    // "code": <code-from-input>
    // "version": <version>
    // },
    // {
    // "system": <unknown, so made up "urn:id:L">,  << SECOND (ALTERNATE CODING)
    // "display": <original-alternate display-value>
    // "code": <altenate-code>
    // "version": <alternate-version>
    // } ],
    // "text": <original-display-value>
    // },
    String patientWithDoubleRaceWithVersionAndAlternate = "MSH|^~\\&|MIICEHRApplication|MIIC|MIIC|MIIC|201705130822||VXU^V04^VXU_V04|test1100|P|2.5.1|||AL|AL|||||Z22^CDCPHINVS|^^^^^MIIC^SR^^^MIIC|MIIC\n" + // Test double race in the SAME CWE (not a second CWE) and versions.  Use made up Cauc to ensure test doesn't mix up whites.
    "PID|1||12345678^^^^MR||TestPatientLastName^Jane|||||2106-3^White^CDCREC^CA^Caucasian^L^1.1^4|\n";
    Patient patient = PatientUtils.createPatientFromHl7Segment(ftv, patientWithDoubleRaceWithVersionAndAlternate);
    assertThat(patient.hasExtension()).isTrue();
    List<Extension> extensions = patient.getExtensionsByUrl(UrlLookup.getExtensionUrl("race"));
    assertThat(extensions).isNotNull();
    assertThat(extensions.size()).isEqualTo(1);
    assertThat(extensions.get(0).hasValue()).isTrue();
    CodeableConcept ccW = (CodeableConcept) extensions.get(0).getValue();
    assertThat(ccW.hasCoding()).isTrue();
    assertThat(ccW.hasText()).isTrue();
    assertThat(ccW.getText()).hasToString("White");
    List<Coding> codings = ccW.getCoding();
    assertThat(codings.size()).isEqualTo(2);
    DatatypeUtils.checkCommonCodingAssertions(codings.get(0), "2106-3", "White", V3_RACE_SYSTEM, "1.1");
    DatatypeUtils.checkCommonCodingAssertions(codings.get(1), "CA", "Caucasian", "urn:id:L", "4");
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Coding(org.hl7.fhir.r4.model.Coding) Patient(org.hl7.fhir.r4.model.Patient) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 78 with Extension

use of org.hl7.fhir.r4.model.Extension in project hl7v2-fhir-converter by LinuxForHealth.

the class FHIRExtensionsTest method testTextOnlyReligion.

@Test
void testTextOnlyReligion() {
    String patientWithDataForExtensions = "MSH|^~\\&|MIICEHRApplication|MIIC|MIIC|MIIC|201705130822||VXU^V04^VXU_V04|test1100|P|2.5.1|||AL|AL|||||Z22^CDCPHINVS|^^^^^MIIC^SR^^^MIIC|MIIC\n" + // Test text only religion
    "PID|1||12345678^^^^MR||Jane^TestPatientLastName||||||||||||Methodist|\n";
    Patient patient = PatientUtils.createPatientFromHl7Segment(ftv, patientWithDataForExtensions);
    assertThat(patient.hasExtension()).isTrue();
    Extension ext = patient.getExtensionByUrl(UrlLookup.getExtensionUrl("religion"));
    assertThat(ext).isNotNull();
    CodeableConcept cc = (CodeableConcept) ext.getValue();
    assertThat(cc.hasCoding()).isTrue();
    assertThat(cc.hasText()).isFalse();
    Coding coding = cc.getCodingFirstRep();
    assertThat(coding).isNotNull();
    assertThat(coding.hasCode()).isFalse();
    String theSystem = V3ReligiousAffiliation._1029.getSystem();
    assertThat(coding.hasSystem()).isTrue();
    assertThat(coding.getSystem()).isEqualTo(theSystem);
    assertThat(coding.hasDisplay()).isTrue();
    assertThat(coding.getDisplay()).containsPattern("Invalid.*Methodist.*" + theSystem);
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Coding(org.hl7.fhir.r4.model.Coding) Patient(org.hl7.fhir.r4.model.Patient) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.jupiter.api.Test)

Example 79 with Extension

use of org.hl7.fhir.r4.model.Extension in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7PatientFHIRConversionTest method validate_data_lineage.

private void validate_data_lineage(String hl7message, String messageType, boolean millis) {
    String json = ftv.convert(hl7message, PatientUtils.OPTIONS);
    assertThat(json).isNotBlank();
    LOGGER.debug(json);
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    List<BundleEntryComponent> e = b.getEntry();
    // Get bundle meta extensions *not using these currently*
    // Meta bundleMeta = b.getMeta();
    // List<Extension> bundleMetaExtensions = bundleMeta.getExtension();
    LOGGER.debug("Found {} resources.", e.stream().count());
    e.stream().forEach(bec -> {
        LOGGER.debug("Validating " + bec.getResource().getResourceType());
        Meta meta = bec.getResource().getMeta();
        List<Extension> extensions = meta.getExtension();
        LOGGER.debug("Found " + extensions.size() + " meta extensions");
        validate_lineage_json(extensions, messageType, millis);
    });
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Meta(org.hl7.fhir.r4.model.Meta) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource)

Example 80 with Extension

use of org.hl7.fhir.r4.model.Extension in project hl7v2-fhir-converter by LinuxForHealth.

the class InputTimeZoneIdTest method validateTimeZoneIdSettingViaOption.

@Test
void validateTimeZoneIdSettingViaOption() {
    // NOTE: This simple Condition (PRB) segment is used for testing time because it has both
    // standard DateTime conversions (abatementDateTime, recordedDate) and value conversions (extension).
    String hl7message = "MSH|^~\\&|||||20040629164652|1|PPR^PC1|331|P|2.3.1||\r" + "PID||||||||||||||||||||||||||||||\r" + "PV1||I||||||||||||||||||||||||||||||||||||||||||\r" + // PRB.16 to onsetDateTime (check time ZoneId)
    "PRB|AD|20020202020000|K80.00^Cholelithiasis^I10|53956|||20070707070000||20090909090000|||||||20160616160000\r";
    // FIRST test with city based ZoneId passed through options
    ConverterOptions customOptionsWithTenant = new Builder().withValidateResource().withPrettyPrint().withZoneIdText("America/Chicago").build();
    // "America/Chicago" will become -06:00 in winter (CST) -05:00 in spring/summer/fall (CDT).  This is expected.
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message, customOptionsWithTenant);
    // Find the condition from the FHIR bundle.
    List<Resource> conditionResource = ResourceUtils.getResourceList(e, ResourceType.Condition);
    assertThat(conditionResource).hasSize(1);
    Condition condition = (Condition) conditionResource.get(0);
    // PRB.2 Chicago Central STANDARD Time
    assert (condition.getRecordedDateElement().getValueAsString()).contains("2002-02-02T02:00:00-06:00");
    // PRB.9 Chicago Central DAYLIGHT Time
    assert (condition.getAbatementDateTimeType().getValueAsString()).contains("2009-09-09T09:00:00-05:00");
    // PRB.16 Chicago CDT
    assert (condition.getOnsetDateTimeType().getValueAsString()).contains("2016-06-16T16:00:00-05:00");
    assert (condition.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/condition-assertedDate").getValueAsPrimitive().getValueAsString()).contains(// PRB.7 Chicago CDT
    "2007-07-07T07:00:00-05:00");
    // SECOND test with fixed ZoneId passed through options
    customOptionsWithTenant = new Builder().withValidateResource().withPrettyPrint().withZoneIdText("+03:00").build();
    e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message, customOptionsWithTenant);
    // Find the condition from the FHIR bundle.
    conditionResource = ResourceUtils.getResourceList(e, ResourceType.Condition);
    assertThat(conditionResource).hasSize(1);
    condition = (Condition) conditionResource.get(0);
    // PRB.2 fixed ZoneId
    assert (condition.getRecordedDateElement().getValueAsString()).contains("2002-02-02T02:00:00+03:00");
    // PRB.9
    assert (condition.getAbatementDateTimeType().getValueAsString()).contains("2009-09-09T09:00:00+03:00");
    // PRB.16
    assert (condition.getOnsetDateTimeType().getValueAsString()).contains("2016-06-16T16:00:00+03:00");
    assert (condition.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/condition-assertedDate").getValueAsPrimitive().getValueAsString()).contains(// PRB.7
    "2007-07-07T07:00:00+03:00");
    // THIRD test with no ZoneId passed through options, so it uses the config.properties ZoneId
    customOptionsWithTenant = new Builder().withValidateResource().withPrettyPrint().build();
    e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message, customOptionsWithTenant);
    // Find the condition from the FHIR bundle.
    conditionResource = ResourceUtils.getResourceList(e, ResourceType.Condition);
    assertThat(conditionResource).hasSize(1);
    condition = (Condition) conditionResource.get(0);
    // PRB.2 config.properties ZoneId
    assert (condition.getRecordedDateElement().getValueAsString()).contains("2002-02-02T02:00:00+08:00");
    // PRB.9
    assert (condition.getAbatementDateTimeType().getValueAsString()).contains("2009-09-09T09:00:00+08:00");
    // PRB.16
    assert (condition.getOnsetDateTimeType().getValueAsString()).contains("2016-06-16T16:00:00+08:00");
    assert (condition.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/condition-assertedDate").getValueAsPrimitive().getValueAsString()).contains(// PRB.7
    "2007-07-07T07:00:00+08:00");
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) ConverterOptions(io.github.linuxforhealth.hl7.ConverterOptions) Builder(io.github.linuxforhealth.hl7.ConverterOptions.Builder) Resource(org.hl7.fhir.r4.model.Resource) Test(org.junit.jupiter.api.Test)

Aggregations

Extension (org.hl7.fhir.r4.model.Extension)154 ArrayList (java.util.ArrayList)104 Coding (org.hl7.fhir.r4.model.Coding)69 Test (org.junit.jupiter.api.Test)69 Extension (org.hl7.fhir.dstu3.model.Extension)67 FHIRException (org.hl7.fhir.exceptions.FHIRException)55 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)46 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)42 Extension (org.hl7.fhir.r5.model.Extension)41 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)39 Test (org.junit.Test)36 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)35 List (java.util.List)34 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)34 Date (java.util.Date)30 Coding (org.hl7.fhir.dstu3.model.Coding)29 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)27 Row (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row)27 Reference (org.hl7.fhir.dstu3.model.Reference)26 Patient (org.hl7.fhir.r4.model.Patient)26