use of org.hl7.fhir.r5.model.Patient 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);
}
use of org.hl7.fhir.r5.model.Patient in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7FinancialInsuranceTest method testInsuranceCoverageFromIN2.
@Test
// Tests empty IN2.63 missing telecom.
void testInsuranceCoverageFromIN2() throws IOException {
String hl7message = "MSH|^~\\&|||||20151008111200||ADT^A01^ADT_A01|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.5 to 15 NOT REFERENCED (See test testBasicInsuranceCoverageFields)
"|IdValue1^^^IdSystem4^^^^|Large Blue Organization|||||||||||" + // IN1.18 through IN1.35 NOT REFERENCED
"|DoeFake^Judy^^^Rev.|||||||||||||||||||" + // IN1.37 through IN1.53 NOT REFERENCED
"|MEMBER36|||||||||||||||||\n" + // IN2.63 purposely empty to ensure an empty telecom is not created.
"IN2||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" + // IN2.72 to Coverage.relationship and RelatedPerson.relationship. (Backup for IN1.17) Codes from table 0344
"04|\n";
// 04 = Natural child
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();
List<Resource> organizations = ResourceUtils.getResourceList(e, ResourceType.Organization);
// From Payor created by IN1
assertThat(organizations).hasSize(1);
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
// 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 one RelatedPerson
List<Resource> relatedPersons = ResourceUtils.getResourceList(e, ResourceType.RelatedPerson);
// From IN2.72
assertThat(relatedPersons).hasSize(1);
RelatedPerson related = (RelatedPerson) relatedPersons.get(0);
// Because IN2.63 is empty
assertThat(related.hasTelecom()).isFalse();
assertThat(related.getName()).hasSize(1);
HumanName relatedName = related.getName().get(0);
// Simplified name test. Deeper tests in other tests.
// from IN1.16 aggregate
assertThat(relatedName.getText()).isEqualTo("Rev. Judy DoeFake");
// Check coverage relationship
DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getRelationship(), "child", "Child", "http://terminology.hl7.org/CodeSystem/subscriber-relationship", // IN2.72 (04 = Natural child)
null);
// Check relatedPerson relationship
assertThat(related.getRelationship()).hasSize(1);
DatatypeUtils.checkCommonCodeableConceptAssertions(related.getRelationship().get(0), "PRN", "parent", "http://terminology.hl7.org/CodeSystem/v3-RoleCode", // IN2.72 (04 = Natural child)
null);
// Confirm the Coverage (subscriber) references the RelatedPerson
assertThat(coverage.getSubscriber().getReference()).isEqualTo(related.getId());
// Confirm the RelatedPerson references the Patient
assertThat(related.getPatient().getReference()).isEqualTo(patientId);
// Confirm there are no unaccounted for resources
// Expected: Coverage, Organization, Patient, Encounter, RelatedPerson
assertThat(e).hasSize(5);
}
use of org.hl7.fhir.r5.model.Patient in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7AddressFHIRConversionTest method patient_address_date_ranges_test.
@Test
void patient_address_date_ranges_test() {
String patientAddress = "MSH|^~\\&|MIICEHRApplication|MIIC|MIIC|MIIC|201705130822||VXU^V04^VXU_V04|test1100|P|2.5.1|||AL|AL|||||Z22^CDCPHINVS|^^^^^MIIC^SR^^^MIIC|MIIC\n" + "PID|1||12345678^^^^MR|ALTID|Moose^Mickey^J^III^^^|Mother^Micky|20060504|M|Alias^Alias|2106-3^White^ HL70005|111 1st Street^Suite #1^Minneapolis^MN^11111^USA^H^^AdrC^^^20010101&20081231^^^^Y^Z^V^c/o Pluto19|PatC|^PRN^^^PH^555^5555555|^PRN^^^PH^555^666666|english|married|bhuddist|1234567_account|111-22-3333|||2186-5^not Hispanic or Latino^CDCREC|Born in USA|||USA||||\n";
String patientAddressExplicitEffectiveExpirationDates = "MSH|^~\\&|MIICEHRApplication|MIIC|MIIC|MIIC|201705130822||VXU^V04^VXU_V04|test1100|P|2.5.1|||AL|AL|||||Z22^CDCPHINVS|^^^^^MIIC^SR^^^MIIC|MIIC\n" + "PID|1||12345678^^^^MR|ALTID|Moose^Mickey^J^III^^^|Mother^Micky|20060504|M|Alias^Alias|2106-3^White^ HL70005|111 1st Street^Suite #1^Minneapolis^MN^11111^USA^H^^AdrC^^^20010101&20081231^19920101^19981231^^Y^Z^V^c/o Pluto19|PatC|^PRN^^^PH^555^5555555|^PRN^^^PH^555^666666|english|married|bhuddist|1234567_account|111-22-3333|||2186-5^not Hispanic or Latino^CDCREC|Born in USA|||USA||||\n";
// If address county, ignore patient county
Patient patient = PatientUtils.createPatientFromHl7Segment(ftv, patientAddress);
assertThat(patient.hasAddress()).isTrue();
List<Address> addresses = patient.getAddress();
assertThat(addresses.size()).isEqualTo(1);
Address address = addresses.get(0);
// Test date range
Period period = address.getPeriod();
assertThat(period.hasStart()).isTrue();
assertThat(period.hasEnd()).isTrue();
Date startDate = period.getStart();
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(startDate);
assertThat(startCalendar.get(Calendar.YEAR)).isEqualTo(2001);
// Zero based; January is 0
assertThat(startCalendar.get(Calendar.MONTH)).isZero();
assertThat(startCalendar.get(Calendar.DAY_OF_MONTH)).isEqualTo(1);
Date endDate = period.getEnd();
Calendar endCalendar = Calendar.getInstance();
endCalendar.setTime(endDate);
assertThat(endCalendar.get(Calendar.YEAR)).isEqualTo(2008);
// Zero based; December is 11
assertThat(endCalendar.get(Calendar.MONTH)).isEqualTo(11);
assertThat(endCalendar.get(Calendar.DAY_OF_MONTH)).isEqualTo(31);
// Test explicit date start (effective) and end (expiration)
patient = PatientUtils.createPatientFromHl7Segment(ftv, patientAddressExplicitEffectiveExpirationDates);
assertThat(patient.hasAddress()).isTrue();
addresses = patient.getAddress();
assertThat(addresses.size()).isEqualTo(1);
address = addresses.get(0);
period = address.getPeriod();
assertThat(period.hasStart()).isTrue();
assertThat(period.hasEnd()).isTrue();
startDate = period.getStart();
startCalendar = Calendar.getInstance();
startCalendar.setTime(startDate);
assertThat(startCalendar.get(Calendar.YEAR)).isEqualTo(1992);
// Zero based; January is 0
assertThat(startCalendar.get(Calendar.MONTH)).isZero();
assertThat(startCalendar.get(Calendar.DAY_OF_MONTH)).isEqualTo(1);
endDate = period.getEnd();
endCalendar = Calendar.getInstance();
endCalendar.setTime(endDate);
assertThat(endCalendar.get(Calendar.YEAR)).isEqualTo(1998);
// Zero based; December is 11
assertThat(endCalendar.get(Calendar.MONTH)).isEqualTo(11);
assertThat(endCalendar.get(Calendar.DAY_OF_MONTH)).isEqualTo(31);
}
use of org.hl7.fhir.r5.model.Patient in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7DocumentReferenceFHIRConversionTest method doc_ref_subject_test.
@ParameterizedTest
@ValueSource(strings = { "MDM^T02", "MDM^T06" })
void doc_ref_subject_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||||201801180346||<PHYSID1>||||||||||AV|||<PHYSID2>||\n" + "OBX|1|SN|||||||||X";
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, documentReferenceMessage);
List<Resource> documentReferenceList = ResourceUtils.getResourceList(e, ResourceType.DocumentReference);
String s = context.getParser().encodeResourceToString(documentReferenceList.get(0));
Class<? extends IBaseResource> klass = DocumentReference.class;
DocumentReference documentReference = (DocumentReference) context.getParser().parseResource(klass, s);
assertThat(documentReference.hasSubject()).isTrue();
assertThat(documentReference.getSubject().getReference()).startsWith("Patient");
}
use of org.hl7.fhir.r5.model.Patient 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");
}
Aggregations