use of org.hl7.fhir.r4.model.Medication 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.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationRequestSearchQueryTest method searchForMedicationRequests_shouldHandleMultipleIncludes.
@Test
public void searchForMedicationRequests_shouldHandleMultipleIncludes() {
TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(MEDICATION_REQUEST_UUID));
HashSet<Include> includes = new HashSet<>();
includes.add(new Include("MedicationRequest:medication"));
includes.add(new Include("MedicationRequest:requester"));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
IBundleProvider results = search(theParams);
assertThat(results.size(), equalTo(1));
assertThat(results, notNullValue());
List<IBaseResource> resultList = results.getResources(0, 10);
assertThat(resultList, not(empty()));
// included resources (medication + requester) added as part of the result list
assertThat(resultList.size(), equalTo(3));
assertThat(((MedicationRequest) resultList.iterator().next()).getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID));
MedicationRequest returnedMedicationRequest = (MedicationRequest) resultList.iterator().next();
assertThat(resultList, hasItem(allOf(is(instanceOf(Medication.class)), hasProperty("id", equalTo((returnedMedicationRequest.getMedicationReference().getReferenceElement().getIdPart()))))));
assertThat(resultList, hasItem(allOf(is(instanceOf(Practitioner.class)), hasProperty("id", equalTo(returnedMedicationRequest.getRequester().getReferenceElement().getIdPart())))));
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationSearchQueryTest method searchForMedications_shouldHandleComplexQuery.
@Test
public void searchForMedications_shouldHandleComplexQuery() {
TokenAndListParam code = new TokenAndListParam();
code.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(CONCEPT_UUID)));
TokenAndListParam dosageForm = new TokenAndListParam();
dosageForm.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(DOSAGE_FORM_UUID)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CODED_SEARCH_HANDLER, code).addParameter(FhirConstants.DOSAGE_FORM_SEARCH_HANDLER, dosageForm);
IBundleProvider result = search(theParams);
assertThat(result, notNullValue());
assertThat(result.size(), greaterThanOrEqualTo(1));
List<Medication> resultList = get(result);
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
assertThat(resultList.get(0).getCode().getCodingFirstRep().getCode(), equalTo(CONCEPT_UUID));
assertThat(resultList.get(0).getForm().getCodingFirstRep().getCode(), equalTo(DOSAGE_FORM_UUID));
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationSearchQueryTest method searchForMedications_shouldSearchMedicationsByWrongIngredientCode.
@Test
public void searchForMedications_shouldSearchMedicationsByWrongIngredientCode() {
TokenAndListParam ingredientCode = new TokenAndListParam();
ingredientCode.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(WRONG_INGREDIENT_CODE_UUID)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.INGREDIENT_SEARCH_HANDLER, ingredientCode);
IBundleProvider result = search(theParams);
assertThat(result, notNullValue());
assertThat(result.size(), equalTo(0));
List<Medication> resultList = get(result);
assertThat(resultList, empty());
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationSearchQueryTest method searchForMedications_shouldSearchMedicationsByWrongCode.
@Test
public void searchForMedications_shouldSearchMedicationsByWrongCode() {
TokenAndListParam code = new TokenAndListParam();
code.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(WRONG_CONCEPT_UUID)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CODED_SEARCH_HANDLER, code);
IBundleProvider result = search(theParams);
List<Medication> resultList = get(result);
assertThat(result, notNullValue());
assertThat(resultList, empty());
}
Aggregations