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

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.ClinicalBloodDoc;
import com.lantone.qc.pub.util.DateUtil;
import com.lantone.qc.pub.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ClassName : CLI0305
 * @Description : 输血记录未在输注结束后24小时内完成
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class CLI0305 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        Boolean flag = false;
        List<ClinicalBloodDoc> clinicalBloodDocs = inputInfo.getClinicalBloodDocs();
        if (clinicalBloodDocs != null && clinicalBloodDocs.size() > 0) {
            for (ClinicalBloodDoc cliB : clinicalBloodDocs) {
                Map<String, String> cliBStructureMap = cliB.getStructureMap();
                String infusionEnd = cliBStructureMap.get("输注结束");
                String recordDateStr = cliBStructureMap.get("记录时间");
                if (StringUtils.isNotEmpty(infusionEnd) && StringUtils.isNotEmpty(recordDateStr)) {
                    Date infusionEndDate = StringUtil.parseDateTime(infusionEnd);
                    Date recordDate = StringUtil.parseDateTime(recordDateStr);
                    if (infusionEndDate != null && recordDate != null) {
                        if (infusionEndDate.after(recordDate)) {
                            continue;
                        }
                        if (CatalogueUtil.compareTime(infusionEndDate, recordDate, 24 * 60L)) {
                            flag = true;
                            info.set(infusionEnd + " -> " + recordDateStr);
                        }
                    }
                }
            }
        }
        if(flag){
            status.set("-1");
        }
    }
}