use of org.openmrs.module.fhir2.api.search.SearchQueryBundleProvider in project openmrs-module-fhir2 by openmrs.
the class FhirPractitionerServiceImplTest method shouldSearchForPractitionersByFamilyNameWhoIsUserAndProvider.
@Test
public void shouldSearchForPractitionersByFamilyNameWhoIsUserAndProvider() {
StringAndListParam familyName = new StringAndListParam().addAnd(new StringParam(PRACTITIONER_FAMILY_NAME));
SearchParameterMap theParams = new SearchParameterMap().addParameter(NAME_SEARCH_HANDLER, FAMILY_PROPERTY, familyName);
when(practitionerDao.getSearchResults(any(), any())).thenReturn(singletonList(provider));
when(practitionerDao.getSearchResultUuids(any())).thenReturn(singletonList(UUID));
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, practitionerDao, practitionerTranslator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
when(practitionerTranslator.toFhirResource(provider)).thenReturn(practitioner);
when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider(practitioner2));
IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, familyName, null, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(greaterThanOrEqualTo(2)));
}
use of org.openmrs.module.fhir2.api.search.SearchQueryBundleProvider in project openmrs-module-fhir2 by openmrs.
the class FhirPractitionerServiceImplTest method shouldSearchForPractitionersByNameWhoIsProvider.
@Test
public void shouldSearchForPractitionersByNameWhoIsProvider() {
StringAndListParam name = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(NAME)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(NAME_SEARCH_HANDLER, NAME_PROPERTY, name);
when(practitionerDao.getSearchResultUuids(any())).thenReturn(singletonList(UUID));
when(practitionerDao.getSearchResults(any(), any())).thenReturn(singletonList(provider));
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, practitionerDao, practitionerTranslator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
when(practitionerTranslator.toFhirResource(provider)).thenReturn(practitioner);
when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider());
IBundleProvider results = practitionerService.searchForPractitioners(null, name, null, null, null, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
use of org.openmrs.module.fhir2.api.search.SearchQueryBundleProvider in project openmrs-module-fhir2 by openmrs.
the class FhirPractitionerServiceImplTest method shouldReturnEmptyCollectionByWrongIdentifier.
@Test
public void shouldReturnEmptyCollectionByWrongIdentifier() {
TokenAndListParam identifier = new TokenAndListParam().addAnd(new TokenOrListParam().add(WRONG_IDENTIFIER));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.IDENTIFIER_SEARCH_HANDLER, identifier);
when(practitionerDao.getSearchResultUuids(any())).thenReturn(Collections.emptyList());
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, practitionerDao, practitionerTranslator, globalPropertyService, searchQueryInclude));
when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider());
IBundleProvider results = practitionerService.searchForPractitioners(identifier, null, null, null, null, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, empty());
}
use of org.openmrs.module.fhir2.api.search.SearchQueryBundleProvider in project openmrs-module-fhir2 by openmrs.
the class FhirConditionServiceImplTest method searchConditions_shouldReturnTranslatedConditionReturnedByDao.
@Test
public void searchConditions_shouldReturnTranslatedConditionReturnedByDao() {
ReferenceAndListParam patientReference = new ReferenceAndListParam();
patientReference.addValue(new ReferenceOrListParam().add(new ReferenceParam(org.hl7.fhir.r4.model.Patient.SP_GIVEN, "patient name")));
TokenAndListParam codeList = new TokenAndListParam();
codeList.addValue(new TokenOrListParam().add(new TokenParam("test code")));
TokenAndListParam clinicalList = new TokenAndListParam();
clinicalList.addValue(new TokenOrListParam().add(new TokenParam("test clinical")));
DateRangeParam onsetDate = new DateRangeParam().setLowerBound("gt2020-05-01").setUpperBound("lt2021-05-01");
QuantityAndListParam onsetAge = new QuantityAndListParam();
onsetAge.addValue(new QuantityOrListParam().add(new QuantityParam(12)));
DateRangeParam recordDate = new DateRangeParam().setLowerBound("gt2020-05-01").setUpperBound("lt2021-05-01");
TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(OBS_UUID));
DateRangeParam lastUpdated = new DateRangeParam().setLowerBound(LAST_UPDATED_DATE).setUpperBound(LAST_UPDATED_DATE);
SortSpec sort = new SortSpec("sort param");
HashSet<Include> includes = new HashSet<>();
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, patientReference).addParameter(FhirConstants.CODED_SEARCH_HANDLER, codeList).addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, onsetAge).addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "onsetDate", onsetDate).addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "dateCreated", recordDate).addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated).setSortSpec(sort);
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(OBS_UUID));
when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(obsCondition));
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
when(translator.toFhirResource(obsCondition)).thenReturn(condition);
IBundleProvider result = fhirConditionService.searchConditions(patientReference, codeList, clinicalList, onsetDate, onsetAge, recordDate, uuid, lastUpdated, sort, includes);
List<IBaseResource> resultList = get(result);
assertThat(result, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
use of org.openmrs.module.fhir2.api.search.SearchQueryBundleProvider 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))));
}
Aggregations