Example #1
0
        /// <summary>
        /// Initalize the breast Q engine
        /// </summary>
        protected void InitBreastQ()
        {
            string datasetSQL = CacheManager.GetDatasetSQL(Session[SessionKey.DatasetId]);

            service = new CaisisBreastQServices(datasetSQL);
            engine  = new CaisisBreastQEngine();
        }
Example #2
0
        protected void ViewBreastQDefinitions(IEnumerable <string> surveyTypes)
        {
            bool doFilter = surveyTypes.Count() > 0;
            CaisisBreastQEngine engine = new CaisisBreastQEngine();
            var surveys = from survey in engine.GetAllDefinitions()
                          from scale in survey.Definitions
                          // optional filter by survey
                          where !doFilter || surveyTypes.Contains(survey.SurveyType, StringComparer.OrdinalIgnoreCase)
                          let def = new
            {
                Survey         = survey.SurveyType,
                ScaleName      = scale.Scale,
                ScaleTitle     = scale.Title,
                ScaleAlias     = scale.Alias,
                ScaleQuestions = string.Join(",", scale.Questions),
                ManualScoring  = engine.manualScaleLookup.ContainsKey(scale.Scale).ToString().ToUpper()
            }
            group def by survey.SurveyType into g
            orderby g.Key
                select new
            {
                Survey      = g.Key,
                Definitions = g
            };

            SurveysRptr.DataSource = surveys;
            SurveysRptr.DataBind();
            SurveysRptr.Visible = true;
        }
        private IEnumerable <string> BuildSurveyMappings()
        {
            typesToSurveys.Clear();
            CaisisBreastQEngine engine = new CaisisBreastQEngine();
            var definitions            = engine.GetAllDefinitions();

            foreach (string type in types)
            {
                var surveyTypes = definitions.Where(d => d.SurveyType.Contains(type)).Select(d => d.SurveyType);
                if (surveyTypes.Count() > 0 && !typesToSurveys.ContainsKey(type))
                {
                    typesToSurveys.Add(type, surveyTypes.ToArray());
                }
            }
            return(typesToSurveys.Keys);
        }
        private DataView GetBreastQReport(string surveyGroup, string subType)
        {
            // validate type map
            if (!typesToSurveys.ContainsKey(surveyGroup))
            {
                return(new DataTable().DefaultView);
            }
            IEnumerable <string> surveyTypes = typesToSurveys[surveyGroup];

            Caisis.Controller.PatientController pc = new Controller.PatientController();
            string datasetSQL            = CacheManager.GetDatasetSQL(Session[SessionKey.DatasetId]);
            CaisisBreastQEngine engine   = new CaisisBreastQEngine();
            SurveyDa            surveyDA = new SurveyDa();
            List <Dictionary <string, string> > allScores = new List <Dictionary <string, string> >();
            var aliasMap = GetAliasToSurveys();

            foreach (string surveyType in surveyTypes)
            {
                var      survey    = engine.GetSurveyDefinition(surveyType);
                var      scales    = survey.Definitions;
                string[] questions = scales.SelectMany(s => s.Questions).Distinct().ToArray();

                string[] _surveyTypes = new string[] { surveyType };
                // special case
                if (aliasMap.ContainsKey(surveyType))
                {
                    _surveyTypes = aliasMap[surveyType].ToArray();
                }
                foreach (string _surveyType in _surveyTypes)
                {
                    // optional filter by exact survey
                    if (string.IsNullOrEmpty(subType) || subType.Equals(_surveyType, StringComparison.OrdinalIgnoreCase))
                    {
                        string engineSurveyType = surveyType;
                        // TODO: refactor into generic class to read and fill scores data table
                        // read pivotted row (patient+survey+questions), and score
                        surveyDA.ConsumeBreastQSurveyData(datasetSQL, _surveyType, questions, (record) =>
                        {
                            // get responses, 1a=>2, 1b=>2, ...
                            Dictionary <string, string> responses = questions.ToDictionary(q => q, q => record[q].ToString());
                            // get scores by scale, Satisfaction With Breasts => 56, ...
                            Dictionary <string, BreastQ.BreastQScaleScore> scores = engine.GetSurveyScoreByScale(engineSurveyType, responses);
                            // create column values
                            Dictionary <string, string> values = new Dictionary <string, string>();
                            // add required columns
                            values.Add("MRN", pc.GetPatientMRN(record["PtMRN"].ToString()));
                            values.Add("Survey", _surveyType);
                            values.Add("Date", string.Format("{0:d}", record["SurveyDate"]));
                            // fill in scale scores
                            foreach (var score in scores)
                            {
                                string scaleName  = score.Key;
                                string scaleValue = "";
                                // valida score
                                if (score.Value.Error == QScoreLibrary.Estimation.eErrors.eNoError)
                                {
                                    scaleValue = score.Value.Score.ToString();
                                }
                                // error in scoring
                                else
                                {
                                    scaleValue = "FAIL: " + engine.GetQScoreErrorString(score.Value.Error);
                                }

                                //values.Add(score.Key, score.Value.Score.ToString());
                                values.Add(scaleName, scaleValue);
                            }

                            // add row
                            allScores.Add(values);

                            // continue
                            return(true);
                        });
                    }
                }
            }

            // get a list of columns across patients (i.e., PtMRN, Date, Scale 1, Scale 3, Scale 7)
            string[] columns        = allScores.SelectMany(s => s.Keys).Distinct().ToArray();
            string[] patientColumns = new string[] { "MRN", "Survey", "Date" };
            string[] scaleColumns   = columns.Except(patientColumns).ToArray();
            // normalize datasource
            DataTable dataSource = new DataTable();

            dataSource.Columns.AddRange(columns.Select(c => new DataColumn(c, typeof(String))).ToArray());
            // for each row, normalize values
            foreach (var row in allScores)
            {
                object[] values = new object[columns.Length];
                for (int i = 0; i < columns.Length; i++)
                {
                    string column = columns[i];
                    // add patient columns
                    if (patientColumns.Contains(column))
                    {
                        values[i] = row[column];
                    }
                    else if (scaleColumns.Contains(column))
                    {
                        // applicable scale
                        if (row.ContainsKey(column))
                        {
                            values[i] = row[column];
                        }
                        // non-applicable scale
                        else
                        {
                            values[i] = "N/A";
                        }
                    }
                }
                dataSource.Rows.Add(values);
            }

            return(dataSource.DefaultView);
        }