Search in sources :

Example 51 with Medication

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));
}
Also used : OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) Medication(org.hl7.fhir.dstu3.model.Medication) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 52 with Medication

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"));
}
Also used : InputStream(java.io.InputStream) Medication(org.hl7.fhir.dstu3.model.Medication) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 53 with Medication

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())));
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) Medication(org.hl7.fhir.dstu3.model.Medication) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 54 with Medication

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));
}
Also used : OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 55 with Medication

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())));
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) Medication(org.hl7.fhir.dstu3.model.Medication) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Aggregations

Test (org.junit.Test)112 Medication (org.hl7.fhir.r4.model.Medication)62 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)43 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)34 Medication (org.hl7.fhir.dstu3.model.Medication)33 BaseFhirIntegrationTest (org.openmrs.module.fhir2.BaseFhirIntegrationTest)30 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)24 TokenParam (ca.uhn.fhir.rest.param.TokenParam)24 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)20 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)20 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)19 MedicationRequest (org.hl7.fhir.r4.model.MedicationRequest)18 InputStream (java.io.InputStream)17 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)16 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)14 Coding (org.hl7.fhir.r4.model.Coding)14 Date (java.util.Date)13 ArrayList (java.util.ArrayList)12 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)12 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)11