Advance Directives addition by Thomas Wong's group
[openemr.git] / interface / patient_file / summary / demographics.php
blob4d28d57495e6161e1680a893327690d1a0b13581
1 <?php
2 require_once("../../globals.php");
3 require_once("$srcdir/patient.inc");
4 require_once("$srcdir/acl.inc");
5 require_once("$srcdir/classes/Address.class.php");
6 require_once("$srcdir/classes/InsuranceCompany.class.php");
7 require_once("./patient_picture.php");
8 require_once("$srcdir/options.inc.php");
9 if ($GLOBALS['concurrent_layout'] && $_GET['set_pid']) {
10 include_once("$srcdir/pid.inc");
11 setpid($_GET['set_pid']);
14 function print_as_money($money) {
15 preg_match("/(\d*)\.?(\d*)/",$money,$moneymatches);
16 $tmp = wordwrap(strrev($moneymatches[1]),3,",",1);
17 $ccheck = strrev($tmp);
18 if ($ccheck[0] == ",") {
19 $tmp = substr($ccheck,1,strlen($ccheck)-1);
21 if ($moneymatches[2] != "") {
22 return "$ " . strrev($tmp) . "." . $moneymatches[2];
23 } else {
24 return "$ " . strrev($tmp);
28 <html>
30 <head>
31 <?php html_header_show();?>
32 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
33 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
34 <script type="text/javascript" src="../../../library/textformat.js"></script>
35 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
36 <script type="text/javascript" src="../../../library/dynarch_calendar_en.js"></script>
37 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
38 <script type="text/javascript" src="../../../library/dialog.js"></script>
39 <script language="JavaScript">
41 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
43 function oldEvt(eventid) {
44 dlgopen('../../main/calendar/add_edit_event.php?eid=' + eventid, '_blank', 550, 270);
47 function advdirconfigure() {
48 dlgopen('advancedirectives.php', '_blank', 500, 450);
51 function refreshme() {
52 top.restoreSession();
53 location.reload();
56 // Process click on Delete link.
57 function deleteme() {
58 dlgopen('../deleter.php?patient=<?php echo $pid ?>', '_blank', 500, 450);
59 return false;
62 // Called by the deleteme.php window on a successful delete.
63 function imdeleted() {
64 <?php if ($GLOBALS['concurrent_layout']) { ?>
65 parent.left_nav.clearPatient();
66 <?php } else { ?>
67 top.restoreSession();
68 top.location.href = '../main/main_screen.php';
69 <?php } ?>
72 function validate() {
73 var f = document.forms[0];
74 <?php
75 if ($GLOBALS['athletic_team']) {
76 echo " if (f.form_userdate1.value != f.form_original_userdate1.value) {\n";
77 $irow = sqlQuery("SELECT id, title FROM lists WHERE " .
78 "pid = '$pid' AND enddate IS NULL ORDER BY begdate DESC LIMIT 1");
79 if (!empty($irow)) {
81 if (confirm('Do you wish to also set this new return date in the issue titled "<?php echo addslashes($irow['title']) ?>"?')) {
82 f.form_issue_id.value = '<?php echo $irow['id'] ?>';
83 } else {
84 alert('OK, you will need to manually update the return date in any affected issue(s).');
86 <?php } else { ?>
87 alert('You have changed the return date but there are no open issues. You probably need to create or modify one.');
88 <?php
89 } // end empty $irow
90 echo " }\n";
91 } // end athletic team
93 return true;
96 function newEvt() {
97 dlgopen('../../main/calendar/add_edit_event.php?patientid=<?php echo $pid ?>', '_blank', 550, 270);
98 return false;
101 function sendimage(pid, what) {
102 // alert('Not yet implemented.'); return false;
103 dlgopen('../upload_dialog.php?patientid=' + pid + '&file=' + what,
104 '_blank', 500, 400);
105 return false;
107 </script>
108 </head>
110 <body class="body_top">
111 <?php
112 $result = getPatientData($pid, "*, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
113 $result2 = getEmployerData($pid);
115 $thisauth = acl_check('patients', 'demo');
116 if ($thisauth) {
117 if ($result['squad'] && ! acl_check('squads', $result['squad']))
118 $thisauth = 0;
121 if (!$thisauth) {
122 echo "<p>(" . xl('Demographics not authorized') . ")</p>\n";
123 echo "</body>\n</html>\n";
124 exit();
127 if ($thisauth == 'write') {
128 foreach (pic_array() as $var) {print $var;}
129 echo "<table cellspacing=0 cellpadding=0 width=100%><tr><td><p><a href='demographics_full.php'";
130 if (! $GLOBALS['concurrent_layout']) echo " target='Main'";
131 echo " onclick='top.restoreSession()'><span class='title'>" .
132 xl('Demographics') . "</span>" .
133 " <span class='more'>$tmore</span></a>";
134 if (acl_check('admin', 'super')) {
135 echo "&nbsp;&nbsp;<a href='' onclick='return deleteme()'>" .
136 "<span class='more' style='color:red'>(".xl('Delete').")</span></a>";
138 echo "</p></td><td align=right><div id=DEM><table cellspacing=0 cellpadding=0 width=100%><tr><td class='label'>";
139 if ($GLOBALS['advance_directives_warning'])
141 echo "<a title='" . xl('Click here to manage Advance Directives') . "' href='#' onclick='return advdirconfigure()'>";
142 echo xl('Advance Directives').":";
143 echo "</a>";
144 $counterFlag = false; //flag to record whether any categories contain ad records
145 $query = "SELECT id FROM categories WHERE name='Advance Directive'";
146 $myrow2 = sqlQuery($query);
147 if ($myrow2) {
148 $parentId = $myrow2['id'];
149 $query = "SELECT id, name FROM categories WHERE parent='$parentId'";
150 $resNew1 = sqlStatement($query);
151 while ($myrows3 = sqlFetchArray($resNew1)) {
152 $categoryId = $myrows3['id'];
153 $nameDoc = $myrows3['name'];
154 $query = "SELECT documents.date, documents.id " .
155 "FROM documents " .
156 "INNER JOIN categories_to_documents " .
157 "ON categories_to_documents.document_id=documents.id " .
158 "WHERE categories_to_documents.category_id='$categoryId' " .
159 "AND documents.foreign_id='$pid' " .
160 "ORDER BY documents.date DESC";
161 $resNew2 = sqlStatement($query);
162 $limitCounter = 0; // limit to one entry per category
163 while (($myrows4 = sqlFetchArray($resNew2)) && ($limitCounter == 0)) {
164 $dateTimeDoc = $myrows4['date'];
165 // remove time from datetime stamp
166 $tempParse = explode(" ",$dateTimeDoc);
167 $dateDoc = $tempParse[0];
168 $idDoc = $myrows4['id'];
169 echo "<br>";
170 echo "<a href='$web_root/controller.php?document&retrieve&patient_id=$pid&document_id=" .
171 $idDoc . "&as_file=true'>" . xl_document_category($nameDoc) . "</a> " . $dateDoc;
172 $limitCounter = $limitCounter + 1;
173 $counterFlag = true;
177 if (!$counterFlag) {
178 echo "<br>";
179 echo '<a title="' . xl("Click here to manage Advance Directives") .
180 '" href="#" onclick="return advdirconfigure()"><span style="color:red;">' .
181 xl("No Advance Directive Document Was Found"). '</span></a>';
184 echo "</td><td width=10></td></tr></table></div></td></tr></table><br>";
187 // Get the document ID of the patient ID card if access to it is wanted here.
188 $document_id = 0;
189 if ($GLOBALS['patient_id_category_name']) {
190 $tmp = sqlQuery("SELECT d.id, d.date, d.url FROM " .
191 "documents AS d, categories_to_documents AS cd, categories AS c " .
192 "WHERE d.foreign_id = $pid " .
193 "AND cd.document_id = d.id " .
194 "AND c.id = cd.category_id " .
195 "AND c.name LIKE '" . $GLOBALS['patient_id_category_name'] . "' " .
196 "ORDER BY d.date DESC LIMIT 1");
197 if ($tmp) $document_id = $tmp['id'];
201 <table border="0" width="100%">
202 <tr>
203 <!-- Left column of main table; contains another table -->
204 <td align="left" valign="top">
205 <div id="DEM">
206 <table border='0' cellpadding='0'>
207 <?php display_layout_rows('DEM', $result, $result2); ?>
208 </table>
209 </div>
211 <table border='0' cellpadding='0' width='100%'>
212 <?php
213 ///////////////////////////////// INSURANCE SECTION
215 foreach (array('primary','secondary','tertiary') as $instype) {
216 $enddate = 'Present';
218 $query = "SELECT * FROM insurance_data WHERE " .
219 "pid = '$pid' AND type = '$instype' " .
220 "ORDER BY date DESC";
221 $res = sqlStatement($query);
222 while ($row = sqlFetchArray($res)) {
223 if ($row['provider']) {
224 $icobj = new InsuranceCompany($row['provider']);
225 $adobj = $icobj->get_address();
226 $insco_name = trim($icobj->get_name());
228 <tr>
229 <td valign='top' colspan='3'>
230 <br><span class='bold'>
231 <?php if (strcmp($enddate, 'Present') != 0) echo "Old "; ?>
232 <?php xl(ucfirst($instype) . ' Insurance','e'); ?>
233 <?php if (strcmp($row['date'], '0000-00-00') != 0) { ?>
234 <?php xl(' from','e'); echo ' ' . $row['date']; ?>
235 <?php } ?>
236 <?php xl(' until ','e'); echo $enddate; ?>
237 :</span>
238 </td>
239 </tr>
240 <tr>
241 <td valign='top'>
242 <span class='text'>
243 <?php
244 if ($insco_name) {
245 echo $insco_name . '<br>';
246 if (trim($adobj->get_line1())) {
247 echo $adobj->get_line1() . '<br>';
248 echo $adobj->get_city() . ', ' . $adobj->get_state() . ' ' . $adobj->get_zip();
250 } else {
251 echo "<font color='red'><b>Unassigned</b></font>";
254 <br>
255 <?php xl('Policy Number','e'); ?>: <?php echo $row['policy_number'] ?><br>
256 Plan Name: <?php echo $row['plan_name']; ?><br>
257 Group Number: <?php echo $row['group_number']; ?></span>
258 </td>
259 <td valign='top'>
260 <span class='bold'><?php xl('Subscriber','e'); ?>: </span><br>
261 <span class='text'><?php echo $row['subscriber_fname'] . ' ' . $row['subscriber_mname'] . ' ' . $row['subscriber_lname'] ?>
262 <?php
263 if ($row['subscriber_relationship'] != "") {
264 echo "(" . $row['subscriber_relationship'] . ")";
267 <br>
268 S.S.: <?php echo $row['subscriber_ss']; ?><br>
269 <?php xl('D.O.B.','e'); ?>:
270 <?php if ($row['subscriber_DOB'] != "0000-00-00 00:00:00") echo $row['subscriber_DOB']; ?><br>
271 Phone: <?php echo $row['subscriber_phone'] ?>
272 </span>
273 </td>
274 <td valign='top'>
275 <span class='bold'><?php xl('Subscriber Address','e'); ?>: </span><br>
276 <span class='text'><?php echo $row['subscriber_street']; ?><br>
277 <?php echo $row['subscriber_city']; ?>
278 <?php if($row['subscriber_state'] != "") echo ", "; echo $row['subscriber_state']; ?>
279 <?php if($row['subscriber_country'] != "") echo ", "; echo $row['subscriber_country']; ?>
280 <?php echo " " . $row['subscriber_postal_code']; ?></span>
282 <?php if (trim($row['subscriber_employer'])) { ?>
283 <br><span class='bold'><?php xl('Subscriber Employer','e'); ?>: </span><br>
284 <span class='text'><?php echo $row['subscriber_employer']; ?><br>
285 <?php echo $row['subscriber_employer_street']; ?><br>
286 <?php echo $row['subscriber_employer_city']; ?>
287 <?php if($row['subscriber_employer_city'] != "") echo ", "; echo $row['subscriber_employer_state']; ?>
288 <?php if($row['subscriber_employer_country'] != "") echo ", "; echo $row['subscriber_employer_country']; ?>
289 <?php echo " " . $row['subscriber_employer_postal_code']; ?>
290 </span>
291 <?php } ?>
293 </td>
294 </tr>
295 <tr>
296 <td>
297 <?php if ($row['copay'] != "") { ?>
298 <span class='bold'><?php xl('CoPay','e'); ?>: </span>
299 <span class='text'><?php echo $row['copay']; ?></span>
300 <?php } ?>
301 <br>
302 <span class='bold'><?php xl('Accept Assignment','e'); ?>:</span>
303 <span class='text'><?php if($row['accept_assignment'] == "TRUE") echo "YES"; ?>
304 <?php if($row['accept_assignment'] == "FALSE") echo "NO"; ?></span>
305 </td>
306 <td valign='top'></td>
307 <td valign='top'></td>
308 </tr>
309 <?php
310 } // end if ($row['provider'])
311 $enddate = $row['date'];
312 } // end while
313 } // end foreach
315 ///////////////////////////////// END INSURANCE SECTION
318 </table>
319 </td>
321 <!-- Right column of main table -->
323 <td valign="top" class="text">
324 <?php
326 // This is a feature for a specific client. -- Rod
327 if ($GLOBALS['cene_specific']) {
328 echo " <br />\n";
330 $imagedir = "$webserver_root/documents/$pid/demographics";
331 $imagepath = "$web_root/documents/$pid/demographics";
333 echo " <a href='' onclick=\"return sendimage($pid, 'photo');\" " .
334 "title='Click to attach patient image'>\n";
335 if (is_file("$imagedir/photo.jpg")) {
336 echo " <img src='$imagepath/photo.jpg' /></a>\n";
337 } else {
338 echo " Attach Patient Image</a><br />\n";
340 echo " <br />&nbsp;<br />\n";
342 echo " <a href='' onclick=\"return sendimage($pid, 'fingerprint');\" " .
343 "title='Click to attach fingerprint'>\n";
344 if (is_file("$imagedir/fingerprint.jpg")) {
345 echo " <img src='$imagepath/fingerprint.jpg' /></a>\n";
346 } else {
347 echo " Attach Biometric Fingerprint</a><br />\n";
349 echo " <br />&nbsp;<br />\n";
352 // This stuff only applies to athletic team use of OpenEMR. The client
353 // insisted on being able to quickly change fitness and return date here:
355 if ($GLOBALS['athletic_team']) {
356 // blue green yellow red orange
357 $fitcolors = array('#6677ff','#00cc00','#ffff00','#ff3333','#ff8800','#ffeecc','#ffccaa');
358 if (!empty($GLOBALS['fitness_colors'])) $fitcolors = $GLOBALS['fitness_colors'];
359 $fitcolor = $fitcolors[0];
360 $form_fitness = $_POST['form_fitness'];
361 $form_userdate1 = fixDate($_POST['form_userdate1'], '');
362 $form_issue_id = $_POST['form_issue_id'];
363 if ($form_submit) {
364 $returndate = $form_userdate1 ? "'$form_userdate1'" : "NULL";
365 sqlStatement("UPDATE patient_data SET fitness = '$form_fitness', " .
366 "userdate1 = $returndate WHERE pid = '$pid'");
367 // Update return date in the designated issue, if requested.
368 if ($form_issue_id) {
369 sqlStatement("UPDATE lists SET returndate = $returndate WHERE " .
370 "id = '$form_issue_id'");
372 } else {
373 $form_fitness = $result['fitness'];
374 if (! $form_fitness) $form_fitness = 1;
375 $form_userdate1 = $result['userdate1'];
377 $fitcolor = $fitcolors[$form_fitness - 1];
378 echo " <form method='post' action='demographics.php' onsubmit='return validate()'>\n";
379 echo " <span class='bold'>Fitness to Play:</span><br />\n";
380 echo " <select name='form_fitness' style='background-color:$fitcolor'>\n";
381 $res = sqlStatement("SELECT * FROM list_options WHERE " .
382 "list_id = 'fitness' ORDER BY seq");
383 while ($row = sqlFetchArray($res)) {
384 $key = $row['option_id'];
385 echo " <option value='$key'";
386 if ($key == $form_fitness) echo " selected";
387 echo ">" . $row['title'] . "</option>\n";
389 echo " </select>\n";
390 echo " <br /><span class='bold'>Return to Play:</span><br>\n";
391 echo " <input type='text' size='10' name='form_userdate1' id='form_userdate1' " .
392 "value='$form_userdate1' " .
393 "title='" . xl('yyyy-mm-dd Date of return to play') . "' " .
394 "onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />\n" .
395 " <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22' " .
396 "id='img_userdate1' border='0' alt='[?]' style='cursor:pointer' " .
397 "title='" . xl('Click here to choose a date') . "'>\n";
398 echo " <input type='hidden' name='form_original_userdate1' value='$form_userdate1' />\n";
399 echo " <input type='hidden' name='form_issue_id' value='' />\n";
400 echo "<p><input type='submit' name='form_submit' value='Change' /></p>\n";
401 echo " </form>\n";
404 if ($GLOBALS['oer_config']['ws_accounting']['enabled']) {
405 // Show current balance and billing note, if any.
406 echo "<span class='bold'><font color='#ee6600'>" . xl('Balance Due') . ": " . xl('$') .
407 get_patient_balance($pid) . "</font><br />";
408 if ($result['genericname2'] == 'Billing') {
409 xl('Billing Note') . ":";
410 echo "<span class='bold'><font color='red'>" .
411 $result['genericval2'] . "</font></span>";
413 echo "</span><br />";
416 // If there is a patient ID card, then show a link to it.
417 if ($document_id) {
418 echo "<a href='" . $web_root . "/controller.php?document&retrieve" .
419 "&patient_id=$pid&document_id=$document_id' style='color:#00cc00' " .
420 "onclick='top.restoreSession()'>Click for ID card</a><br />";
423 // Show current and upcoming appointments.
424 if (isset($pid) && !$GLOBALS['disable_calendar']) {
425 $query = "SELECT e.pc_eid, e.pc_aid, e.pc_title, e.pc_eventDate, " .
426 "e.pc_startTime, e.pc_hometext, u.fname, u.lname, u.mname, " .
427 "c.pc_catname " .
428 "FROM openemr_postcalendar_events AS e, users AS u, " .
429 "openemr_postcalendar_categories AS c WHERE " .
430 "e.pc_pid = '$pid' AND e.pc_eventDate >= CURRENT_DATE AND " .
431 "u.id = e.pc_aid AND e.pc_catid = c.pc_catid " .
432 "ORDER BY e.pc_eventDate, e.pc_startTime";
433 $res = sqlStatement($query);
435 if (isset($res) && $res != null) {
436 echo "<div id='appts'><span id='apptstitle'>" . xl('Upcoming Appointments') . "</span><br>";
437 // link to create a new appointment
438 echo "<span class='link' style='margin: 2px 0px 5px 0px; width:100%; text-align: center;'>";
439 echo "<a href='#' onclick='return newEvt()'>".xl('New Appointment')."</a>";
440 echo "</span><br>";
442 while($row = sqlFetchArray($res)) {
443 $dayname = date("l", strtotime($row['pc_eventDate']));
444 $dispampm = "am";
445 $disphour = substr($row['pc_startTime'], 0, 2) + 0;
446 $dispmin = substr($row['pc_startTime'], 3, 2);
447 if ($disphour >= 12) {
448 $dispampm = "pm";
449 if ($disphour > 12) $disphour -= 12;
451 $etitle = xl('(Click to edit)');
452 if ($row['pc_hometext'] != "") {
453 $etitle = xl('Comments').": ".addslashes($row['pc_hometext'])."\r\n".$etitle;
455 echo "<a href='javascript:oldEvt(" . $row['pc_eid'] . ")' title='$etitle'>";
456 echo "<b>" . xl($dayname) . ", " . $row['pc_eventDate'] . "</b><br>";
457 echo "$disphour:$dispmin " . xl($dispampm) . " " . xl_appt_category($row['pc_catname']) . "<br>\n";
458 echo $row['fname'] . " " . $row['lname'] . "</a><br>&nbsp;<br>\n";
460 if (isset($res) && $res != null) { echo "</div>"; }
463 </td>
465 </tr>
466 </table>
468 <?php if ($GLOBALS['concurrent_layout'] && $_GET['set_pid']) { ?>
469 <script language='JavaScript'>
470 parent.left_nav.setPatient(<?php echo "'" . addslashes($result['fname']) . " " . addslashes($result['lname']) . "',$pid,'" . addslashes($result['pubpid']) . "','', ' ".xl('DOB').": ".$result['DOB_YMD']." ".xl('Age').": ".getPatientAge($result['DOB_YMD'])."'"; ?>);
471 parent.left_nav.setRadio(window.name, 'dem');
472 <?php if (!$_GET['is_new']) { // if new pt, do not load other frame ?>
473 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
474 parent.left_nav.forceDual();
475 parent.left_nav.setRadio(othername, 'sum');
476 parent.left_nav.loadFrame('sum1', othername, 'patient_file/summary/summary_bottom.php');
477 <?php } ?>
478 </script>
479 <?php } ?>
481 <?php if ($GLOBALS['athletic_team']) { ?>
482 <script language='JavaScript'>
483 Calendar.setup({inputField:"form_userdate1", ifFormat:"%Y-%m-%d", button:"img_userdate1"});
484 </script>
485 <?php } ?>
487 </body>
488 </html>