From 3fef2f06c48f2bfb3003cb63ac95eacf5b3f3bdc Mon Sep 17 00:00:00 2001 From: David Date: Sat, 11 May 2024 20:47:29 -0600 Subject: [PATCH] =?UTF-8?q?Receta=20no=20manches=20est=C3=A1=20bien=20larg?= =?UTF-8?q?o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/mx/uv/DaoReceta.java | 141 ++++++++++++++++++ .../src/main/java/mx/uv/IDaoReceta.java | 12 ++ .../src/main/java/mx/uv/Receta.java | 81 +++++++--- 3 files changed, 213 insertions(+), 21 deletions(-) create mode 100644 healthmanager_back/src/main/java/mx/uv/DaoReceta.java create mode 100644 healthmanager_back/src/main/java/mx/uv/IDaoReceta.java diff --git a/healthmanager_back/src/main/java/mx/uv/DaoReceta.java b/healthmanager_back/src/main/java/mx/uv/DaoReceta.java new file mode 100644 index 0000000..afbdf5f --- /dev/null +++ b/healthmanager_back/src/main/java/mx/uv/DaoReceta.java @@ -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 getData() throws SQLException { + List 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 getDataWhere(String condicion) throws SQLException { + List 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; + } + +} diff --git a/healthmanager_back/src/main/java/mx/uv/IDaoReceta.java b/healthmanager_back/src/main/java/mx/uv/IDaoReceta.java new file mode 100644 index 0000000..6396d0b --- /dev/null +++ b/healthmanager_back/src/main/java/mx/uv/IDaoReceta.java @@ -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 getData() throws SQLException; + public List getDataWhere(String condicion) throws SQLException; +} diff --git a/healthmanager_back/src/main/java/mx/uv/Receta.java b/healthmanager_back/src/main/java/mx/uv/Receta.java index 66921b4..21e052c 100644 --- a/healthmanager_back/src/main/java/mx/uv/Receta.java +++ b/healthmanager_back/src/main/java/mx/uv/Receta.java @@ -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; + } + + + }