use of org.hl7.fhir.dstu2.model.Bundle.BundleEntryComponent 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.dstu2.model.Bundle.BundleEntryComponent 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);
}
}
use of org.hl7.fhir.dstu2.model.Bundle.BundleEntryComponent 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());
}
use of org.hl7.fhir.dstu2.model.Bundle.BundleEntryComponent 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]");
}
use of org.hl7.fhir.dstu2.model.Bundle.BundleEntryComponent in project hl7v2-fhir-converter by LinuxForHealth.
the class HL7EventTypeFHIRConversionTest method validate_evn_segment.
@Test
void validate_evn_segment() {
String hl7message = "MSH|^~\\&|||||||ADT^A01^ADT_A01|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6||||||\r" + // + "EVN||||851||20210319134735|\r" // TODO, not working with this value
"EVN||||O||20210319134735|\r" + "PV1|1|I||R|||||||||R|1||||||||||||||||||||||||||||||||||||||";
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 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("851"); // TODO, should be able to use user-defined values
assertThat(encounterReasonCoding.getCode()).isEqualTo("O");
// EVN.6 is used for start period (with no end) if there is no PV1.44
Base period = encounter.getNamedProperty("period").getValues().get(0);
String startPeriod = period.getNamedProperty("start").getValues().get(0).toString();
int endPeriodSize = period.getNamedProperty("end").getValues().size();
assertThat(startPeriod).isEqualTo("DateTimeType[2021-03-19T13:47:35+08:00]");
assertThat(endPeriodSize).isZero();
}
Aggregations