package com.yihu.wlyy.web.doctor.observer;

import com.yihu.wlyy.service.app.observer.DoctorObserverService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/1/4.
 */
@RestController
@RequestMapping(value = "/doctor/observer", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "医生端-观察者")
public class DoctorObserverController extends BaseController {

    @Autowired
    private DoctorObserverService doctorObserverService;


    @ApiOperation(value = "获取医生观察者列表")
    @RequestMapping(value = "/getAllObserver", method = RequestMethod.GET)
    public String getAllObserver(
            @ApiParam(name = "doctorCode", value = "医生code", required = false) @RequestParam(value = "doctorCode", required = false) String doctorCode) {
        try {
            if (StringUtils.isEmpty(doctorCode)) {
                //如果医生code为空从头信息获取
                doctorCode = getUID();
            }
            if (StringUtils.isEmpty(doctorCode)) {
                throw new Exception("参数错误");
            }
            //返回被观察者的医生的code
            JSONArray doctors = doctorObserverService.getDoctorObservers(doctorCode);
            return write(200, "获取成功！", "data", doctors);
        } catch (Exception e) {
            error(e);
            return error(-1, "获取失败！");
        }
    }
}
