mirror of
https://github.com/sartography/cr-connect-workflow.git
synced 2025-02-23 13:18:35 +00:00
Merge pull request #483 from sartography/chore/study-status-changes-653
Chore/study status changes #653
This commit is contained in:
commit
eae0b5286e
@ -18,6 +18,7 @@ class StudyStatus(enum.Enum):
|
||||
hold = 'hold'
|
||||
open_for_enrollment = 'open_for_enrollment'
|
||||
abandoned = 'abandoned'
|
||||
cr_connect_complete = 'cr_connect_complete'
|
||||
|
||||
|
||||
class ProgressStatus(enum.Enum):
|
||||
|
37
crc/scripts/set_study_status.py
Normal file
37
crc/scripts/set_study_status.py
Normal file
@ -0,0 +1,37 @@
|
||||
from crc import session
|
||||
from crc.api.common import ApiError
|
||||
from crc.models.study import StudyModel, StudyStatus
|
||||
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):
|
||||
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 study_status_values:
|
||||
return True
|
||||
else:
|
||||
raise ApiError(code='bad_parameter',
|
||||
message=f"The set_study_status script requires 1 parameter, from 'in_progress', 'hold', 'open_for_enrollment', 'abandoned', or 'cr_connect_complete'. You sent: {args[0]}.")
|
||||
else:
|
||||
raise ApiError(code='bad_parameter_count',
|
||||
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 study_status_values:
|
||||
study = session.query(StudyModel).filter(StudyModel.id==study_id).first()
|
||||
study.status = StudyStatus(args[0]).value
|
||||
session.commit()
|
42
migrations/versions/cf57eba23a16_new_study_status.py
Normal file
42
migrations/versions/cf57eba23a16_new_study_status.py
Normal file
@ -0,0 +1,42 @@
|
||||
"""new study status 'cr_connect_complete'
|
||||
|
||||
Revision ID: cf57eba23a16
|
||||
Revises: 3c56c894ff5c
|
||||
Create Date: 2022-03-03 08:04:24.292180
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
from crc.models.study import StudyModel, StudyStatus
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'cf57eba23a16'
|
||||
down_revision = '3c56c894ff5c'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# add cr_connect_complete to studystatus
|
||||
op.execute('ALTER TYPE studystatus RENAME TO studystatus_old;')
|
||||
op.execute("CREATE TYPE studystatus AS ENUM('in_progress', 'hold', 'open_for_enrollment', 'abandoned', 'cr_connect_complete')")
|
||||
op.execute("ALTER TABLE study ALTER COLUMN status TYPE studystatus USING status::text::studystatus;")
|
||||
op.execute('DROP TYPE studystatus_old;')
|
||||
|
||||
|
||||
def downgrade():
|
||||
# Removing cr_connect_complete, so change those to in_progress first
|
||||
bind = op.get_bind()
|
||||
session = sa.orm.Session(bind=bind)
|
||||
session.flush()
|
||||
studies = session.query(StudyModel).filter(StudyModel.status=='cr_connect_complete').all()
|
||||
for study in studies:
|
||||
study.status = StudyStatus('in_progress')
|
||||
session.commit()
|
||||
|
||||
# delete cr_connect_complete from studystatus
|
||||
op.execute('ALTER TYPE studystatus RENAME TO studystatus_old;')
|
||||
op.execute("CREATE TYPE studystatus AS ENUM('in_progress', 'hold', 'open_for_enrollment', 'abandoned')")
|
||||
op.execute("ALTER TABLE study ALTER COLUMN status TYPE studystatus USING status::text::studystatus;")
|
||||
op.execute('DROP TYPE studystatus_old;')
|
51
tests/data/set_study_status/set_study_status.bpmn
Normal file
51
tests/data/set_study_status/set_study_status.bpmn
Normal file
@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_7fa2a49" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.2.0">
|
||||
<bpmn:process id="Process_SetStudyStatus" name="Set Study Status" isExecutable="true">
|
||||
<bpmn:startEvent id="StartEvent_1">
|
||||
<bpmn:outgoing>Flow_1id1rb8</bpmn:outgoing>
|
||||
</bpmn:startEvent>
|
||||
<bpmn:sequenceFlow id="Flow_1id1rb8" sourceRef="StartEvent_1" targetRef="Activity_Pause" />
|
||||
<bpmn:endEvent id="Event_0ky05kq">
|
||||
<bpmn:incoming>Flow_0kxs039</bpmn:incoming>
|
||||
</bpmn:endEvent>
|
||||
<bpmn:sequenceFlow id="Flow_0kxs039" sourceRef="Activity_SetStudyStatus" targetRef="Event_0ky05kq" />
|
||||
<bpmn:scriptTask id="Activity_SetStudyStatus" name="Set Study Status">
|
||||
<bpmn:incoming>Flow_1wyotj4</bpmn:incoming>
|
||||
<bpmn:outgoing>Flow_0kxs039</bpmn:outgoing>
|
||||
<bpmn:script>set_study_status('cr_connect_complete')</bpmn:script>
|
||||
</bpmn:scriptTask>
|
||||
<bpmn:sequenceFlow id="Flow_1wyotj4" sourceRef="Activity_Pause" targetRef="Activity_SetStudyStatus" />
|
||||
<bpmn:manualTask id="Activity_Pause" name="Pause">
|
||||
<bpmn:incoming>Flow_1id1rb8</bpmn:incoming>
|
||||
<bpmn:outgoing>Flow_1wyotj4</bpmn:outgoing>
|
||||
</bpmn:manualTask>
|
||||
</bpmn:process>
|
||||
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
|
||||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_SetStudyStatus">
|
||||
<bpmndi:BPMNEdge id="Flow_1id1rb8_di" bpmnElement="Flow_1id1rb8">
|
||||
<di:waypoint x="215" y="117" />
|
||||
<di:waypoint x="280" y="117" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="Flow_0kxs039_di" bpmnElement="Flow_0kxs039">
|
||||
<di:waypoint x="570" y="117" />
|
||||
<di:waypoint x="642" y="117" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge id="Flow_1wyotj4_di" bpmnElement="Flow_1wyotj4">
|
||||
<di:waypoint x="380" y="117" />
|
||||
<di:waypoint x="470" y="117" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
|
||||
<dc:Bounds x="179" y="99" width="36" height="36" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Event_0ky05kq_di" bpmnElement="Event_0ky05kq">
|
||||
<dc:Bounds x="642" y="99" width="36" height="36" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Activity_1mxl8q8_di" bpmnElement="Activity_SetStudyStatus">
|
||||
<dc:Bounds x="470" y="77" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape id="Activity_1ds8uv8_di" bpmnElement="Activity_Pause">
|
||||
<dc:Bounds x="280" y="77" width="100" height="80" />
|
||||
</bpmndi:BPMNShape>
|
||||
</bpmndi:BPMNPlane>
|
||||
</bpmndi:BPMNDiagram>
|
||||
</bpmn:definitions>
|
22
tests/scripts/test_set_study_status.py
Normal file
22
tests/scripts/test_set_study_status.py
Normal file
@ -0,0 +1,22 @@
|
||||
from tests.base_test import BaseTest
|
||||
|
||||
from crc import session
|
||||
from crc.models.study import StudyModel
|
||||
|
||||
|
||||
class TestSetStudyStatus(BaseTest):
|
||||
|
||||
def test_set_study_status(self):
|
||||
workflow = self.create_workflow('set_study_status')
|
||||
workflow_api = self.get_workflow_api(workflow)
|
||||
task = workflow_api.next_task
|
||||
|
||||
# assert we start with in_progress
|
||||
status = session.query(StudyModel.status).filter(StudyModel.id==workflow.study_id).scalar()
|
||||
self.assertEqual('in_progress', status.value)
|
||||
|
||||
# the workflow sets the status to cr_connect_complete
|
||||
self.complete_form(workflow, task, {})
|
||||
|
||||
status = session.query(StudyModel.status).filter(StudyModel.id==workflow.study_id).scalar()
|
||||
self.assertEqual('cr_connect_complete', status.value)
|
Loading…
x
Reference in New Issue
Block a user