use of org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskUpdateBundleFactory in project Gravity-SDOH-Exchange-RI by FHIR.
the class TaskService method update.
public void update(String id, UpdateTaskRequestDto update, UserDto user) {
Bundle taskBundle = getTask(id, Task.INCLUDE_FOCUS, Task.INCLUDE_OWNER, Organization.INCLUDE_ENDPOINT.setRecurse(true));
TaskUpdateInfoHolder updateInfo = new TaskUpdateBundleExtractor(id).extract(taskBundle);
Task task = updateInfo.getTask();
ServiceRequest serviceRequest = updateInfo.getServiceRequest();
TaskUpdateBundleFactory updateBundleFactory = new TaskUpdateBundleFactory();
updateBundleFactory.setTask(task);
updateBundleFactory.setServiceRequest(serviceRequest);
updateBundleFactory.setStatus(update.getFhirStatus());
updateBundleFactory.setStatusReason(update.getStatusReason());
updateBundleFactory.setComment(update.getComment());
updateBundleFactory.setUser(user);
ehrClient.transaction().withBundle(updateBundleFactory.createUpdateBundle()).execute();
try {
cpService.sync(task, serviceRequest, updateInfo.getEndpoint());
} catch (CpClientException exc) {
ehrClient.transaction().withBundle(new TaskFailBundleFactory(task, serviceRequest, exc.getMessage()).createFailBundle()).execute();
}
}
use of org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskUpdateBundleFactory in project Gravity-SDOH-Exchange-RI by FHIR.
the class TaskService method update.
public void update(String id, UpdateTaskRequestDto update) throws AuthClientException {
Server server = serverRepository.findById(update.getServerId()).orElseThrow(() -> new ServerNotFoundException(String.format("No server was found by id '%s'", update.getServerId())));
IGenericClient fhirClient = fhirContext.newRestfulGenericClient(server.getFhirServerUrl());
// Doesn't support now
// fhirClient.registerInterceptor(new BearerTokenAuthInterceptor(
// authorizationClient.getTokenResponse(URI.create(server.getAuthServerUrl()), server.getClientId(),
// server.getClientSecret(), SCOPE)
// .getAccessToken()));
TaskRepository taskRepository = new TaskRepository(fhirClient, applicationUrl);
// Validates and converts Procedure codes to Coding
List<Coding> procedureCodes = Optional.ofNullable(update.getProcedureCodes()).orElse(Collections.emptyList()).stream().map(code -> sdohMappings.findResourceCoding(Procedure.class, code)).collect(Collectors.toList());
Bundle taskBundle = taskRepository.find(id, Lists.newArrayList(Task.INCLUDE_FOCUS));
TaskInfoBundleExtractor.TaskInfoHolder taskInfo = new TaskInfoBundleExtractor().extract(taskBundle).stream().findFirst().orElseThrow(() -> new ResourceNotFoundException(new IdType(Task.class.getSimpleName(), id)));
TaskUpdateBundleFactory bundleFactory = new TaskUpdateBundleFactory();
bundleFactory.setTask(taskInfo.getTask());
bundleFactory.setStatus(update.getTaskStatus());
bundleFactory.setServiceRequest(taskInfo.getServiceRequest());
bundleFactory.setStatusReason(update.getStatusReason());
bundleFactory.setComment(update.getComment());
bundleFactory.setOutcome(update.getOutcome());
bundleFactory.setProcedureCodes(procedureCodes);
taskRepository.transaction(bundleFactory.createUpdateBundle());
}
Aggregations