<!---
This file is Copyright © 1998-2009 by Home Care Business Services. This work may not be reproduced, in whole or in part, 
using any medium, including, but not limited to, electronic transmission, CD-ROM or published in print, without the express 
permission of Home Care Business Services.

$Revision:$
$Id:$
$Date:$
--->

<cfquery name="GetP" datasource="#Application.DataSrc#">
SELECT Patient_ID, Last_Name_M0040 AS Last_Name, First_Name_M0040 AS First_Name, 
Middle_Initial_M0040 AS Middle
FROM #Request.prefix_db_agency#.patient WHERE Patient_ID = #session.cs.patientid#
AND Agency_ID = #session.AgencyID#
</cfquery>
<cfquery name="GetPatientPayer" datasource="#Application.DataSrc#">
SELECT PatientPayer_ID,patientpayer.Payer_ID,Patient_ID,InsuredIDNumber,InsuredName,RelationShip_to_Insured
,insured_street,insured_city,insured_state,insured_zip,insured_dob,insured_gender,HealthBenefitPlan,FamilyPlan,PayName,PriorAuthorization from #Request.prefix_db_agency#.patientpayer,#Request.prefix_db_agency#.Payer 
Where Patient_ID = #session.cs.patientid# and patientpayer.payer_id=Payer.payer_id and patientpayer.Payer_ID <> 0 order by PatientPayer_ID asc

</cfquery>




	<cfinclude template="PatientMenu.cfc">
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr>
            <td valign="bottom" align="left">
				<cfscript>
                pm = CreateObject("Component", "PatientMenu");
                pm.getPatientMenu(#session.cs.PatientId#);
                </cfscript>
            </td>
        </tr> 
    </table> 
    <div class="portlet box blue">
    	<div class="portlet-title">
            <div class="caption">
                <i class="fa fa-gear"></i><cfoutput>#getP.Last_Name#, #getP.First_Name# #getP.Middle# - Payers List</cfoutput>
            </div>
            <div class="tools">
                <a href="javascript:;" class="collapse"></a>
            </div>
            <div class="actions margin-right-10">
                <cfif session.eaClientEdit eq 1 or session.IsAgencyLogin eq 1>
                   <cfoutput>
                   	<a class="btn btn-default btn-sm" href='index.cfm?page=patient&ID=#session.cs.patientid#&cat=Patient_Payers_forms&PPID=0&action=new'><i class="fa fa-plus"></i> Add New PatientPayer</a>
                   </cfoutput>
                </cfif> 
            </div>        
        </div>
        <div class="portlet-body flip-scroll">
            <table class="table table-bordered table-striped table-condensed flip-content margin-top-15">
                <thead class="flip-content">
                    <tr>
                        <th>PayerName</th>
                        <th>Insured's Name</th>
                        <th>Insured's Number</th>
                        <th>Prior Authorization</th>
                    </tr> 
                </thead>
                <tbody>
                <cfif isdefined('GetPatientPayer.RecordCount') and GetPatientPayer.RecordCount GT 0>
                    <cfoutput query="GetPatientPayer">
                    <cfset RowBG = IIF(GetPatientPayer.CurrentRow MOD 2 EQ 0, "'d1'", "'d2'") />
                    <tr>
                        <td>
                            <cfif session.eaClientEdit eq 1 or session.IsAgencyLogin eq 1>
                            <a href='index.cfm?page=patient&ID=#GetPatientPayer.Patient_ID#&cat=Patient_Payers_forms&PPID=#PatientPayer_ID#&action=update'>#PayName#</a>
                            <cfelse>
                            #PayName#
                            </cfif>
                        </td>
                        <td>#InsuredName#</td>
                        <td>#InsuredIDNumber#</td>
                        <td>
                            <cfif #GetPatientPayer.priorAuthorization# NEQ 0>
                            <cfquery name="GetBenefitCount" datasource="#Application.DataSrc#">
                            select count(Benefit_ID) as Benefitcount from #Request.prefix_db_agency#.benefits where payer_ID=#GetPatientPayer.Payer_ID#
                            </cfquery>
                            <cfif #GetBenefitCount.Benefitcount# NEQ 0>
                            <a href='index.cfm?page=patient&ID=#GetPatientPayer.PatientPayer_ID#&PatientID=#GetPatientPayer.Patient_ID#&cat=payer_prior_form'>Prior Authorization</a>
                            <cfelse>Prior Authorization
                            </cfif>
                            </cfif>
                        </td>
                    </tr>
                    </cfoutput>
                <cfelse>
                <tr>
                    <td colspan="6" align="center">
                        No PatientPayer Records for <cfoutput>#getP.Last_Name#, #getP.First_Name# #getP.Middle#</cfoutput>
                    </td>
                </tr>
                </cfif>
                </tbody>
            </table>
        </div>
    </div>