Exemplo n.º 1
0
        /// <summary>
        /// Gets the cost and quantity values.
        /// </summary>
        /// <param name="dataset">The dataset.</param>
        /// <param name="websiteId">The website identifier.</param>
        /// <returns></returns>
        private List <Tuple <int, int, double> > GetCostAndQuantityValues(WebsiteDataset dataset, int websiteId)
        {
            var query = string.Format(@"SELECT h.Id as HospitalId, COUNT(h.id) AS TotalCount, AVG(TotalCharge * CAST(ISNULL(wh.ccr, dbo.fnGetCostToChargeRatio('{2}',h.CmsProviderID)) as float)) AS AvgCost
                                        FROM Websites_WebsiteHospitals wh
                                            INNER JOIN Hospitals h on wh.Hospital_Id = h.Id
                                            INNER JOIN Targets_InpatientTargets ip on h.LocalHospitalId = ip.LocalHospitalID
                                            INNER JOIN [Base_ICD9toPRCCSCrosswalks] bicd on bicd.ICD9ID = ip.PrincipalProcedure
                                            INNER JOIN Base_CostToCharges ccr on ccr.ProviderID = h.CmsProviderID 
                                        WHERE PRCCSID = 153 and ip.PrincipalDiagnosis NOT IN ({0}) 
                                        AND Dataset_Id = {1} and wh.Website_Id = {3}
                                        AND 1 = (CASE  WHEN wh.CCR IS NULL AND ccr.Ratio IS NULL THEN 0 ELSE 1 END)
                                        GROUP BY h.id", string.Join(",", _excludedICDCodes), dataset.Dataset.Id, dataset.Dataset.ReportingYear, websiteId);

            List <Tuple <int, int, double> > result;

            using (var session = DataServiceProvider.SessionFactory.OpenSession())
            {
                result = session.CreateSQLQuery(query)
                         .AddScalar("HospitalId", NHibernateUtil.Int32)
                         .AddScalar("TotalCount", NHibernateUtil.Int32)
                         .AddScalar("AvgCost", NHibernateUtil.Double)
                         .List <object[]>().Select(r => Tuple.Create((int)r[0], (int)r[1], (double)r[2]))
                         .ToList();
            }

            return(result);
        }
        private void ProcessWebsitesAndDatasets()
        {
            if (CurrentWebsite == null || InstalledDatasets == null)
            {
                return;
            }

            CurrentWebsite.Datasets.Clear();

            // put the selected datasets into the website to be saved
            foreach (var ids in InstalledDatasets)
            {
                foreach (var wds in ids.WebsiteDatasets)
                {
                    //if ((wds.DataSetFile.Dataset != null && CurrentWebsite.Datasets.All(d => d.Dataset.Id != wds.DataSetFile.Dataset.Id)
                    // this is the simple object I think we SHOULD save for each website dataset...
                    //var dataSetFile = new DataSetFile(wds.DataSetFile.DatasetId, wds.DataSetFile.Name, wds.DataSetFile.Year, wds.DataSetFile.Quarter);

                    //if(CurrentWebsite.Datasets.All(ds => ds.Dataset.Id == ))
                    // BUT this is what the current infrastructure requires...
                    //var import = new DatasetImport {DatasetId = wds.DataSetFile.DatasetId};
                    //import.DatasetType = new TARGET() ?????????????????
                    //import.ImportDate = IMPORT DATE ???????????????
                    var websiteDataset = new WebsiteDataset();

                    if (wds.DataSetFile.Dataset != null)
                    {
                        websiteDataset.Dataset = wds.DataSetFile.Dataset;
                    }
                    else if (wds.DataSetFile.DatasetId > 0)
                    {
                        WebsiteDataService.GetEntityById <Dataset>(wds.DataSetFile.DatasetId, (record, exception) =>
                        {
                            if (exception == null && record != null)
                            {
                                websiteDataset.Dataset = record;
                            }
                        });
                    }

                    if (websiteDataset.Dataset != null &&
                        CurrentWebsite.Datasets.All(d => d.Dataset.Id != websiteDataset.Dataset.Id))
                    {
                        CurrentWebsite.Datasets.Add(websiteDataset);
                    }
                }
            }

            RaisePropertyChanged(() => CurrentWebsite.Datasets);
            RaisePropertyChanged(() => ManageViewModel.WebsiteViewModel.Website.Datasets);
        }