Esempio n. 1
0
        public GlobalPKAnalysis CalculateGlobalPKAnalysisFor(IEnumerable <Simulation> simulations)
        {
            var globalPKAnalysis = new GlobalPKAnalysis();

            var allSimulations = simulations.ToList();

            if (allSimulations.Count != 1)
            {
                return(globalPKAnalysis);
            }

            var simulation = allSimulations[0] as IndividualSimulation;

            if (simulation == null)
            {
                return(globalPKAnalysis);
            }

            //one container per compound
            foreach (var compound in simulation.Compounds)
            {
                var compoundName = compound.Name;
                var container    = new Container().WithName(compoundName);
                globalPKAnalysis.Add(container);

                var peripheralVenousBloodCurve = simulation.DataRepository.PeripheralVenousBloodColumn(compoundName);
                var venousBloodCurve           = simulation.DataRepository.VenousBloodColumn(compoundName);

                if (peripheralVenousBloodCurve == null || venousBloodCurve == null)
                {
                    continue;
                }

                var options             = _pkCalculationOptionsFactory.CreateFor(simulation, compoundName);
                var venousBloodPlasmaPK = _pkAnalysisTask.CalculatePK(venousBloodCurve, options);

                var aucIV   = simulation.AucIVFor(compoundName);
                var aucDDI  = simulation.AucDDIFor(compoundName);
                var cmaxDDI = simulation.CmaxDDIFor(compoundName);

                var bioAvailability      = createRatioParameter(CoreConstants.PKAnalysis.Bioavailability, venousBloodPlasmaPK[Constants.PKParameters.AUC_inf], aucIV, Constants.Dimension.DIMENSIONLESS);
                var bioAvailabilityValue = bioAvailability.Value;

                var bloodCurveForPKAnalysis = bloodCurveForSpecies(peripheralVenousBloodCurve, venousBloodCurve, simulation.Individual);
                var bloodPlasmaPK           = _pkAnalysisTask.CalculatePK(bloodCurveForPKAnalysis, options);

                var applicationType = applicationTypeFor(simulation, compound);

                var aucRatio  = createRatioParameter(CoreConstants.PKAnalysis.AUCRatio, bloodPlasmaPK[pkParameterNameForAUCRatio(applicationType)], aucDDI, Constants.Dimension.DIMENSIONLESS);
                var cmaxRatio = createRatioParameter(CoreConstants.PKAnalysis.C_maxRatio, bloodPlasmaPK[pkParameterNameForCmaxRatio(applicationType)], cmaxDDI, Constants.Dimension.DIMENSIONLESS);

                var vssPlasma          = createParameter(CoreConstants.PKAnalysis.VssPlasma, bloodPlasmaPK[Constants.PKParameters.Vss], CoreConstants.Dimension.VolumePerBodyWeight);
                var vssPlasmaOverF     = createParameter(CoreConstants.PKAnalysis.VssPlasmaOverF, bloodPlasmaPK[Constants.PKParameters.Vss], CoreConstants.Dimension.VolumePerBodyWeight);
                var vdPlasma           = createParameter(CoreConstants.PKAnalysis.VdPlasma, bloodPlasmaPK[Constants.PKParameters.Vd], CoreConstants.Dimension.VolumePerBodyWeight);
                var vdPlasmaOverF      = createParameter(CoreConstants.PKAnalysis.VdPlasmaOverF, bloodPlasmaPK[Constants.PKParameters.Vd], CoreConstants.Dimension.VolumePerBodyWeight);
                var vssPhysChem        = createParameter(CoreConstants.PKAnalysis.VssPhysChem, calculateVSSPhysChemFor(simulation, compoundName), CoreConstants.Dimension.VolumePerBodyWeight);
                var totalPlasmaCL      = createParameter(CoreConstants.PKAnalysis.TotalPlasmaCL, bloodPlasmaPK[Constants.PKParameters.CL], CoreConstants.Dimension.FlowPerWeight);
                var totalPlasmaCLOverF = createParameter(CoreConstants.PKAnalysis.TotalPlasmaCLOverF, bloodPlasmaPK[Constants.PKParameters.CL], CoreConstants.Dimension.FlowPerWeight);

                if (_interactionTask.HasInteractionInvolving(compound, simulation))
                {
                    container.AddChildren(aucRatio, cmaxRatio);
                }

                var fractionAbsorbed = fractionAbsorbedFor(simulation, compoundName);

                //multiple application or no application? in that case, only show fraction absorbed for oral
                if (applicationType != ApplicationType.Single)
                {
                    if (isMultipleOral(simulation, compound))
                    {
                        container.Add(fractionAbsorbed);
                    }

                    continue;
                }

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

                if (isIntravenous(schemaItem))
                {
                    container.AddChildren(vssPlasma, vdPlasma, vssPhysChem, totalPlasmaCL);
                    continue;
                }

                var fractionAbsorbedWarningParameters = new List <IParameter>();
                if (bioAvailabilityCalculated)
                {
                    vssPlasma.Value     *= bioAvailabilityValue;
                    vdPlasma.Value      *= bioAvailabilityValue;
                    totalPlasmaCL.Value *= bioAvailabilityValue;
                    fractionAbsorbedWarningParameters.AddRange(new[] { vssPlasma, vdPlasma });
                    pkValues.AddRange(new[] { vssPlasma, vdPlasma, totalPlasmaCL, bioAvailability });
                }
                else
                {
                    fractionAbsorbedWarningParameters.AddRange(new[] { vssPlasmaOverF, vdPlasmaOverF });
                    pkValues.AddRange(new[] { vssPlasmaOverF, vdPlasmaOverF, totalPlasmaCLOverF, bioAvailability });
                }


                if (isOral(schemaItem))
                {
                    fractionAbsorbed.Rules.Add(fractionAbsorbedRule);
                    pkValues.Add(fractionAbsorbed);

                    if (bioAvailability.Value > fractionAbsorbed.Value)
                    {
                        bioAvailability.Rules.Add(bioAvailabilityRule);
                    }

                    addFractionAbsorvedWarningTo(fractionAbsorbed, fractionAbsorbedWarningParameters);
                }

                container.AddChildren(pkValues);
            }

            return(globalPKAnalysis);
        }
        protected override void Context()
        {
            _vssCalculator               = A.Fake <IVSSCalculator>();
            _parameterFactory            = A.Fake <IParameterFactory>();
            _protocolMapper              = A.Fake <IProtocolToSchemaItemsMapper>();
            _protocolFactory             = A.Fake <IProtocolFactory>();
            _globalPKAnalysisRunner      = A.Fake <IGlobalPKAnalysisRunner>();
            _pkCalculationOptionsFactory = A.Fake <IPKCalculationOptionsFactory>();
            _pkAnalysisTask              = A.Fake <IPKAnalysisTask>();
            _interactionTask             = A.Fake <IInteractionTask>();
            _cloner = A.Fake <ICloner>();
            sut     = new GlobalPKAnalysisTask(_parameterFactory, _protocolMapper, _protocolFactory, _globalPKAnalysisRunner,
                                               _pkAnalysisTask, _pkCalculationOptionsFactory, _vssCalculator, _interactionTask, _cloner);

            var baseGrid = new BaseGrid("time", A.Fake <IDimension>());

            _peripheralVenousBloodPlasma = CalculationColumnFor(baseGrid, CoreConstants.Organ.PeripheralVenousBlood, CoreConstants.Observer.PLASMA_PERIPHERAL_VENOUS_BLOOD, CoreConstants.Observer.PLASMA_PERIPHERAL_VENOUS_BLOOD, _compoundName);
            _venousBloodPlasma           = CalculationColumnFor(baseGrid, CoreConstants.Organ.VenousBlood, CoreConstants.Compartment.Plasma, CoreConstants.Observer.CONCENTRATION, _compoundName);

            _individual = A.Fake <Individual>();
            _species    = new Species();
            A.CallTo(() => _individual.Species).Returns(_species);

            _compound           = new Compound().WithName(_compoundName);
            _compoundProperties = new CompoundProperties {
                Compound = _compound
            };
            _simulationSchemaItems = new List <ISchemaItem>();
            _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
            };

            _venousBloodPK = new PKValues();
            _venousBloodPK.AddValue(Constants.PKParameters.Vss, 10);
            _venousBloodPK.AddValue(Constants.PKParameters.Vd, 11);
            _venousBloodPK.AddValue(Constants.PKParameters.CL, 12);

            _venousBloodPK.AddValue(Constants.PKParameters.AUC_inf, 13);
            _venousBloodPK.AddValue(Constants.PKParameters.AUC_inf_t1_norm, 14);

            _peripheralVenousBloodPK = new PKValues();
            _peripheralVenousBloodPK.AddValue(Constants.PKParameters.Vss, 21);
            _peripheralVenousBloodPK.AddValue(Constants.PKParameters.Vd, 22);
            _peripheralVenousBloodPK.AddValue(Constants.PKParameters.CL, 23);
            _peripheralVenousBloodPK.AddValue(Constants.PKParameters.AUC_inf, 24);
            _peripheralVenousBloodPK.AddValue(Constants.PKParameters.AUC_inf_t1_norm, 25);
            _peripheralVenousBloodPK.AddValue(Constants.PKParameters.C_max, 26);
            _peripheralVenousBloodPK.AddValue(Constants.PKParameters.C_max_tLast_tEnd, 27);


            A.CallTo(() => _pkAnalysisTask.CalculatePK(_venousBloodPlasma, A <PKCalculationOptions> ._)).Returns(_venousBloodPK);
            A.CallTo(() => _pkAnalysisTask.CalculatePK(_peripheralVenousBloodPlasma, A <PKCalculationOptions> ._)).Returns(_peripheralVenousBloodPK);
            A.CallTo(() => _parameterFactory.CreateFor(A <string> ._, A <double> ._, A <string> ._, PKSimBuildingBlockType.Simulation))
            .ReturnsLazily(s => new PKSimParameter().WithName((string)s.Arguments[0])
                           .WithDimension(A.Fake <IDimension>())
                           .WithFormula(new ConstantFormula((double)s.Arguments[1])));
        }