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 -- arguments: table_name colname
65 -- behavior: If the table table_name does have a row where colname is null, the block will be executed.
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.
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
78 -- all blocks are terminated with a #EndIf statement.
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.
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.
98 -- behavior: can take a long time.
100 -- #IfDocumentNamingNeeded
101 -- desc: populate name field with document names.
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.
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,
127 `code` varchar(255) DEFAULT NULL,
129 `questionnaire` longtext,
131 UNIQUE KEY `uuid` (`uuid`),
132 KEY `search` (`name`,`questionnaire_id`)
136 -- At this point below table was never used. Simply recreating with additions
137 #IfMissingColumn questionnaire_response response_id
138 DROP TABLE `questionnaire_response`;
141 #IfMissingColumn questionnaire_repository lform
142 ALTER TABLE `questionnaire_repository` ADD `lform` LONGTEXT;
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.';
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,
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,
166 `lform_response` longtext,
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);
172 #IfMissingColumn openemr_postcalendar_events uuid
173 ALTER TABLE `openemr_postcalendar_events` ADD `uuid` binary(16) DEFAULT NULL;
176 #IfNotIndex openemr_postcalendar_events uuid
177 CREATE UNIQUE INDEX `uuid` ON `openemr_postcalendar_events` (`uuid`);
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');
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';
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');
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',
220 UNIQUE KEY `uuid` (`uuid`),
221 KEY `response_index` (`response_id`, `patient_id`, `questionnaire_id`, `questionnaire_name`)
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';
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);
235 #IfMissingColumn layout_group_properties grp_unchecked
236 ALTER TABLE `layout_group_properties` ADD `grp_unchecked` tinyint(1) NOT NULL DEFAULT 0;
239 #IfMissingColumn form_encounter in_collection
240 ALTER TABLE `form_encounter` ADD `in_collection` tinyint(1) DEFAULT NULL;
246 #IfRow2D categories aco_spec patients|docs name Patient Information
247 UPDATE `categories` SET `aco_spec` = 'patients|demo' WHERE `name` = 'Patient Information';
250 #IfRow2D categories aco_spec patients|docs name Patient ID card
251 UPDATE `categories` SET `aco_spec` = 'patients|demo' WHERE `name` = 'Patient ID card';
254 #IfRow2D categories aco_spec patients|docs name Patient Photograph
255 UPDATE `categories` SET `aco_spec` = 'patients|demo' WHERE `name` = 'Patient Photograph';
258 #IfNotColumnType audit_details field_value LONGTEXT
259 ALTER TABLE `audit_details` CHANGE `field_value` `field_value` LONGTEXT COMMENT 'openemr table field value';
262 #IfMissingColumn audit_master is_unstructured_document
263 ALTER TABLE `audit_master` ADD `is_unstructured_document` BOOLEAN NULL DEFAULT FALSE;
266 #IfNotColumnType ccda ccda_data LONGTEXT
267 ALTER TABLE `ccda` CHANGE `ccda_data` `ccda_data` LONGTEXT;
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';
274 #IfRow2D registry directory procedure_order category Administrative
275 UPDATE `registry` SET `category` = 'Orders' WHERE `directory` = 'procedure_order' AND `category` = 'Administrative';