Example #1
0
 public BreastQScaleScore(ScaleDefinition scale, int score, Estimation.eErrors error)
     : this()
 {
     Scale = scale;
     Score = score;
     Error = error;
 }
Example #2
0
        private static ScaleDefinition ParseScaleFromXml(XmlNode scaleNode)
        {
            QScoreLibrary.Estimation.eScales?scaleEnum = null;
            string name      = ParseXmlAttribute(scaleNode, "name");
            string scaleName = ParseXmlAttribute(scaleNode, "scaleName");
            string questions = ParseXmlAttribute(scaleNode, "numbers");
            string alias     = ParseXmlAttribute(scaleNode, "alias");

            if (!string.IsNullOrEmpty(scaleName) && !string.IsNullOrEmpty(questions))
            {
                string[]        questionsList = questions.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                ScaleDefinition tempScaleDef  = new ScaleDefinition(scaleName, name, questionsList);

                if (!string.IsNullOrEmpty(alias))
                {
                    tempScaleDef.Alias = alias;
                }

                /*
                 * if (!string.IsNullOrEmpty(maxResponse))
                 * {
                 *  tempScaleDef.maxResponse = Convert.ToInt16(maxResponse);
                 * }
                 *
                 */
                return(tempScaleDef);
            }


            return(null);
        }
Example #3
0
 /// <summary>
 /// Gets an normalized (pad invalid/empty responses) to match scale definition expectations.
 /// </summary>
 /// <param name="scaleDefinition"></param>
 /// <param name="surveyResponses"></param>
 /// <returns></returns>
 public int[] GetScaleResponses(ScaleDefinition scaleDefinition, IDictionary <string, int?> surveyResponses)
 {
     // create array of responses
     int[] responses = new int[scaleDefinition.NumberOfItems];
     for (int i = 0; i < scaleDefinition.NumberOfItems; i++)
     {
         string questionNum = scaleDefinition.Questions[i];
         // default response
         int questionResponse = NO_RESPONSE_VALUE;
         // check response (if applicable)
         if (surveyResponses.ContainsKey(questionNum))
         {
             int?surveyResponse = surveyResponses[questionNum];
             if (surveyResponse.HasValue)
             {
                 questionResponse = surveyResponse.Value;
             }
         }
         // set response
         responses[i] = questionResponse;
     }
     return(responses);
 }
Example #4
0
 public BreastQScaleScore()
 {
     Scale = new ScaleDefinition();
     Score = null;
     Error = Estimation.eErrors.eNoError;
 }
Example #5
0
        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);
        }
Example #6
0
 /// <summary>
 /// Gets the score for the specificed scale.
 /// </summary>
 /// <param name="scaleDefinition"></param>
 /// <param name="surveyResponses"></param>
 /// <returns></returns>
 public BreastQScaleScore GetScaleScore(ScaleDefinition scaleDefinition, IDictionary <string, int?> surveyResponses)
 {
     int[] responses = GetScaleResponses(scaleDefinition, surveyResponses);
     return(GetScaleScore(scaleDefinition, responses));
 }
Example #7
0
 public BreastQScaleScore GetScaleScore(ScaleDefinition scaleDefinition, IDictionary <string, int> surveyResponses)
 {
     return(GetScaleScore(scaleDefinition, surveyResponses.ToDictionary(a => a.Key, v => true ? v.Value : (int?)null)));
 }
Example #8
0
        /*
         * public Dictionary<string, int> GetManSurveyScoreByScale(string surveyType, IDictionary<string,int> surveyResponses)
         * {
         *
         * }
         */


        public BreastQScaleScore GetScaleScore(ScaleDefinition scaleDefinition, IEnumerable <BreastQResponse> responses)
        {
            return(GetScaleScore(scaleDefinition, responses.ToDictionary(k => k.Question, v => v.Response)));
        }