use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderWebTest method updateMedication_shouldUpdateRequestedMedication.
@Test
public void updateMedication_shouldUpdateRequestedMedication() throws Exception {
org.hl7.fhir.r4.model.Medication medication = new org.hl7.fhir.r4.model.Medication();
medication.setId(MEDICATION_UUID);
medication.setStatus(org.hl7.fhir.r4.model.Medication.MedicationStatus.INACTIVE);
String medicationJson;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_UPDATE_MEDICATION_PATH)) {
Objects.requireNonNull(is);
medicationJson = IOUtils.toString(is, StandardCharsets.UTF_8);
}
when(fhirMedicationService.update(any(String.class), any(org.hl7.fhir.r4.model.Medication.class))).thenReturn(medication);
MockHttpServletResponse response = put("/Medication/" + MEDICATION_UUID).jsonContent(medicationJson).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderWebTest method getMedicationByUuid_shouldReturnMedication.
@Test
public void getMedicationByUuid_shouldReturnMedication() throws Exception {
org.hl7.fhir.r4.model.Medication medication = new org.hl7.fhir.r4.model.Medication();
medication.setId(MEDICATION_UUID);
when(fhirMedicationService.get(MEDICATION_UUID)).thenReturn(medication);
MockHttpServletResponse response = get("/Medication/" + MEDICATION_UUID).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
assertThat(readResponse(response).getIdElement().getIdPart(), equalTo(MEDICATION_UUID));
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderWebTest method createMedication_shouldCreateNewMedication.
@Test
public void createMedication_shouldCreateNewMedication() throws Exception {
Medication medication = new Medication();
medication.setId(MEDICATION_UUID);
String medicationJson;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_MEDICATION_PATH)) {
Objects.requireNonNull(is);
medicationJson = IOUtils.toString(is, StandardCharsets.UTF_8);
}
when(fhirMedicationService.create(any(Medication.class))).thenReturn(medication);
MockHttpServletResponse response = post("/Medication").jsonContent(medicationJson).accept(FhirMediaTypes.JSON).go();
assertThat(response, isCreated());
assertThat(response.getStatus(), is(201));
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderWebTest method getMedicationByUuid_shouldReturnMedication.
@Test
public void getMedicationByUuid_shouldReturnMedication() throws Exception {
Medication medication = new Medication();
medication.setId(MEDICATION_UUID);
when(fhirMedicationService.get(MEDICATION_UUID)).thenReturn(medication);
MockHttpServletResponse response = get("/Medication/" + MEDICATION_UUID).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
assertThat(readResponse(response).getIdElement().getIdPart(), equalTo(MEDICATION_UUID));
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderWebTest method updateMedication_shouldUpdateRequestedMedication.
@Test
public void updateMedication_shouldUpdateRequestedMedication() throws Exception {
Medication medication = new Medication();
medication.setId(MEDICATION_UUID);
medication.setStatus(Medication.MedicationStatus.INACTIVE);
String medicationJson;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_UPDATE_MEDICATION_PATH)) {
assert is != null;
Objects.requireNonNull(is);
medicationJson = IOUtils.toString(is, StandardCharsets.UTF_8);
}
when(fhirMedicationService.update(any(String.class), any(Medication.class))).thenReturn(medication);
MockHttpServletResponse response = put("/Medication/" + MEDICATION_UUID).jsonContent(medicationJson).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
}
Aggregations