Search in sources :

Example 91 with Value

use of org.hl7.fhir.utilities.graphql.Value in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7FinancialInsuranceTest method testInsuranceCoverageOfWorkersComp.

@Test
// Tests non-related subscriber, employer.
void testInsuranceCoverageOfWorkersComp() throws IOException {
    String hl7message = "MSH|^~\\&|TEST|TEST|||20220101120000||DFT^P03|1234|P|2.6\n" + // + "EVN||20210407191342||||||\n"
    "PID|||workers_comp^^^XYZ^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + "PV1||I||||||||||||||||||||||||||||||||||||||||||\n" + // FT1.7 is required transaction code (currently not used)
    "FT1||||20201231145045||CG|FAKE|||||||||||||||||||||||||||||||||||||\n" + // IN1.2.4, IN1.2.6 to second XV Coverage.identifier
    "IN1|1|Value1^^System3^Value4^^System6" + // IN1.5 through 15 NOT REFERENCED (Tested in testBasicInsuranceCoverageFields)
    "|IdValue1^^^IdSystem4^^^^|Large Blue Organization|||||||||||" + // IN1.18 through IN1.35 NOT REFERENCED
    "||EMR||||||||||||||||||" + // IN1.37 through IN1.53 NOT REFERENCED
    "|MEMBER36|||||||||||||J321456||||\n";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    List<Resource> encounters = ResourceUtils.getResourceList(e, ResourceType.Encounter);
    // From PV1
    assertThat(encounters).hasSize(1);
    List<Resource> patients = ResourceUtils.getResourceList(e, ResourceType.Patient);
    // From PID
    assertThat(patients).hasSize(1);
    Patient patient = (Patient) patients.get(0);
    String patientId = patient.getId();
    // No patient identifier should have value IN1.49 "J321456" because relationship is not SEL (self)
    // Finding exactly 1 expected identifier "workers_comp" proves not "J321456"
    assertThat(patient.getIdentifier()).hasSize(1);
    assertThat(patient.getIdentifierFirstRep().getValueElement()).hasToString("workers_comp");
    List<Resource> organizations = ResourceUtils.getResourceList(e, ResourceType.Organization);
    // From Payor created by IN1
    assertThat(organizations).hasSize(1);
    Organization org = (Organization) organizations.get(0);
    // Check organization Id's
    assertThat(org.getIdentifier()).hasSize(1);
    // Org identifiers checked deeply in other tests
    List<Resource> coverages = ResourceUtils.getResourceList(e, ResourceType.Coverage);
    // From IN1 segment
    assertThat(coverages).hasSize(1);
    Coverage coverage = (Coverage) coverages.get(0);
    // Confirm Coverage Identifiers
    // XV, XV, MB, SN
    assertThat(coverage.getIdentifier()).hasSize(4);
    // Coverage Identifiers deep check in testBasicInsuranceCoverageFields
    // Because the relationship is EMR (Employer), no subscriber is created (subscriber can't be an Organization)
    assertThat(coverage.hasSubscriber()).isFalse();
    // Confirm Coverage Beneficiary references to Patient, and Payor references to Organization
    assertThat(coverage.getBeneficiary().getReference()).isEqualTo(patientId);
    assertThat(coverage.getPayorFirstRep().getReference()).isEqualTo(organizations.get(0).getId());
    // Expect no RelatedPerson because IN1.17 was EMR
    List<Resource> relatedPersons = ResourceUtils.getResourceList(e, ResourceType.RelatedPerson);
    // No related person should be created because IN2.72 was 01 (self)
    assertThat(relatedPersons).isEmpty();
    // Check coverage.relationship (from SubscriberRelationship mapping)
    DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getRelationship(), "EMR", null, null, // IN1.17, because it is not mapped there is no system or display.
    null);
    // Confirm there are no unaccounted for resources
    // Expected: Coverage, Organization, Patient, Encounter
    assertThat(e).hasSize(4);
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Organization(org.hl7.fhir.r4.model.Organization) Resource(org.hl7.fhir.r4.model.Resource) Patient(org.hl7.fhir.r4.model.Patient) Coverage(org.hl7.fhir.r4.model.Coverage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 92 with Value

use of org.hl7.fhir.utilities.graphql.Value in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7DocumentReferenceFHIRConversionTest method doc_ref_status_test.

@ParameterizedTest
@ValueSource(strings = { "MDM^T02", "MDM^T06" })
void doc_ref_status_test(String segment) {
    // Check TXA.19
    // TXA.19 value maps to status; OBR.25 is ignored
    String documentReferenceMessage = "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|" + segment + "^MDM_T02|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6|56789^NID^UID|MCM||||\n" + "PID|1||000054321^^^MRN|||||||||||||M|CAT|||||N\n" + "PV1|1|I||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|NW|||PGN001|SC|D|1|||MS|MS|||||\n" + "OBR|1||||||20170825010500|||||||||||||002|||||F||||||||\n" + "TXA|1||TEXT||||201801180346||<PHYSID1>||||||||PA||OB|||<PHYSID2>||\n" + "OBX|1|SN|||||||||X";
    DocumentReference report = ResourceUtils.getDocumentReference(ftv, documentReferenceMessage);
    org.hl7.fhir.r4.model.Enumerations.DocumentReferenceStatus status = report.getStatus();
    // TXA.19
    assertThat(status.toCode()).isEqualTo("superseded");
    assertThat(status.getSystem()).isEqualTo("http://hl7.org/fhir/document-reference-status");
    // Check OBR.25 as fallback
    // TXA.19 value is empty so OBR.25 is used
    documentReferenceMessage = "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|" + segment + "^MDM_T02|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6|56789^NID^UID|MCM||||\n" + "PID|1||000054321^^^MRN|||||||||||||M|CAT|||||N\n" + "PV1|1|I||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|NW|||PGN001|SC|D|1|||MS|MS\n" + "OBR|1||||||20170825010500|||||||||||||002|||||X\n" + "TXA|1||TEXT||||201801180346||<PHYSID1>||||||||PA|||||<PHYSID2>\n" + "OBX|1|SN|||||||||X";
    report = ResourceUtils.getDocumentReference(ftv, documentReferenceMessage);
    status = report.getStatus();
    // OBR.25
    assertThat(status.toCode()).isEqualTo("entered-in-error");
    assertThat(status.getSystem()).isEqualTo("http://hl7.org/fhir/document-reference-status");
    // Check default value case
    // TXA.19 and OBR.25 values are empty so should fallback to "current"
    documentReferenceMessage = "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|" + segment + "^MDM_T02|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6|56789^NID^UID|MCM||||\n" + "PID|1||000054321^^^MRN|||||||||||||M|CAT|||||N\n" + "PV1|1|I||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|NW|||PGN001|SC|D|1|||MS|MS|||||\n" + "OBR|1||||||20170825010500|||||||||||||002\n" + "TXA|1||TEXT||||201801180346||<PHYSID1>||||||||PA\n" + "OBX|1|SN|||||||||X";
    report = ResourceUtils.getDocumentReference(ftv, documentReferenceMessage);
    status = report.getStatus();
    // default value
    assertThat(status.toCode()).isEqualTo("current");
    assertThat(status.getSystem()).isEqualTo("http://hl7.org/fhir/document-reference-status");
}
Also used : DocumentReference(org.hl7.fhir.r4.model.DocumentReference) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 93 with Value

use of org.hl7.fhir.utilities.graphql.Value in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7DocumentReferenceFHIRConversionTest method doc_ref_doc_status_test.

@ParameterizedTest
@ValueSource(strings = { "MDM^T02", "MDM^T06" })
void doc_ref_doc_status_test(String segment) {
    String documentReferenceMessage = "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|" + segment + "^MDM_T02|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6|56789^NID^UID|MCM||||\n" + "PID|1||000054321^^^MRN|||||||||||||M|CAT|||||N\n" + "PV1|1|I||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|NW|||PGN001|SC|D|1|||MS|MS|||||\n" + "OBR|1||||||20170825010500|||||||||||||002|||||F||||||||\n" + "TXA|1||TEXT|||20180117144200|201801180346||<PHYSID1>||||||||PA||AV|||<PHYSID2>||\n" + "OBX|1|ST|100||This is content|||||||X\n";
    DocumentReference report = ResourceUtils.getDocumentReference(ftv, documentReferenceMessage);
    DocumentReference.ReferredDocumentStatus docStatus = report.getDocStatus();
    // TXA.17
    assertThat(docStatus.toCode()).isEqualTo("preliminary");
    assertThat(docStatus.getDefinition()).contains("This is a preliminary composition or document (also known as initial or interim).");
    assertThat(docStatus.getSystem()).isEqualTo("http://hl7.org/fhir/composition-status");
    // Check OBX.11 as fallback
    documentReferenceMessage = "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|" + segment + "^MDM_T02|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6|56789^NID^UID|MCM||||\n" + "PID|1||000054321^^^MRN|||||||||||||M|CAT|||||N\n" + "PV1|1|I||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|NW|||PGN001|SC|D|1|||MS|MS|||||\n" + "OBR|1|||555|||20170825010500|||||||||||||002|||||F||||||||\n" + "TXA|1||TEXT|||20180117144200|201801180346||<PHYSID1>||||||||||AV|||<PHYSID2>||\n" + "OBX|1|SN|||||||||F";
    report = ResourceUtils.getDocumentReference(ftv, documentReferenceMessage);
    docStatus = report.getDocStatus();
    // OBX.11
    assertThat(docStatus.toCode()).isEqualTo("final");
    assertThat(docStatus.getDefinition()).contains("This version of the composition is complete and verified by an appropriate person and no further work is planned.");
    assertThat(docStatus.getSystem()).isEqualTo("http://hl7.org/fhir/composition-status");
    // Check a value that is not mapped results is no docStatus
    documentReferenceMessage = "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|" + segment + "^MDM_T02|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6|56789^NID^UID|MCM||||\n" + "PID|1||000054321^^^MRN|||||||||||||M|CAT|||||N\n" + "PV1|1|I||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|NW|||PGN001|SC|D|1|||MS|MS\n" + "OBR|1|||555|||20170825010500|||||||||||||002|||||F\n" + "TXA|1||TEXT|||20180117144200|201801180346||<PHYSID1>||||||||||AV|||<PHYSID2>\n" + "OBX|1|SN|||||||||X";
    report = ResourceUtils.getDocumentReference(ftv, documentReferenceMessage);
    // OBX-11 'X' is not mapped
    assertThat(report.getDocStatus()).isNull();
}
Also used : DocumentReference(org.hl7.fhir.r4.model.DocumentReference) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 94 with Value

use of org.hl7.fhir.utilities.graphql.Value 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 95 with Value

use of org.hl7.fhir.utilities.graphql.Value in project hl7v2-fhir-converter by LinuxForHealth.

the class HL7EventTypeFHIRConversionTest method validate_evn_segment_no_period_override.

@Test
void validate_evn_segment_no_period_override() {
    String hl7message = "MSH|^~\\&|||||||ADT^A01^ADT_A01|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6||||||\r" + // + "EVN||||7525||20210319134735|\r"  // TODO, not working with this value
    "EVN||||O||20210319134735|\r" + "PV1|1|I||R|||||||||R|1||||||||||||||||||||||||||||||200603150624|200603150625|||||||";
    String json = ftv.convert(hl7message, OPTIONS);
    assertThat(json).isNotBlank();
    FHIRContext context = new FHIRContext();
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    List<BundleEntryComponent> e = b.getEntry();
    // 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);
    // ENV.4 is used for reasonCode
    List<CodeableConcept> reasonCodes = encounter.getReasonCode();
    assertEquals(1, reasonCodes.size());
    CodeableConcept encounterReason = encounter.getReasonCodeFirstRep();
    Coding encounterReasonCoding = encounterReason.getCodingFirstRep();
    // assertThat(encounterReasonCoding.getCode()).isEqualTo("7525");  // TODO, should be able to use user-defined values
    assertThat(encounterReasonCoding.getCode()).isEqualTo("O");
    // EVN.6 is used for start period if there is no PV1.44 but since we have a
    // PV1.44 it should use that not EVN.6
    Base period = encounter.getNamedProperty("period").getValues().get(0);
    String startPeriod = period.getNamedProperty("start").getValues().get(0).toString();
    // And use PV1.45 for end period.
    String endPeriod = period.getNamedProperty("end").getValues().get(0).toString();
    assertThat(startPeriod).isEqualTo("DateTimeType[2006-03-15T06:24:00+08:00]");
    assertThat(endPeriod).isEqualTo("DateTimeType[2006-03-15T06:25:00+08:00]");
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Base(org.hl7.fhir.r4.model.Base) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) Encounter(org.hl7.fhir.r4.model.Encounter) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)222 ArrayList (java.util.ArrayList)183 FHIRException (org.hl7.fhir.exceptions.FHIRException)107 List (java.util.List)97 DisplayName (org.junit.jupiter.api.DisplayName)96 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)89 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)85 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)70 Identifier (org.hl7.fhir.r4.model.Identifier)69 Test (org.junit.Test)66 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)64 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)54 IOException (java.io.IOException)52 Bundle (org.hl7.fhir.r4.model.Bundle)49 Coding (org.hl7.fhir.r4.model.Coding)49 ValueSet (org.hl7.fhir.r5.model.ValueSet)48 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)46 Resource (org.hl7.fhir.r4.model.Resource)46 BigDecimal (java.math.BigDecimal)45 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)44