<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>

<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 =  '4 - Recertification (follow-up) reassessment - PT' THEN  '4 - Recertification PT'
            WHEN  F26 =  '4 - Recertification (follow-up) reassessment - OT' THEN  '4 - Recertification OT'
            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
    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 AND pPatients.Status < 2
</cfquery> 

<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>
<cfquery name="GetE" datasource="#Application.DataSrc#">
    SELECT Emp_Last, Emp_First, Skill_1, Skill_2, Skill_3
    FROM #Request.prefix_db_lookup#.pEmployee
    WHERE Emp_ID = '#Assform.Record_Created_By#'
</cfquery>
<cfquery name="GetPhysician" datasource="#Application.DataSrc#">
    SELECT * FROM #Request.prefix_db_agency#.pAdmit
    JOIN #Request.prefix_db_lookup#.pPhysicians ON pPhysicians.Phys_ID = pAdmit.Render_Phys_ID
    WHERE pAdmit.Patient_ID =   #session.cs.PATIENTID#
    AND pAdmit.Status = 0
    ORDER BY pAdmit.M0030_START_CARE_DT DESC LIMIT 1
</cfquery>

<cfparam name="url.Evaltype" default="PT">

<cfif url.Evaltype EQ 'PT'>
    <cfset Request.assessmenttype= "PT Adult Evaluation" />
<cfelseif url.Evaltype EQ 'OT'>
    <cfset Request.assessmenttype= "OT Adult Evaluation" />
<cfelseif url.Evaltype EQ 'ST'>
    <cfset Request.assessmenttype= "ST Adult Evaluation" />
<cfelseif url.Evaltype EQ 'SN_Adult'>
    <cfset Request.assessmenttype= "SN Adult Evaluation" />
<cfelseif url.Evaltype EQ 'MSW'>
    <cfset Request.assessmenttype= "MSW Evaluation" />
<cfelseif url.Evaltype EQ 'SN_Pediatric'>
    <cfset Request.assessmenttype= "SN Pediatric Evaluation" />
<cfelseif url.Evaltype EQ 'PT_Pediatric'>
    <cfset Request.assessmenttype= "PT Pediatric Evaluation" />
<cfelseif url.Evaltype EQ 'OT_Pediatric'>
    <cfset Request.assessmenttype= "OT Pediatric Evaluation" />
<cfelseif url.Evaltype EQ 'ST_Pediatric'>
    <cfset Request.assessmenttype= "ST Pediatric Evaluation" />
<cfelseif url.Evaltype EQ 'PT_Followup'> 
    <cfset Request.assessmenttype= "PT Followup" />
<cfelseif url.Evaltype EQ 'OT_Followup'>
    <cfset Request.assessmenttype= "OT Followup" />
<cfelseif url.Evaltype EQ 'ST_Followup'>
    <cfset Request.assessmenttype= "ST Followup" />
<cfelseif url.Evaltype EQ '6_transfer'>
    <cfset Request.assessmenttype= "6 - Transferred to an inpatient facility - patient not discharged from agency" />
<cfelseif url.Evaltype EQ '7_transfer'>
    <cfset Request.assessmenttype= "7 - Transferred to an inpatient facility - patient discharged from agency" />
<cfelseif url.Evaltype EQ '8_death'>
    <cfset Request.assessmenttype= "8 - Death at home" />
<cfelseif url.Evaltype EQ '9_discharge'>
    <cfset Request.assessmenttype= "9 - Discharge from agency" />
<cfelseif url.Evaltype EQ 'OASIS_review'>
    <cfset Request.assessmenttype= "H&P Review" />
<cfelseif url.Evaltype EQ 'PT_Pediatric_Discharge'>
    <cfset Request.assessmenttype= "PT Pediatric Discharge" />
</cfif>

<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#'
    AND  answer_label != 'F175'
    ORDER BY wizard,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.Visit_Date, pSchedules.Assmt_ID, pEmployee.Emp_First, pEmployee.Emp_Last,
            pEmployee.Skill_1, pEmployee.Skill_2, pEmployee.Skill_3
    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 = <cfqueryparam cfsqltype="cf_sql_integer" value="#AssForm.Assmt_ID#">
        OR (
            pSchedules.Visit_Type = '#AssForm.assesments#'
            AND pSchedules.Followup_visit = 1
        )
    )
    ORDER BY CASE WHEN pSchedules.Assmt_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#AssForm.Assmt_ID#"> THEN 0 ELSE 1 END,
             pSchedules.Visit_Date DESC
</cfquery>
<!--- #10690: Date Completed = Visit_Date; clinician + credentials --->
<cfset printCompletedDate = AssForm.F176 />
<cfset completed_by = "" />
<cfif getempass.recordcount GT 0>
    <cfif IsDate(getempass.Visit_Date)>
        <cfset printCompletedDate = getempass.Visit_Date />
    </cfif>
    <cfset completed_by = Trim(getempass.Emp_First & " " & getempass.Emp_Last) />
    <cfif Len(Trim(getempass.Skill_1))><cfset completed_by = completed_by & ", " & Trim(getempass.Skill_1) /></cfif>
    <cfif Len(Trim(getempass.Skill_2))><cfset completed_by = completed_by & " " & Trim(getempass.Skill_2) /></cfif>
    <cfif Len(Trim(getempass.Skill_3))><cfset completed_by = completed_by & " " & Trim(getempass.Skill_3) /></cfif>
<cfelseif GetE.recordcount GT 0>
    <cfset completed_by = Trim(GetE.Emp_First & " " & GetE.Emp_Last) />
    <cfif Len(Trim(GetE.Skill_1))><cfset completed_by = completed_by & ", " & Trim(GetE.Skill_1) /></cfif>
    <cfif Len(Trim(GetE.Skill_2))><cfset completed_by = completed_by & " " & Trim(GetE.Skill_2) /></cfif>
    <cfif Len(Trim(GetE.Skill_3))><cfset completed_by = completed_by & " " & Trim(GetE.Skill_3) /></cfif>
</cfif>

<!--- <cfif CGI.REMOTE_ADDR EQ '121.200.49.65'>
       <cfdump var="#AssForm#"><cfdump var="#getempass#"><cfabort>
</cfif> --->
<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# - DOB: #DateFormat(Assform.Pt_DOB,"mm/dd/yyyy")#</td>
                                        <td width="50%" align="right" style="padding-right: 2px; font-family: Arial; font-size: 14px; font-weight: bold; font-style: italic;"> #Request.assessmenttype# &nbsp;- #DateFormat(printCompletedDate,"mm/dd/yyyy")#</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">
                                  <tr>
                                     <cfif trim(title) neq '<br>' AND len(title) gt 6>
                                           <td style="font-size: 12px; margin-left:10px;"> #title#</td>
                                    <cfelse>
                                           <td> <div class="row" style="margin:10px;">  #title# </div></td>  
                                    </cfif>
                                </tr>

                               <!---  <tr>
                                     <cfif trim(title) neq ''>
                                        <cfif ques_id EQ '20' OR ques_id EQ '24' OR ques_id EQ '70' OR ques_id EQ '159'  OR ques_id EQ '50'  >
                                           <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  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#
                                                        <cfif Location NEQ ''><br>Location: #Location#<br> </cfif>
                                                    </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="font-family: Arial; font-size: 12px; padding-top: 5px; width: 50%; padding-left: 8px;"> Comments
                                </td>
                                <td colspan="0" style="font-family: Arial; font-size: 12px; font-weight: bold; padding-top: 5px;width: 50%; padding-left: 8px;"><cfoutput>#Assform.F175#</cfoutput></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:<br>
                                <span>(<cfoutput>#GetPhysician.Phys_First#,#GetPhysician.Phys_Last#<cfif GetPhysician.Phys_Credentials NEQ ''>,#GetPhysician.Phys_Credentials#</cfif></cfoutput>)</span>
                              </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(printCompletedDate,"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>
                            
                    <!--- <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# 
            <cfif  url.Evaltype EQ '6_transfer' >
                6 - Transferred to an inpatient facility 
            <cfelse>
                #Request.assessmenttype#
            </cfif> for <cfoutput>#AssForm.Pt_First# #AssForm.Pt_Last#</cfoutput></cfoutput>
            </td>
            </tr>
            </table>        
        </cfdocumentitem>
           


</cfdocument>


