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

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.consultation.ConsultationDoc;
import com.lantone.qc.pub.model.doc.consultation.ConsultationResultsDoc;
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 : CON0280
 * @Description : 普通会诊未在24小时内完成
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class CON0280 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getConsultationDocs() == null) {
            return;
        }
        List<ConsultationDoc> consultationDocs = inputInfo.getConsultationDocs();
        for (ConsultationDoc consultationDoc : consultationDocs) {
            ConsultationResultsDoc consultationResultsDoc = consultationDoc.getConsultationResultsDoc();
            if (consultationResultsDoc == null) {
                continue;
            }
            Map<String, String> structureMap = consultationResultsDoc.getStructureMap();
            String applicationDateStr = structureMap.get("会诊申请日期");
            String arrivalDateStr = structureMap.get("会诊到达时间");
            if (StringUtil.isBlank(applicationDateStr) || StringUtil.isBlank(arrivalDateStr)) {
                continue;
            }
            Date applicationDate = StringUtil.parseDateTime(applicationDateStr);
            Date arrivalDate = StringUtil.parseDateTime(arrivalDateStr);
            if (applicationDate == null || arrivalDate == null) {
                continue;
            }
            if (CatalogueUtil.compareTime(applicationDate, arrivalDate, (long) (24 * 60))) {
                status.set("-1");
                return;
            }
        }
    }
}