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

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.util.StringUtil;
import org.springframework.stereotype.Component;

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

/**
 * @ClassName : BEH03061
 * @Description : 体征前后描述矛盾
 * @Author : 胡敬
 * @Date: 2020-08-11 15:28
 */
@Component
public class BEH03061 extends QCCatalogue {

    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getBeHospitalizedDoc() == null) {
            return;
        }
        Map<String, String> behStructureMap = inputInfo.getBeHospitalizedDoc().getStructureMap();
        String heartRate = behStructureMap.get("心律");
        String specialCheck = behStructureMap.get("专科体格检查");
        if (StringUtil.isNotBlank(heartRate) && StringUtil.isNotBlank(specialCheck)) {
            Pattern p = Pattern.compile("心律.*齐");
            Matcher m = p.matcher(specialCheck);
            if (m.find()) {
                String matchVital = m.group(0);
                if (StringUtil.isNotBlank(matchVital)) {
                    if ("齐".equals(heartRate) && matchVital.contains("不")) {
                        status.set("-1");
                        info.set("心律齐><" + matchVital);
                    } else if ("不齐".equals(heartRate) && !matchVital.contains("不")) {
                        status.set("-1");
                        info.set("心律不齐><" + matchVital);
                    }
                }
            }
        }
    }
}