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

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.operation.OperationDiscussionDoc;
import com.lantone.qc.pub.model.doc.operation.OperationDoc;
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 : OPE0651
 * @Description : 术后首程未在手术结束1小时内完成
 * @Author : 胡敬
 * @Date: 2020-03-30 17:03
 */
@Component
public class OPE0651 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        List<OperationDoc> operationDocs = inputInfo.getOperationDocs();
        if (ListUtil.isEmpty(operationDocs)) {
            return;
        }
        for (OperationDoc operationDoc : operationDocs) {
            OperationDiscussionDoc operationDiscussionDoc = operationDoc.getOperationDiscussionDoc();
            if (operationDiscussionDoc == null) {
                continue;
            }
            Map<String, String> operationDiscussionStructureMap = operationDiscussionDoc.getStructureMap();
            String operationDateStr = operationDiscussionStructureMap.get("手术日期");
            String dateStr = operationDiscussionStructureMap.get("时间");
            if (CatalogueUtil.isEmpty(operationDateStr) || CatalogueUtil.isEmpty(dateStr)) {
                continue;
            }
            Date operationDate = StringUtil.parseDateTime(operationDateStr);
            Date date = StringUtil.parseDateTime(dateStr);
            if (operationDate == null || date == null) {
                continue;
            }
            boolean compareTime = CatalogueUtil.compareTime(operationDate, date, (long) 60);
            if (compareTime) {
                status.set("-1");
                return;
            }
        }
    }
}