/** * Print the next letter for an operation. * * @param OEPDFPrint $pdf_print * @param Element_OphTrOperationbooking_Operation $operation * @param bool $auto_confirm * * @throws CException */ protected function printLetter($operation, $auto_confirm = false) { $patient = $operation->event->episode->patient; $letter_status = $operation->getDueLetter(); if ($letter_status === null && $operation->getLastLetter() == Element_OphTrOperationbooking_Operation::LETTER_GP) { $letter_status = Element_OphTrOperationbooking_Operation::LETTER_GP; } $letter_templates = array(Element_OphTrOperationbooking_Operation::LETTER_INVITE => 'invitation_letter', Element_OphTrOperationbooking_Operation::LETTER_REMINDER_1 => 'reminder_letter', Element_OphTrOperationbooking_Operation::LETTER_REMINDER_2 => 'reminder_letter', Element_OphTrOperationbooking_Operation::LETTER_GP => 'gp_letter', Element_OphTrOperationbooking_Operation::LETTER_REMOVAL => false); $letter_template = isset($letter_templates[$letter_status]) ? $letter_templates[$letter_status] : false; if ($letter_template) { $firm = $operation->event->episode->firm; $site = $operation->site; $waitingListContact = $operation->waitingListContact; // Don't print GP letter if practice address is not defined if ($letter_status != Element_OphTrOperationbooking_Operation::LETTER_GP || $patient->practice && $patient->practice->contact->address) { Yii::log('Printing letter: ' . $letter_template, 'trace'); $html = call_user_func(array($this, 'print_' . $letter_template), $operation); if ($auto_confirm) { $operation->confirmLetterPrinted(); } return $html; } else { Yii::log('Patient has no practice address, printing letter supressed: ' . $patient->id, 'trace'); } } elseif ($letter_status === null) { Yii::log('No letter is due: ' . $patient->id, 'trace'); } else { throw new CException('Undefined letter status'); } }