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 SASScale extends BaseScale{

    public SASScale(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;
                }

            }
        }
        //标准分
        score = (int) (score * 1.25);
        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("总分", String.valueOf(score));
        resultJson.put("总分", String.valueOf(score));
        //根据得分判断症状
        if (score >= 69){
            resultMap.put("结论", "重度焦虑");
            resultJson.put("结论", "重度焦虑");
        }else if (score >= 60 && score < 69){
            resultMap.put("结论", "中度焦虑");
            resultJson.put("结论", "中度焦虑");
        }else if (score >= 50 && score < 60){
            resultMap.put("结论", "轻度焦虑");
            resultJson.put("结论", "轻度焦虑");
        }else if (score < 50){
            resultMap.put("结论", "不焦虑");
            resultJson.put("结论", "不焦虑");
        }

        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_SAS);
        returnJson.put("resultJson",resultJson);

        return returnJson;
    }
}
