=== 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
@@ -16,6 +16,7 @@ namespace adas_core.Infrastructure.Repositories;
/// <summary>
/// Represents a MongoDB-backed repository for <see cref="PointOfCare"/> entities, providing the persistence operations defined by the <see cref="IPointOfCareRepository"/> interface.
/// </summary>
/// <!-- aidoc:v1 sig=47f85a2 -->
public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareRepository
{
private readonly ApiSettings _apiSettings;
@@ -41,6 +42,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// Retrieves the collection name used for Locations operations from the API settings configuration.
/// </summary>
/// <returns>The configured Locations collection name retrieved from the API settings.</returns>
/// <!-- aidoc:v1 sig=94e22ff body=3c89cf4 -->
public override string GetCollectionName()
{
return _apiSettings.Locations;
@@ -51,6 +53,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// If the base insert operation fails, the exception is written to the console and logged, then rethrown to preserve the original failure.
/// </summary>
/// <param name="pointOfCare">The <see cref="PointOfCare"/> entity to insert.</param>
/// <!-- aidoc:v1 sig=fb673ff body=2d2093f -->
public override async Task InsertOneAsync(PointOfCare pointOfCare)
{
try
@@ -70,6 +73,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// Any exception encountered during the delete operation is logged and rethrown to the caller.
/// </summary>
/// <param name="id">The unique identifier of the <see cref="PointOfCare"/> entity to remove.</param>
/// <!-- aidoc:v1 sig=3de1ad6 body=f09ede6 -->
public async Task Delete(ObjectId id)
{
try
@@ -90,6 +94,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// </summary>
/// <param name="unitId">The identifier of the unit whose related <see cref="PointOfCare"/> records should be removed.</param>
/// <returns>A task that resolves to <c>true</c> when the records are deleted, or <c>false</c> when an error occurs during the operation.</returns>
/// <!-- aidoc:v1 sig=be3448b body=d89d1ff -->
public async Task<bool> DeleteManyByUnitId(ObjectId unitId)
{
try
@@ -110,6 +115,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// Updates an existing PointOfCare entity asynchronously in the data store.
/// </summary>
/// <param name="pointOfCare">The PointOfCare entity to update, identified by its Id.</param>
/// <!-- aidoc:v1 sig=f80d98a body=9bbdcdc -->
public async Task Update(PointOfCare pointOfCare)
{
try
@@ -128,6 +134,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// </summary>
/// <param name="id">The ObjectId of the PointOfCare document to update.</param>
/// <param name="unit">The Unit object whose Name and Id values will be set on the matching document.</param>
/// <!-- aidoc:v1 sig=d74e094 body=6b7a6b3 -->
public async Task UpdateUnitId(ObjectId id, Unit unit)
{
var filterBuilder = Builders<PointOfCare>.Filter;
@@ -146,6 +153,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// </summary>
/// <param name="pocId">The unique identifier of the Point of Care whose relay configuration will be updated.</param>
/// <param name="relayConfig">The collection of relays whose identifiers will be stored as the new relay configuration.</param>
/// <!-- aidoc:v1 sig=598eb3a body=e78ac25 -->
public async Task UpdateRelayConfig(ObjectId pocId, List<Relay> relayConfig)
{
var filterBuilder = Builders<PointOfCare>.Filter;
@@ -161,6 +169,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// </summary>
/// <param name="pocId">The identifier of the point of care whose relay configuration will be updated.</param>
/// <param name="relayConfig">The new list of relay identifiers to assign to the point of care's configuration.</param>
/// <!-- aidoc:v1 sig=784ef54 body=8ee7aff -->
public async Task UpdateRelayConfig(ObjectId pocId, List<ObjectId> relayConfig)
{
var filterBuilder = Builders<PointOfCare>.Filter;
@@ -176,6 +185,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// </summary>
/// <param name="id">The unique identifier of the <see cref="PointOfCare"/> entity to update.</param>
/// <param name="configuration">The new configuration values to apply to the entity.</param>
/// <!-- aidoc:v1 sig=1874ae4 body=c5f4db7 -->
public async Task UpdateConfiguration(ObjectId id, PointOfCareConfiguration configuration)
{
var filterBuilder = Builders<PointOfCare>.Filter;
@@ -193,6 +203,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// </summary>
/// <param name="id">The unique <see cref="ObjectId"/> of the point of care to retrieve.</param>
/// <returns>A <see cref="PointOfCare"/> if a matching record is found; otherwise, <c>null</c>.</returns>
/// <!-- aidoc:v1 sig=2826028 body=1db2247 -->
public async Task<PointOfCare?> FindById(ObjectId id)
{
try
@@ -215,6 +226,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// <param name="status">The point of care status used to filter the results.</param>
/// <param name="excludeVirtual">When <c>true</c>, filters out entries whose bed matches one of the known <see cref="VirtualPointOfCare"/> values; otherwise virtual entries are included.</param>
/// <returns>A task that resolves to an <see cref="IEnumerable{PointOfCare}"/> containing the matching entries, or an empty collection if the query fails.</returns>
/// <!-- aidoc:v1 sig=66efb59 body=346b01e -->
public async Task<IEnumerable<PointOfCare>> FindByUnitAndStatus(ObjectId unitId, StatusEnum.PointOfCare status,
bool excludeVirtual = false)
{
@@ -292,6 +304,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// </summary>
/// <param name="unit">The identifier of the unit whose points of care should be retrieved.</param>
/// <returns>A task that yields a collection of <see cref="PointOfCare"/> instances matching the given unit, or <c>null</c> if the search fails.</returns>
/// <!-- aidoc:v1 sig=1265646 body=709d354 -->
public async Task<IEnumerable<PointOfCare>?> FindAllByUnitId(ObjectId unit)
{
try
@@ -314,6 +327,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// </summary>
/// <param name="room">The room identifier used to filter the point-of-care records.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains a collection of matching <see cref="PointOfCare"/> entries, or <see langword="null"/> if the search fails.</returns>
/// <!-- aidoc:v1 sig=d9b8bd7 body=11151e4 -->
public async Task<IEnumerable<PointOfCare>?> FindByRoom(string room)
{
try
@@ -336,6 +350,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// </summary>
/// <param name="bed">The bed identifier used to filter the point of care records.</param>
/// <returns>A task containing an enumerable collection of matching <see cref="PointOfCare"/> records, or null if an error occurs.</returns>
/// <!-- aidoc:v1 sig=27196b1 body=358ac53 -->
public async Task<IEnumerable<PointOfCare>?> FindByBed(string bed)
{
try
@@ -359,6 +374,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// <param name="filter">The MongoDB filter definition used to match the desired <see cref="PointOfCare"/> documents.</param>
/// <param name="projection">An optional projection definition to limit or transform the fields returned in each document. When <c>null</c>, the full documents are returned.</param>
/// <returns>A task that represents the asynchronous operation, containing a list of <see cref="PointOfCare"/> documents that match the filter.</returns>
/// <!-- aidoc:v1 sig=18993a9 body=c2bab2a -->
public async Task<List<PointOfCare>> FindByFilter(FilterDefinition<PointOfCare> filter,
ProjectionDefinition<PointOfCare>? projection = null)
{
@@ -372,6 +388,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// </summary>
/// <param name="unitId">The identifier of the unit whose point-of-care entries should be counted.</param>
/// <returns>A <see cref="Task{Int64}"/> that resolves to the number of matching point-of-care documents for the given unit.</returns>
/// <!-- aidoc:v1 sig=baa8175 body=a7b09ba -->
public async Task<long> CountByUnitId(ObjectId unitId)
{
try
@@ -446,6 +463,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// </summary>
/// <param name="pocId">The unique identifier of the point of care whose configuration is being requested.</param>
/// <returns>A <see cref="Task{PointOfCare}"/> containing the matching <see cref="PointOfCare"/> with its configuration, or <c>null</c> if no record exists for the given identifier.</returns>
/// <!-- aidoc:v1 sig=8e7499c body=da257e7 -->
public async Task<PointOfCare?> GetPoCConfiguration(ObjectId pocId)
{
var filter = Builders<PointOfCare>.Filter.Eq(p => p.Id, pocId);
@@ -461,6 +479,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// Retrieves all <see cref="PointOfCare"/> records from the underlying data store using an empty filter.
/// </summary>
/// <returns>A <see cref="Task{TResult}"/> containing a <see cref="List{T}"/> of <see cref="PointOfCare"/> items, or <c>null</c> when no results are returned.</returns>
/// <!-- aidoc:v1 sig=54c1971 body=b4b56a0 -->
public async Task<List<PointOfCare>?> GetAll()
{
var filter = Builders<PointOfCare>.Filter.Empty;
@@ -472,6 +491,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// </summary>
/// <param name="id">The unique identifier of the point of care to retrieve.</param>
/// <returns>A task that represents the asynchronous operation, containing the matching <see cref="PointOfCare"/> with its resolved beacon, camera, and relay configuration, or <c>null</c> if not found.</returns>
/// <!-- aidoc:v1 sig=3a998f5 body=6d67850 -->
public async Task<PointOfCare?> FindByIdAllConfig(ObjectId id)
{
return await Collection.Aggregate()
@@ -515,6 +535,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// contra el total de cámaras en uso, independientemente del volumen de datos.
/// </remarks>
/// <returns>Un conjunto hash con los <see cref="ObjectId"/> de las cámaras en uso.</returns>
/// <!-- aidoc:v1 sig=f6346fe body=c7c2683 -->
public async Task<HashSet<ObjectId>> FindAllIdCamerasInUse()
{
var distinctIds = await Collection
@@ -527,6 +548,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// Retrieves all distinct beacon identifiers currently referenced by any point-of-care configuration.
/// </summary>
/// <returns>A set containing the unique <see cref="ObjectId"/> values of beacons in use across all point-of-care records.</returns>
/// <!-- aidoc:v1 sig=7e41dd8 body=2dfc33a -->
public async Task<HashSet<ObjectId>> FindAllIdBeaconsInUse()
{
var distinctIds = await Collection
@@ -541,6 +563,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// </summary>
/// <param name="unitId">The identifier of the unit used to filter the points of care.</param>
/// <returns>A task that returns a collection of PointOfCare with their associated device lists populated, or null if an error occurs during the query.</returns>
/// <!-- aidoc:v1 sig=74ce5ed body=bc6b30b -->
public async Task<IEnumerable<PointOfCare>?> FindAllByUnitIdWithDevices(ObjectId unitId)
{
try
@@ -592,6 +615,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// Retrieves the set of distinct relay identifiers currently referenced by any <see cref="PointOfCare"/> configuration in the collection.
/// </summary>
/// <returns>A <see cref="HashSet{T}"/> of <see cref="ObjectId"/> values containing all unique relay IDs found across the <c>configuration.relayIdList</c> field of every document.</returns>
/// <!-- aidoc:v1 sig=7d4add8 body=4904eff -->
public async Task<HashSet<ObjectId>> FindAllIdRelaysInUse()
{
var distinctIds = await Collection
@@ -605,6 +629,8 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// Retrieves all point-of-care configurations, joining each configuration with its associated light beacons, cameras, and relays through MongoDB lookups and projecting the combined result into a flattened <see cref="PointOfCare"/> structure.
/// </summary>
/// <returns>A task that resolves to a list of <see cref="PointOfCare"/> objects enriched with the corresponding beacon, camera, and relay details, or <c>null</c> when no configurations are found.</returns>
/// <!-- aidoc-review:v1 severity=medium kind=wrong_returns
/// "Documentation states the method returns 'null when no configurations are found', but the implementation uses pipeline.ToListAsync() which returns an empty list (not null) when no documents exist. The nullable return type annotation does not match the actual runtime behavior." -->
public async Task<List<PointOfCare>?> GetAllConfigs()
{
var pipeline = Collection.Aggregate()
@@ -655,6 +681,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// Uses an empty filter to return every record and returns a nullable list that may be null if no results are found.
/// </summary>
/// <returns>A task that represents the asynchronous operation, containing a list of <see cref="PointOfCare"/> objects with the projected fields, or <c>null</c> if no matching records exist.</returns>
/// <!-- aidoc:v1 sig=7d0cd41 body=44afaf5 -->
public async Task<List<PointOfCare>?> GetAllLocationInfo()
{
var filter = Builders<PointOfCare>.Filter.Empty;
@@ -675,6 +702,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// </summary>
/// <param name="filter">The pagination and filtering criteria. If <c>FilteredRequest</c> is null, no additional filters are applied.</param>
/// <returns>An <see cref="IFindFluent{PointOfCare, PointOfCare}"/> representing the resulting MongoDB query with the applied filters and sort.</returns>
/// <!-- aidoc:v1 sig=63378f1 body=ab03c99 -->
public IFindFluent<PointOfCare, PointOfCare> GetPaginatedPoCs(PaginationFilter filter)
{
var filterBuilder = Builders<PointOfCare>.Filter;
@@ -742,6 +770,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// <summary>
/// Creates MongoDB indexes for the <see cref="PointOfCare"/> collection on the <c>unitId</c>, <c>room</c>, and <c>bed</c> fields, using background creation and non-unique constraints, to optimize query performance.
/// </summary>
/// <!-- aidoc:v1 sig=4955da2 body=b988d70 -->
public override async Task CreateIndexes()
{
var options = new CreateIndexOptions { Background = true, Unique = false };
@@ -760,6 +789,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// </summary>
/// <param name="id">The unique identifier of the point-of-care record to update.</param>
/// <param name="status">The new status value to apply to the point-of-care record.</param>
/// <!-- aidoc:v1 sig=ad30072 body=87cbbaf -->
public async Task UpdateStatus(ObjectId id, StatusEnum.PointOfCare status)
{
var filterBuilder = Builders<PointOfCare>.Filter;
@@ -777,6 +807,7 @@ public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareR
/// <param name="filters">The list of filter definitions to be combined; an empty list results in no filtering.</param>
/// <param name="sort">The sort definition applied to the resulting query.</param>
/// <returns>An <see cref="IFindFluent{PointOfCare, PointOfCare}"/> representing the filtered and sorted query.</returns>
/// <!-- aidoc:v1 sig=76fee2f body=51d06bc -->
private IFindFluent<PointOfCare, PointOfCare> CreateFindFluent(List<FilterDefinition<PointOfCare>> filters,
SortDefinition<PointOfCare> sort)
{