use of org.openmrs.module.fhir2.api.translators.PatientTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirPatientServiceImplTest method searchForPatients_shouldReturnCollectionOfPatientWhenPatientCountryMatched.
@Test
public void searchForPatients_shouldReturnCollectionOfPatientWhenPatientCountryMatched() {
List<Patient> patients = new ArrayList<>();
patients.add(patient);
StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringParam(COUNTRY));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, "country", 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, null, null, null, stringAndListParam, null, null, null, null);
assertThat(results, notNullValue());
assertThat(results.size(), greaterThanOrEqualTo(1));
assertThat(get(results), not(empty()));
}
use of org.openmrs.module.fhir2.api.translators.PatientTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirPatientServiceImplTest method getPatientEverything_shouldReturnAllInformationAboutAllPatients.
@Test
public void getPatientEverything_shouldReturnAllInformationAboutAllPatients() {
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.EVERYTHING_SEARCH_HANDLER, "");
HashSet<Include> revIncludes = new HashSet<>();
revIncludes.add(new Include(FhirConstants.OBSERVATION + ":" + FhirConstants.INCLUDE_PATIENT_PARAM));
revIncludes.add(new Include(FhirConstants.ALLERGY_INTOLERANCE + ":" + FhirConstants.INCLUDE_PATIENT_PARAM));
revIncludes.add(new Include(FhirConstants.DIAGNOSTIC_REPORT + ":" + FhirConstants.INCLUDE_PATIENT_PARAM));
revIncludes.add(new Include(FhirConstants.ENCOUNTER + ":" + FhirConstants.INCLUDE_PATIENT_PARAM));
revIncludes.add(new Include(FhirConstants.MEDICATION_REQUEST + ":" + FhirConstants.INCLUDE_PATIENT_PARAM));
revIncludes.add(new Include(FhirConstants.SERVICE_REQUEST + ":" + FhirConstants.INCLUDE_PATIENT_PARAM));
revIncludes.add(new Include(FhirConstants.PROCEDURE_REQUEST + ":" + FhirConstants.INCLUDE_PATIENT_PARAM));
theParams.addParameter(FhirConstants.REVERSE_INCLUDE_SEARCH_HANDLER, revIncludes);
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(PATIENT_UUID));
when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(patient));
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, patientTranslator, globalPropertyService, searchQueryInclude));
when(patientTranslator.toFhirResource(patient)).thenReturn(fhirPatient);
IBundleProvider results = patientService.getPatientEverything();
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList.size(), greaterThanOrEqualTo(1));
}
use of org.openmrs.module.fhir2.api.translators.PatientTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirPatientServiceImplTest method searchForPatients_shouldReturnEmptyCollectionWhenPatientNameNotMatched.
@Test
public void searchForPatients_shouldReturnEmptyCollectionWhenPatientNameNotMatched() {
StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringParam(PATIENT_GIVEN_NAME_NOT_MATCHED));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, 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(stringAndListParam, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
assertThat(results, notNullValue());
assertThat(get(results), is(empty()));
}
use of org.openmrs.module.fhir2.api.translators.PatientTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirPatientServiceImplTest method searchForPatients_shouldReturnEmptyCollectionWhenLastUpdatedNotMatched.
@Test
public void searchForPatients_shouldReturnEmptyCollectionWhenLastUpdatedNotMatched() {
DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(WRONG_LAST_UPDATED_DATE).setLowerBound(WRONG_LAST_UPDATED_DATE);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated);
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, null, null, null, lastUpdated, null, null);
assertThat(results, notNullValue());
assertThat(get(results), empty());
}
use of org.openmrs.module.fhir2.api.translators.PatientTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirPatientServiceImplTest method searchForPatients_shouldReturnCollectionOfPatientsForPartialMatchOnFamilyName.
@Test
public void searchForPatients_shouldReturnCollectionOfPatientsForPartialMatchOnFamilyName() {
List<Patient> patients = new ArrayList<>();
patients.add(patient);
StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringParam(PATIENT_PARTIAL_FAMILY_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, null, stringAndListParam, null, null, null, null, null, null, null, null, null, null, null, null, null);
assertThat(results, notNullValue());
assertThat(results.size(), greaterThanOrEqualTo(1));
assertThat(get(results), not(empty()));
}
Aggregations