167 住院管理-》住院护士站-》入出转管理:护士登录的科室能接收查看到其他科室的入科患者 入院病区字段下拉内容限制只能显示当前登录科室对应的病区,如该护士还有其他科室的权限需要做切换科室操作。
This commit is contained in:
@@ -464,17 +464,86 @@ public class CommonServiceImpl implements ICommonService {
|
||||
*/
|
||||
@Override
|
||||
public List<LocationDto> getPractitionerWard() {
|
||||
// 查询当前登录者管理的病区
|
||||
// 获取当前登录用户信息
|
||||
Long practitionerId = SecurityUtils.getLoginUser().getPractitionerId();
|
||||
Long currentOrgId = SecurityUtils.getLoginUser().getOrgId();
|
||||
|
||||
log.info("getPractitionerWard - practitionerId: {}, currentOrgId: {}", practitionerId, currentOrgId);
|
||||
|
||||
// 获取用户配置的位置 ID 列表(可能包含科室、病区等)
|
||||
List<Long> locationIds = practitionerRoleService.getLocationIdsByPractitionerId(practitionerId);
|
||||
List<Location> locationList
|
||||
= locationService.getLocationList(locationIds, Collections.singletonList(LocationStatus.ACTIVE.getValue()));
|
||||
// 获取用户配置的科室 ID 列表
|
||||
List<Long> orgIds = practitionerRoleService.getOrgIdsByPractitionerId(practitionerId);
|
||||
|
||||
log.info("getPractitionerWard - locationIds: {}, orgIds: {}", locationIds, orgIds);
|
||||
|
||||
List<Location> 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<Location> 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<Location> 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<Location> 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<LocationDto> 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<LocationDto> convertToLocationDtoList(List<Location> locationList) {
|
||||
List<LocationDto> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -202,8 +202,8 @@ public class CommonAppController {
|
||||
* @return 病区列表
|
||||
*/
|
||||
@GetMapping(value = "/practitioner-ward")
|
||||
public List<LocationDto> getPractitionerWard() {
|
||||
return commonService.getPractitionerWard();
|
||||
public R<?> getPractitionerWard() {
|
||||
return R.ok(commonService.getPractitionerWard());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user