<cfscript>
    request.general = CreateObject("component","components.general.general").init();
    request.ass     = CreateObject("component","components.general.assessments").init();
    get_ass = request.general.get_answers('assessment_type','assessment_form');
    getmess = request.general.get_messages('assessment_form');
</cfscript>
 <cfset Request.assessmenttype= "9 - Discharge from agency" />

<cfquery name="AssForm" datasource="#Application.DataSrc#">    
    SELECT  pAssessments.*,pPatients.*,
     CASE 
            WHEN  F26 =  '1 - Start of care - further visits planned' THEN "1 - SOC - SN"
            WHEN  F26 =  '1 - Start of care - further visits planned - Physical Therapy'  THEN  "1 - SOC - PT"
            WHEN  F26 =  '3 - Resumption of care (after inpatient stay'  THEN  "3 - ROC - SN" 
            WHEN F26 =  '4 - Recertification (follow-up) reassessment' THEN  '4 - Recertification'
            WHEN  F26 =  'PT Adult Evaluation' THEN "PT Eval" 
            WHEN  F26 =  'OT Adult Evaluation' THEN "OT Eval"
            WHEN  F26 =  'ST Adult Evaluation' THEN "ST Eval" 
            WHEN  F26 =  'SN Adult Evaluation' THEN "SN Eval" 
            WHEN  F26 =  'MSW Evaluation' THEN "MSW Eval" 
            WHEN  F26 =  'PT Followup' THEN "PT FU Eval" 
            WHEN  F26 =  'OT Followup' THEN "OT FU Eval"
            WHEN  F26 =  'ST Followup' THEN "ST FU Eval"
            WHEN F26 =  'MSW Followup' THEN "MSW FU Eval" 
            WHEN F26 =  'SN Followup' THEN "SN FU Eval" 
            WHEN F26 =  'Hospice Comprehensive' THEN "Hospice Comprehensive" 
            WHEN F26 =  'SN Hospice' THEN "SN Hospice"  
            WHEN F26 =  'Chaplain Comprehensive Evaluation' THEN "Chaplain Comprehensive Evaluation" 
            WHEN F26 =  'Hospice Discharge' THEN "Hospice Discharge"  
            WHEN F26 =  '5 - Other follow-up' THEN "5 - Other follow-up" 
            WHEN F26 =  '6 - Transferred to an inpatient facility - patient not discharged from agency' THEN "6 - Transfer no discharge" 
            WHEN F26 =  '7 - Transferred to an inpatient facility - patient discharged from agency' THEN "7 - Transfer discharged" 
            WHEN F26 =  '8 - Death at home' THEN "8 - Death" 
            WHEN F26 =  '9 - Discharge from agency' THEN "9 - Discharge from agency" 
            ELSE 0
        END AS assesments  

    FROM  #Request.prefix_db_agency#.pAssessments
    INNER join #Request.prefix_db_agency#.pPatients ON pAssessments.patient_id = pPatients.patient_id
    AND pPatients.Status IN (0,1,4)
    WHERE pAssessments.Assmt_ID =  <cfqueryparam cfsqltype="cf_sql_integer" value="#session.cs.ASSESSMENTID#">
    AND pAssessments.Patient_ID =    <cfqueryparam cfsqltype="cf_sql_integer" value="#session.cs.PATIENTID#">
    AND pAssessments.Status = 0
</cfquery> 



<cfquery name="get_cg_questions" datasource="#Application.DataSrc#">
    SELECT * FROM  #Request.prefix_db_lookup#.#Request.assessment_questions_lookup#
    WHERE  Deleted <> 1  
    AND  assessment_reason = '#Request.assessmenttype#'
    ORDER BY order_id
</cfquery>

<cfoutput query="get_cg_questions" group="ques_id">
    <cfset  Variables.checked_value = "AssForm."&answer_label />
    <cfset answer_value = #Evaluate(Variables.checked_value)# />
</cfoutput>

<cfquery name="get_patient_details" datasource="#Application.DataSrc#">
    SELECT * FROM  #Request.prefix_db_agency#.pPatients
    WHERE  patient_id =  #AssForm.patient_id# 
</cfquery>



<cfquery datasource="#Application.DataSrc#" name="getproblem">
    SELECT * FROM  #Request.prefix_db_agency#.pProblem
    WHERE Status = 0
    AND Assmt_ID =  <cfqueryparam value = "#AssForm.Assmt_ID#" CFSQLType ="CF_SQL_INTEGER">
    AND M0_No like 'M102%'
    ORDER BY dx_order ASC
</cfquery>

 <cfset assessmentreason = AssForm.F26 />
 <cfset assmids  = AssForm.Assmt_ID />
 <cfquery name="getempass" datasource="#Application.DataSrc#">
    SELECT  pSchedules.* , pEmployee.Emp_First,  pEmployee.Emp_Last 
    FROM  #Request.prefix_db_agency#.pSchedules  
    JOIN   #Request.prefix_db_lookup#.pEmployee ON pEmployee.Emp_ID = pSchedules.Emp_ID
    WHERE pSchedules.Status = <cfqueryparam cfsqltype="cf_sql_integer"  value="0"> 
    AND pSchedules.Patient_ID = '#session.cs.PATIENTID#'
     <!--- AND pSchedules.Assmt_ID = '#AssForm.Assmt_ID#' --->
    AND pSchedules.Visit_Type =  '#AssForm.assesments#'
    AND pSchedules.Followup_visit = 1
    ORDER BY pSchedules.Visit_Date DESC
</cfquery> 
<cfset completed_by =  #getempass.Emp_First#  & " "& #getempass.Emp_Last# />
<cfquery  name="GetVitals" datasource="#Application.DataSrc#">
    SELECT pWoundsVitals.*,pWoundsVitals.ID AS woundsid
    FROM  #Request.prefix_db_agency#.pWoundsVitals
    WHERE  pWoundsVitals.Assmt_ID = <cfqueryparam value = "#AssForm.Assmt_ID#" CFSQLType ="CF_SQL_INTEGER">
    AND pWoundsVitals.Status = 0
    AND VitalOrWound =  'vital'
    ORDER BY pWoundsVitals.Item_ID ASC
</cfquery>
<cfquery  name="GetWounds" datasource="#Application.DataSrc#">
    SELECT pWoundsVitals.*,pWoundsVitals.ID AS woundsid 
    FROM  #Request.prefix_db_agency#.pWoundsVitals 
    JOIN #Request.prefix_db_agency#.pAssessments ON pAssessments.Assmt_ID = pWoundsVitals.Assmt_ID AND pAssessments.Status = 0
    WHERE  pAssessments.Admit_ID = <cfqueryparam value = "#AssForm.Admit_ID#" CFSQLType ="CF_SQL_INTEGER"> 
    AND pWoundsVitals.Status = 0
    AND VitalOrWound =  'wound' 
    ORDER BY pWoundsVitals.Item_ID ASC
</cfquery>

<cfset page_num = 10 >
<cfset next_page = 1> 
<cfset question_count =  1 >
<cfdocument format="pdf" orientation="portrait" overwrite="yes">
<cfset max_rows = ceiling(get_cg_questions.recordcount/10) >
        <table border="0" height="100%" style="border-left: solid 1px ##CCCCCC; border-right: solid 1px ##CCCCCC; border-top: ##CCCCCC solid 1px; border-bottom: solid 1px ##CCCCCC;" width="100%"  cellpadding="0" cellspacing="0">
          <tr valign="top">
                <td >
                    <table border="0" width="100%" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td style="height: 5px"></td>
                                </tr>
                                <cfoutput>
                                    <tr>
                                        <td style="padding-left: 5px; font-family: Arial; font-size: 14px; font-weight: bold; font-style: italic;">#Assform.Pt_First#  #Assform.Pt_Last# </td>
                                        <td width="36%" align="right" style="padding-right: 30px; font-family: Arial; font-size: 14px; font-weight: bold; font-style: italic;"> #Assform.F26#</td>
                                    </tr>
                                </cfoutput>    
                                <tr>
                                    <td style="height: 5px"></td>
                                </tr>
                                <tr>
                                    <td style="border: solid 1px ##CCCCCC" colspan="5"></td>
                                </tr>
                                <tr>
                                    <td style="height: 5px"></td>
                                </tr>
                    </table>
                 
                    <table border="0" width="100%" height="95%" cellpadding="0" cellspacing="0">
                        <cfoutput query="get_cg_questions" group="ques_id">

                             <cfset discharge_questionslist =  '288,292,917,1653,1650,318,316,296,280,392,1662,363,291,283,376,362,355,320,379,335,284,314,328' />

                            <tr>
                                 <cfif trim(title) neq ''>
                                        <cfif discharge_questionslist contains ques_id >
                                           <td style="font-size: 12px; margin-left:10px;"> #title#</td>

                                        <cfelse>
                                           <td> <div class="row" style="margin:10px;">  #title# </div></td>  
                                        </cfif>
                                </cfif>
                            </tr>

                            <tr>
                                <td style="font-family: Arial; font-size: 12px; padding-top: 5px; width: 50%; padding-left: 8px;"><cfif  ques_identifier NEQ ''>(#ques_identifier#)</cfif> #questions#
                                </td>
                                <cfset  Variables.cheked_value = "Assform."&answer_label />
                                <td colspan="0" style="font-family: Arial; font-size: 12px; font-weight: bold; padding-top: 5px;width: 50%; padding-left: 8px;"><cfif #Evaluate(Variables.cheked_value)# neq ''>#Evaluate(Variables.cheked_value)#<cfelse> - </cfif></td>
                            </tr>
                            <tr>
                                <td style="height: 5px">
                                </td>
                            </tr>
                            </cfoutput>

                            <tr>
                                <td style="height: 10px"> </td>
                            </tr>
                            <cfif #GetVitals.recordcount# GT 0>
                                <tr>
                                    <td style="font-family: Arial; font-size: 12px; font-weight: bold; padding-top: 5px;width: 50%; padding-left: 8px;"> VITAL SIGNS</td>  
                                </tr>
                                <cfoutput query="GetVitals">
                                    <tr>
                                        <td style="font-family: Arial; font-size: 12px; padding-top: 5px; width: 50%; padding-left: 8px;">
                                            #(GetVitals.Description)#
                                        </td>
                                        <td style="font-family: Arial; font-size: 12px; padding-top: 5px; width: 50%; padding-left: 8px;">#GetVitals.Reading1#  - #GetVitals.Notes#</td>
                                    </tr>
                                </cfoutput>
                            <cfelse>
                                <tr>
                                  <td style="font-family: Arial; font-size: 12px; padding-top: 5px; width: 50%; padding-left: 8px;"> No Vital Sign Records were Found </td>
                                </tr>
                            </cfif>
                            <tr>
                                <td style="height: 10px"> </td>
                            </tr>
                            <tr>
                               <td style="font-family: Arial; font-size: 12px; font-weight: bold; padding-top: 5px;width: 50%; padding-left: 8px;"> WOUNDS</td>  
                            </tr>
                                <cfif #GetWounds.recordcount# GT 0>
                                    <cfoutput query="GetWounds">
                                        <tr>
                                            <td style="font-family: Arial; font-size: 12px; padding-top: 5px; width: 50%; padding-left: 8px;">#GetWounds.WoundType#</td>
                                            <td style="font-family: Arial; font-size: 12px; padding-top: 5px; width: 50%; padding-left: 8px;">
                                                Length: #Length# cm, Width:#Width# cm, Depth: #Depth# cm, <br>Severity: #HealingStage#,#GetWounds.Notes#
                                            </td>
                                        </tr>
                                    </cfoutput>
                                <cfelse>
                                    <tr style="font-family: Arial; font-size: 12px; padding-top: 5px; width: 50%; padding-left: 8px;">
                                        <td colspan="3"> No Wound Records were Found </td>
                                    </tr>
                                </cfif>
                            <tr>
                                <td style="height: 10px">
                                </td>
                            </tr>

                            <tr><td style="border: solid 1px ##CCCCCC" colspan="2"></td>    </tr>
                              <tr>
                                <td style="height: 10px">
                                </td>
                            </tr>

                            <tr valign="top" style="font-size:12px;font-family:'Times New Roman, Times, serif';line-height:12px;padding-left:20px">
                              <td style="font-family: Arial; font-size: 12px; padding-top: 5px; width: 50%; padding-left: 8px"><br><br>Physician Signature:</td>
                              <td style="width: 200px; height: 80px; border: 1px solid black;padding-right:5px"></td>
                            </tr>
                            <tr>
                                <td style="height: 10px">
                                </td>
                            </tr>


                            <tr><td style="border: solid 1px ##CCCCCC" colspan="2"></td>    </tr>
                                    <tr><td style="border: solid 1px ##CCCCCC" colspan="2"></td>   </tr>
                                   <table border="0" cellpadding="0" cellspacing="0">
                                        <tr>
                                            <td style="font-family: Arial; font-size: 14px; padding-top: 5px; padding-left: 8px;"><cfoutput>Completed & Digitally Signed by #completed_by# on #DateFormat(AssForm.F176,"mm/dd/yyyy")#</cfoutput>
                                            </td>
                                        </tr>
                                         <tr>
                                        <td style="height: 5px;"></td>
                                     </tr>

                                    </table>
                                     <tr><td style="border: solid 1px ##CCCCCC" colspan="2"></td>    </tr>
                             </table>

                            
                             <tr><td style="border: solid 1px ##CCCCCC" colspan="2"></td>	</tr>
                    </table>
                            
                    <!--- <table border="0" cellpadding="0" cellspacing="0">
                        <tr><td style="page-break-after: always"></td></tr>
                    </table> --->
                </td>
            </tr>
        </table>
        <cfdocumentitem type="footer">
            <table width="100%" cellpadding="0" cellpadding="0" border="0" align="center">
            <tr>
            <td align="center" style="font-family: Arial; font-size: 13px;">
            <cfoutput>Page #cfdocument.currentpagenumber# 9 - Discharge for <cfoutput>#AssForm.Pt_First# #AssForm.Pt_Last#</cfoutput></cfoutput>
            </td>
            </tr>
            </table>        
        </cfdocumentitem>
           


</cfdocument>


