# 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:
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:
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:
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)
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))
else:
raise Exception("Invalid parameter")
except Exception as e:
- raise(e)
return render_template("error.html", data=e)
@app.post("/vaccination/new/<pid>")