Search in sources :

Example 1 with TaskBundleFactory

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

the class PatientTaskService method newTask.

public String newTask(NewPatientTaskRequestDto taskRequest, UserDto user) {
    Assert.notNull(SmartOnFhirContext.get().getPatient(), "Patient id cannot be null.");
    PatientTaskBundleFactory taskBundleFactory;
    if (taskRequest instanceof NewMakeContactTaskRequestDto) {
        taskBundleFactory = createMakeContactTaskBundleFactory(user, (NewMakeContactTaskRequestDto) taskRequest);
    } else if (taskRequest instanceof NewSocialRiskTaskRequestDto) {
        taskBundleFactory = createSocialRiskTaskBundleFactory(user, (NewSocialRiskTaskRequestDto) taskRequest);
    } else if (taskRequest instanceof NewFeedbackTaskRequestDto) {
        taskBundleFactory = createFeedbackTaskBundleFactory(user, (NewFeedbackTaskRequestDto) taskRequest);
    } else {
        throw new IllegalArgumentException(taskRequest.getClass().getSimpleName() + " instances not supported yet.");
    }
    Bundle taskCreateBundle = ehrClient.transaction().withBundle(taskBundleFactory.createBundle()).execute();
    return FhirUtil.getFromResponseBundle(taskCreateBundle, Task.class).getIdPart();
}
Also used : Task(org.hl7.fhir.r4.model.Task) NewFeedbackTaskRequestDto(org.hl7.gravity.refimpl.sdohexchange.dto.request.patienttask.NewFeedbackTaskRequestDto) Bundle(org.hl7.fhir.r4.model.Bundle) NewSocialRiskTaskRequestDto(org.hl7.gravity.refimpl.sdohexchange.dto.request.patienttask.NewSocialRiskTaskRequestDto) NewMakeContactTaskRequestDto(org.hl7.gravity.refimpl.sdohexchange.dto.request.patienttask.NewMakeContactTaskRequestDto) PatientTaskBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.patienttask.PatientTaskBundleFactory)

Example 2 with TaskBundleFactory

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

the class PatientTaskService method createSocialRiskTaskBundleFactory.

private PatientSocialRiskTaskBundleFactory createSocialRiskTaskBundleFactory(UserDto user, NewSocialRiskTaskRequestDto socialRiskTaskRequest) {
    PatientSocialRiskTaskPrepareBundleFactory taskPrepareBundleFactory = new PatientSocialRiskTaskPrepareBundleFactory(SmartOnFhirContext.get().getPatient(), user.getId(), socialRiskTaskRequest.getQuestionnaireId());
    Bundle taskRelatedResources = ehrClient.transaction().withBundle(taskPrepareBundleFactory.createPrepareBundle()).execute();
    PatientSocialRiskTaskPrepareBundleExtractor.PatientSocialRiskTaskPrepareInfoHolder taskPrepareInfoHolder = new PatientSocialRiskTaskPrepareBundleExtractor().extract(taskRelatedResources);
    PatientSocialRiskTaskBundleFactory taskBundleFactory = new PatientSocialRiskTaskBundleFactory();
    taskBundleFactory.setName(socialRiskTaskRequest.getName());
    taskBundleFactory.setPatient(taskPrepareInfoHolder.getPatient());
    taskBundleFactory.setPriority(socialRiskTaskRequest.getPriority());
    taskBundleFactory.setOccurrence(socialRiskTaskRequest.getOccurrence());
    taskBundleFactory.setRequester(taskPrepareInfoHolder.getPerformer());
    taskBundleFactory.setComment(socialRiskTaskRequest.getComment());
    taskBundleFactory.setUser(user);
    taskBundleFactory.setQuestionniare(taskPrepareInfoHolder.getQuestionnaire());
    return taskBundleFactory;
}
Also used : PatientSocialRiskTaskPrepareBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.patienttask.PatientSocialRiskTaskPrepareBundleFactory) PatientSocialRiskTaskBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.patienttask.PatientSocialRiskTaskBundleFactory) Bundle(org.hl7.fhir.r4.model.Bundle) PatientSocialRiskTaskPrepareBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.patienttask.PatientSocialRiskTaskPrepareBundleExtractor)

Example 3 with TaskBundleFactory

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

the class PatientTaskService method createFeedbackTaskBundleFactory.

private PatientTaskBundleFactory createFeedbackTaskBundleFactory(UserDto user, NewFeedbackTaskRequestDto feedbackTaskRequest) {
    PatientFeedbackTaskPrepareBundleFactory taskPrepareBundleFactory = new PatientFeedbackTaskPrepareBundleFactory(SmartOnFhirContext.get().getPatient(), user.getId(), feedbackTaskRequest.getReferralTaskId());
    Bundle taskRelatedResources = ehrClient.transaction().withBundle(taskPrepareBundleFactory.createPrepareBundle()).execute();
    PatientFeedbackTaskPrepareBundleExtractor.PatientFeedbackTaskPrepareInfoHolder taskPrepareInfoHolder = new PatientFeedbackTaskPrepareBundleExtractor().extract(taskRelatedResources);
    PatientFeedbackTaskBundleFactory taskBundleFactory = new PatientFeedbackTaskBundleFactory();
    taskBundleFactory.setName(feedbackTaskRequest.getName());
    taskBundleFactory.setPatient(taskPrepareInfoHolder.getPatient());
    taskBundleFactory.setPriority(feedbackTaskRequest.getPriority());
    taskBundleFactory.setOccurrence(feedbackTaskRequest.getOccurrence());
    taskBundleFactory.setRequester(taskPrepareInfoHolder.getPerformer());
    // TODO verify whether the passed Task instance is related to the Patient
    taskBundleFactory.setReferralTask(taskPrepareInfoHolder.getReferralTask());
    taskBundleFactory.setComment(feedbackTaskRequest.getComment());
    taskBundleFactory.setUser(user);
    return taskBundleFactory;
}
Also used : PatientFeedbackTaskBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.patienttask.PatientFeedbackTaskBundleFactory) PatientFeedbackTaskPrepareBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.patienttask.PatientFeedbackTaskPrepareBundleExtractor) Bundle(org.hl7.fhir.r4.model.Bundle) PatientFeedbackTaskPrepareBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.patienttask.PatientFeedbackTaskPrepareBundleFactory)

Example 4 with TaskBundleFactory

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

the class PatientTaskService method createMakeContactTaskBundleFactory.

private PatientMakeContactTaskBundleFactory createMakeContactTaskBundleFactory(UserDto user, NewMakeContactTaskRequestDto makeContactTaskRequest) {
    PatientMakeContactTaskPrepareBundleFactory taskPrepareBundleFactory = new PatientMakeContactTaskPrepareBundleFactory(SmartOnFhirContext.get().getPatient(), user.getId(), makeContactTaskRequest.getHealthcareServiceId(), makeContactTaskRequest.getReferralTaskId());
    Bundle taskRelatedResources = ehrClient.transaction().withBundle(taskPrepareBundleFactory.createPrepareBundle()).execute();
    PatientMakeContactTaskPrepareBundleExtractor.PatientMakeContactTaskPrepareInfoHolder taskPrepareInfoHolder = new PatientMakeContactTaskPrepareBundleExtractor().extract(taskRelatedResources);
    PatientMakeContactTaskBundleFactory taskBundleFactory = new PatientMakeContactTaskBundleFactory();
    taskBundleFactory.setName(makeContactTaskRequest.getName());
    taskBundleFactory.setPatient(taskPrepareInfoHolder.getPatient());
    taskBundleFactory.setPriority(makeContactTaskRequest.getPriority());
    taskBundleFactory.setOccurrence(makeContactTaskRequest.getOccurrence());
    taskBundleFactory.setRequester(taskPrepareInfoHolder.getPerformer());
    // TODO verify whether the passed Task instance is related to the Patient
    taskBundleFactory.setReferralTask(taskPrepareInfoHolder.getReferralTask());
    taskBundleFactory.setComment(makeContactTaskRequest.getComment());
    taskBundleFactory.setUser(user);
    // TODO verify whether the passed HealthcareService instance is related to the task
    taskBundleFactory.setContactInfo(taskPrepareInfoHolder.getHealthcareService());
    return taskBundleFactory;
}
Also used : PatientMakeContactTaskBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.patienttask.PatientMakeContactTaskBundleFactory) Bundle(org.hl7.fhir.r4.model.Bundle) PatientMakeContactTaskPrepareBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.patienttask.PatientMakeContactTaskPrepareBundleFactory) PatientMakeContactTaskPrepareBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.patienttask.PatientMakeContactTaskPrepareBundleExtractor)

Example 5 with TaskBundleFactory

use of org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskBundleFactory 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

Bundle (org.hl7.fhir.r4.model.Bundle)5 Task (org.hl7.fhir.r4.model.Task)2 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)1 IdType (org.hl7.fhir.r4.model.IdType)1 ServiceRequest (org.hl7.fhir.r4.model.ServiceRequest)1 NewFeedbackTaskRequestDto (org.hl7.gravity.refimpl.sdohexchange.dto.request.patienttask.NewFeedbackTaskRequestDto)1 NewMakeContactTaskRequestDto (org.hl7.gravity.refimpl.sdohexchange.dto.request.patienttask.NewMakeContactTaskRequestDto)1 NewSocialRiskTaskRequestDto (org.hl7.gravity.refimpl.sdohexchange.dto.request.patienttask.NewSocialRiskTaskRequestDto)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 PatientFeedbackTaskPrepareBundleExtractor (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.patienttask.PatientFeedbackTaskPrepareBundleExtractor)1 PatientMakeContactTaskPrepareBundleExtractor (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.patienttask.PatientMakeContactTaskPrepareBundleExtractor)1 PatientSocialRiskTaskPrepareBundleExtractor (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.patienttask.PatientSocialRiskTaskPrepareBundleExtractor)1 TaskBundleFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskBundleFactory)1 TaskFailBundleFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskFailBundleFactory)1 TaskPrepareBundleFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.factory.TaskPrepareBundleFactory)1 PatientFeedbackTaskBundleFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.factory.patienttask.PatientFeedbackTaskBundleFactory)1