Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Azure_Pipelines/azure-pipelines.tenant.cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ trigger:
paths:
include:
- DotNet/Tenant/*
- DotNet/DMRP/*
- DotNet/Shared/*
exclude:
- '*'
Expand Down
7 changes: 7 additions & 0 deletions DotNet/Admin.BFF/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@
"Match": {
"Path": "api/terminology/{**catch-all}"
}
},
"route15": {
"ClusterId": "TenantService",
"AuthorizationPolicy": "AuthenticatedUser",
"Match": {
"Path": "api/dmrp/{**catch-all}"
}
}
},
"Clusters": {
Expand Down
109 changes: 109 additions & 0 deletions DotNet/DMRP/Business/Managers/FacilityReportingPlanManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using LantanaGroup.Link.DMRP.Data.Entities;
using LantanaGroup.Link.Shared.Application.Models;
using LantanaGroup.Link.Shared.Application.Services.Security;
using LantanaGroup.Link.Shared.Domain.Repositories.Interfaces;
using OpenTelemetry.Trace;
using System.Diagnostics;

namespace LantanaGroup.Link.DMRP.Business.Managers
{
public interface IFacilityReportingPlanManager
{
Task<FacilityReportingPlan> CreateAsync(FacilityReportingPlan newFacilityReportingPlan, CancellationToken cancellationToken = default);
Task UpdateAsync(string id, FacilityReportingPlan facilityReportingPlan, CancellationToken cancellationToken = default);
Task DeleteAsync(string id, CancellationToken cancellationToken = default);
}

public class FacilityReportingPlanManager : IFacilityReportingPlanManager
{
private readonly ILogger<FacilityReportingPlanManager> _logger;
private readonly IEntityRepository<FacilityReportingPlan> _repository;

public FacilityReportingPlanManager(ILogger<FacilityReportingPlanManager> logger, IEntityRepository<FacilityReportingPlan> repository)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_repository = repository ?? throw new ArgumentNullException(nameof(repository));
}

public async Task<FacilityReportingPlan> CreateAsync(FacilityReportingPlan newFacilityReportingPlan, CancellationToken cancellationToken = default)
{
using Activity? activity = ServiceActivitySource.Instance.StartActivity("Create Facility Reporting Plan");

try
{
await _repository.AddAsync(newFacilityReportingPlan, cancellationToken);
await _repository.SaveChangesAsync(cancellationToken);
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
Activity.Current?.SetStatus(ActivityStatusCode.Error);
Activity.Current?.AddException(ex);
throw new ApplicationException("Facility reporting plan failed to create. " + ex.Message);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

return newFacilityReportingPlan;
}

public async Task UpdateAsync(string id, FacilityReportingPlan facilityReportingPlan, CancellationToken cancellationToken = default)
{
using Activity? activity = ServiceActivitySource.Instance.StartActivity("Update Facility Reporting Plan");

var existing = await _repository.GetAsync(id, cancellationToken);
if (existing is null)
{
_logger.LogError("Facility reporting plan with Id: {Id} not found", id.SanitizeForLog());
throw new ApplicationException($"Facility reporting plan with Id: {id} not found");
}

// TODO: Map `facilityReportingPlan` to `existing`

try
{
_repository.Update(existing);
await _repository.SaveChangesAsync(cancellationToken);
Comment thread
smailliwcs marked this conversation as resolved.
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
Activity.Current?.SetStatus(ActivityStatusCode.Error);
Activity.Current?.AddException(ex);
throw new ApplicationException($"Facility reporting plan {id} failed to update. " + ex.Message);
}
}

public async Task DeleteAsync(string id, CancellationToken cancellationToken = default)
{
using Activity? activity = ServiceActivitySource.Instance.StartActivity("Delete Facility Reporting Plan");

var existing = await _repository.GetAsync(id, cancellationToken);
if (existing is null)
{
_logger.LogError("Facility reporting plan with Id: {Id} not found", id.SanitizeForLog());
throw new ApplicationException($"Facility reporting plan with Id: {id} not found");
}

try
{
_repository.Remove(existing);
await _repository.SaveChangesAsync(cancellationToken);
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
Activity.Current?.SetStatus(ActivityStatusCode.Error);
Activity.Current?.AddException(ex);
throw new ApplicationException($"Facility reporting plan {id} failed to delete. " + ex.Message);
}
}
}
}
109 changes: 109 additions & 0 deletions DotNet/DMRP/Business/Managers/MeasureMappingManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using LantanaGroup.Link.DMRP.Data.Entities;
using LantanaGroup.Link.Shared.Application.Models;
using LantanaGroup.Link.Shared.Application.Services.Security;
using LantanaGroup.Link.Shared.Domain.Repositories.Interfaces;
using OpenTelemetry.Trace;
using System.Diagnostics;

namespace LantanaGroup.Link.DMRP.Business.Managers
{
public interface IMeasureMappingManager
{
Task<MeasureMapping> CreateAsync(MeasureMapping newMeasureMapping, CancellationToken cancellationToken = default);
Task UpdateAsync(string id, MeasureMapping measureMapping, CancellationToken cancellationToken = default);
Task DeleteAsync(string id, CancellationToken cancellationToken = default);
}

public class MeasureMappingManager : IMeasureMappingManager
{
private readonly ILogger<MeasureMappingManager> _logger;
private readonly IEntityRepository<MeasureMapping> _repository;

public MeasureMappingManager(ILogger<MeasureMappingManager> logger, IEntityRepository<MeasureMapping> repository)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_repository = repository ?? throw new ArgumentNullException(nameof(repository));
}

public async Task<MeasureMapping> CreateAsync(MeasureMapping newMeasureMapping, CancellationToken cancellationToken = default)
{
using Activity? activity = ServiceActivitySource.Instance.StartActivity("Create Measure Mapping");

try
{
await _repository.AddAsync(newMeasureMapping, cancellationToken);
await _repository.SaveChangesAsync(cancellationToken);
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
Activity.Current?.SetStatus(ActivityStatusCode.Error);
Activity.Current?.AddException(ex);
throw new ApplicationException("Measure mapping failed to create. " + ex.Message);
}

return newMeasureMapping;
}

public async Task UpdateAsync(string id, MeasureMapping measureMapping, CancellationToken cancellationToken = default)
{
using Activity? activity = ServiceActivitySource.Instance.StartActivity("Update Measure Mapping");

var existing = await _repository.GetAsync(id, cancellationToken);
if (existing is null)
{
_logger.LogError("Measure mapping with Id: {Id} not found", id.SanitizeForLog());
throw new ApplicationException($"Measure mapping with Id: {id} not found");
}

// TODO: Map `measureMapping` to `existing`

try
{
_repository.Update(existing);
await _repository.SaveChangesAsync(cancellationToken);
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
Activity.Current?.SetStatus(ActivityStatusCode.Error);
Activity.Current?.AddException(ex);
throw new ApplicationException($"Measure mapping {id} failed to update. " + ex.Message);
}
}

public async Task DeleteAsync(string id, CancellationToken cancellationToken = default)
{
using Activity? activity = ServiceActivitySource.Instance.StartActivity("Delete Measure Mapping");

var existing = await _repository.GetAsync(id, cancellationToken);
if (existing is null)
{
_logger.LogError("Measure mapping with Id: {Id} not found", id.SanitizeForLog());
throw new ApplicationException($"Measure mapping with Id: {id} not found");
}

try
{
_repository.Remove(existing);
await _repository.SaveChangesAsync(cancellationToken);
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
Activity.Current?.SetStatus(ActivityStatusCode.Error);
Activity.Current?.AddException(ex);
throw new ApplicationException($"Measure mapping {id} failed to delete. " + ex.Message);
}
}
}
}
49 changes: 49 additions & 0 deletions DotNet/DMRP/Business/Queries/FacilityReportingPlanQueries.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using LantanaGroup.Link.DMRP.Data.Entities;
using LantanaGroup.Link.DMRP.Models;
using LantanaGroup.Link.Shared.Application.Enums;
using LantanaGroup.Link.Shared.Application.Models.Integration.DMRP;
using LantanaGroup.Link.Shared.Domain.Repositories.Interfaces;

namespace LantanaGroup.Link.DMRP.Business.Queries
{
public interface IFacilityReportingPlanQueries
{
Task<FacilityReportingPlanModel?> GetAsync(string id, CancellationToken cancellationToken = default);

Task<PagedFacilityReportingPlanDto> PagedSearchAsync(string sortBy = "Id", SortOrder sortOrder = SortOrder.Descending,
int pageSize = 10, int pageNumber = 1, CancellationToken cancellationToken = default);
}

public class FacilityReportingPlanQueries : IFacilityReportingPlanQueries
{
private readonly IEntityRepository<FacilityReportingPlan> _repository;

public FacilityReportingPlanQueries(IEntityRepository<FacilityReportingPlan> repository)
{
_repository = repository ?? throw new ArgumentNullException(nameof(repository));
}

public async Task<FacilityReportingPlanModel?> GetAsync(string id, CancellationToken cancellationToken = default)
{
var entity = await _repository.FirstOrDefaultAsync(p => p.Id == id, cancellationToken);

return entity == null ? null : ToModel(entity);
}

public async Task<PagedFacilityReportingPlanDto> PagedSearchAsync(string sortBy = "Id",
SortOrder sortOrder = SortOrder.Descending, int pageSize = 10, int pageNumber = 1,
CancellationToken cancellationToken = default)
{
var (records, metadata) = await _repository.SearchAsync(p => true, sortBy, sortOrder,
pageSize, pageNumber, cancellationToken);

return new PagedFacilityReportingPlanDto
{
Metadata = metadata,
Records = records.Select(ToModel).ToList()
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

private static FacilityReportingPlanModel ToModel(FacilityReportingPlan entity) => new() { Id = entity.Id };
}
}
49 changes: 49 additions & 0 deletions DotNet/DMRP/Business/Queries/MeasureMappingQueries.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using LantanaGroup.Link.DMRP.Data.Entities;
using LantanaGroup.Link.DMRP.Models;
using LantanaGroup.Link.Shared.Application.Enums;
using LantanaGroup.Link.Shared.Application.Models.Integration.DMRP;
using LantanaGroup.Link.Shared.Domain.Repositories.Interfaces;

namespace LantanaGroup.Link.DMRP.Business.Queries
{
public interface IMeasureMappingQueries
{
Task<MeasureMappingModel?> GetAsync(string id, CancellationToken cancellationToken = default);

Task<PagedMeasureMappingDto> PagedSearchAsync(string sortBy = "Id", SortOrder sortOrder = SortOrder.Descending,
int pageSize = 10, int pageNumber = 1, CancellationToken cancellationToken = default);
}

public class MeasureMappingQueries : IMeasureMappingQueries
{
private readonly IEntityRepository<MeasureMapping> _repository;

public MeasureMappingQueries(IEntityRepository<MeasureMapping> repository)
{
_repository = repository ?? throw new ArgumentNullException(nameof(repository));
}

public async Task<MeasureMappingModel?> GetAsync(string id, CancellationToken cancellationToken = default)
{
var entity = await _repository.FirstOrDefaultAsync(m => m.Id == id, cancellationToken);

return entity == null ? null : ToModel(entity);
}

public async Task<PagedMeasureMappingDto> PagedSearchAsync(string sortBy = "Id",
SortOrder sortOrder = SortOrder.Descending, int pageSize = 10, int pageNumber = 1,
CancellationToken cancellationToken = default)
{
var (records, metadata) = await _repository.SearchAsync(m => true, sortBy, sortOrder,
pageSize, pageNumber, cancellationToken);

return new PagedMeasureMappingDto
{
Metadata = metadata,
Records = records.Select(ToModel).ToList()
};
}

private static MeasureMappingModel ToModel(MeasureMapping entity) => new() { Id = entity.Id };
}
}
16 changes: 16 additions & 0 deletions DotNet/DMRP/Config/DmrpSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace LantanaGroup.Link.DMRP.Config
{
/// <summary>
/// Settings that control the DMRP module hosted by the Tenant service.
/// </summary>
public class DmrpSettings
{
public const string ConfigSectionName = "DMRP";

/// <summary>
/// When false, none of the DMRP controllers, persistence or scheduling behavior is registered
/// and the host continues to perform facility dQM reporting on its own.
/// </summary>
public bool Enabled { get; set; }
}
}
Loading
Loading