处方作废不再受签署/审核/订单状态限制,作废后订单随重新开方自动关联;签署原文去掉辅方方名;出丸显示辅方克数;查看处方可下载 CA 原件或药房联/处方联
- 作废:药师签署、审核通过、已有业务订单后均可作废(仍需「作废」权限;已提交药房的订单须先远端取消)。 作废时关联的待审核/履约中订单处方审核重置为待审核(履约中退回待审核,支付审核保留), 同诊单重新开方后自动改关联到新处方并写订单日志;已发货/已完成订单按原处方留档。 迁移 2026_11_30_prescription_order_reissue.sql 新增 reissue_from_prescription_id - 签署 PDF 不再写入「辅方方名」 - 出丸:有辅方药材时显示「主方 X克,辅方 Y克」(管理后台与桌面端) - 已开处方「查看处方」下载改为下拉:CA 签署处方 PDF、药房联 PDF、处方联 PDF(A4,按当前笺面样式) - 重新构建管理后台 Co-Authored-By: Claude Opus 5 <[EMAIL]>
This commit is contained in:
co-authored by
Claude Opus 5
parent
0eeb572f0f
commit
b55f30753c
@@ -325,7 +325,6 @@ class PrescriptionLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
$rid = (int) $item['id'];
|
||||
$item['can_void'] = empty($item['void_status'])
|
||||
&& PrescriptionLogic::hasVoidAccess($item, $this->adminId, $this->adminInfo, $voidAccess)
|
||||
&& !PrescriptionLogic::hasBlockingVoidOrder($item, $ordersByPrescription[$rid] ?? [])
|
||||
&& (empty($ordersByPrescription[$rid]) || PrescriptionOrderLogic::remoteSnapshotLockErrorForPrescription($rid) === null);
|
||||
$item['can_restore_rejected'] = PrescriptionLogic::canRestoreRejected($item);
|
||||
$item = PrescriptionLogic::withSigningStatus($item, $this->adminId, $maySubmit);
|
||||
|
||||
@@ -248,7 +248,8 @@ class PrescriptionLogic
|
||||
!in_array((int) $order['fulfillment_status'], PrescriptionOrder::RELEASED_PRESCRIPTION_STATUSES, true)) !== [];
|
||||
$row['has_prescription_order'] = $hasBizOrder ? 1 : 0;
|
||||
$row['can_restore_rejected'] = self::canRestoreRejected($row);
|
||||
$row['can_void'] = empty($row['void_status']) && !self::hasBlockingVoidOrder($row, $orders)
|
||||
// 作废不再受审核、签署或订单状态限制;仅已提交药房的订单(须先远端取消)会阻止作废。
|
||||
$row['can_void'] = empty($row['void_status'])
|
||||
&& self::hasVoidAccess(
|
||||
$row,
|
||||
$viewerAdminId,
|
||||
@@ -260,24 +261,6 @@ class PrescriptionLogic
|
||||
return $row;
|
||||
}
|
||||
|
||||
/** Pending prescriptions can be voided while any active order is still waiting for both reviews. */
|
||||
public static function hasBlockingVoidOrder(array $prescription, array $orders): bool
|
||||
{
|
||||
foreach ($orders as $order) {
|
||||
$fulfillmentStatus = (int) ($order['fulfillment_status'] ?? -1);
|
||||
if (in_array($fulfillmentStatus, PrescriptionOrder::RELEASED_PRESCRIPTION_STATUSES, true)) {
|
||||
continue;
|
||||
}
|
||||
if ($fulfillmentStatus !== 1
|
||||
|| !in_array($order['prescription_audit_status'] ?? null, [0, '0'], true)
|
||||
|| !in_array($order['payment_slip_audit_status'] ?? null, [0, '0'], true)
|
||||
|| !PrescriptionEsignPolicy::isPendingReview($prescription)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static function generateSn(): string
|
||||
{
|
||||
return 'RX' . date('Ymd') . str_pad((string)mt_rand(1, 9999), 4, '0', STR_PAD_LEFT);
|
||||
@@ -539,7 +522,8 @@ class PrescriptionLogic
|
||||
$data['esign_status'] = 'pending';
|
||||
}
|
||||
try {
|
||||
return Db::transaction(static function () use ($data, $params, $adminId, $adminInfo, $diagnosisIdRule, $dateYmd): int {
|
||||
$relinkedOrderIds = [];
|
||||
$newId = Db::transaction(static function () use ($data, $params, $adminId, $adminInfo, $diagnosisIdRule, $dateYmd, &$relinkedOrderIds): int {
|
||||
$replayed = PrescriptionAiRequest::replay($params, $adminId, true);
|
||||
if ($replayed !== null) {
|
||||
return $replayed;
|
||||
@@ -553,6 +537,8 @@ class PrescriptionLogic
|
||||
$prescription = new Prescription();
|
||||
$prescription->save($data);
|
||||
$id = (int) $prescription->id;
|
||||
// 原处方作废后挂起的业务订单,随本次重新开方自动关联到新处方。
|
||||
$relinkedOrderIds = PrescriptionOrderLogic::relinkOrdersToReissue($diagnosisIdRule, $id, $data['sn'], $adminId, $adminInfo);
|
||||
// Read database defaults and JSON exactly as workers will fingerprint them.
|
||||
$saved = Db::name('tcm_prescription')->where('id', $id)->find();
|
||||
self::scheduleAiSaved($saved, $adminId, $adminInfo,
|
||||
@@ -560,6 +546,10 @@ class PrescriptionLogic
|
||||
PrescriptionAiRequest::complete($params, $adminId, $id);
|
||||
return $id;
|
||||
});
|
||||
foreach ($relinkedOrderIds as $orderId) {
|
||||
\app\common\service\tcm\RevisitDueHook::onOrderChanged($diagnosisIdRule, $orderId, 'reissue');
|
||||
}
|
||||
return $newId;
|
||||
} catch (\Throwable $e) {
|
||||
self::setError($e instanceof \DomainException ? $e->getMessage() : '处方保存失败,请稍后重试');
|
||||
return null;
|
||||
@@ -1456,17 +1446,14 @@ class PrescriptionLogic
|
||||
self::setError('处方审核状态已变化,请刷新列表后查看');
|
||||
return false;
|
||||
}
|
||||
if (self::hasBlockingVoidOrder($row->toArray(), $orders)) {
|
||||
self::setError('关联业务订单的审核或履约状态不允许作废此处方');
|
||||
|
||||
return false;
|
||||
}
|
||||
$row->void_status = 1;
|
||||
$row->void_time = time();
|
||||
$row->void_by = $adminId;
|
||||
$row->void_by_name = (string) ($adminInfo['name'] ?? '');
|
||||
$saved = (bool) $row->save();
|
||||
if ($saved) {
|
||||
// 关联订单挂起,待同诊单重新开方后自动关联新处方。
|
||||
PrescriptionOrderLogic::holdOrdersForReissue($row->toArray(), $orders, $adminId, $adminInfo);
|
||||
PrescriptionAiStore::invalidate($id, 'voided');
|
||||
}
|
||||
return $saved;
|
||||
|
||||
@@ -5886,6 +5886,66 @@ class PrescriptionOrderLogic
|
||||
];
|
||||
}
|
||||
|
||||
/** 处方作废时可随重新开方迁移的订单状态:待审核(1)、履约中(2);已发货/已完成的订单按原处方留档。 */
|
||||
private const REISSUE_FOLLOW_STATUSES = [1, 2];
|
||||
|
||||
/**
|
||||
* 处方作废后挂起关联的业务订单:处方审核退回待审核、履约中退回待审核,等待同诊单重新开方后自动关联新处方。
|
||||
* 由 PrescriptionLogic::void 在处方与订单的同一锁内调用。
|
||||
*
|
||||
* @param array<int, array<string, mixed>> $orders 已加锁的订单行
|
||||
*/
|
||||
public static function holdOrdersForReissue(array $voided, array $orders, int $adminId, array $adminInfo): void
|
||||
{
|
||||
$sn = (string) ($voided['sn'] ?? '');
|
||||
foreach ($orders as $order) {
|
||||
if (!in_array((int) ($order['fulfillment_status'] ?? 0), self::REISSUE_FOLLOW_STATUSES, true)) {
|
||||
continue;
|
||||
}
|
||||
$updates = ['reissue_from_prescription_id' => (int) $voided['id'],
|
||||
'prescription_audit_status' => 0, 'prescription_audit_remark' => '', 'update_time' => time()];
|
||||
if ((int) $order['fulfillment_status'] === 2) {
|
||||
$updates['fulfillment_status'] = 1;
|
||||
}
|
||||
Db::name('tcm_prescription_order')->where('id', (int) $order['id'])->update($updates);
|
||||
self::writeLog((int) $order['id'], $adminId, $adminInfo, 'rx_void_hold',
|
||||
"处方 {$sn} 已作废,订单处方审核重置为待审核;同诊单重新开方后将自动关联新处方", true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新处方保存后,把同诊单中因处方作废而挂起的订单关联到新处方。在开方事务内调用。
|
||||
*
|
||||
* @return int[] 已改关联的订单 ID
|
||||
*/
|
||||
public static function relinkOrdersToReissue(int $diagnosisId, int $prescriptionId, string $sn, int $adminId, array $adminInfo): array
|
||||
{
|
||||
if ($diagnosisId <= 0) {
|
||||
return [];
|
||||
}
|
||||
$orders = Db::name('tcm_prescription_order')->alias('o')
|
||||
->join([Db::name('tcm_prescription')->getTable() => 'p'], 'p.id = o.prescription_id')
|
||||
->where('o.diagnosis_id', $diagnosisId)->where('o.reissue_from_prescription_id', '>', 0)
|
||||
->whereColumn('o.reissue_from_prescription_id', '=', 'o.prescription_id')
|
||||
->where('p.void_status', 1)->whereNull('o.delete_time')
|
||||
->whereNotIn('o.fulfillment_status', PrescriptionOrder::RELEASED_PRESCRIPTION_STATUSES)
|
||||
->field('o.*,p.sn AS voided_sn')->order('o.id')->lock(true)->select()->toArray();
|
||||
$relinked = [];
|
||||
foreach ($orders as $order) {
|
||||
if (PharmacyRemoteSnapshotPolicy::isLocked($order, PharmacySubmissionClaimService::claimForOrder((int) $order['id']))) {
|
||||
continue; // 已提交药房的订单不改处方,须先完成远端取消。
|
||||
}
|
||||
Db::name('tcm_prescription_order')->where('id', (int) $order['id'])->update([
|
||||
'prescription_id' => $prescriptionId, 'reissue_from_prescription_id' => 0,
|
||||
'prescription_audit_status' => 0, 'prescription_audit_remark' => '', 'update_time' => time(),
|
||||
]);
|
||||
self::writeLog((int) $order['id'], $adminId, $adminInfo, 'rx_reissue_link',
|
||||
"重新开方 {$sn},自动关联新处方(原处方 {$order['voided_sn']} 已作废)", true);
|
||||
$relinked[] = (int) $order['id'];
|
||||
}
|
||||
return $relinked;
|
||||
}
|
||||
|
||||
private static function writeLog(
|
||||
int $orderId,
|
||||
int $adminId,
|
||||
|
||||
Reference in New Issue
Block a user