功能性

This commit is contained in:
Your Name
2026-11-27 17:25:53 +08:00
parent 954e6f00d0
commit 82a91858f9
7 changed files with 217 additions and 29 deletions
@@ -625,18 +625,18 @@ final class PrescriptionEsignService
};
[$pdf, $issuedAt] = Db::transaction(static function () use ($id, $lockSigningWork): array {
[$currentRow, $current] = $lockSigningWork();
$pdf = self::readPdf($current['source_path'], $current['source_hash']);
$issuedAt = (int) ($current['issued_at'] ?? 0);
if ($issuedAt > 0) {
$archivedSource = self::readPdf($current['source_path'], $current['source_hash']);
// Reuse the issuance time on retries and apply the current disclosure rules before sending.
$issuedAt = (int) ($current['issued_at'] ?? 0) ?: time();
$pdf = PrescriptionPdf::render($currentRow, $current['environment'], $issuedAt, !empty($current['review_required']));
if ($pdf === $archivedSource) {
return [$pdf, $issuedAt];
}
// This is reached only after the doctor confirms signing and their willingness is verified.
$issuedAt = time();
$pdf = PrescriptionPdf::render($currentRow, $current['environment'], $issuedAt, !empty($current['review_required']));
$path = $id . '-' . $current['snapshot_hash'] . '/source-issued.pdf';
$sourceHash = hash('sha256', $pdf);
$path = $id . '-' . $current['snapshot_hash'] . '/source-issued-' . $sourceHash . '.pdf';
self::writePdf($path, $pdf);
Db::name('prescription_esign')->where('prescription_id', $id)->update([
'issued_at' => $issuedAt, 'source_hash' => hash('sha256', $pdf), 'source_path' => $path,
'issued_at' => $issuedAt, 'source_hash' => $sourceHash, 'source_path' => $path,
]);
return [$pdf, $issuedAt];
});
@@ -1149,7 +1149,7 @@ final class PrescriptionEsignService
private static function filePath(string $relative): string
{
if (!preg_match('#^\d+-[a-f0-9]{64}/(?:(?:source(?:-issued)?|signed|review-signed)\.pdf|review-seal-[a-f0-9]{64}\.png)$#D', $relative)) {
if (!preg_match('#^\d+-[a-f0-9]{64}/(?:(?:source(?:-issued(?:-[a-f0-9]{64})?)?|signed|review-signed)\.pdf|review-seal-[a-f0-9]{64}\.png)$#D', $relative)) {
throw new DomainException('签署文件引用无效');
}
return rtrim((string) Config::get('esign.storage_path', root_path() . 'storage/esign'), '/\\') . DIRECTORY_SEPARATOR . $relative;
@@ -43,7 +43,6 @@ final class PrescriptionPdf
$add('舌象', $row['tongue']);
$add('脉象', $row['pulse']);
$add('脉诊补充', $row['pulse_condition']);
$add('方名', $row['prescription_name']);
$add('剂型', $row['prescription_type']);
$herbLabels = ['name' => '药名', 'dosage' => '用量', 'unit' => '单位', 'remark' => '备注',
'usage' => '煎法', 'usage_method' => '煎法', 'method' => '煎法', 'group' => '组别',
@@ -59,8 +58,7 @@ final class PrescriptionPdf
$add('药品 ' . ($index + 1), implode(' / ', $parts));
}
foreach ([
'dose_count' => '总剂数', 'dose_unit' => '剂数单位', 'dosage_amount' => '单次用量',
'dosage_unit' => '用量单位', 'dosage_bag_count' => '单次袋数', 'bags_per_dose' => '每剂袋数',
'dosage_amount' => '单次用量', 'dosage_unit' => '用量单位', 'dosage_bag_count' => '单次袋数',
'usage_days' => '服用天数', 'times_per_day' => '每日次数', 'usage_instruction' => '服用说明',
'usage_time' => '服药时间', 'usage_way' => '服用方式', 'dietary_taboo' => '忌口', 'usage_notes' => '医嘱',
] as $key => $label) {
@@ -69,8 +67,11 @@ final class PrescriptionPdf
$add('代煎', $row['need_decoction'] === '1' ? '是' : '否');
$add('金额(元)', $row['amount']);
foreach ((array) $row['aux_usage'] as $key => $value) {
if ($key === 'bags_per_dose') {
continue;
}
$label = ['dosage_amount' => '单次用量', 'dosage_bag_count' => '单次袋数', 'need_decoction' => '代煎',
'bags_per_dose' => '每剂袋数', 'times_per_day' => '每日次数', 'usage_days' => '服用天数',
'times_per_day' => '每日次数', 'usage_days' => '服用天数',
'prescription_name' => '方名'][$key] ?? $key;
$add('辅方' . $label, $value);
}