Skip to content

Commit

Permalink
Fixes #2570 Move IndividualToIndividualBuildingBlockMapper from prese…
Browse files Browse the repository at this point in the history
…ntation to core (#2572)
  • Loading branch information
rwmcintosh committed Apr 3, 2023
1 parent eccb8b4 commit 6b69018
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,24 @@
using OSPSuite.Core.Domain.Services;
using OSPSuite.Utility.Extensions;
using PKSim.Assets;
using PKSim.Core;
using PKSim.Core.Mappers;
using PKSim.Core.Model;
using PKSim.Core.Repositories;
using PKSim.Presentation.DTO.Mappers;

namespace PKSim.Presentation.Mappers
namespace PKSim.Core.Mappers
{
public interface IIndividualToIndividualBuildingBlockMapper : IPathAndValueBuildingBlockMapper<Individual, IndividualBuildingBlock>
{
}

public class IndividualToIndividualBuildingBlockMapper : PathAndValueBuildingBlockMapper<Individual, IndividualBuildingBlock, IndividualParameter>, IIndividualToIndividualBuildingBlockMapper
{
private readonly ICalculationMethodToCategoryCalculationMethodDTOMapper _calculationMethodDTOMapper;
private readonly IRepresentationInfoRepository _representationInfoRepository;
private readonly ICalculationMethodCategoryRepository _calculationMethodCategoryRepository;

public IndividualToIndividualBuildingBlockMapper(IObjectBaseFactory objectBaseFactory, IEntityPathResolver entityPathResolver, IApplicationConfiguration applicationConfiguration,
ILazyLoadTask lazyLoadTask, ICalculationMethodToCategoryCalculationMethodDTOMapper calculationMethodDTOMapper, ICalculationMethodCategoryRepository calculationMethodCategoryRepository) : base(objectBaseFactory, entityPathResolver, applicationConfiguration, lazyLoadTask)
ILazyLoadTask lazyLoadTask, IRepresentationInfoRepository representationInfoRepository, ICalculationMethodCategoryRepository calculationMethodCategoryRepository) : base(objectBaseFactory, entityPathResolver, applicationConfiguration, lazyLoadTask)
{
_calculationMethodDTOMapper = calculationMethodDTOMapper;
_representationInfoRepository = representationInfoRepository;
_calculationMethodCategoryRepository = calculationMethodCategoryRepository;
}

Expand All @@ -50,14 +47,20 @@ public override IndividualBuildingBlock MapFrom(Individual input)
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Weight, input.OriginData.Weight);
addOriginDataToBuildingBlock(buildingBlock, PKSimConstants.UI.Population, input.OriginData.Population?.DisplayName);

input.OriginData.AllCalculationMethods().Where(cm => _calculationMethodCategoryRepository.HasMoreThanOneOption(cm, input.Species)).MapAllUsing(_calculationMethodDTOMapper)
.Each(x => addOriginDataToBuildingBlock(buildingBlock, x.DisplayName, x.CategoryItem.DisplayName));
input.OriginData.AllCalculationMethods().Where(cm => _calculationMethodCategoryRepository.HasMoreThanOneOption(cm, input.Species))
.Each(x => addCalculationMethodOriginDataToBuildingBlock(buildingBlock, x));

buildingBlock.OriginData.ValueOrigin = input.OriginData.ValueOrigin.Clone();

return buildingBlock;
}

private void addCalculationMethodOriginDataToBuildingBlock(IndividualBuildingBlock buildingBlock, CalculationMethod calculationMethod)
{
var repInfo = _representationInfoRepository.InfoFor(RepresentationObjectType.CATEGORY, calculationMethod.Category);
addOriginDataToBuildingBlock(buildingBlock, repInfo.DisplayName, calculationMethod.Category);
}

private void addOriginDataToBuildingBlock(IndividualBuildingBlock buildingBlock, string key, OriginDataParameter parameter)
{
if (parameter == null)
Expand All @@ -76,7 +79,7 @@ private void addOriginDataToBuildingBlock(IndividualBuildingBlock buildingBlock,
if (string.IsNullOrEmpty(value))
return;

buildingBlock.OriginData.AddOriginDataItem(new OriginDataItem {Name = key, Value = value});
buildingBlock.OriginData.AddOriginDataItem(new OriginDataItem { Name = key, Value = value });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using OSPSuite.Core.Serialization.Xml;
using OSPSuite.Core.Services;
using PKSim.Assets;
using PKSim.Core.Mappers;
using PKSim.Core.Model;
using PKSim.Presentation.Mappers;

namespace PKSim.Presentation.UICommands
{
Expand Down
8 changes: 4 additions & 4 deletions src/PKSim.UI.Starter/IndividualCreator.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using OSPSuite.Core.Commands.Core;
using PKSim.Core.Mappers;
using PKSim.Core.Model;
using PKSim.Presentation;
using PKSim.Presentation.Mappers;
using PKSim.Presentation.Presenters.Individuals;

namespace PKSim.UI.Starter
Expand All @@ -17,10 +17,10 @@ public static object CreateIndividual()
presenter.Initialize();
var workspace = container.Resolve<IWorkspace>();
workspace.Project = new PKSimProject();
if (presenter.Create().IsEmpty())

if (presenter.Create().IsEmpty())
return null;

var mapper = container.Resolve<IIndividualToIndividualBuildingBlockMapper>();
return mapper.MapFrom(presenter.Individual);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
using OSPSuite.Core.Domain.Builder;
using OSPSuite.Core.Domain.Services;
using PKSim.Core;
using PKSim.Core.Mappers;
using PKSim.Core.Model;
using PKSim.Core.Repositories;
using PKSim.Infrastructure;
using PKSim.Presentation.DTO.Mappers;
using PKSim.Presentation.Mappers;

namespace PKSim.Presentation
{
Expand All @@ -21,7 +20,6 @@ public class concern_for_IndividualToIndividualBuildingBlockMapper : ContextSpec
private IObjectBaseFactory _objectBaseFactory;
private IApplicationConfiguration _applicationConfiguration;
private ILazyLoadTask _lazyLoadTask;
private ICalculationMethodToCategoryCalculationMethodDTOMapper _calculationMethodDTOMapper;
private EntityPathResolverForSpecs _objectPathFactory;
private ICalculationMethodCategoryRepository _calculationMethodCategoryRepository;
private static CalculationMethodCategory _category1;
Expand All @@ -34,15 +32,14 @@ protected override void Context()
_objectPathFactory = new EntityPathResolverForSpecs();
_objectBaseFactory = A.Fake<IObjectBaseFactory>();
var representationInfoRepository = A.Fake<IRepresentationInfoRepository>();
_calculationMethodDTOMapper = new CalculationMethodToCategoryCalculationMethodDTOMapper(representationInfoRepository);
A.CallTo(() => representationInfoRepository.InfoFor(A<RepresentationObjectType>._, A<string>._)).Returns(new RepresentationInfo { DisplayName = "displayName" });

_calculationMethodCategoryRepository = A.Fake<ICalculationMethodCategoryRepository>();
updateOriginDataForTest(_individual.OriginData);

A.CallTo(() => _objectBaseFactory.Create<IndividualBuildingBlock>()).Returns(new IndividualBuildingBlock());
A.CallTo(() => _objectBaseFactory.Create<IndividualParameter>()).Returns(new IndividualParameter());
sut = new IndividualToIndividualBuildingBlockMapper(_objectBaseFactory, _objectPathFactory, _applicationConfiguration, _lazyLoadTask, _calculationMethodDTOMapper, _calculationMethodCategoryRepository);
sut = new IndividualToIndividualBuildingBlockMapper(_objectBaseFactory, _objectPathFactory, _applicationConfiguration, _lazyLoadTask, representationInfoRepository, _calculationMethodCategoryRepository);
}

private void updateOriginDataForTest(OriginData originData)
Expand All @@ -53,7 +50,7 @@ private void updateOriginDataForTest(OriginData originData)
originData.GestationalAge = new OriginDataParameter(52, "weeks", "Gestational Age");

_category1 = new CalculationMethodCategory();


var calculationMethod = new CalculationMethod
{
Expand All @@ -74,14 +71,13 @@ private void updateOriginDataForTest(OriginData originData)
Category = "category1",
};
calculationMethod.AddSpecies(_individual.Species.Name);

_category1.Add(calculationMethod);

calculationMethod = new CalculationMethod
{
Category = "category2",
Name = "calculationMethod1"

};
originData.CalculationMethodCache.AddCalculationMethod(calculationMethod);
originData.DiseaseState = new DiseaseState
Expand Down

0 comments on commit 6b69018

Please sign in to comment.