3 * Upload and install a designated code set to the codes table.
5 * Copyright (C) 2014 Rod Roark <rod@sunsetsystems.com>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
19 * @author Rod Roark <rod@sunsetsystems.com>
20 * @link http://www.open-emr.org
25 // Disable magic quotes and fake register globals.
26 $sanitize_all_escapes = true;
27 $fake_register_globals = false;
29 require_once('../globals.php');
30 require_once($GLOBALS['srcdir'] . '/acl.inc');
31 require_once($GLOBALS['fileroot'] . '/custom/code_types.inc.php');
33 if (!acl_check('admin', 'super')) die(xlt('Not authorized'));
35 $form_replace = !empty($_POST['form_replace']);
36 $code_type = empty($_POST['form_code_type']) ?
'' : $_POST['form_code_type'];
41 <title
><?php
echo xlt('Install Code Set'); ?
></title
>
42 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
44 <style type
="text/css">
45 .dehead
{ color
:#000000; font-family:sans-serif; font-size:10pt; font-weight:bold }
46 .detail
{ color
:#000000; font-family:sans-serif; font-size:10pt; font-weight:normal }
51 <body
class="body_top">
55 if (!empty($_POST['bn_upload'])) {
56 if (empty($code_types[$code_type])) die(xlt('Code type not yet defined') . ": '$code_type'");
57 $code_type_id = $code_types[$code_type]['id'];
58 $tmp_name = $_FILES['form_file']['tmp_name'];
62 $seen_codes = array();
64 if (is_uploaded_file($tmp_name) && $_FILES['form_file']['size']) {
65 $zipin = new ZipArchive
;
67 if ($zipin->open($tmp_name) === true) {
68 // Must be a zip archive.
69 for ($i = 0; $i < $zipin->numFiles
; ++
$i) {
70 $ename = $zipin->getNameIndex($i);
71 // TBD: Expand the following test as other code types are supported.
72 if ($code_type == 'RXCUI' && basename($ename) == 'RXNCONSO.RRF') {
73 $eres = $zipin->getStream($ename);
79 $eres = fopen($tmp_name, 'r');
82 if (empty($eres)) die(xlt('Unable to locate the data in this file.'));
85 sqlStatement("DELETE FROM codes WHERE code_type = ?", array($code_type_id));
89 // Settings to drastically speed up import with InnoDB
90 sqlStatementNoLog("SET autocommit=0");
91 sqlStatementNoLog("START TRANSACTION");
92 while (($line = fgets($eres)) !== false) {
94 if ($code_type == 'RXCUI') {
95 $a = explode('|', $line);
96 if (count($a) < 18 ) continue;
97 if ($a[17] != '4096' ) continue;
98 if ($a[11] != 'RXNORM') continue;
100 if (isset($seen_codes[$code])) continue;
101 $seen_codes[$code] = 1;
103 if (!$form_replace) {
104 $tmp = sqlQuery("SELECT id FROM codes WHERE code_type = ? AND code = ? LIMIT 1",
105 array($code_type_id, $code));
107 sqlStatementNoLog("UPDATE codes SET code_text = ? WHERE code_type = ? AND code = ?",
108 array($a[14], $code_type_id, $code));
113 sqlStatementNoLog("INSERT INTO codes SET code_type = ?, code = ?, code_text = ?, " .
114 "fee = 0, units = 0",
115 array($code_type_id, $code, $a[14]));
119 // TBD: Clone/adapt the above for each new code type.
122 // Settings to drastically speed up import with InnoDB
123 sqlStatementNoLog("COMMIT");
124 sqlStatementNoLog("SET autocommit=1");
130 echo "<p style='color:green'>" .
131 xlt('LOAD SUCCESSFUL. Codes inserted') . ": $inscount, " .
132 xlt('replaced') . ": $repcount" .
137 <form method
='post' action
='load_codes.php' enctype
='multipart/form-data'
138 onsubmit
='return top.restoreSession()'>
143 <table border
='1' cellpadding
='4'>
144 <tr bgcolor
='#dddddd' class='dehead'>
145 <td align
='center' colspan
='2'>
146 <?php
echo xlt('Install Code Set'); ?
>
150 <td
class='detail' nowrap
>
151 <?php
echo xlt('Code Type'); ?
>
154 <select name
='form_code_type'>
156 foreach (array('RXCUI') as $codetype) {
157 echo " <option value='$codetype'>$codetype</option>\n";
164 <td
class='detail' nowrap
>
165 <?php
echo htmlspecialchars(xl('Source File')); ?
>
166 <input type
="hidden" name
="MAX_FILE_SIZE" value
="350000000" />
168 <td
class='detail' nowrap
>
169 <input type
="file" name
="form_file" size
="40" />
174 <?php
echo xlt('Replace entire code set'); ?
>
177 <input type
='checkbox' name
='form_replace' value
='1' checked
/>
180 <tr bgcolor
='#dddddd'>
181 <td align
='center' class='detail' colspan
='2'>
182 <input type
='submit' name
='bn_upload' value
='<?php echo xlt('Upload
and Install
') ?>' />
188 <p
class='bold'><?php
echo xlt('Be patient, some files can take several minutes to process!'); ?
></p
>
192 <!-- No translation because this text is long
and US
-specific
and quotes other English
-only text
. -->
194 <b
>RXCUI codes
</b
> may be downloaded from
195 <a href
='http://www.nlm.nih.gov/research/umls/rxnorm/docs/rxnormfiles.html' target
='_blank'>
196 www
.nlm
.nih
.gov
/research
/umls
/rxnorm
/docs
/rxnormfiles
.html
</a
>.
197 Get the
"Current Prescribable Content Monthly Release" zip file
, marked
"no license required".
198 Then you can upload that file
as-is here
, or extract the file RXNCONSO
.RRF from it
and upload just
199 that (zipped
or not
). You may
do the same with the weekly updates
, but
for those uncheck the
200 "<?php echo xlt('Replace entire code set'); ?>" checkbox above
.
203 <!-- TBD
: Another paragraph of instructions here
for each code type
. -->