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.Diag;
import com.lantone.qc.pub.model.label.PastLabel;
import com.lantone.qc.pub.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

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


/**
 * @ClassName : BEH0454
 * @Description :  既往史未描述既往健康状况
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class BEH0454 extends QCCatalogue {
    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("既往健康状况"))) {
            status.set("0");
            return;
        }
        PastLabel pastLabel = inputInfo.getBeHospitalizedDoc().getPastLabel();
        /* 如果既往史为空或者既往史文本为空，则不报错 */
        if (pastLabel == null || StringUtil.isBlank(pastLabel.getText())) {
            status.set("0");
            return;
        }
        if (StringUtils.isNotEmpty(pastLabel.getHeathCondition()) || pastLabel.getText().contains("既往")
                || pastLabel.getText().contains("详见原病历")) {
            status.set("0");
        }
        //既往有任一阳性疾病名称，则认为有健康状况
        List<Diag> diags = pastLabel.getDiags();
        for (Diag diag : diags) {
            if (diag.getNegative() == null) {
                status.set("0");
                return;
            }
        }
    }
}