Removed redundant and not used code at TreatmentEntryAccessor.

This commit is contained in:
eduardopietre 2022-01-12 15:39:44 -03:00 committed by Johan Degraeve
parent d1c8fbbee6
commit 6f391432c2
1 changed files with 0 additions and 41 deletions

View File

@ -85,9 +85,7 @@ class TreatmentEntryAccessor {
/// - returns: an array with treatments, can be empty array.
/// Order by timestamp, descending meaning the treatment at index 0 is the youngest
func getLatestTreatments(limit:Int?, fromDate:Date?) -> [TreatmentEntry] {
return fetchTreatments(limit: limit, fromDate: fromDate)
}
/// gets last treatment
@ -100,45 +98,6 @@ class TreatmentEntryAccessor {
}
}
/// gets treatments, synchronously, in the managedObjectContext's thread
/// - returns:
/// treatments sorted by timestamp, ascending (ie first is oldest)
/// - parameters:
/// - to : if specified, only return treatments with timestamp smaller than fromDate (not equal to)
/// - from : if specified, only return treatments with timestamp greater than fromDate (not equal to)
/// - managedObjectContext : the ManagedObjectContext to use
func getTreatments(from: Date?, to: Date?, on managedObjectContext: NSManagedObjectContext) -> [TreatmentEntry] {
let fetchRequest: NSFetchRequest<TreatmentEntry> = TreatmentEntry.fetchRequest()
fetchRequest.sortDescriptors = [NSSortDescriptor(key: #keyPath(TreatmentEntry.date), ascending: true)]
// create predicate
if let from = from, to == nil {
let predicate = NSPredicate(format: "date > %@", from as NSDate)
fetchRequest.predicate = predicate
} else if let to = to, from == nil {
let predicate = NSPredicate(format: "date < %@", to as NSDate)
fetchRequest.predicate = predicate
} else if let to = to, let from = from {
let predicate = NSPredicate(format: "date < %@ AND date > %@", to as NSDate, from as NSDate)
fetchRequest.predicate = predicate
}
var treatments: [TreatmentEntry] = []
managedObjectContext.performAndWait {
do {
// Execute Fetch Request
treatments = try fetchRequest.execute()
} catch {
let fetchError = error as NSError
trace("in getTreatments, Unable to Execute BgReading Fetch Request : %{public}@", log: self.log, category: ConstantsLog.categoryApplicationDataTreatments, type: .error, fetchError.localizedDescription)
}
}
return treatments
}
/// deletes treatmentEntry, synchronously, in the managedObjectContext's thread
/// - treatmentEntry : treatmentEntry to delete
/// - managedObjectContext : the ManagedObjectContext to use