Search in sources :

Example 26 with BundleEntryComponent

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

the class HL7ConditionFHIRConversionTest method validateProblemWithOnsetDateTimeWithNoOnsetString.

// Tests that onset[x] is set to PRB.16 if it is present AND
// Tests that onset[x] is set to PRB.16 if it is present and PRB.17 is present.
@ParameterizedTest
@ValueSource(strings = { // PRB.17 purposely empty
"PRB|AD|20170110074000|K80.00^Cholelithiasis^I10|53956||||||||||||20180310074000||\r", // PRB.17 present
"PRB|AD|20170110074000|K80.00^Cholelithiasis^I10|53956||||||||||||20180310074000|textual representation of the time when the problem began|\r" })
void validateProblemWithOnsetDateTimeWithNoOnsetString(String segmentPRB) {
    String hl7message = "MSH|^~\\&|||||20040629164652|1|PPR^PC1|331|P|2.3.1||\r" + "PID||||||||||||||||||||||||||||||\r" + segmentPRB;
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    // Find the condition from the FHIR bundle.
    List<Resource> conditionResource = ResourceUtils.getResourceList(e, ResourceType.Condition);
    assertThat(conditionResource).hasSize(1);
    // Get the condition Resource
    Condition condition = (Condition) conditionResource.get(0);
    // Verify onset is set correctly to PRB.16
    // PRB.16
    assertThat(condition.getOnset().toString()).containsPattern("2018-03-10T07:40:00");
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with BundleEntryComponent

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

the class HL7ConditionFHIRConversionTest method validateProblemHappyTestTwo.

// Tests the PRB segment (problem) with all supported message types. This tests
// all the fields in the happy path (Part 2).
@ParameterizedTest
@ValueSource(strings = { "MSH|^~\\&|||||20040629164652|1|PPR^PC1|331|P|2.3.1||\r" // "MSH|^~\\&|||||20040629164652|1|PPR^PC2|331|P|2.3.1||\r",
// "MSH|^~\\&|||||20040629164652|1|PPR^PC3|331|P|2.3.1||\r",
})
void validateProblemHappyTestTwo(String msh) {
    String hl7message = msh + "PID||||||||||||||||||||||||||||||\r" + "PV1||I||||||||||||||||||||||||||||||||||||||||||\r" + // // PRB.14 for clinical Status
    "PRB|AD|20170110074000|K80.00^Cholelithiasis^I10|53956||||||||||remission^Remission^http://terminology.hl7.org/CodeSystem/condition-clinical|||||||||||||\r";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    // Find the conditions from the FHIR bundle.
    List<Resource> conditionResource = ResourceUtils.getResourceList(e, ResourceType.Condition);
    assertThat(conditionResource).hasSize(1);
    Condition condition = (Condition) conditionResource.get(0);
    // Verify code is set correctly.
    DatatypeUtils.checkCommonCodeableConceptAssertions(condition.getCode(), "K80.00", "Cholelithiasis", "http://hl7.org/fhir/sid/icd-10-cm", // PRB.3
    "Cholelithiasis");
    // Verify clinicalStatus is set correctly
    DatatypeUtils.checkCommonCodeableConceptAssertions(condition.getClinicalStatus(), "remission", "Remission", "http://terminology.hl7.org/CodeSystem/condition-clinical", // PRB.14
    "Remission");
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with BundleEntryComponent

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

the class HL7ConditionFHIRConversionTest method validateProblemWithInvalidClinicalStatusAndResolutionDate.

// Tests that if PRB.9 is set and PRB.14 is INVALID, default Condition.clinicalStatus to "resolved"
@Test
void validateProblemWithInvalidClinicalStatusAndResolutionDate() {
    String hl7message = "MSH|^~\\&|||||20040629164652|1|PPR^PC1|331|P|2.3.1||\r" + "PID||||||||||||||||||||||||||||||\r" + // PRB.9 Actual Problem Resolution Date used in connection with INVALID PRB.14 to trigger Resolved clinicalStatus
    "PRB|AD|20170110074000|K80.00^Cholelithiasis^I10|53956|||||20150907175347|||||INVALID|||||||||||||\r";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    // 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);
    // Verify clinicalStatus has a Resolved coding with correct system and text (based on PRB.9 and INVALID PRB.14)
    DatatypeUtils.checkCommonCodeableConceptAssertions(condition.getClinicalStatus(), "resolved", "Resolved", "http://terminology.hl7.org/CodeSystem/condition-clinical", null);
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with BundleEntryComponent

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

the class HL7ConditionFHIRConversionTest method validateDiagnosis.

// --------------------- DIAGNOSIS UNIT TESTS (DG1) ---------------------
// Tests the DG1 segment (diagnosis) with all supported message types.
// This tests all the fields in the happy path.
// 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
@ValueSource(strings = { "MSH|^~\\&|||||||ADT^A01^ADT_A01|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6||||||\r", // "MSH|^~\\&|||||||ADT^A04|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6||||||\r",
"MSH|^~\\&|||||||ADT^A08|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6||||||\r" // "MSH|^~\\&|||||||ADT^A28^ADT^A28|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6||||||\r",
// "MSH|^~\\&|||||||ADT^A31|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6||||||\r",
// "MSH|^~\\&|||||||ORM^O01|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6||||||\r"
// PPR_PC1, PPR_PC2, and PPR_PC3 create Conditions but they don't have a DG1 segment so they are tested in a different testcase.
})
void validateDiagnosis(String msh) {
    String hl7message = msh + "PID||||||||||||||||||||||||||||||\r" + "PV1||I|||||||||||||||||1400|||||||||||||||||||||||||\r" + // DG1.20 to Identifier
    "DG1|1||C56.9^Ovarian Cancer^I10||20210322154449|A|||||||||1|123^DOE^JOHN^A^|||20210322154326|V45|||||\r";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    // Verify no extraneous resources
    // Expect encounter, patient, practitioner, condition
    assertThat(e).hasSize(4);
    // --- CONDITION TESTS ---
    // 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);
    // Verify we have 3 identifiers
    // NOTE: The other identifiers, not related to condition, are tested deeply in the
    // identifier suite of unit tests.
    assertThat(condition.getIdentifier()).hasSize(3);
    // First identifier is the Visit Number, and is a codeable concept
    DatatypeUtils.checkCommonCodeableConceptAssertions(condition.getIdentifier().get(0).getType(), "VN", "Visit number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // Second identifier
    assertThat(condition.getIdentifier().get(1).getSystem()).isEqualTo("urn:id:extID");
    assertThat(condition.getIdentifier().get(1).getValue()).isEqualTo("C56.9-I10");
    // The 3rd identifier value should be from DG1.20
    // DG1.20
    assertThat(condition.getIdentifier().get(2).getValue()).isEqualTo("V45");
    // Verify asserter reference to Practitioner exists
    assertThat(condition.getAsserter().getReference().substring(0, 13)).isEqualTo("Practitioner/");
    // Verify recorded date is set correctly.
    // DG1.19
    assertThat(condition.getRecordedDateElement().toString()).containsPattern("2021-03-22T15:43:26");
    // Verify onset date time is set correctly.
    // DG1.5
    assertThat(condition.getOnset().toString()).containsPattern("2021-03-22T15:44:49");
    // Verify code text and coding are set correctly.
    DatatypeUtils.checkCommonCodeableConceptAssertions(condition.getCode(), "C56.9", "Ovarian Cancer", "http://hl7.org/fhir/sid/icd-10-cm", // DG1.3
    "Ovarian Cancer");
    // Verify encounter reference exists
    assertThat(condition.getEncounter().getReference().substring(0, 10)).isEqualTo("Encounter/");
    // Verify subject reference to Patient exists
    assertThat(condition.getSubject().getReference().substring(0, 8)).isEqualTo("Patient/");
    // Verify category text and coding are set correctly.
    assertThat(condition.getCategory()).hasSize(1);
    DatatypeUtils.checkCommonCodeableConceptAssertions(condition.getCategoryFirstRep(), "encounter-diagnosis", "Encounter Diagnosis", "http://terminology.hl7.org/CodeSystem/condition-category", // DG1.3
    "Encounter Diagnosis");
    // --- ENCOUNTER TESTS ---
    List<Resource> encounterResource = ResourceUtils.getResourceList(e, ResourceType.Encounter);
    assertThat(encounterResource).hasSize(1);
    Encounter encounter = (Encounter) encounterResource.get(0);
    // Encounter should have a reference to the conditions (only 1 in this unit test)
    assertThat(encounter.getReasonReference()).hasSize(1);
    assertThat(encounter.getReasonReference().get(0).getReference().substring(0, 10)).isEqualTo("Condition/");
    // Verify encounter diagnosis condition, use, and rank are set correctly
    assertThat(encounter.getDiagnosis()).hasSize(1);
    assertThat(encounter.getDiagnosisFirstRep().getCondition().getReference().substring(0, 10)).isEqualTo("Condition/");
    DatatypeUtils.checkCommonCodeableConceptAssertions(encounter.getDiagnosisFirstRep().getUse(), "AD", "Admission diagnosis", "http://terminology.hl7.org/CodeSystem/diagnosis-role", // DG1.6
    null);
    // DG1.15
    assertThat(encounter.getDiagnosisFirstRep().getRank()).isEqualTo(1);
    // --- PRACTIONER TESTS ---
    // Find the asserter (practitioner)  resource from the FHIR bundle.
    List<Resource> practitionerResource = ResourceUtils.getResourceList(e, ResourceType.Practitioner);
    assertThat(practitionerResource).hasSize(1);
    Practitioner practitioner = (Practitioner) practitionerResource.get(0);
    // Verify name text, family, and given are set correctly.
    assertThat(practitioner.getName()).hasSize(1);
    // DG1.16
    assertThat(practitioner.getNameFirstRep().getText()).isEqualTo("JOHN A DOE");
    // DG1.16.2
    assertThat(practitioner.getNameFirstRep().getFamily()).isEqualTo("DOE");
    // DG1.16.3
    assertThat(practitioner.getNameFirstRep().getGivenAsSingleString()).isEqualTo("JOHN A");
    // Verify asserter (practitioner) identifier is set correctly.
    assertThat(practitioner.getIdentifier()).hasSize(1);
    // DG1.16.1
    assertThat(practitioner.getIdentifierFirstRep().getValue()).isEqualTo("123");
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) Practitioner(org.hl7.fhir.r4.model.Practitioner) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) Encounter(org.hl7.fhir.r4.model.Encounter) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with BundleEntryComponent

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

the class HL7ConditionFHIRConversionTest method validateEncounterMultipleDiagnosesTestingMultipleDiagnosisAndReasonReferences.

// Tests that the Encounter has the full array of condition references in both
// diagnosis and reasonReference.
@Test
void validateEncounterMultipleDiagnosesTestingMultipleDiagnosisAndReasonReferences() {
    String hl7message = "MSH|^~\\&||||||S1|ADT^A01^ADT_A01||T|2.6|||||||||\r" + "EVN|A04||||||\r" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\r" + "PV1||I|||||||||||||||||1492|||||||||||||||||||||||||\r" + "DG1|1|D1|V72.83^Other specified pre-operative examination^ICD-9^^^|Other specified pre-operative examination|20151008111200|F|||||||||8|\r" + "DG1|2|D2|R00.0^Tachycardia, unspecified^ICD-10^^^|Tachycardia, unspecified|20150725201300|F|||||||||8|\r" + "DG1|3|D3|R06.02^Shortness of breath^ICD-10^^^|Shortness of breath||F|||||||||8|\r" + "DG1|4|D4|Q99.9^Chromosomal abnormality, unspecified^ICD-10^^^|Chromosomal abnormality, unspecified||F|||||||||8|\r" + "DG1|5|D5|I34.8^Arteriosclerosis^ICD-10^^^|Arteriosclerosis||F|||||||||8|\r" + "DG1|6|D6|I34.0^Mitral valve regurgitation^ICD-10^^^|Mitral valve regurgitation||F|||||||||8|\r" + "DG1|6|D7|I05.9^Mitral valve disorder in childbirth^ICD-10^^^|Mitral valve disorder in childbirth||F|||||||||8|\r" + "DG1|7|D8|J45.909^Unspecified asthma, uncomplicated^ICD-10^^^|Unspecified asthma, uncomplicated||F|||||||||8|\r";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    // Find the conditions from the FHIR bundle.
    List<Resource> conditionResource = ResourceUtils.getResourceList(e, ResourceType.Condition);
    // We should have 1 condition for each diagnosis therefore 8 for this message.
    assertThat(conditionResource).hasSize(8);
    // Find the encounter from the FHIR bundle.
    List<Resource> encounterResource = ResourceUtils.getResourceList(e, ResourceType.Encounter);
    // Verify we only have 1 encounter
    assertThat(encounterResource).hasSize(1);
    Encounter encounter = (Encounter) encounterResource.get(0);
    // Verify reasonReference has a reference for each condition. Therefore there should be 8.
    assertThat(encounter.getReasonReference()).hasSize(8);
    // Check the references are referencing conditions
    for (int i = 0; i < 8; i++) {
        assertThat(encounter.getReasonReference().get(i).getReference().substring(0, 10)).isEqualTo("Condition/");
    }
    // Verify there is encounter.diagnosis for every diagnosis. Therefore there should be 8.
    assertThat(encounter.getDiagnosis()).hasSize(8);
    List<String> referencedConditions = encounter.getDiagnosis().stream().map(i -> i.getCondition().getReference()).collect(Collectors.toList());
    List<String> condIdentifiers = conditionResource.stream().map(r -> (Condition) r).map(c -> c.getId()).collect(Collectors.toList());
    assertThat(referencedConditions).containsExactlyInAnyOrderElementsOf(condIdentifiers);
    // Verify each diagnosis is set correctly.
    for (int i = 0; i < 8; i++) {
        // Diagnosis requires a reference to condition.
        assertThat(encounter.getDiagnosis().get(i).getCondition().getReference().substring(0, 10)).isEqualTo("Condition/");
        // Verify Use coding of each diagnosis
        DatatypeUtils.checkCommonCodeableConceptAssertions(encounter.getDiagnosis().get(i).getUse(), "F", "Final", "http://terminology.hl7.org/CodeSystem/v2-0052", null);
        // Verify encounter diagnosis rank is set correctly.
        // DG1.15
        assertThat(encounter.getDiagnosis().get(i).getRank()).isEqualTo(8);
    }
}
Also used : ValueSource(org.junit.jupiter.params.provider.ValueSource) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Resource(org.hl7.fhir.r4.model.Resource) Condition(org.hl7.fhir.r4.model.Condition) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Encounter(org.hl7.fhir.r4.model.Encounter) ResourceType(org.hl7.fhir.r4.model.ResourceType) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DatatypeUtils(io.github.linuxforhealth.hl7.segments.util.DatatypeUtils) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) ResourceUtils(io.github.linuxforhealth.hl7.segments.util.ResourceUtils) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) HL7ToFHIRConverter(io.github.linuxforhealth.hl7.HL7ToFHIRConverter) Practitioner(org.hl7.fhir.r4.model.Practitioner) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) Encounter(org.hl7.fhir.r4.model.Encounter) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)214 Resource (org.hl7.fhir.r4.model.Resource)153 Test (org.junit.jupiter.api.Test)126 Bundle (org.hl7.fhir.r4.model.Bundle)96 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)88 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)87 Reference (org.hl7.fhir.r4.model.Reference)46 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)42 Date (java.util.Date)40 Observation (org.hl7.fhir.r4.model.Observation)34 MedicationRequest (org.hl7.fhir.r4.model.MedicationRequest)33 Patient (org.hl7.fhir.r4.model.Patient)33 BundleEntryComponent (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)32 Condition (org.hl7.fhir.r4.model.Condition)30 Test (org.junit.Test)30 ArrayList (java.util.ArrayList)29 Coding (org.hl7.fhir.r4.model.Coding)29 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)29 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)28 Identifier (org.hl7.fhir.r4.model.Identifier)26