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;
}
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);
}
}
}
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);
}
}
}
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;
}
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;
}
Aggregations