Search in sources :

Example 41 with Medication

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

Example 42 with Medication

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

Example 43 with Medication

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

Example 44 with Medication

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));
}
Also used : Medication(org.hl7.fhir.r4.model.Medication) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 45 with Medication

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

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