415 lines
14 KiB
PHP
415 lines
14 KiB
PHP
<?php
|
|
|
|
namespace service\modules\v1\controllers;
|
|
|
|
use common\core\BaseAppController;
|
|
use common\models\ChineseRepice;
|
|
use common\models\PrescriptionChinese;
|
|
use common\models\PrescriptionWest;
|
|
use common\models\Prescription;
|
|
use common\models\WestRepice;
|
|
use common\services\PrescriptionService;
|
|
use yii\base\Exception;
|
|
use common\helpers\FuncHelper;
|
|
use common\models\GranularRepice;
|
|
use common\models\PrescriptionGranular;
|
|
|
|
/**
|
|
* @doc-module 处方详情
|
|
*/
|
|
class PrescripDetailController extends BaseAppController
|
|
{
|
|
/**
|
|
* 处方列表
|
|
*/
|
|
public function actionList(){
|
|
$post = \YII::$app->request->post();
|
|
$query = Prescription::find()->alias('p')->with('userPatient')->where([
|
|
'p.su_id' => \Yii::$app->user->identity->id,
|
|
'p.is_deleted' => 0,
|
|
'p.store_id' => $post['store_id']
|
|
])->orderBy('p.created_at DESC');
|
|
$this->field = [
|
|
Prescription::class => [
|
|
'id','up_id','prescription_type', 'type','is_pay','refund_status','prescription_no','status','created_at',
|
|
'patient' => function ($model) {
|
|
return [
|
|
'id' => $model->userPatient['id'],
|
|
'name' =>$model->userPatient['name'],
|
|
'sex' => $model->userPatient['sex'],
|
|
'age' => FuncHelper::getAgeFromIdNo($model->userPatient['id_card']),
|
|
];
|
|
}
|
|
]
|
|
];
|
|
|
|
$patient_name = $post['patient_name'];
|
|
$query->joinWith(['userPatient' => function ($q) use ($patient_name) {
|
|
$q->alias('up');
|
|
//搜索就诊人姓名
|
|
if (!empty($patient_name)) {
|
|
$q->andWhere(['like', 'up.name', $patient_name]);
|
|
}
|
|
}]);
|
|
|
|
if($post['prescription_no']){
|
|
$query->andWhere(['p.prescription_no'=> $post['prescription_no']]);
|
|
}
|
|
if($post['status'] ){
|
|
$query->andWhere(['p.status'=> $post['status']]);
|
|
}elseif($post['status']==='0'){
|
|
$query->andWhere(['p.status'=> $post['status']]);
|
|
}else{
|
|
$query->andWhere(['p.status'=> [0,1,2]]);
|
|
}
|
|
if($post['type']){
|
|
$query->andWhere(['p.type'=>$post['type']]);
|
|
}
|
|
if($post['prescription_type']){
|
|
$query->andWhere(['p.prescription_type'=>$post['prescription_type']]);
|
|
}
|
|
|
|
if($post['start_time']&&!$post['end_time']){
|
|
$query->andWhere(['>=','p.created_at',strtotime($post['start_time'])]);
|
|
}
|
|
|
|
if(!$post['start_time']&&$post['end_time']){
|
|
$query->andWhere(['<=','p.created_at',strtotime($post['end_time'])]);
|
|
}
|
|
|
|
if($post['start_time']&&$post['end_time']){
|
|
$query->andWhere(['between','p.created_at',strtotime($post['start_time']),strtotime($post['end_time'])]);
|
|
}
|
|
|
|
return $this->create($query, \Yii::$app->request->post());
|
|
}
|
|
|
|
/**
|
|
* 处方详情
|
|
*/
|
|
public function actionDetail(){
|
|
$post = \Yii::$app->request->post();
|
|
$this->requestValidate($post, [
|
|
['prescription_id','required'],
|
|
['store_id', 'required']
|
|
]);
|
|
return (new PrescriptionService())->detail('', $post['prescription_id']);
|
|
}
|
|
|
|
|
|
/**
|
|
* 开处方-常用方
|
|
*/
|
|
public function actionCommonUse()
|
|
{
|
|
$post = \YII::$app->request->post();
|
|
|
|
$chinese = PrescriptionChinese::find()->where([
|
|
'type' => 2,
|
|
'store_id' => $post['store_id']
|
|
])->andWhere(['su_id' => \Yii::$app->user->identity->id])->all();
|
|
$west = PrescriptionWest::find()->where([
|
|
'type' => 2,
|
|
'store_id' => $post['store_id']
|
|
])->andWhere(['su_id' => \Yii::$app->user->identity->id])->all();
|
|
$granular = PrescriptionGranular::find()->where([
|
|
'type' => 2,
|
|
'store_id' => $post['store_id']
|
|
])->andWhere(['su_id' => \Yii::$app->user->identity->id])->all();
|
|
if (!$chinese && !$west && !$granular) throw new Exception('没有常用方');
|
|
|
|
$chineseRepice = $westRepice = $granularRepice = [];
|
|
if($chinese){
|
|
foreach ($chinese as $value) {
|
|
$ids = explode(',', $value['cr_ids']);
|
|
$chineseRepice[] = ChineseRepice::find()->where(['in', 'id', $ids])->asArray()->all();
|
|
}
|
|
}
|
|
|
|
if($west){
|
|
foreach ($west as $value) {
|
|
$ids = explode(',', $value['wr_ids']);
|
|
$westRepice[] = WestRepice::find()->where(['in', 'id', $ids])->with(['usetime', 'usetype', 'frequency', 'westUnit'])->asArray()->all();
|
|
}
|
|
}
|
|
|
|
if($granular){
|
|
foreach ($granular as $value) {
|
|
$ids = explode(',', $value['gr_ids']);
|
|
$granularRepice[] = GranularRepice::find()->where(['in', 'id', $ids])->asArray()->all();
|
|
}
|
|
}
|
|
|
|
return [
|
|
'chin_prescription' => $chinese,
|
|
'chinese' => $chineseRepice,
|
|
'west_prescription' => $west,
|
|
'west' => $westRepice,
|
|
'granular_prescription' => $granular,
|
|
'granular' => $granularRepice
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @doc-name 开处方-常用方详情(中药)
|
|
* @doc-param int id 处方id
|
|
*/
|
|
public function actionCommonChinese()
|
|
{
|
|
$post = \Yii::$app->request->post();
|
|
$this->requestValidate($post,[
|
|
['id','required']
|
|
]);
|
|
$chinese = PrescriptionChinese::find()->where([
|
|
'id' => $post['id'],
|
|
'store_id' => $post['store_id']
|
|
])->andWhere(['type' => 2])->one();
|
|
if (!$chinese) {
|
|
throw new Exception('没有该处方');
|
|
}
|
|
$ids = explode(',', $chinese['cr_ids']);
|
|
|
|
$recipe = ChineseRepice::find()->where(['in', 'id', $ids])->asArray()->all();
|
|
return $recipe;
|
|
}
|
|
|
|
/**
|
|
* @doc-name 开处方-常用方详情(颗粒药)
|
|
* @doc-param int id 处方id
|
|
*/
|
|
public function actionCommonGranular()
|
|
{
|
|
$post = \Yii::$app->request->post();
|
|
$this->requestValidate($post,[
|
|
['id','required']
|
|
]);
|
|
$granular = PrescriptionGranular::find()->where([
|
|
'id' => $post['id'],
|
|
'store_id' => $post['store_id']
|
|
])->andWhere(['type' => 2])->one();
|
|
if (!$granular) {
|
|
throw new Exception('没有该处方');
|
|
}
|
|
$ids = explode(',', $granular['gr_ids']);
|
|
|
|
$recipe = GranularRepice::find()->where(['in', 'id', $ids])->asArray()->all();
|
|
return $recipe;
|
|
}
|
|
|
|
|
|
/**
|
|
* @doc-name 开处方-常用方详情(西药)
|
|
* @doc-param int id 处方id
|
|
*/
|
|
public function actionCommonWest()
|
|
{
|
|
$post = \Yii::$app->request->post();
|
|
$this->requestValidate($post,[
|
|
['id','required']
|
|
]);
|
|
$west = PrescriptionWest::find()->where([
|
|
'id' => $post['id'],
|
|
'store_id' => $post['store_id']
|
|
])->andWhere(['type' => 2])->one();
|
|
if (!$west) {
|
|
throw new Exception('没有该处方');
|
|
}
|
|
$ids = explode(',', $west['wr_ids']);
|
|
|
|
$recipe = WestRepice::find()->where(['in', 'id', $ids])->with(['usetime', 'usetype', 'frequency', 'westUnit'])->asArray()->all();
|
|
return $recipe;
|
|
}
|
|
|
|
/**
|
|
* 开处方-中药常用方
|
|
* @doc-param string clinical_diagnose 临床诊断
|
|
* @doc-param int up_id 就诊人id
|
|
* @doc-param string doctor_order 医嘱
|
|
* @doc-param int category 类别1自费2医保
|
|
* @doc-param string cr_ids 拼接药方id
|
|
*/
|
|
public function actionSaveChinCommon()
|
|
{
|
|
$id = \Yii::$app->user->identity->id;
|
|
$request = \Yii::$app->request;
|
|
$param = $request->post();
|
|
$this->requestValidate($param, [
|
|
['name', 'required'],
|
|
['store_id', 'required'],
|
|
//['clinical_diagnose', 'required'],
|
|
//['category', 'required'],
|
|
//['doctor_order', 'required'],
|
|
['cr_ids', 'required'],
|
|
]);
|
|
|
|
$store_id = $param['store_id'];
|
|
|
|
try {
|
|
$chineseRepice = new PrescriptionChinese();
|
|
$chineseRepice->su_id = $id;
|
|
$chineseRepice->name = $param['name'];
|
|
$chineseRepice->clinical_diagnose = $param['clinical_diagnose']??'';
|
|
$chineseRepice->prescription_no = 'ZY'.rand(111111, 999999) . time();
|
|
$chineseRepice->up_id = 0;
|
|
$chineseRepice->store_id = $store_id;
|
|
$chineseRepice->status = 0;
|
|
$chineseRepice->category = $param['category']??'';
|
|
$chineseRepice->doctor_order = $param['doctor_order']??'';
|
|
$chineseRepice->cr_ids = $param['cr_ids'];
|
|
$chineseRepice->type = 2;
|
|
$chineseRepice->saveOrFail();
|
|
|
|
return [
|
|
'id' => $chineseRepice->id,
|
|
'issue_time' => time(),
|
|
'clinical_diagnose' => $param['clinical_diagnose']
|
|
];
|
|
} catch (Exception $e) {
|
|
throw new Exception($e->getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 开处方-中药常用方
|
|
* @doc-param string clinical_diagnose 临床诊断
|
|
* @doc-param int up_id 就诊人id
|
|
* @doc-param string doctor_order 医嘱
|
|
* @doc-param int category 类别1自费2医保
|
|
* @doc-param string cr_ids 拼接药方id
|
|
*/
|
|
public function actionSaveGranularCommon()
|
|
{
|
|
$id = \Yii::$app->user->identity->id;
|
|
$request = \Yii::$app->request;
|
|
$param = $request->post();
|
|
$this->requestValidate($param, [
|
|
['store_id', 'required'],
|
|
['name', 'required'],
|
|
//['clinical_diagnose', 'required'],
|
|
//['category', 'required'],
|
|
//['doctor_order', 'required'],
|
|
['gr_ids', 'required'],
|
|
]);
|
|
|
|
$store_id = $param['store_id'];
|
|
|
|
try {
|
|
$granularRepice = new PrescriptionGranular();
|
|
$granularRepice->su_id = $id;
|
|
$granularRepice->name = $param['name'];
|
|
$granularRepice->clinical_diagnose = $param['clinical_diagnose']??'';
|
|
$granularRepice->prescription_no = 'ZY'.rand(111111, 999999) . time();
|
|
$granularRepice->up_id = 0;
|
|
$granularRepice->store_id = $store_id;
|
|
$granularRepice->status = 0;
|
|
$granularRepice->category = $param['category']??'';
|
|
$granularRepice->doctor_order = $param['doctor_order']??'';
|
|
$granularRepice->gr_ids = $param['gr_ids'];
|
|
$granularRepice->type = 2;
|
|
$granularRepice->saveOrFail();
|
|
|
|
return [
|
|
'id' => $granularRepice->id,
|
|
'issue_time' => time(),
|
|
'clinical_diagnose' => $param['clinical_diagnose']
|
|
];
|
|
} catch (Exception $e) {
|
|
throw new Exception($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @doc-name 开处方-西药常用方
|
|
* @doc-param string doctor_order 医嘱
|
|
* @doc-param string clinical_diagnose 临床诊断
|
|
* @doc-param int up_id 就诊人id
|
|
* @doc-param int category 类别1自费2医保
|
|
* @doc-param string wr_ids 关联西药药方表
|
|
* @doc-return string aa bb
|
|
*/
|
|
public function actionSaveWestCommon()
|
|
{
|
|
$id = \Yii::$app->user->identity->id;
|
|
$param = \Yii::$app->request->post();
|
|
try {
|
|
$this->requestValidate($param, [
|
|
['store_id', 'required'],
|
|
['name', 'required'],
|
|
//['doctor_order', 'required'],
|
|
//['clinical_diagnose', 'required'],
|
|
//['category', 'required'],
|
|
['wr_ids', 'required'],
|
|
]);
|
|
$store_id = $param['store_id'];
|
|
|
|
$westRepice = new PrescriptionWest();
|
|
$westRepice->su_id = $id;
|
|
$westRepice->name = $param['name'];
|
|
$westRepice->clinical_diagnose = $param['clinical_diagnose']??'';
|
|
$westRepice->prescription_no = 'XY'.rand(111111, 999999) . time();
|
|
$westRepice->up_id = 0;
|
|
$westRepice->store_id = $store_id;
|
|
$westRepice->status = 0;
|
|
$westRepice->category = $param['category']??'';
|
|
$westRepice->doctor_order = $param['doctor_order']??'';
|
|
$westRepice->wr_ids = $param['wr_ids'];
|
|
$westRepice->type = 2;
|
|
$westRepice->saveOrFail();
|
|
|
|
return [
|
|
'id' => $westRepice->id,
|
|
'issue_time' => time(),
|
|
'clinical_diagnose' => $param['clinical_diagnose']
|
|
];
|
|
} catch (Exception $e) {
|
|
throw new Exception($e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function actionDeleteCommon(){
|
|
$param = \Yii::$app->request->post();
|
|
$this->requestValidate($param, [
|
|
['id', 'required'],
|
|
['type', 'required']
|
|
]);
|
|
try {
|
|
switch ($param['type']) {
|
|
case 'west':
|
|
# code...
|
|
$prescription = PrescriptionWest::findOne([
|
|
'id' => $param['id'],
|
|
'su_id' => \Yii::$app->user->identity->id,
|
|
'type' => 2
|
|
]);
|
|
break;
|
|
case 'chinese':
|
|
# code...
|
|
$prescription = PrescriptionChinese::findOne([
|
|
'id' => $param['id'],
|
|
'su_id' => \Yii::$app->user->identity->id,
|
|
'type' => 2
|
|
]);
|
|
break;
|
|
case 'granular':
|
|
# code...
|
|
$prescription = PrescriptionGranular::findOne([
|
|
'id' => $param['id'],
|
|
'su_id' => \Yii::$app->user->identity->id,
|
|
'type' => 2
|
|
]);
|
|
break;
|
|
|
|
default:
|
|
throw new Exception('错误的type');
|
|
break;
|
|
}
|
|
if(!$prescription) throw new Exception('常用方不存在');
|
|
$prescription->delete();
|
|
} catch (\Exception $e) {
|
|
throw $e;
|
|
}
|
|
return ['删除成功'];
|
|
}
|
|
|
|
} |