2 -- Comment Meta Language Constructs:
5 -- argument: table_name
6 -- behavior: if the table_name does not exist, the block will be executed
9 -- argument: table_name
10 -- behavior: if the table_name does exist, the block will be executed
13 -- arguments: table_name colname
14 -- behavior: if the table and column exist, the block will be executed
17 -- arguments: table_name colname
18 -- behavior: if the table exists but the column does not, the block will be executed
21 -- arguments: table_name colname value
22 -- 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
24 -- #IfNotColumnTypeDefault
25 -- arguments: table_name colname value value2
26 -- behavior: If the table table_name does not have a column colname with a data type equal to value and a default equal to value2, then the block will be executed
29 -- arguments: table_name colname value
30 -- behavior: If the table table_name does not have a row where colname = value, the block will be executed.
33 -- arguments: table_name colname value colname2 value2
34 -- behavior: If the table table_name does not have a row where colname = value AND colname2 = value2, the block will be executed.
37 -- arguments: table_name colname value colname2 value2 colname3 value3
38 -- 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.
41 -- arguments: table_name colname value colname2 value2 colname3 value3 colname4 value4
42 -- 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.
45 -- 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.
46 -- arguments: table_name colname value colname2 value2 colname3 value3
47 -- behavior: The block will be executed if both statements below are true:
48 -- 1) The table table_name does not have a row where colname = value AND colname2 = value2.
49 -- 2) The table table_name does not have a row where colname = value AND colname3 = value3.
52 -- arguments: table_name colname value
53 -- behavior: If the table table_name does have a row where colname = value, the block will be executed.
56 -- arguments: table_name colname value colname2 value2
57 -- behavior: If the table table_name does have a row where colname = value AND colname2 = value2, the block will be executed.
60 -- arguments: table_name colname value colname2 value2 colname3 value3
61 -- behavior: If the table table_name does have a row where colname = value AND colname2 = value2 AND colname3 = value3, the block will be executed.
64 -- desc: This function is most often used for dropping of indexes/keys.
65 -- arguments: table_name colname
66 -- behavior: If the table and index exist the relevant statements are executed, otherwise not.
69 -- desc: This function will allow adding of indexes/keys.
70 -- arguments: table_name colname
71 -- behavior: If the index does not exist, it will be created
74 -- argument: table_name
75 -- behavior: this will populate a uuid column in table (table needs to be mapped in UUID_TABLE_DEFINITIONS in UuidRegistry class)
77 -- #IfMappingUuidNeedUpdate
78 -- behavior: this will populate the mapping_uuid table
81 -- all blocks are terminated with a #EndIf statement.
84 -- Custom function for creating Reaction List
86 -- #IfNotListOccupation
87 -- Custom function for creating Occupation List
89 -- #IfTextNullFixNeeded
90 -- desc: convert all text fields without default null to have default null.
94 -- desc: Execute SQL if the table has been created with given engine specified.
95 -- arguments: table_name engine
96 -- behavior: Use when engine conversion requires more than one ALTER TABLE
98 -- #IfInnoDBMigrationNeeded
99 -- desc: find all MyISAM tables and convert them to InnoDB.
101 -- behavior: can take a long time.
103 -- #IfDocumentNamingNeeded
104 -- desc: populate name field with document names.
107 #IfUuidNeedUpdate patient_data
110 #IfUuidNeedUpdate form_encounter
113 #IfUuidNeedUpdate users
116 #IfUuidNeedUpdate facility_user_ids
119 #IfUuidNeedUpdate facility
122 #IfUuidNeedUpdate immunizations
125 #IfUuidNeedUpdate lists
128 #IfUuidNeedUpdate procedure_order
131 #IfUuidNeedUpdate drugs
134 #IfUuidNeedUpdate prescriptions
137 #IfUuidNeedUpdate procedure_result
140 #IfUuidNeedUpdate ccda
143 #IfMissingColumn insurance_companies uuid
144 ALTER TABLE `insurance_companies` ADD `uuid` binary(16) DEFAULT NULL;
147 #IfNotIndex insurance_companies uuid
148 CREATE UNIQUE INDEX `uuid` ON `insurance_companies` (`uuid`);
151 #IfUuidNeedUpdate insurance_companies
154 #IfMissingColumn insurance_data uuid
155 ALTER TABLE `insurance_data` ADD `uuid` binary(16) DEFAULT NULL;
158 #IfNotIndex insurance_data uuid
159 CREATE UNIQUE INDEX `uuid` ON `insurance_data` (`uuid`);
162 #IfUuidNeedUpdate insurance_data
165 #IfMissingColumn facility weno_id
166 ALTER TABLE `facility` ADD `weno_id` VARCHAR(10) DEFAULT NULL;
169 #IfMissingColumn x12_partners x12_gs03
170 ALTER TABLE `x12_partners` ADD COLUMN `x12_gs03` varchar(15) DEFAULT NULL;
173 #IfMissingColumn x12_partners x12_submitter_name
174 ALTER TABLE `x12_partners` ADD COLUMN `x12_submitter_name` varchar(255) DEFAULT NULL;
177 #IfMissingColumn x12_partners x12_sftp_login
178 ALTER TABLE `x12_partners` ADD COLUMN `x12_sftp_login` varchar(255) DEFAULT NULL;
181 #IfMissingColumn x12_partners x12_sftp_pass
182 ALTER TABLE `x12_partners` ADD COLUMN `x12_sftp_pass` varchar(255) DEFAULT NULL;
185 #IfMissingColumn x12_partners x12_sftp_host
186 ALTER TABLE `x12_partners` ADD COLUMN `x12_sftp_host` varchar(255) DEFAULT NULL;
189 #IfMissingColumn x12_partners x12_sftp_port
190 ALTER TABLE `x12_partners` ADD COLUMN `x12_sftp_port` varchar(255) DEFAULT NULL;
193 #IfMissingColumn x12_partners x12_sftp_local_dir
194 ALTER TABLE `x12_partners` ADD COLUMN `x12_sftp_local_dir` varchar(255) DEFAULT NULL;
197 #IfMissingColumn x12_partners x12_sftp_remote_dir
198 ALTER TABLE `x12_partners` ADD COLUMN `x12_sftp_remote_dir` varchar(255) DEFAULT NULL;
201 #IfNotRow background_services name X12_SFTP
202 INSERT INTO `background_services` (`name`, `title`, `active`, `running`, `next_run`, `execute_interval`, `function`, `require_once`, `sort_order`) VALUES
203 ('X12_SFTP', 'SFTP Claims to X12 Partner Service', 0, 0, '2021-01-18 11:25:10', 1, 'start_X12_SFTP', '/library/billing_sftp_service.php', 100);
206 #IfNotTable x12_remote_tracker
207 CREATE TABLE `x12_remote_tracker` (
208 `id` bigint(20) NOT NULL AUTO_INCREMENT,
209 `x12_partner_id` int(11) NOT NULL,
210 `x12_filename` varchar(255) NOT NULL,
211 `status` varchar(255) NOT NULL,
214 `created_at` datetime DEFAULT NULL,
215 `updated_at` datetime DEFAULT NULL,
219 #IfNotRow2D list_options list_id lists option_id Procedure_Billing
220 INSERT INTO list_options (list_id,option_id,title, seq, is_default, option_value) VALUES ('lists','Procedure_Billing','Procedure Billing',0, 1, 0);
221 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('Procedure_Billing','T','Third-Party',10,1,1);
222 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('Procedure_Billing','P','Self Pay',20,0,1);
223 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('Procedure_Billing','C','Bill Clinic',30,0,1);
226 #IfMissingColumn procedure_order billing_type
227 ALTER TABLE `procedure_order` ADD `billing_type` VARCHAR(4) DEFAULT NULL;
230 #IfMissingColumn procedure_order specimen_fasting
231 ALTER TABLE `procedure_order` ADD `specimen_fasting` VARCHAR(31) DEFAULT NULL;
234 #IfMissingColumn procedure_order order_psc
235 ALTER TABLE `procedure_order` ADD `order_psc` TINYINT(4) DEFAULT NULL;
238 #IfMissingColumn procedure_order order_abn
239 ALTER TABLE `procedure_order` ADD `order_abn` VARCHAR(31) NOT NULL DEFAULT 'not_required';
242 #IfMissingColumn procedure_order collector_id
243 ALTER TABLE `procedure_order` ADD `collector_id` BIGINT(11) NOT NULL DEFAULT '0';
246 #IfMissingColumn procedure_order account
247 ALTER TABLE `procedure_order` ADD `account` VARCHAR(60) DEFAULT NULL;
250 #IfMissingColumn procedure_order account_facility
251 ALTER TABLE `procedure_order` ADD `account_facility` int(11) DEFAULT NULL;
254 #IfMissingColumn procedure_order provider_number
255 ALTER TABLE `procedure_order` ADD `provider_number` VARCHAR(30) DEFAULT NULL;
258 #IfMissingColumn procedure_order procedure_order_type
259 ALTER TABLE `procedure_order` ADD `procedure_order_type` varchar(32) NOT NULL DEFAULT 'laboratory_test';
262 #IfMissingColumn procedure_order_code procedure_type
263 ALTER TABLE `procedure_order_code` ADD `procedure_type` VARCHAR(31) DEFAULT NULL;
266 #IfMissingColumn procedure_order_code transport
267 ALTER TABLE `procedure_order_code` ADD `transport` VARCHAR(31) DEFAULT NULL;
270 #IfMissingColumn procedure_type transport
271 ALTER TABLE `procedure_type` ADD `transport` VARCHAR(31) DEFAULT NULL;
274 #IfMissingColumn procedure_providers type
275 ALTER TABLE `procedure_providers` ADD `type` VARCHAR(31) DEFAULT NULL;
278 #IfMissingColumn procedure_answers procedure_code
279 ALTER TABLE `procedure_answers` ADD `procedure_code` VARCHAR(31) DEFAULT NULL;
282 #IfNotRow users username oe-system
283 INSERT INTO `users`(`username`,`password`,`lname`,`authorized`,`active`) VALUES ('oe-system','NoLogin','System Operation User',0,0);
284 INSERT INTO `gacl_aro`(`id`, `section_value`, `value`, `order_value`, `name`, `hidden`)
285 SELECT max(`id`)+1,'users','oe-system',10,'System Operation User', 0 FROM `gacl_aro`;
286 INSERT INTO `gacl_groups_aro_map`(`group_id`, `aro_id`)
288 (SELECT `id` FROM `gacl_aro_groups` WHERE parent_id=10 AND value='admin')
289 ,(SELECT `id` FROM `gacl_aro` WHERE `section_value` = 'users' AND `value` = 'oe-system')
293 #IfNotTable export_job
294 CREATE TABLE `export_job` (
295 `id` bigint(20) NOT NULL AUTO_INCREMENT,
296 `uuid` binary(16) DEFAULT NULL ,
297 `user_id` varchar(40) NOT NULL,
298 `client_id` varchar(80) NOT NULL,
299 `status` varchar(40) NOT NULL,
300 `start_time` datetime DEFAULT NULL,
301 `resource_include_time` datetime DEFAULT NULL,
302 `output_format` varchar(128) NOT NULL,
303 `request_uri` varchar(128) NOT NULL,
307 `access_token_id` text,
310 ) ENGINE=InnoDB COMMENT='fhir export jobs';
313 #IfNotRow categories name FHIR Export Document
314 SET @max_rght = (SELECT MAX(rght) FROM categories);
315 INSERT INTO categories(`id`,`name`, `value`, `parent`, `lft`, `rght`, `aco_spec`) select (select MAX(id) from categories) + 1, 'FHIR Export Document', '', 1, @max_rght, @max_rght + 1, 'admin|super' from categories where name = 'Categories';
316 UPDATE categories SET rght = rght + 2 WHERE name = 'Categories';
317 UPDATE categories_seq SET id = (select MAX(id) from categories);
320 #IfMissingColumn documents date_expires
321 ALTER TABLE `documents` ADD COLUMN `date_expires` DATETIME DEFAULT NULL;
324 #IfMissingColumn documents foreign_reference_id
325 ALTER TABLE `documents` ADD COLUMN `foreign_reference_id` bigint(20) default NULL,
326 ADD COLUMN `foreign_reference_table` VARCHAR(40) default NULL;
327 ALTER TABLE `documents` ADD KEY `foreign_reference` (`foreign_reference_id`, `foreign_reference_table`);
329 #IfNotRow background_services name WenoExchange
330 INSERT INTO `background_services` (`name`, `title`, `active`, `running`, `next_run`, `execute_interval`, `function`, `require_once`, `sort_order`) VALUES
331 ('WenoExchange', 'Weno Log Sync', 0, 0, '2021-01-18 11:25:10', 0, 'start_weno', '/library/weno_log_sync.php', 100);
334 #IfNotRow2D list_options list_id Eye_Defaults_for_GENERAL option_id ODVITREOUS
335 INSERT INTO list_options (list_id,option_id,title,seq,is_default,option_value,mapping,notes,codes,toggle_setting_1,toggle_setting_2,activity,subtype) VALUES ('Eye_Defaults_for_GENERAL', 'ODVITREOUS', 'clear', 504, 0, 0,'', 'RETINA','', 0, 0, 1,'');
338 #IfNotRow2D list_options list_id Eye_Defaults_for_GENERAL option_id OSVITREOUS
339 INSERT INTO list_options (list_id,option_id,title,seq,is_default,option_value,mapping,notes,codes,toggle_setting_1,toggle_setting_2,activity,subtype) VALUES ('Eye_Defaults_for_GENERAL', 'OSVITREOUS', 'clear', 506, 0, 0,'', 'RETINA','', 0, 0, 1,'');
342 DELETE FROM medex_icons;
343 INSERT INTO `medex_icons` (`i_UID`, `msg_type`, `msg_status`, `i_description`, `i_html`, `i_blob`) VALUES
344 (1, 'SMS', 'ALLOWED', '', '<i title="SMS is possible." class="far fa-comment-dots fa-fw"></i>', ''),
345 (2, 'SMS', 'NotAllowed', '', '<span class="fas fa-stack" title="SMS not possible"><i title="SMS is not possible." class="fas fa-comment-dots fa-fw"></i><i class="fas fa-ban fa-stack-2x text-danger"></i></span>', ''),
346 (3, 'SMS', 'SCHEDULED', '', '<span class="btn scheduled" title="SMS scheduled"><i class="fas fa-comment-dots fa-fw"></i></span>', ''),
347 (4, 'SMS', 'SENT', '', '<span class="btn" title="SMS Sent - in process" style="background-color:yellow;"><i aria-hidden="true" class="fas fa-comment-dots fa-fw"></i></span>', ''),
348 (5, 'SMS', 'READ', '', '<span class="btn" title="SMS Delivered - waiting for response" aria-label="SMS Delivered" style="background-color:#146abd;"><i aria-hidden="true" class="fas fa-comment-dots fa-inverse fa-flip-horizontal fa-fw"></i></span>', ''),
349 (6, 'SMS', 'FAILED', '', '<span class="btn" title="SMS Failed to be delivered" style="background-color:#ffc4c4;"><i aria-hidden="true" class="fas fa-comment-dots fa-fw"></i></span>', ''),
350 (7, 'SMS', 'CONFIRMED', '', '<span class="btn" title="Confirmed by SMS" style="background-color:green;"><i aria-hidden="true" class="fas fa-comment-dots fa-inverse fa-flip-horizontal fa-fw"></i></span>', ''),
351 (8, 'SMS', 'CALL', '', '<span class="btn" style="background-color: red;" title="Patient requests Office Call"><i class="fas fa-flag fa-inverse fa-fw"></i></span>', ''),
352 (9, 'SMS', 'EXTRA', '', '<span class="btn" title="EXTRA" style="background-color:#000;color:#fff;"><i class="fas fa-terminal fa-fw"></i></span>', ''),
353 (10, 'SMS', 'STOP', '', '<span class="btn btn-danger fas fa-comment-dots" title="OptOut of SMS Messaging. Demographics updated." aria-label=\'Optout SMS\'> STOP</span>', ''),
354 (11, 'AVM', 'ALLOWED', '', '<span title="Automated Voice Messages are possible" class="fas fa-phone fa-fw"></span>', ''),
355 (12, 'AVM', 'NotAllowed', '', '<span class="fas fa-stack" title="Automated Voice Messages are not allowed"><i class="fas fa-phone fa-fw fa-stack-1x"></i><i class="fas fa-ban fa-stack-2x text-danger"></i></span>', ''),
356 (13, 'AVM', 'SCHEDULED', '', '<span class="btn scheduled" title="AVM scheduled"><i class="fas fa-phone fa-fw"></i></span>', ''),
357 (14, 'AVM', 'SENT', '', '<span class="btn" title="AVM in process, no response" style="background-color:yellow;"><i class="fas fa-phone-volume fa-reverse fa-fw"></i></span>', ''),
358 (15, 'AVM', 'FAILED', '', '<span class="btn" title="AVM: Failed. Check patient\'s phone numbers." style="background-color:#ffc4c4;"><i class="fas fa-phone fa-fw"></i></span>', ''),
359 (16, 'AVM', 'CONFIRMED', '', '<span class="btn" title="Confirmed by AVM" style="padding:5px;background-color:green;"><i class="fas fa-phone fa-inverse fa-fw"></i></span>', ''),
360 (17, 'AVM', 'CALL', '', '<span class="btn" style="background-color: red;" title="Patient requests Office Call">\r\n<i class="fas fa-flag fa-inverse fa-fw"></i></span>', ''),
361 (18, 'AVM', 'Other', '', '<span class="fas fa-stack fa-lg"><i class="fas fa-square fa-stack-2x"></i><i class="fas fa-terminal fa-fw fa-stack-1x fa-inverse"></i></span>', ''),
362 (19, 'AVM', 'STOP', '', '<span class="btn btn-danger" title="OptOut of Voice Messaging. Demographics updated." aria-label="Optout AVM"><i class="fas fa-phone" aria-hidden="true"> STOP</i></span>', ''),
363 (20, 'EMAIL', 'ALLOWED', '', '<span title="EMAIL is possible" class="fas fa-envelope fa-fw"></span>', ''),
364 (21, 'EMAIL', 'NotAllowed', '', '<span class="fas fa-stack" title="EMAIL is not possible"><i class="fas fa-envelope fa-fw fa-stack-1x"></i><i class="fas fa-ban fa-stack-2x text-danger"></i></span>', ''),
365 (22, 'EMAIL', 'SCHEDULED', '', '<span class="btn scheduled" title="EMAIL scheduled"><i class="fas fa-envelope fa-fw"></i></span>', ''),
366 (23, 'EMAIL', 'SENT', '', '<span class="btn" style="background-color:yellow;" title="EMAIL Message sent, not opened"><i class="fas fa-envelope fa-fw"></i></span>', ''),
367 (24, 'EMAIL', 'READ', '', '<span class="btn" style="background-color:#146abd;" title="E-Mail was read/opened by patient" aria-label="Read via email"><i aria-hidden="true" class="fas fa-envelope fa-inverse fa-fw"></i></span>', ''),
368 (25, 'EMAIL', 'FAILED', '', '<span class="btn" title="EMAIL: Failed. Check patient\'s email address." style="background-color:#ffc4c4;"><i class="fas fa-envelope fa-fw"></i></span>', ''),
369 (26, 'EMAIL', 'CONFIRMED', '', '<span class="btn" title="Confirmed by E-Mail" aria-label="Confirmed via email" style="background-color: green;"><i aria-hidden="true" class="fas fa-envelope fa-inverse fa-fw"></i></span>', ''),
370 (27, 'EMAIL', 'CALL', '', '<span class="btn" style="background-color: red;" title="Patient requests Office Call"><i class="fas fa-flag fa-inverse fa-fw"></i></span>', ''),
371 (28, 'EMAIL', 'Other', '', '<span class="fas fa-stack fa-lg"><i class="fas fa-square fa-stack-2x"></i><i class="fas fa-terminal fa-fw fa-stack-1x fa-inverse fa-fw"></i></span>', ''),
372 (29, 'EMAIL', 'STOP', '', '<span class="btn btn-danger" title="OptOut of EMAIL Messaging. Demographics updated." aria-label="Optout EMAIL"><i class="fas fa-envelope-o" aria-hidden="true"> STOP</i></span>', ''),
373 (30, 'POSTCARD', 'SENT', '', '<span class="btn" title="Postcard Sent - in process" style="padding:5px;background-color:yellow;color:black"><i class="fas fa-image fa-fw"></i></span>', ''),
374 (31, 'POSTCARD', 'READ', '', '<span class="btn" style="background-color:#146abd;" title="e-Postcard was delivered" aria-label="Postcard Delivered"><i class="fas fa-image fa-fw" aria-hidden="true"></i></span>', ''),
375 (32, 'POSTCARD', 'FAILED', '', '<span class="fas fa-stack fa-lg" title="Delivery Failure - check Address for this patient"><i class="fas fa-image fa-fw fa-stack-1x"></i><i class="fas fa-ban fa-stack-2x text-danger"></i></span>', ''),
376 (33, 'POSTCARD', 'SCHEDULED', '', '<span class="btn scheduled" title="Postcard Campaign Event is scheduled."><i class="fas fa-image fa-fw"></i></span>', ''),
377 (36, 'AVM', 'READ', '', '<span class="btn" title="AVM completed - waiting for manual response" aria-label="AVM Delivered" style="padding:5px;background-color:#146abd;"><i class="fas fa-inverse fa-phone fa-fw" aria-hidden="true"></i></span>', ''),
378 (37, 'SMS', 'CALLED', '', '<span class="btn" style="background-color:#146abd;" title="Patient requests Office Call: COMPLETED"><i class="fas fa-flag fa-fw"></i></span>', ''),
379 (38, 'AVM', 'CALLED', '', '<span class="btn" style="background-color:#146abd;" title="Patient requests Office Call: COMPLETED"><i class="fas fa-flag fa-fw"></i></span> ', ''),
380 (39, 'EMAIL', 'CALLED', '', '<span class="btn" style="background-color:#146abd;" title="Patient requests Office Call: COMPLETED"><i class="fas fa-flag fa-fw"></i></span>', '');
382 #IfNotRow2D list_options list_id sex option_id UNK
383 INSERT INTO list_options ( list_id, option_id, title, seq, is_default, codes ) VALUES ('sex', 'UNK', 'Unknown', 10, 0, 'HL7:UNK');
386 #IfNotRow3D list_options list_id sex option_id Female codes HL7:F
387 UPDATE `list_options` SET `codes` = 'HL7:F' WHERE `list_id` = 'sex' AND `option_id` = 'Female';
390 #IfNotRow3D list_options list_id sex option_id Male codes HL7:M
391 UPDATE `list_options` SET `codes` = 'HL7:M' WHERE `list_id` = 'sex' AND `option_id` = 'Male';
394 #IfMissingColumn patient_data sexual_orientation
395 ALTER TABLE patient_data ADD sexual_orientation TEXT;
398 #IfMissingColumn patient_data gender_identity
399 ALTER TABLE patient_data ADD gender_identity TEXT;
402 #IfNotRow2D list_options list_id lists option_id sexual_orientation
403 INSERT INTO list_options (`list_id`, `option_id`, `title`, `seq`) VALUES ('lists', 'sexual_orientation', 'Sexual Orientation', '13');
404 INSERT INTO `list_options`(`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `codes`) VALUES ('sexual_orientation','20430005','Straight or heterosexual',10,0,0,'SNOMED:20430005');
405 INSERT INTO `list_options`(`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `codes`) VALUES ('sexual_orientation','38628009','Lesbian, gay or homosexual',20,0,0,'SNOMED:38628009');
406 INSERT INTO `list_options`(`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `codes`) VALUES ('sexual_orientation','42035005','Bisexual',30,0,0,'SNOMED:42035005');
407 INSERT INTO `list_options`(`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `codes`) VALUES ('sexual_orientation','comment_OTH','Something else, please describe',40,0,0,'HL7:OTH');
408 INSERT INTO `list_options`(`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `codes`) VALUES ('sexual_orientation','UNK','Don\'t know',50,0,0,'HL7:UNK');
409 INSERT INTO `list_options`(`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `codes`) VALUES ('sexual_orientation','ASKU','Choose not to disclose',60,0,0,'HL7:ASKU');
412 #IfNotRow2D list_options list_id lists option_id gender_identity
413 INSERT INTO list_options (`list_id`, `option_id`, `title`, `seq`) VALUES ('lists', 'gender_identity', 'Gender Identity', '1');
414 INSERT INTO `list_options`(`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `codes`) VALUES ('gender_identity','446151000124109','Identifies as Male',10,0,0,'SNOMED:446151000124109');
415 INSERT INTO `list_options`(`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `codes`) VALUES ('gender_identity','446141000124107','Identifies as Female',20,0,0,'SNOMED:446141000124107');
416 INSERT INTO `list_options`(`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `codes`) VALUES ('gender_identity','407377005','Female-to-Male (FTM)/Transgender Male/Trans Man',30,0,0,'SNOMED:407377005');
417 INSERT INTO `list_options`(`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `codes`) VALUES ('gender_identity','407376001','Male-to-Female (MTF)/Transgender Female/Trans Woman',40,0,0,'SNOMED:407376001');
418 INSERT INTO `list_options`(`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `codes`) VALUES ('gender_identity','446131000124102','Genderqueer, neither exclusively male nor female',50,0,0,'SNOMED:446131000124102');
419 INSERT INTO `list_options`(`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `codes`) VALUES ('gender_identity','comment_OTH','Additional gender category or other, please specify',60,0,0,'HL7:OTH');
420 INSERT INTO `list_options`(`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `codes`) VALUES ('gender_identity','ASKU','Choose not to disclose',70,0,0,'HL7:ASKU');
423 #IfNotRow2D layout_options form_id DEM field_id gender_identity
424 SET @group_id = (SELECT group_id FROM layout_options WHERE field_id='sex' AND form_id='DEM');
425 SET @backup_group_id = (SELECT group_id FROM layout_options WHERE field_id='DOB' AND form_id='DEM');
426 SET @seq = (SELECT MAX(seq) FROM layout_options WHERE group_id = IFNULL(@group_id,@backup_group_id) AND form_id='DEM');
427 INSERT INTO `layout_options` (`form_id`,`field_id`,`group_id`,`title`,`seq`,`data_type`,`uor`,`fld_length`,`max_length`,`list_id`,`titlecols`,`datacols`,`default_value`,`edit_options`,`description`,`fld_rows`) VALUES ('DEM', 'gender_identity', IFNULL(@group_id,@backup_group_id), 'Gender Identity', @seq+1, 46, 1, 0, 100, 'gender_identity' , 1 , 1 , '' , 'N' , 'Gender Identity', 0);
430 #IfNotRow2D layout_options form_id DEM field_id sexual_orientation
431 SET @group_id = (SELECT group_id FROM layout_options WHERE field_id='sex' AND form_id='DEM');
432 SET @backup_group_id = (SELECT group_id FROM layout_options WHERE field_id='DOB' AND form_id='DEM');
433 SET @seq = (SELECT MAX(seq) FROM layout_options WHERE group_id = IFNULL(@group_id,@backup_group_id) AND form_id='DEM');
434 INSERT INTO `layout_options` (`form_id`,`field_id`,`group_id`,`title`,`seq`,`data_type`,`uor`,`fld_length`,`max_length`,`list_id`,`titlecols`,`datacols`,`default_value`,`edit_options`,`description`,`fld_rows`) VALUES ('DEM', 'sexual_orientation', IFNULL(@group_id,@backup_group_id), 'Sexual Orientation', @seq+1, 46, 1, 0, 100, 'sexual_orientation', 1, 1, '' ,'N' ,'Sexual Orientation', 0);
437 #IfMissingColumn users google_signin_email
438 ALTER TABLE `users` ADD COLUMN `google_signin_email` VARCHAR(255) UNIQUE DEFAULT NULL;
441 #IfNotRow background_services name UUID_Service
442 INSERT INTO `background_services` (`name`, `title`, `active`, `running`, `next_run`, `execute_interval`, `function`, `require_once`, `sort_order`) VALUES
443 ('UUID_Service', 'Automated UUID Creation Service', 1, 0, '2021-01-18 11:25:10', 240, 'autoPopulateAllMissingUuids', '/library/uuid.php', 100);
446 #IfNotRow codes code_text SARS-COV-2 (COVID-19) vaccine, vector non-replicating, recombinant spike protein-Ad26, preservative free, 0.5 mL
447 SET @codetypeid = (SELECT `ct_id` FROM `code_types` WHERE `ct_key` = 'CVX');
448 INSERT INTO `codes` (`id`, `code_text`, `code_text_short`, `code`, `code_type`, `modifier`, `units`, `fee`, `superbill`, `related_code`, `taxrates`, `active`)
450 (NULL, "SARS-COV-2 (COVID-19) vaccine, vector non-replicating, recombinant spike protein-Ad26, preservative free, 0.5 mL", "COVID-19 vaccine, vector-nr, rS-Ad26, PF, 0.5 mL", 212, @codetypeid, '', 0, 0, '', '', '', 1);
453 #IfNotRow2D list_options list_id lists option_id Document_Template_Categories
454 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`, `codes`, `toggle_setting_1`, `toggle_setting_2`, `activity`) VALUES ('lists','Document_Template_Categories','Document Template Categories',0,1,0,'',NULL,'',0,0,1);
455 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`, `codes`, `toggle_setting_1`, `toggle_setting_2`, `activity`) VALUES ('Document_Template_Categories','repository','Repository',1,1,0,'','','',0,0,1);
457 #IfMissingColumn layout_group_properties grp_save_close
458 ALTER TABLE `layout_group_properties` ADD COLUMN `grp_save_close` tinyint(1) not null default 0;
461 #IfMissingColumn layout_group_properties grp_init_open
462 ALTER TABLE `layout_group_properties` ADD COLUMN `grp_init_open` tinyint(1) not null default 0;
463 UPDATE layout_group_properties AS p, layout_options AS o SET p.grp_init_open = 1 WHERE
464 o.form_id = p.grp_form_id AND o.group_id = p.grp_group_id AND o.uor > 0 AND o.edit_options LIKE '%I%';
465 UPDATE layout_group_properties AS p SET p.grp_init_open = 1 WHERE p.grp_group_id = '1' AND
466 (SELECT count(*) FROM layout_options AS o WHERE o.form_id = p.grp_form_id AND o.uor > 0 AND o.edit_options LIKE '%I%') = 0;
469 #IfMissingColumn layout_group_properties grp_last_update
470 ALTER TABLE `layout_group_properties` ADD COLUMN `grp_last_update` timestamp NULL;
473 #---------- Support for Referrals section of LBFs. ----------#
474 #IfMissingColumn layout_group_properties grp_referrals
475 ALTER TABLE `layout_group_properties` ADD COLUMN `grp_referrals` tinyint(1) not null default 0;
478 #IfMissingColumn drug_sales trans_type
479 ALTER TABLE drug_sales
480 ADD trans_type tinyint NOT NULL DEFAULT 1 COMMENT '1=sale, 2=purchase, 3=return, 4=transfer, 5=adjustment';
481 UPDATE drug_sales SET trans_type = 4 WHERE pid = 0 AND xfer_inventory_id != 0;
482 UPDATE drug_sales SET trans_type = 5 WHERE trans_type = 1 AND pid = 0 AND fee = 0;
483 UPDATE drug_sales SET trans_type = 2 WHERE trans_type = 1 AND pid = 0 AND quantity >= 0;
484 UPDATE drug_sales SET trans_type = 3 WHERE trans_type = 1 AND pid = 0;
487 #IfMissingColumn ar_activity post_date
488 ALTER TABLE ar_activity
489 ADD post_date date DEFAULT NULL COMMENT 'Posting date if specified at payment time';
490 UPDATE ar_activity SET post_date = post_time;
493 #IfMissingColumn form_encounter shift
494 ALTER TABLE form_encounter ADD shift varchar(31) NOT NULL DEFAULT '';
497 #IfNotRow2D list_options list_id lists option_id shift
498 INSERT INTO list_options ( list_id, option_id, title, seq, is_default ) VALUES ('lists','shift','Shifts', 1, 0);
501 #IfMissingColumn form_encounter voucher_number
502 ALTER TABLE form_encounter ADD voucher_number varchar(255) NOT NULL DEFAULT '' COMMENT 'also called referral number';
505 #IfMissingColumn billing chargecat
506 ALTER TABLE `billing` ADD COLUMN `chargecat` varchar(31) default '';
509 #IfMissingColumn drug_sales chargecat
510 ALTER TABLE `drug_sales` ADD COLUMN `chargecat` varchar(31) default '';
512 #IfMissingColumn users_facility warehouse_id
513 ALTER TABLE `users_facility` ADD COLUMN `warehouse_id` varchar(31) NOT NULL default '';
514 ALTER TABLE `users_facility` DROP PRIMARY KEY, ADD PRIMARY KEY (`tablename`,`table_id`,`facility_id`,`warehouse_id`);
517 #IfNotColumnType drugs form varchar(31)
518 ALTER TABLE `drugs` CHANGE `form` `form` varchar(31) NOT NULL default '0';
520 #IfNotColumnType drugs unit varchar(31)
521 ALTER TABLE `drugs` CHANGE `unit` `unit` varchar(31) NOT NULL default '0';
523 #IfNotColumnType drugs route varchar(31)
524 ALTER TABLE `drugs` CHANGE `route` `route` varchar(31) NOT NULL default '0';
527 #IfMissingColumn drug_templates pkgqty
528 ALTER TABLE `drug_templates` ADD COLUMN `pkgqty` float NOT NULL DEFAULT 1.0 COMMENT 'Number of product items per template item';
531 #IfMissingColumn voids reason
532 ALTER TABLE `voids` ADD COLUMN `reason` VARCHAR(31) default '';
535 #IfMissingColumn voids notes
536 ALTER TABLE `voids` ADD COLUMN `notes` VARCHAR(255) default '';
539 #IfNotRow2D list_options list_id lists option_id void_reasons
540 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`) VALUES ('lists','void_reasons','Void Reasons',1,0);
541 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`) VALUES ('void_reasons','one' ,'Reason 1',10,1);
542 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`) VALUES ('void_reasons','two' ,'Reason 2',20,0);
545 #IfNotIndex log patient_id
546 CREATE INDEX `patient_id` ON `log` (`patient_id`);
549 #IfNotRow2D list_options list_id lists option_id paymethod
550 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`) VALUES ('lists','paymethod','Payment Methods', 1,0);
551 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`) VALUES ('paymethod','Cash' ,'Cash' ,10,0);
552 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`) VALUES ('paymethod','Check','Check',20,0);
553 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`) VALUES ('paymethod','MC' ,'MC' ,30,0);
554 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`) VALUES ('paymethod','VISA' ,'VISA' ,40,0);
555 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`) VALUES ('paymethod','AMEX' ,'AMEX' ,50,0);
556 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`) VALUES ('paymethod','DISC' ,'DISC' ,60,0);
557 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`) VALUES ('paymethod','Other','Other',70,0);
560 #IfNotRow2D issue_types category default type medical_device
561 INSERT INTO `issue_types` (`ordering`,`category`,`type`,`plural`,`singular`,`abbreviation`,`style`,`force_show`) VALUES ('35','default','medical_device','Medical Devices','Device','I','0','0');
564 #IfMissingColumn lists udi
565 ALTER TABLE `lists` ADD COLUMN `udi` varchar(255) default NULL;
568 #IfMissingColumn lists udi_data
569 ALTER TABLE `lists` ADD COLUMN `udi_data` text;
572 #IfNotRow globals gl_name gbl_fac_warehouse_restrictions
573 INSERT INTO `globals` (gl_name, gl_index, gl_value) SELECT 'gbl_fac_warehouse_restrictions', gl_index, gl_value
574 FROM globals WHERE gl_name = 'restrict_user_facility';
577 #IfNotRow2D list_options list_id lists option_id chargecats
578 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`)
579 VALUES ('lists','chargecats','Customers', 1,0);
582 #IfNotRow2D list_options list_id lists option_id Clinical_Note_Type
583 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`, `codes`, `toggle_setting_1`, `toggle_setting_2`, `activity`, `subtype`, `edit_options`) VALUES ('lists','Clinical_Note_Type','Clinical Note Type',0,1,0,'',NULL,'',0,0,1,'',1);
584 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`, `codes`, `toggle_setting_1`, `toggle_setting_2`, `activity`, `subtype`, `edit_options`) VALUES ('Clinical_Note_Type','progress_note','Progress Note',10,0,0,'','LOINC:11506-3','',0,0,1,'',1);
585 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`, `codes`, `toggle_setting_1`, `toggle_setting_2`, `activity`, `subtype`, `edit_options`) VALUES ('Clinical_Note_Type','nurse_note','Nurse Note',20,0,0,'','LOINC:34746-8','',0,0,1,'',1);
586 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`, `codes`, `toggle_setting_1`, `toggle_setting_2`, `activity`, `subtype`, `edit_options`) VALUES ('Clinical_Note_Type','history_physical','History & Physical',30,0,0,'','LOINC:34117-2','',0,0,1,'',1);
587 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`, `codes`, `toggle_setting_1`, `toggle_setting_2`, `activity`, `subtype`, `edit_options`) VALUES ('Clinical_Note_Type','general_note','General Note',40,0,0,'','LOINC:34109-9','',0,0,1,'',1);
588 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`, `codes`, `toggle_setting_1`, `toggle_setting_2`, `activity`, `subtype`, `edit_options`) VALUES ('Clinical_Note_Type','discharge_summary','Discharge Summary Note',50,0,0,'','LOINC:18842-5','',0,0,1,'',1);
589 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`, `codes`, `toggle_setting_1`, `toggle_setting_2`, `activity`, `subtype`, `edit_options`) VALUES ('Clinical_Note_Type','procedure_note','Procedure Note',60,0,0,'','LOINC:28570-0','',0,0,1,'',1);
590 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`, `codes`, `toggle_setting_1`, `toggle_setting_2`, `activity`, `subtype`, `edit_options`) VALUES ('Clinical_Note_Type','consultation_note','Consultation Note',70,0,0,'','LOINC:81222-2','',0,0,1,'',1);
591 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`, `codes`, `toggle_setting_1`, `toggle_setting_2`, `activity`, `subtype`, `edit_options`) VALUES ('Clinical_Note_Type','imaging_narrative','Imaging Narrative',80,0,0,'','LOINC:28570-0','',0,0,1,'',1);
592 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`, `codes`, `toggle_setting_1`, `toggle_setting_2`, `activity`, `subtype`, `edit_options`) VALUES ('Clinical_Note_Type','laboratory_report_narrative','Laboratory Report Narrative',90,0,0,'','','',0,0,1,'',1);
593 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`, `codes`, `toggle_setting_1`, `toggle_setting_2`, `activity`, `subtype`, `edit_options`) VALUES ('Clinical_Note_Type','pathology_report_narrative','Pathology Report Narrative',100,0,0,'','','',0,0,1,'',1);
596 #---------- Migrate old form_clinical_notes to form_clinic_note if it is installed ----------#
597 #IfColumn form_clinical_notes followup_timing
598 ALTER TABLE `form_clinical_notes` RENAME TO `form_clinic_note`;
599 UPDATE `forms` SET `form_name` = 'Clinic Note' WHERE `form_name` = 'Clinical Notes';
600 UPDATE `forms` SET `formdir` = 'clinic_note' WHERE `formdir` = 'clinical_notes';
601 UPDATE `registry` SET `name` = 'Clinic Note' WHERE `name` LIKE 'Clinical Notes%' AND `directory` = 'clinical_notes';
602 UPDATE `registry` SET `directory` = 'clinic_note' WHERE `directory` = 'clinical_notes';
605 #IfNotTable form_clinical_notes
606 CREATE TABLE `form_clinical_notes` (
607 `id` bigint(20) NOT NULL,
608 `date` DATE DEFAULT NULL,
609 `pid` bigint(20) DEFAULT NULL,
610 `encounter` varchar(255) DEFAULT NULL,
611 `user` varchar(255) DEFAULT NULL,
612 `groupname` varchar(255) DEFAULT NULL,
613 `authorized` tinyint(4) DEFAULT NULL,
614 `activity` tinyint(4) DEFAULT NULL,
615 `code` varchar(255) DEFAULT NULL,
618 `external_id` VARCHAR(30) DEFAULT NULL,
619 `clinical_notes_type` varchar(100) DEFAULT NULL
621 INSERT INTO `registry` (`name`, `state`, `directory`, `sql_run`, `unpackaged`, `date`, `priority`, `category`, `nickname`, `patient_encounter`, `therapy_group_encounter`, `aco_spec`) VALUES ('Clinical Notes', 1, 'clinical_notes', 1, 1, '2015-09-09 00:00:00', 0, 'Clinical', '', 1, 0, 'encounters|notes');
624 #IfNotRow ccda_components ccda_components_field medical_devices
625 INSERT INTO `ccda_components` (`ccda_components_id`, `ccda_components_field`, `ccda_components_name`, `ccda_type`) VALUES
626 (23, 'medical_devices', 'Medical Devices', 1),
627 (24, 'goals', 'Goals', 1);
630 #IfNotRow ccda_sections ccda_sections_field medical_devices
631 INSERT INTO `ccda_sections` (`ccda_sections_id`, `ccda_components_id`, `ccda_sections_field`, `ccda_sections_name`, `ccda_sections_req_mapping`) VALUES
632 (46, 3, 'medical_devices', 'Medical Devices', 0),
633 (47, 3, 'goals', 'Goals', 0);
636 #IfNotRow2D list_options list_id lists option_id Care_Team_Status
637 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`) VALUES ('lists', 'Care_Team_Status', 'Care Team Status', '1');
638 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`) VALUES ('Care_Team_Status','active','Active',10,0,0);
639 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`) VALUES ('Care_Team_Status','inactive','Inactive',20,0,0);
640 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`) VALUES ('Care_Team_Status','suspended','Suspended',30,0,0);
641 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`) VALUES ('Care_Team_Status','proposed','Proposed',40,0,0);
642 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`) VALUES ('Care_Team_Status','entered-in-error','Entered In Error',50,0,0);
645 #IfMissingColumn patient_data birth_fname
646 ALTER TABLE `patient_data` ADD `birth_fname` TEXT;
649 #IfMissingColumn patient_data birth_lname
650 ALTER TABLE `patient_data` ADD `birth_lname` TEXT;
653 #IfMissingColumn patient_data birth_mname
654 ALTER TABLE `patient_data` ADD `birth_mname` TEXT;
657 #IfNotRow2D layout_options form_id DEM field_id birth_fname
658 SET @group_id = (SELECT group_id FROM layout_options WHERE field_id='fname' AND form_id='DEM');
659 SET @backup_group_id = (SELECT group_id FROM layout_options WHERE field_id='lname' AND form_id='DEM');
660 SET @seq = (SELECT MAX(seq) FROM layout_options WHERE group_id = IFNULL(@group_id,@backup_group_id) AND form_id='DEM');
661 INSERT INTO `layout_options` (`form_id`,`field_id`,`group_id`,`title`,`seq`,`data_type`,`uor`,`fld_length`,`max_length`,`list_id`,`titlecols`,`datacols`,`default_value`,`edit_options`,`description`,`fld_rows`) VALUES ('DEM', 'birth_fname', IFNULL(@group_id,@backup_group_id), 'Birth Name', @seq+1, 2, 1, 10, 63, '', 1, 1, '', 'C', 'Birth First Name', 0);
662 INSERT INTO `layout_options` (`form_id`,`field_id`,`group_id`,`title`,`seq`,`data_type`,`uor`,`fld_length`,`max_length`,`list_id`,`titlecols`,`datacols`,`default_value`,`edit_options`,`description`,`fld_rows`) VALUES ('DEM', 'birth_mname', IFNULL(@group_id,@backup_group_id), '', @seq+2, 2, 1, 2, 63, '', 0, 0, '', 'C', 'Birth Middle Name', 0);
663 INSERT INTO `layout_options` (`form_id`,`field_id`,`group_id`,`title`,`seq`,`data_type`,`uor`,`fld_length`,`max_length`,`list_id`,`titlecols`,`datacols`,`default_value`,`edit_options`,`description`,`fld_rows`) VALUES ('DEM', 'birth_lname', IFNULL(@group_id,@backup_group_id), '', @seq+3, 2, 1, 10, 63, '', 0, 0, '', 'C', 'Birth Last Name', 0);
666 #IfNotRow2D list_options list_id Clinical_Note_Type option_id evaluation_note
667 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`, `codes`, `toggle_setting_1`, `toggle_setting_2`, `activity`, `subtype`, `edit_options`) VALUES ('Clinical_Note_Type','evaluation_note','Evaluation Note',5,0,0,'','LOINC:51848-0','',0,0,1,'',1);
670 #IfNotRow2D list_options list_id Plan_of_Care_Type option_id goal
671 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`, `codes`, `activity`, `toggle_setting_1`, `toggle_setting_2`, `subtype`) VALUES('Plan_of_Care_Type','goal','Goal','6','0','0','','GOL','','1','0','0','');
674 #IfNotIndex audit_details audit_master_id
675 CREATE INDEX `audit_master_id` ON `audit_details` (`audit_master_id`);
678 #IfNotRow2D list_options list_id Plan_of_Care_Type option_id health_concern
679 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`, `codes`, `activity`, `toggle_setting_1`, `toggle_setting_2`, `subtype`) VALUES('Plan_of_Care_Type','health_concern','Health Concern','7','0','0','','ACT','','1','0','0','');
680 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`, `codes`, `activity`, `toggle_setting_1`, `toggle_setting_2`, `subtype`) VALUES('Plan_of_Care_Type','medication','Medication','8','0','0','','INT','','1','0','0','');
683 #IfMissingColumn form_vitals oxygen_flow_rate
684 ALTER TABLE `form_vitals` ADD `oxygen_flow_rate` FLOAT(5,2) NULL DEFAULT '0.00';
687 #IfMissingColumn form_clinical_notes note_related_to
688 ALTER TABLE `form_clinical_notes` ADD `note_related_to` TEXT COMMENT 'Reference to lists id for note relationships(json)';
691 #IfMissingColumn form_care_plan note_related_to
692 ALTER TABLE `form_care_plan` ADD `note_related_to` TEXT COMMENT 'Reference to lists id for note relationships(json)';
695 #IfNotTable insurance_type_codes
696 CREATE TABLE `insurance_type_codes` (
697 `id` int(2) NOT NULL,
698 `type` varchar(60) NOT NULL,
703 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('1','Other HCFA','16');
704 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('2','Medicare Part B','MB');
705 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('3','Medicaid','MC');
706 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('4','ChampUSVA','CH');
707 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('5','ChampUS','CH');
708 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('6','Blue Cross Blue Shield','BL');
709 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('7','FECA','16');
710 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('8','Self Pay','09');
711 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('9','Central Certification','10');
712 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('10','Other Non-Federal Programs','11');
713 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('11','Preferred Provider Organization (PPO)','12');
714 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('12','Point of Service (POS)','13');
715 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('13','Exclusive Provider Organization (EPO)','14');
716 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('14','Indemnity Insurance','15');
717 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('15','Health Maintenance Organization (HMO) Medicare Risk','16');
718 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('16','Automobile Medical','AM');
719 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('17','Commercial Insurance Co.','CI');
720 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('18','Disability','DS');
721 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('19','Health Maintenance Organization','HM');
722 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('20','Liability','LI');
723 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('21','Liability Medical','LM');
724 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('22','Other Federal Program','OF');
725 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('23','Title V','TV');
726 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('24','Veterans Administration Plan','VA');
727 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('25','Workers Compensation Health Plan','WC');
728 INSERT INTO insurance_type_codes(`id`,`type`,`claim_type`) VALUES ('26','Mutually Defined','ZZ');
731 #IfNotColumnTypeDefault insurance_companies alt_cms_id varchar(15) NULL
732 ALTER TABLE `insurance_companies` MODIFY `alt_cms_id` varchar(15) NULL;
735 #IfMissingColumn form_vitals uuid
736 ALTER TABLE `form_vitals` ADD `uuid` binary(16) DEFAULT NULL AFTER `id`;
739 #IfNotIndex form_vitals uuid
740 CREATE UNIQUE INDEX `uuid` ON `form_vitals` (`uuid`);
743 #IfUuidNeedUpdate form_vitals
746 #IfMissingColumn uuid_mapping resource_path
747 ALTER TABLE `uuid_mapping` ADD `resource_path` VARCHAR(255) DEFAULT NULL;
750 #IfMissingColumn form_vitals ped_weight_height
751 ALTER TABLE `form_vitals` ADD `ped_weight_height` FLOAT(4,1) DEFAULT '0.00';
754 #IfMissingColumn form_vitals ped_bmi
755 ALTER TABLE `form_vitals` ADD `ped_bmi` FLOAT(4,1) DEFAULT '0.00';
758 #IfMissingColumn form_vitals ped_head_circ
759 ALTER TABLE `form_vitals` ADD `ped_head_circ` FLOAT(4,1) DEFAULT '0.00';
762 #IfMissingColumn history_data uuid
763 ALTER TABLE `history_data` ADD `uuid` binary(16) DEFAULT NULL AFTER `id`;
766 #IfNotIndex history_data uuid
767 CREATE UNIQUE INDEX `uuid` ON `history_data` (`uuid`);
770 #IfUuidNeedUpdate history_data
773 #IfMissingColumn form_clinical_notes form_id
774 ALTER TABLE `form_clinical_notes` CHANGE `id` `form_id` bigint(20) NOT NULL;
775 ALTER TABLE `form_clinical_notes` ADD COLUMN `id` bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;
778 #IfMissingColumn form_clinical_notes uuid
779 ALTER TABLE `form_clinical_notes` ADD `uuid` binary(16) DEFAULT NULL AFTER `id`;
782 #IfNotIndex form_clinical_notes uuid
783 CREATE UNIQUE INDEX `uuid` ON `form_clinical_notes` (`uuid`);
786 #IfUuidNeedUpdate form_clinical_notes
789 #IfMissingColumn documents uuid
790 ALTER TABLE `documents` ADD `uuid` binary(16) DEFAULT NULL AFTER `id`;
793 #IfNotIndex documents uuid
794 CREATE UNIQUE INDEX `uuid` ON `documents` (`uuid`);
797 #IfUuidNeedUpdate documents
800 #IfNotRow list_options list_id Clinical_Note_Category
801 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`
802 , `notes`, `codes`, `toggle_setting_1`, `toggle_setting_2`, `activity`, `subtype`, `edit_options`)
804 ('lists','Clinical_Note_Category','Clinical Note Category',1,0,0,'','',0,0,0,1,'',1);
805 INSERT INTO `list_options`(`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`
806 , `notes`, `codes`, `toggle_setting_1`, `toggle_setting_2`, `activity`, `subtype`, `edit_options`, `timestamp`)
808 ('Clinical_Note_Category','cardiology','Cardiology',10,0,0,'','LOINC:LP29708-2',0,0,0,1,'',1,NOW()),
809 ('Clinical_Note_Category','pathology','Pathology',20,0,0,'','LOINC:LP7839-6',0,0,0,1,'',1,NOW()),
810 ('Clinical_Note_Category','radiology','Radiology',30,0,0,'','LOINC:LP29684-5',0,0,0,1,'',1,NOW());
813 #IfMissingColumn form_clinical_notes clinical_notes_category
814 ALTER TABLE `form_clinical_notes` ADD COLUMN `clinical_notes_category` varchar(100) DEFAULT NULL;
818 #IfRow3D list_options list_id Clinical_Note_Type option_id consultation_note notes LOINC:11488-4
819 UPDATE `list_options` SET notes="LOINC:11488-4" WHERE list_id="Clinical_Note_Type" AND option_id="consultation_note" AND notes="LOINC:81222-2";
822 #IfMissingColumn procedure_report uuid
823 ALTER TABLE `procedure_report` ADD `uuid` binary(16) DEFAULT NULL AFTER `procedure_report_id`;
826 #IfNotIndex procedure_report uuid
827 CREATE UNIQUE INDEX `uuid` ON `procedure_report` (`uuid`);
830 #IfUuidNeedUpdate procedure_report
833 #IfMissingColumn procedure_providers uuid
834 ALTER TABLE `procedure_providers` ADD `uuid` binary(16) DEFAULT NULL AFTER `ppid`;
837 #IfNotIndex procedure_providers uuid
838 CREATE UNIQUE INDEX `uuid` ON `procedure_providers` (`uuid`);
841 #IfUuidNeedUpdate procedure_providers
844 #IfMissingColumn patient_data dupscore
845 ALTER TABLE `patient_data` ADD COLUMN `dupscore` INT NOT NULL default -9;
848 #IfMissingColumn procedure_type procedure_type_name
849 ALTER TABLE `procedure_type` ADD `procedure_type_name` VARCHAR(64) NULL;
852 #IfNotIndex external_procedures ep_pid
853 CREATE INDEX `ep_pid` ON `external_procedures` (`ep_pid`);
856 #IfNotIndex users abook_type
857 CREATE INDEX `abook_type` ON `users` (`abook_type`);
861 #IfNotIndex procedure_type ptype_procedure_code
862 ALTER TABLE `procedure_type` ADD INDEX `ptype_procedure_code`(`procedure_code`);
865 #IfNotTable form_vital_details
866 CREATE TABLE `form_vital_details` (
867 `id` bigint(20) NOT NULL AUTO_INCREMENT,
868 `form_id` bigint(20) NOT NULL COMMENT 'FK to vital_forms.id',
869 `vitals_column` varchar(64) NOT NULL COMMENT 'Column name from form_vitals',
870 `interpretation_list_id` varchar(100) DEFAULT NULL COMMENT 'FK to list_options.list_id for observation_interpretation',
871 `interpretation_option_id` varchar(100) DEFAULT NULL COMMENT 'FK to list_options.option_id for observation_interpretation',
872 `interpretation_codes` varchar(255) DEFAULT NULL COMMENT 'Archived original codes value from list_options observation_interpretation',
873 `interpretation_title` varchar(255) DEFAULT NULL COMMENT 'Archived original title value from list_options observation_interpretation',
875 KEY `fk_form_id` (`form_id`),
876 KEY `fk_list_options_id` (`interpretation_list_id`, `interpretation_option_id`)
877 ) ENGINE=InnoDB COMMENT='Detailed information of each vital_forms observation column';
880 #IfNotRow2D list_options list_id lists option_id vitals-interpretation
881 INSERT INTO list_options (list_id,option_id,title, seq, is_default, option_value) VALUES ('lists','vitals-interpretation','Observation Interpretation',0, 1, 0);
882 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('vitals-interpretation','N','Normal',10,0,1);
883 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('vitals-interpretation','H','High',20,0,1);
884 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('vitals-interpretation','L','Low',30,0,1);
885 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('vitals-interpretation','A','Abnormal',40,0,1);
886 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('vitals-interpretation','AA','Critical abnormal',50,0,1);
887 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('vitals-interpretation','HH','Critical high',60,0,1);
888 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('vitals-interpretation','LL','Critical low',70,0,1);
889 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('vitals-interpretation','HU','Significantly high',80,0,1);
890 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('vitals-interpretation','LU','Significantly low',90,0,1);
894 #IfMappingUuidNeedUpdate
897 #IfRow2D list_options list_id page_validation option_id messages#new_note
898 UPDATE `list_options` SET `notes` = '{"form_datetime":{"futureDate":{"message": "Must be future date"}}, "reply_to":{"presence": {"message": "Please choose a patient"}}, "note":{"presence": {"message": "Please enter a note"}}}' where option_id = 'messages#new_note';