=== Summary: 675 files | 7 generated | 484 fresh | 4605 untracked | 4268 adopted | 355 marked | 466 validated-ok | 2+0 stale (sig+body) | 0 skipped | 0 failed | elapsed 11:08:11.442 (40091.44s) ===

This commit is contained in:
julian
2026-06-28 02:50:05 -07:00
parent a19fb90902
commit 586f02a2ca
654 changed files with 5260 additions and 0 deletions
@@ -17,6 +17,8 @@ namespace adas_core.Infrastructure.Repositories
/// As a specialized repository inheriting from <see cref="MongoRepository{PumpObservation}"/>, this class
/// reuses the base MongoDB storage capabilities while exposing the pump observation-specific repository contract.
/// </remarks>
/// <!-- aidoc-review:v1 severity=medium kind=extra_param
/// "The <typeparam name=\"PumpObservation\"> tag is incorrect: PumpObservationRepository is not a generic class, so it has no type parameters." -->
public class PumpObservationRepository : MongoRepository<PumpObservation>, IPumpObservationRepository
{
private readonly ApiSettings _apiSettings;
@@ -38,6 +40,7 @@ namespace adas_core.Infrastructure.Repositories
/// Retrieves the collection name used for pump observations, returning the configured value from API settings if available, or falling back to the default "pump_observations" name when no custom configuration is provided.
/// </summary>
/// <returns>The configured pump observations collection name from API settings, or the default "pump_observations" string if the setting is null.</returns>
/// <!-- aidoc:v1 sig=94e22ff body=711309f -->
public override string GetCollectionName()
{
return _apiSettings.PumpObservations ?? "pump_observations";
@@ -77,6 +80,7 @@ namespace adas_core.Infrastructure.Repositories
/// Asynchronously inserts a pump observation into the underlying collection.
/// </summary>
/// <param name="obs">The pump observation document to be persisted.</param>
/// <!-- aidoc:v1 sig=2e9b63d body=ff40c9a -->
public async Task InsertAsync(PumpObservation obs)
{
await Collection.InsertOneAsync(obs);
@@ -86,6 +90,7 @@ namespace adas_core.Infrastructure.Repositories
/// Inserts a batch of pump observations into the underlying collection in a single operation. Returns immediately when the input is null or contains no elements, performing no insertion in those cases.
/// </summary>
/// <param name="observations">The pump observations to insert. A null or empty collection results in a no-op.</param>
/// <!-- aidoc:v1 sig=9b8dfd0 body=13df81e -->
public async Task InsertManyAsync(IEnumerable<PumpObservation>? observations)
{
if (observations == null) return;
@@ -104,6 +109,7 @@ namespace adas_core.Infrastructure.Repositories
/// <param name="to">Optional end timestamp; when provided, only observations with a time less than or equal to this value are returned.</param>
/// <param name="limit">Optional maximum number of observations to return; when not provided, all matching observations are returned.</param>
/// <returns>A task that represents the asynchronous operation, containing the collection of matching <see cref="PumpObservation"/> records.</returns>
/// <!-- aidoc:v1 sig=c4c17bd body=fccb1f4 -->
public async Task<IEnumerable<PumpObservation>> FindByDeviceIdAsync(
string deviceId,
DateTime? from = null,
@@ -136,6 +142,7 @@ namespace adas_core.Infrastructure.Repositories
/// <param name="to">Optional inclusive upper bound for the observation time. When null, no upper time bound is applied.</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 the matching pump observations sorted by time in descending order.</returns>
/// <!-- aidoc:v1 sig=7a9379f body=b1db477 -->
public async Task<IEnumerable<PumpObservation>> FindByPatientAsync(
ObjectId patientId,
DateTime? from = null,
@@ -205,6 +212,7 @@ namespace adas_core.Infrastructure.Repositories
/// </summary>
/// <param name="deviceId">The unique identifier of the device whose latest pump observation should be retrieved.</param>
/// <returns>A task that resolves to the most recent <see cref="PumpObservation"/> for the device, or <c>null</c> if no observation is found.</returns>
/// <!-- aidoc:v1 sig=c025146 body=088b34a -->
public async Task<PumpObservation?> FindLastByDeviceIdAsync(string deviceId)
{
return await Collection
@@ -218,6 +226,7 @@ namespace adas_core.Infrastructure.Repositories
/// </summary>
/// <param name="patientId">The optional patient identifier used to filter the pump observations.</param>
/// <returns>A task that represents the asynchronous operation, containing a collection of pump observations matching the given patient identifier.</returns>
/// <!-- aidoc:v1 sig=db5b147 body=51d8815 -->
public async Task<IEnumerable<PumpObservation>> FindByPatientId(ObjectId? patientId)
{
return await Collection.Find(x => x.PatientId == patientId).ToListAsync();
@@ -230,6 +239,7 @@ namespace adas_core.Infrastructure.Repositories
/// <param name="patientId">The identifier of the patient whose observations are being retrieved.</param>
/// <param name="num">The maximum number of observations to consider before deduplication. Defaults to 100.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains a list of distinct <see cref="PumpObservation"/> entries for the patient, ordered from most recent to oldest.</returns>
/// <!-- aidoc:v1 sig=0c8097f body=4281403 -->
public async Task<List<PumpObservation>> AggregatedPatientLastObservations(ObjectId patientId, int num = 100)
{
var filterBuilder = Builders<PumpObservation>.Filter;
@@ -252,6 +262,7 @@ namespace adas_core.Infrastructure.Repositories
/// Deletes all records whose <c>PatientId</c> matches the specified patient identifier.
/// </summary>
/// <param name="patientId">The patient identifier whose associated records should be removed; may be <c>null</c>.</param>
/// <!-- aidoc:v1 sig=e8c536a body=395df12 -->
public async Task DeleteByPatientId(ObjectId? patientId)
{
await Collection.DeleteManyAsync(x => x.PatientId == patientId);
@@ -264,6 +275,7 @@ namespace adas_core.Infrastructure.Repositories
/// <param name="days">The age threshold in days. Observations with a <c>Time</c> older than <c>DateTime.UtcNow - days</c> are eligible for deletion.</param>
/// <param name="name">Optional name used to further restrict the deletion to observations with a matching <c>Name</c> value. If null or empty, the name filter is not applied.</param>
/// <returns>The number of <see cref="PumpObservation"/> documents that were deleted.</returns>
/// <!-- aidoc:v1 sig=102a371 body=9c5bcf4 -->
public async Task<long> DeleteOlderThanDaysAsync(int days, string? name = null)
{
var limitDate = DateTime.UtcNow.AddDays(-days);
@@ -281,6 +293,7 @@ namespace adas_core.Infrastructure.Repositories
/// </summary>
/// <param name="maxCount">The maximum number of most recent records to keep per device.</param>
/// <returns>The total number of observations deleted across all devices.</returns>
/// <!-- aidoc:v1 sig=295122a body=e030407 -->
public async Task<long> DeleteKeepLastNAsync(int maxCount)
{
// Para cada DeviceId:
@@ -320,6 +333,7 @@ namespace adas_core.Infrastructure.Repositories
/// <param name="oldId">The current <see cref="ObjectId"/> value used to match documents; if <c>null</c>, the filter matches documents where the field is null.</param>
/// <returns>The number of documents that were modified by the update operation.</returns>
/// <exception cref="ArgumentException">Thrown when <paramref name="fieldName"/> is null, empty, or whitespace.</exception>
/// <!-- aidoc:v1 sig=260cb78 body=f2c2192 -->
public async Task<long> UpdateManyObjectIdByFieldAsync(string fieldName, ObjectId newId, ObjectId? oldId)
{
if (string.IsNullOrWhiteSpace(fieldName))
@@ -386,6 +400,7 @@ namespace adas_core.Infrastructure.Repositories
/// <param name="patientId">The unique identifier of the patient whose observations are being queried.</param>
/// <param name="name">The name of the pump observation to filter by. If null, empty, or whitespace, an empty list is returned.</param>
/// <returns>A task representing the asynchronous operation, containing a list of the matching pump observations (at most two) sorted from newest to oldest.</returns>
/// <!-- aidoc:v1 sig=2ba6244 body=efdef74 -->
public async Task<List<PumpObservation>> FindLastObservations(ObjectId patientId, string name)
{
if (string.IsNullOrWhiteSpace(name))