use of org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor in project Gravity-SDOH-Exchange-RI by FHIR.
the class OurTaskService method update.
public void update(String id, UpdateOurTaskRequestDto update, UserDto user) {
Bundle taskBundle = taskRepository.find(id, Lists.newArrayList(Task.INCLUDE_FOCUS));
TaskInfoHolder taskInfo = new TaskInfoBundleExtractor().extract(taskBundle).stream().findFirst().orElseThrow(() -> new ResourceNotFoundException(new IdType(Task.class.getSimpleName(), id)));
OurTaskUpdateBundleFactory bundleFactory = new OurTaskUpdateBundleFactory();
bundleFactory.setTask(taskInfo.getTask());
bundleFactory.setServiceRequest(taskInfo.getServiceRequest());
bundleFactory.setStatus(update.getTaskStatus());
bundleFactory.setStatusReason(update.getStatusReason());
bundleFactory.setComment(update.getComment());
bundleFactory.setUser(user);
taskRepository.transaction(bundleFactory.createUpdateBundle());
}
use of org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor in project Gravity-SDOH-Exchange-RI by FHIR.
the class CpService method read.
public TaskInfoHolder read(final String id, final Endpoint endpoint) throws CpClientException {
try {
Bundle taskBundle = cpClient(endpoint).search().forResource(Task.class).where(Task.IDENTIFIER.exactly().systemAndValues(identifierSystem, id)).include(Task.INCLUDE_FOCUS).returnBundle(Bundle.class).execute();
// Additional validation
int tasksSize = FhirUtil.getFromBundle(taskBundle, Task.class).size();
if (tasksSize == 0) {
throw new CpClientException(String.format("No Task is present at '%s' for identifier '%s'.", endpoint.getAddress(), identifierSystem + "|" + id));
} else if (tasksSize > 1) {
throw new CpClientException(String.format("More than one Task is present at '%s' for identifier '%s'.", endpoint.getAddress(), identifierSystem + "|" + id));
}
return new TaskInfoBundleExtractor().extract(taskBundle).stream().findFirst().get();
} catch (BaseServerResponseException exc) {
throw new CpClientException(String.format("Task retrieval failed for identifier '%s' at CP location '%s'. Reason: %s.", identifierSystem + "|" + id, endpoint.getAddress(), exc.getMessage()), exc);
}
}
use of org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor in project Gravity-SDOH-Exchange-RI by FHIR.
the class TaskService method sync.
public void sync(Task task, final ServiceRequest serviceRequest) {
Bundle ourUpdateBundle = new Bundle();
ourUpdateBundle.setType(Bundle.BundleType.TRANSACTION);
Bundle ourTaskBundle = taskRepository.findOurTask(task);
TaskInfoHolder ourTaskInfo = new TaskInfoBundleExtractor().extract(ourTaskBundle).stream().findFirst().orElseThrow(() -> new ResourceNotFoundException("No our task is found for task " + task.getIdElement().getIdPart()));
Task ourTask = ourTaskInfo.getTask();
ourTask.setStatus(task.getStatus());
ourTask.setStatusReason(task.getStatusReason());
ourTask.setLastModifiedElement(task.getLastModifiedElement());
ourTask.setNote(task.getNote());
ourUpdateBundle.addEntry(FhirUtil.createPutEntry(ourTask));
ServiceRequest ourServiceRequest = ourTaskInfo.getServiceRequest();
if (!serviceRequest.getStatus().equals(ourServiceRequest.getStatus())) {
ourServiceRequest.setStatus(serviceRequest.getStatus());
ourUpdateBundle.addEntry(FhirUtil.createPutEntry(ourServiceRequest));
}
taskRepository.transaction(ourUpdateBundle);
}
use of org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor 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());
}
use of org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor in project Gravity-SDOH-Exchange-RI by FHIR.
the class TaskService method newTask.
public String newTask(NewTaskRequestDto taskRequest, UserDto user) {
Assert.notNull(SmartOnFhirContext.get().getPatient(), "Patient id cannot be null.");
TaskPrepareBundleFactory taskPrepareBundleFactory = new TaskPrepareBundleFactory(SmartOnFhirContext.get().getPatient(), user.getId(), taskRequest.getPerformerId(), taskRequest.getConsent(), taskRequest.getConditionIds(), taskRequest.getGoalIds());
Bundle taskRelatedResources = ehrClient.transaction().withBundle(taskPrepareBundleFactory.createPrepareBundle()).execute();
TaskPrepareInfoHolder taskPrepareInfoHolder = new TaskPrepareBundleExtractor().extract(taskRelatedResources);
TaskBundleFactory taskBundleFactory = new TaskBundleFactory();
taskBundleFactory.setName(taskRequest.getName());
taskBundleFactory.setPatient(taskPrepareInfoHolder.getPatient());
taskBundleFactory.setCategory(sdohMappings.findCategoryCoding(taskRequest.getCategory()));
taskBundleFactory.setRequestCode(sdohMappings.findResourceCoding(ServiceRequest.class, taskRequest.getCode()));
taskBundleFactory.setPriority(taskRequest.getPriority());
taskBundleFactory.setOccurrence(taskRequest.getOccurrence());
taskBundleFactory.setPerformer(taskPrepareInfoHolder.getPerformerOrganization());
taskBundleFactory.setRequester(taskPrepareInfoHolder.getPerformer());
taskBundleFactory.setComment(taskRequest.getComment());
taskBundleFactory.setUser(user);
taskBundleFactory.setConsent(taskPrepareInfoHolder.getConsent());
taskBundleFactory.setConditions(taskPrepareInfoHolder.getConditions(taskRequest.getConditionIds()));
taskBundleFactory.setGoals(taskPrepareInfoHolder.getGoals(taskRequest.getGoalIds()));
Bundle taskCreateBundle = ehrClient.transaction().withBundle(taskBundleFactory.createBundle()).execute();
IdType taskId = FhirUtil.getFromResponseBundle(taskCreateBundle, Task.class);
TaskInfoHolder createInfo = new TaskInfoBundleExtractor().extract(getTask(taskId.getIdPart(), Task.INCLUDE_FOCUS)).stream().findFirst().orElseThrow(() -> new TaskCreateException("Task/ServiceRequest are not found in the response bundle."));
Task task = createInfo.getTask();
try {
cpService.create(task, taskPrepareInfoHolder.getEndpoint());
} catch (CpClientException exc) {
log.warn("Task '{}' creation failed at CP. Failing a local Task and related ServiceRequest.", task.getIdElement().getIdPart(), exc);
ehrClient.transaction().withBundle(new TaskFailBundleFactory(task, createInfo.getServiceRequest(), exc.getMessage()).createFailBundle()).execute();
}
return task.getIdElement().getIdPart();
}
Aggregations