Class DischargeRepository
- Namespace
- adas_core.Infrastructure.Repositories
- Assembly
- adas-core.Infrastructure.dll
Repository for managing Discharge entities in MongoDB. Provides methods for CRUD operations and specific queries related to discharges.
public class DischargeRepository : MongoRepository<Discharge>, IDischargeRepository, IMongoRepository<Discharge>
- Inheritance
-
DischargeRepository
- Implements
- Inherited Members
- Extension Methods
Constructors
DischargeRepository(IOptions<ApiSettings>, IMongoDatabase)
Initializes a new instance of the DischargeRepository class with the specified API settings and MongoDB database.
public DischargeRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database)
Parameters
apiSettingsIOptions<ApiSettings>The API settings containing configuration for the repository.
databaseIMongoDatabaseThe MongoDB database instance.
Methods
CountByUnitId(ObjectId)
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.
public Task<long> CountByUnitId(ObjectId unitId)
Parameters
unitIdObjectIdThe ID of the unit to count discharge records for.
Returns
- Task<long>
A task representing the asynchronous operation, containing the count of discharge records matching the specified unit ID, or 0 if an error occurs.
CreateIndexes()
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.
public override Task CreateIndexes()
Returns
Delete(ObjectId)
Deletes a discharge record from the MongoDB collection based on the specified ID.
public Task Delete(ObjectId id)
Parameters
idObjectIdThe ID of the discharge record to delete.
Returns
- Task
A task representing the asynchronous operation.
DeleteByUnitId(ObjectId)
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.
public Task<bool> DeleteByUnitId(ObjectId unitId)
Parameters
unitIdObjectIdThe ID of the unit for which to delete discharge records.
Returns
- Task<bool>
A task representing the asynchronous operation, containing true if the deletion was successful, or false if an error occurred.
DeleteMasterListOption(List<ObjectId>, OptionList, string)
Deletes master list options for discharge records in the MongoDB collection based on the specified unit IDs, update option, and master list type.
public Task<IEnumerable<Discharge>> DeleteMasterListOption(List<ObjectId> unitIds, OptionList opt, string typeName)
Parameters
unitIdsList<ObjectId>The list of unit IDs for which to delete master list options.
optOptionListThe update option specifying the changes to be applied to the master list.
typeNamestringThe name of the master list type to be updated.
Returns
- Task<IEnumerable<Discharge>>
A task representing the asynchronous operation, containing the updated discharge records, or an empty list if an error occurs.
FindAll()
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.
public Task<IEnumerable<Discharge>> FindAll()
Returns
- Task<IEnumerable<Discharge>>
A task representing the asynchronous operation, containing a list of all discharge records.
FindByDestination(string)
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.
public Task<IEnumerable<Discharge>?> FindByDestination(string destination)
Parameters
destinationstringThe destination to search for.
Returns
- Task<IEnumerable<Discharge>>
A task representing the asynchronous operation, containing a list of discharge records matching the specified destination, or null if an error occurs.
FindById(ObjectId)
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.
public Task<Discharge?> FindById(ObjectId id)
Parameters
idObjectIdThe ID of the discharge record to retrieve.
Returns
- Task<Discharge>
A task representing the asynchronous operation, containing the discharge record if found, or null if not found or an error occurs.
FindByPoCId(ObjectId)
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.
public Task<IEnumerable<Discharge>?> FindByPoCId(ObjectId pocId)
Parameters
pocIdObjectIdThe ID of the Point of Care to search for.
Returns
- Task<IEnumerable<Discharge>>
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.
FindByService(string)
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.
public Task<IEnumerable<Discharge>?> FindByService(string service)
Parameters
servicestringThe service to search for.
Returns
- Task<IEnumerable<Discharge>>
A task representing the asynchronous operation, containing a list of discharge records matching the specified service, or null if an error occurs.
FindByUnit(string)
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.
public Task<IEnumerable<Discharge>?> FindByUnit(string unit)
Parameters
unitstringThe unit name to search for.
Returns
- Task<IEnumerable<Discharge>>
A task representing the asynchronous operation, containing a list of discharge records matching the specified unit name, or null if an error occurs.
GetByPatientId(ObjectId)
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.
public Task<Discharge?> GetByPatientId(ObjectId patientId)
Parameters
patientIdObjectIdThe ID of the patient for which to retrieve the discharge record.
Returns
- Task<Discharge>
A task representing the asynchronous operation, containing the discharge record if found, or null if an error occurs or the record is not found.
GetCollectionName()
Gets the name of the MongoDB collection for discharges from the API settings.
public override string GetCollectionName()
Returns
- string
The name of the MongoDB collection for discharges.
GetDischargeByLocation(PatientLocation)
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.
public Task<Discharge?> GetDischargeByLocation(PatientLocation location)
Parameters
locationPatientLocationThe patient location to search for.
Returns
- Task<Discharge>
A task representing the asynchronous operation, containing the discharge record matching the specified patient location, or null if an error occurs.
GetDischargeByPointOfCareId(ObjectId)
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.
public Task<Discharge?> GetDischargeByPointOfCareId(ObjectId id)
Parameters
idObjectIdThe ID of the Point of Care to search for.
Returns
- Task<Discharge>
A task representing the asynchronous operation, containing the discharge record matching the specified Point of Care ID, or null if an error occurs.
GetDischargesByUnitIds(IEnumerable<ObjectId>?)
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.
public Task<IEnumerable<Discharge>?> GetDischargesByUnitIds(IEnumerable<ObjectId>? unitIds)
Parameters
unitIdsIEnumerable<ObjectId>The IDs of the units to search for.
Returns
- Task<IEnumerable<Discharge>>
A task representing the asynchronous operation, containing a list of discharge records matching the specified unit IDs, or null if an error occurs.
InsertOneAsync(Discharge)
Inserts a new discharge record into the MongoDB collection. Sets the discharge date to the current UTC time before insertion.
public override Task InsertOneAsync(Discharge discharge)
Parameters
dischargeDischargeThe discharge record to insert.
Returns
- Task
A task representing the asynchronous operation.
Update(Discharge)
Updates an existing discharge record in the MongoDB collection. If the update operation fails, a ConflictException is thrown.
public Task Update(Discharge discharge)
Parameters
dischargeDischargeThe discharge record to update.
Returns
- Task
A task representing the asynchronous operation.
Exceptions
UpdateMasterListOption(List<ObjectId>, UpdateOptionMasterListDto, string)
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.
public Task<IEnumerable<Discharge>> UpdateMasterListOption(List<ObjectId> unitIds, UpdateOptionMasterListDto opt, string typeName)
Parameters
unitIdsList<ObjectId>The list of unit IDs for which to update the master list options.
optUpdateOptionMasterListDtoThe update option specifying the changes to be applied to the master list.
typeNamestringThe name of the master list type to be updated.
Returns
- Task<IEnumerable<Discharge>>
A task representing the asynchronous operation, containing the updated discharge records, or an empty list if an error occurs.
UpdatePatient(ObjectId, Patient)
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.
public Task UpdatePatient(ObjectId id, Patient patient)
Parameters
idObjectIdThe ID of the discharge record to update.
patientPatientThe new patient information to set.
Returns
- Task
A task representing the asynchronous operation.
UpdateUnit(ObjectId, string)
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.
public Task UpdateUnit(ObjectId id, string unit)
Parameters
idObjectIdThe ID of the discharge record to update.
unitstringThe new unit name to set.
Returns
- Task
A task representing the asynchronous operation.