/// <summary> /// Gets the score for the specificed scale. /// </summary> /// <param name="scaleDefinition"></param> /// <param name="surveyResponses"></param> /// <returns></returns> private int GetScaleScore(ScaleDefinition scaleDefinition, IDictionary <string, int> surveyResponses) { // get required mappings Estimation.eScales _scale = scaleDefinition.Scale; Estimation.eErrors _error = Estimation.eErrors.eNoError; // create array of responses int[] _responses = new int[scaleDefinition.NumberOfItems]; for (int i = 0; i < scaleDefinition.NumberOfItems; i++) { string questionNum = scaleDefinition.Questions[i]; // set default response int questionResponse = NO_RESPONSE_VALUE; // set response value (if applicable) if (surveyResponses.ContainsKey(questionNum)) { questionResponse = surveyResponses[questionNum]; } _responses[i] = questionResponse; } // score scale uint scaleScore = scoringEngine.EstimateQuestionnaireScale(_scale, _responses, out _error); // check error status string errorText = QScoreError(_error); return((int)scaleScore); }
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); }