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;
|
|
|
|
|
|
|
|
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-05-13 00:44:10 +02:00
|
|
|
localidad VARCHAR(100) NOT NULL,
|
|
|
|
provincia VARCHAR(50) NOT NULL,
|
|
|
|
pais VARCHAR(100) NOT NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
medico VARCHAR(50),
|
|
|
|
FOREIGN KEY (medico)
|
|
|
|
REFERENCES usuario(usuario)
|
|
|
|
);
|
|
|
|
|
|
|
|
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,
|
|
|
|
medico VARCHAR(50),
|
|
|
|
PRIMARY KEY (id, medico),
|
|
|
|
FOREIGN KEY (medico)
|
|
|
|
REFERENCES usuario(usuario)
|
|
|
|
);
|
|
|
|
|
|
|
|
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,
|
|
|
|
medico VARCHAR(50) NOT NULL,
|
|
|
|
observaciones VARCHAR(255),
|
2020-06-17 08:42:53 +02:00
|
|
|
paciente INT,
|
2020-05-13 00:44:10 +02:00
|
|
|
PRIMARY KEY (id, medico),
|
|
|
|
FOREIGN KEY (medico)
|
|
|
|
REFERENCES usuario(usuario),
|
|
|
|
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,
|
|
|
|
paciente VARCHAR(50) NOT NULL,
|
|
|
|
titulo VARCHAR(100) NOT NULL,
|
|
|
|
contenido VARCHAR(255) NOT NULL,
|
|
|
|
medico VARCHAR(50) NOT NULL,
|
|
|
|
PRIMARY KEY (id, paciente),
|
|
|
|
FOREIGN KEY (medico)
|
|
|
|
REFERENCES usuario(usuario),
|
|
|
|
FOREIGN KEY (paciente)
|
|
|
|
REFERENCES paciente(documento_identificativo)
|
|
|
|
);
|
2020-06-16 18:56:35 +02:00
|
|
|
|
|
|
|
INSERT INTO rol (codigo, nombre) VALUES (1, "administrativo");
|
|
|
|
INSERT INTO rol (codigo, nombre) VALUES (2, "medico");
|