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.dto.PatientCardDto;
import com.ruoyi.web.work.domain.Pv1;
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.service.IPv1Service;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 住院信息
 * @author lsw
 * @date 2024-07-19
 */
@Api(tags = "住院信息管理")
@Anonymous
@RestController
@RequestMapping("/work/pv1")
public class Pv1Controller extends BaseController {

    @Autowired
    private IPv1Service pv1Service;

    //@PreAuthorize("@ss.hasPermi('work:pv1:list')")
    @ApiOperation(value = "获取所有科室")
    @Anonymous
    @GetMapping("/department")
    public TableDataInfo getAllDepartment() {
        startPage();
        List<PatientCardDto> list=pv1Service.getAllDepartment();
        return getDataTable(list);
    }

    @ApiOperation(value = "根据姓名、科室、主治医生查询就诊信息列表",notes = "可单条件或多条件查询，需要查哪个就传哪个")
    @Anonymous
    @GetMapping("/patientCard")
    public TableDataInfo getPatientCardByNameOrDepartment(@RequestParam(value = "patientName",required = false) String patientName,
                                                            @RequestParam(value = "departmentName",required = false) String departmentName,
                                                          @RequestParam(value = "physician",required = false) String physician){
        startPage();
        List<PatientCardDto> list=pv1Service.getPatientCardByNameOrDepartment(patientName,departmentName,physician);
        return getDataTable(list);
    }


    @ApiOperation(value = "获取住院信息列表")
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('work:pv1:list')")
    @GetMapping("/list")
    public TableDataInfo list(Pv1 pv1){
        startPage();
        List<Pv1> list = pv1Service.selectList(pv1);
        return getDataTable(list);
    }

    @ApiOperation(value = "根据id查询住院信息")
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('work:pv1:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id){
        return AjaxResult.success(pv1Service.getById(id));
    }

    @ApiOperation(value = "添加住院信息")
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('work:pv1:add')")
    @Log(title = "住院信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Pv1 pv1){
        return toAjax(pv1Service.save(pv1));
    }

    @ApiOperation(value = "修改住院信息")
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('work:pv1:edit')")
    @Log(title = "住院信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Pv1 pv1){
        return toAjax(pv1Service.updateById(pv1));
    }

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