Exemple #1
0
 function fax_widget($varname, $id)
 {
     global $sql, ${$varname};
     $r = $GLOBALS['sql']->get_link($this->table_name, $id);
     $p = $GLOBALS['sql']->get_link('patient', $r[$this->patient_field]);
     $pharmacy = $GLOBALS['sql']->get_link('pharmacy', $p['ptpharmacy']);
     ${$varname} = $pharmacy['phfax'];
     return module_function('pharmacymaintenance', 'widget', array($varname, false, 'phfax'));
 }
Exemple #2
0
 public function mod($data, $blockedACOs = NULL, $allowedACOs = NULL)
 {
     freemed::acl_enforce('admin', 'write');
     if (is_array($data)) {
         if (!$data['id']) {
             return false;
         }
     } elseif (is_object($data)) {
         if (!$data->id) {
             return false;
         }
     } else {
         return false;
     }
     $ourdata = (array) $data;
     // Protect admin user
     if ($ourdata['id'] + 0 == 1) {
         return false;
     }
     $tempVariables = $this->variables;
     if (!$data['userpassword']) {
         // remove password from variables if no need to change the password
         unset($tempVariables[1]);
     }
     $this->mod_pre($ourdata);
     $GLOBALS['sql']->load_data($ourdata);
     $result = $GLOBALS['sql']->query($GLOBALS['sql']->update_query('user', $tempVariables, array("id" => $data['id'])));
     if ($data['useracl']) {
         if (!is_array($data['useracl'])) {
             $data['useracl'] = explode(",", $data['useracl']);
         }
     } else {
         $data['useracl'] = array($data['useracl']);
     }
     // Create user ACL object If not already exists in ACL tables
     module_function('ACL', 'UserAdd', array($data['id']));
     if (is_array($data['useracl'])) {
         $groups = module_function('ACL', 'UserGroups');
         foreach ($groups as $group) {
             $found = false;
             foreach ($data['useracl'] as $acl_id) {
                 if ($group[1] == $acl_id) {
                     $found = true;
                 }
             }
             $inThisGroup = module_function('ACL', 'UserInGroup', array($data['id'], $group[1]));
             if ($found && !$inThisGroup) {
                 // Need to add
                 $o = module_function('ACL', 'AddUserToGroup', array($data['id'], $group[1]));
             }
             if (!$found && $inThisGroup) {
                 // Need to remove
                 $abc = $abc . ':rm:';
                 $o = module_function('ACL', 'RemoveUserFromGroup', array($data['id'], $group[1]));
             }
         }
     }
     // ACL routine for adding all blockedACOs
     if ($blockedACOs) {
         module_function('ACL', 'DelBlockedACOs', $data['id']);
         $blockedACOsSuccess = module_function('ACL', 'AddBlockedACOs', array($data['id'], $blockedACOs));
     } else {
         //else remove blocked permission if exists
         module_function('ACL', 'DelBlockedACOs', $data['id']);
     }
     // ACL routine for adding all allowedACOs
     if ($allowedACOs) {
         module_function('ACL', 'DelAllowedACOs', $data['id']);
         $allowedACOsSuccess = module_function('ACL', 'AddAllowedACOs', array($data['id'], $allowedACOs));
     } else {
         //else remove blocked permission if exists
         module_function('ACL', 'DelAllowedACOs', $data['id']);
     }
     return $result ? true : false;
 }
Exemple #3
0
 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;
     }
 }
 public function PrintToBrowser($items)
 {
     foreach ($items as $i) {
         $k[] = (int) $i;
     }
     $q = "SELECT p.patient AS patient, p.module AS module, p.oid AS oid, p.annotation AS annotation, p.summary AS summary, p.stamp AS stamp, DATE_FORMAT(p.stamp, '%m/%d/%Y') AS date_mdy, m.module_name AS type, m.module_class AS module_namespace, p.locked AS locked, p.id AS id FROM patient_emr p LEFT OUTER JOIN modules m ON m.module_table = p.module WHERE p.id IN ( " . join(',', $k) . " )";
     $r = $GLOBALS['sql']->queryAll($q);
     // Handle differently depending on single or multiple
     if (count($items) < 2) {
         // Single render
         Header("Content-type: application/x-pdf");
         Header("Content-Disposition: inline; filename=\"" . mktime() . ".pdf\"");
         $thisFile = module_function($r[0]['module_namespace'], 'RenderToPDF', array($r[0]['oid']));
         print file_get_contents($thisFile);
         @unlink($thisFile);
     } else {
         // Multiples, use composite object
         $c = CreateObject('org.freemedsoftware.core.MultiplePDF');
         foreach ($r as $o) {
             $thisFile = module_function($o['module_namespace'], 'RenderToPDF', array($o['oid']));
             $comp->Add($thisFile);
             $f[] = $thisFile;
         }
         Header("Content-type: application/x-pdf");
         Header("Content-Disposition: inline; filename=\"" . mktime() . ".pdf\"");
         print file_get_contents($comp->Composite());
         @unlink($comp->Composite());
         foreach ($f as $fn) {
             @unlink($fn);
         }
     }
 }
 public function MoveEmrAttachments($patientFrom, $patientTo, $attachments)
 {
     // Go through all records, make changes
     if (!is_array($attachments)) {
         return false;
     }
     $success = true;
     foreach ($attachments as $attachment) {
         // Resolve original id and table
         $resolve = $GLOBALS['sql']->queryRow("SELECT m.module_table AS 'table', m.module_class AS 'class', p.oid AS oid FROM patient_emr p LEFT OUTER JOIN modules m ON m.module_table = p.module WHERE p.patient = " . $GLOBALS['sql']->quote($patient) . " AND p.id = " . (int) $patientFrom);
         // Get patient field from meta data
         $patient_field = freemed::module_get_meta($resolve['class'], 'patient_field');
         // Move actual record
         $result = $GLOBALS['sql']->query("UPDATE " . $resolve['table'] . " SET {$patient_field} = " . $GLOBALS['sql']->quote((int) $patientTo) . " WHERE id = " . $GLOBALS['sql']->quote((int) $resolve['oid']));
         $success &= (bool) $result;
         // Move any annotations, if they exist
         $result = $GLOBALS['sql']->query("UPDATE annotations SET apatient = " . $GLOBALS['sql']->quote((int) $patientTo) . " WHERE apatient = " . $GLOBALS['sql']->quote((int) $patientFrom) . " AND atable = " . $GLOBALS['sql']->quote($resolve['table']) . " AND aid = " . $GLOBALS['sql']->quote((int) $resolve['oid']));
         $success &= (bool) $result;
         // Anything additional
         module_function($resolve['class'], 'additional_move', array($resolve['oid'], $patientFrom, $patientTo));
     }
     return $success;
 }
Exemple #6
0
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
if (!$_SERVER['argc']) {
    die("cannot be called via web");
}
ini_set('include_path', dirname(dirname(__FILE__)) . ':' . ini_get('include_path'));
include_once 'lib/freemed.php';
$cache = freemed::module_cache();
print "ACL Rebuild Tool\n";
print "(c) 2006 FreeMED Software Foundation\n\n";
$tables = array('acl_acl', 'acl_acl_sections', 'acl_acl_seq', 'acl_aco', 'acl_aco_map', 'acl_aco_sections', 'acl_aro', 'acl_aro_groups', 'acl_aro_groups_map', 'acl_aro_map', 'acl_aro_sections', 'acl_aro_seq', 'acl_axo', 'acl_axo_groups', 'acl_axo_groups_map', 'acl_axo_map', 'acl_axo_sections', 'acl_axo_seq', 'acl_groups_aro_map', 'acl_groups_axo_map', 'acl_phpgacl');
print " - Dropping tables ... ";
foreach ($tables as $table) {
    $GLOBALS['sql']->query('DROP TABLE ' . $table);
}
print "[done]\n";
// Reinitialize db
print " - Reinitializing ACL tables ... ";
$GLOBALS['sql']->query("CREATE TABLE IF NOT EXISTS acl ( id SERIAL );");
module_function('acl', '_setup', array());
print "[done]\n";
// Reimport users
print " - Reimporting users ... \n";
$users = $GLOBALS['sql']->queryCol("SELECT id FROM user");
foreach ($users as $u) {
    print " -- Importing user #{$u} ... ";
    module_function('acl', 'UserAdd', array($u));
    print "done.\n";
}
 function fax_widget($varname, $id)
 {
     global ${$varname};
     $r = $GLOBALS['sql']->get_link($this->table_name, $id);
     $phy = $GLOBALS['sql']->get_link('physician', $r['imagephy']);
     ${$varname} = $phy['phyfaxa'];
     return module_function('faxcontacts', 'widget', array($varname, false, 'phyfaxa'));
 }
Exemple #8
0
 function ProcessData($data)
 {
     $cache = freemed::module_cache();
     // Handle "module:" prefix
     if (substr($data['table'], 0, 7) == 'object:') {
         $objectname = substr($data['table'], -(strlen($data['table']) - 7));
         $params = explode(':', $data['field']);
         if ($params[0] == 'patient') {
             $obj = CreateObject('org.freemedsoftware.core.' . $objectname, $this->patient->local_record[$params[1]]);
             $method = $params[2] ? $params[2] : 'to_text';
             $raw = $obj->{${method}}();
         } else {
             syslog(LOG_INFO, get_class($this) . "| could not process {$data['table']}, {$data['field']}");
             return '';
         }
     } elseif (substr($data['table'], 0, 7) == 'module:') {
         $modulename = substr($data['table'], -(strlen($data['table']) - 7));
         // Deal with method: prefix on data
         if (substr($data['field'], 0, 7) == 'method:') {
             $params = explode(':', $data['field']);
             $raw = module_function($modulename, $params[1], array($params[2] ? $params[2] : $this->patient->id));
         } else {
             // Load information from module
             include_once resolve_module($modulename);
             $m = new $modulename();
             // Run SQL query
             $query = "SELECT *" . (count($m->summary_query) > 0 ? "," . join(",", $m->summary_query) . " " : " ") . "FROM " . $m->table_name . " " . "WHERE " . $m->patient_field . "='" . addslashes($this->patient->id) . "' " . ($m->summary_conditional ? 'AND ' . $m->summary_conditional . ' ' : '') . "ORDER BY id DESC LIMIT 1";
             $result = $GLOBALS['sql']->query($query);
             if ($GLOBALS['sql']->num_rows($result) != 1) {
                 syslog(LOG_INFO, get_class($this) . "| could not retrieve rows for {$data['table']}, {$data['field']}");
                 return "";
             }
             $r = $GLOBALS['sql']->fetch_array($result);
             return $r[$data['field']];
         }
     } else {
         // Deal with straight abbreviations for data
         switch ($data['table']) {
             case 'patient':
                 if (strpos($data['field'], ':') === false) {
                     $raw = $this->patient->local_record[$data['field']];
                 } else {
                     list($desc, $field) = explode(':', $data['field']);
                     switch ($desc) {
                         case 'method':
                             $raw = $this->patient->{${field}}();
                             break;
                             // end method
                         // end method
                         default:
                             syslog(LOG_INFO, get_class($this) . "| could not figure out syntax for {$data['table']}, {$data['field']}");
                             $raw = "";
                             break;
                             // end default
                     }
                     // end switch desc
                 }
                 break;
             case 'control':
                 $raw = $this->FetchDataElement($data['field']);
                 break;
             case 'static':
                 $raw = $data['field'];
                 break;
             default:
                 break;
         }
         // end switch
     }
     // Deal with output formatting
     switch ($data['type']) {
         case 'link':
             if (!$data['value']) {
                 syslog(LOG_INFO, get_class($this) . "| could not process {$data['table']}, {$data['field']}, {$data['value']}");
                 return '';
             }
             if (strpos($data['value'], ':') !== false) {
                 $params = explode(':', $data['value']);
                 return module_function($params[0], 'get_field', array($raw, $params[1]));
             } else {
                 return module_function($data['value'], 'to_text', array($raw));
             }
             break;
         case 'ssn':
             return substr($raw, 0, 3) . '-' . substr($raw, 3, 2) . '-' . substr($raw, 5, 4);
             break;
         case 'conditional':
             // Handle "static" type
             if ($data['table'] == 'static') {
                 return 'X';
             }
             // Handle "multiple" type
             if ($data['table'] == 'control') {
                 if (!isset($this->controls)) {
                     $this->controls = $this->GetControls();
                 }
                 if ($this->controls[$data['field']]['type'] == 'multiple') {
                     foreach (explode(',', $raw) as $value) {
                         if ($data['value'] == $value) {
                             return 'X';
                         }
                     }
                     return '';
                 }
             }
             // Handle everything else
             if ($data['value'] == $raw) {
                 return 'X';
             } else {
                 return '';
             }
             break;
         case 'phone':
             return freemed::phone_display($raw);
             break;
         case 'date':
             if (!$raw) {
                 return '';
             }
             $_date = explode('-', $raw);
             switch (freemed::config_value('dtfmt')) {
                 case 'ymd':
                     return $raw;
                     break;
                 case 'mdy':
                 default:
                     return "{$_date[1]}/{$_date[2]}/{$_date[0]}";
                     break;
             }
             // Should never get here
             return $raw;
             break;
         case 'string':
         default:
             return $raw;
             break;
     }
     // end data type
 }
Exemple #9
0
<?php 
// $Id$
//
// Authors:
//      Jeff Buchbinder <*****@*****.**>
//
// FreeMED Electronic Medical Record and Practice Management System
// Copyright (C) 1999-2012 FreeMED Software Foundation
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
include_once dirname(__FILE__) . '/bootstrap.test.php';
if ($argc < 3) {
    die("syntax: {$argv['0']} moduleclass id [tex|pdf]\n");
}
$module = $argv[1];
$id = $argv[2];
$modules = freemed::module_cache();
print module_function($module, 'RenderToPDF', array($id, strtolower($argv[3]) == 'tex'));
Exemple #10
0
 public function acl_patient_add($pid, $current_user = true)
 {
     global $this_user;
     // Create ACL manipulation class (cached, of course)
     $acl = $this->acl_object();
     // Create an AXO object
     $axo = $acl->add_object('patient', 'Patient ' . $pid, 'patient_' . $pid, $pid, 0, 'AXO');
     //print "made new object with axo = ".$axo."<br/>\n";
     // If this fails, we die out here
     if (!$axo) {
         trigger_error(__("Failed to create patient AXO ACL control object."), E_ERROR);
     }
     // Create user object if it doesn't exist yet
     $this_user = freemed::user_cache();
     $_pat = $GLOBALS['sql']->get_link('patient', $pid);
     // Get ptpcp, ptphy{1,2,3,4}, ptdoc and add their respective
     // user numbers to the ACL.
     $to_add = array($this->get_user_from_phy($_pat['ptpcp']), $this->get_user_from_phy($_pat['ptdoc']), $this->get_user_from_phy($_pat['ptphy1']), $this->get_user_from_phy($_pat['ptphy2']), $this->get_user_from_phy($_pat['ptphy3']), $this->get_user_from_phy($_pat['ptphy4']));
     if ($current_user) {
         $to_add[] = $this_user->user_number;
     }
     // Make sure there are no zeros
     foreach ($to_add as $v) {
         if ($v) {
             $u[$v] = $v;
         }
     }
     foreach ($u as $v) {
         $users[] = 'user_' . $v;
     }
     // This is a *nasty* hack, but otherwise we loop forever.
     //include_once(dirname(__FILE__).'/patient_acl.emr.module.php');
     // Add the current user to have access
     //print "access for"; print_r($users); print "<br/>\n";
     module_function('patientacl', 'add_acl', array($pid, array('add', 'view', 'modify', 'delete'), $users, $this->acl_object()));
     // Send back the appropriate ACL id (AXO)
     return $axo;
 }
 function RuleInterface($type)
 {
     switch ($type) {
         case 'if':
             $if[] = array('procpos', array('=', '!='), module_function('FacilityModule', 'widget', array('procpos')), __("Facility"));
             $if[] = array('proccpt', array('=', '!='), module_function('CptMaintenance', 'widget', array('proccpt')), __("CPT Code"));
             $if[] = array('proccptmod', array('=', '!='), module_function('CptModifiersMaintenance', 'widget', array('proccptmod')), __("CPT Modifier"));
             $if[] = array('proccptmod', array('=', '!='), module_function('CptModifiersMaintenance', 'widget', array('proccptmod2')), __("CPT Modifier") . " 2");
             $if[] = array('proccptmod', array('=', '!='), module_function('CptModifiersMaintenance', 'widget', array('proccptmod3')), __("CPT Modifier") . " 3");
             return $if;
             break;
         case 'then':
             $then[] = array('proccharges', array('='), html_form::text_widget('proccharges', 20), __("Charges"));
             $then[] = array('proctosoverride', array('='), module_function('TypeOfServiceMaintenance', 'widget', array('proctosoverride')), __("Type of Service"));
             return $then;
             break;
     }
 }
Exemple #12
0
 public static function handler_breakpoint($name, $params = NULL)
 {
     $handlers = freemed::module_handler($name);
     if (is_array($handlers)) {
         foreach ($handlers as $class => $handler) {
             T_textdomain(strtolower($class));
             if ($params != NULL) {
                 $reply[] = module_function($class, $handler, $params);
             } else {
                 $reply[] = module_function($class, $handler);
             }
         }
         return $reply;
     }
     return false;
 }
Exemple #13
0
 public function GetLanguages()
 {
     $m = module_function('i18nlanguages', 'GetAll', array());
     foreach ($m as $r) {
         $res[] = array($r['language'], $r['abbrev']);
     }
     return $res;
 }
 public function GenerateWorkList($provider, $date = '', $show = 20, $limit = 10)
 {
     static $lookup_cache, $s;
     $return = array();
     if (!is_object($s)) {
         $s = CreateObject('org.freemedsoftware.api.Scheduler');
     }
     if (!$date) {
         $_date = date('Y-m-d');
     } else {
         $_date = $s->ImportDate($date);
     }
     // Load lookup table
     if (!isset($lookup_cache)) {
         $lookup_cache = $GLOBALS['sql']->queryAll("SELECT * FROM schedulerstatustype");
     }
     foreach ($lookup_cache as $r) {
         $lookup[$r['id']] = $r['scolor'];
         $name_lookup[$r['id']] = $r['sname'];
         $fullname_lookup[$r['id']] = $r['sdescrip'];
         $age_lookup[$r['id']] = $r['sage'];
     }
     unset($r);
     $pobj = CreateObject('org.freemedsoftware.core.Physician', $provider);
     // Needs improvement. Needs to count ONLY dates after the current date
     $add_sql = "s.caldateof='" . addslashes($_date) . "' AND";
     if ($date == '') {
         $query = "SELECT caldateof, COUNT(*) AS count FROM scheduler WHERE calphysician='" . addslashes($provider) . "' AND calstatus != 'cancelled' AND (DATEDIFF(caldateof,NOW())>= 0) GROUP BY caldateof LIMIT " . $limit . ";";
         $q = $GLOBALS['sql']->queryAll($query);
         if (count($q) >= 1) {
             $add_sql = "(";
             foreach ($q as $r) {
                 $sum += $r['count'];
                 if ($sum < $show) {
                     $add_sql .= "caldateof='" . $r['caldateof'] . "' OR ";
                 } else {
                     break;
                 }
             }
             $add_sql = substr($add_sql, 0, strlen($add_sql) - 4) . ") AND ";
         }
     }
     $query = "SELECT s.id AS id, s.calpatient AS s_patient_id,s.caltype as appointment_type, CASE s.caltype WHEN 'temp' THEN CONCAT( '[!] ', ci.cilname, ', ', ci.cifname, ' (', ci.cicomplaint, ')' ) WHEN 'group' THEN CONCAT( cg.groupname, ' (', cg.grouplength, ' members)') ELSE CONCAT(p.ptlname, ', ', p.ptfname, IF(LENGTH(p.ptmname)>0,CONCAT(' ',p.ptmname),''), IF(LENGTH(p.ptsuffix)>0,CONCAT(' ',p.ptsuffix),''), ' (', p.ptid, ')') END AS s_patient, s.calprenote AS s_note, s.calhour AS s_hour, s.calminute AS s_minute, s.calduration AS s_duration, s.caldateof AS s_date, CONCAT(phy.phyfname, ' ', phy.phylname) AS s_provider FROM scheduler s LEFT OUTER JOIN patient p ON p.id=s.calpatient LEFT OUTER JOIN physician phy ON phy.id=s.calphysician LEFT OUTER JOIN callin ci ON s.calpatient=ci.id LEFT OUTER JOIN calgroup cg ON s.calpatient=cg.id WHERE " . $add_sql . " s.calphysician='" . addslashes($provider) . "' AND s.calstatus != 'cancelled' ORDER BY s_hour, s_minute";
     $q = $GLOBALS['sql']->queryAll($query);
     foreach ($q as $r) {
         $current_status = module_function('schedulerpatientstatus', 'getPatientStatus', array($r['s_patient_id'], $r['id']));
         $expired = false;
         if ($age_lookup[$current_status[0]] > 0 and $current_status[1] >= $age_lookup[$current_status[0]]) {
             syslog(LOG_INFO, "age_lookup ( {$current_status['0']} ) = " . $age_lookup[$current_status[0]] . ", current_status[1] = {$current_status['1']}");
             $expired = true;
         }
         $return[] = array('id' => $r['id'], 'note' => $r['s_note'], 'status_name' => $name_lookup[$current_status[0]], 'status_fullname' => $fullname_lookup[$current_status[0]], 'status_color' => $current_status ? $lookup[$current_status[0]] : "", 'provider' => $r['s_provider'], 'patient' => $r['s_patient_id'], 'patient_name' => $r['s_patient'], 'appointment_type' => $r['appointment_type'], 'hour' => $r['s_hour'], 'minute' => sprintf('%02d', $r['s_minute']), 'time' => $r['s_hour'] . ':' . sprintf('%02d', $r['s_minute']), 'date' => date("d/m", strtotime($r['s_date'])), 'expired' => $expired ? true : false);
     }
     // end get array
     if (count($return) < 1) {
         return array(array());
     }
     return $return;
 }
Exemple #15
0
 public function CreateForm($report)
 {
     $form = CreateObject('net.php.pear.HTML_QuickForm', 'form', 'get');
     freemed::quickform_i18n(&$form);
     $form->addElement('hidden', 'report', $report);
     $form->addElement('hidden', 'action', 'view');
     $form->setDefaults(array('action' => 'view'));
     // Make sure module cache is loaded, just in case
     $_cache = freemed::module_cache();
     // Get meta-information from the report
     $this->api->setReportPath(FREEMED_DIR . '/data/report/' . $report . '.report');
     $report = $this->api->getReport();
     // Display the header if one exists
     if ($report['Report']['Properties']['Description']) {
         $form->addElement('header', '', $report['Report']['Properties']['Description']);
     }
     $merged = $this->DetermineMergedFormat($report);
     //if (!is_array($report['Report']['Parameters'])) { return NULL; }
     foreach ($report['Report']['Parameters'] as $k => $v) {
         if ($k == 'module') {
             next;
         }
         list($desc, $type, $detail) = explode(':', $v['value']);
         switch ($type) {
             case 'date':
                 $form->addElement('static', $k, $desc, fm_date_entry($k));
                 break;
                 // date
             // date
             case 'module':
                 $form->addElement('static', $k, $desc, module_function($detail, 'widget', $k));
                 break;
                 // module
             // module
             case 'select':
                 $form->addElement('select', $k, $desc, explode(',', $detail));
                 break;
                 // select
             // select
             case 'text':
                 $form->addElement('text', $k, $desc);
                 break;
                 // text
             // text
             default:
                 break;
         }
     }
     // Show format selection
     if (!$merged) {
         $form->addElement('select', 'format', __("Report Format"), array('csv' => 'CSV', 'html' => 'HTML', 'pdf' => 'PDF', 'ps' => 'Postscript', 'txt' => 'Plain Text'));
     } else {
         $form->addElement('select', 'format', __("Report Format"), array('pdf' => 'PDF'));
     }
     $submit_group[] =& HTML_QuickForm::createElement('submit', 'submit_action', __("Generate"));
     $submit_group[] =& HTML_QuickForm::createElement('submit', 'submit_action', __("Cancel"));
     $form->addGroup($submit_group, null, null, '&nbsp;');
     return $form;
 }
Exemple #16
0
 function control_module($action, $data)
 {
     if ($action == 'serialize') {
         return $_REQUEST['variable_' . $data['variable']];
     } elseif ($action == 'widget') {
         if (!$_REQUEST['variable_' . $data['variable']]) {
             $GLOBALS['variable_' . $data['variable']] = $_REQUEST['variable_' . $data['variable']] = $data['default'];
         }
         return module_function($data['options'], 'widget', array('variable_' . $data['variable']));
     }
 }