3 * CAMOS note generator.
6 * @link http://www.open-emr.org
7 * @author Mark Leeds <drleeds@gmail.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2006-2009 Mark Leeds <drleeds@gmail.com>
10 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 require_once($depth.'interface/globals.php');
17 require_once("content_parser.php");
20 if (!($_POST['submit_pdf'] ||
$_POST['submit_html']) && ($_GET['pid'] && $_GET['encounter'])) {
25 <?php
xl('Print Notes', 'e'); ?
>
29 <?php
xl('Choose print format for this encounter report.', 'e'); ?
><br
><br
>
30 <form method
=post name
=choose_patients
>
31 <input type
='submit' name
='submit_pdf' value
='<?php xl('Print (PDF
)', 'e
'); ?>'>
32 <input type
='submit' name
='submit_html' value
='<?php xl('Print (HTML
)', 'e
'); ?>'>
40 if (!$_POST['submit_pdf'] && !$_POST['submit_html'] && !($_GET['pid'] && $_GET['encounter'])) {
46 <?php
xl('Print Notes', 'e'); ?
>
49 <?php
html_header_show();?
>
50 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
51 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
53 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script
>
54 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script
>
55 <script type
="text/javascript" src
="<?php echo $depth ?>library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
56 <script type
="text/javascript" src
="<?php echo $depth ?>library/textformat.js?v=<?php echo $v_js_includes; ?>"></script
>
58 <script type
="text/javascript">
59 $
(document
).ready(function(){
60 $
('.datepicker').datetimepicker({
61 <?php
$datetimepicker_timepicker = false; ?
>
62 <?php
$datetimepicker_showseconds = false; ?
>
63 <?php
$datetimepicker_formatInput = false; ?
>
64 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
65 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
73 <script language
='JavaScript'> var mypcc
= '1'; </script
>
75 <form method
=post name
=choose_patients
>
79 <span
class='text'><?php
xl('Start (yyyy-mm-dd): ', 'e') ?
></span
>
81 <input type
='text' size
='10' name
='start' id
='start' value
='<?php echo $_POST['end
'] ? $_POST['end
'] : date('Y
-m
-d
') ?>'
83 title
='<?php xl('yyyy
-mm
-dd last date of this event
', 'e
'); ?>' />
86 <span
class='text'><?php
xl('End (yyyy-mm-dd): ', 'e') ?
></span
>
88 <input type
='text' size
='10' name
='end' id
='end' value
='<?php echo $_POST['end
'] ? $_POST['end
'] : date('Y
-m
-d
') ?>'
90 title
='<?php xl('yyyy
-mm
-dd last date of this event
', 'e
'); ?>' />
92 <tr
><td
></td
><td
></td
></tr
>
93 <tr
><td
><?php
xl('Last Name', 'e'); ?
>: </td
><td
>
94 <input type
='text' name
='lname'/>
96 <tr
><td
><?php
xl('First Name', 'e'); ?
>: </td
><td
>
97 <input type
='text' name
='fname'/>
100 <input type
='submit' name
='submit_pdf' value
='<?php xl('Print (PDF
)', 'e
'); ?>'>
101 <input type
='submit' name
='submit_html' value
='<?php xl('Print (HTML
)', 'e
'); ?>'>
111 if ($_POST['submit_pdf'] ||
$_POST['submit_html'] ||
($_GET['pid'] && $_GET['encounter'])) {
112 // note we are cleaning input, trimming, and preparing the variables for database insert
113 // before sending through this function
114 $output = getFormData(formData("start", "P", true), formData("end", "P", true), formData("lname", "P", true), formData("fname", "P", true));
116 if ($_POST['submit_html']) { //print as html
122 font
-family
: sans
-serif
;
141 page
-break-after
: always
;
150 <title
><?php
xl('Patient Notes', 'e'); ?
></title
>
153 <div
class='paddingdiv'>
155 foreach ($output as $datekey => $dailynote) {
156 foreach ($dailynote as $note_id => $notecontents) {
157 preg_match('/(\d+)_(\d+)/', $note_id, $matches); //the unique note id contains the pid and encounter
162 print "<DIV class='page'>";
164 print xl("Date").": ".$notecontents['date'] . "<br/>";
165 print xl("Name").": ".$notecontents['name'] . "<br/>";
166 print xl("DOB").": ".$notecontents['dob'] . "<br/>";
167 print xl("Claim")."# ".$notecontents['pubpid'] . "<br/>";
170 print xl("Chief Complaint").": ".$notecontents['reason'] . "<br/>";
171 if ($notecontents['vitals']) {
173 print $notecontents['vitals'] . "<br/>";
176 if (count($notecontents['exam']) > 0) {
178 print "<span class='heading'>" . xl("Progress Notes") . "</span><br/>";
180 foreach ($notecontents['exam'] as $examnote) {
181 print nl2br(replace($pid, $enc, $examnote)) . "<br/>";
185 if (count($notecontents['prescriptions']) > 0) {
187 print "<span class='heading'>" . xl("Prescriptions") . "</span><br/>";
189 foreach ($notecontents['prescriptions'] as $rx) {
190 print nl2br(replace($pid, $enc, $rx)) . "<br/>";
194 if (count($notecontents['other']) > 0) {
196 print "<span class='heading'>" . xl("Other") . "</span><br/>";
198 foreach ($notecontents['other'] as $other => $othercat) {
199 print nl2br($other) . "<br/>";
200 foreach ($othercat as $items) {
201 print nl2br(replace($pid, $enc, $items)) . "<br/>";
206 if (count($notecontents['billing']) > 0) {
208 foreach ($notecontents['billing'] as $code) {
212 if (count($tmp) > 0) {
214 print "<span class='heading'>" . xl("Coding") . "</span><br/>";
216 foreach ($tmp as $code => $val) {
217 print nl2br($code) . "<br/>";
222 if (count($notecontents['calories']) > 0) {
225 print "<span class='heading'>" . xl("Calories") . "</span><br/>";
227 foreach ($notecontents['calories'] as $calories => $value) {
228 print $value['content'].' - '.$value['item'].' - '.$value['date'] . "<br/>";
229 $sum +
= $value['content'];
232 print "--------" . "<br/>";
233 print $sum . "<br/>";
238 print "<span class='heading'>" . xl("Digitally Signed") . "</span><br/>";
240 $query = sqlStatement("select t2.id, t2.fname, t2.lname, t2.title from forms as t1 join users as t2 on " .
241 "(t1.user like t2.username) where t1.pid=$pid and t1.encounter=$encounter");
242 if ($results = sqlFetchArray($query)) {
243 $name = $results['fname']." ".$results['lname'].", ".$results['title'];
244 $user_id = $results['id'];
247 $path = $GLOBALS['fileroot']."/interface/forms/CAMOS";
248 if (file_exists($path."/sig".$user_id.".jpg")) {
249 //show the image here
252 print "<span class='heading'>" . $name . "</span><br/>";
253 print "</DIV>"; //end of last page
257 <script language
='JavaScript'>
258 var win
= top
.printLogPrint ? top
: opener
.top
;
259 win
.printLogPrint(window
);
266 } else { // print as pdf
268 $pdf->selectFont('Helvetica');
269 $pdf->ezSetCmMargins(3, 1, 1, 1);
271 foreach ($output as $datekey => $dailynote) {
272 foreach ($dailynote as $note_id => $notecontents) {
273 preg_match('/(\d+)_(\d+)/', $note_id, $matches); //the unique note id contains the pid and encounter
276 if (!$first) { //generate a new page each time except first iteration when nothing has been printed yet
282 $pdf->ezText(xl("Date").": ".$notecontents['date'], 8);
283 $pdf->ezText(xl("Name").": ".$notecontents['name'], 8);
284 $pdf->ezText(xl("DOB").": ".$notecontents['dob'], 8);
285 $pdf->ezText(xl("Claim")."# ".$notecontents['pubpid'], 8);
288 $pdf->ezText(xl("Chief Complaint").": ".$notecontents['reason'], 8);
289 if ($notecontents['vitals']) {
291 $pdf->ezText($notecontents['vitals'], 8);
294 if (count($notecontents['exam']) > 0) {
296 $pdf->ezText(xl("Progress Notes"), 12);
298 foreach ($notecontents['exam'] as $examnote) {
299 $pdf->ezText(replace($pid, $enc, $examnote));
303 if (count($notecontents['prescriptions']) > 0) {
305 $pdf->ezText(xl("Prescriptions"), 12);
307 foreach ($notecontents['prescriptions'] as $rx) {
308 $pdf->ezText(replace($pid, $enc, $rx));
312 if (count($notecontents['other']) > 0) {
314 $pdf->ezText(xl("Other"), 12);
316 foreach ($notecontents['other'] as $other => $othercat) {
317 $pdf->ezText($other, 8);
318 foreach ($othercat as $items) {
319 $pdf->ezText(replace($pid, $enc, $items), 8);
324 if (count($notecontents['billing']) > 0) {
326 foreach ($notecontents['billing'] as $code) {
330 if (count($tmp) > 0) {
332 $pdf->ezText(xl("Coding"), 12);
334 foreach ($tmp as $code => $val) {
335 $pdf->ezText($code, 8);
340 if (count($notecontents['calories']) > 0) {
343 $pdf->ezText(xl("Calories"), 12);
345 foreach ($notecontents['calories'] as $calories => $value) {
346 $pdf->ezText($value['content'].' - '.$value['item'].' - '.$value['date'], 8);
347 $sum +
= $value['content'];
350 $pdf->ezText("--------", 8);
351 $pdf->ezText($sum, 8);
354 $pdf->ezText("", 12);
355 $pdf->ezText("", 12);
356 $pdf->ezText(xl("Digitally Signed"), 12);
358 $query = sqlStatement("select t2.id, t2.fname, t2.lname, t2.title from forms as t1 join users as t2 on " .
359 "(t1.user like t2.username) where t1.pid=$pid and t1.encounter=$encounter");
360 if ($results = sqlFetchArray($query)) {
361 $name = $results['fname']." ".$results['lname'].", ".$results['title'];
362 $user_id = $results['id'];
365 $path = $GLOBALS['fileroot']."/interface/forms/CAMOS";
366 if (file_exists($path."/sig".$user_id.".jpg")) {
367 $pdf->ezImage($path."/sig".$user_id.".jpg", '', '72', '', 'left', '');
370 $pdf->ezText($name, 12);
378 function getFormData($start_date, $end_date, $lname, $fname)
380 //dates in sql format
382 // All 4 parameters have previously been trimmed, globally validated,
383 // and prepared for database insert
386 $date_clause = "date(t2.date) >= '".$start_date."' and date(t2.date) <= '".$end_date."' ";
387 if ($lname ||
$fname) {
388 $name_clause = "and t3.lname like '%".$lname."%' and t3.fname like '%".$fname."%' ";
392 if ($_GET['pid'] && $_GET['encounter']) {
394 $name_clause = "t2.pid=".$_GET['pid']." and t2.encounter=".$_GET['encounter']." ";
397 $query1 = sqlStatement(
398 "select t1.form_id, t1.form_name, t1.pid, date_format(t2.date,'%m-%d-%Y') as date, " .
399 "date_format(t2.date,'%Y%m%d') as datekey, " .
400 "t3.lname, t3.fname, t3.pubpid, date_format(t3.DOB,'%m-%d-%Y') as dob, " .
401 "t2.encounter as enc, " .
403 "forms as t1 join " .
404 "form_encounter as t2 on " .
405 "(t1.pid = t2.pid and t1.encounter = t2.encounter) " .
406 "join patient_data as t3 on " .
407 "(t1.pid = t3.pid) where " .
412 while ($results1 = sqlFetchArray($query1)) {
413 if (!$dates[$results1['datekey']]) {
414 $dates[$results1['datekey']] = array();
417 if (!$dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]) {
418 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']] = array();
419 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['name'] = $results1['fname'].' '.$results1['lname'];
420 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['date'] = $results1['date'];
421 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['pubpid'] = $results1['pubpid'];
422 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['dob'] = $results1['dob'];
423 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['vitals'] = '';
424 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['reason'] = $results1['reason'];
425 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['exam'] = array();
426 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['prescriptions'] = array();
427 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['other'] = array();
428 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['billing'] = array();
429 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['calories'] = array();
432 // get icd9 codes for this encounter
433 $query2 = sqlStatement("select * from billing where encounter = ".
434 $results1['enc']." and pid = ".$results1['pid']." and code_type like 'ICD9' and activity=1");
435 while ($results2 = sqlFetchArray($query2)) {
437 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['billing'],
438 $results2['code'].' '.$results2['code_text']
442 if (strtolower($results1['form_name']) == 'vitals') { // deal with Vitals
443 $query2 = sqlStatement("select * from form_vitals where id = " .
444 $results1['form_id']);
445 if ($results2 = sqlFetchArray($query2)) {
446 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['vitals'] = formatVitals($results2);
450 if (substr(strtolower($results1['form_name']), 0, 5) == 'camos') { // deal with camos
451 $query2 = sqlStatement("select category,subcategory,item,content,date_format(date,'%h:%i %p') as date from ".mitigateSqlTableUpperCase("form_CAMOS")." where id = " .
452 $results1['form_id']);
453 if ($results2 = sqlFetchArray($query2)) {
454 if ($results2['category'] == 'exam') {
455 array_push($dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['exam'], $results2['content']);
456 } elseif ($results2['category'] == 'prescriptions') {
457 array_push($dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['prescriptions'], preg_replace("/\n+/", ' ', $results2['content']));
458 } elseif ($results2['category'] == 'communications') {
460 } elseif ($results2['category'] == 'calorie intake') {
461 $values = array('subcategory' => $results2['subcategory'],
462 'item' => $results2['item'],
463 'content' => $results2['content'],
464 'date' => $results2['date']);
465 array_push($dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['calories'], $values);
467 if (!$dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['other'][$results2['category']]) {
468 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['other'][$results2['category']] = array();
472 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['other'][$results2['category']],
473 preg_replace(array("/\n+/","/patientname/i"), array(' ',$results1['fname'].' '.$results1['lname']), $results2['content'])
482 function formatVitals($raw)
484 //pass raw vitals array, format and return as string
492 $oxygen_saturation = '';
493 if ($raw['height'] && $raw['height'] > 0) {
494 $height = xl("HT").": ".$raw['height']." ";
497 if ($raw['weight'] && $raw['weight'] > 0) {
498 $weight = xl("WT").": ".$raw['weight']." ";
501 if ($raw['BMI'] && $raw['BMI'] > 0) {
502 $bmi = xl("BMI").": ".$raw['BMI']." ";
505 if ($raw['temperature'] && $raw['temperature'] > 0) {
506 $temp = xl("Temp").": ".$raw['temperature']." ";
509 if ($raw['bps'] && $raw['bpd'] && $raw['bps'] > 0 && $raw['bpd'] > 0) {
510 $bp = xl("BP").": ".$raw['bps']."/".$raw['bpd']." ";
513 if ($raw['pulse'] && $raw['pulse'] > 0) {
514 $pulse = xl("Pulse").": ".$raw['pulse']." ";
517 if ($raw['respiration'] && $raw['respiration'] > 0) {
518 $respiration = xl("Respiration").": ".$raw['respiration']." ";
521 if ($raw['oxygen_saturation'] && $raw['oxygen_saturation'] > 0) {
522 $oxygen_saturation = xl("O2 Sat").": ".$raw['oxygen_saturation']."% ";
525 $ret = $height.$weight.$bmi.$temp.$bp.
526 $pulse.$respiration.$oxygen_saturation;
528 $ret = xl("Vital Signs").": ".$ret;