using adas_core.Application.Repositories.Interfaces; using adas_core.Application.Services.Interfaces; using adas_core.Domain.Models.MongoModels; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using MongoDB.Bson; namespace adas_core.Application.Services; public class ArchivePatientCarePlanService( IArchivePatientCarePlanRepository archivedPatientRepository, ILogger logger, IHttpContextAccessor httpContextAccessor, ILocalAuditService auditService) : IArchivePatientCarePlanService { #region Create public async Task InsertOneAsync(PatientCarePlan patient) { await archivedPatientRepository.InsertOneAsync(patient); logger.LogInformation( "Inserted archived patient care plan for patientId: {PatientId}, patientNumber: {PatientNumber}", patient.PatientId, patient.PatientNumber); await auditService.CreateAuditLogAsync(httpContextAccessor.HttpContext?.User!, null, patient); return patient; } public async Task InsertManyAsync(List patientCarePla) { await archivedPatientRepository.InsertManyAsync(patientCarePla); logger.LogInformation("Inserted {Count} archived patient care plans", patientCarePla.Count); foreach (var patient in patientCarePla) await auditService.CreateAuditLogAsync(httpContextAccessor.HttpContext?.User!, null, patient); } #endregion #region Read public async Task?> FindByPatientId(ObjectId patientId) { return await archivedPatientRepository.FindByPatientId(patientId); } public async Task?> FindByPatientId(string patientId) { return await archivedPatientRepository.FindByPatientId(patientId); } public async Task?> FindByPatientNumber(string patientId) { return await archivedPatientRepository.FindByPatientNumber(patientId); } public Task> FindAll() { return archivedPatientRepository.FindAll(); } #endregion }