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

    public BRMSScale(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 += 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 <= 5){
            resultMap.put("结论", "无明显躁狂症状");
            resultJson.put("结论", "无明显躁狂症状");
        }else if (score >= 6 && score <= 10){
            resultMap.put("结论", "有肯定躁狂症状");
            resultJson.put("结论", "有肯定躁狂症状");
        }else if (score >= 11 && score <= 22) {
            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_BRMS);
        returnJson.put("resultJson",resultJson);

        return returnJson;
    }
}
