/// <summary> /// Calculates the scores for all domains belonging to the questionnaire includes and saves them to the database. Any existing domains are overwritten. /// This is ONLY done for PROs /// </summary> /// <param name="group">The group to calculate the scores for</param> public void CalculateResponseScores(QuestionnaireUserResponseGroup group) { if (group.Questionnaire.GetType() == typeof(ProInstrument)) { ProDomainResultSet proDomainResultSet = this.ProcessGroup(group); this.manager.QuestionnaireAccessHandler.SaveProDomainResult(proDomainResultSet); } }
/// <summary> /// Saves the given ProDomainResultSet and all results to the database /// </summary> /// <param name="proDomainResultSet">The ProDomainResultSet to save</param> public void SaveProDomainResult(ProDomainResultSet proDomainResultSet) { if (proDomainResultSet.GroupId < 1) { proDomainResultSet.GroupId = proDomainResultSet.Group.Id; } this.context.ProDomainResultSet.Where(pds => pds.Group.Id == proDomainResultSet.GroupId).ToList().ForEach(pds => this.context.Entry(pds).State = EntityState.Deleted); this.context.ProDomainResultSet.Add(proDomainResultSet); this.context.SaveChanges(); }
/// <summary> /// Processes a QuestionnaireUserResponseGroup and calculates the domain results for it. /// The domain must be loaded in the the questionnaire (PRO) of the group /// </summary> /// <param name="group">The group to get the result for</param> /// <returns>A ProDomainResultSet containing the list of calculated PRO Domain Results</returns> private ProDomainResultSet ProcessGroup(QuestionnaireUserResponseGroup group) { ProDomainResultSet gr = new ProDomainResultSet(); gr.GroupId = group.Id; foreach (ProDomain domain in ((ProInstrument)group.Questionnaire).Domains) { ProDomainResult result = new ProDomainResult(); result.DomainId = domain.Id; result.Score = DomainScoreEngine.DomainScoreEngine.CalculateResult(group.Responses.ToList(), domain.ScoreFormula); gr.Results.Add(result); } return(gr); }