mirror of
https://github.com/sartography/cr-connect-workflow.git
synced 2025-02-24 05:38:25 +00:00
Use the actual enum values so we don't have to deal with this the next time we make a change to study status
This commit is contained in:
parent
027e436546
commit
eb7548ea0f
@ -5,14 +5,21 @@ from crc.scripts.script import Script
|
|||||||
|
|
||||||
|
|
||||||
class SetStudyStatus(Script):
|
class SetStudyStatus(Script):
|
||||||
|
@staticmethod
|
||||||
|
def get_study_status_values():
|
||||||
|
study_status_values = []
|
||||||
|
for item in StudyStatus:
|
||||||
|
study_status_values.append(item.value)
|
||||||
|
return study_status_values
|
||||||
|
|
||||||
def get_description(self):
|
def get_description(self):
|
||||||
return """Set the study status. Requires a study status.
|
study_status_values = self.get_study_status_values()
|
||||||
Study status must be 'in_progress', 'hold', 'open_for_enrollment', 'abandoned', or 'cr_connect_complete'."""
|
return f"Set the study status. Requires a study status. Study status must be in {study_status_values}."
|
||||||
|
|
||||||
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):
|
||||||
|
study_status_values = self.get_study_status_values()
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
if args[0] in ['in_progress', 'hold', 'open_for_enrollment', 'abandoned', 'cr_connect_complete']:
|
if args[0] in study_status_values:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
raise ApiError(code='bad_parameter',
|
raise ApiError(code='bad_parameter',
|
||||||
@ -22,8 +29,9 @@ class SetStudyStatus(Script):
|
|||||||
message=f'The set_study_status script requires 1 parameter, {len(args)} were given.')
|
message=f'The set_study_status script requires 1 parameter, {len(args)} were given.')
|
||||||
|
|
||||||
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
|
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
|
||||||
|
study_status_values = self.get_study_status_values()
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
if args[0] in ['in_progress', 'hold', 'open_for_enrollment', 'abandoned', 'cr_connect_complete']:
|
if args[0] in study_status_values:
|
||||||
study = session.query(StudyModel).filter(StudyModel.id==study_id).first()
|
study = session.query(StudyModel).filter(StudyModel.id==study_id).first()
|
||||||
study.status = StudyStatus(args[0]).value
|
study.status = StudyStatus(args[0]).value
|
||||||
session.commit()
|
session.commit()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user