已提交药房的处方也可作废:先远端撤单再作废
- 洛阳药房:作废时先调用 POST /api/openapi/v1/prescription-orders/{订单号}/cancel 撤单,确认 CANCELLED 后再作废并挂起订单;
远端拒绝(已发货/已扣库存,409)或未确认时不作废并提示原因;撤单写订单日志。撤单后的订单重新审核通过后以新版本提交药房
- 甘草:暂无撤单接口,须先在甘草撤单;甘草回传撤单/驳回(91/92)后可作废
- 远端已确认取消且无在途新版本提交时,订单不再被药房快照锁定
- 列表与详情的 can_void 按「能否自动撤单」判断
- 重新构建管理后台
Co-Authored-By: Claude Opus 5 <[EMAIL]>
This commit is contained in:
co-authored by
Claude Opus 5
parent
b55f30753c
commit
365b16c14d
@@ -268,7 +268,9 @@ namespace {
|
||||
id INTEGER PRIMARY KEY, prescription_id INTEGER, prescription_audit_status INTEGER,
|
||||
prescription_audit_remark TEXT, payment_slip_audit_status INTEGER DEFAULT 0,
|
||||
fulfillment_status INTEGER, delete_time INTEGER, diagnosis_id INTEGER, creator_id INTEGER,
|
||||
reissue_from_prescription_id INTEGER NOT NULL DEFAULT 0,
|
||||
reissue_from_prescription_id INTEGER NOT NULL DEFAULT 0, order_no TEXT DEFAULT "", ship_mode TEXT DEFAULT "gancao",
|
||||
ej_pharmacy_order_no TEXT DEFAULT "", ej_pharmacy_status TEXT DEFAULT "", gancao_reciperl_order_no TEXT DEFAULT "",
|
||||
gancao_order_state INTEGER DEFAULT 0,
|
||||
create_time INTEGER, update_time INTEGER
|
||||
)');
|
||||
Db::execute('CREATE TABLE zyt_tcm_prescription_order_pay_order (id INTEGER PRIMARY KEY, prescription_order_id INTEGER, pay_order_id INTEGER)');
|
||||
@@ -1195,6 +1197,53 @@ namespace {
|
||||
$assert($appointmentPrescription['can_void'] === false && $appointmentPrescription['can_restore_rejected'] === true
|
||||
&& PrescriptionLogic::detail($oldId, 1, $doctor)['can_restore_rejected'] === true,
|
||||
'audit rejection is restorable from detail and appointment');
|
||||
|
||||
// 已提交药房的处方作废:洛阳药房先远端撤单再作废;甘草须对方回传撤单(91/92)后才可作废。
|
||||
$ejCalls = [];
|
||||
$ejReplies = [['http_status' => 409, 'body' => ['code' => 409, 'message' => 'Shipped order cannot be cancelled automatically']],
|
||||
['http_status' => 200, 'body' => ['code' => 0, 'data' => ['status' => 'CANCELLED']]]];
|
||||
$config->set(['enabled' => true, 'base_url' => 'https://ej.invalid', 'app_key' => 'k', 'app_secret' => 's'], 'ej_pharmacy');
|
||||
Container::getInstance()->instance(\app\common\service\pharmacy\EjPharmacyClient::class,
|
||||
new \app\common\service\pharmacy\EjPharmacyClient('https://ej.invalid', 'k', 's',
|
||||
static function (string $method, string $path, string $body) use (&$ejCalls, &$ejReplies): array {
|
||||
$ejCalls[] = [$method, $path, json_decode($body, true)];
|
||||
return array_shift($ejReplies) + ['request_id' => 'fixture'];
|
||||
}));
|
||||
$ejRx = PrescriptionLogic::add($params, 1, $doctor);
|
||||
Db::name('tcm_prescription_order')->insert(['id' => 3001, 'prescription_id' => $ejRx, 'diagnosis_id' => 10,
|
||||
'order_no' => 'PO-EJ-1', 'ship_mode' => 'direct', 'fulfillment_status' => 2, 'prescription_audit_status' => 1,
|
||||
'payment_slip_audit_status' => 1, 'ej_pharmacy_order_no' => 'EJ001', 'ej_pharmacy_status' => 'PENDING_REVIEW']);
|
||||
Db::execute("INSERT INTO zyt_pharmacy_submission_claim VALUES (3, 3001, 1, 'SUCCESS')");
|
||||
$assert(PrescriptionOrderLogic::remoteSnapshotLockErrorForPrescription($ejRx) !== null
|
||||
&& PrescriptionLogic::detail($ejRx, 1, $doctor)['can_void'] === true,
|
||||
'a prescription submitted to the Luoyang pharmacy stays voidable through automatic remote cancellation');
|
||||
$assert(!PrescriptionLogic::void($ejRx, 1, $doctor) && str_contains(PrescriptionLogic::getError(), '已发货或已扣减库存')
|
||||
&& (int) Db::name('tcm_prescription')->where('id', $ejRx)->value('void_status') === 0
|
||||
&& Db::name('tcm_prescription_order')->where('id', 3001)->value('ej_pharmacy_status') === 'PENDING_REVIEW',
|
||||
'a remote refusal to cancel leaves the prescription and order untouched');
|
||||
$assert(PrescriptionLogic::void($ejRx, 1, $doctor), 'void succeeds after the pharmacy confirms cancellation: ' . PrescriptionLogic::getError());
|
||||
$ejOrder = Db::name('tcm_prescription_order')->find(3001);
|
||||
$assert(count($ejCalls) === 2 && $ejCalls[1][0] === 'POST'
|
||||
&& $ejCalls[1][1] === '/api/openapi/v1/prescription-orders/PO-EJ-1/cancel?source_system=zyt&source_revision=1'
|
||||
&& str_contains((string) $ejCalls[1][2]['reason'], '作废')
|
||||
&& $ejOrder['ej_pharmacy_status'] === 'CANCELLED' && (int) $ejOrder['reissue_from_prescription_id'] === $ejRx
|
||||
&& (int) $ejOrder['fulfillment_status'] === 1
|
||||
&& Db::name('tcm_prescription_order_log')->where('prescription_order_id', 3001)->where('action', 'ej_cancel')->count() === 1,
|
||||
'the remote order is cancelled first, then the voided prescription holds the order for reissue');
|
||||
$assert(\app\common\service\pharmacy\PharmacySubmissionClaimService::claimForOrder(3001) !== null
|
||||
&& !\app\common\service\pharmacy\PharmacyRemoteSnapshotPolicy::isLocked($ejOrder, ['status' => 'SUCCESS'])
|
||||
&& \app\common\service\pharmacy\PharmacyRemoteSnapshotPolicy::isLocked($ejOrder, ['status' => 'PENDING']),
|
||||
'a cancelled remote order is mutable until a new revision is in flight');
|
||||
$gancaoRx = PrescriptionLogic::add($params, 1, $doctor);
|
||||
Db::name('tcm_prescription_order')->where('id', 3001)->update(['fulfillment_status' => 4]);
|
||||
Db::name('tcm_prescription_order')->insert(['id' => 3002, 'prescription_id' => $gancaoRx, 'diagnosis_id' => 10,
|
||||
'order_no' => 'PO-GC-1', 'fulfillment_status' => 2, 'gancao_reciperl_order_no' => 'GC001']);
|
||||
$assert(PrescriptionLogic::detail($gancaoRx, 1, $doctor)['can_void'] === false && !PrescriptionLogic::void($gancaoRx, 1, $doctor)
|
||||
&& str_contains(PrescriptionLogic::getError(), '甘草') && count($ejCalls) === 2,
|
||||
'a Gancao submission blocks void until Gancao reports cancellation, without calling the Luoyang API');
|
||||
Db::name('tcm_prescription_order')->where('id', 3002)->update(['gancao_order_state' => 91, 'fulfillment_status' => 4]);
|
||||
$assert(PrescriptionLogic::detail($gancaoRx, 1, $doctor)['can_void'] === true && PrescriptionLogic::void($gancaoRx, 1, $doctor),
|
||||
'a Gancao withdrawal callback (91) makes the prescription voidable');
|
||||
$decimalRow = array_replace($sample, ['dosage_amount' => '10.0000', 'amount' => '20.00']);
|
||||
$floatRow = array_replace($sample, ['dosage_amount' => 10.0, 'amount' => 20]);
|
||||
$assert(Policy::hash($decimalRow) === Policy::hash($floatRow), 'raw DECIMAL and ORM float hashes agree');
|
||||
|
||||
Reference in New Issue
Block a user