<commit_before>/**
 * Copyright (C) 2011,2012 <NAME> <http://www.lj.se/minhalsoplan>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.callistasoftware.netcare.core.repository;

import java.util.Date;
import java.util.List;

import org.callistasoftware.netcare.model.entity.PatientEntity;
import org.callistasoftware.netcare.model.entity.ScheduledActivityEntity;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface ScheduledActivityRepository extends JpaRepository<ScheduledActivityEntity, Long> {
		
	/**
	 * Used to display activities and report back results for the patient. <p>
	 *  
	 * @param patient the patient.
	 * @param start start date.
	 * @param end end date.
	 * @return the list.
	 */
	@Query("select e from ScheduledActivityEntity as e inner join " +
			"e.activityDefinition as ad inner join " +
			"ad.healthPlan as hp " +
			"where hp.forPatient = :patient and " +
			"hp.active = 'true' and " +
			"ad.removedFlag = 'false' and " +
			"e.scheduledTime between :start and :end " +
			"order by e.scheduledTime asc")
	List<ScheduledActivityEntity> findByPatientAndScheduledTimeBetween(
			@Param("patient") final PatientEntity patient,
			@Param("start") final Date start,
			@Param("end") final Date end);

	@Query("select e from ScheduledActivityEntity as e inner join " +
			"e.activityDefinition as ad inner join " +
			"ad.healthPlan as hp " +
			"where hp.forPatient = :patient and ad.removedFlag = 'false' " +
			"and (e.scheduledTime < :expires and e.reportedTime is null and e.status = 0) " +
			"order by e.scheduledTime asc")
	List<ScheduledActivityEntity> findDueExpiresAt(@Param("patient") final PatientEntity patient<commit_msg>Added distinct to JPQL for findByPatientAndScheduledTimeBetween<commit_after>/**
 * Copyright (C) 2011,2012 <NAME> <http://www.lj.se/minhalsoplan>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.callistasoftware.netcare.core.repository;

import java.util.Date;
import java.util.List;

import org.callistasoftware.netcare.model.entity.PatientEntity;
import org.callistasoftware.netcare.model.entity.ScheduledActivityEntity;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface ScheduledActivityRepository extends JpaRepository<ScheduledActivityEntity, Long> {
		
	/**
	 * Used to display activities and report back results for the patient. <p>
	 *  
	 * @param patient the patient.
	 * @param start start date.
	 * @param end end date.
	 * @return the list.
	 */
	@Query("select distinct e from ScheduledActivityEntity as e inner join " +
			"e.activityDefinition as ad inner join " +
			"ad.healthPlan as hp " +
			"where hp.forPatient = :patient and " +
			"hp.active = 'true' and " +
			"ad.removedFlag = 'false' and " +
			"e.scheduledTime between :start and :end " +
			"order by e.scheduledTime asc")
	List<ScheduledActivityEntity> findByPatientAndScheduledTimeBetween(
			@Param("patient") final PatientEntity patient,
			@Param("start") final Date start,
			@Param("end") final Date end);

	@Query("select e from ScheduledActivityEntity as e inner join " +
			"e.activityDefinition as ad inner join " +
			"ad.healthPlan as hp " +
			"where hp.forPatient = :patient and ad.removedFlag = 'false' " +
			"and (e.scheduledTime < :expires and e.reportedTime is null and e.status = 0) " +
			"order by e.scheduledTime asc")
	List<ScheduledActivityEntity> findDueExpiresAt(@Param("patient") final PatientEntity patient
{'fraction_non_alphanumeric': 0.09607335060793303, 'fraction_numerical': 0.003986446083316724, 'mean_word_length': 4.29883843717001, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5568860', 'n_tokens_mistral': 1536, 'n_tokens_neox': 1416, 'n_words': 503}