Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .flaskenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FLASK_APP=webscas.py
FLASK_DEBUG=1
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__pycache__
migrations
*.db
venv
whoosh
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@
Web application for sepsis clinical assessment scores using batch ICU patient data
Backend of the application will be in Flask and the project will be completely python based
Frontend will be purely based on html, css and may be on javascript.

# Run Web
```shell
To run the web Do:
>>> pip install -r requirements.txt
And run the flask server
>>> flask run
Open it on your localhost http://127.0.0.1:5000
11 changes: 11 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from flask import Flask
from config import Config
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate

app = Flask(__name__)
app.config.from_object(Config)
db = SQLAlchemy(app)
migrate = Migrate(app, db)

from app import routes, models
18 changes: 18 additions & 0 deletions app/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField
from wtforms.validators import DataRequired

class PatientForm(FlaskForm):
patient_id = StringField('Patient Id', validators=[DataRequired()])
patient_name = StringField('Patient Name', validators=[DataRequired()])
patient_disease = StringField('Disease', validators=[DataRequired()])
submit = SubmitField('Submit')

class SepsisForm(FlaskForm):
patient_id = StringField('Patient ID', validators=[DataRequired()])
fever = StringField('Fever(in degree celsius)', validators=[DataRequired()])
heart_rate = StringField('Heart Rate(in beats per minute)', validators=[DataRequired()])
respiratory_rate = StringField('Respiratory Rate(in breaths per minute)', validators=[DataRequired()])
abnormal_white_blood_cell_count = StringField('Abnormal White Blood Cell Count(/mm3)', validators=[DataRequired()])
paco2 = StringField('PaCO2(Partial pressure of carbon dioxide)')
submit = SubmitField('Submit')
26 changes: 26 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from app import db, app
import flask_whooshalchemy as wa

class Patient(db.Model):
# id = db.Column(db.Integer, primary_key=1)
__searchable__ = ['patien_name', 'patient_disease']
patient_id = db.Column(db.Integer, primary_key=1)
patient_name = db.Column(db.String(64))
patient_disease = db.Column(db.String(128))
sepsis = db.relationship('Sepsis', backref='patient', lazy='dynamic')

def __repr__(self):
return '<Patient {}>'.format(self.patient_id)

wa.whoosh_index(app, Patient)
class Sepsis(db.Model):
s_id = db.Column(db.Integer, primary_key=1)
fever = db.Column(db.Integer)
heart_rate = db.Column(db.Integer)
respiratory_rate = db.Column(db.Integer)
abnormal_white_blood_cell_count = db.Column(db.Integer)
paco2 = db.Column(db.Integer)
patient_id = db.Column(db.Integer, db.ForeignKey('patient.patient_id'))

# def load_user(id):
# return User.query.get(int(id))
67 changes: 67 additions & 0 deletions app/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from flask import render_template, redirect, url_for, flash, request
from app.forms import PatientForm, SepsisForm
from app.models import Patient, Sepsis
from app import app, db
import flask_whooshalchemy as wa

@app.route('/')
@app.route('/index')
def index():
patients = Patient.query.all()
for patient in patients:
print(patient.patient_name)
return render_template("index.html", title="webscas", patients=patients)

@app.route('/add_patient', methods=['GET', 'POST'])
def add_patient():
form = PatientForm()
if request.method == 'GET':
return render_template('add_patient.html', title='Add Patient', form=form)
elif form.validate_on_submit():
patient_id = Patient.query.filter_by(patient_id=form.patient_id.data).first()
print(type(patient_id))
if patient_id is not None:
flash('Patient with id {} already exist'.format(form.patient_id.data), 'info')
return redirect(url_for('add_patient'))
else:
patient = Patient(patient_name=form.patient_name.data, patient_id=form.patient_id.data, patient_disease=form.patient_disease.data)
db.session.add(patient)
db.session.commit()
flash('Your data has been saved successfully', 'success')
return redirect(url_for('index'))
return render_template('add_patient.html',title='Add Patient', form=form)

@app.route('/patient_details', methods=['GET', 'POST'])
def patient_details():
form = SepsisForm()
if request.method == 'GET':
return render_template('patient_details.html', title='Patient Details', form=form)
elif form.validate_on_submit():
patient_id = Patient.query.filter_by(patient_id=form.patient_id.data).first()
if patient_id:
s_id = Sepsis.query.filter_by(patient_id=form.patient_id.data).first()
if not s_id:
details = Sepsis(fever=form.fever.data, heart_rate=form.heart_rate.data, respiratory_rate=form.respiratory_rate.data, abnormal_white_blood_cell_count=form.abnormal_white_blood_cell_count.data, paco2=form.paco2.data, patient_id=form.patient_id.data)
db.session.add(details)
db.session.commit()
flash('Details has been saved', 'success')
else:
s_id.fever=form.fever.data
s_id.heart_rate=form.heart_rate.data
s_id.respiratory_rate=form.respiratory_rate.data
s_id.abnormal_white_blood_cell_count=form.abnormal_white_blood_cell_count.data
s_id.paco2=form.paco2.data
db.session.commit()
flash("Details has been updated", 'success')
else:
flash('No Patient exist with Patient ID {}'.format(form.patient_id.data), 'warning')
return render_template('patient_details.html', title='Patient Details', form=form)

# @app.route('/search')
# def search():
# data = request.args.get('query')
# # print(data)
# patients = Patient.query.whoosh_search(data).all()
# print(type(patients))
# return render_template('index.html', patients=patients)
# # return 'hi'
37 changes: 37 additions & 0 deletions app/templates/add_patient.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% extends 'base.html' %}

{% block content %}
<style >
h3 {margin-top: 5%;margin-bottom: 5%;}
</style>
<center>
<h3>Add Patient</h3>
<form action="" method="POST" novalidate>
{{ form.hidden_tag() }}
<p>
{{ form.patient_name.label }} <br>
{{ form.patient_name(size=32) }} <br>
{% for error in form.patient_name.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
</p>
<p>
{{ form.patient_id.label }} <br>
{{ form.patient_id(size=32) }} <br>
{% for error in form.patient_id.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
</p>
<p>
{{ form.patient_disease.label }} <br>
{{ form.patient_disease(size=32) }} <br>
{% for error in form.patient_disease.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
</p>
<p>
{{ form.submit() }}
</p>
</form>
</center>
{% endblock %}
59 changes: 59 additions & 0 deletions app/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>{{ title }}</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-dark fixed-top">
<!-- <a class="navbar-brand text-light col-sm-4" href="#">
<img src="/docs/4.1/assets/brand/bootstrap-solid.svg" width="30" height="30" class="d-inline-block align-top" alt="">
Builder
</a> -->
<button type="button" class="navbar-toggler bg-light float-right" data-toggle="collapse" data-target="#navbarCollapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav mr-auto col-sm-12">
<li class="nav-item active" style="margin-right: 2%;margin-left: 5%;">
<a class="nav-link text-light" href="{{ url_for('index') }}">Web Scas <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item"><a href="{{ url_for('add_patient') }}" class="nav-link text-light">&nbsp;<i class="fa fa-user-plus" aria-hidden="true"></i>&nbsp;Add Patient</a></li>
<li class="nav-item">
<a href="{{ url_for('patient_details') }}" class="nav-link text-light">&nbsp;
<i class="fa fa-user-plus" aria-hidden="true"></i>&nbsp;Add Patient Detail</a>
</li>
</ul>
</div>
</nav>
<div class="container message" style="margin-top: 5%;">
{% with messages = get_flashed_messages(with_categories=true) %}
<!-- Categories: success (green), info (blue), warning (yellow), danger (red) -->
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ category }} alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span
aria-hidden="true">&times;</span></button>
{{ message }}
</div>
{% endfor %}
{% endif %}
{% endwith %}
</div>
{% block content %} {% endblock %}
<script>
setTimeout(function() {
$('.alert-dismissible').remove();
}, 2000);

$(".custom-file-input").on("change", function() {
var fileName = $(this).val().split("\\").pop();
$(this).siblings(".custom-file-label").addClass("selected").html(fileName);
});
</script>
</body>
</html>
18 changes: 18 additions & 0 deletions app/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends 'base.html' %}

{% block content %}
<center>
<!-- <h4>Search</h4>
<form action="search" method="GET">
<label for="query">Name</label>
<input type="text" name="query" id="query">
<button class="btn btn-primary">Search</button>
</form> -->
{% for patient in patients %}
<h6>{{ patient.patient_id }}</h6>
<h6>{{ patient.patient_name }}</h6>
<h6>{{ patient.patient_disease }}</h6>
<br>
{% endfor %}
</center>
{% endblock %}
56 changes: 56 additions & 0 deletions app/templates/patient_details.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{% extends 'base.html' %}

{% block content %}
<style>
h4 {margin-top: 5%; margin-bottom: 1%;}
</style>
<center>
<h4>Add Patient Details</h4>
<form action="" method="POST" novalidate>
{{ form.hidden_tag() }}
<p>
{{ form.patient_id.label }} <br>
{{ form.patient_id(size=32) }} <br>
{% for error in form.patient_id.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
</p>
<p>
{{ form.fever.label }} <br>
{{ form.fever(size=32) }} <br>
{% for error in form.fever.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
</p>
<p>
{{ form.heart_rate.label }} <br>
{{ form.heart_rate(size=32) }} <br>
{% for error in form.heart_rate.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
</p>
<p>
{{ form.respiratory_rate.label }} <br>
{{ form.respiratory_rate(size=32) }} <br>
{% for error in form.respiratory_rate.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
</p>
<p>
{{ form.abnormal_white_blood_cell_count.label }} <br>
{{ form.abnormal_white_blood_cell_count(size=32) }} <br>
{% for error in form.abnormal_white_blood_cell_count.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
</p>
<p>
{{ form.paco2.label }} <br>
{{ form.paco2(size=32) }} <br>
{% for error in form.paco2.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
</p>
<p>{{ form.submit() }}</p>
</form>
</center>
{% endblock %}
8 changes: 8 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os
basedir = os.path.abspath(os.path.dirname(__file__))

class Config(object):
SECRET_KEY = os.environ.get('SECRET_KEY') or 'thisissecretkey'
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
'sqlite:///' + os.path.join(basedir, 'app.db')
SQLALCHEMY_TRACK_MODIFICATIONS = False
Binary file added requirements.txt
Binary file not shown.
6 changes: 6 additions & 0 deletions webscas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from app import app, db
from app.models import Patient

@app.shell_context_processor
def make_shell_context():
return {'db': db, 'Patient': Patient}