package com.ruoyi.web.work.controller;

import java.util.Arrays;
import java.util.List;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.web.work.domain.Request;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.work.domain.Result;
import com.ruoyi.web.work.service.IResultService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * request
 * @author lsw
 * @date 2024-07-23
 */
@Api(tags = "检测项目管理")
@RestController
@RequestMapping("/work/result")
public class ResultController extends BaseController {
    @Autowired
    private IResultService resultService;


    @ApiOperation(value = "根据患者ID获取此人的全部检查结果列表")
    @PreAuthorize("@ss.hasPermi('work:result:list')")
    @GetMapping("/patid/{patId}")
    public TableDataInfo getAllResultByPatId(@PathVariable("patId") Long patId){
        startPage();
        List<Result> list = resultService.getAllResultByPatId(patId);
        return getDataTable(list);
    }

    @ApiOperation(value = "获取检测项目列表")
    @PreAuthorize("@ss.hasPermi('work:result:list')")
    @GetMapping("/list")
    public TableDataInfo list(Result result){
        startPage();
        List<Result> list = resultService.selectList(result);
        return getDataTable(list);
    }

    @ApiOperation(value = "根据Id获取检测项目列表")
    @PreAuthorize("@ss.hasPermi('work:result:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id){
        return AjaxResult.success(resultService.getById(id));
    }

    @PreAuthorize("@ss.hasPermi('work:result:add')")
    @Log(title = "request", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Result request){
        return toAjax(resultService.save(request));
    }

    @PreAuthorize("@ss.hasPermi('work:result:edit')")
    @Log(title = "request", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Result request){
        return toAjax(resultService.updateById(request));
    }

    @PreAuthorize("@ss.hasPermi('work:result:remove')")
    @Log(title = "request", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(resultService.removeByIds(Arrays.asList(ids)));
    }

    @ApiOperation(value = "根据obrId获取检测结果详情")
    @PreAuthorize("@ss.hasPermi('work:result:select')")
    @GetMapping(value = "/getResults/{obrId}")
    public AjaxResult getResults(@PathVariable("obrId") String obrId){
        return AjaxResult.success(resultService.getObxResultByObrId(obrId));
    }
}
