Search in sources :

Example 46 with SearchQueryInclude

use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.

the class FhirPatientServiceImplTest method searchForPatients_shouldSearchForPatientsByGivenName.

@Test
public void searchForPatients_shouldSearchForPatientsByGivenName() {
    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(null, stringAndListParam, 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), not(empty()));
    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 47 with SearchQueryInclude

use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.

the class FhirPatientServiceImplTest method searchForPatients_shouldReturnCollectionOfPatientWhenPatientBirthDateMatched.

@Test
public void searchForPatients_shouldReturnCollectionOfPatientWhenPatientBirthDateMatched() throws ParseException {
    Date birthDate = dateFormatter.parse(DATE);
    patient.setBirthdate(birthDate);
    List<Patient> patients = new ArrayList<>();
    patients.add(patient);
    DateRangeParam dateRangeParam = new DateRangeParam().setLowerBound(DATE).setUpperBound(DATE);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, dateRangeParam);
    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(null, null, null, null, null, dateRangeParam, null, null, null, null, null, null, null, null, null, null);
    assertThat(results, notNullValue());
    assertThat(results.size(), greaterThanOrEqualTo(1));
    assertThat(get(results), not(empty()));
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) Date(java.util.Date) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 48 with SearchQueryInclude

use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.

the class FhirPatientServiceImplTest method searchForPatients_shouldReturnCollectionOfPatientWhenPatientCityMatched.

@Test
public void searchForPatients_shouldReturnCollectionOfPatientWhenPatientCityMatched() {
    List<Patient> patients = new ArrayList<>();
    patients.add(patient);
    StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringParam(CITY));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, "city", 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(null, null, null, null, null, null, null, null, stringAndListParam, null, null, null, null, null, null, null);
    assertThat(results, notNullValue());
    assertThat(results.size(), greaterThanOrEqualTo(1));
    assertThat(get(results), not(empty()));
}
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 49 with SearchQueryInclude

use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.

the class FhirPatientServiceImplTest method searchForPatients_shouldReturnEmptyCollectionWhenPatientPostalCodeNotMatched.

@Test
public void searchForPatients_shouldReturnEmptyCollectionWhenPatientPostalCodeNotMatched() {
    StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringParam(UNKNOWN_ADDRESS));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, "postalCode", 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, null, stringAndListParam, 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)

Example 50 with SearchQueryInclude

use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.

the class FhirPatientServiceImplTest method searchForPatients_shouldReturnEmptyCollectionWhenPatientBirthDateNotMatched.

@Test
public void searchForPatients_shouldReturnEmptyCollectionWhenPatientBirthDateNotMatched() {
    DateRangeParam dateRangeParam = new DateRangeParam().setLowerBound(UNKNOWN_DATE).setUpperBound(UNKNOWN_DATE);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, dateRangeParam);
    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, dateRangeParam, null, null, null, null, null, null, null, null, null, null);
    assertThat(results, notNullValue());
    assertThat(get(results), empty());
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Aggregations

SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)190 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)187 Test (org.junit.Test)184 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)49 TokenParam (ca.uhn.fhir.rest.param.TokenParam)41 ArrayList (java.util.ArrayList)41 SimpleBundleProvider (ca.uhn.fhir.rest.server.SimpleBundleProvider)39 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