Search in sources :

Example 86 with SearchQueryBundleProvider

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)));
}
Also used : SearchQueryInclude(org.openmrs.module.fhir2.api.search.SearchQueryInclude) Include(ca.uhn.fhir.model.api.Include) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) HashSet(java.util.HashSet) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 87 with SearchQueryBundleProvider

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()));
}
Also used : Allergy(org.openmrs.Allergy) ArrayList(java.util.ArrayList) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 88 with SearchQueryBundleProvider

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)));
}
Also used : Allergy(org.openmrs.Allergy) TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) TokenParam(ca.uhn.fhir.rest.param.TokenParam) ArrayList(java.util.ArrayList) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 89 with SearchQueryBundleProvider

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()));
}
Also used : Allergy(org.openmrs.Allergy) TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) TokenParam(ca.uhn.fhir.rest.param.TokenParam) ArrayList(java.util.ArrayList) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 90 with SearchQueryBundleProvider

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));
}
Also used : GroupMember(org.openmrs.module.fhir2.model.GroupMember) ArrayList(java.util.ArrayList) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) CohortMembership(org.openmrs.CohortMembership) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)184 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)184 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)183 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)148 StringParam (ca.uhn.fhir.rest.param.StringParam)72 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)66 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)46 ArrayList (java.util.ArrayList)41 TokenParam (ca.uhn.fhir.rest.param.TokenParam)40 SimpleBundleProvider (ca.uhn.fhir.rest.server.SimpleBundleProvider)38 Include (ca.uhn.fhir.model.api.Include)29 HashSet (java.util.HashSet)29 SearchQueryInclude (org.openmrs.module.fhir2.api.search.SearchQueryInclude)29 StringOrListParam (ca.uhn.fhir.rest.param.StringOrListParam)28 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)27 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)22 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)22 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)22 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)19 Patient (org.openmrs.Patient)12