3 include_once ($depth.'interface/globals.php');
4 include_once ($depth.'library/classes/class.ezpdf.php');
7 if (!$_POST['submit'] && !($_GET['pid'] && $_GET['encounter'])) {
14 <style type
="text/css">@import
url('<?php echo $depth ?>library/dynarch_calendar.css');</style
>
15 <script type
="text/javascript" src
="<?php echo $depth ?>library/dialog.js"></script
>
16 <script type
="text/javascript" src
="<?php echo $depth ?>library/textformat.js"></script
>
17 <script type
="text/javascript" src
="<?php echo $depth ?>library/dynarch_calendar.js"></script
>
18 <script type
="text/javascript" src
="<?php echo $depth ?>library/dynarch_calendar_en.js"></script
>
19 <script type
="text/javascript" src
="<?php echo $depth ?>library/dynarch_calendar_setup.js"></script
>
23 <script language
='JavaScript'> var mypcc
= '1'; </script
>
25 <form method
=post name
=choose_patients
>
29 <span
class='text'><?php
xl('Start (yyyy-mm-dd): ','e') ?
></span
>
31 <input type
='text' size
='10' name
='start' id
='start' value
='<? echo $_POST['end
'] ? $_POST['end
'] : date('Y
-m
-d
') ?>'
32 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)'
33 title
='yyyy-mm-dd last date of this event' />
34 <img src
='<?php echo $depth ?>interface/pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
35 id
='img_start' border
='0' alt
='[?]' style
='cursor:pointer'
36 title
='Click here to choose a date'>
38 Calendar
.setup({inputField
:'start', ifFormat
:'%Y-%m-%d', button
:'img_start'});
43 <span
class='text'><?php
xl('End (yyyy-mm-dd): ','e') ?
></span
>
45 <input type
='text' size
='10' name
='end' id
='end' value
='<? echo $_POST['end
'] ? $_POST['end
'] : date('Y
-m
-d
') ?>'
46 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)'
47 title
='yyyy-mm-dd last date of this event' />
48 <img src
='<?php echo $depth ?>interface/pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
49 id
='img_end' border
='0' alt
='[?]' style
='cursor:pointer'
50 title
='Click here to choose a date'>
52 Calendar
.setup({inputField
:'end', ifFormat
:'%Y-%m-%d', button
:'img_end'});
55 <tr
><td
></td
><td
></td
></tr
>
56 <tr
><td
>Last Name
: </td
><td
>
57 <input type
='text' name
='lname'/>
59 <tr
><td
>First Name
: </td
><td
>
60 <input type
='text' name
='fname'/>
63 <input type
='submit' name
='submit' value
='submit'>
72 if ($_POST['submit'] ||
($_GET['pid'] && $_GET['encounter'])) {
74 $pdf->selectFont($depth.'library/fonts/Helvetica');
75 $pdf->ezSetCmMargins(3,1,1,1);
76 $output = getFormData($_POST['start'],$_POST['end'],$_POST['lname'],$_POST['fname']);
79 foreach ($output as $datekey => $dailynote) {
80 foreach ($dailynote as $note_id => $notecontents) {
81 preg_match('/(\d+)_(\d+)/', $note_id, $matches); //the unique note id contains the pid and encounter
84 if (!$first) { //generate a new page each time except first iteration when nothing has been printed yet
90 $pdf->ezText("Date: ".$notecontents['date'],8);
91 $pdf->ezText("Name: ".$notecontents['name'],8);
92 // $pdf->ezText("ID: ".$note_id,8);
94 $query = sqlStatement("select pubpid from patient_data where id=".$_GET['pid']);
95 if ($results = mysql_fetch_array($query, MYSQL_ASSOC
)) {
96 $pubpid = $results['pubpid'];
98 $pdf->ezText("Claim# ".$pubpid,8);
101 $pdf->ezText("Chief Complaint: ".$notecontents['reason'],8);
102 if ($notecontents['vitals']) {
104 $pdf->ezText($notecontents['vitals'],8);
106 if (count($notecontents['exam']) > 0) {
108 $pdf->ezText("Progress Notes",12);
110 foreach($notecontents['exam'] as $examnote) {
111 $pdf->ezText("$examnote");
114 if (count($notecontents['prescriptions']) > 0) {
116 $pdf->ezText("Prescriptions",12);
118 foreach($notecontents['prescriptions'] as $rx) {
122 if (count($notecontents['other']) > 0) {
124 $pdf->ezText("Other",12);
126 foreach($notecontents['other'] as $other => $othercat) {
127 $pdf->ezText($other,8);
128 foreach($othercat as $items) {
129 $pdf->ezText($items,8);
133 if (count($notecontents['billing']) > 0) {
135 foreach($notecontents['billing'] as $code) {
138 if (count($tmp) > 0) {
140 $pdf->ezText("Coding",12);
142 foreach($tmp as $code => $val) {
143 $pdf->ezText($code,8);
147 if (count($notecontents['calories']) > 0) {
150 $pdf->ezText("Calories",12);
152 foreach($notecontents['calories'] as $calories => $value) {
153 $pdf->ezText($value['content'].' - '.$value['item'].' - '.$value['date'],8);
154 $sum +
= $value['content'];
156 $pdf->ezText("--------",8);
157 $pdf->ezText($sum,8);
161 $pdf->ezText("Digitally Signed",12);
163 $query = sqlStatement("select t2.id, t2.fname, t2.lname, t2.title from forms as t1 join users as t2 on " .
164 "(t1.user like t2.username) where t1.pid=$pid and t1.encounter=$encounter");
165 if ($results = mysql_fetch_array($query, MYSQL_ASSOC
)) {
166 $name = $results['fname']." ".$results['lname'].", ".$results['title'];
167 $user_id = $results['id'];
169 $path = $GLOBALS['fileroot']."/interface/forms/CAMOS";
170 if (file_exists($path."/sig".$user_id.".jpg")) {
171 $pdf->ezImage($path."/sig".$user_id.".jpg",'','72','','left','');
173 $pdf->ezText($name,12);
178 function getFormData($start_date,$end_date,$lname,$fname) { //dates in sql format
179 $lname = trim($lname);
180 $fname = trim($fname);
182 $date_clause = "date(t2.date) >= '".$start_date."' and date(t2.date) <= '".$end_date."' ";
183 if ($lname ||
$fname) {
184 $name_clause = "and t3.lname like '%".$lname."%' and t3.fname like '%".$fname."%' ";
187 if ($_GET['pid'] && $_GET['encounter']) {
189 $name_clause = "t2.pid=".$_GET['pid']." and t2.encounter=".$_GET['encounter']." ";
191 $query1 = sqlStatement(
192 "select t1.form_id, t1.form_name, t1.pid, date_format(t2.date,'%m-%d-%Y') as date, " .
193 "date_format(t2.date,'%Y%m%d') as datekey, " .
194 "t3.lname, t3.fname, date_format(t3.DOB,'%m-%d-%Y') as dob, " .
195 "t2.encounter as enc, " .
197 "forms as t1 join " .
198 "form_encounter as t2 on " .
199 "(t1.pid = t2.pid and t1.encounter = t2.encounter) " .
200 "join patient_data as t3 on " .
201 "(t1.pid = t3.pid) where " .
204 "order by date,pid");
205 while ($results1 = mysql_fetch_array($query1, MYSQL_ASSOC
)) {
206 if (!$dates[$results1['datekey']]) {
207 $dates[$results1['datekey']] = array();
209 if (!$dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]) {
210 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']] = array();
211 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['name'] = $results1['fname'].' '.$results1['lname'];
212 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['date'] = $results1['date'];
213 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['dob'] = $results1['dob'];
214 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['vitals'] = '';
215 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['reason'] = $results1['reason'];
216 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['exam'] = array();
217 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['prescriptions'] = array();
218 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['other'] = array();
219 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['billing'] = array();
220 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['calories'] = array();
222 // get icd9 codes for this encounter
223 $query2 = sqlStatement("select * from billing where encounter = ".
224 $results1['enc']." and pid = ".$results1['pid']." and code_type like 'ICD9' and activity=1");
225 while ($results2 = mysql_fetch_array($query2, MYSQL_ASSOC
)) {
226 array_push($dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['billing'],
227 $results2['code'].' '.$results2['code_text']);
229 if (strtolower($results1['form_name']) == 'vitals') { // deal with Vitals
230 $query2 = sqlStatement("select * from form_vitals where id = " .
231 $results1['form_id']);
232 if ($results2 = mysql_fetch_array($query2, MYSQL_ASSOC
)) {
233 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['vitals'] = formatVitals($results2);
236 if (substr(strtolower($results1['form_name']),0,5) == 'camos') { // deal with camos
237 $query2 = sqlStatement("select category,subcategory,item,content,date_format(date,'%h:%i %p') as date from form_CAMOS where id = " .
238 $results1['form_id']);
239 if ($results2 = mysql_fetch_array($query2, MYSQL_ASSOC
)) {
240 if ($results2['category'] == 'exam') {
241 array_push($dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['exam'],$results2['content']);
243 elseif ($results2['category'] == 'prescriptions') {
244 array_push($dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['prescriptions'],preg_replace("/\n+/",' ',$results2['content']));
246 elseif ($results2['category'] == 'communications') {
249 elseif ($results2['category'] == 'calorie intake') {
250 $values = array('subcategory' => $results2['subcategory'],
251 'item' => $results2['item'],
252 'content' => $results2['content'],
253 'date' => $results2['date']);
254 array_push($dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['calories'],$values);
258 if (!$dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['other'][$results2['category']]) {
259 $dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['other'][$results2['category']] = array();
261 array_push($dates[$results1['datekey']][$results1['pid'].'_'.$results1['enc']]['other'][$results2['category']],
262 preg_replace(array("/\n+/","/patientname/i"),array(' ',$results1['fname'].' '.$results1['lname']),$results2['content']));
269 function formatVitals($raw) { //pass raw vitals array, format and return as string
277 $oxygen_saturation = '';
278 if ($raw['height'] && $raw['height'] > 0) {
279 $height = "HT: ".$raw['height']." ";
281 if ($raw['weight'] && $raw['weight'] > 0) {
282 $weight = "WT: ".$raw['weight']." ";
284 if ($raw['BMI'] && $raw['BMI'] > 0) {
285 $bmi = "BMI: ".$raw['BMI']." ";
287 if ($raw['temperature'] && $raw['temperature'] > 0) {
288 $temp = "Temp: ".$raw['temperature']." ";
290 if ($raw['bps'] && $raw['bpd'] && $raw['bps'] > 0 && $raw['bpd'] > 0) {
291 $bp = "BP: ".$raw['bps']."/".$raw['bpd']." ";
293 if ($raw['pulse'] && $raw['pulse'] > 0) {
294 $pulse = "Pulse: ".$raw['pulse']." ";
296 if ($raw['respiration'] && $raw['respiration'] > 0) {
297 $respiration = "Respiration: ".$raw['respiration']." ";
299 if ($raw['oxygen_saturation'] && $raw['oxygen_saturation'] > 0) {
300 $oxygen_saturation = "O2 Sat: ".$raw['oxygen_saturation']."% ";
302 $ret = $height.$weight.$bmi.$temp.$bp.
303 $pulse.$respiration.$oxygen_saturation;
305 $ret = "Vital Signs: ".$ret;