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;

/**
 * @description 儿童自闭症评量量表
 */
public class CARSScale extends BaseScale {
    public CARSScale(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;
            } else if (jsonObject1.getString("checkItems").equals("极不正常")) {
                score += 4;
            }
        }


        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("总分", String.valueOf(score));
        resultJson.put("总分", String.valueOf(score));


        if (score <= 30) {
            resultMap.put("总分结论", "非自闭症");
            resultJson.put("总分结论", "非自闭症");
        } else if (score <= 36) {
            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_CARS);
        returnJson.put("resultJson", resultJson);

        return returnJson;
    }
}
