Fully responsive globals.php with vertical menu (#2460)
[openemr.git] / interface / super / layout_service_codes.php
blob5797c32396b88c028282eb404104049a61dabf68
1 <?php
2 /**
3 * Upload designated service codes as "services=" attributes for designated layouts.
4 * This supports specifying related codes to determine the service codes to be used.
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2016 Rod Roark <rod@sunsetsystems.com>
11 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 require_once('../globals.php');
17 require_once($GLOBALS['srcdir'] . '/acl.inc');
18 require_once($GLOBALS['fileroot'] . '/custom/code_types.inc.php');
20 if (!acl_check('admin', 'super')) {
21 die(xlt('Not authorized'));
24 $form_dryrun = !empty($_POST['form_dryrun']);
26 function applyCode($layoutid, $codetype, $code, $description)
28 global $thecodes;
29 if (!isset($thecodes[$layoutid])) {
30 $thecodes[$layoutid] = array();
32 $thecodes[$layoutid]["$codetype:$code"] = $description;
36 <html>
38 <head>
39 <title><?php echo xlt('Install Layout Service Codes'); ?></title>
40 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
42 <style type="text/css">
43 .dehead { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:bold }
44 .detail { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:normal }
45 </style>
47 </head>
49 <body class="body_top">
51 <?php
52 // Handle uploads.
53 if (!empty($_POST['bn_upload'])) {
54 //verify csrf
55 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
56 csrfNotVerified();
59 $thecodes = array();
60 $tmp_name = $_FILES['form_file']['tmp_name'];
62 if (is_uploaded_file($tmp_name) && $_FILES['form_file']['size']) {
63 $fhcsv = fopen($tmp_name, 'r');
64 if (empty($fhcsv)) {
65 die(xlt('Cannot open') . text(" '$tmp_name'"));
68 // Columns are:
69 // 0 - Layout ID, e.g. LBFVIA
70 // 1 - Code type, e.g. IPPF2
71 // 2 - Code
73 while (!feof($fhcsv)) {
74 $codecount = 0;
75 $acsv = fgetcsv($fhcsv, 1024);
76 if (count($acsv) < 3) {
77 continue;
79 $layoutid = trim($acsv[0]);
80 $codetype = trim($acsv[1]);
81 $code = trim($acsv[2]);
82 if (empty($layoutid) || empty($codetype) || empty($code)) {
83 continue;
85 // If this is already a Fee Sheet code, add it.
86 if (empty($code_types[$codetype]['nofs'])) {
87 applyCode($layoutid, $codetype, $code, xl('Direct'));
88 ++$codecount;
90 // Add all Fee Sheet codes that relate to this code.
91 foreach ($code_types as $ct_key => $ct_arr) {
92 if (!$ct_arr['active'] || $ct_arr['nofs']) {
93 continue;
95 $tmp = "$codetype:$code";
96 $relres = sqlStatement(
97 "SELECT code, code_text FROM codes WHERE code_type = ? AND " .
98 "(related_code LIKE ? OR related_code LIKE ? OR related_code LIKE ? OR related_code LIKE ?) " .
99 "AND active = 1 ORDER BY code",
100 array($ct_arr['id'], $tmp, "$tmp;%", "%;$tmp", "%;$tmp;%")
102 while ($relrow = sqlFetchArray($relres)) {
103 applyCode($layoutid, $ct_key, $relrow['code'], $relrow['code_text']);
104 ++$codecount;
107 if ($codecount == 0) {
108 echo "<p style='color:red'>" . xlt('No matches for') . " '" . text($tmp) . "'.</p>\n";
110 } // end while
111 fclose($eres);
113 // Now zap the found service codes into the parameters for each layout.
114 foreach ($thecodes as $layoutid => $arr) {
115 $services = '';
116 foreach ($arr as $key => $description) {
117 if ($services) {
118 $services .= ';';
120 $services .= $key;
122 if (!$form_dryrun) {
123 sqlStatement(
124 "UPDATE layout_group_properties SET grp_services = ? WHERE " .
125 "grp_form_id = ? AND grp_group_id = ''",
126 array($services, $layoutid)
130 } // end upload logic
134 <form method='post' action='layout_service_codes.php' enctype='multipart/form-data'
135 onsubmit='return top.restoreSession()'>
136 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
138 <center>
140 <p class='text'>
141 <table border='1' cellpadding='4'>
142 <tr bgcolor='#dddddd' class='dehead'>
143 <td align='center' colspan='2'>
144 <?php echo xlt('Install Layout Service Codes'); ?>
145 </td>
146 </tr>
147 <tr>
148 <td class='detail' nowrap>
149 <?php echo xlt('Source CSV File'); ?>
150 <input type="hidden" name="MAX_FILE_SIZE" value="350000000" />
151 </td>
152 <td class='detail' nowrap>
153 <input type="file" name="form_file" size="40" />
154 </td>
155 </tr>
156 <tr>
157 <td class='detail' nowrap>
158 <?php echo xlt('Test only, skip updates'); ?>
159 </td>
160 <td class='detail' >
161 <input type='checkbox' name='form_dryrun' value='1' checked />
162 </td>
163 </tr>
164 <tr bgcolor='#dddddd'>
165 <td align='center' class='detail' colspan='2'>
166 <input type='submit' name='bn_upload' value='<?php echo xla('Upload and Apply') ?>' />
167 </td>
168 </tr>
169 </table>
170 </p>
173 <?php echo xlt('The input should be a CSV file with 3 columns: layout ID, code type and code.'); ?>
174 </p>
176 <p class='text'>
177 <table border='1' cellpadding='4'>
178 <tr bgcolor='#dddddd' class='dehead'>
179 <td><?php echo xlt('Category'); ?></td>
180 <td><?php echo xlt('Layout'); ?></td>
181 <td><?php echo xlt('Code'); ?></td>
182 <td><?php echo xlt('Description'); ?></td>
183 </tr>
184 <?php
185 $lastcat = '';
186 $lastlayout = '';
188 $res = sqlStatement("SELECT grp_form_id, grp_title, grp_mapping, grp_services FROM layout_group_properties " .
189 "WHERE grp_group_id = '' AND grp_activity = 1 AND grp_services != '' ORDER BY grp_mapping, grp_title, grp_form_id");
191 while ($row = sqlFetchArray($res)) {
192 // $jobj = json_decode($row['notes'], true);
193 if ($row['grp_services'] == '*') {
194 $row['grp_services'] = '';
196 $codes = explode(';', $row['grp_services']);
197 foreach ($codes as $codestring) {
198 echo " <tr>\n";
200 echo " <td class='detail'>";
201 if ($row['grp_mapping'] != $lastcat) {
202 $lastcat = $row['grp_mapping'];
203 echo text($lastcat);
205 echo "&nbsp;</td>\n";
207 echo " <td class='detail'>";
208 if ($row['grp_form_id'] != $lastlayout) {
209 $lastlayout = $row['grp_form_id'];
210 echo text($row['grp_title']);
212 echo "&nbsp;</td>\n";
214 echo " <td class='detail'>";
215 echo text($codestring);
216 echo "</td>\n";
218 echo " <td class='detail'>\n";
219 list ($codetype, $code) = explode(':', $codestring);
220 $crow = sqlQuery(
221 "SELECT code_text FROM codes WHERE " .
222 "code_type = ? AND code = ? AND active = 1 " .
223 "ORDER BY id LIMIT 1",
224 array($code_types[$codetype]['id'], $code)
226 echo text($crow['code_text']);
227 echo "&nbsp;</td>\n";
228 echo " </tr>\n";
232 </table>
233 </p>
235 </center>
237 </form>
238 </body>
239 </html>