use of org.hl7.fhir.r4.model.Encounter in project openmrs-module-fhir2 by openmrs.
the class FhirMedicationRequestServiceImplTest method searchForMedicationRequest_shouldReturnCollectionOfMedicationRequestByEncounter.
@Test
public void searchForMedicationRequest_shouldReturnCollectionOfMedicationRequestByEncounter() {
ReferenceAndListParam encounter = new ReferenceAndListParam();
encounter.addValue(new ReferenceOrListParam().add(new ReferenceParam().setValue("jdjdj-kdkdkkd-kddd").setChain(Encounter.SP_IDENTIFIER)));
List<DrugOrder> drugOrders = new ArrayList<>();
drugOrders.add(drugOrder);
medicationRequest.setId(MEDICATION_REQUEST_UUID);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER, encounter);
when(dao.getSearchResults(any(), any())).thenReturn(drugOrders);
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(MEDICATION_REQUEST_UUID));
when(medicationRequestTranslator.toFhirResource(drugOrder)).thenReturn(medicationRequest);
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, medicationRequestTranslator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
IBundleProvider results = medicationRequestService.searchForMedicationRequests(null, encounter, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, Matchers.notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
use of org.hl7.fhir.r4.model.Encounter in project openmrs-module-fhir2 by openmrs.
the class ServiceRequestSearchQueryTest method searchForServiceRequests_shouldReturnServiceRequestsByMultipleEncountersOr.
@Test
public void searchForServiceRequests_shouldReturnServiceRequestsByMultipleEncountersOr() {
ReferenceAndListParam encounterReference = new ReferenceAndListParam().addAnd(new ReferenceOrListParam().add(new ReferenceParam().setValue(ENCOUNTER_UUID)).add(new ReferenceParam().setValue(ENCOUNTER_UUID_TWO)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER, encounterReference);
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
assertThat(results.size(), equalTo(4));
List<ServiceRequest> resources = get(results);
assertThat(resources, not(empty()));
assertThat(resources, hasSize(equalTo(4)));
assertThat(resources, everyItem(anyOf(hasProperty("encounter", hasProperty("referenceElement", hasProperty("idPart", equalTo(ENCOUNTER_UUID)))), hasProperty("encounter", hasProperty("referenceElement", hasProperty("idPart", equalTo(ENCOUNTER_UUID_TWO)))))));
}
use of org.hl7.fhir.r4.model.Encounter in project openmrs-module-fhir2 by openmrs.
the class ServiceRequestSearchQueryTest method searchForServiceRequests_shouldReturnServiceRequestsByEncounter.
@Test
public void searchForServiceRequests_shouldReturnServiceRequestsByEncounter() {
ReferenceAndListParam encounterReference = new ReferenceAndListParam().addAnd(new ReferenceOrListParam().add(new ReferenceParam().setValue(ENCOUNTER_UUID)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER, encounterReference);
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
assertThat(results.size(), equalTo(4));
List<ServiceRequest> resources = get(results);
assertThat(resources, not(empty()));
assertThat(resources, hasSize(equalTo(4)));
assertThat(resources, everyItem(hasProperty("encounter", hasProperty("referenceElement", hasProperty("idPart", equalTo(ENCOUNTER_UUID))))));
}
use of org.hl7.fhir.r4.model.Encounter in project openmrs-module-fhir2 by openmrs.
the class VisitSearchQueryTest method shouldReturnCollectionOfEncountersSortedByEncounterDate.
@Test
public void shouldReturnCollectionOfEncountersSortedByEncounterDate() {
SortSpec sort = new SortSpec();
sort.setParamName("date");
sort.setOrder(SortOrderEnum.ASC);
SearchParameterMap theParams = new SearchParameterMap().setSortSpec(sort);
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
assertThat(results.size(), greaterThan(1));
List<Encounter> resultList = get(results).stream().filter(it -> it instanceof Encounter).map(it -> (Encounter) it).collect(Collectors.toList());
assertThat(resultList, hasSize(greaterThan(1)));
for (int i = 1; i < resultList.size(); i++) {
assertNotNull(resultList.get(i - 1).getPeriod().getStart());
assertNotNull(resultList.get(i).getPeriod().getStart());
assertThat(resultList.get(i - 1).getPeriod().getStart(), lessThanOrEqualTo(resultList.get(i).getPeriod().getStart()));
}
sort.setOrder(SortOrderEnum.DESC);
theParams.setSortSpec(sort);
results = search(theParams);
assertThat(results, notNullValue());
assertThat(results.size(), greaterThan(1));
resultList = get(results).stream().filter(it -> it instanceof Encounter).map(it -> (Encounter) it).collect(Collectors.toList());
assertThat(resultList, hasSize(greaterThan(1)));
for (int i = 1; i < resultList.size(); i++) {
assertNotNull(resultList.get(i - 1).getPeriod().getStart());
assertNotNull(resultList.get(i).getPeriod().getStart());
assertThat(resultList.get(i - 1).getPeriod().getStart(), greaterThanOrEqualTo(resultList.get(i).getPeriod().getStart()));
}
}
use of org.hl7.fhir.r4.model.Encounter in project openmrs-module-fhir2 by openmrs.
the class VisitSearchQueryTest method searchForVisits_shouldSearchForVisitsBySubjectIdentifier.
@Test
public void searchForVisits_shouldSearchForVisitsBySubjectIdentifier() {
ReferenceAndListParam subjectReference = new ReferenceAndListParam();
ReferenceParam subject = new ReferenceParam();
subject.setValue(PATIENT_IDENTIFIER);
subject.setChain(Patient.SP_IDENTIFIER);
subjectReference.addValue(new ReferenceOrListParam().add(subject));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, subjectReference);
IBundleProvider results = search(theParams);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
assertThat(((Encounter) resultList.iterator().next()).getSubject().getReference(), endsWith(PATIENT_UUID));
}
Aggregations