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.Content;
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.util.ListUtil;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

/**
 * @Description: 手术结束时间不规范
 * @author: 胡敬
 * @time: 2020/3/28 16:32
 */
@Component
public class OPE0631 extends QCCatalogue {

    @Override
    protected void start(InputInfo inputInfo, OutputInfo outputInfo) throws ParseException {
        status.set("0");
        //        boolean isOperativePatient = true;//是手术患者(暂时默认是)
        //        if (isOperativePatient) {
        List<OperationDoc> operationDocs = inputInfo.getOperationDocs();
        if (operationDocs == null || operationDocs.size() == 0) {
            status.set("0");
            return;
        }
        if (ListUtil.isNotEmpty(operationDocs)) {
            for (OperationDoc operationDoc : operationDocs) {
                if (operationDoc.getOperationRecordDoc() == null){
                    continue;
                }
                String operationEndDateStr = operationDoc.getOperationRecordDoc().getStructureMap().get("手术结束时间");
                if (CatalogueUtil.isEmpty(operationEndDateStr)) {
                    continue;
                }
                Date operationEndDate = StringUtil.parseDateTime(operationEndDateStr, CatalogueUtil.processDateFormat(Content.dateFormats));
                if (null == operationEndDate) {
                    status.set("-1");
                    return;
                }
            }
        }
        //        }
    }

}