Search in sources :

Example 1 with TaskBundleToDtoConverter

use of org.hl7.gravity.refimpl.sdohexchange.dto.converter.TaskBundleToDtoConverter 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;
}
Also used : Server(org.hl7.gravity.refimpl.sdohexchange.model.Server) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) TaskRepository(org.hl7.gravity.refimpl.sdohexchange.dao.TaskRepository) TaskBundleToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.TaskBundleToDtoConverter) ArrayList(java.util.ArrayList) TaskDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskDto)

Example 2 with TaskBundleToDtoConverter

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

the class TaskService method read.

public TaskDto read(String id) {
    Bundle taskBundle = taskRepository.find(id, Lists.newArrayList(Task.INCLUDE_FOCUS, Task.INCLUDE_OWNER.asNonRecursive()), Lists.newArrayList(Task.INCLUDE_BASED_ON));
    Task task = FhirUtil.getFirstFromBundle(taskBundle, Task.class);
    if (Objects.isNull(task)) {
        throw new ResourceNotFoundException(new IdType(Task.class.getSimpleName(), id));
    }
    if (!task.getIntent().equals(Task.TaskIntent.ORDER)) {
        throw new TaskReadException("The intent of Task/" + id + " is not order.");
    }
    return new TaskBundleToDtoConverter().convert(taskBundle).stream().findFirst().get();
}
Also used : Task(org.hl7.fhir.r4.model.Task) Bundle(org.hl7.fhir.r4.model.Bundle) TaskBundleToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.TaskBundleToDtoConverter) TaskReadException(org.hl7.gravity.refimpl.sdohexchange.exception.TaskReadException) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) IdType(org.hl7.fhir.r4.model.IdType)

Example 3 with TaskBundleToDtoConverter

use of org.hl7.gravity.refimpl.sdohexchange.dto.converter.TaskBundleToDtoConverter 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)

Example 4 with TaskBundleToDtoConverter

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

the class TaskService method listTasks.

public List<TaskDto> listTasks() {
    Assert.notNull(SmartOnFhirContext.get().getPatient(), "Patient id cannot be null.");
    Bundle tasksBundle = new TaskQueryFactory().query(ehrClient, SmartOnFhirContext.get().getPatient()).include(Task.INCLUDE_FOCUS).where(new TokenClientParam("owner:Organization.type").hasSystemWithAnyCode(OrganizationTypeCode.SYSTEM)).returnBundle(Bundle.class).execute();
    return new TaskBundleToDtoConverter().convert(tasksBundle);
}
Also used : TaskQueryFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.query.TaskQueryFactory) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Bundle(org.hl7.fhir.r4.model.Bundle) TaskBundleToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.TaskBundleToDtoConverter)

Aggregations

TaskBundleToDtoConverter (org.hl7.gravity.refimpl.sdohexchange.dto.converter.TaskBundleToDtoConverter)4 Bundle (org.hl7.fhir.r4.model.Bundle)3 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)2 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)2 IdType (org.hl7.fhir.r4.model.IdType)2 Task (org.hl7.fhir.r4.model.Task)2 TaskRepository (org.hl7.gravity.refimpl.sdohexchange.dao.TaskRepository)2 TaskReadException (org.hl7.gravity.refimpl.sdohexchange.exception.TaskReadException)2 Server (org.hl7.gravity.refimpl.sdohexchange.model.Server)2 TokenClientParam (ca.uhn.fhir.rest.gclient.TokenClientParam)1 ArrayList (java.util.ArrayList)1 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)1 TaskDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskDto)1 ServerNotFoundException (org.hl7.gravity.refimpl.sdohexchange.exception.ServerNotFoundException)1 TaskQueryFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.query.TaskQueryFactory)1