Template
185 lines
11 KiB
C#
185 lines
11 KiB
C#
using Strata.DecisionSupport.Biz.Encounters;
|
|
using Strata.DecisionSupport.Biz.Parameters;
|
|
using Strata.DecisionSupport.Biz.Services;
|
|
using Strata.DecisionSupport.Models.Encounters;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace Strata.DecisionSupport.Biz.Test.Unit
|
|
{
|
|
public static class SnowflakeTestCases
|
|
{
|
|
public static string LineReader(this string query)
|
|
=> string.Join("", query.Split(Environment.NewLine)
|
|
.Select((l, i) => $"{i:G}".PadLeft(3, ' ') + ": " + l + Environment.NewLine));
|
|
|
|
public static string Query<T>(T queryInfo) where T : class
|
|
{
|
|
var args = queryInfo is IWithArgs hasArgs ? hasArgs.Args() : [];
|
|
var globalId = queryInfo is IWithGlobalId hasGlobalId ? hasGlobalId.GlobalId() : "";
|
|
var patientSpecific = queryInfo is IWithPatientSpecific hasPatientSpecific ? hasPatientSpecific.PatientSpecific() : false;
|
|
var first = 0; var rows = 1000;
|
|
if (queryInfo is EncounterQueryInfo encounterQueryInfo)
|
|
{
|
|
args = encounterQueryInfo.Args("sl.serviceLineid", "INNER JOIN fw.DimServiceLine sl on sl.ServiceLineId = OBJ.ServiceLineId");
|
|
}
|
|
else if (queryInfo is EncounterChargeQueryInfo encounterChargeQueryInfo)
|
|
{
|
|
first = encounterChargeQueryInfo.First;
|
|
rows = encounterChargeQueryInfo.Rows;
|
|
}
|
|
else if (queryInfo is VariationEncounterChargeQueryInfo variationEncounterChargeQueryInfo)
|
|
{
|
|
first = variationEncounterChargeQueryInfo.First;
|
|
rows = variationEncounterChargeQueryInfo.Rows;
|
|
}
|
|
return typeof(T).Name switch
|
|
{
|
|
nameof(AllChargeQueryInfo) => EncounterQueries.AllChargeInfoQuery(args),
|
|
nameof(ChargeQueryInfo) => EncounterQueries.ChargeInfoQuery(args),
|
|
nameof(DepartmentEncounterUnitOfServiceQueryInfo) => EncounterQueries.DepartmentEncounterUnitOfServiceQuery(globalId, args),
|
|
nameof(EncounterChargeQueryInfo) => EncounterQueries.EncounterChargeQuery(first, rows, args),
|
|
nameof(EncounterCostQueryInfo) => EncounterQueries.EncounterCostInfoQuery(globalId, patientSpecific, args),
|
|
nameof(EncounterQueryInfo) => EncounterQueries.EncounterInfoQuery(globalId, args),
|
|
nameof(EncounterUnitOfServiceQueryInfo) => EncounterQueries.EncounterUnitOfServiceQuery(args),
|
|
nameof(LOSOpportunityQueryInfo) => EncounterQueries.LOSOpportunityInfoQuery(args),
|
|
nameof(VariationEncounterChargeQueryInfo) => EncounterQueries.VariationEncounterChargeQuery(first, rows, args),
|
|
_ => $""
|
|
};
|
|
}
|
|
|
|
//Revisit these test cases for department rollups
|
|
//If we're validating the query text there shouldn't be any string manipulation in here
|
|
public static IEnumerable<TestCaseData> TestCases()
|
|
{
|
|
var assembly = AppDomain.CurrentDomain.GetAssemblies()
|
|
.SingleOrDefault(a => a.GetName().Name.Equals("Strata.DecisionSupport.Biz", StringComparison.OrdinalIgnoreCase));
|
|
var thisAssembly = Assembly.GetExecutingAssembly();
|
|
var resourceNames = assembly.GetManifestResourceNames()
|
|
.Where(r => r.EndsWith(".sql")).ToList();
|
|
var testCases = assembly.GetManifestResourceNames()
|
|
.Where(r => r.EndsWith(".json")).ToList();
|
|
|
|
foreach (var resource in resourceNames)
|
|
{
|
|
var name = resource.Split('.').TakeLast(2).First();
|
|
var globalId = string.Empty;
|
|
var testName = "{c}" + name;
|
|
switch (name)
|
|
{
|
|
case "Billing":
|
|
case "WithEncounterUnitOfServiceQuery":
|
|
break;
|
|
case "AllChargeInfoQuery":
|
|
yield return new TestCaseData(new AllChargeInfo(), new AllChargeQueryInfo(
|
|
Guid.NewGuid(),
|
|
[1, 2]
|
|
), null).SetName(testName);
|
|
break;
|
|
case "ChargeInfoQuery":
|
|
yield return new TestCaseData(new ChargeInfo(), new ChargeQueryInfo(
|
|
Guid.NewGuid(),
|
|
2,
|
|
[1, 2],
|
|
Guid.NewGuid()
|
|
), new Func<IEnumerable<ChargeInfo>, IEnumerable<ChargeInfo>>(x => x.OrderBy(y => y.ChargeCodeId)
|
|
)).SetName(testName);
|
|
break;
|
|
case "DepartmentEncounterUnitOfServiceDepartmentRollupQuery":
|
|
break;
|
|
case "DepartmentEncounterUnitOfServiceEntityQuery":
|
|
case "DepartmentEncounterUnitOfServiceLocationQuery":
|
|
globalId = Regex.Replace(name, ".*UnitOfService(.*)Query", "$1")
|
|
.Replace("DepartmentRollup", "DepartmentRollup1")
|
|
.Replace("Entity", "");
|
|
yield return new TestCaseData(new DepartmentEncounterUnitOfService(), new DepartmentEncounterUnitOfServiceQueryInfo
|
|
(
|
|
globalId,
|
|
24,
|
|
[2L]
|
|
), null).SetName(testName);
|
|
break;
|
|
case "EncounterChargeQuery":
|
|
yield return new TestCaseData(new EncounterChargeInfo(), new EncounterChargeQueryInfo(
|
|
false, false,
|
|
false, false,
|
|
false, true,
|
|
Guid.NewGuid(), [1]), null)
|
|
.SetName(testName);
|
|
yield return new TestCaseData(new EncounterChargeInfo(), new EncounterChargeQueryInfo(
|
|
true, false,
|
|
true, false,
|
|
true, true,
|
|
Guid.NewGuid(), [1]), null)
|
|
.SetName($"{testName} hasManufacturer hasSupply usingCustomDimension");
|
|
yield return new TestCaseData(new EncounterChargeInfo(), new EncounterChargeQueryInfo(
|
|
true, true,
|
|
true, true,
|
|
true, true,
|
|
Guid.NewGuid(), [1]), null)
|
|
.SetName($"{testName} hasManufacturer Inferred hasSupply Inferred usingCustomDimension")
|
|
.Ignore("Temporarily ignored: investigate manufacturer/supply table logic. This test always fails due to table not found.");
|
|
break;
|
|
case "EncounterInfoDepartmentRollupQuery":
|
|
break;
|
|
case "EncounterInfoEntityQuery":
|
|
case "EncounterInfoLocationQuery":
|
|
globalId = Regex.Replace(name, ".*Info(.*)Query", "$1")
|
|
.Replace("DepartmentRollup", "DepartmentRollup1")
|
|
.Replace("Entity", "");
|
|
var skipCaseTypeCategories = new Models.Queries.CaseTypeCategory[] { Models.Queries.CaseTypeCategory.ExplorationPopulation };
|
|
foreach (var caseType in Enum.GetValues<Models.Queries.CaseTypeCategory>().Where(x => !skipCaseTypeCategories.Contains(x)))
|
|
{
|
|
yield return new TestCaseData(new EncounterInfo(), new EncounterQueryInfo(caseType, 1,
|
|
new DateTime(2023, 1, 1), new DateTime(2024, 1, 1), globalId, Guid.NewGuid(), 24, [1]), null)
|
|
.SetName($"{testName} {Enum.GetName(caseType).ToLower()}");
|
|
}
|
|
break;
|
|
case "EncounterSpecificCostInfoDepartmentRollupQuery":
|
|
case "EncounterStaticCostInfoDepartmentRollupQuery":
|
|
break;
|
|
case "EncounterSpecificCostInfoEntityQuery":
|
|
case "EncounterSpecificCostInfoLocationQuery":
|
|
case "EncounterStaticCostInfoEntityQuery":
|
|
case "EncounterStaticCostInfoLocationQuery":
|
|
var isPatientSpecific = name.Contains("Specific");
|
|
globalId = Regex.Replace(name, ".*CostInfo(.*)Query", "$1")
|
|
.Replace("DepartmentRollup", "DepartmentRollup1")
|
|
.Replace("Entity", "");
|
|
yield return new TestCaseData(new EncounterCostInfo(), new EncounterCostQueryInfo(isPatientSpecific, Guid.NewGuid(), string.Empty, globalId, [1L]), null)
|
|
.SetName(testName);
|
|
break;
|
|
case "EncounterUnitOfServiceQuery":
|
|
yield return new TestCaseData(new EncounterUnitOfService(), new EncounterUnitOfServiceQueryInfo(24, [1L, 2L]), null)
|
|
.SetName(testName);
|
|
break;
|
|
case "LOSOpportunityInfoQuery":
|
|
yield return new TestCaseData(new LOSOpportunityInfo(), new LOSOpportunityQueryInfo(Guid.NewGuid(), 24, 2), null)
|
|
.SetName(testName);
|
|
break;
|
|
case "VariationEncounterChargeQuery":
|
|
yield return new TestCaseData(new VariationEncounterChargeInfo(), new VariationEncounterChargeQueryInfo(false, false,
|
|
false, false,
|
|
false, true, [Guid.NewGuid(), Guid.NewGuid()], [1, 2], 1, 1000), null)
|
|
.SetName(testName);
|
|
yield return new TestCaseData(new VariationEncounterChargeInfo(), new VariationEncounterChargeQueryInfo(true, false,
|
|
true, false,
|
|
true, true, [Guid.NewGuid(), Guid.NewGuid()], [1, 2], 1, 1000), null)
|
|
.SetName($"{testName} hasManufacturer hasSupply usingCustomDimension");
|
|
yield return new TestCaseData(new VariationEncounterChargeInfo(), new VariationEncounterChargeQueryInfo(true, true,
|
|
true, true,
|
|
true, true, [Guid.NewGuid(), Guid.NewGuid()], [1, 2], 1, 1000), null)
|
|
.SetName($"{testName} hasManufacturer Inferred hasSupply Inferred usingCustomDimension")
|
|
.Ignore("Temporarily ignored: investigate manufacturer/supply table logic. This test always fails due to table not found."); ;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
} |