use `qc`;
ALTER TABLE `med_check_info` ADD COLUMN `check_type` INT(11) NULL COMMENT '核查类型（0病历，1病案首页）' AFTER `status`;
UPDATE med_check_info a SET check_type =0;
UPDATE med_check_info a SET check_name = (SELECT linkman FROM sys_user b WHERE a.check_id=b.id) inkman FROM sys_user b WHERE a.check_id=b.id);


DELETE FROM sys_user_pageset WHERE user_id = -1;

INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '病历等级', 'level', '1', '1', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES ( 'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '病历得分', 'scoreRes', '1', '2', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '病人住院序号', 'behospitalCode', '1', '3', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '病案首页核查状态', 'mrStatus', '1', '4', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '病案首页核查人', 'mrName', '1', '5', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES ( 'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '病案首页核查时间', 'mrTime', '1', '6', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '病历核查状态', 'checkStatus', '1', '7', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '病历核查人', 'chName', '1', '8', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '病历核查时间', 'chTime', '1', '9', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '病案号', 'fileCode', '1', '10', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '病人姓名', 'name', '1', '11', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '性别', 'sex', '1', '12', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '年龄', 'age', '1', '13', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '床号', 'bedCode', '1', '14', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '入院日期', 'behospitalDate', '1', '15', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '出院日期', 'leaveHospitalDate', '1', '16', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '归档日期', 'placefileDate', '1', '17', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '主诊断', 'diagnose', '1', '18', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '住院医生', 'behDoctorName', '1', '19', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '主管医生', 'doctorName', '1', '20', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '主任医生', 'directorDoctorName', '1', '21', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES (  'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '科室', 'behDeptName', '1', '22', NULL);
INSERT INTO `sys_user_pageset` (  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`) VALUES ( 'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '-1', '1', '评分时间', 'gradeTime', '1', '23', NULL);

-- 找出没有”核查状态“的人员并给加上
 INSERT INTO sys_user_pageset
(  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`)
 SELECT is_deleted,
gmt_create,
 gmt_modified,
 creator,
MODIFIER,
 user_id,
 page_type,
 CASE WHEN ISNULL(NAME) THEN "病案首页核查状态" ELSE "病案首页核查状态" END NAME,
 CASE WHEN ISNULL(userId) THEN "mrStatus" ELSE "mrStatus" END val,
 CASE WHEN ISNULL(STATUS) THEN 0 ELSE 0 END STATUS,
 CASE WHEN ISNULL(order_no) THEN 4 ELSE 4 END order_no,
 remark
 FROM (SELECT * FROM  sys_user_pageset  WHERE user_id <> -1) b LEFT JOIN  (SELECT c.user_id AS userId FROM  sys_user_pageset c  WHERE user_id <> -1 AND val = "mrStatus") p ON b.user_id = p.userId
WHERE  userId IS NULL
 GROUP BY user_id ;


 INSERT INTO sys_user_pageset
(  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`)
 SELECT is_deleted,
gmt_create,
 gmt_modified,
 creator,
MODIFIER,
 user_id,
 page_type,
 CASE WHEN ISNULL(NAME) THEN "病案首页核查人" ELSE "病案首页核查人" END NAME,
 CASE WHEN ISNULL(userId) THEN "mrName" ELSE "mrName" END val,
 CASE WHEN ISNULL(STATUS) THEN 0 ELSE 0 END STATUS,
 CASE WHEN ISNULL(order_no) THEN 5 ELSE 5 END order_no,
 remark
 FROM (SELECT * FROM  sys_user_pageset  WHERE user_id <> -1) b LEFT JOIN  (SELECT c.user_id AS userId FROM  sys_user_pageset c  WHERE user_id <> -1 AND val = "mrName") p ON b.user_id = p.userId
WHERE  userId IS NULL
 GROUP BY user_id ;


 INSERT INTO sys_user_pageset
(  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`)
 SELECT is_deleted,
gmt_create,
 gmt_modified,
 creator,
MODIFIER,
 user_id,
 page_type,
 CASE WHEN ISNULL(NAME) THEN "病案首页核查时间" ELSE "病案首页核查时间" END NAME,
 CASE WHEN ISNULL(userId) THEN "mrTime" ELSE "mrTime" END val,
 CASE WHEN ISNULL(STATUS) THEN 0 ELSE 0 END STATUS,
 CASE WHEN ISNULL(order_no) THEN 6 ELSE 6 END order_no,
 remark
 FROM (SELECT * FROM  sys_user_pageset  WHERE user_id <> -1) b LEFT JOIN  (SELECT c.user_id AS userId FROM  sys_user_pageset c  WHERE user_id <> -1 AND val = "mrTime") p ON b.user_id = p.userId
WHERE  userId IS NULL
 GROUP BY user_id ;



 INSERT INTO sys_user_pageset
(  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`)
 SELECT is_deleted,
gmt_create,
 gmt_modified,
 creator,
MODIFIER,
 user_id,
 page_type,
 CASE WHEN ISNULL(NAME) THEN "病历核查人" ELSE "病历核查人" END NAME,
 CASE WHEN ISNULL(userId) THEN "chName" ELSE "chName" END val,
 CASE WHEN ISNULL(STATUS) THEN 0 ELSE 0 END STATUS,
 CASE WHEN ISNULL(order_no) THEN 7 ELSE 7 END order_no,
 remark
 FROM (SELECT * FROM  sys_user_pageset  WHERE user_id <> -1) b LEFT JOIN  (SELECT c.user_id AS userId FROM  sys_user_pageset c  WHERE user_id <> -1 AND val = "chName") p ON b.user_id = p.userId
WHERE  userId IS NULL
 GROUP BY user_id ;


 INSERT INTO sys_user_pageset
(  `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `user_id`, `page_type`, `name`, `val`, `status`, `order_no`, `remark`)
 SELECT is_deleted,
gmt_create,
 gmt_modified,
 creator,
MODIFIER,
 user_id,
 page_type,
 CASE WHEN ISNULL(NAME) THEN "病历核查时间" ELSE "病历核查时间" END NAME,
 CASE WHEN ISNULL(userId) THEN "chTime" ELSE "chTime" END val,
 CASE WHEN ISNULL(STATUS) THEN 0 ELSE 0 END STATUS,
 CASE WHEN ISNULL(order_no) THEN 8 ELSE 8 END order_no,
 remark
 FROM (SELECT * FROM  sys_user_pageset  WHERE user_id <> -1) b LEFT JOIN  (SELECT c.user_id AS userId FROM  sys_user_pageset c  WHERE user_id <> -1 AND val = "chTime") p ON b.user_id = p.userId
WHERE  userId IS NULL
 GROUP BY user_id ;

 UPDATE sys_user_pageset a SET a.name = "病历核查状态" WHERE a.user_id <> -1 AND val ="checkStatus";

-- 新增权限
INSERT INTO `sys_menu`(`id`, `is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `name`, `parent_id`, `code`, `show_status`, `maintain_status`, `order_no`, `remark`) VALUES (38, 'N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', '31天再入院人数', 17, 'YH-ZKK-31TZRYRS', 1, 1, 14, '用户-质控科-31天再入院人数');
INSERT INTO `sys_role_menu`(`is_deleted`, `gmt_create`, `gmt_modified`, `creator`, `modifier`, `role_id`, `menu_id`, `remark`) VALUES ('N', '1970-01-01 12:00:00', '1970-01-01 12:00:00', '0', '0', -1, 38, '用户-质控科-31天再入院人数');

update sys_menu set name ='时效性相关统计' where id=37;