计算公式错误
This commit is contained in:
parent
bfa637c393
commit
fd7a7c0cbf
@ -23,7 +23,7 @@ public class CalcUtils {
|
|||||||
variableMap=replaceAllSpecialKeys(variableMap);
|
variableMap=replaceAllSpecialKeys(variableMap);
|
||||||
for (Map.Entry<String, String> entry : variableMap.entrySet()) {
|
for (Map.Entry<String, String> entry : variableMap.entrySet()) {
|
||||||
String str = entry.getValue();
|
String str = entry.getValue();
|
||||||
if (isNumber(str)) {
|
if (isNumber(str) && getnumbervalue(entry.getKey())) {
|
||||||
context.setVariable(entry.getKey(), Double.parseDouble(str));
|
context.setVariable(entry.getKey(), Double.parseDouble(str));
|
||||||
} else {
|
} else {
|
||||||
context.setVariable(entry.getKey(), entry.getValue());
|
context.setVariable(entry.getKey(), entry.getValue());
|
||||||
@ -55,12 +55,18 @@ public class CalcUtils {
|
|||||||
return result.toString();
|
return result.toString();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} 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) {
|
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);
|
String result1 = getValueFromCalc(resultcondition, variableMap);
|
||||||
if ("1".equals(result1)) return true;
|
if ("1".equals(result1)) return true;
|
||||||
return false;
|
return false;
|
||||||
@ -142,6 +148,9 @@ public class CalcUtils {
|
|||||||
* 递归解析并替换if表达式
|
* 递归解析并替换if表达式
|
||||||
*/
|
*/
|
||||||
private static String processIf(String expr) {
|
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(");
|
int start = expr.indexOf("if(");
|
||||||
if (start == -1) {
|
if (start == -1) {
|
||||||
return expr;
|
return expr;
|
||||||
@ -336,15 +345,15 @@ public class CalcUtils {
|
|||||||
// 测试
|
// 测试
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Map<String, String> variables = new HashMap<>();
|
Map<String, String> variables = new HashMap<>();
|
||||||
variables.put("SEX", "1");
|
variables.put("DEPT", "0123");
|
||||||
variables.put("CREA", "30.3");
|
variables.put("CREA", "30.3");
|
||||||
variables.put("AGE", "30");
|
variables.put("AGE", "30");
|
||||||
// 示例值
|
// 示例值
|
||||||
// variables.put("TP", "6.0");
|
// 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]");
|
// testCalc=testCalc.replace("[结果]", "[RESULT]");
|
||||||
//System.out.println(getCalc(testCalc));
|
//System.out.println(getCalc(testCalc));
|
||||||
System.out.println(getValueFromCalc(testCalc,variables));
|
System.out.println(getBooleanFromCalc(testCalc,variables));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -339,7 +339,7 @@ public class CheckResultUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
flag = CalcUtils.getBooleanFromCalc(checkrules, variables);
|
flag = CalcUtils.getBooleanFromCalc(checkrules, variables);
|
||||||
if (flag = true) errmsg = "审核条件: " + ruledisplay + " 规则触发,未通过审核!";
|
if (flag) errmsg = "审核条件: " + ruledisplay + " 规则触发,未通过审核!";
|
||||||
}
|
}
|
||||||
return errmsg;
|
return errmsg;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -339,7 +339,7 @@ public class LisWorkOperServiceImpl implements LisWorkOperService {
|
|||||||
labResultList = saveallresult(labPat, labResultList);
|
labResultList = saveallresult(labPat, labResultList);
|
||||||
boolean wjz = getAlarmFlag(labResultList);
|
boolean wjz = getAlarmFlag(labResultList);
|
||||||
//同步主表危急值标识
|
//同步主表危急值标识
|
||||||
String alarmflag = labPat.getAlarmflag().trim();
|
String alarmflag = labPat.getAlarmflag();
|
||||||
if (("1".equals(alarmflag) && !wjz)) {
|
if (("1".equals(alarmflag) && !wjz)) {
|
||||||
labPat.setAlarmflag("");
|
labPat.setAlarmflag("");
|
||||||
commonUtil.updateLabPat(labPat);
|
commonUtil.updateLabPat(labPat);
|
||||||
@ -1259,22 +1259,20 @@ public class LisWorkOperServiceImpl implements LisWorkOperService {
|
|||||||
samplecondition = samplecondition.replace("[诊断]", "[DIAG]");
|
samplecondition = samplecondition.replace("[诊断]", "[DIAG]");
|
||||||
samplecondition = samplecondition.replace("[样本状态]", "[YBZT]");
|
samplecondition = samplecondition.replace("[样本状态]", "[YBZT]");
|
||||||
Map<String, String> variables = new HashMap<>();
|
Map<String, String> variables = new HashMap<>();
|
||||||
variables.put("ZB", "1");
|
variables.put("CB", "1");
|
||||||
variables.put("DEPT", ksdh);
|
variables.put("DEPT", ksdh);
|
||||||
variables.put("DIAG", zd);
|
variables.put("DIAG", zd);
|
||||||
variables.put("YBZT", ybzt);
|
variables.put("YBZT", ybzt);
|
||||||
samplecondition = "if((" + samplecondition + ") ,1,0)";
|
boolean ref = CalcUtils.getBooleanFromCalc(samplecondition, variables);
|
||||||
String result = CalcUtils.getValueFromCalc(samplecondition, variables);
|
if (ref) {
|
||||||
if ("1".equals(result)) {
|
|
||||||
if (lb_fcb) return 0;
|
if (lb_fcb) return 0;
|
||||||
lb_hasval = true;
|
lb_hasval = true;
|
||||||
String resultcondition = xmAlarmdetail.getResultcondition();
|
String resultcondition = xmAlarmdetail.getResultcondition();
|
||||||
resultcondition = resultcondition.replace("[结果]", "[RESULT]");
|
resultcondition = resultcondition.replace("[结果]", "[RESULT]");
|
||||||
Map<String, String> variables1 = new HashMap<>();
|
Map<String, String> variables1 = new HashMap<>();
|
||||||
variables1.put("RESULT", csjg);
|
variables1.put("RESULT", csjg);
|
||||||
resultcondition = "if((" + resultcondition + ") ,1,0)";
|
boolean ref1 = CalcUtils.getBooleanFromCalc(resultcondition, variables1);
|
||||||
String result1 = CalcUtils.getValueFromCalc(resultcondition, variables1);
|
if (ref1) return 1;
|
||||||
if ("1".equals(result1)) return 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (lb_hasval) return 0;
|
if (lb_hasval) return 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user