# Class SectionRepository

Namespace
  adas_core.Infrastructure.Repositories

Assembly
  adas-core.Infrastructure.dll

Represents a MongoDB repository for `Section` entities, implementing the contract defined by ISectionRepository.

    public class SectionRepository : MongoRepository<Section>, ISectionRepository, IMongoRepository<Section>

Inheritance
  object
  MongoRepository<Section>
  SectionRepository

Implements
  ISectionRepository
  IMongoRepository<Section>

Inherited Members
  MongoRepository<Section>.Db
  MongoRepository<Section>.Collection
  MongoRepository<Section>.InsertOneAsync(Section)
  MongoRepository<Section>.UpdateOneAsync(ObjectId, Section)
  MongoRepository<Section>.DeleteAsync(ObjectId)
  MongoRepository<Section>.CreateIndexes()
  MongoRepository<Section>.InsertInitialLoad()
  MongoRepository<Section>.InsertManyAsync(List<Section>)
  MongoRepository<Section>.UpdateManyObjectIdAsync(string, ObjectId, ObjectId)
  MongoRepository<Section>.DeleteAsync(string)
  MongoRepository<Section>.CollectionExists(string)
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

Extension Methods
  NumberUtils.IsNumber(object)
  NumberUtils.ToDouble(object)
  ObjectUtils.ToStr(object?)

## Constructors

### SectionRepository(IOptions<ApiSettings>, IMongoDatabase)

    public SectionRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database)

#### Parameters

`apiSettings` IOptions<ApiSettings>
`database` IMongoDatabase

## Methods

### FindById(object)

Asynchronously retrieves a Section by its identifier from the collection, returning `null` when no matching document is found.

    public Task<Section?> FindById(object id)

#### Parameters

`id` object

  The identifier of the section to locate.

#### Returns

Task<Section>

  A Section instance if a document with the given identifier exists; otherwise, `null`.

### FindById(string)

Finds a Section by its unique identifier in the underlying collection. Returns `null` when no matching section exists.

    public Task<Section?> FindById(string id)

#### Parameters

`id` string

  The unique identifier of the section to retrieve.

#### Returns

Task<Section>

  A task containing the matching Section if found; otherwise, `null`.

### FindByLocation(PatientLocation)

Retrieves the active sections associated with the specified patient location by matching the unit name and bed against the section hierarchy. Filtering is performed in memory after retrieving all sections because the underlying query does not support direct filtering on the collection's point of care field. A section is considered matching when its point of care equals the unit name and contains a box with a null point of care for the requested bed, or when it contains a box whose point of care equals the unit name for the requested bed.

    public Task<List<Section>> FindByLocation(PatientLocation location)

#### Parameters

`location` PatientLocation

  The patient location containing the unit name and bed used to locate the corresponding sections.

#### Returns

Task<List<Section>>

  A task that represents the asynchronous operation. The task result contains a list of sections matching the provided patient location; an empty list is returned when no matching sections are found.

### FindByPointOfCare(string)

Asynchronously retrieves the first Section whose `PointOfCare` matches the specified value.

    public Task<Section?> FindByPointOfCare(string pointOfCare)

#### Parameters

`pointOfCare` string

  The point of care identifier used to filter the sections.

#### Returns

Task<Section>

  The first matching Section, or `null` if no section is found.

### FindBySection(string)

Finds and returns the first Section whose `SectionTitle` matches the specified section value.

    public Task<Section?> FindBySection(string section)

#### Parameters

`section` string

  The section title used to look up the matching Section.

#### Returns

Task<Section>

  The first matching Section, or `null` if no section with the given title is found.

### GetAll()

Retrieves all Section documents from the underlying collection by querying with an empty filter.

    public Task<List<Section>> GetAll()

#### Returns

Task<List<Section>>

  A task that represents the asynchronous operation, containing a list of all Section documents found in the collection.

### GetCollectionName()

Gets the configuration sections collection name from the API settings, falling back to a default value when not configured.

    public override string GetCollectionName()

#### Returns

string

  The configured collection name, or "config_sections" if `_apiSettings.ConfigSections` is null.

### InsertOneSection(Section)

Asynchronously inserts a single Section into the collection and returns the persisted entity retrieved by its identifier. If the insertion fails, the error is logged and the method returns `null` instead of propagating the exception.

    public Task<Section?> InsertOneSection(Section section)

#### Parameters

`section` Section

  The section to insert into the collection.

#### Returns

Task<Section>

  The inserted Section on success, or `null` if the operation fails.

### UpdateSection(Section)

Updates an existing Section in the data store and returns the updated document. If no section with the specified identifier is found, the method returns null.

    public Task<Section?> UpdateSection(Section section)

#### Parameters

`section` Section

  The section containing the identifier of the record to update and the new field values to persist.

#### Returns

Task<Section>

  The updated Section as it appears after the update, or null if no matching record was found.