use of org.openmrs.module.fhir2.api.translators.PatientTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirPatientServiceImplTest method searchForPatients_shouldReturnCollectionOfPatientsForPartialMatchOnGivenName.
@Test
public void searchForPatients_shouldReturnCollectionOfPatientsForPartialMatchOnGivenName() {
List<Patient> patients = new ArrayList<>();
patients.add(patient);
StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringParam(PATIENT_PARTIAL_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(), 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_shouldReturnAllInformationAboutSpecifiedPatient.
@Test
public void getPatientEverything_shouldReturnAllInformationAboutSpecifiedPatient() {
TokenParam patientId = new TokenParam().setValue(PATIENT_UUID);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.EVERYTHING_SEARCH_HANDLER, "").addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, patientId);
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(patientId);
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_shouldReturnEmptyCollectionWhenPatientCountryNotMatched.
@Test
public void searchForPatients_shouldReturnEmptyCollectionWhenPatientCountryNotMatched() {
StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringParam(UNKNOWN_ADDRESS));
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(null, null, null, null, null, null, null, null, null, null, null, stringAndListParam, null, null, 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_shouldReturnCollectionOfPatientWhenPatientPostalCodeMatched.
@Test
public void searchForPatients_shouldReturnCollectionOfPatientWhenPatientPostalCodeMatched() {
List<Patient> patients = new ArrayList<>();
patients.add(patient);
StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringParam(POSTAL_CODE));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, "postalCode", 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, stringAndListParam, null, 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 searchForPatients_shouldSearchForPatientsByFamilyName.
@Test
public void searchForPatients_shouldSearchForPatientsByFamilyName() {
List<Patient> patients = new ArrayList<>();
patients.add(patient);
StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringParam(PATIENT_FAMILY_NAME));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, stringAndListParam);
when(globalPropertyService.getGlobalProperty(anyString(), anyInt())).thenReturn(10);
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.getUuid(), notNullValue());
assertThat(results.size(), equalTo(1));
assertThat(results.preferredPageSize(), equalTo(10));
assertThat(get(results), not(empty()));
}
Aggregations