104 lines
3.1 KiB
PHP
104 lines
3.1 KiB
PHP
<?php
|
|
/*
|
|
* @author: liudiao
|
|
* @Date: 2023-04-18 11:05:02
|
|
* @Description:
|
|
*/
|
|
|
|
namespace admin\models\forms\drug;
|
|
|
|
use common\core\BaseModel;
|
|
|
|
use common\modelsgii\Disease;
|
|
use Overtrue\Pinyin\Pinyin;
|
|
use yii\db\Exception;
|
|
|
|
//症状诊断form
|
|
class DiagnoseForm extends BaseModel
|
|
{
|
|
public $id;
|
|
public $name;
|
|
public $diagnose_code;
|
|
public $major_number;
|
|
public $ref_number;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
['id','integer'],
|
|
['name','required'],
|
|
[['diagnose_code','major_number','ref_number'],'string']
|
|
];
|
|
}
|
|
|
|
//录入
|
|
public function save()
|
|
{
|
|
if (!$this->validate()){
|
|
throw new Exception($this->getErrorMsg());
|
|
}
|
|
if ($this->id){
|
|
$Disease=Disease::find()->where(['id'=>$this->id,'is_delete'=>0])->one();
|
|
$Disease->attributes=$this->attributes;
|
|
$Disease->saveOrFail();
|
|
return ['编辑成功'];
|
|
}
|
|
$is_disease=Disease::find()->where(['name'=>$this->name,'is_delete'=>0])->one();
|
|
if ($is_disease) throw new Exception('改症状已经存在,请勿重复添加');
|
|
$add_disease=new Disease();
|
|
$add_disease->attributes=$this->attributes;
|
|
$add_disease->pinyin = (new Pinyin())->abbr($this->name);
|
|
$add_disease->saveOrFail();
|
|
return ['添加成功'];
|
|
}
|
|
|
|
//导入
|
|
public function export($data)
|
|
{
|
|
if (empty($data)) {
|
|
throw new Exception('导入数据为空');
|
|
} else {
|
|
foreach ($data as $item) {
|
|
try {
|
|
$Disease=Disease::find()->where(['diagnose_code'=>$item['编码'],'is_delete'=>0])->one();
|
|
|
|
if (!$Disease){
|
|
$model = new Disease();
|
|
$model->setAttribute('diagnose_code', trim($item['编码']));
|
|
$model->setAttribute('name', trim($item['名称']));
|
|
$model->setAttribute('pinyin', (new Pinyin())->abbr(trim($item['名称'])));
|
|
$model->setAttribute('major_number', trim($item['主编号']));
|
|
$model->setAttribute('ref_number',trim($item['次编号']) );
|
|
if (!$model->save()) {
|
|
$errorsMsg = array_values($model->getFirstErrors());
|
|
return [$errorsMsg[0]];
|
|
}
|
|
|
|
$success[] = '诊断症状导入成功';
|
|
}else{
|
|
$errors[]= '编码:'.$item['编码'].'导入失败,原因:重复导入';
|
|
}
|
|
} catch (\Exception $e) {
|
|
$errors[] = $e->getMessage();
|
|
continue;
|
|
}
|
|
}
|
|
return ['success'=> $success,'error'=>$errors];
|
|
}
|
|
}
|
|
|
|
|
|
public function del()
|
|
{
|
|
$Disease=Disease::find()->where([
|
|
'id'=>$this->id,
|
|
'is_delete'=>0
|
|
])->one();
|
|
if (!$Disease) throw new Exception('诊断症状不存在');
|
|
|
|
$Disease->is_delete=1;
|
|
$Disease->saveorFail();
|
|
|
|
return ['删除成功'];
|
|
}
|
|
} |