Receta no manches está bien largo

This commit is contained in:
David 2024-05-11 20:47:29 -06:00
parent 2ac62a6c5d
commit 3fef2f06c4
3 changed files with 213 additions and 21 deletions

View File

@ -0,0 +1,141 @@
package mx.uv;
import java.sql.Blob;
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 DaoReceta implements IDaoReceta{
private final Conexion con;
private Connection connection;
private PreparedStatement ps;
private ResultSet rs;
private Statement st;
public DaoReceta(){
con=new Conexion();
}
@Override
public void add(Receta receta) throws SQLException {
connection = con.obtenerConexion();
String consulta = "Receta (nombreMed, firmaMed, contactoMed, pesoPac, edadPac, fecha, presArt, tempPac, fk_idMed, fk_idPac) VALUES(?,?,?,?,?,?,?,?,?,?)";
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());
ps.setBlob(2, receta.getFirmaMed());
ps.setString(3, receta.getContactoMed());
ps.setFloat(4, receta.getPesoPac());
ps.setInt(5, receta.getEdadPac());
ps.setDate(6, receta.getFecha());
ps.setFloat(7, receta.getPresArt());
ps.setFloat(8, receta.getTempPac());
ps.setInt(9, receta.getIdPaciente());
ps.setInt(10, receta.getIdMedico());
ps.execute();
connection.close();
}
@Override
public void update(int id, Receta receta) throws SQLException {
connection = con.obtenerConexion();
String consulta = "UPDATE Receta "
+ "set nombreMed = ?, firmaMed = ?, "
+ "contactoMed = ?, pesoPac = ?, edadPac = ?, fecha = ?, presArt = ?, "
+ "tempPac = ?, fk_idMed = ?, fk_idPac = ?"
+ " 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());
ps.setBlob(2, receta.getFirmaMed());
ps.setString(3, receta.getContactoMed());
ps.setFloat(4, receta.getPesoPac());
ps.setInt(5, receta.getEdadPac());
ps.setDate(6, receta.getFecha());
ps.setFloat(7, receta.getPresArt());
ps.setFloat(8, receta.getTempPac());
ps.setInt(9, receta.getIdPaciente());
ps.setInt(10, receta.getIdMedico());
ps.setInt(11, id);
ps.execute();
connection.close();
}
@Override
public void delete(int id) throws SQLException {
connection = con.obtenerConexion();
String consulta = "Delete FROM Receta where idRec = ?;";
ps = connection.prepareStatement(consulta);
ps.setInt(1, id);
ps.execute();
connection.close();
}
@Override
public List<Receta> getData() throws SQLException {
List<Receta> recetas = new ArrayList<>();
String consulta = "SELECT * FROM Receta";
connection = con.obtenerConexion();
st = connection.createStatement();
rs = st.executeQuery(consulta);
while(rs.next()){
int idRec = rs.getInt("idRec");
String nombreMed = rs.getString("nombreMed");
Blob firmaMed = rs.getBlob("firmaMed");
String contactoMed = rs.getString("contactoMed");
float pesoPac = rs.getFloat("pesoPac");
int edadPac = rs.getInt("edadPac");
Date fecha = rs.getDate("fecha");
float presArt = rs.getFloat("presArt");
float tempPac = rs.getFloat("tempPac");
int idPaciente = rs.getInt("fk_idMed");
int idMedico = rs.getInt("fk_idPac");
recetas.add(new Receta(idRec, nombreMed, firmaMed, contactoMed, pesoPac, edadPac,
fecha, presArt, tempPac, idPaciente, idMedico));
}
connection.close();
return recetas;
}
@Override
public List<Receta> getDataWhere(String condicion) throws SQLException {
List<Receta> recetas = new ArrayList<>();
String consulta = "SELECT * FROM WHERE " + condicion;
connection = con.obtenerConexion();
st = connection.createStatement();
rs = st.executeQuery(consulta);
while(rs.next()){
int idRec = rs.getInt("idRec");
String nombreMed = rs.getString("nombreMed");
Blob firmaMed = rs.getBlob("firmaMed");
String contactoMed = rs.getString("contactoMed");
float pesoPac = rs.getFloat("pesoPac");
int edadPac = rs.getInt("edadPac");
Date fecha = rs.getDate("fecha");
float presArt = rs.getFloat("presArt");
float tempPac = rs.getFloat("tempPac");
int idPaciente = rs.getInt("fk_idMed");
int idMedico = rs.getInt("fk_idPac");
recetas.add(new Receta(idRec, nombreMed, firmaMed, contactoMed, pesoPac, edadPac,
fecha, presArt, tempPac, idPaciente, idMedico));
}
connection.close();
return recetas;
}
}

View File

@ -0,0 +1,12 @@
package mx.uv;
import java.sql.SQLException;
import java.util.List;
public interface IDaoReceta {
public void add(Receta receta) throws SQLException;
public void update(int id, Receta receta) throws SQLException;
public void delete(int id) throws SQLException;
public List<Receta> getData() throws SQLException;
public List<Receta> getDataWhere(String condicion) throws SQLException;
}

View File

@ -1,7 +1,7 @@
package mx.uv;
import java.sql.Blob;
import java.util.Date;
import java.sql.Date;
public class Receta {
private int idRec;
@ -13,13 +13,15 @@ public class Receta {
private Date fecha;
private float presArt;
private float tempPac;
private Paciente paciente;
private Medico medico;
private int idPaciente;
private int idMedico;
public Receta() {
}
public Receta(String nombreMed, Blob firmaMed, String contactoMed, float pesoPac, int edadPac, Date fecha,
float presArt, float tempPac) {
this.nombreMed = nombreMed;
@ -47,10 +49,26 @@ public class Receta {
this.tempPac = tempPac;
}
public Receta(String nombreMed, Blob firmaMed, String contactoMed, float pesoPac, int edadPac, Date fecha,
float presArt, float tempPac, int idPaciente, int idMedico) {
this.nombreMed = nombreMed;
this.firmaMed = firmaMed;
this.contactoMed = contactoMed;
this.pesoPac = pesoPac;
this.edadPac = edadPac;
this.fecha = fecha;
this.presArt = presArt;
this.tempPac = tempPac;
this.idPaciente = idPaciente;
this.idMedico = idMedico;
}
public Receta(int idRec, String nombreMed, Blob firmaMed, String contactoMed, float pesoPac, int edadPac,
Date fecha, float presArt, float tempPac, Paciente paciente, Medico medico) {
Date fecha, float presArt, float tempPac, int idPaciente, int idMedico) {
this.idRec = idRec;
this.nombreMed = nombreMed;
this.firmaMed = firmaMed;
@ -60,80 +78,101 @@ public class Receta {
this.fecha = fecha;
this.presArt = presArt;
this.tempPac = tempPac;
this.paciente = paciente;
this.medico = medico;
this.idPaciente = idPaciente;
this.idMedico = idMedico;
}
public Paciente getPaciente() {
return paciente;
}
public void setPaciente(Paciente paciente) {
this.paciente = paciente;
}
public Medico getMedico() {
return medico;
}
public void setMedico(Medico medico) {
this.medico = medico;
}
public int getIdRec() {
return idRec;
}
public void setIdRec(int idRec) {
this.idRec = idRec;
}
public String getNombreMed() {
return nombreMed;
}
public void setNombreMed(String nombreMed) {
this.nombreMed = nombreMed;
}
public Blob getFirmaMed() {
return firmaMed;
}
public void setFirmaMed(Blob firmaMed) {
this.firmaMed = firmaMed;
}
public String getContactoMed() {
return contactoMed;
}
public void setContactoMed(String contactoMed) {
this.contactoMed = contactoMed;
}
public float getPesoPac() {
return pesoPac;
}
public void setPesoPac(float pesoPac) {
this.pesoPac = pesoPac;
}
public int getEdadPac() {
return edadPac;
}
public void setEdadPac(int edadPac) {
this.edadPac = edadPac;
}
public Date getFecha() {
return fecha;
}
public void setFecha(Date fecha) {
this.fecha = fecha;
}
public float getPresArt() {
return presArt;
}
public void setPresArt(float presArt) {
this.presArt = presArt;
}
public float getTempPac() {
return tempPac;
}
public void setTempPac(float tempPac) {
this.tempPac = tempPac;
}
public int getIdPaciente() {
return idPaciente;
}
public void setIdPaciente(int idPaciente) {
this.idPaciente = idPaciente;
}
public int getIdMedico() {
return idMedico;
}
public void setIdMedico(int idMedico) {
this.idMedico = idMedico;
}
}