桌面端编辑处方可修改手机号、身份证号
- 桌面端开方/编辑处方表单新增「手机号」「身份证号」,已开处方编辑时可修改(姓名仍只读);身份证号本地先校验格式 - 服务端 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
@@ -45,7 +45,7 @@ class PrescriptionController extends BaseAdminController
|
||||
public function edit()
|
||||
{
|
||||
$params = (new PrescriptionValidate())->post()->goCheck('edit');
|
||||
$result = PrescriptionLogic::edit($params, $this->adminId);
|
||||
$result = PrescriptionLogic::edit($params, $this->adminId, $this->adminInfo);
|
||||
if (!$result) {
|
||||
return $this->fail(PrescriptionLogic::getError());
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
* 处方笺展示所需的"收件信息/订单号/合计"等字段,
|
||||
|
||||
@@ -1050,8 +1050,9 @@ namespace {
|
||||
Db::name('system_role_menu')->insert(['role_id' => 1, 'menu_id' => 6]);
|
||||
Db::execute("INSERT INTO zyt_system_role VALUES (1, 'Doctor', 4, NULL), (2, 'Read only', 4, NULL), (3, 'Audit', 1, NULL)");
|
||||
Db::execute('CREATE TABLE zyt_tcm_diagnosis (id INTEGER PRIMARY KEY, status INTEGER, patient_id INTEGER,
|
||||
assistant_id INTEGER, patient_name TEXT, gender INTEGER, age INTEGER, phone TEXT, delete_time INTEGER)');
|
||||
Db::execute("INSERT INTO zyt_tcm_diagnosis VALUES (10, 1, 99, 3, 'Test patient', 1, 30, '13800000000', NULL)");
|
||||
assistant_id INTEGER, patient_name TEXT, gender INTEGER, age INTEGER, phone TEXT, delete_time INTEGER, id_card TEXT DEFAULT "")');
|
||||
Db::execute("INSERT INTO zyt_tcm_diagnosis VALUES (10, 1, 99, 3, 'Test patient', 1, 30, '13800000000', NULL, '')");
|
||||
Db::execute("INSERT INTO zyt_tcm_diagnosis VALUES (11, 1, 98, 3, 'Other patient', 1, 40, '', NULL, '110101199001011237')");
|
||||
Db::execute('CREATE TABLE zyt_doctor_appointment (id INTEGER PRIMARY KEY, patient_id INTEGER, doctor_id INTEGER, status INTEGER)');
|
||||
Db::execute('INSERT INTO zyt_doctor_appointment VALUES (40, 10, 1, 3)');
|
||||
Db::execute('CREATE TABLE zyt_doctor_note (id INTEGER PRIMARY KEY, diagnosis_id INTEGER, delete_time INTEGER)');
|
||||
@@ -1244,6 +1245,34 @@ namespace {
|
||||
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');
|
||||
|
||||
// 开方/编辑处方可修改处方笺手机号;身份证号写回诊单(校验格式与重复、按出生日期更新年龄),仅可管理诊单者可见。
|
||||
$contactRx = PrescriptionLogic::add($params + ['phone' => '13900000001', 'id_card' => '11010119800101123x'], 1, $doctor);
|
||||
$contact = Db::name('tcm_prescription')->find($contactRx);
|
||||
$assert($contactRx !== null && $contact['phone'] === '13900000001'
|
||||
&& Db::name('tcm_diagnosis')->where('id', 10)->value('id_card') === '11010119800101123X'
|
||||
&& (int) $contact['age'] === (int) Db::name('tcm_diagnosis')->where('id', 10)->value('age')
|
||||
&& (int) $contact['age'] >= 45, 'new prescriptions store the phone and fill the diagnosis ID card with derived age');
|
||||
$assert(PrescriptionLogic::detail($contactRx, 1, $doctor)['patient_id_card'] === '11010119800101123X'
|
||||
&& !array_key_exists('patient_id_card', PrescriptionLogic::detail($contactRx, 4, ['root' => 0, 'admin_id' => 4, 'role_id' => [3]]) ?? []),
|
||||
'the ID card is returned only to accounts that manage the diagnosis');
|
||||
$edit = static fn (array $fields): array => ['id' => $contactRx, 'diagnosis_id' => 10, 'herbs' => $params['herbs'],
|
||||
'prescription_date' => $params['prescription_date']] + $fields;
|
||||
$assert(!PrescriptionLogic::edit($edit(['id_card' => '110101199001011237']), 1, $doctor)
|
||||
&& str_contains(PrescriptionLogic::getError(), '已登记')
|
||||
&& Db::name('tcm_diagnosis')->where('id', 10)->value('id_card') === '11010119800101123X',
|
||||
'a duplicate ID card is refused and nothing is saved');
|
||||
$assert(!PrescriptionLogic::edit($edit(['id_card' => '1234']), 1, $doctor)
|
||||
&& str_contains(PrescriptionLogic::getError(), '格式'), 'a malformed ID card is refused');
|
||||
$assert(!PrescriptionLogic::edit($edit(['phone' => '13900000002', 'id_card' => '110101200001011234']), 1)
|
||||
&& Db::name('tcm_prescription')->where('id', $contactRx)->value('phone') === '13900000001',
|
||||
'editing the ID card without a verified diagnosis scope is refused and rolls back the phone');
|
||||
$assert(PrescriptionLogic::edit($edit(['phone' => '13900000002', 'id_card' => '110101200001011234']), 1, $doctor),
|
||||
'phone and ID card can be edited together: ' . PrescriptionLogic::getError());
|
||||
$assert(Db::name('tcm_prescription')->where('id', $contactRx)->value('phone') === '13900000002'
|
||||
&& Db::name('tcm_diagnosis')->where('id', 10)->value('id_card') === '110101200001011234'
|
||||
&& (int) Db::name('tcm_prescription')->where('id', $contactRx)->value('age') === (int) Db::name('tcm_diagnosis')->where('id', 10)->value('age'),
|
||||
'edit saves the phone on the prescription and the ID card and age on the diagnosis');
|
||||
$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