Ejemplo n.º 1
0
 /**
  * a function to export data to excel
  */
 public function excelDownload1()
 {
     /** Include PHPExcel */
     require_once dirname(__FILE__) . '/Classes/PHPExcel.php';
     // Create new PHPExcel object
     $objPHPExcel = new PHPExcel();
     $title = "";
     $pat = false;
     $row = array();
     $column = array();
     $columntype = $this->generateArray(Input::get("show"));
     if (Input::get("vertical") == "Patients") {
         $pat = true;
     }
     if (Input::get("horizontal") == "Year") {
         $row = array("01" => "jan", "02" => "feb", "03" => "mar", "04" => "apr", "05" => "may", "06" => "jun", "07" => "jul", "08" => "aug", "09" => "sep", "10" => "oct", "11" => "nov", "12" => "dec");
         foreach ($row as $key => $value) {
             $from = Input::get('year') . "-" . $key . "-01";
             $to = Input::get('year') . "-" . $key . "-31";
             if (isset($columntype)) {
                 foreach ($columntype as $key1 => $value1) {
                     $patientquery = DB::table('patient');
                     $visitquery = DB::table('visit');
                     $query = $this->processQuery($patientquery, $visitquery);
                     $que = $this->checkCondition($query, $pat, $key1)->whereBetween('created_at', array($from, $to));
                     $column[$value1][] = $que->count();
                 }
                 $title .= " " . $query[2] . " " . Input::get('year');
             }
         }
     } elseif (Input::get("horizontal") == "Years") {
         $row = range(Input::get('start'), Input::get('end'));
         foreach ($row as $value) {
             $from = $value . "-01-01";
             $to = $value . "-12-31";
             if (isset($columntype)) {
                 foreach ($columntype as $key1 => $value1) {
                     $patientquery = DB::table('patient');
                     $visitquery = DB::table('visit');
                     $query = $this->processQuery($patientquery, $visitquery);
                     $que = $this->checkCondition($query, $pat, $key1)->whereBetween('created_at', array($from, $to));
                     $column[$value1][] = $que->count();
                 }
                 $title .= " " . $query[2] . " " . Input::get('start') . " - " . Input::get('end');
             }
         }
     } elseif (Input::get("horizontal") == "Age Range") {
         //setting the limits
         $agetouse = Input::get('age') == 0 ? 3 : Input::get('age');
         if (parent::maxAge() % $agetouse == 0) {
             $limit = parent::maxAge();
         } else {
             $limit = parent::maxAge() - parent::maxAge() % $agetouse + $agetouse;
         }
         //making a loop for values
         //year iterator
         $k = 0;
         //getting age
         $range = Input::get('age');
         $yeardate = date("Y") + 1;
         $yaerdate1 = $yeardate . "-01-01";
         //creating title
         $data = array();
         for ($i = $range; $i <= $limit; $i += $range) {
             $row[] = $k . " - " . $i;
             //start year
             $time = $k * 365 * 24 * 3600;
             $today = date("Y-m-d");
             $timerange = strtotime($today) - $time;
             $start = date("Y", $timerange) + 1 . "-01-01";
             //end year
             $time1 = $i * 365 * 24 * 3600;
             $timerange1 = strtotime($today) - $time1;
             $end = date("Y", $timerange1) . "-01-01";
             if (isset($columntype)) {
                 foreach ($columntype as $key1 => $value1) {
                     $patientquery = DB::table('patient');
                     $visitquery = DB::table('visit');
                     $query = $this->processQuery($patientquery, $visitquery);
                     $que = $this->checkCondition($query, true, $key1)->whereBetween('birth_date', array($end, $start));
                     $column[$value1][] = $que->count();
                 }
                 $title .= " Age Range " . $query[2];
             }
             $k = $i;
         }
     }
     // Set document properties
     $objPHPExcel->getProperties()->setCreator("Cervical Cancer Prevention Program")->setLastModifiedBy(Auth::user()->first_name)->setTitle($title)->setSubject($title)->setDescription("Cervical Cancer Prevention Program Reports")->setKeywords("cancer cecap openxml php")->setCategory("Result file");
     $latterArr = array("A", "B", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "AB", "AC", "AD", "AE", "AF", "AG", "AH", "AI", "AJ", "AK", "AL", "AM", "AN", "AO", "AP", "AQ", "AR", "AS", "AT", "AU", "AV", "AW", "AX", "AY", "AZ", "BA", "BB", "BC", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BK", "BM", "BL", "BO", "BP", "BQ", "BR", "BS", "BT", "BU", "BV", "BW", "BX", "BY", "BZ");
     $ttlecont = 1;
     $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', Input::get("show"));
     foreach ($row as $header) {
         $objPHPExcel->setActiveSheetIndex(0)->setCellValue("{$latterArr[$ttlecont]}1", $header);
         $ttlecont++;
     }
     $k = 2;
     $colcount = 1;
     foreach ($column as $keys => $cols) {
         $objPHPExcel->setActiveSheetIndex(0)->setCellValue("A{$k}", $keys);
         foreach ($cols as $colsval) {
             $objPHPExcel->setActiveSheetIndex(0)->setCellValue("{$latterArr[$colcount]}{$k}", $colsval);
             $colcount++;
         }
         $colcount = 1;
         $k++;
     }
     // Rename worksheet
     $objPHPExcel->getActiveSheet()->setTitle($title);
     // Set active sheet index to the first sheet, so Excel opens this as the first sheet
     $objPHPExcel->setActiveSheetIndex(0);
     // Redirect output to a client’s web browser (Excel2007)
     header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
     header('Content-Disposition: attachment;filename="' . $title . '.xlsx"');
     header('Cache-Control: max-age=0');
     // If you're serving to IE 9, then the following may be needed
     header('Cache-Control: max-age=1');
     // If you're serving to IE over SSL, then the following may be needed
     header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     // Date in the past
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
     // always modified
     header('Cache-Control: cache, must-revalidate');
     // HTTP/1.1
     header('Pragma: public');
     // HTTP/1.0
     $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
     $objWriter->save('php://output');
     exit;
 }
Ejemplo n.º 2
0
    public function makeLine()
    {
        $title = "";
        $pat = false;
        $row = "categories: [";
        $column = "";
        if (Input::get("show") == "Findings") {
            $columntype = PapsmearResult::all()->lists('name', 'id');
        } elseif (Input::get("show") == "Pap Smear Status") {
            $columnhistory = array('yes' => 'Pap Smear Done', 'no' => 'Pap Smear Not Done');
        }
        if (Input::get("vertical") == "Patients") {
            $pat = true;
        } elseif (Input::get("vertical") == "Visits") {
            $vis = true;
        }
        if (Input::get("horizontal") == "Year") {
            $row1 = array("01" => "jan", "02" => "feb", "03" => "mar", "04" => "apr", "05" => "may", "06" => "jun", "07" => "jul", "08" => "aug", "09" => "sep", "10" => "oct", "11" => "nov", "12" => "dec");
            $j = 1;
            foreach ($row1 as $value) {
                $row .= $j < count($row1) ? "'" . $value . "'," : "'" . $value . "'";
                $j++;
            }
            $col = 1;
            if (isset($columntype)) {
                foreach ($columntype as $key1 => $value1) {
                    $column .= "{ name: '" . $value1 . "', data: [ ";
                    $i = 1;
                    foreach ($row1 as $key => $value) {
                        $from = Input::get('year') . "-" . $key . "-01";
                        $to = Input::get('year') . "-" . $key . "-31";
                        $patientquery = DB::table('patient');
                        $visitquery = DB::table('visit');
                        $query = $this->processQuery($patientquery, $visitquery);
                        if ($pat) {
                            $que = $query[0]->whereIn('id', PapsmearStatus::where('result_id', $key1)->get()->lists('patient_id') + array('0'))->whereBetween('created_at', array($from, $to));
                            $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        } elseif ($vis) {
                            $que = $query[1]->whereIn('id', PapsmearStatus::where('result_id', $key1)->get()->lists('visit_id') + array('0'))->whereBetween('created_at', array($from, $to));
                            $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        }
                        $i++;
                    }
                    $column .= $col < count($columntype) ? "]}," : "]}";
                    $col++;
                }
            } elseif (isset($columnhistory)) {
                foreach ($columnhistory as $key1 => $value1) {
                    $column .= "{ name: '" . $value1 . "', data: [ ";
                    $i = 1;
                    foreach ($row1 as $key => $value) {
                        $from = Input::get('year') . "-" . $key . "-01";
                        $to = Input::get('year') . "-" . $key . "-31";
                        $patientquery = DB::table('patient');
                        $visitquery = DB::table('visit');
                        $query = $this->processQuery($patientquery, $visitquery);
                        if ($pat) {
                            $que = $query[0]->whereIn('id', PapsmearStatus::where('status', $key1)->get()->lists('patient_id') + array('0'))->whereBetween('created_at', array($from, $to));
                            $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        } elseif ($vis) {
                            $que = $query[1]->whereIn('id', PapsmearStatus::where('status', $key1)->get()->lists('visit_id') + array('0'))->whereBetween('created_at', array($from, $to));
                            $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        }
                        $i++;
                    }
                    $column .= $col < count($columnhistory) ? "]}," : "]}";
                    $col++;
                }
            }
            $title = Input::get('vertical') . " " . $query[2] . " " . Input::get('Year');
        } elseif (Input::get("horizontal") == "Years") {
            $row1 = range(Input::get('start'), Input::get('end'));
            $j = 1;
            foreach ($row1 as $value) {
                $row .= $j < count($row1) ? "'" . $value . "'," : "'" . $value . "'";
                $j++;
            }
            $col = 1;
            if (isset($columntype)) {
                foreach ($columntype as $key1 => $value1) {
                    $column .= "{ name: '" . $value1 . "', data: [ ";
                    $i = 1;
                    foreach ($row1 as $key => $value) {
                        $from = $value . "-01-01";
                        $to = $value . "-12-31";
                        $patientquery = DB::table('patient');
                        $visitquery = DB::table('visit');
                        $query = $this->processQuery($patientquery, $visitquery);
                        if ($pat) {
                            $que = $query[0]->whereIn('id', PapsmearStatus::where('result_id', $key1)->get()->lists('patient_id') + array('0'))->whereBetween('created_at', array($from, $to));
                            $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        } elseif ($vis) {
                            $que = $query[1]->whereIn('id', PapsmearStatus::where('result_id', $key1)->get()->lists('visit_id') + array('0'))->whereBetween('created_at', array($from, $to));
                            $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        }
                        $i++;
                    }
                    $column .= $col < count($columntype) ? "]}," : "]}";
                    $col++;
                }
            } elseif (isset($columnhistory)) {
                foreach ($columnhistory as $key1 => $value1) {
                    $column .= "{ name: '" . $value1 . "', data: [ ";
                    $i = 1;
                    foreach ($row1 as $value) {
                        $from = $value . "-01-01";
                        $to = $value . "-12-31";
                        $patientquery = DB::table('patient');
                        $visitquery = DB::table('visit');
                        $query = $this->processQuery($patientquery, $visitquery);
                        if ($pat) {
                            $que = $query[0]->whereIn('id', PapsmearStatus::where('status', $key1)->get()->lists('patient_id') + array('0'))->whereBetween('created_at', array($from, $to));
                            $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        } elseif ($vis) {
                            $que = $query[1]->whereIn('id', PapsmearStatus::where('status', $key1)->get()->lists('visit_id') + array('0'))->whereBetween('created_at', array($from, $to));
                            $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        }
                        $i++;
                    }
                    $column .= $col < count($columnhistory) ? "]}," : "]}";
                    $col++;
                }
            }
            $title = Input::get('vertical') . " " . $query[2] . " " . Input::get('Year');
        } elseif (Input::get("horizontal") == "Age Range") {
            //setting the limits
            if (parent::maxAge() % Input::get('age') == 0) {
                $limit = parent::maxAge();
            } else {
                $limit = parent::maxAge() - parent::maxAge() % Input::get('age') + Input::get('age');
            }
            //making a loop for values
            //year iterator
            $k = 0;
            //getting age
            $range = Input::get('age');
            $yeardate = date("Y") + 1;
            $yaerdate1 = $yeardate . "-01-01";
            //creating title
            $j = 1;
            for ($i = $range; $i <= $limit; $i += $range) {
                $row .= $i < $limit ? "'" . $k . " - " . $i . "'," : "'" . $k . " - " . $i . "'";
                $k = $i;
            }
            $col = 1;
            if (isset($columntype)) {
                foreach ($columntype as $key1 => $value1) {
                    $column .= "{ name: '" . $value1 . "', data: [ ";
                    $i = 1;
                    for ($i = $range; $i <= $limit; $i += $range) {
                        //start year
                        $time = $k * 365 * 24 * 3600;
                        $today = date("Y-m-d");
                        $timerange = strtotime($today) - $time;
                        $start = date("Y", $timerange) + 1 . "-01-01";
                        //end year
                        $time1 = $i * 365 * 24 * 3600;
                        $timerange1 = strtotime($today) - $time1;
                        $end = date("Y", $timerange1) . "-01-01";
                        $patientquery = DB::table('patient');
                        $visitquery = DB::table('visit');
                        $query = $this->processQuery($patientquery, $visitquery);
                        $que = $query[0]->whereIn('id', PapsmearStatus::where('result_id', $key1)->get()->lists('patient_id') + array('0'))->whereBetween('birth_date', array($end, $start));
                        $column .= $i < $limit ? $que->count() . "," : $que->count();
                        $k = $i;
                    }
                    $column .= $col < count($columntype) ? "]}," : "]}";
                    $col++;
                }
            } elseif (isset($columnhistory)) {
                foreach ($columnhistory as $key1 => $value1) {
                    $column .= "{ name: '" . $value1 . "', data: [ ";
                    for ($i = $range; $i <= $limit; $i += $range) {
                        //start year
                        $time = $k * 365 * 24 * 3600;
                        $today = date("Y-m-d");
                        $timerange = strtotime($today) - $time;
                        $start = date("Y", $timerange) + 1 . "-01-01";
                        //end year
                        $time1 = $i * 365 * 24 * 3600;
                        $timerange1 = strtotime($today) - $time1;
                        $end = date("Y", $timerange1) . "-01-01";
                        $patientquery = DB::table('patient');
                        $visitquery = DB::table('visit');
                        $query = $this->processQuery($patientquery, $visitquery);
                        $que = $query[0]->whereIn('id', PapsmearStatus::where('status', $key1)->get()->lists('patient_id') + array('0'))->whereBetween('birth_date', array($end, $start));
                        $column .= $i < $limit ? $que->count() . "," : $que->count();
                        $k = $i;
                    }
                    $column .= $col < count($columnhistory) ? "]}," : "]}";
                    $col++;
                }
            }
            $title = Input::get('vertical') . " Age Range " . $query[2] . " ";
        }
        $row .= "]";
        ?>
        <script type="text/javascript">
            $(function () {
                $('#chartarea').highcharts({
                    title: {
                        text: '<?php 
        echo $title;
        ?>
'
                    },
                    xAxis: {
                        <?php 
        echo $row;
        ?>
                    },
                    yAxis: {
                        title: {
                            text: '<?php 
        echo Input::get('vertical');
        ?>
'
                        },
                        plotLines: [{
                            value: 0,
                            width: 1,
                            color: '#808080'
                        }]
                    },
                    tooltip: {
                        valueSuffix: '<?php 
        Input::get('vertical');
        ?>
'
                    },
                    legend: {
                        layout: 'vertical',
                        align: 'right',
                        verticalAlign: 'middle',
                        borderWidth: 0
                    },
                    series: [<?php 
        echo $column;
        ?>
]
                });
            });
        </script>
    <?php 
    }
Ejemplo n.º 3
0
    public function makeLine()
    {
        $title = "";
        $pat = false;
        $row = "categories: [";
        $column = "";
        if (Input::get("show") == "HIV Status") {
            $columntype = array('Unknown' => 'Unknown', 'Negative' => 'Negative', 'Positive' => 'Positive');
        } elseif (Input::get("show") == "CD4 Count") {
            $columcd4 = array('0' => '0-200', '200' => '200-400', '400' => '400-600', '600' => '600-1000', '1000' => '1000-1500');
        }
        if (Input::get("vertical") == "Patients") {
            $pat = true;
        } elseif (Input::get("show") == "Test  Results") {
            $columresult = array('yes' => 'Tests', 'Positive' => 'Positive', 'Negative' => 'Negative');
        } elseif (Input::get("show") == "Decline Reason") {
            $columreason = array('Counselling not offered' => 'Counselling not offered', 'Patient declined test' => 'Patient declined test', 'Test kits shortage' => 'Test kits shortage', 'Other' => 'Other');
        } elseif (Input::get("vertical") == "Visits") {
            $vis = true;
        }
        if (Input::get("horizontal") == "Year") {
            $row1 = array("01" => "jan", "02" => "feb", "03" => "mar", "04" => "apr", "05" => "may", "06" => "jun", "07" => "jul", "08" => "aug", "09" => "sep", "10" => "oct", "11" => "nov", "12" => "dec");
            $j = 1;
            foreach ($row1 as $value) {
                $row .= $j < count($row1) ? "'" . $value . "'," : "'" . $value . "'";
                $j++;
            }
            $col = 1;
            if (isset($columntype)) {
                foreach ($columntype as $key1 => $value1) {
                    $column .= "{ name: '" . $value1 . "', data: [ ";
                    $i = 1;
                    foreach ($row1 as $key => $value) {
                        $from = Input::get('year') . "-" . $key . "-01";
                        $to = Input::get('year') . "-" . $key . "-31";
                        $patientquery = DB::table('patient');
                        $visitquery = DB::table('visit');
                        $query = $this->processQuery($patientquery, $visitquery);
                        if ($pat) {
                            $que = $query[0]->whereIn('id', PatientReport::where('HIV_status', $key1)->get()->lists('patient_id') + array('0'))->whereBetween('created_at', array($from, $to));
                            $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        } elseif ($vis) {
                            $que = $query[1]->whereIn('id', HivStatus::where('status', $key1)->get()->lists('visit_id') + array('0'))->whereBetween('created_at', array($from, $to));
                            $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        }
                        $i++;
                    }
                    $column .= $col < count($columntype) ? "]}," : "]}";
                    $col++;
                }
            } elseif (isset($columcd4)) {
                foreach ($columcd4 as $key1 => $value1) {
                    $arr = explode("-", $value1);
                    $column .= "{ name: '" . $value1 . "', data: [ ";
                    $i = 1;
                    foreach ($row1 as $key => $value) {
                        $from = Input::get('year') . "-" . $key . "-01";
                        $to = Input::get('year') . "-" . $key . "-31";
                        $patientquery = DB::table('patient');
                        $visitquery = DB::table('visit');
                        $query = $this->processQuery($patientquery, $visitquery);
                        if ($pat) {
                            $que = $query[0]->whereIn('id', PatientReport::whereBetween('cd4_count', array($arr[0], $arr[1]))->get()->lists('patient_id') + array('0'))->whereBetween('created_at', array($from, $to));
                            $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        } elseif ($vis) {
                            $que = $query[1]->whereIn('id', HivStatus::whereBetween('pitc_cd4', array($arr[0], $arr[1]))->get()->lists('visit_id') + ContraceptiveHistory::where('current_status', $key1)->get()->lists('visit_id') + array('0'))->whereBetween('created_at', array($from, $to));
                            $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        }
                        $i++;
                    }
                    $column .= $col < count($columcd4) ? "]}," : "]}";
                    $col++;
                }
            } elseif (isset($columresult)) {
                $count = 0;
                foreach ($columresult as $key1 => $value1) {
                    $column .= "{ name: '" . $value1 . "', data: [ ";
                    $i = 1;
                    foreach ($row1 as $key => $value) {
                        $from = Input::get('year') . "-" . $key . "-01";
                        $to = Input::get('year') . "-" . $key . "-31";
                        $patientquery = DB::table('patient');
                        $visitquery = DB::table('visit');
                        $query = $this->processQuery($patientquery, $visitquery);
                        $count == 0 ? $que = $query[1]->whereIn('id', HivStatus::where('pitc_agreed', "yes")->get()->lists('visit_id') + array('0'))->whereBetween('created_at', array($from, $to)) : ($que = $query[1]->whereIn('id', HivStatus::where('pitc_result', $key1)->get()->lists('visit_id') + array('0'))->whereBetween('created_at', array($from, $to)));
                        $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        $i++;
                    }
                    $count++;
                    $column .= $col < count($columresult) ? "]}," : "]}";
                    $col++;
                }
            } elseif (isset($columreason)) {
                foreach ($columreason as $key1 => $value1) {
                    $column .= "{ name: '" . $value1 . "', data: [ ";
                    $i = 1;
                    foreach ($row1 as $key => $value) {
                        $from = Input::get('year') . "-" . $key . "-01";
                        $to = Input::get('year') . "-" . $key . "-31";
                        $patientquery = DB::table('patient');
                        $visitquery = DB::table('visit');
                        $query = $this->processQuery($patientquery, $visitquery);
                        $que = $query[1]->whereIn('id', HivStatus::where('unknown_reason', $key1)->get()->lists('visit_id') + array('0'))->whereBetween('created_at', array($from, $to));
                        $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        $i++;
                    }
                    $column .= $col < count($columreason) ? "]}," : "]}";
                    $col++;
                }
            }
            $title = Input::get('vertical') . " " . $query[2] . " " . Input::get('Year');
        } elseif (Input::get("horizontal") == "Years") {
            $row1 = range(Input::get('start'), Input::get('end'));
            $j = 1;
            foreach ($row1 as $value) {
                $row .= $j < count($row1) ? "'" . $value . "'," : "'" . $value . "'";
                $j++;
            }
            $col = 1;
            if (isset($columntype)) {
                foreach ($columntype as $key1 => $value1) {
                    $column .= "{ name: '" . $value1 . "', data: [ ";
                    $i = 1;
                    foreach ($row1 as $key => $value) {
                        $from = $value . "-01-01";
                        $to = $value . "-12-31";
                        $patientquery = DB::table('patient');
                        $visitquery = DB::table('visit');
                        $query = $this->processQuery($patientquery, $visitquery);
                        if ($pat) {
                            $que = $query[0]->whereIn('id', PatientReport::where('HIV_status', $key1)->get()->lists('patient_id') + array('0'))->whereBetween('created_at', array($from, $to));
                            $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        } elseif ($vis) {
                            $que = $query[1]->whereIn('id', HivStatus::where('status', $key1)->get()->lists('visit_id') + array('0'))->whereBetween('created_at', array($from, $to));
                            $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        }
                        $i++;
                    }
                    $column .= $col < count($columntype) ? "]}," : "]}";
                    $col++;
                }
            } elseif (isset($columcd4)) {
                foreach ($columcd4 as $key1 => $value1) {
                    $arr = explode("-", $value1);
                    $column .= "{ name: '" . $value1 . "', data: [ ";
                    $i = 1;
                    foreach ($row1 as $value) {
                        $from = $value . "-01-01";
                        $to = $value . "-12-31";
                        $patientquery = DB::table('patient');
                        $visitquery = DB::table('visit');
                        $query = $this->processQuery($patientquery, $visitquery);
                        if ($pat) {
                            $que = $query[0]->whereIn('id', PatientReport::whereBetween('cd4_count', array($arr[0], $arr[1]))->get()->lists('patient_id') + array('0'))->whereBetween('created_at', array($from, $to));
                            $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        } elseif ($vis) {
                            $que = $query[1]->whereIn('id', HivStatus::whereBetween('pitc_cd4', array($arr[0], $arr[1]))->get()->lists('visit_id') + ContraceptiveHistory::where('current_status', $key1)->get()->lists('visit_id') + array('0'))->whereBetween('created_at', array($from, $to));
                            $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        }
                        $i++;
                    }
                    $column .= $col < count($columcd4) ? "]}," : "]}";
                    $col++;
                }
            } elseif (isset($columresult)) {
                $count = 0;
                foreach ($columresult as $key1 => $value1) {
                    $column .= "{ name: '" . $value1 . "', data: [ ";
                    $i = 1;
                    foreach ($row1 as $value) {
                        $from = $value . "-01-01";
                        $to = $value . "-12-31";
                        $patientquery = DB::table('patient');
                        $visitquery = DB::table('visit');
                        $query = $this->processQuery($patientquery, $visitquery);
                        $count == 0 ? $que = $query[1]->whereIn('id', HivStatus::where('pitc_agreed', "yes")->get()->lists('visit_id') + array('0'))->whereBetween('created_at', array($from, $to)) : ($que = $query[1]->whereIn('id', HivStatus::where('pitc_result', $key1)->get()->lists('visit_id') + array('0'))->whereBetween('created_at', array($from, $to)));
                        $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        $i++;
                    }
                    $count++;
                    $column .= $col < count($columresult) ? "]}," : "]}";
                    $col++;
                }
            } elseif (isset($columreason)) {
                foreach ($columreason as $key1 => $value1) {
                    $column .= "{ name: '" . $value1 . "', data: [ ";
                    $i = 1;
                    foreach ($row1 as $value) {
                        $from = $value . "-01-01";
                        $to = $value . "-12-31";
                        $patientquery = DB::table('patient');
                        $visitquery = DB::table('visit');
                        $query = $this->processQuery($patientquery, $visitquery);
                        $que = $query[1]->whereIn('id', HivStatus::where('unknown_reason', $key1)->get()->lists('visit_id') + array('0'))->whereBetween('created_at', array($from, $to));
                        $column .= $i < count($row1) ? $que->count() . "," : $que->count();
                        $i++;
                    }
                    $column .= $col < count($columreason) ? "]}," : "]}";
                    $col++;
                }
            }
            $title = Input::get('vertical') . " " . $query[2] . " " . Input::get('Year');
        } elseif (Input::get("horizontal") == "Age Range") {
            //setting the limits
            if (parent::maxAge() % Input::get('age') == 0) {
                $limit = parent::maxAge();
            } else {
                $limit = parent::maxAge() - parent::maxAge() % Input::get('age') + Input::get('age');
            }
            //making a loop for values
            //year iterator
            $k = 0;
            //getting age
            $range = Input::get('age');
            $yeardate = date("Y") + 1;
            $yaerdate1 = $yeardate . "-01-01";
            //creating title
            $j = 1;
            for ($i = $range; $i <= $limit; $i += $range) {
                $row .= $i < $limit ? "'" . $k . " - " . $i . "'," : "'" . $k . " - " . $i . "'";
                $k = $i;
            }
            $col = 1;
            if (isset($columntype)) {
                foreach ($columntype as $key1 => $value1) {
                    $column .= "{ name: '" . $value1 . "', data: [ ";
                    $i = 1;
                    for ($i = $range; $i <= $limit; $i += $range) {
                        //start year
                        $time = $k * 365 * 24 * 3600;
                        $today = date("Y-m-d");
                        $timerange = strtotime($today) - $time;
                        $start = date("Y", $timerange) + 1 . "-01-01";
                        //end year
                        $time1 = $i * 365 * 24 * 3600;
                        $timerange1 = strtotime($today) - $time1;
                        $end = date("Y", $timerange1) . "-01-01";
                        $patientquery = DB::table('patient');
                        $visitquery = DB::table('visit');
                        $query = $this->processQuery($patientquery, $visitquery);
                        $que = $query[0]->whereIn('id', PatientReport::where('HIV_status', $key1)->get()->lists('patient_id') + array('0'))->whereBetween('birth_date', array($end, $start));
                        $column .= $i < $limit ? $que->count() . "," : $que->count();
                        $k = $i;
                    }
                    $column .= $col < count($columntype) ? "]}," : "]}";
                    $col++;
                }
            } elseif (isset($columcd4)) {
                foreach ($columcd4 as $key1 => $value1) {
                    $arr = explode("-", $value1);
                    $column .= "{ name: '" . $value1 . "', data: [ ";
                    for ($i = $range; $i <= $limit; $i += $range) {
                        //start year
                        $time = $k * 365 * 24 * 3600;
                        $today = date("Y-m-d");
                        $timerange = strtotime($today) - $time;
                        $start = date("Y", $timerange) + 1 . "-01-01";
                        //end year
                        $time1 = $i * 365 * 24 * 3600;
                        $timerange1 = strtotime($today) - $time1;
                        $end = date("Y", $timerange1) . "-01-01";
                        $patientquery = DB::table('patient');
                        $visitquery = DB::table('visit');
                        $query = $this->processQuery($patientquery, $visitquery);
                        $que = $query[0]->whereIn('id', PatientReport::whereBetween('cd4_count', array($arr[0], $arr[1]))->get()->lists('patient_id') + array('0'))->whereBetween('birth_date', array($end, $start));
                        $column .= $i < $limit ? $que->count() . "," : $que->count();
                        $k = $i;
                    }
                    $column .= $col < count($columcd4) ? "]}," : "]}";
                    $col++;
                }
            } elseif (isset($columresult)) {
                $count = 0;
                foreach ($columresult as $key1 => $value1) {
                    $column .= "{ name: '" . $value1 . "', data: [ ";
                    for ($i = $range; $i <= $limit; $i += $range) {
                        //start year
                        $time = $k * 365 * 24 * 3600;
                        $today = date("Y-m-d");
                        $timerange = strtotime($today) - $time;
                        $start = date("Y", $timerange) + 1 . "-01-01";
                        //end year
                        $time1 = $i * 365 * 24 * 3600;
                        $timerange1 = strtotime($today) - $time1;
                        $end = date("Y", $timerange1) . "-01-01";
                        $patientquery = DB::table('patient');
                        $visitquery = DB::table('visit');
                        $query = $this->processQuery($patientquery, $visitquery);
                        $count == 0 ? $que = $query[1]->whereIn('id', HivStatus::where('pitc_agreed', "yes")->get()->lists('visit_id') + array('0'))->whereIn('patient_id', Patient::whereBetween('birth_date', array($end, $start))->get()->lists('id') + array('0')) : ($que = $query[1]->whereIn('id', HivStatus::where('pitc_result', $key1)->get()->lists('visit_id') + array('0'))->whereIn('patient_id', Patient::whereBetween('birth_date', array($end, $start))->get()->lists('id') + array('0')));
                        $column .= $i < $limit ? $que->count() . "," : $que->count();
                        $k = $i;
                    }
                    $count++;
                    $column .= $col < count($columresult) ? "]}," : "]}";
                    $col++;
                }
            } elseif (isset($columreason)) {
                foreach ($columreason as $key1 => $value1) {
                    $column .= "{ name: '" . $value1 . "', data: [ ";
                    for ($i = $range; $i <= $limit; $i += $range) {
                        //start year
                        $time = $k * 365 * 24 * 3600;
                        $today = date("Y-m-d");
                        $timerange = strtotime($today) - $time;
                        $start = date("Y", $timerange) + 1 . "-01-01";
                        //end year
                        $time1 = $i * 365 * 24 * 3600;
                        $timerange1 = strtotime($today) - $time1;
                        $end = date("Y", $timerange1) . "-01-01";
                        $patientquery = DB::table('patient');
                        $visitquery = DB::table('visit');
                        $query = $this->processQuery($patientquery, $visitquery);
                        $que = $query[1]->whereIn('id', HivStatus::where('unknown_reason', $key1)->get()->lists('visit_id') + array('0'))->whereIn('patient_id', Patient::whereBetween('birth_date', array($end, $start))->get()->lists('id') + array('0'));
                        $column .= $i < $limit ? $que->count() . "," : $que->count();
                        $k = $i;
                    }
                    $column .= $col < count($columreason) ? "]}," : "]}";
                    $col++;
                }
            }
            $title = Input::get('vertical') . " Age Range " . $query[2] . " ";
        }
        $row .= "]";
        ?>
        <script type="text/javascript">
            $(function () {
                $('#chartarea').highcharts({
                    title: {
                        text: '<?php 
        echo $title;
        ?>
'
                    },
                    xAxis: {
                        <?php 
        echo $row;
        ?>
                    },
                    yAxis: {
                        title: {
                            text: '<?php 
        echo Input::get('vertical');
        ?>
'
                        },
                        plotLines: [{
                            value: 0,
                            width: 1,
                            color: '#808080'
                        }]
                    },
                    tooltip: {
                        valueSuffix: '<?php 
        Input::get('vertical');
        ?>
'
                    },
                    legend: {
                        layout: 'vertical',
                        align: 'right',
                        verticalAlign: 'middle',
                        borderWidth: 0
                    },
                    series: [<?php 
        echo $column;
        ?>
]
                });
            });
        </script>
    <?php 
    }