Search in sources :

Example 86 with Task

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.");
}
Also used : Task(org.hl7.fhir.r4.model.Task) Bundle(org.hl7.fhir.r4.model.Bundle) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 87 with Task

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;
}
Also used : Converter(org.springframework.core.convert.converter.Converter) GoalDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.GoalDto) Goal(org.hl7.fhir.r4.model.Goal) ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Condition(org.hl7.fhir.r4.model.Condition) Reference(org.hl7.fhir.r4.model.Reference) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Task(org.hl7.fhir.r4.model.Task) CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) List(java.util.List) GoalAchievement(org.hl7.fhir.r4.model.codesystems.GoalAchievement) TaskInfoDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskInfoDto) Coding(org.hl7.fhir.r4.model.Coding) Map(java.util.Map) Optional(java.util.Optional) Bundle(org.hl7.fhir.r4.model.Bundle) ConditionDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ConditionDto) System(org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System) SDOHMappings(org.hl7.gravity.refimpl.sdohexchange.sdohmappings.SDOHMappings) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) Condition(org.hl7.fhir.r4.model.Condition) GoalDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.GoalDto) ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) Task(org.hl7.fhir.r4.model.Task) Optional(java.util.Optional) Reference(org.hl7.fhir.r4.model.Reference) TaskInfoDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskInfoDto) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) Goal(org.hl7.fhir.r4.model.Goal) Coding(org.hl7.fhir.r4.model.Coding) ConditionDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ConditionDto)

Example 88 with Task

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;
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle)

Example 89 with Task

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();
}
Also used : UserInfoToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.UserInfoToDtoConverter) UserDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.UserDto) PutMapping(org.springframework.web.bind.annotation.PutMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 90 with Task

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;
}
Also used : TaskCode(org.hl7.fhir.r4.model.codesystems.TaskCode) Organization(org.hl7.fhir.r4.model.Organization) ArrayList(java.util.ArrayList) Patient(org.hl7.fhir.r4.model.Patient)

Aggregations

Test (org.junit.Test)127 Task (org.hl7.fhir.r4.model.Task)120 FhirTask (org.openmrs.module.fhir2.model.FhirTask)59 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)46 Bundle (org.hl7.fhir.r4.model.Bundle)40 Reference (org.hl7.fhir.r4.model.Reference)28 ServiceRequest (org.hl7.fhir.r4.model.ServiceRequest)24 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)23 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)22 Task (org.hl7.fhir.dstu3.model.Task)21 IdType (org.hl7.fhir.r4.model.IdType)21 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)17 Date (java.util.Date)16 ArrayList (java.util.ArrayList)13 List (java.util.List)13 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)13 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)12 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)11 TokenParam (ca.uhn.fhir.rest.param.TokenParam)11 Collectors (java.util.stream.Collectors)11