优化医生端处方列表数据
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user