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

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) { async findVisibleDoctors(actor: ActorContext, requestedHospitalId?: number) {
const hospitalId = this.resolveHospitalId(actor, requestedHospitalId); 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({ return this.prisma.user.findMany({
where, where: this.buildVisibleDoctorWhere(actor, hospitalId),
select: { select: {
id: true, id: true,
name: true, name: true,
@ -584,29 +556,51 @@ export class BPatientsService {
throw new BadRequestException(MESSAGES.PATIENT.DOCTOR_NOT_FOUND); 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) { switch (actor.role) {
case Role.SYSTEM_ADMIN: case Role.SYSTEM_ADMIN:
return doctor;
case Role.HOSPITAL_ADMIN: case Role.HOSPITAL_ADMIN:
if (!actor.hospitalId || doctor.hospitalId !== actor.hospitalId) { return where;
throw new ForbiddenException(MESSAGES.PATIENT.DOCTOR_SCOPE_FORBIDDEN);
}
return doctor;
case Role.DIRECTOR: case Role.DIRECTOR:
if (!actor.departmentId || doctor.departmentId !== actor.departmentId) { if (!actor.departmentId) {
throw new ForbiddenException(MESSAGES.PATIENT.DOCTOR_SCOPE_FORBIDDEN); throw new BadRequestException(MESSAGES.PATIENT.DEPARTMENT_REQUIRED);
} }
return doctor; where.departmentId = actor.departmentId;
return where;
case Role.LEADER: case Role.LEADER:
if (!actor.groupId || doctor.groupId !== actor.groupId) { if (!actor.groupId) {
throw new ForbiddenException(MESSAGES.PATIENT.DOCTOR_SCOPE_FORBIDDEN); throw new BadRequestException(MESSAGES.PATIENT.GROUP_REQUIRED);
} }
return doctor; where.groupId = actor.groupId;
return where;
case Role.DOCTOR: case Role.DOCTOR:
if (doctor.id !== actor.id) { if (!actor.departmentId) {
throw new ForbiddenException(MESSAGES.PATIENT.DOCTOR_SCOPE_FORBIDDEN); throw new BadRequestException(MESSAGES.PATIENT.DEPARTMENT_REQUIRED);
} }
return doctor; where.departmentId = actor.departmentId;
return where;
default: default:
throw new ForbiddenException(MESSAGES.PATIENT.ROLE_FORBIDDEN); throw new ForbiddenException(MESSAGES.PATIENT.ROLE_FORBIDDEN);
} }

View File

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