├── cron ├── actualizar_tokens.php └── registros │ └── registros.txt ├── clases ├── conexion │ ├── config │ └── conexion.php ├── token.class.php ├── respuestas.class.php ├── auth.class.php └── pacientes.class.php ├── .htaccess ├── auth.php ├── assets └── estilo.css ├── index.php ├── pacientes.php └── database └── apirest.sql /cron/actualizar_tokens.php: -------------------------------------------------------------------------------- 1 | actualizarTokens($fecha); 6 | ?> -------------------------------------------------------------------------------- /clases/conexion/config: -------------------------------------------------------------------------------- 1 | { 2 | "conexion":{ 3 | "server" : "localhost", 4 | "user" : "root", 5 | "password" : "", 6 | "database" : "apirest", 7 | "port": "3306" 8 | } 9 | } -------------------------------------------------------------------------------- /cron/registros/registros.txt: -------------------------------------------------------------------------------- 1 | ------------------------------------ Registros del CRON JOB ------------------------------------ 2 | Se modificaron -1 el dia [2020-10-18 16:36] 3 | Se modificaron 3 el dia [2020-10-18 16:39] 4 | Se modificaron 2 el dia [2020-10-18 16:41] 5 | -------------------------------------------------------------------------------- /.htaccess: -------------------------------------------------------------------------------- 1 | 2 | RewriteEngine On 3 | 4 | # esta lineas son para quitar la ext .php 5 | RewriteCond %{REQUEST_FILENAME} !-d 6 | RewriteCond %{REQUEST_FILENAME}.php -f 7 | RewriteRule ^(.*)$ $1.php 8 | 9 | # esta lineas son para quitar la ext .html 10 | RewriteCond %{REQUEST_FILENAME} !-d 11 | RewriteCond %{REQUEST_FILENAME}.html -f 12 | RewriteRule ^(.*)$ $1.html 13 | 14 | 15 | # Si la ruta no es un archivo existente, ni una carpeta 16 | # Reescribir al index 17 | RewriteCond %{REQUEST_FILENAME} !-f 18 | RewriteCond %{REQUEST_FILENAME} !-d 19 | RewriteRule ^(.+?)/?$ index.php?url=$1 [L,QSA] -------------------------------------------------------------------------------- /auth.php: -------------------------------------------------------------------------------- 1 | login($postBody); 17 | 18 | //delvolvemos una respuesta 19 | header('Content-Type: application/json'); 20 | if(isset($datosArray["result"]["error_id"])){ 21 | $responseCode = $datosArray["result"]["error_id"]; 22 | http_response_code($responseCode); 23 | }else{ 24 | http_response_code(200); 25 | } 26 | echo json_encode($datosArray); 27 | 28 | 29 | }else{ 30 | header('Content-Type: application/json'); 31 | $datosArray = $_respuestas->error_405(); 32 | echo json_encode($datosArray); 33 | 34 | } 35 | 36 | 37 | ?> -------------------------------------------------------------------------------- /assets/estilo.css: -------------------------------------------------------------------------------- 1 | body{ 2 | color:black; 3 | } 4 | 5 | 6 | 7 | .container { 8 | margin: 10px; 9 | border: 1px solid #D0D0D0; 10 | box-shadow: 0 0 8px #D0D0D0; 11 | } 12 | h1{ 13 | color: #444; 14 | background-color: transparent; 15 | border-bottom: 1px solid #D0D0D0; 16 | font-size: 24px; 17 | font-weight: normal; 18 | margin: 0 0 14px 0; 19 | padding: 14px 15px 10px 15px; 20 | } 21 | 22 | h2 { 23 | display: block; 24 | font-size: 1.5em; 25 | -webkit-margin-before: 0.83em; 26 | -webkit-margin-after: 0.83em; 27 | -webkit-margin-start: 0px; 28 | -webkit-margin-end: 0px; 29 | font-weight: bold; 30 | } 31 | 32 | p { 33 | display: block; 34 | -webkit-margin-before: 1em; 35 | -webkit-margin-after: 1em; 36 | -webkit-margin-start: 0px; 37 | -webkit-margin-end: 0px; 38 | } 39 | 40 | 41 | .divbody{ 42 | margin: 0 15px 0 15px; 43 | } 44 | 45 | p.divfooter { 46 | text-align: right; 47 | font-size: 16px; 48 | border-top: 1px solid #D0D0D0; 49 | line-height: 32px; 50 | padding: 0 10px 0 10px; 51 | margin: 20px 0 0 0; 52 | } 53 | 54 | code { 55 | font-family: Consolas, Monaco, Courier New, Courier, monospace; 56 | font-size: 16px; 57 | background-color: #f9f9f9; 58 | border: 1px solid #D0D0D0; 59 | color: #002166; 60 | display: block; 61 | margin: 14px 0 14px 0; 62 | padding: 12px 10px 12px 10px; 63 | } -------------------------------------------------------------------------------- /clases/token.class.php: -------------------------------------------------------------------------------- 1 | escribirEntrada($verifica); 11 | return $verifica; 12 | }else{ 13 | return 0; 14 | } 15 | } 16 | 17 | function crearTxt($direccion){ 18 | $archivo = fopen($direccion, 'w') or die ("error al crear el archivo de registros"); 19 | $texto = "------------------------------------ Registros del CRON JOB ------------------------------------ \n"; 20 | fwrite($archivo,$texto) or die ("no pudimos escribir el registro"); 21 | fclose($archivo); 22 | } 23 | 24 | function escribirEntrada($registros){ 25 | $direccion = "../cron/registros/registros.txt"; 26 | if(!file_exists($direccion)){ 27 | $this->crearTxt($direccion); 28 | } 29 | /* crear una entrada nueva */ 30 | $this->escribirTxt($direccion, $registros); 31 | } 32 | 33 | function escribirTxt($direccion, $registros){ 34 | $date = date("Y-m-d H:i"); 35 | $archivo = fopen($direccion, 'a') or die ("error al abrir el archivo de registros"); 36 | $texto = "Se modificaron $registros registro(s) el dia [$date] \n"; 37 | fwrite($archivo,$texto) or die ("no pudimos escribir el registro"); 38 | fclose($archivo); 39 | } 40 | } 41 | 42 | ?> -------------------------------------------------------------------------------- /clases/respuestas.class.php: -------------------------------------------------------------------------------- 1 | "ok", 7 | "result" => array() 8 | ]; 9 | 10 | 11 | public function error_405(){ 12 | $this->response['status'] = "error"; 13 | $this->response['result'] = array( 14 | "error_id" => "405", 15 | "error_msg" => "Metodo no permitido" 16 | ); 17 | return $this->response; 18 | } 19 | 20 | public function error_200($valor = "Datos incorrectos"){ 21 | $this->response['status'] = "error"; 22 | $this->response['result'] = array( 23 | "error_id" => "200", 24 | "error_msg" => $valor 25 | ); 26 | return $this->response; 27 | } 28 | 29 | 30 | public function error_400(){ 31 | $this->response['status'] = "error"; 32 | $this->response['result'] = array( 33 | "error_id" => "400", 34 | "error_msg" => "Datos enviados incompletos o con formato incorrecto" 35 | ); 36 | return $this->response; 37 | } 38 | 39 | 40 | public function error_500($valor = "Error interno del servidor"){ 41 | $this->response['status'] = "error"; 42 | $this->response['result'] = array( 43 | "error_id" => "500", 44 | "error_msg" => $valor 45 | ); 46 | return $this->response; 47 | } 48 | 49 | 50 | public function error_401($valor = "No autorizado"){ 51 | $this->response['status'] = "error"; 52 | $this->response['result'] = array( 53 | "error_id" => "401", 54 | "error_msg" => $valor 55 | ); 56 | return $this->response; 57 | } 58 | 59 | 60 | 61 | } 62 | 63 | ?> -------------------------------------------------------------------------------- /clases/conexion/conexion.php: -------------------------------------------------------------------------------- 1 | datosConexion(); 17 | foreach ($listadatos as $key => $value) { 18 | $this->server = $value['server']; 19 | $this->user = $value['user']; 20 | $this->password = $value['password']; 21 | $this->database = $value['database']; 22 | $this->port = $value['port']; 23 | } 24 | $this->conexion = new mysqli($this->server,$this->user,$this->password,$this->database,$this->port); 25 | if($this->conexion->connect_errno){ 26 | echo "algo va mal con la conexion"; 27 | die(); 28 | } 29 | 30 | } 31 | 32 | private function datosConexion(){ 33 | $direccion = dirname(__FILE__); 34 | $jsondata = file_get_contents($direccion . "/" . "config"); 35 | return json_decode($jsondata, true); 36 | } 37 | 38 | 39 | private function convertirUTF8($array){ 40 | array_walk_recursive($array,function(&$item,$key){ 41 | if(!mb_detect_encoding($item,'utf-8',true)){ 42 | $item = utf8_encode($item); 43 | } 44 | }); 45 | return $array; 46 | } 47 | 48 | 49 | public function obtenerDatos($sqlstr){ 50 | $results = $this->conexion->query($sqlstr); 51 | $resultArray = array(); 52 | foreach ($results as $key) { 53 | $resultArray[] = $key; 54 | } 55 | return $this->convertirUTF8($resultArray); 56 | 57 | } 58 | 59 | 60 | 61 | public function nonQuery($sqlstr){ 62 | $results = $this->conexion->query($sqlstr); 63 | return $this->conexion->affected_rows; 64 | } 65 | 66 | 67 | //INSERT 68 | public function nonQueryId($sqlstr){ 69 | $results = $this->conexion->query($sqlstr); 70 | $filas = $this->conexion->affected_rows; 71 | if($filas >= 1){ 72 | return $this->conexion->insert_id; 73 | }else{ 74 | return 0; 75 | } 76 | } 77 | 78 | //encriptar 79 | 80 | protected function encriptar($string){ 81 | return md5($string); 82 | } 83 | 84 | 85 | 86 | 87 | 88 | } 89 | 90 | 91 | 92 | ?> -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | API - Prubebas 7 | 8 | 9 | 10 | 11 |
12 |

Api de pruebas

13 |
14 |

Auth - login

15 | 16 | POST /auth 17 |
18 | { 19 |
20 | "usuario" :"", -> REQUERIDO 21 |
22 | "password": "" -> REQUERIDO 23 |
24 | } 25 | 26 |
27 |
28 |
29 |

Pacientes

30 | 31 | GET /pacientes?page=$numeroPagina 32 |
33 | GET /pacientes?id=$idPaciente 34 |
35 | 36 | 37 | POST /pacientes 38 |
39 | { 40 |
41 | "nombre" : "", -> REQUERIDO 42 |
43 | "dni" : "", -> REQUERIDO 44 |
45 | "correo":"", -> REQUERIDO 46 |
47 | "codigoPostal" :"", 48 |
49 | "genero" : "", 50 |
51 | "telefono" : "", 52 |
53 | "fechaNacimiento" : "", 54 |
55 | "token" : "" -> REQUERIDO 56 |
57 | } 58 | 59 |
60 | 61 | PUT /pacientes 62 |
63 | { 64 |
65 | "nombre" : "", 66 |
67 | "dni" : "", 68 |
69 | "correo":"", 70 |
71 | "codigoPostal" :"", 72 |
73 | "genero" : "", 74 |
75 | "telefono" : "", 76 |
77 | "fechaNacimiento" : "", 78 |
79 | "token" : "" , -> REQUERIDO 80 |
81 | "pacienteId" : "" -> REQUERIDO 82 |
83 | } 84 | 85 |
86 | 87 | DELETE /pacientes 88 |
89 | { 90 |
91 | "token" : "", -> REQUERIDO 92 |
93 | "pacienteId" : "" -> REQUERIDO 94 |
95 | } 96 | 97 |
98 |
99 | 100 | 101 |
102 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /pacientes.php: -------------------------------------------------------------------------------- 1 | listaPacientes($pagina); 14 | header("Content-Type: application/json"); 15 | echo json_encode($listaPacientes); 16 | http_response_code(200); 17 | }else if(isset($_GET['id'])){ 18 | $pacienteid = $_GET['id']; 19 | $datosPaciente = $_pacientes->obtenerPaciente($pacienteid); 20 | header("Content-Type: application/json"); 21 | echo json_encode($datosPaciente); 22 | http_response_code(200); 23 | } 24 | 25 | }else if($_SERVER['REQUEST_METHOD'] == "POST"){ 26 | //recibimos los datos enviados 27 | $postBody = file_get_contents("php://input"); 28 | //enviamos los datos al manejador 29 | $datosArray = $_pacientes->post($postBody); 30 | //delvovemos una respuesta 31 | header('Content-Type: application/json'); 32 | if(isset($datosArray["result"]["error_id"])){ 33 | $responseCode = $datosArray["result"]["error_id"]; 34 | http_response_code($responseCode); 35 | }else{ 36 | http_response_code(200); 37 | } 38 | echo json_encode($datosArray); 39 | 40 | }else if($_SERVER['REQUEST_METHOD'] == "PUT"){ 41 | //recibimos los datos enviados 42 | $postBody = file_get_contents("php://input"); 43 | //enviamos datos al manejador 44 | $datosArray = $_pacientes->put($postBody); 45 | //delvovemos una respuesta 46 | header('Content-Type: application/json'); 47 | if(isset($datosArray["result"]["error_id"])){ 48 | $responseCode = $datosArray["result"]["error_id"]; 49 | http_response_code($responseCode); 50 | }else{ 51 | http_response_code(200); 52 | } 53 | echo json_encode($datosArray); 54 | 55 | }else if($_SERVER['REQUEST_METHOD'] == "DELETE"){ 56 | 57 | $headers = getallheaders(); 58 | if(isset($headers["token"]) && isset($headers["pacienteId"])){ 59 | //recibimos los datos enviados por el header 60 | $send = [ 61 | "token" => $headers["token"], 62 | "pacienteId" =>$headers["pacienteId"] 63 | ]; 64 | $postBody = json_encode($send); 65 | }else{ 66 | //recibimos los datos enviados 67 | $postBody = file_get_contents("php://input"); 68 | } 69 | 70 | //enviamos datos al manejador 71 | $datosArray = $_pacientes->delete($postBody); 72 | //delvovemos una respuesta 73 | header('Content-Type: application/json'); 74 | if(isset($datosArray["result"]["error_id"])){ 75 | $responseCode = $datosArray["result"]["error_id"]; 76 | http_response_code($responseCode); 77 | }else{ 78 | http_response_code(200); 79 | } 80 | echo json_encode($datosArray); 81 | 82 | 83 | }else{ 84 | header('Content-Type: application/json'); 85 | $datosArray = $_respuestas->error_405(); 86 | echo json_encode($datosArray); 87 | } 88 | 89 | 90 | ?> -------------------------------------------------------------------------------- /clases/auth.class.php: -------------------------------------------------------------------------------- 1 | error_400(); 15 | }else{ 16 | //todo esta bien 17 | $usuario = $datos['usuario']; 18 | $password = $datos['password']; 19 | $password = parent::encriptar($password); 20 | $datos = $this->obtenerDatosUsuario($usuario); 21 | if($datos){ 22 | //verificar si la contraseña es igual 23 | if($password == $datos[0]['Password']){ 24 | if($datos[0]['Estado'] == "Activo"){ 25 | //crear el token 26 | $verificar = $this->insertarToken($datos[0]['UsuarioId']); 27 | if($verificar){ 28 | // si se guardo 29 | $result = $_respustas->response; 30 | $result["result"] = array( 31 | "token" => $verificar 32 | ); 33 | return $result; 34 | }else{ 35 | //error al guardar 36 | return $_respustas->error_500("Error interno, No hemos podido guardar"); 37 | } 38 | }else{ 39 | //el usuario esta inactivo 40 | return $_respustas->error_200("El usuario esta inactivo"); 41 | } 42 | }else{ 43 | //la contraseña no es igual 44 | return $_respustas->error_200("El password es invalido"); 45 | } 46 | }else{ 47 | //no existe el usuario 48 | return $_respustas->error_200("El usuaro $usuario no existe "); 49 | } 50 | } 51 | } 52 | 53 | 54 | 55 | private function obtenerDatosUsuario($correo){ 56 | $query = "SELECT UsuarioId,Password,Estado FROM usuarios WHERE Usuario = '$correo'"; 57 | $datos = parent::obtenerDatos($query); 58 | if(isset($datos[0]["UsuarioId"])){ 59 | return $datos; 60 | }else{ 61 | return 0; 62 | } 63 | } 64 | 65 | 66 | private function insertarToken($usuarioid){ 67 | $val = true; 68 | $token = bin2hex(openssl_random_pseudo_bytes(16,$val)); 69 | $date = date("Y-m-d H:i"); 70 | $estado = "Activo"; 71 | $query = "INSERT INTO usuarios_token (UsuarioId,Token,Estado,Fecha)VALUES('$usuarioid','$token','$estado','$date')"; 72 | $verifica = parent::nonQuery($query); 73 | if($verifica){ 74 | return $token; 75 | }else{ 76 | return 0; 77 | } 78 | } 79 | 80 | 81 | } 82 | 83 | 84 | 85 | 86 | ?> -------------------------------------------------------------------------------- /database/apirest.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 5.0.1 3 | -- https://www.phpmyadmin.net/ 4 | -- 5 | -- Servidor: 127.0.0.1 6 | -- Tiempo de generación: 07-08-2020 a las 15:36:00 7 | -- Versión del servidor: 10.4.11-MariaDB 8 | -- Versión de PHP: 7.2.28 9 | 10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 11 | SET AUTOCOMMIT = 0; 12 | START TRANSACTION; 13 | SET time_zone = "+00:00"; 14 | 15 | 16 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 17 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 18 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 19 | /*!40101 SET NAMES utf8mb4 */; 20 | 21 | -- 22 | -- Base de datos: `apirest` 23 | -- 24 | 25 | -- -------------------------------------------------------- 26 | 27 | -- 28 | -- Estructura de tabla para la tabla `citas` 29 | -- 30 | 31 | CREATE TABLE `citas` ( 32 | `CitaId` int(11) NOT NULL, 33 | `PacienteId` varchar(45) DEFAULT NULL, 34 | `Fecha` varchar(45) DEFAULT NULL, 35 | `HoraInicio` varchar(45) DEFAULT NULL, 36 | `HoraFIn` varchar(45) DEFAULT NULL, 37 | `Estado` varchar(45) DEFAULT NULL, 38 | `Motivo` varchar(45) DEFAULT NULL 39 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 40 | 41 | -- 42 | -- Volcado de datos para la tabla `citas` 43 | -- 44 | 45 | INSERT INTO `citas` (`CitaId`, `PacienteId`, `Fecha`, `HoraInicio`, `HoraFIn`, `Estado`, `Motivo`) VALUES 46 | (1, '1', '2020-06-09', '08:30:00', '09:00:00', 'Confirmada', 'El paciente presenta un leve dolor de espalda'), 47 | (2, '2', '2020-06-10', '08:30:00', '09:00:00', 'Confirmada', 'Dolor en la zona lumbar '), 48 | (3, '3', '2020-06-18', '09:00:00', '09:30:00', 'Confirmada', 'Dolor en el cuello'); 49 | 50 | -- -------------------------------------------------------- 51 | 52 | -- 53 | -- Estructura de tabla para la tabla `pacientes` 54 | -- 55 | 56 | CREATE TABLE `pacientes` ( 57 | `PacienteId` int(11) NOT NULL, 58 | `DNI` varchar(45) DEFAULT NULL, 59 | `Nombre` varchar(150) DEFAULT NULL, 60 | `Direccion` varchar(45) DEFAULT NULL, 61 | `CodigoPostal` varchar(45) DEFAULT NULL, 62 | `Telefono` varchar(45) DEFAULT NULL, 63 | `Genero` varchar(45) DEFAULT NULL, 64 | `FechaNacimiento` date DEFAULT NULL, 65 | `Correo` varchar(45) DEFAULT NULL 66 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 67 | 68 | -- 69 | -- Volcado de datos para la tabla `pacientes` 70 | -- 71 | 72 | INSERT INTO `pacientes` (`PacienteId`, `DNI`, `Nombre`, `Direccion`, `CodigoPostal`, `Telefono`, `Genero`, `FechaNacimiento`, `Correo`) VALUES 73 | (1, 'A000000001', 'Juan Carlos Medina', 'Calle de pruebas 1', '20001', '633281515', 'M', '1989-03-02', 'Paciente1@gmail.com'), 74 | (2, 'B000000002', 'Daniel Rios', 'Calle de pruebas 2', '20002', '633281512', 'M', '1990-05-11', 'Paciente2@gmail.com'), 75 | (3, 'C000000003', 'Marcela Dubon', 'Calle de pruebas 3', '20003', '633281511', 'F', '2000-07-22', 'Paciente3@gmail.com'), 76 | (4, 'D000000004', 'Maria Mendez', 'Calle de pruebas 4', '20004', '633281516', 'F', '1980-01-01', 'Paciente4@gmail.com'), 77 | (5, 'E000000005', 'Zamuel Valladares', 'Calle de pruebas 5', '20006', '633281519', 'M', '1985-12-15', 'Paciente5@gmail.com'), 78 | (6, 'F000000006', 'Angel Rios', 'Calle de pruebas 6', '20005', '633281510', 'M', '1988-11-30', 'Paciente6@gmail.com'); 79 | 80 | -- -------------------------------------------------------- 81 | 82 | -- 83 | -- Estructura de tabla para la tabla `usuarios` 84 | -- 85 | 86 | CREATE TABLE `usuarios` ( 87 | `UsuarioId` int(11) NOT NULL, 88 | `Usuario` varchar(45) DEFAULT NULL, 89 | `Password` varchar(45) DEFAULT NULL, 90 | `Estado` varchar(45) DEFAULT NULL 91 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 92 | 93 | -- 94 | -- Volcado de datos para la tabla `usuarios` 95 | -- 96 | 97 | INSERT INTO `usuarios` (`UsuarioId`, `Usuario`, `Password`, `Estado`) VALUES 98 | (1, 'usuario1@gmail.com', 'e10adc3949ba59abbe56e057f20f883e', 'Activo'), 99 | (2, 'usuario2@gmail.com', 'e10adc3949ba59abbe56e057f20f883e', 'Activo'), 100 | (3, 'usuario3@gmail.com', 'e10adc3949ba59abbe56e057f20f883e', 'Activo'), 101 | (4, 'usuario4@gmail.com', 'e10adc3949ba59abbe56e057f20f883e', 'Activo'), 102 | (5, 'usuario5@gmail.com', 'e10adc3949ba59abbe56e057f20f883e', 'Activo'), 103 | (6, 'usuario6@gmail.com', 'e10adc3949ba59abbe56e057f20f883e', 'Activo'), 104 | (7, 'usuario7@gmail.com', 'e10adc3949ba59abbe56e057f20f883e', 'Inactivo'), 105 | (8, 'usuario8@gmail.com', 'e10adc3949ba59abbe56e057f20f883e', 'Inactivo'), 106 | (9, 'usuario9@gmail.com', 'e10adc3949ba59abbe56e057f20f883e', 'Inactivo'); 107 | 108 | -- -------------------------------------------------------- 109 | 110 | -- 111 | -- Estructura de tabla para la tabla `usuarios_token` 112 | -- 113 | 114 | CREATE TABLE `usuarios_token` ( 115 | `TokenId` int(11) NOT NULL, 116 | `UsuarioId` varchar(45) DEFAULT NULL, 117 | `Token` varchar(45) DEFAULT NULL, 118 | `Estado` varchar(45) CHARACTER SET armscii8 DEFAULT NULL, 119 | `Fecha` datetime DEFAULT NULL 120 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 121 | 122 | -- 123 | -- Índices para tablas volcadas 124 | -- 125 | 126 | -- 127 | -- Indices de la tabla `citas` 128 | -- 129 | ALTER TABLE `citas` 130 | ADD PRIMARY KEY (`CitaId`); 131 | 132 | -- 133 | -- Indices de la tabla `pacientes` 134 | -- 135 | ALTER TABLE `pacientes` 136 | ADD PRIMARY KEY (`PacienteId`); 137 | 138 | -- 139 | -- Indices de la tabla `usuarios` 140 | -- 141 | ALTER TABLE `usuarios` 142 | ADD PRIMARY KEY (`UsuarioId`); 143 | 144 | -- 145 | -- Indices de la tabla `usuarios_token` 146 | -- 147 | ALTER TABLE `usuarios_token` 148 | ADD PRIMARY KEY (`TokenId`); 149 | 150 | -- 151 | -- AUTO_INCREMENT de las tablas volcadas 152 | -- 153 | 154 | -- 155 | -- AUTO_INCREMENT de la tabla `citas` 156 | -- 157 | ALTER TABLE `citas` 158 | MODIFY `CitaId` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4; 159 | 160 | -- 161 | -- AUTO_INCREMENT de la tabla `pacientes` 162 | -- 163 | ALTER TABLE `pacientes` 164 | MODIFY `PacienteId` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7; 165 | 166 | -- 167 | -- AUTO_INCREMENT de la tabla `usuarios` 168 | -- 169 | ALTER TABLE `usuarios` 170 | MODIFY `UsuarioId` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10; 171 | 172 | -- 173 | -- AUTO_INCREMENT de la tabla `usuarios_token` 174 | -- 175 | ALTER TABLE `usuarios_token` 176 | MODIFY `TokenId` int(11) NOT NULL AUTO_INCREMENT; 177 | COMMIT; 178 | 179 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 180 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 181 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -------------------------------------------------------------------------------- /clases/pacientes.class.php: -------------------------------------------------------------------------------- 1 | 1){ 25 | $inicio = ($cantidad * ($pagina - 1)) +1 ; 26 | $cantidad = $cantidad * $pagina; 27 | } 28 | $query = "SELECT PacienteId,Nombre,DNI,Telefono,Correo FROM " . $this->table . " limit $inicio,$cantidad"; 29 | $datos = parent::obtenerDatos($query); 30 | return ($datos); 31 | } 32 | 33 | public function obtenerPaciente($id){ 34 | $query = "SELECT * FROM " . $this->table . " WHERE PacienteId = '$id'"; 35 | return parent::obtenerDatos($query); 36 | 37 | } 38 | 39 | public function post($json){ 40 | $_respuestas = new respuestas; 41 | $datos = json_decode($json,true); 42 | 43 | if(!isset($datos['token'])){ 44 | return $_respuestas->error_401(); 45 | }else{ 46 | $this->token = $datos['token']; 47 | $arrayToken = $this->buscarToken(); 48 | if($arrayToken){ 49 | 50 | if(!isset($datos['nombre']) || !isset($datos['dni']) || !isset($datos['correo'])){ 51 | return $_respuestas->error_400(); 52 | }else{ 53 | $this->nombre = $datos['nombre']; 54 | $this->dni = $datos['dni']; 55 | $this->correo = $datos['correo']; 56 | if(isset($datos['telefono'])) { $this->telefono = $datos['telefono']; } 57 | if(isset($datos['direccion'])) { $this->direccion = $datos['direccion']; } 58 | if(isset($datos['codigoPostal'])) { $this->codigoPostal = $datos['codigoPostal']; } 59 | if(isset($datos['genero'])) { $this->genero = $datos['genero']; } 60 | if(isset($datos['fechaNacimiento'])) { $this->fechaNacimiento = $datos['fechaNacimiento']; } 61 | $resp = $this->insertarPaciente(); 62 | if($resp){ 63 | $respuesta = $_respuestas->response; 64 | $respuesta["result"] = array( 65 | "pacienteId" => $resp 66 | ); 67 | return $respuesta; 68 | }else{ 69 | return $_respuestas->error_500(); 70 | } 71 | } 72 | 73 | }else{ 74 | return $_respuestas->error_401("El Token que envio es invalido o ha caducado"); 75 | } 76 | } 77 | 78 | 79 | 80 | 81 | } 82 | 83 | 84 | private function insertarPaciente(){ 85 | $query = "INSERT INTO " . $this->table . " (DNI,Nombre,Direccion,CodigoPostal,Telefono,Genero,FechaNacimiento,Correo) 86 | values 87 | ('" . $this->dni . "','" . $this->nombre . "','" . $this->direccion ."','" . $this->codigoPostal . "','" . $this->telefono . "','" . $this->genero . "','" . $this->fechaNacimiento . "','" . $this->correo . "')"; 88 | $resp = parent::nonQueryId($query); 89 | if($resp){ 90 | return $resp; 91 | }else{ 92 | return 0; 93 | } 94 | } 95 | 96 | public function put($json){ 97 | $_respuestas = new respuestas; 98 | $datos = json_decode($json,true); 99 | 100 | if(!isset($datos['token'])){ 101 | return $_respuestas->error_401(); 102 | }else{ 103 | $this->token = $datos['token']; 104 | $arrayToken = $this->buscarToken(); 105 | if($arrayToken){ 106 | if(!isset($datos['pacienteId'])){ 107 | return $_respuestas->error_400(); 108 | }else{ 109 | $this->pacienteid = $datos['pacienteId']; 110 | if(isset($datos['nombre'])) { $this->nombre = $datos['nombre']; } 111 | if(isset($datos['dni'])) { $this->dni = $datos['dni']; } 112 | if(isset($datos['correo'])) { $this->correo = $datos['correo']; } 113 | if(isset($datos['telefono'])) { $this->telefono = $datos['telefono']; } 114 | if(isset($datos['direccion'])) { $this->direccion = $datos['direccion']; } 115 | if(isset($datos['codigoPostal'])) { $this->codigoPostal = $datos['codigoPostal']; } 116 | if(isset($datos['genero'])) { $this->genero = $datos['genero']; } 117 | if(isset($datos['fechaNacimiento'])) { $this->fechaNacimiento = $datos['fechaNacimiento']; } 118 | 119 | $resp = $this->modificarPaciente(); 120 | if($resp){ 121 | $respuesta = $_respuestas->response; 122 | $respuesta["result"] = array( 123 | "pacienteId" => $this->pacienteid 124 | ); 125 | return $respuesta; 126 | }else{ 127 | return $_respuestas->error_500(); 128 | } 129 | } 130 | 131 | }else{ 132 | return $_respuestas->error_401("El Token que envio es invalido o ha caducado"); 133 | } 134 | } 135 | 136 | 137 | } 138 | 139 | 140 | private function modificarPaciente(){ 141 | $query = "UPDATE " . $this->table . " SET Nombre ='" . $this->nombre . "',Direccion = '" . $this->direccion . "', DNI = '" . $this->dni . "', CodigoPostal = '" . 142 | $this->codigoPostal . "', Telefono = '" . $this->telefono . "', Genero = '" . $this->genero . "', FechaNacimiento = '" . $this->fechaNacimiento . "', Correo = '" . $this->correo . 143 | "' WHERE PacienteId = '" . $this->pacienteid . "'"; 144 | $resp = parent::nonQuery($query); 145 | if($resp >= 1){ 146 | return $resp; 147 | }else{ 148 | return 0; 149 | } 150 | } 151 | 152 | 153 | public function delete($json){ 154 | $_respuestas = new respuestas; 155 | $datos = json_decode($json,true); 156 | 157 | if(!isset($datos['token'])){ 158 | return $_respuestas->error_401(); 159 | }else{ 160 | $this->token = $datos['token']; 161 | $arrayToken = $this->buscarToken(); 162 | if($arrayToken){ 163 | 164 | if(!isset($datos['pacienteId'])){ 165 | return $_respuestas->error_400(); 166 | }else{ 167 | $this->pacienteid = $datos['pacienteId']; 168 | $resp = $this->eliminarPaciente(); 169 | if($resp){ 170 | $respuesta = $_respuestas->response; 171 | $respuesta["result"] = array( 172 | "pacienteId" => $this->pacienteid 173 | ); 174 | return $respuesta; 175 | }else{ 176 | return $_respuestas->error_500(); 177 | } 178 | } 179 | 180 | }else{ 181 | return $_respuestas->error_401("El Token que envio es invalido o ha caducado"); 182 | } 183 | } 184 | 185 | 186 | 187 | 188 | } 189 | 190 | 191 | private function eliminarPaciente(){ 192 | $query = "DELETE FROM " . $this->table . " WHERE PacienteId= '" . $this->pacienteid . "'"; 193 | $resp = parent::nonQuery($query); 194 | if($resp >= 1 ){ 195 | return $resp; 196 | }else{ 197 | return 0; 198 | } 199 | } 200 | 201 | 202 | private function buscarToken(){ 203 | $query = "SELECT TokenId,UsuarioId,Estado from usuarios_token WHERE Token = '" . $this->token . "' AND Estado = 'Activo'"; 204 | $resp = parent::obtenerDatos($query); 205 | if($resp){ 206 | return $resp; 207 | }else{ 208 | return 0; 209 | } 210 | } 211 | 212 | 213 | private function actualizarToken($tokenid){ 214 | $date = date("Y-m-d H:i"); 215 | $query = "UPDATE usuarios_token SET Fecha = '$date' WHERE TokenId = '$tokenid' "; 216 | $resp = parent::nonQuery($query); 217 | if($resp >= 1){ 218 | return $resp; 219 | }else{ 220 | return 0; 221 | } 222 | } 223 | 224 | 225 | 226 | } 227 | 228 | 229 | 230 | 231 | 232 | ?> --------------------------------------------------------------------------------