package com.yihu.wlyy.service.app.observer;

import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.repository.doctor.DoctorObserverDao;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2017/1/3.
 */
@Service
public class DoctorObserverService {
    @Autowired
    private DoctorObserverDao doctorObserverDao;

    /**
     * 得到医生的被观察者
     *
     * @param doctorCode
     * @return
     */
    public JSONArray getDoctorObservers(String doctorCode) {
        /**  map.put("id", doctor.getId());
             map.put("uid", doctor.getCode());
             map.put("token", token.getToken());
             map.put("name", doctor.getName());
             map.put("hospital", doctor.getHospital());
             map.put("photo", doctor.getPhoto());
             // 设置医生类型：1专科医生，2全科医生，3健康管理师
             map.put("doctorType", doctor.getLevel());
             //获取医生角色和区域权限
             List<Map<String, String>> roleMap = roleService.getUserRoleAndArea(doctor.getCode());
             map.put("userRole", roleMap);
             if("10".equals(doctor.getLevel())&&roleMap.size()==0){
             errorMessage="改用户没有管理员权限";
             loginLog.setErrorMessage(errorMessage);
         */
        List<Doctor> doctors = doctorObserverDao.getDoctorObserversByDoctorCode(doctorCode);
        JSONArray jsonArray = new JSONArray();
        for (int i = 0; i < doctors.size(); i++) {
            JSONObject jo = new JSONObject();
            Doctor doctor = doctors.get(i);
            jo.put("id", doctor.getId());
            jo.put("uid", doctor.getCode());
            jo.put("name", doctor.getName());
            jo.put("hospital", doctor.getHospital());
            jo.put("HospitalName", doctor.getHospitalName());
            jo.put("photo", doctor.getPhoto());
            jo.put("doctorType", doctor.getLevel());
            jsonArray.put(jo);
        }
        return jsonArray;
    }

}
