109 lines
3.0 KiB
SQL
109 lines
3.0 KiB
SQL
CREATE DATABASE IF NOT EXISTS practica CHARACTER SET utf8mb4;
|
|
|
|
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;
|
|
|
|
source database/provincias.sql;
|
|
|
|
source database/municipios.sql;
|
|
|
|
CREATE TABLE IF NOT EXISTS paciente (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
nombre VARCHAR(50) NOT NULL,
|
|
apellido VARCHAR(50) NOT NULL,
|
|
fecha_de_nacimiento DATE NOT NULL,
|
|
documento_identificativo VARCHAR(50) UNIQUE NOT NULL,
|
|
tipo_documento VARCHAR(10) NOT NULL,
|
|
direccion VARCHAR(255) NOT NULL,
|
|
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)
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS rol(
|
|
codigo INT PRIMARY KEY,
|
|
nombre VARCHAR(25) NOT NULL
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS usuario(
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
nombre VARCHAR(50) NOT NULL,
|
|
usuario VARCHAR(50) UNIQUE,
|
|
contraseña VARCHAR(100) NOT NULL,
|
|
rol INT NOT NULL,
|
|
especialidad VARCHAR(50),
|
|
correo VARCHAR(100) NOT NULL,
|
|
fecha_alta TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
fecha_baja TIMESTAMP NULL,
|
|
FOREIGN KEY (rol)
|
|
REFERENCES rol(codigo)
|
|
);
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS festivo (
|
|
id INT PRIMARY KEY AUTO_INCREMENT,
|
|
fecha_festivo DATE NOT NULL,
|
|
tipo_festivo VARCHAR(15) NOT NULL,
|
|
medico INT DEFAULT NULL,
|
|
FOREIGN KEY (medico)
|
|
REFERENCES usuario(id)
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS calendario (
|
|
id INT AUTO_INCREMENT,
|
|
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 INT,
|
|
PRIMARY KEY (id, medico),
|
|
FOREIGN KEY (medico)
|
|
REFERENCES usuario(id)
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS cita(
|
|
id INT AUTO_INCREMENT,
|
|
fecha DATE NOT NULL,
|
|
hora TIME NOT NULL,
|
|
duracion INT,
|
|
medico INT NOT NULL,
|
|
observaciones VARCHAR(255),
|
|
paciente INT NOT NULL,
|
|
PRIMARY KEY (id, medico),
|
|
FOREIGN KEY (medico)
|
|
REFERENCES usuario(id),
|
|
FOREIGN KEY (paciente)
|
|
REFERENCES paciente(id)
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS informe(
|
|
id INT AUTO_INCREMENT,
|
|
fecha DATE NOT NULL,
|
|
hora TIME NOT NULL,
|
|
paciente INT NOT NULL,
|
|
titulo VARCHAR(100) NOT NULL,
|
|
contenido VARCHAR(255) NOT NULL,
|
|
medico INT NOT NULL,
|
|
PRIMARY KEY (id, paciente),
|
|
FOREIGN KEY (medico)
|
|
REFERENCES usuario(id),
|
|
FOREIGN KEY (paciente)
|
|
REFERENCES paciente(id)
|
|
);
|
|
|
|
INSERT INTO rol (codigo, nombre) VALUES (1, "administrativo");
|
|
INSERT INTO rol (codigo, nombre) VALUES (2, "medico");
|