签署原文中金额为 0、辅方不代煎时不再写入
- 金额(元)为 0 / 0.00 时省略,非 0 照常写入 - 辅方代煎为 0 时省略;代煎时显示「是」(与主方代煎一致),不再显示 0/1 Co-Authored-By: Claude Opus 5 (1M context) <[EMAIL]>
This commit is contained in:
co-authored by
Claude Opus 5 (1M context)
parent
c22be5d586
commit
7c916d8053
@@ -65,7 +65,10 @@ final class PrescriptionPdf
|
||||
$add($label, $row[$key]);
|
||||
}
|
||||
$add('代煎', $row['need_decoction'] === '1' ? '是' : '否');
|
||||
$add('金额(元)', $row['amount']);
|
||||
// 金额为 0(含 0.00)时不写入签署原文。
|
||||
if (is_numeric($row['amount']) && (float) $row['amount'] != 0.0) {
|
||||
$add('金额(元)', $row['amount']);
|
||||
}
|
||||
// 开方表单总会带一份默认辅方用法;只有药品里确有辅方(与笺面 formula_type 判定一致)才写入。
|
||||
$hasAux = array_filter((array) $row['herbs'], static fn ($herb): bool =>
|
||||
is_array($herb) && ($herb['formula_type'] ?? '') === '辅方') !== [];
|
||||
@@ -76,6 +79,13 @@ final class PrescriptionPdf
|
||||
$label = ['dosage_amount' => '单次用量', 'dosage_bag_count' => '单次袋数', 'need_decoction' => '代煎',
|
||||
'times_per_day' => '每日次数', 'usage_days' => '服用天数',
|
||||
'prescription_name' => '方名'][$key] ?? $key;
|
||||
if ($key === 'need_decoction') {
|
||||
// 辅方不代煎(0)时不写;代煎时与主方一样显示「是」。
|
||||
if ((int) $value === 0) {
|
||||
continue;
|
||||
}
|
||||
$value = '是';
|
||||
}
|
||||
$add('辅方' . $label, $value);
|
||||
}
|
||||
$pages = array_chunk($lines, 33);
|
||||
|
||||
@@ -1204,6 +1204,17 @@ namespace {
|
||||
$mainOnly = PrescriptionPdf::render(array_replace($sample, ['aux_usage' => $auxUsage,
|
||||
'herbs' => array_map(static fn (array $herb): array => $herb + ['formula_type' => '主方'], $sampleHerbs)]), 'sandbox');
|
||||
$assert(!str_contains($mainOnly, $pdfText('辅方')), 'a prescription without auxiliary herbs omits the default auxiliary usage');
|
||||
$auxHerbs = array_merge($sampleHerbs, [['name' => '虚构辅方药', 'dosage' => 6, 'unit' => 'g', 'formula_type' => '辅方']]);
|
||||
foreach (['0', '0.00', 0] as $zero) {
|
||||
$zeroPdf = PrescriptionPdf::render(array_replace($sample, ['amount' => $zero, 'herbs' => $auxHerbs,
|
||||
'aux_usage' => ['need_decoction' => 0, 'usage_days' => 7]]), 'sandbox');
|
||||
$assert(!str_contains($zeroPdf, $pdfText('金额(元)')) && !str_contains($zeroPdf, $pdfText('辅方代煎'))
|
||||
&& str_contains($zeroPdf, $pdfText('辅方服用天数:7')), 'zero amount and no auxiliary decoction are omitted: ' . var_export($zero, true));
|
||||
}
|
||||
$paidPdf = PrescriptionPdf::render(array_replace($sample, ['amount' => '18.50', 'herbs' => $auxHerbs,
|
||||
'aux_usage' => ['need_decoction' => 1]]), 'sandbox');
|
||||
$assert(str_contains($paidPdf, $pdfText('金额(元):18.5')) && str_contains($paidPdf, $pdfText('辅方代煎:是')),
|
||||
'a non-zero amount and auxiliary decoction are still disclosed');
|
||||
$manyHerbs = [];
|
||||
for ($i = 1; $i <= 65; ++$i) { $manyHerbs[] = ['name' => '虚构药品' . $i, 'dosage' => $i, 'unit' => 'g']; }
|
||||
$largePdf = PrescriptionPdf::render(array_replace($sample, ['herbs' => $manyHerbs, 'amount' => '18.50']), 'sandbox');
|
||||
|
||||
Reference in New Issue
Block a user