The Third Reminders email bug fix - contributed by arnabnaha
[openemr.git] / interface / patient_file / summary / immunizations.php
blobf89a375f70771e3601ce8d9aba4e9116bcd2adf3
1 <?php
3 //SANITIZE ALL ESCAPES
4 $sanitize_all_escapes=true;
5 //
7 //STOP FAKE REGISTER GLOBALS
8 $fake_register_globals=false;
9 //
11 include_once("../../globals.php");
12 include_once("$srcdir/sql.inc");
13 include_once("$srcdir/options.inc.php");
15 if (isset($_GET['mode'])) {
17 if ($_GET['mode'] == "add" ) {
19 $sql = "REPLACE INTO immunizations set
20 id = ?,
21 administered_date = if(?,?,NULL),
22 immunization_id = ?,
23 cvx_code = ?,
24 manufacturer = ?,
25 lot_number = ?,
26 administered_by_id = if(?,?,NULL),
27 administered_by = if(?,?,NULL),
28 education_date = if(?,?,NULL),
29 vis_date = if(?,?,NULL),
30 note = ?,
31 patient_id = ?,
32 created_by = ?,
33 updated_by = ?,
34 create_date = now() ";
35 $sqlBindArray = array(
36 trim($_GET['id']),
37 trim($_GET['administered_date']), trim($_GET['administered_date']),
38 trim($_GET['form_immunization_id']),
39 trim($_GET['cvx_code']),
40 trim($_GET['manufacturer']),
41 trim($_GET['lot_number']),
42 trim($_GET['administered_by_id']), trim($_GET['administered_by_id']),
43 trim($_GET['administered_by']), trim($_GET['administered_by']),
44 trim($_GET['education_date']), trim($_GET['education_date']),
45 trim($_GET['vis_date']), trim($_GET['vis_date']),
46 trim($_GET['note']),
47 $pid,
48 $_SESSION['authId'],
49 $_SESSION['authId']
51 sqlStatement($sql,$sqlBindArray);
52 $administered_date=$education_date=date('Y-m-d');
53 $immunization_id=$cvx_code=$manufacturer=$lot_number=$administered_by_id=$note=$id="";
54 $administered_by=$vis_date="";
56 elseif ($_GET['mode'] == "delete" ) {
57 // log the event
58 newEvent("delete", $_SESSION['authUser'], $_SESSION['authProvider'], 1, "Immunization id ".$_GET['id']." deleted from pid ".$pid);
59 // delete the immunization
60 $sql="DELETE FROM immunizations WHERE id =? LIMIT 1";
61 sqlStatement($sql, array($_GET['id']));
63 elseif ($_GET['mode'] == "edit" ) {
64 $sql = "select * from immunizations where id = ?";
65 $result = sqlQuery($sql, array($_GET['id']));
66 $administered_date = $result['administered_date'];
67 $immunization_id = $result['immunization_id'];
68 $cvx_code = $result['cvx_code'];
69 $code_text = '';
70 if ( !(empty($cvx_code)) ) {
71 $query = "SELECT codes.code_text as `code_text`, codes.code as `code` " .
72 "FROM codes " .
73 "LEFT JOIN code_types on codes.code_type = code_types.ct_id " .
74 "WHERE code_types.ct_key = 'CVX' AND codes.code = ?";
75 $result_code_text = sqlQuery($query, array($cvx_code));
76 $code_text = $result_code_text['code_text'];
78 $manufacturer = $result['manufacturer'];
79 $lot_number = $result['lot_number'];
80 $administered_by_id = ($result['administered_by_id'] ? $result['administered_by_id'] : 0);
81 $administered_by = $result['administered_by'];
82 $education_date = $result['education_date'];
83 $vis_date = $result['vis_date'];
84 $note = $result['note'];
86 //set id for page
87 $id = $_GET['id'];
92 // Decide whether using the CVX list or the custom list in list_options
93 if ($GLOBALS['use_custom_immun_list']) {
94 // user forces the use of the custom list
95 $useCVX = false;
97 else {
98 if ($_GET['mode'] == "edit") {
99 //depends on if a cvx code is enterer already
100 if (empty($cvx_code)) {
101 $useCVX = false;
103 else {
104 $useCVX = true;
107 else { // $_GET['mode'] == "add"
108 $useCVX = true;
112 // set the default sort method for the list of past immunizations
113 $sortby = $_GET['sortby'];
114 if (!$sortby) { $sortby = 'vacc'; }
116 // set the default value of 'administered_by'
117 if (!$administered_by && !$administered_by_id) {
118 $stmt = "select concat(lname,', ',fname) as full_name ".
119 " from users where ".
120 " id=?";
121 $row = sqlQuery($stmt, array($_SESSION['authId']));
122 $administered_by = $row['full_name'];
126 <html>
127 <head>
128 <?php html_header_show();?>
130 <!-- supporting javascript code -->
131 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
132 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js"></script>
133 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
136 <!-- page styles -->
137 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
139 <style>
140 .highlight {
141 color: green;
143 tr.selected {
144 background-color: white;
146 </style>
148 <!-- pop up calendar -->
149 <style type="text/css">@import url(<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.css);</style>
150 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.js"></script>
151 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
152 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_setup.js"></script>
154 <script language="JavaScript">
155 // required to validate date text boxes
156 var mypcc = '<?php echo htmlspecialchars( $GLOBALS['phone_country_code'], ENT_QUOTES); ?>';
157 </script>
159 </head>
161 <body class="body_top">
163 <?php if ($GLOBALS['concurrent_layout']) { ?>
164 <span class="title"><?php echo htmlspecialchars( xl('Immunizations'), ENT_NOQUOTES); ?></span>
165 <?php } else { ?>
166 <a href="patient_summary.php" target="Main" onclick="top.restoreSession()">
167 <span class="title"><?php echo htmlspecialchars( xl('Immunizations'), ENT_NOQUOTES); ?></span>
168 <span class=back><?php echo htmlspecialchars( $tback, ENT_NOQUOTES); ?></span></a>
169 <?php } ?>
171 <form action="immunizations.php" name="add_immunization" id="add_immunization">
172 <input type="hidden" name="mode" id="mode" value="add">
173 <input type="hidden" name="id" id="id" value="<?php echo htmlspecialchars( $id, ENT_QUOTES); ?>">
174 <input type="hidden" name="pid" id="pid" value="<?php echo htmlspecialchars( $pid, ENT_QUOTES); ?>">
175 <br>
176 <table border=0 cellpadding=1 cellspacing=1>
178 <?php if (!($useCVX)) { ?>
179 <tr>
180 <td align="right">
181 <span class=text>
182 <?php echo htmlspecialchars( xl('Immunization'), ENT_NOQUOTES); ?>
183 </span>
184 </td>
185 <td>
186 <?php
187 // Modified 7/2009 by BM to incorporate the immunization items into the list_options listings
188 generate_form_field(array('data_type'=>1,'field_id'=>'immunization_id','list_id'=>'immunizations','empty_title'=>'SKIP'), $immunization_id);
190 </td>
191 </tr>
192 <?php } else { ?>
193 <tr>
194 <td align="right" valign="top" style="padding-top:4px;">
195 <span class=text>
196 <?php echo htmlspecialchars( xl('Immunization'), ENT_NOQUOTES); ?> (<?php echo htmlspecialchars( xl('CVX Code'), ENT_NOQUOTES); ?>)
197 </span>
198 </td>
199 <td>
200 <input type='text' size='10' name='cvx_code' id='cvx_code'
201 value='<?php echo htmlspecialchars($cvx_code,ENT_QUOTES); ?>' onclick='sel_cvxcode(this)'
202 title='<?php echo htmlspecialchars( xl('Click to select or change CVX code'), ENT_QUOTES); ?>'
204 <div id='cvx_description' style='display:inline; float:right; padding:3px; margin-left:3px; width:400px'>
205 <?php echo htmlspecialchars( xl( $code_text ), ENT_QUOTES); ?>
206 </div>
207 </td>
208 </tr>
209 <?php } ?>
211 <tr>
212 <td align="right">
213 <span class=text>
214 <?php echo htmlspecialchars( xl('Date Administered'), ENT_NOQUOTES); ?>
215 </span>
216 </td>
217 <td>
219 <input type='text' size='10' name="administered_date" id="administered_date"
220 value='<?php echo $administered_date ? htmlspecialchars( $administered_date, ENT_QUOTES) : date('Y-m-d'); ?>'
221 title='<?php echo htmlspecialchars( xl('yyyy-mm-dd'), ENT_QUOTES); ?>'
222 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc);'
224 <img src='<?php echo $rootdir; ?>/pic/show_calendar.gif' align='absbottom' width='24' height='22'
225 id='img_administered_date' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
226 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>'>
228 </td>
229 </tr>
230 <tr>
231 <td align="right">
232 <span class=text>
233 <?php echo htmlspecialchars( xl('Immunization Manufacturer'), ENT_NOQUOTES); ?>
234 </span>
235 </td>
236 <td>
237 <input class='text' type='text' name="manufacturer" size="25" value="<?php echo htmlspecialchars( $manufacturer, ENT_QUOTES); ?>">
238 </td>
239 </tr>
240 <tr>
241 <td align="right">
242 <span class=text>
243 <?php echo htmlspecialchars( xl('Immunization Lot Number'), ENT_NOQUOTES); ?>
244 </span>
245 </td>
246 <td>
247 <input class='text' type='text' name="lot_number" size="25" value="<?php echo htmlspecialchars( $lot_number, ENT_QUOTES); ?>">
248 </td>
249 </tr>
250 <tr>
251 <td align="right">
252 <span class='text'>
253 <?php echo htmlspecialchars( xl('Name and Title of Immunization Administrator'), ENT_NOQUOTES); ?>
254 </span>
255 </td>
256 <td class='text'>
257 <input type="text" name="administered_by" id="administered_by" size="25" value="<?php echo htmlspecialchars( $administered_by, ENT_QUOTES); ?>">
258 <?php echo htmlspecialchars( xl('or choose'), ENT_NOQUOTES); ?>
259 <!-- NEEDS WORK -->
260 <select name="administered_by_id" id='administered_by_id'>
261 <option value=""></option>
262 <?php
263 $sql = "select id, concat(lname,', ',fname) as full_name " .
264 "from users where username != '' " .
265 "order by concat(lname,', ',fname)";
267 $result = sqlStatement($sql);
268 while($row = sqlFetchArray($result)){
269 echo '<OPTION VALUE=' . htmlspecialchars( $row{'id'}, ENT_QUOTES);
270 echo (isset($administered_by_id) && $administered_by_id != "" ? $administered_by_id : $_SESSION['authId']) == $row{'id'} ? ' selected>' : '>';
271 echo htmlspecialchars( $row{'full_name'}, ENT_NOQUOTES) . '</OPTION>';
274 </select>
275 </td>
276 </tr>
277 <tr>
278 <td align="right" class="text">
279 <?php echo htmlspecialchars( xl('Date Immunization Information Statements Given'), ENT_NOQUOTES); ?>
280 </td>
281 <td>
282 <input type='text' size='10' name="education_date" id="education_date"
283 value='<?php echo $education_date? htmlspecialchars( $education_date, ENT_QUOTES) : date('Y-m-d'); ?>'
284 title='<?php echo htmlspecialchars( xl('yyyy-mm-dd'), ENT_QUOTES); ?>'
285 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc);'
287 <img src='<?php echo $rootdir; ?>/pic/show_calendar.gif' align='absbottom' width='24' height='22'
288 id='img_education_date' border='0' alt='[?]' style='cursor:pointer;'
289 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>'
291 </td>
292 </tr>
293 <tr>
294 <td align="right" class="text">
295 <?php echo htmlspecialchars( xl('Date of VIS Statement'), ENT_NOQUOTES); ?>
296 (<a href="http://www.cdc.gov/vaccines/pubs/vis/default.htm" title="<?php echo htmlspecialchars( xl('Help'), ENT_QUOTES); ?>" target="_blank">?</a>)
297 </td>
298 <td>
299 <input type='text' size='10' name="vis_date" id="vis_date"
300 value='<?php echo $vis_date ? htmlspecialchars( $vis_date, ENT_QUOTES) : date('Y-m-d'); ?>'
301 title='<?php echo htmlspecialchars( xl('yyyy-mm-dd'), ENT_QUOTES); ?>'
302 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc);'
304 <img src='<?php echo $rootdir; ?>/pic/show_calendar.gif' align='absbottom' width='24' height='22'
305 id='img_vis_date' border='0' alt='[?]' style='cursor:pointer;'
306 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>'
308 </td>
309 </tr>
310 <tr>
311 <td align="right" class='text'>
312 <?php echo htmlspecialchars( xl('Notes'), ENT_NOQUOTES); ?>
313 </td>
314 <td>
315 <textarea class='text' name="note" id="note" rows=5 cols=25><?php echo htmlspecialchars( $note, ENT_NOQUOTES); ?></textarea>
316 </td>
317 </tr>
318 <tr>
319 <td colspan="3" align="center">
321 <input type="button" name="save" id="save" value="<?php echo htmlspecialchars( xl('Save Immunization'), ENT_QUOTES); ?>">
323 <input type="button" name="print" id="print" value="<?php echo htmlspecialchars( xl('Print Record') . xl('PDF','',' (',')'), ENT_QUOTES); ?>">
325 <input type="button" name="printHtml" id="printHtml" value="<?php echo htmlspecialchars( xl('Print Record') . xl('HTML','',' (',')'), ENT_QUOTES); ?>">
327 <input type="reset" name="clear" id="clear" value="<?php echo htmlspecialchars( xl('Clear'), ENT_QUOTES); ?>">
328 </td>
329 </tr>
330 </table>
331 </form>
333 <div id="immunization_list">
335 <table border=0 cellpadding=3 cellspacing=0>
337 <!-- some columns are sortable -->
338 <tr class='text bold'>
339 <th>
340 <a href="javascript:top.restoreSession();location.href='immunizations.php?sortby=vacc';" title='<?php echo htmlspecialchars( xl('Sort by vaccine'), ENT_QUOTES); ?>'>
341 <?php echo htmlspecialchars( xl('Vaccine'), ENT_NOQUOTES); ?></a>
342 <span class='small' style='font-family:arial'><?php if ($sortby == 'vacc') { echo 'v'; } ?></span>
343 </th>
344 <th>
345 <a href="javascript:top.restoreSession();location.href='immunizations.php?sortby=date';" title='<?php echo htmlspecialchars( xl('Sort by date'), ENT_QUOTES); ?>'>
346 <?php echo htmlspecialchars( xl('Date'), ENT_NOQUOTES); ?></a>
347 <span class='small' style='font-family:arial'><?php if ($sortby == 'date') { echo 'v'; } ?></span>
348 </th>
349 <th><?php echo htmlspecialchars( xl('Manufacturer'), ENT_NOQUOTES); ?></th>
350 <th><?php echo htmlspecialchars( xl('Lot Number'), ENT_NOQUOTES); ?></th>
351 <th><?php echo htmlspecialchars( xl('Administered By'), ENT_NOQUOTES); ?></th>
352 <th><?php echo htmlspecialchars( xl('Education Date'), ENT_NOQUOTES); ?></th>
353 <th><?php echo htmlspecialchars( xl('Note'), ENT_NOQUOTES); ?></th>
354 <th>&nbsp;</th>
355 </tr>
357 <?php
358 $sql = "select i1.id ,i1.immunization_id, i1.cvx_code, i1.administered_date, c.code_text_short, c.code".
359 ",i1.manufacturer ,i1.lot_number ".
360 ",ifnull(concat(u.lname,', ',u.fname),'Other') as administered_by ".
361 ",i1.education_date ,i1.note ".
362 " from immunizations i1 ".
363 " left join users u on i1.administered_by_id = u.id ".
364 " left join code_types ct on ct.ct_key = 'CVX' ".
365 " left join codes c on c.code_type = ct.ct_id AND i1.cvx_code = c.code ".
366 " where i1.patient_id = ? ".
367 " order by ";
368 if ($sortby == "vacc") {
369 $sql .= " c.code_text_short, i1.immunization_id, i1.administered_date DESC";
371 else { $sql .= " administered_date desc"; }
373 $result = sqlStatement($sql, array($pid) );
374 while($row = sqlFetchArray($result)) {
375 if ($row["id"] == $id) {
376 echo "<tr class='immrow text selected' id='".htmlspecialchars( $row["id"], ENT_QUOTES)."'>";
378 else {
379 echo "<tr class='immrow text' id='".htmlspecialchars( $row["id"], ENT_QUOTES)."'>";
382 // Figure out which name to use (ie. from cvx list or from the custom list)
383 if ($GLOBALS['use_custom_immun_list']) {
384 $vaccine_display = generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
386 else {
387 if (!empty($row['code_text_short'])) {
388 $vaccine_display = htmlspecialchars( xl($row['code_text_short']), ENT_NOQUOTES);
390 else {
391 $vaccine_display = generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
395 echo "<td>" . $vaccine_display . "</td>";
397 echo "<td>" . htmlspecialchars( $row["administered_date"], ENT_NOQUOTES) . "</td>";
398 echo "<td>" . htmlspecialchars( $row["manufacturer"], ENT_NOQUOTES) . "</td>";
399 echo "<td>" . htmlspecialchars( $row["lot_number"], ENT_NOQUOTES) . "</td>";
400 echo "<td>" . htmlspecialchars( $row["administered_by"], ENT_NOQUOTES) . "</td>";
401 echo "<td>" . htmlspecialchars( $row["education_date"], ENT_NOQUOTES) . "</td>";
402 echo "<td>" . htmlspecialchars( $row["note"], ENT_NOQUOTES) . "</td>";
403 echo "<td><input type='button' class='delete' id='".htmlspecialchars( $row["id"], ENT_QUOTES)."' value='" . htmlspecialchars( xl('Delete'), ENT_QUOTES) . "'></td>";
404 echo "</tr>";
409 </table>
410 </div> <!-- end immunizations -->
412 </body>
414 <script language="javascript">
415 /* required for popup calendar */
416 Calendar.setup({inputField:"administered_date", ifFormat:"%Y-%m-%d", button:"img_administered_date"});
417 Calendar.setup({inputField:"education_date", ifFormat:"%Y-%m-%d", button:"img_education_date"});
418 Calendar.setup({inputField:"vis_date", ifFormat:"%Y-%m-%d", button:"img_vis_date"});
420 // jQuery stuff to make the page a little easier to use
422 $(document).ready(function(){
423 <?php if (!($useCVX)) { ?>
424 $("#save").click(function() { SaveForm(); });
425 <?php } else { ?>
426 $("#save").click(function() {
427 if (validate_cvx()) {
428 SaveForm();
430 else {
431 return;
434 <?php } ?>
435 $("#print").click(function() { PrintForm("pdf"); });
436 $("#printHtml").click(function() { PrintForm("html"); });
437 $(".immrow").click(function() { EditImm(this); });
438 $(".delete").click(function(event) { DeleteImm(this); event.stopPropagation(); });
440 $(".immrow").mouseover(function() { $(this).toggleClass("highlight"); });
441 $(".immrow").mouseout(function() { $(this).toggleClass("highlight"); });
443 $("#administered_by_id").change(function() { $("#administered_by").val($("#administered_by_id :selected").text()); });
445 $("#form_immunization_id").change( function() {
446 if ( $(this).val() != "" ) {
447 $("#cvx_code").val( "" );
448 $("#cvx_description").text( "" );
449 $("#cvx_code").change();
454 var PrintForm = function(typ) {
455 top.restoreSession();
456 newURL='shot_record.php?output='+typ+'&sortby=<?php echo $sortby; ?>';
457 if (typ=="pdf") {
458 location.href=newURL;
460 else { // typ=html
461 window.open(newURL, '_blank', "menubar=1,toolbar=1,scrollbars=1,resizable=1,width=600,height=450");
465 var SaveForm = function() {
466 top.restoreSession();
467 $("#add_immunization").submit();
470 var EditImm = function(imm) {
471 top.restoreSession();
472 location.href='immunizations.php?mode=edit&id='+imm.id;
475 var DeleteImm = function(imm) {
476 if (confirm("<?php echo htmlspecialchars( xl('This action cannot be undone.'), ENT_QUOTES); ?>" + "\n" +"<?php echo htmlspecialchars( xl('Do you wish to PERMANENTLY delete this immunization record?'), ENT_QUOTES); ?>")) {
477 top.restoreSession();
478 location.href='immunizations.php?mode=delete&id='+imm.id;
482 //This is for callback by the find-code popup.
483 //Appends to or erases the current list of diagnoses.
484 function set_related(codetype, code, selector, codedesc) {
485 var f = document.forms[0][current_sel_name];
486 var s = f.value;
488 if (code) {
489 s = code;
491 else {
492 s = '';
495 f.value = s;
496 $("#cvx_description").text( codedesc );
497 $("#form_immunization_id").attr( "value", "" );
498 $("#form_immunization_id").change();
502 // This invokes the find-code popup.
503 function sel_cvxcode(e) {
504 current_sel_name = e.name;
505 dlgopen('../encounter/find_code_popup.php?codetype=CVX', '_blank', 500, 400);
508 // This ensures the cvx centric entry is filled.
509 function validate_cvx() {
510 if (document.add_immunization.cvx_code.value>0) {
511 return true;
513 else {
514 document.add_immunization.cvx_code.style.backgroundColor="red";
515 document.add_immunization.cvx_code.focus();
516 return false;
520 </script>
522 </html>