private static ManualScaleDefinition ParseManScaleFromXml(XmlNode manScaleNode) { string name = ParseXmlAttribute(manScaleNode, "name"); string scaleName = ParseXmlAttribute(manScaleNode, "scaleName"); string questionsString = ParseXmlAttribute(manScaleNode, "questions"); int _slope = Convert.ToInt16(ParseXmlAttribute(manScaleNode, "slope")); int _intercept = Convert.ToInt16(ParseXmlAttribute(manScaleNode, "intercept")); int _max = Convert.ToInt16(ParseXmlAttribute(manScaleNode, "max")); int _maxResponse = Convert.ToInt16(ParseXmlAttribute(manScaleNode, "maxResponse")); string[] questions; Dictionary <int, int> manualScoreTable = new Dictionary <int, int>(); questions = questionsString.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); XmlNodeList scoreMapvals = manScaleNode.SelectNodes("scoreMapValue"); foreach (XmlNode scoreitem in scoreMapvals) { string _response = scoreitem.SelectSingleNode("response").InnerText; string _score = scoreitem.SelectSingleNode("score").InnerText; int response = Convert.ToInt16(_response); int score = Convert.ToInt16(_score); manualScoreTable.Add(response, score); } ManualScaleDefinition manscaledef = new ManualScaleDefinition(name, scaleName, questions, _slope, _intercept, _max, _maxResponse, manualScoreTable); return(manscaledef); }
public BreastQScaleScore GetScaleScore(ScaleDefinition scaleDefinition, int[] scaleResponses) { // ask if scale is defined in QScoreLibrary QScoreLibrary.Estimation.eScales?_scale = null; // manual scale ManualScaleDefinition manualScale = null; _scale = BreastQEngine.GetScale(scaleDefinition.Scale); Estimation.eErrors scaleError = Estimation.eErrors.eErrorNoResponseData; int?scaleScore = null; if (_scale.HasValue) { // use breastq assembly to calculate the score int engineScore = (int)scoringEngine.EstimateQuestionnaireScale(_scale.Value, scaleResponses, out scaleError); if (scaleError == Estimation.eErrors.eNoError) { scaleScore = engineScore; } } else if (manualScaleLookup.TryGetValue(scaleDefinition.Scale, out manualScale)) { // score manually int[] convertedResponses = new int[scaleResponses.Length]; for (int i = 0; i < scaleResponses.Length; i++) { convertedResponses[i] = manualScale.slope * scaleResponses[i] + manualScale.intercept; //Some responses saturate. if (convertedResponses[i] > manualScale.max) { convertedResponses[i] = manualScale.max; } //0 is an invalid response for all manual scales if (scaleResponses[i] == 0) { convertedResponses[i] = -1; } } int responseSum = convertedResponses.Sum(); int finalScore; if (!manualScale.ScoreHashTable.TryGetValue(responseSum, out finalScore)) { //finalScore = -1; //invalid sum scaleError = Estimation.eErrors.eErrorNoResponseData; } else if (scaleResponses.Max() > manualScale.maxResponse) { //invalid response //finalScore = -1; scaleError = Estimation.eErrors.eErrorImplementationResponsesInvalidValue; } else { scaleError = Estimation.eErrors.eNoError; scaleScore = finalScore; } } else if (!string.IsNullOrEmpty(scaleDefinition.Alias)) { _scale = BreastQEngine.GetScale(scaleDefinition.Alias); if (_scale.HasValue) { // can you call this function recursively? int engineScore = (int)scoringEngine.EstimateQuestionnaireScale(_scale.Value, scaleResponses, out scaleError); if (scaleError == Estimation.eErrors.eNoError) { scaleScore = engineScore; } } } BreastQScaleScore breastQScore = new BreastQScaleScore(); // set error code if (_scale == null && manualScale == null) { breastQScore.Error = Estimation.eErrors.eErrorImplementationInvalidScaleEnum; } else { breastQScore.Error = scaleError; } breastQScore.Scale = scaleDefinition; // set score if (scaleError == Estimation.eErrors.eNoError && scaleScore.HasValue) { breastQScore.Score = (int?)scaleScore; } else { breastQScore.Score = null; } return(breastQScore); }