package com.openhis.web.inhospitalnursestation.controller;

import java.util.List;

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

import com.openhis.web.inhospitalnursestation.appservice.IMedicineSummaryAppService;
import com.openhis.web.inhospitalnursestation.dto.InpatientMedicinePrescriptionInfoDto;
import org.springframework.web.bind.annotation.*;

import com.core.common.core.domain.R;
import com.openhis.web.inhospitalnursestation.dto.InpatientMedicineSearchParam;

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

/**
 * 住院领药
 *
 * @author yuxj
 * @date 2025/8/18
 */
@RestController
@RequestMapping("/nurse-station/medicine-summary")
@Slf4j
@AllArgsConstructor
public class MedicineSummaryController {

    @Resource
    public IMedicineSummaryAppService medicineCollectionService;

    /**
     * 分页查询在科病人列表
     *
     * @param searchParam 查询条件
     * @param searchKey 模糊查询关键字
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @param request 请求数据
     * @return 发药病人列表
     */
    @GetMapping("/encounter-list")
    public R<?> getEncounterInfoList(InpatientMedicineSearchParam searchParam, String searchKey,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest request) {
        return medicineCollectionService.getEncounterInfoListPage(searchParam, searchKey, pageNo, pageSize, request);
    }

    /**
     * 医嘱查询
     *
     * @param searchParam 查询条件
     * @param searchKey 模糊查询关键字
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @param request 请求数据
     */
    @GetMapping("/advice-list")
    public R<?> getPatientInfoList(InpatientMedicineSearchParam searchParam, String searchKey,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest request) {
        return medicineCollectionService.getPrescriptionInfo(searchParam, searchKey, pageNo, pageSize, request);
    }

    /**
     * 显示汇总发药单（生成之前的确认，此刻还没生成汇总单）
     *
     * @param searchParam 查询条件
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @return 处理结果
     */
    @GetMapping("/show-medicine-summary")
    public R<?> showMedicineSummary(@RequestBody List<InpatientMedicineSearchParam> searchParam,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return medicineCollectionService.showMedicineSummary(searchParam, pageNo, pageSize);
    }

    /**
     * 生成汇总发药单
     *
     * @param prescriptionInfo 汇总发药单
     * @return 处理结果
     */
    @PostMapping("/medicine-summary")
    public R<?> medicineSummary(@RequestBody List<InpatientMedicinePrescriptionInfoDto> prescriptionInfo) {
        return medicineCollectionService.medicineSummary(prescriptionInfo);
    }
}
