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.Cause;
import com.lantone.qc.pub.model.entity.Clinical;
import com.lantone.qc.pub.model.label.PresentLabel;
import com.lantone.qc.pub.util.ListUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * @ClassName : BEH0014
 * @Description :  现病史症状缺少诱因
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class BEH0014 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        if (inputInfo.getBeHospitalizedDoc() == null) {
            status.set("0");
            return;
        }
        /*List<Clinical> clinicals = inputInfo.getBeHospitalizedDoc().getPresentLabel().getClinicals();
        if(clinicals.size()>0){
            Clinical clinical = clinicals.get(0);
            String clinicalName = clinical.getName();
            Cause cause = clinical.getCause();
            if(cause == null){
                info.set(clinicalName);
            }else {
                status.set("0");
            }
        }*/
        PresentLabel presentLabel = inputInfo.getBeHospitalizedDoc().getPresentLabel();
        List<Clinical> clinicals = presentLabel.getClinicals();
        if (ListUtil.isNotEmpty(clinicals)) {
            for (Clinical clinical : clinicals) {
                if (clinical.getCause() != null) {
                    status.set("0");
                    return;
                }
            }
        }
        //硬规则匹配 前30个字有"体检"或"发现"或"检查"字样
        String present = presentLabel.getText();
        if (StringUtils.isNotEmpty(present)) {
            if (present.length() > 30) {
                present = present.substring(0, 30);
            }
            if (present.contains("体检") || present.contains("发现") || present.contains("检查") || present.contains("因")
                    || present.contains("确诊") || present.contains("诊断") || present.contains("复查") || present.contains("术后")
                    || present.contains("药物") || present.contains("误服")) {
                status.set("0");
                return;
            }
        }
        List<Cause> causes = presentLabel.getCauses();
        if (causes != null && causes.size() > 0) {
            status.set("0");
        }
    }
}