Search in sources :

Example 66 with Task

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

the class TaskFhirResourceIntegrationTest method shouldCreateNewTaskAsXML.

@Test
public void shouldCreateNewTaskAsXML() throws Exception {
    String xmlTask;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_TASK_DOCUMENT)) {
        assertThat(is, notNullValue());
        xmlTask = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    MockHttpServletResponse response = post("/Task").accept(FhirMediaTypes.XML).xmlContent(xmlTask).go();
    assertThat(response, isCreated());
    assertThat(response.getHeader("Location"), containsString("/Task/"));
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Task task = readResponse(response);
    assertThat(task, notNullValue());
    assertThat(task.getIdElement().getIdPart(), notNullValue());
    assertThat(task.getStatus(), is(Task.TaskStatus.ACCEPTED));
    assertThat(task.getIntent(), is(Task.TaskIntent.ORDER));
    assertThat(task.getAuthoredOn(), within(1, ChronoUnit.MINUTES, new Date()));
    assertThat(task.getLastModified(), within(1, ChronoUnit.MINUTES, new Date()));
    assertThat(task, validResource());
    response = get("/Task/" + task.getIdElement().getIdPart()).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    Task newTask = readResponse(response);
    assertThat(newTask, notNullValue());
    assertThat(newTask.getIdElement().getIdPart(), equalTo(task.getIdElement().getIdPart()));
    assertThat(newTask.getStatus(), equalTo(task.getStatus()));
    assertThat(newTask.getIntent(), equalTo(task.getIntent()));
    assertThat(task.getAuthoredOn(), equalTo(task.getAuthoredOn()));
    assertThat(task.getLastModified(), equalTo(task.getLastModified()));
}
Also used : Task(org.hl7.fhir.r4.model.Task) InputStream(java.io.InputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Date(java.util.Date) Test(org.junit.Test)

Example 67 with Task

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

the class TaskFhirResourceIntegrationTest method shouldSearchForAllTasksAsJson.

@Test
public void shouldSearchForAllTasksAsJson() throws Exception {
    MockHttpServletResponse response = get("/Task").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/R4/Task/"))));
    assertThat(entries, everyItem(hasResource(instanceOf(Task.class))));
    assertThat(entries, everyItem(hasResource(validResource())));
}
Also used : Task(org.hl7.fhir.r4.model.Task) Bundle(org.hl7.fhir.r4.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 68 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.r4.model.Task) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 69 with Task

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

the class TaskFhirResourceIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchTaskIdAsXML.

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

Example 70 with Task

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

the class TaskFhirResourceIntegrationTest method shouldSearchForFilteredAndSortedTasksAsJson.

@Test
public void shouldSearchForFilteredAndSortedTasksAsJson() throws Exception {
    MockHttpServletResponse response = get("/Task?status=requested&_sort=_lastUpdated").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(), is(Bundle.BundleType.SEARCHSET));
    assertThat(results.hasEntry(), is(true));
    List<Bundle.BundleEntryComponent> entries = results.getEntry();
    assertThat(entries, hasSize(2));
    assertThat(entries, everyItem(hasResource(hasProperty("status", is(Task.TaskStatus.REQUESTED)))));
    assertThat(entries, containsInRelativeOrder(hasResource(hasProperty("meta", hasProperty("lastUpdated", equalTo(Date.from(LocalDateTime.of(2012, 5, 1, 0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))))), hasResource(hasProperty("meta", hasProperty("lastUpdated", equalTo(Date.from(LocalDateTime.of(2012, 7, 1, 0, 0, 0).atZone(ZoneId.systemDefault()).toInstant())))))));
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) 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