INSERT INTO `sc_tb_menu` (`id`, `pai`, `nome`, `icone`, `tipo`, `local`, `arquivo`, `url`, `target`, `ativo`, `modulo`, `ordem`, `ad_a_click`, `ad_p_nome`, `ad_p_nome_cor`, `cor_nome`, `cor_icone`, `temp`) VALUES
('painel_01', '000', 'Painel', 'command', 'N', '.content-body', NULL, '#', NULL, 1, 'painel', 0, NULL, NULL, 'bg-primary', NULL, NULL, NULL),
('painel_02', 'painel_01', 'Configuração', 'settings', 'N', '.content-body', NULL, '#', NULL, 1, 'painel', 0, NULL, NULL, 'bg-primary', NULL, NULL, NULL),
('painel_03', 'painel_01', 'Chamar', 'monitor', 'C', '.content-body', 'mod/painel/chamar.php', '#', NULL, 1, 'painel', 0, NULL, NULL, 'bg-primary', NULL, NULL, NULL),
('painel_04', 'painel_02', 'Geral', 'tool', 'C', '.content-body', 'mod/painel/frm_cf.php', '#', NULL, 1, 'painel', 0, NULL, NULL, 'bg-primary', NULL, NULL, NULL),
('painel_05', 'painel_02', 'Limpar', 'x-circle', 'C', '.content-body', 'mod/painel/frm_limpa.php', '#', NULL, 1, 'painel', 0, NULL, NULL, 'bg-primary', NULL, NULL, NULL),
('painel_06', 'painel_02', 'Profissionais', 'x-circle', 'C', '.content-body', 'mod/painel/frm_profs.php', '#', NULL, 1, 'painel', 0, NULL, NULL, 'bg-primary', NULL, NULL, NULL),
('painel_07', 'painel_01', 'Incluir', 'monitor', 'C', '.content-body', 'mod/painel/incluir.php', '#', NULL, 1, 'painel', 0, NULL, NULL, 'bg-primary', NULL, NULL, NULL),
('painel_08', 'painel_02', 'Unidades', 'x-circle', 'C', '.content-body', 'mod/painel/frm_unidades.php', '#', NULL, 1, 'painel', 0, NULL, NULL, 'bg-primary', NULL, NULL, NULL),
('painel_09', 'painel_01', 'Monitor', 'monitor', 'C', '.content-body', 'mod/painel/monitor.php', '#', NULL, 1, 'painel', 0, NULL, NULL, 'bg-primary', NULL, NULL, NULL),
('painel_10', 'painel_02', 'Português', 'x-circle', 'C', '.content-body', 'mod/painel/frm_portuga.php', '#', NULL, 1, 'painel', 0, NULL, NULL, 'bg-primary', NULL, NULL, NULL),
('painel_11', 'painel_02', 'CNES', 'x-circle', 'C', '.content-body', 'mod/painel/frm_cnes.php', '#', NULL, 1, 'painel', 0, NULL, NULL, 'bg-primary', NULL, NULL, NULL);

INSERT INTO `sc_tb_modulos` (`modulo`) VALUES ('painel');

CREATE TABLE IF NOT EXISTS `painel_tb_portugues` (
  `origem` varchar(25) NOT NULL,
  `destino` varchar(25) NOT NULL,
  CONSTRAINT pk_CE primary key(origem,destino)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `painel_tb_cf_geral` (
  `id` varchar(11) NOT NULL,
  `ibge` varchar(7) NOT NULL,
  `usar` int(11) NOT NULL DEFAULT 0,
  `segundos` int(11) NOT NULL DEFAULT 2,
  `ligacao` varchar(250) DEFAULT 'se dirija à sala',
  `ligacaopec` varchar(250) DEFAULT 'se dirija',
  `sligacao` varchar(250) DEFAULT 'se dirija à sala indicada',
  `prefixo` varchar(250) DEFAULT 'Atenção',
  `prop_url` varchar(250) DEFAULT NULL,
  `prop_tipo` int(11) DEFAULT 0,
  `qrcode` int(11) DEFAULT 0,
  `qrcodesz` int(11) DEFAULT 4,
  `tema` varchar(150) DEFAULT 'default',
  `linha_cab` varchar(350) DEFAULT NULL,
  `linha_rod` varchar(350) DEFAULT NULL,
  `pec_auto` int(11) NOT NULL DEFAULT 0,
  `escuta` varchar(1) DEFAULT 'T',
  `cbo_escuta` varchar(250) DEFAULT '322250,322245',
  `cbo_procedimento` varchar(250) DEFAULT '322250,322245',
  `cbo_enfermagem` varchar(250) DEFAULT '223565',
  `cbo_medico` varchar(250) DEFAULT '225142',
  `cbo_odonto` varchar(250) DEFAULT '223293,322425,322415',
  `sl_escuta` varchar(150) DEFAULT 'à sala de escuta inicial',
  `sl_procedimento` varchar(150) DEFAULT 'à sala de procedimentos',
  `sl_enfermagem` varchar(150) DEFAULT 'à sala de enfermagem',
  `sl_medico` varchar(150) DEFAULT 'ao consultório médico',
  `sl_odonto` varchar(150) DEFAULT 'ao consultório odontológico',
  `sl_vacina` varchar(150) DEFAULT 'à sala de vacina',
  `portugues` int(11) NOT NULL DEFAULT 0,
  `voz_voz` varchar(350) DEFAULT NULL,
  `voz_velocidade` FLOAT NOT NULL DEFAULT '1',
  `voz_pitch` FLOAT NOT NULL DEFAULT '1',
  `voz_metodo` varchar(20) DEFAULT 'google',
  `chamados` int(11) NOT NULL DEFAULT 5,
  CONSTRAINT pk_CE primary key(id,ibge)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `painel_tb_chave_diaria` (
  `ibge` varchar(7) NOT NULL,
  `cnes` varchar(7) DEFAULT NULL,
  `tempo` date NOT NULL,
  `chave_celular` varchar(250) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `painel_tb_class_risco` (
  `idpec` int(11) NOT NULL PRIMARY KEY,
  `prioridade` int(11) NOT NULL DEFAULT 0,
  `cor` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `painel_tb_cnes` (
  `cnes` varchar(7) NOT NULL PRIMARY KEY,
  `ibge` varchar(7) NOT NULL,
  `estabelecimento` varchar(200) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `painel_tb_class_risco` (`idpec`, `prioridade`, `cor`) VALUES ('0', '0', 'dark');
INSERT INTO `painel_tb_class_risco` (`idpec`, `prioridade`, `cor`) VALUES ('1', '2', 'success');
INSERT INTO `painel_tb_class_risco` (`idpec`, `prioridade`, `cor`) VALUES ('2', '3', 'primary');
INSERT INTO `painel_tb_class_risco` (`idpec`, `prioridade`, `cor`) VALUES ('3', '4', 'warning');
INSERT INTO `painel_tb_class_risco` (`idpec`, `prioridade`, `cor`) VALUES ('4', '5', 'danger');
INSERT INTO `painel_tb_class_risco` (`idpec`, `prioridade`, `cor`) VALUES ('5', '6', 'danger');
INSERT INTO `painel_tb_class_risco` (`idpec`, `prioridade`, `cor`) VALUES ('6', '2', 'success');
INSERT INTO `painel_tb_class_risco` (`idpec`, `prioridade`, `cor`) VALUES ('7', '4', 'warning');
INSERT INTO `painel_tb_class_risco` (`idpec`, `prioridade`, `cor`) VALUES ('8', '5', 'danger');
INSERT INTO `painel_tb_class_risco` (`idpec`, `prioridade`, `cor`) VALUES ('9', '3', 'primary');

CREATE TABLE IF NOT EXISTS `painel_tb_chamada` (
  `idc` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `tempo` datetime NOT NULL DEFAULT current_timestamp(),
  `tempo_cancelado` datetime DEFAULT NULL,
  `tempo_atendido` datetime DEFAULT NULL,
  `tempo_chamada` datetime DEFAULT NULL,
  `sala` varchar(100) DEFAULT NULL,
  `cidadao` varchar(250) NOT NULL,
  `cpf` varchar(11) DEFAULT NULL,
  `cns` varchar(15) DEFAULT NULL,
  `profissional` varchar(250) DEFAULT NULL,
  `pri_clas_risco` int(11) NOT NULL DEFAULT 0,
  `pec_clas_risco` int(11) NOT NULL DEFAULT 0,
  `des_clas_risco` varchar(250) DEFAULT 'NÃO CLASSIFICADO',
  `cor_clas_risco` varchar(10) DEFAULT 'dark',
  `prof_cpf` varchar(11) DEFAULT NULL,
  `prof_cns` varchar(15) DEFAULT NULL,
  `cnes` varchar(7) DEFAULT NULL,
  `dt_nascimento` date DEFAULT NULL,
  `estagio` int(11) NOT NULL DEFAULT 1,
  `senha` int(11) NOT NULL DEFAULT 0,
  `ibge` varchar(7) NOT NULL,
  `origem` varchar(10) DEFAULT 'ESUS',
  `ctc` int(11) NOT NULL DEFAULT 0,
  `txt_final` varchar(350) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


CREATE TABLE IF NOT EXISTS `painel_tb_cidadao` (
  `senha` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `status` varchar(250) DEFAULT NULL,
  `estagio` int(11) NOT NULL DEFAULT 1,
  `cidadao` varchar(250) NOT NULL,
  `dt_nascimento` date DEFAULT NULL,
  `cpf` varchar(11) DEFAULT NULL,
  `cns` varchar(15) DEFAULT NULL,
  `sexo` varchar(1) DEFAULT 'F',
  `tempo` datetime NOT NULL DEFAULT current_timestamp(),
  `tempo_cancelado` datetime DEFAULT NULL,
  `tempo_atendido` datetime DEFAULT NULL,
  `profissional` varchar(250) DEFAULT NULL,
  `prof_cns` varchar(15) DEFAULT NULL,
  `prof_cpf` varchar(11) DEFAULT NULL,
  `prof_cbo` varchar(250) DEFAULT NULL,
  `prof_cbo_nu` varchar(7) DEFAULT NULL,
  `prof_ine` varchar(10) DEFAULT NULL,
  `prof_equipe` varchar(250) DEFAULT NULL,
  `cnes` varchar(7) DEFAULT NULL,
  `unidade` varchar(250) DEFAULT NULL,
  `ibge` varchar(7) DEFAULT NULL,
  `sala` varchar(100) DEFAULT NULL,
  `no_classificacao_risco` varchar(100) DEFAULT NULL,
  `co_classificacao_risco` int(11) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `painel_tb_profissionais` (
  `id` varchar(11) NOT NULL,
  `ibge` varchar(7) NOT NULL,
  `cnes` varchar(7) NOT NULL,
  `nome` varchar(250) DEFAULT NULL,
  `sala` varchar(50) DEFAULT NULL,
  `exclusivo` int(11) NOT NULL DEFAULT 1,
  CONSTRAINT pk_CE primary key(id,ibge,cnes)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `painel_tb_unidades` (
  `id` varchar(7) NOT NULL,
  `ibge` varchar(7) NOT NULL,
  `chave` varchar(250) DEFAULT NULL,
  `nome` varchar(250) DEFAULT NULL,
  CONSTRAINT pk_CE primary key(id,ibge)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO sc_tb_usuarios_perfil (id,nome)
SELECT * FROM (SELECT 'painel_chamador' AS id,'Chamador PAINEL' AS nome) AS temp
WHERE NOT EXISTS (
	SELECT id FROM sc_tb_usuarios_perfil WHERE id = 'painel_chamador'
) 
LIMIT 1;

INSERT INTO sc_tb_usuarios_perfil (id,nome)
SELECT * FROM (SELECT 'painel_inclusor' AS id,'Recepcao PAINEL' AS nome) AS temp
WHERE NOT EXISTS (
	SELECT id FROM sc_tb_usuarios_perfil WHERE id = 'painel_inclusor'
) 
LIMIT 1;

INSERT INTO sc_rl_menu_perfil (id_menu, id_perfil) SELECT * FROM (SELECT 'painel_01' AS id_menu, 'painel_chamador' AS id_perfil) AS temp WHERE NOT EXISTS (SELECT id_menu FROM sc_rl_menu_perfil WHERE id_menu = 'painel_01' AND id_perfil = 'painel_chamador') LIMIT 1;
INSERT INTO sc_rl_menu_perfil (id_menu, id_perfil) SELECT * FROM (SELECT 'painel_03' AS id_menu, 'painel_chamador' AS id_perfil) AS temp WHERE NOT EXISTS (SELECT id_menu FROM sc_rl_menu_perfil WHERE id_menu = 'painel_03' AND id_perfil = 'painel_chamador') LIMIT 1;

INSERT INTO sc_rl_menu_perfil (id_menu, id_perfil) SELECT * FROM (SELECT 'painel_01' AS id_menu, 'painel_inclusor' AS id_perfil) AS temp WHERE NOT EXISTS (SELECT id_menu FROM sc_rl_menu_perfil WHERE id_menu = 'painel_01' AND id_perfil = 'painel_inclusor') LIMIT 1;
INSERT INTO sc_rl_menu_perfil (id_menu, id_perfil) SELECT * FROM (SELECT 'painel_02' AS id_menu, 'painel_inclusor' AS id_perfil) AS temp WHERE NOT EXISTS (SELECT id_menu FROM sc_rl_menu_perfil WHERE id_menu = 'painel_02' AND id_perfil = 'painel_inclusor') LIMIT 1;
INSERT INTO sc_rl_menu_perfil (id_menu, id_perfil) SELECT * FROM (SELECT 'painel_04' AS id_menu, 'painel_inclusor' AS id_perfil) AS temp WHERE NOT EXISTS (SELECT id_menu FROM sc_rl_menu_perfil WHERE id_menu = 'painel_04' AND id_perfil = 'painel_inclusor') LIMIT 1;
INSERT INTO sc_rl_menu_perfil (id_menu, id_perfil) SELECT * FROM (SELECT 'painel_05' AS id_menu, 'painel_inclusor' AS id_perfil) AS temp WHERE NOT EXISTS (SELECT id_menu FROM sc_rl_menu_perfil WHERE id_menu = 'painel_05' AND id_perfil = 'painel_inclusor') LIMIT 1;
INSERT INTO sc_rl_menu_perfil (id_menu, id_perfil) SELECT * FROM (SELECT 'painel_06' AS id_menu, 'painel_inclusor' AS id_perfil) AS temp WHERE NOT EXISTS (SELECT id_menu FROM sc_rl_menu_perfil WHERE id_menu = 'painel_06' AND id_perfil = 'painel_inclusor') LIMIT 1;
INSERT INTO sc_rl_menu_perfil (id_menu, id_perfil) SELECT * FROM (SELECT 'painel_07' AS id_menu, 'painel_inclusor' AS id_perfil) AS temp WHERE NOT EXISTS (SELECT id_menu FROM sc_rl_menu_perfil WHERE id_menu = 'painel_07' AND id_perfil = 'painel_inclusor') LIMIT 1;
INSERT INTO sc_rl_menu_perfil (id_menu, id_perfil) SELECT * FROM (SELECT 'painel_08' AS id_menu, 'painel_inclusor' AS id_perfil) AS temp WHERE NOT EXISTS (SELECT id_menu FROM sc_rl_menu_perfil WHERE id_menu = 'painel_08' AND id_perfil = 'painel_inclusor') LIMIT 1;
INSERT INTO sc_rl_menu_perfil (id_menu, id_perfil) SELECT * FROM (SELECT 'painel_09' AS id_menu, 'painel_inclusor' AS id_perfil) AS temp WHERE NOT EXISTS (SELECT id_menu FROM sc_rl_menu_perfil WHERE id_menu = 'painel_09' AND id_perfil = 'painel_inclusor') LIMIT 1;
INSERT INTO sc_rl_menu_perfil (id_menu, id_perfil) SELECT * FROM (SELECT 'painel_10' AS id_menu, 'painel_inclusor' AS id_perfil) AS temp WHERE NOT EXISTS (SELECT id_menu FROM sc_rl_menu_perfil WHERE id_menu = 'painel_10' AND id_perfil = 'painel_inclusor') LIMIT 1;