private function generateCsvFile($lineCount, $lines)
 {
     /*{{{*/
     $fileName = "/tmp/doctor_" . strtotime("now") . ".csv";
     $csvFileGenerator = new CsvFileGenerator($fileName, $lineCount);
     foreach ($lines as $line) {
         $csvFileGenerator->writeLine($line);
     }
     $csvFileGenerator->closeFp();
     return $csvFileGenerator->getFileName();
 }
    public function downloadCsvFile($request, $response)
    {/*{{{*/
        $dir = "/tmp/financialfiles";
        if(is_dir($dir)==false)
        {
            mkdir($dir, 0777);
        }

        $fileName = $dir."/".$request->filename;
        if(true || false == file_exists($fileName))
        {
            $firstLine = $request->firstline;
            $firstLine = XString::string2TwoDimArray($firstLine);
            $firstLine = array_shift($firstLine);
            $fileGenerator = new CsvFileGenerator($fileName, count($firstLine));
            $fileGenerator->writeLine($firstLine);

            $allLines = $request->content;
            foreach($allLines as $lines)
            {
                $lines = XString::string2TwoDimArray($lines);
                foreach($lines as $l)
                {
                    $fileGenerator->writeLine($l);
                }
            }

            $fileGenerator->closeFp();
        }

        $file = fopen($fileName,"r"); 
        Header("Content-type: application/octet-stream");
        Header("Accept-Ranges: bytes");
        Header("Accept-Length: ".filesize($fileName));
        Header("Content-Disposition: attachment; filename=".$request->filename);
        echo fread($file, filesize($fileName));
        fclose($file);

        exit;
    }/*}}}*/