This commit is contained in:
Your Name
2026-05-18 11:20:24 +08:00
parent 1d66f84bd3
commit 08290b329e
8 changed files with 157 additions and 43 deletions
@@ -437,9 +437,9 @@ class PrescriptionLogic
}
/**
* 仅修正处方笺展示用患者姓名手机号(zyt_tcm_prescription),不改变审核状态与其它字段
* 仅修正处方笺展示用患者姓名手机号与性别zyt_tcm_prescription),不改变审核状态与其它字段
*/
public static function patchPatientContact(int $rxId, string $patientName, string $phone, int $adminId, array $adminInfo): bool
public static function patchPatientContact(int $rxId, string $patientName, string $phone, int $gender, int $adminId, array $adminInfo): bool
{
self::$error = '';
$prescription = Prescription::find($rxId);
@@ -476,20 +476,38 @@ class PrescriptionLogic
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) {
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)
@@ -500,13 +518,17 @@ class PrescriptionLogic
$nameFrom = $oldName === '' ? '—' : $oldName;
$phoneFrom = $oldPhone === '' ? '—' : $oldPhone;
$genderFrom = $genderText($oldGender);
$genderTo = $genderText($gender);
$summary = sprintf(
'处方 #%d:患者姓名「%s」→「%s」,手机「%s」→「%s」',
'处方 #%d:患者姓名「%s」→「%s」,手机「%s」→「%s」,性别「%s」→「%s」',
$rxId,
$nameFrom,
$patientName,
$phoneFrom,
$phone
$phone,
$genderFrom,
$genderTo
);
PrescriptionOrderLogic::appendRxPatientPatchLog($logOrderId, $adminId, $adminInfo, $summary);
@@ -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'] ?? '');