Tag documents to procedures (#4465)
[openemr.git] / interface / patient_file / encounter / find_code_history.php
blobb73632d4d519800917667113050bdf14f6dd52d3
1 <?php
3 /**
4 * Lookup past and current dx codes (favorites)
5 * (Temporary rest test interface until add a model)
7 * @package OpenEMR
8 * @link http://www.open-emr.org
9 * @author Jerry Padgett <sjpadgett@gmail.com>
10 * @copyright Copyright (c) 2019 Jerry Padgett <sjpadgett@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
14 require_once(__DIR__ . "/../../globals.php");
15 require_once($GLOBALS["srcdir"] . "/options.inc.php");
17 use OpenEMR\Core\Header;
19 function get_history_codes($pid)
21 $origin = xlt('Problems');
22 $probcodes = array();
23 $dres = sqlStatementNoLog(
24 "SELECT diagnosis as codes, title FROM lists " .
25 "Where activity = 1 And type = ? And pid = ? Group By lists.diagnosis",
26 array('medical_problem', $pid)
28 while ($diag = sqlFetchArray($dres)) {
29 $diag['codes'] = preg_replace('/^;+|;+$/', '', $diag['codes']);
30 $bld = explode(';', $diag['codes']);
31 foreach ($bld as $cde) {
32 $probcodes[] = array(
33 'origin' => $origin,
34 'code' => $cde,
35 'desc' => lookup_code_descriptions($cde),
36 'procedure' => $diag['title']
40 // well that's problems history, now procedure history
41 $dres = sqlStatementNoLog(
42 "Select procedure_order_code.diagnoses as codes, procedure_order_code.procedure_name as proc From procedure_order " .
43 "Inner Join procedure_order_code On procedure_order_code.procedure_order_id = procedure_order.procedure_order_id " .
44 "Where procedure_order_code.diagnoses > '' Group By procedure_order_code.diagnoses"
46 $origin = xlt('Procedures');
47 $dxcodes = array();
48 while ($diag = sqlFetchArray($dres)) {
49 $diag['codes'] = preg_replace('/^;+|;+$/', '', $diag['codes']);
50 $bld = explode(';', $diag['codes']);
51 foreach ($bld as $cde) {
52 $dxcodes[] = array(
53 'origin' => $origin,
54 'code' => $cde,
55 'desc' => lookup_code_descriptions($cde),
56 'procedure' => $diag['proc']
60 // make unique
61 $dxcodes = array_intersect_key($dxcodes, array_unique(array_map('serialize', $dxcodes)));
62 // the king of sort
63 array_multisort(
64 array_column($dxcodes, 'procedure'),
65 SORT_ASC,
66 array_column($dxcodes, 'code'),
67 SORT_ASC,
68 $dxcodes
71 // problems on top then our sorted dx/procedure array
72 return array_merge($probcodes, $dxcodes);
75 <!DOCTYPE html>
76 <html>
77 <head>
78 <title><?php xlt("Find Code History"); ?></title>
79 <meta charset="utf-8" />
80 <?php Header::setupHeader(['opener']); ?>
81 <script>
82 const errorMsg = '' + <?php echo xlj("Error finding diagnosis element. Try again."); ?>;
84 function setFormDx() {
85 if (opener) {
86 let currentDx = document.getElementById('workingDx').value;
87 currentDx = currentDx.replace(';;', ';');
88 currentDx = currentDx.trim().replace(/^;+|;+$/gm, '');
89 opener.targetElement.value = currentDx;
90 } else {
91 alert(errorMsg);
93 dlgclose();
96 function rtnCode(codeElement) {
97 let target = opener.targetElement;
98 let currentDx = document.getElementById('workingDx').value;
99 if (currentDx.indexOf(codeElement.value) !== -1) {
100 currentDx = currentDx.replace(codeElement.value, '').replace(';;', ';');
101 currentDx = currentDx.trim().replace(/^;+|;+$/gm, '');
102 document.getElementById('workingDx').value = currentDx;
103 return;
105 if (currentDx.length > 1) {
106 currentDx += ';' + codeElement.value;
107 } else {
108 currentDx = codeElement.value;
110 document.getElementById('workingDx').value = currentDx;
113 function clearCodes(codeElement) {
114 if (opener) {
115 opener.targetElement.value = '';
116 document.getElementById('workingDx').value = "";
117 } else {
118 alert(errorMsg);
122 function setCodes() {
123 if (opener) {
124 document.getElementById('workingDx').value = opener.targetElement.value;
125 } else {
126 alert(errorMsg);
130 $(function () {
131 setCodes();
132 let targetDoneButton = top.document.getElementById('saveDx');
133 let targetTipsButton = top.document.getElementById('showTips');
134 targetDoneButton.onclick = function () {
135 setFormDx();
137 targetTipsButton.onclick = function () {
138 $("#tips").toggleClass("d-none");
140 // search table to find a match for procedure we are seeking dx for.
141 let src = opener.targetProcedure.children[1].value;
142 let rows = $("#historyTable tr td").filter(":contains(" + src + ")");
143 let i = 0;
144 while (i < rows.length && src !== '') {
145 rows[i].innerHTML = '<mark>' + rows[i].innerHTML + '</mark>';
146 $(rows[i]).closest('tr').addClass('text-danger ');
147 i++;
149 $('.spinner-border').fadeOut();
150 if (rows.length) {
151 // scroll to first match and make active
152 $(rows[0]).closest('tr').addClass('active');
153 $(window).scrollTop($(rows[0]).offset().top - ($(window).height() / 2));
156 </script>
157 </head>
159 <body>
160 <div class="container-fluid sticky-top">
161 <div class="input-group bg-white">
162 <div class="input-group-prepend">
163 <button class="btn btn-danger" onclick='clearCodes(this)'><i class="fa fa-trash fa-1x"></i></button>
164 </div>
165 <input class='form-control text-danger' type='text' id='workingDx' title='<?php echo xla('Current Working Procedure Diagnoses'); ?>' value='' />
166 </div>
167 <div id="tips" class="d-none">
168 <section class="card bg-warning">
169 <header class="card-heading card-heading-sm">
170 <h4 class="card-title"><?php echo xlt('Usage Tips') ?></h4>
171 </header>
172 <div class="card-body">
173 <ul>
174 <?php
175 echo "<li>" . xlt("This dialog is generated from patient problem diagnoses and the accumulated diagnoses of all past procedures.") . "</li>";
176 echo "<li>" . xlt("The finder table is grouped by past procedures then diagnosis code. Although there may be duplicate dx codes, they will be grouped with the appropriate procedure making building diagnoses list easier.") . "</li>";
177 echo "<li>" . xlt("On opening, all dx code rows that match the new procedure from procedure order form will be marked and then will scroll to the first match.") . "</li>";
178 echo "<li>" . xlt("Build diagnoses list by clicking appropriate code button.") . "</li>";
179 echo "<li>" . xlt("Duplicate codes are deleted from editor list otherwise, code will append to list.") . "</li>";
180 echo "<li>" . xlt("Once finished editing, click Save. The procedure forms current procedure diagnoses will fill exactly as built in this dialog.") . "</li>";
181 echo "<li>" . xlt("The legacy code finder is still available for codes not found in this finder or code list editing.") . "</li>";
183 </ul>
184 <button class='btn btn-sm btn-success float-right' onclick='$("#tips").toggleClass("d-none");return false;'><?php echo xlt('Dismiss') ?></button>
185 </div>
186 </section>
187 </div>
188 <div class="spinner-border" role="status">
189 <span class="sr-only"><?php echo xlt('Loading'); ?>...</span>
190 </div>
191 </div>
192 <div class="container-fluid">
193 <div class="table-responsive mt-1">
194 <table class="table table-sm table-hover" id="historyTable">
195 <thead>
196 <tr>
197 <th><?php echo xlt('Origin'); ?></th>
198 <th><?php echo xlt('Code'); ?></th>
199 <th><?php echo xlt('Code Description'); ?></th>
200 <th><?php echo xlt('Origin Description'); ?></th>
201 </tr>
202 </thead>
203 <tbody>
204 <?php
205 $dxcodes = get_history_codes($pid);
206 foreach ($dxcodes as $pc) {
207 $code = explode(':', $pc['code']);
208 $code[0] = text($code[0]);
209 $code[1] = text($code[1]); ?>
211 <tr>
212 <td>
213 <?php echo $pc['origin']; ?>
214 </td>
215 <td>
216 <button class='btn btn-sm btn-secondary' onclick='rtnCode(this)' value='<?php echo attr($pc['code']); ?>'>
217 <?php echo $code[0]; ?>:&nbsp;<u class='text-danger'><?php echo $code[1]; ?></u>
218 </button>
219 </td>
220 <td>
221 <?php echo text($pc['desc']); ?>
222 </td>
223 <td>
224 <?php echo text($pc['procedure']); ?>
225 </td>
226 </tr>
227 <?php } ?>
228 </tbody>
229 </table>
230 </div>
231 </div>
232 </body>
233 </html>