Exemple #1
0
        protected override SummaryRequestModel ConvertToModel(DTO.QueryComposer.QueryComposerRequestDTO request)
        {
            var criteria = request.Where.Criteria.First();

            SummaryRequestModel model = new SummaryRequestModel();

            //var observationPeriodTerm = criteria.Terms.FirstOrDefault(t => t.Type == ModelTermsFactory.YearID);
            var observationPeriodTerm = GetAllCriteriaTerms(criteria, ModelTermsFactory.YearID).FirstOrDefault();

            if (observationPeriodTerm != null)
            {
                model.StartPeriod = observationPeriodTerm.GetStringValue("StartYear");
                model.EndPeriod   = observationPeriodTerm.GetStringValue("EndYear");
                model.Period      = string.Join(",", QueryAdapter.ExpandYears(model).Select(y => "'" + y + "'"));//used in query
            }

            //var codeTerms = criteria.Criteria.SelectMany(c => c.Terms.Where(t => t.Type == ModelTermsFactory.ICD9DiagnosisCodes3digitID)).Concat(criteria.Terms.Where(t => t.Type == ModelTermsFactory.ICD9DiagnosisCodes3digitID));
            var codeTerms = GetAllCriteriaTerms(criteria, ModelTermsFactory.ICD9DiagnosisCodes3digitID);
            IEnumerable <string> codeTermValues = from t in codeTerms
                                                  from v in t.GetCodeStringCollection()
                                                  where !string.IsNullOrWhiteSpace(v)
                                                  select v.Trim();

            model.Codes     = string.Join(",", codeTermValues.Distinct());
            model.CodeNames = null;//this is a collection of the full names of the codes selected, original query used in the crossjoin for the name of the code, pulling from db now

            DTO.Enums.Settings settingValue;
            var setting = GetAllCriteriaTerms(criteria, ModelTermsFactory.SettingID).FirstOrDefault();

            if (setting.GetEnumValue("Setting", out settingValue))
            {
                model.Setting = settingValue.ToString();
            }

            //These values are pulled from the stratification section of the request json
            var ageStratification = request.Select.Fields.Where(f => f.Type == ModelTermsFactory.AgeRangeID).FirstOrDefault();

            if (ageStratification != null)
            {
                QueryAdapter.SetAgeStratification(model, ageStratification);
            }

            //var sexTerm = criteria.Criteria.Select(y => y.Terms.Where( z => z.Type == ModelTermsFactory.SexID).FirstOrDefault());
            var sexStratification = GetAllCriteriaTerms(criteria, ModelTermsFactory.SexID).FirstOrDefault();

            if (sexStratification != null)
            {
                QueryAdapter.SetSexStratification(model, sexStratification);
            }

            model.Coverage       = null; //not applicable to this query
            model.MetricType     = "0";  //not applicable to this query
            model.OutputCriteria = "0";  //not applicable to this query
            model.StartQuarter   = null; //not applicable to this query
            model.EndQuarter     = null; //not applicable to this query
            model.SubtypeId      = 0;    //value never gets set in ui of v5 summary query composer

            return(model);
        }
        protected override SummaryRequestModel ConvertToModel(DTO.QueryComposer.QueryComposerRequestDTO request)
        {
            var criteria = request.Where.Criteria.First();

            SummaryRequestModel model = new SummaryRequestModel();
            var observationPeriodTerm = GetAllCriteriaTerms(criteria, ModelTermsFactory.YearID).FirstOrDefault();

            if (observationPeriodTerm != null)
            {
                model.StartPeriod = observationPeriodTerm.GetStringValue("StartYear");
                model.EndPeriod   = observationPeriodTerm.GetStringValue("EndYear");
                model.Period      = string.Join(",", QueryAdapter.ExpandYears(model).Select(y => "'" + y + "'"));//used in query
            }

            IEnumerable <DTO.QueryComposer.QueryComposerTermDTO> codeTerms = criteria.Criteria.SelectMany(c => c.Terms.Where(t => t.Type == TermID)).Concat(criteria.Terms.Where(t => t.Type == TermID));

            var codeTermValues = (from t in codeTerms
                                  let v = t.GetCodeSelectorValues()
                                          from c in v
                                          where c != null && !string.IsNullOrWhiteSpace(c.Code)
                                          select c).GroupBy(k => k.Code.Trim()).Select(k => new { Code = k.Key, Name = k.Select(c => c.Name).FirstOrDefault() ?? k.Key }).ToArray();

            model.Codes     = string.Join(",", codeTermValues.Select(c => c.Code));
            model.CodeNames = codeTermValues.Select(c => c.Name).ToArray();

            DTO.Enums.Settings settingValue;
            var set = GetAllCriteriaTerms(criteria, ModelTermsFactory.SettingID).FirstOrDefault();

            if (set.GetEnumValue("Setting", out settingValue))
            {
                model.Setting = settingValue.ToString();
            }

            //These values are pulled from the stratification section of the request json
            var ageStratification = request.Select.Fields.Where(f => f.Type == ModelTermsFactory.AgeRangeID).FirstOrDefault();

            if (ageStratification != null)
            {
                QueryAdapter.SetAgeStratification(model, ageStratification);
            }

            var sexStratification = GetAllCriteriaTerms(criteria, ModelTermsFactory.SexID).FirstOrDefault();

            if (sexStratification != null)
            {
                QueryAdapter.SetSexStratification(model, sexStratification);
            }

            model.Coverage       = null; //not applicable to this query
            model.MetricType     = "0";  //not applicable to this query
            model.OutputCriteria = "0";  //not applicable to this query
            model.StartQuarter   = null; //not applicable to this query
            model.EndQuarter     = null; //not applicable to this query
            model.SubtypeId      = 0;    //value never gets set in ui of v5 summary query composer

            return(model);
        }
Exemple #3
0
        protected override SummaryRequestModel ConvertToModel(DTO.QueryComposer.QueryComposerRequestDTO request)
        {
            SummaryRequestModel model = new SummaryRequestModel();

            var criteria = request.Where.Criteria.First();

            var observationPeriodTerm = GetAllCriteriaTerms(criteria, ModelTermsFactory.QuarterYearID).FirstOrDefault();

            if (observationPeriodTerm != null)
            {
                model.StartPeriod = observationPeriodTerm.GetStringValue("StartYear");
                model.EndPeriod   = observationPeriodTerm.GetStringValue("EndYear");
                model.Period      = string.Join(",", QueryAdapter.ExpandYears(model).Select(y => "'" + y + "'"));//used in query
            }

            DTO.Enums.DispensingMetric metricValue;
            var dispensing = GetAllCriteriaTerms(criteria, ModelTermsFactory.DispensingMetricID).FirstOrDefault();

            if (dispensing.GetEnumValue("Metric", out metricValue))
            {
                model.MetricType = metricValue.ToString("D");
            }

            DTO.Enums.OutputCriteria outputValue;
            var cri = GetAllCriteriaTerms(criteria, ModelTermsFactory.CriteriaID).FirstOrDefault();

            if (cri.GetEnumValue("Criteria", out outputValue))
            {
                model.OutputCriteria = outputValue.ToString("D");
            }

            var ageStratification = request.Select.Fields.Where(f => f.Type == ModelTermsFactory.AgeRangeID).FirstOrDefault();

            if (ageStratification != null)
            {
                QueryAdapter.SetAgeStratification(model, ageStratification);
            }

            var sexStratification = GetAllCriteriaTerms(criteria, ModelTermsFactory.SexID).FirstOrDefault();

            if (sexStratification != null)
            {
                QueryAdapter.SetSexStratification(model, sexStratification);
            }

            model.Setting      = null;
            model.Codes        = null; //not applicable to this query
            model.CodeNames    = null; //not applicable to this query
            model.Coverage     = null; //not applicable to this query
            model.StartQuarter = null; //not applicable to this query
            model.EndQuarter   = null; //not applicable to this query
            model.SubtypeId    = 0;    //value never gets set in ui of v5 summary query composer

            return(model);
        }
        protected override SummaryRequestModel ConvertToModel(DTO.QueryComposer.QueryComposerRequestDTO request)
        {
            var criteria = request.Where.Criteria.First();

            SummaryRequestModel model = new SummaryRequestModel();
            var observationPeriodTerm = GetAllCriteriaTerms(criteria, ModelTermsFactory.YearID).FirstOrDefault();

            if (observationPeriodTerm != null)
            {
                model.StartPeriod = observationPeriodTerm.GetStringValue("StartYear");
                model.EndPeriod   = observationPeriodTerm.GetStringValue("EndYear");
                model.Period      = string.Join(",", QueryAdapter.ExpandYears(model).Select(y => "'" + y + "'"));//used in query
            }

            DTO.Enums.Coverages coverage;
            var cov = GetAllCriteriaTerms(criteria, ModelTermsFactory.CoverageID).FirstOrDefault();

            if (cov.GetEnumValue("Coverage", out coverage))
            {
                model.Coverage = coverage;
            }

            //These values are pulled from the stratification section of the request json
            var ageStratification = GetAgeField(request.Select.Fields.Where(f => f.Type == ModelTermsFactory.AgeRangeID));

            if (ageStratification != null)
            {
                QueryAdapter.SetAgeStratification(model, ageStratification);
            }

            var sexStratification = GetAllCriteriaTerms(criteria, ModelTermsFactory.SexID).FirstOrDefault();

            if (sexStratification != null)
            {
                QueryAdapter.SetSexStratification(model, sexStratification);
            }

            model.Codes          = null; //not applicable to this query
            model.CodeNames      = null; //not applicable to this query
            model.Setting        = null; //not applicable to this query
            model.MetricType     = "0";  //not applicable to this query
            model.OutputCriteria = "0";  //not applicable to this query
            model.StartQuarter   = null; //not applicable to this query
            model.EndQuarter     = null; //not applicable to this query
            model.SubtypeId      = 0;    //value never gets set in ui of v5 summary query composer

            return(model);
        }
        protected override SummaryRequestModel ConvertToModel(DTO.QueryComposer.QueryComposerRequestDTO request)
        {
            var criteria = request.Where.Criteria.First();

            SummaryRequestModel model = new SummaryRequestModel();

            //var observationPeriodTerm = criteria.Terms.FirstOrDefault(t => t.Type == ModelTermsFactory.QuarterYearID);
            var observationPeriodTerm = GetAllCriteriaTerms(criteria, ModelTermsFactory.QuarterYearID).FirstOrDefault();

            if (observationPeriodTerm != null)
            {
                model.StartPeriod = observationPeriodTerm.GetStringValue("StartYear");
                model.EndPeriod   = observationPeriodTerm.GetStringValue("EndYear");
                model.Period      = string.Join(",", QueryAdapter.ExpandYears(model).Select(y => "'" + y + "'"));//used in query
            }

            IEnumerable <DTO.QueryComposer.QueryComposerTermDTO> codeTerms = criteria.Criteria.SelectMany(c => c.Terms.Where(t => t.Type == ModelTermsFactory.DrugClassID || t.Type == ModelTermsFactory.DrugNameID)).Concat(criteria.Terms.Where(t => t.Type == ModelTermsFactory.DrugClassID || t.Type == ModelTermsFactory.DrugNameID)).ToArray();

            if (codeTerms.Any(t => t.Type == ModelTermsFactory.DrugNameID))
            {
                _queryType = IncidencePharmaDispensingQueryType.DrugName;
            }
            else if (codeTerms.Any(t => t.Type == ModelTermsFactory.DrugClassID))
            {
                _queryType = IncidencePharmaDispensingQueryType.DrugClass;
            }
            else
            {
                throw new InvalidOperationException("Either a Drug Name term or a Drug Class term is required for the query.");
            }

            IEnumerable <string> codeTermValues = from t in codeTerms
                                                  from v in t.GetCodeStringCollection()
                                                  where !string.IsNullOrWhiteSpace(v)
                                                  select v.Trim();

            model.Codes     = string.Join(",", codeTermValues.Distinct().Select(c => System.Net.WebUtility.HtmlEncode(c).Replace(",", "&#44;")));
            model.CodeNames = null;//not applicable to this query

            //These values are pulled from the stratification section of the request json
            var ageStratification = request.Select.Fields.Where(f => f.Type == ModelTermsFactory.AgeRangeID).FirstOrDefault();

            if (ageStratification != null)
            {
                QueryAdapter.SetAgeStratification(model, ageStratification);
            }

            var sexStratification = GetAllCriteriaTerms(criteria, ModelTermsFactory.SexID).FirstOrDefault();

            if (sexStratification != null)
            {
                QueryAdapter.SetSexStratification(model, sexStratification);
            }
            model.Setting        = null; //not applicable to this query
            model.Coverage       = null; //not applicable to this query
            model.MetricType     = "0";  //not applicable to this query
            model.OutputCriteria = "0";  //not applicable to this query
            model.StartQuarter   = null; //not applicable to this query
            model.EndQuarter     = null; //not applicable to this query
            model.SubtypeId      = 0;    //value never gets set in ui of v5 summary query composer

            return(model);
        }
Exemple #6
0
        protected override SummaryRequestModel ConvertToModel(DTO.QueryComposer.QueryComposerQueryDTO query)
        {
            var criteria = query.Where.Criteria.First();

            SummaryRequestModel model = new SummaryRequestModel();
            var observationPeriodTerm = GetAllCriteriaTerms(criteria, ModelTermsFactory.QuarterYearID).FirstOrDefault();

            if (observationPeriodTerm != null)
            {
                model.StartPeriod = observationPeriodTerm.GetStringValue("StartYear");
                model.EndPeriod   = observationPeriodTerm.GetStringValue("EndYear");

                if (string.Equals(observationPeriodTerm.GetStringValue("ByYearsOrQuarters"), "ByQuarters", StringComparison.OrdinalIgnoreCase))
                {
                    model.StartQuarter = observationPeriodTerm.GetStringValue("StartQuarter");
                    model.EndQuarter   = observationPeriodTerm.GetStringValue("EndQuarter");
                    model.Period       = string.Join(",", QueryAdapter.ExpandYearsWithQuarters(Convert.ToInt32(model.StartPeriod), Convert.ToInt32(model.StartQuarter[1].ToString()), Convert.ToInt32(model.EndPeriod), Convert.ToInt32(model.EndQuarter[1].ToString())).Select(y => "'" + y + "'"));//used in query
                }
                else
                {
                    model.StartQuarter = null;
                    model.EndQuarter   = null;
                    model.Period       = string.Join(",", QueryAdapter.ExpandYears(model).Select(y => "'" + y + "'"));//used in query
                }
            }

            var codeTerms = criteria.FlattenCriteriaToTerms().Where(t => t.Type == ModelTermsFactory.DrugNameID || t.Type == ModelTermsFactory.DrugClassID);

            if (codeTerms.Any(t => t.Type == ModelTermsFactory.DrugNameID))
            {
                _queryType = IncidencePharmaDispensingQueryType.DrugName;
            }
            else if (codeTerms.Any(t => t.Type == ModelTermsFactory.DrugClassID))
            {
                _queryType = IncidencePharmaDispensingQueryType.DrugClass;
            }
            else
            {
                throw new InvalidOperationException("Either a Drug Name term or a Drug Class term is required for the query.");
            }

            var codeTermValues = (from t in codeTerms
                                  let v = t.GetCodeSelectorValues()
                                          from c in v
                                          where c != null && !string.IsNullOrWhiteSpace(c.Code)
                                          select c).GroupBy(k => k.Code.Trim()).Select(k => new { Code = k.Key, Name = k.Select(c => c.Name).FirstOrDefault() ?? k.Key }).ToArray();

            model.Codes     = string.Join(",", codeTermValues.Select(c => System.Net.WebUtility.HtmlEncode(c.Code).Replace(",", "&#44;")));
            model.CodeNames = codeTermValues.Select(c => c.Name).ToArray();

            //These values are pulled from the stratification section of the request json
            var ageStratification = GetAgeField(query.Select.Fields.Where(f => f.Type == ModelTermsFactory.AgeRangeID));

            if (ageStratification != null)
            {
                QueryAdapter.SetAgeStratification(model, ageStratification);
            }
            var sexStratification = GetAllCriteriaTerms(criteria, ModelTermsFactory.SexID).FirstOrDefault();

            if (sexStratification != null)
            {
                QueryAdapter.SetSexStratification(model, sexStratification);
            }

            model.Setting        = null; //not applicable to this query
            model.Coverage       = null; //not applicable to this query
            model.MetricType     = "0";  //not applicable to this query
            model.OutputCriteria = "0";  //not applicable to this query
            model.SubtypeId      = 0;    //value never gets set in ui of v5 summary query composer

            return(model);
        }