Commit generated changelog for 7.0.2.1 (#7458)
[openemr.git] / sql / 7_0_0-to-7_0_1_upgrade.sql
blob71ef2ef2b9935085b13926b8019279d3a23c73c2
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 --  #IfColumn
13 --    arguments: table_name colname
14 --    behavior:  if the table and column exist,  the block will be executed
16 --  #IfMissingColumn
17 --    arguments: table_name colname
18 --    behavior:  if the table exists but the column does not,  the block will be executed
20 --  #IfNotColumnType
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
28 --  #IfNotRow
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.
32 --  #IfNotRow2D
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.
36 --  #IfNotRow3D
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.
40 --  #IfNotRow4D
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.
44 --  #IfNotRow2Dx2
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.
51 --  #IfRow
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.
55 --  #IfRow2D
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.
59 --  #IfRow3D
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.
63 --  #IfRowIsNull
64 --    arguments: table_name colname
65 --    behavior:  If the table table_name does have a row where colname is null, the block will be executed.
67 --  #IfIndex
68 --    desc:      This function is most often used for dropping of indexes/keys.
69 --    arguments: table_name colname
70 --    behavior:  If the table and index exist the relevant statements are executed, otherwise not.
72 --  #IfNotIndex
73 --    desc:      This function will allow adding of indexes/keys.
74 --    arguments: table_name colname
75 --    behavior:  If the index does not exist, it will be created
77 --  #EndIf
78 --    all blocks are terminated with a #EndIf statement.
80 --  #IfNotListReaction
81 --    Custom function for creating Reaction List
83 --  #IfNotListOccupation
84 --    Custom function for creating Occupation List
86 --  #IfTextNullFixNeeded
87 --    desc: convert all text fields without default null to have default null.
88 --    arguments: none
90 --  #IfTableEngine
91 --    desc:      Execute SQL if the table has been created with given engine specified.
92 --    arguments: table_name engine
93 --    behavior:  Use when engine conversion requires more than one ALTER TABLE
95 --  #IfInnoDBMigrationNeeded
96 --    desc: find all MyISAM tables and convert them to InnoDB.
97 --    arguments: none
98 --    behavior: can take a long time.
100 --  #IfDocumentNamingNeeded
101 --    desc: populate name field with document names.
102 --    arguments: none
104 --  #IfUpdateEditOptionsNeeded
105 --    desc: Change Layout edit options.
106 --    arguments: mode(add or remove) layout_form_id the_edit_option comma_separated_list_of_field_ids
108 --  #IfVitalsDatesNeeded
109 --    desc: Change date from zeroes to date of vitals form creation.
110 --    arguments: none
112 #IfNotTable questionnaire_repository
113 CREATE TABLE `questionnaire_repository` (
114     `id` bigint(21) UNSIGNED NOT NULL AUTO_INCREMENT,
115     `uuid` binary(16) DEFAULT NULL,
116     `questionnaire_id` varchar(255) DEFAULT NULL,
117     `provider` int(11) UNSIGNED DEFAULT NULL,
118     `version` int(11) NOT NULL DEFAULT 1,
119     `created_date` datetime DEFAULT current_timestamp(),
120     `modified_date` datetime DEFAULT current_timestamp(),
121     `name` varchar(255) DEFAULT NULL,
122     `type` varchar(63) NOT NULL DEFAULT 'Questionnaire',
123     `profile` varchar(255) DEFAULT NULL,
124     `active` tinyint(2) NOT NULL DEFAULT 1,
125     `status` varchar(31) DEFAULT NULL,
126     `source_url` text,
127     `code` varchar(255) DEFAULT NULL,
128     `code_display` text,
129     `questionnaire` longtext,
130     PRIMARY KEY (`id`),
131     UNIQUE KEY `uuid` (`uuid`),
132     KEY `search` (`name`,`questionnaire_id`)
133 ) ENGINE=InnoDB;
134 #EndIf
136 -- At this point below table was never used. Simply recreating with additions
137 #IfMissingColumn questionnaire_response response_id
138 DROP TABLE `questionnaire_response`;
139 #EndIf
141 #IfMissingColumn questionnaire_repository lform
142 ALTER TABLE `questionnaire_repository` ADD `lform` LONGTEXT;
143 #EndIf
145 #IfMissingColumn registry form_foreign_id
146 ALTER TABLE `registry` ADD `form_foreign_id` BIGINT(21) NULL DEFAULT NULL COMMENT 'An id to a form repository. Primarily questionnaire_repository.';
147 #EndIf
149 #IfNotTable form_questionnaire_assessments
150 CREATE TABLE `form_questionnaire_assessments` (
151   `id` bigint(21) NOT NULL AUTO_INCREMENT,
152   `date` datetime DEFAULT current_timestamp(),
153   `last_date` datetime DEFAULT NULL,
154   `pid` bigint(21) NOT NULL DEFAULT 0,
155   `user` bigint(21) DEFAULT NULL,
156   `groupname` varchar(255) DEFAULT NULL,
157   `authorized` tinyint(4) NOT NULL DEFAULT 0,
158   `activity` tinyint(4) NOT NULL DEFAULT 1,
159   `copyright` text,
160   `form_name` varchar(255) DEFAULT NULL,
161   `code` varchar(31) DEFAULT NULL,
162   `code_type` varchar(31) DEFAULT "LOINC",
163   `questionnaire` longtext,
164   `questionnaire_response` longtext,
165   `lform` longtext,
166   `lform_response` longtext,
167   PRIMARY KEY (`id`)
168 ) ENGINE=InnoDB;
169 INSERT INTO `registry` (`name`, `state`, `directory`, `sql_run`, `unpackaged`, `date`, `priority`, `category`, `nickname`, `patient_encounter`, `therapy_group_encounter`, `aco_spec`, `form_foreign_id`) VALUES ('New Questionnaire', 1, 'questionnaire_assessments', 1, 1, '2022-08-04 14:45:15', 0, 'Questionnaires', '', 1, 0, 'admin|forms', NULL);
170 #EndIf
172 #IfMissingColumn openemr_postcalendar_events uuid
173 ALTER TABLE `openemr_postcalendar_events` ADD `uuid` binary(16) DEFAULT NULL;
174 #EndIf
176 #IfNotIndex openemr_postcalendar_events uuid
177 CREATE UNIQUE INDEX `uuid` ON `openemr_postcalendar_events` (`uuid`);
178 #EndIf
180 #IfNotRow2D list_options list_id drug_route option_id bymouth
181 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `notes`, `codes`) VALUES ('drug_route', 'bymouth', 'By Mouth', 1, 0, 'PO', 'NCI-CONCEPT-ID:C38288');
182 #EndIf
184 #IfNotColumnType prescriptions route VARCHAR(100)
185 ALTER TABLE `prescriptions` CHANGE `route` `route` VARCHAR(100) NULL DEFAULT NULL Comment 'Max size 100 characters is same max as immunizations';
186 #EndIf
188 #IfNotRow4D supported_external_dataloads load_type ICD10 load_source CMS load_release_date 2022-10-01 load_filename 2023 Code Descriptions in Tabular Order.zip
189 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES
190     ('ICD10', 'CMS', '2022-10-01', '2023 Code Descriptions in Tabular Order.zip', 'a2bd2e87d6fac3f861b03dba9ca87cbc');
191 #EndIf
193 #IfNotRow4D supported_external_dataloads load_type ICD10 load_source CMS load_release_date 2022-10-01 load_filename Zip File 3 2023 ICD-10-PCS Codes File.zip
194 INSERT INTO `supported_external_dataloads` (`load_type`, `load_source`, `load_release_date`, `load_filename`, `load_checksum`) VALUES
195     ('ICD10', 'CMS', '2022-10-01', 'Zip File 3 2023 ICD-10-PCS Codes File.zip', 'a4c0e6026557d770dc3d994718acaa21');
197 #IfNotTable questionnaire_response
198 CREATE TABLE `questionnaire_response` (
199  `id` bigint(21) NOT NULL AUTO_INCREMENT,
200  `uuid` binary(16) DEFAULT NULL,
201  `response_id` varchar(255) DEFAULT NULL COMMENT 'A globally unique id for answer set. String version of UUID',
202  `questionnaire_foreign_id` bigint(21) DEFAULT NULL COMMENT 'questionnaire_repository id for subject questionnaire',
203  `questionnaire_id` varchar(255) DEFAULT NULL COMMENT 'Id for questionnaire content. String version of UUID',
204  `questionnaire_name` varchar(255) DEFAULT NULL,
205  `patient_id` int(11) DEFAULT NULL,
206  `encounter` int(11) DEFAULT NULL COMMENT 'May or may not be associated with an encounter',
207  `audit_user_id` int(11) DEFAULT NULL,
208  `creator_user_id` int(11) DEFAULT NULL COMMENT 'user id if answers are provider',
209  `create_time` datetime DEFAULT current_timestamp(),
210  `last_updated` datetime DEFAULT NULL,
211  `version` int(11) NOT NULL DEFAULT 1,
212  `status` varchar(63) DEFAULT NULL COMMENT 'form current status. completed,active,incomplete',
213  `questionnaire` longtext COMMENT 'the subject questionnaire json',
214  `questionnaire_response` longtext COMMENT 'questionnaire response json',
215  `form_response` longtext COMMENT 'lform answers array json',
216  `form_score` int(11) DEFAULT NULL COMMENT 'Arithmetic scoring of questionnaires',
217  `tscore` double DEFAULT NULL COMMENT 'T-Score',
218  `error` double DEFAULT NULL COMMENT 'Standard error for the T-Score',
219  PRIMARY KEY (`id`),
220  UNIQUE KEY `uuid` (`uuid`),
221  KEY `response_index` (`response_id`, `patient_id`, `questionnaire_id`, `questionnaire_name`)
222 ) ENGINE=InnoDB;
223 #EndIf
225 #IfMissingColumn form_questionnaire_assessments response_id
226 ALTER TABLE `form_questionnaire_assessments` CHANGE `last_date` `response_id` TEXT COMMENT 'The foreign id to the questionnaire_response repository';
227 ALTER TABLE `form_questionnaire_assessments` CHANGE `code` `response_meta` TEXT COMMENT 'json meta data for the response resource';
228 ALTER TABLE `form_questionnaire_assessments` CHANGE `code_type` `questionnaire_id` TEXT COMMENT 'The foreign id to the questionnaire_repository';
229 #EndIf
231 #IfNotRow2D list_options list_id Document_Template_Categories option_id questionnaire
232 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','questionnaire','Questionnaires',10,0,0,'','','',0,0,1);
233 #EndIf
235 #IfMissingColumn layout_group_properties grp_unchecked
236 ALTER TABLE `layout_group_properties` ADD `grp_unchecked` tinyint(1) NOT NULL DEFAULT 0;
237 #EndIf
239 #IfMissingColumn form_encounter in_collection
240 ALTER TABLE `form_encounter` ADD `in_collection` tinyint(1) DEFAULT NULL;
241 #EndIf
243 #IfVitalsDatesNeeded
244 #EndIf
246 #IfRow2D categories aco_spec patients|docs name Patient Information
247 UPDATE `categories` SET `aco_spec` = 'patients|demo' WHERE `name` = 'Patient Information';
248 #EndIf
250 #IfRow2D categories aco_spec patients|docs name Patient ID card
251 UPDATE `categories` SET `aco_spec` = 'patients|demo' WHERE `name` = 'Patient ID card';
252 #EndIf
254 #IfRow2D categories aco_spec patients|docs name Patient Photograph
255 UPDATE `categories` SET `aco_spec` = 'patients|demo' WHERE `name` = 'Patient Photograph';
256 #EndIf
258 #IfNotColumnType audit_details field_value LONGTEXT
259 ALTER TABLE `audit_details` CHANGE `field_value` `field_value` LONGTEXT COMMENT 'openemr table field value';
260 #EndIf
262 #IfMissingColumn audit_master is_unstructured_document
263 ALTER TABLE `audit_master` ADD `is_unstructured_document` BOOLEAN NULL DEFAULT FALSE;
264 #EndIf
266 #IfNotColumnType ccda ccda_data LONGTEXT
267 ALTER TABLE `ccda` CHANGE `ccda_data` `ccda_data` LONGTEXT;
268 #EndIf
270 #IfNotRow2D background_services name phimail require_once /library/direct_message_check.inc.php
271 UPDATE `background_services` SET `require_once` = '/library/direct_message_check.inc.php' WHERE `name` = 'phimail';
272 #EndIf
274 #IfRow2D registry directory procedure_order category Administrative
275 UPDATE `registry` SET `category` = 'Orders' WHERE `directory` = 'procedure_order' AND `category` = 'Administrative';
276 #EndIf
278 #IfMissingColumn insurance_data date_end
279 ALTER TABLE `insurance_data` ADD `date_end` date NULL;
280 #EndIf
282 #IfNotColumnType form_questionnaire_assessments user VARCHAR(255)
283 ALTER TABLE `form_questionnaire_assessments` CHANGE `user` `user` VARCHAR(255) NULL DEFAULT NULL;
284 #EndIf
286 #IfMissingColumn module_configuration date_created
287 ALTER TABLE `module_configuration` ADD COLUMN `date_created` DATETIME DEFAULT NULL COMMENT 'Datetime the record was created';
288 #EndIf
290 #IfRow2D globals gl_name login_page_layout gl_value center
291 UPDATE `globals` SET `gl_value` = 'login/layouts/vertical_box.html.twig' WHERE `gl_name` = 'login_page_layout' AND `gl_value` = 'center';
292 #EndIf
294 #IfRow2D globals gl_name login_page_layout gl_value left
295 UPDATE `globals` SET `gl_value` = 'login/layouts/horizontal_box_left_logo.html.twig' WHERE `gl_name` = 'login_page_layout' AND `gl_value` = 'left';
296 #EndIf
298 #IfRow2D globals gl_name login_page_layout gl_value right
299 UPDATE `globals` SET `gl_value` = 'login/layouts/horizontal_band_right_logo.html.twig' WHERE `gl_name` = 'login_page_layout' AND `gl_value` = 'right';
300 #EndIf
302 #IfMissingColumn ar_activity payer_claim_number
303 ALTER TABLE `ar_activity` ADD `payer_claim_number` VARCHAR(30) DEFAULT NULL;
304 #EndIf
306 #IfNotTable onetime_auth
307 CREATE TABLE `onetime_auth` (
308   `id` int(11) NOT NULL AUTO_INCREMENT,
309   `pid` bigint(20) DEFAULT NULL,
310   `create_user_id` bigint(20) DEFAULT NULL,
311   `context` varchar(64) DEFAULT NULL,
312   `access_count` int(11) NOT NULL DEFAULT 0,
313   `remote_ip` varchar(32) DEFAULT NULL,
314   `onetime_pin` varchar(10) DEFAULT NULL COMMENT 'Max 10 numeric. Default 6',
315   `onetime_token` tinytext,
316   `redirect_url` tinytext,
317   `expires` int(11) DEFAULT NULL,
318   `date_created` datetime DEFAULT current_timestamp(),
319   `last_accessed` datetime DEFAULT NULL,
320   PRIMARY KEY (`id`),
321   KEY `pid` (`pid`,`onetime_token`(255))
322 ) ENGINE=InnoDB;
323 #EndIf