use of org.openmrs.module.fhir2.api.search.SearchQueryInclude 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.search.SearchQueryInclude 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.search.SearchQueryInclude 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)));
}
use of org.openmrs.module.fhir2.api.search.SearchQueryInclude 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.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.
the class FhirMedicationRequestServiceImplTest method searchForMedicationRequest_shouldReturnCollectionOfMedicationRequestByEncounter.
@Test
public void searchForMedicationRequest_shouldReturnCollectionOfMedicationRequestByEncounter() {
ReferenceAndListParam encounter = new ReferenceAndListParam();
encounter.addValue(new ReferenceOrListParam().add(new ReferenceParam().setValue("jdjdj-kdkdkkd-kddd").setChain(Encounter.SP_IDENTIFIER)));
List<DrugOrder> drugOrders = new ArrayList<>();
drugOrders.add(drugOrder);
medicationRequest.setId(MEDICATION_REQUEST_UUID);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER, encounter);
when(dao.getSearchResults(any(), any())).thenReturn(drugOrders);
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(MEDICATION_REQUEST_UUID));
when(medicationRequestTranslator.toFhirResource(drugOrder)).thenReturn(medicationRequest);
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, medicationRequestTranslator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
IBundleProvider results = medicationRequestService.searchForMedicationRequests(null, encounter, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, Matchers.notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
Aggregations