Internationalization Project: added Amharic language.
[openemr.git] / interface / forms / CAMOS / notegen.php
blob0c1112bfb42a15244d3d671dd510857869938595
1 <?php
2 $depth = '../../../';
3 include_once ($depth.'interface/globals.php');
4 include_once($depth.'library/formdata.inc.php');
5 include_once ($depth.'library/classes/class.ezpdf.php');
6 include_once("content_parser.php");
7 ?>
8 <?php
9 if (!($_POST['submit_pdf'] || $_POST['submit_html']) && ($_GET['pid'] && $_GET['encounter'])) {
11 <html>
12 <head>
13 <title>
14 <?php xl('Print Notes','e'); ?>
15 </title>
16 </head>
17 <body>
18 <?php xl('Choose print format for this encounter report.','e'); ?><br><br>
19 <form method=post name=choose_patients>
20 <input type='submit' name='submit_pdf' value='<?php xl('Print (PDF)','e'); ?>'>
21 <input type='submit' name='submit_html' value='<?php xl('Print (HTML)','e'); ?>'>
22 </form>
23 </body>
24 </html>
25 <?php
26 exit;
28 if (!$_POST['submit_pdf'] && !$_POST['submit_html'] && !($_GET['pid'] && $_GET['encounter'])) {
30 <html>
31 <head>
32 <title>
33 <?php xl('Print Notes','e'); ?>
34 </title>
35 <style type="text/css">@import url('<?php echo $depth ?>library/dynarch_calendar.css');</style>
36 <script type="text/javascript" src="<?php echo $depth ?>library/dialog.js"></script>
37 <script type="text/javascript" src="<?php echo $depth ?>library/textformat.js"></script>
38 <script type="text/javascript" src="<?php echo $depth ?>library/dynarch_calendar.js"></script>
39 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
40 <script type="text/javascript" src="<?php echo $depth ?>library/dynarch_calendar_setup.js"></script>
41 </head>
43 <body>
44 <script language='JavaScript'> var mypcc = '1'; </script>
46 <form method=post name=choose_patients>
48 <table>
49 <tr><td>
50 <span class='text'><?php xl('Start (yyyy-mm-dd): ','e') ?></span>
51 </td><td>
52 <input type='text' size='10' name='start' id='start' value='<? echo $_POST['end'] ? $_POST['end'] : date('Y-m-d') ?>'
53 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
54 title='<?php xl('yyyy-mm-dd last date of this event','e'); ?>' />
55 <img src='<?php echo $depth ?>interface/pic/show_calendar.gif' align='absbottom' width='24' height='22'
56 id='img_start' border='0' alt='[?]' style='cursor:pointer'
57 title='<?php xl('Click here to choose a date','e'); ?>'>
58 <script>
59 Calendar.setup({inputField:'start', ifFormat:'%Y-%m-%d', button:'img_start'});
60 </script>
61 </td></tr>
63 <tr><td>
64 <span class='text'><?php xl('End (yyyy-mm-dd): ','e') ?></span>
65 </td><td>
66 <input type='text' size='10' name='end' id='end' value ='<? echo $_POST['end'] ? $_POST['end'] : date('Y-m-d') ?>'
67 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
68 title='<?php xl('yyyy-mm-dd last date of this event','e'); ?>' />
69 <img src='<?php echo $depth ?>interface/pic/show_calendar.gif' align='absbottom' width='24' height='22'
70 id='img_end' border='0' alt='[?]' style='cursor:pointer'
71 title='<?php xl('Click here to choose a date','e'); ?>'>
72 <script>
73 Calendar.setup({inputField:'end', ifFormat:'%Y-%m-%d', button:'img_end'});
74 </script>
75 </td></tr>
76 <tr><td></td><td></td></tr>
77 <tr><td><?php xl('Last Name','e'); ?>: </td><td>
78 <input type='text' name='lname'/>
79 </td></tr>
80 <tr><td><?php xl('First Name','e'); ?>: </td><td>
81 <input type='text' name='fname'/>
82 </td></tr>
83 <tr><td>
84 <input type='submit' name='submit_pdf' value='<?php xl('Print (PDF)','e'); ?>'>
85 <input type='submit' name='submit_html' value='<?php xl('Print (HTML)','e'); ?>'>
86 </td><td>
87 </td></tr>
88 </table>
89 </form>
90 </body>
91 </html>
92 <?php
94 if ($_POST['submit_pdf'] || $_POST['submit_html'] || ($_GET['pid'] && $_GET['encounter'])) {
95 // note we are cleaning input, trimming, and preparing the variables for database insert
96 // before sending through this function
97 $output = getFormData(formData("start","P",true),formData("end","P",true),formData("lname","P",true),formData("fname","P",true));
98 ksort($output);
99 if ($_POST['submit_html']) { //print as html
101 <html>
102 <head>
103 <style>
104 body {
105 font-family: sans-serif;
106 font-weight: normal;
107 font-size: 8pt;
108 background: white;
109 color: black;
111 .paddingdiv {
112 width: 524pt;
113 padding: 0pt;
115 .navigate {
116 margin-top: 2.5em;
118 @media print {
119 .navigate {
120 display: none;
123 div.page {
124 page-break-after: always;
125 padding: 0pt;
126 margin-top: 50pt;
128 span.heading {
129 font-weight: bold;
130 font-size: 130%;
132 </style>
133 <title><?php xl('Patient Notes','e'); ?></title>
134 </head>
135 <body>
136 <div class='paddingdiv'>
137 <?php
138 foreach ($output as $datekey => $dailynote) {
139 foreach ($dailynote as $note_id => $notecontents) {
140 preg_match('/(\d+)_(\d+)/', $note_id, $matches); //the unique note id contains the pid and encounter
141 $pid = $matches[1];
142 $enc = $matches[2];
144 //new page code here
145 print "<DIV class='page'>";
147 print xl("Date").": ".$notecontents['date'] . "<br/>";
148 print xl("Name").": ".$notecontents['name'] . "<br/>";
149 print xl("DOB").": ".$notecontents['dob'] . "<br/>";
150 print xl("Claim")."# ".$notecontents['pubpid'] . "<br/>";
152 print "<br/>";
153 print xl("Chief Complaint").": ".$notecontents['reason'] . "<br/>";
154 if ($notecontents['vitals']) {
155 print "<br/>";
156 print $notecontents['vitals'] . "<br/>";
158 if (count($notecontents['exam']) > 0) {
159 print "<br/>";
160 print "<span class='heading'>" . xl("Progress Notes") . "</span><br/>";
161 print "<br/>";
162 foreach($notecontents['exam'] as $examnote) {
163 print nl2br(replace($pid,$enc,$examnote)) . "<br/>";
166 if (count($notecontents['prescriptions']) > 0) {
167 print "<br/>";
168 print "<span class='heading'>" . xl("Prescriptions") . "</span><br/>";
169 print "<br/>";
170 foreach($notecontents['prescriptions'] as $rx) {
171 print nl2br(replace($pid,$enc,$rx)) . "<br/>";
174 if (count($notecontents['other']) > 0) {
175 print "<br/>";
176 print "<span class='heading'>" . xl("Other") . "</span><br/>";
177 print "<br/>";
178 foreach($notecontents['other'] as $other => $othercat) {
179 print nl2br($other) . "<br/>";
180 foreach($othercat as $items) {
181 print nl2br(replace($pid,$enc,$items)) . "<br/>";
185 if (count($notecontents['billing']) > 0) {
186 $tmp = array();
187 foreach($notecontents['billing'] as $code) {
188 $tmp[$code]++;
190 if (count($tmp) > 0) {
191 print "<br/>";
192 print "<span class='heading'>" . xl("Coding") . "</span><br/>";
193 print "<br/>";
194 foreach($tmp as $code => $val) {
195 print nl2br($code) . "<br/>";
199 if (count($notecontents['calories']) > 0) {
200 $sum = 0;
201 print "<br/>";
202 print "<span class='heading'>" . xl("Calories") . "</span><br/>";
203 print "<br/>";
204 foreach($notecontents['calories'] as $calories => $value) {
205 print $value['content'].' - '.$value['item'].' - '.$value['date'] . "<br/>";
206 $sum += $value['content'];
208 print "--------" . "<br/>";
209 print $sum . "<br/>";
211 print "<br/>";
212 print "<br/>";
213 print "<span class='heading'>" . xl("Digitally Signed") . "</span><br/>";
215 $query = sqlStatement("select t2.id, t2.fname, t2.lname, t2.title from forms as t1 join users as t2 on " .
216 "(t1.user like t2.username) where t1.pid=$pid and t1.encounter=$encounter");
217 if ($results = mysql_fetch_array($query, MYSQL_ASSOC)) {
218 $name = $results['fname']." ".$results['lname'].", ".$results['title'];
219 $user_id = $results['id'];
221 $path = $GLOBALS['fileroot']."/interface/forms/CAMOS";
222 if (file_exists($path."/sig".$user_id.".jpg")) {
223 //show the image here
225 print "<span class='heading'>" . $name . "</span><br/>";
226 print "</DIV>"; //end of last page
230 <script language='JavaScript'>
231 window.print();
232 </script>
233 </div>
234 </body>
235 </html>
236 <?php
237 exit;
239 else { // print as pdf
240 $pdf =& new Cezpdf();
241 $pdf->selectFont($depth.'library/fonts/Helvetica');
242 $pdf->ezSetCmMargins(3,1,1,1);
243 $first = 1;
244 foreach ($output as $datekey => $dailynote) {
245 foreach ($dailynote as $note_id => $notecontents) {
246 preg_match('/(\d+)_(\d+)/', $note_id, $matches); //the unique note id contains the pid and encounter
247 $pid = $matches[1];
248 $enc = $matches[2];
249 if (!$first) { //generate a new page each time except first iteration when nothing has been printed yet
250 $pdf->ezNewPage();
252 else {
253 $first = 0;
255 $pdf->ezText(xl("Date").": ".$notecontents['date'],8);
256 $pdf->ezText(xl("Name").": ".$notecontents['name'],8);
257 $pdf->ezText(xl("DOB").": ".$notecontents['dob'],8);
258 $pdf->ezText(xl("Claim")."# ".$notecontents['pubpid'],8);
260 $pdf->ezText("",8);
261 $pdf->ezText(xl("Chief Complaint").": ".$notecontents['reason'],8);
262 if ($notecontents['vitals']) {
263 $pdf->ezText("",8);
264 $pdf->ezText($notecontents['vitals'],8);
266 if (count($notecontents['exam']) > 0) {
267 $pdf->ezText("",8);
268 $pdf->ezText(xl("Progress Notes"),12);
269 $pdf->ezText("",8);
270 foreach($notecontents['exam'] as $examnote) {
271 $pdf->ezText(replace($pid,$enc,$examnote));
274 if (count($notecontents['prescriptions']) > 0) {
275 $pdf->ezText("",8);
276 $pdf->ezText(xl("Prescriptions"),12);
277 $pdf->ezText("",8);
278 foreach($notecontents['prescriptions'] as $rx) {
279 $pdf->ezText(replace($pid,$enc,$rx));
282 if (count($notecontents['other']) > 0) {
283 $pdf->ezText("",8);
284 $pdf->ezText(xl("Other"),12);
285 $pdf->ezText("",8);
286 foreach($notecontents['other'] as $other => $othercat) {
287 $pdf->ezText($other,8);
288 foreach($othercat as $items) {
289 $pdf->ezText(replace($pid,$enc,$items),8);
293 if (count($notecontents['billing']) > 0) {
294 $tmp = array();
295 foreach($notecontents['billing'] as $code) {
296 $tmp[$code]++;
298 if (count($tmp) > 0) {
299 $pdf->ezText("",8);
300 $pdf->ezText(xl("Coding"),12);
301 $pdf->ezText("",8);
302 foreach($tmp as $code => $val) {
303 $pdf->ezText($code,8);
307 if (count($notecontents['calories']) > 0) {
308 $sum = 0;
309 $pdf->ezText("",8);
310 $pdf->ezText(xl("Calories"),12);
311 $pdf->ezText("",8);
312 foreach($notecontents['calories'] as $calories => $value) {
313 $pdf->ezText($value['content'].' - '.$value['item'].' - '.$value['date'],8);
314 $sum += $value['content'];
316 $pdf->ezText("--------",8);
317 $pdf->ezText($sum,8);
319 $pdf->ezText("",12);
320 $pdf->ezText("",12);
321 $pdf->ezText(xl("Digitally Signed"),12);
323 $query = sqlStatement("select t2.id, t2.fname, t2.lname, t2.title from forms as t1 join users as t2 on " .
324 "(t1.user like t2.username) where t1.pid=$pid and t1.encounter=$encounter");
325 if ($results = mysql_fetch_array($query, MYSQL_ASSOC)) {
326 $name = $results['fname']." ".$results['lname'].", ".$results['title'];
327 $user_id = $results['id'];
329 $path = $GLOBALS['fileroot']."/interface/forms/CAMOS";
330 if (file_exists($path."/sig".$user_id.".jpg")) {
331 $pdf->ezImage($path."/sig".$user_id.".jpg",'','72','','left','');
333 $pdf->ezText($name,12);
336 $pdf->ezStream();
339 function getFormData($start_date,$end_date,$lname,$fname) { //dates in sql format
341 // All 4 parameters have previously been trimmed, globally validated,
342 // and prepared for database insert
344 $name_clause = '';
345 $date_clause = "date(t2.date) >= '".$start_date."' and date(t2.date) <= '".$end_date."' ";
346 if ($lname || $fname) {
347 $name_clause = "and t3.lname like '%".$lname."%' and t3.fname like '%".$fname."%' ";
349 $dates = array();
350 if ($_GET['pid'] && $_GET['encounter']) {
351 $date_clause = '';
352 $name_clause = "t2.pid=".$_GET['pid']." and t2.encounter=".$_GET['encounter']." ";
354 $query1 = sqlStatement(
355 "select t1.form_id, t1.form_name, t1.pid, date_format(t2.date,'%m-%d-%Y') as date, " .
356 "date_format(t2.date,'%Y%m%d') as datekey, " .
357 "t3.lname, t3.fname, t3.pubpid, date_format(t3.DOB,'%m-%d-%Y') as dob, " .
358 "t2.encounter as enc, " .
359 "t2.reason from " .
360 "forms as t1 join " .
361 "form_encounter as t2 on " .
362 "(t1.pid = t2.pid and t1.encounter = t2.encounter) " .
363 "join patient_data as t3 on " .
364 "(t1.pid = t3.pid) where " .
365 $date_clause .
366 $name_clause .
367 "order by date,pid");
368 while ($results1 = mysql_fetch_array($query1, MYSQL_ASSOC)) {
369 if (!$dates[$results1['datekey']]) {
370 $dates[$results1['datekey']] = array();
372 if (!$dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]) {
373 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']] = array();
374 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['name'] = $results1['fname'].' '.$results1['lname'];
375 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['date'] = $results1['date'];
376 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['pubpid'] = $results1['pubpid'];
377 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['dob'] = $results1['dob'];
378 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['vitals'] = '';
379 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['reason'] = $results1['reason'];
380 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['exam'] = array();
381 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['prescriptions'] = array();
382 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['other'] = array();
383 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['billing'] = array();
384 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['calories'] = array();
386 // get icd9 codes for this encounter
387 $query2 = sqlStatement("select * from billing where encounter = ".
388 $results1['enc']." and pid = ".$results1['pid']." and code_type like 'ICD9' and activity=1");
389 while ($results2 = mysql_fetch_array($query2, MYSQL_ASSOC)) {
390 array_push($dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['billing'],
391 $results2['code'].' '.$results2['code_text']);
393 if (strtolower($results1['form_name']) == 'vitals') { // deal with Vitals
394 $query2 = sqlStatement("select * from form_vitals where id = " .
395 $results1['form_id']);
396 if ($results2 = mysql_fetch_array($query2, MYSQL_ASSOC)) {
397 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['vitals'] = formatVitals($results2);
400 if (substr(strtolower($results1['form_name']),0,5) == 'camos') { // deal with camos
401 $query2 = sqlStatement("select category,subcategory,item,content,date_format(date,'%h:%i %p') as date from form_CAMOS where id = " .
402 $results1['form_id']);
403 if ($results2 = mysql_fetch_array($query2, MYSQL_ASSOC)) {
404 if ($results2['category'] == 'exam') {
405 array_push($dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['exam'],$results2['content']);
407 elseif ($results2['category'] == 'prescriptions') {
408 array_push($dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['prescriptions'],preg_replace("/\n+/",' ',$results2['content']));
410 elseif ($results2['category'] == 'communications') {
411 //do nothing
413 elseif ($results2['category'] == 'calorie intake') {
414 $values = array('subcategory' => $results2['subcategory'],
415 'item' => $results2['item'],
416 'content' => $results2['content'],
417 'date' => $results2['date']);
418 array_push($dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['calories'],$values);
421 else {
422 if (!$dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['other'][$results2['category']]) {
423 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['other'][$results2['category']] = array();
425 array_push($dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['other'][$results2['category']],
426 preg_replace(array("/\n+/","/patientname/i"),array(' ',$results1['fname'].' '.$results1['lname']),$results2['content']));
431 return $dates;
433 function formatVitals($raw) { //pass raw vitals array, format and return as string
434 $height = '';
435 $weight = '';
436 $bmi = '';
437 $temp= '';
438 $bp = '';
439 $pulse = '';
440 $respiration = '';
441 $oxygen_saturation = '';
442 if ($raw['height'] && $raw['height'] > 0) {
443 $height = xl("HT").": ".$raw['height']." ";
445 if ($raw['weight'] && $raw['weight'] > 0) {
446 $weight = xl("WT").": ".$raw['weight']." ";
448 if ($raw['BMI'] && $raw['BMI'] > 0) {
449 $bmi = xl("BMI").": ".$raw['BMI']." ";
451 if ($raw['temperature'] && $raw['temperature'] > 0) {
452 $temp = xl("Temp").": ".$raw['temperature']." ";
454 if ($raw['bps'] && $raw['bpd'] && $raw['bps'] > 0 && $raw['bpd'] > 0) {
455 $bp = xl("BP").": ".$raw['bps']."/".$raw['bpd']." ";
457 if ($raw['pulse'] && $raw['pulse'] > 0) {
458 $pulse = xl("Pulse").": ".$raw['pulse']." ";
460 if ($raw['respiration'] && $raw['respiration'] > 0) {
461 $respiration = xl("Respiration").": ".$raw['respiration']." ";
463 if ($raw['oxygen_saturation'] && $raw['oxygen_saturation'] > 0) {
464 $oxygen_saturation = xl("O2 Sat").": ".$raw['oxygen_saturation']."% ";
466 $ret = $height.$weight.$bmi.$temp.$bp.
467 $pulse.$respiration.$oxygen_saturation;
468 if ($ret != '') {
469 $ret = xl("Vital Signs").": ".$ret;
471 return $ret;