机构树
This commit is contained in:
@@ -2,7 +2,9 @@ package com.core.common.utils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Period;
|
||||
import java.time.ZoneId;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 根据出生日期算年龄
|
||||
@@ -15,7 +17,9 @@ public final class AgeCalculatorUtil {
|
||||
/**
|
||||
* 当前年龄取得(床位列表表示年龄用)
|
||||
*/
|
||||
public static String getAge(LocalDateTime dateTime) {
|
||||
public static String getAge(Date date) {
|
||||
// 将 Date 转换为 LocalDateTime
|
||||
LocalDateTime dateTime = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
int years = now.getYear() - dateTime.getYear();
|
||||
if (years > 2) {
|
||||
@@ -78,5 +82,4 @@ public final class AgeCalculatorUtil {
|
||||
private static boolean isLeapYear(int year) {
|
||||
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.openhis.web.basedatamanage.appservice;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.openhis.web.basedatamanage.dto.OrganizationQueryDto;
|
||||
|
||||
/**
|
||||
* Organization 应该服务类
|
||||
*/
|
||||
public interface IOrganizationAppService {
|
||||
// 查询机构树
|
||||
Page<OrganizationQueryDto> getOrganizationTree(Integer pageNo, Integer pageSize);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.openhis.web.basedatamanage.appservice.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.openhis.administration.domain.Organization;
|
||||
import com.openhis.administration.service.IOrganizationService;
|
||||
import com.openhis.web.basedatamanage.appservice.IOrganizationAppService;
|
||||
import com.openhis.web.basedatamanage.dto.OrganizationQueryDto;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class IOrganizationAppServiceImpl implements IOrganizationAppService {
|
||||
|
||||
@Resource
|
||||
IOrganizationService organizationService;
|
||||
|
||||
@Override
|
||||
public Page<OrganizationQueryDto> getOrganizationTree(Integer pageNo, Integer pageSize) {
|
||||
// 查询机构列表
|
||||
Page<Organization> page = organizationService.page(new Page<>(pageNo, pageSize));
|
||||
List<Organization> organizationList = page.getRecords();
|
||||
// 将机构列表转为树结构
|
||||
List<OrganizationQueryDto> orgTree = buildTree(organizationList);
|
||||
Page<OrganizationQueryDto> orgQueryDtoPage = new Page<>(pageNo, pageSize, page.getTotal());
|
||||
orgQueryDtoPage.setRecords(orgTree);
|
||||
return orgQueryDtoPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将机构列表转换为树结构
|
||||
*
|
||||
* @param records 机构列表
|
||||
* @return tree
|
||||
*/
|
||||
private List<OrganizationQueryDto> buildTree(List<Organization> records) {
|
||||
// 按b_no的层级排序,确保父节点先处理
|
||||
List<Organization> sortedRecords = records.stream()
|
||||
.sorted(Comparator.comparingInt(r -> r.getBusNo().split("\\.").length)).collect(Collectors.toList());
|
||||
|
||||
Map<String, OrganizationQueryDto> nodeMap = new HashMap<>();
|
||||
List<OrganizationQueryDto> tree = new ArrayList<>();
|
||||
|
||||
for (Organization record : sortedRecords) {
|
||||
String bNo = record.getBusNo();
|
||||
String[] parts = bNo.split("\\.");
|
||||
OrganizationQueryDto node = new OrganizationQueryDto();
|
||||
BeanUtils.copyProperties(record, node);
|
||||
// 将当前节点加入映射
|
||||
nodeMap.put(bNo, node);
|
||||
|
||||
if (parts.length == 1) {
|
||||
// 根节点
|
||||
tree.add(node);
|
||||
} else {
|
||||
// 获取父节点的b_no(去掉最后一部分)
|
||||
String parentBNo = String.join(".", Arrays.copyOf(parts, parts.length - 1));
|
||||
OrganizationQueryDto parent = nodeMap.get(parentBNo);
|
||||
|
||||
if (parent != null) {
|
||||
parent.getChildren().add(node);
|
||||
} else {
|
||||
// 处理父节点不存在的情况(例如数据缺失)
|
||||
// 可根据需求调整为将节点加入根或抛出异常
|
||||
}
|
||||
}
|
||||
}
|
||||
return tree;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,16 +3,6 @@
|
||||
*/
|
||||
package com.openhis.web.basedatamanage.controller;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.core.common.core.domain.R;
|
||||
import com.core.common.utils.AssignSeqUtil;
|
||||
@@ -22,12 +12,18 @@ import com.openhis.administration.mapper.OrganizationMapper;
|
||||
import com.openhis.administration.service.IOrganizationService;
|
||||
import com.openhis.common.constant.PromptMsgConstant;
|
||||
import com.openhis.common.enums.OrganizationType;
|
||||
import com.openhis.web.basedatamanage.dto.OrgQueryParam;
|
||||
import com.openhis.web.basedatamanage.appservice.IOrganizationAppService;
|
||||
import com.openhis.web.basedatamanage.dto.OrganizationInitDto;
|
||||
import com.openhis.web.basedatamanage.dto.OrganizationQueryDto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 机构管理controller
|
||||
@@ -42,6 +38,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
public class OrganizationController {
|
||||
|
||||
private final IOrganizationService organizationService;
|
||||
private final IOrganizationAppService iOrganizationAppService;
|
||||
|
||||
@Autowired
|
||||
private OrganizationMapper organizationMapper;
|
||||
@@ -63,38 +60,17 @@ public class OrganizationController {
|
||||
/**
|
||||
* 机构分页列表
|
||||
*
|
||||
* @param orgQueryParam 查询字段
|
||||
* @param searchKey 模糊查询关键字
|
||||
* @param pageNo 当前页码
|
||||
* @param pageNo 当前页码
|
||||
* @param pageSize 查询条数
|
||||
* @param request 请求数据
|
||||
* @return 机构分页列表
|
||||
*/
|
||||
@GetMapping(value = "/organization")
|
||||
public R<?> getOrganizationPage(OrgQueryParam orgQueryParam,
|
||||
@RequestParam(value = "searchKey", defaultValue = "") String searchKey,
|
||||
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest request) {
|
||||
|
||||
// // 构建查询条件
|
||||
// QueryWrapper<Organization> queryWrapper = HisQueryUtils.buildQueryWrapper(orgQueryParam, searchKey,
|
||||
// new HashSet<>(Arrays.asList("name", "py_str", "wb_str")), request);
|
||||
//
|
||||
// // 设置排序
|
||||
// queryWrapper.orderByDesc("create_time");
|
||||
// // 执行分页查询并转换为 orgQueryDtoPage
|
||||
// Page<OrganizationQueryDto> orgQueryDtoPage =
|
||||
// HisPageUtils.selectPage(organizationMapper, queryWrapper, pageNo, pageSize, OrganizationQueryDto.class);
|
||||
// 查询机构列表
|
||||
Page<Organization> page = organizationService.page(new Page<>(pageNo, pageSize));
|
||||
List<Organization> organizationList = page.getRecords();
|
||||
// 将机构列表转为树结构
|
||||
List<OrganizationQueryDto> orgTree = buildTree(organizationList);
|
||||
Page<OrganizationQueryDto> orgQueryDtoPage = new Page<>(pageNo, pageSize, page.getTotal());
|
||||
orgQueryDtoPage.setRecords(orgTree);
|
||||
|
||||
return R.ok(orgQueryDtoPage,
|
||||
MessageUtils.createMessage(PromptMsgConstant.Common.M00009, new Object[] {"机构信息"}));
|
||||
public R<?> getOrganizationPage(
|
||||
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
|
||||
Page<OrganizationQueryDto> organizationTree = iOrganizationAppService.getOrganizationTree(pageNo, pageSize);
|
||||
return R.ok(organizationTree,
|
||||
MessageUtils.createMessage(PromptMsgConstant.Common.M00009, new Object[]{"机构信息"}));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,8 +92,8 @@ public class OrganizationController {
|
||||
boolean saveOrgSuccess = organizationService.save(organization);
|
||||
|
||||
return saveOrgSuccess
|
||||
? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00001, new Object[] {"机构信息"}))
|
||||
: R.fail(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00003, new Object[] {"机构信息"}));
|
||||
? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00001, new Object[]{"机构信息"}))
|
||||
: R.fail(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00003, new Object[]{"机构信息"}));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,7 +105,7 @@ public class OrganizationController {
|
||||
public R<?> getOrganizationById(@Validated @RequestParam Long orgId) {
|
||||
|
||||
Organization organization = organizationService.getById(orgId);
|
||||
return R.ok(organization, MessageUtils.createMessage(PromptMsgConstant.Common.M00009, new Object[] {"机构信息"}));
|
||||
return R.ok(organization, MessageUtils.createMessage(PromptMsgConstant.Common.M00009, new Object[]{"机构信息"}));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,8 +121,8 @@ public class OrganizationController {
|
||||
|
||||
boolean updateOrgSuccess = organizationService.updateById(organization);
|
||||
return updateOrgSuccess
|
||||
? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[] {"机构信息"}))
|
||||
: R.fail(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00007, new Object[] {"机构信息"}));
|
||||
? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[]{"机构信息"}))
|
||||
: R.fail(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00007, new Object[]{"机构信息"}));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,8 +142,8 @@ public class OrganizationController {
|
||||
boolean deleteOrgSuccess = organizationService.removeByIds(orgIdList);
|
||||
|
||||
return deleteOrgSuccess
|
||||
? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00005, new Object[] {"机构信息"}))
|
||||
: R.fail(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00006, new Object[] {"机构信息"}));
|
||||
? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00005, new Object[]{"机构信息"}))
|
||||
: R.fail(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00006, new Object[]{"机构信息"}));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,8 +157,8 @@ public class OrganizationController {
|
||||
boolean activeSuccess = organizationService.activeChange(orgId);
|
||||
|
||||
return activeSuccess
|
||||
? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00004, new Object[] {"启用"}))
|
||||
: R.fail(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00007, new Object[] {"启用"}));
|
||||
? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00004, new Object[]{"启用"}))
|
||||
: R.fail(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00007, new Object[]{"启用"}));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,49 +172,9 @@ public class OrganizationController {
|
||||
boolean inActiveSuccess = organizationService.activeChange(orgId);
|
||||
|
||||
return inActiveSuccess
|
||||
? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00004, new Object[] {"停用"}))
|
||||
: R.fail(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00007, new Object[] {"停用"}));
|
||||
? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00004, new Object[]{"停用"}))
|
||||
: R.fail(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00007, new Object[]{"停用"}));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将机构列表转换为树结构
|
||||
*
|
||||
* @param records 机构列表
|
||||
* @return tree
|
||||
*/
|
||||
private List<OrganizationQueryDto> buildTree(List<Organization> records) {
|
||||
// 按b_no的层级排序,确保父节点先处理
|
||||
List<Organization> sortedRecords = records.stream()
|
||||
.sorted(Comparator.comparingInt(r -> r.getBusNo().split("\\.").length)).collect(Collectors.toList());
|
||||
|
||||
Map<String, OrganizationQueryDto> nodeMap = new HashMap<>();
|
||||
List<OrganizationQueryDto> tree = new ArrayList<>();
|
||||
|
||||
for (Organization record : sortedRecords) {
|
||||
String bNo = record.getBusNo();
|
||||
String[] parts = bNo.split("\\.");
|
||||
OrganizationQueryDto node = new OrganizationQueryDto();
|
||||
BeanUtils.copyProperties(record, node);
|
||||
// 将当前节点加入映射
|
||||
nodeMap.put(bNo, node);
|
||||
|
||||
if (parts.length == 1) {
|
||||
// 根节点
|
||||
tree.add(node);
|
||||
} else {
|
||||
// 获取父节点的b_no(去掉最后一部分)
|
||||
String parentBNo = String.join(".", Arrays.copyOf(parts, parts.length - 1));
|
||||
OrganizationQueryDto parent = nodeMap.get(parentBNo);
|
||||
|
||||
if (parent != null) {
|
||||
parent.getChildren().add(node);
|
||||
} else {
|
||||
// 处理父节点不存在的情况(例如数据缺失)
|
||||
// 可根据需求调整为将节点加入根或抛出异常
|
||||
}
|
||||
}
|
||||
}
|
||||
return tree;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import com.openhis.common.enums.OrganizationClass;
|
||||
import com.openhis.common.enums.OrganizationType;
|
||||
|
||||
@@ -24,6 +26,7 @@ public class OrganizationQueryDto {
|
||||
|
||||
/** ID */
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/** 编码 */
|
||||
|
||||
@@ -30,6 +30,7 @@ public class HealthcareServiceDto {
|
||||
* 提供部门ID
|
||||
*/
|
||||
@Dict(dictTable = "adm_organization",dictCode = "id",dictText = "name")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long offeredOrgId;
|
||||
private String offeredOrgId_dictText;
|
||||
|
||||
@@ -58,6 +59,7 @@ public class HealthcareServiceDto {
|
||||
* 地点
|
||||
*/
|
||||
@Dict(dictTable = "adm_location",dictCode = "id",dictText = "name")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long locationId;
|
||||
private String locationId_dictText;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.openhis.web.outpatientservice.controller.appservice.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.core.common.utils.AgeCalculatorUtil;
|
||||
import com.openhis.administration.domain.Patient;
|
||||
import com.openhis.administration.mapper.PatientMapper;
|
||||
import com.openhis.common.enums.AdministrativeGender;
|
||||
@@ -49,6 +50,8 @@ public class IOutpatientRegistrationServiceImpl implements IOutpatientRegistrati
|
||||
patientMetadataPage.getRecords().forEach(e -> {
|
||||
// 性别枚举
|
||||
e.setGenderEnum_enumText(EnumUtils.getInfoByValue(AdministrativeGender.class, e.getGenderEnum()));
|
||||
// 计算年龄
|
||||
e.setAge(AgeCalculatorUtil.getAge(e.getBirthDate()));
|
||||
});
|
||||
return patientMetadataPage;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package com.openhis.web.outpatientservice.dto;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 患者信息 元数据
|
||||
*/
|
||||
@@ -12,6 +16,7 @@ public class PatientMetadata {
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
@@ -25,4 +30,25 @@ public class PatientMetadata {
|
||||
private Integer genderEnum;
|
||||
private String genderEnum_enumText;
|
||||
|
||||
/**
|
||||
* 身份证号
|
||||
*/
|
||||
private String idCard;
|
||||
|
||||
/**
|
||||
* 电话
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 生日
|
||||
*/
|
||||
|
||||
private Date birthDate;
|
||||
|
||||
/**
|
||||
* 年龄
|
||||
*/
|
||||
private String age;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user