ソースを参照

add
不良评价

lifang 4 週間 前
コミット
dbce5ad888

+ 222 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/utils/AdverseReactionUtil.java

@@ -0,0 +1,222 @@
+package com.nb.web.service.bus.utils;
+
+import cn.hutool.core.util.StrUtil;
+import com.nb.web.api.entity.BusEvaluationEntity;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * 不良反应工具类
+ * 用于筛选评价中的不良反应项并转换为字符串数组
+ */
+public class AdverseReactionUtil {
+
+    /**
+     * 根据评价实体筛选出不良反应项并转换为字符串数组
+     * 只返回不良反应的描述含义
+     *
+     * @param evaluation 评价实体
+     * @return 不良反应字符串数组
+     */
+    public static String getAdverseReactions(BusEvaluationEntity evaluation) {
+        List<String> reactions = new ArrayList<>();
+        if (evaluation == null) {
+            return "";
+        }
+        // 恶心呕吐
+        if (evaluation.getNauseaVomit() != null && evaluation.getNauseaVomit() > 0) {
+            reactions.add(getNauseaVomitDescription(evaluation.getNauseaVomit()));
+        }
+        
+        // 瘙痒
+        if (evaluation.getItch() != null && evaluation.getItch() > 0) {
+            reactions.add(getItchDescription(evaluation.getItch()));
+        }
+        
+        // 眩晕
+        if (evaluation.getVertigo() != null && evaluation.getVertigo() > 0) {
+            reactions.add(getVertigoDescription(evaluation.getVertigo()));
+        }
+        
+        // 咽喉疼痛
+        if (evaluation.getSoreThroat() != null && evaluation.getSoreThroat() > 0) {
+            reactions.add(getSoreThroatDescription(evaluation.getSoreThroat()));
+        }
+        
+        // 尿潴留
+        if (evaluation.getUroschesis() != null && evaluation.getUroschesis() > 0) {
+            reactions.add(getUroschesisDescription(evaluation.getUroschesis()));
+        }
+        
+        // 呼吸抑制
+        if (evaluation.getBreathDepression() != null && evaluation.getBreathDepression() > 0) {
+            reactions.add(getBreathDepressionDescription(evaluation.getBreathDepression()));
+        }
+        
+        // 声音嘶哑
+        if (evaluation.getHoarseness() != null && evaluation.getHoarseness() > 0) {
+            reactions.add(getHoarsenessDescription(evaluation.getHoarseness()));
+        }
+        
+        // 认知障碍
+        if (evaluation.getCognitionObstacle() != null && evaluation.getCognitionObstacle() > 0) {
+            reactions.add(getCognitionObstacleDescription(evaluation.getCognitionObstacle()));
+        }
+
+        // 满意度
+        if (evaluation.getSatisfaction() != null) {
+            switch (evaluation.getSatisfaction()) {
+                case 0:
+                    reactions.add("满意");
+                    break;
+                case 1:
+                    reactions.add("较满意");
+                    break;
+                case 2:
+                    reactions.add("不满意");
+                    break;
+            }
+        }
+
+        // 备注
+        if (StrUtil.isNotBlank(evaluation.getRemark())) {
+            reactions.add(evaluation.getRemark());
+        }
+        
+        return reactions.stream()
+                .filter(StrUtil::isNotBlank)
+                .collect(Collectors.joining(","));
+    }
+
+    /**
+     * 获取恶心呕吐评分描述
+     * @param score 评分
+     * @return 描述
+     */
+    private static String getNauseaVomitDescription(Integer score) {
+        if (score == null || score <= 0) {
+            return "";
+        } else if (score == 1) {
+            return "仅恶心";
+        } else if (score == 2) {
+            return "恶心+呕吐";
+        }
+        return "";
+    }
+    
+    /**
+     * 获取瘙痒评分描述
+     * @param score 评分
+     * @return 描述
+     */
+    private static String getItchDescription(Integer score) {
+        if (score == null || score <= 0) {
+            return "";
+        } else if (score == 1) {
+            return "轻度瘙痒";
+        } else if (score == 2) {
+            return "中度瘙痒";
+        } else if (score >= 3) {
+            return "重度瘙痒";
+        }
+        return "";
+    }
+    
+    /**
+     * 获取眩晕评分描述
+     * @param score 评分
+     * @return 描述
+     */
+    private static String getVertigoDescription(Integer score) {
+        if (score == null || score <= 0) {
+            return "";
+        } else if (score == 1) {
+            return "轻度眩晕";
+        } else if (score == 2) {
+            return "中度眩晕";
+        } else if (score >= 3) {
+            return "重度眩晕";
+        }
+        return "";
+    }
+    
+    /**
+     * 获取咽喉疼痛评分描述
+     * @param score 评分
+     * @return 描述
+     */
+    private static String getSoreThroatDescription(Integer score) {
+        if (score == null || score <= 0) {
+            return "";
+        } else if (score == 1) {
+            return "轻微疼痛";
+        } else if (score == 2) {
+            return "吞咽困难";
+        } else if (score >= 3) {
+            return "无法进食";
+        }
+        return "";
+    }
+    
+    /**
+     * 获取尿潴留评分描述
+     * @param score 评分
+     * @return 描述
+     */
+    private static String getUroschesisDescription(Integer score) {
+        if (score == null || score <= 0) {
+            return "";
+        } else if (score == 1) {
+            return "排尿时间延长";
+        } else if (score == 2) {
+            return "排尿困难";
+        } else if (score >= 3) {
+            return "需导尿";
+        }
+        return "";
+    }
+    
+    /**
+     * 获取呼吸抑制评分描述
+     * @param score 评分
+     * @return 描述
+     */
+    private static String getBreathDepressionDescription(Integer score) {
+        if (score == null || score <= 0) {
+            return "";
+        } else if (score == 1) {
+            return "呼吸抑制";
+        }
+        return "";
+    }
+    
+    /**
+     * 获取声音嘶哑评分描述
+     * @param score 评分
+     * @return 描述
+     */
+    private static String getHoarsenessDescription(Integer score) {
+        if (score == null || score <= 0) {
+            return "";
+        } else if (score == 1) {
+            return "声音嘶哑";
+        }
+        return "";
+    }
+    
+    /**
+     * 获取认知障碍评分描述
+     * @param score 评分
+     * @return 描述
+     */
+    private static String getCognitionObstacleDescription(Integer score) {
+        if (score == null || score <= 0) {
+            return "";
+        } else if (score == 1) {
+            return "认知障碍";
+        }
+        return "";
+    }
+}

+ 82 - 0
nb-service/web-service/src/test/java/com/nb/web/service/bus/AdverseReactionUtilTest.java

@@ -0,0 +1,82 @@
+package com.nb.web.service.bus;
+
+import com.nb.web.api.entity.BusEvaluationEntity;
+import com.nb.web.service.bus.utils.AdverseReactionUtil;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+
+/**
+ * 不良反应工具类测试
+ */
+public class AdverseReactionUtilTest {
+
+    @Test
+    public void testGetAdverseReactionsWithNullInput() {
+        List<String> reactions = AdverseReactionUtil.getAdverseReactions(null);
+        assertNotNull(reactions);
+        assertEquals(0, reactions.size());
+    }
+
+    @Test
+    public void testGetAdverseReactionsWithEmptyEvaluation() {
+        BusEvaluationEntity evaluation = new BusEvaluationEntity();
+        List<String> reactions = AdverseReactionUtil.getAdverseReactions(evaluation);
+        assertNotNull(reactions);
+        assertEquals(0, reactions.size());
+    }
+
+    @Test
+    public void testGetAdverseReactionsWithSomePositiveValues() {
+        BusEvaluationEntity evaluation = new BusEvaluationEntity();
+        evaluation.setNauseaVomit(1);       // 恶心
+        evaluation.setItch(2);              // 全身瘙痒
+        evaluation.setCalm(0);              // 镇静评分为0,不应包含在结果中
+        
+        List<String> reactions = AdverseReactionUtil.getAdverseReactions(evaluation);
+        assertNotNull(reactions);
+        assertEquals(2, reactions.size());
+        assertTrue(reactions.contains("恶心"));
+        assertTrue(reactions.contains("全身瘙痒"));
+        assertFalse(reactions.contains("镇静评分: 0"));
+    }
+
+    @Test
+    public void testGetAdverseReactionsWithAllPositiveValues() {
+        BusEvaluationEntity evaluation = new BusEvaluationEntity();
+        evaluation.setNauseaVomit(1);       // 恶心
+        evaluation.setItch(2);              // 全身瘙痒
+        evaluation.setVertigo(3);           // 无法行走
+        evaluation.setSoreThroat(1);        // 轻微疼痛
+        evaluation.setUroschesis(2);        // 尿潴留
+        evaluation.setBreathDepression(3);  // 需辅助呼吸
+        evaluation.setHoarseness(1);        // 声音轻微嘶哑
+        evaluation.setCognitionObstacle(2); // 意识模糊
+        
+        List<String> reactions = AdverseReactionUtil.getAdverseReactions(evaluation);
+        assertNotNull(reactions);
+        assertEquals(8, reactions.size());
+        assertTrue(reactions.contains("恶心"));
+        assertTrue(reactions.contains("全身瘙痒"));
+        assertTrue(reactions.contains("无法行走"));
+        assertTrue(reactions.contains("轻微疼痛"));
+        assertTrue(reactions.contains("尿潴留"));
+        assertTrue(reactions.contains("需辅助呼吸"));
+        assertTrue(reactions.contains("声音轻微嘶哑"));
+        assertTrue(reactions.contains("意识模糊"));
+    }
+    
+    @Test
+    public void testGetAdverseReactionsWithZeroValues() {
+        BusEvaluationEntity evaluation = new BusEvaluationEntity();
+        evaluation.setNauseaVomit(0);       // 0分,不应包含在结果中
+        evaluation.setItch(0);              // 0分,不应包含在结果中
+        
+        List<String> reactions = AdverseReactionUtil.getAdverseReactions(evaluation);
+        assertNotNull(reactions);
+        assertEquals(0, reactions.size());
+    }
+}