Search in sources :

Example 1 with TaskFailBundleFactory

use of org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskFailBundleFactory in project Gravity-SDOH-Exchange-RI by FHIR.

the class TaskService method update.

public void update(String id, UpdateTaskRequestDto update, UserDto user) {
    Bundle taskBundle = getTask(id, Task.INCLUDE_FOCUS, Task.INCLUDE_OWNER, Organization.INCLUDE_ENDPOINT.setRecurse(true));
    TaskUpdateInfoHolder updateInfo = new TaskUpdateBundleExtractor(id).extract(taskBundle);
    Task task = updateInfo.getTask();
    ServiceRequest serviceRequest = updateInfo.getServiceRequest();
    TaskUpdateBundleFactory updateBundleFactory = new TaskUpdateBundleFactory();
    updateBundleFactory.setTask(task);
    updateBundleFactory.setServiceRequest(serviceRequest);
    updateBundleFactory.setStatus(update.getFhirStatus());
    updateBundleFactory.setStatusReason(update.getStatusReason());
    updateBundleFactory.setComment(update.getComment());
    updateBundleFactory.setUser(user);
    ehrClient.transaction().withBundle(updateBundleFactory.createUpdateBundle()).execute();
    try {
        cpService.sync(task, serviceRequest, updateInfo.getEndpoint());
    } catch (CpClientException exc) {
        ehrClient.transaction().withBundle(new TaskFailBundleFactory(task, serviceRequest, exc.getMessage()).createFailBundle()).execute();
    }
}
Also used : TaskFailBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskFailBundleFactory) Task(org.hl7.fhir.r4.model.Task) CpClientException(org.hl7.gravity.refimpl.sdohexchange.service.CpService.CpClientException) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Bundle(org.hl7.fhir.r4.model.Bundle) TaskUpdateBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskUpdateBundleExtractor) TaskUpdateInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskUpdateBundleExtractor.TaskUpdateInfoHolder) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) TaskUpdateBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskUpdateBundleFactory)

Example 2 with TaskFailBundleFactory

use of org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskFailBundleFactory in project Gravity-SDOH-Exchange-RI by FHIR.

the class TaskService method newTask.

public String newTask(NewTaskRequestDto taskRequest, UserDto user) {
    Assert.notNull(SmartOnFhirContext.get().getPatient(), "Patient id cannot be null.");
    TaskPrepareBundleFactory taskPrepareBundleFactory = new TaskPrepareBundleFactory(SmartOnFhirContext.get().getPatient(), user.getId(), taskRequest.getPerformerId(), taskRequest.getConsent(), taskRequest.getConditionIds(), taskRequest.getGoalIds());
    Bundle taskRelatedResources = ehrClient.transaction().withBundle(taskPrepareBundleFactory.createPrepareBundle()).execute();
    TaskPrepareInfoHolder taskPrepareInfoHolder = new TaskPrepareBundleExtractor().extract(taskRelatedResources);
    TaskBundleFactory taskBundleFactory = new TaskBundleFactory();
    taskBundleFactory.setName(taskRequest.getName());
    taskBundleFactory.setPatient(taskPrepareInfoHolder.getPatient());
    taskBundleFactory.setCategory(sdohMappings.findCategoryCoding(taskRequest.getCategory()));
    taskBundleFactory.setRequestCode(sdohMappings.findResourceCoding(ServiceRequest.class, taskRequest.getCode()));
    taskBundleFactory.setPriority(taskRequest.getPriority());
    taskBundleFactory.setOccurrence(taskRequest.getOccurrence());
    taskBundleFactory.setPerformer(taskPrepareInfoHolder.getPerformerOrganization());
    taskBundleFactory.setRequester(taskPrepareInfoHolder.getPerformer());
    taskBundleFactory.setComment(taskRequest.getComment());
    taskBundleFactory.setUser(user);
    taskBundleFactory.setConsent(taskPrepareInfoHolder.getConsent());
    taskBundleFactory.setConditions(taskPrepareInfoHolder.getConditions(taskRequest.getConditionIds()));
    taskBundleFactory.setGoals(taskPrepareInfoHolder.getGoals(taskRequest.getGoalIds()));
    Bundle taskCreateBundle = ehrClient.transaction().withBundle(taskBundleFactory.createBundle()).execute();
    IdType taskId = FhirUtil.getFromResponseBundle(taskCreateBundle, Task.class);
    TaskInfoHolder createInfo = new TaskInfoBundleExtractor().extract(getTask(taskId.getIdPart(), Task.INCLUDE_FOCUS)).stream().findFirst().orElseThrow(() -> new TaskCreateException("Task/ServiceRequest are not found in the response bundle."));
    Task task = createInfo.getTask();
    try {
        cpService.create(task, taskPrepareInfoHolder.getEndpoint());
    } catch (CpClientException exc) {
        log.warn("Task '{}' creation failed at CP. Failing a local Task and related ServiceRequest.", task.getIdElement().getIdPart(), exc);
        ehrClient.transaction().withBundle(new TaskFailBundleFactory(task, createInfo.getServiceRequest(), exc.getMessage()).createFailBundle()).execute();
    }
    return task.getIdElement().getIdPart();
}
Also used : TaskInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder) Task(org.hl7.fhir.r4.model.Task) TaskPrepareBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskPrepareBundleExtractor) TaskPrepareBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskPrepareBundleFactory) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Bundle(org.hl7.fhir.r4.model.Bundle) TaskPrepareInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskPrepareBundleExtractor.TaskPrepareInfoHolder) TaskCreateException(org.hl7.gravity.refimpl.sdohexchange.exception.TaskCreateException) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) TaskBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskBundleFactory) IdType(org.hl7.fhir.r4.model.IdType) TaskFailBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskFailBundleFactory) CpClientException(org.hl7.gravity.refimpl.sdohexchange.service.CpService.CpClientException) TaskInfoBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor)

Aggregations

IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)2 Bundle (org.hl7.fhir.r4.model.Bundle)2 ServiceRequest (org.hl7.fhir.r4.model.ServiceRequest)2 Task (org.hl7.fhir.r4.model.Task)2 TaskFailBundleFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskFailBundleFactory)2 CpClientException (org.hl7.gravity.refimpl.sdohexchange.service.CpService.CpClientException)2 IdType (org.hl7.fhir.r4.model.IdType)1 TaskCreateException (org.hl7.gravity.refimpl.sdohexchange.exception.TaskCreateException)1 TaskInfoBundleExtractor (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor)1 TaskInfoHolder (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor.TaskInfoHolder)1 TaskPrepareBundleExtractor (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskPrepareBundleExtractor)1 TaskPrepareInfoHolder (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskPrepareBundleExtractor.TaskPrepareInfoHolder)1 TaskUpdateBundleExtractor (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskUpdateBundleExtractor)1 TaskUpdateInfoHolder (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskUpdateBundleExtractor.TaskUpdateInfoHolder)1 TaskBundleFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskBundleFactory)1 TaskPrepareBundleFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskPrepareBundleFactory)1 TaskUpdateBundleFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskUpdateBundleFactory)1