package com.lantone.qc.kernel.catalogue.behospitalized;

import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.kernel.util.CatalogueUtil;
import com.lantone.qc.pub.model.InputInfo;
import com.lantone.qc.pub.model.OutputInfo;
import com.lantone.qc.pub.model.label.PastLabel;
import com.lantone.qc.pub.util.ListUtil;
import com.lantone.qc.pub.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Description: 传染病史未填写
 * @author: rengb
 * @time: 2020/3/10 14:02
 */
@Component
public class BEH0030 extends QCCatalogue {

    @Override
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        if (inputInfo.getBeHospitalizedDoc() == null) {
            status.set("0");
            return;
        }
        Map<String, String> structureMap = inputInfo.getBeHospitalizedDoc().getStructureMap();
        if (StringUtils.isNotEmpty(structureMap.get("结核病")) || StringUtils.isNotEmpty(structureMap.get("病毒性肝炎"))) {
            status.set("0");
            return;
        }
        PastLabel pastLabel = inputInfo.getBeHospitalizedDoc().getPastLabel();
        /* 如果既往史为空或者既往史文本为空，则不报错 */
        if (pastLabel == null || StringUtil.isBlank(pastLabel.getText())) {
            status.set("0");
            return;
        }
        if (ListUtil.isNotEmpty(
                CatalogueUtil.filterDiagsByNature(
                        pastLabel.getDiags(),
                        "infectious",
                        "1"
                )
        )) {
            status.set("0");
        }
        String pastText = pastLabel.getText();
        if (pastText.contains("肝炎") || pastText.contains("结核") || pastText.contains("详见原病历")
                || pastText.contains("乙肝")) {
            status.set("0");
        }
    }

}