<!---
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.2 $
$Id: event_log.cfm,v 1.2 2010/03/22 22:03:44 arlen Exp $
$Date: 2010/03/22 22:03:44 $
--->
<script type="text/javascript">
    $(document).ready(function () {
        $("#incident_tables").dataTable({
            "sPaginationType": "full_numbers",
        //  "bJQueryUI": true,
            "aaSorting": [[0,'desc']]
        });
    });
    $(function() {
        $( "#tabs" ).tabs();
    });

</script>
<!--- Set Page Parameters --->
<cfset CurrentPage=GetFileFromPath(GetTemplatePath())>
<cfparam name="PageNum_GetEvent" default="1">
<cfparam name="url.res" default="No">
<cfparam name="form.From_Date" type="string" default="">
<cfparam name="form.To_Date" type="string" default="">
<cfparam name='session.atTelFromDate' default='' />
<cfparam name='session.atTelToDate' default='' />
<cfparam name='session.eventsubval' default='' />

 <cfif isdefined('form.EventSub_ID') and #form.EventSub_ID# neq 0>
  <cfset session.eventsubval = form.EventSub_ID />
 <cfelse>
 <cfset session.eventsubval =0>
 </cfif>

<cfparam name="form.EventSub_ID" type="integer" default="0">

<!--- Page specific code, such as queries and variable settings should go here --->

<cfquery  name="GetEvent" datasource="#Application.DataSrc#">
 

    SELECT Event.Event_ID, Event.EventSub_ID, Event.Event_Date, Event.Patient_ID,
    pPatients.Pt_Last, pEmployee.Emp_ID, pEmployee.Emp_Last, EventSubjects.EventSub_ID,
     EventSubjects.Subject,Event.Resolved,Event_to.Date_Sent,pPatients.Pt_First,pPatients.Patient_ID    
    FROM #Request.prefix_db_agency#.Event
     LEFT OUTER JOIN #Request.prefix_db_agency#.Event_to ON Event_to.Event_ID = Event.Event_ID
    LEFT OUTER JOIN #Request.prefix_db_lookup#.pEmployee ON pEmployee.Emp_ID =  Event_to.Emp_ID
    JOIN #Request.prefix_db_agency#.pPatients ON Event.Patient_ID = pPatients.Patient_ID AND pPatients.status IN (0,1,4)
    JOIN  #Request.prefix_db_agency#.EventSubjects ON Event.EventSub_ID = EventSubjects.EventSub_ID
    WHERE Event.Agency_ID = #session.AgencyID#
    And Event.Resolved = '#url.res#'
    <cfif #form.EventSub_ID# neq 0>
        AND Event.EventSub_ID = #form.EventSub_ID#
    </cfif>
    AND Event.status = 0
    <cfif #Form.From_Date# neq '' and #Form.To_Date# neq ''>
        AND Event.Event_Date BETWEEN #CreateODBCDate(Form.From_Date)# AND #CreateODBCDate(Form.To_Date)#
    </cfif>
    <cfif session.eaRole DOES NOT CONTAIN 'Project Manager' AND 
    session.eaRole DOES NOT CONTAIN 'Clinical Quality Assurance'>
         AND Event_to.Emp_ID = '#session.EmployeeId#'
    </cfif>
     <!---  GROUP BY Event.Event_ID --->
    ORDER BY Event_Date DESC, Event.Event_ID

</cfquery>

<cfquery  name="GetEventSub" datasource="#Application.DataSrc#">
    SELECT EventSub_ID, Subject FROM #Request.prefix_db_agency#.EventSubjects
    WHERE Agency_ID = #session.AgencyID#
    ORDER BY Subject
</cfquery>

<cfset MaxRows_GetEvent=10>
<cfset StartRow_GetEvent=Min((PageNum_GetEvent-1)*MaxRows_GetEvent+1,Max(GetEvent.RecordCount,1))>
<cfset EndRow_GetEvent=Min(StartRow_GetEvent+MaxRows_GetEvent-1,GetEvent.RecordCount)>
<cfset TotalPages_GetEvent=Ceiling(GetEvent.RecordCount/MaxRows_GetEvent)>
<cfset QueryString_GetEvent=Iif(CGI.QUERY_STRING NEQ "",DE("&"&CGI.QUERY_STRING),DE(""))>
<cfset tempPos=ListContainsNoCase(QueryString_GetEvent,"PageNum_GetEvent=","&")>
<cfif tempPos NEQ 0>
  <cfset QueryString_GetEvent=ListDeleteAt(QueryString_GetEvent,tempPos,"&")>
</cfif>

<!--- End page specific code --->
<style>
    @media print{
        a[href]:after
        {
        content:none
        }
    }
</style>

<div class="portlet box blue">
    <div class="portlet-title">
        <div class="caption">
            <i class="fa fa-gear"></i> 
            <cfif url.res eq "No">
                Unresolved Incident Log
            <cfelse>
                Resolved Incident Log
            </cfif>
        </div>
        <div class="tools">
            <a href="javascript:;" class="collapse"></a>
        </div>
    </div>
    <div class="portlet-body form">
        <form name="form" id='form' method="post" action="index.cfm?page=agency&cat=AgencyManagement&rpt=event_log&res=<cfoutput>#url.res#</cfoutput>" onSubmit="return v(this);">
			<div class="form-body">
				<cfoutput>
                	<div class="form-group">
                        <label>Select Date</label>
                        <div>
                            <div class="input-group input-large date-picker input-daterange" data-date-format="mm/dd/yyyy">
                                <input type="text" class="form-control" name="From_Date" value="<cfoutput>#Form.From_Date#</cfoutput>" />
                
                                <span class="input-group-addon"> to </span>
                                
                                <input type="text" class="form-control" name="To_Date" value="<cfoutput>#Form.To_Date#</cfoutput>" />
                            </div>
                            <span class="help-block">Date Format: mm/dd/yyyy </span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label>Subject :</label>
                        <select class="form-control" name="EventSub_ID" id="select">
                            <option value="0">All</option>
                            <cfloop query="GetEventSub">
                            	<option value="#GetEventSub.EventSub_ID#" <cfif session.eventsubval eq GetEventSub.EventSub_ID>selected</cfif>>#GetEventSub.Subject#</option>
                            </cfloop>
                        </select>
                    </div>
                </cfoutput>
            </div>
            <div class="form-actions">
                <input class="btn blue" type="submit" value="Submit" name='submit' id='submit'>
                <input class="btn blue" type="button" value="Reset" onClick="resetForm();">
            </div>
        </form>
	</div>
</div>
<cfoutput>
	<script>
	 
		function resetForm() {
			for(i=0;i<document.form.length;i++) {
				switch(document.form[i].name) {
					case 'From_Date':
						document.form[i].value = '';
					break;
					case 'To_Date':
						document.form[i].value = '';
					break;
					case 'EventSub_ID':
						document.form[i].value = '0';
					break;
				}
			}
			document.getElementById('EventSub_ID').value='0';
		}
	</script>
</cfoutput>

<cfif #GetEvent.recordcount# neq 0>
	<div class="portlet box blue">
        <div class="portlet-title">
            <div class="caption">
                <i class="fa fa-gear"></i> 
                <cfif url.res eq "No">
                    Unresolved Incident Log
                <cfelse>
                    Resolved Incident Log
                </cfif>
            </div>
            <div class="tools">
                <a href="javascript:;" class="collapse"></a>
            </div>
			 <div class="actions">
                <form method="post" name="Active_form" id="Active_form" action="index.cfm?page=agency&cat=AgencyManagement&rpt=event_log_export&res=<cfoutput>#url.res#</cfoutput><cfif #form.EventSub_ID# neq 0>&esubid=<cfoutput>#form.EventSub_ID#</cfoutput></cfif><cfif #Form.From_Date# neq '' and #Form.To_Date# neq ''>&fdate=<cfoutput>#Form.From_Date#</cfoutput>&tdate=<cfoutput>#Form.To_Date#</cfoutput></cfif>">
                    <cfoutput>
                        <a class="btn btn-default btn-sm" href="index.cfm?page=agency&cat=Event&rpt=patient_IncidenceWizard&ID=0&res=#url.res#">New Incident</a>
                        <cfif url.res eq "No">
                            <a class="btn btn-default btn-sm" href="index.cfm?page=agency&cat=Event&rpt=Event_log&res=Yes">Resolved Incident Log</a>
                        <cfelse>
                            <a class="btn btn-default btn-sm" href="index.cfm?page=agency&cat=Event&rpt=Event_log&res=No">Un-Resolved Incident Log</a>                    
                        </cfif>
                        <cfif #Form.From_Date# eq '' and #Form.To_Date# eq '' and #form.EventSub_ID# eq 0>
                            <a class="btn btn-default btn-sm" href="index.cfm?page=agency&cat=Event&rpt=Event_history_printer&res=#url.res#&esubid=#form.EventSub_ID#" target='_new'>Print Incident History</a>
                        <cfelseif #Form.From_Date# eq '' and #Form.To_Date# eq '' and #form.EventSub_ID# neq 0>
                            <a class="btn btn-default btn-sm" href="index.cfm?page=agency&cat=Event&rpt=Event_history_printer&res=#url.res#&esubid=#form.EventSub_ID#" target='_new'>Print Incident History</a>
                        <cfelse>
                            <a class="btn btn-default btn-sm" href="index.cfm?page=agency&cat=Event&rpt=Event_history_printer&res=#url.res#&fdate=#Form.From_Date#&tdate=#Form.To_Date#&esubid=#form.EventSub_ID#" target='_new'>Print Incident History</a>
                        </cfif>                    
                    </cfoutput>
                    <input class="btn btn-default btn-sm" type="submit" name="submit" value="Export Report">
                </form>
            </div>
        </div>
		
 <div class="portlet-body">           
           <table class="table table-striped table-bordered table-hover" id="incident_tables"> 
                <thead>
                    <tr>
                        <th>Date</th>
                        <th>Patient</th>
                        <th>Employee</th>
                        <th>Subject</th>
                        <th>Physician Fax Date</th>	
                        <th style="text-align:center;">Print</th>
                    </tr>
                </thead>
                <tbody>
					<cfoutput query="getEvent" group="Event_ID">
                       <cfset encpid = encrypt(#GetEvent.Patient_ID#,"#application.enckey#","AES","Hex") />
                        <tr>
                            <td>#DateFormat(GetEvent.Event_Date,"mm/dd/yyyy")#</td>
                            <td><a href="../patientadmin_new/index.cfm?page=patient&ID=#encpid#&cat=incidencelist">#GetEvent.Pt_Last#, #GetEvent.Pt_First#</a></td>
                            <td><cfoutput>#GetEvent.Emp_Last#<br></cfoutput></td>
                            <td><a href="index.cfm?page=agency&cat=Event&rpt=patient_IncidenceWizardnew&ID=#getEvent.Event_ID#&res=#url.res#">#Subject#</a></td>
                            <td>#DateFormat(GetEvent.Date_Sent,"mm/dd/yyyy")#</td>
                            <td style="text-align:center;">
                                <a class="btn blue btn-sm" href='index.cfm?page=agency&cat=Event&rpt=Event_form_printer&ID=#getEvent.Event_ID#' target="_blank"><i class="fa fa-print"></i> Print</a>
                            </td>
                        </tr>
                    </cfoutput>
                </tbody>
            </table>
            <!--- <cfif TotalPages_GetEvent neq 0>
				<cfif GetEvent.RecordCount gt 10>
					<div class="form-group">
                        <a class="btn blue" href="<cfoutput>#CurrentPage#?PageNum_GetEvent=1#QueryString_GetEvent#</cfoutput>">First 10</a>
                        <a class="btn blue" href="<cfoutput>#CurrentPage#?PageNum_GetEvent=#Max(DecrementValue(PageNum_GetEvent),1)##QueryString_GetEvent#</cfoutput>">Previous 10</a>
                        <a class="btn blue" href="<cfoutput>#CurrentPage#?PageNum_GetEvent=#Min(IncrementValue(PageNum_GetEvent),TotalPages_GetEvent)##QueryString_GetEvent#</cfoutput>">Next 10</a>
                        <a class="btn blue" href="<cfoutput>#CurrentPage#?PageNum_GetEvent=#TotalPages_GetEvent##QueryString_GetEvent#</cfoutput>">Last 10</a>
                    </div>
                </cfif>
            </cfif>--->
		</div>
	</div>
<cfelse>
	<div class="portlet box blue">
        <div class="portlet-title">
            <div class="caption">
                <i class="fa fa-gear"></i> 
                <cfif url.res eq "No">
                    Unresolved Incident Log
                <cfelse>
                    Resolved Incident Log
                </cfif>
            </div>
            <div class="tools">
                <a href="javascript:;" class="collapse"></a>
            </div>
            <div class="actions">
                <form method="post" name="Active_form" id="Active_form" action="index.cfm?page=agency&cat=AgencyManagement&rpt=event_log_export&res=<cfoutput>#url.res#</cfoutput><cfif #form.EventSub_ID# neq 0>&esubid=<cfoutput>#form.EventSub_ID#</cfoutput></cfif><cfif #Form.From_Date# neq '' and #Form.To_Date# neq ''>&fdate=<cfoutput>#Form.From_Date#</cfoutput>&tdate=<cfoutput>#Form.To_Date#</cfoutput></cfif>">
                    <cfoutput>
                        <a class="btn btn-default btn-sm" href="index.cfm?page=agency&cat=Event&rpt=patient_IncidenceWizard&ID=0&res=#url.res#">New Incident</a>
                        <cfif url.res eq "No">
                            <a class="btn btn-default btn-sm" href="index.cfm?page=agency&cat=Event&rpt=Event_log&res=Yes">Resolved Incident Log</a>
                        <cfelse>
                            <a class="btn btn-default btn-sm" href="index.cfm?page=agency&cat=Event&rpt=Event_log&res=No">Un-Resolved Incident Log</a>                    
                        </cfif>
                        <cfif #Form.From_Date# eq '' and #Form.To_Date# eq '' and #form.EventSub_ID# eq 0>
                            <a class="btn btn-default btn-sm" href="index.cfm?page=agency&cat=Event&rpt=Event_history_printer&res=#url.res#&esubid=#form.EventSub_ID#" target='_new'>Print Incident History</a>
                        <cfelseif #Form.From_Date# eq '' and #Form.To_Date# eq '' and #form.EventSub_ID# neq 0>
                            <a class="btn btn-default btn-sm" href="index.cfm?page=agency&cat=Event&rpt=Event_history_printer&res=#url.res#&esubid=#form.EventSub_ID#" target='_new'>Print Incident History</a>
                        <cfelse>
                            <a class="btn btn-default btn-sm" href="index.cfm?page=agency&cat=Event&rpt=Event_history_printer&res=#url.res#&fdate=#Form.From_Date#&tdate=#Form.To_Date#&esubid=#form.EventSub_ID#" target='_new'>Print Incident History</a>
                        </cfif>                    
                    </cfoutput>
                    <input class="btn btn-default btn-sm" type="submit" name="submit" value="Export Report">
                </form>
            </div>
        </div>
        <div class="portlet-body">
        	<table class="table table-bordered table-striped table-condensed flip-content">
                <thead>
                    <tr>
                        <th>Date</th>
                        <th>Patient</th>
                        <th>Employee</th>
                        <th>Subject</th>	
                        <th style="text-align:center;">Print</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td colspan="5">No data was found. Please try a different search.</td>
                    </tr>
				</tbody>
			</table>
		</div>
    </div>
</cfif>
