示例#1
0
 * @link    http://www.open-emr.org
 */
//SANITIZE ALL ESCAPES
$sanitize_all_escapes = true;
//
//STOP FAKE REGISTER GLOBALS
$fake_register_globals = false;
//
require_once dirname(__FILE__) . "/../../interface/globals.php";
require_once dirname(__FILE__) . "/../parse_patient_xml.php";
require_once dirname(__FILE__) . "/../classes/Document.class.php";
require_once dirname(__FILE__) . "/../classes/CouchDB.class.php";
if ($_REQUEST["ccr_ajax"] == "yes") {
    $doc_id = $_REQUEST["document_id"];
    $d = new Document($doc_id);
    $url = $d->get_url();
    $storagemethod = $d->get_storagemethod();
    $couch_docid = $d->get_couch_docid();
    $couch_revid = $d->get_couch_revid();
    if ($storagemethod == 1) {
        $couch = new CouchDB();
        $data = array($GLOBALS['couchdb_dbase'], $couch_docid);
        $resp = $couch->retrieve_doc($data);
        $content = $resp->data;
        if ($content == '' && $GLOBALS['couchdb_log'] == 1) {
            $log_content = date('Y-m-d H:i:s') . " ==> Retrieving document\r\n";
            $log_content = date('Y-m-d H:i:s') . " ==> URL: " . $url . "\r\n";
            $log_content .= date('Y-m-d H:i:s') . " ==> CouchDB Document Id: " . $couch_docid . "\r\n";
            $log_content .= date('Y-m-d H:i:s') . " ==> CouchDB Revision Id: " . $couch_revid . "\r\n";
            $log_content .= date('Y-m-d H:i:s') . " ==> Failed to fetch document content from CouchDB.\r\n";
            $log_content .= date('Y-m-d H:i:s') . " ==> Will try to download file from HardDisk if exists.\r\n\r\n";
示例#2
0
 function update_action_process($patient_id = "", $document_id)
 {
     if ($_POST['process'] != "true") {
         die("process is '" . $_POST['process'] . "', expected 'true'");
         return;
     }
     $docdate = $_POST['docdate'];
     $docname = $_POST['docname'];
     $issue_id = $_POST['issue_id'];
     if (is_numeric($document_id)) {
         $messages = '';
         $d = new Document($document_id);
         $file_name = $d->get_url_file();
         if ($docname != '' && $docname != $file_name) {
             $path = $d->get_url_filepath();
             $path = str_replace($file_name, "", $path);
             $new_url = $this->_rename_file($path . $docname);
             if (rename($d->get_url(), $new_url)) {
                 // check the "converted" file, and delete it if it exists. It will be regenerated when report is run
                 $url = preg_replace("|^(.*)://|", "", $d->get_url());
                 $convertedFile = substr(basename($url), 0, strrpos(basename($url), '.')) . '_converted.jpg';
                 $url = $GLOBALS['OE_SITE_DIR'] . '/documents/' . $patient_id . '/' . $convertedFile;
                 if (file_exists($url)) {
                     unlink($url);
                 }
                 $d->url = $new_url;
                 $d->persist();
                 $d->populate();
                 $messages .= xl('Document successfully renamed.') . "<br>";
             } else {
                 $messages .= xl('The file could not be succesfully renamed, this error is usually related to permissions problems on the storage system.') . "<br>";
             }
         }
         if (preg_match('/^\\d\\d\\d\\d-\\d+-\\d+$/', $docdate)) {
             $docdate = "'{$docdate}'";
         } else {
             $docdate = "NULL";
         }
         if (!is_numeric($issue_id)) {
             $issue_id = 0;
         }
         $sql = "UPDATE documents SET docdate = {$docdate}, " . "list_id = '{$issue_id}' " . "WHERE id = '{$document_id}'";
         $this->tree->_db->Execute($sql);
         $messages .= xl('Document date and issue updated successfully') . "<br>";
     }
     $this->_state = false;
     $this->assign("messages", $messages);
     return $this->view_action($patient_id, $document_id);
 }
示例#3
0
         printPatientTransactions($pid);
         echo "</div>";
     }
 } else {
     // Documents is an array of checkboxes whose values are document IDs.
     //
     if ($key == "documents") {
         echo "<hr />";
         echo "<div class='text documents'>";
         foreach ($val as $valkey => $valvalue) {
             $document_id = $valvalue;
             if (!is_numeric($document_id)) {
                 continue;
             }
             $d = new Document($document_id);
             $fname = basename($d->get_url());
             $couch_docid = $d->get_couch_docid();
             $couch_revid = $d->get_couch_revid();
             $extension = substr($fname, strrpos($fname, "."));
             echo "<h1>" . xl('Document') . " '" . $fname . "'</h1>";
             $notes = Note::notes_factory($d->get_id());
             if (!empty($notes)) {
                 echo "<table>";
             }
             foreach ($notes as $note) {
                 echo '<tr>';
                 echo '<td>' . xl('Note') . ' #' . $note->get_id() . '</td>';
                 echo '</tr>';
                 echo '<tr>';
                 echo '<td>' . xl('Date') . ': ' . oeFormatShortDate($note->get_date()) . '</td>';
                 echo '</tr>';
 /**
  * Outputs this item in HTML.  Can be overridden for descendants.
  **/
 public function toHTML($object)
 {
     $title = Document::get_title($object);
     $url = Document::get_url($object);
     $html = "<a href='{$url}'>{$title}</a>";
     return $html;
 }
示例#5
0
function display_draw_image($zone, $encounter, $pid)
{
    global $form_folder;
    global $web_root;
    global $PDF_OUTPUT;
    $side = "OU";
    $base_name = $pid . "_" . $encounter . "_" . $side . "_" . $zone . "_VIEW";
    $filename = $base_name . ".jpg";
    $sql = "SELECT * from documents where documents.url like '%" . $filename . "'";
    $doc = sqlQuery($sql);
    $document_id = $doc['id'];
    if ($document_id > '1' && is_numeric($document_id)) {
        $d = new Document($document_id);
        $fname = basename($d->get_url());
        $couch_docid = $d->get_couch_docid();
        $couch_revid = $d->get_couch_revid();
        $extension = substr($fname, strrpos($fname, "."));
        $notes = Note::notes_factory($d->get_id());
        if (!empty($notes)) {
            echo "<table>";
        }
        foreach ($notes as $note) {
            echo '<tr>';
            echo '<td>' . xlt('Note') . ' #' . $note->get_id() . '</td>';
            echo '</tr>';
            echo '<tr>';
            echo '<td>' . xlt('Date') . ': ' . oeFormatShortDate($note->get_date()) . '</td>';
            echo '</tr>';
            echo '<tr>';
            echo '<td>' . $note->get_note() . '<br /><br /></td>';
            echo '</tr>';
        }
        if (!empty($notes)) {
            echo "</table>";
        }
        $url_file = $d->get_url_filepath();
        if ($couch_docid && $couch_revid) {
            $url_file = $d->get_couch_url($pid, $encounter);
        }
        // Collect filename and path
        $from_all = explode("/", $url_file);
        $from_filename = array_pop($from_all);
        $from_pathname_array = array();
        for ($i = 0; $i < $d->get_path_depth(); $i++) {
            $from_pathname_array[] = array_pop($from_all);
        }
        $from_pathname_array = array_reverse($from_pathname_array);
        $from_pathname = implode("/", $from_pathname_array);
        if ($couch_docid && $couch_revid) {
            $from_file = $GLOBALS['OE_SITE_DIR'] . '/documents/temp/' . $from_filename;
            $to_file = substr($from_file, 0, strrpos($from_file, '.')) . '_converted.jpg';
        } else {
            $from_file = $GLOBALS["fileroot"] . "/sites/" . $_SESSION['site_id'] . '/documents/' . $from_pathname . '/' . $from_filename;
            $to_file = substr($from_file, 0, strrpos($from_file, '.')) . '_converted.jpg';
        }
        //               if ($extension == ".png" || $extension == ".jpg" || $extension == ".jpeg" || $extension == ".gif") {
        if ($PDF_OUTPUT) {
            echo "<img src='" . $from_file . "' style='width:220px;height:120px;'>";
        } else {
            $filetoshow = $GLOBALS['webroot'] . "/controller.php?document&retrieve&patient_id={$pid}&document_id=" . $doc['id'] . "&as_file=false&blahblah=" . rand();
            echo "<img src='" . $filetoshow . "' style='width:220px;height:120px;'>";
        }
    } else {
        $filetoshow = "../../forms/" . $form_folder . "/images/" . $side . "_" . $zone . "_BASE.jpg";
        if ($PDF_OUTPUT) {
            $filetoshow = $GLOBALS["webroot"] . "/interface/forms/" . $form_folder . "/images/" . $side . "_" . $zone . "_BASE.jpg";
        }
        // uncomment to show base image, no touch up by user.
        // echo "<img src='". $filetoshow."' style='width:220px;height:120px;'>";
    }
    return;
}
示例#6
0
 function retrieve_action($patient_id = "", $document_id, $as_file = true, $original_file = true)
 {
     //controller function ruins booleans, so need to manually re-convert to booleans
     if ($as_file == "true") {
         $as_file = true;
     } else {
         if ($as_file == "false") {
             $as_file = false;
         }
     }
     if ($original_file == "true") {
         $original_file = true;
     } else {
         if ($original_file == "false") {
             $original_file = false;
         }
     }
     $d = new Document($document_id);
     $url = $d->get_url();
     //strip url of protocol handler
     $url = preg_replace("|^(.*)://|", "", $url);
     //change full path to current webroot.  this is for documents that may have
     //been moved from a different filesystem and the full path in the database
     //is not current.  this is also for documents that may of been moved to
     //different patients
     // NOTE that $from_filename and basename($url) are the same thing
     $from_all = explode("/", $url);
     $from_filename = array_pop($from_all);
     $from_patientid = array_pop($from_all);
     $temp_url = $GLOBALS["fileroot"] . '/documents/' . $from_patientid . '/' . $from_filename;
     if (file_exists($temp_url)) {
         $url = $temp_url;
     }
     if (!file_exists($url)) {
         echo xl('The requested document is not present at the expected location on the filesystem or there are not sufficient permissions to access it.', '', '', ' ') . $url;
     } else {
         if ($original_file) {
             //normal case when serving the file referenced in database
             header("Pragma: public");
             header("Expires: 0");
             header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
             header("Content-Disposition: " . ($as_file ? "attachment" : "inline") . "; filename=\"" . basename($d->get_url()) . "\"");
             header("Content-Type: " . $d->get_mimetype());
             header("Content-Length: " . $d->get_size());
             $f = fopen($url, "r");
             fpassthru($f);
             exit;
         } else {
             //special case when retrieving a document that has been converted to a jpg and not directly referenced in database
             $convertedFile = substr(basename($url), 0, strrpos(basename($url), '.')) . '_converted.jpg';
             $url = $GLOBALS["fileroot"] . '/documents/' . $from_patientid . '/' . $convertedFile;
             header("Pragma: public");
             header("Expires: 0");
             header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
             header("Content-Disposition: " . ($as_file ? "attachment" : "inline") . "; filename=\"" . basename($url) . "\"");
             header("Content-Type: image/jpeg");
             header("Content-Length: " . filesize($url));
             $f = fopen($url, "r");
             fpassthru($f);
             exit;
         }
     }
 }