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.PatientHealthRecordMedication;

import java.util.Date;

public interface PatientHealthRecordMedicationDao extends PagingAndSortingRepository<PatientHealthRecordMedication, Long>, JpaSpecificationExecutor<PatientHealthRecordMedication> {

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

	@Query("SELECT a FROM PatientHealthRecordMedication a WHERE a.patient = ?1 and a.recordDate >= ?2 and a.recordDate <= ?3 and a.del = '1' ORDER BY a.recordDate DESC")
	Page<PatientHealthRecordMedication> findMedicalByPatient(String patient, Date start,Date end, Pageable pageRequest);
}
