/*
 * Copyright ©2023 CJB-CNIT Team. All rights reserved
 */
package com.openhis.web.inhospitalcharge.controller;

import javax.servlet.http.HttpServletRequest;

import com.openhis.web.inhospitalcharge.dto.*;
import org.springframework.web.bind.annotation.*;

import com.core.common.core.domain.R;
import com.openhis.web.inhospitalcharge.appservice.IInHospitalRegisterAppService;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 住院登记 controller
 */
@RestController
@RequestMapping("/inhospital-charge/register")
@Slf4j
@AllArgsConstructor
public class InHospitalRegisterController {

    private final IInHospitalRegisterAppService iInHospitalRegisterAppService;

    /**
     * 门诊医生开住院申请
     * 
     * @param inHospitalRegisterDto 住院登记参数
     * @return 结果
     */
    @PostMapping(value = "/by-doctor")
    public R<?> registerByDoctor(@RequestBody InHospitalRegisterDto inHospitalRegisterDto) {
        return iInHospitalRegisterAppService.registerByDoctor(inHospitalRegisterDto);
    }

    /**
     * 查询住院登记信息
     * 
     * @param inHospitalRegisterQueryDto 查询dto
     * @param searchKey 模糊查询关键字
     * @param registeredFlag 已登记标识,已登记传 1 ,待登记传 0
     * @param pageNo 当前页
     * @param pageSize 每页多少条
     * @param request 请求
     * @return 住院登记信息
     */
    @GetMapping(value = "/register-info")
    public R<?> getRegisterInfo(InHospitalRegisterQueryDto inHospitalRegisterQueryDto,
        @RequestParam(value = "searchKey", defaultValue = "") String searchKey,
        @RequestParam(value = "registeredFlag") String registeredFlag,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest request) {
        return R.ok(iInHospitalRegisterAppService.getRegisterInfo(inHospitalRegisterQueryDto, searchKey, registeredFlag,
            pageNo, pageSize, request));
    }

    /**
     * 查询患者基本信息
     * 
     * @param patientId 患者ID
     * @return 患者基本信息
     */
    @GetMapping(value = "/patient-info")
    public R<?> getPatientInfo(@RequestParam Long patientId) {
        return R.ok(iInHospitalRegisterAppService.getPatientInfo(patientId));
    }

    /**
     * 查询住院就诊信息
     * 
     * @param encounterId 住院就诊id
     * @return 住院就诊信息
     */
    @GetMapping(value = "/in-hospital-info")
    public R<?> getInHospitalInfo(@RequestParam Long encounterId) {
        return R.ok(iInHospitalRegisterAppService.getInHospitalInfo(encounterId));
    }

    /**
     * 根据病区号查询床位数
     * 
     * @param wardBusNo 病区号
     * @return 床位数
     */
    @GetMapping(value = "/beds-num")
    public R<?> getBedsNumByWardBusNo(@RequestParam String wardBusNo) {
        return R.ok(iInHospitalRegisterAppService.getBedsNumByWardBusNo(wardBusNo));
    }

    /**
     * 更新患者信息
     * 
     * @param patientUpdateDto 更新患者信息dto
     * @return 结果
     */
    @PutMapping(value = "/update-patient")
    public R<?> updatePatient(@RequestBody PatientUpdateDto patientUpdateDto) {
        return iInHospitalRegisterAppService.updatePatient(patientUpdateDto);
    }

    /**
     * 款台登记
     * 
     * @param inHospitalInfoDto 登记dto
     * @return 结果
     */
    @PostMapping(value = "/by-cashier")
    public R<?> registerByCashier(@RequestBody InHospitalInfoDto inHospitalInfoDto) {
        return iInHospitalRegisterAppService.registerByCashier(inHospitalInfoDto);
    }

    /**
     * 无档登记
     * 
     * @param noFilesRegisterDto 无档登记dto
     * @return 结果
     */
    @PostMapping(value = "/no-files")
    public R<?> noFilesRegister(@RequestBody NoFilesRegisterDto noFilesRegisterDto) {
        return iInHospitalRegisterAppService.noFilesRegister(noFilesRegisterDto);
    }

}
