Search in sources :

Example 46 with Use

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

the class Hl7EncounterFHIRConversionTest method test_encounter_PV1_serviceProvider.

// Test for serviceProvider reference in messages with both PV1 and PV2 segments
// Part 2: Field PV2.23 is provided but no PV2.23.8; serviceProvider id should use backup field PV1.3.4.1
@ParameterizedTest
@ValueSource(strings = { "ADT^A01", /* "ADT^A02", "ADT^A03", "ADT^A04", */
"ADT^A08", // MDM messages are not tested here because they do not have PV2 segments
"OMP^O09", "ORU^R01", "RDE^O11", "RDE^O25", "VXU^V04" })
void test_encounter_PV1_serviceProvider(String message) {
    String hl7message = "MSH|^~\\&|TestSystem||TestTransformationAgent||20150502090000||" + message + "|controlID|P|2.6\r" + "EVN||20210330144208||ADT_EVENT|007|20210309140700\r" + "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\r" + "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\r" + "PV2||TEL||||X-5546||20210330144208|20210309||||||||||||n|N|South Shore Hosptial Weymouth|||||||||N||||||\r";
    String json = ftv.convert(hl7message, OPTIONS);
    assertThat(json).isNotBlank();
    LOGGER.debug("FHIR json result:\n" + json);
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    List<BundleEntryComponent> e = b.getEntry();
    List<Resource> encounterResource = ResourceUtils.getResourceList(e, ResourceType.Encounter);
    assertThat(encounterResource).hasSize(1);
    Encounter encounter = ResourceUtils.getResourceEncounter(encounterResource.get(0), context);
    Reference serviceProvider = encounter.getServiceProvider();
    assertThat(serviceProvider).isNotNull();
    String providerString = serviceProvider.getReference();
    assertThat(providerString).isEqualTo("Organization/toronto");
    List<Resource> organizations = ResourceUtils.getResourceList(e, ResourceType.Organization);
    assertThat(organizations).hasSize(1);
    Organization orgResource = ResourceUtils.getResourceOrganization(organizations.get(0), context);
    assertThat(orgResource.getId()).isEqualTo(providerString);
    assertThat(orgResource.getName()).isEqualTo("South Shore Hosptial Weymouth");
    assertThat(orgResource.getIdentifier()).hasSize(1);
    // PV1.3.4.1
    assertThat(orgResource.getIdentifierFirstRep().getValue()).hasToString("Toronto");
    // Because ID is name based
    assertThat(orgResource.getIdentifierFirstRep().getSystem()).hasToString("urn:id:extID");
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Organization(org.hl7.fhir.r4.model.Organization) Bundle(org.hl7.fhir.r4.model.Bundle) Reference(org.hl7.fhir.r4.model.Reference) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) Encounter(org.hl7.fhir.r4.model.Encounter) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 47 with Use

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

the class Hl7FinancialInsuranceTest method testBasicInsuranceCoverageFields.

// 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")
@Test
void testBasicInsuranceCoverageFields() throws IOException {
    // Tests fields listed below.
    String hl7message = "MSH|^~\\&|||||20151008111200||DFT^P03^DFT_P03|MSGID000001|T|2.6|||||||||\n" + "EVN||20210407191342||||||\n" + "PID|||MR1^^^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.3.8 to Organization Identifier.period.end
    "|IdValue1^^^IdSystem4^IdType5^^20201231145045^20211231145045" + // IN1.4 to Organization Name
    "|Large Blue Organization" + // IN1.5 to Organization Address (All XAD standard fields)
    "|456 Ultramarine Lane^^Faketown^CA^ZIP5" + // IN1.6.13 to Organization Contact Name .period.end
    "|LastFake^FirstFake^MiddleFake^III^Dr.^^L^^^^^20201231145045^20211231145045" + // IN1.7.18 to Organization Contact telecom .rank
    "|^WPN^^^^333^4444444^^^^^^20201231145045^20211231145045^^^^1" + // IN1.9.1 (2) to list element Coverage.class.name and value (because IN1.9.10 (2) does not exist)
    "|UA34567|NameBlue^^^^^^^^^IDBlue~NameGreen||" + // IN1.35 to Organization.identifier
    "|20201231145045|20211231145045|||||||||5|||||||||||||COMPANYPLANCODE35" + // IN1.49 has value to show that it is not used for Patient.identifier because NO relationship (IN1.17/IN2.72 empty)
    "|MEMBER36||||||||||Value46|||PatientId49.1||||\n" + // IN2.61 is purposely empty (primary to IN1.36) so IN1.36 will be used as the MB Coverage.identifier
    "IN2|||||||||||||||||||||||||IdValue25.1^^^IdSystem25.4^IdType25.5^^20201231145045^20211231145045|||||||||||||||||||||||||||||||||||||||||||" + // IN2.72 is purposely empty (backup to IN1.17) so no RelatedPerson is created.
    "|Name69.1^^^^^IdSystem69.6^UNK^^^IdValue69.10||\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();
    // From PID.3
    assertThat(patient.getIdentifier()).hasSize(1);
    Identifier patientIdentifier = patient.getIdentifier().get(0);
    // PID.3.1
    assertThat(patientIdentifier.getValue()).isEqualTo("MR1");
    // PID.3.4
    assertThat(patientIdentifier.getSystem()).isEqualTo("urn:id:XYZ");
    DatatypeUtils.checkCommonCodeableConceptAssertions(patientIdentifier.getType(), "MR", "Medical record number", "http://terminology.hl7.org/CodeSystem/v2-0203", // PID.3.5
    null);
    // IN1.49 not used
    List<Resource> organizations = ResourceUtils.getResourceList(e, ResourceType.Organization);
    // From IN1.3 creates Payor, IN2.25 to new PayorId Organization, IN2.69 creates new PolicyHolder Organization Name
    assertThat(organizations).hasSize(3);
    Organization org = (Organization) organizations.get(0);
    // Check Payor Organization Id's
    String payorOrgId = org.getId();
    // IN1.17.1 (no TENANT)  (Id's lowercased)
    assertThat(payorOrgId).isEqualTo("Organization/idvalue1");
    // IN1.4
    assertThat(org.getName()).isEqualTo("Large Blue Organization");
    assertThat(org.getIdentifier()).hasSize(2);
    Identifier orgIdentifier = org.getIdentifier().get(0);
    // IN1.3.1
    assertThat(orgIdentifier.getValue()).isEqualTo("IdValue1");
    // IN1.3.4
    assertThat(orgIdentifier.getSystem()).isEqualTo("urn:id:IdSystem4");
    // IN1.3.7
    assertThat(orgIdentifier.getPeriod().getStartElement().toString()).containsPattern("2020-12-31T14:50:45");
    // IN1.3.8
    assertThat(orgIdentifier.getPeriod().getEndElement().toString()).containsPattern("2021-12-31T14:50:45");
    // IN1.3.5
    DatatypeUtils.checkCommonCodeableConceptAssertions(orgIdentifier.getType(), "IdType5", null, null, null);
    Identifier orgIdentifier1 = org.getIdentifier().get(1);
    // IN1.35
    assertThat(orgIdentifier1.getValue()).isEqualTo("COMPANYPLANCODE35");
    // Check Payor Organization address. IN1.4 is a standard XAD address, which is tested exhaustively in other tests.
    assertThat(org.getAddress()).hasSize(1);
    assertThat(org.getAddress().get(0).getLine().get(0).getValueAsString()).isEqualTo(// IN1.4.1
    "456 Ultramarine Lane");
    // IN1.4.3
    assertThat(org.getAddress().get(0).getCity()).isEqualTo("Faketown");
    // IN1.4.4
    assertThat(org.getAddress().get(0).getState()).isEqualTo("CA");
    // IN1.4.5
    assertThat(org.getAddress().get(0).getPostalCode()).isEqualTo("ZIP5");
    // Check Payor Organization contact name.  IN1.6 name is standard XPN, tested exhaustively in other tests.
    HumanName contactName = org.getContact().get(0).getName();
    assertThat(org.getContact()).hasSize(1);
    // IN1.6.1
    assertThat(contactName.getFamily()).isEqualTo("LastFake");
    // IN1.6.2
    assertThat(contactName.getGiven().get(0).getValueAsString()).isEqualTo("FirstFake");
    // IN1.6.3
    assertThat(contactName.getGiven().get(1).getValueAsString()).isEqualTo("MiddleFake");
    // IN1.6.6
    assertThat(contactName.getPrefixAsSingleString()).hasToString("Dr.");
    // IN1.6.5
    assertThat(contactName.getSuffixAsSingleString()).hasToString("III");
    // from IN1.6 aggregate
    assertThat(contactName.getText()).isEqualTo("Dr. FirstFake MiddleFake LastFake III");
    // IN1.6.7
    assertThat(contactName.getUseElement().getCode()).hasToString("official");
    // IN1.6.12
    assertThat(contactName.getPeriod().getStartElement().toString()).containsPattern("2020-12-31T14:50:45");
    // IN1.6.13
    assertThat(contactName.getPeriod().getEndElement().toString()).containsPattern("2021-12-31T14:50:45");
    // Check there is no purpose. Don't need one, here.
    assertThat(org.getContact().get(0).hasPurpose()).isFalse();
    // Check Payor Organization contact telecom.  IN1.7 is standard XTN, tested exhaustively in other tests.
    assertThat(org.getContact().get(0).getTelecom()).hasSize(1);
    // telecom is type ContactPoint
    ContactPoint contactPoint = org.getContact().get(0).getTelecomFirstRep();
    // default type hardcoded.
    assertThat(contactPoint.getSystemElement().getCode()).hasToString("phone");
    // IN1.7.2 is not mapped (ignored)
    assertThat(contactPoint.hasUseElement()).isFalse();
    // IN1.7.6, IN1.7.7 via getFormattedTelecomNumberValue
    assertThat(contactPoint.getValue()).hasToString("(333) 444 4444");
    // IN1.7.13
    assertThat(contactPoint.getPeriod().getStartElement().toString()).containsPattern("2020-12-31T14:50:45");
    // IN1.7.14
    assertThat(contactPoint.getPeriod().getEndElement().toString()).containsPattern("2021-12-31T14:50:45");
    // IN1.7.18
    assertThat(contactPoint.getRank()).isEqualTo(1);
    // Check PayorId Organization from IN2.25
    org = (Organization) organizations.get(1);
    String payorOrgIdIn25 = org.getId();
    // IN1.25.1 (no TENANT) (Id's lowercased)
    assertThat(payorOrgIdIn25).isEqualTo("Organization/idvalue25.1");
    // IN2.25.1
    assertThat(org.getName()).isEqualTo("IdValue25.1");
    assertThat(org.getIdentifier()).hasSize(1);
    orgIdentifier = org.getIdentifier().get(0);
    // IN2.25.1
    assertThat(orgIdentifier.getValue()).isEqualTo("IdValue25.1");
    // IN2.25.4
    assertThat(orgIdentifier.getSystem()).isEqualTo("urn:id:IdSystem25.4");
    // IN2.25.7
    assertThat(orgIdentifier.getPeriod().getStartElement().toString()).containsPattern("2020-12-31T14:50:45");
    // IN2.25.8
    assertThat(orgIdentifier.getPeriod().getEndElement().toString()).containsPattern("2021-12-31T14:50:45");
    // IN2.25.5
    DatatypeUtils.checkCommonCodeableConceptAssertions(orgIdentifier.getType(), "IdType25.5", null, null, null);
    // Check PolicyHolder Organization Name and ID Organization from IN2.69
    org = (Organization) organizations.get(2);
    String policyHolderOrgId = org.getId();
    // IN2.69.1 (no TENANT) (Id's lowercased)
    assertThat(policyHolderOrgId).isEqualTo("Organization/idvalue69.10");
    // IN2.69.1
    assertThat(org.getName()).isEqualTo("Name69.1");
    assertThat(org.getIdentifier()).hasSize(1);
    orgIdentifier = org.getIdentifier().get(0);
    // IN2.69.10
    assertThat(orgIdentifier.getValue()).isEqualTo("IdValue69.10");
    // IN2.69.6
    assertThat(orgIdentifier.getSystem()).isEqualTo("urn:id:IdSystem69.6");
    // Becuase the code is unknown, the 0203 table lookup fails, and the coding has just the code, no system
    // IN2.69.7
    DatatypeUtils.checkCommonCodeableConceptAssertions(orgIdentifier.getType(), "UNK", null, null, null);
    List<Resource> coverages = ResourceUtils.getResourceList(e, ResourceType.Coverage);
    // From IN1 segment
    assertThat(coverages).hasSize(1);
    Coverage coverage = (Coverage) coverages.get(0);
    // Confirm Coverage Identifiers - Order matches order of identifier_X in Coverage.yml
    // XV, XV, XV, MB, SN; but not MA (IN2.8) nor MC (IN2.6)
    assertThat(coverage.getIdentifier()).hasSize(5);
    // IN1.2.1
    assertThat(coverage.getIdentifier().get(0).getValue()).isEqualTo("Value1");
    // IN1.2.3
    assertThat(coverage.getIdentifier().get(0).getSystem()).isEqualTo("urn:id:System3");
    // No use, here
    assertThat(coverage.getIdentifier().get(0).getUse()).isNull();
    DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(0).getType(), "XV", "Health Plan Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // IN1.2.4
    assertThat(coverage.getIdentifier().get(1).getValue()).isEqualTo("Value4");
    // IN1.2.6
    assertThat(coverage.getIdentifier().get(1).getSystem()).isEqualTo("urn:id:System6");
    // No use, here
    assertThat(coverage.getIdentifier().get(1).getUse()).isNull();
    DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(1).getType(), "XV", "Health Plan Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // IN1.46
    assertThat(coverage.getIdentifier().get(2).getValue()).isEqualTo("Value46");
    // No system, here
    assertThat(coverage.getIdentifier().get(2).getSystem()).isNull();
    // Use is enumeration "old"
    assertThat(coverage.getIdentifier().get(2).getUseElement().getCode()).hasToString("old");
    DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(2).getType(), "XV", "Health Plan Identifier", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // IN1.36
    assertThat(coverage.getIdentifier().get(3).getValue()).isEqualTo("MEMBER36");
    // No system, here
    assertThat(coverage.getIdentifier().get(3).getSystem()).isNull();
    // No use, here
    assertThat(coverage.getIdentifier().get(3).getUse()).isNull();
    DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(3).getType(), "MB", "Member Number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // IN1.36
    assertThat(coverage.getIdentifier().get(4).getValue()).isEqualTo("MEMBER36");
    // No system, here
    assertThat(coverage.getIdentifier().get(4).getSystem()).isNull();
    // No use, here
    assertThat(coverage.getIdentifier().get(4).getUse()).isNull();
    DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getIdentifier().get(4).getType(), "SN", "Subscriber Number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // Confirm SubscriberId
    // IN1.36
    assertThat(coverage.getSubscriberId()).isEqualTo("MEMBER36");
    // Confirm coverage.Order
    // IN1.22 takes priority over IN1.1
    assertThat(coverage.getOrder()).isEqualTo(5);
    // Confirm Coverage Beneficiary references to Patient, and Payor references correct Organizations
    assertThat(coverage.getBeneficiary().getReference()).isEqualTo(patientId);
    // One for each payorOrganization
    assertThat(coverage.getPayor()).hasSize(2);
    assertThat(coverage.getPayor().get(0).getReference()).isEqualTo(payorOrgId);
    assertThat(coverage.getPayor().get(1).getReference()).isEqualTo(payorOrgIdIn25);
    // Confirm policyHolder references correct organization
    assertThat(coverage.getPolicyHolder().getReference()).isEqualTo(policyHolderOrgId);
    // Only one Coverage Class expected.  (getClass_ is correct name for method)
    assertThat(coverage.getClass_()).hasSize(3);
    // IN1.8  Only has value
    checkCoverageClassExistsWithCorrectValueAndName(coverage.getClass_(), "UA34567", null);
    // IN1.9 (1)
    checkCoverageClassExistsWithCorrectValueAndName(coverage.getClass_(), "IDBlue", "NameBlue");
    // IN1.9 (2) Name is also used for value
    checkCoverageClassExistsWithCorrectValueAndName(coverage.getClass_(), "NameGreen", "NameGreen");
    // Confirm Coverage period
    // IN1.12
    assertThat(coverage.getPeriod().getStartElement().toString()).containsPattern("2020-12-31T14:50:45");
    // IN1.13
    assertThat(coverage.getPeriod().getEndElement().toString()).containsPattern("2021-12-31T14:50:45");
    // Expect no RelatedPerson because IN1.17 was empty
    List<Resource> relatedPersons = ResourceUtils.getResourceList(e, ResourceType.RelatedPerson);
    // IN1.17 empty
    assertThat(relatedPersons).isEmpty();
    // Confirm there are no unaccounted for resources
    // Expected: Coverage, Organization (3x), Patient, Encounter
    assertThat(e).hasSize(6);
}
Also used : HumanName(org.hl7.fhir.r4.model.HumanName) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Identifier(org.hl7.fhir.r4.model.Identifier) 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 48 with Use

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

the class Hl7DocumentReferenceFHIRConversionTest method doc_ref_has_all_fields_in_yaml.

// Note: All tests for MDM_T02 and MDM_T06 are the same. Use parameters.
@ParameterizedTest
@ValueSource(strings = { "MDM^T02", "MDM^T06" })
void doc_ref_has_all_fields_in_yaml(String segment) {
    // every field covered in the yaml should be listed here
    String documentReference = "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|OP|TEXT|20180117144200|5566^PAPLast^PAPFirst^J^^MD|20180117144200|201801180346||<PHYSID>|<PHYSID>|MODL|<MESSAGEID>|4466^TRANSCLast^TRANSCFirst^J||<MESSAGEID>|This segment is for description|PA|R|AV|||||\n" + "OBX|1|SN|||||||||X";
    DocumentReference report = ResourceUtils.getDocumentReference(ftv, documentReference);
    assertThat(report.hasAuthenticator()).isTrue();
    assertThat(report.hasAuthor()).isTrue();
    assertThat(report.hasContent()).isTrue();
    assertThat(report.hasContext()).isTrue();
    assertThat(report.hasDate()).isTrue();
    assertThat(report.hasDescription()).isTrue();
    assertThat(report.hasDocStatus()).isTrue();
    assertThat(report.hasId()).isTrue();
    assertThat(report.hasIdentifier()).isTrue();
    assertThat(report.hasMasterIdentifier()).isTrue();
    assertThat(report.hasSecurityLabel()).isTrue();
    assertThat(report.hasStatus()).isTrue();
    assertThat(report.hasSubject()).isTrue();
    assertThat(report.hasType()).isTrue();
}
Also used : DocumentReference(org.hl7.fhir.r4.model.DocumentReference) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 49 with Use

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

the class Hl7EncounterFHIRConversionTest method test_encounter_with_serviceProvider_from_PV1_3_4.

// Test for serviceProvider reference in messages with PV1 segment and no PV2 segment
// Use serviceProvider from PV1-3.4.1
@ParameterizedTest
@ValueSource(strings = { "ADT^A01", /* "ADT^A02", "ADT^A03", "ADT^A04", */
"ADT^A08", // MDM messages are not tested here because they do not have PV2 segments
"OMP^O09", "ORU^R01", "RDE^O11", "RDE^O25", "VXU^V04" })
void test_encounter_with_serviceProvider_from_PV1_3_4(String message) {
    String hl7message = "MSH|^~\\&|TestSystem||TestTransformationAgent||20150502090000||" + message + "|controlID|P|2.6\r" + "EVN|A01|20150502090000|\r" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\r" + // PV1-3.4 used for serviceProvider reference; used for both id and name
    "PV1||I|INT^0001^02^Toronto East|||||||SUR||||||||S|VisitNumber^^^Toronto North|A|||||||||||||||||||Toronto West||||||\r";
    String json = ftv.convert(hl7message, OPTIONS);
    assertThat(json).isNotBlank();
    LOGGER.debug("FHIR json result:\n" + json);
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    List<BundleEntryComponent> e = b.getEntry();
    List<Resource> encounterResource = ResourceUtils.getResourceList(e, ResourceType.Encounter);
    assertThat(encounterResource).hasSize(1);
    Encounter encounter = ResourceUtils.getResourceEncounter(encounterResource.get(0), context);
    Reference serviceProvider = encounter.getServiceProvider();
    assertThat(serviceProvider).isNotNull();
    String providerString = serviceProvider.getReference();
    // Also verify underscore replacement for VALID_ID
    assertThat(providerString).isEqualTo("Organization/toronto-east");
    List<Resource> organizations = ResourceUtils.getResourceList(e, ResourceType.Organization);
    assertThat(organizations).hasSize(1);
    Organization orgResource = ResourceUtils.getResourceOrganization(organizations.get(0), context);
    assertThat(orgResource.getId()).isEqualTo(providerString);
    // PV1.3.4.1
    assertThat(orgResource.getName()).isEqualTo("Toronto East");
    assertThat(orgResource.getIdentifier()).hasSize(1);
    // PV1.3.4.1
    assertThat(orgResource.getIdentifierFirstRep().getValue()).hasToString("Toronto East");
    // Because ID is name based
    assertThat(orgResource.getIdentifierFirstRep().getSystem()).hasToString("urn:id:extID");
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Organization(org.hl7.fhir.r4.model.Organization) Bundle(org.hl7.fhir.r4.model.Bundle) Reference(org.hl7.fhir.r4.model.Reference) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) Encounter(org.hl7.fhir.r4.model.Encounter) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 50 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use 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)

Aggregations

ArrayList (java.util.ArrayList)82 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)43 List (java.util.List)41 FHIRException (org.hl7.fhir.exceptions.FHIRException)40 Date (java.util.Date)39 IOException (java.io.IOException)38 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)35 Test (org.junit.jupiter.api.Test)35 Resource (org.hl7.fhir.r4.model.Resource)34 Collectors (java.util.stream.Collectors)29 Coding (org.hl7.fhir.r4.model.Coding)27 Reference (org.hl7.fhir.r4.model.Reference)27 Timer (com.codahale.metrics.Timer)26 HashMap (java.util.HashMap)25 Bundle (org.hl7.fhir.r4.model.Bundle)25 Reference (org.hl7.fhir.dstu3.model.Reference)24 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)23 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)21 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)21 JsonObject (com.google.gson.JsonObject)20