package com.openhis.web.pharmacymanage.controller;

import java.util.List;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.core.common.core.domain.R;
import com.openhis.web.pharmacymanage.appservice.IWesternMedicineDispenseAppService;
import com.openhis.web.pharmacymanage.dto.DispenseItemDto;
import com.openhis.web.pharmacymanage.dto.EncounterInfoSearchParam;
import com.openhis.web.pharmacymanage.dto.ItemDispenseOrderDto;

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

/**
 * 西药发药
 *
 * @author wangyang
 * @date 2025/3/14
 */
@RestController
@RequestMapping("/pharmacy-manage/western-medicine-dispense")
@Slf4j
@AllArgsConstructor
public class WesternMedicineDispenseController {

    @Resource
    public IWesternMedicineDispenseAppService westernMedicineDispenseService;

    /**
     * 获取页面初始化信息
     *
     * @return 初始化信息
     */
    @GetMapping(value = "/init")
    public R<?> medicineDispenseInit() {
        return westernMedicineDispenseService.init();
    }

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

    /**
     * 发药单查询
     *
     * @param itemDispenseOrderDto 查询信息
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @return 处方单
     */
    @GetMapping("/medicine-order")
    public R<?> getMedicineDispenseOrderList(ItemDispenseOrderDto itemDispenseOrderDto,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return westernMedicineDispenseService.getMedicineDispenseOrderList(itemDispenseOrderDto, pageNo, pageSize);
    }

    /**
     * 配药
     *
     * @param dispenseMedicineList 配药信息
     * @return 处理结果
     */
    @PutMapping("/prepare")
    public R<?> medicinePrepare(@RequestBody List<DispenseItemDto> dispenseMedicineList) {
        return westernMedicineDispenseService.medicinePrepare(dispenseMedicineList);
    }

    /**
     * 核对发药
     *
     * @param dispenseMedicineList 发药信息
     * @return 处理结果
     */
    @PutMapping("/medicine-dispense")
    public R<?> medicineDispense(@RequestBody List<DispenseItemDto> dispenseMedicineList) {
        return westernMedicineDispenseService.medicineDispense(dispenseMedicineList);
    }

    /**
     * 作废
     *
     * @param dispenseMedicineList 作废信息
     * @return 处理结果
     */
    @PutMapping("/medicine-cancel")
    public R<?> medicineCancel(@RequestBody List<DispenseItemDto> dispenseMedicineList) {
        return westernMedicineDispenseService.medicineCancel(dispenseMedicineList);
    }
}
