diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/common/appservice/impl/CommonServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/common/appservice/impl/CommonServiceImpl.java index 9d1ca616..62c2bbff 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/common/appservice/impl/CommonServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/common/appservice/impl/CommonServiceImpl.java @@ -464,17 +464,86 @@ public class CommonServiceImpl implements ICommonService { */ @Override public List getPractitionerWard() { - // 查询当前登录者管理的病区 + // 获取当前登录用户信息 Long practitionerId = SecurityUtils.getLoginUser().getPractitionerId(); + Long currentOrgId = SecurityUtils.getLoginUser().getOrgId(); + + log.info("getPractitionerWard - practitionerId: {}, currentOrgId: {}", practitionerId, currentOrgId); + + // 获取用户配置的位置 ID 列表(可能包含科室、病区等) List locationIds = practitionerRoleService.getLocationIdsByPractitionerId(practitionerId); - List locationList - = locationService.getLocationList(locationIds, Collections.singletonList(LocationStatus.ACTIVE.getValue())); + // 获取用户配置的科室 ID 列表 + List orgIds = practitionerRoleService.getOrgIdsByPractitionerId(practitionerId); + + log.info("getPractitionerWard - locationIds: {}, orgIds: {}", locationIds, orgIds); + List wardList = new ArrayList<>(); - for (Location ward : locationList) { - if (LocationForm.WARD.getValue().equals(ward.getFormEnum())) { - wardList.add(ward); + + // 方式 1:从 locationIds 中过滤出病区 + if (locationIds != null && !locationIds.isEmpty()) { + // 过滤掉 null 值 + locationIds = locationIds.stream().filter(id -> id != null).collect(java.util.stream.Collectors.toList()); + if (!locationIds.isEmpty()) { + List locationList + = locationService.getLocationList(locationIds, Collections.singletonList(LocationStatus.ACTIVE.getValue())); + log.info("getPractitionerWard - 从 locationIds 查询到的位置总数:{}", locationList != null ? locationList.size() : 0); + + for (Location location : locationList) { + log.info("getPractitionerWard - 位置:id={}, name={}, formEnum={}, organizationId={}", + location.getId(), location.getName(), location.getFormEnum(), location.getOrganizationId()); + if (LocationForm.WARD.getValue().equals(location.getFormEnum())) { + // 如果当前有选择科室,只添加当前科室的病区 + if (currentOrgId == null || currentOrgId.equals(location.getOrganizationId())) { + wardList.add(location); + } + } + } } } + + // 方式 2:从 orgIds 查询病区(补充查询,确保能获取到病区) + if (orgIds != null && !orgIds.isEmpty()) { + // 过滤掉 null 值并去重 + orgIds = orgIds.stream().filter(id -> id != null).distinct().collect(java.util.stream.Collectors.toList()); + if (!orgIds.isEmpty()) { + log.info("getPractitionerWard - 从 orgIds 查询病区,orgIds: {}", orgIds); + for (Long orgId : orgIds) { + // 如果当前有选择科室,只查询当前科室的病区 + if (currentOrgId != null && !currentOrgId.equals(orgId)) { + continue; + } + List orgWards = locationService.getWardList(orgId); + log.info("getPractitionerWard - orgId: {} 查询到病区数:{}", orgId, orgWards != null ? orgWards.size() : 0); + if (orgWards != null && !orgWards.isEmpty()) { + wardList.addAll(orgWards); + } + } + } + } + + // 方式 3:如果仍然没有病区,且 currentOrgId 为空,尝试获取所有病区 + if (wardList.isEmpty() && currentOrgId == null) { + log.info("getPractitionerWard - 尝试获取所有病区"); + List allWards = locationService.getWardList(null); + log.info("getPractitionerWard - 所有病区数:{}", allWards != null ? allWards.size() : 0); + if (allWards != null && !allWards.isEmpty()) { + wardList.addAll(allWards); + } + } + + // 去重:根据病区 ID 去重(因为方式 1 和方式 2 可能会查询到相同的病区) + if (!wardList.isEmpty()) { + wardList = wardList.stream() + .collect(java.util.stream.Collectors.collectingAndThen( + java.util.stream.Collectors.toCollection(() -> + new java.util.TreeSet<>(java.util.Comparator.comparing(Location::getId))), + ArrayList::new + )); + } + + log.info("getPractitionerWard - 最终病区数:{}", wardList.size()); + + // 转换为 DTO List locationDtoList = new ArrayList<>(); LocationDto locationDto; for (Location ward : wardList) { @@ -482,6 +551,31 @@ public class CommonServiceImpl implements ICommonService { BeanUtils.copyProperties(ward, locationDto); locationDtoList.add(locationDto); } + + return locationDtoList; + } + + /** + * 将Location列表转换为LocationDto列表 + * + * @param locationList Location列表 + * @return LocationDto列表 + */ + private List convertToLocationDtoList(List locationList) { + List locationDtoList = new ArrayList<>(); + if (locationList == null || locationList.isEmpty()) { + return locationDtoList; + } + + LocationDto locationDto; + for (Location location : locationList) { + // 只返回病区类型的位置 + if (LocationForm.WARD.getValue().equals(location.getFormEnum())) { + locationDto = new LocationDto(); + BeanUtils.copyProperties(location, locationDto); + locationDtoList.add(locationDto); + } + } return locationDtoList; } diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/common/controller/CommonAppController.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/common/controller/CommonAppController.java index 1b043e1a..d3a0dfd1 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/common/controller/CommonAppController.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/common/controller/CommonAppController.java @@ -202,8 +202,8 @@ public class CommonAppController { * @return 病区列表 */ @GetMapping(value = "/practitioner-ward") - public List getPractitionerWard() { - return commonService.getPractitionerWard(); + public R getPractitionerWard() { + return R.ok(commonService.getPractitionerWard()); } /** diff --git a/openhis-ui-vue3/src/views/inHospitalManagement/charge/register/components/api.js b/openhis-ui-vue3/src/views/inHospitalManagement/charge/register/components/api.js index a3ea9cae..d6711d77 100644 --- a/openhis-ui-vue3/src/views/inHospitalManagement/charge/register/components/api.js +++ b/openhis-ui-vue3/src/views/inHospitalManagement/charge/register/components/api.js @@ -206,3 +206,14 @@ export function getAllWards(params = {}) { }, }); } + +/** + * 获取当前登录用户有权限管理的病区 + */ +export function getPractitionerWard(queryParams) { + return request({ + url: '/app-common/practitioner-ward', + method: 'get', + params: queryParams, + }); +} diff --git a/openhis-ui-vue3/src/views/inHospitalManagement/charge/register/components/registerForm.vue b/openhis-ui-vue3/src/views/inHospitalManagement/charge/register/components/registerForm.vue index 05f42564..425dbe82 100644 --- a/openhis-ui-vue3/src/views/inHospitalManagement/charge/register/components/registerForm.vue +++ b/openhis-ui-vue3/src/views/inHospitalManagement/charge/register/components/registerForm.vue @@ -202,7 +202,7 @@