use of org.hl7.fhir.r5.model.Observation in project openmrs-module-fhir2 by openmrs.
the class ObservationSearchQueryTest method searchForObs_shouldSortObsAsRequested.
@Test
public void searchForObs_shouldSortObsAsRequested() {
SortSpec sort = new SortSpec();
sort.setParamName("date");
sort.setOrder(SortOrderEnum.ASC);
SearchParameterMap theParams = new SearchParameterMap();
theParams.setSortSpec(sort);
IBundleProvider results = search(theParams);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(greaterThan(1)));
for (int i = 1; i < resultList.size(); i++) {
assertThat(((Observation) resultList.get(i - 1)).getEffectiveDateTimeType().getValue(), sameOrBefore(((Observation) resultList.get(i)).getEffectiveDateTimeType().getValue()));
}
sort.setOrder(SortOrderEnum.DESC);
theParams.setSortSpec(sort);
results = search(theParams);
resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(greaterThan(1)));
for (int i = 1; i < resultList.size(); i++) {
assertThat(((Observation) resultList.get(i - 1)).getEffectiveDateTimeType().getValue(), sameOrAfter(((Observation) resultList.get(i)).getEffectiveDateTimeType().getValue()));
}
}
use of org.hl7.fhir.r5.model.Observation in project openmrs-module-fhir2 by openmrs.
the class ObservationSearchQueryTest method searchForObs_shouldAddNotNullGroupMembersToReturnedResultsR3.
@Test
public void searchForObs_shouldAddNotNullGroupMembersToReturnedResultsR3() {
TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(OBS_GROUP_UUID));
HashSet<Include> includes = new HashSet<>();
Include include = new Include("Observation:related-type");
includes.add(include);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
IBundleProvider results = search(theParams);
assertThat(results.size(), equalTo(1));
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
// included resource added as part of the result list
assertThat(resultList.size(), equalTo(2));
Observation returnedObservation = (Observation) resultList.iterator().next();
assertThat(resultList, hasItem(allOf(is(instanceOf(Observation.class)), hasProperty("id", equalTo(returnedObservation.getHasMemberFirstRep().getReferenceElement().getIdPart())))));
}
use of org.hl7.fhir.r5.model.Observation in project openmrs-module-fhir2 by openmrs.
the class ObservationSearchQueryTest method searchForObs_shouldSearchForObsByValueDate.
@Test
public void searchForObs_shouldSearchForObsByValueDate() {
SearchParameterMap theParams = new SearchParameterMap();
theParams.addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "valueDatetime", new DateRangeParam(new DateParam(VALUE_DATE)));
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
assertThat(results.size(), equalTo(1));
List<IBaseResource> resultList = get(results);
assertThat(resultList, not(empty()));
assertThat(resultList, hasItem(hasProperty("id", equalTo(OBS_VALUE_CONCEPT_UUID))));
assertThat(((Observation) resultList.get(0)).getIssued().toString(), startsWith(VALUE_DATE));
}
use of org.hl7.fhir.r5.model.Observation in project openmrs-module-fhir2 by openmrs.
the class ObservationSearchQueryTest method searchForObs_shouldSearchByObsDateAndTime.
@Test
public void searchForObs_shouldSearchByObsDateAndTime() {
SearchParameterMap theParams = new SearchParameterMap();
theParams.addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "obsDatetime", new DateRangeParam(new DateParam(OBS_DATE_AND_TIME)));
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
assertThat(results.size(), equalTo(12));
List<IBaseResource> resultList = get(results);
assertThat(resultList, not(empty()));
assertThat(resultList.size(), equalTo(10));
assertThat(resultList, hasItem(hasProperty("id", equalTo(OBS_VALUE_CONCEPT_UUID))));
assertThat(((Observation) resultList.get(0)).getEffectiveDateTimeType().getValue().toString(), equalTo(EXPECTED_OBS_DATE_AND_TIME));
}
use of org.hl7.fhir.r5.model.Observation in project openmrs-module-fhir2 by openmrs.
the class DiagnosticReportTranslatorImplTest method setup.
@Before
public void setup() {
translator = new DiagnosticReportTranslatorImpl();
translator.setObservationReferenceTranslator(observationReferenceTranslator);
translator.setConceptTranslator(conceptTranslator);
translator.setEncounterReferenceTranslator(encounterReferenceTranslator);
translator.setPatientReferenceTranslator(patientReferenceTranslator);
// OpenMRS setup
fhirDiagnosticReport = new FhirDiagnosticReport();
Obs childObs = new Obs();
childObs.setUuid(CHILD_UUID);
fhirDiagnosticReport.setUuid(PARENT_UUID);
fhirDiagnosticReport.getResults().add(childObs);
// FHIR setup
Reference obsReference = new Reference().setType("Observation").setReference("Observation/" + CHILD_UUID);
diagnosticReport = new DiagnosticReport();
diagnosticReport.setId(PARENT_UUID);
diagnosticReport.addResult(obsReference);
// Mocks for DiagnosticReport.result
when(observationReferenceTranslator.toFhirResource(childObs)).thenReturn(obsReference);
when(observationReferenceTranslator.toOpenmrsType(obsReference)).thenReturn(childObs);
}
Aggregations