=== 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
@@ -41,6 +41,7 @@ public class UnitService(
/// </summary>
/// <param name="withPoCs">If <c>true</c>, loads and assigns the PointOfCares for each unit; if <c>false</c>, returns units without their PointOfCares.</param>
/// <returns>A task representing the asynchronous operation, containing the list of all units, with PointOfCares populated when requested.</returns>
/// <!-- aidoc:v1 sig=e53198c body=b2eb1e0 -->
public async Task<List<Unit>> GetAll(bool withPoCs = false)
{
var units = await unitRepository.GetAll();
@@ -59,6 +60,7 @@ public class UnitService(
/// Retrieves all units in a compact representation, mapping each unit to a <see cref="UnitInfoDto"/> containing its identifier, name, and title, with null name and title values safely replaced by empty strings.
/// </summary>
/// <returns>A task that represents the asynchronous operation. The task result contains a list of <see cref="UnitInfoDto"/> objects for all available units.</returns>
/// <!-- aidoc:v1 sig=d5bdc99 body=459fadb -->
public async Task<List<UnitInfoDto>> GetAllCompact()
{
var units = await unitRepository.GetAll();
@@ -78,6 +80,7 @@ public class UnitService(
/// </summary>
/// <param name="id">The unique identifier of the unit to retrieve.</param>
/// <returns>A <see cref="Task{UnitInfoDto}"/> containing the compact unit information, or a DTO with null/empty fields if the unit does not exist.</returns>
/// <!-- aidoc:v1 sig=83a227f body=03176e8 -->
public async Task<UnitInfoDto> GetOneCompact(ObjectId id)
{
var unit = await unitRepository.FindById(id);
@@ -97,6 +100,7 @@ public class UnitService(
/// <param name="filter">The pagination parameters controlling the page number, page size, and total count.</param>
/// <param name="withPoCs">Indicates whether the response units should be populated with their related Points of Care. Defaults to false.</param>
/// <returns>A <see cref="Task{PaginationResponse{Unit}}"/> containing the requested page of units along with pagination metadata.</returns>
/// <!-- aidoc:v1 sig=ace0a7a body=e4686d4 -->
public async Task<PaginationResponse<Unit>> GetPaginatedUnits(PaginationFilter filter, bool withPoCs = false)
{
var result = unitRepository.GetPaginatedUnits(filter);
@@ -133,6 +137,8 @@ public class UnitService(
/// <param name="withPoCs">When <see langword="true"/>, also loads and assigns the Points of Care associated with the unit; when <see langword="false"/> (default), the Points of Care collection is not populated.</param>
/// <returns>A <see cref="Task{Unit}"/> that yields the requested <see cref="Unit"/> with its optional related lists and Points of Care, or <see langword="null"/> when no unit matches the identifier.</returns>
/// <exception cref="NotFoundException">Thrown when no unit is found for the supplied <paramref name="id"/>.</exception>
/// <!-- aidoc-review:v1 severity=high kind=wrong_returns
/// "The <returns> tag states the method yields 'null when no unit matches the identifier', but the code uses '?? throw new NotFoundException(...)' so a missing unit causes an exception rather than a null return." -->
public async Task<Unit?> GetInfo(ObjectId id, LocaleEnum? dataLocale, bool fillLists = true, bool withPoCs = false)
{
var unit = await Get(id.ToString()) ??
@@ -252,6 +258,8 @@ public class UnitService(
/// <param name="withDevices">Flag intended to control device inclusion alongside the points of care.</param>
/// <returns>The matching <see cref="Unit"/> instance.</returns>
/// <exception cref="NotFoundException">Thrown when no unit exists for the supplied <paramref name="id"/>.</exception>
/// <!-- aidoc-review:v1 severity=medium kind=mentions_removed_behavior
/// "The `withDevices` parameter is documented as a 'flag intended to control device inclusion alongside the points of care', but the parameter is never used in the method body — `FindAllByUnitIdWithDevices` is always called (with devices) regardless of the flag whenever `withPoCs` is true." -->
public async Task<Unit?> GetInfo(ObjectId id, bool withPoCs = true, bool withDevices = true)
{
var unit = await Get(id.ToString()) ??
@@ -271,6 +279,7 @@ public class UnitService(
/// <param name="itemUnitName">The name of the unit to search for.</param>
/// <returns>The unit matching the specified name.</returns>
/// <exception cref="NotFoundException">Thrown when no unit exists with the provided name.</exception>
/// <!-- aidoc:v1 sig=7ccf7cc body=9d60511 -->
public async Task<Unit?> GetByName(string itemUnitName)
{
return await unitRepository.FindByName(itemUnitName) ??
@@ -284,6 +293,8 @@ public class UnitService(
/// <param name="patientId">The identifier of the patient whose associated unit should be retrieved.</param>
/// <returns>A <see cref="Task{Unit}"/> containing the associated <see cref="Unit"/> if found, or <c>null</c> when no matching unit exists.</returns>
/// <exception cref="NotFoundException">Thrown when the patient has no associated <c>UnitId</c> (i.e., the resource is missing).</exception>
/// <!-- aidoc-review:v1 severity=low kind=wrong_returns
/// "The returns tag uses <see cref=\"Task{Unit}\"/> but the method signature is Task<Unit?>; the nullable annotation is missing from the type reference (the descriptive text 'or null' partially compensates)." -->
public async Task<Unit?> FindByPatientId(ObjectId patientId)
{
//var sections = await GetAll();
@@ -305,6 +316,7 @@ public class UnitService(
/// <param name="masterListId">The identifier of the master list used to find the associated units.</param>
/// <param name="masterListType">The type of the master list used to filter the units.</param>
/// <returns>A task that represents the asynchronous operation, containing a collection of <see cref="Unit"/> entities if found, or <c>null</c> if an error occurs.</returns>
/// <!-- aidoc:v1 sig=d996cfa body=ae5cf23 -->
public async Task<IEnumerable<Unit>?> FindUnitsByMasterListId(ObjectId masterListId, MasterListType masterListType)
{
try
@@ -327,6 +339,7 @@ public class UnitService(
/// <param name="masterListId">The unique identifier of the master list whose units should be counted.</param>
/// <param name="masterListType">The type of the master list used to filter the units to be counted.</param>
/// <returns>A <see cref="Task{Int64}"/> representing the asynchronous operation, containing the total number of units that match the given master list identifier and type.</returns>
/// <!-- aidoc:v1 sig=2014d9c body=8106f59 -->
public async Task<long> CountUnitsByMasterListId(ObjectId masterListId, MasterListType masterListType)
{
return await unitRepository.CountUnitsByMasterListId(masterListId, masterListType);
@@ -338,6 +351,7 @@ public class UnitService(
/// </summary>
/// <param name="masterListId">The identifier of the master list whose units should be retrieved.</param>
/// <returns>A task that yields the collection of <see cref="Unit"/> items matching the master list identifier, or an empty list if an error occurs.</returns>
/// <!-- aidoc:v1 sig=ff45b25 body=1fd5690 -->
public async Task<IEnumerable<Unit>> FindUnitsByMasterListId(ObjectId masterListId)
{
try
@@ -362,6 +376,8 @@ public class UnitService(
/// <returns>The updated <see cref="Unit"/> if the operation succeeds; otherwise, <c>null</c> when the underlying update returns no result.</returns>
/// <exception cref="NotFoundException">Thrown when no unit is found matching the identifier specified in <paramref name="updateUnitListDto"/>.</exception>
/// <exception cref="ConflictException">Thrown when the update operation performed by the repository fails to produce a result.</exception>
/// <!-- aidoc-review:v1 severity=high kind=wrong_returns
/// "The documentation states the method returns null when the underlying update returns no result, but the code throws ConflictException in that case; the method never actually returns null." -->
public async Task<Unit?> UpdateUnitMasterList(UpdateUnitIdListDto updateUnitListDto)
{
var unit = await FindById(updateUnitListDto.UnitId) ??
@@ -380,6 +396,8 @@ public class UnitService(
/// <returns>A task that resolves to <c>true</c> when the configuration was successfully updated; otherwise, <c>false</c>.</returns>
/// <exception cref="NotFoundException">Thrown when the unit cannot be found either before or after the update operation.</exception>
/// <exception cref="ConflictException">Thrown when the underlying update operation fails to persist the new configuration.</exception>
/// <!-- aidoc-review:v1 severity=high kind=wrong_returns
/// "Documentation claims the method resolves to false when the update fails, but the code throws ConflictException instead and never returns false." -->
public async Task<bool> UpdateConfiguration(ObjectId unitIdParsed, UnitConfiguration unitConfiguration)
{
var oldConfig = await FindById(unitIdParsed) ??
@@ -398,6 +416,7 @@ public class UnitService(
/// </summary>
/// <param name="id">The identifier of the unit to find.</param>
/// <returns>The unit matching the specified identifier, or null if the identifier is null.</returns>
/// <!-- aidoc:v1 sig=ee7012d body=14c7c27 -->
public async Task<Unit?> FindById(ObjectId? id)
{
if (id == null)
@@ -411,6 +430,7 @@ public class UnitService(
/// </summary>
/// <param name="name">The name of the unit to look up. Can be <see langword="null"/> or empty.</param>
/// <returns>A <see cref="Task{Unit}"/> containing the matching <see cref="Unit"/>, or <see langword="null"/> if no name was provided.</returns>
/// <!-- aidoc:v1 sig=09cbbd2 body=8b96d0b -->
public async Task<Unit?> FindByName(string? name)
{
if (string.IsNullOrEmpty(name))
@@ -426,6 +446,7 @@ public class UnitService(
/// <param name="name">The name of the unit to search for. Takes precedence over <paramref name="pocName"/> when provided.</param>
/// <param name="pocName">The point of care bed identifier used as a fallback to locate the unit when <paramref name="name"/> is not supplied.</param>
/// <returns>A task containing the matching <see cref="Unit"/>, or <c>null</c> if no unit can be resolved from the given inputs.</returns>
/// <!-- aidoc:v1 sig=cfafc13 body=67e6827 -->
public async Task<Unit?> FindByUnitNameOrPocName(string? name, string? pocName)
{
if (!string.IsNullOrEmpty(name))
@@ -451,6 +472,7 @@ public class UnitService(
/// <param name="unit">The unit entity to be inserted.</param>
/// <returns>The newly created unit returned by the repository.</returns>
/// <exception cref="ConflictException">Thrown when the repository returns null, indicating that the unit could not be created.</exception>
/// <!-- aidoc:v1 sig=a8b3336 body=f2e2479 -->
public async Task<Unit?> InsertOne(Unit unit)
{
var newUnit = await unitRepository.InsertOneUnit(unit) ??
@@ -465,6 +487,7 @@ public class UnitService(
/// <param name="unit">The unit containing the updated information, including the identifier of the existing unit to modify.</param>
/// <returns>The updated <see cref="Unit"/> if the operation succeeded; <c>null</c> if the repository could not persist the update.</returns>
/// <exception cref="NotFoundException">Thrown when no unit exists with the specified identifier.</exception>
/// <!-- aidoc:v1 sig=2e95c1d body=7f75d2a -->
public async Task<Unit?> UpdateUnit(Unit unit)
{
var oldUnit = await FindById(unit.Id) ??
@@ -488,6 +511,8 @@ public class UnitService(
/// <returns>The updated unit when the operation succeeds; otherwise, null.</returns>
/// <exception cref="NotFoundException">Thrown when no unit is found for the provided identifier.</exception>
/// <exception cref="ConflictException">Thrown when the underlying unit update operation fails.</exception>
/// <!-- aidoc-review:v1 severity=low kind=wrong_returns
/// "Returns doc says 'otherwise, null' but the method throws NotFoundException/ConflictException on failure rather than ever returning null; the nullable return type is documented but no path actually produces null." -->
public async Task<Unit?> UpdateUnitInfo(ObjectId unitId, string name, string title, string? configObsId = null)
{
var oldUnit = await FindById(unitId) ??
@@ -507,6 +532,7 @@ public class UnitService(
/// <param name="unit">The unit entity to delete, identified by its <c>Id</c>.</param>
/// <returns>A task that resolves to <c>true</c> when the unit is successfully deleted.</returns>
/// <exception cref="ConflictException">Thrown when the delete operation fails (returns <c>null</c>).</exception>
/// <!-- aidoc:v1 sig=226184c body=dcf53cd -->
public async Task<bool> DeleteUnitById(Unit unit)
{
//if (unit is not { Status: null }) throw new ConflictException(ErrorMessage.Conflict_ResourceInUse);
@@ -521,6 +547,7 @@ public class UnitService(
/// </summary>
/// <param name="id">The identifier used to locate the unit. It can be an ObjectId, a title, or a name.</param>
/// <returns>The matching <see cref="Unit"/> if found; otherwise, <c>null</c>.</returns>
/// <!-- aidoc:v1 sig=fbd7a84 body=0390751 -->
public async Task<Unit?> Get(string id)
{
Unit? section = null;
@@ -541,6 +568,7 @@ public class UnitService(
/// </summary>
/// <param name="location">The <see cref="PatientLocation"/> providing the <c>Bed</c> and <c>UnitName</c> values used to filter the results.</param>
/// <returns>A task containing a list of <see cref="Unit"/> entries whose point of care matches the given location, or <c>null</c> if an error occurs while retrieving the data.</returns>
/// <!-- aidoc:v1 sig=1ca25fc body=0bf54cf -->
public async Task<List<Unit>?> FindByLocation(PatientLocation location)
{
try
@@ -564,6 +592,7 @@ public class UnitService(
/// </summary>
/// <param name="unit">The unit whose operation is being broadcast.</param>
/// <param name="operation">The type of operation performed on the unit, sent as part of the broadcast message.</param>
/// <!-- aidoc:v1 sig=719c6f2 body=28f4ccb -->
private async void SendUnitBroadcast(Unit unit, OperationType operation)
{
try