package com.lantone.qc.kernel.catalogue.ywzxyy.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.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 : BEH0061
 * @Description : 月经史未描述月经周期
 * @Author : 胡敬
 * @Date: 2020-03-11 14:18
 */
@Component
public class BEH0061 extends QCCatalogue {
    @Override
    protected void start(InputInfo inputInfo, OutputInfo outputInfo) {
        if (inputInfo.getBeHospitalizedDoc() != null) {
            if (inputInfo.getBeHospitalizedDoc().getStructureMap() == null
                    || 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 (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.getMenstrualCycle() != null && StringUtil.isNotBlank(menses.getMenstrualCycle().getName())) {
                            status.set("0");
                            return;
                        }
                    }
                }
            }
        }
    }
}