fix for users.calendar calculation
[openemr.git] / sql / 3_0_1-to-3_0_2_upgrade.sql
blobe5720b3423c35f980d6fb3f9c9b06d3eb147b675
1 #IfMissingColumn pnotes deleted
2 ALTER TABLE `pnotes` 
3     ADD `deleted` TINYINT DEFAULT '0' COMMENT 'flag indicates note is deleted';
4 #EndIf
6 #IfNotRow list_options list_id adjreason
7 INSERT INTO list_options VALUES ('lists'    ,'adjreason'      ,'Adjustment Reasons',1,0,0);
8 INSERT INTO list_options VALUES ('adjreason','Adm adjust'     ,'Adm adjust'     , 5,0,0);
9 INSERT INTO list_options VALUES ('adjreason','After hrs calls','After hrs calls',10,0,0);
10 INSERT INTO list_options VALUES ('adjreason','Bad check'      ,'Bad check'      ,15,0,0);
11 INSERT INTO list_options VALUES ('adjreason','Bad debt'       ,'Bad debt'       ,20,0,0);
12 INSERT INTO list_options VALUES ('adjreason','Coll w/o'       ,'Coll w/o'       ,25,0,0);
13 INSERT INTO list_options VALUES ('adjreason','Discount'       ,'Discount'       ,30,0,0);
14 INSERT INTO list_options VALUES ('adjreason','Hardship w/o'   ,'Hardship w/o'   ,35,0,0);
15 INSERT INTO list_options VALUES ('adjreason','Ins adjust'     ,'Ins adjust'     ,40,0,0);
16 INSERT INTO list_options VALUES ('adjreason','Ins bundling'   ,'Ins bundling'   ,45,0,0);
17 INSERT INTO list_options VALUES ('adjreason','Ins overpaid'   ,'Ins overpaid'   ,50,0,0);
18 INSERT INTO list_options VALUES ('adjreason','Ins refund'     ,'Ins refund'     ,55,0,0);
19 INSERT INTO list_options VALUES ('adjreason','Pt overpaid'    ,'Pt overpaid'    ,60,0,0);
20 INSERT INTO list_options VALUES ('adjreason','Pt refund'      ,'Pt refund'      ,65,0,0);
21 INSERT INTO list_options VALUES ('adjreason','Pt released'    ,'Pt released'    ,70,0,0);
22 INSERT INTO list_options VALUES ('adjreason','Sm debt w/o'    ,'Sm debt w/o'    ,75,0,0);
23 INSERT INTO list_options VALUES ('adjreason','To copay'       ,'To copay'       ,80,0,0);
24 INSERT INTO list_options VALUES ('adjreason','To ded\'ble'    ,'To ded\'ble'    ,85,0,0);
25 INSERT INTO list_options VALUES ('adjreason','Untimely filing','Untimely filing',90,0,0);
26 #EndIf
28 #IfNotRow list_options list_id sub_relation
29 INSERT INTO list_options VALUES ('lists'       ,'sub_relation','Subscriber Relationship',18,0,0);
30 INSERT INTO list_options VALUES ('sub_relation','self'        ,'Self'                   , 1,0,0);
31 INSERT INTO list_options VALUES ('sub_relation','spouse'      ,'Spouse'                 , 2,0,0);
32 INSERT INTO list_options VALUES ('sub_relation','child'       ,'Child'                  , 3,0,0);
33 INSERT INTO list_options VALUES ('sub_relation','other'       ,'Other'                  , 4,0,0);
34 #EndIf
36 #IfNotRow list_options list_id occurrence
37 INSERT INTO list_options VALUES ('lists'     ,'occurrence','Occurrence'                  ,10,0,0);
38 INSERT INTO list_options VALUES ('occurrence','0'         ,'Unknown or N/A'              , 5,0,0);
39 INSERT INTO list_options VALUES ('occurrence','1'         ,'First'                       ,10,0,0);
40 INSERT INTO list_options VALUES ('occurrence','6'         ,'Early Recurrence (<2 Mo)'    ,15,0,0);
41 INSERT INTO list_options VALUES ('occurrence','7'         ,'Late Recurrence (2-12 Mo)'   ,20,0,0);
42 INSERT INTO list_options VALUES ('occurrence','8'         ,'Delayed Recurrence (> 12 Mo)',25,0,0);
43 INSERT INTO list_options VALUES ('occurrence','4'         ,'Chronic/Recurrent'           ,30,0,0);
44 INSERT INTO list_options VALUES ('occurrence','5'         ,'Acute on Chronic'            ,35,0,0);
45 #EndIf
47 #IfNotRow list_options list_id outcome
48 INSERT INTO list_options VALUES ('lists'  ,'outcome','Outcome'         ,10,0,0);
49 INSERT INTO list_options VALUES ('outcome','0'      ,'Unassigned'      , 2,0,0);
50 INSERT INTO list_options VALUES ('outcome','1'      ,'Resolved'        , 5,0,0);
51 INSERT INTO list_options VALUES ('outcome','2'      ,'Improved'        ,10,0,0);
52 INSERT INTO list_options VALUES ('outcome','3'      ,'Status quo'      ,15,0,0);
53 INSERT INTO list_options VALUES ('outcome','4'      ,'Worse'           ,20,0,0);
54 INSERT INTO list_options VALUES ('outcome','5'      ,'Pending followup',25,0,0);
55 #EndIf
57 #IfNotRow list_options list_id note_type
58 INSERT INTO list_options VALUES ('lists'    ,'note_type'      ,'Patient Note Types',10,0,0);
59 INSERT INTO list_options VALUES ('note_type','Unassigned'     ,'Unassigned'        , 1,0,0);
60 INSERT INTO list_options VALUES ('note_type','Chart Note'     ,'Chart Note'        , 2,0,0);
61 INSERT INTO list_options VALUES ('note_type','Insurance'      ,'Insurance'         , 3,0,0);
62 INSERT INTO list_options VALUES ('note_type','New Document'   ,'New Document'      , 4,0,0);
63 INSERT INTO list_options VALUES ('note_type','Pharmacy'       ,'Pharmacy'          , 5,0,0);
64 INSERT INTO list_options VALUES ('note_type','Prior Auth'     ,'Prior Auth'        , 6,0,0);
65 INSERT INTO list_options VALUES ('note_type','Referral'       ,'Referral'          , 7,0,0);
66 INSERT INTO list_options VALUES ('note_type','Test Scheduling','Test Scheduling'   , 8,0,0);
67 INSERT INTO list_options VALUES ('note_type','Bill/Collect'   ,'Bill/Collect'      , 9,0,0);
68 INSERT INTO list_options VALUES ('note_type','Other'          ,'Other'             ,10,0,0);
69 #EndIf
71 #IfNotRow list_options list_id immunizations
72 INSERT INTO list_options VALUES ('lists','immunizations','Immunizations',8,0,0);
73 INSERT INTO list_options (list_id,option_id,title) SELECT 'immunizations',id,name FROM immunization ORDER BY name;
74 DROP TABLE immunization;
75 #EndIf
77 #IfNotRow2D list_options list_id drug_form option_id 0
78 INSERT INTO list_options VALUES ('drug_form'    ,'0' ,''         , 0,0,0);
79 #EndIf
80 #IfNotRow2D list_options list_id drug_form option_id 10
81 INSERT INTO list_options VALUES ('drug_form'    ,'10','cream'    ,10,0,0);
82 #EndIf
83 #IfNotRow2D list_options list_id drug_form option_id 11
84 INSERT INTO list_options VALUES ('drug_form'    ,'11','ointment' ,11,0,0);
85 #EndIf
86 #IfNotRow2D list_options list_id drug_units option_id 0
87 INSERT INTO list_options VALUES ('drug_units'   ,'0' ,''         , 0,0,0);
88 #EndIf
89 #IfNotRow2D list_options list_id drug_route option_id 0
90 INSERT INTO list_options VALUES ('drug_route'   ,'0' ,''         , 0,0,0);
91 #EndIf
92 #IfNotRow2D list_options list_id drug_route option_id 13
93 INSERT INTO list_options VALUES ('drug_route'   ,'13','Both Ears',13,0,0);
94 #EndIf
95 #IfNotRow2D list_options list_id drug_route option_id 14
96 INSERT INTO list_options VALUES ('drug_route'   ,'14','Left Ear' ,14,0,0);
97 #EndIf
98 #IfNotRow2D list_options list_id drug_route option_id 15
99 INSERT INTO list_options VALUES ('drug_route'   ,'15','Right Ear',15,0,0);
100 #EndIf
101 #IfNotRow2D list_options list_id drug_interval option_id 0
102 INSERT INTO list_options VALUES ('drug_interval','0' ,''         , 0,0,0);
103 #EndIf
104 #IfNotRow2D list_options list_id drug_interval option_id 10
105 INSERT INTO list_options VALUES ('drug_interval','10','a.c.'     ,10,0,0);
106 #EndIf
107 #IfNotRow2D list_options list_id drug_interval option_id 11
108 INSERT INTO list_options VALUES ('drug_interval','11','p.c.'     ,11,0,0);
109 #EndIf
110 #IfNotRow2D list_options list_id drug_interval option_id 12
111 INSERT INTO list_options VALUES ('drug_interval','12','a.m.'     ,12,0,0);
112 #EndIf
113 #IfNotRow2D list_options list_id drug_interval option_id 13
114 INSERT INTO list_options VALUES ('drug_interval','13','p.m.'     ,13,0,0);
115 #EndIf
116 #IfNotRow2D list_options list_id drug_interval option_id 14
117 INSERT INTO list_options VALUES ('drug_interval','14','ante'     ,14,0,0);
118 #EndIf
119 #IfNotRow2D list_options list_id drug_interval option_id 15
120 INSERT INTO list_options VALUES ('drug_interval','15','h'        ,15,0,0);
121 #EndIf
122 #IfNotRow2D list_options list_id drug_interval option_id 16
123 INSERT INTO list_options VALUES ('drug_interval','16','h.s.'     ,16,0,0);
124 #EndIf
125 #IfNotRow2D list_options list_id drug_interval option_id 17
126 INSERT INTO list_options VALUES ('drug_interval','17','p.r.n.'   ,17,0,0);
127 #EndIf
128 #IfNotRow2D list_options list_id drug_interval option_id 18
129 INSERT INTO list_options VALUES ('drug_interval','18','stat'     ,18,0,0);
130 #EndIf
132 UPDATE list_options 
133     SET option_id = '6' WHERE option_id = ' 6' and list_id = 'drug_route';    
134 UPDATE list_options
135     SET title = 'mcg' WHERE option_id = '7' and list_id = 'drug_units';
136 UPDATE list_options
137     SET title = 'grams' WHERE option_id = '8' and list_id = 'drug_units';
139 UPDATE `layout_options` 
140     SET data_type = 26 WHERE form_id = 'DEM' and field_id = 'state';
141 UPDATE `layout_options`
142     SET data_type = 26 WHERE form_id = 'DEM' and field_id = 'country_code';
143 UPDATE `layout_options`
144     SET data_type = 26, list_id = 'state', fld_length = 0, max_length = 0, edit_options = '' WHERE form_id = 'DEM' and field_id = 'em_state';
145 UPDATE `layout_options`
146     SET data_type = 26, list_id = 'country', fld_length = 0, max_length = 0, edit_options = '' WHERE form_id = 'DEM' and field_id = 'em_country';
148 ALTER TABLE `prices` 
149     CHANGE `pr_selector` `pr_selector` VARCHAR( 255 ) NOT NULL default '' COMMENT 'template selector for drugs, empty for codes';
151 #IfMissingColumn form_encounter provider_id
152 ALTER TABLE `form_encounter` 
153   ADD `provider_id` INT(11) DEFAULT '0' COMMENT 'default and main provider for this visit';
154 UPDATE form_encounter AS fe, forms AS f, billing AS b, users AS u
155   SET fe.provider_id = u.id WHERE
156   fe.provider_id = 0 AND
157   f.form_id = fe.id AND
158   f.formdir = 'newpatient' AND
159   f.deleted = 0 AND
160   b.pid = fe.pid AND
161   b.encounter = fe.encounter AND
162   b.fee > 0 AND
163   b.provider_id > 0 AND
164   b.activity = 1 AND
165   u.id = b.provider_id AND
166   u.authorized = 1;
167 UPDATE form_encounter AS fe, forms AS f, users AS u
168   SET fe.provider_id = u.id WHERE
169   fe.provider_id = 0 AND
170   f.form_id = fe.id AND
171   f.formdir = 'newpatient' AND
172   f.deleted = 0 AND
173   u.username = f.user AND
174   u.authorized = 1;
175 UPDATE form_encounter AS fe, forms AS f, billing AS b
176   SET b.provider_id = 0 WHERE
177   fe.provider_id > 0 AND
178   f.form_id = fe.id AND
179   f.formdir = 'newpatient' AND
180   f.deleted = 0 AND
181   b.pid = fe.pid AND
182   b.encounter = fe.encounter AND
183   b.activity = 1;
184 #EndIf
186 #IfMissingColumn codes active
187 ALTER TABLE `codes` 
188   ADD `active` TINYINT(1) DEFAULT 1 COMMENT '0 = inactive, 1 = active';
189 #EndIf
191 #IfMissingColumn drugs active
192 ALTER TABLE `drugs` 
193   ADD `active` TINYINT(1) DEFAULT 1 COMMENT '0 = inactive, 1 = active';
194 #EndIf
196 #IfNotTable users_facility
197 CREATE TABLE `users_facility` (
198   `tablename` varchar(64) NOT NULL,
199   `table_id` int(11) NOT NULL,
200   `facility_id` int(11) NOT NULL,
201   PRIMARY KEY (`tablename`,`table_id`,`facility_id`)
202 ) ENGINE=InnoDB COMMENT='joins users or patient_data to facility table';
203 #EndIf
205 #IfMissingColumn users calendar
206 ALTER TABLE `users` 
207   ADD `calendar` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '1 = appears in calendar';
208 UPDATE users SET calendar = 1 WHERE authorized = 1 AND ( info IS NULL OR info NOT LIKE '%Nocalendar%' );
209 #EndIf