public function actionCreate()
{
if (!empty($_POST)) {
// form has been submitted
if (isset($_POST['cancel'])) {
$this->redirectToPatientEpisodes();
}
// set and validate
$errors = $this->setAndValidateElementsFromData($_POST);
// creation
if (empty($errors)) {
$transaction = Yii::app()->db->beginTransaction();
try {
$success = $this->saveEvent($_POST);
if ($success) {
//TODO: should this be in the save event as pass through?
if ($this->eventIssueCreate) {
$this->event->addIssue($this->eventIssueCreate);
}
//TODO: should not be passing event?
$this->afterCreateElements($this->event);
$this->logActivity('created event.');
$this->event->audit('event', 'create');
Yii::app()->user->setFlash('success', "{$this->event_type->name} created.");
$transaction->commit();
$this->redirect(array($this->successUri . $this->event->id));
} else {
throw new Exception('could not save event');
}
} catch (Exception $e) {
$transaction->rollback();
throw $e;
}
}
} else {
$this->setOpenElementsFromCurrentEvent('create');
}
$this->editable = false;
$this->event_tabs = array(array('label' => 'Create', 'active' => true));
$cancel_url = $this->episode ? '/patient/episode/' . $this->episode->id : '/patient/episodes/' . $this->patient->id;
$this->event_actions = array(EventAction::link('Cancel', Yii::app()->createUrl($cancel_url), array('level' => 'cancel')));
$this->render('create', array('errors' => @$errors));
}