From 79910e808f2578c570a00c8d9de7a8dd5c2a89fc Mon Sep 17 00:00:00 2001 From: Agnibho Mondal Date: Tue, 27 Feb 2024 03:14:56 +0530 Subject: [PATCH] Vaccine Availability --- inventory.py | 15 +++++++++------ librevax.py | 9 +++++---- templates/inventory-edit.html | 8 ++++++++ templates/inventory-view.html | 1 + 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/inventory.py b/inventory.py index efa7363..0d4b0d3 100644 --- a/inventory.py +++ b/inventory.py @@ -5,9 +5,9 @@ # LibreVax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # You should have received a copy of the GNU General Public License along with LibreVax. If not, see . -def create(cursor, data): +def create(cursor, data, available): try: - cursor.execute("INSERT INTO inventory (mid, vaccine, altname, dose, dpv, route, batch, doe, available, data) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (data["mid"], data["vaccine"], data["altname"], data["dose"], data["dpv"], data["route"], data["batch"], data["doe"], "", "")) + cursor.execute("INSERT INTO inventory (mid, vaccine, altname, dose, dpv, route, batch, doe, available, data) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (data["mid"], data["vaccine"], data["altname"], data["dose"], data["dpv"], data["route"], data["batch"], data["doe"], available, "")) if(cursor.rowcount==0): return (False, "Failed to create record.") else: @@ -26,9 +26,9 @@ def read(cursor, iid): except Exception as e: return (False, e) -def update(cursor, iid, data): +def update(cursor, iid, data, available): try: - cursor.execute("UPDATE inventory SET vaccine=?, altname=?, dose=?, dpv=?, route=?, batch=?, doe=?, available=? WHERE iid=?", (data["vaccine"], data["altname"], data["dose"], data["dpv"], data["route"], data["batch"], data["doe"], "", iid)) + cursor.execute("UPDATE inventory SET vaccine=?, altname=?, dose=?, dpv=?, route=?, batch=?, doe=?, available=? WHERE iid=?", (data["vaccine"], data["altname"], data["dose"], data["dpv"], data["route"], data["batch"], data["doe"], available, iid)) if(cursor.rowcount==0): return (False, "Failed to update record.") else: @@ -46,9 +46,12 @@ def delete(cursor, iid): except Exception as e: return (False, e) -def list(cursor, mid): +def list(cursor, mid, all=False): try: - result=cursor.execute("SELECT * FROM inventory WHERE mid=?", (mid,)) + if(all): + result=cursor.execute("SELECT * FROM inventory WHERE mid=?", (mid,)) + else: + result=cursor.execute("SELECT * FROM inventory WHERE mid=? AND available=?", (mid, True)) if(cursor.rowcount==0): return (False, "Record not found.") else: diff --git a/librevax.py b/librevax.py index 8e6363f..3c109de 100644 --- a/librevax.py +++ b/librevax.py @@ -249,7 +249,7 @@ def inventory_view(action, id=None): cursor=get_db().cursor() if(action=="list"): if(id is not None): - (ok, data)=inventory.list(cursor, id) + (ok, data)=inventory.list(cursor, id, all=True) if(not ok): raise exception(data) (ok, center)=multicenter.read(cursor, id) @@ -294,12 +294,14 @@ def inventory_edit(mid=None, iid=None): try: cursor=get_db().cursor() if(iid is None): - (ok, data)=inventory.create(cursor, request.form) + available="available" in request.form.keys() + (ok, data)=inventory.create(cursor, request.form, available) if(not ok): raise Exception(data) iid=data else: - (ok, data)=inventory.update(cursor, iid, request.form) + available="available" in request.form.keys() + (ok, data)=inventory.update(cursor, iid, request.form, available) if(not ok): raise Exception(data) return redirect("/inventory/view/"+str(iid)) @@ -510,7 +512,6 @@ def vaccination_view(action, id=None): else: raise Exception("Invalid parameter") except Exception as e: - raise(e) return render_template("error.html", data=e) @app.post("/vaccination/new/") diff --git a/templates/inventory-edit.html b/templates/inventory-edit.html index 06c5ab2..993ac5a 100644 --- a/templates/inventory-edit.html +++ b/templates/inventory-edit.html @@ -57,6 +57,14 @@ You should have received a copy of the GNU General Public License along with Lib +
+
+
+ + +
+
+
diff --git a/templates/inventory-view.html b/templates/inventory-view.html index 4e72d80..bada27f 100644 --- a/templates/inventory-view.html +++ b/templates/inventory-view.html @@ -38,6 +38,7 @@ You should have received a copy of the GNU General Public License along with Lib Route of Administration{{data["route"]}} Batch Number{{data["batch"]}} Date of Expiry{{data["doe"]}} + Available{% if data["available"] %}Yes{% else %}No{% endif %} Edit Delete -- 2.39.5