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

import com.yihu.wlyy.entity.dict.DmDrugsGroupItem;
import com.yihu.wlyy.entity.followup.Followup;
import com.yihu.wlyy.entity.followup.FollowupDrugs;
import com.yihu.wlyy.service.app.followup.FollowUpService;
import com.yihu.wlyy.service.app.followup.FollowupDrugsService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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;

import java.util.List;
import java.util.Map;

/**
 * 医生端：随访接口
 * 
 * @author hzp add 2016-12-07
 *
 */
@Controller
@RequestMapping(value = "/doctor/followup/drugs", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "医生端-随访用药接口")
public class DoctorFollowupDrugsController extends BaseController {

	@Autowired
	private FollowupDrugsService followupDrugsService;


	@ApiOperation("获取面访用药数据")
	@RequestMapping(value = "/getFollowupDrugs", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
	@ResponseBody
	public String getFollowupDrugs(@ApiParam(name="id",value="随访记录ID",defaultValue = "")
									@RequestParam(value="id",required = true) String id)
	{
		try {
			Map<String,Object> response = followupDrugsService.getFollowupDrugs(id);

			return write(200, "获取面访用药数据成功！","data",response);
		} catch (Exception e) {
			return invalidUserException(e, -1, "获取面访用药数据失败！"+e.getMessage());
		}
	}



	@ApiOperation("保存面访用药数据")
	@RequestMapping(value = "/saveFollowupDrugs", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public String saveFollowupDrugs(@ApiParam(name="id",value="随访记录ID",defaultValue = "")
										  @RequestParam(value="id",required = true) String id,
									      @ApiParam(name="drugsData",value="面访用药数据",defaultValue = "[]")
										  @RequestParam(value="drugsData",required = true) String drugsData)
	{
		try {
			followupDrugsService.saveFollowupDrugs(id,drugsData);

			return write(200, "保存面访用药数据成功！");
		} catch (Exception e) {
			return invalidUserException(e, -1, "保存面访用药数据失败！"+e.getMessage());
		}
	}

	@ApiOperation("获取随访类别用药列表")
	@RequestMapping(value = "/getFollowupClassDrugs", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
	@ResponseBody
	public String getFollowupClassDrugs(@ApiParam(name="followupClass",value="随访类别：1.高血压 2.糖尿病",defaultValue = "")
									@RequestParam(value="followupClass",required = true) String followupClass)
	{
		try {
			List<DmDrugsGroupItem> list = followupDrugsService.getFollowupClassDrugs(followupClass);

			return write(200, "获取随访类别用药列表成功！","data",list);
		} catch (Exception e) {
			return invalidUserException(e, -1, "获取随访类别用药列表失败！"+e.getMessage());
		}
	}

}
