package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.entity.AssessmentReport;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface AssessmentReportMapper extends BaseMapper<AssessmentReport> {
    
    /**
     * 查询患者的评估报告列表
     */
    @Select("SELECT ar.*, p.name as patientName " +
            "FROM assessment_report ar " +
            "LEFT JOIN patient p ON ar.patient_id = p.id " +
            "WHERE ar.patient_id = #{patientId} " +
            "ORDER BY ar.create_time DESC")
    List<AssessmentReport> selectByPatientId(@Param("patientId") Integer patientId);
    
    /**
     * 查询医生负责的患者的评估报告列表
     */
    @Select("SELECT ar.*, p.name as patientName " +
            "FROM assessment_report ar " +
            "LEFT JOIN patient p ON ar.patient_id = p.id " +
            "INNER JOIN doctor_patient dp ON ar.patient_id = dp.patient_id " +
            "WHERE dp.doctor_id = #{doctorId} " +
            "ORDER BY ar.create_time DESC")
    List<AssessmentReport> selectByDoctorId(@Param("doctorId") Integer doctorId);
    
    /**
     * 查询所有评估报告（管理员使用）
     */
    @Select("SELECT ar.*, p.name as patientName " +
            "FROM assessment_report ar " +
            "LEFT JOIN patient p ON ar.patient_id = p.id " +
            "ORDER BY ar.create_time DESC")
    List<AssessmentReport> selectAllReports();
    
    /**
     * 根据ID查询评估报告
     */
    @Select("SELECT id, patient_id, report_period, start_date, end_date, summary, trend_analysis, " +
            "recommendation, doctor_comment, status, create_time " +
            "FROM assessment_report " +
            "WHERE id = #{id}")
    AssessmentReport selectById(@Param("id") Integer id);
} 