rama creada apartir de master en j

This commit is contained in:
jrojas
2026-06-26 10:29:23 +02:00
parent 319fd3dfb0
commit c1517fda87
2810 changed files with 1927392 additions and 25392 deletions
@@ -57,42 +57,62 @@ namespace adas_core.Infrastructure.Repositories
await Collection.Indexes.CreateManyAsync(indexModels);
}
/// <summary>
/// Asynchronously inserts a <see cref="PumpObservation"/> into the underlying MongoDB collection.
/// </summary>
/// <param name="obs">The pump observation to persist.</param>
public async Task InsertAsync(PumpObservation obs)
{
await Collection.InsertOneAsync(obs);
}
{
await Collection.InsertOneAsync(obs);
}
/// <summary>
/// Asynchronously inserts a batch of pump observations into the underlying data store. If the collection is empty, the method completes without performing any insertion.
/// </summary>
/// <param name="observations">The pump observations to insert into the collection.</param>
public async Task InsertManyAsync(IEnumerable<PumpObservation> observations)
{
var list = observations as IList<PumpObservation> ?? observations.ToList();
if (list.Count == 0) return;
await Collection.InsertManyAsync(list);
}
{
var list = observations as IList<PumpObservation> ?? observations.ToList();
if (list.Count == 0) return;
await Collection.InsertManyAsync(list);
}
/// <summary>
/// Retrieves a collection of <see cref="PumpObservation"/> records for a specific patient, optionally filtered by a time range and limited in count, sorted by time in descending order.
/// </summary>
/// <param name="patientId">The identifier of the patient whose pump observations are being queried.</param>
/// <param name="from">Optional inclusive lower bound for the observation time. When provided, only observations on or after this time are returned.</param>
/// <param name="to">Optional inclusive upper bound for the observation time. When provided, only observations on or before this time are returned.</param>
/// <param name="limit">Optional maximum number of observations to return. When null, all matching observations are returned.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains an <see cref="IEnumerable{PumpObservation}"/> of matching observations ordered from newest to oldest.</returns>
public async Task<IEnumerable<PumpObservation>> FindByPatientIdAsync(
ObjectId patientId, DateTime? from = null, DateTime? to = null, int? limit = null)
{
var filter = Builders<PumpObservation>.Filter.Eq(x => x.PatientId, patientId);
if (from.HasValue)
filter &= Builders<PumpObservation>.Filter.Gte(x => x.Time, from.Value);
if (to.HasValue)
filter &= Builders<PumpObservation>.Filter.Lte(x => x.Time, to.Value);
var query = Collection.Find(filter).SortByDescending(x => x.Time);
if (limit.HasValue)
query = query.Limit(limit.Value) as IOrderedFindFluent<PumpObservation, PumpObservation>;
return await query.ToListAsync();
}
ObjectId patientId, DateTime? from = null, DateTime? to = null, int? limit = null)
{
var filter = Builders<PumpObservation>.Filter.Eq(x => x.PatientId, patientId);
if (from.HasValue)
filter &= Builders<PumpObservation>.Filter.Gte(x => x.Time, from.Value);
if (to.HasValue)
filter &= Builders<PumpObservation>.Filter.Lte(x => x.Time, to.Value);
var query = Collection.Find(filter).SortByDescending(x => x.Time);
if (limit.HasValue)
query = query.Limit(limit.Value) as IOrderedFindFluent<PumpObservation, PumpObservation>;
return await query.ToListAsync();
}
/// <summary>
/// Deletes all pump observations whose recording time is earlier than the specified cutoff date.
/// </summary>
/// <param name="addDays">The cutoff date; observations with a timestamp before this value are removed.</param>
public async Task DeleteBeforeDate(DateTime addDays)
{
var filter = Builders<PumpObservation>.Filter.Lt(x => x.Time, addDays);
await Collection.DeleteManyAsync(filter);
}
{
var filter = Builders<PumpObservation>.Filter.Lt(x => x.Time, addDays);
await Collection.DeleteManyAsync(filter);
}
}
}