Template
87 lines
4.8 KiB
C#
87 lines
4.8 KiB
C#
using Riok.Mapperly.Abstractions;
|
|
using Strata.ContinuousImprovement.Biz.Dtos;
|
|
using Strata.ContinuousImprovement.Biz.Encounter.Opportunities;
|
|
using Strata.ContinuousImprovement.Biz.Encounter.Opportunities.Filters;
|
|
using Strata.ContinuousImprovement.Biz.OrgDefined.Queries;
|
|
using Strata.ContinuousImprovement.Biz.Shared;
|
|
using System.Text.Json;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace Strata.ContinuousImprovement.Api.Test.Integration.Mapperly
|
|
{
|
|
[Mapper(UseDeepCloning = true, EnumMappingStrategy = EnumMappingStrategy.ByName, EnumMappingIgnoreCase = true)]
|
|
public static partial class OpportunityMetricBaseMap
|
|
{
|
|
public static OpportunityMetricBase Map(this ENOpportunityDataModel dataModel)
|
|
{
|
|
var enOpportunityBase = JsonSerializer.Deserialize<ENOpportunityBaseFilters>(dataModel.EncounterOpportunityJSON);
|
|
OpportunityMetricBase target = new OpportunityMetricBase();
|
|
if (enOpportunityBase != null)
|
|
{
|
|
target = enOpportunityBase.Map();
|
|
target.CaseTypeIds = enOpportunityBase
|
|
.CaseTypes.Select(fh => int.TryParse(fh.Id, out var id) ? id : -1).Where(id => id >= 0).ToList();
|
|
switch (enOpportunityBase.EncounterOpportunityLevel)
|
|
{
|
|
case OpportunityLevel.Entity:
|
|
target.OpportunityLevelIds = enOpportunityBase
|
|
.Entities.Select(fh => int.TryParse(fh.Id, out var id) ? id : -1).Where(id => id >= 0).ToList();
|
|
break;
|
|
case OpportunityLevel.ServiceLine:
|
|
target.OpportunityLevelIds = enOpportunityBase
|
|
.ServiceLines.Select(fh => int.TryParse(fh.Id, out var id) ? id : -1).Where(id => id >= 0).ToList();
|
|
break;
|
|
case OpportunityLevel.Specialty:
|
|
target.OpportunityLevelIds = enOpportunityBase
|
|
.Specialties.Select(fh => int.TryParse(fh.Id, out var id) ? id : -1).Where(id => id >= 0).ToList();
|
|
break;
|
|
case OpportunityLevel.Provider:
|
|
target.OpportunityLevelIds = enOpportunityBase
|
|
.Providers.Select(fh => int.TryParse(fh.Id, out var id) ? id : -1).Where(id => id >= 0).ToList();
|
|
break;
|
|
}
|
|
}
|
|
return target;
|
|
}
|
|
|
|
public static OpportunityMetricBase Map(this ENOpportunityDto source)
|
|
{
|
|
var target = source.MapTo();
|
|
var enOpportunityBase = JsonSerializer.Deserialize<ENOpportunityBaseFilters>(source.EncounterOpportunityJSON);
|
|
var regexp = new Regex(@"[^\d]*\|([\d]+)", RegexOptions.Compiled);
|
|
if (enOpportunityBase != null)
|
|
{
|
|
target = enOpportunityBase.Map();
|
|
target.CaseTypeIds = enOpportunityBase
|
|
.CaseTypes.Select(fh => int.TryParse(regexp.Replace(fh.Id, "$1"), out var id) ? id : -1).Where(id => id >= 0).ToList();
|
|
switch (enOpportunityBase.EncounterOpportunityLevel)
|
|
{
|
|
case OpportunityLevel.Entity:
|
|
target.OpportunityLevelIds = enOpportunityBase
|
|
.Entities.Select(fh => int.TryParse(regexp.Replace(fh.Id, "$1"), out var id) ? id : -1).Where(id => id >= 0).ToList();
|
|
break;
|
|
case OpportunityLevel.ServiceLine:
|
|
target.OpportunityLevelIds = enOpportunityBase
|
|
.ServiceLines.Select(fh => int.TryParse(regexp.Replace(fh.Id, "$1"), out var id) ? id : -1).Where(id => id >= 0).ToList();
|
|
break;
|
|
case OpportunityLevel.Specialty:
|
|
target.OpportunityLevelIds = enOpportunityBase
|
|
.Specialties.Select(fh => int.TryParse(regexp.Replace(fh.Id, "$1"), out var id) ? id : -1).Where(id => id >= 0).ToList();
|
|
break;
|
|
case OpportunityLevel.Provider:
|
|
target.OpportunityLevelIds = enOpportunityBase
|
|
.Providers.Select(fh => int.TryParse(regexp.Replace(fh.Id, "$1"), out var id) ? id : -1).Where(id => id >= 0).ToList();
|
|
break;
|
|
}
|
|
target.OpportunityLevelIdAsCSV = string.Join(",", target.OpportunityLevelIds);
|
|
}
|
|
return target;
|
|
}
|
|
|
|
public static partial OpportunityMetricBase Map(this ENOpportunityBaseFilters enOpportunityBase);
|
|
|
|
[MapperIgnoreSource(nameof(ENOpportunityDto.OpportunityLevelIds))]
|
|
private static partial OpportunityMetricBase MapTo(this ENOpportunityDto source);
|
|
}
|
|
}
|