package com.yihu.wlyy.repository.patient;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.yihu.wlyy.entity.patient.PatientHealthRecordSports;

import java.util.Date;

public interface PatientHealthRecordSportsDao extends PagingAndSortingRepository<PatientHealthRecordSports, Long>, JpaSpecificationExecutor<PatientHealthRecordSports> {

	// 查询患者标识健康记录
	@Query("select a from PatientHealthRecordSports a where a.patient = ?1 and a.del = '1'")
	Iterable<PatientHealthRecordSports> findByPatient(String patient);
	
	// 查询最近的健康记录
	@Query("SELECT a FROM PatientHealthRecordSports a WHERE a.patient = ?1 and a.del = '1' ORDER BY a.czrq DESC")
	Page<PatientHealthRecordSports> findRecentByPatient(String patient, Pageable pageRequest);

	@Query("select a from PatientHealthRecordSports a where a.patient = ?1 and a.recordDate >= ?2 and a.recordDate <= ?3 and a.del = '1' order by a.recordDate desc")
	Page<PatientHealthRecordSports> findSportsByPatient(String patient, Date start, Date end, Pageable pageRequest);

}
