cr-connect-workflow/crc/scripts/set_study_progress_status.py

39 lines
1.9 KiB
Python
Raw Normal View History

from SpiffWorkflow.exceptions import WorkflowTaskExecException
2021-12-02 17:11:28 -05:00
from crc import session
from crc.api.common import ApiError
from crc.models.study import StudyModel, ProgressStatus
2021-12-02 17:11:28 -05:00
from crc.scripts.script import Script
class SetStudyProgressStatus(Script):
2021-12-02 17:11:28 -05:00
def get_description(self):
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
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:
new_status = args[0]
try:
progress_status = getattr(ProgressStatus, new_status)
except AttributeError as ae:
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:
raise WorkflowTaskExecException(task, f"set_study_progress_status() failed You must include the new"
f" progress status when calling `set_study_progress_status` script.")
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
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