chore: deploy initial linqpad queries

This commit is contained in:
Thom Lamb
2026-05-12 11:33:21 -05:00
parent 0a7a550d46
commit 96d0067f2d
120 changed files with 22939 additions and 0 deletions
+193
View File
@@ -0,0 +1,193 @@
<Query Kind="Program">
<Connection>
<ID>77b65bea-e766-4e3c-a1ed-c4c2534b6019</ID>
<Persist>true</Persist>
<Server>D0001-SQL-11.sdt.local</Server>
<Database>jazz dev master Prod</Database>
<ShowServer>true</ShowServer>
</Connection>
<Reference>&lt;ProgramFilesX64&gt;\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics\Newtonsoft.Json.dll</Reference>
<NuGetReference>Amazon.Lambda.S3Events</NuGetReference>
<NuGetReference>AWSSDK.Core</NuGetReference>
<NuGetReference>AWSSDK.S3</NuGetReference>
<Namespace>Amazon</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy.ActionIdentifiers</Namespace>
<Namespace>Amazon.Internal</Namespace>
<Namespace>Amazon.Lambda.S3Events</Namespace>
<Namespace>Amazon.MissingTypes</Namespace>
<Namespace>Amazon.Runtime</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement.Internal</Namespace>
<Namespace>Amazon.Runtime.EventStreams</Namespace>
<Namespace>Amazon.Runtime.EventStreams.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal.Auth</Namespace>
<Namespace>Amazon.Runtime.Internal.Settings</Namespace>
<Namespace>Amazon.Runtime.Internal.Transform</Namespace>
<Namespace>Amazon.Runtime.Internal.Util</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces.Internal</Namespace>
<Namespace>Amazon.S3</Namespace>
<Namespace>Amazon.S3.Encryption</Namespace>
<Namespace>Amazon.S3.Encryption.Internal</Namespace>
<Namespace>Amazon.S3.Internal</Namespace>
<Namespace>Amazon.S3.IO</Namespace>
<Namespace>Amazon.S3.Model</Namespace>
<Namespace>Amazon.S3.Model.Internal.MarshallTransformations</Namespace>
<Namespace>Amazon.S3.Transfer</Namespace>
<Namespace>Amazon.S3.Util</Namespace>
<Namespace>Amazon.Util</Namespace>
<Namespace>Amazon.Util.Internal</Namespace>
<Namespace>Amazon.Util.Internal.PlatformServices</Namespace>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>Newtonsoft.Json.Converters</Namespace>
<Namespace>Newtonsoft.Json.Linq</Namespace>
<Namespace>Newtonsoft.Json.Schema</Namespace>
<Namespace>Newtonsoft.Json.Serialization</Namespace>
<Namespace>System</Namespace>
<Namespace>System.Diagnostics</Namespace>
<Namespace>System.Diagnostics.Tracing</Namespace>
<Namespace>System.IO.Compression</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1.Utilities</Namespace>
<Namespace>ThirdParty.BouncyCastle.Math</Namespace>
<Namespace>ThirdParty.BouncyCastle.OpenSsl</Namespace>
<Namespace>ThirdParty.BouncyCastle.Utilities.IO.Pem</Namespace>
<Namespace>ThirdParty.Ionic.Zlib</Namespace>
<Namespace>ThirdParty.Json.LitJson</Namespace>
<Namespace>ThirdParty.MD5</Namespace>
<Namespace>System.ComponentModel</Namespace>
</Query>
void Main()
{
var caseTypes = (from fpes in FactPatientEncounterSummaries
join ves in VariationEncounterSavings on fpes.EncounterID equals ves.EncounterID
join vo in VariationOpportunities on ves.OpportunityGUID equals vo.OpportunityGUID
join config in Configurations on vo.ConfigurationGUID equals config.ConfigurationGUID
join cte in CaseTypeEntities on vo.CaseTypeEntityID equals cte.CaseTypeEntityID
join dct in DimCaseTypes on cte.CaseTypeGUID equals dct.MemberGUID
join d in DimMSDRGs on fpes.ReportingDRGID equals d.MSDRGID into da
from e in da.DefaultIfEmpty()
join f in DimAPRDRGs on fpes.APDRGID equals f.APRDRGID into fa
from g in fa.DefaultIfEmpty()
join cpt in DimCPTs on fpes.PrimaryCPTID equals cpt.CPTID into cpta
from ca in cpta.DefaultIfEmpty()
where config.FiscalYearID == 2020
select new
{
vo.ConfigurationGUID,
config.FiscalYearID,
dct.CaseTypeId,
dct.Name,
CCMCCCategory = e.CCMCCCategory ?? "",
SOI = g.APRSOI ?? "",
ROM = g.APRROM ?? "",
CPTCode = ca.CPTCode ?? "",
CaseTypeConfig = JsonConvert.DeserializeObject<CaseTypeDRGConfiguration>(dct.CaseTypeConfigJSON)
})
.Distinct()
.Select(t => new
{
t.ConfigurationGUID,
t.FiscalYearID,
t.CaseTypeId,
t.Name,
t.CCMCCCategory,
t.SOI,
t.ROM,
t.CPTCode,
t.CaseTypeConfig.AgeCohortIDInclusions,
t.CaseTypeConfig.PhysicianIDExclusions,
t.CaseTypeConfig.StandardDeviationExcludedTypeEnum,
t.CaseTypeConfig.LengthOfStayThreshold,
t.CaseTypeConfig.SOIROMInclusions,
t.CaseTypeConfig.CCMCCCategories,
t.CaseTypeConfig.CPTCodes,
t.CaseTypeConfig.PatientTypeRollupIDInclusions,
t.CaseTypeConfig.PhysicianMinVolume
})
.OrderBy(t => t.Name);
caseTypes.Dump();
}
// Define other methods and classes here
public const string CCMCCCATEGORY_CC = "CC";
public const string CCMCCCATEGORY_MCC = "MCC";
public const string CCMCCCATEGORY_WO = "W/O";
public const string CCMCCCATEGORY_NA = "N/A";
public const string CCMCCCATEGORY_CCMCC = "CC/MCC";
public enum CCMCCCategoryTypes
{
/// <summary>
/// No Category
/// </summary>
[Description("")]
None,
/// <summary>
/// Complication or Comorbidity
/// </summary>
[Description(CCMCCCATEGORY_CC)]
CC,
/// <summary>
/// Major Complication or Comorbidity
/// </summary>
[Description(CCMCCCATEGORY_MCC)]
MCC,
/// <summary>
/// Without Complication or Comorbidity OR Major Complication or Comorbidity
/// </summary>
[Description(CCMCCCATEGORY_WO)]
WO,
/// <summary>
/// Not Available
/// </summary>
[Description(CCMCCCATEGORY_NA)]
NA,
/// <summary>
/// Both Complication or Comorbidity AND Major Complication or Comorbidity
/// </summary>
[Description(CCMCCCATEGORY_CCMCC)]
CCMCC
}
public class SOIROMInclusion
{
public string SOI { get; }
public string ROM { get; }
public SOIROMInclusion(string soi, string rom)
{
SOI = soi;
ROM = rom;
}
}
public class CaseTypeDRGConfiguration
{
public int PhysicianMinVolume { get; set; }
public List<int> AgeCohortIDInclusions { get; set; }
public List<int> PhysicianIDExclusions { get; set; }
public int StandardDeviationExcludedTypeEnum { get; set; }
public int LengthOfStayThreshold { get; set; }
public List<int> PatientTypeRollupIDInclusions { get; set; }
public List<SOIROMInclusion> SOIROMInclusions { get; set; }
public HashSet<CCMCCCategoryTypes> CCMCCCategories { get; set; }
public HashSet<string> CPTCodes { get; set; }
public CaseTypeDRGConfiguration()
{
PhysicianMinVolume = 0;
AgeCohortIDInclusions = new List<int>();
PhysicianIDExclusions = new List<int>();
PatientTypeRollupIDInclusions = new List<int>();
StandardDeviationExcludedTypeEnum = 0;
LengthOfStayThreshold = 0;
CCMCCCategories = new HashSet<CCMCCCategoryTypes>();
CPTCodes = new HashSet<string>();
}
}
+139
View File
@@ -0,0 +1,139 @@
<Query Kind="Program">
<Connection>
<ID>870a756b-af44-4db4-b004-58ff41318b3a</ID>
<Persist>true</Persist>
<Server>P9900-SQL-11.sdt.local</Server>
<Database>jazz tst GM DSS Share Training Master</Database>
<ShowServer>true</ShowServer>
</Connection>
<Reference>&lt;ProgramFilesX64&gt;\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics\Newtonsoft.Json.dll</Reference>
<NuGetReference>Amazon.Lambda.S3Events</NuGetReference>
<NuGetReference>AWSSDK.Core</NuGetReference>
<NuGetReference>AWSSDK.S3</NuGetReference>
<Namespace>Amazon</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy.ActionIdentifiers</Namespace>
<Namespace>Amazon.Internal</Namespace>
<Namespace>Amazon.Lambda.S3Events</Namespace>
<Namespace>Amazon.MissingTypes</Namespace>
<Namespace>Amazon.Runtime</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement.Internal</Namespace>
<Namespace>Amazon.Runtime.EventStreams</Namespace>
<Namespace>Amazon.Runtime.EventStreams.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal.Auth</Namespace>
<Namespace>Amazon.Runtime.Internal.Settings</Namespace>
<Namespace>Amazon.Runtime.Internal.Transform</Namespace>
<Namespace>Amazon.Runtime.Internal.Util</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces.Internal</Namespace>
<Namespace>Amazon.S3</Namespace>
<Namespace>Amazon.S3.Encryption</Namespace>
<Namespace>Amazon.S3.Encryption.Internal</Namespace>
<Namespace>Amazon.S3.Internal</Namespace>
<Namespace>Amazon.S3.IO</Namespace>
<Namespace>Amazon.S3.Model</Namespace>
<Namespace>Amazon.S3.Model.Internal.MarshallTransformations</Namespace>
<Namespace>Amazon.S3.Transfer</Namespace>
<Namespace>Amazon.S3.Util</Namespace>
<Namespace>Amazon.Util</Namespace>
<Namespace>Amazon.Util.Internal</Namespace>
<Namespace>Amazon.Util.Internal.PlatformServices</Namespace>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>Newtonsoft.Json.Converters</Namespace>
<Namespace>Newtonsoft.Json.Linq</Namespace>
<Namespace>Newtonsoft.Json.Schema</Namespace>
<Namespace>Newtonsoft.Json.Serialization</Namespace>
<Namespace>System</Namespace>
<Namespace>System.Diagnostics</Namespace>
<Namespace>System.Diagnostics.Tracing</Namespace>
<Namespace>System.IO.Compression</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1.Utilities</Namespace>
<Namespace>ThirdParty.BouncyCastle.Math</Namespace>
<Namespace>ThirdParty.BouncyCastle.OpenSsl</Namespace>
<Namespace>ThirdParty.BouncyCastle.Utilities.IO.Pem</Namespace>
<Namespace>ThirdParty.Ionic.Zlib</Namespace>
<Namespace>ThirdParty.Json.LitJson</Namespace>
<Namespace>ThirdParty.MD5</Namespace>
</Query>
private IEnumerable<VersionInfo> existing_versions;
private IEnumerable<string> existing_migrations;
private IEnumerable<FamilyInfo> existing_families;
private IEnumerable<MappingInfo> existing_mappings;
void Main()
{
Step1();
existing_migrations.Dump();
existing_versions.Dump();
existing_families.Count().Dump();
existing_mappings.Count().Dump();
var documentFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
File.WriteAllText(Path.Combine(documentFolder, $"{nameof(existing_migrations)}.json"), JsonConvert.SerializeObject(existing_migrations, Newtonsoft.Json.Formatting.Indented));
File.WriteAllText(Path.Combine(documentFolder, $"{nameof(existing_versions)}.json"), JsonConvert.SerializeObject(existing_versions, Newtonsoft.Json.Formatting.Indented));
File.WriteAllText(Path.Combine(documentFolder, $"{nameof(existing_families)}.json"), JsonConvert.SerializeObject(existing_families, Newtonsoft.Json.Formatting.Indented));
File.WriteAllText(Path.Combine(documentFolder, $"{nameof(existing_mappings)}.json"), JsonConvert.SerializeObject(existing_mappings, Newtonsoft.Json.Formatting.Indented));
}
// Define other methods and classes here
private void Step1()
{
existing_migrations = from ml in MigrationLogs where ml.DateTimeStamp > new DateTime(2018, 11, 16) && ml.Name.Replace(" ", "").Contains("CaseType") orderby ml.DateTimeStamp descending select ml.Name;
existing_versions = from ctfv in CaseTypeFamilyVersions select new VersionInfo(ctfv.CaseTypeFamilyVersionID, ctfv.Name, ctfv.StartDate, ctfv.EndDate);
existing_families = from ctf in CaseTypeFamilies select new FamilyInfo(ctf.CaseTypeFamilyGlobalID, ctf.Name, ctf.CaseTypeFamilyID);
existing_mappings = (from ctfm in CaseTypeFamilyMappingICD10s
join family in CaseTypeFamilies on ctfm.CaseTypeFamilyID equals family.CaseTypeFamilyID
where ctfm.CaseTypeFamilyVersionID == 1
select new MappingInfo(family.CaseTypeFamilyGlobalID, ctfm.SkipICD, ctfm.ICD10Code, ctfm.MSDRGCode)).Distinct();
}
public class VersionInfo
{
public int CaseTypeFamilyVersionId { get; set; }
public string Name { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public VersionInfo(int id, string name, DateTime start, DateTime end)
{
CaseTypeFamilyVersionId = id;
Name = name;
StartDate = start;
EndDate = end;
}
}
public class FamilyInfo
{
public int CaseTypeFamilyID { get; set; }
public string CaseTypeFamilyGlobalID { get; set; }
public string Name { get; set; }
public FamilyInfo(string caseTypeFamilyGlobalID, string name, int caseTypeFamilyID)
{
CaseTypeFamilyID = caseTypeFamilyID;
CaseTypeFamilyGlobalID = caseTypeFamilyGlobalID;
Name = name;
}
}
public class MappingInfo
{
public string CaseTypeFamilyGlobalID { get; set; }
public bool SkipICD { get; set; }
public string ICD10Code { get; set; }
public string MSDRGCode { get; set; }
public MappingInfo(string caseTypeFamilyGlobalID, bool skipICD, string icd10Code, string msdrgCode)
{
CaseTypeFamilyGlobalID = caseTypeFamilyGlobalID;
SkipICD = skipICD;
ICD10Code = icd10Code;
MSDRGCode = msdrgCode;
}
}
@@ -0,0 +1,286 @@
<Query Kind="Program">
<Connection>
<ID>870a756b-af44-4db4-b004-58ff41318b3a</ID>
<Persist>true</Persist>
<Server>P9900-SQL-11.sdt.local</Server>
<Database>jazz tst GM non DSS Share Training Master</Database>
<ShowServer>true</ShowServer>
</Connection>
<Reference>&lt;ProgramFilesX64&gt;\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics\Newtonsoft.Json.dll</Reference>
<NuGetReference>Amazon.Lambda.S3Events</NuGetReference>
<NuGetReference>AWSSDK.Core</NuGetReference>
<NuGetReference>AWSSDK.S3</NuGetReference>
<Namespace>Amazon</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy.ActionIdentifiers</Namespace>
<Namespace>Amazon.Internal</Namespace>
<Namespace>Amazon.Lambda.S3Events</Namespace>
<Namespace>Amazon.MissingTypes</Namespace>
<Namespace>Amazon.Runtime</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement.Internal</Namespace>
<Namespace>Amazon.Runtime.EventStreams</Namespace>
<Namespace>Amazon.Runtime.EventStreams.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal.Auth</Namespace>
<Namespace>Amazon.Runtime.Internal.Settings</Namespace>
<Namespace>Amazon.Runtime.Internal.Transform</Namespace>
<Namespace>Amazon.Runtime.Internal.Util</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces.Internal</Namespace>
<Namespace>Amazon.S3</Namespace>
<Namespace>Amazon.S3.Encryption</Namespace>
<Namespace>Amazon.S3.Encryption.Internal</Namespace>
<Namespace>Amazon.S3.Internal</Namespace>
<Namespace>Amazon.S3.IO</Namespace>
<Namespace>Amazon.S3.Model</Namespace>
<Namespace>Amazon.S3.Model.Internal.MarshallTransformations</Namespace>
<Namespace>Amazon.S3.Transfer</Namespace>
<Namespace>Amazon.S3.Util</Namespace>
<Namespace>Amazon.Util</Namespace>
<Namespace>Amazon.Util.Internal</Namespace>
<Namespace>Amazon.Util.Internal.PlatformServices</Namespace>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>Newtonsoft.Json.Converters</Namespace>
<Namespace>Newtonsoft.Json.Linq</Namespace>
<Namespace>Newtonsoft.Json.Schema</Namespace>
<Namespace>Newtonsoft.Json.Serialization</Namespace>
<Namespace>System</Namespace>
<Namespace>System.Diagnostics</Namespace>
<Namespace>System.Diagnostics.Tracing</Namespace>
<Namespace>System.IO.Compression</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1.Utilities</Namespace>
<Namespace>ThirdParty.BouncyCastle.Math</Namespace>
<Namespace>ThirdParty.BouncyCastle.OpenSsl</Namespace>
<Namespace>ThirdParty.BouncyCastle.Utilities.IO.Pem</Namespace>
<Namespace>ThirdParty.Ionic.Zlib</Namespace>
<Namespace>ThirdParty.Json.LitJson</Namespace>
<Namespace>ThirdParty.MD5</Namespace>
</Query>
private IEnumerable<VersionInfo> correct_versions;
private IEnumerable<string> correct_migrations;
private IEnumerable<FamilyInfo> correct_families;
private IEnumerable<MappingInfo> correct_mappings;
private IEnumerable<VersionInfo> existing_versions;
private IEnumerable<string> existing_migrations;
private IEnumerable<FamilyInfo> existing_families;
private IEnumerable<MappingInfo> existing_mappings;
void Main()
{
//var cts = Util.GetMyQueries().FirstOrDefault(u => u.FilePath.EndsWith("CaseTypeSource.linq"));
//var connStr = cts.GetConnectionInfo().DatabaseInfo.GetCxString();
Step1();
Step2();
var versions = (from cf in correct_versions
join ef in existing_versions on cf.CaseTypeFamilyVersionId equals ef.CaseTypeFamilyVersionId into cef
from ef in cef.DefaultIfEmpty()
select new { cf, ef }).ToList();
versions.Dump(nameof(versions));
var migrations = (from cf in correct_migrations
join ef in existing_migrations on cf equals ef into cef
from ef in cef.DefaultIfEmpty()
select new { cf, ef }).ToList();
var migrationDeletes = (from cf in existing_migrations
join ef in correct_migrations on cf equals ef into cef
from ef in cef.DefaultIfEmpty()
select new { cf, ef }).ToList();
var families = (from cf in correct_families
join ef in existing_families on cf.CaseTypeFamilyGlobalID equals ef.CaseTypeFamilyGlobalID into cef
from ef in cef.DefaultIfEmpty()
select new { cf, ef }).ToList();
var familyDeletes = (from cf in existing_families
join ef in correct_families on cf.CaseTypeFamilyGlobalID equals ef.CaseTypeFamilyGlobalID into cef
from ef in cef.DefaultIfEmpty()
select new { cf, ef }).ToList();
var mappings = (from cm in correct_mappings
join em in existing_mappings on new { cm.CaseTypeFamilyGlobalID, cm.SkipICD, cm.ICD10Code, cm.MSDRGCode }
equals new { em.CaseTypeFamilyGlobalID, em.SkipICD, em.ICD10Code, em.MSDRGCode } into cem
from em in cem.DefaultIfEmpty()
select new { cm, em }).ToList();
var mappingDeletes = (from cm in existing_mappings
join em in correct_mappings on new { cm.CaseTypeFamilyGlobalID, cm.SkipICD, cm.ICD10Code, cm.MSDRGCode }
equals new { em.CaseTypeFamilyGlobalID, em.SkipICD, em.ICD10Code, em.MSDRGCode } into cem
from em in cem.DefaultIfEmpty()
select new { cm, em }).ToList();
var documentFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var sql = versions.Where(f => f.ef == null)
.Aggregate(@"", (x, y) => $@"{x}
INSERT INTO [dss].[CaseTypeFamilyVersion] (CaseTypeFamilyVersionId, Name, StartDate, EndDate)
SELECT '{y.cf.CaseTypeFamilyVersionId}', '{y.cf.Name}', '{y.cf.StartDate:G}', '{y.cf.EndDate:G}'
WHERE NOT EXISTS (SELECT 1 FROM [dss].[CaseTypeFamilyVersion] WHERE CaseTypeFamilyVersionId = '{y.cf.CaseTypeFamilyVersionId}');
");
if (File.Exists(Path.Combine(documentFolder, $"Case Type Family Corrections 1 ({this.Connection.Database}).sql")))
File.Delete(Path.Combine(documentFolder, $"Case Type Family Corrections 1 ({this.Connection.Database}).sql"));
if (!string.IsNullOrEmpty(sql.Trim()))
File.WriteAllText(Path.Combine(documentFolder, $"Case Type Family Corrections 1 ({this.Connection.Database}).sql"), sql);
sql = versions.Where(f => f.ef != null
&& ((f.cf.Name != f.ef.Name
&& f.cf.Name.Replace("And", "&") != f.ef.Name
&& f.cf.Name.Replace(" And ", "&") != f.ef.Name)
|| (f.cf.StartDate != f.ef.StartDate)
|| (f.cf.EndDate != f.ef.EndDate)))
.Aggregate(@"", (x, y) => $@"{x}
UPDATE [dss].[CaseTypeFamilyVersion]
SET Name = '{y.cf.Name}', StartDate = '{y.cf.StartDate:G}', EndDate = '{y.cf.EndDate:G}'
WHERE CaseTypeFamilyVersionId = '{y.cf.CaseTypeFamilyVersionId}'; -- current name = {y.ef.Name}
");
if (File.Exists(Path.Combine(documentFolder, $"Case Type Family Corrections 2 ({this.Connection.Database}).sql")))
File.Delete(Path.Combine(documentFolder, $"Case Type Family Corrections 2 ({this.Connection.Database}).sql"));
if (!string.IsNullOrEmpty(sql.Trim()))
File.WriteAllText(Path.Combine(documentFolder, $"Case Type Family Corrections 2 ({this.Connection.Database}).sql"), sql);
sql = families.Where(f => f.ef == null)
.Aggregate(@"", (x, y) => $@"{x}
INSERT INTO [dss].[CaseTypeFamily] (CaseTypeFamilyGlobalID, Name)
SELECT '{y.cf.CaseTypeFamilyGlobalID}', '{y.cf.Name}'
WHERE NOT EXISTS (SELECT 1 FROM [dss].[CaseTypeFamily] WHERE CaseTypeFamilyGlobalID = '{y.cf.CaseTypeFamilyGlobalID}');
");
if (File.Exists(Path.Combine(documentFolder, $"Case Type Family Corrections 3 ({this.Connection.Database}).sql")))
File.Delete(Path.Combine(documentFolder, $"Case Type Family Corrections 3 ({this.Connection.Database}).sql"));
if (!string.IsNullOrEmpty(sql.Trim()))
File.WriteAllText(Path.Combine(documentFolder, $"Case Type Family Corrections 3 ({this.Connection.Database}).sql"), sql);
sql = families.Where(f => f.ef != null
&& (f.cf.Name != f.ef.Name
&& f.cf.Name.Replace("And", "&") != f.ef.Name
&& f.cf.Name.Replace(" And ", "&") != f.ef.Name))
.Aggregate(@"", (x, y) => $@"{x}
UPDATE [dss].[CaseTypeFamily]
SET Name = '{y.cf.Name}'
WHERE CaseTypeFamilyGlobalID = '{y.cf.CaseTypeFamilyGlobalID}'; -- current name = {y.ef.Name}
");
if (File.Exists(Path.Combine(documentFolder, $"Case Type Family Corrections 4 ({this.Connection.Database}).sql")))
File.Delete(Path.Combine(documentFolder, $"Case Type Family Corrections 4 ({this.Connection.Database}).sql"));
if (!string.IsNullOrEmpty(sql.Trim()))
File.WriteAllText(Path.Combine(documentFolder, $"Case Type Family Corrections 4 ({this.Connection.Database}).sql"), sql);
var insert = sql = mappings.Where(f => f.em == null).Any()
? @"INSERT INTO [dss].[CaseTypeFamilyMappingICD10] ([CaseTypeFamilyID], [SkipICD], [ICD10Code], [MSDRGCode], [CaseTypeFamilyVersionID])
" : "";
var selects = mappings.Where(f => f.em == null)
.Select((y, idx) => new { query = $@"SELECT [CaseTypeFamilyID], {(y.cm.SkipICD ? 1 : 0)}, '{y.cm.ICD10Code}', '{y.cm.MSDRGCode}', 1 FROM [dss].[CaseTypeFamily] WHERE [CaseTypeFamilyGlobalID] = '{y.cm.CaseTypeFamilyGlobalID}'", idx })
.GroupBy(g => g.idx / 1000, (g, d) => d)
.Select(z => insert + string.Join("\r\nUNION ALL\r\n", z.Select(y => y.query)));
Enumerable.Range(0, 999).ToList()
.ForEach(y =>
{
if (File.Exists(Path.Combine(documentFolder, $"Case Type Family Corrections 3{y:000} ({this.Connection.Database}).sql")))
File.Delete(Path.Combine(documentFolder, $"Case Type Family Corrections 3{y:000} ({this.Connection.Database}).sql"));
});
selects.ForEach((x, y) => File.WriteAllText(Path.Combine(documentFolder, $"Case Type Family Corrections 3{y:000} ({this.Connection.Database}).sql"), x));
versions.Where(f => f.ef == null).Dump("missing versions");
migrations.Where(f => f.ef == null).Dump("missing migrations");
migrationDeletes.Where(f => f.ef == null).Dump("migrations to delete");
families.Where(f => f.ef == null).Dump("missing families");
families.Where(f => f.ef != null
&& (f.cf.Name != f.ef.Name
&& f.cf.Name.Replace("And", "&") != f.ef.Name
&& f.cf.Name.Replace(" And ", "&") != f.ef.Name)).Dump("families to update");
familyDeletes.Where(f => f.ef == null).Dump("families to detele");
mappings.Where(f => f.em == null).Dump("missing mappings");
mappings.Where(f => f.em != null && (f.cm.SkipICD != f.em.SkipICD || f.cm.ICD10Code != f.em.ICD10Code || f.cm.MSDRGCode != f.em.MSDRGCode)).Dump("mappings to update");
mappingDeletes.Where(f => f.em == null).Dump("mappings to delete");
}
// Define other methods and classes here
///
/// Connect to P2680-SQL-03 - jazz prd Mercy Health 20160308.1
///
private void Step1(string connectionString)
{
var currentConnection = this.Connection.ConnectionString;
this.Connection.ConnectionString = connectionString;
this.Connection.Dump();
correct_migrations = from ml in MigrationLogs
where ml.Name.Replace(" ", "").Contains("CaseType") //&& ml.DateTimeStamp > new DateTime(2018, 11, 16)
orderby ml.DateTimeStamp descending
select ml.Name;
correct_versions = from ctfv in CaseTypeFamilyVersions select new VersionInfo(ctfv.CaseTypeFamilyVersionID, ctfv.Name, ctfv.StartDate, ctfv.EndDate);
correct_families = from ctf in CaseTypeFamilies select new FamilyInfo(ctf.CaseTypeFamilyGlobalID, ctf.Name, ctf.CaseTypeFamilyID);
correct_mappings = (from ctfm in CaseTypeFamilyMappingICD10s
join family in CaseTypeFamilies on ctfm.CaseTypeFamilyID equals family.CaseTypeFamilyID
where ctfm.CaseTypeFamilyVersionID == 1
select new MappingInfo(family.CaseTypeFamilyGlobalID, ctfm.SkipICD, ctfm.ICD10Code, ctfm.MSDRGCode)).Distinct();
this.Connection.ConnectionString = currentConnection;
}
private void Step1()
{
var documentFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
correct_migrations = JsonConvert.DeserializeObject<IEnumerable<string>>(File.ReadAllText(Path.Combine(documentFolder, $"{nameof(correct_migrations)}.json")));
correct_versions = JsonConvert.DeserializeObject<IEnumerable<VersionInfo>>(File.ReadAllText(Path.Combine(documentFolder, $"{nameof(correct_versions)}.json")));
correct_families = JsonConvert.DeserializeObject<IEnumerable<FamilyInfo>>(File.ReadAllText(Path.Combine(documentFolder, $"{nameof(correct_families)}.json")));
correct_mappings = JsonConvert.DeserializeObject<IEnumerable<MappingInfo>>(File.ReadAllText(Path.Combine(documentFolder, $"{nameof(correct_mappings)}.json")));
}
private void Step2()
{
existing_migrations = from ml in MigrationLogs
where ml.Name.Replace(" ", "").Contains("CaseType") //&& ml.DateTimeStamp > new DateTime(2018, 11, 16)
orderby ml.DateTimeStamp
select ml.Name;
existing_versions = from ctfv in CaseTypeFamilyVersions select new VersionInfo(ctfv.CaseTypeFamilyVersionID, ctfv.Name, ctfv.StartDate, ctfv.EndDate);
existing_families = from ctf in CaseTypeFamilies select new FamilyInfo(ctf.CaseTypeFamilyGlobalID, ctf.Name, ctf.CaseTypeFamilyID);
existing_mappings = (from ctfm in CaseTypeFamilyMappingICD10s
join family in CaseTypeFamilies on ctfm.CaseTypeFamilyID equals family.CaseTypeFamilyID
where ctfm.CaseTypeFamilyVersionID == 1
select new MappingInfo(family.CaseTypeFamilyGlobalID, ctfm.SkipICD, ctfm.ICD10Code, ctfm.MSDRGCode)).Distinct();
}
public class VersionInfo
{
public int CaseTypeFamilyVersionId { get; set; }
public string Name { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public VersionInfo(int id, string name, DateTime start, DateTime end)
{
CaseTypeFamilyVersionId = id;
Name = name;
StartDate = start;
EndDate = end;
}
}
public class FamilyInfo
{
public int CaseTypeFamilyID { get; set; }
public string CaseTypeFamilyGlobalID { get; set; }
public string Name { get; set; }
public FamilyInfo(string caseTypeFamilyGlobalID, string name, int caseTypeFamilyID)
{
CaseTypeFamilyID = caseTypeFamilyID;
CaseTypeFamilyGlobalID = caseTypeFamilyGlobalID;
Name = name;
}
}
public class MappingInfo
{
public string CaseTypeFamilyGlobalID { get; set; }
public bool SkipICD { get; set; }
public string ICD10Code { get; set; }
public string MSDRGCode { get; set; }
public MappingInfo(string caseTypeFamilyGlobalID, bool skipICD, string icd10Code, string msdrgCode)
{
CaseTypeFamilyGlobalID = caseTypeFamilyGlobalID;
SkipICD = skipICD;
ICD10Code = icd10Code;
MSDRGCode = msdrgCode;
}
}
@@ -0,0 +1,79 @@
<Query Kind="Program">
<Connection>
<ID>870a756b-af44-4db4-b004-58ff41318b3a</ID>
<Persist>true</Persist>
<Server>P9900-SQL-11.sdt.local</Server>
<Database>jazz tst GM non DSS Share Training Master</Database>
<ShowServer>true</ShowServer>
</Connection>
<Reference>&lt;ProgramFilesX64&gt;\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics\Newtonsoft.Json.dll</Reference>
<NuGetReference>Amazon.Lambda.S3Events</NuGetReference>
<NuGetReference>AWSSDK.Core</NuGetReference>
<NuGetReference>AWSSDK.S3</NuGetReference>
<Namespace>Amazon</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy.ActionIdentifiers</Namespace>
<Namespace>Amazon.Internal</Namespace>
<Namespace>Amazon.Lambda.S3Events</Namespace>
<Namespace>Amazon.MissingTypes</Namespace>
<Namespace>Amazon.Runtime</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement.Internal</Namespace>
<Namespace>Amazon.Runtime.EventStreams</Namespace>
<Namespace>Amazon.Runtime.EventStreams.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal.Auth</Namespace>
<Namespace>Amazon.Runtime.Internal.Settings</Namespace>
<Namespace>Amazon.Runtime.Internal.Transform</Namespace>
<Namespace>Amazon.Runtime.Internal.Util</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces.Internal</Namespace>
<Namespace>Amazon.S3</Namespace>
<Namespace>Amazon.S3.Encryption</Namespace>
<Namespace>Amazon.S3.Encryption.Internal</Namespace>
<Namespace>Amazon.S3.Internal</Namespace>
<Namespace>Amazon.S3.IO</Namespace>
<Namespace>Amazon.S3.Model</Namespace>
<Namespace>Amazon.S3.Model.Internal.MarshallTransformations</Namespace>
<Namespace>Amazon.S3.Transfer</Namespace>
<Namespace>Amazon.S3.Util</Namespace>
<Namespace>Amazon.Util</Namespace>
<Namespace>Amazon.Util.Internal</Namespace>
<Namespace>Amazon.Util.Internal.PlatformServices</Namespace>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>Newtonsoft.Json.Converters</Namespace>
<Namespace>Newtonsoft.Json.Linq</Namespace>
<Namespace>Newtonsoft.Json.Schema</Namespace>
<Namespace>Newtonsoft.Json.Serialization</Namespace>
<Namespace>System</Namespace>
<Namespace>System.Diagnostics</Namespace>
<Namespace>System.Diagnostics.Tracing</Namespace>
<Namespace>System.IO.Compression</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1.Utilities</Namespace>
<Namespace>ThirdParty.BouncyCastle.Math</Namespace>
<Namespace>ThirdParty.BouncyCastle.OpenSsl</Namespace>
<Namespace>ThirdParty.BouncyCastle.Utilities.IO.Pem</Namespace>
<Namespace>ThirdParty.Ionic.Zlib</Namespace>
<Namespace>ThirdParty.Json.LitJson</Namespace>
<Namespace>ThirdParty.MD5</Namespace>
</Query>
void Main()
{
var documentFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var files = Directory.GetFiles(documentFolder, "Case Type Family Corrections*.sql")
.Select(d => Path.GetFileName(d))
.OrderBy(d => d)
.ToList();
files.ForEach(f =>
{
"".Dump(f);
var query = File.ReadAllText(Path.Combine(documentFolder, f));
this.ExecuteCommand(query);
});
}
// Define other methods and classes here
+142
View File
@@ -0,0 +1,142 @@
<Query Kind="Program">
<Connection>
<ID>94a82e0d-b8c1-4789-96cc-f34a75ba3c45</ID>
<Persist>true</Persist>
<Server>P2980-SQL-03.sdt.local</Server>
<Database>jazz prd Mercy Health 20160308.1</Database>
<ShowServer>true</ShowServer>
</Connection>
<Reference>&lt;ProgramFilesX64&gt;\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics\Newtonsoft.Json.dll</Reference>
<NuGetReference>Amazon.Lambda.S3Events</NuGetReference>
<NuGetReference>AWSSDK.Core</NuGetReference>
<NuGetReference>AWSSDK.S3</NuGetReference>
<Namespace>Amazon</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy.ActionIdentifiers</Namespace>
<Namespace>Amazon.Internal</Namespace>
<Namespace>Amazon.Lambda.S3Events</Namespace>
<Namespace>Amazon.MissingTypes</Namespace>
<Namespace>Amazon.Runtime</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement.Internal</Namespace>
<Namespace>Amazon.Runtime.EventStreams</Namespace>
<Namespace>Amazon.Runtime.EventStreams.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal.Auth</Namespace>
<Namespace>Amazon.Runtime.Internal.Settings</Namespace>
<Namespace>Amazon.Runtime.Internal.Transform</Namespace>
<Namespace>Amazon.Runtime.Internal.Util</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces.Internal</Namespace>
<Namespace>Amazon.S3</Namespace>
<Namespace>Amazon.S3.Encryption</Namespace>
<Namespace>Amazon.S3.Encryption.Internal</Namespace>
<Namespace>Amazon.S3.Internal</Namespace>
<Namespace>Amazon.S3.IO</Namespace>
<Namespace>Amazon.S3.Model</Namespace>
<Namespace>Amazon.S3.Model.Internal.MarshallTransformations</Namespace>
<Namespace>Amazon.S3.Transfer</Namespace>
<Namespace>Amazon.S3.Util</Namespace>
<Namespace>Amazon.Util</Namespace>
<Namespace>Amazon.Util.Internal</Namespace>
<Namespace>Amazon.Util.Internal.PlatformServices</Namespace>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>Newtonsoft.Json.Converters</Namespace>
<Namespace>Newtonsoft.Json.Linq</Namespace>
<Namespace>Newtonsoft.Json.Schema</Namespace>
<Namespace>Newtonsoft.Json.Serialization</Namespace>
<Namespace>System</Namespace>
<Namespace>System.Diagnostics</Namespace>
<Namespace>System.Diagnostics.Tracing</Namespace>
<Namespace>System.IO.Compression</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1.Utilities</Namespace>
<Namespace>ThirdParty.BouncyCastle.Math</Namespace>
<Namespace>ThirdParty.BouncyCastle.OpenSsl</Namespace>
<Namespace>ThirdParty.BouncyCastle.Utilities.IO.Pem</Namespace>
<Namespace>ThirdParty.Ionic.Zlib</Namespace>
<Namespace>ThirdParty.Json.LitJson</Namespace>
<Namespace>ThirdParty.MD5</Namespace>
</Query>
private IEnumerable<VersionInfo> correct_versions;
private IEnumerable<string> correct_migrations;
private IEnumerable<FamilyInfo> correct_families;
private IEnumerable<MappingInfo> correct_mappings;
void Main()
{
Step1();
correct_migrations.Dump();
correct_versions.Dump();
correct_families.Count().Dump();
correct_mappings.Count().Dump();
var documentFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
File.WriteAllText(Path.Combine(documentFolder, $"{nameof(correct_migrations)}.json"), JsonConvert.SerializeObject(correct_migrations, Newtonsoft.Json.Formatting.Indented));
File.WriteAllText(Path.Combine(documentFolder, $"{nameof(correct_versions)}.json"), JsonConvert.SerializeObject(correct_versions, Newtonsoft.Json.Formatting.Indented));
File.WriteAllText(Path.Combine(documentFolder, $"{nameof(correct_families)}.json"), JsonConvert.SerializeObject(correct_families, Newtonsoft.Json.Formatting.Indented));
File.WriteAllText(Path.Combine(documentFolder, $"{nameof(correct_mappings)}.json"), JsonConvert.SerializeObject(correct_mappings, Newtonsoft.Json.Formatting.Indented));
}
// Define other methods and classes here
private void Step1()
{
correct_migrations = from ml in MigrationLogs
where ml.Name.Replace(" ", "").Contains("CaseType") //&& ml.DateTimeStamp > new DateTime(2018, 11, 16)
orderby ml.DateTimeStamp descending
select ml.Name;
correct_versions = from ctfv in CaseTypeFamilyVersions select new VersionInfo(ctfv.CaseTypeFamilyVersionID, ctfv.Name, ctfv.StartDate, ctfv.EndDate);
correct_families = from ctf in CaseTypeFamilies select new FamilyInfo(ctf.CaseTypeFamilyGlobalID, ctf.Name, ctf.CaseTypeFamilyID);
correct_mappings = (from ctfm in CaseTypeFamilyMappingICD10s
join family in CaseTypeFamilies on ctfm.CaseTypeFamilyID equals family.CaseTypeFamilyID
where ctfm.CaseTypeFamilyVersionID == 1
select new MappingInfo(family.CaseTypeFamilyGlobalID, ctfm.SkipICD, ctfm.ICD10Code, ctfm.MSDRGCode)).Distinct();
}
public class VersionInfo
{
public int CaseTypeFamilyVersionId { get; set; }
public string Name { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public VersionInfo(int id, string name, DateTime start, DateTime end)
{
CaseTypeFamilyVersionId = id;
Name = name;
StartDate = start;
EndDate = end;
}
}
public class FamilyInfo
{
public int CaseTypeFamilyID { get; set; }
public string CaseTypeFamilyGlobalID { get; set; }
public string Name { get; set; }
public FamilyInfo(string caseTypeFamilyGlobalID, string name, int caseTypeFamilyID)
{
CaseTypeFamilyID = caseTypeFamilyID;
CaseTypeFamilyGlobalID = caseTypeFamilyGlobalID;
Name = name;
}
}
public class MappingInfo
{
public string CaseTypeFamilyGlobalID { get; set; }
public bool SkipICD { get; set; }
public string ICD10Code { get; set; }
public string MSDRGCode { get; set; }
public MappingInfo(string caseTypeFamilyGlobalID, bool skipICD, string icd10Code, string msdrgCode)
{
CaseTypeFamilyGlobalID = caseTypeFamilyGlobalID;
SkipICD = skipICD;
ICD10Code = icd10Code;
MSDRGCode = msdrgCode;
}
}
@@ -0,0 +1,788 @@
<Query Kind="Program">
<Reference>&lt;ProgramFilesX64&gt;\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics\Newtonsoft.Json.dll</Reference>
<NuGetReference>Amazon.Lambda.S3Events</NuGetReference>
<NuGetReference>AWSSDK.Core</NuGetReference>
<NuGetReference>AWSSDK.S3</NuGetReference>
<Namespace>Amazon</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy.ActionIdentifiers</Namespace>
<Namespace>Amazon.Internal</Namespace>
<Namespace>Amazon.Lambda.S3Events</Namespace>
<Namespace>Amazon.MissingTypes</Namespace>
<Namespace>Amazon.Runtime</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement.Internal</Namespace>
<Namespace>Amazon.Runtime.EventStreams</Namespace>
<Namespace>Amazon.Runtime.EventStreams.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal.Auth</Namespace>
<Namespace>Amazon.Runtime.Internal.Settings</Namespace>
<Namespace>Amazon.Runtime.Internal.Transform</Namespace>
<Namespace>Amazon.Runtime.Internal.Util</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces.Internal</Namespace>
<Namespace>Amazon.S3</Namespace>
<Namespace>Amazon.S3.Encryption</Namespace>
<Namespace>Amazon.S3.Encryption.Internal</Namespace>
<Namespace>Amazon.S3.Internal</Namespace>
<Namespace>Amazon.S3.IO</Namespace>
<Namespace>Amazon.S3.Model</Namespace>
<Namespace>Amazon.S3.Model.Internal.MarshallTransformations</Namespace>
<Namespace>Amazon.S3.Transfer</Namespace>
<Namespace>Amazon.S3.Util</Namespace>
<Namespace>Amazon.Util</Namespace>
<Namespace>Amazon.Util.Internal</Namespace>
<Namespace>Amazon.Util.Internal.PlatformServices</Namespace>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>Newtonsoft.Json.Converters</Namespace>
<Namespace>Newtonsoft.Json.Linq</Namespace>
<Namespace>Newtonsoft.Json.Schema</Namespace>
<Namespace>Newtonsoft.Json.Serialization</Namespace>
<Namespace>System</Namespace>
<Namespace>System.ComponentModel.Composition</Namespace>
<Namespace>System.ComponentModel.Composition.Hosting</Namespace>
<Namespace>System.ComponentModel.Composition.Primitives</Namespace>
<Namespace>System.ComponentModel.Composition.ReflectionModel</Namespace>
<Namespace>System.Diagnostics</Namespace>
<Namespace>System.Diagnostics.Tracing</Namespace>
<Namespace>System.IO.Compression</Namespace>
<Namespace>System.Net.Http</Namespace>
<Namespace>System.Net.Http.Headers</Namespace>
<Namespace>System.Numerics</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1.Utilities</Namespace>
<Namespace>ThirdParty.BouncyCastle.Math</Namespace>
<Namespace>ThirdParty.BouncyCastle.OpenSsl</Namespace>
<Namespace>ThirdParty.BouncyCastle.Utilities.IO.Pem</Namespace>
<Namespace>ThirdParty.Ionic.Zlib</Namespace>
<Namespace>ThirdParty.Json.LitJson</Namespace>
<Namespace>ThirdParty.MD5</Namespace>
</Query>
private string text = @"1 558 M-296
1 987 M-345
1 895 M-16
1 670 M-304
1 445 M-98
1 599 A-19
1 505 M-125
1 033 M-322
1 247 M-229
1 881 M-90
1 294 M-100
1 605 M-305
1 208 M-367
1 163 M-177
1 248 M-230
1 182 M-262
1 637 A-6
1 287 M-337
1 815 M-264
1 344 M-194
1 387 A-13
1 281 M-5
1 985 M-249
1 923 M-354
1 896 M-17
1 920 M-338
1 230 A-21
1 975 M-142
1 504 M-125
1 754 M-187
1 950 M-13
1 263 M-321
1 579 M-362
1 034 M-231
1 595 A-18
1 574 M-277
1 472 M-61
1 258 M-56
1 776 M-245
1 200 M-241
1 336 A-24
1 603 M-58
1 334 M-253
1 729 M-217
1 816 M-264
1 158 M-89
1 485 M-163
1 310 M-328
1 555 M-274
1 600 M-204
1 661 M-162
1 849 A-26
1 939 M-346
1 389 M-131
1 187 M-239
1 410 M-283
1 712 M-297
1 333 M-253
1 186 M-239
1 510 M-222
1 343 M-29
1 865 A-32
1 790 M-116
1 183 M-178
1 501 M-280
1 578 M-276
1 809 M-182
1 781 M-25
1 750 M-214
1 150 M-108
1 350 M-152
1 770 M-281
1 335 A-24
1 453 M-27
1 053 M-288
1 474 M-21
1 424 M-353
1 709 M-228
1 178 M-261
1 561 M-72
1 100 M-270
1 710 M-228
1 556 M-274
1 416 M-65
1 123 M-201
1 935 M-203
1 516 M-357
1 355 M-140
1 215 M-137
1 189 M-251
1 094 M-34
1 064 M-59
1 685 M-8
1 617 M-22
1 759 A-9
1 464 M-323
1 725 M-36
1 664 M-193
1 789 M-344
1 167 M-361
1 292 A-12
1 800 A-29
1 509 M-30
1 668 M-304
1 069 A-31
1 594 A-27
1 882 M-202
1 663 M-193
1 314 A-22
1 767 M-318
1 489 M-164
1 871 M-273
1 688 M-161
1 959 M-359
1 667 M-248
1 455 M-27
1 675 M-355
1 006 M-169
1 155 M-213
1 228 A-21
1 059 M-88
1 760 M-118
1 843 M-220
1 903 M-111
1 070 M-60
1 031 M-322
1 495 M-109
1 779 M-1
1 928 M-129
1 179 M-261
1 222 M-55
1 371 M-180
1 381 M-70
1 949 M-13
1 298 M-52
1 792 M-247
1 285 M-6
1 308 M-328
1 221 M-285
1 657 M-159
1 264 M-349
1 028 A-28
1 639 A-6
1 511 M-222
1 500 M-280
1 695 M-158
1 180 M-262
1 176 A-25
1 674 M-355
1 037 M-115
1 945 M-105
1 597 A-19
1 478 M-41
1 841 M-172
1 869 M-150
1 306 M-75
1 948 M-368
1 570 M-329
1 654 A-15
1 138 M-196
1 908 M-358
1 434 M-66
1 538 M-291
1 559 M-72
1 965 M-356
1 202 M-48
1 557 M-296
1 689 M-160
1 244 M-234
1 446 M-98
1 101 M-270
1 723 M-189
1 225 M-54
1 835 M-4
1 549 M-272
1 262 M-57
1 964 M-356
1 956 M-167
1 376 A-7
1 437 M-188
1 135 M-275
1 352 M-152
1 984 M-249
1 226 M-53
1 283 M-6
1 218 M-284
1 370 A-16
1 540 M-209
1 191 M-77
1 534 M-120
1 602 M-58
1 982 M-114
1 148 M-102
1 838 M-62
1 007 M-171
1 293 A-12
1 097 M-287
1 280 M-5
1 498 M-110
1 746 M-317
1 830 M-199
1 272 M-334
1 067 M-205
1 458 M-290
1 078 M-146
1 147 M-102
1 345 M-194
1 071 M-60
1 295 M-100
1 096 M-34
1 235 M-49
1 385 A-13
1 624 M-279
1 499 M-110
1 922 M-354
1 234 M-50
1 423 M-353
1 989 M-345
1 715 M-186
1 765 M-84
1 934 M-128
1 550 M-272
1 137 M-196
1 918 M-242
1 056 M-86
1 958 M-359
1 868 M-150
1 207 M-366
1 250 M-232
1 442 M-99
1 826 M-342
1 671 M-311
1 062 M-293
1 201 M-241
1 165 M-177
1 257 M-371
1 441 M-99
1 565 M-198
1 421 M-139
1 886 M-35
1 625 M-298
1 085 M-306
1 354 M-140
1 074 M-80
1 038 M-115
1 113 A-20
1 791 M-246
1 393 M-210
1 660 M-162
1 857 M-244
1 904 M-278
1 630 M-351
1 940 M-346
1 197 M-153
1 241 M-282
1 273 M-333
1 330 M-175
1 390 M-131
1 195 M-240
1 456 M-290
1 814 M-264
1 713 M-308
1 866 A-32
1 553 M-43
1 010 A-23
1 747 M-317
1 804 M-360
1 125 M-211
1 473 M-61
1 700 M-216
1 755 M-187
1 341 M-29
1 933 M-113
1 340 M-28
1 496 M-109
1 023 M-339
1 289 M-7
1 239 M-282
1 963 M-356
1 149 M-101
1 159 M-89
1 618 M-22
1 515 M-357
1 309 M-328
1 193 M-240
1 444 M-98
1 242 M-234
1 076 A-33
1 577 M-276
1 432 M-66
1 029 A-28
1 032 M-322
1 691 M-313
1 300 M-233
1 016 M-32
1 408 M-283
1 435 M-188
1 622 M-279
1 870 M-271
1 249 M-230
1 502 M-280
1 388 M-131
1 662 M-193
1 757 A-9
1 828 M-342
1 282 M-5
1 604 M-305
1 854 M-341
1 573 M-277
1 793 M-127
1 554 M-43
1 699 M-216
1 058 M-88
1 008 M-225
1 339 M-28
1 902 M-111
1 223 M-55
1 542 M-227
1 115 M-286
1 592 A-27
1 269 M-332
1 316 A-22
1 846 M-63
1 231 M-51
1 768 M-319
1 707 A-17
1 665 M-248
1 268 M-332
1 883 M-235
1 483 M-183
1 856 M-244
1 497 M-109
1 134 M-350
1 955 A-5
1 642 M-76
1 332 M-253
1 181 M-262
1 129 M-181
1 976 M-142
1 947 M-368
1 139 M-269
1 151 M-108
1 718 M-218
1 842 M-172
1 440 M-97
1 052 M-288
1 040 M-363
1 156 M-213
1 229 A-21
1 544 M-227
1 847 M-63
1 844 M-220
1 382 M-70
1 862 M-243
1 077 M-146
1 641 M-207
1 572 M-329
1 780 A-8
1 744 M-85
1 658 M-159
1 927 M-112
1 820 M-173
1 216 M-284
1 643 M-106
1 166 M-361
1 290 M-7
1 233 M-50
1 855 M-341
1 083 M-307
1 824 M-174
1 411 M-64
1 696 M-158
1 304 A-128
1 409 M-283
1 055 M-200
1 102 M-136
1 655 A-15
1 378 M-130
1 520 M-335
1 666 M-248
1 687 M-161
1 693 M-312
1 079 M-146
1 099 M-287
1 307 M-75
1 914 M-370
1 327 M-369
1 539 M-209
1 722 M-189
1 546 A-4
1 133 M-350
1 834 M-4
1 969 M-340
1 368 A-16
1 375 A-7
1 894 M-18
1 297 M-52
1 457 M-290
1 717 M-218
1 004 M-301
1 383 M-309
1 303 M-31
1 065 M-59
1 724 M-189
1 728 M-151
1 801 A-29
1 255 M-371
1 014 M-19
1 672 M-311
1 880 M-2
1 291 A-12
1 863 M-243
1 232 M-51
1 017 M-32
1 256 M-371
1 130 M-181
1 063 M-293
1 417 M-166
1 296 M-52
1 748 M-119
1 475 M-21
1 438 M-97
1 734 M-252
1 745 M-85
1 970 M-340
1 545 A-4
1 593 A-27
1 566 M-198
1 425 M-353
1 897 M-17
1 487 M-163
1 974 M-142
1 627 M-298
1 560 M-72
1 562 M-197
1 575 M-277
1 177 M-261
1 068 M-205
1 271 M-334
1 337 A-24
1 782 M-26
1 198 M-153
1 203 M-48
1 629 M-351
1 199 M-241
1 486 M-163
1 714 M-308
1 095 M-34
1 623 M-279
1 087 M-306
1 917 M-242
1 876 M-347
1 716 M-186
1 227 M-53
1 380 M-70
1 988 M-345
1 517 M-357
1 188 M-239
1 152 M-223
1 374 A-7
1 284 M-6
1 506 M-185
1 711 M-297
1 082 M-307
1 802 M-360
1 116 M-157
1 795 M-206
1 184 M-178
1 395 M-210
1 420 M-139
1 073 M-80
1 628 M-351
1 921 M-338
1 794 M-343
1 114 A-20
1 606 M-195
1 286 M-337
1 596 A-18
1 035 M-231
1 260 M-57
1 415 M-65
1 887 M-219
1 471 M-61
1 829 M-199
1 645 M-106
1 217 M-284
1 146 M-102
1 346 M-194
1 758 A-9
1 708 A-17
1 827 M-342
1 192 M-77
1 351 M-152
1 329 M-175
1 205 M-221
1 338 M-28
1 541 M-209
1 245 M-14
1 749 M-214
1 463 M-323
1 086 M-306
1 164 M-177
1 769 M-364
1 342 M-29
1 601 M-204
1 808 M-182
1 386 A-13
1 204 M-263
1 810 M-182
1 243 M-234
1 454 M-27
1 259 M-56
1 837 M-62
1 117 M-157
1 433 M-66
1 288 M-7
1 813 M-68
1 075 A-33
1 576 M-276
1 885 M-250
1 692 M-313
1 981 M-114
1 224 M-54
1 652 A-14
1 261 M-57
1 512 M-222
1 372 M-180
1 799 A-29
1 686 M-161
1 190 M-77
1 638 A-6
1 042 M-363
1 465 M-323
1 313 A-3
1 414 M-65
1 024 M-339
1 598 A-19
1 246 M-229
1 519 M-335
1 236 M-49
1 547 A-4
1 543 M-227
1 946 M-105
1 777 M-104
1 419 M-166
1 477 M-41
1 840 M-172
1 533 M-120
1 659 M-162
1 270 M-334
1 872 M-273
1 864 A-10
1 154 M-213
1 479 M-41
1 909 M-358
1 823 M-174
1 503 M-125
1 194 M-240
1 735 M-252
1 951 M-352
1 030 A-28
1 583 M-190
1 656 M-159
1 418 M-166
1 690 M-160
1 379 M-130
1 326 M-369
1 929 M-129
1 518 M-335
1 311 M-24
1 157 M-89
1 436 M-188
1 041 M-363
1 673 M-355
1 582 M-190
1 413 M-64
1 853 M-341
1 756 M-187
1 124 M-211
1 168 M-361
1 901 M-111
1 089 M-74
1 581 M-362
1 036 M-231
1 775 M-327
1 373 M-180
1 913 M-370
1 669 M-304
1 301 M-233
1 122 A-1
1 312 M-294
1 653 A-15
1 315 A-22
1 571 M-329
1 039 M-115
1 697 M-310
1 369 A-16
1 858 M-244
1 551 M-192
1 412 M-64
1 265 M-15
1 061 M-293
1 084 M-307
1 825 M-174
1 088 M-74
1 727 M-151
1 240 M-282
1 443 M-99
1 054 M-200
1 778 A-30
1 730 M-217
1 836 M-4
1 185 M-178
1 072 M-60
1 220 M-285
1 377 M-130
1 175 A-25
1 121 A-1
1 353 M-140
1 057 M-86
1 867 M-150
1 919 M-338
1 274 M-333
1 726 M-36
1 644 M-106
1 537 M-291
1 552 M-192
1 983 M-114
1 328 M-369
1 821 M-173
1 564 M-198
1 626 M-298
1 098 M-287
1 219 M-285
1 060 M-88
1 394 M-210
1 384 M-309
1 822 M-173
1 136 M-275
1 607 M-195
1 153 M-223
1 905 M-278
1 616 M-22
1 331 M-175
1 066 M-59
1 580 M-362
1 907 M-358
1 196 M-153
1 476 M-21
1 941 M-346
1 548 M-272
1 698 M-216
1 439 M-97
1 206 M-221
1 916 A-2
1 305 A-128
1 803 M-360
1 103 M-136
1 251 M-232
1 766 M-84
1 915 A-2
1 299 M-233
1 563 M-197
1 848 M-63
1 986 M-249
1 694 M-312
1 957 M-359
1 977 M-143
1 845 M-220
1 090 M-74
1 488 M-164
1 302 M-31
1 839 M-62
1 422 M-139
1 761 M-118
1 640 M-207
1 774 M-330
1 0 783 M-412
1 0 784 M-412
1 0 785 M-412
1 0 786 M-413
1 0 787 M-413
1 0 788 M-413
1 0 805 M-414
1 0 806 M-414
1 0 807 M-414
1 0 817 M-415
1 0 818 M-415
1 0 819 M-415
1 0 831 M-416
1 0 832 M-416
1 0 833 M-416
1 0 796 M-318
1 0 797 M-318
1 0 798 M-318";
void Main()
{
var mappings = text.Replace("\r\n", "\r").Split('\r')
.Where(r => !string.IsNullOrEmpty(r) && r.Split('\t').Length == 4) // There must be exactly 4 columns in each row of data
.Select(x =>
{
var column = x.Split('\t');
return new CaseTypeFamilyMapping(column[0], column[1], column[2], column[3], 0);
});
mappings.Where(m => m != null).OrderBy(m => m.SkipICD).ThenBy(m => m.ICD10Code).ThenBy(m => m.MSDRGCode).ThenBy(m => m.GlobalID).Dump();
}
public class CaseTypeFamilyMapping
{
public bool SkipICD { get; set; }
public string ICD10Code { get; set; }
public string MSDRGCode { get; set; }
public string GlobalID { get; set; }
public int CaseTypeFamilyId { get; set; }
public CaseTypeFamilyMapping(string skipICD, string icd10Code, string msdrgCode, string globalID, int caseTypeFamilyId)
{
if (!bool.TryParse(skipICD, out bool skipped)) skipped = false;
SkipICD = (skipICD == "1");
ICD10Code = icd10Code;
MSDRGCode = msdrgCode;
GlobalID = globalID;
//CaseTypeFamilyId = caseTypeFamilyId;
}
}
@@ -0,0 +1,134 @@
<Query Kind="Statements">
<Connection>
<ID>77b65bea-e766-4e3c-a1ed-c4c2534b6019</ID>
<Persist>true</Persist>
<Server>D0001-SQL-01.sdt.local</Server>
<Database>jazz dev master</Database>
<ShowServer>true</ShowServer>
</Connection>
<Reference>&lt;ProgramFilesX64&gt;\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics\Newtonsoft.Json.dll</Reference>
<NuGetReference>Amazon.Lambda.S3Events</NuGetReference>
<NuGetReference>AWSSDK.Core</NuGetReference>
<NuGetReference>AWSSDK.S3</NuGetReference>
<Namespace>Amazon</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy.ActionIdentifiers</Namespace>
<Namespace>Amazon.Internal</Namespace>
<Namespace>Amazon.Lambda.S3Events</Namespace>
<Namespace>Amazon.MissingTypes</Namespace>
<Namespace>Amazon.Runtime</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement.Internal</Namespace>
<Namespace>Amazon.Runtime.EventStreams</Namespace>
<Namespace>Amazon.Runtime.EventStreams.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal.Auth</Namespace>
<Namespace>Amazon.Runtime.Internal.Settings</Namespace>
<Namespace>Amazon.Runtime.Internal.Transform</Namespace>
<Namespace>Amazon.Runtime.Internal.Util</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces.Internal</Namespace>
<Namespace>Amazon.S3</Namespace>
<Namespace>Amazon.S3.Encryption</Namespace>
<Namespace>Amazon.S3.Encryption.Internal</Namespace>
<Namespace>Amazon.S3.Internal</Namespace>
<Namespace>Amazon.S3.IO</Namespace>
<Namespace>Amazon.S3.Model</Namespace>
<Namespace>Amazon.S3.Model.Internal.MarshallTransformations</Namespace>
<Namespace>Amazon.S3.Transfer</Namespace>
<Namespace>Amazon.S3.Util</Namespace>
<Namespace>Amazon.Util</Namespace>
<Namespace>Amazon.Util.Internal</Namespace>
<Namespace>Amazon.Util.Internal.PlatformServices</Namespace>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>Newtonsoft.Json.Converters</Namespace>
<Namespace>Newtonsoft.Json.Linq</Namespace>
<Namespace>Newtonsoft.Json.Schema</Namespace>
<Namespace>Newtonsoft.Json.Serialization</Namespace>
<Namespace>System</Namespace>
<Namespace>System.ComponentModel.Composition</Namespace>
<Namespace>System.ComponentModel.Composition.Hosting</Namespace>
<Namespace>System.ComponentModel.Composition.Primitives</Namespace>
<Namespace>System.ComponentModel.Composition.ReflectionModel</Namespace>
<Namespace>System.Diagnostics</Namespace>
<Namespace>System.Diagnostics.Tracing</Namespace>
<Namespace>System.IO.Compression</Namespace>
<Namespace>System.Net.Http</Namespace>
<Namespace>System.Net.Http.Headers</Namespace>
<Namespace>System.Numerics</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1.Utilities</Namespace>
<Namespace>ThirdParty.BouncyCastle.Math</Namespace>
<Namespace>ThirdParty.BouncyCastle.OpenSsl</Namespace>
<Namespace>ThirdParty.BouncyCastle.Utilities.IO.Pem</Namespace>
<Namespace>ThirdParty.Ionic.Zlib</Namespace>
<Namespace>ThirdParty.Json.LitJson</Namespace>
<Namespace>ThirdParty.MD5</Namespace>
</Query>
var grps = CaseTypeFamilyMappingICD10s
.Where(ctf => ctf.CaseTypeFamilyVersionID == 2)
.GroupBy(ctf => new { ctf.CaseTypeFamilyID, ctf.ICD10Code })
.OrderBy(grp => grp.Key.CaseTypeFamilyID)
.ThenBy(grp => grp.Key.ICD10Code)
.Select(grp => new { grp.Key.CaseTypeFamilyID, grp.Key.ICD10Code, count = grp.Count() });
var grpBreak = 100000;
var pageSize = 10000;
foreach (var grp in grps)
{
grp.Dump();
if (grp.count > grpBreak)
{
var subgrps = CaseTypeFamilyMappingICD10s
.Where(ctf => ctf.CaseTypeFamilyVersionID == 2)
.GroupBy(ctf => new { ctf.CaseTypeFamilyID, ctf.ICD10Code, ctf.MSDRGCode })
.OrderBy(subgrp => subgrp.Key.CaseTypeFamilyID)
.ThenBy(subgrp => subgrp.Key.ICD10Code)
.ThenBy(subgrp => subgrp.Key.MSDRGCode)
.Select(subgrp => new { subgrp.Key.CaseTypeFamilyID, subgrp.Key.ICD10Code, subgrp.Key.MSDRGCode, count = subgrp.Count() });
foreach (var subgrp in subgrps)
{
subgrp.Dump();
var subgrpremove = from mapping in CaseTypeFamilyMappingICD10s
where mapping.CaseTypeFamilyID == subgrp.CaseTypeFamilyID
&& mapping.ICD10Code == subgrp.ICD10Code
&& mapping.MSDRGCode == subgrp.MSDRGCode
&& mapping.CaseTypeFamilyVersionID == 2
select mapping;
if (subgrpremove.Any())
{
var pages = ((subgrp.count + (pageSize - 1)) / pageSize);
Enumerable.Range(0, pages).ToList()
.ForEach(page =>
{
$"{(page + 1)} of {pages}".Dump();
var workSet = subgrpremove.Skip(page * pageSize).Take(pageSize).ToList();
CaseTypeFamilyMappingICD10s.DeleteAllOnSubmit(workSet);
SubmitChanges();
});
}
}
continue;
}
var remove = from mapping in CaseTypeFamilyMappingICD10s
where mapping.CaseTypeFamilyID == grp.CaseTypeFamilyID
&& mapping.ICD10Code == grp.ICD10Code
&& mapping.CaseTypeFamilyVersionID == 2
select mapping;
if (remove.Any())
{
var pages = ((grp.count + (pageSize - 1)) / pageSize);
Enumerable.Range(0, pages).ToList()
.ForEach(page =>
{
$"{(page + 1)} of {pages}".Dump();
var workSet = remove.Skip(page * pageSize).Take(pageSize).ToList();
CaseTypeFamilyMappingICD10s.DeleteAllOnSubmit(workSet);
SubmitChanges();
});
}
}