function _procedure_to_patient($procedure) { return freemed::get_link_field($procedure, 'procrec', 'procpatient'); }
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; }
public static function check_access_for_facility($facility_number) { // Separate out authdata $authdata = HTTP_Session2::get('authdata', array()); // Root has all access... if ($authdata['user'] == 1) { return true; } // Grab the authorizations field $f_fac = freemed::get_link_field($authdata['user'], "user", "userfac"); // No facility, assume no access restrictions if ($facility_number == 0) { return true; } // If it's an "ALL" or it is found, return true if (fm_value_in_string($f_fac, "-1") or fm_value_in_string($f_fac, $facility_number)) { return true; } // Default to false return false; }