Immunization bug fix: made cvx_code entry a required field
[openemr.git] / interface / patient_file / summary / immunizations.php
blob1652c7c2d4f449c706fe0e83aa9799bfadd3865e
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 $results = sqlQ($sql, array($_GET['id']));
66 while ($row = sqlFetchArray($results)) {
67 $administered_date = $row['administered_date'];
68 $immunization_id = $row['immunization_id'];
69 $cvx_code = $row['cvx_code'];
70 $code_text = '';
71 if ( !(empty($cvx_code)) ) {
72 $query = "SELECT codes.code_text as `code_text`, codes.code as `code` " .
73 "FROM codes " .
74 "LEFT JOIN code_types on codes.code_type = code_types.ct_id " .
75 "WHERE code_types.ct_key = 'CVX' AND codes.code = ?";
76 $row = sqlQuery($query, array($cvx_code));
77 $code_text = $row['code_text'];
79 $manufacturer = $row['manufacturer'];
80 $lot_number = $row['lot_number'];
81 $administered_by_id = ($row['administered_by_id'] ? $row['administered_by_id'] : 0);
82 $administered_by = $row['administered_by'];
83 $education_date = $row['education_date'];
84 $vis_date = $row['vis_date'];
85 $note = $row['note'];
88 //set id for page
89 $id = $_GET['id'];
94 // Decide whether using the CVX list or the custom list in list_options
95 if ($GLOBALS['use_custom_immun_list']) {
96 // user forces the use of the custom list
97 $useCVX = false;
99 else {
100 if ($_GET['mode'] == "edit") {
101 //depends on if a cvx code is enterer already
102 if (empty($cvx_code)) {
103 $useCVX = false;
105 else {
106 $useCVX = true;
109 else { // $_GET['mode'] == "add"
110 $useCVX = true;
114 // set the default sort method for the list of past immunizations
115 $sortby = $_GET['sortby'];
116 if (!$sortby) { $sortby = 'vacc'; }
118 // set the default value of 'administered_by'
119 if (!$administered_by && !$administered_by_id) {
120 $stmt = "select concat(lname,', ',fname) as full_name ".
121 " from users where ".
122 " id=?";
123 $row = sqlQuery($stmt, array($_SESSION['authId']));
124 $administered_by = $row['full_name'];
128 <html>
129 <head>
130 <?php html_header_show();?>
132 <!-- supporting javascript code -->
133 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
134 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js"></script>
135 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
138 <!-- page styles -->
139 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
141 <style>
142 .highlight {
143 color: green;
145 tr.selected {
146 background-color: white;
148 </style>
150 <!-- pop up calendar -->
151 <style type="text/css">@import url(<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.css);</style>
152 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.js"></script>
153 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
154 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_setup.js"></script>
156 <script language="JavaScript">
157 // required to validate date text boxes
158 var mypcc = '<?php echo htmlspecialchars( $GLOBALS['phone_country_code'], ENT_QUOTES); ?>';
159 </script>
161 </head>
163 <body class="body_top">
165 <?php if ($GLOBALS['concurrent_layout']) { ?>
166 <span class="title"><?php echo htmlspecialchars( xl('Immunizations'), ENT_NOQUOTES); ?></span>
167 <?php } else { ?>
168 <a href="patient_summary.php" target="Main" onclick="top.restoreSession()">
169 <span class="title"><?php echo htmlspecialchars( xl('Immunizations'), ENT_NOQUOTES); ?></span>
170 <span class=back><?php echo htmlspecialchars( $tback, ENT_NOQUOTES); ?></span></a>
171 <?php } ?>
173 <form action="immunizations.php" name="add_immunization" id="add_immunization">
174 <input type="hidden" name="mode" id="mode" value="add">
175 <input type="hidden" name="id" id="id" value="<?php echo htmlspecialchars( $id, ENT_QUOTES); ?>">
176 <input type="hidden" name="pid" id="pid" value="<?php echo htmlspecialchars( $pid, ENT_QUOTES); ?>">
177 <br>
178 <table border=0 cellpadding=1 cellspacing=1>
180 <?php if (!($useCVX)) { ?>
181 <tr>
182 <td align="right">
183 <span class=text>
184 <?php echo htmlspecialchars( xl('Immunization'), ENT_NOQUOTES); ?>
185 </span>
186 </td>
187 <td>
188 <?php
189 // Modified 7/2009 by BM to incorporate the immunization items into the list_options listings
190 generate_form_field(array('data_type'=>1,'field_id'=>'immunization_id','list_id'=>'immunizations','empty_title'=>'SKIP'), $immunization_id);
192 </td>
193 </tr>
194 <?php } else { ?>
195 <tr>
196 <td align="right" valign="top" style="padding-top:4px;">
197 <span class=text>
198 <?php echo htmlspecialchars( xl('Immunization'), ENT_NOQUOTES); ?> (<?php echo htmlspecialchars( xl('CVX Code'), ENT_NOQUOTES); ?>)
199 </span>
200 </td>
201 <td>
202 <input type='text' size='10' name='cvx_code' id='cvx_code'
203 value='<?php echo htmlspecialchars($cvx_code,ENT_QUOTES); ?>' onclick='sel_cvxcode(this)'
204 title='<?php echo htmlspecialchars( xl('Click to select or change CVX code'), ENT_QUOTES); ?>'
206 <div id='cvx_description' style='display:inline; float:right; padding:3px; margin-left:3px; width:400px'>
207 <?php echo htmlspecialchars( xl( $code_text ), ENT_QUOTES); ?>
208 </div>
209 </td>
210 </tr>
211 <?php } ?>
213 <tr>
214 <td align="right">
215 <span class=text>
216 <?php echo htmlspecialchars( xl('Date Administered'), ENT_NOQUOTES); ?>
217 </span>
218 </td>
219 <td>
221 <input type='text' size='10' name="administered_date" id="administered_date"
222 value='<?php echo $administered_date ? htmlspecialchars( $administered_date, ENT_QUOTES) : date('Y-m-d'); ?>'
223 title='<?php echo htmlspecialchars( xl('yyyy-mm-dd'), ENT_QUOTES); ?>'
224 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc);'
226 <img src='<?php echo $rootdir; ?>/pic/show_calendar.gif' align='absbottom' width='24' height='22'
227 id='img_administered_date' border='0' alt='[?]' style='cursor:pointer;cursor:hand'
228 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>'>
230 </td>
231 </tr>
232 <tr>
233 <td align="right">
234 <span class=text>
235 <?php echo htmlspecialchars( xl('Immunization Manufacturer'), ENT_NOQUOTES); ?>
236 </span>
237 </td>
238 <td>
239 <input class='text' type='text' name="manufacturer" size="25" value="<?php echo htmlspecialchars( $manufacturer, ENT_QUOTES); ?>">
240 </td>
241 </tr>
242 <tr>
243 <td align="right">
244 <span class=text>
245 <?php echo htmlspecialchars( xl('Immunization Lot Number'), ENT_NOQUOTES); ?>
246 </span>
247 </td>
248 <td>
249 <input class='text' type='text' name="lot_number" size="25" value="<?php echo htmlspecialchars( $lot_number, ENT_QUOTES); ?>">
250 </td>
251 </tr>
252 <tr>
253 <td align="right">
254 <span class='text'>
255 <?php echo htmlspecialchars( xl('Name and Title of Immunization Administrator'), ENT_NOQUOTES); ?>
256 </span>
257 </td>
258 <td class='text'>
259 <input type="text" name="administered_by" id="administered_by" size="25" value="<?php echo htmlspecialchars( $administered_by, ENT_QUOTES); ?>">
260 <?php echo htmlspecialchars( xl('or choose'), ENT_NOQUOTES); ?>
261 <!-- NEEDS WORK -->
262 <select name="administered_by_id" id='administered_by_id'>
263 <option value=""></option>
264 <?php
265 $sql = "select id, concat(lname,', ',fname) as full_name " .
266 "from users where username != '' " .
267 "order by concat(lname,', ',fname)";
269 $result = sqlStatement($sql);
270 while($row = sqlFetchArray($result)){
271 echo '<OPTION VALUE=' . htmlspecialchars( $row{'id'}, ENT_QUOTES);
272 echo (isset($administered_by_id) && $administered_by_id != "" ? $administered_by_id : $_SESSION['authId']) == $row{'id'} ? ' selected>' : '>';
273 echo htmlspecialchars( $row{'full_name'}, ENT_NOQUOTES) . '</OPTION>';
276 </select>
277 </td>
278 </tr>
279 <tr>
280 <td align="right" class="text">
281 <?php echo htmlspecialchars( xl('Date Immunization Information Statements Given'), ENT_NOQUOTES); ?>
282 </td>
283 <td>
284 <input type='text' size='10' name="education_date" id="education_date"
285 value='<?php echo $education_date? htmlspecialchars( $education_date, ENT_QUOTES) : date('Y-m-d'); ?>'
286 title='<?php echo htmlspecialchars( xl('yyyy-mm-dd'), ENT_QUOTES); ?>'
287 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc);'
289 <img src='<?php echo $rootdir; ?>/pic/show_calendar.gif' align='absbottom' width='24' height='22'
290 id='img_education_date' border='0' alt='[?]' style='cursor:pointer;'
291 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>'
293 </td>
294 </tr>
295 <tr>
296 <td align="right" class="text">
297 <?php echo htmlspecialchars( xl('Date of VIS Statement'), ENT_NOQUOTES); ?>
298 (<a href="http://www.cdc.gov/vaccines/pubs/vis/default.htm" title="<?php echo htmlspecialchars( xl('Help'), ENT_QUOTES); ?>" target="_blank">?</a>)
299 </td>
300 <td>
301 <input type='text' size='10' name="vis_date" id="vis_date"
302 value='<?php echo $vis_date ? htmlspecialchars( $vis_date, ENT_QUOTES) : date('Y-m-d'); ?>'
303 title='<?php echo htmlspecialchars( xl('yyyy-mm-dd'), ENT_QUOTES); ?>'
304 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc);'
306 <img src='<?php echo $rootdir; ?>/pic/show_calendar.gif' align='absbottom' width='24' height='22'
307 id='img_vis_date' border='0' alt='[?]' style='cursor:pointer;'
308 title='<?php echo htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES); ?>'
310 </td>
311 </tr>
312 <tr>
313 <td align="right" class='text'>
314 <?php echo htmlspecialchars( xl('Notes'), ENT_NOQUOTES); ?>
315 </td>
316 <td>
317 <textarea class='text' name="note" id="note" rows=5 cols=25><?php echo htmlspecialchars( $note, ENT_NOQUOTES); ?></textarea>
318 </td>
319 </tr>
320 <tr>
321 <td colspan="3" align="center">
323 <input type="button" name="save" id="save" value="<?php echo htmlspecialchars( xl('Save Immunization'), ENT_QUOTES); ?>">
325 <input type="button" name="print" id="print" value="<?php echo htmlspecialchars( xl('Print Record') . xl('PDF','',' (',')'), ENT_QUOTES); ?>">
327 <input type="button" name="printHtml" id="printHtml" value="<?php echo htmlspecialchars( xl('Print Record') . xl('HTML','',' (',')'), ENT_QUOTES); ?>">
329 <input type="reset" name="clear" id="clear" value="<?php echo htmlspecialchars( xl('Clear'), ENT_QUOTES); ?>">
330 </td>
331 </tr>
332 </table>
333 </form>
335 <div id="immunization_list">
337 <table border=0 cellpadding=3 cellspacing=0>
339 <!-- some columns are sortable -->
340 <tr class='text bold'>
341 <th>
342 <a href="javascript:top.restoreSession();location.href='immunizations.php?sortby=vacc';" title='<?php echo htmlspecialchars( xl('Sort by vaccine'), ENT_QUOTES); ?>'>
343 <?php echo htmlspecialchars( xl('Vaccine'), ENT_NOQUOTES); ?></a>
344 <span class='small' style='font-family:arial'><?php if ($sortby == 'vacc') { echo 'v'; } ?></span>
345 </th>
346 <th>
347 <a href="javascript:top.restoreSession();location.href='immunizations.php?sortby=date';" title='<?php echo htmlspecialchars( xl('Sort by date'), ENT_QUOTES); ?>'>
348 <?php echo htmlspecialchars( xl('Date'), ENT_NOQUOTES); ?></a>
349 <span class='small' style='font-family:arial'><?php if ($sortby == 'date') { echo 'v'; } ?></span>
350 </th>
351 <th><?php echo htmlspecialchars( xl('Manufacturer'), ENT_NOQUOTES); ?></th>
352 <th><?php echo htmlspecialchars( xl('Lot Number'), ENT_NOQUOTES); ?></th>
353 <th><?php echo htmlspecialchars( xl('Administered By'), ENT_NOQUOTES); ?></th>
354 <th><?php echo htmlspecialchars( xl('Education Date'), ENT_NOQUOTES); ?></th>
355 <th><?php echo htmlspecialchars( xl('Note'), ENT_NOQUOTES); ?></th>
356 <th>&nbsp;</th>
357 </tr>
359 <?php
360 $sql = "select i1.id ,i1.immunization_id, i1.cvx_code, i1.administered_date, c.code_text_short, c.code".
361 ",i1.manufacturer ,i1.lot_number ".
362 ",ifnull(concat(u.lname,', ',u.fname),'Other') as administered_by ".
363 ",i1.education_date ,i1.note ".
364 " from immunizations i1 ".
365 " left join users u on i1.administered_by_id = u.id ".
366 " left join codes c on CAST(IFNULL(i1.cvx_code,0) AS CHAR) = c.code ".
367 " left join code_types ct on c.code_type = ct.ct_id ".
368 " where patient_id = ? ".
369 " AND (( i1.cvx_code = '0' OR i1.cvx_code IS NULL ) OR ".
370 " ( (i1.cvx_code != '0' AND i1.cvx_code IS NOT NULL ) AND ct.ct_key = 'CVX') ) ".
371 " order by ";
372 if ($sortby == "vacc") {
373 $sql .= " c.code_text_short, i1.immunization_id, i1.administered_date DESC";
375 else { $sql .= " administered_date desc"; }
377 $result = sqlStatement($sql, array($pid) );
378 while($row = sqlFetchArray($result)) {
379 if ($row["id"] == $id) {
380 echo "<tr class='immrow text selected' id='".htmlspecialchars( $row["id"], ENT_QUOTES)."'>";
382 else {
383 echo "<tr class='immrow text' id='".htmlspecialchars( $row["id"], ENT_QUOTES)."'>";
386 // Figure out which name to use (ie. from cvx list or from the custom list)
387 if ($GLOBALS['use_custom_immun_list']) {
388 $vaccine_display = generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
390 else {
391 if (!empty($row['code_text_short'])) {
392 $vaccine_display = htmlspecialchars( xl($row['code_text_short']), ENT_NOQUOTES);
394 else {
395 $vaccine_display = generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
399 echo "<td>" . $vaccine_display . "</td>";
401 echo "<td>" . htmlspecialchars( $row["administered_date"], ENT_NOQUOTES) . "</td>";
402 echo "<td>" . htmlspecialchars( $row["manufacturer"], ENT_NOQUOTES) . "</td>";
403 echo "<td>" . htmlspecialchars( $row["lot_number"], ENT_NOQUOTES) . "</td>";
404 echo "<td>" . htmlspecialchars( $row["administered_by"], ENT_NOQUOTES) . "</td>";
405 echo "<td>" . htmlspecialchars( $row["education_date"], ENT_NOQUOTES) . "</td>";
406 echo "<td>" . htmlspecialchars( $row["note"], ENT_NOQUOTES) . "</td>";
407 echo "<td><input type='button' class='delete' id='".htmlspecialchars( $row["id"], ENT_QUOTES)."' value='" . htmlspecialchars( xl('Delete'), ENT_QUOTES) . "'></td>";
408 echo "</tr>";
413 </table>
414 </div> <!-- end immunizations -->
416 </body>
418 <script language="javascript">
419 /* required for popup calendar */
420 Calendar.setup({inputField:"administered_date", ifFormat:"%Y-%m-%d", button:"img_administered_date"});
421 Calendar.setup({inputField:"education_date", ifFormat:"%Y-%m-%d", button:"img_education_date"});
422 Calendar.setup({inputField:"vis_date", ifFormat:"%Y-%m-%d", button:"img_vis_date"});
424 // jQuery stuff to make the page a little easier to use
426 $(document).ready(function(){
427 <?php if (!($useCVX)) { ?>
428 $("#save").click(function() { SaveForm(); });
429 <?php } else { ?>
430 $("#save").click(function() {
431 if (validate_cvx()) {
432 SaveForm();
434 else {
435 return;
438 <?php } ?>
439 $("#print").click(function() { PrintForm("pdf"); });
440 $("#printHtml").click(function() { PrintForm("html"); });
441 $(".immrow").click(function() { EditImm(this); });
442 $(".delete").click(function(event) { DeleteImm(this); event.stopPropagation(); });
444 $(".immrow").mouseover(function() { $(this).toggleClass("highlight"); });
445 $(".immrow").mouseout(function() { $(this).toggleClass("highlight"); });
447 $("#administered_by_id").change(function() { $("#administered_by").val($("#administered_by_id :selected").text()); });
449 $("#form_immunization_id").change( function() {
450 if ( $(this).val() != "" ) {
451 $("#cvx_code").val( "" );
452 $("#cvx_description").text( "" );
453 $("#cvx_code").change();
458 var PrintForm = function(typ) {
459 top.restoreSession();
460 newURL='shot_record.php?output='+typ+'&sortby=<?php echo $sortby; ?>';
461 if (typ=="pdf") {
462 location.href=newURL;
464 else { // typ=html
465 window.open(newURL, '_blank', "menubar=1,toolbar=1,scrollbars=1,resizable=1,width=600,height=450");
469 var SaveForm = function() {
470 top.restoreSession();
471 $("#add_immunization").submit();
474 var EditImm = function(imm) {
475 top.restoreSession();
476 location.href='immunizations.php?mode=edit&id='+imm.id;
479 var DeleteImm = function(imm) {
480 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); ?>")) {
481 top.restoreSession();
482 location.href='immunizations.php?mode=delete&id='+imm.id;
486 //This is for callback by the find-code popup.
487 //Appends to or erases the current list of diagnoses.
488 function set_related(codetype, code, selector, codedesc) {
489 var f = document.forms[0][current_sel_name];
490 var s = f.value;
492 if (code) {
493 s = code;
495 else {
496 s = '';
499 f.value = s;
500 $("#cvx_description").text( codedesc );
501 $("#form_immunization_id").attr( "value", "" );
502 $("#form_immunization_id").change();
506 // This invokes the find-code popup.
507 function sel_cvxcode(e) {
508 current_sel_name = e.name;
509 dlgopen('../encounter/find_code_popup.php?codetype=CVX', '_blank', 500, 400);
512 // This ensures the cvx centric entry is filled.
513 function validate_cvx() {
514 if (document.add_immunization.cvx_code.value>0) {
515 return true;
517 else {
518 document.add_immunization.cvx_code.style.backgroundColor="red";
519 document.add_immunization.cvx_code.focus();
520 return false;
524 </script>
526 </html>