function _print() { // Turn off the template // Deal with faxstatus if (isset($_REQUEST['faxstatus'])) { $fax = CreateObject('org.freemedsoftware.core.Fax', '/dev/null'); $status = $fax->State($_REQUEST['faxstatus']); $display_buffer .= "<b>" . $output . "</b>\n"; if ($status == 1) { $display_buffer .= "<div align=\"center\"><b>" . __("Fax sent successfully.") . "</b></div>\n"; $display_buffer .= "<div align=\"center\"><a onClick=\"javascript:close();\" class=\"button\">" . __("Close") . "</div>\n"; } else { $display_buffer .= "<b>" . __("Fax is attempting to send: ") . "</b>" . $status . "\n"; $GLOBALS['__freemed']['automatic_refresh'] = 10; } return true; break; } // Handle render if ($render = $this->print_override($_REQUEST['id'])) { // Handle this elsewhere } else { // Create TeX object for patient $TeX = CreateObject('org.freemedsoftware.core.TeX'); // Actual renderer for formatting array if ($this->table_name) { if ($this->summary_query) { // If this is an EMR module with additional // fields, import them $query = "SELECT *" . (count($this->summary_query) > 0 ? "," . join(",", $this->summary_query) . " " : " ") . "FROM " . $this->table_name . " " . "WHERE id='" . addslashes($_REQUEST['id']) . "'"; $rec = $GLOBALS['sql']->queryRow($query); } else { $rec = $GLOBALS['sql']->get_link($this->table_name, $_REQUEST['id']); } // end checking for summary_query } else { $rec = array('id' => $_REQUEST['id']); } // Check for overridden template if (file_exists('lib/tex/' . freemed::secure_filename($_REQUEST['print_template']) . '.tex')) { $this_template = freemed::secure_filename($_REQUEST['print_template']); } else { $this_template = $this->print_template; } $TeX->_buffer = $TeX->RenderFromTemplate($this_template, $rec); } // Get appropriate printer from user settings global $this_user; if (!is_object($this_user)) { $this_user = CreateObject('org.freemedsoftware.api.User'); } $printer = CreateObject('PHP.PrinterWrapper'); $display_buffer .= __("Printing") . " ... <br/>\n"; // Figure out print method $_pm = $_REQUEST['print_method']; switch ($_pm) { // Handle direct to browser case 'browser': if ($render) { $_file = $render; } else { $_file = $TeX->RenderToPDF(!empty($this->print_template)); } if ($_REQUEST['attachment']) { // Render second PDF $parts = explode('|', $_REQUEST['attachment']); // Composite ... $comp = CreateObject('org.freemedsoftware.core.MultiplePDF'); $comp->Add($_file); $comp->Add(module_function($parts[0], '_RenderToPDF', array($parts[1]))); $file = $comp->Composite(); } else { $file = $_file; } ob_start(); readfile($file); $contents = ob_get_contents(); ob_end_clean(); Header('Content-Type: application/x-freemed-print-pdf'); Header('Content-Length: ' . strlen($contents)); Header('Content-Disposition: inline; filename="' . mktime() . '.pdf"'); print $contents; flush(); //print "file = $file<br/>\n"; unlink($file); die; break; case 'fax': if ($render) { $_file = $render; } else { $_file = $TeX->RenderToPDF(!empty($this->print_template)); } // Handle attachments if ($_REQUEST['attachment']) { // Render second PDF $parts = explode('|', $_REQUEST['attachment']); // Composite ... $comp = CreateObject('org.freemedsoftware.core.MultiplePDF'); $comp->Add($_file); $comp->Add(module_function($parts[0], '_RenderToPDF', array($parts[1]))); $file = $comp->Composite(); } else { // Pass through ... $file = $_file; } $fax = CreateObject('org.freemedsoftware.core.Fax', $file, array('sender' => $this_user->user_descrip, 'comments' => __("HIPPA Compliance Notice: This transmission contains confidential medical information which is protected by the patient/physician privilege. The enclosed message is being communicated to the intended recipient for the purposes of facilitating healthcare. If you have received this transmission in error, please notify the sender immediately, return the fax message and delete the message from your system."))); //print ($_REQUEST['fax_number']); $output = $fax->Send($_REQUEST['fax_number']); //$display_buffer .= "<b>".$output."</b>\n"; // TODO : Descrip call back if ($this->patient_field) { $_r = $GLOBALS['sql']->get_link($this->table_name, $_REQUEST['id']); $_p = CreateObject('org.freemedsoftware.core.Patient', $_r[$this->patient_field]); $descrip = $this->record_name . ' for ' . $_p->fullName(); $this_user->setFaxInQueue($output, $_r[$this->patient_field], $_REQUEST['fax_number'], get_class($this), $_REQUEST['id']); if ($_REQUEST['attachment']) { $parts = explode('|', $_REQUEST['attachment']); $this_user->setFaxInQueue($output, $_r[$this->patient_field], $_REQUEST['fax_number'], $parts[0], $parts[1]); } } $display_buffer .= "<b>" . __("Refreshing") . "... </b>\n"; //$GLOBALS['refresh'] = $this->page_name."?". // "module=".urlencode($_REQUEST['module'])."&". // "type=".urlencode($_REQUEST['type'])."&". // "action=print&". // "faxstatus=".urlencode($output); $GLOBALS['__freemed']['close_on_load'] = true; break; // Handle actual printer // Handle actual printer case 'printer': if ($render) { $_p = CreateObject('PHP.PrinterWrapper'); $_p->PrintFile($_REQUEST['printer'], $render); unlink($render); } else { // DEBUG: //$display_buffer .= "<pre>\n". // $TeX->RenderDebug(). // "</pre>\n(You must disable this to print)"; //template_display(); $TeX->SetPrinter(CreateObject('PHP.PrinterWrapper'), $_REQUEST['printer']); // TODO: Handle direct PDF generation and return here $TeX->PrintTeX(1, !empty($this->print_template)); } $GLOBALS['__freemed']['close_on_load'] = true; break; default: print "print_method = " . $_pm . "<br/>\n"; break; } }
protected function mod_pre(&$data) { $id = $data['id']; $rec = $GLOBALS['sql']->get_link($this->table_name, $id); $filename = $this->GetLocalCachedFile($id); $s = CreateObject('org.freemedsoftware.api.Scheduler'); $data['date'] = $s->ImportDate($data['date']); // Catch multiple people using the same document if ($rec['ufffile'] == '') { trigger_error(__("Document file does not exist!")); } if ($data['flip'] == 1) { syslog(LOG_INFO, "flip"); $command = "./scripts/flip_djvu.sh \"{$filename}\""; system("{$command}"); $this->UpdateFileFromCachedFile($id); } if (!empty($data['faxback'])) { syslog(LOG_INFO, "faxback"); $this->faxback($data['id'], $data['faxback']); } if ($data['notify'] + 0 > 0) { syslog(LOG_INFO, "notify"); $msg = CreateObject('org.freemedsoftware.api.Messages'); $msg->send(array('patient' => $data['patient'], 'user' => $data['notify'], 'urgency' => 4, 'text' => __("Document received for patient") . " (" . $data['note'] . ")")); } // If we're removing the first page, do that now if ($data['withoutfirstpage']) { syslog(LOG_INFO, "remove 1st page"); $command = "/usr/bin/djvm -d " . escapeshellarg($filename) . " 1"; system("{$command}"); $this->UpdateFileFromCachedFile($id); } // Figure category / type $cat = $GLOBALS['sql']->get_link('documents_tc', $data['category']); if ($data['filedirectly']) { syslog(LOG_INFO, "directly"); // Insert new table query in unread $query = $GLOBALS['sql']->query($GLOBALS['sql']->insert_query('images', array("imagedt" => $data['date'], "imagepat" => $data['patient'], "imagetype" => $data['category'], "imagedesc" => $data['note'], "imagephy" => $data['physician'], "imagetext" => $data['text'], "imagereviewed" => 0, "user" => freemed::user_cache()->user_number))); $new_id = $GLOBALS['sql']->lastInsertID('images', 'id'); $new_filename = freemed::image_filename(freemed::secure_filename($data['patient']), $new_id, 'djvu', true); $query = $GLOBALS['sql']->update_query('images', array('imagefile' => $new_filename), array('id' => $new_id)); // Move actual file to new location $pds = CreateObject('org.freemedsoftware.core.PatientDataStore'); $pds->StoreFile($data['urfpatient'], "scanneddocuments", $new_id, file_get_contents($this->GetLocalCachedFile($id))); } else { // Insert new table query in unread $result = $GLOBALS['sql']->query($GLOBALS['sql']->insert_query('unreaddocuments', array("urfdate" => $data['date'], "urffilename" => $filename, "urffile" => file_get_contents($filename), "urfpatient" => $data['patient'], "urfphysician" => $data['physician'], "urftype" => $data['category'], "urfnote" => $data['note'], "user" => freemed::user_cache()->user_number))); } // Remove old entry $GLOBALS['sql']->query("DELETE FROM `" . $this->table_name . "` WHERE id='" . addslashes($data['id']) . "'"); //$new_id = $GLOBALS['sql']->lastInsertID( $this->table_name, 'id' ); $this->save_variables = $this->variables; unset($this->variables); }
protected function del_pre($id) { unlink(freemed::image_filename(freemed::secure_filename($patient), freemed::secure_filename($id), 'djvu')); }
public function GetFeed($feed = 'Security') { $myfeed = freemed::secure_filename($feed); $rss = CreateObject('org.freemedsoftware.core.MagpieRSS', join("\n", file("data/cache/rss.feed.{$myfeed}"))); $display_buffer .= "<div class=\"DataHead\">" . ($return['title'] = $rss->channel['title']); foreach ($rss->items as $item) { $return['feed'][] = array('link' => $item['link'], 'title' => $item['title'], 'date' => $item['dc']['date'], 'description' => $item['description']); } return $return; }
public function ReviewIntoRecord($id) { syslog(LOG_DEBUG, "ReviewIntoRecord {$id}"); $data = $GLOBALS['sql']->get_link($this->table_name, $id); $this_user = freemed::user_cache()->user_number; $filename = $this->GetLocalCachedFile($id); syslog(LOG_DEBUG, "user = this_user, filename = {$filename}"); // Document sanity check if ($data['id'] == 0) { syslog(LOG_INFO, "UnreadDocument| attempted to file document that doesn't exist ({$filename})"); return false; } // Extract type and category list($type, $cat) = explode('/', $data['urftype']); // Insert new table query in unread $query = $GLOBALS['sql']->insert_query('images', array("imagedt" => $data['urfdate'], "imagepat" => $data['urfpatient'], "imagetype" => $type, "imagecat" => $cat, "imagedesc" => $data['urfnote'], "imagephy" => $data['urfphysician'], "imagetext" => $data['urftext'], "imagereviewed" => $this_user, "user" => $this_user)); syslog(LOG_DEBUG, "query = {$query}"); $result = $GLOBALS['sql']->query($query); $new_id = $GLOBALS['sql']->lastInsertID('images', 'id'); $new_filename = freemed::image_filename(freemed::secure_filename($data['urfpatient']), $new_id, 'djvu', true); syslog(LOG_DEBUG, "insert id = {$new_id}, filename = {$new_filename}"); $query2 = $GLOBALS['sql']->update_query('images', array('imagefile' => $new_filename), array('id' => $new_id)); $result2 = $GLOBALS['sql']->query($query2); // Move actual file to new location $pds = CreateObject('org.freemedsoftware.core.PatientDataStore'); $pds->StoreFile($data['urfpatient'], "scanneddocuments", $new_id, file_get_contents($this->GetLocalCachedFile($id))); $q = "DELETE FROM " . $this->table_name . " WHERE id=" . $GLOBALS['sql']->quote($id); syslog(LOG_DEBUG, "q = {$q}"); $GLOBALS['sql']->query($q); return true; }
public static function store_image($patient_id = 0, $varname, $type = 0, $encoding = 'cjb2') { global ${$varname}; // Check for valid patient id if ($patient_id < 1) { return false; } // Determine extension $file_parts = explode(".", $_FILES[$varname]["name"]); $ext = $file_parts[count($file_parts) - 1]; // If there is no extension, die if (strlen($ext) < 3) { return false; } // Get temporary name $image = $_FILES[$varname]["tmp_name"]; // If temp name doesn't exist, return false if (empty($image)) { return false; } if (is_array($type)) { $id = $type[1]; $ext = 'id.djvu'; } else { $id = $type; $ext = 'djvu'; } // Create proper path $mkdir_command = 'mkdir -p ' . PHYSICAL_LOCATION . '/' . dirname(freemed::image_filename($patient_id, $id, $ext)); //print "mkdir_command = $mkdir_command<br/>\n"; $mkdir_output = `{$mkdir_command}`; //print $mkdir_output."<br/>\n"; // Process depending on switch (strtolower($ext)) { /* case "jpg": case "jpeg": // Simple JPEG handler: copy $name = freemed::image_filename( $patient_id, $id, $ext ); copy ($image, "./".$name); return $name; break; // end handle JPEGs */ default: // More complex: use imagemagick $name = freemed::image_filename($patient_id, $id, $ext); // Convert to PBM $command = "/usr/bin/convert " . freemed::secure_filename($image) . " " . PHYSICAL_LOCATION . "/" . freemed::image_filename($patient_id, $id, $ext . '.' . ($encoding == 'c44' ? 'jpg' : 'pbm')); //print "convert command = ".$command."<br/>\n"; $output = `{$command}`; //print "convert output = ".$output."<br/>\n"; // Convert to DJVU switch ($encoding) { case 'c44': $ee = '/usr/bin/c44'; break; case 'cjb2': default: $ee = '/usr/bin/cjb2'; break; } $command = $ee . " " . PHYSICAL_LOCATION . "/" . freemed::image_filename($patient_id, $id, $ext . '.' . ($encoding == 'c44' ? 'jpg' : 'pbm')) . " " . PHYSICAL_LOCATION . "/" . freemed::image_filename($patient_id, $id, $ext); //print "command = $command<br/>\n"; //print "<br/>".exec ($command)."<br/>\n"; $output = `{$command}`; //print "<br/>".`$command`."<br/>\n"; // Remove PBM unlink(PHYSICAL_LOCATION . '/' . freemed::image_filename($patient_id, $id, $ext . '.' . ($encoding == 'c44' ? 'jpg' : 'pbm'))); return $name; break; // end handle others } // end checking by extension }
die("cannot be called via web"); } ini_set('include_path', dirname(dirname(__FILE__)) . ':' . ini_get('include_path')); include_once 'lib/freemed.php'; print "Patient Data Store Import Tool\n"; print "(c) 2010 FreeMED Software Foundation\n\n"; // Loop through the scanned documents table print " - Getting all scanned documents ... "; $ds = $GLOBALS['sql']->queryAll("SELECT * FROM images;"); print "[done]\n"; print " - Removing any existing images ... "; $GLOBALS['sql']->query("DELETE FROM pds WHERE module = 'scanneddocuments';"); print "[done]\n"; print " - Looping through all scanned documents.\n"; foreach ($ds as $d) { $fn = PHYSICAL_LOCATION . "/" . freemed::image_filename(freemed::secure_filename($d['imagepat']), freemed::secure_filename($d['id']), 'djvu'); print " - Processing document id " . $d['id'] . " for patient id " . $d['imagepat'] . " ( filename = {$fn} ) ... "; if (!file_exists($fn)) { print "[FAILED, DOESN'T EXIST]\n"; } else { $GLOBALS['sql']->query("INSERT INTO pds ( id, patient, module, contents ) VALUES ( " . $GLOBALS['sql']->quote($d['id']) . ", " . $GLOBALS['sql']->quote($d['imagepat']) . ", " . $GLOBALS['sql']->quote("scanneddocuments") . ", " . $GLOBALS['sql']->quote(file_get_contents($fn)) . " );"); print "[done]\n"; } } // Loop through the photoid table print " - Getting all photo id ... "; $ds = $GLOBALS['sql']->queryAll("SELECT * FROM photoid;"); print "[done]\n"; print " - Removing any existing photoid ... "; $GLOBALS['sql']->query("DELETE FROM pds WHERE module = 'photographicidentification';"); print "[done]\n";