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

import com.lantone.qc.kernel.catalogue.QCCatalogue;
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.FirstPageRecordDoc;
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.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @ClassName : FIRP0193
 * @Description :手术及操作名称填写不全
 * @Author : 胡敬
 * @Date: 2020-03-16 20:28
 */
@Component
public class FIRP0193 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        FirstPageRecordDoc firstPageRecordDoc = inputInfo.getFirstPageRecordDoc();
        if (firstPageRecordDoc == null){
            return;
        }
        List<OperationDoc> operationDocs = inputInfo.getOperationDocs();
        List<String> operations = new ArrayList<>();
        List<String> operations_first = new ArrayList<>();
        if (ListUtil.isNotEmpty(operationDocs)) {
            for (OperationDoc opd : operationDocs) {
                OperationDiscussionDoc operationDiscussionDoc = opd.getOperationDiscussionDoc();
                if (operationDiscussionDoc == null) {
                    continue;
                }
                String operativeMethod = operationDiscussionDoc.getStructureMap().get("手术方式");
                if (StringUtil.isBlank(operativeMethod)){
                    continue;
                }
                operations.add(operativeMethod);
            }
        }
        Map<String, Object> firstPageRecordDocStructureMap = firstPageRecordDoc.getStructureExtMap();
        List<Map<String, String>> mapList = (List<Map<String, String>>) firstPageRecordDocStructureMap.get(Content.operative_information);
        if (mapList != null && mapList.size() > 0) {
            for (Map<String, String> ds : mapList) {
                String oName = ds.get(Content.operative_name);
                if (StringUtils.isNotEmpty(oName)) {
                    operations_first.add(oName);
                }
            }
        }
        boolean equals = ListUtil.equals(operations, operations_first);
        if (equals) {
            status.set("0");
        } else {
            status.set("-1");
        }

    }
}