diff --git a/.flaskenv b/.flaskenv new file mode 100644 index 0000000..b5a49d0 --- /dev/null +++ b/.flaskenv @@ -0,0 +1,2 @@ +FLASK_APP=webscas.py +FLASK_DEBUG=1 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f2b85d4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +__pycache__ +migrations +*.db +venv +whoosh \ No newline at end of file diff --git a/README.md b/README.md index 5f23e42..bdc08b3 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..0d7bc57 --- /dev/null +++ b/app/__init__.py @@ -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 \ No newline at end of file diff --git a/app/forms.py b/app/forms.py new file mode 100644 index 0000000..fff43ce --- /dev/null +++ b/app/forms.py @@ -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') diff --git a/app/models.py b/app/models.py new file mode 100644 index 0000000..52cc94c --- /dev/null +++ b/app/models.py @@ -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 ''.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)) \ No newline at end of file diff --git a/app/routes.py b/app/routes.py new file mode 100644 index 0000000..75b8fa0 --- /dev/null +++ b/app/routes.py @@ -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' \ No newline at end of file diff --git a/app/templates/add_patient.html b/app/templates/add_patient.html new file mode 100644 index 0000000..35af554 --- /dev/null +++ b/app/templates/add_patient.html @@ -0,0 +1,37 @@ +{% extends 'base.html' %} + +{% block content %} + +
+

Add Patient

+
+ {{ form.hidden_tag() }} +

+ {{ form.patient_name.label }}
+ {{ form.patient_name(size=32) }}
+ {% for error in form.patient_name.errors %} + [{{ error }}] + {% endfor %} +

+

+ {{ form.patient_id.label }}
+ {{ form.patient_id(size=32) }}
+ {% for error in form.patient_id.errors %} + [{{ error }}] + {% endfor %} +

+

+ {{ form.patient_disease.label }}
+ {{ form.patient_disease(size=32) }}
+ {% for error in form.patient_disease.errors %} + [{{ error }}] + {% endfor %} +

+

+ {{ form.submit() }} +

+
+
+{% endblock %} \ No newline at end of file diff --git a/app/templates/base.html b/app/templates/base.html new file mode 100644 index 0000000..1fee011 --- /dev/null +++ b/app/templates/base.html @@ -0,0 +1,59 @@ + + + + + + + + + {{ title }} + + + +
+ {% with messages = get_flashed_messages(with_categories=true) %} + + {% if messages %} + {% for category, message in messages %} + + {% endfor %} + {% endif %} + {% endwith %} +
+ {% block content %} {% endblock %} + + + \ No newline at end of file diff --git a/app/templates/index.html b/app/templates/index.html new file mode 100644 index 0000000..a7fa13f --- /dev/null +++ b/app/templates/index.html @@ -0,0 +1,18 @@ +{% extends 'base.html' %} + +{% block content %} +
+ + {% for patient in patients %} +
{{ patient.patient_id }}
+
{{ patient.patient_name }}
+
{{ patient.patient_disease }}
+
+ {% endfor %} +
+{% endblock %} \ No newline at end of file diff --git a/app/templates/patient_details.html b/app/templates/patient_details.html new file mode 100644 index 0000000..2e3d4ca --- /dev/null +++ b/app/templates/patient_details.html @@ -0,0 +1,56 @@ +{% extends 'base.html' %} + +{% block content %} + +
+

Add Patient Details

+
+ {{ form.hidden_tag() }} +

+ {{ form.patient_id.label }}
+ {{ form.patient_id(size=32) }}
+ {% for error in form.patient_id.errors %} + [{{ error }}] + {% endfor %} +

+

+ {{ form.fever.label }}
+ {{ form.fever(size=32) }}
+ {% for error in form.fever.errors %} + [{{ error }}] + {% endfor %} +

+

+ {{ form.heart_rate.label }}
+ {{ form.heart_rate(size=32) }}
+ {% for error in form.heart_rate.errors %} + [{{ error }}] + {% endfor %} +

+

+ {{ form.respiratory_rate.label }}
+ {{ form.respiratory_rate(size=32) }}
+ {% for error in form.respiratory_rate.errors %} + [{{ error }}] + {% endfor %} +

+

+ {{ form.abnormal_white_blood_cell_count.label }}
+ {{ form.abnormal_white_blood_cell_count(size=32) }}
+ {% for error in form.abnormal_white_blood_cell_count.errors %} + [{{ error }}] + {% endfor %} +

+

+ {{ form.paco2.label }}
+ {{ form.paco2(size=32) }}
+ {% for error in form.paco2.errors %} + [{{ error }}] + {% endfor %} +

+

{{ form.submit() }}

+
+
+{% endblock %} \ No newline at end of file diff --git a/config.py b/config.py new file mode 100644 index 0000000..dadf457 --- /dev/null +++ b/config.py @@ -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 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c860b9c Binary files /dev/null and b/requirements.txt differ diff --git a/webscas.py b/webscas.py new file mode 100644 index 0000000..654859a --- /dev/null +++ b/webscas.py @@ -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} \ No newline at end of file