protected void SetHearingLevel(EarType ear, double freqHz, string hearingLevel) { HearingLevelValidation hlValidator = new HearingLevelValidation(); ValidationResult validResult = hlValidator.Validate(hearingLevel, CultureInfo.InvariantCulture); HLValidationError = validResult.IsValid ? String.Empty : validResult.ErrorContent.ToString(); if (validResult.IsValid) { if (HearingLevels.ContainsKey(freqHz)) { if (ear == EarType.RightEar) { HearingLevels[freqHz].RightEarHLdBStr = hearingLevel; } else if (ear == EarType.LeftEar) { HearingLevels[freqHz].LeftEarHLdBStr = hearingLevel; } else { throw new InvalidEnumArgumentException(); } } else { if (ear == EarType.RightEar) { HearingLevels.Add(freqHz, new HearingLevel { RightEarHLdBStr = hearingLevel }); } else if (ear == EarType.LeftEar) { HearingLevels.Add(freqHz, new HearingLevel { LeftEarHLdBStr = hearingLevel }); } else { throw new InvalidEnumArgumentException(); } } AudiogramPlot.UpdateEarPlot(ear, HearingLevels, AddBCFreqShift); if (ear == EarType.RightEar) { HasRtEarValidData = HearingLevels.Values.Any(hl => hl.RightEarHLdB != null || hl.RightEarHLdBStr == HearingLevelTypes.NoResponse.GetDescription()); } else if (ear == EarType.LeftEar) { HasLtEarValidData = HearingLevels.Values.Any(hl => hl.LeftEarHLdB != null || hl.LeftEarHLdBStr == HearingLevelTypes.NoResponse.GetDescription()); } else { throw new InvalidEnumArgumentException(); } } }
private void UpdateAvgSpPercImpairDisability(EarType earType) { double?th500; double?th1000; double?th2000; double?th3000; if (earType == EarType.RightEar) { if (HearingLevels.ContainsKey(500) && HearingLevels.ContainsKey(1000) && HearingLevels.ContainsKey(2000) && HearingLevels.ContainsKey(3000)) { th500 = HearingLevels[500].RightEarHLdB; th1000 = HearingLevels[1000].RightEarHLdB; th2000 = HearingLevels[2000].RightEarHLdB; th3000 = HearingLevels[3000].RightEarHLdB; if (th500 != null && th1000 != null && th2000 != null && th3000 != null) { AvgSpPerRtEar = (th500.Value + th1000.Value + th2000.Value + th3000.Value) / 4; if (AvgSpPerRtEar > 25) { ImpairRtEar = (AvgSpPerRtEar - 25) * 1.5; } else { ImpairRtEar = 0; } } } } else if (earType == EarType.LeftEar) { if (HearingLevels.ContainsKey(500) && HearingLevels.ContainsKey(1000) && HearingLevels.ContainsKey(2000) && HearingLevels.ContainsKey(3000)) { th500 = HearingLevels[500].LeftEarHLdB; th1000 = HearingLevels[1000].LeftEarHLdB; th2000 = HearingLevels[2000].LeftEarHLdB; th3000 = HearingLevels[3000].LeftEarHLdB; if (th500 != null && th1000 != null && th2000 != null && th3000 != null) { AvgSpPerLtEar = (th500.Value + th1000.Value + th2000.Value + th3000.Value) / 4; if (AvgSpPerLtEar > 25) { ImpairLtEar = (AvgSpPerLtEar - 25) * 1.5; } else { ImpairLtEar = 0; } } } } else { throw new NotImplementedException("Unimplemented EarType " + earType.ToString()); } if (ImpairRtEar < ImpairLtEar) { Disability = ((ImpairRtEar * 5) + ImpairLtEar) / 6; } else { Disability = ((ImpairLtEar * 5) + ImpairRtEar) / 6; } }