protected function deceasedPatients()
{
echo 'Cancelling operations for deceased patients: ';
// TODO: This needs to be made more robust
$cancellation_reason = OphTrOperationbooking_Operation_Cancellation_Reason::model()->find("text = 'Patient has died'");
if (!$cancellation_reason) {
throw new CException('Cannot find cancellation code for "patient has died"');
}
$criteria = new CDbCriteria();
$criteria->addInCondition('`t`.status_id', array(1, 2, 3, 4));
$criteria->addCondition('is_deceased = 1 and session_date > :dateNow');
$criteria->params[':dateNow'] = date('Y-m-d');
foreach (Element_OphTrOperationbooking_Operation::model()->with(array('event' => array('with' => array('episode' => array('with' => 'patient'))), 'booking'))->findAll($criteria) as $operation) {
$operation = Element_OphTrOperationbooking_Operation::model()->findByPk($operation['id']);
$operation->cancel($cancellation_reason->id, 'Booking cancelled automatically', 1);
echo '.';
}
echo "\n";
}