主业务添加代码

This commit is contained in:
tangw 2025-09-03 19:26:35 +08:00
parent 59bb8a7b97
commit 366e1ea1e1
5 changed files with 122 additions and 89 deletions

View File

@ -20,6 +20,7 @@ public class CalcUtils {
public static String getValueFromCalc(String CalcExpression, Map<String, String> variableMap) {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
variableMap=replaceAllSpecialKeys(variableMap);
for (Map.Entry<String, String> entry : variableMap.entrySet()) {
String str = entry.getValue();
if (isNumber(str)) {
@ -57,13 +58,29 @@ public class CalcUtils {
throw new RuntimeException("表达式计算失败: " + expression, e);
}
}
public static boolean getBooleanFromCalc(String CalcExpression, Map<String, String> variableMap) {
String resultcondition = "if((" + CalcExpression + ") ,1,0)";
String result1 = getValueFromCalc(resultcondition, variableMap);
if ("1".equals(result1)) return true;
return false;
}
/**
* 批量替换Map中所有包含"/"的键(将"/"改为"_")
* @param variableMap 原始变量Map
* @return 处理后的Map
*/
public static Map<String, String> replaceAllSpecialKeys(Map<String, String> variableMap) {
Map<String, String> newMap = new HashMap<>();
for (Map.Entry<String, String> entry : variableMap.entrySet()) {
// 将键中所有"/"替换为"_"
String newKey = entry.getKey().replace("/", "_");
newMap.put(newKey, entry.getValue());
}
return newMap;
}
/**
* 此方法把PB的计算公式转换为SpEL表达式
* @param CalcExpression
@ -74,7 +91,8 @@ public class CalcUtils {
// 1. 替换逻辑运算符:and→&&,or→||
String processed = CalcExpression.replaceAll("\\band|AND\\b", "&&").replaceAll("\\bor|OR\\b", "||");
// 2. 替换变量格式:[a] → #a
processed = processed.replaceAll("\\[(\\w+)\\]", "#$1");
processed = processed.replaceAll("\\[(\\w+)/(\\w+)\\]", "[$1_$2]");
processed = processed.replaceAll("\\[([^]]+)\\]", "#$1");
// 3. 替换len()函数为length()方法:len(xxx) → xxx.length()
processed = replaceLenFunction(processed);
//4.like '%aa'或者 like 'aa%'或者 like '%aa%'
@ -318,10 +336,13 @@ public class CalcUtils {
// 测试
public static void main(String[] args) {
Map<String, String> variables = new HashMap<>();
variables.put("RESULT", "4.0"); // 示例值
variables.put("SEX", "1");
variables.put("CREA", "30.3");
variables.put("AGE", "30");
// 示例值
// variables.put("TP", "6.0");
String testCalc = "if(([结果]>7.12) ,1,0)";
testCalc=testCalc.replace("[结果]", "[RESULT]");
String testCalc = "if([AGE]>18,(if([SEX]=1,(( [CREA] / 88.4)^(-1.234)) * ([AGE]^(-0.179))*175 ,(( [CREA] / 88.4)^(-1.234)) * ([AGE]^(-0.179))*175*0.79)),0)";
// testCalc=testCalc.replace("[结果]", "[RESULT]");
//System.out.println(getCalc(testCalc));
System.out.println(getValueFromCalc(testCalc,variables));

View File

@ -31,7 +31,9 @@ public class CheckResultUtils {
String yq = labPat.getYq();
Date jyrq = labPat.getJyrq();
String ybh = labPat.getYbh();
List<XmInfo> xmInfoList = commonUtil.xmInfoMapper.getXmInfoList(yq);
List<XmInfo> xmInfoList0 = commonUtil.getXmInfoList(yq);
List<XmInfo> xmInfoList = xmInfoList0.stream().filter(xmInfo -> xmInfo.getXjx()!=null||xmInfo.getSjx()!=null||xmInfo.getJgjg()!=null||xmInfo.getJgz()!=null||xmInfo.getJgbz()!=null).collect(Collectors.toList());
if(xmInfoList.size()>0) {
for (LabResult labResult : labResultList) {
String xmdh = labResult.getXmdh();
List<XmInfo> collect = xmInfoList.stream().filter(xmInfo -> xmInfo.getXmdh().equals(xmdh)).collect(Collectors.toList());
@ -89,6 +91,7 @@ public class CheckResultUtils {
}
}
}
List<LabChk> labChkList = checkResultMapper.getLabChkList(yq);
for (LabChk labChk : labChkList) {
String jsgs = labChk.getHdnr();
@ -99,8 +102,8 @@ public class CheckResultUtils {
String itemcode = parameters[i];
if ("SEX".equals(itemcode)) {
String sex = labPat.getBrxb().trim();
if ("1".equals(sex)) sex = "男";
if ("2".equals(sex)) sex = "女";
// if ("1".equals(sex)) sex = "男";
// if ("2".equals(sex)) sex = "女";
variables.put("SEX", sex);
} else if ("AGE".equals(itemcode)) {
double age = AgeUtils.getDecimalAge(AgeUtils.getBirthDateByAge(labPat.getNl(), labPat.getNldw()));
@ -117,8 +120,8 @@ public class CheckResultUtils {
//项目不全,此公式跳过
if (setjgsg) {
boolean result = CalcUtils.getBooleanFromCalc(jsgs, variables);
if (!result) {
errmsg = errmsg + LisUtil.LINE_SEPARATOR + "审核条件: " + jsgs + " 未通过!";
if (result) {
errmsg = errmsg + LisUtil.LINE_SEPARATOR + "审核条件: " + jsgs + " 规则触发,未通过审核!";
}
}
@ -164,7 +167,7 @@ public class CheckResultUtils {
params.put("xh", xh);
List<LabCheckrules> labCheckruleslist = labCheckrulesMapper.getLabCheckrules(yq);
if (labCheckruleslist.size() == 0) return params;
if (xh >= labCheckruleslist.size()) return params;
if (xh > labCheckruleslist.size()) return params;
for (int i = xh; i < labCheckruleslist.size(); i++) {
LabCheckrules labCheckrules = labCheckruleslist.get(i);
String checkrules = labCheckrules.getCheckrules();
@ -174,16 +177,17 @@ public class CheckResultUtils {
String errmsg = checkcondition(labPat, labResultList, checkrules, ruledisplay);
if (!"".equals(errmsg)) {
if ("0".equals(checktype)) {
errmsg = "审核未通过,你是否要强行通过?" + ruledisplay + LisUtil.LINE_SEPARATOR + "审核未通过,你是否要强行通过?" + LisUtil.LINE_SEPARATOR + errmsg;
errmsg = "审核规则触发,未通过审核!,你是否要强行通过?" + ruledisplay + LisUtil.LINE_SEPARATOR + "审核规则触发,未通过审核!,你是否要强行通过?" + LisUtil.LINE_SEPARATOR + errmsg;
params.put("code", "5");
params.put("msg", errmsg);
int ruleid0 = labCheckrules.getRuleid();
params.put("xh", i);
params.put("xh", i+1);
return params;
} else if ("3".equals(checktype)) {
errmsg = "审核未通过" + LisUtil.LINE_SEPARATOR + "设置的组合审核条件:" + errmsg + LisUtil.LINE_SEPARATOR + "审核未通过,不允许审核!";
errmsg = "审核规则触发,未通过审核!" + LisUtil.LINE_SEPARATOR + "设置的组合审核条件:" + errmsg + LisUtil.LINE_SEPARATOR + "审核规则触发,未通过审核!,不允许审核!";
params.put("code", "1");
params.put("msg", errmsg);
params.put("xh", i+1);
return params;
} else if ("4".equals(checktype)) {
bz = replacebz(labPat, labResultList, logcontent);
@ -193,6 +197,7 @@ public class CheckResultUtils {
params.put("code", "3");
params.put("msg", errmsg);
params.put("bz", bz);
params.put("xh", i+1);
}
}
}
@ -220,8 +225,8 @@ public class CheckResultUtils {
switch (itemcode) {
case "SEX":
String sex = labPat.getBrxb().trim();
if ("1".equals(sex)) sex = "男";
if ("2".equals(sex)) sex = "女";
// if ("1".equals(sex)) sex = "男";
// if ("2".equals(sex)) sex = "女";
errmsg.replace("[SEX]", sex);
break;
case "AGE":
@ -230,14 +235,14 @@ public class CheckResultUtils {
break;
case "BRLY":
String brly = labPat.getBrly();
String brlymc = commonUtil.getComDictNameById("PT", brly);
if (!"".equals(brlymc) || brlymc != null) brly = brlymc;
// String brlymc = commonUtil.getComDictNameById("PT", brly);
// if (!"".equals(brlymc) || brlymc != null) brly = brlymc;
errmsg.replace("[BRLY]", brly);
break;
case "KSDH":
String ksdh = labPat.getKsdh();
String ksdhmc = commonUtil.getComDictNameById("DP", ksdh);
if (!"".equals(ksdhmc) || ksdhmc != null) ksdh = ksdhmc;
// String ksdhmc = commonUtil.getComDictNameById("DP", ksdh);
// if (!"".equals(ksdhmc) || ksdhmc != null) ksdh = ksdhmc;
errmsg.replace("[KSDH]", ksdh);
break;
case "YBLX":
@ -279,7 +284,7 @@ public class CheckResultUtils {
List<LabResult> labResultList0 = commonUtil.labResultMapper.getLabResultWithSql(labPat.getJyrq(), labPat.getYq(), labPat.getYbh(), errmsg);
if (labResultList0.size() > 0) flag = true;
}
if (flag = true) errmsg = "审核条件: " + ruledisplay + " 未通过!";
if (flag = true) errmsg = "审核条件: " + ruledisplay + " 规则触发,未通过审核!";
} else {
Map<String, String> variables = new HashMap<>();
String[] parameters = CalcUtils.getParameters(checkrules);
@ -288,8 +293,8 @@ public class CheckResultUtils {
switch (itemcode) {
case "SEX":
String sex = labPat.getBrxb().trim();
if ("1".equals(sex)) sex = "男";
if ("2".equals(sex)) sex = "女";
// if ("1".equals(sex)) sex = "男";
// if ("2".equals(sex)) sex = "女";
variables.put(itemcode, sex);
break;
case "AGE":
@ -298,14 +303,14 @@ public class CheckResultUtils {
break;
case "BRLY":
String brly = labPat.getBrly();
String brlymc = commonUtil.getComDictNameById("PT", brly);
if (!"".equals(brlymc) || brlymc != null) brly = brlymc;
// String brlymc = commonUtil.getComDictNameById("PT", brly);
// if (!"".equals(brlymc) || brlymc != null) brly = brlymc;
variables.put(itemcode, brly);
break;
case "KSDH":
String ksdh = labPat.getKsdh();
String ksdhmc = commonUtil.getComDictNameById("DP", ksdh);
if (!"".equals(ksdhmc) || ksdhmc != null) ksdh = ksdhmc;
// String ksdhmc = commonUtil.getComDictNameById("DP", ksdh);
// if (!"".equals(ksdhmc) || ksdhmc != null) ksdh = ksdhmc;
variables.put(itemcode, ksdh);
break;
case "YBLX":
@ -328,7 +333,7 @@ public class CheckResultUtils {
}
}
flag = CalcUtils.getBooleanFromCalc(checkrules, variables);
if (flag = true) errmsg = "审核条件: " + ruledisplay + " 未通过!";
if (flag = true) errmsg = "审核条件: " + ruledisplay + " 规则触发,未通过审核!";
}
return errmsg;
}

View File

@ -20,4 +20,5 @@ public interface LisWorkOperMapper {
Integer checkresultwxh(@Param("jyrq") Date jyrq, @Param("yq") String yq, @Param("ybh") String ybh);
LabPat checkdublereport(@Param("sqh") String sqh, @Param("ybh") String ybh);
LabPat checkyqdublereport(@Param("sqh") String sqh,@Param("yq") String yq, @Param("ybh") String ybh);
Integer getxsws(@Param("yq") String yq, @Param("xmdh") String xmdh);
}

View File

@ -235,7 +235,7 @@ public class LisWorkOperServiceImpl implements LisWorkOperService {
commonUtil.updateLabPat(labPat);
}
//医学审核条件判断
if (problemId < 4) problemId = 4;
if (problemId < 3) problemId = 3;
result = chksample(labPat, problemId);
if ("99".equals(result.getCode())) {
labPat.setBz(result.getMsg());
@ -400,8 +400,8 @@ public class LisWorkOperServiceImpl implements LisWorkOperService {
setReport.setStatus(LisinterfaceNameConstants.REPORTSTART);
Result result = lisInterfaceUtil.invokeLisInterface(LisinterfaceNameConstants.SETREPORT, setReport);
if (result.getCode().equals("5")) {
if (problemId < 5) {
return new Result(result.getCode(), result.getMsg(), 5);
if (problemId < 3) {
return new Result(result.getCode(), result.getMsg(), 3);
}
return new Result("0", "保存成功!");
}
@ -420,21 +420,22 @@ public class LisWorkOperServiceImpl implements LisWorkOperService {
private Result chksample(LabPat labPat, Integer problemId) {
List<LabResult> labResultList = commonUtil.getLabResultList(labPat.getJyrq(), labPat.getYq(), labPat.getYbh());
//医学审核条件判断
if (problemId < 3) {
if (problemId < 4) {
String checkvalue = checkResultUtils.chksample(labPat, labResultList);
if (checkvalue != null && !"".equals(checkvalue)) {
return new Result("5", checkvalue, 3);
return new Result("5", checkvalue, 4);
}
}
Boolean setbz = false;
String bz = labPat.getBz();
//医学审核条件判断(新规则),预留99个递归ID
if (problemId < 4) problemId = 4;
if (problemId < 99) {
int xh = 0;
if (problemId > 4) xh = problemId - 4;
int xh = problemId - 4;
Map<String, Object> chksamplenewvalue = checkResultUtils.chksamplenew(labPat, labResultList, xh);
String chkCode = (String) chksamplenewvalue.get("code");
String chkMsg = (String) chksamplenewvalue.get("code");
String chkMsg = (String) chksamplenewvalue.get("msg");
bz = (String) chksamplenewvalue.get("bz");
labPat.setBz(bz);
xh = (Integer) chksamplenewvalue.get("xh");
@ -759,8 +760,8 @@ public class LisWorkOperServiceImpl implements LisWorkOperService {
String itemcode = parameters[i];
if ("SEX".equals(itemcode)) {
String sex = labPat.getBrxb().trim();
if ("1".equals(sex)) sex = "男";
if ("2".equals(sex)) sex = "女";
// if ("1".equals(sex)) sex = "男";
// if ("2".equals(sex)) sex = "女";
variables.put("SEX", sex);
} else if ("AGE".equals(itemcode)) {
double age = AgeUtils.getDecimalAge(AgeUtils.getBirthDateByAge(labPat.getNl(), labPat.getNldw()));
@ -777,6 +778,10 @@ public class LisWorkOperServiceImpl implements LisWorkOperService {
if (setjgsg) {
String result = CalcUtils.getValueFromCalc(jsgs, variables);
if (result != null && !result.trim().isEmpty()) {
if(LisUtil.isNumber(result)) {
Integer xsws =lisWorkOperMapper.getxsws(yq,xmdh);
if (xsws >= 0) result = LisUtil.round(result, xsws);
}
//插入结果值
LabResult labResult = commonUtil.getLabResult(jyrq, yq, ybh, xmdh);
if (labResult == null) {

View File

@ -79,6 +79,7 @@
<if test="brxm != null and brxm != ''">and lab_pat.brdh = #{brxm}</if>
</where>
</select>
<select id="getxsws" resultType="Integer">
select xsws from xm_info where yq=#{yq} and xmdh=#{xmdh}
</select>
</mapper>