public function updatePatientFactorAnswers($data)
{
$current = $this->getRelated('patient_factor_answers', true);
while ($answer = array_shift($current)) {
if (array_key_exists($answer->patient_factor_id, $data)) {
$this->updateAnswer($answer, $data[$answer->patient_factor_id]);
unset($data[$answer->patient_factor_id]);
} else {
if (!$answer->delete()) {
throw new \Exception('Unable to delete CVI Patient Factor Answer: ' . print_r($answer->getErrors(), true));
}
}
}
foreach ($data as $factor_id => $values) {
$answer = new OphCoCvi_ClericalInfo_PatientFactor_Answer();
$answer->patient_factor_id = $factor_id;
$this->updateAnswer($answer, $values);
if (!$answer->save()) {
throw new \Exception('Unable to save CVI Patient Factor Answer: ' . print_r($answer->getErrors(), true));
}
}
}