예제 #1
0
 function getSesCopay($sesId)
 {
     $sesCopayAmt = array("amount" => 0, "place" => 0);
     try {
         if ($sesId > 0) {
             $sqlGetSes = "SELECT cs.clientID, cs.providerID, cs.sessionDate, cs.fee, cs.adj_fee, \n\t\t\t\t\t\t\tcs.other_ins_adj, cs.amt_paid, cs.out_of_network_ins_type, cs.client_copay,\n\t\t\t\t\t\t\tcs.procedureID, cs.pending_personinsurance_id, pp.code\n\t\t\t\t\t\t\tFROM clientsession AS cs \n\t\t\t\t\t\t\tLEFT JOIN providerprocedure AS pp ON cs.procedureID = pp.id\n\t\t\t\t\t\t\tWHERE cs.id = '{$sesId}'\n\t\t\t\t\t\t\tAND cs.sessionStatus = 1";
             $resGetSes = DB::do_query($sqlGetSes);
             if (DB::db_fetch_num_rows($resGetSes) > 0) {
                 $rowGetSes = DB::db_fetch_assoc($resGetSes);
                 $clientId = $rowGetSes['clientID'];
                 $providerId = $rowGetSes['providerID'];
                 $sesDate = $rowGetSes['sessionDate'];
                 $sesProc = $rowGetSes['code'];
                 $sesFee = $rowGetSes['fee'];
                 $sesAdjFee = $rowGetSes['adj_fee'];
                 $sesOthInsAdj = $rowGetSes['other_ins_adj'];
                 $sesInsPay = $rowGetSes['amt_paid'];
                 $sesInsCopay = $rowGetSes['client_copay'];
                 $pendingInsId = $rowGetSes['pending_personinsurance_id'];
                 $ONNType = $rowGetSes['out_of_network_ins_type'];
                 if ($ONNType == 1) {
                     $sesCopayAmt['amount'] = 0;
                     $sesCopayAmt['place'] = 0;
                 } else {
                     if ($pendingInsId == 0) {
                         $sesCopayAmt['amount'] = 0;
                         $sesCopayAmt['place'] = 0;
                     } else {
                         if ($sesInsCopay > 0) {
                             // if copay set by insurance, we have to this as priority
                             $sesCopayAmt["amount"] = $sesInsCopay;
                             $sesCopayAmt["place"] = 1;
                         } else {
                             $balMethod = new GetBalMethod();
                             $clientBalCalMethod = array();
                             $clientBalCalMethod = $balMethod->checkClientBalCalcMethodToUse(strtotime($sesDate), $clientId, $providerId, $sesProc);
                             if (count($clientBalCalMethod) && $clientBalCalMethod['method'] == 2) {
                                 if (array_key_exists($sesProc, $clientBalCalMethod['copay'])) {
                                     $sesCopayAmt['amount'] = $clientBalCalMethod['copay'][$sesProc];
                                 } else {
                                     $sesCopayAmt['amount'] = $balMethod->getFirstCopayUcrAmount($clientBalCalMethod['balCustId'], $sesProc, 1);
                                 }
                                 $sesCopayAmt['place'] = 0;
                             }
                         }
                     }
                 }
             }
         }
     } catch (Exception $e) {
         APP::logErrors($e);
     }
     return $sesCopayAmt;
 }