Search in sources :

Example 26 with TokenAndListParam

use of ca.uhn.fhir.rest.param.TokenAndListParam in project openmrs-module-fhir2 by openmrs.

the class AllergyIntoleranceSearchQueryTest method searchForAllergies_shouldHandleComplexQuery.

@Test
public void searchForAllergies_shouldHandleComplexQuery() {
    ReferenceAndListParam referenceParam = new ReferenceAndListParam();
    ReferenceParam allergyParam = new ReferenceParam();
    allergyParam.setValue(PATIENT_UUID);
    allergyParam.setChain(null);
    referenceParam.addValue(new ReferenceOrListParam().add(allergyParam));
    TokenAndListParam status = new TokenAndListParam();
    status.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(STATUS)));
    TokenAndListParam category = new TokenAndListParam();
    category.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(CATEGORY_ENVIRONMENT)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, referenceParam).addParameter(FhirConstants.BOOLEAN_SEARCH_HANDLER, status).addParameter(FhirConstants.CATEGORY_SEARCH_HANDLER, category);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
    assertThat(((AllergyIntolerance) resultList.iterator().next()).getClinicalStatus().getCodingFirstRep().getCode(), equalTo(STATUS));
    assertThat(((AllergyIntolerance) resultList.iterator().next()).getCategory().get(0).getValue(), equalTo(AllergyIntolerance.AllergyIntoleranceCategory.ENVIRONMENT));
    assertThat(((AllergyIntolerance) resultList.iterator().next()).getPatient().getReferenceElement().getIdPart(), equalTo(PATIENT_UUID));
}
Also used : TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) TokenParam(ca.uhn.fhir.rest.param.TokenParam) 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) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 27 with TokenAndListParam

use of ca.uhn.fhir.rest.param.TokenAndListParam in project openmrs-module-fhir2 by openmrs.

the class FhirMedicationServiceImplTest method searchForMedications_shouldSearchMedicationsByDosageForm.

@Test
public void searchForMedications_shouldSearchMedicationsByDosageForm() {
    List<Drug> medications = new ArrayList<>();
    medications.add(drug);
    TokenAndListParam dosageForm = new TokenAndListParam();
    dosageForm.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(CODE)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DOSAGE_FORM_SEARCH_HANDLER, dosageForm);
    when(medicationDao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(MEDICATION_UUID));
    when(medicationDao.getSearchResults(any(), any())).thenReturn(medications);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, medicationDao, medicationTranslator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(medicationTranslator.toFhirResource(drug)).thenReturn(medication);
    IBundleProvider result = fhirMedicationService.searchForMedications(null, dosageForm, null, null, null, null);
    List<IBaseResource> resultList = get(result);
    assertThat(result, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
Also used : Drug(org.openmrs.Drug) TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) TokenParam(ca.uhn.fhir.rest.param.TokenParam) ArrayList(java.util.ArrayList) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) 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 28 with TokenAndListParam

use of ca.uhn.fhir.rest.param.TokenAndListParam in project openmrs-module-fhir2 by openmrs.

the class FhirMedicationServiceImplTest method searchForMedications_shouldSearchMedicationsByUUID.

@Test
public void searchForMedications_shouldSearchMedicationsByUUID() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(MEDICATION_UUID));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid);
    when(medicationDao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(MEDICATION_UUID));
    when(medicationDao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(drug));
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, medicationDao, medicationTranslator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(medicationTranslator.toFhirResource(drug)).thenReturn(medication);
    IBundleProvider result = fhirMedicationService.searchForMedications(null, null, null, uuid, null, null);
    List<IBaseResource> resultList = get(result);
    assertThat(result, 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) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 29 with TokenAndListParam

use of ca.uhn.fhir.rest.param.TokenAndListParam in project openmrs-module-fhir2 by openmrs.

the class FhirObservationServiceImplTest method getLastnObservations_shouldReturnRecentNObservationsForAllPatientsWhenNoPatientIsSpecified.

@Test
public void getLastnObservations_shouldReturnRecentNObservationsForAllPatientsWhenNoPatientIsSpecified() {
    Obs obs = new Obs();
    obs.setUuid(OBS_UUID);
    Observation observation = new Observation();
    observation.setId(OBS_UUID);
    NumberParam max = new NumberParam(2);
    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.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, null, 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) 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) NumberParam(ca.uhn.fhir.rest.param.NumberParam) 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 30 with TokenAndListParam

use of ca.uhn.fhir.rest.param.TokenAndListParam 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)

Aggregations

TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)357 Test (org.junit.Test)347 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)340 TokenParam (ca.uhn.fhir.rest.param.TokenParam)312 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)260 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)247 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)211 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)119 HashSet (java.util.HashSet)79 Include (ca.uhn.fhir.model.api.Include)77 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)48 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)48 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)46 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)46 NumberParam (ca.uhn.fhir.rest.param.NumberParam)36 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)36 Observation (org.hl7.fhir.r4.model.Observation)24 StringParam (ca.uhn.fhir.rest.param.StringParam)21 MockIBundleProvider (org.openmrs.module.fhir2.providers.r4.MockIBundleProvider)21 ServiceRequest (org.hl7.fhir.r4.model.ServiceRequest)19