]>
Softwares of Agnibho - librevax.git/blob - personnel.py
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/>.
8 def create ( cursor
, data
, active
):
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." )
17 return ( True , cursor
. lastrowid
)
18 except Exception as e
:
22 def read ( cursor
, sid
):
24 result
= cursor
. execute ( "SELECT * FROM personnel WHERE sid=?" , ( sid
,))
25 return ( True , result
. fetchone ())
26 except Exception as e
:
29 def update ( cursor
, sid
, data
, active
):
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." )
38 return ( True , cursor
. lastrowid
)
39 except Exception as e
:
42 def delete ( cursor
, sid
):
44 cursor
. execute ( "DELETE FROM personnel WHERE sid=?" , ( sid
,))
45 if ( cursor
. rowcount
<= 0 ):
46 return ( False , "Failed to delete record." )
48 return ( True , cursor
. lastrowid
)
49 except Exception as e
:
52 def list ( cursor
, mid
, filter = None ):
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
,))
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
: