Skip to content

Commit

Permalink
Fixes #2485 observed added mobi (#2500)
Browse files Browse the repository at this point in the history
  • Loading branch information
msevestre authored Jan 2, 2023
1 parent bd3fd9b commit 670a4fc
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 46 deletions.
30 changes: 5 additions & 25 deletions src/PKSim.Core/Services/SimulationPersistableUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,36 +87,16 @@ private void setMoleculeAmountToPersistableIn(IContainer container)
private void setApplicationObserversNonPersistable(Simulation simulation)
{
//Set all observers defined in application to persistable false
var applicationSet = simulation.Model.Root.GetSingleChildByName<IContainer>(Constants.APPLICATIONS);
if (applicationSet == null) return;
var applications = simulation.Model.Root.Container(Constants.APPLICATIONS);

foreach (var appObserver in applicationSet.GetAllChildren<IObserver>())
{
if (applicationObserverShouldBeShown(appObserver))
continue;

appObserver.Persistable = false;
}
applications?.GetAllChildren<IObserver>(applicationObserverShouldBeHidden)
.Each(x => x.Persistable = false);
}

/// <summary>
/// Return true if an application observer should not be hidden from user
/// Return true if an application observer should be hidden from user
/// </summary>
/// <param name="observer"></param>
private bool applicationObserverShouldBeShown(IObserver observer)
{
string name = observer.Name;

if (name.StartsWith(CoreConstants.Observer.FRACTION_SOLID_PREFIX))
return true;

if (name.StartsWith(CoreConstants.Observer.FRACTION_DISSOLVED_PREFIX))
return true;

if (name.StartsWith(CoreConstants.Observer.FRACTION_INSOLUBLE_PREFIX))
return true;

return false;
}
private bool applicationObserverShouldBeHidden(IObserver observer) => observer.Name == CoreConstants.Observer.CONCENTRATION_IN_CONTAINER;
}
}
84 changes: 63 additions & 21 deletions tests/PKSim.Tests/Core/SimulationPersistableUpdaterSpecs.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using OSPSuite.BDDHelper;
using OSPSuite.BDDHelper.Extensions;
using FakeItEasy;
using FakeItEasy;
using NUnit.Framework;
using PKSim.Core.Model;
using PKSim.Core.Services;
using OSPSuite.BDDHelper;
using OSPSuite.BDDHelper.Extensions;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Builder;
using PKSim.Core.Model;
using PKSim.Core.Services;

namespace PKSim.Core
{
Expand All @@ -30,10 +30,11 @@ public class When_updating_the_simulation_settings_for_a_simulation : concern_fo
protected override void Context()
{
base.Context();
var organsim = new Container().WithName(Constants.ORGANISM);
var venousBlood = new Container().WithName(CoreConstants.Organ.VENOUS_BLOOD).WithParentContainer(organsim);
var peripheralVenousBlood = new Container().WithName(CoreConstants.Organ.PERIPHERAL_VENOUS_BLOOD).WithParentContainer(organsim);
var lumen = new Container().WithName(CoreConstants.Organ.LUMEN).WithParentContainer(organsim);
var organism = new Container().WithName(Constants.ORGANISM);
var applications = new Container().WithName(Constants.APPLICATIONS);
var venousBlood = new Container().WithName(CoreConstants.Organ.VENOUS_BLOOD).WithParentContainer(organism);
var peripheralVenousBlood = new Container().WithName(CoreConstants.Organ.PERIPHERAL_VENOUS_BLOOD).WithParentContainer(organism);
var lumen = new Container().WithName(CoreConstants.Organ.LUMEN).WithParentContainer(organism);
var plasma = new Container().WithName(CoreConstants.Compartment.PLASMA);
var moleculeVenousBlood = new Container().WithName("DRUG")
.WithParentContainer(plasma.WithParentContainer(venousBlood));
Expand All @@ -53,14 +54,14 @@ protected override void Context()
_fabsObserver = new Observer().WithName(CoreConstants.Observer.FABS_ORAL);
moleculeLumen.Add(_fabsObserver);


var compound = new Compound().WithName("DRUG");

_individualSimulation = new IndividualSimulation();
_individualSimulation.SimulationSettings = new SimulationSettings();
_individualSimulation.AddUsedBuildingBlock(new UsedBuildingBlock("Id", PKSimBuildingBlockType.Compound) { BuildingBlock = compound });
_individualSimulation.AddUsedBuildingBlock(new UsedBuildingBlock("Id", PKSimBuildingBlockType.Compound) {BuildingBlock = compound});
_individualSimulation.Model = new OSPSuite.Core.Domain.Model();
_individualSimulation.Model.Root = new Container();
_individualSimulation.Model.Root.Add(organsim);
_individualSimulation.Model.Root = new Container {organism, applications};
}

protected override void Because()
Expand All @@ -81,12 +82,53 @@ public void should_always_select_the_lumen_fabs_observer()
}

[Observation]
public void should_always_select_the_peripheral_venous_blood_plasna()
public void should_always_select_the_peripheral_venous_blood_plasma()
{
_peripheralVenousBloodObserver.Persistable.ShouldBeTrue();
}
}

public class When_resetting_the_persitable_flags_for_a_simulation : concern_for_SimulationPersistableUpdater
{
private IndividualSimulation _individualSimulation;
private Observer _appConcentrationObserver;
private Observer _appUserDefinedObserver;

protected override void Context()
{
base.Context();
var organism = new Container().WithName(Constants.ORGANISM);
var applications = new Container().WithName(Constants.APPLICATIONS);

_appConcentrationObserver = new Observer().WithName(CoreConstants.Observer.CONCENTRATION_IN_CONTAINER);
_appUserDefinedObserver = new Observer().WithName("Super awesome observer");

applications.Add(_appConcentrationObserver);
applications.Add(_appUserDefinedObserver);


_individualSimulation = new IndividualSimulation
{
Model = new OSPSuite.Core.Domain.Model
{
Root = new Container {organism, applications}
}
};
}

protected override void Because()
{
sut.ResetPersistable(_individualSimulation);
}

[Observation]
public void should_show_all_observer_under_application_except_concentration()
{
_appUserDefinedObserver.Persistable.ShouldBeTrue();
_appConcentrationObserver.Persistable.ShouldBeFalse();
}
}

public class When_updating_the_simulation_settings_for_a_population_simulation : concern_for_SimulationPersistableUpdater
{
private PopulationSimulation _populationSimulation;
Expand All @@ -97,10 +139,10 @@ public class When_updating_the_simulation_settings_for_a_population_simulation :
protected override void Context()
{
base.Context();
var organsim = new Container().WithName(Constants.ORGANISM);
var venousBlood = new Container().WithName(CoreConstants.Organ.VENOUS_BLOOD).WithParentContainer(organsim);
var peripheralVenousBlood = new Container().WithName(CoreConstants.Organ.PERIPHERAL_VENOUS_BLOOD).WithParentContainer(organsim);
var lumen = new Container().WithName(CoreConstants.Organ.LUMEN).WithParentContainer(organsim);
var organism = new Container().WithName(Constants.ORGANISM);
var venousBlood = new Container().WithName(CoreConstants.Organ.VENOUS_BLOOD).WithParentContainer(organism);
var peripheralVenousBlood = new Container().WithName(CoreConstants.Organ.PERIPHERAL_VENOUS_BLOOD).WithParentContainer(organism);
var lumen = new Container().WithName(CoreConstants.Organ.LUMEN).WithParentContainer(organism);
var plasma = new Container().WithName(CoreConstants.Compartment.PLASMA);
var moleculeVenousBlood = new Container().WithName("DRUG")
.WithParentContainer(plasma.WithParentContainer(venousBlood));
Expand All @@ -124,10 +166,10 @@ protected override void Context()

_populationSimulation = new PopulationSimulation();
_populationSimulation.SimulationSettings = new SimulationSettings();
_populationSimulation.AddUsedBuildingBlock(new UsedBuildingBlock("Id", PKSimBuildingBlockType.Compound) { BuildingBlock = compound });
_populationSimulation.AddUsedBuildingBlock(new UsedBuildingBlock("Id", PKSimBuildingBlockType.Compound) {BuildingBlock = compound});
_populationSimulation.Model = new OSPSuite.Core.Domain.Model();
_populationSimulation.Model.Root = new Container();
_populationSimulation.Model.Root.Add(organsim);
_populationSimulation.Model.Root.Add(organism);
}

protected override void Because()
Expand Down Expand Up @@ -197,8 +239,8 @@ protected override void Context()
var compound = new Compound().WithName("DRUG");

_individualSimulation = new IndividualSimulation();
_individualSimulation.AddUsedBuildingBlock(new UsedBuildingBlock("Id", PKSimBuildingBlockType.Compound) { BuildingBlock = compound });
_individualSimulation.Model = new OSPSuite.Core.Domain.Model { Root = new Container { organsim } };
_individualSimulation.AddUsedBuildingBlock(new UsedBuildingBlock("Id", PKSimBuildingBlockType.Compound) {BuildingBlock = compound});
_individualSimulation.Model = new OSPSuite.Core.Domain.Model {Root = new Container {organsim}};
}

protected override void Because()
Expand Down

0 comments on commit 670a4fc

Please sign in to comment.