public function updateComplications($complication_ids)
{
$curr_by_id = array();
foreach ($this->complication_assignments as $ca) {
$curr_by_id[$ca->complication_id] = $ca;
}
foreach ($complication_ids as $c_id) {
if (!isset($curr_by_id[$c_id])) {
$ca = new OphTrOperationnote_CataractComplication();
$ca->cataract_id = $this->id;
$ca->complication_id = $c_id;
if (!$ca->save()) {
throw new Exception('Unable to save complication assignment: ' . print_r($ca->getErrors(), true));
}
} else {
unset($curr_by_id[$c_id]);
}
}
foreach ($curr_by_id as $ca) {
if (!$ca->delete()) {
throw new Exception('Unable to delete complication assignment: ' . print_r($ca->getErrors(), true));
}
}
}