package com.xinelu.web.controller.familydoctor;

import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.R;
import com.xinelu.familydoctor.entity.*;
import com.xinelu.familydoctor.service.PhysicalSignService;
import com.xinelu.familydoctor.vo.PhysicalLastRecordVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author gaoyu
 * @description 体征检测控制器
 * @date 2023-9-26 11:21
 */
@Api(tags = {"体征检测控制器"})
@RestController
@RequestMapping("/fd/ps")
public class PhysicalSignController extends BaseController {
    @Resource
    private PhysicalSignService physicalSignService;

    @ApiOperation("上传血糖")
    @PostMapping("bg/save")
    public R<?> saveBg(@RequestBody DeviceBgRecord record) {
        physicalSignService.saveBg(record);
        return R.ok();
    }

    @ApiOperation("上传血压")
    @PostMapping("bp/save")
    public R<?> saveBp(@RequestBody DeviceBpRecord record) {
        physicalSignService.saveBp(record);
        return R.ok();
    }

    @ApiOperation("上传血脂")
    @PostMapping("bf/save")
    public R<?> saveBf(@RequestBody DeviceBfRecord record) {
        physicalSignService.saveBf(record);
        return R.ok();
    }

    @ApiOperation("上传BMI")
    @PostMapping("bmi/save")
    public R<?> saveBmi(@RequestBody DeviceBmiRecord record) {
        physicalSignService.saveBmi(record);
        return R.ok();
    }

    @ApiOperation("上传血氧")
    @PostMapping("bo/save")
    public R<?> saveBo(@RequestBody DeviceBoRecord record) {
        physicalSignService.saveBo(record);
        return R.ok();
    }

    @ApiOperation("上传心率")
    @PostMapping("hr/save")
    public R<?> saveHr(@RequestBody DeviceHrRecord record) {
        physicalSignService.saveHr(record);
        return R.ok();
    }

    @ApiOperation("上传体温")
    @PostMapping("temp/save")
    public R<?> saveTemp(@RequestBody DeviceTempRecord record) {
        physicalSignService.saveTemp(record);
        return R.ok();
    }

    @ApiOperation("获取体征记录")
    @GetMapping("record")
    @ApiImplicitParams({@ApiImplicitParam(name = "identity", value = "身份证号", required = true),
    @ApiImplicitParam(name = "type", value = "时间类型0：全部1：周2：月3：年", required = true),
    @ApiImplicitParam(name = "label", value = "查询标识1：血糖2：血压3：血脂4：bmi5：血氧6：心率7：体温", required = true)})
    public R<?> record(String identity, String type, String label) {
        Map<String, Object> map = physicalSignService.record(identity, type, label);
        return R.ok(map);
    }

    @ApiOperation("获取最后一次体征记录")
    @GetMapping("record/last/{identity}")
    @ApiImplicitParam(name = "identity", value = "身份证号", required = true)
    public R<List<PhysicalLastRecordVO>> lastRecord(@PathVariable String identity) {
        return R.ok(physicalSignService.getLastRecord(identity));
    }
}
