用户和医生预警接口开发

发布时间 2023-04-07 09:04:09作者: 葬爱_坤疤

摘要:

  • 其中涉及到八张表(TbUser表,TbBlood表,TbBloodSugar表,TbAtheromatousPlaque表,TbUserSymptom表,TbSymptom表,TbUserComplication表,TbComplication表)

  • 这个接口的设计思路:用户的每周的填报和月季填报,当有些的数据超过属于它的范围就会出现报警,比如说在用户端,只需要将超值的警告反馈出来,而医生端中将患者的预警报告出来,需要详细点,将所有的参数也要反馈出来。

  • TbVocationController

    • /**
      * 用户预警报告
      * @return
      */
      @GetMapping("/userWarning")
      public AjaxResult selectWarningList(Long userId){
         Map<String, Object> stringObjectMap = tbVocationService.selectWarningList(userId);
         return AjaxResult.success(stringObjectMap);
      }
  • ITbVocationService

    • /**
      * 用户预警报告
      * @param userId
      * @return
      */
      public Map<String,Object> selectWarningList(Long userId);
  • TbVocationServiceImpl

    • //用户表  (正常大于等于3次)/每次运动时间(正常大于等于30分钟)
      //       体重指数(kg/m2输入计算公式为体重/身高的米数平方,正常值:18.5-24)
      //       血脂(甘油三酯(正常:0.56~1.7mmol/L)
      //       总胆固醇(正常:2.8-5.17mmol/L)
      //       高密度脂蛋白(正常:男:0.96-1.15mmol/L;女:0.90-1.55mmol/L)
      //       低密度脂蛋白(正常0-3.1mmol/L)
      @Autowired
      private ITbUserService iTbUserService;

      //血压表   (mmhg,正常值收缩压不超过140mmhg,舒张压不超过90mmhg)
      @Autowired
      private ITbBloodService iTbBloodService;

      //血糖表   血糖(空腹(正常值3.9-6.1mmol/L)/餐后2小时血糖正常值4.4-7.8mmol/L)
      @Autowired
      private ITbBloodSugarService iTbBloodSugarService;

      //劲动脉超声检查   (粥样斑块(正常无斑块,如有斑块注明大小/内膜中层厚度(正常值是小于1mm)
      @Autowired
      private ITbAtheromatousPlaqueService iTbAtheromatousPlaqueService;

      //患者症状和用户的关联表
      @Autowired
      private ITbUserSymptomService iTbUserSymptomService;

      //患者症状
      @Autowired
      private ITbSymptomService iTbSymptomService;

      //合并症和用户关联表
      @Autowired
      private ITbUserComplicationService iTbUserComplicationService;

      //合并症
      @Autowired
      private ITbComplicationService iTbComplicationService;




      /**
      * 用户预警报告
      * @param userId
      * @return
      */
      @Override
      public Map<String,Object> selectWarningList(Long userId) {
         Map<String, Object> map = new HashMap<>();
         Map<String, Object> map1 = new HashMap<>();



         //通过UserId找到这个患者的个人信息
         LambdaQueryWrapper<TbUser> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
         userLambdaQueryWrapper.eq(TbUser::getUserId,userId);
         TbUser one = iTbUserService.getOne(userLambdaQueryWrapper);
         Double height;
         Double weight;
         //有值为false
         //当这个两个身高体重都有值时
         if (one.getHeight() != null  && one.getWeight() != null){
             //身高cm
             height = one.getHeight();
             //体重kg
             weight = one.getWeight();
             //体重指数
             Double heightweight = weight/((height/100)*(height/100));
             if (heightweight<=18.5){
                 map.put("heightweight","体重指数偏瘦");
            }else if (heightweight<=24){
                 map1.put("heightweight","体重指数正常");
            }else {
                 map.put("heightweight","体重指数偏胖");
            }
        }else {
             map.put("heightweight","请填写身高体重!");
        }



         //血脂(mmol/L)
         Double bloodFat;
         //当血脂不为空
         if (one.getBloodFat()!=null){
             bloodFat = one.getBloodFat();
             if (bloodFat<=0.56){
                 map.put("bloodFat","血脂偏低");
            }else if (bloodFat<=1.7){
                 map1.put("bloodFat","血脂正常");
            }else {
                 map.put("bloodFat","血脂偏高");
            }
        }else {
             map.put("bloodFat","请填写血脂数值!");
        }



         //总胆固醇(mmol/L)
         Double totalCholesterol;
         if (one.getTotalCholesterol()!=null){
             totalCholesterol =one.getTotalCholesterol();
             if (totalCholesterol<=2.8){
                 map.put("totalCholesterol","总胆固醇偏低");
            }else if (totalCholesterol<=5.17){
                 map1.put("totalCholesterol","总胆固醇正常");
            }else {
                 map.put("totalCholesterol","总胆固醇偏高");
            }
        }else {
             map.put("totalCholesterol","请填写总胆固醇数值!");
        }


         //高密度脂蛋白(mmol/L)
         Double highDensityLipoprotein ;
         if (one.getHighDensityLipoprotein()!=null){
             highDensityLipoprotein= one.getHighDensityLipoprotein();
             //男
             if (one.getSex().equals("1")){
                 if (highDensityLipoprotein<=0.96){
                     map.put("highDensityLipoprotein","高密度脂蛋白偏低");
                }else if (highDensityLipoprotein<=1.15){
                     map1.put("highDensityLipoprotein","高密度脂蛋白正常");
                }else {
                     map.put("highDensityLipoprotein","高密度脂蛋白偏高");
                }
            }else {//女
                 if (highDensityLipoprotein<=0.90){
                     map.put("highDensityLipoprotein","高密度脂蛋白偏低");
                }else if (highDensityLipoprotein<=1.55){
                     map1.put("highDensityLipoprotein","高密度脂蛋白正常");
                }else {
                     map.put("highDensityLipoprotein","高密度脂蛋白偏高");
                }
            }

        }else {
             map.put("highDensityLipoprotein","请填写高密度脂蛋白数值!");
        }




         //低密度脂蛋白(mmol/L)
         Double lowDensityLipoprotein ;
         if (one.getLowDensityLipoprotein()!=null){
             lowDensityLipoprotein = one.getLowDensityLipoprotein();
             if (lowDensityLipoprotein<=0){
                 map.put("lowDensityLipoprotein","低密度脂蛋白偏低");
            }else if (lowDensityLipoprotein<=3.1){
                 map1.put("lowDensityLipoprotein","低密度脂蛋白正常");
            }else {
                 map.put("lowDensityLipoprotein","低密度脂蛋白偏高");
            }
        }else {
             map.put("lowDensityLipoprotein","请填写低密度脂蛋白数值!");
        }




         //每周运动次数
         Integer motionNumber;
         if (one.getMotionNumber()!=null){
             motionNumber = one.getMotionNumber();
             if (motionNumber<3){
                 map.put("motionNumber","缺少运动次数");
            }else {
                 map1.put("motionNumber","爱运动,继续保持");
            }
        }else {
             map.put("motionNumber","请填写每周运动次数数值!");
        }




         //单次运动的平均时间(分钟)
         Integer motionTime;
         if (one.getMotionTime()!=null){
             motionTime = one.getMotionTime();
             if (motionTime<30){
                 map.put("motionTime","平均的运动时间少于30分钟");
            }else {
                 map1.put("motionTime","爱运动,继续保持");
            }
        }else {
             map.put("motionTime","请填写单次运动的平均时间数值!");
        }


         //---------------------------------------------------------
         //血糖id'
         String bloodSugarId = one.getBloodSugarId();
         //血压id
         String bloodId = one.getBloodId();



         //到血压表中找到收缩压和舒张压的数值
         LambdaQueryWrapper<TbBlood> lambdaQueryWrapper = new LambdaQueryWrapper<>();
         lambdaQueryWrapper.eq(TbBlood::getBloodId,bloodId);
         TbBlood one1 = iTbBloodService.getOne(lambdaQueryWrapper);

         //收缩压
         Long systolicPressure;
         if (one1.getSystolicPressure()!=null){
             systolicPressure = one1.getSystolicPressure();
             if (systolicPressure<=140){
                 map1.put("systolicPressure","收缩压正常");
            }else {
                 map.put("systolicPressure","收缩压偏高");
            }
        }else {
             map.put("systolicPressure","请填写收缩压数值!");
        }


         //舒张压
         Long diastolicPressure;
         if (one1.getDiastolicPressure()!=null){
             diastolicPressure = one1.getDiastolicPressure();
             if (diastolicPressure<=90){
                 map1.put("diastolicPressure","舒张压正常");
            }else {
                 map.put("diastolicPressure","舒张压偏高");
            }
        }else {
             map.put("diastolicPressure","请填写舒张压数值!");
        }



         //根据血糖的id到血糖表中找到餐后血糖和空腹血糖
         LambdaQueryWrapper<TbBloodSugar> tbBloodSugarLambdaQueryWrapper = new LambdaQueryWrapper<>();
         tbBloodSugarLambdaQueryWrapper.eq(TbBloodSugar::getBloodSugarId,bloodSugarId);
         TbBloodSugar one2 = iTbBloodSugarService.getOne(tbBloodSugarLambdaQueryWrapper);
         //餐后血糖
         Long postprandialBloodSugar;
         if ( one2.getPostprandialBloodSugar()!=null){
             postprandialBloodSugar=one2.getPostprandialBloodSugar();
             if (postprandialBloodSugar<=4.4){
                 map.put("postprandialBloodSugar","餐后血糖偏低");
            }else if (postprandialBloodSugar<=7.8){
                 map1.put("postprandialBloodSugar","餐后血糖正常");
            }else {
                 map.put("postprandialBloodSugar","餐后血糖偏高");
            }
        }else {
             map.put("postprandialBloodSugar","请填写餐后血糖数值!");
        }


         //空腹血糖
         Long fastingBloodSugar;
         if ( one2.getFastingBloodSugar()!=null){
             fastingBloodSugar=one2.getFastingBloodSugar();
             if (fastingBloodSugar<=3.9){
                 map.put("fastingBloodSugar","空腹血糖偏低");
            }else if (fastingBloodSugar<=6.1){
                 map1.put("fastingBloodSugar","空腹血糖正常");
            }else {
                 map.put("fastingBloodSugar","空腹血糖偏高");
            }
        }else {
             map.put("fastingBloodSugar","请填写空腹血糖数值!");
        }



         //根据userId到颈动脉超声检查表找粥样斑快大小
         LambdaQueryWrapper<TbAtheromatousPlaque> tbAtheromatousPlaqueLambdaQueryWrapper = new LambdaQueryWrapper<>();
         tbAtheromatousPlaqueLambdaQueryWrapper.eq(TbAtheromatousPlaque::getUserId,userId);
         TbAtheromatousPlaque one3 = iTbAtheromatousPlaqueService.getOne(tbAtheromatousPlaqueLambdaQueryWrapper);
         //有无粥样斑快(1有/0无)
         String atheromatousPlaque;
         //粥样斑快大小
         Long atheromatousPlaqueSize = one3.getAtheromatousPlaqueSize();

         if (one3.getAtheromatousPlaque()!=null){
             atheromatousPlaque = one3.getAtheromatousPlaque();
             //就是有斑块
             if (atheromatousPlaque.equals("1")){
                 if (one3.getAtheromatousPlaqueSize()!=null){
                     if (atheromatousPlaqueSize<1){
                         map1.put("atheromatousPlaque","内膜中层厚度正常");
                    }else {
                         map.put("atheromatousPlaque","内膜中层厚度偏大");
                    }

                }else {
                     map.put("atheromatousPlaque","请填写斑块大小");
                }

            }else {
                 map1.put("atheromatousPlaque","无粥样斑块");
            }
        }else {
             map.put("atheromatousPlaque","请填写是否有斑块");
        }




         //根据userId到患者症状中找症状
         LambdaQueryWrapper<TbUserSymptom> tbUserSymptomLambdaQueryWrapper = new LambdaQueryWrapper<>();
         tbUserSymptomLambdaQueryWrapper.eq(TbUserSymptom::getUserId,userId);
         List<TbUserSymptom> list = iTbUserSymptomService.list(tbUserSymptomLambdaQueryWrapper);
         String symptomName=null;
         Long symptomId =null;
         for (TbUserSymptom tbUserSymptom : list) {
             symptomId = tbUserSymptom.getSymptomId();


             if (tbUserSymptom.getSymptomId()!=null){

                 LambdaQueryWrapper<TbSymptom> tbSymptomLambdaQueryWrapper = new LambdaQueryWrapper<>();
                 tbSymptomLambdaQueryWrapper.eq(TbSymptom::getSymptomId,symptomId);
                 TbSymptom one4 = iTbSymptomService.getOne(tbSymptomLambdaQueryWrapper);
                 symptomName = one4.getSymptomName();
                 if (tbUserSymptom.getSymptomId().equals("1")){
                     map1.put("symptomName","无症状");
                }else {
                     map.put("symptomName",symptomName);
                }
            }else {
                 map.put("symptomName","请填写患者状态");
            }

        }



         //根据userId到合并病表中找
         LambdaQueryWrapper<TbUserComplication> userComplicationLambdaQueryWrapper = new LambdaQueryWrapper<>();
         userComplicationLambdaQueryWrapper.eq(TbUserComplication::getUserId,userId);
         List<TbUserComplication> list1 = iTbUserComplicationService.list(userComplicationLambdaQueryWrapper);

         String complicationName=null;
         for (TbUserComplication tbUserComplication : list1) {
             Long complicationId = tbUserComplication.getComplicationId();

             if (tbUserComplication.getComplicationId()!=null){
                 LambdaQueryWrapper<TbComplication> complicationLambdaQueryWrapper = new LambdaQueryWrapper<>();
                 complicationLambdaQueryWrapper.eq(TbComplication::getComplicationId,complicationId);
                 TbComplication one4 = iTbComplicationService.getOne(complicationLambdaQueryWrapper);
                 complicationName = one4.getComplicationName();

                 if (tbUserComplication.getComplicationId().equals("1")){
                     map1.put("complicationName","无合并症");
                }else {
                     map.put("complicationName",complicationName);
                }
            }else {
                 map.put("complicationName","请填写合并症");
            }

        }


         return map;
      }

其中要将数据库中的数据都要读取出来,一个一个的判断,如果数据库中为空的话,就会报错,我们首先就应该判断他不能为空,将判断出来的结果存进map中,这只是用户端的预警,判断是一模一样的,但是反馈的数据结果有一些的改变,用户端的预警只会报出异常的数据,医生端会详细的报出所有的信息。比如说:

//血脂(mmol/L)
Double bloodFat;
//当血脂不为空
if (one.getBloodFat()!=null){
   bloodFat = one.getBloodFat();
   if (bloodFat<=0.56){
       map.put("bloodFat","血脂偏低,当前为"+bloodFat+"mmol/L");
  }else if (bloodFat<=1.7){
       map.put("bloodFat","血脂正常,当前为"+bloodFat+"mmol/L");
  }else {
       map.put("bloodFat","血脂偏高,当前为"+bloodFat+"mmol/L");
  }
}else {
   map.put("bloodFat","请填写血脂数值!");
}

输出的结果:

 

 

问题及解决

对于数据库中存的是Double类型的数据,如何判断它是否为空

开始我使用的isNAN来判断,但是还是出现,数据库为空的报错,又使用eq的来判断,还是不行,最后就直接用(!=null)实现了效果。

 

总结

今天的状态是不错的,将一个很难的接口完成了,这个接口代码量很大,但是没有太大的错误,每对一个参数判断完都,都会运行起来看一下效果。