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.entity.Consanguineous;
import com.lantone.qc.pub.model.label.FamilyLabel;
import com.lantone.qc.pub.model.label.MaritalLabel;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

/**
 * @Description: 是否近亲结婚未描述
 * @author: rengb
 * @time: 2020/3/10 14:02
 */
@Component
public class BEH0054 extends QCCatalogue {

    @Override
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        if (inputInfo.getBeHospitalizedDoc() == null) {
            status.set("0");
            return;
        }
        //硬规则 未婚
        String marry = inputInfo.getBeHospitalizedDoc().getStructureMap().get(Content.marry);
        MaritalLabel maritalLabel = inputInfo.getBeHospitalizedDoc().getMaritalLabel();
        FamilyLabel familyLabel = inputInfo.getBeHospitalizedDoc().getFamilyLabel();
        if (maritalLabel == null) {
            status.set("0");
            return;
        }
        if ("未婚".equals(marry) || StringUtil.isBlank(maritalLabel.getText()) || maritalLabel.getText().contains("未婚")
                || maritalLabel.getText().contains("详见原病历")) {
            status.set("0");
            return;
        }
        /* 有少数病历的近亲结婚时会写在家族史中（普通病历会写在婚育史里） */
        if (familyLabel != null) {
            String familyText = familyLabel.getText();
            if (StringUtil.isNotBlank(familyText) && familyText.contains("近亲结婚")) {
                status.set("0");
                return;
            }
        }
        Consanguineous consanguineous = inputInfo.getBeHospitalizedDoc().getMaritalLabel().getConsanguineous();
        if (consanguineous != null && StringUtil.isNotBlank(consanguineous.getName())) {
            status.set("0");
        }
    }

}