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

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

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

/**
 * @ClassName : DEAC0108
 * @Description : 死亡患者无死亡病例讨论记录
 * @Author : 胡敬
 * @Date: 2020-03-19 11:24
 */
@Component
public class DEAC0108 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        DeathRecordDoc deathRecordDoc = inputInfo.getDeathRecordDoc();
        if (inputInfo.getFirstPageRecordDoc() != null && inputInfo.getFirstPageRecordDoc().getStructureMap() != null) {
            Map<String, String> FirstPageStructure = inputInfo.getFirstPageRecordDoc().getStructureMap();
            String outWay = FirstPageStructure.get(Content.outWay);
            //判断患者是否死亡
            if (CatalogueUtil.isEmpty(outWay) || !outWay.contains("死亡")) {
                return;
            }
            List<DoctorAdviceDoc> doctorAdviceDocs = inputInfo.getDoctorAdviceDocs();
            if (doctorAdviceDocs.size() == 0 ) {
                return;
            }
            long count = doctorAdviceDocs.stream().filter(x -> x.getStructureMap().get("医嘱项目名称").contains("死亡")).count();
            if((count>0 || outWay.contains("死亡")) && (inputInfo.getDeathCaseDiscussDoc() == null || inputInfo.getDeathCaseDiscussDoc().getStructureMap().size() == 0)){
                status.set("-1");
            }
            /*if (((inputInfo.getDeathCaseDiscussDoc() == null || inputInfo.getDeathCaseDiscussDoc().getStructureMap().size() == 0)
            && outWay.contains("死亡")) || ((inputInfo.getDeathCaseDiscussDoc() == null || inputInfo.getDeathCaseDiscussDoc().getStructureMap().size() == 0)
            && deathRecordDoc != null)){
                status.set("-1");
            }*/
        }
    }
}