use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderTest method updateMedication_shouldUpdateRequestedMedication.
@Test
public void updateMedication_shouldUpdateRequestedMedication() {
Medication med = medication;
med.setStatus(Medication.MedicationStatus.INACTIVE);
when(fhirMedicationService.update(MEDICATION_UUID, medication)).thenReturn(med);
MethodOutcome result = resourceProvider.updateMedication(new IdType().setValue(MEDICATION_UUID), medication);
assertThat(result, notNullValue());
assertThat(result.getResource(), equalTo(med));
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderTest method searchForMedication_shouldReturnMatchingBundleOfMedicationByUUID.
@Test
public void searchForMedication_shouldReturnMatchingBundleOfMedicationByUUID() {
TokenAndListParam uuid = new TokenAndListParam();
uuid.addAnd(new TokenParam().setValue(MEDICATION_UUID));
when(fhirMedicationService.searchForMedications(isNull(), isNull(), isNull(), argThat(is(uuid)), isNull(), isNull())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medication), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchForMedication(null, null, null, uuid, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
assertThat(resultList.iterator().next().fhirType(), equalTo(FhirConstants.MEDICATION));
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderTest method searchForMedication_shouldNotAddResourcesForEmptyRevInclude.
@Test
public void searchForMedication_shouldNotAddResourcesForEmptyRevInclude() {
when(fhirMedicationService.searchForMedications(any(), any(), any(), any(), any(), isNull())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medication), PREFERRED_PAGE_SIZE, COUNT));
HashSet<Include> revIncludes = new HashSet<>();
IBundleProvider results = resourceProvider.searchForMedication(null, null, null, null, null, revIncludes);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList.size(), equalTo(1));
assertThat(resultList.get(0).fhirType(), equalTo(FhirConstants.MEDICATION));
assertThat(((Medication) resultList.iterator().next()).getId(), equalTo(MEDICATION_UUID));
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderTest method getMedicationByUuid_shouldReturnMatchingMedication.
@Test
public void getMedicationByUuid_shouldReturnMatchingMedication() {
when(fhirMedicationService.get(MEDICATION_UUID)).thenReturn(medication);
IdType id = new IdType();
id.setValue(MEDICATION_UUID);
Medication medication = resourceProvider.getMedicationById(id);
assertThat(medication, notNullValue());
assertThat(medication.getId(), notNullValue());
assertThat(medication.getId(), equalTo(MEDICATION_UUID));
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderTest method searchForMedication_shouldReturnMatchingBundleOfMedicationByIngredientCode.
@Test
public void searchForMedication_shouldReturnMatchingBundleOfMedicationByIngredientCode() {
TokenAndListParam ingredientCode = new TokenAndListParam();
ingredientCode.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(CODE)));
when(fhirMedicationService.searchForMedications(isNull(), isNull(), argThat(is(ingredientCode)), isNull(), isNull(), isNull())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medication), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchForMedication(null, null, ingredientCode, null, null, null);
List<Medication> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
assertThat(resultList.get(0).fhirType(), equalTo(FhirConstants.MEDICATION));
}
Aggregations