1
package org.hisp.dhis.period;
4
* Copyright (c) 2004-2007, University of Oslo
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright notice, this
10
* list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright notice,
12
* this list of conditions and the following disclaimer in the documentation
13
* and/or other materials provided with the distribution.
14
* * Neither the name of the HISP project nor the names of its contributors may
15
* be used to endorse or promote products derived from this software without
16
* specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
import java.util.Collection;
31
import java.util.Date;
32
import java.util.List;
34
import org.hisp.dhis.dataelement.DataElement;
35
import org.hisp.dhis.source.Source;
38
* @author Kristian Nordal
39
* @version $Id: PeriodService.java 5983 2008-10-17 17:42:44Z larshelg $
41
public interface PeriodService
43
String ID = PeriodService.class.getName();
45
// -------------------------------------------------------------------------
47
// -------------------------------------------------------------------------
52
* @param period the Period to add.
53
* @return a generated unique id of the added Period.
55
int addPeriod( Period period );
60
* @param period the Period to delete.
62
void deletePeriod( Period period );
67
* @param id the id of the Period to return.
68
* @return the Period with the given id, or null if no match.
70
Period getPeriod( int id );
75
* @param startDate the start date of the Period.
76
* @param endDate the end date of the Period.
77
* @param periodType the PeriodType of the Period
78
* @return the Period matching the dates and periodtype, or null if no match.
80
Period getPeriod( Date startDate, Date endDate, PeriodType periodType );
83
* Returns all persisted Periods.
85
* @return all persisted Periods.
87
Collection<Period> getAllPeriods();
90
* Returns all Periods with corresponding identifiers.
92
* @param identifiers a collection of identifiers.
93
* @return a collection of Periods.
95
Collection<Period> getPeriods( Collection<Integer> identifiers );
98
* Returns all Periods with start date after or equal the specified start
99
* date and end date before or equal the specified end date.
101
* @param startDate the ultimate start date.
102
* @param endDate the ultimate end date.
103
* @return a collection of all Periods with start date after or equal the
104
* specified start date and end date before or equal the specified
105
* end date, or an empty collection if no Periods match.
107
Collection<Period> getPeriodsBetweenDates( Date startDate, Date endDate );
110
* Returns all Periods of the specified PeriodType with start date after or
111
* equal the specified start date and end date before or equal the specified
114
* @param periodType the PeriodType.
115
* @param startDate the ultimate start date.
116
* @param endDate the ultimate end date.
117
* @return a collection of all Periods with start date after or equal the
118
* specified start date and end date before or equal the specified
119
* end date, or an empty collection if no Periods match.
121
Collection<Period> getPeriodsBetweenDates( PeriodType periodType, Date startDate, Date endDate );
124
* Returns all Intersecting Periods between the startDate and endDate based on PeriodType
125
* For example if the startDate is 2007-05-01 and endDate is 2007-08-01 and periodType is Quartely
126
* then it retuns the periods for Q2,Q3
128
* @param periodType is the ultimate period type
129
* @param startDate is intercepting startDate
130
* @param endDate is intercepting endDate
133
Collection<Period> getIntersectingPeriodsByPeriodType( PeriodType periodType, Date startDate, Date endDate );
136
* Returns Periods where at least one its days are between the given start date and end date.
138
* @param startDate the start date.
139
* @param endDate the end date.
140
* @return Periods where at least one its days are between the given start date and end date.
142
Collection<Period> getIntersectingPeriods( Date startDate, Date endDate );
145
* Returns all Periods from the given collection of Periods which span the border of either the
146
* start date OR end date of the given Period.
148
* @param period the base Period.
149
* @param periods the collection of Periods.
150
* @return all Periods from the given collection of Periods which span the border of either the
151
* start date or end date of the given Period.
153
Collection<Period> getBoundaryPeriods( Period period, Collection<Period> periods );
156
* Returns all Periods from the given collection of Periods which are completely within the
157
* span of the of the given Period.
159
* @param period the base Period.
160
* @param periods the collection of Periods.
161
* @return all Periods from the given collection of Periods which are completely within the
162
* span of the of the given Period.
164
Collection<Period> getInclusivePeriods( Period period, Collection<Period> periods );
167
* Returns all Periods with a given PeriodType.
169
* @param periodType the PeriodType of the Periods to return.
170
* @return all Periods with the given PeriodType, or an empty collection if
173
Collection<Period> getPeriodsByPeriodType( PeriodType periodType );
176
* Returns all intersecting Periods for the given Period which have assosiated DataValues for
177
* the given collection of DataElements and Sources.
179
* @param period the Period.
180
* @param dataElements the collection of DataElements.
181
* @param sources the collection of Sources.
182
* @return all intersecting Periods for the given Period which have assosiated DataValues for
183
* the given collection of DataElements and Sources.
185
Collection<Period> getPeriods( Period period, Collection<DataElement> dataElements, Collection<? extends Source> sources );
188
* Returns a Period of type Relative. The Period will be persisted if it does
191
* @param date the date defining the base month for the Period generation.
192
* @param startMonths the number of months of which to add to or subtract from the
194
* @param endMonths the number of months of which to add to or subtract from the
196
* @throws IllegalArgumentException if start months is equal to or greater than
198
* @return a Period of type Relative.
200
Period getRelativePeriod( Date date, int startMonths, int endMonths );
203
* Returns a Period of type Relative. The Period will be persisted if it does
206
* @param date the date indicating in which month the start date will be. The
207
* start date is always the first day in the month.
208
* @param months the number of months the period will span. A positive value
209
* will return a period with current month's start date as start date
210
* and the month ( value - 1 ) months ahead in time's end date as end
211
* date. A negative value will return a period with current month's end
212
* date as end date and the month ( value - 1 ) months back in time's
213
* start date as start date.
214
* @throws IllegalArgumentException if 0 is passed as second argument.
215
* @return a Period of type Relative.
217
Period getRelativePeriod( Date date, int months );
219
// -------------------------------------------------------------------------
221
// -------------------------------------------------------------------------
224
* Returns a PeriodType.
226
* @param id the id of the PeriodType to return.
227
* @return the PeriodType with the given id, or null if no match.
229
PeriodType getPeriodType( int id );
232
* Returns all PeriodTypes.
234
* @return a list of all PeriodTypes, or an empty list if there are no
235
* PeriodTypes. The PeriodTypes have a natural order.
237
List<PeriodType> getAllPeriodTypes();
240
* Returns a PeriodType with a given name.
242
* @param name the name of the PeriodType to return.
243
* @return the PeriodType with the given name, or null if no match.
245
PeriodType getPeriodTypeByName( String name );