use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.
the class TaskFhirResourceProviderTest method searchTasks_shouldAddRelatedServiceRequestResourceToResultListWhenIncluded.
@Test
public void searchTasks_shouldAddRelatedServiceRequestResourceToResultListWhenIncluded() {
HashSet<Include> includes = new HashSet<>();
includes.add(new Include("Task:based-on"));
when(taskService.searchForTasks(any(), any(), any(), any(), any(), any(), argThat(is(includes)))).thenReturn(new MockIBundleProvider<>(Arrays.asList(task, new ServiceRequest()), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchTasks(null, null, null, null, null, null, includes);
List<IBaseResource> resources = getResources(results);
assertThat(results, notNullValue());
assertThat(resources, hasSize(Matchers.equalTo(2)));
assertThat(resources.get(0), notNullValue());
assertThat(resources.get(0).fhirType(), Matchers.equalTo(FhirConstants.TASK));
assertThat(resources.get(1).fhirType(), Matchers.equalTo(FhirConstants.SERVICE_REQUEST));
assertThat(resources.get(0).getIdElement().getIdPart(), Matchers.equalTo(TASK_UUID));
}
use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.
the class TaskFhirResourceIntegrationTest method shouldCreateNewTaskAsJson.
@Test
public void shouldCreateNewTaskAsJson() throws Exception {
String jsonTask;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_TASK_DOCUMENT)) {
assertThat(is, notNullValue());
jsonTask = IOUtils.toString(is, StandardCharsets.UTF_8);
}
MockHttpServletResponse response = post("/Task").accept(FhirMediaTypes.JSON).jsonContent(jsonTask).go();
assertThat(response, isCreated());
assertThat(response.getHeader("Location"), containsString("/Task/"));
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.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.JSON).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()));
}
use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.
the class TaskFhirResourceIntegrationTest method shouldReturnExistingTaskAsXML.
@Test
public void shouldReturnExistingTaskAsXML() throws Exception {
MockHttpServletResponse response = get("/Task/" + TASK_UUID).accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
Task task = readResponse(response);
assertThat(task, notNullValue());
assertThat(task.getIdElement().getIdPart(), equalTo(TASK_UUID));
assertThat(task.getStatus(), is(Task.TaskStatus.ACCEPTED));
assertThat(task.getIntent(), is(Task.TaskIntent.ORDER));
assertThat(task, validResource());
}
use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.
the class TaskFhirResourceIntegrationTest method shouldUpdateExistingTaskAsJson.
@Test
public void shouldUpdateExistingTaskAsJson() throws Exception {
MockHttpServletResponse response = get("/Task/" + TASK_UUID).accept(FhirMediaTypes.JSON).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).jsonContent(toJson(task)).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.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.JSON).go();
assertThat(response, isOk());
Task reReadTask = readResponse(response);
assertThat(reReadTask.getStatus(), is(Task.TaskStatus.COMPLETED));
}
use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.
the class TaskFhirResourceIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchTaskIdAsJson.
@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchTaskIdAsJson() throws Exception {
MockHttpServletResponse response = get("/Task/" + TASK_UUID).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
Task task = readResponse(response);
task.setId(WRONG_TASK_UUID);
response = put("/Task/" + TASK_UUID).jsonContent(toJson(task)).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));
}
Aggregations