From e6b23758f80da296190905b44f31721585bca1ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=90=A6?= Date: Fri, 22 May 2026 10:24:51 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=A4=84=E6=96=B9=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/services/PrescriptionService.php | 94 ++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 3 deletions(-) diff --git a/common/services/PrescriptionService.php b/common/services/PrescriptionService.php index 64bf604..ce740a5 100644 --- a/common/services/PrescriptionService.php +++ b/common/services/PrescriptionService.php @@ -12,6 +12,7 @@ use common\models\oldDb\ProductOrder; use common\models\oldDb\Store; use common\modelsgii\oldDb\DoctorIdentity; use Exception; +use Yii; use yii\helpers\Json; class PrescriptionService{ @@ -26,11 +27,11 @@ class PrescriptionService{ } if($prescriptionNo){ - $prescription = Prescription::find()->select('id,store_id,prescription_no,online_prescription_no,is_online,prescription_type,type,is_dispense,valid_hours,content,doctor_order,status,pharmacist_id,su_id,process_rule_id,process_rule,process_rule_note,doctor_second_sign')->where([ + $prescription = Prescription::find()->select('id,store_id,prescription_no,online_prescription_no,is_online,prescription_type,type,is_dispense,valid_hours,content,doctor_order,status,pharmacist_id,su_id,process_rule_id,process_rule,process_rule_note,doctor_second_sign,created_at')->where([ 'prescription_no' => $prescriptionNo ])->with('pharmacistInfo')->asArray()->one(); } else { - $prescription = Prescription::find()->select('id,store_id,prescription_no,online_prescription_no,is_online,prescription_type,type,is_dispense,valid_hours,content,doctor_order,status,pharmacist_id,su_id,process_rule_id,process_rule,process_rule_note,doctor_second_sign')->where([ + $prescription = Prescription::find()->select('id,store_id,prescription_no,online_prescription_no,is_online,prescription_type,type,is_dispense,valid_hours,content,doctor_order,status,pharmacist_id,su_id,process_rule_id,process_rule,process_rule_note,doctor_second_sign,created_at')->where([ 'id' => $presciptionId ])->with('pharmacistInfo')->asArray()->one(); } @@ -59,10 +60,97 @@ class PrescriptionService{ $prescription['Pharmacist_sign_image']=$PharmacistIdentity['sign_image']?? ''; $prescription['Pharmacist_sign_type']=$PharmacistIdentity['sign_type']?? ''; + $prescription['online_tcm_print'] = $this->buildOnlineTcmPrint($prescription); + return $prescription; } catch (Exception $e) { throw new Exception($e->getMessage(). json_encode($e->getLine())); } } -} \ No newline at end of file + /** + * 在线中药处方笺:监管中医术语展示(与 xk-api online_tcm_print 一致) + * + * @param array $prescription + * @return array + */ + private function buildOnlineTcmPrint(array $prescription): array + { + $ptype = (int) ($prescription['prescription_type'] ?? 0); + $isOnline = (int) ($prescription['is_online'] ?? 0); + if ($ptype !== 1 || !in_array($isOnline, [1, 2, 3], true)) { + return ['show' => false]; + } + + $prescriptionId = (int) ($prescription['id'] ?? 0); + if ($prescriptionId <= 0) { + return ['show' => false]; + } + + try { + $syndrome = $this->fetchTcmTermNames( + 'prescription_disease', + 'disease_id', + 'traditional_chinese_medicine_diseases', + $prescriptionId + ); + $method = $this->fetchTcmTermNames( + 'prescription_method', + 'method_id', + 'traditional_chinese_medicine_method', + $prescriptionId + ); + $disease = $this->fetchTcmTermNames( + 'prescription_syndrome', + 'syndrome_id', + 'traditional_chinese_medicine_syndrome', + $prescriptionId + ); + + if ($syndrome === '' && $method === '' && $disease === '') { + return ['show' => false, 'a' => 1]; + } + + $result = ['show' => true]; + if ($syndrome !== '') { + $result['tcm_syndrome'] = $syndrome; + } + if ($method !== '') { + $result['tcm_method'] = $method; + } + if ($disease !== '') { + $result['tcm_disease'] = $disease; + } + + return $result; + } catch (\Throwable $e) { + Yii::warning('online_tcm_print query failed: '.$e->getMessage(), __METHOD__); + + return ['show' => false, 'a' => $e->getMessage()]; + } + } + + private function fetchTcmTermNames( + string $linkTable, + string $linkColumn, + string $termTable, + int $prescriptionId + ): string { + if (! Yii::$app->has('new_db')) { + return ''; + } + + $db = Yii::$app->new_db; + $rows = $db->createCommand( + "SELECT t.name FROM {{%{$linkTable}}} l + INNER JOIN {{%{$termTable}}} t ON t.id = l.{$linkColumn} + WHERE l.prescription_id = :pid", + [':pid' => $prescriptionId] + )->queryColumn(); + + $names = array_filter(array_map('trim', $rows)); + + return implode('、', $names); + } + +}