Skip to content

Commit

Permalink
fix: wrong unit for hair in hazard characterisations (#1957)
Browse files Browse the repository at this point in the history
  • Loading branch information
Voorthuijsen, Tijmen van committed May 31, 2024
1 parent 4cf37cb commit adb1fb7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
11 changes: 0 additions & 11 deletions MCRA.General/UnitDefinitions/McraUnitDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public partial class McraUnitDefinitions {
private static IDictionary<string, UnitDefinition> _unitDefinitions = null;

public static readonly ConcentrationUnit DefaultExternalConcentrationUnit = ConcentrationUnit.mgPerKg;
public static readonly ConcentrationUnit DefaultInternalConcentrationUnit = ConcentrationUnit.ugPerL;

/// <summary>
/// Singleton accessor.
Expand All @@ -27,16 +26,6 @@ public static McraUnitDefinitions Instance {
}
}

public static ExposureUnitTriple GetDefaultInternalTargetExposureUnit(ExpressionType expressionType) {
return expressionType switch {
ExpressionType.None => new ExposureUnitTriple(DefaultInternalConcentrationUnit.GetSubstanceAmountUnit(), DefaultInternalConcentrationUnit.GetConcentrationMassUnit()),
ExpressionType.Lipids => new ExposureUnitTriple(DefaultInternalConcentrationUnit.GetSubstanceAmountUnit(), ConcentrationMassUnit.Grams),
ExpressionType.Creatinine => new ExposureUnitTriple(DefaultInternalConcentrationUnit.GetSubstanceAmountUnit(), ConcentrationMassUnit.Grams),
ExpressionType.SpecificGravity => new ExposureUnitTriple(DefaultInternalConcentrationUnit.GetSubstanceAmountUnit(), DefaultInternalConcentrationUnit.GetConcentrationMassUnit()),
_ => throw new NotImplementedException(),
};
}

private McraUnitDefinitions() {
_unitDefinitions = _loadUnitDefinitions();
}
Expand Down
11 changes: 11 additions & 0 deletions MCRA.General/UnitDefinitions/Units/ExposureUnitTriple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ public static ExposureUnitTriple FromExposureUnit(ExternalExposureUnit exposureU
);
}

public static ExposureUnitTriple FromExposureTarget(ExposureTarget exposureTarget) {
var defaultUnit = exposureTarget.BiologicalMatrix.GetTargetConcentrationUnit();
return exposureTarget.ExpressionType switch {
ExpressionType.None => new ExposureUnitTriple(defaultUnit.GetSubstanceAmountUnit(), defaultUnit.GetConcentrationMassUnit()),
ExpressionType.Lipids => new ExposureUnitTriple(defaultUnit.GetSubstanceAmountUnit(), ConcentrationMassUnit.Grams),
ExpressionType.Creatinine => new ExposureUnitTriple(defaultUnit.GetSubstanceAmountUnit(), ConcentrationMassUnit.Grams),
ExpressionType.SpecificGravity => new ExposureUnitTriple(defaultUnit.GetSubstanceAmountUnit(), defaultUnit.GetConcentrationMassUnit()),
_ => throw new NotImplementedException(),
};
}

/// <summary>
/// Creates a external (dietary) target exposure unit based on the provided
/// food consumption unit, concentration unit, bodyweight unit, and specification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,10 @@ public void LoadData_DifferentExpressionTypes_ShouldApplyCorrectoseUnitAlignment
project.AssessmentSettings.ExposureType = exposureType;
project.EffectSettings.TargetDoseLevelType = TargetLevelType.Internal;

var biologicalMatrix = expressionType == ExpressionType.Creatinine ? BiologicalMatrix.Urine : BiologicalMatrix.Blood;
var compiledData = new CompiledData() {
AllHazardCharacterisations = MockHazardCharacterisationsGenerator
.Create(substances, effect, exposureType, 100, ExposurePathType.AtTarget, TargetLevelType.Internal, doseUnit, BiologicalMatrix.Blood, expressionType)
.Create(substances, effect, exposureType, 100, ExposurePathType.AtTarget, TargetLevelType.Internal, doseUnit, biologicalMatrix, expressionType)
.Values.Cast<HazardCharacterisation>()
.ToList()
};
Expand All @@ -395,4 +396,4 @@ public void LoadData_DifferentExpressionTypes_ShouldApplyCorrectoseUnitAlignment
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ protected override void loadData(ActionData data, SubsetManager subsetManager, C
.Where(r => substances.Contains(r.Substance))
.GroupBy(c => CreateExposureTargetKey(c))
.Select(hc => {
var targetUnit = createTargetUnit(settings.TargetDoseLevel, data, hc.Key);
// MCRA expresses the hazard characterisaiton values in a default unit, so imported values may
// be scaled to match these default units.
var targetUnit = getDefaultTargetUnit(settings.TargetDoseLevel, data, hc.Key);
var hazardDoseConverter = new HazardDoseConverter(targetUnit.ExposureUnit);
return new HazardCharacterisationModelCompoundsCollection {
TargetUnit = targetUnit,
Expand All @@ -119,8 +121,6 @@ protected override void loadData(ActionData data, SubsetManager subsetManager, C
.OrderBy(r => r.TargetUnit.BiologicalMatrix)
.ThenBy(r => r.TargetUnit.ExpressionType)
.ToList();


}

protected override void loadDataUncertain(
Expand Down Expand Up @@ -153,7 +153,7 @@ protected override HazardCharacterisationsActionResult run(ActionData data, Comp

var exposureTargets = GetExposureTargets(data, settings);
foreach (var exposureTarget in exposureTargets) {
var targetUnit = createTargetUnit(settings.TargetDoseLevel, data, exposureTarget);
var targetUnit = getDefaultTargetUnit(settings.TargetDoseLevel, data, exposureTarget);
var hazardDoseConverter = new HazardDoseConverter(
settings.GetTargetHazardDoseType(),
targetUnit.ExposureUnit
Expand Down Expand Up @@ -217,7 +217,7 @@ CompositeProgressState progressReport

var exposureTargets = GetExposureTargets(data, settings);
foreach (var exposureTarget in exposureTargets) {
var targetUnit = createTargetUnit(settings.TargetDoseLevel, data, exposureTarget);
var targetUnit = getDefaultTargetUnit(settings.TargetDoseLevel, data, exposureTarget);
var hazardDoseConverter = new HazardDoseConverter(
settings.GetTargetHazardDoseType(),
targetUnit.ExposureUnit
Expand Down Expand Up @@ -619,7 +619,7 @@ IRandom generator
return result;
}

private TargetUnit createTargetUnit(
private TargetUnit getDefaultTargetUnit(
TargetLevelType targetLevelType,
ActionData data,
ExposureTarget exposureTarget
Expand All @@ -635,7 +635,7 @@ ExposureTarget exposureTarget
isPerPerson: false
);
} else {
return new TargetUnit(exposureTarget, McraUnitDefinitions.GetDefaultInternalTargetExposureUnit(exposureTarget.ExpressionType));
return new TargetUnit(exposureTarget, ExposureUnitTriple.FromExposureTarget(exposureTarget));
};
}

Expand Down

0 comments on commit adb1fb7

Please sign in to comment.