use of org.openmrs.module.fhir2.api.translators.MedicationTranslator 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)));
}
use of org.openmrs.module.fhir2.api.translators.MedicationTranslator 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)));
}
use of org.openmrs.module.fhir2.api.translators.MedicationTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirMedicationServiceImplTest method searchForMedications_shouldSearchMedicationsByLastUpdated.
@Test
public void searchForMedications_shouldSearchMedicationsByLastUpdated() {
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(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, null, lastUpdated, null);
List<IBaseResource> resultList = get(result);
assertThat(result, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
use of org.openmrs.module.fhir2.api.translators.MedicationTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirMedicationServiceImplTest method searchForMedications_shouldSearchMedicationsByCode.
@Test
public void searchForMedications_shouldSearchMedicationsByCode() {
List<Drug> medications = new ArrayList<>();
medications.add(drug);
TokenAndListParam code = new TokenAndListParam();
code.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(CODE)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CODED_SEARCH_HANDLER, code);
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(code, null, null, null, null, null);
List<IBaseResource> resultList = get(result);
assertThat(result, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
use of org.openmrs.module.fhir2.api.translators.MedicationTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirMedicationServiceImplTest method searchForMedications_shouldNotAddRelatedResourcesToResultListForEmptyRevInclude.
@Test
public void searchForMedications_shouldNotAddRelatedResourcesToResultListForEmptyRevInclude() {
HashSet<Include> revIncludes = new HashSet<>();
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.REVERSE_INCLUDE_SEARCH_HANDLER, revIncludes);
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 results = fhirMedicationService.searchForMedications(null, null, null, null, null, revIncludes);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList.size(), greaterThanOrEqualTo(1));
}
Aggregations