use of org.hl7.fhir.r4.model.Reference in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7EncounterFHIRConversionTest method test_encounter_PV2_serviceProvider_idfix.
@Test
void test_encounter_PV2_serviceProvider_idfix() {
String hl7message = "MSH|^~\\&|WHI_LOAD_GENERATOR|IBM_TORONTO_LAB||IBM|20210330144208|8078780|ADT^A01|MSGID_4e1c575f-6c6d-47b2-ab9f-829f20c96db2|T|2.3\n" + "EVN||20210330144208||ADT_EVENT|007|20210309140700\n" + "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\n" + "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\n" + "PV2||TEL||||X-5546||20210330144208|20210309||||||||||||n|N|South Shore Hosptial Weymouth^SSHW^^^^^^SSH*WEYMOUTH WEST_BUILD-7.F|||||||||N||||||\n";
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/ssh-weymouth-west-build-7.f");
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);
// PV2.23.1
assertThat(orgResource.getIdentifierFirstRep().getValue()).hasToString("SSH*WEYMOUTH WEST_BUILD-7.F");
// Because ID is name based
assertThat(orgResource.getIdentifierFirstRep().getSystem()).hasToString("urn:id:extID");
}
use of org.hl7.fhir.r4.model.Reference 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");
}
use of org.hl7.fhir.r4.model.Reference 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");
}
use of org.hl7.fhir.r4.model.Reference 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");
}
use of org.hl7.fhir.r4.model.Reference 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);
}
}
Aggregations