package com.openhis.web.outpatientmanage.controller;

import java.util.List;

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

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

import com.core.common.core.domain.R;
import com.openhis.web.outpatientmanage.appservice.IOutpatientTreatmentAppService;
import com.openhis.web.outpatientmanage.dto.OutpatientTreatmentEncounterDto;
import com.openhis.web.outpatientmanage.dto.OutpatientTreatmentInfoDto;

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

/**
 * 门诊处置
 *
 * @author yuxj
 * @date 2025/4/10
 */
@RestController
@RequestMapping("/outpatient-manage/treatment")
@Slf4j
@AllArgsConstructor
public class OutpatientTreatmentController {

    @Resource
    private IOutpatientTreatmentAppService outpatientTreatmentAppService;

    /**
     * 门诊处置初期数据
     *
     * @return 初始化信息
     */
    @GetMapping("/init")
    public R<?> outpatientTreatmentInit() {
        return outpatientTreatmentAppService.init();
    }

    /**
     * 分页查询就诊病人列表
     *
     * @param outpatientTreatmentEncounterDto 查询条件
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @param searchKey 模糊查询关键字
     * @param request 请求数据
     * @return 就诊病人列表
     */
    @GetMapping("/encounter-list")
    public R<?> getEncounterInfoList(OutpatientTreatmentEncounterDto outpatientTreatmentEncounterDto,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
        @RequestParam(name = "searchKey", required = false) String searchKey, HttpServletRequest request) {
        return outpatientTreatmentAppService.getEncounterInfoListPage(outpatientTreatmentEncounterDto, pageNo, pageSize,
            searchKey, request);
    }

    /**
     * 处置单查询
     *
     * @param outpatientTreatmentInfoDto 处置信息
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @return 处置单
     */
    @GetMapping("/treatment-list")
    public R<?> getOutpatientTreatmentInfo(OutpatientTreatmentInfoDto outpatientTreatmentInfoDto,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "100") Integer pageSize) {
        return outpatientTreatmentAppService.getOutpatientTreatmentInfo(outpatientTreatmentInfoDto, pageNo, pageSize);
    }

    /**
     * 诊疗执行记录查询
     *
     * @param reqId 请求项目id
     * @return 执行记录列表
     */
    @GetMapping(value = "/perform-record")
    public R<?> getPerformRecord(@RequestParam Long reqId) {
        return outpatientTreatmentAppService.getPerformRecord(reqId);
    }

    /**
     * 诊疗执行
     *
     * @param performInfoList 执行信息列表
     * @return 执行结果
     */
    @PutMapping("/perform")
    public R<?> perform(@RequestBody List<PerformInfoDto> performInfoList) {
        return outpatientTreatmentAppService.perform(performInfoList);
    }

    /**
     * 取消执行
     *
     * @param performInfoList 执行信息列表
     * @return 取消结果
     */
    @PutMapping(value = "/cancel-perform")
    public R<?> cancelPerform(@RequestBody List<PerformInfoDto> performInfoList) {
        return outpatientTreatmentAppService.cancelPerform(performInfoList);
    }

    /**
     * 输血贴查询
     * 
     * @param requestId 请求id
     * @return 输血贴
     */
    @GetMapping(value = "/blood-transfusion-patch")
    public R<?> getBloodTransfusionPatch(@RequestParam(value = "requestId") Long requestId) {
        return outpatientTreatmentAppService.getBloodTransfusionPatch(requestId);
    }

}
