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

import com.google.common.collect.Lists;
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.PD;
import com.lantone.qc.pub.model.label.ChiefLabel;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;


/**
 * @ClassName : BEH0005
 * @Description :主诉症状时间描述前后不合理
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class BEH0005 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getBeHospitalizedDoc() == null) {
            return;
        }
        List<Integer> timeIndex = new ArrayList<>();
        ChiefLabel chiefLabel = inputInfo.getBeHospitalizedDoc().getChiefLabel();
        if (chiefLabel == null) {
            return;
        }
        List<PD> pds = chiefLabel.getPds();
        String chiefText = chiefLabel.getText();
        if (StringUtil.isNotBlank(chiefText)) {
//            chiefText = chiefText.replace("月经", "");/* 月经这个词会影响逻辑判断，这里把月经这个词去除 */
            if (chiefText.contains("检查") || chiefText.contains("术后")
                    || chiefText.contains("药物") || chiefText.contains("月经") || chiefText.contains("停经")) {
                return;
            } else {
                List<String> words = Lists.newArrayList("年", "月", "周", "天", "日", "时", "分");
                String name;
                for (PD pd : pds) {
                    name = pd.getName();
                    if (StringUtil.isBlank(name)) {
                        continue;
                    }
                    for (int i = 0; i < words.size(); i++) {
                        String word = words.get(i);
                        if (name.contains(word)) {
                            timeIndex.add(i);
                            break;
                        }
                    }
                }
            }
            if (timeIndex.size() <= 1) {
                return;
            }
            for (int i = 0; i < timeIndex.size(); i++) {
                for (int j = i + 1; j < timeIndex.size(); j++) {
                    if (timeIndex.get(i) > timeIndex.get(j)) {
                        status.set("-1");
                        return;
                    }
                }
            }
        }
    }
}