<cfparam name="url.redirect_from" default="">
<cfparam name="url.OASIS_D_PDGM_Visit" default="">
<cfparam name="url.report" default="teachplan">
<cfparam name = "url.report_type" default ="1">
<!---<cfif CGI.REMOTE_ADDR EQ '157.51.194.126'>
<cfabort>
</cfif>--->
<cfset TheFile="/var/www/datafiles/Agency_Logos/#session.AgencyID#.png">

	<cfoutput> 
	   <cfscript>
			dashboard_component = CreateObject("Component", "teachingplan_dashboard");			
			Get_Report5_groupby = dashboard_component.Get_Report5_groupby(Patient_ID="#url.patient_id#",Assessment_ID="#url.assessment_id#",Report="#url.report_type#");
			Get_Assessment_Patient_data = dashboard_component.Get_Assess_Patient_data(Patient_ID="#url.patient_id#",Assessment_ID="#url.assessment_id#");	
		</cfscript>	
		
		<cfset url.AID = #url.assessment_id# />
		<cfset url.ID = #url.patient_id# />	
				
	</cfoutput>

 <cfset agency_name = rereplace(Session.AgencyName,"[^A-Za-z0-9]","","all") />
         <cfset recommended_reports= #agency_name#&"_"&#Trim(Get_Assessment_Patient_data.PatientLast)#&"_"&#DateFormat(now(),'yyyymmddhhmmss')#&"_"&#url.report#&"_report.pdf" />
       <!--- <cfset recommended_reports= #agency_name#&"_"&#Trim(Get_Assessment_Patient_data.PatientLast)#&"_"&#DateFormat(now(),'yyyymmdd')#&"_recommended_report.pdf" />--->
     
<cfif url.report_type EQ 1>
     <cfdocument format="pdf"   margintop=".75" marginbottom="1.25"   orientation="landscape"  filename="/var/www/dashboard/coding_files/#recommended_reports#"  overwrite="yes">
	
		<cfdocumentsection>	
		
		<div class="row">
			<div class="row">
			
				<cfoutput>
				<div class="row">
					<div>
						<label style="padding-left:0px; font-family: Arial; font-size: 20px;font-weight:bold;"><cfif #url.report_method# eq "2019_OASIS_D">2019 OASIS-D Recommended Diagnoses<cfelseif #url.report_method# eq "2020_PDGM">2020 PDGM Recommended Diagnoses</cfif></label>
					</div>
				</div>
				<div class="row">
					<table cellpadding="0" cellspacing="0" border="0" width="100%">
						<tr>
							<td align="left" width="45%">
								<table cellpadding="0" cellspacing="0" border="0" width="100%">							
									<!---<tr>
										<td height="2px"></td>
									</tr>--->
									<tr>				
										<td style="padding-left:20px; font-family: Arial; font-size: 28px; font-weight: bold;"><cfoutput>#Get_Assessment_Patient_data.PatientFirst# #Get_Assessment_Patient_data.PatientLast#</cfoutput></td>
									</tr>
									<tr>	
										<cfoutput>
										<cfset strSomestring = #Get_Assessment_Patient_data.Assessment_Reason_M0100#>
										<cfset SOC_String = find( "Start of care", strSomestring )>	
										<cfset Recertification_String = find( "Recertification", strSomestring )>
										<cfset Resumption_String = find( "Resumption", strSomestring )>
																						
										<td style="padding-left:30px; font-family: Arial; font-size: 20px; font-weight: bold;"><cfif #SOC_String# neq 0>Start of Care<cfelseif #Recertification_String# neq 0>Recertification<cfelseif #Resumption_String# neq 0>Resumption<cfelse>#Get_Assessment_Patient_data.Assessment_Reason_M0100#</cfif> #DateFormat(Get_Assessment_Patient_data.Assessment_Completed_M0090,"mm/dd/yy")#</td>
										</cfoutput>
									</tr>
								</table>
							</td>				
							<td align="right" width="25%">
								<table cellpadding="0" cellspacing="0" border="0" width="100%">
									<tr>
										<td>
										   
										</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>
				
				
				<table cellpadding="5" border="1" cellspacing="0" width="100%">
				
					<tr style="font-family: Arial;">
						<th width="10%" height="20px"></th>
						<th width="25%">User-entered Diagnoses</th>
						<th width="30%">Rationale</th>
						<th width="30%">Goal</th>
					</tr>
					
					<cfquery name="Get_Report_1_data_all" datasource="#Application.DataSrc#">
						SELECT * FROM 
							#Request.prefix_db_agency#.Coding_Results 
						WHERE 
							Patient_ID=<cfqueryparam value="#url.patient_id#" cfsqltype="cf_sql_integer"> 
							AND Assessment_ID=<cfqueryparam value="#url.assessment_id#" cfsqltype="cf_sql_integer"> 
							AND ( M0_Item_Medication like '%(M102%' or M0_Item_Medication = 'OASIS' ) 
							<!---AND ( M0_Item_Medication like '%(M102%' or M0_Item_Medication = 'OASIS' )--->	
                        Order by Results_ID ASC
					</cfquery>	
					<cfquery name="Get_Patient" datasource="#Application.DataSrc#">
						SELECT * FROM 
							#Request.prefix_db_agency#.patient
						WHERE 
							Patient_ID=<cfqueryparam value="#url.patient_id#" cfsqltype="cf_sql_integer"> 
				   </cfquery>	
                    <cfif Get_Patient.Safety_Hazards_M0320 neq ''>
                        <cfset Primary = '('&Get_Patient.Safety_Hazards_M0320 &')'>
                        <cfelse>
                            <cfset Primary = '(no primary reason documented)'>
					</cfif>

					<cfif #url.report_method# eq "2019_OASIS_D">
						<cfif isdefined('Get_Report_1_data_all.recordcount') and  Get_Report_1_data_all.RecordCount GT 0>	
							<cfoutput query="Get_Report_1_data_all">
                              <tr style="font-family: Arial; font-size: 13px;">
                                  <td width="5%">#Get_Report_1_data_all.M0_Item_Medication#</td>
                                  <td width="30%"><cfif Get_Report_1_data_all.Message_ID eq 13 or Get_Report_1_data_all.Message_ID eq 15 or Get_Report_1_data_all.Message_ID eq 16><font color="##FF0000">#Get_Report_1_data_all.Diagnosis#</font><cfelseif Get_Report_1_data_all.M0_Item_Medication eq 'OASIS'><font color="##0000FF">#Get_Report_1_data_all.Diagnosis#</font><cfelse>#Get_Report_1_data_all.Diagnosis#</cfif></td>
                                  <td width="30%">#Get_Report_1_data_all.OASIS#<!---<br>
                                      <cfif Get_Report_1_data_all.Medications eq 'no medications' and Get_Report_1_data_all.M0_Item_Medication neq 'OASIS'><font color="##9933ff">no medication</font><cfelseif Get_Report_1_data_all.M0_Item_Medication neq 'OASIS'><i>#Get_Report_1_data_all.Medications#</i><cfelse>&nbsp;</cfif>---></td>
                                  <td width="30%"><cfif Get_Report_1_data_all.Message_ID eq 13 or Get_Report_1_data_all.Message_ID eq 15><font color="##FF0000">GOAL ALREADY MET<br><br>#Get_Report_1_data_all.TextField_8#</font><cfelse>#Get_Report_1_data_all.TextField_8#</cfif></td>
                              </tr>								
							</cfoutput>
						<cfelse>
							<tr>
								<td align="center" valign="middle" colspan="4" height="50px">
									No Report Found
								</td>
							</tr>
						</cfif>						
					<cfelseif #url.report_method# eq "2020_PDGM">
						<cfif isdefined('Get_Report_1_data_all.recordcount') and  Get_Report_1_data_all.RecordCount GT 0>	
							<cfoutput query="Get_Report_1_data_all">
								<tr style="font-family: Arial; font-size: 13px;">
									<td width="10%">#Get_Report_1_data_all.M0_Item_Medication#</td>
									<td width="25%"><cfif Get_Report_1_data_all.TextField_10 contains 'replace' or Get_Report_1_data_all.TextField_10 contains 'redund'><font color="##FF0000">#Get_Report_1_data_all.Diagnosis#</font><cfelse>#Get_Report_1_data_all.Diagnosis#</cfif><cfif Get_Report_1_data_all.Textfield_1 neq '' or Get_Report_1_data_all.Textfield_2 neq ''><br><br><i>#Get_Report_1_data_all.Textfield_1#<br>#Get_Report_1_data_all.Textfield_2#</i><cfelse></cfif></td>
									<td width="30%"><cfif Get_Report_1_data_all.Created_by contains 'replace' or Get_Report_1_data_all.Created_by contains 'redund'><font color="##FF0000">#Get_Report_1_data_all.Created_by#</font><cfelse>#Get_Report_1_data_all.Created_by#</cfif></td>
									<td width="30%"><cfif Get_Report_1_data_all.Textfield_9 contains '2020'><font color="##9933ff">#Get_Report_1_data_all.OASIS#<br><br>#Get_Report_1_data_all.Textfield_9#&nbsp;</font>&nbsp;#Primary#<br><br><cfelse>#Get_Report_1_data_all.OASIS#<br><br>#Get_Report_1_data_all.Textfield_9#</cfif><i>#Get_Report_1_data_all.Medications#</i></td>	
								</tr>								
							</cfoutput>
						<cfelse>
							<tr>
								<td align="center" valign="middle" colspan="4" height="50px">
									No Report Found
								</td>
							</tr>
						</cfif>
					</cfif>
					
				</table>
					
					
			</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: 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>



<cfelseif url.report_type EQ 2>
   

	<cfdocument format="pdf"  localURL = "yes"   margintop=".75" marginbottom="1.25"   orientation="landscape"  overwrite="yes"  filename="/var/www/dashboard/coding_files/#recommended_reports#"   >
	
		<cfdocumentsection>	
		
		<div class="row">
		
				<cfquery name="Get_Report_2_data_2019" datasource="#Application.DataSrc#">
					SELECT * FROM 
						#Request.prefix_db_agency#.Coding_Results 
					WHERE 
						Patient_ID=<cfqueryparam value="#url.patient_id#" cfsqltype="cf_sql_integer"> 
						AND Assessment_ID=<cfqueryparam value="#url.assessment_id#" cfsqltype="cf_sql_integer">
                        AND ( M0_Item_Medication like '%(M102%' <!---or Order_ID = 28 or Order_ID = 29--->)
                    Order by Results_ID
				</cfquery>	
						
                    	<cfquery name="Get_Report_2_data_2020" datasource="#Application.DataSrc#">
                    SELECT * FROM 
						#Request.prefix_db_agency#.Coding_Results 
					WHERE 
						Patient_ID=<cfqueryparam value="#url.patient_id#" cfsqltype="cf_sql_integer"> 
						AND Assessment_ID=<cfqueryparam value="#url.assessment_id#" cfsqltype="cf_sql_integer">
                        AND (M0_Item_Medication like '%(M102%' or M0_Item_Medication = 'OASIS') 
                            AND Message_ID not in (13,15,16)
                    Order by Results_ID
				</cfquery>	

				<div class="row">
					<div>
						<label style="padding-left:0px; font-family: Arial; font-size: 20px;font-weight:bold;"><cfif #url.report_method# eq "User_entered">User-entered Interventions & Goals for 485<cfelseif #url.report_method# eq "Recommended">Recommended Interventions & Goals for 485</cfif></label>
					</div>
				</div>
				<div class="row">
					<table cellpadding="0" cellspacing="0" border="0" width="100%">
						<tr>
							<td align="left" width="45%">
								<table cellpadding="0" cellspacing="0" border="0" width="100%">							
									<!---<tr>
										<td height="2px"></td>
									</tr>--->
									<tr>				
										<td style="padding-left:40px; font-family: Arial; font-size: 28px; font-weight: bold;"><cfoutput>#Get_Assessment_Patient_data.PatientFirst# #Get_Assessment_Patient_data.PatientLast#</cfoutput></td>
									</tr>
									<tr>	
										<cfoutput>
										<cfset strSomestring = #Get_Assessment_Patient_data.Assessment_Reason_M0100#>
										<cfset SOC_String = find( "Start of care", strSomestring )>	
										<cfset Recertification_String = find( "Recertification", strSomestring )>
										<cfset Resumption_String = find( "Resumption", strSomestring )>
																						
										<td style="padding-left:50px; font-family: Arial; font-size: 24px; font-weight: bold;"><cfif #SOC_String# neq 0>Start of Care<cfelseif #Recertification_String# neq 0>Recertification<cfelseif #Resumption_String# neq 0>Resumption<cfelse>#Get_Assessment_Patient_data.Assessment_Reason_M0100#</cfif> #DateFormat(Get_Assessment_Patient_data.Assessment_Completed_M0090,"mm/dd/yy")#</td>
										</cfoutput>
									</tr>
								</table>
							</td>				
							<td align="right" width="25%">
								<table cellpadding="0" cellspacing="0" border="0" width="100%">
									<tr>
										<td>
										   
										</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="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>
				
                                        <cfoutput>#Get_Report_2_data_2019.Textfield_9#</cfoutput>
				<cfif url.report_method eq "User_entered">
					<div class="row">
						<table cellpadding="5" border="1" cellspacing="0" width="100%">					
							<tr style="font-family: Arial;">
								<th width="10%" height="40px"></th>
								<th width="25%">User-entered Diagnosis List</th>
								<th width="30%">Goals for CMS485 FL 22</th>
								<th width="30%">Interventions for CMS485 FL 21</th>
							</tr>
							
							<cfif isdefined('Get_Report_2_data_2019.recordcount') and  Get_Report_2_data_2019.RecordCount GT 0>	
								<cfoutput query="Get_Report_2_data_2019">
									<tr style="font-family: Arial; font-size: 13px;">
										<td width="10%">#Get_Report_2_data_2019.M0_Item_Medication#</td>
										<td width="25%">#Get_Report_2_data_2019.Diagnosis#</td>
										<td width="30%">#Get_Report_2_data_2019.Memo#</td>
										<td width="30%" valign="top">#Get_Report_2_data_2019.Textfield_12#</td>	
									</tr>
								</cfoutput>
							<cfelse>
								<tr>
									<td align="center" valign="middle" colspan="4" height="50px">
										No Report Found
									</td>
								</tr>
							</cfif>					
						</table>
					</div>						
					<!---<br /><br /><br /><br />--->
					<cfdocumentitem type="pagebreak">
            		</cfdocumentitem>
					<div class="row">			
						<div class="row">
							<div>
								<label style="padding-left:0px; font-family: Arial; font-size: 34px;font-weight:bold;">INSERT INTO CMS485</label>
							</div>
						</div>
						<br /> <cfoutput>#Get_Report_2_data_2019.Textfield_9#</cfoutput>
					
						<table cellpadding="5" border="1" cellspacing="0" width="100%">
												
							<tr style="font-family: Arial;">
								<th width="50%" height="40px">All Goals for CMS485 FL 22</th>
								<th width="50%">All Interventions for CMS485 FL 21</th>						
							</tr>
							
							<cfif isdefined('Get_Report_2_data_2019.recordcount') and  Get_Report_2_data_2019.RecordCount GT 0>	
								<tr style="font-family: Arial; font-size: 13px;">
									<td width="50%" valign="top">
										<cfoutput query="Get_Report_2_data_2019">
											<cfif #Get_Report_2_data_2019.Memo# neq "">
												#Get_Report_2_data_2019.Memo# <br />
											</cfif>
										</cfoutput>										
									</td>
									<td width="50%" valign="top">
										<cfoutput query="Get_Report_2_data_2019">
											<cfif #Get_Report_2_data_2019.Textfield_12# neq "">
												#Get_Report_2_data_2019.Textfield_12# <br />
											</cfif>
										</cfoutput>	
									</td>									
								</tr>
							<cfelse>
								<tr>
									<td align="center" valign="middle" colspan="2" height="50px">
										No Report Found
									</td>
								</tr>
							</cfif>					
						</table>
					</div>	
				<cfelseif url.report_method eq "Recommended">
					<div class="row">
						<table cellpadding="5" border="1" cellspacing="0" width="100%">					
							<tr style="font-family: Arial;">
								<th width="10%" height="40px"></th>
								<th width="25%">User-entered Diagnosis List</th>
								<th width="30%">Goals for CMS485 FL 22</th>
								<th width="30%">Interventions for CMS485 FL 21</th>
							</tr>
							
							<cfif isdefined('Get_Report_2_data_2020.recordcount') and  Get_Report_2_data_2020.RecordCount GT 0>	
								<cfoutput query="Get_Report_2_data_2020">
									<tr style="font-family: Arial; font-size: 13px;">
										<td width="10%">#Get_Report_2_data_2020.M0_Item_Medication#</td>
										<td width="25%">#Get_Report_2_data_2020.Textfield_10#</td>
										<td width="30%">#Get_Report_2_data_2020.Memo#</td>
										<td width="30%" valign="top">#Get_Report_2_data_2020.Textfield_12#</td>	
									</tr>
								</cfoutput>							
							<cfelse>
								<tr>
									<td align="center" valign="middle" colspan="4" height="50px">
										No Report Found
									</td>
								</tr>
							</cfif>					
						</table>
					</div>						
					<!---<br /><br /><br />--->
					<cfdocumentitem type="pagebreak">
            		</cfdocumentitem>
					<div class="row">			
						<div class="row">
							<div>
								<label style="padding-left:0px; font-family: Arial; font-size: 34px;font-weight:bold;">INSERT INTO CMS485</label>
							</div>
						</div>
						<br /><br />
					
						<table cellpadding="5" border="1" cellspacing="0" width="100%">
												
							<tr style="font-family: Arial;">
								<th width="50%" height="40px">All Goals for CMS485 FL 22</th>
								<th width="50%">All Interventions for CMS485 FL 21</th>						
							</tr>
							
							<cfif isdefined('Get_Report_2_data_2020.recordcount') and  Get_Report_2_data_2020.RecordCount GT 0>	
									<tr style="font-family: Arial; font-size: 13px;">
										<td width="50%" valign="top">
											<cfoutput query="Get_Report_2_data_2020">
												<cfif #Get_Report_2_data_2020.Memo# neq "">
													#Get_Report_2_data_2020.Memo# <br />
												</cfif>
											</cfoutput>										
										</td>
										<td width="50%" valign="top">
											<cfoutput query="Get_Report_2_data_2020">
												<cfif #Get_Report_2_data_2020.Textfield_12# neq "">
													#Get_Report_2_data_2020.Textfield_12# <br />
												</cfif>
											</cfoutput>	
										</td>								
									</tr>
							<cfelse>
								<tr>
									<td align="center" valign="middle" colspan="2" height="50px">
										No Report Found
									</td>
								</tr>
							</cfif>					
						</table>
					</div>				
				
				</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>



<cfelseif url.report_type EQ 4>


	<cfdocument format="pdf"  localURL = "yes"   margintop=".75" marginbottom="1.25"   orientation="landscape"  overwrite="yes"  filename="/var/www/dashboard/coding_files/#recommended_reports#"   >
	
		<cfdocumentsection>	
		
		<div class="row">
		
			<div class="row">
				
				<div class="row">
					<div>
						<label style="padding-left:0px; font-family: Arial; font-size: 20px;font-weight:bold;">OASIS-D and PDGM Visit Utilization</label>
					</div>
				</div>
				<div class="row">
					<table cellpadding="0" cellspacing="0" border="0" width="100%">
						<tr>
							<td align="left" width="45%">
								<table cellpadding="0" cellspacing="0" border="0" width="100%">							
																		<tr>				
										<td style="padding-left:20px; font-family: Arial; font-size: 24px; font-weight: bold;"><cfoutput>#Get_Assessment_Patient_data.PatientFirst# #Get_Assessment_Patient_data.PatientLast#</cfoutput></td>
									</tr>
									<tr>	
										<cfoutput>

										<cfset strSomestring = #Get_Assessment_Patient_data.Assessment_Reason_M0100#>
										<cfset SOC_String = find( "Start of care", strSomestring )>	
										<cfset Recertification_String = find( "Recertification", strSomestring )>
										<cfset Resumption_String = find( "Resumption", strSomestring )>
																						
										<td style="padding-left:30px; font-family: Arial; font-size: 20px; font-weight: bold;"><cfif #SOC_String# neq 0>Start of Care<cfelseif #Recertification_String# neq 0>Recertification<cfelseif #Resumption_String# neq 0>Resumption<cfelse>#Get_Assessment_Patient_data.Assessment_Reason_M0100#</cfif> #DateFormat(Get_Assessment_Patient_data.Assessment_Completed_M0090,"mm/dd/yy")#</td>
										</cfoutput>
									</tr>
								</table>
							</td>				
							<td align="right" width="25%">
								<table cellpadding="0" cellspacing="0" border="0" width="100%">
									<tr>
										<td>
										   
										</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="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 />
			
			<cfquery name="Get_Report_data_all" datasource="#Application.DataSrc#">
				SELECT * FROM 
					#Request.prefix_db_agency#.Coding_Results 
				WHERE 
					Patient_ID=<cfqueryparam value="#url.patient_id#" cfsqltype="cf_sql_integer"> 
					AND Assessment_ID=<cfqueryparam value="#url.assessment_id#" cfsqltype="cf_sql_integer"> 
					AND ( M0_Item_Medication='(M1021)' or M0_Item_Medication='(M1023)' or M0_Item_Medication='OASIS' )	
               
			</cfquery>
                                 			
			<cfquery name="Get_Report_4_datas_User" datasource="#Application.DataSrc#">
				SELECT * FROM 
					 #Request.prefix_db_agency#.Coding_Results as r 
				JOIN 
					#Request.prefix_db_agency#.Coding_Scrub as s on s.patient_ID=r.Patient_ID and s.Assessment_ID=r.Assessment_ID and s.Message_ID = 76
				WHERE  
					r.Patient_ID=<cfqueryparam value="#url.patient_id#" cfsqltype="cf_sql_integer"> 
					AND r.Assessment_ID=<cfqueryparam value="#url.assessment_id#" cfsqltype="cf_sql_integer">
               		AND r.M0_Item_Medication like '%(M102%'
                	Order by r.Results_ID
			</cfquery>
			<cfquery name="Get_Report_4_datas" datasource="#Application.DataSrc#">
				SELECT * FROM 
					 #Request.prefix_db_agency#.Coding_Results as r 
				JOIN 
					#Request.prefix_db_agency#.Coding_Scrub as s on s.patient_ID=r.Patient_ID and s.Assessment_ID=r.Assessment_ID and s.Message_ID = 76
				WHERE  
					r.Patient_ID=<cfqueryparam value="#url.patient_id#" cfsqltype="cf_sql_integer"> 
					AND r.Assessment_ID=<cfqueryparam value="#url.assessment_id#" cfsqltype="cf_sql_integer">
                    AND r.Message_ID NOT IN (13,15,16)
                    and r.Textfield_10 IS NOT NULL
                and r.Message_ID != 78
                    Order by r.Results_ID
			</cfquery>

			
			<!---<cfquery name="Get_Report_4_Groupby" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_agency#.Coding_Scrub					 
				WHERE  
					Patient_ID=<cfqueryparam value="#url.patient_id#" cfsqltype="cf_sql_integer"> 
					AND Assessment_ID=<cfqueryparam value="#url.assessment_id#" cfsqltype="cf_sql_integer">
					GROUP BY Patient_ID,Assessment_ID
			</cfquery>--->
			
			
			
			<cfif url.report_method eq "2019_OASIS_D">
					<div class="row">			
						<div class="row">
							<div>
								<label style="padding-left:0px; font-family: Arial; font-size: 20px;font-weight:bold;">2019 OASIS-D Coding Wizard-Recommended <font color="##0000FF">MEDICARE AVERAGE</font></label>
							</div>
						</div>
						<br /><br />					
						<table cellpadding="5" border="1" cellspacing="0" width="100%">											
							<tr style="font-family: Arial;">
								<th width="100%">2019 OASIS D Analysis and Rationale</th>
							</tr>														
							<cfif isdefined('Get_Report_data_all.recordcount') and  Get_Report_data_all.RecordCount GT 0>														
								<cfoutput query="Get_Report_data_all">
									<tr style="font-family: Arial; font-size: 12px;">
										<td width="10%">#Get_Report_data_all.M0_Item_Medication#</td>
										<td width="45%">#Get_Report_data_all.Diagnosis#</td>
										<td width="45%">#Get_Report_data_all.Deficits#</td>	
									</tr>
								</cfoutput>			
							<cfelse>
								<tr>
									<td align="center" valign="middle" colspan="4" height="50px">
										No Report Found
									</td>
								</tr>
							</cfif>												
						</table>
					</div>			
			<cfelseif url.report_method eq "2020_PDGM">			
					<div class="row">			
						<div class="row">
							<div>
								<label style="padding-left:0px; font-family: Arial; font-size: 20px;font-weight:bold;">2020 PDGM Coding Wizard-Recommended</label>
							</div>
						</div>
						<br /><br />					
						<table cellpadding="5" border="1" cellspacing="0" width="100%">											
							<tr style="font-family: Arial;">
								<th width="10%" height="80px" width="80px">Skill</th>
								<th width="45%">User-entered Diagnosis List</th>
								<th width="45%">2020 PDGM Analysis and Rationale</th>
							</tr>
							<cfif isdefined('Get_Report_data_all.recordcount') and  Get_Report_data_all.RecordCount GT 0>	
								<cfoutput query="Get_Report_data_all">
									<tr style="font-family: Arial; font-size: 12px;">
										<td width="10%">#Get_Report_data_all.M0_Item_Medication#</td>
										<td width="45%">#Get_Report_data_all.Diagnosis#</td>
										<td width="45%">#Get_Report_data_all.Memo#</td>	
									</tr>
								</cfoutput>														
							<cfelse>
								<tr>
									<td align="center" valign="middle" colspan="4" height="50px">
										No Report Found
									</td>
								</tr>
							</cfif>												
						</table>
					</div>	 
					
			<cfelseif url.report_method eq "View">	
			
					<!---<cfif CGI.REMOTE_ADDR eq "103.66.78.232">
						<cfdump var="#Get_Report_4_datas_User#">
						<cfabort>
					</cfif>--->
			
				<!---		
					<div class="row">			
						<div class="row">
							<div>
								<label style="padding-left:0px; font-family: Arial; font-size: 20px;font-weight:bold;">Visit Plan</label>
							</div>
						</div>
						<br /><br />--->					
						<table cellpadding="5" border="1" cellspacing="0" width="100%">											
							<tr style="font-family: Arial;">
																<th width="100%">User-Entered Utilization and Rationale</th>
							</tr>
							<cfif isdefined('Get_Report_4_datas_User.recordcount') and  Get_Report_4_datas_User.RecordCount GT 0>	
								<cfset Report_4_count_chk = 0 />
								<cfoutput query="Get_Report_4_datas_User" group="Results_ID">
									<cfset Report_4_count_chk = Report_4_count_chk + 1 />
									<tr style="font-family: Arial; font-size: 14px;">
												<cfif #Report_4_count_chk# eq 1>
                                          <td width="100%" rowspan="#Get_Report_4_datas_User.RecordCount#" valign="top">
										  	<cfoutput>												
												<cfif #Get_Report_4_datas_User.Answer_1# neq "">
													#Get_Report_4_datas_User.Answer_1# <br />
												</cfif>												
											</cfoutput>
										  </td>	
                                          <cfelse>
											<td width="100%" style="display:none;"></td>
										</cfif>
									</tr>
								</cfoutput>	
								<cfset Report_4_count_chk = 0 />												
							<cfelse>
								<tr>
									<td align="center" valign="middle" colspan="4" height="50px">
										No Report Found
									</td>
								</tr>
							</cfif>												
						</table>
					</div>
					<!---<br /><br />--->
					<cfdocumentitem type="pagebreak">
            		</cfdocumentitem>
					<div class="row">			
						<div class="row">
							<div>
								<label style="padding-left:0px; font-family: Arial; font-size: 20px;font-weight:bold;">2019 OASIS-D Coding Wizard-Recommended&nbsp;&nbsp;<font color="##0000FF">MEDICARE AVG</font></label>
							</div>
						</div>
						<br />					
						<table cellpadding="5" border="1" cellspacing="0" width="100%">											
							<!---<tr style="font-family: Arial;">
								
								<th width="100%">2019 OASIS D Analysis and Rationale</th>
							</tr>--->
							<cfif isdefined('Get_Report_4_datas.recordcount') and  Get_Report_4_datas.RecordCount GT 0>	
								<cfset Report_4_count_chk_1 = 0 />
								<cfoutput query="Get_Report_4_datas"  group="Results_ID">
									<cfset Report_4_count_chk_1 = Report_4_count_chk_1 + 1 />
									<tr style="font-family: Arial; font-size: 14px;">
										<cfif #Report_4_count_chk_1# eq 1>
											<td width="100%" rowspan="#Get_Report_4_datas.RecordCount#" valign="top">
												<cfoutput>												
													<cfif #Get_Report_4_datas.Field_2# neq "">
														#Get_Report_4_datas.Field_2# <br />
													</cfif>												
												</cfoutput>
											</td>	
										<cfelse>
											<td width="100%" style="display:none;"></td>
										</cfif>										
									</tr>
								</cfoutput>	
								<cfset Report_4_count_chk_1 = 0 />													
							<cfelse>
								<tr>
									<td align="center" valign="middle" colspan="4" height="50px">
										No Report Found
									</td>
								</tr>
							</cfif>												
						</table>
					</div>
					<!---<br /><br />--->
					<cfdocumentitem type="pagebreak">
            		</cfdocumentitem>
					<div class="row">			
						<div class="row">
							<div>
								<label style="padding-left:0px; font-family: Arial; font-size: 20px;font-weight:bold;">2020 PDGM Coding Wizard-Recommended</label>
							</div>
						</div>
						<br />					
						<table cellpadding="5" border="1" cellspacing="0" width="100%">											
							<!---<tr style="font-family: Arial;">
								<th width="70%">2020 PDGM Analysis and Rationale</th>
							</tr>--->
							<cfif isdefined('Get_Report_4_datas.recordcount') and  Get_Report_4_datas.RecordCount GT 0>	
								<cfset Report_4_count_chk_2 = 0 />
								<cfoutput query="Get_Report_4_datas" group="Results_ID">
									<cfset Report_4_count_chk_2 = Report_4_count_chk_2 + 1 />
									<tr style="font-family: Arial; font-size: 14px;">
										<cfif #Report_4_count_chk_2# eq 1>
											<td width="100%" rowspan="#Get_Report_4_datas.RecordCount#" valign="top">
												<cfoutput>												
													<cfif #Get_Report_4_datas.Field_7# neq "">
														#Get_Report_4_datas.Field_7# <br />
													</cfif>												
												</cfoutput>
											</td>	
										<cfelse>
											<td width="100%" style="display:none;"></td>
										</cfif>		
									</tr>
								</cfoutput>	
								<cfset Report_4_count_chk_2 = 0 />													
							<cfelse>
								<tr>
									<td align="center" valign="middle" colspan="4" height="50px">
										No Report Found
									</td>
								</tr>
							</cfif>												
						</table>
					</div>
			</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>

<cfelseif url.report_type EQ 5>

	<cfdocument format="pdf"  localURL = "yes"   margintop=".75" marginbottom="1.25"   orientation="landscape"  overwrite="yes"  filename="/var/www/dashboard/coding_files/#recommended_reports#"   >
	
		<cfdocumentsection>	
		
		<div class="row">
			<div class="row">
				<!---<div class="row">
					<div>
						<label style="padding-left:0px; font-family: Arial; font-size: 20px;font-weight:bold;">REPORT <cfoutput>#url.report_type#</cfoutput> - Visit Plan</label>
					</div>
				</div>
				<br />--->
				
				<div class="row">
					<table cellpadding="0" cellspacing="0" border="0" width="100%">
						<tr>
							<td align="left" width="45%">
								<table cellpadding="0" cellspacing="0" border="0" width="100%">							
									<tr>
										<td height="2px"></td>
									</tr>
									<tr>				
										<td style="padding-left:0px; font-family: Arial; font-size: 28px; font-weight: bold;"><cfoutput>#Get_Assessment_Patient_data.PatientFirst# #Get_Assessment_Patient_data.PatientLast#</cfoutput>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<!---</td>
									</tr>
									<tr>--->	
										<cfoutput>
										<cfset strSomestring = #Get_Assessment_Patient_data.Assessment_Reason_M0100#>
										<cfset SOC_String = find( "Start of care", strSomestring )>	
										<cfset Recertification_String = find( "Recertification", strSomestring )>
										<cfset Resumption_String = find( "Resumption", strSomestring )>
																						
										<td style="padding-left:50px; font-family: Arial; font-size: 24px; font-weight: bold;"><cfif #SOC_String# neq 0>Start of Care<cfelseif #Recertification_String# neq 0>Recertification<cfelseif #Resumption_String# neq 0>Resumption<cfelse>#Get_Assessment_Patient_data.Assessment_Reason_M0100#</cfif> #DateFormat(Get_Assessment_Patient_data.Assessment_Completed_M0090,"mm/dd/yy")#</td>
										</cfoutput>
									</tr>
								</table>
							</td>				
							<!---<td align="right" width="25%">
								<table cellpadding="0" cellspacing="0" border="0" width="100%">
									<tr>
										<td>
										   
										</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="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 />
				
				<cfoutput>
				<cfparam name="Record_Type_Full" default = "">
				<cfif url.OASIS_D_PDGM_Visit eq "">					
				
						<cfif isdefined('Get_Report5_groupby.recordcount') and  Get_Report5_groupby.RecordCount GT 0>	
						   <cfset i = 1 >
							<cfloop query="Get_Report5_groupby">
							
								<cfscript>
									Get_coding_scrub_data_all = dashboard_component.Get_Report5_Visit_based(Patient_ID="#url.patient_id#",Assessment_ID="#url.assessment_id#",Risk_value="#Get_Report5_groupby.Risk#",Message_value="#Get_Report5_groupby.Message#");
								</cfscript>
							
								<cfif isdefined('Get_coding_scrub_data_all.recordcount') and  Get_coding_scrub_data_all.RecordCount GT 0>								
									<div class="row">
										<div>
											<label style="padding-left:50px; font-family: Arial; font-size: 24px;font-weight:bold;">VISIT PLAN FOR #Get_Report5_groupby.Risk#<!--- - #Get_Report5_groupby.Message#---></label>
										</div>
									</div>
									<br />
									<cfloop query="Get_coding_scrub_data_all">	
								   		<cfset i = 1 >						
										<div class="row">
											<div>
												<label style="padding-left:0px; font-family: Arial; font-size: 20px;font-weight:bold;">Visit #Get_coding_scrub_data_all.Message_ID#&nbsp;&nbsp;&nbsp;&nbsp;Goals of Visit: SYMPTOMS ARE MANAGED</label>
											</div>
										</div>
										<div class="row" style="height:10px;">							
										</div>					
										<table cellpadding="5" border="1" cellspacing="0" width="100%">	
											
											<tr style="font-family: Arial; font-size: 13px;">
												<td width="20%">GOALS Of VISIT #Get_coding_scrub_data_all.Message_ID# </td>
												<td width="80%">#Get_coding_scrub_data_all.Answer_1#</td>						
											</tr>
											<tr style="font-family: Arial; font-size: 13px;">
												<td width="20%">ASSESSMENT</td>
												<td width="80%">#Get_coding_scrub_data_all.Answer_2#</td>						
											</tr>		
											<tr style="font-family: Arial; font-size: 13px;">
												<td width="20%">PHYSICIAN FOLLOW-UP</td>
												<td width="80%">#Get_coding_scrub_data_all.GG_1#</td>						
											</tr>	
											<tr style="font-family: Arial; font-size: 13px;">
												<td width="20%">PERFORM</td>
												<td width="80%">#Get_coding_scrub_data_all.GG_2#</td>						
											</tr>
											<tr style="font-family: Arial; font-size: 13px;">
												<td width="20%">PATIENT TEACHING</td>
												<td width="80%">#Get_coding_scrub_data_all.Created_by#</td>						
											</tr>
											
										</table>
										<br />
										<cfset i = i + 1 >
										<cfdocumentitem type="pagebreak">
										</cfdocumentitem>
									</cfloop>
								</cfif>	
					
							</cfloop>
						<cfelse>
							<table>
								<tr>
									<td align="center" valign="middle" colspan="2" height="50px">
										No Report Found
									</td>
								</tr>
							</table>
						</cfif>	
						
				<cfelse>
					<cfset risk_message = url.OASIS_D_PDGM_Visit.Split("~")>	
					<cfset Record_Type_Full = #risk_message[1]#&" - "&#risk_message[2]# />
					<cfscript>
						Groupby_coding_scrub = dashboard_component.Get_Report5_Visit_based(Patient_ID="#url.patient_id#",Assessment_ID="#url.assessment_id#",Risk_value="#risk_message[1]#",Message_value="#risk_message[2]#");
					</cfscript>
                       

					<cfif isdefined('Groupby_coding_scrub.recordcount') and  Groupby_coding_scrub.RecordCount GT 0>	
					   <cfset j = 1 >					   		
					   		<div class="row">
								<div>
									<label style="padding-left:0px; font-family: Arial; font-size: 20px;font-weight:bold;">VISIT PLAN FOR #Record_Type_Full#</label>
								</div>
							</div>
							<br />
						<cfloop query="Groupby_coding_scrub">
							<div class="row">
								<div>
									<!---<label style="padding-left:0px; font-family: Arial; font-size: 20px;font-weight:bold;">Visit #Groupby_coding_scrub.Message_ID#</label>--->
                                    <label style="padding-left:0px; font-family: Arial; font-size: 18px;font-weight:bold;">Visit&nbsp;#Groupby_coding_scrub.Message_ID#&nbsp;<cfif Record_Type_Full contains 'SN'>Goals: Symptoms are managed<cfif #Groupby_coding_scrub.Message_ID# neq 1>;&nbsp;#Groupby_coding_scrub.Subject#</cfif></cfif></label>
								</div>
							</div>
							<div class="row" style="height:10px;">							
							</div>					
							<table cellpadding="5" border="1" cellspacing="0" width="100%">	
								<cfif Record_Type_Full contains 'PT' or Record_Type_Full contains 'OT'>
								<tr style="font-family: Arial; font-size: 13px;">
									<td width="20%">GOALS for VISIT #Message_ID# </td>
									<td width="80%">#Groupby_coding_scrub.Answer_1#</td>					
								</tr></cfif>
								<tr style="font-family: Arial; font-size: 13px;">
									<td width="10%">ASSESSMENT</td>
									<td width="90%">#Groupby_coding_scrub.Answer_2#</td>						
								</tr>		
								<tr style="font-family: Arial; font-size: 13px;">
									<td width="10%">PHYSICIAN FOLLOW-UP</td>
									<td width="90%">#GG_1#</td>						
								</tr>	
								<tr style="font-family: Arial; font-size: 13px;">
									<td width="10%">PERFORM</td>
									<td width="90%">#Groupby_coding_scrub.GG_2#</td>						
								</tr>
								<tr style="font-family: Arial; font-size: 13px;">
									<td width="10%">TEACHING</td>
									<td width="90%">#Groupby_coding_scrub.Created_by#</td>						
								</tr>
								
							</table>
							<br />
							<cfset j = j + 1 >
							<cfdocumentitem type="pagebreak">
							</cfdocumentitem>
						</cfloop>				
					<cfelse>
						<table>
							<tr>
								<td align="center" valign="middle" colspan="2" height="50px">
									No Report Found
								</td>
							</tr>
						</table>
					</cfif>	
					
				</cfif>
						
						
									
				</cfoutput>	
			</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: font-family: Consolas, 'Andale Mono', 'Lucida Console', 'Lucida Sans Typewriter', Monaco, 'Courier New; font-size: 22px; ">
							  <tr>
								<td height="2px"></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;"><cfoutput>#Record_Type_Full#&nbsp;Visit Plan for #Get_Assessment_Patient_data.PatientFirst#&nbsp;#Get_Assessment_Patient_data.PatientLast#</cfoutput><br><cfoutput>page #cfdocument.currentpagenumber#</cfoutput> </td>
							  </tr>
							  <!---<tr>
								<td height="2px"></td>
							  </tr>--->
							</table>
						</td>
					</tr>
				</table>
			</cfdocumentitem>  
		</cfdocumentsection>
	</cfdocument>

</cfif>