use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.
the class FhirDiagnosticReportServiceImplTest method searchForDiagnosticReports_shouldNotAddRelatedResourcesForEmptyInclude.
@Test
public void searchForDiagnosticReports_shouldNotAddRelatedResourcesForEmptyInclude() {
FhirDiagnosticReport fhirDiagnosticReport = new FhirDiagnosticReport();
fhirDiagnosticReport.setUuid(UUID);
DiagnosticReport diagnosticReport = new DiagnosticReport();
diagnosticReport.setId(UUID);
List<FhirDiagnosticReport> diagnosticReportList = new ArrayList<>();
diagnosticReportList.add(fhirDiagnosticReport);
HashSet<Include> includes = new HashSet<>();
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
when(dao.getSearchResults(any(), any())).thenReturn(diagnosticReportList);
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(UUID));
when(translator.toFhirResource(fhirDiagnosticReport)).thenReturn(diagnosticReport);
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
IBundleProvider results = service.searchForDiagnosticReports(null, null, null, null, null, null, null, null, includes);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList.size(), equalTo(1));
assertThat(resultList, hasItem(hasProperty("id", equalTo(UUID))));
}
use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.
the class FhirDiagnosticReportServiceImplTest method searchForDiagnosticReports_shouldAddRelatedResourcesWhenIncluded.
@Test
public void searchForDiagnosticReports_shouldAddRelatedResourcesWhenIncluded() {
FhirDiagnosticReport fhirDiagnosticReport = new FhirDiagnosticReport();
fhirDiagnosticReport.setUuid(UUID);
DiagnosticReport diagnosticReport = new DiagnosticReport();
diagnosticReport.setId(UUID);
List<FhirDiagnosticReport> diagnosticReportList = new ArrayList<>();
diagnosticReportList.add(fhirDiagnosticReport);
HashSet<Include> includes = new HashSet<>();
includes.add(new Include("DiagnosticReport:patient"));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
when(dao.getSearchResults(any(), any())).thenReturn(diagnosticReportList);
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(UUID));
when(translator.toFhirResource(fhirDiagnosticReport)).thenReturn(diagnosticReport);
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.singleton(new Patient()));
IBundleProvider results = service.searchForDiagnosticReports(null, null, null, null, null, null, null, null, includes);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList.size(), equalTo(2));
assertThat(resultList, hasItem(is(instanceOf(Patient.class))));
assertThat(resultList, hasItem(hasProperty("id", equalTo(UUID))));
}
use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.
the class FhirDiagnosticReportServiceImplTest method searchForDiagnosticReports_shouldReturnCollectionOfDiagnosticReportsByParameters.
@Test
public void searchForDiagnosticReports_shouldReturnCollectionOfDiagnosticReportsByParameters() {
FhirDiagnosticReport fhirDiagnosticReport = new FhirDiagnosticReport();
fhirDiagnosticReport.setUuid(UUID);
DiagnosticReport diagnosticReport = new DiagnosticReport();
diagnosticReport.setId(UUID);
List<FhirDiagnosticReport> fhirDiagnosticReports = new ArrayList<>();
fhirDiagnosticReports.add(fhirDiagnosticReport);
SearchParameterMap theParams = new SearchParameterMap();
when(dao.getSearchResults(any(), any())).thenReturn(fhirDiagnosticReports);
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(UUID));
when(translator.toFhirResource(fhirDiagnosticReport)).thenReturn(diagnosticReport);
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
IBundleProvider results = service.searchForDiagnosticReports(null, null, null, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasItem(hasProperty("id", equalTo(UUID))));
}
use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.
the class FhirEncounterServiceImplTest method searchForEncounter_shouldReturnCollectionOfEncounterByLastUpdated.
@Test
public void searchForEncounter_shouldReturnCollectionOfEncounterByLastUpdated() {
DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(LAST_UPDATED_DATE).setLowerBound(LAST_UPDATED_DATE);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated);
when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(openMrsEncounter));
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(ENCOUNTER_UUID));
when(encounterTranslator.toFhirResource(openMrsEncounter)).thenReturn(fhirEncounter);
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, encounterTranslator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
when(visitService.searchForVisits(any())).thenReturn(new SimpleBundleProvider());
IBundleProvider results = encounterService.searchForEncounters(null, null, null, null, null, null, lastUpdated, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList.size(), greaterThanOrEqualTo(1));
}
use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.
the class FhirEncounterServiceImplTest method searchForEncounter_shouldNotAddRelatedResourcesToResultListForEmptyRevInclude.
@Test
public void searchForEncounter_shouldNotAddRelatedResourcesToResultListForEmptyRevInclude() {
HashSet<Include> revIncludes = new HashSet<>();
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.REVERSE_INCLUDE_SEARCH_HANDLER, revIncludes);
when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(openMrsEncounter));
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(ENCOUNTER_UUID));
when(encounterTranslator.toFhirResource(openMrsEncounter)).thenReturn(fhirEncounter);
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, encounterTranslator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
when(visitService.searchForVisits(any())).thenReturn(new SimpleBundleProvider());
IBundleProvider results = encounterService.searchForEncounters(null, null, null, null, null, null, null, null, null, revIncludes);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
Aggregations