use of org.hl7.gravity.refimpl.sdohexchange.dao.TaskRepository in project Gravity-SDOH-Exchange-RI by FHIR.
the class TaskService method readAll.
public List<TaskDto> readAll() throws AuthClientException {
List<Server> serverList = serverRepository.findAll();
List<TaskDto> taskDtoList = new ArrayList<>();
for (Server server : serverList) {
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);
taskDtoList.addAll(new TaskBundleToDtoConverter(server.getId()).convert(taskRepository.findAllTasks()));
}
return taskDtoList;
}
use of org.hl7.gravity.refimpl.sdohexchange.dao.TaskRepository 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.dao.TaskRepository in project Gravity-SDOH-Exchange-RI by FHIR.
the class TaskService method read.
public TaskDto read(Integer serverId, String taskId) {
Server server = serverRepository.findById(serverId).orElseThrow(() -> new ServerNotFoundException(String.format("No server was found by id '%s'", serverId)));
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);
Bundle taskBundle = taskRepository.find(taskId, Lists.newArrayList(Task.INCLUDE_FOCUS));
Task task = FhirUtil.getFirstFromBundle(taskBundle, Task.class);
if (Objects.isNull(task)) {
throw new ResourceNotFoundException(new IdType(Task.class.getSimpleName(), taskId));
}
if (!task.getIntent().equals(Task.TaskIntent.FILLERORDER)) {
throw new TaskReadException("The intent of Task/" + taskId + " is not filler-order.");
}
return new TaskBundleToDtoConverter(serverId).convert(taskBundle).stream().findFirst().get();
}
Aggregations