package com.yihu.figure.service.jw;

import com.yihu.figure.service.dict.SystemDictService;
import com.yihu.figure.util.HttpClientUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * Created by hzp on 2016/11/15.
 * 基卫健康档案服务
 */
@Service("JwArchivesService")
public class JwArchivesService {

    //基卫服务地址
    @Value("${jiwei.url}")
    private String jwUrl ;

    @Autowired
    private SystemDictService systemDictService;


    /**
     *  查询居民健康体检列表信息接口
     */
    public JSONArray getEhrSickMedicalList(String idcard,Integer pageIndex,Integer pageSize)  throws Exception
    {
        JSONArray re =  new JSONArray();
        String url = jwUrl + "/third/archives/getEhrSickMedicalList";

        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("idcard", idcard));

        String response = HttpClientUtil.post(url, params, "UTF-8");
        if(!StringUtils.isEmpty(response))
        {
            JSONObject json = new JSONObject(response);
            if (!"200".equals(json.optString("status"))) {
                throw new Exception(json.optString("msg"));
            }else{
                String dataStr = json.getString("data");
                if(!StringUtils.isEmpty(dataStr)){
                    JSONObject data = new JSONObject(dataStr);
                    if("1".equals(data.optString("CODE")))
                    {
                        JSONArray jsonArray = data.getJSONArray("DATA");
                        List<JSONObject> jsonValues = new ArrayList<JSONObject>();
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            JSONObject mjson = new JSONObject();
                            String medicalNo  = jsonObject.get("MEDICAL_NO").toString();
                            mjson.put("orgName",jsonObject.get("ORG_NAME").toString());
                            mjson.put("medicalNo",medicalNo);
                            mjson.put("medicalTime",jsonObject.get("MEDICAL_TIME").toString());
                            jsonValues.add(mjson);
                        }
                        Collections.sort( jsonValues, new Comparator<JSONObject>() {
                            @Override
                            public int compare(JSONObject a, JSONObject b) {
                                String valA = a.get("medicalTime").toString();
                                String valB = b.get("medicalTime").toString();
                                return valB.compareTo(valA);
                            }
                        });
                        for (JSONObject temp:jsonValues){
                            re.put(temp);
                        }
                    }
                    else{
                        throw new Exception(json.optString("MESSAGE"));
                    }
                }else{
                    throw new Exception("返回结果为空！");
                }
            }
        }
        else{
            throw new Exception("返回结果为空！");
        }

        return re;
    }

    /**
     *  查询居民健康体检详情接口
     */
    public JSONObject getEhrSickMedicalRecord(String medicalNo)  throws Exception
    {
        JSONObject re = new JSONObject();
        String url = jwUrl + "/third/archives/getEhrSickMedicalRecord";

        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("medicalNo", medicalNo));

        String response = HttpClientUtil.post(url, params, "UTF-8");
        if(!StringUtils.isEmpty(response))
        {
            JSONObject json = new JSONObject(response);
            if (!"200".equals(json.optString("status"))) {
                throw new Exception(json.optString("msg"));
            }else {
                String dataStr = json.getString("data");
                if(!StringUtils.isEmpty(dataStr)){
                    JSONObject data = new JSONObject(dataStr);
                    if("1".equals(data.optString("CODE")))
                    {
                        JSONArray jsonArray = data.getJSONArray("DATA");
                        if(jsonArray.length()==0){
                            throw new Exception("返回结果为空！");
                        }
                        JSONObject jsonObject = jsonArray.getJSONObject(0);
                        //报告信息
                        re.put("medicalTime",jsonObject.get("MEDICAL_TIME").toString());//体检时间
                        re.put("doctorName",jsonObject.get("MEDICAL_OPERATOR").toString());//体检医生
                        re.put("orgName",jsonObject.get("ORG_NAME").toString());//机构名称
                        // 健康评价
                        String isExaminationExcep = jsonObject.get("IS_EXAMINATION_EXCEP").toString();//是否异常2为异常，空或非2为正常
                        JSONArray jsonArrayEx = new JSONArray();
                        if("2".equals(isExaminationExcep)){
                            re.put("isExaminationExcep","1");//(0.无异常;1.异常)
                            String name = "EXAMINATION_EXCEP";
                            Boolean flag = true;
                            int i = 0;
                            while (flag){
                                i++;
                                if(jsonObject.isNull(name+i)){
                                    flag = false;
                                }else {
                                    Object ex = jsonObject.get(name+i);
                                    String examinationExcep = ex.toString();
                                    if(StringUtils.isEmpty(examinationExcep)){
                                        flag = false;
                                    }else {
                                        jsonArrayEx.put(examinationExcep);
                                    }
                                }
                            }
                            re.put("examinationList",jsonArrayEx);//异常
                        }else{
                            re.put("isExaminationExcep","0");
                            re.put("examinationList",jsonArrayEx);//异常
                        }
                        // 健康指导-定期随访
                        String healthRegularFollowUp = jsonObject.get("HEALTH_REGULAR_FOLLOW_UP").toString();//是否有定期随访
                        String healthGuidanceSlowDisease = jsonObject.get("HEALTH_GUIDANCE_SLOW_DISEASE").toString();//纳入慢性病患者健康管理
                        String healthGuidanceInhospital = jsonObject.get("HEALTH_GUIDANCE_INHOSPITAL").toString();//建议复查
                        String healthGuidanceReview = jsonObject.get("HEALTH_GUIDANCE_REVIEW").toString();//建议转诊
                        String healthGuidanceOther = jsonObject.get("HEALTH_GUIDANCE_OTHER").toString();//其他0.无 1.有
                        String healthGuidanceOtherStr = jsonObject.get("HEALTH_GUIDANCE_OTHER_STR").toString();//其它内容
                        re.put("healthRegularFollowUp",healthRegularFollowUp);
                        re.put("healthGuidanceSlowDisease",healthGuidanceSlowDisease);
                        re.put("healthGuidanceInhospital",healthGuidanceInhospital);
                        re.put("healthGuidanceReview",healthGuidanceReview);
                        re.put("healthGuidanceOther",healthGuidanceOther);
                        re.put("healthGuidanceOtherStr",healthGuidanceOtherStr);

                        //危险因素控制
                        String hazardQuitSmocking = jsonObject.get("HAZARD_QUIT_SMOCKING").toString();//戒烟
                        String hazardHealthDrink = jsonObject.get("HAZARD_HEALTH_DRINK").toString();//健康饮酒
                        String hazardFood = jsonObject.get("HAZARD_FOOD").toString();//饮食
                        String hazardHardening = jsonObject.get("HAZARD_HARDENING").toString();//锻炼
                        String hazardLoseWeight = jsonObject.get("HAZARD_LOSE_WEIGHT").toString();//减体重
                        String hazardLoseWeightTarget = jsonObject.get("HAZARD_LOSE_WEIGHT_TARGET").toString();//减体重其它内容
                        String hazardVaccination = jsonObject.get("HAZARD_VACCINATION").toString();//建议接种疫苗
                        String hazardVaccinationStr = jsonObject.get("HAZARD_VACCINATION_STR").toString();//建议接种疫苗其它内容
                        String hazardOthers = jsonObject.get("HAZARD_OTHERS").toString();//其它
                        String hazardOthersStr = jsonObject.get("HAZARD_OTHERS_STR").toString();//其它内容
                        re.put("hazardQuitSmocking",hazardQuitSmocking);
                        re.put("hazardHealthDrink",hazardHealthDrink);
                        re.put("hazardFood",hazardFood);
                        re.put("hazardHardening",hazardHardening);
                        re.put("hazardLoseWeight",hazardLoseWeight);
                        re.put("hazardLoseWeightTarget",hazardLoseWeightTarget);
                        re.put("hazardVaccination",hazardVaccination);
                        re.put("hazardVaccinationStr",hazardVaccinationStr);
                        re.put("hazardOthers",hazardOthers);
                        re.put("hazardOthersStr",hazardOthersStr);

                        // 症状
                        String asymptomatic = jsonObject.get("ASYMPTOMATIC").toString();//0.无 1.有
                        String symptomHeadache = jsonObject.get("SYMPTOM_HEADACHE").toString();//头痛
                        String symptomDizziness = jsonObject.get("SYMPTOM_DIZZINESS").toString();//头晕
                        String symptomPalpitation = jsonObject.get("SYMPTOM_PALPITATION").toString();//心悸
                        String symptomChestStuffiness = jsonObject.get("SYMPTOM_CHEST_STUFFINESS").toString();//胸闷
                        String symptomChestPain = jsonObject.get("SYMPTOM_CHEST_PAIN").toString();//胸痛
                        String symptomChronicCough = jsonObject.get("SYMPTOM_CHRONIC_COUGH").toString();//慢性咳嗽
                        String symptomExpectoration = jsonObject.get("SYMPTOM_EXPECTORATION").toString();//咳痰
                        String symptomDyspnea = jsonObject.get("SYMPTOM_DYSPNEA").toString();//呼吸困难
                        String symptomPolydipsia = jsonObject.get("SYMPTOM_POLYDIPSIA").toString();//多饮
                        String symptomPolyuria = jsonObject.get("SYMPTOM_POLYURIA").toString();//多尿
                        String symptomWeightLoss = jsonObject.get("SYMPTOM_WEIGHT_LOSS").toString();//体重下降
                        String symptomLackOfPower = jsonObject.get("SYMPTOM_LACK_OF_POWER").toString();//乏力
                        String symptomJointGall = jsonObject.get("SYMPTOM_JOINT_GALL").toString();//关节肿痛
                        String symptomBlurredVision = jsonObject.get("SYMPTOM_BLURRED_VISION").toString();//视力模糊
                        String symptomHandFootNumbness = jsonObject.get("SYMPTOM_HAND_FOOT_NUMBNESS").toString();//手脚麻木
                        String symptomUrinaryUrgency = jsonObject.get("SYMPTOM_URINARY_URGENCY").toString();//尿急
                        String symptomDysuria = jsonObject.get("SYMPTOM_DYSURIA").toString();//尿痛
                        String symptomConstipation = jsonObject.get("SYMPTOM_CONSTIPATION").toString();//便秘
                        String symptomDiarrhea = jsonObject.get("SYMPTOM_DIARRHEA").toString();//腹泻
                        String symptomNauseaVomiting = jsonObject.get("SYMPTOM_NAUSEA_VOMITING").toString();//恶心呕吐
                        String symptomDazzle = jsonObject.get("SYMPTOM_DAZZLE").toString();//眼花
                        String symptomTinnitus = jsonObject.get("SYMPTOM_TINNITUS").toString();//耳鸣
                        String symptomBreastBursting = jsonObject.get("SYMPTOM_BREAST_BURSTING").toString();//乳房胀痛
                        String symptomOther = jsonObject.get("SYMPTOM_OTHER").toString();//症状其它
                        String symptomOtherStr = jsonObject.get("SYMPTOM_OTHER_STR").toString();//症状其它内容
                        re.put("asymptomatic",asymptomatic);
                        re.put("symptomHeadache",symptomHeadache);
                        re.put("symptomDizziness",symptomDizziness);
                        re.put("symptomPalpitation",symptomPalpitation);
                        re.put("symptomChestStuffiness",symptomChestStuffiness);
                        re.put("symptomChestPain",symptomChestPain);
                        re.put("symptomChronicCough",symptomChronicCough);
                        re.put("symptomExpectoration",symptomExpectoration);
                        re.put("symptomDyspnea",symptomDyspnea);
                        re.put("symptomPolydipsia",symptomPolydipsia);
                        re.put("symptomPolyuria",symptomPolyuria);
                        re.put("symptomWeightLoss",symptomWeightLoss);
                        re.put("symptomLackOfPower",symptomLackOfPower);
                        re.put("symptomJointGall",symptomJointGall);
                        re.put("symptomBlurredVision",symptomBlurredVision);
                        re.put("symptomHandFootNumbness",symptomHandFootNumbness);
                        re.put("symptomUrinaryUrgency",symptomUrinaryUrgency);
                        re.put("symptomDysuria",symptomDysuria);
                        re.put("symptomConstipation",symptomConstipation);
                        re.put("symptomDiarrhea",symptomDiarrhea);
                        re.put("symptomNauseaVomiting",symptomNauseaVomiting);
                        re.put("symptomDazzle",symptomDazzle);
                        re.put("symptomTinnitus",symptomTinnitus);
                        re.put("symptomBreastBursting",symptomBreastBursting);
                        re.put("symptomOther",symptomOther);
                        re.put("symptomOtherStr",symptomOtherStr);

                        // 一般情况
                        re.put("bodyTemperature",jsonObject.get("BODY_TEMPERATURE").toString());// 体温
                        re.put("pulseFrequency",jsonObject.get("PULSE_FREQUENCY").toString());//   脉率
                        re.put("respiratoryRate",jsonObject.get("RESPIRATORY_RATE").toString());// 呼吸频率
                        re.put("bloodPressureLeftD",jsonObject.get("BLOOD_PRESSURE_LEFT_D").toString());// 血压(左)
                        re.put("bloodPressureLeftU",jsonObject.get("BLOOD_PRESSURE_LEFT_U").toString());// 血压(左)
                        re.put("bloodPressureRigthD",jsonObject.get("BLOOD_PRESSURE_RIGTH_D").toString());// 血压(右)
                        re.put("bloodPressureRigthU",jsonObject.get("BLOOD_PRESSURE_RIGTH_U").toString());// 血压(右)
                        re.put("height",jsonObject.get("HEIGHT").toString());// 身高
                        re.put("weight",jsonObject.get("WEIGHT").toString());// 体重
                        re.put("waist",jsonObject.get("WAIST").toString());// 腰围
                        re.put("bmi",jsonObject.get("BMI").toString());// 体质指数(BMI)

                        String elderlyHealthStatus = jsonObject.get("ELDERLY_HEALTH_STATUS").toString();
                        String elderlySelfCare = jsonObject.get("ELDERLY_SELF_CARE").toString();
                        if(!StringUtils.isEmpty(elderlyHealthStatus)){
                            elderlyHealthStatus = systemDictService.getDictValue("ELDERLY_HEALTH_STATUS",elderlyHealthStatus);
                        }
                        if(!StringUtils.isEmpty(elderlySelfCare)){
                            elderlySelfCare = systemDictService.getDictValue("ELDERLY_SELF_CARE",elderlySelfCare);
                        }
                        re.put("elderlyHealthStatus",elderlyHealthStatus);// 老年人健康状态自我评估
                        re.put("elderlySelfCare",elderlySelfCare);// 老年人生活自理能力评估
                        re.put("elderlyCognitiveFun",jsonObject.get("ELDERLY_COGNITIVE_FUN").toString());// 老年人认知功能
                        re.put("miniMentalStateExamination",jsonObject.get("MINI_MENTAL_STATE_EXAMINATION").toString());//  --简易智力状态检查
                        re.put("elderlyAffectiveState",jsonObject.get("ELDERLY_AFFECTIVE_STATE").toString());//                            老年人情感状态
                        re.put("elderlyDepressionCheck",jsonObject.get("ELDERLY_DEPRESSION_CHECK").toString());//  --老年人抑郁评分

                        // 生活方式
                        // 体育锻炼
                        re.put("hardeningMode",jsonObject.get("HARDENING_MODE").toString());// 锻炼方式
                        String hardeningFrequency = jsonObject.get("HARDENING_FREQUENCY").toString();
                        if(!StringUtils.isEmpty(hardeningFrequency)){
                            hardeningFrequency = systemDictService.getDictValue("HARDENING_FREQUENCY",hardeningFrequency);
                        }
                        re.put("hardeningFrequency",hardeningFrequency);// 锻炼频率
                        re.put("everyHardeningTime",jsonObject.get("EVERY_HARDENING_TIME").toString());// 每次锻炼时间
                        re.put("insistHardeningTime",jsonObject.get("INSIST_HARDENING_TIME").toString());// 坚持锻炼时间
                        //         饮食习惯
                        String eatClitocybineEqualization = jsonObject.get("EAT_CLITOCYBINE_EQUALIZATION").toString();//荤素均衡
                        String eatMeatdietFlash = jsonObject.get("EAT_MEATDIET_FLASH").toString();//荤食为主
                        String eatVegetarianFlash = jsonObject.get("EAT_VEGETARIAN_FLASH").toString();//素食为主
                        String eatHobbySalt = jsonObject.get("EAT_HOBBY_SALT").toString();//嗜盐
                        String eatHobbyOil = jsonObject.get("EAT_HOBBY_OIL").toString();//嗜油
                        String eatHobbySugar = jsonObject.get("EAT_HOBBY_SUGAR").toString();//嗜糖
                        re.put("eatClitocybineEqualization",eatClitocybineEqualization);
                        re.put("eatMeatdietFlash",eatMeatdietFlash);
                        re.put("eatVegetarianFlash",eatVegetarianFlash);
                        re.put("eatHobbySalt",eatHobbySalt);
                        re.put("eatHobbyOil",eatHobbyOil);
                        re.put("eatHobbySugar",eatHobbySugar);

                        //         吸烟情况
                        re.put("smokingCircumstance",jsonObject.get("SMOKING_CIRCUMSTANCE").toString());// 吸烟状况
                        re.put("dailySmokingQuantity",jsonObject.get("DAILY_SMOKING_QUANTITY").toString());// 日吸烟量
                        re.put("beginSmokingAge",jsonObject.get("BEGIN_SMOKING_AGE").toString());// 开始吸烟年龄
                        re.put("quitSmokingAge",jsonObject.get("QUIT_SMOKING_AGE").toString());// 戒烟年龄
                        //         饮酒情况
                        String drinkFrequency = jsonObject.get("DRINK_FREQUENCY").toString();
                        if(!StringUtils.isEmpty(drinkFrequency)){
                            drinkFrequency = systemDictService.getDictValue("DRINK_FREQUENCY",drinkFrequency);
                        }
                        re.put("drinkFrequency",drinkFrequency);// 饮酒频率
                        re.put("everyAlcohol_tolerance",jsonObject.get("EVERY_ALCOHOL_TOLERANCE").toString());// 日饮酒量
                        re.put("isDryOut",jsonObject.get("IS_DRY_OUT").toString());// 是否戒酒
                        re.put("dryOutAge",jsonObject.get("DRY_OUT_AGE").toString());//  --戒酒年龄
                        re.put("beginDrinkAge",jsonObject.get("BEGIN_DRINK_AGE").toString());// 开始饮酒年龄
                        re.put("oneYearIsTemulentia",jsonObject.get("ONE_YEAR_IS_TEMULENTIA").toString());// 近一年内是否曾醉酒
                        // 饮酒种类：drinks
                        String drinkWhiteSpirits  = jsonObject.get("DRINK_WHITE_SPIRITS").toString();//白酒
                        String drinkBeer = jsonObject.get("DRINK_BEER").toString();//啤酒
                        String drinkRedWine = jsonObject.get("DRINK_RED_WINE").toString();//红酒
                        String drinkYellowWine = jsonObject.get("DRINK_YELLOW_WINE").toString();//黄酒
                        String drinkOthers = jsonObject.get("DRINK_OTHERS").toString();//饮酒种类其它
                        String drinkOthersStr = jsonObject.get("DRINK_OTHERS_STR").toString();//饮酒种类其它内容
                        re.put("drinkWhiteSpirits",drinkWhiteSpirits);
                        re.put("drinkBeer",drinkBeer);
                        re.put("drinkRedWine",drinkRedWine);
                        re.put("drinkYellowWine",drinkYellowWine);
                        re.put("drinkOthers",drinkOthers);
                        re.put("drinkOthersStr",drinkOthersStr);

                        //         职业暴露情况
                        re.put("occupationalDisease",jsonObject.get("OCCUPATIONAL_DISEASE").toString());// 有接触史
                        re.put("occDiseaseTrades",jsonObject.get("OCC_DISEASE_TRADES").toString());//--工种
                        re.put("occupationalDiseaseWorkTime",jsonObject.get("OCCUPATIONAL_DISEASE_WORK_TIME").toString());//--从业时间
                        re.put("poisonDust",jsonObject.get("POISON_DUST").toString());//  粉尘
                        re.put("poisonDustIspre",jsonObject.get("POISON_DUST_ISPRE").toString());//-- 是否有防护措施
                        re.put("poisonDustPreStr",jsonObject.get("POISON_DUST_PRE_STR").toString());//--防护措施
                        re.put("poisonRadiogen",jsonObject.get("POISON_RADIOGEN").toString());//  放射物质
                        re.put("poisonRadiogenIspre",jsonObject.get("POISON_RADIOGEN_ISPRE").toString());//-- 是否有防护措施
                        re.put("poisonRadiogenPreStr",jsonObject.get("POISON_RADIOGEN_PRE_STR").toString());//--防护措施
                        re.put("poisonPhysicalfactor",jsonObject.get("POISON_PHYSICALFACTOR").toString());//  物理因素
                        re.put("poisonPhysicalIspre",jsonObject.get("POISON_PHYSICAL_ISPRE").toString());//-- 是否有防护措施
                        re.put("poisonPhysicalPreStr",jsonObject.get("POISON_PHYSICAL_PRE_STR").toString());//--防护措施
                        re.put("poisonChemical",jsonObject.get("POISON_CHEMICAL").toString());//  化学物质
                        re.put("poisonChemicalIspre",jsonObject.get("POISON_CHEMICAL_ISPRE").toString());//-- 是否有防护措施
                        re.put("poisonChemicalPreStr",jsonObject.get("POISON_CHEMICAL_PRE_STR").toString());//--防护措施
                        re.put("poisonOthers",jsonObject.get("POISON_OTHERS").toString());//  其他
                        re.put("poisonOthersIspre",jsonObject.get("POISON_OTHERS_ISPRE").toString());//-- 是否有防护措施
                        re.put("poisonOthersPreStr",jsonObject.get("POISON_OTHERS_PRE_STR").toString());//--防护措施

                        //  脏器功能
                        //  口腔
                        re.put("lips",jsonObject.get("LIPS").toString());//  --口唇
                        String dentitiondentureNormal = jsonObject.get("DENTITIONDENTURE_NORMAL").toString();//齿列--名称【正常】【0.无 1.有】",
                        String  dentitiondentureMissTeeth = jsonObject.get("DENTITIONDENTURE_MISS_TEETH").toString();//缺齿
                        String dentitiondentureDentalCaries = jsonObject.get("DENTITIONDENTURE_DENTAL_CARIES").toString();//龋齿
                        String dentitiondentureDenture = jsonObject.get("DENTITIONDENTURE_DENTURE").toString();//义齿(假牙)
                        re.put("dentitiondentureNormal",dentitiondentureNormal);
                        re.put("dentitiondentureMissTeeth",dentitiondentureMissTeeth);
                        re.put("dentitiondentureDentalCaries",dentitiondentureDentalCaries);
                        re.put("dentitiondentureDenture",dentitiondentureDenture);

                        String pharyngealportionNo = jsonObject.get("PHARYNGEALPORTION_NO").toString();//咽部--名称【无充血】【0.无 1.有】",
                        String pharyngealportionYes = jsonObject.get("PHARYNGEALPORTION_YES").toString();//充血
                        String pharyngealportionAdd = jsonObject.get("PHARYNGEALPORTION_ADD").toString();//淋巴滤泡增生
                        re.put("pharyngealportionNo",pharyngealportionNo);
                        re.put("pharyngealportionYes",pharyngealportionYes);
                        re.put("pharyngealportionAdd",pharyngealportionAdd);

                        //   视力
                        re.put("visionLeftEye",jsonObject.get("VISION_LEFT_EYE").toString());//  --左眼
                        re.put("visionRightEye",jsonObject.get("VISION_RIGHT_EYE").toString());//  --右眼
                        //   矫正视力
                        re.put("straightenVisionLeftEye",jsonObject.get("STRAIGHTEN_VISION_LEFT_EYE").toString());//  --左眼
                        re.put("straightenVisionRightEye",jsonObject.get("STRAIGHTEN_VISION_RIGHT_EYE").toString());//  --右眼
                        String audition = jsonObject.get("AUDITION").toString();
                        String motorFunction = jsonObject.get("MOTOR_FUNCTION").toString();
                        if(!StringUtils.isEmpty(audition)){
                            audition = systemDictService.getDictValue("AUDITION",audition);
                        }
                        if(!StringUtils.isEmpty(motorFunction)){
                            motorFunction = systemDictService.getDictValue("MOTOR_FUNCTION",motorFunction);
                        }
                        re.put("audition",audition);// 听力
                        re.put("motorFunction",motorFunction);// 运动功能

                        // 查体
                        String eyeground = jsonObject.get("EYEGROUND").toString();//眼底【1.正常;2.异常;】
                        String eyegroundException = jsonObject.get("EYEGROUND_EXCEPTION").toString();//眼底异常内容
                        String skin = jsonObject.get("SKIN").toString();//皮肤
                        String skinOthers = jsonObject.get("SKIN_OTHERS").toString();//皮肤其它内容
                        String sclera = jsonObject.get("SCLERA").toString();//巩膜
                        String scleraOthers = jsonObject.get("SCLERA_OTHERS").toString();//巩膜其它
                        if(!StringUtils.isEmpty(skin)){
                            skin = systemDictService.getDictValue("SKIN",skin);
                        }
                        if(!StringUtils.isEmpty(sclera)){
                            sclera = systemDictService.getDictValue("SCLERA",sclera);
                        }
                        re.put("eyeground",eyeground);// 眼底
                        re.put("eyegroundException",eyegroundException);// 眼底
                        re.put("skin",skin);// 皮肤
                        re.put("skinOthers",skinOthers);// 皮肤
                        re.put("sclera",sclera);// 巩膜
                        re.put("scleraOthers",scleraOthers);// 巩膜

                        String lymphNodeNotTouch = jsonObject.get("LYMPH_NODE_NOT_TOUCH").toString();//淋巴结--名称【未触及】(1未触及)
                        String lymphNodeClavicle = jsonObject.get("LYMPH_NODE_CLAVICLE").toString();//锁骨上
                        String lymphNodeRrmprt = jsonObject.get("LYMPH_NODE_RRMPRT").toString();//腋窝
                        String lymphNode = jsonObject.get("LYMPH_NODE").toString();//淋巴结--名称【其他】
                        String lymphNodeOthers = jsonObject.get("LYMPH_NODE_OTHERS").toString();//其他内容
                        re.put("lymphNodeNotTouch",lymphNodeNotTouch);
                        re.put("lymphNodeClavicle",lymphNodeClavicle);
                        re.put("lymphNodeRrmprt",lymphNodeRrmprt);
                        re.put("lymphNode",lymphNode);
                        re.put("lymphNodeOthers",lymphNodeOthers);

                        // 肺
                        String lungBarrelChest = jsonObject.get("LUNG_BARREL_CHEST").toString();//  --肺桶状胸【1否;2.是;】
                        String lungBreathSound = jsonObject.get("LUNG_BREATH_SOUND").toString();//  --肺呼吸音【1.正常;2.异常】
                        String lungBreathSoundExcep = jsonObject.get("LUNG_BREATH_SOUND_EXCEP").toString();//  --呼吸音异常内容
                        String lungRhonchus = jsonObject.get("LUNG_RHONCHUS").toString();//  --罗音
                        String lungRhonchusException = jsonObject.get("LUNG_RHONCHUS_EXCEPTION").toString();// -- 罗音异常内容
                        if(!StringUtils.isEmpty(lungRhonchus)){
                            lungRhonchus = systemDictService.getDictValue("LUNG_RHONCHUS",lungRhonchus);
                        }
                        re.put("lungBarrelChest",lungBarrelChest);
                        re.put("lungBreathSound",lungBreathSound);
                        re.put("lungBreathSoundExcep",lungBreathSoundExcep);
                        re.put("lungRhonchus",lungRhonchus);
                        re.put("lungRhonchusException",lungRhonchusException);

                        //    心脏
                        re.put("heartRate",jsonObject.get("HEART_RATE").toString());//--心率
                        String cardiacRhythm = jsonObject.get("CARDIAC_RHYTHM").toString();
                        if(!StringUtils.isEmpty(cardiacRhythm)){
                            cardiacRhythm = systemDictService.getDictValue("CARDIAC_RHYTHM",cardiacRhythm);
                        }
                        re.put("cardiacRhythm",cardiacRhythm);//--心律
                        //  --杂音
                        String cardiacSouffle = jsonObject.get("CARDIAC_SOUFFLE").toString();//--杂音
                        String cardiacSouffleOthers = jsonObject.get("CARDIAC_SOUFFLE_OTHERS").toString();//--杂音其它内容
                        re.put("cardiacSouffle",cardiacSouffle);
                        re.put("cardiacSouffleOthers",cardiacSouffleOthers);

                        //   腹部
                        String abdoPressPain = jsonObject.get("ABDO_PRESS_PAIN").toString();//压痛
                        String abdoPressPainOth = jsonObject.get("ABDO_PRESS_PAIN_OTH").toString();//压痛其它内容
                        String abdoMasses = jsonObject.get("ABDO_MASSES").toString();//包块
                        String abdoMassesOthers = jsonObject.get("ABDO_MASSES_OTHERS").toString();//包块其它内容
                        String abdoHepatomegaly = jsonObject.get("ABDO_HEPATOMEGALY").toString();//肝大
                        String abdoHepatomegalyOth = jsonObject.get("ABDO_HEPATOMEGALY_OTH").toString();//肝大其它内容
                        String abdoSplenomegaly = jsonObject.get("ABDO_SPLENOMEGALY").toString();//脾大
                        String abdoSplenomegalyOth = jsonObject.get("ABDO_SPLENOMEGALY_OTH").toString();//脾大其它内容
                        String abdoShiftingDull = jsonObject.get("ABDO_SHIFTING_DULL").toString();//移动性浊音
                        String abdoShiftingDullOth = jsonObject.get("ABDO_SHIFTING_DULL_OTH").toString();//移动性浊音其它内容
                        re.put("abdoPressPain",abdoPressPain);
                        re.put("abdoPressPainOth",abdoPressPainOth);
                        re.put("abdoMasses",abdoMasses);
                        re.put("abdoMassesOthers",abdoMassesOthers);
                        re.put("abdoHepatomegaly",abdoHepatomegaly);
                        re.put("abdoHepatomegalyOth",abdoHepatomegalyOth);
                        re.put("abdoSplenomegaly",abdoSplenomegaly);
                        re.put("abdoSplenomegalyOth",abdoSplenomegalyOth);
                        re.put("abdoShiftingDull",abdoShiftingDull);
                        re.put("abdoShiftingDullOth",abdoShiftingDullOth);

                        String immersionFoot = jsonObject.get("IMMERSION_FOOT").toString();//下肢水肿
                        String dorsumOfFootArteriopalmus = jsonObject.get("DORSUM_OF_FOOT_ARTERIOPALMUS").toString();//足背动脉博动
                        String fundamentFingerp = jsonObject.get("FUNDAMENT_FINGERP").toString();//肛门指诊
                        String fundamentFingerpOth = jsonObject.get("FUNDAMENT_FINGERP_OTH").toString();//肛门指诊其它内容
                        if(!StringUtils.isEmpty(immersionFoot)){
                            immersionFoot = systemDictService.getDictValue("IMMERSION_FOOT",immersionFoot);
                        }
                        if(!StringUtils.isEmpty(dorsumOfFootArteriopalmus)){
                            dorsumOfFootArteriopalmus = systemDictService.getDictValue("DORSUM_OF_FOOT_ARTERIOPALMUS",dorsumOfFootArteriopalmus);
                        }
                        re.put("immersionFoot",immersionFoot);
                        re.put("dorsumOfFootArteriopalmus",dorsumOfFootArteriopalmus);
                        re.put("fundamentFingerp",fundamentFingerp);
                        re.put("fundamentFingerpOth",fundamentFingerpOth);

                        //   乳腺 breast
                        String breastNotTroubleFind = jsonObject.get("BREAST_NOT_TROUBLE_FIND").toString();//乳腺--名称【未见异常】
                        String breastMastectomy = jsonObject.get("BREAST_MASTECTOMY").toString();//乳房切除
                        String breastAbnormalLactation = jsonObject.get("BREAST_ABNORMAL_LACTATION").toString();//异常泌乳
                        String breastMasses = jsonObject.get("BREAST_MASSES").toString();//乳腺包块
                        String breastOthers = jsonObject.get("BREAST_OTHERS").toString();//其它
                        String breastOthersStr = jsonObject.get("BREAST_OTHERS_STR").toString();//其它内容
                        re.put("breastNotTroubleFind",breastNotTroubleFind);
                        re.put("breastMastectomy",breastMastectomy);
                        re.put("breastAbnormalLactation",breastAbnormalLactation);
                        re.put("breastMasses",breastMasses);
                        re.put("breastOthers",breastOthers);
                        re.put("breastOthersStr",breastOthersStr);

                        //   妇科
                        String vulva = jsonObject.get("VULVA").toString();//外阴
                        String vulvaException = jsonObject.get("VULVA_EXCEPTION").toString();//外阴异常
                        String vagina = jsonObject.get("VAGINA").toString();//阴道
                        String vaginaException = jsonObject.get("VAGINA_EXCEPTION").toString();//阴道异常
                        String cervix = jsonObject.get("CERVIX").toString();//宫颈
                        String cervixException = jsonObject.get("CERVIX_EXCEPTION").toString();//宫颈异常
                        String corpus = jsonObject.get("CORPUS").toString();//宫体
                        String corpusException = jsonObject.get("CORPUS_EXCEPTION").toString();//宫体异常
                        String attachment = jsonObject.get("ATTACHMENT").toString();//附件
                        String attachmentException = jsonObject.get("ATTACHMENT_EXCEPTION").toString();//附件异常
                        re.put("vulva",vulva);
                        re.put("vulvaException",vulvaException);
                        re.put("vagina",vagina);
                        re.put("vaginaException",vaginaException);
                        re.put("cervix",cervix);
                        re.put("cervixException",cervixException);
                        re.put("corpus",corpus);
                        re.put("corpusException",corpusException);
                        re.put("attachment",attachment);
                        re.put("attachmentException",attachmentException);

                        re.put("physicalExaminationOth",jsonObject.get("PHYSICAL_EXAMINATION_OTH").toString());// 其他

                        // 辅助检查
                        //         血常规
                        re.put("hemoglobin",jsonObject.get("HEMOGLOBIN").toString());// 血红蛋白
                        re.put("leukocyte",jsonObject.get("LEUKOCYTE").toString());// 白细胞
                        re.put("platelet",jsonObject.get("PLATELET").toString());// 血小板
                        re.put("bloodRoutineOthers",jsonObject.get("BLOOD_ROUTINE_OTHERS").toString());// 其他
                        //         尿常规
                        re.put("proteinuria",jsonObject.get("PROTEINURIA").toString());// 尿蛋白
                        re.put("urineSugar",jsonObject.get("URINE_SUGAR").toString());// 尿糖
                        re.put("ket",jsonObject.get("KET").toString());// 尿酮体：
                        re.put("urinaryOccultBlood",jsonObject.get("URINARY_OCCULT_BLOOD").toString());// 尿潜血
                        re.put("urineRoutineOthers",jsonObject.get("URINE_ROUTINE_OTHERS").toString());// 其他
                        //         空腹血糖
                        re.put("fastingPlasmaGlucoseL",jsonObject.get("FASTING_PLASMA_GLUCOSE_L").toString());//
                        re.put("fastingPlasmaGlucoseDL",jsonObject.get("FASTING_PLASMA_GLUCOSE_DL").toString());//
                        //         心电图
                        re.put("electrocardiogram",jsonObject.get("ELECTROCARDIOGRAM").toString());// 是否异常
                        re.put("electrocardiogramExcep",jsonObject.get("ELECTROCARDIOGRAM_EXCEP").toString());// 异常情况
                        re.put("microalbuminuria",jsonObject.get("MICROALBUMINURIA").toString());//尿微量白蛋白
                        re.put("upcr",jsonObject.get("UP_CR").toString());//尿白蛋白/肌酥比值
                        re.put("stoolOccultBlood",jsonObject.get("STOOL_OCCULT_BLOOD").toString());//大便潜血
                        re.put("glycolatedHemoglobin",jsonObject.get("GLYCOLATED_HEMOGLOBIN").toString());//糖化血红蛋白
                        re.put("hbsag",jsonObject.get("HBSAG").toString());//乙型肝炎表面抗原
                        //         肾功能
                        re.put("liverFunctionSalt",jsonObject.get("LIVER_FUNCTION_SALT").toString());// 血清谷丙转氨酶
                        re.put("liverFunctionSgot",jsonObject.get("LIVER_FUNCTION_SGOT").toString());// 血清谷草转氨酶
                        re.put("liverFunctionAlbumin",jsonObject.get("LIVER_FUNCTION_ALBUMIN").toString());// 白蛋白
                        re.put("liverFunctionTotalBilirubin",jsonObject.get("LIVER_FUNCTION_TOTAL_BILIRUBIN").toString());// 总胆红素
                        re.put("liverFunctionCb",jsonObject.get("LIVER_FUNCTION_CB").toString());// 结合胆红素
                        //         肝功能
                        re.put("renalFunctionCreatinine",jsonObject.get("RENAL_FUNCTION_CREATININE").toString());// 血清肌酥：
                        re.put("renalFunctionBun",jsonObject.get("RENAL_FUNCTION_BUN").toString());// 血尿素氮：
                        re.put("renalFunctionBloodPotassium",jsonObject.get("RENAL_FUNCTION_BLOOD_POTASSIUM").toString());// 血钾浓度：
                        re.put("renalFunctionNatremia",jsonObject.get("RENAL_FUNCTION_NATREMIA").toString());// 血钠浓度：
                        re.put("uricAcid",jsonObject.get("URIC_ACID").toString());// 尿酸
                        //         血脂
                        re.put("bloodFatTc",jsonObject.get("BLOOD_FAT_TC").toString());// 总胆固醇
                        re.put("bloodFatTriglyceride",jsonObject.get("BLOOD_FAT_TRIGLYCERIDE").toString());// 甘油三酯
                        re.put("bloodFatLdlc",jsonObject.get("BLOOD_FAT_LDLC").toString());// 血清低密度脂蛋白胆固醇
                        re.put("bloodFatHdlc",jsonObject.get("BLOOD_FAT_HDLC").toString());// 血清告密的脂蛋白胆固醇
                        //         胸部X线片
                        re.put("cxr",jsonObject.get("CXR").toString());// 是否异常
                        re.put("cxrException",jsonObject.get("CXR_EXCEPTION").toString());// 异常情况
                        //         B超
                        re.put("typeBUltrasonic",jsonObject.get("TYPE_B_ULTRASONIC").toString());// 是否异常
                        re.put("typeBUltrasonicExcep",jsonObject.get("TYPE_B_ULTRASONIC_EXCEP").toString());// 异常情况
                        //         宫颈涂片
                        re.put("cervicalPapSmears",jsonObject.get("CERVICAL_PAP_SMEARS").toString());// 是否异常
                        re.put("cervicalPapSmearsExcep",jsonObject.get("CERVICAL_PAP_SMEARS_EXCEP").toString());// 异常情况
                        //         其他
                        re.put("assistantInvesOth",jsonObject.get("ASSISTANT_INVES_OTH").toString());//
                        //         中医体质辨识
                        re.put("corporeityGentle",jsonObject.get("CORPOREITY_GENTLE").toString());// 平和质
                        re.put("corporeityQiAsthenia",jsonObject.get("CORPOREITY_QI_ASTHENIA").toString());// 气虚质
                        re.put("corporeityYangDeficiency",jsonObject.get("CORPOREITY_YANG_DEFICIENCY").toString());// 阳虚质
                        re.put("corporeityYinDeficiency",jsonObject.get("CORPOREITY_YIN_DEFICIENCY").toString());// 阴虚质
                        re.put("corporeityPhlegmDamp",jsonObject.get("CORPOREITY_PHLEGM_DAMP").toString());// 痰湿质
                        re.put("corporeityDampHeat",jsonObject.get("CORPOREITY_DAMP_HEAT").toString());// 湿热质
                        re.put("corporeityHaemostasis",jsonObject.get("CORPOREITY_HAEMOSTASIS").toString());// 血瘀质
                        re.put("corporeityQiDepression",jsonObject.get("CORPOREITY_QI_DEPRESSION").toString());// 气郁质
                        re.put("corporeityTeBing",jsonObject.get("CORPOREITY_TE_BING").toString());// 特秉质
                        // 现存主要健康问题
                        //         脑血管疾病
                        re.put("cvdUndiscovered",jsonObject.get("CVD_UNDISCOVERED").toString());//名称【未发现】【0.无 1.有】
                        re.put("cvdIschemicStroke",jsonObject.get("CVD_ISCHEMIC_STROKE").toString());//缺血性卒中
                        re.put("cvdCerebralHemorrhage",jsonObject.get("CVD_CEREBRAL_HEMORRHAGE").toString());//脑出血
                        re.put("cvdSah",jsonObject.get("CVD_SAH").toString());//蛛网膜下腔出血
                        re.put("cvdTia",jsonObject.get("CVD_TIA").toString());//短暂性脑缺血发作
                        re.put("cvdOthers",jsonObject.get("CVD_OTHERS").toString());//其他
                        re.put("cvdOthersStr",jsonObject.get("CVD_OTHERS_STR").toString());//其他内容
                        //         肾脏疾病
                        re.put("renalUndiscovered",jsonObject.get("RENAL_UNDISCOVERED").toString());//名称【未发现】【0.无 1.有】
                        re.put("renalDn",jsonObject.get("RENAL_DN").toString());//糖尿病肾病
                        re.put("renalFailure",jsonObject.get("RENAL_FAILURE").toString());//肾功能衰竭
                        re.put("renalAgn",jsonObject.get("RENAL_AGN").toString());//急性肾炎
                        re.put("renalCgn",jsonObject.get("RENAL_CGN").toString());//慢性肾炎
                        re.put("renalOthers",jsonObject.get("RENAL_OTHERS").toString());//其他
                        re.put("renalOthersStr",jsonObject.get("RENAL_OTHERS_STR").toString());//其他内容
                        //         心脏疾病
                        re.put("heartUndiscovered",jsonObject.get("HEART_UNDISCOVERED").toString());//名称【未发现】【0.无 1.有】
                        re.put("heartMyocardialInfarction",jsonObject.get("HEART_MYOCARDIAL_INFARCTION").toString());//心肌梗死
                        re.put("heartAnginaPectoris",jsonObject.get("HEART_ANGINA_PECTORIS").toString());//心绞痛
                        re.put("heartCoronaryArtery",jsonObject.get("HEART_CORONARY_ARTERY").toString());//冠状动脉血运重建
                        re.put("heartChf",jsonObject.get("HEART_CHF").toString());//充血性心力衰竭
                        re.put("heartPrecordialpain",jsonObject.get("HEART_PRECORDIALPAIN").toString());//心前区疼痛
                        re.put("heartOthers",jsonObject.get("HEART_OTHERS").toString());//其他
                        re.put("heartOthersStr",jsonObject.get("HEART_OTHERS_STR").toString());//其他内容
                        //         血管疾病
                        re.put("angiosisUndiscovered",jsonObject.get("ANGIOSIS_UNDISCOVERED").toString());//名称【未发现】【0.无 1.有】
                        re.put("angiosisDa",jsonObject.get("ANGIOSIS_DA").toString());//夹层动脉瘤
                        re.put("angiosisOcclusionArteries",jsonObject.get("ANGIOSIS_OCCLUSION_ARTERIES").toString());//动脉闭塞性疾病
                        re.put("angiosisOthers",jsonObject.get("ANGIOSIS_OTHERS").toString());//其他
                        re.put("angiosisOthersStr",jsonObject.get("ANGIOSIS_OTHERS_STR").toString());//其他内容
                        //         眼部疾病
                        re.put("eyeDiseaseUndiscovered",jsonObject.get("EYE_DISEASE_UNDISCOVERED").toString());//名称【未发现】【0.无 1.有】
                        re.put("retinalHemorrhage",jsonObject.get("RETINAL_HEMORRHAGE").toString());//视网膜出血
                        re.put("papilledema",jsonObject.get("PAPILLEDEMA").toString());//视乳头水肿
                        re.put("eyeDiseaseCataract",jsonObject.get("EYE_DISEASE_CATARACT").toString());//名称【白内障】【0.无 1.有】
                        re.put("eyeDiseaseOthers",jsonObject.get("EYE_DISEASE_OTHERS").toString());//其他
                        re.put("eyeDiseaseOthersStr",jsonObject.get("EYE_DISEASE_OTHERS_STR").toString());//其他内容
                        //         神经系统疾病
                        re.put("nervousSystemDisease",jsonObject.get("NERVOUS_SYSTEM_DISEASE").toString());//
                        re.put("nervousSystemDiseaseStr",jsonObject.get("NERVOUS_SYSTEM_DISEASE_STR").toString());// 神经系统疾病有内容
                        //         其他系统疾病
                        re.put("othersSystemDisease",jsonObject.get("OTHERS_SYSTEM_DISEASE").toString());//
                        re.put("othersSystemDiseaseStr",jsonObject.get("OTHERS_SYSTEM_DISEASE_STR").toString());//其他系统疾病有内容
                        //         住院治疗情况
                        // 住院史 inhospitalList
                        JSONArray jsonArrayinhospital = new JSONArray();
                        String inhospitalAdmissiondate = "INHOSPITAL_ADMISSIONDATE";// 入院时间
                        String inhospitalLeavedate = "INHOSPITAL_LEAVEDATE";// 出院时间
                        String inhospitalCause = "INHOSPITAL_CAUSE";// 原因
                        String inhospitalPatientId = "INHOSPITAL_PATIENT_ID";// 病案号
                        String inhospitalOrgName = "INHOSPITAL_ORG_NAME";// inhospitalOrgNameN
                        Boolean inhospitalFlag = true;
                        int inhospitali = 0;
                        while (inhospitalFlag){
                            inhospitali++;
                            if(jsonObject.isNull(inhospitalPatientId+inhospitali)){
                                inhospitalFlag = false;
                            }else {
                                Object ex = jsonObject.get(inhospitalPatientId+inhospitali);
                                String examinationExcep = ex.toString();
                                if(StringUtils.isEmpty(examinationExcep)){
                                    inhospitalFlag = false;
                                }else {
                                    JSONObject inhospital = new JSONObject();
                                    inhospital.put("inhospitalAdmissiondate",jsonObject.get(inhospitalAdmissiondate+inhospitali));
                                    inhospital.put("inhospitalLeavedate",jsonObject.get(inhospitalLeavedate+inhospitali));
                                    inhospital.put("inhospitalCause",jsonObject.get(inhospitalCause+inhospitali));
                                    inhospital.put("inhospitalPatientId",jsonObject.get(inhospitalPatientId+inhospitali));
                                    inhospital.put("inhospitalOrgName",jsonObject.get(inhospitalOrgName+inhospitali+"_N"));
                                    jsonArrayinhospital.put(inhospital);
                                }
                            }
                        }
                        re.put("inhospitalList",jsonArrayinhospital);//异常

                        // 家庭病床史 fpList
                        JSONArray jsonArrayFp = new JSONArray();
                        String fpEstablishDate = "FP_ESTABLISH_DATE";// 建床时间
                        String fpCancelDate = "FP_CANCEL_DATE";// 撤床时间
                        String fpCause = "FP_CAUSE";// 原因
                        String fpPatientId = "FP_PATIENT_ID";// 病案号
                        String fpOrgName = "FP_ORG_NAME";// 名称
                        Boolean fpFlag = true;
                        int fpi = 0;
                        while (fpFlag){
                            fpi++;
                            if(jsonObject.isNull(fpPatientId+fpi)){
                                fpFlag = false;
                            }else {
                                Object ex = jsonObject.get(fpPatientId+fpi);
                                String examinationExcep = ex.toString();
                                if(StringUtils.isEmpty(examinationExcep)){
                                    fpFlag = false;
                                }else {
                                    JSONObject fp = new JSONObject();
                                    fp.put("fpEstablishDate",jsonObject.get(fpEstablishDate+fpi));
                                    fp.put("fpCancelDate",jsonObject.get(fpCancelDate+fpi));
                                    fp.put("fpCause",jsonObject.get(fpCause+fpi));
                                    fp.put("fpPatientId",jsonObject.get(fpPatientId+fpi));
                                    fp.put("fpOrgName",jsonObject.get(fpOrgName+fpi+"_N"));
                                    jsonArrayFp.put(fp);
                                }
                            }
                        }
                        re.put("fpList",jsonArrayFp);

                        // 主要用药情况 drugList
                        JSONArray jsonArrayDrug = new JSONArray();
                        String drugName = "DRUG_NAME";// 药品名称
                        String drugUsage = "DRUG_USAGE";// 用法文字
                        String drugDosage = "DRUG_DOSAGE";// 用量内容
                        String drugDate = "DRUG_DATE";//用药时间
                        String drugCompliance = "DRUG_COMPLIANCE";// 服药依从性
                        Boolean drugFlag = true;
                        int drugi = 0;
                        while (drugFlag){
                            drugi++;
                            if(jsonObject.isNull(drugName+drugi)){
                                drugFlag = false;
                            }else {
                                Object ex = jsonObject.get(drugName+drugi);
                                String examinationExcep = ex.toString();
                                if(StringUtils.isEmpty(examinationExcep)){
                                    drugFlag = false;
                                }else {
                                    JSONObject drug = new JSONObject();
                                    drug.put("drugName",jsonObject.get(drugName+drugi));
                                    drug.put("drugUsage",jsonObject.get(drugUsage+drugi));
                                    drug.put("drugDosage",jsonObject.get(drugDosage+drugi));
                                    drug.put("drugDate",jsonObject.get(drugDate+drugi));
                                    drug.put("drugCompliance",jsonObject.get(drugCompliance+drugi));
                                    jsonArrayDrug.put(drug);
                                }
                            }
                        }
                        re.put("drugList",jsonArrayDrug);

                        // 非免疫规划预防接种史 niVaccinationList
                        JSONArray jsonArrayNiVaccination = new JSONArray();
                        String niVaccinationName = "NI_VACCINATION_NAME";// 接种名称
                        String niVaccinationDate = "NI_VACCINATION_DATE";// 接种日期
                        String niVaccinationOrg = "NI_VACCINATION_ORG";// 接种机构
                        Boolean niVaccinationFlag = true;
                        int niVaccinationi = 0;
                        while (niVaccinationFlag){
                            niVaccinationi++;
                            if(jsonObject.isNull(niVaccinationName+niVaccinationi)){
                                niVaccinationFlag = false;
                            }else {
                                Object ex = jsonObject.get(niVaccinationName+niVaccinationi);
                                String examinationExcep = ex.toString();
                                if(StringUtils.isEmpty(examinationExcep)){
                                    niVaccinationFlag = false;
                                }else {
                                    JSONObject niVaccination = new JSONObject();
                                    niVaccination.put("niVaccinationName",jsonObject.get(niVaccinationName+niVaccinationi));
                                    niVaccination.put("niVaccinationDate",jsonObject.get(niVaccinationDate+niVaccinationi));
                                    niVaccination.put("niVaccinationOrg",jsonObject.get(niVaccinationOrg+niVaccinationi+"_N"));
                                    jsonArrayNiVaccination.put(niVaccination);
                                }
                            }
                        }
                        re.put("niVaccinationList",jsonArrayNiVaccination);
                    }
                    else{
                        throw new Exception(json.optString("MESSAGE"));
                    }
                }else{
                    throw new Exception("返回结果为空！");
                }
            }
        }
        else{
            throw new Exception("返回结果为空！");
        }

        return re;
    }

    /**
     *  上传体征指标接口
     */
    public void uploadHealthIndex(String id)  throws Exception
    {
        String url = jwUrl + "/third/archives/uploadHealthIndex";

        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("id", id));

        String response = HttpClientUtil.post(url, params, "UTF-8");

        if(!StringUtils.isEmpty(response))
        {
            JSONObject json = new JSONObject(response);
            if (!"200".equals(json.optString("status"))) {
                throw new Exception(json.optString("msg"));
            }
        }
        else{
            throw new Exception("返回结果为空！");
        }
    }

    /**
     * 上传随访记录接口
     */
    public void uploadFollowup(String id) throws Exception
    {
        String url = jwUrl + "/third/archives/uploadFollowup";

        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("id", id));

        String response = HttpClientUtil.post(url, params, "UTF-8");

        if(!StringUtils.isEmpty(response))
        {
            JSONObject json = new JSONObject(response);
            if (!"200".equals(json.optString("status"))) {
                throw new Exception(json.optString("msg"));
            }
        }
        else{
            throw new Exception("返回结果为空！");
        }
    }
}
