package com.lantone.qc.kernel.catalogue.xiamen.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.entity.MaritalStatus;
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 BEH0372 extends QCCatalogue {

    @Override
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getBeHospitalizedDoc() == null) {
            return;
        }

        String basicInfoStatus = inputInfo.getBeHospitalizedDoc().getStructureMap().get("婚育史");
        String bhbasicInfoStatus = inputInfo.getBeHospitalizedDoc().getStructureMap().get("婚姻状况");
        if (StringUtil.isBlank(bhbasicInfoStatus)) {
            bhbasicInfoStatus = inputInfo.getBeHospitalizedDoc().getStructureMap().get("婚姻");
        }
        if (StringUtil.isBlank(basicInfoStatus) || StringUtil.isBlank(bhbasicInfoStatus)) {
            return;
        }
        if (basicInfoStatus.contains(bhbasicInfoStatus)) {
            return;
        }
        if (bhbasicInfoStatus.equals("未婚") && basicInfoStatus.contains("结婚")) {
            status.set("-1");
            return;
        }

        if (bhbasicInfoStatus.equals("未婚") && basicInfoStatus.contains("未婚")) {
            return;
        }

        if (StringUtil.isNotBlank(bhbasicInfoStatus) && basicInfoStatus.equals("其他")) {
            return;
        }

        if (bhbasicInfoStatus.equals("丧偶") &&
                (basicInfoStatus.contains("已故") || basicInfoStatus.contains("丧偶") || basicInfoStatus.contains("亡故") || basicInfoStatus.contains("已逝"))) {
            return;
        }

        if ((bhbasicInfoStatus.equals("离婚") || bhbasicInfoStatus.equals("离异")) &&
                (basicInfoStatus.contains("离异") || bhbasicInfoStatus.equals("离婚"))) {
            return;
        }

        if (bhbasicInfoStatus.equals("已婚") && (basicInfoStatus.contains("结婚") || basicInfoStatus.contains("再婚"))) {
            return;
        }

        MaritalStatus mts = inputInfo.getBeHospitalizedDoc().getMaritalLabel().getMaritalStatus();
        if (mts != null && StringUtil.isNotBlank(mts.getName())) {
            String maritalStatus = mts.getName();
            if (basicInfoStatus.equals(maritalStatus)) {
                return;
            }
        }

        //无婚育史
        MaritalLabel maritalLabel = inputInfo.getBeHospitalizedDoc().getMaritalLabel();
        if (maritalLabel == null || maritalLabel.getText() == null) {
            return;
        }
    }

}