4 * This script add and delete Issues and Encounters relationships.
6 * Copyright (C) 2005 Rod Roark <rod@sunsetsystems.com>
7 * Copyright (C) 2015 Roberto Vasquez <robertogagliotta@gmail.com>
8 * Copyright (C) 2015 Brady Miller <brady@sparmy.com>
10 * LICENSE: This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
22 * @author Rod Roark <rod@sunsetsystems.com>
23 * @author Roberto Vasquez <robertogagliotta@gmail.com>
24 * @author Brady Miller <brady@sparmy.com>
25 * @link http://www.open-emr.org
28 $fake_register_globals=false;
29 $sanitize_all_escapes=true;
31 include_once("../globals.php");
32 include_once("$srcdir/patient.inc");
33 include_once("$srcdir/acl.inc");
34 include_once("$srcdir/lists.inc");
36 $patdata = getPatientData($pid, "fname,lname,squad");
38 $thisauth = ((acl_check('encounters','notes','','write') ||
39 acl_check('encounters','notes_a','','write')) &&
40 acl_check('patients','med','','write'));
42 if ($patdata['squad'] && ! acl_check('squads', $patdata['squad']))
46 echo "<html>\n<body>\n";
47 echo "<p>" .xlt('You are not authorized for this.'). "</p>\n";
48 echo "</body>\n</html>\n";
52 $alertmsg = ""; // anything here pops up in an alert box
53 $endjs = ""; // holds javascript to write at the end
55 // If the Save button was clicked...
56 if ($_POST['form_save']) {
57 $form_pid = $_POST['form_pid'];
58 $form_pelist = $_POST['form_pelist'];
59 // $pattern = '|/(\d+),(\d+),([YN])|';
60 $pattern = '|/(\d+),(\d+)|';
62 preg_match_all($pattern, $form_pelist, $matches);
63 $numsets = count($matches[1]);
65 $query = "DELETE FROM issue_encounter WHERE pid = ?";
66 sqlQuery($query, array($form_pid));
67 for ($i = 0; $i < $numsets; ++
$i) {
68 $list_id = $matches[1][$i];
69 $encounter = $matches[2][$i];
70 $query = "INSERT INTO issue_encounter ( " .
71 "pid, list_id, encounter" .
75 sqlQuery($query, array($form_pid, $list_id, $encounter));
79 ."<script type=\"text/javascript\" src=\"". $webroot ."/interface/main/tabs/js/include_opener.js\"></script>"
80 . "<script language='JavaScript'>\n";
81 if ($alertmsg) echo " alert('" . addslashes($alertmsg) . "');\n";
82 echo " var myboss = opener ? opener : parent;\n";
83 echo " myboss.location.reload();\n";
84 echo " window.close();\n";
85 echo "</script></body></html>\n";
90 $pres = sqlStatement("SELECT * FROM lists WHERE pid = ? " .
91 "ORDER BY type, date", array($pid));
94 $eres = sqlStatement("SELECT * FROM form_encounter WHERE pid = ? " .
95 "ORDER BY date DESC", array($pid));
97 // get problem/encounter relations
98 $peres = sqlStatement("SELECT * FROM issue_encounter WHERE pid = ?", array($pid));
102 <?php
html_header_show();?
>
103 <script type
="text/javascript" src
="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script
>
104 <link rel
=stylesheet href
="<?php echo $css_header; ?>" type
="text/css">
105 <title
><?php
echo xlt('Issues and Encounters'); ?
></title
>
108 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
109 tr
.detail
{ font
-size
:10pt
; background
-color
:#eeeeee; }
112 <script type
="text/javascript" src
="../../library/topdialog.js"></script
>
113 <script type
="text/javascript" src
="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
115 <script language
="JavaScript">
117 // These are the possible colors for table rows.
118 var trcolors
= new Object();
119 // Colors for: Foreground Background
120 trcolors
['U'] = new Array('#000000', '#eeeeee'); // unselected
121 trcolors
['K'] = new Array('#000000', '#eeee00'); // selected key
122 // trcolors['Y'] = new Array('#000000', '#99ff99'); // selected value resolved=Y
123 // trcolors['N'] = new Array('#000000', '#ff9999'); // selected value resolved=N
124 trcolors
['V'] = new Array('#000000', '#9999ff'); // selected value
126 var pselected
= new Object();
127 var eselected
= new Object();
128 var keyid
= null; // id of currently hilited key, if any
130 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
132 // callback from add_edit_issue.php:
133 function refreshIssue(issue
, title
) {
134 top
.restoreSession();
138 // New Issue button is clicked.
139 function newIssue() {
140 var f
= document
.forms
[0];
141 var tmp
= (keyid
&& f
.form_key
[1].checked
) ?
('?enclink=' + keyid
) : '';
142 dlgopen('summary/add_edit_issue.php' + tmp
, '_blank', 600, 475);
145 // New Encounter button is clicked.
146 function newEncounter() {
147 var f
= document
.forms
[0];
148 if (!f
.form_save
.disabled
) {
149 if (!confirm('<?php echo xls('This will abandon your unsaved changes
. Are you sure?
'); ?>'))
152 top
.restoreSession();
153 var tmp
= (keyid
&& f
.form_key
[0].checked
) ?
('&issue=' + keyid
) : '';
154 opener
.top
.Title
.location
.href
='encounter/encounter_title.php';
155 opener
.top
.Main
.location
.href
='encounter/patient_encounter.php?mode=new' + tmp
;
159 // Determine if a given problem/encounter pair is currently linked.
160 // If yes, return the "resolved" character (Y or N), else an empty string.
161 function isPair(problem
, encounter
) {
162 var pelist
= document
.forms
[0].form_pelist
;
163 // var frag = '/' + problem + ',' + encounter + ',';
164 var frag
= '/' + problem +
',' + encounter +
'/';
165 var i
= pelist
.value
.indexOf(frag
);
166 if (i
< 0) return '';
167 // return pelist.value.charAt(i + frag.length);
171 // Unlink a problem/encounter pair.
172 function removePair(problem
, encounter
) {
173 var pelist
= document
.forms
[0].form_pelist
;
174 // var frag = '/' + problem + ',' + encounter + ',';
175 var frag
= '/' + problem +
',' + encounter +
'/';
176 var i
= pelist
.value
.indexOf(frag
);
178 // pelist.value = pelist.value.substring(0, i) + pelist.value.substring(i + frag.length + 1);
179 pelist
.value
= pelist
.value
.substring(0, i
) + pelist
.value
.substring(i + frag
.length
- 1);
180 document
.forms
[0].form_save
.disabled
= false;
184 // Link a new or modified problem/encounter pair.
185 // function addPair(problem, encounter, resolved) {
186 function addPair(problem
, encounter
) {
187 removePair(problem
, encounter
);
188 var pelist
= document
.forms
[0].form_pelist
;
189 // pelist.value += '' + problem + ',' + encounter + ',' + resolved + '/';
190 pelist
.value +
= '' + problem +
',' + encounter +
'/';
191 document
.forms
[0].form_save
.disabled
= false;
194 // Clear displayed highlights.
195 function doclearall(pfx
) {
196 var thisarr
= (pfx
== 'p') ? pselected
: eselected
;
197 for (var id in thisarr
) {
198 var thistr
= document
.getElementById(pfx +
'_' + id
);
201 thistr
.style
.color
= trcolors
['U'][0];
202 thistr
.style
.backgroundColor
= trcolors
['U'][1];
207 function clearall() {
213 // Process clicks on table rows.
214 function doclick(pfx
, id
) {
215 var thisstyle
= document
.getElementById(pfx +
'_' + id
).style
;
216 var thisarr
= (pfx
== 'p') ? pselected
: eselected
;
217 var piskey
= document
.forms
[0].form_key
[0].checked
;
218 var thisiskey
= (pfx
== 'p') ? piskey
: !piskey
;
219 var wasset
= thisarr
[id
];
220 if (thisiskey
) { // they clicked in the key table
222 if (!wasset
) { // this item is not already hilited
225 thisstyle
.color
= trcolors
['K'][0];
226 thisstyle
.backgroundColor
= trcolors
['K'][1];
227 // Now hilite the related value table entries:
228 if (pfx
== 'p') { // key is problems, values are encounters
229 for (key in eselected
) {
230 var resolved
= isPair(id
, key
);
231 if (resolved
.length
> 0) {
232 eselected
[key
] = resolved
;
233 var valstyle
= document
.getElementById('e_' + key
).style
;
234 valstyle
.color
= trcolors
[resolved
][0];
235 valstyle
.backgroundColor
= trcolors
[resolved
][1];
238 } else { // key is encounters, values are problems
239 for (key in pselected
) {
240 var resolved
= isPair(key
, id
);
241 if (resolved
.length
> 0) {
242 pselected
[key
] = resolved
;
243 var valstyle
= document
.getElementById('p_' + key
).style
;
244 valstyle
.color
= trcolors
[resolved
][0];
245 valstyle
.backgroundColor
= trcolors
[resolved
][1];
250 } else { // they clicked in the value table
252 var resolved
= thisarr
[id
];
253 // if (resolved == 'Y') { // it was hilited and resolved, change to unresolved
254 // thisarr[id] = 'N';
255 // thisstyle.color = trcolors['N'][0];
256 // thisstyle.backgroundColor = trcolors['N'][1];
257 // if (pfx == 'p') addPair(id, keyid, 'N'); else addPair(keyid, id, 'N');
258 // } else if (resolved == 'N') { // it was hilited and unresolved, remove it
259 if (resolved
!= '') { // hilited, so remove it
261 thisstyle
.color
= trcolors
['U'][0];
262 thisstyle
.backgroundColor
= trcolors
['U'][1];
263 if (pfx
== 'p') removePair(id
, keyid
); else removePair(keyid
, id
);
264 // } else { // not hilited, change to hilited and resolved
265 // thisarr[id] = 'Y';
266 // thisstyle.color = trcolors['Y'][0];
267 // thisstyle.backgroundColor = trcolors['Y'][1];
268 // if (pfx == 'p') addPair(id, keyid, 'Y'); else addPair(keyid, id, 'Y');
269 } else { // not hilited, change to hilited
271 thisstyle
.color
= trcolors
['V'][0];
272 thisstyle
.backgroundColor
= trcolors
['V'][1];
273 if (pfx
== 'p') addPair(id
, keyid
); else addPair(keyid
, id
);
276 alert('<?php echo xls('You must first select an item in the section whose radio button is checked
.') ;?>');
284 <body leftmargin
='0' topmargin
='0' marginwidth
='0' marginheight
='0'
285 bgcolor
='#ffffff' onunload
='imclosing()'>
286 <form method
='post' action
='problem_encounter.php' onsubmit
='return top.restoreSession()'>
288 echo "<input type='hidden' name='form_pid' value='" . attr($pid) . "' />\n";
289 // pelist looks like /problem,encounter/problem,encounter/[...].
290 echo "<input type='hidden' name='form_pelist' value='/";
291 while ($row = sqlFetchArray($peres)) {
292 // echo $row['list_id'] . "," . $row['encounter'] . "," .
293 // ($row['resolved'] ? "Y" : "N") . "/";
294 echo text($row['list_id']) . "," . text($row['encounter']) . "/";
299 <table border
='0' cellpadding
='5' cellspacing
='0' width
='100%'>
302 <td colspan
='2' align
='center'>
303 <b
><?php
echo xlt('Issues and Encounters for'); ?
> <?php
echo text($patdata['fname']) . " " . text($patdata['lname']) . " (" . text($pid) . ")</b>\n"; ?
>
308 <td align
='center' valign
='top'>
309 <table width
='100%' cellpadding
='1' cellspacing
='2'>
311 <td colspan
='3' align
='center'>
312 <input type
='radio' name
='form_key' value
='p' onclick
='clearall()' checked
/>
313 <b
><?php
echo xlt('Issues Section'); ?
></b
>
317 <td
><?php
echo xlt('Type'); ?
></td
>
318 <td
><?php
echo xlt('Title'); ?
></td
>
319 <td
><?php
echo xlt('Description'); ?
></td
>
322 while ($row = sqlFetchArray($pres)) {
324 echo " <tr class='detail' id='p_" . attr($rowid) . "' onclick='doclick(\"p\", " . attr(addslashes($rowid)) . ")'>\n";
325 echo " <td valign='top'>" . text($ISSUE_TYPES[($row['type'])][1]) . "</td>\n";
326 echo " <td valign='top'>" . text($row['title']) . "</td>\n";
327 echo " <td valign='top'>" . text($row['comments']) . "</td>\n";
329 $endjs .= "pselected['" . attr($rowid) . "'] = '';\n";
334 <td align
='center' valign
='top'>
335 <table width
='100%' cellpadding
='1' cellspacing
='2'>
337 <td colspan
='2' align
='center'>
338 <input type
='radio' name
='form_key' value
='e' onclick
='clearall()' />
339 <b
><?php
echo xlt('Encounters Section'); ?
></b
>
343 <td
><?php
echo xlt('Date'); ?
></td
>
344 <td
><?php
echo xlt('Presenting Complaint'); ?
></td
>
347 while ($row = sqlFetchArray($eres)) {
348 $rowid = $row['encounter'];
349 echo " <tr class='detail' id='e_" . attr($rowid) . "' onclick='doclick(\"e\", " . attr(addslashes($rowid)) . ")'>\n";
350 echo " <td valign='top'>" . text(substr($row['date'], 0, 10)) . "</td>\n";
351 echo " <td valign='top'>" . text($row['reason']) . "</td>\n";
353 $endjs .= "eselected['" . attr($rowid) . "'] = '';\n";
361 <td colspan
='2' align
='center'>
362 <input type
='submit' name
='form_save' value
='<?php echo xla('Save
'); ?>' disabled
/>  
;
363 <input type
='button' value
='<?php echo xla('Add Issue
'); ?>' onclick
='newIssue()' />
364 <input type
='button' value
='<?php echo xla('Cancel
'); ?>' onclick
='window.close()' />
372 <p
><b
><?php
echo xlt('Instructions:'); ?
></b
> <?php
echo xlt('Choose a section and click an item within it; then in
373 the other section you will see the related items highlighted, and you can click
374 in that section to add and delete relationships.'); ?
>
380 if ($_REQUEST['issue']) {
381 echo "doclick('p', " . attr(addslashes($_REQUEST['issue'])) . ");\n";
383 if ($alertmsg) echo "alert('" . addslashes($alertmsg) . "');\n";