Search in sources :

Example 26 with StringAndListParam

use of ca.uhn.fhir.rest.param.StringAndListParam in project openmrs-module-fhir2 by openmrs.

the class FhirUserServiceImplTest method shouldsearchForUsersByAddressCity.

@Test
public void shouldsearchForUsersByAddressCity() {
    StringAndListParam city = new StringAndListParam().addAnd(new StringParam(CITY));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(ADDRESS_SEARCH_HANDLER, CITY_PROPERTY, city);
    when(dao.getSearchResultUuids(any())).thenReturn(singletonList(USER_UUID));
    when(dao.getSearchResults(any(), any())).thenReturn(singletonList(user));
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
    when(translator.toFhirResource(user)).thenReturn(practitioner);
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    IBundleProvider results = userService.searchForUsers(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 27 with StringAndListParam

use of ca.uhn.fhir.rest.param.StringAndListParam in project openmrs-module-fhir2 by openmrs.

the class FhirUserServiceImplTest method shouldsearchForUsersByAddressPostalCode.

@Test
public void shouldsearchForUsersByAddressPostalCode() {
    StringAndListParam postalCode = new StringAndListParam().addAnd(new StringParam(POSTAL_CODE));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(ADDRESS_SEARCH_HANDLER, POSTAL_CODE_PROPERTY, postalCode);
    when(dao.getSearchResultUuids(any())).thenReturn(singletonList(USER_UUID));
    when(dao.getSearchResults(any(), any())).thenReturn(singletonList(user));
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
    when(translator.toFhirResource(user)).thenReturn(practitioner);
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    IBundleProvider results = userService.searchForUsers(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 28 with StringAndListParam

use of ca.uhn.fhir.rest.param.StringAndListParam 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());
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) StringOrListParam(ca.uhn.fhir.rest.param.StringOrListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 29 with StringAndListParam

use of ca.uhn.fhir.rest.param.StringAndListParam in project openmrs-module-fhir2 by openmrs.

the class FhirPatientServiceImplTest method searchForPatients_shouldSearchForPatientsByName.

@Test
public void searchForPatients_shouldSearchForPatientsByName() {
    List<Patient> patients = new ArrayList<>();
    patients.add(patient);
    StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringParam(PATIENT_GIVEN_NAME));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, stringAndListParam);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(PATIENT_UUID));
    when(dao.getSearchResults(any(), any())).thenReturn(patients);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, patientTranslator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(patientTranslator.toFhirResource(patient)).thenReturn(fhirPatient);
    IBundleProvider results = patientService.searchForPatients(stringAndListParam, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
    assertThat(results, notNullValue());
    assertThat(results.size(), equalTo(1));
    assertThat(get(results), hasSize(equalTo(1)));
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 30 with StringAndListParam

use of ca.uhn.fhir.rest.param.StringAndListParam in project openmrs-module-fhir2 by openmrs.

the class FhirPatientServiceImplTest method searchForPatients_shouldReturnEmptyCollectionWhenPatientStateNotMatched.

@Test
public void searchForPatients_shouldReturnEmptyCollectionWhenPatientStateNotMatched() {
    StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringParam(UNKNOWN_ADDRESS));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, "state", stringAndListParam);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.emptyList());
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, patientTranslator, globalPropertyService, searchQueryInclude));
    IBundleProvider results = patientService.searchForPatients(null, null, null, null, null, null, null, null, null, stringAndListParam, null, null, null, null, null, null);
    assertThat(results, notNullValue());
    assertThat(get(results), empty());
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Aggregations

StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)264 StringParam (ca.uhn.fhir.rest.param.StringParam)243 Test (org.junit.Test)233 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)232 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)157 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)137 StringOrListParam (ca.uhn.fhir.rest.param.StringOrListParam)110 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)91 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)37 MockIBundleProvider (org.openmrs.module.fhir2.providers.r4.MockIBundleProvider)30 Practitioner (org.hl7.fhir.r4.model.Practitioner)26 Patient (org.hl7.fhir.r4.model.Patient)21 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)21 Test (org.junit.jupiter.api.Test)20 SimpleBundleProvider (ca.uhn.fhir.rest.server.SimpleBundleProvider)18 RequestDetails (ca.uhn.fhir.rest.api.server.RequestDetails)16 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)16 Location (org.hl7.fhir.r4.model.Location)14 Person (org.hl7.fhir.r4.model.Person)14 SortSpec (ca.uhn.fhir.rest.api.SortSpec)13