初始化仓库
This commit is contained in:
134
member/models/forms/HealthForm.php
Normal file
134
member/models/forms/HealthForm.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace member\models\forms;
|
||||
|
||||
use common\core\BaseModel;
|
||||
use common\models\UserPatientHealthInquiry;
|
||||
use common\modelsgii\UserPatient;
|
||||
use yii\db\Exception;
|
||||
|
||||
//健康信息form
|
||||
class HealthForm extends BaseModel
|
||||
{
|
||||
public $user_patient_id;
|
||||
|
||||
public $family_status;
|
||||
public $family_history;
|
||||
public $allergic_status;
|
||||
public $allergic_history;
|
||||
public $person_status;
|
||||
public $person_history;
|
||||
public $liver_function;
|
||||
public $liver_index;
|
||||
public $renal_function;
|
||||
public $renal_index;
|
||||
|
||||
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
['user_patient_id','required'],
|
||||
[['family_status','allergic_status','person_status','liver_function','renal_function'],'default','value'=>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\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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user