use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.
the class TaskTranslatorImpl method toFhirResource.
@Override
public Task toFhirResource(@Nonnull FhirTask openmrsTask) {
notNull(openmrsTask, "The openmrsTask object should not be null");
Task fhirTask = new Task();
setFhirTaskFields(openmrsTask, fhirTask);
fhirTask.addContained(provenanceTranslator.getCreateProvenance(openmrsTask));
fhirTask.addContained(provenanceTranslator.getUpdateProvenance(openmrsTask));
return fhirTask;
}
use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.
the class BaseServiceRequestTranslator method determineServiceRequestPerformer.
protected Reference determineServiceRequestPerformer(String orderUuid) {
IBundleProvider results = taskService.searchForTasks(new ReferenceAndListParam().addAnd(new ReferenceOrListParam().add(new ReferenceParam("ServiceRequest", null, orderUuid))), null, null, null, null, null, null);
Collection<Task> serviceRequestTasks = results.getResources(START_INDEX, END_INDEX).stream().map(p -> (Task) p).collect(Collectors.toList());
if (serviceRequestTasks.size() != 1) {
return null;
}
return serviceRequestTasks.iterator().next().getOwner();
}
use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.
the class TaskFhirResourceProviderWebTest method updateTask_shouldErrorForNonexistentTask.
@Test
public void updateTask_shouldErrorForNonexistentTask() throws Exception {
String jsonTask;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_TASK_WRONG_ID_PATH)) {
Objects.requireNonNull(is);
jsonTask = IOUtils.toString(is, StandardCharsets.UTF_8);
}
when(service.update(eq(WRONG_TASK_UUID), any(org.hl7.fhir.r4.model.Task.class))).thenThrow(new MethodNotAllowedException("Can't find Task"));
MockHttpServletResponse response = put("/Task/" + WRONG_TASK_UUID).jsonContent(jsonTask).accept(FhirMediaTypes.JSON).go();
assertThat(response, isMethodNotAllowed());
}
use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.
the class TaskFhirResourceProviderWebTest method updateTask_shouldUpdateExistingTask.
@Test
public void updateTask_shouldUpdateExistingTask() throws Exception {
String jsonTask;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_TASK_PATH)) {
Objects.requireNonNull(is);
jsonTask = IOUtils.toString(is, StandardCharsets.UTF_8);
}
when(service.update(anyString(), any(org.hl7.fhir.r4.model.Task.class))).thenReturn(task);
MockHttpServletResponse response = put("/Task/" + TASK_UUID).jsonContent(jsonTask).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
}
use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.
the class TaskFhirResourceProviderWebTest method deleteTask_shouldDeleteTask.
@Test
public void deleteTask_shouldDeleteTask() throws Exception {
Task task = new Task();
task.setId(TASK_UUID);
task.setStatus(Task.TaskStatus.ACCEPTED);
when(service.delete(any(String.class))).thenReturn(TaskVersionConverter.convertTask(task));
MockHttpServletResponse response = delete("/Task/" + TASK_UUID).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
}
Aggregations