package com.lantone.structure.ai;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lantone.common.util.ListUtil;
import com.lantone.structure.ai.process.*;
import com.lantone.structure.client.CRFServiceClient;
import com.lantone.structure.ai.process.EntityProcessClinic;
import com.lantone.structure.ai.process.EntityProcessDiag;
import com.lantone.structure.ai.process.EntityProcessFamily;
import com.lantone.structure.ai.process.EntityProcessLis;
import com.lantone.structure.ai.process.EntityProcessMarital;
import com.lantone.structure.ai.process.EntityProcessMenses;
import com.lantone.structure.ai.process.EntityProcessPacs;
import com.lantone.structure.ai.process.EntityProcessPast;
import com.lantone.structure.ai.process.EntityProcessPersonal;
import com.lantone.structure.ai.process.EntityProcessVital;
import com.lantone.structure.model.Content;
import com.lantone.structure.model.InputInfo;
import com.lantone.structure.model.doc.BeHospitalizedDoc;
import com.lantone.structure.model.entity.*;
import com.lantone.structure.model.label.*;
import com.lantone.common.util.FastJsonUtils;
import com.lantone.common.util.StringUtil;
import org.springframework.stereotype.Component;

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

import static com.lantone.structure.model.Content.developmentLabel;
import static com.lantone.structure.model.Content.familyLabel;

/**
 * @ClassName : InHospitalDoc
 * @Description :
 * @Author : 楼辉荣
 * @Date: 2020-03-03 18:58
 */
@Component
public class BeHospitalizedAI extends ModelAI {
    /**
     * FirstCourseRecord_cx[病历首程]
     * PastFamily_cx[既往史家族史]
     * PersonalHistory_cx[个人史(月经史、婚育史)]
     * HPIForCX_cx[主诉、现病史、专科检查]
     * GeneralVital_cx[一般体格检查]
     * chief_present[邵逸夫医院主诉]
     * Diagnoses_cx[诊断]
     * Present_cx[现病史]
     * DiagnoseInAssistant[辅助检查]
     */
    public static List<String> medicalTextType = Arrays.asList("FirstCourseRecord_cx", "PastFamily_cx", "PersonalHistory_cx", "HPIForCX_cx",
            "GeneralVital_cx", "chief_present", "Diagnoses_cx", "Present_cx", "DiagnoseInAssistant","Taizhou_past_family","Taizhou_growth");
    public static String entityRelationObject = "entity_relation_object";
    public static String outputs = "outputs";

    public void medrec(InputInfo inputInfo, CRFServiceClient crfServiceClient) {
        JSONArray crfContent = new JSONArray();
        BeHospitalizedDoc beHospitalizedDoc = inputInfo.getBeHospitalizedDoc();
        if (beHospitalizedDoc != null) {
            Map<String, String> structureMap = beHospitalizedDoc.getStructureMap();
           // String text = beHospitalizedDoc.getText();
            if (StringUtil.isNotEmpty(structureMap.get("既往史"))) {
                String opName = "既往史：" + structureMap.get("既往史");
                putContent(crfContent, medicalTextType.get(9), opName, Content.pastLabel);
            }
            if (StringUtil.isNotEmpty(structureMap.get("家族史"))) {
                String opName = "家族史：" + structureMap.get("家族史");
                putContent(crfContent, medicalTextType.get(9), opName, familyLabel);
            }
            if (StringUtil.isNotEmpty(structureMap.get("生长发育史"))) {
                String opName = structureMap.get("生长发育史").replace("：","").replace(":","");
                putContent(crfContent, medicalTextType.get(10), opName, developmentLabel);
            }
            /* 主诉 */
            if (beHospitalizedDoc.getChiefLabel() != null && beHospitalizedDoc.getChiefLabel().isCrfLabel()) {
                String chiefText = beHospitalizedDoc.getChiefLabel().getText();
                if (StringUtil.isNotBlank(chiefText)) {
                    chiefText = "主诉：" + StringUtil.removeBlank(chiefText);//主诉入参 文本前需加 "主诉："
                    putContent(crfContent, medicalTextType.get(7), chiefText, Content.chief);/* 2020-06-08修改主诉模型为现病史模型 */
                }
            }
            /* 现病史 */
            if (beHospitalizedDoc.getPresentLabel() != null && beHospitalizedDoc.getPresentLabel().isCrfLabel()) {
                String presentText = beHospitalizedDoc.getPresentLabel().getText();
                putContent(crfContent, medicalTextType.get(7), presentText, Content.present);
            }
            /* 既往史 */
            if (beHospitalizedDoc.getPastLabel() != null && beHospitalizedDoc.getPastLabel().isCrfLabel()) {
                String pastText = beHospitalizedDoc.getPastLabel().getText();
                putContent(crfContent, medicalTextType.get(1), pastText, Content.past);
            }
            /* 月经史文本需从个人史截取一部分文本拼接 */
            String concatMenstrual = "";
            /* 个人史 */
            if (beHospitalizedDoc.getPersonalLabel() != null && beHospitalizedDoc.getPersonalLabel().isCrfLabel()) {
                String personalText = beHospitalizedDoc.getPersonalLabel().getText();
                putContent(crfContent, medicalTextType.get(2), personalText, Content.personal);
                concatMenstrual = getConcatMenstrual(concatMenstrual, personalText);
            }
            /* 婚育史 */
            if (beHospitalizedDoc.getMaritalLabel() != null && beHospitalizedDoc.getMaritalLabel().isCrfLabel()) {
                String maritalText = beHospitalizedDoc.getMaritalLabel().getText();
                putContent(crfContent, medicalTextType.get(2), maritalText, Content.marriage);
            }
            /* 月经史 */
            if (beHospitalizedDoc.getMenstrualLabel() != null && beHospitalizedDoc.getMenstrualLabel().isCrfLabel()) {
                String menstrualText = beHospitalizedDoc.getMenstrualLabel().getText();
                putContent(crfContent, medicalTextType.get(2), concatMenstrual, menstrualText, Content.menses);
            }
            /* 家族史 */
            if (beHospitalizedDoc.getFamilyLabel() != null && beHospitalizedDoc.getFamilyLabel().isCrfLabel()) {
                String familyText = beHospitalizedDoc.getFamilyLabel().getText();
                putContent(crfContent, medicalTextType.get(1), familyText, Content.family);
            }
            /* 辅助检查 */
            if (beHospitalizedDoc.getPacsLabel() != null && beHospitalizedDoc.getPacsLabel().isCrfLabel()) {
                String pacsText = beHospitalizedDoc.getPacsLabel().getText();
                putContent(crfContent, medicalTextType.get(3), pacsText, Content.pacs + "含时间地点");
                putContent(crfContent, medicalTextType.get(8), pacsText, Content.pacs);
            }
            /* 专科检查(专科体格检查) */
            if (beHospitalizedDoc.getVitalLabelSpecial() != null && beHospitalizedDoc.getVitalLabelSpecial().isCrfLabel()) {
                String vitalSpecialText = beHospitalizedDoc.getVitalLabelSpecial().getText();
                putContent(crfContent, medicalTextType.get(7), vitalSpecialText, Content.special_exam);
            }
            /* 一般体格检查(存放一般查体) */
            if (beHospitalizedDoc.getVitalLabel() != null && beHospitalizedDoc.getVitalLabel().isCrfLabel()) {
                String vitalText = beHospitalizedDoc.getVitalLabel().getText();
                putContent(crfContent, medicalTextType.get(4), vitalText, Content.phys_exam);
            }
            /* 初步诊断 */
            if (beHospitalizedDoc.getInitialDiagLabel() != null && beHospitalizedDoc.getInitialDiagLabel().isCrfLabel()) {
                String initialDiagText = beHospitalizedDoc.getInitialDiagLabel().getText();
                if (StringUtil.isNotBlank(initialDiagText)) {
                    /*initial_diag_text = CatalogueUtil.removeBetweenWordSpace(initial_diag_text);*/
                    putContent(crfContent, medicalTextType.get(6), initialDiagText, Content.initial_diag);
                }
            }
            /* 修正诊断 */
            if (beHospitalizedDoc.getRevisedDiagLabel() != null && beHospitalizedDoc.getRevisedDiagLabel().isCrfLabel()) {
                String revisedDiagText = beHospitalizedDoc.getRevisedDiagLabel().getText();
                /*if (CatalogueUtil.numberExist(initial_diag_text)) {
                    revised_diag_text = CatalogueUtil.removeBetweenWordSpace(revised_diag_text);
                }*/
                putContent(crfContent, medicalTextType.get(6), revisedDiagText, Content.revised_diag);
            }
            /* 补充诊断 */
            if (beHospitalizedDoc.getSuppleDiagLabel() != null && beHospitalizedDoc.getSuppleDiagLabel().isCrfLabel()) {
                String suppleDiagText = beHospitalizedDoc.getSuppleDiagLabel().getText();
                /*if (CatalogueUtil.numberExist(initial_diag_text)) {
                    supple_diag_text = CatalogueUtil.removeBetweenWordSpace(supple_diag_text);
                }*/
                putContent(crfContent, medicalTextType.get(6), suppleDiagText, Content.supple_diag);
            }

            JSONObject midData = loadAI(crfContent, crfServiceClient);
            if (midData.get(Content.pastLabel) != null || midData.get(familyLabel) != null || midData.get(developmentLabel) != null){
                BeHospitalizedDoc beHospitalizedDocs = new BeHospitalizedDoc();
                /* 恩泽过敏史、输血史、手术史、预防接种史、疾病史（含外伤）*/
                if (midData.get(Content.pastLabel) != null)
                    EZAllCrfData(midData.getJSONObject(Content.pastLabel), inputInfo);
                     beHospitalizedDocs = inputInfo.getBeHospitalizedDoc();
                List<DiagInfectious> flagDia = beHospitalizedDocs.getPastLabel().getDiagInfectiouses();
                /* 恩泽传染病史 */
                if (midData.get(familyLabel) != null) {
                    EZAllCrfData(midData.getJSONObject(familyLabel), inputInfo);
                    List<DiagInfectious> diagInfectiouses = inputInfo.getBeHospitalizedDoc().getPastLabel().getDiagInfectiouses();
                    if(ListUtil.isNotEmpty(flagDia) && ListUtil.isNotEmpty(diagInfectiouses)){
                        for (DiagInfectious diagInfectiouse : diagInfectiouses) {
                            flagDia.add(diagInfectiouse);
                        }
                    }else {
                        if(ListUtil.isNotEmpty(diagInfectiouses)){
                            flagDia = diagInfectiouses;
                        }
                    }
                    beHospitalizedDocs.getPastLabel().setDiagInfectiouses(flagDia);
                    inputInfo.setBeHospitalizedDoc(beHospitalizedDocs);
                }
                /* 恩泽生长发育史 */
                if (midData.get(developmentLabel) != null) {
                    EZAllCrfData(midData.getJSONObject(developmentLabel), inputInfo);
                }
            }

            /* 处理主诉 */
            if (beHospitalizedDoc.getChiefLabel() != null && beHospitalizedDoc.getChiefLabel().isCrfLabel()) {
                putChiefCrfData(midData.getJSONObject(Content.chief), inputInfo);
            }
            /* 处理现病史 */
            if (beHospitalizedDoc.getPresentLabel() != null && beHospitalizedDoc.getPresentLabel().isCrfLabel()) {
                putPresentCrfData(midData.getJSONObject(Content.present), inputInfo);
                beHospitalizedDoc.getPresentLabel().setCrfOutput(midData.getJSONObject(Content.present));
                System.out.println(FastJsonUtils.getBeanToJson(beHospitalizedDoc.getPresentLabel()));
            }
            /* 处理既往史 */
            if (beHospitalizedDoc.getPastLabel() != null && beHospitalizedDoc.getPastLabel().isCrfLabel()) {
                putPastCrfData(midData.getJSONObject(Content.past), inputInfo);
            }
            /* 处理个人史 */
            if (beHospitalizedDoc.getPersonalLabel() != null && beHospitalizedDoc.getPersonalLabel().isCrfLabel()) {
                putPersonalCrfData(midData.getJSONObject(Content.personal), inputInfo);
            }
            /* 处理月经史 */
            if (beHospitalizedDoc.getMenstrualLabel() != null && beHospitalizedDoc.getMenstrualLabel().isCrfLabel()) {
                putMensesCrfData(midData.getJSONObject(Content.menses), inputInfo);
            }
            /* 处理家族史 */
            if (beHospitalizedDoc.getFamilyLabel() != null && beHospitalizedDoc.getFamilyLabel().isCrfLabel()) {
                putFamilyCrfData(midData.getJSONObject(Content.family), inputInfo);
            }
            /* 处理婚育史 */
            if (beHospitalizedDoc.getMaritalLabel() != null && beHospitalizedDoc.getMaritalLabel().isCrfLabel()) {
                putMaritalCrfData(midData.getJSONObject(Content.marriage), inputInfo);
            }
            /* 处理初步诊断 */
            if (beHospitalizedDoc.getInitialDiagLabel() != null && beHospitalizedDoc.getInitialDiagLabel().isCrfLabel()) {
                putInitialDiagCrfData(midData.getJSONObject(Content.initial_diag), inputInfo);
            }
            /* 处理修正诊断 */
            if (beHospitalizedDoc.getRevisedDiagLabel() != null && beHospitalizedDoc.getRevisedDiagLabel().isCrfLabel()) {
                putRevisedDiagCrfData(midData.getJSONObject(Content.revised_diag), inputInfo);
            }
            /* 处理补充诊断 */
            if (beHospitalizedDoc.getSuppleDiagLabel() != null && beHospitalizedDoc.getSuppleDiagLabel().isCrfLabel()) {
                putSuppleDiagCrfData(midData.getJSONObject(Content.supple_diag), inputInfo);
            }
            /* 处理专科体格检查 */
            if (beHospitalizedDoc.getVitalLabelSpecial() != null && beHospitalizedDoc.getVitalLabelSpecial().isCrfLabel()) {
                beHospitalizedDoc.getVitalLabelSpecial().setCrfOutput(midData.getJSONObject(Content.special_exam));
            }
            /* 处理辅助检查 */
            if (beHospitalizedDoc.getPacsLabel() != null && beHospitalizedDoc.getPacsLabel().isCrfLabel()) {
                /* 辅检提取时间、地点和提取疾病分为两个模型 */
                putPacsCrfData(midData.getJSONObject(Content.pacs + "含时间地点"), inputInfo);
                putPacsCrfData(midData.getJSONObject(Content.pacs), inputInfo);
            }
        }
    }

    public void putChiefCrfData(JSONObject jsonObject, InputInfo inputInfo) {
        if (jsonObject == null) {
            return;
        }
        JSONObject aiOut = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
        if (aiOut == null) {
            return;
        }
        //使用现病史结构
        EntityProcessClinic entityProcessClinic = new EntityProcessClinic();
        PresentLabel presentLabel = entityProcessClinic.extractEntity(aiOut);

        ChiefLabel chiefLabel = inputInfo.getBeHospitalizedDoc().getChiefLabel();
        chiefLabel.setClinicals(presentLabel.getClinicals());
        chiefLabel.setDiags(presentLabel.getDiags());
        chiefLabel.setPds(presentLabel.getPds());
        System.out.println(FastJsonUtils.getBeanToJson(chiefLabel));
    }

         public void EZAllCrfData(JSONObject jsonObject, InputInfo inputInfo) {
        if (jsonObject == null) {
            return;
        }
        JSONObject aiOut = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
        if (aiOut == null) {
            return;
        }
             EntityProcessEZaAll entityProcessEZaAll = new EntityProcessEZaAll();
             BeHospitalizedDoc beHospitalizedDoc = entityProcessEZaAll.extractEntity(aiOut);
             inputInfo.setBeHospitalizedDoc(beHospitalizedDoc);
         }

    public void putPresentCrfData(JSONObject jsonObject, InputInfo inputInfo) {
        if (jsonObject == null) {
            return;
        }
        JSONObject aiOut = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
        if (aiOut == null) {
            return;
        }
        //放置入inputinfo
        EntityProcessClinic entityProcessClinic = new EntityProcessClinic();
        PresentLabel presentLabel = entityProcessClinic.extractEntity(aiOut);
        presentLabel.setText(inputInfo.getBeHospitalizedDoc().getPresentLabel().getText());
        List<Lis> lis = loadLises(aiOut);
        presentLabel.setLises(lis);
        inputInfo.getBeHospitalizedDoc().setPresentLabel(presentLabel);
    }

    /**
     * 家族史
     *
     * @param jsonObject
     * @param inputInfo
     */
    public void putFamilyCrfData(JSONObject jsonObject, InputInfo inputInfo) {
        if (jsonObject == null) {
            return;
        }
        JSONObject aiOut = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
        if (aiOut == null) {
            return;
        }
        //家族史信息处理
        EntityProcessFamily entityProcess = new EntityProcessFamily();
        FamilyLabel familyLabel = entityProcess.extractEntity(aiOut);
        familyLabel.setText(inputInfo.getBeHospitalizedDoc().getFamilyLabel().getText());
        inputInfo.getBeHospitalizedDoc().setFamilyLabel(familyLabel);
    }

    /**
     * 婚育史
     *
     * @param jsonObject
     * @param inputInfo
     */
    public void putMaritalCrfData(JSONObject jsonObject, InputInfo inputInfo) {
        if (jsonObject == null) {
            return;
        }
        JSONObject aiOut = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
        if (aiOut == null) {
            return;
        }
        //家族史信息处理
        EntityProcessMarital entityProcess = new EntityProcessMarital();
        MaritalLabel maritalLabel = entityProcess.extractEntity(aiOut);
        maritalLabel.setText(inputInfo.getBeHospitalizedDoc().getMaritalLabel().getText());
        inputInfo.getBeHospitalizedDoc().setMaritalLabel(maritalLabel);
    }

    public void putPastCrfData(JSONObject jsonObject, InputInfo inputInfo) {
        if (jsonObject == null) {
            return;
        }
        JSONObject aiOut = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
        if (aiOut == null) {
            return;
        }
        //放置入inputinfo
        EntityProcessPast entityProcessPast = new EntityProcessPast();
        PastLabel pastLabel = entityProcessPast.extractEntity(aiOut);
        pastLabel.setText(inputInfo.getBeHospitalizedDoc().getPastLabel().getText());
        inputInfo.getBeHospitalizedDoc().setPastLabel(pastLabel);

    }

    /**
     * 个人史信息提取
     *
     * @param jsonObject
     * @param inputInfo
     */
    public void putPersonalCrfData(JSONObject jsonObject, InputInfo inputInfo) {
        if (jsonObject == null) {
            return;
        }
        JSONObject aiOut = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
        if (aiOut == null) {
            return;
        }
        //个人史信息提取
        EntityProcessPersonal entityProcessPersonal = new EntityProcessPersonal();
        PersonalLabel personalLabel = entityProcessPersonal.extractEntity(aiOut);
        personalLabel.setText(inputInfo.getBeHospitalizedDoc().getPersonalLabel().getText());
        inputInfo.getBeHospitalizedDoc().setPersonalLabel(personalLabel);
    }

    /**
     * 月经史信息提取
     *
     * @param jsonObject
     * @param inputInfo
     */
    public void putMensesCrfData(JSONObject jsonObject, InputInfo inputInfo) {
        if (jsonObject == null || jsonObject.getJSONObject(entityRelationObject) == null) {
            return;
        }
        JSONObject aiOut = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
        if (aiOut == null) {
            return;
        }
        //月经史信息处理
        EntityProcessMenses entityProcess = new EntityProcessMenses();
        MenstrualLabel menstrualLabel = entityProcess.extractEntity(aiOut);
        menstrualLabel.setText(inputInfo.getBeHospitalizedDoc().getMenstrualLabel().getText());
        inputInfo.getBeHospitalizedDoc().setMenstrualLabel(menstrualLabel);
    }

    /**
     * 初步诊断信息提取
     *
     * @param jsonObject
     * @param inputInfo
     */
    public void putInitialDiagCrfData(JSONObject jsonObject, InputInfo inputInfo) {
        if (jsonObject == null) {
            return;
        }
        JSONObject aiOut = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
        if (aiOut == null) {
            return;
        }
        //诊断信息
        EntityProcessDiag entityProcessDiag = new EntityProcessDiag();
        List<Diag> diags = entityProcessDiag.extractEntity(aiOut);

        DiagLabel initialDiagLabel = new DiagLabel();
        initialDiagLabel.setText(inputInfo.getBeHospitalizedDoc().getInitialDiagLabel().getText());
        initialDiagLabel.setDiags(diags);
        inputInfo.getBeHospitalizedDoc().setInitialDiagLabel(initialDiagLabel);

        //        //因为关系抽取未标注完成，先用规则
        //        String diagString = inputInfo.getBeHospitalizedDoc().getInitialDiagLabel().getText();
        //        if (StringUtils.isNotEmpty(diagString)) {
        //            String[] diagArray = diagString.split(",");
        //            List<Diag> diags = new ArrayList<>();
        //            for (String d : diagArray) {
        //                Diag diag = DiagEnhancer.create(d);
        //                diags.add(diag);
        //            }
        //            InitialDiagLabel initialDiagLabel = new InitialDiagLabel();
        //            initialDiagLabel.setDiags(diags);
        //        }
    }

    /**
     * 修正诊断信息提取
     *
     * @param jsonObject
     * @param inputInfo
     */
    public void putRevisedDiagCrfData(JSONObject jsonObject, InputInfo inputInfo) {
        if (jsonObject == null) {
            return;
        }
        JSONObject aiOut = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
        if (aiOut == null) {
            return;
        }
        //诊断信息
        EntityProcessDiag entityProcessDiag = new EntityProcessDiag();
        List<Diag> diags = entityProcessDiag.extractEntity(aiOut);

        DiagLabel revisedDiagLabel = new DiagLabel();
        revisedDiagLabel.setText(inputInfo.getBeHospitalizedDoc().getRevisedDiagLabel().getText());
        revisedDiagLabel.setDiags(diags);
        inputInfo.getBeHospitalizedDoc().setRevisedDiagLabel(revisedDiagLabel);

        //替换初步诊断中的第一个诊断信息
       /* DiagLabel initialDiagLabel = inputInfo.getBeHospitalizedDoc().getInitialDiagLabel();
        if (initialDiagLabel.getDiags().size() > 0 && diags.size() > 0) {
            initialDiagLabel.getDiags().remove(0);
            initialDiagLabel.getDiags().add(0, diags.get(0));
        }*/
    }

    /**
     * 补充诊断信息提取
     *
     * @param jsonObject
     * @param inputInfo
     */
    public void putSuppleDiagCrfData(JSONObject jsonObject, InputInfo inputInfo) {
        if (jsonObject == null) {
            return;
        }
        JSONObject aiOut = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
        if (aiOut == null) {
            return;
        }
        //诊断信息
        EntityProcessDiag entityProcessDiag = new EntityProcessDiag();
        List<Diag> diags = entityProcessDiag.extractEntity(aiOut);

        DiagLabel suppleDiagLabel = new DiagLabel();
        suppleDiagLabel.setText(inputInfo.getBeHospitalizedDoc().getSuppleDiagLabel().getText());
        suppleDiagLabel.setDiags(diags);
        inputInfo.getBeHospitalizedDoc().setSuppleDiagLabel(suppleDiagLabel);
    }

    /**
     * 辅助检查信息抽取
     *
     * @param jsonObject
     * @param inputInfo
     */
    public void putPacsCrfData(JSONObject jsonObject, InputInfo inputInfo) {
        if (jsonObject == null) {
            return;
        }
        JSONObject aiOut = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
        if (aiOut == null) {
            return;
        }
        //放置入inputinfo
        PacsLabel pacsLabel = inputInfo.getBeHospitalizedDoc().getPacsLabel();
        if (pacsLabel.getPacses() == null) {
            pacsLabel.setPacses(loadPacses(aiOut));
        } else {
            List<Pacs> pacses = pacsLabel.getPacses();
            pacses.addAll(loadPacses(aiOut));
            pacsLabel.setPacses(pacses);
        }
    }

    /**
     * 关系抽取疾病信息
     *
     * @param aiOut
     * @return
     */
    public List<Diag> loadDiags(JSONObject aiOut) {
        //诊断信息
        EntityProcessDiag entityProcessDiag = new EntityProcessDiag();
        List<Diag> diags = entityProcessDiag.extractEntity(aiOut);
        return diags;
    }

    /**
     * 关系抽取化验信息
     *
     * @param aiOut
     * @return
     */
    public List<Lis> loadLises(JSONObject aiOut) {
        //化验信息
        EntityProcessLis entityProcessLis = new EntityProcessLis();
        List<Lis> lises = entityProcessLis.extractEntity(aiOut);
        return lises;
    }

    /**
     * 关系抽取辅检信息
     *
     * @param aiOut
     * @return
     */
    public List<Pacs> loadPacses(JSONObject aiOut) {
        //辅检信息
        EntityProcessPacs entityProcessLis = new EntityProcessPacs();
        List<Pacs> pacses = entityProcessLis.extractEntity(aiOut);
        return pacses;
    }

    /**
     * 关系抽取体格检查
     *
     * @param aiOut
     * @return
     */
    public List<Vital> loadvital(JSONObject aiOut) {
        //一般情况描述信息
        EntityProcessVital entityProcessVital = new EntityProcessVital();
        List<Vital> vitals = entityProcessVital.extractEntity(aiOut);
        return vitals;
    }

    /**
     * 从个人史取最后30个字，拼接到月经史
     *
     * @param concatMenstrual
     * @param personalText
     * @return
     */
    private String getConcatMenstrual(String concatMenstrual, String personalText) {
        if (personalText != null) {
            if (personalText.length() > 30) {
                concatMenstrual = personalText.substring(personalText.length() - 30);
            } else {
                concatMenstrual = personalText;
            }
        }
        return concatMenstrual;
    }
}