if((ret:=problem())!="go"):
return ret
try:
- date=request.args.get("date", datetime.now().strftime("%Y-%m-%d"))
+
+ def get_valid_date(date_str):
+ today=datetime.now().strftime("%Y-%m-%d")
+ try:
+ return datetime.strptime(date_str, "%Y-%m-%d").strftime("%Y-%m-%d")
+ except (ValueError, TypeError):
+ return today
+
+ fromDate=get_valid_date(request.args.get("fromDate"))
+ toDate=get_valid_date(request.args.get("toDate"))
+
cursor=get_db().cursor()
- (ok, data)=vaccination.list_by_date(cursor, date)
+ (ok, data)=vaccination.list_by_date(cursor, fromDate, toDate)
if(not ok):
raise Exception(data)
(ok, center)=multicenter.read(cursor, g.mid)
count[i["vaccine"]]=count[i["vaccine"]]+i["dosage"]
except KeyError:
count[i["vaccine"]]=i["dosage"]
- return render_template("report.html", data=data, count=count, individual=individual, center=center, date=date)
+ return render_template("report.html", data=data, count=count, individual=individual, center=center, fromDate=fromDate, toDate=toDate)
except Exception as e:
raise(e)
return render_template("error.html", data=e)
<div class="content report">
<form>
<div class="mb-2 row">
- <div class="col-sm-9">
- <input name="date" type="date" class="form-control">
+ <div class="col-sm-4">
+ <input name="fromDate" type="date" class="form-control" title="From this date">
</div>
- <div class="col-sm-3 d-grid">
+ <div class="col-sm-4">
+ <input name="toDate" type="date" class="form-control" title="To this date">
+ </div>
+ <div class="col-sm-2 d-grid">
<button type="submit" class="btn btn-primary">Report</button>
</div>
</div>
</form>
<table class="table">
- <tr><td>{{config["TITLE"]}} / {{center["center"]}}</td><td>Vaccination Report: {{date}}</td></tr>
+ <tr><td>{{config["TITLE"]}} / {{center["center"]}}</td><td>Vaccination Report: {{toDate}} to {{fromDate}}</td></tr>
</table>
<table class="table table-bordered">
{% for i in data %}
except Exception as e:
return (False, e)
-def list_by_date(cursor, date):
+def list_by_date(cursor, fromDate, toDate):
try:
- result=cursor.execute("SELECT * FROM vaccination LEFT JOIN inventory ON vaccination.iid=inventory.iid LEFT JOIN patients ON vaccination.pid=patients.pid WHERE date LIKE ? ORDER BY vaccination.iid", (date+"%",))
+ result=cursor.execute("SELECT * FROM vaccination LEFT JOIN inventory ON vaccination.iid=inventory.iid LEFT JOIN patients ON vaccination.pid=patients.pid WHERE date BETWEEN ? AND ? ORDER BY vaccination.iid", (fromDate, toDate))
if(cursor.rowcount==0):
return (False, "Record not found.")
else: