<!---
This file is Copyright © 1998-2009 by Home Care Business Services. This work may not be reproduced, in whole or in part, 
using any medium, including, but not limited to, electronic transmission, CD-ROM or published in print, without the express 
permission of Home Care Business Services.

$Revision: 1.6 $
$Id: 487_print.cfm,v 1.6 2010/05/27 22:04:14 melissa Exp $
$Date: 2010/05/27 22:04:14 $
--->
<!--- #10621: old dashboard 487 layout. Fax and print use the patient template. --->
<cflocation url="#application.siteURL#/patientadmin_new/patient/487_print.cfm?#CGI.query_string#" addtoken="no" />
<cfabort />

<cfset url.afid = decrypt(#url.afid#, "54kczhzgHTj4a8n+SRZPyg==", "AES", "Hex") />

<cfquery name="Get487" datasource="#Application.DataSrc#">
    SELECT pCMS4857.Agy_Name, pCMS4857.Agy_CCN, pCMS4857.Agy_Street, pCMS4857.Agy_City, pCMS4857.Agy_State, pCMS4857.Agy_Zip, pCMS4857.Agy_Phone,
        "" AS Faxs, "" AS Location, pCMS4857.Pt_Last, pCMS4857.Pt_First, pCMS4857.Render_Phys_ID AS Primary_ReferringPhys_ID_M0072, pCMS4857.Pt_Agy_ID, pCMS4857.Pt_DOB, pPhysicians.Phys_Last AS LastName, pPhysicians.Phys_First AS FirstName, pPhysicians.Phys_Street AS Address1, "" AS Address2, pPhysicians.Phys_City AS City, pPhysicians.Phys_State AS State, pPhysicians.Phys_Zip AS Zip, pPhysicians.Phys_Phone AS Telephone1, pPhysicians.Phys_ID, Order_ID,
        pCMS4857.Date_Create AS Record_Creation_Date, pCMS4857.Change_by AS Record_Modified_by, "" AS Medical_Num_Item_4, 
        "" AS SOC_Item_2, pCMS4857.Certification_From, pCMS4857.Certification_To, pCMS4857.Assmt_ID,
        Order_description AS Addendum_Details_21, pCMS4857.MD_Digital_Signature, pCMS4857.Date_Sent,
        pCMS4857.Date_Received, pCMS4857.Clinician_Signature, pCMS4857.Form_Status, pCMS4857.Created_by,
        0 AS contact_id, "" AS ContactName, "" AS ContactType, "" AS ContactStreet, "" AS ContactCity, "" AS ContactState, "" AS ContactZip,
        pCMS4857.Render_Phys_ID, "" AS ContactTelephone1, "" AS ContactTelephone2, pPhysicians.Phys_Fax AS FAX
    FROM #Request.prefix_db_agency#.pCMS4857
    LEFT OUTER JOIN #Request.prefix_db_lookup#.pPhysicians ON pCMS4857.Render_Phys_ID = pPhysicians.Phys_ID 
    WHERE Order_ID = '#url.afid#'
    GROUP BY pCMS4857.Order_ID
</cfquery>

<cfquery name="GetAdmit" datasource="#Application.DataSrc#">
    SELECT * FROM #Request.prefix_db_agency#.pAdmit
    WHERE Admit_ID IN 
        (SELECT Admit_ID FROM #Request.prefix_db_agency#.pAssessments WHERE Assmt_ID = #Get487.Assmt_ID# AND status = 0)
    AND status = 0 
</cfquery>

<!---
<cfquery name="GetE" datasource="#Application.DataSrc#">
    SELECT Employee_ID, First_Name, Last_Name 
    FROM Employee
    WHERE Employee_ID = '#Get487.Record_Created_by#' AND EmployeeType != 'Physician'
</cfquery> --->

<cfquery name="GetEmps" datasource="#Application.DataSrc#">
    SELECT Emp_ID, Emp_First, Emp_Last  
    FROM #Request.prefix_db_lookup#.pEmployee
    WHERE
    <cfif GetAdmit.clinical_authorization EQ 1>
        Emp_ID = '#GetAdmit.Clinical_Manager#' 
    <cfelseif GetAdmit.case_authorization EQ 1>    
        Emp_ID = '#GetAdmit.Case_Manager#' 
    <cfelse>
        Emp_ID = '#Get487.Created_by#'
    </cfif>
</cfquery>

<cfif Get487.Form_Status NEQ 'Signed & Received via Fax' AND Get487.Form_Status NEQ 'Sent via Fax' AND len(getTimeZone.FAX_APINumber) gt 0>
    <cfquery name="updatepCMS4857" datasource="#Application.DataSrc#">
        UPDATE #Request.prefix_db_agency#.pCMS4857 
        SET Form_Status = 'Printed Only'
        WHERE Order_ID = <cfqueryparam value="#url.afId#" CFSQLType="CF_SQL_INTEGER">
    </cfquery> 
</cfif>

<cfset CrLf = Chr(13) & Chr(10) />

<cfdocument format="PDF" orientation="portrait" overwrite="yes">
    <cfoutput query="get487">
        <div style="font-size:14px; font-weight:bold;">
            Medical Update for #Pt_First# #Pt_Last# #Medical_Num_Item_4# DOB: #DateFormat(Pt_DOB, "mm/dd/yyyy")#
        </div>
        <br><br>
        <div style="font-size:13px;">
            <b>Date Order Created:</b> #DateFormat(Record_Creation_Date, "mm/dd/yyyy")#
            <br><br>
            <b>Agency Assigned Id:</b> #Pt_Agy_ID#
            <br><br>
            <!--- <b>Start of Care:</b> #DateFormat(SOC_Item_2, "mm/dd/yyyy")#
            <br><br> --->
            <b>Certification Period:</b> #DateFormat(Certification_From, "mm/dd/yyyy")# to #DateFormat(Certification_To, "mm/dd/yyyy")#</b>
            <br><br>
            <cfif get487.Location neq 0 and get487.Location neq ''>
                <i>#Agy_Name# #Agy_CCN#<br>#Agy_Street#<br>#Agy_City#, #Agy_State# #Agy_Zip#<br>PHONE #Agy_Phone# FAX #getTimeZone.Agency_Fax#</i>
            <cfelse>
                <i>#Agy_Name# #Agy_CCN#<br>#Agy_Street#<br>#Agy_City#, #Agy_State# #Agy_Zip#<br>PHONE #Agy_Phone# FAX #getTimeZone.Agency_Fax#</i>
            </cfif>
            <br><br>
            _______________________________________________________________<br>
            Orders:<br>
            <td><i>#Replace(Addendum_Details_21, CrLf, "<br>", "ALL")#</i></td>
            <br><br><br><br>
            <!--- Read back and verified? Yes___ No___
            <br> --->
            _______________________________________________________________<br> 

            <cfif Get487.contact_id> 
                <i>#ContactName#<br>#ContactStreet#<br>#ContactCity#, #ContactState# #ContactZip# #ContactTelephone1# #ContactTelephone2#</i>
            <cfelse>
                <i>#FirstName# #LastName#<br>#Address1#<br><cfif Address2 NEQ ''>#Address2#<br></cfif>
                #City#, #State# #Zip#  
                <br />
                Tele:#Telephone1# FAX: #FAX#</i>
            </cfif>
        </div>
    </cfoutput>

    <br><br>
    <cfoutput>
        <!--- <cfif Get487.MD_Digital_Signature IS NOT ''>
            <cfif Get487.contact_id eq 0>PHYSICIAN </cfif>SIGNATURE VALID - Digitally Signed by #Get487.MD_Digital_Signature# 
        <cfelse> --->
        <cfif Get487.contact_id eq 0>Physician </cfif>Signature_________________________________________ Date __________
        <!--- </cfif> --->
    </cfoutput>
    <br><br>
    <p>
        <cfoutput>
            <cfif Get487.Clinician_Signature IS NOT ''>
                <strong>#Get487.Clinician_Signature#</strong>
            <cfelse>
                Staff Signature: <span style="text-decoration: underline;">Electronically Signed by #GetEmps.Emp_Last#, #GetEmps.Emp_First#</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Date <span style="text-decoration: underline;">#DateFormat(Get487.Date_Sent, "mm/dd/yyyy")#</span>
            </cfif>
        </cfoutput><br>
    </p>
</cfdocument>
