mirror of
https://github.com/sartography/cr-connect-workflow.git
synced 2025-02-22 20:58:28 +00:00
Fixes for set_study_progress_status to use new ProgressStatus enum
This commit is contained in:
parent
9cd5022bf0
commit
100e822f2e
@ -1,14 +1,14 @@
|
||||
from crc import session
|
||||
from crc.api.common import ApiError
|
||||
from crc.models.study import StudyModel, StudyStatus
|
||||
from crc.models.study import StudyModel, ProgressStatus
|
||||
from crc.scripts.script import Script
|
||||
|
||||
|
||||
class SetStudyStatus(Script):
|
||||
class SetStudyProgressStatus(Script):
|
||||
|
||||
def get_description(self):
|
||||
return """Set the status of the current study.
|
||||
Status can be one of `in_progress`, `hold`, `open_for_enrollment`, or `abandoned`."""
|
||||
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`."""
|
||||
|
||||
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
|
||||
|
||||
@ -19,17 +19,17 @@ class SetStudyStatus(Script):
|
||||
new_status = args[0]
|
||||
|
||||
try:
|
||||
study_status = getattr(StudyStatus, new_status)
|
||||
progress_status = getattr(ProgressStatus, new_status)
|
||||
|
||||
except AttributeError as ae:
|
||||
raise ApiError.from_task(code='invalid_argument',
|
||||
message=f"We could not find a status matching `{new_status}`. Original message: {ae}",
|
||||
task=task)
|
||||
return study_status.value
|
||||
return progress_status.value
|
||||
|
||||
else:
|
||||
raise ApiError.from_task(code='missing_argument',
|
||||
message='You must include the new status when calling `set_study_status` script. '
|
||||
message='You must include the new status when calling `set_study_progress_status` script. '
|
||||
'The new status must be one of `in_progress`, `hold`, `open_for_enrollment`, or `abandoned`.',
|
||||
task=task)
|
||||
|
||||
@ -42,28 +42,26 @@ class SetStudyStatus(Script):
|
||||
else:
|
||||
new_status = args[0]
|
||||
|
||||
# Get StudyStatus object for new_status
|
||||
# Get ProgressStatus object for new_status
|
||||
try:
|
||||
study_status = getattr(StudyStatus, new_status)
|
||||
progress_status = getattr(ProgressStatus, new_status)
|
||||
|
||||
# Invalid argument
|
||||
except AttributeError as ae:
|
||||
raise ApiError.from_task(code='invalid_argument',
|
||||
message=f"We could not find a status matching `{new_status}`. Original message: {ae}"
|
||||
'The new status must be one of `in_progress`, `hold`, `open_for_enrollment`, or `abandoned`.',
|
||||
message=f"We could not find a status matching `{new_status}`. Original message: {ae}.",
|
||||
task=task)
|
||||
|
||||
# Set new status
|
||||
study_model = session.query(StudyModel).filter(StudyModel.id == study_id).first()
|
||||
study_model.status = study_status
|
||||
study_model.progress_status = progress_status
|
||||
session.commit()
|
||||
|
||||
return study_model.status.value
|
||||
return study_model.progress_status.value
|
||||
|
||||
# Missing argument
|
||||
else:
|
||||
raise ApiError.from_task(code='missing_argument',
|
||||
message='You must include the new status when calling `set_study_status` script. '
|
||||
'The new status must be one of `in_progress`, `hold`, `open_for_enrollment`, or `abandoned`.',
|
||||
message='You must include the new progress status when calling `set_study_progress_status` script. ',
|
||||
task=task)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user