function consult_info() {
     if (func_num_args()>0) {
         $arg_list = func_get_args();
         $menu_id = $arg_list[0];
         $post_vars = $arg_list[1];
         $get_vars = $arg_list[2];
         $validuser = $arg_list[3];
         $isadmin = $arg_list[4];
         //print_r($arg_list);
     }
     $sql = "select c.consult_id, p.patient_id, p.patient_lastname, p.patient_firstname, see_doctor_flag ".
            "from m_consult c, m_patient p where c.patient_id = p.patient_id ".
            "and consult_end = '0000-00-00 00:00:00' order by c.consult_date asc";
     if ($result = mysql_query($sql)) {
         print "<span class='patient'>".FTITLE_CONSULTS_TODAY."</span><br>";
         print "<table width=600 bgcolor='#FFFFFF' cellpadding='3' cellspacing='0' style='border: 2px solid black'>";
         print "<tr><td>";
         print "<span class='tinylight'>HIGHLIGHTED NAMES OR THOSE MARKED WITH <img src='../images/star.gif' border='0'/> WILL SEE PHYSICIAN.</span><br/>";
         if (mysql_num_rows($result)) {
             // initialize array index
             $i=0;
             // have to return always to consult page
             // wherever this is shown
             $consult_menu_id = module::get_menu_id("_consult");
             while (list($cid, $pid, $plast, $pfirst, $see_doctor) = mysql_fetch_array($result)) {
                 $visits = healthcenter::get_total_visits($pid);
                 $consult_array[$i] = "<a href='".$_SERVER["PHP_SELF"]."?page=CONSULTS&menu_id=$consult_menu_id&consult_id=$cid&ptmenu=DETAILS' title='".INSTR_CLICK_TO_VIEW_RECORD."' ".($see_doctor=="Y"?"style='background-color: #FFFF33'":"").">".
                                      "<b>$plast, $pfirst</b></a> [$visits] ".($see_doctor=="Y"?"<img src='../images/star.gif' border='0'/>":"");
                 $i++;
             }
             // pass on patient list to be columnized
             print $this->columnize_list($consult_array);
         } else {
             print "<font color='red'>No consults available.</font>";
         }
         $sql_time = "select round(avg(unix_timestamp(consult_end)-unix_timestamp(consult_date))/60,2) consult_minutes from m_consult where consult_end>0 and to_days(consult_date) = to_days(sysdate());";
         if ($result_time = mysql_query($sql_time)) {
             if (mysql_num_rows($result_time)) {
                 list($mean_consult_time) = mysql_fetch_array($result_time);
             }
             if ($mean_consult_time) {
                 print "<tr><td class='tinylight'>";
                 if ($mean_consult_time>60) {
                     $unit_time = "hour(s)";
                 } elseif ($meantime>1440) {
                     $unit_time = "day(s)";
                 } else {
                     $unit_time = "minute(s)";
                 }
                 print "AVERAGE CONSULT TIME: <font color='red'>$mean_consult_time $unit_time</font><br/>";
                 print "</td></tr>";
             }
         }
         print "</td></tr>";
         print "</table>";
     }
 }
 function consult_info()
 {
     if (func_num_args() > 0) {
         $arg_list = func_get_args();
         $menu_id = $arg_list[0];
         $post_vars = $arg_list[1];
         $get_vars = $arg_list[2];
         $validuser = $arg_list[3];
         $isadmin = $arg_list[4];
         //print_r($arg_list);
     }
     $arr_facility = array();
     if (mysql_num_rows(mysql_query("SHOW TABLES LIKE 'm_lib_health_facility_barangay'")) != 0) {
         $q_facility = mysql_query("SELECT DISTINCT(a.facility_id),b.facility_name FROM m_lib_health_facility_barangay a,m_lib_health_facility b WHERE a.facility_id=b.facility_id ORDER by b.facility_name ASC") or die("Cannot query 1226 " . mysql_error());
         if (mysql_num_rows($q_facility) != 0) {
             while (list($facility_id, $facility_name) = mysql_fetch_array($q_facility)) {
                 array_push($arr_facility, array($facility_id, $facility_name));
             }
         }
     }
     if (empty($arr_facility)) {
         $result = mysql_query("select c.consult_id, p.patient_id, p.patient_lastname, p.patient_firstname, see_doctor_flag from m_consult c, m_patient p where c.patient_id = p.patient_id and consult_end = '0000-00-00 00:00:00' order by c.consult_date asc") or die("Cannot query 1241 " . mysql_error());
     } else {
         if (!empty($_GET["facid"])) {
             $q_facid = mysql_query("SELECT a.barangay_id FROM m_lib_barangay a, m_lib_health_facility_barangay b WHERE b.facility_id='{$_GET['facid']}' AND a.barangay_id=b.barangay_id") or die("Cannot query 1246 " . mysql_error());
             if (mysql_num_rows($q_facid) != 0) {
                 $arr_brgy = array();
                 while (list($brgy_id) = mysql_fetch_array($q_facid)) {
                     array_push($arr_brgy, $brgy_id);
                 }
                 $str_brgy = implode(",", $arr_brgy);
                 $result = mysql_query("select c.consult_id, p.patient_id, p.patient_lastname, p.patient_firstname, see_doctor_flag from m_consult c, m_patient p, m_family_members x, m_family_address y, m_lib_barangay z where c.patient_id = p.patient_id and consult_end = '0000-00-00 00:00:00' AND p.patient_id=x.patient_id AND x.family_id=y.family_id AND y.barangay_id IN ({$str_brgy}) AND y.barangay_id=z.barangay_id order by c.consult_date asc") or die("Cannot query 1258 " . mysql_error());
             } else {
                 echo "<script language='Javascript'>";
                 echo "window.alert('Invalid health facility code!')";
                 echo "</script>";
             }
         } else {
             $result = mysql_query("select c.consult_id, p.patient_id, p.patient_lastname, p.patient_firstname, see_doctor_flag from m_consult c, m_patient p where c.patient_id = p.patient_id and consult_end = '0000-00-00 00:00:00' order by c.consult_date asc") or die("Cannot query 1271 " . mysql_error());
         }
     }
     if ($result) {
         print "<a name='consults'></a>";
         print "<span class='patient'>" . FTITLE_CONSULTS_TODAY . "</span><br>";
         healthcenter::show_tab_headers($arr_facility);
         print "<table width=600 bgcolor='#FFFFFF' cellpadding='3' cellspacing='0' style='border: 2px solid black'>";
         print "<tr><td>";
         print "<span class='tinylight'>HIGHLIGHTED NAMES OR THOSE MARKED WITH <img src='../images/star.gif' border='0'/> WILL SEE PHYSICIAN.</span><br/>";
         if (mysql_num_rows($result)) {
             // initialize array index
             $i = 0;
             // have to return always to consult page
             // wherever this is shown
             $consult_menu_id = module::get_menu_id("_consult");
             while (list($cid, $pid, $plast, $pfirst, $see_doctor) = mysql_fetch_array($result)) {
                 $q_lab = mysql_query("SELECT request_id,request_done FROM m_consult_lab WHERE patient_id='{$pid}' AND consult_id='{$cid}'") or die("Cannot query 1224" . mysql_error());
                 if (mysql_num_rows($q_lab) != 0) {
                     $arr_done = array();
                     $arr_id = array();
                     while (list($req_id, $done_status) = mysql_fetch_array($q_lab)) {
                         array_push($arr_id, $req_id);
                         array_push($arr_done, $done_status);
                     }
                     $done = in_array("N", $arr_done) ? "N" : "Y";
                     $request_id = $arr_id[0];
                     $url = "page=CONSULTS&menu_id=1327&consult_id={$cid}&ptmenu=LABS#consults";
                 } else {
                     $request_id = $done = "";
                 }
                 $visits = healthcenter::get_total_visits($pid);
                 $consult_array[$i] = "<a href='" . $_SERVER["PHP_SELF"] . "?page=CONSULTS&menu_id={$consult_menu_id}&consult_id={$cid}&ptmenu=DETAILS' title='" . INSTR_CLICK_TO_VIEW_RECORD . "' " . ($see_doctor == "Y" ? "style='background-color: #FFFF33'" : "") . ">" . "<b>{$plast}, {$pfirst}</b></a> [{$visits}] " . ($see_doctor == "Y" ? "<img src='../images/star.gif' border='0'/>" : "") . ($request_id != "" ? $done == "Y" ? "<a href='{$_SERVER['PHP_SELF']}?{$url}' title='lab completed'><img src='../images/lab.png' width='15px' height='15px' border='0' alt='lab completed' /></a>" : "<a href='{$_SERVER['PHP_SELF']}?{$url}' title='lab pending'><img src='../images/lab_untested.png' width='15px' height='15px' border='0' alt='lab pending' /></a>" : "");
                 $i++;
             }
             // pass on patient list to be columnized
             print $this->columnize_list($consult_array);
         } else {
             print "<font color='red'>No consults available.</font>";
         }
         $sql_time = "select round(avg(unix_timestamp(consult_end)-unix_timestamp(consult_date))/60,2) consult_minutes from m_consult where consult_end>0 and to_days(consult_date) = to_days(sysdate());";
         if ($result_time = mysql_query($sql_time)) {
             if (mysql_num_rows($result_time)) {
                 list($mean_consult_time) = mysql_fetch_array($result_time);
             }
             if ($mean_consult_time) {
                 print "<tr><td class='tinylight'>";
                 if ($mean_consult_time > 60) {
                     $unit_time = "hour(s)";
                 } elseif ($meantime > 1440) {
                     $unit_time = "day(s)";
                 } else {
                     $unit_time = "minute(s)";
                 }
                 print "AVERAGE CONSULT TIME: <font color='red'>{$mean_consult_time} {$unit_time}</font><br/>";
                 print "</td></tr>";
             }
         }
         print "</td></tr>";
         print "</table>";
     }
 }
 function generate_summary()
 {
     if (func_num_args() > 0) {
         $arg_list = func_get_args();
         $menu_id = $arg_list[0];
         $post_vars = $arg_list[1];
         $get_vars = $arg_list[2];
         $validuser = $arg_list[3];
         $isadmin = $arg_list[4];
         //print_r($arg_list);
     }
     list($month, $day, $year) = explode("/", $post_vars["report_date"]);
     //$report_date = $year."-".str_pad($month, 2, "0", STR_PAD_LEFT)."-".str_pad($day, 2, "0", STR_PAD_LEFT);
     $report_date = $year . '-' . $month . '-' . str_pad($day, 2, "0", STR_PAD_LEFT);
     list($end_month, $end_day, $end_year) = explode("/", $post_vars["end_report_date"]);
     //$end_report_date = $end_year."-".str_pad($end_month, 2, "0", STR_PAD_LEFT)."-".str_pad($day, 2, "0", STR_PAD_LEFT);
     $end_report_date = $end_year . '-' . $end_month . '-' . str_pad($end_day, 2, "0", STR_PAD_LEFT);
     $_SESSION[report_date] = $report_date;
     $_SESSION[end_report_date] = $end_report_date;
     // STEP 1. empty report tables for given date
     $sql_delete = "delete from m_consult_report_dailyservice where service_date BETWEEN '{$report_date}' AND '{$end_report_date}'";
     $result_delete = mysql_query($sql_delete);
     $sql_delete = "delete from m_consult_ccdev_report_dailyservice where service_date BETWEEN '{$report_date}' AND '{$end_report_date}'";
     $result_delete = mysql_query($sql_delete);
     $sql_delete = "delete from m_consult_mc_report_dailyservice where service_date BETWEEN '{$report_date}' AND '{$end_report_date}'";
     $result_delete = mysql_query($sql_delete);
     // STEP 2. get all consults for specified report date
     // records are unique for patient_id and service_date
     /*$sql_patient = "select c.patient_id, c.consult_id, ".
       "concat(p.patient_lastname, ', ', p.patient_firstname) patient_name, ".
              "round((to_days(c.consult_date)-to_days(p.patient_dob))/365,2) patient_age, ".
              "p.patient_gender ".
              "from m_consult c, m_patient p ".
              "where c.patient_id = p.patient_id ".
              "and to_days(c.consult_date) = to_days('$report_date')"; */
     $sql_patient = "select c.patient_id, c.consult_id, " . "concat(p.patient_lastname, ', ', p.patient_firstname, ' ',p.patient_middle) patient_name, " . "round((to_days(c.consult_date)-to_days(p.patient_dob))/365,2) patient_age, " . "p.patient_gender,date_format(c.consult_date,'%h:%i %p') as consult_start,date_format(c.consult_end,'%h:%i %p') as consult_end, round((unix_timestamp(c.consult_end)-unix_timestamp(c.consult_date))/60,2) as consult_minutes, elapsed_time " . "from m_consult c, m_patient p " . "where c.patient_id = p.patient_id " . "and c.consult_date BETWEEN '{$report_date}' AND '{$end_report_date}'";
     $result_patient = mysql_query($sql_patient) or die("Cannot query: 305 " . mysql_error());
     if ($result_patient) {
         if (mysql_num_rows($result_patient)) {
             while ($patient = mysql_fetch_array($result_patient)) {
                 // get family and address
                 if ($family_id = family::get_family_id($patient["patient_id"])) {
                     $patient_address = family::get_family_address($family_id);
                     $barangay_id = family::barangay_id($family_id);
                 } else {
                     $family_id = 0;
                     $barangay_id = 0;
                     $patient_address = reminder::get_home_address($patient_id);
                     //$barangay_name = reminder::get_barangay($patient_id);
                 }
                 // get chief complaint and diagnosis from notes
                 $complaints = notes::get_complaints($patient["patient_id"], $report_date);
                 $diagnosis = notes::get_diagnosis_list($patient["patient_id"], $report_date);
                 $treatment = notes::get_plan($patient["patient_id"], $report_date);
                 //get vaccines
                 $vaccines = $this->get_vaccines($patient["patient_id"], $report_date, $end_report_date);
                 $services = $this->get_services($patient["consult_id"], $patient["patient_id"], $report_date, $end_report_date);
                 $ptgroup = $this->get_ptgroup($patient["consult_id"], $report_date, $end_report_date);
                 $aog = $this->get_aog($patient["patient_id"], $report_date, $end_report_date);
                 $visit_seq = healthcenter::get_total_visits($patient["patient_id"]);
                 $philhealth_id = philhealth::get_philhealth_id($patient["patient_id"]);
                 //get elapsed time and data and time started
                 $elapsed_time = $this->get_str_elapsed($patient["consult_start"], $patient["consult_end"], $patient["elapsed_time"]);
                 if ($mc_id = mc::registry_record_exists($patient["patient_id"])) {
                     $pp_weeks = mc::get_pp_weeks($mc_id, $patient["consult_id"]);
                     //$visit_sequence = mc::get_ppvisit_sequence($mc_id, $patient["consult_id"]);
                 }
                 if ($complaints != '' || $diagnosis != '' || $treatment != '') {
                     $sql_insert = "insert into m_consult_report_dailyservice (patient_id, patient_name, " . "patient_gender, patient_age, patient_address, patient_bgy, family_id, philhealth_id, " . "notes_cc, notes_dx, notes_tx, service_date) values " . "('" . $patient["patient_id"] . "', '" . $patient["patient_name"] . "', " . "'" . $patient["patient_gender"] . "', '" . $patient["patient_age"] . "', " . "'{$patient_address}', '{$barangay_id}', '{$family_id}', '{$philhealth_id}', " . "'{$complaints}', '{$diagnosis}', '{$treatment}', '{$report_date}')";
                     $result_insert = mysql_query($sql_insert);
                 }
                 if ($vaccines != '' || $services != '') {
                     if ($ptgroup == 'CHILD') {
                         $sql_insert = "insert into m_consult_ccdev_report_dailyservice (patient_id, " . "patient_name, patient_gender, patient_age, patient_address, patient_bgy, " . "family_id, philhealth_id, service_given, vaccine_given, service_date) values " . "('" . $patient["patient_id"] . "', '" . $patient["patient_name"] . "', " . "'" . $patient["patient_gender"] . "', '" . $patient["patient_age"] . "', " . "'{$patient_address}', '{$barangay_id}', '{$family_id}', '{$philhealth_id}', " . "'{$services}', '{$vaccines}', '{$report_date}')";
                         $result_insert = mysql_query($sql_insert);
                     }
                     if ($ptgroup == 'MATERNAL') {
                         $sql_insert = "insert into m_consult_mc_report_dailyservice (patient_id, " . "patient_name, patient_gender, patient_age, aog_weeks, postpartum_weeks, patient_address, " . "patient_bgy, family_id, philhealth_id, visit_sequence, service_given, vaccine_given, " . "service_date) values " . "('" . $patient["patient_id"] . "', '" . $patient["patient_name"] . "', " . "'" . $patient["patient_gender"] . "', '" . $patient["patient_age"] . "', " . "'{$aog}', '{$pp_weeks}', '{$patient_address}', '{$barangay_id}', '{$family_id}', '{$philhealth_id}', " . "'{$visit_seq}', '{$services}', '{$vaccines}', '{$report_date}')";
                         $result_insert = mysql_query($sql_insert);
                     }
                 }
             }
             /*$sql = "select patient_id 'PATIENT ID', concat(patient_name,' / ',patient_gender,' / ',patient_age) ".
                                    "'NAME / SEX / AGE', patient_address 'ADDRESS', patient_bgy 'BRGY', family_id 'FAMILY ID', ".  
                                    "philhealth_id 'PHILHEALTH ID', notes_cc 'COMPLAINTS', notes_dx 'DIAGNOSIS', notes_tx 'TREATMENT' ".
                                    "from m_consult_report_dailyservice where service_date = '$report_date' order by patient_name ";
                              
                             $pdf = new PDF('L','pt','A4');
                             $pdf->SetFont('Arial','',12); 
                             $pdf->AliasNbPages();
                             $pdf->connect('localhost','$_SESSION[dbuser]','$_SESSION[dbpass]','$_SESSION[dbname]');
                             $attr=array('titleFontSize'=>14,'titleText'=>'DAILY SERVICE REGISTER - CONSULTS');
             		$pdf->mysql_report($sql,false,$attr,"../modules/_uploads/consult_reg.pdf");
             		header("location:".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&report_menu=SUMMARY");
             
                             //$sql = "select patient_id 'PATIENT ID', concat(patient_name,' / ',patient_gender,' / ',patient_age) ".
                             //       "'NAME / SEX / AGE', patient_address 'ADDRESS', patient_bgy 'BRGY', family_id 'FAMILY ID', ".  
                             //       "philhealth_id 'PHILHEALTH ID', vaccine_given 'VACCINE(S) GIVEN', service_given 'SERVICE(S) GIVEN' "
                             //       "from m_consult_ccdev_report_dailyservice where service_date = '$report_date' order by patient_name ";
                     
                             //$pdf = new PDF('L','pt','A4');
                             //$pdf->SetFont('Arial','',12); 
                             //$pdf->AliasNbPages();
                             //$pdf->connect('localhost','$_SESSION[dbuser]','$_SESSION[dbpass]','$_SESSION[dbname]');
                             //$attr=array('titleFontSize'=>14,'titleText'=>'DAILY SERVICE REGISTER - CHILD CARE SERVICES');
             		//$pdf->mysql_report($sql,false,$attr,"../modules/_uploads/consult_ccdev_reg.pdf");
             		//header("location:".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&report_menu=SUMMARY");
             
                             $sql = "select patient_id 'PATIENT ID', concat(patient_name,' / ',patient_gender,' / ',patient_age) ".
                                    "'NAME / SEX / AGE', aog_weeks 'AOG (wks)', postpartum_weeks 'POSTPARTUM WK', ". 
                                    "patient_address 'ADDRESS', patient_bgy 'BRGY', family_id 'FAMILY ID', ".
                                    "philhealth_id 'PHILHEALTH ID', visit_sequence 'VISIT SEQ.', vaccine_given 'VACCINE(S) GIVEN', ".
                                    "service_given 'SERVICE(S) GIVEN' ".
                                    "from m_consult_mc_report_dailyservice where service_date = '$report_date' order by patient_name ";
             
                             $pdf = new PDF('L','pt','A4');
                             $pdf->SetFont('Arial','',12); 
                             $pdf->AliasNbPages();
                             $pdf->connect('localhost','$_SESSION[dbuser]','$_SESSION[dbpass]','$_SESSION[dbname]');
                             $attr=array('titleFontSize'=>14,'titleText'=>'DAILY SERVICE REGISTER - MATERNAL CARE SERVICES');
             		$pdf->mysql_report($sql,false,$attr,"../modules/_uploads/consult_mc_reg.pdf");
             		header("location:".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&report_menu=SUMMARY");
                             */
         }
     }
     //STEP 3. display daily service report
     print "<br/>";
     print "<b>DAILY SERVICE REPORT</b><br/>";
     print "REPORT DATE : <b>" . $post_vars["report_date"] . " to " . $post_vars["end_report_date"] . "</b><br/><br/>";
     print "PRINTER FRIENDLY VERSION: <a href='../chits_query/pdf_reports/dailyservice_report.php?arr=consult' target='new'>CONSULTS</a>&nbsp;&nbsp;&nbsp;";
     print "<a href='../chits_query/pdf_reports/dailyservice_report.php?arr=ccdev' target='new'>CHILD CARE</a>&nbsp;&nbsp;&nbsp;";
     print "<a href='../chits_query/pdf_reports/dailyservice_report.php?arr=mc' target='new'>MATERNAL CARE</a><br />";
     $_SESSION["arr_consult"] = $this->display_consults($report_date, "patient_id", $end_report_date);
     //pass the report_date and patient_id
     $_SESSION["arr_ccdev"] = $this->display_ccdev($report_date, $end_report_date);
     $_SESSION["arr_mc"] = $this->display_mc($report_date, $end_report_date);
     $sql = "select count(distinct(patient_id)) from m_consult where " . "to_days(consult_date) = to_days('{$report_date}') and patient_id != '0'";
     $result = mysql_result(mysql_query($sql), 0);
     print "<br/>";
     print "Total No. of Today's Patients : {$result}";
 }
 function generate_summary()
 {
     if (func_num_args() > 0) {
         $arg_list = func_get_args();
         $menu_id = $arg_list[0];
         $post_vars = $arg_list[1];
         $get_vars = $arg_list[2];
         $validuser = $arg_list[3];
         $isadmin = $arg_list[4];
         //print_r($arg_list);
     }
     list($month, $day, $year) = explode("/", $post_vars["report_date"]);
     $report_date = $year . "-" . str_pad($month, 2, "0", STR_PAD_LEFT) . "-" . str_pad($day, 2, "0", STR_PAD_LEFT);
     // STEP 1. empty report tables for given date
     $sql_delete = "delete from m_consult_report_dailyservice where service_date = '{$report_date}'";
     $result_delete = mysql_query($sql_delete);
     $sql_delete = "delete from m_consult_ccdev_report_dailyservice where service_date = '{$report_date}'";
     $result_delete = mysql_query($sql_delete);
     $sql_delete = "delete from m_consult_mc_report_dailyservice where service_date = '{$report_date}'";
     $result_delete = mysql_query($sql_delete);
     // STEP 2. get all consults for specified report date
     // records are unique for patient_id and service_date
     $sql_patient = "select c.patient_id, c.consult_id, " . "concat(p.patient_lastname, ', ', p.patient_firstname) patient_name, " . "round((to_days(c.consult_date)-to_days(p.patient_dob))/365,2) patient_age, " . "p.patient_gender " . "from m_consult c, m_patient p " . "where c.patient_id = p.patient_id " . "and to_days(c.consult_date) = to_days('{$report_date}')";
     if ($result_patient = mysql_query($sql_patient)) {
         if (mysql_num_rows($result_patient)) {
             while ($patient = mysql_fetch_array($result_patient)) {
                 // get family and address
                 if ($family_id = family::get_family_id($patient["patient_id"])) {
                     $patient_address = family::get_family_address($family_id);
                     $barangay_name = family::barangay_name($family_id);
                 } else {
                     $family_id = 0;
                     $patient_address = reminder::get_home_address($patient_id);
                     $barangay_name = reminder::get_barangay($patient_id);
                 }
                 // get chief complaint and diagnosis from notes
                 $complaints = notes::get_complaints($patient["patient_id"], $report_date);
                 $diagnosis = notes::get_diagnosis_list($patient["patient_id"], $report_date);
                 $treatment = notes::get_plan($patient["patient_id"], $report_date);
                 //get vaccines
                 $vaccines = $this->get_vaccines($patient["patient_id"], $report_date);
                 $services = $this->get_services($patient["consult_id"], $patient["patient_id"], $report_date);
                 $ptgroup = $this->get_ptgroup($patient["consult_id"], $report_date);
                 $aog = $this->get_aog($patient["patient_id"], $report_date);
                 $visit_seq = healthcenter::get_total_visits($patient["patient_id"]);
                 if ($mc_id = mc::registry_record_exists($patient["patient_id"])) {
                     $pp_weeks = mc::get_pp_weeks($mc_id, $patient["consult_id"]);
                     //$visit_sequence = mc::get_ppvisit_sequence($mc_id, $patient["consult_id"]);
                 }
                 if ($complaints != '' || $diagnosis != '' || $treatment != '') {
                     $sql_insert = "insert into m_consult_report_dailyservice (patient_id, patient_name, " . "patient_gender, patient_age, patient_address, patient_bgy, family_id, " . "notes_cc, notes_dx, notes_tx, service_date) values " . "('" . $patient["patient_id"] . "', '" . $patient["patient_name"] . "', " . "'" . $patient["patient_gender"] . "', '" . $patient["patient_age"] . "', " . "'{$patient_address}', '{$barangay_name}', '{$family_id}', " . "'{$complaints}', '{$diagnosis}', '{$treatment}', '{$report_date}')";
                     $result_insert = mysql_query($sql_insert);
                 }
                 if ($vaccines != '' || $services != '') {
                     if ($ptgroup == 'CHILD') {
                         $sql_insert = "insert into m_consult_ccdev_report_dailyservice (patient_id, " . "patient_name, patient_gender, patient_age, patient_address, patient_bgy, " . "family_id, service_given, vaccine_given, service_date) values " . "('" . $patient["patient_id"] . "', '" . $patient["patient_name"] . "', " . "'" . $patient["patient_gender"] . "', '" . $patient["patient_age"] . "', " . "'{$patient_address}', '{$barangay_name}', '{$family_id}', " . "'{$services}', '{$vaccines}', '{$report_date}')";
                         $result_insert = mysql_query($sql_insert);
                     }
                     if ($ptgroup == 'MATERNAL') {
                         $sql_insert = "insert into m_consult_mc_report_dailyservice (patient_id, " . "patient_name, patient_gender, patient_age, aog_weeks, postpartum_weeks, patient_address, " . "patient_bgy, family_id, visit_sequence, service_given, vaccine_given, " . "service_date) values " . "('" . $patient["patient_id"] . "', '" . $patient["patient_name"] . "', " . "'" . $patient["patient_gender"] . "', '" . $patient["patient_age"] . "', " . "'{$aog}', '{$pp_weeks}', '{$patient_address}', '{$barangay_name}', '{$family_id}', '{$visit_seq}', " . "'{$services}', '{$vaccines}', '{$report_date}')";
                         $result_insert = mysql_query($sql_insert);
                     }
                 }
             }
         }
     }
     //STEP 3. display daily service report
     print "<br/>";
     print "<b>DAILY SERVICE REPORT</b><br/>";
     print "REPORT DATE : <b>" . $post_vars["report_date"] . "</b><br/><br/>";
     $this->display_consults($report_date);
     $this->display_ccdev($report_date);
     $this->display_mc($report_date);
     $sql = "select count(distinct(patient_id)) from m_consult where " . "to_days(consult_date) = to_days('{$report_date}') and patient_id != '0'";
     $result = mysql_result(mysql_query($sql), 0);
     print "<br/>";
     print "Total No. of Today's Patients : {$result}";
 }