Moved picture display code below security check (thanks cfapress).
[openemr.git] / interface / patient_file / summary / demographics.php
blob78ea9b8cd0eee759480caff0e8a7a4583ee89431
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 = '<? echo $GLOBALS['phone_country_code'] ?>';
43 function oldEvt(eventid) {
44 dlgopen('../../main/calendar/add_edit_event.php?eid=' + eventid, '_blank', 550, 270);
47 function refreshme() {
48 top.restoreSession();
49 location.reload();
52 // Process click on Delete link.
53 function deleteme() {
54 dlgopen('../deleter.php?patient=<?php echo $pid ?>', '_blank', 500, 450);
55 return false;
58 // Called by the deleteme.php window on a successful delete.
59 function imdeleted() {
60 <?php if ($GLOBALS['concurrent_layout']) { ?>
61 parent.left_nav.clearPatient();
62 <?php } else { ?>
63 top.restoreSession();
64 top.location.href = '../main/main_screen.php';
65 <?php } ?>
68 function validate() {
69 var f = document.forms[0];
70 <?php
71 if ($GLOBALS['athletic_team']) {
72 echo " if (f.form_userdate1.value != f.form_original_userdate1.value) {\n";
73 $irow = sqlQuery("SELECT id, title FROM lists WHERE " .
74 "pid = '$pid' AND enddate IS NULL ORDER BY begdate DESC LIMIT 1");
75 if (!empty($irow)) {
77 if (confirm('Do you wish to also set this new return date in the issue titled "<?php echo addslashes($irow['title']) ?>"?')) {
78 f.form_issue_id.value = '<?php echo $irow['id'] ?>';
79 } else {
80 alert('OK, you will need to manually update the return date in any affected issue(s).');
82 <?php } else { ?>
83 alert('You have changed the return date but there are no open issues. You probably need to create or modify one.');
84 <?php
85 } // end empty $irow
86 echo " }\n";
87 } // end athletic team
89 return true;
92 </script>
93 </head>
95 <body class="body_top">
96 <?php
97 $result = getPatientData($pid);
98 $result2 = getEmployerData($pid);
100 $thisauth = acl_check('patients', 'demo');
101 if ($thisauth) {
102 if ($result['squad'] && ! acl_check('squads', $result['squad']))
103 $thisauth = 0;
106 if (!$thisauth) {
107 echo "<p>(" . xl('Demographics not authorized') . ")</p>\n";
108 echo "</body>\n</html>\n";
109 exit();
112 if ($thisauth == 'write') {
113 foreach (pic_array() as $var) {print $var;}
114 echo "<p><a href='demographics_full.php'";
115 if (! $GLOBALS['concurrent_layout']) echo " target='Main'";
116 echo " onclick='top.restoreSession()'><span class='title'>" .
117 xl('Demographics') . "</span>" .
118 " <span class='more'>$tmore</span></a>";
119 if (acl_check('admin', 'super')) {
120 echo "&nbsp;&nbsp;<a href='' onclick='return deleteme()'>" .
121 "<span class='more' style='color:red'>(".xl('Delete').")</span></a>";
123 echo "</p>\n";
126 // Get the document ID of the patient ID card if access to it is wanted here.
127 $document_id = 0;
128 if ($GLOBALS['patient_id_category_name']) {
129 $tmp = sqlQuery("SELECT d.id, d.date, d.url FROM " .
130 "documents AS d, categories_to_documents AS cd, categories AS c " .
131 "WHERE d.foreign_id = $pid " .
132 "AND cd.document_id = d.id " .
133 "AND c.id = cd.category_id " .
134 "AND c.name LIKE '" . $GLOBALS['patient_id_category_name'] . "' " .
135 "ORDER BY d.date DESC LIMIT 1");
136 if ($tmp) $document_id = $tmp['id'];
140 <table border="0" width="100%">
141 <tr>
142 <!-- Left column of main table; contains another table -->
143 <td align="left" valign="top">
144 <div id="DEM">
145 <table border='0' cellpadding='0'>
146 <?php display_layout_rows('DEM', $result, $result2); ?>
147 </table>
148 </div>
150 <table border='0' cellpadding='0' width='100%'>
151 <?php
152 ///////////////////////////////// INSURANCE SECTION
154 foreach (array('primary','secondary','tertiary') as $instype) {
155 $enddate = 'Present';
157 $query = "SELECT * FROM insurance_data WHERE " .
158 "pid = '$pid' AND type = '$instype' " .
159 "ORDER BY date DESC";
160 $res = sqlStatement($query);
161 while ($row = sqlFetchArray($res)) {
162 if ($row['provider']) {
163 $icobj = new InsuranceCompany($row['provider']);
164 $adobj = $icobj->get_address();
165 $insco_name = trim($icobj->get_name());
167 <tr>
168 <td valign='top' colspan='3'>
169 <br><span class='bold'>
170 <?php if (strcmp($enddate, 'Present') != 0) echo "Old "; ?>
171 <?php xl(ucfirst($instype) . ' Insurance','e'); ?>
172 <?php if (strcmp($row['date'], '0000-00-00') != 0) { ?>
173 <?php xl(' from','e'); echo ' ' . $row['date']; ?>
174 <?php } ?>
175 <?php xl(' until ','e'); echo $enddate; ?>
176 :</span>
177 </td>
178 </tr>
179 <tr>
180 <td valign='top'>
181 <span class='text'>
182 <?php
183 if ($insco_name) {
184 echo $insco_name . '<br>';
185 if (trim($adobj->get_line1())) {
186 echo $adobj->get_line1() . '<br>';
187 echo $adobj->get_city() . ', ' . $adobj->get_state() . ' ' . $adobj->get_zip();
189 } else {
190 echo "<font color='red'><b>Unassigned</b></font>";
193 <br>
194 <?php xl('Policy Number','e'); ?>: <?php echo $row['policy_number'] ?><br>
195 Plan Name: <?php echo $row['plan_name']; ?><br>
196 Group Number: <?php echo $row['group_number']; ?></span>
197 </td>
198 <td valign='top'>
199 <span class='bold'><?php xl('Subscriber','e'); ?>: </span><br>
200 <span class='text'><?php echo $row['subscriber_fname'] . ' ' . $row['subscriber_mname'] . ' ' . $row['subscriber_lname'] ?>
201 <?php
202 if ($row['subscriber_relationship'] != "") {
203 echo "(" . $row['subscriber_relationship'] . ")";
206 <br>
207 S.S.: <?php echo $row['subscriber_ss']; ?><br>
208 <?php xl('D.O.B.','e'); ?>:
209 <?php if ($row['subscriber_DOB'] != "0000-00-00 00:00:00") echo $row['subscriber_DOB']; ?><br>
210 Phone: <?php echo $row['subscriber_phone'] ?>
211 </span>
212 </td>
213 <td valign='top'>
214 <span class='bold'><?php xl('Subscriber Address','e'); ?>: </span><br>
215 <span class='text'><?php echo $row['subscriber_street']; ?><br>
216 <?php echo $row['subscriber_city']; ?>
217 <?php if($row['subscriber_state'] != "") echo ", "; echo $row['subscriber_state']; ?>
218 <?php if($row['subscriber_country'] != "") echo ", "; echo $row['subscriber_country']; ?>
219 <?php echo " " . $row['subscriber_postal_code']; ?></span>
221 <?php if (trim($row['subscriber_employer'])) { ?>
222 <br><span class='bold'><?php xl('Subscriber Employer','e'); ?>: </span><br>
223 <span class='text'><?php echo $row['subscriber_employer']; ?><br>
224 <?php echo $row['subscriber_employer_street']; ?><br>
225 <?php echo $row['subscriber_employer_city']; ?>
226 <?php if($row['subscriber_employer_city'] != "") echo ", "; echo $row['subscriber_employer_state']; ?>
227 <?php if($row['subscriber_employer_country'] != "") echo ", "; echo $row['subscriber_employer_country']; ?>
228 <?php echo " " . $row['subscriber_employer_postal_code']; ?>
229 </span>
230 <?php } ?>
232 </td>
233 </tr>
234 <tr>
235 <td>
236 <?php if ($row['copay'] != "") { ?>
237 <span class='bold'><?php xl('CoPay','e'); ?>: </span>
238 <span class='text'><?php echo $row['copay']; ?></span>
239 <?php } ?>
240 <br>
241 <span class='bold'><?php xl('Accept Assignment','e'); ?>:</span>
242 <span class='text'><?php if($row['accept_assignment'] == "TRUE") echo "YES"; ?>
243 <?php if($row['accept_assignment'] == "FALSE") echo "NO"; ?></span>
244 </td>
245 <td valign='top'></td>
246 <td valign='top'></td>
247 </tr>
248 <?php
249 } // end if ($row['provider'])
250 $enddate = $row['date'];
251 } // end while
252 } // end foreach
254 ///////////////////////////////// END INSURANCE SECTION
257 </table>
258 </td>
260 <!-- Right column of main table -->
262 <td valign="top" class="text">
263 <?php
265 // This stuff only applies to athletic team use of OpenEMR. The client
266 // insisted on being able to quickly change fitness and return date here:
268 if ($GLOBALS['athletic_team']) {
269 // blue green yellow red orange
270 $fitcolors = array('#6677ff','#00cc00','#ffff00','#ff3333','#ff8800','#ffeecc','#ffccaa');
271 if (!empty($GLOBALS['fitness_colors'])) $fitcolors = $GLOBALS['fitness_colors'];
272 $fitcolor = $fitcolors[0];
273 $form_fitness = $_POST['form_fitness'];
274 $form_userdate1 = fixDate($_POST['form_userdate1'], '');
275 $form_issue_id = $_POST['form_issue_id'];
276 if ($form_submit) {
277 $returndate = $form_userdate1 ? "'$form_userdate1'" : "NULL";
278 sqlStatement("UPDATE patient_data SET fitness = '$form_fitness', " .
279 "userdate1 = $returndate WHERE pid = '$pid'");
280 // Update return date in the designated issue, if requested.
281 if ($form_issue_id) {
282 sqlStatement("UPDATE lists SET returndate = $returndate WHERE " .
283 "id = '$form_issue_id'");
285 } else {
286 $form_fitness = $result['fitness'];
287 if (! $form_fitness) $form_fitness = 1;
288 $form_userdate1 = $result['userdate1'];
290 $fitcolor = $fitcolors[$form_fitness - 1];
291 echo " <form method='post' action='demographics.php' onsubmit='return validate()'>\n";
292 echo " <span class='bold'>Fitness to Play:</span><br />\n";
293 echo " <select name='form_fitness' style='background-color:$fitcolor'>\n";
294 $res = sqlStatement("SELECT * FROM list_options WHERE " .
295 "list_id = 'fitness' ORDER BY seq");
296 while ($row = sqlFetchArray($res)) {
297 $key = $row['option_id'];
298 echo " <option value='$key'";
299 if ($key == $form_fitness) echo " selected";
300 echo ">" . $row['title'] . "</option>\n";
302 echo " </select>\n";
303 echo " <br /><span class='bold'>Return to Play:</span><br>\n";
304 echo " <input type='text' size='10' name='form_userdate1' id='form_userdate1' " .
305 "value='$form_userdate1' " .
306 "title='" . xl('yyyy-mm-dd Date of return to play') . "' " .
307 "onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />\n" .
308 " <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22' " .
309 "id='img_userdate1' border='0' alt='[?]' style='cursor:pointer' " .
310 "title='" . xl('Click here to choose a date') . "'>\n";
311 echo " <input type='hidden' name='form_original_userdate1' value='$form_userdate1' />\n";
312 echo " <input type='hidden' name='form_issue_id' value='' />\n";
313 echo "<p><input type='submit' name='form_submit' value='Change' /></p>\n";
314 echo " </form>\n";
317 if ($GLOBALS['oer_config']['ws_accounting']['enabled']) {
318 // Show current balance and billing note, if any.
319 echo "<span class='bold'><font color='#ee6600'>Balance Due: $" .
320 get_patient_balance($pid) . "</font><br />";
321 if ($result['genericname2'] == 'Billing') {
322 xl('Billing Note') . ":";
323 echo "<span class='bold'><font color='red'>" .
324 $result['genericval2'] . "</font></span>";
326 echo "</span><br />";
329 // If there is a patient ID card, then show a link to it.
330 if ($document_id) {
331 echo "<a href='" . $web_root . "/controller.php?document&retrieve" .
332 "&patient_id=$pid&document_id=$document_id' style='color:#00cc00' " .
333 "onclick='top.restoreSession()'>Click for ID card</a><br />";
336 // Show current and upcoming appointments.
337 if (isset($pid)) {
338 $query = "SELECT e.pc_eid, e.pc_aid, e.pc_title, e.pc_eventDate, " .
339 "e.pc_startTime, e.pc_hometext, u.fname, u.lname, u.mname " .
340 "FROM openemr_postcalendar_events AS e, users AS u WHERE " .
341 "e.pc_pid = '$pid' AND e.pc_eventDate >= CURRENT_DATE AND " .
342 "u.id = e.pc_aid " .
343 "ORDER BY e.pc_eventDate, e.pc_startTime";
344 $res = sqlStatement($query);
346 if (isset($res) && $res != null) {
347 echo "<div id='appts'><span id='apptstitle'>Upcoming Appointments</span><br>";
349 while($row = sqlFetchArray($res)) {
350 $dayname = date("l", strtotime($row['pc_eventDate']));
351 $dispampm = "am";
352 $disphour = substr($row['pc_startTime'], 0, 2) + 0;
353 $dispmin = substr($row['pc_startTime'], 3, 2);
354 if ($disphour >= 12) {
355 $dispampm = "pm";
356 if ($disphour > 12) $disphour -= 12;
358 $etitle = "(Click to edit)";
359 if ($row['pc_hometext'] != "") {
360 $etitle = "Comments: ".addslashes($row['pc_hometext'])."\r\n".$etitle;
362 echo "<a href='javascript:oldEvt(" . $row['pc_eid'] . ")' title='$etitle'>";
363 echo "<b>$dayname, " . $row['pc_eventDate'] . "</b><br>";
364 echo "$disphour:$dispmin $dispampm " . $row['pc_title'] . "<br>\n";
365 echo $row['fname'] . " " . $row['lname'] . "</a><br>&nbsp;<br>\n";
367 if (isset($res) && $res != null) { echo "</div>"; }
370 </td>
372 </tr>
373 </table>
375 <?php if ($GLOBALS['concurrent_layout'] && $_GET['set_pid']) { ?>
376 <script language='JavaScript'>
377 parent.left_nav.setPatient(<?php echo "'" . addslashes($result['fname']) . " " . addslashes($result['lname']) . "',$pid,'" . addslashes($result['pubpid']) . "',''"; ?>);
378 parent.left_nav.setRadio(window.name, 'dem');
379 <?php if (!$_GET['is_new']) { // if new pt, do not load other frame ?>
380 var othername = (window.name == 'RTop') ? 'RBot' : 'RTop';
381 parent.left_nav.forceDual();
382 parent.left_nav.setRadio(othername, 'sum');
383 parent.left_nav.loadFrame('sum1', othername, 'patient_file/summary/summary_bottom.php');
384 <?php } ?>
385 </script>
386 <?php } ?>
388 <?php if ($GLOBALS['athletic_team']) { ?>
389 <script language='JavaScript'>
390 Calendar.setup({inputField:"form_userdate1", ifFormat:"%Y-%m-%d", button:"img_userdate1"});
391 </script>
392 <?php } ?>
394 </body>
395 </html>