<cfparam name="url.redirect_from" default="">
<cfset Redirect_to = #url.redirect_from# />
<cfset session.cs.patientid = #url.ID# />
<cfset Patient_ID = #url.ID# />
<cfset Assessment_ID = #url.AID# />
<cfset Session.CS.Count_Thpy = #Session.CS.Count_Thpy# />
<cfset Caregiver = #Session.CS.Caregiver#/>
<cfset Confusion = #Session.CS.Confusion#/>
<cfset Request.prefix_db_lookup = 'hhapowerpath' />
<cfset All_Assess = '' />
<cfset All_Goal = '' />
<cfset Goal_1 = '' />
<cfset Goal_2 = '' />
<cfset Goal_3 = '' />
<cfset Goal_4 = '' />
<cfset Goal_5 = '' />
<cfset Goal_6 = '' />
<cfset Intv_1 = '' />
<cfset Intv_2 = '' />
<cfset Intv_3 = '' />
<cfset Intv_4 = '' />
<cfset Intv_5 = '' />
<cfset Intv_6 = '' />
<cfquery  name="get_max_dx" datasource="#Application.DataSrc#">
  	SELECT Max(Question_ID) as MAX from #Request.prefix_db_agency#.Coding_Results
  	where Assessment_ID = #url.AID#
  	and Patient_ID = #url.ID#
  </cfquery>
<cfset MAX = #get_max_dx.MAX#>
<cfif MAX gte 1>
  <cfquery name="Get_Path1" datasource="#Application.DataSrc#">
    SELECT c.Dx_order, c.Diagnosis, c.Message_ID, c.Memo, c.Deficits, i.Teach_Patient
    FROM #Request.prefix_db_agency#.Coding_Results c, #Request.prefix_db_lookup#.CW_Coding_Class_PDGM i
    where c.Assessment_ID = #url.AID#
    and c.Patient_ID = #url.ID#
    and c.Question_ID = 1
    and c.Order_ID = i.Priority
    </cfquery>
  <cfif Caregiver eq 'A'>
    <cfloop query="Get_Path1">
      <cfset Goal_1 = Goal_1 &'caregiver accurately recalls '&'#Teach_Patient#'&'<br>'>
      <cfset Intv_1 = Intv_1 &'TEACH caregiver '&'#Teach_Patient#'&'<br>'>
    </cfloop>
    <cfelseif Caregiver eq 'B' and Confusion eq 'A'>
    <cfloop query="Get_Path1">
      <cfset Goal_1 = Goal_1 &'patient accurately recalls '&'#Teach_Patient#'&'<br>'>
      <cfset Intv_1 = Intv_1 &'TEACH patient '&'#Teach_Patient#'&'<br>'>
    </cfloop>
    <cfelseif Caregiver eq 'B' and Confusion eq 'B'>
    <cfset Goal_1 = ''>
    <cfset Intv_1 = ''>
  </cfif>
  <cfquery  name="update" datasource="#Application.DataSrc#">
    Update #Request.prefix_db_agency#.Coding_Results
    set Textfield_9 = <cfif Caregiver eq 'A'>'PATIENT HAS A TEACHABLE CAREGIVER AVAILABLE DURING THE DAY. CAREGIVER WILL BE TAUGHT SYMPTOM MANAGEMENT AND DISEASE PREVENTION.'<cfelseif Caregiver eq 'B' and Confusion eq 'A'>'PATIENT HAS NO TEACHABLE CAREGIVER AVAILABLE DURING THE DAY. PATIENT WILL BE TAUGHT SYMPTOM MANAGEMENT AND DISEASE PREVENTION.'<cfelseif Caregiver eq 'B' and Confusion eq 'B'>'PATIENT IS CONFUSED AND DOES NOT HAVE A TEACHABLE CAREGIVER. LONG-TERM SYMPTOM MONITORING AND DISEASE MANAGEMENT POSSIBLE.'</cfif>,
    Memo = concat('#Get_Path1.Memo#','; ', '#Goal_1#'),
    Textfield_12 = concat('#UCASE(Get_Path1.Diagnosis)#',': MONITOR patient for ','#Get_Path1.Deficits#','; ','#Intv_1#'), Textfield_14 = '#Intv_1#'
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
     and Question_ID = 1
      and M0_Item_Medication like '%M102%'
    </cfquery>
</cfif>
<cfif MAX gte 2>
  <cfquery name="Get_Path2" datasource="#Application.DataSrc#">
    SELECT c.Dx_order, c.Diagnosis, c.Message_ID, c.Memo, c.Deficits, i.Teach_Patient
    FROM #Request.prefix_db_agency#.Coding_Results c, #Request.prefix_db_lookup#.CW_Coding_Class_PDGM i
    where c.Assessment_ID = #url.AID#
    and c.Patient_ID = #url.ID#
    and c.Question_ID = 2
    and c.Order_ID = i.Priority
    </cfquery>
  <cfif Caregiver eq 'A'>
    <cfloop query="Get_Path2">
      <cfset Goal_2 = Goal_2 &'caregiver accurately recalls '&'#Teach_Patient#'&'<br>'>
      <cfset Intv_2 = Intv_2 &'TEACH caregiver '&'#Teach_Patient#'&'<br>'>
    </cfloop>
    <cfelseif Caregiver eq 'B' and Confusion eq 'A'>
    <cfloop query="Get_Path2">
      <cfset Goal_2 = Goal_2 &'patient accurately recalls '&'#Teach_Patient#'&'<br>'>
      <cfset Intv_2 = Intv_2 &'TEACH patient '&'#Teach_Patient#'&'<br>'>
    </cfloop>
    <cfelseif Caregiver eq 'B' and Confusion eq 'B'>
    <cfset Goal_2 = ''>
    <cfset Intv_2 = ''>
  </cfif>
  <cfquery  name="update" datasource="#Application.DataSrc#">
    Update #Request.prefix_db_agency#.Coding_Results
    set Memo = concat('#Get_Path2.Memo#','; ', '#Goal_2#'),
    Textfield_12 = concat('#UCASE(Get_Path2.Diagnosis)#',': MONITOR patient for ','#Get_Path2.Deficits#','; ','#Intv_2#'), Textfield_14 = '#Intv_2#'
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
     and Question_ID = 2
      and M0_Item_Medication like '%M102%'
    </cfquery>
</cfif>
<cfif MAX gte 3>
  <cfquery name="Get_Path3" datasource="#Application.DataSrc#">
    SELECT c.Dx_order, c.Diagnosis, c.Message_ID, c.Memo, c.Deficits, i.Teach_Patient
    FROM #Request.prefix_db_agency#.Coding_Results c, #Request.prefix_db_lookup#.CW_Coding_Class_PDGM i
    where c.Assessment_ID = #url.AID#
    and c.Patient_ID = #url.ID#
    and c.Question_ID = 3
     and c.Order_ID = i.Priority
    </cfquery>
  <cfif Caregiver eq 'A'>
    <cfloop query="Get_Path3">
      <cfset Goal_3 = Goal_3 &'caregiver accurately recalls '&'#Teach_Patient#'&'<br>'>
      <cfset Intv_3 = Intv_3 &'TEACH caregiver '&'#Teach_Patient#'&'<br>'>
    </cfloop>
    <cfelseif Caregiver eq 'B' and Confusion eq 'A'>
    <cfloop query="Get_Path3">
      <cfset Goal_3 = Goal_3 &'patient accurately recalls '&'#Teach_Patient#'&'<br>'>
      <cfset Intv_3 = Intv_3 &'TEACH patient '&'#Teach_Patient#'&'<br>'>
    </cfloop>
    <cfelseif Caregiver eq 'B' and Confusion eq 'B'>
    <cfset Goal_3 = ''>
    <cfset Intv_3 = ''>
  </cfif>
  <cfquery  name="update" datasource="#Application.DataSrc#">
    Update #Request.prefix_db_agency#.Coding_Results
    set Memo = concat('#Get_Path3.Memo#','; ', '#Goal_3#'),
    Textfield_12 = concat('#UCASE(Get_Path3.Diagnosis)#',': MONITOR patient for ','#Get_Path3.Deficits#','; ','#Intv_3#'), Textfield_14 = '#Intv_3#'
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
     and Question_ID = 3
      and M0_Item_Medication like '%M102%'
    </cfquery>
</cfif>
<cfif MAX gte 4>
  <cfquery name="Get_Path4" datasource="#Application.DataSrc#">
    SELECT c.Dx_order, c.Diagnosis, c.Message_ID, c.Memo, c.Deficits, i.Teach_Patient
    FROM #Request.prefix_db_agency#.Coding_Results c, #Request.prefix_db_lookup#.CW_Coding_Class_PDGM i
    where c.Assessment_ID = #url.AID#
    and c.Patient_ID = #url.ID#
    and c.Question_ID = 4
 and c.Order_ID = i.Priority
    </cfquery>
  <cfif Caregiver eq 'A'>
    <cfloop query="Get_Path4">
      <cfset Goal_4 = Goal_4 &'caregiver accurately recalls '&'#Teach_Patient#'&'<br>'>
      <cfset Intv_4 = Intv_4 &'TEACH caregiver '&'#Teach_Patient#'&'<br>'>
    </cfloop>
    <cfelseif Caregiver eq 'B' and Confusion eq 'A'>
    <cfloop query="Get_Path4">
      <cfset Goal_4 = Goal_4 &'patient accurately recalls '&'#Teach_Patient#'&'<br>'>
      <cfset Intv_4 = Intv_4 &'TEACH patient '&'#Teach_Patient#'&'<br>'>
    </cfloop>
    <cfelseif Caregiver eq 'B' and Confusion eq 'B'>
    <cfset Goal_4 = ''>
    <cfset Intv_4 = ''>
  </cfif>
  <cfquery  name="update" datasource="#Application.DataSrc#">
    Update #Request.prefix_db_agency#.Coding_Results
    set Memo = concat('#Get_Path4.Memo#','; ', '#Goal_4#'),
    Textfield_12 = concat('#UCASE(Get_Path4.Diagnosis)#',': MONITOR patient for ','#Get_Path4.Deficits#','; ','#Intv_4#'), Textfield_14 = '#Intv_4#'
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
     and Question_ID = 4
      and M0_Item_Medication like '%M102%'
    </cfquery>
</cfif>
<cfif MAX gte 5>
  <cfquery name="Get_Path5" datasource="#Application.DataSrc#">
    SELECT c.Dx_order, c.Diagnosis, c.Message_ID, c.Memo, c.Deficits, i.Teach_Patient
    FROM #Request.prefix_db_agency#.Coding_Results c, #Request.prefix_db_lookup#.CW_Coding_Class_PDGM i
    where c.Assessment_ID = #url.AID#
    and c.Patient_ID = #url.ID#
    and c.Question_ID = 5
  and c.Order_ID = i.Priority
    </cfquery>
  <cfif Caregiver eq 'A'>
    <cfloop query="Get_Path5">
      <cfset Goal_5 = Goal_5 &'caregiver accurately recalls '&'#Teach_Patient#'&'<br>'>
      <cfset Intv_5 = Intv_5 &'TEACH caregiver '&'#Teach_Patient#'&'<br>'>
    </cfloop>
    <cfelseif Caregiver eq 'B' and Confusion eq 'A'>
    <cfloop query="Get_Path5">
      <cfset Goal_5 = Goal_5 &'patient accurately recalls '&'#Teach_Patient#'&'<br>'>
      <cfset Intv_5 = Intv_5 &'TEACH patient '&'#Teach_Patient#'&'<br>'>
    </cfloop>
    <cfelseif Caregiver eq 'B' and Confusion eq 'B'>
    <cfset Goal_5 = ''>
    <cfset Intv_5 = ''>
  </cfif>
  <cfquery  name="update" datasource="#Application.DataSrc#">
    Update #Request.prefix_db_agency#.Coding_Results
    set Memo = concat('#Get_Path5.Memo#','; ', '#Goal_5#'),
    Textfield_12 = concat('#UCASE(Get_Path5.Diagnosis)#',': MONITOR patient for ','#Get_Path5.Deficits#','; ','#Intv_5#'), Textfield_14 = '#Intv_5#'
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
     and Question_ID = 5
      and M0_Item_Medication like '%M102%'
    </cfquery>
</cfif>
<cfif MAX gte 6>
  <cfquery name="Get_Path6" datasource="#Application.DataSrc#">
    SELECT c.Dx_order, c.Diagnosis, c.Message_ID, c.Memo, c.Deficits, i.Teach_Patient
    FROM #Request.prefix_db_agency#.Coding_Results c, #Request.prefix_db_lookup#.CW_Coding_Class_PDGM i
    where c.Assessment_ID = #url.AID#
    and c.Patient_ID = #url.ID#
    and c.Question_ID = 6
    and c.Order_ID = i.Priority
    </cfquery>
  <cfif Caregiver eq 'A'>
    <cfloop query="Get_Path6">
      <cfset Goal_6 = Goal_6 &'caregiver accurately recalls '&'#Teach_Patient#'&'<br>'>
      <cfset Intv_6 = Intv_6 &'TEACH caregiver '&'#Teach_Patient#'&'<br>'>
    </cfloop>
    <cfelseif Caregiver eq 'B' and Confusion eq 'A'>
    <cfloop query="Get_Path6">
      <cfset Goal_6 = Goal_6 &'patient accurately recalls '&'#Teach_Patient#'&'<br>'>
      <cfset Intv_6 = Intv_6 &'TEACH patient '&'#Teach_Patient#'&'<br>'>
    </cfloop>
    <cfelseif Caregiver eq 'B' and Confusion eq 'B'>
    <cfset Goal_6 = ''>
    <cfset Intv_6 = ''>
  </cfif>
  <cfquery  name="update" datasource="#Application.DataSrc#">
    Update #Request.prefix_db_agency#.Coding_Results
    set Memo = concat('#Get_Path6.Memo#','; ', '#Goal_6#'),
    Textfield_12 = concat('#UCASE(Get_Path6.Diagnosis)#',': MONITOR patient for ','#Get_Path6.Deficits#','; ','#Intv_6#'), Textfield_14 = '#Intv_6#'
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
     and Question_ID = 6
      and M0_Item_Medication like '%M102%'
    </cfquery>
</cfif>
<!---get OT--->
<cfset MAX = ''>
<cfquery  name="get_max_OT" datasource="#Application.DataSrc#">
  	SELECT Max(Dx_Order) as MAX from #Request.prefix_db_agency#.Coding_Results
  	where Assessment_ID = #url.AID#
  	and Patient_ID = #url.ID#
    and Message_ID = 10
    and Order_ID = 28
  </cfquery>
<cfset MAX = #get_max_OT.MAX#>
<cfif MAX gte 1>
  <cfquery name="Get_Path1" datasource="#Application.DataSrc#">
    SELECT Dx_order, Diagnosis, Message_ID, Memo, Deficits, Textfield_1, Textfield_14
    FROM #Request.prefix_db_agency#.Coding_Results c
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Dx_Order = 1
    and Message_ID = 10
    and Order_ID = 28
    </cfquery>
  <cfif Caregiver eq 'A'>
    <cfset Goal_1 = 'caregiver accurately recalls '&'#Get_Path1.Textfield_14#'>
    <cfset Intv_1 = 'TEACH caregiver '&'#Get_Path1.Textfield_14#'>
    <cfelseif Caregiver eq 'B' and Confusion eq 'A'>
    <cfset Goal_1 = 'patient accurately recalls '&'#Get_Path1.Textfield_14#'>
    <cfset Intv_1 = 'TEACH patient '&'#Get_Path1.Textfield_14#'>
    <cfelseif Caregiver eq 'B' and Confusion eq 'B'>
    <cfset Goal_1 = ''>
    <cfset Intv_1 = ''>
  </cfif>
  <cfquery  name="update" datasource="#Application.DataSrc#">
    Update #Request.prefix_db_agency#.Coding_Results
    set Textfield_9 = <cfif Caregiver eq 'A'>'PATIENT HAS A TEACHABLE CAREGIVER AVAILABLE DURING THE DAY. CAREGIVER WILL BE TAUGHT SYMPTOM MANAGEMENT AND DISEASE PREVENTION.'<cfelseif Caregiver eq 'B' and Confusion eq 'A'>'PATIENT HAS NO TEACHABLE CAREGIVER AVAILABLE DURING THE DAY. PATIENT WILL BE TAUGHT SYMPTOM MANAGEMENT AND DISEASE PREVENTION.'<cfelseif Caregiver eq 'B' and Confusion eq 'B'>'PATIENT IS CONFUSED AND DOES NOT HAVE A TEACHABLE CAREGIVER. LONG-TERM SYMPTOM MONITORING AND DISEASE MANAGEMENT POSSIBLE.'</cfif>,
    Memo = concat('#Get_Path1.Diagnosis#',' is optimized as evidenced by ', '#Get_Path1.Textfield_1#','; ', '#Goal_1#'),
    Textfield_12 = concat('#UCASE(Get_Path1.Diagnosis)#',': ','#Intv_1#'), Textfield_14 = '#Intv_1#'
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Dx_Order = 1
    and Message_ID = 10
    and Order_ID = 28
    </cfquery>
</cfif>
<cfif MAX gte 2>
  <cfquery name="Get_Path2" datasource="#Application.DataSrc#">
    SELECT Dx_order, Diagnosis, Message_ID, Memo, Deficits, Textfield_1, Textfield_14
    FROM #Request.prefix_db_agency#.Coding_Results c
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Dx_Order = 2
    and Message_ID = 10
    and Order_ID = 28
    </cfquery>
  <cfif Caregiver eq 'A'>
    <cfset Goal_2 = 'caregiver accurately recalls '&'#Get_Path2.Textfield_14#'>
    <cfset Intv_2 = 'TEACH caregiver '&'#Get_Path2.Textfield_14#'>
    <cfelseif Caregiver eq 'B' and Confusion eq 'A'>
    <cfset Goal_2 = 'patient accurately recalls '&'#Get_Path2.Textfield_14#'>
    <cfset Intv_2 = 'TEACH patient '&'#Get_Path2.Textfield_14#'>
    <cfelseif Caregiver eq 'B' and Confusion eq 'B'>
    <cfset Goal_2 = ''>
    <cfset Intv_2 = ''>
  </cfif>
  <cfquery  name="update" datasource="#Application.DataSrc#">
    Update #Request.prefix_db_agency#.Coding_Results
    set Memo = concat('#Get_Path2.Diagnosis#',' is optimized as evidenced by ', '#Get_Path2.Textfield_1#','; ', '#Goal_2#'),
    Textfield_12 = concat('#UCASE(Get_Path2.Diagnosis)#',': ','#Intv_2#'), Textfield_14 = '#Intv_2#'
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Dx_Order = 2
    and Message_ID = 10
    and Order_ID = 28
    </cfquery>
</cfif>
<cfif MAX gte 3>
  <cfquery name="Get_Path3" datasource="#Application.DataSrc#">
    SELECT Dx_order, Diagnosis, Message_ID, Memo, Deficits, Textfield_1, Textfield_14
    FROM #Request.prefix_db_agency#.Coding_Results c
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Dx_Order = 3
    and Message_ID = 10
    and Order_ID = 28
    </cfquery>
  <cfif Caregiver eq 'A'>
    <cfset Goal_3 = 'caregiver accurately recalls '&'#Get_Path3.Textfield_14#'>
    <cfset Intv_3 = 'TEACH caregiver '&'#Get_Path3.Textfield_14#'>
    <cfelseif Caregiver eq 'B' and Confusion eq 'A'>
    <cfset Goal_3 = 'patient accurately recalls '&'#Get_Path3.Textfield_14#'>
    <cfset Intv_3 = 'TEACH patient '&'#Get_Path3.Textfield_14#'>
    <cfelseif Caregiver eq 'B' and Confusion eq 'B'>
    <cfset Goal_3 = ''>
    <cfset Intv_3 = ''>
  </cfif>
  <cfquery  name="update" datasource="#Application.DataSrc#">
    Update #Request.prefix_db_agency#.Coding_Results
    set Memo = concat('#Get_Path3.Diagnosis#',' is optimized as evidenced by ', '#Get_Path3.Textfield_1#','; ', '#Goal_3#'),
    Textfield_12 = concat('#UCASE(Get_Path3.Diagnosis)#',': ','#Intv_3#'), Textfield_14 = '#Intv_3#'
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Dx_Order = 3
    and Message_ID = 10
    and Order_ID = 28
    </cfquery>
</cfif>
<cfif MAX gte 4>
  <cfquery name="Get_Path4" datasource="#Application.DataSrc#">
    SELECT Dx_order, Diagnosis, Message_ID, Memo, Deficits, Textfield_1, Textfield_14
    FROM #Request.prefix_db_agency#.Coding_Results c
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Dx_Order = 4
    and Message_ID = 10
    and Order_ID = 28
    </cfquery>
  <cfif Caregiver eq 'A'>
    <cfset Goal_4 = 'caregiver accurately recalls '&'#Get_Path4.Textfield_14#'>
    <cfset Intv_4 = 'TEACH caregiver '&'#Get_Path4.Textfield_14#'>
    <cfelseif Caregiver eq 'B' and Confusion eq 'A'>
    <cfset Goal_4 = 'patient accurately recalls '&'#Get_Path4.Textfield_14#'>
    <cfset Intv_4 = 'TEACH patient '&'#Get_Path4.Textfield_14#'>
    <cfelseif Caregiver eq 'B' and Confusion eq 'B'>
    <cfset Goal_4 = ''>
    <cfset Intv_4 = ''>
  </cfif>
  <cfquery  name="update" datasource="#Application.DataSrc#">
    Update #Request.prefix_db_agency#.Coding_Results
    set Memo = concat('#Get_Path4.Diagnosis#',' is optimized as evidenced by ', '#Get_Path4.Textfield_1#','; ', '#Goal_4#'),
    Textfield_12 = concat('#UCASE(Get_Path4.Diagnosis)#',': ','#Intv_4#'), Textfield_14 = '#Intv_4#'
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Dx_Order = 4
    and Message_ID = 10
    and Order_ID = 28
    </cfquery>
</cfif>
<cfif MAX gte 5>
  <cfquery name="Get_Path5" datasource="#Application.DataSrc#">
    SELECT Dx_order, Diagnosis, Message_ID, Memo, Deficits, Textfield_1, Textfield_14
    FROM #Request.prefix_db_agency#.Coding_Results c
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Dx_Order = 5
    and Message_ID = 10
    and Order_ID = 28
    </cfquery>
  <cfif Caregiver eq 'A'>
    <cfset Goal_5 = 'caregiver accurately recalls '&'#Get_Path5.Textfield_14#'>
    <cfset Intv_5 = 'TEACH caregiver '&'#Get_Path5.Textfield_14#'>
    <cfelseif Caregiver eq 'B' and Confusion eq 'A'>
    <cfset Goal_5 = 'patient accurately recalls '&'#Get_Path5.Textfield_14#'>
    <cfset Intv_5 = 'TEACH patient '&'#Get_Path5.Textfield_14#'>
    <cfelseif Caregiver eq 'B' and Confusion eq 'B'>
    <cfset Goal_5 = ''>
    <cfset Intv_5 = ''>
  </cfif>
  <cfquery  name="update" datasource="#Application.DataSrc#">
    Update #Request.prefix_db_agency#.Coding_Results
    set Memo = concat('#Get_Path5.Diagnosis#',' is optimized as evidenced by ', '#Get_Path5.Textfield_1#','; ', '#Goal_5#'),
    Textfield_12 = concat('#UCASE(Get_Path5.Diagnosis)#',': ','#Intv_5#'), Textfield_14 = '#Intv_5#'
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Dx_Order = 5
    and Message_ID = 10
    and Order_ID = 28
    </cfquery>
</cfif>
<cfif MAX gte 6>
  <cfquery name="Get_Path6" datasource="#Application.DataSrc#">
    SELECT Dx_order, Diagnosis, Message_ID, Memo, Deficits, Textfield_1, Textfield_14
    FROM #Request.prefix_db_agency#.Coding_Results c
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Dx_Order = 6
    and Message_ID = 10
    and Order_ID = 28
    </cfquery>
  <cfif Caregiver eq 'A'>
    <cfset Goal_6 = 'caregiver accurately recalls '&'#Get_Path6.Textfield_14#'>
    <cfset Intv_6 = 'TEACH caregiver '&'#Get_Path6.Textfield_14#'>
    <cfelseif Caregiver eq 'B' and Confusion eq 'A'>
    <cfset Goal_6 = 'patient accurately recalls '&'#Get_Path6.Textfield_14#'>
    <cfset Intv_6 = 'TEACH patient '&'#Get_Path6.Textfield_14#'>
    <cfelseif Caregiver eq 'B' and Confusion eq 'B'>
    <cfset Goal_6 = ''>
    <cfset Intv_6 = ''>
  </cfif>
  <cfquery  name="update" datasource="#Application.DataSrc#">
    Update #Request.prefix_db_agency#.Coding_Results
    set Memo = concat('#Get_Path6.Diagnosis#',' is optimized as evidenced by ', '#Get_Path6.Textfield_1#','; ', '#Goal_6#'),
    Textfield_12 = concat('#UCASE(Get_Path6.Diagnosis)#',': ','#Intv_6#'), Textfield_14 = '#Intv_6#'
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Dx_Order = 6
    and Message_ID = 10
    and Order_ID = 28
    </cfquery>
</cfif>
<!---get PT--->
<cfset MAX = ''>
<cfquery  name="get_max_PT" datasource="#Application.DataSrc#">
  	SELECT Max(Dx_Order) as MAX from #Request.prefix_db_agency#.Coding_Results
  	where Assessment_ID = #url.AID#
  	and Patient_ID = #url.ID#
    and Message_ID = 10
    and Order_ID = 29
  </cfquery>
<cfset MAX = #get_max_PT.MAX#>
<cfif MAX gte 1>
  <cfquery name="Get_Path1" datasource="#Application.DataSrc#">
    SELECT Dx_order, Diagnosis, Message_ID, Memo, Deficits, Textfield_1, Textfield_14
    FROM #Request.prefix_db_agency#.Coding_Results c
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Dx_Order = 1
    and Message_ID = 10
    and Order_ID = 29
    </cfquery>
  <cfif Caregiver eq 'A'>
    <cfset Goal_1 = 'caregiver accurately recalls '&'#Get_Path1.Textfield_14#'>
    <cfset Intv_1 = 'TEACH caregiver '&'#Get_Path1.Textfield_14#'>
    <cfelseif Caregiver eq 'B' and Confusion eq 'A'>
    <cfset Goal_1 = 'patient accurately recalls '&'#Get_Path1.Textfield_14#'>
    <cfset Intv_1 = 'TEACH patient '&'#Get_Path1.Textfield_14#'>
    <cfelseif Caregiver eq 'B' and Confusion eq 'B'>
    <cfset Goal_1 = ''>
    <cfset Intv_1 = ''>
  </cfif>
  <cfquery  name="update" datasource="#Application.DataSrc#">
    Update #Request.prefix_db_agency#.Coding_Results
    set Textfield_9 = <cfif Caregiver eq 'A'>'PATIENT HAS A TEACHABLE CAREGIVER AVAILABLE DURING THE DAY. CAREGIVER WILL BE TAUGHT SYMPTOM MANAGEMENT AND DISEASE PREVENTION.'<cfelseif Caregiver eq 'B' and Confusion eq 'A'>'PATIENT HAS NO TEACHABLE CAREGIVER AVAILABLE DURING THE DAY. PATIENT WILL BE TAUGHT SYMPTOM MANAGEMENT AND DISEASE PREVENTION.'<cfelseif Caregiver eq 'B' and Confusion eq 'B'>'PATIENT IS CONFUSED AND DOES NOT HAVE A TEACHABLE CAREGIVER. LONG-TERM SYMPTOM MONITORING AND DISEASE MANAGEMENT POSSIBLE.'</cfif>,
    Memo = concat('#Get_Path1.Diagnosis#',' is optimized as evidenced by ', '#Get_Path1.Textfield_1#','; ', '#Goal_1#'),
    Textfield_12 = concat('#UCASE(Get_Path1.Diagnosis)#',': ','#Intv_1#'), Textfield_14 = '#Intv_1#'
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Dx_Order = 1
    and Message_ID = 10
    and Order_ID = 29
    </cfquery>
</cfif>
<cfif MAX gte 2>
  <cfquery name="Get_Path2" datasource="#Application.DataSrc#">
    SELECT Dx_order, Diagnosis, Message_ID, Memo, Deficits, Textfield_1, Textfield_14
    FROM #Request.prefix_db_agency#.Coding_Results c
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Dx_Order = 2
    and Message_ID = 10
    and Order_ID = 29
    </cfquery>
  <cfif Caregiver eq 'A'>
    <cfset Goal_2 = 'caregiver accurately recalls '&'#Get_Path2.Textfield_14#'>
    <cfset Intv_2 = 'TEACH caregiver '&'#Get_Path2.Textfield_14#'>
    <cfelseif Caregiver eq 'B' and Confusion eq 'A'>
    <cfset Goal_2 = 'patient accurately recalls '&'#Get_Path2.Textfield_14#'>
    <cfset Intv_2 = 'TEACH patient '&'#Get_Path2.Textfield_14#'>
    <cfelseif Caregiver eq 'B' and Confusion eq 'B'>
    <cfset Goal_2 = ''>
    <cfset Intv_2 = ''>
  </cfif>
  <cfquery  name="update" datasource="#Application.DataSrc#">
    Update #Request.prefix_db_agency#.Coding_Results
    set Memo = concat('#Get_Path2.Diagnosis#',' is optimized as evidenced by ', '#Get_Path2.Textfield_1#','; ', '#Goal_2#'),
    Textfield_12 = concat('#UCASE(Get_Path2.Diagnosis)#',': ','#Intv_2#'), Textfield_14 = '#Intv_2#'
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Dx_Order = 2
    and Message_ID = 10
    and Order_ID = 29
    </cfquery>
</cfif>
<cfif MAX gte 3>
  <cfquery name="Get_Path3" datasource="#Application.DataSrc#">
    SELECT Dx_order, Diagnosis, Message_ID, Memo, Deficits, Textfield_1, Textfield_14
    FROM #Request.prefix_db_agency#.Coding_Results c
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Dx_Order = 3
    and Message_ID = 10
    and Order_ID = 29
    </cfquery>
  <cfif Caregiver eq 'A'>
    <cfset Goal_3 = 'caregiver accurately recalls '&'#Get_Path3.Textfield_14#'>
    <cfset Intv_3 = 'TEACH caregiver '&'#Get_Path3.Textfield_14#'>
    <cfelseif Caregiver eq 'B' and Confusion eq 'A'>
    <cfset Goal_3 = 'patient accurately recalls '&'#Get_Path3.Textfield_14#'>
    <cfset Intv_3 = 'TEACH patient '&'#Get_Path3.Textfield_14#'>
    <cfelseif Caregiver eq 'B' and Confusion eq 'B'>
    <cfset Goal_3 = ''>
    <cfset Intv_3 = ''>
  </cfif>
  <cfquery  name="update" datasource="#Application.DataSrc#">
    Update #Request.prefix_db_agency#.Coding_Results
    set Memo = concat('#Get_Path3.Diagnosis#',' is optimized as evidenced by ', '#Get_Path3.Textfield_1#','; ', '#Goal_3#'),
    Textfield_12 = concat('#UCASE(Get_Path3.Diagnosis)#',': ','#Intv_3#'), Textfield_14 = '#Intv_3#'
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
    and Dx_Order = 3
    and Message_ID = 10
    and Order_ID = 29
    </cfquery>
</cfif>
<cfquery  name="GetM0090" datasource="#Application.DataSrc#">
    Select Assessment_Completed_M0090
    from #Request.prefix_db_agency#.Assessment_New
    where Assessment_ID = #url.AID#
    and Patient_ID = #url.ID#
</cfquery>
<!---<cfif CGI.REMOTE_ADDR EQ '103.136.137.35'>
    <cfabort>
 </cfif>  --->      
<cfif Redirect_to eq "View_Reports">
  <cfset Encrypted_patient_ID=encrypt(#url.ID#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
  <cfset Encrypted_Ass_ID_Report1=encrypt(#url.AID#,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
  <cfset Encrypted_Report1_Type=encrypt(1,"54kczhzgHTj4a8n+SRZPyg==","AES","Hex") />
  <cfset Encrypted_Report4_2019_OASIS=encrypt("2019_OASIS_D","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_Report1#&report_type=#Encrypted_Report1_Type#&report_method=#Encrypted_Report4_2019_OASIS#" addtoken="no">
  <cfelse>
  <cfif GetM0090.Assessment_Completed_M0090 contains "2019">
    <cfinclude template="cron_coding_VISITPLAN.cfm" />
    <cfelse>
    <cfinclude template="cron_coding_VISITPLAN_2020.cfm" />
  </cfif>
</cfif>
