package com.ruoyi.web.work.controller;

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

import com.ruoyi.common.annotation.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.Patient;
import com.ruoyi.web.work.service.IPatientService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 患者
 * @author lsw
 * @date 2024-07-19
 */
@Api(tags = "患者信息管理")
@Anonymous
@RestController
@RequestMapping("/work/patient")
public class PatientController extends BaseController {

    @Autowired
    private IPatientService patientService;

    @ApiOperation(value = "获取患者信息列表")
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('work:patient:list')")
    @GetMapping("/list")
    public TableDataInfo list(Patient patient){
        startPage();
        List<Patient> list = patientService.selectList(patient);
        return getDataTable(list);
    }

    @ApiOperation(value = "根据id查询患者个人信息")
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('work:patient:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id){
        return AjaxResult.success(patientService.getById(id));
    }

    @ApiOperation(value = "添加患者信息")
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('work:patient:add')")
    @Log(title = "患者", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Patient patient){
        return toAjax(patientService.save(patient));
    }

    @ApiOperation(value = "修改患者信息")
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('work:patient:edit')")
    @Log(title = "患者", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Patient patient){
        return toAjax(patientService.updateById(patient));
    }

    @ApiOperation(value = "删除患者信息")
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('work:patient:remove')")
    @Log(title = "患者", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(patientService.removeByIds(Arrays.asList(ids)));
    }
}
