Skip to content
Browse files

Able add and query patients by name and ID.

  • Loading branch information...
1 parent b310435 commit b12eac7629eb7ea1dd50bd08d61696dcc2f1b29a @skarra committed May 20, 2012
View
121 prs.py
@@ -1,6 +1,6 @@
##
## Created : Mon May 14 18:10:41 IST 2012
-## Last Modified : Fri May 18 15:14:00 IST 2012
+## Last Modified : Sun May 20 22:51:41 IST 2012
##
## Copyright (C) 2012 Sriram Karra <karra.etc@gmail.com>
##
@@ -21,7 +21,8 @@
## First up we need to fix the sys.path before we can even import stuff we
## want.
-import os, sys
+import os, sys, webbrowser
+from datetime import datetime
DIR_PATH = os.path.abspath('')
EXTRA_PATHS = [os.path.join(DIR_PATH, 'src'),
@@ -30,7 +31,7 @@
sys.path = EXTRA_PATHS + sys.path
-import tornado.ioloop, tornado.web
+import tornado.ioloop, tornado.web, tornado.options
import models, config
static_path = os.path.join(DIR_PATH, 'static')
@@ -40,22 +41,130 @@
settings = {'debug': True,
'static_path': os.path.join(__file__, 'static')}
+class SearchHandler(tornado.web.RequestHandler):
+ def search (self, role, field, value):
+ if role == 'patient':
+ model = models.Patient
+ elif role == 'doctor':
+ model = models.Doctor
+ else:
+ print 'SearchHandler:search: Invalid role: %s' % role
+ return
+
+ query = session().query(model)
+ total_cnt = query.count()
+
+ if value != 'all':
+ if field == 'name':
+ query = query.filter(model.name.like('%%%s%%' % value))
+ elif field == 'id':
+ query = query.filter(model.id == value)
+
+ qstr = 'Role: "%-7s" Field: "%6s" Value: "%s"' % (role, field, value)
+ match_cnt = query.count()
+
+ template = os.path.join(DIR_PATH, 'templates', 'srp.html')
+ self.render(template, title=config.get_title(), search_query=qstr,
+ search_results=query.order_by(model.id), total_cnt=total_cnt,
+ match_cnt=match_cnt)
+
+ def get (self, role):
+ """role is one of 'patient' or 'doctor', field will be one of Name or
+ ID (for now). value is the value to lookup for the field in the database"""
+
+ print 'SearchHandler.get()...'
+
+ name = self.get_argument('name', None)
+ id = self.get_argument('id', None)
+
+ if id:
+ field = 'id'
+ value = id
+ else:
+ field = 'name'
+ value = name
+
+ if role in ['patient', 'doctor']:
+ return self.search(role, field, value)
+ else:
+ self.redirect('/')
+
+class ViewHandler (tornado.web.RequestHandler):
+ """once search is done, this handler will serve up a page with all the
+ details."""
+
+ def view_doctor (self, field, value):
+ template = os.path.join(DIR_PATH, 'templates', 'doctor.html')
+ self.render(template, title=config.get_title(), name="Goofy", value=value)
+
+ def view_patient (self, field, value):
+ template = os.path.join(DIR_PATH, 'templates', 'patient.html')
+ self.render(template, title=config.get_title(), name="Goofy", value=value)
+
+ def get (self, role, field, value):
+ """role is one of 'patient' or 'doctor', field will be one of Name or
+ ID (for now). value is the value to lookup for the field in the database"""
+
+ if role == 'patient':
+ return self.view_patient(field, value)
+ elif role == 'doctor':
+ return self.view_doctor(field, value)
+ else:
+ self.redirect('/')
+
class NewPatientHandler(tornado.web.RequestHandler):
- def get(self):
+ def post (self):
+ print 'Got the post, buddy.'
+
+ ga = self.get_argument
+ session().add(models.Patient(name=ga("new_name", ''),
+ age=ga("new_age", 0),
+ gender=ga('new_gender', 'Male'),
+ regdate=ga("new_regdate", datetime.now()),
+ phone=ga('new_phone', ''),
+ address=ga('new_addr', ''),
+ ))
+ session().commit()
+ self.redirect('/')
+
+ def get (self):
template = os.path.join(DIR_PATH, 'templates', 'new-patient.html')
self.render(template, title=config.get_title())
class MainHandler(tornado.web.RequestHandler):
- def get(self):
+ def get (self):
template = os.path.join(DIR_PATH, 'templates', 'index.html')
self.render(template, title=config.get_title())
+def engine (val=None):
+ global _engine
+ if val:
+ _engine = val
+ else:
+ return _engine
+
+def session (val=None):
+ global _session
+ if val:
+ _session = val
+ else:
+ return _session
+
application = tornado.web.Application([
(r"/", MainHandler),
(r"/newpatient", NewPatientHandler),
+ (r"/view/(.*)/(.*)/(.*)", ViewHandler),
+ (r"/search/(.*)", SearchHandler),
(r'/static/(.*)', tornado.web.StaticFileHandler, {'path': static_path})
-])
+], debug=True)
if __name__ == "__main__":
+ tornado.options.parse_command_line()
+
+ eng, sess= models.setup_tables()
+ engine(eng)
+ session(sess)
+
application.listen(8888)
+ ## webbrowser.open('localhost:8888', new=2)
tornado.ioloop.IOLoop.instance().start()
View
7 src/models.py
@@ -1,6 +1,6 @@
##
## Created : Mon May 14 23:04:44 IST 2012
-## Last Modified : Fri May 18 07:13:48 IST 2012
+## Last Modified : Sun May 20 21:53:27 IST 2012
##
## Copyright (C) 2012 Sriram Karra <karra.etc@gmail.com>
##
@@ -20,7 +20,7 @@
from sqlalchemy.ext.declarative import declarative_base
-Base = declarative_base(bind=create_engine('sqlite:///../db/prs.db',
+Base = declarative_base(bind=create_engine('sqlite:///db/prs.db',
echo=False))
def now():
@@ -33,12 +33,13 @@ class Patient(Base):
name = Column(Unicode(255), nullable=False)
regdate = Column(DateTime(), default=now)
age = Column(Integer, nullable=False)
+ gender = Column(Unicode(6), nullable=False)
phone = Column(Unicode(255), nullable=False)
address = Column(Text())
email = Column(Unicode(255))
- relative = Column(Unicode(255), nullable=False)
+ relative = Column(Unicode(255))
relative_phone = Column(Unicode(255))
relative_relation = Column(Unicode(255))
View
3 static/css/doctor.css
@@ -0,0 +1,3 @@
+h1 {
+ color: green;
+}
View
30 static/css/prs.css
@@ -24,6 +24,11 @@ canvas, footer, header, hgroup, menu, section, summary, time, audio, video {
color: #666666;
}
+#site-title:hover {
+ color: blue;
+ cursor: pointer;
+}
+
a {
font-size: 100%;
vertical-align: baseline;
@@ -520,22 +525,19 @@ footer p {
// clear: both;
}
-#sheet div.field .checkbox label {
- padding-left: 0.5em;
-}
-
#sheet .field.small {
max-width: 310px;
margin: 0;
padding: 0;
float: left;
+ padding-top: 5px;
}
#sheet .field.small label {
- font-weight: bold;
- font-size: 110%;
- float: left;
- width: 310px;
+ font-weight: bold;
+ font-size: 110%;
+ float: left;
+ width: 310px;
}
#sheet div.field.small div.ctrl {
@@ -556,7 +558,7 @@ footer p {
-khtml-border-radius: 4px;
border-radius: 4px;
}
-#sheet div.field.small div.ctrl ul li label {
+#sheet div.field.small .checkbox div.ctrl ul li label {
padding-left: 0.5em;
}
#sheet div.field.small div.ctrl ul li.selected {
@@ -687,3 +689,13 @@ p {
margin-top: 0.9em;
// margin-bottom: 0.9em;
}
+
+.reqd_field {
+ color: red;
+ font-size: 80%;
+ vertical-align: super;
+}
+
+#newp_submit {
+
+}
View
3 static/css/srp.css
@@ -0,0 +1,3 @@
+h1 {
+ color: blue;
+}
View
3 static/js/doctor.js
@@ -0,0 +1,3 @@
+h1 {
+ color: green;
+}
View
72 static/js/prs.js
@@ -1,23 +1,83 @@
-//
+//
// Created : Sat May 05 13:15:20 IST 2012
-// Last Modified : Fri May 18 22:33:10 IST 2012
+// Last Modified : Sun May 20 22:51:09 IST 2012
//
// Copyright (C) 2012, Sriram Karra <karra.etc@gmail.com>
// All Rights Reserved
//
// Licensed under the GNU GPL v3
-//
+//
+
+function validateNewPatient (event) {
+ console.log('Validating new patient record...');
+
+ var f_name = $('#new_name').val();
+ var f_age = $('#new_age').val();
+ var f_reg_date = $('#new_reg_date').val();
+ var f_phone = $('#new_phone').val();
+ var f_addr = $('#new_addr').val();
+ var f_doc = $('#new_doc').val();
+
+ var failed = false;
+ var errmsg = "";
+
+ if (f_name === "") {
+ errmsg += "Name cannot be empty\n";
+ }
+
+ if (f_age === "") {
+ errmsg += "Age field cannot be empty\n";
+ } else {
+ }
+
+ if (f_reg_date === "") {
+ f_reg_date = new Date();
+ }
+
+ if (errmsg != "") {
+ alert(errmsg)
+ return false;
+ }
+
+ console.log('WTF.... f_name: ' + f_name)
+}
function addHandlers () {
- console.log('addFormHandlers');
+ console.log('addFormHandlers...');
- $("#new_submit").submit(function () {
-
+ $("#site-title").click(function() {
+ window.location = "/";
})
+
+ $("#dispatch_new_p").click(function() {
+ window.location = '/newpatient';
+ });
+
+ $("#view_all_p").click(function() {
+ window.location = '/search/patient?id=all';
+ });
+
+/*
+ $("#name_pat_q").submit(function() {
+ window.location = '/search/patient/name/' + $("#name_pat_v").val();
+ });
+
+ $("#id_pat_q").submit(function() {
+ window.location = '/search/patient/id/' + $("#id_pat_v").val();
+ });
+*/
+
+ $("#new_patient_form").submit(validateNewPatient);
}
function onLoad () {
console.log('jQuery.onLoad(): Howdy dowdy');
+
+ window.onerror = function (em, url, ln) {
+ alert(em + ", " + url + ", " + ln);
+ return false;
+ }
+
addHandlers();
}
View
56 templates/base.html
@@ -1,6 +1,6 @@
<!--
// Created : Sat May 05 13:15:20 IST 2012
-// Last Modified : Sat May 19 01:04:52 IST 2012
+// Last Modified : Sun May 20 22:56:51 IST 2012
//
// Copyright (C) 2012, Sriram Karra <karra.etc@gmail.com>
// All Rights Reserved
@@ -11,23 +11,23 @@
// controls panel in this template, with a div for a single container element
// that will be populated by different operations before being rendered.
-->
-
<!DOCTYPE html>
<html>
<title>{{ title }} </title>
<head>
<!-- Stylesheets -->
<link href="/static/css/prs.css" rel="stylesheet" type="text/css" />
-<!--
-<link href="/static/css/print.css" media="screen, projection"
- rel="stylesheet" type="text/css" /> -->
+{% block styles %}
-<!-- Javascripts -->
-<script src="./static/js/libs/jquery-1.7.2.min.js"></script>
-<script src="./static/js/libs/jquery.dataTables-1.9.1.min.js"></script>
-<script src="./static/js/prs.js"></script>
+<!-- Any additional style sheets -->
+
+{% end block %}
+<!-- Javascripts -->
+<script src="/static/js/libs/jquery-1.7.2.min.js"> </script>
+<script src="/static/js/libs/jquery.dataTables-1.9.1.min.js"> </script>
+<script src="/static/js/prs.js"> </script>
</head>
<body>
@@ -50,31 +50,33 @@
type="submit" value="View All &rarr;"/>
<br/>
- <form id="search_name_p" class="search" action="/search">
- <input type="text" placeholder="Find patient by name..." name="q"/>
- <input type="submit" value="Go"/>
+ <form id="search_name_p" class="search" action="/search/patient">
+ <input type="text" placeholder="Find patient by name..."
+ id="name_pat_v" name="name"/>
+ <input type="submit" value="Go" id="name_pat_q"/>
</form>
<br/>
- <form id="search_id_p" class="search" action="/search">
- <input type="text" placeholder="Find patient by ID..." name="q"/>
- <input type="submit" value="Go"/>
+ <form id="search_id_p" class="search" action="/search/patient">
+ <input type="text" placeholder="Find patient by ID..."
+ id="id_pat_v" name="id"/>
+ <input type="submit" value="Go" id="id_pat_q"/>
</form>
</div> <!-- .patient_admin -->
<div class="push"></div>
- <div id="content">
- <div id="sheet">
- <div class="section">
- {% block content %}
- You should never see this message because the handlers should render
- only pages dervived from this which should overwrite this with
- something more meaningful.
- {% end %}
- </div>
- </div>
- </div>
-<div id="main_footer"></div>
+ <div id="content">
+ <div id="sheet">
+ <div class="section">
+ {% block content %}
+ You should never see this message because the handlers should render
+ only pages dervived from this which should overwrite this with
+ something more meaningful.
+ {% end block %}
+ </div>
+ </div>
+ </div>
+ <div id="main_footer"></div>
</div> <!-- Container -->
<!--
View
15 templates/doctor.html
@@ -0,0 +1,15 @@
+{% extends templates/base.html %}
+
+{% block styles %}
+
+<link href="/static/css/doctor.css" rel="stylesheet" type="text/css" />
+
+{% end block %}
+
+{% block content %}
+
+<h1>{{ name }}</h1>
+<hr/>
+
+
+{% end block %}
View
4 templates/index.html
@@ -1,11 +1,11 @@
{% extends templates/base.html %}
{% block content %}
-<p>
+<p/>
<h1>Welcome Page</h1>
PRS is a Patient Record Management system, developed exclusively for managing
patients contact details, visit record, doctor availability, and other such
matters of day to day operation of the clinic.
-{% end %}
+{% end block %}
View
33 templates/new-patient.html
@@ -3,60 +3,53 @@
{% block content %}
<!-- Input form for a new patient -->
- <form id="new_patient_form" enctype="multipart/form-data" method="POST">
+ <form id="new_patient_form" method="POST">
<h1>New Patient Details:</h1>
<div class="field small">
<div class="ctrl">
- <label>Full Name</label>
- <input class="age" type="text" id="new_title"/>
- <input type="text" id="new_name"/>
+ <label>Full Name<span class="reqd_field">*</span></label>
+ <input class="age" type="text" name="new_title"/>
+ <input type="text" id="new_name" name="new_name"/>
</div> <!-- .ctrl -->
</div> <!-- .field.small -->
<div class="field small">
<div class="ctrl">
- <label>Age</label>
- <input class="age" type="text" id="new_age"/>
+ <label>Age<span class="reqd_field">*</span></label>
+ <input class="age" type="text" id="new_age" name="new_age"/>
</div> <!-- .ctrl -->
</div> <!-- .field.small -->
<div class="field small">
<div class="ctrl">
<label>Gender</label>
- <input type="text" id="new_gender"/>
+ <input type="text" id="new_gender" name="new_gender"/>
</div> <!-- .ctrl -->
</div> <!-- .field.small -->
<div class="field small">
<div class="ctrl">
- <label>Date of Registration</label>
- <input type="text" id="new_reg_date"/>
+ <label>Date of Registration<span class="reqd_field">*</span></label>
+ <input type="text" id="new_reg_date" name="new_reg_date"/>
</div> <!-- .ctrl -->
</div> <!-- .field.small -->
<div class="field small">
<div class="ctrl">
- <label>Contact Number</label>
- <input type="text" id="new_phone"/>
+ <label>Contact Number<span class="reqd_field">*</span></label>
+ <input type="text" id="new_phone" name="new_phone"/>
</div> <!-- .ctrl -->
</div> <!-- .field.small -->
<div class="field small">
<div class="ctrl">
<label>Contact Address</label>
- <input type="text" id="new_addr"/>
+ <input type="text" id="new_addr" name="new_addr"/>
</div> <!-- .ctrl -->
</div> <!-- .field.small -->
- <div class="field small">
- <div class="ctrl">
- <label>Doctor</label>
- <input type="text" id="new_reg_date"/>
- </div> <!-- .ctrl -->
- </div> <!-- .field.small -->
-
- <input type="submit" id="new_submit" value="Add Patient Details &rarr;"/>
+ <input type="submit" id="newp_submit" value="Add Patient Details &rarr;"/>
</form>
<!--
View
9 templates/patient.html
@@ -0,0 +1,9 @@
+{% extends templates/base.html %}
+
+{% block content %}
+
+<h1> {{ name }} </h1>
+<hr/>
+Value: {{ value }}
+
+{% end block %}
View
38 templates/srp.html
@@ -0,0 +1,38 @@
+{% extends templates/base.html %}
+
+{% block styles %}
+
+<link href="/static/css/srp.css" rel="stylesheet" type="text/css" />
+
+{% end block %}
+
+{% block content %}
+
+<h1>Search Results Summary</h1>
+<hr/>
+
+<h3>You searched for: {{ search_query }}</h3>
+<p/>
+Total rows in database: {{ total_cnt }}
+<br/>
+Matches: {{ match_cnt }}
+
+<hr/>
+
+<table>
+ <tr>
+ <td>ID</td>
+ <td>Name</td>
+ <td>Phone</td>
+ </tr>
+
+ {% for res in search_results %}
+ <tr>
+ <td> {{ res.id }} </td>
+ <td> {{ res.name }} </td>
+ <td> {{ res.phone }} </td>
+ </tr>
+ {% end %}
+</table>
+
+{% end block %}

0 comments on commit b12eac7

Please sign in to comment.
Something went wrong with that request. Please try again.