back medico
This commit is contained in:
parent
1d384b23ad
commit
6d832b59da
|
@ -11,6 +11,8 @@ import com.google.gson.Gson;
|
||||||
*/
|
*/
|
||||||
public class App
|
public class App
|
||||||
{
|
{
|
||||||
|
static Gson gson = new Gson();
|
||||||
|
static HashMap<String, Usuario> usuarios = new HashMap<>();
|
||||||
public static void main( String[] args )
|
public static void main( String[] args )
|
||||||
{
|
{
|
||||||
System.out.println( "HEALTH MANAGER BACK END CORRIENDO..." );
|
System.out.println( "HEALTH MANAGER BACK END CORRIENDO..." );
|
||||||
|
@ -33,5 +35,59 @@ public class App
|
||||||
|
|
||||||
before((request, response) -> response.header("Access-Control-Allow-Origin", "*"));
|
before((request, response) -> response.header("Access-Control-Allow-Origin", "*"));
|
||||||
//CORS
|
//CORS
|
||||||
|
|
||||||
|
post("/validacion", (request, response) -> {
|
||||||
|
response.type("application/json");
|
||||||
|
String payload = request.body();
|
||||||
|
String mensaje = "";
|
||||||
|
Usuario usuario = gson.fromJson(payload, Usuario.class);
|
||||||
|
System.out.println("usuario " + usuario.getCorreo()+ " " + usuario.getContraseña());
|
||||||
|
boolean respuesta = DaoUsuario.estaRegistrado(usuario.getCorreo(), usuario.getContraseña());
|
||||||
|
boolean respuestaMedico = usuario.esMedico();
|
||||||
|
System.out.println(respuesta);
|
||||||
|
System.out.println(respuestaMedico);
|
||||||
|
if (respuesta == true) {
|
||||||
|
System.out.println("Usuario Correcto");
|
||||||
|
mensaje = "Usuario Correcto";
|
||||||
|
/*if(respuestaMedico == true){
|
||||||
|
mensaje = "Usuario Medico";
|
||||||
|
}*/
|
||||||
|
} else {
|
||||||
|
System.out.println("Usuario incorrecto");
|
||||||
|
mensaje = "Usuario incorrecto";
|
||||||
|
}
|
||||||
|
return mensaje;
|
||||||
|
});
|
||||||
|
|
||||||
|
post("/validacionMedico", (request, response) -> {
|
||||||
|
response.type("application/json");
|
||||||
|
String payload = request.body();
|
||||||
|
String mensaje = "";
|
||||||
|
Usuario usuario = gson.fromJson(payload, Usuario.class);
|
||||||
|
System.out.println("usuario " + usuario.getCorreo() + usuario.getContraseña() + usuario.esMedico());
|
||||||
|
boolean respuesta = DaoUsuario.estaRegistrado(usuario.getCorreo(), usuario.getContraseña());
|
||||||
|
System.out.println(respuesta);
|
||||||
|
if (respuesta == true) {
|
||||||
|
System.out.println("Usuario Correcto");
|
||||||
|
|
||||||
|
mensaje = "Usuario Correcto";
|
||||||
|
} else {
|
||||||
|
System.out.println("Usuario incorrecto");
|
||||||
|
mensaje = "Usuario incorrecto";
|
||||||
|
}
|
||||||
|
return mensaje;
|
||||||
|
});
|
||||||
|
|
||||||
|
get("/datosUsuario", (request, response) -> {
|
||||||
|
String correo = request.queryParams("correo");
|
||||||
|
response.type("application/json");
|
||||||
|
return gson.toJson(DaoPaciente.datosPaciente(correo));
|
||||||
|
});
|
||||||
|
|
||||||
|
get("/MisRecetas", (request, response) -> {
|
||||||
|
String nombre = request.queryParams("idUsuario");
|
||||||
|
response.type("application/json");
|
||||||
|
return gson.toJson(DaoUsuario.dameMiReceta(nombre));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,9 @@ public class Conexion {
|
||||||
|
|
||||||
private Connection conexion;
|
private Connection conexion;
|
||||||
String driver = "com.mysql.cj.jdbc.Driver";
|
String driver = "com.mysql.cj.jdbc.Driver";
|
||||||
private String url = "jdbc:mysql://root:tdPXEKculfAIumCBQirpMvZYXnrOuCbZ@monorail.proxy.rlwy.net:51101/railway";
|
private String url = "jdbc:mysql://root:ECGtugnerOnWGDCdGXSlqeNQSUGEJfhk@monorail.proxy.rlwy.net:15340/railway";
|
||||||
private final String USUARIO="root";
|
private final String USUARIO="root";
|
||||||
private final String CONTRASENA="tdPXEKculfAIumCBQirpMvZYXnrOuCbZ";
|
private final String CONTRASENA="ECGtugnerOnWGDCdGXSlqeNQSUGEJfhk";
|
||||||
|
|
||||||
public Connection obtenerConexion() throws SQLException{
|
public Connection obtenerConexion() throws SQLException{
|
||||||
conecta();
|
conecta();
|
||||||
|
|
|
@ -10,7 +10,7 @@ import java.util.List;
|
||||||
|
|
||||||
public class DaoPaciente implements IDaoPaciente{
|
public class DaoPaciente implements IDaoPaciente{
|
||||||
|
|
||||||
private final Conexion con = new Conexion();
|
private static Conexion con = new Conexion();
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
private PreparedStatement ps;
|
private PreparedStatement ps;
|
||||||
private ResultSet rs;
|
private ResultSet rs;
|
||||||
|
@ -109,4 +109,25 @@ public class DaoPaciente implements IDaoPaciente{
|
||||||
return pacientes;
|
return pacientes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Paciente datosPaciente(String correoUsuario) throws SQLException {
|
||||||
|
Connection conn = con.obtenerConexion();
|
||||||
|
Paciente paciente = null;
|
||||||
|
try {
|
||||||
|
Statement st = conn.createStatement();
|
||||||
|
ResultSet rs = st.executeQuery("SELECT nombre , edad , peso, contacto, idPac FROM Paciente INNER JOIN Usuario ON Paciente.idPac = Usuario.idUsuario WHERE correo='" + correoUsuario + "'");
|
||||||
|
while (rs.next()) {
|
||||||
|
paciente = new Paciente(rs.getString("nombre"), rs.getInt("edad"),rs.getFloat("peso"),rs.getString("contacto"),rs.getInt("idPac"));
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.out.println("Error al obtener datos del usuario: " + ex.toString());
|
||||||
|
}finally {
|
||||||
|
try {
|
||||||
|
conn.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return paciente;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DaoUsuario implements IDaoUsuario{
|
public class DaoUsuario implements IDaoUsuario{
|
||||||
private final Conexion con = new Conexion();
|
private static Conexion con = new Conexion();
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
private PreparedStatement ps;
|
private PreparedStatement ps;
|
||||||
private ResultSet rs;
|
private ResultSet rs;
|
||||||
|
@ -97,19 +97,73 @@ public class DaoUsuario implements IDaoUsuario{
|
||||||
return usuarios;
|
return usuarios;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean estaRegistrado(String correo, String contraseña) throws SQLException{
|
public static boolean estaRegistrado(String correo, String contraseña) throws SQLException{
|
||||||
boolean respuesta = false;
|
boolean respuesta = false;
|
||||||
String consulta = "SELECT * FROM Usuario WHERE correo = ? AND contrasena = ? ;";
|
Connection conn = con.obtenerConexion();
|
||||||
connection = con.obtenerConexion();
|
try {
|
||||||
ps = connection.prepareStatement(consulta);
|
Statement st = conn.createStatement();
|
||||||
ps.setString(1, correo);
|
ResultSet rs = st.executeQuery("SELECT correo, contrasena, esMedico FROM Usuario WHERE correo='" + correo + "' AND contrasena='" + contraseña + "';");
|
||||||
ps.setString(2, contraseña);
|
//ResultSet rs = st.executeQuery("SELECT correo FROM usuario WHERE correo='" + correo + "';");
|
||||||
rs = ps.executeQuery();
|
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
respuesta = true;
|
respuesta = true;
|
||||||
}
|
}
|
||||||
connection.close();
|
} catch (Exception ex) {
|
||||||
|
System.out.println("Error al iniciar sesion: " + ex.toString());
|
||||||
|
}finally {
|
||||||
|
try {
|
||||||
|
conn.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
return respuesta;
|
return respuesta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean esMedico(String correo, String contraseña) throws SQLException{
|
||||||
|
boolean respuesta = false;
|
||||||
|
Connection conn = con.obtenerConexion();
|
||||||
|
try {
|
||||||
|
Statement st = conn.createStatement();
|
||||||
|
ResultSet rs = st.executeQuery("SELECT esMedico FROM Usuario WHERE correo='" + correo + "' AND contrasena='" + contraseña + "'AND esMedico='1';");
|
||||||
|
//ResultSet rs = st.executeQuery("SELECT correo FROM usuario WHERE correo='" + correo + "';");
|
||||||
|
if (rs.next()) {
|
||||||
|
respuesta = true;
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.out.println("Error al iniciar sesion: " + ex.toString());
|
||||||
|
}finally {
|
||||||
|
try {
|
||||||
|
conn.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return respuesta;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static List<Receta> dameMiReceta(String nombreUsuario) throws SQLException{
|
||||||
|
Connection conn = con.obtenerConexion();
|
||||||
|
ArrayList<Receta> recetas = new ArrayList<>();
|
||||||
|
try{
|
||||||
|
Statement st = conn.createStatement();
|
||||||
|
ResultSet rs = st.executeQuery("SELECT idRec, nombreMed, firmaMed, contactoMed, pesoPac, edadPac, fecha, presArt, tempPac FROM Receta WHERE fk_idPac = '" + nombreUsuario + "';");
|
||||||
|
while (rs.next()){
|
||||||
|
Receta receta = new Receta(rs.getInt("idRec"), rs.getString("nombreMed"),
|
||||||
|
rs.getBlob("firmaMed"), rs.getString("contactoMed"),rs.getFloat("pesoPac"),
|
||||||
|
rs.getInt("edadPac"),rs.getDate("fecha"),rs.getString("presArt"),rs.getFloat("tempPac"));
|
||||||
|
recetas.add(receta);
|
||||||
|
}
|
||||||
|
} catch (SQLException e){
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}finally {
|
||||||
|
try {
|
||||||
|
conn.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return recetas;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ public class Receta {
|
||||||
private float pesoPac;
|
private float pesoPac;
|
||||||
private int edadPac;
|
private int edadPac;
|
||||||
private Date fecha;
|
private Date fecha;
|
||||||
private float presArt;
|
private String presArt;
|
||||||
private float tempPac;
|
private float tempPac;
|
||||||
private int idPaciente;
|
private int idPaciente;
|
||||||
private int idMedico;
|
private int idMedico;
|
||||||
|
@ -23,7 +23,7 @@ public class Receta {
|
||||||
|
|
||||||
|
|
||||||
public Receta(String nombreMed, Blob firmaMed, String contactoMed, float pesoPac, int edadPac, Date fecha,
|
public Receta(String nombreMed, Blob firmaMed, String contactoMed, float pesoPac, int edadPac, Date fecha,
|
||||||
float presArt, float tempPac) {
|
String presArt, float tempPac) {
|
||||||
this.nombreMed = nombreMed;
|
this.nombreMed = nombreMed;
|
||||||
this.firmaMed = firmaMed;
|
this.firmaMed = firmaMed;
|
||||||
this.contactoMed = contactoMed;
|
this.contactoMed = contactoMed;
|
||||||
|
@ -37,7 +37,7 @@ public class Receta {
|
||||||
|
|
||||||
|
|
||||||
public Receta(int idRec, String nombreMed, Blob firmaMed, String contactoMed, float pesoPac, int edadPac,
|
public Receta(int idRec, String nombreMed, Blob firmaMed, String contactoMed, float pesoPac, int edadPac,
|
||||||
Date fecha, float presArt, float tempPac) {
|
Date fecha, String presArt, float tempPac) {
|
||||||
this.idRec = idRec;
|
this.idRec = idRec;
|
||||||
this.nombreMed = nombreMed;
|
this.nombreMed = nombreMed;
|
||||||
this.firmaMed = firmaMed;
|
this.firmaMed = firmaMed;
|
||||||
|
@ -52,7 +52,7 @@ public class Receta {
|
||||||
|
|
||||||
|
|
||||||
public Receta(String nombreMed, Blob firmaMed, String contactoMed, float pesoPac, int edadPac, Date fecha,
|
public Receta(String nombreMed, Blob firmaMed, String contactoMed, float pesoPac, int edadPac, Date fecha,
|
||||||
float presArt, float tempPac, int idPaciente, int idMedico) {
|
String presArt, float tempPac, int idPaciente, int idMedico) {
|
||||||
this.nombreMed = nombreMed;
|
this.nombreMed = nombreMed;
|
||||||
this.firmaMed = firmaMed;
|
this.firmaMed = firmaMed;
|
||||||
this.contactoMed = contactoMed;
|
this.contactoMed = contactoMed;
|
||||||
|
@ -68,7 +68,7 @@ public class Receta {
|
||||||
|
|
||||||
|
|
||||||
public Receta(int idRec, String nombreMed, Blob firmaMed, String contactoMed, float pesoPac, int edadPac,
|
public Receta(int idRec, String nombreMed, Blob firmaMed, String contactoMed, float pesoPac, int edadPac,
|
||||||
Date fecha, float presArt, float tempPac, int idPaciente, int idMedico) {
|
Date fecha, String presArt, float tempPac, int idPaciente, int idMedico) {
|
||||||
this.idRec = idRec;
|
this.idRec = idRec;
|
||||||
this.nombreMed = nombreMed;
|
this.nombreMed = nombreMed;
|
||||||
this.firmaMed = firmaMed;
|
this.firmaMed = firmaMed;
|
||||||
|
@ -140,11 +140,11 @@ public class Receta {
|
||||||
this.fecha = fecha;
|
this.fecha = fecha;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getPresArt() {
|
public String getPresArt() {
|
||||||
return presArt;
|
return presArt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPresArt(float presArt) {
|
public void setPresArt(String presArt) {
|
||||||
this.presArt = presArt;
|
this.presArt = presArt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,18 @@
|
||||||
|
C:\Users\Roberto\Documents\healthmanager_back\mezontleTeam-ProyectoBackend\healthmanager_back\src\main\java\mx\uv\IDaoUsuario.java
|
||||||
|
C:\Users\Roberto\Documents\healthmanager_back\mezontleTeam-ProyectoBackend\healthmanager_back\src\main\java\mx\uv\Historial.java
|
||||||
|
C:\Users\Roberto\Documents\healthmanager_back\mezontleTeam-ProyectoBackend\healthmanager_back\src\main\java\mx\uv\DAO.java
|
||||||
|
C:\Users\Roberto\Documents\healthmanager_back\mezontleTeam-ProyectoBackend\healthmanager_back\src\main\java\mx\uv\IDaoPaciente.java
|
||||||
|
C:\Users\Roberto\Documents\healthmanager_back\mezontleTeam-ProyectoBackend\healthmanager_back\src\main\java\mx\uv\DaoPaciente.java
|
||||||
|
C:\Users\Roberto\Documents\healthmanager_back\mezontleTeam-ProyectoBackend\healthmanager_back\src\main\java\mx\uv\IDaoReceta.java
|
||||||
|
C:\Users\Roberto\Documents\healthmanager_back\mezontleTeam-ProyectoBackend\healthmanager_back\src\main\java\mx\uv\DaoUsuario.java
|
||||||
|
C:\Users\Roberto\Documents\healthmanager_back\mezontleTeam-ProyectoBackend\healthmanager_back\src\main\java\mx\uv\Medico.java
|
||||||
|
C:\Users\Roberto\Documents\healthmanager_back\mezontleTeam-ProyectoBackend\healthmanager_back\src\main\java\mx\uv\IDaoMedico.java
|
||||||
|
C:\Users\Roberto\Documents\healthmanager_back\mezontleTeam-ProyectoBackend\healthmanager_back\src\main\java\mx\uv\App.java
|
||||||
|
C:\Users\Roberto\Documents\healthmanager_back\mezontleTeam-ProyectoBackend\healthmanager_back\src\main\java\mx\uv\Receta.java
|
||||||
|
C:\Users\Roberto\Documents\healthmanager_back\mezontleTeam-ProyectoBackend\healthmanager_back\src\main\java\mx\uv\DaoReceta.java
|
||||||
|
C:\Users\Roberto\Documents\healthmanager_back\mezontleTeam-ProyectoBackend\healthmanager_back\src\main\java\mx\uv\IDaoHistorial.java
|
||||||
|
C:\Users\Roberto\Documents\healthmanager_back\mezontleTeam-ProyectoBackend\healthmanager_back\src\main\java\mx\uv\Paciente.java
|
||||||
|
C:\Users\Roberto\Documents\healthmanager_back\mezontleTeam-ProyectoBackend\healthmanager_back\src\main\java\mx\uv\DaoHistorial.java
|
||||||
|
C:\Users\Roberto\Documents\healthmanager_back\mezontleTeam-ProyectoBackend\healthmanager_back\src\main\java\mx\uv\Conexion.java
|
||||||
|
C:\Users\Roberto\Documents\healthmanager_back\mezontleTeam-ProyectoBackend\healthmanager_back\src\main\java\mx\uv\DaoMedico.java
|
||||||
|
C:\Users\Roberto\Documents\healthmanager_back\mezontleTeam-ProyectoBackend\healthmanager_back\src\main\java\mx\uv\Usuario.java
|
Binary file not shown.
Loading…
Reference in New Issue