示例#1
0
        private DataSet GetResponseDataSet(IDnsResponseContext context, string reqDoc, IDnsResponseAggregationMode aggregationMode)
        {
            var termData = RequestCriteriaHelper.ToServerModel(reqDoc).Criterias.First().Terms;
            var mdData   = termData.Where(t => t.TermType == RequestCriteria.Models.TermTypes.MetaDataTableTerm).FirstOrDefault() as MetaDataTableData;

            DataSet ds = new DataSet();

            foreach (var r in context.DataMartResponses)
            {
                foreach (var doc in r.Documents)
                {
                    try
                    {
                        ds.ReadXml(doc.GetStream(_dataContext.Value));
                    }
                    catch (System.Xml.XmlException)
                    {
                        string content = FixDocumentContent(doc.ReadStreamAsString(_dataContext.Value));
                        using (var ms = new MemoryStream(System.Text.Encoding.Default.GetBytes(content)))
                        {
                            ds.ReadXml(ms);
                        }
                    }


                    if (doc.Name == "DataCheckerResponse.xml")
                    {
                        if (context.Request.RequestType.ID == Guid.Parse(DataCheckerRequestType.DATA_CHECKER_METADATA_COMPLETENESS))
                        {
                            foreach (string unselectedMetadataTable in GetUnselectedMetaDataTables(mdData.Tables))
                            {
                                if (ds.Tables[ds.Tables.Count - 1].Columns.Contains(unselectedMetadataTable))
                                {
                                    ds.Tables[ds.Tables.Count - 1].Columns.Remove(unselectedMetadataTable);
                                }
                            }
                        }


                        foreach (DataRow row in ds.Tables[ds.Tables.Count - 1].Rows)
                        {
                            if (context.Request.RequestType.ID == Guid.Parse(DataCheckerRequestType.DATA_CHECKER_DISPENSING_RXAMT))
                            {
                                row["RxAmt"] = FormatRxAmt((string)row["RxAmt"]);
                            }
                            else if (context.Request.RequestType.ID == Guid.Parse(DataCheckerRequestType.DATA_CHECKER_DISPENSING_RXSUP))
                            {
                                row["RxSup"] = FormatRxSup((string)row["RxSup"]);
                            }
                        }
                    }
                }
            }
            return(ds);
        }
示例#2
0
        private bool Validate(DataCheckerModel m, out IList <string> errorMessages)
        {
            errorMessages = new List <string>();

            var criteria  = RequestCriteriaHelper.ToServerModel(m.CriteriaGroupsJSON);
            var datamarts = (from c in criteria.Criterias
                             from t in c.Terms
                             where t.TermType == RequestCriteria.Models.TermTypes.DataPartnerTerm
                             select((DataPartnersData)t).DataPartners.Count()).Sum();

            if (datamarts < 1)
            {
                errorMessages.Add("Please select at least one Data Partner in the Data Partner Criteria selector.");
            }


            return(errorMessages.Count > 0 ? false : true);
        }
示例#3
0
        public Func <HtmlHelper, IHtmlString> DisplayResponse(IDnsResponseContext context, IDnsResponseAggregationMode aggregationMode)
        {
            try
            {
                var doc = context.Request.Documents.Where(d => d.Name == REQUEST_ARGS_FILENAME).FirstOrDefault();
                using (var db = new DataContext())
                {
                    string reqDoc    = FixDocumentContent(System.Text.UTF8Encoding.UTF8.GetString(doc.GetData(db)));
                    var    termData  = RequestCriteriaHelper.ToServerModel(reqDoc).Criterias.First().Terms;
                    var    rxAmtData = termData.Where(t => t.TermType == RequestCriteria.Models.TermTypes.RxAmtTerm).FirstOrDefault() as RxAmountData;
                    var    rxSupData = termData.Where(t => t.TermType == RequestCriteria.Models.TermTypes.RxSupTerm).FirstOrDefault() as RxSupData;
                    var    codeData  = termData.Where(t => t.TermType == RequestCriteria.Models.TermTypes.CodesTerm).FirstOrDefault() as CodesData;
                    var    mdData    = termData.Where(t => t.TermType == RequestCriteria.Models.TermTypes.MetaDataTableTerm).FirstOrDefault() as MetaDataTableData;

                    var model = new ResponseModel
                    {
                        RequestID     = context.Request.RequestID,
                        ResponseToken = context.Token,

                        RxAmounts           = rxAmtData != null ? rxAmtData.RxAmounts : null,
                        RxSups              = rxSupData != null ? rxSupData.RxSups : null,
                        CodeType            = codeData != null ? codeData.CodeType : null,
                        MetadataTables      = mdData != null ? mdData.Tables : null,
                        RawData             = null,//only load the raw response data for the original request types until they have been converted to use ajax to load shaped data
                        IsExternalView      = context.IsExternalView,
                        ResponseDocumentIDs = context.DataMartResponses.SelectMany(r => r.Documents).Where(dc => dc.Name != "ViewableDocumentStyle.xml").Select(d => d.ID).ToArray()
                    };

                    if (context.Request.RequestType.ID == new Guid(DataCheckerRequestType.DATA_CHECKER_DIAGNOSIS) ||
                        context.Request.RequestType.ID == new Guid(DataCheckerRequestType.DATA_CHECKER_ETHNICITY) ||
                        context.Request.RequestType.ID == new Guid(DataCheckerRequestType.DATA_CHECKER_NDC) ||
                        context.Request.RequestType.ID == new Guid(DataCheckerRequestType.DATA_CHECKER_PROCEDURE) ||
                        context.Request.RequestType.ID == new Guid(DataCheckerRequestType.DATA_CHECKER_RACE))
                    {
                        //only load the raw response data for the original request types until they have been converted to use ajax to load shaped data
                        model.RawData = GetResponseDataSet(context, reqDoc, aggregationMode);
                    }

                    return(html =>
                    {
                        if (context.Request.RequestType.ID == new Guid(DataCheckerRequestType.DATA_CHECKER_DIAGNOSIS))
                        {
                            return html.Partial <DiagnosesResponse>().WithModel(model);
                        }

                        if (context.Request.RequestType.ID == new Guid(DataCheckerRequestType.DATA_CHECKER_ETHNICITY))
                        {
                            return html.Partial <EthnicityResponse>().WithModel(model);
                        }

                        if (context.Request.RequestType.ID == new Guid(DataCheckerRequestType.DATA_CHECKER_NDC))
                        {
                            return html.Partial <NDCResponse>().WithModel(model);
                        }

                        if (context.Request.RequestType.ID == new Guid(DataCheckerRequestType.DATA_CHECKER_PROCEDURE))
                        {
                            return html.Partial <ProceduresResponse>().WithModel(model);
                        }

                        if (context.Request.RequestType.ID == new Guid(DataCheckerRequestType.DATA_CHECKER_RACE))
                        {
                            return html.Partial <RaceResponse>().WithModel(model);
                        }

                        if (context.Request.RequestType.ID == new Guid(DataCheckerRequestType.DATA_CHECKER_DIAGNOSIS_PDX))
                        {
                            return html.Partial <DiagnosisPDXResponse>().WithModel(model);
                        }

                        if (context.Request.RequestType.ID == new Guid(DataCheckerRequestType.DATA_CHECKER_DISPENSING_RXAMT))
                        {
                            return html.Partial <DispensingRxAmtResponse>().WithModel(model);
                        }

                        if (context.Request.RequestType.ID == new Guid(DataCheckerRequestType.DATA_CHECKER_DISPENSING_RXSUP))
                        {
                            return html.Partial <DispensingRxSup>().WithModel(model);
                        }

                        if (context.Request.RequestType.ID == new Guid(DataCheckerRequestType.DATA_CHECKER_METADATA_COMPLETENESS))
                        {
                            return html.Partial <MetadataDataCompletenessResponse>().WithModel(model);
                        }

                        throw new Exception("Unknown request type, could not determine response view.");
                    });
                }
            }
            catch (Exception ex)
            {
                return(html => html.Partial <Views.Error>().WithModel(new InvalidDataSetException(ex)));
            }
        }
示例#4
0
        private string GetDisplayableRequest(DataCheckerModel model)

        {
            var terms = RequestCriteriaHelper.ToServerModel(model.CriteriaGroupsJSON).Criterias.First().Terms;
            var sb    = new StringBuilder("<html><body style='font-family: Sans-serif; font-size:9pt;'>");

            foreach (var term in terms)
            {
                switch (term.TermType)
                {
                case RequestCriteria.Models.TermTypes.CodesTerm:
                    string CodeTypeDescription = string.Empty;
                    switch ((term as CodesData).CodesTermType)
                    {
                    case CodesTermTypes.Diagnosis_ICD9Term:
                        switch ((term as CodesData).CodeType)
                        {
                        case "09": CodeTypeDescription = "ICD-9-CM"; break;

                        case "10": CodeTypeDescription = "ICD-10-CM"; break;

                        case "11": CodeTypeDescription = "ICD-11-CM"; break;

                        case "SM": CodeTypeDescription = "SNOMED CT"; break;

                        case "OT": CodeTypeDescription = "Other"; break;
                        }
                        break;

                    case CodesTermTypes.Procedure_ICD9Term:
                        switch ((term as CodesData).CodeType)
                        {
                        case "09": CodeTypeDescription = "ICD-9-CM"; break;

                        case "10": CodeTypeDescription = "ICD-10-CM"; break;

                        case "11": CodeTypeDescription = "ICD-11-CM"; break;

                        case "C2": CodeTypeDescription = "CPT Category II"; break;

                        case "C3": CodeTypeDescription = "CPT Category III"; break;

                        case "C4": CodeTypeDescription = "CPT-4 (i.e., HCPCS Level I)"; break;

                        case "HC": CodeTypeDescription = "HCPCS (i.e., HCPCS Level II)"; break;

                        case "H3": CodeTypeDescription = "HCPCS Level III"; break;

                        case "LC": CodeTypeDescription = "LOINC"; break;

                        case "LO": CodeTypeDescription = "Local Homegrown"; break;

                        case "ND": CodeTypeDescription = "NDC"; break;

                        case "RE": CodeTypeDescription = "Revenue"; break;

                        case "OT": CodeTypeDescription = "Other"; break;
                        }
                        break;
                    }
                    if (CodeTypeDescription != string.Empty)
                    {
                        sb.AppendFormat("<b>Code Type:</b> {0}<br />", CodeTypeDescription);
                    }

                    sb.AppendFormat("<b>Codes:</b> <i>{0}</i> {1}<br />",
                                    (term as CodesData).SearchMethodType == SearchMethodTypes.ExactMatch ? "Exact Match" : "Starts With",
                                    (term as CodesData).Codes);
                    break;

                case RequestCriteria.Models.TermTypes.DataPartnerTerm:
                    var partners      = (term as DataPartnersData).DataPartners;
                    var organizations = DataContext.Organizations.Where(o => partners.Contains(o.Acronym)).Select(o => new { o.Name, o.Acronym }).ToArray();
                    sb.AppendFormat("<b>Data Partners:</b> {0}<br />", String.Join(", ", organizations.Select(o => string.Format("{0} ({1})", o.Name, o.Acronym))));
                    break;

                case RequestCriteria.Models.TermTypes.EthnicityTerm:
                    var ethnicities = new List <string>();

                    foreach (var ethnicity in (term as EthnicityData).Ethnicities)
                    {
                        switch (ethnicity)
                        {
                        case EthnicityTypes.Unknown:
                            ethnicities.Add("Unknown");
                            break;

                        case EthnicityTypes.Hispanic:
                            ethnicities.Add("Hispanic");
                            break;

                        case EthnicityTypes.NotHispanic:
                            ethnicities.Add("Not Hispanic");
                            break;

                        case EthnicityTypes.Missing:
                            ethnicities.Add("Missing");
                            break;
                        }
                    }

                    sb.AppendFormat("<b>Ethnicities:</b> {0}<br />", String.Join(", ", ethnicities));
                    break;

                case RequestCriteria.Models.TermTypes.MetricTerm:
                    var metrics = new List <string>();

                    foreach (var metric in (term as MetricsData).Metrics)
                    {
                        switch (metric)
                        {
                        case MetricsTypes.DataPartnerCount:
                            metrics.Add("Count by Data Partner"); break;

                        case MetricsTypes.DataPartnerPercent:
                            metrics.Add("Percent within Data Partner"); break;

                        case MetricsTypes.DataPartnerPercentContribution:
                            metrics.Add("Percent of Data Partner Contribution"); break;

                        case MetricsTypes.DataPartnerPresence:
                            metrics.Add("Presence by Data Partner"); break;

                        case MetricsTypes.Overall:
                            metrics.Add("Overall"); break;

                        case MetricsTypes.OverallCount:
                            metrics.Add("Overall Count"); break;

                        case MetricsTypes.OverallPresence:
                            metrics.Add("Overall Presence"); break;
                        }
                    }

                    sb.AppendFormat("<b>Metrics:</b> {0}<br />", String.Join(", ", metrics));
                    break;

                case RequestCriteria.Models.TermTypes.RaceTerm:
                    var races = new List <string>();

                    foreach (var race in (term as RaceData).Races)
                    {
                        switch (race)
                        {
                        case RaceTypes.AmericanIndianOrAlaskaNative:
                            races.Add("American Indian/Alaska Native");
                            break;

                        case RaceTypes.Asian:
                            races.Add("Asian");
                            break;

                        case RaceTypes.BlackOrAfricanAmerican:
                            races.Add("Black/African American");
                            break;

                        case RaceTypes.NativeHawaiianOrOtherPacificIslander:
                            races.Add("Native Hawaiian/Pacific Islander");
                            break;

                        case RaceTypes.Unknown:
                            races.Add("Unknown");
                            break;

                        case RaceTypes.White:
                            races.Add("White");
                            break;

                        case RaceTypes.Missing:
                            races.Add("Missing");
                            break;
                        }
                    }

                    sb.AppendFormat("<b>Races:</b> {0}<br />", String.Join(", ", races));
                    break;

                case RequestCriteria.Models.TermTypes.PDXTerm:
                    var pdxes = new List <string>();
                    foreach (var pdx in (term as PDXData).PDXes)
                    {
                        switch (pdx)
                        {
                        case PDXTypes.Other:
                            pdxes.Add("Other PDX");
                            break;

                        default:
                            pdxes.Add(pdx.ToString());
                            break;
                        }
                    }
                    sb.AppendFormat("<b>PDX Codes:</b> {0}<br />", String.Join(", ", pdxes));
                    break;

                case RequestCriteria.Models.TermTypes.MetaDataTableTerm:
                    var tables = new List <string>();
                    foreach (var table in (term as MetaDataTableData).Tables)
                    {
                        tables.Add(table.ToString());
                    }
                    sb.AppendFormat("<b>Completeness Tables:</b> {0}<br />", String.Join(", ", tables));
                    break;

                case RequestCriteria.Models.TermTypes.EncounterTypeTerm:
                    var encounters = new List <string>();
                    foreach (var encounter in (term as EncounterData).Encounters)
                    {
                        switch (encounter)
                        {
                        case EncounterTypes.All:
                            encounters.Add("All Encounters");
                            break;

                        case EncounterTypes.AmbulatoryVisit:
                            encounters.Add("Ambulatory Visit (AV)");
                            break;

                        case EncounterTypes.EmergencyDepartment:
                            encounters.Add("Emergency Department (ED)");
                            break;

                        case EncounterTypes.InpatientHospitalStay:
                            encounters.Add("Inpatient Hospital Stay (IP)");
                            break;

                        case EncounterTypes.NonAcuteInstitutionalStay:
                            encounters.Add("Non-Acute Institutional Stay (IS)");
                            break;

                        case EncounterTypes.OtherAmbulatoryVisit:
                            encounters.Add("Other Ambulatory Visit (OA)");
                            break;

                        default:
                            encounters.Add("Missing");
                            break;
                        }
                    }
                    sb.AppendFormat("<b>Encounters:</b> {0}<br />", String.Join(", ", encounters));
                    break;

                case RequestCriteria.Models.TermTypes.RxAmtTerm:
                    var amtTerms = new List <string>();
                    foreach (var amt in (term as RxAmountData).RxAmounts)
                    {
                        switch (amt)
                        {
                        case RxAmountTypes.LessThanZero:
                            amtTerms.Add("< 0");
                            break;

                        case RxAmountTypes.Ninety:
                            amtTerms.Add("91-120");
                            break;

                        case RxAmountTypes.OneHundredTwenty:
                            amtTerms.Add("121-180");
                            break;

                        case RxAmountTypes.OneHundredEighty:
                            amtTerms.Add(">180");
                            break;

                        case RxAmountTypes.Other:
                            amtTerms.Add("Other RxAmt");
                            break;

                        case RxAmountTypes.Sixty:
                            amtTerms.Add("61-90");
                            break;

                        case RxAmountTypes.Thirty:
                            amtTerms.Add("31-60");
                            break;

                        case RxAmountTypes.TwoThroughThirty:
                            amtTerms.Add("2-30");
                            break;

                        case RxAmountTypes.Zero:
                            amtTerms.Add("0-1");
                            break;

                        case RxAmountTypes.Missing:
                            amtTerms.Add("Missing");
                            break;

                        default:
                            amtTerms.Add("Missing");
                            break;
                        }
                    }
                    sb.AppendFormat("<b>RxAmt Terms:</b> {0}<br />", String.Join(", ", amtTerms));
                    break;

                case RequestCriteria.Models.TermTypes.RxSupTerm:
                    var supTerms = new List <string>();
                    foreach (var sup in (term as RxSupData).RxSups)
                    {
                        switch (sup)
                        {
                        case RxSupTypes.LessThanZero:
                            supTerms.Add("<0");
                            break;

                        case RxSupTypes.Ninety:
                            supTerms.Add(">90");
                            break;

                        case RxSupTypes.TwoThroughThirty:
                            supTerms.Add("2-30");
                            break;

                        case RxSupTypes.Other:
                            supTerms.Add("Other RxSup");
                            break;

                        case RxSupTypes.Sixty:
                            supTerms.Add("61-90");
                            break;

                        case RxSupTypes.Thirty:
                            supTerms.Add("31-60");
                            break;

                        case RxSupTypes.Zero:
                            supTerms.Add("0-1");
                            break;

                        case RxSupTypes.Missing:
                            supTerms.Add("Missing");
                            break;

                        default:
                            supTerms.Add("Missing");
                            break;
                        }
                    }
                    sb.AppendFormat("<b>RxSup Terms:</b> {0}<br />", String.Join(", ", supTerms));
                    break;
                }
            }

            sb.Append("</body></html>");

            return(sb.ToString());
        }
示例#5
0
        DataCheckerModel GetModel(IDnsRequestContext request)
        {
            var m = new DataCheckerModel
            {
                RequestType = DataCheckerRequestType.All.FirstOrDefault(rt => rt.ID == request.RequestType.ID),
                RequestId   = request.RequestID
            };

            if ((request.Documents != null) && (request.Documents.Where(d => d.Name == REQUEST_ARGS_FILENAME).Count() > 0))
            {
                var doc = request.Documents.First(d => d.Name == REQUEST_ARGS_FILENAME);
                m.CriteriaGroupsJSON = FixDocumentContent(System.Text.UTF8Encoding.UTF8.GetString(doc.GetData(_dataContext.Value)));
            }
            else
            {
                // set up an initial model based on the request type
                var terms = new List <ITermData> {
                    new DataPartnersData()
                    {
                        TermType     = RequestCriteria.Models.TermTypes.DataPartnerTerm,
                        DataPartners = new string[] {}
                    }
                };

                var criteria = new CriteriaData()
                {
                    IsExclusion = false,
                    IsPrimary   = true,
                    Name        = "Primary",
                    Terms       = terms
                };

                var myRequest = new RequestCriteriaData()
                {
                    RequestType = m.RequestType.ID,
                    Criterias   = new List <CriteriaData> {
                        criteria
                    }
                };

                if (m.RequestType.ID == Guid.Parse(DataCheckerRequestType.DATA_CHECKER_DIAGNOSIS))
                {
                    terms.Add(new CodesData()
                    {
                        TermType      = RequestCriteria.Models.TermTypes.CodesTerm,
                        CodesTermType = CodesTermTypes.Diagnosis_ICD9Term,
                        Codes         = string.Empty
                    });
                }
                else if (m.RequestType.ID == Guid.Parse(DataCheckerRequestType.DATA_CHECKER_ETHNICITY))
                {
                    terms.Add(new EthnicityData()
                    {
                        TermType    = RequestCriteria.Models.TermTypes.EthnicityTerm,
                        Ethnicities = new EthnicityTypes[] { }
                    });
                }
                else if (m.RequestType.ID == Guid.Parse(DataCheckerRequestType.DATA_CHECKER_NDC))
                {
                    terms.Add(new CodesData()
                    {
                        TermType      = RequestCriteria.Models.TermTypes.CodesTerm,
                        CodesTermType = CodesTermTypes.NDCTerm,
                        Codes         = string.Empty
                    });
                }
                else if (m.RequestType.ID == Guid.Parse(DataCheckerRequestType.DATA_CHECKER_PROCEDURE))
                {
                    terms.Add(new CodesData()
                    {
                        TermType      = RequestCriteria.Models.TermTypes.CodesTerm,
                        CodesTermType = CodesTermTypes.Procedure_ICD9Term,
                        Codes         = string.Empty
                    });
                }
                else if (m.RequestType.ID == Guid.Parse(DataCheckerRequestType.DATA_CHECKER_RACE))
                {
                    terms.Add(new RaceData()
                    {
                        TermType = RequestCriteria.Models.TermTypes.RaceTerm,
                        Races    = new RaceTypes[] { }
                    });
                }
                else if (m.RequestType.ID == new Guid(DataCheckerRequestType.DATA_CHECKER_DIAGNOSIS_PDX))
                {
                    terms.Add(new PDXData
                    {
                        TermType = RequestCriteria.Models.TermTypes.PDXTerm,
                        PDXes    = new PDXTypes[] { }
                    });

                    terms.Add(new EncounterData
                    {
                        TermType   = RequestCriteria.Models.TermTypes.EncounterTypeTerm,
                        Encounters = new EncounterTypes[] { }
                    });
                }
                else if (m.RequestType.ID == new Guid(DataCheckerRequestType.DATA_CHECKER_METADATA_COMPLETENESS))
                {
                    terms.Add(new MetaDataTableData {
                        TermType = RequestCriteria.Models.TermTypes.MetaDataTableTerm,
                        Tables   = new MetaDataTableTypes[] {}
                    });
                }
                else if (m.RequestType.ID == new Guid(DataCheckerRequestType.DATA_CHECKER_DISPENSING_RXAMT))
                {
                    terms.Add(new RxAmountData
                    {
                        TermType  = RequestCriteria.Models.TermTypes.RxAmtTerm,
                        RxAmounts = new RxAmountTypes[] { }
                    });
                }
                else if (m.RequestType.ID == new Guid(DataCheckerRequestType.DATA_CHECKER_DISPENSING_RXSUP))
                {
                    terms.Add(new RxSupData
                    {
                        TermType = RequestCriteria.Models.TermTypes.RxSupTerm,
                        RxSups   = new RxSupTypes[] { }
                    });
                }

                m.CriteriaGroupsJSON = RequestCriteriaHelper.ToClientModel(myRequest);
            }

            return(m);
        }