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

    public GADScale(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 += 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 <= 4){
            resultMap.put("结论", "没有GAD");
            resultJson.put("结论", "没有GAD");
        }else if (score > 4 && score <= 9){
            resultMap.put("结论", "轻度GAD (建议咨询心理医生或心理医学工作者)");
            resultJson.put("结论", "轻度GAD (建议咨询心理医生或心理医学工作者)");
        }else if (score >9 && score <= 14){
            resultMap.put("结论", "中度GAD  (建议咨询心理医生或精神科医生) ");
            resultJson.put("结论", "中度GAD  (建议咨询心理医生或精神科医生) ");
        }else if (score >14 && score <= 21){
            resultMap.put("结论", "重度GAD (一定要看心理医生或精神科医生)");
            resultJson.put("结论", "重度GAD (一定要看心理医生或精神科医生)");
        }

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

        return returnJson;
    }
}
