示例#1
0
 function _update()
 {
     $version = freemed::module_version($this->MODULE_NAME);
     /* 
     	// Example of how to upgrade with ALTER TABLE
     	// Successive instances change the structure of the table
     	// into whatever its current version is, without having
     	// to reload the table at all. This pulls in all of the
     	// changes a version at a time. (You can probably use
     	// REMOVE COLUMN as well, but I'm steering away for now.)
     
     if (!version_check($version, '0.1.0')) {
     	$sql->query('ALTER TABLE '.$this->table_name.' '.
     		'ADD COLUMN ptglucose INT UNSIGNED AFTER id');
     }
     if (!version_check($version, '0.1.1')) {
     	$sql->query('ALTER TABLE '.$this->table_name.' '.
     		'ADD COLUMN somedescrip TEXT AFTER ptglucose');
     }
     if (!version_check($version, '0.1.3')) {
     	$sql->query('ALTER TABLE '.$this->table_name.' '.
     		'ADD COLUMN fakefield AFTER ptglucose');
     }
     */
 }
示例#2
0
 function _update()
 {
     $version = freemed::module_version($this->MODULE_NAME);
     // Version 0.2
     //
     //	Migrated to separate table
     //
     if (!version_check($version, '0.2')) {
         // Create table
         $GLOBALS['sql']->query($GLOBALS['sql']->create_table_query($this->table_name, $this->table_definition, array('id')));
         // Migrate old entries
         $q = $GLOBALS['sql']->queryAll('SELECT ptproblems,id FROM patient WHERE LENGTH(ptproblems) > 3');
         foreach ($q as $r) {
             $e = sql_expand($r['ptproblems']);
             if (!is_array($e)) {
                 $e = array($e);
             }
             foreach ($e as $a) {
                 $GLOBALS['sql']->query($GLOBALS['sql']->insert_query($this->table_name, array('ppatient' => $r['id'], 'problem' => $a)));
                 // end query
             }
             // end foreach $e
         }
         // end while
     }
 }
 public function action()
 {
     // Load dashboard components
     $components = freemed::module_handler('Dashboard');
     $this->smarty->assign('COMPONENTS', $components);
     $this->load('org.freemedsoftware.ui.dashboard');
 }
示例#4
0
 function MainMenuAppointments()
 {
     if (!freemed::acl('schedule', 'view')) {
         return false;
     }
     // Decide if this user is a physician or not...
     if (!is_object($GLOBALS['this_user'])) {
         $GLOBALS['this_user'] = CreateObject('org.freemedsoftware.core.User');
     }
     if ($GLOBALS['this_user']->isPhysician()) {
         // If physician, give links to daily and weekly
         // schedules, as well as a total of appointments
         // Get day that is one week from today
         $begin_date = date("Y-m-d");
         $end_date = $begin_date;
         for ($day = 1; $day < 7; $day++) {
             $end_date = freemed_get_date_next($end_date);
         }
         // Figure out appointments for today
         $day_count = $GLOBALS['sql']->queryOne("SELECT COUNT(*) AS day_count FROM scheduler WHERE " . "caldateof='" . $begin_date . "' AND " . "calphysician='" . $GLOBALS['this_user']->getPhysician() . "'");
         // Figure out appointments for this week
         $week_count = $GLOBALS['sql']->queryOne("SELECT COUNT(*) AS week_count FROM scheduler WHERE " . "caldateof >= '" . $begin_date . "' AND " . "caldateof <= '" . $end_date . "' AND " . "calphysician='" . $GLOBALS['this_user']->getPhysician() . "'");
         return array(__("Patient Scheduler"), sprintf(__("You have %s%d appointment(s) today%s and %s%d appointment(s) this week%s."), "<a href=\"physician_day_view.php?physician=" . urlencode($GLOBALS['this_user']->getPhysician()) . "\">", $day_count, "</a>", "<a href=\"physician_week_view.php?physician=" . urlencode($GLOBALS['this_user']->getPhysician()) . "\">", $week_count, "</a>"), "img/calendar_icon.png");
     } else {
         // If not a physician, give number of appointments
         // for the current facility if there is one
         $day_count = $GLOBALS['sql']->query("SELECT COUNT(*) AS day_count FROM scheduler WHERE " . "caldateof = '" . date('Y-m-d') . "' " . (HTTP_Session2::get('default_facility') ? "AND calfacility='" . addslashes(HTTP_Session2::get('default_facility')) . "' " : ""));
         // Figure out appointments for this week
         return array(__("Patient Scheduler"), sprintf(__("There are %s appointments scheduled for today."), "<b>{$day_count}</b>"), "img/calendar_icon.png");
     }
 }
示例#5
0
 public function getUncompletedItemsCount($patient = NULL)
 {
     $u = freemed::user_cache();
     $q = "select count(*) as count from " . $this->table_name . " mfc where mfc.status_completed=0 and mfc.user = "******" and mfc.patient=" . $GLOBALS['sql']->quote($patient) : " ");
     $return = $GLOBALS['sql']->queryRow($q);
     return $return['count'];
 }
示例#6
0
 protected function mod_pre(&$data)
 {
     $data['user'] = freemed::user_cache()->user_number;
     if ($data['dateof']) {
         $s = CreateObject('org.freemedsoftware.api.Scheduler');
         $data['dateof'] = $s->ImportDate($data['dateof']);
     }
 }
示例#7
0
 public function GetAvailableGraphs()
 {
     $h = freemed::module_handler('GraphingModule');
     $req = $GLOBALS['sql']->queryAll("SELECT module_name AS v, module_class AS k FROM modules WHERE FIND_IN_SET( LOWER(module_class), LOWER(" . $GLOBALS['sql']->quote(join(',', $h)) . ") ) ");
     foreach ($req as $r) {
         $result[$r['k']] = $r['v'];
     }
     return $result;
 }
示例#8
0
 protected function mod_pre(&$data)
 {
     $s = CreateObject('org.freemedsoftware.api.Scheduler');
     $data['covstatus'] = "1";
     $data['covdtmod'] = date('Y-m-d');
     $data['covdteff'] = $s->ImportDate($data['covdteff']);
     $data['covrelinfodt'] = $s->ImportDate($data['covrelinfodt']);
     $data['covdob'] = $s->ImportDate($data['covdob']);
     $data['user'] = freemed::user_cache()->user_number;
 }
示例#9
0
 private function resolve_module_to_table($module)
 {
     $cache = freemed::module_cache();
     foreach ($cache as $v) {
         if (strtolower($v['MODULE_CLASS']) == strtolower($module)) {
             return $v['META_INFORMATION']['table_name'];
         }
     }
     trigger_error(__("Could not resolve table name!"), E_USER_ERROR);
 }
示例#10
0
 public function RunBackup()
 {
     $pwd = `pwd`;
     $dev = escapeshellarg(freemed::config_value('cdrw_device'));
     $driver = escapeshellarg(freemed::config_value('cdrw_driver'));
     $speed = escapeshellarg(freemed::config_value('cdrw_speed'));
     $output = `/usr/share/freemed/scripts/cdrw_backup.sh {$dev} {$driver} {$speed}`;
     //print "/usr/share/freemed/scripts/cdrw_backup.sh $dev | $driver | $speed\n";
     return $output;
 }
示例#11
0
 public function GetBlockedTimeSlots($providerid, $date = null)
 {
     freemed::acl_enforce('scheduling', 'write');
     $providerGroups = CreateObject('org.freemedsoftware.module.ProviderGroups');
     $providerGroupsIds = $providerGroups->getGroupIds($providerid);
     $q = "select sbshour,sbsminute,sbsduration from scheduler_block_slots where sbsprovider=" . $GLOBALS['sql']->quote($providerid) . ($date ? " and sbdate='" . $date . "'" : "");
     foreach ($providerGroupsIds as $ids) {
         $q = $q . " or sbsprovidergroup = " . $ids['id'];
     }
     return $GLOBALS['sql']->queryAll($q);
 }
示例#12
0
function smarty_block_acl($params, $text, &$smarty)
{
    if (!isset($params['category'])) {
        $smarty->trigger_error("Category not specified");
    }
    if (!isset($params['permission'])) {
        $smarty->trigger_error("Permission not specified");
    }
    $perm = freemed::user_cache()->CachedACL($params['category'], $params['permission']);
    if ($perm) {
        return $text;
    }
}
示例#13
0
function smarty_function_config_value($params, &$smarty)
{
    if (!isset($params['option'])) {
        $smarty->trigger_error("Option not specified");
    }
    $x = freemed::config_value($params['option']);
    // Handle optional variable return policy
    if ($params['var']) {
        $smarty->assign($params['var'], $x);
    } else {
        return $x;
    }
}
 function _update()
 {
     $version = freemed::module_version($this->MODULE_NAME);
     // Version 0.3
     //
     //	Move phyidmap to be mapped in insco table (inscoidmap)
     //
     if (!version_check($version, '0.3')) {
         $GLOBALS['sql']->query('ALTER TABLE ' . $this->table_name . ' ' . 'ADD COLUMN inscoidmap TEXT AFTER inscomod');
     }
     // Version 0.3.1
     //
     //	Add inscodefformat and inscodeftarget mappings
     //
     if (!version_check($version, '0.3.4.1')) {
         $GLOBALS['sql']->query('ALTER TABLE ' . $this->table_name . ' ' . 'ADD COLUMN inscodefformat VARCHAR(50) AFTER inscoidmap');
         $GLOBALS['sql']->query('ALTER TABLE ' . $this->table_name . ' ' . 'ADD COLUMN inscodeftarget VARCHAR(50) AFTER inscodefformat');
         $GLOBALS['sql']->query('ALTER TABLE ' . $this->table_name . ' ' . 'ADD COLUMN inscodefformate VARCHAR(50) AFTER inscodeftarget');
         $GLOBALS['sql']->query('ALTER TABLE ' . $this->table_name . ' ' . 'ADD COLUMN inscodeftargete VARCHAR(50) AFTER inscodefformatE');
     }
     // Version 0.3.3 (Actual update from old module name - HACK)
     //
     //	Add inscodef{format,target}e for electronic mappings
     //
     if ($GLOBALS['sql']->results($GLOBALS['sql']->query("SELECT * FROM module WHERE module_name='Insurance Company Maintenance'"))) {
         // Remove stale entry
         $GLOBALS['sql']->query('DELETE FROM module WHERE ' . 'module_name=\'Insurance Company Maintenance\'');
         // Make changes
         $GLOBALS['sql']->query('ALTER TABLE ' . $this->table_name . ' ' . 'ADD COLUMN inscodefformat VARCHAR(50) AFTER inscoidmap');
         $GLOBALS['sql']->query('ALTER TABLE ' . $this->table_name . ' ' . 'ADD COLUMN inscodeftarget VARCHAR(50) AFTER inscodefformat');
         $GLOBALS['sql']->query('ALTER TABLE ' . $this->table_name . ' ' . 'ADD COLUMN inscodefformate VARCHAR(50) AFTER inscodeftarget');
         $GLOBALS['sql']->query('ALTER TABLE ' . $this->table_name . ' ' . 'ADD COLUMN inscodeftargete VARCHAR(50) AFTER inscodefformate');
     }
     // Version 0.4
     //
     //	Add inscox12id for 837p/remitt
     //
     if (!version_check($version, '0.4')) {
         $GLOBALS['sql']->query('ALTER TABLE ' . $this->table_name . ' ' . 'ADD COLUMN inscox12id VARCHAR(32) AFTER inscoidmap');
         $GLOBALS['sql']->query('UPDATE ' . $this->table_name . ' SET inscox12id=\'\' WHERE id>0');
     }
     // Version 0.4.1
     //
     //	Add inscodefoutput for remitt
     //
     if (!version_check($version, '0.4.1')) {
         $GLOBALS['sql']->query('ALTER TABLE ' . $this->table_name . ' ' . 'ADD COLUMN inscodefoutput ENUM(\'electronic\', \'paper\') AFTER inscox12id');
         $GLOBALS['sql']->query('UPDATE ' . $this->table_name . ' SET inscodefoutput=\'electronic\' WHERE id>0');
     }
 }
示例#15
0
 protected function add_pre(&$data)
 {
     $s = CreateObject('org.freemedsoftware.api.Scheduler');
     $data['noriginal'] = date('Y-m-d');
     $data['nuser'] = freemed::user_cache()->user_number;
     if (empty($data['ntarget']) and $data['noffset'] > 0) {
         $data['ntarget'] = $s->date_add($s->ImportDate(date('Y-m-d')), $data['noffset'] + 0);
     } else {
         $data['ntarget'] = $s->ImportDate($data['ntarget']);
     }
     if (!$data['nfor']) {
         $data['nfor'] = $data['nuser'];
     }
 }
示例#16
0
 public function display_short($code)
 {
     switch (freemed::config_value('icd')) {
         case '10':
             $suffix = '10';
             break;
         case '9':
         default:
             $suffix = '9';
             break;
     }
     $code_record = $GLOBALS['sql']->get_link($this->table_name, $code);
     return $code_record['icd' . $suffix . 'code'] . ' - ' . $code_record['icd' . $suffix . 'descrip'];
 }
示例#17
0
 protected function mod_pre(&$data)
 {
     $data['user'] = freemed::user_cache()->user_number;
     $s = CreateObject('org.freemedsoftware.api.Scheduler');
     if ($data['dateof']) {
         $data['dateof'] = $s->ImportDate($data['dateof']);
     }
     if ($data['delinquentdate']) {
         $data['delinquentdate'] = $s->ImportDate($data['delinquentdate']);
     }
     if ($data['immunizationgivendate']) {
         $data['immunizationgivendate'] = $s->ImportDate($data['immunizationgivendate']);
     }
 }
示例#18
0
 protected function mod_pre(&$data)
 {
     $s = CreateObject('org.freemedsoftware.api.Scheduler');
     if (is_array($data['provider']) or is_object($data['provider'])) {
         $data['provider'] = join(',', $data['provider']);
     }
     $data['user'] = freemed::user_cache()->user_number;
     $data['datebegin'] = $data['datebegin'] ? $s->ImportDate($data['datebegin']) : '';
     if (!$data['datebegin']) {
         unset($data['datebegin']);
     }
     $data['dateend'] = $data['dateend'] ? $s->ImportDate($data['dateend']) : '';
     if (!$data['dateend']) {
         unset($data['dateend']);
     }
 }
示例#19
0
 public function GetDetailedRecord($id)
 {
     freemed::acl_enforce('emr', 'read');
     $q = "SELECT cg.id,cg.groupname,cg.grouplength,cg.groupfrequency,cg.groupmembers,cg.groupfacility as facility, CONCAT(f.psrname,' ',f.psrnote,' (',f.psrcity,',',f.psrstate,')') as groupfacility  FROM calgroup cg  left outer join facility f on f.id=cg.groupfacility where cg.id=" . $GLOBALS['sql']->quote($id);
     $groupResult = $GLOBALS['sql']->queryRow($q);
     if ($groupResult) {
         $members = $groupResult['groupmembers'];
         $q2 = "select CONCAT(pa.ptlname, ', ', pa.ptfname, IF(LENGTH(pa.ptmname)>0,CONCAT(' ',pa.ptmname),''), IF(LENGTH(pa.ptsuffix)>0,CONCAT(' ',pa.ptsuffix),''), ' (', pa.ptid, ')') AS patient from patient pa where pa.id in (" . $members . ")";
         $membersResult = $GLOBALS['sql']->queryAll($q2);
         $allMembers = "";
         foreach ($membersResult as $mem) {
             $allMembers = $allMembers . $mem['patient'] . "\n";
         }
         $groupResult['groupmembersName'] = $allMembers;
     }
     return $groupResult;
 }
示例#20
0
 function IsValid($credentials)
 {
     syslog(LOG_INFO, "isvalid");
     if (!isset($credentials['username'])) {
         return false;
     }
     // Find this user
     $r = $GLOBALS['sql']->queryRow("SELECT * FROM user " . "WHERE username = '******'username']) . "'");
     // If the user isn't found, false
     if (!$r['id']) {
         return false;
     }
     if (LOGLEVEL < 1 || (LOG_HIPAA || LOG_LOGIN)) {
         syslog(LOG_INFO, "FreeMED.Authentication_Basic| verify_auth login attempt {$user} ");
     }
     $db_pass = $r['userpassword'];
     // Check password
     if ($credentials['password'] == $r['userpassword']) {
         // Set session vars
         unset($r['userpassword']);
         HTTP_Session2::set('authdata', array("username" => $credentials['username'], "user" => $r['id'], "user_record" => $r));
         // Set ipaddr for SESSION_PROTECTION
         HTTP_Session2::set('ipaddr', $_SERVER['REMOTE_ADDR']);
         // Authorize
         if (LOGLEVEL < 1 || LOG_ERRORS || (LOG_HIPAA || LOG_LOGIN)) {
             syslog(LOG_INFO, "FreeMED.Authentication_Basic| verify_auth successful login");
         }
         $log = freemed::log_object();
         $log->SystemLog(LOG__SECURITY, 'Authentication', get_class($this), "Successfully logged in");
         return true;
     } else {
         // check password
         // Failed password check
         HTTP_Session2::set('authdata', null);
         HTTP_Session2::set('ipaddr', null);
         if (LOGLEVEL < 1 || LOG_ERRORS || (LOG_HIPAA || LOG_LOGIN)) {
             syslog(LOG_INFO, "FreeMED.Authentication_Basic| verify_auth failed login");
         }
         $log = freemed::log_object();
         $log->SystemLog(LOG__SECURITY, 'Authentication', get_class($this), "Failed login");
         return false;
     }
     // end check password
 }
示例#21
0
 function _update()
 {
     $version = freemed::module_version($this->MODULE_NAME);
     // Version 0.7.1
     //
     //	Add ability to track events by payment record (clpayrec)
     //
     if (!version_check($version, '0.7.1')) {
         $GLOBALS['sql']->query('ALTER TABLE ' . $this->table_name . ' ' . 'ADD COLUMN clpayrec INT UNSIGNED AFTER clprocedure');
         // Set to 0 by default (not associated with any payrec)
         $GLOBALS['sql']->query('UPDATE ' . $this->table_name . ' ' . 'SET clpayrec=\'0\'');
     }
     // Version 0.7.2
     //
     //	Force table creation, due to messed up older version
     //
     if (!version_check($version, '0.8.2')) {
         $this->create_table();
     }
 }
示例#22
0
 public function checkUtilitiesMenu(&$userLeftNavigationMenu)
 {
     //Tools stuff
     $toolsRead = freemed::acl('Tools', 'read') ? 1 : 0;
     $toolsWrite = freemed::acl('Tools', 'write') ? 1 : 0;
     $toolsModify = freemed::acl('Tools', 'modify') ? 1 : 0;
     $tools = $this->getShowBit($toolsRead, $toolsWrite, $toolsModify);
     //Admin stuff
     $adminRead = freemed::acl('admin', 'read') ? 1 : 0;
     $adminWrite = freemed::acl('admin', 'write') ? 1 : 0;
     $adminDelete = freemed::acl('admin', 'delete') ? 1 : 0;
     $adminModify = freemed::acl('admin', 'modify') ? 1 : 0;
     $admin = $this->getShowBit($adminRead, $adminWrite, $adminDelete, $adminModify);
     //ACL stuff
     $aclRead = freemed::acl('acl', 'read') ? 1 : 0;
     $aclWrite = freemed::acl('acl', 'write') ? 1 : 0;
     $aclDelete = freemed::acl('acl', 'delete') ? 1 : 0;
     $aclModify = freemed::acl('acl', 'modify') ? 1 : 0;
     $acl = $this->getShowBit($aclRead, $aclWrite, $aclDelete, $aclModify);
     if ($tools || $admin || $acl) {
         $UtilitiesAccessOptionsDB = $userLeftNavigationMenu['Tools'];
         $UtilitiesAccessOptions['Tools'] = $tools;
         if (!$UtilitiesAccessOptions['Tools']) {
             unset($UtilitiesAccessOptions['Tools']);
         }
         $UtilitiesAccessOptions['Support Data'] = $admin;
         if (!$UtilitiesAccessOptions['Support Data']) {
             unset($UtilitiesAccessOptions['Support Data']);
         }
         $UtilitiesAccessOptions['Field Checker'] = $admin;
         if (!$UtilitiesAccessOptions['Field Checker']) {
             unset($UtilitiesAccessOptions['Field Checker']);
         }
         $UtilitiesAccessOptions['User Management'] = $admin;
         if (!$UtilitiesAccessOptions['User Management']) {
             unset($UtilitiesAccessOptions['User Management']);
         }
         $UtilitiesAccessOptions['System Configuration'] = $admin;
         if (!$UtilitiesAccessOptions['System Configuration']) {
             unset($UtilitiesAccessOptions['System Configuration']);
         }
         $UtilitiesAccessOptions['DB Administration'] = $admin;
         if (!$UtilitiesAccessOptions['DB Administration']) {
             unset($UtilitiesAccessOptions['DB Administration']);
         }
         $UtilitiesAccessOptions['ACL'] = $acl;
         if (!$UtilitiesAccessOptions['ACL']) {
             unset($UtilitiesAccessOptions['ACL']);
         }
         if (strlen(serialize($UtilitiesAccessOptions)) != strlen(serialize($UtilitiesAccessOptionsDB)) - 13) {
             $userLeftNavigationMenu['Utilities'] = $UtilitiesAccessOptions;
         }
     } else {
         unset($userLeftNavigationMenu['Utilities']);
     }
 }
示例#23
0
 function _update()
 {
     $version = freemed::module_version($this->MODULE_NAME);
     // Version 0.1.1
     //
     //	Add colors
     //
     if (!version_check($version, '0.1.1')) {
         $GLOBALS['sql']->query('ALTER TABLE ' . $this->table_name . ' ' . 'ADD COLUMN atcolor CHAR(7) AFTER atequipment');
         $GLOBALS['sql']->query('UPDATE ' . $this->table_name . ' ' . 'SET atcolor=\'\' WHERE id>0');
     }
     // end version 0.1.1
 }
示例#24
0
 protected function mod_pre(&$data)
 {
     $data['pnotesuser'] = freemed::user_cache()->user_number;
 }
示例#25
0
// (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 'lib/freemed.php';
error_reporting();
set_error_handler("controller_standard_error_handler");
// Start logging
unset($log);
$log = freemed::log_object();
$log->SystemLog(LOG__SECURITY, 'Provider', 'Controller', "Controller called with " . $_SERVER['PATH_INFO']);
// Get provider from URL
unset($layout);
unset($piece);
list($_garbage_, $layout, $piece) = explode('/', $_SERVER['PATH_INFO']);
$layout = ucfirst(strtolower($layout));
Header('Content-Type: text/html; charset=' . $GLOBALS['ISOSET']);
// Sanity checking
if (!preg_match("/^[[:alpha:]]+\$/", $layout)) {
    print "Hack attempt, dying ( '{$layout}' given ).";
    exit;
}
if (!file_exists(dirname(__FILE__) . "/ui/" . strtolower(${layout}) . "/controller/controller.{$piece}.php")) {
    //print "Controller ${layout}::${piece} not present.";
    //exit;
示例#26
0
 function menu_notify()
 {
     // Check to see if we're the person who is supposed to be
     // notified. If not, die out right now.
     $supposed = freemed::config_value('uffax_user');
     $authdata = HTTP_Session2::get('authdata');
     if (!(strpos($supposed, ',') === false)) {
         // Handle array
         $found = false;
         foreach (explode(',', $supposed) as $s) {
             if ($s == $authdata['user']) {
                 $found = true;
             }
         }
         if (!$found) {
             return false;
         }
     } else {
         if ($supposed > 0 and $supposed != $authdata['user']) {
             return false;
         }
     }
     // Decide if we have any "unfiled documents" in the system
     $query = "SELECT COUNT(*) AS unfiled FROM " . $this->table_name;
     $unfiled = $GLOBALS['sql']->queryOne($query);
     if ($unfiled > 0) {
         return array(sprintf(__("You have %d unfiled documents"), $unfiled), "module_loader.php?module=" . urlencode(get_class($this)) . "&action=display");
     } else {
         // For now, we're just going to return nothing so that
         // the box doesn't show up
         return false;
     }
 }
示例#27
0
 public function GetAllRecords()
 {
     $user = freemed::user_cache()->user_number;
     $q = "SELECT * from " . $this->table_name . " WHERE user =" . $GLOBALS['sql']->quote($user);
     return $GLOBALS['sql']->queryAll($q);
 }
示例#28
0
 public function ProcessSuperbills($superbills = 0)
 {
     if ($superbills == 0) {
         $query = "SELECT * FROM " . $this->table_name . " WHERE processed = 0 AND reviewed > 0";
     } else {
         // Use enumerated superbill ids
         $query = "SELECT * FROM " . $this->table_name . " WHERE FIND_IN_SET( id, " . $GLOBALS['sql']->quote(join(',', $superbills)) . " )";
     }
     $s = $GLOBALS['sql']->queryAll($query);
     foreach ($s as $bill) {
         $dxs = explode(',', $bill['dx']);
         $pxs = explode(',', $bill['procs']);
         $detail = unserialize($bill['detail']);
         foreach ($pxs as $px) {
             // Get current coverages
             // Calculate charges
             // Create database insert
             $ins = $GLOBALS['sql']->insert_query('procrec', array('procpatient' => $bill['patient'], 'proccpt' => $px, 'procdiag1' => $dx[0], 'procdiag2' => $dx[1], 'procdiag3' => $dx[2], 'procdiag4' => $dx[3], 'procbillable' => 1, 'procbilled' => 0, 'procamtpaid' => 0));
             $result = $GLOBALS['sql']->query($ins);
         }
         // end foreach procedure
         // Mark superbill as processed
         $query = $GLOBALS['sql']->update_query($this->table_name, array('processed' => freemed::user_cache()->user_number), array('id' => $id + 0));
     }
     // end foreach superbill
     return true;
 }
示例#29
0
 public function GetSystemTaskUserInbox($box = NULL)
 {
     $q = "SELECT DATE_FORMAT(s.stamp, '%m/%d/%Y') AS stamp_mdy, s.stamp AS stamp, s.patient AS patient, s.box AS box, s.module AS module, m.module_name AS module_name, CONCAT( p.ptlname, ', ', p.ptfname, ' ', p.ptmname, ' (', p.ptid, ')' ) AS patient_name, s.oid AS oid, s.summary AS summary, s.id AS id FROM systemtaskinbox s LEFT OUTER JOIN modules m ON s.module = m.module_class LEFT OUTER JOIN patient p ON s.patient = p.id WHERE s.user = "******" AND s.box = " . $GLOBALS['sql']->quote($box) : '');
     return $GLOBALS['sql']->queryAll($q);
 }
示例#30
0
 protected function _RenderProcedure($procedure)
 {
     $p = $GLOBALS['sql']->get_link('procrec', $procedure);
     // Aadded new tags to use in the patient statement MD 05-03-2008
     $query = "SELECT payrecamt, payreccat, payrecsource, payreclink, payrecdt FROM payrec WHERE payrecproc='" . $procedure . "'";
     $pay_result = $GLOBALS['sql']->queryAll($query);
     foreach ($pay_result as $r) {
         $payrecdt = $r["payrecdt"];
         $payrecamt = $r["payrecamt"];
         $payreclink = $r["payreclink"];
         $ins_id = freemed::get_link_field($payreclink, 'coverage', 'covinsco');
         $ins_name = freemed::get_link_field($ins_id, 'insco', 'insconame');
         $payrecsource = $r["payrecsource"];
         $payreccat = $r["payreccat"];
         if ($payreccat == 11 and $payrecsource == 0) {
             $copay = $payrecamt;
             $copay_dt = $payrecdt;
         }
         if ($payreccat == 0 and $payrecsource == 1) {
             $pri_pay += $payrecamt;
             $pri_pay_dt = $payrecdt;
             $pri_name = $ins_name;
         } elseif ($payreccat == 0 and $payrecsource == 2) {
             $sec_pay += $payrecamt;
             $sec_pay_dt = $payrecdt;
             $sec_name = $ins_name;
         } elseif ($payreccat == 0 and $payrecsource == 3) {
             $tet_pay += $payrecamt;
             $tet_pay_dt = $payrecdt;
             $tet_name = $ins_name;
         } elseif (($payreccat == 0 or $payreccat == 11) and $payrecsource == 0) {
             $pat_pay += $payrecamt;
             $pat_pay_dt = $payrecdt;
         } elseif ($payreccat == 1 and $payrecsource == 5) {
             $mng_adj += $payrecamt;
             $mng_adj_dt = $payrecdt;
         } else {
         }
     }
     // wend
     $payhistory = NULL;
     if ($pat_pay > 0) {
         $payhistory = "Patient \$" . $pat_pay . " (" . $pat_pay_dt . "); ";
     }
     if ($pri_pay > 0) {
         $payhistory .= substr($pri_name, 0, 14) . " \$" . $pri_pay . " (" . $pri_pay_dt . "); ";
     }
     if ($sec_pay > 0) {
         $payhistory .= substr($sec_name, 0, 14) . " \$" . $sec_pay . " (" . $sec_pay_dt . "); ";
     }
     if ($tet_pay > 0) {
         $payhistory .= substr($tet_name, 0, 6) . " \$" . $tet_pay . " (" . $tet_pay_dt . "); ";
     }
     if ($mng_adj > 0) {
         $payhistory .= " Doctor adj \$" . $mng_adj . " (" . $mng_adj_dt . "); ";
     }
     if ($payhistory == NULL) {
         $payhistory = "No payment has been received for this service";
     } else {
         $payhistory = ucwords("Paid By: " . strtolower($payhistory));
     }
     $buffer .= "<procedure id=\"" . htmlentities($procedure) . "\">\n" . $this->_tag('cpt4code', freemed::get_link_field($p['proccpt'], 'cpt', 'cptcode'), true) . $this->_tag('cpt5code', freemed::get_link_field($p['proccpt'], 'cpt', 'cptcode'), true) . $this->_tag('cptdescription', freemed::get_link_field($p['proccpt'], 'cpt', 'cptnameint'), true) . $this->_tag('cptcob', '0', true) . $this->_tag('cptcharges', $p['procbalorig'], true) . $this->_tag('allowcharges', $p['proccharges'], true) . $this->_tag('comment', $p['proccomment'], true) . $this->_tag('pripay', $pri_pay, true) . $this->_date('pripaydt', $pri_pay_dt) . $this->_tag('pripayname', $pri_name, true) . $this->_tag('patpay', $pat_pay, true) . $this->_date('patpaydt', $pat_pay_dt) . $this->_tag('copay', $copay, true) . $this->_date('copaydt', $copay_dt) . $this->_tag('payhistory', $payhistory, true) . $this->_tag('cptcount', 1, true) . $this->_tag('cptemergency', '0', true) . $this->_tag('cptepsdt', '0', true) . $this->_tag('cptmodifier', freemed::get_link_field($p['proccptmod'], 'cptmod', 'cptmod'), true) . $this->_tag('cptmodifier2', freemed::get_link_field($p['proccptmod2'], 'cptmod', 'cptmod'), true) . $this->_tag('cptmodifier3', freemed::get_link_field($p['proccptmod3'], 'cptmod', 'cptmod'), true) . $this->_tag('cptunits', $p['procunits'], true) . $this->_tag('weightgrams', '0', true);
     $this->_AddDependency('cpt', $p['proccpt']);
     // Handle "array" of diagnoses/eoc
     $e = explode(':', $p['proceoc']);
     $eoc = $e[0];
     for ($i = 1; $i <= 4; $i++) {
         if ($p['procdiag' . $i] > 0) {
             $buffer .= $this->_tag('diagnosiskey', $eoc . ',' . $p['procdiag' . $i], true);
             $this->_AddDependency('diagnosis', $eoc . ',' . $p['procdiag' . $i]);
         }
     }
     $buffer .= $this->_tag('patientkey', $p['procpatient'], true);
     $this->_AddDependency('patient', $p['procpatient']);
     // Handle payer key
     switch ($p['proccurcovtp']) {
         case '1':
             $covnum = 1;
             break;
         case '2':
             $covnum = 2;
             break;
         case '3':
             $covnum = 3;
             break;
         case '4':
             $covnum = 4;
             break;
         default:
             $covnum = 0;
             break;
     }
     $coverage = $GLOBALS['sql']->get_link('coverage', $p['proccov' . $covnum]);
     $buffer .= $this->_tag('insuredkey', $p['proccov' . $covnum], true);
     //print "Should have added $coverage as coverage<br/>\n";
     $this->_AddDependency('coverage', $p['proccov' . $covnum]);
     $buffer .= $this->_tag('payerkey', $coverage['covinsco'], true);
     $this->_AddDependency('insco', $coverage['covinsco']);
     // Get id map (while we still have the primary coverage)
     $map = unserialize(freemed::get_link_field($coverage['covinsco'], 'insco', 'inscoidmap'));
     // Handle second key
     switch ($p['proccurcovtp']) {
         case 2:
             $covnum = 1;
             break;
         case 3:
             $covnum = 1;
             break;
         case 4:
             $covnum = 1;
             break;
         case 1:
             $covnum = 2;
             break;
         default:
             $covnum = 0;
             break;
     }
     $buffer .= $this->_tag('secondinsuredkey', $p['proccov' . $covnum], true);
     $this->_AddDependency('coverage', $p['proccov' . $covnum]);
     $coverage = $GLOBALS['sql']->get_link('coverage', $p['proccov' . $covnum]);
     $buffer .= $this->_tag('secondpayerkey', $coverage['covinsco'], true);
     $this->_AddDependency('insco', $coverage['covinsco']);
     // Get other insured key
     switch ($p['proccurcovtp']) {
         case '2':
             $covnum = 3;
             break;
         case '3':
             $covnum = 4;
             break;
         case '4':
             $covnum = 0;
             break;
         case '1':
         default:
             $covnum = 2;
             break;
     }
     $buffer .= $this->_tag('otherinsuredkey', $coverage['covinsco'], 'coverage');
     $this->_AddDependency('insco', $coverage['covinsco']);
     // Figure out type of service
     $cptobj = $GLOBALS['sql']->get_link('cpt', $p['proccpt']);
     $hash = unserialize($cptobj['cpttos']);
     if ($hash[$coverage['covinsco']] > 0) {
         $tos = freemed::get_link_field($hash[$coverage['covinsco']], 'tos', 'tosname');
     } else {
         $tos = freemed::get_link_field($cptobj['cptdeftos'], 'tos', 'tosname');
     }
     // Check for TOS override from procedure record
     if ($p['proctosoverride'] > 0) {
         $tos = $p['proctosoverride'];
     }
     // Get provider record
     $provider = $GLOBALS['sql']->get_link('physician', $p['procphysician']);
     $hcfalocaluse19 = '';
     $hcfalocaluse10d = '';
     $hcfalocaluse24k = '';
     if (is_array($map)) {
         if (is_array($map[$p['procphysician']])) {
             $hcfalocaluse19 = $map[$p['procphysician']]['local19'];
             $hcfalocaluse10d = $map[$p['procphysician']]['local10d'];
             $hcfalocaluse24k = $map[$p['procphysician']]['local24k'];
         }
     }
     // Various resubmission codes, etc
     $buffer .= $this->_tag('medicaidresubmissioncode', $p['procmedicaidresub'], true) . $this->_tag('medicaidoriginalreference', $p['procmedicaidresub'], true) . $this->_tag('hcfalocaluse19', $hcfalocaluse19, true) . $this->_tag('hcfalocaluse10d', $hcfalocaluse10d, true) . $this->_tag('hcfalocaluse24k', $hcfalocaluse24k, true) . $this->_tag('amountpaid', (double) $p['procamtpaid'], true) . $this->_tag('providerkey', $p['procphysician'], true) . $this->_tag('referringproviderkey', $p['procrefdoc'], true) . $this->_tag('facilitykey', $p['procpos'], true) . $this->_tag('practicekey', $provider['phypractice'], true) . $this->_tag('typeofservice', $tos, true) . '';
     $this->_AddDependency('physician', $p['procphysician']);
     $this->_AddDependency('physician', $p['procrefdoc']);
     $this->_AddDependency('practice', $provider['phypractice']);
     $this->_AddDependency('facility', $p['procpos']);
     // Authorizations
     $buffer .= $this->_tag('priorauth', freemed::get_link_field($p['procauth'], 'authorizations', 'authnum'), true);
     $this->_AddDependency('authorizations', $p['procauth']);
     // isOutsideLab
     $buffer .= $this->_tag('isoutsidelab', $p['proclabcharges'] > 0 ? '1' : '0', true);
     $buffer .= $this->_tag('outsidelabcharges', $p['proclabcharges'] + 0, true);
     $buffer .= $this->_date('dateofservicestart', $p['procdt']);
     switch ($procdtend) {
         case '':
         case '0000-00-00':
             $buffer .= $this->_date('dateofserviceend', $p['procdt']);
             break;
         default:
             $buffer .= $this->_date('dateofserviceend', $p['procdtend']);
             break;
     }
     $buffer .= $this->_tag('aging', (strtotime(date("Y-m-d")) - strtotime($p['procdt'])) / (60 * 60 * 24), true);
     $e = $GLOBALS['sql']->get_link('eoc', $eoc);
     $buffer .= $this->_tag('ishospitalized', $e['eochospital'] == 1 ? '1' : '0', true);
     $buffer .= $this->_date('dateofhospitalstart', $e['eochosadmdt']);
     $buffer .= $this->_date('dateofhospitalend', $e['eochosdischrgdt']);
     $buffer .= "</procedure>\n";
     return $buffer;
 }