From eb7548ea0f7f434b9fbebb2eaceecebb245cd426 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Mon, 7 Mar 2022 13:28:29 -0500 Subject: [PATCH] Use the actual enum values so we don't have to deal with this the next time we make a change to study status --- crc/scripts/set_study_status.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crc/scripts/set_study_status.py b/crc/scripts/set_study_status.py index 5036ad1e..40b9c245 100644 --- a/crc/scripts/set_study_status.py +++ b/crc/scripts/set_study_status.py @@ -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()