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.Clinical;
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.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * @ClassName : BEH0007
 * @Description :主诉症状时间描述模糊
 * 主诉中不能出现数天，数月，数年等带“数”字这种描述，如果出现，均视为模糊不清
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class BEH0007 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        if (inputInfo.getBeHospitalizedDoc() == null) {
            status.set("0");
            return;
        }
        ChiefLabel chiefLabel = inputInfo.getBeHospitalizedDoc().getChiefLabel();
        if (chiefLabel == null || StringUtil.isBlank(chiefLabel.getText())) {
            status.set("0");
            return;
        }
        String chiefText = chiefLabel.getText();
        if ((chiefText.contains("检查") || chiefText.contains("术后") || chiefText.contains("药物"))) {
            status.set("0");
        } else {
            List<Clinical> clinicals = chiefLabel.getClinicals();
            if (clinicals.size() > 0) {
                Clinical clinical = clinicals.get(0);
                List<PD> timestamp = clinical.getTimestamp();
                if (timestamp.size() > 0) {
                    for (PD pd : timestamp) {
                        String value = pd.getValue();
                        String unit = pd.getUnit();
                        if (StringUtils.isEmpty(unit) && value.contains("数")) {
                            status.set("-1");
                            break;
                        } else {
                            status.set("0");
                        }
                    }
                } else {
                    status.set("0");
                }
            } else {
                status.set("0");
            }
        }
    }
}