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

import com.google.common.collect.Lists;
import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.kernel.util.CatalogueUtil;
import com.lantone.qc.pub.model.InputInfo;
import com.lantone.qc.pub.model.OutputInfo;
import com.lantone.qc.pub.model.doc.FirstCourseRecordDoc;
import com.lantone.qc.pub.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @ClassName : FIRC0084
 * @Description : 首程记录内容不可写同上
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class FIRC0084 extends QCCatalogue {
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        FirstCourseRecordDoc firstCourseRecordDoc = inputInfo.getFirstCourseRecordDoc();
        if (firstCourseRecordDoc != null) {
            Map<String, String> courseRecordDocStructureMap = firstCourseRecordDoc.getStructureMap();
            if (courseRecordDocStructureMap != null) {
                String identify_diag = courseRecordDocStructureMap.get("鉴别诊断");
                String characteristic = courseRecordDocStructureMap.get("病例特点");
                String initDiags = courseRecordDocStructureMap.get("初步诊断");
                String condition = courseRecordDocStructureMap.get("诊断依据");
                String pacs = courseRecordDocStructureMap.get("辅助检查");
                if (StringUtil.isBlank(pacs)){
                    pacs = getPacs(courseRecordDocStructureMap);
                }
                String tretment_plan = courseRecordDocStructureMap.get("诊疗计划");
                if (StringUtils.isNotEmpty(tretment_plan)) {
                    if (CatalogueUtil.removeSpecialChar(tretment_plan).contains("同上")) {
                        status.set("-1");
                    }
                } else if (StringUtils.isNotEmpty(identify_diag)) {
                    if (CatalogueUtil.removeSpecialChar(identify_diag).contains("同上")) {
                        status.set("-1");
                    }
                } else if (StringUtils.isNotEmpty(characteristic)) {
                    if (CatalogueUtil.removeSpecialChar(characteristic).contains("同上")) {
                        status.set("-1");
                    }
                } else if (StringUtils.isNotEmpty(initDiags)) {
                    if (CatalogueUtil.removeSpecialChar(initDiags).contains("同上")) {
                        status.set("-1");
                    }
                } else if (StringUtils.isNotEmpty(condition)) {
                    if (CatalogueUtil.removeSpecialChar(condition).contains("同上")) {
                        status.set("-1");
                    }
                } else if (StringUtils.isNotEmpty(pacs)) {
                    if (CatalogueUtil.removeSpecialChar(pacs).contains("同上")) {
                        status.set("-1");
                    }
                }
            }
        }
    }

    private String getPacs(Map<String, String> courseRecordDocStructureMap) {
        return CatalogueUtil.structureMapJoin(courseRecordDocStructureMap, Lists.newArrayList("实验室检查", "影像学检查"));
    }
}