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));
}
use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.
the class TaskFhirResourceIntegrationTest method shouldSearchForAllTasksAsXML.
@Test
public void shouldSearchForAllTasksAsXML() throws Exception {
MockHttpServletResponse response = get("/Task").accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.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())));
}
use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.
the class TaskFhirResourceIntegrationTest method shouldReturnCountForTaskAsXml.
@Test
public void shouldReturnCountForTaskAsXml() throws Exception {
MockHttpServletResponse response = get("/Task?status=requested&_summary=count").accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.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)));
}
use of org.hl7.fhir.r5.model.Task in project Gravity-SDOH-Exchange-RI by FHIR.
the class TaskPollingService method updateTasks.
public void updateTasks() {
log.info("Updating tasks from CP Organizations...");
Bundle tasksBundle = openEhrClient.search().forResource(Task.class).include(Task.INCLUDE_FOCUS).include(Task.INCLUDE_OWNER).include(Organization.INCLUDE_ENDPOINT.setRecurse(true)).where(new TokenClientParam("owner:Organization.type").exactly().systemAndCode(OrganizationTypeCode.CP.getSystem(), OrganizationTypeCode.CP.toCode())).where(new TokenClientParam(Task.SP_STATUS + ":" + SearchModifierCode.NOT.toCode()).exactly().code(Task.TaskStatus.FAILED.toCode())).where(new TokenClientParam(Task.SP_STATUS + ":" + SearchModifierCode.NOT.toCode()).exactly().code(Task.TaskStatus.REJECTED.toCode())).where(new TokenClientParam(Task.SP_STATUS + ":" + SearchModifierCode.NOT.toCode()).exactly().code(Task.TaskStatus.COMPLETED.toCode())).where(new TokenClientParam(Task.SP_STATUS + ":" + SearchModifierCode.NOT.toCode()).exactly().code(Task.TaskStatus.CANCELLED.toCode())).where(Task.AUTHORED_ON.before().millis(Date.from(LocalDateTime.now().minusSeconds(10).atZone(ZoneId.systemDefault()).toInstant()))).returnBundle(Bundle.class).execute();
TasksPollingInfo tasksPollingInfo = new TasksPollingBundleExtractor().extract(tasksBundle);
// Collect all entries from every Task bundle for performance considerations.
Bundle updateBundle = new Bundle();
updateBundle.setType(Bundle.BundleType.TRANSACTION);
for (Task task : tasksPollingInfo.getTasks()) {
ServiceRequest serviceRequest = tasksPollingInfo.getServiceRequest(task);
Organization organization = tasksPollingInfo.getOrganization(task);
try {
Endpoint endpoint = tasksPollingInfo.getEndpoint(organization);
combineResult(updateBundle, getUpdateBundle(task, serviceRequest, endpoint));
} catch (TaskPollingUpdateException | CpClientException exc) {
combineResult(updateBundle, failTask(task, serviceRequest, exc.getMessage()));
}
}
// If there is at least one bundle entry - execute a transaction request.
if (updateBundle.getEntry().size() != 0) {
log.info("One or more tasks were changed. Storing updates to EHR...");
openEhrClient.transaction().withBundle(updateBundle).execute();
}
log.info("Task update process finished.");
}
use of org.hl7.fhir.r5.model.Task in project Gravity-SDOH-Exchange-RI by FHIR.
the class TaskPollingService method copyTaskFields.
protected void copyTaskFields(Task ehrTask, Task cpTask, Endpoint endpoint) {
ehrTask.setStatus(cpTask.getStatus());
ehrTask.setStatusReason(cpTask.getStatusReason());
ehrTask.setLastModified(cpTask.getLastModified());
int ehrNotesSize = ehrTask.getNote().size();
int cpNotesSize = cpTask.getNote().size();
if (ehrNotesSize < cpNotesSize) {
cpTask.getNote().subList(ehrNotesSize, cpNotesSize).stream().filter(cpComment -> cpComment.getAuthor() instanceof Reference).forEach(cpComment -> {
cpService.externalizeReference(cpComment.getAuthorReference(), endpoint.getAddress());
ehrTask.addNote(cpComment);
});
}
}
Aggregations