use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchMedicationIdAsJson.
@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchMedicationIdAsJson() throws Exception {
// get the existing record
MockHttpServletResponse response = get("/Medication/" + MEDICATION_UUID).accept(FhirMediaTypes.JSON).go();
Medication medication = readResponse(response);
// update the existing record
medication.setId(WRONG_MEDICATION_UUID);
// send the update to the server
response = put("/Medication/" + MEDICATION_UUID).jsonContent(toJson(medication)).accept(FhirMediaTypes.JSON).go();
assertThat(response, isBadRequest());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
OperationOutcome operationOutcome = readOperationOutcome(response);
assertThat(operationOutcome, notNullValue());
assertThat(operationOutcome.hasIssue(), is(true));
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderIntegrationTest method shouldUpdateExistingMedicationAsXml.
@Test
public void shouldUpdateExistingMedicationAsXml() throws Exception {
// Before update
MockHttpServletResponse response = get("/Medication/" + MEDICATION_UUID).accept(BaseFhirIntegrationTest.FhirMediaTypes.XML).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(BaseFhirIntegrationTest.FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
Medication medication = readResponse(response);
assertThat(medication, notNullValue());
assertThat(medication, validResource());
assertThat(medication.getIdElement().getIdPart(), equalTo(MEDICATION_UUID));
assertThat(getStrengthExtensionValue(medication), equalTo("200mg"));
// Get existing medication with updated medication strength
String xmlMedication;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_UPDATE_MEDICATION_DOCUMENT)) {
Objects.requireNonNull(is);
xmlMedication = IOUtils.toString(is, StandardCharsets.UTF_8);
}
// Update
response = put("/Medication/" + MEDICATION_UUID).xmlContent(xmlMedication).accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
// read updated record
medication = readResponse(response);
assertThat(medication, notNullValue());
assertThat(medication.getIdElement().getIdPart(), equalTo(MEDICATION_UUID));
assertThat(medication.getStatus(), is(Medication.MedicationStatus.ACTIVE));
assertThat(getStrengthExtensionValue(medication), equalTo("800mg"));
assertThat(medication, validResource());
// Double-check via get
response = get("/Medication/" + MEDICATION_UUID).accept(FhirMediaTypes.XML).go();
Medication updatedMedication = readResponse(response);
assertThat(updatedMedication, validResource());
assertThat(updatedMedication, notNullValue());
assertThat(updatedMedication.getStatus(), is(Medication.MedicationStatus.ACTIVE));
assertThat(getStrengthExtensionValue(updatedMedication), equalTo("800mg"));
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderIntegrationTest method shouldSearchForExistingMedicationsAsXml.
@Test
public void shouldSearchForExistingMedicationsAsXml() throws Exception {
MockHttpServletResponse response = get("/Medication").accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
Bundle results = readBundleResponse(response);
assertThat(results, notNullValue());
assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET));
assertThat(results.hasEntry(), is(true));
List<Bundle.BundleEntryComponent> entries = results.getEntry();
assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R3/Medication/"))));
assertThat(entries, everyItem(hasResource(instanceOf(Medication.class))));
assertThat(entries, everyItem(hasResource(validResource())));
response = get(String.format("/Medication?_id=%s", MEDICATION_UUID)).accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
results = readBundleResponse(response);
assertThat(results, notNullValue());
assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET));
assertThat(results.hasEntry(), is(true));
entries = results.getEntry();
assertThat(entries, everyItem(hasResource(hasProperty("id", is("http://localhost/ws/fhir2/R3/Medication/1085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")))));
assertThat(entries, everyItem(hasResource(validResource())));
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenDeletingNonExistentMedication.
@Test
public void shouldReturnNotFoundWhenDeletingNonExistentMedication() throws Exception {
MockHttpServletResponse response = delete("/Medication/" + WRONG_MEDICATION_UUID).accept(FhirMediaTypes.JSON).go();
assertThat(response, isNotFound());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
OperationOutcome operationOutcome = readOperationOutcome(response);
assertThat(operationOutcome, notNullValue());
assertThat(operationOutcome.hasIssue(), is(true));
}
use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.
the class MedicationFhirResourceProviderIntegrationTest method shouldSearchForExistingMedicationsAsJson.
@Test
public void shouldSearchForExistingMedicationsAsJson() throws Exception {
MockHttpServletResponse response = get("/Medication").accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
Bundle results = readBundleResponse(response);
assertThat(results, notNullValue());
assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET));
assertThat(results.hasEntry(), is(true));
List<Bundle.BundleEntryComponent> entries = results.getEntry();
assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R3/Medication/"))));
assertThat(entries, everyItem(hasResource(instanceOf(Medication.class))));
assertThat(entries, everyItem(hasResource(validResource())));
response = get(String.format("/Medication?_id=%s", MEDICATION_UUID)).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
results = readBundleResponse(response);
assertThat(results, notNullValue());
assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET));
assertThat(results.hasEntry(), is(true));
entries = results.getEntry();
assertThat(entries, everyItem(hasResource(hasProperty("id", is("http://localhost/ws/fhir2/R3/Medication/1085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")))));
assertThat(entries, everyItem(hasResource(validResource())));
}
Aggregations