# Class PointOfCareService

Namespace
  adas_core.Application.Services

Assembly
  adas-core.Application.dll

    public class PointOfCareService : IPointOfCareService

Inheritance
  object
  PointOfCareService

Implements
  IPointOfCareService

Inherited Members
  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

### PointOfCareService(ILogger<PointOfCareService>, IPointOfCareRepository, Lazy<IPatientService>, Lazy<IUnitService>, ISubscribersService, Lazy<IClientMessageService>, Lazy<IAdmissionService>, IHttpContextAccessor, ILocalAuditService, ICacheService, IOptions<CacheSettings>)

    public PointOfCareService(ILogger<PointOfCareService> logger, IPointOfCareRepository pointOfCareRepository, Lazy<IPatientService> patientService, Lazy<IUnitService> unitService, ISubscribersService subscribersService, Lazy<IClientMessageService> clientMessageService, Lazy<IAdmissionService> admissionService, IHttpContextAccessor httpContextAccessor, ILocalAuditService auditService, ICacheService cacheService, IOptions<CacheSettings> cacheSettings)

#### Parameters

`logger` ILogger<PointOfCareService>
`pointOfCareRepository` IPointOfCareRepository
`patientService` Lazy<IPatientService>
`unitService` Lazy<IUnitService>
`subscribersService` ISubscribersService
`clientMessageService` Lazy<IClientMessageService>
`admissionService` Lazy<IAdmissionService>
`httpContextAccessor` IHttpContextAccessor
`auditService` ILocalAuditService
`cacheService` ICacheService
`cacheSettings` IOptions<CacheSettings>

## Methods

### CheckNextAdmission(ObjectId?)

Check nex admission when patient has exit from poc

    public void CheckNextAdmission(ObjectId? patientLocation)

#### Parameters

`patientLocation` ObjectId?

  PoC id

### CountPoCsByUnitId(ObjectId)

Asynchronously counts the number of Points of Care (PoCs) associated with the specified unit identifier.

    public Task<long> CountPoCsByUnitId(ObjectId unitId)

#### Parameters

`unitId` ObjectId

  The unique identifier of the unit whose PoCs should be counted.

#### Returns

Task<long>

  A task representing the asynchronous operation, containing the total number of PoCs linked to the given unit.

### CountVirtualPoCsByUnitId(ObjectId)

Asynchronously counts the number of virtual Points of Care (PoCs) associated with the specified unit identifier by delegating to the repository.

    public Task<long> CountVirtualPoCsByUnitId(ObjectId unitId)

#### Parameters

`unitId` ObjectId

  The unique identifier of the unit whose virtual PoCs are being counted.

#### Returns

Task<long>

  A Task<TResult> representing the asynchronous operation, containing the total number of virtual PoCs linked to the given unit.

### Delete(ObjectId)

Deletes a Point of Care record by its identifier, but only when the record has no associated admission. The deletion is skipped if the record cannot be found or if it is linked to an admission.

    public Task Delete(ObjectId id)

#### Parameters

`id` ObjectId

  The unique identifier of the Point of Care record to delete.

#### Returns

Task

### DeletePoCsByUnitId(ObjectId)

Deletes all Points of Care associated with the specified unit identifier and removes the corresponding cached entries.

    public Task DeletePoCsByUnitId(ObjectId unitId)

#### Parameters

`unitId` ObjectId

  The identifier of the unit whose Points of Care records will be removed.

#### Returns

Task

### FindAllByUnitId(ObjectId)

Retrieves all points of care associated with the specified unit identifier. Returns an empty collection when the underlying repository yields no results, instead of propagating a null reference.

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

#### Parameters

`unit` ObjectId

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

#### Returns

Task<IEnumerable<PointOfCare>>

  A task that represents the asynchronous operation, containing a collection of points of care for the given unit, or an empty collection if none are found.

### FindAllByUnitIdWithDevices(ObjectId)

Asynchronously retrieves all points of care associated with the specified unit, including their associated devices. Returns an empty collection when no results are found by the repository.

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

#### Parameters

`unitId` ObjectId

  The unique identifier of the unit whose points of care are being queried.

#### Returns

Task<IEnumerable<PointOfCare>>

  A task that represents the asynchronous operation. The task result contains a collection of PointOfCare with their devices, or an empty collection if the repository returns no results.

### FindAllByUnitIds(List<ObjectId>)

Retrieves all points of care associated with the specified unit identifiers.

    public Task<List<PointOfCare>> FindAllByUnitIds(List<ObjectId> unitIds)

#### Parameters

`unitIds` List<ObjectId>

  The list of unit identifiers used to filter the points of care.

#### Returns

Task<List<PointOfCare>>

  A task that represents the asynchronous operation, containing the list of matching points of care.

### FindAllIdBeaconsInUse()

Asynchronously retrieves the set of beacon identifiers that are currently in use from the point of care repository.

    public Task<HashSet<ObjectId>> FindAllIdBeaconsInUse()

#### Returns

Task<HashSet<ObjectId>>

  A task that represents the asynchronous operation. The task result contains a HashSet<T> with the identifiers of all beacons in use.

### FindAllIdCamerasInUse()

Asynchronously retrieves the set of camera identifiers that are currently in use by delegating to the point of care repository.

    public Task<HashSet<ObjectId>> FindAllIdCamerasInUse()

#### Returns

Task<HashSet<ObjectId>>

  A task that represents the asynchronous operation, containing a HashSet<T> of camera identifiers in use.

### FindAllIdRelaysInUse()

Asynchronously retrieves the set of all ID relay identifiers currently in use by delegating to the point of care repository.

    public Task<HashSet<ObjectId>> FindAllIdRelaysInUse()

#### Returns

Task<HashSet<ObjectId>>

  A task that represents the asynchronous operation. The task result contains a HashSet<T> of MongoDB.Bson.ObjectId values representing the ID relays that are in use.

### FindByBed(string)

Retrieves the collection of points of care associated with the specified bed.

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

#### Parameters

`bed` string

  The bed identifier used to look up the associated points of care.

#### Returns

Task<IEnumerable<PointOfCare>>

  A task that returns an IEnumerable<T> of points of care linked to the given bed, or `null` if no points of care are found.

### FindByBedAndUnitId(string?, ObjectId?)

Retrieves a PointOfCare by bed and unit identifier. Returns `null` when the unit identifier is `null` or the bed is `null` or empty.

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

#### Parameters

`bed` string

  The bed identifier used to locate the point of care.

`unitId` ObjectId?

  The unit identifier; when `null`, the method short-circuits and returns `null`.

#### Returns

Task<PointOfCare>

  A Task<TResult> containing the matching PointOfCare, or `null` if no input is valid or no record is found.

### FindById(ObjectId)

Retrieves a point of care by its identifier, including all associated configurations.

    public Task<PointOfCare?> FindById(ObjectId id)

#### Parameters

`id` ObjectId

  The unique identifier of the point of care to retrieve.

#### Returns

Task<PointOfCare>

  The matching PointOfCare with all configurations, or `null` if no point of care is found.

### FindByIdAllConfig(ObjectId)

Retrieves a point of care entity by its identifier, including all associated configuration data.

    public Task<PointOfCare?> FindByIdAllConfig(ObjectId id)

#### Parameters

`id` ObjectId

  The unique identifier of the point of care to retrieve.

#### Returns

Task<PointOfCare>

  The matching PointOfCare with all configuration when found; otherwise, `null`.

### FindByRoom(string)

Retrieves a collection of points of care associated with the specified room by delegating to the repository.

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

#### Parameters

`room` string

  The room identifier used to look up matching points of care.

#### Returns

Task<IEnumerable<PointOfCare>>

  A task that represents the asynchronous operation. The task result contains an IEnumerable<T> of points of care for the given room, or `null` if no matching points of care are found.

### FindByUnitAndStatus(ObjectId, PointOfCare, bool)

Retrieves the points of care associated with the specified unit that match the given status, optionally excluding virtual points of care.

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

#### Parameters

`unitId` ObjectId

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

`poc` StatusEnum.PointOfCare

  The point of care status used to filter the results.

`excludeVirtual` bool

  When set to `true`, virtual points of care are excluded from the returned collection.

#### Returns

Task<IEnumerable<PointOfCare>>

  A task that represents the asynchronous operation. The task result contains the collection of points of care matching the specified unit and status.

### FindPoCByPatientId(ObjectId)

Retrieves the Point of Care associated with the specified patient by resolving the patient's assigned Point of Care identifier. Returns null if the patient cannot be found or if the patient has no Point of Care assigned.

    public Task<PointOfCare?> FindPoCByPatientId(ObjectId patientId)

#### Parameters

`patientId` ObjectId

  The unique identifier of the patient whose Point of Care is being requested.

#### Returns

Task<PointOfCare>

  The PointOfCare associated with the patient if one is assigned; otherwise, `null`.

### FindPoCByPatientLocation(PatientLocation)

Asynchronously retrieves a Point of Care associated with the specified patient location by delegating to the repository. Returns a null result if no matching Point of Care is found.

    public Task<PointOfCare?> FindPoCByPatientLocation(PatientLocation patientLocation)

#### Parameters

`patientLocation` PatientLocation

  The patient location used to look up the associated Point of Care.

#### Returns

Task<PointOfCare>

  A task that yields the matching PointOfCare, or `null` if no Point of Care is found for the given location.

### FindPoCByPatientNumber(string)

Retrieves the Point of Care associated with the specified patient number. Returns null if no patient is found with the given number, or if the patient exists but has no associated Point of Care.

    public Task<PointOfCare?> FindPoCByPatientNumber(string patientNumber)

#### Parameters

`patientNumber` string

  The unique patient number used to look up the patient.

#### Returns

Task<PointOfCare>

  A task that represents the asynchronous operation, containing the associated PointOfCare if found; otherwise, null.

### GetAll()

Asynchronously retrieves all points of care from the repository, returning an empty list when the repository yields a null result.

    public Task<List<PointOfCare>> GetAll()

#### Returns

Task<List<PointOfCare>>

  A task representing the asynchronous operation, containing the list of points of care, or an empty list if none are available.

### GetAllConfigs()

Retrieves all point of care configurations from the repository. Returns an empty list if the repository result is null.

    public Task<List<PointOfCare>> GetAllConfigs()

#### Returns

Task<List<PointOfCare>>

  A list of PointOfCare configurations, or an empty list when no configurations are available.

### GetAllLocationInfo()

Retrieves all point-of-care location information from the repository. Returns an empty list when the repository yields no results, ensuring callers never receive a null collection.

    public Task<List<PointOfCare>> GetAllLocationInfo()

#### Returns

Task<List<PointOfCare>>

  A task that resolves to a list of PointOfCare entries, or an empty list if no locations are found.

### GetInfo(ObjectId, bool)

Retrieves a PointOfCare by its identifier, enriching it with related unit, patient, and admission data. Returns `null` when no point of care matches the supplied id. When `fillPatientData` is `true`, the associated patient and, if present, admission are loaded and attached to the result; the related unit's name is always resolved when available.

    public Task<PointOfCare?> GetInfo(ObjectId id, bool fillPatientData = true)

#### Parameters

`id` ObjectId

  The identifier of the point of care to retrieve.

`fillPatientData` bool

  If `true`, loads and attaches the related patient and admission (when an admission id is present) to the returned point of care.

#### Returns

Task<PointOfCare>

  A task that yields the PointOfCare with resolved related data, or `null` if no point of care is found for the given id.

### GetInfo(ObjectId, LocaleEnum?, bool, CancellationToken)

Retrieves a PointOfCare by its identifier, using a cache-aside strategy, and optionally enriches it with related unit, patient, and admission data. When `fillPatientData` is `false` or the point of care is not found, the method returns the cached value without further enrichment; the patient lookup is performed using the supplied `locale` when provided, and admission data is only attached when an `AdmissionId` exists on the point of care.

    public Task<PointOfCare?> GetInfo(ObjectId id, LocaleEnum? locale, bool fillPatientData = true, CancellationToken ct = default)

#### Parameters

`id` ObjectId

  The unique identifier of the point of care to retrieve.

`locale` LocaleEnum?

  Optional locale used to select the appropriate patient translation; when `null`, a locale-independent patient lookup is used.

`fillPatientData` bool

  When `true`, enriches the result with unit, patient, and admission data; when `false`, returns the point of care as-is.

`ct` CancellationToken

  Token used to cancel the asynchronous operation.

#### Returns

Task<PointOfCare>

  The retrieved and optionally enriched PointOfCare, or `null` if no point of care is found for the given identifier.

### GetPaginatedPoCs(PaginationFilter)

Retrieves a paginated list of Points of Care (PoCs) based on the provided pagination filter, along with the total document count. Applies skip and limit operations to return only the items corresponding to the requested page.

    public Task<PaginationResponse<PointOfCare>> GetPaginatedPoCs(PaginationFilter filter)

#### Parameters

`filter` PaginationFilter

  The pagination filter containing the page number and page size used to compute the skip offset and limit the number of returned items.

#### Returns

Task<PaginationResponse<PointOfCare>>

  A PaginationResponse<T> containing the requested page of points of care, the current page number, page size, and the total document count.

### InsertPointOfCare(PointOfCare)

Inserts a new point of care after validating that the referenced unit exists, and records an audit log entry for the operation. Returns null if the associated unit cannot be found or if an exception is raised during the insertion process.

    public Task<PointOfCare?> InsertPointOfCare(PointOfCare pointOfCare)

#### Parameters

`pointOfCare` PointOfCare

  The point of care to be inserted; its `UnitId` is validated against the existing unit and reassigned to the resolved unit's identifier.

#### Returns

Task<PointOfCare>

  A task that resolves to the newly inserted PointOfCare, or `null` when the referenced unit is not found or the operation fails.

### SetPointOfCareStatus(ObjectId, PointOfCare)

Updates the status of an existing point of care identified by its id, persisting the change, invalidating the related cache entries, recording an audit log of the change, and broadcasting the update. If no point of care is found for the given id, the method returns without making any changes.

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

#### Parameters

`id` ObjectId

  The unique identifier of the point of care whose status should be updated.

`status` StatusEnum.PointOfCare

  The new point of care status to apply.

#### Returns

Task

### Update(PointOfCare)

Updates an existing point of care record, refreshes the related cache entries, creates an audit log entry for the change, and broadcasts the update. Returns the updated point of care, or `null` if the updated record cannot be retrieved after the update.

    public Task<PointOfCare?> Update(PointOfCare pointOfCare)

#### Parameters

`pointOfCare` PointOfCare

  The point of care entity containing the updated information to persist.

#### Returns

Task<PointOfCare>

  The updated PointOfCare, or `null` if the record was not found after the update.

### UpdateConfiguration(ObjectId, PointOfCareConfiguration)

Updates the Point of Care configuration for the specified identifier, invalidates the associated cache entries, and records an audit log of the change.

    public Task UpdateConfiguration(ObjectId id, PointOfCareConfiguration configuration)

#### Parameters

`id` ObjectId

  The identifier of the Point of Care configuration to update.

`configuration` PointOfCareConfiguration

  The new configuration values to persist.

#### Returns

Task

  A task that represents the asynchronous update operation.

#### Exceptions

ConflictException

  Thrown when no existing Point of Care configuration is found for the specified identifier.

### UpdateRelayConfig(PointOfCare)

Updates the relay configuration for the specified Point of Care, refreshing the related cache and recording an audit log entry when a relay ID list is provided. The update, cache invalidation, and audit logging are only performed when Configuration and its `RelayIdList` are not null.

    public Task UpdateRelayConfig(PointOfCare poc)

#### Parameters

`poc` PointOfCare

  The Point of Care whose relay configuration will be updated.

#### Returns

Task

### UpdateUnit(ObjectId, Unit)

Updates the unit associated with an existing point of care identified by the given id. If no point of care is found, the method returns without changes; otherwise it persists the new unit, invalidates the related cache entries, records an audit log of the change, and broadcasts the update.

    public Task UpdateUnit(ObjectId id, Unit unit)

#### Parameters

`id` ObjectId

  The identifier of the point of care to update.

`unit` Unit

  The unit to assign to the point of care.

#### Returns

Task