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

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.*;

import com.core.common.core.domain.R;
import com.openhis.web.inhospitalnursestation.appservice.IATDManageAppService;
import com.openhis.web.inhospitalnursestation.dto.AdmissionPageParam;
import com.openhis.web.inhospitalnursestation.dto.AdmissionPatientInfoDto;

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

/**
 * 入出转管理 controller
 *
 * @author zwh
 * @date 2025-07-28
 */
@RestController
@RequestMapping("/nurse-station/atd-manage")
@Slf4j
@AllArgsConstructor
public class ATDManageController {

    @Resource
    private IATDManageAppService atdManageAppService;

    /**
     * 入出转管理页面初始化
     *
     * @return 初始化信息
     */
    @GetMapping(value = "/init")
    public R<?> atdManageInit() {
        return atdManageAppService.atdManageInit();
    }

    /**
     * 入院患者分页列表
     *
     * @param admissionPageParam 查询条件
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @param searchKey 模糊查询关键字
     * @param request 请求数据
     * @return 入院患者分页列表
     */
    @GetMapping(value = "/admission-patient")
    public R<?> getAdmissionPatientPage(AdmissionPageParam admissionPageParam,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
        @RequestParam(name = "searchKey", required = false) String searchKey, HttpServletRequest request) {
        return atdManageAppService.getAdmissionPatientPage(admissionPageParam, pageNo, pageSize, searchKey, request);
    }

    /**
     * 入院患者床位信息分页列表
     *
     * @param admissionPageParam 查询条件
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @return 床位信息分页列表
     */
    @GetMapping(value = "/admission-bed")
    public R<?> getAdmissionBedPage(AdmissionPageParam admissionPageParam,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return atdManageAppService.getAdmissionBedPage(admissionPageParam, pageNo, pageSize);
    }

    /**
     * 入院患者详细信息
     *
     * @param encounterId 住院id
     * @return 入院患者详细信息
     */
    @GetMapping(value = "/admission-patient-info")
    public R<?> getAdmissionPatientInfo(Long encounterId) {
        return atdManageAppService.getAdmissionPatientInfo(encounterId);
    }

    /**
     * 住院患者待处理信息列表
     *
     * @param encounterId 住院id
     * @return 待处理信息列表
     */
    @GetMapping(value = "/patient-pending")
    public R<?> getInPatientPendingList(Long encounterId) {
        return atdManageAppService.getInPatientPendingList(encounterId);
    }

    /**
     * 入科床位分配
     *
     * @param admissionPatientInfoDto 床位分配参数
     * @return 结果
     */
    @PostMapping(value = "/bed-assignment")
    public R<?> admissionBedAssignment(@RequestBody AdmissionPatientInfoDto admissionPatientInfoDto) {
        return atdManageAppService.admissionBedAssignment(admissionPatientInfoDto);
    }

    /**
     * 转科
     *
     * @param encounterId 住院id
     * @return 结果
     */
    @PutMapping(value = "/transfer-department")
    public R<?> transferDepartment(Long encounterId) {
        return atdManageAppService.transferDepartment(encounterId);
    }

    /**
     * 出院
     *
     * @param encounterId 住院id
     * @return 结果
     */
    @PutMapping(value = "/hospital-discharge")
    public R<?> hospitalDischarge(Long encounterId) {
        return atdManageAppService.hospitalDischarge(encounterId);
    }
}
