public function save()
{
$assignment = $this->getAssignment();
$model = $assignment->getInternal();
$this->isNewResource = $model->isNewRecord;
if ($this->isNewResource && $this->partial_record) {
$this->addError('Cannot perform partial update on a new record');
return;
}
if (!$this->validate()) {
return;
}
$transaction = $this->startTransaction();
try {
if ($this->isNewResource && $this->update_only) {
return;
}
if ($this->saveModel($model)) {
$assignment->internal_id = $model->id;
$assignment->save();
$assignment->unlock();
$this->audit($this->isNewResource ? 'create' : 'update', null, null, array('patient_id' => $model->id));
if ($transaction) {
$transaction->commit();
}
return $model->id;
} else {
if ($transaction) {
$transaction->rollback();
}
}
} catch (\Exception $e) {
if ($transaction) {
$transaction->rollback();
}
throw $e;
}
}