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