Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1755 aucr cmax r not calculated properly #2093

Merged
merged 1 commit into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/PKSim.Core/Model/Simulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,11 @@ public virtual void UpdateFromOriginalSimulation(Simulation originalSimulation)
}

/// <summary>
/// Returns the endtime of the simulation in kernel unit
/// Returns the end time of the simulation in kernel unit
/// </summary>
public virtual double? EndTime
{
get { return OutputSchema.Intervals.Select(x => x.EndTime.Value).Max(); }
get { return OutputSchema?.Intervals.Select(x => x.EndTime.Value).Max(); }
}

/// <summary>
Expand Down
21 changes: 14 additions & 7 deletions src/PKSim.Core/Services/GlobalPKAnalysisTask.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Collections.Generic;
using System.Linq;
using PKSim.Assets;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Data;
using OSPSuite.Core.Domain.Services;
using OSPSuite.Utility.Extensions;
using OSPSuite.Utility.Validation;
using PKSim.Assets;
using PKSim.Core.Mappers;
using PKSim.Core.Model;
using PKSim.Core.Model.Extensions;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Data;
using OSPSuite.Core.Domain.Services;
using IParameterFactory = PKSim.Core.Model.IParameterFactory;

namespace PKSim.Core.Services
Expand Down Expand Up @@ -123,10 +123,10 @@ public GlobalPKAnalysis CalculateGlobalPKAnalysisFor(IEnumerable<Simulation> sim
continue;
}

var schemaItem = singleDosingItem(simulation, compound);
var pkValues = new List<IParameter>();
var bioAvailabilityCalculated = !double.IsNaN(bioAvailabilityValue);

var schemaItem = singleDosingItem(simulation, compound);
if (isIntravenous(schemaItem))
{
container.AddChildren(vssPlasma, vdPlasma, vssPhysChem, totalPlasmaCL);
Expand Down Expand Up @@ -319,17 +319,23 @@ private bool isMultipleOral(Simulation simulation, Compound compound)

private static bool isOral(ISchemaItem schemaItem)
{
if (schemaItem == null)
return false;

return schemaItem.ApplicationType == ApplicationTypes.Oral;
}

private static bool isIntravenous(ISchemaItem schemaItem)
{
if (schemaItem == null)
return false;

return schemaItem.ApplicationType == ApplicationTypes.Intravenous || schemaItem.ApplicationType == ApplicationTypes.IntravenousBolus;
}

private ApplicationType applicationTypeFor(Simulation simulation, Compound compound)
{
var numberOfApplications = schemaItemsFrom(simulation, compound).Count;
var numberOfApplications = simulation.AllApplicationParametersOrderedByStartTimeFor(compound.Name).Count;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only relevant difference, correct?
For a metabolite (which is not administered) number of applications was zero before; now it is number of applications of its parent drug, right?

By the way, I would rename the function AllApplicationParametersOrderedByStartTimeFor to something like AllOrderedApplicationStartTimes.
Because in AllApplicationParameters I would expect also all other application parameters like e.g. DrugMass, InfusionTime etc. (I had to look into the implementation of the function to understand what it does)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok but this is in core so not directly relevant to this problem. Please create an issue for this

For a metabolite (which is not administered) number of applications was zero before; now it is number of applications of its parent drug, right?

yes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue created: Open-Systems-Pharmacology/OSPSuite.Core#1494
PR looks good for me

if (numberOfApplications == 1)
return ApplicationType.Single;

Expand All @@ -338,7 +344,8 @@ private ApplicationType applicationTypeFor(Simulation simulation, Compound compo

private ISchemaItem singleDosingItem(Simulation simulation, Compound compound)
{
return schemaItemsFrom(simulation, compound)[0];
//this may be null for compound created by metabolization process only
return schemaItemsFrom(simulation, compound).FirstOrDefault();
}

private IReadOnlyList<ISchemaItem> schemaItemsFrom(Simulation simulation, Compound compound)
Expand Down
40 changes: 26 additions & 14 deletions tests/PKSim.Tests/Core/GlobalPKAnalysisTaskSpecs.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System;
using System.Collections.Generic;
using FakeItEasy;
using OSPSuite.BDDHelper;
using OSPSuite.BDDHelper.Extensions;
using FakeItEasy;
using PKSim.Core.Mappers;
using PKSim.Core.Model;
using PKSim.Core.Services;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Builder;
using OSPSuite.Core.Domain.Data;
using OSPSuite.Core.Domain.Formulas;
using OSPSuite.Core.Domain.Services;
using OSPSuite.Core.Domain.UnitSystem;
using PKSim.Core.Mappers;
using PKSim.Core.Model;
using PKSim.Core.Services;
using IParameterFactory = PKSim.Core.Model.IParameterFactory;
using IPKAnalysesTask = PKSim.Core.Services.IPKAnalysesTask;
using IPKCalculationOptionsFactory = PKSim.Core.Services.IPKCalculationOptionsFactory;
Expand All @@ -36,10 +36,12 @@ public abstract class concern_for_GlobalPKAnalysisTask : ContextSpecification<IG
protected PKValues _peripheralVenousBloodPK;
protected Species _species;
protected SimpleProtocol _protocol;
protected List<SchemaItem> _simulationSchemaItems;
private IInteractionTask _interactionTask;
protected Compound _compound;
private ICloner _cloner;
protected EventGroup _eventGroup;
private Container _application1;
protected Container _application2;

protected override void Context()
{
Expand All @@ -65,18 +67,28 @@ protected override void Context()

_compound = new Compound().WithName(_compoundName);
_compoundProperties = new CompoundProperties {Compound = _compound};
_simulationSchemaItems = new List<SchemaItem>();
_protocol = new SimpleProtocol();
_compoundProperties.ProtocolProperties.Protocol = _protocol;
A.CallTo(() => _protocolMapper.MapFrom(_protocol)).Returns(_simulationSchemaItems);

_simulation = new IndividualSimulation {Properties = new SimulationProperties()};

_simulation.Properties.AddCompoundProperties(_compoundProperties);
_simulation.AddUsedBuildingBlock(new UsedBuildingBlock("CompId", PKSimBuildingBlockType.Compound) {BuildingBlock = _compound});
_simulation.AddUsedBuildingBlock(new UsedBuildingBlock("IndividualId", PKSimBuildingBlockType.Individual) {BuildingBlock = _individual});
_simulation.DataRepository = new DataRepository {_venousBloodPlasma, _peripheralVenousBloodPlasma};

_simulation.SimulationSettings = new SimulationSettings();
_simulation.OutputSchema = new OutputSchema();
_simulation.OutputSchema.AddInterval(new OutputInterval{DomainHelperForSpecs.ConstantParameterWithValue(100).WithName(Constants.Parameters.END_TIME) });
_simulation.Model = new OSPSuite.Core.Domain.Model {Root = new Container()};
_eventGroup = new EventGroup();
_application1 = new Container().WithName("App1").WithContainerType(ContainerType.Application);
_application1.Add(new MoleculeAmount().WithName(_compoundName));
_application1.Add(DomainHelperForSpecs.ConstantParameterWithValue(10).WithName(Constants.Parameters.START_TIME));
_application2 = new Container().WithName("App2").WithContainerType(ContainerType.Application);
_application2.Add(DomainHelperForSpecs.ConstantParameterWithValue(10).WithName(Constants.Parameters.START_TIME));
_application2.Add(new MoleculeAmount().WithName(_compoundName));
_simulation.Model.Root.Add(_eventGroup);
_eventGroup.Add(_application1);
_venousBloodPK = new PKValues();
_venousBloodPK.AddValue(Constants.PKParameters.Vss, 10);
_venousBloodPK.AddValue(Constants.PKParameters.Vd, 11);
Expand Down Expand Up @@ -113,7 +125,7 @@ protected DataColumn CalculationColumnFor(BaseGrid baseGrid, string organ, strin
}
}

public class When_calculating_the_global_pk_analyes_parameter_such_as_VSS_VD_and_Plasma_CL_for_the_human_species : concern_for_GlobalPKAnalysisTask
public class When_calculating_the_global_pk_analyses_parameter_such_as_VSS_VD_and_Plasma_CL_for_the_human_species : concern_for_GlobalPKAnalysisTask
{
private GlobalPKAnalysis _results;

Expand Down Expand Up @@ -309,7 +321,9 @@ protected override void Context()
var startTime = DomainHelperForSpecs.ConstantParameterWithValue(3);
A.CallTo(() => schemaItem.Dose).Returns(inputDose);
A.CallTo(() => schemaItem.StartTime).Returns(startTime);
_simulationSchemaItems.Add(schemaItem);

A.CallTo(() => _protocolMapper.MapFrom(_protocol)).Returns(new []{schemaItem, });

}

protected override void Because()
Expand Down Expand Up @@ -361,8 +375,6 @@ protected override void Context()

A.CallTo(() => _globalPKAnalysisRunner.RunForDDIRatio(_simulation)).Returns(_ddiRatioSimulation);
A.CallTo(() => _pkAnalysisTask.CalculateFor(_ddiRatioSimulation, _peripheralVenousBloodPlasma)).Returns(new IndividualPKAnalysis(_peripheralVenousBloodPlasma, _pkAnalysis));
//single dosing
_simulationSchemaItems.Add(new SchemaItem());
}

protected override void Because()
Expand Down Expand Up @@ -444,7 +456,7 @@ protected override void Context()
A.CallTo(() => _globalPKAnalysisRunner.RunForDDIRatio(_simulation)).Returns(_ddiRatioSimulation);
A.CallTo(() => _pkAnalysisTask.CalculateFor(_ddiRatioSimulation, _peripheralVenousBloodPlasma)).Returns(new IndividualPKAnalysis(_peripheralVenousBloodPlasma, _pkAnalysis));
//multiple dosing
_simulationSchemaItems.AddRange(new[] {new SchemaItem(), new SchemaItem()});
_eventGroup.Add(_application2);
}

protected override void Because()
Expand Down