Search in sources :

Example 1 with ServerNotFoundException

use of org.hl7.gravity.refimpl.sdohexchange.exception.ServerNotFoundException in project Gravity-SDOH-Exchange-RI by FHIR.

the class ResourceService method getTaskResources.

public TaskJsonResourcesDto getTaskResources(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()));
    // Getting task by id with Patient, requester Organization and ServiceRequest
    Bundle taskBundle = fhirClient.search().forResource(Task.class).where(Task.RES_ID.exactly().code(taskId)).include(Task.INCLUDE_FOCUS).include(Task.INCLUDE_PATIENT).include(Task.INCLUDE_REQUESTER).returnBundle(Bundle.class).execute();
    Task task = FhirUtil.getFromBundle(taskBundle, Task.class).stream().findFirst().orElseThrow(() -> new ResourceNotFoundException(new IdType(Task.class.getSimpleName(), taskId)));
    // We expect that task was validated and contains all resources
    ServiceRequest serviceRequest = FhirUtil.getFirstFromBundle(taskBundle, ServiceRequest.class);
    Patient patient = FhirUtil.getFirstFromBundle(taskBundle, Patient.class);
    Organization requester = FhirUtil.getFirstFromBundle(taskBundle, Organization.class);
    // Load all Task Procedures and ServiceRequest required resources as one transaction
    Map<Class<? extends Resource>, List<Resource>> loadedResources = resourceLoader.getResources(fhirClient, collectAllReferences(task, serviceRequest));
    TaskJsonResourcesDto resourcesDto = new TaskJsonResourcesDto();
    resourcesDto.setTask(resourceParser.parse(task));
    resourcesDto.setServiceRequest(resourceParser.parse(serviceRequest));
    resourcesDto.setPatient(resourceParser.parse(patient));
    resourcesDto.setRequester(resourceParser.parse(requester));
    resourcesDto.setConsent(resourceParser.parse(loadedResources.get(Consent.class)).stream().findFirst().orElse(null));
    resourcesDto.setConditions(resourceParser.parse(loadedResources.get(Condition.class)));
    resourcesDto.setGoals(resourceParser.parse(loadedResources.get(Goal.class)));
    resourcesDto.setProcedures(resourceParser.parse(loadedResources.get(Procedure.class)));
    return resourcesDto;
}
Also used : Task(org.hl7.fhir.r4.model.Task) Organization(org.hl7.fhir.r4.model.Organization) Server(org.hl7.gravity.refimpl.sdohexchange.model.Server) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) Patient(org.hl7.fhir.r4.model.Patient) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) IdType(org.hl7.fhir.r4.model.IdType) TaskJsonResourcesDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskJsonResourcesDto) Consent(org.hl7.fhir.r4.model.Consent) ArrayList(java.util.ArrayList) List(java.util.List) ServerNotFoundException(org.hl7.gravity.refimpl.sdohexchange.exception.ServerNotFoundException) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)

Example 2 with ServerNotFoundException

use of org.hl7.gravity.refimpl.sdohexchange.exception.ServerNotFoundException in project Gravity-SDOH-Exchange-RI by FHIR.

the class ServerService method updateServer.

@Transactional
public ServerDto updateServer(Integer id, NewServerDto newServerDto) throws AuthClientException {
    Server server = serverRepository.findById(id).orElseThrow(() -> new ServerNotFoundException(String.format("No Server was found by id '%s'", id)));
    if (serverRepository.findByServerName(newServerDto.getServerName()).isPresent() && !server.getServerName().equals(newServerDto.getServerName())) {
        throw new DuplicateServerNameNotAllowedException(newServerDto.getServerName());
    }
    // Just a validation of credentials.
    authorizationClient.getTokenResponse(URI.create(newServerDto.getAuthServerUrl()), newServerDto.getClientId(), newServerDto.getClientSecret(), SCOPE);
    modelMapper.map(newServerDto, server);
    return modelMapper.map(server, ServerDto.class);
}
Also used : Server(org.hl7.gravity.refimpl.sdohexchange.model.Server) ServerNotFoundException(org.hl7.gravity.refimpl.sdohexchange.exception.ServerNotFoundException) DuplicateServerNameNotAllowedException(org.hl7.gravity.refimpl.sdohexchange.exception.DuplicateServerNameNotAllowedException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with ServerNotFoundException

use of org.hl7.gravity.refimpl.sdohexchange.exception.ServerNotFoundException 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)

Example 4 with ServerNotFoundException

use of org.hl7.gravity.refimpl.sdohexchange.exception.ServerNotFoundException 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();
}
Also used : 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) TaskBundleToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.TaskBundleToDtoConverter) TaskReadException(org.hl7.gravity.refimpl.sdohexchange.exception.TaskReadException) ServerNotFoundException(org.hl7.gravity.refimpl.sdohexchange.exception.ServerNotFoundException) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) IdType(org.hl7.fhir.r4.model.IdType)

Aggregations

ServerNotFoundException (org.hl7.gravity.refimpl.sdohexchange.exception.ServerNotFoundException)4 Server (org.hl7.gravity.refimpl.sdohexchange.model.Server)4 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)3 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)3 Bundle (org.hl7.fhir.r4.model.Bundle)3 IdType (org.hl7.fhir.r4.model.IdType)3 Task (org.hl7.fhir.r4.model.Task)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TaskRepository (org.hl7.gravity.refimpl.sdohexchange.dao.TaskRepository)2 TaskBundleToDtoConverter (org.hl7.gravity.refimpl.sdohexchange.dto.converter.TaskBundleToDtoConverter)2 TaskReadException (org.hl7.gravity.refimpl.sdohexchange.exception.TaskReadException)2 FhirContext (ca.uhn.fhir.context.FhirContext)1 Lists (com.google.common.collect.Lists)1 Collections (java.util.Collections)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Coding (org.hl7.fhir.r4.model.Coding)1 Consent (org.hl7.fhir.r4.model.Consent)1