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

import com.alibaba.fastjson.JSONArray;
import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.kernel.client.ChiefPresentSimilarityServiceClient;
import com.lantone.qc.kernel.structure.ai.ModelAI;
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.model.entity.Diag;
import com.lantone.qc.pub.model.label.CaseCharacteristicLabel;
import com.lantone.qc.pub.model.label.ChiefLabel;
import com.lantone.qc.pub.model.label.DiagLabel;
import com.lantone.qc.pub.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

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

/**
 * @ClassName : FIRC0087
 * @Description : 无鉴别诊断
 * @Author : 楼辉荣
 * @Date: 2020-03-06 17:28
 */
@Component
public class FIRC0087 extends QCCatalogue {
    @Autowired
    ChiefPresentSimilarityServiceClient chiefPresentSimilarityServiceClient;

    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        FirstCourseRecordDoc firstCourseRecordDoc = inputInfo.getFirstCourseRecordDoc();
        if (firstCourseRecordDoc != null) {
            DiagLabel differentialDiagLabel = firstCourseRecordDoc.getDifferentialDiagLabel();
            CaseCharacteristicLabel casecharLabel = firstCourseRecordDoc.getCaseCharacteristicLabel();
            DiagLabel initDiagLabel = firstCourseRecordDoc.getInitialDiagLabel();

            if (differentialDiagLabel != null) {
                Map<String, String> structureMap = firstCourseRecordDoc.getStructureMap();
                String diffDiagStruct = structureMap.get("鉴别诊断");
                if(StringUtils.isNotEmpty(diffDiagStruct)){
                    return;
                }
                /*if (StringUtil.isNotBlank(diffDiagStruct) && (diffDiagStruct.contains("诊断明确") || diffDiagStruct.contains("无需鉴别")
                        || diffDiagStruct.contains("明确诊断"))) {
                    return;
                }*/

                //List<Diag> diags = differentialDiagLabel.getDiags();
                String diag = initDiagLabel.getDiags().get(0).getHospitalDiagName();
                String casechar = casecharLabel.getText();
                String chief = "";
                String present = "";
                if (casechar.contains("主诉") && casechar.contains("现病史")) {
                    chief = casechar.substring(casechar.indexOf("主诉") + 2, casechar.indexOf("现病史"));
                    present = casechar.substring(casechar.indexOf("现病史") + 3, casechar.indexOf("既往史"));
                }

                if (StringUtils.isNotEmpty(differentialDiagLabel.getText())) {
                    if (differentialDiagLabel.getText().contains("诊断明确")
                            || differentialDiagLabel.getText().contains("无需鉴别")) {
                        if (chief.contains("术后") || chief.contains("孕") || chief.contains("化疗")
                                || chief.contains("肿瘤") || chief.contains("癌") || chief.contains("确诊")
                                || chief.contains("外伤") || chief.contains("摔伤")) {
                            status.set("0");
                        } else if (present.contains(diag)) {
                            status.set("0");
                        } else {
                            status.set("-1");
                        }
                    }
                } else if (StringUtils.isEmpty(differentialDiagLabel.getText())) {
                    status.set("-1");
                }
                /*
                if(diags == null || diags.size()<1){
                    status.set("-1");
                }

                if (StringUtils.isNotEmpty(differentialDiagLabel.getText())
                        && (differentialDiagLabel.getText().contains("暂缺")
                            || differentialDiagLabel.getText().contains("无") || differentialDiagLabel.getText().contains("诊断"))) {
                    status.set("0");
                }
                */
            }
        }
    }

}