From 11528a97f645ad70db77d8c78d740b4bc0f6a5f8 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 13 May 2024 20:21:44 -0600 Subject: [PATCH] Historial --- .../src/main/java/mx/uv/DaoHistorial.java | 106 ++++++++++++++++++ .../src/main/java/mx/uv/DaoMedico.java | 2 - .../src/main/java/mx/uv/DaoReceta.java | 4 +- .../src/main/java/mx/uv/Historial.java | 57 ++++++++++ .../src/main/java/mx/uv/IDaoHistorial.java | 12 ++ 5 files changed, 177 insertions(+), 4 deletions(-) create mode 100644 healthmanager_back/src/main/java/mx/uv/DaoHistorial.java create mode 100644 healthmanager_back/src/main/java/mx/uv/Historial.java create mode 100644 healthmanager_back/src/main/java/mx/uv/IDaoHistorial.java diff --git a/healthmanager_back/src/main/java/mx/uv/DaoHistorial.java b/healthmanager_back/src/main/java/mx/uv/DaoHistorial.java new file mode 100644 index 0000000..31ff5e5 --- /dev/null +++ b/healthmanager_back/src/main/java/mx/uv/DaoHistorial.java @@ -0,0 +1,106 @@ +package mx.uv; + +import java.sql.Connection; +import java.sql.Date; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +public class DaoHistorial implements IDaoHistorial{ + + private final Conexion con; + private Connection connection; + private PreparedStatement ps; + private ResultSet rs; + private Statement st; + + public DaoHistorial(){ + con=new Conexion(); + } + + @Override + public void add(Historial historial) throws SQLException { + connection = con.obtenerConexion(); + String consulta = "INSERT INTO Historial (fecha, fk_idPac, fk_idRec) VALUES(?,?,?)"; + ps = connection.prepareStatement(consulta); + ps.setDate(1, historial.getFecha()); + ps.setInt(2, historial.getIdPac()); + ps.setInt(3, historial.getIdRec()); + ps.execute(); + connection.close(); + } + + @Override + public void update(int id, Historial historial) throws SQLException { + connection = con.obtenerConexion(); + String consulta = "Update Historial " + + "set fecha = ?, fk_idPac = ?, fk_idRec = ? " + + "where idHistorial = ? ;"; + ps = connection.prepareStatement(consulta); + ps.setDate(1, historial.getFecha()); + ps.setInt(2, historial.getIdPac()); + ps.setInt(3, historial.getIdRec()); + ps.setInt(4, id); + ps.execute(); + connection.close(); + + } + + @Override + public void delete(int id) throws SQLException { + connection = con.obtenerConexion(); + String consulta = "Delete FROM Historial where idHistorial = ?;"; + ps = connection.prepareStatement(consulta); + ps.setInt(1, id); + ps.execute(); + connection.close(); + } + + @Override + public List getData() throws SQLException { + List historiales = new ArrayList<>(); + + String consulta = "SELECT * FROM Historial"; + connection = con.obtenerConexion(); + st = connection.createStatement(); + rs = st.executeQuery(consulta); + + while(rs.next()){ + int id = rs.getInt("idHistorial"); + Date fecha = rs.getDate("fecha"); + int idPac = rs.getInt("fk_idPac"); + int idRec = rs.getInt("fk_idRec"); + + historiales.add(new Historial(id, fecha, idRec, idPac)); + } + connection.close(); + return historiales; + } + + @Override + public List getDataWhere(String condicion) throws SQLException { + List historiales = new ArrayList<>(); + + String consulta = "SELECT * FROM Historial where " + condicion; + connection = con.obtenerConexion(); + st = connection.createStatement(); + rs = st.executeQuery(consulta); + + while(rs.next()){ + int id = rs.getInt("idHistorial"); + Date fecha = rs.getDate("fecha"); + int idPac = rs.getInt("fk_idPac"); + int idRec = rs.getInt("fk_idRec"); + + historiales.add(new Historial(id, fecha, idRec, idPac)); + } + connection.close(); + return historiales; + } + + + +} diff --git a/healthmanager_back/src/main/java/mx/uv/DaoMedico.java b/healthmanager_back/src/main/java/mx/uv/DaoMedico.java index ab184a3..13ede15 100644 --- a/healthmanager_back/src/main/java/mx/uv/DaoMedico.java +++ b/healthmanager_back/src/main/java/mx/uv/DaoMedico.java @@ -40,8 +40,6 @@ public class DaoMedico implements IDaoMedico{ String consulta = "Update Medico " + "set nombreMed = ?, cedProf = ?, contacto = ?, fk_idUsuario = ? " + "where idMed = ? ;"; - ps = connection.prepareStatement(consulta); - ps = connection.prepareStatement(consulta); ps.setString(1, medico.getNombreMed()); ps.setString(2, medico.getCedProf()); diff --git a/healthmanager_back/src/main/java/mx/uv/DaoReceta.java b/healthmanager_back/src/main/java/mx/uv/DaoReceta.java index afbdf5f..65a4fa9 100644 --- a/healthmanager_back/src/main/java/mx/uv/DaoReceta.java +++ b/healthmanager_back/src/main/java/mx/uv/DaoReceta.java @@ -49,7 +49,7 @@ public class DaoReceta implements IDaoReceta{ + "set nombreMed = ?, firmaMed = ?, " + "contactoMed = ?, pesoPac = ?, edadPac = ?, fecha = ?, presArt = ?, " + "tempPac = ?, fk_idMed = ?, fk_idPac = ?" - + " where idRec = ?;"; + + " where idRec = ? ;"; ps = connection.prepareStatement(consulta); //Receta(String nombreMed, Blob firmaMed, String contactoMed, float pesoPac, int edadPac, Date fecha,float presArt, float tempPac, Paciente paciente, Medico medico) ps.setString(1, receta.getNombreMed()); @@ -112,7 +112,7 @@ public class DaoReceta implements IDaoReceta{ public List getDataWhere(String condicion) throws SQLException { List recetas = new ArrayList<>(); - String consulta = "SELECT * FROM WHERE " + condicion; + String consulta = "SELECT * FROM Receta WHERE " + condicion; connection = con.obtenerConexion(); st = connection.createStatement(); rs = st.executeQuery(consulta); diff --git a/healthmanager_back/src/main/java/mx/uv/Historial.java b/healthmanager_back/src/main/java/mx/uv/Historial.java new file mode 100644 index 0000000..0acb29f --- /dev/null +++ b/healthmanager_back/src/main/java/mx/uv/Historial.java @@ -0,0 +1,57 @@ +package mx.uv; + +import java.sql.Date; + +public class Historial { + /*CREATE TABLE Historial ( + idHistorial INT PRIMARY KEY AUTO_INCREMENT, + fecha DATE NOT NULL, + fk_idPac INT NOT NULL, + fk_idRec INT NOT NULL, + FOREIGN KEY (fk_idPac) REFERENCES Paciente(idPac), + FOREIGN KEY (fk_idRec) REFERENCES Receta(idRec) ); */ + private int idHistorial; + private Date fecha; + private int idRec; + private int idPac; + + + + public Historial(Date fecha, int idRec, int idPac) { + this.fecha = fecha; + this.idRec = idRec; + this.idPac = idPac; + } + public Historial(int idHistorial, Date fecha, int idRec, int idPac) { + this.idHistorial = idHistorial; + this.fecha = fecha; + this.idRec = idRec; + this.idPac = idPac; + } + public int getIdHistorial() { + return idHistorial; + } + public void setIdHistorial(int idHistorial) { + this.idHistorial = idHistorial; + } + public Date getFecha() { + return fecha; + } + public void setFecha(Date fecha) { + this.fecha = fecha; + } + public int getIdRec() { + return idRec; + } + public void setIdRec(int idRec) { + this.idRec = idRec; + } + public int getIdPac() { + return idPac; + } + public void setIdPac(int idPac) { + this.idPac = idPac; + } + + +} diff --git a/healthmanager_back/src/main/java/mx/uv/IDaoHistorial.java b/healthmanager_back/src/main/java/mx/uv/IDaoHistorial.java new file mode 100644 index 0000000..c239df7 --- /dev/null +++ b/healthmanager_back/src/main/java/mx/uv/IDaoHistorial.java @@ -0,0 +1,12 @@ +package mx.uv; + +import java.sql.SQLException; +import java.util.List; + +public interface IDaoHistorial { + public void add(Historial historial) throws SQLException; + public void update(int id, Historial historial) throws SQLException; + public void delete(int id) throws SQLException; + public List getData() throws SQLException; + public List getDataWhere(String condicion) throws SQLException; +}