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.OperationDoc;
import com.lantone.qc.pub.model.doc.operation.OperationRecordDoc;
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 : OPE0647
 * @Description : 手术记录未在术后24h内完成
 * @Author : 胡敬
 * @Date: 2020-03-30 10:22
 */
@Component
public class OPE0647 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        //        boolean isOperativePatient = true;//是手术患者(暂时默认是)
        //        if (isOperativePatient) {
        List<OperationDoc> operationDocs = inputInfo.getOperationDocs();
        if (operationDocs == null || operationDocs.size() == 0) {
            status.set("0");
            return;
        }
        for (OperationDoc operationDoc : operationDocs) {
            OperationRecordDoc operationRecordDoc = operationDoc.getOperationRecordDoc();
            if (operationRecordDoc == null) {
                continue;
            }
            Map<String, String> operationRecordStructureMap = operationRecordDoc.getStructureMap();
            String operationEndDateStr = operationRecordStructureMap.get("手术结束时间");
            String operationRecordDateStr = operationRecordStructureMap.get("记录时间");
            if (CatalogueUtil.isEmpty(operationEndDateStr) || CatalogueUtil.isEmpty(operationRecordDateStr)) {
                continue;
            }
            Date operationEndDate = StringUtil.parseDateTime(operationEndDateStr);
            Date operationRecordDate = StringUtil.parseDateTime(operationRecordDateStr);
            if (operationEndDate == null || operationRecordDate == null) {
                continue;
            }
            boolean compareTime = CatalogueUtil.compareTime(operationEndDate, operationRecordDate, 24 * 60L);
            if (compareTime) {
                status.set("-1");
                return;
            }
        }
        //        }
    }
}