Table of Contents

Class PointOfCareRepository

Namespace
adas_core.Infrastructure.Repositories
Assembly
adas-core.Infrastructure.dll

Represents a MongoDB-backed repository for PointOfCare entities, providing the persistence operations defined by the IPointOfCareRepository interface.

public class PointOfCareRepository : MongoRepository<PointOfCare>, IPointOfCareRepository, IMongoRepository<PointOfCare>
Inheritance
PointOfCareRepository
Implements
Inherited Members
Extension Methods

Constructors

PointOfCareRepository(IOptions<ApiSettings>?, IMongoDatabase)

public PointOfCareRepository(IOptions<ApiSettings>? apiSettings, IMongoDatabase database)

Parameters

apiSettings IOptions<ApiSettings>
database IMongoDatabase

Methods

CountByUnitId(ObjectId)

Asynchronously counts the number of PointOfCare documents associated with the specified unit, excluding entries whose bed is a virtual or non-representative value (Pushed, Unknown, Deleted, NoBed, Cancelled, UnitData, Recovered, or Moved).

public Task<long> CountByUnitId(ObjectId unitId)

Parameters

unitId ObjectId

The identifier of the unit whose point-of-care entries should be counted.

Returns

Task<long>

A Task<TResult> that resolves to the number of matching point-of-care documents for the given unit.

CountVirtualsByUnitId(ObjectId)

Asynchronously counts the number of virtuals associated with the specified unit.

public Task<long> CountVirtualsByUnitId(ObjectId unitId)

Parameters

unitId ObjectId

The identifier of the unit whose virtuals will be counted.

Returns

Task<long>

A task that represents the asynchronous operation. The task result contains the count of virtuals for the given unit.

CreateIndexes()

Creates MongoDB indexes for the PointOfCare collection on the unitId, room, and bed fields, using background creation and non-unique constraints, to optimize query performance.

public override Task CreateIndexes()

Returns

Task

Delete(ObjectId)

Deletes the PointOfCare entity matching the specified id from the underlying collection. Any exception encountered during the delete operation is logged and rethrown to the caller.

public Task Delete(ObjectId id)

Parameters

id ObjectId

The unique identifier of the PointOfCare entity to remove.

Returns

Task

DeleteManyByUnitId(ObjectId)

Deletes all PointOfCare records associated with the specified unit identifier. Returns true if the deletion completes successfully, or false if an exception is caught and logged.

public Task<bool> DeleteManyByUnitId(ObjectId unitId)

Parameters

unitId ObjectId

The identifier of the unit whose related PointOfCare records should be removed.

Returns

Task<bool>

A task that resolves to true when the records are deleted, or false when an error occurs during the operation.

FindAllByUnitId(ObjectId)

Retrieves all points of care associated with the specified unit. If an error occurs during the search, the exception is logged and null is returned.

public Task<IEnumerable<PointOfCare>?> FindAllByUnitId(ObjectId unit)

Parameters

unit ObjectId

The identifier of the unit whose points of care should be retrieved.

Returns

Task<IEnumerable<PointOfCare>>

A task that yields a collection of PointOfCare instances matching the given unit, or null if the search fails.

FindAllByUnitIdWithDevices(ObjectId)

Retrieves all points of care associated with the specified unit, including their related beacons, cameras, and relays resolved through MongoDB lookups and projected to the PointOfCare model.

public Task<IEnumerable<PointOfCare>?> FindAllByUnitIdWithDevices(ObjectId unitId)

Parameters

unitId ObjectId

The identifier of the unit used to filter the points of care.

Returns

Task<IEnumerable<PointOfCare>>

A task that returns a collection of PointOfCare with their associated device lists populated, or null if an error occurs during the query.

FindAllIdBeaconsInUse()

Retrieves all distinct beacon identifiers currently referenced by any point-of-care configuration.

public Task<HashSet<ObjectId>> FindAllIdBeaconsInUse()

Returns

Task<HashSet<ObjectId>>

A set containing the unique MongoDB.Bson.ObjectId values of beacons in use across all point-of-care records.

FindAllIdCamerasInUse()

Obtiene de forma asíncrona todos los identificadores únicos de cámaras que están vinculados a algún PointOfCare.

public Task<HashSet<ObjectId>> FindAllIdCamerasInUse()

Returns

Task<HashSet<ObjectId>>

Un conjunto hash con los MongoDB.Bson.ObjectId de las cámaras en uso.

Remarks

Se retorna un HashSet<T> para optimizar la búsqueda de pertenencia (Contains) en el servicio. Mientras que una List<T> requiere un tiempo de búsqueda lineal \(O(n)\), el HashSet utiliza una tabla hash que permite verificar si una cámara está en uso en tiempo constante \(O(1)\). Esto es crítico para mantener el rendimiento al comparar los IDs de la página actual contra el total de cámaras en uso, independientemente del volumen de datos.

FindAllIdRelaysInUse()

Retrieves the set of distinct relay identifiers currently referenced by any PointOfCare configuration in the collection.

public Task<HashSet<ObjectId>> FindAllIdRelaysInUse()

Returns

Task<HashSet<ObjectId>>

A HashSet<T> of MongoDB.Bson.ObjectId values containing all unique relay IDs found across the configuration.relayIdList field of every document.

FindByBed(string)

Asynchronously finds all PointOfCare records matching the specified bed. Returns null if an error occurs during the search.

public Task<IEnumerable<PointOfCare>?> FindByBed(string bed)

Parameters

bed string

The bed identifier used to filter the point of care records.

Returns

Task<IEnumerable<PointOfCare>>

A task containing an enumerable collection of matching PointOfCare records, or null if an error occurs.

FindByBedAndUnitId(string?, ObjectId)

Asynchronously retrieves the PointOfCare associated with the specified bed within the given unit, returning null if no matching record is found.

public Task<PointOfCare?> FindByBedAndUnitId(string? bed, ObjectId unitId)

Parameters

bed string

The bed identifier used to locate the point of care; may be null.

unitId ObjectId

The identifier of the unit in which the bed is located.

Returns

Task<PointOfCare>

A Task<TResult> that yields the matching PointOfCare, or null if none is found.

FindByFilter(FilterDefinition<PointOfCare>, ProjectionDefinition<PointOfCare>?)

Finds a list of PointOfCare documents matching the specified filter, optionally applying a projection to shape the returned fields. When a projection is provided, only the projected fields are returned; otherwise, the full documents are returned.

public Task<List<PointOfCare>> FindByFilter(FilterDefinition<PointOfCare> filter, ProjectionDefinition<PointOfCare>? projection = null)

Parameters

filter FilterDefinition<PointOfCare>

The MongoDB filter definition used to match the desired PointOfCare documents.

projection ProjectionDefinition<PointOfCare>

An optional projection definition to limit or transform the fields returned in each document. When null, the full documents are returned.

Returns

Task<List<PointOfCare>>

A task that represents the asynchronous operation, containing a list of PointOfCare documents that match the filter.

FindById(ObjectId)

Retrieves a PointOfCare entity by its unique identifier from the underlying collection. Returns null if no matching entity is found or if an error occurs during the lookup.

public Task<PointOfCare?> FindById(ObjectId id)

Parameters

id ObjectId

The unique MongoDB.Bson.ObjectId of the point of care to retrieve.

Returns

Task<PointOfCare>

A PointOfCare if a matching record is found; otherwise, null.

FindByIdAllConfig(ObjectId)

Retrieves a PointOfCare by its identifier, enriching the result with the full configuration details by performing lookups against the light beacons, cameras, and relays collections. Returns null when no matching point of care is found.

public Task<PointOfCare?> FindByIdAllConfig(ObjectId id)

Parameters

id ObjectId

The unique identifier of the point of care to retrieve.

Returns

Task<PointOfCare>

A task that represents the asynchronous operation, containing the matching PointOfCare with its resolved beacon, camera, and relay configuration, or null if not found.

FindByPatientLocation(PatientLocation)

Retrieves the point of care associated with the specified patient location.

public Task<PointOfCare?> FindByPatientLocation(PatientLocation patientLocation)

Parameters

patientLocation PatientLocation

The patient location used to look up the corresponding point of care.

Returns

Task<PointOfCare>

A task that represents the asynchronous operation. The task result contains the matching PointOfCare, or null if no point of care is found for the given patient location.

FindByRoom(string)

Asynchronously retrieves all PointOfCare entities that match the specified room. Returns null if an error occurs while querying the collection.

public Task<IEnumerable<PointOfCare>?> FindByRoom(string room)

Parameters

room string

The room identifier used to filter the point-of-care records.

Returns

Task<IEnumerable<PointOfCare>>

A task that represents the asynchronous operation. The task result contains a collection of matching PointOfCare entries, or null if the search fails.

FindByUnitAndStatus(ObjectId, PointOfCare, bool)

Retrieves the collection of PointOfCare entries associated with the specified unit and status. When excludeVirtual is true, virtual entries such as Pushed, Unknown, Deleted, NoBed, Cancelled, Recovered, and Moved are excluded from the results. If an error occurs during the lookup, an empty collection is returned and the exception is logged.

public Task<IEnumerable<PointOfCare>> FindByUnitAndStatus(ObjectId unitId, StatusEnum.PointOfCare status, bool excludeVirtual = false)

Parameters

unitId ObjectId

The identifier of the unit whose point of care entries will be searched.

status StatusEnum.PointOfCare

The point of care status used to filter the results.

excludeVirtual bool

When true, filters out entries whose bed matches one of the known VirtualPointOfCare values; otherwise virtual entries are included.

Returns

Task<IEnumerable<PointOfCare>>

A task that resolves to an IEnumerable<T> containing the matching entries, or an empty collection if the query fails.

GetAll()

Retrieves all PointOfCare records from the underlying data store using an empty filter.

public Task<List<PointOfCare>?> GetAll()

Returns

Task<List<PointOfCare>>

A Task<TResult> containing a List<T> of PointOfCare items, or null when no results are returned.

GetAllConfigs()

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 PointOfCare structure.

public Task<List<PointOfCare>?> GetAllConfigs()

Returns

Task<List<PointOfCare>>

A task that resolves to a list of PointOfCare objects enriched with the corresponding beacon, camera, and relay details, or null when no configurations are found.

GetAllLocationInfo()

Retrieves all point of care location records from the collection, projecting only the essential location fields (Id, UnitId, Room, and Bed). Uses an empty filter to return every record and returns a nullable list that may be null if no results are found.

public Task<List<PointOfCare>?> GetAllLocationInfo()

Returns

Task<List<PointOfCare>>

A task that represents the asynchronous operation, containing a list of PointOfCare objects with the projected fields, or null if no matching records exist.

GetCollectionName()

Retrieves the collection name used for Locations operations from the API settings configuration.

public override string GetCollectionName()

Returns

string

The configured Locations collection name retrieved from the API settings.

GetPaginatedPoCs(PaginationFilter)

Retrieves a paginated, filtered query of PointOfCare records, supporting optional filtering by unit (by id or name) and status, sorted by id descending.

public IFindFluent<PointOfCare, PointOfCare> GetPaginatedPoCs(PaginationFilter filter)

Parameters

filter PaginationFilter

The pagination and filtering criteria. If FilteredRequest is null, no additional filters are applied.

Returns

IFindFluent<PointOfCare, PointOfCare>

An MongoDB.Driver.IFindFluent<TDocument, TProjection> representing the resulting MongoDB query with the applied filters and sort.

GetPoCConfiguration(ObjectId)

Retrieves the PointOfCare configuration identified by the specified pocId, projecting only the identifier and configuration fields. Returns null when no matching point of care is found.

public Task<PointOfCare?> GetPoCConfiguration(ObjectId pocId)

Parameters

pocId ObjectId

The unique identifier of the point of care whose configuration is being requested.

Returns

Task<PointOfCare>

A Task<TResult> containing the matching PointOfCare with its configuration, or null if no record exists for the given identifier.

InsertOneAsync(PointOfCare)

Asynchronously inserts a single PointOfCare record, adding error logging around the base insertion behavior. If the base insert operation fails, the exception is written to the console and logged, then rethrown to preserve the original failure.

public override Task InsertOneAsync(PointOfCare pointOfCare)

Parameters

pointOfCare PointOfCare

The PointOfCare entity to insert.

Returns

Task

Update(PointOfCare)

Updates an existing PointOfCare entity asynchronously in the data store.

public Task Update(PointOfCare pointOfCare)

Parameters

pointOfCare PointOfCare

The PointOfCare entity to update, identified by its Id.

Returns

Task

UpdateConfiguration(ObjectId, PointOfCareConfiguration)

Updates the PointOfCareConfiguration of an existing PointOfCare entity identified by the specified id, setting only the configuration field via a partial update.

public Task UpdateConfiguration(ObjectId id, PointOfCareConfiguration configuration)

Parameters

id ObjectId

The unique identifier of the PointOfCare entity to update.

configuration PointOfCareConfiguration

The new configuration values to apply to the entity.

Returns

Task

UpdateRelayConfig(ObjectId, List<ObjectId>)

Updates the relay configuration of a specific point of care by replacing its associated relay identifier list.

public Task UpdateRelayConfig(ObjectId pocId, List<ObjectId> relayConfig)

Parameters

pocId ObjectId

The identifier of the point of care whose relay configuration will be updated.

relayConfig List<ObjectId>

The new list of relay identifiers to assign to the point of care's configuration.

Returns

Task

UpdateRelayConfig(ObjectId, List<Relay>)

Updates the relay configuration of a Point of Care by replacing its relay identifier list with the identifiers extracted from the provided relay configuration entries.

public Task UpdateRelayConfig(ObjectId pocId, List<Relay> relayConfig)

Parameters

pocId ObjectId

The unique identifier of the Point of Care whose relay configuration will be updated.

relayConfig List<Relay>

The collection of relays whose identifiers will be stored as the new relay configuration.

Returns

Task

UpdateStatus(ObjectId, PointOfCare)

Updates the status of an existing point-of-care record identified by its unique identifier.

public Task UpdateStatus(ObjectId id, StatusEnum.PointOfCare status)

Parameters

id ObjectId

The unique identifier of the point-of-care record to update.

status StatusEnum.PointOfCare

The new status value to apply to the point-of-care record.

Returns

Task

UpdateUnitId(ObjectId, Unit)

Updates the unit name and unit identifier of a PointOfCare document identified by the specified id.

public Task UpdateUnitId(ObjectId id, Unit unit)

Parameters

id ObjectId

The ObjectId of the PointOfCare document to update.

unit Unit

The Unit object whose Name and Id values will be set on the matching document.

Returns

Task