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

import java.util.List;

/**
 * @Description: 接到危急值报告后6小时内无病程记录
 * @author: rengb
 * @time: 2020/3/19 19:54
 */
@Component
public class CRI0382 extends QCCatalogue {

    @Override
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        List<CrisisValueReportDoc> crisisValueReportDocs = inputInfo.getCrisisValueReportDocs();
        if (ListUtil.isEmpty(crisisValueReportDocs)) {
            return;
        }
        String format = "yyyy年MM月dd日HH时mm分";
        int timeCha = 21600000;
        crisisValueReportDocs.forEach(crisisValueReportDoc -> {
            String baogaoTimeStr = crisisValueReportDoc.getStructureMap().get("报告时间");
            String jiluTimeStr = crisisValueReportDoc.getStructureMap().get("记录时间");
            if (StringUtil.isNotBlank(baogaoTimeStr)
                    && StringUtil.isNotBlank(jiluTimeStr)
                    && DateUtil.parseDate(jiluTimeStr, format).getTime() - DateUtil.parseDate(baogaoTimeStr, format).getTime() > timeCha) {
                status.set("-1");
            }
        });
    }

}