桌面端编辑处方可修改手机号、身份证号
- 桌面端开方/编辑处方表单新增「手机号」「身份证号」,已开处方编辑时可修改(姓名仍只读);身份证号本地先校验格式 - 服务端 add/edit 接收 phone(写入处方笺)与 id_card(写回关联诊单,校验格式与重复,按出生日期更新年龄,与处方保存同一事务); 编辑时须可管理该诊单;处方详情仅对可管理诊单的账号返回 patient_id_card Co-Authored-By: Claude Opus 5 <[EMAIL]>
This commit is contained in:
co-authored by
Claude Opus 5
parent
365b16c14d
commit
c6df345138
@@ -534,7 +534,13 @@ class PrescriptionLogic
|
||||
if (!self::assertUniquePrescriptionPerDiagnosisDay($diagnosisIdRule, $adminId, $dateYmd, null)) {
|
||||
throw new \DomainException(self::getError());
|
||||
}
|
||||
// 开方入口已校验诊单管理权限;身份证号写回诊单并按出生日期更新年龄。
|
||||
$age = self::applyPatientIdCard($diagnosisIdRule, (string) ($params['id_card'] ?? ''));
|
||||
if ($age !== null) {
|
||||
$data['age'] = $age;
|
||||
}
|
||||
}
|
||||
$data['phone'] = self::phoneParam($params, (string) $data['phone']);
|
||||
$prescription = new Prescription();
|
||||
$prescription->save($data);
|
||||
$id = (int) $prescription->id;
|
||||
@@ -560,14 +566,14 @@ class PrescriptionLogic
|
||||
/**
|
||||
* 编辑处方
|
||||
*/
|
||||
public static function edit(array $params, int $adminId): bool
|
||||
public static function edit(array $params, int $adminId, array $adminInfo = []): bool
|
||||
{
|
||||
$prescriptionId = (int) ($params['id'] ?? 0);
|
||||
self::setError('');
|
||||
try {
|
||||
return (bool) LockedPharmacySnapshotMutation::executeForPrescription(
|
||||
$prescriptionId,
|
||||
static fn (): bool => self::editLocked($params, $adminId)
|
||||
static fn (): bool => self::editLocked($params, $adminId, $adminInfo)
|
||||
);
|
||||
} catch (\Throwable $exception) {
|
||||
if (self::getError() === '') {
|
||||
@@ -577,7 +583,7 @@ class PrescriptionLogic
|
||||
}
|
||||
}
|
||||
|
||||
private static function editLocked(array $params, int $adminId): bool
|
||||
private static function editLocked(array $params, int $adminId, array $adminInfo = []): bool
|
||||
{
|
||||
try {
|
||||
$prescription = Prescription::where('id', $params['id'])->lock(true)->find();
|
||||
@@ -723,6 +729,17 @@ class PrescriptionLogic
|
||||
$data['void_by'] = null;
|
||||
$data['void_by_name'] = '';
|
||||
}
|
||||
$data['phone'] = self::phoneParam($params, (string) ($prescription->phone ?? ''));
|
||||
if (trim((string) ($params['id_card'] ?? '')) !== '') {
|
||||
if ($newDiagnosisId <= 0 || $adminInfo === []
|
||||
|| !DiagnosisLogic::canManageDiagnosis($newDiagnosisId, $adminId, $adminInfo)) {
|
||||
throw new \DomainException('无权修改该患者身份证号');
|
||||
}
|
||||
$age = self::applyPatientIdCard($newDiagnosisId, (string) $params['id_card']);
|
||||
if ($age !== null) {
|
||||
$data['age'] = $age;
|
||||
}
|
||||
}
|
||||
|
||||
$prescription->save($data);
|
||||
PrescriptionOrderLogic::onConsumerPrescriptionSaved((int) $params['id']);
|
||||
@@ -739,6 +756,41 @@ class PrescriptionLogic
|
||||
}
|
||||
}
|
||||
|
||||
/** 处方笺手机号:传入非空值时采用(最长 20 位),否则保留原值。 */
|
||||
private static function phoneParam(array $params, string $fallback): string
|
||||
{
|
||||
$phone = trim((string) ($params['phone'] ?? ''));
|
||||
if ($phone === '') {
|
||||
return $fallback;
|
||||
}
|
||||
if (strlen($phone) > 20) {
|
||||
throw new \DomainException('手机号过长');
|
||||
}
|
||||
return $phone;
|
||||
}
|
||||
|
||||
/**
|
||||
* 补全/修改患者身份证号:写入诊单并按出生日期更新年龄,返回新年龄;为空或未变更返回 null。
|
||||
* 调用方须已确认当前账号可管理该诊单,并在同一事务内调用。
|
||||
*/
|
||||
private static function applyPatientIdCard(int $diagnosisId, string $idCard): ?int
|
||||
{
|
||||
$idCard = strtoupper(trim($idCard));
|
||||
if ($diagnosisId <= 0 || $idCard === '') {
|
||||
return null;
|
||||
}
|
||||
if (strtoupper(trim((string) Diagnosis::where('id', $diagnosisId)->value('id_card'))) === $idCard) {
|
||||
return null;
|
||||
}
|
||||
if (!empty(DiagnosisLogic::checkIdCard(['id' => $diagnosisId, 'id_card' => $idCard])['exists'])) {
|
||||
throw new \DomainException('该身份证号已登记在其他诊单');
|
||||
}
|
||||
if (!DiagnosisLogic::fillIdCard(['id' => $diagnosisId, 'id_card' => $idCard])) {
|
||||
throw new \DomainException(DiagnosisLogic::getError() ?: '身份证号保存失败');
|
||||
}
|
||||
return (int) Diagnosis::where('id', $diagnosisId)->value('age');
|
||||
}
|
||||
|
||||
private static function scheduleAiSaved(array $saved, int $actor, ?array $info, array $options): void
|
||||
{
|
||||
try {
|
||||
@@ -955,6 +1007,11 @@ class PrescriptionLogic
|
||||
|
||||
$arr = self::withActionAvailability($arr, $viewerAdminId, $viewerAdminInfo);
|
||||
$arr['visible_role_ids'] = self::visibleRoleIdsToArray($arr['visible_role_ids'] ?? '');
|
||||
// 患者身份证号存于诊单,仅对可管理该诊单的账号返回,供编辑处方时修改。
|
||||
$diagnosisId = (int) ($arr['diagnosis_id'] ?? 0);
|
||||
if ($diagnosisId > 0 && DiagnosisLogic::canManageDiagnosis($diagnosisId, $viewerAdminId, $viewerAdminInfo)) {
|
||||
$arr['patient_id_card'] = (string) Diagnosis::where('id', $diagnosisId)->value('id_card');
|
||||
}
|
||||
|
||||
/**
|
||||
* 处方笺展示所需的"收件信息/订单号/合计"等字段,
|
||||
|
||||
Reference in New Issue
Block a user