Пример #1
0
 def __empty__(self):
     '''
     self.patients = []
     return True
     '''
     sql = "DELETE FROM PATIENTS;"
     try:
         cnx.execute(sql)
         cnx.commit()
         self.__getall__(self)
         return True
     except Exception as e:
         return False
Пример #2
0
 def __add__(p):
     '''
     if self.patients.__len__():
         for i in self.patients:
             if i.cin == self.cin:
                 return False
     self.patients.append(self)
     return True
     '''
     date_naissance = sqlite3.Date(int(p.date_naiss.split("-")[2]),int(p.date_naiss.split("-")[1]), int(p.date_naiss.split("-")[0]))
     sql = "INSERT INTO PATIENTS(CIN, NOM, PRENOM, DATE_NAISS, NUM_TEL) VALUES (?,?,?,?,?);"
     try:
         cnx.execute(sql, (str(p.cin), p.nom, p.prenom, date_naissance, p.num_tel))
         cnx.commit()
         Patient.__getall__(Patient)
         return True
     except Exception as e:
         print(e)
         return False
Пример #3
0
 def __delete__(self, ncin):
     '''
     for i in self.patients:
         if i.cin == ncin:
             self.patients.remove(i)
             return True
     return False
     '''
     self.__getall__(self)
     if self.patients:
         for i in self.patients:
             if i.cin == ncin:
                 sql = "DELETE FROM PATIENTS WHERE CIN="+str(ncin)+";"
                 try:
                     cnx.execute(sql)
                     cnx.commit()
                     return True
                 except Exception as e:
                     print(e)
                     return False
     return False
Пример #4
0
 def __edit___(self, pcin,  patient_modif):
     '''
     for i in self.patients:
         if i.cin == pcin:
             self.patients[self.patients.index(i)] = patient_modif
             return True
     return False
     '''
     self.__getall__(self)
     if self.patients:
         for i in self.patients:
             if i.cin == pcin:
                 sql = "UPDATE PATIENTS SET NOM = ?, PRENOM = ?, DATE_NAISS = ?, NUM_TEL=? WHERE CIN=?;"
                 date_naissance = sqlite3.Date(int(patient_modif.date_naiss.split("-")[2]),int(patient_modif.date_naiss.split("-")[1]), int(patient_modif.date_naiss.split("-")[0]))
                 try:
                     cnx.execute(sql, (patient_modif.nom, patient_modif.prenom, date_naissance, patient_modif.num_tel, str(pcin)))
                     cnx.commit()
                     return True
                 except Exception as e:
                     return False
     return False
Пример #5
0
 def __getall__(self):
     #get patients list from database
     sql = "SELECT * FROM PATIENTS;"
     pats = []
     try:
         cursor = cnx.execute(sql)
         for i in cursor:
             pats.append(self(i[0], i[1], i[2], i[3], i[4]))
         self.patients = pats
     except Exception as e:
         print(e)
     return self.patients