Search in sources :

Example 1 with TaskDto

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

the class OurTaskService method read.

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

Example 2 with TaskDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskDto 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 3 with TaskDto

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

the class TaskToDtoConverter method convert.

@Override
public TaskDto convert(Task task) {
    TaskDto taskDto = new TaskDto();
    taskDto.setId(task.getIdElement().getIdPart());
    taskDto.setName(task.getDescription());
    taskDto.setCreatedAt(FhirUtil.toLocalDateTime(task.getAuthoredOnElement()));
    taskDto.setLastModified(FhirUtil.toLocalDateTime(task.getLastModifiedElement()));
    taskDto.setPriority(task.getPriority().getDisplay());
    taskDto.setStatus(task.getStatus().getDisplay());
    taskDto.setComments(task.getNote().stream().map(annotationToDtoConverter::convert).collect(Collectors.toList()));
    taskDto.setStatusReason(task.getStatusReason().getText());
    taskDto.setOrganization(typeToDtoConverter.convert(task.getOwner()));
    for (TaskOutputComponent outputComponent : task.getOutput()) {
        Type componentValue = outputComponent.getValue();
        if (componentValue instanceof Reference) {
            Reference procedureReference = (Reference) componentValue;
            taskDto.getProcedures().add(new ProcedureDto(procedureReference.getReferenceElement().getIdPart(), procedureReference.getDisplay()));
        } else if (componentValue instanceof CodeableConcept) {
            CodeableConcept outcome = (CodeableConcept) componentValue;
            taskDto.setOutcome(outcome.getText());
        }
    }
    return taskDto;
}
Also used : ProcedureDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ProcedureDto) Type(org.hl7.fhir.r4.model.Type) Reference(org.hl7.fhir.r4.model.Reference) TaskOutputComponent(org.hl7.fhir.r4.model.Task.TaskOutputComponent) TaskDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskDto) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 4 with TaskDto

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

the class PatientTaskInfoHolderToDtoConverter method convert.

@Override
public PatientTaskDto convert(PatientTaskInfoHolder taskInfoHolder) {
    Task task = taskInfoHolder.getTask();
    PatientTaskDto taskDto = (PatientTaskDto) super.convert(taskInfoHolder);
    taskDto.setCreatedAt(FhirUtil.toLocalDateTime(task.getAuthoredOnElement()));
    taskDto.setComments(task.getNote().stream().map(annotationToDtoConverter::convert).collect(Collectors.toList()));
    taskDto.setOccurrence(new OccurrenceResponseDto(FhirUtil.toLocalDateTime(task.getExecutionPeriod().getStartElement()), FhirUtil.toLocalDateTime(task.getExecutionPeriod().getEndElement())));
    if (taskInfoHolder.getQuestionnaireResponse() != null) {
        taskDto.setAnswers(taskInfoHolder.getQuestionnaireResponse().getItem().stream().collect(Collectors.toMap(qr -> qr.getText(), qr -> {
            Type itemAnswer = qr.getAnswerFirstRep().getValue();
            if (itemAnswer instanceof StringType) {
                return ((StringType) itemAnswer).getValue();
            } else if (itemAnswer instanceof Coding) {
                return ((Coding) itemAnswer).getDisplay();
            } else {
                taskDto.getErrors().add(String.format("Answer cannot be resolved. %s type is not expected.", itemAnswer.getClass().getSimpleName()));
                return "Answer cannot be parsed.";
            }
        }, (existing, replacement) -> {
            taskDto.getErrors().add(String.format("Duplicating questions detected. Value '%s' overwrites the value '%s'", replacement, existing));
            return replacement;
        }, LinkedHashMap::new)));
    }
    return taskDto;
}
Also used : Task(org.hl7.fhir.r4.model.Task) Type(org.hl7.fhir.r4.model.Type) StringType(org.hl7.fhir.r4.model.StringType) StringType(org.hl7.fhir.r4.model.StringType) Coding(org.hl7.fhir.r4.model.Coding) OccurrenceResponseDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.OccurrenceResponseDto) PatientTaskDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.patienttask.PatientTaskDto) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with TaskDto

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

the class PatientTaskItemInfoHolderToItemDtoConverter method convert.

@Override
public PatientTaskItemDto convert(T taskInfoHolder) {
    Task task = taskInfoHolder.getTask();
    Questionnaire questionnaire = taskInfoHolder.getQuestionnaire();
    PatientTaskItemDto taskDto = createDto();
    taskDto.setId(task.getIdElement().getIdPart());
    taskDto.setName(task.getDescription());
    taskDto.setPriority(task.getPriority().getDisplay());
    taskDto.setLastModified(FhirUtil.toLocalDateTime(task.getLastModifiedElement()));
    taskDto.setStatus(task.getStatus().getDisplay());
    taskDto.setStatusReason(task.getStatusReason().getText());
    setReferralTask(task, taskDto);
    List<Coding> codings = task.getCode().getCoding();
    PatientTaskCode code = getCode(taskDto, codings);
    if (code != null) {
        Coding coding = code.toCoding();
        taskDto.setCode(new CodingDto(coding.getCode(), coding.getDisplay()));
    }
    setTaskType(task, taskDto, code);
    if (questionnaire != null) {
        taskDto.setAssessment(new ReferenceDto(questionnaire.getIdElement().getIdPart(), questionnaire.getTitle()));
    }
    for (TaskOutputComponent outputComponent : task.getOutput()) {
        Type componentValue = outputComponent.getValue();
        Coding coding = FhirUtil.findCoding(Lists.newArrayList(outputComponent.getType()), SDCTemporaryCode.SYSTEM, SDCTemporaryCode.QUESTIONNAIRE_RESPONSE.getCode());
        if (coding != null) {
            Reference qrRef = (Reference) componentValue;
            if (QuestionnaireResponse.class.getSimpleName().equals(qrRef.getReferenceElement().getResourceType())) {
                taskDto.setAssessmentResponse(new ReferenceDto(qrRef.getReferenceElement().getIdPart(), coding.getDisplay()));
            }
        }
        if (componentValue instanceof CodeableConcept) {
            CodeableConcept outcome = (CodeableConcept) componentValue;
            taskDto.setOutcome(outcome.getText());
        }
    }
    return taskDto;
}
Also used : Task(org.hl7.fhir.r4.model.Task) ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) Reference(org.hl7.fhir.r4.model.Reference) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) PatientTaskItemDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.patienttask.PatientTaskItemDto) CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) Type(org.hl7.fhir.r4.model.Type) PatientTaskType(org.hl7.gravity.refimpl.sdohexchange.dto.request.patienttask.PatientTaskType) Coding(org.hl7.fhir.r4.model.Coding) PatientTaskCode(org.hl7.gravity.refimpl.sdohexchange.codes.PatientTaskCode) TaskOutputComponent(org.hl7.fhir.r4.model.Task.TaskOutputComponent) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Aggregations

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