2020-07-15 02:16:44 +00:00
|
|
|
from marshmallow import INCLUDE, fields
|
|
|
|
from marshmallow_sqlalchemy import SQLAlchemyAutoSchema
|
|
|
|
|
|
|
|
from crc import db, ma
|
|
|
|
from crc.models.study import StudyModel, StudySchema, WorkflowMetadataSchema, WorkflowMetadata
|
|
|
|
from crc.models.workflow import WorkflowModel
|
2021-02-18 13:44:44 +00:00
|
|
|
from crc.services.ldap_service import LdapService
|
2021-04-28 14:00:22 +00:00
|
|
|
from sqlalchemy import func
|
2020-07-15 02:16:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TaskEventModel(db.Model):
|
|
|
|
__tablename__ = 'task_event'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2021-04-26 12:36:09 +00:00
|
|
|
study_id = db.Column(db.Integer, db.ForeignKey('study.id'))
|
2020-07-15 02:16:44 +00:00
|
|
|
user_uid = db.Column(db.String, nullable=False) # In some cases the unique user id may not exist in the db yet.
|
|
|
|
workflow_id = db.Column(db.Integer, db.ForeignKey('workflow.id'), nullable=False)
|
|
|
|
workflow_spec_id = db.Column(db.String, db.ForeignKey('workflow_spec.id'))
|
|
|
|
spec_version = db.Column(db.String)
|
|
|
|
action = db.Column(db.String)
|
|
|
|
task_id = db.Column(db.String)
|
|
|
|
task_name = db.Column(db.String)
|
|
|
|
task_title = db.Column(db.String)
|
|
|
|
task_type = db.Column(db.String)
|
|
|
|
task_state = db.Column(db.String)
|
|
|
|
task_lane = db.Column(db.String)
|
|
|
|
form_data = db.Column(db.JSON) # And form data submitted when the task was completed.
|
|
|
|
mi_type = db.Column(db.String)
|
|
|
|
mi_count = db.Column(db.Integer)
|
|
|
|
mi_index = db.Column(db.Integer)
|
|
|
|
process_name = db.Column(db.String)
|
2021-04-28 14:00:22 +00:00
|
|
|
date = db.Column(db.DateTime(timezone=True),default=func.now())
|
2020-07-15 02:16:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TaskEventModelSchema(SQLAlchemyAutoSchema):
|
|
|
|
class Meta:
|
|
|
|
model = TaskEventModel
|
|
|
|
load_instance = True
|
|
|
|
include_relationships = True
|
|
|
|
include_fk = True # Includes foreign keys
|
|
|
|
|
|
|
|
|
|
|
|
class TaskEvent(object):
|
|
|
|
def __init__(self, model: TaskEventModel, study: StudyModel, workflow: WorkflowMetadata):
|
|
|
|
self.id = model.id
|
|
|
|
self.study = study
|
|
|
|
self.workflow = workflow
|
|
|
|
self.user_uid = model.user_uid
|
2021-02-18 13:44:44 +00:00
|
|
|
self.user_display = LdapService.user_info(model.user_uid).display_name
|
2020-07-15 02:16:44 +00:00
|
|
|
self.action = model.action
|
|
|
|
self.task_id = model.task_id
|
|
|
|
self.task_title = model.task_title
|
|
|
|
self.task_name = model.task_name
|
|
|
|
self.task_type = model.task_type
|
|
|
|
self.task_state = model.task_state
|
|
|
|
self.task_lane = model.task_lane
|
2020-07-22 18:47:53 +00:00
|
|
|
self.date = model.date
|
2020-07-15 02:16:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TaskEventSchema(ma.Schema):
|
|
|
|
|
|
|
|
study = fields.Nested(StudySchema, dump_only=True)
|
|
|
|
workflow = fields.Nested(WorkflowMetadataSchema, dump_only=True)
|
2020-07-28 14:16:48 +00:00
|
|
|
task_lane = fields.String(allow_none=True, required=False)
|
2020-07-15 02:16:44 +00:00
|
|
|
class Meta:
|
|
|
|
model = TaskEvent
|
2021-02-18 13:44:44 +00:00
|
|
|
additional = ["id", "user_uid", "user_display", "action", "task_id", "task_title",
|
2020-07-22 18:47:53 +00:00
|
|
|
"task_name", "task_type", "task_state", "task_lane", "date"]
|
2020-07-15 02:16:44 +00:00
|
|
|
unknown = INCLUDE
|