fix: ccda zip import and php warnings and deprecations (#7416)
[openemr.git] / sql / 6_1_0-to-7_0_0_upgrade.sql
blob9cc4f7f83dd0f89b8374fd012d6708fd04807478
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 #IfNotRow2D layout_options form_id DEM field_id prevent_portal_apps
109 SET @group_id = (SELECT `group_id` FROM layout_options WHERE field_id='allow_patient_portal' AND form_id='DEM');
110 SET @seq_start := 0;
111 UPDATE `layout_options` SET `seq` = (@seq_start := @seq_start+1)*10 WHERE group_id = @group_id AND form_id='DEM' ORDER BY `seq`;
112 SET @seq_add_to = (SELECT seq FROM layout_options WHERE group_id = @group_id AND field_id='allow_patient_portal' AND form_id='DEM');
113 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','prevent_portal_apps',@group_id,'Prevent API Access',@seq_add_to+5,21,1,0,0,'',1,1,'','','Check to not allow third party API access.',0);
114 ALTER TABLE `patient_data` ADD `prevent_portal_apps` TEXT;
115 #Endif
117 #IfMissingColumn clinical_rules bibliographic_citation
118 ALTER TABLE `clinical_rules` ADD COLUMN `bibliographic_citation` VARCHAR(255) NOT NULL DEFAULT '';
119 #EndIf
121 #IfMissingColumn clinical_rules linked_referential_cds
122 ALTER TABLE `clinical_rules` ADD COLUMN `linked_referential_cds` VARCHAR(50) NOT NULL DEFAULT '';
123 #EndIf
125 #IfMissingColumn clinical_rules amc_2015_flag
126 ALTER TABLE `clinical_rules` ADD `amc_2015_flag` TINYINT(1) NULL DEFAULT NULL
127     COMMENT '2015 Automated Measure Calculation flag for (unable to customize per patient)';
128 #EndIf
130 #IfMissingColumn clinical_rules amc_code_2015
131 ALTER TABLE `clinical_rules` ADD `amc_code_2015` VARCHAR(30) NOT NULL DEFAULT '' COMMENT 'Automated Measure Calculation 2014 identifier (MU rule)';
132 #EndIf
134 #IfMissingColumn patient_access_onsite date_created
135 -- We add the date time so we know exactly when the credentials were generated without having to lookup in the audit log
136 ALTER TABLE patient_access_onsite ADD `date_created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP;
137 #EndIf
139 #IfNotRow clinical_rules id patient_access_amc
140 INSERT INTO `clinical_rules` (`id`, `pid`, `active_alert_flag`, `passive_alert_flag`, `cqm_flag`, `cqm_2011_flag`,
141                               `cqm_2014_flag`, `cqm_nqf_code`, `cqm_pqri_code`, `amc_flag`, `amc_2011_flag`,
142                               `amc_2014_flag`, `amc_code`, `amc_code_2014`, `amc_code_2015`, `amc_2014_stage1_flag`,
143                               `amc_2014_stage2_flag`, `amc_2015_flag`, `patient_reminder_flag`, `developer`,
144                               `funding_source`, `release_version`, `web_reference`, `access_control`,
145                               `bibliographic_citation`, `linked_referential_cds`)
146     VALUES ('patient_access_amc', '0', '0', '0', '0', '0', '0', '', '', '1', '0', '0', '', ''
147     , '170.315(g)(1)/(2)–2c', '0', '0', '1', '0', '', '', '', '', 'patients:med', '', '');
148 #EndIf
150 #IfNotRow2D list_options list_id clinical_rules option_id patient_access_amc
151 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`
152                             , `codes`, `toggle_setting_1`, `toggle_setting_2`)
153     VALUES ('clinical_rules', 'patient_access_amc', 'Provide Patients Electronic Access to Their Health Information - API Access'
154     , 240, 0, 0, '', '', '', 0, 0);
155 #EndIf
157 #IfRow2D list_options list_id lists option_id ecqm_2021_reporting
158 DELETE FROM list_options WHERE list_id = "ecqm_2021_reporting";
159 DELETE FROM list_options WHERE list_id = 'lists' AND option_id = "ecqm_2021_reporting";
160 #EndIf
162 #IfNotRow2D list_options list_id lists option_id ecqm_2022_reporting
163 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`) VALUES ('lists','ecqm_2022_reporting','eCQM 2022 Performance Period',0,1,0);
164 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS117v10','Childhood Immunization Status',10,0);
165 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS122v10','Diabetes: Hemoglobin A1c (HbA1c) Poor Control (>9%)',20,1);
166 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS124v10','Cervical Cancer Screening',30,1);
167 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS125v10','Breast Cancer Screening',40,1);
168 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS127v10','Pneumococcal Vaccination Status for Older Adults',50,1);
169 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS128v10','Anti-Depressant Medication Management',60,0);
170 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS129v11','Prostate Cancer: Avoidance of Overuse of Bone Scan for Staging Low Risk Prostate Cancer Patients',70,0);
171 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS130v10','Colorectal Cancer Screening',80,1);
172 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS131v10','Diabetes: Eye Exam',90,0);
173 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS133v10','Cataracts: 20/40 or Better Visual Acuity within 90 Days Following Cataract Surgery',95,0);
174 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS134v10','Diabetes: Medical Attention for Nephropathy',100,0);
175 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS135v10','Heart Failure (HF): Angiotensin-Converting Enzyme (ACE) Inhibitor or Angiotensin Receptor Blocker (ARB) or Angiotensin Receptor-Neprilysin Inhibitor (ARNI) Therapy for Left Ventricular Systolic Dysfunction (LVSD)',110,0);
176 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS136v11','Follow-Up Care for Children Prescribed ADHD Medication (ADD)',120,0);
177 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS137v10','Initiation and Engagement of Alcohol and Other Drug Dependence Treatment',130,0);
178 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS138v10','Preventive Care and Screening: Tobacco Use: Screening and Cessation Intervention',140,1);
179 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS139v10','Falls: Screening for Future Fall Risk',150,0);
180 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS142v10','Diabetic Retinopathy: Communication with the Physician Managing Ongoing Diabetes Care',160,0);
181 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS143v10','Primary Open-Angle Glaucoma (POAG): Optic Nerve Evaluation',170,0);
182 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS144v10','Heart Failure (HF): Beta-Blocker Therapy for Left Ventricular Systolic Dysfunction (LVSD)',180,0);
183 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS145v10','Coronary Artery Disease (CAD): Beta-Blocker Therapy – Prior Myocardial Infarction (MI) or Left Ventricular Systolic Dysfunction (LVEF < 40%)',190,0);
184 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS146v10','Appropriate Testing for Pharyngitis',200,0);
185 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS147v11','Preventive Care and Screening: Influenza Immunization',210,1);
186 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS149v10','Dementia: Cognitive Assessment',220,0);
187 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS153v10','Chlamydia Screening for Women',230,0);
188 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS154v10','Appropriate Treatment for Upper Respiratory Infection (URI)',240,0);
189 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS155v10','Weight Assessment and Counseling for Nutrition and Physical `activity` for Children and Adolescents',250,0);
190 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS156v10','Use of High-Risk Medications in Older Adults',260,0);
191 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS157v10','Oncology: Medical and Radiation – Pain Intensity Quantified',280,0);
192 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS159v10','Depression Remission at Twelve Months',290,0);
193 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS161v10','Adult Major Depressive Disorder (MDD): Suicide Risk Assessment',300,0);
194 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS165v10','Controlling High Blood Pressure',310,1);
195 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS177v10','Child and Adolescent Major Depressive Disorder (MDD): Suicide Risk Assessment',320,0);
196 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS22v10','Preventive Care and Screening: Screening for High Blood Pressure and Follow-Up Documented',330,1);
197 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS249v4','Appropriate Use of DXA Scans in Women Under 65 Years Who Do Not Meet the Risk Factor Profile for Osteoporotic Fracture',340,0);
198 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS2v11','Preventive Care and Screening: Screening for Depression and Follow-Up Plan',350,0);
199 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS347v5','Statin Therapy for the Prevention and Treatment of Cardiovascular Disease',360,0);
200 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS349v4','HIV Screening',370,0);
201 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS50v10','Closing the Referral Loop: Receipt of Specialist Report',380,0);
202 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS56v10','Functional Status Assessment for Total Hip Replacement',390,0);
203 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS645v5','Bone Density Evaluation for Patients with Prostate Cancer and Receiving Androgen Deprivation Therapy',400,0);
204 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS646v2','Intravesical Bacillus-Calmette-Guerin for non-muscle invasive bladder cancer',405,0);
205 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS66v10','Functional Status Assessment for Total Knee Replacement',410,0);
206 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS68v11','Documentation of Current Medications in the Medical Record',420,0);
207 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS69v10','Preventive Care and Screening: Body Mass Index (BMI) Screening and Follow-Up Plan',430,1);
208 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS74v11','Primary Caries Prevention Intervention as Offered by Primary Care Providers, including Dentists',440,0);
209 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS75v10','Children Who Have Dental Decay or Cavities',450,0);
210 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS771v3','Urinary Symptom Score Change 6-12 Months After Diagnosis of Benign Prostatic Hyperplasia',460,0);
211 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`) VALUES ('ecqm_2022_reporting','CMS90v11','Functional Status Assessments for Congestive Heart Failure',470,0);
212 #EndIf
214 #IfNotRow2D list_options list_id discharge-disposition option_id home-hospice
215 DELETE FROM list_options WHERE list_id = "discharge-disposition";
216 DELETE FROM list_options WHERE list_id = 'lists' AND option_id = "discharge-disposition";
218 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','discharge-disposition','Discharge Disposition',0,1,0,'',NULL,'',0,0,1);
219 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 ('discharge-disposition','home','Home',10,1,0,'','','SNOMED-CT:10161009',0,0,1);
220 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 ('discharge-disposition','home-hospice','Discharge to home for hospice care',20,0,0,'','','SNOMED-CT:428361000124107',0,0,1);
221 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 ('discharge-disposition','alt-home','Alternative Home',30,0,0,'','','',0,0,1);
222 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 ('discharge-disposition','other-hcf','Other healthcare facility',40,0,0,'','','',0,0,1);
223 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 ('discharge-disposition','hosp','Hospice',50,0,0,'','','SNOMED-CT:428371000124100',0,0,1);
224 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 ('discharge-disposition','long','Long-term care',60,0,0,'','','',0,0,1);
225 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 ('discharge-disposition','aadvice','Left against advice (Finding)',70,0,0,'','','SNOMED-CT:445060000',0,0,1);
226 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 ('discharge-disposition','self-aadvice','Patient self-discharge against medical advice',80,0,0,'','','SNOMED-CT:225928004',0,0,1);
227 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 ('discharge-disposition','exp','Expired',90,0,0,'','','SNOMED-CT:371828006',0,0,1);
228 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 ('discharge-disposition','psy','Psychiatric hospital',100,0,0,'','','',0,0,1);
229 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 ('discharge-disposition','rehab','Rehabilitation',110,0,0,'','','SNOMED-CT:433591000124103',0,0,1);
230 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 ('discharge-disposition','snf','Skilled nursing facility',120,0,0,'','','',0,0,1);
231 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 ('discharge-disposition','comm-hospital','Discharge to community hospital',130,0,0,'','','SNOMED-CT:306701001',0,0,1);
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 ('discharge-disposition','oth','Other',140,0,0,'','','',0,0,1);
233 #EndIf
235 #IfNotRow2D list_options list_id clinical_rules option_id send_sum_2015_amc
236 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`
237                            , `codes`, `toggle_setting_1`, `toggle_setting_2`)
238 VALUES ('clinical_rules', 'send_sum_2015_amc', 'Support Electronic Referral Loops by Sending Health Information'
239        , 240, 0, 0, '', '', '', 0, 0);
240 #EndIf
242 #IfNotRow clinical_rules id send_sum_2015_amc
243 INSERT INTO `clinical_rules` (`id`, `pid`, `active_alert_flag`, `passive_alert_flag`, `cqm_flag`, `cqm_2011_flag`,
244                               `cqm_2014_flag`, `cqm_nqf_code`, `cqm_pqri_code`, `amc_flag`, `amc_2011_flag`,
245                               `amc_2014_flag`, `amc_code`, `amc_code_2014`, `amc_code_2015`, `amc_2014_stage1_flag`,
246                               `amc_2014_stage2_flag`, `amc_2015_flag`, `patient_reminder_flag`, `developer`,
247                               `funding_source`, `release_version`, `web_reference`, `access_control`,
248                               `bibliographic_citation`, `linked_referential_cds`)
249 VALUES ('send_sum_2015_amc', '0', '0', '0', '0', '0', '0', '', '', '1', '0', '0', '', ''
250        , '170.315(g)(1)/(2)–7', '0', '0', '1', '0', '', '', '', '', '', '', '');
251 #EndIf
253 #IfNotRow2D layout_options form_id LBTref field_id billing_facility_id
254 DELETE FROM `layout_options` WHERE `form_id`='LBTref' AND `field_id`='encounter_id' AND `data_type`=53 and `seq`=10;
255 INSERT INTO `layout_options` (`form_id`,`field_id`,`group_id`,`title`,`seq`,`data_type`,`uor`,`fld_length`,`max_length`
256                              ,`list_id`,`titlecols`,`datacols`,`default_value`,`edit_options`,`description`,`fld_rows`)
257 VALUES ('LBTref', 'billing_facility_id', '1', 'Patient Billing Facility', 11, 35, 1, 0, 0, '', 1, 1, '', ''
258        ,'Billing facility that patient claims are billed against', 0);
259 #EndIf
262 #IfMissingColumn report_itemized rule_id
263 ALTER TABLE `report_itemized` ADD COLUMN `rule_id` VARCHAR(31) DEFAULT NULL;
264 #EndIf
266 #IfMissingColumn report_itemized item_details
267 ALTER TABLE `report_itemized` ADD COLUMN `item_details` TEXT;
268 #EndIf
270 #IfMissingColumn ccda transaction_id
271 ALTER TABLE `ccda` ADD COLUMN `transaction_id` BIGINT(20) COMMENT 'fk to transactions referral record';
272 #EndIf
274 #IfMissingColumn form_care_plan date_end
275 ALTER TABLE `form_care_plan` ADD `date_end` DATETIME DEFAULT NULL, ADD `reason_code` VARCHAR(31) DEFAULT NULL, ADD `reason_description` TEXT, ADD `reason_date_low` DATETIME DEFAULT NULL COMMENT 'The date the reason was recorded', ADD `reason_date_high` DATETIME DEFAULT NULL COMMENT 'The date the explanation reason for the care plan entry value ends' ;
276 #EndIf
278 #IfNotColumnType insurance_companies ins_type_code int(11)
279 ALTER TABLE `insurance_companies` CHANGE `ins_type_code` `ins_type_code` INT(11) NULL DEFAULT NULL;
280 ALTER TABLE `insurance_companies` CHANGE `inactive` `inactive` TINYINT(1) NOT NULL DEFAULT '0';
281 #EndIf
283 #IfUpdateEditOptionsNeeded remove DEM C street, street_line_2, city
284 #EndIf
286 #IfUpdateEditOptionsNeeded add DEM U street, street_line_2, city
287 #EndIf
289 #IfNotRow3D layout_options form_id DEM field_id postal_code fld_length 8
290 UPDATE `layout_options` SET `fld_length` = '8' WHERE `layout_options`.`form_id` = 'DEM' AND `layout_options`.`field_id` = 'postal_code';
291 #EndIf
293 #IfNotColumnType form_observation date datetime
294 ALTER TABLE `form_observation` CHANGE `date` `date` DATETIME NULL DEFAULT NULL;
295 ALTER TABLE `form_observation` CHANGE `ob_code` `ob_code` VARCHAR(64) NULL DEFAULT NULL, CHANGE `ob_type` `ob_type` VARCHAR(64) NULL DEFAULT NULL, CHANGE `ob_reason_code` `ob_reason_code` VARCHAR(64) NULL DEFAULT NULL;
296 #EndIf
298 #IfMissingColumn form_care_plan reason_status
299 ALTER TABLE `form_care_plan` ADD `reason_status` VARCHAR(31) NULL DEFAULT NULL;
300 #EndIf
302 #IfNotColumnType lists begdate datetime
303 ALTER TABLE `lists` CHANGE `begdate` `begdate` DATETIME NULL DEFAULT NULL;
304 ALTER TABLE `lists` CHANGE `enddate` `enddate` DATETIME NULL DEFAULT NULL;
305 #EndIf
307 #IfMissingColumn form_observation date_end
308 ALTER TABLE `form_observation` ADD `date_end` DATETIME NULL DEFAULT NULL;
309 #EndIf
311 #IfNotColumnType form_care_plan date datetime
312 ALTER TABLE `form_care_plan` CHANGE `date` `date` DATETIME NULL DEFAULT NULL;
313 #EndIf
315 #IfMissingColumn api_token context
316 ALTER TABLE api_token ADD COLUMN `context` TEXT COMMENT 'context values that change/govern how access token are used';
317 #EndIf
319 #IfRow2D list_options list_id language notes eng
320 CREATE TEMPORARY TABLE lang_updates_610 (notes char(15), twodigit_notes char(2));
321 START TRANSACTION;
322 INSERT INTO lang_updates_610 VALUES
323 ('abk','ab'),
324 ('aar','aa'),
325 ('afr','af'),
326 ('aka','ak'),
327 ('alb(B)|sqi(T)','sq'),
328 ('amh','am'),
329 ('ara','ar'),
330 ('arg','an'),
331 ('arm(B)|hye(T)','hy'),
332 ('asm','as'),
333 ('ava','av'),
334 ('ave','ae'),
335 ('aym','ay'),
336 ('aze','az'),
337 ('bam','bm'),
338 ('bak','ba'),
339 ('baq(B)|eus(T)','eu'),
340 ('bel','be'),
341 ('ben','bn'),
342 ('bih','bh'),
343 ('bis','bi'),
344 ('nob','nb'),
345 ('bos','bs'),
346 ('bre','br'),
347 ('bul','bg'),
348 ('bur(B)|mya(T)','my'),
349 ('cat','ca'),
350 ('khm','km'),
351 ('cha','ch'),
352 ('che','ce'),
353 ('nya','ny'),
354 ('chi(B)|zho(T)','zh'),
355 ('chu','cu'),
356 ('chv','cv'),
357 ('cor','kw'),
358 ('cos','co'),
359 ('cre','cr'),
360 ('hrv','hr'),
361 ('cze(B)|ces(T)','cs'),
362 ('dan','da'),
363 ('div','dv'),
364 ('dut(B)|nld(T)','nl'),
365 ('dzo','dz'),
366 ('eng','en'),
367 ('epo','eo'),
368 ('est','et'),
369 ('ewe','ee'),
370 ('fao','fo'),
371 ('fij','fj'),
372 ('fin','fi'),
373 ('fre(B)|fra(T)','fr'),
374 ('ful','ff'),
375 ('gla','gd'),
376 ('glg','gl'),
377 ('lug','lg'),
378 ('geo(B)|kat(T)','ka'),
379 ('ger(B)|deu(T)','de'),
380 ('gre(B)|ell(T)','el'),
381 ('grn','gn'),
382 ('guj','gu'),
383 ('hat','ht'),
384 ('hau','ha'),
385 ('heb','he'),
386 ('her','hz'),
387 ('hin','hi'),
388 ('hmo','ho'),
389 ('hun','hu'),
390 ('ice(B)|isl(T)','is'),
391 ('ido','io'),
392 ('ibo','ig'),
393 ('ind','in'),
394 ('ina','ia'),
395 ('ile','ie'),
396 ('iku','iu'),
397 ('ipk','ik'),
398 ('gle','ga'),
399 ('ita','it'),
400 ('jpn','ja'),
401 ('jav','jv'),
402 ('kal','kl'),
403 ('kan','kn'),
404 ('kau','kr'),
405 ('kas','ks'),
406 ('kaz','kk'),
407 ('kik','ki'),
408 ('kin','rw'),
409 ('kir','ky'),
410 ('kom','kv'),
411 ('kon','kg'),
412 ('kor','ko'),
413 ('kua','kj'),
414 ('kur','ku'),
415 ('lao','lo'),
416 ('lat','la'),
417 ('lav','lv'),
418 ('lim','li'),
419 ('lin','ln'),
420 ('lit','lt'),
421 ('lub','lu'),
422 ('ltz','lb'),
423 ('mac(B)|mkd(T)','mk'),
424 ('mlg','mg'),
425 ('may(B)|msa(T)','ms'),
426 ('mal','ml'),
427 ('mlt','mt'),
428 ('glv','gv'),
429 ('mao(B)|mri(T)','mi'),
430 ('mar','mr'),
431 ('mah','mh'),
432 ('mon','mn'),
433 ('nau','na'),
434 ('nav','nv'),
435 ('nde','nd'),
436 ('nbl','nr'),
437 ('ndo','ng'),
438 ('nep','ne'),
439 ('sme','se'),
440 ('nor','no'),
441 ('nno','nn'),
442 ('oci','oc'),
443 ('oji','oj'),
444 ('ori','or'),
445 ('orm','om'),
446 ('oss','os'),
447 ('pli','pi'),
448 ('per(B)|fas(T)','fa'),
449 ('pol','pl'),
450 ('por','pt'),
451 ('pan','pa'),
452 ('pus','ps'),
453 ('que','qu'),
454 ('rum(B)|ron(T)','ro'),
455 ('roh','rm'),
456 ('run','rn'),
457 ('rus','ru'),
458 ('smo','sm'),
459 ('sag','sg'),
460 ('san','sa'),
461 ('srd','sc'),
462 ('srp','sr'),
463 ('sna','sn'),
464 ('iii','ii'),
465 ('snd','sd'),
466 ('sin','si'),
467 ('slo(B)|slk(T)','sk'),
468 ('slv','sl'),
469 ('som','so'),
470 ('sot','st'),
471 ('spa','es'),
472 ('sun','su'),
473 ('swa','sw'),
474 ('ssw','ss'),
475 ('swe','sv'),
476 ('tgl','tl'),
477 ('tah','ty'),
478 ('tgk','tg'),
479 ('tam','ta'),
480 ('tat','tt'),
481 ('tel','te'),
482 ('tha','th'),
483 ('tib(B)|bod(T)','bo'),
484 ('tir','ti'),
485 ('ton','to'),
486 ('tso','ts'),
487 ('tsn','tn'),
488 ('tur','tr'),
489 ('tuk','tk'),
490 ('twi','tw'),
491 ('uig','ug'),
492 ('ukr','uk'),
493 ('urd','ur'),
494 ('uzb','uz'),
495 ('ven','ve'),
496 ('vie','vi'),
497 ('vol','vo'),
498 ('wln','wa'),
499 ('wel(B)|cym(T)','cy'),
500 ('fry','fy'),
501 ('wol','wo'),
502 ('xho','xh'),
503 ('yid','yi'),
504 ('yor','yo'),
505 ('zha','za'),
506 ('zul','zu');
508 UPDATE list_options JOIN lang_updates_610 ON list_options.list_id='language' AND list_options.notes = lang_updates_610.notes SET list_options.notes = lang_updates_610.twodigit_notes;
509 DROP TABLE lang_updates_610;
510 #EndIf;
512 #IfNotRow3D list_options list_id language option_id malay notes ms
513 UPDATE list_options SET notes='ms' WHERE list_id='language' AND option_id='malay';
514 #EndIf
516 #IfMissingColumn form_encounter date_end
517 ALTER TABLE `form_encounter` ADD `date_end` DATETIME DEFAULT NULL;
518 #EndIf
520 #IfMissingColumn procedure_order_code date_end
521 ALTER TABLE `procedure_order_code` ADD `date_end` datetime DEFAULT NULL;
522 ALTER TABLE `procedure_order_code` ADD `reason_code` varchar(31) DEFAULT NULL;
523 ALTER TABLE `procedure_order_code` ADD `reason_description` text;
524 ALTER TABLE `procedure_order_code` ADD `reason_date_low` datetime DEFAULT NULL;
525 ALTER TABLE `procedure_order_code` ADD `reason_date_high` datetime DEFAULT NULL;
526 ALTER TABLE `procedure_order_code` ADD `reason_status` varchar(31) DEFAULT NULL;
527 #EndIf
529 #IfNotColumnType procedure_order_code procedure_code VARCHAR(64)
530 ALTER TABLE `procedure_order_code` CHANGE `procedure_code` `procedure_code` VARCHAR(64) NOT NULL DEFAULT '' COMMENT 'like procedure_type.procedure_code';
531 #EndIf
533 #IfNotColumnType procedure_order date_ordered DATETIME
534 ALTER TABLE `procedure_order` CHANGE `date_ordered` `date_ordered` DATETIME DEFAULT NULL;
535 #EndIf
537 #IfMissingColumn immunizations reason_code
538 ALTER TABLE `immunizations` CHANGE `cvx_code` `cvx_code` VARCHAR(64) DEFAULT NULL;
539 ALTER TABLE `immunizations` ADD `reason_code` varchar(31) DEFAULT NULL COMMENT 'Medical code explaining reason of the vital observation value in form codesystem:codetype;...;';
540 ALTER TABLE `immunizations` ADD `reason_description` TEXT COMMENT 'Human readable text description of the reason_code column';
541 #EndIf
543 #IfMissingColumn categories codes
544 ALTER TABLE categories ADD COLUMN `codes` varchar(255) NOT NULL DEFAULT '' COMMENT 'Category codes for documents stored in this category';
545 UPDATE categories SET codes='LOINC:LP173418-7' WHERE name='Advance Directive';
546 UPDATE categories SET codes='LOINC:LP173421-1' WHERE name='FHIR Export Document';
547 UPDATE categories SET codes='LOINC:LP173394-0' WHERE name='Reviewed';
548 #EndIf
550 #IfMissingColumn form_vital_details reason_code
551 ALTER TABLE `form_vital_details` ADD `reason_code` VARCHAR(31) DEFAULT NULL COMMENT 'Medical code explaining reason of the vital observation value in form codesystem:codetype;...;', ADD `reason_description` TEXT COMMENT 'Human readable text description of the reason_code column', ADD `reason_status` VARCHAR(31) NULL DEFAULT NULL COMMENT 'The status of the reason ie completed, in progress, etc';
552 #EndIf
554 #IfNotRow2D list_options list_id lists option_id encounter-types
555 INSERT INTO list_options (list_id,option_id,title, seq, is_default, option_value) VALUES ('lists','encounter-types','Encounter Types',0, 1, 0);
556 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('encounter-types','visit-after-hours','Visit out of hours',10,0,1);
557 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('encounter-types','visit-after-hours-not-night','Out of Hours visit (Not Night)',20,0,1);
558 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('encounter-types','weekend-visit','Weekend Visit',30,0,1);
559 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('encounter-types','office-visit','Office visit for pediatric care and assessment',40,0,1);
560 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('encounter-types','established-patient','Evaluation and management of established patient in office or outpatient facility',50,0,1);
561 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('encounter-types','new-patient','Evaluation and management of new patient in office or outpatient facility',60,0,1);
562 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('encounter-types','postoperative-follow-up','Postoperative follow-up visit',70,0,1);
563 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('encounter-types','new-patient-10','New Patient - 10 Minutes',80,0,1);
564 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('encounter-types','new-patient-15-29','New Patient - 15-29 Minutes',90,0,1);
565 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('encounter-types','new-patient-30-44','New Patient - 30-44 Minutes',100,0,1);
566 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('encounter-types','new-patient-45-59','New Patient - 45-59 Minutes',110,0,1);
567 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('encounter-types','new-patient-60-74','New Patient - 60-74 Minutes',120,0,1);
568 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('encounter-types','established-patient-10-19','Established Patient - 10-19 Minutes',130,0,1);
569 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('encounter-types','established-patient-20-29','Established Patient - 20-29 Minutes',140,0,1);
570 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('encounter-types','established-patient-30-39','Established Patient - 30-39 Minutes',140,0,1);
571 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('encounter-types','established-patient-40-54','Established Patient - 40-54 Minutes',150,0,1);
572 #EndIf
574 #IfNotRow2D list_options list_id immunization_refusal_reason option_id financial_problem
575 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','financial_problem','Financial Problem',50,1, "03");
576 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','financial_circumstances_change','Financial circumstances change',60,1, "03");
577 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','alternative_treatment_requested','Alternative Treatment Requested',70,1, "03");
578 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','patient_declined_procedure','Patient declined procedure',80,1, "03");
579 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','patient_declined_drug','Patient declined drug',90,1, "03");
580 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','patient_declined_drug_effects','Patient declined drug - side effects',100,1, "03");
581 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','patient_declined_drug_beliefs','Patient declined drug - patient beliefs',110,1, "01");
582 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','patient_declined_drug_cannot_pay','Patient declined drug - cannot pay script',120,1, "03");
583 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','patient_moved','Patient moved',130,1, "03");
584 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','patient_dissatisfied_result','Patient dissatisfied with result',140,1, "03");
585 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','patient_dissatisfied_doctor','Patient dissatisfied with doctor',150,1, "03");
586 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','patient_variable_income','Variable income',160,1, "03");
587 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','patient_self_discharge','Patient self-discharge against medical advice',170,1, "03");
588 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','drugs_not_completed','Drugs not taken/completed',180,1, "03");
589 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','family_illness','Family illness',190,1, "02");
590 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','follow_defaulted','Patient defaulted from follow-up',200,1, "03");
591 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','patient_noncompliance','Patient noncompliance - general',210,1, "03");
592 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','patient_noshow','Patient did not attend',220,1, "03");
593 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','patient_further_opinion','Further opinion sought',230,1, "03");
594 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','patient_treatment_delay','Treatment delay - patient choice',240,1, "03");
595 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','patient_medication_declined','Medication declined',250,1, "03");
596 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','patient_medication_forgot','Patient forgets to take medication',260,1, "03");
597 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','patient_non_compliant','Patient non-compliant declined intervention/support',270,1, "03");
598 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','procedure_not_wanted','Procedure not wanted',280,1, "03");
599 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','income_insufficient','Income insufficient to buy necessities',290,1, "03");
600 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','income_necessities_only','Income sufficient to buy only necessities',300,1, "03");
601 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','refused','Refused',310,1, "03");
602 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`, `activity`, `notes`) VALUES ('immunization_refusal_reason','patient_procedure_discontinued','Procedure discontinued by patient',320,1, "03");
603 #EndIf
605 #IfNotRow2D list_options list_id Plan_of_Care_Type option_id planned_medication_activity
606 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 ('Plan_of_Care_Type', 'planned_medication_activity', 'Planned Medication Act', '20', '0', '0', '', 'RQO', '', '0', '0', '1', '', '1');
607 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 ('Plan_of_Care_Type', 'supply_order', 'Supply Order Act', '30', '0', '0', '', 'RQO', '', '0', '0', '1', '', '1');
608 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 ('Plan_of_Care_Type', 'device_order', 'Device Order', '40', '0', '0', '', 'RQO', '', '0', '0', '1', '', '1');
609 #EndIf
611 -- below is missing in some demos and test databases
612 #IfNotRow2D list_options list_id Plan_of_Care_Type option_id medication
613 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','');
614 #EndIf
616 #IfNotRow2D list_options list_id issue_subtypes option_id assessment
617 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`) VALUES ('issue_subtypes','assessment','Assessment',20);
618 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`) VALUES ('issue_subtypes','concern','Concern',30);
619 #EndIf
621 #IfNotRow2D list_options list_id Observation_Types option_id assessment
622 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 ('lists','Observation_Types','Observation Types',0,1,0,'',NULL,'',0,0,1,'');
623 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 ('Observation_Types','assessment','Assessment',10,0,0,'','','',0,0,1,'');
624 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 ('Observation_Types','procedure_diagnostic','Procedure Diagnostic',20,0,0,'','','',0,0,1,'');
625 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 ('Observation_Types','physical_exam_performed','Physical Exam Performed',30,0,0,'','','',0,0,1,'');
626 #EndIf
628 #IfNotRow2D list_options list_id Plan_of_Care_Type option_id intervention
629 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 ('Plan_of_Care_Type', 'intervention', 'Intervention', '9', '0', '0', '', 'RQO', '', '0', '0', '1', '', '1');
630 #EndIf
632 #IfNotTable valueset_oid
633 CREATE TABLE `valueset_oid` (
634   `nqf_code` varchar(255) NOT NULL DEFAULT '',
635   `code` varchar(255) NOT NULL DEFAULT '',
636   `code_system` varchar(255) NOT NULL DEFAULT '',
637   `code_type` varchar(255) DEFAULT NULL,
638   `valueset` varchar(255) NOT NULL DEFAULT '',
639   `description` varchar(255) DEFAULT NULL,
640   `valueset_name` varchar(500) DEFAULT NULL,
641   PRIMARY KEY (`nqf_code`,`code`,`valueset`)
642 ) ENGINE=InnoDB;
643 #EndIf
645 #IfNotRow code_types ct_key OID
646 DROP TABLE IF EXISTS `temp_table_one`;
647 CREATE TABLE `temp_table_one` (`id` int(11) NOT NULL DEFAULT '0',`seq` int(11) NOT NULL DEFAULT '0') ENGINE=InnoDB;
648 INSERT INTO `temp_table_one` (`id`, `seq`) VALUES (
649   IF(((SELECT MAX(`ct_id` ) FROM `code_types`) >= 100), ((SELECT MAX(`ct_id` ) FROM `code_types`) + 1), 100),
650   IF(((SELECT MAX(`ct_seq`) FROM `code_types`) >= 100), ((SELECT MAX(`ct_seq`) FROM `code_types`) + 1), 100));
651 INSERT INTO `code_types` (`ct_key`, `ct_id`, `ct_seq`, `ct_mod`, `ct_just`, `ct_mask`, `ct_fee`, `ct_rel`, `ct_nofs`, `ct_diag`, `ct_active`, `ct_label`, `ct_external`, `ct_claim`, `ct_proc`, `ct_term`, `ct_problem`, `ct_drug`) VALUES
652     ('OID', (SELECT MAX(`id`) FROM `temp_table_one`), (SELECT MAX(`seq`) FROM `temp_table_one`), '0', '', '', '1', '1', '0', '1', '1', 'OID Valueset', '14', '1', '1', '1', '1', '1');
653 DROP TABLE `temp_table_one`;
654 #EndIf
656 #IfNotRow2D list_options list_id issue_subtypes option_id diagnosis
657 INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `seq`) VALUES ('issue_subtypes','diagnosis','Diagnosis',40);
658 #EndIf
660 #IfColumn patient_data deceased_date
661 SET @currentSQLMode = (SELECT @@sql_mode);
662 SET sql_mode = '';
663 UPDATE `patient_data` SET `deceased_date` = NULL WHERE `deceased_date` = '0000-00-00 00:00:00';
664 SET sql_mode = @currentSQLMode;
665 #EndIf
667 #IfMissingColumn insurance_companies cqm_sop
668 ALTER TABLE `insurance_companies` ADD `cqm_sop` int DEFAULT NULL COMMENT 'HL7 Source of Payment for eCQMs';
669 #EndIf
671 #IfNotRow2D list_options list_id order_type option_id order
672 INSERT INTO list_options ( list_id, option_id, title, seq, is_default ) VALUES ('order_type','order','Order',90,0);
673 #EndIf
675 #IfNotColumnType procedure_type procedure_code varchar(64)
676 ALTER TABLE `procedure_type` MODIFY `procedure_code` varchar(64) NOT NULL DEFAULT '' COMMENT 'code identifying this procedure';
677 #EndIf
679 #IfNotRow2D categories name CCD codes LOINC:34133-9
680 Update categories SET codes='LOINC:34133-9' WHERE name='CCD';
681 #EndIf
683 #IfNotRow2D list_options list_id lists option_id ccda-sections
684 INSERT INTO list_options (list_id,option_id,title, seq, is_default, option_value) VALUES ('lists','ccda-sections','CCDA Sections',0, 1, 0);
685 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','allergies_required','Allergies and Intollerances (entries required)',10,0,1, 'oid:2.16.840.1.113883.10.20.22.2.6.1');
686 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','medications','History of medication use',20,0,1, 'oid:2.16.840.1.113883.10.20.22.2.1.1');
687 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','problems','Problem list',30,0,1, 'oid:2.16.840.1.113883.10.20.22.2.5.1');
688 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','procedures','History of procedures',40,0,1, 'oid:2.16.840.1.113883.10.20.22.2.7.1');
689 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','dx_tests_labdata','Relevant Dx tests/lab data',50,0,1, 'oid:2.16.840.1.113883.10.20.22.2.3.1');
690 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','functional_status','Functional Status',60,0,1, 'oid:2.16.840.1.113883.10.20.22.2.14');
691 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','progress_note','Clinical Notes (History & Physical,Procedure,Discharge,Imaging)',70,0,1, 'oid:2.16.840.1.113883.10.20.22.2.65');
692 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','procedures_section','Procedures Section',80,0,1, 'oid:2.16.840.1.113883.10.20.22.2.7.1');
693 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','encounters','Encounters',110,0,1, 'oid:2.16.840.1.113883.10.20.22.2.22.1');
694 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','immunizations','Immunizations',120,0,1, 'oid:2.16.840.1.113883.10.20.22.2.2');
695 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','assessments','Assessments',130,0,1, 'oid:2.16.840.1.113883.10.20.22.2.8');
696 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','treatment_plan','Treatment Plan',140,0,1, 'oid:2.16.840.1.113883.10.20.22.2.10');
697 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','goals','Goals',150,0,1, 'oid:2.16.840.1.113883.10.20.22.2.60');
698 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','health_concerns','Health Concerns',160,0,1, 'oid:2.16.840.1.113883.10.20.22.2.58');
699 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','reason_of_visit','Reason for Referral',170,0,1, 'oid:1.3.6.1.4.1.19376.1.5.3.1.3.1');
700 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','mental_status','Mental Status',180,0,1, 'oid:2.16.840.1.113883.10.20.22.2.56');
701 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','social_history','Social History',190,0,1, 'oid:2.16.840.1.113883.10.20.22.2.17');
702 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','vital_signs','Vital Signs',200,0,1, 'oid:2.16.840.1.113883.10.20.22.2.4.1');
703 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','medical_equipment','Medical Equipment',210,0,1, 'oid:2.16.840.1.113883.10.20.22.2.23');
704 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity, codes) VALUES ('ccda-sections','us_realm_person_name','US Realm Person Name',220,0,1, 'oid:2.16.840.1.113883.10.20.22.5.1.1');
705 #EndIf
707 #IfRow3D list_options list_id immunization_refusal_reason option_id parental_decision seq 10
708 UPDATE list_options SET seq=40 WHERE list_id="immunization_refusal_reason" AND option_id="parental_decision";
709 UPDATE list_options SET seq=10 WHERE list_id="immunization_refusal_reason" AND option_id="patient_decision";
710 #EndIf
712 #IfMissingColumn procedure_result date_end
713 ALTER TABLE `procedure_result` ADD `date_end` datetime DEFAULT NULL COMMENT 'lab-provided end date specific to this result';
714 #EndIf
716 #IfNotRow3D layout_options form_id DEM field_id title title Title
717 UPDATE `layout_options` SET `title` = 'Title' WHERE `layout_options`.`form_id` = 'DEM' AND `layout_options`.`field_id` = 'title';
718 #EndIf
720 #IfNotRow3D layout_options form_id DEM field_id fname title Name
721 UPDATE `layout_options` SET `title` = 'Name', `titlecols` = '1', `datacols` = '3' WHERE `layout_options`.`form_id` = 'DEM' AND `layout_options`.`field_id` = 'fname';
722 #EndIf
724 #IfMissingColumn addresses district
725 ALTER TABLE `addresses` ADD COLUMN `district` VARCHAR(255) DEFAULT NULL COMMENT 'The county or district of the address';
726 #EndIf
729 #IfNotTable contact
730 CREATE TABLE `contact` (
731    `id` BIGINT(20) NOT NULL auto_increment,
732    `foreign_table_name` VARCHAR(255) NOT NULL DEFAULT '',
733    `foreign_id` BIGINT(20) NOT NULL DEFAULT '0',
734    PRIMARY KEY (`id`),
735    KEY (`foreign_id`)
736 ) ENGINE = InnoDB;
737 #EndIf
741 #IfNotTable contact_address
742 CREATE TABLE `contact_address` (
743     `id` BIGINT(20) NOT NULL auto_increment,
744     `contact_id` BIGINT(20) NOT NULL,
745     `address_id` BIGINT(20) NOT NULL,
746     `priority` INT(11) NULL,
747     `type` VARCHAR(255) NULL COMMENT 'FK to list_options.option_id for list_id address-types',
748     `use` VARCHAR(255) NULL COMMENT 'FK to list_options.option_id for list_id address-uses',
749     `notes` TINYTEXT,
750     `status` CHAR(1) NULL COMMENT 'A=active,I=inactive',
751     `is_primary` CHAR(1) NULL COMMENT 'Y=yes,N=no',
752     `created_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
753     `period_start` DATETIME NULL COMMENT 'Date the address became active',
754     `period_end` DATETIME NULL COMMENT 'Date the address became deactivated',
755     `inactivated_reason` VARCHAR(45) NULL DEFAULT NULL COMMENT '[Values: Moved, Mail Returned, etc]',
756     PRIMARY KEY (`id`),
757     KEY (`contact_id`),
758     KEY (`address_id`)
759 ) ENGINE = InnoDB ;
760 #EndIf
762 #IfNotRow2D list_options list_id lists option_id address-uses
763 INSERT INTO list_options (list_id,option_id,title, seq, is_default, option_value) VALUES ('lists','address-uses','Address Uses',0, 1, 0);
764 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('address-uses','home','Home',10,0,1);
765 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('address-uses','work','Work',20,0,1);
766 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('address-uses','temp','Temporary',30,0,1);
767 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('address-uses','old','Old/Incorrect',40,0,1);
768 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('address-uses','billing','Billing',50,0,1);
769 #EndIf
771 #IfNotRow2D list_options list_id lists option_id address-types
772 INSERT INTO list_options (list_id,option_id,title, seq, is_default, option_value) VALUES ('lists','address-types','Address Types',0, 1, 0);
773 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('address-types','postal','Postal',10,0,1);
774 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('address-types','physical','Physical',20,0,1);
775 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('address-types','both','Postal & Physical',30,0,1);
776 #EndIf
778 #IfNotRow2D layout_options form_id DEM field_id additional_addresses
779 SET @group_id = (SELECT `group_id` FROM layout_options WHERE field_id='street' AND form_id='DEM');
780 SET @seq_add_to = (SELECT max(seq) FROM layout_options WHERE group_id = @group_id AND form_id='DEM');
781 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`)
782 VALUES ('DEM','additional_addresses',@group_id,'',@seq_add_to+1,54,1,0,0,'',4,4,'','','Additional Patient Addresses',0);
783 #Endif
785 #IfNotColumnType form_vitals weight DECIMAL(12,6)
786 ALTER TABLE form_vitals ADD `weight_dec` DECIMAL(12,2) DEFAULT NULL COMMENT 'patient weight stored in imperial lbs' AFTER `height`;
787 UPDATE form_vitals SET weight_dec=CAST(weight AS DECIMAL(12,2));
788 ALTER TABLE form_vitals DROP `weight`;
789 ALTER TABLE form_vitals CHANGE `weight_dec` `weight` DECIMAL(12,6) DEFAULT NULL COMMENT 'patient weight stored in imperial lbs';
790 #EndIf
792 #IfNotColumnType form_vitals height DECIMAL(12,6)
793 ALTER TABLE form_vitals ADD `height_dec` DECIMAL(12,2) DEFAULT NULL COMMENT 'patient height stored in imperial in' AFTER `height`;
794 UPDATE form_vitals SET height_dec=CAST(height AS DECIMAL(12,2));
795 ALTER TABLE form_vitals DROP `height`;
796 ALTER TABLE form_vitals CHANGE `height_dec` `height` DECIMAL(12,6) DEFAULT NULL COMMENT 'patient height stored in imperial in';
797 #EndIf
799 #IfNotColumnType form_vitals temperature DECIMAL(12,6)
800 ALTER TABLE form_vitals ADD `temperature_dec` DECIMAL(12,2) DEFAULT NULL COMMENT 'patient temperature stored in fahrenheit degrees' AFTER `temperature`;
801 UPDATE form_vitals SET temperature_dec=CAST(temperature AS DECIMAL(12,2));
802 ALTER TABLE form_vitals DROP `temperature`;
803 ALTER TABLE form_vitals CHANGE `temperature_dec` `temperature` DECIMAL(12,6) DEFAULT NULL COMMENT 'patient temperature stored in fahrenheit degrees';
804 #EndIf
806 #IfNotColumnType form_vitals pulse DECIMAL(12,6)
807 ALTER TABLE form_vitals ADD `pulse_dec` DECIMAL(12,2) DEFAULT NULL AFTER `pulse`;
808 UPDATE form_vitals SET pulse_dec=CAST(pulse AS DECIMAL(12,2));
809 ALTER TABLE form_vitals DROP `pulse`;
810 ALTER TABLE form_vitals CHANGE `pulse_dec` `pulse` DECIMAL(12,6) DEFAULT NULL;
811 #EndIf
813 #IfNotColumnType form_vitals respiration DECIMAL(12,6)
814 ALTER TABLE form_vitals ADD `respiration_dec` DECIMAL(12,2) DEFAULT NULL AFTER `respiration`;
815 UPDATE form_vitals SET respiration_dec=CAST(respiration AS DECIMAL(12,2));
816 ALTER TABLE form_vitals DROP `respiration`;
817 ALTER TABLE form_vitals CHANGE `respiration_dec` `respiration` DECIMAL(12,6) DEFAULT NULL;
818 #EndIf
820 #IfNotColumnType form_vitals BMI DECIMAL(12,6)
821 ALTER TABLE form_vitals ADD `BMI_dec` DECIMAL(6,1) DEFAULT NULL AFTER `BMI`;
822 UPDATE form_vitals SET BMI_dec=CAST(BMI AS DECIMAL(6,1));
823 ALTER TABLE form_vitals DROP `BMI`;
824 ALTER TABLE form_vitals CHANGE `BMI_dec` `BMI` DECIMAL(12,6) DEFAULT NULL;
825 #EndIf
827 #IfNotColumnType form_vitals waist_circ DECIMAL(12,6)
828 ALTER TABLE form_vitals ADD `waist_circ_dec` DECIMAL(12,2) DEFAULT NULL COMMENT 'patient waist circumference stored in imperial in' AFTER `waist_circ`;
829 UPDATE form_vitals SET waist_circ_dec=CAST(waist_circ AS DECIMAL(12,2));
830 ALTER TABLE form_vitals DROP `waist_circ`;
831 ALTER TABLE form_vitals CHANGE `waist_circ_dec` `waist_circ` DECIMAL(12,6) DEFAULT NULL COMMENT 'patient waist circumference stored in imperial in';
832 #EndIf
834 #IfNotColumnType form_vitals head_circ DECIMAL(12,6)
835 ALTER TABLE form_vitals ADD `head_circ_dec` DECIMAL(12,2) DEFAULT NULL COMMENT 'patient head circumference stored in imperial in' AFTER `head_circ`;
836 UPDATE form_vitals SET head_circ_dec=CAST(head_circ AS DECIMAL(12,2));
837 ALTER TABLE form_vitals DROP `head_circ`;
838 ALTER TABLE form_vitals CHANGE `head_circ_dec` `head_circ` DECIMAL(12,6) DEFAULT NULL COMMENT 'patient head circumference stored in imperial in';
839 #EndIf
841 #IfNotColumnType form_vitals oxygen_flow_rate DECIMAL(12,6)
842 ALTER TABLE form_vitals ADD `oxygen_flow_rate_dec` DECIMAL(12,2) DEFAULT NULL AFTER `oxygen_flow_rate`;
843 UPDATE form_vitals SET oxygen_flow_rate_dec=CAST(oxygen_flow_rate AS DECIMAL(12,2));
844 ALTER TABLE form_vitals DROP `oxygen_flow_rate`;
845 ALTER TABLE form_vitals CHANGE `oxygen_flow_rate_dec` `oxygen_flow_rate` DECIMAL(12,6) DEFAULT NULL;
846 #EndIf
848 #IfNotColumnType form_vitals oxygen_saturation DECIMAL(6,2)
849 ALTER TABLE form_vitals ADD `oxygen_saturation_dec` DECIMAL(6,2) DEFAULT NULL AFTER `oxygen_saturation`;
850 UPDATE form_vitals SET oxygen_saturation_dec=CAST(oxygen_saturation AS DECIMAL(6,2));
851 ALTER TABLE form_vitals DROP `oxygen_saturation`;
852 ALTER TABLE form_vitals CHANGE `oxygen_saturation_dec` `oxygen_saturation` DECIMAL(6,2) DEFAULT NULL;
853 #EndIf
855 #IfNotColumnType form_vitals ped_weight_height DECIMAL(6,2)
856 ALTER TABLE form_vitals ADD `ped_weight_height_dec` DECIMAL(6,2) DEFAULT NULL COMMENT 'pediatric weight height percentile' AFTER `ped_weight_height`;
857 UPDATE form_vitals SET ped_weight_height_dec=CAST(ped_weight_height AS DECIMAL(6,1));
858 ALTER TABLE form_vitals DROP `ped_weight_height`;
859 ALTER TABLE form_vitals CHANGE `ped_weight_height_dec` `ped_weight_height` DECIMAL(6,2) DEFAULT NULL COMMENT 'pediatric weight height percentile';
860 #EndIf
862 #IfNotColumnType form_vitals ped_bmi DECIMAL(6,2)
863 ALTER TABLE form_vitals ADD `ped_bmi_dec` DECIMAL(6,1) DEFAULT NULL COMMENT 'pediatric bmi percentile' AFTER `ped_bmi`;
864 UPDATE form_vitals SET ped_bmi_dec=CAST(ped_bmi AS DECIMAL(6,1));
865 ALTER TABLE form_vitals DROP `ped_bmi`;
866 ALTER TABLE form_vitals CHANGE `ped_bmi_dec` `ped_bmi` DECIMAL(6,2) DEFAULT NULL COMMENT 'pediatric bmi percentile';
867 #EndIf
869 #IfNotColumnType form_vitals ped_head_circ DECIMAL(6,2)
870 ALTER TABLE form_vitals ADD `ped_head_circ_dec` DECIMAL(6,1) DEFAULT NULL COMMENT 'pediatric head circumference percentile' AFTER `ped_head_circ`;
871 UPDATE form_vitals SET ped_head_circ_dec=CAST(ped_head_circ AS DECIMAL(6,1));
872 ALTER TABLE form_vitals DROP `ped_head_circ`;
873 ALTER TABLE form_vitals CHANGE `ped_head_circ_dec` `ped_head_circ` DECIMAL(6,2) DEFAULT NULL COMMENT 'pediatric head circumference percentile';
874 #EndIf
876 #IfNotColumnType form_vitals inhaled_oxygen_concentration DECIMAL(6,2)
877 ALTER TABLE form_vitals ADD `inhaled_oxygen_concentration_dec` DECIMAL(6,1) DEFAULT NULL AFTER `inhaled_oxygen_concentration`;
878 UPDATE form_vitals SET inhaled_oxygen_concentration_dec=CAST(inhaled_oxygen_concentration AS DECIMAL(6,1));
879 ALTER TABLE form_vitals DROP `inhaled_oxygen_concentration`;
880 ALTER TABLE form_vitals CHANGE `inhaled_oxygen_concentration_dec` `inhaled_oxygen_concentration` DECIMAL(6,2) DEFAULT NULL;
881 #EndIf
883 #IfNotRow2D layout_options form_id DEM field_id provider_since_date
884 SET @group_id = (SELECT `group_id` FROM layout_options WHERE field_id='providerID' AND form_id='DEM');
885 SET @seq_start := 0;
886 UPDATE `layout_options` SET `seq` = (@seq_start := @seq_start+1)*10 WHERE group_id = @group_id AND form_id='DEM' ORDER BY `seq`;
887 SET @seq_add_to = (SELECT seq FROM layout_options WHERE group_id = @group_id AND field_id='providerID' AND form_id='DEM');
888 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','provider_since_date',@group_id,'Provide Since Date',@seq_add_to+5,4,1,10,10,'',1,1,'','','Patient assigned provider since date.',0);
889 UPDATE `layout_options` SET `datacols` = 1 WHERE `layout_options`.`form_id` = 'DEM' AND `layout_options`.`field_id` = 'providerID';
890 UPDATE `layout_options` SET `description` = 'Multi Select race and or race category that describes patient race' WHERE `layout_options`.`form_id` = 'DEM' AND `layout_options`.`field_id` = 'race';
891 ALTER TABLE `patient_data` ADD `provider_since_date` TINYTEXT;
892 -- White
893 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'European';
894 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'English';
895 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'French';
896 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'German';
897 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'Irish';
898 -- Hispanic or Latino
899 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'Latin American';
900 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'Latino';
901 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'Hispanic';
902 -- American Indian or Alaska Native
903 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'American Indian';
904 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'Alaska Native';
905 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'Alaska Indian';
906 -- African American
907 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'African American';
908 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'African';
909 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'Middle Eastern or North African';
910 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'Black';
911 -- Asian & Pacific
912 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'Other Pacific Islander';
913 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'Chinese';
914 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'Filipino';
915 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'Japanese';
916 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'Korean';
917 UPDATE `list_options` SET `activity` = '1' WHERE `list_id` = 'race' AND `title` = 'Asian Indian';
918 #Endif
920 #IfNotIndex patient_history pid_idx
921 ALTER TABLE patient_history ADD INDEX `pid_idx` (`pid`);
922 #EndIf
924 #IfNotIndex contact_address contact_address_idx
925 ALTER TABLE contact_address ADD INDEX `contact_address_idx` (`contact_id`,`address_id`);
926 #EndIf
928 #IfUpdateEditOptionsNeeded add DEM J additional_addresses
929 #EndIf
931 #IfUpdateEditOptionsNeeded add DEM SP additional_addresses
932 #EndIf
934 #IfNotRow3D list_options list_id drug_route title IM codes NCI-CONCEPT-ID:C28161
935 UPDATE list_options SET codes='NCI-CONCEPT-ID:C28161' WHERE list_id='drug_route' AND title='IM' AND codes != 'NCI-CONCEPT-ID:C28161';
936 #EndIf
938 #IfRow2D list_options list_id drug_interval option_id WK
939 UPDATE list_options SET option_id='19' WHERE list_id='drug_interval' AND option_id='WK';
940 #EndIf
942 #IfRow2D list_options list_id drug_interval option_id MO
943 UPDATE list_options SET option_id='20' WHERE list_id='drug_interval' AND option_id='MO';
944 #EndIf
946 #IfNotRow2D list_options list_id drug_interval option_id 19
947 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('drug_interval','19','Weekly',19,0,1);
948 INSERT INTO list_options (list_id,option_id,title,seq,is_default,activity) VALUES ('drug_interval','20','Monthly',20,0,1);
949 #EndIf
951 #IfMissingColumn history_data created_by
952 ALTER TABLE history_data ADD COLUMN `created_by` BIGINT(20) DEFAULT NULL COMMENT 'users.id the user that first created this record';
953 #EndIf
955 #IfMissingColumn patient_data created_by
956 ALTER TABLE patient_data ADD COLUMN `created_by` BIGINT(20) DEFAULT NULL COMMENT 'users.id the user that first created this record';
957 #EndIf
959 #IfNotColumnType patient_data regdate DATETIME
960 ALTER TABLE `patient_data` CHANGE COLUMN `regdate` `regdate` DATETIME DEFAULT NULL COMMENT 'Registration Date';
961 #EndIf
963 #IfMissingColumn patient_data updated_by
964 ALTER TABLE patient_data ADD COLUMN `updated_by` BIGINT(20) DEFAULT NULL COMMENT 'users.id the user that last modified this record';
965 #EndIf
967 #IfMissingColumn patient_history created_by
968 ALTER TABLE patient_history ADD COLUMN `created_by` BIGINT(20) DEFAULT NULL COMMENT 'users.id the user that first created this record';
969 #EndIf
971 #IfNotColumnType prescriptions date_modified DATETIME
972 ALTER TABLE `prescriptions` CHANGE COLUMN `date_modified` `date_modified` DATETIME DEFAULT NULL COMMENT 'Datetime the prescriptions was last modified';
973 #EndIf
975 #IfNotColumnType prescriptions date_added DATETIME
976 ALTER TABLE `prescriptions` CHANGE COLUMN `date_added` `date_added` DATETIME DEFAULT NULL COMMENT 'Datetime the prescriptions was initially created';
977 #EndIf
979 #IfMissingColumn prescriptions created_by
980 ALTER TABLE prescriptions ADD COLUMN `created_by` BIGINT(20) DEFAULT NULL COMMENT 'users.id the user that first created this record';
981 #EndIf
983 #IfMissingColumn prescriptions updated_by
984 ALTER TABLE prescriptions ADD COLUMN `updated_by` BIGINT(20) DEFAULT NULL COMMENT 'users.id the user that last modified this record';
985 #EndIf
987 #IfMissingColumn module_configuration created_by
988 ALTER TABLE module_configuration ADD COLUMN `created_by` BIGINT(20) DEFAULT NULL COMMENT 'users.id the user that first created this record';
989 ALTER TABLE `module_configuration` ADD COLUMN `date_added` DATETIME DEFAULT NULL COMMENT 'Datetime the record was initially created';
990 #EndIf
992 #IfMissingColumn module_configuration updated_by
993 ALTER TABLE module_configuration ADD COLUMN `updated_by` BIGINT(20) DEFAULT NULL COMMENT 'users.id the user that last modified this record';
994 ALTER TABLE `module_configuration` ADD COLUMN `date_modified` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT 'Datetime the record was last modified';
995 #EndIf
997 #IfUpdateEditOptionsNeeded remove DEM K birth_fname, pubpid, name_history
998 #EndIf