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

import com.google.common.collect.Lists;
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.label.DiagLabel;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @ClassName : BEH03060
 * @Description : 诊断与体征描述相互矛盾
 * @Author : 胡敬
 * @Date: 2020-08-10 19:00
 */
@Component
public class BEH03060 extends QCCatalogue {

    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getBeHospitalizedDoc() == null) {
            return;
        }
        DiagLabel initialDiagLabel = inputInfo.getBeHospitalizedDoc().getInitialDiagLabel();
        if (initialDiagLabel == null || StringUtil.isBlank(initialDiagLabel.getText())) {
            return;
        }

        List<String> diags = Lists.newArrayList(initialDiagLabel.getText().split("\n"));
        List<String> matchDiag = diags.stream().filter(x -> x.contains("房扑") || x.contains("房颤")).collect(Collectors.toList());
        if (matchDiag.size() > 0) {
            String diag = matchDiag.get(0);//取第一个包含房扑或房颤的疾病名称
            Map<String, String> behStructureMap = inputInfo.getBeHospitalizedDoc().getStructureMap();
            String heartRate = behStructureMap.get("心律");
            if (StringUtil.isNotBlank(heartRate) && "齐".equals(heartRate)) {
                status.set("-1");
                info.set(diag + "><心律齐");
                return;
            }
            String specialCheck = behStructureMap.get("专科体格检查");
            if (StringUtil.isNotBlank(specialCheck) && specialCheck.contains("律齐")) {
                status.set("-1");
                info.set(diag + "><心律齐");
            }
        }
    }
}