package com.ruoyi.web.controller.smartor; 
 | 
  
 | 
import com.github.pagehelper.ISelect; 
 | 
import com.ruoyi.common.annotation.Log; 
 | 
import com.ruoyi.common.constant.HttpStatus; 
 | 
import com.ruoyi.common.core.controller.BaseController; 
 | 
import com.ruoyi.common.core.domain.AjaxResult; 
 | 
import com.ruoyi.common.core.domain.entity.SysUser; 
 | 
import com.ruoyi.common.core.domain.model.LoginUser; 
 | 
import com.ruoyi.common.core.page.TableDataInfo; 
 | 
import com.ruoyi.common.enums.BusinessType; 
 | 
import com.ruoyi.common.utils.PageUtils; 
 | 
import com.ruoyi.common.utils.poi.ExcelUtil; 
 | 
import com.smartor.domain.*; 
 | 
import com.smartor.service.IPatArchiveService; 
 | 
import io.swagger.annotations.Api; 
 | 
import io.swagger.annotations.ApiImplicitParam; 
 | 
import io.swagger.annotations.ApiImplicitParams; 
 | 
import io.swagger.annotations.ApiOperation; 
 | 
import lombok.extern.slf4j.Slf4j; 
 | 
import org.springframework.beans.factory.annotation.Autowired; 
 | 
import org.springframework.security.access.prepost.PreAuthorize; 
 | 
import org.springframework.util.CollectionUtils; 
 | 
import org.springframework.web.bind.annotation.*; 
 | 
import org.springframework.web.multipart.MultipartFile; 
 | 
  
 | 
import javax.servlet.http.HttpServletResponse; 
 | 
import java.util.HashMap; 
 | 
import java.util.List; 
 | 
import java.util.Map; 
 | 
import java.util.concurrent.Executor; 
 | 
import java.util.concurrent.Executors; 
 | 
  
 | 
/** 
 | 
 * 患者档案Controller 
 | 
 * 
 | 
 * @author smartor 
 | 
 * @date 2023-03-04 
 | 
 */ 
 | 
@Slf4j 
 | 
@Api(description = "患者档案") 
 | 
@RestController 
 | 
@RequestMapping("/smartor/patarchive") 
 | 
public class PatArchiveController extends BaseController { 
 | 
    @Autowired 
 | 
    private IPatArchiveService patArchiveService; 
 | 
  
 | 
    /** 
 | 
     * 查询患者档案列表 
 | 
     */ 
 | 
    @ApiOperation("查询患者档案列表") 
 | 
    //@PreAuthorize("@ss.hasPermi('smartor:patarchive:list')") 
 | 
    @PostMapping("/list") 
 | 
    public TableDataInfo list(@RequestBody PatArchive patArchive) { 
 | 
        PageUtils.startPageByPost(patArchive.getPageNum(), patArchive.getPageSize()); 
 | 
        List<PatArchive> list = patArchiveService.selectPatArchiveList(patArchive); 
 | 
        return getDataTable(list); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 导出患者档案列表 
 | 
     */ 
 | 
    @ApiOperation("导出患者档案列表") 
 | 
    //@PreAuthorize("@ss.hasPermi('smartor:patarchive:export')") 
 | 
    @Log(title = "患者档案", businessType = BusinessType.EXPORT) 
 | 
    @PostMapping("/export") 
 | 
    public void export(HttpServletResponse response, PatArchive patArchive) { 
 | 
        List<PatArchive> list = patArchiveService.selectPatArchiveList(patArchive); 
 | 
        ExcelUtil<PatArchive> util = new ExcelUtil<PatArchive>(PatArchive.class); 
 | 
        util.exportExcel(response, list, "患者档案数据"); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 获取患者档案详细信息 
 | 
     */ 
 | 
    @ApiOperation("获取患者档案详细信息") 
 | 
    //@PreAuthorize("@ss.hasPermi('smartor:patarchive:query')") 
 | 
    @GetMapping(value = "/getInfo/{patid}") 
 | 
    @ApiImplicitParam(name = "patid", value = "患者id") 
 | 
    public AjaxResult getInfo(@PathVariable(name = "patid") Long patid) { 
 | 
        return success(patArchiveService.selectPatArchiveByPatid(patid)); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 新增患者档案 
 | 
     */ 
 | 
    @ApiOperation("新增患者档案") 
 | 
    //@PreAuthorize("@ss.hasPermi('smartor:patarchive:add')") 
 | 
    @Log(title = "患者档案", businessType = BusinessType.INSERT) 
 | 
    @PostMapping("/add") 
 | 
    public AjaxResult add(@RequestBody PatArchive patArchive) { 
 | 
        return toAjax(patArchiveService.insertPatArchive(patArchive)); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 新增患者档案 
 | 
     */ 
 | 
    @ApiOperation("修改患者档案") 
 | 
    //@PreAuthorize("@ss.hasPermi('smartor:patarchive:update')") 
 | 
    @Log(title = "患者档案", businessType = BusinessType.UPDATE) 
 | 
    @PostMapping("/update") 
 | 
    public AjaxResult update(@RequestBody PatArchive patArchive) { 
 | 
        return toAjax(patArchiveService.update(patArchive)); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 新增或修改患者档信息 
 | 
     */ 
 | 
    @ApiOperation("新增或修改患者档信息") 
 | 
    //@PreAuthorize("@ss.hasPermi('smartor:patarchive:edit')") 
 | 
    @Log(title = "患者档案", businessType = BusinessType.UPDATE) 
 | 
    @PostMapping("/saveOrUpdatePatInfo") 
 | 
    public AjaxResult saveOrUpdatePatInfo(@RequestBody PatArchiveVO patArchiveVO) { 
 | 
        SysUser user = getLoginUser().getUser(); 
 | 
        patArchiveVO.setOrgid(user.getOrgid()); 
 | 
        return toAjax(patArchiveService.saveOrUpdatePatInfo(patArchiveVO)); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 删除患者档案 
 | 
     */ 
 | 
    @ApiOperation("删除患者档案") 
 | 
    //@PreAuthorize("@ss.hasPermi('smartor:patarchive:remove')") 
 | 
    @Log(title = "患者档案", businessType = BusinessType.DELETE) 
 | 
    @GetMapping("/remove/{patids}") 
 | 
    @ApiImplicitParam(name = "patids", value = "患者id集合", dataType = "long", dataTypeClass = Long.class) 
 | 
    public AjaxResult remove(@PathVariable Long[] patids) { 
 | 
        return toAjax(patArchiveService.deletePatArchiveByPatids(patids)); 
 | 
    } 
 | 
  
 | 
  
 | 
    /** 
 | 
     * 导入患者文件处理 
 | 
     * 
 | 
     * @param multipartFile 
 | 
     */ 
 | 
    @ApiOperation("导入患者文件处理") 
 | 
    @PostMapping("/importFilehandle") 
 | 
    @ApiImplicitParams({@ApiImplicitParam(name = "tags", value = "标签"), @ApiImplicitParam(name = "multipartFile", value = "上传文件")}) 
 | 
    public AjaxResult importFilehandle(@RequestParam("tags") String tags, @RequestParam("multipartFile") MultipartFile multipartFile) { 
 | 
        Executor executor = Executors.newFixedThreadPool(3); 
 | 
        //获取当前登陆人 
 | 
        LoginUser loginUser = getLoginUser(); 
 | 
        SysUser user = loginUser.getUser(); 
 | 
        PatUpInfoVO patUpInfoVO = patArchiveService.importFilehandle(user, tags, multipartFile); 
 | 
        return success(patUpInfoVO); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 导入患者信息模板 
 | 
     * 
 | 
     * @param response 
 | 
     */ 
 | 
    @ApiOperation("患者信息导入模板") 
 | 
    @PostMapping("/patImportTemplate") 
 | 
    public void patImportTemplate(HttpServletResponse response) { 
 | 
//        ExcelUtil<PatImportInfoVO> util = new ExcelUtil<PatImportInfoVO>(PatImportInfoVO.class); 
 | 
        ExcelUtil<PatArchive> util = new ExcelUtil<PatArchive>(PatArchive.class); 
 | 
        util.importTemplateExcel(response, "患者信息导入"); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 导出患者错误信息 
 | 
     * 
 | 
     * @param patArchiveList 
 | 
     */ 
 | 
    @ApiOperation("导出患者错误信息") 
 | 
    @PostMapping(value = "/exportErrPatInfo") 
 | 
    public void exportErrPatInfo(HttpServletResponse response, @RequestBody List<PatImportInfoVO> patArchiveList) { 
 | 
  
 | 
        ExcelUtil<PatImportInfoVO> util = new ExcelUtil<PatImportInfoVO>(PatImportInfoVO.class); 
 | 
        util.exportExcel(response, patArchiveList, "导出患者错误信息"); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 查询患者列表 
 | 
     */ 
 | 
    @ApiOperation("查询患者列表") 
 | 
    @PostMapping("/patInfoByContion") 
 | 
    public TableDataInfo patInfoByCondition(@RequestBody PatArchiveReq patArchive) { 
 | 
//       PageUtils.startPageByPost(patArchive.getPageNum(), patArchive.getPageSize()); 
 | 
        LoginUser loginUser = getLoginUser(); 
 | 
        SysUser user = loginUser.getUser(); 
 | 
        patArchive.setOrgid(user.getOrgid()); 
 | 
        if (CollectionUtils.isEmpty(patArchive.getLeavehospitaldistrictcodes()) || patArchive.getLeavehospitaldistrictcodes().size() == 0) { 
 | 
            patArchive.setLeavehospitaldistrictcodes(null); 
 | 
        } 
 | 
        if (CollectionUtils.isEmpty(patArchive.getLeaveldeptcodes()) || patArchive.getLeaveldeptcodes().size() == 0) { 
 | 
            patArchive.setLeaveldeptcodes(null); 
 | 
        } 
 | 
        List<PatArchive> patArchives = patArchiveService.patInfoByContion(patArchive); 
 | 
        long count = PageUtils.count(new ISelect() { 
 | 
            @Override 
 | 
            public void doSelect() { 
 | 
                patArchive.setPn(null); 
 | 
                patArchive.setPs(null); 
 | 
                patArchiveService.patInfoByContion(patArchive); 
 | 
            } 
 | 
        }); 
 | 
        return getDataTable2(count, patArchives); 
 | 
    } 
 | 
  
 | 
  
 | 
    /** 
 | 
     * 导出患者列表根据条件 
 | 
     */ 
 | 
    @ApiOperation("导出患者列表根据条件") 
 | 
    @PostMapping("/exportPatInfo") 
 | 
    public void exportPpatInfo(HttpServletResponse response, @RequestBody PatArchiveReq patArchive) { 
 | 
        startPage(); 
 | 
        LoginUser loginUser = getLoginUser(); 
 | 
        SysUser user = loginUser.getUser(); 
 | 
        patArchive.setOrgid(user.getOrgid()); 
 | 
        List<PatArchive> patArchives = patArchiveService.patInfoByContion(patArchive); 
 | 
        if (!CollectionUtils.isEmpty(patArchives)) { 
 | 
            for (int i = 0; i < patArchives.size(); i++) { 
 | 
                patArchives.get(i).setTag(patArchives.get(i).getTagList().toString()); 
 | 
            } 
 | 
        } 
 | 
        ExcelUtil<PatArchive> util = new ExcelUtil<PatArchive>(PatArchive.class); 
 | 
        util.exportExcel(response, patArchives, "患者档案数据"); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 获取患者信息 
 | 
     */ 
 | 
    @ApiOperation("获取患者信息") 
 | 
    @PostMapping("/getPatientInfo") 
 | 
    public Map<String, Object> getPatientInfo(@RequestBody PatArchiveReq patArchiveReq) { 
 | 
        if (patArchiveReq.getPageSize() != null && patArchiveReq.getPageNum() != null) 
 | 
            patArchiveReq.setPageNum(PageUtils.getOffset(patArchiveReq.getPageNum(), patArchiveReq.getPageSize())); 
 | 
  
 | 
        LoginUser loginUser = getLoginUser(); 
 | 
        SysUser user = loginUser.getUser(); 
 | 
        patArchiveReq.setOrgid(user.getOrgid()); 
 | 
        if (CollectionUtils.isEmpty(patArchiveReq.getLeavehospitaldistrictcodes()) || patArchiveReq.getLeavehospitaldistrictcodes().size() == 0) { 
 | 
            patArchiveReq.setLeavehospitaldistrictcodes(null); 
 | 
        } 
 | 
        if (CollectionUtils.isEmpty(patArchiveReq.getLeaveldeptcodes()) || patArchiveReq.getLeaveldeptcodes().size() == 0) { 
 | 
            patArchiveReq.setLeaveldeptcodes(null); 
 | 
        } 
 | 
        List<PatArchiveOthreInfo> patientInfo = patArchiveService.getPatientInfo(patArchiveReq); 
 | 
  
 | 
        Map<String, Object> map = new HashMap<>(); 
 | 
        map.put("code", HttpStatus.SUCCESS); 
 | 
        map.put("msg", "查询成功"); 
 | 
        map.put("rows", patientInfo); 
 | 
  
 | 
        patArchiveReq.setPageNum(null); 
 | 
        patArchiveReq.setPageSize(null); 
 | 
        List<PatArchiveOthreInfo> count = patArchiveService.getPatientInfo(patArchiveReq); 
 | 
        map.put("total", count); 
 | 
        return map; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 获取患者信息 
 | 
     */ 
 | 
    @ApiOperation("获取患者信息") 
 | 
    @PostMapping("/getPatientInfoQC") 
 | 
    public Map<String, Object> getPatientInfoQC(@RequestBody PatArchiveReq patArchiveReq) { 
 | 
        patArchiveReq.setPageNum(PageUtils.getOffset(patArchiveReq.getPageNum(), patArchiveReq.getPageSize())); 
 | 
  
 | 
        LoginUser loginUser = getLoginUser(); 
 | 
        SysUser user = loginUser.getUser(); 
 | 
        patArchiveReq.setOrgid(user.getOrgid()); 
 | 
        if (CollectionUtils.isEmpty(patArchiveReq.getLeavehospitaldistrictcodes()) || patArchiveReq.getLeavehospitaldistrictcodes().size() == 0) { 
 | 
            patArchiveReq.setLeavehospitaldistrictcodes(null); 
 | 
        } 
 | 
        if (CollectionUtils.isEmpty(patArchiveReq.getLeaveldeptcodes()) || patArchiveReq.getLeaveldeptcodes().size() == 0) { 
 | 
            patArchiveReq.setLeaveldeptcodes(null); 
 | 
        } 
 | 
        System.out.println("--------11111111:" + patArchiveReq); 
 | 
        List<PatArchiveOthreInfo> patientInfo = patArchiveService.getPatientInfoQC(patArchiveReq); 
 | 
        System.out.println("--------222222:" + patientInfo.size()); 
 | 
        patArchiveReq.setPageSize(null); 
 | 
        patArchiveReq.setPageNum(null); 
 | 
        List<PatArchiveOthreInfo> patientInfoQC = patArchiveService.getPatientInfoQC(patArchiveReq); 
 | 
  
 | 
//        long count = PageUtils.count(new ISelect() { 
 | 
//            @Override 
 | 
//            public void doSelect() { 
 | 
//                patArchiveService.getPatientInfoQC(patArchiveReq); 
 | 
//            } 
 | 
//        }); 
 | 
        return getDataTable3(patientInfoQC.size(), patientInfo); 
 | 
    } 
 | 
  
 | 
} 
 |