package com.openhis.web.inpatientmanage.controller;

import java.util.List;

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

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

import com.core.common.core.domain.R;
import com.openhis.web.inpatientmanage.appservice.INursingRecordAppService;
import com.openhis.web.inpatientmanage.dto.NursingEmrTemplateDto;
import com.openhis.web.inpatientmanage.dto.NursingRecordDto;
import com.openhis.web.inpatientmanage.dto.NursingSearchParam;

import lombok.extern.slf4j.Slf4j;

/**
 * 护理记录单 controller
 *
 * @author gyy
 * @date 2025-05-30
 */
@RestController
@RequestMapping("/nursing-record")
@Slf4j
public class NursingRecordController {

    @Resource
    private INursingRecordAppService nursingRecordAppService;

    /**
     * 获取住院患者信息 分页显示
     *
     * @param nursingSearchParam 查询参数
     * @param searchKey 模糊查询
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @return 患者信息
     */
    @GetMapping("/patient-page")
    public R<?> getPatientInfoPage(NursingSearchParam nursingSearchParam,
        @RequestParam(value = "searchKey", defaultValue = "") String searchKey,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest request) {

        return nursingRecordAppService.getPatientInfoPage(nursingSearchParam, searchKey, pageNo, pageSize, request);
    }

    /**
     * 获取患者护理记录单信息 分页显示
     *
     * @param nursingSearchParam 查询参数
     * @param searchKey 模糊查询
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @return 患者护理记录单信息
     */
    @GetMapping("/nursing-patient-page")
    public R<?> getNursingPatientPage(NursingSearchParam nursingSearchParam,
        @RequestParam(value = "searchKey", defaultValue = "") String searchKey,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest request) {

        return nursingRecordAppService.getNursingPatientPage(nursingSearchParam, searchKey, pageNo, pageSize, request);
    }

    /**
     * 保存护理记录单
     *
     * @param nursingRecordDto 护理记录实体
     */
    @PostMapping("/save-nursing")
    public R<?> saveRecord(@Validated @RequestBody NursingRecordDto nursingRecordDto) {
        return nursingRecordAppService.saveRecord(nursingRecordDto);
    }

    /**
     * 编辑护理记录单
     *
     * @param nursingRecordDto 护理记录实体
     */
    @PostMapping("/update-nursing")
    public R<?> updateRecord(@Validated @RequestBody NursingRecordDto nursingRecordDto) {
        return nursingRecordAppService.updateRecord(nursingRecordDto);
    }

    /**
     * 删除护理记录单
     *
     * @param recordList 记录单List
     */
    @PostMapping("/delete-nursing")
    public R<?> delRecord(@Validated @RequestBody List<NursingRecordDto> recordList) {
        return nursingRecordAppService.delRecord(recordList);
    }

    /**
     * 获取电子病历模板列表 分页显示
     *
     * @param nursingSearchParam 查询参数
     * @param searchKey 模糊查询
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @return 患者护理记录单信息
     */
    @GetMapping("/emr-template-page")
    public R<?> getEmrTemplate(NursingSearchParam nursingSearchParam,
        @RequestParam(value = "searchKey", defaultValue = "") String searchKey,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest request) {

        return nursingRecordAppService.getEmrTemplate(nursingSearchParam, searchKey, pageNo, pageSize, request);
    }

    /**
     * 保存病历模板
     *
     * @param emrTemplateDto 病历模板信息
     */
    @PostMapping("/emr-template-save")
    public R<?> saveEmrTemplate(@Validated @RequestBody NursingEmrTemplateDto emrTemplateDto) {
        return nursingRecordAppService.saveEmrTemplate(emrTemplateDto);
    }

    /**
     * 删除病历模板
     *
     * @param idList 模板id
     * @return 操作结果
     */
    @PostMapping("/emr-template-del")
    public R<?> deleteEmrTemplate(@Validated @RequestBody List<Long> idList) {
        return nursingRecordAppService.deleteEmrTemplate(idList);
    }

    /**
     * 编辑病历模板
     *
     * @param emrTemplateDto 病历模板信息
     * @return 操作结果
     */
    @PostMapping("/emr-template-update")
    public R<?> updateEmrTemplate(@Validated @RequestBody NursingEmrTemplateDto emrTemplateDto) {
        return nursingRecordAppService.updateEmrTemplate(emrTemplateDto);
    }

}
