Search in sources :

Example 1 with TaskOutputComponent

use of org.hl7.fhir.r4.model.Task.TaskOutputComponent in project openmrs-module-fhir2 by openmrs.

the class TaskTranslatorImpl method translateToOutputReference.

private FhirTaskOutput translateToOutputReference(Task.TaskOutputComponent taskOutputComponent) {
    FhirReference outputReference = referenceTranslator.toOpenmrsType((Reference) taskOutputComponent.getValue());
    Concept type = conceptTranslator.toOpenmrsType(taskOutputComponent.getType());
    FhirTaskOutput output = new FhirTaskOutput();
    output.setValueReference(outputReference);
    output.setType(type);
    output.setName("TaskOutputComponent/" + output.getUuid());
    return output;
}
Also used : CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Concept(org.openmrs.Concept) FhirTaskOutput(org.openmrs.module.fhir2.model.FhirTaskOutput) FhirReference(org.openmrs.module.fhir2.model.FhirReference)

Example 2 with TaskOutputComponent

use of org.hl7.fhir.r4.model.Task.TaskOutputComponent in project Gravity-SDOH-Exchange-RI by FHIR.

the class TaskPollingService method handleFinishedTask.

protected void handleFinishedTask(Bundle resultBundle, Task ehrTask, ServiceRequest ehrServiceRequest, Task cpTask, Endpoint endpoint) {
    if (Task.TaskStatus.COMPLETED.equals(cpTask.getStatus())) {
        ehrServiceRequest.setStatus(ServiceRequest.ServiceRequestStatus.COMPLETED);
        resultBundle.addEntry(FhirUtil.createPutEntry(ehrServiceRequest));
    }
    // property.
    if (Task.TaskStatus.COMPLETED.equals(cpTask.getStatus()) || Task.TaskStatus.CANCELLED.equals(cpTask.getStatus())) {
        // Modify Task.output. If task output is of type resulting-activity and contains a Reference to a proper
        // Procedure - copy output changing a Procedure reference to a local one.
        List<TaskOutputComponent> cpOutputs = cpTask.getOutput().stream().filter(t -> t.getValue() instanceof CodeableConcept || (t.getValue() instanceof Reference && ((Reference) t.getValue()).getReferenceElement().getResourceType().equals(Procedure.class.getSimpleName()))).collect(Collectors.toList());
        if (cpOutputs.size() == 0) {
            log.warn("Not output of type 'http://hl7.org/fhir/us/sdoh-clinicalcare/CodeSystem/sdohcc-temporary-codes|resulting" + "-activity' with a reference to a proper Procedure is present in task with id '{}' at '{}'. " + "Expecting a reference to a Procedure resource.", cpTask.getIdElement().getIdPart(), endpoint.getAddress());
        }
        Map<String, Procedure> cpProcedureMap = getCpProcedures(cpOutputs, endpoint);
        for (Task.TaskOutputComponent cpOutput : cpOutputs) {
            Task.TaskOutputComponent ehrTaskOutput = cpOutput.copy();
            if (cpOutput.getValue() instanceof Reference) {
                Reference cpProcedureReference = (Reference) cpOutput.getValue();
                String cpProcedureId = cpProcedureReference.getReferenceElement().getIdPart();
                Procedure cpProcedure = cpProcedureMap.get(cpProcedureId);
                // All Procedures have the same reason reference as ServiceRequest
                Procedure resultProcedure = copyProcedure(cpProcedure, ehrTask.getFor(), ehrTask.getFocus(), ehrServiceRequest.getReasonReference());
                resultProcedure.setId(IdType.newRandomUuid());
                resultProcedure.addIdentifier().setSystem(endpoint.getAddress()).setValue(cpProcedureId);
                // Add Procedure to result bundle
                resultBundle.addEntry(FhirUtil.createPostEntry(resultProcedure));
                ehrTaskOutput.setValue(FhirUtil.toReference(Procedure.class, resultProcedure.getIdElement().getIdPart(), cpProcedureReference.getDisplay()));
            }
            ehrTask.addOutput(ehrTaskOutput);
        }
    }
}
Also used : Date(java.util.Date) TaskOutputComponent(org.hl7.fhir.r4.model.Task.TaskOutputComponent) Constants(ca.uhn.fhir.rest.api.Constants) RequiredArgsConstructor(lombok.RequiredArgsConstructor) LocalDateTime(java.time.LocalDateTime) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Autowired(org.springframework.beans.factory.annotation.Autowired) Endpoint(org.hl7.fhir.r4.model.Endpoint) Scheduled(org.springframework.scheduling.annotation.Scheduled) Reference(org.hl7.fhir.r4.model.Reference) TaskStatus(org.hl7.fhir.r4.model.Task.TaskStatus) Function(java.util.function.Function) ArrayList(java.util.ArrayList) JSONParser(net.minidev.json.parser.JSONParser) TasksPollingInfo(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor.TasksPollingInfo) Procedure(org.hl7.fhir.r4.model.Procedure) Task(org.hl7.fhir.r4.model.Task) FhirContext(ca.uhn.fhir.context.FhirContext) TaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Map(java.util.Map) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) StringClientParam(ca.uhn.fhir.rest.gclient.StringClientParam) SearchModifierCode(org.hl7.fhir.r4.model.codesystems.SearchModifierCode) Observation(org.hl7.fhir.r4.model.Observation) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) SDOHProfiles(org.hl7.gravity.refimpl.sdohexchange.fhir.SDOHProfiles) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) Set(java.util.Set) TaskFailBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskFailBundleFactory) CpClientException(org.hl7.gravity.refimpl.sdohexchange.service.CpService.CpClientException) Collectors(java.util.stream.Collectors) IdType(org.hl7.fhir.r4.model.IdType) ZoneId(java.time.ZoneId) Organization(org.hl7.fhir.r4.model.Organization) Slf4j(lombok.extern.slf4j.Slf4j) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) TaskPollingUpdateException(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor.TaskPollingUpdateException) List(java.util.List) TasksPollingBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TasksPollingBundleExtractor) JSONObject(net.minidev.json.JSONObject) Bundle(org.hl7.fhir.r4.model.Bundle) OrganizationTypeCode(org.hl7.gravity.refimpl.sdohexchange.codes.OrganizationTypeCode) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) Task(org.hl7.fhir.r4.model.Task) Reference(org.hl7.fhir.r4.model.Reference) Procedure(org.hl7.fhir.r4.model.Procedure) TaskOutputComponent(org.hl7.fhir.r4.model.Task.TaskOutputComponent) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) TaskOutputComponent(org.hl7.fhir.r4.model.Task.TaskOutputComponent)

Example 3 with TaskOutputComponent

use of org.hl7.fhir.r4.model.Task.TaskOutputComponent in project Gravity-SDOH-Exchange-RI by FHIR.

the class OurTaskPollingService method handleFinishedTask.

protected void handleFinishedTask(Bundle resultBundle, Task task, ServiceRequest serviceRequest, Task ourTask) {
    boolean isFinished = false;
    if (TaskStatus.COMPLETED.equals(ourTask.getStatus())) {
        serviceRequest.setStatus(ServiceRequest.ServiceRequestStatus.COMPLETED);
        resultBundle.addEntry(FhirUtil.createPutEntry(serviceRequest));
        isFinished = true;
    } else if (TaskStatus.CANCELLED.equals(ourTask.getStatus()) || TaskStatus.REJECTED.equals(ourTask.getStatus()) || TaskStatus.FAILED.equals(ourTask.getStatus())) {
        serviceRequest.setStatus(ServiceRequest.ServiceRequestStatus.REVOKED);
        resultBundle.addEntry(FhirUtil.createPutEntry(serviceRequest));
        isFinished = true;
    }
    // property.
    if (isFinished) {
        // Modify Task.output. If task output is of type resulting-activity and contains a Reference to a proper
        // Procedure - copy output changing a Procedure reference to a local one.
        List<TaskOutputComponent> ourTaskOutputs = ourTask.getOutput().stream().filter(t -> t.getValue() instanceof CodeableConcept || (t.getValue() instanceof Reference && ((Reference) t.getValue()).getReferenceElement().getResourceType().equals(Procedure.class.getSimpleName()))).collect(Collectors.toList());
        if (ourTaskOutputs.size() == 0) {
            log.warn("No output of type 'http://hl7.org/fhir/us/sdoh-clinicalcare/CodeSystem/sdohcc-temporary-codes|resulting" + "-activity' with a reference to a proper Procedure is present in task with id '{}'. " + "Expecting a reference to a Procedure resource.", ourTask.getIdElement().getIdPart());
        }
        Map<String, Procedure> ourProcedureMap = getOurTaskProcedures(ourTaskOutputs);
        for (TaskOutputComponent ourTaskOutput : ourTaskOutputs) {
            TaskOutputComponent taskOutput = ourTaskOutput.copy();
            if (ourTaskOutput.getValue() instanceof Reference) {
                Reference ourProcedureReference = (Reference) ourTaskOutput.getValue();
                String ourProcedureId = ourProcedureReference.getReferenceElement().getIdPart();
                Procedure ourProcedure = ourProcedureMap.get(ourProcedureId);
                // All Procedures have the same reason reference as ServiceRequest
                Procedure resultProcedure = copyProcedure(ourProcedure, task.getFor(), task.getFocus(), serviceRequest.getReasonReference());
                resultProcedure.setId(IdType.newRandomUuid());
                // TODO add identifier
                // resultProcedure.addIdentifier()
                // .setSystem(SERVER_BASE)
                // .setValue(ourProcedureId);
                // Add Procedure to result bundle
                resultBundle.addEntry(FhirUtil.createPostEntry(resultProcedure));
                taskOutput.setValue(FhirUtil.toReference(Procedure.class, resultProcedure.getIdElement().getIdPart(), ourProcedureReference.getDisplay()));
            }
            task.addOutput(taskOutput);
        }
    }
}
Also used : OurTaskPollingUpdateException(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.OurTasksPollingBundleExtractor.OurTaskPollingUpdateException) OurTasksPollingInfo(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.OurTasksPollingBundleExtractor.OurTasksPollingInfo) Date(java.util.Date) TaskOutputComponent(org.hl7.fhir.r4.model.Task.TaskOutputComponent) RequiredArgsConstructor(lombok.RequiredArgsConstructor) LocalDateTime(java.time.LocalDateTime) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Autowired(org.springframework.beans.factory.annotation.Autowired) Scheduled(org.springframework.scheduling.annotation.Scheduled) Reference(org.hl7.fhir.r4.model.Reference) TaskStatus(org.hl7.fhir.r4.model.Task.TaskStatus) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Procedure(org.hl7.fhir.r4.model.Procedure) Task(org.hl7.fhir.r4.model.Task) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Map(java.util.Map) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) SearchModifierCode(org.hl7.fhir.r4.model.codesystems.SearchModifierCode) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) SDOHProfiles(org.hl7.gravity.refimpl.sdohexchange.fhir.SDOHProfiles) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) TaskFailBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskFailBundleFactory) Collectors(java.util.stream.Collectors) IdType(org.hl7.fhir.r4.model.IdType) ZoneId(java.time.ZoneId) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) OurTasksPollingBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.OurTasksPollingBundleExtractor) Bundle(org.hl7.fhir.r4.model.Bundle) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) Reference(org.hl7.fhir.r4.model.Reference) Procedure(org.hl7.fhir.r4.model.Procedure) TaskOutputComponent(org.hl7.fhir.r4.model.Task.TaskOutputComponent) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 4 with TaskOutputComponent

use of org.hl7.fhir.r4.model.Task.TaskOutputComponent 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 5 with TaskOutputComponent

use of org.hl7.fhir.r4.model.Task.TaskOutputComponent 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

CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)5 Reference (org.hl7.fhir.r4.model.Reference)4 TaskOutputComponent (org.hl7.fhir.r4.model.Task.TaskOutputComponent)4 Task (org.hl7.fhir.r4.model.Task)3 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)2 TokenClientParam (ca.uhn.fhir.rest.gclient.TokenClientParam)2 Lists (com.google.common.collect.Lists)2 LocalDateTime (java.time.LocalDateTime)2 ZoneId (java.time.ZoneId)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 List (java.util.List)2 Map (java.util.Map)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 RequiredArgsConstructor (lombok.RequiredArgsConstructor)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Bundle (org.hl7.fhir.r4.model.Bundle)2 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)2 IdType (org.hl7.fhir.r4.model.IdType)2