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

    public BPRSScale(JSONArray jsonArray, JSONObject resultJson) {
        super(jsonArray, resultJson);
    }

    public  JSONObject scaleCalculate() throws Exception {
        //得分
        int score = 0;
        //焦虑忧郁得分
        int ANDPscore = 0;
        //缺乏活力得分
        int ANEGscore = 0;
        //思维障碍得分
        int thoughtScore = 0;
        //激活性得分
        int ACTVscore = 0;
        //敌对猜疑得分
        int suspicionScore = 0;
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (jsonObject1.getString("scoreDirection").equals("1")) {
                if (i == 0 || i == 1 || i == 4 || i == 8){
                    if (jsonObject1.getString("checkItems").equals("无症状")) {
                        score += 1;
                        ANDPscore += 1;
                    } else if (jsonObject1.getString("checkItems").equals("可疑或很轻")) {
                        score += 2;
                        ANDPscore += 2;
                    } else if (jsonObject1.getString("checkItems").equals("轻度")) {
                        score += 3;
                        ANDPscore += 3;
                    } else if (jsonObject1.getString("checkItems").equals("中度")) {
                        score += 4;
                        ANDPscore += 4;
                    } else if (jsonObject1.getString("checkItems").equals("偏重")) {
                        score += 5;
                        ANDPscore += 5;
                    } else if (jsonObject1.getString("checkItems").equals("重度")) {
                        score += 6;
                        ANDPscore += 6;
                    } else if (jsonObject1.getString("checkItems").equals("极重")) {
                        score += 7;
                        ANDPscore += 7;
                    }
                }else if (i == 2 || i == 12 || i == 15 || i == 17){
                    if (jsonObject1.getString("checkItems").equals("无症状")) {
                        score += 1;
                        ANEGscore += 1;
                    } else if (jsonObject1.getString("checkItems").equals("可疑或很轻")) {
                        score += 2;
                        ANEGscore += 2;
                    } else if (jsonObject1.getString("checkItems").equals("轻度")) {
                        score += 3;
                        ANEGscore += 3;
                    } else if (jsonObject1.getString("checkItems").equals("中度")) {
                        score += 4;
                        ANEGscore += 4;
                    } else if (jsonObject1.getString("checkItems").equals("偏重")) {
                        score += 5;
                        ANEGscore += 5;
                    } else if (jsonObject1.getString("checkItems").equals("重度")) {
                        score += 6;
                        ANEGscore += 6;
                    } else if (jsonObject1.getString("checkItems").equals("极重")) {
                        score += 7;
                        ANEGscore += 7;
                    }
                }else if (i == 3 || i == 7 || i == 11 || i == 14){
                    if (jsonObject1.getString("checkItems").equals("无症状")) {
                        score += 1;
                        thoughtScore += 1;
                    } else if (jsonObject1.getString("checkItems").equals("可疑或很轻")) {
                        score += 2;
                        thoughtScore += 2;
                    } else if (jsonObject1.getString("checkItems").equals("轻度")) {
                        score += 3;
                        thoughtScore += 3;
                    } else if (jsonObject1.getString("checkItems").equals("中度")) {
                        score += 4;
                        thoughtScore += 4;
                    } else if (jsonObject1.getString("checkItems").equals("偏重")) {
                        score += 5;
                        thoughtScore += 5;
                    } else if (jsonObject1.getString("checkItems").equals("重度")) {
                        score += 6;
                        thoughtScore += 6;
                    } else if (jsonObject1.getString("checkItems").equals("极重")) {
                        score += 7;
                        thoughtScore += 7;
                    }
                }else if (i == 5 || i == 6 || i == 16){
                    if (jsonObject1.getString("checkItems").equals("无症状")) {
                        score += 1;
                        ACTVscore += 1;
                    } else if (jsonObject1.getString("checkItems").equals("可疑或很轻")) {
                        score += 2;
                        ACTVscore += 2;
                    } else if (jsonObject1.getString("checkItems").equals("轻度")) {
                        score += 3;
                        ACTVscore += 3;
                    } else if (jsonObject1.getString("checkItems").equals("中度")) {
                        score += 4;
                        ACTVscore += 4;
                    } else if (jsonObject1.getString("checkItems").equals("偏重")) {
                        score += 5;
                        ACTVscore += 5;
                    } else if (jsonObject1.getString("checkItems").equals("重度")) {
                        score += 6;
                        ACTVscore += 6;
                    } else if (jsonObject1.getString("checkItems").equals("极重")) {
                        score += 7;
                        ACTVscore += 7;
                    }
                }else if (i == 9 || i == 10 || i == 15){
                    if (jsonObject1.getString("checkItems").equals("无症状")) {
                        score += 1;
                        suspicionScore += 1;
                    } else if (jsonObject1.getString("checkItems").equals("可疑或很轻")) {
                        score += 2;
                        suspicionScore += 2;
                    } else if (jsonObject1.getString("checkItems").equals("轻度")) {
                        score += 3;
                        suspicionScore += 3;
                    } else if (jsonObject1.getString("checkItems").equals("中度")) {
                        score += 4;
                        suspicionScore += 4;
                    } else if (jsonObject1.getString("checkItems").equals("偏重")) {
                        score += 5;
                        suspicionScore += 5;
                    } else if (jsonObject1.getString("checkItems").equals("重度")) {
                        score += 6;
                        suspicionScore += 6;
                    } else if (jsonObject1.getString("checkItems").equals("极重")) {
                        score += 7;
                        suspicionScore += 7;
                    }
                }else {
                    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("checkItems").equals("偏重")) {
                        score += 5;
                    } else if (jsonObject1.getString("checkItems").equals("重度")) {
                        score += 6;
                    } else if (jsonObject1.getString("checkItems").equals("极重")) {
                        score += 7;
                    }
                }
            } else if (jsonObject1.getString("scoreDirection").equals("0")){
                if (i == 0 || i == 1 || i == 4 || i == 8){
                    if (jsonObject1.getString("checkItems").equals("无症状")) {
                        score += 7;
                        ANDPscore += 7;
                    } else if (jsonObject1.getString("checkItems").equals("可疑或很轻")) {
                        score += 6;
                        ANDPscore += 6;
                    } else if (jsonObject1.getString("checkItems").equals("轻度")) {
                        score += 5;
                        ANDPscore += 5;
                    } else if (jsonObject1.getString("checkItems").equals("中度")) {
                        score += 4;
                        ANDPscore += 4;
                    } else if (jsonObject1.getString("checkItems").equals("偏重")) {
                        score += 3;
                        ANDPscore += 3;
                    } else if (jsonObject1.getString("checkItems").equals("重度")) {
                        score += 2;
                        ANDPscore += 2;
                    } else if (jsonObject1.getString("checkItems").equals("极重")) {
                        score += 1;
                        ANDPscore += 1;
                    }
                }else if (i == 2 || i == 12 || i == 15 || i == 17){
                    if (jsonObject1.getString("checkItems").equals("无症状")) {
                        score += 7;
                        ANEGscore += 7;
                    } else if (jsonObject1.getString("checkItems").equals("可疑或很轻")) {
                        score += 6;
                        ANEGscore += 6;
                    } else if (jsonObject1.getString("checkItems").equals("轻度")) {
                        score += 5;
                        ANEGscore += 5;
                    } else if (jsonObject1.getString("checkItems").equals("中度")) {
                        score += 4;
                        ANEGscore += 4;
                    } else if (jsonObject1.getString("checkItems").equals("偏重")) {
                        score += 3;
                        ANEGscore += 3;
                    } else if (jsonObject1.getString("checkItems").equals("重度")) {
                        score += 2;
                        ANEGscore += 2;
                    } else if (jsonObject1.getString("checkItems").equals("极重")) {
                        score += 1;
                        ANEGscore += 1;
                    }
                }else if (i == 3 || i == 7 || i == 11 || i == 14){
                    if (jsonObject1.getString("checkItems").equals("无症状")) {
                        score += 7;
                        thoughtScore += 7;
                    } else if (jsonObject1.getString("checkItems").equals("可疑或很轻")) {
                        score += 6;
                        thoughtScore += 6;
                    } else if (jsonObject1.getString("checkItems").equals("轻度")) {
                        score += 5;
                        thoughtScore += 5;
                    } else if (jsonObject1.getString("checkItems").equals("中度")) {
                        score += 4;
                        thoughtScore += 4;
                    } else if (jsonObject1.getString("checkItems").equals("偏重")) {
                        score += 3;
                        thoughtScore += 3;
                    } else if (jsonObject1.getString("checkItems").equals("重度")) {
                        score += 2;
                        thoughtScore += 2;
                    } else if (jsonObject1.getString("checkItems").equals("极重")) {
                        score += 1;
                        thoughtScore += 1;
                    }
                }else if (i == 5 || i == 6 || i == 16){
                    if (jsonObject1.getString("checkItems").equals("无症状")) {
                        score += 7;
                        ACTVscore += 7;
                    } else if (jsonObject1.getString("checkItems").equals("可疑或很轻")) {
                        score += 6;
                        ACTVscore += 6;
                    } else if (jsonObject1.getString("checkItems").equals("轻度")) {
                        score += 5;
                        ACTVscore += 5;
                    } else if (jsonObject1.getString("checkItems").equals("中度")) {
                        score += 4;
                        ACTVscore += 4;
                    } else if (jsonObject1.getString("checkItems").equals("偏重")) {
                        score += 3;
                        ACTVscore += 3;
                    } else if (jsonObject1.getString("checkItems").equals("重度")) {
                        score += 2;
                        ACTVscore += 2;
                    } else if (jsonObject1.getString("checkItems").equals("极重")) {
                        score += 1;
                        ACTVscore += 1;
                    }
                }else if (i == 9 || i == 10 || i == 15){
                    if (jsonObject1.getString("checkItems").equals("无症状")) {
                        score += 7;
                        suspicionScore += 7;
                    } else if (jsonObject1.getString("checkItems").equals("可疑或很轻")) {
                        score += 6;
                        suspicionScore += 6;
                    } else if (jsonObject1.getString("checkItems").equals("轻度")) {
                        score += 5;
                        suspicionScore += 5;
                    } else if (jsonObject1.getString("checkItems").equals("中度")) {
                        score += 4;
                        suspicionScore += 4;
                    } else if (jsonObject1.getString("checkItems").equals("偏重")) {
                        score += 3;
                        suspicionScore += 3;
                    } else if (jsonObject1.getString("checkItems").equals("重度")) {
                        score += 2;
                        suspicionScore += 2;
                    } else if (jsonObject1.getString("checkItems").equals("极重")) {
                        score += 1;
                        suspicionScore += 1;
                    }
                }else {
                    if (jsonObject1.getString("checkItems").equals("无症状")) {
                        score += 7;
                    } else if (jsonObject1.getString("checkItems").equals("可疑或很轻")) {
                        score += 6;
                    } else if (jsonObject1.getString("checkItems").equals("轻度")) {
                        score += 5;
                    } else 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));
        resultMap.put("焦虑忧郁得分", String.valueOf(ANDPscore));
        resultJson.put("焦虑忧郁得分", String.valueOf(ANDPscore));
        resultMap.put("缺乏活力得分", String.valueOf(ANEGscore));
        resultJson.put("缺乏活力得分", String.valueOf(ANEGscore));
        resultMap.put("思维障碍得分", String.valueOf(thoughtScore));
        resultJson.put("思维障碍得分", String.valueOf(thoughtScore));
        resultMap.put("激活性得分", String.valueOf(ACTVscore));
        resultJson.put("激活性得分", String.valueOf(ACTVscore));
        resultMap.put("敌对猜疑得分", String.valueOf(suspicionScore));
        resultJson.put("敌对猜疑得分", String.valueOf(suspicionScore));
        System.out.println("得分：" + score);
        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_BPRS);
        returnJson.put("resultJson",resultJson);

        return returnJson;
    }
}
