package com.cirle.scientific.controller.miniapp;/*
 *24901
 *2022/12/26
 *15:43
 */


import com.cirle.scientific.dto.lungreport.LungReportAddReq;
import com.cirle.scientific.pojo.BizCodeEnum;
import com.cirle.scientific.pojo.Result;
import com.cirle.scientific.service.QkjLungReportAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author 24901
 */
@Controller
@RequestMapping("/app/LungReportApp")
@Api("上传肺功能报告接口")
public class QkjLungReportAppController {

    private QkjLungReportAppService qkjLungReportAppService;


    @Autowired
    public void setQkjLungReportAppService(QkjLungReportAppService qkjLungReportAppService) {
        this.qkjLungReportAppService = qkjLungReportAppService;
    }

    @ApiOperation(value = "新增肺功能报告")
    @PostMapping("/addLungReport")
    @ResponseBody
    public Result addLungReport(@ApiParam(name = "memCard", value = "用户唯一标识") @RequestAttribute(name = "memCard", required = false)  String memCard, @RequestBody LungReportAddReq req){
        if (StringUtils.isBlank(memCard)) {
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        req.setMemCard(memCard);
        return Result.success(qkjLungReportAppService.addLungReport(req));
    }


    @ApiOperation(value = "查询肺功能报告")
    @GetMapping("/findLungReport")
    @ResponseBody
    public Result findLungReport(@ApiParam(name = "id", value = "肺功能报告id") @RequestParam(name = "id") Long id){
        return Result.success(qkjLungReportAppService.findLungReport(id));
    }

    @ApiOperation(value = "删除肺功能报告")
    @DeleteMapping("/delLungReport")
    @ResponseBody
    public Result delLungReport(@ApiParam(name = "id", value = "问卷") Long id){
        return Result.success(qkjLungReportAppService.delLungReport(id));
    }

    @ApiOperation(value = "更具当前医生查询肺功报告是否完成")
    @GetMapping("/findLungQuantity")
    @ResponseBody
    public Result findLungQuantity(@ApiParam(name = "memCard", value = "用户唯一标识")   @RequestAttribute(name = "memCard", required = false)  String memCard){
        if (StringUtils.isBlank(memCard)) {
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return Result.success(qkjLungReportAppService.findLungQuantity(memCard));
    }

    @ApiOperation(value = "更具当前医生查询肺功报告的数量和问卷的数量")
    @GetMapping("/findLungCount")
    @ResponseBody
    public Result findLungCount(@ApiParam(name = "memCard", value = "用户唯一标识")   @RequestAttribute(name = "memCard", required = false)  String memCard){
        if (StringUtils.isBlank(memCard)) {
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return Result.success(qkjLungReportAppService.findLungCount(memCard));
    }

    @ApiOperation(value = "更具当前医生以及查询患者名字查询出患者的问卷以及报告")
    @GetMapping("/findQuestionAndLung")
    @ResponseBody
    public Result findQuestionAndLung(@ApiParam(name = "memCard", value = "用户唯一标识")   @RequestAttribute(name = "memCard", required = false)  String memCard,
                                      @RequestParam(name = "patientName") String patientName){
        if (StringUtils.isBlank(memCard)) {
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return Result.success(qkjLungReportAppService.findQuestionAndLung(memCard, patientName));
    }

}
