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:
mike cullerton 2022-03-07 13:28:29 -05:00
parent 027e436546
commit eb7548ea0f

View File

@ -5,14 +5,21 @@ from crc.scripts.script import 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):
return """Set the study status. Requires a study status.
Study status must be 'in_progress', 'hold', 'open_for_enrollment', 'abandoned', or 'cr_connect_complete'."""
study_status_values = self.get_study_status_values()
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):
study_status_values = self.get_study_status_values()
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
else:
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.')
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
study_status_values = self.get_study_status_values()
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.status = StudyStatus(args[0]).value
session.commit()