use of org.hl7.fhir.dstu2.model.Range in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7ObservationFHIRConversionTest method extendedObservationTestForRDEMessages.
// Tests resources created for Observations from RDE messages
@ParameterizedTest
@ValueSource(strings = { "MSH|^~\\&|WHI_LOAD_GENERATOR|IBM_TORONTO_LAB||IBM|20210407191342|25739|RDE^O11|MSGID_f209e83f-20db-474d-a7ae-82e5c3894273|T|2.6\r", "MSH|^~\\&|WHI_LOAD_GENERATOR|IBM_TORONTO_LAB||IBM|20210407191342|25739|RDE^O25|MSGID_f209e83f-20db-474d-a7ae-82e5c3894273|T|2.6\r" })
// 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")
void extendedObservationTestForRDEMessages(String msh) throws IOException {
String hl7message = msh + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + "ORC|RE|||3200|||||20210407191342||2799^BY^VERIFIED||||20210407191342||||||ORDERING FAC NAME||||||||I\r" + "RXE|^Q24H&0600^^20210407191342^^ROU|DEFAULTMED^cefTRIAXone (ROCEPHIN) 2 g in sodium chloride 0.9 % 50 mL IVPB|2||g||||||||\n" + "OBX|1|NM|Most Current Weight^Most current measured weight (actual)||90|kg||IND||||||20210320153850||1111^ClinicianLastName^ClinicianFirstName^^^^Title|Manual^Text the 4th^SNM3|Device_1234567^mySystem|20210322153925|Observation Site^Text 5^SNM3|INST^Instance Identifier System||Radiology^Radiological Services|467 Albany Hospital^^Albany^NY|Cardiology^ContactLastName^Jane^Q^^Dr.^MD\r";
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
assertThat(obsResource).hasSize(1);
Observation obs = (Observation) obsResource.get(0);
// Check the coding (OBX.3)
assertThat(obs.hasCode()).isTrue();
DatatypeUtils.checkCommonCodeableConceptAssertions(obs.getCode(), "Most Current Weight", "Most current measured weight (actual)", null, "Most current measured weight (actual)");
// Check the value (OBX.5)
assertNotNull(obs.getValueQuantity());
Quantity q = obs.getValueQuantity();
// code for unit
assertNull(q.getCode());
// unit units to OBX.6.1
assertEquals("kg", q.getUnit());
// system for unit
assertNull(q.getSystem());
assertEquals(90f, q.getValue().floatValue());
// = is not put in comparator
assertNull(q.getComparator());
// Check that there is no reference range, OBX.6 and OBX.7
assertThat(obs.hasReferenceRange()).isFalse();
// Check interpretation (OBX.8)
assertThat(obs.hasInterpretation()).isTrue();
assertThat(obs.getInterpretation()).hasSize(1);
DatatypeUtils.checkCommonCodeableConceptAssertions(obs.getInterpretationFirstRep(), "IND", "Indeterminate", "http://terminology.hl7.org/CodeSystem/v2-0078", null);
// Check the effective Date Time (OBX.14)
assertThat(obs.hasEffective()).isTrue();
assertThat(obs.hasEffectiveDateTimeType()).isTrue();
assertThat(obs.getEffectiveDateTimeType().asStringValue()).isEqualTo("2021-03-20T15:38:50+08:00");
// Check performer (OBX.16 Practictioner + OBX.23/OBX.24/OBX.25 Organization)
assertThat(obs.hasPerformer()).isTrue();
// Practioner and Organization
assertThat(obs.getPerformer()).hasSize(2);
// Get Practitioner and see that it is populated with OBX.16 information
assertThat(obs.getPerformer().get(0).hasReference()).isTrue();
List<Resource> practitionerResource = e.stream().filter(v -> ResourceType.Practitioner == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(practitionerResource).hasSize(1);
Practitioner doctor = ResourceUtils.getResourcePractitioner(practitionerResource.get(0), ResourceUtils.context);
assertThat(doctor.getName().get(0).getFamily()).isEqualTo("ClinicianLastName");
// Get Organization and see that it is populated with OBX.23/OBX.24/OBX.25 information
assertThat(obs.getPerformer().get(1).hasReference()).isTrue();
List<Resource> organizationResource = e.stream().filter(v -> ResourceType.Organization == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(organizationResource).hasSize(1);
Organization org = ResourceUtils.getResourceOrganization(organizationResource.get(0), ResourceUtils.context);
// from OBX.23
assertThat(org.getName()).isEqualTo("Radiology");
assertThat(org.getAddress().get(0).getLine().get(0).getValueAsString()).isEqualTo(// from OBX.24
"467 Albany Hospital");
// from OBX.24
assertThat(org.getAddress().get(0).getCity()).isEqualTo("Albany");
// from OBX.24
assertThat(org.getAddress().get(0).getState()).isEqualTo("NY");
// from OBX.25
assertThat(org.getContact().get(0).getName().getFamily()).isEqualTo("ContactLastName");
// from OBX.25
assertThat(org.getContact().get(0).getName().getGiven().get(0).getValueAsString()).isEqualTo("Jane");
// There should be no suffix, currently not putting degree 'Title' in suffix
assertThat(org.getContact().get(0).getName().getSuffix()).isEmpty();
// from OBX.25
assertThat(org.getContact().get(0).getName().getText()).isEqualTo("Dr. Jane Q ContactLastName");
// purpose added because of OBX.25
assertThat(org.getContact().get(0).hasPurpose()).isTrue();
DatatypeUtils.checkCommonCodeableConceptAssertions(org.getContact().get(0).getPurpose(), "ADMIN", "Administrative", "http://terminology.hl7.org/CodeSystem/contactentity-type", "Organization Medical Director");
// Check method (OBX.17)
assertThat(obs.hasMethod()).isTrue();
DatatypeUtils.checkCommonCodeableConceptAssertions(obs.getMethod(), "Manual", "Text the 4th", "http://terminology.hl7.org/CodeSystem/SNM3", "Text the 4th");
// Check device (OBX.18)
assertThat(obs.hasDevice()).isTrue();
assertThat(obs.getDevice().hasReference()).isTrue();
List<Resource> deviceResource = e.stream().filter(v -> ResourceType.Device == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(deviceResource).hasSize(1);
Device device = ResourceUtils.getResourceDevice(deviceResource.get(0), ResourceUtils.context);
assertThat(device.getIdentifier().get(0).getValue()).isEqualTo("Device_1234567");
assertThat(device.getIdentifier().get(0).getSystem()).isEqualTo("urn:id:mySystem");
// Check bodySite (OBX.20)
assertThat(obs.hasBodySite()).isTrue();
DatatypeUtils.checkCommonCodeableConceptAssertions(obs.getBodySite(), "Observation Site", "Text 5", "http://terminology.hl7.org/CodeSystem/SNM3", "Text 5");
// Check identifier (OBX.21)
assertThat(obs.hasIdentifier()).isTrue();
assertThat(obs.getIdentifier()).hasSize(2);
assertThat(obs.getIdentifier().get(1).getValue()).isEqualTo("INST");
assertThat(obs.getIdentifier().get(1).getSystem()).isEqualTo("urn:id:Instance_Identifier_System");
// OBX.23/OBX.24/OBX.25 went into Performer: Organization. Checked above.
// Check for ABSENCE of category (because no SPM) Presence of category tested in extendedObservationUnusualRangesAndOtherTest
assertThat(obs.hasCategory()).isFalse();
}
use of org.hl7.fhir.dstu2.model.Range in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7ObservationFHIRConversionTest method extendedObservationUnusualRangesAndOtherTest.
// A companion test to extendedObservationCWEtest that looks for edge cases
@Test
// 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")
void extendedObservationUnusualRangesAndOtherTest() throws IOException {
String ORU_r01 = "MSH|^~\\&|NIST Test Lab APP|NIST Lab Facility||NIST EHR Facility|20150926140551||ORU^R01|NIST-LOI_5.0_1.1-NG|T|2.5.1|||AL|AL|||||\r" + "PID|1||||DOE^JANE||||||||||||\r" + "ORC|NW|ORD448811^NIST EHR|R-511^NIST Lab Filler||||||20120628070100|||5742200012^Radon^Nicholas^^^^^^NPI^L^^^NPI\r" + "OBR|1|ORD448811^NIST EHR|R-511^NIST Lab Filler|1000^Hepatitis A B C Panel^99USL|||20120628070100|||||||||5742200012^Radon^Nicholas^^^^^^NPI^L^^^NPI\r" + "OBX|1|CWE|22314-9^Hepatitis A virus IgM Ab [Presence] in Serum^LN^HAVM^Hepatitis A IgM antibodies (IgM anti-HAV)^L^2.52||260385009^Negative (qualifier value)^SCT^NEG^NEGATIVE^L^201509USEd^^Negative (qualifier value)||Negative|N|||F|||20150925|||||201509261400\r" + "OBX|2|NM|22316-4^Hepatitis B virus core Ab [Units/volume] in Serum^LN^HBcAbQ^Hepatitis B core antibodies (anti-HBVc) Quant^L^2.52||0.70|[IU]/mL^international unit per milliliter^UCUM^IU/ml^^L^1.9|<0.50 IU/mL|H|||F|||20150925|||||201509261400\r" + "SPM|1|SpecimenID||BLOOD^Blood^^87612001^BLOOD^SCT^^||||Cord Art^Blood, Cord Arterial^^^^^^^|||P||||||201110060535|201110060821||Y||||||1\r";
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, ORU_r01);
List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
assertThat(obsResource).hasSize(2);
Observation obs = (Observation) obsResource.get(0);
assertThat(obs.hasReferenceRange()).isTrue();
assertThat(obs.getReferenceRange()).hasSize(1);
ObservationReferenceRangeComponent range = obs.getReferenceRangeFirstRep();
assertThat(range).isNotNull();
assertThat(range.hasHigh()).isFalse();
assertThat(range.hasLow()).isFalse();
assertThat(range.hasText()).isTrue();
assertThat(range.getText()).isEqualTo("Negative");
obs = (Observation) obsResource.get(1);
assertThat(obs.hasValueQuantity()).isTrue();
Quantity q = obs.getValueQuantity();
assertThat(q.hasUnit()).isTrue();
assertThat(q.getUnit()).isEqualTo("[IU]/mL");
assertThat(q.hasValue()).isTrue();
assertThat(q.getValue().floatValue()).isEqualTo(0.7f);
assertThat(q.hasSystem()).isTrue();
assertThat(q.getSystem()).isEqualTo("http://unitsofmeasure.org");
assertThat(obs.hasReferenceRange()).isTrue();
assertThat(obs.getReferenceRange()).hasSize(1);
range = obs.getReferenceRangeFirstRep();
assertThat(range).isNotNull();
assertThat(range.hasHigh()).isTrue();
assertThat(range.hasLow()).isFalse();
Quantity high = range.getHigh();
assertThat(high.getUnit()).isEqualTo("[IU]/mL");
assertThat(high.getValue().floatValue()).isEqualTo(0.5f);
assertThat(range.hasText()).isTrue();
assertThat(range.getText()).isEqualTo("<0.50 IU/mL");
// Because there is an SPM record, there should be a category. (Absence of SPM and category checkedin extendedObservationCWEtest)
assertThat(obs.hasCategory()).isTrue();
assertThat(obs.getCategory()).hasSize(1);
DatatypeUtils.checkCommonCodeableConceptAssertions(obs.getCategoryFirstRep(), "laboratory", "Laboratory", "http://terminology.hl7.org/CodeSystem/observation-category", null);
}
use of org.hl7.fhir.dstu2.model.Range in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7ObservationFHIRConversionTest method testObservationSN_valueQuantity_equals_comparator_result.
/**
* Testing Observation.yml valueQuantity_2 with a comparator that FHIR does not support
*
* Also tests referenceRange and interpretation fields
*
* @throws IOException
*/
@Test
void testObservationSN_valueQuantity_equals_comparator_result() throws IOException {
String hl7message = baseMessage + "OBX|1|SN|24467-3^CD3+CD4+ (T4 helper) cells [#/volume] in Blood^LN||=^440|{Cells}/uL^cells per microliter^UCUM|649-1346 cells/mcL|L|||F";
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
assertThat(obsResource).hasSize(1);
Observation obs = (Observation) obsResource.get(0);
// Check valueQuantity
assertNotNull(obs.getValueQuantity());
Quantity q = obs.getValueQuantity();
// code for unit
assertEquals("{Cells}/uL", q.getCode());
// unit units to OBX.6.1
assertEquals("{Cells}/uL", q.getUnit());
// system for unit
assertEquals("http://unitsofmeasure.org", q.getSystem());
assertEquals(440f, q.getValue().floatValue());
// = is not put in comparator
assertNull(q.getComparator());
// Check referenceRange
assertTrue(obs.hasReferenceRange());
assertThat(obs.getReferenceRange()).hasSize(1);
ObservationReferenceRangeComponent range = obs.getReferenceRangeFirstRep();
assertNotNull(range);
assertTrue(range.hasHigh());
assertTrue(range.hasLow());
Quantity high = range.getHigh();
// uses OBX.6.1 for units not text in string
assertEquals("{Cells}/uL", high.getUnit());
assertEquals(1346f, high.getValue().floatValue());
Quantity low = range.getLow();
// uses OBX.6.1 for units not text in string
assertEquals("{Cells}/uL", low.getUnit());
assertEquals(649f, low.getValue().floatValue());
assertEquals("649-1346 cells/mcL", range.getText());
// Check interpretation (OBX.8)
assertTrue(obs.hasInterpretation());
assertThat(obs.getInterpretation()).hasSize(1);
DatatypeUtils.checkCommonCodeableConceptAssertions(obs.getInterpretation().get(0), "L", "Low", "http://terminology.hl7.org/CodeSystem/v2-0078", null);
}
use of org.hl7.fhir.dstu2.model.Range in project elexis-server by elexis.
the class EncounterResourceProvider method searchReqPatientOptDate.
/**
* Search for all encounters by the patient id. Optional the date range of the returned
* encounters can be specified.
*
* @param thePatientId
* @param dates
* @return
*/
@Search
public List<Encounter> searchReqPatientOptDate(@RequiredParam(name = Encounter.SP_PATIENT) IdType thePatientId, @OptionalParam(name = Encounter.SP_DATE) DateRangeParam dates, @IncludeParam(allow = { "Encounter.diagnosis" }) Set<Include> theIncludes) {
if (thePatientId != null && !thePatientId.isEmpty()) {
Optional<IPatient> patient = coreModelService.load(thePatientId.getIdPart(), IPatient.class);
if (patient.isPresent()) {
if (patient.get().isPatient()) {
// migrate encounters first
migratorService.migratePatientsFindings(thePatientId.getIdPart(), IEncounter.class, null);
List<IEncounter> findings = findingsService.getPatientsFindings(patient.get().getId(), IEncounter.class);
if (findings != null && !findings.isEmpty()) {
List<Encounter> ret = new ArrayList<Encounter>();
for (IEncounter iFinding : findings) {
Optional<Encounter> fhirEncounter = getTransformer().getFhirObject(iFinding);
fhirEncounter.ifPresent(fe -> {
if (dates != null) {
if (!DateRangeParamUtil.isPeriodInRange(fe.getPeriod(), dates)) {
return;
}
}
ret.add(fe);
});
}
return ret;
}
}
}
}
return null;
}
use of org.hl7.fhir.dstu2.model.Range in project quality-measure-and-cohort-service by Alvearie.
the class R4ParameterDefinitionWithDefaultToCohortParameterConverter method toCohortParameter.
public static Parameter toCohortParameter(Extension extension) {
Parameter parameter;
Type extensionValue = extension.getValue();
if (extensionValue instanceof Base64BinaryType) {
parameter = new StringParameter(((Base64BinaryType) extensionValue).asStringValue());
} else if (extensionValue instanceof BooleanType) {
parameter = new BooleanParameter(((BooleanType) extensionValue).booleanValue());
} else if (extensionValue instanceof DateType) {
parameter = new DateParameter(((DateType) extensionValue).asStringValue());
} else if (extensionValue instanceof DateTimeType) {
parameter = convertDateTimeType((DateTimeType) extensionValue);
} else if (extensionValue instanceof DecimalType) {
parameter = new DecimalParameter(((DecimalType) extensionValue).getValueAsString());
} else if (extensionValue instanceof InstantType) {
parameter = new DatetimeParameter(((InstantType) extensionValue).getValueAsString());
} else if (extensionValue instanceof IntegerType) {
parameter = new IntegerParameter(((IntegerType) extensionValue).getValue());
} else if (extensionValue instanceof StringType) {
parameter = new StringParameter(((StringType) extensionValue).getValue());
} else if (extensionValue instanceof TimeType) {
parameter = new TimeParameter(((TimeType) extensionValue).asStringValue());
} else if (extensionValue instanceof UriType) {
parameter = new StringParameter(((UriType) extensionValue).getValue());
} else if (extensionValue instanceof Coding) {
parameter = convertCoding((Coding) extensionValue);
} else if (extensionValue instanceof CodeableConcept) {
parameter = convertCodeableConcept((CodeableConcept) extensionValue);
} else if (extensionValue instanceof Period) {
Period castValue = (Period) extensionValue;
parameter = new IntervalParameter(convertDateTimeType(castValue.getStartElement()), true, convertDateTimeType(castValue.getEndElement()), true);
} else if (extensionValue instanceof Quantity) {
parameter = convertQuantity((Quantity) extensionValue);
} else if (extensionValue instanceof Range) {
Range castValue = (Range) extensionValue;
parameter = new IntervalParameter(convertQuantity(castValue.getLow()), true, convertQuantity(castValue.getHigh()), true);
} else if (extensionValue instanceof Ratio) {
Ratio castValue = (Ratio) extensionValue;
parameter = new RatioParameter().setDenominator(convertQuantity(castValue.getDenominator())).setNumerator(convertQuantity(castValue.getNumerator()));
} else {
throw new UnsupportedFhirTypeException(extensionValue);
}
return parameter;
}
Aggregations