package com.ruoyi.web.work.controller;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.List;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.web.work.domain.Visit;
import com.ruoyi.web.work.domain.dto.PatientCardDto;
import com.ruoyi.web.work.service.IVisitService;
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.common.core.page.TableDataInfo;

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

    @Autowired
    private IVisitService visitService;

    @PreAuthorize("@ss.hasPermi('work:visit:list')")
    @ApiOperation(value = "根据姓名、科室、主治医生查询就诊信息列表",notes = "可单条件或多条件查询，需要查哪个就传哪个")
    @GetMapping("/patientCard")
    public TableDataInfo getPatientCardByNameOrDepartment(PatientCardDto patientCardDto){
        startPage();
        List<PatientCardDto> list=visitService.getPatientCardByNameOrDepartmentOrPhysician(patientCardDto);
        return getDataTable(list);
    }

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

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

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

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

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