rama creada apartir de master en j
This commit is contained in:
@@ -14,20 +14,37 @@ using MongoUtils = adas_core.Infrastructure.Utils.MongoUtils;
|
||||
|
||||
namespace adas_core.Infrastructure.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// Repository for managing Discharge entities in MongoDB. Provides methods for CRUD operations and specific queries related to discharges.
|
||||
/// </summary>
|
||||
public class DischargeRepository : MongoRepository<Discharge>, IDischargeRepository
|
||||
{
|
||||
private readonly ApiSettings _apiSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the DischargeRepository class with the specified API settings and MongoDB database.
|
||||
/// </summary>
|
||||
/// <param name="apiSettings">The API settings containing configuration for the repository.</param>
|
||||
/// <param name="database">The MongoDB database instance.</param>
|
||||
public DischargeRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database) : base(database)
|
||||
{
|
||||
_apiSettings = apiSettings.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the MongoDB collection for discharges from the API settings.
|
||||
/// </summary>
|
||||
/// <returns>The name of the MongoDB collection for discharges.</returns>
|
||||
public override string GetCollectionName()
|
||||
{
|
||||
return _apiSettings.Discharges;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts a new discharge record into the MongoDB collection. Sets the discharge date to the current UTC time before insertion.
|
||||
/// </summary>
|
||||
/// <param name="discharge">The discharge record to insert.</param>
|
||||
/// <returns>A task representing the asynchronous operation.</returns>
|
||||
public override async Task InsertOneAsync(Discharge discharge)
|
||||
{
|
||||
try
|
||||
@@ -41,6 +58,11 @@ public class DischargeRepository : MongoRepository<Discharge>, IDischargeReposit
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a discharge record from the MongoDB collection based on the specified ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the discharge record to delete.</param>
|
||||
/// <returns>A task representing the asynchronous operation.</returns>
|
||||
public async Task Delete(ObjectId id)
|
||||
{
|
||||
try
|
||||
@@ -55,6 +77,12 @@ public class DischargeRepository : MongoRepository<Discharge>, IDischargeReposit
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing discharge record in the MongoDB collection. If the update operation fails, a ConflictException is thrown.
|
||||
/// </summary>
|
||||
/// <param name="discharge">The discharge record to update.</param>
|
||||
/// <returns>A task representing the asynchronous operation.</returns>
|
||||
/// <exception cref="ConflictException"></exception>
|
||||
public async Task Update(Discharge discharge)
|
||||
{
|
||||
try
|
||||
@@ -68,7 +96,12 @@ public class DischargeRepository : MongoRepository<Discharge>, IDischargeReposit
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Updates the unit name of a discharge record in the MongoDB collection based on the specified ID. If the update operation fails, an error is logged.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the discharge record to update.</param>
|
||||
/// <param name="unit">The new unit name to set.</param>
|
||||
/// <returns>A task representing the asynchronous operation.</returns>
|
||||
public async Task UpdateUnit(ObjectId id, string unit)
|
||||
{
|
||||
var filterBuilder = Builders<Discharge>.Filter;
|
||||
@@ -80,6 +113,12 @@ public class DischargeRepository : MongoRepository<Discharge>, IDischargeReposit
|
||||
await Collection.UpdateOneAsync(filter, update);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the patient information of a discharge record in the MongoDB collection based on the specified ID. If the update operation fails, an error is logged.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the discharge record to update.</param>
|
||||
/// <param name="patient">The new patient information to set.</param>
|
||||
/// <returns>A task representing the asynchronous operation.</returns>
|
||||
public async Task UpdatePatient(ObjectId id, Patient patient)
|
||||
{
|
||||
var filterBuilder = Builders<Discharge>.Filter;
|
||||
@@ -91,7 +130,10 @@ public class DischargeRepository : MongoRepository<Discharge>, IDischargeReposit
|
||||
await Collection.UpdateOneAsync(filter, update);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Finds and retrieves all discharge records from the MongoDB collection. If an error occurs during retrieval, an error is logged and an empty list is returned.
|
||||
/// </summary>
|
||||
/// <returns>A task representing the asynchronous operation, containing a list of all discharge records.</returns>
|
||||
public async Task<IEnumerable<Discharge>> FindAll()
|
||||
{
|
||||
try
|
||||
@@ -106,6 +148,11 @@ public class DischargeRepository : MongoRepository<Discharge>, IDischargeReposit
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds and retrieves a discharge record from the MongoDB collection based on the specified ID. If an error occurs during retrieval, an error is logged and null is returned.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the discharge record to retrieve.</param>
|
||||
/// <returns>A task representing the asynchronous operation, containing the discharge record if found, or null if not found or an error occurs.</returns>
|
||||
public async Task<Discharge?> FindById(ObjectId id)
|
||||
{
|
||||
try
|
||||
@@ -122,7 +169,11 @@ public class DischargeRepository : MongoRepository<Discharge>, IDischargeReposit
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Finds and retrieves discharge records from the MongoDB collection based on the specified unit name. If an error occurs during retrieval, an error is logged and null is returned.
|
||||
/// </summary>
|
||||
/// <param name="unit">The unit name to search for.</param>
|
||||
/// <returns>A task representing the asynchronous operation, containing a list of discharge records matching the specified unit name, or null if an error occurs.</returns>
|
||||
public async Task<IEnumerable<Discharge>?> FindByUnit(string unit)
|
||||
{
|
||||
try
|
||||
@@ -139,6 +190,11 @@ public class DischargeRepository : MongoRepository<Discharge>, IDischargeReposit
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of discharge records in the MongoDB collection that match the specified unit ID. If an error occurs during counting, an error is logged and 0 is returned.
|
||||
/// </summary>
|
||||
/// <param name="unitId">The ID of the unit to count discharge records for.</param>
|
||||
/// <returns>A task representing the asynchronous operation, containing the count of discharge records matching the specified unit ID, or 0 if an error occurs.</returns>
|
||||
public async Task<long> CountByUnitId(ObjectId unitId)
|
||||
{
|
||||
try
|
||||
@@ -153,6 +209,11 @@ public class DischargeRepository : MongoRepository<Discharge>, IDischargeReposit
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds and retrieves discharge records from the MongoDB collection based on the specified destination. If an error occurs during retrieval, an error is logged and null is returned.
|
||||
/// </summary>
|
||||
/// <param name="destination">The destination to search for.</param>
|
||||
/// <returns>A task representing the asynchronous operation, containing a list of discharge records matching the specified destination, or null if an error occurs.</returns>
|
||||
public async Task<IEnumerable<Discharge>?> FindByDestination(string destination)
|
||||
{
|
||||
try
|
||||
@@ -172,13 +233,22 @@ public class DischargeRepository : MongoRepository<Discharge>, IDischargeReposit
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds and retrieves discharge records from the MongoDB collection based on the specified unit IDs. If an error occurs during retrieval, an error is logged and null is returned.
|
||||
/// </summary>
|
||||
/// <param name="unitIds">The IDs of the units to search for.</param>
|
||||
/// <returns>A task representing the asynchronous operation, containing a list of discharge records matching the specified unit IDs, or null if an error occurs.</returns>
|
||||
public async Task<IEnumerable<Discharge>?> GetDischargesByUnitIds(IEnumerable<ObjectId>? unitIds)
|
||||
{
|
||||
var filterUnit = Builders<Discharge>.Filter.In("unitId", unitIds);
|
||||
return await Collection.Find(filterUnit).ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Finds and retrieves discharge records from the MongoDB collection based on the specified Point of Care ID. If an error occurs during retrieval, an error is logged and null is returned.
|
||||
/// </summary>
|
||||
/// <param name="pocId">The ID of the Point of Care to search for.</param>
|
||||
/// <returns>A task representing the asynchronous operation, containing a list of discharge records matching the specified Point of Care ID, or null if an error occurs.</returns>
|
||||
public async Task<IEnumerable<Discharge>?> FindByPoCId(ObjectId pocId)
|
||||
{
|
||||
try
|
||||
@@ -195,7 +265,12 @@ public class DischargeRepository : MongoRepository<Discharge>, IDischargeReposit
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Finds and retrieves discharge records from the MongoDB collection based on the specified service. If an error occurs during retrieval, an error is logged and null is returned.
|
||||
/// </summary>
|
||||
/// <param name="service">The service to search for.</param>
|
||||
/// <returns>A task representing the asynchronous operation, containing a list of discharge records matching the specified service, or null if an error occurs.</returns>
|
||||
public async Task<IEnumerable<Discharge>?> FindByService(string service)
|
||||
{
|
||||
try
|
||||
@@ -212,6 +287,11 @@ public class DischargeRepository : MongoRepository<Discharge>, IDischargeReposit
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds and retrieves a discharge record from the MongoDB collection based on the specified patient location. If an error occurs during retrieval, an error is logged and null is returned.
|
||||
/// </summary>
|
||||
/// <param name="location">The patient location to search for.</param>
|
||||
/// <returns>A task representing the asynchronous operation, containing the discharge record matching the specified patient location, or null if an error occurs.</returns>
|
||||
public async Task<Discharge?> GetDischargeByLocation(PatientLocation location)
|
||||
{
|
||||
try
|
||||
@@ -228,6 +308,11 @@ public class DischargeRepository : MongoRepository<Discharge>, IDischargeReposit
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds and retrieves a discharge record from the MongoDB collection based on the specified Point of Care ID. If an error occurs during retrieval, an error is logged and null is returned.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the Point of Care to search for.</param>
|
||||
/// <returns>A task representing the asynchronous operation, containing the discharge record matching the specified Point of Care ID, or null if an error occurs.</returns>
|
||||
public async Task<Discharge?> GetDischargeByPointOfCareId(ObjectId id)
|
||||
{
|
||||
try
|
||||
@@ -244,6 +329,14 @@ public class DischargeRepository : MongoRepository<Discharge>, IDischargeReposit
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the master list options for discharge records in the MongoDB collection based on the specified unit IDs, update option, and master list type.
|
||||
/// The method parses the master list type and performs updates accordingly. If an error occurs during the update process, an error is logged and an empty list is returned.
|
||||
/// </summary>
|
||||
/// <param name="unitIds">The list of unit IDs for which to update the master list options.</param>
|
||||
/// <param name="opt">The update option specifying the changes to be applied to the master list.</param>
|
||||
/// <param name="typeName">The name of the master list type to be updated.</param>
|
||||
/// <returns>A task representing the asynchronous operation, containing the updated discharge records, or an empty list if an error occurs.</returns>
|
||||
public Task<IEnumerable<Discharge>> UpdateMasterListOption(List<ObjectId> unitIds, UpdateOptionMasterListDto opt,
|
||||
string typeName)
|
||||
{
|
||||
@@ -263,7 +356,11 @@ public class DischargeRepository : MongoRepository<Discharge>, IDischargeReposit
|
||||
return Task.FromResult<IEnumerable<Discharge>>(new List<Discharge>());
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Deletes discharge records from the MongoDB collection based on the specified unit ID. If an error occurs during deletion, an error is logged and false is returned; otherwise, true is returned upon successful deletion.
|
||||
/// </summary>
|
||||
/// <param name="unitId">The ID of the unit for which to delete discharge records.</param>
|
||||
/// <returns>A task representing the asynchronous operation, containing true if the deletion was successful, or false if an error occurred.</returns>
|
||||
public async Task<bool> DeleteByUnitId(ObjectId unitId)
|
||||
{
|
||||
try
|
||||
@@ -279,6 +376,13 @@ public class DischargeRepository : MongoRepository<Discharge>, IDischargeReposit
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes master list options for discharge records in the MongoDB collection based on the specified unit IDs, update option, and master list type.
|
||||
/// </summary>
|
||||
/// <param name="unitIds">The list of unit IDs for which to delete master list options.</param>
|
||||
/// <param name="opt">The update option specifying the changes to be applied to the master list.</param>
|
||||
/// <param name="typeName">The name of the master list type to be updated.</param>
|
||||
/// <returns>A task representing the asynchronous operation, containing the updated discharge records, or an empty list if an error occurs.</returns>
|
||||
public Task<IEnumerable<Discharge>> DeleteMasterListOption(List<ObjectId> unitIds, OptionList opt, string typeName)
|
||||
{
|
||||
var isParsed = Enum.TryParse<MasterListType>(typeName, out var parsedTypeName);
|
||||
@@ -297,6 +401,11 @@ public class DischargeRepository : MongoRepository<Discharge>, IDischargeReposit
|
||||
return Task.FromResult<IEnumerable<Discharge>>(new List<Discharge>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds and retrieves a discharge record from the MongoDB collection based on the specified patient ID. If an error occurs during retrieval, an error is logged and null is returned.
|
||||
/// </summary>
|
||||
/// <param name="patientId">The ID of the patient for which to retrieve the discharge record.</param>
|
||||
/// <returns>A task representing the asynchronous operation, containing the discharge record if found, or null if an error occurs or the record is not found.</returns>
|
||||
public async Task<Discharge?> GetByPatientId(ObjectId patientId)
|
||||
{
|
||||
try
|
||||
@@ -313,6 +422,12 @@ public class DischargeRepository : MongoRepository<Discharge>, IDischargeReposit
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates indexes for the MongoDB collection based on the specified fields and options.
|
||||
/// The method ensures that unique indexes are created for the medical discharge and admin discharge fields, with a partial filter expression to only include documents where both fields exist.
|
||||
/// If an error occurs during index creation, an error is logged.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override async Task CreateIndexes()
|
||||
{
|
||||
var optionsUq = new CreateIndexOptions<Discharge>
|
||||
|
||||
Reference in New Issue
Block a user