Search in sources :

Example 1 with UpdateTaskRequestDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.request.UpdateTaskRequestDto 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();
    }
}
Also used : TaskFailBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskFailBundleFactory) Task(org.hl7.fhir.r4.model.Task) CpClientException(org.hl7.gravity.refimpl.sdohexchange.service.CpService.CpClientException) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Bundle(org.hl7.fhir.r4.model.Bundle) TaskUpdateBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskUpdateBundleExtractor) TaskUpdateInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskUpdateBundleExtractor.TaskUpdateInfoHolder) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) TaskUpdateBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskUpdateBundleFactory)

Example 2 with UpdateTaskRequestDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.request.UpdateTaskRequestDto in project Gravity-SDOH-Exchange-RI by FHIR.

the class PatientTaskController method update.

@PutMapping("{id}")
@ApiOperation(value = "Update Task resource.")
public ResponseEntity<Void> update(@PathVariable @NotBlank(message = "Task id can't be empty.") String id, @Valid @RequestBody UpdateTaskRequestDto update, @ApiIgnore @AuthenticationPrincipal OidcUser user) {
    UserDto userDto = new UserInfoToDtoConverter().convert(user.getClaims());
    patientTaskService.update(id, update, userDto);
    return ResponseEntity.noContent().build();
}
Also used : UserInfoToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.UserInfoToDtoConverter) UserDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.UserDto) PutMapping(org.springframework.web.bind.annotation.PutMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with UpdateTaskRequestDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.request.UpdateTaskRequestDto in project Gravity-SDOH-Exchange-RI by FHIR.

the class PatientTaskService method update.

public void update(String id, UpdateTaskRequestDto update, UserDto user) {
    Task task = ehrClient.read().resource(Task.class).withId(id).execute();
    if (task == null) {
        throw new ResourceNotFoundException(new IdType(Task.class.getSimpleName(), id));
    }
    PatientTaskUpdateBundleFactory updateBundleFactory = new PatientTaskUpdateBundleFactory();
    updateBundleFactory.setTask(task);
    updateBundleFactory.setStatus(update.getFhirStatus());
    updateBundleFactory.setStatusReason(update.getStatusReason());
    updateBundleFactory.setComment(update.getComment());
    updateBundleFactory.setUser(user);
    ehrClient.transaction().withBundle(updateBundleFactory.createUpdateBundle()).execute();
}
Also used : Task(org.hl7.fhir.r4.model.Task) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) PatientTaskUpdateBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.PatientTaskUpdateBundleFactory) IdType(org.hl7.fhir.r4.model.IdType)

Example 4 with UpdateTaskRequestDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.request.UpdateTaskRequestDto in project Gravity-SDOH-Exchange-RI by FHIR.

the class TaskController method update.

@PutMapping("{id}")
@ApiOperation(value = "Update Task resource.")
public ResponseEntity<Void> update(@PathVariable @NotBlank(message = "Task id can't be empty.") String id, @Valid @RequestBody UpdateTaskRequestDto update, @ApiIgnore @AuthenticationPrincipal OidcUser user) {
    UserDto userDto = new UserInfoToDtoConverter().convert(user.getClaims());
    taskService.update(id, update, userDto);
    return ResponseEntity.noContent().build();
}
Also used : UserInfoToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.UserInfoToDtoConverter) UserDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.UserDto) PutMapping(org.springframework.web.bind.annotation.PutMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with UpdateTaskRequestDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.request.UpdateTaskRequestDto 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());
}
Also used : TaskDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskDto) ServerNotFoundException(org.hl7.gravity.refimpl.sdohexchange.exception.ServerNotFoundException) AuthorizationClient(org.hl7.gravity.refimpl.sdohexchange.auth.AuthorizationClient) TaskUpdateBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskUpdateBundleFactory) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) Procedure(org.hl7.fhir.r4.model.Procedure) Task(org.hl7.fhir.r4.model.Task) FhirContext(ca.uhn.fhir.context.FhirContext) UpdateTaskRequestDto(org.hl7.gravity.refimpl.sdohexchange.dto.request.UpdateTaskRequestDto) Lists(com.google.common.collect.Lists) TaskInfoBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor) Service(org.springframework.stereotype.Service) TaskRepository(org.hl7.gravity.refimpl.sdohexchange.dao.TaskRepository) TaskReadException(org.hl7.gravity.refimpl.sdohexchange.exception.TaskReadException) Server(org.hl7.gravity.refimpl.sdohexchange.model.Server) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) RestTemplate(org.springframework.web.client.RestTemplate) AuthClientException(org.hl7.gravity.refimpl.sdohexchange.exception.AuthClientException) TaskBundleToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.TaskBundleToDtoConverter) ServerRepository(org.hl7.gravity.refimpl.sdohexchange.dao.ServerRepository) Collectors(java.util.stream.Collectors) IdType(org.hl7.fhir.r4.model.IdType) Objects(java.util.Objects) List(java.util.List) Coding(org.hl7.fhir.r4.model.Coding) Optional(java.util.Optional) Bundle(org.hl7.fhir.r4.model.Bundle) Collections(java.util.Collections) SDOHMappings(org.hl7.gravity.refimpl.sdohexchange.sdohmappings.SDOHMappings) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) Task(org.hl7.fhir.r4.model.Task) Server(org.hl7.gravity.refimpl.sdohexchange.model.Server) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.r4.model.Bundle) TaskRepository(org.hl7.gravity.refimpl.sdohexchange.dao.TaskRepository) IdType(org.hl7.fhir.r4.model.IdType) Coding(org.hl7.fhir.r4.model.Coding) ServerNotFoundException(org.hl7.gravity.refimpl.sdohexchange.exception.ServerNotFoundException) TaskInfoBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) TaskUpdateBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskUpdateBundleFactory)

Aggregations

Task (org.hl7.fhir.r4.model.Task)3 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)2 ApiOperation (io.swagger.annotations.ApiOperation)2 Bundle (org.hl7.fhir.r4.model.Bundle)2 IdType (org.hl7.fhir.r4.model.IdType)2 UserInfoToDtoConverter (org.hl7.gravity.refimpl.sdohexchange.dto.converter.UserInfoToDtoConverter)2 UserDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.UserDto)2 TaskUpdateBundleFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskUpdateBundleFactory)2 PutMapping (org.springframework.web.bind.annotation.PutMapping)2 FhirContext (ca.uhn.fhir.context.FhirContext)1 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)1 Lists (com.google.common.collect.Lists)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)1 Coding (org.hl7.fhir.r4.model.Coding)1