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

import java.util.Map;

/**
 * @ClassName : BEH0472
 * @Description :  月经史未描述生育情况
 * @Author : 胡敬
 * @Date: 2020-03-26 20:14
 */
@Component
public class BEH0472 extends QCCatalogue {

    @Override
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        BeHospitalizedDoc beHospitalizedDoc = inputInfo.getBeHospitalizedDoc();
        if (beHospitalizedDoc == null) {
            return;
        }
        Map<String, String> beHospitalStructureMap = beHospitalizedDoc.getStructureMap();
        if (beHospitalStructureMap != null) {
            if (beHospitalStructureMap.get("性别") == null || beHospitalStructureMap.get("性别").contains("男")) {
                status.set("0"); //如果性别是男,就不报错
                return;
            }
            boolean fertilitySituation = StringUtil.isBlank(beHospitalStructureMap.get("存活"))
                    || StringUtil.isBlank(beHospitalStructureMap.get("顺产(足月)"))
                    || StringUtil.isBlank(beHospitalStructureMap.get("早产"))
                    || StringUtil.isBlank(beHospitalStructureMap.get("流产"));
            if (fertilitySituation) {
                //如果结构化数据中上述条件缺少，则在婚育史中查找生育情况
                MaritalLabel maritalLabel = beHospitalizedDoc.getMaritalLabel();//婚育史
                if (maritalLabel == null || maritalLabel.getFertility() == null) {
                    status.set("-1");
                }
            }
        }
    }
}