Search in sources :

Example 56 with Medication

use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.

the class AllergyIntoleranceFhirResourceProviderIntegrationTest method shouldCreateNewAllergyAsJson.

@Test
public void shouldCreateNewAllergyAsJson() throws Exception {
    // read JSON record
    String jsonAllergy;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_ALLERGY_DOCUMENT)) {
        Objects.requireNonNull(is);
        jsonAllergy = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    // create allergy
    MockHttpServletResponse response = post("/AllergyIntolerance").accept(FhirMediaTypes.JSON).jsonContent(jsonAllergy).go();
    // verify created correctly
    assertThat(response, isCreated());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    AllergyIntolerance allergy = readResponse(response);
    assertThat(allergy, notNullValue());
    assertThat(allergy.getPatient().getReferenceElement().getIdPart(), equalTo("da7f524f-27ce-4bb2-86d6-6d1d05312bd5"));
    assertThat(allergy.getRecorder().getReferenceElement().getIdPart(), equalTo("c98a1558-e131-11de-babe-001e378eb67e"));
    assertThat(allergy.getCategory().get(0).getValue().toCode(), equalTo("medication"));
    assertThat(allergy.getReactionFirstRep().getSeverity().toCode(), equalTo("severe"));
    assertThat(allergy.getReactionFirstRep().getManifestationFirstRep().getCodingFirstRep().getCode(), equalTo("5088AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
    assertThat(allergy.getReactionFirstRep().getManifestationFirstRep().getText(), equalTo("manifestation text"));
    assertThat(allergy.getCode().getCodingFirstRep().getCode(), equalTo("5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
    assertThat(allergy.getClinicalStatus().toCode(), equalTo("active"));
    assertThat(allergy.getVerificationStatus().toCode(), equalTo("confirmed"));
    assertThat(allergy.getType().toCode(), equalTo("allergy"));
    assertThat(allergy, validResource());
    // try to get new allergy
    response = get("/AllergyIntolerance/" + allergy.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    AllergyIntolerance newAllergy = readResponse(response);
    assertThat(newAllergy.getId(), equalTo(allergy.getId()));
}
Also used : AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance) InputStream(java.io.InputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 57 with Medication

use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.

the class MedicationFhirResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchMedicationIdAsXML.

@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchMedicationIdAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Medication/" + MEDICATION_UUID).accept(FhirMediaTypes.XML).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).xmlContent(toXML(medication)).accept(FhirMediaTypes.XML).go();
    assertThat(response, isBadRequest());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    OperationOutcome operationOutcome = readOperationOutcome(response);
    assertThat(operationOutcome, notNullValue());
    assertThat(operationOutcome.hasIssue(), is(true));
}
Also used : OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) Medication(org.hl7.fhir.r4.model.Medication) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 58 with Medication

use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.

the class MedicationFhirResourceProviderIntegrationTest method shouldReturnCountForMedicationAsXml.

@Test
public void shouldReturnCountForMedicationAsXml() throws Exception {
    MockHttpServletResponse response = get("/Medication?_summary=count").accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Bundle result = readBundleResponse(response);
    assertThat(result, notNullValue());
    assertThat(result.getType(), equalTo(Bundle.BundleType.SEARCHSET));
    assertThat(result, hasProperty("total", equalTo(4)));
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 59 with Medication

use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.

the class MedicationFhirResourceProviderIntegrationTest method shouldReturnExistingMedicationAsJson.

@Test
public void shouldReturnExistingMedicationAsJson() throws Exception {
    MockHttpServletResponse response = get("/Medication/" + MEDICATION_UUID).accept(BaseFhirIntegrationTest.FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(BaseFhirIntegrationTest.FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Medication medication = readResponse(response);
    assertThat(medication, notNullValue());
    assertThat(medication.getIdElement().getIdPart(), equalTo(MEDICATION_UUID));
    assertThat(medication, validResource());
}
Also used : Medication(org.hl7.fhir.r4.model.Medication) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 60 with Medication

use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.

the class MedicationFhirResourceProviderIntegrationTest method shouldReturnExistingMedicationAsXML.

@Test
public void shouldReturnExistingMedicationAsXML() throws Exception {
    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.getIdElement().getIdPart(), equalTo(MEDICATION_UUID));
    assertThat(medication, validResource());
}
Also used : Medication(org.hl7.fhir.r4.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