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 import session
|
||||||
from crc.api.common import ApiError
|
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
|
from crc.scripts.script import Script
|
||||||
|
|
||||||
|
|
||||||
class SetStudyStatus(Script):
|
class SetStudyProgressStatus(Script):
|
||||||
|
|
||||||
def get_description(self):
|
def get_description(self):
|
||||||
return """Set the status of the current study.
|
return """Set the progress status of the current study.
|
||||||
Status can be one of `in_progress`, `hold`, `open_for_enrollment`, or `abandoned`."""
|
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):
|
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
|
||||||
|
|
||||||
@ -19,17 +19,17 @@ class SetStudyStatus(Script):
|
|||||||
new_status = args[0]
|
new_status = args[0]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
study_status = getattr(StudyStatus, new_status)
|
progress_status = getattr(ProgressStatus, new_status)
|
||||||
|
|
||||||
except AttributeError as ae:
|
except AttributeError as ae:
|
||||||
raise ApiError.from_task(code='invalid_argument',
|
raise ApiError.from_task(code='invalid_argument',
|
||||||
message=f"We could not find a status matching `{new_status}`. Original message: {ae}",
|
message=f"We could not find a status matching `{new_status}`. Original message: {ae}",
|
||||||
task=task)
|
task=task)
|
||||||
return study_status.value
|
return progress_status.value
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ApiError.from_task(code='missing_argument',
|
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`.',
|
'The new status must be one of `in_progress`, `hold`, `open_for_enrollment`, or `abandoned`.',
|
||||||
task=task)
|
task=task)
|
||||||
|
|
||||||
@ -42,28 +42,26 @@ class SetStudyStatus(Script):
|
|||||||
else:
|
else:
|
||||||
new_status = args[0]
|
new_status = args[0]
|
||||||
|
|
||||||
# Get StudyStatus object for new_status
|
# Get ProgressStatus object for new_status
|
||||||
try:
|
try:
|
||||||
study_status = getattr(StudyStatus, new_status)
|
progress_status = getattr(ProgressStatus, new_status)
|
||||||
|
|
||||||
# Invalid argument
|
# Invalid argument
|
||||||
except AttributeError as ae:
|
except AttributeError as ae:
|
||||||
raise ApiError.from_task(code='invalid_argument',
|
raise ApiError.from_task(code='invalid_argument',
|
||||||
message=f"We could not find a status matching `{new_status}`. Original message: {ae}"
|
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`.',
|
|
||||||
task=task)
|
task=task)
|
||||||
|
|
||||||
# Set new status
|
# Set new status
|
||||||
study_model = session.query(StudyModel).filter(StudyModel.id == study_id).first()
|
study_model = session.query(StudyModel).filter(StudyModel.id == study_id).first()
|
||||||
study_model.status = study_status
|
study_model.progress_status = progress_status
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
return study_model.status.value
|
return study_model.progress_status.value
|
||||||
|
|
||||||
# Missing argument
|
# Missing argument
|
||||||
else:
|
else:
|
||||||
raise ApiError.from_task(code='missing_argument',
|
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 progress 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)
|
task=task)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user