From: Agnibho Mondal <mondal@agnibho.com> Date: Mon, 26 Feb 2024 21:44:56 +0000 (+0530) Subject: Vaccine Availability X-Git-Url: https://code.agnibho.com/repo?a=commitdiff_plain;h=79910e808f2578c570a00c8d9de7a8dd5c2a89fc;p=librevax.git Vaccine Availability --- 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 <https://www.gnu.org/licenses/>. -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/<pid>") 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 <input name="doe" placeholder="Date of expiry" class="form-control" value="{{data["doe"]}}"> </div> </div> + <div class="mb-2 row"> + <div class="offset-sm-3 col-sm-9"> + <div class="form-check"> + <input name="available" type="checkbox" class="form-check-input" {% if data["available"] %} checked {% endif %}> + <label class="form-check-label">Available</label> + </div> + </div> + </div> <button type="submit" class="btn btn-primary">Save</button> </form> </div> 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 <tr><th>Route of Administration</th><td>{{data["route"]}}</td></tr> <tr><th>Batch Number</th><td>{{data["batch"]}}</td></tr> <tr><th>Date of Expiry</th><td>{{data["doe"]}}</td></tr> + <tr><th>Available</th><td>{% if data["available"] %}Yes{% else %}No{% endif %}</td></tr> </table> <a href="/inventory/edit/{{data["iid"]}}" class="btn btn-primary">Edit</a> <a href="/delete/inventory/{{data["iid"]}}" class="btn btn-danger delete-link">Delete</a>