Modifications for module installer in openemr.
[openemr.git] / sql / 4_1_2-to-4_1_3_upgrade.sql
blob8ca886aed7f5452c0dd97633e1415ba56b320221
1 --
2 --  Comment Meta Language Constructs:
3 --
4 --  #IfNotTable
5 --    argument: table_name
6 --    behavior: if the table_name does not exist,  the block will be executed
8 --  #IfTable
9 --    argument: table_name
10 --    behavior: if the table_name does exist, the block will be executed
12 --  #IfMissingColumn
13 --    arguments: table_name colname
14 --    behavior:  if the table exists but the column does not,  the block will be executed
16 --  #IfNotColumnType
17 --    arguments: table_name colname value
18 --    behavior:  If the table table_name does not have a column colname with a data type equal to value, then the block will be executed
20 --  #IfNotRow
21 --    arguments: table_name colname value
22 --    behavior:  If the table table_name does not have a row where colname = value, the block will be executed.
24 --  #IfNotRow2D
25 --    arguments: table_name colname value colname2 value2
26 --    behavior:  If the table table_name does not have a row where colname = value AND colname2 = value2, the block will be executed.
28 --  #IfNotRow3D
29 --    arguments: table_name colname value colname2 value2 colname3 value3
30 --    behavior:  If the table table_name does not have a row where colname = value AND colname2 = value2 AND colname3 = value3, the block will be executed.
32 --  #IfNotRow4D
33 --    arguments: table_name colname value colname2 value2 colname3 value3 colname4 value4
34 --    behavior:  If the table table_name does not have a row where colname = value AND colname2 = value2 AND colname3 = value3 AND colname4 = value4, the block will be executed.
36 --  #IfNotRow2Dx2
37 --    desc:      This is a very specialized function to allow adding items to the list_options table to avoid both redundant option_id and title in each element.
38 --    arguments: table_name colname value colname2 value2 colname3 value3
39 --    behavior:  The block will be executed if both statements below are true:
40 --               1) The table table_name does not have a row where colname = value AND colname2 = value2.
41 --               2) The table table_name does not have a row where colname = value AND colname3 = value3.
43 --  #IfRow2D
44 --    arguments: table_name colname value colname2 value2
45 --    behavior:  If the table table_name does have a row where colname = value AND colname2 = value2, the block will be executed.
47 --  #IfIndex
48 --    desc:      This function is most often used for dropping of indexes/keys.
49 --    arguments: table_name colname
50 --    behavior:  If the table and index exist the relevant statements are executed, otherwise not.
52 --  #IfNotIndex
53 --    desc:      This function will allow adding of indexes/keys.
54 --    arguments: table_name colname
55 --    behavior:  If the index does not exist, it will be created
57 --  #EndIf
58 --    all blocks are terminated with a #EndIf statement.
60 #IfNotRow4D supported_external_dataloads load_type ICD9 load_source CMS load_release_date 2013-10-01 load_filename cmsv31-master-descriptions.zip
61 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES ('ICD9', 'CMS', '2013-10-01', 'cmsv31-master-descriptions.zip', 'fe0d7f9a5338f5ff187683b4737ad2b7');
62 #EndIf
64 #IfNotRow4D supported_external_dataloads load_type ICD10 load_source CMS load_release_date 2012-10-01 load_filename 2013_PCS_long_and_abbreviated_titles.zip
65 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES ('ICD10', 'CMS', '2012-10-01', '2013_PCS_long_and_abbreviated_titles.zip', '04458ed0631c2c122624ee0a4ca1c475');
66 #EndIf
68 #IfNotRow4D supported_external_dataloads load_type ICD10 load_source CMS load_release_date 2012-10-01 load_filename 2013-DiagnosisGEMs.zip
69 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES ('ICD10', 'CMS', '2012-10-01', '2013-DiagnosisGEMs.zip', '773aac2a675d6aefd1d7dd149883be51');
70 #EndIf
72 #IfNotRow4D supported_external_dataloads load_type ICD10 load_source CMS load_release_date 2012-10-01 load_filename ICD10CMOrderFiles_2013.zip
73 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES ('ICD10', 'CMS', '2012-10-01', 'ICD10CMOrderFiles_2013.zip', '1c175a858f833485ef8f9d3e66b4d8bd');
74 #EndIf
76 #IfNotRow4D supported_external_dataloads load_type ICD10 load_source CMS load_release_date 2012-10-01 load_filename ProcedureGEMs_2013.zip
77 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES ('ICD10', 'CMS', '2012-10-01', 'ProcedureGEMs_2013.zip', '92aa7640e5ce29b9629728f7d4fc81db');
78 #EndIf
80 #IfNotRow4D supported_external_dataloads load_type ICD10 load_source CMS load_release_date 2012-10-01 load_filename 2013-ReimbursementMapping_dx.zip
81 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES ('ICD10', 'CMS', '2012-10-01', '2013-ReimbursementMapping_dx.zip', '0d5d36e3f4519bbba08a9508576787fb');
82 #EndIf
84 #IfNotRow4D supported_external_dataloads load_type ICD10 load_source CMS load_release_date 2012-10-01 load_filename ReimbursementMapping_pr_2013.zip
85 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES ('ICD10', 'CMS', '2012-10-01', 'ReimbursementMapping_pr_2013.zip', '4c3920fedbcd9f6af54a1dc9069a11ca');
86 #EndIf
88 #IfNotRow4D supported_external_dataloads load_type ICD10 load_source CMS load_release_date 2013-10-01 load_filename 2014-PCS-long-and-abbreviated-titles.zip
89 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES ('ICD10', 'CMS', '2013-10-01', '2014-PCS-long-and-abbreviated-titles.zip', '2d03514a0c66d92cf022a0bc28c83d38');
90 #EndIf
92 #IfNotRow4D supported_external_dataloads load_type ICD10 load_source CMS load_release_date 2013-10-01 load_filename DiagnosisGEMs-2014.zip
93 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES ('ICD10', 'CMS', '2013-10-01', 'DiagnosisGEMs-2014.zip', '3ed7b7c5a11c766102b12d97d777a11b');
94 #EndIf
96 #IfNotRow4D supported_external_dataloads load_type ICD10 load_source CMS load_release_date 2013-10-01 load_filename 2014-ICD10-Code-Descriptions.zip
97 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES ('ICD10', 'CMS', '2013-10-01', '2014-ICD10-Code-Descriptions.zip', '5458b95f6f37228b5cdfa03aefc6c8bb');
98 #EndIf
100 #IfNotRow4D supported_external_dataloads load_type ICD10 load_source CMS load_release_date 2013-10-01 load_filename ProcedureGEMs-2014.zip
101 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES ('ICD10', 'CMS', '2013-10-01', 'ProcedureGEMs-2014.zip', 'be46de29f4f40f97315d04821273acf9');
102 #EndIf
104 #IfNotRow4D supported_external_dataloads load_type ICD10 load_source CMS load_release_date 2013-10-01 load_filename 2014-Reimbursement-Mappings-DX.zip
105 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES ('ICD10', 'CMS', '2013-10-01', '2014-Reimbursement-Mappings-DX.zip', '614b3957304208e3ef7d3ba8b3618888');
106 #EndIf
108 #IfNotRow4D supported_external_dataloads load_type ICD10 load_source CMS load_release_date 2013-10-01 load_filename 2014-Reimbursement-Mappings-PR.zip
109 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES ('ICD10', 'CMS', '2013-10-01', '2014-Reimbursement-Mappings-PR.zip', 'f306a0e8c9edb34d28fd6ce8af82b646');
110 #EndIf
112 #IfMissingColumn patient_data email_direct
113 ALTER TABLE `patient_data` ADD COLUMN `email_direct` varchar(255) NOT NULL default '';
114 INSERT INTO `layout_options` (`form_id`, `field_id`, `group_name`, `title`, `seq`, `data_type`, `uor`, `fld_length`, `max_length`, `list_id`, `titlecols`, `datacols`, `default_value`, `edit_options`, `description`, `fld_rows`) VALUES('DEM', 'email_direct', '2Contact', 'Trusted Email', 14, 2, 1, 30, 95, '', 1, 1, '', '', 'Trusted (Direct) Email Address', 0);
115 #EndIf
117 #IfMissingColumn users email_direct
118 ALTER TABLE `users` ADD COLUMN `email_direct` varchar(255) NOT NULL default '';
119 #EndIf
121 #IfNotTable erx_ttl_touch
122 CREATE TABLE `erx_ttl_touch` (
123   `patient_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'Patient record Id', 
124   `process` ENUM('allergies','medications') NOT NULL COMMENT 'NewCrop eRx SOAP process',
125   `updated` DATETIME NOT NULL COMMENT 'Date and time of last process update for patient', 
126   PRIMARY KEY (`patient_id`, `process`) ) 
127 ENGINE = InnoDB COMMENT = 'Store records last update per patient data process';
128 #EndIf
130 #IfMissingColumn form_misc_billing_options box_14_date_qual
131 ALTER TABLE `form_misc_billing_options` 
132 ADD COLUMN `box_14_date_qual` CHAR(3) NULL DEFAULT NULL;
133 #EndIf
135 #IfMissingColumn form_misc_billing_options box_15_date_qual
136 ALTER TABLE `form_misc_billing_options` 
137 ADD COLUMN `box_15_date_qual` CHAR(3) NULL DEFAULT NULL;
138 #EndIf
140 #IfNotTable esign_signatures
141 CREATE TABLE `esign_signatures` (
142   `id` int(11) NOT NULL AUTO_INCREMENT,
143   `tid` int(11) NOT NULL COMMENT 'Table row ID for signature',
144   `table` varchar(255) NOT NULL COMMENT 'table name for the signature',
145   `uid` int(11) NOT NULL COMMENT 'user id for the signing user',
146   `datetime` datetime NOT NULL COMMENT 'datetime of the signature action',
147   `is_lock` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'sig, lock or amendment',
148   `amendment` text COMMENT 'amendment text, if any',
149   `hash` varchar(255) NOT NULL COMMENT 'hash of signed data',
150   `signature_hash` varchar(255) NOT NULL COMMENT 'hash of signature itself',
151   PRIMARY KEY (`id`),
152   KEY `tid` (`tid`),
153   KEY `table` (`table`)
154 ) ENGINE=InnoDB AUTO_INCREMENT=1 ;
155 #EndIf
157 #IfMissingColumn layout_options list_backup_id
158 ALTER TABLE `layout_options` ADD COLUMN `list_backup_id` VARCHAR(31) NOT NULL DEFAULT '';
159 UPDATE `layout_options` SET `list_backup_id` = 'ethrace' WHERE `layout_options`.`form_id` = 'DEM' AND `layout_options`.`field_id` = 'ethnicity';
160 UPDATE `layout_options` SET `list_backup_id` = 'ethrace' WHERE `layout_options`.`form_id` = 'DEM' AND `layout_options`.`field_id` = 'race';
161 #EndIf
163 UPDATE `layout_options` SET `data_type` = '36' WHERE `layout_options`.`form_id` = 'DEM' AND `layout_options`.`field_id` = 'race';
164 UPDATE `layout_options` SET `data_type` = '1', `datacols` = '3' WHERE `layout_options`.`form_id` = 'DEM' AND `layout_options`.`field_id` = 'language';
167 #IfNotTable modules
168 CREATE TABLE `modules` (
169   `mod_id` INT(11) NOT NULL AUTO_INCREMENT,
170   `mod_name` VARCHAR(64) NOT NULL DEFAULT '0',
171   `mod_directory` VARCHAR(64) NOT NULL DEFAULT '',
172   `mod_parent` VARCHAR(64) NOT NULL DEFAULT '',
173   `mod_type` VARCHAR(64) NOT NULL DEFAULT '',
174   `mod_active` INT(1) UNSIGNED NOT NULL DEFAULT '0',
175   `mod_ui_name` VARCHAR(20) NOT NULL DEFAULT '''',
176   `mod_relative_link` VARCHAR(64) NOT NULL DEFAULT '',
177   `mod_ui_order` TINYINT(3) NOT NULL DEFAULT '0',
178   `mod_ui_active` INT(1) UNSIGNED NOT NULL DEFAULT '0',
179   `mod_description` VARCHAR(255) NOT NULL DEFAULT '',
180   `mod_nick_name` VARCHAR(25) NOT NULL DEFAULT '',
181   `mod_enc_menu` VARCHAR(10) NOT NULL DEFAULT 'no',
182   `permissions_item_table` CHAR(100) DEFAULT NULL,
183   `directory` VARCHAR(255) NOT NULL,
184   `date` DATETIME NOT NULL,
185   `sql_run` TINYINT(4) DEFAULT '0',
186   `type` TINYINT(4) DEFAULT '0',
187   PRIMARY KEY (`mod_id`,`mod_directory`)
188 ) ENGINE=InnoDB;
189 #EndIf
191 #IfNotTable module_acl_group_settings
192 CREATE TABLE `module_acl_group_settings` (
193   `module_id` int(11) NOT NULL,
194   `group_id` int(11) NOT NULL,
195   `section_id` int(11) NOT NULL,
196   `allowed` tinyint(1) DEFAULT NULL,
197   PRIMARY KEY (`module_id`,`group_id`,`section_id`)
198 ) ENGINE=InnoDB;
199 #EndIf
201 #IfNotTable module_acl_sections
202 CREATE TABLE `module_acl_sections` (
203   `section_id` int(11) DEFAULT NULL,
204   `section_name` varchar(255) DEFAULT NULL,
205   `parent_section` int(11) DEFAULT NULL,
206   `section_identifier` varchar(50) DEFAULT NULL,
207   `module_id` int(11) DEFAULT NULL
208 ) ENGINE=InnoDB;
209 #EndIf
211 #IfNotTable module_acl_user_settings
212 CREATE TABLE `module_acl_user_settings` (
213   `module_id` int(11) NOT NULL,
214   `user_id` int(11) NOT NULL,
215   `section_id` int(11) NOT NULL,
216   `allowed` int(1) DEFAULT NULL,
217   PRIMARY KEY (`module_id`,`user_id`,`section_id`)
218 ) ENGINE=InnoDB;
219 #EndIf
221 #IfNotTable module_configuration
222 CREATE TABLE `module_configuration` (
223   `module_config_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
224   `module_id` int(10) unsigned NOT NULL,
225   `field_name` varchar(45) NOT NULL,
226   `field_value` varchar(255) NOT NULL,
227   PRIMARY KEY (`module_config_id`)
228 ) ENGINE=InnoDB;
229 #EndIf
231 #IfNotTable modules_hooks_settings
232 CREATE TABLE `modules_hooks_settings` (
233   `id` int(11) NOT NULL AUTO_INCREMENT,
234   `mod_id` int(11) DEFAULT NULL,
235   `enabled_hooks` varchar(255) DEFAULT NULL,
236   `attached_to` varchar(45) DEFAULT NULL,
237   PRIMARY KEY (`id`)
238 ) ENGINE=InnoDB;
239 #EndIf
241 #IfNotTable modules_settings
242 CREATE TABLE `modules_settings` (
243   `mod_id` INT(11) DEFAULT NULL,
244   `fld_type` SMALLINT(6) DEFAULT NULL COMMENT '1=>ACL,2=>preferences,3=>hooks',
245   `obj_name` VARCHAR(255) DEFAULT NULL,
246   `menu_name` VARCHAR(255) DEFAULT NULL,
247   `path` VARCHAR(255) DEFAULT NULL
248 ) ENGINE=InnoDB;
249 #EndIf