This commit is contained in:
gr
2026-05-18 11:36:21 +08:00
283 changed files with 716 additions and 316 deletions
@@ -436,6 +436,110 @@ class PrescriptionLogic
}
}
/**
* 仅修正处方笺展示用患者姓名、手机号与性别(zyt_tcm_prescription),不改变审核状态与其它字段
*/
public static function patchPatientContact(int $rxId, string $patientName, string $phone, int $gender, int $adminId, array $adminInfo): bool
{
self::$error = '';
$prescription = Prescription::find($rxId);
if (!$prescription) {
self::setError('处方不存在');
return false;
}
if (!self::canViewPrescription($prescription, $adminId, $adminInfo)) {
self::setError('无权限修改此处方');
return false;
}
$patientName = trim($patientName);
$phone = trim($phone);
if ($patientName === '') {
self::setError('患者姓名不能为空');
return false;
}
if (mb_strlen($patientName) > 50) {
self::setError('患者姓名过长');
return false;
}
if ($phone === '') {
self::setError('手机号不能为空');
return false;
}
if (strlen($phone) > 20) {
self::setError('手机号过长');
return false;
}
if (!in_array($gender, [0, 1], true)) {
self::setError('性别无效');
return false;
}
$oldName = trim((string) ($prescription->patient_name ?? ''));
$oldPhone = trim((string) ($prescription->phone ?? ''));
$oldGender = (int) ($prescription->gender ?? 0);
if ($oldName === $patientName && $oldPhone === $phone && $oldGender === $gender) {
self::setError('信息未变更');
return false;
}
$genderText = static function (int $g): string {
if ($g === 1) {
return '男';
}
if ($g === 0) {
return '女';
}
return '未知';
};
try {
$prescription->save([
'patient_name' => $patientName,
'phone' => $phone,
'gender' => $gender,
]);
$latestPo = PrescriptionOrder::where('prescription_id', $rxId)
->whereNull('delete_time')
->order('id', 'desc')
->find();
$logOrderId = $latestPo ? (int) $latestPo->id : 0;
$nameFrom = $oldName === '' ? '—' : $oldName;
$phoneFrom = $oldPhone === '' ? '—' : $oldPhone;
$genderFrom = $genderText($oldGender);
$genderTo = $genderText($gender);
$summary = sprintf(
'处方 #%d:患者姓名「%s」→「%s」,手机「%s」→「%s」,性别「%s」→「%s」',
$rxId,
$nameFrom,
$patientName,
$phoneFrom,
$phone,
$genderFrom,
$genderTo
);
PrescriptionOrderLogic::appendRxPatientPatchLog($logOrderId, $adminId, $adminInfo, $summary);
return true;
} catch (\Throwable $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* 删除处方
*/
@@ -1097,7 +1097,7 @@ class PrescriptionOrderLogic
$phoneFrom,
$phone
);
self::writeLog($prescriptionOrderId, $adminId, $adminInfo, 'patch_rx_patient', $summary);
self::appendRxPatientPatchLog($prescriptionOrderId, $adminId, $adminInfo, $summary);
return true;
} catch (\Exception $e) {
@@ -2486,6 +2486,25 @@ class PrescriptionOrderLogic
return $m[$fs] ?? ('状态' . (string) $fs);
}
/**
* 业务订单列表/导出:「诊单医助」admin id。
* 与 {@see PrescriptionLists} 一致优先 {@see Prescription::$assistant_id}(开方时从诊单快照到处方表);
* 为 0 时再取诊单当前 {@see Diagnosis::$assistant_id}(兼容历史处方或未写入快照列的数据)。
*/
public static function resolveAssistantAdminIdForPrescriptionOrderRow(
int $prescriptionAssistantId,
int $diagnosisAssistantId
): int {
if ($prescriptionAssistantId > 0) {
return $prescriptionAssistantId;
}
if ($diagnosisAssistantId > 0) {
return $diagnosisAssistantId;
}
return 0;
}
/**
* 导出用:诊单医助在 admin_dept 中的部门路径(多部门「;」、路径内「 / 」)
*/
@@ -2656,7 +2675,7 @@ class PrescriptionOrderLogic
$rxById = [];
if ($rxIdList !== []) {
$rxRows = Prescription::whereIn('id', $rxIdList)->whereNull('delete_time')
->field(['id', 'prescription_type', 'need_decoction', 'dose_unit'])
->field(['id', 'prescription_type', 'need_decoction', 'dose_unit', 'assistant_id'])
->select()
->toArray();
foreach ($rxRows as $xr) {
@@ -2697,13 +2716,17 @@ class PrescriptionOrderLogic
$diagId = (int) ($item['diagnosis_id'] ?? 0);
$dg = $diagById[$diagId] ?? null;
$rxId = (int) ($item['prescription_id'] ?? 0);
$rx = $rxById[$rxId] ?? [];
$item['export_patient_name'] = \is_array($dg) ? (string) ($dg['patient_name'] ?? '') : '';
if (\is_array($dg)) {
$g = (int) ($dg['gender'] ?? 0);
$item['export_patient_gender'] = $g === 1 ? '男' : '女';
$item['export_patient_age'] = (string) ($dg['age'] ?? '');
$item['export_patient_phone'] = (string) ($dg['phone'] ?? '');
$astId = (int) ($dg['assistant_id'] ?? 0);
$rxAst = \is_array($rx) ? (int) ($rx['assistant_id'] ?? 0) : 0;
$diagAst = (int) ($dg['assistant_id'] ?? 0);
$astId = self::resolveAssistantAdminIdForPrescriptionOrderRow($rxAst, $diagAst);
if ($astId > 0) {
if (!isset($assistantDeptCache[$astId])) {
$assistantDeptCache[$astId] = self::formatAssistantDeptPathForExport($astId);
@@ -2719,8 +2742,6 @@ class PrescriptionOrderLogic
$item['export_assistant_dept'] = '';
}
$rxId = (int) ($item['prescription_id'] ?? 0);
$rx = $rxById[$rxId] ?? [];
$item['export_medication_form'] = self::formatMedicationFormForExport(\is_array($rx) ? $rx : []);
$item['export_channel'] = (string) ($item['service_channel'] ?? '');
@@ -3248,4 +3269,14 @@ class PrescriptionOrderLogic
// 忽略日志写入错误
}
}
/**
* 处方患者姓名/手机号修正日志(写入 zyt_tcm_prescription_order_log,与 patchPrescriptionPatient 同源)
*
* @param int $prescriptionOrderId 无关联订单时可传 0(若库表禁止则可能静默失败)
*/
public static function appendRxPatientPatchLog(int $prescriptionOrderId, int $adminId, array $adminInfo, string $summary): void
{
self::writeLog($prescriptionOrderId, $adminId, $adminInfo, 'patch_rx_patient', $summary);
}
}