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.entity.Clinical;
import com.lantone.qc.pub.model.entity.Menses;
import com.lantone.qc.pub.model.label.MenstrualLabel;
import com.lantone.qc.pub.util.ListUtil;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @ClassName : BEH0064
 * @Description : 月经史未描述月经量
 * @Author : 胡敬
 * @Date: 2020-03-11 14:41
 */
@Component
public class BEH0064 extends QCCatalogue {
    @Override
    protected void start(InputInfo inputInfo, OutputInfo outputInfo) {
        if (inputInfo.getBeHospitalizedDoc() == null) {
            status.set("0");
            return;
        }
        if (inputInfo.getBeHospitalizedDoc().getStructureMap().get("性别") == null
                || inputInfo.getBeHospitalizedDoc().getStructureMap().get("性别").contains("男")) {
            status.set("0"); //如果性别是男,就不报错
        } else {
            Map<String, String> structureMap = inputInfo.getBeHospitalizedDoc().getStructureMap();
            if (StringUtil.isNotBlank(structureMap.get("月经量"))) {
                status.set("0");
                return;
            }
            //硬规则匹配经量
            if (StringUtil.isNotBlank(structureMap.get("月经史"))) {
                if (structureMap.get("月经史").contains("经量")) {
                    status.set("0");
                    return;
                }
            }
            if (inputInfo.getBeHospitalizedDoc().getMenstrualLabel() != null) {
                MenstrualLabel menstrualLabel = inputInfo.getBeHospitalizedDoc().getMenstrualLabel();
                String text = menstrualLabel.getText();
                if (StringUtil.isNotBlank(text) && text.contains("未行经")) {
                    status.set("0");
                    return;
                }
                List<Menses> mensesList = menstrualLabel.getMensesList();
                if (ListUtil.isEmpty(mensesList)) {
                    return;
                }
                for (Menses menses : mensesList) {
                    if (menses.getClinicals() == null) {
                        continue;
                    }
                    List<Clinical> clinicals = menses.getClinicals();
                    for (Clinical clinical : clinicals) {
                        if (clinical.getName().contains("经量")) {
                            status.set("0");
                            return;
                        }
                    }
                }
            }
        }
    }
}