-- SCHEMA: int

---------------------------------------------
--  TABLES
---------------------------------------------


---------------------------------------------
-- int.AggregatePostDIHistory ------------------
---------------------------------------------
CREATE TABLE [int].[AggregatePostDIHistory] (
    [AggregatePostDIHistoryGuid] uniqueidentifier NOT NULL,
    [CreatedAtUtc] datetime NOT NULL,
    [LastRanUtc] datetime NOT NULL,
    [AggregatePostDIStatus] int NOT NULL,
    PRIMARY KEY ([AggregatePostDIHistoryGuid])
);
GO
ALTER TABLE [int].[AggregatePostDIHistory] ADD CONSTRAINT [DF__Aggregate__Aggre__4EDF0E15] DEFAULT (newid()) FOR [AggregatePostDIHistoryGuid]; GO
ALTER TABLE [int].[AggregatePostDIHistory] ADD CONSTRAINT [DF__Aggregate__Creat__4FD3324E] DEFAULT (getutcdate()) FOR [CreatedAtUtc]; GO
ALTER TABLE [int].[AggregatePostDIHistory] ADD CONSTRAINT [DF__Aggregate__LastR__50C75687] DEFAULT ('1900-01-01 00:00:00.000') FOR [LastRanUtc]; GO
ALTER TABLE [int].[AggregatePostDIHistory] ADD CONSTRAINT [DF__Aggregate__Aggre__51BB7AC0] DEFAULT ((0)) FOR [AggregatePostDIStatus]; GO

---------------------------------------------

---------------------------------------------
-- int.AggregatePostDITransactionInfo ------------------
---------------------------------------------
CREATE TABLE [int].[AggregatePostDITransactionInfo] (
    [AggregatePostDITransactionInfoGuid] uniqueidentifier NOT NULL,
    [AggregatePostDIHistoryGuid] uniqueidentifier NOT NULL,
    [CreatedAtUtc] datetime NOT NULL,
    [TransactionId] int NOT NULL,
    PRIMARY KEY ([AggregatePostDITransactionInfoGuid])
);
GO
ALTER TABLE [int].[AggregatePostDITransactionInfo] ADD CONSTRAINT [FK__Aggregate__Aggre__558C0BA4] FOREIGN KEY ([AggregatePostDIHistoryGuid]) REFERENCES [int].[AggregatePostDIHistory] ([AggregatePostDIHistoryGuid]); GO
ALTER TABLE [int].[AggregatePostDITransactionInfo] ADD CONSTRAINT [DF__Aggregate__Aggre__5497E76B] DEFAULT (newid()) FOR [AggregatePostDITransactionInfoGuid]; GO
ALTER TABLE [int].[AggregatePostDITransactionInfo] ADD CONSTRAINT [DF__Aggregate__Creat__56802FDD] DEFAULT (getutcdate()) FOR [CreatedAtUtc]; GO
ALTER TABLE [int].[AggregatePostDITransactionInfo] ADD CONSTRAINT [DF__Aggregate__Trans__57745416] DEFAULT ((0)) FOR [TransactionId]; GO

---------------------------------------------

---------------------------------------------
-- int.ClaimsPostDIHistory ------------------
---------------------------------------------
CREATE TABLE [int].[ClaimsPostDIHistory] (
    [ClaimsPostDIHistoryGuid] uniqueidentifier NOT NULL,
    [CreatedAtUtc] datetime NOT NULL,
    [LastRanUtc] datetime NOT NULL,
    [ClaimsPostDIStatus] int NOT NULL,
    PRIMARY KEY ([ClaimsPostDIHistoryGuid])
);
GO
ALTER TABLE [int].[ClaimsPostDIHistory] ADD CONSTRAINT [DF__ClaimsPos__Claim__34801D94] DEFAULT (newid()) FOR [ClaimsPostDIHistoryGuid]; GO
ALTER TABLE [int].[ClaimsPostDIHistory] ADD CONSTRAINT [DF__ClaimsPos__Creat__357441CD] DEFAULT (getutcdate()) FOR [CreatedAtUtc]; GO
ALTER TABLE [int].[ClaimsPostDIHistory] ADD CONSTRAINT [DF__ClaimsPos__LastR__36686606] DEFAULT ('1900-01-01 00:00:00.000') FOR [LastRanUtc]; GO
ALTER TABLE [int].[ClaimsPostDIHistory] ADD CONSTRAINT [DF__ClaimsPos__Claim__375C8A3F] DEFAULT ((0)) FOR [ClaimsPostDIStatus]; GO

---------------------------------------------

---------------------------------------------
-- int.ClaimsPostDITransactionInfo ------------------
---------------------------------------------
CREATE TABLE [int].[ClaimsPostDITransactionInfo] (
    [ClaimsPostDITransactionInfoGuid] uniqueidentifier NOT NULL,
    [ClaimsPostDIHistoryGuid] uniqueidentifier NOT NULL,
    [CreatedAtUtc] datetime NOT NULL,
    [TransactionId] int NOT NULL,
    PRIMARY KEY ([ClaimsPostDITransactionInfoGuid])
);
GO
ALTER TABLE [int].[ClaimsPostDITransactionInfo] ADD CONSTRAINT [FK__ClaimsPos__Claim__3B2D1B23] FOREIGN KEY ([ClaimsPostDIHistoryGuid]) REFERENCES [int].[ClaimsPostDIHistory] ([ClaimsPostDIHistoryGuid]); GO
ALTER TABLE [int].[ClaimsPostDITransactionInfo] ADD CONSTRAINT [DF__ClaimsPos__Claim__3A38F6EA] DEFAULT (newid()) FOR [ClaimsPostDITransactionInfoGuid]; GO
ALTER TABLE [int].[ClaimsPostDITransactionInfo] ADD CONSTRAINT [DF__ClaimsPos__Creat__3C213F5C] DEFAULT (getutcdate()) FOR [CreatedAtUtc]; GO
ALTER TABLE [int].[ClaimsPostDITransactionInfo] ADD CONSTRAINT [DF__ClaimsPos__Trans__3D156395] DEFAULT ((0)) FOR [TransactionId]; GO

---------------------------------------------

---------------------------------------------
-- int.FactADTDataImport ------------------
---------------------------------------------
CREATE TABLE [int].[FactADTDataImport] (
    [RowID] int NOT NULL,
    [EntityID] int NOT NULL,
    [DepartmentID] int NOT NULL,
    [EncounterID] bigint NOT NULL,
    [EntityCode] nvarchar(100) NOT NULL,
    [DepartmentCode] nvarchar(100) NOT NULL,
    [UnitCode] nvarchar(100) NOT NULL,
    [AccommodationCode] nvarchar(100) NOT NULL,
    [AccommodationDSC] nvarchar(100) NOT NULL,
    [EncounterCode] nvarchar(100) NOT NULL,
    [AdmitDateTime] datetime NOT NULL,
    [DischargeDateTime] datetime NOT NULL,
    [TransferDateTime] datetime NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    [EventID] varchar(50) NOT NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactADTDataImport] ADD CONSTRAINT [FK__FactADTDa__Depar__12FD33F6] FOREIGN KEY ([DepartmentID]) REFERENCES [fw].[DimDepartment] ([DepartmentID]); GO
ALTER TABLE [int].[FactADTDataImport] ADD CONSTRAINT [FK__FactADTDa__Encou__14E57C68] FOREIGN KEY ([EncounterID]) REFERENCES [dss].[DimPatientEncounter] ([EncounterID]); GO
ALTER TABLE [int].[FactADTDataImport] ADD CONSTRAINT [FK__FactADTDa__Entit__1114EB84] FOREIGN KEY ([EntityID]) REFERENCES [fw].[DimEntity] ([EntityID]); GO
ALTER TABLE [int].[FactADTDataImport] ADD CONSTRAINT [DF__FactADTDa__Entit__1020C74B] DEFAULT ((0)) FOR [EntityID]; GO
ALTER TABLE [int].[FactADTDataImport] ADD CONSTRAINT [DF__FactADTDa__Depar__12090FBD] DEFAULT ((0)) FOR [DepartmentID]; GO
ALTER TABLE [int].[FactADTDataImport] ADD CONSTRAINT [DF__FactADTDa__Encou__13F1582F] DEFAULT ((0)) FOR [EncounterID]; GO
ALTER TABLE [int].[FactADTDataImport] ADD CONSTRAINT [DF__FactADTDa__Entit__15D9A0A1] DEFAULT ('') FOR [EntityCode]; GO
ALTER TABLE [int].[FactADTDataImport] ADD CONSTRAINT [DF__FactADTDa__Depar__16CDC4DA] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactADTDataImport] ADD CONSTRAINT [DF__FactADTDa__UnitC__17C1E913] DEFAULT ('') FOR [UnitCode]; GO
ALTER TABLE [int].[FactADTDataImport] ADD CONSTRAINT [DF__FactADTDa__Accom__18B60D4C] DEFAULT ('') FOR [AccommodationCode]; GO
ALTER TABLE [int].[FactADTDataImport] ADD CONSTRAINT [DF__FactADTDa__Accom__19AA3185] DEFAULT ('') FOR [AccommodationDSC]; GO
ALTER TABLE [int].[FactADTDataImport] ADD CONSTRAINT [DF__FactADTDa__Encou__1A9E55BE] DEFAULT ('') FOR [EncounterCode]; GO
ALTER TABLE [int].[FactADTDataImport] ADD CONSTRAINT [DF__FactADTDa__Admit__1B9279F7] DEFAULT (getdate()) FOR [AdmitDateTime]; GO
ALTER TABLE [int].[FactADTDataImport] ADD CONSTRAINT [DF__FactADTDa__Disch__1C869E30] DEFAULT (getdate()) FOR [DischargeDateTime]; GO
ALTER TABLE [int].[FactADTDataImport] ADD CONSTRAINT [DF__FactADTDa__Trans__1D7AC269] DEFAULT (getdate()) FOR [TransferDateTime]; GO
ALTER TABLE [int].[FactADTDataImport] ADD CONSTRAINT [DF__FactADTDa__IsDel__1E6EE6A2] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactADTDataImport] ADD CONSTRAINT [DF__FactADTDa__Trans__20572F14] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactADTDataImport] ADD CONSTRAINT [DF__FactADTDa__Histo__1F630ADB] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactADTDataImport] ADD CONSTRAINT [DF__FactADTDa__Event__58E8CE56] DEFAULT ('') FOR [EventID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactAPDetail ------------------
---------------------------------------------
CREATE TABLE [int].[FactAPDetail] (
    [RowID] int NOT NULL,
    [AccountID] int NOT NULL,
    [ComponentID] smallint NOT NULL,
    [ProjectID] int NOT NULL,
    [RequisitionID] int NOT NULL,
    [VendorID] int NOT NULL,
    [DepartmentID] int NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [ClientCapitalID] nvarchar(100) NOT NULL,
    [ClientComponentID] nvarchar(100) NOT NULL,
    [InvoiceNumber] nvarchar(100) NOT NULL,
    [PONumber] nvarchar(100) NULL,
    [LineDescription] nvarchar(100) NOT NULL,
    [ClientDate] datetime NOT NULL,
    [Quantity] decimal NOT NULL,
    [CostPerItem] decimal NOT NULL,
    [Total] decimal NULL,
    [LineNumber] nvarchar(100) NOT NULL,
    [VendorCode] nvarchar(100) NOT NULL,
    [VendorName] nvarchar(100) NOT NULL,
    [AccountCode] nvarchar(100) NOT NULL,
    [ItemNumber] nvarchar(100) NOT NULL,
    [FiscalMonthCode] nvarchar(100) NOT NULL,
    [FiscalYearCode] nvarchar(100) NOT NULL,
    [DepartmentCode] nvarchar(100) NOT NULL,
    [CustomText1] nvarchar(100) NOT NULL,
    [CustomText2] nvarchar(100) NOT NULL,
    [CustomText3] nvarchar(100) NOT NULL,
    [CustomText4] nvarchar(100) NOT NULL,
    [CustomText5] nvarchar(100) NOT NULL,
    [CustomDate1] datetime NOT NULL,
    [CustomDate2] datetime NOT NULL,
    [CustomNumeric1] decimal NOT NULL,
    [CustomNumeric2] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    [IsSampled] bit NOT NULL,
    [SampleDate] datetime NOT NULL,
    [TransID] nvarchar(100) NOT NULL,
    [CustomLongText1] nvarchar(2000) NOT NULL,
    [CustomLongText2] nvarchar(2000) NOT NULL,
    [InvoiceImage] nvarchar(2000) NOT NULL,
    PRIMARY KEY ([RowID])
);

CREATE CLUSTERED INDEX [CNU_BASE] ON [int].[FactAPDetail] ([FiscalMonthID], [IsDeleted], [FiscalYearID], [DepartmentID], [AccountID], [ComponentID], [ProjectID], [RequisitionID], [VendorID]);
CREATE NONCLUSTERED INDEX [NCNU_SampleView] ON [int].[FactAPDetail] ([FiscalMonthID], [IsDeleted], [FiscalYearID], [DepartmentID], [AccountID], [ComponentID], [ProjectID], [RequisitionID], [VendorID]);
GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [FK__FactAPDet__Accou__0F3DB8F8] FOREIGN KEY ([AccountID]) REFERENCES [fw].[DimAccount] ([AccountID]); GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [FK__FactAPDet__Compo__1126016A] FOREIGN KEY ([ComponentID]) REFERENCES [cap].[DimComponent] ([ComponentID]); GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [FK__FactAPDet__Depar__18C72332] FOREIGN KEY ([DepartmentID]) REFERENCES [fw].[DimDepartment] ([DepartmentID]); GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [FK__FactAPDet__Fisca__1AAF6BA4] FOREIGN KEY ([FiscalMonthID]) REFERENCES [fw].[DimFiscalMonth] ([FiscalMonthID]); GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [FK__FactAPDet__Fisca__1C97B416] FOREIGN KEY ([FiscalYearID]) REFERENCES [fw].[DimFiscalYear] ([FiscalYearID]); GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [FK__FactAPDet__Proje__130E49DC] FOREIGN KEY ([ProjectID]) REFERENCES [cap].[DimProject] ([ProjectID]); GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [FK__FactAPDet__Requi__14F6924E] FOREIGN KEY ([RequisitionID]) REFERENCES [cap].[DimRequisition] ([RequisitionID]); GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [FK__FactAPDet__Vendo__16DEDAC0] FOREIGN KEY ([VendorID]) REFERENCES [cap].[DimVendor] ([VendorID]); GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Accou__0E4994BF] DEFAULT ((0)) FOR [AccountID]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Compo__1031DD31] DEFAULT ((0)) FOR [ComponentID]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Proje__121A25A3] DEFAULT ((0)) FOR [ProjectID]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Requi__14026E15] DEFAULT ((0)) FOR [RequisitionID]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Vendo__15EAB687] DEFAULT ((0)) FOR [VendorID]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Fisca__19BB476B] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Fisca__1BA38FDD] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Clien__1D8BD84F] DEFAULT ('') FOR [ClientCapitalID]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Clien__1E7FFC88] DEFAULT ('') FOR [ClientComponentID]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Invoi__1F7420C1] DEFAULT ('') FOR [InvoiceNumber]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__LineD__215C6933] DEFAULT ('') FOR [LineDescription]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Clien__22508D6C] DEFAULT (getdate()) FOR [ClientDate]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Quant__2344B1A5] DEFAULT ((0)) FOR [Quantity]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__CostP__2438D5DE] DEFAULT ((0)) FOR [CostPerItem]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__LineN__252CFA17] DEFAULT ('') FOR [LineNumber]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Vendo__26211E50] DEFAULT ('') FOR [VendorCode]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Vendo__27154289] DEFAULT ('') FOR [VendorName]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Histo__36578619] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Accou__280966C2] DEFAULT ('') FOR [AccountCode]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Invoi__289937D2] DEFAULT ('') FOR [InvoiceImage]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__ItemN__28FD8AFB] DEFAULT ('') FOR [ItemNumber]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Fisca__29F1AF34] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Depar__17D2FEF9] DEFAULT ((0)) FOR [DepartmentID]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Fisca__2AE5D36D] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Depar__2BD9F7A6] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Custo__2CCE1BDF] DEFAULT ('') FOR [CustomText1]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Custo__2DC24018] DEFAULT ('') FOR [CustomText2]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Custo__2EB66451] DEFAULT ('') FOR [CustomText3]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Custo__2FAA888A] DEFAULT ('') FOR [CustomText4]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Custo__309EACC3] DEFAULT ('') FOR [CustomText5]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Custo__3192D0FC] DEFAULT (getdate()) FOR [CustomDate1]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Custo__3286F535] DEFAULT (getdate()) FOR [CustomDate2]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Custo__337B196E] DEFAULT ((0)) FOR [CustomNumeric1]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Custo__346F3DA7] DEFAULT ((0)) FOR [CustomNumeric2]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__IsDel__356361E0] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Trans__374BAA52] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__IsSam__3933F2C4] DEFAULT ((0)) FOR [IsSampled]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Sampl__3A2816FD] DEFAULT (getdate()) FOR [SampleDate]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Trans__69D72A1F] DEFAULT ('') FOR [TransID]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__PONum__7A89B943] DEFAULT ('') FOR [PONumber]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Custo__7B7DDD7C] DEFAULT ('') FOR [CustomLongText1]; GO
ALTER TABLE [int].[FactAPDetail] ADD CONSTRAINT [DF__FactAPDet__Custo__7C7201B5] DEFAULT ('') FOR [CustomLongText2]; GO

---------------------------------------------

---------------------------------------------
-- int.FactAssetWorkOrderDetail ------------------
---------------------------------------------
CREATE TABLE [int].[FactAssetWorkOrderDetail] (
    [RowID] int NOT NULL,
    [WorkOrderTypeID] int NOT NULL,
    [DateID] int NOT NULL,
    [AssetCode] nvarchar(100) NOT NULL,
    [WorkOrderNumber] nvarchar(100) NOT NULL,
    [LaborHours] decimal NOT NULL,
    [PartsCost] decimal NOT NULL,
    [LaborCost] decimal NOT NULL,
    [CustomNumeric1] decimal NOT NULL,
    [CustomNumeric2] decimal NOT NULL,
    [CustomNumeric3] decimal NOT NULL,
    [CustomNumeric4] decimal NOT NULL,
    [CustomNumeric5] decimal NOT NULL,
    [CustomText1] nvarchar(200) NOT NULL,
    [CustomText2] nvarchar(200) NOT NULL,
    [CustomText3] nvarchar(200) NOT NULL,
    [CustomText4] nvarchar(200) NOT NULL,
    [CustomText5] nvarchar(200) NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [FK__FactAsset__DateI__6A1E1157] FOREIGN KEY ([DateID]) REFERENCES [fw].[DimDate] ([DateID]); GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [FK__FactAsset__WorkO__6835C8E5] FOREIGN KEY ([WorkOrderTypeID]) REFERENCES [cap].[DimWorkOrderType] ([WorkOrderTypeID]); GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__WorkO__6741A4AC] DEFAULT ((0)) FOR [WorkOrderTypeID]; GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__DateI__6929ED1E] DEFAULT ((0)) FOR [DateID]; GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__Asset__6B123590] DEFAULT ('') FOR [AssetCode]; GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__WorkO__6C0659C9] DEFAULT ('') FOR [WorkOrderNumber]; GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__Labor__6CFA7E02] DEFAULT ((0)) FOR [LaborHours]; GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__Parts__6DEEA23B] DEFAULT ((0)) FOR [PartsCost]; GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__Labor__6EE2C674] DEFAULT ((0)) FOR [LaborCost]; GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__Custo__6FD6EAAD] DEFAULT ((0)) FOR [CustomNumeric1]; GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__Custo__70CB0EE6] DEFAULT ((0)) FOR [CustomNumeric2]; GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__Custo__71BF331F] DEFAULT ((0)) FOR [CustomNumeric3]; GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__Custo__72B35758] DEFAULT ((0)) FOR [CustomNumeric4]; GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__Custo__73A77B91] DEFAULT ((0)) FOR [CustomNumeric5]; GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__Custo__749B9FCA] DEFAULT ('') FOR [CustomText1]; GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__Custo__758FC403] DEFAULT ('') FOR [CustomText2]; GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__Custo__7683E83C] DEFAULT ('') FOR [CustomText3]; GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__Custo__77780C75] DEFAULT ('') FOR [CustomText4]; GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__Custo__786C30AE] DEFAULT ('') FOR [CustomText5]; GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__IsDel__796054E7] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__Histo__7A547920] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactAssetWorkOrderDetail] ADD CONSTRAINT [DF__FactAsset__Trans__7B489D59] DEFAULT ((0)) FOR [TransactionID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactCDM ------------------
---------------------------------------------
CREATE TABLE [int].[FactCDM] (
    [RowID] bigint NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] nvarchar(100) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] nvarchar(100) NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [FiscalMonthCode] nvarchar(100) NOT NULL,
    [DepartmentID] int NOT NULL,
    [DepartmentCode] nvarchar(100) NOT NULL,
    [PatientClassID] int NOT NULL,
    [PatientClassCode] nvarchar(100) NOT NULL,
    [ChargeCodeID] int NOT NULL,
    [ChargeCode] nvarchar(100) NOT NULL,
    [ServiceLineID] int NOT NULL,
    [ServiceLine] nvarchar(100) NOT NULL,
    [MedicalSurgicalID] int NOT NULL,
    [MedSurg] nvarchar(100) NOT NULL,
    [AgeCohortID] int NOT NULL,
    [AgeCohort] nvarchar(100) NOT NULL,
    [UnitTypeID] tinyint NOT NULL,
    [UnitType] nvarchar(100) NOT NULL,
    [Value] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    PRIMARY KEY ([RowID])
);

CREATE CLUSTERED INDEX [CNU_BASE] ON [int].[FactCDM] ([FiscalMonthID], [IsDeleted], [FiscalYearID], [DepartmentID], [ChargeCodeID], [ServiceLineID], [PatientClassID], [AgeCohortID], [MedicalSurgicalID]);
CREATE NONCLUSTERED INDEX [NCNU_SampleView] ON [int].[FactCDM] ([FiscalMonthID], [IsDeleted], [FiscalYearID], [DepartmentID], [ChargeCodeID], [ServiceLineID], [PatientClassID], [AgeCohortID], [MedicalSurgicalID]);
CREATE NONCLUSTERED INDEX [IX_FactCDM_ForFlexingReconciliation] ON [int].[FactCDM] ([DepartmentID], [ChargeCodeID], [FiscalYearID], [UnitTypeID], [TimeClassID], [FiscalMonthID]) INCLUDE ([ServiceLineID]);
GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [FK__FactCDM__AgeCoho__604A9289] FOREIGN KEY ([AgeCohortID]) REFERENCES [fw].[DimAgeCohort] ([AgeCohortID]); GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [FK__FactCDM__ChargeC__6232DAFB] FOREIGN KEY ([ChargeCodeID]) REFERENCES [fw].[DimChargeCode] ([ChargeCodeID]); GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [FK__FactCDM__Departm__5E624A17] FOREIGN KEY ([DepartmentID]) REFERENCES [fw].[DimDepartment] ([DepartmentID]); GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [FK__FactCDM__FiscalM__641B236D] FOREIGN KEY ([FiscalMonthID]) REFERENCES [fw].[DimFiscalMonth] ([FiscalMonthID]); GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [FK__FactCDM__FiscalY__66036BDF] FOREIGN KEY ([FiscalYearID]) REFERENCES [fw].[DimFiscalYear] ([FiscalYearID]); GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [FK__FactCDM__Medical__67EBB451] FOREIGN KEY ([MedicalSurgicalID]) REFERENCES [fw].[DimMedicalSurgical] ([MedicalSurgicalID]); GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [FK__FactCDM__Patient__69D3FCC3] FOREIGN KEY ([PatientClassID]) REFERENCES [fw].[DimPatientClass] ([PatientClassID]); GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [FK__FactCDM__Service__6BBC4535] FOREIGN KEY ([ServiceLineID]) REFERENCES [fw].[DimServiceLine] ([ServiceLineID]); GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [FK__FactCDM__UnitTyp__6DA48DA7] FOREIGN KEY ([UnitTypeID]) REFERENCES [fw].[DimUnitType] ([UnitTypeID]); GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__Departm__5D6E25DE] DEFAULT ((0)) FOR [DepartmentID]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__TimeCla__79170BAA] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__TimeCla__7A0B2FE3] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__FiscalY__650F47A6] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__FiscalY__735D66FD] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__History__79164053] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__FiscalM__6326FF34] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__FiscalM__726942C4] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__Departm__6F8CD619] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__Patient__68DFD88A] DEFAULT ((0)) FOR [PatientClassID]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__Patient__74518B36] DEFAULT ('') FOR [PatientClassCode]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__ChargeC__613EB6C2] DEFAULT ((0)) FOR [ChargeCodeID]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__ChargeC__7080FA52] DEFAULT ('') FOR [ChargeCode]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__Service__6AC820FC] DEFAULT ((0)) FOR [ServiceLineID]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__Service__71751E8B] DEFAULT ('') FOR [ServiceLine]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__Medical__66F79018] DEFAULT ((0)) FOR [MedicalSurgicalID]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__MedSurg__7639D3A8] DEFAULT ('') FOR [MedSurg]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__AgeCoho__5F566E50] DEFAULT ((0)) FOR [AgeCohortID]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__AgeCoho__7545AF6F] DEFAULT ('') FOR [AgeCohort]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__UnitTyp__6CB0696E] DEFAULT ((0)) FOR [UnitTypeID]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__UnitTyp__772DF7E1] DEFAULT ('') FOR [UnitType]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__Value__6E98B1E0] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__IsDelet__78221C1A] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactCDM] ADD CONSTRAINT [DF__FactCDM__Transac__7A0A648C] DEFAULT ((0)) FOR [TransactionID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactCDMImport ------------------
---------------------------------------------
CREATE TABLE [int].[FactCDMImport] (
    [RowID] int NOT NULL,
    [DepartmentID] int NOT NULL,
    [ChargeCodeID] int NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [EntityID] int NOT NULL,
    [Dollars] decimal NOT NULL,
    [Units] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NULL,
    PRIMARY KEY ([RowID])
);

CREATE UNIQUE NONCLUSTERED INDEX [NCU_Score] ON [int].[FactCDMImport] ([DepartmentID], [ChargeCodeID], [FiscalYearID], [FiscalMonthID], [TimeClassID], [EntityID], [IsDeleted]);
GO
ALTER TABLE [int].[FactCDMImport] ADD CONSTRAINT [FK__FactCDMIm__Charg__0FC60065] FOREIGN KEY ([ChargeCodeID]) REFERENCES [fw].[DimChargeCode] ([ChargeCodeID]); GO
ALTER TABLE [int].[FactCDMImport] ADD CONSTRAINT [FK__FactCDMIm__Depar__0DDDB7F3] FOREIGN KEY ([DepartmentID]) REFERENCES [fw].[DimDepartment] ([DepartmentID]); GO
ALTER TABLE [int].[FactCDMImport] ADD CONSTRAINT [FK__FactCDMIm__Entit__1767222D] FOREIGN KEY ([EntityID]) REFERENCES [fw].[DimEntity] ([EntityID]); GO
ALTER TABLE [int].[FactCDMImport] ADD CONSTRAINT [FK__FactCDMIm__Fisca__11AE48D7] FOREIGN KEY ([FiscalYearID]) REFERENCES [fw].[DimFiscalYear] ([FiscalYearID]); GO
ALTER TABLE [int].[FactCDMImport] ADD CONSTRAINT [FK__FactCDMIm__Fisca__13969149] FOREIGN KEY ([FiscalMonthID]) REFERENCES [fw].[DimFiscalMonth] ([FiscalMonthID]); GO
ALTER TABLE [int].[FactCDMImport] ADD CONSTRAINT [FK__FactCDMIm__TimeC__157ED9BB] FOREIGN KEY ([TimeClassID]) REFERENCES [fw].[DimTimeClass] ([TimeClassID]); GO
ALTER TABLE [int].[FactCDMImport] ADD CONSTRAINT [DF__FactCDMIm__Charg__0ED1DC2C] DEFAULT ((0)) FOR [ChargeCodeID]; GO
ALTER TABLE [int].[FactCDMImport] ADD CONSTRAINT [DF__FactCDMIm__Fisca__10BA249E] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactCDMImport] ADD CONSTRAINT [DF__FactCDMIm__Fisca__12A26D10] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactCDMImport] ADD CONSTRAINT [DF__FactCDMIm__TimeC__148AB582] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactCDMImport] ADD CONSTRAINT [DF__FactCDMIm__Entit__1672FDF4] DEFAULT ((0)) FOR [EntityID]; GO
ALTER TABLE [int].[FactCDMImport] ADD CONSTRAINT [DF__FactCDMIm__Dolla__185B4666] DEFAULT ((0)) FOR [Dollars]; GO
ALTER TABLE [int].[FactCDMImport] ADD CONSTRAINT [DF__FactCDMIm__Hours__194F6A9F] DEFAULT ((0)) FOR [Units]; GO
ALTER TABLE [int].[FactCDMImport] ADD CONSTRAINT [DF__FactCDMIm__IsDel__1A438ED8] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactCDMImport] ADD CONSTRAINT [DF__FactCDMIm__Depar__0CE993BA] DEFAULT ((0)) FOR [DepartmentID]; GO
ALTER TABLE [int].[FactCDMImport] ADD CONSTRAINT [DF__INT_FactCDMImport_TransactionID ] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactCDMImport] ADD CONSTRAINT [DF__FactCDMIm__Histo__1B37B311] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactCernerPatientADT ------------------
---------------------------------------------
CREATE TABLE [int].[FactCernerPatientADT] (
    [RowID] int NOT NULL,
    [EncounterNumber] nvarchar(100) NOT NULL,
    [PatientType] nvarchar(100) NOT NULL,
    [ChangeType] nvarchar(100) NOT NULL,
    [ChangeTypeDescription] nvarchar(100) NOT NULL,
    [Entity] nvarchar(100) NOT NULL,
    [Service] nvarchar(100) NOT NULL,
    [EffectiveDateTime] datetime NOT NULL,
    [SourceNurseStation] nvarchar(100) NOT NULL,
    [SourceBed] nvarchar(100) NOT NULL,
    [SourceCostCenter] nvarchar(100) NOT NULL,
    [TargetNurseStation] nvarchar(100) NOT NULL,
    [TargetBed] nvarchar(100) NOT NULL,
    [TargetCostCenter] nvarchar(100) NOT NULL,
    [SequenceNumber] nvarchar(100) NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    PRIMARY KEY ([RowID])
);

CREATE NONCLUSTERED INDEX [IDX_PatType_HistGUID_Incl_Ern] ON [int].[FactCernerPatientADT] ([PatientType], [HistoryItemGUID]) INCLUDE ([EncounterNumber]);
CREATE NONCLUSTERED INDEX [IDX_ChType_INC_Ern_EffDt_Tcc_Scc_SeqN] ON [int].[FactCernerPatientADT] ([ChangeType]) INCLUDE ([EncounterNumber], [EffectiveDateTime], [TargetCostCenter], [SourceCostCenter], [SequenceNumber]);
CREATE NONCLUSTERED INDEX [IDX_Ern_Incl_CType_EffDate_Tcc_SeqNum] ON [int].[FactCernerPatientADT] ([EncounterNumber]) INCLUDE ([ChangeType], [EffectiveDateTime], [TargetCostCenter], [SequenceNumber]);
GO
ALTER TABLE [int].[FactCernerPatientADT] ADD CONSTRAINT [DF__FactCerne__Encou__200A1ABF] DEFAULT ('') FOR [EncounterNumber]; GO
ALTER TABLE [int].[FactCernerPatientADT] ADD CONSTRAINT [DF__FactCerne__Patie__20FE3EF8] DEFAULT ('') FOR [PatientType]; GO
ALTER TABLE [int].[FactCernerPatientADT] ADD CONSTRAINT [DF__FactCerne__Chang__21F26331] DEFAULT ('') FOR [ChangeType]; GO
ALTER TABLE [int].[FactCernerPatientADT] ADD CONSTRAINT [DF__FactCerne__Chang__22E6876A] DEFAULT ('') FOR [ChangeTypeDescription]; GO
ALTER TABLE [int].[FactCernerPatientADT] ADD CONSTRAINT [DF__FactCerne__Entit__23DAABA3] DEFAULT ('') FOR [Entity]; GO
ALTER TABLE [int].[FactCernerPatientADT] ADD CONSTRAINT [DF__FactCerne__Servi__24CECFDC] DEFAULT ('') FOR [Service]; GO
ALTER TABLE [int].[FactCernerPatientADT] ADD CONSTRAINT [DF__FactCerne__Effec__25C2F415] DEFAULT (getdate()) FOR [EffectiveDateTime]; GO
ALTER TABLE [int].[FactCernerPatientADT] ADD CONSTRAINT [DF__FactCerne__Histo__2E583A16] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactCernerPatientADT] ADD CONSTRAINT [DF__FactCerne__Sourc__26B7184E] DEFAULT ('') FOR [SourceNurseStation]; GO
ALTER TABLE [int].[FactCernerPatientADT] ADD CONSTRAINT [DF__FactCerne__Sourc__27AB3C87] DEFAULT ('') FOR [SourceBed]; GO
ALTER TABLE [int].[FactCernerPatientADT] ADD CONSTRAINT [DF__FactCerne__Sourc__289F60C0] DEFAULT ('') FOR [SourceCostCenter]; GO
ALTER TABLE [int].[FactCernerPatientADT] ADD CONSTRAINT [DF__FactCerne__Targe__299384F9] DEFAULT ('') FOR [TargetNurseStation]; GO
ALTER TABLE [int].[FactCernerPatientADT] ADD CONSTRAINT [DF__FactCerne__Targe__2A87A932] DEFAULT ('') FOR [TargetBed]; GO
ALTER TABLE [int].[FactCernerPatientADT] ADD CONSTRAINT [DF__FactCerne__Targe__2B7BCD6B] DEFAULT ('') FOR [TargetCostCenter]; GO
ALTER TABLE [int].[FactCernerPatientADT] ADD CONSTRAINT [DF__FactCerne__Seque__2C6FF1A4] DEFAULT ('') FOR [SequenceNumber]; GO
ALTER TABLE [int].[FactCernerPatientADT] ADD CONSTRAINT [DF__FactCerne__IsDel__2D6415DD] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactCernerPatientADT] ADD CONSTRAINT [DF__FactCerne__Trans__2F4C5E4F] DEFAULT ((0)) FOR [TransactionID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactEpicPatientADT ------------------
---------------------------------------------
CREATE TABLE [int].[FactEpicPatientADT] (
    [RowID] int NOT NULL,
    [EncounterRecordNumber] nvarchar(100) NOT NULL,
    [AccommodationCode] nvarchar(100) NOT NULL,
    [AccommodationCodeDescription] nvarchar(100) NOT NULL,
    [EventID] nvarchar(100) NOT NULL,
    [EventTypeCode] nvarchar(100) NOT NULL,
    [EventTypeCodeDescription] nvarchar(100) NOT NULL,
    [EventSubTypeCode] nvarchar(100) NOT NULL,
    [DepartmentCode] nvarchar(100) NOT NULL,
    [DepartmentDescription] nvarchar(100) NOT NULL,
    [RoomNumber] nvarchar(100) NOT NULL,
    [BedID] nvarchar(100) NOT NULL,
    [EffectiveDateTimeStamp] datetime NOT NULL,
    [TransferInEventID] nvarchar(100) NOT NULL,
    [NextOutEventID] nvarchar(100) NOT NULL,
    [LastInEventID] nvarchar(100) NOT NULL,
    [EventSequenceNumber] nvarchar(100) NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    [AcuityCode] nvarchar(100) NOT NULL,
    [EpicDepartment] nvarchar(100) NULL,
    PRIMARY KEY ([RowID])
);

CREATE NONCLUSTERED INDEX [NC_IDX_EpicADT_HistGUID_ERN] ON [int].[FactEpicPatientADT] ([HistoryItemGUID]) INCLUDE ([EncounterRecordNumber]);
CREATE NONCLUSTERED INDEX [NC_FactEpicADT_HistGUID_ERN] ON [int].[FactEpicPatientADT] ([HistoryItemGUID]) INCLUDE ([EncounterRecordNumber]);
CREATE NONCLUSTERED INDEX [NC_FactEpicADT_AC_HistGUID_ERN] ON [int].[FactEpicPatientADT] ([AccommodationCode], [HistoryItemGUID]) INCLUDE ([EncounterRecordNumber]);
CREATE NONCLUSTERED INDEX [NC_FactEpicADT_ERN] ON [int].[FactEpicPatientADT] ([EncounterRecordNumber]);
CREATE NONCLUSTERED INDEX [NC_Hist_EffectDateTime] ON [int].[FactEpicPatientADT] ([HistoryItemGUID]) INCLUDE ([EffectiveDateTimeStamp]);
CREATE NONCLUSTERED INDEX [NC_EpiAdt_AccDesc] ON [int].[FactEpicPatientADT] ([AccommodationCodeDescription]) INCLUDE ([EncounterRecordNumber], [EventTypeCode], [EventSubTypeCode], [DepartmentCode], [EffectiveDateTimeStamp]);
CREATE NONCLUSTERED INDEX [NC_IDX_EpicPatientADT_LastEventID] ON [int].[FactEpicPatientADT] ([LastInEventID]);
CREATE NONCLUSTERED INDEX [NC_IDX_EpicPatientADT_NextOutEventID] ON [int].[FactEpicPatientADT] ([NextOutEventID]);
GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__Trans__0116BB41] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__Histo__00229708] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__EpicD__50CF1623] DEFAULT ('') FOR [EpicDepartment]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__Acuit__67D24542] DEFAULT ('') FOR [AcuityCode]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__Encou__6FEC2F3F] DEFAULT ('') FOR [EncounterRecordNumber]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__Accom__70E05378] DEFAULT ('') FOR [AccommodationCode]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__Accom__71D477B1] DEFAULT ('') FOR [AccommodationCodeDescription]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__Event__72C89BEA] DEFAULT ('') FOR [EventID]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__Event__73BCC023] DEFAULT ('') FOR [EventTypeCode]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__Event__74B0E45C] DEFAULT ('') FOR [EventTypeCodeDescription]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__Event__75A50895] DEFAULT ('') FOR [EventSubTypeCode]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__Depar__76992CCE] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__Depar__778D5107] DEFAULT ('') FOR [DepartmentDescription]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__RoomN__78817540] DEFAULT ('') FOR [RoomNumber]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__BedID__79759979] DEFAULT ('') FOR [BedID]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__Effec__7A69BDB2] DEFAULT (getdate()) FOR [EffectiveDateTimeStamp]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__Trans__7B5DE1EB] DEFAULT ('') FOR [TransferInEventID]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__NextO__7C520624] DEFAULT ('') FOR [NextOutEventID]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__LastI__7D462A5D] DEFAULT ('') FOR [LastInEventID]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__Event__7E3A4E96] DEFAULT ('') FOR [EventSequenceNumber]; GO
ALTER TABLE [int].[FactEpicPatientADT] ADD CONSTRAINT [DF__FactEpicP__IsDel__7F2E72CF] DEFAULT ((0)) FOR [IsDeleted]; GO

---------------------------------------------

---------------------------------------------
-- int.FactFinancialServiceLineCost ------------------
---------------------------------------------
CREATE TABLE [int].[FactFinancialServiceLineCost] (
    [RowID] int NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [ForecastDetailID] int NOT NULL,
    [UnitTypeID] tinyint NOT NULL,
    [EntityID] int NOT NULL,
    [DepartmentID] int NOT NULL,
    [ServiceLineID] int NOT NULL,
    [PatientClassID] int NOT NULL,
    [AgeCohortID] int NOT NULL,
    [MedicalSurgicalID] int NOT NULL,
    [FiscalMonthCode] nvarchar(100) NOT NULL,
    [TimeClassCode] nvarchar(100) NOT NULL,
    [ForecastDetailCode] nvarchar(100) NOT NULL,
    [EntityCode] nvarchar(100) NOT NULL,
    [DepartmentCode] nvarchar(100) NOT NULL,
    [ServiceLineCode] nvarchar(100) NOT NULL,
    [PatientClassCode] nvarchar(100) NOT NULL,
    [AgeCohortCode] nvarchar(100) NOT NULL,
    [Value] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    [MedicalSurgicalCode] nvarchar(100) NOT NULL,
    [UnitTypeName] nvarchar(100) NOT NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [FK__FactFinan__AgeCo__1210CF59] FOREIGN KEY ([AgeCohortID]) REFERENCES [fw].[DimAgeCohort] ([AgeCohortID]); GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [FK__FactFinan__Depar__0C57F603] FOREIGN KEY ([DepartmentID]) REFERENCES [fw].[DimDepartment] ([DepartmentID]); GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [FK__FactFinan__Entit__0A6FAD91] FOREIGN KEY ([EntityID]) REFERENCES [fw].[DimEntity] ([EntityID]); GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [FK__FactFinan__Fisca__00E64357] FOREIGN KEY ([FiscalYearID]) REFERENCES [fw].[DimFiscalYear] ([FiscalYearID]); GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [FK__FactFinan__Fisca__02CE8BC9] FOREIGN KEY ([FiscalMonthID]) REFERENCES [fw].[DimFiscalMonth] ([FiscalMonthID]); GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [FK__FactFinan__Forec__069F1CAD] FOREIGN KEY ([ForecastDetailID]) REFERENCES [fw].[DimForecastDetail] ([ForecastDetailID]); GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [FK__FactFinan__Medic__13F917CB] FOREIGN KEY ([MedicalSurgicalID]) REFERENCES [fw].[DimMedicalSurgical] ([MedicalSurgicalID]); GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [FK__FactFinan__Patie__102886E7] FOREIGN KEY ([PatientClassID]) REFERENCES [fw].[DimPatientClass] ([PatientClassID]); GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [FK__FactFinan__Servi__0E403E75] FOREIGN KEY ([ServiceLineID]) REFERENCES [fw].[DimServiceLine] ([ServiceLineID]); GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [FK__FactFinan__TimeC__04B6D43B] FOREIGN KEY ([TimeClassID]) REFERENCES [fw].[DimTimeClass] ([TimeClassID]); GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [FK__FactFinan__UnitT__0887651F] FOREIGN KEY ([UnitTypeID]) REFERENCES [fw].[DimUnitType] ([UnitTypeID]); GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__Fisca__01DA6790] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__TimeC__03C2B002] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__Forec__05AAF874] DEFAULT ((0)) FOR [ForecastDetailID]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__UnitT__079340E6] DEFAULT ((0)) FOR [UnitTypeID]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__Servi__0D4C1A3C] DEFAULT ((0)) FOR [ServiceLineID]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__Patie__0F3462AE] DEFAULT ((0)) FOR [PatientClassID]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__AgeCo__111CAB20] DEFAULT ((0)) FOR [AgeCohortID]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__Medic__1304F392] DEFAULT ((0)) FOR [MedicalSurgicalID]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__Fisca__14ED3C04] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__TimeC__15E1603D] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__Forec__16D58476] DEFAULT ('') FOR [ForecastDetailCode]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__Entit__18BDCCE8] DEFAULT ('') FOR [EntityCode]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__Depar__19B1F121] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__Servi__1AA6155A] DEFAULT ('') FOR [ServiceLineCode]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__Patie__1B9A3993] DEFAULT ('') FOR [PatientClassCode]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__AgeCo__1C8E5DCC] DEFAULT ('') FOR [AgeCohortCode]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__Value__1D828205] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__IsDel__1E76A63E] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__Entit__097B8958] DEFAULT ((0)) FOR [EntityID]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__Depar__0B63D1CA] DEFAULT ((0)) FOR [DepartmentID]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__Trans__205EEEB0] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__Medic__333CB8FA] DEFAULT ('') FOR [MedicalSurgicalCode]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__Histo__1F6ACA77] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__UnitT__78DB0D3B] DEFAULT ('') FOR [UnitTypeName]; GO
ALTER TABLE [int].[FactFinancialServiceLineCost] ADD CONSTRAINT [DF__FactFinan__Fisca__7FF21F1E] DEFAULT ((0)) FOR [FiscalYearID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactFinancialServiceLineRevenue ------------------
---------------------------------------------
CREATE TABLE [int].[FactFinancialServiceLineRevenue] (
    [RowID] bigint NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [EntityID] int NOT NULL,
    [ForecastDetailID] int NOT NULL,
    [ServiceLineID] int NOT NULL,
    [PatientClassID] int NOT NULL,
    [AgeCohortID] int NOT NULL,
    [MedicalSurgicalID] int NOT NULL,
    [PayorID] int NOT NULL,
    [PayorGroupID] int NOT NULL,
    [FiscalMonthCode] nvarchar(100) NOT NULL,
    [TimeClassCode] nvarchar(100) NOT NULL,
    [ServiceLineCode] nvarchar(100) NOT NULL,
    [PatientClassCode] nvarchar(100) NOT NULL,
    [AgeCohortCode] nvarchar(100) NOT NULL,
    [MedSurgCode] nvarchar(100) NOT NULL,
    [PayorCode] nvarchar(100) NOT NULL,
    [PayorGroupCode] nvarchar(100) NOT NULL,
    [Value] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    [EntityCode] nvarchar(100) NOT NULL,
    [ForecastDetailCode] nvarchar(100) NOT NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [FK__FactFinan__AgeCo__6A02DDFF] FOREIGN KEY ([AgeCohortID]) REFERENCES [fw].[DimAgeCohort] ([AgeCohortID]); GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [FK__FactFinan__Entit__6261BC37] FOREIGN KEY ([EntityID]) REFERENCES [fw].[DimEntity] ([EntityID]); GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [FK__FactFinan__Fisca__5CA8E2E1] FOREIGN KEY ([FiscalMonthID]) REFERENCES [fw].[DimFiscalMonth] ([FiscalMonthID]); GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [FK__FactFinan__Fisca__5E912B53] FOREIGN KEY ([FiscalYearID]) REFERENCES [fw].[DimFiscalYear] ([FiscalYearID]); GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [FK__FactFinan__Forec__644A04A9] FOREIGN KEY ([ForecastDetailID]) REFERENCES [fw].[DimForecastDetail] ([ForecastDetailID]); GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [FK__FactFinan__Medic__6BEB2671] FOREIGN KEY ([MedicalSurgicalID]) REFERENCES [fw].[DimMedicalSurgical] ([MedicalSurgicalID]); GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [FK__FactFinan__Patie__681A958D] FOREIGN KEY ([PatientClassID]) REFERENCES [fw].[DimPatientClass] ([PatientClassID]); GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [FK__FactFinan__Payor__6DD36EE3] FOREIGN KEY ([PayorID]) REFERENCES [fw].[DimPayor] ([PayorID]); GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [FK__FactFinan__Payor__6FBBB755] FOREIGN KEY ([PayorGroupID]) REFERENCES [fw].[DimPayorGroup] ([PayorGroupID]); GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [FK__FactFinan__Servi__66324D1B] FOREIGN KEY ([ServiceLineID]) REFERENCES [fw].[DimServiceLine] ([ServiceLineID]); GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [FK__FactFinan__TimeC__607973C5] FOREIGN KEY ([TimeClassID]) REFERENCES [fw].[DimTimeClass] ([TimeClassID]); GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__Fisca__70AFDB8E] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__TimeC__71A3FFC7] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__Servi__74806C72] DEFAULT ('') FOR [ServiceLineCode]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__Patie__757490AB] DEFAULT ('') FOR [PatientClassCode]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__AgeCo__7668B4E4] DEFAULT ('') FOR [AgeCohortCode]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__MedSu__775CD91D] DEFAULT ('') FOR [MedSurgCode]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__Payor__7850FD56] DEFAULT ('') FOR [PayorCode]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__Payor__7945218F] DEFAULT ('') FOR [PayorGroupCode]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__Entit__616D97FE] DEFAULT ((0)) FOR [EntityID]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__Value__7A3945C8] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__Entit__7AC355AD] DEFAULT ('') FOR [EntityCode]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__IsDel__7B2D6A01] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__Trans__7D15B273] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__Histo__7C218E3A] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__Forec__22CBE970] DEFAULT ('') FOR [ForecastDetailCode]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__Fisca__5BB4BEA8] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__Fisca__5D9D071A] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__TimeC__5F854F8C] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__Forec__6355E070] DEFAULT ((0)) FOR [ForecastDetailID]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__Servi__653E28E2] DEFAULT ((0)) FOR [ServiceLineID]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__Patie__67267154] DEFAULT ((0)) FOR [PatientClassID]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__AgeCo__690EB9C6] DEFAULT ((0)) FOR [AgeCohortID]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__Medic__6AF70238] DEFAULT ((0)) FOR [MedicalSurgicalID]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__Payor__6CDF4AAA] DEFAULT ((0)) FOR [PayorID]; GO
ALTER TABLE [int].[FactFinancialServiceLineRevenue] ADD CONSTRAINT [DF__FactFinan__Payor__6EC7931C] DEFAULT ((0)) FOR [PayorGroupID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactGL ------------------
---------------------------------------------
CREATE TABLE [int].[FactGL] (
    [RowID] int NOT NULL,
    [DepartmentID] int NOT NULL,
    [DepartmentCode] varchar(100) NOT NULL,
    [AccountID] int NOT NULL,
    [AccountCode] varchar(50) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] varchar(20) NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] varchar(20) NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [FiscalMonthCode] varchar(20) NOT NULL,
    [Value] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NULL,
    PRIMARY KEY ([RowID])
);

CREATE UNIQUE CLUSTERED INDEX [CU_Base] ON [int].[FactGL] ([FiscalMonthID], [IsDeleted], [FiscalYearID], [TimeClassID], [DepartmentID], [AccountID], [RowID]);
CREATE NONCLUSTERED INDEX [IX_FactGL_Covering_0] ON [int].[FactGL] ([AccountID]) INCLUDE ([DepartmentID], [FiscalMonthID], [FiscalYearID], [TimeClassID], [Value]);
GO
ALTER TABLE [int].[FactGL] ADD CONSTRAINT [DF__FactGL__TimeClas__5E3009B5] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactGL] ADD CONSTRAINT [DF__FactGL__FiscalMo__7AFE56FB] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactGL] ADD CONSTRAINT [DF_FactGL_FiscalMonthCode] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactGL] ADD CONSTRAINT [DF_INTFACTGLVALUETOTAL] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactGL] ADD CONSTRAINT [DF__FactGL__IsDelete__3FA88703] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactGL] ADD CONSTRAINT [DF__FactGL__HistoryI__6D724D45] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactGL] ADD CONSTRAINT [DF__FactGL__Departme__57830C26] DEFAULT ((0)) FOR [DepartmentID]; GO
ALTER TABLE [int].[FactGL] ADD CONSTRAINT [DF__INT_FactGL_TransactionID ] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactGL] ADD CONSTRAINT [DF__FactGL__Departme__5877305F] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactGL] ADD CONSTRAINT [DF__FactGL__AccountI__596B5498] DEFAULT ((0)) FOR [AccountID]; GO
ALTER TABLE [int].[FactGL] ADD CONSTRAINT [DF__FactGL__AccountC__5A5F78D1] DEFAULT ('') FOR [AccountCode]; GO
ALTER TABLE [int].[FactGL] ADD CONSTRAINT [DF__FactGL__FiscalYe__5B539D0A] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactGL] ADD CONSTRAINT [DF__FactGL__FiscalYe__5C47C143] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactGL] ADD CONSTRAINT [DF__FactGL__TimeClas__5D3BE57C] DEFAULT ((0)) FOR [TimeClassID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactGLDetail ------------------
---------------------------------------------
CREATE TABLE [int].[FactGLDetail] (
    [RowID] bigint NOT NULL,
    [AccountID] int NOT NULL,
    [ComponentID] smallint NOT NULL,
    [ProjectID] int NOT NULL,
    [DepartmentID] int NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [AccountCode] nvarchar(100) NOT NULL,
    [ClientCapitalID] nvarchar(100) NOT NULL,
    [ClientComponentID] nvarchar(100) NOT NULL,
    [ClientDate] datetime NOT NULL,
    [Amount] decimal NOT NULL,
    [DepartmentCode] nvarchar(100) NOT NULL,
    [FiscalMonthCode] nvarchar(100) NOT NULL,
    [FiscalYearCode] nvarchar(100) NOT NULL,
    [IsSampled] bit NOT NULL,
    [ItemDescription] nvarchar(100) NOT NULL,
    [SampleDate] datetime NOT NULL,
    [JournalNumber] nvarchar(100) NOT NULL,
    [JournalLineNumber] nvarchar(100) NOT NULL,
    [CustomText1] nvarchar(100) NOT NULL,
    [CustomText2] nvarchar(100) NOT NULL,
    [CustomText3] nvarchar(100) NOT NULL,
    [CustomText4] nvarchar(100) NOT NULL,
    [CustomText5] nvarchar(100) NOT NULL,
    [CustomDate1] datetime NOT NULL,
    [CustomDate2] datetime NOT NULL,
    [CustomNumeric1] decimal NOT NULL,
    [CustomNumeric2] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    [TransID] nvarchar(100) NOT NULL,
    [BigRowID] bigint NULL,
    PRIMARY KEY ([RowID])
);

CREATE CLUSTERED INDEX [CNU_BASE] ON [int].[FactGLDetail] ([FiscalMonthID], [IsDeleted], [FiscalYearID], [DepartmentID], [AccountID], [ComponentID], [ProjectID]);
CREATE NONCLUSTERED INDEX [NCNU_SampleView] ON [int].[FactGLDetail] ([FiscalMonthID], [IsDeleted], [FiscalYearID], [DepartmentID], [AccountID], [ComponentID], [ProjectID]);
GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [FK__FactGLDet__Accou__741FAE68] FOREIGN KEY ([AccountID]) REFERENCES [fw].[DimAccount] ([AccountID]); GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [FK__FactGLDet__Compo__7607F6DA] FOREIGN KEY ([ComponentID]) REFERENCES [cap].[DimComponent] ([ComponentID]); GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [FK__FactGLDet__Depar__79D887BE] FOREIGN KEY ([DepartmentID]) REFERENCES [fw].[DimDepartment] ([DepartmentID]); GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [FK__FactGLDet__Fisca__7BC0D030] FOREIGN KEY ([FiscalMonthID]) REFERENCES [fw].[DimFiscalMonth] ([FiscalMonthID]); GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [FK__FactGLDet__Fisca__7DA918A2] FOREIGN KEY ([FiscalYearID]) REFERENCES [fw].[DimFiscalYear] ([FiscalYearID]); GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [FK__FactGLDet__Proje__77F03F4C] FOREIGN KEY ([ProjectID]) REFERENCES [cap].[DimProject] ([ProjectID]); GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Clien__0085854D] DEFAULT ('') FOR [ClientComponentID]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Clien__0179A986] DEFAULT (getdate()) FOR [ClientDate]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Amoun__026DCDBF] DEFAULT ((0)) FOR [Amount]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Depar__0361F1F8] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Fisca__04561631] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Fisca__054A3A6A] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__IsSam__063E5EA3] DEFAULT ((0)) FOR [IsSampled]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__ItemD__073282DC] DEFAULT ('') FOR [ItemDescription]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Sampl__0826A715] DEFAULT (getdate()) FOR [SampleDate]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Journ__091ACB4E] DEFAULT ('') FOR [JournalNumber]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Journ__0A0EEF87] DEFAULT ('') FOR [JournalLineNumber]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Custo__0B0313C0] DEFAULT ('') FOR [CustomText1]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Custo__0BF737F9] DEFAULT ('') FOR [CustomText2]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Custo__0CEB5C32] DEFAULT ('') FOR [CustomText3]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Custo__0DDF806B] DEFAULT ('') FOR [CustomText4]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Depar__78E46385] DEFAULT ((0)) FOR [DepartmentID]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Custo__0ED3A4A4] DEFAULT ('') FOR [CustomText5]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Custo__0FC7C8DD] DEFAULT (getdate()) FOR [CustomDate1]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Custo__10BBED16] DEFAULT (getdate()) FOR [CustomDate2]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Custo__11B0114F] DEFAULT ((0)) FOR [CustomNumeric1]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Custo__12A43588] DEFAULT ((0)) FOR [CustomNumeric2]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__IsDel__139859C1] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Trans__1580A233] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Trans__415F2471] DEFAULT ('') FOR [TransID]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Accou__732B8A2F] DEFAULT ((0)) FOR [AccountID]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Compo__7513D2A1] DEFAULT ((0)) FOR [ComponentID]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Proje__76FC1B13] DEFAULT ((0)) FOR [ProjectID]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Fisca__7ACCABF7] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Fisca__7CB4F469] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Accou__7E9D3CDB] DEFAULT ('') FOR [AccountCode]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Histo__148C7DFA] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactGLDetail] ADD CONSTRAINT [DF__FactGLDet__Clien__7F916114] DEFAULT ('') FOR [ClientCapitalID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactGlobalStatistics ------------------
---------------------------------------------
CREATE TABLE [int].[FactGlobalStatistics] (
    [RowID] int NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] nvarchar(2000) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] nvarchar(2000) NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [FiscalMonthCode] nvarchar(2000) NOT NULL,
    [EntityID] int NOT NULL,
    [EntityCode] nvarchar(2000) NOT NULL,
    [DepartmentID] int NOT NULL,
    [DepartmentCode] nvarchar(2000) NOT NULL,
    [AccountID] int NOT NULL,
    [AccountCode] nvarchar(2000) NOT NULL,
    [Value] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactGlobalStatistics] ADD CONSTRAINT [DF__FactGloba__TimeC__04F8FB98] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactGlobalStatistics] ADD CONSTRAINT [DF__FactGloba__Fisca__0034467B] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactGlobalStatistics] ADD CONSTRAINT [DF__FactGloba__Fisca__0404D75F] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactGlobalStatistics] ADD CONSTRAINT [DF__FactGloba__Fisca__7F402242] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactGlobalStatistics] ADD CONSTRAINT [DF__FactGloba__Fisca__0310B326] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactGlobalStatistics] ADD CONSTRAINT [DF__FactGloba__Entit__7D97D0F2] DEFAULT ('') FOR [EntityCode]; GO
ALTER TABLE [int].[FactGlobalStatistics] ADD CONSTRAINT [DF__FactGloba__Depar__021C8EED] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactGlobalStatistics] ADD CONSTRAINT [DF__FactGloba__Accou__01286AB4] DEFAULT ('') FOR [AccountCode]; GO
ALTER TABLE [int].[FactGlobalStatistics] ADD CONSTRAINT [DF__FactGloba__Value__05ED1FD1] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactGlobalStatistics] ADD CONSTRAINT [DF__FactGloba__IsDel__06E1440A] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactGlobalStatistics] ADD CONSTRAINT [DF__FactGloba__Trans__08C98C7C] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactGlobalStatistics] ADD CONSTRAINT [DF__FactGloba__Entit__7CA3ACB9] DEFAULT ((0)) FOR [EntityID]; GO
ALTER TABLE [int].[FactGlobalStatistics] ADD CONSTRAINT [DF__FactGloba__Histo__07D56843] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactImportProvider ------------------
---------------------------------------------
CREATE TABLE [int].[FactImportProvider] (
    [RowID] int NOT NULL,
    [DepartmentID] int NOT NULL,
    [ProviderID] int NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [OBForecastDetailID] int NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [AccountRollup] nvarchar(2000) NOT NULL,
    [DepartmentCode] nvarchar(2000) NOT NULL,
    [FiscalMonthCode] nvarchar(2000) NOT NULL,
    [FiscalYearCode] nvarchar(2000) NOT NULL,
    [ProviderCode] nvarchar(2000) NOT NULL,
    [TimeClassCode] nvarchar(2000) NOT NULL,
    [Value] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    PRIMARY KEY ([RowID])
);

CREATE NONCLUSTERED INDEX [NCNU_SampleView] ON [int].[FactImportProvider] ([IsDeleted], [FiscalMonthID], [TimeClassID], [FiscalYearID], [DepartmentID], [ProviderID], [OBForecastDetailID]);
GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [FK__FactImpor__Depar__4CB63923] FOREIGN KEY ([DepartmentID]) REFERENCES [fw].[DimDepartment] ([DepartmentID]); GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [FK__FactImpor__Fisca__526F1279] FOREIGN KEY ([FiscalMonthID]) REFERENCES [fw].[DimFiscalMonth] ([FiscalMonthID]); GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [FK__FactImpor__Fisca__54575AEB] FOREIGN KEY ([FiscalYearID]) REFERENCES [fw].[DimFiscalYear] ([FiscalYearID]); GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [FK__FactImpor__OBFor__563FA35D] FOREIGN KEY ([OBForecastDetailID]) REFERENCES [ob].[DimOBForecastDetail] ([OBForecastDetailID]); GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [FK__FactImpor__Provi__4E9E8195] FOREIGN KEY ([ProviderID]) REFERENCES [fw].[DimProvider] ([ProviderID]); GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [FK__FactImpor__TimeC__5827EBCF] FOREIGN KEY ([TimeClassID]) REFERENCES [fw].[DimTimeClass] ([TimeClassID]); GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [DF__FactImpor__Provi__4DAA5D5C] DEFAULT ((0)) FOR [ProviderID]; GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [DF__FactImpor__Fisca__517AEE40] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [DF__FactImpor__Fisca__536336B2] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [DF__FactImpor__Histo__61B15609] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [DF__FactImpor__OBFor__554B7F24] DEFAULT ((0)) FOR [OBForecastDetailID]; GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [DF__FactImpor__TimeC__5733C796] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [DF__FactImpor__Accou__591C1008] DEFAULT ('') FOR [AccountRollup]; GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [DF__FactImpor__Depar__5A103441] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [DF__FactImpor__Fisca__5B04587A] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [DF__FactImpor__Fisca__5BF87CB3] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [DF__FactImpor__Provi__5CECA0EC] DEFAULT ('') FOR [ProviderCode]; GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [DF__FactImpor__TimeC__5DE0C525] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [DF__FactImpor__Value__5FC90D97] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [DF__FactImpor__IsDel__60BD31D0] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [DF__FactImpor__Trans__62A57A42] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactImportProvider] ADD CONSTRAINT [DF__FactImpor__Depar__4BC214EA] DEFAULT ((0)) FOR [DepartmentID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactIntERAsset ------------------
---------------------------------------------
CREATE TABLE [int].[FactIntERAsset] (
    [RowID] int NOT NULL,
    [DepartmentID] int NOT NULL,
    [VendorID] int NOT NULL,
    [GlobalTypeID] int NOT NULL,
    [AssetCode] nvarchar(100) NOT NULL,
    [AssetName] nvarchar(100) NOT NULL,
    [DepartmentCode] nvarchar(100) NOT NULL,
    [DepartmentDescription] nvarchar(100) NOT NULL,
    [EntityCode] nvarchar(100) NOT NULL,
    [EntityName] nvarchar(100) NOT NULL,
    [AssetCategory] nvarchar(100) NOT NULL,
    [VendorCode] nvarchar(100) NOT NULL,
    [VendorName] nvarchar(100) NOT NULL,
    [Model] nvarchar(100) NOT NULL,
    [Serial] nvarchar(100) NOT NULL,
    [PurchaseDate] datetime NOT NULL,
    [PurchaseCost] decimal NOT NULL,
    [ReplacementCost] decimal NOT NULL,
    [Downtime] decimal NOT NULL,
    [MaintenanceCost] decimal NOT NULL,
    [ServiceStatus] nvarchar(100) NOT NULL,
    [Volume] decimal NOT NULL,
    [CustomMetricText1] nvarchar(100) NOT NULL,
    [CustomMetricText2] nvarchar(100) NOT NULL,
    [CustomMetricNumeric1] decimal NOT NULL,
    [CustomMetricNumeric2] decimal NOT NULL,
    [CustomText1] nvarchar(100) NOT NULL,
    [CustomText2] nvarchar(100) NOT NULL,
    [CustomText3] nvarchar(100) NOT NULL,
    [CustomText4] nvarchar(100) NOT NULL,
    [CustomText5] nvarchar(100) NOT NULL,
    [CustomNumeric1] decimal NOT NULL,
    [CustomNumeric2] decimal NOT NULL,
    [CustomNumeric3] decimal NOT NULL,
    [CustomNumeric4] decimal NOT NULL,
    [CustomNumeric5] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    [AssetStatusID] int NOT NULL,
    [AssetStatusCode] nvarchar(100) NOT NULL,
    [ManufacturerID] int NOT NULL,
    [ManufacturerCode] nvarchar(100) NOT NULL,
    [ManufacturerDescription] nvarchar(100) NOT NULL,
    [CustomMetricNumeric3] decimal NOT NULL,
    [CustomMetricNumeric4] decimal NOT NULL,
    [CustomMetricNumeric5] decimal NOT NULL,
    [CustomMetricNumeric6] decimal NOT NULL,
    [CustomMetricNumeric7] decimal NOT NULL,
    [CustomMetricNumeric8] decimal NOT NULL,
    [CustomMetricNumeric9] decimal NOT NULL,
    [CustomMetricNumeric10] decimal NOT NULL,
    [CustomMetricNumeric11] decimal NOT NULL,
    [CustomMetricNumeric12] decimal NOT NULL,
    [CustomMetricNumeric13] decimal NOT NULL,
    [CustomMetricNumeric14] decimal NOT NULL,
    [CustomMetricNumeric15] decimal NOT NULL,
    [CustomMetricText3] nvarchar(100) NOT NULL,
    [CustomMetricText4] nvarchar(100) NOT NULL,
    [CustomMetricText5] nvarchar(100) NOT NULL,
    [CustomMetricText6] nvarchar(100) NOT NULL,
    [CustomMetricText7] nvarchar(100) NOT NULL,
    [CustomMetricText8] nvarchar(100) NOT NULL,
    [CustomMetricText9] nvarchar(100) NOT NULL,
    [CustomMetricText10] nvarchar(100) NOT NULL,
    [CustomMetricText11] nvarchar(100) NOT NULL,
    [CustomMetricText12] nvarchar(100) NOT NULL,
    [CustomMetricText13] nvarchar(100) NOT NULL,
    [CustomMetricText14] nvarchar(100) NOT NULL,
    [CustomMetricText15] nvarchar(100) NOT NULL,
    [CriticalityStatus] nvarchar(100) NOT NULL,
    [EndOfLifeSupportNotification] nvarchar(100) NOT NULL,
    [EndOfLifeSupportDate] datetime NOT NULL,
    [AssetOwnership] nvarchar(100) NOT NULL,
    [SupportedBy] nvarchar(100) NOT NULL,
    [CMWorkOrderCount] decimal NOT NULL,
    [CMLaborHours] decimal NOT NULL,
    [CMLaborCosts] decimal NOT NULL,
    [CMPartsCosts] decimal NOT NULL,
    [PMWorkOrderCount] decimal NOT NULL,
    [PMLaborHours] decimal NOT NULL,
    [PMLaborCosts] decimal NOT NULL,
    [PMPartsCosts] decimal NOT NULL,
    [LastUpdateDate] datetime NOT NULL,
    [OperatingSystem] nvarchar(100) NOT NULL,
    [NetworkTechnology] nvarchar(100) NOT NULL,
    [FleetManaged] nvarchar(100) NOT NULL,
    [EquipmentType] nvarchar(100) NOT NULL,
    [IsCapital] bit NOT NULL,
    [CustomText6] nvarchar(100) NOT NULL,
    [CustomText7] nvarchar(100) NOT NULL,
    [CustomText8] nvarchar(100) NOT NULL,
    [CustomText9] nvarchar(100) NOT NULL,
    [CustomText10] nvarchar(100) NOT NULL,
    [CustomNumeric6] decimal NOT NULL,
    [CustomNumeric7] decimal NOT NULL,
    [CustomNumeric8] decimal NOT NULL,
    [CustomNumeric9] decimal NOT NULL,
    [CustomNumeric10] decimal NOT NULL,
    [CustomDate1] datetime NOT NULL,
    [CustomDate2] datetime NOT NULL,
    [CustomDate3] datetime NOT NULL,
    [CustomDate4] datetime NOT NULL,
    [CustomDate5] datetime NOT NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [FK__FactIntER__Depar__61F61135] FOREIGN KEY ([DepartmentID]) REFERENCES [fw].[DimDepartment] ([DepartmentID]); GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [FK__FactIntER__Globa__65C6A219] FOREIGN KEY ([GlobalTypeID]) REFERENCES [cap].[DimGlobalType] ([GlobalTypeID]); GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [FK__FactIntER__Vendo__63DE59A7] FOREIGN KEY ([VendorID]) REFERENCES [cap].[DimVendor] ([VendorID]); GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__007A9855] DEFAULT ('') FOR [CustomText5]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__00C050A2] DEFAULT ('') FOR [CustomMetricText8]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__016EBC8E] DEFAULT ((0)) FOR [CustomNumeric1]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__01B474DB] DEFAULT ('') FOR [CustomMetricText9]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__0262E0C7] DEFAULT ((0)) FOR [CustomNumeric2]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__02A89914] DEFAULT ('') FOR [CustomMetricText10]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Asset__02E9F51A] DEFAULT ((0)) FOR [AssetStatusID]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__03570500] DEFAULT ((0)) FOR [CustomNumeric3]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__039CBD4D] DEFAULT ('') FOR [CustomMetricText11]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__044B2939] DEFAULT ((0)) FOR [CustomNumeric4]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__0490E186] DEFAULT ('') FOR [CustomMetricText12]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__053F4D72] DEFAULT ((0)) FOR [CustomNumeric5]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__058505BF] DEFAULT ('') FOR [CustomMetricText13]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__IsDel__063371AB] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__067929F8] DEFAULT ('') FOR [CustomMetricText14]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__076D4E31] DEFAULT ('') FOR [CustomMetricText15]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Trans__081BBA1D] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Criti__0861726A] DEFAULT ('') FOR [CriticalityStatus]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__EndOf__095596A3] DEFAULT ('') FOR [EndOfLifeSupportNotification]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__EndOf__0A49BADC] DEFAULT (getdate()) FOR [EndOfLifeSupportDate]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Asset__0B3DDF15] DEFAULT ('') FOR [AssetOwnership]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Suppo__0C32034E] DEFAULT ('') FOR [SupportedBy]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__CMWor__0D262787] DEFAULT ((0)) FOR [CMWorkOrderCount]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__CMLab__0E1A4BC0] DEFAULT ((0)) FOR [CMLaborHours]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__CMLab__0F0E6FF9] DEFAULT ((0)) FOR [CMLaborCosts]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Histo__072795E4] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__CMPar__10029432] DEFAULT ((0)) FOR [CMPartsCosts]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__PMWor__10F6B86B] DEFAULT ((0)) FOR [PMWorkOrderCount]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__PMLab__11EADCA4] DEFAULT ((0)) FOR [PMLaborHours]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Asset__122C38AA] DEFAULT ('') FOR [AssetStatusCode]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__PMLab__12DF00DD] DEFAULT ((0)) FOR [PMLaborCosts]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__PMPar__13D32516] DEFAULT ((0)) FOR [PMPartsCosts]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__LastU__14C7494F] DEFAULT (getdate()) FOR [LastUpdateDate]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Opera__15BB6D88] DEFAULT ('') FOR [OperatingSystem]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Netwo__16AF91C1] DEFAULT ('') FOR [NetworkTechnology]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Fleet__17A3B5FA] DEFAULT ('') FOR [FleetManaged]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Equip__1897DA33] DEFAULT ('') FOR [EquipmentType]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__IsCap__198BFE6C] DEFAULT ((0)) FOR [IsCapital]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Manuf__391D7F47] DEFAULT ((0)) FOR [ManufacturerID]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Manuf__3A11A380] DEFAULT ('') FOR [ManufacturerCode]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Manuf__3B05C7B9] DEFAULT ('') FOR [ManufacturerDescription]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__56C7E69B] DEFAULT ('') FOR [CustomText6]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__57BC0AD4] DEFAULT ('') FOR [CustomText7]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__58B02F0D] DEFAULT ('') FOR [CustomText8]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__59A45346] DEFAULT ('') FOR [CustomText9]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__5A98777F] DEFAULT ('') FOR [CustomText10]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__5B8C9BB8] DEFAULT ((0)) FOR [CustomNumeric6]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__5C80BFF1] DEFAULT ((0)) FOR [CustomNumeric7]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__5D74E42A] DEFAULT ((0)) FOR [CustomNumeric8]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__5E690863] DEFAULT ((0)) FOR [CustomNumeric9]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__5F5D2C9C] DEFAULT ((0)) FOR [CustomNumeric10]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__605150D5] DEFAULT (getdate()) FOR [CustomDate1]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__6145750E] DEFAULT (getdate()) FOR [CustomDate2]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__62399947] DEFAULT (getdate()) FOR [CustomDate3]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Vendo__62EA356E] DEFAULT ((0)) FOR [VendorID]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__632DBD80] DEFAULT (getdate()) FOR [CustomDate4]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__6421E1B9] DEFAULT (getdate()) FOR [CustomDate5]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Globa__64D27DE0] DEFAULT ((0)) FOR [GlobalTypeID]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Asset__66BAC652] DEFAULT ('') FOR [AssetCode]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Asset__67AEEA8B] DEFAULT ('') FOR [AssetName]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Depar__68A30EC4] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Depar__699732FD] DEFAULT ('') FOR [DepartmentDescription]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Entit__6A8B5736] DEFAULT ('') FOR [EntityCode]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Entit__6B7F7B6F] DEFAULT ('') FOR [EntityName]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Asset__6C739FA8] DEFAULT ('') FOR [AssetCategory]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Vendo__6D67C3E1] DEFAULT ('') FOR [VendorCode]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Vendo__6E5BE81A] DEFAULT ('') FOR [VendorName]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__6F95C4A0] DEFAULT ((0)) FOR [CustomMetricNumeric3]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Model__7044308C] DEFAULT ('') FOR [Model]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__7089E8D9] DEFAULT ((0)) FOR [CustomMetricNumeric4]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Seria__713854C5] DEFAULT ('') FOR [Serial]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__717E0D12] DEFAULT ((0)) FOR [CustomMetricNumeric5]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Purch__722C78FE] DEFAULT (getdate()) FOR [PurchaseDate]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__7272314B] DEFAULT ((0)) FOR [CustomMetricNumeric6]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Purch__73209D37] DEFAULT ((0)) FOR [PurchaseCost]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__73665584] DEFAULT ((0)) FOR [CustomMetricNumeric7]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Repla__7414C170] DEFAULT ((0)) FOR [ReplacementCost]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__745A79BD] DEFAULT ((0)) FOR [CustomMetricNumeric8]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Downt__7508E5A9] DEFAULT ((0)) FOR [Downtime]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__754E9DF6] DEFAULT ((0)) FOR [CustomMetricNumeric9]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Maint__75FD09E2] DEFAULT ((0)) FOR [MaintenanceCost]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__7642C22F] DEFAULT ((0)) FOR [CustomMetricNumeric10]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Servi__76F12E1B] DEFAULT ('') FOR [ServiceStatus]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__7736E668] DEFAULT ((0)) FOR [CustomMetricNumeric11]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Volum__77E55254] DEFAULT ((0)) FOR [Volume]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__782B0AA1] DEFAULT ((0)) FOR [CustomMetricNumeric12]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__78D9768D] DEFAULT ('') FOR [CustomMetricText1]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__791F2EDA] DEFAULT ((0)) FOR [CustomMetricNumeric13]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__79CD9AC6] DEFAULT ('') FOR [CustomMetricText2]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__7A135313] DEFAULT ((0)) FOR [CustomMetricNumeric14]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__7AC1BEFF] DEFAULT ((0)) FOR [CustomMetricNumeric1]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__7B07774C] DEFAULT ((0)) FOR [CustomMetricNumeric15]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__7BB5E338] DEFAULT ((0)) FOR [CustomMetricNumeric2]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__7BFB9B85] DEFAULT ('') FOR [CustomMetricText3]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__7CAA0771] DEFAULT ('') FOR [CustomText1]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__7CEFBFBE] DEFAULT ('') FOR [CustomMetricText4]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Depar__6101ECFC] DEFAULT ((0)) FOR [DepartmentID]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__7D9E2BAA] DEFAULT ('') FOR [CustomText2]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__7DE3E3F7] DEFAULT ('') FOR [CustomMetricText5]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__7E924FE3] DEFAULT ('') FOR [CustomText3]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__7ED80830] DEFAULT ('') FOR [CustomMetricText6]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__7F86741C] DEFAULT ('') FOR [CustomText4]; GO
ALTER TABLE [int].[FactIntERAsset] ADD CONSTRAINT [DF__FactIntER__Custo__7FCC2C69] DEFAULT ('') FOR [CustomMetricText7]; GO

---------------------------------------------

---------------------------------------------
-- int.FactInventoryDetail ------------------
---------------------------------------------
CREATE TABLE [int].[FactInventoryDetail] (
    [RowID] bigint NOT NULL,
    [AccountID] int NOT NULL,
    [DepartmentID] int NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [AccountCode] nvarchar(100) NOT NULL,
    [FiscalYearCode] nvarchar(100) NOT NULL,
    [FiscalMonthCode] nvarchar(100) NOT NULL,
    [DepartmentCode] nvarchar(100) NOT NULL,
    [ItemNumber] nvarchar(100) NOT NULL,
    [ItemDescription] nvarchar(100) NOT NULL,
    [Quantity] decimal NOT NULL,
    [InventoryCost] decimal NOT NULL,
    [TransID] nvarchar(100) NOT NULL,
    [IsSampled] bit NOT NULL,
    [SampleDate] datetime NOT NULL,
    [CustomText1] nvarchar(100) NOT NULL,
    [CustomText2] nvarchar(100) NOT NULL,
    [CustomText3] nvarchar(100) NOT NULL,
    [CustomText4] nvarchar(100) NOT NULL,
    [CustomText5] nvarchar(100) NOT NULL,
    [CustomNumeric1] decimal NOT NULL,
    [CustomNumeric2] decimal NOT NULL,
    [CustomDate1] datetime NOT NULL,
    [CustomDate2] datetime NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    PRIMARY KEY ([RowID])
);

CREATE CLUSTERED INDEX [CNU_BASE] ON [int].[FactInventoryDetail] ([FiscalMonthID], [IsDeleted], [FiscalYearID], [DepartmentID], [AccountID]);
CREATE NONCLUSTERED INDEX [NCNU_SampleView] ON [int].[FactInventoryDetail] ([FiscalMonthID], [IsDeleted], [FiscalYearID], [DepartmentID], [AccountID]);
GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [FK__FactInven__Accou__431262B9] FOREIGN KEY ([AccountID]) REFERENCES [fw].[DimAccount] ([AccountID]); GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [FK__FactInven__Depar__44FAAB2B] FOREIGN KEY ([DepartmentID]) REFERENCES [fw].[DimDepartment] ([DepartmentID]); GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [FK__FactInven__Fisca__46E2F39D] FOREIGN KEY ([FiscalMonthID]) REFERENCES [fw].[DimFiscalMonth] ([FiscalMonthID]); GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [FK__FactInven__Fisca__48CB3C0F] FOREIGN KEY ([FiscalYearID]) REFERENCES [fw].[DimFiscalYear] ([FiscalYearID]); GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Histo__5DC658F5] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Accou__421E3E80] DEFAULT ((0)) FOR [AccountID]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Fisca__45EECF64] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Fisca__47D717D6] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Accou__49BF6048] DEFAULT ('') FOR [AccountCode]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Fisca__4AB38481] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Fisca__4BA7A8BA] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Depar__4C9BCCF3] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__ItemN__4D8FF12C] DEFAULT ('') FOR [ItemNumber]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__ItemD__4E841565] DEFAULT ('') FOR [ItemDescription]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Quant__4F78399E] DEFAULT ((0)) FOR [Quantity]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Inven__506C5DD7] DEFAULT ((0)) FOR [InventoryCost]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Trans__51608210] DEFAULT ('') FOR [TransID]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__IsSam__5254A649] DEFAULT ((0)) FOR [IsSampled]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Sampl__5348CA82] DEFAULT (getdate()) FOR [SampleDate]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Custo__543CEEBB] DEFAULT ('') FOR [CustomText1]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Custo__553112F4] DEFAULT ('') FOR [CustomText2]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Custo__5625372D] DEFAULT ('') FOR [CustomText3]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Custo__57195B66] DEFAULT ('') FOR [CustomText4]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Custo__580D7F9F] DEFAULT ('') FOR [CustomText5]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Custo__5901A3D8] DEFAULT ((0)) FOR [CustomNumeric1]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Custo__59F5C811] DEFAULT ((0)) FOR [CustomNumeric2]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Custo__5AE9EC4A] DEFAULT (getdate()) FOR [CustomDate1]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Custo__5BDE1083] DEFAULT (getdate()) FOR [CustomDate2]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__IsDel__5CD234BC] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Trans__5EBA7D2E] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactInventoryDetail] ADD CONSTRAINT [DF__FactInven__Depar__440686F2] DEFAULT ((0)) FOR [DepartmentID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactMRImportPODetail ------------------
---------------------------------------------
CREATE TABLE [int].[FactMRImportPODetail] (
    [RowID] int NOT NULL,
    [AccountID] int NOT NULL,
    [DepartmentID] int NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [LineNumber] nvarchar(100) NOT NULL,
    [LineDescription] nvarchar(100) NOT NULL,
    [ClientDate] datetime NOT NULL,
    [Quantity] decimal NOT NULL,
    [CostPerItem] decimal NOT NULL,
    [Total] decimal NULL,
    [VendorCode] nvarchar(100) NOT NULL,
    [VendorName] nvarchar(100) NOT NULL,
    [AccountCode] nvarchar(100) NOT NULL,
    [FiscalYearCode] nvarchar(100) NOT NULL,
    [FiscalMonthCode] nvarchar(100) NOT NULL,
    [DepartmentCode] nvarchar(100) NOT NULL,
    [PONumber] nvarchar(100) NOT NULL,
    [ItemNumber] nvarchar(100) NOT NULL,
    [CustomText1] nvarchar(100) NOT NULL,
    [CustomText2] nvarchar(100) NOT NULL,
    [CustomText3] nvarchar(100) NOT NULL,
    [CustomText4] nvarchar(100) NOT NULL,
    [CustomText5] nvarchar(100) NOT NULL,
    [CustomDate1] datetime NOT NULL,
    [CustomDate2] datetime NOT NULL,
    [CustomNumeric1] decimal NOT NULL,
    [CustomNumeric2] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    [IsSampled] bit NOT NULL,
    [SampleDate] datetime NOT NULL,
    PRIMARY KEY ([RowID])
);

CREATE CLUSTERED INDEX [CNU_BASE] ON [int].[FactMRImportPODetail] ([FiscalMonthID], [IsDeleted], [FiscalYearID], [DepartmentID], [AccountID]);
CREATE NONCLUSTERED INDEX [NCNU_SampleView] ON [int].[FactMRImportPODetail] ([FiscalMonthID], [IsDeleted], [FiscalYearID], [DepartmentID], [AccountID]);
GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [FK__FactMRImp__Accou__710E3793] FOREIGN KEY ([AccountID]) REFERENCES [fw].[DimAccount] ([AccountID]); GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [FK__FactMRImp__Depar__72F68005] FOREIGN KEY ([DepartmentID]) REFERENCES [fw].[DimDepartment] ([DepartmentID]); GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [FK__FactMRImp__Fisca__74DEC877] FOREIGN KEY ([FiscalMonthID]) REFERENCES [fw].[DimFiscalMonth] ([FiscalMonthID]); GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [FK__FactMRImp__Fisca__76C710E9] FOREIGN KEY ([FiscalYearID]) REFERENCES [fw].[DimFiscalYear] ([FiscalYearID]); GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Fisca__00507B23] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Depar__01449F5C] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__PONum__0238C395] DEFAULT ('') FOR [PONumber]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__ItemN__032CE7CE] DEFAULT ('') FOR [ItemNumber]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Custo__04210C07] DEFAULT ('') FOR [CustomText1]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Custo__05153040] DEFAULT ('') FOR [CustomText2]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Custo__06095479] DEFAULT ('') FOR [CustomText3]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Custo__06FD78B2] DEFAULT ('') FOR [CustomText4]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Custo__07F19CEB] DEFAULT ('') FOR [CustomText5]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Custo__08E5C124] DEFAULT (getdate()) FOR [CustomDate1]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Custo__09D9E55D] DEFAULT (getdate()) FOR [CustomDate2]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Depar__72025BCC] DEFAULT ((0)) FOR [DepartmentID]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Custo__0ACE0996] DEFAULT ((0)) FOR [CustomNumeric1]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Custo__0BC22DCF] DEFAULT ((0)) FOR [CustomNumeric2]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__IsDel__0CB65208] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Trans__0E9E9A7A] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__IsSam__3E4DAD9C] DEFAULT ((0)) FOR [IsSampled]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Sampl__3F41D1D5] DEFAULT (getdate()) FOR [SampleDate]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Accou__701A135A] DEFAULT ((0)) FOR [AccountID]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Fisca__73EAA43E] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Fisca__75D2ECB0] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__LineN__77BB3522] DEFAULT ('') FOR [LineNumber]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__LineD__78AF595B] DEFAULT ('') FOR [LineDescription]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Histo__0DAA7641] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Clien__79A37D94] DEFAULT (getdate()) FOR [ClientDate]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Quant__7A97A1CD] DEFAULT ((0)) FOR [Quantity]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__CostP__7B8BC606] DEFAULT ((0)) FOR [CostPerItem]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Vendo__7C7FEA3F] DEFAULT ('') FOR [VendorCode]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Vendo__7D740E78] DEFAULT ('') FOR [VendorName]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Accou__7E6832B1] DEFAULT ('') FOR [AccountCode]; GO
ALTER TABLE [int].[FactMRImportPODetail] ADD CONSTRAINT [DF__FactMRImp__Fisca__7F5C56EA] DEFAULT ('') FOR [FiscalYearCode]; GO

---------------------------------------------

---------------------------------------------
-- int.FactMeditechPatientADT ------------------
---------------------------------------------
CREATE TABLE [int].[FactMeditechPatientADT] (
    [RowID] bigint NOT NULL,
    [EncounterRecordNumber] nvarchar(100) NOT NULL,
    [PatientClass] nvarchar(100) NOT NULL,
    [EventTypeCode] nvarchar(100) NOT NULL,
    [EventTypeCodeDescription] nvarchar(100) NOT NULL,
    [DepartmentCode] nvarchar(100) NOT NULL,
    [DepartmentDescription] nvarchar(100) NOT NULL,
    [RoomNumber] nvarchar(100) NOT NULL,
    [BedNumber] nvarchar(100) NOT NULL,
    [EffectiveDateTimeStamp] datetime NOT NULL,
    [EventDate] datetime NOT NULL,
    [EventSequenceNumber] int NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactMeditechPatientADT] ADD CONSTRAINT [DF__FactMedit__Encou__1B9B36B4] DEFAULT ('') FOR [EncounterRecordNumber]; GO
ALTER TABLE [int].[FactMeditechPatientADT] ADD CONSTRAINT [DF__FactMedit__Patie__1C8F5AED] DEFAULT ('') FOR [PatientClass]; GO
ALTER TABLE [int].[FactMeditechPatientADT] ADD CONSTRAINT [DF__FactMedit__Event__1D837F26] DEFAULT ('') FOR [EventTypeCode]; GO
ALTER TABLE [int].[FactMeditechPatientADT] ADD CONSTRAINT [DF__FactMedit__Event__1E77A35F] DEFAULT ('') FOR [EventTypeCodeDescription]; GO
ALTER TABLE [int].[FactMeditechPatientADT] ADD CONSTRAINT [DF__FactMedit__Depar__1F6BC798] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactMeditechPatientADT] ADD CONSTRAINT [DF__FactMedit__Depar__205FEBD1] DEFAULT ('') FOR [DepartmentDescription]; GO
ALTER TABLE [int].[FactMeditechPatientADT] ADD CONSTRAINT [DF__FactMedit__RoomN__2154100A] DEFAULT ('') FOR [RoomNumber]; GO
ALTER TABLE [int].[FactMeditechPatientADT] ADD CONSTRAINT [DF__FactMedit__BedNu__22483443] DEFAULT ('') FOR [BedNumber]; GO
ALTER TABLE [int].[FactMeditechPatientADT] ADD CONSTRAINT [DF__FactMedit__Effec__233C587C] DEFAULT (getdate()) FOR [EffectiveDateTimeStamp]; GO
ALTER TABLE [int].[FactMeditechPatientADT] ADD CONSTRAINT [DF__FactMedit__Event__24307CB5] DEFAULT (getdate()) FOR [EventDate]; GO
ALTER TABLE [int].[FactMeditechPatientADT] ADD CONSTRAINT [DF__FactMedit__Event__2524A0EE] DEFAULT ((0)) FOR [EventSequenceNumber]; GO
ALTER TABLE [int].[FactMeditechPatientADT] ADD CONSTRAINT [DF__FactMedit__IsDel__2618C527] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactMeditechPatientADT] ADD CONSTRAINT [DF__FactMedit__Trans__28010D99] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactMeditechPatientADT] ADD CONSTRAINT [DF__FactMedit__Histo__270CE960] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactOBImportPayor ------------------
---------------------------------------------
CREATE TABLE [int].[FactOBImportPayor] (
    [RowID] int NOT NULL,
    [DepartmentID] int NOT NULL,
    [PayorID] int NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [OBForecastDetailID] int NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [DepartmentCode] nvarchar(2000) NOT NULL,
    [PayorCode] nvarchar(2000) NOT NULL,
    [FiscalYearCode] nvarchar(2000) NOT NULL,
    [FiscalMonthCode] nvarchar(2000) NOT NULL,
    [OBForecastDetailCode] nvarchar(2000) NOT NULL,
    [TimeClassCode] nvarchar(2000) NOT NULL,
    [Value] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    [PatientClassID] int NOT NULL,
    [EntityID] int NOT NULL,
    [PatientClassCode] nvarchar(2000) NOT NULL,
    [EntityCode] nvarchar(2000) NOT NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactOBImportPayor] ADD CONSTRAINT [DF__FactOBImp__Histo__2BA1C020] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactOBImportPayor] ADD CONSTRAINT [DF__FactOBImp__Fisca__221855E6] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactOBImportPayor] ADD CONSTRAINT [DF__FactOBImp__Fisca__230C7A1F] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactOBImportPayor] ADD CONSTRAINT [DF__FactOBImp__Depar__24009E58] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactOBImportPayor] ADD CONSTRAINT [DF__FactOBImp__Payor__24F4C291] DEFAULT ('') FOR [PayorCode]; GO
ALTER TABLE [int].[FactOBImportPayor] ADD CONSTRAINT [DF__FactOBImp__Fisca__25E8E6CA] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactOBImportPayor] ADD CONSTRAINT [DF__FactOBImp__Fisca__26DD0B03] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactOBImportPayor] ADD CONSTRAINT [DF__FactOBImp__OBFor__27D12F3C] DEFAULT ('') FOR [OBForecastDetailCode]; GO
ALTER TABLE [int].[FactOBImportPayor] ADD CONSTRAINT [DF__FactOBImp__TimeC__28C55375] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactOBImportPayor] ADD CONSTRAINT [DF__FactOBImp__Value__29B977AE] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactOBImportPayor] ADD CONSTRAINT [DF__FactOBImp__IsDel__2AAD9BE7] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactOBImportPayor] ADD CONSTRAINT [DF__FactOBImp__Trans__2C95E459] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactOBImportPayor] ADD CONSTRAINT [DF__FactOBImp__Entit__4EEAFC5D] DEFAULT ((0)) FOR [EntityID]; GO
ALTER TABLE [int].[FactOBImportPayor] ADD CONSTRAINT [DF__FactOBImp__Patie__4DF6D824] DEFAULT ((0)) FOR [PatientClassID]; GO
ALTER TABLE [int].[FactOBImportPayor] ADD CONSTRAINT [DF__FactOBImp__Patie__4FDF2096] DEFAULT ('') FOR [PatientClassCode]; GO
ALTER TABLE [int].[FactOBImportPayor] ADD CONSTRAINT [DF__FactOBImp__Entit__50D344CF] DEFAULT ('') FOR [EntityCode]; GO

---------------------------------------------

---------------------------------------------
-- int.FactOBImportPayorGroup ------------------
---------------------------------------------
CREATE TABLE [int].[FactOBImportPayorGroup] (
    [RowID] int NOT NULL,
    [DepartmentID] int NOT NULL,
    [PayorGroupID] int NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [OBForecastDetailID] int NOT NULL,
    [DepartmentCode] nvarchar(2000) NOT NULL,
    [PayorGroupCode] nvarchar(2000) NOT NULL,
    [FiscalMonthCode] nvarchar(2000) NOT NULL,
    [FiscalYearCode] nvarchar(2000) NOT NULL,
    [TimeClassCode] nvarchar(2000) NOT NULL,
    [OBForecastDetailCode] nvarchar(2000) NOT NULL,
    [Value] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    [PatientClassID] int NOT NULL,
    [EntityID] int NOT NULL,
    [PatientClassCode] nvarchar(2000) NOT NULL,
    [EntityCode] nvarchar(2000) NOT NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactOBImportPayorGroup] ADD CONSTRAINT [DF__FactOBImp__Fisca__409CDD06] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactOBImportPayorGroup] ADD CONSTRAINT [DF__FactOBImp__Fisca__4191013F] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactOBImportPayorGroup] ADD CONSTRAINT [DF__FactOBImp__Depar__42852578] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactOBImportPayorGroup] ADD CONSTRAINT [DF__FactOBImp__Payor__437949B1] DEFAULT ('') FOR [PayorGroupCode]; GO
ALTER TABLE [int].[FactOBImportPayorGroup] ADD CONSTRAINT [DF__FactOBImp__Fisca__446D6DEA] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactOBImportPayorGroup] ADD CONSTRAINT [DF__FactOBImp__Fisca__45619223] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactOBImportPayorGroup] ADD CONSTRAINT [DF__FactOBImp__TimeC__4655B65C] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactOBImportPayorGroup] ADD CONSTRAINT [DF__FactOBImp__OBFor__4749DA95] DEFAULT ('') FOR [OBForecastDetailCode]; GO
ALTER TABLE [int].[FactOBImportPayorGroup] ADD CONSTRAINT [DF__FactOBImp__Value__483DFECE] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactOBImportPayorGroup] ADD CONSTRAINT [DF__FactOBImp__IsDel__49322307] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactOBImportPayorGroup] ADD CONSTRAINT [DF__FactOBImp__Trans__4B1A6B79] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactOBImportPayorGroup] ADD CONSTRAINT [DF__FactOBImp__Patie__51C76908] DEFAULT ((0)) FOR [PatientClassID]; GO
ALTER TABLE [int].[FactOBImportPayorGroup] ADD CONSTRAINT [DF__FactOBImp__Patie__53AFB17A] DEFAULT ('') FOR [PatientClassCode]; GO
ALTER TABLE [int].[FactOBImportPayorGroup] ADD CONSTRAINT [DF__FactOBImp__Entit__54A3D5B3] DEFAULT ('') FOR [EntityCode]; GO
ALTER TABLE [int].[FactOBImportPayorGroup] ADD CONSTRAINT [DF__FactOBImp__Entit__52BB8D41] DEFAULT ((0)) FOR [EntityID]; GO
ALTER TABLE [int].[FactOBImportPayorGroup] ADD CONSTRAINT [DF__FactOBImp__Histo__4A264740] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactOBPayor ------------------
---------------------------------------------
CREATE TABLE [int].[FactOBPayor] (
    [RowID] int NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] nvarchar(2000) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] nvarchar(2000) NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [FiscalMonthCode] nvarchar(2000) NOT NULL,
    [OBReimbursementPlanID] int NOT NULL,
    [ReimbursementPlan] nvarchar(2000) NOT NULL,
    [CareSettingID] int NOT NULL,
    [CareSettingCode] nvarchar(2000) NOT NULL,
    [PatientClassID] int NOT NULL,
    [PatientClassCode] nvarchar(2000) NOT NULL,
    [PayorID] int NOT NULL,
    [PayorCode] nvarchar(2000) NOT NULL,
    [OBForecastDetailID] int NOT NULL,
    [OBForecastDetailCode] nvarchar(2000) NOT NULL,
    [Value] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    PRIMARY KEY ([RowID])
);

CREATE CLUSTERED INDEX [CNU_BASE] ON [int].[FactOBPayor] ([FiscalMonthID], [IsDeleted], [TimeClassID], [FiscalYearID], [PayorID], [OBReimbursementPlanID], [PatientClassID], [OBForecastDetailID], [RowID]);
CREATE NONCLUSTERED INDEX [NCNU_SampleViews] ON [int].[FactOBPayor] ([FiscalMonthID], [IsDeleted], [TimeClassID], [FiscalYearID], [PayorID], [OBReimbursementPlanID], [PatientClassID], [OBForecastDetailID]);
GO
ALTER TABLE [int].[FactOBPayor] ADD CONSTRAINT [DF__FactOBPay__Histo__7877ED2C] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactOBPayor] ADD CONSTRAINT [DF__FactOBPay__TimeC__759B8081] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactOBPayor] ADD CONSTRAINT [DF__FactOBPay__Fisca__6D063A80] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactOBPayor] ADD CONSTRAINT [DF__FactOBPay__Fisca__72BF13D6] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactOBPayor] ADD CONSTRAINT [DF__FactOBPay__Fisca__6C121647] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactOBPayor] ADD CONSTRAINT [DF__FactOBPay__Fisca__71CAEF9D] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactOBPayor] ADD CONSTRAINT [DF__FactOBPay__Reimb__70D6CB64] DEFAULT ('') FOR [ReimbursementPlan]; GO
ALTER TABLE [int].[FactOBPayor] ADD CONSTRAINT [DF__FactOBPay__CareS__217A02BF] DEFAULT ((0)) FOR [CareSettingID]; GO
ALTER TABLE [int].[FactOBPayor] ADD CONSTRAINT [DF__FactOBPay__CareS__226E26F8] DEFAULT ('') FOR [CareSettingCode]; GO
ALTER TABLE [int].[FactOBPayor] ADD CONSTRAINT [DF__FactOBPay__Patie__6DFA5EB9] DEFAULT ((0)) FOR [PatientClassID]; GO
ALTER TABLE [int].[FactOBPayor] ADD CONSTRAINT [DF__FactOBPay__Patie__73B3380F] DEFAULT ('') FOR [PatientClassCode]; GO
ALTER TABLE [int].[FactOBPayor] ADD CONSTRAINT [DF__FactOBPay__Payor__74A75C48] DEFAULT ('') FOR [PayorCode]; GO
ALTER TABLE [int].[FactOBPayor] ADD CONSTRAINT [DF__FactOBPay__OBFor__6EEE82F2] DEFAULT ((0)) FOR [OBForecastDetailID]; GO
ALTER TABLE [int].[FactOBPayor] ADD CONSTRAINT [DF__FactOBPay__OBFor__6FE2A72B] DEFAULT ('') FOR [OBForecastDetailCode]; GO
ALTER TABLE [int].[FactOBPayor] ADD CONSTRAINT [DF__FactOBPay__Value__768FA4BA] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactOBPayor] ADD CONSTRAINT [DF__FactOBPay__IsDel__7783C8F3] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactOBPayor] ADD CONSTRAINT [DF__FactOBPay__Trans__796C1165] DEFAULT ((0)) FOR [TransactionID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactOBPayorGroup ------------------
---------------------------------------------
CREATE TABLE [int].[FactOBPayorGroup] (
    [RowID] int NOT NULL,
    [OBForecastDetailID] int NOT NULL,
    [OBReimbursementPlanID] int NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [PatientClassID] int NOT NULL,
    [PayorGroupID] int NOT NULL,
    [OBForecastDetailCode] nvarchar(2000) NOT NULL,
    [ReimbursementPlan] nvarchar(2000) NOT NULL,
    [FiscalMonthCode] nvarchar(2000) NOT NULL,
    [FiscalYearCode] nvarchar(2000) NOT NULL,
    [TimeClassCode] nvarchar(2000) NOT NULL,
    [PatientClassCode] nvarchar(2000) NOT NULL,
    [PayorGroupCode] nvarchar(2000) NOT NULL,
    [Value] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    [CareSettingID] int NOT NULL,
    [CareSettingCode] nvarchar(2000) NOT NULL,
    PRIMARY KEY ([RowID])
);

CREATE CLUSTERED INDEX [CNU_BASE] ON [int].[FactOBPayorGroup] ([FiscalMonthID], [IsDeleted], [TimeClassID], [FiscalYearID], [PayorGroupID], [OBReimbursementPlanID], [PatientClassID], [OBForecastDetailID], [RowID]);
CREATE NONCLUSTERED INDEX [NCNU_SampleViews] ON [int].[FactOBPayorGroup] ([FiscalMonthID], [IsDeleted], [TimeClassID], [FiscalYearID], [PayorGroupID], [OBReimbursementPlanID], [PatientClassID], [OBForecastDetailID]);
GO
ALTER TABLE [int].[FactOBPayorGroup] ADD CONSTRAINT [DF__FactOBPay__Fisca__0C7EE5D9] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactOBPayorGroup] ADD CONSTRAINT [DF__FactOBPay__Fisca__0D730A12] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactOBPayorGroup] ADD CONSTRAINT [DF__FactOBPay__Patie__0E672E4B] DEFAULT ((0)) FOR [PatientClassID]; GO
ALTER TABLE [int].[FactOBPayorGroup] ADD CONSTRAINT [DF__FactOBPay__OBFor__0F5B5284] DEFAULT ('') FOR [OBForecastDetailCode]; GO
ALTER TABLE [int].[FactOBPayorGroup] ADD CONSTRAINT [DF__FactOBPay__Reimb__104F76BD] DEFAULT ('') FOR [ReimbursementPlan]; GO
ALTER TABLE [int].[FactOBPayorGroup] ADD CONSTRAINT [DF__FactOBPay__Fisca__11439AF6] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactOBPayorGroup] ADD CONSTRAINT [DF__FactOBPay__Fisca__1237BF2F] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactOBPayorGroup] ADD CONSTRAINT [DF__FactOBPay__TimeC__132BE368] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactOBPayorGroup] ADD CONSTRAINT [DF__FactOBPay__Patie__142007A1] DEFAULT ('') FOR [PatientClassCode]; GO
ALTER TABLE [int].[FactOBPayorGroup] ADD CONSTRAINT [DF__FactOBPay__Payor__15142BDA] DEFAULT ('') FOR [PayorGroupCode]; GO
ALTER TABLE [int].[FactOBPayorGroup] ADD CONSTRAINT [DF__FactOBPay__Value__16085013] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactOBPayorGroup] ADD CONSTRAINT [DF__FactOBPay__IsDel__16FC744C] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactOBPayorGroup] ADD CONSTRAINT [DF__FactOBPay__Trans__18E4BCBE] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactOBPayorGroup] ADD CONSTRAINT [DF__FactOBPay__CareS__1F91BA4D] DEFAULT ((0)) FOR [CareSettingID]; GO
ALTER TABLE [int].[FactOBPayorGroup] ADD CONSTRAINT [DF__FactOBPay__CareS__2085DE86] DEFAULT ('') FOR [CareSettingCode]; GO
ALTER TABLE [int].[FactOBPayorGroup] ADD CONSTRAINT [DF_FactOBPayorGroup_OBForecastDetailID] DEFAULT ((0)) FOR [OBForecastDetailID]; GO
ALTER TABLE [int].[FactOBPayorGroup] ADD CONSTRAINT [DF_FactOBPayorGroup_OBReimbursementPlanID] DEFAULT ((0)) FOR [OBReimbursementPlanID]; GO
ALTER TABLE [int].[FactOBPayorGroup] ADD CONSTRAINT [DF__FactOBPay__Histo__17F09885] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactPayorSummary ------------------
---------------------------------------------
CREATE TABLE [int].[FactPayorSummary] (
    [RowID] int NOT NULL,
    [DepartmentID] int NOT NULL,
    [DepartmentCode] varchar(100) NOT NULL,
    [PatientTypeRollupID] tinyint NOT NULL,
    [PatientTypeRollupCode] varchar(50) NOT NULL,
    [AccountRollupID] int NOT NULL,
    [AccountRollupCode] varchar(50) NOT NULL,
    [PayorGroupID] int NOT NULL,
    [PayorGroupCode] varchar(50) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] varchar(20) NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] varchar(20) NOT NULL,
    [UnitTypeID] tinyint NOT NULL,
    [UnitType] varchar(20) NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [FiscalMonthCode] varchar(20) NOT NULL,
    [Value] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NULL,
    PRIMARY KEY ([RowID])
);

CREATE UNIQUE CLUSTERED INDEX [CU_Base] ON [int].[FactPayorSummary] ([FiscalMonthID], [IsDeleted], [FiscalYearID], [TimeClassID], [DepartmentID], [PatientTypeRollupID], [AccountRollupID], [PayorGroupID], [UnitTypeID], [RowID]);
GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF__FactPayor__Depar__5A2A6EA7] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF__FactPayor__Patie__5B1E92E0] DEFAULT ((0)) FOR [PatientTypeRollupID]; GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF__FactPayor__Patie__5C12B719] DEFAULT ('') FOR [PatientTypeRollupCode]; GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF__FactPayor__Accou__5D06DB52] DEFAULT ((0)) FOR [AccountRollupID]; GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF__FactPayor__Accou__5DFAFF8B] DEFAULT ('') FOR [AccountRollupCode]; GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF__FactPayor__Payor__5EEF23C4] DEFAULT ((0)) FOR [PayorGroupID]; GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF__FactPayor__Payor__5FE347FD] DEFAULT ('') FOR [PayorGroupCode]; GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF__FactPayor__Fisca__60D76C36] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF__FactPayor__Fisca__61CB906F] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF__FactPayor__TimeC__62BFB4A8] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF__FactPayor__TimeC__63B3D8E1] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF__FactPayor__UnitT__64A7FD1A] DEFAULT ((0)) FOR [UnitTypeID]; GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF__FactPayor__UnitT__659C2153] DEFAULT ('') FOR [UnitType]; GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF__FactPayor__Fisca__315A67AC] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF__FactPayor__Fisca__409CAB3C] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF_INTFACTPAYORSUMMARYVALUE] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF__FactPayor__IsDel__4190CF75] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF__FactPayor__Histo__72F61C71] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF__FactPayor__Depar__0ECD49EC] DEFAULT ((0)) FOR [DepartmentID]; GO
ALTER TABLE [int].[FactPayorSummary] ADD CONSTRAINT [DF__INT_FactPayorSummary_TransactionID ] DEFAULT ((0)) FOR [TransactionID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactPhysicianSummary ------------------
---------------------------------------------
CREATE TABLE [int].[FactPhysicianSummary] (
    [RowID] int NOT NULL,
    [DepartmentID] int NOT NULL,
    [DepartmentCode] varchar(100) NOT NULL,
    [PatientTypeRollupID] tinyint NOT NULL,
    [PatientTypeRollupCode] varchar(50) NOT NULL,
    [AccountRollupID] int NOT NULL,
    [AccountRollupCode] varchar(50) NOT NULL,
    [PhysicianGroupID] int NOT NULL,
    [PhysicianGroupCode] varchar(50) NOT NULL,
    [UnitTypeID] tinyint NOT NULL,
    [UnitType] varchar(20) NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] varchar(20) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] varchar(20) NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [FiscalMonthCode] varchar(20) NOT NULL,
    [Value] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NULL,
    PRIMARY KEY ([RowID])
);

CREATE UNIQUE CLUSTERED INDEX [CU_Base] ON [int].[FactPhysicianSummary] ([FiscalMonthID], [IsDeleted], [FiscalYearID], [TimeClassID], [DepartmentID], [PatientTypeRollupID], [AccountRollupID], [PhysicianGroupID], [UnitTypeID], [RowID]);
GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF__FactPhysi__Depar__6587DE11] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF__FactPhysi__Patie__667C024A] DEFAULT ((0)) FOR [PatientTypeRollupID]; GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF__FactPhysi__Patie__67702683] DEFAULT ('') FOR [PatientTypeRollupCode]; GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF__FactPhysi__Accou__68644ABC] DEFAULT ((0)) FOR [AccountRollupID]; GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF__FactPhysi__Accou__69586EF5] DEFAULT ('') FOR [AccountRollupCode]; GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF__FactPhysi__Physi__6A4C932E] DEFAULT ((0)) FOR [PhysicianGroupID]; GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF__FactPhysi__Physi__6B40B767] DEFAULT ('') FOR [PhysicianGroupCode]; GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF__FactPhysi__UnitT__70056C84] DEFAULT ((0)) FOR [UnitTypeID]; GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF__FactPhysi__UnitT__70F990BD] DEFAULT ('') FOR [UnitType]; GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF__FactPhysi__TimeC__6E1D2412] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF__FactPhysi__TimeC__6F11484B] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF__FactPhysi__Fisca__6C34DBA0] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF__FactPhysi__Fisca__6D28FFD9] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF__FactPhysi__Fisca__352AF890] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF__FactPhysi__Fisca__4284F3AE] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF_INTFACTPHYSICIANSUMMARYVALUE] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF__FactPhysi__IsDel__437917E7] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF__FactPhysi__Histo__7E538BDB] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF__INT_FactPhysicianSummary_TransactionID ] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactPhysicianSummary] ADD CONSTRAINT [DF__FactPhysi__Depar__6493B9D8] DEFAULT ((0)) FOR [DepartmentID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactProvider ------------------
---------------------------------------------
CREATE TABLE [int].[FactProvider] (
    [RowID] int NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [PhysicianID] int NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [ProviderLineItemID] int NOT NULL,
    [UnitTypeID] tinyint NOT NULL,
    [DepartmentID] int NOT NULL,
    [DepartmentCode] nvarchar(2000) NOT NULL,
    [FiscalMonthCode] nvarchar(2000) NOT NULL,
    [FiscalYearCode] nvarchar(2000) NOT NULL,
    [ProviderCode] nvarchar(2000) NOT NULL,
    [TimeClassCode] nvarchar(2000) NOT NULL,
    [UnitTypeName] nvarchar(2000) NOT NULL,
    [Value] decimal NOT NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [FK__FactProvi__Depar__4CB63923] FOREIGN KEY ([DepartmentID]) REFERENCES [fw].[DimDepartment] ([DepartmentID]); GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [FK__FactProvi__Fisca__03857E79] FOREIGN KEY ([FiscalMonthID]) REFERENCES [fw].[DimFiscalMonth] ([FiscalMonthID]); GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [FK__FactProvi__Fisca__0479A2B2] FOREIGN KEY ([FiscalYearID]) REFERENCES [fw].[DimFiscalYear] ([FiscalYearID]); GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [FK__FactProvi__Provi__056DC6EB] FOREIGN KEY ([ProviderLineItemID]) REFERENCES [fp].[ProviderLineItem] ([ProviderLineItemID]); GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [FK__FactProvi__Provi__4E9E8195] FOREIGN KEY ([PhysicianID]) REFERENCES [dss].[DimPhysician] ([PhysicianID]); GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [FK__FactProvi__TimeC__07560F5D] FOREIGN KEY ([TimeClassID]) REFERENCES [fw].[DimTimeClass] ([TimeClassID]); GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [FK__FactProvi__UnitT__084A3396] FOREIGN KEY ([UnitTypeID]) REFERENCES [fw].[DimUnitType] ([UnitTypeID]); GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [DF__FactProvi__UnitT__00A911CE] DEFAULT ('') FOR [UnitTypeName]; GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [DF__FactProvi__Value__019D3607] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [DF__FactProvi__IsDel__725AF277] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [DF__FactProvi__Trans__74433AE9] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [DF__FactProvi__Histo__734F16B0] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [DF__FactProvi__TimeC__75375F22] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [DF__FactProvi__Physi__762B835B] DEFAULT ((0)) FOR [PhysicianID]; GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [DF__FactProvi__Fisca__771FA794] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [DF__FactProvi__Fisca__7813CBCD] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [DF__FactProvi__Provi__7907F006] DEFAULT ((0)) FOR [ProviderLineItemID]; GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [DF__FactProvi__UnitT__79FC143F] DEFAULT ((0)) FOR [UnitTypeID]; GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [DF__FactProvi__Depar__7AF03878] DEFAULT ((0)) FOR [DepartmentID]; GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [DF__FactProvi__Depar__7BE45CB1] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [DF__FactProvi__Fisca__7CD880EA] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [DF__FactProvi__Fisca__7DCCA523] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [DF__FactProvi__Provi__7EC0C95C] DEFAULT ('') FOR [ProviderCode]; GO
ALTER TABLE [int].[FactProvider] ADD CONSTRAINT [DF__FactProvi__TimeC__7FB4ED95] DEFAULT ('') FOR [TimeClassCode]; GO

---------------------------------------------

---------------------------------------------
-- int.FactSPDirectBalAccount ------------------
---------------------------------------------
CREATE TABLE [int].[FactSPDirectBalAccount] (
    [RowID] int NOT NULL,
    [SPLongRangePlanID] int NOT NULL,
    [SPLongRangePlanName] varchar(200) NOT NULL,
    [AccountRollupID] int NOT NULL,
    [SPAccountRollupName] varchar(200) NOT NULL,
    [SPCapitalRollupID] int NOT NULL,
    [SPCapitalRollupName] varchar(200) NOT NULL,
    [SPDebtIssuanceID] int NOT NULL,
    [SPDebtIssuanceName] varchar(400) NOT NULL,
    [UnitTypeID] tinyint NOT NULL,
    [UnitType] varchar(20) NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] varchar(20) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] varchar(20) NOT NULL,
    [Amount] decimal NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactSPDirectBalAccount] ADD CONSTRAINT [DF__FactSPDir__SPLon__250E31A0] DEFAULT ((0)) FOR [SPLongRangePlanID]; GO
ALTER TABLE [int].[FactSPDirectBalAccount] ADD CONSTRAINT [DF__FactSPDir__SPLon__260255D9] DEFAULT ('') FOR [SPLongRangePlanName]; GO
ALTER TABLE [int].[FactSPDirectBalAccount] ADD CONSTRAINT [DF__FactSPDir__SPAcc__26F67A12] DEFAULT ((0)) FOR [AccountRollupID]; GO
ALTER TABLE [int].[FactSPDirectBalAccount] ADD CONSTRAINT [DF__FactSPDir__SPAcc__27EA9E4B] DEFAULT ('') FOR [SPAccountRollupName]; GO
ALTER TABLE [int].[FactSPDirectBalAccount] ADD CONSTRAINT [DF__FactSPDir__SPCap__28DEC284] DEFAULT ((0)) FOR [SPCapitalRollupID]; GO
ALTER TABLE [int].[FactSPDirectBalAccount] ADD CONSTRAINT [DF__FactSPDir__SPCap__29D2E6BD] DEFAULT ('') FOR [SPCapitalRollupName]; GO
ALTER TABLE [int].[FactSPDirectBalAccount] ADD CONSTRAINT [DF__FactSPDir__SPDeb__2AC70AF6] DEFAULT ((0)) FOR [SPDebtIssuanceID]; GO
ALTER TABLE [int].[FactSPDirectBalAccount] ADD CONSTRAINT [DF__FactSPDir__SPDeb__2BBB2F2F] DEFAULT ('') FOR [SPDebtIssuanceName]; GO
ALTER TABLE [int].[FactSPDirectBalAccount] ADD CONSTRAINT [DF__FactSPDir__UnitT__2CAF5368] DEFAULT ((0)) FOR [UnitTypeID]; GO
ALTER TABLE [int].[FactSPDirectBalAccount] ADD CONSTRAINT [DF__FactSPDir__UnitT__2DA377A1] DEFAULT ('') FOR [UnitType]; GO
ALTER TABLE [int].[FactSPDirectBalAccount] ADD CONSTRAINT [DF__FactSPDir__TimeC__2E979BDA] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactSPDirectBalAccount] ADD CONSTRAINT [DF__FactSPDir__TimeC__2F8BC013] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactSPDirectBalAccount] ADD CONSTRAINT [DF__FactSPDir__Fisca__307FE44C] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactSPDirectBalAccount] ADD CONSTRAINT [DF__FactSPDir__Fisca__31740885] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactSPDirectBalAccount] ADD CONSTRAINT [DF__FactSPDir__Amoun__32682CBE] DEFAULT ((0.0)) FOR [Amount]; GO
ALTER TABLE [int].[FactSPDirectBalAccount] ADD CONSTRAINT [DF__FactSPDir__Histo__335C50F7] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactSPDirectBalAccount] ADD CONSTRAINT [DF__INT_FactSPDirectBalAccount_TransactionID ] DEFAULT ((0)) FOR [TransactionID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactSPDirectISAccount ------------------
---------------------------------------------
CREATE TABLE [int].[FactSPDirectISAccount] (
    [RowID] int NOT NULL,
    [SPLongRangePlanID] int NOT NULL,
    [SPLongRangePlanName] varchar(200) NOT NULL,
    [AccountRollupID] int NOT NULL,
    [SPAccountRollupName] varchar(200) NOT NULL,
    [UnitTypeID] tinyint NOT NULL,
    [UnitType] varchar(20) NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] varchar(20) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] varchar(20) NOT NULL,
    [Amount] decimal NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactSPDirectISAccount] ADD CONSTRAINT [DF__FactSPDir__SPLon__38210614] DEFAULT ((0)) FOR [SPLongRangePlanID]; GO
ALTER TABLE [int].[FactSPDirectISAccount] ADD CONSTRAINT [DF__FactSPDir__SPLon__39152A4D] DEFAULT ('') FOR [SPLongRangePlanName]; GO
ALTER TABLE [int].[FactSPDirectISAccount] ADD CONSTRAINT [DF__FactSPDir__SPAcc__3A094E86] DEFAULT ((0)) FOR [AccountRollupID]; GO
ALTER TABLE [int].[FactSPDirectISAccount] ADD CONSTRAINT [DF__FactSPDir__SPAcc__3AFD72BF] DEFAULT ('') FOR [SPAccountRollupName]; GO
ALTER TABLE [int].[FactSPDirectISAccount] ADD CONSTRAINT [DF__FactSPDir__UnitT__3BF196F8] DEFAULT ((0)) FOR [UnitTypeID]; GO
ALTER TABLE [int].[FactSPDirectISAccount] ADD CONSTRAINT [DF__FactSPDir__UnitT__3CE5BB31] DEFAULT ('') FOR [UnitType]; GO
ALTER TABLE [int].[FactSPDirectISAccount] ADD CONSTRAINT [DF__FactSPDir__TimeC__3DD9DF6A] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactSPDirectISAccount] ADD CONSTRAINT [DF__FactSPDir__TimeC__3ECE03A3] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactSPDirectISAccount] ADD CONSTRAINT [DF__FactSPDir__Fisca__3FC227DC] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactSPDirectISAccount] ADD CONSTRAINT [DF__FactSPDir__Fisca__40B64C15] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactSPDirectISAccount] ADD CONSTRAINT [DF__FactSPDir__Amoun__41AA704E] DEFAULT ((0.0)) FOR [Amount]; GO
ALTER TABLE [int].[FactSPDirectISAccount] ADD CONSTRAINT [DF__FactSPDir__Histo__429E9487] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactSPDirectISAccount] ADD CONSTRAINT [DF__INT_FactSPDirectISAccount_TransactionID ] DEFAULT ((0)) FOR [TransactionID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactSPDirectISPayor ------------------
---------------------------------------------
CREATE TABLE [int].[FactSPDirectISPayor] (
    [RowID] int NOT NULL,
    [SPLongRangePlanID] int NOT NULL,
    [SPLongRangePlanName] varchar(200) NOT NULL,
    [AccountRollupID] int NOT NULL,
    [SPAccountRollupName] varchar(200) NOT NULL,
    [PatientTypeRollupID] tinyint NOT NULL,
    [PatientTypeRollupCode] varchar(200) NOT NULL,
    [PayorGroupID] int NOT NULL,
    [PayorGroupCode] varchar(200) NOT NULL,
    [UnitTypeID] tinyint NOT NULL,
    [UnitType] varchar(20) NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] varchar(20) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] varchar(20) NOT NULL,
    [Amount] decimal NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactSPDirectISPayor] ADD CONSTRAINT [DF__INT_FactSPDirectISPayor_TransactionID ] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactSPDirectISPayor] ADD CONSTRAINT [DF__FactSPDir__SPLon__476349A4] DEFAULT ((0)) FOR [SPLongRangePlanID]; GO
ALTER TABLE [int].[FactSPDirectISPayor] ADD CONSTRAINT [DF__FactSPDir__SPLon__48576DDD] DEFAULT ('') FOR [SPLongRangePlanName]; GO
ALTER TABLE [int].[FactSPDirectISPayor] ADD CONSTRAINT [DF__FactSPDir__SPAcc__494B9216] DEFAULT ((0)) FOR [AccountRollupID]; GO
ALTER TABLE [int].[FactSPDirectISPayor] ADD CONSTRAINT [DF__FactSPDir__SPAcc__4A3FB64F] DEFAULT ('') FOR [SPAccountRollupName]; GO
ALTER TABLE [int].[FactSPDirectISPayor] ADD CONSTRAINT [DF__FactSPDir__Patie__4B33DA88] DEFAULT ((0)) FOR [PatientTypeRollupID]; GO
ALTER TABLE [int].[FactSPDirectISPayor] ADD CONSTRAINT [DF__FactSPDir__Patie__4C27FEC1] DEFAULT ('') FOR [PatientTypeRollupCode]; GO
ALTER TABLE [int].[FactSPDirectISPayor] ADD CONSTRAINT [DF__FactSPDir__Payor__4D1C22FA] DEFAULT ((0)) FOR [PayorGroupID]; GO
ALTER TABLE [int].[FactSPDirectISPayor] ADD CONSTRAINT [DF__FactSPDir__Payor__4E104733] DEFAULT ('') FOR [PayorGroupCode]; GO
ALTER TABLE [int].[FactSPDirectISPayor] ADD CONSTRAINT [DF__FactSPDir__UnitT__4F046B6C] DEFAULT ((0)) FOR [UnitTypeID]; GO
ALTER TABLE [int].[FactSPDirectISPayor] ADD CONSTRAINT [DF__FactSPDir__UnitT__4FF88FA5] DEFAULT ('') FOR [UnitType]; GO
ALTER TABLE [int].[FactSPDirectISPayor] ADD CONSTRAINT [DF__FactSPDir__TimeC__50ECB3DE] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactSPDirectISPayor] ADD CONSTRAINT [DF__FactSPDir__TimeC__51E0D817] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactSPDirectISPayor] ADD CONSTRAINT [DF__FactSPDir__Fisca__52D4FC50] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactSPDirectISPayor] ADD CONSTRAINT [DF__FactSPDir__Fisca__53C92089] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactSPDirectISPayor] ADD CONSTRAINT [DF__FactSPDir__Amoun__54BD44C2] DEFAULT ((0.0)) FOR [Amount]; GO
ALTER TABLE [int].[FactSPDirectISPayor] ADD CONSTRAINT [DF__FactSPDir__Histo__55B168FB] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactSPDirectISPhysician ------------------
---------------------------------------------
CREATE TABLE [int].[FactSPDirectISPhysician] (
    [RowID] int NOT NULL,
    [SPLongRangePlanID] int NOT NULL,
    [SPLongRangePlanName] varchar(200) NOT NULL,
    [AccountRollupID] int NOT NULL,
    [SPAccountRollupName] varchar(200) NOT NULL,
    [PatientTypeRollupID] tinyint NOT NULL,
    [PatientTypeRollupCode] varchar(200) NOT NULL,
    [PhysicianGroupID] int NOT NULL,
    [PhysicianGroupCode] varchar(200) NOT NULL,
    [UnitTypeID] tinyint NOT NULL,
    [UnitType] varchar(20) NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] varchar(20) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] varchar(20) NOT NULL,
    [Amount] decimal NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactSPDirectISPhysician] ADD CONSTRAINT [DF__FactSPDir__Fisca__66DBF4FD] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactSPDirectISPhysician] ADD CONSTRAINT [DF__FactSPDir__Amoun__67D01936] DEFAULT ((0.0)) FOR [Amount]; GO
ALTER TABLE [int].[FactSPDirectISPhysician] ADD CONSTRAINT [DF__FactSPDir__Histo__68C43D6F] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactSPDirectISPhysician] ADD CONSTRAINT [DF__INT_FactSPDirectISPhysician_TransactionID ] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactSPDirectISPhysician] ADD CONSTRAINT [DF__FactSPDir__SPLon__5A761E18] DEFAULT ((0)) FOR [SPLongRangePlanID]; GO
ALTER TABLE [int].[FactSPDirectISPhysician] ADD CONSTRAINT [DF__FactSPDir__SPLon__5B6A4251] DEFAULT ('') FOR [SPLongRangePlanName]; GO
ALTER TABLE [int].[FactSPDirectISPhysician] ADD CONSTRAINT [DF__FactSPDir__SPAcc__5C5E668A] DEFAULT ((0)) FOR [AccountRollupID]; GO
ALTER TABLE [int].[FactSPDirectISPhysician] ADD CONSTRAINT [DF__FactSPDir__SPAcc__5D528AC3] DEFAULT ('') FOR [SPAccountRollupName]; GO
ALTER TABLE [int].[FactSPDirectISPhysician] ADD CONSTRAINT [DF__FactSPDir__Patie__5E46AEFC] DEFAULT ((0)) FOR [PatientTypeRollupID]; GO
ALTER TABLE [int].[FactSPDirectISPhysician] ADD CONSTRAINT [DF__FactSPDir__Patie__5F3AD335] DEFAULT ('') FOR [PatientTypeRollupCode]; GO
ALTER TABLE [int].[FactSPDirectISPhysician] ADD CONSTRAINT [DF__FactSPDir__Physi__602EF76E] DEFAULT ((0)) FOR [PhysicianGroupID]; GO
ALTER TABLE [int].[FactSPDirectISPhysician] ADD CONSTRAINT [DF__FactSPDir__Physi__61231BA7] DEFAULT ('') FOR [PhysicianGroupCode]; GO
ALTER TABLE [int].[FactSPDirectISPhysician] ADD CONSTRAINT [DF__FactSPDir__UnitT__62173FE0] DEFAULT ((0)) FOR [UnitTypeID]; GO
ALTER TABLE [int].[FactSPDirectISPhysician] ADD CONSTRAINT [DF__FactSPDir__UnitT__630B6419] DEFAULT ('') FOR [UnitType]; GO
ALTER TABLE [int].[FactSPDirectISPhysician] ADD CONSTRAINT [DF__FactSPDir__TimeC__63FF8852] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactSPDirectISPhysician] ADD CONSTRAINT [DF__FactSPDir__TimeC__64F3AC8B] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactSPDirectISPhysician] ADD CONSTRAINT [DF__FactSPDir__Fisca__65E7D0C4] DEFAULT ((0)) FOR [FiscalYearID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactSPDirectISStaffing ------------------
---------------------------------------------
CREATE TABLE [int].[FactSPDirectISStaffing] (
    [RowID] int NOT NULL,
    [SPLongRangePlanID] int NOT NULL,
    [SPLongRangePlanName] varchar(200) NOT NULL,
    [AccountRollupID] int NOT NULL,
    [SPAccountRollupName] varchar(200) NOT NULL,
    [JobCodeGroupID] int NOT NULL,
    [JobCodeGroup] varchar(200) NOT NULL,
    [UnitTypeID] tinyint NOT NULL,
    [UnitType] varchar(20) NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] varchar(20) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] varchar(20) NOT NULL,
    [Amount] decimal NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactSPDirectISStaffing] ADD CONSTRAINT [DF__FactSPDir__SPLon__6D88F28C] DEFAULT ((0)) FOR [SPLongRangePlanID]; GO
ALTER TABLE [int].[FactSPDirectISStaffing] ADD CONSTRAINT [DF__FactSPDir__SPLon__6E7D16C5] DEFAULT ('') FOR [SPLongRangePlanName]; GO
ALTER TABLE [int].[FactSPDirectISStaffing] ADD CONSTRAINT [DF__FactSPDir__SPAcc__6F713AFE] DEFAULT ((0)) FOR [AccountRollupID]; GO
ALTER TABLE [int].[FactSPDirectISStaffing] ADD CONSTRAINT [DF__FactSPDir__SPAcc__70655F37] DEFAULT ('') FOR [SPAccountRollupName]; GO
ALTER TABLE [int].[FactSPDirectISStaffing] ADD CONSTRAINT [DF__FactSPDir__JobCo__71598370] DEFAULT ((0)) FOR [JobCodeGroupID]; GO
ALTER TABLE [int].[FactSPDirectISStaffing] ADD CONSTRAINT [DF__FactSPDir__JobCo__724DA7A9] DEFAULT ('') FOR [JobCodeGroup]; GO
ALTER TABLE [int].[FactSPDirectISStaffing] ADD CONSTRAINT [DF__FactSPDir__UnitT__7341CBE2] DEFAULT ((0)) FOR [UnitTypeID]; GO
ALTER TABLE [int].[FactSPDirectISStaffing] ADD CONSTRAINT [DF__FactSPDir__UnitT__7435F01B] DEFAULT ('') FOR [UnitType]; GO
ALTER TABLE [int].[FactSPDirectISStaffing] ADD CONSTRAINT [DF__FactSPDir__TimeC__752A1454] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactSPDirectISStaffing] ADD CONSTRAINT [DF__FactSPDir__TimeC__761E388D] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactSPDirectISStaffing] ADD CONSTRAINT [DF__FactSPDir__Fisca__77125CC6] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactSPDirectISStaffing] ADD CONSTRAINT [DF__FactSPDir__Fisca__780680FF] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactSPDirectISStaffing] ADD CONSTRAINT [DF__FactSPDir__Amoun__78FAA538] DEFAULT ((0.0)) FOR [Amount]; GO
ALTER TABLE [int].[FactSPDirectISStaffing] ADD CONSTRAINT [DF__FactSPDir__Histo__79EEC971] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactSPDirectISStaffing] ADD CONSTRAINT [DF__INT_FactSPDirectISStaffing_TransactionID ] DEFAULT ((0)) FOR [TransactionID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactSPDirectRollingISAccount ------------------
---------------------------------------------
CREATE TABLE [int].[FactSPDirectRollingISAccount] (
    [RowID] int NOT NULL,
    [SPRollingForecastPlanID] int NOT NULL,
    [SPRollingForecastPlanName] varchar(200) NOT NULL,
    [AccountRollupID] int NOT NULL,
    [SPAccountRollupName] varchar(200) NOT NULL,
    [UnitTypeID] tinyint NOT NULL,
    [UnitType] varchar(20) NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] varchar(20) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] varchar(20) NOT NULL,
    [ValueMonth01] decimal NOT NULL,
    [ValueMonth02] decimal NOT NULL,
    [ValueMonth03] decimal NOT NULL,
    [ValueMonth04] decimal NOT NULL,
    [ValueMonth05] decimal NOT NULL,
    [ValueMonth06] decimal NOT NULL,
    [ValueMonth07] decimal NOT NULL,
    [ValueMonth08] decimal NOT NULL,
    [ValueMonth09] decimal NOT NULL,
    [ValueMonth10] decimal NOT NULL,
    [ValueMonth11] decimal NOT NULL,
    [ValueMonth12] decimal NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__Value__0066BCD6] DEFAULT ((0.0)) FOR [ValueMonth09]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__Value__015AE10F] DEFAULT ((0.0)) FOR [ValueMonth10]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__Value__024F0548] DEFAULT ((0.0)) FOR [ValueMonth11]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__Value__03432981] DEFAULT ((0.0)) FOR [ValueMonth12]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__Histo__04374DBA] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__INT_FactSPDirectRollingISAccount_TransactionID ] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__SPRol__6F3C30D4] DEFAULT ((0)) FOR [SPRollingForecastPlanID]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__SPRol__7030550D] DEFAULT ('') FOR [SPRollingForecastPlanName]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__SPAcc__71247946] DEFAULT ((0)) FOR [AccountRollupID]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__SPAcc__72189D7F] DEFAULT ('') FOR [SPAccountRollupName]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__UnitT__730CC1B8] DEFAULT ((0)) FOR [UnitTypeID]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__UnitT__7400E5F1] DEFAULT ('') FOR [UnitType]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__TimeC__74F50A2A] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__TimeC__75E92E63] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__Fisca__76DD529C] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__Fisca__77D176D5] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__Value__78C59B0E] DEFAULT ((0.0)) FOR [ValueMonth01]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__Value__79B9BF47] DEFAULT ((0.0)) FOR [ValueMonth02]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__Value__7AADE380] DEFAULT ((0.0)) FOR [ValueMonth03]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__Value__7BA207B9] DEFAULT ((0.0)) FOR [ValueMonth04]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__Value__7C962BF2] DEFAULT ((0.0)) FOR [ValueMonth05]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__Value__7D8A502B] DEFAULT ((0.0)) FOR [ValueMonth06]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__Value__7E7E7464] DEFAULT ((0.0)) FOR [ValueMonth07]; GO
ALTER TABLE [int].[FactSPDirectRollingISAccount] ADD CONSTRAINT [DF__FactSPDir__Value__7F72989D] DEFAULT ((0.0)) FOR [ValueMonth08]; GO

---------------------------------------------

---------------------------------------------
-- int.FactSPDirectRollingISPayor ------------------
---------------------------------------------
CREATE TABLE [int].[FactSPDirectRollingISPayor] (
    [RowID] int NOT NULL,
    [SPRollingForecastPlanID] int NOT NULL,
    [SPRollingForecastPlanName] varchar(200) NOT NULL,
    [AccountRollupID] int NOT NULL,
    [SPAccountRollupName] varchar(200) NOT NULL,
    [PatientTypeRollupID] tinyint NOT NULL,
    [PatientTypeRollupCode] varchar(200) NOT NULL,
    [PayorGroupID] int NOT NULL,
    [PayorGroupCode] varchar(200) NOT NULL,
    [UnitTypeID] tinyint NOT NULL,
    [UnitType] varchar(20) NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] varchar(20) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] varchar(20) NOT NULL,
    [ValueMonth01] decimal NOT NULL,
    [ValueMonth02] decimal NOT NULL,
    [ValueMonth03] decimal NOT NULL,
    [ValueMonth04] decimal NOT NULL,
    [ValueMonth05] decimal NOT NULL,
    [ValueMonth06] decimal NOT NULL,
    [ValueMonth07] decimal NOT NULL,
    [ValueMonth08] decimal NOT NULL,
    [ValueMonth09] decimal NOT NULL,
    [ValueMonth10] decimal NOT NULL,
    [ValueMonth11] decimal NOT NULL,
    [ValueMonth12] decimal NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__SPRol__08FC02D7] DEFAULT ((0)) FOR [SPRollingForecastPlanID]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__SPRol__09F02710] DEFAULT ('') FOR [SPRollingForecastPlanName]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__SPAcc__0AE44B49] DEFAULT ((0)) FOR [AccountRollupID]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__SPAcc__0BD86F82] DEFAULT ('') FOR [SPAccountRollupName]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__Patie__0CCC93BB] DEFAULT ((0)) FOR [PatientTypeRollupID]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__Patie__0DC0B7F4] DEFAULT ('') FOR [PatientTypeRollupCode]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__Payor__0EB4DC2D] DEFAULT ((0)) FOR [PayorGroupID]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__Payor__0FA90066] DEFAULT ('') FOR [PayorGroupCode]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__UnitT__109D249F] DEFAULT ((0)) FOR [UnitTypeID]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__UnitT__119148D8] DEFAULT ('') FOR [UnitType]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__TimeC__12856D11] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__TimeC__1379914A] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__Fisca__146DB583] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__Fisca__1561D9BC] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__Value__1655FDF5] DEFAULT ((0.0)) FOR [ValueMonth01]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__Value__174A222E] DEFAULT ((0.0)) FOR [ValueMonth02]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__Value__183E4667] DEFAULT ((0.0)) FOR [ValueMonth03]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__Value__19326AA0] DEFAULT ((0.0)) FOR [ValueMonth04]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__Value__1A268ED9] DEFAULT ((0.0)) FOR [ValueMonth05]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__Value__1B1AB312] DEFAULT ((0.0)) FOR [ValueMonth06]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__Value__1C0ED74B] DEFAULT ((0.0)) FOR [ValueMonth07]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__Value__1D02FB84] DEFAULT ((0.0)) FOR [ValueMonth08]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__Value__1DF71FBD] DEFAULT ((0.0)) FOR [ValueMonth09]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__Value__1EEB43F6] DEFAULT ((0.0)) FOR [ValueMonth10]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__Value__1FDF682F] DEFAULT ((0.0)) FOR [ValueMonth11]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__Value__20D38C68] DEFAULT ((0.0)) FOR [ValueMonth12]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__FactSPDir__Histo__21C7B0A1] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactSPDirectRollingISPayor] ADD CONSTRAINT [DF__INT_FactSPDirectRollingISPayor_TransactionID ] DEFAULT ((0)) FOR [TransactionID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactSPDirectRollingISPhysician ------------------
---------------------------------------------
CREATE TABLE [int].[FactSPDirectRollingISPhysician] (
    [RowID] int NOT NULL,
    [SPRollingForecastPlanID] int NOT NULL,
    [SPRollingForecastPlanName] varchar(200) NOT NULL,
    [AccountRollupID] int NOT NULL,
    [SPAccountRollupName] varchar(200) NOT NULL,
    [PatientTypeRollupID] tinyint NOT NULL,
    [PatientTypeRollupCode] varchar(200) NOT NULL,
    [PhysicianGroupID] int NOT NULL,
    [PhysicianGroupCode] varchar(200) NOT NULL,
    [UnitTypeID] tinyint NOT NULL,
    [UnitType] varchar(20) NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] varchar(20) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] varchar(20) NOT NULL,
    [ValueMonth01] decimal NOT NULL,
    [ValueMonth02] decimal NOT NULL,
    [ValueMonth03] decimal NOT NULL,
    [ValueMonth04] decimal NOT NULL,
    [ValueMonth05] decimal NOT NULL,
    [ValueMonth06] decimal NOT NULL,
    [ValueMonth07] decimal NOT NULL,
    [ValueMonth08] decimal NOT NULL,
    [ValueMonth09] decimal NOT NULL,
    [ValueMonth10] decimal NOT NULL,
    [ValueMonth11] decimal NOT NULL,
    [ValueMonth12] decimal NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__SPRol__268C65BE] DEFAULT ((0)) FOR [SPRollingForecastPlanID]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__SPRol__278089F7] DEFAULT ('') FOR [SPRollingForecastPlanName]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__SPAcc__2874AE30] DEFAULT ((0)) FOR [AccountRollupID]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__SPAcc__2968D269] DEFAULT ('') FOR [SPAccountRollupName]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__Patie__2A5CF6A2] DEFAULT ((0)) FOR [PatientTypeRollupID]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__Patie__2B511ADB] DEFAULT ('') FOR [PatientTypeRollupCode]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__Physi__2C453F14] DEFAULT ((0)) FOR [PhysicianGroupID]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__Physi__2D39634D] DEFAULT ('') FOR [PhysicianGroupCode]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__UnitT__2E2D8786] DEFAULT ((0)) FOR [UnitTypeID]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__UnitT__2F21ABBF] DEFAULT ('') FOR [UnitType]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__TimeC__3015CFF8] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__TimeC__3109F431] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__Fisca__31FE186A] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__Fisca__32F23CA3] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__Value__33E660DC] DEFAULT ((0.0)) FOR [ValueMonth01]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__Value__34DA8515] DEFAULT ((0.0)) FOR [ValueMonth02]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__Value__35CEA94E] DEFAULT ((0.0)) FOR [ValueMonth03]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__Value__36C2CD87] DEFAULT ((0.0)) FOR [ValueMonth04]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__Value__37B6F1C0] DEFAULT ((0.0)) FOR [ValueMonth05]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__Value__38AB15F9] DEFAULT ((0.0)) FOR [ValueMonth06]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__Value__399F3A32] DEFAULT ((0.0)) FOR [ValueMonth07]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__Value__3A935E6B] DEFAULT ((0.0)) FOR [ValueMonth08]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__Value__3B8782A4] DEFAULT ((0.0)) FOR [ValueMonth09]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__Value__3C7BA6DD] DEFAULT ((0.0)) FOR [ValueMonth10]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__Value__3D6FCB16] DEFAULT ((0.0)) FOR [ValueMonth11]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__Value__3E63EF4F] DEFAULT ((0.0)) FOR [ValueMonth12]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__FactSPDir__Histo__3F581388] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactSPDirectRollingISPhysician] ADD CONSTRAINT [DF__INT_FactSPDirectRollingISPhysician_TransactionID ] DEFAULT ((0)) FOR [TransactionID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactSPDirectRollingISStaffing ------------------
---------------------------------------------
CREATE TABLE [int].[FactSPDirectRollingISStaffing] (
    [RowID] int NOT NULL,
    [SPRollingForecastPlanID] int NOT NULL,
    [SPRollingForecastPlanName] varchar(200) NOT NULL,
    [AccountRollupID] int NOT NULL,
    [SPAccountRollupName] varchar(200) NOT NULL,
    [UnitTypeID] tinyint NOT NULL,
    [UnitType] varchar(20) NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] varchar(20) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] varchar(20) NOT NULL,
    [JobCodeGroupID] int NOT NULL,
    [JobCodeGroup] varchar(200) NOT NULL,
    [ValueMonth01] decimal NOT NULL,
    [ValueMonth02] decimal NOT NULL,
    [ValueMonth03] decimal NOT NULL,
    [ValueMonth04] decimal NOT NULL,
    [ValueMonth05] decimal NOT NULL,
    [ValueMonth06] decimal NOT NULL,
    [ValueMonth07] decimal NOT NULL,
    [ValueMonth08] decimal NOT NULL,
    [ValueMonth09] decimal NOT NULL,
    [ValueMonth10] decimal NOT NULL,
    [ValueMonth11] decimal NOT NULL,
    [ValueMonth12] decimal NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__INT_FactSPDirectRollingISStaffing_TransactionID ] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__SPRol__441CC8A5] DEFAULT ((0)) FOR [SPRollingForecastPlanID]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__SPRol__4510ECDE] DEFAULT ('') FOR [SPRollingForecastPlanName]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__SPAcc__46051117] DEFAULT ((0)) FOR [AccountRollupID]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__SPAcc__46F93550] DEFAULT ('') FOR [SPAccountRollupName]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__UnitT__47ED5989] DEFAULT ((0)) FOR [UnitTypeID]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__UnitT__48E17DC2] DEFAULT ('') FOR [UnitType]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__TimeC__49D5A1FB] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__TimeC__4AC9C634] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__Fisca__4BBDEA6D] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__Fisca__4CB20EA6] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__JobCo__4DA632DF] DEFAULT ((0)) FOR [JobCodeGroupID]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__JobCo__4E9A5718] DEFAULT ('') FOR [JobCodeGroup]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__Value__4F8E7B51] DEFAULT ((0.0)) FOR [ValueMonth01]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__Value__50829F8A] DEFAULT ((0.0)) FOR [ValueMonth02]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__Value__5176C3C3] DEFAULT ((0.0)) FOR [ValueMonth03]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__Value__526AE7FC] DEFAULT ((0.0)) FOR [ValueMonth04]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__Value__535F0C35] DEFAULT ((0.0)) FOR [ValueMonth05]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__Value__5453306E] DEFAULT ((0.0)) FOR [ValueMonth06]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__Value__554754A7] DEFAULT ((0.0)) FOR [ValueMonth07]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__Value__563B78E0] DEFAULT ((0.0)) FOR [ValueMonth08]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__Value__572F9D19] DEFAULT ((0.0)) FOR [ValueMonth09]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__Value__5823C152] DEFAULT ((0.0)) FOR [ValueMonth10]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__Value__5917E58B] DEFAULT ((0.0)) FOR [ValueMonth11]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__Value__5A0C09C4] DEFAULT ((0.0)) FOR [ValueMonth12]; GO
ALTER TABLE [int].[FactSPDirectRollingISStaffing] ADD CONSTRAINT [DF__FactSPDir__Histo__5B002DFD] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactServiceLine ------------------
---------------------------------------------
CREATE TABLE [int].[FactServiceLine] (
    [RowID] int NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] nvarchar(100) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] nvarchar(100) NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [FiscalMonthCode] nvarchar(100) NOT NULL,
    [EntityID] int NOT NULL,
    [EntityCode] nvarchar(100) NOT NULL,
    [PatientClassID] int NOT NULL,
    [PatientClassCode] nvarchar(100) NOT NULL,
    [ServiceLineID] int NOT NULL,
    [ServiceLine] nvarchar(100) NOT NULL,
    [AgeCohortID] int NOT NULL,
    [AgeCohort] nvarchar(100) NOT NULL,
    [MedicalSurgicalID] int NOT NULL,
    [MedSurg] nvarchar(100) NOT NULL,
    [DepartmentID] int NOT NULL,
    [DepartmentCode] nvarchar(100) NOT NULL,
    [OBForecastDetailID] int NOT NULL,
    [ForecastDetail] nvarchar(100) NOT NULL,
    [PayorGroupID] int NOT NULL,
    [PayorID] int NOT NULL,
    [Value] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    [PayorGroupCode] nvarchar(100) NOT NULL,
    [PayorCode] nvarchar(100) NOT NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [FK__FactServi__AgeCo__7CB29264] FOREIGN KEY ([AgeCohortID]) REFERENCES [fw].[DimAgeCohort] ([AgeCohortID]); GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [FK__FactServi__Fisca__00832348] FOREIGN KEY ([FiscalMonthID]) REFERENCES [fw].[DimFiscalMonth] ([FiscalMonthID]); GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [FK__FactServi__Fisca__026B6BBA] FOREIGN KEY ([FiscalYearID]) REFERENCES [fw].[DimFiscalYear] ([FiscalYearID]); GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [FK__FactServi__Medic__0453B42C] FOREIGN KEY ([MedicalSurgicalID]) REFERENCES [fw].[DimMedicalSurgical] ([MedicalSurgicalID]); GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [FK__FactServi__Patie__08244510] FOREIGN KEY ([PatientClassID]) REFERENCES [fw].[DimPatientClass] ([PatientClassID]); GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [FK__FactServi__Servi__0A0C8D82] FOREIGN KEY ([ServiceLineID]) REFERENCES [fw].[DimServiceLine] ([ServiceLineID]); GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [FK__FactServi__TimeC__0BF4D5F4] FOREIGN KEY ([TimeClassID]) REFERENCES [fw].[DimTimeClass] ([TimeClassID]); GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Payor__14498B46] DEFAULT ('') FOR [PayorGroupCode]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Payor__153DAF7F] DEFAULT ('') FOR [PayorCode]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Histo__176688A0] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__TimeC__0B00B1BB] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__TimeC__148A1BF5] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Fisca__01774781] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Fisca__0FC566D8] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Fisca__7F8EFF0F] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Fisca__0ED1429F] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Entit__5156606F] DEFAULT ('') FOR [EntityCode]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Patie__073020D7] DEFAULT ((0)) FOR [PatientClassID]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Patie__12A1D383] DEFAULT ('') FOR [PatientClassCode]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Servi__09186949] DEFAULT ((0)) FOR [ServiceLineID]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Servi__1395F7BC] DEFAULT ('') FOR [ServiceLine]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__AgeCo__7BBE6E2B] DEFAULT ((0)) FOR [AgeCohortID]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__AgeCo__0CE8FA2D] DEFAULT ('') FOR [AgeCohort]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Medic__035F8FF3] DEFAULT ((0)) FOR [MedicalSurgicalID]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__MedSu__10B98B11] DEFAULT ('') FOR [MedSurg]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Depar__299CA979] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__OBFor__50623C36] DEFAULT ((0)) FOR [OBForecastDetailID]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Forec__11ADAF4A] DEFAULT ('') FOR [ForecastDetail]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Payor__2C791624] DEFAULT ((0)) FOR [PayorGroupID]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Payor__2B84F1EB] DEFAULT ((0)) FOR [PayorID]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Value__157E402E] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__IsDel__16726467] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Trans__185AACD9] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Entit__4F6E17FD] DEFAULT ((0)) FOR [EntityID]; GO
ALTER TABLE [int].[FactServiceLine] ADD CONSTRAINT [DF__FactServi__Depar__28A88540] DEFAULT ((0)) FOR [DepartmentID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactSharedImportDailyStatistics ------------------
---------------------------------------------
CREATE TABLE [int].[FactSharedImportDailyStatistics] (
    [RowID] bigint NOT NULL,
    [AccountID] int NOT NULL,
    [DepartmentID] int NOT NULL,
    [EntityID] int NOT NULL,
    [StatDate] datetime NOT NULL,
    [AccountCode] nvarchar(100) NOT NULL,
    [DepartmentCode] nvarchar(100) NOT NULL,
    [EntityCode] nvarchar(100) NOT NULL,
    [Value] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    [DateID] int NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    PRIMARY KEY ([RowID])
);

CREATE UNIQUE CLUSTERED INDEX [CU_Base] ON [int].[FactSharedImportDailyStatistics] ([IsDeleted], [DepartmentID], [AccountID], [DateID], [RowID]);
GO
ALTER TABLE [int].[FactSharedImportDailyStatistics] ADD CONSTRAINT [FK__FactShare__Accou__09156DB7] FOREIGN KEY ([AccountID]) REFERENCES [fw].[DimAccount] ([AccountID]); GO
ALTER TABLE [int].[FactSharedImportDailyStatistics] ADD CONSTRAINT [FK__FactShare__Depar__0AFDB629] FOREIGN KEY ([DepartmentID]) REFERENCES [fw].[DimDepartment] ([DepartmentID]); GO
ALTER TABLE [int].[FactSharedImportDailyStatistics] ADD CONSTRAINT [FK__FactShare__Entit__0CE5FE9B] FOREIGN KEY ([EntityID]) REFERENCES [fw].[DimEntity] ([EntityID]); GO
ALTER TABLE [int].[FactSharedImportDailyStatistics] ADD CONSTRAINT [DF__FactShare__Trans__1FF8D30F] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactSharedImportDailyStatistics] ADD CONSTRAINT [DF_FactSharedImportDailyStatistics_TimeClassID] DEFAULT ((1)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactSharedImportDailyStatistics] ADD CONSTRAINT [DF__FactShare__Histo__1F04AED6] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactSharedImportDailyStatistics] ADD CONSTRAINT [DF__FactShare__DateI__4BC3DD62] DEFAULT ((0)) FOR [DateID]; GO
ALTER TABLE [int].[FactSharedImportDailyStatistics] ADD CONSTRAINT [DF__FactShare__Accou__0821497E] DEFAULT ((0)) FOR [AccountID]; GO
ALTER TABLE [int].[FactSharedImportDailyStatistics] ADD CONSTRAINT [DF__FactShare__Depar__0A0991F0] DEFAULT ((0)) FOR [DepartmentID]; GO
ALTER TABLE [int].[FactSharedImportDailyStatistics] ADD CONSTRAINT [DF__FactShare__Entit__0BF1DA62] DEFAULT ((0)) FOR [EntityID]; GO
ALTER TABLE [int].[FactSharedImportDailyStatistics] ADD CONSTRAINT [DF__FactShare__StatD__157B449C] DEFAULT (getdate()) FOR [StatDate]; GO
ALTER TABLE [int].[FactSharedImportDailyStatistics] ADD CONSTRAINT [DF__FactShare__Accou__166F68D5] DEFAULT ('') FOR [AccountCode]; GO
ALTER TABLE [int].[FactSharedImportDailyStatistics] ADD CONSTRAINT [DF__FactShare__Depar__17638D0E] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactSharedImportDailyStatistics] ADD CONSTRAINT [DF__FactShare__Entit__1857B147] DEFAULT ('') FOR [EntityCode]; GO
ALTER TABLE [int].[FactSharedImportDailyStatistics] ADD CONSTRAINT [DF__FactShare__Value__1C28422B] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactSharedImportDailyStatistics] ADD CONSTRAINT [DF__FactShare__IsDel__1E108A9D] DEFAULT ((0)) FOR [IsDeleted]; GO

---------------------------------------------

---------------------------------------------
-- int.FactStaffing ------------------
---------------------------------------------
CREATE TABLE [int].[FactStaffing] (
    [RowID] bigint NOT NULL,
    [DepartmentID] int NOT NULL,
    [DepartmentCode] varchar(100) NOT NULL,
    [JobCodeID] int NOT NULL,
    [JobCode] varchar(50) NOT NULL,
    [EmployeeID] int NOT NULL,
    [Employeecode] nvarchar(2000) NOT NULL,
    [PayCodeID] smallint NOT NULL,
    [PayCode] varchar(100) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] varchar(20) NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] varchar(20) NOT NULL,
    [UnitTypeID] tinyint NOT NULL,
    [UnitType] varchar(20) NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [FiscalMonthCode] varchar(20) NOT NULL,
    [Value] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NULL,
    [GlPostDateID] int NOT NULL,
    [GlPostDateTime] datetime NOT NULL,
    PRIMARY KEY ([RowID])
);

CREATE UNIQUE CLUSTERED INDEX [CU_Base] ON [int].[FactStaffing] ([FiscalMonthID], [IsDeleted], [FiscalYearID], [TimeClassID], [DepartmentID], [JobCodeID], [PayCodeID], [EmployeeID], [UnitTypeID], [RowID]);
CREATE NONCLUSTERED INDEX [NCNU_PayCodeID] ON [int].[FactStaffing] ([PayCodeID]) INCLUDE ([Value]);
CREATE NONCLUSTERED INDEX [NCNU_ReconciliationPerformance] ON [int].[FactStaffing] ([EmployeeID], [UnitTypeID], [FiscalYearID], [PayCodeID]);
CREATE NONCLUSTERED INDEX [NCNU_TransactionID] ON [int].[FactStaffing] ([TransactionID]);
CREATE NONCLUSTERED INDEX [IX_FactStaffing_1] ON [int].[FactStaffing] ([FiscalYearID], [TimeClassID], [UnitTypeID]) INCLUDE ([Value]);
GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__FactStaff__GlPos__0D4E147E] DEFAULT ((0)) FOR [GlPostDateID]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__FactStaff__GlPos__0E4238B7] DEFAULT ('01-01-1900') FOR [GlPostDateTime]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__FactStaff__Depar__2B6F7FBE] DEFAULT ((0)) FOR [DepartmentID]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__FactStaff__Depar__2C63A3F7] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__FactStaff__JobCo__2D57C830] DEFAULT ((0)) FOR [JobCodeID]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__FactStaff__JobCo__2E4BEC69] DEFAULT ('') FOR [JobCode]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__FactStaff__Emplo__6C3C01AF] DEFAULT ((0)) FOR [EmployeeID]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF_INTFACTSTAFFINGEMPLOYEECODE] DEFAULT ('') FOR [Employeecode]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__FactStaff__PayCo__2F4010A2] DEFAULT ((0)) FOR [PayCodeID]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__FactStaff__PayCo__303434DB] DEFAULT ('') FOR [PayCode]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__FactStaff__Fisca__31285914] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__FactStaff__Fisca__321C7D4D] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__FactStaff__TimeC__3310A186] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__FactStaff__TimeC__3404C5BF] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__FactStaff__UnitT__34F8E9F8] DEFAULT ((0)) FOR [UnitTypeID]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__FactStaff__UnitT__35ED0E31] DEFAULT ('') FOR [UnitType]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__FactStaff__Fisca__3CCC1A58] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__FactStaff__Fisca__46558492] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF_INTFACTSTAFFINGVALUE] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__FactStaff__IsDel__4749A8CB] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__FactStaff__Histo__4347094F] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactStaffing] ADD CONSTRAINT [DF__INT_FactStaffing_TransactionID ] DEFAULT ((0)) FOR [TransactionID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactStaffingByPayPeriod ------------------
---------------------------------------------
CREATE TABLE [int].[FactStaffingByPayPeriod] (
    [RowID] bigint NOT NULL,
    [DepartmentID] int NOT NULL,
    [DepartmentCode] varchar(100) NOT NULL,
    [JobCodeID] int NOT NULL,
    [JobCode] varchar(50) NOT NULL,
    [PayCodeID] smallint NOT NULL,
    [PayCode] varchar(100) NOT NULL,
    [PayPeriodID] smallint NOT NULL,
    [PayPeriodCode] varchar(50) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] varchar(20) NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] varchar(20) NOT NULL,
    [UnitTypeID] tinyint NOT NULL,
    [UnitType] varchar(20) NOT NULL,
    [Value] decimal NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [EmployeeID] int NOT NULL,
    [Employeecode] nvarchar(2000) NOT NULL,
    [TransactionID] int NULL,
    [IsDeleted] bit NOT NULL,
    [GlPostDateID] int NOT NULL,
    [GlPostDateTime] datetime NOT NULL,
    PRIMARY KEY ([RowID])
);

CREATE UNIQUE CLUSTERED INDEX [CU_Base] ON [int].[FactStaffingByPayPeriod] ([IsDeleted], [FiscalYearID], [TimeClassID], [PayPeriodID], [DepartmentID], [JobCodeID], [PayCodeID], [EmployeeID], [UnitTypeID], [RowID]);
GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [FK_FactStaff_DimPayPeriod] FOREIGN KEY ([PayPeriodID]) REFERENCES [fw].[DimPayPeriod] ([PayPeriodID]); GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF_INTFACTSTAFFINGBYPAYPERIODEMPLOYEECODE] DEFAULT ('') FOR [Employeecode]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF__FactStaff__GlPos__0B65CC0C] DEFAULT ((0)) FOR [GlPostDateID]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF__FactStaff__GlPos__0C59F045] DEFAULT (getdate()) FOR [GlPostDateTime]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF_FactStaffingByPayPeriod_IsDeleted] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF__INT_FactStaffingByPayPeriod_TransactionID ] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF__FactStaff__Depar__480BBE6C] DEFAULT ((0)) FOR [DepartmentID]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF__FactStaff__Depar__48FFE2A5] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF__FactStaff__JobCo__49F406DE] DEFAULT ((0)) FOR [JobCodeID]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF__FactStaff__JobCo__4AE82B17] DEFAULT ('') FOR [JobCode]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF__FactStaff__PayCo__4BDC4F50] DEFAULT ((0)) FOR [PayCodeID]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF__FactStaff__PayCo__4CD07389] DEFAULT ('') FOR [PayCode]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF_FactStaffingByPayPeriod_PayPeriodID] DEFAULT ((0)) FOR [PayPeriodID]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF_FactStaffingByPayPeriod_PayPeriodCode] DEFAULT ('') FOR [PayPeriodCode]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF__FactStaff__Fisca__4DC497C2] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF__FactStaff__Fisca__4EB8BBFB] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF__FactStaff__TimeC__4FACE034] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF__FactStaff__TimeC__50A1046D] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF__FactStaff__UnitT__519528A6] DEFAULT ((0)) FOR [UnitTypeID]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF__FactStaff__UnitT__52894CDF] DEFAULT ('') FOR [UnitType]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF__FactStaff__Value__537D7118] DEFAULT ((0.0)) FOR [Value]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF__FactStaff__Histo__54719551] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactStaffingByPayPeriod] ADD CONSTRAINT [DF__FactStaff__Emplo__6D3025E8] DEFAULT ((0)) FOR [EmployeeID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactStaffingDaily ------------------
---------------------------------------------
CREATE TABLE [int].[FactStaffingDaily] (
    [RowID] bigint NOT NULL,
    [DepartmentID] int NOT NULL,
    [JobCodeID] int NOT NULL,
    [PayCodeID] smallint NOT NULL,
    [EmployeeID] int NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [UnitTypeID] tinyint NOT NULL,
    [DateID] int NOT NULL,
    [Value] decimal NOT NULL,
    [DepartmentCode] nvarchar(2000) NOT NULL,
    [JobCode] nvarchar(2000) NOT NULL,
    [PayCode] nvarchar(2000) NOT NULL,
    [EmployeeCode] nvarchar(2000) NOT NULL,
    [FiscalYearCode] nvarchar(2000) NOT NULL,
    [TimeClassCode] nvarchar(2000) NOT NULL,
    [UnitType] nvarchar(2000) NOT NULL,
    [PayrollDate] datetime NOT NULL,
    [TransactionCode] nvarchar(2000) NOT NULL,
    [CustomTextField] nvarchar(2000) NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    PRIMARY KEY ([RowID])
);

CREATE UNIQUE CLUSTERED INDEX [CU_Base] ON [int].[FactStaffingDaily] ([IsDeleted], [DepartmentID], [JobCodeID], [PayCodeID], [EmployeeID], [FiscalYearID], [TimeClassID], [UnitTypeID], [DateID], [RowID]);
GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__IsDel__46FF2845] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__Trans__48E770B7] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__Depar__34E0780A] DEFAULT ((0)) FOR [DepartmentID]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__JobCo__35D49C43] DEFAULT ((0)) FOR [JobCodeID]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__PayCo__36C8C07C] DEFAULT ((0)) FOR [PayCodeID]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__Emplo__37BCE4B5] DEFAULT ((0)) FOR [EmployeeID]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__Fisca__38B108EE] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__TimeC__39A52D27] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__UnitT__3A995160] DEFAULT ((0)) FOR [UnitTypeID]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__DateI__3B8D7599] DEFAULT ((0)) FOR [DateID]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__Value__3C8199D2] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__Depar__3D75BE0B] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__JobCo__3E69E244] DEFAULT ('') FOR [JobCode]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__PayCo__3F5E067D] DEFAULT ('') FOR [PayCode]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__Emplo__40522AB6] DEFAULT ('') FOR [EmployeeCode]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__Fisca__41464EEF] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__TimeC__423A7328] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__UnitT__432E9761] DEFAULT ('') FOR [UnitType]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__Payro__4422BB9A] DEFAULT ('1/1/1900 12:00:00 AM') FOR [PayrollDate]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__Trans__4516DFD3] DEFAULT ('') FOR [TransactionCode]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__Custo__460B040C] DEFAULT ('') FOR [CustomTextField]; GO
ALTER TABLE [int].[FactStaffingDaily] ADD CONSTRAINT [DF__FactStaff__Histo__47F34C7E] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactStaffingSummary ------------------
---------------------------------------------
CREATE TABLE [int].[FactStaffingSummary] (
    [RowID] int NOT NULL,
    [DepartmentID] int NOT NULL,
    [DepartmentCode] varchar(100) NOT NULL,
    [JobCodeGroupID] int NOT NULL,
    [JobCodeGroup] varchar(50) NOT NULL,
    [AccountRollupID] int NOT NULL,
    [AccountRollupCode] varchar(50) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] varchar(20) NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] varchar(20) NOT NULL,
    [UnitTypeID] tinyint NOT NULL,
    [UnitType] varchar(20) NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [FiscalMonthCode] varchar(20) NOT NULL,
    [Value] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NULL,
    PRIMARY KEY ([RowID])
);

CREATE UNIQUE CLUSTERED INDEX [CU_Base] ON [int].[FactStaffingSummary] ([FiscalMonthID], [IsDeleted], [FiscalYearID], [TimeClassID], [DepartmentID], [JobCodeGroupID], [AccountRollupID], [UnitTypeID], [RowID]);
GO
ALTER TABLE [int].[FactStaffingSummary] ADD CONSTRAINT [DF__FactStaff__Depar__0FC76549] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactStaffingSummary] ADD CONSTRAINT [DF__FactStaff__JobCo__10BB8982] DEFAULT ((0)) FOR [JobCodeGroupID]; GO
ALTER TABLE [int].[FactStaffingSummary] ADD CONSTRAINT [DF__FactStaff__JobCo__11AFADBB] DEFAULT ('') FOR [JobCodeGroup]; GO
ALTER TABLE [int].[FactStaffingSummary] ADD CONSTRAINT [DF__FactStaff__Accou__12A3D1F4] DEFAULT ((0)) FOR [AccountRollupID]; GO
ALTER TABLE [int].[FactStaffingSummary] ADD CONSTRAINT [DF__FactStaff__Accou__1397F62D] DEFAULT ('') FOR [AccountRollupCode]; GO
ALTER TABLE [int].[FactStaffingSummary] ADD CONSTRAINT [DF__FactStaff__Fisca__148C1A66] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactStaffingSummary] ADD CONSTRAINT [DF__FactStaff__Fisca__15803E9F] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactStaffingSummary] ADD CONSTRAINT [DF__FactStaff__TimeC__167462D8] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactStaffingSummary] ADD CONSTRAINT [DF__FactStaff__TimeC__17688711] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactStaffingSummary] ADD CONSTRAINT [DF__FactStaff__UnitT__185CAB4A] DEFAULT ((0)) FOR [UnitTypeID]; GO
ALTER TABLE [int].[FactStaffingSummary] ADD CONSTRAINT [DF__FactStaff__UnitT__1950CF83] DEFAULT ('') FOR [UnitType]; GO
ALTER TABLE [int].[FactStaffingSummary] ADD CONSTRAINT [DF__FactStaff__Fisca__38FB8974] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactStaffingSummary] ADD CONSTRAINT [DF__INT_FactStaffingSummary_TransactionID ] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactStaffingSummary] ADD CONSTRAINT [DF__FactStaff__Fisca__446D3C20] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactStaffingSummary] ADD CONSTRAINT [DF_INTFACTSTAFFINGSUMMARYVALUE] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactStaffingSummary] ADD CONSTRAINT [DF__FactStaff__IsDel__45616059] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactStaffingSummary] ADD CONSTRAINT [DF__FactStaff__Histo__26AACAA1] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactStaffingSummary] ADD CONSTRAINT [DF__FactStaff__Depar__0ED34110] DEFAULT ((0)) FOR [DepartmentID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactStarPatientADT ------------------
---------------------------------------------
CREATE TABLE [int].[FactStarPatientADT] (
    [RowID] int NOT NULL,
    [EventID] nvarchar(100) NOT NULL,
    [PatientAccountNumber] nvarchar(100) NOT NULL,
    [DateTimeIn] nvarchar(100) NOT NULL,
    [DateTimeOut] nvarchar(100) NOT NULL,
    [SequenceNumber] nvarchar(100) NOT NULL,
    [Department] nvarchar(100) NOT NULL,
    [RoomNumber] nvarchar(100) NOT NULL,
    [BedNumber] nvarchar(100) NOT NULL,
    [TransferInType] nvarchar(100) NOT NULL,
    [TransferOutType] nvarchar(100) NOT NULL,
    [PatientType] nvarchar(100) NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    PRIMARY KEY ([RowID])
);

CREATE NONCLUSTERED INDEX [NC_IDX_StarADT_HistGUID_TrnsInType] ON [int].[FactStarPatientADT] ([HistoryItemGUID], [TransferInType]) INCLUDE ([PatientAccountNumber]);
CREATE NONCLUSTERED INDEX [NC_IDX_Star_PatACN_AllColumns] ON [int].[FactStarPatientADT] ([PatientAccountNumber]) INCLUDE ([DateTimeIn], [DateTimeOut], [SequenceNumber], [Department], [RoomNumber], [TransferInType]);
GO
ALTER TABLE [int].[FactStarPatientADT] ADD CONSTRAINT [DF__FactStarP__Histo__2D01C125] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactStarPatientADT] ADD CONSTRAINT [DF__FactStarP__Event__21900E79] DEFAULT ('') FOR [EventID]; GO
ALTER TABLE [int].[FactStarPatientADT] ADD CONSTRAINT [DF__FactStarP__Patie__228432B2] DEFAULT ('') FOR [PatientAccountNumber]; GO
ALTER TABLE [int].[FactStarPatientADT] ADD CONSTRAINT [DF__FactStarP__DateT__237856EB] DEFAULT ('') FOR [DateTimeIn]; GO
ALTER TABLE [int].[FactStarPatientADT] ADD CONSTRAINT [DF__FactStarP__DateT__246C7B24] DEFAULT ('') FOR [DateTimeOut]; GO
ALTER TABLE [int].[FactStarPatientADT] ADD CONSTRAINT [DF__FactStarP__Seque__25609F5D] DEFAULT ('') FOR [SequenceNumber]; GO
ALTER TABLE [int].[FactStarPatientADT] ADD CONSTRAINT [DF__FactStarP__Depar__2654C396] DEFAULT ('') FOR [Department]; GO
ALTER TABLE [int].[FactStarPatientADT] ADD CONSTRAINT [DF__FactStarP__RoomN__2748E7CF] DEFAULT ('') FOR [RoomNumber]; GO
ALTER TABLE [int].[FactStarPatientADT] ADD CONSTRAINT [DF__FactStarP__BedNu__283D0C08] DEFAULT ('') FOR [BedNumber]; GO
ALTER TABLE [int].[FactStarPatientADT] ADD CONSTRAINT [DF__FactStarP__Trans__29313041] DEFAULT ('') FOR [TransferInType]; GO
ALTER TABLE [int].[FactStarPatientADT] ADD CONSTRAINT [DF__FactStarP__Trans__2A25547A] DEFAULT ('') FOR [TransferOutType]; GO
ALTER TABLE [int].[FactStarPatientADT] ADD CONSTRAINT [DF__FactStarP__Patie__2B1978B3] DEFAULT ('') FOR [PatientType]; GO
ALTER TABLE [int].[FactStarPatientADT] ADD CONSTRAINT [DF__FactStarP__IsDel__2C0D9CEC] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactStarPatientADT] ADD CONSTRAINT [DF__FactStarP__Trans__2DF5E55E] DEFAULT ((0)) FOR [TransactionID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactStatistic ------------------
---------------------------------------------
CREATE TABLE [int].[FactStatistic] (
    [RowID] int NOT NULL,
    [DepartmentID] int NOT NULL,
    [DepartmentCode] varchar(100) NOT NULL,
    [AccountID] int NOT NULL,
    [AccountCode] varchar(50) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] varchar(20) NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] varchar(20) NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [FiscalMonthCode] varchar(20) NOT NULL,
    [Value] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NULL,
    PRIMARY KEY ([RowID])
);

CREATE UNIQUE CLUSTERED INDEX [CU_Base] ON [int].[FactStatistic] ([FiscalMonthID], [IsDeleted], [FiscalYearID], [TimeClassID], [DepartmentID], [AccountID], [RowID]);
CREATE NONCLUSTERED INDEX [IX_FactGL_Covering] ON [int].[FactStatistic] ([AccountID]) INCLUDE ([DepartmentID], [FiscalMonthID], [FiscalYearID], [TimeClassID], [Value]);
GO
ALTER TABLE [int].[FactStatistic] ADD CONSTRAINT [FK__FactStati__Accou__48DCEB82] FOREIGN KEY ([AccountID]) REFERENCES [fw].[DimAccount] ([AccountID]); GO
ALTER TABLE [int].[FactStatistic] ADD CONSTRAINT [FK__FactStati__Depar__4AC533F4] FOREIGN KEY ([DepartmentID]) REFERENCES [fw].[DimDepartment] ([DepartmentID]); GO
ALTER TABLE [int].[FactStatistic] ADD CONSTRAINT [FK__FactStati__Fisca__4CAD7C66] FOREIGN KEY ([FiscalYearID]) REFERENCES [fw].[DimFiscalYear] ([FiscalYearID]); GO
ALTER TABLE [int].[FactStatistic] ADD CONSTRAINT [FK__FactStati__TimeC__4E95C4D8] FOREIGN KEY ([TimeClassID]) REFERENCES [fw].[DimTimeClass] ([TimeClassID]); GO
ALTER TABLE [int].[FactStatistic] ADD CONSTRAINT [DF_FactStatistic_DepartmentCode] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactStatistic] ADD CONSTRAINT [DF_FactStatistic_AccountCode] DEFAULT ('') FOR [AccountCode]; GO
ALTER TABLE [int].[FactStatistic] ADD CONSTRAINT [DF_FactStatistic_FiscalYearCode] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactStatistic] ADD CONSTRAINT [DF__FactStati__Depar__49D10FBB] DEFAULT ((0)) FOR [DepartmentID]; GO
ALTER TABLE [int].[FactStatistic] ADD CONSTRAINT [DF_FactStatistic_TimeClassCode] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactStatistic] ADD CONSTRAINT [DF__INT_FactStatistic_TransactionID ] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactStatistic] ADD CONSTRAINT [DF__FactStati__Accou__47E8C749] DEFAULT ((0)) FOR [AccountID]; GO
ALTER TABLE [int].[FactStatistic] ADD CONSTRAINT [DF__FactStati__Fisca__4BB9582D] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactStatistic] ADD CONSTRAINT [DF__FactStati__TimeC__4DA1A09F] DEFAULT ((0)) FOR [TimeClassID]; GO
ALTER TABLE [int].[FactStatistic] ADD CONSTRAINT [DF__FactStati__Fisca__2D89D6C8] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactStatistic] ADD CONSTRAINT [DF__FactStati__Fisca__3EB462CA] DEFAULT ('') FOR [FiscalMonthCode]; GO
ALTER TABLE [int].[FactStatistic] ADD CONSTRAINT [DF_INTFACTSTATISTICVALUE] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactStatistic] ADD CONSTRAINT [DF__FactStati__Histo__5CE3E42F] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactStatistic] ADD CONSTRAINT [DF__FactStati__IsDel__5BEFBFF6] DEFAULT ((0)) FOR [IsDeleted]; GO

---------------------------------------------

---------------------------------------------
-- int.FactStatisticsbyPayPeriod ------------------
---------------------------------------------
CREATE TABLE [int].[FactStatisticsbyPayPeriod] (
    [RowID] int NOT NULL,
    [TimeClassID] tinyint NOT NULL,
    [TimeClassCode] nvarchar(100) NOT NULL,
    [FiscalYearID] smallint NOT NULL,
    [FiscalYearCode] nvarchar(100) NOT NULL,
    [PayPeriodID] smallint NOT NULL,
    [PayPeriodCode] nvarchar(100) NOT NULL,
    [FiscalMonthID] tinyint NOT NULL,
    [EntityID] int NOT NULL,
    [EntityDescription] nvarchar(200) NOT NULL,
    [DepartmentID] int NOT NULL,
    [DepartmentCode] nvarchar(100) NOT NULL,
    [DepartmentDescription] nvarchar(200) NOT NULL,
    [AccountID] int NOT NULL,
    [AccountCode] nvarchar(100) NOT NULL,
    [AccountDescription] nvarchar(160) NOT NULL,
    [GLRollup] nvarchar(100) NOT NULL,
    [Value] decimal NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    PRIMARY KEY ([RowID])
);

CREATE CLUSTERED INDEX [CNU_Base] ON [int].[FactStatisticsbyPayPeriod] ([PayPeriodID], [FiscalYearID], [TimeClassID], [DepartmentID], [AccountID]);
CREATE NONCLUSTERED INDEX [NCNU_DepartmentAccount] ON [int].[FactStatisticsbyPayPeriod] ([DepartmentID], [AccountID], [PayPeriodID], [FiscalYearID], [TimeClassID]);
GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [FK__FactStati__Accou__0C4779AA] FOREIGN KEY ([AccountID]) REFERENCES [fw].[DimAccount] ([AccountID]); GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [FK__FactStati__Depar__0E2FC21C] FOREIGN KEY ([DepartmentID]) REFERENCES [fw].[DimDepartment] ([DepartmentID]); GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [FK__FactStati__Fisca__10180A8E] FOREIGN KEY ([FiscalYearID]) REFERENCES [fw].[DimFiscalYear] ([FiscalYearID]); GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [FK__FactStati__PayPe__12005300] FOREIGN KEY ([PayPeriodID]) REFERENCES [fw].[DimPayPeriod] ([PayPeriodID]); GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [FK__FactStati__TimeC__13E89B72] FOREIGN KEY ([TimeClassID]) REFERENCES [fw].[DimTimeClass] ([TimeClassID]); GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__TimeC__19A174C8] DEFAULT ('') FOR [TimeClassCode]; GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__Fisca__0F23E655] DEFAULT ((0)) FOR [FiscalYearID]; GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__Fisca__17B92C56] DEFAULT ('') FOR [FiscalYearCode]; GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__PayPe__110C2EC7] DEFAULT ((0)) FOR [PayPeriodID]; GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__PayPe__18AD508F] DEFAULT ('') FOR [PayPeriodCode]; GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__Fisca__52763888] DEFAULT ((0)) FOR [FiscalMonthID]; GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__Entit__545E80FA] DEFAULT ('') FOR [EntityDescription]; GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__Depar__16C5081D] DEFAULT ('') FOR [DepartmentCode]; GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__Depar__5552A533] DEFAULT ('') FOR [DepartmentDescription]; GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__Accou__0B535571] DEFAULT ((0)) FOR [AccountID]; GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__Accou__15D0E3E4] DEFAULT ('') FOR [AccountCode]; GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__Accou__5646C96C] DEFAULT ('') FOR [AccountDescription]; GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__GLRol__536A5CC1] DEFAULT ('') FOR [GLRollup]; GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__Value__14DCBFAB] DEFAULT ((0)) FOR [Value]; GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__IsDel__1A959901] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__Trans__1C7DE173] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__Entit__5182144F] DEFAULT ((0)) FOR [EntityID]; GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__Depar__0D3B9DE3] DEFAULT ((0)) FOR [DepartmentID]; GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__Histo__1B89BD3A] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactStatisticsbyPayPeriod] ADD CONSTRAINT [DF__FactStati__TimeC__12F47739] DEFAULT ((0)) FOR [TimeClassID]; GO

---------------------------------------------

---------------------------------------------
-- int.FactSwipeDataImport ------------------
---------------------------------------------
CREATE TABLE [int].[FactSwipeDataImport] (
    [RowID] int NOT NULL,
    [EntityID] int NOT NULL,
    [DepartmentID] int NOT NULL,
    [JobCodeID] int NOT NULL,
    [PayCodeID] smallint NOT NULL,
    [EmployeeID] int NOT NULL,
    [EmployeeCode] nvarchar(100) NOT NULL,
    [HomeDeptCode] nvarchar(100) NOT NULL,
    [HomeJobCode] nvarchar(100) NOT NULL,
    [WorkedDeptCode] nvarchar(100) NOT NULL,
    [WorkedJobCode] nvarchar(100) NOT NULL,
    [InDate] nvarchar(100) NOT NULL,
    [InTime] nvarchar(100) NOT NULL,
    [OutDate] nvarchar(100) NOT NULL,
    [OutTime] nvarchar(100) NOT NULL,
    [PayCode] nvarchar(100) NOT NULL,
    [PayGroupCode] nvarchar(100) NOT NULL,
    [WorkedEntityCode] nvarchar(100) NOT NULL,
    [HomeEntityCode] nvarchar(100) NOT NULL,
    [IsDeleted] bit NOT NULL,
    [HistoryItemGUID] uniqueidentifier NOT NULL,
    [Version] timestamp NOT NULL,
    [TransactionID] int NOT NULL,
    [InDateTime] datetime NOT NULL,
    [OutDateTime] datetime NOT NULL,
    [IsShiftStart] nvarchar(100) NOT NULL,
    PRIMARY KEY ([RowID])
);
GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [FK__FactSwipe__Depar__78493DBA] FOREIGN KEY ([DepartmentID]) REFERENCES [fw].[DimDepartment] ([DepartmentID]); GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [FK__FactSwipe__Emplo__7E021710] FOREIGN KEY ([EmployeeID]) REFERENCES [fw].[DimEmployee] ([EmployeeID]); GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [FK__FactSwipe__Entit__7660F548] FOREIGN KEY ([EntityID]) REFERENCES [fw].[DimEntity] ([EntityID]); GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [FK__FactSwipe__JobCo__7A31862C] FOREIGN KEY ([JobCodeID]) REFERENCES [fw].[DimJobCode] ([JobCodeID]); GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [FK__FactSwipe__PayCo__7C19CE9E] FOREIGN KEY ([PayCodeID]) REFERENCES [fw].[DimPayCode] ([PayCodeID]); GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__Depar__77551981] DEFAULT ((0)) FOR [DepartmentID]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__JobCo__793D61F3] DEFAULT ((0)) FOR [JobCodeID]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__PayCo__7B25AA65] DEFAULT ((0)) FOR [PayCodeID]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__Emplo__7D0DF2D7] DEFAULT ((0)) FOR [EmployeeID]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__Emplo__7EF63B49] DEFAULT ('') FOR [EmployeeCode]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__HomeD__7FEA5F82] DEFAULT ('') FOR [HomeDeptCode]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__HomeJ__00DE83BB] DEFAULT ('') FOR [HomeJobCode]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__Worke__01D2A7F4] DEFAULT ('') FOR [WorkedDeptCode]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__Worke__02C6CC2D] DEFAULT ('') FOR [WorkedJobCode]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__InDat__03BAF066] DEFAULT ('') FOR [InDate]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__InTim__04AF149F] DEFAULT ('') FOR [InTime]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__OutDa__05A338D8] DEFAULT ('') FOR [OutDate]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__OutTi__06975D11] DEFAULT ('') FOR [OutTime]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__PayCo__078B814A] DEFAULT ('') FOR [PayCode]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__PayGr__087FA583] DEFAULT ('') FOR [PayGroupCode]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__Worke__0973C9BC] DEFAULT ('') FOR [WorkedEntityCode]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__HomeE__0A67EDF5] DEFAULT ('') FOR [HomeEntityCode]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__IsDel__0B5C122E] DEFAULT ((0)) FOR [IsDeleted]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__Trans__0D445AA0] DEFAULT ((0)) FOR [TransactionID]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__InDat__29A238DA] DEFAULT (getdate()) FOR [InDateTime]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__OutDa__2A965D13] DEFAULT (getdate()) FOR [OutDateTime]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__IsShi__57EE812F] DEFAULT ('') FOR [IsShiftStart]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__Histo__0C503667] DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [HistoryItemGUID]; GO
ALTER TABLE [int].[FactSwipeDataImport] ADD CONSTRAINT [DF__FactSwipe__Entit__756CD10F] DEFAULT ((0)) FOR [EntityID]; GO

---------------------------------------------

---------------------------------------------
-- int.PositionTypeJobCodeAssignments ------------------
---------------------------------------------
CREATE TABLE [int].[PositionTypeJobCodeAssignments] (
    [RowId] int NOT NULL,
    [PositionTypeId] int NOT NULL,
    [JobCodeId] int NOT NULL,
    PRIMARY KEY ([RowId])
);
GO
ALTER TABLE [int].[PositionTypeJobCodeAssignments] ADD CONSTRAINT [FK__PositionT__JobCo__47C8F953] FOREIGN KEY ([JobCodeId]) REFERENCES [fw].[DimJobCode] ([JobCodeID]); GO
ALTER TABLE [int].[PositionTypeJobCodeAssignments] ADD CONSTRAINT [FK__PositionT__Posit__46D4D51A] FOREIGN KEY ([PositionTypeId]) REFERENCES [fw].[DimPositionType] ([PositionTypeID]); GO

---------------------------------------------

---------------------------------------------
-- int.QU_Physician_Time_Test_Data_xlsx_f8e654ea_85a1_4884_8db1_f91e3da5edc8 ------------------
---------------------------------------------
CREATE TABLE [int].[QU_Physician_Time_Test_Data_xlsx_f8e654ea_85a1_4884_8db1_f91e3da5edc8] (
    [RowID] varchar(max) NULL,
    [departmentcode] varchar(max) NULL,
    [departmentID] varchar(max) NULL,
    [cptID] varchar(max) NULL,
    [cptcode] varchar(max) NULL,
    [encounterrecordnumber] varchar(max) NULL,
    [CustomPhysicianOfficeTime] varchar(max) NULL
);
GO

---------------------------------------------
---------------------------------------------
--  VIEWS
---------------------------------------------

-- int.viewFactCDMPivoted
/************************************************************
** Author: Ramya Amancharla
** Create Date: 2013-10-25
** Description: Pivoted view for sampling (Will only be used
**	if Charge Code tab is being used without ServiceLine)
** Last Modified: 2016-12-12
** GM Release: 2013-11
**************************************************************
** Change History
**************************************************************
** CID	Date			Author		WI			Description
** 1	2016-12-12	srk			D04896		Filtering out months that are not part of YTD months loaded
** 2   2018-04-03   sdominsk	D-06562   Add cast the setting as an integer.
*************************************************************/
CREATE view [int].[viewFactCDMPivoted] as

select 
	[DepartmentID], 
	[DepartmentCode],
	ChargeCodeID, 
	ChargeCode,
	ServiceLineID,
	ServiceLine,
	AgeCohortID,
	AgeCohort,
	MedicalSurgicalID, 
	MedSurg,
	PatientClassID,
	PatientClassCode,
	FiscalYearID,
	TimeClassID, 
	UnitTypeID,
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
( SELECT [DepartmentID], [DepartmentCode], UnitTypeID,ChargeCodeID, ChargeCode, timeclassID, TimeClassCode,ServiceLine, ServiceLineID, AgeCohort, AgeCohortID, MedicalSurgicalID, MedSurg, [FiscalYearID], [FiscalYearCode],PatientClassID,PatientClassCode, m.MonthColumnName, [Value],f.[HistoryItemGUID]
FROM [int].[FactCDM] f
inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID
where f.IsDeleted = 0
--CID 1
and f.FiscalYearID = (select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year
and Cast(m.FiscalMonthCode as int) <= Cast((Select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '14cbd1a1-15e9-411d-9fea-78cecaadf7e7')as int) -- OB_Months_Loaded
and f.TimeClassID = 1
--CID 1
) as data
PIVOT
(
SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt

UNION ALL

select 
	[DepartmentID], 
	[DepartmentCode],
	ChargeCodeID, 
	ChargeCode,
	ServiceLineID,
	ServiceLine,
	AgeCohortID,
	AgeCohort,
	MedicalSurgicalID, 
	MedSurg,
	PatientClassID,
	PatientClassCode,
	FiscalYearID,
	TimeClassID, 
	UnitTypeID,
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
( SELECT [DepartmentID], [DepartmentCode], UnitTypeID,ChargeCodeID, ChargeCode, timeclassID, TimeClassCode,ServiceLine, ServiceLineID, AgeCohort, AgeCohortID, MedicalSurgicalID, MedSurg, [FiscalYearID], [FiscalYearCode],PatientClassID,PatientClassCode, m.MonthColumnName, [Value],f.[HistoryItemGUID]
FROM [int].[FactCDM] f
inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID
where f.IsDeleted = 0
--CID 1
and f.FiscalYearID = (select dbs.setting - 1 from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year - 1
or f.FiscalYearID = (select dbs.setting + 1 from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year + 1
--CID 1
) as data
PIVOT
(
SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt

UNION ALL

select 
	[DepartmentID], 
	[DepartmentCode],
	ChargeCodeID, 
	ChargeCode,
	ServiceLineID,
	ServiceLine,
	AgeCohortID,
	AgeCohort,
	MedicalSurgicalID, 
	MedSurg,
	PatientClassID,
	PatientClassCode,
	FiscalYearID,
	TimeClassID, 
	UnitTypeID,
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
( SELECT [DepartmentID], [DepartmentCode], UnitTypeID,ChargeCodeID, ChargeCode, timeclassID, TimeClassCode,ServiceLine, ServiceLineID, AgeCohort, AgeCohortID, MedicalSurgicalID, MedSurg, [FiscalYearID], [FiscalYearCode],PatientClassID,PatientClassCode, m.MonthColumnName, [Value],f.[HistoryItemGUID]
FROM [int].[FactCDM] f
inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID
where f.IsDeleted = 0
--CID 1
and f.FiscalYearID = (select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year
and f.TimeClassID = 2
--CID 1
) as data
PIVOT
(
SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt
GO


---------------------------------------------

-- int.viewFactGLPivoted
/*******************************************************************************************************
** Author: unknown
** Create Date: NA
** Description: The pivoted view that is used by the GL account sampling view/proc
** Last Modified: 2016-12-12
** GM Release: 2014.4
********************************************************************************************************
** Change History
********************************************************************************************************
** CID		Date		Author	WI			Description
** 1		2016-12-12	SRK		D-04896   	Filtering out months that are not part of YTD months loaded
** 2		2018-04-03   sdominsk	d-06562   Add cast the setting as an integer.
 
*******************************************************************************************************/

CREATE view [int].[viewFactGLPivoted] as

--------------Actual YTD--------------------------
select 
[DepartmentID],
	[DepartmentCode],
	[AccountID],
	[AccountCode],
	[FiscalYearID],
	[FiscalYearCode],
	[TimeClassID],
	[TimeClassCode],
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
( SELECT [DepartmentID], [DepartmentCode], [AccountID], [AccountCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], m.MonthColumnName, [Value],f.[HistoryItemGUID]
FROM [int].[FactGL] f
inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID 
--CID 1
where 1=1
and f.FiscalYearID = (select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year
and Cast(m.FiscalMonthCode as int) <= Cast((Select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '14cbd1a1-15e9-411d-9fea-78cecaadf7e7')as int) -- OB_Months_Loaded
and f.TimeClassID = 1
--CID 1
) as data
PIVOT
(
SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt

UNION ALL

--------------Actual Prior Year and Budget for Next Year--------------------------
select 
[DepartmentID],
	[DepartmentCode],
	[AccountID],
	[AccountCode],
	[FiscalYearID],
	[FiscalYearCode],
	[TimeClassID],
	[TimeClassCode],
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
( SELECT [DepartmentID], [DepartmentCode], [AccountID], [AccountCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], m.MonthColumnName, [Value],f.[HistoryItemGUID]
FROM [int].[FactGL] f
inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID 
--CID 1
where 1=1
and f.FiscalYearID = (select dbs.setting - 1 from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year - 1
or f.FiscalYearID = (select dbs.setting + 1 from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year + 1
--CID 1
) as data
PIVOT
(
SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt

UNION ALL

--------------Budget for Current Year--------------------------
select 
[DepartmentID],
	[DepartmentCode],
	[AccountID],
	[AccountCode],
	[FiscalYearID],
	[FiscalYearCode],
	[TimeClassID],
	[TimeClassCode],
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
( SELECT [DepartmentID], [DepartmentCode], [AccountID], [AccountCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], m.MonthColumnName, [Value],f.[HistoryItemGUID]
FROM [int].[FactGL] f
inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID 
--CID 1
where 1=1
and f.FiscalYearID = (select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year
and f.TimeClassID = 2
--CID 1
) as data
PIVOT
(
SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt
GO


---------------------------------------------

-- int.viewFactGlobalStatisticsPivoted
CREATE view [int].[viewFactGlobalStatisticsPivoted] as

/*******************************************************************************************************
** Author: unknown
** Create Date: NA
** Description: The pivoted view that is used by the Global Statistics sampling view/proc
** Last Modified: 2016-12-12
** GM Release: 2014.4
********************************************************************************************************
** Change History
********************************************************************************************************
** CID		Date		Author		WI		Description
** 1		2016-12-12	SRK		D-04896   	Filtering out months that are not part of YTD months loaded
** 2      2018-04-03  sdominsk    D-06562 Add cast the setting as an integer.
*******************************************************************************************************/

select 
	[EntityID],
[DepartmentID],
	[DepartmentCode],
	[AccountID],
	[AccountCode],
	[FiscalYearID],
	[FiscalYearCode],
	[TimeClassID],
	[TimeClassCode],
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
( SELECT [EntityID],[DepartmentID], [DepartmentCode], [AccountID], [AccountCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], m.MonthColumnName, [Value],f.[HistoryItemGUID]
FROM [int].[FactGlobalStatistics] f
inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID 
--CID 1
where 1=1
and f.FiscalYearID = (select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year
and Cast(m.FiscalMonthCode as int) <= Cast((Select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '14cbd1a1-15e9-411d-9fea-78cecaadf7e7')as int) -- OB_Months_Loaded
and f.TimeClassID = 1
--CID 1
) as data
PIVOT
(
SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt

UNION ALL

select 
	[EntityID],
[DepartmentID],
	[DepartmentCode],
	[AccountID],
	[AccountCode],
	[FiscalYearID],
	[FiscalYearCode],
	[TimeClassID],
	[TimeClassCode],
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
( SELECT [EntityID],[DepartmentID], [DepartmentCode], [AccountID], [AccountCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], m.MonthColumnName, [Value],f.[HistoryItemGUID]
FROM [int].[FactGlobalStatistics] f
inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID 
--CID 1
where 1=1
and f.FiscalYearID = (select dbs.setting - 1 from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year - 1
or f.FiscalYearID = (select dbs.setting + 1 from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year + 1
--CID 1
) as data
PIVOT
(
SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt

UNION ALL

select 
	[EntityID],
[DepartmentID],
	[DepartmentCode],
	[AccountID],
	[AccountCode],
	[FiscalYearID],
	[FiscalYearCode],
	[TimeClassID],
	[TimeClassCode],
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
( SELECT [EntityID],[DepartmentID], [DepartmentCode], [AccountID], [AccountCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], m.MonthColumnName, [Value],f.[HistoryItemGUID]
FROM [int].[FactGlobalStatistics] f
inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID 
--CID 1
where 1=1
and f.FiscalYearID = (select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year
and f.TimeClassID = 2
--CID 1
) as data
PIVOT
(
SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt
GO


---------------------------------------------

-- int.viewFactOBPayorGroupPivoted
/************************************************************
** Author: jgerber
** Create Date: 2013-10-14
** Description: Pivoted view of Payor Group to allow for easy sampling into structure
** Last Modified: 2016-12-12
** GM Release: 2013-11-18
**************************************************************
** Change History
**************************************************************
** CID		Date		Author	WI			Description
** 1		2016-12-12	srk		D-04896		Filtering out months that are not part of YTD months loaded
** 2        2018-04-03  sdominsk D-06562    Add cast the setting as an integer.
*************************************************************/
CREATE view [int].[viewFactOBPayorGroupPivoted] as

select 
	[OBReimbursementPlanID], 
	[ReimbursementPlan],
	[CareSettingID], 
	[CareSettingCode],
	[PayorGroupID],
	[PayorGroupCode],
	[FiscalYearID],
	[FiscalYearCode],
	[TimeClassID],
	[TimeClassCode],
	[OBForeCastDetailID], 
	[OBForeCastDetailCode],
	[PatientClassID], 
	[PatientClassCode],
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
	(ISNULL(Month01, 0)
	+ISNULL(Month02, 0)
	+ISNULL(Month03, 0)
	+ISNULL(Month04, 0)
	+ISNULL(Month05, 0)
	+ISNULL(Month06, 0)
	+ISNULL(Month07, 0)
	+ISNULL(Month08, 0)
	+ISNULL(Month09, 0)
	+ISNULL(Month10, 0)
	+ISNULL(Month11, 0)
	+ISNULL(Month12, 0)
	+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
	( 	
		SELECT 
			[OBReimbursementPlanID], [ReimbursementPlan],
			[CareSettingID],[CareSettingCode],
			[PayorGroupID], [PayorGroupCode], 
			[FiscalYearID], [FiscalYearCode], 
			[TimeClassID], [TimeClassCode], 
			[OBForeCastDetailID], [OBForeCastDetailCode],
			[PatientClassID], [PatientClassCode],
			m.MonthColumnName, 
			[Value],
			f.[HistoryItemGUID] 
		FROM 
			[int].[FactOBPayorGroup] f
			inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID 
			--CID 1
		where 1=1
		and f.FiscalYearID = (select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year
		and Cast(m.FiscalMonthCode as int) <= Cast((Select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '14cbd1a1-15e9-411d-9fea-78cecaadf7e7')as int) -- OB_Months_Loaded
		and f.TimeClassID = 1
			--CID 1
	) as data
	PIVOT
	(
		SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
	) as pvt
	
	UNION ALL
	
	select 
	[OBReimbursementPlanID], 
	[ReimbursementPlan],
	[CareSettingID], 
	[CareSettingCode],
	[PayorGroupID],
	[PayorGroupCode],
	[FiscalYearID],
	[FiscalYearCode],
	[TimeClassID],
	[TimeClassCode],
	[OBForeCastDetailID], 
	[OBForeCastDetailCode],
	[PatientClassID], 
	[PatientClassCode],
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
	(ISNULL(Month01, 0)
	+ISNULL(Month02, 0)
	+ISNULL(Month03, 0)
	+ISNULL(Month04, 0)
	+ISNULL(Month05, 0)
	+ISNULL(Month06, 0)
	+ISNULL(Month07, 0)
	+ISNULL(Month08, 0)
	+ISNULL(Month09, 0)
	+ISNULL(Month10, 0)
	+ISNULL(Month11, 0)
	+ISNULL(Month12, 0)
	+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
	( 	
		SELECT 
			[OBReimbursementPlanID], [ReimbursementPlan],
			[CareSettingID],[CareSettingCode],
			[PayorGroupID], [PayorGroupCode], 
			[FiscalYearID], [FiscalYearCode], 
			[TimeClassID], [TimeClassCode], 
			[OBForeCastDetailID], [OBForeCastDetailCode],
			[PatientClassID], [PatientClassCode],
			m.MonthColumnName, 
			[Value],
			f.[HistoryItemGUID] 
		FROM 
			[int].[FactOBPayorGroup] f
			inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID 
			--CID 1
		where 1=1
		and f.FiscalYearID = (select dbs.setting - 1 from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year - 1
		or f.FiscalYearID = (select dbs.setting + 1 from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year + 1
			--CID 1
	) as data
	PIVOT
	(
		SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
	) as pvt
	
	UNION ALL
	
	select 
	[OBReimbursementPlanID], 
	[ReimbursementPlan],
	[CareSettingID], 
	[CareSettingCode],
	[PayorGroupID],
	[PayorGroupCode],
	[FiscalYearID],
	[FiscalYearCode],
	[TimeClassID],
	[TimeClassCode],
	[OBForeCastDetailID], 
	[OBForeCastDetailCode],
	[PatientClassID], 
	[PatientClassCode],
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
	(ISNULL(Month01, 0)
	+ISNULL(Month02, 0)
	+ISNULL(Month03, 0)
	+ISNULL(Month04, 0)
	+ISNULL(Month05, 0)
	+ISNULL(Month06, 0)
	+ISNULL(Month07, 0)
	+ISNULL(Month08, 0)
	+ISNULL(Month09, 0)
	+ISNULL(Month10, 0)
	+ISNULL(Month11, 0)
	+ISNULL(Month12, 0)
	+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
	( 	
		SELECT 
			[OBReimbursementPlanID], [ReimbursementPlan],
			[CareSettingID],[CareSettingCode],
			[PayorGroupID], [PayorGroupCode], 
			[FiscalYearID], [FiscalYearCode], 
			[TimeClassID], [TimeClassCode], 
			[OBForeCastDetailID], [OBForeCastDetailCode],
			[PatientClassID], [PatientClassCode],
			m.MonthColumnName, 
			[Value],
			f.[HistoryItemGUID] 
		FROM 
			[int].[FactOBPayorGroup] f
			inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID 
			--CID 1
		where 1=1
		and f.FiscalYearID = (select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year
		and f.TimeClassID = 2
			--CID 1
	) as data
	PIVOT
	(
		SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
	) as pvt
GO


---------------------------------------------

-- int.viewFactOBPayorPivoted
/************************************************************
** Author: jgerber
** Create Date: 2013-10-14
** Description: Pivoted view of Payor to allow for easy sampling into structure
** Last Modified: 2016-12-12
** GM Release: 2013-11-18
**************************************************************
** Change History
**************************************************************
** CID		Date			Author	WI			Description
** 1		2016-12-12		SRK		D-04896 	Filtering out months that are not part of YTD months loaded 
** 2        2018-04-03      sdominsk    D-06562 Add cast the setting as an integer.
*************************************************************/
CREATE view [int].[viewFactOBPayorPivoted] as

select 
	[OBReimbursementPlanID], 
	[ReimbursementPlan],
	[CareSettingID], 
	[CareSettingCode],
	[PayorID],
	[PayorCode],
	[FiscalYearID],
	[FiscalYearCode],
	[TimeClassID],
	[TimeClassCode],
	[OBForeCastDetailID], 
	[OBForeCastDetailCode],
	[PatientClassID], 
	[PatientClassCode],
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
	(ISNULL(Month01, 0)
	+ISNULL(Month02, 0)
	+ISNULL(Month03, 0)
	+ISNULL(Month04, 0)
	+ISNULL(Month05, 0)
	+ISNULL(Month06, 0)
	+ISNULL(Month07, 0)
	+ISNULL(Month08, 0)
	+ISNULL(Month09, 0)
	+ISNULL(Month10, 0)
	+ISNULL(Month11, 0)
	+ISNULL(Month12, 0)
	+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
	( 	
		SELECT 
			[OBReimbursementPlanID], [ReimbursementPlan],
			[CareSettingID],[CareSettingCode],
			[PayorID], [PayorCode], 
			[FiscalYearID], [FiscalYearCode], 
			[TimeClassID], [TimeClassCode],
			[OBForeCastDetailID], [OBForeCastDetailCode],
			[PatientClassID], [PatientClassCode],
			m.MonthColumnName, 
			[Value],
			f.[HistoryItemGUID]
		FROM 
			[int].[FactOBPayor] f
			inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID 
		--CID 1
		where 1=1
		and f.FiscalYearID = (select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year
		and Cast(m.FiscalMonthCode as int) <= Cast((Select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '14cbd1a1-15e9-411d-9fea-78cecaadf7e7')as int) -- OB_Months_Loaded
		and f.TimeClassID = 1
		--CID 1
	) as data
	PIVOT
	(
		SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
	) as pvt
	
	UNION ALL
	
select 
	[OBReimbursementPlanID], 
	[ReimbursementPlan],
	[CareSettingID], 
	[CareSettingCode],
	[PayorID],
	[PayorCode],
	[FiscalYearID],
	[FiscalYearCode],
	[TimeClassID],
	[TimeClassCode],
	[OBForeCastDetailID], 
	[OBForeCastDetailCode],
	[PatientClassID], 
	[PatientClassCode],
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
	(ISNULL(Month01, 0)
	+ISNULL(Month02, 0)
	+ISNULL(Month03, 0)
	+ISNULL(Month04, 0)
	+ISNULL(Month05, 0)
	+ISNULL(Month06, 0)
	+ISNULL(Month07, 0)
	+ISNULL(Month08, 0)
	+ISNULL(Month09, 0)
	+ISNULL(Month10, 0)
	+ISNULL(Month11, 0)
	+ISNULL(Month12, 0)
	+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
	( 	
		SELECT 
			[OBReimbursementPlanID], [ReimbursementPlan],
			[CareSettingID],[CareSettingCode],
			[PayorID], [PayorCode], 
			[FiscalYearID], [FiscalYearCode], 
			[TimeClassID], [TimeClassCode],
			[OBForeCastDetailID], [OBForeCastDetailCode],
			[PatientClassID], [PatientClassCode],
			m.MonthColumnName, 
			[Value],
			f.[HistoryItemGUID]
		FROM 
			[int].[FactOBPayor] f
			inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID 
		--CID 1
		where 1=1
		and f.FiscalYearID = (select dbs.setting - 1 from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year - 1
		or f.FiscalYearID = (select dbs.setting + 1 from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year + 1
		--CID 1
	) as data
	PIVOT
	(
		SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
	) as pvt
	
	UNION ALL
	
	select 
	[OBReimbursementPlanID], 
	[ReimbursementPlan],
	[CareSettingID], 
	[CareSettingCode],
	[PayorID],
	[PayorCode],
	[FiscalYearID],
	[FiscalYearCode],
	[TimeClassID],
	[TimeClassCode],
	[OBForeCastDetailID], 
	[OBForeCastDetailCode],
	[PatientClassID], 
	[PatientClassCode],
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
	(ISNULL(Month01, 0)
	+ISNULL(Month02, 0)
	+ISNULL(Month03, 0)
	+ISNULL(Month04, 0)
	+ISNULL(Month05, 0)
	+ISNULL(Month06, 0)
	+ISNULL(Month07, 0)
	+ISNULL(Month08, 0)
	+ISNULL(Month09, 0)
	+ISNULL(Month10, 0)
	+ISNULL(Month11, 0)
	+ISNULL(Month12, 0)
	+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
	( 	
		SELECT 
			[OBReimbursementPlanID], [ReimbursementPlan],
			[CareSettingID],[CareSettingCode],
			[PayorID], [PayorCode], 
			[FiscalYearID], [FiscalYearCode], 
			[TimeClassID], [TimeClassCode],
			[OBForeCastDetailID], [OBForeCastDetailCode],
			[PatientClassID], [PatientClassCode],
			m.MonthColumnName, 
			[Value],
			f.[HistoryItemGUID]
		FROM 
			[int].[FactOBPayor] f
			inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID 
		--CID 1
		where 1=1
		and f.FiscalYearID = (select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year
		and f.TimeClassID = 2
		--CID 1
	) as data
	PIVOT
	(
		SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
	) as pvt
GO


---------------------------------------------

-- int.viewFactPayorSummaryPivoted
create view int.viewFactPayorSummaryPivoted as

select 
	[DepartmentID],
	[DepartmentCode],
	[AccountRollupID], 
	[AccountRollupCode], 
	[FiscalYearID], 
	[FiscalYearCode], 
	[PatientTypeRollupID], 
	[PatientTypeRollupCode], 
	[PayorGroupID], 
	[PayorGroupCode],
	[UnitTypeID],
	[UnitType],
	[TimeClassID],
	[TimeClassCode],
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
( 
SELECT 
	DepartmentID,
	DepartmentCode, 
	AccountRollupID, 
	AccountRollupCode, 
	FiscalYearID, 
	FiscalYearCode, 
	PatientTypeRollupID, 
	PatientTypeRollupCode, 
	PayorGroupID, 
	PayorGroupCode,
	TimeClassID, 
	TimeClassCode, 
	UnitTypeID, 
	UnitType,
	m.MonthColumnName, 
	Value,
	f.HistoryItemGUID
FROM [int].[FactPayorSummary] f
inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID ) as data
PIVOT
(
SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt
GO


---------------------------------------------

-- int.viewFactPhysicianSummaryPivoted
create view int.viewFactPhysicianSummaryPivoted as

select 
    DepartmentID, 
	DepartmentCode, 
	PatientTypeRollupID, 
	PatientTypeRollupCode, 
	AccountRollupID, 
	AccountRollupCode, 
	PhysicianGroupID, 
	PhysicianGroupCode,
	UnitTypeID, 
	UnitType,
	TimeClassID, 
	TimeClassCode, 
	FiscalYearID, 
	FiscalYearCode,
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
( 
SELECT 
    DepartmentID, 
	DepartmentCode, 
	PatientTypeRollupID, 
	PatientTypeRollupCode, 
	AccountRollupID, 
	AccountRollupCode, 
	PhysicianGroupID, 
	PhysicianGroupCode,
	UnitTypeID, 
	UnitType,
	TimeClassID, 
	TimeClassCode, 
	FiscalYearID, 
	FiscalYearCode, 
	m.MonthColumnName, 
	Value,
	f.HistoryItemGUID
FROM [int].[FactPhysicianSummary] f
inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID ) as data
PIVOT
(
SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt
GO


---------------------------------------------

-- int.viewFactProviderPivoted
/************************************************************
** Author: Ramya Amancharla
** Create Date: 2013-08-26
** Description: Pivoted view for sampling
** Last Modified: 2016-12-12
** GM Release: 2013-11
**************************************************************
** Change History
**************************************************************
** CID	Date			Author				WI			Description
** 	1	11/12/2013		ramancharla						Removing UnitTypeID
**	2	2016-12-12		skandimalla			D04896	Filtering out months that are not part of YTD months loaded
**  3   2018-04-03      sdominsk            D-06562 Add cast the setting as an integer. 
*************************************************************/

CREATE view [int].[viewFactProviderPivoted] as

select 
	OBForecastDetailID,
	ProviderID,
	FiscalMonthID,
	TimeClassID,
	DepartmentID,
	FiscalYearID,
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
( SELECT OBForecastDetailID,	ProviderID, f.FiscalMonthID,	TimeClassID, DepartmentID, FiscalYearID,m.MonthColumnName, [Value],f.[HistoryItemGUID]
FROM [int].[FactImportProvider] f
inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID 
--CID 2
where 1=1
and f.FiscalYearID = (select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year
and Cast(m.FiscalMonthCode as int) <= Cast((Select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '14cbd1a1-15e9-411d-9fea-78cecaadf7e7')as int)-- OB_Months_Loaded
and f.TimeClassID = 1
--CID 2
) as data
PIVOT
(
SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt

UNION ALL

select 
	OBForecastDetailID,
	ProviderID,
	FiscalMonthID,
	TimeClassID,
	DepartmentID,
	FiscalYearID,
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
( SELECT OBForecastDetailID,	ProviderID, f.FiscalMonthID,	TimeClassID, DepartmentID, FiscalYearID,m.MonthColumnName, [Value],f.[HistoryItemGUID]
FROM [int].[FactImportProvider] f
inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID 
--CID 2
where 1=1
and f.FiscalYearID = (select dbs.setting - 1 from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year - 1
or f.FiscalYearID = (select dbs.setting + 1 from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year + 1
--CID 2
) as data
PIVOT
(
SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt

UNION ALL

select 
	OBForecastDetailID,
	ProviderID,
	FiscalMonthID,
	TimeClassID,
	DepartmentID,
	FiscalYearID,
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
( SELECT OBForecastDetailID,	ProviderID, f.FiscalMonthID,	TimeClassID, DepartmentID, FiscalYearID,m.MonthColumnName, [Value],f.[HistoryItemGUID]
FROM [int].[FactImportProvider] f
inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID 
--CID 2
where 1=1
and f.FiscalYearID = (select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year
and f.TimeClassID = 2
--CID 2
) as data
PIVOT
(
SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt
GO


---------------------------------------------

-- int.viewFactSPDirectRollingISAccountUnpivoted
create View [int].[viewFactSPDirectRollingISAccountUnpivoted] As
select
	[SPRollingForecastPlanID]
	, [SPRollingForecastPlanName]
	, [AccountRollupID]
	, [SPAccountRollupName]
	, [UnitTypeID]
	, [UnitType]
	, [TimeClassID]
	, [TimeClassCode]
	, [FiscalYearID]
	, [FiscalYearCode]
	, fm.FiscalMonthID
	, fm.FiscalMonthCode
	, Value
FROM 
	(SELECT * FROM [int].[FactSPDirectRollingISAccount] source) As PIV
	UNPIVOT(VALUE FOR MonthColumnName IN ([ValueMonth01], [ValueMonth02], [ValueMonth03], [ValueMonth04], [ValueMonth05], [ValueMonth06], [ValueMonth07], [ValueMonth08], [ValueMonth09], [ValueMonth10], [ValueMonth11], [ValueMonth12])) As f
	inner join fw.DimFiscalMonth fm on f.MonthColumnName=fm.MonthColumnName
GO


---------------------------------------------

-- int.viewFactSPDirectRollingISPayorUnpivoted
create View [int].[viewFactSPDirectRollingISPayorUnpivoted] As
select
	[SPRollingForecastPlanID]
	, [SPRollingForecastPlanName]
	, [AccountRollupID]
	, [SPAccountRollupName]
	, [PatientTypeRollupID]
	, [PatientTypeRollupCode]
	, [PayorGroupID]
	, [PayorGroupCode]
	, [UnitTypeID]
	, [UnitType]
	, [TimeClassID]
	, [TimeClassCode]
	, [FiscalYearID]
	, [FiscalYearCode]
	, fm.FiscalMonthID
	, fm.FiscalMonthCode
	, Value
FROM 
	(SELECT * FROM [int].[FactSPDirectRollingISPayor] source) As PIV
	UNPIVOT(VALUE FOR MonthColumnName IN ([ValueMonth01], [ValueMonth02], [ValueMonth03], [ValueMonth04], [ValueMonth05], [ValueMonth06], [ValueMonth07], [ValueMonth08], [ValueMonth09], [ValueMonth10], [ValueMonth11], [ValueMonth12])) As f
	inner join fw.DimFiscalMonth fm on f.MonthColumnName=fm.MonthColumnName
GO


---------------------------------------------

-- int.viewFactSPDirectRollingISPhysicianUnpivoted
Create View [int].[viewFactSPDirectRollingISPhysicianUnpivoted] As
select
	[SPRollingForecastPlanID]
	, [SPRollingForecastPlanName]
	, [AccountRollupID]
	, [SPAccountRollupName]
	, [PatientTypeRollupID]
	, [PatientTypeRollupCode]
	, [PhysicianGroupID]
	, [PhysicianGroupCode]
	, [UnitTypeID]
	, [UnitType]
	, [TimeClassID]
	, [TimeClassCode]
	, [FiscalYearID]
	, [FiscalYearCode]
	, fm.FiscalMonthID
	, fm.FiscalMonthCode
	, Value
FROM 
	(SELECT * FROM [int].[FactSPDirectRollingISPhysician] source) As PIV
	UNPIVOT(VALUE FOR MonthColumnName IN ([ValueMonth01], [ValueMonth02], [ValueMonth03], [ValueMonth04], [ValueMonth05], [ValueMonth06], [ValueMonth07], [ValueMonth08], [ValueMonth09], [ValueMonth10], [ValueMonth11], [ValueMonth12])) As f
	inner join fw.DimFiscalMonth fm on f.MonthColumnName='Value'+fm.MonthColumnName
GO


---------------------------------------------

-- int.viewFactSPDirectRollingISStaffingUnpivoted
create View [int].[viewFactSPDirectRollingISStaffingUnpivoted] As
select
	[SPRollingForecastPlanID]
	, [SPRollingForecastPlanName]
	, [AccountRollupID]
	, [SPAccountRollupName]
	, [JobCodeGroupID]
	, [JobCodeGroup]
	, [UnitTypeID]
	, [UnitType]
	, [TimeClassID]
	, [TimeClassCode]
	, [FiscalYearID]
	, [FiscalYearCode]
	, fm.FiscalMonthID
	, fm.FiscalMonthCode
	, Value
FROM 
	(SELECT * FROM [int].[FactSPDirectRollingISStaffing] source) As PIV
	UNPIVOT(VALUE FOR MonthColumnName IN ([ValueMonth01], [ValueMonth02], [ValueMonth03], [ValueMonth04], [ValueMonth05], [ValueMonth06], [ValueMonth07], [ValueMonth08], [ValueMonth09], [ValueMonth10], [ValueMonth11], [ValueMonth12])) As f
	inner join fw.DimFiscalMonth fm on f.MonthColumnName=fm.MonthColumnName
GO


---------------------------------------------

-- int.viewFactServiceLinePivoted
/************************************************************
** Author: ramancharla
** Create Date: 2013-10-11
** Description: Service Line view used to pivot the imported data to get it ready to sample into the Service Line Models
** Last Modified: 2016-12-12
** GM Release: 2013-11-18
**************************************************************
** Change History
**************************************************************
** CID		Date			Author			WI			Description
**	1		11/22/13		ramancharla					removing unit type
** 	2		05/29/13		bparrott					removing entity, adding department, added payor, payor group, forecast detail , account rolup
** 	3     	10/14/2014		blewis						removing payor, payor group, forecast detail , account rolup
**	4		2016-12-12		skandimalla		D-04896 	Filtering out months that are not part of YTD months loaded
**  5       2018-04-03      sdominsk        D-06562     Add cast the setting as an integer.
*************************************************************/

CREATE view [int].[viewFactServiceLinePivoted] as

--------------Actual YTD--------------------------
select 
	--EntityID,
	--EntityCode,
	DepartmentID,
	DepartmentCode,
	FiscalYearID,
	FiscalYearCode,
	TimeClassID,
	TimeClassCode,
	AgeCohortID,
	AgeCohort,
	PatientClassID,
	PatientClassCode,
	MedicalSurgicalID,
	MedSurg,
	ServiceLineID,
	ServiceLine,
--added Payor, Payor Group, Forecast Detail, Account Rollup
	--PayorID,
	--PayorCode,
	--PayorGroupID,
	--PayorGroupCode,
	OBForecastDetailID,
	ForecastDetail,
	--AccountRollupID,
	--AccountRollupCode,
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
( 
SELECT 
--	EntityID,
--	EntityCode,
	DepartmentID,
	DepartmentCode, 
	FiscalYearID,
	FiscalYearCode,
	TimeClassID,
	TimeClassCode,
	AgeCohortID,
	AgeCohort,
	PatientClassID,
	PatientClassCode,
	MedicalSurgicalID,
	MedSurg,
	ServiceLineID,
	ServiceLine,
--added Payor, Payor Group, Forecast Detail, Account Rollup
	--PayorID,
	--PayorCode,
	--PayorGroupID,
	--PayorGroupCode,
	OBForecastDetailID,
	ForecastDetail,
	--AccountRollupID,
	--AccountRollupCode,	
	m.MonthColumnName, 
	Value,
	f.HistoryItemGUID
FROM [int].[FactServiceLine] f
inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID
--CID 4
where 1=1
and f.FiscalYearID = (select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year
and Cast(m.FiscalMonthCode as int) <= Cast((Select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '14cbd1a1-15e9-411d-9fea-78cecaadf7e7')as int) -- OB_Months_Loaded
and f.TimeClassID = 1
--CID 4
)as data

PIVOT
(
SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt

UNION ALL

--------------Actual Prior Year and Budget for Next Year--------------------------

select 
	--EntityID,
	--EntityCode,
	DepartmentID,
	DepartmentCode,
	FiscalYearID,
	FiscalYearCode,
	TimeClassID,
	TimeClassCode,
	AgeCohortID,
	AgeCohort,
	PatientClassID,
	PatientClassCode,
	MedicalSurgicalID,
	MedSurg,
	ServiceLineID,
	ServiceLine,
--added Payor, Payor Group, Forecast Detail, Account Rollup
	--PayorID,
	--PayorCode,
	--PayorGroupID,
	--PayorGroupCode,
	OBForecastDetailID,
	ForecastDetail,
	--AccountRollupID,
	--AccountRollupCode,
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
( 
SELECT 
--	EntityID,
--	EntityCode,
	DepartmentID,
	DepartmentCode, 
	FiscalYearID,
	FiscalYearCode,
	TimeClassID,
	TimeClassCode,
	AgeCohortID,
	AgeCohort,
	PatientClassID,
	PatientClassCode,
	MedicalSurgicalID,
	MedSurg,
	ServiceLineID,
	ServiceLine,
--added Payor, Payor Group, Forecast Detail, Account Rollup
	--PayorID,
	--PayorCode,
	--PayorGroupID,
	--PayorGroupCode,
	OBForecastDetailID,
	ForecastDetail,
	--AccountRollupID,
	--AccountRollupCode,	
	m.MonthColumnName, 
	Value,
	f.HistoryItemGUID
FROM [int].[FactServiceLine] f
inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID
--CID 4
where 1=1
and f.FiscalYearID = (select dbs.setting - 1 from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year - 1
or f.FiscalYearID = (select dbs.setting + 1 from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year + 1
--CID 4
)as data

PIVOT
(
SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt

UNION ALL

--------------Budget for Current Year--------------------------

select 
	--EntityID,
	--EntityCode,
	DepartmentID,
	DepartmentCode,
	FiscalYearID,
	FiscalYearCode,
	TimeClassID,
	TimeClassCode,
	AgeCohortID,
	AgeCohort,
	PatientClassID,
	PatientClassCode,
	MedicalSurgicalID,
	MedSurg,
	ServiceLineID,
	ServiceLine,
--added Payor, Payor Group, Forecast Detail, Account Rollup
	--PayorID,
	--PayorCode,
	--PayorGroupID,
	--PayorGroupCode,
	OBForecastDetailID,
	ForecastDetail,
	--AccountRollupID,
	--AccountRollupCode,
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
( 
SELECT 
--	EntityID,
--	EntityCode,
	DepartmentID,
	DepartmentCode, 
	FiscalYearID,
	FiscalYearCode,
	TimeClassID,
	TimeClassCode,
	AgeCohortID,
	AgeCohort,
	PatientClassID,
	PatientClassCode,
	MedicalSurgicalID,
	MedSurg,
	ServiceLineID,
	ServiceLine,
--added Payor, Payor Group, Forecast Detail, Account Rollup
	--PayorID,
	--PayorCode,
	--PayorGroupID,
	--PayorGroupCode,
	OBForecastDetailID,
	ForecastDetail,
	--AccountRollupID,
	--AccountRollupCode,	
	m.MonthColumnName, 
	Value,
	f.HistoryItemGUID
FROM [int].[FactServiceLine] f
inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID
--CID 4
where 1=1
and f.FiscalYearID = (select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year
and f.TimeClassID = 2
--CID 4
)as data

PIVOT
(
SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt
GO


---------------------------------------------

-- int.viewFactStaffPivoted
CREATE view [int].[viewFactStaffPivoted] as

select 
[DepartmentID],
	[DepartmentCode],
	[jobcodeID],
	[jobCode],
	[FiscalYearID],
	[FiscalYearCode],
	[TimeClassID],
	[TimeClassCode],
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
( SELECT [DepartmentID], [DepartmentCode], [JobCodeID], [JobCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], m.MonthColumnName, [Value],f.[HistoryItemGUID]
FROM [int].[FactStaffing] f
inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID ) as data
PIVOT
(
SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt
GO


---------------------------------------------

-- int.viewFactStaffingPivoted
/** Change History
**************************************************************************************************************************************
** CID		Date		Author	WI			Description
** 1		2013-10-04	JG		    		Should only pull from Staffing table since ByPayPeriod will be sampled into Staffing table
** 2		2016-12-12	SK		D-04896   	Filtering out months that are not part of YTD months loaded
** 3		2017-03-10	srk		D-05679		Filtering out budget for next year. Budget for next year should be generated as output data 
											by the model so it does not need to be imported.
** 4		2017-04-26	srk		D-05900		Include filter for next year's budget data so ABB Baseline data gets sampled
** 5      2017-11-16	sdominsk D-06589    Change script in the "Budget for Next Year -- ABB Only-" section.
											       Should looking for setting 'Baseline data source is loaded - GL' from [dbo].[TemplateSettings] but not from  [ob].[SystemSetting].
										       	And should be pulled only Timeclass 18 (Baseline Budget).
** 5       2018-04-03 sdominsk  D-06562     Add cast the setting as an integer.
** 6       2019-03-27   OV      B-22369	    Data from AP is pulled if both "Is ABB Enabled" = 1 and "AP Preview Enabled" = 0.
**************************************************************************************************************************************/

CREATE view [int].[viewFactStaffingPivoted] as


/*------------Actual YTD--------------------------*/
SELECT DepartmentID
	,DepartmentCode
	,JobCodeID
	,JobCode
	,PayCodeID
	,PayCode
	,FiscalYearID
	,FiscalYearCode
	,TimeClassID
	,TimeClassCode
	,UnitTypeID
	,UnitType
	,EmployeeID
	,ISNULL(Month01, 0) [ValueMonth01]
	,ISNULL(Month02, 0) [ValueMonth02]
	,ISNULL(Month03, 0) [ValueMonth03]
	,ISNULL(Month04, 0) [ValueMonth04]
	,ISNULL(Month05, 0) [ValueMonth05]
	,ISNULL(Month06, 0) [ValueMonth06]
	,ISNULL(Month07, 0) [ValueMonth07]
	,ISNULL(Month08, 0) [ValueMonth08]
	,ISNULL(Month09, 0) [ValueMonth09]
	,ISNULL(Month10, 0) [ValueMonth10]
	,ISNULL(Month11, 0) [ValueMonth11]
	,ISNULL(Month12, 0) [ValueMonth12]
	,ISNULL(Month00, 0) [ValueYearly]
	,(ISNULL(Month01, 0) + ISNULL(Month02, 0) + ISNULL(Month03, 0) + ISNULL(Month04, 0) + ISNULL(Month05, 0) + ISNULL(Month06, 0) + ISNULL(Month07, 0) + ISNULL(Month08, 0) + ISNULL(Month09, 0) + ISNULL(Month10, 0) + ISNULL(Month11, 0) + ISNULL(Month12, 0) + ISNULL(Month00, 0)) AS [ValueTotal]
	,[HistoryItemGUID]
FROM (
	SELECT DepartmentID
		,DepartmentCode
		,JobCodeID
		,JobCode
		,PayCodeID
		,PayCode
		,FiscalYearID
		,FiscalYearCode
		,TimeClassID
		,TimeClassCode
		,UnitTypeID
		,UnitType
		,m.MonthColumnName
		,Value
		,EmployeeID
		,f.HistoryItemGUID
	FROM [int].[FactStaffing] f
	INNER JOIN fw.DimFiscalMonth m ON m.FiscalMonthID = f.FiscalMonthID
	/*CID 2*/ WHERE 1 = 1
		AND f.FiscalYearID = (
			SELECT dbs.setting
			FROM [dbo].[DBSetting] dbs
			WHERE dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62'
			) /* OB_Current_Year*/
		AND Cast(m.FiscalMonthCode AS INT) <= Cast((
				SELECT dbs.setting
				FROM [dbo].[DBSetting] dbs
				WHERE dbs.DBSettingGUID = '14cbd1a1-15e9-411d-9fea-78cecaadf7e7'
				) AS INT) /* OB_Months_Loaded*/
		AND f.TimeClassID = 1 /*CID 2*/
	) AS data
PIVOT(SUM(Value) FOR MonthColumnName IN (
			[Month01]
			,[Month02]
			,[Month03]
			,[Month04]
			,[Month05]
			,[Month06]
			,[Month07]
			,[Month08]
			,[Month09]
			,[Month10]
			,[Month11]
			,[Month12]
			,[Month00]
			)) AS pvt

UNION ALL

/*------------Actual Prior Year--------------------------*/
SELECT DepartmentID
	,DepartmentCode
	,JobCodeID
	,JobCode
	,PayCodeID
	,PayCode
	,FiscalYearID
	,FiscalYearCode
	,TimeClassID
	,TimeClassCode
	,UnitTypeID
	,UnitType
	,EmployeeID
	,ISNULL(Month01, 0) [ValueMonth01]
	,ISNULL(Month02, 0) [ValueMonth02]
	,ISNULL(Month03, 0) [ValueMonth03]
	,ISNULL(Month04, 0) [ValueMonth04]
	,ISNULL(Month05, 0) [ValueMonth05]
	,ISNULL(Month06, 0) [ValueMonth06]
	,ISNULL(Month07, 0) [ValueMonth07]
	,ISNULL(Month08, 0) [ValueMonth08]
	,ISNULL(Month09, 0) [ValueMonth09]
	,ISNULL(Month10, 0) [ValueMonth10]
	,ISNULL(Month11, 0) [ValueMonth11]
	,ISNULL(Month12, 0) [ValueMonth12]
	,ISNULL(Month00, 0) [ValueYearly]
	,(ISNULL(Month01, 0) + ISNULL(Month02, 0) + ISNULL(Month03, 0) + ISNULL(Month04, 0) + ISNULL(Month05, 0) + ISNULL(Month06, 0) + ISNULL(Month07, 0) + ISNULL(Month08, 0) + ISNULL(Month09, 0) + ISNULL(Month10, 0) + ISNULL(Month11, 0) + ISNULL(Month12, 0) + ISNULL(Month00, 0)) AS [ValueTotal]
	,[HistoryItemGUID]
FROM (
	SELECT DepartmentID
		,DepartmentCode
		,JobCodeID
		,JobCode
		,PayCodeID
		,PayCode
		,FiscalYearID
		,FiscalYearCode
		,TimeClassID
		,TimeClassCode
		,UnitTypeID
		,UnitType
		,m.MonthColumnName
		,Value
		,EmployeeID
		,f.HistoryItemGUID
	FROM [int].[FactStaffing] f
	INNER JOIN fw.DimFiscalMonth m ON m.FiscalMonthID = f.FiscalMonthID
	/*CID 2*/ WHERE 1 = 1
		AND f.FiscalYearID = (
			SELECT dbs.setting - 1
			FROM [dbo].[DBSetting] dbs
			WHERE dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62'
			) /*CID 2*/
	) AS data
PIVOT(SUM(Value) FOR MonthColumnName IN (
			[Month01]
			,[Month02]
			,[Month03]
			,[Month04]
			,[Month05]
			,[Month06]
			,[Month07]
			,[Month08]
			,[Month09]
			,[Month10]
			,[Month11]
			,[Month12]
			,[Month00]
			)) AS pvt

UNION ALL

/*------------Budget for Next Year -- ABB Only--------------------------*/
SELECT DepartmentID
	,DepartmentCode
	,JobCodeID
	,JobCode
	,PayCodeID
	,PayCode
	,FiscalYearID
	,FiscalYearCode
	,TimeClassID
	,TimeClassCode
	,UnitTypeID
	,UnitType
	,EmployeeID
	,ISNULL(Month01, 0) [ValueMonth01]
	,ISNULL(Month02, 0) [ValueMonth02]
	,ISNULL(Month03, 0) [ValueMonth03]
	,ISNULL(Month04, 0) [ValueMonth04]
	,ISNULL(Month05, 0) [ValueMonth05]
	,ISNULL(Month06, 0) [ValueMonth06]
	,ISNULL(Month07, 0) [ValueMonth07]
	,ISNULL(Month08, 0) [ValueMonth08]
	,ISNULL(Month09, 0) [ValueMonth09]
	,ISNULL(Month10, 0) [ValueMonth10]
	,ISNULL(Month11, 0) [ValueMonth11]
	,ISNULL(Month12, 0) [ValueMonth12]
	,ISNULL(Month00, 0) [ValueYearly]
	,(ISNULL(Month01, 0) + ISNULL(Month02, 0) + ISNULL(Month03, 0) + ISNULL(Month04, 0) + ISNULL(Month05, 0) + ISNULL(Month06, 0) + ISNULL(Month07, 0) + ISNULL(Month08, 0) + ISNULL(Month09, 0) + ISNULL(Month10, 0) + ISNULL(Month11, 0) + ISNULL(Month12, 0) + ISNULL(Month00, 0)) AS [ValueTotal]
	,[HistoryItemGUID]
FROM (
	SELECT DepartmentID
		,DepartmentCode
		,JobCodeID
		,JobCode
		,PayCodeID
		,PayCode
		,FiscalYearID
		,FiscalYearCode
		,TimeClassID
		,TimeClassCode
		,UnitTypeID
		,UnitType
		,m.MonthColumnName
		,Value
		,EmployeeID
		,f.HistoryItemGUID
	FROM [int].[FactStaffing] f
	INNER JOIN fw.DimFiscalMonth m ON m.FiscalMonthID = f.FiscalMonthID
	/*CID 2*/ WHERE 1 = 1 /*CID 3*/
		AND f.FiscalYearID = (
			SELECT dbs.setting + 1
			FROM [dbo].[DBSetting] dbs
			WHERE dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62'
			) /* OB_Current_Year + 1*/
		AND (
			EXISTS (
				SELECT TOP 1 1
				FROM [dbo].[TemplateSettings]
				WHERE SettingID = 'Baseline data source is loaded - GL'
					AND TemplateGUID = 'C397FA93-F151-4751-AD36-7A34AA7EE3EF'
					AND Value = 1
				)
			OR (EXISTS (
				SELECT TOP 1 1
				FROM [fp].[SystemSetting]
				WHERE (Name = 'Is ABB Enabled' AND Value = '1')		)
				AND
				EXISTS (
				SELECT TOP 1 1
				FROM [fp].[SystemSetting]
				WHERE (Name = 'AP Preview Enabled' AND Value = '0') )
            )
			)
		AND f.TimeClassID = 18 /*CID 2*/
	) AS data
PIVOT(SUM(Value) FOR MonthColumnName IN (
			[Month01]
			,[Month02]
			,[Month03]
			,[Month04]
			,[Month05]
			,[Month06]
			,[Month07]
			,[Month08]
			,[Month09]
			,[Month10]
			,[Month11]
			,[Month12]
			,[Month00]
			)) AS pvt
/*CID 4*/

UNION ALL

/*------------Budget for Current Year--------------------------*/
SELECT DepartmentID
	,DepartmentCode
	,JobCodeID
	,JobCode
	,PayCodeID
	,PayCode
	,FiscalYearID
	,FiscalYearCode
	,TimeClassID
	,TimeClassCode
	,UnitTypeID
	,UnitType
	,EmployeeID
	,ISNULL(Month01, 0) [ValueMonth01]
	,ISNULL(Month02, 0) [ValueMonth02]
	,ISNULL(Month03, 0) [ValueMonth03]
	,ISNULL(Month04, 0) [ValueMonth04]
	,ISNULL(Month05, 0) [ValueMonth05]
	,ISNULL(Month06, 0) [ValueMonth06]
	,ISNULL(Month07, 0) [ValueMonth07]
	,ISNULL(Month08, 0) [ValueMonth08]
	,ISNULL(Month09, 0) [ValueMonth09]
	,ISNULL(Month10, 0) [ValueMonth10]
	,ISNULL(Month11, 0) [ValueMonth11]
	,ISNULL(Month12, 0) [ValueMonth12]
	,ISNULL(Month00, 0) [ValueYearly]
	,(ISNULL(Month01, 0) + ISNULL(Month02, 0) + ISNULL(Month03, 0) + ISNULL(Month04, 0) + ISNULL(Month05, 0) + ISNULL(Month06, 0) + ISNULL(Month07, 0) + ISNULL(Month08, 0) + ISNULL(Month09, 0) + ISNULL(Month10, 0) + ISNULL(Month11, 0) + ISNULL(Month12, 0) + ISNULL(Month00, 0)) AS [ValueTotal]
	,[HistoryItemGUID]
FROM (
	SELECT DepartmentID
		,DepartmentCode
		,JobCodeID
		,JobCode
		,PayCodeID
		,PayCode
		,FiscalYearID
		,FiscalYearCode
		,TimeClassID
		,TimeClassCode
		,UnitTypeID
		,UnitType
		,m.MonthColumnName
		,Value
		,EmployeeID
		,f.HistoryItemGUID
	FROM [int].[FactStaffing] f
	INNER JOIN fw.DimFiscalMonth m ON m.FiscalMonthID = f.FiscalMonthID
	/*CID 2*/ WHERE 1 = 1
		AND f.FiscalYearID = (
			SELECT dbs.setting
			FROM [dbo].[DBSetting] dbs
			WHERE dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62'
			) /* OB_Current_Year*/
		AND f.TimeClassID = 2 /*CID 2*/
	) AS data
PIVOT(SUM(Value) FOR MonthColumnName IN (
			[Month01]
			,[Month02]
			,[Month03]
			,[Month04]
			,[Month05]
			,[Month06]
			,[Month07]
			,[Month08]
			,[Month09]
			,[Month10]
			,[Month11]
			,[Month12]
			,[Month00]
			)) AS pvt
GO


---------------------------------------------

-- int.viewFactStaffingSummaryPivoted
CREATE view [int].[viewFactStaffingSummaryPivoted] as

select 
	DepartmentID,
	DepartmentCode,
	JobCodeGroupID,
	JobCodeGroup,
	AccountRollupID,
	AccountRollupCode,
	FiscalYearID,
	FiscalYearCode,
	[TimeClassID],
	[TimeClassCode],
	UnitTypeID,
	UnitType,
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	[HistoryItemGUID]
from
( 
SELECT 
	DepartmentID,
	DepartmentCode,
	JobCodeGroupID,
	JobCodeGroup,
	AccountRollupID,
	AccountRollupCode,
	FiscalYearID,
	FiscalYearCode,
	TimeClassID, 
	TimeClassCode, 
	UnitTypeID, 
	UnitType,
	m.MonthColumnName, 
	Value,
	f.HistoryItemGUID
FROM [int].[FactStaffingSummary] f
inner join fw.DimFiscalMonth m on m.FiscalMonthID=f.FiscalMonthID ) as data
PIVOT
(
SUM(Value) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt
GO


---------------------------------------------

-- int.viewFactStaffingValuesPivoted
CREATE VIEW int.viewFactStaffingValuesPivoted
AS
SELECT 
	pv.DepartmentID,
	pv.JobCodeID,
	pv.PayCodeID,
	pv.FiscalYearID,
	pv.TimeClassID,
	pv.UnitTypeID,
	ISNULL(pv.Month01, 0) as Month01,
	ISNULL(pv.Month02, 0) as Month02,
	ISNULL(pv.Month03, 0) as Month03,
	ISNULL(pv.Month04, 0) as Month04,
	ISNULL(pv.Month05, 0) as Month05,
	ISNULL(pv.Month06, 0) as Month06,
	ISNULL(pv.Month07, 0) as Month07,
	ISNULL(pv.Month08, 0) as Month08,
	ISNULL(pv.Month09, 0) as Month09,
	ISNULL(pv.Month10, 0) as Month10,
	ISNULL(pv.Month11, 0) as Month11,
	ISNULL(pv.Month12, 0) as Month12
FROM (
		SELECT 
			fs.DepartmentID,
			fs.JobCodeID,
			fs.PayCodeID,
			fs.FiscalYearID,
			fs.TimeClassID,
			fs.UnitTypeID,
			fm.MonthColumnName,
			fs.Value
		FROM [int].[FactStaffing] fs
		INNER JOIN [fw].[DimFiscalMonth] fm ON fm.FiscalMonthID = fs.FiscalMonthID
	) data
PIVOT
(SUM(Value) FOR MonthColumnName IN ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12])) as pv
GO


---------------------------------------------

-- int.viewFactStatisticPivoted
CREATE view [int].[viewFactStatisticPivoted] as
/************************************************************
** Author: Unknown
** Create Date: 
** Description: The pivoted view that is used by the Stat account sampling view/proc
** Last Modified: 2016-12-12
** GM Release: 2016.2.3
**************************************************************
** Change History
**************************************************************
** CID	Date		Author		WI			Description
** 	1 	2016-06-01	cbb		D-04383	    Remove history item guid
**  2	2016-12-12	srk		D-04896	    Filtering out months that are not part of YTD months loaded
**  3   2018-03-0   sdominsk  D-06562    Cast the setting as an integer for dbs.setting . 
*************************************************************/
--------------Actual YTD--------------------------
select 
	[DepartmentID],
	[DepartmentCode],
	[AccountID],
	[AccountCode],
	[FiscalYearID],
	[FiscalYearCode],
	[TimeClassID],
	[TimeClassCode],
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	'00000000-0000-0000-0000-000000000000' as [HistoryItemGUID]	-- CID 1
from
	(
		SELECT 
			[DepartmentID],
			[DepartmentCode],
			[AccountID],
			[AccountCode],
			[FiscalYearID],
			[FiscalYearCode],
			[TimeClassID],
			[TimeClassCode],
			m.MonthColumnName,
			[Value]
			--,f.[HistoryItemGUID]		-- CID 1
		FROM [int].[FactStatistic] f
			inner join fw.DimFiscalMonth m 
				on m.FiscalMonthID=f.FiscalMonthID 
--CID 1
where 1=1
and f.FiscalYearID = (select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year
and Cast(m.FiscalMonthCode as int) <= Cast((Select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '14cbd1a1-15e9-411d-9fea-78cecaadf7e7')as int) -- OB_Months_Loaded
and f.TimeClassID = 1
--CID 1
	) as data
	PIVOT
		(
			SUM(Value) 
			for MonthColumnName in 
				(
					[Month01],
					[Month02],
					[Month03],
					[Month04],
					[Month05],
					[Month06],
					[Month07],
					[Month08],
					[Month09],
					[Month10],
					[Month11],
					[Month12],
					[Month00]
				)
		) as pvt

UNION ALL


--------------Actual Prior Year and Budget for Next Year--------------------------
select 
	[DepartmentID],
	[DepartmentCode],
	[AccountID],
	[AccountCode],
	[FiscalYearID],
	[FiscalYearCode],
	[TimeClassID],
	[TimeClassCode],
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	'00000000-0000-0000-0000-000000000000' as [HistoryItemGUID]	-- CID 1
from
	(
		SELECT 
			[DepartmentID],
			[DepartmentCode],
			[AccountID],
			[AccountCode],
			[FiscalYearID],
			[FiscalYearCode],
			[TimeClassID],
			[TimeClassCode],
			m.MonthColumnName,
			[Value]
			--,f.[HistoryItemGUID]		-- CID 1
		FROM [int].[FactStatistic] f
			inner join fw.DimFiscalMonth m 
				on m.FiscalMonthID=f.FiscalMonthID 
	--CID 2
		where 1=1
		and f.FiscalYearID = (select dbs.setting - 1 from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year - 1
		or f.FiscalYearID = (select dbs.setting + 1 from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year + 1
	--CID 2
	) as data
	PIVOT
		(
			SUM(Value) 
			for MonthColumnName in 
				(
					[Month01],
					[Month02],
					[Month03],
					[Month04],
					[Month05],
					[Month06],
					[Month07],
					[Month08],
					[Month09],
					[Month10],
					[Month11],
					[Month12],
					[Month00]
				)
		) as pvt

UNION ALL

--------------Budget for Current Year--------------------------

select 
	[DepartmentID],
	[DepartmentCode],
	[AccountID],
	[AccountCode],
	[FiscalYearID],
	[FiscalYearCode],
	[TimeClassID],
	[TimeClassCode],
	ISNULL(Month01, 0) [ValueMonth01],
	ISNULL(Month02, 0) [ValueMonth02],
	ISNULL(Month03, 0) [ValueMonth03],
	ISNULL(Month04, 0) [ValueMonth04],
	ISNULL(Month05, 0) [ValueMonth05],
	ISNULL(Month06, 0) [ValueMonth06],
	ISNULL(Month07, 0) [ValueMonth07],
	ISNULL(Month08, 0) [ValueMonth08],
	ISNULL(Month09, 0) [ValueMonth09],
	ISNULL(Month10, 0) [ValueMonth10],
	ISNULL(Month11, 0) [ValueMonth11],
	ISNULL(Month12, 0) [ValueMonth12],
	ISNULL(Month00, 0) [ValueYearly],
		(ISNULL(Month01, 0)
		+ISNULL(Month02, 0)
		+ISNULL(Month03, 0)
		+ISNULL(Month04, 0)
		+ISNULL(Month05, 0)
		+ISNULL(Month06, 0)
		+ISNULL(Month07, 0)
		+ISNULL(Month08, 0)
		+ISNULL(Month09, 0)
		+ISNULL(Month10, 0)
		+ISNULL(Month11, 0)
		+ISNULL(Month12, 0)
		+ISNULL(Month00, 0)) as [ValueTotal],
	'00000000-0000-0000-0000-000000000000' as [HistoryItemGUID]	-- CID 1
from
	(
		SELECT 
			[DepartmentID],
			[DepartmentCode],
			[AccountID],
			[AccountCode],
			[FiscalYearID],
			[FiscalYearCode],
			[TimeClassID],
			[TimeClassCode],
			m.MonthColumnName,
			[Value]
			--,f.[HistoryItemGUID]		-- CID 1
		FROM [int].[FactStatistic] f
			inner join fw.DimFiscalMonth m 
				on m.FiscalMonthID=f.FiscalMonthID 
	--CID 2
		where 1=1
		and f.FiscalYearID = (select dbs.setting from [dbo].[DBSetting] dbs where dbs.DBSettingGUID = '9c921c27-f3e4-4616-b3fd-925a75870b62') -- OB_Current_Year
		and f.TimeClassID = 2
	--CID 2
	) as data
	PIVOT
		(
			SUM(Value) 
			for MonthColumnName in 
				(
					[Month01],
					[Month02],
					[Month03],
					[Month04],
					[Month05],
					[Month06],
					[Month07],
					[Month08],
					[Month09],
					[Month10],
					[Month11],
					[Month12],
					[Month00]
				)
		) as pvt
GO


---------------------------------------------

-- int.viewImport_ADT_Data_Import_Accepted
CREATE VIEW [int].[viewImport_ADT_Data_Import_Accepted] AS
      SELECT I.* from [int].[Import_93097e23_eabb_43f3_8f3d_c79ceb19edd9_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_ADT_Data_Import_Rejected
CREATE VIEW [int].[viewImport_ADT_Data_Import_Rejected] AS
      SELECT I.* from [int].[Import_93097e23_eabb_43f3_8f3d_c79ceb19edd9_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_APC_Accepted
CREATE VIEW [int].[viewImport_APC_Accepted] AS
      SELECT I.* from [int].[Import_91875e90_a5cb_4d45_a93f_bacaf3d6e5ab_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_APC_Rejected
CREATE VIEW [int].[viewImport_APC_Rejected] AS
      SELECT I.* from [int].[Import_91875e90_a5cb_4d45_a93f_bacaf3d6e5ab_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_APR_DRG_Accepted
CREATE VIEW [int].[viewImport_APR_DRG_Accepted] AS
      SELECT I.* from [int].[Import_a57ad3ab_478b_4682_8de1_eb11594a1e63_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_APR_DRG_Rejected
CREATE VIEW [int].[viewImport_APR_DRG_Rejected] AS
      SELECT I.* from [int].[Import_a57ad3ab_478b_4682_8de1_eb11594a1e63_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_AP_Accepted
CREATE   VIEW [int].[viewImport_AP_Accepted] AS
                SELECT I.* from [int].[Import_FF885362_3CD2_49C1_9F71_34E52704459F_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_AP_Detail__Account__Accepted
CREATE VIEW [int].[viewImport_AP_Detail__Account__Accepted] AS
      SELECT I.* from [int].[Import_a2170c4d_524b_43bf_ae0c_3dc41add37c7_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_AP_Detail__Account__Rejected
CREATE VIEW [int].[viewImport_AP_Detail__Account__Rejected] AS
      SELECT I.* from [int].[Import_a2170c4d_524b_43bf_ae0c_3dc41add37c7_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_AP_Detail__Department_Accepted
CREATE VIEW [int].[viewImport_AP_Detail__Department_Accepted] AS
      SELECT I.* from [int].[Import_31918c69_255b_4d8b_8466_2807769456f3_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_AP_Detail__Department_Rejected
CREATE VIEW [int].[viewImport_AP_Detail__Department_Rejected] AS
      SELECT I.* from [int].[Import_31918c69_255b_4d8b_8466_2807769456f3_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_AP_Detail__Entity_Accepted
CREATE VIEW [int].[viewImport_AP_Detail__Entity_Accepted] AS
      SELECT I.* from [int].[Import_ba58afbc_6795_44c2_b20f_d750b58352c7_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_AP_Detail__Entity_Rejected
CREATE VIEW [int].[viewImport_AP_Detail__Entity_Rejected] AS
      SELECT I.* from [int].[Import_ba58afbc_6795_44c2_b20f_d750b58352c7_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_AP_Rejected
CREATE VIEW [int].[viewImport_AP_Rejected] AS
      SELECT I.* from [int].[Import_ff885362_3cd2_49c1_9f71_34e52704459f_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Account_Class_Accepted
CREATE VIEW [int].[viewImport_Account_Class_Accepted] AS
      SELECT I.* from [int].[Import_8d09af27_cbe4_4298_b143_82153df07736_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Account_Class_Rejected
CREATE VIEW [int].[viewImport_Account_Class_Rejected] AS
      SELECT I.* from [int].[Import_8d09af27_cbe4_4298_b143_82153df07736_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Account_Dimension_Accepted
CREATE VIEW [int].[viewImport_Account_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_046c1e49_22d9_4307_9e6c_ddece0c81814_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Account_Dimension_Rejected
CREATE VIEW [int].[viewImport_Account_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_046c1e49_22d9_4307_9e6c_ddece0c81814_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Account_Status_Accepted
CREATE VIEW [int].[viewImport_Account_Status_Accepted] AS
      SELECT I.* from [int].[Import_083e2fa5_387a_4303_b12d_e57fbecddaba_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Account_Status_Rejected
CREATE VIEW [int].[viewImport_Account_Status_Rejected] AS
      SELECT I.* from [int].[Import_083e2fa5_387a_4303_b12d_e57fbecddaba_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Account_Type_Accepted
CREATE VIEW [int].[viewImport_Account_Type_Accepted] AS
      SELECT I.* from [int].[Import_04ec6ca3_4c91_4618_a243_3fef8e4ae8a2_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Account_Type_Rejected
CREATE VIEW [int].[viewImport_Account_Type_Rejected] AS
      SELECT I.* from [int].[Import_04ec6ca3_4c91_4618_a243_3fef8e4ae8a2_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Admit_Source_Accepted
CREATE VIEW [int].[viewImport_Admit_Source_Accepted] AS
      SELECT I.* from [int].[Import_42301852_f1c6_4162_a412_4c138f64c24c_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Admit_Source_Rejected
CREATE VIEW [int].[viewImport_Admit_Source_Rejected] AS
      SELECT I.* from [int].[Import_42301852_f1c6_4162_a412_4c138f64c24c_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Admit_Type_Accepted
CREATE VIEW [int].[viewImport_Admit_Type_Accepted] AS
      SELECT I.* from [int].[Import_364e6242_32c1_4b1e_9bf1_4e73dbf75f81_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Admit_Type_Rejected
CREATE VIEW [int].[viewImport_Admit_Type_Rejected] AS
      SELECT I.* from [int].[Import_364e6242_32c1_4b1e_9bf1_4e73dbf75f81_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Bill_Area_Accepted
CREATE VIEW [int].[viewImport_Bill_Area_Accepted] AS
      SELECT I.* from [int].[Import_4062e0de_46b1_49fc_9ac4_edf3ffe20041_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Bill_Area_Rejected
CREATE VIEW [int].[viewImport_Bill_Area_Rejected] AS
      SELECT I.* from [int].[Import_4062e0de_46b1_49fc_9ac4_edf3ffe20041_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Bill_Status_Accepted
CREATE VIEW [int].[viewImport_Bill_Status_Accepted] AS
      SELECT I.* from [int].[Import_76b17c6b_646d_46af_83b1_fab576c5c95e_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Bill_Status_Rejected
CREATE VIEW [int].[viewImport_Bill_Status_Rejected] AS
      SELECT I.* from [int].[Import_76b17c6b_646d_46af_83b1_fab576c5c95e_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_CAP_Manufacturer_Import_Accepted
CREATE VIEW [int].[viewImport_CAP_Manufacturer_Import_Accepted] AS
      SELECT I.* from [int].[Import_d9774449_2043_4a3a_96c1_e94d4d84dd0d_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_CAP_Manufacturer_Import_Rejected
CREATE VIEW [int].[viewImport_CAP_Manufacturer_Import_Rejected] AS
      SELECT I.* from [int].[Import_d9774449_2043_4a3a_96c1_e94d4d84dd0d_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_CAP_Vendor_Import_Accepted
CREATE VIEW [int].[viewImport_CAP_Vendor_Import_Accepted] AS
      SELECT I.* from [int].[Import_b9234962_9264_4e66_9b23_0e36044a0680_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_CAP_Vendor_Import_Rejected
CREATE VIEW [int].[viewImport_CAP_Vendor_Import_Rejected] AS
      SELECT I.* from [int].[Import_b9234962_9264_4e66_9b23_0e36044a0680_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_CPT_Accepted
CREATE VIEW [int].[viewImport_CPT_Accepted] AS
      SELECT I.* from [int].[Import_4a72918d_ad78_49ea_987e_606968768bb7_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_CPT_Rejected
CREATE VIEW [int].[viewImport_CPT_Rejected] AS
      SELECT I.* from [int].[Import_4a72918d_ad78_49ea_987e_606968768bb7_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Cerner_Patient_ADT_Accepted
CREATE VIEW [int].[viewImport_Cerner_Patient_ADT_Accepted] AS
      SELECT I.* from [int].[Import_65bd3825_3026_4ea7_9f30_167f2203c7a8_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Cerner_Patient_ADT_Rejected
CREATE VIEW [int].[viewImport_Cerner_Patient_ADT_Rejected] AS
      SELECT I.* from [int].[Import_65bd3825_3026_4ea7_9f30_167f2203c7a8_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Charge_Code_Accepted
CREATE VIEW [int].[viewImport_Charge_Code_Accepted] AS
      SELECT I.* from [int].[Import_b95a048a_c805_48d4_b5b8_f9e7c3d7b2e1_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Charge_Code_Rejected
CREATE VIEW [int].[viewImport_Charge_Code_Rejected] AS
      SELECT I.* from [int].[Import_b95a048a_c805_48d4_b5b8_f9e7c3d7b2e1_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Charge_Code_Type_Accepted
CREATE VIEW [int].[viewImport_Charge_Code_Type_Accepted] AS
      SELECT I.* from [int].[Import_e3d00bc7_4bf4_4974_83d1_65f381fba65a_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Charge_Code_Type_Rejected
CREATE VIEW [int].[viewImport_Charge_Code_Type_Rejected] AS
      SELECT I.* from [int].[Import_e3d00bc7_4bf4_4974_83d1_65f381fba65a_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Chart_String___Department_Accepted
CREATE VIEW [int].[viewImport_Chart_String___Department_Accepted] AS
      SELECT I.* from [int].[Import_9e8131b0_aa80_4ddf_82cb_0a302b5c9ea6_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Chart_String___Department_Rejected
CREATE VIEW [int].[viewImport_Chart_String___Department_Rejected] AS
      SELECT I.* from [int].[Import_9e8131b0_aa80_4ddf_82cb_0a302b5c9ea6_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Chart_String___Entity_Accepted
CREATE VIEW [int].[viewImport_Chart_String___Entity_Accepted] AS
      SELECT I.* from [int].[Import_32dc9972_08dd_47a3_af0d_48656eef1ef4_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Chart_String___Entity_Rejected
CREATE VIEW [int].[viewImport_Chart_String___Entity_Rejected] AS
      SELECT I.* from [int].[Import_32dc9972_08dd_47a3_af0d_48656eef1ef4_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Chart_String___Fund_Accepted
CREATE VIEW [int].[viewImport_Chart_String___Fund_Accepted] AS
      SELECT I.* from [int].[Import_c8c7331d_d553_41e5_8987_df917c2653ea_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Chart_String___Fund_Rejected
CREATE VIEW [int].[viewImport_Chart_String___Fund_Rejected] AS
      SELECT I.* from [int].[Import_c8c7331d_d553_41e5_8987_df917c2653ea_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Chart_String___Home_Department_Accepted
CREATE VIEW [int].[viewImport_Chart_String___Home_Department_Accepted] AS
      SELECT I.* from [int].[Import_467c497f_8ff0_48a8_bc2c_81e557a0bf46_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Chart_String___Home_Department_Rejected
CREATE VIEW [int].[viewImport_Chart_String___Home_Department_Rejected] AS
      SELECT I.* from [int].[Import_467c497f_8ff0_48a8_bc2c_81e557a0bf46_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Chart_String___Program_Accepted
CREATE VIEW [int].[viewImport_Chart_String___Program_Accepted] AS
      SELECT I.* from [int].[Import_3c96d49a_097c_4eee_9f09_a4bf38c1ce90_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Chart_String___Program_Rejected
CREATE VIEW [int].[viewImport_Chart_String___Program_Rejected] AS
      SELECT I.* from [int].[Import_3c96d49a_097c_4eee_9f09_a4bf38c1ce90_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Chart_String___Project_Accepted
CREATE VIEW [int].[viewImport_Chart_String___Project_Accepted] AS
      SELECT I.* from [int].[Import_f8fc007c_d092_4b2b_ac8f_546453a60deb_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Chart_String___Project_Rejected
CREATE VIEW [int].[viewImport_Chart_String___Project_Rejected] AS
      SELECT I.* from [int].[Import_f8fc007c_d092_4b2b_ac8f_546453a60deb_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Claim_ICD_10_Diagnostic_Detail_Accepted
CREATE VIEW [int].[viewImport_Claim_ICD_10_Diagnostic_Detail_Accepted] AS
      SELECT I.* from [int].[Import_6707e9d7_b3b8_4c79_a81d_debcc0f5a9d5_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Claim_ICD_10_Diagnostic_Detail_Rejected
CREATE VIEW [int].[viewImport_Claim_ICD_10_Diagnostic_Detail_Rejected] AS
      SELECT I.* from [int].[Import_6707e9d7_b3b8_4c79_a81d_debcc0f5a9d5_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Claim_ICD_10_Procedural_Detail_Accepted
CREATE VIEW [int].[viewImport_Claim_ICD_10_Procedural_Detail_Accepted] AS
      SELECT I.* from [int].[Import_aa3d4fd6_2a9f_4c72_ab29_b4b8782aa034_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Claim_ICD_10_Procedural_Detail_Rejected
CREATE VIEW [int].[viewImport_Claim_ICD_10_Procedural_Detail_Rejected] AS
      SELECT I.* from [int].[Import_aa3d4fd6_2a9f_4c72_ab29_b4b8782aa034_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Claim_Line_Item_Detail_Accepted
CREATE VIEW [int].[viewImport_Claim_Line_Item_Detail_Accepted] AS
      SELECT I.* from [int].[Import_4ea3d011_7b53_4397_9c6b_998109c5f1a7_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Claim_Line_Item_Detail_Rejected
CREATE VIEW [int].[viewImport_Claim_Line_Item_Detail_Rejected] AS
      SELECT I.* from [int].[Import_4ea3d011_7b53_4397_9c6b_998109c5f1a7_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Claim_Number_Accepted
CREATE VIEW [int].[viewImport_Claim_Number_Accepted] AS
      SELECT I.* from [int].[Import_73cb6477_0c98_43b9_8b3e_afe758a3b795_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Claim_Number_Rejected
CREATE VIEW [int].[viewImport_Claim_Number_Rejected] AS
      SELECT I.* from [int].[Import_73cb6477_0c98_43b9_8b3e_afe758a3b795_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Claim_Patient_Accepted
CREATE VIEW [int].[viewImport_Claim_Patient_Accepted] AS
      SELECT I.* from [int].[Import_9d0bade3_2b6b_4133_a72e_251bf38688c4_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Claim_Patient_Encounter_Accepted
CREATE VIEW [int].[viewImport_Claim_Patient_Encounter_Accepted] AS
      SELECT I.* from [int].[Import_ef55dbd6_a275_405f_8a96_7f27673dcf57_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Claim_Patient_Encounter_Rejected
CREATE VIEW [int].[viewImport_Claim_Patient_Encounter_Rejected] AS
      SELECT I.* from [int].[Import_ef55dbd6_a275_405f_8a96_7f27673dcf57_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Claim_Patient_Rejected
CREATE VIEW [int].[viewImport_Claim_Patient_Rejected] AS
      SELECT I.* from [int].[Import_9d0bade3_2b6b_4133_a72e_251bf38688c4_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Claim_Summary_Accepted
CREATE VIEW [int].[viewImport_Claim_Summary_Accepted] AS
      SELECT I.* from [int].[Import_f582d6c6_e1af_48cb_8318_568324fe78d6_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Claim_Summary_Rejected
CREATE VIEW [int].[viewImport_Claim_Summary_Rejected] AS
      SELECT I.* from [int].[Import_f582d6c6_e1af_48cb_8318_568324fe78d6_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Clinical_Department_Accepted
CREATE VIEW [int].[viewImport_Clinical_Department_Accepted] AS
      SELECT I.* from [int].[Import_eb2c2315_5478_4cff_b902_fcda612bc338_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Clinical_Department_Rejected
CREATE VIEW [int].[viewImport_Clinical_Department_Rejected] AS
      SELECT I.* from [int].[Import_eb2c2315_5478_4cff_b902_fcda612bc338_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Clinical_to_GL_Department_Crosswalk_Import_Accepted
CREATE VIEW [int].[viewImport_Clinical_to_GL_Department_Crosswalk_Import_Accepted] AS
      SELECT I.* from [int].[Import_9ef0ee82_5e42_4b84_9021_f1db7565b167_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Clinical_to_GL_Department_Crosswalk_Import_Rejected
CREATE VIEW [int].[viewImport_Clinical_to_GL_Department_Crosswalk_Import_Rejected] AS
      SELECT I.* from [int].[Import_9ef0ee82_5e42_4b84_9021_f1db7565b167_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Coding_Status_Accepted
CREATE VIEW [int].[viewImport_Coding_Status_Accepted] AS
      SELECT I.* from [int].[Import_b4a931ce_95cd_4fe2_a527_4f0a8f4793e2_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Coding_Status_Rejected
CREATE VIEW [int].[viewImport_Coding_Status_Rejected] AS
      SELECT I.* from [int].[Import_b4a931ce_95cd_4fe2_a527_4f0a8f4793e2_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_DSS_Charge_Detail_Update_Accepted
CREATE VIEW [int].[viewImport_DSS_Charge_Detail_Update_Accepted] AS
      SELECT I.* from [int].[Import_84007eba_a8f5_4f76_84a1_bf028b6a9c93_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_DSS_Charge_Detail_Update_Rejected
CREATE VIEW [int].[viewImport_DSS_Charge_Detail_Update_Rejected] AS
      SELECT I.* from [int].[Import_84007eba_a8f5_4f76_84a1_bf028b6a9c93_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_DSS_Encounter_Summary_Update_Accepted
CREATE VIEW [int].[viewImport_DSS_Encounter_Summary_Update_Accepted] AS
      SELECT I.* from [int].[Import_97fd57ed_7fba_4c16_b253_75a0cc7cd7b8_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_DSS_Encounter_Summary_Update_Rejected
CREATE VIEW [int].[viewImport_DSS_Encounter_Summary_Update_Rejected] AS
      SELECT I.* from [int].[Import_97fd57ed_7fba_4c16_b253_75a0cc7cd7b8_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_DSS_Membership_Accepted
CREATE VIEW [int].[viewImport_DSS_Membership_Accepted] AS
      SELECT I.* from [int].[Import_098e5edc_7338_4abb_aa38_fd3b959ee894_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_DSS_Membership_Rejected
CREATE VIEW [int].[viewImport_DSS_Membership_Rejected] AS
      SELECT I.* from [int].[Import_098e5edc_7338_4abb_aa38_fd3b959ee894_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_DSS_Order_Sets_Accepted
CREATE VIEW [int].[viewImport_DSS_Order_Sets_Accepted] AS
      SELECT I.* from [int].[Import_2b3c65b9_1037_4ae6_9fa0_fcd8a7c004fa_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_DSS_Order_Sets_Rejected
CREATE VIEW [int].[viewImport_DSS_Order_Sets_Rejected] AS
      SELECT I.* from [int].[Import_2b3c65b9_1037_4ae6_9fa0_fcd8a7c004fa_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_DSS_Physician_Charge_Update_Accepted
CREATE VIEW [int].[viewImport_DSS_Physician_Charge_Update_Accepted] AS
      SELECT I.* from [int].[Import_736f6e77_ca1f_482f_aa51_8af8bdd8f7b9_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_DSS_Physician_Charge_Update_Rejected
CREATE VIEW [int].[viewImport_DSS_Physician_Charge_Update_Rejected] AS
      SELECT I.* from [int].[Import_736f6e77_ca1f_482f_aa51_8af8bdd8f7b9_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_DSS_Physician_Encounter_Summary_Update_Accepted
CREATE VIEW [int].[viewImport_DSS_Physician_Encounter_Summary_Update_Accepted] AS
      SELECT I.* from [int].[Import_97fd57ed_7fba_4c16_b253_75a0cc7cd7b8_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_DSS_Physician_Encounter_Summary_Update_Rejected
CREATE VIEW [int].[viewImport_DSS_Physician_Encounter_Summary_Update_Rejected] AS
      SELECT I.* from [int].[Import_97fd57ed_7fba_4c16_b253_75a0cc7cd7b8_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_DSS_Statistic_Accounts_Accepted
CREATE VIEW [int].[viewImport_DSS_Statistic_Accounts_Accepted] AS
      SELECT I.* from [int].[Import_58ea5959_ebae_446f_ab99_a6647d7a9158_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_DSS_Statistic_Accounts_Rejected
CREATE VIEW [int].[viewImport_DSS_Statistic_Accounts_Rejected] AS
      SELECT I.* from [int].[Import_58ea5959_ebae_446f_ab99_a6647d7a9158_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_DSS_Stats_Accepted
CREATE VIEW [int].[viewImport_DSS_Stats_Accepted] AS
      SELECT I.* from [int].[Import_36860a9f_b83d_4b5c_93b3_d4284899ef2f_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_DSS_Stats_Rejected
CREATE VIEW [int].[viewImport_DSS_Stats_Rejected] AS
      SELECT I.* from [int].[Import_36860a9f_b83d_4b5c_93b3_d4284899ef2f_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Daily_Staffing_Hours_Import_Accepted
CREATE VIEW [int].[viewImport_Daily_Staffing_Hours_Import_Accepted] AS
      SELECT I.* from [int].[Import_b63569de_9f6b_4b0d_afce_82c699ea16b0_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Daily_Staffing_Hours_Import_Rejected
CREATE VIEW [int].[viewImport_Daily_Staffing_Hours_Import_Rejected] AS
      SELECT I.* from [int].[Import_b63569de_9f6b_4b0d_afce_82c699ea16b0_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Daily_Statistics___Account_Accepted
CREATE VIEW [int].[viewImport_Daily_Statistics___Account_Accepted] AS
      SELECT I.* from [int].[Import_e17d2b59_cbe5_41da_9568_689d4e30f8d1_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Daily_Statistics___Account_Rejected
CREATE VIEW [int].[viewImport_Daily_Statistics___Account_Rejected] AS
      SELECT I.* from [int].[Import_e17d2b59_cbe5_41da_9568_689d4e30f8d1_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Daily_Statistics___Department_Accepted
CREATE VIEW [int].[viewImport_Daily_Statistics___Department_Accepted] AS
      SELECT I.* from [int].[Import_ad87cc47_84bd_4e70_818f_53878696245a_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Daily_Statistics___Department_Rejected
CREATE VIEW [int].[viewImport_Daily_Statistics___Department_Rejected] AS
      SELECT I.* from [int].[Import_ad87cc47_84bd_4e70_818f_53878696245a_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Daily_Statistics___Entity_Accepted
CREATE VIEW [int].[viewImport_Daily_Statistics___Entity_Accepted] AS
      SELECT I.* from [int].[Import_6c103280_bb57_41d4_9df2_9792244ed13e_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Daily_Statistics___Entity_Rejected
CREATE VIEW [int].[viewImport_Daily_Statistics___Entity_Rejected] AS
      SELECT I.* from [int].[Import_6c103280_bb57_41d4_9df2_9792244ed13e_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Data_Accepted
CREATE VIEW [int].[viewImport_Data_Accepted] AS
      SELECT I.* from [int].[Import_c9008ae4_d813_4daf_be6a_e60603ae4291_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Data_Rejected
CREATE VIEW [int].[viewImport_Data_Rejected] AS
      SELECT I.* from [int].[Import_c9008ae4_d813_4daf_be6a_e60603ae4291_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Definitions___Charge_Code_Accepted
CREATE VIEW [int].[viewImport_Definitions___Charge_Code_Accepted] AS
      SELECT I.* from [int].[Import_bac1cc6d_608a_4326_add4_510301e3dbed_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Definitions___Charge_Code_Rejected
CREATE VIEW [int].[viewImport_Definitions___Charge_Code_Rejected] AS
      SELECT I.* from [int].[Import_bac1cc6d_608a_4326_add4_510301e3dbed_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Definitions___Provider_Accepted
CREATE VIEW [int].[viewImport_Definitions___Provider_Accepted] AS
      SELECT I.* from [int].[Import_12358a20_dfb4_4557_b5d4_2754fb693e29_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Definitions___Provider_Rejected
CREATE VIEW [int].[viewImport_Definitions___Provider_Rejected] AS
      SELECT I.* from [int].[Import_12358a20_dfb4_4557_b5d4_2754fb693e29_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Department_Dimension_Accepted
CREATE VIEW [int].[viewImport_Department_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_1a7c67ed_75c5_4f21_b25d_e61463b9e5e3_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Department_Dimension_Rejected
CREATE VIEW [int].[viewImport_Department_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_1a7c67ed_75c5_4f21_b25d_e61463b9e5e3_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Department_Rollup_1_Accepted
CREATE VIEW [int].[viewImport_Department_Rollup_1_Accepted] AS
      SELECT I.* from [int].[Import_7253c618_9ae8_423b_9496_708b18842228_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Department_Rollup_1_Rejected
CREATE VIEW [int].[viewImport_Department_Rollup_1_Rejected] AS
      SELECT I.* from [int].[Import_7253c618_9ae8_423b_9496_708b18842228_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Department_Rollup_2_Accepted
CREATE VIEW [int].[viewImport_Department_Rollup_2_Accepted] AS
      SELECT I.* from [int].[Import_bdeff0f2_ed8f_416c_b5ab_ce916c12546c_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Department_Rollup_2_Rejected
CREATE VIEW [int].[viewImport_Department_Rollup_2_Rejected] AS
      SELECT I.* from [int].[Import_bdeff0f2_ed8f_416c_b5ab_ce916c12546c_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Department_Rollup_3_Accepted
CREATE VIEW [int].[viewImport_Department_Rollup_3_Accepted] AS
      SELECT I.* from [int].[Import_48e437e4_f553_4537_9619_d8d11b494860_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Department_Rollup_3_Rejected
CREATE VIEW [int].[viewImport_Department_Rollup_3_Rejected] AS
      SELECT I.* from [int].[Import_48e437e4_f553_4537_9619_d8d11b494860_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Department_Rollup_4_Accepted
CREATE VIEW [int].[viewImport_Department_Rollup_4_Accepted] AS
      SELECT I.* from [int].[Import_99caa082_e655_43ee_8ebf_29d1128e9c19_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Department_Rollup_4_Rejected
CREATE VIEW [int].[viewImport_Department_Rollup_4_Rejected] AS
      SELECT I.* from [int].[Import_99caa082_e655_43ee_8ebf_29d1128e9c19_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Department_Rollup_5_Accepted
CREATE VIEW [int].[viewImport_Department_Rollup_5_Accepted] AS
      SELECT I.* from [int].[Import_6a3ff17b_8b18_41ca_84a1_9006ec32c3ec_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Department_Rollup_5_Rejected
CREATE VIEW [int].[viewImport_Department_Rollup_5_Rejected] AS
      SELECT I.* from [int].[Import_6a3ff17b_8b18_41ca_84a1_9006ec32c3ec_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Department_Rollup_6_Accepted
CREATE VIEW [int].[viewImport_Department_Rollup_6_Accepted] AS
      SELECT I.* from [int].[Import_bed6f14e_3b4b_4d0e_8b1d_2e49984784b6_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Department_Rollup_6_Rejected
CREATE VIEW [int].[viewImport_Department_Rollup_6_Rejected] AS
      SELECT I.* from [int].[Import_bed6f14e_3b4b_4d0e_8b1d_2e49984784b6_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Department___ADT_Accepted
CREATE VIEW [int].[viewImport_Department___ADT_Accepted] AS
      SELECT I.* from [int].[Import_13a87531_818d_4bd6_8984_1022370bb34b_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Department___ADT_Rejected
CREATE VIEW [int].[viewImport_Department___ADT_Rejected] AS
      SELECT I.* from [int].[Import_13a87531_818d_4bd6_8984_1022370bb34b_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Department___Swipe_Accepted
CREATE VIEW [int].[viewImport_Department___Swipe_Accepted] AS
      SELECT I.* from [int].[Import_5a0dd3bd_e215_4507_a115_dfaa6d4dc144_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Department___Swipe_Rejected
CREATE VIEW [int].[viewImport_Department___Swipe_Rejected] AS
      SELECT I.* from [int].[Import_5a0dd3bd_e215_4507_a115_dfaa6d4dc144_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Discharge_Destination_Accepted
CREATE VIEW [int].[viewImport_Discharge_Destination_Accepted] AS
      SELECT I.* from [int].[Import_f611efd1_6c46_4890_a56c_5d16b62317ef_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Discharge_Destination_Rejected
CREATE VIEW [int].[viewImport_Discharge_Destination_Rejected] AS
      SELECT I.* from [int].[Import_f611efd1_6c46_4890_a56c_5d16b62317ef_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Discharge_Status_Accepted
CREATE VIEW [int].[viewImport_Discharge_Status_Accepted] AS
      SELECT I.* from [int].[Import_cd6af6f5_bef3_4c36_9d56_8184128dca8c_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Discharge_Status_Rejected
CREATE VIEW [int].[viewImport_Discharge_Status_Rejected] AS
      SELECT I.* from [int].[Import_cd6af6f5_bef3_4c36_9d56_8184128dca8c_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_ER_Asset_Accepted
CREATE VIEW [int].[viewImport_ER_Asset_Accepted] AS
      SELECT I.* from [int].[Import_ae7c40cc_a69b_4608_bbb1_2b0930874537_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_ER_Asset_Rejected
CREATE VIEW [int].[viewImport_ER_Asset_Rejected] AS
      SELECT I.* from [int].[Import_ae7c40cc_a69b_4608_bbb1_2b0930874537_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Employee_Dimension_Accepted
CREATE VIEW [int].[viewImport_Employee_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_0c1a0c34_3971_4249_ae11_25f1e62483d3_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Employee_Dimension_Rejected
CREATE VIEW [int].[viewImport_Employee_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_0c1a0c34_3971_4249_ae11_25f1e62483d3_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Employee___Job_Code_Accepted
CREATE VIEW [int].[viewImport_Employee___Job_Code_Accepted] AS
      SELECT I.* from [int].[Import_bd0795a0_27a1_4f98_9488_905a052059b8_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Employee___Job_Code_Rejected
CREATE VIEW [int].[viewImport_Employee___Job_Code_Rejected] AS
      SELECT I.* from [int].[Import_bd0795a0_27a1_4f98_9488_905a052059b8_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Employee___Swipe_Accepted
CREATE VIEW [int].[viewImport_Employee___Swipe_Accepted] AS
      SELECT I.* from [int].[Import_7bbbc308_b7ee_4e56_8294_453b090423a2_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Employee___Swipe_Rejected
CREATE VIEW [int].[viewImport_Employee___Swipe_Rejected] AS
      SELECT I.* from [int].[Import_7bbbc308_b7ee_4e56_8294_453b090423a2_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Employer_Accepted
CREATE VIEW [int].[viewImport_Employer_Accepted] AS
      SELECT I.* from [int].[Import_445b19c4_0c1f_4fa6_ab7d_1efc29601462_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Employer_Rejected
CREATE VIEW [int].[viewImport_Employer_Rejected] AS
      SELECT I.* from [int].[Import_445b19c4_0c1f_4fa6_ab7d_1efc29601462_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Employment_Status_Accepted
CREATE VIEW [int].[viewImport_Employment_Status_Accepted] AS
      SELECT I.* from [int].[Import_028edf9e_1237_40bc_b705_76fb89c062b2_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Employment_Status_Rejected
CREATE VIEW [int].[viewImport_Employment_Status_Rejected] AS
      SELECT I.* from [int].[Import_028edf9e_1237_40bc_b705_76fb89c062b2_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Entity_Accepted
CREATE VIEW [int].[viewImport_Entity_Accepted] AS
      SELECT I.* from [int].[Import_59034048_22d5_4297_bad6_711509824ef0_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Entity_Dimension_Accepted
CREATE VIEW [int].[viewImport_Entity_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_79987164_cfd1_4850_b843_633b11bbcfef_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Entity_Dimension_Rejected
CREATE VIEW [int].[viewImport_Entity_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_79987164_cfd1_4850_b843_633b11bbcfef_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Entity_Rejected
CREATE VIEW [int].[viewImport_Entity_Rejected] AS
      SELECT I.* from [int].[Import_59034048_22d5_4297_bad6_711509824ef0_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Epic_Patient_ADT_Accepted
CREATE VIEW [int].[viewImport_Epic_Patient_ADT_Accepted] AS
      SELECT I.* from [int].[Import_7f420ecd_81f7_4928_9375_67bc0e6a11d4_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Epic_Patient_ADT_Rejected
CREATE VIEW [int].[viewImport_Epic_Patient_ADT_Rejected] AS
      SELECT I.* from [int].[Import_7f420ecd_81f7_4928_9375_67bc0e6a11d4_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Ethnicity_Accepted
CREATE VIEW [int].[viewImport_Ethnicity_Accepted] AS
      SELECT I.* from [int].[Import_763b92b1_2509_40c4_b07b_6c8b944c0824_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Ethnicity_Rejected
CREATE VIEW [int].[viewImport_Ethnicity_Rejected] AS
      SELECT I.* from [int].[Import_763b92b1_2509_40c4_b07b_6c8b944c0824_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_FP_Provider___Department_Accepted
CREATE VIEW [int].[viewImport_FP_Provider___Department_Accepted] AS
      SELECT I.* from [int].[Import_46d6d617_a86b_469b_801e_ed98fc7e1095_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_FP_Provider___Department_Rejected
CREATE VIEW [int].[viewImport_FP_Provider___Department_Rejected] AS
      SELECT I.* from [int].[Import_46d6d617_a86b_469b_801e_ed98fc7e1095_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_FP_Provider___Provider_Accepted
CREATE VIEW [int].[viewImport_FP_Provider___Provider_Accepted] AS
      SELECT I.* from [int].[Import_4732ad1a_6e60_4d3b_85a4_d4e6b17cf656_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_FP_Provider___Provider_Data_Accepted
CREATE VIEW [int].[viewImport_FP_Provider___Provider_Data_Accepted] AS
      SELECT I.* from [int].[Import_21624ee8_8626_4074_913a_803dccd3b257_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_FP_Provider___Provider_Data_Rejected
CREATE VIEW [int].[viewImport_FP_Provider___Provider_Data_Rejected] AS
      SELECT I.* from [int].[Import_21624ee8_8626_4074_913a_803dccd3b257_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_FP_Provider___Provider_Line_Item_Accepted
CREATE VIEW [int].[viewImport_FP_Provider___Provider_Line_Item_Accepted] AS
      SELECT I.* from [int].[Import_7d5a90f2_0697_4dd6_99b0_dc01ed097ed5_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_FP_Provider___Provider_Line_Item_Rejected
CREATE VIEW [int].[viewImport_FP_Provider___Provider_Line_Item_Rejected] AS
      SELECT I.* from [int].[Import_7d5a90f2_0697_4dd6_99b0_dc01ed097ed5_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_FP_Provider___Provider_Rejected
CREATE VIEW [int].[viewImport_FP_Provider___Provider_Rejected] AS
      SELECT I.* from [int].[Import_4732ad1a_6e60_4d3b_85a4_d4e6b17cf656_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Financial_Class_Accepted
CREATE VIEW [int].[viewImport_Financial_Class_Accepted] AS
      SELECT I.* from [int].[Import_f135ce47_b163_466e_948a_d37edb01191f_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Financial_Class_Rejected
CREATE VIEW [int].[viewImport_Financial_Class_Rejected] AS
      SELECT I.* from [int].[Import_f135ce47_b163_466e_948a_d37edb01191f_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Financial_Service_Line_Cost_Accepted
CREATE VIEW [int].[viewImport_Financial_Service_Line_Cost_Accepted] AS
      SELECT I.* from [int].[Import_52e46d2d_2300_4763_b192_5b9b7a40c7b9_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Financial_Service_Line_Cost_Rejected
CREATE VIEW [int].[viewImport_Financial_Service_Line_Cost_Rejected] AS
      SELECT I.* from [int].[Import_52e46d2d_2300_4763_b192_5b9b7a40c7b9_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_GL_Accepted
CREATE VIEW [int].[viewImport_GL_Accepted] AS
      SELECT I.* from [int].[Import_c7524bbc_9670_4441_bbb6_f81ab44ffeb9_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_GL_Detail___Account_Accepted
CREATE VIEW [int].[viewImport_GL_Detail___Account_Accepted] AS
      SELECT I.* from [int].[Import_30df7c2e_f1d8_4a95_a60e_d6cf45df5c63_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_GL_Detail___Account_Rejected
CREATE VIEW [int].[viewImport_GL_Detail___Account_Rejected] AS
      SELECT I.* from [int].[Import_30df7c2e_f1d8_4a95_a60e_d6cf45df5c63_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_GL_Detail___Department_Accepted
CREATE VIEW [int].[viewImport_GL_Detail___Department_Accepted] AS
      SELECT I.* from [int].[Import_848aaf1b_5270_4398_ba9e_196ba30e811a_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_GL_Detail___Department_Rejected
CREATE VIEW [int].[viewImport_GL_Detail___Department_Rejected] AS
      SELECT I.* from [int].[Import_848aaf1b_5270_4398_ba9e_196ba30e811a_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_GL_Detail___Entity_Accepted
CREATE VIEW [int].[viewImport_GL_Detail___Entity_Accepted] AS
      SELECT I.* from [int].[Import_727bbd93_6161_4798_9cd8_306c12310213_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_GL_Detail___Entity_Rejected
CREATE VIEW [int].[viewImport_GL_Detail___Entity_Rejected] AS
      SELECT I.* from [int].[Import_727bbd93_6161_4798_9cd8_306c12310213_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_GL_Dollars___Account_Dimension_Accepted
CREATE VIEW [int].[viewImport_GL_Dollars___Account_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_74f78355_3946_4c0f_8258_3b4226e350ed_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_GL_Dollars___Account_Dimension_Rejected
CREATE VIEW [int].[viewImport_GL_Dollars___Account_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_74f78355_3946_4c0f_8258_3b4226e350ed_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_GL_Dollars___Department_Dimension_Accepted
CREATE VIEW [int].[viewImport_GL_Dollars___Department_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_6e6c926a_b0ed_4f08_b9c6_f8a34c7f3df6_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_GL_Dollars___Department_Dimension_Rejected
CREATE VIEW [int].[viewImport_GL_Dollars___Department_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_6e6c926a_b0ed_4f08_b9c6_f8a34c7f3df6_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_GL_Dollars___Entity_Dimension_Accepted
CREATE VIEW [int].[viewImport_GL_Dollars___Entity_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_8ee06a17_968c_4e98_a1ae_8675dba87259_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_GL_Dollars___Entity_Dimension_Rejected
CREATE VIEW [int].[viewImport_GL_Dollars___Entity_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_8ee06a17_968c_4e98_a1ae_8675dba87259_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_GL_Dollars_and_Stats___Account_Dimension_Accepted
CREATE VIEW [int].[viewImport_GL_Dollars_and_Stats___Account_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_651d7197_08e9_4d8a_a9dc_0d8b4ef9dbf4_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_GL_Dollars_and_Stats___Account_Dimension_Rejected
CREATE VIEW [int].[viewImport_GL_Dollars_and_Stats___Account_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_651d7197_08e9_4d8a_a9dc_0d8b4ef9dbf4_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_GL_Dollars_and_Stats___Department_Dimension_Accepted
CREATE VIEW [int].[viewImport_GL_Dollars_and_Stats___Department_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_88e8e3e7_a7b5_4623_bbea_865ed04889bc_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_GL_Dollars_and_Stats___Department_Dimension_Rejected
CREATE VIEW [int].[viewImport_GL_Dollars_and_Stats___Department_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_88e8e3e7_a7b5_4623_bbea_865ed04889bc_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_GL_Dollars_and_Stats___Entity_Dimension_Accepted
CREATE VIEW [int].[viewImport_GL_Dollars_and_Stats___Entity_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_6992d450_167c_49ef_acda_a244db67fa92_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_GL_Dollars_and_Stats___Entity_Dimension_Rejected
CREATE VIEW [int].[viewImport_GL_Dollars_and_Stats___Entity_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_6992d450_167c_49ef_acda_a244db67fa92_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_GL_Rejected
CREATE VIEW [int].[viewImport_GL_Rejected] AS
      SELECT I.* from [int].[Import_c7524bbc_9670_4441_bbb6_f81ab44ffeb9_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_GL_Statistics___Account_Dimension_Accepted
CREATE VIEW [int].[viewImport_GL_Statistics___Account_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_fe8c3254_f36b_4517_a9dd_f1cba0ed8229_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_GL_Statistics___Account_Dimension_Rejected
CREATE VIEW [int].[viewImport_GL_Statistics___Account_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_fe8c3254_f36b_4517_a9dd_f1cba0ed8229_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_GL_Statistics___Department_Dimension_Accepted
CREATE VIEW [int].[viewImport_GL_Statistics___Department_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_f3346fe2_dde5_4558_8064_e69f635b3fe4_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_GL_Statistics___Department_Dimension_Rejected
CREATE VIEW [int].[viewImport_GL_Statistics___Department_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_f3346fe2_dde5_4558_8064_e69f635b3fe4_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_GL_Statistics___Entity_Dimension_Accepted
CREATE VIEW [int].[viewImport_GL_Statistics___Entity_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_634f38fc_9e5f_42f5_93ec_53364d283496_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_GL_Statistics___Entity_Dimension_Rejected
CREATE VIEW [int].[viewImport_GL_Statistics___Entity_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_634f38fc_9e5f_42f5_93ec_53364d283496_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_General_Ledger___Dollars_Accepted
CREATE VIEW [int].[viewImport_General_Ledger___Dollars_Accepted] AS
      SELECT I.* from [int].[Import_acdc514d_78d3_454b_8cc7_100827da737b_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_General_Ledger___Dollars_Rejected
CREATE VIEW [int].[viewImport_General_Ledger___Dollars_Rejected] AS
      SELECT I.* from [int].[Import_acdc514d_78d3_454b_8cc7_100827da737b_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_General_Ledger___Statistics_Accepted
CREATE VIEW [int].[viewImport_General_Ledger___Statistics_Accepted] AS
      SELECT I.* from [int].[Import_0e1cffed_57a5_4e98_a7a6_f4d360516637_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_General_Ledger___Statistics_Rejected
CREATE VIEW [int].[viewImport_General_Ledger___Statistics_Rejected] AS
      SELECT I.* from [int].[Import_0e1cffed_57a5_4e98_a7a6_f4d360516637_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Global_Statistics___Account_Dimension_Accepted
CREATE VIEW [int].[viewImport_Global_Statistics___Account_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_f36dc91e_9cbb_4f26_a8e5_3075af897c36_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Global_Statistics___Account_Dimension_Rejected
CREATE VIEW [int].[viewImport_Global_Statistics___Account_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_f36dc91e_9cbb_4f26_a8e5_3075af897c36_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Global_Statistics___Department_Dimension_Accepted
CREATE VIEW [int].[viewImport_Global_Statistics___Department_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_57cffafa_4d7c_483d_b53e_9d7dc1c0a2df_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Global_Statistics___Department_Dimension_Rejected
CREATE VIEW [int].[viewImport_Global_Statistics___Department_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_57cffafa_4d7c_483d_b53e_9d7dc1c0a2df_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Global_Statistics___Entity_Dimension_Accepted
CREATE VIEW [int].[viewImport_Global_Statistics___Entity_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_941043ef_cd41_407a_9829_5a48eeba9ed6_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Global_Statistics___Entity_Dimension_Rejected
CREATE VIEW [int].[viewImport_Global_Statistics___Entity_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_941043ef_cd41_407a_9829_5a48eeba9ed6_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Guarantor_Accepted
CREATE VIEW [int].[viewImport_Guarantor_Accepted] AS
      SELECT I.* from [int].[Import_348e7530_aef5_4a94_a08d_a19d176fc3b4_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Guarantor_Rejected
CREATE VIEW [int].[viewImport_Guarantor_Rejected] AS
      SELECT I.* from [int].[Import_348e7530_aef5_4a94_a08d_a19d176fc3b4_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Guarantor_Relation_to_Patient_Accepted
CREATE VIEW [int].[viewImport_Guarantor_Relation_to_Patient_Accepted] AS
      SELECT I.* from [int].[Import_7a1c5935_8b9f_465d_aaaa_f396602a3f7c_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Guarantor_Relation_to_Patient_Rejected
CREATE VIEW [int].[viewImport_Guarantor_Relation_to_Patient_Rejected] AS
      SELECT I.* from [int].[Import_7a1c5935_8b9f_465d_aaaa_f396602a3f7c_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_HB_APC_Accepted
CREATE VIEW [int].[viewImport_HB_APC_Accepted] AS
      SELECT I.* from [int].[Import_10d22f81_2a9d_40ce_b50e_b4e2979a1a7b_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_HB_APC_Rejected
CREATE VIEW [int].[viewImport_HB_APC_Rejected] AS
      SELECT I.* from [int].[Import_10d22f81_2a9d_40ce_b50e_b4e2979a1a7b_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_HB_CPT_Accepted
CREATE VIEW [int].[viewImport_HB_CPT_Accepted] AS
      SELECT I.* from [int].[Import_842beb71_e55e_4072_83f8_ae0e81fa3c83_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_HB_CPT_Rejected
CREATE VIEW [int].[viewImport_HB_CPT_Rejected] AS
      SELECT I.* from [int].[Import_842beb71_e55e_4072_83f8_ae0e81fa3c83_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_HB_Charge_Accepted
CREATE VIEW [int].[viewImport_HB_Charge_Accepted] AS
      SELECT I.* from [int].[Import_c9de651a_4a0f_45fa_97d3_2ff5c2a7c0a6_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_HB_Charge_Rejected
CREATE VIEW [int].[viewImport_HB_Charge_Rejected] AS
      SELECT I.* from [int].[Import_c9de651a_4a0f_45fa_97d3_2ff5c2a7c0a6_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_HB_Department_Def_Accepted
CREATE VIEW [int].[viewImport_HB_Department_Def_Accepted] AS
      SELECT I.* from [int].[Import_414ea8b5_e2eb_47b4_a184_3b0ba711eb65_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_HB_Department_Def_Rejected
CREATE VIEW [int].[viewImport_HB_Department_Def_Rejected] AS
      SELECT I.* from [int].[Import_414ea8b5_e2eb_47b4_a184_3b0ba711eb65_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_HB_EAPG_Accepted
CREATE VIEW [int].[viewImport_HB_EAPG_Accepted] AS
      SELECT I.* from [int].[Import_6518daae_02f6_463a_b0bb_46d5d2811690_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_HB_EAPG_Rejected
CREATE VIEW [int].[viewImport_HB_EAPG_Rejected] AS
      SELECT I.* from [int].[Import_6518daae_02f6_463a_b0bb_46d5d2811690_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_HB_Encounter_Summary_Accepted
CREATE VIEW [int].[viewImport_HB_Encounter_Summary_Accepted] AS
      SELECT I.* from [int].[Import_2258b00e_cbfa_4561_aa46_ccff5e6be9bc_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_HB_Encounter_Summary_Rejected
CREATE VIEW [int].[viewImport_HB_Encounter_Summary_Rejected] AS
      SELECT I.* from [int].[Import_2258b00e_cbfa_4561_aa46_ccff5e6be9bc_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_HB_ICD10_Diagnosis_Accepted
CREATE VIEW [int].[viewImport_HB_ICD10_Diagnosis_Accepted] AS
      SELECT I.* from [int].[Import_b3dd76aa_acdf_4af5_b5a6_5e2bc5f770a2_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_HB_ICD10_Diagnosis_Rejected
CREATE VIEW [int].[viewImport_HB_ICD10_Diagnosis_Rejected] AS
      SELECT I.* from [int].[Import_b3dd76aa_acdf_4af5_b5a6_5e2bc5f770a2_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_HB_ICD10_Procedure_Accepted
CREATE VIEW [int].[viewImport_HB_ICD10_Procedure_Accepted] AS
      SELECT I.* from [int].[Import_f7849bf9_92bc_4d1c_a391_7009e89c7a72_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_HB_ICD10_Procedure_Rejected
CREATE VIEW [int].[viewImport_HB_ICD10_Procedure_Rejected] AS
      SELECT I.* from [int].[Import_f7849bf9_92bc_4d1c_a391_7009e89c7a72_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_HB_ICD9_Diagnosis_Accepted
CREATE VIEW [int].[viewImport_HB_ICD9_Diagnosis_Accepted] AS
      SELECT I.* from [int].[Import_6612abe2_5105_4737_af57_62c4b75d9166_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_HB_ICD9_Diagnosis_Rejected
CREATE VIEW [int].[viewImport_HB_ICD9_Diagnosis_Rejected] AS
      SELECT I.* from [int].[Import_6612abe2_5105_4737_af57_62c4b75d9166_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_HB_ICD9_Procedure_Accepted
CREATE VIEW [int].[viewImport_HB_ICD9_Procedure_Accepted] AS
      SELECT I.* from [int].[Import_58ed0522_7856_4041_8c47_38b0fe07e16d_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_HB_ICD9_Procedure_Rejected
CREATE VIEW [int].[viewImport_HB_ICD9_Procedure_Rejected] AS
      SELECT I.* from [int].[Import_58ed0522_7856_4041_8c47_38b0fe07e16d_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_HB_Newborn_Accepted
CREATE VIEW [int].[viewImport_HB_Newborn_Accepted] AS
      SELECT I.* from [int].[Import_e6cea41d_96f3_4015_9531_9f428d7170a3_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_HB_Newborn_Rejected
CREATE VIEW [int].[viewImport_HB_Newborn_Rejected] AS
      SELECT I.* from [int].[Import_e6cea41d_96f3_4015_9531_9f428d7170a3_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_HB_Patient_Accepted
CREATE VIEW [int].[viewImport_HB_Patient_Accepted] AS
      SELECT I.* from [int].[Import_75171c9c_2114_432c_a3ac_af18a63e6e3e_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_HB_Patient_Encounter_Accepted
CREATE VIEW [int].[viewImport_HB_Patient_Encounter_Accepted] AS
      SELECT I.* from [int].[Import_20a65a06_4893_4ae9_a1c0_3745bfafecd3_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_HB_Patient_Encounter_Rejected
CREATE VIEW [int].[viewImport_HB_Patient_Encounter_Rejected] AS
      SELECT I.* from [int].[Import_20a65a06_4893_4ae9_a1c0_3745bfafecd3_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_HB_Patient_Mother_Accepted
CREATE VIEW [int].[viewImport_HB_Patient_Mother_Accepted] AS
      SELECT I.* from [int].[Import_338ed6bc_e68a_496f_a148_11c69faf86c2_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_HB_Patient_Mother_Rejected
CREATE VIEW [int].[viewImport_HB_Patient_Mother_Rejected] AS
      SELECT I.* from [int].[Import_338ed6bc_e68a_496f_a148_11c69faf86c2_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_HB_Patient_Rejected
CREATE VIEW [int].[viewImport_HB_Patient_Rejected] AS
      SELECT I.* from [int].[Import_75171c9c_2114_432c_a3ac_af18a63e6e3e_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_HB_Payment_Accepted
CREATE VIEW [int].[viewImport_HB_Payment_Accepted] AS
      SELECT I.* from [int].[Import_98503a8b_709f_451b_b076_e34ca12bce26_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_HB_Payment_Rejected
CREATE VIEW [int].[viewImport_HB_Payment_Rejected] AS
      SELECT I.* from [int].[Import_98503a8b_709f_451b_b076_e34ca12bce26_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_ICD10_DX_Accepted
CREATE VIEW [int].[viewImport_ICD10_DX_Accepted] AS
      SELECT I.* from [int].[Import_e825cfc3_dda8_4cc7_89e1_18f0b2981840_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_ICD10_DX_Rejected
CREATE VIEW [int].[viewImport_ICD10_DX_Rejected] AS
      SELECT I.* from [int].[Import_e825cfc3_dda8_4cc7_89e1_18f0b2981840_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_ICD10_PX_Accepted
CREATE VIEW [int].[viewImport_ICD10_PX_Accepted] AS
      SELECT I.* from [int].[Import_7da8cb8f_032f_4770_8ca5_eb99972911c3_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_ICD10_PX_Rejected
CREATE VIEW [int].[viewImport_ICD10_PX_Rejected] AS
      SELECT I.* from [int].[Import_7da8cb8f_032f_4770_8ca5_eb99972911c3_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_ICD9_DX_Accepted
CREATE VIEW [int].[viewImport_ICD9_DX_Accepted] AS
      SELECT I.* from [int].[Import_22765fae_27dd_4dc1_a62a_d956e1ffc411_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_ICD9_DX_Rejected
CREATE VIEW [int].[viewImport_ICD9_DX_Rejected] AS
      SELECT I.* from [int].[Import_22765fae_27dd_4dc1_a62a_d956e1ffc411_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_ICD9_PX_Accepted
CREATE VIEW [int].[viewImport_ICD9_PX_Accepted] AS
	  SELECT I.* from [int].[Import_a3dda0eb_11dc_4de3_8e90_a187fc846769_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_ICD9_PX_Rejected
CREATE VIEW [int].[viewImport_ICD9_PX_Rejected] AS
	  SELECT I.* from [int].[Import_a3dda0eb_11dc_4de3_8e90_a187fc846769_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Insurance_Plan_Accepted
CREATE VIEW [int].[viewImport_Insurance_Plan_Accepted] AS
      SELECT I.* from [int].[Import_c4f0937d_1cb5_4863_a392_6397b8d05286_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Insurance_Plan_Rejected
CREATE VIEW [int].[viewImport_Insurance_Plan_Rejected] AS
      SELECT I.* from [int].[Import_c4f0937d_1cb5_4863_a392_6397b8d05286_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Inventory___Account_Accepted
CREATE VIEW [int].[viewImport_Inventory___Account_Accepted] AS
      SELECT I.* from [int].[Import_9325dcb3_1392_44bc_ad7d_6ed528f5c1a4_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Inventory___Account_Rejected
CREATE VIEW [int].[viewImport_Inventory___Account_Rejected] AS
      SELECT I.* from [int].[Import_9325dcb3_1392_44bc_ad7d_6ed528f5c1a4_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Inventory___Department_Accepted
CREATE VIEW [int].[viewImport_Inventory___Department_Accepted] AS
      SELECT I.* from [int].[Import_07d9cafb_d6cb_4bbf_90ac_7046aa2f240a_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Inventory___Department_Rejected
CREATE VIEW [int].[viewImport_Inventory___Department_Rejected] AS
      SELECT I.* from [int].[Import_07d9cafb_d6cb_4bbf_90ac_7046aa2f240a_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Inventory___Entity_Accepted
CREATE VIEW [int].[viewImport_Inventory___Entity_Accepted] AS
      SELECT I.* from [int].[Import_4c0b1040_9202_42e6_8cc0_b488ac904805_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Inventory___Entity_Rejected
CREATE VIEW [int].[viewImport_Inventory___Entity_Rejected] AS
      SELECT I.* from [int].[Import_4c0b1040_9202_42e6_8cc0_b488ac904805_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Job_Code_Dimension_Accepted
CREATE VIEW [int].[viewImport_Job_Code_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_d23efdc3_9d21_412e_a854_78044343b3da_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Job_Code_Dimension_Rejected
CREATE VIEW [int].[viewImport_Job_Code_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_d23efdc3_9d21_412e_a854_78044343b3da_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Language_Accepted
CREATE VIEW [int].[viewImport_Language_Accepted] AS
      SELECT I.* from [int].[Import_20a3aede_fb89_4581_94af_8e1c876f9581_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Language_Rejected
CREATE VIEW [int].[viewImport_Language_Rejected] AS
      SELECT I.* from [int].[Import_20a3aede_fb89_4581_94af_8e1c876f9581_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Location_Accepted
CREATE VIEW [int].[viewImport_Location_Accepted] AS
      SELECT I.* from [int].[Import_6579b2fc_0c27_493c_bd5c_957512179500_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Location_Rejected
CREATE VIEW [int].[viewImport_Location_Rejected] AS
      SELECT I.* from [int].[Import_6579b2fc_0c27_493c_bd5c_957512179500_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_MR_Import_PO_Detail_Accepted
CREATE VIEW [int].[viewImport_MR_Import_PO_Detail_Accepted] AS
      SELECT I.* from [int].[Import_b6e47e1b_9e3a_41c3_954d_bf8e01e0939c_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_MR_Import_PO_Detail_Rejected
CREATE VIEW [int].[viewImport_MR_Import_PO_Detail_Rejected] AS
      SELECT I.* from [int].[Import_b6e47e1b_9e3a_41c3_954d_bf8e01e0939c_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_MR___Import___Inventory_Detail_Accepted
CREATE VIEW [int].[viewImport_MR___Import___Inventory_Detail_Accepted] AS
      SELECT I.* from [int].[Import_61e83a29_7616_4c97_b8e5_052ba9f2564d_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_MR___Import___Inventory_Detail_Rejected
CREATE VIEW [int].[viewImport_MR___Import___Inventory_Detail_Rejected] AS
      SELECT I.* from [int].[Import_61e83a29_7616_4c97_b8e5_052ba9f2564d_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Marital_Status_Accepted
CREATE VIEW [int].[viewImport_Marital_Status_Accepted] AS
      SELECT I.* from [int].[Import_6b471f1c_a562_47b8_ba15_f2838ef7612d_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Marital_Status_Rejected
CREATE VIEW [int].[viewImport_Marital_Status_Rejected] AS
      SELECT I.* from [int].[Import_6b471f1c_a562_47b8_ba15_f2838ef7612d_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Method_of_Arrival_Accepted
CREATE VIEW [int].[viewImport_Method_of_Arrival_Accepted] AS
      SELECT I.* from [int].[Import_14408ff3_5253_4210_b488_0c4d64f8ef29_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Method_of_Arrival_Rejected
CREATE VIEW [int].[viewImport_Method_of_Arrival_Rejected] AS
      SELECT I.* from [int].[Import_14408ff3_5253_4210_b488_0c4d64f8ef29_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_NDC_Accepted
CREATE VIEW [int].[viewImport_NDC_Accepted] AS
      SELECT I.* from [int].[Import_1552b55e_d263_4431_acfb_f37fd7c9607f_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_NDC_Charge_Code_Accepted
CREATE VIEW [int].[viewImport_NDC_Charge_Code_Accepted] AS
      SELECT I.* from [int].[Import_c9f14a1c_353b_4e81_90f6_944c66ff2da7_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_NDC_Charge_Code_Rejected
CREATE VIEW [int].[viewImport_NDC_Charge_Code_Rejected] AS
      SELECT I.* from [int].[Import_c9f14a1c_353b_4e81_90f6_944c66ff2da7_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_NDC_Rejected
CREATE VIEW [int].[viewImport_NDC_Rejected] AS
      SELECT I.* from [int].[Import_1552b55e_d263_4431_acfb_f37fd7c9607f_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_New_Section_Accepted
CREATE VIEW [int].[viewImport_New_Section_Accepted] AS
      SELECT I.* from [int].[Import_0b5e225a_c041_4c5d_a67d_1bbed0e8ed73_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_New_Section_Rejected
CREATE VIEW [int].[viewImport_New_Section_Rejected] AS
      SELECT I.* from [int].[Import_0b5e225a_c041_4c5d_a67d_1bbed0e8ed73_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Nurse_Station_Accepted
CREATE VIEW [int].[viewImport_Nurse_Station_Accepted] AS
      SELECT I.* from [int].[Import_0af75e75_cbfa_4771_a8e8_19f393d877cd_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Nurse_Station_Rejected
CREATE VIEW [int].[viewImport_Nurse_Station_Rejected] AS
      SELECT I.* from [int].[Import_0af75e75_cbfa_4771_a8e8_19f393d877cd_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_OB_CDM___CDM_Data_Accepted
CREATE VIEW [int].[viewImport_OB_CDM___CDM_Data_Accepted] AS
      SELECT I.* from [int].[Import_16935f62_5386_4e1d_9b11_1d8d0039a787_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_OB_CDM___CDM_Data_Rejected
CREATE VIEW [int].[viewImport_OB_CDM___CDM_Data_Rejected] AS
      SELECT I.* from [int].[Import_16935f62_5386_4e1d_9b11_1d8d0039a787_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_OB_CDM___Charge_Code_Dimension_Accepted
CREATE VIEW [int].[viewImport_OB_CDM___Charge_Code_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_9b8857e0_b5fd_432e_a7ea_eaeabfa03478_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_OB_CDM___Charge_Code_Dimension_Rejected
CREATE VIEW [int].[viewImport_OB_CDM___Charge_Code_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_9b8857e0_b5fd_432e_a7ea_eaeabfa03478_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_OB_CDM___Department_Dimension_Accepted
CREATE VIEW [int].[viewImport_OB_CDM___Department_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_7bce7227_e774_4bc7_9107_ab733ee26967_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_OB_CDM___Department_Dimension_Rejected
CREATE VIEW [int].[viewImport_OB_CDM___Department_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_7bce7227_e774_4bc7_9107_ab733ee26967_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_OB_CDM___Entity_Dimension_Accepted
CREATE VIEW [int].[viewImport_OB_CDM___Entity_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_648411fe_abe7_4f6e_898a_2f17dad277a1_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_OB_CDM___Entity_Dimension_Rejected
CREATE VIEW [int].[viewImport_OB_CDM___Entity_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_648411fe_abe7_4f6e_898a_2f17dad277a1_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_OB_Payor_Group___Payor_Data_Accepted
CREATE VIEW [int].[viewImport_OB_Payor_Group___Payor_Data_Accepted] AS
      SELECT I.* from [int].[Import_64d37379_4a27_4762_a96d_db47c63e074a_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_OB_Payor_Group___Payor_Data_Rejected
CREATE VIEW [int].[viewImport_OB_Payor_Group___Payor_Data_Rejected] AS
      SELECT I.* from [int].[Import_64d37379_4a27_4762_a96d_db47c63e074a_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_OB_Payor___Payor_Data_Accepted
CREATE VIEW [int].[viewImport_OB_Payor___Payor_Data_Accepted] AS
      SELECT I.* from [int].[Import_016181a5_1e9a_4c1e_8876_f0644a86d574_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_OB_Payor___Payor_Data_Rejected
CREATE VIEW [int].[viewImport_OB_Payor___Payor_Data_Rejected] AS
      SELECT I.* from [int].[Import_016181a5_1e9a_4c1e_8876_f0644a86d574_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_OB_Payor___Payor_Dimension_Accepted
CREATE VIEW [int].[viewImport_OB_Payor___Payor_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_c6d5c3a4_e558_490b_bbb5_7378fb1e597e_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_OB_Payor___Payor_Dimension_Rejected
CREATE VIEW [int].[viewImport_OB_Payor___Payor_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_c6d5c3a4_e558_490b_bbb5_7378fb1e597e_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_OB_Provider___Department_Accepted
CREATE VIEW [int].[viewImport_OB_Provider___Department_Accepted] AS
      SELECT I.* from [int].[Import_ffc50184_d407_4e99_80f5_dba396459ac2_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_OB_Provider___Department_Rejected
CREATE VIEW [int].[viewImport_OB_Provider___Department_Rejected] AS
      SELECT I.* from [int].[Import_ffc50184_d407_4e99_80f5_dba396459ac2_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_OB_Provider___Entity_Accepted
CREATE VIEW [int].[viewImport_OB_Provider___Entity_Accepted] AS
      SELECT I.* from [int].[Import_566cab78_e8c0_4586_a6d8_dc0fd4995c08_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_OB_Provider___Entity_Rejected
CREATE VIEW [int].[viewImport_OB_Provider___Entity_Rejected] AS
      SELECT I.* from [int].[Import_566cab78_e8c0_4586_a6d8_dc0fd4995c08_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_OB_Provider___Provider_Accepted
CREATE VIEW [int].[viewImport_OB_Provider___Provider_Accepted] AS
      SELECT I.* from [int].[Import_a78b1a9d_9d2f_4173_acad_d65732645bfc_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_OB_Provider___Provider_Data_Accepted
CREATE VIEW [int].[viewImport_OB_Provider___Provider_Data_Accepted] AS
      SELECT I.* from [int].[Import_10a747b9_9726_4dc4_b1b2_7d79ab4820e3_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_OB_Provider___Provider_Data_Rejected
CREATE VIEW [int].[viewImport_OB_Provider___Provider_Data_Rejected] AS
      SELECT I.* from [int].[Import_10a747b9_9726_4dc4_b1b2_7d79ab4820e3_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_OB_Provider___Provider_Rejected
CREATE VIEW [int].[viewImport_OB_Provider___Provider_Rejected] AS
      SELECT I.* from [int].[Import_a78b1a9d_9d2f_4173_acad_d65732645bfc_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_OB_Service_Line_Data_Accepted
CREATE VIEW [int].[viewImport_OB_Service_Line_Data_Accepted] AS
      SELECT I.* from [int].[Import_aefa0c08_665a_4026_a197_f05b3ed47be8_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_OB_Service_Line_Data_Rejected
CREATE VIEW [int].[viewImport_OB_Service_Line_Data_Rejected] AS
      SELECT I.* from [int].[Import_aefa0c08_665a_4026_a197_f05b3ed47be8_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_PB_Charge_Accepted
CREATE VIEW [int].[viewImport_PB_Charge_Accepted] AS
      SELECT I.* from [int].[Import_23adab15_9aa5_40a8_9244_57af97adc0c9_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_PB_Charge_Rejected
CREATE VIEW [int].[viewImport_PB_Charge_Rejected] AS
      SELECT I.* from [int].[Import_23adab15_9aa5_40a8_9244_57af97adc0c9_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_PB_Department_Def_Accepted
CREATE VIEW [int].[viewImport_PB_Department_Def_Accepted] AS
      SELECT I.* from [int].[Import_3cb89960_cb0c_49c4_b703_ce0bd34a336b_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_PB_Department_Def_Rejected
CREATE VIEW [int].[viewImport_PB_Department_Def_Rejected] AS
      SELECT I.* from [int].[Import_3cb89960_cb0c_49c4_b703_ce0bd34a336b_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_PB_Encounter_Summary_Accepted
CREATE VIEW [int].[viewImport_PB_Encounter_Summary_Accepted] AS
      SELECT I.* from [int].[Import_65b97fac_1748_4519_aac1_b01a30307411_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_PB_Encounter_Summary_Rejected
CREATE VIEW [int].[viewImport_PB_Encounter_Summary_Rejected] AS
      SELECT I.* from [int].[Import_65b97fac_1748_4519_aac1_b01a30307411_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_PB_ICD10_DX_Accepted
CREATE VIEW [int].[viewImport_PB_ICD10_DX_Accepted] AS
      SELECT I.* from [int].[Import_260807f0_9d60_45fd_8637_1fddea525a42_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_PB_ICD10_DX_Rejected
CREATE VIEW [int].[viewImport_PB_ICD10_DX_Rejected] AS
      SELECT I.* from [int].[Import_260807f0_9d60_45fd_8637_1fddea525a42_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_PB_ICD_9_Diagnosis_Accepted
CREATE VIEW [int].[viewImport_PB_ICD_9_Diagnosis_Accepted] AS
      SELECT I.* from [int].[Import_0e183be7_ca58_4b8f_99f4_7c8cf40712be_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_PB_ICD_9_Diagnosis_Rejected
CREATE VIEW [int].[viewImport_PB_ICD_9_Diagnosis_Rejected] AS
      SELECT I.* from [int].[Import_0e183be7_ca58_4b8f_99f4_7c8cf40712be_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_PB_Patient_Accepted
CREATE VIEW [int].[viewImport_PB_Patient_Accepted] AS
      SELECT I.* from [int].[Import_761ba260_dceb_43cd_8c14_3a6bb32b72aa_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_PB_Patient_Encounter_Accepted
CREATE VIEW [int].[viewImport_PB_Patient_Encounter_Accepted] AS
      SELECT I.* from [int].[Import_c4014baa_8c39_488e_aa81_c43adcf97537_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_PB_Patient_Encounter_Rejected
CREATE VIEW [int].[viewImport_PB_Patient_Encounter_Rejected] AS
      SELECT I.* from [int].[Import_c4014baa_8c39_488e_aa81_c43adcf97537_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_PB_Patient_Rejected
CREATE VIEW [int].[viewImport_PB_Patient_Rejected] AS
      SELECT I.* from [int].[Import_761ba260_dceb_43cd_8c14_3a6bb32b72aa_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_PB_Payment_Accepted
CREATE VIEW [int].[viewImport_PB_Payment_Accepted] AS
      SELECT I.* from [int].[Import_80d83f16_0bb5_4a5a_80d7_41bb50a3e541_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_PB_Payment_Rejected
CREATE VIEW [int].[viewImport_PB_Payment_Rejected] AS
      SELECT I.* from [int].[Import_80d83f16_0bb5_4a5a_80d7_41bb50a3e541_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_PO_Accepted
CREATE   VIEW [int].[viewImport_PO_Accepted] AS
                SELECT I.* from [int].[Import_C46AB25F_C509_4D2C_A1A3_E267A37F74A1_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_PO_Detail___Account_Accepted
CREATE VIEW [int].[viewImport_PO_Detail___Account_Accepted] AS
      SELECT I.* from [int].[Import_a77fa9e4_cb34_423f_8d2b_0a2acd5ce480_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_PO_Detail___Account_Rejected
CREATE VIEW [int].[viewImport_PO_Detail___Account_Rejected] AS
      SELECT I.* from [int].[Import_a77fa9e4_cb34_423f_8d2b_0a2acd5ce480_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_PO_Detail___Department_Accepted
CREATE VIEW [int].[viewImport_PO_Detail___Department_Accepted] AS
      SELECT I.* from [int].[Import_98f86655_3c72_43ca_93ca_b8129bd7b892_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_PO_Detail___Department_Rejected
CREATE VIEW [int].[viewImport_PO_Detail___Department_Rejected] AS
      SELECT I.* from [int].[Import_98f86655_3c72_43ca_93ca_b8129bd7b892_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_PO_Detail___Entity_Accepted
CREATE VIEW [int].[viewImport_PO_Detail___Entity_Accepted] AS
      SELECT I.* from [int].[Import_b94afad7_d581_4554_8421_54186a8e57dc_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_PO_Detail___Entity_Rejected
CREATE VIEW [int].[viewImport_PO_Detail___Entity_Rejected] AS
      SELECT I.* from [int].[Import_b94afad7_d581_4554_8421_54186a8e57dc_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_PO_Rejected
CREATE VIEW [int].[viewImport_PO_Rejected] AS
      SELECT I.* from [int].[Import_c46ab25f_c509_4d2c_a1a3_e267a37f74a1_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Patient_Type_Accepted
CREATE VIEW [int].[viewImport_Patient_Type_Accepted] AS
      SELECT I.* from [int].[Import_d8b61020_2515_4740_a887_c4d533b8ebd6_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Patient_Type_Rejected
CREATE VIEW [int].[viewImport_Patient_Type_Rejected] AS
      SELECT I.* from [int].[Import_d8b61020_2515_4740_a887_c4d533b8ebd6_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Pay_Code_Dimension_Accepted
CREATE VIEW [int].[viewImport_Pay_Code_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_f8ddbae5_cf68_45e8_9226_65c77cc598ba_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Pay_Code_Dimension_Rejected
CREATE VIEW [int].[viewImport_Pay_Code_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_f8ddbae5_cf68_45e8_9226_65c77cc598ba_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Payor_Accepted
CREATE VIEW [int].[viewImport_Payor_Accepted] AS
      SELECT I.* from [int].[Import_f5bbaad9_d4db_4e30_bd53_7c750241a0e8_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Payor_Rejected
CREATE VIEW [int].[viewImport_Payor_Rejected] AS
      SELECT I.* from [int].[Import_f5bbaad9_d4db_4e30_bd53_7c750241a0e8_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Physician_Accepted
CREATE VIEW [int].[viewImport_Physician_Accepted] AS
      SELECT I.* from [int].[Import_453ea40e_995c_4ff3_86be_842479076a78_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Physician_Rejected
CREATE VIEW [int].[viewImport_Physician_Rejected] AS
      SELECT I.* from [int].[Import_453ea40e_995c_4ff3_86be_842479076a78_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Physician_Specialty_Accepted
CREATE VIEW [int].[viewImport_Physician_Specialty_Accepted] AS
      SELECT I.* from [int].[Import_88098b84_48f4_4a5f_b82f_ea4488a6f06a_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Physician_Specialty_Rejected
CREATE VIEW [int].[viewImport_Physician_Specialty_Rejected] AS
      SELECT I.* from [int].[Import_88098b84_48f4_4a5f_b82f_ea4488a6f06a_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Physician_Taxonomy_Accepted
CREATE VIEW [int].[viewImport_Physician_Taxonomy_Accepted] AS
      SELECT I.* from [int].[Import_4e10321a_6a92_4c18_8ee2_d6de7db7deb0_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Physician_Taxonomy_Rejected
CREATE VIEW [int].[viewImport_Physician_Taxonomy_Rejected] AS
      SELECT I.* from [int].[Import_4e10321a_6a92_4c18_8ee2_d6de7db7deb0_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Place_of_Service_Accepted
CREATE VIEW [int].[viewImport_Place_of_Service_Accepted] AS
      SELECT I.* from [int].[Import_26fe1011_4e1d_4cc5_a654_0511f30ad101_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Place_of_Service_Rejected
CREATE VIEW [int].[viewImport_Place_of_Service_Rejected] AS
      SELECT I.* from [int].[Import_26fe1011_4e1d_4cc5_a654_0511f30ad101_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Present_on_Admission_Accepted
CREATE VIEW [int].[viewImport_Present_on_Admission_Accepted] AS
      SELECT I.* from [int].[Import_1583023d_2bdb_47fc_a35c_58349fe260b2_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Present_on_Admission_Rejected
CREATE VIEW [int].[viewImport_Present_on_Admission_Rejected] AS
      SELECT I.* from [int].[Import_1583023d_2bdb_47fc_a35c_58349fe260b2_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Race_Accepted
CREATE VIEW [int].[viewImport_Race_Accepted] AS
      SELECT I.* from [int].[Import_8046deb4_8cf5_49a8_8416_bf27e282f4fe_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Race_Rejected
CREATE VIEW [int].[viewImport_Race_Rejected] AS
      SELECT I.* from [int].[Import_8046deb4_8cf5_49a8_8416_bf27e282f4fe_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Religion_Accepted
CREATE VIEW [int].[viewImport_Religion_Accepted] AS
      SELECT I.* from [int].[Import_48875bd8_0911_4801_8a7b_20863c859544_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Religion_Rejected
CREATE VIEW [int].[viewImport_Religion_Rejected] AS
      SELECT I.* from [int].[Import_48875bd8_0911_4801_8a7b_20863c859544_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading_Combined___Physician___Ops_Accepted
CREATE VIEW [int].[viewImport_SP_Direct_Loading_Combined___Physician___Ops_Accepted] AS
      SELECT I.* from [int].[Import_45bed270_56ba_4b59_ab31_d6055563f64f_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading_Combined___Physician___Ops_Rejected
CREATE VIEW [int].[viewImport_SP_Direct_Loading_Combined___Physician___Ops_Rejected] AS
      SELECT I.* from [int].[Import_45bed270_56ba_4b59_ab31_d6055563f64f_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading_Combined___Physician___RF_Accepted
CREATE VIEW [int].[viewImport_SP_Direct_Loading_Combined___Physician___RF_Accepted] AS
      SELECT I.* from [int].[Import_4789e844_91e6_429a_a09a_29d12bc2685d_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading_Combined___Physician___RF_Rejected
CREATE VIEW [int].[viewImport_SP_Direct_Loading_Combined___Physician___RF_Rejected] AS
      SELECT I.* from [int].[Import_4789e844_91e6_429a_a09a_29d12bc2685d_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___Bal_Account_Accepted
CREATE VIEW [int].[viewImport_SP_Direct_Loading___Bal_Account_Accepted] AS
      SELECT I.* from [int].[Import_72b01d2b_e4b9_4dc6_879c_e55104013e39_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___Bal_Account_Rejected
CREATE VIEW [int].[viewImport_SP_Direct_Loading___Bal_Account_Rejected] AS
      SELECT I.* from [int].[Import_72b01d2b_e4b9_4dc6_879c_e55104013e39_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___Combined_Payor___Ops_Accepted
CREATE VIEW [int].[viewImport_SP_Direct_Loading___Combined_Payor___Ops_Accepted] AS
      SELECT I.* from [int].[Import_a1551fab_31f9_450a_aa0b_d0a0b56a06f0_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___Combined_Payor___Ops_Rejected
CREATE VIEW [int].[viewImport_SP_Direct_Loading___Combined_Payor___Ops_Rejected] AS
      SELECT I.* from [int].[Import_a1551fab_31f9_450a_aa0b_d0a0b56a06f0_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___Combined_Payor___RF_Accepted
CREATE VIEW [int].[viewImport_SP_Direct_Loading___Combined_Payor___RF_Accepted] AS
      SELECT I.* from [int].[Import_598947bd_4660_4196_b08d_22860f7e753b_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___Combined_Payor___RF_Rejected
CREATE VIEW [int].[viewImport_SP_Direct_Loading___Combined_Payor___RF_Rejected] AS
      SELECT I.* from [int].[Import_598947bd_4660_4196_b08d_22860f7e753b_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___Combined_Staffing___Ops_Accepted
CREATE VIEW [int].[viewImport_SP_Direct_Loading___Combined_Staffing___Ops_Accepted] AS
      SELECT I.* from [int].[Import_d6265927_6239_4f63_95cc_ff7e37890e2d_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___Combined_Staffing___Ops_Rejected
CREATE VIEW [int].[viewImport_SP_Direct_Loading___Combined_Staffing___Ops_Rejected] AS
      SELECT I.* from [int].[Import_d6265927_6239_4f63_95cc_ff7e37890e2d_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___Combined_Staffing___RF_Accepted
CREATE VIEW [int].[viewImport_SP_Direct_Loading___Combined_Staffing___RF_Accepted] AS
      SELECT I.* from [int].[Import_b4074250_5ad3_41b3_a57d_778aa994f7ba_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___Combined_Staffing___RF_Rejected
CREATE VIEW [int].[viewImport_SP_Direct_Loading___Combined_Staffing___RF_Rejected] AS
      SELECT I.* from [int].[Import_b4074250_5ad3_41b3_a57d_778aa994f7ba_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___IS_Account_Accepted
CREATE VIEW [int].[viewImport_SP_Direct_Loading___IS_Account_Accepted] AS
      SELECT I.* from [int].[Import_27e99a35_500b_4ed0_9338_11f85c014142_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___IS_Account_Rejected
CREATE VIEW [int].[viewImport_SP_Direct_Loading___IS_Account_Rejected] AS
      SELECT I.* from [int].[Import_27e99a35_500b_4ed0_9338_11f85c014142_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___IS_Payor_Accepted
CREATE VIEW [int].[viewImport_SP_Direct_Loading___IS_Payor_Accepted] AS
      SELECT I.* from [int].[Import_2ecebb10_f896_468f_b907_840682d7b42d_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___IS_Payor_Rejected
CREATE VIEW [int].[viewImport_SP_Direct_Loading___IS_Payor_Rejected] AS
      SELECT I.* from [int].[Import_2ecebb10_f896_468f_b907_840682d7b42d_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___IS_Physician_Accepted
CREATE VIEW [int].[viewImport_SP_Direct_Loading___IS_Physician_Accepted] AS
      SELECT I.* from [int].[Import_885c8237_bb58_44cd_830f_0c86d7ef73d8_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___IS_Physician_Rejected
CREATE VIEW [int].[viewImport_SP_Direct_Loading___IS_Physician_Rejected] AS
      SELECT I.* from [int].[Import_885c8237_bb58_44cd_830f_0c86d7ef73d8_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___IS_Staffing_Accepted
CREATE VIEW [int].[viewImport_SP_Direct_Loading___IS_Staffing_Accepted] AS
      SELECT I.* from [int].[Import_6404089e_bb14_49ca_93df_64f21361602d_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___IS_Staffing_Rejected
CREATE VIEW [int].[viewImport_SP_Direct_Loading___IS_Staffing_Rejected] AS
      SELECT I.* from [int].[Import_6404089e_bb14_49ca_93df_64f21361602d_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___Rolling_IS_Account_Accepted
CREATE VIEW [int].[viewImport_SP_Direct_Loading___Rolling_IS_Account_Accepted] AS
      SELECT I.* from [int].[Import_a0b47498_722d_46c3_8c92_025f3238aefb_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___Rolling_IS_Account_Rejected
CREATE VIEW [int].[viewImport_SP_Direct_Loading___Rolling_IS_Account_Rejected] AS
      SELECT I.* from [int].[Import_a0b47498_722d_46c3_8c92_025f3238aefb_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___Rolling_IS_Payor_Accepted
CREATE VIEW [int].[viewImport_SP_Direct_Loading___Rolling_IS_Payor_Accepted] AS
      SELECT I.* from [int].[Import_690d6e05_8bb8_40b3_967b_5b2562dc74a5_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___Rolling_IS_Payor_Rejected
CREATE VIEW [int].[viewImport_SP_Direct_Loading___Rolling_IS_Payor_Rejected] AS
      SELECT I.* from [int].[Import_690d6e05_8bb8_40b3_967b_5b2562dc74a5_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___Rolling_IS_Physician_Accepted
CREATE VIEW [int].[viewImport_SP_Direct_Loading___Rolling_IS_Physician_Accepted] AS
      SELECT I.* from [int].[Import_c0602559_270a_4ad0_865e_de5ca87fb775_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___Rolling_IS_Physician_Rejected
CREATE VIEW [int].[viewImport_SP_Direct_Loading___Rolling_IS_Physician_Rejected] AS
      SELECT I.* from [int].[Import_c0602559_270a_4ad0_865e_de5ca87fb775_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___Rolling_IS_Staffing_Accepted
CREATE VIEW [int].[viewImport_SP_Direct_Loading___Rolling_IS_Staffing_Accepted] AS
      SELECT I.* from [int].[Import_89d2131c_400c_4336_b7ce_9d8c6ea97469_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Direct_Loading___Rolling_IS_Staffing_Rejected
CREATE VIEW [int].[viewImport_SP_Direct_Loading___Rolling_IS_Staffing_Rejected] AS
      SELECT I.* from [int].[Import_89d2131c_400c_4336_b7ce_9d8c6ea97469_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Payor_Combined_Allocation_Percentage___Ops_Accepted
CREATE VIEW [int].[viewImport_SP_Payor_Combined_Allocation_Percentage___Ops_Accepted] AS
      SELECT I.* from [int].[Import_555f13b5_ff0f_4b0d_98e2_a7a7db130aed_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Payor_Combined_Allocation_Percentage___Ops_Rejected
CREATE VIEW [int].[viewImport_SP_Payor_Combined_Allocation_Percentage___Ops_Rejected] AS
      SELECT I.* from [int].[Import_555f13b5_ff0f_4b0d_98e2_a7a7db130aed_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Payor_Combined_Allocation_Percentage___RF_Accepted
CREATE VIEW [int].[viewImport_SP_Payor_Combined_Allocation_Percentage___RF_Accepted] AS
      SELECT I.* from [int].[Import_caa46bcd_8369_4856_ab80_3948a4c02bac_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Payor_Combined_Allocation_Percentage___RF_Rejected
CREATE VIEW [int].[viewImport_SP_Payor_Combined_Allocation_Percentage___RF_Rejected] AS
      SELECT I.* from [int].[Import_caa46bcd_8369_4856_ab80_3948a4c02bac_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Payor_Operations_Allocation_Percentage_Accepted
CREATE VIEW [int].[viewImport_SP_Payor_Operations_Allocation_Percentage_Accepted] AS
      SELECT I.* from [int].[Import_1c6714b7_8f01_42ed_98a2_56e342ebbaea_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Payor_Operations_Allocation_Percentage_Rejected
CREATE VIEW [int].[viewImport_SP_Payor_Operations_Allocation_Percentage_Rejected] AS
      SELECT I.* from [int].[Import_1c6714b7_8f01_42ed_98a2_56e342ebbaea_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Payor_Rolling_Forecast_Allocation_Percentage_Accepted
CREATE VIEW [int].[viewImport_SP_Payor_Rolling_Forecast_Allocation_Percentage_Accepted] AS
      SELECT I.* from [int].[Import_383266e2_8965_427d_93d5_d60522fe8824_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Payor_Rolling_Forecast_Allocation_Percentage_Rejected
CREATE VIEW [int].[viewImport_SP_Payor_Rolling_Forecast_Allocation_Percentage_Rejected] AS
      SELECT I.* from [int].[Import_383266e2_8965_427d_93d5_d60522fe8824_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Payor_Summary_Accepted
CREATE VIEW [int].[viewImport_SP_Payor_Summary_Accepted] AS
      SELECT I.* from [int].[Import_6ae98a0d_7667_4d23_81c8_287a7c8ff9f3_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Payor_Summary_Rejected
CREATE VIEW [int].[viewImport_SP_Payor_Summary_Rejected] AS
      SELECT I.* from [int].[Import_6ae98a0d_7667_4d23_81c8_287a7c8ff9f3_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Physician_Combined_Allocation_Percentage___Ops_Accepted
CREATE VIEW [int].[viewImport_SP_Physician_Combined_Allocation_Percentage___Ops_Accepted] AS
      SELECT I.* from [int].[Import_2774d4ad_b858_47a2_b5e4_3375bd73d29d_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Physician_Combined_Allocation_Percentage___Ops_Rejected
CREATE VIEW [int].[viewImport_SP_Physician_Combined_Allocation_Percentage___Ops_Rejected] AS
      SELECT I.* from [int].[Import_2774d4ad_b858_47a2_b5e4_3375bd73d29d_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Physician_Combined_Allocation_Percentage___RF_Accepted
CREATE VIEW [int].[viewImport_SP_Physician_Combined_Allocation_Percentage___RF_Accepted] AS
      SELECT I.* from [int].[Import_ecb4800d_2106_4948_a4f7_c42b71f987a7_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Physician_Combined_Allocation_Percentage___RF_Rejected
CREATE VIEW [int].[viewImport_SP_Physician_Combined_Allocation_Percentage___RF_Rejected] AS
      SELECT I.* from [int].[Import_ecb4800d_2106_4948_a4f7_c42b71f987a7_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Physician_Operations_Allocation_Percentage_Accepted
CREATE VIEW [int].[viewImport_SP_Physician_Operations_Allocation_Percentage_Accepted] AS
      SELECT I.* from [int].[Import_25a6fbdd_672f_4b40_ae14_fc196f71a4dd_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Physician_Operations_Allocation_Percentage_Rejected
CREATE VIEW [int].[viewImport_SP_Physician_Operations_Allocation_Percentage_Rejected] AS
      SELECT I.* from [int].[Import_25a6fbdd_672f_4b40_ae14_fc196f71a4dd_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Physician_Rolling_Forecast_Allocation_Percentage_Accepted
CREATE VIEW [int].[viewImport_SP_Physician_Rolling_Forecast_Allocation_Percentage_Accepted] AS
      SELECT I.* from [int].[Import_0bc9c76c_e4f3_488a_9851_394b07eed375_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Physician_Rolling_Forecast_Allocation_Percentage_Rejected
CREATE VIEW [int].[viewImport_SP_Physician_Rolling_Forecast_Allocation_Percentage_Rejected] AS
      SELECT I.* from [int].[Import_0bc9c76c_e4f3_488a_9851_394b07eed375_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Physician_Summary_Accepted
CREATE VIEW [int].[viewImport_SP_Physician_Summary_Accepted] AS
      SELECT I.* from [int].[Import_04a46abd_cbaf_4a20_8d76_4e114d74c289_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Physician_Summary_Rejected
CREATE VIEW [int].[viewImport_SP_Physician_Summary_Rejected] AS
      SELECT I.* from [int].[Import_04a46abd_cbaf_4a20_8d76_4e114d74c289_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Staffing_Combined_Allocation_Percentage___Ops_Accepted
CREATE VIEW [int].[viewImport_SP_Staffing_Combined_Allocation_Percentage___Ops_Accepted] AS
      SELECT I.* from [int].[Import_f60feba4_4bfe_447b_a7f7_befd007ffcd1_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Staffing_Combined_Allocation_Percentage___Ops_Rejected
CREATE VIEW [int].[viewImport_SP_Staffing_Combined_Allocation_Percentage___Ops_Rejected] AS
      SELECT I.* from [int].[Import_f60feba4_4bfe_447b_a7f7_befd007ffcd1_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Staffing_Combined_Allocation_Percentage___RF_Accepted
CREATE VIEW [int].[viewImport_SP_Staffing_Combined_Allocation_Percentage___RF_Accepted] AS
      SELECT I.* from [int].[Import_fee9ab0a_eac6_4485_a270_15d465bf368d_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Staffing_Combined_Allocation_Percentage___RF_Rejected
CREATE VIEW [int].[viewImport_SP_Staffing_Combined_Allocation_Percentage___RF_Rejected] AS
      SELECT I.* from [int].[Import_fee9ab0a_eac6_4485_a270_15d465bf368d_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Staffing_Operations_Allocation_Percentage_Accepted
CREATE VIEW [int].[viewImport_SP_Staffing_Operations_Allocation_Percentage_Accepted] AS
      SELECT I.* from [int].[Import_29b44bab_4abe_43ae_acd4_3bb99d5dcb53_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Staffing_Operations_Allocation_Percentage_Rejected
CREATE VIEW [int].[viewImport_SP_Staffing_Operations_Allocation_Percentage_Rejected] AS
      SELECT I.* from [int].[Import_29b44bab_4abe_43ae_acd4_3bb99d5dcb53_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Staffing_Rolling_Forecast_Allocation_Percentage_Accepted
CREATE VIEW [int].[viewImport_SP_Staffing_Rolling_Forecast_Allocation_Percentage_Accepted] AS
      SELECT I.* from [int].[Import_2f7492bb_480f_4658_a865_b204ce4a7c93_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Staffing_Rolling_Forecast_Allocation_Percentage_Rejected
CREATE VIEW [int].[viewImport_SP_Staffing_Rolling_Forecast_Allocation_Percentage_Rejected] AS
      SELECT I.* from [int].[Import_2f7492bb_480f_4658_a865_b204ce4a7c93_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SP_Staffing_Summary_Accepted
CREATE VIEW [int].[viewImport_SP_Staffing_Summary_Accepted] AS
      SELECT I.* from [int].[Import_730932c6_0239_46c2_a5c0_8ed31dde8ad5_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SP_Staffing_Summary_Rejected
CREATE VIEW [int].[viewImport_SP_Staffing_Summary_Rejected] AS
      SELECT I.* from [int].[Import_730932c6_0239_46c2_a5c0_8ed31dde8ad5_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_SUP_Charge_Code_Accepted
CREATE VIEW [int].[viewImport_SUP_Charge_Code_Accepted] AS
      SELECT I.* from [int].[Import_5e2e18da_ff3c_40ab_b713_fa393f0bb3cd_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_SUP_Charge_Code_Rejected
CREATE VIEW [int].[viewImport_SUP_Charge_Code_Rejected] AS
      SELECT I.* from [int].[Import_5e2e18da_ff3c_40ab_b713_fa393f0bb3cd_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Service_Accepted
CREATE VIEW [int].[viewImport_Service_Accepted] AS
      SELECT I.* from [int].[Import_f94bf095_39cf_4c18_9c1f_80dd4476ec91_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Service_Line_Revenue_Accepted
CREATE VIEW [int].[viewImport_Service_Line_Revenue_Accepted] AS
      SELECT I.* from [int].[Import_38e60101_6e90_4e2a_bcbf_77c84a1e9d04_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Service_Line_Revenue_Rejected
CREATE VIEW [int].[viewImport_Service_Line_Revenue_Rejected] AS
      SELECT I.* from [int].[Import_38e60101_6e90_4e2a_bcbf_77c84a1e9d04_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Service_Rejected
CREATE VIEW [int].[viewImport_Service_Rejected] AS
      SELECT I.* from [int].[Import_f94bf095_39cf_4c18_9c1f_80dd4476ec91_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Shared___General_Ledger_Accepted
CREATE VIEW [int].[viewImport_Shared___General_Ledger_Accepted] AS
      SELECT I.* from [int].[Import_56db8dc7_31ee_4f79_a683_2e7bf0ab0d2b_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Shared___General_Ledger_Rejected
CREATE VIEW [int].[viewImport_Shared___General_Ledger_Rejected] AS
      SELECT I.* from [int].[Import_56db8dc7_31ee_4f79_a683_2e7bf0ab0d2b_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Shared___Global_Statistics_Accepted
CREATE VIEW [int].[viewImport_Shared___Global_Statistics_Accepted] AS
      SELECT I.* from [int].[Import_e623e263_bf35_4c9c_b256_510a766b8242_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Shared___Global_Statistics_Rejected
CREATE VIEW [int].[viewImport_Shared___Global_Statistics_Rejected] AS
      SELECT I.* from [int].[Import_e623e263_bf35_4c9c_b256_510a766b8242_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Shared___Import___AP_Detail_Accepted
CREATE VIEW [int].[viewImport_Shared___Import___AP_Detail_Accepted] AS
      SELECT I.* from [int].[Import_d5750d90_0ee2_443e_8a88_2f7370eee0ac_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Shared___Import___AP_Detail_Rejected
CREATE VIEW [int].[viewImport_Shared___Import___AP_Detail_Rejected] AS
      SELECT I.* from [int].[Import_d5750d90_0ee2_443e_8a88_2f7370eee0ac_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Shared___Import___Daily_Statistics_Accepted
CREATE VIEW [int].[viewImport_Shared___Import___Daily_Statistics_Accepted] AS
      SELECT I.* from [int].[Import_2ba30098_5a69_497b_a768_46a2a1c11e35_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Shared___Import___Daily_Statistics_Rejected
CREATE VIEW [int].[viewImport_Shared___Import___Daily_Statistics_Rejected] AS
      SELECT I.* from [int].[Import_2ba30098_5a69_497b_a768_46a2a1c11e35_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Shared___Import___GL_Detail_Accepted
CREATE VIEW [int].[viewImport_Shared___Import___GL_Detail_Accepted] AS
      SELECT I.* from [int].[Import_e2d145bc_120b_4d00_b59b_07de233aaedf_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Shared___Import___GL_Detail_Rejected
CREATE VIEW [int].[viewImport_Shared___Import___GL_Detail_Rejected] AS
      SELECT I.* from [int].[Import_e2d145bc_120b_4d00_b59b_07de233aaedf_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Shared___Import___Staffing_Daily_Accepted
CREATE VIEW [int].[viewImport_Shared___Import___Staffing_Daily_Accepted] AS
      SELECT I.* from [int].[Import_4f5655bc_33bc_452e_9da0_7326c2ba0363_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Shared___Import___Staffing_Daily_Rejected
CREATE VIEW [int].[viewImport_Shared___Import___Staffing_Daily_Rejected] AS
      SELECT I.* from [int].[Import_4f5655bc_33bc_452e_9da0_7326c2ba0363_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Shared___Service_Line_Import_Accepted
CREATE VIEW [int].[viewImport_Shared___Service_Line_Import_Accepted] AS
      SELECT I.* from [int].[Import_8d2bd278_6c37_427d_9cd1_b27e71341636_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Shared___Service_Line_Import_Rejected
CREATE VIEW [int].[viewImport_Shared___Service_Line_Import_Rejected] AS
      SELECT I.* from [int].[Import_8d2bd278_6c37_427d_9cd1_b27e71341636_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Shared___Staffing_Accepted
CREATE VIEW [int].[viewImport_Shared___Staffing_Accepted] AS
      SELECT I.* from [int].[Import_e1a1a312_32e8_4ee8_805f_61455f171001_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Shared___Staffing_By_Pay_Period_Accepted
CREATE VIEW [int].[viewImport_Shared___Staffing_By_Pay_Period_Accepted] AS
      SELECT I.* from [int].[Import_cdc2ef8b_987e_4ca6_a06c_22827507f5f5_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Shared___Staffing_By_Pay_Period_Rejected
CREATE VIEW [int].[viewImport_Shared___Staffing_By_Pay_Period_Rejected] AS
      SELECT I.* from [int].[Import_cdc2ef8b_987e_4ca6_a06c_22827507f5f5_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Shared___Staffing_Rejected
CREATE VIEW [int].[viewImport_Shared___Staffing_Rejected] AS
      SELECT I.* from [int].[Import_e1a1a312_32e8_4ee8_805f_61455f171001_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Shared___Statistics_Accepted
CREATE VIEW [int].[viewImport_Shared___Statistics_Accepted] AS
      SELECT I.* from [int].[Import_8a1ed204_bccc_4da6_b74e_20c0629b6431_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Shared___Statistics_Rejected
CREATE VIEW [int].[viewImport_Shared___Statistics_Rejected] AS
      SELECT I.* from [int].[Import_8a1ed204_bccc_4da6_b74e_20c0629b6431_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Staffign_by_Pay_Period___Department_Dimension_Accepted
CREATE VIEW [int].[viewImport_Staffign_by_Pay_Period___Department_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_f4e4f855_b91e_4c8c_a621_20ff76e3832b_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Staffign_by_Pay_Period___Department_Dimension_Rejected
CREATE VIEW [int].[viewImport_Staffign_by_Pay_Period___Department_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_f4e4f855_b91e_4c8c_a621_20ff76e3832b_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_Daily___Department_Accepted
CREATE VIEW [int].[viewImport_Staffing_Daily___Department_Accepted] AS
      SELECT I.* from [int].[Import_5a639f91_3e82_4bf6_94ce_aa2b17c1fa80_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_Daily___Department_Rejected
CREATE VIEW [int].[viewImport_Staffing_Daily___Department_Rejected] AS
      SELECT I.* from [int].[Import_5a639f91_3e82_4bf6_94ce_aa2b17c1fa80_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_Daily___Employee_Accepted
CREATE VIEW [int].[viewImport_Staffing_Daily___Employee_Accepted] AS
      SELECT I.* from [int].[Import_82f72e8d_78a5_4258_ac8a_05e331e2dffc_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_Daily___Employee_Rejected
CREATE VIEW [int].[viewImport_Staffing_Daily___Employee_Rejected] AS
      SELECT I.* from [int].[Import_82f72e8d_78a5_4258_ac8a_05e331e2dffc_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_Daily___Entity_Accepted
CREATE VIEW [int].[viewImport_Staffing_Daily___Entity_Accepted] AS
      SELECT I.* from [int].[Import_46f14f26_5df7_4519_8bdd_1a840936f00c_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_Daily___Entity_Rejected
CREATE VIEW [int].[viewImport_Staffing_Daily___Entity_Rejected] AS
      SELECT I.* from [int].[Import_46f14f26_5df7_4519_8bdd_1a840936f00c_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_Daily___Job_Code_Accepted
CREATE VIEW [int].[viewImport_Staffing_Daily___Job_Code_Accepted] AS
      SELECT I.* from [int].[Import_60cab422_84e9_490c_a37d_ba6955b2a6da_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_Daily___Job_Code_Rejected
CREATE VIEW [int].[viewImport_Staffing_Daily___Job_Code_Rejected] AS
      SELECT I.* from [int].[Import_60cab422_84e9_490c_a37d_ba6955b2a6da_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_Daily___Pay_Code_Accepted
CREATE VIEW [int].[viewImport_Staffing_Daily___Pay_Code_Accepted] AS
      SELECT I.* from [int].[Import_86796983_c8ab_4853_b417_1e116953658c_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_Daily___Pay_Code_Rejected
CREATE VIEW [int].[viewImport_Staffing_Daily___Pay_Code_Rejected] AS
      SELECT I.* from [int].[Import_86796983_c8ab_4853_b417_1e116953658c_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_Detail_Accepted
CREATE VIEW [int].[viewImport_Staffing_Detail_Accepted] AS
      SELECT I.* from [int].[Import_1cd9dc31_e651_46e0_8b9a_d7385891ae95_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_Detail_Rejected
CREATE VIEW [int].[viewImport_Staffing_Detail_Rejected] AS
      SELECT I.* from [int].[Import_1cd9dc31_e651_46e0_8b9a_d7385891ae95_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Staffing___Department_Dimension_Accepted
CREATE VIEW [int].[viewImport_Staffing___Department_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_5050eb0a_6146_4c2c_bef5_830e860d3f68_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Staffing___Department_Dimension_Rejected
CREATE VIEW [int].[viewImport_Staffing___Department_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_5050eb0a_6146_4c2c_bef5_830e860d3f68_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Staffing___Employee_Dimension_Accepted
CREATE VIEW [int].[viewImport_Staffing___Employee_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_5990705e_57d6_41a6_b97b_07f5cc5a67df_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Staffing___Employee_Dimension_Rejected
CREATE VIEW [int].[viewImport_Staffing___Employee_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_5990705e_57d6_41a6_b97b_07f5cc5a67df_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Staffing___Entity_Dimension_Accepted
CREATE VIEW [int].[viewImport_Staffing___Entity_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_fcc81949_ca89_4ab8_82ec_d00583464125_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Staffing___Entity_Dimension_Rejected
CREATE VIEW [int].[viewImport_Staffing___Entity_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_fcc81949_ca89_4ab8_82ec_d00583464125_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Staffing___Job_Code_Dimension_Accepted
CREATE VIEW [int].[viewImport_Staffing___Job_Code_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_6e8d8449_137c_4c04_9533_53cbed43e341_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Staffing___Job_Code_Dimension_Rejected
CREATE VIEW [int].[viewImport_Staffing___Job_Code_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_6e8d8449_137c_4c04_9533_53cbed43e341_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Staffing___Pay_Code_Accepted
CREATE VIEW [int].[viewImport_Staffing___Pay_Code_Accepted] AS
      SELECT I.* from [int].[Import_35413d7f_3756_43b3_ad3a_54f12ba46ebc_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Staffing___Pay_Code_Rejected
CREATE VIEW [int].[viewImport_Staffing___Pay_Code_Rejected] AS
      SELECT I.* from [int].[Import_35413d7f_3756_43b3_ad3a_54f12ba46ebc_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_by_Pay_Period___Department_Dimension_Accepted
CREATE VIEW [int].[viewImport_Staffing_by_Pay_Period___Department_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_f4e4f855_b91e_4c8c_a621_20ff76e3832b_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_by_Pay_Period___Department_Dimension_Rejected
CREATE VIEW [int].[viewImport_Staffing_by_Pay_Period___Department_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_f4e4f855_b91e_4c8c_a621_20ff76e3832b_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_by_Pay_Period___Employee_Accepted
CREATE VIEW [int].[viewImport_Staffing_by_Pay_Period___Employee_Accepted] AS
      SELECT I.* from [int].[Import_9edb7cd7_f8cd_4dda_9eb4_0fb4b8f1de81_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_by_Pay_Period___Employee_Rejected
CREATE VIEW [int].[viewImport_Staffing_by_Pay_Period___Employee_Rejected] AS
      SELECT I.* from [int].[Import_9edb7cd7_f8cd_4dda_9eb4_0fb4b8f1de81_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_by_Pay_Period___Entity_Dimension_Accepted
CREATE VIEW [int].[viewImport_Staffing_by_Pay_Period___Entity_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_dee10748_f674_489d_8fa7_cf4a10da6a99_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_by_Pay_Period___Entity_Dimension_Rejected
CREATE VIEW [int].[viewImport_Staffing_by_Pay_Period___Entity_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_dee10748_f674_489d_8fa7_cf4a10da6a99_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_by_Pay_Period___Job_Code_Dimension_Accepted
CREATE VIEW [int].[viewImport_Staffing_by_Pay_Period___Job_Code_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_6ab7765c_8474_4b9a_b759_5b207f118a0e_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_by_Pay_Period___Job_Code_Dimension_Rejected
CREATE VIEW [int].[viewImport_Staffing_by_Pay_Period___Job_Code_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_6ab7765c_8474_4b9a_b759_5b207f118a0e_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_by_Pay_Period___Pay_Code_Dimension_Accepted
CREATE VIEW [int].[viewImport_Staffing_by_Pay_Period___Pay_Code_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_a67d8f1c_36c2_4d13_b6e1_3dae138bdff7_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Staffing_by_Pay_Period___Pay_Code_Dimension_Rejected
CREATE VIEW [int].[viewImport_Staffing_by_Pay_Period___Pay_Code_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_a67d8f1c_36c2_4d13_b6e1_3dae138bdff7_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Star_Patient_ADT_Accepted
CREATE VIEW [int].[viewImport_Star_Patient_ADT_Accepted] AS
      SELECT I.* from [int].[Import_a3b197db_0e91_4efd_acec_cc071e9345dc_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Star_Patient_ADT_Rejected
CREATE VIEW [int].[viewImport_Star_Patient_ADT_Rejected] AS
      SELECT I.* from [int].[Import_a3b197db_0e91_4efd_acec_cc071e9345dc_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Statistics_by_Pay_Period_Accepted
CREATE VIEW [int].[viewImport_Statistics_by_Pay_Period_Accepted] AS
      SELECT I.* from [int].[Import_b1bf2582_5ddb_4a43_9dce_7c8b41aca4ba_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Statistics_by_Pay_Period_Rejected
CREATE VIEW [int].[viewImport_Statistics_by_Pay_Period_Rejected] AS
      SELECT I.* from [int].[Import_b1bf2582_5ddb_4a43_9dce_7c8b41aca4ba_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Stats_by_Period___Account_Dimension_Accepted
CREATE VIEW [int].[viewImport_Stats_by_Period___Account_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_98292ff4_b580_4db7_9f43_7e15e07421a1_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Stats_by_Period___Account_Dimension_Rejected
CREATE VIEW [int].[viewImport_Stats_by_Period___Account_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_98292ff4_b580_4db7_9f43_7e15e07421a1_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Stats_by_Period___Department_Dimension_Accepted
CREATE VIEW [int].[viewImport_Stats_by_Period___Department_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_0ee07141_3103_4c56_bec3_2d1157da2ce6_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Stats_by_Period___Department_Dimension_Rejected
CREATE VIEW [int].[viewImport_Stats_by_Period___Department_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_0ee07141_3103_4c56_bec3_2d1157da2ce6_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Stats_by_Period___Entity_Dimension_Accepted
CREATE VIEW [int].[viewImport_Stats_by_Period___Entity_Dimension_Accepted] AS
      SELECT I.* from [int].[Import_48b416a8_1b74_4343_803f_cd9f8a8d7c96_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Stats_by_Period___Entity_Dimension_Rejected
CREATE VIEW [int].[viewImport_Stats_by_Period___Entity_Dimension_Rejected] AS
      SELECT I.* from [int].[Import_48b416a8_1b74_4343_803f_cd9f8a8d7c96_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Subscriber_Relationship_Accepted
CREATE VIEW [int].[viewImport_Subscriber_Relationship_Accepted] AS
      SELECT I.* from [int].[Import_4a0480e2_2ae1_49c5_ad13_276303db067b_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Subscriber_Relationship_Rejected
CREATE VIEW [int].[viewImport_Subscriber_Relationship_Rejected] AS
      SELECT I.* from [int].[Import_4a0480e2_2ae1_49c5_ad13_276303db067b_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Supply_Accepted
CREATE VIEW [int].[viewImport_Supply_Accepted] AS
      SELECT I.* from [int].[Import_a6dc4c39_f907_4301_8776_7f7b78deef0e_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Supply_Rejected
CREATE VIEW [int].[viewImport_Supply_Rejected] AS
      SELECT I.* from [int].[Import_a6dc4c39_f907_4301_8776_7f7b78deef0e_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Surgical_Detail_Accepted
CREATE VIEW [int].[viewImport_Surgical_Detail_Accepted] AS
      SELECT I.* from [int].[Import_cf70c229_e22b_4e09_b64d_e609c358d4f0_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Surgical_Detail_Rejected
CREATE VIEW [int].[viewImport_Surgical_Detail_Rejected] AS
      SELECT I.* from [int].[Import_cf70c229_e22b_4e09_b64d_e609c358d4f0_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Surgical_Staff_Accepted
CREATE VIEW [int].[viewImport_Surgical_Staff_Accepted] AS
      SELECT I.* from [int].[Import_eef1997c_a3c0_4af9_a779_74ce72717249_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Surgical_Staff_Rejected
CREATE VIEW [int].[viewImport_Surgical_Staff_Rejected] AS
      SELECT I.* from [int].[Import_eef1997c_a3c0_4af9_a779_74ce72717249_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Surgical_Staff_Type_Accepted
CREATE VIEW [int].[viewImport_Surgical_Staff_Type_Accepted] AS
      SELECT I.* from [int].[Import_c493d8f4_6da4_4488_9ae9_3b5a4791d92a_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Surgical_Staff_Type_Category_Accepted
CREATE VIEW [int].[viewImport_Surgical_Staff_Type_Category_Accepted] AS
      SELECT I.* from [int].[Import_26138873_9e4b_4298_8eb5_66ac7dfab5c5_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Surgical_Staff_Type_Category_Rejected
CREATE VIEW [int].[viewImport_Surgical_Staff_Type_Category_Rejected] AS
      SELECT I.* from [int].[Import_26138873_9e4b_4298_8eb5_66ac7dfab5c5_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Surgical_Staff_Type_Rejected
CREATE VIEW [int].[viewImport_Surgical_Staff_Type_Rejected] AS
      SELECT I.* from [int].[Import_c493d8f4_6da4_4488_9ae9_3b5a4791d92a_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Swipe_Data_Import_Accepted
CREATE VIEW [int].[viewImport_Swipe_Data_Import_Accepted] AS
      SELECT I.* from [int].[Import_f04709bb_195b_4bba_8945_5e260800a269_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Swipe_Data_Import_Rejected
CREATE VIEW [int].[viewImport_Swipe_Data_Import_Rejected] AS
      SELECT I.* from [int].[Import_f04709bb_195b_4bba_8945_5e260800a269_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Transaction_Code_Accepted
CREATE VIEW [int].[viewImport_Transaction_Code_Accepted] AS
      SELECT I.* from [int].[Import_ceb9826b_aa15_465f_ab19_1d34ffa6f1c6_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Transaction_Code_Rejected
CREATE VIEW [int].[viewImport_Transaction_Code_Rejected] AS
      SELECT I.* from [int].[Import_ceb9826b_aa15_465f_ab19_1d34ffa6f1c6_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Transaction_Source_Accepted
CREATE VIEW [int].[viewImport_Transaction_Source_Accepted] AS
      SELECT I.* from [int].[Import_fd1dbdb7_48c2_46fd_a0e0_fc5ebc7d8f56_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Transaction_Source_Rejected
CREATE VIEW [int].[viewImport_Transaction_Source_Rejected] AS
      SELECT I.* from [int].[Import_fd1dbdb7_48c2_46fd_a0e0_fc5ebc7d8f56_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_UB_Revenue_Code_Accepted
CREATE VIEW [int].[viewImport_UB_Revenue_Code_Accepted] AS
      SELECT I.* from [int].[Import_2ea260c3_2e2d_4e1d_9271_f09ecd89bdbf_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_UB_Revenue_Code_Rejected
CREATE VIEW [int].[viewImport_UB_Revenue_Code_Rejected] AS
      SELECT I.* from [int].[Import_2ea260c3_2e2d_4e1d_9271_f09ecd89bdbf_Rejected] I;
GO


---------------------------------------------

-- int.viewImport_Unit_Accepted
CREATE VIEW [int].[viewImport_Unit_Accepted] AS
      SELECT I.* from [int].[Import_e71555c3_2e75_4f6e_9eef_056f9a8dc621_Accepted] I;
GO


---------------------------------------------

-- int.viewImport_Unit_Rejected
CREATE VIEW [int].[viewImport_Unit_Rejected] AS
      SELECT I.* from [int].[Import_e71555c3_2e75_4f6e_9eef_056f9a8dc621_Rejected] I;
GO


---------------------------------------------

-- int.viewReportExceptionsFactGL
CREATE VIEW [int].[viewReportExceptionsFactGL] 
AS
------------- int.FactGL  exceptions -------------

SELECT DISTINCT 
      source.AccountCode as DataMember, 
      'Account' as Identifier, 
      'int.FactGL' as Source,
      'Account "'+source.AccountCode +'" is present in int.FactGL but is not present in the Account Dimension' as Explanation 
FROM 
      int.FactGL source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimAccount WHERE AccountCode = source.AccountCode)


UNION ALL


SELECT DISTINCT 
      source.DepartmentCode as DataMember, 
      'Department' as Identifier, 
      'int.FactGL' as Source,
      'Department "'+ source.DepartmentCode +'" is present in int.FactGL but is not present in the Department Dimension' as Explanation 
FROM 
      int.FactGL source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimDepartment WHERE DepartmentCode = source.DepartmentCode)


UNION ALL


SELECT DISTINCT 
      source.TimeClassCode as DataMember, 
      'Time Class' as Identifier, 
      'int.FactGL' as Source,
      'Time Class "'+ source.TimeClassCode +'" is present in int.FactGL but is not present in the Time Class Dimension' as Explanation 
FROM 
      int.FactGL source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimTimeClass WHERE TimeClassCode = source.TimeClassCode)


UNION ALL


SELECT DISTINCT 
      source.FiscalYearCode as DataMember, 
      'Fiscal Year' as Identifier, 
      'int.FactGL' as Source,
      'Fiscal Year "'+ source.FiscalYearCode +'" is present in int.FactGL but is not present in the Fiscal Year Dimension' as Explanation 
FROM 
      int.FactGL source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimFiscalYear WHERE Name = source.FiscalYearCode)


UNION ALL


SELECT DISTINCT 
      source.FiscalMonthCode as DataMember, 
      'Fiscal Month' as Identifier, 
      'int.FactGL' as Source,
      'Fiscal Month "'+ source.FiscalMonthCode +'" is present in int.FactGL but is not present in the Fiscal Month Dimension' as Explanation 
FROM 
      int.FactGL source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimFiscalMonth WHERE FiscalMonthCode = source.FiscalMonthCode)
GO


---------------------------------------------

-- int.viewReportExceptionsFactPayorSummary
CREATE VIEW [int].[viewReportExceptionsFactPayorSummary] 
AS
------------- int.FactPayorSummary  exceptions -------------


SELECT DISTINCT 
      source.DepartmentCode as DataMember, 
      'Department' as Identifier, 
      'int.FactPayorSummary' as Source,
      'Department "'+ source.DepartmentCode +'" is present in int.FactPayorSummary but is not present in the Department Dimension' as Explanation 
FROM 
      int.FactPayorSummary source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimDepartment WHERE DepartmentCode = source.DepartmentCode)


UNION ALL


SELECT DISTINCT 
      source.AccountRollupCode as DataMember, 
      'SP Account Rollup' as Identifier, 
      'int.FactPayorSummary' as Source,
      'AccountRollup "'+source.AccountRollupCode +'" is present in int.FactPayorSummary but is not present in the SP Account Rollup Dimension' as Explanation 
FROM 
      int.FactPayorSummary source 
 WHERE NOT EXISTS
(select 1 FROM sp.DimAccountRollup ar where ar.Name = source.AccountRollupCode)


UNION ALL


SELECT DISTINCT 
      source.PayorGroupCode as DataMember, 
      'Payor Group' as Identifier, 
      'int.FactPayorSummary' as Source,
      'PayorGroup "'+source.PayorGroupCode +'" is present in int.FactPayorSummary but is not present in the Payor Group Dimension' as Explanation 
FROM 
      int.FactPayorSummary source
WHERE NOT EXISTS
(select 1 FROM fw.DimPayorGroup pr where source.PayorGroupCode=pr.Name)


UNION ALL


SELECT DISTINCT 
      source.PatientTypeRollupCode as DataMember, 
      'Patient Type Rollup' as Identifier, 
      'int.FactPayorSummary' as Source,
      'Patient Type Rollup "'+ source.TimeClassCode +'" is present in int.FactPayorSummary but is not present in the Patient Type Rollup Dimension' as Explanation 
FROM 
      int.FactPayorSummary source
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimPatientTypeRollup WHERE Name = source.PatientTypeRollupCode)


UNION ALL


SELECT DISTINCT 
      source.TimeClassCode as DataMember, 
      'Time Class' as Identifier, 
      'int.FactPayorSummary' as Source,
      'Time Class "'+ source.TimeClassCode +'" is present in int.FactPayorSummary but is not present in the Time Class Dimension' as Explanation 
FROM 
      int.FactPayorSummary source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimTimeClass WHERE TimeClassCode = source.TimeClassCode)


UNION ALL


SELECT DISTINCT 
      source.FiscalYearCode as DataMember, 
      'Fiscal Year' as Identifier, 
      'int.FactPayorSummary' as Source,
      'Fiscal Year "'+ source.FiscalYearCode +'" is present in int.FactPayorSummary but is not present in the Fiscal Year Dimension' as Explanation 
FROM 
      int.FactPayorSummary source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimFiscalYear WHERE Name = source.FiscalYearCode)


UNION ALL


SELECT DISTINCT 
      source.UnitType as DataMember, 
      'Unit Type' as Identifier, 
      'int.FactPayorSummary' as Source,
      'Unit Type "'+ source.UnitType +'" is present in int.FactPayorSummary but is not present in the Unit Type Dimension' as Explanation 
FROM 
      int.FactPayorSummary source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimUnitType WHERE Name = source.UnitType)

UNION ALL


SELECT DISTINCT 
      source.FiscalMonthCode as DataMember, 
      'Fiscal Month' as Identifier, 
      'int.FactPayorSummary' as Source,
      'Fiscal Month "'+ source.FiscalMonthCode +'" is present in int.FactPayorSummary but is not present in the Fiscal Month Dimension' as Explanation 
FROM 
      int.FactPayorSummary source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimFiscalMonth WHERE FiscalMonthCode = source.FiscalMonthCode)
GO


---------------------------------------------

-- int.viewReportExceptionsFactPhysicianSummary
CREATE VIEW [int].[viewReportExceptionsFactPhysicianSummary] 
AS
------------- int.FactPhysicianSummary  exceptions -------------


SELECT DISTINCT 
      source.DepartmentCode as DataMember, 
      'Department' as Identifier, 
      'int.FactPhysicianSummary' as Source,
      'Department "'+ source.DepartmentCode +'" is present in int.FactPhysicianSummary but is not present in the Department Dimension' as Explanation 
FROM 
      int.FactPhysicianSummary source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimDepartment WHERE DepartmentCode = source.DepartmentCode)


UNION ALL


SELECT DISTINCT 
      source.AccountRollupCode as DataMember, 
      'SP Account Rollup' as Identifier, 
      'int.FactPhysicianSummary' as Source,
      'AccountRollup "'+source.AccountRollupCode +'" is present in int.FactPhysicianSummary but is not present in the SP Account Rollup Dimension' as Explanation 
FROM 
      int.FactPhysicianSummary source 
 WHERE NOT EXISTS
(select 1 FROM sp.DimAccountRollup ar where ar.Name = source.AccountRollupCode)


UNION ALL


SELECT DISTINCT 
      source.PhysicianGroupCode as DataMember, 
      'Physician Group' as Identifier, 
      'int.FactPhysicianSummary' as Source,
      'Physician Group "'+source.PhysicianGroupCode +'" is present in int.FactPhysicianSummary but is not present in the Physician Group Dimension' as Explanation 
FROM 
      int.FactPhysicianSummary source
WHERE NOT EXISTS
(select 1 FROM fw.DimPhysicianGroup pr where source.PhysicianGroupCode=pr.Name)

UNION ALL


SELECT DISTINCT 
      source.PatientTypeRollupCode as DataMember, 
      'Patient Type Rollup' as Identifier, 
      'int.FactPhysicianSummary' as Source,
      'Patient Type Rollup "'+ source.TimeClassCode +'" is present in int.FactPhysicianSummary but is not present in the Patient Type Rollup Dimension' as Explanation 
FROM 
      int.FactPhysicianSummary source
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimPatientTypeRollup WHERE Name = source.PatientTypeRollupCode)


UNION ALL


SELECT DISTINCT 
      source.TimeClassCode as DataMember, 
      'Time Class' as Identifier, 
      'int.FactPhysicianSummary' as Source,
      'Time Class "'+ source.TimeClassCode +'" is present in int.FactPhysicianSummary but is not present in the Time Class Dimension' as Explanation 
FROM 
      int.FactPhysicianSummary source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimTimeClass WHERE TimeClassCode = source.TimeClassCode)


UNION ALL


SELECT DISTINCT 
      source.FiscalYearCode as DataMember, 
      'Fiscal Year' as Identifier, 
      'int.FactPhysicianSummary' as Source,
      'Fiscal Year "'+ source.FiscalYearCode +'" is present in int.FactPhysicianSummary but is not present in the Fiscal Year Dimension' as Explanation 
FROM 
      int.FactPhysicianSummary source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimFiscalYear WHERE Name = source.FiscalYearCode)


UNION ALL


SELECT DISTINCT 
      source.UnitType as DataMember, 
      'Unit Type' as Identifier, 
      'int.FactPhysicianSummary' as Source,
      'Unit Type "'+ source.UnitType +'" is present in int.FactPhysicianSummary but is not present in the Unit Type Dimension' as Explanation 
FROM 
      int.FactPhysicianSummary source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimUnitType WHERE Name = source.UnitType)

UNION ALL


SELECT DISTINCT 
      source.FiscalMonthCode as DataMember, 
      'Fiscal Month' as Identifier, 
      'int.FactPhysicianSummary' as Source,
      'Fiscal Month "'+ source.FiscalMonthCode +'" is present in int.FactPhysicianSummary but is not present in the Fiscal Month Dimension' as Explanation 
FROM 
      int.FactPhysicianSummary source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimFiscalMonth WHERE FiscalMonthCode = source.FiscalMonthCode)
GO


---------------------------------------------

-- int.viewReportExceptionsFactSPDirectBalAccount
CREATE VIEW [int].[viewReportExceptionsFactSPDirectBalAccount] 
AS
------------- int.FactSPDirectBalAccount  exceptions -------------

SELECT DISTINCT 
      source.SPLongRangePlanName as DataMember, 
      'Balance Sheet Plan' as Identifier, 
      'int.FactSPDirectBalAccount' as Source,
      'Balance Sheet Plan "'+ source.SPLongRangePlanName +'" is present in int.FactSPDirectBalAccount but is not present in the SP Long Range Plan Dimension' as Explanation 
FROM 
      [int].[FactSPDirectBalAccount] source
WHERE 
     source.SPLongRangePlanID=0
	 
	 

UNION ALL



SELECT DISTINCT 
      source.SPLongRangePlanName as DataMember, 
      'Account Rollup' as Identifier, 
      'int.FactSPDirectBalAccount' as Source,
      'Account Rollup "'+ source.SPLongRangePlanName +'" is present in int.FactSPDirectBalAccount but is not present in the SP Account Rollup Dimension' as Explanation 
FROM 
      [int].[FactSPDirectBalAccount] source
WHERE 
     source.AccountRollupID=0
	 
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Account Rollup related to a Debt Issuance' as Identifier, 
      'int.FactSPDirectBalAccount' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectBalAccount but does not have a Debt Issuance which is defined in the SP Debt Issuance Dimension associated to it. Please review the data file to ensure that it looks accurate' as Explanation 
FROM 
      [int].[FactSPDirectBalAccount] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Category='Debt - Long Term' and source.SPDebtIssuanceID=0)


UNION ALL


SELECT DISTINCT 
      source.SPCapitalRollupName as DataMember, 
      'Capital Rollup' as Identifier, 
      'int.FactSPDirectBalAccount' as Source,
      'Capital Rollup "'+ source.SPCapitalRollupName +'" is present in int.FactSPDirectBalAccount but is not present in the SP Capital Rollup Dimension' as Explanation 
FROM 
      [int].[FactSPDirectBalAccount] source
WHERE 
     NOT EXISTS (select 1 FROM [sp].[viewDimSPCapitalRollup] cr where source.SPCapitalRollupName=cr.Name)


UNION ALL


SELECT DISTINCT 
      source.TimeClassCode as DataMember, 
      'Time Class' as Identifier, 
      'int.FactSPDirectBalAccount' as Source,
      'Time Class "'+ source.TimeClassCode +'" is present in int.FactSPDirectBalAccount but is not present in the Time Class Dimension' as Explanation 
FROM 
      int.FactSPDirectBalAccount source  
WHERE 
      source.TimeClassID=0


UNION ALL


SELECT DISTINCT 
      source.FiscalYearCode as DataMember, 
      'Fiscal Year' as Identifier, 
      'int.FactSPDirectBalAccount' as Source,
      'Fiscal Year "'+ source.FiscalYearCode +'" is present in int.FactSPDirectBalAccount but is not present in the Fiscal Year Dimension' as Explanation 
FROM 
      int.FactSPDirectBalAccount source  
WHERE 
      source.FiscalYearID=0


UNION ALL


SELECT DISTINCT 
      source.UnitType as DataMember, 
      'Unit Type' as Identifier, 
      'int.FactSPDirectBalAccount' as Source,
      'Unit Type "'+ source.UnitType +'" is present in int.FactSPDirectBalAccount but is not present in the Unit Type Dimension' as Explanation 
FROM 
      int.FactSPDirectBalAccount source  
WHERE 
      source.UnitTypeID=0
GO


---------------------------------------------

-- int.viewReportExceptionsFactSPDirectISAccount
CREATE VIEW [int].[viewReportExceptionsFactSPDirectISAccount] 
AS
------------- int.FactSPDirectISAccount  exceptions -------------

SELECT DISTINCT 
      source.SPLongRangePlanName as DataMember, 
      'Operations Plan' as Identifier, 
      'int.FactSPDirectISAccount' as Source,
      'Operations Plan "'+ source.SPLongRangePlanName +'" is present in int.FactSPDirectISAccount but is not present in the SP Long Range Plan Dimension' as Explanation 
FROM 
      [int].[FactSPDirectISAccount] source
WHERE 
     source.SPLongRangePlanID=0
	 
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Account Rollup' as Identifier, 
      'int.FactSPDirectISAccount' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISAccount but is not present in the SP Account Rollup Dimension' as Explanation 
FROM 
      [int].[FactSPDirectISAccount] source
WHERE 
     source.AccountRollupID=0


UNION ALL


SELECT DISTINCT 
      source.TimeClassCode as DataMember, 
      'Time Class' as Identifier, 
      'int.FactSPDirectISAccount' as Source,
      'Time Class "'+ source.TimeClassCode +'" is present in int.FactSPDirectISAccount but is not present in the Time Class Dimension' as Explanation 
FROM 
      int.FactSPDirectISAccount source  
WHERE 
      source.TimeClassID=0


UNION ALL


SELECT DISTINCT 
      source.FiscalYearCode as DataMember, 
      'Fiscal Year' as Identifier, 
      'int.FactSPDirectISAccount' as Source,
      'Fiscal Year "'+ source.FiscalYearCode +'" is present in int.FactSPDirectISAccount but is not present in the Fiscal Year Dimension' as Explanation 
FROM 
      int.FactSPDirectISAccount source  
WHERE 
      source.FiscalYearID=0


UNION ALL


SELECT DISTINCT 
      source.UnitType as DataMember, 
      'Unit Type' as Identifier, 
      'int.FactSPDirectISAccount' as Source,
      'Unit Type "'+ source.UnitType +'" is present in int.FactSPDirectISAccount but is not present in the Unit Type Dimension' as Explanation 
FROM 
      int.FactSPDirectISAccount source  
WHERE 
      source.UnitTypeID=0
GO


---------------------------------------------

-- int.viewReportExceptionsFactSPDirectISPayor
CREATE VIEW [int].[viewReportExceptionsFactSPDirectISPayor] 
AS
------------- int.FactSPDirectISPayor  exceptions -------------

SELECT DISTINCT 
      source.SPLongRangePlanName as DataMember, 
      'Operations Plan' as Identifier, 
      'int.FactSPDirectISPayor' as Source,
      'Operations Plan "'+ source.SPLongRangePlanName +'" is present in int.FactSPDirectISPayor but is not present in the SP Long Range Plan Dimension' as Explanation 
FROM 
      [int].[FactSPDirectISPayor] source
WHERE 
     source.SPLongRangePlanID=0
	 
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Account Rollup' as Identifier, 
      'int.FactSPDirectISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPayor but is not present in the SP Account Rollup Dimension' as Explanation 
FROM 
      [int].[FactSPDirectISPayor] source
WHERE 
     source.AccountRollupID=0


UNION ALL



SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Account Rollup related to a Payor' as Identifier, 
      'int.FactSPDirectISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPayor but does not have a Payor which is defined in the Payor Group Dimension associated to it. Please review the data file to ensure that it looks accurate' as Explanation 
FROM 
      [int].[FactSPDirectISPayor] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Category='Payor Related Accounts Category' and source.PayorGroupID=0)



UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Account Rollup related to a Payor' as Identifier, 
      'int.FactSPDirectISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPayor but does not have a Patient Type Rollup which is defined in the Patient Type Rollup Dimension associated to it. Please review the data file to ensure that it looks accurate' as Explanation 
FROM 
      [int].[FactSPDirectISPayor] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Category='Payor Related Accounts Category' and source.PatientTypeRollupID=0)
	 
	 
UNION ALL


SELECT DISTINCT 
      source.TimeClassCode as DataMember, 
      'Time Class' as Identifier, 
      'int.FactSPDirectISPayor' as Source,
      'Time Class "'+ source.TimeClassCode +'" is present in int.FactSPDirectISPayor but is not present in the Time Class Dimension' as Explanation 
FROM 
      int.FactSPDirectISPayor source  
WHERE 
      source.TimeClassID=0


UNION ALL


SELECT DISTINCT 
      source.FiscalYearCode as DataMember, 
      'Fiscal Year' as Identifier, 
      'int.FactSPDirectISPayor' as Source,
      'Fiscal Year "'+ source.FiscalYearCode +'" is present in int.FactSPDirectISPayor but is not present in the Fiscal Year Dimension' as Explanation 
FROM 
      int.FactSPDirectISPayor source  
WHERE 
      source.FiscalYearID=0


UNION ALL


SELECT DISTINCT 
      source.UnitType as DataMember, 
      'Unit Type' as Identifier, 
      'int.FactSPDirectISPayor' as Source,
      'Unit Type "'+ source.UnitType +'" is present in int.FactSPDirectISPayor but is not present in the Unit Type Dimension' as Explanation 
FROM 
      int.FactSPDirectISPayor source  
WHERE 
      source.UnitTypeID=0



UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPayor but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "CMI"' as Explanation 
FROM 
      [int].[FactSPDirectISPayor] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='CMI' and source.UnitType<>'CMI')



UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPayor but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Volume"' as Explanation 
FROM 
      [int].[FactSPDirectISPayor] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Days' and source.UnitType<>'Volume')
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPayor but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Volume"' as Explanation 
FROM 
      [int].[FactSPDirectISPayor] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Total RVUs' and source.UnitType<>'Volume')


UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPayor but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Volume"' as Explanation 
FROM 
      [int].[FactSPDirectISPayor] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Worked RVUs' and source.UnitType<>'Volume')
	 
	 
UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPayor but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Volume"' as Explanation 
FROM 
      [int].[FactSPDirectISPayor] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Volume' and source.UnitType<>'Volume')
	 
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPayor but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Dollars"' as Explanation 
FROM 
      [int].[FactSPDirectISPayor] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Gross Charges' and source.UnitType<>'Dollars')
	 
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPayor but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Dollars"' as Explanation 
FROM 
      [int].[FactSPDirectISPayor] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Contractuals' and source.UnitType<>'Dollars')
GO


---------------------------------------------

-- int.viewReportExceptionsFactSPDirectISPhysician
CREATE VIEW [int].[viewReportExceptionsFactSPDirectISPhysician] 
AS
------------- int.FactSPDirectISPhysician  exceptions -------------

SELECT DISTINCT 
      source.SPLongRangePlanName as DataMember, 
      'Operations Plan' as Identifier, 
      'int.FactSPDirectISPhysician' as Source,
      'Operations Plan "'+ source.SPLongRangePlanName +'" is present in int.FactSPDirectISPhysician but is not present in the SP Long Range Plan Dimension' as Explanation 
FROM 
      [int].[FactSPDirectISPhysician] source
WHERE 
     source.SPLongRangePlanID=0
	 
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Account Rollup' as Identifier, 
      'int.FactSPDirectISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPhysician but is not present in the SP Account Rollup Dimension' as Explanation 
FROM 
      [int].[FactSPDirectISPhysician] source
WHERE 
     source.AccountRollupID=0


UNION ALL



SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Account Rollup related to a Physician Group' as Identifier, 
      'int.FactSPDirectISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPhysician but does not have a Physician Group which is defined in the Physician Group Dimension associated to it. Please review the data file to ensure that it looks accurate' as Explanation 
FROM 
      [int].[FactSPDirectISPhysician] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Category='Payor Related Accounts Category' and source.PhysicianGroupID=0)



UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Patient Type Rollup related to a Physician Group' as Identifier, 
      'int.FactSPDirectISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPhysician but has the incorrect Patient Type Rollup associated to it. The suggested patient type rollup for this type of an account rollup is "Clinic"' as Explanation 
FROM 
      [int].[FactSPDirectISPhysician] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Category='Payor Related Accounts Category' and source.PatientTypeRollupCode<>'Clinic')
	 
	 
UNION ALL


SELECT DISTINCT 
      source.TimeClassCode as DataMember, 
      'Time Class' as Identifier, 
      'int.FactSPDirectISPhysician' as Source,
      'Time Class "'+ source.TimeClassCode +'" is present in int.FactSPDirectISPhysician but is not present in the Time Class Dimension' as Explanation 
FROM 
      int.FactSPDirectISPhysician source  
WHERE 
      source.TimeClassID=0


UNION ALL


SELECT DISTINCT 
      source.FiscalYearCode as DataMember, 
      'Fiscal Year' as Identifier, 
      'int.FactSPDirectISPhysician' as Source,
      'Fiscal Year "'+ source.FiscalYearCode +'" is present in int.FactSPDirectISPhysician but is not present in the Fiscal Year Dimension' as Explanation 
FROM 
      int.FactSPDirectISPhysician source  
WHERE 
      source.FiscalYearID=0


UNION ALL


SELECT DISTINCT 
      source.UnitType as DataMember, 
      'Unit Type' as Identifier, 
      'int.FactSPDirectISPhysician' as Source,
      'Unit Type "'+ source.UnitType +'" is present in int.FactSPDirectISPhysician but is not present in the Unit Type Dimension' as Explanation 
FROM 
      int.FactSPDirectISPhysician source  
WHERE 
      source.UnitTypeID=0



UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPhysician but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "CMI"' as Explanation 
FROM 
      [int].[FactSPDirectISPhysician] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='CMI' and source.UnitType<>'CMI')



UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPhysician but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Volume"' as Explanation 
FROM 
      [int].[FactSPDirectISPhysician] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Days' and source.UnitType<>'Volume')
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPhysician but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Volume"' as Explanation 
FROM 
      [int].[FactSPDirectISPhysician] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Total RVUs' and source.UnitType<>'Volume')


UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPhysician but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Volume"' as Explanation 
FROM 
      [int].[FactSPDirectISPhysician] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Worked RVUs' and source.UnitType<>'Volume')
	 
	 
UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPhysician but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Volume"' as Explanation 
FROM 
      [int].[FactSPDirectISPhysician] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Volume' and source.UnitType<>'Volume')
	 
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPhysician but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Dollars"' as Explanation 
FROM 
      [int].[FactSPDirectISPhysician] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Gross Charges' and source.UnitType<>'Dollars')
	 
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISPhysician but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Dollars"' as Explanation 
FROM 
      [int].[FactSPDirectISPhysician] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Contractuals' and source.UnitType<>'Dollars')
GO


---------------------------------------------

-- int.viewReportExceptionsFactSPDirectISStaffing
CREATE VIEW [int].[viewReportExceptionsFactSPDirectISStaffing] 
AS
------------- int.FactSPDirectISStaffing  exceptions -------------

SELECT DISTINCT 
      source.SPLongRangePlanName as DataMember, 
      'Operations Plan' as Identifier, 
      'int.FactSPDirectISStaffing' as Source,
      'Operations Plan "'+ source.SPLongRangePlanName +'" is present in int.FactSPDirectISStaffing but is not present in the SP Long Range Plan Dimension' as Explanation 
FROM 
      [int].[FactSPDirectISStaffing] source
WHERE 
     source.SPLongRangePlanID=0
	 
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Account Rollup' as Identifier, 
      'int.FactSPDirectISStaffing' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISStaffing but is not present in the SP Account Rollup Dimension' as Explanation 
FROM 
      [int].[FactSPDirectISStaffing] source
WHERE 
     source.AccountRollupID=0


UNION ALL



SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Account Rollup related to a Job Code Group' as Identifier, 
      'int.FactSPDirectISStaffing' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISStaffing but does not have a Job Code Group which is defined in the Job Code Group Dimension associated to it. Please review the data file to ensure that it looks accurate' as Explanation 
FROM 
      [int].[FactSPDirectISStaffing] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Category='Staffing Related Accounts Category' and source.JobCodeGroupID=0)


UNION ALL


SELECT DISTINCT 
      source.TimeClassCode as DataMember, 
      'Time Class' as Identifier, 
      'int.FactSPDirectISStaffing' as Source,
      'Time Class "'+ source.TimeClassCode +'" is present in int.FactSPDirectISStaffing but is not present in the Time Class Dimension' as Explanation 
FROM 
      int.FactSPDirectISStaffing source  
WHERE 
      source.TimeClassID=0


UNION ALL


SELECT DISTINCT 
      source.FiscalYearCode as DataMember, 
      'Fiscal Year' as Identifier, 
      'int.FactSPDirectISStaffing' as Source,
      'Fiscal Year "'+ source.FiscalYearCode +'" is present in int.FactSPDirectISStaffing but is not present in the Fiscal Year Dimension' as Explanation 
FROM 
      int.FactSPDirectISStaffing source  
WHERE 
      source.FiscalYearID=0


UNION ALL


SELECT DISTINCT 
      source.UnitType as DataMember, 
      'Unit Type' as Identifier, 
      'int.FactSPDirectISStaffing' as Source,
      'Unit Type "'+ source.UnitType +'" is present in int.FactSPDirectISStaffing but is not present in the Unit Type Dimension' as Explanation 
FROM 
      int.FactSPDirectISStaffing source  
WHERE 
      source.UnitTypeID=0



UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectISStaffing' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISStaffing but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "FTEs"' as Explanation 
FROM 
      [int].[FactSPDirectISStaffing] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='FTEs' and source.UnitType<>'FTEs')



UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectISStaffing' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectISStaffing but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Dollars"' as Explanation 
FROM 
      [int].[FactSPDirectISStaffing] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Salaries' and source.UnitType<>'Dollars')
GO


---------------------------------------------

-- int.viewReportExceptionsFactSPDirectRollingISAccount
CREATE VIEW [int].[viewReportExceptionsFactSPDirectRollingISAccount] 
AS
------------- int.FactSPDirectRollingISAccount  exceptions -------------

SELECT DISTINCT 
      source.SPRollingForecastPlanName as DataMember, 
      'Rolling Forecast Plan' as Identifier, 
      'int.FactSPDirectRollingISAccount' as Source,
      'Rolling Forecast Plan "'+ source.SPRollingForecastPlanName +'" is present in int.FactSPDirectRollingISAccount but is not present in the SP Rolling Forecast Plan Dimension' as Explanation 
FROM 
      [int].[FactSPDirectRollingISAccount] source
WHERE 
     source.SPRollingForecastPlanID=0
	 
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISAccount' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISAccount but is not present in the SP Account Rollup Dimension' as Explanation 
FROM 
      [int].[FactSPDirectRollingISAccount] source
WHERE 
     source.AccountRollupID=0


UNION ALL


SELECT DISTINCT 
      source.TimeClassCode as DataMember, 
      'Time Class' as Identifier, 
      'int.FactSPDirectRollingISAccount' as Source,
      'Time Class "'+ source.TimeClassCode +'" is present in int.FactSPDirectRollingISAccount but is not present in the Time Class Dimension' as Explanation 
FROM 
      int.FactSPDirectRollingISAccount source  
WHERE 
      source.TimeClassID=0


UNION ALL


SELECT DISTINCT 
      source.FiscalYearCode as DataMember, 
      'Fiscal Year' as Identifier, 
      'int.FactSPDirectRollingISAccount' as Source,
      'Fiscal Year "'+ source.FiscalYearCode +'" is present in int.FactSPDirectRollingISAccount but is not present in the Fiscal Year Dimension' as Explanation 
FROM 
      int.FactSPDirectRollingISAccount source  
WHERE 
      source.FiscalYearID=0


UNION ALL


SELECT DISTINCT 
      source.UnitType as DataMember, 
      'Unit Type' as Identifier, 
      'int.FactSPDirectRollingISAccount' as Source,
      'Unit Type "'+ source.UnitType +'" is present in int.FactSPDirectRollingISAccount but is not present in the Unit Type Dimension' as Explanation 
FROM 
      int.FactSPDirectRollingISAccount source  
WHERE 
      source.UnitTypeID=0
GO


---------------------------------------------

-- int.viewReportExceptionsFactSPDirectRollingISPayor
CREATE VIEW [int].[viewReportExceptionsFactSPDirectRollingISPayor] 
AS
------------- int.FactSPDirectRollingISPayor  exceptions -------------

SELECT DISTINCT 
      source.SPRollingForecastPlanName as DataMember, 
      'Rolling Forecast Plan' as Identifier, 
      'int.FactSPDirectRollingISPayor' as Source,
      'Rolling Forecast Plan "'+ source.SPRollingForecastPlanName +'" is present in int.FactSPDirectRollingISPayor but is not present in the SP Rolling Forecast Plan Dimension' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPayor] source
WHERE 
     source.SPRollingForecastPlanID=0
	 
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPayor but is not present in the SP Account Rollup Dimension' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPayor] source
WHERE 
     source.AccountRollupID=0


UNION ALL



SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Account Rollup related to a Payor' as Identifier, 
      'int.FactSPDirectRollingISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPayor but does not have a Payor which is defined in the Payor Group Dimension associated to it. Please review the data file to ensure that it looks accurate' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPayor] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Category='Payor Related Accounts Category' and source.PayorGroupID=0)



UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Account Rollup related to a Payor' as Identifier, 
      'int.FactSPDirectRollingISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPayor but does not have a Patient Type Rollup which is defined in the Patient Type Rollup Dimension associated to it. Please review the data file to ensure that it looks accurate' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPayor] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Category='Payor Related Accounts Category' and source.PatientTypeRollupID=0)
	 
	 
UNION ALL


SELECT DISTINCT 
      source.TimeClassCode as DataMember, 
      'Time Class' as Identifier, 
      'int.FactSPDirectRollingISPayor' as Source,
      'Time Class "'+ source.TimeClassCode +'" is present in int.FactSPDirectRollingISPayor but is not present in the Time Class Dimension' as Explanation 
FROM 
      int.FactSPDirectRollingISPayor source  
WHERE 
      source.TimeClassID=0


UNION ALL


SELECT DISTINCT 
      source.FiscalYearCode as DataMember, 
      'Fiscal Year' as Identifier, 
      'int.FactSPDirectRollingISPayor' as Source,
      'Fiscal Year "'+ source.FiscalYearCode +'" is present in int.FactSPDirectRollingISPayor but is not present in the Fiscal Year Dimension' as Explanation 
FROM 
      int.FactSPDirectRollingISPayor source  
WHERE 
      source.FiscalYearID=0


UNION ALL


SELECT DISTINCT 
      source.UnitType as DataMember, 
      'Unit Type' as Identifier, 
      'int.FactSPDirectRollingISPayor' as Source,
      'Unit Type "'+ source.UnitType +'" is present in int.FactSPDirectRollingISPayor but is not present in the Unit Type Dimension' as Explanation 
FROM 
      int.FactSPDirectRollingISPayor source  
WHERE 
      source.UnitTypeID=0



UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPayor but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "CMI"' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPayor] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='CMI' and source.UnitType<>'CMI')



UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPayor but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Volume"' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPayor] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Days' and source.UnitType<>'Volume')
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPayor but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Volume"' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPayor] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Total RVUs' and source.UnitType<>'Volume')


UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPayor but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Volume"' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPayor] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Worked RVUs' and source.UnitType<>'Volume')
	 
	 
UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPayor but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Volume"' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPayor] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Volume' and source.UnitType<>'Volume')
	 
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPayor but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Dollars"' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPayor] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Gross Charges' and source.UnitType<>'Dollars')
	 
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISPayor' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPayor but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Dollars"' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPayor] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Contractuals' and source.UnitType<>'Dollars')
GO


---------------------------------------------

-- int.viewReportExceptionsFactSPDirectRollingISPhysician
CREATE VIEW [int].[viewReportExceptionsFactSPDirectRollingISPhysician] 
AS
------------- int.FactSPDirectRollingISPhysician  exceptions -------------

SELECT DISTINCT 
      source.SPRollingForecastPlanName as DataMember, 
      'Rolling Forecast Plan' as Identifier, 
      'int.FactSPDirectRollingISPhysician' as Source,
      'Rolling Forecast Plan "'+ source.SPRollingForecastPlanName +'" is present in int.FactSPDirectRollingISPhysician but is not present in the SP Rolling Forecast Plan Dimension' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPhysician] source
WHERE 
     source.SPRollingForecastPlanID=0
	 
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPhysician but is not present in the SP Account Rollup Dimension' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPhysician] source
WHERE 
     source.AccountRollupID=0


UNION ALL



SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Account Rollup related to a Physician Group' as Identifier, 
      'int.FactSPDirectRollingISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPhysician but does not have a Physician Group which is defined in the Physician Group Dimension associated to it. Please review the data file to ensure that it looks accurate' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPhysician] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Category='Payor Related Accounts Category' and source.PhysicianGroupID=0)



UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Patient Type Rollup related to a Physician Group' as Identifier, 
      'int.FactSPDirectRollingISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPhysician but has the incorrect Patient Type Rollup associated to it. The suggested patient type rollup for this type of an account rollup is "Clinic"' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPhysician] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Category='Payor Related Accounts Category' and source.PatientTypeRollupCode<>'Clinic')
	 
	 
UNION ALL


SELECT DISTINCT 
      source.TimeClassCode as DataMember, 
      'Time Class' as Identifier, 
      'int.FactSPDirectRollingISPhysician' as Source,
      'Time Class "'+ source.TimeClassCode +'" is present in int.FactSPDirectRollingISPhysician but is not present in the Time Class Dimension' as Explanation 
FROM 
      int.FactSPDirectRollingISPhysician source  
WHERE 
      source.TimeClassID=0


UNION ALL


SELECT DISTINCT 
      source.FiscalYearCode as DataMember, 
      'Fiscal Year' as Identifier, 
      'int.FactSPDirectRollingISPhysician' as Source,
      'Fiscal Year "'+ source.FiscalYearCode +'" is present in int.FactSPDirectRollingISPhysician but is not present in the Fiscal Year Dimension' as Explanation 
FROM 
      int.FactSPDirectRollingISPhysician source  
WHERE 
      source.FiscalYearID=0


UNION ALL


SELECT DISTINCT 
      source.UnitType as DataMember, 
      'Unit Type' as Identifier, 
      'int.FactSPDirectRollingISPhysician' as Source,
      'Unit Type "'+ source.UnitType +'" is present in int.FactSPDirectRollingISPhysician but is not present in the Unit Type Dimension' as Explanation 
FROM 
      int.FactSPDirectRollingISPhysician source  
WHERE 
      source.UnitTypeID=0



UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPhysician but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "CMI"' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPhysician] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='CMI' and source.UnitType<>'CMI')



UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPhysician but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Volume"' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPhysician] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Days' and source.UnitType<>'Volume')
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPhysician but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Volume"' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPhysician] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Total RVUs' and source.UnitType<>'Volume')


UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPhysician but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Volume"' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPhysician] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Worked RVUs' and source.UnitType<>'Volume')
	 
	 
UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPhysician but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Volume"' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPhysician] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Volume' and source.UnitType<>'Volume')
	 
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPhysician but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Dollars"' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPhysician] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Gross Charges' and source.UnitType<>'Dollars')
	 
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISPhysician' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISPhysician but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Dollars"' as Explanation 
FROM 
      [int].[FactSPDirectRollingISPhysician] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Contractuals' and source.UnitType<>'Dollars')
GO


---------------------------------------------

-- int.viewReportExceptionsFactSPDirectRollingISStaffing
CREATE VIEW [int].[viewReportExceptionsFactSPDirectRollingISStaffing] 
AS
------------- int.FactSPDirectRollingISStaffing  exceptions -------------

SELECT DISTINCT 
      source.SPRollingForecastPlanName as DataMember, 
      'Operations Plan' as Identifier, 
      'int.FactSPDirectRollingISStaffing' as Source,
      'Operations Plan "'+ source.SPRollingForecastPlanName +'" is present in int.FactSPDirectRollingISStaffing but is not present in the SP Rolling Forecast Plan Dimension' as Explanation 
FROM 
      [int].[FactSPDirectRollingISStaffing] source
WHERE 
     source.SPRollingForecastPlanID=0
	 
	 

UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISStaffing' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISStaffing but is not present in the SP Account Rollup Dimension' as Explanation 
FROM 
      [int].[FactSPDirectRollingISStaffing] source
WHERE 
     source.AccountRollupID=0


UNION ALL



SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Account Rollup related to a Job Code Group' as Identifier, 
      'int.FactSPDirectRollingISStaffing' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISStaffing but does not have a Job Code Group which is defined in the Job Code Group Dimension associated to it. Please review the data file to ensure that it looks accurate' as Explanation 
FROM 
      [int].[FactSPDirectRollingISStaffing] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Category='Staffing Related Accounts Category' and source.JobCodeGroupID=0)


UNION ALL


SELECT DISTINCT 
      source.TimeClassCode as DataMember, 
      'Time Class' as Identifier, 
      'int.FactSPDirectRollingISStaffing' as Source,
      'Time Class "'+ source.TimeClassCode +'" is present in int.FactSPDirectRollingISStaffing but is not present in the Time Class Dimension' as Explanation 
FROM 
      int.FactSPDirectRollingISStaffing source  
WHERE 
      source.TimeClassID=0


UNION ALL


SELECT DISTINCT 
      source.FiscalYearCode as DataMember, 
      'Fiscal Year' as Identifier, 
      'int.FactSPDirectRollingISStaffing' as Source,
      'Fiscal Year "'+ source.FiscalYearCode +'" is present in int.FactSPDirectRollingISStaffing but is not present in the Fiscal Year Dimension' as Explanation 
FROM 
      int.FactSPDirectRollingISStaffing source  
WHERE 
      source.FiscalYearID=0


UNION ALL


SELECT DISTINCT 
      source.UnitType as DataMember, 
      'Unit Type' as Identifier, 
      'int.FactSPDirectRollingISStaffing' as Source,
      'Unit Type "'+ source.UnitType +'" is present in int.FactSPDirectRollingISStaffing but is not present in the Unit Type Dimension' as Explanation 
FROM 
      int.FactSPDirectRollingISStaffing source  
WHERE 
      source.UnitTypeID=0



UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISStaffing' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISStaffing but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "FTEs"' as Explanation 
FROM 
      [int].[FactSPDirectRollingISStaffing] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='FTEs' and source.UnitType<>'FTEs')



UNION ALL


SELECT DISTINCT 
      source.SPAccountRollupName as DataMember, 
      'Unit Type related to an Account Rollup' as Identifier, 
      'int.FactSPDirectRollingISStaffing' as Source,
      'Account Rollup "'+ source.SPAccountRollupName +'" is present in int.FactSPDirectRollingISStaffing but has the incorrect Unit Type associated to it. The suggested unit type for this type of an account rollup is "Dollars"' as Explanation 
FROM 
      [int].[FactSPDirectRollingISStaffing] source
WHERE 
     EXISTS (select 1 FROM [sp].[viewDimAccountRollup] ar where source.SPAccountRollupName = ar.Name and ar.Name='Salaries' and source.UnitType<>'Dollars')
GO


---------------------------------------------

-- int.viewReportExceptionsFactStaffing
CREATE VIEW [int].[viewReportExceptionsFactStaffing] 
AS
------------- int.FactStaffing exceptions -------------

SELECT DISTINCT source.DepartmentCode as DataMember, 
      'Department' as Identifier, 
      'int.FactStaffing' as Source,
      'Department "'+ source.DepartmentCode +'" is present in int.FactStaffing but is not present in the Department Dimension' as Explanation 
FROM 
      int.FactStaffing source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimDepartment WHERE DepartmentCode = source.DepartmentCode)


UNION ALL


SELECT DISTINCT 
      source.JobCode  as DataMember, 
      'Job Code' as Identifier, 
      'int.FactStaffing' as Source,
      'Job Code "'+source.JobCode +'" is present in int.FactStaffing but is not present in the Job Code Dimension' as Explanation 
FROM 
      int.FactStaffing source 
 WHERE NOT EXISTS
(select 1 FROM fw.DimJobCode jcg where source.JobCode=jcg.JobCode)



UNION ALL


SELECT DISTINCT 
      source.PayCode as DataMember, 
      'Pay Code' as Identifier, 
      'int.FactStaffing' as Source,
      'Pay Code "'+source.PayCode +'" is present in int.FactStaffing but is not present in the Pay Code Dimension' as Explanation 
FROM 
      int.FactStaffing source 
 WHERE NOT EXISTS
(select 1 FROM fw.DimPayCode pc where pc.PayCode = source.PayCode)



UNION ALL


SELECT DISTINCT 
      source.TimeClassCode as DataMember, 
      'Time Class' as Identifier, 
      'int.FactStaffing' as Source,
      'Time Class "'+ source.TimeClassCode +'" is present in int.FactStaffing but is not present in the Time Class Dimension' as Explanation 
FROM 
      int.FactStaffing source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimTimeClass WHERE TimeClassCode = source.TimeClassCode)


UNION ALL


SELECT DISTINCT 
      source.FiscalYearCode as DataMember, 
      'Fiscal Year' as Identifier, 
      'int.FactStaffing' as Source,
      'Fiscal Year "'+ source.FiscalYearCode +'" is present in int.FactStaffing but is not present in the Fiscal Year Dimension' as Explanation 
FROM 
      int.FactStaffing source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimFiscalYear WHERE Name = source.FiscalYearCode)


UNION ALL


SELECT DISTINCT 
      source.UnitType as DataMember, 
      'Unit Type' as Identifier, 
      'int.FactStaffing' as Source,
      'Unit Type "'+ source.UnitType +'" is present in int.FactStaffing but is not present in the Unit Type Dimension' as Explanation 
FROM 
      int.FactStaffing source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimUnitType WHERE Name = source.UnitType)

UNION ALL


SELECT DISTINCT 
      source.FiscalMonthCode as DataMember, 
      'Fiscal Month' as Identifier, 
      'int.FactStaffing' as Source,
      'Fiscal Month "'+ source.FiscalMonthCode +'" is present in int.FactStaffing but is not present in the Fiscal Month Dimension' as Explanation 
FROM 
      int.FactStaffing source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimFiscalMonth WHERE FiscalMonthCode = source.FiscalMonthCode)
	  
	  
	  UNION ALL


SELECT DISTINCT 
      cast(source.EmployeeCode as nvarchar(20)) as DataMember, 
      'Employee Code' as Identifier, 
      'int.FactStaffing' as Source,
      'Employee Code "'+ source.EmployeeCode +'" is present in int.FactStaffing but is not present in the Employee Dimension' as Explanation 
FROM 
      int.FactStaffing source  
WHERE 
      NOT EXISTS (select 1 FROM [fw].[DimEmployee] WHERE Code = source.EmployeeCode)
GO


---------------------------------------------

-- int.viewReportExceptionsFactStaffingByPayPeriod
CREATE VIEW [int].[viewReportExceptionsFactStaffingByPayPeriod] 
AS
------------- int.FactStaffingByPayPeriod exceptions -------------

SELECT DISTINCT source.DepartmentCode as DataMember, 
      'Department' as Identifier, 
      'int.FactStaffingByPayPeriod' as Source,
      'Department "'+ source.DepartmentCode +'" is present in int.FactStaffingByPayPeriod but not present in the Department Dimension' as Explanation 
FROM 
      int.FactStaffingByPayPeriod source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimDepartment WHERE DepartmentCode = source.DepartmentCode)


UNION ALL


SELECT DISTINCT 
      source.JobCode  as DataMember, 
      'Job Code' as Identifier, 
      'int.FactStaffingByPayPeriod' as Source,
      'Job Code "'+source.JobCode +'" is present in int.FactStaffingByPayPeriod but not present in the Job Code Dimension' as Explanation 
FROM 
      int.FactStaffingByPayPeriod source 
 WHERE NOT EXISTS
(select 1 FROM fw.DimJobCode jcg where source.JobCode=jcg.JobCode)



UNION ALL


SELECT DISTINCT 
      source.PayCode as DataMember, 
      'Pay Code' as Identifier, 
      'int.FactStaffingByPayPeriod' as Source,
      'Pay Code "'+source.PayCode +'" is present in int.FactStaffingByPayPeriod but not present in the Pay Code Dimension' as Explanation 
FROM 
      int.FactStaffingByPayPeriod source 
 WHERE NOT EXISTS
(select 1 FROM fw.DimPayCode pc where pc.PayCode = source.PayCode)



UNION ALL


SELECT DISTINCT 
      source.PayPeriodCode as DataMember, 
      'Pay Period Code' as Identifier, 
      'int.FactStaffingByPayPeriod' as Source,
      'Pay Period Code "'+source.PayPeriodCode +'" is present in int.FactStaffingByPayPeriod but not present in the Pay Period Code Dimension' as Explanation 
FROM 
      int.FactStaffingByPayPeriod source 
 WHERE NOT EXISTS
(select 1 FROM fw.DimPayPeriod pp where pp.PayPeriodCode = source.PayPeriodCode)



UNION ALL


SELECT DISTINCT 
      source.TimeClassCode as DataMember, 
      'Time Class' as Identifier, 
      'int.FactStaffingByPayPeriod' as Source,
      'Time Class "'+ source.TimeClassCode +'" is present in int.FactStaffingByPayPeriod but not present in the Time Class Dimension' as Explanation 
FROM 
      int.FactStaffingByPayPeriod source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimTimeClass WHERE TimeClassCode = source.TimeClassCode)


UNION ALL


SELECT DISTINCT 
      source.FiscalYearCode as DataMember, 
      'Fiscal Year' as Identifier, 
      'int.FactStaffingByPayPeriod' as Source,
      'Fiscal Year "'+ source.FiscalYearCode +'" is present in int.FactStaffingByPayPeriod but not present in the Fiscal Year Dimension' as Explanation 
FROM 
      int.FactStaffingByPayPeriod source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimFiscalYear WHERE Name = source.FiscalYearCode)


UNION ALL


SELECT DISTINCT 
      source.UnitType as DataMember, 
      'Unit Type' as Identifier, 
      'int.FactStaffingByPayPeriod' as Source,
      'Unit Type "'+ source.UnitType +'" is present in int.FactStaffingByPayPeriod but not present in the Unit Type Dimension' as Explanation 
FROM 
      int.FactStaffingByPayPeriod source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimUnitType WHERE Name = source.UnitType)
	  
	  UNION ALL


SELECT DISTINCT 
      cast(source.EmployeeCode as nvarchar(20)) as DataMember,
      'Employee Code' as Identifier, 
      'int.FactStaffingByPayPeriod' as Source,
      'Employee Code "'+ source.EmployeeCode +'" is present in int.FactStaffingByPayPeriod but not present in the Employee Dimension' as Explanation 
FROM 
      int.FactStaffingByPayPeriod source  
WHERE 
      NOT EXISTS (select 1 FROM [fw].[DimEmployee] WHERE Code = source.EmployeeCode)
GO


---------------------------------------------

-- int.viewReportExceptionsFactStaffingSummary
CREATE VIEW [int].[viewReportExceptionsFactStaffingSummary] 
AS
------------- int.FactStaffingSummary exceptions -------------

SELECT DISTINCT source.DepartmentCode as DataMember, 
      'Department' as Identifier, 
      'int.FactStaffingSummary' as Source,
      'Department "'+ source.DepartmentCode +'" is present in int.FactStaffingSummary but not present in the Department Dimension' as Explanation 
FROM 
      int.FactStaffingSummary source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimDepartment WHERE DepartmentCode = source.DepartmentCode)


UNION ALL


SELECT DISTINCT 
      source.AccountRollupCode as DataMember, 
      'SP Account Rollup' as Identifier, 
      'int.FactStaffingSummary' as Source,
      'AccountRollup "'+source.AccountRollupCode +'" is present in int.FactStaffingSummary but not present in the SP Account Rollup Dimension' as Explanation 
FROM 
      int.FactStaffingSummary source 
 WHERE NOT EXISTS
(select 1 FROM sp.DimAccountRollup ar where ar.Name = source.AccountRollupCode)


UNION ALL


SELECT DISTINCT 
      source.JobCodeGroup  as DataMember, 
      'Job Code Group' as Identifier, 
      'int.FactStaffingSummary' as Source,
      'JobCodeGroup "'+source.JobCodeGroup +'" is present in int.FactStaffingSummary but not present in the Job Code Group Dimension' as Explanation 
FROM 
      int.FactStaffingSummary source 
 WHERE NOT EXISTS
(select 1 FROM fw.DimJobCodeGroup sr where source.JobCodeGroup=sr.Name)

UNION ALL


SELECT DISTINCT 
      source.TimeClassCode as DataMember, 
      'Time Class' as Identifier, 
      'int.FactStaffingSummary' as Source,
      'Time Class "'+ source.TimeClassCode +'" is present in int.FactStaffingSummary but not present in the Time Class Dimension' as Explanation 
FROM 
      int.FactStaffingSummary source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimTimeClass WHERE TimeClassCode = source.TimeClassCode)


UNION ALL


SELECT DISTINCT 
      source.FiscalYearCode as DataMember, 
      'Fiscal Year' as Identifier, 
      'int.FactStaffingSummary' as Source,
      'Fiscal Year "'+ source.FiscalYearCode +'" is present in int.FactStaffingSummary but not present in the Fiscal Year Dimension' as Explanation 
FROM 
      int.FactStaffingSummary source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimFiscalYear WHERE Name = source.FiscalYearCode)


UNION ALL


SELECT DISTINCT 
      source.UnitType as DataMember, 
      'Unit Type' as Identifier, 
      'int.FactStaffingSummary' as Source,
      'Unit Type "'+ source.UnitType +'" is present in int.FactStaffingSummary but not present in the Unit Type Dimension' as Explanation 
FROM 
      int.FactStaffingSummary source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimUnitType WHERE Name = source.UnitType)

UNION ALL


SELECT DISTINCT 
      source.FiscalMonthCode as DataMember, 
      'Fiscal Month' as Identifier, 
      'int.FactStaffingSummary' as Source,
      'Fiscal Month "'+ source.FiscalMonthCode +'" is present in int.FactStaffingSummary but is not present in the Fiscal Month Dimension' as Explanation 
FROM 
      int.FactStaffingSummary source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimFiscalMonth WHERE FiscalMonthCode = source.FiscalMonthCode)
GO


---------------------------------------------

-- int.viewReportExceptionsFactStatistic
CREATE VIEW [int].[viewReportExceptionsFactStatistic] 
AS
------------- int.FactStatistic  exceptions -------------

SELECT DISTINCT 
      source.AccountCode as DataMember, 
      'Account' as Identifier, 
      'int.FactStatistic' as Source,
      'Account "'+source.AccountCode +'" is present in int.FactStatistic but is not present in the Account Dimension' as Explanation 
FROM 
      [int].[FactStatistic] source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimAccount WHERE AccountCode = source.AccountCode)


UNION ALL


SELECT DISTINCT 
      source.DepartmentCode as DataMember, 
      'Department' as Identifier, 
      'int.FactStatistic' as Source,
      'Department "'+ source.DepartmentCode +'" is present in int.FactStatistic but is not present in the Department Dimension' as Explanation 
FROM 
      [int].[FactStatistic] source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimDepartment WHERE DepartmentCode = source.DepartmentCode)



UNION ALL


SELECT DISTINCT 
      source.TimeClassCode as DataMember, 
      'Time Class' as Identifier, 
      'int.FactStatistic' as Source,
      'Time Class "'+ source.TimeClassCode +'" is present in int.FactStatistic but is not present in the Time Class Dimension' as Explanation 
FROM 
      [int].[FactStatistic]source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimTimeClass WHERE TimeClassCode = source.TimeClassCode)


UNION ALL


SELECT DISTINCT 
      source.FiscalYearCode as DataMember, 
      'Fiscal Year' as Identifier, 
      'int.FactStatistic' as Source,
      'Fiscal Year "'+ source.FiscalYearCode +'" is present in int.FactStatistic but is not present in the Fiscal Year Dimension' as Explanation 
FROM 
      [int].[FactStatistic] source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimFiscalYear WHERE Name = source.FiscalYearCode)

UNION ALL


SELECT DISTINCT 
      source.FiscalMonthCode as DataMember, 
      'Fiscal Month' as Identifier, 
      'int.FactStatistic' as Source,
      'Fiscal Month "'+ source.FiscalMonthCode +'" is present in int.FactStatistic but is not present in the Fiscal Month Dimension' as Explanation 
FROM 
      int.FactStatistic source  
WHERE 
      NOT EXISTS (select 1 FROM fw.viewDimFiscalMonth WHERE FiscalMonthCode = source.FiscalMonthCode)
GO


---------------------------------------------

-- int.viewWeeklyINTStatus
CREATE view [int].[viewWeeklyINTStatus] 
as
	select
		ConfigName,
		EndTimeUtc as [Upload Date],
		case when IsSuccess = 1 AND HasCompleted = 1 then 'SUCCESS' else 'FAILED' end as [Status],
		RowsImported as NumberofRows,
		UserNameFirst + ' ' + UserNameLast as ImportUser,
		'NA' as SumofItems
	from [dbo].[viewIntTransaction]
	where EndTimeUtc >= dateadd(dd, -7, getutcdate())
GO


---------------------------------------------

---------------------------------------------
--  PROCEDURES
---------------------------------------------

-- int.procDeleteAllUnusedIntTables
CREATE procedure [int].[procDeleteAllUnusedIntTables]
	@AreYouReallySureYouWantToDoThis bit = 0
	--this will drop many tables, if you are unsure, do not run this.
AS

IF @AreYouReallySureYouWantToDoThis = 1
BEGIN

declare @schema varchar(25) = 'int';
declare @count int = 0;
declare crsCursor CURSOR LOCAL FAST_FORWARD FOR
	select t.name from sys.tables t
		inner join sys.schemas s on s.schema_id = t.schema_id
	where s.name = @schema
	
OPEN crsCursor;
DECLARE @tablename varchar(200)
FETCH NEXT FROM crsCursor into @tablename
WHILE (@@FETCH_STATUS = 0) 
	BEGIN
		IF NOT EXISTS (SELECT * FROM [dbo].[IntDataInterfaceSection] WHERE  @tablename  LIKE '%' + REPLACE( DataInterfaceSectionID,'-','_') + '%')  AND ((@tablename LIKE 'Import%' OR @tablename LIKE 'Temp%') AND (@tablename NOT LIKE 'Fact%' AND @tablename NOT LIKE 'QU%' ))
		BEGIN
			PRINT @tablename
			SET @count = @count + 1
			exec procSysDropTable @schema, @tablename
		END
		FETCH NEXT FROM crsCursor into @tablename
	END
	PRINT  CAST(@count AS varchar) + ' tables were droped.'
CLOSE crsCursor;
DEALLOCATE crsCursor;

declare @viewschema varchar(25) = 'int';
declare @viewcount int = 0;
declare crsCursor CURSOR LOCAL FAST_FORWARD FOR
	select t.name from sys.views t
		inner join sys.schemas s on s.schema_id = t.schema_id
	where s.name = @viewschema
	
OPEN crsCursor;
DECLARE @viewtablename varchar(200)
FETCH NEXT FROM crsCursor into @viewtablename
WHILE (@@FETCH_STATUS = 0) 
	BEGIN
		IF NOT EXISTS 
			(
				SELECT top 1 1
				FROM [dbo].[IntDataInterfaceSection] 
				WHERE 1=1
					and (
							@viewtablename LIKE 'viewImport%' + REPLACE(REPLACE(Name,'-','_'), ' ', '_') + '\_Accepted' ESCAPE '\'
							or @viewtablename LIKE 'viewImport%' + REPLACE(REPLACE(Name,'-','_'), ' ', '_') + '\_Rejected' ESCAPE '\'
						)
			) 
		and @viewtablename LIKE 'viewImport%'
		BEGIN
			PRINT @viewtablename
			SET @viewcount = @viewcount + 1
			exec [dbo].[procSysDropView] @viewschema, @viewtablename
		END
		FETCH NEXT FROM crsCursor into @viewtablename
	END
	PRINT  CAST(@viewcount AS varchar) + ' views were droped.'
CLOSE crsCursor;
DEALLOCATE crsCursor;

END
GO


---------------------------------------------

-- int.procDeleteIntegrationConfig
/************************************************************
** Author: 
** Create Date: 
** Description: deletes integration config and 
** Last Modified: 2015-10-12
** GM Release: 2016.1
**************************************************************
** Change History
**************************************************************
** CID	Date		Author	WI			Description
** 001	2015.10.12	CBB		B-08607		adding post action delete
*************************************************************/

CREATE proc int.procDeleteIntegrationConfig 
	@configID uniqueidentifier,
	@isExecuting bit = 0
as

if @isExecuting = 1
	begin
		-- This part could return multiple files
		--declare @DataSourceID uniqueidentifier = (select SourceFileID from [dbo].[IntSourceFile] where ConfigID=@configID)

		delete from [dbo].[IntDataInterfaceMap] 
		where SourceColumnID in 
			(
				select SourceColumnID 
				from [dbo].[IntSourceField] 
				where 
					DataSourceID in 
						(
							select TransformationID 
							from [dbo].[IntTransformation] 
							where ConfigID=@configID
						)
					or DataSourceID in 
						(
							select SourceFileID 
							from [dbo].[IntSourceFile] 
							where ConfigID=@configID
						)
			)

		delete from [dbo].[IntSourceField] 
		where 
			DataSourceID in 
				(
					select TransformationID 
					from [dbo].[IntTransformation] 
					where ConfigID=@configID
				)
			or DataSourceID in 
				(
					select SourceFileID 
					from [dbo].[IntSourceFile] 
					where ConfigID=@configID
				)

		--CID 1 begin - delete post actions--------------------------------------------------
		delete from [dbo].[IntPostAction] 
		where ConfigID=@configID
		--CID 1 end -------------------------------------------------------------------------

		delete from [dbo].[IntTransformationLink] 
		where TargetDataSourceID in
			(
				select TransformationID 
				from [dbo].[IntTransformation] 
				where ConfigID=@configID
			)

		delete from [dbo].[IntConfigFramework] 
		where ConfigID=@configID

		delete from [dbo].[IntConfigResponse] 
		where ConfigID=@configID

		delete from [dbo].[IntSourceFileLocation] 
		where 
			SourceFileID in 
				(
					select SourceFileID 
					from [dbo].[IntSourceFile] 
					where ConfigID=@configID
				)

		delete from [dbo].[IntTransformation]
		where ConfigID=@configID

		delete from [dbo].[IntSourceFile]
		where ConfigID=@configID

		delete from [dbo].[IntConfig]
		where ConfigID=@configID

	end

RETURN
GO


---------------------------------------------

-- int.procDeleteIntegrationData
create proc [int].[procDeleteIntegrationData]
AS
BEGIN

    --TRUNCATE ALL IMPORT TABLES
    declare crsCursor CURSOR LOCAL FAST_FORWARD FOR
        select 'truncate table ' + '[int].[' + ObjectName + '];
        DBCC CHECKIDENT (''int.' + ObjectName + ''', RESEED, 1)' 
        from viewsystables t where schemaname = 'int' and (objectname like '%Import%' or ObjectName like 'Fact%') 
        and t.ObjectID not in (
            select t.object_id from sys.tables t
            inner join sys.schemas s on t.schema_id=s.schema_id
            inner join sys.foreign_keys fk on t.object_id=fk.referenced_object_id
            )
        order by objectname
    open crsCursor;

    DECLARE @sql varchar(1000) --This was the wrong data type

    FETCH NEXT FROM crsCursor into @sql
    WHILE (@@FETCH_STATUS = 0) 
        BEGIN
            print @sql
            exec (@sql);
            FETCH NEXT FROM crsCursor into @sql
        END
    close crsCursor;
    DEALLOCATE crsCursor;
    
    -- delete tables that have an FK reference to them
    declare crsCursor CURSOR LOCAL FAST_FORWARD FOR
        select 'delete from ' + '[int].[' + ObjectName + '];
        DBCC CHECKIDENT (''int.' + ObjectName + ''', RESEED, 1)' 
        from viewsystables t where schemaname = 'int' and (objectname like '%Import%' or ObjectName like 'Fact%') 
        and t.ObjectID in (
            select t.object_id from sys.tables t
            inner join sys.schemas s on t.schema_id=s.schema_id
            inner join sys.foreign_keys fk on t.object_id=fk.referenced_object_id
            )
        order by objectname
    open crsCursor;
    FETCH NEXT FROM crsCursor into @sql
    WHILE (@@FETCH_STATUS = 0) 
        BEGIN
            print @sql
            exec (@sql);
            FETCH NEXT FROM crsCursor into @sql
        END
    close crsCursor;
    DEALLOCATE crsCursor;
    
    --TRUNCATE DATA CONFIGURATION HISTORY
    Truncate table [dbo].[IntTransaction]
    Truncate table [dbo].[IntTransactionData]
    Truncate table [dbo].[IntNotification]
    
    --Rebuild Indexes and Update Statistics
    exec [int].[procOptimizationRebuildIndexesData]

END
RETURN
GO


---------------------------------------------

-- int.procDropTempTables
Create procedure [int].[procDropTempTables] as

declare @schema varchar(25) = 'int';
declare @tablefilter varchar(50) = 'Temp%';
declare crsCursor CURSOR LOCAL FAST_FORWARD FOR
	select t.name from sys.tables t
		inner join sys.schemas s on s.schema_id = t.schema_id
	where s.name = @schema and t.name like @tablefilter
	
OPEN crsCursor;
DECLARE @tablename varchar(200)
FETCH NEXT FROM crsCursor into @tablename
WHILE (@@FETCH_STATUS = 0) 
	BEGIN
		PRINT @tablename
		exec procSysDropTable @schema, @tablename
		FETCH NEXT FROM crsCursor into @tablename
	END
CLOSE crsCursor;
DEALLOCATE crsCursor;

RETURN
GO


---------------------------------------------

-- int.procGetImportUnitsDollarsCalc
CREATE PROCEDURE [int].[procGetImportUnitsDollarsCalc](
	@TransactionID As Int,
	@SchemaName As varchar(50),
	@TableName As varchar(100)
)
AS
BEGIN
	DECLARE @FinalScript NVARCHAR(MAX), 
		@Value VARCHAR(200) = '',
		@Dollars decimal(19,4) = 0,
		@Units decimal(19,4) = 0


	DECLARE @HasUnitType bit = dbo.ColumnExists(@SchemaName,@TableName,'UnitTypeID')

	DECLARE @DollarsType int 
	SELECT @DollarsType = UnitTypeID FROM fw.DimUnitType WHERE Name = 'Dollars'

	DECLARE @UnitsType int 
	SELECT @UnitsType = UnitTypeID FROM fw.DimUnitType WHERE Name = 'Units'

	IF(dbo.ColumnExists(@SchemaName,@TableName,'Value') = 1)
	BEGIN
		SET @Value = 'Value' 
	END

	IF(dbo.ColumnExists(@SchemaName,@TableName,'Amount') = 1 And @Value='')
	BEGIN
		SET @Value = 'Amount' 
	END

	IF(dbo.ColumnExists(@SchemaName,@TableName,'Total') = 1 And @Value='')
	BEGIN
		SET @Value = 'Total' 
	END

	IF(@Value = '')
	BEGIN
		Select 0 As 'Dollars', 0 As 'Units'
		RETURN
	END

	SELECT @FinalScript = 'SELECT @Result=sum(' + @Value + ') FROM ' + @SchemaName + '.' + @TableName + ' WHERE TransactionID=' + CAST(@TransactionID As varchar(20))

	print @Dollars

	IF @Value = 'Total'
	BEGIN
		exec sp_executesql @FinalScript, N'@Result decimal(19,4) OUTPUT', @Dollars output

		IF(dbo.ColumnExists(@SchemaName,@TableName,'Quantity') = 0)
		BEGIN
			Select IsNull(@Dollars, 0) As 'Dollars', 0 As 'Units'
			RETURN
		END

		DECLARE @QuantityScript NVARCHAR(MAX) = 'SELECT @Result=sum(Quantity) FROM ' + @SchemaName + '.' + @TableName + ' WHERE TransactionID=' + CAST(@TransactionID As varchar(20))
		exec sp_executesql @QuantityScript, N'@Result decimal(19,4) OUTPUT', @Units output

		Select IsNull(@Dollars, 0) As 'Dollars', IsNull(@Units, 0) As 'Units'
		RETURN
	END

	IF (@HasUnitType = 1) 
		BEGIN
			DECLARE @CurrScript NVARCHAR(MAX) = @FinalScript + ' AND UnitTypeID=' + CAST(@DollarsType As varchar(20))
			exec sp_executesql @CurrScript, N'@Result decimal(19,4) OUTPUT', @Dollars output
			SET @CurrScript = @FinalScript + ' AND UnitTypeID<>' + CAST(@DollarsType As varchar(20))
			exec sp_executesql @CurrScript, N'@Result decimal(19,4) OUTPUT', @Units output
		END
	ELSE
		BEGIN
			exec sp_executesql @FinalScript, N'@Result decimal(19,4) OUTPUT', @Dollars output
		END
	
	Select IsNull(@Dollars, 0) As 'Dollars', IsNull(@Units, 0) As 'Units'
END
GO


---------------------------------------------

-- int.procImportAcceptedTableDeleteDataForTransaction
/************************************************************
** Author: lcorbeille
** Create Date: 2022-06-14
** Description: Removes data out of accepted table to optimize New Member Creation and Sampling for Data loads
** Last Modified: 2022-06-14
** GM Release: 2022.23
**************************************************************
** Change History
**************************************************************
** CID		Date		Author		WI		Description
** 1              2022-06-14  rbl               Creating proc that can be used as post action to clean up accepted tables and optimize new member creation
*************************************************************/
CREATE PROC [int].[procImportAcceptedTableDeleteDataForTransaction]
	@TransactionGUID uniqueidentifier
AS

DECLARE @TransactionID VARCHAR(10) = (SELECT TransactionID FROM dbo.IntTransaction WHERE TransactionGUID=@transactionguid);

IF (@TransactionID IS NULL) RETURN; --shouldn't happen

SELECT CAST(0 AS smallint) AS IsProcessed,'DELETE FROM ['+x.TABLE_SCHEMA+'].['+x.TABLE_NAME+'] WHERE TransactionID=' AS QueryTextStub
INTO #QueryStubs
FROM INFORMATION_SCHEMA.TABLES x
WHERE
	x.TABLE_SCHEMA='int' 
	AND x.TABLE_NAME LIKE 'Import%Accepted' 
	AND LEN(x.TABLE_NAME)=52
	AND '['+x.TABLE_SCHEMA+'].['+x.TABLE_NAME+']' IN (
		SELECT '[int].[Import_'+REPLACE(CAST(s.DataInterfaceSectionID AS CHAR(36)),'-','_')+'_Accepted]'
		FROM
			dbo.IntTransaction t
			INNER JOIN dbo.IntConfig c ON t.ConfigID=c.ConfigID
			INNER JOIN dbo.IntDataInterfaceSection s ON c.DataInterfaceID=s.DataInterfaceID
		WHERE t.TransactionGUID=@TransactionGUID
		)

DECLARE @QueryStub VARCHAR(450);
DECLARE @SQL VARCHAR(450);

WHILE EXISTS (SELECT TOP 1 NULL FROM #QueryStubs WHERE IsProcessed=0)
BEGIN
	
	SET @QueryStub = (SELECT TOP 1 QueryTextStub FROM #QueryStubs WHERE IsProcessed=0);
	SET @SQL = @QueryStub+@TransactionID;
	EXEC (@SQL);
	--PRINT @SQL;

UPDATE #QueryStubs SET IsProcessed=1 WHERE QueryTextStub=@QueryStub

END
GO


---------------------------------------------

-- int.procImportCleanup
CREATE PROCEDURE [int].[procImportCleanup]
	-- Add the parameters for the stored procedure here
	@IsWeekly As Bit = 1
AS
BEGIN
	
	DECLARE @BatchDeleteSQLTemplate VARCHAR(MAX)
	DECLARE @FinalScript VARCHAR(MAX)
	DECLARE @DateDiffNum INT
	
	SET @DateDiffNum = -90
	
	IF @IsWeekly = 1
	BEGIN
		SET @DateDiffNum = -21
	END

	SET @BatchDeleteSQLTemplate = '
	CREATE TABLE ##~CurrTempTable~# (TransactionGuid UNIQUEIDENTIFIER PRIMARY KEY)

	DECLARE @BatchSize_#~CurrTempTable~# INT
	SET @BatchSize_#~CurrTempTable~# = 5000

	INSERT INTO ##~CurrTempTable~# VALUES #~TransactionGUIDList~#

	WHILE @BatchSize_#~CurrTempTable~# <> 0
	BEGIN
		DELETE TOP (@BatchSize_#~CurrTempTable~#) FROM #~CurrentImportTableName~# WHERE TransactionGUID IN ( SELECT * FROM ##~CurrTempTable~# )
		SET @BatchSize_#~CurrTempTable~# = @@ROWCOUNT
	END

	DROP TABLE ##~CurrTempTable~#'

	SELECT @FinalScript = COALESCE(@FinalScript + ';', '') + TableDeleteScript
	FROM 
	(
		SELECT REPLACE(REPLACE(REPLACE(@BatchDeleteSQLTemplate,'#~CurrTempTable~#',TempTableName),'#~TransactionGUIDList~#',InFilterList),'#~CurrentImportTableName~#',ImportTableName) As TableDeleteScript
		FROM 
		(
			SELECT 'ImpTemp_' + REPLACE(NEWID(),'-','_') as TempTableName,'int.Import_' + REPLACE(dif.DataInterfaceSectionID,'-','_') + '_Accepted'  AS ImportTableName , dbo.STRAGGR('(''' + CAST(vit.TransactionGUID AS VARCHAR(100)) + ''')', ',','') As InFilterList
			FROM dbo.viewIntTransaction vit
			INNER JOIN [dbo].[IntConfig] ic ON vit.ConfigID = ic.ConfigID
			INNER JOIN [dbo].[IntDataInterfaceSection] dif ON dif.DataInterfaceID = ic.DataInterfaceID
			WHERE vit.StartTimeUtc <= DATEADD(DAY,@DateDiffNum,GETUTCDATE())
			AND OBJECT_ID('int.Import_' + REPLACE(dif.DataInterfaceSectionID,'-','_') + '_Accepted', 'U') IS NOT NULL
			GROUP BY DataInterfaceSectionID 
		) A
	) B
	
	PRINT @FinalScript
	
	EXEC(@FinalScript)
	
END

RETURN
GO


---------------------------------------------

-- int.procManualIntFactGLTransactionDeletion
CREATE procedure int.procManualIntFactGLTransactionDeletion (
	@TransGUID uniqueidentifier
)
as
begin
	
	--Delete data from int.FactGL table
	delete from [int].[FactGL]
	where HistoryItemGUID=@TransGUID
	
	--Delete the transaction from the transaction tables
	exec [dbo].[procIntTransactionDelete] @TransactionGUID = @TransGUID
	-- @TransactionGUID (uniqueidentifier)
	
end
GO


---------------------------------------------

-- int.procOptimizationRebuildIndexesData
CREATE proc [int].[procOptimizationRebuildIndexesData] as

/************************************************************
** Author: akowalski
** Create Date: 2013-02-18
** Description: Finds all fact tables in the INT schemas and rebuilds indexes, for use after large imports/deletes
** Last Modified: 2013-02-18
** GM Release: 2013-03-12
**************************************************************
** Change History
**************************************************************
** CID		Date		Author	WI		Description
** 1		2013-02-19	DK		56588	Adding update statistics command
**
*************************************************************/


SET NOCOUNT ON;

	DECLARE @SCHEMA nvarchar(256)
	DECLARE @FactTableName nvarchar(256)
	DECLARE @SQL nvarchar(1024)
	DECLARE FactTableCursor CURSOR FOR 
	select t.name, (select name from sys.schemas where schema_id = t.schema_id) from sys.tables t where t.schema_id in(select schema_id from sys.schemas where name in('int')) and (t.name like 'fact%' and t.name not like '%map')
		and t.object_ID not in (
		select distinct t.object_id from sys.tables t
		inner join sys.indexes i on t.object_id=i.object_id
		inner join sys.partitions p on t.object_id=p.object_ID and i.index_id=p.index_id
		where p.data_compression<>0
		) order by t.name
	open FactTableCursor

	FETCH NEXT FROM FactTableCursor 
	INTO @FactTableName, @SCHEMA
	WHILE @@FETCH_STATUS = 0
	BEGIN

		--=================== BEGIN CID 1 =====================
		set @SQL = 'alter index all on ' + @SCHEMA + '.' + @FactTableName + ' REBUILD WITH (FILLFACTOR=80)
		update statistics ' + @SCHEMA + '.' + @FactTableName + ' WITH FULLSCAN'
		--=================== END CID 1 =======================
	    --print @SQL
	    EXECUTE sp_executesql @SQL 
	    FETCH NEXT FROM FactTableCursor INTO @FactTableName, @SCHEMA
	END

	CLOSE FactTableCursor
	DEALLOCATE FactTableCursor
	
	DECLARE FactTableCursor CURSOR FOR 
	select t.name, (select name from sys.schemas where schema_id = t.schema_id) from sys.tables t where t.schema_id in(select schema_id from sys.schemas where name in('int')) and (t.name like 'fact%' and t.name not like '%map')
		and t.object_ID not in (
		select distinct t.object_id from sys.tables t
		inner join sys.indexes i on t.object_id=i.object_id
		inner join sys.partitions p on t.object_id=p.object_ID and i.index_id=p.index_id
		where p.data_compression=0
		) order by t.name
	open FactTableCursor

	FETCH NEXT FROM FactTableCursor 
	INTO @FactTableName, @SCHEMA
	WHILE @@FETCH_STATUS = 0
	BEGIN

		--=================== BEGIN CID 1 =====================
		set @SQL = 'alter index all on ' + @SCHEMA + '.' + @FactTableName + ' REBUILD WITH (FILLFACTOR=80,DATA_COMPRESSION = PAGE)
		update statistics ' + @SCHEMA + '.' + @FactTableName + ' WITH FULLSCAN'
		--=================== END CID 1 =======================
	    --print @SQL
	    EXECUTE sp_executesql @SQL 
	    FETCH NEXT FROM FactTableCursor INTO @FactTableName, @SCHEMA
	END

	CLOSE FactTableCursor
	DEALLOCATE FactTableCursor
RETURN
GO


---------------------------------------------

-- int.procRefreshFactTableDimensionIDs
CREATE procedure [int].[procRefreshFactTableDimensionIDs]
as
/******************************************************************************
** Author: unknown
** Create Date: unknown
** Description: Used to refresh dimension IDs as part of the Refresh Data Dimension Links custom action (MR/PR use)
** Last Modified: 2016-12-19
** GM Release: 2017.1.1
*******************************************************************************
** Change History
*******************************************************************************
** CID	Date		Author	WI		Description
** 1	2016-12-19	srk	D-04980 	Adding statistic by pay period section
*******************************************************************************/

---------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------FactGL table--------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------

exec int.procRefreshFactTableIDsFactGL

---------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------FactStatistic table--------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------

exec int.procRefreshFactTableIDsFactStatistic

---------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------FactStatisticsbyPayPeriod table-------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------

exec int.procRefreshFactTableIDsFactStatisticByPayPeriod

---------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------FactPayorSummary table----------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------

exec int.procRefreshFactTableIDsFactPayorSummary

---------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------FactPhysicianSummary table------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------

exec int.procRefreshFactTableIDsFactPhysicianSummary

---------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------FactSPDirectBalAccount table----------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------

exec int.procRefreshFactTableIDsFactSPDirectBalAccount

---------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------FactSPDirectISAccount table-----------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------

exec int.procRefreshFactTableIDsFactSPDirectISAccount

---------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------FactSPDirectISPayor table-------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------

exec int.procRefreshFactTableIDsFactSPDirectISPayor

---------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------FactSPDirectISPhysician table-----------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------

exec int.procRefreshFactTableIDsFactSPDirectISPhysician	

---------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------FactSPDirectISStaffing table------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------

exec int.procRefreshFactTableIDsFactSPDirectISStaffing

---------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------FactSPDirectISRollingAccount table----------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------

exec int.procRefreshFactTableIDsFactSPDirectRollingISAccount

---------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------FactSPDirectISRollingPayor table------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------

exec int.procRefreshFactTableIDsFactSPDirectRollingISPayor

---------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------FactSPDirectISRollingPhysician table----------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------


exec int.procRefreshFactTableIDsFactSPDirectRollingISPhysician


---------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------FactSPDirectISRollingStaffing table-----------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------

exec int.procRefreshFactTableIDsFactSPDirectRollingISStaffing


---------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------FactStaffing table--------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------

exec int.procRefreshFactTableIDsFactStaffing



---------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------FactStaffingByPayPeriod table--------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------

exec int.procRefreshFactTableIDsFactStaffingByPayPeriod


---------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------FactStaffingSummary table----------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------

exec int.procRefreshFactTableIDsFactStaffingSummary	

---------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------FactCDM table----------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------

exec [int].[procRefreshFactTableIDsFactCDM] 

---------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------FactServiceLine table----------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------

exec [int].[procRefreshFactTableIDsFactServiceLine] 
--
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactCDM
CREATE procedure int.procRefreshFactTableIDsFactCDM
as

update 
	gl
set 
	gl.DepartmentID=isnull(d.departmentID,0),
	gl.ChargeCodeID=isnull(cc.ChargeCodeID,0),
	gl.AgeCohortID=isnull(ac.AgeCohortID,0),
	gl.MedicalSurgicalID=isnull(ms.MedicalSurgicalID,0),
	gl.PatientClassID=isnull(pc.PatientClassID,0),
	gl.ServiceLineID=isnull(sl.ServiceLineID,0),
	gl.UnitTypeID=isnull(ut.UnitTypeID,0),
	gl.FiscalYearID=isnull(fy.FiscalYearID,0),
	gl.TimeClassID=isnull(tc.TimeClassID,0),
	gl.FiscalMonthID=isnull(fm.FiscalMonthID,0)
from 
	[int].[FactCDM] gl
	left join [fw].[DimDepartment] d on gl.DepartmentCode=d.DepartmentCode
	left join [fw].[DimChargeCode] cc on Gl.ChargeCode=cc.ChargeCode
	left join [fw].[DimAgeCohort] ac on gl.AgeCohort=ac.code
	left join [fw].[DimMedicalSurgical] ms on Gl.MedSurg=ms.Code
	left join [fw].[DimPatientClass] pc on Gl.PatientClassCode=pc.Code
	left join [fw].[DimServiceLine] sl on gl.ServiceLine=sl.code
	left join [fw].[DimUnitType] ut on gl.UnitType=ut.name
	left join [fw].[DimFiscalYear] fy on gl.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc on gl.TimeClassCode = tc.TimeClassCode
	left join [fw].[DimFiscalMonth] fm on gl.FiscalMonthCode = fm.FiscalMonthCode


RETURN
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactFinancialServiceLineCost
/************************************************************
** Author: blewis
** Create Date: 2015-04-22
** Description: Refresh IDs on Table FactFinancialServiceLineCost
** Last Modified: 2015-04-22
** GM Release: 2015.2
**************************************************************
** Change History
**************************************************************
** CID		Date		Author	WI		Description
** 1		
**
*************************************************************/


Create Proc [int].[procRefreshFactTableIDsFactFinancialServiceLineCost]
as

Update F
Set
	ForecastDetailID=isnull(fd.ForecastDetailID,0)
	, EntityID=isnull(e.entityid,0)
	, FiscalMonthID=isnull(fm.FiscalMonthID,0)
	, FiscalYearID=isnull(fy.FiscalYearID,0)
	, ServiceLineID=isnull(sl.ServiceLineID,0)
	, AgeCohortID=isnull(ac.AgeCohortID,0)
	, PatientClassID=isnull(pc.PatientClassID,0)
	, MedicalSurgicalID=isnull(ms.MedicalSurgicalID,0)
	, TimeClassID=isnull(tc.TimeClassID,0)
	, UnitTypeID=isnull(ut.UnitTypeID,0)
	, DepartmentID=isnull(md.DepartmentID,0)
From [int].[FactFinancialServiceLineCost] F
left join [fw].[DimForecastDetail] fd on F.ForecastDetailCode=fd.ForecastDetailCode
left join [fw].[DimEntity] e on e.Code=f.EntityCode
left join [fw].[DimFiscalMonth] fm on fm.FiscalMonthCode=F.FiscalMonthCode
left join [fw].[DimFiscalYear] fy on fy.FiscalYearID=F.FiscalYearID
left join [fw].[DimServiceLine] sl on sl.Code=F.ServiceLineCode
left join [fw].[DimAgeCohort] ac on ac.Code=F.AgeCohortCode
left join [fw].[DimPatientClass] pc on pc.Code=F.PatientClassCode
left join [fw].[DimMedicalSurgical] ms on ms.Code=F.MedicalSurgicalCode
left join [fw].[DimTimeClass] tc on tc.TimeClassCode=F.TimeClassCode
left join [fw].[DimUnitType] ut on F.UnitTypeName=ut.Name
left join [fw].[DimDepartment] md on md.DepartmentCode=F.DepartmentCode
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactFinancialServiceLineRevenue
/************************************************************
** Author: blewis
** Create Date: 2015-04-22
** Description: Refresh IDs on Table FactFinancialServiceLineRevenue
** Last Modified: 2015-04-22
** GM Release: 2015.2
**************************************************************
** Change History
**************************************************************
** CID		Date		Author	WI		Description
** 1		
**
*************************************************************/


Create Proc [int].[procRefreshFactTableIDsFactFinancialServiceLineRevenue]
as

Update F
Set
	ForecastDetailID=isnull(fd.ForecastDetailID,0)
	, EntityID=isnull(e.entityid,0)
	, PayorGroupID=isnull(pg.PayorGroupID,0)
	, PayorID=isnull(p.PayorID,0)
	, FiscalMonthID=isnull(fm.FiscalMonthID,0)
	, FiscalYearID=isnull(fy.FiscalYearID,0)
	, ServiceLineID=isnull(sl.ServiceLineID,0)
	, AgeCohortID=isnull(ac.AgeCohortID,0)
	, PatientClassID=isnull(pc.PatientClassID,0)
	, MedicalSurgicalID=isnull(ms.MedicalSurgicalID,0)
	, TimeClassID=isnull(tc.TimeClassID,0)
From [int].[FactFinancialServiceLineRevenue] F
left join [fw].[DimForecastDetail] fd on F.ForecastDetailCode=fd.ForecastDetailCode
left join [fw].[DimEntity] e on e.Code=f.EntityCode
left join [fw].[DimPayorGroup] pg on pg.PayorGroupCode=F.PayorGroupCode
left join [fw].[DimPayor] p on p.PayorCode=F.PayorCode
left join [fw].[DimFiscalMonth] fm on fm.FiscalMonthCode=F.FiscalMonthCode
left join [fw].[DimFiscalYear] fy on fy.FiscalYearID=F.FiscalYearID
left join [fw].[DimServiceLine] sl on sl.Code=F.ServiceLineCode
left join [fw].[DimAgeCohort] ac on ac.Code=F.AgeCohortCode
left join [fw].[DimPatientClass] pc on pc.Code=F.PatientClassCode
left join [fw].[DimMedicalSurgical] ms on ms.Code=F.MedSurgCode
left join [fw].[DimTimeClass] tc on tc.TimeClassCode=F.TimeClassCode
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactGL
Create procedure int.procRefreshFactTableIDsFactGL
as

update 
	gl
set 
	gl.DepartmentID=isnull(d.departmentID,0),
	gl.AccountID=isnull(a.AccountID,0),
	gl.FiscalYearID=isnull(fy.FiscalYearID,0),
	gl.TimeClassID=isnull(tc.TimeClassID,0),
	gl.FiscalMonthID=isnull(fm.FiscalMonthID,0)
from 
	[int].[FactGL] gl
	left join [fw].[DimDepartment] d on gl.DepartmentCode=d.DepartmentCode
	left join [fw].[DimAccount] a on gl.AccountCode=a.AccountCode
	left join [fw].[DimFiscalYear] fy on gl.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc on gl.TimeClassCode = tc.TimeClassCode
	left join [fw].[DimFiscalMonth] fm on gl.FiscalMonthCode = fm.FiscalMonthCode
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactImportProvider
Create procedure int.procRefreshFactTableIDsFactImportProvider
as

update 
	p
set 
	p.DepartmentID=isnull(d.departmentID,0),
	p.ProviderID=isnull(pt.ProviderID,0),
	p.OBForecastDetailID=isnull(ob.OBForecastDetailID,0),
	p.FiscalYearID=isnull(fy.FiscalYearID,0),
	p.TimeClassID=isnull(tc.TimeClassID,0),
	p.FiscalMonthID=isnull(fm.FiscalMonthID,0)
from 
	[int].[FactImportProvider] p
	left join [fw].[DimDepartment] d on p.DepartmentCode=d.DepartmentCode
	left join [fw].[DimProvider] pt on p.ProviderCode=pt.ProviderCode
	left join [ob].[DimOBForecastDetail] ob on p.AccountRollup=ob.Code
	left join [fw].[DimFiscalYear] fy on p.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc on p.TimeClassCode = tc.TimeClassCode
	left join [fw].[DimFiscalMonth] fm on p.FiscalMonthCode = fm.FiscalMonthCode
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactPayorSummary
Create procedure int.procRefreshFactTableIDsFactPayorSummary
as

update 
	payor
set 
	payor.DepartmentID=isnull(d.departmentID,0),
	payor.PatientTypeRollupID=isnull(pt.PatientTypeRollupID,0),
	payor.AccountRollupID=isnull(ar.AccountRollupID,0),
	payor.PayorGroupID=isnull(p.PayorGroupID,0),
	payor.FiscalYearID=isnull(fy.FiscalYearID,0),
	payor.TimeClassID=isnull(tc.TimeClassID,0),
	payor.UnitTypeID=isnull(ut.UnitTypeID,0),
	payor.FiscalMonthID=isnull(fm.FiscalMonthID,0)
from 
	[int].[FactPayorSummary] payor
	left join [fw].[DimDepartment] d on payor.DepartmentCode=d.DepartmentCode
	left join [fw].[DimPatientTypeRollup] pt on payor.PatientTypeRollupCode=pt.Name
	left join [sp].[DimAccountRollup] ar on payor.AccountRollupCode=ar.Name
	left join [fw].[DimPayorGroup] p on payor.PayorGroupCode=p.Name
	left join [fw].[DimFiscalYear] fy on payor.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc on payor.TimeClassCode = tc.TimeClassCode
	left join [fw].[DimUnitType] ut on payor.UnitType = ut.Name
	left join [fw].[DimFiscalMonth] fm on payor.FiscalMonthCode = fm.FiscalMonthCode
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactPhysicianSummary
Create procedure int.procRefreshFactTableIDsFactPhysicianSummary
as

update 
	physician
set 
	physician.DepartmentID=isnull(d.departmentID,0),
	physician.PatientTypeRollupID=isnull(pt.PatientTypeRollupID,0),
	physician.AccountRollupID=isnull(ar.AccountRollupID,0),
	physician.PhysicianGroupID=isnull(p.physicianGroupID,0),
	physician.FiscalYearID=isnull(fy.FiscalYearID,0),
	physician.TimeClassID=isnull(tc.TimeClassID,0),
	physician.UnitTypeID=isnull(ut.UnitTypeID,0),
	physician.FiscalMonthID=isnull(fm.FiscalMonthID,0)
from 
	[int].[FactPhysicianSummary] physician
	left join [fw].[DimDepartment] d on physician.DepartmentCode=d.DepartmentCode
	left join [fw].[DimPatientTypeRollup] pt on physician.PatientTypeRollupCode=pt.Name
	left join [sp].[DimAccountRollup] ar on physician.AccountRollupCode=ar.Name
	left join [fw].[DimPhysicianGroup] p on physician.PhysicianGroupCode=p.Name
	left join [fw].[DimFiscalYear] fy on physician.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc on physician.TimeClassCode = tc.TimeClassCode
	left join [fw].[DimUnitType] ut on physician.UnitType = ut.Name
	left join [fw].[DimFiscalMonth] fm on physician.FiscalMonthCode = fm.FiscalMonthCode
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactSPDirectBalAccount
Create procedure int.procRefreshFactTableIDsFactSPDirectBalAccount
as

update 
	dbal
set 
	dbal.SPLongRangePlanID=isnull(lrp.SPLongRangePlanID,0),
	dbal.AccountRollupID=isnull(ar.AccountRollupID,0),
	dbal.SPCapitalRollupID=isnull(cap.SPCapitalRollupID,0),
	dbal.SPDebtIssuanceID=isnull(deb.SPDebtIssuanceID,0),
	dbal.FiscalYearID=isnull(fy.FiscalYearID,0),
	dbal.TimeClassID=isnull(tc.TimeClassID,0),
	dbal.UnitTypeID=isnull(ut.UnitTypeID,0)
from 
	[int].[FactSPDirectBalAccount] dbal
	left join [sp].[viewDimSPLongRangePlan] lrp on dbal.SPLongRangePlanName=lrp.Name
	left join [sp].[DimAccountRollup] ar on dbal.SPAccountRollupName=ar.Name
	left join [sp].[DimSPCapitalRollup] cap on dbal.SPCapitalRollupName=cap.Name
	left join [sp].[DimSPDebtIssuance] deb on dbal.SPDebtIssuanceName=deb.Name
	left join [fw].[DimFiscalYear] fy on dbal.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc on dbal.TimeClassCode = tc.TimeClassCode
	left join [fw].[DimUnitType] ut on dbal.UnitType = ut.Name
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactSPDirectISAccount
Create procedure int.procRefreshFactTableIDsFactSPDirectISAccount
as

update 
	disa
set 
	disa.SPLongRangePlanID=isnull(lrp.SPLongRangePlanID,0),
	disa.AccountRollupID=isnull(ar.AccountRollupID,0),
	disa.FiscalYearID=isnull(fy.FiscalYearID,0),
	disa.TimeClassID=isnull(tc.TimeClassID,0),
	disa.UnitTypeID=isnull(ut.UnitTypeID,0)
from 
	[int].[FactSPDirectISAccount] disa
	left join [sp].[viewDimSPLongRangePlan] lrp on disa.SPLongRangePlanName=lrp.Name
	left join [sp].[DimAccountRollup] ar on disa.SPAccountRollupName=ar.Name
	left join [fw].[DimFiscalYear] fy on disa.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc on disa.TimeClassCode = tc.TimeClassCode
	left join [fw].[DimUnitType] ut on disa.UnitType = ut.Name
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactSPDirectISPayor
Create procedure int.procRefreshFactTableIDsFactSPDirectISPayor
as

update 
	disp
set 
	disp.SPLongRangePlanID=isnull(lrp.SPLongRangePlanID,0),
	disp.PatientTypeRollupID=isnull(pt.PatientTypeRollupID,0),
	disp.AccountRollupID=isnull(ar.AccountRollupID,0),
	disp.PayorGroupID=isnull(p.PayorGroupID,0),
	disp.FiscalYearID=isnull(fy.FiscalYearID,0),
	disp.TimeClassID=isnull(tc.TimeClassID,0),
	disp.UnitTypeID=isnull(ut.UnitTypeID,0)
from 
	[int].[FactSPDirectISPayor] disp
	left join [sp].[viewDimSPLongRangePlan] lrp on disp.SPLongRangePlanName=lrp.Name
	left join [fw].[DimPatientTypeRollup] pt on disp.PatientTypeRollupCode=pt.Name
	left join [sp].[DimAccountRollup] ar on disp.SPAccountRollupName=ar.Name
	left join [fw].[DimPayorGroup] p on disp.PayorGroupCode=p.Name
	left join [fw].[DimFiscalYear] fy on disp.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc on disp.TimeClassCode = tc.TimeClassCode
	left join [fw].[DimUnitType] ut on disp.UnitType = ut.Name
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactSPDirectISPhysician
Create procedure int.procRefreshFactTableIDsFactSPDirectISPhysician
as

update 
	disph
set 
	disph.SPLongRangePlanID=isnull(lrp.SPLongRangePlanID,0),
	disph.PatientTypeRollupID=isnull(pt.PatientTypeRollupID,0),
	disph.AccountRollupID=isnull(ar.AccountRollupID,0),
	disph.PhysicianGroupID=isnull(p.PhysicianGroupID,0),
	disph.FiscalYearID=isnull(fy.FiscalYearID,0),
	disph.TimeClassID=isnull(tc.TimeClassID,0),
	disph.UnitTypeID=isnull(ut.UnitTypeID,0)
from 
	[int].[FactSPDirectISPhysician] disph
	left join [sp].[viewDimSPLongRangePlan] lrp on disph.SPLongRangePlanName=lrp.Name
	left join [fw].[DimPatientTypeRollup] pt on disph.PatientTypeRollupCode=pt.Name
	left join [sp].[DimAccountRollup] ar on disph.SPAccountRollupName=ar.Name
	left join [fw].[DimPhysicianGroup] p on disph.PhysicianGroupCode=p.Name
	left join [fw].[DimFiscalYear] fy on disph.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc on disph.TimeClassCode = tc.TimeClassCode
	left join [fw].[DimUnitType] ut on disph.UnitType = ut.Name
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactSPDirectISStaffing
Create procedure int.procRefreshFactTableIDsFactSPDirectISStaffing
as

update 
	diss
set 
	diss.SPLongRangePlanID=isnull(lrp.SPLongRangePlanID,0),
	diss.AccountRollupID=isnull(ar.AccountRollupID,0),
	diss.JobCodeGroupID=isnull(p.JobCodeGroupID,0),
	diss.FiscalYearID=isnull(fy.FiscalYearID,0),
	diss.TimeClassID=isnull(tc.TimeClassID,0),
	diss.UnitTypeID=isnull(ut.UnitTypeID,0)
from 
	[int].[FactSPDirectISStaffing] diss
	left join [sp].[viewDimSPLongRangePlan] lrp on diss.SPLongRangePlanName=lrp.Name
	left join [sp].[DimAccountRollup] ar on diss.SPAccountRollupName=ar.Name
	left join [fw].[DimJobCodeGroup] p on diss.JobCodeGroup=p.Name
	left join [fw].[DimFiscalYear] fy on diss.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc on diss.TimeClassCode = tc.TimeClassCode
	left join [fw].[DimUnitType] ut on diss.UnitType = ut.Name
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactSPDirectRollingISAccount
Create procedure int.procRefreshFactTableIDsFactSPDirectRollingISAccount
as

update 
	drola
set 
	drola.SPRollingForecastPlanID=isnull(lrp.SPRollingForecastPlanID,0),
	drola.AccountRollupID=isnull(ar.AccountRollupID,0),
	drola.FiscalYearID=isnull(fy.FiscalYearID,0),
	drola.TimeClassID=isnull(tc.TimeClassID,0),
	drola.UnitTypeID=isnull(ut.UnitTypeID,0)
from 
	[int].[FactSPDirectRollingISAccount] drola
	left join [sp].[viewDimSPRollingForecastPlan] lrp on drola.SPRollingForecastPlanName=lrp.Name
	left join [sp].[DimAccountRollup] ar on drola.SPAccountRollupName=ar.Name
	left join [fw].[DimFiscalYear] fy on drola.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc on drola.TimeClassCode = tc.TimeClassCode
	left join [fw].[DimUnitType] ut on drola.UnitType = ut.Name
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactSPDirectRollingISPayor
Create procedure int.procRefreshFactTableIDsFactSPDirectRollingISPayor
as

update 
	drolp
set 
	drolp.SPRollingForecastPlanID=isnull(lrp.SPRollingForecastPlanID,0),
	drolp.PatientTypeRollupID=isnull(pt.PatientTypeRollupID,0),
	drolp.AccountRollupID=isnull(ar.AccountRollupID,0),
	drolp.PayorGroupID=isnull(p.PayorGroupID,0),
	drolp.FiscalYearID=isnull(fy.FiscalYearID,0),
	drolp.TimeClassID=isnull(tc.TimeClassID,0),
	drolp.UnitTypeID=isnull(ut.UnitTypeID,0)
from 
	[int].[FactSPDirectRollingISPayor] drolp
	left join [sp].[viewDimSPRollingForecastPlan] lrp on drolp.SPRollingForecastPlanName=lrp.Name
	left join [fw].[DimPatientTypeRollup] pt on drolp.PatientTypeRollupCode=pt.Name
	left join [sp].[DimAccountRollup] ar on drolp.SPAccountRollupName=ar.Name
	left join [fw].[DimPayorGroup] p on drolp.PayorGroupCode=p.Name
	left join [fw].[DimFiscalYear] fy on drolp.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc on drolp.TimeClassCode = tc.TimeClassCode
	left join [fw].[DimUnitType] ut on drolp.UnitType = ut.Name
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactSPDirectRollingISPhysician
Create procedure int.procRefreshFactTableIDsFactSPDirectRollingISPhysician
as


update 
	drolph
set 
	drolph.SPRollingForecastPlanID=isnull(lrp.SPRollingForecastPlanID,0),
	drolph.PatientTypeRollupID=isnull(pt.PatientTypeRollupID,0),
	drolph.AccountRollupID=isnull(ar.AccountRollupID,0),
	drolph.PhysicianGroupID=isnull(p.PhysicianGroupID,0),
	drolph.FiscalYearID=isnull(fy.FiscalYearID,0),
	drolph.TimeClassID=isnull(tc.TimeClassID,0),
	drolph.UnitTypeID=isnull(ut.UnitTypeID,0)
from 
	[int].[FactSPDirectRollingISPhysician] drolph
	left join [sp].[viewDimSPRollingForecastPlan] lrp on drolph.SPRollingForecastPlanName=lrp.Name
	left join [fw].[DimPatientTypeRollup] pt on drolph.PatientTypeRollupCode=pt.Name
	left join [sp].[DimAccountRollup] ar on drolph.SPAccountRollupName=ar.Name
	left join [fw].[DimPhysicianGroup] p on drolph.PhysicianGroupCode=p.Name
	left join [fw].[DimFiscalYear] fy on drolph.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc on drolph.TimeClassCode = tc.TimeClassCode
	left join [fw].[DimUnitType] ut on drolph.UnitType = ut.Name
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactSPDirectRollingISStaffing
Create procedure int.procRefreshFactTableIDsFactSPDirectRollingISStaffing
as


update 
	drols
set 
	drols.SPRollingForecastPlanID=isnull(lrp.SPRollingForecastPlanID,0),
	drols.AccountRollupID=isnull(ar.AccountRollupID,0),
	drols.JobCodeGroupID=isnull(p.JobCodeGroupID,0),
	drols.FiscalYearID=isnull(fy.FiscalYearID,0),
	drols.TimeClassID=isnull(tc.TimeClassID,0),
	drols.UnitTypeID=isnull(ut.UnitTypeID,0)
from 
	[int].[FactSPDirectRollingISStaffing] drols
	left join [sp].[viewDimSPRollingForecastPlan] lrp on drols.SPRollingForecastPlanName=lrp.Name
	left join [sp].[DimAccountRollup] ar on drols.SPAccountRollupName=ar.Name
	left join [fw].[DimJobCodeGroup] p on drols.JobCodeGroup=p.Name
	left join [fw].[DimFiscalYear] fy on drols.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc on drols.TimeClassCode = tc.TimeClassCode
	left join [fw].[DimUnitType] ut on drols.UnitType = ut.Name
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactServiceLine
CREATE procedure int.procRefreshFactTableIDsFactServiceLine
as

update 
	gl
set 
	gl.AgeCohortID=isnull(ac.AgeCohortID,0),
	gl.MedicalSurgicalID=isnull(ms.MedicalSurgicalID,0),
	gl.PatientClassID=isnull(pc.PatientClassID,0),
	gl.ServiceLineID=isnull(sl.ServiceLineID,0),
	gl.OBForecastDetailID=isnull(fd.OBForecastDetailID,0),
	gl.FiscalYearID=isnull(fy.FiscalYearID,0),
	gl.TimeClassID=isnull(tc.TimeClassID,0),
	gl.FiscalMonthID=isnull(fm.FiscalMonthID,0),
	gl.PayorID  =isnull(p.PayorID,0),
	gl.PayorGroupID =isnull(pg.PayorGroupID,0),
	gl.DepartmentID  =isnull(d.DepartmentID,0)
from 
	[int].[FactServiceLine] gl
	left join [fw].[DimAgeCohort] ac on gl.AgeCohort=ac.code
	left join [fw].[DimMedicalSurgical] ms on Gl.MedSurg=ms.Code
	left join [fw].[DimPatientClass] pc on Gl.PatientClassCode=pc.Code
	left join [fw].[DimServiceLine] sl on gl.ServiceLine=sl.name
	left join [ob].[DimOBForecastDetail] fd on fd.Name=gl.forecastdetail
	left join [fw].[DimFiscalYear] fy on gl.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc on gl.TimeClassCode = tc.TimeClassCode
	left join [fw].[DimFiscalMonth] fm on gl.FiscalMonthCode = fm.FiscalMonthCode
	left join [fw].[DimPayor] p on gl.PayorCode  = p.PayorCode 
	left join [fw].[DimPayorGroup]  pg on gl.PayorGroupCode  = pg.PayorGroupCode 
	left join [fw].[DimDepartment] d on gl.DepartmentCode  = d.DepartmentCode
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactStaffing
CREATE procedure [int].[procRefreshFactTableIDsFactStaffing]
as

update 
	staffing
set 
	staffing.DepartmentID=isnull(d.departmentID,0),
	staffing.JobCodeID=isnull(j.JobCodeID,0),
	staffing.PayCodeID=isnull(p.PayCodeID,0),
	staffing.FiscalYearID=isnull(fy.FiscalYearID,0),
	staffing.TimeClassID=isnull(tc.TimeClassID,0),
	staffing.UnitTypeID=isnull(ut.UnitTypeID,0),
	staffing.EmployeeID=isnull(e.EmployeeID,0),
	staffing.FiscalMonthID=isnull(fm.FiscalMonthID,0)
from 
	[int].[FactStaffing] staffing
	left join [fw].[DimDepartment] d on staffing.DepartmentCode=d.DepartmentCode
	left join [fw].[DimJobCode] j on staffing.JobCode=j.JobCode
	left join [fw].[DimPayCode] p on staffing.PayCode=p.PayCode
	left join [fw].[DimFiscalYear] fy on staffing.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc on staffing.TimeClassCode = tc.TimeClassCode
	left join [fw].[DimUnitType] ut on staffing.UnitType = ut.Name
	left join [fw].[DimEmployee] e on staffing.EmployeeCode=e.Code
	left join [fw].[DimFiscalMonth] fm on staffing.FiscalMonthCode = fm.FiscalMonthCode
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactStaffingByPayPeriod
CREATE procedure [int].[procRefreshFactTableIDsFactStaffingByPayPeriod]
	@IsDebugOnly bit = 0
as
begin

--------------------------------------------------------------------------------------------------
-- Logging
--------------------------------------------------------------------------------------------------
	declare @logdesc nvarchar(100)
	select @logdesc = 
		case @IsDebugOnly
			when 1 then 'Debug only - Refressh Staffing By Pay Period Fact table IDs'
			else 'Refressh Staffing By Pay Period Fact table IDs'
		end

	declare @higuid uniqueidentifier
	exec procLogScript @logdesc, @higuid output

	print 'HistoryItemGUID = '''+cast(@higuid as varchar(36))+''''

--------------------------------------------------------------------------------------------------
-- Set SQL Column
--------------------------------------------------------------------------------------------------
	declare @SQLColumn as nvarchar(200)

	select @SQLColumn=sa.SQLColumnName
	from [dbo].[ScoreAttribute] sa
		inner join [dbo].[IntDataInterfaceField] fld
			on sa.AttributeGUID=fld.GivenScoreAttributeGUID
	where 1=1
		and fld.ScoreKeyGUID = '8fc5efa1-e270-4e75-8add-6965c16ab295'
		and fld.DataInterfaceSectionID='cdc2ef8b-987e-4ca6-a06c-22827507f5f5'

--------------------------------------------------------------------------------------------------
-- Create SQL script
--------------------------------------------------------------------------------------------------
	declare @sql nvarchar(max) = '
update staffpayperiod
set staffpayperiod.DepartmentID	= isnull(d.departmentID,0),
	staffpayperiod.JobCodeID	= isnull(j.JobCodeID,0),
	staffpayperiod.PayCodeID	= isnull(p.PayCodeID,0),
	staffpayperiod.PayPeriodID	= isnull(pp.PayPeriodID,0),
	staffpayperiod.FiscalYearID	= isnull(fy.FiscalYearID,0),
	staffpayperiod.TimeClassID	= isnull(tc.TimeClassID,0),
	staffpayperiod.UnitTypeID	= isnull(ut.UnitTypeID,0),
	staffpayperiod.EmployeeID	= isnull(e.EmployeeID,0)
from [int].[FactStaffingByPayPeriod] staffpayperiod
	left join [fw].[DimDepartment] d 
		on staffpayperiod.DepartmentCode=d.DepartmentCode
	left join [fw].[DimJobCode] j 
		on staffpayperiod.JobCode=j.JobCode
	left join [fw].[DimPayCode] p 
		on staffpayperiod.PayCode=p.PayCode
	left join [fw].[DimPayPeriod] pp 
		on staffpayperiod.PayPeriodCode = pp.'
		+ @SQLColumn
		+ '
	left join [fw].[DimFiscalYear] fy 
		on staffpayperiod.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc 
		on staffpayperiod.TimeClassCode = tc.TimeClassCode
	left join [fw].[DimUnitType] ut 
		on staffpayperiod.UnitType = ut.Name
	left join [fw].[DimEmployee] e 
		on staffpayperiod.EmployeeCode = e.Code'

	if @IsDebugOnly=1
		begin
			print(@sql)
		end
	else
		begin
			exec(@sql)
		end

end
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactStaffingSummary
Create procedure int.procRefreshFactTableIDsFactStaffingSummary
as


update 
	staff
set 
	staff.DepartmentID=isnull(d.departmentID,0),
	staff.AccountRollupID=isnull(ar.AccountRollupID,0),
	staff.JobCodeGroupID=isnull(jc.JobCodeGroupID,0),
	staff.FiscalYearID=isnull(fy.FiscalYearID,0),
	staff.TimeClassID=isnull(tc.TimeClassID,0),
	staff.UnitTypeID=isnull(ut.UnitTypeID,0),
	staff.FiscalMonthID=isnull(fm.FiscalMonthID,0)
from 
	[int].[FactStaffingSummary] staff
	left join [fw].[DimDepartment] d on staff.DepartmentCode=d.DepartmentCode
	left join [sp].[DimAccountRollup] ar on staff.AccountRollupCode=ar.Name
	left join [fw].[DimJobCodeGroup] jc on staff.JobCodeGroup=jc.Name
	left join [fw].[DimFiscalYear] fy on staff.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc on staff.TimeClassCode = tc.TimeClassCode
	left join [fw].[DimUnitType] ut on staff.UnitType = ut.Name
	left join [fw].[DimFiscalMonth] fm on staff.FiscalMonthCode = fm.FiscalMonthCode
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactStatistic
Create procedure int.procRefreshFactTableIDsFactStatistic
as

update 
	stat
set 
	stat.DepartmentID=isnull(d.departmentID,0),
	stat.AccountID=isnull(a.AccountID,0),
	stat.FiscalYearID=isnull(fy.FiscalYearID,0),
	stat.TimeClassID=isnull(tc.TimeClassID,0),
	stat.FiscalMonthID=isnull(fm.FiscalMonthID,0)
from 
	[int].[FactStatistic] stat
	left join [fw].[DimDepartment] d on stat.DepartmentCode=d.DepartmentCode
	left join [fw].[DimAccount] a on stat.AccountCode=a.AccountCode
	left join [fw].[DimFiscalYear] fy on stat.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc on stat.TimeClassCode = tc.TimeClassCode
	left join [fw].[DimFiscalMonth] fm on stat.FiscalMonthCode = fm.FiscalMonthCode
GO


---------------------------------------------

-- int.procRefreshFactTableIDsFactStatisticByPayPeriod
/******************************************************************************
** Author: srk
** Create Date: 2016-12-19
** Description: Used to refresh dimension IDs as part of the Refresh Data Dimension Links custom action (MR/PR use)
** Last Modified: 2016-12-19
** GM Release: 2017.1.1
*******************************************************************************
** Change History
*******************************************************************************
** CID	Date		Author	WI		Description
** 1	2016-12-19	srk		D-04980 Creating script so it can be added to the Refresh Data Dimension Links custom action (MR/PR use)
*******************************************************************************/

CREATE procedure [int].[procRefreshFactTableIDsFactStatisticByPayPeriod]
	@IsDebugOnly bit = 0
as
begin

--------------------------------------------------------------------------------------------------
-- Logging
--------------------------------------------------------------------------------------------------
	declare @logdesc nvarchar(100)
	select @logdesc = 
		case @IsDebugOnly
			when 1 then 'Debug only - Refresh Statistic By Pay Period Fact table IDs'
			else 'Refresh Statistic By Pay Period Fact table IDs'
		end

	declare @higuid uniqueidentifier
	exec procLogScript @logdesc, @higuid output

	print 'HistoryItemGUID = '''+cast(@higuid as varchar(36))+''''

--------------------------------------------------------------------------------------------------
-- Set SQL Column
--------------------------------------------------------------------------------------------------
	declare @SQLColumn as nvarchar(200)

	select @SQLColumn=sa.SQLColumnName
	from [dbo].[ScoreAttribute] sa
		inner join [dbo].[IntDataInterfaceField] fld
			on sa.AttributeGUID=fld.GivenScoreAttributeGUID
	where 1=1
		and fld.ScoreKeyGUID = '8fc5efa1-e270-4e75-8add-6965c16ab295'	-- Code (from Pay Period Dimension)
		and fld.DataInterfaceSectionID='b1bf2582-5ddb-4a43-9dce-7c8b41aca4ba' -- Statistics by Pay Period

--------------------------------------------------------------------------------------------------
-- Create SQL script
--------------------------------------------------------------------------------------------------
	declare @sql nvarchar(max) = '
update statpayperiod
set statpayperiod.DepartmentID	= isnull(d.departmentID,0),
	statpayperiod.AccountID	= isnull(a.AccountID,0),
	statpayperiod.PayPeriodID	= isnull(pp.PayPeriodID,0),
	statpayperiod.FiscalYearID	= isnull(fy.FiscalYearID,0),
	statpayperiod.TimeClassID	= isnull(tc.TimeClassID,0)
from [int].[FactStatisticsByPayPeriod] statpayperiod
	left join [fw].[DimDepartment] d 
		on statpayperiod.DepartmentCode=d.DepartmentCode
	left join [fw].[DimAccount] a 
		on statpayperiod.AccountCode=A.AccountCode
	left join [fw].[DimPayPeriod] pp 
		on statpayperiod.PayPeriodCode = pp.'
		+ @SQLColumn
		+ '
	left join [fw].[DimFiscalYear] fy 
		on statpayperiod.FiscalYearCode = fy.Name
	left join [fw].[DimTimeClass] tc 
		on statpayperiod.TimeClassCode = tc.TimeClassCode'

	if @IsDebugOnly=1
		begin
			print(@sql)
		end
	else
		begin
			exec(@sql)
		end

end
GO


---------------------------------------------

-- int.procTransferFactFinancialServiceLineRevenueToSPDirectRollingISPayor
CREATE PROC [int].[procTransferFactFinancialServiceLineRevenueToSPDirectRollingISPayor] as 
/************************************************************
** Author: Bart Lewis
** Create Date: 1/19/2015
** Description: Transfer Fact Financial SL Revenue Data to Fact Direct Rolling IS Payor for Payor Mix
** Last Modified: 2017-04-06
** GM Release: 2017.2
**************************************************************
** Change History
**************************************************************
** CID		Date			Author		WI			Description
** 1		2017-02-10		akk			D-04826		Allowing additional timeclasses
** 2		2017-04-06		srk			D-03689		Updated script to join on fiscalmonthid instead of sort order
*************************************************************/
Delete from [int].[FactSPDirectRollingISPayor] where TransactionID=1

Insert into [int].[FactSPDirectRollingISPayor]
([SPRollingForecastPlanID], [SPRollingForecastPlanName], [AccountRollupID], [SPAccountRollupName], [PatientTypeRollupID], [PatientTypeRollupCode], [PayorGroupID], [PayorGroupCode], [UnitTypeID], [UnitType], [TimeClassID], [TimeClassCode], [FiscalYearID], [FiscalYearCode], [ValueMonth01], [ValueMonth02], [ValueMonth03], [ValueMonth04], [ValueMonth05], [ValueMonth06], [ValueMonth07], [ValueMonth08], [ValueMonth09], [ValueMonth10], [ValueMonth11], [ValueMonth12], [TransactionID])

select 
            [SPRollingForecastPlanID],
            [SPRollingForecastPlanName],
            [AccountRollupID],
            [SPAccountRollupName],
            [PatientTypeRollupID],
            [PatientTypeRollupCode],
            [PayorGroupID],
            [PayorGroupCode],
            [UnitTypeID], 
            [UnitType],
            [TimeClassID],
            [TimeClassCode],
            [FiscalYearID],
            [FiscalYearCode],
            ISNULL(Month01, 0) [ValueMonth01],
            ISNULL(Month02, 0) [ValueMonth02],
            ISNULL(Month03, 0) [ValueMonth03],
            ISNULL(Month04, 0) [ValueMonth04],
            ISNULL(Month05, 0) [ValueMonth05],
            ISNULL(Month06, 0) [ValueMonth06],
            ISNULL(Month07, 0) [ValueMonth07],
            ISNULL(Month08, 0) [ValueMonth08],
            ISNULL(Month09, 0) [ValueMonth09],
            ISNULL(Month10, 0) [ValueMonth10],
            ISNULL(Month11, 0) [ValueMonth11],
            ISNULL(Month12, 0) [ValueMonth12],
            1 as [TransactionID]
            From
            (
                        SELECT 
                        rs.[FiscalYearID]
                        , rs.[FiscalYearID] as [FiscalYearCode]
                        , pg.[PayorGroupID]
                        , pg.Name as [PayorGroupCode]
                        , ar.[UnitTypeID] as [UnitTypeID] 
                        , ut.[Name] as [UnitType]
                        , ptr.[PatientTypeRollupID]
                        , ptr.Name as [PatientTypeRollupCode]
                        , ar.[AccountRollupID]
                        , ar.Name as [SPAccountRollupName]
                        , de.SPRollingForecastSLDrivenModelID [SPRollingForecastPlanID]
                        , rf.Name as [SPRollingForecastPlanName]
                        , tc.TimeClassID as [TimeClassID]
                        , tc.TimeClassCode as [TimeClassCode]
                        , m.[MonthColumnName]
                        , SUM(rs.[Value]) as [Amount]
                        , '00000000-0000-0000-0000-000000000000' as [HistoryItemGUID]
                        , 1 as [TransactionID]
                        FROM [int].[FactFinancialServiceLineRevenue] rs
                        inner join [fw].[DimEntity] de on rs.EntityID=de.EntityID
                        inner join [sp].[DimSPRollingForecastPlan] rf on de.SPRollingForecastSLDrivenModelID=rf.SPRollingForecastPlanID
                        inner join [fw].[DimModelingServiceLine] msl on msl.ServiceLineID=rs.ServiceLineID and msl.AgeCohortID=rs.AgeCohortID and msl.PatientClassID=rs.PatientClassID and msl.MedicalSurgicalID=rs.MedicalSurgicalID
                        inner join [fw].[DimPatientTypeRollup] ptr on msl.PatientClassID=ptr.PatientClassID and ptr.IsSP=1 and ptr.Type In('Inpatient','Outpatient')
                        inner join [fw].[DimForecastDetail] fd on rs.ForecastDetailCode=fd.ForecastDetailCode
                        inner join [sp].[DimAccountRollup] ar on fd.SPAccountRollupID=ar.AccountRollupID
                        inner join [fw].[DimUnitType] ut on ar.UnitTypeID=ut.UnitTypeID
                        inner join [fw].[DimPayorGroup] pg on pg.PayorGroupCode=rs.PayorGroupCode
						-------------BEGIN CID 2-----------------
						--inner join [fw].[DimFiscalMonth] m on rs.FiscalMonthID=m.SortOrder
                        inner join [fw].[DimFiscalMonth] m on rs.FiscalMonthID=m.FiscalMonthID
                        -------------END CID 2-----------------		
						inner join [fw].[DimTimeClass] tc on rs.TimeClassID=tc.TimeClassID
                        where rs.FiscalYearID<>0 and rs.FiscalMonthID<>0 and rs.TimeClassID<>0
                        Group by
                                    rs.[FiscalYearID]
                                    , rs.[FiscalMonthID]
                                    , pg.[Name]
                                    , ptr.[PatientTypeRollupID]
                                    , ptr.[Name]
                                    , ar.[Name]
                                    , ar.[UnitTypeID]
                                    , ut.[Name]
                                    , de.SPRollingForecastSLDrivenModelID 
                                    , rf.Name
                                    , pg.[PayorGroupID]
                                    , ar.[AccountRollupID]
                                    , m.[MonthColumnName]
									, tc.TimeClassID
                        			, tc.TimeClassCode
                        ) as Data
PIVOT
(
SUM(Amount) for MonthColumnName in ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12],[Month00])
) as pvt


Update rp
Set 
            ValueMonth01=Case When rp2.ValueMonth01= 0 Then 0 Else rp.ValueMonth01/rp2.ValueMonth01 End,
            ValueMonth02=Case When rp2.ValueMonth02= 0 Then 0 Else rp.ValueMonth02/rp2.ValueMonth02 End,
            ValueMonth03=Case When rp2.ValueMonth03= 0 Then 0 Else rp.ValueMonth03/rp2.ValueMonth03 End,
            ValueMonth04=Case When rp2.ValueMonth04= 0 Then 0 Else rp.ValueMonth04/rp2.ValueMonth04 End,
            ValueMonth05=Case When rp2.ValueMonth05= 0 Then 0 Else rp.ValueMonth05/rp2.ValueMonth05 End,
            ValueMonth06=Case When rp2.ValueMonth06= 0 Then 0 Else rp.ValueMonth06/rp2.ValueMonth06 End,
            ValueMonth07=Case When rp2.ValueMonth07= 0 Then 0 Else rp.ValueMonth07/rp2.ValueMonth07 End,
            ValueMonth08=Case When rp2.ValueMonth08= 0 Then 0 Else rp.ValueMonth08/rp2.ValueMonth08 End,
            ValueMonth09=Case When rp2.ValueMonth09= 0 Then 0 Else rp.ValueMonth09/rp2.ValueMonth09 End,
            ValueMonth10=Case When rp2.ValueMonth10= 0 Then 0 Else rp.ValueMonth10/rp2.ValueMonth10 End,
            ValueMonth11=Case When rp2.ValueMonth11= 0 Then 0 Else rp.ValueMonth11/rp2.ValueMonth11 End,
            ValueMonth12=Case When rp2.ValueMonth12= 0 Then 0 Else rp.ValueMonth12/rp2.ValueMonth12 End
from [int].[FactSPDirectRollingISPayor] rp
inner join [int].[FactSPDirectRollingISPayor] rp2 on rp.PayorGroupID=rp2.PayorGroupID
            and rp.PatientTypeRollupID=rp2.PatientTypeRollupID
            and rp.SPRollingForecastPlanID=rp2.SPRollingForecastPlanID
            and rp.TimeClassID=rp2.TimeClassID
            and rp.FiscalYearID=rp2.FiscalYearID
where rp.AccountRollupID=65 and rp2.AccountRollupID=3 and rp.TransactionID=1
GO


---------------------------------------------

-- int.procTransferStaffingByPayPeriodToStaffing
/***** *********************************************************** 
****** Author: akowalski 
****** Create Date: 2013-09-19 
****** Description: Transfers Payroll By PayPeriod Data into the FactStaffing Table 
****** Last Modified: 2024-10-15 
****** GM Release: 2024.41 
****** *********************************************************** 
****** Notes: 
****** 
****** Run this query to view the configured PayPeriod Accural Method: 
****** SELECT [Setting] FROM [dbo].[DBSetting] WHERE [Name] = 'GM_Accrual_Method'; 
****** The configured PayPeriod Accural Method determines the logic carried out by this procedure.
****** Explanations of the three PayPeriod Accural Methods outlined below:
****** 
****** PROJECTION WITH REVERSE ACCRUAL (DBSETTING='Reverse') 
****** If the pay period starts in a month and ends in another, the data from the last pay period is used as a reference to accrue 
****** for the remaining of the month based on the days in the current month of the current pay period. 
****** The amount accrued for this month will then be subtracted out of the next month. 
****** Non-Accrued PCs won't be accrued and will be put in the end month 
****** 
****** END MONTH ACCRUAL (DBSETTING='End Month') 
****** The total value goes to the end month of a pay period 
****** 
****** DAYS IN MONTH ACCRUAL (DBSETTING='Days In Month') 
****** If the end and start months are the same, the total value goes to that month. 
****** If the end and start months are different, the data is distributed based on days in each month of the pay period. 
****** Non-Accrued PCs won't be accrued and will be put in the end month 
****** 
****** *********************************************************** 
****** Change History: 
****** 
****** 2024.23 - Removed CID update comments that are 10 years old 
****** To see the old comments find CID 14 rollback script: 
****** SELECT [RollbackScript] FROM [migration].[MigrationLog] WHERE [Name] = '2024-04-07-00-02 INT - JAZZ-66171 - Alter procTransferStaffingByPayPeriodToStaffing for GM'; 
****** Moved PayPeriod Accrual Method explanations into Notes section above 
****** 
****** *********************************************************** 
****** CID  Date        Author         WI              Description 
****** 1    2014-02-04  akowalski      D-01388         Fixing month code select 
****** 2    2014-03-03  akowalski      D-01526         Changing period days filter to look at perioddayssecond 
****** 3    2014-06-12  jgerber        B-02192         Adding reverse accrual and end month as options 
****** 4    2014-06-12  jgerber                        Removed Indexing and Statistics for Staffing Table to improve performance 
****** 5    2014-06-18  jgerber        B-02192         Updating reverse accrual to not use PayPeriodCode 
****** 6    2014-06-19  jgerber        B-01892         Adding a filter for pay code is accrued attribute 
****** 7    2014-07-09  akowalski      D-02068         Filtering out transactionID 1 
****** 8    2014-11-03  akowalski                      Changing delete to chunk delete so it doesn't timeout 
****** 9    2015-02-18  akowalski      D-02733         Removing Value column from all the group bys 
****** 10   2015-10-13  blewis         B-08905         Updating to support multiple pay cycles 
****** 11   2017-12-19  vyaremko       D-04979         Add filter on pay period <> 0 
****** 12   2018-01-12  tparashchak    D-06201         Perfomance improving 
****** 13   2018-03-22  yrhee          D-07041         Increase DepartmentCode field size on temp table 
****** 14   2024-04-07  lcunningham    JAZZ-66171      Definition reformat & clean up - see 2024.23 blurb above 
****** 15   2024-06-14  smeyers        JAZZ-71536      Change JobCodeID from smallint to int 
****** 16   2024-09-13  sfritts        JAZZ-72743      PayCode from varchar(50) to varchar(100) - Extend Field String Limit for Pay Code for Kaiser EPMS
****** 17   2024-10-15  lcunningham    JAZZ-78576      Rolling back Part 2 & 3 #TempStaffing INSERT query joins (lines 165 & 236) and DELETE batching method (line 509) to pre-2024.23 logic  
****** **********************************************************/ 
       
CREATE 
     
  PROC [int].[procTransferStaffingByPayPeriodToStaffing] 
    AS 
 BEGIN 
       ------- INITIALIZE VARIABLES 
       DECLARE @TransactionID int = 1; 
               
       ------ CREATE TEMP TABLE FOR INSERT 
         DROP TABLE IF EXISTS #TempStaffing; 
              
       CREATE TABLE #TempStaffing ( 
              [DepartmentID]     int             NOT NULL, 
              [DepartmentCode]   varchar(100)    NOT NULL, 
              [JobCodeID]        int             NOT NULL, 
              [JobCode]          varchar(50)     NOT NULL, 
              [PayCodeID]        smallint        NOT NULL, 
              [PayCode]          varchar(100)    NOT NULL, 
              [FiscalYearID]     smallint        NOT NULL, 
              [FiscalYearCode]   varchar(20)     NOT NULL, 
              [TimeClassID]      tinyint         NOT NULL, 
              [TimeClassCode]    varchar(20)     NOT NULL, 
              [UnitTypeID]       tinyint         NOT NULL, 
              [UnitType]         varchar(20)     NOT NULL, 
              [FiscalMonthID]    tinyint         NOT NULL, 
              [FiscalMonthCode]  varchar(20)     NOT NULL, 
              [Value]            decimal(19,4)   NOT NULL, 
              [EmployeeID]       int             NOT NULL, 
              [Employeecode]     nvarchar(2000)  NOT NULL, 
              [TransactionID]    int             NULL 
              ); 
              
              
       ------ PART 1: PAY PERIOD ACTUAL DATA 
       ------ This puts all the data into the second month of the pay period 
       INSERT INTO #TempStaffing ([DepartmentID], [DepartmentCode], [JobCodeID], [JobCode], [PayCodeID], [PayCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], [UnitTypeID], [UnitType], [FiscalMonthID], [FiscalMonthCode], [Value], [EmployeeID], [Employeecode], [TransactionID]) 
       SELECT [fact].[DepartmentID], 
              [fact].[DepartmentCode], 
              [fact].[JobCodeID], 
              [fact].[JobCode], 
              [fact].[PayCodeID], 
              [fact].[PayCode], 
              [pp].[FiscalYearIDSecond] AS [FiscalYearID], 
              CAST([pp].[FiscalYearIDSecond] AS varchar(20)) AS [FiscalYearCode], 
              [fact].[TimeClassID], 
              [fact].[TimeClassCode], 
              [fact].[UnitTypeID], 
              [fact].[UnitType], 
              [pp].[FiscalMonthIDSecond] AS [FiscalMonthID], 
              [fm].[FiscalMonthCode] AS [FiscalMonthCode], 
              SUM([fact].[Value]) AS [Value], 
              [fact].[EmployeeID], 
              [fact].[Employeecode], 
              1 AS [TransactionID] 
              
         FROM [int].[FactStaffingByPayPeriod] AS [fact] 
              INNER JOIN [fw].[DimPayPeriod] AS [pp] 
              ON [pp].[PayPeriodID] = [fact].[PayPeriodID] 
              
              INNER JOIN [fw].[DimFiscalMonth] AS [fm] 
              ON [pp].[FiscalMonthIDSecond] = [fm].[FiscalMonthID] 
                 AND [pp].[AccrualMethod] = 'Reverse' 
              
        WHERE [fact].[Value] <> 0 
          AND [fact].[TransactionID] <> @TransactionID 
          AND [pp].[PayPeriodID] <> 0 
              
        GROUP BY 
              [fact].[DepartmentID], 
              [fact].[DepartmentCode], 
              [fact].[JobCodeID], 
              [fact].[JobCode], 
              [fact].[PayCodeID], 
              [fact].[PayCode], 
              [pp].[FiscalYearIDSecond], 
              [fact].[TimeClassID], 
              [fact].[TimeClassCode], 
              [fact].[UnitTypeID], 
              [fact].[UnitType], 
              [pp].[FiscalMonthIDSecond], 
              [fm].[FiscalMonthCode], 
              [fact].[EmployeeID], 
              [fact].[Employeecode]; 
              
              
       ------ PART 2: PAY PERIOD ACCRUAL 
       ------ Accrues data for pay periods that span across 2 months and calculates it based on the previous pay period and days in month 
       INSERT INTO #TempStaffing ([DepartmentID], [DepartmentCode], [JobCodeID], [JobCode], [PayCodeID], [PayCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], [UnitTypeID], [UnitType], [FiscalMonthID], [FiscalMonthCode], [Value], [EmployeeID], [Employeecode], [TransactionID]) 
       SELECT [fact].[DepartmentID], 
              [fact].[DepartmentCode], 
              [fact].[JobCodeID], 
              [fact].[JobCode], 
              [fact].[PayCodeID], 
              [fact].[PayCode], 
              [pp].[FiscalYearIDStart] AS [FiscalYearID], 
              CAST([pp].[FiscalYearIDStart] AS varchar(20)) AS [FiscalYearCode], 
              [fact].[TimeClassID], 
              [fact].[TimeClassCode], 
              [fact].[UnitTypeID], 
              [fact].[UnitType], 
              [pp].[FiscalMonthIDStart] AS [FiscalMonthID], 
              [fm].[FiscalMonthCode] AS [FiscalMonthCode], 
              SUM(CAST([fact].[Value] * [pp].[DaysInPeriodWeightStart] AS money)) AS [Value], 
              [fact].[EmployeeID], 
              [fact].[Employeecode], 
              1 AS [TransactionID] 
              
         FROM [fw].[DimPayPeriod] AS [pp] 
              INNER JOIN [fw].[DimPayPeriod] AS [PPprev] 
              ON [PPprev].[FiscalYearIDSecond] = CASE 
                                                 WHEN [pp].[PeriodNumber] = 1 THEN [pp].[FiscalYearIDSecond] - 1 
                                                 ELSE [pp].[FiscalYearIDSecond] 
                                                  END 
                 AND [PPprev].[PeriodNumber] =   CASE 
                                                 WHEN [pp].[PeriodNumber] = 1 THEN ( SELECT MAX([ipp].[PeriodNumber]) 
                                                                                       FROM [fw].[DimPayPeriod] AS [ipp] 
                                                                                      WHERE [ipp].[FiscalYearIDSecond] = [pp].[FiscalYearIDSecond] - 1 
                                                                                        AND [pp].[PayCycleID] = [ipp].[PayCycleID] ) 
                                                 ELSE [pp].[PeriodNumber] - 1 
                                                  END 
                 AND [pp].[PayCycleID] = [PPprev].[PayCycleID] 
              
              INNER JOIN [int].[FactStaffingByPayPeriod] AS [fact] 
              ON [PPprev].[PayPeriodID] = [fact].[PayPeriodID] 
              
              INNER JOIN [fw].[DimFiscalMonth] AS [fm] 
              ON [pp].[FiscalMonthIDStart] = [fm].[FiscalMonthID] 
              
              INNER JOIN [fw].[DimPayCode] AS [pc] 
              ON [fact].[PayCodeID] = [pc].[PayCodeID] 
              
        WHERE [fact].[Value] <> 0 
          AND [pp].[DaysInPeriodWeightSecond] < 1 
          AND [pc].[IsAccrued] = 1 
          AND [fact].[TransactionID] <> @TransactionID 
          AND [pp].[AccrualMethod] = 'Reverse' 
          AND [pp].[PayPeriodID] <> 0 
              
        GROUP BY 
              [fact].[DepartmentID], 
              [fact].[DepartmentCode], 
              [fact].[JobCodeID], 
              [fact].[JobCode], 
              [fact].[PayCodeID], 
              [fact].[PayCode], 
              [pp].[FiscalYearIDStart], 
              [fact].[TimeClassID], 
              [fact].[TimeClassCode], 
              [fact].[UnitTypeID], 
              [fact].[UnitType], 
              [pp].[FiscalMonthIDStart], 
              [fm].[FiscalMonthCode], 
              [fact].[EmployeeID], 
              [fact].[Employeecode]; 
              
              
       ------ PART 3: PAY PERIOD ACCRUAL REVERSE 
       ------ Adds negative value of accrual to the second month of the pay period for pay periods that span across 2 months 
       INSERT INTO #TempStaffing ([DepartmentID], [DepartmentCode], [JobCodeID], [JobCode], [PayCodeID], [PayCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], [UnitTypeID], [UnitType], [FiscalMonthID], [FiscalMonthCode], [Value], [EmployeeID], [Employeecode], [TransactionID]) 
       SELECT [fact].[DepartmentID], 
              [fact].[DepartmentCode], 
              [fact].[JobCodeID], 
              [fact].[JobCode], 
              [fact].[PayCodeID], 
              [fact].[PayCode], 
              [pp].[FiscalYearIDSecond] AS [FiscalYearID], 
              CAST([pp].[FiscalYearIDSecond] AS varchar(20)) AS [FiscalYearCode], 
              [fact].[TimeClassID], 
              [fact].[TimeClassCode], 
              [fact].[UnitTypeID], 
              [fact].[UnitType], 
              [pp].[FiscalMonthIDSecond] AS [FiscalMonthID], 
              [fm].[FiscalMonthCode] AS [FiscalMonthCode], 
              SUM(CAST(-[fact].[Value] * [pp].[DaysInPeriodWeightStart] AS money)) AS [Value], 
              [fact].[EmployeeID], 
              [fact].[Employeecode], 
              1 AS [TransactionID] 
              
         FROM [fw].[DimPayPeriod] AS [pp] 
              INNER JOIN [fw].[DimPayPeriod] AS [PPprev] 
              ON [PPprev].[FiscalYearIDSecond] = CASE 
                                                 WHEN [pp].[PeriodNumber] = 1 THEN [pp].[FiscalYearIDSecond] - 1 
                                                 ELSE [pp].[FiscalYearIDSecond] 
                                                  END 
                 AND [PPprev].[PeriodNumber] =   CASE 
                                                 WHEN [pp].[PeriodNumber] = 1 THEN ( SELECT MAX([ipp].[PeriodNumber]) 
                                                                                       FROM [fw].[DimPayPeriod] AS [ipp] 
                                                                                      WHERE [ipp].[FiscalYearIDSecond] = [pp].[FiscalYearIDSecond] - 1 
                                                                                        AND [pp].[PayCycleID] = [ipp].[PayCycleID] ) 
                                                 ELSE [pp].[PeriodNumber] - 1 
                                                  END 
                 AND [pp].[PayCycleID] = [PPprev].[PayCycleID] 
              
              INNER JOIN [int].[FactStaffingByPayPeriod] AS [fact] 
              ON [PPprev].[PayPeriodID] = [fact].[PayPeriodID] 
              
              INNER JOIN [fw].[DimFiscalMonth] AS [fm] 
              ON [pp].[FiscalMonthIDSecond] = [fm].[FiscalMonthID] 
              
              INNER JOIN [fw].[DimPayCode] AS [pc] 
              ON [fact].[PayCodeID] = [pc].[PayCodeID] 
              
        WHERE [fact].[Value] <> 0 
          AND [pp].[DaysInPeriodWeightSecond] < 1 
          AND [pc].[IsAccrued] = 1 
          AND [fact].[TransactionID] <> @TransactionID 
          AND [pp].[AccrualMethod] = 'Reverse' 
          AND [pp].[PayPeriodID] <> 0 
              
        GROUP BY
              [fact].[DepartmentID], 
              [fact].[DepartmentCode], 
              [fact].[JobCodeID], 
              [fact].[JobCode], 
              [fact].[PayCodeID], 
              [fact].[PayCode], 
              [pp].[FiscalYearIDSecond], 
              [fact].[TimeClassID], 
              [fact].[TimeClassCode], 
              [fact].[UnitTypeID], 
              [fact].[UnitType], 
              [pp].[FiscalMonthIDSecond], 
              [fm].[FiscalMonthCode], 
              [fact].[EmployeeID], 
              [fact].[Employeecode]; 
              
              
       ------ PART 4: PAY PERIOD ACCRUAL END MONTH (DBSETTING='End Month') 
       ------ The total value goes to the end month of a pay period 
       INSERT INTO #TempStaffing ([DepartmentID], [DepartmentCode], [JobCodeID], [JobCode], [PayCodeID], [PayCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], [UnitTypeID], [UnitType], [FiscalMonthID], [FiscalMonthCode], [Value], [EmployeeID], [Employeecode], [TransactionID]) 
       SELECT [fact].[DepartmentID], 
              [fact].[DepartmentCode], 
              [fact].[JobCodeID], 
              [fact].[JobCode], 
              [fact].[PayCodeID], 
              [fact].[PayCode], 
              [pp].[FiscalYearIDSecond] AS [FiscalYearID], 
              CAST([pp].[FiscalYearIDSecond] AS varchar(20)) AS [FiscalYearCode], 
              [fact].[TimeClassID], 
              [fact].[TimeClassCode], 
              [fact].[UnitTypeID], 
              [fact].[UnitType], 
              [pp].[FiscalMonthIDSecond] AS [FiscalMonthID], 
              [fm].[FiscalMonthCode] AS [FiscalMonthCode], 
              SUM([fact].[Value]) AS [Value], 
              [fact].[EmployeeID], 
              [fact].[Employeecode], 
              1 AS [TransactionID] 
              
         FROM [int].[FactStaffingByPayPeriod] AS [fact] 
              INNER JOIN [fw].[DimPayPeriod]  AS [pp] 
              ON [pp].[PayPeriodID] = [fact].[PayPeriodID] 
              
              INNER JOIN [fw].[DimFiscalMonth] AS [fm] 
              ON [pp].[FiscalMonthIDSecond] = [fm].[FiscalMonthID] 
              
        WHERE [fact].[Value] <> 0 
          AND [fact].[TransactionID] <> @TransactionID 
          AND [pp].[AccrualMethod] = 'End Month' 
          AND [pp].[PayPeriodID] <> 0 
              
        GROUP BY 
              [fact].[DepartmentID], 
              [fact].[DepartmentCode], 
              [fact].[JobCodeID], 
              [fact].[JobCode], 
              [fact].[PayCodeID], 
              [fact].[PayCode], 
              [pp].[FiscalYearIDSecond], 
              [fact].[TimeClassID], 
              [fact].[TimeClassCode], 
              [fact].[UnitTypeID], 
              [fact].[UnitType], 
              [pp].[FiscalMonthIDSecond], 
              [fm].[FiscalMonthCode], 
              [fact].[EmployeeID], 
              [fact].[Employeecode]; 
              
              
       ------ PART 5: PAY PERIOD ACCRUAL DAYS IN MONTH (DBSETTING='Days In Month') 
       ------ If the end and start months are the same, the total value goes to that month. 
       ------ If the end and start months are different, the data is distributed based on days in each month of the pay period. 
       ------ Non-Accrued PCs won't be accrued and will be put in the end month. 
              
       ------ PART 5a: FIRST MONTH 
       INSERT INTO #TempStaffing ([DepartmentID], [DepartmentCode], [JobCodeID], [JobCode], [PayCodeID], [PayCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], [UnitTypeID], [UnitType], [FiscalMonthID], [FiscalMonthCode], [Value], [EmployeeID], [Employeecode], [TransactionID]) 
       SELECT [fact].[DepartmentID], 
              [fact].[DepartmentCode], 
              [fact].[JobCodeID], 
              [fact].[JobCode], 
              [fact].[PayCodeID], 
              [fact].[PayCode], 
              [pp].[FiscalYearIDStart] AS [FiscalYearID], 
              CAST([pp].[FiscalYearIDStart] AS varchar(20)) AS [FiscalYearCode], 
              [fact].[TimeClassID], 
              [fact].[TimeClassCode], 
              [fact].[UnitTypeID], 
              [fact].[UnitType], 
              [pp].[FiscalMonthIDStart] AS [FiscalMonthID], 
              [fm].[FiscalMonthCode] AS [FiscalMonthCode], 
              SUM(CAST([fact].[Value] * [pp].[DaysInPeriodWeightStart] AS money)) AS [Value], 
              [fact].[EmployeeID], 
              [fact].[Employeecode], 
              1 AS [TransactionID] 
              
         FROM [int].[FactStaffingByPayPeriod] AS [fact] 
              INNER JOIN [fw].[DimPayPeriod]  AS [pp] 
              ON [pp].[PayPeriodID] = [fact].[PayPeriodID] 
              
              INNER JOIN [fw].[DimFiscalMonth] AS [fm] 
              ON [pp].[FiscalMonthIDStart] = [fm].[FiscalMonthID] 
              
              INNER JOIN [fw].[DimPayCode] AS [pc] 
              ON [fact].[PayCodeID] = [pc].[PayCodeID] 
              
        WHERE [fact].[Value] <> 0 
          AND [pp].[PeriodDaysStart] > 0 
          AND [pc].[IsAccrued] = 1 
          AND [fact].[TransactionID] <> @TransactionID 
          AND [pp].[AccrualMethod] = 'Days In Month' 
          AND [pp].[PayPeriodID] <> 0 
              
        GROUP BY 
              [fact].[DepartmentID], 
              [fact].[DepartmentCode], 
              [fact].[JobCodeID], 
              [fact].[JobCode], 
              [fact].[PayCodeID], 
              [fact].[PayCode], 
              [pp].[FiscalYearIDStart], 
              [fact].[TimeClassID], 
              [fact].[TimeClassCode], 
              [fact].[UnitTypeID], 
              [fact].[UnitType], 
              [pp].[FiscalMonthIDStart], 
              [fm].[FiscalMonthCode], 
              [fact].[EmployeeID], 
              [fact].[Employeecode]; 
              
       ------ PART 5b: SECOND MONTH 
       INSERT INTO #TempStaffing ([DepartmentID], [DepartmentCode], [JobCodeID], [JobCode], [PayCodeID], [PayCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], [UnitTypeID], [UnitType], [FiscalMonthID], [FiscalMonthCode], [Value], [EmployeeID], [Employeecode], [TransactionID]) 
       SELECT [fact].[DepartmentID], 
              [fact].[DepartmentCode], 
              [fact].[JobCodeID], 
              [fact].[JobCode], 
              [fact].[PayCodeID], 
              [fact].[PayCode], 
              [pp].[FiscalYearIDSecond] AS [FiscalYearID], 
              CAST([pp].[FiscalYearIDSecond] AS varchar(20)) AS [FiscalYearCode], 
              [fact].[TimeClassID], 
              [fact].[TimeClassCode], 
              [fact].[UnitTypeID], 
              [fact].[UnitType], 
              [pp].[FiscalMonthIDSecond] AS [FiscalMonthID], 
              [fm].[FiscalMonthCode] AS [FiscalMonthCode], 
              SUM(CAST([fact].[Value] * [pp].[DaysInPeriodWeightSecond] AS money)) AS [Value], 
              [fact].[EmployeeID], 
              [fact].[Employeecode], 
              1 AS [TransactionID] 
              
         FROM [int].[FactStaffingByPayPeriod] AS [fact] 
              INNER JOIN [fw].[DimPayPeriod]  AS [pp] 
              ON [pp].[PayPeriodID] = [fact].[PayPeriodID] 
              
              INNER JOIN [fw].[DimFiscalMonth] AS [fm] 
              ON [pp].[FiscalMonthIDSecond] = [fm].[FiscalMonthID] 
              
              INNER JOIN [fw].[DimPayCode] AS [pc] 
              ON [fact].[PayCodeID] = [pc].[PayCodeID] 
              
        WHERE [fact].[Value] <> 0 
          AND [pp].[PeriodDaysSecond] > 0 
          AND [pc].[IsAccrued] = 1 
          AND [fact].[TransactionID] <> @TransactionID 
          AND [pp].[AccrualMethod] = 'Days In Month' 
          AND [pp].[PayPeriodID] <> 0 
              
        GROUP BY 
              [fact].[DepartmentID], 
              [fact].[DepartmentCode], 
              [fact].[JobCodeID], 
              [fact].[JobCode], 
              [fact].[PayCodeID], 
              [fact].[PayCode], 
              [pp].[FiscalYearIDSecond], 
              [fact].[TimeClassID], 
              [fact].[TimeClassCode], 
              [fact].[UnitTypeID], 
              [fact].[UnitType], 
              [pp].[FiscalMonthIDSecond], 
              [fm].[FiscalMonthCode], 
              [fact].[EmployeeID], 
              [fact].[Employeecode]; 
              
       ------ PART 5c: NON-ACCRUED PCs 
       INSERT INTO #TempStaffing ([DepartmentID], [DepartmentCode], [JobCodeID], [JobCode], [PayCodeID], [PayCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], [UnitTypeID], [UnitType], [FiscalMonthID], [FiscalMonthCode], [Value], [EmployeeID], [Employeecode], [TransactionID]) 
       SELECT [fact].[DepartmentID], 
              [fact].[DepartmentCode], 
              [fact].[JobCodeID], 
              [fact].[JobCode], 
              [fact].[PayCodeID], 
              [fact].[PayCode], 
              [pp].[FiscalYearIDSecond] AS [FiscalYearID], 
              CAST([pp].[FiscalYearIDSecond] AS varchar(20)) AS [FiscalYearCode], 
              [fact].[TimeClassID], 
              [fact].[TimeClassCode], 
              [fact].[UnitTypeID], 
              [fact].[UnitType], 
              [pp].[FiscalMonthIDSecond] AS [FiscalMonthID], 
              [fm].[FiscalMonthCode] AS [FiscalMonthCode], 
              SUM([fact].[Value]) AS [Value], 
              [fact].[EmployeeID], 
              [fact].[Employeecode], 
              1 AS [TransactionID] 
              
         FROM [int].[FactStaffingByPayPeriod] AS [fact] 
              INNER JOIN [fw].[DimPayPeriod] AS [pp] 
              ON [pp].[PayPeriodID] = [fact].[PayPeriodID] 
              
              INNER JOIN [fw].[DimFiscalMonth] AS [fm] 
              ON [pp].[FiscalMonthIDSecond] = [fm].[FiscalMonthID] 
              
              INNER JOIN [fw].[DimPayCode] AS [pc] 
              ON [fact].[PayCodeID] = [pc].[PayCodeID] 
              
        WHERE [fact].[Value] <> 0 
          AND [pc].[IsAccrued] = 0 
          AND [fact].[TransactionID] <> @TransactionID 
          AND [pp].[AccrualMethod] = 'Days In Month' 
          AND [pp].[PayPeriodID] <> 0 
              
        GROUP BY 
              [fact].[DepartmentID], 
              [fact].[DepartmentCode], 
              [fact].[JobCodeID], 
              [fact].[JobCode], 
              [fact].[PayCodeID], 
              [fact].[PayCode], 
              [pp].[FiscalYearIDSecond], 
              [fact].[TimeClassID], 
              [fact].[TimeClassCode], 
              [fact].[UnitTypeID], 
              [fact].[UnitType], 
              [pp].[FiscalMonthIDSecond], 
              [fm].[FiscalMonthCode], 
              [fact].[EmployeeID], 
              [fact].[Employeecode]; 
              
              
       ------ PART 6: DELETE PREVIOUSLY TRANSFERRED DATA 
              
           IF EXISTS
              ( SELECT NULL 
                  FROM [int].[FactStaffing] 
                 WHERE [TransactionID] <> @TransactionID 
                ) 
        BEGIN 
                 WHILE 1 = 1 
                 BEGIN 
                       DELETE TOP (100000) 
                         FROM [int].[FactStaffing] 
                        WHERE [TransactionID] = @TransactionID; 
                              
                           IF @@ROWCOUNT < 100000 BREAK; 
                   END; 
          END; 
         ELSE 
        BEGIN 
              TRUNCATE TABLE [int].[FactStaffing]; 
          END; 
              
              
       ------ PART 7: INSERT INTO DESTINATION TABLE 
              
       INSERT INTO [int].[FactStaffing] ([DepartmentID], [DepartmentCode], [JobCodeID], [JobCode], [PayCodeID], [PayCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], [UnitTypeID], [UnitType], [FiscalMonthID], [FiscalMonthCode], [Value], [EmployeeID], [Employeecode], [TransactionID]) 
       SELECT [DepartmentID], 
              [DepartmentCode], 
              [JobCodeID], 
              [JobCode], 
              [PayCodeID], 
              [PayCode], 
              [FiscalYearID], 
              [FiscalYearCode], 
              [TimeClassID], 
              [TimeClassCode], 
              [UnitTypeID], 
              [UnitType], 
              [FiscalMonthID], 
              [FiscalMonthCode], 
              SUM([Value]) AS [Value], 
              [EmployeeID], 
              [Employeecode], 
              1 AS [TransactionID] 
              
         FROM #TempStaffing 
        GROUP BY 
              [DepartmentID], 
              [DepartmentCode], 
              [JobCodeID], 
              [JobCode], 
              [PayCodeID], 
              [PayCode], 
              [FiscalYearID], 
              [FiscalYearCode], 
              [TimeClassID], 
              [TimeClassCode], 
              [UnitTypeID], 
              [UnitType], 
              [FiscalMonthID], 
              [FiscalMonthCode], 
              [EmployeeID], 
              [Employeecode]; 
   END;
GO


---------------------------------------------

-- int.procTransferStaffingToStaffingByPayPeriod
CREATE   proc [int].[procTransferStaffingToStaffingByPayPeriod] as  
BEGIN  
/************************************************************  
** Author: ramancharla  
** Create Date: 2013-10-07  
** Description: Transfers FactStaffing Table into Payroll By PayPeriod Data   
** Last Modified: 2014-11-03  
** GM Release: 2015.1  
**************************************************************  
** Change History  
**************************************************************  
** CID  Date  Author WI  Description  
** 1  11/22/13 ramancharla  Updating payperiod and unit type   
**          to smallint from tinyint  
** 2  2014-07-09 akk  D-02068 Filtering out transactionID 1  
** 3   2014-11-03 akk    Changing delete to chunk delete so it doesn't timeout  
** 4  2016-01-15 mjs  D-03862 Adding check for PayCycleID  
** 5  2018-03-22 yr  D-07041 Increase DepartmentCode field size on temp table  
** 6  2020-01-21 IH  D-09186 Increase the deletion sizes from 10K to 100K  
** 7  2020-10-05 HV  JAZZ-1487 MR "Transfer Budget Data" filtering on currently year, not transferring correctly to first/last pay periods  
** 8  2022-12-19 BK  JAZZ-47041 MR "Transfer Budget Data" increase temp table column size to prevent failing when int.FactStaffing EmployeeCode is longer than 50 characters  
** 9  2024-06-14 SM  JAZZ-71536  change JobCodeID from smallint to int  
** 10 2024-09-13 SF  JAZZ-72743 PayCode from varchar(50) to varchar(100) - Extend Field String Limit for Pay Code for Kaiser EPMS
*************************************************************/  
  
  
 /********  Variable Declaration **********/  
 declare @TransactionID int = 1  
  
 /********  Build Rows to Insert **********/  
  
 CREATE TABLE #TEMPSTAFFINGPAYPERIOD (  
  [DepartmentID] [int] NOT NULL,  
  [DepartmentCode] [varchar](100) NOT NULL,  
  [JobCodeID] [int] NOT NULL,  
  [JobCode] [varchar](50) NOT NULL,  
  [PayCodeID] [smallint] NOT NULL,  
  [PayCode] [varchar](100) NOT NULL,  
  [FiscalYearID] [smallint] NOT NULL,  
  [FiscalYearCode] [varchar](20) NOT NULL,  
  [TimeClassID] [tinyint] NOT NULL,  
  [TimeClassCode] [varchar](20) NOT NULL,  
  [UnitTypeID] [smallint] NOT NULL,  
  [UnitType] [varchar](20) NOT NULL,  
  [PayPeriodID] [smallint] NOT NULL,  
  [PayPeriodCode] [varchar](20) NOT NULL,  
  [Value] [decimal](19, 4) NOT NULL,  
  [EmployeeID] [int] NOT NULL,  
  [Employeecode] [varchar](2000) NOT NULL,  
  [TransactionID] [int] NULL  
 )  
  
  
 insert into #TEMPSTAFFINGPAYPERIOD ([DepartmentID], [DepartmentCode], [JobCodeID], [JobCode], [PayCodeID], [PayCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], [UnitTypeID], [UnitType], [PayPeriodID], [PayPeriodCode], [Value], [EmployeeID], [Employeecode], [TransactionID])  
 select  
  fact.[DepartmentID],  
  fact.[DepartmentCode],  
  fact.[JobCodeID],  
  fact.[JobCode],  
  fact.[PayCodeID],  
  fact.[PayCode],  
  PP.FiscalYearIDSecond,  
  PP.FiscalYearIDSecond,  
  fact.[TimeClassID],  
  fact.[TimeClassCode],  
  fact.[UnitTypeID],  
  fact.[UnitType],  
  pp.[PayPeriodID],  
  pp.[PayPeriodCode],  
  SUM(cast(fact.value * PP.PeriodWeightStart as money)) AS Value,  
  fact.[EmployeeID],  
  fact.[Employeecode],  
  1 as TransactionID  
 from  
  [int].[FactStaffing] fact  
  inner join [fw].[DimDepartment] D on fact.DepartmentID=D.DepartmentID  
  inner join [fw].[DimPayPeriod] PP on fact.FiscalMonthID = PP.FiscalMonthIDStart and fact.FiscalYearID = PP.FiscalYearIDStart and PP.PayCycleID=D.PayCycleID  
 where  
  fact.value != 0  
  and PP.PeriodDaysStart > 0 and fact.IsDeleted = 0  
  --============= BEGIN CID 2 =================  
  and fact.TransactionID<>@TransactionID  
  --============= END CID 2 ===================    
 GROUP BY  
  fact.[DepartmentID],  
  fact.[DepartmentCode],  
  fact.[JobCodeID],  
  fact.[JobCode],  
  fact.[PayCodeID],  
  fact.[PayCode],  
  PP.FiscalYearIDSecond,  
  fact.[TimeClassID],  
  fact.[TimeClassCode],  
  fact.[UnitTypeID],  
  fact.[UnitType],  
  fact.[EmployeeID],  
  fact.[Employeecode],  
  pp.[PayPeriodID],  
  pp.[PayPeriodCode]  
    
 insert into #TEMPSTAFFINGPAYPERIOD ([DepartmentID], [DepartmentCode], [JobCodeID], [JobCode], [PayCodeID], [PayCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], [UnitTypeID], [UnitType], [PayPeriodID], [PayPeriodCode], [Value], [EmployeeID], [Employeecode], [TransactionID])  
 select   
  fact.[DepartmentID],  
  fact.[DepartmentCode],  
  fact.[JobCodeID],  
  fact.[JobCode],  
  fact.[PayCodeID],  
  fact.[PayCode],  
  fact.[FiscalYearID],  
  fact.[FiscalYearCode],  
  fact.[TimeClassID],  
  fact.[TimeClassCode],  
  fact.[UnitTypeID],  
  fact.[UnitType],  
  pp.[PayPeriodID],  
  pp.[PayPeriodCode],  
  SUM(cast(fact.value * PP.PeriodWeightSecond as money)) AS Value,  
  fact.[EmployeeID],  
  fact.[Employeecode],  
  1 as TransactionID  
 from  
  [int].[FactStaffing] fact  
  inner join [fw].[DimDepartment] D on fact.DepartmentID=D.DepartmentID  
  inner join [fw].[DimPayPeriod] PP on fact.FiscalMonthID = PP.FiscalMonthIDSecond and fact.FiscalYearID = PP.FiscalYearIDSecond and PP.PayCycleID=D.PayCycleID  
 where  
  fact.value != 0  
  and PP.PeriodDaysSecond > 0 and fact.IsDeleted = 0  
  --============= BEGIN CID 2 =================  
  and fact.TransactionID<>@TransactionID  
  --============= END CID 2 ===================   
 GROUP BY  
  fact.[DepartmentID],  
  fact.[DepartmentCode],  
  fact.[JobCodeID],  
  fact.[JobCode],  
  fact.[PayCodeID],  
  fact.[PayCode],  
  fact.[FiscalYearID],  
  fact.[FiscalYearCode],  
  fact.[TimeClassID],  
  fact.[TimeClassCode],  
  fact.[UnitTypeID],  
  fact.[UnitType],  
  fact.[EmployeeID],  
  fact.[Employeecode],  
  pp.[PayPeriodID],  
  pp.[PayPeriodCode]  
      
 /********  Delete previous transfered data **********/  
--============= BEGIN CID 3 =================   
 while exists (select null from [int].[FactStaffingByPayPeriod] where TransactionID=@TransactionID)  
          delete top (100000) from [int].[FactStaffingByPayPeriod] where TransactionID=@TransactionID  
--============= END CID 3 ===================  
  
  
 /******** Insert into destination table *************/  
 insert into [int].[FactStaffingByPayPeriod] ([DepartmentID], [DepartmentCode], [JobCodeID], [JobCode], [PayCodeID], [PayCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], [UnitTypeID], [UnitType], [PayPeriodID], [PayPeriodCode], [Value], [EmployeeID], [Employeecode], [TransactionID])  
 select   
   [DepartmentID],   
   [DepartmentCode],   
   [JobCodeID],   
   [JobCode],   
   [PayCodeID],   
   [PayCode],   
   [FiscalYearID],   
   [FiscalYearCode],   
   [TimeClassID],   
   [TimeClassCode],   
   [UnitTypeID],   
   [UnitType],   
   [PayPeriodID],   
   [PayPeriodCode],   
   SUM([Value]) AS VALUE,   
   [EmployeeID],   
   [Employeecode],   
   1 as TransactionID  
  from   
   #TEMPSTAFFINGPAYPERIOD  
  group by  
   [DepartmentID],   
   [DepartmentCode],   
   [JobCodeID],   
   [JobCode],   
   [PayCodeID],   
   [PayCode],   
   [FiscalYearID],   
   [FiscalYearCode],   
   [TimeClassID],   
   [TimeClassCode],   
   [UnitTypeID],   
   [UnitType],   
   [PayPeriodID],   
   [PayPeriodCode],  
   [EmployeeID],   
   [Employeecode]  
     
-- alter index all on [int].[FactStaffingbyPayPeriod] REBUILD WITH (FILLFACTOR=80)  
-- update statistics [int].[FactStaffingbyPayPeriod] WITH FULLSCAN  
  
--cleanup  
DROP TABLE #TEMPSTAFFINGPAYPERIOD  
  
  
 /********  Update record in IntTransaction **********/  
  --TODO: Make the way it inserts to the IntTranaction much better  
END;
GO


---------------------------------------------

-- int.procTransferStaffingToStaffingByPayPeriodFiscalYear
CREATE   PROC [int].[procTransferStaffingToStaffingByPayPeriodFiscalYear]   
 @BudgetConfigID INT,  
 @IsBudgetIncluded BIT = 0,  
 @IsProjectionIncluded BIT = 0  
AS  
  
BEGIN  
  
/**************************************************************  
** Change History  
**************************************************************  
** CID  Date         Author    WI        Description  
** 1    2024-08-06   AO        JAZZ-75144   Initial  
** 2    2024-08-29   NH        JAZZ-76159   JobCodeID smallint to int  
** 3	2024-09-13   SF	       JAZZ-72743   PayCode from varchar(50) to varchar(100) - Extend Field String Limit for Pay Code for Kaiser EPMS
*************************************************************/  
-- !!! If you modifying this proc, check [fw].[procTransferStaffingToStaffingByPayPeriodCurrentYear] for updates !!!  
  
 /********  Variable Declaration **********/  
 DECLARE @TransactionID INT = 1  
   
 DECLARE @BudgetFiscalYear INT = -999;  
 DECLARE @ProjectionFiscalYear INT = -999;  
  
 IF (@IsBudgetIncluded = 1) BEGIN SET @BudgetFiscalYear = (SELECT bc.FiscalYearID FROM [fp].[BudgetConfig] bc WHERE BudgetConfigID = @BudgetConfigID ) END  
 IF (@IsProjectionIncluded = 1) BEGIN SET @ProjectionFiscalYear = (SELECT bc.FiscalYearID - 1 FROM [fp].[BudgetConfig] bc WHERE BudgetConfigID = @BudgetConfigID ) END  
  
 /********  Build Rows to Insert **********/  
  
 CREATE TABLE #TEMPSTAFFINGPAYPERIOD (  
  [DepartmentID] [int] NOT NULL,  
  [DepartmentCode] [varchar](50) NOT NULL,  
  [JobCodeID] [int] NOT NULL,  
  [JobCode] [varchar](50) NOT NULL,  
  [PayCodeID] [smallint] NOT NULL,  
  [PayCode] [varchar](100) NOT NULL,  
  [FiscalYearID] [smallint] NOT NULL,  
  [FiscalYearCode] [varchar](20) NOT NULL,  
  [TimeClassID] [tinyint] NOT NULL,  
  [TimeClassCode] [varchar](20) NOT NULL,  
  [UnitTypeID] [smallint] NOT NULL,  
  [UnitType] [varchar](20) NOT NULL,  
  [PayPeriodID] [smallint] NOT NULL,  
  [PayPeriodCode] [varchar](20) NOT NULL,  
  [Value] [decimal](19, 4) NOT NULL,  
  [EmployeeID] [int] NOT NULL,  
  [Employeecode] [varchar](2000) NOT NULL,  
  [TransactionID] [int] NULL  
 )  
  
  
 INSERT INTO #TEMPSTAFFINGPAYPERIOD ([DepartmentID], [DepartmentCode], [JobCodeID], [JobCode], [PayCodeID], [PayCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], [UnitTypeID], [UnitType], [PayPeriodID], [PayPeriodCode], [Value], [EmployeeID], [Employeecode], [TransactionID])  
 SELECT  
  fact.[DepartmentID],  
  fact.[DepartmentCode],  
  fact.[JobCodeID],  
  fact.[JobCode],  
  fact.[PayCodeID],  
  fact.[PayCode],  
  PP.[FiscalYearIDSecond],  
  PP.[FiscalYearIDSecond],  
  fact.[TimeClassID],  
  fact.[TimeClassCode],  
  fact.[UnitTypeID],  
  fact.[UnitType],  
  pp.[PayPeriodID],  
  pp.[PayPeriodCode],  
  SUM(CAST(fact.value * PP.PeriodWeightStart as money)) AS Value,  
  fact.[EmployeeID],  
  fact.[Employeecode],  
  1 AS TransactionID  
 FROM  
  [int].[FactStaffing] fact  
  INNER JOIN [fw].[DimDepartment] D ON fact.DepartmentID=D.DepartmentID  
  INNER JOIN [fw].[DimPayPeriod] PP ON fact.FiscalMonthID = PP.FiscalMonthIDStart AND fact.FiscalYearID = PP.FiscalYearIDStart AND PP.PayCycleID=D.PayCycleID  
 WHERE  
  fact.value != 0  
  AND fact.TimeclassID = 2  
  AND PP.PeriodDaysStart > 0 AND fact.IsDeleted = 0  
  --============= BEGIN CID 2 =================  
  AND fact.TransactionID <> @TransactionID  
  --============= END CID 2 ===================    
  AND PP.FiscalYearIDSecond IN (@BudgetFiscalYear, @ProjectionFiscalYear)  
 GROUP BY  
  fact.[DepartmentID],  
  fact.[DepartmentCode],  
  fact.[JobCodeID],  
  fact.[JobCode],  
  fact.[PayCodeID],  
  fact.[PayCode],  
  PP.[FiscalYearIDSecond],  
  fact.[TimeClassID],  
  fact.[TimeClassCode],  
  fact.[UnitTypeID],  
  fact.[UnitType],  
  fact.[EmployeeID],  
  fact.[Employeecode],  
  pp.[PayPeriodID],  
  pp.[PayPeriodCode]  
    
 INSERT INTO #TEMPSTAFFINGPAYPERIOD ([DepartmentID], [DepartmentCode], [JobCodeID], [JobCode], [PayCodeID], [PayCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], [UnitTypeID], [UnitType], [PayPeriodID], [PayPeriodCode], [Value], [EmployeeID], [Employeecode], [TransactionID])  
 SELECT   
  fact.[DepartmentID],  
  fact.[DepartmentCode],  
  fact.[JobCodeID],  
  fact.[JobCode],  
  fact.[PayCodeID],  
  fact.[PayCode],  
  fact.[FiscalYearID],  
  fact.[FiscalYearCode],  
  fact.[TimeClassID],  
  fact.[TimeClassCode],  
  fact.[UnitTypeID],  
  fact.[UnitType],  
  pp.[PayPeriodID],  
  pp.[PayPeriodCode],  
  SUM(CAST(fact.value * PP.PeriodWeightSecond as money)) AS Value,  
  fact.[EmployeeID],  
  fact.[Employeecode],  
  1 AS TransactionID  
 FROM  
  [int].[FactStaffing] fact  
  INNER JOIN [fw].[DimDepartment] D ON fact.DepartmentID=D.DepartmentID  
  INNER JOIN [fw].[DimPayPeriod] PP ON fact.FiscalMonthID = PP.FiscalMonthIDSecond AND fact.FiscalYearID = PP.FiscalYearIDSecond AND PP.PayCycleID=D.PayCycleID  
 WHERE  
  fact.value != 0  
  AND fact.TimeclassID = 2  
  AND PP.PeriodDaysSecond > 0 AND fact.IsDeleted = 0  
  --============= BEGIN CID 2 =================  
  AND fact.TransactionID <> @TransactionID  
  --============= END CID 2 ===================  
  AND PP.FiscalYearIDSecond IN (@BudgetFiscalYear, @ProjectionFiscalYear)  
 GROUP BY  
  fact.[DepartmentID],  
  fact.[DepartmentCode],  
  fact.[JobCodeID],  
  fact.[JobCode],  
  fact.[PayCodeID],  
  fact.[PayCode],  
  fact.[FiscalYearID],  
  fact.[FiscalYearCode],  
  fact.[TimeClassID],  
  fact.[TimeClassCode],  
  fact.[UnitTypeID],  
  fact.[UnitType],  
  fact.[EmployeeID],  
  fact.[Employeecode],  
  pp.[PayPeriodID],  
  pp.[PayPeriodCode]  
      
 /********  Delete previous transfered data **********/  
--============= BEGIN CID 3 =================   
 WHILE EXISTS (SELECT NULL FROM [int].[FactStaffingByPayPeriod] WHERE TransactionID=@TransactionID AND FiscalYearID IN (@BudgetFiscalYear, @ProjectionFiscalYear) AND TimeClassID = 2)  
          DELETE TOP (100000) FROM [int].[FactStaffingByPayPeriod] WHERE TransactionID=@TransactionID AND FiscalYearID IN (@BudgetFiscalYear, @ProjectionFiscalYear) AND TimeClassID = 2  
--============= END CID 3 ===================  
  
  
 /******** Insert into destination table *************/  
 INSERT INTO [int].[FactStaffingByPayPeriod] ([DepartmentID], [DepartmentCode], [JobCodeID], [JobCode], [PayCodeID], [PayCode], [FiscalYearID], [FiscalYearCode], [TimeClassID], [TimeClassCode], [UnitTypeID], [UnitType], [PayPeriodID], [PayPeriodCode], [Value], [EmployeeID], [Employeecode], [TransactionID])  
 SELECT   
   [DepartmentID],   
   [DepartmentCode],   
   [JobCodeID],   
   [JobCode],   
   [PayCodeID],   
   [PayCode],   
   [FiscalYearID],   
   [FiscalYearCode],   
   [TimeClassID],   
   [TimeClassCode],   
   [UnitTypeID],   
   [UnitType],   
   [PayPeriodID],   
   [PayPeriodCode],   
   SUM([Value]) AS VALUE,   
   [EmployeeID],   
   [Employeecode],   
   1 AS TransactionID  
  FROM   
   #TEMPSTAFFINGPAYPERIOD  
  GROUP BY  
   [DepartmentID],   
   [DepartmentCode],   
   [JobCodeID],   
   [JobCode],   
   [PayCodeID],   
   [PayCode],   
   [FiscalYearID],   
   [FiscalYearCode],   
   [TimeClassID],   
   [TimeClassCode],   
   [UnitTypeID],   
   [UnitType],   
   [PayPeriodID],   
   [PayPeriodCode],  
   [EmployeeID],   
   [Employeecode]  
     
  
-- alter index all on [int].[FactStaffingbyPayPeriod] REBUILD WITH (FILLFACTOR=80)  
-- update statistics [int].[FactStaffingbyPayPeriod] WITH FULLSCAN  
  
--cleanup  
DROP TABLE #TEMPSTAFFINGPAYPERIOD  
  
  
 /********  Update record in IntTransaction **********/  
  --TODO: Make the way it inserts to the IntTranaction much better  
END
GO


---------------------------------------------

-- int.procTransferStatisticsMonthlyByPayPeriodFiscalYear
CREATE   PROC [int].[procTransferStatisticsMonthlyByPayPeriodFiscalYear]
	@BudgetConfigID INT,
	@IsBudgetIncluded BIT = 0,
	@IsProjectionIncluded BIT = 0
AS
BEGIN

/**************************************************************
** Change History
**************************************************************
** CID  Date        Author  WI			Description
** 1    2024-07-11  AO      JAZZ-73257	Initial
*************************************************************/

	/********  Variable Declaration **********/
	DECLARE @TransactionID int = 1

	DECLARE @BudgetFiscalYear INT = -999;
	DECLARE @ProjectionFiscalYear INT = -999;

	IF (@IsBudgetIncluded = 1) BEGIN SET @BudgetFiscalYear = (SELECT bc.FiscalYearID FROM [fp].[BudgetConfig] bc WHERE BudgetConfigID = @BudgetConfigID ) END
	IF (@IsProjectionIncluded = 1) BEGIN SET @ProjectionFiscalYear = (SELECT bc.FiscalYearID - 1 FROM [fp].[BudgetConfig] bc WHERE BudgetConfigID = @BudgetConfigID ) END


	/********  Build Rows to Insert **********/

	CREATE TABLE #TEMPSTATISTICS (
		[AccountID] [int] NOT NULL,
		[DepartmentID] [int] NOT NULL,
		[FiscalYearID] [smallint] NOT NULL,
		[PayPeriodID] [smallint] NOT NULL,
		[TimeClassID] [tinyint] NOT NULL,
		[Value] [decimal](19, 4) NOT NULL,
		[AccountCode] [nvarchar](100) NOT NULL,
		[DepartmentCode] [nvarchar](100) NOT NULL,
		[FiscalYearCode] [nvarchar](100) NOT NULL,
		[PayPeriodCode] [nvarchar](100) NOT NULL,
		[TimeClassCode] [nvarchar](100) NOT NULL,
		[TransactionID] [int] NOT NULL,
	)

	INSERT INTO #TEMPSTATISTICS (DepartmentID, DepartmentCode, AccountID, AccountCode, FiscalYearID, FiscalYearCode, PayPeriodID, PayPeriodCode, TimeClassID, TimeClassCode, Value, TransactionID)
	SELECT
		fact.DepartmentID,
		fact.DepartmentCode,
		fact.AccountID,
		fact.AccountCode,
		PP.FiscalYearIDSecond,
		PP.FiscalYearIDSecond,
		PP.PayPeriodID,
		PP.PayPeriodCode,
		fact.TimeClassID,
		fact.TimeClassCode,
		SUM(cast(fact.value * PP.PeriodWeightStart as money)) AS Value,
		1 as TransactionID
	FROM
		[int].[FactStatistic] fact
		INNER JOIN [fw].[DimDepartment] D ON fact.DepartmentID=D.DepartmentID
		INNER JOIN fw.DimPayPeriod PP ON PP.FiscalMonthIDStart = fact.FiscalMonthID and PP.FiscalYearIDStart = fact.FiscalYearID and PP.PayCycleID=D.PayCycleID
	WHERE
		fact.value != 0
		AND fact.TimeClassID = 2
		AND PP.PeriodDaysStart > 0
		--============= BEGIN CID 2 =================
		AND fact.TransactionID<>@TransactionID
		--============= END CID 2 ===================	
		AND PP.FiscalYearIDSecond IN (@BudgetFiscalYear, @ProjectionFiscalYear)
	GROUP BY
		fact.DepartmentID,
		fact.DepartmentCode,
		fact.AccountID,
		fact.AccountCode,
		PP.FiscalYearIDSecond,
		PP.PayPeriodID,
		PP.PayPeriodCode,
		fact.TimeClassID,
		fact.TimeClassCode
		
	INSERT INTO #TEMPSTATISTICS (DepartmentID, DepartmentCode, AccountID, AccountCode, FiscalYearID, FiscalYearCode, PayPeriodID, PayPeriodCode, TimeClassID, TimeClassCode, Value, TransactionID)
	SELECT
		fact.DepartmentID,
		fact.DepartmentCode,
		fact.AccountID,
		fact.AccountCode,
		fact.FiscalYearID,
		fact.FiscalYearCode,
		PP.PayPeriodID,
		PP.PayPeriodCode,
		fact.TimeClassID,
		fact.TimeClassCode,
		SUM(cast(fact.value * PP.PeriodWeightSecond as money)) AS Value,
		1 AS TransactionID
	FROM
		[int].[FactStatistic] fact
		INNER JOIN [fw].[DimDepartment] D ON fact.DepartmentID = D.DepartmentID
		INNER JOIN fw.DimPayPeriod PP ON PP.FiscalMonthIDSecond = fact.FiscalMonthID AND PP.FiscalYearIDSecond = fact.FiscalYearID AND PP.PayCycleID=D.PayCycleID
	WHERE
		fact.value != 0
		AND fact.TimeClassID = 2
		AND PP.PeriodDaysSecond > 0
		--============= BEGIN CID 2 =================
		AND fact.TransactionID < >@TransactionID
		--============= END CID 2 ===================	
		AND fact.FiscalYearID IN (@BudgetFiscalYear, @ProjectionFiscalYear)
	GROUP BY
		fact.DepartmentID,
		fact.DepartmentCode,
		fact.AccountID,
		fact.AccountCode,
		fact.FiscalYearID,
		fact.FiscalYearCode,
		PP.PayPeriodID,
		PP.PayPeriodCode,
		fact.TimeClassID,
		fact.TimeClassCode
				
	/********  Delete previous transfered data **********/
	DELETE FROM [int].[FactStatisticsbyPayPeriod] 
	WHERE TransactionID = @TransactionID 
		AND FiscalYearID IN (@BudgetFiscalYear, @ProjectionFiscalYear) 
		AND TimeClassID = 2


	/******** Insert into destination table *************/
	INSERT INTO [int].[FactStatisticsbyPayPeriod] (DepartmentID, DepartmentCode, AccountID, AccountCode, FiscalYearID, FiscalYearCode, PayPeriodID, PayPeriodCode, TimeClassID, TimeClassCode, Value, TransactionID)
	SELECT
			DepartmentID,
			DepartmentCode,
			AccountID,
			AccountCode,
			FiscalYearID,
			FiscalYearCode,
			PayPeriodID,
			PayPeriodCode,
			TimeClassID,
			TimeClassCode,
			SUM(value),
			TransactionID
		FROM 
			#TEMPSTATISTICS
		GROUP BY
			DepartmentID,
			DepartmentCode,
			AccountID,
			AccountCode,
			FiscalYearID,
			FiscalYearCode,
			PayPeriodID,
			PayPeriodCode,
			TimeClassID,
			TimeClassCode,
			TransactionID
			
	ALTER INDEX ALL ON [int].[FactStatisticsbyPayPeriod] REBUILD WITH (FILLFACTOR=80)
	UPDATE STATISTICS [int].[FactStatisticsbyPayPeriod] WITH FULLSCAN


	/********  Update record in IntTransaction **********/
	--TODO: Make the way it inserts to the IntTranaction much better
END
GO


---------------------------------------------

-- int.procTransferStatisticsMonthlyToPayPeriod
CREATE proc [int].[procTransferStatisticsMonthlyToPayPeriod] as
/************************************************************
** Author: akowalski
** Create Date: 2013-09-19
** Description: Transfers Monthly statistics Data into the FactStatisticsByPayPeriod Table and does the accrual calculation (converts month to pay period)
** Last Modified: 2014-07-09
** GM Release: 2014.3
**************************************************************
** Change History
**************************************************************
** CID		Date		Author	WI		 Description
** 1		10/29/2013	ramancharla		 Updating insert to PP.FiscalYearIDSecond instead of fact.FiscalYearID
** 2		2014-07-09	akk		D-02068	 Filtering out transactionID 1
** 3		2016-01-15	mjs		D-03862	 Adding check for PayCycleID
** 4		2017-02-16	apukii		TK-37995 Fixed DepartmentID type
*************************************************************/


	/********  Variable Declaration **********/
	declare @TransactionID int = 1



	/********  Build Rows to Insert **********/

	CREATE TABLE #TEMPSTATISTICS (
		[AccountID] [int] NOT NULL,
		[DepartmentID] [int] NOT NULL,
		[FiscalYearID] [smallint] NOT NULL,
		[PayPeriodID] [smallint] NOT NULL,
		[TimeClassID] [tinyint] NOT NULL,
		[Value] [decimal](19, 4) NOT NULL,
		[AccountCode] [nvarchar](100) NOT NULL,
		[DepartmentCode] [nvarchar](100) NOT NULL,
		[FiscalYearCode] [nvarchar](100) NOT NULL,
		[PayPeriodCode] [nvarchar](100) NOT NULL,
		[TimeClassCode] [nvarchar](100) NOT NULL,
		[TransactionID] [int] NOT NULL,
	)

	insert into #TEMPSTATISTICS (DepartmentID, DepartmentCode, AccountID, AccountCode, FiscalYearID, FiscalYearCode, PayPeriodID, PayPeriodCode, TimeClassID, TimeClassCode, Value, TransactionID)
	select
		fact.DepartmentID,
		fact.DepartmentCode,
		fact.AccountID,
		fact.AccountCode,
		PP.FiscalYearIDSecond,
		PP.FiscalYearIDSecond,
		PP.PayPeriodID,
		PP.PayPeriodCode,
		fact.TimeClassID,
		fact.TimeClassCode,
		SUM(cast(fact.value * PP.PeriodWeightStart as money)) AS Value,
		1 as TransactionID
	from
		[int].[FactStatistic] fact
		inner join [fw].[DimDepartment] D on fact.DepartmentID=D.DepartmentID
		inner join fw.DimPayPeriod PP on PP.FiscalMonthIDStart = fact.FiscalMonthID and PP.FiscalYearIDStart = fact.FiscalYearID and PP.PayCycleID=D.PayCycleID
	where
		fact.value != 0
		and PP.PeriodDaysStart > 0
		--============= BEGIN CID 2 =================
		and fact.TransactionID<>@TransactionID
		--============= END CID 2 ===================	
	GROUP BY
		fact.DepartmentID,
		fact.DepartmentCode,
		fact.AccountID,
		fact.AccountCode,
		PP.FiscalYearIDSecond,
		PP.PayPeriodID,
		PP.PayPeriodCode,
		fact.TimeClassID,
		fact.TimeClassCode
		
	insert into #TEMPSTATISTICS (DepartmentID, DepartmentCode, AccountID, AccountCode, FiscalYearID, FiscalYearCode, PayPeriodID, PayPeriodCode, TimeClassID, TimeClassCode, Value, TransactionID)
	select
		fact.DepartmentID,
		fact.DepartmentCode,
		fact.AccountID,
		fact.AccountCode,
		fact.FiscalYearID,
		fact.FiscalYearCode,
		PP.PayPeriodID,
		PP.PayPeriodCode,
		fact.TimeClassID,
		fact.TimeClassCode,
		SUM(cast(fact.value * PP.PeriodWeightSecond as money)) AS Value,
		1 as TransactionID
	from
		[int].[FactStatistic] fact
		inner join [fw].[DimDepartment] D on fact.DepartmentID=D.DepartmentID
		inner join fw.DimPayPeriod PP on PP.FiscalMonthIDSecond = fact.FiscalMonthID and PP.FiscalYearIDSecond = fact.FiscalYearID and PP.PayCycleID=D.PayCycleID
	where
		fact.value != 0
		and PP.PeriodDaysSecond > 0
		--============= BEGIN CID 2 =================
		and fact.TransactionID<>@TransactionID
		--============= END CID 2 ===================	
	GROUP BY
		fact.DepartmentID,
		fact.DepartmentCode,
		fact.AccountID,
		fact.AccountCode,
		fact.FiscalYearID,
		fact.FiscalYearCode,
		PP.PayPeriodID,
		PP.PayPeriodCode,
		fact.TimeClassID,
		fact.TimeClassCode
				
	/********  Delete previous transfered data **********/
	delete from [int].[FactStatisticsbyPayPeriod] where TransactionID=@TransactionID


	/******** Insert into destination table *************/
	insert into [int].[FactStatisticsbyPayPeriod] (DepartmentID, DepartmentCode, AccountID, AccountCode, FiscalYearID, FiscalYearCode, PayPeriodID, PayPeriodCode, TimeClassID, TimeClassCode, Value, TransactionID)
	select
			DepartmentID,
			DepartmentCode,
			AccountID,
			AccountCode,
			FiscalYearID,
			FiscalYearCode,
			PayPeriodID,
			PayPeriodCode,
			TimeClassID,
			TimeClassCode,
			sum(value),
			TransactionID
		from 
			#TEMPSTATISTICS
		group by
			DepartmentID,
			DepartmentCode,
			AccountID,
			AccountCode,
			FiscalYearID,
			FiscalYearCode,
			PayPeriodID,
			PayPeriodCode,
			TimeClassID,
			TimeClassCode,
			TransactionID
			
	alter index all on [int].[FactStatisticsbyPayPeriod] REBUILD WITH (FILLFACTOR=80)
	update statistics [int].[FactStatisticsbyPayPeriod] WITH FULLSCAN


	/********  Update record in IntTransaction **********/
		--TODO: Make the way it inserts to the IntTranaction much better
GO


---------------------------------------------

-- int.procTransferStatisticsPayPeriodToMonthly
CREATE proc [int].[procTransferStatisticsPayPeriodToMonthly] as
/************************************************************
** Author: ramancharla
** Create Date: 2013-10-07
** Description: Transfers statistics by pay period Data into the FactStatistic Table(converts pay period to month)
** Last Modified: 2014-07-09
** GM Release: 2014.3
**************************************************************
** Change History
**************************************************************
** CID		Date		Author	WI		Description
** 1		11/22/13	ramancharla		Updating group by to include fiscal month
** 2		2014-07-09	akk		D-02068	Filtering out transactionID 1
** 4		2017-02-16	apukii	TK-37995 Fixed DepartmentID type
** 5		2017-12-13	ipetriv	D-06594 Fixed Department Code
*************************************************************/
	/********  Variable Declaration **********/
	declare @TransactionID int = 1

	/********  Build Rows to Insert **********/

	CREATE TABLE #TEMPSTATISTICS (
		[AccountID] [int] NOT NULL,
		[DepartmentID] [int] NOT NULL,
		[FiscalYearID] [smallint] NOT NULL,
		[FiscalMonthID] [smallint] NOT NULL,
		[TimeClassID] [tinyint] NOT NULL,
		[Value] [decimal](19, 4) NOT NULL,
		[AccountCode] [nvarchar](100) NOT NULL,
		[DepartmentCode] [nvarchar](100) NOT NULL,
		[FiscalYearCode] [nvarchar](100) NOT NULL,
		[FiscalMonthCode] [nvarchar](100) NOT NULL,
		[TimeClassCode] [nvarchar](100) NOT NULL,
		[TransactionID] [int] NOT NULL,
	)
	insert into #TEMPSTATISTICS (DepartmentID, DepartmentCode, AccountID, AccountCode, FiscalYearID, FiscalYearCode, FiscalMonthID, FiscalMonthCode, TimeClassID, TimeClassCode, Value, TransactionID)
	select 
		fact.DepartmentID,
		fact.DepartmentCode,
		fact.AccountID,
		fact.AccountCode,
		PP.FiscalYearIDStart as [FiscalYearID],
		PP.FiscalYearIDStart as [FiscalYearCode],
		PP.FiscalMonthIDStart as [FiscalMonthID],
		FM.FiscalMonthCode as [FiscalMonthCode],
		fact.TimeClassID,
		fact.TimeClassCode,
		SUM(cast(fact.value * PP.DaysinPeriodWeightStart as money)) AS Value,
		1 as TransactionID
	from
		[int].[FactStatisticsbyPayPeriod] fact
		inner join fw.DimPayPeriod PP on PP.PayPeriodID = fact.PayPeriodID
		inner join fw.DimFiscalMonth FM on FM.FiscalMonthID = PP.FiscalMonthIDStart
	where
		fact.value != 0
		and PP.PeriodDaysStart > 0
		and fact.isdeleted = 0
		--============= BEGIN CID 2 =================
		and fact.TransactionID<>@TransactionID
		--============= END CID 2 ===================	
	GROUP BY
		fact.DepartmentID,
		fact.DepartmentCode,
		fact.AccountID,
		fact.AccountCode,
		PP.FiscalYearIDStart,
		PP.FiscalMonthIDStart,
		fact.TimeClassID,
		fact.TimeClassCode,
		fm.FiscalMonthCode
		
		
	insert into #TEMPSTATISTICS (DepartmentID, DepartmentCode, AccountID, AccountCode, FiscalYearID, FiscalYearCode, FiscalMonthID, FiscalMonthCode, TimeClassID, TimeClassCode, Value, TransactionID)
	select 
		fact.DepartmentID,
		fact.DepartmentCode,
		fact.AccountID,
		fact.AccountCode,
		PP.FiscalYearIDSecond as [FiscalYearID],
		PP.FiscalYearIDSecond as [FiscalYearCode],
		PP.FiscalMonthIDSecond as [FiscalMonthID],
		FM.FiscalMonthCode as [FiscalMonthCode],
		fact.TimeClassID,
		fact.TimeClassCode,
		SUM(cast(fact.value * PP.DaysinPeriodWeightSecond as money)) AS Value,
		1 as TransactionID
	from
		[int].[FactStatisticsbyPayPeriod] fact
		inner join fw.DimPayPeriod PP on PP.PayPeriodID = fact.PayPeriodID
		inner join fw.DimFiscalMonth FM on FM.FiscalMonthID = PP.FiscalMonthIDSecond
	where
		fact.value != 0
		and PP.PeriodDaysSecond > 0
		and fact.isdeleted = 0
		--============= BEGIN CID 2 =================
		and fact.TransactionID<>@TransactionID
		--============= END CID 2 ===================	
	GROUP BY
		fact.DepartmentID,
		fact.DepartmentCode,
		fact.AccountID,
		fact.AccountCode,
		PP.FiscalYearIDSecond,
		PP.FiscalMonthIDSecond,
		fact.TimeClassID,
		fact.TimeClassCode,
		fm.FiscalMonthCode
				
	/********  Delete previous transfered data **********/
	delete from [int].[FactStatistic] where TransactionID=@TransactionID


	/******** Insert into destination table *************/
	insert into [int].[FactStatistic] (DepartmentID, DepartmentCode, AccountID, AccountCode, FiscalYearID, FiscalYearCode, FiscalMonthID, FiscalMonthCode, TimeClassID, TimeClassCode, Value, TransactionID)
	select
			DepartmentID, 
			DepartmentCode, 
			AccountID, 
			AccountCode, 
			FiscalYearID, 
			FiscalYearCode, 
			FiscalMonthID, 
			FiscalMonthCode, 
			TimeClassID, 
			TimeClassCode, 
			SUM(Value), 
			TransactionID
		from 
			#TEMPSTATISTICS
		group by
			DepartmentID,
			DepartmentCode,
			AccountID,
			AccountCode,
			FiscalYearID,
			FiscalYearCode,
			FiscalMonthID, 
			FiscalMonthCode, 
			TimeClassID,
			TimeClassCode,
			TransactionID
			
	alter index all on [int].[FactStatistic] REBUILD WITH (FILLFACTOR=80)
	update statistics [int].[FactStatistic] WITH FULLSCAN


	/********  Update record in IntTransaction **********/
		--TODO: Make the way it inserts to the IntTranaction much better
GO


---------------------------------------------

-- int.procTransferStatisticsToGlobalStatistics
CREATE proc [int].[procTransferStatisticsToGlobalStatistics] as
/************************************************************ 
** Author: akowalski 
** Create Date: 2014-07-16 
** Description: Transfers data from statistics to global statistics based on the current global statistics setup 
** Last Modified: 2014-07-16 
** GM Release: 2014.4 
************************************************************** 
** Change History 
************************************************************** 
** CID	Date	Author	WI	Description 
** 01   2018-04-17 sdominsk B-18563  Added PK WORKAROUND ESC-07594
** 
*************************************************************/ 


/******** Variable Declaration **********/ 
declare @TransactionID int = 1 



/******** Build Rows to Insert **********/ 

CREATE TABLE #TEMPSTATISTICS ( 
[AccountID] [int] NOT NULL, 
[DepartmentID] [int] NOT NULL, 
[FiscalYearID] [int] NOT NULL, 
[FiscalMonthID] [smallint] NOT NULL, 
[TimeClassID] [tinyint] NOT NULL, 
[Value] [decimal](19, 4) NOT NULL, 
[AccountCode] [nvarchar](100) NOT NULL, 
[DepartmentCode] [nvarchar](100) NOT NULL, 
[FiscalYearCode] [nvarchar](100) NOT NULL, 
[FiscalMonthCode] [nvarchar](100) NOT NULL, 
[TimeClassCode] [nvarchar](100) NOT NULL, 
[TransactionID] [int] NOT NULL, 
) 

-- Department level stats 
insert into #TEMPSTATISTICS (DepartmentID, DepartmentCode, AccountID, AccountCode, FiscalYearID, FiscalYearCode, FiscalMonthID, FiscalMonthCode, TimeClassID, TimeClassCode, Value, TransactionID) 
select 
fct.DepartmentID, 
fct.DepartmentCode, 
fct.AccountID, 
fct.AccountCode, 
fct.[FiscalYearID], 
fct.[FiscalYearCode], 
fct.[FiscalMonthID], 
fct.[FiscalMonthCode], 
fct.TimeClassID, 
fct.TimeClassCode, 
fct.value AS Value, 
1 as TransactionID 
FROM	
[int].[FactStatistic] fct with (readuncommitted) 
inner join fw.DimDepartment d with (readuncommitted) on fct.DepartmentID=d.DepartmentID 
inner join [fw].[DimAccount] a with (readuncommitted) on a.AccountID=fct.AccountID 
inner join [ob].[DimOBGlobalStatisticsPlan] gsp with (readuncommitted) on gsp.OBGlobalStatisticsPlanID=d.OBGlobalStatisticsPlanID 
inner join [ob].[DimOBGlobalStatistics] gs with (readuncommitted) on gs.AccountID=fct.AccountID and gs.DepartmentID=fct.DepartmentID 
where a.IsGlobal=0 and a.isStat=1 
and gsp.OBGlobalStatisticsPlanID<>0 and d.IsOB=1 and d.IsActive=1 

-- Entity level stats 
insert into #TEMPSTATISTICS (DepartmentID, DepartmentCode, AccountID, AccountCode, FiscalYearID, FiscalYearCode, FiscalMonthID, FiscalMonthCode, TimeClassID, TimeClassCode, Value, TransactionID) 
select 
fct.DepartmentID, 
fct.DepartmentCode, 
fct.AccountID, 
fct.AccountCode, 
fct.[FiscalYearID], 
fct.[FiscalYearCode], 
fct.[FiscalMonthID], 
fct.[FiscalMonthCode], 
fct.TimeClassID, 
fct.TimeClassCode, 
fct.value AS Value, 
1 as TransactionID 
FROM	
[int].[FactStatistic] fct with (readuncommitted) 
inner join fw.DimDepartment d with (readuncommitted) on fct.DepartmentID=d.DepartmentID 
inner join [fw].[DimAccount] a with (readuncommitted) on a.AccountID=fct.AccountID 
inner join [ob].[DimOBGlobalStatisticsPlan] gsp with (readuncommitted) on gsp.OBGlobalStatisticsPlanID=d.OBGlobalStatisticsPlanID 
inner join [ob].[DimOBGlobalStatistics] gs with (readuncommitted) on gs.AccountID=fct.AccountID and gs.DepartmentID=0 
where a.IsGlobal=1 and a.isStat=1 
and gsp.OBGlobalStatisticsPlanID<>0 and d.IsOB=1 and d.IsActive=1 

--------------------------------- 
--PK WORKAROUND ESC-07594 START-- 
--------------------------------- 

CREATE TABLE #TEMPCHARGEBASEDSTATS ( 
[AccountID] [int] NOT NULL, 
[DepartmentID] [int] NOT NULL, 
[FiscalYearID] [int] NOT NULL, 
[FiscalMonthID] [smallint] NOT NULL, 
[TimeClassID] [tinyint] NOT NULL, 
[Value] [decimal](19, 4) NOT NULL, 
[AccountCode] [nvarchar](100) NOT NULL, 
[DepartmentCode] [nvarchar](100) NOT NULL, 
[FiscalYearCode] [nvarchar](100) NOT NULL, 
[FiscalMonthCode] [nvarchar](100) NOT NULL, 
[TimeClassCode] [nvarchar](100) NOT NULL, 
[TransactionID] [int] NOT NULL, 
) 

-- Department level stats (charge-based statistics) 
insert into #TEMPCHARGEBASEDSTATS (DepartmentID, DepartmentCode, AccountID, AccountCode, FiscalYearID, FiscalYearCode, FiscalMonthID, FiscalMonthCode, TimeClassID, TimeClassCode, Value, TransactionID) 
select 
fct.DepartmentID, 
d.DepartmentCode, 
fct.AccountID, 
a.AccountCode, 
fct.[FiscalYearID], 
fy.Name as FiscalYearCode, 
fct.[FiscalMonthID], 
fm.[FiscalMonthCode], 
1 as TimeClassID, 
'A' as TimeClassCode, 
fct.value AS Value, 
1 as TransactionID 
FROM	
[fw].[FactChargeBasedStatisticsMonthly] fct 
inner join fw.DimDepartment d on fct.DepartmentID=d.DepartmentID 
inner join [fw].[DimAccount] a on a.AccountID=fct.AccountID 
inner join [ob].[DimOBGlobalStatisticsPlan] gsp on gsp.OBGlobalStatisticsPlanID=d.OBGlobalStatisticsPlanID 
inner join [ob].[DimOBGlobalStatistics] gs on gs.AccountID=fct.AccountID and gs.DepartmentID=fct.DepartmentID 
inner join [fw].[DimFiscalYear] fy on fy.FiscalYearID = fct.FiscalYearID 
inner join [fw].[DimFiscalMonth] fm on fm.FiscalMonthID = fct.FiscalMonthID 
where a.IsGlobal=0 and a.isStat=1 
and gsp.OBGlobalStatisticsPlanID<>0 and d.IsOB=1 and d.IsActive=1 
and fct.IsDeleted=0 

-- Entity level stats (charge-based statistics) 
insert into #TEMPCHARGEBASEDSTATS (DepartmentID, DepartmentCode, AccountID, AccountCode, FiscalYearID, FiscalYearCode, FiscalMonthID, FiscalMonthCode, TimeClassID, TimeClassCode, Value, TransactionID) 
select 
fct.DepartmentID, 
d.DepartmentCode, 
fct.AccountID, 
a.AccountCode, 
fct.[FiscalYearID], 
fy.Name as FiscalYearCode, 
fct.[FiscalMonthID], 
fm.[FiscalMonthCode], 
1 as TimeClassID, 
'A' as TimeClassCode, 
fct.value AS Value, 
1 as TransactionID 
FROM	
[fw].[FactChargeBasedStatisticsMonthly] fct 
inner join fw.DimDepartment d on fct.DepartmentID=d.DepartmentID 
inner join [fw].[DimAccount] a on a.AccountID=fct.AccountID 
inner join [ob].[DimOBGlobalStatisticsPlan] gsp on gsp.OBGlobalStatisticsPlanID=d.OBGlobalStatisticsPlanID 
inner join [ob].[DimOBGlobalStatistics] gs on gs.AccountID=fct.AccountID and gs.DepartmentID=fct.DepartmentID 
inner join [fw].[DimFiscalYear] fy on fy.FiscalYearID = fct.FiscalYearID 
inner join [fw].[DimFiscalMonth] fm on fm.FiscalMonthID = fct.FiscalMonthID 
where a.IsGlobal=1 and a.isStat=1 
and gsp.OBGlobalStatisticsPlanID<>0 and d.IsOB=1 and d.IsActive=1 
and fct.IsDeleted=0 

--Push charge-based statistics into stat temp table for rows not already loaded via DI 

merge 
#TEMPSTATISTICS AS fact 
using 
(select DepartmentID, DepartmentCode, AccountID, AccountCode, FiscalYearID, FiscalYearCode, FiscalMonthID, FiscalMonthCode, TimeClassID, TimeClassCode, Value, TransactionID from #TEMPCHARGEBASEDSTATS where Value != 0) as source 
on 
fact.DepartmentID = source.DepartmentID and fact.AccountID = source.AccountID and fact.FiscalYearID = source.FiscalYearID and fact.FiscalMonthID = source.FiscalMonthID and fact.TimeClassID = source.TimeClassID 
when not matched then 
insert (DepartmentID, DepartmentCode, AccountID, AccountCode, FiscalYearID, FiscalYearCode, FiscalMonthID, FiscalMonthCode, TimeClassID, TimeClassCode, Value, TransactionID) 
values (source.DepartmentID, source.DepartmentCode, source.AccountID, source.AccountCode, source.FiscalYearID, source.FiscalYearCode, source.FiscalMonthID, source.FiscalMonthCode, source.TimeClassID, source.TimeClassCode, source.Value, source.TransactionID);	

------------------------------- 
--PK WORKAROUND ESC-07594 END-- 
------------------------------- 

/******** Delete previous transfered data **********/ 
delete from [int].[FactGlobalStatistics] where TransactionID=@TransactionID 


/******** Insert into destination table *************/ 
insert into [int].[FactGlobalStatistics] (DepartmentID, DepartmentCode, AccountID, AccountCode, FiscalYearID, FiscalYearCode, FiscalMonthID, FiscalMonthCode, TimeClassID, TimeClassCode, Value, TransactionID) 
select 
DepartmentID, 
DepartmentCode, 
AccountID, 
AccountCode, 
FiscalYearID, 
FiscalYearCode, 
FiscalMonthID, 
FiscalMonthCode, 
TimeClassID, 
TimeClassCode, 
SUM(Value), 
TransactionID 
from 
#TEMPSTATISTICS 
group by 
DepartmentID, 
DepartmentCode, 
AccountID, 
AccountCode, 
FiscalYearID, 
FiscalYearCode, 
FiscalMonthID, 
FiscalMonthCode, 
TimeClassID, 
TimeClassCode, 
TransactionID 

alter index all on [int].[FactGlobalStatistics] REBUILD WITH (FILLFACTOR=80) 
update statistics [int].[FactGlobalStatistics] WITH FULLSCAN 

/******** Update record in IntTransaction **********/ 
--TODO: Make the way it inserts to the IntTranaction much better
GO


---------------------------------------------

-- int.procTruncateAllImportTables
CREATE PROC [int].[procTruncateAllImportTables]
		@IncludeRejectedTables bit = 1
	AS	
	BEGIN
		DECLARE @TruncQuery VARCHAR(MAX)

		SET @TruncQuery = (SELECT dbo.STRAGGR('TRUNCATE TABLE [' + SchemaName + '].[' + ObjectName + ']', CHAR(13) + CHAR(10),'') 
							FROM dbo.ViewSysTables 
							WHERE SchemaName = 'int' AND ObjectName LIKE 'Import______________________________________Accepted')

		EXEC (@TruncQuery)

		IF @IncludeRejectedTables = 1
		BEGIN
			SET @TruncQuery = (SELECT dbo.STRAGGR('TRUNCATE TABLE [' + SchemaName + '].[' + ObjectName + ']', CHAR(13) + CHAR(10),'') 
							FROM dbo.ViewSysTables 
							WHERE SchemaName = 'int' AND ObjectName LIKE 'Import______________________________________Rejected')

			EXEC (@TruncQuery)
		END
	END
GO


---------------------------------------------

-- int.procUpdateMissingEmployeeNamesandHomeDepartments
/***** *********************************************************** 
****** Author: dkondaveeti
****** Create Date: 2017-01-09 
****** Description: Updates missing employee name and home deparments after DI Import 
****** Last Modified: 2024-04-07 
****** GM Release: 2024.23 
****** *********************************************************** 
****** Change History 
****** *********************************************************** 
****** CID  Date        Author         WI              Description 
****** 1    2017-04-25  ydemb                          Ensure that procUpdateMissingEmployeeNamesandHomeDepartments exists 
****** 2    2017-04-25  ydemb                          Updated proc to refresh missing employee names after DI import 
****** 3    2024-04-07  lcunningham    JAZZ-66177      Updated proc to refresh missing employee names to Not Specified after DI import 
****** **********************************************************/ 
       
CREATE 
     
  PROC [int].[procUpdateMissingEmployeeNamesandHomeDepartments] 
    AS 
 BEGIN 
       UPDATE [de1] 
          SET [de1].[NameFirst] = [de2].[NameFirst], 
              [de1].[NameLast]  = [de2].[NameLast] 
       ------ SELECT * 
         FROM [fw].[DimEmployee] AS [de1] 
              INNER JOIN [fw].[DimEmployee] AS [de2] 
              ON [de2].[EmployeeID] = ( SELECT TOP 1 [de3].[EmployeeID] 
                                          FROM [fw].[DimEmployee] AS [de3] 
                                         WHERE [de1].[Number] = [de3].[Number] 
                                           AND (    [de3].[NameLast]  <> '' 
                                                 OR [de3].[NameFirst] <> '' 
                                                 ) 
                                           AND (    [de1].[NameFirst] <> 'Specified' 
                                                 OR [de1].[NameLast]  <> 'Not' 
                                                 ) 
                                        ) 
        WHERE (    [de1].[NameFirst] = '' 
                OR [de1].[NameLast]  = '' 
                ) 
          AND (    [de1].[NameFirst] = 'Specified' 
                OR [de1].[NameLast]  = 'Not' 
                ); 
              
              
       UPDATE [e] 
          SET [e].[NameFirst] = 'Specified', 
              [e].[NameLast]  = 'Not' 
       ------ SELECT * 
         FROM [fw].[DimEmployee] AS [e] 
        WHERE [e].[NameFirst] = '' 
           OR [e].[NameLast]  = ''; 
              
              
       UPDATE [de1] 
          SET [de1].[HomeDepartmentID] = [de2].[HomeDepartmentID] 
       ------ SELECT * 
         FROM [fw].[DimEmployee] AS [de1] 
              INNER JOIN [fw].[DimEmployee] AS [de2] 
              ON [de1].[Number] = [de2].[Number] 
              
        WHERE [de1].[HomeDepartmentID] =  0 
          AND [de2].[HomeDepartmentID] <> 0; 
              
              
         EXEC [dbo].[procScoreDimensionCacheRefresh] 'FD66443C-1F8F-46EC-A074-0D5F6D8DFD29'; 
   END;
GO


---------------------------------------------

---------------------------------------------
--  FUNCTIONS
---------------------------------------------

-- int.viewFactStaffingYTDValuesPivoted
CREATE FUNCTION int.viewFactStaffingYTDValuesPivoted (@MonthsLoaded INT)
	RETURNS TABLE
	AS 
	RETURN
		SELECT 
			pv.DepartmentID,
			pv.JobCodeID,
			pv.PayCodeID,
			pv.FiscalYearID,
			pv.TimeClassID,
			pv.UnitTypeID,
			ISNULL(pv.Month01, 0) as Month01,
			ISNULL(pv.Month02, 0) as Month02,
			ISNULL(pv.Month03, 0) as Month03,
			ISNULL(pv.Month04, 0) as Month04,
			ISNULL(pv.Month05, 0) as Month05,
			ISNULL(pv.Month06, 0) as Month06,
			ISNULL(pv.Month07, 0) as Month07,
			ISNULL(pv.Month08, 0) as Month08,
			ISNULL(pv.Month09, 0) as Month09,
			ISNULL(pv.Month10, 0) as Month10,
			ISNULL(pv.Month11, 0) as Month11,
			ISNULL(pv.Month12, 0) as Month12
		FROM (
				SELECT 
					fs.DepartmentID,
					fs.JobCodeID,
					fs.PayCodeID,
					fs.FiscalYearID,
					fs.TimeClassID,
					fs.UnitTypeID,
					fm.MonthColumnName,
					fs.Value
				FROM [int].[FactStaffing] fs
				INNER JOIN [fw].[DimFiscalMonth] fm ON fm.FiscalMonthID = fs.FiscalMonthID
				WHERE fm.SortOrder <= @MonthsLoaded
			) data
		PIVOT
		(SUM(Value) FOR MonthColumnName IN ([Month01],[Month02],[Month03],[Month04],[Month05],[Month06],[Month07],[Month08],[Month09],[Month10],[Month11],[Month12])) as pv
GO


---------------------------------------------

