package thyyxxk.webserver.controller.inpatient.xmlr;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import thyyxxk.webserver.aop.interfaces.NeedYbCode;
import thyyxxk.webserver.config.auth.PassToken;
import thyyxxk.webserver.config.exception.ExceptionEnum;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
import thyyxxk.webserver.entity.datamodify.ZyDetailCharge;
import thyyxxk.webserver.entity.inpatient.FeeSelect;
import thyyxxk.webserver.entity.inpatient.ZyActpatient;
import thyyxxk.webserver.entity.projectEntry.DrugReturnForm;
import thyyxxk.webserver.entity.xmlr.dto.XmlrQueryFee;
import thyyxxk.webserver.entity.xmlr.vo.FeeResult;
import thyyxxk.webserver.service.inpatient.xmlr.XiangMuLuRuService;
import thyyxxk.webserver.utils.ResultVoUtil;
import thyyxxk.webserver.utils.StringUtil;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 描述： 项目录入
 * </p>
 *
 * @author xc
 * @date 2021-08-02 10:36
 */
@RestController
@RequestMapping("/xmlr")
public class XiangMuLuRuController {
    private final XiangMuLuRuService service;

    @Autowired
    public XiangMuLuRuController(XiangMuLuRuService service) {
        this.service = service;
    }

    @GetMapping("/getPatientInfo")
    public ResultVo<ZyActpatient> getPatientInfo(@RequestParam("patNo") String patNo,
                                                 @RequestParam(value = "times", required = false) Integer times) {
        return service.getPatientInfo(patNo, times);
    }


    @PostMapping("/getFee")
    public ResultVo<FeeResult> getFee(@RequestBody XmlrQueryFee params) {
        return service.getFee(params);
    }

    @PostMapping("/getHuanZheFeiYong")
    public ResultVo<XiangMuLuRuService.PatientResult> getHuanZheFeiYong(@RequestBody ZyDetailCharge param) {
        if (StringUtil.isBlank(param.getInpatientNo()) || param.getAdmissTimes() == null) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_HTML_ERROR, "住院号或住院次数为空 <br/>๑乛◡乛๑");
        }
        return ResultVoUtil.success(service.getHuanZheFeiYong(param));
    }

    @GetMapping("/getChargeCode")
    public ResultVo<List<FeeSelect>> getChargeCode(@RequestParam("pyCode") String pyCode) {
        return service.getChargeCode(pyCode);
    }

    @PostMapping("/getMuBan")
    public ResultVo<IPage<ZyDetailCharge>> getMuBan(@RequestBody XiangMuLuRuService.SearchMb params) {
        return service.getMuBan(params);
    }

    @GetMapping("/getMuBanXinXi")
    public ResultVo<List<ZyDetailCharge>> getMuBanXinXi(@RequestParam("patternName") String patternName,
                                                        @RequestParam("opIdCode") String opIdCode) {
        return service.getMuBanXinXi(patternName, opIdCode);
    }

    @GetMapping("/getDept")
    public ResultVo<List<GetDropdownBox>> getDept() {
        return service.getDept();
    }

    @GetMapping("/getWard")
    public ResultVo<List<GetDropdownBox>> getWard() {
        return service.getWard();
    }

    @GetMapping("/queryXiangMu")
    public ResultVo<List<ZyDetailCharge>> queryXiangMu(@RequestParam("pyCode") String pyCode,
                                                       @RequestParam("xiangMuHuoYaoPinFlag") Integer xiangMuHuoYaoPinFlag) {
        return service.queryXiangMu(pyCode, xiangMuHuoYaoPinFlag);
    }

    @PostMapping("/xiangMuFeiYongShangChuan")
    @NeedYbCode
    public ResultVo<String> xiangMuFeiYongShangChuan(@RequestBody ZyDetailCharge param) {
        return service.xiangMuFeiYongShangChuan(param);
    }

    @PostMapping("/shangChuanMuBan")
    public ResultVo<String> shangChuanMuBan(@RequestBody ZyDetailCharge zyDetailCharge) {
        return service.shangChuanMuBan(zyDetailCharge);
    }

    @GetMapping("/yiZhuTuiFeiPiPei")
    public ResultVo<String> yiZhuTuiFeiPiPei(@RequestParam("inpatientNo") String inpatientNo,
                                             @RequestParam("admissTimes") Integer admissTimes,
                                             @RequestParam("deptCode") String deptCode) {
        return service.yiZhuTuiFeiPiPei(inpatientNo, admissTimes, deptCode);
    }

    @GetMapping("/shanChuMuBan")
    public ResultVo<String> shanChuMuBan(@RequestParam("patterName") String patterName,
                                         @RequestParam("opIdCode") String opIdCode) {
        return service.shanChuMuBan(patterName, opIdCode);
    }

    @GetMapping("/getPyCode")
    public ResultVo<ZyDetailCharge> getPyCode(String inputStr) {
        return service.getPyCode(inputStr);
    }

    @GetMapping("/getBingQuDuiYingKeShi")
    public ResultVo<List<GetDropdownBox>> getBingQuDuiYingKeShi(String ward) {
        return service.getBingQuDuiYingKeShi(ward);
    }

    @PassToken
    @GetMapping("/weiGuiFeiYongFenXi")
    public ResultVo<ZyActpatient> weiGuiFeiYongFenXi(@RequestParam("inpatientNo") String inpatientNo,
                                                     @RequestParam("execUnit") String execUnit) {
        return service.weiGuiFeiYongFenXi(inpatientNo, execUnit);
    }

    @GetMapping("/huoQuZhenShuKePiPei")
    public ResultVo<List<ZyDetailCharge>> huoQuZhenShuKePiPei(@RequestParam("inpatientNo") String inpatientNo,
                                                              @RequestParam("admissTimes") Integer admissTimes,
                                                              @RequestParam("ledgerSn") Integer ledgerSn,
                                                              @RequestParam("chargeCodeMx") String chargeCodeMx,
                                                              @RequestParam("execUnit") String execUnit,
                                                              @RequestParam("orderNo") String orderNo,
                                                              @RequestParam("startTime") String startTime,
                                                              @RequestParam("endTime") String endTime,
                                                              @RequestParam("riQiPaiXu") String riQiPaiXu) {
        return service.huoQuZhenShuKePiPei(inpatientNo, admissTimes, ledgerSn, chargeCodeMx, execUnit, orderNo, startTime, endTime, riQiPaiXu);
    }

    @PostMapping("/caiFenPiPei")
    public ResultVo<String> caiFenPiPei(@RequestBody ZyDetailCharge zyDetailCharge) {
        return service.caiFenPiPei(zyDetailCharge);
    }

    @PostMapping("/exportExcel")
    public void exportExcel(HttpServletResponse response,
                            @RequestBody @Validated ZyDetailCharge param) {
        service.exportExcel(response, param);
    }

    @PostMapping("/xiuGaiZiFeiBiaoZhi")
    public ResultVo<String> xiuGaiZiFeiBiaoZhi(@RequestBody @Validated ZyDetailCharge param) throws Exception {
        return service.xiuGaiZiFeiBiaoZhi(param);
    }

    @GetMapping("/rejectNotGeneratedMedicationList")
    public ResultVo<String> rejectNotGeneratedMedicationList(@RequestParam("patNo") String patNo,
                                                             @RequestParam("times") Integer times) {
        return service.rejectNotGeneratedMedicationList(patNo, times);
    }

    @GetMapping("/getNoMedicineReturnOrderGenerated")
    public ResultVo<List<DrugReturnForm>> getNoMedicineReturnOrderGenerated(@RequestParam("startDate") String startDate,
                                                                            @RequestParam("endDate") String endDate,
                                                                            @RequestParam("groupNo") String groupNo) {
        return service.getNoMedicineReturnOrderGenerated(startDate, endDate, groupNo);
    }

    @GetMapping("/generateMedicationList")
    public ResultVo<JSONObject> generateMedicationList(@RequestParam("startDate") String startDate,
                                                       @RequestParam("endDate") String endDate,
                                                       @RequestParam("groupNo") String groupNo,
                                                       @RequestParam("refundReason") Integer refundReason) {
        return service.generateMedicationList(startDate, endDate, groupNo, refundReason);
    }

    @GetMapping("/getPrescription")
    public ResultVo<List<DrugReturnForm>> getPrescription(@RequestParam("startDate") String startDate,
                                                          @RequestParam("endDate") String endDate) {
        return service.getPrescription(startDate, endDate);
    }


    @GetMapping("/getAPrescriptionByPageNo")
    public ResultVo<JSONObject> getAPrescriptionByPageNo(@RequestParam("pageNo") Integer pageNo) {
        return service.getAPrescriptionByPageNo(pageNo);
    }


}

