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

import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.kernel.util.CatalogueUtil;
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.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * @Description: 化验结果为危急值的，6小时内危急值记录中没有体现危急值记录
 * 在没有化验报告单之前，以记录时间和接收时间的比较为准
 * @author: Mark
 * @time: 2020/6/19 13:34
 */
@Component
public class CON0382 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.isBlank(crisisValueReportDoc.getStructureMap().get("危急值记录内容"))) {
                    String record_time = crisisValueReportDoc.getStructureMap().get("记录时间");
                    String receive_time = crisisValueReportDoc.getStructureMap().get("接收时间");
                    String crisisVal =null;
                    if(crisisValueReportDoc.getStructureMap().get("危急值记录内容") != null){
                        crisisVal = crisisValueReportDoc.getStructureMap().get("危急值记录内容").trim();
                    }
                    if(record_time != null && receive_time != null && crisisVal != null){
                        Date record = StringUtil.parseDateTime(record_time);
                        Date receive = StringUtil.parseDateTime(receive_time);
                        if (crisisVal.length()==0 || CatalogueUtil.compareTime(receive, record, 6*60L) ) {
                            status.set("-1");
                        }
                    }

                }
            });
        }
    }

}