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

import javax.servlet.http.HttpServletRequest;

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

import com.core.common.core.domain.R;
import com.openhis.common.enums.AdviceOpType;
import com.openhis.web.regdoctorstation.appservice.IAdviceManageAppService;
import com.openhis.web.regdoctorstation.dto.RegAdviceSaveParam;
import com.openhis.web.regdoctorstation.dto.RegDoctorStationInitDto;
import com.openhis.web.regdoctorstation.dto.RegPatientMainInfoDto;

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

import java.util.List;

/**
 * 医嘱管理 controller
 */
@RestController
@RequestMapping("/reg-doctorstation/advice-manage")
@Slf4j
@AllArgsConstructor
public class AdviceManageController {

    private final IAdviceManageAppService iAdviceManageAppService;

    /**
     * 住院基础数据初始化
     *
     * @return 基础数据
     */
    @GetMapping(value = "/init")
    public R<?> init() {
        return R.ok(new RegDoctorStationInitDto());
    }

    /**
     * 查询在科住院患者信息
     * 
     * @param regPatientMainInfoDto 住院患者信息 dto
     * @param status 状态 - 在科
     * @param searchKey 模糊查询关键字
     * @param pageNo 当前页
     * @param pageSize 每页多少条
     * @param request 请求
     * @return 在科住院患者信息
     */
    @GetMapping(value = "/reg-patient-zk")
    public R<?> getRegPatientZkInfo(RegPatientMainInfoDto regPatientMainInfoDto,
        @RequestParam(value = "status") Integer status,
        @RequestParam(value = "searchKey", defaultValue = "") String searchKey,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest request) {
        return R.ok(iAdviceManageAppService.getRegPatientMainInfo(regPatientMainInfoDto, status, searchKey, pageNo,
            pageSize, request));
    }

    /**
     * 查询出院住院患者信息
     *
     * @param regPatientMainInfoDto 住院患者信息 dto
     * @param status 状态 - 出院
     * @param searchKey 模糊查询关键字
     * @param pageNo 当前页
     * @param pageSize 每页多少条
     * @param request 请求
     * @return 出院住院患者信息
     */
    @GetMapping(value = "/reg-patient-cy")
    public R<?> getRegPatientCyInfo(RegPatientMainInfoDto regPatientMainInfoDto,
        @RequestParam(value = "status") Integer status,
        @RequestParam(value = "searchKey", defaultValue = "") String searchKey,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest request) {
        return R.ok(iAdviceManageAppService.getRegPatientMainInfo(regPatientMainInfoDto, status, searchKey, pageNo,
            pageSize, request));
    }

    /**
     * 住院保存医嘱
     *
     * @param regAdviceSaveParam 医嘱表单信息
     * @return 结果
     */
    @PostMapping(value = "/save-reg-advice")
    public R<?> saveRegAdvice(@RequestBody RegAdviceSaveParam regAdviceSaveParam) {
        return iAdviceManageAppService.saveRegAdvice(regAdviceSaveParam, AdviceOpType.SAVE_ADVICE.getCode());
    }

    /**
     * 住院签发医嘱
     *
     * @param regAdviceSaveParam 医嘱表单信息
     * @return 结果
     */
    @PostMapping(value = "/sign-reg-advice")
    public R<?> signRegAdvice(@RequestBody RegAdviceSaveParam regAdviceSaveParam) {
        return iAdviceManageAppService.saveRegAdvice(regAdviceSaveParam, AdviceOpType.SIGN_ADVICE.getCode());
    }

    /**
     * 查询住院医嘱请求数据
     *
     * @param encounterId 就诊id
     * @return 住院医嘱请求数据
     */
    @GetMapping(value = "/reg-request-base-info")
    public R<?> getRegRequestBaseInfo(@RequestParam Long encounterId) {
        return iAdviceManageAppService.getRegRequestBaseInfo(encounterId);
    }

    /**
     * 查询历史住院医嘱请求数据
     *
     * @param encounterId 就诊id
     * @param patientId 病人id
     * @return 历史住院医嘱请求数据
     */
    @GetMapping(value = "/reg-request-history-info")
    public R<?> getRegRequestHistoryInfo(@RequestParam Long patientId, Long encounterId) {
        return iAdviceManageAppService.getRegRequestHistoryInfo(patientId, encounterId);
    }

    /**
     * 住院医嘱签退
     * 
     * @param paramList 签退参数
     * @return 结果
     */
    @PostMapping(value = "/sign-off-reg")
    public R<?> signOffRegAdvice(@RequestBody List<AdviceBatchOpParam> paramList) {
        return iAdviceManageAppService.signOffRegAdvice(paramList);
    }

    /**
     * 住院医嘱停止
     * 
     * @param paramList 停嘱
     * @return 结果
     */
    @PostMapping(value = "/stop-reg-advice")
    public R<?> stopRegAdvice(@RequestBody List<AdviceBatchOpParam> paramList) {
        return iAdviceManageAppService.stopRegAdvice(paramList);
    }

}
