134 lines
3.9 KiB
PHP
134 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace member\models\forms;
|
|
|
|
use common\core\BaseModel;
|
|
use common\models\oldDb\UserPatientHealthInquiry;
|
|
use common\modelsgii\oldDb\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\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;
|
|
}
|
|
} |