<cfparam name="url.redirect_from" default="">
<cfparam name="url.download_all" default="no">
<cfset Redirect_to = #url.redirect_from# />
<cfset session.cs.patientid = #url.ID# />
<cfset Session.CS.PDGM_4 = '#Session.CS.PDGM_4#'/>
<cfset Patient_ID = #url.ID# />
<cfset messageid = 1 />
<cfset Assessment_ID = #url.AID# />
<cfset Request.prefix_db_lookup = 'hhapowerpath' />
<cfset User_Visit_1 = '' />
<cfquery  name="Get_diagnosis" datasource="#Application.DataSrc#">
  select *
  from #Request.prefix_db_agency#.Assessment_New
  where Assessment_ID = #url.AID#
</cfquery>
<cfif Get_diagnosis.HHRG_825_Score gt '15'>
  <cfset OT_User = 15>
  <cfelseif Get_diagnosis.HHRG_825_Score eq ''>
  <cfset OT_User = 0>
  <cfelse>
  <cfset OT_User = Get_diagnosis.HHRG_825_Score>
</cfif>
<cfquery  name="Get_Patient" datasource="#Application.DataSrc#">
select  M1100_Living_Situation
from #Request.prefix_db_agency#.patient
where	Patient_ID = #url.ID#
</cfquery>
<cfif Get_Patient.M1100_Living_Situation contains '01' or Get_Patient.M1100_Living_Situation contains '02' or Get_Patient.M1100_Living_Situation contains '06' or Get_Patient.M1100_Living_Situation contains '07' 
  or Get_Patient.M1100_Living_Situation contains '11' or Get_Patient.M1100_Living_Situation contains '12' >
  <cfset caregiver = 'A'>
  <cfelse>
  <cfset caregiver = 'B'>
</cfif>
<cfif Get_diagnosis.Cog_Function_M0560 contains '3 -' or  Get_diagnosis.Cog_Function_M0560 contains '4 -' or Get_diagnosis.Patient_Behav_Weekly_M0610 contains '2 -'>
  <cfset confusion = 'B'>
  <cfelse>
  <cfset confusion = 'A'>
</cfif>
<cfquery name="Get_User" datasource="#Application.DataSrc#">
    SELECT Assessment_ID, Order_ID, ICD, count(*) AS dxcount
    FROM #Request.prefix_db_agency#.Coding_Results
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Textfield_11 = 'OT'
    and Order_ID = 28
    and Message_ID = 10
    order by Results_ID
    </cfquery>
<cfset CWProbs = Get_User.dxcount>
<cfif CWProbs gt 0 and OT_User gt 0>
  <cfquery name="Get_OT_User" datasource="#Application.DataSrc#">
    SELECT * FROM #Request.prefix_db_lookup#.CW_Visit_Stagger
    where Total_Visits = #OT_User#
    and Total_Dx = '#CWProbs#'
    </cfquery>
  <cfif Get_OT_User.Recordcount gte 1>
    <cfloop query="Get_OT_User">
      <cfquery  name="Insert_Coding_results" datasource="#Application.DataSrc#">
          INSERT IGNORE INTO #Request.prefix_db_agency#.Coding_Scrub
            (Assessment_ID,Patient_ID,Message_ID,Risk,Risk_Type,Message,Subject,Created_Date)
            VALUES (#url.AID#,#url.ID#,'#VisitNo#','OT','#Goals#','User Entered',<cfif caregiver eq 'A'>'Caregiver recalls teaching from prior visit'<cfelseif caregiver eq 'B' and confusion eq 'A'>'Patient recalls teaching from prior visit'<cfelse>'no teachable caregiver; patient is not teachable'</cfif>,'#DateFormat(Now(),"yyyy-mm-dd")#')
        </cfquery>
    </cfloop>
    <cfquery  name="Get_assessment" datasource="#Application.DataSrc#">
    Select Diagnosis, Deficits
    from #Request.prefix_db_agency#.Coding_Results
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
     and Textfield_11 = 'OT'
    and Order_ID = 28
    and Message_ID = 10
      order by Dx_Order
    </cfquery>
    <cfset assessment = '' />
    <cfloop query="Get_assessment">
      <cfset assessment = assessment &'#UCASE(Diagnosis)#'&':'&'#Deficits#'&'<br><br>'>
    </cfloop>
    <cfquery  name="Get_goals" datasource="#Application.DataSrc#">
    Select Diagnosis, Textfield_1
    from #Request.prefix_db_agency#.Coding_Results
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Textfield_11 = 'OT'
    and Order_ID = 28
    and Message_ID = 10
    order by Dx_Order
    </cfquery>
    <cfset goals = '' />
    <cfloop query="Get_goals">
      <cfset goals = goals &'#UCASE(Diagnosis)#'&': '&'#Textfield_1#'&'<br><br>'>
    </cfloop>
  </cfif>
  <cfif OT_User gte 1>
    <cfquery name="Get_Visit_1" datasource="#Application.DataSrc#"> 
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 28
	    and s.Risk = 'OT'
        and v.visit_no = 1
        and v.problems = #CWProbs#
        and v.total_visits = #OT_User#
      </cfquery>
    <cfset CW_Visit_1 = '' />
    <cfloop query="Get_Visit_1">
      <cfset CW_Visit_1 = CW_Visit_1 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
      Update #Request.prefix_db_agency#.Coding_Scrub
      set Created_by = '#CW_Visit_1#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
      <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif> 
      where Assessment_ID = #url.AID#
      and Patient_ID = #url.ID#
      and Message_ID = 1
      and Message = 'User Entered'
      and Risk = 'OT'
    </cfquery>
  </cfif>
  <cfif OT_User gte 2>
    <cfquery name="Get_Visit_2" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 28
	    and s.Risk = 'OT'
        and v.visit_no = 2
        and v.problems = #CWProbs#
        and v.total_visits = #OT_User#
        </cfquery>
    <cfset CW_Visit_2 = '' />
    <cfloop query="Get_Visit_2">
      <cfset CW_Visit_2 = CW_Visit_2 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_2#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 2
        and Message = 'User Entered'
        and Risk = 'OT'
    </cfquery>
    <cfset CW_Visit_1=replace(CW_Visit_1,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_1#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 2
        and Risk = 'OT'
        </cfquery>
  </cfif>
  <cfif OT_User gte 3>
    <cfquery name="Get_Visit_3" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
and r.Dx_order = v.goals
        and r.Order_ID = 28
	and s.Risk = 'OT'
        and v.visit_no = 3
        and v.problems = #CWProbs#
        and v.total_visits = #OT_User#
        </cfquery>
    <cfset CW_Visit_3 = '' />
    <cfloop query="Get_Visit_3">
      <cfset CW_Visit_3 = CW_Visit_3 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_3#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 3
        and Message = 'User Entered'
        and Risk = 'OT'
    </cfquery>
        <cfset CW_Visit_2=replace(CW_Visit_2,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_2#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 3
        and Risk = 'OT'
        </cfquery>
  </cfif>
  <cfif OT_User gte 4>
    <cfquery name="Get_Visit_4" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
and r.Dx_order = v.goals
        and r.Order_ID = 28
	and s.Risk = 'OT'
        and v.visit_no = 4
        and v.problems = #CWProbs#
        and v.total_visits = #OT_User#
        </cfquery>
    <cfset CW_Visit_4 = '' />
    <cfloop query="Get_Visit_4">
      <cfset CW_Visit_4 = CW_Visit_4 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_4#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 4
        and Message = 'User Entered'
        and Risk = 'OT'
    </cfquery>
    <cfset CW_Visit_3=replace(CW_Visit_3,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_3#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 4
        and Risk = 'OT'
        </cfquery>
  </cfif>
  <cfif OT_User gte 5>
    <cfquery name="Get_Visit_5" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
and r.Dx_order = v.goals
        and r.Order_ID = 28
	and s.Risk = 'OT'
        and v.visit_no = 5
        and v.problems = #CWProbs#
        and v.total_visits = #OT_User#
        </cfquery>
    <cfset CW_Visit_5 = '' />
    <cfloop query="Get_Visit_5">
      <cfset CW_Visit_5 = CW_Visit_5 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_5#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 5
        and Message = 'User Entered'
        and Risk = 'OT'
    </cfquery>
    <cfset CW_Visit_4=replace(CW_Visit_4,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_4#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 5
        and Risk = 'OT'
        </cfquery>
  </cfif>
  <cfif OT_User gte 6>
    <cfquery name="Get_Visit_6" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 28
	    and s.Risk = 'OT'
        and v.visit_no = 6
        and v.problems = #CWProbs#
        and v.total_visits = #OT_User#
        </cfquery>
    <cfset CW_Visit_6 = '' />
    <cfloop query="Get_Visit_6">
      <cfset CW_Visit_6 = CW_Visit_6 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_6#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 6
        and Message = 'User Entered'
        and Risk = 'OT'
    </cfquery>
    <cfset CW_Visit_5=replace(CW_Visit_5,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_5#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 6
        and Risk = 'OT'
        </cfquery>
  </cfif>
  <cfif OT_User gte 7>
    <cfquery name="Get_Visit_7" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 28
	    and s.Risk = 'OT'
        and v.visit_no = 7
        and v.problems = #CWProbs#
        and v.total_visits = #OT_User#
        </cfquery>
    <cfset CW_Visit_7 = '' />
    <cfloop query="Get_Visit_7">
      <cfset CW_Visit_7 = CW_Visit_7 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_7#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 7
        and Message = 'User Entered'
        and Risk = 'OT'
    </cfquery>
    <cfset CW_Visit_6=replace(CW_Visit_6,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_6#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 7
        and Risk = 'OT'
        </cfquery>
  </cfif>
  <cfif OT_User gte 8>
    <cfquery name="Get_Visit_8" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 28
	    and s.Risk = 'OT'
        and v.visit_no = 8
        and v.problems = #CWProbs#
        and v.total_visits = #OT_User#
        </cfquery>
    <cfset CW_Visit_8 = '' />
    <cfloop query="Get_Visit_8">
      <cfset CW_Visit_8 = CW_Visit_8 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_8#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 8
        and Message = 'User Entered'
        and Risk = 'OT'
    </cfquery>
    <cfset CW_Visit_7=replace(CW_Visit_7,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_7#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 8
        and Risk = 'OT'
        </cfquery>
  </cfif>
  <cfif OT_User gte 9>
    <cfquery name="Get_Visit_9" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 28
	    and s.Risk = 'OT'
        and v.visit_no = 9
        and v.problems = #CWProbs#
        and v.total_visits = #OT_User#
        </cfquery>
    <cfset CW_Visit_9 = '' />
    <cfloop query="Get_Visit_9">
      <cfset CW_Visit_9 = CW_Visit_9 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_9#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 9
        and Message = 'User Entered'
        and Risk = 'OT'
    </cfquery>
    <cfset CW_Visit_8=replace(CW_Visit_8,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_8#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 9
        and Risk = 'OT'
        </cfquery>
  </cfif>
  <cfif OT_User gte 10>
    <cfquery name="Get_Visit_10" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 28
	    and s.Risk = 'OT'
        and v.visit_no = 10
        and v.problems = #CWProbs#
        and v.total_visits = #OT_User#
        </cfquery>
    <cfset CW_Visit_10 = '' />
    <cfloop query="Get_Visit_10">
      <cfset CW_Visit_10 = CW_Visit_10 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_10#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 10
        and Message = 'User Entered'
        and Risk = 'OT'
    </cfquery>
    <cfset CW_Visit_9=replace(CW_Visit_9,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_9#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 10
        and Risk = 'OT'
        </cfquery>
  </cfif>
  <cfif OT_User gte 11>
    <cfquery name="Get_Visit_11" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 28
	    and s.Risk = 'OT'
        and v.visit_no = 11
        and v.problems = #CWProbs#
        and v.total_visits = #OT_User#
        </cfquery>
    <cfset CW_Visit_11 = '' />
    <cfloop query="Get_Visit_11">
      <cfset CW_Visit_11 = CW_Visit_11 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_11#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 11
        and Message = 'User Entered'
        and Risk = 'OT'
    </cfquery>
    <cfset CW_Visit_10=replace(CW_Visit_10,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_10#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 11
        and Risk = 'OT'
        </cfquery>
  </cfif>
  <cfif OT_User gte 12>
    <cfquery name="Get_Visit_12" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 28
	    and s.Risk = 'OT'
        and v.visit_no = 12
        and v.problems = #CWProbs#
        and v.total_visits = #OT_User#
        </cfquery>
    <cfset CW_Visit_12 = '' />
    <cfloop query="Get_Visit_12">
      <cfset CW_Visit_12 = CW_Visit_12 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_12#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 12
        and Message = 'User Entered'
        and Risk = 'OT'
    </cfquery>
    <cfset CW_Visit_11=replace(CW_Visit_11,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_11#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 12
        and Risk = 'OT'
        </cfquery>
  </cfif>
<cfif OT_User gte 13>
    <cfquery name="Get_Visit_13" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 28
	    and s.Risk = 'OT'
        and v.visit_no = 13
        and v.problems = #CWProbs#
        and v.total_visits = #OT_User#
        </cfquery>
    <cfset CW_Visit_13 = '' />
    <cfloop query="Get_Visit_13">
      <cfset CW_Visit_13 = CW_Visit_13 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_13#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 13
        and Message = 'User Entered'
        and Risk = 'OT'
    </cfquery>
    <cfset CW_Visit_12=replace(CW_Visit_12,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_12#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 13
        and Risk = 'OT'
        </cfquery>
  </cfif>
  <cfif OT_User gte 14>
    <cfquery name="Get_Visit_14" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 28
	    and s.Risk = 'OT'
        and v.visit_no = 14
        and v.problems = #CWProbs#
        and v.total_visits = #OT_User#
        </cfquery>
    <cfset CW_Visit_14 = '' />
    <cfloop query="Get_Visit_14">
      <cfset CW_Visit_14 = CW_Visit_14 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_14#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 14
        and Message = 'User Entered'
        and Risk = 'OT'
    </cfquery>
    <cfset CW_Visit_13=replace(CW_Visit_13,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_13#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 14
        and Risk = 'OT'
        </cfquery>
  </cfif>
  <cfif OT_User gte 15>
    <cfquery name="Get_Visit_15" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 28
	    and s.Risk = 'OT'
        and v.visit_no = 15
        and v.problems = #CWProbs#
        and v.total_visits = #OT_User#
        </cfquery>
    <cfset CW_Visit_15 = '' />
    <cfloop query="Get_Visit_15">
      <cfset CW_Visit_15 = CW_Visit_15 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_15#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 15
        and Message = 'User Entered'
        and Risk = 'OT'
    </cfquery>
    <cfset CW_Visit_14=replace(CW_Visit_14,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_14#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 15
        and Risk = 'OT'
        </cfquery>
  </cfif>
</cfif>
<cfset CWProbs = ''>
<!---NOW GET PT--->
<cfif Get_diagnosis.HHRG_700_Score gt '15'>
  <cfset PT_User = 15>
  <cfelseif Get_diagnosis.HHRG_700_Score eq ''>
  <cfset PT_User = 0>
  <cfelse>
  <cfset PT_User = Get_diagnosis.HHRG_700_Score>
</cfif>
<cfquery name="Get_User_PT" datasource="#Application.DataSrc#">
    SELECT Assessment_ID, Order_ID, ICD, count(*) AS dxcount
    FROM #Request.prefix_db_agency#.Coding_Results
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Textfield_11 = 'PT'
    and Order_ID = 29
    and Message_ID = 10
    order by Results_ID
    </cfquery>
<cfset CWProbs = Get_User_PT.dxcount>
<cfif CWProbs gt 0 and PT_User gt 0>
  <cfquery name="Get_PT_User" datasource="#Application.DataSrc#">
    SELECT * FROM #Request.prefix_db_lookup#.CW_Visit_Stagger
    where Total_Visits = #PT_User#
    and Total_Dx = #CWProbs#
    </cfquery>
  <cfif Get_PT_User.Recordcount gte 1>
    <cfloop query="Get_PT_User">
      <cfquery  name="Insert_Coding_results" datasource="#Application.DataSrc#">
          INSERT IGNORE INTO #Request.prefix_db_agency#.Coding_Scrub
            (Assessment_ID,Patient_ID,Message_ID,Risk,Risk_Type,Message,Subject,Created_Date)
            VALUES (#url.AID#,#url.ID#,'#VisitNo#','PT','#Goals#','User Entered',<cfif caregiver eq 'A'>'Caregiver recalls teaching from prior visit'<cfelseif caregiver eq 'B' and confusion eq 'A'>'Patient recalls teaching from prior visit'<cfelse>'no teachable caregiver; patient is not teachable'</cfif>,'#DateFormat(Now(),"yyyy-mm-dd")#')
        </cfquery>
    </cfloop>
    <!--- <cfif CGI.REMOTE_ADDR EQ '103.136.137.35'><cfabort>
          </cfif> --->
    <cfquery  name="Get_assessment" datasource="#Application.DataSrc#">
    Select Diagnosis, Deficits
    from #Request.prefix_db_agency#.Coding_Results
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
     and Textfield_11 = 'PT'
    and Order_ID = 29
    and Message_ID = 10
      order by Dx_Order
    </cfquery>
    <cfset assessment = '' />
    <cfloop query="Get_assessment">
      <cfset assessment = assessment &'#UCASE(Diagnosis)#'&':'&'#Deficits#'&'<br><br>'>
    </cfloop>
    <cfquery  name="Get_goals" datasource="#Application.DataSrc#">
      Select Diagnosis, Textfield_1
      from #Request.prefix_db_agency#.Coding_Results
      where Assessment_ID = #url.AID#
      and Patient_ID = #url.ID#
      and Textfield_11 = 'PT'
      and Order_ID = 29
      and Message_ID = 10
      order by Dx_Order
    </cfquery>
    <cfset goals = '' />
    <cfloop query="Get_goals">
      <cfset goals = goals &'#UCASE(Diagnosis)#'&': '&'#Textfield_1#'&'<br><br>'>
    </cfloop>
  </cfif>
  <cfif PT_User gte 1>
    <cfquery name="Get_Visit_1" datasource="#Application.DataSrc#"> 
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID        
        and r.Dx_order = v.goals
        and r.Order_ID = 29
	    and s.Risk = 'PT'
        and v.visit_no = 1
        and v.problems = #CWProbs#
        and v.total_visits = #PT_User#
      </cfquery>
    <cfset CW_Visit_1 = '' />
    <cfloop query="Get_Visit_1">
      <cfset CW_Visit_1 = CW_Visit_1 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
      Update #Request.prefix_db_agency#.Coding_Scrub
      set Created_by = '#CW_Visit_1#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
      <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif> 
      where Assessment_ID = #url.AID#
      and Patient_ID = #url.ID#
      and Message_ID = 1
      and Message = 'User Entered'
      and Risk = 'PT'
    </cfquery>
  </cfif>
  <cfif PT_User gte 2>
    <cfquery name="Get_Visit_2" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 29
	    and s.Risk = 'PT'
        and v.visit_no = 2
        and v.problems = #CWProbs#
        and v.total_visits = #PT_User#
        </cfquery>
    <cfset CW_Visit_2 = '' />
    <cfloop query="Get_Visit_2">
      <cfset CW_Visit_2 = CW_Visit_2 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_2#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 2
        and Message = 'User Entered'
        and Risk = 'PT'
    </cfquery>
    <cfset CW_Visit_1=replace(CW_Visit_1,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_1#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 2
        and Risk = 'PT'
        </cfquery>
  </cfif>
  <cfif PT_User gte 3>
    <cfquery name="Get_Visit_3" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 29
	    and s.Risk = 'PT'
        and v.visit_no = 3
        and v.problems = #CWProbs#
        and v.total_visits = #PT_User#
        </cfquery>
    <cfset CW_Visit_3 = '' />
    <cfloop query="Get_Visit_3">
      <cfset CW_Visit_3 = CW_Visit_3 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_3#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 3
        and Message = 'User Entered'
        and Risk = 'PT'
    </cfquery>
    <cfset CW_Visit_2=replace(CW_Visit_2,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_2#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 3
        and Risk = 'PT'
        </cfquery>
  </cfif>
  <cfif PT_User gte 4>
    <cfquery name="Get_Visit_4" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 29
	    and s.Risk = 'PT'
        and v.visit_no = 4
        and v.problems = #CWProbs#
        and v.total_visits = #PT_User#
        </cfquery>
    <cfset CW_Visit_4 = '' />
    <cfloop query="Get_Visit_4">
      <cfset CW_Visit_4 = CW_Visit_4 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_4#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 4
        and Message = 'User Entered'
        and Risk = 'PT'
    </cfquery>
    <cfset CW_Visit_3=replace(CW_Visit_3,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_3#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 4
        and Risk = 'PT'
        </cfquery>
  </cfif>
  <cfif PT_User gte 5>
    <cfquery name="Get_Visit_5" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 29
	    and s.Risk = 'PT'
        and v.visit_no = 5
        and v.problems = #CWProbs#
        and v.total_visits = #PT_User#
        </cfquery>
    <cfset CW_Visit_5 = '' />
    <cfloop query="Get_Visit_5">
      <cfset CW_Visit_5 = CW_Visit_5 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_5#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 5
        and Message = 'User Entered'
        and Risk = 'PT'
    </cfquery>
    <cfset CW_Visit_4=replace(CW_Visit_4,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_4#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 5
        and Risk = 'PT'
        </cfquery>
  </cfif>
  <cfif PT_User gte 6>
    <cfquery name="Get_Visit_6" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 29
	    and s.Risk = 'PT'
        and v.visit_no = 6
        and v.problems = #CWProbs#
        and v.total_visits = #PT_User#
        </cfquery>
    <cfset CW_Visit_6 = '' />
    <cfloop query="Get_Visit_6">
      <cfset CW_Visit_6 = CW_Visit_6 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_6#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 6
        and Message = 'User Entered'
        and Risk = 'PT'
    </cfquery>
    <cfset CW_Visit_5=replace(CW_Visit_5,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_5#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 6
        and Risk = 'PT'
        </cfquery>
  </cfif>
  <cfif PT_User gte 7>
    <cfquery name="Get_Visit_7" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 29
	    and s.Risk = 'PT'
        and v.visit_no = 7
        and v.problems = #CWProbs#
        and v.total_visits = #PT_User#
        </cfquery>
    <cfset CW_Visit_7 = '' />
    <cfloop query="Get_Visit_7">
      <cfset CW_Visit_7 = CW_Visit_7 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_7#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 7
        and Message = 'User Entered'
        and Risk = 'PT'
    </cfquery>
    <cfset CW_Visit_6=replace(CW_Visit_6,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_6#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 7
        and Risk = 'PT'
        </cfquery>
  </cfif>
  <cfif PT_User gte 8>
    <cfquery name="Get_Visit_8" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 29
	    and s.Risk = 'PT'
        and v.visit_no = 8
        and v.problems = #CWProbs#
        and v.total_visits = #PT_User#
        </cfquery>
    <cfset CW_Visit_8 = '' />
    <cfloop query="Get_Visit_8">
      <cfset CW_Visit_8 = CW_Visit_8 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_8#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 8
        and Message = 'User Entered'
        and Risk = 'PT'
    </cfquery>
    <cfset CW_Visit_7=replace(CW_Visit_7,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_7#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 8
        and Risk = 'PT'
        </cfquery>
  </cfif>
  <cfif PT_User gte 9>
    <cfquery name="Get_Visit_9" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 29
	    and s.Risk = 'PT'
        and v.visit_no = 9
        and v.problems = #CWProbs#
        and v.total_visits = #PT_User#
        </cfquery>
    <cfset CW_Visit_9 = '' />
    <cfloop query="Get_Visit_9">
      <cfset CW_Visit_9 = CW_Visit_9 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_9#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 9
        and Message = 'User Entered'
        and Risk = 'PT'
    </cfquery>
    <cfset CW_Visit_8=replace(CW_Visit_8,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_8#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 9
        and Risk = 'PT'
        </cfquery>
  </cfif>
  <cfif PT_User gte 10>
    <cfquery name="Get_Visit_10" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 29
	    and s.Risk = 'PT'
        and v.visit_no = 10
        and v.problems = #CWProbs#
        and v.total_visits = #PT_User#
        </cfquery>
    <cfset CW_Visit_10 = '' />
    <cfloop query="Get_Visit_10">
      <cfset CW_Visit_10 = CW_Visit_10 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_10#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 10
        and Message = 'User Entered'
        and Risk = 'PT'
    </cfquery>
    <cfset CW_Visit_9=replace(CW_Visit_9,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_9#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 10
        and Risk = 'PT'
        </cfquery>
  </cfif>
  <cfif PT_User gte 11>
    <cfquery name="Get_Visit_11" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 29
	    and s.Risk = 'PT'
        and v.visit_no = 11
        and v.problems = #CWProbs#
        and v.total_visits = #PT_User#
        </cfquery>
    <cfset CW_Visit_11 = '' />
    <cfloop query="Get_Visit_11">
      <cfset CW_Visit_11 = CW_Visit_11 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_11#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 11
        and Message = 'User Entered'
        and Risk = 'PT'
    </cfquery>
    <cfset CW_Visit_10=replace(CW_Visit_10,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_11#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 11
        and Risk = 'PT'
        </cfquery>
  </cfif>
  <cfif PT_User gte 12>
    <cfquery name="Get_Visit_12" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 29
	    and s.Risk = 'PT'
        and v.visit_no = 12
        and v.problems = #CWProbs#
        and v.total_visits = #PT_User#
        </cfquery>
    <cfset CW_Visit_12 = '' />
    <cfloop query="Get_Visit_12">
      <cfset CW_Visit_12 = CW_Visit_12 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_12#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 12
        and Message = 'User Entered'
        and Risk = 'PT'
    </cfquery>
    <cfset CW_Visit_11=replace(CW_Visit_11,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_11#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 12
        and Risk = 'PT'
        </cfquery>
  </cfif>
<cfif PT_User gte 13>
    <cfquery name="Get_Visit_13" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 29
	    and s.Risk = 'PT'
        and v.visit_no = 13
        and v.problems = #CWProbs#
        and v.total_visits = #PT_User#
        </cfquery>
    <cfset CW_Visit_13 = '' />
    <cfloop query="Get_Visit_13">
      <cfset CW_Visit_13 = CW_Visit_13 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_13#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 13
        and Message = 'User Entered'
        and Risk = 'PT'
    </cfquery>
    <cfset CW_Visit_12=replace(CW_Visit_12,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_12#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 13
        and Risk = 'PT'
        </cfquery>
  </cfif>
  <cfif PT_User gte 14>
    <cfquery name="Get_Visit_14" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 29
	    and s.Risk = 'PT'
        and v.visit_no = 14
        and v.problems = #CWProbs#
        and v.total_visits = #PT_User#
        </cfquery>
    <cfset CW_Visit_14 = '' />
    <cfloop query="Get_Visit_14">
      <cfset CW_Visit_14 = CW_Visit_14 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_14#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 14
        and Message = 'User Entered'
        and Risk = 'PT'
    </cfquery>
    <cfset CW_Visit_13=replace(CW_Visit_13,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_13#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 14
        and Risk = 'PT'
        </cfquery>
  </cfif>
  <cfif PT_User gte 15>
    <cfquery name="Get_Visit_15" datasource="#Application.DataSrc#">   
        SELECT r.Diagnosis, r.Textfield_14 FROM #Request.prefix_db_agency#.Coding_Scrub s
        LEFT OUTER JOIN #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail v ON s.Message_ID = v.visit_no
        JOIN #Request.prefix_db_agency#.Coding_Results r ON r.Dx_order = v.goals
        where s.Assessment_ID = #url.AID#
        and s.Patient_ID = #url.ID#        
        and r.Assessment_ID = s.Assessment_ID
        and r.Dx_order = v.goals
        and r.Order_ID = 29
	    and s.Risk = 'PT'
        and v.visit_no = 15
        and v.problems = #CWProbs#
        and v.total_visits = #PT_User#
        </cfquery>
    <cfset CW_Visit_15 = '' />
    <cfloop query="Get_Visit_15">
      <cfset CW_Visit_15 = CW_Visit_15 &'#UCASE(Diagnosis)#'&': '&'#Textfield_14#'&'<br><br>'>
    </cfloop>
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Created_by = '#CW_Visit_15#', Answer_1 = '#goals#',Answer_2 = '#assessment#', GG_1 = 'report unstable symptoms to physician; implement changes to physician orders', GG_2 = <cfif caregiver eq 'B' and confusion eq 'A'>'since patient does not have teachable caregiver document challenges of teaching patient symptom monitoring and preventive care all while patient must manage ADLs with minimal or no assistance'
        <cfelseif caregiver eq 'B' and confusion eq 'B'>'since patient is not teachable and does not have teachable caregiver document challenges of achieving stable symptoms and the need for long-term monitoring'<cfelse>'document unstable symptoms and success of caregiver recall'</cfif>
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 15
        and Message = 'User Entered'
        and Risk = 'PT'
    </cfquery>
    <cfset CW_Visit_14=replace(CW_Visit_14,'TEACH patient','RECALL','All') />
    <cfquery  name="update" datasource="#Application.DataSrc#">
        Update #Request.prefix_db_agency#.Coding_Scrub
        set Field_12 = '#CW_Visit_14#'
        where Assessment_ID = #url.AID#
        and Patient_ID = #url.ID#
        and Message_ID = 15
        and Risk = 'PT'
        </cfquery>
  </cfif>
</cfif>
<cfquery name="Get_HHA" datasource="#Application.DataSrc#">
   SELECT HHA_Visit_Count from #Request.prefix_db_agency#.Assessment_New
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
        and HHA_Visit_Count > 0
</cfquery>
<cfif Get_HHA.Recordcount gt 0>
  <cfif Get_HHA.HHA_Visit_Count gt 20>
    <cfset HHA_visits = 20>
    <cfelse>
    <cfset HHA_visits = Get_HHA.HHA_Visit_Count>
  </cfif>
  <cfquery name="User_HHA" datasource="#Application.DataSrc#">
   SELECT * from #Request.prefix_db_lookup#.CW_Visit_Stagger_Detail
    where problems = 1
    and total_visits = '#HHA_visits#'
</cfquery>
  <cfquery name="Get_HHA_1" datasource="#Application.DataSrc#">   
    SELECT Textfield_14 FROM #Request.prefix_db_agency#.Coding_Results
      where Assessment_ID = #url.AID#
      and Patient_ID = #url.ID#
      and (Order_ID = 30)
    and Message_ID = 10
    </cfquery>
  <cfset H_List = '' />
  <cfloop query="Get_HHA_1">
    <cfset H_List = H_List & '#Textfield_14#'&'<br><br>'>
  </cfloop>
  <cfif Get_HHA_1.Recordcount gte 1>
    <cfloop query="User_HHA">
      <cfquery  name="Insert_Coding_results" datasource="#Application.DataSrc#">
          INSERT IGNORE INTO #Request.prefix_db_agency#.Coding_Scrub
            (Assessment_ID,Patient_ID,Message_ID,Risk,Risk_Type,Message,GG_2,Created_Date)
           VALUES (#Assessment_ID#,#Patient_ID#,'#visit_no#','HHA','1','User entered','#H_List#','#DateFormat(Now(),"yyyy-mm-dd")#')
        </cfquery>
    </cfloop>
  </cfif>
</cfif>
<!---<cfif CGI.REMOTE_ADDR EQ '103.136.137.35'>
    <cfabort>
 </cfif>  --->  
<cfif url.download_all eq 'no'> 
        <cfif #Redirect_to# eq "Recomen_Visit_Schedule_Report">
          <cfset Encrypted_patient_ID=encrypt(#url.ID#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
          <cfset Encrypted_Ass_ID_Report4=encrypt(#url.AID#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
          <cfset Encrypted_Report4_Type=encrypt(4,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
          <cfset Encrypted_Report4_view=encrypt("View","54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
          <cflocation url="../dashboard/index.cfm?page=dashboard&cat&rpt=Recomended_Diagnoses_Report&patient_id=#Encrypted_patient_ID#&assessment_id=#Encrypted_Ass_ID_Report4#&report_type=#Encrypted_Report4_Type#&report_method=#Encrypted_Report4_view#" addtoken="no">
          <cfelse>
          <cflocation url="../dashboard/index.cfm?page=dashboard&cat=dashboard&rpt=coding_wizard_dashboard" addtoken="no">
        </cfif>
      </cfif>
