]> Softwares of Agnibho - librevax.git/commitdiff
Vaccine Availability
authorAgnibho Mondal <mondal@agnibho.com>
Mon, 26 Feb 2024 21:44:56 +0000 (03:14 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Mon, 26 Feb 2024 21:44:56 +0000 (03:14 +0530)
inventory.py
librevax.py
templates/inventory-edit.html
templates/inventory-view.html

index efa7363317b68e37614201636aba3a4a9424c2cb..0d4b0d31547ea133f71bdd56669f9729b7cd9844 100644 (file)
@@ -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:
index 8e6363fb6c29ed3ff959bdc4ba0b64179a9ace5f..3c109dee2078def61faf9e0061a8670170b06bd7 100644 (file)
@@ -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>")
index 06c5ab290119a69206567696ead27248d456c3a6..993ac5a8743e05bcf9ef090a4300d6318e212075 100644 (file)
@@ -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>
index 4e72d80414b6067c351b8d1c865dae7a24e3d0e3..bada27f2fde11b4381a5fdf0580a0a8c8f4767ba 100644 (file)
@@ -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>