MU2 certification support (smoking and clinical terms), final revision.
[openemr.git] / interface / code_systems / list_staged.php
blob36ab2f0f3d19ecbd7bfed67a13e8484979c6a20a
1 <?php
2 /**
3 * This file implements the listing of the staged database files
4 * downloaded from an external source (e.g. CMS, NIH, etc.)
6 * The logic will also render the appropriate action button which
7 * can be one of the following:
8 * INSTALL - this is rendered when the external database has
9 * not been installed in this openEMR instance
10 * UPGRADE - this is rendered when the external database has
11 * been installed and the staged files are more recent
12 * than the instance installed
13 * When the staged files are the same as the instance installed then
14 * an appropriate message is rendered
16 * Copyright (C) 2012 Patient Healthcare Analytics, Inc.
17 * Copyright (C) 2011 Phyaura, LLC <info@phyaura.com>
19 * LICENSE: This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License
21 * as published by the Free Software Foundation; either version 2
22 * of the License, or (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
30 * @package OpenEMR
31 * @author (Mac) Kevin McAloon <mcaloon@patienthealthcareanalytics.com>
32 * @author Rohit Kumar <pandit.rohit@netsity.com>
33 * @author Brady Miller <brady@sparmy.com>
34 * @link http://www.open-emr.org
38 //SANITIZE ALL ESCAPES
39 $sanitize_all_escapes=true;
42 //STOP FAKE REGISTER GLOBALS
43 $fake_register_globals=false;
46 require_once("../../interface/globals.php");
47 require_once("$srcdir/acl.inc");
49 // Ensure script doesn't time out and has enough memory
50 set_time_limit(0);
51 ini_set('memory_limit', '150M');
53 // Control access
54 if (!acl_check('admin', 'super')) {
55 echo xlt('Not Authorized');
56 exit;
59 $db = isset($_GET['db']) ? $_GET['db'] : '0';
60 $mainPATH = $GLOBALS['fileroot']."/contrib/".strtolower($db);
61 $file_checksum = "";
64 // Get current revision (if installed)
66 // this retreives the most recent revision_date for a table "name"
68 // for SNOMED and RXNORM you get the date from the filename as those naming
69 // conventions allow for that derivation
70 // for ICD versions the revision date is equal to the load_release_date attribute
71 // value from the supported_external_dataloads table
73 $installed_flag = 0;
74 $supported_file = 0;
75 $current_revision = '';
76 $current_version = '';
77 $current_name = '';
78 $current_checksum = '';
79 // For now, only order by the revision_date. When have different formats of a code type (such as WHO vs CMS for ICD10 or different languages for SNOMED, then will incorporate this field)
80 $sqlReturn = sqlQuery("SELECT DATE_FORMAT(`revision_date`,'%Y-%m-%d') as `revision_date`, `revision_version`, `name`, `file_checksum` FROM `standardized_tables_track` WHERE upper(`name`) = ? ORDER BY `revision_date` DESC", array($db) );
81 if (!empty($sqlReturn)) {
82 $installed_flag = 1;
83 $current_name = $sqlReturn['name'];
84 $current_revision = $sqlReturn['revision_date'];
85 $current_version = $sqlReturn['revision_version'];
86 $current_checksum = $sqlReturn['file_checksum'];
89 // See if a database file exist (collect revision and see if upgrade is an option)
90 $file_revision_path = ''; //Holds the database file
91 $file_revision_date = ''; //Holds the database file revision date
92 $version = '';
93 $revisions = array();
94 $files_array = array();
95 if (is_dir($mainPATH)) {
96 $files_array = scandir($mainPATH);
98 array_shift($files_array); // get rid of "."
99 array_shift($files_array); // get rid of ".."
102 // this foreach loop only encounters 1 file for SNOMED, RXNORM and ICD9 but will cycle through all the
103 // the release files for ICD10
105 $i = -1;
106 foreach ($files_array as $file) {
107 $i++;
108 $file = $mainPATH."/".$file;
109 if (is_file($file)) {
110 if (!strpos($file, ".zip") !== false) {
111 unset($files_array[$i]);
112 continue;
114 $supported_file = 0;
115 if ($db == 'RXNORM') {
116 if (preg_match("/RxNorm_full_([0-9]{8}).zip/",$file,$matches)) {
118 // Hard code the version RxNorm feed to be Standard
119 // (if add different RxNorm types/versions/lanuages, then can use this)
121 $version = "Standard";
122 $date_release = substr($matches[1],4)."-".substr($matches[1],0,2)."-".substr($matches[1],2,-4);
123 $temp_date = array('date'=>$date_release, 'version'=>$version, 'path'=>$mainPATH."/".$matches[0]);
124 array_push($revisions,$temp_date);
125 $supported_file = 1;
128 else if ($db == 'SNOMED') {
129 if (preg_match("/SnomedCT_INT_([0-9]{8}).zip/",$file,$matches)) {
131 // Hard code the version SNOMED feed to be International:English
132 // (if add different SNOMED types/versions/languages, then can use this)
134 $version = "International:English";
135 $date_release = substr($matches[1],0,4)."-".substr($matches[1],4,-2)."-".substr($matches[1],6);
136 $temp_date = array('date'=>$date_release, 'version'=>$version, 'path'=>$mainPATH."/".$matches[0]);
137 array_push($revisions,$temp_date);
138 $supported_file = 1;
140 else if (preg_match("/SnomedCT_Release_INT_([0-9]{8}).zip/",$file,$matches)) {
142 // Hard code the version SNOMED feed to be International:English
143 // (if add different SNOMED types/versions/languages, then can use this)
145 $version = "International:English";
146 $date_release = substr($matches[1],0,4)."-".substr($matches[1],4,-2)."-".substr($matches[1],6);
147 $temp_date = array('date'=>$date_release, 'version'=>$version, 'path'=>$mainPATH."/".$matches[0]);
148 array_push($revisions,$temp_date);
149 $supported_file = 1;
151 else if (preg_match("/SnomedCT_Release_US[0-9]*_([0-9]{8}).zip/",$file,$matches)) {
153 // This is the SNOMED US extension pack which can only be installed on top
154 // of a International SNOMED version.
155 // Hard code this version SNOMED feed to be US Extension
157 $version = "US Extension";
158 $date_release = substr($matches[1],0,4)."-".substr($matches[1],4,-2)."-".substr($matches[1],6);
159 $temp_date = array('date'=>$date_release, 'version'=>$version, 'path'=>$mainPATH."/".$matches[0]);
160 array_push($revisions,$temp_date);
161 $supported_file = 1;
163 else {
164 // nothing
167 else if (is_numeric(strpos($db, "ICD"))) {
169 $qry_str = "SELECT `load_checksum`,`load_source`,`load_release_date` FROM `supported_external_dataloads` WHERE `load_type` = ? and `load_filename` = ? and `load_checksum` = ? ORDER BY `load_release_date` DESC";
171 // this query determines whether you can load the data into openEMR. you must have the correct
172 // filename and checksum for each file that are part of the same release.
174 // IMPORTANT: Releases that contain mutliple zip file (e.g. ICD10) are grouped together based
175 // on the load_release_date attribute value specified in the supported_external_dataloads table
177 // Just in case same filename is released on different release dates, best to actually include the md5sum in the query itself.
178 // (and if a hit, then it is a pass)
179 // (even if two duplicate files that are in different releases, will still work since chooses most recent)
180 $file_checksum = md5(file_get_contents($file));
181 $sqlReturn = sqlQuery($qry_str, array($db, basename($file), $file_checksum) );
183 if (!empty($sqlReturn)) {
184 $version = $sqlReturn['load_source'];
185 $date_release = $sqlReturn['load_release_date'];
186 $temp_date = array('date'=>$date_release, 'version'=>$version, 'path'=>$file, 'checksum'=>$file_checksum);
187 array_push($revisions,$temp_date);
188 $supported_file = 1;
191 if ($supported_file === 1) {
193 <div class="stg"><?php echo text(basename($file)); ?></div>
194 <?php
195 } else {
197 <div class="error_msg"><?php echo xlt("UNSUPPORTED database load file"); ?>: <BR><?php echo text(basename($file)) ?><span class="msg" id="<?php echo attr($db); ?>_unsupportedmsg">!</span></div>
198 <?php
202 } else {
204 <div class="error_msg"><?php echo xlt("The installation directory needs to be created."); ?><span class="msg" id="<?php echo attr($db); ?>_dirmsg">!</span></div>
205 <?php
207 if (count($files_array) === 0) {
209 <div class="error_msg"><?php echo xlt("No files staged for installation"); ?><span class="msg" id="<?php echo attr($db); ?>_msg">!</span></div>
210 <div class="stg msg"><?php echo xlt("Follow these instructions for installing or upgrading the following database") . ": " . text($db); ?><span class="msg" id="<?php echo attr($db); ?>_instrmsg">?</span></div>
211 <?php
215 // only render messages and action buttons when supported files exists
216 // otherwise we have an error message already displayed to the user
217 if ($supported_file === 1) {
219 $success_flag=1;
221 // Only allow 1 staged revision for the SNOMED and RXNORM imports
222 if ( ($db=="SNOMED" || $db=="RXNORM") && (count($revisions) > 1) ) {
224 <div class="error_msg"><?php echo xlt("The number of staged files is incorrect. Only place the file that you wish to install/upgrade to."); ?></div>
225 <div class="stg msg"><?php echo xlt("Follow these instructions for installing or upgrading the following database") . ": " . text($db); ?><span class="msg" id="<?php echo attr($db); ?>_instrmsg">?</span></div>
226 <?php
227 $success_flag=0;
230 // Ensure all release dates and revisions are the same for multiple file imports
231 // and collect the date and revision. Also collect a checksum and path.
232 $file_revision_date = '';
233 $file_revision = '';
234 $file_checksum = '';
235 $file_revision_path = '';
236 foreach ($revisions as $value) {
237 // date check
238 $temp_file_revision_date = $value['date'];
239 if (empty($file_revision_date)) {
240 $file_revision_date = $temp_file_revision_date;
242 else {
243 if ( ($file_revision_date != $temp_file_revision_date) && ($success_flag === 1) ) {
245 <div class="error_msg"><?php echo xlt("The staged files release dates are not all from the same release."); ?></div>
246 <div class="stg msg"><?php echo xlt("Follow these instructions for installing or upgrading the following database") . ": " . text($db); ?><span class="msg" id="<?php echo attr($db); ?>_instrmsg">?</span></div>
247 <?php
248 $success_flag=0;
251 // revision check
252 $temp_file_revision = $value['version'];
253 if (empty($file_revision)) {
254 $file_revision = $temp_file_revision;
256 else {
257 if ( ($file_revision != $temp_file_revision) && ($success_flag === 1) ) {
259 <div class="error_msg"><?php echo xlt("The staged files revisions are not all from the same release."); ?></div>
260 <div class="stg msg"><?php echo xlt("Follow these instructions for installing or upgrading the following database") . ": " . text($db); ?><span class="msg" id="<?php echo attr($db); ?>_instrmsg">?</span></div>
261 <?php
262 $success_flag=0;
265 // collect checksum (if a multiple file import, then can use any one)
266 $file_checksum = $value['checksum'];
267 // collect path (if a multiple file import, then can use any one)
268 $file_revision_path = $value['path'];
271 // Determine and enforce only a certain number of files to be staged
272 if ($success_flag === 1) {
273 $number_files = 1;
274 $sql_query_ret = sqlStatement("SELECT * FROM `supported_external_dataloads` WHERE `load_type` = ? AND `load_source` = ? AND `load_release_date` = ?", array($db,$file_revision,$file_revision_date) );
275 $number_files_temp = sqlNumRows($sql_query_ret);
276 if ($number_files_temp > 1) {
277 // To ensure number_files is set to 1 for imports that are not tracked in the supported_external_dataloads table
278 $number_files = $number_files_temp;
280 if ( count($revisions) != $number_files ) {
282 <div class="error_msg"><?php echo xlt("The number of staged files is incorrect. Only place the files that you wish to install/upgrade to."); ?></div>
283 <div class="stg msg"><?php echo xlt("Follow these instructions for installing or upgrading the following database") . ": " . text($db); ?><span class="msg" id="<?php echo attr($db); ?>_instrmsg">?</span></div>
284 <?php
285 $success_flag=0;
289 // If new version is being offered, then provide install/upgrade options
290 if ($success_flag === 1) {
291 $action = "";
292 if ($installed_flag === 1) {
293 if (strtotime($current_revision) == strtotime($file_revision_date)) {
295 <div class="error_msg"><?php echo xlt("The installed version and the staged files are the same."); ?></div>
296 <div class="stg msg"><?php echo xlt("Follow these instructions for installing or upgrading the following database") . ": " . text($db); ?><span class="msg" id="<?php echo attr($db); ?>_instrmsg">?</span></div>
297 <?php
298 } else if (strtotime($current_revision) > strtotime($file_revision_date)) {
300 <div class="error_msg"><?php echo xlt("The installed version is a more recent version than the staged files."); ?></div>
301 <div class="stg msg"><?php echo xlt("Follow these instructions for installing or upgrading the following database") . ": " . text($db); ?><span class="msg" id="<?php echo attr($db); ?>_instrmsg">?</span></div>
302 <?php
303 } else if ($current_name=="SNOMED" && $current_version=="US Extension" && $file_revision=="US Extension") {
304 // The Staged US Extension SNOMED package has already been installed
306 <div class="error_msg"><?php echo xlt("The compatible staged US Extension SNOMED package has already been installed."); ?></div>
307 <div class="stg msg"><?php echo xlt("Follow these instructions for installing or upgrading the following database") . ": " . text($db); ?><span class="msg" id="<?php echo attr($db); ?>_instrmsg">?</span></div>
308 <?php
309 } else if ( ($current_name=="SNOMED" && $file_revision=="US Extension") && (strtotime($current_revision." +4 month") < strtotime($file_revision_date)) ) {
310 // The Staged US Extension SNOMED file is not compatible with the current SNOMED International Package (ie. the International package is outdated)
312 <div class="error_msg"><?php echo xlt("The installed International SNOMED version is out of date and not compatible with the staged US Extension SNOMED file."); ?></div>
313 <div class="stg msg"><?php echo xlt("Follow these instructions for installing or upgrading the following database") . ": " . text($db); ?><span class="msg" id="<?php echo attr($db); ?>_instrmsg">?</span></div>
314 <?php
315 } else {
317 <div class="stg"><?php echo text(basename($file_revision_path)); ?> <?php echo xlt("is a more recent version of the following database") . ": " . text($db); ?></div>
318 <?php
319 $action=xl("UPGRADE");
321 } else {
322 if ($db=="SNOMED" && $file_revision=="US Extension") {
323 // The Staged US Extension SNOMED package can not be installed by itself (it is done after the international package is installed)
325 <div class="error_msg"><?php echo xlt("The staged US Extension SNOMED package can not be installed until after the International SNOMED package has been installed."); ?></div>
326 <div class="stg msg"><?php echo xlt("Follow these instructions for installing or upgrading the following database") . ": " . text($db); ?><span class="msg" id="<?php echo attr($db); ?>_instrmsg">?</span></div>
327 <?php
329 else if (count($files_array) > 0) {
330 $action=xl("INSTALL");
332 else {
333 //do nothing
336 if (strlen($action) > 0) {
338 <input id="<?php echo attr($db); ?>_install_button" version="<?php echo attr($file_revision); ?>" file_revision_date="<?php echo attr($file_revision_date); ?>" file_checksum="<?php echo attr($file_checksum); ?>" type="button" value="<?php echo attr($action); ?>"/>
339 </div>
340 <?php