package com.rf.psychological.scale.resultBusiness.scaleResult;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rf.psychological.utils.Constant;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zsy
 * @description:汉密顿焦虑量表
 * @date 2021/7/20 15:55
 */
public class HAMAScale extends BaseScale{

    public HAMAScale(JSONArray jsonArray, JSONObject resultJson) {
        super(jsonArray, resultJson);
    }

    public  JSONObject scaleCalculate() throws Exception {
        //得分
        int score = 0;
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (jsonObject1.getString("scoreDirection").equals("1")) {
                if (jsonObject1.getString("checkItems").equals("轻")) {
                    score += 1;
                } else if (jsonObject1.getString("checkItems").equals("中等")) {
                    score += 2;
                } else if (jsonObject1.getString("checkItems").equals("重")) {
                    score += 3;
                } else if (jsonObject1.getString("checkItems").equals("极重")) {
                    score += 4;
                }
            } else if (jsonObject1.getString("scoreDirection").equals("0")){
                if (jsonObject1.getString("checkItems").equals("轻")) {
                    score += 4;
                } else if (jsonObject1.getString("checkItems").equals("中等")) {
                    score += 3;
                } else if (jsonObject1.getString("checkItems").equals("重")) {
                    score += 2;
                } else if (jsonObject1.getString("checkItems").equals("极重")) {
                    score += 1;
                }

            }
        }
        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("总分", String.valueOf(score));
        resultJson.put("总分", String.valueOf(score));
        //根据得分判断症状
        if (score >= 29){
            resultMap.put("结论", "严重焦虑");
            resultJson.put("结论", "严重焦虑");
        }else if (score >= 21 && score < 29){
            resultMap.put("结论", "明显焦虑");
            resultJson.put("结论", "明显焦虑");
        }else if (score >= 14 && score < 21){
            resultMap.put("结论", "肯定有焦虑");
            resultJson.put("结论", "肯定有焦虑");
        }else if (score >= 7 && score < 14){
            resultMap.put("结论", "可能有焦虑");
            resultJson.put("结论", "可能有焦虑");
        }else if (score <= 6){
            resultMap.put("结论", "没有焦虑");
            resultJson.put("结论", "没有焦虑");
        }
        System.out.println("得分：" + score);
        List<Map<String,String>> resultMapList = new ArrayList<>();
        resultMapList.add(resultMap);

        JSONObject returnJson = new JSONObject(true);
        returnJson.put("resultMapList",resultMapList);
        returnJson.put("scaleName",Constant.SHEET_NAME_HAMA);
        returnJson.put("resultJson",resultJson);

        return returnJson;
    }
}
