mirror of
https://github.com/sartography/cr-connect-workflow.git
synced 2025-02-23 13:18:35 +00:00
Update the study model to include a progress (integer)
This commit is contained in:
parent
791ab20f8c
commit
2ab96b16a0
@ -66,6 +66,7 @@ class StudyModel(db.Model):
|
|||||||
events_history = db.relationship("StudyEvent", cascade="all, delete, delete-orphan")
|
events_history = db.relationship("StudyEvent", cascade="all, delete, delete-orphan")
|
||||||
short_name = db.Column(db.String, nullable=True)
|
short_name = db.Column(db.String, nullable=True)
|
||||||
proposal_name = db.Column(db.String, nullable=True)
|
proposal_name = db.Column(db.String, nullable=True)
|
||||||
|
progress = db.Column(db.Integer, nullable=True)
|
||||||
|
|
||||||
def update_from_protocol_builder(self, study: ProtocolBuilderCreatorStudy, user_id):
|
def update_from_protocol_builder(self, study: ProtocolBuilderCreatorStudy, user_id):
|
||||||
self.title = study.TITLE
|
self.title = study.TITLE
|
||||||
@ -186,7 +187,7 @@ class Study(object):
|
|||||||
id=None, status=None, progress_status=None, irb_status=None, short_name=None, proposal_name=None, comment="",
|
id=None, status=None, progress_status=None, irb_status=None, short_name=None, proposal_name=None, comment="",
|
||||||
sponsor="", ind_number="", categories=[],
|
sponsor="", ind_number="", categories=[],
|
||||||
files=[], approvals=[], enrollment_date=None, events_history=[],
|
files=[], approvals=[], enrollment_date=None, events_history=[],
|
||||||
last_activity_user="",last_activity_date =None,create_user_display="", **argsv):
|
last_activity_user="",last_activity_date =None,create_user_display="", progress=0, **argsv):
|
||||||
self.id = id
|
self.id = id
|
||||||
self.user_uid = user_uid
|
self.user_uid = user_uid
|
||||||
self.create_user_display = create_user_display
|
self.create_user_display = create_user_display
|
||||||
@ -210,6 +211,7 @@ class Study(object):
|
|||||||
self.events_history = events_history
|
self.events_history = events_history
|
||||||
self.short_name = short_name
|
self.short_name = short_name
|
||||||
self.proposal_name = proposal_name
|
self.proposal_name = proposal_name
|
||||||
|
self.progress = progress
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_model(cls, study_model: StudyModel):
|
def from_model(cls, study_model: StudyModel):
|
||||||
@ -274,13 +276,14 @@ class StudySchema(ma.Schema):
|
|||||||
events_history = fields.List(fields.Nested('StudyEventSchema'), dump_only=True)
|
events_history = fields.List(fields.Nested('StudyEventSchema'), dump_only=True)
|
||||||
short_name = fields.String(allow_none=True)
|
short_name = fields.String(allow_none=True)
|
||||||
proposal_name = fields.String(allow_none=True)
|
proposal_name = fields.String(allow_none=True)
|
||||||
|
progress = fields.Integer(allow_none=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Study
|
model = Study
|
||||||
additional = ["id", "title", "short_title", "last_updated", "primary_investigator_id", "user_uid",
|
additional = ["id", "title", "short_title", "last_updated", "primary_investigator_id", "user_uid",
|
||||||
"sponsor", "ind_number", "files", "enrollment_date",
|
"sponsor", "ind_number", "files", "enrollment_date",
|
||||||
"create_user_display", "last_activity_date", "last_activity_user",
|
"create_user_display", "last_activity_date", "last_activity_user",
|
||||||
"events_history", "short_name", "proposal_name"]
|
"events_history", "short_name", "proposal_name", "progress"]
|
||||||
unknown = INCLUDE
|
unknown = INCLUDE
|
||||||
|
|
||||||
@marshmallow.post_load
|
@marshmallow.post_load
|
||||||
|
@ -74,6 +74,7 @@ class StudyService(object):
|
|||||||
studies.append(study)
|
studies.append(study)
|
||||||
return studies
|
return studies
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_study(study_id, categories: List[WorkflowSpecCategory], study_model: StudyModel = None,
|
def get_study(study_id, categories: List[WorkflowSpecCategory], study_model: StudyModel = None,
|
||||||
master_workflow_results=None):
|
master_workflow_results=None):
|
||||||
@ -105,8 +106,21 @@ class StudyService(object):
|
|||||||
study.warnings = StudyService._update_status_of_workflow_meta(workflow_metas,
|
study.warnings = StudyService._update_status_of_workflow_meta(workflow_metas,
|
||||||
master_workflow_results)
|
master_workflow_results)
|
||||||
category.workflows = workflow_metas
|
category.workflows = workflow_metas
|
||||||
|
# Calculate study progress and return it as a integer out of a hundred
|
||||||
|
completed_wfs = 0
|
||||||
|
total_wfs = 0
|
||||||
|
for category in study.categories:
|
||||||
|
for workflow in category.workflows:
|
||||||
|
total_wfs +=1
|
||||||
|
if workflow.status == WorkflowStatus.complete:
|
||||||
|
completed_wfs += 1
|
||||||
|
if total_wfs > 0:
|
||||||
|
study.progress = int((completed_wfs/total_wfs)*100)
|
||||||
|
else:
|
||||||
|
study.progress = 0
|
||||||
return study
|
return study
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_workflow_metas(study_id, category):
|
def _get_workflow_metas(study_id, category):
|
||||||
# Add in the Workflows for each category
|
# Add in the Workflows for each category
|
||||||
@ -266,6 +280,7 @@ class StudyService(object):
|
|||||||
g.doc_statuses[study_id] = StudyService.__get_documents_status(study_id)
|
g.doc_statuses[study_id] = StudyService.__get_documents_status(study_id)
|
||||||
return g.doc_statuses[study_id]
|
return g.doc_statuses[study_id]
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __get_documents_status(study_id):
|
def __get_documents_status(study_id):
|
||||||
"""Returns a list of documents related to the study, and any file information
|
"""Returns a list of documents related to the study, and any file information
|
||||||
|
28
migrations/versions/8f0d445dd297_.py
Normal file
28
migrations/versions/8f0d445dd297_.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 8f0d445dd297
|
||||||
|
Revises: 28752ce0775c
|
||||||
|
Create Date: 2022-03-17 16:51:29.873798
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '8f0d445dd297'
|
||||||
|
down_revision = '28752ce0775c'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.add_column('study', sa.Column('progress', sa.Integer(), nullable=True))
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_column('study', 'progress')
|
||||||
|
# ### end Alembic commands ###
|
Loading…
x
Reference in New Issue
Block a user