From e52249599376f1a3a1c689658a31fe158291feec Mon Sep 17 00:00:00 2001 From: lq Date: Thu, 26 Sep 2024 12:49:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8C=BB=E7=94=9F=E7=AB=AF?= =?UTF-8?q?=E5=A4=84=E6=96=B9=E5=88=97=E8=A1=A8=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1/controllers/ExamineController.php | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/service/modules/v1/controllers/ExamineController.php b/service/modules/v1/controllers/ExamineController.php index b56ac93..e69cc51 100644 --- a/service/modules/v1/controllers/ExamineController.php +++ b/service/modules/v1/controllers/ExamineController.php @@ -95,29 +95,42 @@ class ExamineController extends BasePharmacistController */ public function actionListByDoctor() { + // 查询处方信息,包括患者详情,并按创建时间倒序排列 $prescription = Prescription::find()->where(['up_id' => \Yii::$app->request->get('up_id'), 'store_id' => \Yii::$app->request->get('store_id')])->with('patients')->orderBy('created_at DESC')->asArray()->all(); + // 若未找到任何处方信息,则抛出异常 if (!$prescription) { throw new Exception('暂无数据'); } + // 遍历处方列表,处理每个处方的内容 foreach ($prescription as &$v) { + // 解析处方内容中的JSON数据 $tmp = json_decode($v['content'], true); + // 提取并赋值处方类别 $v['p_category'] = $tmp['category']; - $v['p_repice'] = $tmp['repice']; + // 初始化处方药品列表 $v['p_drugs'] = []; + // 遍历处方明细中的每种药品信息 foreach ($tmp['repice'] as $repiceInfo) { + // 解析药品内容中的JSON数据 $drugJson = json_decode($repiceInfo['content'], true); - if (!array_key_exists('drug_name', $drugJson)) { - $v['p_drugs'] = array_column($drugJson, 'name'); - } else { + // 若药品信息中包含名称,则添加到处方药品列表中 + if (array_key_exists('name', $drugJson)) { + $v['p_drugs'][] = array_column($drugJson, 'name'); + } + // 若药品信息中包含药品名称键,则直接添加药品名称到列表 + if (array_key_exists('drug_name', $drugJson)){ $v['p_drugs'][] = $drugJson['drug_name']; } - } -// $v['p_drug_name'] = json_decode($tmp['repice'][0]['content'])['drug_name']; + // 移除重复的药品名称,并计算唯一药品的数量 + $v['p_drugs'] = array_unique($v['p_drugs']); + $v['drugs_count'] = count($v['p_drugs']); + // 格式化创建时间,若无创建时间则设为空字符串 $v['created_at'] = !empty($v['created_at']) ? date('Y-m-d H:i:s', $v['created_at']) : ''; } + // 返回处理后的处方列表 return $prescription; }