-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a27bc7
commit 7572de7
Showing
43 changed files
with
1,031 additions
and
783 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import os | ||
|
||
SECRET_KEY = os.urandom(32) | ||
|
||
DEBUG = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
from flask import render_template, redirect, request, session | ||
from models.DB import connectDB | ||
|
||
def splittime(ora_inizio,ora_fine): | ||
x = ora_inizio.split(':') | ||
y = ora_fine.split(':') | ||
|
||
hours1 = int(x[0]) | ||
minutes1 = int(x[1]) | ||
hours2 = int(y[0]) | ||
minutes2 = int(y[1]) | ||
|
||
ore = [hours1] | ||
minuti = [minutes1] | ||
while hours1!=hours2 or minutes1!=minutes2: | ||
minutes1+=15 | ||
if minutes1 >= 60: | ||
minutes1-=60 | ||
hours1+=1 | ||
|
||
ore.append(hours1) | ||
minuti.append(minutes1) | ||
|
||
ora_splittata = [] | ||
for i in range(len(ore)): | ||
if (minuti[i]==0): | ||
ora_splittata.append(str(ore[i])+':'+str(minuti[i])+'0') | ||
else: | ||
ora_splittata.append(str(ore[i])+':'+str(minuti[i])) | ||
|
||
return ora_splittata | ||
|
||
def creaDisponibilitaTamponi(): | ||
msg_error = "" | ||
if 'loggedin' in session: | ||
connection = connectDB() | ||
tamponi = connection.execute('SELECT * FROM Tamponi WHERE ID_Farmacia = ?',(session['id'],)).fetchall() | ||
totaleRapido = connection.execute('SELECT COALESCE(SUM(N_pezzi),0) as TOT FROM Tamponi WHERE tipo = ? AND ID_Farmacia = ?',('Rapido',session['id'],)).fetchall() | ||
totaleMolecolare = connection.execute('SELECT COALESCE(SUM(N_pezzi),0) as TOT FROM Tamponi WHERE tipo = ? AND ID_Farmacia = ?',('Molecolare',session['id'],)).fetchall() | ||
connection.close() | ||
|
||
if request.method == "POST": | ||
NomeTampone = request.form['NomeTampone'] | ||
Tipo= request.form['Tipo'] | ||
N_pezzi = request.form['N_pezzi'] | ||
Giorno = request.form['Giorno'] | ||
OraInizio = request.form['OraInizio'] | ||
OraFine = request.form['OraFine'] | ||
Prezzo = request.form['Prezzo'] | ||
|
||
connection = connectDB() | ||
cursor = connection.cursor() | ||
|
||
try: | ||
cursor.execute('INSERT INTO Tamponi (NomeTampone, Tipo, N_pezzi, Giorno, OraInizio, OraFine, Prezzo, ID_Farmacia) VALUES (?,?,?,?,?,?,?,?)', (NomeTampone,Tipo,N_pezzi,Giorno,OraInizio,OraFine,Prezzo,session['id'],)) | ||
ID_Tampone = cursor.lastrowid | ||
FasceOrarie=splittime(OraInizio,OraFine) | ||
for Orario in FasceOrarie: | ||
connection.execute('INSERT INTO Orari (ID_Tampone, Orario, Giorno) VALUES (?,?,?)', (ID_Tampone,Orario,Giorno,)) | ||
connection.commit() | ||
except: | ||
msg_error = "Tampone già presente nel sistema, se si vuole aggiornare la disponibilità andare in Modifica disponibilità tamponi" | ||
tamponi = connection.execute('SELECT * FROM Tamponi WHERE ID_Farmacia = ?',(session['id'],)).fetchall() | ||
totaleRapido = connection.execute('SELECT COALESCE(SUM(N_pezzi),0) as TOT FROM Tamponi WHERE tipo = ? AND ID_Farmacia = ?',('Rapido',session['id'],)).fetchall() | ||
totaleMolecolare = connection.execute('SELECT COALESCE(SUM(N_pezzi),0) as TOT FROM Tamponi WHERE tipo = ? AND ID_Farmacia = ?',('Molecolare',session['id'],)).fetchall() | ||
connection.close() | ||
return render_template('/FarmaciaView/creazioneDisponibilitaTamponi.html',tamponi=tamponi, totaleRapido=totaleRapido, totaleMolecolare=totaleMolecolare, msg_error=msg_error) | ||
else: | ||
return redirect('/loginFarmacia') | ||
return render_template('/FarmaciaView/creazioneDisponibilitaTamponi.html',tamponi=tamponi, totaleRapido=totaleRapido, totaleMolecolare=totaleMolecolare, msg_error=msg_error) | ||
|
||
def modificaDisponibilitaTamponi(): | ||
msg = "" | ||
if 'loggedin' in session: | ||
connection = connectDB() | ||
tamponi = connection.execute('SELECT * FROM Tamponi WHERE ID_Farmacia = ?',(session['id'],)).fetchall() | ||
connection.close() | ||
else: | ||
return redirect('/loginFarmacia') | ||
return render_template('/FarmaciaView/modificaDisponibilitaTamponi.html', tamponi=tamponi, msg=msg) | ||
|
||
def aggiornaTamponi(ID_tamponi): | ||
msg = "" | ||
if 'loggedin' in session: | ||
if request.method == "POST": | ||
NomeTampone = request.form['NomeTampone'] | ||
Tipo = request.form['Tipo'] | ||
N_pezzi = request.form['N_pezzi'] | ||
Giorno = request.form['Giorno'] | ||
OraInizio = request.form['OraInizio'] | ||
OraFine = request.form['OraFine'] | ||
Prezzo = request.form['Prezzo'] | ||
connection = connectDB() | ||
connection.execute('UPDATE Tamponi SET NomeTampone = ?, Tipo = ?, N_pezzi = ?, Giorno = ?, OraInizio = ?, OraFine = ?, Prezzo = ? WHERE ID = ?', (NomeTampone,Tipo,N_pezzi,Giorno,OraInizio,OraFine,Prezzo,ID_tamponi)) | ||
connection.execute('DELETE FROM Orari WHERE ID_Tampone = ?', (ID_tamponi,)) | ||
FasceOrarie=splittime(OraInizio,OraFine) | ||
for Orario in FasceOrarie: | ||
connection.execute('INSERT INTO Orari (ID_Tampone, Orario, Giorno) VALUES (?,?,?)', (ID_tamponi,Orario,Giorno,)) | ||
connection.commit() | ||
tamponi = connection.execute('SELECT * FROM Tamponi WHERE ID_Farmacia = ?',(session['id'],)).fetchall() | ||
connection.close() | ||
msg = "Aggiornamento del tampone " + NomeTampone + " è avvenuto con successo!" | ||
else: | ||
return redirect('/loginFarmacia') | ||
return render_template('/FarmaciaView/modificaDisponibilitaTamponi.html', tamponi=tamponi, msg=msg) | ||
|
||
def rimozioneTamponi(): | ||
msg = "" | ||
if 'loggedin' in session: | ||
connection = connectDB() | ||
tamponi = connection.execute('SELECT * FROM Tamponi WHERE ID_Farmacia = ?',(session['id'],)).fetchall() | ||
connection.close() | ||
else: | ||
return redirect('/loginFarmacia') | ||
return render_template('/FarmaciaView/rimozioneDisponibilitaTamponi.html', tamponi=tamponi, msg=msg) | ||
|
||
def rimuoviTamponi(ID_tamponi): | ||
msg = "" | ||
if 'loggedin' in session: | ||
connection = connectDB() | ||
connection.execute('DELETE FROM Tamponi WHERE ID = ?', (ID_tamponi,)) | ||
connection.execute('DELETE FROM Orari WHERE ID_Tampone = ?', (ID_tamponi,)) | ||
connection.commit() | ||
tamponi = connection.execute('SELECT * FROM Tamponi WHERE ID_Farmacia = ?',(session['id'],)).fetchall() | ||
connection.close() | ||
msg = "Rimozione del tampone nr. " + str(ID_tamponi) + " è avvenuto con successo!" | ||
else: | ||
return redirect('/loginFarmacia') | ||
return render_template('/FarmaciaView/rimozioneDisponibilitaTamponi.html', tamponi=tamponi, msg=msg) | ||
|
||
def loginFarmacia(): | ||
msg = "" | ||
if request.method == 'POST': | ||
Email = request.form['Email'] | ||
PWD = request.form['PWD'] | ||
connection = connectDB() | ||
account = connection.execute('SELECT * FROM Farmacie WHERE Email = ? AND PWD = ?', (Email, PWD,)).fetchone() | ||
|
||
if account: | ||
session['loggedin'] = True | ||
session['id'] = account['ID'] | ||
session['username'] = account['Email'] | ||
connection = connectDB() | ||
prenotazioni = connection.execute('SELECT * FROM Prenotazioni WHERE ID_Farmacia = ? AND Prenotazioni.Giorno >= DATE()',(session['id'],)).fetchall() | ||
totaleRapido = connection.execute('SELECT COALESCE(SUM(N_pezzi),0) as TOT FROM Tamponi WHERE tipo = ? AND ID_Farmacia = ?',('Rapido',session['id'],)).fetchone() | ||
totaleMolecolare = connection.execute('SELECT COALESCE(SUM(N_pezzi),0) as TOT FROM Tamponi WHERE tipo = ? AND ID_Farmacia = ?',('Molecolare',session['id'],)).fetchone() | ||
connection.close() | ||
return render_template('/FarmaciaView/dashboardFarmacia.html', nomefarmacia=account['NomeFarmacia'], prenotazioni=prenotazioni, totaleRapido=totaleRapido, totaleMolecolare=totaleMolecolare) | ||
else: | ||
msg = 'Credenziali inserite non valide!' | ||
|
||
return render_template('/FarmaciaView/loginFarmacia.html',msg=msg) | ||
|
||
def dashFarmacia(): | ||
if 'loggedin' in session: | ||
connection = connectDB() | ||
prenotazioni = connection.execute('SELECT * FROM Prenotazioni WHERE ID_Farmacia = ? AND Prenotazioni.Giorno >= DATE()',(session['id'],)).fetchall() | ||
nomefarmacia = connection.execute('SELECT (NomeFarmacia) FROM Farmacie WHERE ID = ?',(session['id'],)).fetchone() | ||
totaleRapido = connection.execute('SELECT COALESCE(SUM(N_pezzi),0) as TOT FROM Tamponi WHERE Tipo = ? AND ID_Farmacia = ?',('Rapido',session['id'],)).fetchone() | ||
totaleMolecolare = connection.execute('SELECT COALESCE(SUM(N_pezzi),0) as TOT FROM Tamponi WHERE Tipo = ? AND ID_Farmacia = ?',('Molecolare',session['id'],)).fetchone() | ||
connection.close() | ||
else: | ||
return redirect('/loginFarmacia') | ||
return render_template('/FarmaciaView/dashboardFarmacia.html', nomefarmacia=nomefarmacia['NomeFarmacia'], prenotazioni=prenotazioni, totaleRapido=totaleRapido, totaleMolecolare=totaleMolecolare) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from flask import render_template, redirect, request, session | ||
from models.DB import connectDB | ||
|
||
def aggiuntaEsitoTamponi(): | ||
if 'loggedin' in session: | ||
connection = connectDB() | ||
prenotazioni = connection.execute('SELECT * FROM Prenotazioni WHERE ID_Farmacia = ?',(session['id'],)).fetchall() | ||
connection.close() | ||
else: | ||
return redirect('/loginFarmacia') | ||
return render_template('/FarmaciaView/aggiuntaEsitoTampone.html', prenotazioni=prenotazioni) | ||
|
||
def aggiungiEsitoTamponi(ID): | ||
if 'loggedin' in session: | ||
if request.method == "POST": | ||
EsitoTampone = request.form['EsitoTampone'] | ||
connection = connectDB() | ||
connection.execute('UPDATE Prenotazioni SET EsitoTampone = ? WHERE ID = ?', (EsitoTampone,ID)) | ||
connection.commit() | ||
connection.close() | ||
else: | ||
return redirect('/loginFarmacia') | ||
return redirect('/aggiuntaEsitoTamponi') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
from flask import render_template, redirect, request, session | ||
from models.DB import connectDB | ||
|
||
def loginAdmin(): | ||
msg = "" | ||
if request.method == 'POST': | ||
Username = request.form['Username'] | ||
PWD = request.form['PWD'] | ||
connection = connectDB() | ||
account = connection.execute('SELECT * FROM Admin WHERE Username = ? AND PWD = ?', (Username, PWD,)).fetchone() | ||
connection.close() | ||
|
||
if account: | ||
session['loggedin'] = True | ||
session['id'] = account['ID'] | ||
session['id'] = account['Username'] | ||
return redirect('/dashboardAdmin') | ||
else: | ||
msg = 'Credenziali inserite non valide!' | ||
|
||
return render_template('/AdminView/loginAdmin.html',msg=msg) | ||
|
||
def logout(): | ||
session.pop('loggedin', None) | ||
session.pop('id', None) | ||
session.pop('username', None) | ||
return redirect('/') | ||
|
||
def dashAdmin(): | ||
if 'loggedin' in session: | ||
connection = connectDB() | ||
farmacie = connection.execute('SELECT * FROM Farmacie').fetchall() | ||
connection.close() | ||
else: | ||
return redirect('/loginAdmin') | ||
return render_template('/AdminView/dashboardAdmin.html', farmacie=farmacie) | ||
|
||
def creaFarmacia(): | ||
if 'loggedin' in session: | ||
if request.method == "POST": | ||
NomeFarmacia = request.form['NomeFarmacia'] | ||
Citta = request.form['Citta'] | ||
CAP = request.form['CAP'] | ||
Indirizzo = request.form['Indirizzo'] | ||
Email = request.form['Email'] | ||
PWD = request.form['PWD'] | ||
connection = connectDB() | ||
connection.execute('INSERT INTO Farmacie (NomeFarmacia, Citta, CAP, Indirizzo, Email, PWD) VALUES (?,?,?,?,?,?)', (NomeFarmacia,Citta,CAP,Indirizzo,Email,PWD)) | ||
connection.commit() | ||
connection.close() | ||
return redirect('/dashboardAdmin') | ||
else: | ||
return redirect('/loginAdmin') | ||
return render_template('/AdminView/creaFarmacia.html') | ||
|
||
def ricercaFarmacia(): | ||
if 'loggedin' in session: | ||
if request.method == "POST": | ||
NomeFarmacia = request.form['NomeFarmacia'] | ||
Citta = request.form['Citta'] | ||
CAP = request.form['CAP'] | ||
connection = connectDB() | ||
farmacie = connection.execute('SELECT * FROM Farmacie WHERE (NomeFarmacia = ? OR Citta = ? OR CAP = ?)', (NomeFarmacia,Citta,CAP,)).fetchall() | ||
connection.close() | ||
return render_template('/AdminView/listaFarmacie.html', farmacie=farmacie) | ||
else: | ||
return redirect('/loginAdmin') | ||
return render_template('/AdminView/ricercaFarmacia.html') | ||
|
||
def modificaFarmacia(): | ||
msg = "" | ||
if 'loggedin' in session: | ||
connection = connectDB() | ||
farmacie = connection.execute('SELECT * FROM Farmacie').fetchall() | ||
connection.close() | ||
else: | ||
return redirect('/loginAdmin') | ||
return render_template('/AdminView/modificaFarmacia.html', farmacie=farmacie, msg=msg) | ||
|
||
def aggiornaFarmacia(ID): | ||
msg = "" | ||
if 'loggedin' in session: | ||
if request.method == "POST": | ||
NomeFarmacia = request.form['NomeFarmacia'] | ||
Citta = request.form['Citta'] | ||
CAP = request.form['CAP'] | ||
Email = request.form['Email'] | ||
PWD = request.form['PWD'] | ||
connection = connectDB() | ||
connection.execute('UPDATE Farmacie SET NomeFarmacia = ?, Citta = ?, CAP = ?, Email = ?, PWD = ? WHERE ID = ?', (NomeFarmacia,Citta,CAP,Email,PWD,ID)) | ||
connection.commit() | ||
farmacie = connection.execute('SELECT * FROM Farmacie').fetchall() | ||
connection.close() | ||
msg = "Aggiornamento della farmacia " + NomeFarmacia + " è avvenuto con successo!" | ||
else: | ||
return redirect('/loginAdmin') | ||
return render_template('/AdminView/modificaFarmacia.html', farmacie=farmacie, msg=msg) | ||
|
||
def rimozioneFarmacia(): | ||
msg = "" | ||
if 'loggedin' in session: | ||
connection = connectDB() | ||
farmacie = connection.execute('SELECT * FROM Farmacie').fetchall() | ||
connection.close() | ||
else: | ||
return redirect('/loginAdmin') | ||
return render_template('/AdminView/rimozioneFarmacia.html', farmacie=farmacie, msg=msg) | ||
|
||
def rimuoviFarmacia(ID): | ||
msg = "" | ||
if 'loggedin' in session: | ||
connection = connectDB() | ||
connection.execute('DELETE FROM Farmacie WHERE ID = ?', (ID,)) | ||
connection.commit() | ||
farmacie = connection.execute('SELECT * FROM Farmacie').fetchall() | ||
connection.close() | ||
msg = "Rimozione della farmacia nr. " + str(ID) + " è avvenuta con successo!" | ||
else: | ||
return redirect('/loginAdmin') | ||
return render_template('/AdminView/rimozioneFarmacia.html', farmacie=farmacie, msg=msg) |
Oops, something went wrong.