Search in sources :

Example 36 with SearchQueryInclude

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

the class FhirObservationServiceImplTest method searchForObservations_shouldReturnObservationsByParameters.

@Test
public void searchForObservations_shouldReturnObservationsByParameters() {
    Obs obs = new Obs();
    obs.setUuid(OBS_UUID);
    Observation observation = new Observation();
    observation.setId(OBS_UUID);
    ReferenceAndListParam patientReference = new ReferenceAndListParam();
    ReferenceParam patient = new ReferenceParam();
    patient.setValue(PATIENT_GIVEN_NAME);
    patient.setChain(Patient.SP_GIVEN);
    patientReference.addValue(new ReferenceOrListParam().add(patient));
    SearchParameterMap theParams = new SearchParameterMap();
    theParams.addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, patientReference);
    when(globalPropertyService.getGlobalProperty(anyString(), anyInt())).thenReturn(10);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(OBS_UUID));
    when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(obs));
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(translator.toFhirResource(obs)).thenReturn(observation);
    IBundleProvider results = fhirObservationService.searchForObservations(null, patientReference, null, null, null, null, null, null, null, null, null, null, null, null, null);
    assertThat(results, notNullValue());
    assertThat(results.size(), equalTo(1));
    assertThat(results.preferredPageSize(), equalTo(10));
    List<IBaseResource> resultList = results.getResources(1, 10);
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(equalTo(1)));
}
Also used : Obs(org.openmrs.Obs) Observation(org.hl7.fhir.r4.model.Observation) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 37 with SearchQueryInclude

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

the class FhirObservationServiceImplTest method getLastnObservations_shouldReturnRecentNObservations.

@Test
public void getLastnObservations_shouldReturnRecentNObservations() {
    Obs obs = new Obs();
    obs.setUuid(OBS_UUID);
    Observation observation = new Observation();
    observation.setId(OBS_UUID);
    NumberParam max = new NumberParam(2);
    ReferenceAndListParam referenceParam = new ReferenceAndListParam();
    ReferenceParam patient = new ReferenceParam();
    patient.setValue(PATIENT_UUID);
    referenceParam.addValue(new ReferenceOrListParam().add(patient));
    TokenAndListParam categories = new TokenAndListParam().addAnd(new TokenParam().setValue("laboratory"));
    TokenAndListParam code = new TokenAndListParam().addAnd(new TokenParam().setSystem(FhirTestConstants.LOINC_SYSTEM_URL).setValue(LOINC_SYSTOLIC_BP), new TokenParam().setSystem(FhirTestConstants.CIEL_SYSTEM_URN).setValue(CIEL_DIASTOLIC_BP));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, referenceParam).addParameter(FhirConstants.CODED_SEARCH_HANDLER, code).addParameter(FhirConstants.CATEGORY_SEARCH_HANDLER, categories).addParameter(FhirConstants.MAX_SEARCH_HANDLER, max).addParameter(FhirConstants.LASTN_OBSERVATION_SEARCH_HANDLER, new StringParam());
    when(globalPropertyService.getGlobalProperty(anyString(), anyInt())).thenReturn(10);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(OBS_UUID));
    when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(obs));
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(translator.toFhirResource(obs)).thenReturn(observation);
    IBundleProvider results = fhirObservationService.getLastnObservations(max, referenceParam, categories, code);
    assertThat(results, notNullValue());
    assertThat(results.size(), equalTo(1));
    assertThat(results.preferredPageSize(), equalTo(10));
    List<IBaseResource> resultList = results.getResources(1, 10);
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(equalTo(1)));
}
Also used : Obs(org.openmrs.Obs) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) NumberParam(ca.uhn.fhir.rest.param.NumberParam) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Observation(org.hl7.fhir.r4.model.Observation) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 38 with SearchQueryInclude

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

the class FhirPatientServiceImplTest method searchForPatients_shouldReturnEmptyCollectionWhenUUIDNotMatched.

@Test
public void searchForPatients_shouldReturnEmptyCollectionWhenUUIDNotMatched() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(WRONG_PATIENT_UUID));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.emptyList());
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, patientTranslator, globalPropertyService, searchQueryInclude));
    IBundleProvider results = patientService.searchForPatients(null, null, null, null, null, null, null, null, null, null, null, null, uuid, null, null, null);
    assertThat(results, notNullValue());
    assertThat(get(results), empty());
}
Also used : TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 39 with SearchQueryInclude

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

the class FhirPatientServiceImplTest method searchForPatients_shouldReturnEmptyCollectionWhenPatientGenderNotMatched.

@Test
public void searchForPatients_shouldReturnEmptyCollectionWhenPatientGenderNotMatched() {
    TokenAndListParam tokenAndListParam = new TokenAndListParam().addAnd(new TokenParam(WRONG_GENDER));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, tokenAndListParam);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.emptyList());
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, patientTranslator, globalPropertyService, searchQueryInclude));
    IBundleProvider results = patientService.searchForPatients(null, null, null, null, tokenAndListParam, null, null, null, null, null, null, null, null, null, null, null);
    assertThat(results, notNullValue());
    assertThat(get(results), is(empty()));
}
Also used : TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 40 with SearchQueryInclude

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

the class FhirPatientServiceImplTest method searchForPatients_shouldReturnEmptyCollectionWhenPatientDeathDateNotMatched.

@Test
public void searchForPatients_shouldReturnEmptyCollectionWhenPatientDeathDateNotMatched() {
    DateRangeParam dateRangeParam = new DateRangeParam().setLowerBound(UNKNOWN_DATE).setUpperBound(UNKNOWN_DATE);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, dateRangeParam);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.emptyList());
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, patientTranslator, globalPropertyService, searchQueryInclude));
    IBundleProvider results = patientService.searchForPatients(null, null, null, null, null, null, dateRangeParam, null, null, null, null, null, null, null, null, null);
    assertThat(results, notNullValue());
    assertThat(get(results), empty());
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) 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