2 /*******************************************************************/
3 // Copyright (C) 2011 Phyaura, LLC <info@phyaura.com>
6 // Rohit Kumar <pandit.rohit@netsity.com>
7 // Brady Miller <brady@sparmy.com>
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License
11 // as published by the Free Software Foundation; either version 2
12 // of the License, or (at your option) any later version.
13 /*******************************************************************/
15 //SANITIZE ALL ESCAPES
16 $sanitize_all_escapes=true;
19 //STOP FAKE REGISTER GLOBALS
20 $fake_register_globals=false;
23 require_once("../../interface/globals.php");
24 require_once("$srcdir/acl.inc");
25 require_once("$srcdir/standard_tables_capture.inc");
27 // Ensure script doesn't time out and has enough memory
29 ini_set('memory_limit', '150M');
32 if (!acl_check('admin', 'super')) {
33 echo htmlspecialchars( xl('Not Authorized'), ENT_NOQUOTES
);
37 // Collect parameters (ensure mode is either rxnorm or snomed)
38 $mode = isset($_GET['mode']) ?
$_GET['mode'] : '';
39 if ($mode != 'rxnorm' && $mode != 'snomed') {
42 $process = isset($_GET['process']) ?
$_GET['process'] : '0';
45 if ($mode == 'rxnorm') {
46 $mainPATH = $GLOBALS['fileroot']."/contrib/rxnorm";
48 else { // $mode == 'snomed'
49 $mainPATH = $GLOBALS['fileroot']."/contrib/snomed";
52 // Get current revision (if installed)
53 $installed_flag = false;
54 $current_revision = '';
55 if ($mode == 'rxnorm') {
56 $sqlReturn = sqlQuery("SELECT DATE_FORMAT(`revision_date`,'%Y-%m-%d') as `revision` FROM `standardized_tables_track` WHERE `name` = 'RXNORM' ORDER BY `revision_date` DESC");
58 else { // $mode == 'snomed'
59 $sqlReturn = sqlQuery("SELECT DATE_FORMAT(`revision_date`,'%Y-%m-%d') as `revision` FROM `standardized_tables_track` WHERE `name` = 'SNOMED' ORDER BY `revision_date` DESC");
61 if (!empty($sqlReturn)) {
62 $installed_flag = true;
63 $current_revision = $sqlReturn['revision'];
66 // See if a database file exist (collect revision and see if upgrade is an option)
68 $pending_upgrade = false;
69 $file_revision_path = ''; //Holds the database file
70 $file_revision_date = ''; //Holds the database file revision date
72 $files_array = array();
73 if (is_dir($mainPATH)) {
74 $files_array = scandir($mainPATH);
76 foreach ($files_array as $file) {
77 $file = $mainPATH."/".$file;
79 if ($mode == 'rxnorm') {
80 if (preg_match("/RxNorm_full_([0-9]{8}).zip/",$file,$matches)) {
81 $temp_date = array(substr($matches[1],4)."-".substr($matches[1],0,2)."-".substr($matches[1],2,-4)=>$mainPATH."/".$matches[0]);
82 $revisions = array_merge($revisions,$temp_date);
85 else { // $mode == 'snomed'
86 if (preg_match("/SnomedCT_INT_([0-9]{8}).zip/",$file,$matches)) {
87 $temp_date = array(substr($matches[1],0,4)."-".substr($matches[1],4,-2)."-".substr($matches[1],6)=>$mainPATH."/".$matches[0]);
88 $revisions = array_merge($revisions,$temp_date);
93 if (!empty($revisions)) {
94 //sort dates and store the most recent dated file
97 $file_revision_path = $revisions[key($revisions)];
99 $file_revision_date = key($revisions);
101 if ( !($installed_flag) && !empty($file_revision_date) ) {
104 else if (strtotime($file_revision_date) > strtotime($current_revision)) {
105 $pending_upgrade = true;
112 // Use the above booleans ($pending_new=>new,$pending_upgrade=>upgrade,$installed_flag=>installed vs. not installed)
113 // to figure out what to do in below script.
118 <?php
html_header_show();?
>
119 <?php
if ($mode == 'rxnorm') { ?
>
120 <title
><?php
echo htmlspecialchars( xl('RxNorm'), ENT_NOQUOTES
); ?
></title
>
121 <?php
} else { //$mode == 'snomed' ?>
122 <title
><?php
echo htmlspecialchars( xl('SNOMED'), ENT_NOQUOTES
); ?
></title
>
124 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
126 <script type
="text/javascript" src
="../../library/js/jquery-1.4.3.min.js"></script
>
127 <script type
="text/javascript" src
="../../../library/dialog.js"></script
>
128 <script type
="text/javascript" src
="../../../library/textformat.js"></script
>
129 <script type
="text/javascript" src
="../../../library/js/common.js"></script
>
131 <script type
="text/javascript">
132 function loading_show() {
133 $
('#loading').show();
138 <body
class="body_top">
140 <?php
if ($mode == 'rxnorm') { ?
>
141 <span
class="title"><?php
echo htmlspecialchars( xl('RxNorm Database'), ENT_NOQUOTES
); ?
></span
><br
><br
>
142 <?php
} else { //$mode == 'snomed' ?>
143 <span
class="title"><?php
echo htmlspecialchars( xl('SNOMED Database'), ENT_NOQUOTES
); ?
></span
><br
><br
>
146 <?php
if ($pending_new ||
$pending_upgrade) { ?
>
150 echo htmlspecialchars( xl('Database is not installed.'), ENT_NOQUOTES
)."<br>";
151 echo htmlspecialchars( xl('Click Install button to install database release from the following date').": ", ENT_NOQUOTES
)."<b>".htmlspecialchars($file_revision_date, ENT_NOQUOTES
)."</b><br>";
152 echo "(".htmlspecialchars( xl('Note it will take 5-10 minutes to fully process after you click Install'), ENT_NOQUOTES
).")<br><br>";
153 echo "<div id='loading' style='margin:10px;display:none;'><img src='../pic/ajax-loader.gif'/></div>";
154 echo "<a href='standard_tables_manage.php?process=1&mode=".$mode."' class='css_button' onclick='loading_show();top.restoreSession();'><span>".htmlspecialchars( xl('Install'), ENT_NOQUOTES
)."</span></a><br><br>";
156 else { //$pending_upgrade
157 echo htmlspecialchars( xl('The following database release is currently installed').": ",ENT_NOQUOTES
)."<b>".htmlspecialchars($current_revision,ENT_NOQUOTES
)."</b><br>";
158 echo htmlspecialchars( xl('Click Upgrade button to upgrade database release from the following date').": ", ENT_NOQUOTES
)."<b>".htmlspecialchars($file_revision_date, ENT_NOQUOTES
)."</b><br>";
159 echo "(".htmlspecialchars( xl('Note it will take 5-10 minutes to fully process after you click Upgrade'), ENT_NOQUOTES
).")<br><br>";
160 echo "<div id='loading' style='margin:10px;display:none;'><img src='../pic/ajax-loader.gif'/></div>";
161 echo "<a href='standard_tables_manage.php?process=1&mode=".$mode."' class='css_button' onclick='loading_show();top.restoreSession();'><span>".htmlspecialchars( xl('Upgrade'), ENT_NOQUOTES
)."</span></a><br><br>";
165 // install/upgrade the rxnorm database
167 // Clean up temp dir before start
168 temp_dir_cleanup($mode);
170 // 1. copy the file to temp directory
171 echo htmlspecialchars( xl('Copying the database file. This will take some time...'), ENT_NOQUOTES
)."<br>";
172 if (!temp_copy($file_revision_path,$mode)) {
173 echo htmlspecialchars( xl('ERROR: Unable to copy the file.'), ENT_NOQUOTES
)."<br>";
174 temp_dir_cleanup($mode);
178 // 2. unarchive the file
179 echo htmlspecialchars( xl('Extracting the file. This will take some time...'), ENT_NOQUOTES
)."<br>";
180 if (!temp_unarchive($file_revision_path,$mode)) {
181 echo htmlspecialchars( xl('ERROR: Unable to extract the file.'), ENT_NOQUOTES
)."<br>";
182 temp_dir_cleanup($mode);
186 // 3. load the database
187 echo htmlspecialchars( xl('Loading the files into the database. This will take some time...'), ENT_NOQUOTES
)."<br>";
188 if ($mode == 'rxnorm') {
189 if (!rxnorm_import(IS_WINDOWS
)) {
190 echo htmlspecialchars( xl('ERROR: Unable to load the file into the database.'), ENT_NOQUOTES
)."<br>";
191 temp_dir_cleanup($mode);
195 else { //$mode == 'snomed'
196 if (!snomed_import()) {
197 echo htmlspecialchars( xl('ERROR: Unable to load the file into the database.'), ENT_NOQUOTES
)."<br>";
198 temp_dir_cleanup($mode);
203 // 4. set the revision version in the database
204 echo htmlspecialchars( xl('Setting the version number in the database...'), ENT_NOQUOTES
)."<br>";
205 if (!update_tracker_table($mode,$file_revision_date)) {
206 echo htmlspecialchars( xl('ERROR: Unable to set the version number.'), ENT_NOQUOTES
)."<br>";
207 temp_dir_cleanup($mode);
211 // done, so clean up the temp directory
213 echo "<b>".htmlspecialchars( xl('Successfully installed the database.'), ENT_NOQUOTES
)."</b><br>";
215 else { //$pending_upgrade
216 echo "<b>".htmlspecialchars( xl('Successfully upgraded the database.'), ENT_NOQUOTES
)."</b><br>";
218 temp_dir_cleanup($mode);
221 <?php
} else if ($installed_flag) { ?
>
222 <?php
echo htmlspecialchars( xl('The following database release is currently installed').": ",ENT_NOQUOTES
)."<b>".htmlspecialchars($current_revision,ENT_NOQUOTES
)."</b><br>"; ?
>
223 <?php
echo htmlspecialchars( xl('If you want to upgrade the database, then place the database zip file in the following directory').": contrib/".$mode, ENT_NOQUOTES
); ?
><br
><br
>
224 <?php
} else { // !$installed_flag ?>
225 <?php
echo htmlspecialchars( xl('Database is not installed.'), ENT_NOQUOTES
); ?
><br
>
226 <?php
echo htmlspecialchars( xl('Place the database zip file in the following directory if want the option to install').": contrib/".$mode, ENT_NOQUOTES
); ?
><br
><br
>