Adds study inactive flag. Sets study to inactive if not found in Protocol Builder.
This commit is contained in:
parent
f3068e68db
commit
0cc59d0974
|
@ -1,18 +1,16 @@
|
|||
from typing import List
|
||||
|
||||
from dateutil.parser import parse
|
||||
from connexion import NoContent
|
||||
from flask import g
|
||||
|
||||
from crc import session, auth
|
||||
from crc.api.common import ApiError, ApiErrorSchema
|
||||
from crc.api.workflow import __get_workflow_api_model
|
||||
from crc.models.protocol_builder import ProtocolBuilderStatus, ProtocolBuilderStudy
|
||||
from crc.models.study import StudyModelSchema, StudyModel
|
||||
from models.protocol_builder import ProtocolBuilderStatus, ProtocolBuilderStudy
|
||||
from crc.models.workflow import WorkflowModel, WorkflowApiSchema, WorkflowSpecModel
|
||||
from crc.services import protocol_builder
|
||||
from crc.services.workflow_processor import WorkflowProcessor
|
||||
from services.protocol_builder import ProtocolBuilderService
|
||||
from crc.services.protocol_builder import ProtocolBuilderService
|
||||
|
||||
|
||||
@auth.login_required
|
||||
|
@ -77,10 +75,13 @@ def update_from_protocol_builder():
|
|||
|
||||
db_studies = session.query(StudyModel).filter_by(user_uid=user.uid).all()
|
||||
db_study_ids = list(map(lambda s: s.id, db_studies))
|
||||
pb_study_ids = list(map(lambda s: s.id, pb_studies))
|
||||
|
||||
# Add studies from Protocol Builder that aren't in the database yet
|
||||
for pb_study in pb_studies:
|
||||
if pb_study['HSRNUMBER'] not in db_study_ids:
|
||||
status = ProtocolBuilderStatus.complete._value_ if pb_study['Q_COMPLETE'] else ProtocolBuilderStatus.in_process._value_
|
||||
status = ProtocolBuilderStatus.complete._value_ if pb_study[
|
||||
'Q_COMPLETE'] else ProtocolBuilderStatus.in_process._value_
|
||||
add_study({
|
||||
'id': pb_study['HSRNUMBER'],
|
||||
'title': pb_study['TITLE'],
|
||||
|
@ -89,6 +90,11 @@ def update_from_protocol_builder():
|
|||
'last_updated': pb_study['DATE_MODIFIED']
|
||||
})
|
||||
|
||||
# Mark studies as inactive that are no longer in Protocol Builder
|
||||
for study_id in db_study_ids:
|
||||
if study_id not in pb_study_ids:
|
||||
update_study(study_id=study_id, body={'inactive': True})
|
||||
|
||||
|
||||
def post_update_study_from_protocol_builder(study_id):
|
||||
"""Update a single study based on data received from
|
||||
|
|
|
@ -3,7 +3,7 @@ from marshmallow_sqlalchemy import ModelSchema
|
|||
from sqlalchemy import func
|
||||
|
||||
from crc import db
|
||||
from models.protocol_builder import ProtocolBuilderStatus
|
||||
from crc.models.protocol_builder import ProtocolBuilderStatus
|
||||
|
||||
|
||||
class StudyModel(db.Model):
|
||||
|
@ -17,6 +17,7 @@ class StudyModel(db.Model):
|
|||
ind_number = db.Column(db.String)
|
||||
user_uid = db.Column(db.String, db.ForeignKey('user.uid'), nullable=True)
|
||||
investigator_uids = db.Column(db.ARRAY(db.String))
|
||||
inactive = db.Column(db.Boolean, default=False)
|
||||
|
||||
|
||||
class StudyModelSchema(ModelSchema):
|
||||
|
|
|
@ -4,7 +4,7 @@ from typing import List, Optional
|
|||
import requests
|
||||
|
||||
from crc import app
|
||||
from models.protocol_builder import ProtocolBuilderStudy, ProtocolBuilderStudySchema, ProtocolBuilderInvestigator, \
|
||||
from crc.models.protocol_builder import ProtocolBuilderStudy, ProtocolBuilderStudySchema, ProtocolBuilderInvestigator, \
|
||||
ProtocolBuilderRequiredDocument, ProtocolBuilderStudyDetails, ProtocolBuilderInvestigatorSchema, \
|
||||
ProtocolBuilderRequiredDocumentSchema, ProtocolBuilderStudyDetailsSchema
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: 2c88e49d0ffc
|
||||
Revises: 726d09a4fa0c
|
||||
Create Date: 2020-02-27 11:17:01.768161
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '2c88e49d0ffc'
|
||||
down_revision = '726d09a4fa0c'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('study', sa.Column('inactive', sa.Boolean(), nullable=True))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('study', 'inactive')
|
||||
# ### end Alembic commands ###
|
|
@ -3,7 +3,7 @@ from datetime import datetime, timezone
|
|||
|
||||
from crc import session
|
||||
from crc.models.study import StudyModel, StudyModelSchema
|
||||
from models.protocol_builder import ProtocolBuilderStatus
|
||||
from crc.models.protocol_builder import ProtocolBuilderStatus
|
||||
from crc.models.workflow import WorkflowSpecModel, WorkflowSpecModelSchema, WorkflowModel, WorkflowStatus, \
|
||||
WorkflowApiSchema
|
||||
from tests.base_test import BaseTest
|
||||
|
|
Loading…
Reference in New Issue