Search in sources :

Example 86 with Bundle

use of org.hl7.fhir.r4b.model.Bundle 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 87 with Bundle

use of org.hl7.fhir.r4b.model.Bundle 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 88 with Bundle

use of org.hl7.fhir.r4b.model.Bundle 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 89 with Bundle

use of org.hl7.fhir.r4b.model.Bundle 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)

Example 90 with Bundle

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

the class HL7EventTypeFHIRConversionTest method validateEVNsegmentWithOBXreference.

@Test
void validateEVNsegmentWithOBXreference() {
    // When there is an OBX record, it should create a reason reference in the encounter segment
    String hl7message = "MSH|^~\\&|||||||ADT^A01^ADT_A01|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6||||||\r" + "EVN||||7525|||\r" + "PV1|1|I||R|||||||||R|1||||||||||||||||||||||||||||||200603150624|200603150625|||||||\r" + "OBX|1|CWE|DQW^Some text 1^SNM3|||||||||||||||||||||\r";
    String json = ftv.convert(hl7message, OPTIONS);
    assertThat(json).isNotBlank();
    FHIRContext context = new FHIRContext(true, false);
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    List<BundleEntryComponent> e = b.getEntry();
    // Find the Observation in the bundle
    List<Resource> obsResource = e.stream().filter(v -> ResourceType.Observation == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    assertThat(obsResource).hasSize(1);
    Observation obs = (Observation) obsResource.get(0);
    // Find the encounter from the FHIR bundle.
    List<Resource> encounterResource = e.stream().filter(v -> ResourceType.Encounter == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    assertThat(encounterResource).hasSize(1);
    Encounter encounter = (Encounter) encounterResource.get(0);
    assertThat(encounter.hasReasonReference()).isTrue();
    assertThat(encounter.getReasonReference()).hasSize(1);
    // Check that the cross reference is equal to the Observation id
    assertThat(encounter.getReasonReferenceFirstRep().getReference()).hasToString(obs.getId());
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Observation(org.hl7.fhir.r4.model.Observation) Encounter(org.hl7.fhir.r4.model.Encounter) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Test(org.junit.jupiter.api.Test)

Aggregations

Bundle (org.hl7.fhir.r4.model.Bundle)603 Bundle (org.hl7.fhir.dstu3.model.Bundle)357 Test (org.junit.Test)343 Test (org.junit.jupiter.api.Test)316 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)306 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)192 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)167 Date (java.util.Date)159 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)151 ArrayList (java.util.ArrayList)147 List (java.util.List)143 Resource (org.hl7.fhir.r4.model.Resource)128 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)116 HashMap (java.util.HashMap)113 Collectors (java.util.stream.Collectors)108 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)106 Patient (org.hl7.fhir.r4.model.Patient)93 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)85 Observation (org.hl7.fhir.r4.model.Observation)79 IOException (java.io.IOException)77