diff --git a/src/PKSim.Core/Model/SchemaItem.cs b/src/PKSim.Core/Model/SchemaItem.cs index 8288deae0..868b8ebb0 100644 --- a/src/PKSim.Core/Model/SchemaItem.cs +++ b/src/PKSim.Core/Model/SchemaItem.cs @@ -52,10 +52,12 @@ public string TargetOrgan public bool NeedsFormulation => ApplicationType.NeedsFormulation; - public bool IsOral => ApplicationType==ApplicationTypes.Oral; + public bool IsOral => ApplicationType == ApplicationTypes.Oral; + + public bool IsUserDefined => ApplicationType == ApplicationTypes.UserDefined; + + public bool IsIV => ApplicationType == ApplicationTypes.Intravenous || ApplicationType == ApplicationTypes.IntravenousBolus; - public bool IsUserDefined => ApplicationType==ApplicationTypes.UserDefined; - public virtual IParameter StartTime => this.Parameter(Constants.Parameters.START_TIME); public virtual IParameter Dose => this.Parameter(CoreConstants.Parameters.INPUT_DOSE); diff --git a/src/PKSim.Core/Services/PKAnalysesTask.cs b/src/PKSim.Core/Services/PKAnalysesTask.cs index 8fa45a004..e9cc72bef 100644 --- a/src/PKSim.Core/Services/PKAnalysesTask.cs +++ b/src/PKSim.Core/Services/PKAnalysesTask.cs @@ -27,9 +27,7 @@ using static PKSim.Core.CoreConstants.PKAnalysis; using static PKSim.Core.CoreConstants.Species; using static PKSim.Core.CoreConstants.Units; -using Compound = PKSim.Core.Model.Compound; using IParameterFactory = PKSim.Core.Model.IParameterFactory; -using PKAnalysis = PKSim.Core.Model.PKAnalysis; namespace PKSim.Core.Services { @@ -110,7 +108,7 @@ public PKAnalysesTask(ILazyLoadTask lazyLoadTask, IStatisticalDataCalculator statisticalDataCalculator, IRepresentationInfoRepository representationInfoRepository, IParameterFactory parameterFactory, IProtocolToSchemaItemsMapper protocolToSchemaItemsMapper, IProtocolFactory protocolFactory, - IGlobalPKAnalysisRunner globalPKAnalysisRunner, IVSSCalculator vssCalculator, IInteractionTask interactionTask, ICloner cloner, IEntityPathResolver entityPathResolver) : + IGlobalPKAnalysisRunner globalPKAnalysisRunner, IVSSCalculator vssCalculator, IInteractionTask interactionTask, ICloner cloner, IEntityPathResolver entityPathResolver) : base(lazyLoadTask, pkValuesCalculator, pkParameterRepository, pkCalculationOptionsFactory) { _lazyLoadTask = lazyLoadTask; @@ -145,10 +143,7 @@ public PopulationSimulationPKAnalyses CalculateFor(PopulationSimulation populati { var globalPKAnalysesForIndividuals = new Cache(); var analyses = base.CalculateFor(populationSimulation, populationSimulation.Results, - individualId => - { - updateBodyWeightForIndividual(bodyWeightParameter, allBodyWeights, individualId); - }, + individualId => { updateBodyWeightForIndividual(bodyWeightParameter, allBodyWeights, individualId); }, (individualId, options, compoundName) => { var globalPKAnalysis = globalPkAnalysisForIndividual(globalPKAnalysesForIndividuals, individualId); @@ -234,6 +229,7 @@ private static CompoundPKContext createCompoundPKContext(Compound compound, Indi compoundPK.AddDDIAucInf(individualId, individualSimulation.AucDDI[compound.Name]); compoundPK.AddDDICMax(individualId, individualSimulation.CMaxDDI[compound.Name]); } + return compoundPKContext; } @@ -247,7 +243,7 @@ private Container createCompoundContainer(PopulationSimulation populationSimulat var compoundContainer = new Container().WithName(compoundName); populationSimulation.PKAnalyses.AllPKParametersFor(compoundName).Each(quantityPKParameter => { - double? defaultValue = new SortedFloatArray(quantityPKParameter.ValuesAsArray, alreadySorted:false).Median(); + double? defaultValue = new SortedFloatArray(quantityPKParameter.ValuesAsArray, alreadySorted: false).Median(); if (double.IsNaN(defaultValue.Value)) defaultValue = null; @@ -319,7 +315,7 @@ private IContainer calculateGlobalPKAnalysisFor(Simulation simulation, Compound var vssPlasmaOverF = createParameter(VssPlasmaOverF, bloodPlasmaPK[Vss], VolumePerBodyWeight); var vdPlasma = createParameter(VdPlasma, bloodPlasmaPK[Vd], VolumePerBodyWeight); var vdPlasmaOverF = createParameter(VdPlasmaOverF, bloodPlasmaPK[Vd], VolumePerBodyWeight); - if(simulation is IndividualSimulation) + if (simulation is IndividualSimulation) vssPhysChem = createParameter(VssPhysChem, calculateVSSPhysChemFor(simulation, compoundName), VolumePerBodyWeight); var totalPlasmaCL = createParameter(TotalPlasmaCL, bloodPlasmaPK[PKParameters.CL], FlowPerWeight); @@ -346,7 +342,7 @@ private IContainer calculateGlobalPKAnalysisFor(Simulation simulation, Compound if (isIntravenous(schemaItem)) { container.AddChildren(vssPlasma, vdPlasma, totalPlasmaCL); - if(vssPhysChem != null) + if (vssPhysChem != null) container.Add(vssPhysChem); return container; @@ -530,9 +526,8 @@ public void CalculateBioavailabilityFor(Simulation simulation, string compoundNa // We know this is a valid cast because it is cloned from simulation var populationSimulation = simulation.DowncastTo(); CalculateFor(ivPopulationSimulation, ivCompoundPKContext); - var contextForPopulationSimulation = createContextForPopulationSimulation(ivCompoundPKContext, mapFromBioavailabilityCompoundPK, compoundName, populationSimulation, new []{Bioavailability}); + var contextForPopulationSimulation = createContextForPopulationSimulation(ivCompoundPKContext, mapFromBioavailabilityCompoundPK, compoundName, populationSimulation, new[] { Bioavailability }); populationSimulation.PKAnalyses = CalculateFor(populationSimulation, contextForPopulationSimulation); - } else if (ivSimulation is IndividualSimulation ivIndividualSimulation) { @@ -648,7 +643,7 @@ private bool isMultipleOral(Simulation simulation, Compound compound) return allSchemaItems.Any() && allSchemaItems.All(isOral); } - private static bool isOral(ISchemaItem schemaItem) + private static bool isOral(SchemaItem schemaItem) { if (schemaItem == null) return false; @@ -656,12 +651,12 @@ private static bool isOral(ISchemaItem schemaItem) return schemaItem.ApplicationType == ApplicationTypes.Oral; } - private static bool isIntravenous(ISchemaItem schemaItem) + private static bool isIntravenous(SchemaItem schemaItem) { if (schemaItem == null) return false; - return schemaItem.ApplicationType == ApplicationTypes.Intravenous || schemaItem.ApplicationType == ApplicationTypes.IntravenousBolus; + return schemaItem.IsIV; } private ApplicationType applicationTypeFor(Simulation simulation, Compound compound) @@ -673,17 +668,17 @@ private ApplicationType applicationTypeFor(Simulation simulation, Compound compo return numberOfApplications > 1 ? ApplicationType.Multiple : ApplicationType.Empty; } - private ISchemaItem singleDosingItem(Simulation simulation, Compound compound) + private SchemaItem singleDosingItem(Simulation simulation, Compound compound) { //this may be null for compound created by metabolization process only return schemaItemsFrom(simulation, compound).FirstOrDefault(); } - private IReadOnlyList schemaItemsFrom(Simulation simulation, Compound compound) + private IReadOnlyList schemaItemsFrom(Simulation simulation, Compound compound) { var protocol = simulation.CompoundPropertiesFor(compound).ProtocolProperties.Protocol; if (protocol == null) - return new List(); + return new List(); return _protocolToSchemaItemsMapper.MapFrom(protocol); } @@ -778,8 +773,8 @@ private IEnumerable columnsFor(CurveData y.Y).ToList(), - DataInfo = {MolWeight = populationDataCollector.MolWeightFor(curveData.QuantityPath)}, - QuantityInfo = {Path = curveData.QuantityPath.ToPathArray()} + DataInfo = { MolWeight = populationDataCollector.MolWeightFor(curveData.QuantityPath) }, + QuantityInfo = { Path = curveData.QuantityPath.ToPathArray() } } }; } @@ -857,11 +852,13 @@ public PKAnalysis CreatePKAnalysisFromValues(PKValues pkValues, Simulation simul } /// - /// Returns the range strings when the contains 'Range 2.5% to 97.5%' language + /// Returns the range strings when the contains 'Range 2.5% to 97.5%' language /// /// The text being split - /// The individual range descriptions as a tuple containing low range and high range. - /// If the string cannot be split on 'Range', returns the original text in both members of the tuple + /// + /// The individual range descriptions as a tuple containing low range and high range. + /// If the string cannot be split on 'Range', returns the original text in both members of the tuple + /// private (string lowerRange, string upperRange) rangeDescriptions(string text) { var splitStrings = text.Split(new[] { "Range" }, StringSplitOptions.None); diff --git a/src/PKSim.Presentation/Presenters/Simulations/GlobalPKAnalysisPresenter.cs b/src/PKSim.Presentation/Presenters/Simulations/GlobalPKAnalysisPresenter.cs index 9a73db1cc..6f8d47f87 100644 --- a/src/PKSim.Presentation/Presenters/Simulations/GlobalPKAnalysisPresenter.cs +++ b/src/PKSim.Presentation/Presenters/Simulations/GlobalPKAnalysisPresenter.cs @@ -1,21 +1,22 @@ using System; using System.Collections.Generic; using System.Linq; -using PKSim.Assets; +using OSPSuite.Core.Domain; +using OSPSuite.Core.Domain.UnitSystem; +using OSPSuite.Core.Services; +using OSPSuite.Presentation.Core; +using OSPSuite.Presentation.Presenters; +using OSPSuite.Presentation.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.Core.Services; using PKSim.Presentation.DTO.Mappers; using PKSim.Presentation.DTO.Simulations; using PKSim.Presentation.Views.Simulations; -using OSPSuite.Core.Domain; -using OSPSuite.Core.Domain.UnitSystem; -using OSPSuite.Core.Services; -using OSPSuite.Presentation.Core; -using OSPSuite.Presentation.Presenters; -using OSPSuite.Presentation.Services; namespace PKSim.Presentation.Presenters.Simulations { @@ -29,6 +30,7 @@ public interface IGlobalPKAnalysisPresenter : IPresenter, void CalculateDDIRatioFor(string compoundName); string DisplayNameFor(string parameterName); bool HasParameters(); + bool CanCalculateGlobalPK(); } public class GlobalPKAnalysisPresenter : AbstractSubPresenter, IGlobalPKAnalysisPresenter @@ -43,15 +45,17 @@ public class GlobalPKAnalysisPresenter : AbstractSubPresenter - { - parameter.DisplayUnit = parameter.Dimension.Unit(_settings.GetSetting(parameterName, DisplayUnitFor(parameterName).Name)); - }); + GlobalPKAnalysis.PKParameters(parameterName).Each(parameter => { parameter.DisplayUnit = parameter.Dimension.Unit(_settings.GetSetting(parameterName, DisplayUnitFor(parameterName).Name)); }); } private Simulation firstSimulation => _simulations.FirstOrDefault(); @@ -164,6 +165,18 @@ public bool HasParameters() return false; } + public bool CanCalculateGlobalPK() + { + return firstSimulation.Compounds.Any(compound => + { + var schemaItems = _protocolToSchemaItemsMapper.MapFrom(firstSimulation.CompoundPropertiesFor(compound).ProtocolProperties.Protocol); + return !isMultipleIV(schemaItems); + }); + } + + private bool isMultipleIV(IReadOnlyList schemaItems) => schemaItems.Count(schemaItem => schemaItem.IsIV) > 1; + + public void LoadSettingsForSubject(IWithId subject) { _settings = _presentationSettingsTask.PresentationSettingsFor(this, subject); diff --git a/src/PKSim.Presentation/Presenters/Simulations/IndividualPKAnalysisPresenter.cs b/src/PKSim.Presentation/Presenters/Simulations/IndividualPKAnalysisPresenter.cs index 6af3e44a2..4aac27089 100644 --- a/src/PKSim.Presentation/Presenters/Simulations/IndividualPKAnalysisPresenter.cs +++ b/src/PKSim.Presentation/Presenters/Simulations/IndividualPKAnalysisPresenter.cs @@ -1,5 +1,11 @@ using System.Collections.Generic; using System.Linq; +using OSPSuite.Core.Chart; +using OSPSuite.Core.Domain; +using OSPSuite.Core.Domain.Data; +using OSPSuite.Core.Domain.PKAnalyses; +using OSPSuite.Presentation.Presenters; +using OSPSuite.Presentation.Services; using OSPSuite.Utility.Collections; using OSPSuite.Utility.Extensions; using PKSim.Core.Extensions; @@ -8,12 +14,6 @@ using PKSim.Presentation.DTO.Mappers; using PKSim.Presentation.Services; using PKSim.Presentation.Views.Simulations; -using OSPSuite.Core.Chart; -using OSPSuite.Core.Domain; -using OSPSuite.Core.Domain.Data; -using OSPSuite.Core.Domain.PKAnalyses; -using OSPSuite.Presentation.Presenters; -using OSPSuite.Presentation.Services; namespace PKSim.Presentation.Presenters.Simulations { @@ -30,20 +30,16 @@ public class IndividualPKAnalysisPresenter : PKAnalysisPresenter _simulations; private readonly ICache _curveCache; private List _allColumns; - private readonly IGlobalPKAnalysisPresenter _globalPKAnalysisPresenter; private readonly IIndividualPKAnalysisToPKAnalysisDTOMapper _pKAnalysisToDTOMapper; public IndividualPKAnalysisPresenter(IIndividualPKAnalysisView view, IPKAnalysesTask pkAnalysesTask, IPKAnalysisExportTask exportTask, IGlobalPKAnalysisPresenter globalPKAnalysisPresenter, IIndividualPKAnalysisToPKAnalysisDTOMapper pKAnalysisToDTOMapper, - IPKParameterRepository pkParameterRepository, IPresentationSettingsTask presentationSettingsTask) : base(view, pkParameterRepository, presentationSettingsTask) + IPKParameterRepository pkParameterRepository, IPresentationSettingsTask presentationSettingsTask) : base(view, pkParameterRepository, presentationSettingsTask, globalPKAnalysisPresenter) { _pkAnalysesTask = pkAnalysesTask; - _globalPKAnalysisPresenter = globalPKAnalysisPresenter; _exportTask = exportTask; _view.ShowControls = false; _curveCache = new Cache(onMissingKey: x => null); - AddSubPresenters(_globalPKAnalysisPresenter); - _view.AddGlobalPKAnalysisView(_globalPKAnalysisPresenter.View); _pKAnalysisToDTOMapper = pKAnalysisToDTOMapper; } @@ -61,7 +57,7 @@ public void ShowPKAnalysis(IEnumerable simulations, IEnumerable, IPresen } public abstract class PKAnalysisPresenter : AbstractSubPresenter, IPKAnalysisPresenter - where TView : IView + where TView : IView, IPKAnalysisView where TPresenter : IPresenter { private readonly IPKParameterRepository _pkParameterRepository; private readonly IParameter _undefinedPKParameter; private DefaultPresentationSettings _settings; private readonly IPresentationSettingsTask _presentationSettingsTask; + protected IGlobalPKAnalysisPresenter _globalPKAnalysisPresenter; - protected PKAnalysisPresenter(TView view, IPKParameterRepository pkParameterRepository, IPresentationSettingsTask presentationSettingsTask) + protected PKAnalysisPresenter(TView view, IPKParameterRepository pkParameterRepository, IPresentationSettingsTask presentationSettingsTask, IGlobalPKAnalysisPresenter globalPKAnalysisPresenter) : base(view) { _pkParameterRepository = pkParameterRepository; _presentationSettingsTask = presentationSettingsTask; - _undefinedPKParameter = new PKSimParameter {Dimension = Constants.Dimension.NO_DIMENSION}; + _undefinedPKParameter = new PKSimParameter { Dimension = Constants.Dimension.NO_DIMENSION }; _settings = new DefaultPresentationSettings(); + _globalPKAnalysisPresenter = globalPKAnalysisPresenter; + AddSubPresenters(_globalPKAnalysisPresenter); + _view.AddGlobalPKAnalysisView(_globalPKAnalysisPresenter.View); } public void ChangeUnit(string pkParameterName, Unit newUnit) diff --git a/src/PKSim.Presentation/Presenters/Simulations/PopulationPKAnalysisPresenter.cs b/src/PKSim.Presentation/Presenters/Simulations/PopulationPKAnalysisPresenter.cs index b88c0ffb3..93788a22e 100644 --- a/src/PKSim.Presentation/Presenters/Simulations/PopulationPKAnalysisPresenter.cs +++ b/src/PKSim.Presentation/Presenters/Simulations/PopulationPKAnalysisPresenter.cs @@ -30,20 +30,16 @@ public class PopulationPKAnalysisPresenter : PKAnalysisPresenter _allPKAnalysesIndividualPKValues = new List(); private IPopulationDataCollector _populationDataCollector; private readonly IPopulationPKAnalysisToPKAnalysisDTOMapper _populationPKAnalysisToDTOMapper; - private readonly IGlobalPKAnalysisPresenter _globalPKAnalysisPresenter; public PopulationPKAnalysisPresenter(IPopulationPKAnalysisView view, IPKAnalysesTask pkAnalysesTask, IPKAnalysisExportTask exportTask, IPopulationPKAnalysisToPKAnalysisDTOMapper populationPKAnalysisToDTOMapper, IPKParameterRepository pkParameterRepository, IPresentationSettingsTask presentationSettingsTask, IGlobalPKAnalysisPresenter globalPKAnalysisPresenter) - : base(view, pkParameterRepository, presentationSettingsTask) + : base(view, pkParameterRepository, presentationSettingsTask, globalPKAnalysisPresenter) { _pkAnalysesTask = pkAnalysesTask; _exportTask = exportTask; _populationPKAnalysisToDTOMapper = populationPKAnalysisToDTOMapper; - _globalPKAnalysisPresenter = globalPKAnalysisPresenter; - AddSubPresenters(_globalPKAnalysisPresenter); - _view.AddGlobalPKAnalysisView(_globalPKAnalysisPresenter.View); } public void CalculatePKAnalyses(IPopulationDataCollector populationDataCollector, ChartData timeProfileChartData, PopulationStatisticalAnalysis populationAnalysis) @@ -67,7 +63,9 @@ public void CalculatePKAnalyses(IPopulationDataCollector populationDataCollector var simulation = populationDataCollector.DowncastTo(); //Calculate first global PK that should always be updated - _globalPKAnalysisPresenter.CalculatePKAnalysis(new[] {simulation}); + _globalPKAnalysisPresenter.CalculatePKAnalysis(new[] { simulation }); + + _view.GlobalPKVisible = _globalPKAnalysisPresenter.CanCalculateGlobalPK(); var pkParametersCache = extractPKParameters(populationAnalysis, simulation); if (!pkParametersCache.Any() || pkParametersCache.All(x => !x.Any())) diff --git a/src/PKSim.Presentation/Views/Simulations/IIndividualPKAnalysisView.cs b/src/PKSim.Presentation/Views/Simulations/IIndividualPKAnalysisView.cs index dc2c44ea4..7204eb0c9 100644 --- a/src/PKSim.Presentation/Views/Simulations/IIndividualPKAnalysisView.cs +++ b/src/PKSim.Presentation/Views/Simulations/IIndividualPKAnalysisView.cs @@ -1,16 +1,12 @@ -using System.Data; using PKSim.Presentation.DTO.Simulations; using PKSim.Presentation.Presenters.Simulations; using OSPSuite.Presentation.Views; namespace PKSim.Presentation.Views.Simulations { - public interface IIndividualPKAnalysisView : IView + public interface IIndividualPKAnalysisView : IView, IPKAnalysisView { bool ShowControls { set; } - void AddGlobalPKAnalysisView(IGlobalPKAnalysisView view); void BindTo(PKAnalysisDTO pkAnalysisDTO); - DataTable GetSummaryData(); - bool GlobalPKVisible { set; } } } \ No newline at end of file diff --git a/src/PKSim.Presentation/Views/Simulations/IPopulationPKAnalysisView.cs b/src/PKSim.Presentation/Views/Simulations/IPopulationPKAnalysisView.cs index dbd8aea58..94fc8a21d 100644 --- a/src/PKSim.Presentation/Views/Simulations/IPopulationPKAnalysisView.cs +++ b/src/PKSim.Presentation/Views/Simulations/IPopulationPKAnalysisView.cs @@ -1,15 +1,21 @@ using System.Data; +using OSPSuite.Presentation.Views; using PKSim.Presentation.DTO.Simulations; using PKSim.Presentation.Presenters.Simulations; -using OSPSuite.Presentation.Views; namespace PKSim.Presentation.Views.Simulations { - public interface IPopulationPKAnalysisView : IView + public interface IPKAnalysisView { - void BindTo(IntegratedPKAnalysisDTO pkAnalysisDTO); - DataTable GetSummaryData(); void AddGlobalPKAnalysisView(IGlobalPKAnalysisView view); + bool GlobalPKVisible { set; } + DataTable GetSummaryData(); + } + + public interface IPopulationPKAnalysisView : IView, IPKAnalysisView + { + void BindTo(IntegratedPKAnalysisDTO pkAnalysisDTO); + bool IsAggregatedPKValuesSelected { get; } void ShowPKAnalysisIndividualPKValues(bool visible); } diff --git a/src/PKSim.UI/Views/Simulations/IndividualPKAnalysisView.cs b/src/PKSim.UI/Views/Simulations/IndividualPKAnalysisView.cs index dff58f379..63e773d90 100644 --- a/src/PKSim.UI/Views/Simulations/IndividualPKAnalysisView.cs +++ b/src/PKSim.UI/Views/Simulations/IndividualPKAnalysisView.cs @@ -1,13 +1,13 @@ using System.Data; -using OSPSuite.DataBinding; using DevExpress.XtraLayout.Utils; +using OSPSuite.Assets; +using OSPSuite.DataBinding; +using OSPSuite.UI.Controls; +using OSPSuite.UI.Extensions; using PKSim.Assets; using PKSim.Presentation.DTO.Simulations; using PKSim.Presentation.Presenters.Simulations; using PKSim.Presentation.Views.Simulations; -using OSPSuite.Assets; -using OSPSuite.UI.Controls; -using OSPSuite.UI.Extensions; namespace PKSim.UI.Views.Simulations { @@ -48,7 +48,7 @@ public DataTable GetSummaryData() public bool GlobalPKVisible { - set { setGlobalAnalysisViewVisibility(value); } + set => setGlobalAnalysisViewVisibility(value); } private void setGlobalAnalysisViewVisibility(bool showing) diff --git a/src/PKSim.UI/Views/Simulations/PopulationPKAnalysisView.cs b/src/PKSim.UI/Views/Simulations/PopulationPKAnalysisView.cs index a287787ac..2e2247038 100644 --- a/src/PKSim.UI/Views/Simulations/PopulationPKAnalysisView.cs +++ b/src/PKSim.UI/Views/Simulations/PopulationPKAnalysisView.cs @@ -51,6 +51,16 @@ public void BindTo(IntegratedPKAnalysisDTO pkAnalysisDTO) public bool IsAggregatedPKValuesSelected => populationPKAnalysisTabControl.SelectedTabPage == pageAggregatedPKValues; + public bool GlobalPKVisible + { + set + { + layoutControlItemGlobalPKAnalysis.Visibility = LayoutVisibilityConvertor.FromBoolean(value); + layoutControlItemGlobalPKAnalysisDescription.Visibility = LayoutVisibilityConvertor.FromBoolean(value); + splitter.Visibility = LayoutVisibilityConvertor.FromBoolean(value); + } + } + public void ShowPKAnalysisIndividualPKValues(bool visible) { var visibility = LayoutVisibilityConvertor.FromBoolean(visible); @@ -85,7 +95,7 @@ public override void InitializeResources() { base.InitializeResources(); populationPKAnalysisTabControl.Images = _imageListRetriever.AllImages16x16; - + pageIndividualPKValues.ImageIndex = _imageListRetriever.ImageIndex(ApplicationIcons.Population); pageIndividualPKValues.Text = PKSimConstants.PKAnalysis.IndividualPKValues; pageIndividualPKValues.Tooltip = PKSimConstants.PKAnalysis.IndivdualPKValuesTooltip; diff --git a/tests/PKSim.Tests/Presentation/GlobalPKAnalysisPresenterSpecs.cs b/tests/PKSim.Tests/Presentation/GlobalPKAnalysisPresenterSpecs.cs index a1cc647db..e81a6e059 100644 --- a/tests/PKSim.Tests/Presentation/GlobalPKAnalysisPresenterSpecs.cs +++ b/tests/PKSim.Tests/Presentation/GlobalPKAnalysisPresenterSpecs.cs @@ -10,6 +10,7 @@ using OSPSuite.Presentation.Presenters; using OSPSuite.Presentation.Services; using PKSim.Core; +using PKSim.Core.Mappers; using PKSim.Core.Model; using PKSim.Core.Repositories; using PKSim.Core.Services; @@ -26,8 +27,9 @@ public abstract class concern_for_GlobalPKAnalysisPresenter : ContextSpecificati protected IPKAnalysesTask _pKAnalysesTask; protected IPresentationSettingsTask _presenterSettingsTask; protected string _compoundName; - protected IReadOnlyList _simulations; + protected List _simulations; protected GlobalPKAnalysis _globalPKAnalysis; + protected IProtocolToSchemaItemsMapper _protocolToSchemaItemsMapper; protected override void Context() { @@ -37,7 +39,9 @@ protected override void Context() var heavyWorkManager = A.Fake(); var representationInfoRepository = A.Fake(); _presenterSettingsTask = A.Fake(); - sut = new GlobalPKAnalysisPresenter(_view, _pKAnalysesTask, globalPKAnalysisDTOMapper, heavyWorkManager, representationInfoRepository, _presenterSettingsTask); + _protocolToSchemaItemsMapper = A.Fake(); + + sut = new GlobalPKAnalysisPresenter(_view, _pKAnalysesTask, globalPKAnalysisDTOMapper, heavyWorkManager, representationInfoRepository, _presenterSettingsTask, _protocolToSchemaItemsMapper); _simulations = new List(); _compoundName = "DRUG"; @@ -62,7 +66,155 @@ public void has_parameters_should_return_false() } } - public class when_calculating_pk_analysis : concern_for_GlobalPKAnalysisPresenter + public abstract class context_for_can_calculate_global_pk_analysis : concern_for_GlobalPKAnalysisPresenter + { + protected bool _result; + + protected override void Context() + { + base.Context(); + var firstCompound = new Compound().WithName("Compound1"); + var firstCompoundProperties = new CompoundProperties + { + Compound = firstCompound, + ProtocolProperties = new ProtocolProperties + { + Protocol = new AdvancedProtocol() + } + }; + + var secondCompound = new Compound().WithName("Compound2"); + var secondCompoundProperties = new CompoundProperties + { + Compound = secondCompound, + ProtocolProperties = new ProtocolProperties + { + Protocol = new AdvancedProtocol() + } + }; + + var simulationProperties = new SimulationProperties(); + simulationProperties.AddCompoundProperties(firstCompoundProperties); + simulationProperties.AddCompoundProperties(secondCompoundProperties); + + var firstUsedBuildingBlock = new UsedBuildingBlock("t1", PKSimBuildingBlockType.Compound) + { + BuildingBlock = firstCompound + }; + var secondUsedBuildingBlock = new UsedBuildingBlock("t2", PKSimBuildingBlockType.Compound) + { + BuildingBlock = secondCompound + }; + + var individualSimulation = new IndividualSimulation + { + Properties = simulationProperties + }; + individualSimulation.AddUsedBuildingBlock(firstUsedBuildingBlock); + individualSimulation.AddUsedBuildingBlock(secondUsedBuildingBlock); + + _simulations.Add(individualSimulation); + var firstSchemaItems = GetFirstCompoundSchemaItems(); + var secondSchemaItems = GetSecondCompoundSchemaItems(); + + A.CallTo(() => _protocolToSchemaItemsMapper.MapFrom(individualSimulation.CompoundPropertiesFor(firstCompound).ProtocolProperties.Protocol)).Returns(firstSchemaItems); + A.CallTo(() => _protocolToSchemaItemsMapper.MapFrom(individualSimulation.CompoundPropertiesFor(secondCompound).ProtocolProperties.Protocol)).Returns(secondSchemaItems); + + sut.CalculatePKAnalysis(_simulations); + } + + protected abstract List GetSecondCompoundSchemaItems(); + + protected override void Because() + { + _result = sut.CanCalculateGlobalPK(); + } + + protected abstract List GetFirstCompoundSchemaItems(); + } + + + public class When_calculating_if_a_global_pk_analysis_is_possible_for_single_iv : context_for_can_calculate_global_pk_analysis + { + protected override List GetSecondCompoundSchemaItems() + { + return new List + { + new SchemaItem { ApplicationType = ApplicationTypes.Intravenous }, + new SchemaItem { ApplicationType = ApplicationTypes.Intravenous } + }; + } + + protected override List GetFirstCompoundSchemaItems() + { + return new List + { + new SchemaItem { ApplicationType = ApplicationTypes.IntravenousBolus } + }; + } + + [Observation] + public void the_calculation_is_possible() + { + _result.ShouldBeTrue(); + } + } + + public class When_calculating_if_a_global_pk_analysis_is_possible_for_multiple_oral : context_for_can_calculate_global_pk_analysis + { + protected override List GetSecondCompoundSchemaItems() + { + return new List + { + new SchemaItem { ApplicationType = ApplicationTypes.Intravenous }, + new SchemaItem { ApplicationType = ApplicationTypes.Intravenous } + }; + } + + protected override List GetFirstCompoundSchemaItems() + { + return new List + { + new SchemaItem { ApplicationType = ApplicationTypes.Oral }, + new SchemaItem { ApplicationType = ApplicationTypes.Oral } + }; + } + + [Observation] + public void the_calculation_is_possible() + { + _result.ShouldBeTrue(); + } + } + + public class When_calculating_if_a_global_pk_analysis_is_possible_for_multiple_iv : context_for_can_calculate_global_pk_analysis + { + protected override List GetSecondCompoundSchemaItems() + { + return new List + { + new SchemaItem { ApplicationType = ApplicationTypes.Intravenous }, + new SchemaItem { ApplicationType = ApplicationTypes.Intravenous } + }; + } + + protected override List GetFirstCompoundSchemaItems() + { + return new List + { + new SchemaItem { ApplicationType = ApplicationTypes.Intravenous }, + new SchemaItem { ApplicationType = ApplicationTypes.Intravenous } + }; + } + + [Observation] + public void the_calculation_is_not_possible() + { + _result.ShouldBeFalse(); + } + } + + public class When_calculating_pk_analysis : concern_for_GlobalPKAnalysisPresenter { private IParameter _parameter; private Unit _preferredDisplayUnit;