4 * Lookup past and current dx codes (favorites)
5 * (Temporary rest test interface until add a model)
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');
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) {
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');
48 while ($diag = sqlFetchArray($dres)) {
49 $diag['codes'] = preg_replace('/^;+|;+$/', '', $diag['codes']);
50 $bld = explode(';', $diag['codes']);
51 foreach ($bld as $cde) {
55 'desc' => lookup_code_descriptions($cde),
56 'procedure' => $diag['proc']
61 $dxcodes = array_intersect_key($dxcodes, array_unique(array_map('serialize', $dxcodes)));
64 array_column($dxcodes, 'procedure'),
66 array_column($dxcodes, 'code'),
71 // problems on top then our sorted dx/procedure array
72 return array_merge($probcodes, $dxcodes);
78 <title
><?php
xlt("Find Code History"); ?
></title
>
79 <meta charset
="utf-8" />
80 <?php Header
::setupHeader(['opener']); ?
>
82 const errorMsg
= '' +
<?php
echo xlj("Error finding diagnosis element. Try again."); ?
>;
84 function setFormDx() {
86 let currentDx
= document
.getElementById('workingDx').value
;
87 currentDx
= currentDx
.replace(';;', ';');
88 currentDx
= currentDx
.trim().replace(/^
;+|
;+$
/gm
, '');
89 opener
.targetElement
.value
= currentDx
;
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
;
105 if (currentDx
.length
> 1) {
106 currentDx +
= ';' + codeElement
.value
;
108 currentDx
= codeElement
.value
;
110 document
.getElementById('workingDx').value
= currentDx
;
113 function clearCodes(codeElement
) {
115 opener
.targetElement
.value
= '';
116 document
.getElementById('workingDx').value
= "";
122 function setCodes() {
124 document
.getElementById('workingDx').value
= opener
.targetElement
.value
;
132 let targetDoneButton
= top
.document
.getElementById('saveDx');
133 let targetTipsButton
= top
.document
.getElementById('showTips');
134 targetDoneButton
.onclick
= function () {
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 +
")");
144 while (i
< rows
.length
&& src
!== '') {
145 rows
[i
].innerHTML
= '<mark>' + rows
[i
].innerHTML +
'</mark>';
146 $
(rows
[i
]).closest('tr').addClass('text-danger ');
149 $
('.spinner-border').fadeOut();
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));
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
>
165 <input
class='form-control text-danger' type
='text' id
='workingDx' title
='<?php echo xla('Current Working Procedure Diagnoses
'); ?>' value
='' />
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
>
172 <div
class="card-body">
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>";
184 <button
class='btn btn-sm btn-success float-right' onclick
='$("#tips").toggleClass("d-none");return false;'><?php
echo xlt('Dismiss') ?
></button
>
188 <div
class="spinner-border" role
="status">
189 <span
class="sr-only"><?php
echo xlt('Loading'); ?
>...</span
>
192 <div
class="container-fluid">
193 <div
class="table-responsive mt-1">
194 <table
class="table table-sm table-hover" id
="historyTable">
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
>
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]); ?
>
213 <?php
echo $pc['origin']; ?
>
216 <button
class='btn btn-sm btn-secondary' onclick
='rtnCode(this)' value
='<?php echo attr($pc['code
']); ?>'>
217 <?php
echo $code[0]; ?
>: 
;<u
class='text-danger'><?php
echo $code[1]; ?
></u
>
221 <?php
echo text($pc['desc']); ?
>
224 <?php
echo text($pc['procedure']); ?
>