]> Softwares of Agnibho - librevax.git/blob - personnel.py
Database dump
[librevax.git] / personnel.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, active):
9 try:
10 cid=None
11 if(data["cid"]!=""):
12 cid=data["cid"]
13 cursor.execute("INSERT INTO personnel (cid, mid, name, designation, contact, role, info, active) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", (cid, data["mid"], data["name"], data["designation"], data["contact"], data["role"], data["info"], active))
14 if(cursor.rowcount<=0):
15 return (False, "Failed to create record.")
16 else:
17 return (True, cursor.lastrowid)
18 except Exception as e:
19 raise(e)
20 return (False, e)
21
22 def read(cursor, sid):
23 try:
24 result=cursor.execute("SELECT * FROM personnel WHERE sid=?", (sid,))
25 return (True, result.fetchone())
26 except Exception as e:
27 return (False, e)
28
29 def update(cursor, sid, data, active):
30 try:
31 cid=None
32 if(data["cid"]!=""):
33 cid=data["cid"]
34 cursor.execute("UPDATE personnel SET cid=?, mid=?, name=?, designation=?, contact=?, role=?, info=?, active=? WHERE sid=?", (cid, data["mid"], data["name"], data["designation"], data["contact"], data["role"], data["info"], active, sid))
35 if(cursor.rowcount<=0):
36 return (False, "Failed to update record.")
37 else:
38 return (True, cursor.lastrowid)
39 except Exception as e:
40 return (False, e)
41
42 def delete(cursor, sid):
43 try:
44 cursor.execute("DELETE FROM personnel WHERE sid=?", (sid,))
45 if(cursor.rowcount<=0):
46 return (False, "Failed to delete record.")
47 else:
48 return (True, cursor.lastrowid)
49 except Exception as e:
50 return (False, e)
51
52 def list(cursor, mid, filter=None):
53 try:
54 if(filter=="consultant"):
55 result=cursor.execute("SELECT * FROM personnel WHERE role='consultant' AND active=TRUE AND mid IN (0, ?)", (mid,))
56 elif(filter=="vaccinator"):
57 result=cursor.execute("SELECT * FROM personnel WHERE role='vaccinator' AND active=TRUE AND mid IN (0, ?)", (mid,))
58 elif(filter=="staff"):
59 result=cursor.execute("SELECT * FROM personnel WHERE role='staff' AND active=TRUE AND mid IN (0, ?)", (mid,))
60 else:
61 result=cursor.execute("SELECT * FROM personnel WHERE mid IN (0, ?) ORDER BY active DESC, role ASC", (mid,))
62 return (True, result.fetchall())
63 except Exception as e:
64 raise(e)
65 return (False, e)