コード例 #1
0
        public IEnumerable <BreastQPoint> GetBreastQPointsByPhysicians(string[] apptPhysicians, string surveyType, string[] questions, Dictionary <int, List <int> > patientsToSurveys)
        {
            // capture distinct points
            List <BreastQPoint> breastQPoints = new List <BreastQPoint>();

            // consume by Physician's patients
            if (apptPhysicians.Count() > 0)
            {
                da.ConsumeBreastQSurveyDataByPhysician(datasetSQL, apptPhysicians, surveyType, questions, (record) => { FillBreastQPoints(surveyType, surveyType, questions, breastQPoints, patientsToSurveys, record); return(true); });
            }
            // consume by all patients
            else
            {
                da.ConsumeBreastQSurveyData(datasetSQL, surveyType, questions, (record) => { FillBreastQPoints(surveyType, surveyType, questions, breastQPoints, patientsToSurveys, record); return(true); });
            }

            return(breastQPoints);
        }
コード例 #2
0
        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);
        }