Adds is_status flag to workflow_spec, status_spec_id & version to study, and is_active flag to WorkflowApi

This commit is contained in:
Aaron Louie 2020-03-15 15:52:59 -04:00
parent b1a6c9b6c7
commit e4af6f77d0
4 changed files with 42 additions and 16 deletions

View File

@ -95,7 +95,8 @@ class TaskSchema(ma.Schema):
class WorkflowApi(object):
def __init__(self, id, status, user_tasks, last_task, next_task, workflow_spec_id, spec_version, is_latest_spec):
def __init__(self, id, status, user_tasks, last_task, next_task, workflow_spec_id, spec_version,
is_latest_spec, is_active):
self.id = id
self.status = status
self.user_tasks = user_tasks
@ -104,13 +105,13 @@ class WorkflowApi(object):
self.workflow_spec_id = workflow_spec_id
self.spec_version = spec_version
self.is_latest_spec = is_latest_spec
self.is_active = is_active
class WorkflowApiSchema(ma.Schema):
class Meta:
model = WorkflowApi
fields = ["id", "status", "user_tasks", "last_task", "next_task",
"workflow_spec_id", "spec_version", "is_latest_spec",
"num_tasks_total", "num_tasks_complete", "num_tasks_incomplete"]
"workflow_spec_id", "spec_version", "is_latest_spec", "is_active"]
unknown = INCLUDE
status = EnumField(WorkflowStatus)
@ -120,15 +121,7 @@ class WorkflowApiSchema(ma.Schema):
@marshmallow.post_load
def make_workflow(self, data, **kwargs):
keys = [
'id',
'status',
'user_tasks',
'last_task',
'next_task',
'workflow_spec_id',
'spec_version',
'is_latest_spec'
]
keys = ['id', 'status', 'user_tasks', 'last_task', 'next_task',
'workflow_spec_id', 'spec_version', 'is_latest_spec', "is_active"]
filtered_fields = {key: data[key] for key in keys}
return WorkflowApi(**filtered_fields)

View File

@ -1,6 +1,6 @@
from marshmallow_enum import EnumField
from marshmallow_sqlalchemy import ModelSchema
from sqlalchemy import func
from sqlalchemy import func, Column
from crc import db
from crc.models.protocol_builder import ProtocolBuilderStatus
@ -20,6 +20,8 @@ class StudyModel(db.Model):
investigator_uids = db.Column(db.ARRAY(db.String), nullable=True)
inactive = db.Column(db.Boolean, default=False)
requirements = db.Column(db.ARRAY(db.Integer), nullable=True)
status_spec_id = db.Column(db.String, db.ForeignKey('workflow_spec.id'))
status_spec_version = db.Column(db.String)
class StudyModelSchema(ModelSchema):

View File

@ -25,7 +25,7 @@ class WorkflowSpecModel(db.Model):
primary_process_id = db.Column(db.String)
workflow_spec_category_id = db.Column(db.Integer, db.ForeignKey('workflow_spec_category.id'))
workflow_spec_category = db.relationship("WorkflowSpecCategoryModel")
is_status = db.Column(db.Boolean)
is_status = db.Column(db.Boolean, default=False)
class WorkflowSpecModelSchema(ModelSchema):
@ -49,4 +49,3 @@ class WorkflowModel(db.Model):
study_id = db.Column(db.Integer, db.ForeignKey('study.id'))
workflow_spec_id = db.Column(db.String, db.ForeignKey('workflow_spec.id'))
spec_version = db.Column(db.String)

View File

@ -0,0 +1,32 @@
"""empty message
Revision ID: 65f3fce6031a
Revises: 5f06108116ae
Create Date: 2020-03-15 12:40:42.314190
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '65f3fce6031a'
down_revision = '5f06108116ae'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('study', sa.Column('status_spec_id', sa.String(), nullable=True))
op.add_column('study', sa.Column('status_spec_version', sa.String(), nullable=True))
op.create_foreign_key(None, 'study', 'workflow_spec', ['status_spec_id'], ['id'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'study', type_='foreignkey')
op.drop_column('study', 'status_spec_version')
op.drop_column('study', 'status_spec_id')
# ### end Alembic commands ###