Search in sources :

Example 1 with TaskInfoHolder

use of org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder in project Gravity-SDOH-Exchange-RI by FHIR.

the class OurTaskService method update.

public void update(String id, UpdateOurTaskRequestDto update, UserDto user) {
    Bundle taskBundle = taskRepository.find(id, Lists.newArrayList(Task.INCLUDE_FOCUS));
    TaskInfoHolder taskInfo = new TaskInfoBundleExtractor().extract(taskBundle).stream().findFirst().orElseThrow(() -> new ResourceNotFoundException(new IdType(Task.class.getSimpleName(), id)));
    OurTaskUpdateBundleFactory bundleFactory = new OurTaskUpdateBundleFactory();
    bundleFactory.setTask(taskInfo.getTask());
    bundleFactory.setServiceRequest(taskInfo.getServiceRequest());
    bundleFactory.setStatus(update.getTaskStatus());
    bundleFactory.setStatusReason(update.getStatusReason());
    bundleFactory.setComment(update.getComment());
    bundleFactory.setUser(user);
    taskRepository.transaction(bundleFactory.createUpdateBundle());
}
Also used : TaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder) Task(org.hl7.fhir.r4.model.Task) OurTaskUpdateBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.OurTaskUpdateBundleFactory) Bundle(org.hl7.fhir.r4.model.Bundle) TaskInfoBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) IdType(org.hl7.fhir.r4.model.IdType)

Example 2 with TaskInfoHolder

use of org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder in project Gravity-SDOH-Exchange-RI by FHIR.

the class CpService method read.

public TaskInfoHolder read(final String id, final Endpoint endpoint) throws CpClientException {
    try {
        Bundle taskBundle = cpClient(endpoint).search().forResource(Task.class).where(Task.IDENTIFIER.exactly().systemAndValues(identifierSystem, id)).include(Task.INCLUDE_FOCUS).returnBundle(Bundle.class).execute();
        // Additional validation
        int tasksSize = FhirUtil.getFromBundle(taskBundle, Task.class).size();
        if (tasksSize == 0) {
            throw new CpClientException(String.format("No Task is present at '%s' for identifier '%s'.", endpoint.getAddress(), identifierSystem + "|" + id));
        } else if (tasksSize > 1) {
            throw new CpClientException(String.format("More than one Task is present at '%s' for identifier '%s'.", endpoint.getAddress(), identifierSystem + "|" + id));
        }
        return new TaskInfoBundleExtractor().extract(taskBundle).stream().findFirst().get();
    } catch (BaseServerResponseException exc) {
        throw new CpClientException(String.format("Task retrieval failed for identifier '%s' at CP location '%s'. Reason: %s.", identifierSystem + "|" + id, endpoint.getAddress(), exc.getMessage()), exc);
    }
}
Also used : Task(org.hl7.fhir.r4.model.Task) Bundle(org.hl7.fhir.r4.model.Bundle) TaskInfoBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor) BaseServerResponseException(ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException) Endpoint(org.hl7.fhir.r4.model.Endpoint)

Example 3 with TaskInfoHolder

use of org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder 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 4 with TaskInfoHolder

use of org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder 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)

Example 5 with TaskInfoHolder

use of org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder in project Gravity-SDOH-Exchange-RI by FHIR.

the class CpTaskInfoBundleExtractor method extract.

@Override
public List<CpTaskInfoHolder> extract(Bundle bundle) {
    List<TaskInfoHolder> taskInfoHolders = taskInfoBundleExtractor.extract(bundle);
    Map<String, Task> taskIdToOurTaskMap = FhirUtil.getFromBundle(bundle, Task.class).stream().filter(t -> t.getIntent() == Task.TaskIntent.FILLERORDER).collect(Collectors.toMap(ourTask -> ourTask.getBasedOn().get(0).getResource().getIdElement().getIdPart(), Function.identity()));
    return taskInfoHolders.stream().filter(t -> t.getTask().getIntent() == Task.TaskIntent.ORDER).map(taskInfoHolder -> {
        Task ourTask = taskIdToOurTaskMap.get(taskInfoHolder.getTask().getIdElement().getIdPart());
        Organization performer = null;
        if (!Objects.isNull(ourTask)) {
            if (!(ourTask.getOwner().getResource() instanceof Organization)) {
                String reason = String.format("Our task resource with id '%s' does not contain owner of type Organization.", ourTask.getIdElement().getIdPart());
                throw new CpTaskInfoBundleExtractorException(reason);
            }
            performer = (Organization) ourTask.getOwner().getResource();
        }
        return new CpTaskInfoHolder(taskInfoHolder, ourTask, performer);
    }).collect(Collectors.toList());
}
Also used : TaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder) CpTaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.CpTaskInfoBundleExtractor.CpTaskInfoHolder) Objects(java.util.Objects) Organization(org.hl7.fhir.r4.model.Organization) Task(org.hl7.fhir.r4.model.Task) TaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder) List(java.util.List) Getter(lombok.Getter) Map(java.util.Map) Bundle(org.hl7.fhir.r4.model.Bundle) CpTaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.CpTaskInfoBundleExtractor.CpTaskInfoHolder) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) Task(org.hl7.fhir.r4.model.Task) Organization(org.hl7.fhir.r4.model.Organization) CpTaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.CpTaskInfoBundleExtractor.CpTaskInfoHolder)

Aggregations

Task (org.hl7.fhir.r4.model.Task)10 Bundle (org.hl7.fhir.r4.model.Bundle)8 TaskInfoHolder (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder)6 ServiceRequest (org.hl7.fhir.r4.model.ServiceRequest)4 TaskInfoBundleExtractor (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor)4 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)2 List (java.util.List)2 Map (java.util.Map)2 Getter (lombok.Getter)2 Coding (org.hl7.fhir.r4.model.Coding)2 IdType (org.hl7.fhir.r4.model.IdType)2 Type (org.hl7.fhir.r4.model.Type)2 FhirUtil (org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil)2 BaseServerResponseException (ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1