diff --git a/migrations/versions/277f05065db0_.py b/migrations/versions/277f05065db0_.py new file mode 100644 index 0000000..5cc74ce --- /dev/null +++ b/migrations/versions/277f05065db0_.py @@ -0,0 +1,37 @@ +"""empty message + +Revision ID: 277f05065db0 +Revises: 119c1269ee7c +Create Date: 2021-04-07 16:14:01.470659 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '277f05065db0' +down_revision = '119c1269ee7c' +branch_labels = None +depends_on = None + + +def upgrade(): + op.create_table('irb_info', + sa.Column('SS_STUDY_ID', sa.Integer(), nullable=False), + sa.Column('UVA_STUDY_TRACKING', sa.String(), nullable=False, default=''), + sa.Column('DATE_MODIFIED', sa.DateTime(timezone=True), nullable=True), + sa.Column('IRB_ADMINISTRATIVE_REVIEWER', sa.String(), nullable=False, default=''), + sa.Column('AGENDA_DATE', sa.DateTime(timezone=True), nullable=True), + sa.Column('IRB_REVIEW_TYPE', sa.String(), nullable=False, default=''), + sa.Column('IRBEVENT', sa.String(), nullable=False, default=''), + sa.Column('IRB_STATUS', sa.String(), nullable=False, default=''), + sa.Column('RB_OF_RECORD', sa.String(), nullable=False, default=''), + sa.Column('UVA_IRB_HSR_IS_IRB_OF_RECORD_FOR_ALL_SITES', sa.Integer(), nullable=True), + sa.Column('STUDYIRBREVIEWERADMIN', sa.String(), nullable=False, default=''), + sa.ForeignKeyConstraint(['SS_STUDY_ID'], ['study.STUDYID'],), + sa.PrimaryKeyConstraint('SS_STUDY_ID')) + + +def downgrade(): + op.drop_table('irb_info') diff --git a/pb/__init__.py b/pb/__init__.py index 29f080a..5aad397 100644 --- a/pb/__init__.py +++ b/pb/__init__.py @@ -160,9 +160,11 @@ def site_map(): # ************************** # WEB FORMS # ************************** -from pb.forms import StudyForm, StudyTable, InvestigatorForm, StudyDetailsForm, ConfirmDeleteForm, StudySponsorForm +from pb.forms import StudyForm, StudyTable, InvestigatorForm, StudyDetailsForm, ConfirmDeleteForm, StudySponsorForm, \ + IRBInfoForm from pb.models import Study, RequiredDocument, Investigator, StudySchema, RequiredDocumentSchema, InvestigatorSchema, \ - StudyDetails, StudyDetailsSchema, StudySponsor, Sponsor, SponsorSchema, StudySponsorSchema, IRBStatus, IRBStatusSchema + StudyDetails, StudyDetailsSchema, StudySponsor, Sponsor, SponsorSchema, StudySponsorSchema, IRBStatus, \ + IRBStatusSchema, IRBInfo, IRBInfoSchema from pb.ldap.ldap_service import LdapService @@ -245,6 +247,29 @@ def edit_study(study_id): ) +@app.route('/irb_info/', methods=['GET', 'POST']) +def edit_irb_info(study_id): + irb_info = db.session.query(IRBInfo).filter(IRBInfo.SS_STUDY_ID == study_id).first() + form = IRBInfoForm(request.form, obj=irb_info) + action = BASE_HREF + "/irb_info/" + study_id + title = "Edit IRB Info #" + study_id + # if request.method == 'GET': + # form.SS_STUDY_ID.data = study_id + if request.method == 'POST': + if form.validate(): + _update_irb_info(study_id, irb_info, form) + flash('IRB Info updated successfully!', 'success') + return redirect_home() + return render_template( + 'form.html', + form=form, + action=action, + title=title, + description_map={}, + base_href=BASE_HREF + ) + + @app.route('/investigator/', methods=['GET', 'POST']) def new_investigator(study_id): form = InvestigatorForm(request.form) @@ -473,6 +498,26 @@ def _update_study(study, form): db.session.commit() +def _update_irb_info(study_id, irb_info, form): + if irb_info is None: + irb_info = IRBInfo(SS_STUDY_ID=study_id) + irb_info.UVA_STUDY_TRACKING = form.UVA_STUDY_TRACKING.data + irb_info.DATE_MODIFIED = form.DATE_MODIFIED.data + irb_info.IRB_ADMINISTRATIVE_REVIEWER = form.IRB_ADMINISTRATIVE_REVIEWER.data + irb_info.AGENDA_DATE = form.AGENDA_DATE.data + irb_info.IRB_REVIEW_TYPE = form.IRB_REVIEW_TYPE.data + irb_info.IRBEVENT = form.IRBEVENT.data + irb_info.IRB_STATUS = form.IRB_STATUS.data + irb_info.RB_OF_RECORD = form.RB_OF_RECORD.data + irb_info.UVA_IRB_HSR_IS_IRB_OF_RECORD_FOR_ALL_SITES = form.UVA_IRB_HSR_IS_IRB_OF_RECORD_FOR_ALL_SITES.data + irb_info.STUDYIRBREVIEWERADMIN = form.STUDYIRBREVIEWERADMIN.data + + db.session.add(irb_info) + db.session.commit() + + print('_update_irb_info') + + def _allowed_file(filename): allowed_extensions = ['csv', 'xls', 'xlsx'] return '.' in filename and \ diff --git a/pb/forms.py b/pb/forms.py index 98ac508..ff69d6b 100644 --- a/pb/forms.py +++ b/pb/forms.py @@ -1,9 +1,9 @@ from flask_table import Table, Col, LinkCol, BoolCol, DatetimeCol, NestedTableCol from flask_wtf import FlaskForm -from wtforms import SelectMultipleField, StringField, BooleanField, SelectField, validators, HiddenField +from wtforms import SelectMultipleField, StringField, BooleanField, SelectField, validators, HiddenField, DateField, IntegerField from wtforms_alchemy import ModelForm -from pb.models import RequiredDocument, Investigator, StudyDetails, IRBStatus +from pb.models import RequiredDocument, Investigator, StudyDetails, IRBStatus, IRBInfo class StudyForm(FlaskForm): @@ -18,6 +18,12 @@ class StudyForm(FlaskForm): choices=[((q.STATUS, q.DETAIL), q.DETAIL) for q in IRBStatus.all()]) +class IRBInfoForm(ModelForm, FlaskForm): + class Meta: + model = IRBInfo + hidden = 'SS_STUDY_ID' + + class InvestigatorForm(FlaskForm): NETBADGEID = StringField('UVA Id') INVESTIGATORTYPE = SelectField("InvestigatorType", choices=[(i.INVESTIGATORTYPE, i.INVESTIGATORTYPEFULL) for i in Investigator.all_types()]) @@ -115,6 +121,11 @@ class StudyTable(Table): anchor_attrs={'class': 'btn btn-icon btn-accent', 'title': 'Edit Sponsor(s)'}, th_html_attrs={'class': 'mat-icon text-center', 'title': 'Edit Sponsor(s)'} ) + irb_info = LinkCol( + 'irb_info', 'edit_irb_info', url_kwargs=dict(study_id='STUDYID'), + anchor_attrs={'class': 'btn btn-icon btn-accent', 'title': 'Edit Info'}, + th_html_attrs={'class': 'mat-icon text-center', 'title': 'Edit Info'} + ) STUDYID = Col('Study Id') TITLE = Col('Title') NETBADGEID = Col('User') diff --git a/pb/models.py b/pb/models.py index f1f8564..bbd49d5 100644 --- a/pb/models.py +++ b/pb/models.py @@ -69,6 +69,7 @@ class Study(db.Model): NETBADGEID = db.Column(db.String(), nullable=False) DATE_MODIFIED = db.Column(db.DateTime(timezone=True), default=func.now()) Q_COMPLETE = db.relationship("IRBStatus", backref="study", lazy='dynamic') + irb_info = db.relationship("IRBInfo", backref="study", lazy='dynamic') requirements = db.relationship("RequiredDocument", backref="study", lazy='dynamic') investigators = db.relationship("Investigator", backref="study", lazy='dynamic') study_details = db.relationship("StudyDetails", uselist=False, backref="study") @@ -82,6 +83,27 @@ class StudySchema(ma.Schema): "DATE_MODIFIED") +class IRBInfo(db.Model): + SS_STUDY_ID = db.Column(db.Integer, db.ForeignKey('study.STUDYID'), primary_key=True) + UVA_STUDY_TRACKING = db.Column(db.String(), nullable=False, default='') + DATE_MODIFIED = db.Column(db.Date, nullable=True) + IRB_ADMINISTRATIVE_REVIEWER = db.Column(db.String(), nullable=False, default='') + AGENDA_DATE = db.Column(db.Date, nullable=True) + IRB_REVIEW_TYPE = db.Column(db.String(), nullable=False, default='') + IRBEVENT = db.Column(db.String(), nullable=False, default='') + IRB_STATUS = db.Column(db.String(), nullable=False, default='') + RB_OF_RECORD = db.Column(db.String(), nullable=False, default='') + UVA_IRB_HSR_IS_IRB_OF_RECORD_FOR_ALL_SITES = db.Column(db.Integer(), nullable=True) + STUDYIRBREVIEWERADMIN = db.Column(db.String(), nullable=False, default='') + + +class IRBInfoSchema(ma.Schema): + class Meta: + # Fields to expose + fields = ("UVA_STUDY_TRACKING", "DATE_MODIFIED", "IRB_ADMINISTRATIVE_REVIEWER", + "AGENDA_DATE", "IRB_REVIEW_TYPE", "IRBEVENT", "IRB_STATUS", "RB_OF_RECORD", + "UVA_IRB_HSR_IS_IRB_OF_RECORD_FOR_ALL_SITES", "STUDYIRBREVIEWERADMIN") + class Investigator(db.Model): id = db.Column(db.Integer, primary_key=True) STUDYID = db.Column(db.Integer, db.ForeignKey('study.STUDYID'))