统一医生可见范围并优化患者归属医生选择

This commit is contained in:
EL 2026-04-02 05:29:00 +08:00
parent 8f7e13bf2b
commit d77627e44b
2 changed files with 37 additions and 49 deletions

View File

@ -186,36 +186,8 @@ export class BPatientsService {
*/
async findVisibleDoctors(actor: ActorContext, requestedHospitalId?: number) {
const hospitalId = this.resolveHospitalId(actor, requestedHospitalId);
const where: Prisma.UserWhereInput = {
role: { in: PATIENT_OWNER_ROLES },
hospitalId,
};
switch (actor.role) {
case Role.DOCTOR:
where.id = actor.id;
break;
case Role.LEADER:
if (!actor.groupId) {
throw new BadRequestException(MESSAGES.PATIENT.GROUP_REQUIRED);
}
where.groupId = actor.groupId;
break;
case Role.DIRECTOR:
if (!actor.departmentId) {
throw new BadRequestException(MESSAGES.PATIENT.DEPARTMENT_REQUIRED);
}
where.departmentId = actor.departmentId;
break;
case Role.HOSPITAL_ADMIN:
case Role.SYSTEM_ADMIN:
break;
default:
throw new ForbiddenException(MESSAGES.PATIENT.ROLE_FORBIDDEN);
}
return this.prisma.user.findMany({
where,
where: this.buildVisibleDoctorWhere(actor, hospitalId),
select: {
id: true,
name: true,
@ -584,29 +556,51 @@ export class BPatientsService {
throw new BadRequestException(MESSAGES.PATIENT.DOCTOR_NOT_FOUND);
}
const visibleDoctor = await this.prisma.user.findFirst({
where: {
id: doctor.id,
...this.buildVisibleDoctorWhere(actor, doctor.hospitalId),
},
select: { id: true },
});
if (!visibleDoctor) {
throw new ForbiddenException(MESSAGES.PATIENT.DOCTOR_SCOPE_FORBIDDEN);
}
return doctor;
}
/**
*
*/
private buildVisibleDoctorWhere(actor: ActorContext, hospitalId: number) {
const where: Prisma.UserWhereInput = {
role: { in: PATIENT_OWNER_ROLES },
hospitalId,
};
switch (actor.role) {
case Role.SYSTEM_ADMIN:
return doctor;
case Role.HOSPITAL_ADMIN:
if (!actor.hospitalId || doctor.hospitalId !== actor.hospitalId) {
throw new ForbiddenException(MESSAGES.PATIENT.DOCTOR_SCOPE_FORBIDDEN);
}
return doctor;
return where;
case Role.DIRECTOR:
if (!actor.departmentId || doctor.departmentId !== actor.departmentId) {
throw new ForbiddenException(MESSAGES.PATIENT.DOCTOR_SCOPE_FORBIDDEN);
if (!actor.departmentId) {
throw new BadRequestException(MESSAGES.PATIENT.DEPARTMENT_REQUIRED);
}
return doctor;
where.departmentId = actor.departmentId;
return where;
case Role.LEADER:
if (!actor.groupId || doctor.groupId !== actor.groupId) {
throw new ForbiddenException(MESSAGES.PATIENT.DOCTOR_SCOPE_FORBIDDEN);
if (!actor.groupId) {
throw new BadRequestException(MESSAGES.PATIENT.GROUP_REQUIRED);
}
return doctor;
where.groupId = actor.groupId;
return where;
case Role.DOCTOR:
if (doctor.id !== actor.id) {
throw new ForbiddenException(MESSAGES.PATIENT.DOCTOR_SCOPE_FORBIDDEN);
if (!actor.departmentId) {
throw new BadRequestException(MESSAGES.PATIENT.DEPARTMENT_REQUIRED);
}
return doctor;
where.departmentId = actor.departmentId;
return where;
default:
throw new ForbiddenException(MESSAGES.PATIENT.ROLE_FORBIDDEN);
}

View File

@ -216,12 +216,10 @@
v-model="patientForm.doctorId"
:data="doctorTreeOptions"
:props="doctorTreeProps"
check-strictly
filterable
clearable
placeholder="请选择归属医生(按科室/小组)"
style="width: 100%"
:disabled="userStore.role === 'DOCTOR'"
/>
</el-form-item>
</el-col>
@ -1588,10 +1586,6 @@ async function openCreateDialog() {
isEdit.value = false;
resetPatientForm();
if (userStore.role === 'DOCTOR') {
patientForm.doctorId = userStore.userInfo?.id || null;
}
dialogVisible.value = true;
}