public function delete_duplicate($number_of_diseases, $first_surveillance_id, $malaria_data_id, $district, $epiweek, $year)
 {
     $last_surveillance_id = $first_surveillance_id + $number_of_diseases - 1;
     $surveillance_records = Surveillance::getSurveillanceDataRange($first_surveillance_id, $last_surveillance_id);
     foreach ($surveillance_records as $surveillance_record) {
         $surveillance_record->delete();
     }
     $lab_data = Lab_Weekly::getLabObjects($malaria_data_id);
     $lab_data->delete();
     $redirection_url = base_url() . "data_duplication/view_details/" . $epiweek . "/" . $year . "/" . $district;
     redirect($redirection_url);
 }
 public function get_list()
 {
     $year = $this->input->post('year');
     $epiweek = $this->input->post('epiweek');
     $data['reports'] = Surveillance::getReports($year, $epiweek);
     $data['quality_view'] = "district_reports_listing_v";
     $data['total_diseases'] = Disease::getTotal();
     $data['epiweek'] = $epiweek;
     $data['year'] = $year;
     $data['small_title'] = "List of all District Reports in " . $year . " Epiweek " . $epiweek;
     $this->base_params($data);
 }
 public function export()
 {
     $surveillance_data_requested = $this->input->post('surveillance');
     $malaria_data_requested = $this->input->post('malaria');
     $year = $this->input->post('year_from');
     $start_week = $this->input->post('epiweek_from');
     $end_week = $this->input->post('epiweek_to');
     if (strlen($surveillance_data_requested) > 0) {
         $surveillance_data = Surveillance::getRawDataArray($year, $start_week, $end_week);
         $excell_headers = "Disease\t District Name\t Province Name\t Week Number\t Week Ending\t Male Cases (Less Than 5)\t Female Cases (Less Than 5)\t Male Cases (Greater Than 5)\t Female Cases (Greater Than 5)\t Total Cases\t Male Deaths (Less Than 5)\t Female Deaths (Less Than 5)\t Male Deaths (Greater Than 5)\t Female Deaths (Greater Than 5)\t Total Deaths\tYear\t Reported By\t Designation\t Date Reported\t\n";
         $excell_data = "";
         foreach ($surveillance_data as $result_set) {
             //$excell_data .= $result_set -> Disease_Object -> Name . "\t" . $result_set -> District_Object -> Name . "\t" . $result_set -> District_Object -> Province_Object -> Name . "\t" . $result_set -> Epiweek . "\t" . $result_set -> Week_Ending . "\t" . $result_set -> Lmcase . "\t" . $result_set -> Lfcase . "\t" . $result_set -> Gmcase . "\t" . $result_set -> Gfcase . "\t" . ($result_set -> Lmcase + $result_set -> Lfcase + $result_set -> Gmcase + $result_set -> Gfcase) . "\t" . $result_set -> Lmdeath . "\t" . $result_set -> Lfdeath . "\t" . $result_set -> Gmdeath . "\t" . $result_set -> Gfdeath . "\t" . ($result_set -> Lmdeath + $result_set -> Lfdeath + $result_set -> Gmdeath + $result_set -> Gfdeath) . "\t" . $result_set -> Reporting_Year . "\t" . $result_set -> Reported_By . "\t" . $result_set -> Designation . "\t" . $result_set -> Date_Reported . "\t";
             $excell_data .= $result_set['Disease_Name'] . "\t" . $result_set['District_Name'] . "\t" . $result_set['Province_Name'] . "\t" . $result_set['Epiweek'] . "\t" . $result_set['Week_Ending'] . "\t" . $result_set['Lmcase'] . "\t" . $result_set['Lfcase'] . "\t" . $result_set['Gmcase'] . "\t" . $result_set['Gfcase'] . "\t" . ($result_set['Lmcase'] + $result_set['Lfcase'] + $result_set['Gmcase'] + $result_set['Gfcase']) . "\t" . $result_set['Lmdeath'] . "\t" . $result_set['Lfdeath'] . "\t" . $result_set['Gmdeath'] . "\t" . $result_set['Gfdeath'] . "\t" . ($result_set['Lmdeath'] + $result_set['Lfdeath'] + $result_set['Gmdeath'] + $result_set['Gfdeath']) . "\t" . $result_set['Reporting_Year'] . "\t" . $result_set['Reported_By'] . "\t" . $result_set['Designation'] . "\t" . $result_set['Date_Reported'] . "\t";
             $excell_data .= "\n";
         }
         header("Content-type: application/vnd.ms-excel; name='excel'");
         header("Content-Disposition: filename=Surveillance_Data (" . $year . " epiweek " . $start_week . " to epiweek " . $end_week . ").xls");
         // Fix for crappy IE bug in download.
         header("Pragma: ");
         header("Cache-Control: ");
         echo $excell_headers . $excell_data;
     } else {
         if (strlen($malaria_data_requested) > 0) {
             $malaria_data = Lab_Weekly::getRawData($year, $start_week, $end_week);
             $excell_headers = "District\t Province\t Week Number\t Week Ending\t Tested (Less Than 5)\t Tested (Greater Than 5)\t Total Tested\t Positive (Less Than 5)\t Positive (Greater Than 5)\t Total Positive\t\n";
             $excell_data = "";
             foreach ($malaria_data as $result_set) {
                 $excell_data .= $result_set->District_Object->Name . "\t" . $result_set->District_Object->Province_Object->Name . "\t" . $result_set->Epiweek . "\t" . $result_set->Week_Ending . "\t" . $result_set->Malaria_Below_5 . "\t" . $result_set->Malaria_Above_5 . "\t" . ($result_set->Malaria_Below_5 + $result_set->Malaria_Above_5) . "\t" . $result_set->Positive_Below_5 . "\t" . $result_set->Positive_Above_5 . "\t" . ($result_set->Positive_Below_5 + $result_set->Positive_Above_5) . "\t";
                 $excell_data .= "\n";
             }
             header("Content-type: application/vnd.ms-excel; name='excel'");
             header("Content-Disposition: filename=Malaria_Test_Data (" . $_POST['year_from'] . " epiweek " . $_POST['epiweek_from'] . " to epiweek " . $_POST['epiweek_to'] . ").xls");
             // Fix for crappy IE bug in download.
             header("Pragma: ");
             header("Cache-Control: ");
             echo $excell_headers . $excell_data;
         }
     }
 }
 public function getPerDistrict($districtId, $epiweek, $provinceId, $filterdyear)
 {
     $diseases = Disease::getAllObjects();
     $value = "";
     foreach ($diseases as $disease) {
         $sums = Surveillance::getDistrictSums($districtId, $epiweek, $filterdyear, $disease->id);
         $value[$disease->id][0] = $sums->lmcase;
         $value[$disease->id][1] = $sums->lfcase;
         $value[$disease->id][2] = $sums->lmdeath;
         $value[$disease->id][3] = $sums->lfdeath;
         $value[$disease->id][4] = $sums->gmcase;
         $value[$disease->id][5] = $sums->gfcase;
         $value[$disease->id][6] = $sums->gmdeath;
         $value[$disease->id][7] = $sums->gfdeath;
         $cumulative = Surveillance::getDistrictCumulative($districtId, $epiweek, $provinceId, $disease->id, $filterdyear);
         $value[$disease->id][8] = $cumulative->lmcase;
         $value[$disease->id][9] = $cumulative->lfcase;
         $value[$disease->id][10] = $cumulative->lmdeath;
         $value[$disease->id][11] = $cumulative->lfdeath;
         $value[$disease->id][12] = $cumulative->gmcase;
         $value[$disease->id][13] = $cumulative->gfcase;
         $value[$disease->id][14] = $cumulative->gmdeath;
         $value[$disease->id][15] = $cumulative->gfdeath;
     }
     return $value;
 }
 function dave()
 {
     $year = $_POST['year'];
     $disease = $_POST['disease'];
     $province = $_POST['province'];
     $epiweek = $_POST['epiweek'];
     $values = array($year, $disease, $province, $epiweek);
     $currentyear = date('Y');
     $rights = User_Right::getRights($this->session->userdata('access_level'));
     $menu_data = array();
     $menus = array();
     $counter = 0;
     foreach ($rights as $right) {
         $menu_data['menus'][$right->Menu] = $right->Access_Type;
         $menus['menu_items'][$counter]['url'] = $right->Menu_Item->Menu_Url;
         $menus['menu_items'][$counter]['text'] = $right->Menu_Item->Menu_Text;
         $counter++;
     }
     $this->session->set_userdata($menu_data);
     $this->session->set_userdata($menus);
     $provinces = Province::getAll();
     $epiweeks = Surveillance::getEpiweek();
     $years = Surveillance::getYears();
     $diseases = Diseases::getAllObjects();
     $this->load->database();
     $sql = 'select Districts.name as District, Lmcase,Gmcase,Lfcase,Gfcase from Surveillance,Districts,Diseases where Epiweek = ? and Disease = ? and Reporting_Year = ? and abs(Lmcase) != 0 and abs(Gmcase) != 0 and abs(Lfcase) != 0 and ABS(Gfcase) != 0  and surveillance.disease=diseases.id and surveillance.district=districts.id';
     $query = $this->db->query($sql, array($epiweek, $disease, $year));
     $data['epidemiks'] = $query->result_array();
     $data['epiweeks'] = $epiweeks;
     $data['provinces'] = $provinces;
     $data['years'] = $years;
     $data['diseases'] = $diseases;
     $data['values'] = $values;
     $data['scripts'] = array("FusionCharts/FusionCharts.js");
     $data['title'] = "System Home";
     $data['content_view'] = "home_v";
     $data['banner_text'] = "System Home";
     $data['link'] = "home";
     $this->load->view("template", $data);
 }
 function check_facility_data($epiweek, $year, $facility)
 {
     $data = Surveillance::getFacilityData($epiweek, $year, $facility);
     if ($data->id) {
         echo "yes";
     } else {
         echo "no";
     }
 }
 function check_district_data($epiweek, $year, $district)
 {
     $data = Surveillance::getDistrictData($epiweek, $year, $district);
     if ($data->id) {
         echo "yes";
     } else {
         echo "no";
     }
 }
 public function generate()
 {
     $bata_buffer = "";
     $year = $this->input->post('year_from');
     $epiweek = $this->input->post('epiweek_to');
     $province = $this->input->post('province');
     $district = $this->input->post('district');
     $display_type = $this->input->post('display_type');
     $weekending = Surveillance::getWeekEnding($year, $epiweek);
     $provinces = array();
     $districts = array();
     //Check if a province has been specified
     if ($province > 0) {
         //if so, retrieve it's details from the database
         $provinces = Province::getProvince($province);
     } else {
         //if not, retrieve all provinces
         $provinces = Province::getAll();
     }
     //Check if a district has been specified
     if ($district > 0) {
         //if so, retrieve it's details from the database
         $districts = District::getDistrict($district);
         //also, retrieve the province details for this district
         $provinces = Province::getProvince($districts[0]['Province']);
     } else {
         //if not, empty the array
         $districts = array();
     }
     //Start displaying the header of the table
     $bata_buffer .= " <table class='data-table'>\n            <tr style='background: #F5D2AE;'>\n                <th rowspan=2>Province</th>\n                <th rowspan=2>District</th>\n                <th rowspan=2>Reports Expected</th>\n                <th rowspan=2>Reports Received</th>\n                <th rowspan=2>%RR</th>";
     $diseases["reports"] = "reports";
     $diseases["submitted"] = "submitted";
     $diseases["percentage"] = "percentage";
     $disease_array = Disease::getAll();
     foreach ($disease_array as $disease) {
         if ($disease['Name'] == 'Malaria') {
             $diseases[$disease['id']] = $disease['Name'];
             $diseases["tested"] = "tested";
             $diseases["positive"] = "positive";
             $bata_buffer .= "<th rowspan=2>" . $disease['Name'] . "</th>";
             $bata_buffer .= "<th  colspan=2 style='color:green;'>" . $disease['Name'] . " Indicators</th>";
         } else {
             $diseases[$disease['id']] = $disease['Name'];
             $bata_buffer .= "<th rowspan=2>" . $disease['Name'] . "</th>";
         }
     }
     //Finish Displaying the Header
     $bata_buffer .= " </tr>\n            <tr style='background: #F5D2AE'>\n                 <th >Tested</th><th >Positive</th>\n            </tr>\n\t\t";
     //Start retrieving all the rows for the data
     foreach ($provinces as $province_object) {
         $bata_buffer .= "<tr class='even'><td style='font-weight:bold; font-size:14px'>" . $province_object->Name . "</td></tr>";
         $province_districts = array();
         //check if a district was specified
         if (count($districts) > 0) {
             $province_districts = $districts;
         } else {
             //Get all the districts for this province
             $province_districts = district::getProvinceDistrict($province_object->id);
         }
         //loop through all the districts to get their data
         foreach ($province_districts as $province_district) {
             $available_data = array();
             $surveillance_counter = 2;
             $bata_buffer .= "<tr class='even' style='background:#C4E8B7'><td></td><td>" . $province_district['Name'] . "</td>";
             $surveillance_data = Surveillance::getWeeklySummaries($year, $epiweek, $province_district['id']);
             //Check if any surveillance data exists
             if (isset($surveillance_data[0])) {
                 $available_data['reports'] = $surveillance_data[0]['Expected'];
                 $available_data['submitted'] = $surveillance_data[0]['Submitted'];
                 //Calculate the reporting
                 $available_data['percentage'] = floor($available_data['submitted'] / $available_data['reports'] * 100);
                 //Display these Parameters
                 $bata_buffer .= "<td>" . $available_data['reports'] . "</td><td>" . $available_data['submitted'] . "</td><td>" . $available_data['percentage'] . "</td>";
             } else {
                 $bata_buffer .= "<td>DNR</td><td>DNR</td><td>0</td>";
             }
             //Check if there is any surveillance data
             if (isset($surveillance_data[0])) {
                 //Loop through all the surveillance data returned
                 foreach ($surveillance_data as $disease_data) {
                     $bata_buffer .= "<td>" . $disease_data['Cases'] . "(" . $disease_data['Deaths'] . ")</td>";
                     //Check if the disease is malaria and if so, get the lab data and display it
                     if ($disease_data['Disease'] == 1) {
                         //Get malaria data
                         $lab_weekly_data = Lab_Weekly::getWeeklyLabData($year, $epiweek, $province_district['id']);
                         //Check if any data exists
                         if (isset($lab_weekly_data)) {
                             $bata_buffer .= "<td>" . $lab_weekly_data['Tested'] . "</td><td>" . $lab_weekly_data['Positive'] . "</td>";
                         } else {
                             $bata_buffer .= "<td>DNR</td><td>DNR</td>";
                         }
                     }
                 }
             } else {
                 $total_diseases = count($disease_array);
                 $total_elements = $total_diseases + 1;
                 for ($x = 0; $x <= $total_elements; $x++) {
                     $bata_buffer .= "<td>DNR</td>";
                 }
             }
             //Marks the end of data for one district
             $bata_buffer .= "</tr>";
         }
         //End districts loop
     }
     //End provinces loop
     //Finish the table
     $bata_buffer .= "</table>";
     //Start section that shows cumulative data
     $bata_buffer .= "<table class='data-table'>\n            <tr style='background: #F5D2AE;'>\n                <th rowspan='2' colspan='5'>Cumulative Summaries</th>";
     //Loop through all the diseases to display their names
     foreach ($disease_array as $disease) {
         if ($disease['Name'] == 'Malaria') {
             $diseases[$disease['id']] = $disease['Name'];
             $diseases["tested"] = "tested";
             $diseases["positive"] = "positive";
             $bata_buffer .= "<th rowspan=2>" . $disease['Name'] . "</th>";
             $bata_buffer .= "<th  colspan=2 style='color:green;'>" . $disease['Name'] . " Indicators</th>";
         } else {
             $diseases[$disease['id']] = $disease['Name'];
             $bata_buffer .= "<th rowspan=2>" . $disease['Name'] . "</th>";
         }
     }
     //end diseases loop
     $bata_buffer .= "</tr>\n            <tr style='background: #F5D2AE'>\n                <th >Tested</th><th >Positive</th>\n            </tr>";
     //Get the malaria lab data summaries
     $lab_weekly_summary = Lab_Weekly::getWeeklyLabSummaries($year, $epiweek);
     //Start Displaying this week summary
     $bata_buffer .= "<tr class='even'><td rowspan='2' colspan='5'>Week " . $epiweek . " Summary</td>";
     //Get the summary for the week. Disease cases vs. deaths
     $disease_deaths = array();
     foreach ($disease_array as $disease_object) {
         $disease_summaries = Surveillance::getWeeklyDiseaseSummaries($year, $epiweek, $disease_object['id']);
         $bata_buffer .= "<td>" . $disease_summaries['Cases'] . "</td>";
         $disease_deaths[$disease_object['id']] = $disease_summaries['Deaths'];
         //check if the disease is Malaria. If so, display lab data
         if ($disease_object['Name'] == "Malaria") {
             $bata_buffer .= "<td rowspan=2>" . $lab_weekly_summary['Tested'] . "</td>";
             $bata_buffer .= "<td rowspan=2>" . $lab_weekly_summary['Positive'] . "</td>";
         }
     }
     //Finish the cases row
     $bata_buffer .= "</tr>";
     //Start the deaths row
     $bata_buffer .= "<tr>";
     //Loop through one more time to display the total number of deaths
     foreach ($disease_array as $disease_object) {
         $bata_buffer .= "<td>(" . $disease_deaths[$disease_object['id']] . ")</td>";
     }
     //finish the deaths row
     $bata_buffer .= "</tr>";
     //Get the annual summary
     //Get the malaria lab data summaries
     $lab_weekly_summary = Lab_Weekly::getAnnualLabSummaries($year);
     //Start Displaying this week summary
     $bata_buffer .= "<tr class='even' style='background:#BB00FF'><td rowspan='2' colspan='5'>Years Cummulative Summary</td>";
     //Get the summary for the week. Disease cases vs. deaths
     $disease_deaths = array();
     foreach ($disease_array as $disease_object) {
         $disease_summaries = Surveillance::getAnnualDiseaseSummaries($year, $disease_object['id']);
         $bata_buffer .= "<td>" . $disease_summaries['Cases'] . "</td>";
         $disease_deaths[$disease_object['id']] = $disease_summaries['Deaths'];
         //check if the disease is Malaria. If so, display lab data
         if ($disease_object['Name'] == "Malaria") {
             $bata_buffer .= "<td rowspan=2>" . $lab_weekly_summary['Tested'] . "</td>";
             $bata_buffer .= "<td rowspan=2>" . $lab_weekly_summary['Positive'] . "</td>";
         }
     }
     //Finish the cases row
     $bata_buffer .= "</tr>";
     //Start the deaths row
     $bata_buffer .= "<tr class='even' style='background:#BB00FF'>";
     //Loop through one more time to display the total number of deaths
     foreach ($disease_array as $disease_object) {
         $bata_buffer .= "<td>(" . $disease_deaths[$disease_object['id']] . ")</td>";
     }
     //finish the deaths row
     $bata_buffer .= "</tr></table>";
     $this->generatePDF($year, $bata_buffer, $epiweek, $weekending, $display_type);
 }