use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class EncounterSearchQueryTest method searchForEncounters_shouldHandleMultipleReverseIncludes.
@Test
public void searchForEncounters_shouldHandleMultipleReverseIncludes() {
TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(ENCOUNTER_UUID));
HashSet<Include> revIncludes = new HashSet<>();
revIncludes.add(new Include("ServiceRequest:encounter"));
revIncludes.add(new Include("MedicationRequest:encounter"));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.REVERSE_INCLUDE_SEARCH_HANDLER, revIncludes);
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
assertThat(results.size(), equalTo(1));
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
// reverse included resources (8 medication request + 3 service request) added as part of the result list
assertThat(resultList.size(), equalTo(12));
assertThat(resultList.subList(1, 12), everyItem(allOf(anyOf(is(instanceOf(MedicationRequest.class)), is(instanceOf(ServiceRequest.class))), hasProperty("encounter", hasProperty("referenceElement", hasProperty("idPart", equalTo(ENCOUNTER_UUID)))))));
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class FhirMedicationServiceImplTest method setup.
@Before
public void setup() {
fhirMedicationService = new FhirMedicationServiceImpl() {
@Override
protected void validateObject(Drug object) {
}
};
fhirMedicationService.setTranslator(medicationTranslator);
fhirMedicationService.setDao(medicationDao);
fhirMedicationService.setSearchQuery(searchQuery);
fhirMedicationService.setSearchQueryInclude(searchQueryInclude);
medication = new Medication();
medication.setId(MEDICATION_UUID);
drug = new Drug();
drug.setUuid(MEDICATION_UUID);
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class FhirMedicationServiceImplTest method updateMedication_shouldThrowInvalidRequestException.
@Test(expected = InvalidRequestException.class)
public void updateMedication_shouldThrowInvalidRequestException() {
Medication medication = new Medication();
medication.setId(MEDICATION_UUID);
fhirMedicationService.update(WRONG_MEDICATION_UUID, medication);
}
use of org.hl7.fhir.r4.model.Medication 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.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class FhirMedicationServiceImplTest method getMedicationByUuid_shouldGetMedicationByUuid.
@Test
public void getMedicationByUuid_shouldGetMedicationByUuid() {
when(medicationDao.get(MEDICATION_UUID)).thenReturn(drug);
when(medicationTranslator.toFhirResource(drug)).thenReturn(medication);
Medication medication = fhirMedicationService.get(MEDICATION_UUID);
assertThat(medication, notNullValue());
assertThat(medication.getId(), notNullValue());
assertThat(medication.getId(), equalTo(MEDICATION_UUID));
}
Aggregations