package cn.sh.stc.sict.theme.hphy.controller.web;

import cn.hutool.core.util.StrUtil;
import cn.sh.stc.sict.cloud.common.core.util.R;
import cn.sh.stc.sict.cloud.common.security.util.SecurityUtils;
import cn.sh.stc.sict.cloud.upms.dto.CurrentUser;
import cn.sh.stc.sict.theme.hphy.model.HphyGuideRecord;
import cn.sh.stc.sict.theme.hphy.service.HphyGuideQuestionService;
import cn.sh.stc.sict.theme.hphy.service.HphyGuideRecordService;
import cn.sh.stc.sict.theme.hphy.vo.DiseaseAnalysisDTO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author F_xh
 */
@Slf4j
@RestController
@AllArgsConstructor
@Api(tags = "[B]导医记录")
@RequestMapping("/b/guide/record")
public class GuideRecordController {

    private HphyGuideRecordService hphyGuideRecordService;

    @ApiOperation("分页查询")
    @GetMapping("/page")
    public R<HphyGuideRecord> page(Page page, String patientName, String disease){
        LambdaQueryWrapper<HphyGuideRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StrUtil.isNotBlank(patientName), HphyGuideRecord::getPatientName, patientName)
                .like(StrUtil.isNotBlank(disease), HphyGuideRecord::getDisease, disease)
                .orderByDesc(HphyGuideRecord::getUpdateTime, HphyGuideRecord::getCreateTime);

        page = hphyGuideRecordService.page(page, wrapper);

        return new R(page);
    }

    @ApiOperation("获取详情")
    @GetMapping("/info")
    public R info(@RequestParam("guideId")Long guideId){

        HphyGuideRecord guide = hphyGuideRecordService.getById(guideId);
        if (guide == null) {
            return new R().error("未找到导医记录！");
        }
        List<DiseaseAnalysisDTO> dtoList = hphyGuideRecordService.listAnalysis(guideId);

        return new R();
    }

}
