Merge branch 'long-0507'

This commit is contained in:
2026-05-07 11:59:45 +08:00
8 changed files with 101 additions and 13 deletions
@@ -152,6 +152,19 @@ class PrescriptionLogic
return $ts ? date('Y-m-d', $ts) : date('Y-m-d');
}
private static function normalizeDosageBagCount($raw): int
{
$count = (int) $raw;
if ($count < 1) {
return 1;
}
if ($count > 5) {
return 5;
}
return $count;
}
/**
* 同一诊单、同一开方人、同一处方日期:仅允许一张「未作废」的未删除记录;已作废的可再新开一张。
*
@@ -230,6 +243,7 @@ class PrescriptionLogic
'prescription_type' => $params['prescription_type'] ?? '浓缩水丸',
'dosage_amount' => isset($params['dosage_amount']) ? (float)$params['dosage_amount'] : null,
'dosage_unit' => $params['dosage_unit'] ?? '',
'dosage_bag_count' => self::normalizeDosageBagCount($params['dosage_bag_count'] ?? 1),
'need_decoction' => (int)($params['need_decoction'] ?? 0),
'bags_per_dose' => isset($params['bags_per_dose']) ? (int)$params['bags_per_dose'] : 1,
'diagnosis_id' => (int)($params['diagnosis_id'] ?? 0),
@@ -359,6 +373,7 @@ class PrescriptionLogic
'prescription_type' => $params['prescription_type'] ?? $prescription->prescription_type,
'dosage_amount' => isset($params['dosage_amount']) ? (float)$params['dosage_amount'] : $prescription->dosage_amount,
'dosage_unit' => $params['dosage_unit'] ?? $prescription->dosage_unit,
'dosage_bag_count' => self::normalizeDosageBagCount($params['dosage_bag_count'] ?? ($prescription->dosage_bag_count ?? 1)),
'need_decoction' => isset($params['need_decoction']) ? (int)$params['need_decoction'] : (int)($prescription->need_decoction ?? 0),
'bags_per_dose' => isset($params['bags_per_dose']) ? (int)$params['bags_per_dose'] : (int)($prescription->bags_per_dose ?? 1),
'patient_name' => $params['patient_name'] ?? $prescription->patient_name,
@@ -811,6 +826,7 @@ class PrescriptionLogic
'prescription_type' => '浓缩水丸',
'dosage_amount' => 1.0,
'dosage_unit' => 'g',
'dosage_bag_count' => 1,
'need_decoction' => 0,
'bags_per_dose' => 1,
'diagnosis_id' => $diagnosisId,
@@ -12,6 +12,7 @@ class PrescriptionValidate extends BaseValidate
'id' => 'require',
'diagnosis_id' => 'number',
'appointment_id' => 'number',
'dosage_bag_count' => 'integer|between:1,5',
'patient_name' => 'require',
'clinical_diagnosis' => 'require',
'herbs' => 'require|array',
@@ -20,6 +21,8 @@ class PrescriptionValidate extends BaseValidate
];
protected $message = [
'dosage_bag_count.integer' => '用量袋数必须为整数',
'dosage_bag_count.between' => '用量袋数必须在1到5袋之间',
'patient_name.require' => '患者姓名不能为空',
'clinical_diagnosis.require' => '临床诊断不能为空',
'herbs.require' => '请添加中药',
@@ -28,7 +31,7 @@ class PrescriptionValidate extends BaseValidate
public function sceneAdd()
{
return $this->only([
'prescription_type', 'dosage_amount', 'dosage_unit', 'need_decoction', 'bags_per_dose',
'prescription_type', 'dosage_amount', 'dosage_unit', 'dosage_bag_count', 'need_decoction', 'bags_per_dose',
'patient_name', 'gender', 'age',
'visit_no', 'prescription_date', 'tongue', 'tongue_image', 'pulse',
'pulse_condition', 'clinical_diagnosis', 'herbs', 'dose_count', 'dose_unit',
@@ -41,7 +44,7 @@ class PrescriptionValidate extends BaseValidate
public function sceneEdit()
{
return $this->only([
'id', 'prescription_type', 'dosage_amount', 'dosage_unit', 'need_decoction', 'bags_per_dose',
'id', 'prescription_type', 'dosage_amount', 'dosage_unit', 'dosage_bag_count', 'need_decoction', 'bags_per_dose',
'patient_name', 'gender', 'age',
'visit_no', 'prescription_date', 'tongue', 'tongue_image', 'pulse',
'pulse_condition', 'clinical_diagnosis', 'herbs', 'dose_count', 'dose_unit',
@@ -24,6 +24,7 @@ class Prescription extends BaseModel
// 字段类型转换
protected $type = [
'dosage_amount' => 'float',
'dosage_bag_count' => 'integer',
'need_decoction' => 'integer',
];
@@ -0,0 +1,3 @@
-- 添加处方用量袋数字段(浓缩水丸等开方场景,1-5袋)
ALTER TABLE `zyt_tcm_prescription`
ADD COLUMN `dosage_bag_count` TINYINT UNSIGNED NOT NULL DEFAULT 1 COMMENT '用量袋数(1-5袋)' AFTER `dosage_unit`;