public function getWardOptions($session)
{
if (!$session || !$session->id) {
throw new Exception('Session is required.');
}
$siteId = $session->theatre->site_id;
$theatreId = $session->theatre_id;
$results = array();
if (!empty($theatreId)) {
if ($session->theatre->ward) {
$results[$session->theatre->ward_id] = $session->theatre->ward->name;
}
}
if (empty($results)) {
// otherwise select by site and patient age/gender
$patient = $this->getPatient();
$genderRestrict = $ageRestrict = 0;
$genderRestrict = 'M' == $patient->gender ? OphTrOperationbooking_Operation_Ward::RESTRICTION_MALE : OphTrOperationbooking_Operation_Ward::RESTRICTION_FEMALE;
$ageRestrict = $patient->isChild($session->date) ? OphTrOperationbooking_Operation_Ward::RESTRICTION_CHILD : OphTrOperationbooking_Operation_Ward::RESTRICTION_ADULT;
$criteria = new CDbCriteria();
$criteria->addCondition('`t`.site_id = :siteId');
$criteria->addCondition('`t`.restriction & :r1 >0');
$criteria->addCondition('`t`.restriction & :r2 >0');
$criteria->params[':siteId'] = $siteId;
$criteria->params[':r1'] = $genderRestrict;
$criteria->params[':r2'] = $ageRestrict;
$criteria->order = 't.display_order asc';
$results = CHtml::listData(OphTrOperationbooking_Operation_Ward::model()->active()->findAll($criteria), 'id', 'name');
}
return $results;
}