package com.yihu.wlyy.web.third;

import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.health.entity.DevicePatientHealthIndex;
import com.yihu.wlyy.health.repository.DevicePatientHealthIndexDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.third.jw.JwSignService;
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.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;

/**
 * 档案相关接口
 * @author hzp at 2016-12-19
 */
@Controller
@RequestMapping(value = "/third/archive")
@Api(description = "档案相关接口（设备、随访）")
public class OpenApiArchiveController extends BaseController {

	@Autowired
	DevicePatientHealthIndexDao healthIndexDao;

	@RequestMapping(value = "/healthIndex", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation("获取指标数据")
	public String getHealthIndex(@ApiParam(name="idcard",value="身份证号",defaultValue = "52222419850508381X")
								 @RequestParam(value="idcard",required = true) String idcard,
								 @ApiParam(name="type",value="数据类型(1:血糖，2:血压，3腰围 4体重)",defaultValue = "1")
								 @RequestParam(value="type",required = true) Integer type)
	{
		try {
			List<DevicePatientHealthIndex> result = healthIndexDao.findByIdcardAndType(idcard,type);
			return write(200, "获取指标数据成功！","data",result);
		} catch (Exception e) {
			return invalidUserException(e, -1, "获取指标数据失败！");
		}
	}

	@ApiOperation("设备数据上传接口")
	@RequestMapping(value = "/healthIndex/upload",method = RequestMethod.POST)
	@ResponseBody
	public String uploadHealthIndex(
			@ApiParam(name="appkey",value="应用key",defaultValue = "")
			@RequestParam(value="appkey",required = true) String appkey,
			@ApiParam(name="sign",value="签名校验",defaultValue = "")
			@RequestParam(value="sign",required = true) String sign,
			@ApiParam(name="timestamp",value="时间戳",defaultValue = "")
			@RequestParam(value="timestamp",required = true) String timestamp,
			@ApiParam(name="data",value="设备数据",defaultValue = "")
			@RequestParam(value="data",required = true) String data,
			@ApiParam(name="type",value="指标类型1血糖2血压3体重4腰围",defaultValue = "")
			@RequestParam(value="type",required = true) String type,
			@ApiParam(name="sn",value="设备sn码",defaultValue = "")
			@RequestParam(value="sn",required = true) String sn) {
		return write(-1, "设备数据上传失败！");
	}

	@ApiOperation("随访数据上传接口")
	@RequestMapping(value = "/followup/upload",method = RequestMethod.POST)
	@ResponseBody
	public String uploadFollowup(
			@ApiParam(name="appkey",value="应用key",defaultValue = "")
			@RequestParam(value="appkey",required = true) String appkey,
			@ApiParam(name="sign",value="签名校验",defaultValue = "")
			@RequestParam(value="sign",required = true) String sign,
			@ApiParam(name="timestamp",value="时间戳",defaultValue = "")
			@RequestParam(value="timestamp",required = true) String timestamp,
			@ApiParam(name="data",value="随访数据",defaultValue = "")
			@RequestParam(value="data",required = true) String data) {
		return write(-1, "随访数据上传失败！");
	}


}
