/**
  * The order detail page of an order for Operator User
  */
 public function vieworderAction()
 {
     $this->view->id = $id = $this->getRequest()->getParam('id', '');
     $patient = patient::getOrderById($id);
     $this->view->userType = $this->userObj['user_type'];
     $this->view->patient = $patient;
 }
 /**
  * PDF of a test order is downloaded by this method
  */
 public function downloadpdfAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $id = $this->getRequest()->getParam('id', '');
     $email = $this->getRequest()->getParam('email', 0);
     require_once 'mpdf/mpdf.php';
     $html .= $this->view->action('viewreport', 'patient', 'patient', array('id' => $id));
     $mpdf = new mPDF('+aCJK', 'A4', '', '', 15, 15, 15, 0, 0, 0);
     $mpdf->mirrorMargins = 0;
     $mpdf->setAutoBottomMargin = 'stretch';
     $mpdf->SetDisplayMode('fullwidth');
     $mpdf->WriteHTML($html);
     $fileName = 'PDF_Form' . time() . '.pdf';
     $mpdf->Output('tmp/' . $fileName, $email ? 'F' : 'D');
     if ($email) {
         $patient = patient::getOrderById($id);
         $mail = new PHPMailer();
         $mail->From = '*****@*****.**';
         $mail->FromName = 'Lab';
         $mail->addAddress($patient[0]['email'], '');
         $mail->addAttachment('tmp/' . $fileName);
         $mail->Subject = 'Your Test Report';
         $mail->Body = 'Please find attached report';
         if (!$mail->send()) {
             echo 'Message could not be sent.';
             echo 'Mailer Error: ' . $mail->ErrorInfo;
         } else {
             unlink('tmp/' . $fileName);
             $flashMessenger = $this->_helper->getHelper('FlashMessenger');
             $flashMessenger->addMessage('mail_sent');
             $this->_redirect('/patient/orders');
         }
     }
 }