public function updateWorklistPatientFromMapping(WorklistPatient $worklist_patient, DateTime $when, $attributes = array(), $allow_worklist_change = false)
{
$worklist = $this->getWorklistForMapping($when, $attributes);
if (!$worklist) {
return;
}
if (!$allow_worklist_change && $worklist->id != $worklist_patient->worklist_id) {
$this->addError('Worklist mapping change not allowed for partial update.');
return;
}
$transaction = $this->startTransaction();
try {
$worklist_patient->worklist_id = $worklist->id;
$worklist_patient->when = $when->format('Y-m-d H:i:s');
if (!$this->setAttributesForWorklistPatient($worklist_patient, $attributes)) {
throw new Exception('Could not set worklist attributes');
}
if (!$worklist_patient->save()) {
foreach ($worklist_patient->getErrors() as $key => $error) {
foreach ($error as $message) {
$this->addError("{$key}: {$message}");
}
throw new Exception('Could not update WorklistPatient');
}
}
if ($transaction) {
$transaction->commit();
}
return $worklist_patient;
} catch (Exception $e) {
echo $e->getMessage();
$this->addError($e->getMessage());
if ($transaction) {
$transaction->rollback();
}
return;
}
}