Historial

This commit is contained in:
David 2024-05-13 20:21:44 -06:00
parent 3fef2f06c4
commit 11528a97f6
5 changed files with 177 additions and 4 deletions

View File

@ -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<Historial> getData() throws SQLException {
List<Historial> 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<Historial> getDataWhere(String condicion) throws SQLException {
List<Historial> 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;
}
}

View File

@ -40,8 +40,6 @@ public class DaoMedico implements IDaoMedico{
String consulta = "Update Medico " String consulta = "Update Medico "
+ "set nombreMed = ?, cedProf = ?, contacto = ?, fk_idUsuario = ? " + "set nombreMed = ?, cedProf = ?, contacto = ?, fk_idUsuario = ? "
+ "where idMed = ? ;"; + "where idMed = ? ;";
ps = connection.prepareStatement(consulta);
ps = connection.prepareStatement(consulta); ps = connection.prepareStatement(consulta);
ps.setString(1, medico.getNombreMed()); ps.setString(1, medico.getNombreMed());
ps.setString(2, medico.getCedProf()); ps.setString(2, medico.getCedProf());

View File

@ -49,7 +49,7 @@ public class DaoReceta implements IDaoReceta{
+ "set nombreMed = ?, firmaMed = ?, " + "set nombreMed = ?, firmaMed = ?, "
+ "contactoMed = ?, pesoPac = ?, edadPac = ?, fecha = ?, presArt = ?, " + "contactoMed = ?, pesoPac = ?, edadPac = ?, fecha = ?, presArt = ?, "
+ "tempPac = ?, fk_idMed = ?, fk_idPac = ?" + "tempPac = ?, fk_idMed = ?, fk_idPac = ?"
+ " where idRec = ?;"; + " where idRec = ? ;";
ps = connection.prepareStatement(consulta); 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) //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()); ps.setString(1, receta.getNombreMed());
@ -112,7 +112,7 @@ public class DaoReceta implements IDaoReceta{
public List<Receta> getDataWhere(String condicion) throws SQLException { public List<Receta> getDataWhere(String condicion) throws SQLException {
List<Receta> recetas = new ArrayList<>(); List<Receta> recetas = new ArrayList<>();
String consulta = "SELECT * FROM WHERE " + condicion; String consulta = "SELECT * FROM Receta WHERE " + condicion;
connection = con.obtenerConexion(); connection = con.obtenerConexion();
st = connection.createStatement(); st = connection.createStatement();
rs = st.executeQuery(consulta); rs = st.executeQuery(consulta);

View File

@ -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;
}
}

View File

@ -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<Historial> getData() throws SQLException;
public List<Historial> getDataWhere(String condicion) throws SQLException;
}