Commit 904c74189a479821bc015130fad62a9551bad567

Authored by Administrator
1 parent 13851c5e3c

人体成分分析功能开发

Showing 1 changed file with 300 additions and 16 deletions

platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/VolumeComponentAnalysisFacade.java View file @ 904c741
... ... @@ -7,7 +7,10 @@
7 7 import com.lyms.platform.common.result.PageResult;
8 8 import com.lyms.platform.common.result.RespBuilder;
9 9 import com.lyms.platform.common.utils.DateUtil;
  10 +import com.lyms.platform.operate.web.service.PatientWeightService;
10 11 import com.lyms.platform.operate.web.service.impl.BaseServiceImpl;
  12 +import com.lyms.platform.operate.web.service.impl.ComputeKulServiceManager;
  13 +import com.lyms.platform.pojo.BodyMassAnalysisModel;
11 14 import com.lyms.platform.pojo.Patients;
12 15 import com.lyms.platform.pojo.TemporaryUserModel;
13 16 import com.lyms.platform.pojo.VolumeComponentAnalysisModel;
... ... @@ -18,7 +21,6 @@
18 21 import org.springframework.data.mongodb.core.query.Query;
19 22 import org.springframework.stereotype.Component;
20 23  
21   -import javax.servlet.http.HttpServletRequest;
22 24 import java.util.*;
23 25  
24 26 @Component
... ... @@ -32,6 +34,12 @@
32 34 @Autowired
33 35 private AutoMatchFacade autoMatchFacade;
34 36  
  37 + @Autowired
  38 + private ComputeKulServiceManager computeKulServiceManager;
  39 +
  40 + @Autowired
  41 + private PatientWeightService patientWeightService;
  42 +
35 43 public BaseObjectResponse addComponentAnalysis(VolumeComponentAnalysisModel volume) {
36 44 mongoTemplate.insert(volume);
37 45 BaseObjectResponse objectResponse = new BaseObjectResponse();
38 46  
39 47  
40 48  
41 49  
... ... @@ -96,24 +104,300 @@
96 104 if (volumeComponentAnalysisModel != null) {
97 105 Patients patients = mongoTemplate.findOne(Query.query(Criteria.where("_id").is(volumeComponentAnalysisModel.getParentId()).and("yn").is(YnEnums.YES.getId()).and("hospitalId").is(hospitalId)), Patients.class);
98 106 if (patients != null) {
99   - Map<String, Object> userMap = new HashMap<>();
100   - userMap.put("username", patients.getUsername());
101   - userMap.put("age", patients.getAge());
102   - userMap.put("height", volumeComponentAnalysisModel.getHeight());
103   - userMap.put("week", DateUtil.getWeekDesc(patients.getLastMenses(), new Date()));
104   - userMap.put("kacl", "能量值");
105   - userMap.put("bmi", "bmi值");
106   - userMap.put("yqWeight", "孕前体重");
107   - userMap.put("weight", volumeComponentAnalysisModel.getWeight());
108   - data.add(userMap);
  107 + data = setData(patients, volumeComponentAnalysisModel);
109 108 }
110   - Map<String, Object> basicsInfo = new HashMap<>();
111   - basicsInfo.put("basicsInfo", volumeComponentAnalysisModel);
112 109 }
113   -
114   - return null;
  110 + BaseObjectResponse objectResponse = new BaseObjectResponse();
  111 + objectResponse.setErrorcode(ErrorCodeConstants.SUCCESS);
  112 + objectResponse.setErrormsg("成功");
  113 + objectResponse.setData(data);
  114 + return objectResponse;
115 115 }
116 116  
  117 + public List<Map<String, Object>> setData(Patients patients, VolumeComponentAnalysisModel volumeComponentAnalysisModel) {
  118 + List<Map<String, Object>> data = new ArrayList<>();
  119 + Map<String, Object> userMap = new HashMap<>();
  120 + //用户基本信息
  121 + userMap.put("username", patients.getUsername());
  122 + userMap.put("age", patients.getAge());
  123 + userMap.put("height", volumeComponentAnalysisModel.getHeight());
  124 + userMap.put("week", DateUtil.getWeekDesc(patients.getLastMenses(), new Date()));
  125 + userMap.put("kacl", "能量值");
  126 + userMap.put("bmi", "bmi值");
  127 + userMap.put("yqWeight", "孕前体重");
  128 + userMap.put("weight", volumeComponentAnalysisModel.getWeight());
  129 + data.add(userMap);
  130 + //人体成分分析信息
  131 + Map<String, Object> componentInfo = new HashMap<>();
117 132  
  133 + componentInfo.put("icw", volumeComponentAnalysisModel.getIcw());
  134 + componentInfo.put("ecw", volumeComponentAnalysisModel.getEcw());
  135 + componentInfo.put("protein", volumeComponentAnalysisModel.getProtein());
  136 + componentInfo.put("inorganicSalt", volumeComponentAnalysisModel.getBone());//无机盐
  137 + componentInfo.put("fat", volumeComponentAnalysisModel.getFat());
  138 + componentInfo.put("waterContent", Double.valueOf(volumeComponentAnalysisModel.getIcw() + Double.valueOf(volumeComponentAnalysisModel.getEcw())));
  139 + componentInfo.put("muscle", volumeComponentAnalysisModel.getMuscle());
  140 + componentInfo.put("weight", volumeComponentAnalysisModel.getWeight());
  141 + data.add(componentInfo);
  142 + //基本评估
  143 + Map<String, Object> basicInfo = new HashMap<>();
  144 + basicInfo.put("weight", volumeComponentAnalysisModel.getWeight());
  145 + basicInfo.put("muscle", volumeComponentAnalysisModel.getMuscle());
  146 + basicInfo.put("pbf", volumeComponentAnalysisModel.getPbf());
  147 + basicInfo.put("bone", volumeComponentAnalysisModel.getBone());
  148 + basicInfo.put("smm", volumeComponentAnalysisModel.getSmm());
  149 + data.add(basicInfo);
  150 + //内脏脂肪分析
  151 + Map<String, Object> viscusInfo = new HashMap<>();
  152 + viscusInfo.put("trFat", volumeComponentAnalysisModel.getTrFat());
  153 + viscusInfo.put("visceralLevel", volumeComponentAnalysisModel.getVfi());
  154 + data.add(viscusInfo);
  155 + //营养评估
  156 + Map<String, Object> basalMetabolismInfo = new HashMap<>();
  157 + basalMetabolismInfo.put("bmr", volumeComponentAnalysisModel.getBmr());
  158 + basalMetabolismInfo.put("protein", range(DateUtil.getWeek(patients.getLastMenses(), new Date()),
  159 + Double.valueOf(volumeComponentAnalysisModel.getWeight()), Double.valueOf(volumeComponentAnalysisModel.getProtein()), "dbz"));
  160 + basalMetabolismInfo.put("fat", range(DateUtil.getWeek(patients.getLastMenses(), new Date()), Double.valueOf(volumeComponentAnalysisModel.getWeight()),
  161 + Double.valueOf(volumeComponentAnalysisModel.getFat()), "zf"));
  162 + basalMetabolismInfo.put("wjy", range(DateUtil.getWeek(patients.getLastMenses(), new Date()), Double.valueOf(volumeComponentAnalysisModel.getWeight()),
  163 + Double.valueOf(volumeComponentAnalysisModel.getBone()), "wjy"));
  164 + data.add(basalMetabolismInfo);
  165 + //节段分析
  166 + Map<String, Object> limbsInfo = new HashMap<>();
  167 + limbsInfo.put("trWater", volumeComponentAnalysisModel.getTrWater());//躯干水分
  168 + limbsInfo.put("laWater", volumeComponentAnalysisModel.getLaWater());//左上肢水分
  169 + limbsInfo.put("raWater", volumeComponentAnalysisModel.getRaWater());//右上肢水分
  170 + limbsInfo.put("llWater", volumeComponentAnalysisModel.getLlWater());//左下肢水分
  171 + limbsInfo.put("rlWater", volumeComponentAnalysisModel.getRlWater());//右下肢水分
  172 +
  173 + limbsInfo.put("trFat", volumeComponentAnalysisModel.getTrFat());
  174 + limbsInfo.put("laFat", volumeComponentAnalysisModel.getLaFat());
  175 + limbsInfo.put("raFat", volumeComponentAnalysisModel.getRaFat());
  176 + limbsInfo.put("llFat", volumeComponentAnalysisModel.getLlFat());
  177 + limbsInfo.put("rlFat", volumeComponentAnalysisModel.getRlFat());
  178 + data.add(limbsInfo);
  179 + //报告内容
  180 + double bmi = Double.valueOf(patientWeightService.getBmi("65", "175"));
  181 + //计算热量值
  182 + Map<String, String> kmap = computeKulServiceManager.getComputeKulByRisk("").getComputeKul(56.5,
  183 + Double.parseDouble(volumeComponentAnalysisModel.getWeight()), DateUtil.getWeek(patients.getLastMenses(), new Date()),
  184 + bmi, "1", "175", "0");
  185 + //获取体质
  186 + String tz = range(DateUtil.getWeek(patients.getLastMenses(), new Date()),
  187 + Double.valueOf(volumeComponentAnalysisModel.getWeight()), Double.valueOf(volumeComponentAnalysisModel.getProtein()), "zf");
  188 + //肌肉的计算规则
  189 + String jr = range(DateUtil.getWeek(patients.getLastMenses(), new Date()),
  190 + Double.valueOf(volumeComponentAnalysisModel.getWeight()), Double.valueOf(volumeComponentAnalysisModel.getProtein()), "zf");
  191 +
  192 + //无机盐
  193 + String wjy = range(DateUtil.getWeek(patients.getLastMenses(), new Date()), Double.valueOf(volumeComponentAnalysisModel.getWeight()),
  194 + Double.valueOf(volumeComponentAnalysisModel.getBone()), "wjy");
  195 +
  196 + double kulStart = Double.valueOf(kmap.get("kulStart"));
  197 + int k1 = ((int) kulStart / 100) * 100;
  198 + double k2 = kulStart - k1;
  199 + if (k2 > 50) {
  200 + k1 += 100;
  201 + }
  202 +
  203 + if (k1 < 1000) {
  204 + k1 = 1000;
  205 + } else if (k1 > 3300) {
  206 + k1 = 3300;
  207 + }
  208 + String type = null;
  209 + String evaluationType = null;
  210 + //低体脂低肌肉
  211 + if ("不足".equals(tz) && "不足".equals(jr)) {
  212 + type = "5";
  213 + evaluationType = "3";
  214 + //超体制底肌肉
  215 + } else if ("过量".equals(tz) && "不足".equals(jr)) {
  216 + type = "3";
  217 + evaluationType = "4";
  218 + //低肌肉
  219 + } else if ("正常".equals(tz) && "不足".equals(jr)) {
  220 + type = "2";
  221 + evaluationType = "5";
  222 + //低体脂
  223 + } else if ("不足".equals(tz) && "正常".equals(jr)) {
  224 + type = "4";
  225 + evaluationType = "2";
  226 + //超体制
  227 + } else if ("过量".equals(tz) && "正常".equals(jr)) {
  228 + type = "1";
  229 + evaluationType = "1";
  230 + //正常
  231 + } else {
  232 + type = "6";
  233 + evaluationType = "8";
  234 + }
  235 + if ("过量".equals(wjy)) {
  236 + evaluationType = "7";
  237 + } else if ("不足".equals(wjy)) {
  238 + evaluationType = "6";
  239 + }
  240 +
  241 + //报告内容
  242 + BodyMassAnalysisModel bodyMassAnalysisModel = mongoTemplate.findOne(Query.query(Criteria.where("type").is(type).and("kcal").is(k1)), BodyMassAnalysisModel.class);
  243 + //食谱
  244 + if (null != bodyMassAnalysisModel) {
  245 + Map<String, Object> recipesInfo = new HashMap<>();
  246 + recipesInfo.put("breakfast", bodyMassAnalysisModel.getBreakfast());
  247 + recipesInfo.put("breakfastAdd", bodyMassAnalysisModel.getBreakfastAdd());
  248 + recipesInfo.put("lunch", bodyMassAnalysisModel.getLunch());
  249 + recipesInfo.put("lunchAdd", bodyMassAnalysisModel.getLunchAdd());
  250 + recipesInfo.put("dinner", bodyMassAnalysisModel.getDinner());
  251 + recipesInfo.put("dinnerAdd", bodyMassAnalysisModel.getDinnerAdd());
  252 + data.add(recipesInfo);
  253 + Integer week = DateUtil.getWeek(patients.getLastMenses());
  254 + //膳食结构
  255 + Map<String, Object> dietInfo = new HashMap<>();
  256 + if (week <= 12) {
  257 + dietInfo.put("diet", bodyMassAnalysisModel.getEarlySuggests());
  258 + } else if (week >= 13 && week <= 28) {
  259 + dietInfo.put("diet", bodyMassAnalysisModel.getMiddleSuggests());
  260 + } else if (week >= 28 && week <= 40) {
  261 + dietInfo.put("diet", bodyMassAnalysisModel.getLaterSuggests());
  262 + }
  263 + data.add(dietInfo);
  264 + }
  265 + BodyMassAnalysisModel nutrition = mongoTemplate.findOne(Query.query(Criteria.where("evaluationType").is(evaluationType)), BodyMassAnalysisModel.class);
  266 + if (null != nutrition) {
  267 + //人体成分营养评价
  268 + Map<String, Object> nutritionInfo = new HashMap<>();
  269 + nutritionInfo.put("nutritionalEvaluation", nutrition.getNutritionalEvaluationInfo());
  270 + data.add(nutritionInfo);
  271 + //食谱规则
  272 + Map<String, Object> recipeRulesInfo = new HashMap<>();
  273 + recipeRulesInfo.put("recipesRule", nutrition.getRecipesRule());
  274 + data.add(recipeRulesInfo);
  275 + }
  276 +
  277 + return data;
  278 + }
  279 +
  280 + private String range(Integer week, double weight, double value, String type) {
  281 + //孕早期
  282 + if (week >= 0 && week <= 12) {
  283 + //蛋白质
  284 + if ("dbz".equals(type)) {
  285 + double d = weight * 0.13;//最低
  286 + double c = weight * 0.17;//最高
  287 + if (value < d) {
  288 + return "不足";
  289 + } else {
  290 + return "正常";
  291 + }
  292 + } else if ("zf".equals(type)) {
  293 + double b = weight * 21.4;
  294 + double c = weight * 0.35;
  295 + if (value < b) {
  296 + return "不足";
  297 + } else if (value > c) {
  298 + return "过量";
  299 + } else {
  300 + return "正常";
  301 + }
  302 + } else if ("wjy".equals(type)) {
  303 + double b = weight * 0.033;
  304 + double c = weight * 0.047;
  305 + if (value < b) {
  306 + return "不足";
  307 + } else if (value > c) {
  308 + return "过量";
  309 + } else {
  310 + return "正常";
  311 + }
  312 + } else if ("jr".equals(type)) {
  313 + double b = weight * 0.65;
  314 + double c = weight * 0.8;
  315 + if (value < b) {
  316 + return "低肌肉";
  317 + } else {
  318 + return "正常";
  319 + }
  320 + }
  321 + //孕中期
  322 + } else if (week >= 13 && week <= 28) {
  323 + if ("dbz".equals(type)) {
  324 + double d = weight * 0.15;
  325 + double c = weight * 0.18;
  326 + if (value < d) {
  327 + return "不足";
  328 + } else {
  329 + return "正常";
  330 + }
  331 + } else if ("zf".equals(type)) {
  332 + double b = weight * 21.4;
  333 + double c = weight * 0.35;
  334 + if (value < b) {
  335 + return "不足";
  336 + } else if (value > c) {
  337 + return "过量";
  338 + } else {
  339 + return "正常";
  340 + }
  341 + } else if ("wjy".equals(type)) {
  342 + double b = weight * 0.034;
  343 + double c = weight * 0.048;
  344 + if (value < b) {
  345 + return "不足";
  346 + } else if (value > c) {
  347 + return "过量";
  348 + } else {
  349 + return "正常";
  350 + }
  351 + } else if ("jr".equals(type)) {
  352 + double b = weight * 0.67;
  353 + double c = weight * 0.8;
  354 + if (value < b) {
  355 + return "低肌肉";
  356 + } else {
  357 + return "正常";
  358 + }
  359 + }
  360 + //孕晚期
  361 + } else if (week >= 29 && week <= 40) {
  362 + if ("dbz".equals(type)) {
  363 + double b = weight * 15.78;
  364 + double c = weight * 19.2;
  365 + if (value < b) {
  366 + return "不足";
  367 + } else {
  368 + return "正常";
  369 + }
  370 + } else if ("zf".equals(type)) {
  371 + double b = weight * 0.25;
  372 + double c = weight * 0.35;
  373 + if (value < b) {
  374 + return "不足";
  375 + } else if (value > c) {
  376 + return "过量";
  377 + } else {
  378 + return "正常";
  379 + }
  380 + } else if ("wjy".equals(type)) {
  381 + double b = weight * 0.035;
  382 + double c = weight * 0.055;
  383 + if (value < b) {
  384 + return "不足";
  385 + } else if (value > c) {
  386 + return "过量";
  387 + } else {
  388 + return "正常";
  389 + }
  390 + } else if ("jr".equals(type)) {
  391 + double b = weight * 0.7;
  392 + double c = weight * 0.85;
  393 + if (value < b) {
  394 + return "低肌肉";
  395 + } else {
  396 + return "正常";
  397 + }
  398 + }
  399 + }
  400 + return "";
  401 + }
118 402 }