|
@@ -139,7 +139,7 @@ public class ShareParamServiceImpl implements ShareParamService {
|
|
|
@Override
|
|
|
public void computeShareParamCost(String computeDate){
|
|
|
//完全法项目分摊参数计算
|
|
|
- computeShareParamCostAction(computeDate);
|
|
|
+ calcShareParamCost(computeDate);
|
|
|
//执行完全法项目分摊参数计算后续处理脚本
|
|
|
execShareParamCostSQL(computeDate);
|
|
|
}
|
|
@@ -231,6 +231,329 @@ public class ShareParamServiceImpl implements ShareParamService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 项目分摊参数计算
|
|
|
+ * @param computeDate
|
|
|
+ */
|
|
|
+ public void calcShareParamCost(String computeDate){
|
|
|
+ SessionUserVO currentUser = UserContext.getCurrentUser();
|
|
|
+ //获取收费项目数据(项目)
|
|
|
+ checkItemCount(computeDate, currentUser);
|
|
|
+ //作废上次计算记录
|
|
|
+ repository.removeByComputeDate(computeDate, currentUser);
|
|
|
+ detailRepository.removeByComputeDate(computeDate, currentUser);
|
|
|
+ //医疗服务项目字典
|
|
|
+ List<Item> itemList = itemRepository.getList();
|
|
|
+ if (CollectionUtils.isEmpty(itemList)) {
|
|
|
+ throw new CostException("医疗服务项目未维护,请先添加医疗服务项目再进行计算,当前计算中止");
|
|
|
+ }
|
|
|
+ //医疗服务项目的参与人员信息
|
|
|
+ List<ItemEmpMap> itemEmpMaps = itemEmpMapRepository.getList();
|
|
|
+ //医疗服务项目的使用设备信息
|
|
|
+ List<ItemEquipmentMap> itemEquipmentMaps = itemEquipmentMapRepository.getList();
|
|
|
+ //医疗服务项目的使用空间信息
|
|
|
+ List<ItemSpaceMap> itemSpaceMaps = itemSpaceMapRepository.getList();
|
|
|
+ //科室责任中心对照信息
|
|
|
+ List<ResponsibilityDepartIdVO> responsibilityDeptMaps = responsibilityDepartmentRepository.getResponsibility(currentUser.getHospId());
|
|
|
+ //分摊参数设置信息
|
|
|
+ List<ShareParamTypeMap> shareParamTypeMaps = shareParamTypeMapRepository.getList();
|
|
|
+ //医疗服务项目分类字典
|
|
|
+ DictDataVo itemTypeDict = centerService.getDict(Constant.MED_SERVICE_ITEM_TYPE);
|
|
|
+ //月度患者收费项目信息
|
|
|
+ List<PatientItemDepartmentGroupVo> ptChargeItems = importPatientItemRepository.getByDepartGroupComputeDateItem(computeDate, currentUser);
|
|
|
+ if (CollectionUtils.isEmpty(ptChargeItems)){
|
|
|
+ throw new CostException("没有可计算的收费项目");
|
|
|
+ }
|
|
|
+// //筛选出字典维护了的项目
|
|
|
+// List<PatientItemDepartmentGroupVo> activePtChargeItems = ptChargeItems.stream().filter(ptItem -> {
|
|
|
+// //科室项目字典维护了的数据
|
|
|
+// if (itemList.stream().anyMatch(item -> item.getCode().equals(ptItem.getItemCode()) && item.getDepartmentCode().equals(ptItem.getExecuteDepartmentCode()))) {
|
|
|
+// return true;
|
|
|
+// }
|
|
|
+// //全院项目字典维护了的数据
|
|
|
+// if (itemList.stream().anyMatch(item -> item.getCode().equals(ptItem.getItemCode()) && item.getDepartmentCode().equals(NumberConstant.ZERO))) {
|
|
|
+// return true;
|
|
|
+// }
|
|
|
+// return false;
|
|
|
+// }).collect(Collectors.toList());
|
|
|
+// if (CollectionUtils.isEmpty(activePtChargeItems)){
|
|
|
+// throw new CostException("所有收费项目都没有对应的字典数据,请联系管理员");
|
|
|
+// }
|
|
|
+ //绑定收费项目对应的医疗服务型项目字典对象
|
|
|
+ ptChargeItems.stream().forEach(ptItem->{
|
|
|
+ Item item = getDicItem(ptItem,itemList);
|
|
|
+ ptItem.setDicItem(item);
|
|
|
+ });
|
|
|
+ List<ComputeShareParam> computeShareParamList = new ArrayList();
|
|
|
+ List<ComputeShareParamDetail> ComputeShareParamDetailList = new ArrayList();
|
|
|
+ ptChargeItems.stream().forEach(ptItem->{
|
|
|
+ //只处理字典有项目
|
|
|
+ if(!Objects.isNull(ptItem.getDicItem())) {
|
|
|
+ //根据收费项目创建分摊参数主表对象
|
|
|
+ ComputeShareParam computeShareCost = creatComputeShareParam(currentUser, computeDate, ptItem, itemTypeDict, responsibilityDeptMaps);
|
|
|
+ computeShareParamList.add(computeShareCost);
|
|
|
+ //创建分摊参数主表对象对应的明细对象
|
|
|
+ shareParamTypeMaps.stream().forEach(shareParamType -> {
|
|
|
+ ComputeShareParamDetail computeShareParamDetail = createComputeShareParamDetail(currentUser, computeDate, ptItem, computeShareCost, shareParamType, itemEmpMaps, itemEquipmentMaps, itemSpaceMaps);
|
|
|
+ ComputeShareParamDetailList.add(computeShareParamDetail);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //没有任何可保存的数据
|
|
|
+ if (CollectionUtils.isEmpty(computeShareParamList)) {
|
|
|
+ throw new CostException("没有任何可保存的数据");
|
|
|
+ }
|
|
|
+ //保存分摊参数主表对象数据
|
|
|
+ repository.saveBatch(computeShareParamList, 500);
|
|
|
+ if (CollectionUtils.isEmpty(ComputeShareParamDetailList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //保存分摊参数明细表对象数据
|
|
|
+ ComputeShareParamDetailList.stream().forEach(shareParamDetailL->shareParamDetailL.setShareParamId(shareParamDetailL.getComputeShareCost().getId()));
|
|
|
+ detailRepository.saveBatch(ComputeShareParamDetailList, 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取收费项目对应的医疗服务项目字典对象
|
|
|
+ * @param ptItem
|
|
|
+ * @param itemList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Item getDicItem(PatientItemDepartmentGroupVo ptItem,List<Item> itemList){
|
|
|
+ //优先取科室项目字典的记录
|
|
|
+ Optional<Item> first = itemList.stream().filter(dicItem -> dicItem.getCode().equals(ptItem.getItemCode()) && dicItem.getDepartmentCode().equals(ptItem.getExecuteDepartmentCode())).findFirst();
|
|
|
+ if(first.isPresent()) {
|
|
|
+ return first.get();
|
|
|
+ }
|
|
|
+ //取全院通用的字典记录
|
|
|
+ first = itemList.stream().filter(dicItem -> dicItem.getCode().equals(ptItem.getItemCode()) && dicItem.getDepartmentCode().equals(NumberConstant.ZERO)).findFirst();
|
|
|
+ if(first.isPresent()) {
|
|
|
+ return first.get();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据收费项目创建分摊参数主表对象
|
|
|
+ * @param currentUser
|
|
|
+ * @param computeDate
|
|
|
+ * @param itemTypeDict
|
|
|
+ * @param ptItem
|
|
|
+ * @param responsibilityDeptMaps
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ComputeShareParam creatComputeShareParam(SessionUserVO currentUser,String computeDate,PatientItemDepartmentGroupVo ptItem,DictDataVo itemTypeDict, List<ResponsibilityDepartIdVO> responsibilityDeptMaps){
|
|
|
+ ComputeShareParam computeShareCost = new ComputeShareParam();
|
|
|
+ computeShareCost.setComputeDate(computeDate);
|
|
|
+ computeShareCost.setHospId(currentUser.getHospId());
|
|
|
+ computeShareCost.setCreateUser(String.valueOf(currentUser.getId()));
|
|
|
+ computeShareCost.setCreateTime(new Date());
|
|
|
+ computeShareCost.setCode(ptItem.getItemCode());
|
|
|
+ computeShareCost.setName(ptItem.getItemName());
|
|
|
+ computeShareCost.setNum(ptItem.getNum());
|
|
|
+ //获取执行科室对应的责任中心
|
|
|
+ ResponsibilityDepartIdVO responsibilityDepartIdVO = responsibilityDeptMaps.stream().filter(respDeptmap -> respDeptmap.getDepartmentCode().equals(ptItem.getExecuteDepartmentCode())).findFirst().get();
|
|
|
+ if(Objects.isNull(responsibilityDepartIdVO)){
|
|
|
+ String errMsg = String.format("【%s(%s)】没有对应的责任中心,计算中止", ptItem.getExecuteDepartmentName(), ptItem.getExecuteDepartmentCode());
|
|
|
+ throw new CostException(errMsg);
|
|
|
+ }
|
|
|
+ computeShareCost.setResponsibilityCode(responsibilityDepartIdVO.getResponsibilityCode());
|
|
|
+ computeShareCost.setResponsibilityName(responsibilityDepartIdVO.getResponsibilityName());
|
|
|
+ computeShareCost.setItemType(getChargeItemType(itemTypeDict,responsibilityDepartIdVO.getShareId()));
|
|
|
+ return computeShareCost;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据收费项目创建分摊参数明细表对象
|
|
|
+ * @param currentUser
|
|
|
+ * @param computeDate
|
|
|
+ * @param ptItem
|
|
|
+ * @param computeShareCost
|
|
|
+ * @param shareParamType
|
|
|
+ * @param itemEmpMaps
|
|
|
+ * @param itemEquipmentMaps
|
|
|
+ * @param itemSpaceMaps
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ComputeShareParamDetail createComputeShareParamDetail( SessionUserVO currentUser,String computeDate,PatientItemDepartmentGroupVo ptItem,ComputeShareParam computeShareCost,ShareParamTypeMap shareParamType,
|
|
|
+ List<ItemEmpMap> itemEmpMaps,List<ItemEquipmentMap> itemEquipmentMaps ,List<ItemSpaceMap> itemSpaceMaps){
|
|
|
+ //明细表公共对象
|
|
|
+ ComputeShareParamDetail costDetail = new ComputeShareParamDetail();
|
|
|
+ costDetail.setComputeDate(computeDate);
|
|
|
+ costDetail.setHospId(currentUser.getHospId());
|
|
|
+ costDetail.setCreateUser(String.valueOf(currentUser.getId()));
|
|
|
+ costDetail.setCreateTime(new Date());
|
|
|
+ costDetail.setShareParamCode(shareParamType.getShareParamCode());
|
|
|
+ if(shareParamType.getSourceType().equals(NumberConstant.ONE_S)){
|
|
|
+ //计算参与人员的参数值
|
|
|
+ BigDecimal computeSingleResult = calcEmpParamValue(shareParamType, ptItem, itemEmpMaps);
|
|
|
+ costDetail.setComputeSingleResult(computeSingleResult);
|
|
|
+ costDetail.setComputeResult(computeSingleResult.multiply(ptItem.getNum()));
|
|
|
+ }else if(shareParamType.getSourceType().equals(NumberConstant.TWO_S)){
|
|
|
+ //计算使用设备的参数值
|
|
|
+ BigDecimal computeSingleResult = calcEquipmentParamValue(shareParamType, ptItem, itemEquipmentMaps);
|
|
|
+ costDetail.setComputeSingleResult(computeSingleResult);
|
|
|
+ costDetail.setComputeResult(computeSingleResult.multiply(ptItem.getNum()));
|
|
|
+ }else if(shareParamType.getSourceType().equals(NumberConstant.THREE_S)){
|
|
|
+ //计算使用空间的参数值
|
|
|
+ BigDecimal computeSingleResult = calcSpaceParamValue(shareParamType, ptItem, itemSpaceMaps);
|
|
|
+ costDetail.setComputeSingleResult(computeSingleResult);
|
|
|
+ costDetail.setComputeResult(computeSingleResult.multiply(ptItem.getNum()));
|
|
|
+ }else if(shareParamType.getSourceType().equals(NumberConstant.FOUR_S)){
|
|
|
+ //计算项目收入的参数值
|
|
|
+ BigDecimal computeResult = ptItem.getAmount();
|
|
|
+ if (!ptItem.getNum().equals(BigDecimal.ZERO.setScale(NumberConstant.TWO, RoundingMode.HALF_UP))) {
|
|
|
+ costDetail.setComputeSingleResult(computeResult.divide(ptItem.getNum(), NumberConstant.FOUR, RoundingMode.HALF_UP));
|
|
|
+ } else {
|
|
|
+ costDetail.setComputeSingleResult(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ costDetail.setComputeResult(computeResult);
|
|
|
+ }else if(shareParamType.getSourceType().equals(NumberConstant.FIVE_S)){
|
|
|
+ //计算项目数量的参数值
|
|
|
+ BigDecimal computeResult = ptItem.getNum();
|
|
|
+ costDetail.setComputeSingleResult(BigDecimal.ONE);
|
|
|
+ costDetail.setComputeResult(computeResult);
|
|
|
+ }
|
|
|
+ costDetail.setComputeShareCost(computeShareCost);
|
|
|
+ return costDetail;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算参与人员的参数值
|
|
|
+ * @param ptItem
|
|
|
+ * @param itemEmpMaps
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public BigDecimal calcEmpParamValue(ShareParamTypeMap shareParamType,PatientItemDepartmentGroupVo ptItem,List<ItemEmpMap> itemEmpMaps){
|
|
|
+ //没有人员配置
|
|
|
+ if(CollectionUtils.isEmpty(itemEmpMaps)){
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ String sourceCode = shareParamType.getSourceCode();
|
|
|
+ //没有维护对应的来源代码
|
|
|
+ if(Objects.isNull(sourceCode)||sourceCode.equals(Constant.EMPTY_STR)){
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ //获取项目对应的参与人员配置
|
|
|
+ List<ItemEmpMap> itemEmpList = itemEmpMaps.stream().filter(itemEmp -> itemEmp.getItemCode().equals(ptItem.getDicItem().getCode()) && itemEmp.getDepartmentCode().equals(ptItem.getDicItem().getDepartmentCode())).collect(Collectors.toList());
|
|
|
+ if(CollectionUtils.isEmpty(itemEmpList)){
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ BigDecimal paramValue=BigDecimal.ZERO;
|
|
|
+ //全部项目
|
|
|
+ if(sourceCode.equals(NumberConstant.ZERO_S)){
|
|
|
+ paramValue = itemEmpList.stream().map(itemEmp -> itemEmp.getExecuteTime().multiply(itemEmp.getNum())).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ return paramValue;
|
|
|
+ }
|
|
|
+ //不是全部的项目时,有可能会是多个
|
|
|
+ List<String> sourceCodeList = StrUtil.split(sourceCode, "|");
|
|
|
+ //获取符合条件的项目
|
|
|
+ List<ItemEmpMap> activeItemEmpList = itemEmpList.stream().filter(itemEmp -> sourceCodeList.contains(itemEmp.getEmpTypeCode())).collect(Collectors.toList());
|
|
|
+ if(CollectionUtils.isEmpty(activeItemEmpList)){
|
|
|
+ return paramValue;
|
|
|
+ }
|
|
|
+ //只统计符合条件的项目
|
|
|
+ paramValue = activeItemEmpList.stream().map(itemEmp -> itemEmp.getExecuteTime().multiply(itemEmp.getNum())).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ return paramValue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算使用设备参数值
|
|
|
+ * @param shareParamType
|
|
|
+ * @param ptItem
|
|
|
+ * @param itemEquipmentMaps
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public BigDecimal calcEquipmentParamValue(ShareParamTypeMap shareParamType,PatientItemDepartmentGroupVo ptItem,List<ItemEquipmentMap> itemEquipmentMaps){
|
|
|
+ //没有人员配置
|
|
|
+ if(CollectionUtils.isEmpty(itemEquipmentMaps)){
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ String sourceCode = shareParamType.getSourceCode();
|
|
|
+ //没有维护对应的来源代码
|
|
|
+ if(Objects.isNull(sourceCode)||sourceCode.equals(Constant.EMPTY_STR)){
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ //获取项目对应的使用设备配置
|
|
|
+ List<ItemEquipmentMap> itemEquipmentList = itemEquipmentMaps.stream().filter(itemEmp -> itemEmp.getItemCode().equals(ptItem.getDicItem().getCode()) && itemEmp.getDepartmentCode().equals(ptItem.getDicItem().getDepartmentCode())).collect(Collectors.toList());
|
|
|
+ if(CollectionUtils.isEmpty(itemEquipmentList)){
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ BigDecimal paramValue=BigDecimal.ZERO;
|
|
|
+ //全部项目
|
|
|
+ if(sourceCode.equals(NumberConstant.ZERO_S)){
|
|
|
+ paramValue = itemEquipmentList.stream().map(itemEmp -> itemEmp.getExecuteTime().multiply(itemEmp.getNum())).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ return paramValue;
|
|
|
+ }
|
|
|
+ //不是全部的项目时,有可能会是多个
|
|
|
+ List<String> sourceCodeList = StrUtil.split(sourceCode, "|");
|
|
|
+ //获取符合条件的项目
|
|
|
+ List<ItemEquipmentMap> activeItemEquipmentList = itemEquipmentList.stream().filter(itemEmp -> sourceCodeList.contains(itemEmp.getEquipmentCode())).collect(Collectors.toList());
|
|
|
+ if(CollectionUtils.isEmpty(activeItemEquipmentList)){
|
|
|
+ return paramValue;
|
|
|
+ }
|
|
|
+ //只统计符合条件的项目
|
|
|
+ paramValue = activeItemEquipmentList.stream().map(itemEmp -> itemEmp.getExecuteTime().multiply(itemEmp.getNum())).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ return paramValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算使用空间参数值
|
|
|
+ * @param shareParamType
|
|
|
+ * @param ptItem
|
|
|
+ * @param itemSpaceMaps
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public BigDecimal calcSpaceParamValue(ShareParamTypeMap shareParamType,PatientItemDepartmentGroupVo ptItem,List<ItemSpaceMap> itemSpaceMaps){
|
|
|
+ //没有人员配置
|
|
|
+ if(CollectionUtils.isEmpty(itemSpaceMaps)){
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ String sourceCode = shareParamType.getSourceCode();
|
|
|
+ //没有维护对应的来源代码
|
|
|
+ if(Objects.isNull(sourceCode)||sourceCode.equals(Constant.EMPTY_STR)){
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ //获取项目对应的使用空间配置
|
|
|
+ List<ItemSpaceMap> itemSpaceList = itemSpaceMaps.stream().filter(itemEmp -> itemEmp.getItemCode().equals(ptItem.getDicItem().getCode()) && itemEmp.getDepartmentCode().equals(ptItem.getDicItem().getDepartmentCode())).collect(Collectors.toList());
|
|
|
+ if(CollectionUtils.isEmpty(itemSpaceList)){
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ BigDecimal paramValue=BigDecimal.ZERO;
|
|
|
+ //全部项目
|
|
|
+ if(sourceCode.equals(NumberConstant.ZERO_S)){
|
|
|
+ paramValue = itemSpaceList.stream().map(itemEmp -> itemEmp.getExecuteTime().multiply(itemEmp.getNum())).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ return paramValue;
|
|
|
+ }
|
|
|
+ //不是全部的项目时,有可能会是多个
|
|
|
+ List<String> sourceCodeList = StrUtil.split(sourceCode, "|");
|
|
|
+ //获取符合条件的项目
|
|
|
+ List<ItemSpaceMap> activeItemSpaceList = itemSpaceList.stream().filter(itemEmp -> sourceCodeList.contains(itemEmp.getSpaceCode())).collect(Collectors.toList());
|
|
|
+ if(CollectionUtils.isEmpty(activeItemSpaceList)){
|
|
|
+ return paramValue;
|
|
|
+ }
|
|
|
+ //只统计符合条件的项目
|
|
|
+ paramValue = activeItemSpaceList.stream().map(itemEmp -> itemEmp.getExecuteTime().multiply(itemEmp.getNum())).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ return paramValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据责任中心获取医疗服务项目分类
|
|
|
+ * @param dict
|
|
|
+ * @param shareLevelId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getChargeItemType(DictDataVo dict,Long shareLevelId){
|
|
|
+ List<DictDataVo> dataVoList= dict.getDataVoList();
|
|
|
+ if(CollectionUtils.isEmpty(dataVoList)){
|
|
|
+ return NumberConstant.ONE_S;
|
|
|
+ }
|
|
|
+ DictDataVo dictDataVo = dataVoList.stream().filter(dataVo -> dataVo.getValue().equals(shareLevelId.toString())).findFirst().get();
|
|
|
+ return NumberConstant.ONE_S;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 执行完全法项目分摊参数计算后续处理脚本
|
|
|
* @param computeDate
|