76 lines
2.0 KiB
PHP
76 lines
2.0 KiB
PHP
<?php
|
|
/*
|
|
* @author: liudiao
|
|
* @Date: 2023-07-31 13:45:51
|
|
* @Description:
|
|
*/
|
|
|
|
namespace service\modules\v1\controllers;
|
|
|
|
use common\core\BaseServiceController;
|
|
use common\models\oldDb\DiagnoseCommon;
|
|
use yii\base\Exception;
|
|
|
|
|
|
/**
|
|
* @doc-module 常用医嘱
|
|
*/
|
|
class DiagnoseController extends BaseServiceController
|
|
{
|
|
/**
|
|
* 常用医嘱列表
|
|
*/
|
|
public function actionCommon()
|
|
{
|
|
$diagnoseCommon = DiagnoseCommon::find()->select('id,content')->where(['su_id' => \Yii::$app->user->identity->id])->all();
|
|
return $diagnoseCommon;
|
|
}
|
|
|
|
/**
|
|
* 添加常用医嘱
|
|
*/
|
|
public function actionAdd(){
|
|
$post = \Yii::$app->request->post();
|
|
$this->requestValidate($post,[
|
|
[['content'],'required']
|
|
]);
|
|
$diagnoseCommon = DiagnoseCommon::find()->where(['content' => $post['content'],'su_id' => \Yii::$app->user->identity->id])->one();
|
|
if($diagnoseCommon){
|
|
throw new Exception('已存在相同内容的医嘱');
|
|
}
|
|
$common = new DiagnoseCommon();
|
|
$common->su_id = \Yii::$app->user->identity->id;
|
|
$common->content = $post['content'];
|
|
$common->saveOrFail();
|
|
return ['success'];
|
|
}
|
|
|
|
|
|
/**
|
|
* 删除常用医嘱
|
|
*/
|
|
public function actionDelete(){
|
|
$post = \Yii::$app->request->post();
|
|
$this->requestValidate($post,[
|
|
[['id'],'required']
|
|
]);
|
|
$ids = explode(',', $post['id']);
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
try {
|
|
foreach($ids as $v){
|
|
$diagnoseCommon = DiagnoseCommon::find()->where(['id' => $v,'su_id' => \Yii::$app->user->identity->id])->one();
|
|
if(!$diagnoseCommon){
|
|
throw new Exception('医嘱不存在');
|
|
}
|
|
$diagnoseCommon->delete();
|
|
}
|
|
$t->commit();
|
|
} catch (\Exception $e) {
|
|
$t->rollBack();
|
|
throw new Exception($e->getMessage());
|
|
}
|
|
return ['success'];
|
|
}
|
|
|
|
}
|