Search in sources :

Example 6 with EncounterTranslator

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))));
}
Also used : Observation(org.hl7.fhir.r4.model.Observation) 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 7 with EncounterTranslator

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));
}
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 8 with EncounterTranslator

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

Example 9 with EncounterTranslator

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

Example 10 with EncounterTranslator

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)));
}
Also used : ArrayList(java.util.ArrayList) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) Encounter(org.openmrs.Encounter) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SimpleBundleProvider(ca.uhn.fhir.rest.server.SimpleBundleProvider) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) 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