]> Softwares of Agnibho - librevax.git/blob - vaccination.py
Database dump
[librevax.git] / vaccination.py
1 # LibreVax
2 # Copyright (C) 2024 Dr. Agnibho Mondal
3 # This file is part of LibreVax.
4 # LibreVax is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
5 # 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.
6 # You should have received a copy of the GNU General Public License along with LibreVax. If not, see <https://www.gnu.org/licenses/>.
7
8 def create(cursor, data, given):
9 try:
10 cursor.execute("INSERT INTO vaccination (iid, pid, date, dosage, consultant, vaccinator, adverse, memo, given, data) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (data["iid"], data["pid"], data["date"], data["dosage"], data["consultant"], data["vaccinator"], data["adverse"], data["memo"], given, ""))
11 if(cursor.rowcount==0):
12 return (False, "Failed to create record.")
13 else:
14 return (True, cursor.lastrowid)
15 except Exception as e:
16 return (False, e)
17
18 def read(cursor, vid):
19 try:
20 result=cursor.execute("SELECT * FROM vaccination WHERE vid=?", (vid,))
21 if(cursor.rowcount==0):
22 return (False, "Record not found.")
23 else:
24 return (True, result.fetchone())
25 except Exception as e:
26 return (False, e)
27
28 def update(cursor, vid, data, given):
29 try:
30 cursor.execute("UPDATE vaccination SET iid=?, date=?, dosage=?, consultant=?, vaccinator=?, adverse=?, memo=?, given=? WHERE vid=?", (data["iid"], data["date"], data["dosage"], data["consultant"], data["vaccinator"], data["adverse"], data["memo"], given, vid))
31 if(cursor.rowcount==0):
32 return (False, "Failed to update record.")
33 else:
34 return (True, cursor.lastrowid)
35 except Exception as e:
36 return (False, e)
37
38 def delete(cursor, vid):
39 try:
40 cursor.execute("DELETE FROM vaccination WHERE vid=?", (vid,))
41 if(cursor.rowcount==0):
42 return (False, "Failed to delete record.")
43 else:
44 return (True, cursor.lastrowid)
45 except Exception as e:
46 return (False, e)
47
48 def mark(cursor, vid, given):
49 try:
50 cursor.execute("UPDATE vaccination SET given=? WHERE vid=?", (given, vid))
51 if(cursor.rowcount==0):
52 return (False, "Failed to update record.")
53 else:
54 return (True, cursor.lastrowid)
55 except Exception as e:
56 return (False, e)
57
58 def list_by_patient(cursor, pid):
59 try:
60 result=cursor.execute("SELECT * FROM vaccination LEFT JOIN inventory ON vaccination.iid=inventory.iid WHERE pid=? ORDER BY vaccination.date", (pid,))
61 if(cursor.rowcount==0):
62 return (False, "Record not found.")
63 else:
64 return (True, result.fetchall())
65 except Exception as e:
66 return (False, e)
67
68 def list_by_inventory(cursor, iid):
69 try:
70 result=cursor.execute("SELECT * FROM vaccination LEFT JOIN patients ON vaccination.pid=patients.pid WHERE iid=? ORDER BY vaccination.date", (iid,))
71 if(cursor.rowcount==0):
72 return (False, "Record not found.")
73 else:
74 return (True, result.fetchall())
75 except Exception as e:
76 return (False, e)
77
78 def list_by_date(cursor, date):
79 try:
80 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+"%",))
81 if(cursor.rowcount==0):
82 return (False, "Record not found.")
83 else:
84 return (True, result.fetchall())
85 except Exception as e:
86 return (False, e)