Updated Acknowledgments page
[openemr.git] / sql / 4_1_0-to-4_1_1_upgrade.sql
blobdf679f38b50ba61cd350af487500cdf1184297e1
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.
61 #IfNotIndex lists type
62 CREATE INDEX `type` ON `lists` (`type`);
63 #EndIf
65 #IfNotIndex lists pid
66 CREATE INDEX `pid` ON `lists` (`pid`);
67 #EndIf
69 #IfNotIndex form_vitals pid
70 CREATE INDEX `pid` ON `form_vitals` (`pid`);
71 #EndIf
73 #IfIndex forms pid
74 DROP INDEX `pid` ON `forms`;
75 #EndIf
77 #IfIndex form_encounter pid
78 DROP INDEX `pid` ON `form_encounter`;
79 #EndIf
81 #IfNotIndex forms pid_encounter
82 CREATE INDEX `pid_encounter` ON `forms` (`pid`, `encounter`);
83 #EndIf
85 #IfNotIndex form_encounter pid_encounter
86 CREATE INDEX `pid_encounter` ON `form_encounter` (`pid`, `encounter`);
87 #EndIf
89 #IfNotIndex immunizations patient_id
90 CREATE INDEX `patient_id` ON `immunizations` (`patient_id`);
91 #EndIf
93 #IfNotIndex procedure_order patient_id
94 CREATE INDEX `patient_id` ON `procedure_order` (`patient_id`);
95 #EndIf
97 #IfNotIndex pnotes pid
98 CREATE INDEX `pid` ON `pnotes` (`pid`);
99 #EndIf
101 #IfNotIndex transactions pid
102 CREATE INDEX `pid` ON `transactions` (`pid`);
103 #EndIf
105 #IfNotIndex extended_log patient_id
106 CREATE INDEX `patient_id` ON `extended_log` (`patient_id`);
107 #EndIf
109 #IfNotIndex prescriptions patient_id
110 CREATE INDEX `patient_id` ON `prescriptions` (`patient_id`);
111 #EndIf
113 #IfNotIndex openemr_postcalendar_events pc_eventDate
114 CREATE INDEX `pc_eventDate` ON `openemr_postcalendar_events` (`pc_eventDate`);
115 #EndIf
117 #IfMissingColumn version v_realpatch
118 ALTER TABLE `version` ADD COLUMN `v_realpatch` int(11) NOT NULL DEFAULT 0;
119 #EndIf
121 #IfMissingColumn prescriptions drug_info_erx
122 ALTER TABLE `prescriptions` ADD COLUMN `drug_info_erx` TEXT DEFAULT NULL;
123 #EndIf
125 #IfNotRow2D list_options list_id lists option_id nation_notes_replace_buttons
126 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`) VALUES ('lists','nation_notes_replace_buttons','Nation Notes Replace Buttons',1);
127 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`) VALUES ('nation_notes_replace_buttons','Yes','Yes',10);
128 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`) VALUES ('nation_notes_replace_buttons','No','No',20);
129 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`) VALUES ('nation_notes_replace_buttons','Normal','Normal',30);
130 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`) VALUES ('nation_notes_replace_buttons','Abnormal','Abnormal',40);
131 #EndIf
133 #IfMissingColumn insurance_data policy_type
134 ALTER TABLE `insurance_data` ADD COLUMN `policy_type` varchar(25) NOT NULL default '';
135 #EndIf
137 #IfMissingColumn drugs max_level
138 ALTER TABLE drugs ADD max_level float NOT NULL DEFAULT 0.0;
139 ALTER TABLE drugs CHANGE reorder_point reorder_point float NOT NULL DEFAULT 0.0;
140 #EndIf
142 #IfNotTable product_warehouse
143 CREATE TABLE `product_warehouse` (
144   `pw_drug_id`   int(11) NOT NULL,
145   `pw_warehouse` varchar(31) NOT NULL,
146   `pw_min_level` float       DEFAULT 0,
147   `pw_max_level` float       DEFAULT 0,
148   PRIMARY KEY  (`pw_drug_id`,`pw_warehouse`)
149 ) ENGINE=MyISAM;
150 #EndIf
152 #IfNotColumnType billing modifier varchar(12)
153    ALTER TABLE `billing` MODIFY `modifier` varchar(12);
154    UPDATE `code_types` SET `ct_mod` = '12' where ct_key = 'CPT4' OR ct_key = 'HCPCS';
155 #Endif
157 #IfMissingColumn billing notecodes
158 ALTER TABLE `billing` ADD `notecodes` varchar(25) NOT NULL default '';
159 #EndIf
161 #IfNotTable dated_reminders
162 CREATE TABLE `dated_reminders` (
163             `dr_id` int(11) NOT NULL AUTO_INCREMENT,
164             `dr_from_ID` int(11) NOT NULL,
165             `dr_message_text` varchar(160) NOT NULL,
166             `dr_message_sent_date` datetime NOT NULL,
167             `dr_message_due_date` date NOT NULL,
168             `pid` int(11) NOT NULL,
169             `message_priority` tinyint(1) NOT NULL,
170             `message_processed` tinyint(1) NOT NULL DEFAULT '0',
171             `processed_date` timestamp NULL DEFAULT NULL,
172             `dr_processed_by` int(11) NOT NULL,
173             PRIMARY KEY (`dr_id`),
174             KEY `dr_from_ID` (`dr_from_ID`,`dr_message_due_date`)
175           ) ENGINE=MyISAM AUTO_INCREMENT=1;
176 #EndIf
178 #IfNotTable dated_reminders_link
179 CREATE TABLE `dated_reminders_link` (
180             `dr_link_id` int(11) NOT NULL AUTO_INCREMENT,
181             `dr_id` int(11) NOT NULL,
182             `to_id` int(11) NOT NULL,
183             PRIMARY KEY (`dr_link_id`),
184             KEY `to_id` (`to_id`),
185             KEY `dr_id` (`dr_id`)
186           ) ENGINE=MyISAM AUTO_INCREMENT=1;
187 #EndIf
189 #IfMissingColumn x12_partners x12_gs03
190 ALTER TABLE `x12_partners` ADD COLUMN `x12_gs03` VARCHAR(15) NOT NULL DEFAULT '';
191 #EndIf
193 #IfNotTable payment_gateway_details
194 CREATE TABLE `payment_gateway_details` (
195   `id` int(11) NOT NULL AUTO_INCREMENT,
196   `service_name` varchar(100) DEFAULT NULL,
197   `login_id` varchar(255) DEFAULT NULL,
198   `transaction_key` varchar(255) DEFAULT NULL,
199   `md5` varchar(255) DEFAULT NULL,
200   PRIMARY KEY (`id`)
201 ) ENGINE=InnoDB;
202 #EndIf
204 #IfNotRow2D list_options list_id lists option_id payment_gateways
205 insert into `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`) values('lists','payment_gateways','Payment Gateways','297','1','0','','');
206 insert into `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`) values('payment_gateways','authorize_net','Authorize.net','1','0','0','','');
207 #EndIf
209 #IfNotRow2D list_options list_id payment_method option_id authorize_net
210 insert into `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`) values('payment_method','authorize_net','Authorize.net','60','0','0','','');
211 #EndIf
213 #IfMissingColumn patient_access_offsite authorize_net_id
214 ALTER TABLE `patient_access_offsite` ADD COLUMN `authorize_net_id` VARCHAR(20) COMMENT 'authorize.net profile id';
215 #EndIf
217 #IfMissingColumn facility website
218 ALTER TABLE `facility` ADD COLUMN `website` varchar(255) default NULL;
219 #EndIf
221 #IfMissingColumn facility email
222 ALTER TABLE `facility` ADD COLUMN `email` varchar(255) default NULL;
223 #EndIf
225 #IfMissingColumn code_types ct_active
226 ALTER TABLE `code_types` ADD COLUMN `ct_active` tinyint(1) NOT NULL default 1 COMMENT '1 if this is active';
227 #EndIf
229 #IfMissingColumn code_types ct_label
230 ALTER TABLE `code_types` ADD COLUMN `ct_label` varchar(31) NOT NULL default '' COMMENT 'label of this code type';
231 UPDATE `code_types` SET ct_label = ct_key;
232 #EndIf
234 #IfMissingColumn code_types ct_external
235 ALTER TABLE `code_types` ADD COLUMN `ct_external` tinyint(1) NOT NULL default 0 COMMENT '0 if stored codes in codes tables, 1 or greater if codes stored in external tables';
236 #EndIf
238 #IfNotRow code_types ct_key DSMIV
239 DROP TABLE IF EXISTS `temp_table_one`;
240 CREATE TABLE `temp_table_one` (
241   `id` int(11) NOT NULL DEFAULT '0',
242   `seq` int(11) NOT NULL DEFAULT '0'
243 ) ENGINE=MyISAM ;
244 INSERT INTO `temp_table_one` (`id`, `seq`) VALUES ( IF( ((SELECT MAX(`ct_id`) FROM `code_types`)>=100), ((SELECT MAX(`ct_id`) FROM `code_types`) + 1), 100 ) , IF( ((SELECT MAX(`ct_seq`) FROM `code_types`)>=100), ((SELECT MAX(`ct_seq`) FROM `code_types`) + 1), 100 )  );
245 INSERT INTO code_types (ct_key, ct_id, ct_seq, ct_mod, ct_just, ct_fee, ct_rel, ct_nofs, ct_diag, ct_active, ct_label, ct_external ) VALUES ('DSMIV' , (SELECT MAX(`id`) FROM `temp_table_one`), (SELECT MAX(`seq`) FROM `temp_table_one`), 2, '', 0, 0, 0, 1, 0, 'DSMIV', 0);
246 DROP TABLE `temp_table_one`;
247 #EndIf
249 #IfNotRow code_types ct_key ICD10
250 DROP TABLE IF EXISTS `temp_table_one`;
251 CREATE TABLE `temp_table_one` (
252   `id` int(11) NOT NULL DEFAULT '0',
253   `seq` int(11) NOT NULL DEFAULT '0'
254 ) ENGINE=MyISAM ;
255 INSERT INTO `temp_table_one` (`id`, `seq`) VALUES ( IF( ((SELECT MAX(`ct_id`) FROM `code_types`)>=100), ((SELECT MAX(`ct_id`) FROM `code_types`) + 1), 100 ) , IF( ((SELECT MAX(`ct_seq`) FROM `code_types`)>=100), ((SELECT MAX(`ct_seq`) FROM `code_types`) + 1), 100 )  );
256 INSERT INTO code_types (ct_key, ct_id, ct_seq, ct_mod, ct_just, ct_fee, ct_rel, ct_nofs, ct_diag, ct_active, ct_label, ct_external ) VALUES ('ICD10' , (SELECT MAX(`id`) FROM `temp_table_one`), (SELECT MAX(`seq`) FROM `temp_table_one`), 2, '', 0, 0, 0, 1, 0, 'ICD10', 1);
257 DROP TABLE `temp_table_one`;
258 #EndIf
260 #IfNotRow code_types ct_key SNOMED
261 DROP TABLE IF EXISTS `temp_table_one`;
262 CREATE TABLE `temp_table_one` (
263   `id` int(11) NOT NULL DEFAULT '0',
264   `seq` int(11) NOT NULL DEFAULT '0'
265 ) ENGINE=MyISAM ;
266 INSERT INTO `temp_table_one` (`id`, `seq`) VALUES ( IF( ((SELECT MAX(`ct_id`) FROM `code_types`)>=100), ((SELECT MAX(`ct_id`) FROM `code_types`) + 1), 100 ) , IF( ((SELECT MAX(`ct_seq`) FROM `code_types`)>=100), ((SELECT MAX(`ct_seq`) FROM `code_types`) + 1), 100 )  );
267 INSERT INTO code_types (ct_key, ct_id, ct_seq, ct_mod, ct_just, ct_fee, ct_rel, ct_nofs, ct_diag, ct_active, ct_label, ct_external ) VALUES ('SNOMED' , (SELECT MAX(`id`) FROM `temp_table_one`), (SELECT MAX(`seq`) FROM `temp_table_one`), 2, '', 0, 0, 0, 1, 0, 'SNOMED', 2);
268 DROP TABLE `temp_table_one`;
269 #EndIf
271 #IfMissingColumn ar_activity code_type
272 ALTER TABLE `ar_activity` ADD COLUMN `code_type` varchar(12) NOT NULL DEFAULT '';
273 #EndIf
275 #IfRow2D billing code_type COPAY activity 1
276 DROP TABLE IF EXISTS `temp_table_one`;
277 CREATE TABLE `temp_table_one` (
278   id             int unsigned  NOT NULL AUTO_INCREMENT,
279   session_id     int unsigned  NOT NULL,
280   payer_id       int(11)       NOT NULL DEFAULT 0,
281   user_id        int(11)       NOT NULL,
282   pay_total      decimal(12,2) NOT NULL DEFAULT 0,
283   payment_type varchar( 50 ) NOT NULL DEFAULT 'patient',
284   description text NOT NULL,
285   adjustment_code varchar( 50 ) NOT NULL DEFAULT 'patient_payment',
286   post_to_date date NOT NULL,
287   patient_id int( 11 ) NOT NULL,
288   payment_method varchar( 25 ) NOT NULL DEFAULT 'cash',
289   pid            int(11)       NOT NULL,
290   encounter      int(11)       NOT NULL,
291   code_type      varchar(12)   NOT NULL DEFAULT '',
292   code           varchar(9)    NOT NULL,
293   modifier       varchar(5)    NOT NULL DEFAULT '',
294   payer_type     int           NOT NULL DEFAULT 0,
295   post_time      datetime      NOT NULL,
296   post_user      int(11)       NOT NULL,
297   pay_amount     decimal(12,2) NOT NULL DEFAULT 0,
298   account_code varchar(15) NOT NULL DEFAULT 'PCP',
299   PRIMARY KEY (id)
300 ) ENGINE=MyISAM AUTO_INCREMENT=1;
301 INSERT INTO `temp_table_one` (`user_id`, `pay_total`, `patient_id`, `post_to_date`, `pid`, `encounter`, `post_time`, `post_user`, `pay_amount`, `description`) SELECT `user`, (`fee`*-1), `pid`, `date`, `pid`, `encounter`, `date`, `user`, (`fee`*-1), 'COPAY' FROM `billing` WHERE `code_type`='COPAY' AND `activity`!=0;
302 UPDATE `temp_table_one` SET `session_id`= ((SELECT MAX(session_id) FROM ar_session)+`id`);
303 UPDATE `billing`, `code_types`, `temp_table_one` SET temp_table_one.code_type=billing.code_type, temp_table_one.code=billing.code, temp_table_one.modifier=billing.modifier WHERE billing.code_type=code_types.ct_key AND code_types.ct_fee=1 AND temp_table_one.pid=billing.pid AND temp_table_one.encounter=billing.encounter AND billing.activity!=0;
304 INSERT INTO `ar_session` (`payer_id`, `user_id`, `pay_total`, `payment_type`, `description`, `patient_id`, `payment_method`, `adjustment_code`, `post_to_date`) SELECT `payer_id`, `user_id`, `pay_total`, `payment_type`, `description`, `patient_id`, `payment_method`, `adjustment_code`, `post_to_date` FROM `temp_table_one`;
305 INSERT INTO `ar_activity` (`pid`, `encounter`, `code_type`, `code`, `modifier`, `payer_type`, `post_time`, `post_user`, `session_id`, `pay_amount`, `account_code`) SELECT `pid`, `encounter`, `code_type`, `code`, `modifier`, `payer_type`, `post_time`, `post_user`, `session_id`, `pay_amount`, `account_code` FROM `temp_table_one`;
306 UPDATE `billing` SET `activity`=0 WHERE `code_type`='COPAY';
307 DROP TABLE IF EXISTS `temp_table_one`;
308 #EndIf
310 #IfNotTable facility_user_ids
311 CREATE TABLE  `facility_user_ids` (
312   `id` bigint(20) NOT NULL AUTO_INCREMENT,
313   `uid` bigint(20) DEFAULT NULL,
314   `facility_id` bigint(20) DEFAULT NULL,
315   `field_id`    varchar(31)  NOT NULL COMMENT 'references layout_options.field_id',
316   `field_value` TEXT NOT NULL,
317   PRIMARY KEY (`id`),
318   KEY `uid` (`uid`,`facility_id`,`field_id`)
319 ) ENGINE=MyISAM  AUTO_INCREMENT=1 ;
320 #EndIf
322 #IfNotRow layout_options form_id FACUSR
323 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) VALUES ('FACUSR', 'provider_id', '1General', 'Provider ID', 1, 2, 1, 15, 63, '', 1, 1, '', '', 'Provider ID at Specified Facility');
324 #EndIf
326 #IfMissingColumn patient_data ref_providerID
327 ALTER TABLE `patient_data` ADD COLUMN `ref_providerID` int(11) default NULL;
328 UPDATE `patient_data` SET `ref_providerID`=`providerID`;
329 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) VALUES ('DEM', 'ref_providerID', '3Choices', 'Referring Provider', 2, 11, 1, 0, 0, '', 1, 3, '', '', 'Referring Provider');
330 UPDATE `layout_options` SET `description`='Provider' WHERE `form_id`='DEM' AND `field_id`='providerID';
331 UPDATE `layout_options` SET `seq`=(1+`seq`) WHERE `form_id`='DEM' AND `group_name` LIKE '%Choices' AND `field_id` != 'providerID' AND `field_id` != 'ref_providerID';
332 #EndIf
334 #IfMissingColumn documents couch_docid
335 ALTER TABLE `documents` ADD COLUMN `couch_docid` VARCHAR(100) NULL;
336 #EndIf
338 #IfMissingColumn documents couch_revid
339 ALTER TABLE `documents` ADD COLUMN `couch_revid` VARCHAR(100) NULL;
340 #EndIf
342 #IfMissingColumn documents storagemethod
343 ALTER TABLE `documents` ADD COLUMN `storagemethod` TINYINT(4) DEFAULT '0' NOT NULL COMMENT '0->Harddisk,1->CouchDB';
344 #EndIf
346 #IfNotRow2D list_options list_id lists option_id ptlistcols
347 insert into list_options (list_id, option_id, title, seq, option_value, mapping, notes) values('lists','ptlistcols','Patient List Columns','1','0','','');
348 insert into list_options (list_id, option_id, title, seq, option_value, mapping, notes) values('ptlistcols','name'      ,'Full Name'     ,'10','3','','');
349 insert into list_options (list_id, option_id, title, seq, option_value, mapping, notes) values('ptlistcols','phone_home','Home Phone'    ,'20','3','','');
350 insert into list_options (list_id, option_id, title, seq, option_value, mapping, notes) values('ptlistcols','ss'        ,'SSN'           ,'30','3','','');
351 insert into list_options (list_id, option_id, title, seq, option_value, mapping, notes) values('ptlistcols','DOB'       ,'Date of Birth' ,'40','3','','');
352 insert into list_options (list_id, option_id, title, seq, option_value, mapping, notes) values('ptlistcols','pubpid'    ,'External ID'   ,'50','3','','');
353 #EndIf
355 #IfNotRow2D code_types ct_key DSMIV ct_mod 0
356 UPDATE `code_types` SET `ct_mod`=0 WHERE `ct_key`='DSMIV' OR `ct_key`='ICD9' OR `ct_key`='ICD10' OR `ct_key`='SNOMED';
357 #EndIf
359 #IfMissingColumn layout_options fld_rows
360 ALTER TABLE `layout_options` ADD COLUMN `fld_rows` int(11) NOT NULL default '0';
361 UPDATE `layout_options` SET `fld_rows`=max_length WHERE `data_type`='3';
362 UPDATE `layout_options` SET `max_length`='0' WHERE `data_type`='3';
363 UPDATE `layout_options` SET `max_length`='0' WHERE `data_type`='34';
364 UPDATE `layout_options` SET `max_length`='20' WHERE `field_id`='financial_review' AND `form_id`='DEM';
365 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='history_father' AND `form_id`='HIS';
366 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='history_mother' AND `form_id`='HIS';
367 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='history_siblings' AND `form_id`='HIS';
368 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='history_spouse' AND `form_id`='HIS';
369 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='history_offspring' AND `form_id`='HIS';
370 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='relatives_cancer' AND `form_id`='HIS';
371 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='relatives_tuberculosis' AND `form_id`='HIS';
372 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='relatives_diabetes' AND `form_id`='HIS';
373 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='relatives_high_blood_pressure' AND `form_id`='HIS';
374 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='relatives_heart_problems' AND `form_id`='HIS';
375 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='relatives_stroke' AND `form_id`='HIS';
376 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='relatives_epilepsy' AND `form_id`='HIS';
377 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='relatives_mental_illness' AND `form_id`='HIS';
378 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='relatives_suicide' AND `form_id`='HIS';
379 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='coffee' AND `form_id`='HIS';
380 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='tobacco' AND `form_id`='HIS';
381 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='alcohol' AND `form_id`='HIS';
382 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='recreational_drugs' AND `form_id`='HIS';
383 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='counseling' AND `form_id`='HIS';
384 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='exercise_patterns' AND `form_id`='HIS';
385 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='hazardous_activities' AND `form_id`='HIS';
386 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='sleep_patterns' AND `form_id`='HIS';
387 UPDATE `layout_options` SET `max_length`='0' WHERE `field_id`='seatbelt_use' AND `form_id`='HIS';
388 #EndIf
390 #IfNotColumnType history_data usertext11 TEXT
391 ALTER TABLE `history_data` CHANGE `usertext11` `usertext11` TEXT NOT NULL;
392 #EndIf
394 #IfMissingColumn x12_partners x12_isa01
395 ALTER TABLE x12_partners ADD COLUMN x12_isa01 VARCHAR( 2 ) NOT NULL DEFAULT '00' COMMENT 'User logon Required Indicator';
396 #EndIf
398 #IfMissingColumn x12_partners x12_isa02
399 ALTER TABLE x12_partners ADD COLUMN x12_isa02 VARCHAR( 10 ) NOT NULL DEFAULT '          ' COMMENT 'User Logon';
400 #EndIf
402 #IfMissingColumn x12_partners x12_isa03
403 ALTER TABLE x12_partners ADD COLUMN x12_isa03 VARCHAR( 2 ) NOT NULL DEFAULT '00' COMMENT 'User password required Indicator';
404 #EndIf
406 #IfMissingColumn x12_partners x12_isa04
407 ALTER TABLE x12_partners ADD COLUMN x12_isa04 VARCHAR( 10 ) NOT NULL DEFAULT '          ' COMMENT 'User Password';
408 #EndIf
410 #IfMissingColumn codes financial_reporting
411 ALTER TABLE `codes` ADD COLUMN `financial_reporting` TINYINT(1) DEFAULT 0 COMMENT '0 = negative, 1 = considered important code in financial reporting';
412 #EndIf
414 #IfNotColumnType codes code_type smallint(6)
415 ALTER TABLE `codes` CHANGE `code_type` `code_type` SMALLINT(6) default NULL;
416 #EndIf
418 #IfNotIndex codes code_type
419 CREATE INDEX `code_type` ON `codes` (`code_type`);
420 #EndIf
422 #IfNotColumnType billing code_type varchar(15)
423 ALTER TABLE `billing` CHANGE `code_type` `code_type` VARCHAR(15) default NULL;
424 #EndIf
426 #IfNotColumnType codes modifier varchar(12)
427 ALTER TABLE `codes` CHANGE `modifier` `modifier` VARCHAR(12) NOT NULL default '';
428 #EndIf
430 #IfNotColumnType ar_activity modifier varchar(12)
431 ALTER TABLE `ar_activity` CHANGE `modifier` `modifier` VARCHAR(12) NOT NULL default '';
432 #EndIf
434 #IfNotRow code_types ct_key CPTII
435 DROP TABLE IF EXISTS `temp_table_one`;
436 CREATE TABLE `temp_table_one` (
437   `id` int(11) NOT NULL DEFAULT '0',
438   `seq` int(11) NOT NULL DEFAULT '0'
439 ) ENGINE=MyISAM ;
440 INSERT INTO `temp_table_one` (`id`, `seq`) VALUES ( IF( ((SELECT MAX(`ct_id`) FROM `code_types`)>=100), ((SELECT MAX(`ct_id`) FROM `code_types`) + 1), 100 ) , IF( ((SELECT MAX(`ct_seq`) FROM `code_types`)>=100), ((SELECT MAX(`ct_seq`) FROM `code_types`) + 1), 100 )  );
441 INSERT INTO code_types (ct_key, ct_id, ct_seq, ct_mod, ct_just, ct_fee, ct_rel, ct_nofs, ct_diag, ct_active, ct_label, ct_external ) VALUES ('CPTII' , (SELECT MAX(`id`) FROM `temp_table_one`), (SELECT MAX(`seq`) FROM `temp_table_one`), 12, 'ICD9', 1, 0, 0, 0, 0, 'CPTII', 0);
442 DROP TABLE `temp_table_one`;
443 #EndIf
445 #IfNotRow code_types ct_key ICD9-SG
446 DROP TABLE IF EXISTS `temp_table_one`;
447 CREATE TABLE `temp_table_one` (
448   `id` int(11) NOT NULL DEFAULT '0',
449   `seq` int(11) NOT NULL DEFAULT '0'
450 ) ENGINE=MyISAM ;
451 INSERT INTO `temp_table_one` (`id`, `seq`) VALUES ( IF( ((SELECT MAX(`ct_id`) FROM `code_types`)>=100), ((SELECT MAX(`ct_id`) FROM `code_types`) + 1), 100 ) , IF( ((SELECT MAX(`ct_seq`) FROM `code_types`)>=100), ((SELECT MAX(`ct_seq`) FROM `code_types`) + 1), 100 )  );
452 INSERT INTO code_types (ct_key, ct_id, ct_seq, ct_mod, ct_just, ct_fee, ct_rel, ct_nofs, ct_diag, ct_active, ct_label, ct_external ) VALUES ('ICD9-SG' , (SELECT MAX(`id`) FROM `temp_table_one`), (SELECT MAX(`seq`) FROM `temp_table_one`), 12, 'ICD9', 1, 0, 0, 0, 0, 'ICD9 Procedure/Service', 5);
453 DROP TABLE `temp_table_one`;
454 #EndIf
456 #IfNotRow code_types ct_key ICD10-PCS
457 DROP TABLE IF EXISTS `temp_table_one`;
458 CREATE TABLE `temp_table_one` (
459   `id` int(11) NOT NULL DEFAULT '0',
460   `seq` int(11) NOT NULL DEFAULT '0'
461 ) ENGINE=MyISAM ;
462 INSERT INTO `temp_table_one` (`id`, `seq`) VALUES ( IF( ((SELECT MAX(`ct_id`) FROM `code_types`)>=100), ((SELECT MAX(`ct_id`) FROM `code_types`) + 1), 100 ) , IF( ((SELECT MAX(`ct_seq`) FROM `code_types`)>=100), ((SELECT MAX(`ct_seq`) FROM `code_types`) + 1), 100 )  );
463 INSERT INTO code_types (ct_key, ct_id, ct_seq, ct_mod, ct_just, ct_fee, ct_rel, ct_nofs, ct_diag, ct_active, ct_label, ct_external ) VALUES ('ICD10-PCS' , (SELECT MAX(`id`) FROM `temp_table_one`), (SELECT MAX(`seq`) FROM `temp_table_one`), 12, 'ICD10', 1, 0, 0, 0, 0, 'ICD10 Procedure/Service', 6);
464 DROP TABLE `temp_table_one`;
465 UPDATE `code_types` SET `ct_label`='ICD9 Diagnosis' WHERE `ct_key`='ICD9';
466 UPDATE `code_types` SET `ct_label`='CPT4 Procedure/Service' WHERE `ct_key`='CPT4';
467 UPDATE `code_types` SET `ct_label`='HCPCS Procedure/Service' WHERE `ct_key`='HCPCS';
468 UPDATE `code_types` SET `ct_label`='CVX Immunization' WHERE `ct_key`='CVX';
469 UPDATE `code_types` SET `ct_label`='DSMIV Diagnosis' WHERE `ct_key`='DSMIV';
470 UPDATE `code_types` SET `ct_label`='ICD10 Diagnosis' WHERE `ct_key`='ICD10';
471 UPDATE `code_types` SET `ct_label`='SNOMED Diagnosis' WHERE `ct_key`='SNOMED';
472 #EndIf
474 #IfMissingColumn code_types ct_claim
475 ALTER TABLE `code_types` ADD COLUMN `ct_claim` tinyint(1) NOT NULL default 0 COMMENT '1 if this is used in claims';
476 UPDATE `code_types` SET `ct_claim`='1' WHERE `ct_key`='ICD9' OR `ct_key`='CPT4' OR `ct_key`='HCPCS' OR `ct_key`='DSMIV' OR `ct_key`='ICD10' OR `ct_key`='SNOMED' OR `ct_key`='CPTII' OR `ct_key`='ICD9-SG' OR `ct_key`='ICD10-PCS';
477 UPDATE `code_types` SET `ct_fee`='0', `ct_mod`='0', `ct_label`='CPTII Performance Measures' WHERE `ct_key`='CPTII';
478 #EndIf
480 #IfNotTable icd9_dx_code
481 CREATE TABLE `icd9_dx_code` (
482   `dx_id` SERIAL,
483   `dx_code`             varchar(5),
484   `formatted_dx_code`   varchar(6),
485   `short_desc`          varchar(60),
486   `long_desc`           varchar(300),
487   `active` tinyint default 0,
488   `revision` int default 0,
489   KEY `dx_code` (`dx_code`),
490   KEY `formatted_dx_code` (`formatted_dx_code`),
491   KEY `active` (`active`)
492 ) ENGINE=MyISAM;
493 #EndIf
495 #IfNotTable icd9_sg_code
496 CREATE TABLE `icd9_sg_code` (
497   `sg_id` SERIAL,
498   `sg_code`             varchar(5),
499   `formatted_sg_code`   varchar(6),
500   `short_desc`          varchar(60),
501   `long_desc`           varchar(300),
502   `active` tinyint default 0,
503   `revision` int default 0,
504   KEY `sg_code` (`sg_code`),
505   KEY `formatted_sg_code` (`formatted_sg_code`),
506   KEY `active` (`active`)
507 ) ENGINE=MyISAM;
508 #EndIf
510 #IfNotTable icd9_dx_long_code
511 CREATE TABLE `icd9_dx_long_code` (
512   `dx_id` SERIAL,
513   `dx_code`             varchar(5),
514   `long_desc`           varchar(300),
515   `active` tinyint default 0,
516   `revision` int default 0
517 ) ENGINE=MyISAM;
518 #EndIf
520 #IfNotTable icd9_sg_long_code
521 CREATE TABLE `icd9_sg_long_code` (
522   `sq_id` SERIAL,
523   `sg_code`             varchar(5),
524   `long_desc`           varchar(300),
525   `active` tinyint default 0,
526   `revision` int default 0
527 ) ENGINE=MyISAM;
528 #EndIf
530 #IfNotTable icd10_dx_order_code
531 CREATE TABLE `icd10_dx_order_code` (
532   `dx_id`               SERIAL,
533   `dx_code`             varchar(7),
534   `formatted_dx_code`   varchar(10),
535   `valid_for_coding`    char,
536   `short_desc`          varchar(60),
537   `long_desc`           varchar(300),
538   `active` tinyint default 0,
539   `revision` int default 0,
540   KEY `formatted_dx_code` (`formatted_dx_code`),
541   KEY `active` (`active`)
542 ) ENGINE=MyISAM;
543 #EndIf
545 #IfNotTable icd10_pcs_order_code
546 CREATE TABLE `icd10_pcs_order_code` (
547   `pcs_id`              SERIAL,
548   `pcs_code`            varchar(7),
549   `valid_for_coding`    char,
550   `short_desc`          varchar(60),
551   `long_desc`           varchar(300),
552   `active` tinyint default 0,
553   `revision` int default 0,
554   KEY `pcs_code` (`pcs_code`),
555   KEY `active` (`active`)
556 ) ENGINE=MyISAM;
557 #EndIf
559 #IfNotTable icd10_gem_pcs_9_10
560 CREATE TABLE `icd10_gem_pcs_9_10` (
561   `map_id` SERIAL,
562   `pcs_icd9_source` varchar(5) default NULL,
563   `pcs_icd10_target` varchar(7) default NULL,
564   `flags` varchar(5) default NULL,
565   `active` tinyint default 0,
566   `revision` int default 0
567 ) ENGINE=MyISAM;
568 #EndIf
570 #IfNotTable icd10_gem_pcs_10_9
571 CREATE TABLE `icd10_gem_pcs_10_9` (
572   `map_id` SERIAL,
573   `pcs_icd10_source` varchar(7) default NULL,
574   `pcs_icd9_target` varchar(5) default NULL,
575   `flags` varchar(5) default NULL,
576   `active` tinyint default 0,
577   `revision` int default 0
578 ) ENGINE=MyISAM;
579 #EndIf
581 #IfNotTable icd10_gem_dx_9_10
582 DROP TABLE IF EXISTS `icd10_gem_dx_9_10`;
583 CREATE TABLE `icd10_gem_dx_9_10` (
584   `map_id` SERIAL,
585   `dx_icd9_source` varchar(5) default NULL,
586   `dx_icd10_target` varchar(7) default NULL,
587   `flags` varchar(5) default NULL,
588   `active` tinyint default 0,
589   `revision` int default 0
590 ) ENGINE=MyISAM;
591 #EndIf
593 #IfNotTable icd10_gem_dx_10_9
594 CREATE TABLE `icd10_gem_dx_10_9` (
595   `map_id` SERIAL,
596   `dx_icd10_source` varchar(7) default NULL,
597   `dx_icd9_target` varchar(5) default NULL,
598   `flags` varchar(5) default NULL,
599   `active` tinyint default 0,
600   `revision` int default 0
601 ) ENGINE=MyISAM;
602 #EndIf
604 #IfNotTable icd10_reimbr_dx_9_10
605 CREATE TABLE `icd10_reimbr_dx_9_10` (
606   `map_id` SERIAL,
607   `code`        varchar(8),
608   `code_cnt`    tinyint,
609   `ICD9_01`     varchar(5),
610   `ICD9_02`     varchar(5),
611   `ICD9_03`     varchar(5),
612   `ICD9_04`     varchar(5),
613   `ICD9_05`     varchar(5),
614   `ICD9_06`     varchar(5),
615   `active` tinyint default 0,
616   `revision` int default 0
617 ) ENGINE=MyISAM;
618 #EndIf
620 #IfNotTable icd10_reimbr_pcs_9_10
621 CREATE TABLE `icd10_reimbr_pcs_9_10` (
622   `map_id`      SERIAL,
623   `code`        varchar(8),
624   `code_cnt`    tinyint,
625   `ICD9_01`     varchar(5),
626   `ICD9_02`     varchar(5),
627   `ICD9_03`     varchar(5),
628   `ICD9_04`     varchar(5),
629   `ICD9_05`     varchar(5),
630   `ICD9_06`     varchar(5),
631   `active` tinyint default 0,
632   `revision` int default 0
633 ) ENGINE=MyISAM;
634 #EndIf
636 #IfNotTable supported_external_dataloads
637 CREATE TABLE `supported_external_dataloads` (
638   `load_id` SERIAL,
639   `load_type` varchar(24) NOT NULL DEFAULT '',
640   `load_source` varchar(24) NOT NULL DEFAULT 'CMS',
641   `load_release_date` date NOT NULL,
642   `load_filename` varchar(256) NOT NULL DEFAULT '',
643   `load_checksum` varchar(32) NOT NULL DEFAULT ''
644 ) ENGINE=MyISAM;
645 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES
646 ('ICD9', 'CMS', '2011-10-01', 'cmsv29_master_descriptions.zip', 'c360c2b5a29974d6c58617c7378dd7c4');
647 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES
648 ('ICD9', 'CMS', '2012-10-01', 'cmsv30_master_descriptions.zip', 'eb26446536435f5f5e677090a7976b15');
649 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES
650 ('ICD10', 'CMS', '2011-10-01', '2012_PCS_long_and_abbreviated_titles.zip', '201a732b649d8c7fba807cc4c083a71a');
651 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES
652 ('ICD10', 'CMS', '2011-10-01', 'DiagnosisGEMs_2012.zip', '6758c4a3384c47161ce24f13a2464b53');
653 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES
654 ('ICD10', 'CMS', '2011-10-01', 'ICD10OrderFiles_2012.zip', 'a76601df7a9f5270d8229828a833f6a1');
655 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES
656 ('ICD10', 'CMS', '2011-10-01', 'ProcedureGEMs_2012.zip', 'f37416d8fab6cd2700b634ca5025295d');
657 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES
658 ('ICD10', 'CMS', '2011-10-01', 'ReimbursementMapping_2012.zip', '8b438d1fd1f34a9bb0e423c15e89744b');
659 #EndIf
661 #IfMissingColumn standardized_tables_track file_checksum
662 ALTER TABLE `standardized_tables_track` ADD COLUMN `file_checksum` varchar(32);
663 #EndIf
665 #IfMissingColumn code_types ct_proc
666 ALTER TABLE `code_types` ADD COLUMN `ct_proc` tinyint(1) NOT NULL default 0 COMMENT '1 if this is a procedure type';
667 UPDATE `code_types` SET `ct_proc`='1' WHERE `ct_key`='CPT4' OR `ct_key`='HCPCS' OR `ct_key`='ICD9-SG' OR `ct_key`='ICD10-PCS';
668 #EndIf
670 #IfNotIndex forms form_id
671 CREATE INDEX `form_id` ON `forms` (`form_id`);
672 #EndIf