mirror of
https://github.com/sartography/protocol-builder-mock.git
synced 2025-02-11 23:27:18 +00:00
Add / Remove personnel
This commit is contained in:
parent
51c9b8be86
commit
d8cf97fa4a
46
app.py
46
app.py
@ -59,8 +59,8 @@ def site_map():
|
||||
|
||||
app.config['SECRET_KEY'] = 'a really really really really long secret key'
|
||||
|
||||
from forms import StudyForm, StudySearchForm, StudyTable
|
||||
from models import Study, RequiredDocument
|
||||
from forms import StudyForm, StudySearchForm, StudyTable, InvestigatorForm
|
||||
from models import Study, RequiredDocument, Investigator
|
||||
|
||||
|
||||
@app.route('/', methods=['GET', 'POST'])
|
||||
@ -75,13 +75,14 @@ def index():
|
||||
def new_study():
|
||||
form = StudyForm(request.form)
|
||||
action = "/new_study"
|
||||
title = "New Study"
|
||||
if request.method == 'POST':
|
||||
study = Study()
|
||||
_update_study(study, form)
|
||||
flash('Study created successfully!')
|
||||
return redirect('/')
|
||||
|
||||
return render_template('study_form.html', form=form)
|
||||
return render_template('form.html', form=form)
|
||||
|
||||
@app.route('/study/<study_id>}', methods=['GET', 'POST'])
|
||||
def edit_study(study_id):
|
||||
@ -89,13 +90,48 @@ def edit_study(study_id):
|
||||
form = StudyForm(request.form, obj=study)
|
||||
if request.method == 'GET':
|
||||
action = "/study/" + study_id
|
||||
title = "Edit Study #" + study_id
|
||||
if study.requirements:
|
||||
form.requirements.data = list(map(lambda r: r.code, list(study.requirements)))
|
||||
if study.q_complete:
|
||||
form.q_complete.checked = True
|
||||
if request.method == 'POST':
|
||||
_update_study(study, form)
|
||||
flash('Study updated successfully!')
|
||||
return redirect('/')
|
||||
return render_template('study_form.html', form=form)
|
||||
return render_template('form.html', form=form)
|
||||
|
||||
|
||||
@app.route('/investigator/<study_id>}', methods=['GET', 'POST'])
|
||||
def new_investigator(study_id):
|
||||
form = InvestigatorForm(request.form)
|
||||
action = "/investigator/" + study_id
|
||||
title = "Add Investigator to Study " + study_id
|
||||
if request.method == 'POST':
|
||||
investigator = Investigator(study_id=study_id)
|
||||
investigator.netbadge_id = form.netbadge_id.data
|
||||
investigator.type = form.type.data
|
||||
investigator.description = form.type.label.text
|
||||
db.session.add(investigator)
|
||||
db.session.commit()
|
||||
flash('Investigator created successfully!')
|
||||
return redirect('/')
|
||||
|
||||
return render_template('form.html', form=form)
|
||||
|
||||
|
||||
@app.route('/del_investigator/<inv_id>}', methods=['GET'])
|
||||
def del_investigator(inv_id):
|
||||
db.session.query(Investigator).filter(Investigator.id == inv_id).delete()
|
||||
db.session.commit()
|
||||
return redirect('/')
|
||||
|
||||
|
||||
@app.route('/del_study/<study_id>}', methods=['GET'])
|
||||
def del_study(study_id):
|
||||
db.session.query(Study).filter(Study.study_id == study_id).delete()
|
||||
db.session.commit()
|
||||
return redirect('/')
|
||||
|
||||
|
||||
def _update_study(study, form):
|
||||
@ -109,11 +145,13 @@ def _update_study(study, form):
|
||||
study.netbadge_id = form.netbadge_id.data
|
||||
study.last_updated = datetime.datetime.now()
|
||||
study.q_complete = form.q_complete.data
|
||||
study.hsr_number = form.hsr_number.data
|
||||
db.session.add(study)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# run our standalone gevent server
|
||||
app.run(port=4200)
|
26
forms.py
26
forms.py
@ -1,8 +1,9 @@
|
||||
from flask_table import Table, Col, DateCol, LinkCol, BoolCol, DatetimeCol, NestedTableCol
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import SelectMultipleField, SubmitField, StringField, IntegerField, BooleanField, DateField, widgets
|
||||
from wtforms import SelectMultipleField, SubmitField, StringField, IntegerField, BooleanField, DateField, widgets, \
|
||||
SelectField
|
||||
|
||||
from models import RequiredDocument
|
||||
from models import RequiredDocument, Investigator
|
||||
|
||||
|
||||
class StudySearchForm(FlaskForm):
|
||||
@ -12,24 +13,39 @@ class StudySearchForm(FlaskForm):
|
||||
class StudyForm(FlaskForm):
|
||||
title = StringField('Title')
|
||||
netbadge_id = StringField('UVA Id for Primary Investigator')
|
||||
requirements = SelectMultipleField("Requirements", choices=[(rd.code, rd.name) for rd in RequiredDocument.all()])
|
||||
requirements = SelectMultipleField("Requirements",
|
||||
render_kw={'class':'multi'},
|
||||
choices=[(rd.code, rd.name) for rd in RequiredDocument.all()])
|
||||
hsr_number = StringField('HSR Number')
|
||||
q_complete = BooleanField('Complete in Protocol Builder?')
|
||||
q_complete = BooleanField('Complete in Protocol Builder?', default='checked',
|
||||
false_values=(False, 'false', 0, '0'))
|
||||
# last_updated = DateField('Last Updated')
|
||||
|
||||
class InvestigatorForm(FlaskForm):
|
||||
netbadge_id = StringField('UVA Id')
|
||||
type = SelectField("InvestigatorType", choices=[(i.type, i.description) for i in Investigator.all_types()])
|
||||
|
||||
class RequirementsTable(Table):
|
||||
code = Col('Code')
|
||||
name = Col('Name')
|
||||
|
||||
class InvestigatorsTable(Table):
|
||||
netbadge_id = Col('UVA Id')
|
||||
type = Col('Type')
|
||||
delete = LinkCol('Delete', 'del_investigator', url_kwargs=dict(inv_id='id'))
|
||||
|
||||
|
||||
class StudyTable(Table):
|
||||
def sort_url(self, col_id, reverse=False):
|
||||
pass
|
||||
edit = LinkCol('Edit', 'edit_study', url_kwargs=dict(study_id='study_id'))
|
||||
delete = LinkCol('Delete', 'del_study', url_kwargs=dict(study_id='study_id'))
|
||||
add_inv = LinkCol('Add Person', 'new_investigator', url_kwargs=dict(study_id='study_id'))
|
||||
study_id = Col('Study Id')
|
||||
title = Col('Title')
|
||||
netbadge_id = Col('Primary Investigator')
|
||||
netbadge_id = Col('User')
|
||||
last_updated = DatetimeCol('Last Update', "medium")
|
||||
q_complete = BoolCol('Complete?')
|
||||
requirements = NestedTableCol('Requirements', RequirementsTable)
|
||||
investigators = NestedTableCol('Investigators', InvestigatorsTable)
|
||||
|
||||
|
@ -10,7 +10,7 @@ class Study(db.Model):
|
||||
investigators = db.relationship("Investigator", backref="study", lazy='dynamic')
|
||||
last_updated = db.Column(db.DateTime(timezone=True), default=func.now())
|
||||
hsr_number = db.Column(db.String())
|
||||
q_complete = db.Column(db.Integer, nullable=True)
|
||||
q_complete = db.Column(db.Boolean, nullable=True)
|
||||
|
||||
|
||||
class Investigator(db.Model):
|
||||
@ -21,7 +21,7 @@ class Investigator(db.Model):
|
||||
description = db.Column(db.String(), nullable=False)
|
||||
|
||||
@staticmethod
|
||||
def all_types(self):
|
||||
def all_types():
|
||||
types = [
|
||||
Investigator(type="PI", description="Primary Investigator"),
|
||||
Investigator(type="SI", description="Sub Investigator"),
|
||||
|
@ -2,10 +2,10 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>New Study 0 Protocol Builder Mock Configuration</title>
|
||||
<title>Protocol Builder Mock Configuration</title>
|
||||
</head>
|
||||
<style>
|
||||
select {
|
||||
select.multi {
|
||||
height: 600px;
|
||||
}
|
||||
input {
|
||||
@ -14,7 +14,7 @@
|
||||
</style>
|
||||
<body>
|
||||
|
||||
<h2>New Study</h2>
|
||||
<h2>{{title}}</h2>
|
||||
<form action="{{action}}" method="post">
|
||||
|
||||
{{ form.csrf_token() }}
|
Loading…
x
Reference in New Issue
Block a user