use of org.hl7.fhir.r5.model.Task in project Gravity-SDOH-Exchange-RI by FHIR.
the class TaskPollingService method processTasks.
@Scheduled(fixedDelayString = "${scheduling.task-polling-delay-millis}")
public void processTasks() {
log.info("Checking for requested tasks from EHR...");
Bundle searchBundle = openCpClient.search().forResource(Task.class).and(Task.STATUS.exactly().code(Task.TaskStatus.REQUESTED.toCode())).returnBundle(Bundle.class).execute();
Bundle transactionBundle = new Bundle();
transactionBundle.setType(Bundle.BundleType.TRANSACTION);
FhirUtil.getFromBundle(searchBundle, Task.class).stream().map(taskProcessor::process).forEach(bundle -> transactionBundle.getEntry().addAll(bundle.getEntry()));
if (transactionBundle.getEntry().size() > 0) {
log.info("One or more task were received from EHR. Storing updates...");
openCpClient.transaction().withBundle(transactionBundle).execute();
}
log.info("Task receiving process finished.");
}
use of org.hl7.fhir.r5.model.Task in project Gravity-SDOH-Exchange-RI by FHIR.
the class GoalBundleToDtoConverter method convert.
@Override
public List<GoalDto> convert(Bundle bundle) {
List<GoalDto> result = FhirUtil.getFromBundle(bundle, Goal.class).stream().map(goal -> {
GoalDto goalDto = new GoalDto();
goalDto.setId(goal.getIdElement().getIdPart());
if (goal.hasDescription() && goal.getDescription().hasText()) {
goalDto.setName(goal.getDescription().getText());
} else {
goalDto.getErrors().add("Goal description.text not found. Name cannot be set.");
}
if (goal.hasAchievementStatus()) {
goalDto.setAchievementStatus(GoalAchievement.fromCode(goal.getAchievementStatus().getCodingFirstRep().getCode()));
} else {
goalDto.getErrors().add("No achievement status available.");
}
// TODO reused from HealthConcernBundleToDtoConverter class. Refactor!
Coding categoryCoding = FhirUtil.findCoding(goal.getCategory(), SDOHMappings.getInstance().getSystem());
// TODO remove this in future. Fow now two different categories might be used before discussed.
if (categoryCoding == null) {
categoryCoding = FhirUtil.findCoding(goal.getCategory(), "http://hl7.org/fhir/us/sdoh-clinicalcare/CodeSystem/SDOHCC-CodeSystemTemporaryCodes");
}
if (categoryCoding == null) {
goalDto.getErrors().add("SDOH category is not found.");
} else {
goalDto.setCategory(new CodingDto(categoryCoding.getCode(), categoryCoding.getDisplay()));
}
Optional<Coding> snomedCodeCodingOptional = findCode(goal.getDescription(), System.SNOMED);
if (snomedCodeCodingOptional.isPresent()) {
Coding snomedCodeCoding = snomedCodeCodingOptional.get();
goalDto.setSnomedCode(new CodingDto(snomedCodeCoding.getCode(), snomedCodeCoding.getDisplay()));
} else {
goalDto.getErrors().add("SNOMED-CT code is not found.");
}
if (goal.hasExpressedBy()) {
Reference expressedBy = goal.getExpressedBy();
goalDto.setAddedBy(new ReferenceDto(expressedBy.getReferenceElement().getIdPart(), expressedBy.getDisplay()));
} else {
goalDto.getErrors().add("Goal expressedBy property is missing. addedBy will be null.");
}
goalDto.setStartDate(FhirUtil.toLocalDate(goal.getStartDateType()));
// TODO this is invalid. To clarify!
if (goal.getLifecycleStatus() == Goal.GoalLifecycleStatus.COMPLETED) {
if (goal.hasStatusDate()) {
goalDto.setEndDate(FhirUtil.toLocalDate(goal.getStatusDateElement()));
} else {
goalDto.getErrors().add("Goal statusDate must be set when the lifecycleStatus is COMPLETED. endDate will be null.");
}
}
goalDto.setComments(goal.getNote().stream().map(annotationToDtoConverter::convert).collect(Collectors.toList()));
goalDto.setProblems(goal.getAddresses().stream().filter(ref -> Condition.class.getSimpleName().equals(ref.getReferenceElement().getResourceType())).map(ref -> (Condition) ref.getResource()).map(cond -> new ConditionDto(cond.getIdElement().getIdPart(), codeableConceptToStringConverter.convert(cond.getCode()))).collect(Collectors.toList()));
return goalDto;
}).collect(Collectors.toList());
// TODO refactor. method too long.
// TODO refactor. Almost the same fragmen exists in a ProblemInfoBundleExtractor
Map<String, GoalDto> idToDtoMap = result.stream().collect(Collectors.toMap(g -> g.getId(), Function.identity()));
for (Task task : FhirUtil.getFromBundle(bundle, Task.class)) {
if (!task.hasFocus() || !(task.getFocus().getResource() instanceof ServiceRequest)) {
continue;
}
ServiceRequest sr = (ServiceRequest) task.getFocus().getResource();
sr.getSupportingInfo().stream().filter(ref -> Goal.class.getSimpleName().equals(ref.getReferenceElement().getResourceType()) && idToDtoMap.containsKey(ref.getReferenceElement().getIdPart())).forEach(ref -> idToDtoMap.get(ref.getReferenceElement().getIdPart()).getTasks().add(new TaskInfoDto(task.getIdElement().getIdPart(), task.getDescription(), task.getStatus())));
}
return result;
}
use of org.hl7.fhir.r5.model.Task in project Gravity-SDOH-Exchange-RI by FHIR.
the class OurTaskUpdateBundleFactory method createUpdateBundle.
public Bundle createUpdateBundle() {
Assert.notNull(task, "Task can't be null.");
Bundle updateBundle = new Bundle();
updateBundle.setType(Bundle.BundleType.TRANSACTION);
updateTask(updateBundle);
updateBundle.addEntry(FhirUtil.createPutEntry(task));
return updateBundle;
}
use of org.hl7.fhir.r5.model.Task in project Gravity-SDOH-Exchange-RI by FHIR.
the class PatientTaskController method update.
@PutMapping("{id}")
@ApiOperation(value = "Update Task resource.")
public ResponseEntity<Void> update(@PathVariable @NotBlank(message = "Task id can't be empty.") String id, @Valid @RequestBody UpdateTaskRequestDto update, @ApiIgnore @AuthenticationPrincipal OidcUser user) {
UserDto userDto = new UserInfoToDtoConverter().convert(user.getClaims());
patientTaskService.update(id, update, userDto);
return ResponseEntity.noContent().build();
}
use of org.hl7.fhir.r5.model.Task in project Gravity-SDOH-Exchange-RI by FHIR.
the class TaskValidator method validate.
public List<String> validate(Task task) {
List<String> errors = new ArrayList<>();
if (task.hasIdentifier() && task.getIdentifier().size() != 1) {
errors.add("Task.identifier is not valid.");
}
if (!task.getIntent().equals(Task.TaskIntent.ORDER)) {
errors.add(String.format("Task.intent has wrong value. Supported value is '%s'.", Task.TaskIntent.ORDER.toCode()));
}
TaskCode taskCode = TaskCode.FULFILL;
if (task.getCode().getCoding().stream().noneMatch(coding -> taskCode.getSystem().equals(coding.getSystem()) && taskCode.toCode().equals(coding.getCode()) && taskCode.getDisplay().equals(coding.getDisplay()))) {
errors.add(String.format("Task.code has no coding with system '%s' and code '%s'.", taskCode.getSystem(), taskCode.toCode()));
}
if (!task.hasFocus()) {
errors.add("Task.focus is missing.");
}
if (!task.hasFor()) {
errors.add("Task.for is missing.");
}
if (task.hasFor() && !task.getFor().getReferenceElement().getResourceType().equals(Patient.class.getSimpleName())) {
errors.add(String.format("Task.for reference is invalid. Supported reference is '%s'.", Patient.class.getSimpleName()));
}
if (task.hasRequester() && !task.getRequester().getReferenceElement().getResourceType().equals(Organization.class.getSimpleName())) {
errors.add(String.format("Task.requester reference is invalid. Supported reference is '%s'.", Organization.class.getSimpleName()));
}
if (task.hasOwner() && !task.getOwner().getReferenceElement().getResourceType().equals(Organization.class.getSimpleName())) {
errors.add(String.format("Task.owner reference is invalid. Supported reference is '%s'.", Organization.class.getSimpleName()));
}
return errors;
}
Aggregations