Skip to content

Commit

Permalink
Fixes #2596
Browse files Browse the repository at this point in the history
  • Loading branch information
msevestre committed May 5, 2023
1 parent 98555fa commit bf6aa8e
Show file tree
Hide file tree
Showing 29 changed files with 200 additions and 191 deletions.
4 changes: 2 additions & 2 deletions src/PKSim.Assets.Images/PKSim.Assets.Images.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Assets" Version="12.0.0-hTRUM" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.0-hTRUM" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.177" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.177" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/PKSim.Assets/PKSim.Assets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Assets" Version="12.0.0-hTRUM" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.0-hTRUM" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.177" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.177" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/PKSim.BatchTool/PKSim.BatchTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Core" Version="12.0.0-hTRUM" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.0-hTRUM" />
<PackageReference Include="OSPSuite.Core" Version="12.0.177" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.177" />
<PackageReference Include="OSPSuite.DevExpress" Version="21.2.3" />
<PackageReference Include="OSPSuite.FuncParser" Version="4.0.0.54" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModel" Version="4.0.0.53" GeneratePathProperty="true" />
Expand Down
4 changes: 2 additions & 2 deletions src/PKSim.CLI.Core/PKSim.CLI.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OSPSuite.Assets" Version="12.0.0-hTRUM" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.177" />
<PackageReference Include="OSPSuite.Utility" Version="4.0.0.4" />
<PackageReference Include="OSPSuite.Core" Version="12.0.0-hTRUM" />
<PackageReference Include="OSPSuite.Core" Version="12.0.177" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/PKSim.CLI/PKSim.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.0" />
<PackageReference Include="OSPSuite.Core" Version="12.0.0-hTRUM" />
<PackageReference Include="OSPSuite.Presentation" Version="12.0.0-hTRUM" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.0-hTRUM" />
<PackageReference Include="OSPSuite.Core" Version="12.0.177" />
<PackageReference Include="OSPSuite.Presentation" Version="12.0.177" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.177" />
<PackageReference Include="OSPSuite.Utility" Version="4.0.0.4" />
<PackageReference Include="OSPSuite.FuncParser" Version="4.0.0.54" GeneratePathProperty="true" />
<PackageReference Include="OSPSuite.SimModel" Version="4.0.0.53" GeneratePathProperty="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public RandomPopulationSettings MapFrom(Individual individual)
private bool shouldVaryInPopulation(OriginDataParameter originDataParameter)
{
//here list all discrete parameters that cannot be varied
return !originDataParameter.NameIsOneOf(HIDiseaseStateImplementation.CHILD_PUGH_SCORE);
return !originDataParameter.NameIsOneOf(CHILD_PUGH_SCORE);
}

private ParameterRange constrainedParameterRangeFrom(IParameter parameter)
Expand Down
4 changes: 1 addition & 3 deletions src/PKSim.Core/Mappers/ParameterListOfValuesRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public ParameterListOfValuesRetriever() : this(new HashSet<string>(AllWithListOf
public ParameterListOfValuesRetriever(HashSet<string> parameterWithListOfValues)
{
_parameterWithListOfValues = parameterWithListOfValues;
//TODO MOVE TO CORE
_parameterWithListOfValues.Add(HIDiseaseStateImplementation.CHILD_PUGH_SCORE);
_formatter = new NumericFormatter<double>(NumericFormatterOptions.Instance);
}

Expand Down Expand Up @@ -110,7 +108,7 @@ public void UpdateLisOfValues(ICache<double, string> listOfValues, IWithName par
listOfValues.Add(SINK_CONDITION, SinkCondition);
listOfValues.Add(NO_SINK_CONDITION, NoSinkCondition);
}
else if (parameter.IsNamed(HIDiseaseStateImplementation.CHILD_PUGH_SCORE))
else if (parameter.IsNamed(CHILD_PUGH_SCORE))
{
listOfValues.Add(HIDiseaseStateImplementation.ChildPughScore.A, ChildPughScoreFor("A"));
listOfValues.Add(HIDiseaseStateImplementation.ChildPughScore.B, ChildPughScoreFor("B"));
Expand Down
8 changes: 4 additions & 4 deletions src/PKSim.Core/PKSim.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="OSPSuite.Utility" Version="4.0.0.4" />
<PackageReference Include="OSPSuite.Core" Version="12.0.0-hTRUM" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.0-hTRUM" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.0-hTRUM" />
<PackageReference Include="OSPSuite.Infrastructure.Import" Version="12.0.0-hTRUM" />
<PackageReference Include="OSPSuite.Core" Version="12.0.177" />
<PackageReference Include="OSPSuite.Assets" Version="12.0.177" />
<PackageReference Include="OSPSuite.Assets.Images" Version="12.0.177" />
<PackageReference Include="OSPSuite.Infrastructure.Import" Version="12.0.177" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
</ItemGroup>

Expand Down
27 changes: 9 additions & 18 deletions src/PKSim.Core/Services/CKDDiseaseStateImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ private enum CKDStage
Stage5,
}

private readonly IValueOriginRepository _valueOriginRepository;
private readonly IDimension _dimensionForGFR;
public const string TARGET_GFR = "eGFR";
private readonly IDimension _ageDimension;
Expand All @@ -37,7 +36,6 @@ public CKDDiseaseStateImplementation(
IContainerTask containerTask,
IParameterSetUpdater parameterSetUpdater) : base(valueOriginRepository, formulaFactory, individualFactory, containerTask, parameterSetUpdater, CoreConstants.DiseaseStates.CKD)
{
_valueOriginRepository = valueOriginRepository;
_dimensionForGFR = dimensionRepository.DimensionForUnit(GFR_UNIT);
_ageDimension = dimensionRepository.AgeInYears;
}
Expand Down Expand Up @@ -74,7 +72,7 @@ IParameter gastricEmptyingTime

public override bool ApplyForPopulationTo(Individual individual) => applyTo(individual, UpdateParameterValue);

private bool applyTo(Individual individual, Action<IParameter, double, bool> updateParameterFunc)
private bool applyTo(Individual individual, Action<ParameterUpdate> updateParameterFunc)
{
var targetGFR = individual.OriginData.DiseaseStateParameters.FindByName(TARGET_GFR);

Expand All @@ -93,26 +91,26 @@ private bool applyTo(Individual individual, Action<IParameter, double, bool> upd

//Adjust kidney volume and update fat accordingly
var healthyKidneyVolume = kidneyVolume.Value;
updateParameterFunc(kidneyVolume, getKidneyVolumeFactor(targetGFRValue) / getKidneyVolumeFactor(GFR_0), true);
updateParameterFunc(fatVolume, fatVolume.Value + healthyKidneyVolume - kidneyVolume.Value, false);
updateParameterFunc(new(kidneyVolume, getKidneyVolumeFactor(targetGFRValue) / getKidneyVolumeFactor(GFR_0)));
updateParameterFunc(new(fatVolume, fatVolume.Value + healthyKidneyVolume - kidneyVolume.Value, ParameterUpdateMode.Value));

//Adjust renal blood flow spec
updateParameterFunc(kidneySpecificBloodFlowRate, getRenalBloodFlowFactor(targetGFRValue) / getRenalBloodFlowFactor(GFR_0), true);
updateParameterFunc(new(kidneySpecificBloodFlowRate, getRenalBloodFlowFactor(targetGFRValue) / getRenalBloodFlowFactor(GFR_0)));

//Correct specific GFR
updateParameterFunc(GFR_Spec, targetGFRValue / GFR_0 * healthyKidneyVolume / kidneyVolume.Value, true);
updateParameterFunc(new(GFR_Spec, targetGFRValue / GFR_0 * healthyKidneyVolume / kidneyVolume.Value));

var (plasmaProteinScaleFactor, gastricEmptyingTimeFactor, smallIntestinalTransitTimeFactor) = getCategorialFactors(targetGFRValue);

//Categorial Parameters as constant: We set the value as is as the value will not be reset when creating a population
updateParameterFunc(plasmaProteinScaleFactorParameter, plasmaProteinScaleFactor, false);
updateParameterFunc(new(plasmaProteinScaleFactorParameter, plasmaProteinScaleFactor, ParameterUpdateMode.Value));

//Categorial Parameters distributed: We apply the variation to the default value
updateParameterFunc(gastricEmptyingTime, gastricEmptyingTimeFactor, true);
updateParameterFunc(smallIntestinalTransitTime, smallIntestinalTransitTimeFactor, true);
updateParameterFunc(new(gastricEmptyingTime, gastricEmptyingTimeFactor));
updateParameterFunc(new(smallIntestinalTransitTime, smallIntestinalTransitTimeFactor));

//Special case for Hematocrit
updateParameterFunc(hct, getHematocritFactor(targetGFRValue, individual.OriginData.Gender), true);
updateParameterFunc(new(hct, getHematocritFactor(targetGFRValue, individual.OriginData.Gender)));

return true;
}
Expand Down Expand Up @@ -156,13 +154,6 @@ private double getHematocritFactor(double targetGFR, Gender gender)
return diseaseValue / healthyValue;
}

private void updateValueOriginsFor(IParameter parameter)
{
parameter.ValueOrigin.UpdateAllFrom(_valueOriginRepository.FindBy(CKD_VALUE_ORIGIN_ID));
//Make sure we mark this parameter as changed by create individual. It might already be the case but in that case, it does not change anything
parameter.IsChangedByCreateIndividual = true;
}

private double getKidneyVolumeFactor(double gfrValue) => getFactor(gfrValue, -6.3E-5, 0.0149, 4.13);

private double getRenalBloodFlowFactor(double gfrValue) => getFactor(gfrValue, -3.1E-5, 0.0170, 4.09);
Expand Down
34 changes: 16 additions & 18 deletions src/PKSim.Core/Services/HIDiseaseStateImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ private static HIFactors createFactors(double forA, double forB, double forC) =>
{"CYP2D6", createFactors(0.76, 0.33, 0.11)},
};

public const string CHILD_PUGH_SCORE = "Child-Pugh score";

private const int HI_EDGINTON_VALUE_ORIGIN_ID = 93;
private const int HI_JOHNSON_VALUE_ORIGIN_ID = 94;

Expand All @@ -89,7 +87,7 @@ public HIDiseaseStateImplementation(IDimensionRepository dimensionRepository,

public override bool ApplyForPopulationTo(Individual individual) => applyTo(individual, UpdateParameterValue);

private bool applyTo(Individual individual, Action<IParameter, double, bool> updateParameterFunc)
private bool applyTo(Individual individual, Action<ParameterUpdate> updateParameterFunc)
{
updateBloodFlows(individual, updateParameterFunc);
updateVolumes(individual, updateParameterFunc);
Expand Down Expand Up @@ -129,45 +127,45 @@ protected override IReadOnlyList<IParameter> ParameterChangedByDiseaseStateAsLis
var kidney = organism.Organ(KIDNEY);
var liver = organism.Organ(LIVER);

var organsBloodFlow = new[] {STOMACH, SMALL_INTESTINE, LARGE_INTESTINE, SPLEEN, PANCREAS, LIVER, KIDNEY, BONE, FAT, GONADS, HEART, MUSCLE, SKIN};
//Oddly enough the brain blood flow is unaffected within hepatic disease, largely due to compensatory mechanisms from some of the decreased blood flow to other organs.
var organsBloodFlow = new[] { BONE, FAT, GONADS, HEART, KIDNEY, LIVER, MUSCLE, PANCREAS, LARGE_INTESTINE, SKIN, SMALL_INTESTINE, SPLEEN, STOMACH};
var bloodFlows = organsBloodFlow.Select(x => organism.Organ(x).Parameter(SPECIFIC_BLOOD_FLOW_RATE)).ToList();

return new[]
{
organism.Parameter(HCT),
organism.Parameter(CHILD_PUGH_SCORE),
organism.Parameter(CHILD_PUGH_SCORE),
organism.Parameter(ONTOGENY_FACTOR_ALBUMIN),
organism.Parameter(ONTOGENY_FACTOR_AGP),
kidney.Parameter(GFR_SPEC),
liver.Parameter(VOLUME),
}.Union(bloodFlows).ToList();
}

private void updateOntogenyFactory(Individual individual, Action<IParameter, double, bool> updateParameterFunc)
private void updateOntogenyFactory(Individual individual, Action<ParameterUpdate> updateParameterFunc)
{
var score = childPughScoreFor(individual);
var organism = individual.Organism;
updateParameterFunc(organism.Parameter(ONTOGENY_FACTOR_ALBUMIN), _albuminFactor[score], true);
updateParameterFunc(organism.Parameter(ONTOGENY_FACTOR_AGP), _agpFactor[score], true);
updateParameterFunc(new(organism.Parameter(ONTOGENY_FACTOR_ALBUMIN), _albuminFactor[score]));
updateParameterFunc(new(organism.Parameter(ONTOGENY_FACTOR_AGP), _agpFactor[score]));
}

private void updateGFR(Individual individual, Action<IParameter, double, bool> updateParameterFunc)
private void updateGFR(Individual individual, Action<ParameterUpdate> updateParameterFunc)
{
var score = childPughScoreFor(individual);
var kidney = individual.Organism.Organ(KIDNEY);
var GFR_spec = kidney.Parameter(GFR_SPEC);
updateParameterFunc(GFR_spec, _gfrScalingFactor[score], true);
updateParameterFunc(new(GFR_spec, _gfrScalingFactor[score]));
}

private void updateHematocrit(Individual individual, Action<IParameter, double, bool> updateParameterFunc)
private void updateHematocrit(Individual individual, Action<ParameterUpdate> updateParameterFunc)
{
var score = childPughScoreFor(individual);
var hct = individual.Organism.Parameter(HCT);
updateParameterFunc(hct, _hematocritScalingFactor[score], true);
updateParameterFunc(new(hct, _hematocritScalingFactor[score]));
}

private void updateBloodFlows(Individual individual, Action<IParameter, double, bool> updateParameterFunc)
private void updateBloodFlows(Individual individual, Action<ParameterUpdate> updateParameterFunc)
{
var score = childPughScoreFor(individual);
var organism = individual.Organism;
Expand All @@ -188,24 +186,24 @@ private void updateBloodFlows(Individual individual, Action<IParameter, double,
otherOrgans.Each(x => updateBloodFlow(x, _otherOrgansFlowScalingFactor[score]));
}

private void updateVolumes(Individual individual, Action<IParameter, double, bool> updateParameterFunc)
private void updateVolumes(Individual individual, Action<ParameterUpdate> updateParameterFunc)
{
var score = childPughScoreFor(individual);
var organism = individual.Organism;
var parameter = organism.Container(LIVER).Parameter(VOLUME);
updateParameterFunc(parameter, _hepaticVolumeScalingFactor[score], true);
updateParameterFunc(new(parameter, _hepaticVolumeScalingFactor[score]));
}

private Action<string, double> updateBloodFlowDef(Action<IParameter, double, bool> updateParameterFunc, IContainer organism) => (organName, factor) =>
private Action<string, double> updateBloodFlowDef(Action<ParameterUpdate> updateParameterFunc, IContainer organism) => (organName, factor) =>
{
var parameter = organism.Container(organName).Parameter(SPECIFIC_BLOOD_FLOW_RATE);
updateParameterFunc(parameter, factor, true);
updateParameterFunc(new(parameter, factor));
};

private void updateReferenceConcentration(Individual individual, IndividualMolecule individualMolecule, HIFactors factors, int valueOriginId)
{
var score = childPughScoreFor(individual);
UpdateParameter(valueOriginId)(individualMolecule.ReferenceConcentration, factors[score], true);
UpdateParameter(valueOriginId)(new(individualMolecule.ReferenceConcentration, factors[score]));
}

private double childPughScoreFor(Individual individual) => individual.OriginData.DiseaseStateParameters.FindByName(CHILD_PUGH_SCORE).Value;
Expand Down
Loading

0 comments on commit bf6aa8e

Please sign in to comment.