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

import java.util.List;

/**
 * @Description: 术后首次病程记录未记录患者生命体征
 * @author: 胡敬
 * @time: 2020/3/24 13:28
 */
@Component
public class OPE0351 extends QCCatalogue {
    @Override
    protected void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        //医嘱
        //        List<DoctorAdviceDoc> doctorAdviceDocs = inputInfo.getDoctorAdviceDocs();
        //        if (ListUtil.isEmpty(doctorAdviceDocs)) {
        //            return;
        //        }
        //        boolean isOperativePatient = CatalogueUtil.isOperativePatients(doctorAdviceDocs);
        //        boolean isOperativePatient = true;//是手术患者(暂时默认是)
        //        if (isOperativePatient) {
        List<OperationDoc> operationDocs = inputInfo.getOperationDocs();
        if (operationDocs == null || operationDocs.size() == 0) {
            status.set("0");
            return;
        }
        if (ListUtil.isNotEmpty(operationDocs)) {
            long count = operationDocs.stream().filter(operationDoc -> {
                boolean flag = false;
                if (operationDoc.getOperationDiscussionDoc() != null
                        && operationDoc.getOperationDiscussionDoc().getOperationDiscussionLabel() != null
                        && operationDoc.getOperationDiscussionDoc().getOperationDiscussionLabel().getVitals().size() == 0) {
                    flag = true;
                }
                return flag;
            }).count();
            long matchCount = operationDocs.stream().filter(operationDoc -> {
                boolean flag = false;
                if (operationDoc.getOperationDiscussionDoc() != null
                        && StringUtil.isNotBlank(operationDoc.getOperationDiscussionDoc().getText())
                        && (operationDoc.getOperationDiscussionDoc().getText().contains("°C")
                        || operationDoc.getOperationDiscussionDoc().getText().contains("次/分")
                        || operationDoc.getOperationDiscussionDoc().getText().contains("mmHg")
                )) {
                    flag = true;
                }
                return flag;
            }).count();
            /* count为术后首程中没有生命体征的数量，matchCount为术后首程包含体温 呼吸 脉搏 血压 心率这些词的数量 */
            if (count > 0 && matchCount == 0) {
                status.set("-1");
            }
        }
        //        }
    }

}