package com.lantone.qc.kernel.catalogue.clinicalblood;

import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.pub.model.InputInfo;
import com.lantone.qc.pub.model.OutputInfo;
import com.lantone.qc.pub.model.doc.ClinicalBloodDoc;
import com.lantone.qc.pub.util.ListUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ClassName : CLI0300
 * @Description : 输血记录中输血指征不严格
 * CRF缺少足够标注数据，使用规则判断输血原因是否有数字
 * @Author : Mark
 * @Date: 2020-04-05 16:56
 */
@Component
public class CLI0300 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        List<ClinicalBloodDoc> clinicalBloodDocs = inputInfo.getClinicalBloodDocs();
        if (ListUtil.isEmpty(clinicalBloodDocs)) {
            return;
        }
        for (ClinicalBloodDoc cliB : clinicalBloodDocs) {
            Map<String, String> cliBStructureMap = cliB.getStructureMap();
            String infusionReason;
            //台州
            if (StringUtils.isNotEmpty(cliBStructureMap.get("输血检验指标"))) {
                infusionReason = cliBStructureMap.get("输血检验指标");
            } else {
                infusionReason = cliBStructureMap.get("输注原因");
            }
            if (StringUtils.isNotEmpty(infusionReason)) {
                if (infusionReason.contains("白蛋白") || infusionReason.contains("凝血酶原复合物")) {
                    continue;
                }
                if ("其它".equals(infusionReason)) {
                    status.set("-1");
                    return;
                }
                Pattern compile = Pattern.compile("([\\d]+[.\\d+]*)([a-zA-Z]+)(/[a-zA-Z]+)*");
                Matcher matcher = compile.matcher(infusionReason);
                if (matcher.find(0)) {
                    if (null != matcher.group(1)) {
                        double val = Double.parseDouble(matcher.group(1));
                        if (val > 100) {
                            status.set("-1");
                        }
                    }
                }
            }
        }
    }
}