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

import com.yihu.wlyy.service.app.record.DrugService;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
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.ResponseBody;

/**
 * Created by zhenglingfeng on 2016/10/17.
 */
@Controller
@RequestMapping(value = "/wlyy_service/record", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "医生端-健康档案用药记录")
public class DrugController extends BaseController {

    @Autowired
    private DrugService drugService;
    /**
     * 获取用药记录
     *
     * @return
     */

    @RequestMapping(value = "/drug", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("获取用药记录")
    public String getDrugsList(@ApiParam(name="strSSID",value="健康卡号",defaultValue = "A20140513123")
                               @RequestParam(value="strSSID",required = true) String strSSID,
                               @RequestParam(value="startNum",required = true) String startNum,
                               @ApiParam(name="endNum",value="需要获取的结束的行数",defaultValue = "10")
                               @RequestParam(value="endNum",required = true) String endNum) {
        try {
            String result = drugService.getDrugsList(strSSID, startNum, endNum);
            if (result.startsWith("error")) {
                return write(200, result, "data", new JSONArray().toString());
            }
            return write(200, "获取用药记录成功！", "data", result);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "获取用药记录失败！");
        }
    }
}
