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

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.DeathRecordDoc;
import com.lantone.qc.pub.model.doc.FirstPageRecordDoc;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

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

/**
 * @Description: 无出院记录
 * 出院时间-入院时间 大于24小时 有出院记录 （死亡患者除外）
 * @author: 胡敬
 * @time: 2020/3/27 15:15
 */
@Component
public class LEA0507 extends QCCatalogue {
    @Override
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        FirstPageRecordDoc firstPageRecordDoc = inputInfo.getFirstPageRecordDoc();
        if (firstPageRecordDoc == null) {
            return;
        }
        Map<String, String> pageMap = firstPageRecordDoc.getStructureMap();
        DeathRecordDoc deathRecordDoc = inputInfo.getDeathRecordDoc();
        if (deathRecordDoc == null) {
            String outDate = pageMap.get("出院时间");
            String inDate = pageMap.get("入院时间");
            Date infusionEndDate = StringUtil.parseDateTime(inDate);
            Date recordDate = StringUtil.parseDateTime(outDate);

            if (CatalogueUtil.compareTime(infusionEndDate, recordDate, 24 * 60L) && inputInfo.getLeaveHospitalDoc() == null) {
                status.set("-1");
            }
        }
    }
}