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.text.DecimalFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lhh
 * @description:哥本哈根卒中量表
 * @date 2021/11/05 15:55
 */
public class CSScale extends BaseScale {
    public CSScale(JSONArray jsonArray, JSONObject resultJson) {
        super(jsonArray, resultJson);
    }
    public JSONObject scaleCalculate() throws Exception {
        //总分
        int score = 0,j=0,k=0;//j=1代表不能唤醒2题跳过，3，4题直接4分；k代表k=1右侧偏瘫，k=2左侧偏瘫,k=0无偏瘫，k=3双侧偏瘫

        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            System.out.println("题号为："+i+"   用户选择选项："+jsonObject1.getString("checkItems"));
            if(i==0){
                if (jsonObject1.getString("checkItems").equals("唤醒困难")||jsonObject1.getString("checkItems").equals("合作差")) {
                     score+=11;
                     j=1;
                }else if(jsonObject1.getString("checkItems").equals("不能唤醒")){
                    score+=12;
                    j=1;
                }else if(jsonObject1.getString("checkItems").equals("完全清楚")){
                    score+=1;
                }else if(jsonObject1.getString("checkItems").equals("嗜睡但能被言语唤醒并充分合作")){
                    score+=2;
                }
            }else if(i==1&&j!=1){
                  if(jsonObject1.getString("checkItems").equals("无")){
                     k=0;
                  }else if(jsonObject1.getString("checkItems").equals("左侧偏瘫")){
                      k=2;
                  }else if(jsonObject1.getString("checkItems").equals("右侧偏瘫")){
                      k=1;
                  }else if(jsonObject1.getString("checkItems").equals("双侧偏瘫")){
                      k=3;
                  }
            }else if(i==2&&k==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+=4;
            }
           }else if(i==3&&k==2){
                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(i==4){
                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(i==5){
                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(i==6){
                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(i==7){
                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(i==8){
                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(i==9){
                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(i==10){
                if(jsonObject1.getString("checkItems").equals("正常")){
                    score+=1;
                }else if(jsonObject1.getString("checkItems").equals("使用装置(拐杖，助步器等)")){
                    score+=2;
                }else if(jsonObject1.getString("checkItems").equals("需要1或2人的扶持")){
                    score+=3;
                }else if(jsonObject1.getString("checkItems").equals("不能")){
                    score+=4;
                }
            }

        }
        //得分列表
        DecimalFormat df = new DecimalFormat("######0.00");
        Map<String, String> resultMap = new LinkedHashMap<>();
        System.out.println(score+">>>>>>>>>>>>>>>>>>>>>>>>");
        double score1=0.0;//最大评分百分比=[(总分)-(项目数)]/[(最大评分)-(项目数)]×100%
        if(k==0){
            score1= Double.parseDouble(df.format((score-8.0)/(32.0-8.0)));
        }else if(k==1||k==2){
            score1= Double.parseDouble(df.format((score-9.0)/(36.0-9.0)));
        }else {
            score1= Double.parseDouble(df.format((score-10.0)/(40.0-10.0)));
        }

        resultMap.put("卒中评分", String.valueOf(score));
        resultMap.put("卒中评分百分比", String.valueOf(score1));

        resultJson.put("卒中评分", String.valueOf(score));
        resultJson.put("卒中评分百分比", String.valueOf(score1));

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

        return returnJson;



    }
}
