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.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
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.Report;
import com.ruoyi.web.work.service.IReportService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * report
 * @author lsw
 * @date 2024-07-24
 */
@Api(tags = "医嘱信息管理")
@RestController
@RequestMapping("/work/report")
public class ReportController extends BaseController {
    @Autowired
    private IReportService reportService;


    @ApiOperation(value = "根据患者ID获取此人的全部医嘱信息列表")
    @PreAuthorize("@ss.hasPermi('work:report:list')")
    @GetMapping("/patid/{patId}")
    public TableDataInfo getAllReportByPatId(@PathVariable("patId") Long patId){
        startPage();
        List<Request> list = reportService.getAllReportByPatId(patId);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('work:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(Report report){
        startPage();
        List<Report> list = reportService.selectList(report);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('work:report:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id){
        return AjaxResult.success(reportService.getById(id));
    }

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

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

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


    @ApiOperation(value = "根据orcId获取报告单信息")
    @PreAuthorize("@ss.hasPermi('work:report:select')")
    @GetMapping(value = "/getReportByObrId/{orcId}")
    public AjaxResult getReportByObrId(@PathVariable("orcId") String orcId){
        return AjaxResult.success(reportService.getOrcReportByObcId(orcId));
    }
}
