use of org.openmrs.module.fhir2.api.translators.EncounterTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirEncounterServiceImplTest method searchForEncounter_shouldReturnCollectionOfEncounterByLastUpdated.
@Test
public void searchForEncounter_shouldReturnCollectionOfEncounterByLastUpdated() {
DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(LAST_UPDATED_DATE).setLowerBound(LAST_UPDATED_DATE);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated);
when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(openMrsEncounter));
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(ENCOUNTER_UUID));
when(encounterTranslator.toFhirResource(openMrsEncounter)).thenReturn(fhirEncounter);
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, encounterTranslator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
when(visitService.searchForVisits(any())).thenReturn(new SimpleBundleProvider());
IBundleProvider results = encounterService.searchForEncounters(null, null, null, null, null, null, lastUpdated, null, null, null);
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.EncounterTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirEncounterServiceImplTest method searchForEncounter_shouldNotAddRelatedResourcesToResultListForEmptyRevInclude.
@Test
public void searchForEncounter_shouldNotAddRelatedResourcesToResultListForEmptyRevInclude() {
HashSet<Include> revIncludes = new HashSet<>();
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.REVERSE_INCLUDE_SEARCH_HANDLER, revIncludes);
when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(openMrsEncounter));
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(ENCOUNTER_UUID));
when(encounterTranslator.toFhirResource(openMrsEncounter)).thenReturn(fhirEncounter);
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, encounterTranslator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
when(visitService.searchForVisits(any())).thenReturn(new SimpleBundleProvider());
IBundleProvider results = encounterService.searchForEncounters(null, null, null, null, null, null, null, null, null, revIncludes);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
use of org.openmrs.module.fhir2.api.translators.EncounterTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirEncounterServiceImplTest method getEncounterEverything_shouldReturnAllInformationAboutSpecifiedEncounter.
@Test
public void getEncounterEverything_shouldReturnAllInformationAboutSpecifiedEncounter() {
TokenParam encounterId = new TokenParam().setValue(ENCOUNTER_UUID);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.EVERYTHING_SEARCH_HANDLER, "").addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, encounterId);
populateIncludeForEverythingOperationParams(theParams);
populateReverseIncludeForEverythingOperationParams(theParams);
when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(openMrsEncounter));
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(ENCOUNTER_UUID));
when(encounterTranslator.toFhirResource(openMrsEncounter)).thenReturn(fhirEncounter);
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, encounterTranslator, globalPropertyService, searchQueryInclude));
when(visitService.searchForVisits(any())).thenReturn(new SimpleBundleProvider());
IBundleProvider results = encounterService.getEncounterEverything(encounterId);
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.EncounterTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirEncounterServiceImplTest method searchForEncounter_shouldAddIncludedResourcesToResultList.
@Test
public void searchForEncounter_shouldAddIncludedResourcesToResultList() {
HashSet<Include> includes = new HashSet<>();
includes.add(new Include("Encounter:patient"));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(openMrsEncounter));
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(ENCOUNTER_UUID));
when(encounterTranslator.toFhirResource(openMrsEncounter)).thenReturn(fhirEncounter);
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, encounterTranslator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.singleton(new Patient()));
when(visitService.searchForVisits(any())).thenReturn(new SimpleBundleProvider());
IBundleProvider results = encounterService.searchForEncounters(null, null, null, null, null, null, null, null, includes, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList.size(), greaterThanOrEqualTo(2));
assertThat(resultList, hasItem(is(instanceOf(Patient.class))));
}
use of org.openmrs.module.fhir2.api.translators.EncounterTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirEncounterServiceImplTest method searchForEncounter_shouldReturnCollectionOfEncounterByUUID.
@Test
public void searchForEncounter_shouldReturnCollectionOfEncounterByUUID() {
TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(ENCOUNTER_UUID));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid);
when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(openMrsEncounter));
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(ENCOUNTER_UUID));
when(encounterTranslator.toFhirResource(openMrsEncounter)).thenReturn(fhirEncounter);
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, encounterTranslator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
when(visitService.searchForVisits(any())).thenReturn(new SimpleBundleProvider());
IBundleProvider results = encounterService.searchForEncounters(null, null, null, null, null, uuid, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
Aggregations