Search in sources :

Example 76 with SearchQueryInclude

use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.

the class FhirDiagnosticReportServiceImplTest method searchForDiagnosticReports_shouldNotAddRelatedResourcesForEmptyInclude.

@Test
public void searchForDiagnosticReports_shouldNotAddRelatedResourcesForEmptyInclude() {
    FhirDiagnosticReport fhirDiagnosticReport = new FhirDiagnosticReport();
    fhirDiagnosticReport.setUuid(UUID);
    DiagnosticReport diagnosticReport = new DiagnosticReport();
    diagnosticReport.setId(UUID);
    List<FhirDiagnosticReport> diagnosticReportList = new ArrayList<>();
    diagnosticReportList.add(fhirDiagnosticReport);
    HashSet<Include> includes = new HashSet<>();
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
    when(dao.getSearchResults(any(), any())).thenReturn(diagnosticReportList);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(UUID));
    when(translator.toFhirResource(fhirDiagnosticReport)).thenReturn(diagnosticReport);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    IBundleProvider results = service.searchForDiagnosticReports(null, null, null, null, null, null, null, null, includes);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList.size(), equalTo(1));
    assertThat(resultList, hasItem(hasProperty("id", equalTo(UUID))));
}
Also used : FhirDiagnosticReport(org.openmrs.module.fhir2.model.FhirDiagnosticReport) ArrayList(java.util.ArrayList) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) FhirDiagnosticReport(org.openmrs.module.fhir2.model.FhirDiagnosticReport) 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) HashSet(java.util.HashSet) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 77 with SearchQueryInclude

use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.

the class FhirDiagnosticReportServiceImplTest method searchForDiagnosticReports_shouldAddRelatedResourcesWhenIncluded.

@Test
public void searchForDiagnosticReports_shouldAddRelatedResourcesWhenIncluded() {
    FhirDiagnosticReport fhirDiagnosticReport = new FhirDiagnosticReport();
    fhirDiagnosticReport.setUuid(UUID);
    DiagnosticReport diagnosticReport = new DiagnosticReport();
    diagnosticReport.setId(UUID);
    List<FhirDiagnosticReport> diagnosticReportList = new ArrayList<>();
    diagnosticReportList.add(fhirDiagnosticReport);
    HashSet<Include> includes = new HashSet<>();
    includes.add(new Include("DiagnosticReport:patient"));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
    when(dao.getSearchResults(any(), any())).thenReturn(diagnosticReportList);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(UUID));
    when(translator.toFhirResource(fhirDiagnosticReport)).thenReturn(diagnosticReport);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.singleton(new Patient()));
    IBundleProvider results = service.searchForDiagnosticReports(null, null, null, null, null, null, null, null, includes);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList.size(), equalTo(2));
    assertThat(resultList, hasItem(is(instanceOf(Patient.class))));
    assertThat(resultList, hasItem(hasProperty("id", equalTo(UUID))));
}
Also used : FhirDiagnosticReport(org.openmrs.module.fhir2.model.FhirDiagnosticReport) ArrayList(java.util.ArrayList) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) FhirDiagnosticReport(org.openmrs.module.fhir2.model.FhirDiagnosticReport) 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) HashSet(java.util.HashSet) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 78 with SearchQueryInclude

use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.

the class FhirDiagnosticReportServiceImplTest method searchForDiagnosticReports_shouldReturnCollectionOfDiagnosticReportsByParameters.

@Test
public void searchForDiagnosticReports_shouldReturnCollectionOfDiagnosticReportsByParameters() {
    FhirDiagnosticReport fhirDiagnosticReport = new FhirDiagnosticReport();
    fhirDiagnosticReport.setUuid(UUID);
    DiagnosticReport diagnosticReport = new DiagnosticReport();
    diagnosticReport.setId(UUID);
    List<FhirDiagnosticReport> fhirDiagnosticReports = new ArrayList<>();
    fhirDiagnosticReports.add(fhirDiagnosticReport);
    SearchParameterMap theParams = new SearchParameterMap();
    when(dao.getSearchResults(any(), any())).thenReturn(fhirDiagnosticReports);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(UUID));
    when(translator.toFhirResource(fhirDiagnosticReport)).thenReturn(diagnosticReport);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    IBundleProvider results = service.searchForDiagnosticReports(null, null, null, null, null, null, null, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasItem(hasProperty("id", equalTo(UUID))));
}
Also used : FhirDiagnosticReport(org.openmrs.module.fhir2.model.FhirDiagnosticReport) ArrayList(java.util.ArrayList) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) FhirDiagnosticReport(org.openmrs.module.fhir2.model.FhirDiagnosticReport) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 79 with SearchQueryInclude

use of org.openmrs.module.fhir2.api.search.SearchQueryInclude 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 80 with SearchQueryInclude

use of org.openmrs.module.fhir2.api.search.SearchQueryInclude 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)

Aggregations

SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)190 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)187 Test (org.junit.Test)184 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)148 StringParam (ca.uhn.fhir.rest.param.StringParam)72 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)66 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)49 TokenParam (ca.uhn.fhir.rest.param.TokenParam)41 ArrayList (java.util.ArrayList)41 SimpleBundleProvider (ca.uhn.fhir.rest.server.SimpleBundleProvider)39 Include (ca.uhn.fhir.model.api.Include)29 HashSet (java.util.HashSet)29 SearchQueryInclude (org.openmrs.module.fhir2.api.search.SearchQueryInclude)29 StringOrListParam (ca.uhn.fhir.rest.param.StringOrListParam)28 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)27 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)22 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)22 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)22 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)19 Patient (org.openmrs.Patient)12