package com.diagbot.web;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.CheckDeptDTO;
import com.diagbot.dto.CheckJobDTO;
import com.diagbot.dto.RespDTO;
import com.diagbot.facade.MedCheckInfoFacade;
import com.diagbot.facade.MedCheckWorkFacade;
import com.diagbot.vo.CheckJobPageVO;
import com.diagbot.vo.CheckJobVO;
import com.diagbot.vo.DistributionJobVO;
import com.diagbot.vo.MedCheckInfoAddVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 核查表 前端控制器
 * </p>
 *
 * @author wangfeng
 * @since 2020-07-06
 */
@RestController
@RequestMapping("/qc/medCheckInfo")
@Api(value = "核查病历数据模块相关接口API", tags = { "核查病历数据模块相关接口API" })
@SuppressWarnings("unchecked")
public class MedCheckInfoController {

    @Autowired
    MedCheckInfoFacade medCheckInfoFacade;
    @Autowired
    MedCheckWorkFacade medCheckWorkFacade;

    @ApiOperation(value = "核查数据接口[by:wangfeng]",
            notes = "核查数据接口")
    @PostMapping("/addMedCheckInfo")
    @SysLogger("addMedCheckInfo")
    @ApiIgnore
    public RespDTO<Boolean> addMedCheckInfo(@RequestBody MedCheckInfoAddVO medCheckInfoAddVO) {
        Boolean res = medCheckInfoFacade.addMedCheckInfos(medCheckInfoAddVO);
        return RespDTO.onSuc(res);
    }



    @ApiOperation(value = "分配核查任务--获取核查人员列表[by:songxl]",
            notes = "获取核查人员列表")
    @PostMapping("/getCheckUserMap")
    @SysLogger("getCheckUserMap")
    public RespDTO<Map<String, List<CheckDeptDTO>>> getCheckUserMap() {
        Map<String, List<CheckDeptDTO>> userInfoMap = medCheckInfoFacade.getCheckUserMap();
        return RespDTO.onSuc(userInfoMap);
    }


    @ApiOperation(value = "分配核查任务--获取待分配核查任务列表[by:songxl]",
            notes = "startTime：任务生成开始时间 必填<br>" +
                    "endTime：  任务生成结束时间 必填<br>" +
                    "或<br>" +
                    "behosDateStart：  出院开始时间 必填<br>" +
                    "behosDateEnd：  出院结束时间 必填<br>" +
                    "jobType：核查任务类型 必填 0-科室任务  1-质控科 2-院级<br>" )
    @PostMapping("/getCheckList")
    @SysLogger("getCheckList")
    public RespDTO<IPage<CheckJobDTO>> getCheckList(@RequestBody CheckJobPageVO checkJobPageVO) {
        IPage<CheckJobDTO> userInfos = medCheckInfoFacade.getUserCheckList(checkJobPageVO);
        return RespDTO.onSuc(userInfos);
    }

    @ApiOperation(value = "分配核查任务--分配/取消核查任务[by:songxl]",
            notes = "behospitalCodes：病人住院序号集合 必填<br>" +
                    "checkId：  核查用户id 必填<br>" +
                    "checkName：  核查用户姓名 必填<br>" +
                    "checkDept：  核查人科室id 必填<br>" +
                    "behospitalDepts：  核查任务科室id集合 必填<br>" +
                    "jobType：  任务类型 0科室、1质控科额、2院级 必填<br>" +
                    "distributionType：操作类型 必填 分配或取消 0-分配，1-取消分配<br>")
    @PostMapping("/updateDistributionCheck")
    @SysLogger("updateDistributionCheck")
    public RespDTO<Boolean> distributionJobs(@RequestBody DistributionJobVO distributionJobVO) {
        return RespDTO.onSuc(medCheckInfoFacade.distributionJobs(distributionJobVO));
    }


    @ApiOperation(value = "分配核查任务--获取指定核查人员的核查任务[by:songxl]",
            notes = "checkId：核查用户id")
    @PostMapping("/getCheckListByUserId")
    @SysLogger("getCheckListByUserId")
    public RespDTO<IPage<CheckJobDTO>> getCheckListByUserId(@RequestBody CheckJobPageVO checkJobVO) {
        IPage<CheckJobDTO> userInfos = medCheckInfoFacade.getCheckListByUserId(checkJobVO);
        return RespDTO.onSuc(userInfos);
    }

    @ApiOperation(value = "质控核查--生成患者病历类型[by:songxl]",
            notes = "生成患者病历类型 <br>" +
                    "备注：如果历史患者病历类型已经生成，接口只会筛选当前时间前半个小时入院患者生成类型")
    @PostMapping("/createMedBeHospitalInfoType")
    @SysLogger("createMedBeHospitalInfoType")
    public RespDTO<Boolean> createMedBeHospitalInfoType() {
        return RespDTO.onSuc(medCheckWorkFacade.createMedBeHospitalInfoType());
    }
}
