Search in sources :

Example 1 with EncounterTranslator

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));
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SimpleBundleProvider(ca.uhn.fhir.rest.server.SimpleBundleProvider) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 2 with EncounterTranslator

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)));
}
Also used : SearchQueryInclude(org.openmrs.module.fhir2.api.search.SearchQueryInclude) Include(ca.uhn.fhir.model.api.Include) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SimpleBundleProvider(ca.uhn.fhir.rest.server.SimpleBundleProvider) HashSet(java.util.HashSet) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 3 with EncounterTranslator

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));
}
Also used : TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SimpleBundleProvider(ca.uhn.fhir.rest.server.SimpleBundleProvider) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 4 with EncounterTranslator

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))));
}
Also used : SearchQueryInclude(org.openmrs.module.fhir2.api.search.SearchQueryInclude) Include(ca.uhn.fhir.model.api.Include) Patient(org.hl7.fhir.r4.model.Patient) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SimpleBundleProvider(ca.uhn.fhir.rest.server.SimpleBundleProvider) HashSet(java.util.HashSet) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 5 with EncounterTranslator

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)));
}
Also used : TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SimpleBundleProvider(ca.uhn.fhir.rest.server.SimpleBundleProvider) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Aggregations

IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)12 SimpleBundleProvider (ca.uhn.fhir.rest.server.SimpleBundleProvider)12 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)12 Test (org.junit.Test)12 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)12 ArrayList (java.util.ArrayList)5 Encounter (org.openmrs.Encounter)5 Include (ca.uhn.fhir.model.api.Include)4 HashSet (java.util.HashSet)4 SearchQueryInclude (org.openmrs.module.fhir2.api.search.SearchQueryInclude)4 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)3 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)3 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)3 TokenParam (ca.uhn.fhir.rest.param.TokenParam)3 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)2 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)2 DateParam (ca.uhn.fhir.rest.param.DateParam)1 Observation (org.hl7.fhir.r4.model.Observation)1 Patient (org.hl7.fhir.r4.model.Patient)1