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 com.lantone.qc.pub.util.StringUtil;
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 : CLI0569
 * @Description :  输血记录血型未填写
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class CLI0569 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        List<ClinicalBloodDoc> clinicalBloodDocs = inputInfo.getClinicalBloodDocs();
        if (ListUtil.isEmpty(clinicalBloodDocs)) {
            return;
        }
        if (clinicalBloodDocs != null && clinicalBloodDocs.size() > 0) {
            int matchSum = 0;
            for (ClinicalBloodDoc cliB : clinicalBloodDocs) {
                Map<String, String> cliBStructureMap = cliB.getStructureMap();
                //台州
                if (StringUtils.isNotEmpty(cliBStructureMap.get("血型"))) {
                    matchSum++;
                    continue;
                }
                if (cliBStructureMap.containsKey("输注种类、血型、数量")) {
                    String bloodType = cliBStructureMap.get("输注种类、血型、数量");
                    if (StringUtils.isNotEmpty(bloodType) &&
                            (bloodType.contains("白蛋白") || bloodType.contains("凝血酶原复合物")
                                    || bloodType.contains("血浆"))) {
                        matchSum++;
                        continue;
                    }
                    Pattern compile = Pattern.compile("[a-zA-Z]+型");
                    Matcher matcher = compile.matcher(StringUtil.removeBlank(cliBStructureMap.get("输注种类、血型、数量")));
                    if (matcher.find()) {
                        matchSum++;
                    }
                }
            }
            if (matchSum != clinicalBloodDocs.size()) {
                status.set("-1");
            }
        }

    }
}