/** * This function makes and stores a document that we want to deliver. */ function make_document($task) { global $providerNAME; global $encounter; /** * We want to store the current PDF version of this task. */ $query = "SELECT * FROM users WHERE id=?"; $to_data = sqlQuery($query, array($task['TO_ID'])); $from_data = sqlQuery($query, array($task['FROM_ID'])); $sql = "SELECT * FROM facility ORDER BY billing_location DESC LIMIT 1"; $facility_data = sqlQuery($sql); $query = "SELECT * FROM patient_data where pid=?"; $patientData = sqlQuery($query, array($task['PATIENT_ID'])); $from_fax = preg_replace("/[^0-9]/", "", $facility_data['fax']); $from_name = $from_data['fname'] . " " . $from_data['lname']; if ($from_data['suffix']) { $from_name .= ", " . $from_data['suffix']; } $from_fac = $from_facility['name']; $to_fax = preg_replace("/[^0-9]/", "", $to_data['fax']); $to_name = $to_data['fname'] . " " . $to_data['lname']; if ($to_data['suffix']) { $to_name .= ", " . $to_data['suffix']; } $pt_name = $patientData['fname'] . ' ' . $patientData['lname']; $encounter = $task['ENC_ID']; $query = "select form_encounter.date as encounter_date,form_eye_mag.id as form_id,form_encounter.*, form_eye_mag.* \n from form_eye_mag ,forms,form_encounter \n where \n form_encounter.encounter =? and \n form_encounter.encounter = forms.encounter and \n form_eye_mag.id=forms.form_id and\n forms.deleted != '1' and \n form_eye_mag.pid=? "; $encounter_data = sqlQuery($query, array($encounter, $task['PATIENT_ID'])); @extract($encounter_data); $providerID = getProviderIdOfEncounter($encounter); $providerNAME = getProviderName($providerID); $dated = new DateTime($encounter_date); $dated = $dated->format('Y/m/d'); $visit_date = oeFormatShortDate($dated); //$visit_date = $encounter_date; $pid = $task['PATIENT_ID']; $PDF_OUTPUT = '1'; $filepath = $GLOBALS['oer_config']['documents']['repository'] . $task['PATIENT_ID']; //so far we make A "Report", one per encounter, and "Faxes", as many as we need per encounter. //So delete any prior report if that is what we are doing. and replace it. //If it is a fax, can we check to see if the report is already here, and if it is add it, or do we have to // always remake it? For now, REMAKE IT... if ($task['DOC_TYPE'] == 'Fax') { $category_name = "Communication"; //Faxes are stored in the Documents->Communication category. Do we need to translate this? //$category_name = xl('Communication'); $query = "select id from categories where name =?"; $ID = sqlQuery($query, array($category_name)); $category_id = $ID['id']; $filename = "Fax_" . $encounter . "_" . $to_data['lname'] . ".pdf"; while (file_exists($filepath . '/' . $filename)) { $count++; $filename = "FAX_" . $encounter . "_" . $to_data['lname'] . "_" . $count . ".pdf"; } } else { $category_name = "Encounters"; $query = "select id from categories where name =?"; $ID = sqlQuery($query, array($category_name)); $category_id = $ID['id']; $filename = "Report_" . $encounter . ".pdf"; foreach (glob($filepath . '/' . $filename) as $file) { unlink($file); //maybe shorten to just unlink($filepath.'/'.$filename); - well this does test to see if it is there } $sql = "DELETE from categories_to_documents where document_id IN (SELECT id from documents where documents.url like ?)"; sqlQuery($sql, array("%" . $filename)); $sql = "DELETE from documents where documents.url like ?"; sqlQuery($sql, array("%" . $filename)); } $pdf = new HTML2PDF($GLOBALS['pdf_layout'], $GLOBALS['pdf_size'], $GLOBALS['pdf_language'], true, 'UTF-8', array($GLOBALS['pdf_left_margin'], $GLOBALS['pdf_top_margin'], $GLOBALS['pdf_right_margin'], $GLOBALS['pdf_bottom_margin']), $_SESSION['language_direction'] == 'rtl' ? true : false); ob_start(); ?> <html> <head> <TITLE><?php echo xlt('Taskman: Documents in openEMR'); ?> </TITLE> <style> .wrapper { margin:20px; } .col1 { font-weight:bold; width:100px; padding:10px; text-align:right; } .col2 { width:375px; padding:10px; } </style> <link rel="stylesheet" href="<?php echo $webserver_root; ?> /interface/themes/style_pdf.css" type="text/css"> </head> <body> <?php if ($task['DOC_TYPE'] == 'Fax') { ?> <div class='wrapper'> <?php echo report_header($task['PATIENT_ID'], 'PDF'); ?> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <hr /> <table> <tr> <td class='col1'><?php echo xlt('From'); ?> :</td> <td class='col2'> <?php echo text($from_name); ?> <br /> </td> </tr> <tr> <td class='col1'><?php echo xlt('Address'); ?> :</td> <td class='col2'> <?php if ($from_data['name']) { echo text($from_data['name']) . "<br />"; } ?> <?php echo text($from_data['street']); ?> <br /> <?php echo text($from_data['city']); ?> , <?php echo text($from_data['state']) . " " . text($from_data['zip']); ?> <br /> </td> </tr> <tr> <td class='col1'> <?php echo xlt('Phone'); ?> : </td> <td class='col2'> <?php echo text($from_data['phonew1']); ?> </td> </tr> <tr> <td class='col1'> <?php echo xlt('Fax'); ?> : </td> <td class='col2'><?php echo text($from_data['fax']); ?> <br /> </td> </tr> <tr> <td class='col1'><?php echo xlt('To'); ?> :</td> <td class='col2'><?php echo text($to_name); ?> </td> </tr> <tr> <td class='col1'><?php echo xlt('Address'); ?> :</td> <td class='col2'> <?php echo text($to_data['street']) . "<br />\n\t\t\t\t \t\t\t" . text($to_data['city']) . ", " . text($to_data['state']) . " " . text($to_data['zip']); ?> <br /> </td> </tr> <tr> <td class='col1'> <?php echo xlt('Phone'); ?> : </td> <td class='col2'> <?php echo text($to_data['phonew1']); ?> </td> </tr> <tr> <td class='col1'> <?php echo xlt('Fax'); ?> : </td> <td class='col2'> <?php echo text($to_data['fax']); ?> </td> </tr> <tr><td colspan="2"><br /><hr /></td></tr> <tr> <td class='col1'> <?php echo xlt('Comments'); ?> : </td> <td class='col2'><?php echo xlt('Report of visit'); ?> : <?php echo text($pt_name); ?> on <?php echo $visit_date; ?> </td> </tr> </table> </div> <?php echo '<page></page><div style="page-break-after:always; clear:both"></div>'; } // If the doc_id does exit, why remake it? // We could just add another attachment, stopping here at the coversheet, and adding the doc_name that we sent... // No. We actually need a physical copy of what we sent, since the report itself can be overwritten. Keep it legal. // Unless the Report.pdf can be merged with the cover sheet. Until then, just redo it all. echo narrative($pid, $encounter, $task['DOC_TYPE'], $form_id); ?> </body> </html> <?php global $web_root, $webserver_root; $content = ob_get_clean(); // Fix a nasty html2pdf bug - it ignores document root! $i = 0; $wrlen = strlen($web_root); $wsrlen = strlen($webserver_root); while (true) { $i = stripos($content, " src='/", $i + 1); if ($i === false) { break; } if (substr($content, $i + 6, $wrlen) === $web_root && substr($content, $i + 6, $wsrlen) !== $webserver_root) { $content = substr($content, 0, $i + 6) . $webserver_root . substr($content, $i + 6 + $wrlen); } } $pdf->writeHTML($content, false); $temp_filename = '/tmp/' . $filename; $content_pdf = $pdf->Output($temp_filename, 'F'); $type = "application/pdf"; $size = filesize($temp_filename); $return = addNewDocument($filename, $type, $temp_filename, 0, $size, $task['FROM_ID'], $task['PATIENT_ID'], $category_id); $task['DOC_ID'] = $return['doc_id']; $task['DOC_url'] = $filepath . '/' . $filename; $sql = "UPDATE documents set encounter_id=? where id=?"; //link it to this encounter sqlQuery($sql, array($encounter, $task['DOC_ID'])); return $task; }
function eye_mag_report($pid, $encounter, $cols, $id, $formname = 'eye_mag') { global $form_folder; global $form_name; global $choice; /** openEMR note: eye_mag Index is id, * linked to encounter in form_encounter * whose encounter is linked to id in forms. */ $query = "select form_encounter.date as encounter_date,form_eye_mag.*\n from form_eye_mag ,forms,form_encounter\n where\n form_encounter.encounter =? and\n form_encounter.encounter = forms.encounter and\n form_eye_mag.id=forms.form_id and\n forms.pid =form_eye_mag.pid and\n form_eye_mag.pid=? "; $objQuery = sqlQuery($query, array($encounter, $pid)); @extract($objQuery); $dated = new DateTime($encounter_date); $dated = $dated->format('Y/m/d'); global $visit_date; $visit_date = oeFormatShortDate($dated); /* * Patient/Client -> Visits -> Visit History, on mouse over this is called with variable "choice". * To use this feature, this "choice" variable must be added programmatically to * /interface/patient_file/history/encounters_ajax.php, currently line 20. * The variable $choice will tell us what to display. * If it is not present it will display everything == 'narrative'. * @param string $choice options NULL,TEXT,DRAW,NARRATIVE * @param string $encounter = encounter number * @param string $pid value = patient id * @return string => returns the HTML of the report selected */ if ($choice == 'DRAW') { /* $side="OU"; $zone = array("HPI","PMH","VISION","NEURO","EXT","ANTSEG","RETINA","IMPPLAN"); // for ($i = 0; $i < count($zone); ++$i) { // show only 2 for now in the encounter page ($choice =='drawing') ? ($count = count($zone)) : ($count ='2'); for ($i = 0; $i < $count; ++$i) { $file_location = $GLOBALS["OE_SITES_BASE"]."/".$_SESSION['site_id']."/documents/".$pid."/".$form_folder."/".$encounter."/".$side."_".$zone[$i]."_VIEW.png"; $sql = "SELECT * from documents where url='file://".$file_location."'"; $doc = sqlQuery($sql); if (file_exists($file_location) && ($doc['id'] > '0')) { $filetoshow = $GLOBALS['web_root']."/controller.php?document&retrieve&patient_id=$pid&document_id=$doc[id]&as_file=false"; ?><div style='position:relative;float:left;width:100px;height:75px;'> <img src='<?php echo $filetoshow; ?>' width=100 heght=75> </div> <? } else { // $filetoshow = "../../forms/".$form_folder."/images/".$side."_".$zone[$i]."_BASE.png?".rand(); } ?> <?php } } else if ($choice == "drawing") { */ ?> <div class="borderShadow"> <?php display_draw_section("VISION", $encounter, $pid); ?> </div> <div class="borderShadow"> <?php display_draw_section("NEURO", $encounter, $pid); ?> </div> <div class="borderShadow"> <?php display_draw_section("EXT", $encounter, $pid); ?> </div> <div class="borderShadow"> <?php display_draw_section("ANTSEG", $encounter, $pid); ?> </div> <div class="borderShadow"> <?php display_draw_section("RETINA", $encounter, $pid); ?> </div> <div class="borderShadow"> <?php display_draw_section("IMPPLAN", $encounter, $pid); ?> </div> <?php } else { if ($choice == 'TEXT') { //just display HPI and A/P narrative($pid, $encounter, $cols, $id, 'TEXT'); } else { if ($choice != "narrative") { narrative($pid, $encounter, $cols, $id, 'narrative'); //return; } } } }