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

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

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

/**
 * @ClassName : THR02852
 * @Description : 抢救记录未在抢救结束后6h内完成
 * @Author : zhoutg
 * @Date: 2020-04-29 11:42
 */
@Component
public class THR02852 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        /**
         * 【病历日期】与【抢救结束时间】比较是否相差6小时
         */
        status.set("0");
        List<RescueDoc> rescueDocs = inputInfo.getRescueDocs();
        if (ListUtil.isEmpty(rescueDocs)) {
            return;
        }
        for (RescueDoc rescueDoc : rescueDocs) {
            Map<String, String> rescueStructureMap = rescueDoc.getStructureMap();
            String rescueTime = rescueStructureMap.get("抢救结束时间");
            String recordTime = rescueStructureMap.get("病历日期");
            if (StringUtil.isBlank(rescueTime) || StringUtil.isBlank(recordTime)) {
                continue;
            }
            Date rescueTimeDate = StringUtil.parseDateTime(rescueTime);
            Date recordTimeDate = StringUtil.parseDateTime(recordTime);
            if (rescueTimeDate == null || recordTimeDate == null) {
                continue;
            }
            if (CatalogueUtil.compareTime(rescueTimeDate, recordTimeDate, 6 * 60L)) {
                status.set("-1");
                return;
            }
        }
    }
}