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

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

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @ClassName : FIRP03045
 * @Description : 呼吸机辅助治疗未记录
 * 医嘱里找呼吸机
 * 手术和操作里面找
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class FIRP03045 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getFirstPageRecordDoc() != null && inputInfo.getFirstPageRecordDoc().getStructureExtMap() != null
                && inputInfo.getDoctorAdviceDocs().size() > 0) {
            List<DoctorAdviceDoc> doctorAdviceDocs = inputInfo.getDoctorAdviceDocs();
            List<String> docAdviceElement = doctorAdviceDocs
                    .stream()
                    .map(x -> x.getStructureMap().get("医嘱项目名称"))
                    .filter(x -> x != null && x.contains("呼吸机"))
                    .collect(Collectors.toList());

            Map<String, Object> extMap = inputInfo.getFirstPageRecordDoc().getStructureExtMap();
            List<Map<String, String>> operationList = (List<Map<String, String>>) extMap.get("手术信息");
            if (operationList != null && operationList.size() > 0) {
                List<String> firstPageElement = operationList
                        .stream()
                        .map(x -> x.get("手术名称"))
                        .filter(x -> StringUtil.isNotBlank(x) && x.contains("呼吸机"))
                        .collect(Collectors.toList());

                if (docAdviceElement.size() > 0 && firstPageElement.size() == 0) {
                    status.set("-1");
                }
            }

        }
    }
}