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

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

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

/**
 * @ClassName : FIRP02859
 * @Description :质控未在出院三天内完成
 * @Author : 胡敬
 * @Date: 2020-04-29 09:43
 */
@Component
public class FIRP02859 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        FirstPageRecordDoc firstPageRecordDoc = inputInfo.getFirstPageRecordDoc();
        LeaveHospitalDoc leaveHospitalDoc = inputInfo.getLeaveHospitalDoc();
        if (firstPageRecordDoc == null || leaveHospitalDoc == null) {
            status.set("0");
            return;
        }
        Map<String, String> firstStructureMap = firstPageRecordDoc.getStructureMap();
        String qcDateStr = firstStructureMap.get("质控日期");

        // 先从病案首页获取，如果为空，再从出院小结获取
        String leaveDateStr = firstStructureMap.get("出院时间");
        if (StringUtil.isBlank(leaveDateStr)) {
            Map<String, String> leaveStructureMap = leaveHospitalDoc.getStructureMap();
            leaveDateStr = leaveStructureMap.get("出院时间");
        }
        if (StringUtil.isBlank(qcDateStr) || StringUtil.isBlank(leaveDateStr)) {
            status.set("0");
            return;
        }
        Date qcDate = StringUtil.parseDateTime(qcDateStr);
        Date leaveDate = StringUtil.parseDateTime(leaveDateStr);
        if (qcDate == null || leaveDate == null) {
            status.set("0");
            return;
        }
        boolean overTime = CatalogueUtil.compareTime(leaveDate, qcDate, 72 * 60L);
        if (!overTime) {
            //质控日期在出院时间三天内完成
            status.set("0");
        }
    }
}