253 lines
12 KiB
Java
Raw Normal View History

2025-08-28 18:13:57 +08:00
package com.czlis.interfaceCommon.utils;
import com.czlis.common.core.domain.Result;
import com.czlis.common.core.domain.entity.lis.*;
import com.czlis.interfaceCommon.mapper.CheckResultMapper;
2025-09-01 19:19:09 +08:00
import com.czlis.interfaceCommon.mapper.LabCheckrulesMapper;
2025-08-28 18:13:57 +08:00
import com.czlis.interfaceCommon.mapper.XmInfoMapper;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component
public class CheckResultUtils {
@Autowired
XmInfoMapper xmInfoMapper;
@Autowired
CheckResultMapper checkResultMapper;
2025-09-01 19:19:09 +08:00
@Autowired
LabCheckrulesMapper labCheckrulesMapper;
2025-08-28 18:13:57 +08:00
public String chksample(LabPat labPat, List<LabResult> labResultList) {
String errmsg = "";
String brdh = labPat.getBrdh();
if (brdh == null || "".equals(brdh)) {
return errmsg;
}
String yq = labPat.getYq();
Date jyrq = labPat.getJyrq();
String ybh = labPat.getYbh();
List<XmInfo> xmInfoList = xmInfoMapper.getXmInfoList(yq);
for (LabResult labResult : labResultList) {
String xmdh = labResult.getXmdh();
List<XmInfo> collect = xmInfoList.stream().filter(xmInfo -> xmInfo.getXmdh().equals(xmdh)).collect(Collectors.toList());
if (collect.size() > 0) {
XmInfo xmInfo = collect.get(0);
//字典规定的结果值范围约束
Double xjx = xmInfo.getXjx();
Double sjx = xmInfo.getSjx();
if (xjx != null || sjx != null) {
String csjg = LisUtil.getOverNumber(labResult.getCsjg());
if (LisUtil.isNumber(csjg)) {
Double csjgnum = Double.parseDouble(csjg);
if (xjx != null && csjgnum <= xjx) {
errmsg = errmsg + LisUtil.LINE_SEPARATOR + xmdh + " 结果超出审核条件";
} else if (sjx != null && csjgnum >= sjx) {
errmsg = errmsg + LisUtil.LINE_SEPARATOR + xmdh + " 结果超出审核条件";
}
}
}
//字典规定的多少天内结果间隔范围约束
Integer jgjg = xmInfo.getJgjg();
Double jgz = xmInfo.getJgz();
String jgbz = xmInfo.getJgbz();
if (jgjg != null && jgjg > 0 && jgz != null && jgz > 0) {
String csjg = LisUtil.getOverNumber(labResult.getCsjg());
if (LisUtil.isNumber(csjg)) {
Double csjgnum = Double.parseDouble(csjg);
Date ldt_startda = LisUtil.relativeDate(jyrq, -jgjg);
Double lde_up = null;
Double lde_low = null;
if ("2".equals(jgbz)) {
lde_up = csjgnum / (1 - jgz / 100);
lde_low = csjgnum / (1 + jgz / 100);
} else {
lde_up = csjgnum + jgz;
lde_low = csjgnum - jgz;
}
List<LabResult> chkval = checkResultMapper.getChkvaList(brdh, ldt_startda, jyrq, yq, xmdh);
List<LabResult> collect0 = chkval.stream().filter(LabResult0 -> LisUtil.isNumber(LabResult0.getCsjg())).collect(Collectors.toList());
if (collect0.size() > 0) {
Double finalLde_up = lde_up;
Double finalLde_low = lde_low;
List<LabResult> collect1 = collect0.stream().filter(LabResult1 -> Double.parseDouble(LabResult1.getCsjg()) > finalLde_up && Double.parseDouble(LabResult1.getCsjg()) < finalLde_low).collect(Collectors.toList());
if (collect0.size() > 0) {
errmsg = errmsg + LisUtil.LINE_SEPARATOR + xmdh + " 结果 (" + labResult.getCsjg() + ") 和 " +
DateFormatUtils.format(collect1.get(0).getJyrq(), "yyyy-MM-dd") + "日" +
collect1.get(0).getYbh() + " 号标本的结果 (" + collect1.get(0).getCsjg() + ") 相比超标";
}
}
}
}
}
}
List<LabChk> labChkList=checkResultMapper.getLabChkList(yq);
for(LabChk labChk:labChkList){
String jsgs=labChk.getHdnr();
boolean setjgsg = true;
Map<String, String> variables = new HashMap<>();
String[] parameters = CalcUtils.getParameters(jsgs);
for (int i = 0; i < parameters.length; i++) {
String itemcode = parameters[i];
if ("SEX".equals(itemcode)) {
String sex = labPat.getBrxb().trim();
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()));
variables.put("AGE", String.valueOf(age));
} else {
List<LabResult> collect = labResultList.stream().filter(result -> result.getXmdh().equals(itemcode)).collect(Collectors.toList());
if (collect.size() > 0) {
variables.put(itemcode, collect.get(0).getCsjg());
} else {
setjgsg = false;
}
}
}
//项目不全,此公式跳过
if(setjgsg) {
boolean result = CalcUtils.getBooleanFromCalc(jsgs, variables);
if (!result) {
errmsg=errmsg+LisUtil.LINE_SEPARATOR+"审核条件: "+ jsgs + " 未通过!";
}
}
}
if(!"".equals(errmsg))errmsg= errmsg +LisUtil.LINE_SEPARATOR+ "请咨询该仪器组长或专业检验师 !";
return errmsg;
}
2025-09-01 19:19:09 +08:00
/**
* 自动审核时,询问默认失败,填备注默认每次都填
* @param labPat
* @param labResultList
* @return
*/
public Map<String, Object> autochksamplenew(LabPat labPat, List<LabResult> labResultList) {
Map<String, Object> params=chksamplenew(labPat, labResultList,0);
String code=(String)params.get("code");
if ("3".equals(code))params.put("code","0");
if ("5".equals(code))params.put("code","-1");
if ("1".equals(code))params.put("code","-1");
return params;
}
/**
* 高级审核,对于重复询问通过xh递归询问
* @param labPat
* @param labResultList
* @param xh
* @return
*/
public Map<String, Object> chksamplenew(LabPat labPat, List<LabResult> labResultList,int xh){
String yq = labPat.getYq();
Date jyrq = labPat.getJyrq();
String ybh = labPat.getYbh();
String bz= labPat.getBz();
Map<String, Object> params = new HashMap<>();
params.put("code", "0");
params.put("msg","");
params.put("bz",bz);
params.put("setbz",false);
params.put("xh",xh);
List<LabCheckrules> labCheckruleslist=labCheckrulesMapper.getLabCheckrules(yq);
if(labCheckruleslist.size()==0)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();
String checktype=labCheckrules.getChecktype();
String logcontent=labCheckrules.getLogcontent();
String ruledisplay=labCheckrules.getRuledisplay();
String errmsg=checkcondition(labPat,labResultList,checkrules,ruledisplay);
if(!"".equals(errmsg)) {
if("0".equals(checktype)) {
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);
return params;
}else if("3".equals(checktype)) {
errmsg="审核未通过"+LisUtil.LINE_SEPARATOR+"设置的组合审核条件:"+errmsg+LisUtil.LINE_SEPARATOR+"审核未通过,不允许审核!";
params.put("code", "1");
params.put("msg",errmsg);
return params;
}else if("4".equals(checktype)) {
bz=replacebz(labPat,labResultList,logcontent);
labPat.setBz(bz);
params.put("setbz", true);
errmsg="此次审核将产生一个备注信息"+LisUtil.LINE_SEPARATOR+bz;
params.put("code", "3");
params.put("msg",errmsg);
params.put("bz",bz);
}
}
}
return params;
}
private String checkcondition(LabPat labPat, List<LabResult> labResultList,String checkrules,String ruledisplay){
String errmsg="";
if(checkrules.contains("ANY_")){
Map<String, String> variables = new HashMap<>();
String[] parameters=CalcUtils.getParameters(checkrules);
for (int i = 0; i < parameters.length; i++) {
String itemcode = parameters[i];
switch (itemcode) {
case "SEX":
String sex = labPat.getBrxb().trim();
if ("1".equals(sex)) sex = "男";
if ("2".equals(sex)) sex = "女";
variables.put("SEX", sex);
break;
case "AGE":
double age = AgeUtils.getDecimalAge(AgeUtils.getBirthDateByAge(labPat.getNl(), labPat.getNldw()));
variables.put("AGE", String.valueOf(age));
break;
case "":
break;
}
}
boolean flag=CalcUtils.getBooleanFromCalc(checkrules, variables);
errmsg = "审核条件: " + ruledisplay + " 未通过!" ;
}
return errmsg;
}
private String replacebz(LabPat labPat, List<LabResult> labResultList,String logcontent){
String errmsg=logcontent;
String[] parameters=CalcUtils.getParameters(logcontent);
for (int i = 0; i < parameters.length; i++) {
String itemcode = parameters[i];
switch (itemcode) {
case "SEX":
String sex = labPat.getBrxb().trim();
if ("1".equals(sex)) sex = "男";
if ("2".equals(sex)) sex = "女";
errmsg.replace("[SEX]",sex);
break;
case "AGE":
double age = AgeUtils.getDecimalAge(AgeUtils.getBirthDateByAge(labPat.getNl(), labPat.getNldw()));
errmsg.replace("[AGE]",String.valueOf(age));
break;
case "":
break;
}
}
return "";
2025-08-28 18:13:57 +08:00
}
}