using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Strata.ContinuousImprovement.Biz.Test.Integration.SnowflakeIntegrationTests { public static class StrategicOpportunityQueryConstants { public static readonly string TrackingSelectSql = @"SELECT ""dsspesEncounterId"", ""dsspesDischargeDateTime"", ""dsspesEntityID"", ""dsspesPhysicianId"", ""dsspesPrimaryServiceLineId"", ""dsspesCPTCodeCaseTypeFamilyId"", ""dsspesMSDRGCaseTypeFamilyId"", ""dsspesAPRDRGCaseTypeFamilyId"", ""pblidDepartmentId"", ""physPrimaryPhysicianSpecialtyId"", ""ccChargeCodeID"", ""ccCostDriver"", ""encounterPatientTypeRollupPatientTypeRollup"", ZEROIFNULL(""Units"") AS ""Units"", ZEROIFNULL(""Cost"") AS ""Cost"" FROM ( SELECT ""dsspesEncounterId"", ""dsspesDischargeDateTime"", ""dsspesEntityID"", ""dsspesPhysicianId"", ""dsspesPrimaryServiceLineId"", ""dsspesCPTCodeCaseTypeFamilyId"", ""dsspesMSDRGCaseTypeFamilyId"", ""dsspesAPRDRGCaseTypeFamilyId"", ""pblidDepartmentId"", ""physPrimaryPhysicianSpecialtyId"", ""ccChargeCodeID"", ""ccCostDriver"", ""encounterPatientTypeRollupPatientTypeRollup"", SUM(""Units"") AS ""Units"", SUM(""Cost"") AS ""Cost"" FROM ( SELECT DSSPES.encounterid AS ""dsspesEncounterId"", DSSPES.dischargedatetime AS ""dsspesDischargeDateTime"", DSSPES.entityid AS ""dsspesEntityID"", DSSPES.primaryphysicianid AS ""dsspesPhysicianId"", DSSPES.servicelineid AS ""dsspesPrimaryServiceLineId"", DSSPES.cptcodecasetypefamilyid AS ""dsspesCPTCodeCaseTypeFamilyId"", DSSPES.msdrgcasetypefamilyid AS ""dsspesMSDRGCaseTypeFamilyId"", DSSPES.aprdrgcasetypefamilyid AS ""dsspesAPRDRGCaseTypeFamilyId"", PBLID.departmentid AS ""pblidDepartmentId"", PHYSPRIMARY.physicianspecialtyid AS ""physPrimaryPhysicianSpecialtyId"", CC.chargecodeid AS ""ccChargeCodeID"", IFNULL(CC.costdriver::TEXT, '') AS ""ccCostDriver"", IFNULL(ENCOUNTERPATIENTTYPEROLLUP.patienttyperollup::TEXT, '') AS ""encounterPatientTypeRollupPatientTypeRollup"", NULL AS ""Cost"", SUM(PBLID.unitsofservice) AS ""Units"" FROM dss.FactPatientBillingLineItemDetail AS PBLID RIGHT JOIN clientdss.FactPatientEncounterSummary AS DSSPES ON DSSPES.encounterid = PBLID.encounterid LEFT JOIN dss.FactPatientEncounterClinicalIndicator AS DSSPECI ON DSSPECI.encounterid = PBLID.encounterid LEFT JOIN CCI.VIEWENCOUNTERPATIENTTYPEROLLUP AS ENCOUNTERPATIENTTYPEROLLUP ON ENCOUNTERPATIENTTYPEROLLUP.encounterid = PBLID.encounterid INNER JOIN FW.DIMCHARGECODE AS CC ON CC.chargecodeid = PBLID.chargecodeid INNER JOIN DSS.DIMPHYSICIAN AS PHYSPRIMARY ON PHYSPRIMARY.physicianid = DSSPES.primaryphysicianid WHERE ((DSSPES.dischargedatetime >= :dischargedatetime_Start_0 AND DSSPES.dischargedatetime <= :dischargedatetime_End_1) AND DSSPECI.clinicalindicatorid = :clinicalindicatorid_2) GROUP BY ""dsspesEncounterId"", ""dsspesDischargeDateTime"", ""dsspesEntityID"", ""dsspesPhysicianId"", ""dsspesPrimaryServiceLineId"", ""dsspesCPTCodeCaseTypeFamilyId"", ""dsspesMSDRGCaseTypeFamilyId"", ""dsspesAPRDRGCaseTypeFamilyId"", ""pblidDepartmentId"", ""physPrimaryPhysicianSpecialtyId"", ""ccChargeCodeID"", ""ccCostDriver"", ""encounterPatientTypeRollupPatientTypeRollup"" UNION ALL SELECT DSSPES.encounterid AS ""dsspesEncounterId"", DSSPES.dischargedatetime AS ""dsspesDischargeDateTime"", DSSPES.entityid AS ""dsspesEntityID"", DSSPES.primaryphysicianid AS ""dsspesPhysicianId"", DSSPES.servicelineid AS ""dsspesPrimaryServiceLineId"", DSSPES.cptcodecasetypefamilyid AS ""dsspesCPTCodeCaseTypeFamilyId"", DSSPES.msdrgcasetypefamilyid AS ""dsspesMSDRGCaseTypeFamilyId"", DSSPES.aprdrgcasetypefamilyid AS ""dsspesAPRDRGCaseTypeFamilyId"", PBLID.departmentid AS ""pblidDepartmentId"", PHYSPRIMARY.physicianspecialtyid AS ""physPrimaryPhysicianSpecialtyId"", CC.chargecodeid AS ""ccChargeCodeID"", IFNULL(CC.costdriver::TEXT, '') AS ""ccCostDriver"", IFNULL(ENCOUNTERPATIENTTYPEROLLUP.patienttyperollup::TEXT, '') AS ""encounterPatientTypeRollupPatientTypeRollup"", SUM(COSTDETAIL.variabledirectcost) AS ""Cost"", NULL AS ""Units"" FROM dss.FactPatientCostDetail AS COSTDETAIL RIGHT JOIN dss.FactPatientBillingLineItemDetail AS PBLID ON PBLID.rowid = COSTDETAIL.pblidrowid RIGHT JOIN clientdss.FactPatientEncounterSummary AS DSSPES ON DSSPES.encounterid = PBLID.encounterid LEFT JOIN dss.FactPatientEncounterClinicalIndicator AS DSSPECI ON DSSPECI.encounterid = PBLID.encounterid LEFT JOIN CCI.VIEWENCOUNTERPATIENTTYPEROLLUP AS ENCOUNTERPATIENTTYPEROLLUP ON ENCOUNTERPATIENTTYPEROLLUP.encounterid = PBLID.encounterid INNER JOIN FW.DIMCHARGECODE AS CC ON CC.chargecodeid = PBLID.chargecodeid INNER JOIN DSS.DIMPHYSICIAN AS PHYSPRIMARY ON PHYSPRIMARY.physicianid = DSSPES.primaryphysicianid WHERE ((DSSPES.dischargedatetime >= :dischargedatetime_Start_3 AND DSSPES.dischargedatetime <= :dischargedatetime_End_4) AND DSSPECI.clinicalindicatorid = :clinicalindicatorid_5) GROUP BY ""dsspesEncounterId"", ""dsspesDischargeDateTime"", ""dsspesEntityID"", ""dsspesPhysicianId"", ""dsspesPrimaryServiceLineId"", ""dsspesCPTCodeCaseTypeFamilyId"", ""dsspesMSDRGCaseTypeFamilyId"", ""dsspesAPRDRGCaseTypeFamilyId"", ""pblidDepartmentId"", ""physPrimaryPhysicianSpecialtyId"", ""ccChargeCodeID"", ""ccCostDriver"", ""encounterPatientTypeRollupPatientTypeRollup"" ) GROUP BY ""dsspesEncounterId"", ""dsspesDischargeDateTime"", ""dsspesEntityID"", ""dsspesPhysicianId"", ""dsspesPrimaryServiceLineId"", ""dsspesCPTCodeCaseTypeFamilyId"", ""dsspesMSDRGCaseTypeFamilyId"", ""dsspesAPRDRGCaseTypeFamilyId"", ""pblidDepartmentId"", ""physPrimaryPhysicianSpecialtyId"", ""ccChargeCodeID"", ""ccCostDriver"", ""encounterPatientTypeRollupPatientTypeRollup"" ) ORDER BY ""dsspesEncounterId"" ASC NULLS FIRST, ""dsspesDischargeDateTime"" ASC NULLS FIRST, ""dsspesEntityID"" ASC NULLS FIRST, ""dsspesPhysicianId"" ASC NULLS FIRST, ""dsspesPrimaryServiceLineId"" ASC NULLS FIRST, ""dsspesCPTCodeCaseTypeFamilyId"" ASC NULLS FIRST, ""dsspesMSDRGCaseTypeFamilyId"" ASC NULLS FIRST, ""dsspesAPRDRGCaseTypeFamilyId"" ASC NULLS FIRST, ""pblidDepartmentId"" ASC NULLS FIRST, ""physPrimaryPhysicianSpecialtyId"" ASC NULLS FIRST, ""ccChargeCodeID"" ASC NULLS FIRST, ""ccCostDriver"" ASC NULLS FIRST, ""encounterPatientTypeRollupPatientTypeRollup"" ASC NULLS FIRST "; // SQL returned by BuildSqlQuery for the measure detail query (PopulateMeasureDetails, line 215). // Uses real column names from clientdss.FactPatientEncounterSummary and dss.FactPatientBillingLineItemDetail // that exist in the test client's Snowflake database. public static readonly string MeasureSelectSql = @"SELECT ""DischargeDateTime"", ZEROIFNULL(""Value"") AS ""Value"" FROM ( SELECT ""DischargeDateTime"", SUM(""Value"") AS ""Value"" FROM ( SELECT DSSPES.dischargedatetime AS ""DischargeDateTime"", SUM(PBLID.unitsofservice) AS ""Value"" FROM dss.FactPatientBillingLineItemDetail AS PBLID RIGHT JOIN clientdss.FactPatientEncounterSummary AS DSSPES ON DSSPES.encounterid = PBLID.encounterid WHERE (DSSPES.dischargedatetime >= :dischargedatetime_Start_0 AND DSSPES.dischargedatetime <= :dischargedatetime_End_1) GROUP BY ""DischargeDateTime"" ) GROUP BY ""DischargeDateTime"" ) ORDER BY ""DischargeDateTime"" ASC NULLS FIRST "; // SQL for the tracking merge when opportunity uses an ExplorationPopulation instead of PatientPopulationHPath. // Contains LEFT JOIN CCI.FACTEXPLORATIONPOPULATIONENCOUNTER which ApplyExplorationFilters replaces // with an INNER JOIN subquery at runtime. public static readonly string ExplorationTrackingSelectSql = @"SELECT ""dsspesEncounterId"", ""dsspesDischargeDateTime"", ""dsspesEntityID"", ""dsspesPhysicianId"", ""dsspesPrimaryServiceLineId"", ""dsspesCPTCodeCaseTypeFamilyId"", ""dsspesMSDRGCaseTypeFamilyId"", ""dsspesAPRDRGCaseTypeFamilyId"", ""pblidDepartmentId"", ""physPrimaryPhysicianSpecialtyId"", ""ccChargeCodeID"", ""ccCostDriver"", ""encounterPatientTypeRollupPatientTypeRollup"", ZEROIFNULL(""Units"") AS ""Units"", ZEROIFNULL(""Cost"") AS ""Cost"" FROM ( SELECT ""dsspesEncounterId"", ""dsspesDischargeDateTime"", ""dsspesEntityID"", ""dsspesPhysicianId"", ""dsspesPrimaryServiceLineId"", ""dsspesCPTCodeCaseTypeFamilyId"", ""dsspesMSDRGCaseTypeFamilyId"", ""dsspesAPRDRGCaseTypeFamilyId"", ""pblidDepartmentId"", ""physPrimaryPhysicianSpecialtyId"", ""ccChargeCodeID"", ""ccCostDriver"", ""encounterPatientTypeRollupPatientTypeRollup"", SUM(""Units"") AS ""Units"", SUM(""Cost"") AS ""Cost"" FROM ( SELECT DSSPES.encounterid AS ""dsspesEncounterId"", DSSPES.dischargedatetime AS ""dsspesDischargeDateTime"", DSSPES.entityid AS ""dsspesEntityID"", DSSPES.primaryphysicianid AS ""dsspesPhysicianId"", DSSPES.servicelineid AS ""dsspesPrimaryServiceLineId"", DSSPES.cptcodecasetypefamilyid AS ""dsspesCPTCodeCaseTypeFamilyId"", DSSPES.msdrgcasetypefamilyid AS ""dsspesMSDRGCaseTypeFamilyId"", DSSPES.aprdrgcasetypefamilyid AS ""dsspesAPRDRGCaseTypeFamilyId"", PBLID.departmentid AS ""pblidDepartmentId"", PHYSPRIMARY.physicianspecialtyid AS ""physPrimaryPhysicianSpecialtyId"", CC.chargecodeid AS ""ccChargeCodeID"", IFNULL(CC.costdriver::TEXT, '') AS ""ccCostDriver"", IFNULL(ENCOUNTERPATIENTTYPEROLLUP.patienttyperollup::TEXT, '') AS ""encounterPatientTypeRollupPatientTypeRollup"", NULL AS ""Cost"", SUM(PBLID.unitsofservice) AS ""Units"" FROM dss.FactPatientBillingLineItemDetail AS PBLID RIGHT JOIN clientdss.FactPatientEncounterSummary AS DSSPES ON DSSPES.encounterid = PBLID.encounterid LEFT JOIN CCI.FACTEXPLORATIONPOPULATIONENCOUNTER AS EXPLORATIONPOPULATIONENCOUNTER ON EXPLORATIONPOPULATIONENCOUNTER.encounterid = PBLID.encounterid LEFT JOIN CCI.VIEWENCOUNTERPATIENTTYPEROLLUP AS ENCOUNTERPATIENTTYPEROLLUP ON ENCOUNTERPATIENTTYPEROLLUP.encounterid = PBLID.encounterid INNER JOIN FW.DIMCHARGECODE AS CC ON CC.chargecodeid = PBLID.chargecodeid INNER JOIN DSS.DIMPHYSICIAN AS PHYSPRIMARY ON PHYSPRIMARY.physicianid = DSSPES.primaryphysicianid WHERE ((DSSPES.dischargedatetime >= :dischargedatetime_Start_0 AND DSSPES.dischargedatetime <= :dischargedatetime_End_1) AND EXPLORATIONPOPULATIONENCOUNTER.explorationpopulationid = :explorationpopulationid_2) GROUP BY ""dsspesEncounterId"", ""dsspesDischargeDateTime"", ""dsspesEntityID"", ""dsspesPhysicianId"", ""dsspesPrimaryServiceLineId"", ""dsspesCPTCodeCaseTypeFamilyId"", ""dsspesMSDRGCaseTypeFamilyId"", ""dsspesAPRDRGCaseTypeFamilyId"", ""pblidDepartmentId"", ""physPrimaryPhysicianSpecialtyId"", ""ccChargeCodeID"", ""ccCostDriver"", ""encounterPatientTypeRollupPatientTypeRollup"" UNION ALL SELECT DSSPES.encounterid AS ""dsspesEncounterId"", DSSPES.dischargedatetime AS ""dsspesDischargeDateTime"", DSSPES.entityid AS ""dsspesEntityID"", DSSPES.primaryphysicianid AS ""dsspesPhysicianId"", DSSPES.servicelineid AS ""dsspesPrimaryServiceLineId"", DSSPES.cptcodecasetypefamilyid AS ""dsspesCPTCodeCaseTypeFamilyId"", DSSPES.msdrgcasetypefamilyid AS ""dsspesMSDRGCaseTypeFamilyId"", DSSPES.aprdrgcasetypefamilyid AS ""dsspesAPRDRGCaseTypeFamilyId"", PBLID.departmentid AS ""pblidDepartmentId"", PHYSPRIMARY.physicianspecialtyid AS ""physPrimaryPhysicianSpecialtyId"", CC.chargecodeid AS ""ccChargeCodeID"", IFNULL(CC.costdriver::TEXT, '') AS ""ccCostDriver"", IFNULL(ENCOUNTERPATIENTTYPEROLLUP.patienttyperollup::TEXT, '') AS ""encounterPatientTypeRollupPatientTypeRollup"", SUM(COSTDETAIL.variabledirectcost) AS ""Cost"", NULL AS ""Units"" FROM dss.FactPatientCostDetail AS COSTDETAIL RIGHT JOIN dss.FactPatientBillingLineItemDetail AS PBLID ON PBLID.rowid = COSTDETAIL.pblidrowid RIGHT JOIN clientdss.FactPatientEncounterSummary AS DSSPES ON DSSPES.encounterid = PBLID.encounterid LEFT JOIN CCI.FACTEXPLORATIONPOPULATIONENCOUNTER AS EXPLORATIONPOPULATIONENCOUNTER ON EXPLORATIONPOPULATIONENCOUNTER.encounterid = PBLID.encounterid LEFT JOIN CCI.VIEWENCOUNTERPATIENTTYPEROLLUP AS ENCOUNTERPATIENTTYPEROLLUP ON ENCOUNTERPATIENTTYPEROLLUP.encounterid = PBLID.encounterid INNER JOIN FW.DIMCHARGECODE AS CC ON CC.chargecodeid = PBLID.chargecodeid INNER JOIN DSS.DIMPHYSICIAN AS PHYSPRIMARY ON PHYSPRIMARY.physicianid = DSSPES.primaryphysicianid WHERE ((DSSPES.dischargedatetime >= :dischargedatetime_Start_3 AND DSSPES.dischargedatetime <= :dischargedatetime_End_4) AND EXPLORATIONPOPULATIONENCOUNTER.explorationpopulationid = :explorationpopulationid_5) GROUP BY ""dsspesEncounterId"", ""dsspesDischargeDateTime"", ""dsspesEntityID"", ""dsspesPhysicianId"", ""dsspesPrimaryServiceLineId"", ""dsspesCPTCodeCaseTypeFamilyId"", ""dsspesMSDRGCaseTypeFamilyId"", ""dsspesAPRDRGCaseTypeFamilyId"", ""pblidDepartmentId"", ""physPrimaryPhysicianSpecialtyId"", ""ccChargeCodeID"", ""ccCostDriver"", ""encounterPatientTypeRollupPatientTypeRollup"" ) GROUP BY ""dsspesEncounterId"", ""dsspesDischargeDateTime"", ""dsspesEntityID"", ""dsspesPhysicianId"", ""dsspesPrimaryServiceLineId"", ""dsspesCPTCodeCaseTypeFamilyId"", ""dsspesMSDRGCaseTypeFamilyId"", ""dsspesAPRDRGCaseTypeFamilyId"", ""pblidDepartmentId"", ""physPrimaryPhysicianSpecialtyId"", ""ccChargeCodeID"", ""ccCostDriver"", ""encounterPatientTypeRollupPatientTypeRollup"" ) ORDER BY ""dsspesEncounterId"" ASC NULLS FIRST, ""dsspesDischargeDateTime"" ASC NULLS FIRST, ""dsspesEntityID"" ASC NULLS FIRST, ""dsspesPhysicianId"" ASC NULLS FIRST, ""dsspesPrimaryServiceLineId"" ASC NULLS FIRST, ""dsspesCPTCodeCaseTypeFamilyId"" ASC NULLS FIRST, ""dsspesMSDRGCaseTypeFamilyId"" ASC NULLS FIRST, ""dsspesAPRDRGCaseTypeFamilyId"" ASC NULLS FIRST, ""pblidDepartmentId"" ASC NULLS FIRST, ""physPrimaryPhysicianSpecialtyId"" ASC NULLS FIRST, ""ccChargeCodeID"" ASC NULLS FIRST, ""ccCostDriver"" ASC NULLS FIRST, ""encounterPatientTypeRollupPatientTypeRollup"" ASC NULLS FIRST "; // SQL for exploration-path tests (instead of clinical indicator) public static readonly string ExplorationMeasureSelectSql = @"SELECT ""DischargeDateTime"", ZEROIFNULL(""Value"") AS ""Value"" FROM ( SELECT ""DischargeDateTime"", SUM(""Value"") AS ""Value"" FROM ( SELECT DSSPES.dischargedatetime AS ""DischargeDateTime"", SUM(PBLID.unitsofservice) AS ""Value"" FROM dss.FactPatientBillingLineItemDetail AS PBLID RIGHT JOIN clientdss.FactPatientEncounterSummary AS DSSPES ON DSSPES.encounterid = PBLID.encounterid LEFT JOIN CCI.FACTEXPLORATIONPOPULATIONENCOUNTER AS EXPLORATIONPOPULATIONENCOUNTER ON EXPLORATIONPOPULATIONENCOUNTER.encounterid = PBLID.encounterid WHERE ((DSSPES.dischargedatetime >= :dischargedatetime_Start_0 AND DSSPES.dischargedatetime <= :dischargedatetime_End_1) AND EXPLORATIONPOPULATIONENCOUNTER.explorationpopulationid = :explorationpopulationid_2) GROUP BY ""DischargeDateTime"" ) GROUP BY ""DischargeDateTime"" ) ORDER BY ""DischargeDateTime"" ASC NULLS FIRST "; } }