From b58e1398702d96d7a8feaccde2bf72b9abd2a1f0 Mon Sep 17 00:00:00 2001 From: mukeshsihag Date: Thu, 23 Jan 2020 21:56:50 +0530 Subject: [PATCH 1/3] created basic setup and patient table in database --- .flaskenv | 2 ++ .gitignore | 4 +++ app/__init__.py | 11 +++++++ app/forms.py | 9 ++++++ app/models.py | 13 ++++++++ app/routes.py | 31 +++++++++++++++++++ app/templates/add_patient.html | 37 ++++++++++++++++++++++ app/templates/base.html | 56 ++++++++++++++++++++++++++++++++++ app/templates/index.html | 12 ++++++++ config.py | 8 +++++ webscas.py | 6 ++++ 11 files changed, 189 insertions(+) create mode 100644 .flaskenv create mode 100644 .gitignore create mode 100644 app/__init__.py create mode 100644 app/forms.py create mode 100644 app/models.py create mode 100644 app/routes.py create mode 100644 app/templates/add_patient.html create mode 100644 app/templates/base.html create mode 100644 app/templates/index.html create mode 100644 config.py create mode 100644 webscas.py 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..f20d063 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +__pycache__ +migrations +*.db +venv \ No newline at end of file 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..bb75286 --- /dev/null +++ b/app/forms.py @@ -0,0 +1,9 @@ +from flask_wtf import FlaskForm +from wtforms import StringField, PasswordField, BooleanField, SubmitField +from wtforms.validators import DataRequired + +class PatientForm(FlaskForm): + patient_name = StringField('Patient Name', validators=[DataRequired()]) + patient_id = StringField('patient Id', validators=[DataRequired()]) + patient_disease = StringField('Disease', validators=[DataRequired()]) + submit = SubmitField('Submit') \ No newline at end of file diff --git a/app/models.py b/app/models.py new file mode 100644 index 0000000..9547973 --- /dev/null +++ b/app/models.py @@ -0,0 +1,13 @@ +from app import db + +class Patient(db.Model): + id = db.Column(db.Integer, primary_key=1) + patient_name = db.Column(db.String(64), index=1) + patient_id = db.Column(db.String(64), index=1) + patient_disease = db.Column(db.String(128), index=1) + + def __repr__(self): + return ''.format(self.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..a6936d3 --- /dev/null +++ b/app/routes.py @@ -0,0 +1,31 @@ +from flask import render_template, redirect, url_for, flash, request +from app.forms import PatientForm +from app.models import Patient +from app import app, db + +@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 successfulluy', 'success') + return redirect(url_for('index')) + return render_template('add_patient.html',title='Add Patient', form=form) 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..7536be5 --- /dev/null +++ b/app/templates/base.html @@ -0,0 +1,56 @@ + + + + + + + + + {{ 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..986b9a1 --- /dev/null +++ b/app/templates/index.html @@ -0,0 +1,12 @@ +{% 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/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/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 From cd113d2d58ff5e73ffb927de85a2e7f466739ea5 Mon Sep 17 00:00:00 2001 From: mukeshsihag Date: Sun, 26 Jan 2020 23:36:26 +0530 Subject: [PATCH 2/3] added table to detect sepsis --- .gitignore | 3 +- app/forms.py | 13 +++++-- app/models.py | 23 +++++++++--- app/routes.py | 42 ++++++++++++++++++++-- app/templates/base.html | 7 ++-- app/templates/index.html | 8 ++++- app/templates/patient_details.html | 56 +++++++++++++++++++++++++++++ requirements.txt | Bin 0 -> 818 bytes 8 files changed, 138 insertions(+), 14 deletions(-) create mode 100644 app/templates/patient_details.html create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index f20d063..f2b85d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ __pycache__ migrations *.db -venv \ No newline at end of file +venv +whoosh \ No newline at end of file diff --git a/app/forms.py b/app/forms.py index bb75286..fff43ce 100644 --- a/app/forms.py +++ b/app/forms.py @@ -3,7 +3,16 @@ from wtforms.validators import DataRequired class PatientForm(FlaskForm): + patient_id = StringField('Patient Id', validators=[DataRequired()]) patient_name = StringField('Patient Name', validators=[DataRequired()]) - patient_id = StringField('patient Id', validators=[DataRequired()]) patient_disease = StringField('Disease', validators=[DataRequired()]) - submit = SubmitField('Submit') \ No newline at end of file + 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 index 9547973..52cc94c 100644 --- a/app/models.py +++ b/app/models.py @@ -1,13 +1,26 @@ -from app import db +from app import db, app +import flask_whooshalchemy as wa class Patient(db.Model): - id = db.Column(db.Integer, primary_key=1) - patient_name = db.Column(db.String(64), index=1) - patient_id = db.Column(db.String(64), index=1) - patient_disease = db.Column(db.String(128), index=1) + # 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 index a6936d3..75b8fa0 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,7 +1,8 @@ from flask import render_template, redirect, url_for, flash, request -from app.forms import PatientForm -from app.models import Patient +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') @@ -26,6 +27,41 @@ def add_patient(): 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 successfulluy', 'success') + 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/base.html b/app/templates/base.html index 7536be5..1fee011 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -23,7 +23,10 @@ Web Scas (current) - + @@ -45,7 +48,7 @@