Merge remote-tracking branch 'origin/chore/study-progress' into staging-500-error

This commit is contained in:
Dan 2022-03-18 12:59:31 -04:00
commit 405c63aaef
4 changed files with 82 additions and 4 deletions

View File

@ -70,6 +70,7 @@ class StudyModel(db.Model):
on_hold = db.Column(db.Boolean, default=False)
proposal_name = db.Column(db.String, nullable=True)
short_name = db.Column(db.String, nullable=True)
progress = db.Column(db.Integer, nullable=True)
def update_from_protocol_builder(self, study: ProtocolBuilderCreatorStudy, user_id):
self.title = study.TITLE
@ -213,8 +214,8 @@ class Study(object):
comment="",
sponsor="", ind_number="", categories=[],
files=[], approvals=[], enrollment_date=None, events_history=[],
last_activity_user="", last_activity_date=None, create_user_display="",
primary_investigator="", **argsv):
primary_investigator="",
last_activity_user="",last_activity_date =None,create_user_display="", progress=0, **argsv):
self.id = id
self.user_uid = user_uid
self.create_user_display = create_user_display
@ -238,6 +239,7 @@ class Study(object):
self.short_name = short_name
self.proposal_name = proposal_name
self.primary_investigator = primary_investigator
self.progress = progress
@classmethod
def from_model(cls, study_model: StudyModel):
@ -301,13 +303,14 @@ class StudySchema(ma.Schema):
proposal_name = fields.String(allow_none=True)
review_type = fields.Integer(allow_none=True)
primary_investigator = fields.String(allow_none=True)
progress = fields.Integer(allow_none=True)
class Meta:
model = Study
additional = ["id", "title", "short_title", "last_updated", "user_uid",
"sponsor", "ind_number", "files", "enrollment_date",
"create_user_display", "last_activity_date", "last_activity_user",
"events_history", "short_name", "proposal_name", "primary_investigator"]
"events_history", "short_name", "proposal_name", "progress", "primary_investigator"]
unknown = INCLUDE
@marshmallow.post_load

View File

@ -65,16 +65,20 @@ class StudyService(object):
studies.append(study)
return studies
@staticmethod
@timeit
def get_study(study_id, categories: List[WorkflowSpecCategory], study_model: StudyModel = None,
master_workflow_results=None):
"""Returns a study model that contains all the workflows organized by category.
Pass in the results of the master workflow spec, and the status of other workflows will be updated."""
last_time = firsttime()
if not study_model:
study_model = session.query(StudyModel).filter_by(id=study_id).first()
study = Study.from_model(study_model)
last_time = sincetime("from model", last_time)
study.create_user_display = LdapService.user_info(study.user_uid).display_name
last_time = sincetime("user", last_time)
last_event: TaskEventModel = session.query(TaskEventModel) \
.filter_by(study_id=study_id, action='COMPLETE') \
.order_by(TaskEventModel.date.desc()).first()
@ -84,11 +88,13 @@ class StudyService(object):
else:
study.last_activity_user = LdapService.user_info(last_event.user_uid).display_name
study.last_activity_date = last_event.date
last_time = sincetime("task_events", last_time)
study.categories = categories
files = UserFileService.get_files_for_study(study.id)
files = (File.from_models(model, UserFileService.get_file_data(model.id),
DocumentService.get_dictionary()) for model in files)
study.files = list(files)
last_time = sincetime("files", last_time)
if study.status != StudyStatus.abandoned:
for category in study.categories:
workflow_metas = StudyService._get_workflow_metas(study_id, category)
@ -99,13 +105,29 @@ class StudyService(object):
category_meta = StudyService._update_status_of_category_meta(master_workflow_results, category)
category.workflows = workflow_metas
category.meta = category_meta
last_time = sincetime("categories", last_time)
if study.primary_investigator is None:
associates = StudyService().get_study_associates(study.id)
for associate in associates:
if associate.role == "Primary Investigator":
study.primary_investigator = associate.ldap_info.display_name
# Calculate study progress and return it as a integer out of a hundred
last_time = sincetime("PI", last_time)
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
last_time = sincetime("progress", last_time)
@staticmethod
def _get_workflow_metas(study_id, category):
@ -267,6 +289,7 @@ class StudyService(object):
g.doc_statuses[study_id] = StudyService.__get_documents_status(study_id)
return g.doc_statuses[study_id]
@staticmethod
def __get_documents_status(study_id):
"""Returns a list of documents related to the study, and any file information

View 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 ###

View File

@ -0,0 +1,24 @@
"""merge multiple heads
Revision ID: a345e44ecd27
Revises: 2b1ec2118bf3, 8f0d445dd297
Create Date: 2022-03-18 12:40:48.019863
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'a345e44ecd27'
down_revision = ('2b1ec2118bf3', '8f0d445dd297')
branch_labels = None
depends_on = None
def upgrade():
pass
def downgrade():
pass