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

    public ESSScale(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("checkItems").equals("打瞌睡的可能性很小")) {
                score += 1;
            } else if (jsonObject1.getString("checkItems").equals("打瞌睡的可能性中等")) {
                score += 2;
            } else if (jsonObject1.getString("checkItems").equals("很可能打瞌睡")) {
                score += 3;
            }
        }
        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("总分", String.valueOf(score));
        resultJson.put("总分", String.valueOf(score));
        if (score <= 6){
            resultMap.put("结论", "正常");
            resultJson.put("结论", "正常");
        }else if (score > 6 && score <= 11){
            resultMap.put("结论", "瞌睡");
            resultJson.put("结论", "瞌睡");
        }else if (score > 11 && score <= 16){
            resultMap.put("结论", "过度瞌睡");
            resultJson.put("结论", "过度瞌睡");
        }else {
            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_ESS);
        returnJson.put("resultJson",resultJson);

        return returnJson;
    }
}
