4 * This script add and delete Issues and Encounters relationships.
7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Roberto Vasquez <robertogagliotta@gmail.com>
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @copyright Copyright (c) 2005 Rod Roark <rod@sunsetsystems.com>
12 * @copyright Copyright (c) 2015 Roberto Vasquez <robertogagliotta@gmail.com>
13 * @copyright Copyright (c) 2015-2018 Brady Miller <brady.g.miller@gmail.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 require_once("../globals.php");
18 require_once("$srcdir/patient.inc.php");
19 require_once("$srcdir/lists.inc.php");
21 use OpenEMR\Common\Acl\AclMain
;
22 use OpenEMR\Common\Csrf\CsrfUtils
;
23 use OpenEMR\Common\Twig\TwigContainer
;
24 use OpenEMR\Core\Header
;
26 $patdata = getPatientData($pid, "fname,lname,squad");
28 $thisauth = ((AclMain
::aclCheckCore('encounters', 'notes', '', 'write') ||
29 AclMain
::aclCheckCore('encounters', 'notes_a', '', 'write')) &&
30 AclMain
::aclCheckCore('patients', 'med', '', 'write'));
32 if ($patdata['squad'] && ! AclMain
::aclCheckCore('squads', $patdata['squad'])) {
37 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Issues and Encounters")]);
41 $alertmsg = ""; // anything here pops up in an alert box
42 $endjs = ""; // holds javascript to write at the end
44 // If the Save button was clicked...
45 if (!empty($_POST['form_save'])) {
46 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
47 CsrfUtils
::csrfNotVerified();
50 $form_pid = $_POST['form_pid'];
51 $form_pelist = $_POST['form_pelist'];
52 // $pattern = '|/(\d+),(\d+),([YN])|';
53 $pattern = '|/(\d+),(\d+)|';
55 preg_match_all($pattern, $form_pelist, $matches);
56 $numsets = count($matches[1]);
58 $query = "DELETE FROM issue_encounter WHERE pid = ?";
59 sqlQuery($query, array($form_pid));
60 for ($i = 0; $i < $numsets; ++
$i) {
61 $list_id = $matches[1][$i];
62 $encounter = $matches[2][$i];
63 $query = "INSERT INTO issue_encounter ( " .
64 "pid, list_id, encounter" .
68 sqlQuery($query, array($form_pid, $list_id, $encounter));
72 . "<script type=\"text/javascript\" src=\"" . $webroot . "/interface/main/tabs/js/include_opener.js\"></script>"
75 echo " alert(" . js_escape($alertmsg) . ");\n";
78 echo " var myboss = opener ? opener : parent;\n";
79 echo " myboss.location.reload();\n";
80 echo " dlgclose();\n";
81 echo "</script></body></html>\n";
86 $pres = sqlStatement("SELECT * FROM lists WHERE pid = ? " .
87 "ORDER BY type, date", array($pid));
90 $eres = sqlStatement("SELECT * FROM form_encounter WHERE pid = ? " .
91 "ORDER BY date DESC", array($pid));
93 // get problem/encounter relations
94 $peres = sqlStatement("SELECT * FROM issue_encounter WHERE pid = ?", array($pid));
99 <?php Header
::setupHeader(['opener', 'topdialog', 'dialog']); ?
>
101 <title
><?php
echo xlt('Issues and Encounters'); ?
></title
>
104 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
105 tr
.detail
{ font
-size
:10pt
; background
-color
:#eeeeee; }
110 // These are the possible colors for table rows.
111 var trcolors
= new Object();
112 // Colors for: Foreground Background
113 trcolors
['U'] = new Array('var(--black)', 'var(--gray200)'); // unselected
114 trcolors
['K'] = new Array('var(--black)', 'var(--yellow)'); // selected key
115 trcolors
['V'] = new Array('var(--black)', 'var(--indigo)'); // selected value
117 var pselected
= new Object();
118 var eselected
= new Object();
119 var keyid
= null; // id of currently hilited key, if any
121 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
123 // callback from add_edit_issue.php:
124 function refreshIssue(issue
, title
) {
125 top
.restoreSession();
129 // New Issue button is clicked.
130 function newIssue() {
131 var f
= document
.forms
[0];
132 var tmp
= (keyid
&& f
.form_key
[1].checked
) ?
('?enclink=' +
encodeURIComponent(keyid
)) : '';
133 dlgopen('summary/add_edit_issue.php' + tmp
, '_blank', 600, 625);
136 // Determine if a given problem/encounter pair is currently linked.
137 // If yes, return the "resolved" character (Y or N), else an empty string.
138 function isPair(problem
, encounter
) {
139 var pelist
= document
.forms
[0].form_pelist
;
140 // var frag = '/' + problem + ',' + encounter + ',';
141 var frag
= '/' + problem +
',' + encounter +
'/';
142 var i
= pelist
.value
.indexOf(frag
);
143 if (i
< 0) return '';
144 // return pelist.value.charAt(i + frag.length);
148 // Unlink a problem/encounter pair.
149 function removePair(problem
, encounter
) {
150 var pelist
= document
.forms
[0].form_pelist
;
151 // var frag = '/' + problem + ',' + encounter + ',';
152 var frag
= '/' + problem +
',' + encounter +
'/';
153 var i
= pelist
.value
.indexOf(frag
);
155 // pelist.value = pelist.value.substring(0, i) + pelist.value.substring(i + frag.length + 1);
156 pelist
.value
= pelist
.value
.substring(0, i
) + pelist
.value
.substring(i + frag
.length
- 1);
157 document
.forms
[0].form_save
.disabled
= false;
161 // Link a new or modified problem/encounter pair.
162 // function addPair(problem, encounter, resolved) {
163 function addPair(problem
, encounter
) {
164 removePair(problem
, encounter
);
165 var pelist
= document
.forms
[0].form_pelist
;
166 // pelist.value += '' + problem + ',' + encounter + ',' + resolved + '/';
167 pelist
.value +
= '' + problem +
',' + encounter +
'/';
168 document
.forms
[0].form_save
.disabled
= false;
171 // Clear displayed highlights.
172 function doclearall(pfx
) {
173 var thisarr
= (pfx
== 'p') ? pselected
: eselected
;
174 for (var id in thisarr
) {
175 var thistr
= document
.getElementById(pfx +
'_' + id
);
178 thistr
.style
.color
= trcolors
['U'][0];
179 thistr
.style
.backgroundColor
= trcolors
['U'][1];
184 function clearall() {
190 // Process clicks on table rows.
191 function doclick(pfx
, id
) {
192 var thisstyle
= document
.getElementById(pfx +
'_' + id
).style
;
193 var thisarr
= (pfx
== 'p') ? pselected
: eselected
;
194 var piskey
= document
.forms
[0].form_key
[0].checked
;
195 var thisiskey
= (pfx
== 'p') ? piskey
: !piskey
;
196 var wasset
= thisarr
[id
];
197 if (thisiskey
) { // they clicked in the key table
199 if (!wasset
) { // this item is not already hilited
202 thisstyle
.color
= trcolors
['K'][0];
203 thisstyle
.backgroundColor
= trcolors
['K'][1];
204 // Now hilite the related value table entries:
205 if (pfx
== 'p') { // key is problems, values are encounters
206 for (key in eselected
) {
207 var resolved
= isPair(id
, key
);
208 if (resolved
.length
> 0) {
209 eselected
[key
] = resolved
;
210 var valstyle
= document
.getElementById('e_' + key
).style
;
211 valstyle
.color
= trcolors
[resolved
][0];
212 valstyle
.backgroundColor
= trcolors
[resolved
][1];
215 } else { // key is encounters, values are problems
216 for (key in pselected
) {
217 var resolved
= isPair(key
, id
);
218 if (resolved
.length
> 0) {
219 pselected
[key
] = resolved
;
220 var valstyle
= document
.getElementById('p_' + key
).style
;
221 valstyle
.color
= trcolors
[resolved
][0];
222 valstyle
.backgroundColor
= trcolors
[resolved
][1];
227 } else { // they clicked in the value table
229 var resolved
= thisarr
[id
];
230 // if (resolved == 'Y') { // it was hilited and resolved, change to unresolved
231 // thisarr[id] = 'N';
232 // thisstyle.color = trcolors['N'][0];
233 // thisstyle.backgroundColor = trcolors['N'][1];
234 // if (pfx == 'p') addPair(id, keyid, 'N'); else addPair(keyid, id, 'N');
235 // } else if (resolved == 'N') { // it was hilited and unresolved, remove it
236 if (resolved
!= '') { // hilited, so remove it
238 thisstyle
.color
= trcolors
['U'][0];
239 thisstyle
.backgroundColor
= trcolors
['U'][1];
240 if (pfx
== 'p') removePair(id
, keyid
); else removePair(keyid
, id
);
241 // } else { // not hilited, change to hilited and resolved
242 // thisarr[id] = 'Y';
243 // thisstyle.color = trcolors['Y'][0];
244 // thisstyle.backgroundColor = trcolors['Y'][1];
245 // if (pfx == 'p') addPair(id, keyid, 'Y'); else addPair(keyid, id, 'Y');
246 } else { // not hilited, change to hilited
248 thisstyle
.color
= trcolors
['V'][0];
249 thisstyle
.backgroundColor
= trcolors
['V'][1];
250 if (pfx
== 'p') addPair(id
, keyid
); else addPair(keyid
, id
);
253 alert(<?php
echo xlj('You must first select an item in the section whose radio button is checked.') ;?
>);
262 <div
class="container">
263 <form method
='post' action
='problem_encounter.php' onsubmit
='return top.restoreSession()'>
264 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
266 echo "<input type='hidden' name='form_pid' value='" . attr($pid) . "' />\n";
267 // pelist looks like /problem,encounter/problem,encounter/[...].
268 echo "<input type='hidden' name='form_pelist' value='/";
269 while ($row = sqlFetchArray($peres)) {
270 // echo $row['list_id'] . "," . $row['encounter'] . "," .
271 // ($row['resolved'] ? "Y" : "N") . "/";
272 echo attr($row['list_id']) . "," . attr($row['encounter']) . "/";
276 <div
class="table-responsive">
277 <table
class="table">
279 <td colspan
='2' class="text-center font-weight-bold">
280 <?php
echo xlt('Issues and Encounters for'); ?
> <?php
echo text($patdata['fname']) . " " . text($patdata['lname']) . " (" . text($pid) . ")</b>\n"; ?
>
284 <td
class="text-center align-top p-0 pl-3">
285 <div
class="table-responsive">
286 <table
class="table table-sm">
288 <td colspan
='3' class="text-center">
289 <input type
='radio' name
='form_key' value
='p' onclick
='clearall()' checked
/>
290 <span
class="font-weight-bold"><?php
echo xlt('Issues Section'); ?
></span
>
294 <td
><?php
echo xlt('Type'); ?
></td
>
295 <td
><?php
echo xlt('Title'); ?
></td
>
296 <td
><?php
echo xlt('Description'); ?
></td
>
299 while ($row = sqlFetchArray($pres)) {
301 echo " <tr class='detail' id='p_" . attr($rowid) . "' onclick='doclick(\"p\", " . attr_js($rowid) . ")'>\n";
302 echo " <td class='align-top'>" . text($ISSUE_TYPES[($row['type'])][1]) . "</td>\n";
303 echo " <td class='align-top'>" . text($row['title']) . "</td>\n";
304 echo " <td class='align-top'>" . text($row['comments']) . "</td>\n";
306 $endjs .= "pselected[" . js_escape($rowid) . "] = '';\n";
312 <td
class="text-center align-top p-0 pr-3">
313 <div
class="table-responsive">
314 <table
class="table table-sm">
316 <td colspan
='2' class="text-center">
317 <input type
='radio' name
='form_key' value
='e' onclick
='clearall()' />
318 <span
class="font-weight-bold"><?php
echo xlt('Encounters Section'); ?
></span
>
322 <td
><?php
echo xlt('Date'); ?
></td
>
323 <td
><?php
echo xlt('Presenting Complaint'); ?
></td
>
326 while ($row = sqlFetchArray($eres)) {
327 $rowid = $row['encounter'];
328 echo " <tr class='detail' id='e_" . attr($rowid) . "' onclick='doclick(\"e\", " . attr_js($rowid) . ")'>\n";
329 echo " <td class='align-top'>" . text(substr($row['date'], 0, 10)) . "</td>\n";
330 echo " <td class='align-top'>" . text($row['reason']) . "</td>\n";
332 $endjs .= "eselected[" . js_escape($rowid) . "] = '';\n";
340 <td colspan
='2' class="text-center">
341 <div
class="btn-group">
342 <button type
="submit" class="btn btn-primary btn-sm btn-save" name
='form_save' value
='<?php echo xla('Save
'); ?>' disabled
>
343 <?php
echo xlt('Save'); ?
>
345 <button type
="button" class="btn btn-primary btn-sm btn-add" value
='<?php echo xla('Add Issue
'); ?>' onclick
='newIssue()'>
346 <?php
echo xlt('Add Issue'); ?
>
348 <button type
="button" class='btn btn-secondary btn-sm btn-cancel' onclick
='dlgclose()'><?php
echo xla('Cancel'); ?
></button
>
356 <span
class="font-weight-bold"><?php
echo xlt('Instructions:'); ?
></span
> <?php
echo xlt('Choose a section and click an item within it; then in the other section you will see the related items highlighted, and you can click in that section to add and delete relationships.'); ?
>
362 if (!empty($_REQUEST['issue'])) {
363 echo "doclick('p', " . js_escape($_REQUEST['issue']) . ");\n";
367 echo "alert(" . js_escape($alertmsg) . ");\n";