Example #1
0
        public void RetrieveDefaultValueFor(IndividualSettingsDTO individualSettingsDTO)
        {
            individualSettingsDTO.SubPopulation = _subPopulationDTOMapper.MapFrom(_originDataTask.DefaultSubPopulationFor(individualSettingsDTO.Species));
            //Default parameter such as age etc.. were not defined yet
            var originData   = _originDataMapper.MapFrom(individualSettingsDTO);
            var parameterAge = _parameterMapper.MapAsReadWriteFrom(_individualModelTask.MeanAgeFor(originData));

            originData.Age = parameterAge.KernelValue;

            var parameterGestationalAge = _parameterMapper.MapAsReadWriteFrom(_individualModelTask.MeanGestationalAgeFor(originData));

            originData.GestationalAge = parameterGestationalAge.KernelValue;
            setDefaultValues(individualSettingsDTO, originData, parameterAge, parameterGestationalAge);
        }
        public void UpdateDefaultValueFor(IndividualSettingsDTO individualSettingsDTO)
        {
            individualSettingsDTO.SubPopulation = _subPopulationDTOMapper.MapFrom(_originDataTask.DefaultSubPopulationFor(individualSettingsDTO.Species));
            //Default parameter such as age etc.. were not defined yet
            var originData   = _originDataMapper.MapFrom(individualSettingsDTO);
            var parameterAge = _individualModelTask.MeanAgeFor(originData);

            if (parameterAge != null)
            {
                originData.Age = new OriginDataParameter(parameterAge.Value);
            }

            var parameterGestationalAge = _individualModelTask.MeanGestationalAgeFor(originData);

            if (parameterGestationalAge != null)
            {
                originData.GestationalAge = new OriginDataParameter(parameterGestationalAge.Value);
            }

            setDefaultValues(individualSettingsDTO, originData, _parameterMapper.MapAsReadWriteFrom(parameterAge), _parameterMapper.MapAsReadWriteFrom(parameterGestationalAge));
        }
Example #3
0
        public Model.OriginData MapFrom(BatchOriginData batchOriginData)
        {
            var originData = new Model.OriginData();
            var species    = _speciesRepository.FindByName(batchOriginData.Species);

            if (species == null)
            {
                throw new PKSimException(PKSimConstants.Error.CouldNotFindSpecies(batchOriginData.Species, _speciesRepository.AllNames()));
            }

            originData.Species = species;

            var population = species.PopulationByName(batchOriginData.Population);

            if (population == null)
            {
                if (string.IsNullOrEmpty(batchOriginData.Population) && species.Populations.Count() == 1)
                {
                    population = species.Populations.ElementAt(0);
                }
                else
                {
                    throw new PKSimException(PKSimConstants.Error.CouldNotFindPopulationForSpecies(batchOriginData.Population, batchOriginData.Species, species.Populations.AllNames()));
                }
            }

            originData.SpeciesPopulation = population;

            var gender = population.GenderByName(batchOriginData.Gender);

            if (gender == null)
            {
                if (string.IsNullOrEmpty(batchOriginData.Gender))
                {
                    gender = population.Genders.ElementAt(0);
                }
                else
                {
                    throw new PKSimException(PKSimConstants.Error.CouldNotFindGenderForPopulation(batchOriginData.Gender, batchOriginData.Population, population.Genders.AllNames()));
                }
            }

            originData.Gender = gender;
            //this is not defined in matlab yet
            originData.SubPopulation = _originDataTask.DefaultSubPopulationFor(species);

            if (originData.SpeciesPopulation.IsAgeDependent)
            {
                originData.Age = batchOriginData.Age;
                var meanAgeParameter = _individualModelTask.MeanAgeFor(originData);
                originData.Age                = valueFrom(batchOriginData.Age, meanAgeParameter.Value);
                originData.AgeUnit            = meanAgeParameter.Dimension.BaseUnit.Name;
                originData.GestationalAge     = valueFrom(batchOriginData.GestationalAge, CoreConstants.NOT_PRETERM_GESTATIONAL_AGE_IN_WEEKS);
                originData.GestationalAgeUnit = CoreConstants.Units.Weeks;
            }

            var calculationMethodCategoryForSpecies = _originDataTask.AllCalculationMethodCategoryFor(species);

            foreach (var category in calculationMethodCategoryForSpecies)
            {
                string selectedCalculationMethod = batchOriginData.CalculationMethodFor(category.Name);
                if (string.IsNullOrEmpty(selectedCalculationMethod))
                {
                    originData.AddCalculationMethod(category.DefaultItemForSpecies(species));
                }
                else
                {
                    var calculationMethod = category.AllItems().FindByName(selectedCalculationMethod);
                    if (calculationMethod == null)
                    {
                        throw new PKSimException(PKSimConstants.Error.CouldNotFindCalculationMethodInCategory(selectedCalculationMethod, category.Name, category.AllItems().AllNames()));
                    }
                    if (calculationMethod.AllSpecies.Contains(species.Name))
                    {
                        originData.AddCalculationMethod(calculationMethod);
                    }
                    else
                    {
                        throw new PKSimException(PKSimConstants.Error.CalculationMethodIsNotDefinedForSpecies(selectedCalculationMethod, category.Name, species.Name));
                    }
                }
            }

            var meanWeightParameter = _individualModelTask.MeanWeightFor(originData);

            originData.Weight     = valueFrom(batchOriginData.Weight, meanWeightParameter.Value).Value;
            originData.WeightUnit = meanWeightParameter.Dimension.BaseUnit.Name;

            if (originData.SpeciesPopulation.IsHeightDependent)
            {
                var meanHeightParameter = _individualModelTask.MeanHeightFor(originData);
                originData.Height     = valueFrom(batchOriginData.Height, meanHeightParameter.Value);
                originData.HeightUnit = meanHeightParameter.Dimension.BaseUnit.Name;
            }

            return(originData);
        }