use of org.openmrs.module.fhir2.api.search.SearchQueryBundleProvider in project openmrs-module-fhir2 by openmrs.
the class FhirAllergyIntoleranceServiceImplTest method searchForAllergies_shouldNotAddPatientsToReturnedResultsForEmptyInclude.
@Test
public void searchForAllergies_shouldNotAddPatientsToReturnedResultsForEmptyInclude() {
HashSet<Include> includes = new HashSet<>();
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
when(allergyIntoleranceDao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(omrsAllergy));
when(allergyIntoleranceDao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(ALLERGY_UUID));
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, allergyIntoleranceDao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
when(translator.toFhirResource(omrsAllergy)).thenReturn(fhirAllergy);
IBundleProvider results = service.searchForAllergies(null, null, null, null, null, null, null, null, null, includes);
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 FhirAllergyIntoleranceServiceImplTest method searchForAllergies_shouldSearchForAllergiesByPatientFamilyName.
@Test
public void searchForAllergies_shouldSearchForAllergiesByPatientFamilyName() {
List<Allergy> allergies = new ArrayList<>();
allergies.add(omrsAllergy);
ReferenceAndListParam patientParam = new ReferenceAndListParam();
ReferenceParam referenceParam = new ReferenceParam();
referenceParam.setValue("John");
referenceParam.setChain(Patient.SP_FAMILY);
patientParam.addValue(new ReferenceOrListParam().add(referenceParam));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, patientParam);
when(allergyIntoleranceDao.getSearchResults(any(), any())).thenReturn(allergies);
when(allergyIntoleranceDao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(ALLERGY_UUID));
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, allergyIntoleranceDao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
when(translator.toFhirResource(omrsAllergy)).thenReturn(fhirAllergy);
IBundleProvider results = service.searchForAllergies(patientParam, null, null, null, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
assertThat(resultList, not(empty()));
}
use of org.openmrs.module.fhir2.api.search.SearchQueryBundleProvider in project openmrs-module-fhir2 by openmrs.
the class FhirAllergyIntoleranceServiceImplTest method searchForAllergies_shouldSearchForAllergiesBySeverity.
@Test
public void searchForAllergies_shouldSearchForAllergiesBySeverity() {
List<Allergy> allergies = new ArrayList<>();
allergies.add(omrsAllergy);
TokenAndListParam severity = new TokenAndListParam();
severity.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(SEVERITY_CONCEPT_UUID)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.SEVERITY_SEARCH_HANDLER, severity);
when(allergyIntoleranceDao.getSearchResults(any(), any())).thenReturn(allergies);
when(allergyIntoleranceDao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(ALLERGY_UUID));
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, allergyIntoleranceDao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
when(translator.toFhirResource(omrsAllergy)).thenReturn(fhirAllergy);
IBundleProvider results = service.searchForAllergies(null, null, null, severity, 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 FhirAllergyIntoleranceServiceImplTest method searchForAllergies_shouldSearchForAllergiesByAllergen.
@Test
public void searchForAllergies_shouldSearchForAllergiesByAllergen() {
List<Allergy> allergies = new ArrayList<>();
allergies.add(omrsAllergy);
TokenAndListParam allergen = new TokenAndListParam();
allergen.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(CODED_ALLERGEN_UUID)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ALLERGEN_SEARCH_HANDLER, allergen);
when(allergyIntoleranceDao.getSearchResults(any(), any())).thenReturn(allergies);
when(allergyIntoleranceDao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(ALLERGY_UUID));
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, allergyIntoleranceDao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
when(translator.toFhirResource(omrsAllergy)).thenReturn(fhirAllergy);
IBundleProvider results = service.searchForAllergies(null, null, allergen, null, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
assertThat(resultList, not(empty()));
}
use of org.openmrs.module.fhir2.api.search.SearchQueryBundleProvider in project openmrs-module-fhir2 by openmrs.
the class FhirGroupMemberService_2_1Test method shouldSearchForGroupMembersByGroupUuid.
@Test
public void shouldSearchForGroupMembersByGroupUuid() {
GroupMember groupMember = mock(GroupMember.class);
CohortMembership cohortMembership = mock(CohortMembership.class);
List<CohortMembership> memberships = new ArrayList<>();
memberships.add(cohortMembership);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.GROUP_MEMBERS_SEARCH_HANDLER, GROUP_MEMBER_UUID);
when(dao.getSearchResults(any(), any())).thenReturn(memberships);
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(GROUP_MEMBER_UUID));
when(translator.toFhirResource(cohortMembership)).thenReturn(groupMember);
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 = groupMemberService.getGroupMembers(GROUP_MEMBER_UUID);
List<IBaseResource> resultList = get(results);
assertThat(results, Matchers.notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(1));
}
Aggregations