2020-06-16 18:56:35 +02:00
|
|
|
CREATE DATABASE IF NOT EXISTS practica CHARACTER SET utf8mb4;
|
2020-05-13 00:44:10 +02:00
|
|
|
|
|
|
|
CREATE USER IF NOT EXISTS practica IDENTIFIED BY 'practica';
|
|
|
|
|
|
|
|
GRANT USAGE ON *.* TO practica@localhost IDENTIFIED BY 'practica';
|
|
|
|
|
|
|
|
GRANT ALL PRIVILEGES ON practica.* TO practica@localhost;
|
|
|
|
|
|
|
|
USE practica;
|
|
|
|
|
2020-06-17 22:02:27 +02:00
|
|
|
source database/provincias.sql;
|
|
|
|
|
|
|
|
source database/municipios.sql;
|
|
|
|
|
2020-05-13 00:44:10 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS paciente (
|
2020-06-17 08:42:53 +02:00
|
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
2020-05-13 00:44:10 +02:00
|
|
|
nombre VARCHAR(50) NOT NULL,
|
|
|
|
apellido VARCHAR(50) NOT NULL,
|
|
|
|
fecha_de_nacimiento DATE NOT NULL,
|
2020-06-17 08:42:53 +02:00
|
|
|
documento_identificativo VARCHAR(50) UNIQUE NOT NULL,
|
2020-05-13 00:44:10 +02:00
|
|
|
tipo_documento VARCHAR(10) NOT NULL,
|
2020-06-14 03:12:42 +02:00
|
|
|
direccion VARCHAR(255) NOT NULL,
|
2020-06-17 22:02:27 +02:00
|
|
|
localidad SMALLINT(6) UNSIGNED,
|
|
|
|
provincia SMALLINT(6),
|
|
|
|
pais VARCHAR(100) NOT NULL,
|
|
|
|
FOREIGN KEY (localidad)
|
|
|
|
REFERENCES municipios(id_municipio),
|
|
|
|
FOREIGN KEY (provincia)
|
|
|
|
REFERENCES provincias(id_provincia)
|
2020-05-13 00:44:10 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS rol(
|
|
|
|
codigo INT PRIMARY KEY,
|
|
|
|
nombre VARCHAR(25) NOT NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS usuario(
|
2020-06-17 04:10:09 +02:00
|
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
2020-05-13 00:44:10 +02:00
|
|
|
nombre VARCHAR(50) NOT NULL,
|
2020-06-17 04:10:09 +02:00
|
|
|
usuario VARCHAR(50) UNIQUE,
|
2020-05-13 00:44:10 +02:00
|
|
|
contraseña VARCHAR(100) NOT NULL,
|
|
|
|
rol INT NOT NULL,
|
|
|
|
especialidad VARCHAR(50),
|
2020-06-14 03:12:42 +02:00
|
|
|
correo VARCHAR(100) NOT NULL,
|
2020-06-14 04:25:11 +02:00
|
|
|
fecha_alta TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
2020-06-17 04:10:09 +02:00
|
|
|
fecha_baja TIMESTAMP NULL,
|
2020-05-13 00:44:10 +02:00
|
|
|
FOREIGN KEY (rol)
|
|
|
|
REFERENCES rol(codigo)
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2020-06-14 03:12:42 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS festivo (
|
|
|
|
id INT PRIMARY KEY AUTO_INCREMENT,
|
2020-05-13 00:44:10 +02:00
|
|
|
fecha_festivo DATE NOT NULL,
|
|
|
|
tipo_festivo VARCHAR(15) NOT NULL,
|
2020-06-18 09:04:44 +02:00
|
|
|
medico INT DEFAULT NULL,
|
2020-05-13 00:44:10 +02:00
|
|
|
FOREIGN KEY (medico)
|
2020-06-18 09:04:44 +02:00
|
|
|
REFERENCES usuario(id)
|
2020-05-13 00:44:10 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS calendario (
|
2020-06-17 08:42:53 +02:00
|
|
|
id INT AUTO_INCREMENT,
|
2020-05-13 00:44:10 +02:00
|
|
|
hora_inicio_mañana TIME,
|
|
|
|
hora_fin_mañana TIME,
|
|
|
|
hora_inicio_tarde TIME,
|
|
|
|
hora_fin_tarde TIME,
|
|
|
|
horario VARCHAR(15) NOT NULL,
|
|
|
|
sabado_habil BOOLEAN,
|
|
|
|
domingo_habil BOOLEAN,
|
|
|
|
duracion_cita_por_defecto INT,
|
2020-06-18 09:04:44 +02:00
|
|
|
medico INT,
|
2020-05-13 00:44:10 +02:00
|
|
|
PRIMARY KEY (id, medico),
|
|
|
|
FOREIGN KEY (medico)
|
2020-06-18 09:04:44 +02:00
|
|
|
REFERENCES usuario(id)
|
2020-05-13 00:44:10 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS cita(
|
2020-06-17 08:42:53 +02:00
|
|
|
id INT AUTO_INCREMENT,
|
2020-05-13 00:44:10 +02:00
|
|
|
fecha DATE NOT NULL,
|
|
|
|
hora TIME NOT NULL,
|
|
|
|
duracion INT,
|
2020-06-18 09:04:44 +02:00
|
|
|
medico INT NOT NULL,
|
2020-05-13 00:44:10 +02:00
|
|
|
observaciones VARCHAR(255),
|
2020-06-17 22:02:27 +02:00
|
|
|
paciente INT NOT NULL,
|
2020-05-13 00:44:10 +02:00
|
|
|
PRIMARY KEY (id, medico),
|
|
|
|
FOREIGN KEY (medico)
|
2020-06-18 09:04:44 +02:00
|
|
|
REFERENCES usuario(id),
|
2020-05-13 00:44:10 +02:00
|
|
|
FOREIGN KEY (paciente)
|
2020-06-17 08:42:53 +02:00
|
|
|
REFERENCES paciente(id)
|
2020-05-13 00:44:10 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS informe(
|
2020-06-17 08:42:53 +02:00
|
|
|
id INT AUTO_INCREMENT,
|
2020-05-13 00:44:10 +02:00
|
|
|
fecha DATE NOT NULL,
|
|
|
|
hora TIME NOT NULL,
|
2020-06-17 22:02:27 +02:00
|
|
|
paciente INT NOT NULL,
|
2020-05-13 00:44:10 +02:00
|
|
|
titulo VARCHAR(100) NOT NULL,
|
|
|
|
contenido VARCHAR(255) NOT NULL,
|
2020-06-18 09:04:44 +02:00
|
|
|
medico INT NOT NULL,
|
2020-05-13 00:44:10 +02:00
|
|
|
PRIMARY KEY (id, paciente),
|
|
|
|
FOREIGN KEY (medico)
|
2020-06-18 09:04:44 +02:00
|
|
|
REFERENCES usuario(id),
|
2020-05-13 00:44:10 +02:00
|
|
|
FOREIGN KEY (paciente)
|
2020-06-17 12:08:52 +02:00
|
|
|
REFERENCES paciente(id)
|
2020-05-13 00:44:10 +02:00
|
|
|
);
|
2020-06-16 18:56:35 +02:00
|
|
|
|
|
|
|
INSERT INTO rol (codigo, nombre) VALUES (1, "administrativo");
|
|
|
|
INSERT INTO rol (codigo, nombre) VALUES (2, "medico");
|