1. 处方详情

This commit is contained in:
李琦
2026-05-22 10:24:51 +08:00
parent e033bd787f
commit e6b23758f8

View File

@@ -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()));
}
}
}
/**
* 在线中药处方笺:监管中医术语展示(与 xk-api online_tcm_print 一致)
*
* @param array<string, mixed> $prescription
* @return array<string, mixed>
*/
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);
}
}