Filter appointment report by category
authorKevin Yeh <kevinyeh@alum.mit.edu>
Thu, 14 Feb 2013 20:43:08 +0000 (14 15:43 -0500)
committerKevin Yeh <kevinyeh@alum.mit.edu>
Fri, 22 Feb 2013 14:06:11 +0000 (22 09:06 -0500)
interface/reports/appointments_report.php
library/appointments.inc.php

index 2a26cc4..76b47f5 100644 (file)
@@ -189,7 +189,24 @@ $form_orderby = getComparisonOrder( $_REQUEST['form_orderby'] ) ?  $_REQUEST['fo
                        <tr>
                                <td class='label'><?php xl('Status','e'); ?>:</td>
                                <td><?php generate_form_field(array('data_type'=>1,'field_id'=>'apptstatus','list_id'=>'apptstat','empty_title'=>'All'),$_POST['form_apptstatus']);?></td>
-                               <td colspan="2">&nbsp;</td>
+                               <td><?php echo xlt('Category')?></td>
+                               <td>
+                                    <select id="form_apptcat" name="form_apptcat">
+                                        <?php
+                                            $categories=fetchAppointmentCategories();
+                                            echo "<option value='ALL'>".xlt("All")."</option>";
+                                            while($cat=sqlFetchArray($categories))
+                                            {
+                                                echo "<option value='".attr($cat['id'])."'";
+                                                if($cat['id']==$_POST['form_apptcat'])
+                                                {
+                                                    echo " selected='true' ";
+                                                }
+                                                echo    ">".text(xl_appt_category($cat['category']))."</option>";
+                                            }
+                                        ?>
+                                    </select>
+                                </td>
                        </tr>
                        
                        <tr>
@@ -274,8 +291,16 @@ if ($_POST['form_refresh'] || $_POST['form_orderby']) {
        
        $lastdocname = "";
        //Appointment Status Checking
-       $form_apptstatus = $_POST['form_apptstatus'];
-       
+        $form_apptstatus = $_POST['form_apptstatus'];
+        $form_apptcat=null;
+       if(isset($_POST['form_apptcat']))
+        {
+            if($form_apptcat!="ALL")
+            {
+                $form_apptcat=intval($_POST['form_apptcat']);
+            }
+        }
+            
        //Without provider and facility data checking
        $with_out_provider = null;
        $with_out_facility = null;
@@ -287,7 +312,7 @@ if ($_POST['form_refresh'] || $_POST['form_orderby']) {
        if( isset($_POST['with_out_facility']) ){
                $with_out_facility = $_POST['with_out_facility'];
        }
-       $appointments = fetchAppointments( $from_date, $to_date, $patient, $provider, $facility, $form_apptstatus, $with_out_provider, $with_out_facility );
+       $appointments = fetchAppointments( $from_date, $to_date, $patient, $provider, $facility, $form_apptstatus, $with_out_provider, $with_out_facility,$form_apptcat );
        
        if ( $show_available_times ) {
                $availableSlots = getAvailableSlots( $from_date, $to_date, $provider, $facility );
index 0124c09..0bb2cd6 100644 (file)
@@ -92,7 +92,7 @@ function fetchAllEvents( $from_date, $to_date, $provider_id = null, $facility_id
        return $appointments;
 }
 
-function fetchAppointments( $from_date, $to_date, $patient_id = null, $provider_id = null, $facility_id = null, $pc_appstatus = null, $with_out_provider = null, $with_out_facility = null )
+function fetchAppointments( $from_date, $to_date, $patient_id = null, $provider_id = null, $facility_id = null, $pc_appstatus = null, $with_out_provider = null, $with_out_facility = null, $pc_catid = null )
 {
        $where = "";
        if ( $provider_id ) $where .= " AND e.pc_aid = '$provider_id'";
@@ -117,7 +117,12 @@ function fetchAppointments( $from_date, $to_date, $patient_id = null, $provider_
                $filter_appstatus = " AND e.pc_apptstatus = '".$pc_appstatus."'";
        }
        $where .= $filter_appstatus;
-       
+
+        if($pc_catid !=null)
+        {
+            $where .= " AND e.pc_catid=".intval($pc_catid); // using intval to escape this parameter
+        }
+        
        //Without Provider checking
        $filter_woprovider = '';
        if($with_out_provider != ''){
@@ -437,4 +442,10 @@ function compareAppointmentsByStatus( $appointment1, $appointment2 )
        return compareBasic( $status1, $status2 );
 }
 
+function fetchAppointmentCategories()
+{
+     $catSQL= " SELECT pc_catid as id, pc_catname as category " 
+            . " FROM openemr_postcalendar_categories WHERE pc_recurrtype=0 and pc_cattype=0 ORDER BY category";    
+     return sqlStatement($catSQL);
+}
 ?>