use of org.openmrs.module.fhir2.api.translators.EncounterTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirEncounterServiceImplTest method searchForEncounter_shouldAddReverseIncludedResourcesToResultList.
@Test
public void searchForEncounter_shouldAddReverseIncludedResourcesToResultList() {
HashSet<Include> revIncludes = new HashSet<>();
revIncludes.add(new Include("Observation:encounter"));
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.singleton(new Observation()));
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.size(), greaterThanOrEqualTo(2));
assertThat(resultList, hasItem(is(instanceOf(Observation.class))));
}
use of org.openmrs.module.fhir2.api.translators.EncounterTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirEncounterServiceImplTest method searchForEncounter_shouldNotAddRelatedResourcesToResultListForEmptyInclude.
@Test
public void searchForEncounter_shouldNotAddRelatedResourcesToResultListForEmptyInclude() {
HashSet<Include> includes = new HashSet<>();
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.emptySet());
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(1));
}
use of org.openmrs.module.fhir2.api.translators.EncounterTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirEncounterServiceImplTest method searchForEncounter_shouldReturnCollectionOfEncounterBySubject.
@Test
public void searchForEncounter_shouldReturnCollectionOfEncounterBySubject() {
ReferenceAndListParam subject = new ReferenceAndListParam();
subject.addValue(new ReferenceOrListParam().add(new ReferenceParam().setValue(PATIENT_FAMILY_NAME).setChain(Patient.SP_FAMILY)));
List<Encounter> encounters = new ArrayList<>();
encounters.add(openMrsEncounter);
fhirEncounter.setId(ENCOUNTER_UUID);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, subject);
when(dao.getSearchResults(any(), any())).thenReturn(encounters);
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, subject, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, Matchers.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 searchForEncounter_shouldReturnCollectionOfEncounterByDate.
@Test
public void searchForEncounter_shouldReturnCollectionOfEncounterByDate() {
List<Encounter> encounters = new ArrayList<>();
DateRangeParam dateRangeParam = new DateRangeParam(new DateParam(ENCOUNTER_DATETIME));
encounters.add(openMrsEncounter);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, dateRangeParam);
fhirEncounter.setId(ENCOUNTER_UUID);
when(dao.getSearchResults(any(), any())).thenReturn(encounters);
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(dateRangeParam, null, null, null, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(((org.hl7.fhir.r4.model.Encounter) resultList.iterator().next()).getId(), equalTo(ENCOUNTER_UUID));
}
use of org.openmrs.module.fhir2.api.translators.EncounterTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirEncounterServiceImplTest method searchForEncounter_shouldReturnCollectionOfEncounterByLocation.
@Test
public void searchForEncounter_shouldReturnCollectionOfEncounterByLocation() {
ReferenceAndListParam location = new ReferenceAndListParam();
location.addValue(new ReferenceOrListParam().add(new ReferenceParam().setValue(ENCOUNTER_ADDRESS_STATE).setChain(Location.SP_ADDRESS_STATE)));
List<Encounter> encounters = new ArrayList<>();
encounters.add(openMrsEncounter);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.LOCATION_REFERENCE_SEARCH_HANDLER, location);
when(dao.getSearchResults(any(), any())).thenReturn(encounters);
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, location, null, null, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
Aggregations