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

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

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

/**
 * @ClassName : THR0141
 * @Description : 危重患者、疑难患者、抢救患者无主任医师/科主任查房记录
 * @Author : 胡敬
 * @Date: 2020-03-19 19:26
 */
@Component
public class THR0141 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getThreeLevelWardDocs().size() == 0) {
            return;
        }
        List<ThreeLevelWardDoc> allDoctorWradDocs = inputInfo.getThreeLevelWardDocs().get(0).getAllDoctorWradDocs();
        if (ListUtil.isEmpty(allDoctorWradDocs)) {
            return;
        }
        if (inputInfo.getDifficultCaseDiscussDocs().size() > 0) {
            processSign(allDoctorWradDocs, "疑难患者");
        }
        if (inputInfo.getRescueDocs().size() > 0) {
            processSign(allDoctorWradDocs, "抢救患者");
        }
    }

    private void processSign(List<ThreeLevelWardDoc> allDoctorWradDocs, String message) {
        int directorSum = 0;
        for (ThreeLevelWardDoc threeLevelWardDoc : allDoctorWradDocs) {
            Map<String, String> threeLevelWardDocStructureMap = threeLevelWardDoc.getStructureMap();
            String title = threeLevelWardDocStructureMap.get("查房标题");
            if (CatalogueUtil.isEmpty(title)) {
                continue;
            }
            if (CatalogueUtil.subTitle(title).contains(Content.director)) {
                directorSum++;
            }
        }
        if (directorSum == 0) {
            status.set("-1");
            if (StringUtil.isBlank(info.toString())) {
                info.set(message);
            } else {
                info.set(info.get() + "," + message);
            }
        }
    }
}