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);
 }
Example #2
0
 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;
         }
     }
 }
 function positivityGraph($year, $province, $epiweek)
 {
     $provinces = Province::getAll();
     //$positivityData = Lab_Weekly::getPositivity($year, $epiweek, $province);
     $strXML = "<chart showBorder='0' caption='Positivity Rates' shownames='1' showvalues='0' xAxisName='Positivity' yAxisName='Province'>\n\t <categories>";
     foreach ($provinces as $province) {
         $mkoa = $province->Name;
         $strXML .= "<category label='{$mkoa}'/>";
     }
     $strXML .= "</categories>";
     $strXML .= "<dataset seriesName='Cases Above 5' color='F1683C' showValues='0'>";
     foreach ($provinces as $province) {
         /*			foreach ($positivityData as $positiveCases) {
         
         			 }*/
         $x = Lab_Weekly::getPositivity($year, $province->id, $epiweek);
         $above = $x->Above;
         $strXML .= "<set value='{$above}'/>";
     }
     $strXML .= "</dataset>";
     $strXML .= "<dataset seriesName='Cases Below 5' color='2AD62A' showValues='0'>";
     foreach ($provinces as $province) {
         $y = Lab_Weekly::getPositivity($year, $province->id, $epiweek);
         $below = $y->Below;
         $strXML .= "<set value='{$below}'/>";
     }
     $strXML .= "</dataset>";
     $strXML .= "</chart>";
     echo $strXML;
 }
 public function save()
 {
     $i = 0;
     $valid = $this->_validate_submission();
     if ($valid == false) {
         $this->add();
     } else {
         $editing = false;
         $diseases = Disease::getAllObjects();
         $weekending = $this->input->post("week_ending");
         $reporting_year = $this->input->post("reporting_year");
         $epiweek = $this->input->post("epiweek");
         $facility = $this->input->post("facility");
         $reportingfacilities = $this->input->post("reporting_facilities");
         $expectedfacilities = $this->input->post("expected_facilities");
         $lmcase = $this->input->post("lmcase");
         $lfcase = $this->input->post("lfcase");
         $lmdeath = $this->input->post("lmdeath");
         $lfdeath = $this->input->post("lfdeath");
         $gmcase = $this->input->post("gmcase");
         $gfcase = $this->input->post("gfcase");
         $gmdeath = $this->input->post("gmdeath");
         $gfdeath = $this->input->post("gfdeath");
         $sickness = $this->input->post("disease");
         $reported_by = $this->input->post("reported_by");
         $designation = $this->input->post("designation");
         $lab_id = $this->input->post("lab_id");
         $surveillance_ids = $this->input->post("surveillance_ids");
         $data_exists = Surveillance::getFacilityData($epiweek, $reporting_year, $facility);
         if ($lab_id > 0) {
             $editing = true;
         }
         if ($data_exists->id && $editing == false) {
             $data = array();
             $data['duplicate_facility'] = Facilities::getFacility($facility);
             $data['duplicate_epiweek'] = $epiweek;
             $data['duplicate_reporting_year'] = $reporting_year;
             $data['existing_data'] = true;
             $this->add($data);
             return;
         }
         $total_diseases = Disease::getTotal();
         $timestamp = date('d/m/Y');
         $i = 0;
         foreach ($diseases as $disease) {
             if ($editing == true) {
                 $surveillance = Surveillance::getSurveillance($surveillance_ids[$i]);
             } else {
                 $surveillance = new Surveillance();
             }
             $surveillance->Week_Ending = $weekending;
             $surveillance->Epiweek = $epiweek;
             $surveillance->Facility = $facility;
             $surveillance->Submitted = $reportingfacilities;
             $surveillance->Expected = $expectedfacilities;
             $surveillance->Lmcase = $lmcase[$i];
             $surveillance->Lfcase = $lfcase[$i];
             $surveillance->Lmdeath = $lmdeath[$i];
             $surveillance->Lfdeath = $lfdeath[$i];
             if (isset($gmcase[$i])) {
                 $surveillance->Gmcase = $gmcase[$i];
                 $surveillance->Gfcase = $gfcase[$i];
                 $surveillance->Gmdeath = $gmdeath[$i];
                 $surveillance->Gfdeath = $gfdeath[$i];
             }
             $surveillance->Disease = $disease;
             $surveillance->Reporting_Year = $reporting_year;
             $surveillance->Created_By = $this->session->userdata('user_id');
             $surveillance->Date_Created = date("Y-m-d");
             $surveillance->Reported_By = $reported_by;
             $surveillance->Designation = $designation;
             $surveillance->Total_Diseases = $total_diseases;
             $surveillance->Date_Reported = $timestamp;
             $surveillance->save();
             $i++;
         }
         //end foreach
         //Lab Data
         if ($editing == true) {
             $labdata = Lab_Weekly::getLabObject($lab_id);
         } else {
             $labdata = new Lab_Weekly();
         }
         $totaltestedlessfive = $this->input->post("total_tested_less_than_five");
         $totaltestedgreaterfive = $this->input->post("total_tested_greater_than_five");
         $totalpositivelessfive = $this->input->post("total_positive_less_than_five");
         $totalpositivegreaterfive = $this->input->post("total_positive_greater_than_five");
         $remarks = $this->input->post("remarks");
         $labdata->Epiweek = $epiweek;
         $labdata->Week_Ending = $weekending;
         $labdata->Facility = $facility;
         $labdata->Malaria_Below_5 = $totaltestedlessfive;
         $labdata->Malaria_Above_5 = $totaltestedgreaterfive;
         $labdata->Positive_Below_5 = $totalpositivelessfive;
         $labdata->Positive_Above_5 = $totalpositivegreaterfive;
         $labdata->Remarks = $remarks;
         $labdata->Reporting_Year = $reporting_year;
         $labdata->Date_Created = date("Y-m-d");
         $labdata->save();
         if ($editing) {
             $data['success_message'] = "You have successfully edited data for " . $labdata->Facility->Name;
             $this->add($data);
         }
         if (!$editing) {
             $data['success_message'] = "You have successfully added weekly data for " . $labdata->Facility->Name;
             $this->add($data);
         }
         //redirect("weekly_facility/add");
     }
 }
 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);
 }