<!---GenerateCarePlanHippsAuthCode.cfm--->
<cfform name="HIPPSCAREPLAN">
<cfinclude template="generate_hipps.cfm">
 <cfquery name="GetVisitCount" datasource="#Application.DataSrc#">
	SELECT count(*) as visitcount from #Request.prefix_db_agency#.PatientVisitDetails 
    where Assessment_Id = '#session.cs.AssessmentId#' 
    and ScheduleItems_ID != 0 
    and Type != 'vital sign'
    and Type != 'wound'
</cfquery>
  <cfquery name="GetCarePlanCount" datasource="#Application.DataSrc#">
	SELECT count(*) as careplancount from #Request.prefix_db_agency#.Pathway_Details where Assessment_Id = '#session.cs.AssessmentId#' and Type != 'vital sign';
</cfquery>
  
  <!---<cfoutput>#GetVisitCount.visitcount#</cfoutput>
<cfoutput>#GetCarePlanCount.careplancount#</cfoutput>--->
  
  <cfset thereason = Assessment_Reason_M0100 />
  <cfif LEFT(thereason,1) eq '1'>
    <cfset thereason = 'Start of Care' />
    <cfelseif LEFT(thereason,1) eq '3'>
    <cfset thereason = 'Resumption of Care' />
    <cfelseif LEFT(thereason,1) eq '4'>
    <cfset thereason = 'Recertification' />
    <cfelseif LEFT(thereason,1) eq '5'>
    <cfset thereason = 'Other Follow Up' />
    <cfelseif LEFT(thereason,1) eq '6'>
    <cfset thereason = '6 - Transferred to Inpatient Facility' />
    <cfelseif LEFT(thereason,1) eq '7'>
    <cfset thereason = 'Transferred to Inpatient Facility' />
    <cfelseif LEFT(thereason,1) eq '8'>
    <cfset thereason = 'Death' />
    <cfelseif LEFT(thereason,1) eq '9'>
    <cfset thereason = 'Discharge' />
	<cfelseif thereason contains 'Hospice Discharge'>
    <cfset thereason = 'Hospice Discharge' />
	<cfelseif thereason contains 'Hospice Comp'>
    <cfset thereason = 'H - Hospice Comprehensive' />
    <cfelseif thereason eq 'SN Ped'>
    <cfset thereason = 'SN Pediatric Evaluation' />
 </cfif>
  <cfset thereason=#rereplacenocase(thereason,"recertification","Recertification","ALL")# />
  <cfif GetVisitCount.visitcount eq 0>
            <cfif GetCarePlanCount.careplancount eq 0>
                        <cflocation url="index.cfm?page=patient&cat=GenerateCarePlan" addtoken="no">
             <!---CAREPLAN LOCATION--->
              <cfelse>
                      <script language="JavaScript" type="text/javascript">
                            if(confirm('Would you like to replace careplan for this assessment? (click cancel for "no")'))
                            {
                                location.href="index.cfm?page=patient&cat=GenerateCarePlan&deleted=yes";				
                            }
                            else
                            {
                                window.location= '/patientadmin_new/index.cfm?a=1&page=patient&px=y&cat=assessment_form&type=<cfoutput>#thereason#</cfoutput>';
                                <!---LOCATION--->
                            }
                        </script>
            </cfif>
    <cfelse>
            <script language="JavaScript" type="text/javascript">
                alert('You can not replace the careplan for this assessment! Progress notes already done for this assessment!');	
                window.location= '../patientadmin_new/index.cfm?a=1&page=patient&px=y&cat=assessment_form&type=<cfoutput>#thereason#</cfoutput>';	
            </script>
    </cfif>
 </cfform>