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.model.label.ChiefLabel;
import com.lantone.qc.pub.model.label.PresentLabel;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

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

/**
 * @ClassName : BEH02908
 * @Description : 现病史症状性质描述与主诉不符
 * @Author : 胡敬
 * @Date: 2020-06-11 15:54
 */
@Component
public class BEH02908 extends QCCatalogue {
    @Override
    protected void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getBeHospitalizedDoc() == null) {
            return;
        }
        String chiefProperty = "";
        ChiefLabel chiefLabel = inputInfo.getBeHospitalizedDoc().getChiefLabel();
        PresentLabel presentLabel = inputInfo.getBeHospitalizedDoc().getPresentLabel();
        if (chiefLabel == null || presentLabel == null) {
            return;
        }
        String chiefText = chiefLabel.getText();
        String presentText = presentLabel.getText();
        if (StringUtil.isBlank(chiefText) || StringUtil.isBlank(presentText)) {
            return;
        }
        String regex = "\\d+次";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(chiefText);
        if (matcher.find()) {
            chiefProperty = matcher.group(0);
        }
        if (StringUtil.isNotBlank(chiefProperty) && !presentText.contains(chiefProperty)) {
            status.set("-1");
        }
    }
}