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
@@ -8,6 +8,9 @@ using MongoDB.Driver;
namespace adas_core.Infrastructure.Repositories;
/// <summary>
/// Represents a MongoDB-based repository for <see cref="PumpAlarmState"/> entities, providing concrete data access functionality defined by the <see cref="IPumpAlarmStateRepository"/> contract.
/// </summary>
public class PumpAlarmStateRepository : MongoRepository<PumpAlarmState>, IPumpAlarmStateRepository
{
private readonly ApiSettings _apiSettings;
@@ -20,10 +23,14 @@ public class PumpAlarmStateRepository : MongoRepository<PumpAlarmState>, IPumpAl
/// <summary>
/// Gets the collection name for the pump alarm state, returning the value configured in the API settings or the default "pump_alarm_state" when the configuration is not set.
/// </summary>
/// <returns>The configured collection name, or the default "pump_alarm_state" if the API setting is null.</returns>
public override string GetCollectionName()
{
return _apiSettings.PumpAlarmState ?? "pump_alarm_state";
}
{
return _apiSettings.PumpAlarmState ?? "pump_alarm_state";
}
public override async Task CreateIndexes()
{
@@ -51,18 +58,27 @@ public class PumpAlarmStateRepository : MongoRepository<PumpAlarmState>, IPumpAl
await Collection.Indexes.CreateManyAsync(indexModels);
}
/// <summary>
/// Retrieves the first active <see cref="PumpAlarmState"/> matching the specified device and optional alarm criteria.
/// The filter is always constrained by <paramref name="deviceId"/>, and additionally by <paramref name="alarmType"/> and <paramref name="alarmCodeMdc"/> when those values are provided.
/// Returns <c>null</c> when no matching alarm state is found.
/// </summary>
/// <param name="deviceId">The identifier of the device whose alarm state should be retrieved. Always applied to the query filter.</param>
/// <param name="alarmType">The optional alarm type used to further narrow the filter. When <c>null</c>, the alarm type is not applied.</param>
/// <param name="alarmCodeMdc">The optional alarm code (MDC) used to further narrow the filter. Ignored when <c>null</c>, empty, or whitespace.</param>
/// <returns>A <see cref="PumpAlarmState"/> instance if a matching record is found; otherwise, <c>null</c>.</returns>
public async Task<PumpAlarmState?> FindActiveAsync(string deviceId, PumpEnum.AlarmType? alarmType, string? alarmCodeMdc = null)
{
var filter = Builders<PumpAlarmState>.Filter.Eq(x => x.DeviceId, deviceId);
if (alarmType.HasValue)
filter &= Builders<PumpAlarmState>.Filter.Eq(x => x.AlarmType, alarmType);
if (!string.IsNullOrWhiteSpace(alarmCodeMdc))
filter &= Builders<PumpAlarmState>.Filter.Eq(x => x.AlarmCodeMdc, alarmCodeMdc);
return await Collection.Find(filter).FirstOrDefaultAsync();
}
{
var filter = Builders<PumpAlarmState>.Filter.Eq(x => x.DeviceId, deviceId);
if (alarmType.HasValue)
filter &= Builders<PumpAlarmState>.Filter.Eq(x => x.AlarmType, alarmType);
if (!string.IsNullOrWhiteSpace(alarmCodeMdc))
filter &= Builders<PumpAlarmState>.Filter.Eq(x => x.AlarmCodeMdc, alarmCodeMdc);
return await Collection.Find(filter).FirstOrDefaultAsync();
}
public async Task UpsertActiveAsync(PumpAlarmState state)
{
@@ -87,34 +103,56 @@ public class PumpAlarmStateRepository : MongoRepository<PumpAlarmState>, IPumpAl
}
/// <summary>
/// Removes pump alarm state records from the collection that match the specified device identifier, optionally narrowed by alarm type and/or alarm code MDC.
/// </summary>
/// <param name="deviceId">The identifier of the device whose alarm state records should be removed. Used as a mandatory filter criterion.</param>
/// <param name="alarmType">The optional alarm type to further restrict which records are deleted. When <see langword="null"/>, records of any alarm type for the device are removed.</param>
/// <param name="alarmCodeMdc">The optional alarm code MDC used to further narrow the deletion. Blank or whitespace values are ignored.</param>
public async Task RemoveAsync(string? deviceId, PumpEnum.AlarmType? alarmType, string? alarmCodeMdc = null)
{
var filter = Builders<PumpAlarmState>.Filter.Eq(x => x.DeviceId, deviceId);
if (alarmType.HasValue)
filter &= Builders<PumpAlarmState>.Filter.Eq(x => x.AlarmType, alarmType);
if (!string.IsNullOrWhiteSpace(alarmCodeMdc))
filter &= Builders<PumpAlarmState>.Filter.Eq(x => x.AlarmCodeMdc, alarmCodeMdc);
await Collection.DeleteManyAsync(filter);
}
{
var filter = Builders<PumpAlarmState>.Filter.Eq(x => x.DeviceId, deviceId);
if (alarmType.HasValue)
filter &= Builders<PumpAlarmState>.Filter.Eq(x => x.AlarmType, alarmType);
if (!string.IsNullOrWhiteSpace(alarmCodeMdc))
filter &= Builders<PumpAlarmState>.Filter.Eq(x => x.AlarmCodeMdc, alarmCodeMdc);
await Collection.DeleteManyAsync(filter);
}
/// <summary>
/// Asynchronously deletes all records associated with the specified patient identifier by removing every document whose <c>PatientId</c> matches the supplied value.
/// </summary>
/// <param name="patientId">The unique identifier of the patient whose associated records should be removed.</param>
public async Task DeleteByPatientId(ObjectId patientId)
{
await Collection.DeleteManyAsync(p => p.PatientId == patientId);
}
{
await Collection.DeleteManyAsync(p => p.PatientId == patientId);
}
/// <summary>
/// Asynchronously retrieves all pump alarm states associated with the specified device identifier.
/// </summary>
/// <param name="deviceId">The unique identifier of the device whose pump alarm states are being queried.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains an <see cref="IEnumerable{PumpAlarmState}"/> with the pump alarm states matching the provided device identifier.</returns>
public async Task<IEnumerable<PumpAlarmState>> FindAllActiveByDeviceAsync(string deviceId)
{
return await Collection.Find(x => x.DeviceId == deviceId).ToListAsync();
}
{
return await Collection.Find(x => x.DeviceId == deviceId).ToListAsync();
}
/// <summary>
/// Asynchronously updates all <see cref="PumpAlarmState"/> documents that match the specified <paramref name="oldId"/> on the given <paramref name="fieldName"/>, replacing the value with <paramref name="newId"/>. Used to bulk rewire <see cref="MongoDB.Bson.ObjectId"/> references stored on a dynamic field.
/// </summary>
/// <param name="fieldName">Name of the document field to filter and update.</param>
/// <param name="newId">The new <see cref="MongoDB.Bson.ObjectId"/> value to assign to the field.</param>
/// <param name="oldId">The existing <see cref="MongoDB.Bson.ObjectId"/> value used to locate matching documents.</param>
/// <returns>The number of documents that were modified by the update operation.</returns>
public async Task<long> UpdateManyObjectIdByFieldNameAsync(string fieldName, ObjectId newId, ObjectId oldId)
{
var filter = Builders<PumpAlarmState>.Filter.Eq(fieldName, oldId);
var update = Builders<PumpAlarmState>.Update.Set(fieldName, newId);
var result = await Collection.UpdateManyAsync(filter, update);
return result.ModifiedCount;
}
{
var filter = Builders<PumpAlarmState>.Filter.Eq(fieldName, oldId);
var update = Builders<PumpAlarmState>.Update.Set(fieldName, newId);
var result = await Collection.UpdateManyAsync(filter, update);
return result.ModifiedCount;
}
}