use of org.openmrs.module.fhir2.api.search.SearchQueryBundleProvider in project openmrs-module-fhir2 by openmrs.
the class FhirUserServiceImplTest method shouldReturnEmptyCollectionByWrongName.
@Test
public void shouldReturnEmptyCollectionByWrongName() {
StringAndListParam name = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(WRONG_NAME)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(NAME_SEARCH_HANDLER, NAME_PROPERTY, name);
when(dao.getSearchResultUuids(any())).thenReturn(Collections.emptyList());
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
IBundleProvider results = userService.searchForUsers(theParams);
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 FhirUserServiceImplTest method shouldsearchForUsersByLastUpdated.
@Test
public void shouldsearchForUsersByLastUpdated() {
DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(LAST_UPDATED_DATE).setLowerBound(LAST_UPDATED_DATE);
SearchParameterMap theParams = new SearchParameterMap().addParameter(COMMON_SEARCH_HANDLER, LAST_UPDATED_PROPERTY, lastUpdated);
when(dao.getSearchResultUuids(any())).thenReturn(singletonList(USER_UUID));
when(dao.getSearchResults(any(), any())).thenReturn(singletonList(user));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(translator.toFhirResource(user)).thenReturn(practitioner);
IBundleProvider results = userService.searchForUsers(theParams);
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 FhirMedicationServiceImplTest method searchForMedications_shouldSearchMedicationsByDosageForm.
@Test
public void searchForMedications_shouldSearchMedicationsByDosageForm() {
List<Drug> medications = new ArrayList<>();
medications.add(drug);
TokenAndListParam dosageForm = new TokenAndListParam();
dosageForm.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(CODE)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DOSAGE_FORM_SEARCH_HANDLER, dosageForm);
when(medicationDao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(MEDICATION_UUID));
when(medicationDao.getSearchResults(any(), any())).thenReturn(medications);
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, medicationDao, medicationTranslator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
when(medicationTranslator.toFhirResource(drug)).thenReturn(medication);
IBundleProvider result = fhirMedicationService.searchForMedications(null, dosageForm, null, null, null, null);
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 FhirMedicationServiceImplTest method searchForMedications_shouldSearchMedicationsByUUID.
@Test
public void searchForMedications_shouldSearchMedicationsByUUID() {
TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(MEDICATION_UUID));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid);
when(medicationDao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(MEDICATION_UUID));
when(medicationDao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(drug));
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, medicationDao, medicationTranslator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
when(medicationTranslator.toFhirResource(drug)).thenReturn(medication);
IBundleProvider result = fhirMedicationService.searchForMedications(null, null, null, uuid, null, null);
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 FhirObservationServiceImplTest method getLastnObservations_shouldReturnRecentNObservationsForAllPatientsWhenNoPatientIsSpecified.
@Test
public void getLastnObservations_shouldReturnRecentNObservationsForAllPatientsWhenNoPatientIsSpecified() {
Obs obs = new Obs();
obs.setUuid(OBS_UUID);
Observation observation = new Observation();
observation.setId(OBS_UUID);
NumberParam max = new NumberParam(2);
TokenAndListParam categories = new TokenAndListParam().addAnd(new TokenParam().setValue("laboratory"));
TokenAndListParam code = new TokenAndListParam().addAnd(new TokenParam().setSystem(FhirTestConstants.LOINC_SYSTEM_URL).setValue(LOINC_SYSTOLIC_BP), new TokenParam().setSystem(FhirTestConstants.CIEL_SYSTEM_URN).setValue(CIEL_DIASTOLIC_BP));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CODED_SEARCH_HANDLER, code).addParameter(FhirConstants.CATEGORY_SEARCH_HANDLER, categories).addParameter(FhirConstants.MAX_SEARCH_HANDLER, max).addParameter(FhirConstants.LASTN_OBSERVATION_SEARCH_HANDLER, new StringParam());
when(globalPropertyService.getGlobalProperty(anyString(), anyInt())).thenReturn(10);
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(OBS_UUID));
when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(obs));
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(obs)).thenReturn(observation);
IBundleProvider results = fhirObservationService.getLastnObservations(max, null, categories, code);
assertThat(results, notNullValue());
assertThat(results.size(), equalTo(1));
assertThat(results.preferredPageSize(), equalTo(10));
List<IBaseResource> resultList = results.getResources(1, 10);
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(equalTo(1)));
}
Aggregations