Compare commits
2 Commits
c29ced658a
...
3d55104873
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d55104873 | ||
|
|
8ed023cbf8 |
@ -1,14 +1,17 @@
|
|||||||
package com.czlis.interfaceCommon.utils;
|
package com.czlis.interfaceCommon.utils;
|
||||||
|
import com.czlis.common.core.domain.entity.lis.LabPat;
|
||||||
|
import com.czlis.common.core.domain.entity.lis.LabResult;
|
||||||
|
import com.czlis.common.core.domain.entity.lis.XmCalc;
|
||||||
|
import com.czlis.common.core.domain.entity.lis.XmInfo;
|
||||||
import org.springframework.expression.Expression;
|
import org.springframework.expression.Expression;
|
||||||
import org.springframework.expression.ExpressionParser;
|
import org.springframework.expression.ExpressionParser;
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Stack;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class CalcUtils {
|
public class CalcUtils {
|
||||||
/**
|
/**
|
||||||
@ -19,6 +22,14 @@ public class CalcUtils {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String getValueFromCalc(String CalcExpression, Map<String, String> variableMap,String def) {
|
public static String getValueFromCalc(String CalcExpression, Map<String, String> variableMap,String def) {
|
||||||
|
Map<String, String> refmap=getValueFromCalcbase(CalcExpression,variableMap);
|
||||||
|
if("-1".equals(refmap.get("code")))return def;
|
||||||
|
return refmap.get("msg");
|
||||||
|
}
|
||||||
|
public static Map<String,String> getValueFromCalcbase(String CalcExpression, Map<String, String> variableMap) {
|
||||||
|
Map<String, String> refmap = new HashMap<>();
|
||||||
|
refmap.put("code","0");
|
||||||
|
refmap.put("msg","");
|
||||||
ExpressionParser parser = new SpelExpressionParser();
|
ExpressionParser parser = new SpelExpressionParser();
|
||||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||||
variableMap=replaceAllSpecialKeys(variableMap);
|
variableMap=replaceAllSpecialKeys(variableMap);
|
||||||
@ -38,7 +49,7 @@ public class CalcUtils {
|
|||||||
|
|
||||||
// 安全转换为String
|
// 安全转换为String
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
return ""; // 空值返回空字符串(或根据业务返回null)
|
return refmap; // 空值返回空字符串(或根据业务返回null)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 特殊处理数字类型,避免科学计数法(如1000000.0 → "1000000")
|
// 特殊处理数字类型,避免科学计数法(如1000000.0 → "1000000")
|
||||||
@ -46,18 +57,23 @@ public class CalcUtils {
|
|||||||
Number num = (Number) result;
|
Number num = (Number) result;
|
||||||
// 判断是否为整数(无小数部分)
|
// 判断是否为整数(无小数部分)
|
||||||
if (num.doubleValue() == Math.floor(num.doubleValue())) {
|
if (num.doubleValue() == Math.floor(num.doubleValue())) {
|
||||||
return String.valueOf(num.longValue());
|
refmap.put("msg",String.valueOf(num.longValue()));
|
||||||
|
return refmap;
|
||||||
} else {
|
} else {
|
||||||
return String.valueOf(num.doubleValue());
|
refmap.put("msg",String.valueOf(num.doubleValue()));
|
||||||
|
return refmap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 其他类型直接调用toString()
|
// 其他类型直接调用toString()
|
||||||
return result.toString();
|
refmap.put("msg",result.toString());
|
||||||
|
return refmap;
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//throw new RuntimeException("表达式计算失败: " + expression, e);
|
//throw new RuntimeException("表达式计算失败: " + expression, e);
|
||||||
return def;
|
refmap.put("code","-1");
|
||||||
|
refmap.put("msg",e.getMessage());
|
||||||
|
return refmap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static boolean getnumbervalue(String keyname) {
|
public static boolean getnumbervalue(String keyname) {
|
||||||
@ -381,6 +397,88 @@ public class CalcUtils {
|
|||||||
return str.matches(regex);
|
return str.matches(regex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算公式校验方法
|
||||||
|
* @param CalcExpression 公式内容
|
||||||
|
* @param Calctype 校验种类(1:计算项目,2:特定危急值,3:审核条件,4:其他PB公式)
|
||||||
|
* @return 返回值map->code=0成功code=-1失败,msg为失败原因
|
||||||
|
*/
|
||||||
|
public static Map<String,String> checkcalc(String CalcExpression,String Calctype) {
|
||||||
|
Map<String, String> variables = new HashMap<>();
|
||||||
|
String[] parameters = CalcUtils.getParameters(CalcExpression);
|
||||||
|
if("1".equals(Calctype)) {
|
||||||
|
for (String itemcode : parameters) {
|
||||||
|
if ("SEX".equals(itemcode)) {
|
||||||
|
variables.put("SEX", "1");
|
||||||
|
} else if ("AGE".equals(itemcode)) {
|
||||||
|
variables.put("AGE", "25");
|
||||||
|
} else {
|
||||||
|
variables.put(itemcode, "2.2");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getValueFromCalcbase(CalcExpression, variables);
|
||||||
|
}
|
||||||
|
if("2".equals(Calctype)) {
|
||||||
|
variables.put("CB", "1");
|
||||||
|
variables.put("DEPT", "内科");
|
||||||
|
variables.put("DIAG", "无");
|
||||||
|
variables.put("YBZT", "无");
|
||||||
|
variables.put("RESULT", "12.3");
|
||||||
|
return getValueFromCalcbase(CalcExpression, variables);
|
||||||
|
}
|
||||||
|
if("3".equals(Calctype)) {
|
||||||
|
for (String itemcode : parameters) {
|
||||||
|
switch (itemcode) {
|
||||||
|
case "SEX":
|
||||||
|
variables.put(itemcode, "1");
|
||||||
|
break;
|
||||||
|
case "AGE":
|
||||||
|
variables.put(itemcode,"1.1");
|
||||||
|
break;
|
||||||
|
case "BRLY":
|
||||||
|
variables.put(itemcode, "1");
|
||||||
|
break;
|
||||||
|
case "KSDH":
|
||||||
|
variables.put(itemcode, "111");
|
||||||
|
break;
|
||||||
|
case "YBLX":
|
||||||
|
variables.put(itemcode, "血");
|
||||||
|
break;
|
||||||
|
case "BZ":
|
||||||
|
variables.put(itemcode, "aaa");
|
||||||
|
break;
|
||||||
|
case "ZD":
|
||||||
|
variables.put(itemcode, "aaa");
|
||||||
|
break;
|
||||||
|
case "ANY_NUMER":
|
||||||
|
variables.put(itemcode, "1.1");
|
||||||
|
break;
|
||||||
|
case "ANY_TEXT":
|
||||||
|
variables.put(itemcode, "aaa");
|
||||||
|
break;
|
||||||
|
case "ANY_CRI":
|
||||||
|
variables.put(itemcode, "H");
|
||||||
|
break;
|
||||||
|
case "ANY_REV":
|
||||||
|
variables.put(itemcode, "1");
|
||||||
|
break;
|
||||||
|
case "ANY_JGBZ":
|
||||||
|
variables.put(itemcode, "H");
|
||||||
|
break;
|
||||||
|
case "ANY_ID":
|
||||||
|
variables.put(itemcode, "WBC");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
variables.put(itemcode, "1.1");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getValueFromCalcbase(CalcExpression, variables);
|
||||||
|
}
|
||||||
|
Map<String, String> refmap = new HashMap<>();
|
||||||
|
refmap.put("code","0");
|
||||||
|
refmap.put("msg","");
|
||||||
|
return refmap;
|
||||||
|
}
|
||||||
// 测试
|
// 测试
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Map<String, String> variables = new HashMap<>();
|
Map<String, String> variables = new HashMap<>();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user