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

import com.lantone.qc.kernel.catalogue.QCCatalogue;
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.label.OperationDiscussionLabel;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Description: 术后首次病程记录未记录术后风险
 * @author: 胡敬
 * @time: 2020/3/24 13:28
 */
@Component
public class OPE0352 extends QCCatalogue {
    @Override
    protected void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        List<OperationDoc> operationDocs = inputInfo.getOperationDocs();
        if (operationDocs == null || operationDocs.size() == 0) {
            status.set("0");
            return;
        }
        for (OperationDoc operationDoc : operationDocs) {
            OperationDiscussionDoc doc = operationDoc.getOperationDiscussionDoc();
            if (doc == null) {
                continue;
            }
            Map<String, String> map = doc.getStructureMap();
            String originText = map.get("原始文本");
            String regex = ".*术后.*意外.*";
            Pattern p = Pattern.compile(regex);
            Matcher matcher = p.matcher(originText);
            if (StringUtil.isNotBlank(originText) && matcher.find()) {
                continue;
            }
            OperationDiscussionLabel label = doc.getOperationDiscussionLabel();
            if (label != null && (StringUtil.isBlank(label.getRiskAfterOp()) || label.getRiskAfterOp().length() < 10)
                    && (StringUtil.isBlank(map.get("术后可能出现的并发症及预防措施")) || map.get("术后可能出现的并发症及预防措施").length() < 10)) {
                status.set("-1");
                return;
            }
        }
    }
}