<cfparam name="url.patient_id" default="0">
<cfparam name="url.assessment_id" default="0">
<cfparam name="url.type" default="diagnosis">
<cfparam name="url.report_type" default="teachplan">
<cfparam name="url.download" default="0">

<cfset TheFile="/var/www/datafiles/Agency_Logos/#session.AgencyID#.png">
<cfif isdefined('url.patient_id')>
	<cfoutput>	
	    <cfif url.admitid NEQ 0 >
			<cfset url.admitid= decrypt(#url.admitid#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
		</cfif>
		<cfquery name="getadmit" datasource="#Application.DataSrc#">
				<cfif url.admitid EQ '0' >
					SELECT * FROM  #Request.prefix_db_agency#.pPatients 
			        LEFT OUTER JOIN  #Request.prefix_db_agency#.pAdmit ON pAdmit.Patient_ID = pPatients.Patient_ID AND pAdmit.status = 0
			        LEFT OUTER JOIN  #Request.prefix_db_lookup#.pEmployee ON pEmployee.Emp_ID = pAdmit.Case_Manager
			        LEFT OUTER JOIN  #Request.prefix_db_agency#.pAssessments ON pPatients.Patient_ID = pAssessments.Patient_ID  
			        WHERE pPatients.Patient_ID = '#url.ID#' 
			        AND pPatients.status = 0 
			        GROUP BY  pPatients.Patient_ID
				<cfelse>
					SELECT * FROM  #Request.prefix_db_agency#.pAdmit
			        JOIN  #Request.prefix_db_agency#.pPatients ON pAdmit.Patient_ID = pPatients.Patient_ID
			        JOIN  #Request.prefix_db_lookup#.pEmployee ON pEmployee.Emp_ID = pAdmit.Case_Manager
			        LEFT OUTER JOIN  #Request.prefix_db_agency#.pAssessments ON pAdmit.Admit_ID = pAssessments.Admit_ID  
			        WHERE pAdmit.Admit_ID = '#url.admitid#'
			        AND pAdmit.Status = 0
			        AND pPatients.status = 0 
			        GROUP BY  pAdmit.Admit_ID
				</cfif>
		       
		</cfquery>

	</cfoutput> 
    <cfif url.download eq 1>
		 <cfset agency_name = rereplace(Session.AgencyName,"[^A-Za-z0-9]","","all") />
        <cfset coding_reports= #agency_name#&"_"&#Trim(getadmit.Pt_Last)#&"_"&#DateFormat(now(),'yyyymmddhhmmss')#&"_"&#url.report_type#&"_report.pdf" />
        <cfheader name="Content-disposition" value="attachment;filename=#coding_reports#">
         <cfcontent  type="application/pdf">
     </cfif>
	<cfdocument format="pdf"   margintop=".75" marginbottom="1.25" orientation="landscape" overwrite="yes">	
		<cfdocumentsection>			
			<div class="row">		
				<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:10px; font-family: Arial; font-size: 25px;font-style: italic;">Teaching Plan for</td>
									</tr>
						
									<tr>
										<td height="6px"></td>
									</tr>
									<tr>				
										<td style="padding-left:50px; font-family: Arial; font-size: 30px; font-weight: bold;"><cfoutput>#getadmit.Pt_First# #getadmit.Pt_Last#</cfoutput></td>
									</tr>
									<tr>
										<td height="6px"></td>
									</tr>
									<!--- <tr>	
										<cfoutput>
										<cfset strSomestring = "">
										<cfset SOC_String = find( "Start of care", strSomestring )>	
										<cfset Recertification_String = find( "Recertification", strSomestring )>
										<cfset Resumption_String = find( "Resumption", strSomestring )>
																						
										<td style="padding-left:80px; font-family: Arial; font-size: 25px; font-weight: bold;"><cfif #SOC_String# neq 0>Start of Care<cfelseif #Recertification_String# neq 0>Recertification<cfelseif #Resumption_String# neq 0>Resumption<cfelse>#getadmit.F26#</cfif> #DateFormat(getadmit.F177,"mm/dd/yy")#</td>
										</cfoutput>
									</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="100%"  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 />		
				<div class="row">
					<div style="padding-right:10px; text-align:right; font-family: Arial; font-size: 25px;font-style: italic;">Prepared by <cfoutput>#getadmit.Emp_First#&nbsp;#getadmit.Emp_Last# </cfoutput></div>
				</div>		
				<br />
				<div class="row">
					<div style="border-top:solid 1px blue;"></div>
				</div>
				<cfset list_type =  #url.pathids# />
				<div class="row">			
					<cfloop list="#list_type#" index="i">	
                        <cfset path_type= "">
                        <cfif i neq ''>
                            <cfset path_type= "#i#">
                        </cfif>
						
						<cfquery name="getsymptoms" datasource="#Application.DataSrc#">
						    SELECT  *, Type AS Pathway_Type FROM  #Request.prefix_db_lookup#.Teaching_Symptoms_1
						    WHERE Teaching_Symptoms_1.Path_ID  = '#path_type#'
						    ORDER BY Step_ID ASC
						</cfquery>
						<cfquery name="getteachings" datasource="#Application.DataSrc#">
						    SELECT  *, Type AS Pathway_Type FROM  #Request.prefix_db_lookup#.Teaching_Prevention
						    WHERE  Pathway_ID  = '#path_type#'
						    ORDER BY Type DESC, Step_ID  ASC
						</cfquery>
						<div class="row" style="margin-top:15px;">			
								<label style="padding-left:0px; font-family: Arial; font-size: 22px;font-style:italic;text-transform: capitalize;">
								<cfoutput>
									<cfif path_type EQ '16'>Confusion/Cognition Deficit mild
									<cfelseif path_type EQ '52'>Confusion/Cognition Deficit severe
									<cfelseif path_type EQ '32'>Wound
									<cfelseif path_type EQ '63'>Cancer
									<cfelseif path_type EQ '62'>Depression
									<cfelseif path_type EQ '3'>Anxiety
									<cfelseif path_type EQ '26'>Vision Deficit
									<cfelseif path_type EQ '7'>Hearing Deficit
									<cfelseif path_type EQ '8'>Communication Deficit
									<cfelseif path_type EQ '51'>Urinary Catheter
									<cfelseif path_type EQ '9'>Diabetes 
									<cfelseif path_type EQ '50'>Infection 
									<cfelseif path_type EQ '27'>Hypertension 
									<cfelseif path_type EQ '12'>Cardiac Condition
									<cfelseif path_type EQ '14'>Respiratory Condition
									<cfelseif path_type EQ '57'>UTI 
									</cfif>
								</cfoutput></label>						
						</div>
										
						<div class="row" style="font-family: Arial;padding-left:35px; font-size: 14px;">	<br />
							<cfoutput query="getsymptoms">
                           		<cfif #getsymptoms.Pathway_Type# eq "Title">
									<div class="row">
										<div style="margin-top:5px;"></div>
										<div style="font-size:18px;font-weight:bold;">#UCase(getsymptoms.Explanation)#</div>
										<div style="margin-top:5px;"></div>
									</div>
								</cfif>				        				 
                                <cfif #getsymptoms.Pathway_Type# neq "Title" and #getsymptoms.Pathway_Type# eq "symptom">
                                        <div class="row">
                                            <div style="margin-top:5px;"></div> 
                                            <div style="font-size:14px;width:100%;">
                                                #getsymptoms.Explanation#
                                            </div>												
                                            <div style="margin-top:20px;"></div>
                                        </div>
                                </cfif>
                            	<div class="row">
									<div style="margin-top:5px;"></div>
								</div>	
							</cfoutput>	

							<cfoutput query="getteachings">
                           		<cfif #getteachings.Pathway_Type# eq "Title">
									<div class="row">
										<div style="margin-top:5px;"></div>
										<div style="font-size:18px;font-weight:bold;">#UCase(getteachings.Explanation)#</div>
										<div style="margin-top:5px;"></div>
									</div>
								</cfif>				        				 
                                <cfif #getteachings.Pathway_Type# neq "Title" and #getteachings.Pathway_Type# eq "Teaching">
                                        <div class="row">
                                            <div style="margin-top:5px;"></div> 
                                            <div style="font-size:14px;width:100%;">
                                                #getteachings.Explanation#
                                            </div>												
                                            <div style="margin-top:20px;"></div>
                                        </div>
                                </cfif>
                            	<div class="row">
									<div style="margin-top:10px;"></div>
								</div>	
							</cfoutput>	

						</div>	
									
					</cfloop>
				</div>
			</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: Arial; font-size: 22px; ">
						  <tr>
							<td height="3px"></td>
						  </tr>
						  <tr>
							<td align="center" style="font-family: Arial;font-size:22px;">Teaching Plan for <cfoutput>#getadmit.Pt_First#&nbsp;#getadmit.Pt_Last#</cfoutput></td>
						  </tr>
						  <tr>
							<td height="3px"></td>
						  </tr>
						  <tr>
							<td align="center" style="font-family: Arial;font-size: 22px;">prepared by <cfoutput>#getadmit.Emp_First#&nbsp;#getadmit.Emp_Last# </cfoutput></td>
						  </tr>
						<tr>
							<td height="3px"></td>
						  </tr>
						  <tr>
							<td align="center" style="font-family: Arial;font-size: 22px;"> page <cfoutput>#cfdocument.currentpagenumber#</cfoutput> </td>
						  </tr>
						  <tr>
							<td height="3px"></td>
						  </tr>
						</table></td>
					</tr>
				</table>
			</cfdocumentitem>  
		</cfdocumentsection>
	</cfdocument>
<cfelse>
	<p>Cannot be reloaded. Please close it and try to print report once again</p>
</cfif>