0], [['family_history','allergic_history','person_history','liver_index','renal_index'],'default','value'=>[]], ['family_history','required','when'=>function($model){ return $model->family_status==1; }], ['allergic_history','required','when'=>function($model){ return $model->allergic_status==1; }], ['person_history','required','when'=>function($model){ return $model->person_status==1; }], ['liver_index','required','when'=>function($model){ return $model->liver_function==1; }], ['renal_index','required','when'=>function($model){ return $model->renal_function==1; }], ]; } public function save() { if (!$this->validate()){ throw new Exception($this->getErrorMsg()); } $UserPatient=UserPatient::find()->where([ 'id'=>$this->user_patient_id, 'user_id'=>\Yii::$app->user->identity->getId(), 'is_delete'=>0 ])->one(); if (!$UserPatient){ throw new Exception('患者不存在'); } $UserPatientHealthInquiry= UserPatientHealthInquiry::find()->where([ 'user_patient_id'=>$this->user_patient_id, 'is_delete'=>0 ])->one(); if (!$UserPatientHealthInquiry){ $UserPatientHealthInquiry=new UserPatientHealthInquiry(); } $UserPatientHealthInquiry->attributes=$this->attributes; $UserPatientHealthInquiry->saveOrFail(); return ['保存成功']; } public function del() { if (!$this->validate()){ throw new Exception($this->getErrorMsg()); } $UserPatient=UserPatient::find()->where([ 'id'=>$this->user_patient_id, 'user_id'=>\Yii::$app->user->identity->getId(), 'is_delete'=>0 ])->one(); if (!$UserPatient){ throw new Exception('患者不存在'); } $UserPatientHealthInquiry= UserPatientHealthInquiry::find()->where([ 'user_patient_id'=>$this->user_patient_id, 'is_delete'=>0 ])->one(); if (!$UserPatientHealthInquiry){ throw new Exception('健康信息不存在'); } $UserPatientHealthInquiry->is_delete=1; $UserPatientHealthInquiry->update(); return ['删除成功']; } public function info() { $user_id= \Yii::$app->user->identity->getId(); $patient = \common\models\oldDb\UserPatient::findOne([ 'id' => $this->user_patient_id, 'user_id' =>$user_id, 'is_delete' => 0 ]); if (!$patient) { throw new \yii\base\Exception('就诊人不存在'); } $UserPatientHealthInquiry= UserPatientHealthInquiry::find()->where([ 'user_patient_id'=>$this->user_patient_id, 'is_delete'=>0 ])->one(); if (!$UserPatientHealthInquiry){ throw new Exception('健康信息不存在'); } return $UserPatientHealthInquiry; } }