功能性
This commit is contained in:
@@ -451,6 +451,35 @@ namespace {
|
||||
$assert($retry['issued_at'] === $frozen['issued_at'] && $retry['source_hash'] === $frozen['source_hash'],
|
||||
'retry keeps the exact issuance time and PDF');
|
||||
|
||||
$pdfText = static fn (string $text): string => bin2hex(mb_convert_encoding($text, 'UTF-16BE', 'UTF-8'));
|
||||
$legacyRetryId = 8888;
|
||||
$new($legacyRetryId);
|
||||
Db::name('tcm_prescription')->where('id', $legacyRetryId)->update(['prescription_type' => '浓缩水丸', 'dose_count' => 543]);
|
||||
Service::start($legacyRetryId, 1, $root);
|
||||
Fake::$signRejection = 'PROVIDER_50001';
|
||||
$assert(Service::complete($legacyRetryId, 1, $root)['status'] === 'failed', 'fixture permits a fresh sign after a definite rejection');
|
||||
Fake::$signRejection = null;
|
||||
$cached = Db::name('prescription_esign')->where('prescription_id', $legacyRetryId)->find();
|
||||
$row = Db::name('tcm_prescription')->where('id', $legacyRetryId)->find();
|
||||
$expectedSource = PrescriptionPdf::render($row, 'sandbox', (int) $cached['issued_at']);
|
||||
// Equal-length text substitution creates a readable pre-change cached PDF with the excluded field.
|
||||
$oldSource = str_replace($pdfText('剂型:浓缩水丸'), $pdfText('总剂数:543'), $expectedSource, $changed);
|
||||
$assert($changed === 1 && strlen($oldSource) === strlen($expectedSource), 'legacy PDF fixture contains the excluded field');
|
||||
$oldPath = $legacyRetryId . '-' . $cached['snapshot_hash'] . '/source-issued.pdf';
|
||||
Service::writePdf($oldPath, $oldSource);
|
||||
Db::name('prescription_esign')->where('prescription_id', $legacyRetryId)->update([
|
||||
'source_path' => $oldPath, 'source_hash' => hash('sha256', $oldSource),
|
||||
]);
|
||||
Service::start($legacyRetryId, 1, $root);
|
||||
$assert(Service::complete($legacyRetryId, 1, $root)['status'] === 'signed', 'retry signs a current PDF from the frozen prescription');
|
||||
$reissued = Db::name('prescription_esign')->where('prescription_id', $legacyRetryId)->find();
|
||||
$assert($reissued['issued_at'] === $cached['issued_at'] && $reissued['source_path'] !== $oldPath
|
||||
&& hash_equals($reissued['source_hash'], hash('sha256', $expectedSource))
|
||||
&& Service::readPdf($oldPath, hash('sha256', $oldSource)) === $oldSource, 'retry keeps the old archive and preserves original issuance time');
|
||||
$submitted = Service::readPdf($reissued['signed_path'], $reissued['signed_hash']);
|
||||
$assert(str_starts_with($submitted, $expectedSource) && !str_contains($submitted, $pdfText('总剂数:')),
|
||||
'provider receives the updated PDF rather than the old cached disclosure');
|
||||
|
||||
$new(8); Fake::$startFailure = true;
|
||||
$assert(Service::start(8, 1, $root)['status'] === 'failed', 'identity link outage records failed preparation');
|
||||
Fake::$startFailure = false;
|
||||
@@ -741,7 +770,7 @@ namespace {
|
||||
]);
|
||||
}
|
||||
Db::name('tcm_prescription_order')->insert([
|
||||
'id' => 41, 'prescription_id' => 41, 'prescription_audit_status' => 0, 'fulfillment_status' => 0,
|
||||
'id' => 41, 'prescription_id' => 41, 'prescription_audit_status' => 0, 'fulfillment_status' => 1,
|
||||
]);
|
||||
$disabled = Service::status(41, 1, $root);
|
||||
Service::assertSignedById(41, true);
|
||||
@@ -862,9 +891,33 @@ namespace {
|
||||
$assert(!$pendingList()->lists()[0]['can_review_prescription'],
|
||||
'a row with a stored signed state still needs an intact archive to allow review');
|
||||
file_put_contents($archivePath, $archived);
|
||||
$assert(PrescriptionLogic::audit(41, 'approve', '', 1, $root)
|
||||
Db::name('tcm_prescription_order')->insertAll([
|
||||
['id' => 4101, 'prescription_id' => 41, 'prescription_audit_status' => 2, 'fulfillment_status' => 1],
|
||||
['id' => 4102, 'prescription_id' => 41, 'prescription_audit_status' => 0, 'fulfillment_status' => 4],
|
||||
]);
|
||||
Db::execute("CREATE TRIGGER reject_approval_log BEFORE INSERT ON zyt_tcm_prescription_order_log
|
||||
BEGIN SELECT RAISE(ABORT, 'forced approval log failure'); END");
|
||||
$assert(!PrescriptionLogic::audit(41, 'approve', '测试意见', 1, $root)
|
||||
&& (int) Db::name('tcm_prescription')->where('id', 41)->value('audit_status') === 0
|
||||
&& (int) Db::name('tcm_prescription_order')->where('id', 41)->value('prescription_audit_status') === 0,
|
||||
'approval and order sync both roll back when the order audit log cannot be written');
|
||||
Db::execute('DROP TRIGGER reject_approval_log');
|
||||
$assert(PrescriptionLogic::audit(41, 'approve', '测试意见', 1, $root)
|
||||
&& (int) Db::name('tcm_prescription')->where('id', 41)->value('audit_status') === 1,
|
||||
'the same prescription can be approved after verified eSign');
|
||||
$approvedRx = Db::name('tcm_prescription')->find(41);
|
||||
$approvedOrder = Db::name('tcm_prescription_order')->find(41);
|
||||
$approvalLog = Db::name('tcm_prescription_order_log')->where('prescription_order_id', 41)->find();
|
||||
$assert((int) $approvedOrder['prescription_audit_status'] === 1
|
||||
&& $approvedOrder['prescription_audit_remark'] === '测试意见'
|
||||
&& (int) $approvedOrder['payment_slip_audit_status'] === 0 && (int) $approvedOrder['fulfillment_status'] === 1
|
||||
&& (int) $approvalLog['admin_id'] === (int) $approvedRx['audit_by']
|
||||
&& (int) $approvalLog['create_time'] === (int) $approvedRx['audit_time']
|
||||
&& $approvalLog['action'] === 'audit_rx_approve',
|
||||
'the order records the original approval while payment stays pending');
|
||||
$assert((int) Db::name('tcm_prescription_order')->where('id', 4101)->value('prescription_audit_status') === 2
|
||||
&& (int) Db::name('tcm_prescription_order')->where('id', 4102)->value('prescription_audit_status') === 0,
|
||||
'synchronization preserves rejected and cancelled orders');
|
||||
$assert(PrescriptionLogic::submitForReview(41, 1, $root) === $submission,
|
||||
'a retry after approval still returns the existing upload receipt');
|
||||
$throws(fn () => Service::assertSignedById(41, true), 'sandbox enrollment permits approval but still blocks formal dispensing');
|
||||
@@ -1133,6 +1186,18 @@ namespace {
|
||||
$assert(Policy::hash(Policy::snapshot($decimalRow)) === Policy::hash($decimalRow), 'snapshot hashing is idempotent');
|
||||
$pdf = PrescriptionPdf::render($sample, 'sandbox');
|
||||
$assert($pdf === PrescriptionPdf::render($sample, 'sandbox'), 'deterministic PDF');
|
||||
$pdf = PrescriptionPdf::render(array_replace($sample, [
|
||||
'prescription_name' => '仅内部查看方名', 'dose_count' => 761, 'dose_unit' => '仅内部剂数单位',
|
||||
'bags_per_dose' => 762, 'dosage_bag_count' => 3,
|
||||
'aux_usage' => ['bags_per_dose' => 763, 'dosage_bag_count' => 4, 'usage_days' => 8, 'prescription_name' => '辅助方模板'],
|
||||
]), 'sandbox');
|
||||
foreach (['方名:仅内部查看方名', '总剂数:761', '剂数单位:仅内部剂数单位', '每剂袋数:762', '辅方每剂袋数:763',
|
||||
'辅方bags_per_dose:763'] as $excluded) {
|
||||
$assert(!str_contains($pdf, $pdfText($excluded)), 'signing PDF excludes: ' . $excluded);
|
||||
}
|
||||
foreach (['单次袋数:3', '辅方单次袋数:4', '辅方服用天数:8', '辅方方名:辅助方模板'] as $disclosed) {
|
||||
$assert(str_contains($pdf, $pdfText($disclosed)), 'signing PDF retains distinct field: ' . $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');
|
||||
@@ -1412,6 +1477,21 @@ namespace {
|
||||
'order approval records the actual submitter and synchronizes the prescription without approving payment');
|
||||
$assert(Service::download(84, 22, $auditor) === $combined && count(Fake::$reviewCalls) === 1,
|
||||
'order approval preserves the pharmacist signature and archived original');
|
||||
Db::name('tcm_prescription_order')->insert([
|
||||
'id' => 8401, 'prescription_id' => 84, 'prescription_audit_status' => 0, 'fulfillment_status' => 1,
|
||||
]);
|
||||
file_put_contents($archive, $archivedBytes . 'modified');
|
||||
$assert(!PrescriptionOrderLogic::syncRecordedPrescriptionApproval(8401, true),
|
||||
'historical approval cannot be synchronized with a changed dual-sign PDF');
|
||||
file_put_contents($archive, $archivedBytes);
|
||||
$assert(PrescriptionOrderLogic::syncRecordedPrescriptionApproval(8401)
|
||||
&& (int) Db::name('tcm_prescription_order')->where('id', 8401)->value('prescription_audit_status') === 0
|
||||
&& PrescriptionOrderLogic::syncRecordedPrescriptionApproval(8401, true)
|
||||
&& !PrescriptionOrderLogic::syncRecordedPrescriptionApproval(8401, true),
|
||||
'historical synchronization previews without changes and applies exactly once');
|
||||
$assert((int) Db::name('tcm_prescription_order')->where('id', 8401)->value('prescription_audit_status') === 1
|
||||
&& (int) Db::name('tcm_prescription_order_log')->where('prescription_order_id', 8401)->value('admin_id') === 23,
|
||||
'historical synchronization preserves the original approver, who need not be the signing pharmacist');
|
||||
$signedLog = Service::status(84, 22, $auditor)['signing_log'];
|
||||
$events = array_column($signedLog, null, 'event');
|
||||
$times = array_column($signedLog, 'time');
|
||||
|
||||
@@ -64,6 +64,7 @@ try {
|
||||
id INT PRIMARY KEY AUTO_INCREMENT, diagnosis_id INT DEFAULT 1, gender INT DEFAULT 0,
|
||||
creator_id INT DEFAULT 1, assistant_id INT DEFAULT 0, is_shared INT DEFAULT 0,
|
||||
herbs TEXT, audit_status INT DEFAULT 1, void_status INT DEFAULT 0, visible_role_ids VARCHAR(100) DEFAULT "",
|
||||
audit_by INT NULL, audit_by_name VARCHAR(100), audit_time INT NULL, audit_remark VARCHAR(500),
|
||||
create_time INT DEFAULT 0, update_time INT DEFAULT 0, delete_time INT NULL
|
||||
) ENGINE=InnoDB');
|
||||
$pdo->exec('CREATE TABLE zyt_tcm_diagnosis (id INT PRIMARY KEY, assistant_id INT DEFAULT 0, delete_time INT NULL)');
|
||||
@@ -171,7 +172,7 @@ try {
|
||||
'Final pending audit must reject changed tracking and roll back all form changes');
|
||||
}
|
||||
|
||||
// New orders always start pending, even if clients submit fake audit flags or the source prescription is approved.
|
||||
// Creation trusts recorded approvals, never audit flags supplied by the client or set by a column default.
|
||||
$createParams = static fn (int $rxId): array => [
|
||||
'prescription_id' => $rxId, 'diagnosis_id' => 1, 'recipient_name' => '测试患者',
|
||||
'recipient_phone' => '13000000000', 'shipping_address' => '测试地址', 'fee_type' => 3, 'amount' => 100,
|
||||
@@ -188,6 +189,20 @@ try {
|
||||
&& (int) $out['prescription_audit_status'] === 0 && (int) $out['payment_slip_audit_status'] === 0,
|
||||
'Normal creation must store empty tracking and pending audits');
|
||||
}
|
||||
$rxId = $newRx();
|
||||
$auditTime = time() - 90;
|
||||
Db::name('tcm_prescription')->where('id', $rxId)->update([
|
||||
'herbs' => '[{"name":"测试药材"}]', 'audit_by' => 2, 'audit_by_name' => '实际审核人',
|
||||
'audit_time' => $auditTime, 'audit_remark' => '已开处方审核意见',
|
||||
]);
|
||||
$out = PrescriptionOrderLogic::create($createParams($rxId), 1, $admin);
|
||||
$expect(is_array($out) && (int) $out['prescription_audit_status'] === 1
|
||||
&& (int) $out['payment_slip_audit_status'] === 0 && (int) $out['fulfillment_status'] === 1,
|
||||
'An order created after prescription approval inherits the approval and still needs payment review');
|
||||
$approvalLog = $logs((int) $out['id'])[1];
|
||||
$expect($approvalLog['action'] === 'audit_rx_approve' && (int) $approvalLog['admin_id'] === 2
|
||||
&& (int) $approvalLog['create_time'] === $auditTime,
|
||||
'Inherited approval records the original approver and approval time');
|
||||
|
||||
// Audit revocation must be observed on the next request; historical fulfillment/snapshot data grants no exemption.
|
||||
foreach ([1, 2, 3, 4, 5, 6, 9, 10] as $status) {
|
||||
|
||||
Reference in New Issue
Block a user