Search in sources :

Example 61 with Task

use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.

the class TaskFhirResourceIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentTaskAsJson.

@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentTaskAsJson() throws Exception {
    MockHttpServletResponse response = get("/Task/" + TASK_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    Task patient = readResponse(response);
    patient.setId(WRONG_TASK_UUID);
    response = put("/Task/" + WRONG_TASK_UUID).jsonContent(toJson(patient)).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 : Task(org.hl7.fhir.dstu3.model.Task) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 62 with Task

use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.

the class TaskFhirResourceIntegrationTest method shouldReturnCountForTaskAsJson.

@Test
public void shouldReturnCountForTaskAsJson() throws Exception {
    MockHttpServletResponse response = get("/Task?status=requested&_summary=count").accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Bundle result = readBundleResponse(response);
    assertThat(result, notNullValue());
    assertThat(result.getType(), equalTo(Bundle.BundleType.SEARCHSET));
    assertThat(result, hasProperty("total", equalTo(2)));
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 63 with Task

use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.

the class TaskFhirResourceIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentTaskAsXML.

@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentTaskAsXML() throws Exception {
    MockHttpServletResponse response = get("/Task/" + TASK_UUID).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    Task patient = readResponse(response);
    patient.setId(WRONG_TASK_UUID);
    response = put("/Task/" + WRONG_TASK_UUID).xmlContent(toXML(patient)).accept(FhirMediaTypes.XML).go();
    assertThat(response, isNotFound());
    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 : Task(org.hl7.fhir.dstu3.model.Task) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 64 with Task

use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.

the class TaskFhirResourceIntegrationTest method shouldUpdateExistingTaskAsXML.

@Test
public void shouldUpdateExistingTaskAsXML() throws Exception {
    MockHttpServletResponse response = get("/Task/" + TASK_UUID).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    Task task = readResponse(response);
    assertThat(task.getStatus(), is(Task.TaskStatus.ACCEPTED));
    task.setStatus(Task.TaskStatus.COMPLETED);
    response = put("/Task/" + TASK_UUID).xmlContent(toXML(task)).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Task updatedTask = readResponse(response);
    assertThat(updatedTask, notNullValue());
    assertThat(updatedTask.getIdElement().getIdPart(), equalTo(TASK_UUID));
    assertThat(updatedTask.getStatus(), is(Task.TaskStatus.COMPLETED));
    assertThat(updatedTask, validResource());
    response = get("/Task/" + TASK_UUID).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    Task reReadTask = readResponse(response);
    assertThat(reReadTask.getStatus(), is(Task.TaskStatus.COMPLETED));
}
Also used : Task(org.hl7.fhir.dstu3.model.Task) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 65 with Task

use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.

the class TaskFhirResourceIntegrationTest method shouldReturnNotFoundWhenTaskNotFoundAsJson.

@Test
public void shouldReturnNotFoundWhenTaskNotFoundAsJson() throws Exception {
    MockHttpServletResponse response = get("/Task/" + WRONG_TASK_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)

Aggregations

Test (org.junit.Test)127 Task (org.hl7.fhir.r4.model.Task)120 FhirTask (org.openmrs.module.fhir2.model.FhirTask)59 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)46 Bundle (org.hl7.fhir.r4.model.Bundle)40 Reference (org.hl7.fhir.r4.model.Reference)28 ServiceRequest (org.hl7.fhir.r4.model.ServiceRequest)24 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)23 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)22 Task (org.hl7.fhir.dstu3.model.Task)21 IdType (org.hl7.fhir.r4.model.IdType)21 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)17 Date (java.util.Date)16 ArrayList (java.util.ArrayList)13 List (java.util.List)13 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)13 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)12 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)11 TokenParam (ca.uhn.fhir.rest.param.TokenParam)11 Collectors (java.util.stream.Collectors)11