<!--- lists_emergency_priority_print --->
<cfparam name="url.patient_status" default=""> 
<cfparam name="url.report_type" default="priority"> 
<cfscript>
			reports = CreateObject("Component", "components.report");
			getpatients = reports.get_priority_pat(patient_status="#url.patient_status#");
		</cfscript>	
   <cfset TheFile="/var/www/datafiles/Agency_Logos/#session.AgencyID#.png">
       
	<cfdocument format="pdf"   margintop=".75" marginbottom="1.25"   orientation="landscape"  overwrite="yes">
	    <cfdocumentsection>	
			<div class="row">
			  <cfoutput>
				<div class="row">
					<table cellpadding="0" cellspacing="0" border="0" width="100%">
						<tr>
							<td align="left" width="70%">
								<table cellpadding="0" cellspacing="0" border="0" width="100%">							
									<tr>				
										<td style="padding-left:20px; font-family: Arial; font-size: 28px; font-weight: bold;"> Emergency Priority Report</td>
									</tr>
								</table>
							</td>
							<td align="right" width="30%">
								<table cellpadding="0" cellspacing="0" border="0" width="100%">
									<tr>
										<td>
										   <cfif fileExists(TheFile)> 	
												<img src="file:///<cfoutput>#TheFile#</cfoutput>" width="80%" style="height:100px;">							
											<cfelse> 
												<img src="file:///var/www/img/MHCB_Logo.png" width="100%" style="height:100px;"> 
											</cfif>	
										</td>
									</tr>	
									
								</table>
							</td>	
							
						</tr>
					</table>		
				</div>
				<br />
				</cfoutput>
				<cfif url.report_type eq 'payer'>
                        <table cellpadding="5" border="1" cellspacing="0" width="100%">
                             <tr style="font-family: Arial;">
                                 <th width="10%" >Payer</th>
                                <th width="35%">Patients</th>
                                <th width="35%">Emergency Contacts</th>
                                <th width="20%">Comments</th>
                            </tr>
                         <cfquery   name="get_data"  dbtype="query">
                             SELECT * FROM  getpatients ORDER BY Payer_ID ASC
                        </cfquery>
                             <cfif isdefined('get_data.recordcount') and  getpatients.RecordCount GT 0>	
                                            <cfoutput query="get_data" group="Patient_ID">
                                                <cfquery  datasource="#Application.DataSrc#" name="get_diagnosis">
                                                       
                                                       SELECT * FROM #Request.prefix_db_agency#.pProblem 
                                                 WHERE M0_No like 'M1021%' AND Status = 0
                                                 AND Assmt_ID = 
                                                 (SELECT Assmt_ID FROM #Request.prefix_db_agency#.pAssessments
                                                 WHERE pAssessments.Patient_ID = #get_data.Patient_ID#  AND pAssessments.Status  = 0
                                                 AND (pAssessments.F26 like '%1 -%' OR   pAssessments.F26 like '%3 -%' OR   pAssessments.F26 like '%4 -%' ) 
                                                 ORDER BY pAssessments.F179 DESC LIMIT 1 )
                                                 </cfquery>
                                                <tr style="font-family: Arial; font-size: 14px;">
                                                      <td  width="10%"   valign="center" style="padding-left: 40px">#Pay_Name#</td>
                                                    <td width="35%" valign="center" text-align="center">(#Priority#) &nbsp;#Pt_Last#, #Pt_First# #Pt_Middle#<br>
                                                    #Pt_Street#, #Pt_City# <br>#Pt_Phone#<br>
                                                     <b>Physician :</b>
                                                    <p>#Phys_Last#, #Phys_First#  -  #Phys_Phone#</p>
                                                         <cfif get_diagnosis.recordcount gt 0>
                                                               <b>Primary Diagnosis :</b>
                                                                <cfloop query ="get_diagnosis">
                                                                     <p>#Description#<br></p>
                                                                </cfloop>
                                                          </cfif>
                                                    </td>
                                                    <td width="35%" valign="top">
                                                        <cfoutput>
                                                             <cfif PrimaryContact IS "1"><b style="color:##FF0000;">*</b></cfif>
                                                                #Last_Name# #First_Name# (#Pt_Realtionship#) <br>
                                                                #Telephone1#<br>
                                                        </cfoutput>

                                                    </td>
                                                    <td width="20%" valign="top">#Comment#</td>	
                                                </tr>
                                            </cfoutput>
                                    <cfelse>
                                            <tr>
                                                <td align="center" valign="middle" colspan="4" height="50px">
                                                    No Report Found
                                                </td>
                                            </tr>
                                    </cfif>					
                        </table>
				<cfelse>
				   <table cellpadding="5" border="1" cellspacing="0" width="100%">
				     <tr style="font-family: Arial;">
						<th width="10%" >Priority Level</th>
						<th width="35%">Patients</th>
						<th width="35%">Emergency Contacts</th>
						<th width="20%">Comments</th>
					</tr>
					 <cfif isdefined('getpatients.recordcount') and  getpatients.RecordCount GT 0>	
                                    <cfoutput query="getpatients" group="Patient_ID">
                                        <cfquery  datasource="#Application.DataSrc#" name="get_diagnosis">
                                          SELECT * FROM #Request.prefix_db_agency#.pProblem 
                                                 WHERE M0_No like 'M1021%' AND Status = 0
                                                 AND Assmt_ID = 
                                                 (SELECT Assmt_ID FROM #Request.prefix_db_agency#.pAssessments
                                                 WHERE pAssessments.Patient_ID = #getpatients.Patient_ID#  AND pAssessments.Status  = 0
                                                 AND (pAssessments.F26 like '%1 -%' OR   pAssessments.F26 like '%3 -%' OR   pAssessments.F26 like '%4 -%' ) 
                                                 ORDER BY pAssessments.F179 DESC LIMIT 1 )

                                         </cfquery>
                                        <tr style="font-family: Arial; font-size: 14px;">
                                            <td width="10%"  valign="center" style="padding-left: 40px">#Priority#</td>
                                            <td width="35%" valign="center" text-align="center">#Pt_Last#, #Pt_First# #Pt_Middle#<br>
                                            #Pt_Street#, #Pt_City# <br>#Pt_Phone#<br>
                                             <b>Physician :</b>
                                           <p>#Phys_Last#, #Phys_First#  -  #Phys_Phone#</p>
                                                 <cfif get_diagnosis.recordcount gt 0>
                                                       <b>Primary Diagnosis :</b>
                                                        <cfloop query ="get_diagnosis">
                                                             <p>#Description#<br></p>
                                                        </cfloop>
                                                  </cfif>
                                            </td>
                                            <td width="35%" valign="top">
                                                <cfoutput>
                                                     <cfif PrimaryContact IS "1"><b style="color:##FF0000;">*</b></cfif>
                                                        #Last_Name# #First_Name# (#Pt_Realtionship#)<br>
                                                        #Telephone1#<br>
                                                </cfoutput>

                                            </td>
                                            <td width="20%" valign="top">#Comment#</td>	
                                        </tr>
                                    </cfoutput>
							<cfelse>
                                    <tr>
                                        <td align="center" valign="middle" colspan="4" height="50px">
                                            No Report Found
                                        </td>
                                    </tr>
							</cfif>					
						</table>
               </cfif>
					</div>						
                <cfdocumentitem type="footer"  evalatprint="true">
				<table cellpadding="0" align="center" style="border-top:: solid 1px black;" cellspacing="0" border="0" height="150px" width="100%">
					<tr>
					  	<td>
							<table align="center" cellpadding="0" cellspacing="0" border="0" width="100%" 
						  style="font-family: font-family: Consolas, 'Andale Mono', 'Lucida Console', 'Lucida Sans Typewriter', Monaco, 'Courier New; font-size: 22px; ">
							  <tr>
								<td height="8px"></td>
							  </tr>	
							  <tr>
								<td align="center" style="font-family: font-family: Consolas, 'Andale Mono', 'Lucida Console', 'Lucida Sans Typewriter', Monaco, 'Courier New;font-size: 26px;"> page <cfoutput>#cfdocument.currentpagenumber#</cfoutput> </td>
							  </tr>
							  <tr>
								<td height="10px"></td>
							  </tr>
							</table>
						</td>
					</tr>
				</table>
			</cfdocumentitem>  
		</cfdocumentsection>
	</cfdocument>