Search in sources :

Example 1 with MedicationTranslator

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)));
}
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 2 with MedicationTranslator

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)));
}
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 3 with MedicationTranslator

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)));
}
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) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 4 with MedicationTranslator

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)));
}
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 5 with MedicationTranslator

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));
}
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) HashSet(java.util.HashSet) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Aggregations

IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)7 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)7 Test (org.junit.Test)7 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)7 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)4 TokenParam (ca.uhn.fhir.rest.param.TokenParam)4 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)3 ArrayList (java.util.ArrayList)3 Drug (org.openmrs.Drug)3 Include (ca.uhn.fhir.model.api.Include)2 HashSet (java.util.HashSet)2 SearchQueryInclude (org.openmrs.module.fhir2.api.search.SearchQueryInclude)2 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)1 MedicationRequest (org.hl7.fhir.r4.model.MedicationRequest)1