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

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.doc.CrisisValueReportDoc;
import com.lantone.qc.pub.util.ListUtil;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description: 危急值记录中无危急值结果
 * @author: rengb
 * @time: 2020/3/19 19:54
 */
@Component
public class CRI0384 extends QCCatalogue {

    @Override
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        List<CrisisValueReportDoc> crisisValueReportDocs = inputInfo.getCrisisValueReportDocs();
        if (ListUtil.isNotEmpty(crisisValueReportDocs)) {
            crisisValueReportDocs.forEach(crisisValueReportDoc -> {
                if (StringUtil.isNotBlank(crisisValueReportDoc.getStructureMap().get("内容"))) {
                    /* 台州相应数据需从危急值内容中截取 */
                    String report = getReport(crisisValueReportDoc.getStructureMap().get("内容"));
                    if (StringUtil.isBlank(report)) {
                        status.set("-1");
                    }
                }
            });
        }
    }

    private String getReport(String str) {
        String reportDate = "";
        if (StringUtil.isNotBlank(str) && str.contains("危急值报告：{") && str.contains("}。立即查看")) {
            reportDate = str.substring(str.indexOf("危急值报告：{") + 7, str.indexOf("}。立即查看"));
        }
        return reportDate;
    }
}