=== 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:
@@ -13,6 +13,7 @@ namespace adas_core.Infrastructure.Repositories;
|
||||
/// Repository implementation for managing PatientObservation archive entities in MongoDB.
|
||||
/// Provides operations for storing and retrieving historical patient observations.
|
||||
/// </summary>
|
||||
/// <!-- aidoc:v1 sig=208c7de -->
|
||||
public class ObservationArchiveRepository : MongoRepository<PatientObservation>, IObservationArchiveRepository
|
||||
{
|
||||
private readonly ApiSettings _apiSettings;
|
||||
@@ -23,6 +24,7 @@ public class ObservationArchiveRepository : MongoRepository<PatientObservation>,
|
||||
/// <param name="apiSettings">API settings containing collection names configuration.</param>
|
||||
/// <param name="database">The MongoDB database instance.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown when apiSettings is null.</exception>
|
||||
/// <!-- aidoc:v1 sig=fa9b83d body=d2b18a3 -->
|
||||
public ObservationArchiveRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database) : base(database)
|
||||
{
|
||||
if (apiSettings == null) throw new ArgumentNullException(nameof(apiSettings));
|
||||
@@ -38,6 +40,8 @@ public class ObservationArchiveRepository : MongoRepository<PatientObservation>,
|
||||
/// <param name="lastDate">The cutoff date to filter observations (inclusive).</param>
|
||||
/// <param name="filterObservations">Optional list of observation names to filter by. If null, retrieves all distinct observations.</param>
|
||||
/// <returns>A list of PatientObservation entities sorted by time descending.</returns>
|
||||
/// <!-- aidoc-review:v1 severity=low kind=wrong_returns
|
||||
/// "The returned list is sorted by time descending only within each observation name group (each foreach iteration), not globally across all observation types, since results are appended via AddRange without re-sorting." -->
|
||||
public async Task<List<PatientObservation>> AggregatedPatientLastObservations(ObjectId patientId, int num,
|
||||
DateTime lastDate, List<string>? filterObservations = null)
|
||||
{
|
||||
@@ -64,6 +68,7 @@ public class ObservationArchiveRepository : MongoRepository<PatientObservation>,
|
||||
/// Gets the name of the collection for archived patient observations.
|
||||
/// </summary>
|
||||
/// <returns>The collection name from API settings, or default "archive_patients_observations".</returns>
|
||||
/// <!-- aidoc:v1 sig=94e22ff body=81daff1 -->
|
||||
public override string GetCollectionName()
|
||||
{
|
||||
return _apiSettings.ArchivePatientsObservations ?? "archive_patients_observations";
|
||||
@@ -76,6 +81,7 @@ public class ObservationArchiveRepository : MongoRepository<PatientObservation>,
|
||||
/// <param name="patientObservation">The PatientObservation entity to insert.</param>
|
||||
/// <exception cref="MongoWriteException">Throws when duplicate key error persists after max retries.</exception>
|
||||
/// <exception cref="Exception">Throws when insertion fails for reasons other than duplicate key.</exception>
|
||||
/// <!-- aidoc:v1 sig=ae8c780 body=b4e7347 -->
|
||||
public new async Task InsertOneAsync(PatientObservation patientObservation)
|
||||
{
|
||||
const int maxRetries = 2; // Número máximo de reintentos
|
||||
@@ -117,6 +123,8 @@ public class ObservationArchiveRepository : MongoRepository<PatientObservation>,
|
||||
/// </summary>
|
||||
/// <param name="date">The cutoff date. Observations older than this date will be deleted.</param>
|
||||
/// <returns>The number of deleted documents.</returns>
|
||||
/// <!-- aidoc-review:v1 severity=high kind=wrong_returns
|
||||
/// "Method returns Task, not Task<int>; the number of deleted documents is not exposed to callers." -->
|
||||
public async Task DeleteBeforeDate(DateTime date)
|
||||
{
|
||||
var filter = Builders<PatientObservation>.Filter.Lt(po => po.Time, date);
|
||||
@@ -128,6 +136,7 @@ public class ObservationArchiveRepository : MongoRepository<PatientObservation>,
|
||||
/// </summary>
|
||||
/// <param name="observations">An enumerable of PatientObservation entities to insert.</param>
|
||||
/// <returns>The count of successfully inserted documents.</returns>
|
||||
/// <!-- aidoc:v1 sig=f522e46 body=daebb76 -->
|
||||
public async Task<long> InsertBatch(IEnumerable<PatientObservation> observations)
|
||||
{
|
||||
var writes = new List<WriteModel<PatientObservation>>();
|
||||
@@ -143,6 +152,8 @@ public class ObservationArchiveRepository : MongoRepository<PatientObservation>,
|
||||
/// </summary>
|
||||
/// <param name="patientId">The ObjectId of the patient.</param>
|
||||
/// <returns>A list of all PatientObservation entities for the patient.</returns>
|
||||
/// <!-- aidoc-review:v1 severity=high kind=wrong_summary
|
||||
/// "Summary states observations are 'archived', but the code only filters by PatientId with no archive-status filter, implying retrieval behavior the code does not perform." -->
|
||||
public async Task<List<PatientObservation>> FindAllFromPatient(ObjectId patientId)
|
||||
{
|
||||
var filter = Builders<PatientObservation>.Filter.Eq(p => p.PatientId, patientId);
|
||||
@@ -158,6 +169,7 @@ public class ObservationArchiveRepository : MongoRepository<PatientObservation>,
|
||||
/// <param name="patientId">The ObjectId of the patient.</param>
|
||||
/// <param name="filterObservations">Optional pre-filtered list of observation names. If null or empty, computes distinct values.</param>
|
||||
/// <returns>A list of distinct observation name strings.</returns>
|
||||
/// <!-- aidoc:v1 sig=b7f7b8f body=198b120 -->
|
||||
private async Task<List<string>> AggregatePatientObservations(ObjectId patientId,
|
||||
List<string>? filterObservations = null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user