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

import com.lantone.qc.dbanaly.lt.entity.Clinic;
import com.lantone.qc.dbanaly.lt.facade.ClinicFacade;
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.Degree;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName : BEH0019
 * @Description :  现病史症状缺少程度
 * crf模型中只标注到修饰的程度，需要用词库去配出哪些是程度。
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class BEH0019 extends QCCatalogue {
    @Autowired
    private ClinicFacade clinicFacade;

    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getBeHospitalizedDoc() == null || inputInfo.getBeHospitalizedDoc().getPresentLabel() == null) {
            return;
        }
        List<Clinical> clinicals = inputInfo.getBeHospitalizedDoc().getPresentLabel().getClinicals();
        if (clinicals.size() > 0) {
            Clinical clinical = clinicals.get(0);
            String clinicalName = clinical.getName();
            if (StringUtil.isNotBlank(clinicalName)) {
//                long start = System.currentTimeMillis();
                Clinic clinic = clinicFacade.clinicCache(clinicalName);
//                long end = System.currentTimeMillis();
//                System.out.println("取kl_clinic缓存时间：" + (end-start));
                if (clinic != null && clinic.getHasDegree() == 1) {
                    Degree degree = clinical.getDegree();
                    if (degree == null) {
                        status.set("-1");
                        info.set(clinicalName);
                    }

                    if (clinicals.size() > 1) {
                        String secondeName = clinicals.get(1).getName();
                        String presentText = inputInfo.getBeHospitalizedDoc().getPresentLabel().getText();
                        String subTxt = presentText.substring(presentText.indexOf(clinicalName), presentText.indexOf(secondeName));
                        if (subTxt.indexOf("忍") > -1) {
                            status.set("0");
                        }
                    }
                }
            }
        }
    }

}