OEModule\PASAPI\resources\PatientAppointment::delete PHP Method

delete() public method

public delete ( )
    public function delete()
    {
        if (!$this->assignment) {
            $this->addError('Resource ID required');
            return false;
        }
        $transaction = $this->startTransaction();
        try {
            $model = $this->assignment->getInternal();
            if (!$model) {
                // reference exists, but internal model could not be found
                // TODO: decide if the assignment model should be cleared out given that the internal reference
                // doesn't exist.
                throw new \Exception('Could not find internal model to delete.');
            }
            if ($model->isNewRecord) {
                throw new \Exception('No appointment reference found for this id');
            }
            if (!$model->delete()) {
                $this->addModelErrors($model->getErrors());
                throw new \Exception('Could not delete internal model.');
            }
            if (!$this->assignment->delete()) {
                $this->addModelErrors($this->assignment->getErrors());
                throw new \Exception('Could not delete external reference.');
            }
            if ($transaction) {
                $transaction->commit();
            }
            return true;
        } catch (\Exception $e) {
            if ($transaction) {
                $transaction->rollback();
            }
            throw $e;
        }
    }