From 8a3f202291fca18fe1ce09088f7644d008662390 Mon Sep 17 00:00:00 2001 From: Agnibho Mondal Date: Wed, 22 Jan 2025 01:33:40 +0530 Subject: [PATCH] Date range in report --- librevax.py | 16 +++++++++++++--- templates/report.html | 11 +++++++---- vaccination.py | 4 ++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/librevax.py b/librevax.py index ba2bf1c..56bf9e3 100644 --- a/librevax.py +++ b/librevax.py @@ -824,9 +824,19 @@ def report(mid): 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) @@ -840,7 +850,7 @@ def report(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) diff --git a/templates/report.html b/templates/report.html index 911f5d5..5e72738 100644 --- a/templates/report.html +++ b/templates/report.html @@ -14,16 +14,19 @@ You should have received a copy of the GNU General Public License along with Lib
-
- +
+
-
+
+ +
+
- +
{{config["TITLE"]}} / {{center["center"]}}Vaccination Report: {{date}}
{{config["TITLE"]}} / {{center["center"]}}Vaccination Report: {{toDate}} to {{fromDate}}
{% for i in data %} diff --git a/vaccination.py b/vaccination.py index a92f3cc..a219baf 100644 --- a/vaccination.py +++ b/vaccination.py @@ -75,9 +75,9 @@ def list_by_inventory(cursor, iid): 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: -- 2.39.5