Files
linqpad/Heatmap Facility Deaths.linq

59 lines
2.5 KiB
C#

<Query Kind="Statements">
<Connection>
<ID>ce6f5caf-a955-42be-a634-5eb79966aca4</ID>
<Persist>true</Persist>
<Server>D0017-SQL-01.sdt.local</Server>
<Database>jazz tst Aurora 20160126.1</Database>
<ShowServer>true</ShowServer>
</Connection>
<Reference>&lt;ProgramFilesX64&gt;\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics\Newtonsoft.Json.dll</Reference>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>Newtonsoft.Json.Converters</Namespace>
<Namespace>Newtonsoft.Json.Linq</Namespace>
<Namespace>Newtonsoft.Json.Schema</Namespace>
<Namespace>Newtonsoft.Json.Serialization</Namespace>
</Query>
var dataRun = from i in ((from fpes in FactPatientEncounterSummaries
where fpes.DischargeDateTime > fpes.AdmitDateTime
&& fpes.DateofDeath >= fpes.AdmitDateTime
&& fpes.DateofDeath >= fpes.DischargeDateTime.AddDays(-30) && fpes.DateofDeath <= fpes.DischargeDateTime.AddDays(30)
&& fpes.AdmitDateTime >= new DateTime(2015,1,1)
select new { fpes.FiscalYearID, fpes.EntityID, fpes.FacilityID, fpes.AttendPhysicianID, fpes.PrimaryPhysicianID, fpes.MSDRGCaseTypeFamilyID
, fpes.AdmitDateTime, fpes.DischargeDateTime, fpes.DateofDeath, fpes.PatientID, fpes.LengthOfStay })
.Take(10000))
group i by new { i.FiscalYearID, i.EntityID, i.FacilityID
, i.AttendPhysicianID
, i.PrimaryPhysicianID
, AdmitDateTimeYr = i.AdmitDateTime.Year
, AdmitDateTimeMo = i.AdmitDateTime.Month
, CaseTypeFamilyID= i.MSDRGCaseTypeFamilyID
, DischargeDateTimeYr = i.DischargeDateTime.Year
, DischargeDateTimeMo = i.DischargeDateTime.Month
, DateofDeathYr = i.DateofDeath.Year
, DateofDeathMo = i.DateofDeath.Month
} into g
select new { g.Key.FiscalYearID, g.Key.EntityID, g.Key.FacilityID
, g.Key.AttendPhysicianID
, g.Key.PrimaryPhysicianID
, g.Key.AdmitDateTimeYr
, g.Key.AdmitDateTimeMo
, g.Key.CaseTypeFamilyID
, g.Key.DischargeDateTimeYr
, g.Key.DischargeDateTimeMo
, g.Key.DateofDeathYr
, g.Key.DateofDeathMo
, MinDeath = (int)g.Min(rl => Math.Abs((rl.DateofDeath - rl.DischargeDateTime).TotalDays))
, MaxDeath = (int)g.Max(rl => Math.Abs((rl.DateofDeath - rl.DischargeDateTime).TotalDays))
, AvgDeath = (int)g.Average(rl => Math.Abs((rl.DateofDeath - rl.DischargeDateTime).TotalDays))
, DeceasedPatients = g.Count()
, AvgLOS = (int)g.Average(rl => rl.LengthOfStay) }
;
(from data in dataRun
join de in Clientdss_DimEntities on data.EntityID equals de.EntityID
group data by new { data.EntityID, de.Name } into g
orderby g.Key.EntityID
select new { g.Key.EntityID, g.Key.Name, DeceasedPatients = g.Sum(rl => rl.DeceasedPatients) }).Dump();