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

import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.pub.Content;
import com.lantone.qc.pub.model.InputInfo;
import com.lantone.qc.pub.model.OutputInfo;
import com.lantone.qc.pub.model.doc.BeHospitalizedDoc;
import com.lantone.qc.pub.model.entity.Marryiage;
import com.lantone.qc.pub.model.label.MaritalLabel;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Description: 结婚年龄未描述
 * @author: rengb
 * @time: 2020/3/10 14:02
 */
@Component
public class BEH0053 extends QCCatalogue {

    @Override
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        BeHospitalizedDoc beHospitalizedDoc = inputInfo.getBeHospitalizedDoc();
        if (beHospitalizedDoc == null) {
            status.set("0");
            return;
        }
        //先取一次结构化数据
        Map<String, String> beHospitalizedStructureMap = beHospitalizedDoc.getStructureMap();
        String marryiAgeStr = beHospitalizedStructureMap.get("结婚年龄");
        if (StringUtil.isNotBlank(marryiAgeStr)) {
            status.set("0");
            return;
        }
        //硬规则 匹配未婚
        String marry = beHospitalizedDoc.getStructureMap().get(Content.marry);
        MaritalLabel maritalLabel = beHospitalizedDoc.getMaritalLabel();
        if (maritalLabel == null || StringUtil.isBlank(maritalLabel.getText())) {
            status.set("0");
            return;
        }
        String maritalText = maritalLabel.getText();
        if ("未婚".equals(marry) || maritalText.contains("未婚") || maritalText.contains("详见原病历")) {
            status.set("0");
            return;
        }
        if (beHospitalizedDoc.getMaritalLabel() == null
                || StringUtil.isBlank(beHospitalizedDoc.getMaritalLabel().getText())) {
            status.set("0");
        }

        Marryiage marryiage = beHospitalizedDoc.getMaritalLabel().getMarryiage();
        if (marryiage != null && StringUtil.isNotBlank(marryiage.getName())) {
            status.set("0");
        }
    }

}