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

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.ClinicalBloodDoc;
import com.lantone.qc.pub.util.DateUtil;
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 static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm"; //输注时间
    public static String FORMAT_LONG_CN_MI = "yyyy年MM月dd日HH时mm分"; //记录时间
    DateUtil dateUtil = new DateUtil();
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        List<ClinicalBloodDoc> clinicalBloodDocs = inputInfo.getClinicalBloodDocs();
        if(clinicalBloodDocs != null && clinicalBloodDocs.size()>0){
            for (ClinicalBloodDoc cliB:clinicalBloodDocs) {
                Map<String, String> cliBStructureMap = cliB.getStructureMap();
                String infusion_begin= cliBStructureMap.get("输注开始");
                String infusion_end = cliBStructureMap.get("输注结束");
               if(StringUtils.isNotEmpty(infusion_begin) && StringUtils.isNotEmpty(infusion_end)){
                    try {
                        Date date_in = new SimpleDateFormat(DATE_TIME_FORMAT).parse(infusion_begin);
                        Date date_out = new SimpleDateFormat(DATE_TIME_FORMAT).parse(infusion_end);
                        double distanceHour = dateUtil.getDistanceTime2(date_in, date_out);
                        if(distanceHour > 24.0){
                            status.set("-1");
                        }
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }

                }
            }
        }

    }
}