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.model.doc.operation.OperationRecordDoc;
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 : OPE03026
 * @Description : 术后首程未在手术结束15分钟内完成
 * @Author : 胡敬
 * @Date: 2020-03-30 17:03
 */
@Component
public class OPE03026 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        /**
         * 1.由于术后首程取到的手术时间无法精确到时分，所以去手术记录的手术结束时间取手术时间
         * 2.由于目前operationDocs中的手术记录和术后首程对应不上，因此只判断手术记录只有一次的情况
         */
        status.set("0");
        List<OperationDoc> operationDocs = inputInfo.getOperationDocs();
        if (ListUtil.isEmpty(operationDocs) || operationDocs.size() > 1) {
            return;
        }
        for (OperationDoc operationDoc : operationDocs) {
            OperationRecordDoc operationRecordDoc = operationDoc.getOperationRecordDoc();
            OperationDiscussionDoc operationDiscussionDoc = operationDoc.getOperationDiscussionDoc();
            if (operationRecordDoc == null || operationDiscussionDoc == null) {
                continue;
            }
            Map<String, String> operationRecordStructureMap = operationRecordDoc.getStructureMap();
            Map<String, String> operationDiscussionStructureMap = operationDiscussionDoc.getStructureMap();
            String operationDateStr = operationRecordStructureMap.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, 15L);
            if (compareTime) {
                status.set("-1");
                return;
            }
        }
    }
}