2022-03-14 16:00:53 -04:00
|
|
|
from SpiffWorkflow.exceptions import WorkflowTaskExecException
|
|
|
|
|
2021-12-02 17:11:28 -05:00
|
|
|
from crc import session
|
|
|
|
from crc.api.common import ApiError
|
2021-12-10 16:15:49 -05:00
|
|
|
from crc.models.study import StudyModel, ProgressStatus
|
2021-12-02 17:11:28 -05:00
|
|
|
from crc.scripts.script import Script
|
|
|
|
|
|
|
|
|
2021-12-10 16:15:49 -05:00
|
|
|
class SetStudyProgressStatus(Script):
|
2021-12-02 17:11:28 -05:00
|
|
|
|
|
|
|
def get_description(self):
|
2021-12-10 16:15:49 -05:00
|
|
|
return """Set the progress status of the current study.
|
|
|
|
Progress status can be one of `in_progress`, `submitted_for_pre_review`, `in_pre_review`, `returned_from_pre_review`, `pre_review_complete`, `agenda_date_set`, `approved`, `approved_with_conditions`, `deferred`, or `disapproved`."""
|
2021-12-02 17:11:28 -05:00
|
|
|
|
2022-03-14 16:00:53 -04:00
|
|
|
def get_status(self, task, *args, **kwargs):
|
2021-12-03 12:18:17 -05:00
|
|
|
if 'new_status' in kwargs.keys() or len(args) > 0:
|
|
|
|
if 'new_status' in kwargs.keys():
|
|
|
|
new_status = kwargs['new_status']
|
|
|
|
else:
|
2021-12-03 11:45:02 -05:00
|
|
|
new_status = args[0]
|
|
|
|
try:
|
2021-12-10 16:15:49 -05:00
|
|
|
progress_status = getattr(ProgressStatus, new_status)
|
2021-12-03 11:45:02 -05:00
|
|
|
except AttributeError as ae:
|
2022-03-14 16:00:53 -04:00
|
|
|
raise WorkflowTaskExecException(task, f"set_study_progress_status(). Could not find a status matching"
|
|
|
|
f" `{new_status}`. Original message: {ae}")
|
|
|
|
return progress_status
|
2021-12-02 17:11:28 -05:00
|
|
|
else:
|
2022-03-14 16:00:53 -04:00
|
|
|
raise WorkflowTaskExecException(task, f"set_study_progress_status() failed You must include the new"
|
|
|
|
f" progress status when calling `set_study_progress_status` script.")
|
2021-12-03 11:45:02 -05:00
|
|
|
|
2022-03-14 16:00:53 -04:00
|
|
|
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
|
|
|
|
return self.get_status(task, *args, **kwargs).value
|
2021-12-02 17:11:28 -05:00
|
|
|
|
2022-03-14 16:00:53 -04:00
|
|
|
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
|
|
|
|
study_model = session.query(StudyModel).filter(StudyModel.id == study_id).first()
|
|
|
|
study_model.progress_status = self.get_status(task, *args, **kwargs)
|
|
|
|
session.commit()
|
|
|
|
return study_model.progress_status.value
|