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

saveModel() public method

public saveModel ( WorklistPatient $model ) : boolean | WorklistPatient
$model WorklistPatient
return boolean | WorklistPatient
    public function saveModel(\WorklistPatient $model)
    {
        // extract the values to be passed to the manager instance for mapping
        $patient = $this->mapPatient($model);
        $when = $this->mapWhen($model);
        $attributes = $this->mapAttributes($model);
        // allow the suppression of errors for appointments received prior to the ignore date
        if ($warning_limit = $this->worklist_manager->getWorklistIgnoreDate()) {
            if ($when < $warning_limit) {
                $this->warn_errors = true;
            }
        }
        if ($model->isNewRecord) {
            if (!($model = $this->worklist_manager->mapPatientToWorklistDefinition($patient, $when, $attributes))) {
                foreach ($this->worklist_manager->getErrors() as $err) {
                    $this->addError($err);
                }
                if ($this->warn_errors) {
                    return false;
                }
                throw new \Exception('Could not add patient to worklist');
            }
        } else {
            $model->patient_id = $patient->id;
            if (!$this->worklist_manager->updateWorklistPatientFromMapping($model, $when, $attributes, !$this->partial_record)) {
                foreach ($this->worklist_manager->getErrors() as $err) {
                    $this->addError($err);
                }
                if ($this->warn_errors) {
                    return false;
                }
                throw new \Exception('Could not update patient worklist entry');
            }
        }
        return $model;
    }