计算公式错误

This commit is contained in:
tangw 2025-09-23 19:11:20 +08:00
parent bfa637c393
commit fd7a7c0cbf
3 changed files with 23 additions and 16 deletions

View File

@ -23,7 +23,7 @@ public class CalcUtils {
variableMap=replaceAllSpecialKeys(variableMap);
for (Map.Entry<String, String> entry : variableMap.entrySet()) {
String str = entry.getValue();
if (isNumber(str)) {
if (isNumber(str) && getnumbervalue(entry.getKey())) {
context.setVariable(entry.getKey(), Double.parseDouble(str));
} else {
context.setVariable(entry.getKey(), entry.getValue());
@ -55,12 +55,18 @@ public class CalcUtils {
return result.toString();
} catch (Exception e) {
throw new RuntimeException("表达式计算失败: " + expression, e);
//throw new RuntimeException("表达式计算失败: " + expression, e);
return "0";
}
}
public static boolean getnumbervalue(String keyname) {
if("DEPT".equals(keyname))return false;
if("GIAG".equals(keyname))return false;
if("YBZT".equals(keyname))return false;
return true;
}
public static boolean getBooleanFromCalc(String CalcExpression, Map<String, String> variableMap) {
String resultcondition = "if((" + CalcExpression + ") ,1,0)";
String resultcondition = "if(" + CalcExpression + ",1,0)";
String result1 = getValueFromCalc(resultcondition, variableMap);
if ("1".equals(result1)) return true;
return false;
@ -142,6 +148,9 @@ public class CalcUtils {
* 递归解析并替换if表达式
*/
private static String processIf(String expr) {
expr = expr.replace("IF(", "if(");
expr = expr.replace("IF (", "if(");
expr = expr.replace("if (", "if(");
int start = expr.indexOf("if(");
if (start == -1) {
return expr;
@ -336,15 +345,15 @@ public class CalcUtils {
// 测试
public static void main(String[] args) {
Map<String, String> variables = new HashMap<>();
variables.put("SEX", "1");
variables.put("DEPT", "0123");
variables.put("CREA", "30.3");
variables.put("AGE", "30");
// 示例值
// variables.put("TP", "6.0");
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)";
String testCalc = "[DEPT] like '%内分泌%'";
// testCalc=testCalc.replace("[结果]", "[RESULT]");
//System.out.println(getCalc(testCalc));
System.out.println(getValueFromCalc(testCalc,variables));
System.out.println(getBooleanFromCalc(testCalc,variables));
}
}

View File

@ -339,7 +339,7 @@ public class CheckResultUtils {
}
}
flag = CalcUtils.getBooleanFromCalc(checkrules, variables);
if (flag = true) errmsg = "审核条件: " + ruledisplay + " 规则触发,未通过审核!";
if (flag) errmsg = "审核条件: " + ruledisplay + " 规则触发,未通过审核!";
}
return errmsg;
}

View File

@ -339,7 +339,7 @@ public class LisWorkOperServiceImpl implements LisWorkOperService {
labResultList = saveallresult(labPat, labResultList);
boolean wjz = getAlarmFlag(labResultList);
//同步主表危急值标识
String alarmflag = labPat.getAlarmflag().trim();
String alarmflag = labPat.getAlarmflag();
if (("1".equals(alarmflag) && !wjz)) {
labPat.setAlarmflag("");
commonUtil.updateLabPat(labPat);
@ -1259,22 +1259,20 @@ public class LisWorkOperServiceImpl implements LisWorkOperService {
samplecondition = samplecondition.replace("[诊断]", "[DIAG]");
samplecondition = samplecondition.replace("[样本状态]", "[YBZT]");
Map<String, String> variables = new HashMap<>();
variables.put("ZB", "1");
variables.put("CB", "1");
variables.put("DEPT", ksdh);
variables.put("DIAG", zd);
variables.put("YBZT", ybzt);
samplecondition = "if((" + samplecondition + ") ,1,0)";
String result = CalcUtils.getValueFromCalc(samplecondition, variables);
if ("1".equals(result)) {
boolean ref = CalcUtils.getBooleanFromCalc(samplecondition, variables);
if (ref) {
if (lb_fcb) return 0;
lb_hasval = true;
String resultcondition = xmAlarmdetail.getResultcondition();
resultcondition = resultcondition.replace("[结果]", "[RESULT]");
Map<String, String> variables1 = new HashMap<>();
variables1.put("RESULT", csjg);
resultcondition = "if((" + resultcondition + ") ,1,0)";
String result1 = CalcUtils.getValueFromCalc(resultcondition, variables1);
if ("1".equals(result1)) return 1;
boolean ref1 = CalcUtils.getBooleanFromCalc(resultcondition, variables1);
if (ref1) return 1;
}
}
if (lb_hasval) return 0;