]> Softwares of Agnibho - librevax.git/commitdiff
Date range in report
authorAgnibho Mondal <mondal@agnibho.com>
Tue, 21 Jan 2025 20:03:40 +0000 (01:33 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Tue, 21 Jan 2025 20:03:40 +0000 (01:33 +0530)
librevax.py
templates/report.html
vaccination.py

index ba2bf1c4f3b52642f35a94d52e8d919cb03a9a29..56bf9e3a3665721f5d2b105f1b6f9cc8d6af0ade 100644 (file)
@@ -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)
index 911f5d5b6e96090d42de80b9a95194e51176c03b..5e727387818536b702cb580dd14825a179c3a7d3 100644 (file)
@@ -14,16 +14,19 @@ You should have received a copy of the GNU General Public License along with Lib
 <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 %}
index a92f3cc5f6934c8ba083e71ba1617bf65896ad83..a219baff108eba29b2d1b0515806babf28e7a0a8 100644 (file)
@@ -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: