Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 protected function del_pre($id)
 {
     unlink(freemed::image_filename(freemed::secure_filename($patient), freemed::secure_filename($id), 'djvu'));
 }
Ejemplo n.º 3
0
 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;
 }
 protected function print_override($id)
 {
     // Create djvu object
     $rec = $GLOBALS['sql']->get_link($this->table_name, $id);
     $filename = freemed::image_filename($rec[$this->patient_field], $id, 'djvu');
     $d = CreateObject('org.freemedsoftware.core.Djvu', $filename);
     return $d->ToPDF(true);
 }
Ejemplo n.º 5
0
Archivo: API.php Proyecto: rrsc/freemed
 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
 }
Ejemplo n.º 6
0
    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";