
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[EMT_Edits_VR_AND_Conditions]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[EMT_Edits_VR_AND_Conditions]
GO


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[MDS20_TempCalculating_VR]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[MDS20_TempCalculating_VR]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE View [dbo].[MDS20_TempCalculating_VR]
as
select 
CCRS.LinkID as zzLinkID, ChartNumber as zzChartNumber, ccrs.AdmitDate as zzAdmitDate, 
I.DisplayCode as zzInstitutionNumber,    I.UserDescription as zzInstitutionDesc,
zzLastAssessmentType = 
    (case when DischargeAssessment.LinkID is null
            and QuarterAssessment.LinkID is null and AnnualAssessment.LinkID is null
            and FullAssessment.LinkID is null and ReEntryAssessment.LinkID is null
        then '0'
        when ReEntryAssessment.LinkID is not null 
        then (case when QuarterAssessment.LinkID is null and AnnualAssessment.LinkID is null and FullAssessment.LinkID is null
                   then '0' 
                   when ReEntryAssessment.AssessmentDate > isnull(QuarterAssessment.AssessmentDate, '1950/01/01')
                   then (case when ReEntryAssessment.AssessmentDate > isnull(AnnualAssessment.AssessmentDate, '1950/01/01')
                              then (case when ReEntryAssessment.AssessmentDate > isnull(FullAssessment.AssessmentDate, '1950/01/01')
                                         then '9'    --Reentry
                                         else '1'    --Full
                                    end)
                              else (case when AnnualAssessment.AssessmentDate > isnull(FullAssessment.AssessmentDate, '1950/01/01')
                                         then '2'    --Annual
                                         else '1'    --Full
                                    end)
                        end)
                   else (case when QuarterAssessment.AssessmentDate > isnull(AnnualAssessment.AssessmentDate, '1950/01/01')
                              then (case when QuarterAssessment.AssessmentDate > isnull(FullAssessment.AssessmentDate, '1950/01/01')
                                         then '5'    --Quarter
                                         else (case when AnnualAssessment.AssessmentDate > isnull(FullAssessment.AssessmentDate, '1950/01/01')
                                                    then '2'    --Annual
                                                    else '1'    --Full
                                               end)
                                    end)
                              else (case when AnnualAssessment.AssessmentDate > isnull(FullAssessment.AssessmentDate, '1950/01/01')
                                         then '2'    --Annual
                                         else '1'    --Full
                                    end)
                        end)
             end)
        when QuarterAssessment.LinkID is null
        then (case when FullAssessment.LinkID is null --and AnnualAssessment.AssessmentDate is null 
                   then '0'     --Admit
                   else '1'     --Full A
             end)
        when QuarterAssessment.AssessmentDate > isnull(AnnualAssessment.AssessmentDate, '1950/01/01')
        then (case when QuarterAssessment.AssessmentDate > isnull(FullAssessment.AssessmentDate, '1950/01/01')
                   then '5' --Quarter
                   else '1'
             end)
        else (case when AnnualAssessment.AssessmentDate > isnull(FullAssessment.AssessmentDate, '1950/01/01')
                   then '2' --Annual
                   else '1'
             end)
    end), 
zzLastAssessmentDate = 
    (case when DischargeAssessment.LinkID is null and QuarterAssessment.LinkID is null and AnnualAssessment.LinkID is null
            and FullAssessment.LinkID is null and ReEntryAssessment.LinkID is null
        then CCRS.AdmitDate     --Admit
        when ReEntryAssessment.LinkID is not null 
            and QuarterAssessment.AssessmentDate is null and FullAssessment.AssessmentDate is null and AnnualAssessment.AssessmentDate is null
        then CCRS.AdmitDate --Admit
        --then (case when ReEntryAssessment.AssessmentDate > isnull(QuarterAssessment.AssessmentDate, '1950/01/01')
        --           then (case when ReEntryAssessment.AssessmentDate > isnull(AnnualAssessment.AssessmentDate, '1950/01/01')
        --                      then (case when ReEntryAssessment.AssessmentDate > isnull(FullAssessment.AssessmentDate, '1950/01/01')
        --                                 then ReEntryAssessment.AssessmentDate    --Reentry
        --                                 else FullAssessment.AssessmentDate       --Full
        --                            end)
        --                      else (case when AnnualAssessment.AssessmentDate > isnull(FullAssessment.AssessmentDate, '1950/01/01')
        --                                 then AnnualAssessment.AssessmentDate    --Annual
        --                                 else FullAssessment.AssessmentDate      --Full
        --                            end)
        --                end)
        --           else (case when QuarterAssessment.AssessmentDate > isnull(AnnualAssessment.AssessmentDate, '1950/01/01')
        --                      then (case when QuarterAssessment.AssessmentDate > isnull(FullAssessment.AssessmentDate, '1950/01/01')
        --                                 then QuarterAssessment.AssessmentDate    --Quarter
        --                                 else FullAssessment.AssessmentDate       --Full
        --                            end)
        --                      else (case when AnnualAssessment.AssessmentDate > isnull(FullAssessment.AssessmentDate, '1950/01/01')
        --                                 then AnnualAssessment.AssessmentDate    --Annual
        --                                 else FullAssessment.AssessmentDate      --Full
        --                            end)
        --                end)
        --     end)
        when QuarterAssessment.AssessmentDate is null
        then (case when FullAssessment.AssessmentDate is null --and AnnualAssessment.AssessmentDate is null 
                   then CCRS.AdmitDate                   --Admit
                   else FullAssessment.AssessmentDate    --Full 
             end)
        when QuarterAssessment.AssessmentDate > isnull(AnnualAssessment.AssessmentDate, '1950/01/01')
        then (case when QuarterAssessment.AssessmentDate > isnull(FullAssessment.AssessmentDate, '1950/01/01')
                   then QuarterAssessment.AssessmentDate  --Quarter
                   else (case when isnull(AnnualAssessment.AssessmentDate, '1950/01/01') > isnull(FullAssessment.AssessmentDate, '1950/01/01')
                              then AnnualAssessment.AssessmentDate --Annual
                              else FullAssessment.AssessmentDate   --Full
                         end)
             end)
        else (case when isnull(AnnualAssessment.AssessmentDate, '1950/01/01') > isnull(FullAssessment.AssessmentDate, '1950/01/01')
                   then AnnualAssessment.AssessmentDate --Annual
                   else FullAssessment.AssessmentDate   --Full
             end)
    end), 
zzLastFullAssessment = 
    (case when FullAssessment.LinkID is null and AnnualAssessment.LinkID is null and ReEntryAssessment.LinkID is null 
          then CCRS.AdmitDate     --Admit
          else (case when AnnualAssessment.AssessmentDate is not null
                     then (case when AnnualAssessment.AssessmentDate > isnull(FullAssessment.AssessmentDate, '1950/01/01')
                                then AnnualAssessment.AssessmentDate --Annual
                                else FullAssessment.AssessmentDate   --Full
                           end)
                     else FullAssessment.AssessmentDate
                end)
    end)
from 
CRS_Demographic CCRS with (nolock)
inner join H_InstitutionProfile I with (nolock) on CCRS.InstitutionNumber = I.Code
left join 
	(select Max(A3) as AssessmentDate, LinkID
	 from CRS_Demographic CCRS with (nolock) inner join LU_CodeFile LU_AA8 with (nolock) on CCRS.AA8 = LU_AA8.Code
	 where AbstractID <> LinkID and LU_AA8.CIHIValue = '01'
	 group by LinkID
	 having Max(A3) is not null ) FullAssessment on CCRS.LinkID = FullAssessment.LinkID

left join 
	(select Max(A3) as AssessmentDate, LinkID
	 from CRS_Demographic CCRS with (nolock) inner join LU_CodeFile LU_AA8 with (nolock) on CCRS.AA8 = LU_AA8.Code
	 where AbstractID <> LinkID and LU_AA8.CIHIValue in ('02')
	 group by LinkID
	 having Max(A3) is not null ) AnnualAssessment on CCRS.LinkID = AnnualAssessment.LinkID
left join  
	(select Max(A3) as AssessmentDate, LinkID
	 from CRS_Demographic CCRS with (nolock) inner join LU_CodeFile LU_AA8 with (nolock) on CCRS.AA8 = LU_AA8.Code
	 where AbstractID <> LinkID and LU_AA8.CIHIValue in ('05')
	 group by LinkID
	 having Max(A3) is not null ) QuarterAssessment on CCRS.LinkID = QuarterAssessment.LinkID
left join  
	(select Max(DischargeDate) as DischargeDate, LinkID, max(AdmitDate) as AdmitDate
	 from CRS_Demographic CCRS with (nolock) inner join LU_CodeFile LU_AA8 with (nolock) on CCRS.AA8 = LU_AA8.Code
	 where AbstractID <> LinkID and LU_AA8.CIHIValue in ('06', '07', '08')
	 group by LinkID
	 having Max(DischargeDate) is not null ) DischargeAssessment on CCRS.LinkID = DischargeAssessment.LinkID
left join 
	(select Max(AdmitDate) as AssessmentDate, LinkID
	 from CRS_Demographic CCRS with (nolock) inner join LU_CodeFile LU_AA8 with (nolock) on CCRS.AA8 = LU_AA8.Code
	 where AbstractID <> LinkID and LU_AA8.CIHIValue in ('09')
	 group by LinkID
	 having Max(AdmitDate) is not null ) ReEntryAssessment on CCRS.LinkID = ReEntryAssessment.LinkID

where CCRS.AbstractID = CCRS.LinkID and (DischargeAssessment.LinkID is null 
or (DischargeAssessment.DischargeDate < ReEntryAssessment.AssessmentDate )
or (DischargeAssessment.DischargeDate = ReEntryAssessment.AssessmentDate and DischargeAssessment.AdmitDate < ReEntryAssessment.AssessmentDate))



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

---------------------------------------------  Central_Patient_Index_VR
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_Index_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Central_Patient_Index_VR]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_Index_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE    VIEW [dbo].[Central_Patient_Index_VR]
AS
SELECT dbo.CM_CPI.AlternateAddress, dbo.CM_CPI.AlternatePhone AS AlternatePhoneNumber, dbo.CM_CPI.BirthDate, dbo.CM_CPI.ChartNumber, 
    dbo.CM_CPI.CellPhone, dbo.CM_Notes.PatientNotes AS CPINotes, dbo.CM_CPI.DeathDate AS DatePatientDied, 
    LU_DeathIndicator.DisplayCode AS DeathIndicator, LU_DeathIndicator.UserDescription AS DeathIndicatorDesc, 
    LU_DiagMethod.DisplayCode AS DiagnosisMethod, LU_DiagMethod.UserDescription AS DiagnosisMethodDesc, dbo.CM_CPI.DuplicateChart, 
    Lookup1.DisplayCode AS Education, Lookup1.UserDescription AS EducationDesc, dbo.CM_CPI.EMail, dbo.CM_CPI.EmployerAddress, 
    dbo.CM_CPI.EmployerName, dbo.CM_CPI.EmployerFax, dbo.CM_CPI.EmployerPhone AS EmployerPhoneNumber, 
    dbo.CM_CPI.PhysicianAddress AS FamilyPhysicianAddress, dbo.CM_CPI.PhysicianNumber AS FamilyPhysicianName, 
    dbo.CM_CPI.PhysicianPhone AS FamilyPhysicianPhoneNumber, dbo.CM_CPI.FaxNumber, dbo.CM_CPI.FirstDiagDate AS FirstDiagnosisDate, 
    dbo.CM_CPI.FirstName, dbo.CM_CPI.FixedChartNumber,
    dbo.CM_CPI.FutureDate, Lookup2.DisplayCode AS Gender, Lookup2.UserDescription AS GenderDesc, 
    dbo.CM_CPI.GroupNum1 AS GroupInsuranceNumber1, dbo.CM_CPI.GroupNum2 AS GroupInsuranceNumber2, Lookup3.DisplayCode AS HCNProvince, 
    Lookup3.UserDescription AS HCNProvinceDesc, dbo.CM_CPI.HCNVersion, dbo.CM_CPI.HealthCareNumber, 
    
    LU_HighRisk.DisplayCode AS HighRisk,     LU_HighRisk.UserDescription AS HighRiskDesc, 
    
    LU_Hospital.DisplayCode AS Hospital,     LU_Hospital.UserDescription AS HospitalDesc, 
    IAR_AssessmentConsentFlag = LU_IAR_ConsentFlag.DisplayCode, IAR_AssessmentConsentFlagDesc = LU_IAR_ConsentFlag.UserDescription,

    dbo.CM_CPI.EmergAddress AS InEmergencyAddress, dbo.CM_CPI.EmergContact AS InEmergencyName,
    dbo.CM_CPI.EmergPhone AS InEmergencyPhoneNumber, Lookup4.DisplayCode AS InEmergencyRelationship, 
    Lookup4.UserDescription AS InEmergencyRelationshipDesc, dbo.LU_InsuranceCompany.DisplayCode AS InsuranceCompany1, 
    dbo.LU_InsuranceCompany.UserDescription AS InsuranceCompany1Desc, LU_InsuranceCompany_1.DisplayCode AS InsuranceCompany2, 
    LU_InsuranceCompany_1.UserDescription AS InsuranceCompany2Desc, dbo.CM_CPI.InsurPolicy1 AS InsurancePolicy1, 
    dbo.CM_CPI.InsurPolicy2 AS InsurancePolicy2, Lookup5.DisplayCode AS IsBirthdateEstimated, Lookup5.UserDescription AS IsBirthdateEstimatedDesc,
    LU_PrintLabel.DisplayCode AS LabelPrinted, LU_PrintLabel.UserDescription AS LabelPrintedDesc, Lookup6.DisplayCode AS [Language], 
    Lookup6.UserDescription AS LanguageDesc, dbo.CM_CPI.LastName, dbo.CM_CPI.LastVisitDate, dbo.LU_Provider.DisplayCode AS LinkedProvider, 
    dbo.LU_Provider.UserDescription AS LinkedProviderDesc, Lookup7.DisplayCode AS LivingArrangement, Lookup7.UserDescription AS LivingArrangementDesc, 
    LU_LockedChart.DisplayCode AS LockedChart, LU_LockedChart.UserDescription AS LockedChartDesc, 
    dbo.CM_CPI.MaidenName, Lookup8.DisplayCode AS MaritalStatus, 
    Lookup8.UserDescription AS MaritalStatusDesc, CM_CPI_1.ChartNumber AS MasterChart, dbo.CM_CPI.MedReferralDate AS MedicalReferralDate, 
    dbo.CM_CPI.MiddleName, dbo.CM_CPI.MothersChart, dbo.CM_CPI.BirthName AS NameAtBirth, ISNULL(dbo.CM_CPI.LastName, '' '') 
    + '', '' + ISNULL(dbo.CM_CPI.FirstName, '' '') + '' '' + ISNULL(dbo.CM_CPI.MiddleName, '''') AS NameFull, dbo.CM_CPI.NextKinAddress AS NextofKinAddress, 
    dbo.CM_CPI.NextKin AS NextofKinName, dbo.CM_CPI.NextKinPhone AS NextofKinPhoneNumber, Lookup9.DisplayCode AS NextofKinRelationship, 
    Lookup9.UserDescription AS NextofKinRelationshipDesc, Lookup10.DisplayCode AS Occupation, Lookup10.UserDescription AS OccupationDesc, 
    dbo.LU_CPIOption1.DisplayCode AS OptionField1, dbo.LU_CPIOption1.UserDescription AS OptionField1Desc, 
    dbo.LU_CPIOption2.DisplayCode AS OptionField2, dbo.LU_CPIOption2.UserDescription AS OptionField2Desc, dbo.CM_CPI.BirthPlace AS PlaceofBirth, 
    dbo.CM_CPI.PrevAddress AS PreviousAddress, dbo.CM_CPI.PrevPhone AS PreviousPhone, dbo.CM_CPI.PostalCode, dbo.CM_CPI.PrimaryAddress, 

    -- ED - 01682
    dbo.GetPostalDescription(isnull(dbo.CM_CPI.PostalCode, ''''), getdate()) AS PostalCodeDesc, -- ED - 01682

    dbo.CM_CPI.PrimaryAddress2, dbo.CM_CPI.City AS PrimaryCity, dbo.LU_CPI_Country.DisplayCode AS PrimaryCountry, 
    dbo.LU_CPI_Country.UserDescription AS PrimaryCountryDesc, dbo.LU_CPI_Province.DisplayCode AS PrimaryProvince, 
    dbo.LU_CPI_Province.UserDescription AS PrimaryProvinceDesc, dbo.CM_CPI.PrimaryPhone AS PrimaryPhoneNumber, 
    dbo.CM_CPI.RadReferralDate AS RadiationReferralDate, 
    --pr - 03389
    dbo.LU_Region.DisplayCode AS RegionCode, dbo.LU_Region.UserDescription AS RegionCodeDesc, 
    Lookup12.DisplayCode AS ResidenceCode, Lookup12.UserDescription AS ResidenceCodeDesc, 
    Lookup13.DisplayCode AS ResidenceType, Lookup13.UserDescription AS ResidenceTypeDesc, 
    CM_CPI.ROILegalComments,
    dbo.CM_CPI.Salutation, Lookup14.DisplayCode AS SecretVIPPatient, Lookup14.UserDescription AS SecretVIPPatientDesc, 
    LU_CodeFile_1.DisplayCode AS SensitivityLevel, LU_CodeFile_1.UserDescription AS SensitivityLevelDesc, 
    dbo.CM_CPI.SocialInsurNumber AS SocialInsuranceNumber, dbo.CM_CPI.SupCareReferralDate AS SupportiveCareReferralDate, 
    dbo.CM_CPI.UniqiueLifetimeID, dbo.CM_CPI.WSIB, 
    dbo.CM_CPI.PatientID AS zzPatientLink,
    dbo.CM_CPI.RegionalPatientID as zzRegionalPatientID 
FROM dbo.CM_CPI with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_1 with (nolock) ON dbo.CM_CPI.SensitivityLevel = LU_CodeFile_1.Code LEFT OUTER JOIN
    dbo.LU_InsuranceCompany LU_InsuranceCompany_1 with (nolock) ON dbo.CM_CPI.InsurCompany2 = LU_InsuranceCompany_1.Code LEFT OUTER JOIN
    dbo.LU_InsuranceCompany with (nolock) ON dbo.CM_CPI.InsurCompany1 = dbo.LU_InsuranceCompany.Code LEFT OUTER JOIN
    dbo.LU_CPI_Country with (nolock) ON dbo.CM_CPI.Country = dbo.LU_CPI_Country.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_DeathIndicator with (nolock) ON dbo.CM_CPI.DeathIndicator = LU_DeathIndicator.Code LEFT OUTER JOIN
    dbo.CM_CPI CM_CPI_1 with (nolock) ON dbo.CM_CPI.MasterChart = CM_CPI_1.PatientID LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_PrintLabel with (nolock) ON dbo.CM_CPI.LabelPrinted = LU_PrintLabel.Code LEFT OUTER JOIN
    dbo.H_HospitalProfile LU_Hospital with (nolock) ON dbo.CM_CPI.HospitalID = LU_Hospital.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_DiagMethod with (nolock) ON dbo.CM_CPI.DiagMethod = LU_DiagMethod.Code LEFT OUTER JOIN
    dbo.LU_CPI_Province with (nolock) ON dbo.CM_CPI.Province = dbo.LU_CPI_Province.Code LEFT OUTER JOIN
    dbo.LU_CPIOption1 with (nolock) ON dbo.CM_CPI.OptionField1 = dbo.LU_CPIOption1.Code LEFT OUTER JOIN
    dbo.LU_CPIOption2 with (nolock) ON dbo.CM_CPI.OptionField2 = dbo.LU_CPIOption2.Code LEFT OUTER JOIN
    dbo.LU_Provider with (nolock) ON dbo.CM_CPI.LinkProviderNumber = dbo.LU_Provider.Code LEFT OUTER JOIN
    dbo.CM_Notes with (nolock) ON dbo.CM_CPI.PatientID = dbo.CM_Notes.PatientID LEFT OUTER JOIN
    dbo.LU_Education Lookup1 with (nolock) ON dbo.CM_CPI.EducationLevel = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_Gender_I Lookup2 with (nolock) ON dbo.CM_CPI.Gender = Lookup2.Code LEFT OUTER JOIN
    dbo.LU_HCNProvince Lookup3 with (nolock) ON dbo.CM_CPI.HCNProvince = Lookup3.Code LEFT OUTER JOIN
    dbo.LU_Relationship Lookup4 with (nolock) ON dbo.CM_CPI.EmergRelation = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup5 with (nolock) ON dbo.CM_CPI.BirthDateEstimated = Lookup5.Code LEFT OUTER JOIN
    dbo.LU_Language Lookup6 with (nolock) ON dbo.CM_CPI.LanguageCode = Lookup6.Code LEFT OUTER JOIN
    dbo.LU_LivingArrangement Lookup7 with (nolock) ON dbo.CM_CPI.LivingArrangement = Lookup7.Code LEFT OUTER JOIN
    dbo.LU_MaritalStatus Lookup8 with (nolock) ON dbo.CM_CPI.MaritalStatus = Lookup8.Code LEFT OUTER JOIN
    dbo.LU_Relationship Lookup9 with (nolock) ON dbo.CM_CPI.NextKinRelation = Lookup9.Code LEFT OUTER JOIN
    dbo.LU_Occupation Lookup10 with (nolock) ON dbo.CM_CPI.Occupation = Lookup10.Code LEFT OUTER JOIN
    dbo.LU_ResidenceCode Lookup12 with (nolock) ON dbo.CM_CPI.ResidenceCode = Lookup12.Code LEFT OUTER JOIN
    dbo.LU_ResidenceType Lookup13 with (nolock) ON dbo.CM_CPI.ResidenceType = Lookup13.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup14 with (nolock) ON dbo.CM_CPI.Secret = Lookup14.Code LEFT OUTER JOIN
    dbo.LU_YesBlank LU_LockedChart with (nolock) ON dbo.CM_CPI.LockedChart = LU_LockedChart.Code LEFT OUTER JOIN
    --PR - 03389
    dbo.LU_Region with (nolock) ON Lookup12.RegionCode = dbo.LU_Region.Code left OUTER JOIN
    --PR - 05833
    dbo.LU_CodeFile LU_IAR_ConsentFlag with (nolock) ON dbo.CM_CPI.IAR_ConsentFlag = LU_IAR_ConsentFlag.Code left join
    dbo.LU_CodeFile LU_HighRisk with (nolock) ON dbo.CM_CPI.HighRisk = LU_HighRisk.Code 
    
--QA - 00032 disable the domain securite issue
----PR - 07485
--where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or CM_CPI.HospitalID is null or CM_CPI.HospitalID = 0
--    --EN - 00666
--    or Is_Member(nullif(ReportGroup, '''')) = 1
----    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(CM_CPI.HospitalID, 0))



' 
GO



---Others views
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[WorkloadMeasurement_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[WorkloadMeasurement_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[VisitHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[VisitHistory_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ViewsStructure_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[ViewsStructure_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[View_Report_Dictionary]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[View_Report_Dictionary]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[UserProfile_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[UserProfile_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[UserProfile_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[UserProfile_UpdateHistory_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[UD_RelOI_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[UD_RelOI_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[UD_I9_AbstractingMB_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[UD_I9_AbstractingMB_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[UD_Central_Patient_Index_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[UD_Central_Patient_Index_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[UD_Abstracting_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[UD_Abstracting_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Signature_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Signature_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_SubmissionRecord_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Sec_SubmissionRecord_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_SubmissionAudit]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Sec_SubmissionAudit]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_SearchDetailCPI_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Sec_SearchDetailCPI_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_SearchDetail_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Sec_SearchDetail_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_Search_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Sec_Search_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_ReportHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Sec_ReportHistory_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_Purged_Information_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Sec_Purged_Information_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_LoginAudit_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Sec_LoginAudit_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_EncoderLog_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Sec_EncoderLog_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_AbstractAudit_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Sec_AbstractAudit_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[RelOIUpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[RelOIUpdateHistory_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[RelOISentItems_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[RelOISentItems_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[RelOIPayments_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[RelOIPayments_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[RelOIActions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[RelOIActions_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ReIOIMain_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[ReIOIMain_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ReIOIDocument_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[ReIOIDocument_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[RehabErrorsWarnings_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[RehabErrorsWarnings_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[RehabAdmissionFIM_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[RehabAdmissionFIM_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[RehabAdmission_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[RehabAdmission_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_UpdateHistory_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_UD_Abstracting_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_UD_Abstracting_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_RPG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_RPG_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_RecordInformation_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_RecordInformation_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_Providers_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_Providers_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_Projects_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_Projects_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_Notes_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_Notes_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_Interventions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_Interventions_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_Interrupt_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_Interrupt_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_InHospital_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_InHospital_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_FIM_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_FIM_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_Diagnosis_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_BasicOption_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_BasicOption_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_Ancillary_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_Ancillary_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Purged_Record_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Purged_Record_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[PAC10_CACS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[PAC10_CACS_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRSErrorsWarnings_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRSErrorsWarnings_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRSbyElementID_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRSbyElementID_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_UpdateHistory_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_UD_Abstracting_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_UD_Abstracting_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_Serv_Interrupt_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_Serv_Interrupt_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_SCIPP_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_SCIPP_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_RoleRelations_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_RoleRelations_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_ResDischarge_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_ResDischarge_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_ReferenceDate_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_ReferenceDate_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_RecordInformation_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_RecordInformation_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_QualityIndicators_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_QualityIndicators_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_Providers_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_Providers_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_Projects_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_Projects_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_Notes_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_Notes_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_MHAPS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_MHAPS_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_Medication_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_Medication_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_MedicalDiagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_MedicalDiagnosis_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_Interventions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_Interventions_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_InHospital_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_InHospital_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_IAR_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_IAR_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_DSM_Diag_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_DSM_Diag_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_DSM_Diag_AxisII_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_DSM_Diag_AxisII_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_DSM_5_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_DSM_5_Diagnosis_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_CIHIErrors_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_CIHIErrors_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_BasicOption_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_BasicOption_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_AncillaryField_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[OMHRS_AncillaryField_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Messages_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Messages_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Merge_Volume_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Merge_Volume_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Merge_ROI_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Merge_ROI_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Merge_Records_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Merge_Records_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Merge_Main_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Merge_Main_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Merge_Deficiency_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Merge_Deficiency_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_UpdateHistory_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_UD_Abstracting_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_UD_Abstracting_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Signature_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Signature_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Shared_5_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Shared_5_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Shared_4_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Shared_4_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Shared_3_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Shared_3_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Shared_2_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Shared_2_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Shared_1_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Shared_1_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_RUGS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_RUGS_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_RUGS_Plus_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_RUGS_Plus_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_RUGS_34_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_RUGS_34_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_RAP_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_RAP_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quality_Indicators_Detail_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Quality_Indicators_Detail_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_PURS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_PURS_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Outcome_Scales]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Outcome_Scales]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Out_Hospital_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Out_Hospital_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Notes_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Notes_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Next_Assessment_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Next_Assessment_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Medication_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Medication_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Last_Submitted_Assessment_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Last_Submitted_Assessment_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Last_Assessment_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Last_Assessment_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_In_Hospital_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_In_Hospital_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Hobic_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Hobic_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_General_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_General_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_2_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_FULL_2_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_1_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_FULL_1_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_First_Assessment_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_First_Assessment_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_ErrorsWarnings_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_ErrorsWarnings_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Diagnosis_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_CAP_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_CAP_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_BasicOption_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_BasicOption_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Admission_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Admission_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_2010_QI_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_2010_QI_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDAS_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDAS_UpdateHistory_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDAS_AuditTrail_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDAS_AuditTrail_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[M_DatabaseUpdates_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[M_DatabaseUpdates_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LUProviderSuspension_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[LUProviderSuspension_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_ProviderUnavailable_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[LU_ProviderUnavailable_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_ProviderSpecialties_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[LU_ProviderSpecialties_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_ProviderServices_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[LU_ProviderServices_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_ProviderLog_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[LU_ProviderLog_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_Provider_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[LU_Provider_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_PostalCode_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[LU_PostalCode_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_LookUpTableName_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[LU_LookUpTableName_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_InterventionCat_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[LU_InterventionCat_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_Intervention_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[LU_Intervention_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_DiagnosisCat_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[LU_DiagnosisCat_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[LU_Diagnosis_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_UpdateHistory_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Submissions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Submissions_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_SpecialCareUnits_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_SpecialCareUnits_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_QBP_Flag]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_QBP_Flag]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Provider_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Provider_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Projects_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_Question_24_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Projects_Question_24_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_740_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Projects_740_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_640_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Projects_640_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_340_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Projects_340_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_316_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Projects_316_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_315_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Projects_315_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_250_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Projects_250_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_202_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Projects_202_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_150_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Projects_150_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_100_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Projects_100_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_065_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Projects_065_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_060_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Projects_060_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_PatientService_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_PatientService_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Obstetrics_Newborn_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Obstetrics_Newborn_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_MB_TransferWorksheet_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_MB_TransferWorksheet_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_MB_ReproductiveNewborn_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_MB_ReproductiveNewborn_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_MB_NonALC_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_MB_NonALC_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_MB_FacilityStudy_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_MB_FacilityStudy_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_MB_ALC_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_MB_ALC_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Interventions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Interventions_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_InterventionReplicate_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_InterventionReplicate_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_HIG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_HIG_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_DPG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_DPG_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_DiagnosisToICD9cm_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_DiagnosisToICD9cm_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Diagnosis_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_CRS_General_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_CRS_General_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_CMGOntPerc2002_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_CMGOntPerc2002_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_CMGAverages_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_CMGAverages_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_CMG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_CMG_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_CMG_NonComplex_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_CMG_NonComplex_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_CMG_2002Percentile]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_CMG_2002Percentile]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_BasicOption_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_BasicOption_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AmcareRecordKey_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_AmcareRecordKey_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AmcareGeneral_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_AmcareGeneral_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AmcareCIHIErrors]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_AmcareCIHIErrors]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_statistic_Reporting_BC_2009]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_statistic_Reporting_BC_2009]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_statistic_Reporting_BC]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_statistic_Reporting_BC]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_statistic_Reporting_2009]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_statistic_Reporting_2009]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_statistic_Reporting]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_statistic_Reporting]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Providers_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Providers_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_Question_24_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_Question_24_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_966_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_966_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_965_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_965_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_964_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_964_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_963_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_963_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_962_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_962_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_961_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_961_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_960_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_960_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_740_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_740_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_640_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_640_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_340_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_340_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_316_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_316_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_315_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_315_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_250_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_250_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_202_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_202_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_150_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_150_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_100_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_100_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_065_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_065_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_060_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Projects_060_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Profile_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Profile_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_PresentingComplaint]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_PresentingComplaint]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_MIS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_MIS_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Level1_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Level1_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Interventions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Interventions_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_InterventionReplication_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_InterventionReplication_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_EDInvestigativeTechnology_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_EDInvestigativeTechnology_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_EDInterventionPicklist_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_EDInterventionPicklist_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_DischargeDiagnosis]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_DischargeDiagnosis]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Diagnosis_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Consult_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_Consult_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AmCare_CCM_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_AmCare_CCM_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AmCare_CCM_SystemicDrug_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_AmCare_CCM_SystemicDrug_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AmCare_CACS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_AmCare_CACS_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AllAbstractingGeneral1_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_AllAbstractingGeneral1_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AbstractNotes_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_AbstractNotes_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AbstractingRecordKey_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_AbstractingRecordKey_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AbstractingInterventionReplicate_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_AbstractingInterventionReplicate_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AbstractingGeneral_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_AbstractingGeneral_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AbstractingBasics1_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_AbstractingBasics1_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstracting_Profile_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstracting_Profile_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstracting]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstracting]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AbstractCIHIErrors_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_AbstractCIHIErrors_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_CJRR_Parts]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_CJRR_Parts]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_CJRR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_CJRR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_CACS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_CACS_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Grouper_Audit_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Grouper_Audit_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[EMT_Logical_Conditions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[EMT_Logical_Conditions_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[EMT_FieldConditions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[EMT_FieldConditions_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[EMT_Edits_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[EMT_Edits_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_SpecialCareUnits_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[DAD_SpecialCareUnits_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_Provider_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[DAD_Provider_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_Projects_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[DAD_Projects_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_PatientService_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[DAD_PatientService_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_MB_NonALC_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[DAD_MB_NonALC_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_MB_FacilityStudy_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[DAD_MB_FacilityStudy_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_MB_ALC_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[DAD_MB_ALC_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_Interventions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[DAD_Interventions_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_DPG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[DAD_DPG_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[DAD_Diagnosis_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_CMG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[DAD_CMG_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_Abstracting_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[DAD_Abstracting_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CMG_Benchmarks_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CMG_Benchmarks_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CJRR_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CJRR_UpdateHistory_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_UD_Abstracting_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CJRR_UD_Abstracting_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_TibialInsert_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CJRR_TibialInsert_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_TibialComponent_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CJRR_TibialComponent_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_PatellarComponent_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CJRR_PatellarComponent_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_FemoralHead_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CJRR_FemoralHead_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_FemoralComponent_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CJRR_FemoralComponent_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_ErrorsWarnings_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CJRR_ErrorsWarnings_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_Cement_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CJRR_Cement_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_AcetabularInsert_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CJRR_AcetabularInsert_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_AcetabularComponent_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CJRR_AcetabularComponent_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ChartVisitHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[ChartVisitHistory_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ChartNumberMasked_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[ChartNumberMasked_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ChartLocatorCurrentAct_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[ChartLocatorCurrentAct_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ChartLocator_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[ChartLocator_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ChartLocator_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[ChartLocator_UpdateHistory_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ChartLocator_PullList_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[ChartLocator_PullList_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ChartLocator_PullList_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[ChartLocator_PullList_UpdateHistory_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Chart_DeficiencyStatusbyVisit_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Chart_DeficiencyStatusbyVisit_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Chart_Deficiency_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Chart_Deficiency_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Chart_Deficiency_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Chart_Deficiency_UpdateHistory_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Chart_Deficiency_Transfer_History_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Chart_Deficiency_Transfer_History_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Chart_Deficiency_Current_Transfer_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Chart_Deficiency_Current_Transfer_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_Volume_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Central_Patient_Volume_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_Volume_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Central_Patient_Volume_UpdateHistory_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Central_Patient_UpdateHistory_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_RiskFactors_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Central_Patient_RiskFactors_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_MergeChart_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Central_Patient_MergeChart_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_LinkedChart_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Central_Patient_LinkedChart_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_Index_Notes_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Central_Patient_Index_Notes_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_Index_Alias_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Central_Patient_Index_Alias_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_Contacts_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Central_Patient_Contacts_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_BabyChart_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Central_Patient_BabyChart_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_Alias_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Central_Patient_Alias_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_Alerts_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Central_Patient_Alerts_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CCM_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CCM_UpdateHistory_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_UD_Abstracting_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CCM_UD_Abstracting_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_NDFP_Enrollment_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CCM_NDFP_Enrollment_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_HealthCareProfessional_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CCM_HealthCareProfessional_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_Entity_SysDrugDelivery_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CCM_Entity_SysDrugDelivery_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_Entity_RadPlanTreatActivity_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CCM_Entity_RadPlanTreatActivity_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_Entity_Patient_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CCM_Entity_Patient_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_Entity_NDFP_Enrollment_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CCM_Entity_NDFP_Enrollment_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_Entity_Healthcare_Professional_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CCM_Entity_Healthcare_Professional_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_Entity_Disease_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CCM_Entity_Disease_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_Entity_ClinicVisit_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CCM_Entity_ClinicVisit_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_AbstractNotes_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[CCM_AbstractNotes_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Amcare_Providers_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Amcare_Providers_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Amcare_Projects_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Amcare_Projects_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Amcare_MIS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Amcare_MIS_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Amcare_Interventions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Amcare_Interventions_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Amcare_DPG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Amcare_DPG_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Amcare_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Amcare_Diagnosis_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Amcare_CACS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Amcare_CACS_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Amcare_Abstracting_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Amcare_Abstracting_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[AbstractQueue_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[AbstractQueue_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[AbstractQueue_LOG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[AbstractQueue_LOG_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[AbstractingErrorsWarnings_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[AbstractingErrorsWarnings_VR]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[AbstractingErrorsWarnings_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[AbstractingErrorsWarnings_VR]
AS
SELECT 
    CIHI_ElementID = U_UsersFields.CIHI_ID,
    FieldName = U_UsersFields.Header_User, 
    --ErrorMessage = dbo.MG_Messages.MessageText, 
    MessageLevel = CASE AB_ErrorMessages.MessageType WHEN 1 THEN ''Warning'' 
                                    WHEN 2 THEN ''Error'' 
                                    WHEN 3 THEN ''Critical'' 
                                    WHEN 0 THEN ''Information'' 
                                    WHEN 5 THEN ''Question'' 
									WHEN 4 THEN ''Custom Warning'' 
									WHEN 8 THEN ''Custom Critical'' 
									WHEN 9 THEN ''Custom Error'' 
									WHEN 10 THEN ''Custom Information'' 
					END, 
    MessageType = CASE when AB_ErrorMessages.MessageType in (4, 8, 9, 10) THEN ''EMT'' ELSE '''' END, 
    AB_ErrorMessages.MessageText, 
    AB_ErrorMessages.SaveDate, 
    AB_ErrorMessages.AbstractID AS zzAbstractLink
FROM dbo.AB_ErrorMessages with (nolock)
    --left join dbo.MG_Messages with (nolock)
    --    on dbo.AB_ErrorMessages.MessageKey = dbo.MG_Messages.MessageKey
    left join dbo.AB_ErrorMessageFields with (nolock)
        on dbo.AB_ErrorMessages.AppID = dbo.AB_ErrorMessageFields.AppID
            and dbo.AB_ErrorMessages.AbstractID = dbo.AB_ErrorMessageFields.AbstractID 
            and dbo.AB_ErrorMessages.MessageKey = dbo.AB_ErrorMessageFields.MessageKey
    left join dbo.U_UsersFields with (nolock) 
        on UserID = 1 and dbo.AB_ErrorMessages.AppID = dbo.U_UsersFields.AppID and 
        (case when isnumeric(replace(dbo.AB_ErrorMessageFields.FieldKey, ''FK'', '''')) = 1 
              then replace(dbo.AB_ErrorMessageFields.FieldKey, ''FK'', '''')
              else 0 end) = dbo.U_UsersFields.FieldID 
Where AB_ErrorMessages.appid in (100,101,102,200,201,202,301,401)



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[AbstractQueue_LOG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE view  [dbo].[AbstractQueue_LOG_VR] 
as
select
    AB_Abstract.AdmitDate, 
    AB_Abstract.AdmitTime, 
    LU_AssignedBy.DisplayCode as AssignedBy,     LU_AssignedBy.UserDescription as AssignedByDesc, 
    AssignedTime,
    AB_Abstract.ChartNumber,
    LU_Coder.DisplayCode as Coder,     LU_Coder.UserDescription as CoderDesc, 
    (case when AB_AbstractQueueLog.IsCompleted = ''Y'' then LU_CompletedBy.DisplayCode else null end) as CompletedBy,     
    (case when AB_AbstractQueueLog.IsCompleted = ''Y'' then LU_CompletedBy.UserDescription else null end) as CompletedByDesc, 
    dbo.AB_AbstractQueueLog.CompletedTime,
    (case AB_Abstract.CareType when 1 then ''Inpatient'' when 2 then ''SDS'' when 5 then ''Amcare'' else '''' end) as CareType ,
    --LoanLU_Location.DisplayCode as CurrentLocation,     LoanLU_Location.UserDescription as CurrentLocationDesc, 
    AB_Abstract.DischargeDate, 
    AB_Abstract.DischargeTime, 
    AB_Abstract.FirstName,
    H_InstitutionProfile.Displaycode as InstitutionNumber,     H_InstitutionProfile.UserDescription as InstitutionNumberDesc,
    (case when AB_AbstractQueueLog.IsCompleted = ''Y'' then ''Yes'' else ''No'' end) as IsCompleted,
    LU_MISCode.DisplayCode as MISCode,     LU_MISCode.UserDescription as MISCodeDesc, 
    AB_Abstract.LastName,
    AB_Abstract.EncounterNumber as RegistrationNumber,
    (case when AB_AbstractQueueLog.IsCompleted = ''N'' then LU_CompletedBy.DisplayCode else null end) as UnassignedBy,     
    (case when AB_AbstractQueueLog.IsCompleted = ''N'' then LU_CompletedBy.UserDescription else null end) as UnassignedByDesc, 
    AB_AbstractQueueLog.AbstractID as zzAbstractLink
from dbo.AB_AbstractQueueLog with (nolock) 
    inner join AB_Abstract with (nolock) on AB_AbstractQueueLog.AbstractID = AB_Abstract.AbstractID
    inner join H_InstitutionProfile with (nolock) on H_InstitutionProfile.Code = AB_Abstract.InstitutionNumber
    left join LU_MISCode with (nolock) on LU_MISCode.Code = AB_Abstract.MISCode
    left join U_Users LU_Coder with (nolock) on LU_Coder.Code = AB_AbstractQueueLog.Coder
    left join U_Users LU_AssignedBy with (nolock) on LU_AssignedBy.Code = AB_AbstractQueueLog.AssignedBy
    left join U_Users LU_CompletedBy with (nolock) on LU_CompletedBy.Code = AB_AbstractQueueLog.CompletedBy
    --left join CM_CPI_Volume with (nolock) on CM_CPI_Volume.VolumeID = AB_Abstract.VolumeID
    --left join LoanLU_Location with (nolock) on CM_CPI_Volume.CLCurrentLocation = LoanLU_Location.Code
    

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[AbstractQueue_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE view [dbo].[AbstractQueue_VR] 
as
select
    AB_Abstract.AdmitDate, 
    AB_Abstract.AdmitTime, 
    LU_AssignedBy.DisplayCode as AssignedBy,     LU_AssignedBy.UserDescription as AssignedByDesc, 
    AssignedTime,
    AB_Abstract.ChartNumber,
    LU_Coder.DisplayCode as Coder,     LU_Coder.UserDescription as CoderDesc, 
    (case AB_Abstract.CareType when 1 then ''Inpatient'' when 2 then ''SDS'' when 5 then ''Amcare'' else '''' end) as CareType ,
    LoanLU_Location.DisplayCode as CurrentLocation,     LoanLU_Location.UserDescription as CurrentLocationDesc, 
    AB_Abstract.DischargeDate, 
    AB_Abstract.DischargeTime, 
    AB_Abstract.FirstName,
    H_InstitutionProfile.Displaycode as InstitutionNumber,     H_InstitutionProfile.UserDescription as InstitutionNumberDesc, 
    LU_MISCode.DisplayCode as MISCode,     LU_MISCode.UserDescription as MISCodeDesc, 
    AB_Abstract.LastName,
    AB_Abstract.EncounterNumber as RegistrationNumber,
    CM_CPI_Volume.VolumeNumber, 
    AB_AbstractQueue.AbstractID as zzAbstractLink,
    AB_Abstract.VolumeID as zzVolumeLink
from dbo.AB_AbstractQueue with (nolock) 
    inner join AB_Abstract with (nolock) on AB_AbstractQueue.AbstractID = AB_Abstract.AbstractID
    inner join H_InstitutionProfile with (nolock) on H_InstitutionProfile.Code = AB_Abstract.InstitutionNumber
    left join LU_MISCode with (nolock) on LU_MISCode.Code = AB_Abstract.MISCode
    left join U_Users LU_Coder with (nolock) on LU_Coder.Code = AB_AbstractQueue.Coder
    left join U_Users LU_AssignedBy with (nolock) on LU_AssignedBy.Code = AB_AbstractQueue.AssignedBy
    left join CM_CPI_Volume with (nolock) on CM_CPI_Volume.VolumeID = AB_Abstract.VolumeID
    left join LoanLU_Location with (nolock) on CM_CPI_Volume.CLCurrentLocation = LoanLU_Location.Code
where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB_ABstract.HospitalID is null or AB_ABstract.HospitalID = 0
    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB_ABstract.HospitalID, 0))
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Amcare_Abstracting_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[Amcare_Abstracting_VR]
AS
SELECT     
    dbo.AB_ReproductiveCare.PrevPreTermDelivery AS [#ofPreviousPreTermDeliveries], 
    dbo.AB_ReproductiveCare.PrevSpontAbortions AS [#ofPrevSpontaneousAbortions], 
    dbo.AB_ReproductiveCare.PrevTermDelivery AS [#ofPreviousTermDeliveries], 
    dbo.AB_ReproductiveCare.PrevInduceAbortions AS [#ofPrevTherapeuticAbortions], 
    Lookup1.DisplayCode AS AWOL, Lookup1.UserDescription AS AWOLDesc, 
    dbo.AB_ReproductiveCare.AbortionDate AS AbortDate, 
    dbo.AB_Abstract.AbstractNumber, 
    LU_AbstractOverflow.DisplayCode as AbstractOverflow, LU_AbstractOverflow.UserDescription as AbstractOverflowDesc,
    dbo.AB_Abstract.InjuryActivityDescription AS ActivityDescription, 
    Lookup2.DisplayCode AS ActivityWhenInjured, Lookup2.UserDescription AS ActivityWhenInjuredDesc, 
    dbo.AB_Abstract.AcuteLOS AS ActueLOS, 
    Lookup3.DisplayCode AS AdmitbyAmbulance, Lookup3.UserDescription AS AdmitbyAmbulanceDesc, 
    dbo.AB_Abstract.AdmitCategory, dbo.AB_Abstract.AdmittingDiagnosis AS AdmitDiagnosis, 
    dbo.AB_Abstract.AdmittingNurseArea AS AdmitNursingArea, 
    --dbo.AB_DeathInformation.DeathAfterAdmit AS AfterAdmit, 
    Lookup4.DisplayCode AS AgeCode, Lookup4.UserDescription AS AgeCodeDesc, 
    dbo.AB_Abstract.AgeGroup, dbo.AB_Abstract.AgeNumber, 
    Lookup5.DisplayCode AS Albumin, Lookup5.UserDescription AS AlbuminDesc, 
    Lookup6.DisplayCode AS AlbuminCrossMatched, Lookup6.UserDescription AS AlbuminCrossMatchedDesc, 
    Lookup7.DisplayCode AS AlbuminTyped, Lookup7.UserDescription AS AlbuminTypedDesc, 
    dbo.AB_Blood.AlbuminUnits, dbo.AB_Abstract.ALCLOS, dbo.AB_Abstract.AmbulanceReportNumber, 
    Lookup8.DisplayCode AS AncillaryField1,   Lookup8.UserDescription AS AncillaryField1Desc, 
    Lookup9.DisplayCode AS AncillaryField10,  Lookup9.UserDescription AS AncillaryField10Desc, 
    Lookup10.DisplayCode AS AncillaryField11, Lookup10.UserDescription AS AncillaryField11Desc, 
    Lookup11.DisplayCode AS AncillaryField12, Lookup11.UserDescription AS AncillaryField12Desc, 
    dbo.AB_Ancillary.AncillaryField13 AS AncillaryField13, 
    dbo.AB_Ancillary.AncillaryField14 AS AncillaryField14, 
    dbo.AB_Ancillary.AncillaryField15 AS AncillaryField15, 
    dbo.AB_Ancillary.AncillaryField16 AS AncillaryField16, 
    dbo.AB_Ancillary.AncillaryField17 AS AncillaryField17, 
    Lookup12.DisplayCode AS AncillaryField2,  Lookup12.UserDescription AS AncillaryField2Desc, 
    Lookup13.DisplayCode AS AncillaryField3,  Lookup13.UserDescription AS AncillaryField3Desc, 
    Lookup14.DisplayCode AS AncillaryField4,  Lookup14.UserDescription AS AncillaryField4Desc, 
    Lookup15.DisplayCode AS AncillaryField5,  Lookup15.UserDescription AS AncillaryField5Desc, 
    Lookup16.DisplayCode AS AncillaryField6,  Lookup16.UserDescription AS AncillaryField6Desc, 
    Lookup17.DisplayCode AS AncillaryField7,  Lookup17.UserDescription AS AncillaryField7Desc, 
    Lookup18.DisplayCode AS AncillaryField8,  Lookup18.UserDescription AS AncillaryField8Desc, 
    Lookup19.DisplayCode AS AncillaryField9,  Lookup19.UserDescription AS AncillaryField9Desc, 
    dbo.AB_Abstract.ArrivalDate, 
    Lookup22.DisplayCode AS ArrivalMode, Lookup22.UserDescription AS ArrivalModeDesc, 
    dbo.AB_Abstract.ArrivalTime, 
    dbo.AB_Abstract.ArrivalTriageDifference AS ArrivaltoTriageTime, 
    dbo.AB_Abstract.AssessmentDate, dbo.AB_Abstract.AssessmentTime, 
    Lookup159.DisplayCode AS AssessmentTimeUnknown, Lookup159.UserDescription AS AssessmentTimeUnknownDesc, 
    dbo.AB_Abstract.AttendingPhysician, 
    Lookup23.DisplayCode AS AutoTransfusion, Lookup23.UserDescription AS AutoTransfusionDesc, 
    Lookup24.DisplayCode AS AutopsyPerformed, Lookup24.UserDescription AS AutopsyPerformedDesc, 
    Lookup25.DisplayCode AS BasicOption1,  Lookup25.UserDescription AS BasicOption1Desc, 
    Lookup26.DisplayCode AS BasicOption10, Lookup26.UserDescription AS BasicOption10Desc, 
    Lookup27.DisplayCode AS BasicOption11, Lookup27.UserDescription AS BasicOption11Desc, 
    Lookup28.DisplayCode AS BasicOption12, Lookup28.UserDescription AS BasicOption12Desc, 
    Lookup29.DisplayCode AS BasicOption13, Lookup29.UserDescription AS BasicOption13Desc, 
    Lookup30.DisplayCode AS BasicOption14, Lookup30.UserDescription AS BasicOption14Desc, 
    Lookup31.DisplayCode AS BasicOption15, Lookup31.UserDescription AS BasicOption15Desc, 
    Lookup32.DisplayCode AS BasicOption16, Lookup32.UserDescription AS BasicOption16Desc, 
    Lookup33.DisplayCode AS BasicOption17, Lookup33.UserDescription AS BasicOption17Desc, 
    Lookup34.DisplayCode AS BasicOption18, Lookup34.UserDescription AS BasicOption18Desc, 
    Lookup35.DisplayCode AS BasicOption19, Lookup35.UserDescription AS BasicOption19Desc, 
    Lookup36.DisplayCode AS BasicOption2,  Lookup36.UserDescription AS BasicOption2Desc, 
    Lookup37.DisplayCode AS BasicOption3,  Lookup37.UserDescription AS BasicOption3Desc, 
    Lookup38.DisplayCode AS BasicOption4,  Lookup38.UserDescription AS BasicOption4Desc, 
    Lookup39.DisplayCode AS BasicOption5,  Lookup39.UserDescription AS BasicOption5Desc, 
    Lookup40.DisplayCode AS BasicOption6,  Lookup40.UserDescription AS BasicOption6Desc, 
    Lookup41.DisplayCode AS BasicOption7,  Lookup41.UserDescription AS BasicOption7Desc, 
    Lookup42.DisplayCode AS BasicOption8,  Lookup42.UserDescription AS BasicOption8Desc, 
    Lookup43.DisplayCode AS BasicOption9,  Lookup43.UserDescription AS BasicOption9Desc, 
    dbo.AB_Abstract.BatchNumber, 
    Lookup44.DisplayCode AS BatchPeriod, Lookup44.UserDescription AS BatchPeriodDesc, 
    dbo.AB_Abstract.BatchYear, 
    dbo.AB_Abstract.BirthDate, dbo.AB_ReproductiveCare.BreastFeeding, 
    Lookup45.DisplayCode AS ChangeinLegalStatus, Lookup45.UserDescription AS ChangeinLegalStatusDesc, 
    dbo.AB_Abstract.ChartNumber, 
    dbo.AB_Abstract.ChiefComplaint as ChiefComplaintUponAdmission, 
    Lookup46.DisplayCode AS CoderNumber, Lookup46.UserDescription AS CoderNumberDesc, 
    LUCompleteRecord.DisplayCode AS CompleteRecord, LUCompleteRecord.UserDescription AS CompleteRecordDesc, 

    LUComplication.DisplayCode as Complication, LUComplication.UserDescription as ComplicationDesc,

    Lookup47.DisplayCode AS Complication1, Lookup47.UserDescription AS Complication1Desc, 
    Lookup48.DisplayCode AS Complication2, Lookup48.UserDescription AS Complication2Desc, 
    Lookup49.DisplayCode AS Complication3, Lookup49.UserDescription AS Complication3Desc, 
    Lookup50.DisplayCode AS ContactMode,   Lookup50.UserDescription AS ContactModeDesc, 
    Lookup51.DisplayCode AS CoronerCase, Lookup51.UserDescription AS CoronerCaseDesc, 
    Lookup52.DisplayCode AS DataEntryCoder, Lookup52.UserDescription AS DataEntryCoderDesc, 
    dbo.AB_Abstract.DateLeftER, 
    dbo.AB_ReproductiveCare.LastMensesDate AS DateofLastMenses, 
    dbo.AB_Abstract.DateReadyDischarge AS DateReadyforDisch, 
    dbo.AB_Abstract.CIHIDateSent AS DateSenttoCIHI, 
    Lookup53.DisplayCode AS DeathInER, Lookup53.UserDescription AS DeathInERDesc, 
    Lookup54.DisplayCode AS DeathOnArrival, Lookup54.UserDescription AS DeathOnArrivalDesc, 
    dbo.AB_Abstract.DecisionAdmitDifference, 
    dbo.AB_Abstract.DecisionAdmitDate AS DecisiontoAdmitDate, 
    dbo.AB_Abstract.DecisionAdmitTime AS DecisiontoAdmitTime, 
    Lookup158.DisplayCode AS DecisionAdmitTimeUnknown, Lookup158.UserDescription AS DecisionAdmitTimeUnknownDesc, 
    dbo.AB_ReproductiveCare.DeliveryDate, dbo.AB_ReproductiveCare.DeliveryTime, 
    Lookup58.DisplayCode AS DiedDuringIntervention, Lookup58.UserDescription AS DiedDuringInterventionDesc, 
    dbo.AB_Abstract.DischargeNurseArea AS DischNursingArea, 
    Lookup59.DisplayCode AS DischPlanning, Lookup59.UserDescription AS DischPlanningDesc, 
    dbo.AB_Abstract.DischargeAge, 
    Lookup60.DisplayCode AS DischargeDisposition, Lookup60.UserDescription AS DischargeDispositionDesc, 
    dbo.AB_Abstract.DischargeDate AS DispositionDate, 
    dbo.AB_Abstract.DischargeTime AS DispositionTime, 
    Lookup61.DisplayCode AS ECTTreatment, Lookup61.UserDescription AS ECTTreatmentDesc, 
    Lookup64.DisplayCode AS Education, Lookup64.UserDescription AS EducationDesc, 
    Lookup65.DisplayCode AS Employment, Lookup65.UserDescription AS EmploymentDesc, 
    --dbo.AB_Abstract.EntryCode, 
    dbo.AB_Abstract.EstimatedDischargeDate AS EstimateDischDate, 
    --dbo.AB_Abstract.ExitCode, 
    Lookup67.DisplayCode AS FamilyPhysicianFlag, Lookup67.UserDescription AS FamilyPhysicianFlagDesc, 
    Lookup68.DisplayCode AS FinancialSupport, Lookup68.UserDescription AS FinancialSupportDesc, 
    dbo.AB_Abstract.FinishDate, dbo.AB_Abstract.FinishTime, dbo.AB_Abstract.FirstName, 
    ISNULL(dbo.AB_Abstract.LastName, '' '') + '', '' + ISNULL(dbo.AB_Abstract.FirstName, '''') + '' '' + ISNULL(dbo.AB_Abstract.MiddleName, '''') AS FullName, 
    Lookup69.DisplayCode AS Gender, Lookup69.UserDescription AS GenderDesc, 
    dbo.AB_ReproductiveCare.GestationalAge AS GestationalAgeinweeks, 
    Lookup157.DisplayCode AS GlasgowScale, Lookup157.UserDescription AS GlasgowScaleDesc, 
    --dbo.AB_DeathInformation.DeathGreaterTenPO AS GreaterTenPO, 
    Lookup70.DisplayCode AS HCNProvince, Lookup70.UserDescription AS HCNProvinceDesc, 
    dbo.AB_Abstract.HCNVersion, dbo.AB_Abstract.HealthCareNumber, 
    LU_Hospital.DisplayCode AS Hospital, LU_Hospital.UserDescription AS HospitalDesc, 
    LUHelmetIndicator.DisplayCode AS HelmetIndicator, LUHelmetIndicator.UserDescription AS HelmetIndicatorDesc, 
    -- dbo.AB_DeathInformation.DeathInSCU AS InSCU, 
    Lookup71.DisplayCode AS InitialOR, Lookup71.UserDescription AS InitialORDesc, 
    dbo.AB_Abstract.InjuryDate, 
    Lookup72.DisplayCode AS Injury, Lookup72.UserDescription AS InjuryDesc, 
    dbo.AB_Abstract.InputDate, dbo.AB_Abstract.InputTime, 
    Lookup73.DisplayCode AS InstitutionFrom, Lookup73.UserDescription AS InstitutionFromDesc, 
    InstitutionFrom9.DisplayCode AS InstitutionFrom9, InstitutionFrom9.UserDescription AS InstitutionFrom9Desc, 
    Lookup73.InstCareType AS InstFromCareType, Lookup73.HospitalType AS InstFromHospType, 

    Lookup74.DisplayCode AS InstitutionNumber, Lookup74.UserDescription AS InstitutionNumberDesc, 

    Lookup75.DisplayCode AS InstitutionTo, Lookup75.UserDescription AS InstitutionToDesc, 
    InstitutionTo9.DisplayCode AS InstitutionTo9, InstitutionTo9.UserDescription AS InstitutionTo9Desc, 
    Lookup75.InstCareType AS InstToCareType, Lookup75.HospitalType AS InstToHospType, 

    dbo.AB_Abstract.InterfaceDate, dbo.AB_Abstract.InterfaceTime, 
    Lookup83.DisplayCode AS IsAbstractCompleted, Lookup83.UserDescription AS IsAbstractCompletedDesc, 
    Lookup84.DisplayCode AS IsAbstractCorrected, Lookup84.UserDescription AS IsAbstractCorrectedDesc, 
    Lookup85.DisplayCode AS IsAbstractDeleted, Lookup85.UserDescription AS IsAbstractDeletedDesc, 
    Lookup86.DisplayCode AS IsAbstractSubmitted, Lookup86.UserDescription AS IsAbstractSubmittedDesc, 
    Lookup87.DisplayCode AS IsAbstractValidated, Lookup87.UserDescription AS IsAbstractValidatedDesc, 
    Lookup88.DisplayCode AS IsBirthdateEstimated, Lookup88.UserDescription AS IsBirthdateEstimatedDesc, 
    dbo.AB_Abstract.LOSDays, dbo.AB_Abstract.LOSTotal AS LOSTime, 
    dbo.AB_Abstract.LOSTime AS LOSTimeinHours, dbo.AB_Abstract.LOSMinutes AS LOSTotalMinutes, 
    Lookup89.DisplayCode AS [Language], Lookup89.UserDescription AS LanguageDesc, 
    dbo.AB_Abstract.LastName, 
    -- dbo.AB_DeathInformation.DeathLessTwoPO AS LessTwoPO, 
    Lookup90.DisplayCode AS LivingArrangement, Lookup90.UserDescription AS LivingArrangementDesc, 
    Lookup91.DisplayCode AS LocationofInjury,  Lookup91.UserDescription AS LocationofInjuryDesc, 
    Lookup93.DisplayCode AS MISCode, Lookup93.UserDescription AS MISCodeDesc, 
    dbo.AB_Abstract.MaidenName, 
    Lookup94.DisplayCode AS MaritalStatus, Lookup94.UserDescription AS MaritalStatusDesc, 
    Lookup95.DisplayCode AS MethodofAdmission, Lookup95.UserDescription AS MethodofAdmissionDesc, 
    dbo.AB_Abstract.MiddleName, dbo.AB_Abstract.NewbornChart, 
    dbo.AB_Abstract.NewbornDischargeDate AS NewbornDischDate, 
    dbo.AB_Abstract.NextSchedVisitDate AS NextScheduledVisitDate, 
    dbo.AB_Abstract.NextSchedVisitTime AS NextScheduledVisitTime, 
    dbo.AB_MentalHealth.MentalNumberECT AS NumberofECT, 
    dbo.AB_Abstract.NurseAssessDate AS NursingAssessmentDate, 
    dbo.AB_Abstract.NurseAssessTime AS NursingAssessmentTime, 
    Lookup98.DisplayCode AS Occupation, Lookup98.UserDescription AS OccupationDesc, 
    Lookup99.DisplayCode AS OtherMedicalDeath, Lookup99.UserDescription AS OtherMedicalDeathDesc, 
    Lookup100.DisplayCode AS OtherBlood, Lookup100.UserDescription AS OtherBloodDesc, 
    Lookup101.DisplayCode AS OtherBloodCrossMatched, Lookup101.UserDescription AS OtherBloodCrossMatchedDesc, 
    Lookup102.DisplayCode AS OtherBloodTyped, Lookup102.UserDescription AS OtherBloodTypedDesc, 
    dbo.AB_Blood.OtherBloodUnits, 
    Lookup148.DisplayCode AS PCTASIndicator, Lookup148.UserDescription AS PCTASIndicatorDesc, 
    dbo.AB_Abstract.PhysicianEstimatedLOS AS PhysicianEstLOS, 
    Lookup103.DisplayCode AS Plasma, Lookup103.UserDescription AS PlasmaDesc, 
    Lookup104.DisplayCode AS PlasmaCrossMatched, Lookup104.UserDescription AS PlasmaCrossMatchedDesc, 
    Lookup105.DisplayCode AS PlasmaTyped, Lookup105.UserDescription AS PlasmaTypedDesc, 
    dbo.AB_Blood.PlasmaUnits, 
    Lookup106.DisplayCode AS Platelets, Lookup106.UserDescription AS PlateletsDesc, 
    Lookup107.DisplayCode AS PlateletsCrossMatched, Lookup107.UserDescription AS PlateletsCrossMatchedDesc, 
    Lookup108.DisplayCode AS PlateletsTyped, Lookup108.UserDescription AS PlateletsTypedDesc, 
    dbo.AB_Blood.PlateletsUnits, 
    dbo.AB_Abstract.PostalCode, dbo.AB_Abstract.PostOpDays, dbo.AB_Abstract.PreOpDays, 
    Lookup110.DisplayCode AS PreamditWorkUp, Lookup110.UserDescription AS PreamditWorkUpDesc, 
    Lookup111.DisplayCode AS PregnancyDeath, Lookup111.UserDescription AS PregnancyDeathDesc, 
    dbo.AB_ReproductiveCare.PrevLiveBirths AS PrevLiveBirth, 
    Lookup112.DisplayCode AS PreviousPsychiartricAdmissions, Lookup112.UserDescription AS PreviousPsychiartricAdmDesc, 
    Lookup113.DisplayCode AS Program, Lookup113.UserDescription AS ProgramDesc, 
    Lookup118.DisplayCode AS ProvinceNumber, Lookup118.UserDescription AS ProvinceNumberDesc, 
    -- dbo.AB_Abstract.ReAdmitCode, 
    Lookup132.DisplayCode AS RedBloodCell, Lookup132.UserDescription AS RedBloodCellDesc, 
    Lookup133.DisplayCode AS RedBloodCellCrossMatched, Lookup133.UserDescription AS RedBloodCellCrossMatchedDesc, 
    Lookup134.DisplayCode AS RedBloodCellTyped, Lookup134.UserDescription AS RedBloodCellTypedDesc, 
    dbo.AB_Blood.RedCellUnits AS RedBloodCellUnits, dbo.AB_Abstract.ReferralDate, 
    Lookup135.DisplayCode AS ReferredFrom, Lookup135.UserDescription AS ReferredFromDesc, 
    Lookup136.DisplayCode AS ReferredTo, Lookup136.UserDescription AS ReferredToDesc, 
    dbo.AB_Abstract.RegisterNumber, dbo.AB_Abstract.EncounterNumber AS RegistrationNumber, 
    dbo.AB_Abstract.EncounterSequence AS RegistrationSequenceNumber, 
    dbo.AB_Abstract.AdmitDate AS RegistrationVisitDate, 
    dbo.AB_Abstract.AdmitTime AS RegistrationVisitTime, 
    dbo.AB_ReproductiveCare.ReprodComments AS ReproductiveCareComments, 
    dbo.AB_Abstract.Reserved AS ReserveField, 
    Lookup138.DisplayCode AS ResidenceCode, Lookup138.UserDescription AS ResidenceCodeDesc, 
    Lookup139.DisplayCode AS ResidenceType, Lookup139.UserDescription AS ResidenceTypeDesc, 
    Lookup140.DisplayCode AS ResponsiblityForPayment, Lookup140.UserDescription AS ResponsiblityForPaymentDesc, 
    Lookup153.DisplayCode AS SchedEDVisit, Lookup153.UserDescription AS SchedEDVisitDesc, 
    Lookup156.DisplayCode AS SeatbeltIndicator, Lookup156.UserDescription AS SeatbeltIndicatorDesc, 
    dbo.AB_Abstract.SecondChartRegNumber AS SecondChartRegisterNumber, 
    Lookup141.DisplayCode AS SecretVIPPatient, Lookup141.UserDescription AS SecretVIPPatientDesc, 
    Lookup142.DisplayCode AS SiteNumber, Lookup142.UserDescription AS SiteNumberDesc, 
    Lookup143.DisplayCode AS SocialService, Lookup143.UserDescription AS SocialServiceDesc, 
    Lookup144.DisplayCode AS SourceofReferral, Lookup144.UserDescription AS SourceofReferralDesc, 
    LU_StakeholderType.DisplayCode AS StakeholderType, LU_StakeholderType.UserDescription AS StakeholderTypeDesc, 

    Lookup145.DisplayCode AS Sterilization, 
    Lookup145.UserDescription AS SterilizationDesc, 

    Lookup146.DisplayCode AS SubsequentOR, Lookup146.UserDescription AS SubsequentORDesc, 
    Lookup147.DisplayCode AS Suicide, Lookup147.UserDescription AS SuicideDesc, 

    LUSurgicalCase.DisplayCode as SurgicalCase, LUSurgicalCase.UserDescription as SurgicalCaseDesc,

    dbo.AB_Abstract.TimeLeftER, dbo.AB_Abstract.TransferOverloadDate, 
    dbo.AB_Abstract.TransferOverloadTime, dbo.AB_Abstract.TransferOverloadDifference AS TransferOverloadTimeDifference, 
    Lookup149.DisplayCode AS TransfusionGiven, Lookup149.UserDescription AS TransfusionGivenDesc, 
    Lookup150.DisplayCode AS Trauma, Lookup150.UserDescription AS TraumaDesc, 
    dbo.AB_Abstract.TriageDate, 
    Lookup151.DisplayCode AS TriageLevel, Lookup151.UserDescription AS TriageLevelDesc, 
    dbo.AB_Abstract.TriageTime, 
    Lookup152.DisplayCode AS TSICoder, Lookup152.UserDescription AS TSICoderDesc, 
    dbo.AB_Abstract.TSIDate, dbo.AB_Abstract.TSITime, 
    -- dbo.AB_DeathInformation.DeathTwoTenPO AS TwoTenPO, 
    dbo.AB_Abstract.UniqiueLifetimeID AS ULI, 
    --dbo.AB_Abstract.UnplanReAdmit AS UnplannedReadmit, 
    Lookup154.DisplayCode AS VisitStatus, Lookup154.UserDescription AS VisitStatusDesc, 
    Lookup155.DisplayCode AS VisitType, Lookup155.UserDescription AS VisitTypeDesc, 
    dbo.AB_Abstract.WaitTimeER AS WaitTimeinER, 
    dbo.AB_Abstract.WaitAssessmentDifference AS WaittoAssessmentinMinutes, 
    dbo.AB_Abstract.NurseAssessDiff AS WaittoNursingAssessmentDiff, 
    dbo.AB_Abstract.Weight, 
    dbo.AB_Abstract.AbstractID AS zzAbstractLink, 
    dbo.AB_Abstract.VolumeID AS zzVolumeLink
FROM dbo.AB_Abstract with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile LU_StakeholderType with (nolock) ON dbo.AB_Abstract.StakeHolder = LU_StakeholderType.Code LEFT OUTER JOIN
    dbo.H_HospitalProfile LU_Hospital with (nolock) ON dbo.AB_Abstract.HospitalID = LU_Hospital.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LUCompleteRecord with (nolock) ON dbo.AB_Abstract.CompleteRecord = LUCompleteRecord.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LUHelmetIndicator with (nolock) ON dbo.AB_Abstract.HelmetIndicator = LUHelmetIndicator.Code LEFT OUTER JOIN
    dbo.LU_InjuryActivity Lookup2 with (nolock) ON dbo.AB_Abstract.InjuryActivity = Lookup2.Code LEFT OUTER JOIN
    dbo.LU_AdmitAmbulance Lookup3 with (nolock) ON dbo.AB_Abstract.AdmitAmbulance = Lookup3.Code LEFT OUTER JOIN
    dbo.LU_AgeCode Lookup4 with (nolock) ON dbo.AB_Abstract.AgeCode = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_ArrivalMode Lookup22 with (nolock) ON dbo.AB_Abstract.ArrivalMode = Lookup22.Code LEFT OUTER JOIN
    dbo.LU_BatchPeriod Lookup44 with (nolock) ON dbo.AB_Abstract.BatchPeriod = Lookup44.Code LEFT OUTER JOIN
    dbo.U_Users Lookup46 with (nolock) ON dbo.AB_Abstract.CoderNumber = Lookup46.Code LEFT OUTER JOIN
    dbo.LU_ContactMode Lookup50 with (nolock) ON dbo.AB_Abstract.ContactMode = Lookup50.Code LEFT OUTER JOIN
    dbo.U_Users Lookup52 with (nolock) ON dbo.AB_Abstract.DataEntryCoder = Lookup52.Code LEFT OUTER JOIN
    dbo.LU_TherDischPlan Lookup59 with (nolock) ON dbo.AB_Abstract.DischargePlanning = Lookup59.Code LEFT OUTER JOIN
    dbo.LU_DispositionCode_A Lookup60 with (nolock) ON dbo.AB_Abstract.DispositionCode = Lookup60.Code LEFT OUTER JOIN
    dbo.LU_Education Lookup64 with (nolock) ON dbo.AB_Abstract.EducationLevel = Lookup64.Code LEFT OUTER JOIN
    dbo.LU_FamilyPhysician Lookup67 with (nolock) ON dbo.AB_Abstract.FamilyPhysician = Lookup67.Code LEFT OUTER JOIN
    dbo.LU_Gender_I Lookup69 with (nolock) ON dbo.AB_Abstract.Gender = Lookup69.Code LEFT OUTER JOIN
    dbo.LU_HCNProvince Lookup70 with (nolock) ON dbo.AB_Abstract.HCNProvince = Lookup70.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup72 with (nolock) ON dbo.AB_Abstract.Injury = Lookup72.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 Lookup73 with (nolock) ON dbo.AB_Abstract.InstitutionFrom = Lookup73.Code LEFT OUTER JOIN
    dbo.H_InstitutionProfile Lookup74 with (nolock) ON dbo.AB_Abstract.InstitutionNumber = Lookup74.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 Lookup75 with (nolock) ON dbo.AB_Abstract.InstitutionTo = Lookup75.Code LEFT OUTER JOIN

    dbo.LU_Institution_9 InstitutionFrom9 with (nolock) ON dbo.AB_Abstract.InstitutionFrom = InstitutionFrom9.Code LEFT OUTER JOIN
    dbo.LU_Institution_9 InstitutionTo9 with (nolock) ON dbo.AB_Abstract.InstitutionTo = InstitutionTo9.Code LEFT OUTER JOIN

    dbo.LU_AbstractStatus Lookup83 with (nolock) ON dbo.AB_Abstract.IsCompleted = Lookup83.Code LEFT OUTER JOIN
    dbo.LU_CIHICorrect Lookup84 with (nolock) ON dbo.AB_Abstract.IsCorrected = Lookup84.Code LEFT OUTER JOIN
    dbo.LU_DeleteStatus Lookup85 with (nolock) ON dbo.AB_Abstract.IsDeleted = Lookup85.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem Lookup86 with (nolock) ON dbo.AB_Abstract.IsSubmited = Lookup86.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus Lookup87 with (nolock) ON dbo.AB_Abstract.IsValidated = Lookup87.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup88 with (nolock) ON dbo.AB_Abstract.BirthDateEstimated = Lookup88.Code LEFT OUTER JOIN
    dbo.LU_Language Lookup89 with (nolock) ON dbo.AB_Abstract.LanguageCode = Lookup89.Code LEFT OUTER JOIN
    dbo.LU_LivingArrangement Lookup90 with (nolock) ON dbo.AB_Abstract.LivingArrangement = Lookup90.Code LEFT OUTER JOIN
    dbo.LU_InjuryLocation Lookup91 with (nolock) ON dbo.AB_Abstract.InjuryLocation = Lookup91.Code LEFT OUTER JOIN
    dbo.LU_MISCode Lookup93 with (nolock) ON dbo.AB_Abstract.MISCode = Lookup93.Code LEFT OUTER JOIN
    dbo.LU_MaritalStatus Lookup94 with (nolock) ON dbo.AB_Abstract.MaritalStatus = Lookup94.Code LEFT OUTER JOIN
    dbo.LU_Occupation Lookup98 with (nolock) ON dbo.AB_Abstract.Occupation = Lookup98.Code LEFT OUTER JOIN
    dbo.LU_TherPreAdmitWorkUp Lookup110 with (nolock) ON dbo.AB_Abstract.PreAdmitWorkUp = Lookup110.Code LEFT OUTER JOIN
    dbo.LU_Program Lookup113 with (nolock) ON dbo.AB_Abstract.Program = Lookup113.Code LEFT OUTER JOIN
    dbo.LU_Province Lookup118 with (nolock) ON dbo.AB_Abstract.ProvinceNumber = Lookup118.Code LEFT OUTER JOIN
    dbo.LU_Referral Lookup135 with (nolock) ON dbo.AB_Abstract.ReferredFrom = Lookup135.Code LEFT OUTER JOIN
    dbo.LU_Referral Lookup136 with (nolock) ON dbo.AB_Abstract.ReferredTo = Lookup136.Code LEFT OUTER JOIN
    dbo.LU_ResidenceCode Lookup138 with (nolock) ON dbo.AB_Abstract.ResidenceCode = Lookup138.Code LEFT OUTER JOIN
    dbo.LU_ResidenceType Lookup139 with (nolock) ON dbo.AB_Abstract.ResidenceType = Lookup139.Code LEFT OUTER JOIN
    dbo.LU_RespPayment Lookup140 with (nolock) ON dbo.AB_Abstract.ResponsiblePayment = Lookup140.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup141 with (nolock) ON dbo.AB_Abstract.Secret = Lookup141.Code LEFT OUTER JOIN
    dbo.LU_Site Lookup142 with (nolock) ON dbo.AB_Abstract.SiteNumber = Lookup142.Code LEFT OUTER JOIN
    dbo.LU_TherSocialService Lookup143 with (nolock) ON dbo.AB_Abstract.SocialService = Lookup143.Code LEFT OUTER JOIN
    dbo.LU_TriageLevel Lookup151 with (nolock) ON dbo.AB_Abstract.TriageLevel = Lookup151.Code LEFT OUTER JOIN
    dbo.U_Users Lookup152 with (nolock) ON dbo.AB_Abstract.TSICoder = Lookup152.Code LEFT OUTER JOIN
    dbo.LU_VisitType Lookup154 with (nolock) ON dbo.AB_Abstract.VisitStatus = Lookup154.Code LEFT OUTER JOIN
    dbo.LU_VisitType_10 Lookup155 with (nolock) ON dbo.AB_Abstract.VisitType = Lookup155.Code LEFT OUTER JOIN
    dbo.AB_Ancillary with (nolock) ON dbo.AB_Abstract.AbstractID = dbo.AB_Ancillary.AbstractID LEFT OUTER JOIN
    dbo.LU_Ancillary1 Lookup8 with (nolock) ON dbo.AB_Ancillary.AncillaryField1 = Lookup8.Code LEFT OUTER JOIN
    dbo.LU_Ancillary10 Lookup9 with (nolock) ON dbo.AB_Ancillary.AncillaryField10 = Lookup9.Code LEFT OUTER JOIN
    dbo.LU_Ancillary11 Lookup10 with (nolock) ON dbo.AB_Ancillary.AncillaryField11 = Lookup10.Code LEFT OUTER JOIN
    dbo.LU_Ancillary12 Lookup11 with (nolock) ON dbo.AB_Ancillary.AncillaryField12 = Lookup11.Code LEFT OUTER JOIN
    dbo.LU_Ancillary2 Lookup12 with (nolock) ON dbo.AB_Ancillary.AncillaryField2 = Lookup12.Code LEFT OUTER JOIN
    dbo.LU_Ancillary3 Lookup13 with (nolock) ON dbo.AB_Ancillary.AncillaryField3 = Lookup13.Code LEFT OUTER JOIN
    dbo.LU_Ancillary4 Lookup14 with (nolock) ON dbo.AB_Ancillary.AncillaryField4 = Lookup14.Code LEFT OUTER JOIN
    dbo.LU_Ancillary5 Lookup15 with (nolock) ON dbo.AB_Ancillary.AncillaryField5 = Lookup15.Code LEFT OUTER JOIN
    dbo.LU_Ancillary6 Lookup16 with (nolock) ON dbo.AB_Ancillary.AncillaryField6 = Lookup16.Code LEFT OUTER JOIN
    dbo.LU_Ancillary7 Lookup17 with (nolock) ON dbo.AB_Ancillary.AncillaryField7 = Lookup17.Code LEFT OUTER JOIN
    dbo.LU_Ancillary8 Lookup18 with (nolock) ON dbo.AB_Ancillary.AncillaryField8 = Lookup18.Code LEFT OUTER JOIN
    dbo.LU_Ancillary9 Lookup19 with (nolock) ON dbo.AB_Ancillary.AncillaryField9 = Lookup19.Code LEFT OUTER JOIN
    dbo.AB_BasicOption with (nolock) ON dbo.AB_Abstract.AbstractID = dbo.AB_BasicOption.AbstractID LEFT OUTER JOIN
    dbo.LU_BasicOption1 Lookup25 with (nolock) ON dbo.AB_BasicOption.BasicOption1 = Lookup25.Code LEFT OUTER JOIN
    dbo.LU_BasicOption10 Lookup26 with (nolock) ON dbo.AB_BasicOption.BasicOption10 = Lookup26.Code LEFT OUTER JOIN
    dbo.LU_BasicOption11 Lookup27 with (nolock) ON dbo.AB_BasicOption.BasicOption11 = Lookup27.Code LEFT OUTER JOIN
    dbo.LU_BasicOption12 Lookup28 with (nolock) ON dbo.AB_BasicOption.BasicOption12 = Lookup28.Code LEFT OUTER JOIN
    dbo.LU_BasicOption13 Lookup29 with (nolock) ON dbo.AB_BasicOption.BasicOption13 = Lookup29.Code LEFT OUTER JOIN
    dbo.LU_BasicOption14 Lookup30 with (nolock) ON dbo.AB_BasicOption.BasicOption14 = Lookup30.Code LEFT OUTER JOIN
    dbo.LU_BasicOption15 Lookup31 with (nolock) ON dbo.AB_BasicOption.BasicOption15 = Lookup31.Code LEFT OUTER JOIN
    dbo.LU_BasicOption16 Lookup32 with (nolock) ON dbo.AB_BasicOption.BasicOption16 = Lookup32.Code LEFT OUTER JOIN
    dbo.LU_BasicOption17 Lookup33 with (nolock) ON dbo.AB_BasicOption.BasicOption17 = Lookup33.Code LEFT OUTER JOIN
    dbo.LU_BasicOption18 Lookup34 with (nolock) ON dbo.AB_BasicOption.BasicOption18 = Lookup34.Code LEFT OUTER JOIN
    dbo.LU_BasicOption19 Lookup35 with (nolock) ON dbo.AB_BasicOption.BasicOption19 = Lookup35.Code LEFT OUTER JOIN
    dbo.LU_BasicOption2 Lookup36 with (nolock) ON dbo.AB_BasicOption.BasicOption2 = Lookup36.Code LEFT OUTER JOIN
    dbo.LU_BasicOption3 Lookup37 with (nolock) ON dbo.AB_BasicOption.BasicOption3 = Lookup37.Code LEFT OUTER JOIN
    dbo.LU_BasicOption4 Lookup38 with (nolock) ON dbo.AB_BasicOption.BasicOption4 = Lookup38.Code LEFT OUTER JOIN
    dbo.LU_BasicOption5 Lookup39 with (nolock) ON dbo.AB_BasicOption.BasicOption5 = Lookup39.Code LEFT OUTER JOIN
    dbo.LU_BasicOption6 Lookup40 with (nolock) ON dbo.AB_BasicOption.BasicOption6 = Lookup40.Code LEFT OUTER JOIN
    dbo.LU_BasicOption7 Lookup41 with (nolock) ON dbo.AB_BasicOption.BasicOption7 = Lookup41.Code LEFT OUTER JOIN
    dbo.LU_BasicOption8 Lookup42 with (nolock) ON dbo.AB_BasicOption.BasicOption8 = Lookup42.Code LEFT OUTER JOIN
    dbo.LU_BasicOption9 Lookup43 with (nolock) ON dbo.AB_BasicOption.BasicOption9 = Lookup43.Code LEFT OUTER JOIN
    dbo.AB_Blood with (nolock) ON dbo.AB_Abstract.AbstractID = dbo.AB_Blood.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup5 with (nolock) ON dbo.AB_Blood.Albumin = Lookup5.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup6 with (nolock) ON dbo.AB_Blood.AlbuminXMatch = Lookup6.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup7 with (nolock) ON dbo.AB_Blood.AlbuminTyped = Lookup7.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup23 with (nolock) ON dbo.AB_Blood.AutoTransfusion = Lookup23.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup100 with (nolock) ON dbo.AB_Blood.OtherBlood = Lookup100.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup101 with (nolock) ON dbo.AB_Blood.OtherBloodXMatch = Lookup101.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup102 with (nolock) ON dbo.AB_Blood.OtherBloodTyped = Lookup102.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup103 with (nolock) ON dbo.AB_Blood.Plasma = Lookup103.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup104 with (nolock) ON dbo.AB_Blood.PlasmaXMatch = Lookup104.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup105 with (nolock) ON dbo.AB_Blood.PlasmaTyped = Lookup105.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup106 with (nolock) ON dbo.AB_Blood.Platelets = Lookup106.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup107 with (nolock) ON dbo.AB_Blood.PlateletsXMatch = Lookup107.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup108 with (nolock) ON dbo.AB_Blood.PlateletsTyped = Lookup108.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup132 with (nolock) ON dbo.AB_Blood.RedBloodCell = Lookup132.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup133 with (nolock) ON dbo.AB_Blood.RedCellXMatch = Lookup133.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup134 with (nolock) ON dbo.AB_Blood.RedCellTyped = Lookup134.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup149 with (nolock) ON dbo.AB_Blood.TransfusionIndicator = Lookup149.Code LEFT OUTER JOIN
    dbo.AB_DeathInformation with (nolock) ON dbo.AB_Abstract.AbstractID = dbo.AB_DeathInformation.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup24 with (nolock) ON dbo.AB_DeathInformation.AutopsyPerformed = Lookup24.Code LEFT OUTER JOIN
    dbo.LU_CoronerCase Lookup51 with (nolock) ON dbo.AB_DeathInformation.CoronerCase = Lookup51.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup53 with (nolock) ON dbo.AB_DeathInformation.DeathInER = Lookup53.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup54 with (nolock) ON dbo.AB_DeathInformation.DeathOnArrival = Lookup54.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup58 with (nolock) ON dbo.AB_DeathInformation.DeathInOR = Lookup58.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup99 with (nolock) ON dbo.AB_DeathInformation.OtherDeath = Lookup99.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup111 with (nolock) ON dbo.AB_DeathInformation.PregnancyDeath = Lookup111.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup150 with (nolock) ON dbo.AB_DeathInformation.TraumaDeath = Lookup150.Code LEFT OUTER JOIN
    dbo.AB_MentalHealth with (nolock) ON dbo.AB_Abstract.AbstractID = dbo.AB_MentalHealth.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup1 with (nolock) ON dbo.AB_MentalHealth.MentalAWOL = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_MentalLegalStatus Lookup45 with (nolock) ON dbo.AB_MentalHealth.MentalLegalStatus = Lookup45.Code LEFT OUTER JOIN
    dbo.LU_MentalECTTreat Lookup61 with (nolock) ON dbo.AB_MentalHealth.MentalECTTreatment = Lookup61.Code LEFT OUTER JOIN
    dbo.LU_MentalEducation Lookup63 with (nolock) ON dbo.AB_MentalHealth.MentalEducation = Lookup63.Code LEFT OUTER JOIN
    dbo.LU_MentalEmployment Lookup65 with (nolock) ON dbo.AB_MentalHealth.MentalEmployment = Lookup65.Code LEFT OUTER JOIN
    dbo.LU_MentalFinancial Lookup68 with (nolock) ON dbo.AB_MentalHealth.MentalFinancial = Lookup68.Code LEFT OUTER JOIN
    dbo.LU_MentalAdmitMethod Lookup95 with (nolock) ON dbo.AB_MentalHealth.MentalAdmitMethod = Lookup95.Code LEFT OUTER JOIN
    dbo.LU_MentalPrevPsych Lookup112 with (nolock) ON dbo.AB_MentalHealth.MentalPrevPsych = Lookup112.Code LEFT OUTER JOIN
    dbo.LU_MentalReferral Lookup137 with (nolock) ON dbo.AB_MentalHealth.MentalReferralTo = Lookup137.Code LEFT OUTER JOIN
    dbo.LU_MentalReferral Lookup144 with (nolock) ON dbo.AB_MentalHealth.MentalReferralSource = Lookup144.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup147 with (nolock) ON dbo.AB_MentalHealth.MentalSuicide = Lookup147.Code LEFT OUTER JOIN
    dbo.AB_ReproductiveCare with (nolock) ON dbo.AB_Abstract.AbstractID = dbo.AB_ReproductiveCare.AbstractID LEFT OUTER JOIN
    dbo.LU_ReprodComplication Lookup47 with (nolock) ON dbo.AB_ReproductiveCare.Complication1 = Lookup47.Code LEFT OUTER JOIN
    dbo.LU_ReprodComplication Lookup48 with (nolock) ON dbo.AB_ReproductiveCare.Complication2 = Lookup48.Code LEFT OUTER JOIN
    dbo.LU_ReprodComplication Lookup49 with (nolock) ON dbo.AB_ReproductiveCare.Complication3 = Lookup49.Code LEFT OUTER JOIN
    dbo.LU_ReprodOR Lookup71 with (nolock) ON dbo.AB_ReproductiveCare.InitialOR = Lookup71.Code LEFT OUTER JOIN
    dbo.LU_ReprodSterilization Lookup145 with (nolock) ON dbo.AB_ReproductiveCare.Sterilization = Lookup145.Code LEFT OUTER JOIN

    dbo.LU_ReprodOR Lookup146 with (nolock) ON dbo.AB_ReproductiveCare.SubsequentOR = Lookup146.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup148 with (nolock) ON dbo.AB_Abstract.PCTASIndicator = Lookup148.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup153 with (nolock) ON dbo.AB_Abstract.SchedEDVisit = Lookup153.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup156 with (nolock) ON Lookup156.Code = dbo.AB_Abstract.SeatbeltIndicator AND Lookup156.LookupID = 2 LEFT OUTER JOIN
    dbo.LU_Glasgow Lookup157 with (nolock) ON Lookup157.Code = dbo.AB_Abstract.GlasgowComaScale LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup158 with (nolock) ON dbo.AB_Abstract.DecisionAdmitTimeUnknown = Lookup158.Code AND Lookup158.LookupID = 1 LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup159 with (nolock) ON dbo.AB_Abstract.AssessmentTimeUnknown = Lookup159.Code AND Lookup159.LookupID = 1 LEFT OUTER JOIN
    LU_AbstractOverflow with (nolock) ON AB_Abstract.AbstractOverflow = LU_AbstractOverflow.Code LEFT OUTER JOIN
    LU_YesBlank LUSurgicalCase with (nolock) ON dbo.AB_Abstract.SurgicalCase = LUSurgicalCase.Code  LEFT OUTER JOIN
    LU_YesBlank LUComplication with (nolock) ON dbo.AB_Abstract.Complication = LUComplication.Code
WHERE dbo.AB_Abstract.CareType = 5
    --QA - 00032 disable the domain securite issue
 --   --PR - 07485
 --   and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB_ABstract.HospitalID is null or AB_ABstract.HospitalID = 0
 --   --EN - 00666
 --       or Is_Member(nullif(ReportGroup, '''')) = 1)
 ----       or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB_ABstract.HospitalID, 0))
   

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Amcare_CACS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE  VIEW [dbo].[Amcare_CACS_VR]
AS
SELECT     
    dbo.AB_CACS.OccurrenceNumber, 
    dbo.AB_CACS.CACS_Year AS CACSYear, 
    dbo.AB_CACS.MAC, 
    dbo.AB_CACS.CACSCell, 
    dbo.AB_CACS.ACW, 
    dbo.AB_CACS.CACSDescription, 
    (case AB_Abstract.ICDType 
        when ''T'' then dbo.ICD_ProcFile10.DisplayCode
        when ''9'' then dbo.ICD_ProcFile9.DisplayCode
        when ''C'' then dbo.ICD_ProcFile9cm.DisplayCode
        end) AS InterventionCode, 
    (case AB_Abstract.ICDType 
        when ''T'' then dbo.ICD_ProcFile10.UserDescription
        when ''9'' then dbo.ICD_ProcFile9.UserDescription
        when ''C'' then dbo.ICD_ProcFile9cm.UserDescription
        end) AS IntervCodeDescription, 
    dbo.AB_Abstract.AbstractID AS zzAbstractLink
FROM dbo.AB_Abstract with (nolock) inner join
    dbo.AB_CACS with (nolock) ON dbo.AB_CACS.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
    dbo.ICD_ProcFile10 with (nolock) ON dbo.AB_CACS.InterventionCode = dbo.ICD_ProcFile10.Code LEFT OUTER JOIN
    dbo.ICD_ProcFile9 with (nolock) ON dbo.AB_CACS.InterventionCode = dbo.ICD_ProcFile9.Code LEFT OUTER JOIN
    dbo.ICD_ProcFile9cm with (nolock) ON dbo.AB_CACS.InterventionCode = dbo.ICD_ProcFile9cm.Code
WHERE dbo.AB_Abstract.CareType = 5





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Amcare_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE  VIEW [dbo].[Amcare_Diagnosis_VR]
AS
SELECT     
    (case AB_Abstract.ICDType 
        when ''T'' then dbo.ICD_DiagFile10.DisplayCode 
        when ''9'' then dbo.ICD_DiagFile9.DisplayCode 
        when ''C'' then dbo.ICD_DiagFile9cm.DisplayCode 
     end) AS DiagnosisCode, 
    (case AB_Abstract.ICDType 
        when ''T'' then dbo.ICD_DiagFile10.UserDescription 
        when ''9'' then dbo.ICD_DiagFile9.UserDescription 
        when ''C'' then dbo.ICD_DiagFile9cm.UserDescription 
     end) AS DiagnosisCodeDesc, 
    ICD_DiagFile10.ShortDescription as DiagnosisCodeShortDesc,
    dbo.ICD_DiagFile10.ICD9 AS DiagnosisICD9Equivalent, 
    dbo.ICD_DiagFile10.ICD9cm AS DiagnosisICD9cmEquivalent, 
    dbo.AB_Diagnosis.DiagnosisOccurrence, 
    Lookup55.DisplayCode AS DiagnosisPrefix, Lookup55.UserDescription AS DiagnosisPrefixDesc, 
    Lookup56.DisplayCode AS DiagnosisSuffix, Lookup56.UserDescription AS DiagnosisSuffixDesc, 
    Lookup57.DisplayCode AS DiagnosisType,   Lookup57.UserDescription AS DiagnosisTypeDesc, 
    dbo.AB_Diagnosis.AbstractID AS zzAbstractLink
FROM dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Diagnosis with (nolock) ON dbo.AB_Diagnosis.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
    dbo.ICD_DiagFile10 with (nolock) ON dbo.AB_Diagnosis.DiagnosisCode = dbo.ICD_DiagFile10.Code Left OUTER JOIN
    dbo.ICD_DiagFile9 with (nolock) ON dbo.AB_Diagnosis.DiagnosisCode = dbo.ICD_DiagFile9.Code Left OUTER JOIN
    dbo.ICD_DiagFile9cm with (nolock) ON dbo.AB_Diagnosis.DiagnosisCode = dbo.ICD_DiagFile9cm.Code Left OUTER JOIN
    dbo.LU_DiagnosisPrefix Lookup55 with (nolock) ON dbo.AB_Diagnosis.DiagnosisPrefix = Lookup55.Code LEFT OUTER JOIN
    dbo.LU_DiagnosisSuffix Lookup56 with (nolock) ON dbo.AB_Diagnosis.DiagnosisSuffix = Lookup56.Code LEFT OUTER JOIN
    dbo.LU_DiagnosisType Lookup57 with (nolock) ON dbo.AB_Diagnosis.DiagnosisType = Lookup57.Code
WHERE dbo.AB_Abstract.CareType = 5 AND (dbo.AB_Diagnosis.DiagnosisOccurrence IS NOT NULL)





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Amcare_DPG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE view [dbo].[Amcare_DPG_VR]
as
select 
    DPGOccurrence = dpg.OccurrenceNumber, 
    DPG_Year, 
    DPG, 
    DPG_RIW, 
    DPG_MOH_RIW, 
    DPG_Description, 
    zzAbstractLink = dpg.AbstractID
from AB_DPG dpg  with (nolock)
    Inner join AB_Abstract with (nolock) ON dpg.AbstractID = AB_Abstract.AbstractID
where AB_Abstract.Caretype = 5




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Amcare_Interventions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'





CREATE   VIEW [dbo].[Amcare_Interventions_VR]
AS
SELECT 
    Lookup20.DisplayCode AS AnestheticTechnique, 
    Lookup20.UserDescription AS AnestheticTechniqueDesc, 
    Lookup21.DisplayCode AS AnesthetistID, 
    Lookup21.UserDescription AS AnesthetistIDDesc, 
    Lookup62.DisplayCode AS EUL, 
    Lookup62.UserDescription AS EULDesc, 
    Lookup66.DisplayCode AS Extra, 
    Lookup66.UserDescription AS ExtraDesc,
    (case AB_Abstract.ICDType 
        when ''T'' then dbo.ICD_ProcFile10.DisplayCode 
        when ''9'' then dbo.ICD_ProcFile9.DisplayCode 
        when ''C'' then dbo.ICD_ProcFile9cm.DisplayCode 
     end) AS InterventionCode, 
    (case AB_Abstract.ICDType 
        when ''T'' then dbo.ICD_ProcFile10.UserDescription 
        when ''9'' then dbo.ICD_ProcFile9.UserDescription 
        when ''C'' then dbo.ICD_ProcFile9cm.UserDescription 
     end) AS InterventionCodeDesc, 
    ICD_ProcFile10.ShortDescription as InterventionCodeShortDesc,
    dbo.AB_Intervention.IntervDateIn, dbo.AB_Intervention.IntervDateOut, 
    Lookup77.DisplayCode AS InterventionAttributeExtent, 
    Lookup77.UserDescription AS IntervAttributeExtentDesc, 
    Lookup78.DisplayCode AS InterventionAttributeLocation, 
    Lookup78.UserDescription AS IntervAttributeLocationDesc, 
    Lookup79.DisplayCode AS InterventionAttributeStatus, 
    Lookup79.UserDescription AS IntervAttributeStatusDesc, 
    dbo.AB_Intervention.IntervDate AS InterventionDate, 
    dbo.ICD_ProcFile10.ICD9 AS IntervICD9Equivalent, 
    dbo.ICD_ProcFile10.ICD9cm AS IntervICD9cmEquivalent, 
    Lookup80.DisplayCode AS InterventionLocation, 
    Lookup80.UserDescription AS InterventionLocationDesc, 
    dbo.AB_Intervention.IntervOccurrence AS InterventionOccurrence, 
    Lookup81.DisplayCode AS InterventionProviderNumber, 
    Lookup81.UserDescription AS InterventionProviderNumberDesc, 
    Lookup82.DisplayCode AS InterventionProviderSpecialty, 
    Lookup82.UserDescription AS IntervProviderSpecialtyDesc, 
    Lookup83.DisplayCode AS InterventionSuffix, 
    Lookup83.UserDescription AS InterventionSuffixDesc, 
    dbo.AB_Intervention.IntervTimeIn AS InterventionTimeIn, 
    dbo.AB_Intervention.IntervTimeMinutes AS InterventionTimeinMinutes, 
    dbo.AB_Intervention.IntervTimeOut AS InterventionTimeOut, 
    Lookup97.DisplayCode AS OOHIndicator, 
    Lookup97.UserDescription AS OOHIndicatorDesc, 
    (case when AB_Abstract.ICDType = ''T'' then Lookup98.DisplayCode
          else LU_Institution_9.DisplayCode end) AS OOHInstitutionNumber, 
    (case when AB_Abstract.ICDType = ''T'' then Lookup98.UserDescription
          else LU_Institution_9.UserDescription end) AS OOHInstitutionNumberDesc, 
    Lookup149.DisplayCode AS TissueCode, 
    Lookup149.UserDescription AS TissueCodeDesc, 
    Lookup154.DisplayCode AS UnplannedReturntoOR, 
    Lookup154.UserDescription AS UnplannedReturntoORDesc, 
    dbo.AB_Intervention.AbstractID AS zzAbstractLink
FROM       
    dbo.AB_Abstract  with (nolock) inner JOIN
    dbo.AB_Intervention with (nolock) ON dbo.AB_Intervention.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
    dbo.ICD_ProcFile10 with (nolock) ON dbo.AB_Intervention.IntervCode = dbo.ICD_ProcFile10.Code LEFT OUTER JOIN
    dbo.ICD_ProcFile9 with (nolock) ON dbo.AB_Intervention.IntervCode = dbo.ICD_ProcFile9.Code LEFT OUTER JOIN
    dbo.ICD_ProcFile9cm with (nolock) ON dbo.AB_Intervention.IntervCode = dbo.ICD_ProcFile9cm.Code LEFT OUTER JOIN
    dbo.LU_AnaestTechnique Lookup20 with (nolock) ON dbo.AB_Intervention.IntervAnaestTechnique = Lookup20.Code LEFT OUTER JOIN
    dbo.LU_Provider Lookup21 with (nolock) ON dbo.AB_Intervention.IntervAnaestID = Lookup21.Code LEFT OUTER JOIN
    dbo.LU_IntervEUL Lookup62 with (nolock) ON dbo.AB_Intervention.IntervEUL = Lookup62.Code LEFT OUTER JOIN
    dbo.LU_IntervExtra Lookup66 with (nolock) ON dbo.AB_Intervention.IntervExtra = Lookup66.Code LEFT OUTER JOIN
    dbo.LU_IntervAttExtent Lookup77 with (nolock) ON dbo.AB_Intervention.IntervAttribExtent = Lookup77.Code LEFT OUTER JOIN
    dbo.LU_IntervAttLocation Lookup78 with (nolock) ON dbo.AB_Intervention.IntervAttribLocation = Lookup78.Code LEFT OUTER JOIN
    dbo.LU_IntervAttStatus Lookup79 with (nolock) ON dbo.AB_Intervention.IntervAttribStatus = Lookup79.Code LEFT OUTER JOIN
    dbo.LU_IntervLocation_AI Lookup80 with (nolock) ON dbo.AB_Intervention.IntervLocation = Lookup80.Code LEFT OUTER JOIN
    dbo.LU_Provider Lookup81 with (nolock) ON dbo.AB_Intervention.IntervProviderNumber = Lookup81.Code LEFT OUTER JOIN
    dbo.LU_ProviderSpecialty Lookup82 with (nolock) ON dbo.AB_Intervention.IntervProviderService = Lookup82.Code LEFT OUTER JOIN
    dbo.LU_IntervSuffix Lookup83 with (nolock) ON dbo.AB_Intervention.IntervSuffix = Lookup83.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup97 with (nolock) ON dbo.AB_Intervention.IntervOOHIndicator = Lookup97.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 Lookup98 with (nolock) ON dbo.AB_Intervention.IntervOOHInstitution = Lookup98.Code LEFT OUTER JOIN
    dbo.LU_Institution_9 with (nolock) ON dbo.AB_Intervention.IntervOOHInstitution = LU_Institution_9.Code LEFT OUTER JOIN
    dbo.LU_IntervTissue Lookup149 with (nolock) ON dbo.AB_Intervention.IntervTissueCode = Lookup149.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup154 with (nolock) ON dbo.AB_Intervention.IntervUnplanReturn = Lookup154.Code
WHERE (dbo.AB_Abstract.CareType = 5) AND (dbo.AB_Intervention.IntervOccurrence IS NOT NULL)







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Amcare_MIS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[Amcare_MIS_VR]
AS
SELECT     
    dbo.AB_MIS.DirectCost AS DirectCosts, 
    dbo.AB_MIS.IndirectCost AS IndirectCosts, 
    dbo.LU_MISCode.DisplayCode AS MISCode, 
    dbo.LU_MISCode.UserDescription AS MISCodeDesc, 
    dbo.AB_MIS.MISOccurrence, 
    dbo.AB_MIS.SupplyCost AS SupplyCosts, 
    dbo.AB_MIS.AbstractID AS zzAbstractLink
FROM  dbo.AB_Abstract with (nolock) inner JOIN
    AB_MIS with (nolock) ON dbo.AB_MIS.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
    dbo.LU_MISCode with (nolock) ON dbo.AB_MIS.MISCode = dbo.LU_MISCode.Code
WHERE (dbo.AB_Abstract.CareType = 5) AND (dbo.AB_MIS.MISOccurrence IS NOT NULL)





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Amcare_Projects_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[Amcare_Projects_VR]
AS
SELECT 
    Lookup115.DisplayCode AS ProjectNumber, Lookup115.UserDescription AS ProjectNumberDesc, 
    dbo.AB_Project.ProjectOccurrence, 
    Lookup120.DisplayCode AS Question1,   Lookup120.UserDescription AS Question1Desc, 
    Lookup121.DisplayCode AS Question10,  Lookup121.UserDescription AS Question10Desc, 
    Lookup122.DisplayCode AS Question11,  Lookup122.UserDescription AS Question11Desc, 
    Lookup123.DisplayCode AS Question12,  Lookup123.UserDescription AS Question12Desc, 
    Lookup124.DisplayCode AS Question13,  Lookup124.UserDescription AS Question13Desc, 
    dbo.AB_Project.Question14, dbo.AB_Project.Question15, 
    dbo.AB_Project.Question16, dbo.AB_Project.Question17, 
    Lookup125.DisplayCode AS Question2,   Lookup125.UserDescription AS Question2Desc, 
    Lookup126.DisplayCode AS Question3,   Lookup126.UserDescription AS Question3Desc, 
    Lookup127.DisplayCode AS Question4,   Lookup127.UserDescription AS Question4Desc, 
    Lookup128.DisplayCode AS Question5,   Lookup128.UserDescription AS Question5Desc, 
    Lookup129.DisplayCode AS Question6,   Lookup129.UserDescription AS Question6Desc, 
    Lookup130.DisplayCode AS Question7,   Lookup130.UserDescription AS Question7Desc, 
    Lookup131.DisplayCode AS Question8,   Lookup131.UserDescription AS Question8Desc, 
    Lookup132.DisplayCode AS Question9,   Lookup132.UserDescription AS Question9Desc, 
    dbo.AB_Project.AbstractID AS zzAbstractLink
FROM dbo.AB_Abstract with (nolock) Inner join
    AB_Project with (nolock) ON dbo.AB_Project.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
    dbo.LU_Project Lookup115 with (nolock) ON dbo.AB_Project.ProjectNumber = Lookup115.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1 Lookup120 with (nolock) ON dbo.AB_Project.Question1 = Lookup120.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 Lookup121 with (nolock) ON dbo.AB_Project.Question10 = Lookup121.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 Lookup122 with (nolock) ON dbo.AB_Project.Question11 = Lookup122.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 Lookup123 with (nolock) ON dbo.AB_Project.Question12 = Lookup123.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 Lookup124 with (nolock) ON dbo.AB_Project.Question13 = Lookup124.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2 Lookup125 with (nolock) ON dbo.AB_Project.Question2 = Lookup125.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3 Lookup126 with (nolock) ON dbo.AB_Project.Question3 = Lookup126.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4 Lookup127 with (nolock) ON dbo.AB_Project.Question4 = Lookup127.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5 Lookup128 with (nolock) ON dbo.AB_Project.Question5 = Lookup128.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6 Lookup129 with (nolock) ON dbo.AB_Project.Question6 = Lookup129.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7 Lookup130 with (nolock) ON dbo.AB_Project.Question7 = Lookup130.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8 Lookup131 with (nolock) ON dbo.AB_Project.Question8 = Lookup131.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9 Lookup132 with (nolock) ON dbo.AB_Project.Question9 = Lookup132.Code
WHERE (dbo.AB_Abstract.CareType = 5)





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Amcare_Providers_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[Amcare_Providers_VR]
AS
SELECT    
    dbo.AB_Provider.ProviderArriveDate AS ProviderArrivedDate, 
    dbo.AB_Provider.ProviderArriveTime AS ProviderArrivedTime, 
    dbo.AB_Provider.ProviderCallDate AS ProviderCalledDate, 
    dbo.AB_Provider.ProviderCallTime AS ProviderCalledTime, 
    Lookup116.DisplayCode AS ProviderNumber, 
    Lookup116.UserDescription AS ProviderNumberDesc, dbo.AB_Provider.ProviderOccurrence, 
    Lookup117.DisplayCode AS ProviderSpecialty, 
    Lookup117.UserDescription AS ProviderSpecialtyDesc, 
    dbo.AB_Provider.ProviderTotalTime, 
    Lookup118.DisplayCode AS ProviderType, 
    Lookup118.UserDescription AS ProviderTypeDesc, 
    dbo.AB_Provider.AbstractID AS zzAbstractLink
FROM dbo.AB_Provider with (nolock) inner JOIN
    dbo.AB_Abstract with (nolock) ON dbo.AB_Provider.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
    dbo.LU_Provider Lookup116 with (nolock) ON dbo.AB_Provider.ProviderNumber = Lookup116.Code LEFT OUTER JOIN
    dbo.LU_ProviderSpecialty Lookup117 with (nolock) ON dbo.AB_Provider.ProviderSpecialty = Lookup117.Code LEFT OUTER JOIN
    dbo.LU_ProviderType Lookup118 with (nolock) ON dbo.AB_Provider.ProviderType = Lookup118.Code
WHERE (dbo.AB_Abstract.CareType = 5) AND (dbo.AB_Provider.ProviderOccurrence IS NOT NULL)





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_AbstractNotes_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[CCM_AbstractNotes_VR]
AS
SELECT     
   RecordID AS zzAbstractLink,
   LogNote  as AbstractNotes,
   LogDate  as DateLogged,
   LogTime  as TimeLogged,
   U.DisplayCode as CreateBy,
   U.UserDescription as CreatorName        
from dbo.REC_Notes r with (nolock) left join U_users U  with (nolock) ON r.LogCoder=u.code
where AppID in ( 675, 676 )



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_Entity_ClinicVisit_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[CCM_Entity_ClinicVisit_VR]
AS
SELECT     
    patient_chart_number = dbo.CC_Demographic.ChartNumber, 
    visit_hospital_number = right(H_InstitutionProfile_visit.CIHIValue, 4), 
    submitting_hospital_number = right(H_InstitutionProfile_submit.CIHIValue, 4), 
    visit_date = isnull(convert(varchar(20), AB_Abstract.AdmitDate, 112), ''''),
    visit_time = isnull(left(replace(convert(varchar(20),  AB_Abstract.AdmitTime, 114), '':'', ''''), 4), ''''),
    --0092 do not zero fill- it looks like client issue to use the old one
    hcp_number = isnull(right(Replicate(''0'', 15) + LU_Provider.CIHIValue, 15), ''''),
    --hcp_number = (case when isnumeric(LU_Provider.CIHIValue) = 1 then isnull(right(Replicate(''0'', 15) + LU_Provider.CIHIValue, 15), '''') else LU_Provider.CIHIValue end),
    visit_program_code = isnull(LU_VisitProgramCode.CIHIValue, ''''),
    mis_functional_centre = isnull(LU_MISCode.CIHIValue, ''''),
    radiation_review_flag = isnull(LU_RadiationReviewFlag.CIHIValue, ''''),
    inpatient_flag = isnull(LU_InpatientFlag.CIHIValue, ''''),
    registration_date = isnull(convert(varchar(10), dbo.CC_DiseaseRegister.RegisterDate, 112), ''''),
    disease_sequence_number = isnull(dbo.CC_DiseaseRegister.DiseaseSequenceNum, 0),
    patient_postal_code = isnull(AB_Abstract.PostalCode, ''''),
    patient_mohltc_residence_code = isnull(LU_ResidenceCode.CIHIValue, ''''),
    visit_type = isnull(LU_CCMVisitType.CIHIValue, ''''),


    dbo.AB_CCM_CancerCareInformation.AbstractID as zzNACRSLink,
    dbo.CC_Demographic.AbstractID as zzCCMDiseaseLink
FROM
    dbo.AB_ABstract with (nolock) inner join 
    dbo.H_InstitutionProfile H_InstitutionProfile_visit with (nolock) ON H_InstitutionProfile_visit.Code = dbo.AB_Abstract.InstitutionNumber inner JOIN
    dbo.AB_CCM_CancerCareInformation with (nolock) ON dbo.AB_ABstract.AbstractId = dbo.AB_CCM_CancerCareInformation.AbstractID inner join
    AB_Main with (nolock) ON dbo.AB_CCM_CancerCareInformation.CancerCareVisit = AB_Main.UniversalID inner join
    dbo.CC_Demographic with (nolock) ON AB_Main.AbstractID = dbo.CC_Demographic.AbstractID inner join 
    dbo.CC_DiseaseRegister with (nolock) ON dbo.CC_Demographic.AbstractID = dbo.CC_DiseaseRegister.AbstractID LEFT OUTER JOIN
    dbo.H_InstitutionProfile H_InstitutionProfile_submit with (nolock) ON H_InstitutionProfile_submit.Code = dbo.CC_Demographic.InstitutionNumber LEFT OUTER JOIN

    dbo.LU_MISCode with (nolock) ON dbo.AB_ABstract.MISCode = lu_MISCode.Code left join
    dbo.LU_ResidenceCode with (nolock) ON dbo.AB_ABstract.ResidenceCode = LU_ResidenceCode.Code left join
    dbo.LU_CodeFile LU_VisitProgramCode with (nolock) ON dbo.AB_CCM_CancerCareInformation.VisitProgramCode = LU_VisitProgramCode.Code left join
    dbo.LU_CodeFile LU_CCMVisitType with (nolock) ON dbo.AB_CCM_CancerCareInformation.CCMVisitType = LU_CCMVisitType.Code left join
    dbo.LU_YesNoAlpha LU_InpatientFlag with (nolock) ON dbo.AB_CCM_CancerCareInformation.InpatientFlag = LU_InpatientFlag.Code Left join
    dbo.LU_CodeFile LU_RadiationReviewFlag with (nolock) ON dbo.AB_CCM_CancerCareInformation.RadiationReviewFlag = LU_RadiationReviewFlag.Code Left join
    dbo.LU_Provider with (nolock) ON dbo.AB_CCM_CancerCareInformation.HealthCareProviderNumber = LU_Provider.Code 
where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB_ABstract.HospitalID is null or AB_ABstract.HospitalID = 0
    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB_ABstract.HospitalID, 0))


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_Entity_Disease_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[CCM_Entity_Disease_VR]
AS
SELECT     
    dbo.CC_Demographic.ChartNumber AS patient_chart_number, 
    --RIGHT(dbo.H_InstitutionProfile.CIHIValue, 3) 
    --(select top 1 FacilityNumber from dbo.H_HospitalProfile where isnull(dbo.H_InstitutionProfile.HospitalID, 0) in (0, dbo.H_HospitalProfile.Code) order by FacilityNumber desc)
    --''0930'' AS submitting_hospital_number, 
    right(''0'' + dbo.H_InstitutionProfile.CIHIValue, 4) as submitting_hospital_number, --ED - 02336 0930 is just for GR
    isnull(dbo.ICD_DiagFile10.CIHIValue, '''') AS diagnosis_code, 
    10 as diagnosis_code_version,
    isnull(dbo.LU_CC_Topography.CIHIValue, '''') AS topography_code, 
    (case when LU_TopoMorphVersion.CIHIValue = ''2'' 
          then isnull(dbo.LU_CC_Morphology_O2.CIHIValue, '''') 
          else isnull(dbo.LU_CC_Morphology_O3.CIHIValue, '''') end) AS morphology_code, 
    isnull(LU_TopoMorphVersion.CIHIValue, '''') AS topography_morphology_version, 
    isnull(LU_BasisDiag.CIHIValue, '''') AS basis_of_diagnosis, 
    isnull(convert(varchar(10), dbo.CC_DiseaseRegister.InitalDiagDate, 112), '''') AS date_of_initial_diagnosis, 
    isnull(right(dbo.LU_Institution_10.CIHIValue, 4), '''') AS diagnosis_hospital_number, 
    isnull(dbo.CC_DiseaseRegister.DiagHospitalChartNum , '''')AS diagnosis_hospital_chart_numbe, --PR - 03330
    isnull(dbo.CC_Demographic.PostalCode, '''') AS patient_postal_code_at_diag, 

    dbo.GetPostalDescription(isnull(dbo.CC_Demographic.PostalCode, ''''), isnull(dbo.CC_DiseaseRegister.RegisterDate, getdate())) AS postal_code_desc, -- ED - 01682

    isnull(right(dbo.LU_ResidenceCode.CIHIValue, 4), '''') AS patient_mohltc_resid_at_diag, 
    isnull(convert(varchar(10), dbo.CC_DiseaseRegister.RegisterDate, 112), '''') AS registration_date, 
    isnull(dbo.CC_DiseaseRegister.DiseaseSequenceNum, 0) AS disease_sequence_number, 
    isnull(LU_FirstSurgTreatFlag.CIHIValue, '''') AS surgical_treatment_flag, 
    isnull(convert(varchar(10), dbo.CC_DiseaseRegister.FirstSurgTreatDate, 112), '''') AS surgical_treatment_date, 

    isnull(LU_ClinStageDiag.STAGE, '''') AS clinical_stage_at_diag, 

    isnull(left(dbo.CC_CancerStageDiag.ClinStageDiag_T, 15), '''') AS clinical_stage_t_at_diag, 
    isnull(LU_ClinStageDiag_T_S.CIHIValue, '''') AS clinical_stage_t_suffix_at_diag, 
    isnull(left(dbo.CC_CancerStageDiag.ClinStageDiag_N, 15), '''') AS clinical_stage_n_at_diag, 
    isnull(LU_ClinStageDiag_N_S.CIHIValue, '''') AS clinical_stage_n_suffix_at_diag, 
    isnull(left(dbo.CC_CancerStageDiag.ClinStageDiag_M, 15), '''') AS clinical_stage_m_at_diag, 

    isnull(LU_PathStageDiag.STAGE, '''') AS path_stage_at_diag, 
    isnull(left(dbo.CC_CancerStageDiag.PathStageDiag_T, 15), '''') AS path_stage_t_at_diag, 
    isnull(LU_PathStageDiag_T_S.CIHIValue, '''') AS path_stage_t_suffix_at_diag, 
    isnull(left(dbo.CC_CancerStageDiag.PathStageDiag_N, 15), '''') AS path_stage_n_at_diag, 
    isnull(LU_PathStageDiag_N_S.CIHIValue, '''') AS path_stage_n_suffix_at_diag, 
    isnull(left(dbo.CC_CancerStageDiag.PathStageDiag_M, 15), '''') AS path_stage_m_at_diag, 

    isnull(LU_PostTherapyStage.STAGE, '''') AS post_therapy_stage_at_diag, 
    isnull(left(dbo.CC_CancerStageDiag.PostTherapyStage_T, 15), '''') AS post_therapy_t_at_diag, 
    isnull(LU_PostTherapyStage_T_S.CIHIValue, '''') AS post_therapy_t_suffix_at_diag, 
    isnull(left(dbo.CC_CancerStageDiag.PostTherapyStage_N, 15), '''') AS post_therapy_n_at_diag, 
    isnull(LU_PostTherapyStage_N_S.CIHIValue, '''') AS post_therapy_n_suffix_at_diag, 
    isnull(left(dbo.CC_CancerStageDiag.PostTherapyStage_M, 15), '''') AS post_therapy_m_at_diag, 

    isnull(left(dbo.CC_CancerStageDiag.ExtentDisease_cTNM, 10), '''') AS extent_disease_cTNM_at_pres, 
    isnull(left(dbo.CC_CancerStageDiag.ExtentDisease_cT, 10), '''') AS extent_disease_cT_at_pres, 
    isnull(left(dbo.CC_CancerStageDiag.ExtentDisease_cN, 10), '''') AS extent_disease_cN_at_pres, 
    isnull(left(dbo.CC_CancerStageDiag.ExtentDisease_cM, 10), '''') AS extent_disease_cM_at_pres, 
    isnull(left(dbo.CC_CancerStageDiag.ExtentDisease_pTNM, 10), '''') AS extent_disease_pTNM_at_pres, 
    isnull(left(dbo.CC_CancerStageDiag.ExtentDisease_pT, 10), '''') AS extent_disease_pT_at_pres, 
    isnull(left(dbo.CC_CancerStageDiag.ExtentDisease_pN, 10), '''') AS extent_disease_pN_at_pres, 
    isnull(left(dbo.CC_CancerStageDiag.ExtentDisease_pM, 10), '''') AS extent_disease_pM_at_pres, 
    LU_StagingVersion.CIHIValue AS staging_version,
    isnull(LU_AnalyticFlag.CIHIValue, '''') as analytic_flag,  --PR - 03587
    isnull(convert(varchar(10), dbo.CC_ReferralDate.MedicalOncologistRefDate, 112), '''') AS date_referral_med_oncologist, 
    isnull(convert(varchar(10), dbo.CC_ReferralDate.RadiationOncologistRefDate, 112), '''') AS date_referral_rad_oncologist, 
    isnull(convert(varchar(10), dbo.CC_ReferralDate.SurgicalOncologistRefDate, 112), '''') AS date_referral_surg_oncologist, 
    isnull(convert(varchar(10), dbo.CC_ReferralDate.PalliativeRefDate, 112), '''') AS date_referral_pall_prog, 
    isnull(convert(varchar(10), dbo.CC_ReferralDate.SocialWorkCareRefDate, 112), '''') AS date_referral_social_work, 
    isnull(convert(varchar(10), dbo.CC_ReferralDate.NutritionalRefDate, 112), '''') AS date_referral_nutri_therapy, 
    isnull(convert(varchar(10), dbo.CC_ReferralDate.PhysiotherapyRefDate, 112), '''') AS date_referral_physio, 
    isnull(convert(varchar(10), dbo.CC_ReferralDate.PsychiatryRefDate, 112), '''') AS date_referral_psychiatry, 
    isnull(convert(varchar(10), dbo.CC_ReferralDate.PsychologyRefDate, 112), '''') AS date_referral_psychology, 
    isnull(convert(varchar(10), dbo.CC_ReferralDate.OccupationalRefDate, 112), '''') AS date_referral_ot, 
    isnull(convert(varchar(10), dbo.CC_ReferralDate.SpeechRefDate, 112), '''') AS date_referral_speech_lang_path, 
    isnull(LU_Laterality.CIHIValue, '''') AS Laterality,

    dbo.CC_Demographic.AbstractID as zzAbstractLink
FROM         
    dbo.CC_Demographic with (nolock) LEFT OUTER JOIN
    dbo.H_InstitutionProfile with (nolock) ON dbo.H_InstitutionProfile.Code = dbo.CC_Demographic.InstitutionNumber LEFT OUTER JOIN
    dbo.CC_ReferralDate with (nolock) ON dbo.CC_Demographic.AbstractID = dbo.CC_ReferralDate.AbstractID LEFT OUTER JOIN
    dbo.LU_ResidenceCode with (nolock) ON dbo.CC_Demographic.ResidenceCode = dbo.LU_ResidenceCode.Code LEFT OUTER JOIN
    dbo.CC_CancerStageDiag with (nolock) ON dbo.CC_Demographic.AbstractID = dbo.CC_CancerStageDiag.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_StagingVersion with (nolock) ON LU_StagingVersion.Code = dbo.CC_CancerStageDiag.StagingVersion LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Laterality with (nolock) ON LU_Laterality.Code = dbo.CC_CancerStageDiag.Laterality FULL OUTER JOIN
    dbo.CC_DiseaseRegister with (nolock) ON dbo.CC_Demographic.AbstractID = dbo.CC_DiseaseRegister.AbstractID LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_FirstSurgTreatFlag with (nolock) ON LU_FirstSurgTreatFlag.Code = dbo.CC_DiseaseRegister.FirstSurgTreatFlag LEFT OUTER JOIN
    dbo.LU_Institution_10 with (nolock) ON dbo.CC_DiseaseRegister.DiagHospitalNum = dbo.LU_Institution_10.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_BasisDiag with (nolock) ON dbo.CC_DiseaseRegister.BasisDiag = LU_BasisDiag.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_TopoMorphVersion with (nolock) ON dbo.CC_DiseaseRegister.TopoMorphVersion = LU_TopoMorphVersion.Code LEFT OUTER JOIN
    dbo.ICD_DiagFile10 with (nolock) ON dbo.ICD_DiagFile10.Code = dbo.CC_DiseaseRegister.DiagnosisCode LEFT OUTER JOIN
    dbo.LU_CC_Morphology_O2 with (nolock) ON dbo.CC_DiseaseRegister.MorphologyCodeO2 = dbo.LU_CC_Morphology_O2.Code LEFT OUTER JOIN
    dbo.LU_CC_Morphology_O3 with (nolock) ON dbo.CC_DiseaseRegister.MorphologyCodeO3 = dbo.LU_CC_Morphology_O3.Code LEFT OUTER JOIN
    dbo.LU_CC_Topography with (nolock) ON dbo.CC_DiseaseRegister.TopographyCode = dbo.LU_CC_Topography.Code LEFT OUTER JOIN
    dbo.LLU_CC_STAGE_VALUE LU_ClinStageDiag with (nolock) ON dbo.CC_CancerStageDiag.ClinStageDiag = LU_ClinStageDiag.Code LEFT OUTER JOIN
    dbo.LLU_CC_STAGE_VALUE LU_PathStageDiag with (nolock) ON dbo.CC_CancerStageDiag.PathStageDiag = LU_PathStageDiag.Code LEFT OUTER JOIN
--PR - 03587
    dbo.LU_CodeFile LU_AnalyticFlag with (nolock) ON dbo.CC_DiseaseRegister.AnalyticFlag = LU_AnalyticFlag.Code LEFT OUTER JOIN
    --2.x-1503
    dbo.LU_CodeFile LU_ClinStageDiag_T_S with (nolock) ON dbo.CC_CancerStageDiag.ClinStageDiag_T_S = LU_ClinStageDiag_T_S.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_ClinStageDiag_N_S with (nolock) ON dbo.CC_CancerStageDiag.ClinStageDiag_N_S = LU_ClinStageDiag_N_S.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PathStageDiag_T_S with (nolock) ON dbo.CC_CancerStageDiag.PathStageDiag_T_S = LU_PathStageDiag_T_S.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PathStageDiag_N_S with (nolock) ON dbo.CC_CancerStageDiag.PathStageDiag_N_S = LU_PathStageDiag_N_S.Code LEFT OUTER JOIN
    dbo.LLU_CC_STAGE_VALUE LU_PostTherapyStage with (nolock) ON dbo.CC_CancerStageDiag.PostTherapyStage = LU_PostTherapyStage.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PostTherapyStage_T_S with (nolock) ON dbo.CC_CancerStageDiag.PostTherapyStage_T_S = LU_PostTherapyStage_T_S.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PostTherapyStage_N_S with (nolock) ON dbo.CC_CancerStageDiag.PostTherapyStage_N_S = LU_PostTherapyStage_N_S.Code 

where dbo.CC_Demographic.AppID = 675 
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_Entity_Healthcare_Professional_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[CCM_Entity_Healthcare_Professional_VR]
AS
SELECT distinct
    --ED - 02336
    --submitting_hospital_number = ''0930'', -- (select top 1 FacilityNumber from dbo.H_HospitalProfile where isnull((select top 1 HospitalID from dbo.H_InstitutionProfile where AssociationID = 8 and getdate() between validfrom and validto), 0) in (0, dbo.H_HospitalProfile.Code) order by FacilityNumber desc), 
    submitting_hospital_number = right((select top 1 ''0'' + CIHIValue from dbo.H_InstitutionProfile where associationid = 8), 4), 
    hcp_number = isnull(right(REPLICATE(''0'', 15) + ltrim(rtrim(LU_Provider.CIHIValue)), 15), ''''), 
    hcp_specialty_code = (select top 1 isnull(dbo.LU_ProviderSpecialty.CIHIValue, '''') 
                          from llu_ProviderSpecialty llu inner join dbo.LU_ProviderSpecialty on llu.code = dbo.LU_ProviderSpecialty.code
                          where  llu.AssociationID = LU_Provider.code   --PR - 05381 remove llu.Type = 1 and
                          order by llu.[Type], llu.Validto desc), 
    cco_program_code = isnull(LU_HCPProgramCode.CIHIValue, ''''), 
    hcp_surname = isnull(left(LU_Provider.ProvdrSurName, 20), ''''), 
    hcp_first_name = isnull(left(LU_Provider.ProvdrFirstName, 15), ''''), 
    hcp_status = isnull(LU_HCPStatus.CIHIValue, ''''), 
    host_hospital_hcp_number = isnull(right(REPLICATE(''0'', 15) + ltrim(rtrim(LU_Provider.CIHIValue)), 15), ''''), --isnull(right(REPLICATE(''0'', 15) + LU_HostHCPNumber.CIHIValue, 15), '''') AS , 
    DateStamp = m.LastUpdate
from dbo.LU_Provider LU_Provider with (nolock) 
    inner join (select RecordID, max(Updated) LastUpdate from dbo.H_UpdateHistory  with (nolock) where appid = 1104 group by RecordID) m
        on LU_Provider.Code = m.RecordID
    inner join LU_CodeFile LU_HCPProgramCode  with (nolock) ON LU_Provider.HCPProgramCode = LU_HCPProgramCode.Code
    inner join LU_CodeFile LU_HCPStatus with (nolock) ON LU_Provider.HCPStatus = LU_HCPStatus.Code
where exists (select * from dbo.llu_ProviderSpecialty s with (nolock) where AssociationID = LU_Provider.code and s.code > 0) --PR - 05381 remove and s.Type = 1)
    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or LU_Provider.HospitalID is null or LU_Provider.HospitalID = 0
    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(LU_Provider.HospitalID, 0)))
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_Entity_NDFP_Enrollment_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[CCM_Entity_NDFP_Enrollment_VR]
AS
SELECT     
    dbo.CC_Demographic.ChartNumber AS patient_chart_number, 
    isnull(right(dbo.LU_Institution_10.CIHIValue, 4), '''') AS visit_hospital_number, 
    --(select top 1 FacilityNumber from dbo.H_HospitalProfile where isnull(dbo.H_InstitutionProfile.HospitalID, 0) in (0, dbo.H_HospitalProfile.Code) order by FacilityNumber desc)  
    --''0930'' As submitting_hospital_number, 
    right(''0'' + H_InstitutionProfile.CIHIValue, 4) as submitting_hospital_number,   --ED - 02336
    isnull(dbo.CC_NDFP.NDFPNumber, '''') AS ndfp_form_number, 
    isnull(dbo.CC_NDFP.NDFPVersion, '''') AS ndfp_form_version_number, 
    isnull(right(replicate(''0'', 15) + dbo.LU_Provider.CIHIValue, 15), '''') AS hcp_number, 
    isnull(convert(varchar(10), dbo.CC_NDFP.FirstTreatDate, 112), '''') AS date_of_first_treatment, 
    isnull(dbo.CC_NDFP.Height, '''') AS height, 
    isnull(dbo.CC_NDFP.Weight, '''') AS weight, 
    isnull(dbo.CC_NDFP.BodySurfaceArea, '''') AS body_surface_area, 
    isnull(LU_Intent.CIHIValue, '''') as intent,
    isnull(left(dbo.CC_NDFP.EligAnswr1, 1), '''') AS eligibility_answer_1, 
    isnull(left(dbo.CC_NDFP.EligAnswr2, 1), '''') AS eligibility_answer_2, 
    isnull(left(dbo.CC_NDFP.EligAnswr3, 1), '''') AS eligibility_answer_3, 
    isnull(left(dbo.CC_NDFP.EligAnswr4, 1), '''') AS eligibility_answer_4, 
    isnull(left(dbo.CC_NDFP.EligAnswr5, 1), '''') AS eligibility_answer_5, 
    isnull(left(dbo.CC_NDFP.EligAnswr6, 1), '''') AS eligibility_answer_6, 
    isnull(left(dbo.CC_NDFP.EligAnswr7, 1), '''') AS eligibility_answer_7, 
    isnull(left(dbo.CC_NDFP.EligAnswr8, 1), '''') AS eligibility_answer_8, 
    isnull(left(dbo.CC_NDFP.EligAnswr9, 1), '''') AS eligibility_answer_9, 
    isnull(left(dbo.CC_NDFP.EligAnswr10, 1), '''') AS eligibility_answer_10, 
    isnull(left(dbo.CC_NDFP.EligAnswr11, 1), '''') AS eligibility_answer_11, 
    isnull(left(dbo.CC_NDFP.EligAnswr12, 1), '''') AS eligibility_answer_12, 
    isnull(left(dbo.CC_NDFP.EligAnswr13, 1), '''') AS eligibility_answer_13, 
    isnull(left(dbo.CC_NDFP.EligAnswr14, 1), '''') AS eligibility_answer_14, 
    isnull(left(dbo.CC_NDFP.EligAnswr15, 1), '''') AS eligibility_answer_15, 
    isnull(left(dbo.CC_NDFP.EligAnswr16, 1), '''') AS eligibility_answer_16, 
    isnull(left(dbo.CC_NDFP.EligAnswr17, 1), '''') AS eligibility_answer_17, 
    isnull(left(dbo.CC_NDFP.EligAnswr18, 1), '''') AS eligibility_answer_18, 
    isnull(left(dbo.CC_NDFP.EligAnswr19, 1), '''') AS eligibility_answer_19, 
    isnull(left(dbo.CC_NDFP.EligAnswr20, 1), '''') AS eligibility_answer_20, 
    isnull(left(dbo.CC_NDFP.EligAnswr21, 40), '''') AS eligibility_answer_21, 
    isnull(left(dbo.CC_NDFP.EligAnswr22, 40), '''') AS eligibility_answer_22, 
    isnull(left(dbo.CC_NDFP.EligAnswr23, 40), '''') AS eligibility_answer_23, 
    isnull(left(dbo.CC_NDFP.EligAnswr24, 40), '''') AS eligibility_answer_24, 
    isnull(left(dbo.CC_NDFP.EligAnswr25, 40), '''') AS eligibility_answer_25, 
    isnull(left(dbo.CC_NDFP.EligAnswr26, 40), '''') AS eligibility_answer_26, 
    isnull(left(dbo.CC_NDFP.EligAnswr27, 40), '''') AS eligibility_answer_27, 
    isnull(left(dbo.CC_NDFP.EligAnswr28, 40), '''') AS eligibility_answer_28, 
    isnull(left(dbo.CC_NDFP.EligAnswr29, 40), '''') AS eligibility_answer_29, 
    isnull(left(dbo.CC_NDFP.EligAnswr30, 40), '''') AS eligibility_answer_30,
    dbo.CC_Demographic.AbstractID as zzAbstractLink,
    dbo.CC_Demographic.LinkID as zzLinkID
FROM   
    dbo.CC_NDFP with (nolock) INNER JOIN
    dbo.CC_Demographic with (nolock) ON dbo.CC_NDFP.AbstractID = dbo.CC_Demographic.AbstractID 
    INNER JOIN    dbo.H_InstitutionProfile with (nolock) ON dbo.CC_Demographic.InstitutionNumber = dbo.H_InstitutionProfile.Code 
    LEFT OUTER JOIN dbo.LU_Institution_10 with (nolock) ON dbo.CC_NDFP.VisitHospitalNum = dbo.LU_Institution_10.Code 
    LEFT OUTER JOIN dbo.CC_HealthCareProf with (nolock) ON dbo.CC_Demographic.AbstractID = dbo.CC_HealthCareProf.AbstractID AND dbo.CC_HealthCareProf.Occurrence = 1 
    left JOIN dbo.LU_Provider with (nolock) ON dbo.CC_HealthCareProf.HCPNumber = dbo.LU_Provider.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_Intent with (nolock) ON dbo.CC_NDFP.Intent = LU_Intent.Code
where dbo.CC_Demographic.AppID = 676
    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or CC_Demographic.HospitalID is null or CC_Demographic.HospitalID = 0
    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(CC_Demographic.HospitalID, 0)))





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_Entity_Patient_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[CCM_Entity_Patient_VR]
AS
SELECT     
    --(select top 1 FacilityNumber from dbo.H_HospitalProfile where isnull(dbo.H_InstitutionProfile.HospitalID, 0) in (0, dbo.H_HospitalProfile.Code) order by FacilityNumber desc) 
    dbo.CC_Demographic.ChartNumber AS patient_chart_number, 
    --''0930'' AS submitting_hospital_number, 
    right(''0'' + dbo.H_InstitutionProfile.CIHIValue, 4) as submitting_hospital_number, --ED - 02336 0930 is just for GR
    isnull(left(dbo.CC_Demographic.LastName, 50), '''') AS patient_surname, 
    isnull(left(dbo.CC_Demographic.MaidenName, 50), '''') AS patient_maiden_name, 
    isnull(left(dbo.CC_Demographic.FirstName, 40), '''') AS patient_first_name, 
    isnull(left(dbo.CC_Demographic.MiddleName, 40), '''') AS patient_middle_name, 
    isnull(dbo.LU_Gender_I.CIHIValue, '''') AS patient_gender, 
    isnull(convert(varchar(10), dbo.CC_Demographic.BirthDate, 112), '''') AS patient_birth_date, 
    isnull(convert(varchar(10), dbo.CC_Demographic.DeathDate, 112), '''') AS patient_death_date, 
    isnull(dbo.CC_Demographic.HealthCareNumber, '''') AS health_card_number, 
    isnull(dbo.CC_Demographic.HCNVersion, '''') AS health_card_version, 
    isnull(dbo.LU_HCNProvince.CIHIValue, '''') AS province_issuing_health_card, 
    isnull(dbo.LU_RespPayment.CIHIValue, '''') AS responsibility_for_payment, 
    --isnull(dbo.CC_Demographic.HostChartNumber, '''') 
    dbo.CC_Demographic.ChartNumber AS host_hospital_patient_chart_nu, --PR-03328
    dbo.CC_DiseaseRegister.RegisterDate as RegistrationDate, 
    dbo.CC_Demographic.AbstractID AS zzAbstractLink, dbo.CC_Demographic.LinkID AS zzLinkID
FROM dbo.CC_Demographic with (nolock) inner join
    (select InstitutionNumber, ChartNumber, max(DiseaseSequenceNum) as MaxSeq
     from dbo.CC_Demographic D  with (nolock) 
        inner join dbo.CC_DiseaseRegister R with (nolock) ON D.AbstractID = R.AbstractID
        left  join dbo.CC_RecordInfo I with (nolock) ON D.AbstractID = I.AbstractID
     where D.AppID = 675 and InstitutionNumber > 0 and isnull(I.IsDeleted, 0) in (0, 2)
     group by InstitutionNumber, ChartNumber) M on dbo.CC_Demographic.ChartNumber = m.ChartNumber and dbo.CC_Demographic.InstitutionNumber = M.InstitutionNumber inner JOIN
    dbo.CC_DiseaseRegister with (nolock) ON dbo.CC_DiseaseRegister.AbstractID = dbo.CC_Demographic.AbstractID and M.MaxSeq = dbo.CC_DiseaseRegister.DiseaseSequenceNum LEFT OUTER JOIN
    dbo.LU_RespPayment with (nolock) ON dbo.LU_RespPayment.Code = dbo.CC_Demographic.ResponsiblePayment LEFT OUTER JOIN
    dbo.LU_HCNProvince with (nolock) ON dbo.CC_Demographic.HCNProvince = dbo.LU_HCNProvince.Code LEFT OUTER JOIN
    dbo.LU_Gender_I with (nolock) ON dbo.CC_Demographic.Gender = dbo.LU_Gender_I.Code LEFT OUTER JOIN
    dbo.H_InstitutionProfile with (nolock) ON dbo.CC_Demographic.InstitutionNumber = dbo.H_InstitutionProfile.Code
where dbo.CC_Demographic.AppID = 675
    --and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or CC_Demographic.HospitalID is null or CC_Demographic.HospitalID = 0
    --or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(CC_Demographic.HospitalID, 0)))
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_Entity_RadPlanTreatActivity_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[CCM_Entity_RadPlanTreatActivity_VR]
AS
SELECT     
    patient_chart_number = dbo.CC_Demographic.ChartNumber, 
    visit_hospital_number = right(H_InstitutionProfile_visit.CIHIValue, 4), 
    submitting_hospital_number = right(H_InstitutionProfile_submit.CIHIValue, 4), 
    mis_functional_centre = isnull(LU_MISCode.CIHIValue, ''''),
    visit_date = isnull(convert(varchar(20), AB_Abstract.AdmitDate, 112), ''''),
    visit_time = isnull(left(replace(convert(varchar(20),  AB_Abstract.AdmitTime, 114), '':'', ''''), 4), ''''),
    rt_protocol = left(isnull(LU_CC_RT_PROTOCOL.CIHIVAlue, ''''), 40),
    course_of_radiation_treatment = isnull(cast(dbo.AB_CCM_Radiation.CourseOfRadiationTreatment as varchar(10)), ''''),
    course_complete_flag = isnull(LU_CourseCompleteFlag.CIHIValue, ''''),
    nhpip_code = isnull(LU_CCM_NHPIP_Code.CIHIValue, ''''),
    body_region_code = isnull(LU_CCM_BodyRegion.CIHIValue, ''''),
    dose_per_fraction = isnull(dbo.AB_CCM_Radiation.DosePerFraction, ''''),
    intent_of_radiation_treatment = isnull(LU_IntentOfRadiationTreatment.CIHIValue, ''''),
    inpatient_flag = isnull(LU_InpatientFlag.CIHIValue, ''''),
    chemo_flag = isnull(LU_ChemoFlag.CIHIValue, ''''),
    clinical_trial_flag = isnull(LU_ClinicalTrialFlag.CIHIValue, ''''),
    
    registration_date = isnull(convert(varchar(10), dbo.CC_DiseaseRegister.RegisterDate, 112), ''''),
    disease_sequence_number = isnull(dbo.CC_DiseaseRegister.DiseaseSequenceNum, 0),
    hcp_number = isnull(right(Replicate(''0'', 15) + LU_Provider.CIHIValue, 15), ''''),

    decision_to_treat_date = isnull(convert(varchar(20), dbo.AB_CCM_Radiation.DecisionToTreatDate, 112), ''''),
    ready_to_treat_date = isnull(convert(varchar(20), dbo.AB_CCM_Radiation.ReadyToTreatDate, 112), ''''),
    urgency_category = isnull(LU_UrgencyCategory.CIHIValue, ''''),

    patient_postal_code = isnull(AB_Abstract.PostalCode, ''''),
    patient_mohltc_residence_code = isnull(LU_ResidenceCode.CIHIValue, ''''),
    
    trt_unit_name = isnull(dbo.AB_CCM_Radiation.TreatmentUnitName, ''''),

    dbo.AB_CCM_CancerCareInformation.AbstractID as zzNACRSLink,
    dbo.CC_Demographic.AbstractID as zzCCMDiseaseLink
FROM
    dbo.AB_ABstract with (nolock) inner join 
    dbo.H_InstitutionProfile H_InstitutionProfile_visit with (nolock) ON H_InstitutionProfile_visit.Code = dbo.AB_Abstract.InstitutionNumber inner JOIN
    dbo.AB_CCM_CancerCareInformation with (nolock) ON dbo.AB_ABstract.AbstractId = dbo.AB_CCM_CancerCareInformation.AbstractID inner join
    AB_Main with (nolock) ON dbo.AB_CCM_CancerCareInformation.CancerCareVisit = AB_Main.UniversalID inner join
    dbo.AB_CCM_Radiation with (nolock) ON dbo.AB_CCM_CancerCareInformation.AbstractID = dbo.AB_CCM_Radiation.AbstractID inner join
    dbo.CC_Demographic with (nolock) ON AB_Main.AbstractID = dbo.CC_Demographic.AbstractID inner join 
    dbo.CC_DiseaseRegister with (nolock) ON dbo.CC_Demographic.AbstractID = dbo.CC_DiseaseRegister.AbstractID LEFT OUTER JOIN
    dbo.H_InstitutionProfile H_InstitutionProfile_submit with (nolock) ON H_InstitutionProfile_submit.Code = dbo.CC_Demographic.InstitutionNumber LEFT OUTER JOIN

    dbo.LU_MISCode with (nolock) ON dbo.AB_ABstract.MISCode = lu_MISCode.Code left join
    dbo.LU_ResidenceCode with (nolock) ON dbo.AB_ABstract.ResidenceCode = LU_ResidenceCode.Code left join

    --dbo.LU_CodeFile LU_VisitProgramCode with (nolock) ON dbo.AB_CCM_CancerCareInformation.VisitProgramCode = LU_VisitProgramCode.Code left join
    --dbo.LU_CodeFile LU_CCMVisitType with (nolock) ON dbo.AB_CCM_CancerCareInformation.CCMVisitType = LU_CCMVisitType.Code left join
    dbo.LU_CodeFile LU_RadiationReviewFlag with (nolock) ON dbo.AB_CCM_CancerCareInformation.RadiationReviewFlag = LU_RadiationReviewFlag.Code Left join

    dbo.LU_YesNoAlpha LU_InpatientFlag with (nolock) ON dbo.AB_CCM_CancerCareInformation.InpatientFlag = LU_InpatientFlag.Code Left join
    dbo.LU_YesNoAlpha LU_ChemoFlag with (nolock) ON dbo.AB_CCM_CancerCareInformation.ChemoFlag = LU_ChemoFlag.Code Left join
    dbo.LU_YesNoAlpha LU_ClinicalTrialFlag with (nolock) ON dbo.AB_CCM_CancerCareInformation.ClinicalTrialFlag = LU_ClinicalTrialFlag.Code Left join
    dbo.LU_Provider with (nolock) ON dbo.AB_CCM_CancerCareInformation.HealthCareProviderNumber = LU_Provider.Code left join
    
    dbo.LU_YesNoAlpha LU_CourseCompleteFlag with (nolock) ON dbo.AB_CCM_Radiation.CourseCompleteFlag = LU_CourseCompleteFlag.Code left join
    dbo.LU_CCM_NHPIP_Code with (nolock) ON dbo.AB_CCM_Radiation.NHPIPCode = LU_CCM_NHPIP_Code.Code left join
    dbo.LU_CCM_BodyRegion with (nolock) ON dbo.AB_CCM_Radiation.BodyRegionCode = LU_CCM_BodyRegion.code left join
    dbo.LU_CodeFile LU_IntentOfRadiationTreatment with (nolock) ON dbo.AB_CCM_Radiation.IntentOfRadiationTreatment = LU_IntentOfRadiationTreatment.Code left join
    dbo.LU_CodeFile LU_UrgencyCategory with (nolock) ON dbo.AB_CCM_Radiation.UrgencyCategory = LU_UrgencyCategory.Code left join
    LU_CC_RT_PROTOCOL with (nolock) ON dbo.AB_CCM_Radiation.RTProtocol = LU_CC_RT_PROTOCOL.Code

where   LU_RadiationReviewFlag.CIHIValue = ''R''  
    --and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB_ABstract.HospitalID is null or AB_ABstract.HospitalID = 0
    --or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB_ABstract.HospitalID, 0)))

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_Entity_SysDrugDelivery_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[CCM_Entity_SysDrugDelivery_VR]
AS
SELECT     
    patient_chart_number = dbo.CC_Demographic.ChartNumber, 
    visit_hospital_number = right(H_InstitutionProfile_visit.CIHIValue, 4), 
    submitting_hospital_number = right(H_InstitutionProfile_submit.CIHIValue, 4), 
    mis_functional_centre = isnull(LU_MISCode.CIHIValue, ''''),
    visit_date = isnull(convert(varchar(20), AB_Abstract.AdmitDate, 112), ''''),
    visit_time = isnull(left(replace(convert(varchar(20),  AB_Abstract.AdmitTime, 114), '':'', ''''), 4), ''''),

    cco_regimen = isnull(LU_CCORegimen.CIHIValue, ''''),
    cco_drug_code = isnull(dbo.AB_CCM_SystemicDrug.CCODrugCode, ''''),
    din = isnull(dbo.AB_CCM_SystemicDrug.CCMDIN, ''''),
    drug_origin_flag = isnull(LU_DrugOriginFlag.CIHIValue, ''''),
    body_surface_area = isnull(cast(dbo.AB_CCM_SystemicDrug.BodySurfaceArea as varchar(20)), ''''),
    dose_administered = isnull(cast(dbo.AB_CCM_SystemicDrug.DoseAdministered as varchar(20)), ''''),
    measurement_unit = isnull(LU_MeasurementUnit.CIHIValue, ''''),
    route = isnull(LU_Route.CIHIValue, ''''),
    intent_of_systemic_treatment = isnull(LU_IntentOfSystemicTreatment.CIHIValue, ''''),
    line_of_therapy = isnull(cast(dbo.AB_CCM_SystemicDrug.LineOfTherapy as varchar(10)), ''''),

    inpatient_flag = isnull(LU_InpatientFlag.CIHIValue, ''''),
    clinical_trial_flag = isnull(LU_ClinicalTrialFlag.CIHIValue, ''''),
    arrived_but_not_treated = isnull(LU_ArrivedByNotTreatedFlag.CIHIValue, ''''),
    
    cmir_severity = isnull(LU_CMIRSeverity.CIHIValue, ''''),

    registration_date = isnull(convert(varchar(10), dbo.CC_DiseaseRegister.RegisterDate, 112), ''''),
    disease_sequence_number = isnull(dbo.CC_DiseaseRegister.DiseaseSequenceNum, 0),
    hcp_number = isnull(right(Replicate(''0'', 15) + LU_Provider.CIHIValue, 15), ''''),
    patient_postal_code = isnull(AB_Abstract.PostalCode, ''''),
    patient_mohltc_residence_code = isnull(LU_ResidenceCode.CIHIValue, ''''),
    
    dbo.AB_CCM_SystemicDrug.Occurrence as zzDrugOccurrence,
    dbo.AB_CCM_CancerCareInformation.AbstractID as zzNACRSLink,
    dbo.CC_Demographic.AbstractID as zzCCMDiseaseLink
FROM
    dbo.AB_ABstract inner join 
    dbo.H_InstitutionProfile H_InstitutionProfile_visit ON H_InstitutionProfile_visit.Code = dbo.AB_Abstract.InstitutionNumber inner JOIN
    dbo.AB_CCM_CancerCareInformation on dbo.AB_ABstract.AbstractId = dbo.AB_CCM_CancerCareInformation.AbstractID inner join
	-- '' PR 05464 2011-07-20, use LEFT OUTER JOIN (below) to include records with no SystemicDrug entries...
    AB_Main on dbo.AB_CCM_CancerCareInformation.CancerCareVisit = AB_Main.UniversalID LEFT OUTER JOIN -- inner join 
    dbo.AB_CCM_SystemicDrug on dbo.AB_CCM_CancerCareInformation.AbstractID = dbo.AB_CCM_SystemicDrug.AbstractID inner join
    dbo.CC_Demographic on AB_Main.AbstractID = dbo.CC_Demographic.AbstractID inner join 
    dbo.CC_DiseaseRegister ON dbo.CC_Demographic.AbstractID = dbo.CC_DiseaseRegister.AbstractID LEFT OUTER JOIN
    dbo.H_InstitutionProfile H_InstitutionProfile_submit ON H_InstitutionProfile_submit.Code = dbo.CC_Demographic.InstitutionNumber LEFT OUTER JOIN

    dbo.LU_MISCode on dbo.AB_ABstract.MISCode = lu_MISCode.Code left join
    dbo.LU_ResidenceCode on dbo.AB_ABstract.ResidenceCode = LU_ResidenceCode.Code left join

    dbo.LU_CodeFile LU_VisitProgramCode on dbo.AB_CCM_CancerCareInformation.VisitProgramCode = LU_VisitProgramCode.Code left join
    dbo.LU_CodeFile LU_CCMVisitType on dbo.AB_CCM_CancerCareInformation.CCMVisitType = LU_CCMVisitType.Code left join
    dbo.LU_CodeFile LU_RadiationReviewFlag on dbo.AB_CCM_CancerCareInformation.RadiationReviewFlag = LU_RadiationReviewFlag.Code Left join

    dbo.LU_YesNoAlpha LU_InpatientFlag on dbo.AB_CCM_CancerCareInformation.InpatientFlag = LU_InpatientFlag.Code Left join
    dbo.LU_YesNoAlpha LU_ChemoFlag on dbo.AB_CCM_CancerCareInformation.ChemoFlag = LU_ChemoFlag.Code Left join
     dbo.LU_YesNoAlpha LU_ClinicalTrialFlag on dbo.AB_CCM_CancerCareInformation.ClinicalTrialFlag = LU_ClinicalTrialFlag.Code Left join
    dbo.LU_Provider on dbo.AB_CCM_CancerCareInformation.HealthCareProviderNumber = LU_Provider.Code left join
    dbo.LU_YesNoAlpha LU_ArrivedByNotTreatedFlag on dbo.AB_CCM_CancerCareInformation.ArrivedByNotTreatedFlag = LU_ArrivedByNotTreatedFlag.Code left join
    
    dbo.LU_CodeFile LU_CCORegimen on dbo.AB_CCM_SystemicDrug.CCORegimen = LU_CCORegimen.Code left join
    dbo.LU_YesNoAlpha LU_DrugOriginFlag on dbo.AB_CCM_SystemicDrug.DrugOriginFlag = LU_DrugOriginFlag.Code left join
    dbo.LU_CodeFile LU_MeasurementUnit on dbo.AB_CCM_SystemicDrug.MeasurementUnit = LU_MeasurementUnit.Code left join
    dbo.LU_CodeFile LU_Route on dbo.AB_CCM_SystemicDrug.[Route] = LU_Route.Code left join
    dbo.LU_CodeFile LU_IntentOfSystemicTreatment on dbo.AB_CCM_SystemicDrug.IntentOfSystemicTreatment = LU_IntentOfSystemicTreatment.Code left join
    dbo.LU_CodeFile LU_CMIRSeverity on dbo.AB_CCM_SystemicDrug.CMIRSeverity = LU_CMIRSeverity.Code 
where AB_CCM_CancerCareInformation.CancerCareVisit > 0 and AB_CCM_SystemicDrug.CCORegimen > 0  --   LU_ChemoFlag.CIHIValue = ''Y'' 

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_HealthCareProfessional_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[CCM_HealthCareProfessional_VR]
AS
SELECT     dbo.CC_HealthCareProf.FirstName AS HCPFirstName, dbo.CC_HealthCareProf.Occurrence AS HCPOccurrence, 
    LU_HCPNumber.DisplayCode AS HCPNumber, LU_HCPNumber.UserDescription AS HCPNumberDesc, 
    LU_ProgramCode.DisplayCode AS HCPProgramCode, LU_ProgramCode.UserDescription AS HCPProgramCodeDesc, 
    dbo.LU_ProviderSpecialty.DisplayCode AS HCPSpecialtyCode, dbo.LU_ProviderSpecialty.UserDescription AS HCPSpecialtyCodeDesc, 
    LU_Status.DisplayCode AS HCPStatus, LU_Status.UserDescription AS HCPStatusDesc, dbo.CC_HealthCareProf.SurName AS HCPSurname, 
    LU_HostHCPNumber.DisplayCode AS HostHCPNumber, LU_HostHCPNumber.UserDescription AS HostHCPNumberDesc, 
    dbo.CC_HealthCareProf.AbstractID AS zzAbstractLink
FROM         dbo.CC_HealthCareProf with (nolock) LEFT OUTER JOIN
    dbo.LU_Provider LU_HostHCPNumber with (nolock) ON dbo.CC_HealthCareProf.HostHCPNumber = LU_HostHCPNumber.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Status with (nolock) ON dbo.CC_HealthCareProf.Status = LU_Status.Code LEFT OUTER JOIN
    dbo.LU_ProviderSpecialty with (nolock) ON dbo.CC_HealthCareProf.SpecialtyCode = dbo.LU_ProviderSpecialty.Code LEFT OUTER JOIN
    dbo.LU_Provider LU_HCPNumber with (nolock) ON dbo.CC_HealthCareProf.HCPNumber = LU_HCPNumber.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_ProgramCode with (nolock) ON dbo.CC_HealthCareProf.ProgramCode = LU_ProgramCode.Code
where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or LU_HostHCPNumber.HospitalID is null or LU_HostHCPNumber.HospitalID = 0
    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(LU_HostHCPNumber.HospitalID, 0))
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_NDFP_Enrollment_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[CCM_NDFP_Enrollment_VR]
AS
SELECT     
    VisitHospitalNumber = dbo.LU_Institution_10.DisplayCode, VisitHospitalNumberDesc = dbo.LU_Institution_10.UserDescription, 

    NDFPFormNumber = dbo.CC_NDFP.NDFPNumber, 
    NDFPFormVersionNumber = dbo.CC_NDFP.NDFPVersion, 
    dbo.CC_NDFP.FirstTreatDate, 

    dbo.CC_NDFP.Height, 
    dbo.CC_NDFP.Weight,  
    dbo.CC_NDFP.BodySurfaceArea, 
    Intent = LU_Intent.DisplayCode, IntentDesc = LU_Intent.UserDescription, 
    EligibilityAnswer1  = dbo.CC_NDFP.EligAnswr1, 
    EligibilityAnswer2  = dbo.CC_NDFP.EligAnswr2,
    EligibilityAnswer3  = dbo.CC_NDFP.EligAnswr3, 
    EligibilityAnswer4  = dbo.CC_NDFP.EligAnswr4, 
    EligibilityAnswer5  = dbo.CC_NDFP.EligAnswr5, 
    EligibilityAnswer6  = dbo.CC_NDFP.EligAnswr6, 
    EligibilityAnswer7  = dbo.CC_NDFP.EligAnswr7, 
    EligibilityAnswer8  = dbo.CC_NDFP.EligAnswr8, 
    EligibilityAnswer9  = dbo.CC_NDFP.EligAnswr9, 
    EligibilityAnswer10 = dbo.CC_NDFP.EligAnswr10, 
    EligibilityAnswer11 = dbo.CC_NDFP.EligAnswr11, 
    EligibilityAnswer12 = dbo.CC_NDFP.EligAnswr12, 
    EligibilityAnswer13 = dbo.CC_NDFP.EligAnswr13, 
    EligibilityAnswer14 = dbo.CC_NDFP.EligAnswr14, 
    EligibilityAnswer15 = dbo.CC_NDFP.EligAnswr15, 
    EligibilityAnswer16 = dbo.CC_NDFP.EligAnswr16, 
    EligibilityAnswer17 = dbo.CC_NDFP.EligAnswr17, 
    EligibilityAnswer18 = dbo.CC_NDFP.EligAnswr18, 
    EligibilityAnswer19 = dbo.CC_NDFP.EligAnswr19, 
    EligibilityAnswer20 = dbo.CC_NDFP.EligAnswr20, 
    EligibilityAnswer21 = dbo.CC_NDFP.EligAnswr21, 
    EligibilityAnswer22 = dbo.CC_NDFP.EligAnswr22, 
    EligibilityAnswer23 = dbo.CC_NDFP.EligAnswr23, 
    EligibilityAnswer24 = dbo.CC_NDFP.EligAnswr24, 
    EligibilityAnswer25 = dbo.CC_NDFP.EligAnswr25, 
    EligibilityAnswer26 = dbo.CC_NDFP.EligAnswr26, 
    EligibilityAnswer27 = dbo.CC_NDFP.EligAnswr27, 
    EligibilityAnswer28 = dbo.CC_NDFP.EligAnswr28, 
    EligibilityAnswer29 = dbo.CC_NDFP.EligAnswr29, 
    EligibilityAnswer30 = dbo.CC_NDFP.EligAnswr30, 
    dbo.CC_NDFP.AbstractID as zzAbstractLink
FROM   
    dbo.CC_NDFP with (nolock) 
    LEFT OUTER JOIN dbo.LU_Institution_10  with (nolock) ON dbo.CC_NDFP.VisitHospitalNum = dbo.LU_Institution_10.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_Intent with (nolock) ON dbo.CC_NDFP.Intent = LU_Intent.Code




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_UD_Abstracting_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[CCM_UD_Abstracting_VR]
AS
SELECT
    dbo.CC_UserDefined.UDDate1 AS Date1UD, 
    dbo.CC_UserDefined.UDDate2 AS Date2UD, 
    dbo.CC_UserDefined.UDDate3 AS Date3UD, 
    dbo.CC_UserDefined.UDDate4 AS Date4UD, 
    dbo.CC_UserDefined.UDDate5 AS Date5UD, 
    dbo.CC_UDFieldsDate.UDDate6  AS Date6UD, 
    dbo.CC_UDFieldsDate.UDDate7  AS Date7UD, 
    dbo.CC_UDFieldsDate.UDDate8  AS Date8UD, 
    dbo.CC_UDFieldsDate.UDDate9  AS Date9UD, 
    dbo.CC_UDFieldsDate.UDDate10 AS Date10UD, 
    dbo.CC_UDFieldsDate.UDDate11 AS Date11UD, 
    dbo.CC_UDFieldsDate.UDDate12 AS Date12UD, 
    dbo.CC_UDFieldsDate.UDDate13 AS Date13UD, 
    dbo.CC_UDFieldsDate.UDDate14 AS Date14UD, 
    dbo.CC_UDFieldsDate.UDDate15 AS Date15UD, 
    dbo.CC_UDFieldsDate.UDDate16 AS Date16UD, 
    dbo.CC_UDFieldsDate.UDDate17 AS Date17UD, 
    dbo.CC_UDFieldsDate.UDDate18 AS Date18UD, 
    dbo.CC_UDFieldsDate.UDDate19 AS Date19UD, 
    dbo.CC_UDFieldsDate.UDDate20 AS Date20UD, 
    dbo.CC_UDFieldsDate.UDDate21 AS Date21UD, 
    dbo.CC_UDFieldsDate.UDDate22 AS Date22UD, 
    dbo.CC_UDFieldsDate.UDDate23 AS Date23UD, 
    dbo.CC_UDFieldsDate.UDDate24 AS Date24UD, 
    dbo.CC_UDFieldsDate.UDDate25 AS Date25UD, 
    
    LU_UD_01.DisplayCode AS Lookup1UD,     LU_UD_01.UserDescription AS Lookup1UDDesc, 
    LU_UD_02.DisplayCode AS Lookup2UD,     LU_UD_02.UserDescription AS Lookup2UDDesc, 
    LU_UD_03.DisplayCode AS Lookup3UD,     LU_UD_03.UserDescription AS Lookup3UDDesc, 
    LU_UD_04.DisplayCode AS Lookup4UD,     LU_UD_04.UserDescription AS Lookup4UDDesc, 
    LU_UD_05.DisplayCode AS Lookup5UD,     LU_UD_05.UserDescription AS Lookup5UDDesc, 
    LU_UD_06.DisplayCode AS Lookup6UD,     LU_UD_06.UserDescription AS Lookup6UDDesc, 
    LU_UD_07.DisplayCode AS Lookup7UD,     LU_UD_07.UserDescription AS Lookup7UDDesc, 
    LU_UD_08.DisplayCode AS Lookup8UD,     LU_UD_08.UserDescription AS Lookup8UDDesc, 
    LU_UD_09.DisplayCode AS Lookup9UD,     LU_UD_09.UserDescription AS Lookup9UDDesc, 
    LU_UD_10.DisplayCode AS Lookup10UD,    LU_UD_10.UserDescription AS Lookup10UDDesc, 
    LU_UD_11.DisplayCode AS Lookup11UD,     LU_UD_11.UserDescription AS Lookup11UDDesc, 
    LU_UD_12.DisplayCode AS Lookup12UD,     LU_UD_12.UserDescription AS Lookup12UDDesc, 
    LU_UD_13.DisplayCode AS Lookup13UD,     LU_UD_13.UserDescription AS Lookup13UDDesc, 
    LU_UD_14.DisplayCode AS Lookup14UD,     LU_UD_14.UserDescription AS Lookup14UDDesc, 
    LU_UD_15.DisplayCode AS Lookup15UD,     LU_UD_15.UserDescription AS Lookup15UDDesc, 
    LU_UD_16.DisplayCode AS Lookup16UD,     LU_UD_16.UserDescription AS Lookup16UDDesc, 
    LU_UD_17.DisplayCode AS Lookup17UD,     LU_UD_17.UserDescription AS Lookup17UDDesc, 
    LU_UD_18.DisplayCode AS Lookup18UD,     LU_UD_18.UserDescription AS Lookup18UDDesc, 
    LU_UD_19.DisplayCode AS Lookup19UD,     LU_UD_19.UserDescription AS Lookup19UDDesc, 
    LU_UD_20.DisplayCode AS Lookup20UD,     LU_UD_20.UserDescription AS Lookup20UDDesc, 
    LU_UD_21.DisplayCode AS Lookup21UD,     LU_UD_21.UserDescription AS Lookup21UDDesc, 
    LU_UD_22.DisplayCode AS Lookup22UD,     LU_UD_22.UserDescription AS Lookup22UDDesc, 
    LU_UD_23.DisplayCode AS Lookup23UD,     LU_UD_23.UserDescription AS Lookup23UDDesc, 
    LU_UD_24.DisplayCode AS Lookup24UD,     LU_UD_24.UserDescription AS Lookup24UDDesc, 
    LU_UD_25.DisplayCode AS Lookup25UD,     LU_UD_25.UserDescription AS Lookup25UDDesc, 

    dbo.CC_UserDefined.UDInteger1 AS Numeric1UD, 
    dbo.CC_UserDefined.UDInteger2 AS Numeric2UD, 
    dbo.CC_UserDefined.UDInteger3 AS Numeric3UD, 
    dbo.CC_UserDefined.UDInteger4 AS Numeric4UD, 
    dbo.CC_UserDefined.UDInteger5 AS Numeric5UD, 
    dbo.CC_UDFieldsInteger.UDInteger6  AS Numeric6UD, 
    dbo.CC_UDFieldsInteger.UDInteger7  AS Numeric7UD, 
    dbo.CC_UDFieldsInteger.UDInteger8  AS Numeric8UD, 
    dbo.CC_UDFieldsInteger.UDInteger9  AS Numeric9UD, 
    dbo.CC_UDFieldsInteger.UDInteger10 AS Numeric10UD, 
    dbo.CC_UDFieldsInteger.UDInteger11 AS Numeric11UD, 
    dbo.CC_UDFieldsInteger.UDInteger12 AS Numeric12UD, 
    dbo.CC_UDFieldsInteger.UDInteger13 AS Numeric13UD, 
    dbo.CC_UDFieldsInteger.UDInteger14 AS Numeric14UD, 
    dbo.CC_UDFieldsInteger.UDInteger15 AS Numeric15UD, 
    dbo.CC_UDFieldsInteger.UDInteger16 AS Numeric16UD, 
    dbo.CC_UDFieldsInteger.UDInteger17 AS Numeric17UD, 
    dbo.CC_UDFieldsInteger.UDInteger18 AS Numeric18UD, 
    dbo.CC_UDFieldsInteger.UDInteger19 AS Numeric19UD, 
    dbo.CC_UDFieldsInteger.UDInteger20 AS Numeric20UD, 
    dbo.CC_UDFieldsInteger.UDInteger21 AS Numeric21UD, 
    dbo.CC_UDFieldsInteger.UDInteger22 AS Numeric22UD, 
    dbo.CC_UDFieldsInteger.UDInteger23 AS Numeric23UD, 
    dbo.CC_UDFieldsInteger.UDInteger24 AS Numeric24UD, 
    dbo.CC_UDFieldsInteger.UDInteger25 AS Numeric25UD, 

    dbo.CC_UserDefined.UDText1 AS Notes1UD, 
    dbo.CC_UserDefined.UDText2 AS Notes2UD, 
    dbo.CC_UserDefined.UDText3 AS Notes3UD, 
    dbo.CC_UserDefined.UDText4 AS Notes4UD, 
    dbo.CC_UserDefined.UDText5 AS Notes5UD, 
    dbo.CC_UDFieldsText.UDText6 AS Notes6UD, 
    dbo.CC_UDFieldsText.UDText7 AS Notes7UD, 
    dbo.CC_UDFieldsText.UDText8 AS Notes8UD, 
    dbo.CC_UDFieldsText.UDText9 AS Notes9UD, 
    dbo.CC_UDFieldsText.UDText10 AS Notes10UD, 
    dbo.CC_UDFieldsText.UDText11 AS Notes11UD, 
    dbo.CC_UDFieldsText.UDText12 AS Notes12UD, 
    dbo.CC_UDFieldsText.UDText13 AS Notes13UD, 
    dbo.CC_UDFieldsText.UDText14 AS Notes14UD, 
    dbo.CC_UDFieldsText.UDText15 AS Notes15UD, 
    dbo.CC_UDFieldsText.UDText16 AS Notes16UD, 
    dbo.CC_UDFieldsText.UDText17 AS Notes17UD, 
    dbo.CC_UDFieldsText.UDText18 AS Notes18UD, 
    dbo.CC_UDFieldsText.UDText19 AS Notes19UD, 
    dbo.CC_UDFieldsText.UDText20 AS Notes20UD, 
    dbo.CC_UDFieldsText.UDText21 AS Notes21UD, 
    dbo.CC_UDFieldsText.UDText22 AS Notes22UD, 
    dbo.CC_UDFieldsText.UDText23 AS Notes23UD, 
    dbo.CC_UDFieldsText.UDText24 AS Notes24UD, 
    dbo.CC_UDFieldsText.UDText25 AS Notes25UD, 

    dbo.CC_UserDefined.UDSmallText1 AS Text1UD, 
    dbo.CC_UserDefined.UDSmallText2 AS Text2UD, 
    dbo.CC_UserDefined.UDSmallText3 AS Text3UD, 
    dbo.CC_UserDefined.UDSmallText4 AS Text4UD, 
    dbo.CC_UserDefined.UDSmallText5 AS Text5UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText6 AS Text6UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText7 AS Text7UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText8 AS Text8UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText9 AS Text9UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText10 AS Text10UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText11 AS Text11UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText12 AS Text12UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText13 AS Text13UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText14 AS Text14UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText15 AS Text15UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText16 AS Text16UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText17 AS Text17UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText18 AS Text18UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText19 AS Text19UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText20 AS Text20UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText21 AS Text21UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText22 AS Text22UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText23 AS Text23UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText24 AS Text24UD, 
    dbo.CC_UDFieldsSmallText.UDSmallText25 AS Text25UD, 

    dbo.CC_UserDefined.UDTime1 AS Time1UD, 
    dbo.CC_UserDefined.UDTime2 AS Time2UD, 
    dbo.CC_UserDefined.UDTime3 AS Time3UD, 
    dbo.CC_UserDefined.UDTime4 AS Time4UD, 
    dbo.CC_UserDefined.UDTime5 AS Time5UD, 
    dbo.CC_UDFieldsTime.UDTime6 AS Time6UD, 
    dbo.CC_UDFieldsTime.UDTime7 AS Time7UD, 
    dbo.CC_UDFieldsTime.UDTime8 AS Time8UD, 
    dbo.CC_UDFieldsTime.UDTime9 AS Time9UD, 
    dbo.CC_UDFieldsTime.UDTime10 AS Time10UD, 
    dbo.CC_UDFieldsTime.UDTime11 AS Time11UD, 
    dbo.CC_UDFieldsTime.UDTime12 AS Time12UD, 
    dbo.CC_UDFieldsTime.UDTime13 AS Time13UD, 
    dbo.CC_UDFieldsTime.UDTime14 AS Time14UD, 
    dbo.CC_UDFieldsTime.UDTime15 AS Time15UD, 
    dbo.CC_UDFieldsTime.UDTime16 AS Time16UD, 
    dbo.CC_UDFieldsTime.UDTime17 AS Time17UD, 
    dbo.CC_UDFieldsTime.UDTime18 AS Time18UD, 
    dbo.CC_UDFieldsTime.UDTime19 AS Time19UD, 
    dbo.CC_UDFieldsTime.UDTime20 AS Time20UD, 
    dbo.CC_UDFieldsTime.UDTime21 AS Time21UD, 
    dbo.CC_UDFieldsTime.UDTime22 AS Time22UD, 
    dbo.CC_UDFieldsTime.UDTime23 AS Time23UD, 
    dbo.CC_UDFieldsTime.UDTime24 AS Time24UD, 
    dbo.CC_UDFieldsTime.UDTime25 AS Time25UD, 

    dbo.CC_Demographic.Abstractid AS zzAbstractLink
FROM  [dbo].[CC_Demographic] with (nolock) LEFT OUTER JOIN      
    dbo.CC_UserDefined with (nolock) on CC_Demographic.AbstractID = CC_UserDefined.AbstractID LEFT OUTER JOIN
    [dbo].[CC_UDFieldsDate] with (nolock) on CC_Demographic.AbstractID = CC_UDFieldsDate.AbstractID LEFT OUTER JOIN
    [dbo].[CC_UDFieldsInteger] with (nolock) on CC_Demographic.AbstractID = CC_UDFieldsInteger.AbstractID LEFT OUTER JOIN
    [dbo].[CC_UDFieldsLookUp] with (nolock) on CC_Demographic.AbstractID = CC_UDFieldsLookUp.AbstractID LEFT OUTER JOIN
    [dbo].[CC_UDFieldsSmallText] with (nolock) on CC_Demographic.AbstractID = CC_UDFieldsSmallText.AbstractID LEFT OUTER JOIN
    [dbo].[CC_UDFieldsText] with (nolock) on CC_Demographic.AbstractID = CC_UDFieldsText.AbstractID LEFT OUTER JOIN
    [dbo].[CC_UDFieldsTime] with (nolock) on CC_Demographic.AbstractID = CC_UDFieldsTime.AbstractID LEFT OUTER JOIN

    dbo.LU_CodeFile LU_UD_01 with (nolock) ON dbo.CC_UserDefined.UDLookup1 = LU_UD_01.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_02 with (nolock) ON dbo.CC_UserDefined.UDLookup2 = LU_UD_02.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_03 with (nolock) ON dbo.CC_UserDefined.UDLookup3 = LU_UD_03.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_04 with (nolock) ON dbo.CC_UserDefined.UDLookup4 = LU_UD_04.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_05 with (nolock) ON dbo.CC_UserDefined.UDLookup5 = LU_UD_05.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_06 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup6  = LU_UD_06.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_07 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup7  = LU_UD_07.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_08 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup8  = LU_UD_08.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_09 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup9  = LU_UD_09.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_10 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup10 = LU_UD_10.Code LEFT OUTER JOIN

    dbo.LU_CodeFile LU_UD_11 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup11 = LU_UD_11.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_12 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup12 = LU_UD_12.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_13 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup13 = LU_UD_13.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_14 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup14 = LU_UD_14.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_15 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup15 = LU_UD_15.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_16 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup16 = LU_UD_16.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_17 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup17 = LU_UD_17.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_18 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup18 = LU_UD_18.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_19 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup19 = LU_UD_19.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_20 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup20 = LU_UD_20.Code LEFT OUTER JOIN

    dbo.LU_CodeFile LU_UD_21 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup21 = LU_UD_21.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_22 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup22 = LU_UD_22.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_23 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup23 = LU_UD_23.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_24 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup24 = LU_UD_24.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD_25 with (nolock) ON dbo.CC_UDFieldsLookUp.UDLookup25 = LU_UD_25.Code 
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[CCM_UpdateHistory_VR]
AS
SELECT     dbo.H_HospitalProfile.DisplayCode AS Hospital, dbo.H_HospitalProfile.UserDescription AS HospitalDesc, dbo.U_Users.DisplayCode AS UpdateCoder, 
                      dbo.U_Users.UserDescription AS UpdateCoderDesc, dbo.CC_UpdateHistory.Updated AS UpdateDate, dbo.CC_UpdateHistory.UpdateType, 
                      dbo.CC_UpdateHistory.AbstractID AS zzAbstractLink
FROM         dbo.CC_UpdateHistory with (nolock) LEFT OUTER JOIN
                      dbo.H_HospitalProfile with (nolock) ON dbo.H_HospitalProfile.Code = dbo.CC_UpdateHistory.HospitalID LEFT OUTER JOIN
                      dbo.U_Users with (nolock) ON dbo.CC_UpdateHistory.Coder = dbo.U_Users.Code




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CCM_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE View [dbo].[CCM_VR]
as
SELECT     

AbstractType = Lu_Application.DisplayCode, AbstractTypeDesc = Lu_Application.UserDescription,
--PR - 03587
LU_AnalyticFlag.DisplayCode as AnalyticCaseFlag, LU_AnalyticFlag.UserDescription as AnalyticCaseFlagDesc, 

LU_BasisOfDiagnosis.DisplayCode as BasisOfDiagnosis, LU_BasisOfDiagnosis.UserDescription as BasisOfDiagnosisDesc, 
dbo.CC_Demographic.BirthDate, 

dbo.CC_Demographic.ChartNumber, 

LU_ClinStageDiag.STAGE  as ClinicalStageAtDiagnosis,
dbo.CC_CancerStageDiag.ClinStageDiag_M  as ClinicalStageAtDiagnosis_M, 
dbo.CC_CancerStageDiag.ClinStageDiag_N  as ClinicalStageAtDiagnosis_N, 
LU_ClinStageDiag_N_S.Displaycode AS ClinicalStageAtDiagnosis_N_Suffix, LU_ClinStageDiag_N_S.UserDescription AS ClinicalStageAtDiagnosis_N_SuffixDesc, 
dbo.CC_CancerStageDiag.ClinStageDiag_T  as ClinicalStageAtDiagnosis_T,
LU_ClinStageDiag_T_S.Displaycode AS ClinicalStageAtDiagnosis_T_Suffix, LU_ClinStageDiag_T_S.UserDescription AS ClinicalStageAtDiagnosis_T_SuffixDesc, 


dbo.CC_CollaborateStageDiag.Extension as CSExtension,
LU_CSLymphNodes.DisplayCode as CSLymphNodes, LU_CSLymphNodes.UserDescription as CSLymphNodesDesc,
dbo.CC_CollaborateStageDiag.MetastasesDiag as CSMetastasesAtDiagnosis, 
dbo.CC_CollaborateStageDiag.MetastasesEval as CSMetastasesEvaluated, 
LU_CSRegionalNodesEvaluation.DisplayCode as CSRegionalNodesEvaluation, LU_CSRegionalNodesEvaluation.UserDescription as CSRegionalNodesEvaluationDesc, 
dbo.CC_CollaborateStageDiag.RegionNodeExamined as CSRegionalNodesExamined, 
LU_CSRegionalNodesPositive.DisplayCode as CSRegionalNodesPositive, LU_CSRegionalNodesPositive.UserDescription as CSRegionalNodesPositiveDesc, 
dbo.CC_CollaborateStageDiag.SiteSpecFactor1 as CSSiteSpecificFactor1,
dbo.CC_CollaborateStageDiag.SiteSpecFactor2 as CSSiteSpecificFactor2,
dbo.CC_CollaborateStageDiag.SiteSpecFactor3 as CSSiteSpecificFactor3,
dbo.CC_CollaborateStageDiag.SiteSpecFactor4 as CSSiteSpecificFactor4,
dbo.CC_CollaborateStageDiag.SiteSpecFactor5 as CSSiteSpecificFactor5,
dbo.CC_CollaborateStageDiag.SiteSpecFactor6 as CSSiteSpecificFactor6,
dbo.CC_CollaborateStageDiag.TumourExtensionEval as CSTumourExtensionEvaluation, 
dbo.CC_CollaborateStageDiag.TumourSize as CSTumourSize, 
dbo.CC_CollaborateStageDiag.Version as CSVersion, 

LU_DataEntryCoderNumber.DisplayCode as DataEntryCoderNumber, LU_DataEntryCoderNumber.UserDescription as DataEntryCoderNumberDesc, 
dbo.CC_Demographic.DeathDate AS DatePatientDied, 
LU_DeathIndicator.DisplayCode as DeathIndicator, LU_DeathIndicator.UserDescription as DeathIndicatorDesc, 
LU_DiagnosisCode.DisplayCode as DiagnosisCode, LU_DiagnosisCode.UserDescription as DiagnosisCodeDesc, 
dbo.CC_DiseaseRegister.DiagHospitalChartNum as DiagnosisHospitalChartNumber, 
LU_DiagnosisHospitalNumber.DisplayCode as DiagnosisHospitalNumber, LU_DiagnosisHospitalNumber.UserDescription as DiagnosisHospitalNumberDesc,
dbo.CC_DiseaseRegister.DiagnosisVersion,

dbo.CC_DischargeInfo.DischargeAge,
LU_DischargeAgeCode.DisplayCode as DischargeAgeCode, LU_DischargeAgeCode.UserDescription as DischargeAgeCodeDesc,
dbo.CC_DischargeInfo.DischargeDate, 
dbo.CC_DiseaseRegister.DiseaseSequenceNum as DiseaseSequenceNumber,
LU_DispositionCode.DisplayCode as DispositionCode, LU_DispositionCode.UserDescription as DispositionCodeDesc, 

dbo.CC_DiseaseRegister.DurationDiseaseReg as DurationSinceDiseaseRegistry, 
dbo.CC_DiseaseRegister.DurationInitDiag as DurationSinceInitialDiagnosis,
dbo.CC_DischargeInfo.DurationInMonths, 
dbo.CC_ReferralDate.DurationPalliativeCare,


dbo.CC_CancerStageDiag.ExtentDisease_cM  as ExtentDisease_cM, 
dbo.CC_CancerStageDiag.ExtentDisease_cN  as ExtentDisease_cN, 
dbo.CC_CancerStageDiag.ExtentDisease_cT  as ExtentDisease_cT, 
dbo.CC_CancerStageDiag.ExtentDisease_cTNM  as  ExtentDisease_cTNM, 
dbo.CC_CancerStageDiag.ExtentDisease_pM  as ExtentDisease_pM,  
dbo.CC_CancerStageDiag.ExtentDisease_pN  as ExtentDisease_pN, 
dbo.CC_CancerStageDiag.ExtentDisease_pT  as ExtentDisease_pT, 
dbo.CC_CancerStageDiag.ExtentDisease_pTNM  as ExtentDisease_pTNM, 

--(select top 1 FacilityNumber from dbo.H_HospitalProfile where isnull(dbo.H_InstitutionProfile.HospitalID, 0) in (0, dbo.H_HospitalProfile.Code) order by FacilityNumber desc) AS FacilityNumber, 

dbo.CC_RecordInfo.CCRegFileDate as FileRunDate,
LU_FileRunBy.DisplayCode as FileRunBy, LU_FileRunBy.UserDescription as FileRunByDesc, 
dbo.CC_Demographic.FirstName, 
LU_FirstSurgicalTreatFlag.DisplayCode as FirstSurgicalTreatFlag, LU_FirstSurgicalTreatFlag.UserDescription as FirstSurgicalTreatFlagDesc, 
dbo.CC_DiseaseRegister.FirstSurgTreatDate as FirstSurgicalTreatmentDate, 
FixedChartNumber,

LU_Gender_I.DisplayCode as Gender, LU_Gender_I.UserDescription as GenderDesc, 

LU_HCNProvince.DisplayCode as HCNProvince, LU_HCNProvince.UserDescription as HCNProvinceDesc, 
dbo.CC_Demographic.HCNVersion, 
dbo.CC_Demographic.HealthCareNumber, 
H_HospitalProfile.DisplayCode as Hospital, H_HospitalProfile.UserDescription as HospitalDesc,  
--dbo.CC_Demographic.HostChartNumber as HostHospitalChartNumber, 
dbo.CC_Demographic.ChartNumber as HostHospitalChartNumber, 
HospitalAccountRecord,
LU_InitialDiagnosisAgeCode.DisplayCode as InitialDiagnosisAgeCode, LU_InitialDiagnosisAgeCode.UserDescription as InitialDiagnosisAgeCodeDesc, 
dbo.CC_DiseaseRegister.DiagAgeNumber as InitialDiagnosisAgeNumber,
dbo.CC_DiseaseRegister.InitalDiagDate as InitalDiagnosisDate,
H_InstitutionProfile.DisplayCode as InstitutionNumber, H_InstitutionProfile.UserDescription as InstitutionNumberDesc,  
dbo.CC_RecordInfo.InputDate, dbo.CC_RecordInfo.InputTime,
LU_IsCompleted.DisplayCode as IsCompleted, LU_IsCompleted.UserDescription as IsCompletedDesc, 
LU_CIHICorrect.DisplayCode as IsCorrected, LU_CIHICorrect.UserDescription as IsCorrectedDesc, 
LU_IsDeleted.DisplayCode as IsDeleted, LU_IsDeleted.UserDescription as IsDeletedDesc,
LU_IsSubmited.DisplayCode as IsSubmited, LU_IsSubmited.UserDescription as IsSubmitedDesc, 
LU_IsValidated.DisplayCode as IsValidated, LU_IsValidated.UserDescription as IsValidatedDesc, 

dbo.CC_Demographic.LastName, 
LU_Laterality.DisplayCode as Laterality, LU_Laterality.UserDescription as LateralityDesc,  

dbo.CC_Demographic.MaidenName, 
dbo.CC_ReferralDate.MedicalOncologistRefDate, dbo.CC_ReferralDate.DurationMedicalOncologist AS MedicalOncologistWaitTime, 
dbo.CC_Demographic.MiddleName,

dbo.CC_ReferralDate.NutritionalRefDate as NutritionalTherapyReferralDate,
dbo.CC_ReferralDate.DurationNutritional as NutritionalTherapyWaitTime,

LU_CC_Morphology_O2.DisplayCode as MorphologyCode_O2, LU_CC_Morphology_O2.UserDescription as MorphologyCode_O2Desc, 
LU_CC_Morphology_O3.DisplayCode as MorphologyCode_O3, LU_CC_Morphology_O2.UserDescription as MorphologyCode_O3Desc, 
LU_MorphologyCodeVersion.DisplayCode as MorphologyCodeVersion, LU_MorphologyCodeVersion.UserDescription as MorphologyCodeVersionDesc, 

dbo.CC_ReferralDate.OccupationalRefDate as OccupationalTherapyReferralDate,
dbo.CC_ReferralDate.DurationOccupational as OccupationalTherapyWaitTime,

dbo.CC_ReferralDate.PalliativeRefDate,

LU_PathStageDiag.STAGE  as PathologicalStageAtDiagnosis,
dbo.CC_CancerStageDiag.PathStageDiag_M  as PathologicalStageAtDiagnosis_M, 
dbo.CC_CancerStageDiag.PathStageDiag_N  as PathologicalStageAtDiagnosis_N, 
LU_PathStageDiag_N_S.Displaycode AS PathologicalStageAtDiagnosis_N_Suffix, LU_PathStageDiag_N_S.UserDescription AS PathologicalStageAtDiagnosis_N_SuffixDesc, 
dbo.CC_CancerStageDiag.PathStageDiag_T  as PathologicalStageAtDiagnosis_T, 
LU_PathStageDiag_T_S.Displaycode AS PathologicalStageAtDiagnosis_T_Suffix, LU_PathStageDiag_T_S.UserDescription AS PathologicalStageAtDiagnosis_T_SuffixDesc, 

dbo.CC_Demographic.PostalCode, 
dbo.GetPostalDescription(isnull(dbo.CC_Demographic.PostalCode, ''''), isnull(dbo.CC_DiseaseRegister.RegisterDate, getdate())) AS PostalCodeDesc, -- ED - 01682

LU_PostTherapyStage.STAGE  as PostTherapyStage,
dbo.CC_CancerStageDiag.PostTherapyStage_M  as PostTherapyStage_M, 
dbo.CC_CancerStageDiag.PostTherapyStage_N  as PostTherapyStage_N, 
LU_PostTherapyStage_N_S.Displaycode AS PostTherapyStage_N_Suffix, LU_PostTherapyStage_N_S.UserDescription AS PostTherapyStage_N_SuffixDesc, 
dbo.CC_CancerStageDiag.PostTherapyStage_T  as PostTherapyStage_T, 
LU_PostTherapyStage_T_S.Displaycode AS PostTherapyStage_T_Suffix, LU_PostTherapyStage_T_S.UserDescription AS PostTherapyStage_T_SuffixDesc, 

LU_Province.DisplayCode as ProvinceNumber, LU_Province.UserDescription as ProvinceNumberDesc, 

LU_PhysicianCompletedForm.DisplayCode as PhysicianCompletedForm, LU_PhysicianCompletedForm.UserDescription as PhysicianCompletedFormDesc, 

dbo.CC_ReferralDate.PhysiotherapyRefDate as PhysiotherapyReferralDate,
dbo.CC_ReferralDate.DurationPhysiotherapy as PhysiotherapyWaitTime,
dbo.CC_ReferralDate.PsychiatryRefDate as PsychiatryReferralDate,
dbo.CC_ReferralDate.DurationPsychiatry as PsychiatryWaitTime,
dbo.CC_ReferralDate.PsychologyRefDate as PsychologyReferralDate,
dbo.CC_ReferralDate.DurationPsychology as PsychologyWaitTime,

dbo.CC_ReferralDate.RadiationOncologistRefDate, dbo.CC_ReferralDate.DurationRadiationOncologist AS RadiationOncologistWaitTime, 
dbo.CC_DiseaseRegister.RegisterDate as RegistrationDate, 
LU_ReportingMonth.DisplayCode as ReportingMonth, LU_ReportingMonth.UserDescription as ReportingMonthDesc, 

LU_ResidenceCode.DisplayCode as ResidenceCode, LU_ResidenceCode.UserDescription as ResidenceCodeDesc, 
LU_RespPayment.DisplayCode as ResponsiblityForPayment, LU_RespPayment.UserDescription as ResponsiblityForPaymentDesc, 

dbo.CC_ReferralDate.SocialWorkCareRefDate as SocialWorkCareReferralDate,
dbo.CC_ReferralDate.DurationSocialWorkCare as SocialWorkCareWaitTime,

LU_SourceOfInfo.DisplayCode as SourceOfInfo, LU_SourceOfInfo.UserDescription as SourceOfInfoDesc, 

dbo.CC_ReferralDate.SpeechRefDate as SpeechLanguagePathologyReferralDate,
dbo.CC_ReferralDate.DurationSpeech as SpeechLanguagePathologyWaitTime,

LU_StagingComplete.DisplayCode as StagingComplete, LU_StagingComplete.UserDescription as StagingCompleteDesc, 

LU_STAGEABLE.STAGEABLE as StagingRequired, 
LU_StagingVersion.DisplayCode as StagingVersion, LU_StagingVersion.UserDescription as StagingVersionDesc, 
dbo.CC_ReferralDate.SupportCareRefDate, dbo.CC_ReferralDate.DurationSupportCare AS SupportCareWaitTime, 
dbo.CC_ReferralDate.SurgicalOncologistRefDate, dbo.CC_ReferralDate.DurationSurgicalOncologist AS SurgicalOncologistWaitTime,


LU_CC_Topography.DisplayCode as TopographyCode, LU_CC_Topography.UserDescription as TopographyCodeDesc, 
UniversalEpisodeIdentifier,
dbo.CC_Demographic.AbstractID as zzAbstractLink, dbo.CC_Demographic.LinkID as zzLinkID

FROM         
dbo.CC_Demographic with (nolock) LEFT OUTER JOIN
LU_Province with (nolock) ON dbo.CC_Demographic.ProvinceNumber = LU_Province.Code  LEFT OUTER JOIN
H_HospitalProfile with (nolock) ON dbo.CC_Demographic.HospitalID = H_HospitalProfile.Code  LEFT OUTER JOIN
H_InstitutionProfile with (nolock) ON dbo.CC_Demographic.InstitutionNumber = H_InstitutionProfile.Code  LEFT OUTER JOIN
LU_Gender_I with (nolock) ON dbo.CC_Demographic.Gender = LU_Gender_I.Code  LEFT OUTER JOIN
LU_ResidenceCode with (nolock) ON dbo.CC_Demographic.ResidenceCode = LU_ResidenceCode.Code  LEFT OUTER JOIN
LU_YesNoSystem LU_DeathIndicator with (nolock) ON dbo.CC_Demographic.DeathIndicator = LU_DeathIndicator.Code  LEFT OUTER JOIN
LU_HCNProvince with (nolock) ON dbo.CC_Demographic.HCNProvince = LU_HCNProvince.Code  LEFT OUTER JOIN
LU_RespPayment with (nolock) ON dbo.CC_Demographic.ResponsiblePayment = LU_RespPayment.Code  LEFT OUTER JOIN

dbo.CC_DiseaseRegister with (nolock) ON dbo.CC_Demographic.AbstractID = dbo.CC_DiseaseRegister.AbstractID LEFT OUTER JOIN
dbo.U_Users LU_DataEntryCoderNumber with (nolock) ON dbo.CC_DiseaseRegister.CoderNumber = LU_DataEntryCoderNumber.Code  LEFT OUTER JOIN
LU_Institution_10 LU_DiagnosisHospitalNumber with (nolock) ON dbo.CC_DiseaseRegister.DiagHospitalNum = LU_DiagnosisHospitalNumber.Code  LEFT OUTER JOIN
LU_AgeCode LU_InitialDiagnosisAgeCode with (nolock) ON dbo.CC_DiseaseRegister.DiagAgeCode = LU_InitialDiagnosisAgeCode.Code  LEFT OUTER JOIN
LU_CodeFile LU_BasisOfDiagnosis with (nolock) ON dbo.CC_DiseaseRegister.BasisDiag = LU_BasisOfDiagnosis.Code  LEFT OUTER JOIN
LU_YesNoAlpha LU_FirstSurgicalTreatFlag with (nolock) ON dbo.CC_DiseaseRegister.FirstSurgTreatFlag = LU_FirstSurgicalTreatFlag.Code  LEFT OUTER JOIN
ICD_DiagFile10 LU_DiagnosisCode with (nolock) ON dbo.CC_DiseaseRegister.DiagnosisCode = LU_DiagnosisCode.Code  LEFT OUTER JOIN
LU_CC_Topography with (nolock) ON dbo.CC_DiseaseRegister.TopographyCode = LU_CC_Topography.Code  LEFT OUTER JOIN
LU_CodeFile LU_MorphologyCodeVersion with (nolock) ON dbo.CC_DiseaseRegister.TopoMorphVersion = LU_MorphologyCodeVersion.Code  LEFT OUTER JOIN
LU_CC_Morphology_O2 with (nolock) ON dbo.CC_DiseaseRegister.MorphologyCodeO2 = LU_CC_Morphology_O2.Code  LEFT OUTER JOIN
LU_CC_Morphology_O3 with (nolock) ON dbo.CC_DiseaseRegister.MorphologyCodeO3 = LU_CC_Morphology_O3.Code  LEFT OUTER JOIN
--PR - 03587
dbo.LU_CodeFile LU_AnalyticFlag with (nolock) ON dbo.CC_DiseaseRegister.AnalyticFlag = LU_AnalyticFlag.Code  LEFT OUTER JOIN

dbo.CC_CancerStageDiag with (nolock) ON dbo.CC_Demographic.AbstractID = dbo.CC_CancerStageDiag.AbstractID LEFT OUTER JOIN
LU_CodeFile LU_StagingVersion with (nolock) ON dbo.CC_CancerStageDiag.StagingVersion = LU_StagingVersion.Code  LEFT OUTER JOIN
LU_CodeFile LU_Laterality with (nolock) ON dbo.CC_CancerStageDiag.Laterality = LU_Laterality.Code  LEFT OUTER JOIN


dbo.CC_ReferralDate with (nolock) ON dbo.CC_Demographic.AbstractID = dbo.CC_ReferralDate.AbstractID LEFT OUTER JOIN
dbo.CC_RecordInfo with (nolock) ON dbo.CC_Demographic.AbstractID = dbo.CC_RecordInfo.AbstractID LEFT OUTER JOIN
dbo.LU_AbstractStatus LU_IsValidated with (nolock) ON dbo.CC_RecordInfo.IsValidated = LU_IsValidated.Code LEFT OUTER JOIN
dbo.LU_AbstractStatus LU_IsCompleted with (nolock) ON dbo.CC_RecordInfo.IsCompleted = LU_IsCompleted.Code LEFT OUTER JOIN
dbo.LU_YesNoAlpha LU_CompleteRecord with (nolock) ON  dbo.CC_RecordInfo.CompleteRecord = LU_CompleteRecord.Code LEFT OUTER JOIN
dbo.LU_YesNoSystem LU_IsSubmited with (nolock) ON dbo.CC_RecordInfo.IsSubmited = LU_IsSubmited.Code LEFT OUTER JOIN
dbo.U_Users LU_FileRunBy with (nolock) ON dbo.CC_RecordInfo.CCRegFileCoder = LU_FileRunBy.Code LEFT OUTER JOIN
dbo.LU_DeleteStatus LU_IsDeleted with (nolock) ON dbo.CC_RecordInfo.IsDeleted = LU_IsDeleted.Code  LEFT OUTER JOIN
dbo.LU_CIHICorrect with (nolock) ON dbo.CC_RecordInfo.IsCorrected = LU_CIHICorrect.Code  LEFT OUTER JOIN

dbo.CC_CollaborateStageDiag with (nolock) ON dbo.CC_Demographic.AbstractID = dbo.CC_CollaborateStageDiag.AbstractID LEFT OUTER JOIN
LU_CodeFile LU_CSLymphNodes with (nolock) ON dbo.CC_CollaborateStageDiag.LymphNodes = LU_CSLymphNodes.Code  LEFT OUTER JOIN
LU_CodeFile LU_CSRegionalNodesEvaluation with (nolock) ON dbo.CC_CollaborateStageDiag.RegionNodeEval = LU_CSRegionalNodesEvaluation.Code  LEFT OUTER JOIN
LU_CodeFile LU_CSRegionalNodesPositive with (nolock) ON dbo.CC_CollaborateStageDiag.RegionNodePositive = LU_CSRegionalNodesPositive.Code  LEFT OUTER JOIN

dbo.LLU_CC_STAGE_VALUE LU_ClinStageDiag with (nolock) ON dbo.CC_CancerStageDiag.ClinStageDiag = LU_ClinStageDiag.Code LEFT OUTER JOIN
dbo.LLU_CC_STAGE_VALUE LU_PathStageDiag with (nolock) ON dbo.CC_CancerStageDiag.PathStageDiag = LU_PathStageDiag.Code LEFT OUTER JOIN
dbo.LLU_CC_SITE_GROUP LU_STAGEABLE with (nolock) ON LU_DiagnosisCode.CIHIValue = LU_STAGEABLE.ICD10CA LEFT OUTER JOIN
dbo.LU_AppIDs LU_Application with (nolock) ON dbo.CC_Demographic.AppID = LU_Application.Code LEFT OUTER JOIN
dbo.LU_BatchPeriod LU_ReportingMonth with (nolock) ON dbo.CC_DiseaseRegister.ReportingMonth = LU_ReportingMonth.Code LEFT OUTER JOIN
dbo.LU_CodeFile LU_StagingComplete with (nolock) ON dbo.CC_CancerStageDiag.StagingComplete = LU_StagingComplete.Code LEFT OUTER JOIN
dbo.LU_CodeFile LU_SourceOfInfo with (nolock) ON dbo.CC_CancerStageDiag.SourceOfInfo = LU_SourceOfInfo.Code LEFT OUTER JOIN
dbo.LU_Provider LU_PhysicianCompletedForm with (nolock) ON dbo.CC_CancerStageDiag.PhysicianCompletedForm = LU_PhysicianCompletedForm.Code LEFT OUTER JOIN
dbo.CC_DischargeInfo with (nolock) ON dbo.CC_DischargeInfo.AbstractID = dbo.CC_Demographic.AbstractID LEFT OUTER JOIN 
dbo.LU_DispositionCode_I LU_DispositionCode with (nolock) ON dbo.CC_DischargeInfo.DispositionCode = LU_DispositionCode.Code LEFT OUTER JOIN
dbo.LU_AgeCode LU_DischargeAgeCode with (nolock) ON dbo.CC_DischargeInfo.DischargeAgeCode = LU_DischargeAgeCode.Code LEFT OUTER JOIN
    --2.x-1503
    dbo.LU_CodeFile LU_ClinStageDiag_T_S with (nolock) ON dbo.CC_CancerStageDiag.ClinStageDiag_T_S = LU_ClinStageDiag_T_S.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_ClinStageDiag_N_S with (nolock) ON dbo.CC_CancerStageDiag.ClinStageDiag_N_S = LU_ClinStageDiag_N_S.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PathStageDiag_T_S with (nolock) ON dbo.CC_CancerStageDiag.PathStageDiag_T_S = LU_PathStageDiag_T_S.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PathStageDiag_N_S with (nolock) ON dbo.CC_CancerStageDiag.PathStageDiag_N_S = LU_PathStageDiag_N_S.Code LEFT OUTER JOIN
    dbo.LLU_CC_STAGE_VALUE LU_PostTherapyStage with (nolock) ON dbo.CC_CancerStageDiag.PostTherapyStage = LU_PostTherapyStage.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PostTherapyStage_T_S with (nolock) ON dbo.CC_CancerStageDiag.PostTherapyStage_T_S = LU_PostTherapyStage_T_S.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PostTherapyStage_N_S with (nolock) ON dbo.CC_CancerStageDiag.PostTherapyStage_N_S = LU_PostTherapyStage_N_S.Code 


/*
LU_CodeFile LU_ on dbo.CC_Demographic. = LU_.Code  LEFT OUTER JOIN
LU_CodeFile LU_ on dbo.CC_Demographic. = LU_.Code  LEFT OUTER JOIN
LU_CodeFile LU_ on dbo.CC_Demographic. = LU_.Code  LEFT OUTER JOIN
LU_CodeFile LU_ on dbo.CC_Demographic. = LU_.Code  LEFT OUTER JOIN
LU_CodeFile LU_ on dbo.CC_Demographic. = LU_.Code  LEFT OUTER JOIN
*/
--QA - 00032 disable the domain securite issue
----PR - 07485
--where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or CC_Demographic.HospitalID is null or CC_Demographic.HospitalID = 0
--    --EN - 00666
--    or Is_Member(nullif(ReportGroup, '''')) = 1
----    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(CC_Demographic.HospitalID, 0))



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_Alerts_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'




CREATE  VIEW [dbo].[Central_Patient_Alerts_VR]
AS
SELECT     
AlertAllergyCode       = Lookup1.DisplayCode, 
AlertAllergyCodeDesc   = Lookup1.UserDescription, 
AlertAllergyNote       = dbo.CM_Alert.AlertNote, 
AlertAllergyOccurance  = dbo.CM_Alert.AlertOccurrence, 
zzPatientLink          = dbo.CM_Alert.PatientID
FROM      dbo.CM_Alert  with (nolock) 
LEFT JOIN dbo.LU_Alert Lookup1 with (nolock) ON dbo.CM_Alert.AlertCode = Lookup1.Code








' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_Alias_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE  VIEW [dbo].[Central_Patient_Alias_VR]
AS
SELECT     
    AlternateFirstName      = FirstAlias, 
    AlternateLastName       = LastAlias, 
    AlternateMaidenName     = MaidenAlias, 
    AlternateMiddleName     = MiddleAlias, 
    AlternateNamesOccurance = AliasOccurrence, 
    zzPatientLink           = PatientID
FROM dbo.CM_Alias  with (nolock) 







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_BabyChart_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE  VIEW [dbo].[Central_Patient_BabyChart_VR]
AS
SELECT     
BabyChartNumber    = REPLACE(SPACE(10 - LEN(BabyChartNumber)) + BabyChartNumber, '' '', ''0''), 
BabyChartOccurance = BabyChartOccurrence, 
zzPatientLink      = PatientID
FROM dbo.CM_BabyChart with (nolock)







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_Contacts_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[Central_Patient_Contacts_VR]
AS
SELECT     dbo.CM_Address.Address1 AS CAddress1, dbo.CM_Address.Address2 AS CAddress2, dbo.CM_Address.CellPhone AS CCellPhone, 
                      dbo.CM_Address.City AS CCity, dbo.LU_CPI_Country.DisplayCode AS CCountry, dbo.LU_CPI_Country.UserDescription AS CCountryDesc, 
                      dbo.CM_Address.EMail AS CEMail, dbo.CM_Address.FaxNumber AS CFaxNumber, dbo.CM_Address.ContactName AS CName, 
                      dbo.CM_Address.Occurrence AS COccurrence, dbo.CM_Address.PhoneNumber1 AS CPhoneNumber1, 
                      dbo.CM_Address.PhoneNumber2 AS CPhoneNumber2, dbo.CM_Address.PostalCode AS CPostalCode, dbo.LU_CPI_Province.DisplayCode AS CProvince,
                       dbo.LU_CPI_Province.UserDescription AS CProvinceDesc, dbo.LU_Relationship.DisplayCode AS CRelationship, 
                      dbo.LU_Relationship.UserDescription AS CRelationshipDesc, dbo.LU_CodeFile.DisplayCode AS CType, 
                      dbo.LU_CodeFile.UserDescription AS CTypeDesc, dbo.CM_Address.PatientID AS zzPatientLink
FROM         dbo.CM_Address with (nolock) LEFT OUTER JOIN
    dbo.LU_Relationship with (nolock) ON dbo.CM_Address.Relationship = dbo.LU_Relationship.Code LEFT OUTER JOIN
    dbo.LU_CPI_Country with (nolock) ON dbo.CM_Address.Country = dbo.LU_CPI_Country.Code LEFT OUTER JOIN
    dbo.LU_CPI_Province with (nolock) ON dbo.CM_Address.Province = dbo.LU_CPI_Province.Code LEFT OUTER JOIN
    dbo.LU_CodeFile with (nolock) ON dbo.CM_Address.ContactType = dbo.LU_CodeFile.Code







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_Index_Alias_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'





CREATE VIEW [dbo].[Central_Patient_Index_Alias_VR]
AS
SELECT     AliasOccurrence, FirstAlias AS FirstNameAlias, LastAlias AS LastNameAlias, MaidenAlias AS MaidenNameAlias, MiddleAlias AS MiddleNameAlias, 
                      PatientID AS zzPatientLink
FROM         dbo.CM_Alias with (nolock) 






' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_Index_Notes_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE view [dbo].[Central_Patient_Index_Notes_VR]
as
SELECT     
   RecordID AS zzPatientLink,
   LogNote  as CPINotes,
   LogDate  as DateLogged,
   LogTime  as TimeLogged,
   U.DisplayCode as CreateBy,
   U.UserDescription as CreatorName        
from dbo.REC_Notes r with (nolock) left join U_users U with (nolock) ON r.LogCoder=u.code
where AppID = 0



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_LinkedChart_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[Central_Patient_LinkedChart_VR]
AS
SELECT     dbo.CM_ChartLink.LinkChartNumber, dbo.CM_ChartLink.LinkChartOccurrence, dbo.LU_ChartLinkType.DisplayCode AS LinkChartType, 
                      dbo.LU_ChartLinkType.UserDescription AS LinkChartTypeDesc, dbo.CM_ChartLink.PatientID AS zzPatientLink
FROM         dbo.CM_ChartLink with (nolock) LEFT OUTER JOIN
                      dbo.LU_ChartLinkType with (nolock) on dbo.CM_ChartLink.LinkType = dbo.LU_ChartLinkType.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_MergeChart_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[Central_Patient_MergeChart_VR]
AS
SELECT     dbo.U_Users.DisplayCode AS CoderNumber, dbo.U_Users.UserDescription AS CoderNumberDesc, dbo.CM_CPI_Merge.DateMerged AS MergedDate, 
                      dbo.CM_CPI_Merge.ChartNumberTo AS NewChartNumber, dbo.CM_CPI_Merge.ChartNumberFrom AS OldChartNumber, 
                      dbo.CM_CPI_Merge.PatientIDTo AS zzNewPatientLink, dbo.CM_CPI_Merge.PatientIDFrom AS zzOldPatientLink
FROM         dbo.CM_CPI_Merge with (nolock) LEFT OUTER JOIN
                      dbo.U_Users with (nolock) on dbo.CM_CPI_Merge.CoderNumber = dbo.U_Users.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_RiskFactors_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE view [dbo].[Central_Patient_RiskFactors_VR]
as
select
    RiskOccurrence = Occurrence,
    RiskFactor = LU_RiskFactor.DisplayCode, LU_RiskFactorDesc = LU_RiskFactor.UserDescription,
    Exposure = LU_Exposure.DisplayCode, ExposureDesc = LU_Exposure.UserDescription, 
    dbo.CM_RiskFactors.StartDate,
    AgeOfOnset = dbo.CM_RiskFactors.AgeAtOnset,
    dbo.CM_RiskFactors.EndDate,
    RiskNotes = dbo.CM_RiskFactors.Notes,
    zzPatientLink = PatientID
from dbo.CM_RiskFactors with (nolock) 
    left join lu_codefile LU_RiskFactor with (nolock) on dbo.CM_RiskFactors.RiskFactor = LU_RiskFactor.Code
    left join lu_codefile LU_Exposure with (nolock) on dbo.CM_RiskFactors.Exposure = LU_Exposure.Code


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[Central_Patient_UpdateHistory_VR]
AS
SELECT
    U_Users.DisplayCode as UpdateCoder,
    U_Users.UserDescription as UpdateCoderDesc, 
    CM_UpdateHistory.Updated as UpdateDate,  
    CM_UpdateHistory.UpdateType, 
    CM_UpdateHistory.PatientID AS zzPatientLink
FROM       CM_UpdateHistory with (nolock)  
    inner join U_Users with (nolock) On CM_UpdateHistory.Coder = U_Users.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_Volume_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[Central_Patient_Volume_UpdateHistory_VR]
AS
SELECT     dbo.U_Users.DisplayCode AS UpdateCoder, dbo.U_Users.UserDescription AS UpdateCoderDescription, dbo.CM_Volume_UpdateHistory.Updated, 
                      dbo.CM_Volume_UpdateHistory.UpdateType, dbo.CM_Volume_UpdateHistory.VolumeID AS zzVolumeLink
FROM         dbo.CM_Volume_UpdateHistory with (nolock) LEFT OUTER JOIN
                      dbo.U_Users with (nolock) On dbo.CM_Volume_UpdateHistory.Coder = dbo.U_Users.Code


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Central_Patient_Volume_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[Central_Patient_Volume_VR]
AS
SELECT 
dbo.CM_CPI_Volume.CLBoxNumber AS BoxNumber, dbo.CM_CPI_Volume.CLComments AS Comments, 
--LU_YesNoSystem_4.DisplayCode AS ContainsAmcareData, LU_YesNoSystem_4.UserDescription AS ContainsAmcareDataDesc, 
(case dbo.CM_CPI_Volume.CLAmcare when 1 then LU_Yes.DisplayCode when 2 then LU_No.DisplayCode end) AS ContainsAmcareData, 
(case dbo.CM_CPI_Volume.CLAmcare when 1 then LU_Yes.UserDescription when 2 then LU_No.UserDescription end) AS ContainsAmcareDataDesc, 

--LU_YesNoSystem_1.DisplayCode AS ContainsInpatientData, LU_YesNoSystem_1.UserDescription AS ContainsInpatientDataDesc, 
(case dbo.CM_CPI_Volume.CLInpatient when 1 then LU_Yes.DisplayCode when 2 then LU_No.DisplayCode end) AS ContainsInpatientData, 
(case dbo.CM_CPI_Volume.CLInpatient when 1 then LU_Yes.UserDescription when 2 then LU_No.UserDescription end) AS ContainsInpatientDataDesc, 

--LU_YesNoSystem_11.DisplayCode AS ContainsMicrofilm, LU_YesNoSystem_11.UserDescription AS ContainsMicrofilmDesc, 
(case dbo.CM_CPI_Volume.CLMicroFilm when 1 then LU_Yes.DisplayCode when 2 then LU_No.DisplayCode end) AS ContainsMicrofilm, 
(case dbo.CM_CPI_Volume.CLMicroFilm when 1 then LU_Yes.UserDescription when 2 then LU_No.UserDescription end) AS ContainsMicrofilmDesc, 

LU_YesNoSystem_5.DisplayCode AS ContainsOptional1Data, LU_YesNoSystem_5.UserDescription AS ContainsOptional1DataDesc, 
LU_YesNoSystem_6.DisplayCode AS ContainsOptional2Data, LU_YesNoSystem_6.UserDescription AS ContainsOptional2DataDesc, 
LU_YesNoSystem_8.DisplayCode AS ContainsOptional3Data, LU_YesNoSystem_9.UserDescription AS ContainsOptional4DataDesc, 
LU_YesNoSystem_9.DisplayCode AS ContainsOptional4Data, LU_YesNoSystem_8.UserDescription AS ContainsOptional3DataDesc, 
--LU_YesNoSystem_3.DisplayCode AS ContainsOutpatientData, LU_YesNoSystem_3.UserDescription AS ContainsOutpatientDataDesc, 
(case dbo.CM_CPI_Volume.CLOutpatient when 1 then LU_Yes.DisplayCode when 2 then LU_No.DisplayCode end) AS ContainsOutpatientData, 
(case dbo.CM_CPI_Volume.CLOutpatient when 1 then LU_Yes.UserDescription when 2 then LU_No.UserDescription end) AS ContainsOutpatientDataDesc, 
--LU_YesNoSystem_2.DisplayCode AS ContainsSDSData, LU_YesNoSystem_2.UserDescription AS ContainsSDSDataDesc, 
(case dbo.CM_CPI_Volume.CLSDS when 1 then LU_Yes.DisplayCode when 2 then LU_No.DisplayCode end) AS ContainsSDSData, 
(case dbo.CM_CPI_Volume.CLSDS when 1 then LU_Yes.UserDescription when 2 then LU_No.UserDescription end) AS ContainsSDSDataDesc, 


LU_CurrLocation.DisplayCode AS CurrentLocation, LU_CurrLocation.UserDescription AS CurrentLocationDesc, 
LU_CurrLocationType.DisplayCode AS CurrentLocationType, LU_CurrLocationType.UserDescription AS CurrentLocationTypeDesc, 
--LU_CurrHealthDepartment.DisplayCode as CurrentLocInRecordDepartment, LU_CurrHealthDepartment.UserDescription as CurrentLocInRecordDeparDesc,
(case LU_CurrLocation.InHospital when 1 then LU_Yes.DisplayCode when 2 then LU_No.DisplayCode end) AS CurrentLocInRecordDepartment, 
(case LU_CurrLocation.InHospital when 1 then LU_Yes.UserDescription when 2 then LU_No.UserDescription end) AS CurrentLocInRecordDeparDesc, 

LoanLU_LocationType_1.DisplayCode AS CurrentTransactionType, LoanLU_LocationType_1.UserDescription AS CurrentTransactionTypeDesc, 

dbo.CM_CPI_Volume.DestructionDate,  --''2.x-1854
--TS-222
LU_DigitalIndicator.DisplayCode AS DigitallyAvailable, LU_DigitalIndicator.UserDescription AS DigitallyAvailableDesc, 


dbo.H_HospitalProfile.DisplayCode AS Hospital, dbo.H_HospitalProfile.UserDescription AS HospitalName, 
--LU_PrintLabel.DisplayCode AS LabelPrinted, LU_PrintLabel.UserDescription AS LabelPrintedDesc, 
(case dbo.CM_CPI_Volume.LabelPrinted when 1 then LU_Yes.DisplayCode when 2 then LU_No.DisplayCode end) AS LabelPrinted, 
(case dbo.CM_CPI_Volume.LabelPrinted when 1 then LU_Yes.UserDescription when 2 then LU_No.UserDescription end) AS LabelPrintedDesc, 

LU_LinkToVolume.VolumeNumber AS LinkedToVolume, 
dbo.CM_CPI_Volume.CLMircoFilmNum AS MicroFilmNumber, 

LU_PermLocation.DisplayCode AS PermLocation, LU_PermLocation.UserDescription AS PermLocationDesc, 
LU_PermLocationType.DisplayCode AS PermLocationType, LU_PermLocationType.UserDescription AS PermLocationTypeDesc, 
--LU_PermHealthDepartment.DisplayCode AS PermLocInRecordDepartment, LU_PermHealthDepartment.UserDescription AS PermLocInRecordDepartmentDesc, 
(case LU_PermLocation.InHospital when 1 then LU_Yes.DisplayCode when 2 then LU_No.DisplayCode end) AS PermLocInRecordDepartment, 
(case LU_PermLocation.InHospital when 1 then LU_Yes.UserDescription when 2 then LU_No.UserDescription end) AS PermLocInRecordDepartmentDesc, 


LU_PreviousLocation.DisplayCode AS PreviousLocation, LU_PreviousLocation.UserDescription AS PreviousLocationDesc, 
LU_PrevLocationType.DisplayCode AS PrevLocationType, LU_PrevLocationType.UserDescription AS PrevLocationTypeDesc, 

--LU_PrevHealthDepartment.DisplayCode AS PrevLocInRecordDepartment, LU_PrevHealthDepartment.UserDescription AS PrevLocInRecordDepartmentDesc,
(case LU_PreviousLocation.InHospital when 1 then LU_Yes.DisplayCode when 2 then LU_No.DisplayCode end) AS PrevLocInRecordDepartment, 
(case LU_PreviousLocation.InHospital when 1 then LU_Yes.UserDescription when 2 then LU_No.UserDescription end) AS PrevLocInRecordDepartmentDesc, 

--LU_YesNoSystem_10.DisplayCode AS SubVolume, LU_YesNoSystem_10.UserDescription AS SubVolumeDesc, 
(case dbo.CM_CPI_Volume.SubVolume when 1 then LU_Yes.DisplayCode when 2 then LU_No.DisplayCode end) AS SubVolume, 
(case dbo.CM_CPI_Volume.SubVolume when 1 then LU_Yes.UserDescription when 2 then LU_No.UserDescription end) AS SubVolumeDesc, 

dbo.CM_CPI_Volume.VolumeDateFrom, 
dbo.CM_CPI_Volume.VolumenDateTo AS VolumeDateTo, dbo.CM_CPI_Volume.VolumeNumber, LU_VolumeType.DisplayCode AS VolumeType, 
LU_VolumeType.UserDescription AS VolumeTypeDesc, dbo.CM_CPI_Volume.BarCodeVolume AS UniqueBarCodeVolume, 
dbo.CM_CPI_Volume.CLActivityID AS zzCLLink, dbo.CM_CPI_Volume.PatientID AS zzPatientLink, dbo.CM_CPI_Volume.VolumeID AS zzVolumeLink, 
dbo.CM_CPI_Volume.UniversalID AS zzLatestVH_UniversalLink
FROM         
dbo.CM_CPI_Volume with (nolock) LEFT OUTER JOIN
dbo.LoanLU_Type LoanLU_LocationType_1 with (nolock) ON LoanLU_LocationType_1.Code = dbo.CM_CPI_Volume.ActivityType LEFT OUTER JOIN
dbo.LoanLU_VolumeType LU_VolumeType with (nolock) ON dbo.CM_CPI_Volume.VolumeType = LU_VolumeType.Code LEFT OUTER JOIN
dbo.CM_CPI_Volume LU_LinkToVolume with (nolock) ON dbo.CM_CPI_Volume.CLLinkedVolume = LU_LinkToVolume.VolumeID LEFT OUTER JOIN
dbo.H_HospitalProfile with (nolock) ON dbo.CM_CPI_Volume.HospitalID = dbo.H_HospitalProfile.Code LEFT OUTER JOIN
--dbo.LU_YesNoSystem LU_PrintLabel with (nolock) ON dbo.CM_CPI_Volume.LabelPrinted = LU_PrintLabel.Code LEFT OUTER JOIN
--dbo.LU_YesNoSystem LU_YesNoSystem_10 with (nolock) ON dbo.CM_CPI_Volume.SubVolume = LU_YesNoSystem_10.Code LEFT OUTER JOIN

dbo.LU_CodeFile LU_YesNoSystem_9 with (nolock) ON dbo.CM_CPI_Volume.CLOption4 = LU_YesNoSystem_9.Code LEFT OUTER JOIN
dbo.LU_CodeFile LU_YesNoSystem_8 with (nolock) ON dbo.CM_CPI_Volume.CLOption3 = LU_YesNoSystem_8.Code LEFT OUTER JOIN
dbo.LU_CodeFile LU_YesNoSystem_6 with (nolock) ON dbo.CM_CPI_Volume.CLOption2 = LU_YesNoSystem_6.Code LEFT OUTER JOIN
dbo.LU_CodeFile LU_YesNoSystem_5 with (nolock) ON dbo.CM_CPI_Volume.CLOption1 = LU_YesNoSystem_5.Code LEFT OUTER JOIN
--dbo.LU_YesNoSystem LU_YesNoSystem_4 with (nolock) ON dbo.CM_CPI_Volume.CLAmcare = LU_YesNoSystem_4.Code LEFT OUTER JOIN
--dbo.LU_YesNoSystem LU_YesNoSystem_3 with (nolock) ON dbo.CM_CPI_Volume.CLOutpatient = LU_YesNoSystem_3.Code LEFT OUTER JOIN
--dbo.LU_YesNoSystem LU_YesNoSystem_2 with (nolock) ON dbo.CM_CPI_Volume.CLSDS = LU_YesNoSystem_2.Code LEFT OUTER JOIN
--dbo.LU_YesNoSystem LU_YesNoSystem_1 with (nolock) ON LU_YesNoSystem_1.Code = dbo.CM_CPI_Volume.CLInpatient LEFT OUTER JOIN
--dbo.LU_YesNoSystem LU_YesNoSystem_11 with (nolock) ON LU_YesNoSystem_11.Code = dbo.CM_CPI_Volume.CLMicroFilm LEFT OUTER JOIN

dbo.LoanLU_Location LU_PermLocation with (nolock) ON dbo.CM_CPI_Volume.PermLocation = LU_PermLocation.Code LEFT OUTER JOIN
dbo.LoanLU_LocationType LU_PermLocationType  with (nolock) ON LU_PermLocationType.Code = LU_PermLocation.LocationType LEFT OUTER JOIN
--dbo.LU_YesNoSystem LU_PermHealthDepartment with (nolock) ON LU_PermLocation.InHospital = LU_PermHealthDepartment.Code LEFT OUTER JOIN

dbo.LoanLU_Location LU_CurrLocation with (nolock) ON dbo.CM_CPI_Volume.CLCurrentLocation = LU_CurrLocation.Code LEFT OUTER JOIN
dbo.LoanLU_LocationType LU_CurrLocationType with (nolock) ON LU_CurrLocationType.Code = LU_CurrLocation.LocationType LEFT OUTER JOIN
--dbo.LU_YesNoSystem LU_CurrHealthDepartment with (nolock) ON LU_CurrLocation.InHospital = LU_CurrHealthDepartment.Code LEFT OUTER JOIN

dbo.LoanLU_Location LU_PreviousLocation with (nolock) ON dbo.CM_CPI_Volume.CLPreviousLocation = LU_PreviousLocation.Code LEFT OUTER JOIN
dbo.LoanLU_LocationType LU_PrevLocationType with (nolock) ON LU_PrevLocationType.Code = LU_PreviousLocation.LocationType LEFT OUTER JOIN
-- dbo.LU_YesNoSystem LU_PrevHealthDepartment with (nolock) ON LU_PreviousLocation.InHospital = LU_PrevHealthDepartment.Code 
--TS-222
dbo.LoanLU_DigitalIndicator LU_DigitalIndicator with (nolock) ON dbo.CM_CPI_Volume.DigitalIndicator = LU_DigitalIndicator.Code --LEFT OUTER JOIN

cross join (select DisplayCode, UserDescription from LU_YesNoSystem where code = 1) LU_Yes
Cross join (select DisplayCode, UserDescription from LU_YesNoSystem where code = 2) LU_No
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Chart_Deficiency_Current_Transfer_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[Chart_Deficiency_Current_Transfer_VR]
AS
SELECT     T.DefNewStartDate AS DeficiencyNewStartDate, T.DefStartDate AS DeficiencyOldStartDate, T.DefeciencyID AS HeaderReferenceIDNumber, 
                      T.NewDetailID AS NewDeficiencyDetailID, F.DisplayCode AS TransferFirstCoder, F.UserDescription AS TransferFirstCoderName, 
                      T.DefTransferDate AS TransferFirstDate, C.DisplayCode AS TransferLatestCoder, C.UserDescription AS TransferLatestCoderName, 
                      T.DefTransferStatusDate AS TransferLatestDate, DF.DisplayCode AS TransferProviderFrom, DF.UserDescription AS TransferProviderFromName, 
                      DT.DisplayCode AS TransferProviderTo, DT.UserDescription AS TransferProviderToName, S.DisplayCode AS TransferStatus, 
                      S.UserDescription AS TransferStatusDesc, T.DefID AS zzDefLink
FROM         dbo.Def_Transfer T with (nolock) INNER JOIN
                      dbo.DefLU_TransferStatus S with (nolock) ON T.DefTransferStatus = S.Code LEFT OUTER JOIN
                      dbo.U_Users C with (nolock) ON T.DefTransferStatusCoder = C.Code LEFT OUTER JOIN
                      dbo.U_Users F with (nolock) ON T.DefTransferCoder = F.Code INNER JOIN
                      dbo.LU_Provider DF with (nolock) ON T.DefDrNumberFrom = DF.Code INNER JOIN
                      dbo.LU_Provider DT ON T.DefDrNumberTo = DT.Code INNER JOIN
                          (SELECT     MAX(DefTransferID) MaxID, DefeciencyID
                            FROM          Def_Transfer MT with (nolock) INNER JOIN
                                                   DefLU_TransferStatus MS with (nolock) On MT.DefTransferStatus = MS.Code
                            WHERE      MS.DisplayCode NOT IN (''U'', ''T'')
                            GROUP BY DefeciencyID) M ON M.MaxID = T.DefTransferID

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Chart_Deficiency_Transfer_History_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE     VIEW [dbo].[Chart_Deficiency_Transfer_History_VR]
AS
SELECT     
    T.DefNewStartDate AS DeficiencyNewStartDate, T.DefeciencyID AS DetailReferenceIDFrom, 
    T.NewDetailID AS DetailReferenceIDTo, 
    cast(T.DefeciencyID / 100 as varchar(10)) + ''00'' AS HeaderReferenceIDFrom, 
    cast(T.NewDetailID / 100 as varchar(10)) + ''00'' AS HeaderReferenceIDTo, 
    TC.DisplayCode AS TransferCoder, 
    TC.UserDescription AS TransferCoderName, TS.DisplayCode AS TransferCurrentStatus, TS.UserDescription AS TransferCurrentStatusDesc, 
    H.DefTransferStatusDate AS TransferDate, LS.DisplayCode AS TransferLastStatus, LS.UserDescription AS TransferLastStatusDesc, 
    DF.DisplayCode AS TransferProviderFrom, DF.UserDescription AS TransferProviderFromName, DT.DisplayCode AS TransferProviderTo, 
    DT.UserDescription AS TransferProviderToName, dbo.Def_SlipMain.DefAbstractID AS zzUniversalLink, 
    Def_SlipMain.DefID as zzDefLink
FROM 
    dbo.Def_SlipMain with (nolock) INNER JOIN
    dbo.Def_Transfer AS T with (nolock) ON dbo.Def_SlipMain.DefID = T.DefID INNER JOIN --dbo.Def_SlipMain.DefeciencyID = LEFT(T.NewDetailID, 6) + ''00''
    dbo.LU_Provider AS DF with (nolock) ON DF.Code = T.DefDrNumberFrom INNER JOIN
    dbo.LU_Provider AS DT with (nolock) ON T.DefDrNumberTo = DT.Code INNER JOIN
    dbo.Def_Transfer_History AS H with (nolock) ON H.DefTransferID = T.DefTransferID LEFT OUTER JOIN
    dbo.DefLU_TransferStatus AS TS with (nolock) ON TS.Code = H.DefTransferCurrStatus left OUTER JOIN
    dbo.U_Users AS TC with (nolock) ON H.DefTransferStatusCoder = TC.Code LEFT OUTER JOIN
    dbo.DefLU_TransferStatus AS LS with (nolock) ON H.DefTransferLastStatus = LS.Code 
    --inner join dbo.CheckLogin() login 
    --    ON login.HospitalID in (0, isnull(dbo.Def_SlipMain.HospitalID, login.HospitalID))  
    --        or isnull(dbo.Def_SlipMain.HospitalID, 0) in (0, login.HospitalID)


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Chart_Deficiency_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[Chart_Deficiency_UpdateHistory_VR]
AS
SELECT     
	dbo.Def_UpdateHistory.DefeciencyID AS HeaderReferenceIDNumber, 
	dbo.U_Users.DisplayCode AS UpdateCoder, dbo.U_Users.UserDescription AS UpdateCoderDesc, 
	U_Users_1.DisplayCode AS UpdateCoderHospital, U_Users_1.UserDescription AS UpdateCoderHospitalDesc, 
	dbo.Def_UpdateHistory.Updated AS UpdateDate, 
	dbo.Def_UpdateHistory.UpdateType, 
    dbo.Def_UpdateHistory.DefID AS zzDefLink
FROM         dbo.Def_UpdateHistory with (nolock) LEFT OUTER JOIN
                      dbo.H_HospitalProfile U_Users_1 with (nolock) On dbo.Def_UpdateHistory.HospitalID = U_Users_1.Code LEFT OUTER JOIN
                      dbo.U_Users with (nolock) On dbo.Def_UpdateHistory.Coder = dbo.U_Users.Code
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Chart_Deficiency_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE    VIEW [dbo].[Chart_Deficiency_VR]
AS
SELECT 
    dbo.AB_Main.AdmitDate, dbo.AB_Main.AdmitTime, dbo.Def_SlipMain.DefBirthDate AS BirthDate, LU_CareType.DisplayCode AS CareType, 
    LU_CareType.UserDescription AS CareTypeDesc, dbo.Central_Patient_Index_VR.ChartNumber, Lookup1.DisplayCode AS ColourCode, 
    Lookup1.UserDescription AS ColourCodeDesc, Lookup2.DisplayCode AS CompletedBy, Lookup2.UserDescription AS CompletedByDesc, 
    Lookup3.DisplayCode AS DeficiencyCode, Lookup3.UserDescription AS DeficiencyCodeDesc, Lookup4.DisplayCode AS DeficiencyCodeType, 
    Lookup4.UserDescription AS DeficiencyCodeTypeDesc, dbo.Def_SlipMain.DefDays AS DeficiencyDays, 
    dbo.Def_Activity.DefDays AS DeficiencyDetailDays, dbo.Def_Activity.DefEndDate AS DeficiencyDetailEndDate, 
    dbo.Def_Activity.DefStartDate AS DeficiencyDetailStartDate, dbo.Def_SlipMain.DefEndDate AS DeficiencyEndDate, 
    dbo.Def_Activity.DefOccurrence AS DeficiencyOccurrence, dbo.Def_SlipMain.DefStartDate AS DeficiencyStartDate, 
    dbo.Def_SlipMain.DefTotalDays as DeficiencyTotalDays,
    dbo.Def_Activity.DefNote AS DetailComments, dbo.Def_Activity.JobNumber AS DetailJobNumber, 
    dbo.Def_Activity.DefeciencyID AS DetailReferenceIDNumber, Lookup5.DisplayCode AS DetailStatus, Lookup5.UserDescription AS DetailStatusDesc, 
    dbo.AB_Main.DischargeDate, dbo.AB_Main.DischargeTime, dbo.AB_Main.EncounterNumber, dbo.AB_Main.EncounterSequence, 
    dbo.Def_SlipMain.DefMainNote AS HeaderNotes, dbo.Def_SlipMain.DefeciencyID AS HeaderReferenceIDNumber, 
    Lookup6.DisplayCode AS HeaderStatus, Lookup6.UserDescription AS HeaderStatusDesc, dbo.Def_SlipMain.DefHoldDays AS HoldDays, 
    dbo.Def_SlipMain.DefHoldEndDate AS HoldEndDate, dbo.Def_SlipMain.DefHoldStartDate AS HoldStartDate, 
    isnull(LU_Hospital.DisplayCode, '''') AS Hospital, 
    isnull(LU_Hospital.UserDescription, '''') AS HospitalDesc, 
    Lookup7.DisplayCode AS InstitutionNumber, Lookup7.UserDescription AS InstitutionNumberDesc, 
    dbo.Def_SlipMain.DefManualDays AS ManualDays, Lookup8.DisplayCode AS MessageBox, Lookup8.UserDescription AS MessageBoxDesc, 
    dbo.Def_SlipMain.DefPatFirstName AS PatientFirstName, dbo.Def_SlipMain.DefPatLastName AS PatientLastName, 
    Lookup9.ProvdrAddress AS ProviderAddress, Lookup9.ProvdrCity AS ProviderCity, Lookup9.ProvdrCredentials AS ProviderCredentials, 
    Lookup9.ProvdrEMail AS ProviderEmail, Lookup9.ProvdrFax AS ProviderFAX, LUProviderLanguage.DisplayCode AS ProviderLanguage, 
    Lookup9.DisplayCode AS ProviderNumber, Lookup9.UserDescription AS ProviderNumberDesc, Lookup9.ProvdrCellPhone AS ProviderPhoneCell, 
    Lookup9.ProvdrHomePhone AS ProviderPhoneHome, Lookup9.ProvdrHospitalPhone AS ProviderPhoneHospital, 
    Lookup9.ProvdrOfficePhone AS ProviderPhoneOffice, Lookup9.ProvdrPostal AS ProviderPostalCode, Lookup9.ProvdrProvince AS ProviderProvince, 
    dbo.LU_ProviderService.DisplayCode AS ProviderService, dbo.LU_ProviderService.UserDescription AS ProviderServiceDesc, 
    dbo.LU_ProviderSpecialty.DisplayCode AS ProviderSpecialty, dbo.LU_ProviderSpecialty.UserDescription AS ProviderSpecialtyDesc, 
    dbo.Def_SlipMain.DefDrStatus AS ProviderStatus, Lookup9.ProvdrTitle AS ProviderTitle, Lookup10.DisplayCode AS Resident, 
    Lookup10.UserDescription AS ResidentDesc, Lookup11.DisplayCode AS SiteNumber, Lookup11.UserDescription AS SiteNumberDesc, 
    dbo.Def_SlipMain.DefSuspensionDays AS SuspensionDays, dbo.Def_SlipMain.DefVacationDays AS VacationDays, 
    dbo.CM_CPI_Volume.VolumeNumber, dbo.Central_Patient_Index_VR.AlternateAddress, dbo.Central_Patient_Index_VR.AlternatePhoneNumber, 
    dbo.Central_Patient_Index_VR.CPINotes, dbo.Central_Patient_Index_VR.DatePatientDied, dbo.Central_Patient_Index_VR.DuplicateChart, 
    dbo.Central_Patient_Index_VR.Education, dbo.Central_Patient_Index_VR.EducationDesc, dbo.Central_Patient_Index_VR.EmployerAddress, 
    dbo.Central_Patient_Index_VR.EmployerName, dbo.Central_Patient_Index_VR.EmployerPhoneNumber, 
    dbo.Central_Patient_Index_VR.FamilyPhysicianAddress, dbo.Central_Patient_Index_VR.FamilyPhysicianName, 
    dbo.Central_Patient_Index_VR.FamilyPhysicianPhoneNumber, dbo.Central_Patient_Index_VR.FirstName, dbo.Central_Patient_Index_VR.Gender, 
    dbo.Central_Patient_Index_VR.GenderDesc, dbo.Central_Patient_Index_VR.HCNProvince, dbo.Central_Patient_Index_VR.HCNProvinceDesc, 
    dbo.Central_Patient_Index_VR.HCNVersion, dbo.Central_Patient_Index_VR.HealthCareNumber, dbo.Central_Patient_Index_VR.InEmergencyAddress, 
    dbo.Central_Patient_Index_VR.InEmergencyName, dbo.Central_Patient_Index_VR.InEmergencyPhoneNumber, 
    dbo.Central_Patient_Index_VR.InEmergencyRelationship, dbo.Central_Patient_Index_VR.InEmergencyRelationshipDesc, 
    dbo.Central_Patient_Index_VR.InsuranceCompany1, dbo.Central_Patient_Index_VR.InsuranceCompany2, 
    dbo.Central_Patient_Index_VR.InsurancePolicy1, dbo.Central_Patient_Index_VR.InsurancePolicy2, 
    dbo.Central_Patient_Index_VR.IsBirthdateEstimated, dbo.Central_Patient_Index_VR.IsBirthdateEstimatedDesc, 
    dbo.Central_Patient_Index_VR.[Language], dbo.Central_Patient_Index_VR.LanguageDesc, dbo.Central_Patient_Index_VR.LastName, 
    dbo.Central_Patient_Index_VR.LivingArrangement, dbo.Central_Patient_Index_VR.LivingArrangementDesc, 
    dbo.Central_Patient_Index_VR.MaidenName, dbo.Central_Patient_Index_VR.MaritalStatus, dbo.Central_Patient_Index_VR.MaritalStatusDesc, 
    dbo.Central_Patient_Index_VR.MiddleName, dbo.Central_Patient_Index_VR.MothersChart, dbo.Central_Patient_Index_VR.NextofKinAddress, 
    dbo.Central_Patient_Index_VR.NextofKinName, dbo.Central_Patient_Index_VR.NextofKinPhoneNumber, 
    dbo.Central_Patient_Index_VR.NextofKinRelationship, dbo.Central_Patient_Index_VR.NextofKinRelationshipDesc, 
    dbo.Central_Patient_Index_VR.Occupation, dbo.Central_Patient_Index_VR.OccupationDesc, dbo.Central_Patient_Index_VR.PlaceofBirth, 
    dbo.Central_Patient_Index_VR.PostalCode, dbo.Central_Patient_Index_VR.PrimaryAddress, dbo.Central_Patient_Index_VR.PrimaryPhoneNumber, 
    dbo.Central_Patient_Index_VR.ResidenceCode, dbo.Central_Patient_Index_VR.ResidenceCodeDesc, dbo.Central_Patient_Index_VR.ResidenceType, 
    dbo.Central_Patient_Index_VR.ResidenceTypeDesc, dbo.Central_Patient_Index_VR.SecretVIPPatient, 
    dbo.Central_Patient_Index_VR.SecretVIPPatientDesc, dbo.Central_Patient_Index_VR.SocialInsuranceNumber, 
    (Case when AB_Main.AppType in (1, 2) then DischargeDate else AdmitDate end) as VisitDate,
    dbo.Central_Patient_Index_VR.zzPatientLink, dbo.Def_SlipMain.DefAbstractID AS zzUniversalLink, dbo.AB_Main.AbstractID AS zzAbstractLink, 
    dbo.Def_SlipMain.DefVolumeID AS zzVolumeLink, dbo.Def_SlipMain.DefID AS zzDefLink
FROM dbo.Def_SlipMain with (nolock)  LEFT OUTER JOIN
    dbo.Def_Activity with (nolock) ON dbo.Def_SlipMain.DefID = dbo.Def_Activity.DefID LEFT OUTER JOIN
    dbo.LU_ProviderSpecialty with (nolock) ON dbo.Def_SlipMain.ProviderSpecialty = dbo.LU_ProviderSpecialty.Code LEFT OUTER JOIN
    dbo.LU_ProviderService with (nolock) ON dbo.Def_SlipMain.ProviderService = dbo.LU_ProviderService.Code LEFT OUTER JOIN
    
    dbo.H_HospitalProfile LU_Hospital with (nolock) ON dbo.Def_SlipMain.HospitalID = LU_Hospital.Code LEFT OUTER JOIN
    dbo.Central_Patient_Index_VR with (nolock) ON dbo.Def_SlipMain.DefPatientID = dbo.Central_Patient_Index_VR.zzPatientLink LEFT OUTER JOIN
    dbo.AB_Main with (nolock) ON dbo.Def_SlipMain.DefAbstractID = dbo.AB_Main.UniversalID LEFT OUTER JOIN
    dbo.CM_CPI_Volume with (nolock) ON dbo.Def_SlipMain.DefVolumeID = dbo.CM_CPI_Volume.VolumeID LEFT OUTER JOIN
    dbo.U_Users Lookup2 with (nolock) ON dbo.Def_Activity.DefCompletedBy = Lookup2.Code LEFT OUTER JOIN
    dbo.DefLU_DeficiencyCode Lookup3 with (nolock) ON dbo.Def_Activity.DefCode = Lookup3.Code LEFT OUTER JOIN
    dbo.DefLU_DeficiencyType Lookup4 with (nolock) ON dbo.Def_Activity.DefCodeType = Lookup4.Code LEFT OUTER JOIN
    dbo.DefLU_ChartStatus Lookup5 with (nolock) ON dbo.Def_Activity.DefStatus = Lookup5.Code LEFT OUTER JOIN
    dbo.DefLU_Messages Lookup8 with (nolock) ON dbo.Def_Activity.DefMessage = Lookup8.Code LEFT OUTER JOIN
    dbo.DefLU_Resident Lookup10 with (nolock) ON dbo.Def_Activity.DefResident = Lookup10.Code LEFT OUTER JOIN
    dbo.DefLU_DocColourCode Lookup1 with (nolock) ON dbo.Def_SlipMain.DefColour = Lookup1.Code LEFT OUTER JOIN
    dbo.DefLU_ChartStatus Lookup6 with (nolock) ON dbo.Def_SlipMain.DefMainStatus = Lookup6.Code LEFT OUTER JOIN
    dbo.H_InstitutionProfile Lookup7 with (nolock) ON dbo.Def_SlipMain.DefInstNumber = Lookup7.Code LEFT OUTER JOIN
    dbo.LU_Provider Lookup9 with (nolock) ON dbo.Def_SlipMain.DefDrNumber = Lookup9.Code LEFT OUTER JOIN
    dbo.LLU_Provider_Language LUProviderLanguage with (nolock) ON Lookup9.ProvdrLanguage = LUProviderLanguage.Code LEFT OUTER JOIN
    dbo.LU_Site Lookup11 with (nolock) ON dbo.Def_SlipMain.DefSiteNumber = Lookup11.Code LEFT OUTER JOIN
    dbo.LU_CareType LU_CareType with (nolock) ON Lookup7.AssociationID = LU_CareType.Code
--QA - 00032 disable the domain securite issue
----PR - 07485
--where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or Def_SlipMain.HospitalID is null or Def_SlipMain.HospitalID = 0
--    --EN - 00666
--    or Is_Member(nullif(ReportGroup, '''')) = 1
----    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(Def_SlipMain.HospitalID, 0))

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Chart_DeficiencyStatusbyVisit_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE view [dbo].[Chart_DeficiencyStatusbyVisit_VR]
as
select
    zzUniversalLink = DefAbstractID,
    MinimumDeficiencyStartDate = min(DefStartDate),
    MaximumDeficiencyEndDate = max(DefEndDate),
    TotalHeaderCount = count(*),
    TotalHeaderCompleted = sum((case when DefMainStatus = 8 then 1 else 0 end)),
    TotalHeaderNotCompleted = sum((case when DefMainStatus = 8 then 0 else 1 end))
from dbo.Def_SlipMain with (nolock)
where DefAbstractID > 0
group by DefAbstractID


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ChartLocator_PullList_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE  VIEW [dbo].[ChartLocator_PullList_UpdateHistory_VR]
AS
SELECT     
    dbo.CL_PullListUpdateHistory.PullListID, 
    dbo.U_Users.DisplayCode AS UpdateCoder, dbo.U_Users.UserDescription AS UpdateCoderDesc, 
    dbo.CL_PullListUpdateHistory.Updated AS UpdateDate, 
    dbo.CL_PullListUpdateHistory.UpdateType, 
    CL_PullListUpdateHistory.PullID as zzPullListLink,
    dbo.CL_PullListUpdateHistory.VolumeID AS zzVolumeLink
FROM         dbo.CL_PullListUpdateHistory with (nolock) LEFT OUTER JOIN
                      dbo.U_Users with (nolock) on dbo.CL_PullListUpdateHistory.Coder = dbo.U_Users.Code


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ChartLocator_PullList_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[ChartLocator_PullList_VR]
AS
SELECT     
    CM_CPI_Volume.BarCodeVolume,    
    dbo.CL_PullList.PullOutDate AS ActualOutDate, dbo.CL_PullList.PullOutTime AS ActualOutTime, dbo.CM_CPI.ChartNumber, 
    dbo.CL_PullList.LoanNote AS ChartNote, LoanLU_Location_2.UserDescription AS CurrentLocation, 
    LoanLU_Location_2.DisplayCode AS CurrentLocationCode, dbo.CM_CPI.FirstName, 
    dbo.H_HospitalProfile.DisplayCode as Hospital, dbo.H_HospitalProfile.UserDescription as HospitalDesc,
    LU_YesNoSystem.DisplayCode as IsReturned, LU_YesNoSystem.UserDescription as IsReturnedDesc, 
    dbo.CM_CPI.LastName, LoanDate, LoanTime, 
    LoanLU_Location_3.UserDescription AS PullLocation, LoanLU_Location_3.DisplayCode AS PullLocationCode, 
    LU_LocationType.UserDescription AS PullLocationType, LU_LocationType.DisplayCode AS PullLocationTypeCode, 
    LoanLU_Location_1.UserDescription AS PermLocation, LoanLU_Location_1.DisplayCode AS PermLocationCode, 
    dbo.LoanLU_Borrower.UserDescription AS Puller, dbo.LoanLU_Borrower.DisplayCode AS PullerCode, dbo.CL_PullList.PullDate, 
    dbo.CL_PullList.PullListID, dbo.CL_PullList.PullNotes, 
    PullListStatus = (CASE WHEN isnull(dbo.CL_PullList.PullListStatus, 0) = 0 THEN '''' ELSE ''Loaned'' END), 
    dbo.CL_PullList.PullTime, PurgeDate = NULL, PurgeTime = NULL, 
    dbo.LoanLU_RequestPriority.UserDescription AS PullRequestPriority, dbo.LoanLU_RequestPriority.DisplayCode AS PullRequestPriorityCode, 
    dbo.CL_PullList.LoanReason as ReasonForLoan,
    dbo.CM_CPI_Volume.VolumeNumber, 
    LoanLU_VolumeType.DisplayCode as VolumeType, LoanLU_VolumeType.UserDescription as VolumeTypeDesc,
    dbo.CL_PullList.PullID as zzPullListLink,
    dbo.CM_CPI_Volume.PatientID as zzPatientLink,
    dbo.CL_PullList.VolumeID AS zzVolumeLink
FROM dbo.CM_CPI with (nolock) RIGHT OUTER JOIN
    dbo.CM_CPI_Volume with (nolock) on dbo.CM_CPI.PatientID = dbo.CM_CPI_Volume.PatientID LEFT OUTER JOIN
    dbo.LoanLU_Location LoanLU_Location_2 with (nolock) on dbo.CM_CPI_Volume.CLCurrentLocation = LoanLU_Location_2.Code LEFT OUTER JOIN
    dbo.LoanLU_Location LoanLU_Location_1 with (nolock) on dbo.CM_CPI_Volume.PermLocation = LoanLU_Location_1.Code RIGHT OUTER JOIN
    dbo.CL_PullList with (nolock) on dbo.CM_CPI_Volume.VolumeID = dbo.CL_PullList.VolumeID LEFT OUTER JOIN
    dbo.LoanLU_Location LoanLU_Location_3 with (nolock) on dbo.CL_PullList.PullLocation = LoanLU_Location_3.Code LEFT OUTER JOIN
    dbo.LoanLU_LocationType LU_LocationType with (nolock) on LoanLU_Location_3.LocationType = LU_LocationType.Code LEFT OUTER JOIN
    dbo.LoanLU_Borrower with (nolock) on dbo.CL_PullList.Puller = dbo.LoanLU_Borrower.Code LEFT OUTER JOIN
    dbo.LoanLU_RequestPriority with (nolock) on dbo.CL_PullList.CLRequestPriority = dbo.LoanLU_RequestPriority.Code LEFT OUTER JOIN
    dbo.LoanLU_VolumeType with (nolock) on CM_CPI_Volume.VolumeType = LoanLU_VolumeType.Code LEFT OUTER JOIN 
    dbo.LU_YesNoSystem with (nolock) on CL_PullList.IsReturned = LU_YesNoSystem.Code LEFT JOIN
    dbo.H_HospitalProfile with (nolock) on dbo.CL_PullList.HospitalID = dbo.H_HospitalProfile.Code
--where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or CL_PullList.HospitalID is null or CL_PullList.HospitalID = 0
--    --EN - 00666
--    or Is_Member(nullif(ReportGroup, '''')) = 1
----    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(CL_PullList.HospitalID, 0))
----PR - 04528
----    inner join dbo.CheckLogin() login 
----        with (nolock) on login.HospitalID in (0, isnull(dbo.CL_PullList.HospitalID, login.HospitalID))  
----            or isnull(dbo.CL_PullList.HospitalID, 0) in (0, login.HospitalID)
UNION ALL
SELECT 
    CM_CPI_Volume.BarCodeVolume,    
    dbo.CL_PullList_Purged.PullOutDate AS ActualPullDate, dbo.CL_PullList_Purged.PullOutTime AS ActualPullTime, dbo.CM_CPI.ChartNumber, 
    dbo.CL_PullList_Purged.LoanNote AS ChartNote, LoanLU_Location_2.UserDescription AS CurrentLocation, 
    LoanLU_Location_2.DisplayCode AS CurrentLocationCode, dbo.CM_CPI.FirstName, 
    dbo.H_HospitalProfile.DisplayCode as Hospital, dbo.H_HospitalProfile.UserDescription as HospitalDesc,
    LU_YesNoSystem.DisplayCode as IsReturned, LU_YesNoSystem.UserDescription as IsReturnedDesc, 
    dbo.CM_CPI.LastName, LoanDate = NULL, LoanTime = NULL, 
    LoanLU_Location_3.UserDescription AS PullLocation, LoanLU_Location_3.DisplayCode AS PullLocationCode, 
    LU_LocationType.UserDescription AS PullLocationType, LU_LocationType.DisplayCode AS PullLocationTypeCode, 
    LoanLU_Location_1.UserDescription AS PermLocation, LoanLU_Location_1.DisplayCode AS PermLocationCode, 
    dbo.LoanLU_Borrower.UserDescription AS Puller, dbo.LoanLU_Borrower.DisplayCode AS PullerCode, dbo.CL_PullList_Purged.PullDate, 
    dbo.CL_PullList_Purged.PullListID, dbo.CL_PullList_Purged.PullNotes, PullListStatus = ''Deleted'', dbo.CL_PullList_Purged.PullTime, 
    PurgeDate = LoanDate, PurgeTime = LoanTime, dbo.LoanLU_RequestPriority.UserDescription AS PullRequestPriority, 
    dbo.LoanLU_RequestPriority.DisplayCode AS PullRequestPriorityCode, 
    dbo.CL_PullList_Purged.LoanReason as ReasonForLoan,
    dbo.CM_CPI_Volume.VolumeNumber, 
    LoanLU_VolumeType.DisplayCode as VolumeType, LoanLU_VolumeType.UserDescription as VolumeTypeDesc,
    dbo.CL_PullList_Purged.PullID as zzPullListLink,
    dbo.CM_CPI_Volume.PatientID as zzPatientLink,
    dbo.CL_PullList_Purged.VolumeID AS zzVolumeLink
FROM dbo.CM_CPI with (nolock) RIGHT OUTER JOIN
    dbo.CM_CPI_Volume with (nolock) on dbo.CM_CPI.PatientID = dbo.CM_CPI_Volume.PatientID LEFT OUTER JOIN
    dbo.LoanLU_Location LoanLU_Location_2 with (nolock) on dbo.CM_CPI_Volume.CLCurrentLocation = LoanLU_Location_2.Code LEFT OUTER JOIN
    dbo.LoanLU_Location LoanLU_Location_1 with (nolock) on dbo.CM_CPI_Volume.PermLocation = LoanLU_Location_1.Code RIGHT OUTER JOIN
    dbo.CL_PullList_Purged with (nolock) on dbo.CM_CPI_Volume.VolumeID = dbo.CL_PullList_Purged.VolumeID LEFT OUTER JOIN
    dbo.LoanLU_Location LoanLU_Location_3 with (nolock) on dbo.CL_PullList_Purged.PullLocation = LoanLU_Location_3.Code LEFT OUTER JOIN
    dbo.LoanLU_LocationType LU_LocationType with (nolock) on LoanLU_Location_3.LocationType = LU_LocationType.Code LEFT OUTER JOIN
    dbo.LoanLU_Borrower with (nolock) on dbo.CL_PullList_Purged.Puller = dbo.LoanLU_Borrower.Code LEFT JOIN
    dbo.LoanLU_RequestPriority with (nolock) on dbo.CL_PullList_Purged.CLRequestPriority = dbo.LoanLU_RequestPriority.Code LEFT OUTER JOIN
    dbo.LoanLU_VolumeType with (nolock) on CM_CPI_Volume.VolumeType = LoanLU_VolumeType.Code LEFT OUTER JOIN 
    dbo.LU_YesNoSystem with (nolock) on CL_PullList_Purged.IsReturned = LU_YesNoSystem.Code LEFT JOIN
    dbo.H_HospitalProfile with (nolock) on dbo.CL_PullList_Purged.HospitalID = dbo.H_HospitalProfile.Code
----PR - 07485
--where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or CL_PullList_Purged.HospitalID is null or CL_PullList_Purged.HospitalID = 0
--    --EN - 00666
--    or Is_Member(nullif(ReportGroup, '''')) = 1
----    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(CL_PullList_Purged.HospitalID, 0))

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ChartLocator_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[ChartLocator_UpdateHistory_VR]
AS
SELECT     dbo.U_Users.DisplayCode AS UpdateCoder, dbo.U_Users.UserDescription AS UpdateCoderDesc, 
                      dbo.CL_ActivityUpdateHistory.Updated AS UpdateDate, dbo.CL_ActivityUpdateHistory.UpdateType, 
                      dbo.CL_ActivityUpdateHistory.CLActivityID AS zzCLLink
FROM         dbo.CL_ActivityUpdateHistory with (nolock) LEFT OUTER JOIN
                      dbo.U_Users with (nolock) on dbo.CL_ActivityUpdateHistory.Coder = dbo.U_Users.Code




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ChartLocator_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE  VIEW [dbo].[ChartLocator_VR]
AS
SELECT
LU_ActivityLocation.UserDescription AS ActivityLocation, LU_ActivityLocation.DisplayCode AS ActivityLocationCode, 
LU_ActLocationType.DisplayCode AS ActivityLocationType, LU_ActLocationType.UserDescription AS ActivityLocationTypeDesc, 
LU_ActiveInHealthDepartment.DisplayCode AS ActivityLocInRecordDepartment, LU_ActiveInHealthDepartment.UserDescription AS ActivityLocInRecordDepartDesc, 

dbo.CL_Activity.ActivityNotes, dbo.LoanLU_Type.UserDescription AS ActivityType, dbo.LoanLU_Type.DisplayCode AS ActivityTypeCode, 
dbo.CL_Activity.CLPullOutDate AS ActualPullDate, dbo.CL_Activity.CLPullOutTime AS ActualPullTime, dbo.CM_CPI_Volume.BarCodeVolume, 
dbo.LoanLU_Borrower.UserDescription AS Borrower, dbo.LoanLU_Borrower.DisplayCode AS BorrowerCode, dbo.LoanLU_Borrower.BorrowerAddress, 
dbo.LoanLU_Borrower.BorrowerCity, dbo.LoanLU_Borrower.BorrowerContact, dbo.LoanLU_Borrower.BorrowerPhone, 
dbo.LoanLU_Borrower.BorrowerPostal, dbo.LoanLU_Borrower.BorrowerProvince, dbo.CM_CPI_Volume.CLBoxNumber AS BoxNumber, 
dbo.CM_CPI.ChartNumber, U_Users_1.UserDescription AS CoderIn, U_Users_1.DisplayCode AS CoderInCode, 
dbo.U_Users.UserDescription AS CoderOut, dbo.U_Users.DisplayCode AS CoderOutCode, dbo.CL_Activity.ActivityDateIn AS DateIn, 
dbo.CL_Activity.ActivityDateOut AS DateOut, dbo.CL_Activity.ActivityExpectedReturn AS ExpectedReturnDate, dbo.CM_CPI.DeathDate AS ExpiredDate, 
LU_Hospital.DisplayCode AS Hospital, LU_Hospital.UserDescription AS HospitalDesc, LUNewLocation.DisplayCode AS NewPermanentLocation, 
LUNewLocation.UserDescription AS NewPermanentLocationDesc, dbo.CM_CPI.FirstName AS PatientFirstName, 
dbo.CM_CPI.LastName AS PatientLastName, 

LU_PreviousLocation.UserDescription AS PreviousLocation, LU_PreviousLocation.DisplayCode AS PreviousLocationCode, 
LU_PrevLocationType.DisplayCode AS PreviousLocationType, LU_PrevLocationType.UserDescription AS PreviousLocationTypeDesc, 
LU_PreviousInHealthDepartment.DisplayCode AS PreviousLocInRecordDepartment, LU_PreviousInHealthDepartment.UserDescription AS PreviousLocInRecordDepartDesc, 

dbo.LoanLU_RequestPriority.UserDescription AS RequestPriority, 
dbo.LoanLU_RequestPriority.DisplayCode AS RequestPriorityCode, dbo.CL_Activity.CLPullDate AS RequiredDate, 
dbo.CL_Activity.CLPullTime AS RequiredTime, dbo.CL_Activity.LoanReason AS ReasonOfLoan, dbo.CL_Activity.ActivityTimeIn AS TimeIn, 
dbo.CL_Activity.ActivityTimeOut AS TimeOut, dbo.CM_CPI_Volume.VolumeNumber, dbo.LoanLU_VolumeType.DisplayCode AS VolumeType, 
dbo.LoanLU_VolumeType.UserDescription AS VolumeTypeDesc, dbo.CL_Activity.CLActivityID AS zzCLLink, 
dbo.CL_Activity.VolumeID AS zzVolumeLink
FROM
dbo.CL_Activity with (nolock) LEFT OUTER JOIN
dbo.LoanLU_Location LUNewLocation with (nolock) on dbo.CL_Activity.CLNewPermLocation = LUNewLocation.Code LEFT OUTER JOIN
dbo.LoanLU_RequestPriority with (nolock) on dbo.CL_Activity.CLRequestPriority = dbo.LoanLU_RequestPriority.Code LEFT OUTER JOIN
dbo.H_HospitalProfile LU_Hospital with (nolock) on dbo.CL_Activity.HospitalID = LU_Hospital.Code LEFT OUTER JOIN

dbo.CM_CPI_Volume with (nolock) on dbo.CM_CPI_Volume.VolumeID = dbo.CL_Activity.VolumeID LEFT OUTER JOIN
dbo.U_Users U_Users_1 with (nolock) on U_Users_1.Code = dbo.CL_Activity.ActivityCoderIn LEFT OUTER JOIN
dbo.U_Users with (nolock) on dbo.CL_Activity.ActivityCoderOut = dbo.U_Users.Code LEFT OUTER JOIN

dbo.LoanLU_Location LU_PreviousLocation with (nolock) on LU_PreviousLocation.Code = dbo.CL_Activity.ActivityPrevLocation LEFT OUTER JOIN
dbo.LoanLU_LocationType LU_PrevLocationType with (nolock) on LU_PrevLocationType.Code = LU_PreviousLocation.LocationType LEFT OUTER JOIN

dbo.LoanLU_Type with (nolock) on dbo.LoanLU_Type.Code = dbo.CL_Activity.ActivityType LEFT OUTER JOIN
dbo.LoanLU_Location LU_ActivityLocation with (nolock) on dbo.CL_Activity.ActivityLocation = LU_ActivityLocation.Code LEFT OUTER JOIN
dbo.LoanLU_LocationType LU_ActLocationType with (nolock) on LU_ActLocationType.Code = LU_ActivityLocation.LocationType  LEFT OUTER JOIN
dbo.LoanLU_Borrower with (nolock) on dbo.CL_Activity.ActivityBorrower = dbo.LoanLU_Borrower.Code LEFT OUTER JOIN
dbo.CM_CPI with (nolock) on dbo.CM_CPI_Volume.PatientID = dbo.CM_CPI.PatientID LEFT OUTER JOIN
dbo.LoanLU_VolumeType with (nolock) on dbo.CM_CPI_Volume.VolumeType = dbo.LoanLU_VolumeType.Code LEFT OUTER JOIN

dbo.LU_YesNoSystem LU_ActiveInHealthDepartment with (nolock) on LU_ActivityLocation.InHospital = LU_ActiveInHealthDepartment.Code LEFT OUTER JOIN
dbo.LU_YesNoSystem LU_PreviousInHealthDepartment with (nolock) on LU_PreviousLocation.InHospital = LU_PreviousInHealthDepartment.Code
--QA - 00032 disable the domain securite issue
----PR - 07485
--where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or CL_Activity.HospitalID is null or CL_Activity.HospitalID = 0
--    --EN - 00666
--    or Is_Member(nullif(ReportGroup, '''')) = 1
----    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(CL_Activity.HospitalID, 0))

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ChartLocatorCurrentAct_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE view [dbo].[ChartLocatorCurrentAct_VR]
as
select VolumeID as zzVolumeLink, CLActivityID as zzCLLink
from dbo.CM_CPI_Volume with (nolock)

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ChartNumberMasked_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[ChartNumberMasked_VR]
AS
SELECT     dbo.CM_CPI.ChartNumber AS ChartNumber, dbo.CM_Terminal.MaskChart, dbo.CM_Terminal.TerminalChart,
    zzPatientLink = dbo.CM_CPI.PatientID
FROM         dbo.CM_Terminal with (nolock) INNER JOIN
                      dbo.CM_CPI with (nolock) on dbo.CM_Terminal.PatientID = dbo.CM_CPI.PatientID
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ChartVisitHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE View [dbo].[ChartVisitHistory_VR]
as
select 
    AB.AdmitDate, AB.AdmitTime, 
    AdmitAgeCode = LA.DisplayCode, AdmitAgeCodeDesc = LA.UserDescription, 
    AdmitAgeNumber = AB.AgeNumber, 
    AdmitCategory = LAC.DisplayCode, AdmitCategoryDesc = LAC.UserDescription, 
    AssessmentType = null, AssessmentTypeDesc = null, 
    CM.BirthDate, 
    CM.ChartNumber, 
    CareType = CT.DisplayCode, CareTypeDesc = CT.UserDescription, 
    DiagnosisCode = (case ICDType 
                            when ''9'' then D9.DisplayCode 
                            when ''C'' then DC.DisplayCode 
                            when ''T'' then DT.DisplayCode end), 
    DiagnosisCodeDesc = (case ICDType  
                            when ''9'' then D9.UserDescription 
                            when ''C'' then DC.UserDescription 
                            when ''T'' then DT.UserDescription end), 
    AB.DischargeDate, AB.DischargeTime, 
    AB.EncounterNumber, AB.EncounterSequence, 
    CM.FirstName, CM.LastName, CM.MiddleName, 
    Gender = LG.DisplayCode, GenderDesc = LG.UserDescription, 
    InstitutionNumber = H.DisplayCode, InstitutionNumberDesc = H.UserDescription, 
    InterventionCode = (case ICDType 
                            when ''9'' then P9.DisplayCode 
                            when ''C'' then PC.DisplayCode 
                            when ''T'' then PT.DisplayCode end), 
    InterventionCodeDesc = (case ICDType 
                            when ''9'' then P9.UserDescription 
                            when ''C'' then PC.UserDescription 
                            when ''T'' then PT.UserDescription end), 
    ICDType, 
    ProviderNumber = LP.DisplayCode, 
    ProviderNumberDesc = LP.UserDescription, 
    PSCodeOrMISCode = (case when CareType = 5 then LM.DisplayCode else LPS.DisplayCode end),
    PSCodeOrMISCodeDesc = (case when CareType = 5 then LM.UserDescription else LPS.UserDescription end),

    zzAbstractLink = AB.AbstractID, zzPatientLink = CM.PatientID 
from CM_CPI CM with (nolock)
    inner join AB_Abstract AB with (nolock) on CM.ChartNumber = AB.ChartNumber and (isnull(CM.HospitalID, 0) = isnull(AB.HospitalID, 0) or isnull(CM.HospitalID, 0) = 0)
    inner join LU_CareType CT with (nolock) on AB.CareType = CT.Code
    inner join H_InstitutionProfile H with (nolock) on AB.InstitutionNumber = H.Code
    left  join AB_PatientService PS with (nolock) on AB.AbstractID = PS.AbstractID and ServiceOccurrence = 1
    left  join AB_Diagnosis D with (nolock) on AB.AbstractID = D.AbstractID and D.DiagnosisOccurrence = 1
    left  join AB_Intervention I with (nolock) on AB.AbstractID = I.AbstractID and I.IntervOccurrence = 1
    left  join AB_Provider P with (nolock) on AB.AbstractID = P.AbstractID and P.ProviderOccurrence = 1
    left  join ICD_DiagFile9 D9 with (nolock) on D.DiagnosisCode = D9.Code
    left  join ICD_DiagFile9cm DC with (nolock) on D.DiagnosisCode = DC.Code
    left  join ICD_DiagFile10 DT with (nolock) on D.DiagnosisCode = DT.Code
    left  join ICD_ProcFile9 P9 with (nolock) on I.IntervCode = P9.Code
    left  join ICD_ProcFile9cm PC with (nolock) on I.IntervCode = PC.Code
    left  join ICD_ProcFile10 PT with (nolock) on I.IntervCode = PT.Code
    left  join LU_PatientService LPS with (nolock) on PS.PatientService = LPS.Code
    left  join LU_Provider LP with (nolock) on P.ProviderNumber = LP.Code
    left  join LU_Gender_I LG with (nolock) on CM.Gender = LG.Code
    left  join LU_MisCode LM with (nolock) on AB.MisCode = LM.Code
    left  join LU_AgeCode LA with (nolock) on AB.AgeCode = LA.Code
    left  join LU_AdmitCategory LAC with (nolock) on AB.AdmitCategory = LAC.Code
--PR - 07485
--where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB.HospitalID is null or AB.HospitalID = 0
--    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB.HospitalID, 0))
Union
select 
    AB.AdmitDate, AdmitTime = null, 
    AdmitAgeCode = LA.DisplayCode, AdmitAgeCodeDesc = LA.UserDescription, 
    AdmitAgeNumber = RD.AgeNumber, 
    AdmitCategory = null, AdmitCategoryDesc = null, 
    AssessmentType = A.DisplayCode, AssessmentTypeDesc = A.UserDescription, 
    CM.BirthDate, 
    CM.ChartNumber, 
    CareType = CT.DisplayCode, CareTypeDesc = CT.UserDescription, 
    DiagnosisCode = DT.DisplayCode,    DiagnosisCodeDesc = DT.UserDescription, 
    DischargeDate = (case when A.CIHIValue = ''3'' then AB.FollowUpDate else AB.DischargeDate end), 
    DischargeTime = null, 

    AB.EncounterNumber, EncounterSequence = null, 
    CM.FirstName, CM.LastName, CM.MiddleName, 
    Gender = LG.DisplayCode, GenderDesc = LG.UserDescription, 
    InstitutionNumber = H.DisplayCode, InstitutionNumberDesc = H.UserDescription, 
    InterventionCode = null,  InterventionCodeDesc = null, 
    ICDType, 
    ProviderNumber = LP.DisplayCode, ProviderNumberDesc = LP.UserDescription, 
    PSCodeOrMISCode = null,
    PSCodeOrMISCodeDesc = null,

    zzAbstractLink = AB.AbstractID, zzPatientLink = CM.PatientID 
from CM_CPI CM with (nolock)
    inner join RH_ClientInfo AB with (nolock) on CM.ChartNumber = AB.ChartNumber and (isnull(CM.HospitalID, 0) = isnull(AB.HospitalID, 0) or isnull(CM.HospitalID, 0) = 0)
    inner join RH_Demographic RD with (nolock) on AB.AbstractID = RD.AbstractID
    inner join LU_CareType CT with (nolock) on AB.CareType = CT.Code
    inner join H_InstitutionProfile H with (nolock) on AB.InstitutionNumber = H.Code
    left  join RH_Diagnosis D with (nolock) on AB.AbstractID = D.AbstractID and D.DiagnosisOccurrence = 1
    left  join RH_Provider P with (nolock) on AB.AbstractID = P.AbstractID and P.ProviderOccurrence = 1
    left  join ICD_DiagFile10 DT with (nolock) on D.DiagnosisCode = DT.Code
    left  join LU_Provider LP with (nolock) on P.ProviderNumber = LP.Code
    left  join LU_Gender_I LG with (nolock) on CM.Gender = LG.Code
    left  join LU_AgeCode LA with (nolock) on RD.AgeCode = LA.Code
    left  join LU_CodeFile A with (nolock) on AB.AssessmentType = A.Code
--PR - 07485
--where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB.HospitalID is null or AB.HospitalID = 0
--    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB.HospitalID, 0))
union
select 
    AB.AdmitDate, AdmitTime = null, 
    AdmitAgeCode = (select top 1 DisplayCode from lu_Agecode LAC where LAC.CIHIValue = ''Y''), 
    AdmitAgeCodeDesc = (select top 1 UserDescription from lu_Agecode LAC where LAC.CIHIValue = ''Y''), 
    AdmitAgeNumber = datediff(year, CM.BirthDate, AB.AdmitDate), 
    AdmitCategory = null, AdmitCategoryDesc = null, 
    AssessmentType = A.DisplayCode, AssessmentTypeDesc = A.UserDescription, 
    CM.BirthDate, 
    CM.ChartNumber, 
    CareType = CT.DisplayCode, CareTypeDesc = CT.UserDescription, 
    DiagnosisCode = DT.DisplayCode,    DiagnosisCodeDesc = DT.UserDescription, 
    DischargeDate = (case when A.CIHIValue in ( ''06'', ''07'', ''08'') then AB.DischargeDate
                          when A.CIHIValue = ''00'' then AB.Z7
                          when A.CIHIValue = ''09'' then AB.AB1b
                          else AB.A3 
                    end),
    DischargeTime = null, 
    EncounterNumber = AB.AA1, EncounterSequence = null, 
    CM.FirstName, CM.LastName, CM.MiddleName, 
    Gender = LG.DisplayCode, GenderDesc = LG.UserDescription, 
    InstitutionNumber = H.DisplayCode, InstitutionNumberDesc = H.UserDescription, 
    InterventionCode = null,  InterventionCodeDesc = null, 
    ICDType = ''T'', 
    ProviderNumber = LP.DisplayCode, ProviderNumberDesc = LP.UserDescription, 
    PSCodeOrMISCode = null,
    PSCodeOrMISCodeDesc = null,
    zzAbstractLink = AB.AbstractID, zzPatientLink = CM.PatientID 
from CM_CPI CM with (nolock) 
    inner join CRS_Demographic AB with (nolock) on CM.ChartNumber = AB.ChartNumber and (isnull(CM.HospitalID, 0) = isnull(AB.HospitalID, 0) or isnull(CM.HospitalID, 0) = 0)
    inner join H_InstitutionProfile H with (nolock) on AB.InstitutionNumber = H.Code
    inner join LU_CareType CT with (nolock) on H.AssociationID = CT.Code
    left  join CRS_Diagnosis D with (nolock) on AB.AbstractID = D.AbstractID 
    left  join CRS_Signature P with (nolock) on AB.AbstractID = P.AbstractID and P.ProviderOccurrence = 1
    left  join ICD_DiagFile10 DT with (nolock) on D.I3a = DT.Code
    left  join LU_Provider LP with (nolock) on P.ProviderNumber = LP.Code
    left  join LU_Gender_I LG with (nolock) on CM.Gender = LG.Code
    left  join LU_CodeFile A with (nolock) on AB.AA8 = A.Code
--PR - 07485
--where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB.HospitalID is null or AB.HospitalID = 0
--    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB.HospitalID, 0))
union
select 
    AB.AdmitDate, AB.AdmitTime, 
    AdmitAgeCode = (select top 1 DisplayCode from lu_Agecode LAC where LAC.CIHIValue = ''Y''), 
    AdmitAgeCodeDesc = (select top 1 UserDescription from lu_Agecode LAC where LAC.CIHIValue = ''Y''), 
    AdmitAgeNumber = datediff(year, CM.BirthDate, AB.AdmitDate), 
    AdmitCategory = null, AdmitCategoryDesc = null, 
    AssessmentType = null, AssessmentTypeDesc = null, 
    CM.BirthDate, 
    CM.ChartNumber, 
    CareType = CT.DisplayCode, CareTypeDesc = CT.UserDescription, 
    DiagnosisCode = null,    DiagnosisCodeDesc = null, 
    AB.DischargeDate, AB.DischargeTime, 
    AB.EncounterNumber, AB.EncounterSequence, 
    CM.FirstName, CM.LastName, CM.MiddleName, 
    Gender = LG.DisplayCode, GenderDesc = LG.UserDescription, 
    InstitutionNumber = H.DisplayCode, InstitutionNumberDesc = H.UserDescription, 
    InterventionCode = null,  InterventionCodeDesc = null, 
    ICDType = null, 
    ProviderNumber = null, ProviderNumberDesc = null, 
    PSCodeOrMISCode = null,
    PSCodeOrMISCodeDesc = null,
    zzAbstractLink = AB.AbstractID, zzPatientLink = CM.PatientID 
from CM_CPI CM with (nolock)
    inner join AB_Main AB with (nolock) on CM.ChartNumber = AB.ChartNumber and (isnull(CM.HospitalID, 0) = isnull(AB.HospitalID, 0) or isnull(CM.HospitalID, 0) = 0)
    inner join H_InstitutionProfile H with (nolock) on AB.InstitutionNumber = H.Code
    inner join LU_CareType CT with (nolock) on H.AssociationID = CT.Code
    left  join LU_Gender_I LG with (nolock) on CM.Gender = LG.Code
where AB.AppID <> 0 and AB.AppType = 9
--PR - 07485
--    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB.HospitalID is null or AB.HospitalID = 0
--    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB.HospitalID, 0)))
union
select 
    AdmitDate = AB.AdmitDate, AdmitTime = null, 
    AdmitAgeCode = (select top 1 DisplayCode from lu_Agecode LAC where LAC.CIHIValue = ''Y''), 
    AdmitAgeCodeDesc = (select top 1 UserDescription from lu_Agecode LAC where LAC.CIHIValue = ''Y''), 
    AdmitAgeNumber = datediff(year, CM.BirthDate, AB.AdmitDate), 
    AdmitCategory = null,  
    AdmitCategoryDesc = null, 
    AssessmentType = ASS.DisplayCode, 
    AssessmentTypeDesc = Ass.UserDescription, 
    CM.BirthDate, 
    CM.ChartNumber, 
    CareType = CT.DisplayCode, CareTypeDesc = CT.UserDescription, 
    DiagnosisCode = DT.DisplayCode, 
    DiagnosisCodeDesc = DT.UserDescription, 
    DischargeDate = S.X80, DischargeTime = null, 
    EncounterNumber = null, EncounterSequence = null, 
    CM.FirstName, CM.LastName, CM.MiddleName, 
    Gender = LG.DisplayCode, GenderDesc = LG.UserDescription, 
    InstitutionNumber = H.DisplayCode, InstitutionNumberDesc = H.UserDescription, 
    InterventionCode = PT.DisplayCode, 
    InterventionCodeDesc = PT.UserDescription, 
    ICDType = null, 
    ProviderNumber = LP.DisplayCode, 
    ProviderNumberDesc = LP.UserDescription, 
    PSCodeOrMISCode = null, 
    PSCodeOrMISCodeDesc = null, 
    zzAbstractLink = AB.AbstractID, zzPatientLink = CM.PatientID 
from CM_CPI CM with (nolock)
    inner join OMHRS_SecAA AB with (nolock) on CM.ChartNumber = AB.ChartNumber and (isnull(CM.HospitalID, 0) = isnull(AB.HospitalID, 0) or isnull(CM.HospitalID, 0) = 0)
    inner join OMHRS_SecA A with (nolock) on AB.AbstractID = A.AbstractID
    inner join LU_CodeFile Ass with (nolock) on A.A2 = Ass.Code
    inner join H_InstitutionProfile H with (nolock) on AB.InstitutionNumber = H.Code
    inner join LU_CareType CT with (nolock) on H.AssociationID = CT.Code
    left  join OMHRS_SecS S with (nolock) on AB.AbstractID = S.AbstractID
    left  join OMHRS_DSM_Diag D with (nolock) on AB.AbstractID = D.AbstractID and D.Occurrence = 1
    left  join OMHRS_Intervention I with (nolock) on AB.AbstractID = I.AbstractID and I.IntervOccurrence = 1
    left  join OMHRS_Provider P with (nolock) on AB.AbstractID = P.AbstractID and P.ProviderOccurrence = 1
    left  join ICD_DiagFile10 DT with (nolock) on D.Q2 = DT.Code
    left  join ICD_ProcFile10 PT with (nolock) on I.IntervCode = PT.Code
    left  join LU_Provider LP with (nolock) on P.ProviderNumber = LP.Code
    left  join LU_Gender_I LG with (nolock) on CM.Gender = LG.Code
--PR - 07485
--where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB.HospitalID is null or AB.HospitalID = 0
--    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB.HospitalID, 0))
--    --EN - 00666
--    or Is_Member(nullif((select top 1 ReportGroup from h_hospitalprofile where code = AB.HospitalID), '''')) = 1

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_AcetabularComponent_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
Create View [dbo].[CJRR_AcetabularComponent_VR]
as
select
      CJRR_AcetabularComponent.RecordID as zzCJRR_Link
      ,AcetabularComponentHOccurrence = Occurrence
      ,AcetabularComponentStickerCode = LU_CJRR_AcetabularComponentH.DisplayCode, AcetabularComponentStickerCodeDesc = LU_CJRR_AcetabularComponentH.UserDescription
      ,AcetabularComponentManufacturer = LU_Manufacturer.DisplayCode, AcetabularComponentManufacturerDesc = LU_Manufacturer.UserDescription
      ,AcetabularComponentOtherManufacturer = CJRR_AcetabularComponent.OtherManufacturer
      ,AcetabularComponentCatalogueNumber = CJRR_AcetabularComponent.CatalogueNumber
      ,AcetabularComponentLotNumber = CJRR_AcetabularComponent.LotNumber
from dbo.CJRR_AcetabularComponent
    left join LU_CJRR_AcetabularComponentH on CJRR_AcetabularComponent.StickerCode = LU_CJRR_AcetabularComponentH.Code
    left join LU_CodeFile LU_Manufacturer on CJRR_AcetabularComponent.Manufacturer = LU_Manufacturer.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_AcetabularInsert_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
Create View [dbo].[CJRR_AcetabularInsert_VR]
as
select
      CJRR_AcetabularInsert.RecordID as zzCJRR_Link
      ,AcetabularInsertOccurrence = Occurrence
      ,AcetabularInsertStickerCode = LU_CJRR_AcetabularInsertH.DisplayCode, AcetabularInsertStickerCodeDesc = LU_CJRR_AcetabularInsertH.UserDescription
      ,AcetabularInsertManufacturer = LU_Manufacturer.DisplayCode, AcetabularInsertManufacturerDesc = LU_Manufacturer.UserDescription
      ,AcetabularInsertOtherManufacturer = CJRR_AcetabularInsert.OtherManufacturer
      ,AcetabularInsertCatalogueNumber = CJRR_AcetabularInsert.CatalogueNumber
      ,AcetabularInsertLotNumber = CJRR_AcetabularInsert.LotNumber
from dbo.CJRR_AcetabularInsert
    left join LU_CJRR_AcetabularInsertH on CJRR_AcetabularInsert.StickerCode = LU_CJRR_AcetabularInsertH.Code
    left join LU_CodeFile LU_Manufacturer on CJRR_AcetabularInsert.Manufacturer = LU_Manufacturer.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_Cement_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
Create View [dbo].[CJRR_Cement_VR]
as
select
      CJRR_Cement.RecordID as zzCJRR_Link
      ,CementOccurrence = Occurrence
      ,CementStickerCode = (case when AppID = 40000 then LU_CJRR_CementDetailsK.DisplayCode
                                 when AppID = 40001 then LU_CJRR_CementDetailsH.DisplayCode
                            end)
      ,CementStickerCodeDesc = (case when AppID = 40000 then LU_CJRR_CementDetailsK.UserDescription
                                     when AppID = 40001 then LU_CJRR_CementDetailsH.UserDescription
                                end)
      ,CementName = LU_Name.DisplayCode, CementNameDesc = LU_Name.UserDescription
      ,CementOtherName = CJRR_Cement.OtherName
      ,CementCatalogueNumber = CJRR_Cement.CatalogueNumber
      ,CementLotNumber = CJRR_Cement.LotNumber
from CJRR_Abstract 
    inner join dbo.CJRR_Cement on CJRR_Abstract.RecordID = CJRR_Cement.RecordID
    left join LU_CJRR_CementDetailsK on CJRR_Cement.StickerCode = LU_CJRR_CementDetailsK.Code
    left join LU_CJRR_CementDetailsH on CJRR_Cement.StickerCode = LU_CJRR_CementDetailsH.Code
    left join LU_CodeFile LU_Name on CJRR_Cement.Name = LU_Name.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_ErrorsWarnings_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[CJRR_ErrorsWarnings_VR]
AS
SELECT 
    CIHI_ElementID = U_UsersFields.CIHI_ID,
    FieldName = U_UsersFields.Header_User, 
    --ErrorMessage = dbo.MG_Messages.MessageText, 
    MessageLevel = CASE AB_ErrorMessages.MessageType WHEN 1 THEN ''Warning'' 
                                    WHEN 2 THEN ''Error'' 
                                    WHEN 3 THEN ''Critical'' 
                                    WHEN 0 THEN ''Information'' 
                                    WHEN 5 THEN ''Question'' END, 
    AB_ErrorMessages.MessageText, 
    AB_ErrorMessages.SaveDate, 
    AB_ErrorMessages.AbstractID AS zzCJRR_Link
FROM dbo.AB_ErrorMessages with (nolock)
    --left join dbo.MG_Messages with (nolock)
    --    on dbo.AB_ErrorMessages.MessageKey = dbo.MG_Messages.MessageKey
    left join dbo.AB_ErrorMessageFields with (nolock)
        on dbo.AB_ErrorMessages.AppID = dbo.AB_ErrorMessageFields.AppID
            and dbo.AB_ErrorMessages.AbstractID = dbo.AB_ErrorMessageFields.AbstractID 
            and dbo.AB_ErrorMessages.MessageKey = dbo.AB_ErrorMessageFields.MessageKey
    left join dbo.U_UsersFields with (nolock) 
        on UserID = 1 and dbo.AB_ErrorMessages.AppID = dbo.U_UsersFields.AppID and 
        (case when isnumeric(replace(dbo.AB_ErrorMessageFields.FieldKey, ''FK'', '''')) = 1 
              then replace(dbo.AB_ErrorMessageFields.FieldKey, ''FK'', '''')
              else 0 end) = dbo.U_UsersFields.FieldID 
Where AB_ErrorMessages.appid in (40000, 40001)


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_FemoralComponent_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
Create View [dbo].[CJRR_FemoralComponent_VR]
as
select
       CJRR_FemoralComponent.RecordID as zzCJRR_Link
      ,FemoralComponentOccurrence = Occurrence
      ,FemoralComponentStickerCode = (case when AppID = 40000 then LU_CJRR_FemoralComponentK.DisplayCode
                                           when AppID = 40001 then LU_CJRR_FemoralComponentH.DisplayCode
                                      end)
      ,FemoralComponentStickerCodeDesc = (case when AppID = 40000 then LU_CJRR_FemoralComponentK.UserDescription
                                           when AppID = 40001 then LU_CJRR_FemoralComponentH.UserDescription
                                      end)
      ,Manufacturer = LU_Manufacturer.DisplayCode, ManufacturerDesc = LU_Manufacturer.UserDescription
      ,CJRR_FemoralComponent.OtherManufacturer as FemoralComponentOtherManufacturer
      ,CJRR_FemoralComponent.CatalogueNumber as FemoralComponentCatalogueNumber
      ,CJRR_FemoralComponent.LotNumber as FemoralComponentLotNumber
from CJRR_Abstract 
    inner join dbo.CJRR_FemoralComponent on CJRR_Abstract.RecordID = CJRR_FemoralComponent.RecordID
    left join LU_CJRR_FemoralComponentK on CJRR_FemoralComponent.StickerCode = LU_CJRR_FemoralComponentK.Code
    left join LU_CJRR_FemoralComponentH on CJRR_FemoralComponent.StickerCode = LU_CJRR_FemoralComponentH.Code
    left join LU_CodeFile LU_Manufacturer on CJRR_FemoralComponent.Manufacturer = LU_Manufacturer.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_FemoralHead_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
Create View [dbo].[CJRR_FemoralHead_VR]
as
select
      CJRR_FemoralHead.RecordID as zzCJRR_Link
      ,FemoralHeadOccurrence = Occurrence
      ,FemoralHeadStickerCode = LU_CJRR_FemoralHeadH.DisplayCode, FemoralHeadStickerCodeDesc = LU_CJRR_FemoralHeadH.UserDescription
      ,FemoralHeadManufacturer = LU_Manufacturer.DisplayCode, FemoralHeadManufacturerDesc = LU_Manufacturer.UserDescription
      ,FemoralHeadOtherManufacturer = CJRR_FemoralHead.OtherManufacturer
      ,FemoralHeadCatalogueNumber = CJRR_FemoralHead.CatalogueNumber
      ,FemoralHeadLotNumber = CJRR_FemoralHead.LotNumber
from dbo.CJRR_FemoralHead
    left join LU_CJRR_FemoralHeadH on CJRR_FemoralHead.StickerCode = LU_CJRR_FemoralHeadH.Code
    left join LU_CodeFile LU_Manufacturer on CJRR_FemoralHead.Manufacturer = LU_Manufacturer.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_PatellarComponent_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
Create View [dbo].[CJRR_PatellarComponent_VR]
as
select
      CJRR_PatellarComponent.RecordID as zzCJRR_Link
      ,PatellarComponentOccurrence = Occurrence
      ,PatellarComponentStickerCode = LU_CJRR_PatellarComponentK.DisplayCode, PatellarComponentStickerCodeDesc = LU_CJRR_PatellarComponentK.UserDescription
      ,PatellarComponentManufacturer = LU_Manufacturer.DisplayCode, PatellarComponentManufacturerDesc = LU_Manufacturer.UserDescription
      ,PatellarComponentOtherManufacturer = CJRR_PatellarComponent.OtherManufacturer
      ,PatellarComponentCatalogueNumber = CJRR_PatellarComponent.CatalogueNumber
      ,PatellarComponentLotNumber = CJRR_PatellarComponent.LotNumber
from CJRR_PatellarComponent
    left join LU_CJRR_PatellarComponentK on CJRR_PatellarComponent.StickerCode = LU_CJRR_PatellarComponentK.Code
    left join LU_CodeFile LU_Manufacturer on CJRR_PatellarComponent.Manufacturer = LU_Manufacturer.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_TibialComponent_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
Create View [dbo].[CJRR_TibialComponent_VR]
as
select
      CJRR_TibialComponent.RecordID as zzCJRR_Link
      ,TibialComponentOccurrence = Occurrence
      ,TibialComponentStickerCode = LU_CJRR_TibialComponentK.DisplayCode, TibialComponentStickerCodeDesc = LU_CJRR_TibialComponentK.UserDescription
      ,TibialComponentManufacturer = LU_Manufacturer.DisplayCode, TibialComponentManufacturerDesc = LU_Manufacturer.UserDescription
      ,TibialComponentOtherManufacturer	= CJRR_TibialComponent.OtherManufacturer
      ,TibialComponentCatalogueNumber = CJRR_TibialComponent.CatalogueNumber
      ,TibialComponentLotNumber = CJRR_TibialComponent.LotNumber
from CJRR_TibialComponent
    left join LU_CJRR_TibialComponentK on CJRR_TibialComponent.StickerCode = LU_CJRR_TibialComponentK.Code
    left join LU_CodeFile LU_Manufacturer on CJRR_TibialComponent.Manufacturer = LU_Manufacturer.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_TibialInsert_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
Create View [dbo].[CJRR_TibialInsert_VR]
as
select
      CJRR_TibialInsert.RecordID as zzCJRR_Link
      ,TibialInsertOccurrence  = Occurrence
      ,TibialInsertStickerCode = LU_CJRR_TibialInsertK.DisplayCode, TibialInsertStickerCodeDesc = LU_CJRR_TibialInsertK.UserDescription
      ,TibialInserttManufacturer = LU_Manufacturer.DisplayCode, TibialInsertManufacturerDesc = LU_Manufacturer.UserDescription
      ,TibialInsertOtherManufacturer = CJRR_TibialInsert.OtherManufacturer
      ,TibialInsertCatalogueNumber = CJRR_TibialInsert.CatalogueNumber
      ,TibialInsertLotNumber = CJRR_TibialInsert.LotNumber
From CJRR_TibialInsert
    left join LU_CJRR_TibialInsertK on CJRR_TibialInsert.StickerCode = LU_CJRR_TibialInsertK.Code
    left join LU_CodeFile LU_Manufacturer on CJRR_TibialInsert.Manufacturer = LU_Manufacturer.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_UD_Abstracting_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[CJRR_UD_Abstracting_VR]
AS
SELECT
    dbo.CJRR_UDFieldsDate.UDDate1 AS Date1UD,    dbo.CJRR_UDFieldsDate.UDDate2 AS Date2UD, 
    dbo.CJRR_UDFieldsDate.UDDate3 AS Date3UD,    dbo.CJRR_UDFieldsDate.UDDate4 AS Date4UD,
    dbo.CJRR_UDFieldsDate.UDDate5 AS Date5UD,    dbo.CJRR_UDFieldsDate.UDDate6 AS Date6UD,
    dbo.CJRR_UDFieldsDate.UDDate7 AS Date7UD,    dbo.CJRR_UDFieldsDate.UDDate8 AS Date8UD,
    dbo.CJRR_UDFieldsDate.UDDate9 AS Date9UD,    dbo.CJRR_UDFieldsDate.UDDate10 AS Date10UD,
    dbo.CJRR_UDFieldsDate.UDDate11 AS Date11UD,  dbo.CJRR_UDFieldsDate.UDDate12 AS Date12UD,
    dbo.CJRR_UDFieldsDate.UDDate13 AS Date13UD,  dbo.CJRR_UDFieldsDate.UDDate14 AS Date14UD,
    dbo.CJRR_UDFieldsDate.UDDate15 AS Date15UD,  dbo.CJRR_UDFieldsDate.UDDate16 AS Date16UD,
    dbo.CJRR_UDFieldsDate.UDDate17 AS Date17UD,  dbo.CJRR_UDFieldsDate.UDDate18 AS Date18UD,
    dbo.CJRR_UDFieldsDate.UDDate19 AS Date19UD,  dbo.CJRR_UDFieldsDate.UDDate20 AS Date20UD,
    dbo.CJRR_UDFieldsDate.UDDate21 AS Date21UD,  dbo.CJRR_UDFieldsDate.UDDate22 AS Date22UD,
    dbo.CJRR_UDFieldsDate.UDDate23 AS Date23UD,  dbo.CJRR_UDFieldsDate.UDDate24 AS Date24UD,
    dbo.CJRR_UDFieldsDate.UDDate25 AS Date25UD,  
    
    LU_CodeFile_1.DisplayCode AS Lookup1UD, LU_CodeFile_1.UserDescription AS Lookup1UDDesc, 
    LU_CodeFile_2.DisplayCode AS Lookup2UD, LU_CodeFile_2.UserDescription AS Lookup2UDDesc, 
    LU_CodeFile_3.DisplayCode AS Lookup3UD, LU_CodeFile_3.UserDescription AS Lookup3UDDesc, 
    LU_CodeFile_4.DisplayCode AS Lookup4UD, LU_CodeFile_4.UserDescription AS Lookup4UDDesc, 
    LU_CodeFile_5.DisplayCode AS Lookup5UD, LU_CodeFile_5.UserDescription AS Lookup5UDDesc, 
    LU_CodeFile_6.DisplayCode AS Lookup6UD, LU_CodeFile_6.UserDescription AS Lookup6UDDesc, 
    LU_CodeFile_7.DisplayCode AS Lookup7UD, LU_CodeFile_7.UserDescription AS Lookup7UDDesc, 
    LU_CodeFile_8.DisplayCode AS Lookup8UD, LU_CodeFile_8.UserDescription AS Lookup8UDDesc, 
    LU_CodeFile_9.DisplayCode AS Lookup9UD, LU_CodeFile_9.UserDescription AS Lookup9UDDesc, 
    LU_CodeFile_10.DisplayCode AS Lookup10UD, LU_CodeFile_10.UserDescription AS Lookup10UDDesc, 
    LU_CodeFile_11.DisplayCode AS Lookup11UD, LU_CodeFile_11.UserDescription AS Lookup11UDDesc, 
    LU_CodeFile_12.DisplayCode AS Lookup12UD, LU_CodeFile_12.UserDescription AS Lookup12UDDesc, 
    LU_CodeFile_13.DisplayCode AS Lookup13UD, LU_CodeFile_13.UserDescription AS Lookup13UDDesc, 
    LU_CodeFile_14.DisplayCode AS Lookup14UD, LU_CodeFile_14.UserDescription AS Lookup14UDDesc, 
    LU_CodeFile_15.DisplayCode AS Lookup15UD, LU_CodeFile_15.UserDescription AS Lookup15UDDesc, 
    LU_CodeFile_16.DisplayCode AS Lookup16UD, LU_CodeFile_16.UserDescription AS Lookup16UDDesc, 
    LU_CodeFile_17.DisplayCode AS Lookup17UD, LU_CodeFile_17.UserDescription AS Lookup17UDDesc, 
    LU_CodeFile_18.DisplayCode AS Lookup18UD, LU_CodeFile_18.UserDescription AS Lookup18UDDesc, 
    LU_CodeFile_19.DisplayCode AS Lookup19UD, LU_CodeFile_19.UserDescription AS Lookup19UDDesc, 
    LU_CodeFile_20.DisplayCode AS Lookup20UD, LU_CodeFile_20.UserDescription AS Lookup20UDDesc, 
    LU_CodeFile_21.DisplayCode AS Lookup21UD, LU_CodeFile_21.UserDescription AS Lookup21UDDesc, 
    LU_CodeFile_22.DisplayCode AS Lookup22UD, LU_CodeFile_22.UserDescription AS Lookup22UDDesc, 
    LU_CodeFile_23.DisplayCode AS Lookup23UD, LU_CodeFile_23.UserDescription AS Lookup23UDDesc, 
    LU_CodeFile_24.DisplayCode AS Lookup24UD, LU_CodeFile_24.UserDescription AS Lookup24UDDesc, 
    LU_CodeFile_25.DisplayCode AS Lookup25UD, LU_CodeFile_25.UserDescription AS Lookup25UDDesc, 
    
    dbo.CJRR_UDFieldsInteger.UDInteger1 AS Numeric1UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger2 AS Numeric2UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger3 AS Numeric3UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger4 AS Numeric4UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger5 AS Numeric5UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger6 AS Numeric6UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger7 AS Numeric7UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger8 AS Numeric8UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger9 AS Numeric9UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger10 AS Numeric10UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger11 AS Numeric11UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger12 AS Numeric12UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger13 AS Numeric13UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger14 AS Numeric14UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger15 AS Numeric15UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger16 AS Numeric16UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger17 AS Numeric17UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger18 AS Numeric18UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger19 AS Numeric19UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger20 AS Numeric20UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger21 AS Numeric21UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger22 AS Numeric22UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger23 AS Numeric23UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger24 AS Numeric24UD, 
    dbo.CJRR_UDFieldsInteger.UDInteger25 AS Numeric25UD, 
    
    dbo.CJRR_UDFieldsText.UDText1 AS Notes1UD, 
    dbo.CJRR_UDFieldsText.UDText2 AS Notes2UD, 
    dbo.CJRR_UDFieldsText.UDText3 AS Notes3UD, 
    dbo.CJRR_UDFieldsText.UDText4 AS Notes4UD, 
    dbo.CJRR_UDFieldsText.UDText5 AS Notes5UD, 
    dbo.CJRR_UDFieldsText.UDText6 AS Notes6UD,
    dbo.CJRR_UDFieldsText.UDText7 AS Notes7UD,
    dbo.CJRR_UDFieldsText.UDText8 AS Notes8UD,
    dbo.CJRR_UDFieldsText.UDText9 AS Notes9UD,
    dbo.CJRR_UDFieldsText.UDText10 AS Notes10UD,
    dbo.CJRR_UDFieldsText.UDText11 AS Notes11UD,
    dbo.CJRR_UDFieldsText.UDText12 AS Notes12UD,
    dbo.CJRR_UDFieldsText.UDText13 AS Notes13UD,
    dbo.CJRR_UDFieldsText.UDText14 AS Notes14UD,
    dbo.CJRR_UDFieldsText.UDText15 AS Notes15UD,
    dbo.CJRR_UDFieldsText.UDText16 AS Notes16UD,
    dbo.CJRR_UDFieldsText.UDText17 AS Notes17UD,
    dbo.CJRR_UDFieldsText.UDText18 AS Notes18UD,
    dbo.CJRR_UDFieldsText.UDText19 AS Notes19UD,
    dbo.CJRR_UDFieldsText.UDText20 AS Notes20UD,
    dbo.CJRR_UDFieldsText.UDText21 AS Notes21UD,
    dbo.CJRR_UDFieldsText.UDText22 AS Notes22UD,
    dbo.CJRR_UDFieldsText.UDText23 AS Notes23UD,
    dbo.CJRR_UDFieldsText.UDText24 AS Notes24UD,
    dbo.CJRR_UDFieldsText.UDText25 AS Notes25UD,
    
    dbo.CJRR_UDFieldsSmallText.UDSmallText1 AS Text1UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText2 AS Text2UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText3 AS Text3UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText4 AS Text4UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText5 AS Text5UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText6 AS Text6UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText7 AS Text7UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText8 AS Text8UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText9 AS Text9UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText10 AS Text10UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText11 AS Text11UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText12 AS Text12UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText13 AS Text13UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText14 AS Text14UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText15 AS Text15UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText16 AS Text16UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText17 AS Text17UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText18 AS Text18UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText19 AS Text19UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText20 AS Text20UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText21 AS Text21UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText22 AS Text22UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText23 AS Text23UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText24 AS Text24UD, 
    dbo.CJRR_UDFieldsSmallText.UDSmallText25 AS Text25UD, 
    
    dbo.CJRR_UDFieldsTime.UDTime1 AS Time1UD, 
    dbo.CJRR_UDFieldsTime.UDTime2 AS Time2UD, 
    dbo.CJRR_UDFieldsTime.UDTime3 AS Time3UD, 
    dbo.CJRR_UDFieldsTime.UDTime4 AS Time4UD, 
    dbo.CJRR_UDFieldsTime.UDTime5 AS Time5UD, 
    dbo.CJRR_UDFieldsTime.UDTime6 AS Time6UD, 
    dbo.CJRR_UDFieldsTime.UDTime7 AS Time7UD, 
    dbo.CJRR_UDFieldsTime.UDTime8 AS Time8UD, 
    dbo.CJRR_UDFieldsTime.UDTime9 AS Time9UD, 
    dbo.CJRR_UDFieldsTime.UDTime10 AS Time10UD, 
    dbo.CJRR_UDFieldsTime.UDTime11 AS Time11UD, 
    dbo.CJRR_UDFieldsTime.UDTime12 AS Time12UD, 
    dbo.CJRR_UDFieldsTime.UDTime13 AS Time13UD, 
    dbo.CJRR_UDFieldsTime.UDTime14 AS Time14UD, 
    dbo.CJRR_UDFieldsTime.UDTime15 AS Time15UD, 
    dbo.CJRR_UDFieldsTime.UDTime16 AS Time16UD, 
    dbo.CJRR_UDFieldsTime.UDTime17 AS Time17UD, 
    dbo.CJRR_UDFieldsTime.UDTime18 AS Time18UD, 
    dbo.CJRR_UDFieldsTime.UDTime19 AS Time19UD, 
    dbo.CJRR_UDFieldsTime.UDTime20 AS Time20UD, 
    dbo.CJRR_UDFieldsTime.UDTime21 AS Time21UD, 
    dbo.CJRR_UDFieldsTime.UDTime22 AS Time22UD, 
    dbo.CJRR_UDFieldsTime.UDTime23 AS Time23UD, 
    dbo.CJRR_UDFieldsTime.UDTime24 AS Time24UD, 
    dbo.CJRR_UDFieldsTime.UDTime25 AS Time25UD, 
       
    dbo.CJRR_Abstract.RecordID AS zzRehabLink
FROM         
    dbo.CJRR_Abstract with (nolock) LEFT OUTER JOIN

    dbo.CJRR_UDFieldsDate with (nolock) ON dbo.CJRR_Abstract.RecordID = dbo.CJRR_UDFieldsDate.RecordID LEFT OUTER JOIN
    dbo.CJRR_UDFieldsInteger with (nolock) ON dbo.CJRR_Abstract.RecordID = dbo.CJRR_UDFieldsInteger.RecordID LEFT OUTER JOIN
    dbo.CJRR_UDFieldsLookUp with (nolock) ON dbo.CJRR_Abstract.RecordID = dbo.CJRR_UDFieldsLookUp.RecordID LEFT OUTER JOIN
    dbo.CJRR_UDFieldsSmallText with (nolock) ON dbo.CJRR_Abstract.RecordID = dbo.CJRR_UDFieldsSmallText.RecordID LEFT OUTER JOIN
    dbo.CJRR_UDFieldsText with (nolock) ON dbo.CJRR_Abstract.RecordID = dbo.CJRR_UDFieldsText.RecordID LEFT OUTER JOIN
    dbo.CJRR_UDFieldsTime with (nolock) ON dbo.CJRR_Abstract.RecordID = dbo.CJRR_UDFieldsTime.RecordID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_1 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup1 = LU_CodeFile_1.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_2 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup2 = LU_CodeFile_2.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_3 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup3 = LU_CodeFile_3.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_4 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup4 = LU_CodeFile_4.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_5 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup5 = LU_CodeFile_5.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_6 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup6 = LU_CodeFile_6.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_7 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup7 = LU_CodeFile_7.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_8 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup8 = LU_CodeFile_8.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_9 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup9 = LU_CodeFile_9.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_10 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup10 = LU_CodeFile_10.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_11 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup11 = LU_CodeFile_11.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_12 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup12 = LU_CodeFile_12.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_13 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup13 = LU_CodeFile_13.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_14 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup14 = LU_CodeFile_14.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_15 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup15 = LU_CodeFile_15.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_16 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup16 = LU_CodeFile_16.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_17 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup17 = LU_CodeFile_17.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_18 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup18 = LU_CodeFile_18.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_19 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup19 = LU_CodeFile_19.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_20 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup20 = LU_CodeFile_20.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_21 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup21 = LU_CodeFile_21.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_22 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup22 = LU_CodeFile_22.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_23 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup23 = LU_CodeFile_23.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_24 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup24 = LU_CodeFile_24.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_25 with (nolock) ON dbo.CJRR_UDFieldsLookUp.UDLookup25 = LU_CodeFile_25.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
Create View [dbo].[CJRR_UpdateHistory_VR]
as
select
	CJRR_UpdateHistory.RecordID as zzCJRR_Link
	,Coder = U_Users.DisplayCode, CoderDesc = U_Users.UserDescription
	,Updated
	,UpdateType
	,Hospital = H_HospitalProfile.DisplayCode, HospitalDesc = H_HospitalProfile.UserDescription
from CJRR_UpdateHistory
    left join U_Users on Coder = U_Users.Code
    left join H_HospitalProfile on CJRR_UpdateHistory.HospitalID = H_HospitalProfile.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CJRR_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE View [dbo].[CJRR_VR] 
as
select
      CJRR_Abstract.BirthDate
      ,CJRR_Abstract.ChartNumber
      ,CIHIDateSent
      ,U_Users.DisplayCode as CoderNumber, U_Users.UserDescription as CoderNumberDesc
      ,LU_DiagnosisGrouping.DisplayCode as DiagnosisGrouping, LU_DiagnosisGrouping.UserDescription as DiagnosisGroupingDesc
      ,CJRR_Abstract.FirstName
      ,FiscalSurgeryYear
      ,CJRR_Abstract.FixedChartNumber
      ,LU_Gender.DisplayCode as Gender, LU_Gender.UserDescription as GenderDesc
      ,CJRR_Abstract.HealthCareNumber
      ,LU_HCNProvince.DisplayCode as HCNProvince, LU_HCNProvince.UserDescription as HCNProvinceDesc
      ,HCNVersion
      ,H_HospitalProfile.DisplayCode as Hospital, H_HospitalProfile.UserDescription as HospitalDesc
      ,LU_HospitalProvinceCode.DisplayCode as HospitalProvinceCode, LU_HospitalProvinceCode.UserDescription as HospitalProvinceCodeDesc
      ,H_InstitutionProfile.DisplayCode as InstitutionNumber, H_InstitutionProfile.UserDescription as InstitutionNumberDesc
      ,InterventionCIHI
      ,ICD_ProcFile10.DisplayCode as InterventionCode, ICD_ProcFile10.UserDescription as InterventionCodeDesc

      ,LU_IsCompleted.DisplayCode as IsCompleted, LU_IsCompleted.UserDescription as IsCompletedDesc
      ,LU_CIHICorrect.DisplayCode as IsCorrected, LU_CIHICorrect.UserDescription as IsCorrectedDesc
	  ,LU_CustomStatus.DisplayCode AS IsCustomValidated, LU_CustomStatus.UserDescription AS IsCustomValidatedDesc
      ,LU_DeleteStatus.DisplayCode as IsDeleted, LU_DeleteStatus.UserDescription as IsDeletedDesc
      ,LU_IsValidated.DisplayCode as IsValidated, LU_IsValidated.UserDescription as IsValidatedDesc
      ,LU_IsSubmited.DisplayCode as IsSubmited, LU_IsSubmited.UserDescription as IsSubmitedDesc

      ,ICD_DiagFile10.DisplayCode as MainDiagnosisCode, ICD_DiagFile10.UserDescription as MainDiagnosisCodeDesc
      ,CJRR_Abstract.LastName
      ,CJRR_Abstract.MaidenName
      ,CJRR_Abstract.MiddleName
      ,LU_AppIDs.DisplayCode as Module, LU_AppIDs.UserDescription as ModuleDesc
      ,CJRR_Abstract.PostalCode
      ,LU_PrimaryProcedureType.DisplayCode as PrimaryProcedureType, LU_PrimaryProcedureType.UserDescription as PrimaryProcedureTypeDesc
      ,LU_ReplacementType.DisplayCode as ReplacementType, LU_ReplacementType.UserDescription as ReplacementTypeDesc
      ,LU_RecordSubmitObjective.DisplayCode as RecordSubmitObjective, LU_RecordSubmitObjective.UserDescription as RecordSubmitObjectiveDesc
      ,LU_RecordType.DisplayCode as RecordType, LU_RecordType.UserDescription as RecordTypeDesc
      ,LU_RevisionReason.DisplayCode as RevisionReason, LU_RevisionReason.UserDescription as RevisionReasonDesc
      ,LU_SideLocation.DisplayCode as SideLocation, LU_SideLocation.UserDescription as SideLocationDesc
      ,SurgeonID
      ,SurgeonFirstName
      ,SurgeonLastName
      ,SurgeryDate
      ,CJRR_Abstract.LinkID as zzUniversalLink
      ,AB_Main.AbstractID as zzAbstractLink
      ,CJRR_Abstract.RecordID as zzCJRR_Link
      ,CJRR_Abstract.VolumeID as zzVolumeLink
      
from CJRR_Abstract with (nolock)
    left join AB_Main with (nolock) on CJRR_Abstract.LinkID = AB_Main.UniversalID
    left join LU_AppIDs with (nolock) on CJRR_Abstract.AppID = LU_AppIDs.Code
    left join H_HospitalProfile with (nolock) on CJRR_Abstract.HospitalID = H_HospitalProfile.Code
    left join ICD_DiagFile10 with (nolock) on MainDiagnosisCode = ICD_DiagFile10.Code
    left join ICD_ProcFile10 with (nolock) on CJRR_Abstract.InterventionCode = ICD_ProcFile10.Code
    left join LU_CodeFile LU_RecordType with (nolock) on CJRR_Abstract.RecordType = LU_RecordType.Code
    left join LU_CodeFile LU_HospitalProvinceCode with (nolock) on CJRR_Abstract.HospitalProvinceCode = LU_HospitalProvinceCode.Code 
    left join LU_CodeFile LU_RecordSubmitObjective with (nolock) on CJRR_Abstract.RecordSubmitObjective = LU_RecordSubmitObjective.Code 
    left join H_InstitutionProfile with (nolock) on CJRR_Abstract.InstitutionNumber = H_InstitutionProfile.Code
    left join LU_Provider with (nolock) on CJRR_Abstract.ProviderNumber = LU_Provider.Code
    left join LU_CodeFile LU_HCNProvince with (nolock) on CJRR_Abstract.HCNProvince = LU_HCNProvince.Code 
    left join LU_CodeFile LU_Gender with (nolock) on CJRR_Abstract.Gender = LU_Gender.Code 
    left join LU_CodeFile LU_SideLocation with (nolock) on CJRR_Abstract.SideLocation = LU_SideLocation.Code 
    left join LU_CodeFile LU_ReplacementType with (nolock) on CJRR_Abstract.ReplacementType = LU_ReplacementType.Code 
    left join LU_CodeFile LU_PrimaryProcedureType with (nolock) on CJRR_Abstract.PrimaryProcedureType = LU_PrimaryProcedureType.Code 
    left join LU_CodeFile LU_DiagnosisGrouping with (nolock) on CJRR_Abstract.DiagnosisGrouping = LU_DiagnosisGrouping.Code 
    left join LU_CodeFile LU_RevisionReason with (nolock) on CJRR_Abstract.RevisionReason = LU_RevisionReason.Code 
    left join U_Users with (nolock) on CJRR_Abstract.CoderNumber = U_Users.Code 
    left join LU_DeleteStatus with (nolock) on CJRR_Abstract.IsDeleted = LU_DeleteStatus.Code 
    left join LU_AbstractStatus LU_IsValidated with (nolock) on CJRR_Abstract.IsValidated = LU_IsValidated.Code 
    left join LU_AbstractStatus LU_IsCompleted with (nolock) on CJRR_Abstract.IsCompleted = LU_IsCompleted.Code 
    left join dbo.LU_CustomStatus with (nolock) on dbo.CJRR_Abstract.IsCustomValidated = LU_CustomStatus.Code
    left join LU_YesNoSystem LU_IsSubmited with (nolock) on CJRR_Abstract.IsSubmited = LU_IsSubmited.Code 
    left join LU_CIHICorrect with (nolock) on CJRR_Abstract.IsCorrected = LU_CIHICorrect.Code 
--QA - 00032 disable the domain securite issue
----PR - 07485
--where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or CJRR_Abstract.HospitalID is null or CJRR_Abstract.HospitalID = 0
--    --EN - 00666
--    or Is_Member(nullif(ReportGroup, '''')) = 1
----    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(CJRR_Abstract.HospitalID, 0))



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[CMG_Benchmarks_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[CMG_Benchmarks_VR]
AS
SELECT     GrouperYear, FiscalYear, CMG, CMGDescription, 
    (CASE WHEN GrouperYear < 2007 THEN Complexity ELSE NULL END) AS Complexity, 
    (CASE WHEN GrouperYear > 2006 THEN Complexity ELSE NULL END) AS InpatientRILevel, CMGAgeCategory, 
    AgeGroup, 
    AgeGroupDesc = (case when GrouperYear > 2006 and isnull(CMGAgeCategory, '''') = ''''
						 then (case when AgeGroup = 1 then ''Age 0 - 17'' 
									when AgeGroup = 2 then ''Age 18 - 59'' 
									when AgeGroup = 3 then ''Age 60 - 79'' 
									when AgeGroup = 4 then ''Age 80+'' 
									else null end)
						 else null end),
    BestTotalCases, BestELOS, 
    BestReference, Best10Percentile, Best25Percentile, Best50Percentile, 
    LevelOfCare as LevelOfCareIndicator, 
    ProvTotalCases, ProvELOS, Prov10Percentile, Prov25Percentile, 
    Prov50Percentile, RegionTotalCases, RegionELOS, Region10Percentile, Region25Percentile, Region50Percentile, TargetTotalCases, TargetELOS, 
    TargetReference, Target10Percentile, Target25Percentile, Target50Percentile
FROM         dbo.CMG_Statistics



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_Abstracting_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE   VIEW [dbo].[DAD_Abstracting_VR]
AS
SELECT     
    dbo.AB_ReproductiveCare.PrevTermDelivery AS [#ofPreviousDeliveries], dbo.AB_ReproductiveCare.PrevLiveBirths AS [#ofPreviousLiveBirths], 
    dbo.AB_ReproductiveCare.PrevPreTermDelivery AS [#ofPreviousPreTermDeliveries], 
    dbo.AB_ReproductiveCare.PrevSpontAbortions AS [#ofPrevSpontaneousAbortions], 
    dbo.AB_ReproductiveCare.PrevInduceAbortions AS [#ofPrevTherapueticAbortions], '''' AS AbstractNotes, dbo.AB_Abstract.AbstractNumber, 
    Lookup2.DisplayCode AS AbstractOverflow, Lookup2.UserDescription AS AbstractOverflowDesc, LU_AbstractType.DisplayCode AS AbstractType, 
    LU_AbstractType.UserDescription AS AbstractTypeDesc, dbo.AB_Abstract.AcuteLOS, dbo.AB_Abstract.AdmitDate AS AdmissionDate, 
    dbo.AB_Abstract.AdmitTime AS AdmissionTime, Lookup3.DisplayCode AS AdmitbyAmbulance, Lookup3.UserDescription AS AdmitbyAmbulanceDesc, 
    Lookup4.DisplayCode AS AdmitCategory, Lookup4.UserDescription AS AdmitCategoryDesc, Lookup5.DisplayCode AS AdmitNursingAreaUnitLocation, 
    Lookup5.UserDescription AS AdmittingNursingAreaUnitLDesc, Lookup6.DisplayCode AS AgeCode, Lookup6.UserDescription AS AgeCodeDesc, 
    dbo.AB_Abstract.AgeGroup, dbo.AB_Abstract.AgeNumber, dbo.AB_Abstract.DischargeAge AS AgeUponDischarge, 
    Lookup7.DisplayCode AS AgeUponDischargeCode, Lookup7.UserDescription AS AgeUponDischargeCodeDesc, Lookup8.DisplayCode AS Albumin, 
    Lookup9.DisplayCode AS AlbuminCrossMatched, Lookup9.UserDescription AS AlbuminCrossMatchedDesc, Lookup8.UserDescription AS AlbuminDesc, 
    Lookup10.DisplayCode AS AlbuminTyped, Lookup10.UserDescription AS AlbuminTypedDesc, dbo.AB_Blood.AlbuminUnits, dbo.AB_Abstract.ALCLOS, 
    LU_AlcoholDuringPregnancy.DisplayCode AS AlcoholDuringPregnancy, LU_AlcoholDuringPregnancy.UserDescription AS AlcoholDuringPregnancyDesc, 
    Lookup11.DisplayCode AS AncillaryField1, Lookup11.UserDescription AS AncillaryField1Desc, Lookup12.DisplayCode AS AncillaryField10, 
    Lookup12.UserDescription AS AncillaryField10Desc, Lookup13.DisplayCode AS AncillaryField11, Lookup13.UserDescription AS AncillaryField11Desc, 
    Lookup14.DisplayCode AS AncillaryField12, Lookup14.UserDescription AS AncillaryField12Desc, Lookup15.DisplayCode AS AncillaryField13, 
    Lookup15.UserDescription AS AncillaryField13Desc, Lookup16.DisplayCode AS AncillaryField14, Lookup16.UserDescription AS AncillaryField14Desc, 
    Lookup17.DisplayCode AS AncillaryField15, Lookup17.UserDescription AS AncillaryField15Desc, Lookup18.DisplayCode AS AncillaryField16, 
    Lookup18.UserDescription AS AncillaryField16Desc, Lookup19.DisplayCode AS AncillaryField17, Lookup19.UserDescription AS AncillaryField17Desc, 
    Lookup20.DisplayCode AS AncillaryField2, Lookup20.UserDescription AS AncillaryField2Desc, Lookup21.DisplayCode AS AncillaryField3, 
    Lookup21.UserDescription AS AncillaryField3Desc, Lookup22.DisplayCode AS AncillaryField4, Lookup22.UserDescription AS AncillaryField4Desc, 
    Lookup23.DisplayCode AS AncillaryField5, Lookup23.UserDescription AS AncillaryField5Desc, Lookup24.DisplayCode AS AncillaryField6, 
    Lookup24.UserDescription AS AncillaryField6Desc, Lookup25.DisplayCode AS AncillaryField7, Lookup25.UserDescription AS AncillaryField7Desc, 
    Lookup26.DisplayCode AS AncillaryField8, Lookup26.UserDescription AS AncillaryField8Desc, Lookup27.DisplayCode AS AncillaryField9, 
    Lookup27.UserDescription AS AncillaryField9Desc, dbo.AB_Manitoba.Apgar1Min, dbo.AB_Manitoba.Apgar5Min, 
    dbo.AB_Abstract.ArrivalDate AS ArrivalDateInER, dbo.AB_Abstract.ArrivalTime AS ArrivalTimeInER, Lookup28.DisplayCode AS AttendingPhysician, 
    Lookup28.UserDescription AS AttendingPhysicianDesc, Lookup30.DisplayCode AS AutopsyPerformed, 
    Lookup30.UserDescription AS AutopsyPerformedDesc, Lookup29.DisplayCode AS AutoTransfusion, 
    Lookup29.UserDescription AS AutoTransfusionDesc, Lookup1.DisplayCode AS AWOL, Lookup1.UserDescription AS AWOLDesc, 
    LU_BagVentilation.DisplayCode AS BagVentilation, LU_BagVentilation.UserDescription AS BagVentilationDesc, 
    Lookup31.DisplayCode AS BasicOption1, Lookup31.UserDescription AS BasicOption1Desc, Lookup32.DisplayCode AS BasicOption10, 
    Lookup32.UserDescription AS BasicOption10Desc, Lookup33.DisplayCode AS BasicOption11, Lookup33.UserDescription AS BasicOption11Desc, 
    Lookup34.DisplayCode AS BasicOption12, Lookup34.UserDescription AS BasicOption12Desc, Lookup35.DisplayCode AS BasicOption13, 
    Lookup35.UserDescription AS BasicOption13Desc, Lookup36.DisplayCode AS BasicOption14, Lookup36.UserDescription AS BasicOption14Desc, 
    Lookup37.DisplayCode AS BasicOption15, Lookup37.UserDescription AS BasicOption15Desc, Lookup38.DisplayCode AS BasicOption16, 
    Lookup38.UserDescription AS BasicOption16Desc, Lookup39.DisplayCode AS BasicOption17, Lookup39.UserDescription AS BasicOption17Desc, 
    Lookup40.DisplayCode AS BasicOption18, Lookup40.UserDescription AS BasicOption18Desc, Lookup41.DisplayCode AS BasicOption19, 
    Lookup41.UserDescription AS BasicOption19Desc, Lookup42.DisplayCode AS BasicOption2, Lookup42.UserDescription AS BasicOption2Desc, 
    Lookup43.DisplayCode AS BasicOption3, Lookup43.UserDescription AS BasicOption3Desc, Lookup44.DisplayCode AS BasicOption4, 
    Lookup44.UserDescription AS BasicOption4Desc, Lookup45.DisplayCode AS BasicOption5, Lookup45.UserDescription AS BasicOption5Desc, 
    Lookup46.DisplayCode AS BasicOption6, Lookup46.UserDescription AS BasicOption6Desc, Lookup47.DisplayCode AS BasicOption7, 
    Lookup47.UserDescription AS BasicOption7Desc, Lookup48.DisplayCode AS BasicOption8, Lookup48.UserDescription AS BasicOption8Desc, 
    Lookup49.DisplayCode AS BasicOption9, Lookup49.UserDescription AS BasicOption9Desc, dbo.AB_Abstract.BatchNumber, 
    Lookup50.DisplayCode AS BatchPeriod, Lookup50.UserDescription AS BatchPeriodDesc, dbo.AB_Abstract.BatchYear, 
    Lookup51.DisplayCode AS Between210DaysPostOp, Lookup51.UserDescription AS Between210DaysPostOpDesc, dbo.AB_Abstract.BirthDate, 
    Lookup52.DisplayCode AS BreastFeedingonDischarge, Lookup52.UserDescription AS BreastFeedingonDischargeDesc, 
    dbo.LU_CareType.DisplayCode AS CareType, dbo.LU_CareType.UserDescription AS CareTypeDesc, Lookup53.DisplayCode AS ChangeinLegalStatus, 
    Lookup53.UserDescription AS ChangeinLegalStatusDesc, dbo.AB_Abstract.ChartNumber, LU_ChestCompressions.DisplayCode AS ChestCompressions,
    LU_ChestCompressions.UserDescription AS ChestCompressionsDesc, dbo.AB_Abstract.ChiefComplaint AS ChiefComplaintUponAdmission, 
    dbo.AB_CancerStaging.ClinicalMetastasis, dbo.AB_CancerStaging.ClinicalNode, dbo.AB_CancerStaging.ClinicalTumor, 
    Lookup54.DisplayCode AS CoderNumber, Lookup54.UserDescription AS CoderNumberDesc, Lookup55.DisplayCode AS Complication, 
    Lookup55.UserDescription AS ComplicationDesc, Lookup56.DisplayCode AS Complication1, Lookup56.UserDescription AS Complication1Desc, 
    Lookup57.DisplayCode AS Complication2, Lookup57.UserDescription AS Complication2Desc, Lookup58.DisplayCode AS Complication3, 
    Lookup58.UserDescription AS Complication3Desc, Lookup58.DefaultDescription AS Complication3Desc_D, Lookup59.DisplayCode AS CoronerCase, 
    Lookup59.UserDescription AS CoronerCaseDesc, Lookup60.DisplayCode AS DataEntryCoder, Lookup60.UserDescription AS DataEntryCoderDesc, 
    dbo.AB_ReproductiveCare.LastMensesDate AS DateofLastMenses, dbo.AB_Abstract.DateReadyDischarge AS DateReadyForDischarge, 
    dbo.AB_Abstract.CIHIDateSent AS DateSenttoCIHI, LU_Days_WeekAlcoholConsumed.DisplayCode AS Days_WeekAlcoholConsumed, 
    LU_Days_WeekAlcoholConsumed.UserDescription AS Days_WeekAlcoholConsumedDesc, Lookup61.DisplayCode AS DeathInOR, 
    Lookup61.UserDescription AS DeathInORDesc, Lookup62.DisplayCode AS DeathInSCU, Lookup62.UserDescription AS DeathInSCUDesc, 
    dbo.AB_Manitoba.DeclarationNumber, dbo.AB_ReproductiveCare.DeliveryDate, dbo.AB_ReproductiveCare.DeliveryTime, 
    dbo.AB_Abstract.DischargeDate, 
    isnull(Lookup63.DisplayCode, LU_ExitCode.DisplayCode) AS DischargeDisposition, 
    isnull(Lookup63.UserDescription, LU_ExitCode.UserDescription) AS DischargeDispositionDesc, 
    Lookup64.DisplayCode AS DischNursingAreaUnitLocation, Lookup64.UserDescription AS DischargeNursingAreaUnitDesc, 
    Lookup65.DisplayCode AS DischargePlanning, Lookup65.UserDescription AS DischargePlanningDesc, dbo.AB_Abstract.DischargeTime, 
    dbo.AB_Manitoba.DrinksPerday, Lookup66.DisplayCode AS ECTTreatment, Lookup66.UserDescription AS ECTTreatmentDesc, 
    Lookup67.DisplayCode AS Education, Lookup67.UserDescription AS EducationDesc, LU_Elopements.DisplayCode AS Elopements, 
    LU_Elopements.UserDescription AS ElopementsDesc, dbo.AB_Manitoba.EmployerName, Lookup68.DisplayCode AS Employment, 
    Lookup68.UserDescription AS EmploymentDesc, dbo.AB_Abstract.EncounterNumber, Lookup69.DisplayCode AS EntryCode, 
    Lookup69.UserDescription AS EntryCodeDesc, dbo.AB_Abstract.DateLeftER AS ERDatePatientLeft, 
    dbo.AB_Abstract.DecisionAdmitDate AS ERDecisiontoAdmitDate, dbo.AB_Abstract.DecisionAdmitTime AS ERDecisiontoAdmitTime, 
    
    dbo.AB_Abstract.TimeLeftER AS ERTimePatientLeft, 
    LU_TimeLeftERUnknown.DisplayCode as ERTimePatientLeftUnknown, LU_TimeLeftERUnknown.UserDescription as ERTimePatientLeftUnknownDesc,
    
    LU_Feeding.DisplayCode AS Feeding, LU_Feeding.UserDescription AS FeedingDesc, 
    Lookup70.DisplayCode AS FinancialSupport, Lookup70.UserDescription AS FinancialSupportDesc, dbo.AB_Abstract.FinishDate, 
    dbo.AB_Abstract.FinishTime, dbo.AB_Abstract.FirstName, Lookup71.DisplayCode AS FirstOptionalTherapy, 
    Lookup71.UserDescription AS FirstOptionalTherapyDesc, dbo.AB_Therapeutic.FirstOptionUnits AS FirstOptionalUnits, 
    dbo.AB_Manitoba.FirstStageDuration, LU_FreeFlowOxygen.DisplayCode AS FreeFlowOxygen, 
    LU_FreeFlowOxygen.UserDescription AS FreeFlowOxygenDesc, Lookup72.DisplayCode AS Gender, Lookup72.UserDescription AS GenderDesc, 
    dbo.AB_Manitoba.Gestation, dbo.AB_ReproductiveCare.GestationalAge AS GestationalAgeinweeks, Lookup73.DisplayCode AS GlasgowComaScale, 
    Lookup73.UserDescription AS GlasgowComaScaleDesc, dbo.AB_Manitoba.Gravida, Lookup74.DisplayCode AS Greaterthan10DaysPostOp, 
    Lookup74.UserDescription AS Greaterthan10DaysPostOpDesc, Lookup75.DisplayCode AS HCNProvince, 
    Lookup75.UserDescription AS HCNProvinceDesc, dbo.AB_Abstract.HCNVersion, dbo.AB_Abstract.HealthCareNumber, 
    dbo.H_HospitalProfile.DisplayCode AS Hospital, dbo.H_HospitalProfile.UserDescription AS HospitalDesc, dbo.AB_Abstract.ICDType, 
    Lookup76.DisplayCode AS InitialOR, Lookup76.UserDescription AS InitialORDesc, dbo.AB_Abstract.InputDate, dbo.AB_Abstract.InputTime, 
    Lookup77.InstCareType AS InstFromCareType, Lookup77.HospitalType AS InstFromHospType, 
    
    (case when AB_Abstract.ICDType = ''T'' then Lookup77.DisplayCode else LU_InstFrom_9.DisplayCode end) AS InstitutionFrom, 
    (case when AB_Abstract.ICDType = ''T'' then Lookup77.UserDescription else LU_InstFrom_9.UserDescription end) AS InstitutionFromDesc, 
    (case when AB_Abstract.ICDType = ''T'' then Lookup78.DisplayCode else LU_InstTo_9.DisplayCode end) AS InstitutionTo, 
    (case when AB_Abstract.ICDType = ''T'' then Lookup78.UserDescription else LU_InstTo_9.UserDescription end) AS InstitutionToDesc, 

    Lookup78.InstCareType AS InstToCareType, Lookup78.HospitalType AS InstToHospType, Lookup79.DisplayCode AS InterfaceCoder, 
    Lookup79.UserDescription AS InterfaceCoderDesc, dbo.AB_Abstract.InterfaceDate, dbo.AB_Abstract.InterfaceTime, 
    LU_IntubationNotMeconium.DisplayCode AS IntubationNotMeconium, LU_IntubationNotMeconium.UserDescription AS IntubationNotMeconiumDesc, 
    Lookup80.DisplayCode AS IsAbstractCompleted, Lookup80.UserDescription AS IsAbstractCompletedDesc, 
    Lookup81.DisplayCode AS IsAbstractCorrected, Lookup81.UserDescription AS IsAbstractCorrectedDesc, Lookup82.DisplayCode AS IsAbstractDeleted, 
    Lookup82.UserDescription AS IsAbstractDeletedDesc, Lookup83.DisplayCode AS IsAbstractSubmited, 
    Lookup83.UserDescription AS IsAbstractSubmitedDesc, Lookup84.DisplayCode AS IsAbstractValidated, 
    Lookup84.UserDescription AS IsAbstractValidatedDesc, Lookup85.DisplayCode AS IsBirthdateEstimated, 
    Lookup85.UserDescription AS IsBirthdateEstimatedDesc, dbo.AB_Abstract.LastName, LU_LeaveCertificates.DisplayCode AS LeaveCertificates, 
    LU_LeaveCertificates.UserDescription AS LeaveCertificatesDesc, Lookup86.DisplayCode AS Lessthan2DaysAfterAdmission, 
    Lookup86.UserDescription AS Lessthan2DaysAfterAdmitDesc, Lookup87.DisplayCode AS Lessthan2DaysPostOp, 
    Lookup87.UserDescription AS Lessthan2DaysPostOpDesc, dbo.AB_Abstract.LOSDays, dbo.AB_Abstract.LOSMinutes, 
    dbo.AB_Abstract.LOSTime AS LOSTimeinHours, dbo.AB_Abstract.MaidenName, Lookup88.DisplayCode AS MaritalStatus, 
    Lookup88.UserDescription AS MaritalStatusDesc, dbo.AB_Abstract.NewbornChart AS MaternalNewbornChartNumber, 
    dbo.AB_Abstract.NewbornDischargeDate AS MaternalNewbornDischargeDate, LU_MB_Autopsy.DisplayCode AS MB_Autopsy, 
    LU_MB_Autopsy.UserDescription AS MB_AutopsyDesc, dbo.AB_Manitoba.MB_Weight, LU_MBEducation.DisplayCode AS MBEducation, 
    LU_MBEducation.UserDescription AS MBEducationDesc, LU_Meconium.DisplayCode AS Meconium, 
    LU_Meconium.UserDescription AS MeconiumDesc, LU_MedicationResuscitation.DisplayCode AS MedicationResuscitation, 
    LU_MedicationResuscitation.UserDescription AS MedicationResuscitationDesc, Lookup89.DisplayCode AS MethodofAdmission, 
    Lookup89.UserDescription AS MethodofAdmissionDesc, LU_MHInstFrom.DisplayCode AS MHFacilityTransferFrom, 
    LU_MHInstFrom.UserDescription AS MHFacilityTransferFromDesc, LU_MHInstTo.DisplayCode AS MHFacilityTransferTo, 
    LU_MHInstTo.UserDescription AS MHFacilityTransferToDesc, dbo.AB_Abstract.MiddleName, dbo.AB_Manitoba.MotherPHIN, 
    ISNULL(dbo.AB_Abstract.LastName, '' '') + '', '' + ISNULL(dbo.AB_Abstract.FirstName, '''') + '' '' + ISNULL(dbo.AB_Abstract.MiddleName, '''') AS NameFull, 
    LU_NarconMaloxone.DisplayCode AS NarconMaloxone, LU_NarconMaloxone.UserDescription AS NarconMaloxoneDesc, 
    dbo.AB_MentalHealth.MentalNumberECT AS NumberofECT, Lookup90.DisplayCode AS OccupationalTherapy, 
    Lookup90.UserDescription AS OccupationalTherapyDesc, dbo.AB_Therapeutic.OccupationalUnits, Lookup92.DisplayCode AS OtherBlood, 
    Lookup92.UserDescription AS OtherBloodDesc, Lookup93.DisplayCode AS OtherBloodCrossMatched, 
    
    Lookup93.UserDescription AS OtherBloodCrossMatchedDesc, Lookup94.DisplayCode AS OtherBloodTyped, 
    Lookup94.UserDescription AS OtherBloodTypedDesc, dbo.AB_Blood.OtherBloodUnits, Lookup91.DisplayCode AS OtherMedicalDeath, 
    Lookup91.UserDescription AS OtherMedicalDeathDesc, dbo.AB_Manitoba.Parity, dbo.AB_CancerStaging.PathMetastasis AS PathologicalMetastasis, 
    dbo.AB_CancerStaging.PathNode AS PathologicalNode, dbo.AB_CancerStaging.PathTumor AS PathologicalTumor, 
    Lookup95.DisplayCode AS Physiotherapy, Lookup95.UserDescription AS PhysiotherapyDesc, dbo.AB_Therapeutic.PhysioUnits, 
    Lookup96.DisplayCode AS Plasma, Lookup96.UserDescription AS PlasmaDesc, Lookup97.DisplayCode AS PlasmaCrossMatched, 
    Lookup97.UserDescription AS PlasmaCrossMatchedDesc, Lookup98.DisplayCode AS PlasmaTyped, Lookup98.UserDescription AS PlasmaTypedDesc, 
    dbo.AB_Blood.PlasmaUnits, Lookup99.DisplayCode AS Platelets, Lookup99.UserDescription AS PlateletsDesc, 
    Lookup100.DisplayCode AS PlateletsCrossMatched, Lookup100.UserDescription AS PlateletsCrossMatchedDesc, 
    Lookup101.DisplayCode AS PlateletsTyped, Lookup101.UserDescription AS PlateletsTypedDesc, dbo.AB_Blood.PlateletsUnits, 
    dbo.AB_Abstract.PostalCode, LU_PostConceptionalFolicAcid.DisplayCode AS PostConceptionalFolicAcid, 
    LU_PostConceptionalFolicAcid.UserDescription AS PostConceptionalFolicAcidDesc, dbo.AB_Abstract.PostOpDays, 
    Lookup103.DisplayCode AS PreAdmitWorkup, Lookup103.UserDescription AS PreAdmitWorkupDesc, 
    LU_PreConceptionalFolicAcid.DisplayCode AS PreConceptionalFolicAcid, 
    LU_PreConceptionalFolicAcid.UserDescription AS PreConceptionalFolicAcidDesc, Lookup104.DisplayCode AS Pregnancy, 
    Lookup104.UserDescription AS PregnancyDesc, dbo.AB_Manitoba.PrenatalVisitDate, 
    LU_PrenatalVisitDateUnknown.DisplayCode AS PrenatalVisitDateUnknown, 
    LU_PrenatalVisitDateUnknown.UserDescription AS PrenatalVisitDateUnknownDesc, dbo.AB_Manitoba.NumberPrenatalVisits AS PrenatalVisitsNumber, 
    dbo.AB_Abstract.PreOpDays, LU_Presentation.DisplayCode AS Presentation, LU_Presentation.UserDescription AS PresentationDesc, 
    dbo.AB_Manitoba.PreviousName, Lookup105.DisplayCode AS PreviousPsychiartricAdmission, 
    Lookup105.UserDescription AS PreviousPsychiartricAdmDesc, dbo.AB_Manitoba.PrimaryAddress, dbo.AB_Manitoba.PrimaryAddress2, 
    dbo.AB_Manitoba.PrimaryPhone, 
    LU_Province.DisplayCode AS ProvinceNumber, LU_Province.UserDescription AS ProvinceNumberDesc,
    Lookup106.DisplayCode AS ReAdmitCode, Lookup106.UserDescription AS ReAdmitCodeDesc, 
    Lookup107.DisplayCode AS RedBloodCell, Lookup107.UserDescription AS RedBloodCellDesc, 
    Lookup108.DisplayCode AS RedBloodCellCrossMatched, Lookup108.UserDescription AS RedBloodCellCrossMatchedDesc, 
    Lookup109.DisplayCode AS RedBloodCellTyped, Lookup109.UserDescription AS RedBloodCellTypedDesc, 
    dbo.AB_Blood.RedCellUnits AS RedBloodCellUnits, Lookup110.DisplayCode AS ReferredTo, Lookup110.UserDescription AS ReferredToDesc, 
    dbo.AB_Abstract.RegisterNumber, dbo.AB_Manitoba.RegistrantFirstName AS RegistrantGivenName, 
    dbo.AB_Manitoba.RegistrantLastName AS RegistrantSurname, Lookup111.DisplayCode AS ReportingProvInstNumber, 
    Lookup111.UserDescription AS ReportingProvInstNumberDesc, dbo.AB_ReproductiveCare.ReprodComments AS ReproductiveCareComments, 
    Lookup112.DisplayCode AS ResidenceCode, Lookup112.UserDescription AS ResidenceCodeDesc, Lookup113.DisplayCode AS RespiratoryTherapy, 
    Lookup113.UserDescription AS RespiratoryTherapyDesc, dbo.AB_Therapeutic.RespiratoryUnits, Lookup114.DisplayCode AS ResponsiblityForPayment,
    Lookup114.UserDescription AS ResponsiblityForPaymentDesc, LU_RoutineCare.DisplayCode AS RoutineCare, 
    LU_RoutineCare.UserDescription AS RoutineCareDesc, dbo.AB_Abstract.SecondChartRegNumber AS SecondChartRegisterNumber, 
    Lookup115.DisplayCode AS SecondOptionalTherapy, Lookup115.UserDescription AS SecondOptionalTherapyDesc, 
    dbo.AB_Therapeutic.SecondOptionUnits AS SecondOptionalUnits, dbo.AB_Manitoba.SecondStageDuration, 
    Lookup116.DisplayCode AS SecretVIPPatient, Lookup116.UserDescription AS SecretVIPPatientDesc, Lookup117.DisplayCode AS SiteNumber, 
    Lookup117.UserDescription AS SiteNumberDesc, dbo.AB_Manitoba.SmokingPerDay, dbo.AB_Manitoba.SmokingQuitDate, 
    LU_SmokingQuitDateUnknown.DisplayCode AS SmokingQuitDateUnknown, 
    LU_SmokingQuitDateUnknown.UserDescription AS SmokingQuitDateUnknownDesc, Lookup118.DisplayCode AS SocialServices, 
    Lookup118.UserDescription AS SocialServicesDesc, Lookup119.DisplayCode AS SourceofReferral, 
    Lookup119.UserDescription AS SourceofReferralDesc, Lookup120.DisplayCode AS SpeechTherapy, 
    Lookup120.UserDescription AS SpeechTherapyDesc, dbo.AB_Therapeutic.SpeechUnits, LU_CodeFile_1.DisplayCode AS StakeholderType, 
    LU_CodeFile_1.UserDescription AS StakeholderTypeDesc, dbo.AB_Manitoba.FirstStageDate AS StartFirstStageDate, 
    LU_FirstStageDateUnknown.DisplayCode AS StartFirstStageDateUnknown, 
    LU_FirstStageDateUnknown.UserDescription AS StartFirstStageDateUnknownDes, dbo.AB_Manitoba.FirstStageTime AS StartFirstStageTime, 
    dbo.AB_Manitoba.SecondStageDate AS StartSecondStageDate, LU_SecondStageDateUnknown.DisplayCode AS StartSecondStageDateUnknown, 
    LU_SecondStageDateUnknown.UserDescription AS StartSecondStageDateUnknown_D, dbo.AB_Manitoba.SecondStageTime AS StartSecondStageTime, 

    Lookup121.DisplayCode AS Sterilization, 
    Lookup121.UserDescription AS SterilizationDesc, 

    dbo.AB_Abstract.RecordType AS SubmissionType, 
    Lookup122.DisplayCode AS SubsequentOR, Lookup122.UserDescription AS SubsequentORDesc, Lookup123.DisplayCode AS Suicide, 
    Lookup123.UserDescription AS SuicideDesc, dbo.AB_CancerStaging.SummaryStage, Lookup124.DisplayCode AS SurgicalCase, 
    Lookup124.UserDescription AS SurgicalCaseDesc, 
    Lookup125.DisplayCode AS TransfusionGiven, 
    Lookup125.UserDescription AS TransfusionGivenDesc, Lookup126.DisplayCode AS Trauma, Lookup126.UserDescription AS TraumaDesc, 
    Lookup127.DisplayCode AS TSICoder, Lookup127.UserDescription AS TSICoderDesc, dbo.AB_Abstract.TSIDate, dbo.AB_Abstract.TSITime, 
    dbo.AB_Abstract.UniqiueLifetimeID AS ULI, Lookup128.DisplayCode AS UnplannedReadmission, 
    Lookup128.UserDescription AS UnplannedReadmissionDesc, 
    dbo.AB_Abstract.WaitTimeER as WaitTimeInEmerg, dbo.AB_Abstract.Weight AS Weightingrams, 
    dbo.AB_Abstract.AbstractID AS zzAbstractLink, dbo.AB_Abstract.VolumeID AS zzVolumeLink
FROM         
     dbo.AB_Abstract with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_1 with (nolock) on LU_CodeFile_1.Code = dbo.AB_Abstract.StakeHolder LEFT OUTER JOIN
    dbo.AB_Manitoba with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Manitoba.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Meconium with (nolock) on LU_Meconium.Code = dbo.AB_Manitoba.Meconium LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Feeding with (nolock) on dbo.AB_Manitoba.Feeding = LU_Feeding.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_ChestCompressions with (nolock) on dbo.AB_Manitoba.ChestCompressions = LU_ChestCompressions.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_NarconMaloxone with (nolock) on dbo.AB_Manitoba.NarconMaloxone = LU_NarconMaloxone.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_MedicationResuscitation with (nolock) on dbo.AB_Manitoba.MedicationResuscitation = LU_MedicationResuscitation.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_IntubationNotMeconium with (nolock) on dbo.AB_Manitoba.IntubationNotMeconium = LU_IntubationNotMeconium.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_BagVentilation with (nolock) on dbo.AB_Manitoba.BagVentilation = LU_BagVentilation.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_FreeFlowOxygen with (nolock) on dbo.AB_Manitoba.FreeFlowOxygen = LU_FreeFlowOxygen.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_RoutineCare with (nolock) on dbo.AB_Manitoba.RoutineCare = LU_RoutineCare.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Presentation with (nolock) on dbo.AB_Manitoba.Presentation = LU_Presentation.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_SecondStageDateUnknown with (nolock) on dbo.AB_Manitoba.SecondStageDateUnknown = LU_SecondStageDateUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_FirstStageDateUnknown with (nolock) on dbo.AB_Manitoba.FirstStageDateUnknown = LU_FirstStageDateUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PostConceptionalFolicAcid with (nolock) on dbo.AB_Manitoba.PostConceptionalFolicAcid = LU_PostConceptionalFolicAcid.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PreConceptionalFolicAcid with (nolock) on dbo.AB_Manitoba.PreConceptionalFolicAcid = LU_PreConceptionalFolicAcid.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Days_WeekAlcoholConsumed with (nolock) on dbo.AB_Manitoba.Days_WeekAlcoholConsumed = LU_Days_WeekAlcoholConsumed.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_AlcoholDuringPregnancy with (nolock) on dbo.AB_Manitoba.AlcoholDuringPregnancy = LU_AlcoholDuringPregnancy.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_SmokingQuitDateUnknown with (nolock) on dbo.AB_Manitoba.SmokingQuitDateUnknown = LU_SmokingQuitDateUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_MBEducation with (nolock) on dbo.AB_Manitoba.ObsEducation = LU_MBEducation.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PrenatalVisitDateUnknown with (nolock) on dbo.AB_Manitoba.PrenatalVisitDateUnknown = LU_PrenatalVisitDateUnknown.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_LeaveCertificates with (nolock) on dbo.AB_Manitoba.LeaveCertificates = LU_LeaveCertificates.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_Elopements with (nolock) on dbo.AB_Manitoba.Elopements = LU_Elopements.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_MB_Autopsy with (nolock) on dbo.AB_Manitoba.MB_Autopsy = LU_MB_Autopsy.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_MHInstTo with (nolock) on dbo.AB_Manitoba.MHInstTo = LU_MHInstTo.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_MHInstFrom with (nolock) on dbo.AB_Manitoba.MHInstFrom = LU_MHInstFrom.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_AbstractType with (nolock) on dbo.AB_Manitoba.AbstractType = LU_AbstractType.Code LEFT OUTER JOIN 
    dbo.LU_CareType with (nolock) on dbo.AB_Abstract.CareType = dbo.LU_CareType.Code LEFT OUTER JOIN
    dbo.LU_AbstractOverflow Lookup2 with (nolock) on dbo.AB_Abstract.AbstractOverflow = Lookup2.Code LEFT OUTER JOIN
    dbo.LU_AdmitAmbulance Lookup3 with (nolock) on dbo.AB_Abstract.AdmitAmbulance = Lookup3.Code LEFT OUTER JOIN
    dbo.LU_AdmitCategory Lookup4 with (nolock) on dbo.AB_Abstract.AdmitCategory = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_NurseArea Lookup5 with (nolock) on dbo.AB_Abstract.AdmittingNurseArea = Lookup5.Code LEFT OUTER JOIN
    dbo.LU_AgeCode Lookup6 with (nolock) on dbo.AB_Abstract.AgeCode = Lookup6.Code LEFT OUTER JOIN
    dbo.LU_AgeCode Lookup7 with (nolock) on dbo.AB_Abstract.DischargeAgeCode = Lookup7.Code LEFT OUTER JOIN
    dbo.LU_Provider Lookup28 with (nolock) on dbo.AB_Abstract.AttendingPhysician = Lookup28.Code LEFT OUTER JOIN
    dbo.LU_BatchPeriod Lookup50 with (nolock) on dbo.AB_Abstract.BatchPeriod = Lookup50.Code LEFT OUTER JOIN
    dbo.U_Users Lookup54 with (nolock) on dbo.AB_Abstract.CoderNumber = Lookup54.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup55 with (nolock) on dbo.AB_Abstract.Complication = Lookup55.Code LEFT OUTER JOIN
    dbo.U_Users Lookup60 with (nolock) on dbo.AB_Abstract.DataEntryCoder = Lookup60.Code LEFT OUTER JOIN
    dbo.LU_DispositionCode_I Lookup63 with (nolock) on dbo.AB_Abstract.DispositionCode = Lookup63.Code LEFT OUTER JOIN
    dbo.LU_NurseArea Lookup64 with (nolock) on dbo.AB_Abstract.DischargeNurseArea = Lookup64.Code LEFT OUTER JOIN
    dbo.LU_TherDischPlan Lookup65 with (nolock) on dbo.AB_Abstract.DischargePlanning = Lookup65.Code LEFT OUTER JOIN
    dbo.LU_EntryCode Lookup69 with (nolock) on dbo.AB_Abstract.EntryCode = Lookup69.Code LEFT OUTER JOIN
    dbo.LU_Gender_I Lookup72 with (nolock) on dbo.AB_Abstract.Gender = Lookup72.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup73 with (nolock) on dbo.AB_Abstract.GlasgowComaScale = Lookup73.Code LEFT OUTER JOIN
    dbo.LU_HCNProvince Lookup75 with (nolock) on dbo.AB_Abstract.HCNProvince = Lookup75.Code LEFT OUTER JOIN

    dbo.LU_Institution_10 Lookup77 with (nolock) on dbo.AB_Abstract.InstitutionFrom = Lookup77.Code LEFT OUTER JOIN
    dbo.LU_Institution_9 LU_InstFrom_9 with (nolock) on dbo.AB_Abstract.InstitutionFrom = LU_InstFrom_9.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 Lookup78 with (nolock) on dbo.AB_Abstract.InstitutionTo = Lookup78.Code LEFT OUTER JOIN
    dbo.LU_Institution_9 LU_InstTo_9 with (nolock) on dbo.AB_Abstract.InstitutionTo = LU_InstTo_9.Code LEFT OUTER JOIN

    dbo.U_Users Lookup79 with (nolock) on dbo.AB_Abstract.InterfaceCoder = Lookup79.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus Lookup80 with (nolock) on dbo.AB_Abstract.IsCompleted = Lookup80.Code LEFT OUTER JOIN
    dbo.LU_CIHICorrect Lookup81 with (nolock) on dbo.AB_Abstract.IsCorrected = Lookup81.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem Lookup82 with (nolock) on dbo.AB_Abstract.IsDeleted = Lookup82.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem Lookup83 with (nolock) on dbo.AB_Abstract.IsSubmited = Lookup83.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus Lookup84 with (nolock) on dbo.AB_Abstract.IsValidated = Lookup84.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup85 with (nolock) on dbo.AB_Abstract.BirthDateEstimated = Lookup85.Code LEFT OUTER JOIN
    dbo.LU_MaritalStatus Lookup88 with (nolock) on dbo.AB_Abstract.MaritalStatus = Lookup88.Code LEFT OUTER JOIN
    dbo.LU_TherPreAdmitWorkUp Lookup103 with (nolock) on dbo.AB_Abstract.PreAdmitWorkUp = Lookup103.Code LEFT OUTER JOIN
    dbo.LU_ReAdmitCode Lookup106 with (nolock) on dbo.AB_Abstract.ReAdmitCode = Lookup106.Code LEFT OUTER JOIN
    dbo.H_InstitutionProfile Lookup111 with (nolock) on dbo.AB_Abstract.InstitutionNumber = Lookup111.Code LEFT OUTER JOIN

    dbo.LU_ResidenceCode Lookup112 with (nolock) on dbo.AB_Abstract.ResidenceCode = Lookup112.Code LEFT OUTER JOIN
    dbo.LU_RespPayment Lookup114 with (nolock) on dbo.AB_Abstract.ResponsiblePayment = Lookup114.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup116 with (nolock) on dbo.AB_Abstract.Secret = Lookup116.Code LEFT OUTER JOIN
    dbo.LU_Site Lookup117 with (nolock) on dbo.AB_Abstract.SiteNumber = Lookup117.Code LEFT OUTER JOIN
    dbo.LU_TherSocialService Lookup118 with (nolock) on dbo.AB_Abstract.SocialService = Lookup118.Code LEFT OUTER JOIN
    dbo.LU_SurgicalCode Lookup124 with (nolock) on dbo.AB_Abstract.SurgicalCase = Lookup124.Code LEFT OUTER JOIN
    dbo.U_Users Lookup127 with (nolock) on dbo.AB_Abstract.TSICoder = Lookup127.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup128 with (nolock) on dbo.AB_Abstract.UnplanReAdmit = Lookup128.Code LEFT OUTER JOIN
    dbo.AB_Ancillary with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Ancillary.AbstractID LEFT OUTER JOIN
    dbo.LU_Ancillary1 Lookup11 with (nolock) on dbo.AB_Ancillary.AncillaryField1 = Lookup11.Code LEFT OUTER JOIN
    dbo.LU_Ancillary10 Lookup12 with (nolock) on dbo.AB_Ancillary.AncillaryField10 = Lookup12.Code LEFT OUTER JOIN
    dbo.LU_Ancillary11 Lookup13 with (nolock) on dbo.AB_Ancillary.AncillaryField11 = Lookup13.Code LEFT OUTER JOIN
    dbo.LU_Ancillary12 Lookup14 with (nolock) on dbo.AB_Ancillary.AncillaryField12 = Lookup14.Code LEFT OUTER JOIN
    dbo.LU_Ancillary13 Lookup15 with (nolock) on dbo.AB_Ancillary.AncillaryField13 = Lookup15.Code LEFT OUTER JOIN
    dbo.LU_Ancillary14 Lookup16 with (nolock) on dbo.AB_Ancillary.AncillaryField14 = Lookup16.Code LEFT OUTER JOIN
    dbo.LU_Ancillary15 Lookup17 with (nolock) on dbo.AB_Ancillary.AncillaryField15 = Lookup17.Code LEFT OUTER JOIN
    dbo.LU_Ancillary16 Lookup18 with (nolock) on dbo.AB_Ancillary.AncillaryField16 = Lookup18.Code LEFT OUTER JOIN
    dbo.LU_Ancillary17 Lookup19 with (nolock) on dbo.AB_Ancillary.AncillaryField17 = Lookup19.Code LEFT OUTER JOIN
    dbo.LU_Ancillary2 Lookup20 with (nolock) on dbo.AB_Ancillary.AncillaryField2 = Lookup20.Code LEFT OUTER JOIN
    dbo.LU_Ancillary3 Lookup21 with (nolock) on dbo.AB_Ancillary.AncillaryField3 = Lookup21.Code LEFT OUTER JOIN
    dbo.LU_Ancillary4 Lookup22 with (nolock) on dbo.AB_Ancillary.AncillaryField4 = Lookup22.Code LEFT OUTER JOIN
    dbo.LU_Ancillary5 Lookup23 with (nolock) on dbo.AB_Ancillary.AncillaryField5 = Lookup23.Code LEFT OUTER JOIN
    dbo.LU_Ancillary6 Lookup24 with (nolock) on dbo.AB_Ancillary.AncillaryField6 = Lookup24.Code LEFT OUTER JOIN
    dbo.LU_Ancillary7 Lookup25 with (nolock) on dbo.AB_Ancillary.AncillaryField7 = Lookup25.Code LEFT OUTER JOIN
    dbo.LU_Ancillary8 Lookup26 with (nolock) on dbo.AB_Ancillary.AncillaryField8 = Lookup26.Code LEFT OUTER JOIN
    dbo.LU_Ancillary9 Lookup27 with (nolock) on dbo.AB_Ancillary.AncillaryField9 = Lookup27.Code LEFT OUTER JOIN
    dbo.AB_BasicOption with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_BasicOption.AbstractID LEFT OUTER JOIN
    dbo.LU_BasicOption1 Lookup31 with (nolock) on dbo.AB_BasicOption.BasicOption1 = Lookup31.Code LEFT OUTER JOIN
    dbo.LU_BasicOption10 Lookup32 with (nolock) on dbo.AB_BasicOption.BasicOption10 = Lookup32.Code LEFT OUTER JOIN
    dbo.LU_BasicOption11 Lookup33 with (nolock) on dbo.AB_BasicOption.BasicOption11 = Lookup33.Code LEFT OUTER JOIN
    dbo.LU_BasicOption12 Lookup34 with (nolock) on dbo.AB_BasicOption.BasicOption12 = Lookup34.Code LEFT OUTER JOIN
    dbo.LU_BasicOption13 Lookup35 with (nolock) on dbo.AB_BasicOption.BasicOption13 = Lookup35.Code LEFT OUTER JOIN
    dbo.LU_BasicOption14 Lookup36 with (nolock) on dbo.AB_BasicOption.BasicOption14 = Lookup36.Code LEFT OUTER JOIN
    dbo.LU_BasicOption15 Lookup37 with (nolock) on dbo.AB_BasicOption.BasicOption15 = Lookup37.Code LEFT OUTER JOIN
    dbo.LU_BasicOption16 Lookup38 with (nolock) on dbo.AB_BasicOption.BasicOption16 = Lookup38.Code LEFT OUTER JOIN
    dbo.LU_BasicOption17 Lookup39 with (nolock) on dbo.AB_BasicOption.BasicOption17 = Lookup39.Code LEFT OUTER JOIN
    dbo.LU_BasicOption18 Lookup40 with (nolock) on dbo.AB_BasicOption.BasicOption18 = Lookup40.Code LEFT OUTER JOIN
    dbo.LU_BasicOption19 Lookup41 with (nolock) on dbo.AB_BasicOption.BasicOption19 = Lookup41.Code LEFT OUTER JOIN
    dbo.LU_BasicOption2 Lookup42 with (nolock) on dbo.AB_BasicOption.BasicOption2 = Lookup42.Code LEFT OUTER JOIN
    dbo.LU_BasicOption3 Lookup43 with (nolock) on dbo.AB_BasicOption.BasicOption3 = Lookup43.Code LEFT OUTER JOIN
    dbo.LU_BasicOption4 Lookup44 with (nolock) on dbo.AB_BasicOption.BasicOption4 = Lookup44.Code LEFT OUTER JOIN
    dbo.LU_BasicOption5 Lookup45 with (nolock) on dbo.AB_BasicOption.BasicOption5 = Lookup45.Code LEFT OUTER JOIN
    dbo.LU_BasicOption6 Lookup46 with (nolock) on dbo.AB_BasicOption.BasicOption6 = Lookup46.Code LEFT OUTER JOIN
    dbo.LU_BasicOption7 Lookup47 with (nolock) on dbo.AB_BasicOption.BasicOption7 = Lookup47.Code LEFT OUTER JOIN
    dbo.LU_BasicOption8 Lookup48 with (nolock) on dbo.AB_BasicOption.BasicOption8 = Lookup48.Code LEFT OUTER JOIN
    dbo.LU_BasicOption9 Lookup49 with (nolock) on dbo.AB_BasicOption.BasicOption9 = Lookup49.Code LEFT OUTER JOIN
    dbo.AB_Blood with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Blood.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup8 with (nolock) on dbo.AB_Blood.Albumin = Lookup8.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup9 with (nolock) on dbo.AB_Blood.AlbuminXMatch = Lookup9.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup10 with (nolock) on dbo.AB_Blood.AlbuminTyped = Lookup10.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup29 with (nolock) on dbo.AB_Blood.AutoTransfusion = Lookup29.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup92 with (nolock) on dbo.AB_Blood.OtherBlood = Lookup92.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup93 with (nolock) on dbo.AB_Blood.OtherBloodXMatch = Lookup93.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup94 with (nolock) on dbo.AB_Blood.OtherBloodTyped = Lookup94.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup96 with (nolock) on dbo.AB_Blood.Plasma = Lookup96.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup97 with (nolock) on dbo.AB_Blood.PlasmaXMatch = Lookup97.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup98 with (nolock) on dbo.AB_Blood.PlasmaTyped = Lookup98.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup99 with (nolock) on dbo.AB_Blood.Platelets = Lookup99.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup100 with (nolock) on dbo.AB_Blood.PlateletsXMatch = Lookup100.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup101 with (nolock) on dbo.AB_Blood.PlateletsTyped = Lookup101.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup107 with (nolock) on dbo.AB_Blood.RedBloodCell = Lookup107.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup108 with (nolock) on dbo.AB_Blood.RedCellXMatch = Lookup108.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup109 with (nolock) on dbo.AB_Blood.RedCellTyped = Lookup109.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup125 with (nolock) on dbo.AB_Blood.TransfusionIndicator = Lookup125.Code LEFT OUTER JOIN
    dbo.AB_DeathInformation with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_DeathInformation.AbstractID LEFT OUTER JOIN
    dbo.LU_AutopsyDeath Lookup30 with (nolock) on dbo.AB_DeathInformation.AutopsyPerformed = Lookup30.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup51 with (nolock) on dbo.AB_DeathInformation.DeathTwoTenPO = Lookup51.Code LEFT OUTER JOIN
    dbo.LU_CoronerCase Lookup59 with (nolock) on dbo.AB_DeathInformation.CoronerCase = Lookup59.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup61 with (nolock) on dbo.AB_DeathInformation.DeathInOR = Lookup61.Code LEFT OUTER JOIN
    dbo.LU_SCU_Death Lookup62 with (nolock) on dbo.AB_DeathInformation.DeathInSCU = Lookup62.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup74 with (nolock) on dbo.AB_DeathInformation.DeathGreaterTenPO = Lookup74.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup86 with (nolock) on dbo.AB_DeathInformation.DeathAfterAdmit = Lookup86.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup87 with (nolock) on Lookup87.Code = dbo.AB_DeathInformation.DeathLessTwoPO LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup91 with (nolock) on dbo.AB_DeathInformation.OtherDeath = Lookup91.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup104 with (nolock) on Lookup104.Code = dbo.AB_DeathInformation.PregnancyDeath LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup126 with (nolock) on dbo.AB_DeathInformation.TraumaDeath = Lookup126.Code LEFT OUTER JOIN
    dbo.AB_MentalHealth with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_MentalHealth.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup1 with (nolock) on dbo.AB_MentalHealth.MentalAWOL = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_MentalLegalStatus Lookup53 with (nolock) on dbo.AB_MentalHealth.MentalLegalStatus = Lookup53.Code LEFT OUTER JOIN
    dbo.LU_YesNoNumeric Lookup66 with (nolock) on Lookup66.Code = dbo.AB_MentalHealth.MentalECTTreatment LEFT OUTER JOIN
    dbo.LU_MentalEducation Lookup67 with (nolock) on dbo.AB_MentalHealth.MentalEducation = Lookup67.Code LEFT OUTER JOIN
    dbo.LU_MentalEmployment Lookup68 with (nolock) on dbo.AB_MentalHealth.MentalEmployment = Lookup68.Code LEFT OUTER JOIN
    dbo.LU_MentalFinancial Lookup70 with (nolock) on Lookup70.Code = dbo.AB_MentalHealth.MentalFinancial LEFT OUTER JOIN
    dbo.LU_MentalAdmitMethod Lookup89 with (nolock) on dbo.AB_MentalHealth.MentalAdmitMethod = Lookup89.Code LEFT OUTER JOIN
    dbo.LU_MentalPrevPsych Lookup105 with (nolock) on dbo.AB_MentalHealth.MentalPrevPsych = Lookup105.Code LEFT OUTER JOIN
    dbo.LU_MentalReferral Lookup110 with (nolock) on dbo.AB_MentalHealth.MentalReferralTo = Lookup110.Code LEFT OUTER JOIN
    dbo.LU_MentalReferral Lookup119 with (nolock) on dbo.AB_MentalHealth.MentalReferralSource = Lookup119.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup123 with (nolock) on dbo.AB_MentalHealth.MentalSuicide = Lookup123.Code LEFT OUTER JOIN 
    dbo.AB_Therapeutic with (nolock) on dbo.AB_Therapeutic.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
    dbo.LU_TherOption1 Lookup71 with (nolock) on dbo.AB_Therapeutic.FirstOptionTherapy = Lookup71.Code LEFT OUTER JOIN
    dbo.LU_TherOccupation Lookup90 with (nolock) on dbo.AB_Therapeutic.OccupationalTherapy = Lookup90.Code LEFT OUTER JOIN
    dbo.LU_TherPhysio Lookup95 with (nolock) on dbo.AB_Therapeutic.PhysioTherapy = Lookup95.Code LEFT OUTER JOIN
    dbo.LU_TherRespiratory Lookup113 with (nolock) on dbo.AB_Therapeutic.RespiratoryTherapy = Lookup113.Code LEFT OUTER JOIN
    dbo.LU_TherOption2 Lookup115 with (nolock) on dbo.AB_Therapeutic.SecondOptionTherapy = Lookup115.Code LEFT OUTER JOIN
    dbo.LU_TherSpeech Lookup120 with (nolock) on Lookup120.Code = dbo.AB_Therapeutic.SpeechTherapy LEFT OUTER JOIN
    dbo.AB_ReproductiveCare with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_ReproductiveCare.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup52 with (nolock) on dbo.AB_ReproductiveCare.BreastFeeding = Lookup52.Code LEFT OUTER JOIN
    dbo.LU_ReprodComplication Lookup56 with (nolock) on dbo.AB_ReproductiveCare.Complication1 = Lookup56.Code LEFT OUTER JOIN
    dbo.LU_ReprodComplication Lookup57 with (nolock) on dbo.AB_ReproductiveCare.Complication2 = Lookup57.Code LEFT OUTER JOIN
    dbo.LU_ReprodComplication Lookup58 with (nolock) on dbo.AB_ReproductiveCare.Complication3 = Lookup58.Code LEFT OUTER JOIN
    dbo.LU_ReprodOR Lookup76 with (nolock) on Lookup76.Code = dbo.AB_ReproductiveCare.InitialOR LEFT OUTER JOIN

    dbo.LU_ReprodSterilization Lookup121 with (nolock) on Lookup121.Code = dbo.AB_ReproductiveCare.Sterilization LEFT OUTER JOIN

    dbo.LU_ReprodOR Lookup122 with (nolock) on dbo.AB_ReproductiveCare.SubsequentOR = Lookup122.Code LEFT OUTER JOIN
    dbo.AB_CancerStaging with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_CancerStaging.AbstractID LEFT OUTER JOIN
    dbo.H_HospitalProfile with (nolock) on dbo.AB_Abstract.HospitalID = dbo.H_HospitalProfile.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_TimeLeftERUnknown with (nolock) on dbo.AB_Abstract.TimeLeftERUnknown = LU_TimeLeftERUnknown.Code LEFT OUTER JOIN
    dbo.LU_ExitCode with (nolock) on LU_ExitCode.Code = AB_Abstract.ExitCode LEFT OUTER JOIN
    dbo.LU_Province with (nolock) on LU_Province.Code = AB_Abstract.ProvinceNumber
Where AB_Abstract.CareType in (1, 2)
--QA - 00032 disable the domain securite issue
----PR - 07485
--    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB_ABstract.HospitalID is null or AB_ABstract.HospitalID = 0
--    --EN - 00666
--        or Is_Member(nullif(ReportGroup, '''')) = 1)
----        or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB_ABstract.HospitalID, 0))

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_CMG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE   VIEW [dbo].[DAD_CMG_VR]
AS
SELECT     
    dbo.AB_CMG.AcuteQuartile AS Acute_Quartile, 
    dbo.AB_CMG.CMG, 
    dbo.AB_CMG.CMG_Description, 
    dbo.AB_CMG.CMG_ELOS, 
    dbo.AB_CMG.CMG_Split, 
    dbo.AB_CMG.CMG_Year, 
    dbo.AB_CMG.Complexity, 
    dbo.CMG_LU_Complexity.UserDescription AS Complexity_Description, 
    (case AB_Abstract.ICDType when ''T'' then dbo.ICD_DiagFile10.DisplayCode
                              when ''9'' then dbo.ICD_DiagFile9.DisplayCode
                              when ''C'' then dbo.ICD_DiagFile9cm.DisplayCode
     end) AS Diagnosis_Code, 
    (case AB_Abstract.ICDType when ''T'' then dbo.ICD_DiagFile10.UserDescription
                              when ''9'' then dbo.ICD_DiagFile9.UserDescription
                              when ''C'' then dbo.ICD_DiagFile9cm.UserDescription
     end) AS Diagnosis_Description, 
    ICD_DiagFile10.ShortDescription as Diagnosis_CodeShortDesc,
    dbo.LU_DiagnosisType.DisplayCode AS Diagnosis_Type, 
    dbo.LU_DiagnosisType.UserDescription AS Diagnosis_Type_Desc, 
    dbo.AB_CMG.CMGFiftiethPercent AS FiftiethPercentile, 
    dbo.AB_CMG.ICD_Type, 
    dbo.AB_CMG.MCC, 
    dbo.CMG_LU_MCCDescription.UserDescription AS MCC_Description, 
    dbo.AB_CMG.MCC_Surg, 
    dbo.AB_CMG.CMGModelType AS ModelType, 
    dbo.AB_CMG.MOHQuartile AS MOH_Quartile, 
    dbo.AB_CMG.MOH_Dollar, dbo.AB_CMG.MOH_RIW, 
    dbo.AB_CMG.OccurrenceNumber AS Occurrence_Number, 
    dbo.AB_CMG.CMG_RIW AS RIW, 
    dbo.AB_CMG.RIW_Dollar, 
    dbo.AB_CMG.CMGTenthPercent AS TenthPercentile, 
    dbo.AB_CMG.CMG_Trim AS [Trim], 
    dbo.AB_CMG.CMGTwentyFifthPercent AS TwentyFifthPercentile, 
    dbo.AB_CMG.AbstractID AS zzAbstractLink
FROM AB_Abstract with (nolock) inner join 
    dbo.AB_CMG with (nolock) on AB_Abstract.AbstractID = AB_CMG.AbstractID LEFT JOIN 
    dbo.CMG_LU_Complexity with (nolock) on dbo.CMG_LU_Complexity.DisplayCode = dbo.AB_CMG.Complexity LEFT OUTER JOIN
    dbo.CMG_LU_MCCDescription with (nolock) on dbo.AB_CMG.MCC = dbo.CMG_LU_MCCDescription.DisplayCode LEFT OUTER JOIN
    dbo.ICD_DiagFile10 with (nolock) on dbo.AB_CMG.Diagnosis_Code = dbo.ICD_DiagFile10.Code LEFT OUTER JOIN
    dbo.ICD_DiagFile9 with (nolock) on dbo.AB_CMG.Diagnosis_Code = dbo.ICD_DiagFile9.Code LEFT OUTER JOIN
    dbo.ICD_DiagFile9cm with (nolock) on dbo.AB_CMG.Diagnosis_Code = dbo.ICD_DiagFile9cm.Code LEFT OUTER JOIN
    dbo.LU_DiagnosisType with (nolock) on dbo.AB_CMG.Diagnosis_Type = dbo.LU_DiagnosisType.Code
Where AB_Abstract.CareType = 1 







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE     VIEW [dbo].[DAD_Diagnosis_VR]
AS
SELECT  
    (case AB_Abstract.ICDType 
        when ''T'' then dbo.ICD_DiagFile10.DisplayCode 
        when ''9'' then dbo.ICD_DiagFile9.DisplayCode 
        when ''C'' then dbo.ICD_DiagFile9cm.DisplayCode 
     end) AS DiagnosisCode, 
    (case AB_Abstract.ICDType 
        when ''T'' then dbo.ICD_DiagFile10.UserDescription 
        when ''9'' then dbo.ICD_DiagFile9.UserDescription 
        when ''C'' then dbo.ICD_DiagFile9cm.UserDescription 
     end) AS DiagnosisCodeDesc, 
    ICD_DiagFile10.ShortDescription as DiagnosisCodeShortDesc,
    (case AB_Abstract.ICDType when ''T'' then dbo.ICD_DiagFile10.ICD9cm end) AS DiagnosisICD9cmEquivalent, 
    (case AB_Abstract.ICDType when ''T'' then dbo.ICD_DiagFile10.ICD9 end) AS DiagnosisICD9Equivalent, 
    dbo.AB_Diagnosis.DiagnosisOccurrence, 
    Lookup1.DisplayCode AS DiagnosisPrefix, 
    Lookup1.UserDescription AS DiagnosisPrefixDesc, 
    Lookup2.DisplayCode AS DiagnosisType, 
    Lookup2.UserDescription AS DiagnosisTypeDesc, 
    dbo.AB_Diagnosis.AbstractID AS zzAbstractLink
FROM dbo.AB_Diagnosis with (nolock) INNER JOIN
    dbo.AB_Abstract with (nolock) on dbo.AB_Diagnosis.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
    dbo.ICD_DiagFile10 with (nolock) on dbo.AB_Diagnosis.DiagnosisCode = dbo.ICD_DiagFile10.Code LEFT OUTER JOIN
    dbo.ICD_DiagFile9 with (nolock) on dbo.AB_Diagnosis.DiagnosisCode = dbo.ICD_DiagFile9.Code LEFT OUTER JOIN
    dbo.ICD_DiagFile9cm with (nolock) on dbo.AB_Diagnosis.DiagnosisCode = dbo.ICD_DiagFile9cm.Code LEFT OUTER JOIN
    dbo.LU_DiagnosisPrefix Lookup1 with (nolock) on dbo.AB_Diagnosis.DiagnosisPrefix = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_DiagnosisType Lookup2 with (nolock) on dbo.AB_Diagnosis.DiagnosisType = Lookup2.Code
Where AB_Abstract.CareType in (1, 2)

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_DPG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE  view [dbo].[DAD_DPG_VR]
as
select 
    DPGOccurrence = dpg.OccurrenceNumber, 
    DPG_Year, 
    DPG, 
    DPG_RIW, 
    DPG_MOH_RIW, 
    DPG_Description, 
    zzAbstractLink = dpg.AbstractID
from AB_DPG dpg with (nolock) 
    Inner join AB_Abstract with (nolock) on dpg.AbstractID = AB_Abstract.AbstractID
where AB_Abstract.Caretype = 2

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_Interventions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE    VIEW [dbo].[DAD_Interventions_VR]
AS
SELECT     
    Lookup1.DisplayCode AS AnaestheticTechnique, 
    Lookup1.UserDescription AS AnaestheticTechniqueDesc, 
    Lookup2.DisplayCode AS AnaesthetistID, 
    Lookup2.UserDescription AS AnaesthetistIDDesc, 
    Lookup3.DisplayCode AS EUL, 
    Lookup3.UserDescription AS EULDesc, 
    Lookup4.DisplayCode AS Extra, 
    Lookup4.UserDescription AS ExtraDesc, 
    Lookup5.DisplayCode AS IntervAttribExtent, 
    Lookup5.UserDescription AS IntervAttribExtentDesc, 
    Lookup6.DisplayCode AS IntervAttribLocation, 
    Lookup6.UserDescription AS IntervAttribLocationDesc, 
    Lookup7.DisplayCode AS IntervAttribStatus, 
    Lookup7.UserDescription AS IntervAttribStatusDesc, 
    (case AB_Abstract.ICDType 
        when ''T'' then dbo.ICD_ProcFile10.DisplayCode 
        when ''9'' then dbo.ICD_ProcFile9.DisplayCode 
        when ''C'' then dbo.ICD_ProcFile9CM.DisplayCode 
     end) AS IntervCode, 
    (case AB_Abstract.ICDType 
        when ''T'' then dbo.ICD_ProcFile10.UserDescription 
        when ''9'' then dbo.ICD_ProcFile9.UserDescription 
        when ''C'' then dbo.ICD_ProcFile9CM.UserDescription 
     end) AS IntervCodeDesc, 
    ICD_ProcFile10.ShortDescription as IntervCodeShortDesc,
    dbo.AB_Intervention.IntervDate, 
    dbo.AB_Intervention.IntervDateIn, 
    dbo.AB_Intervention.IntervDateOut, 
    (case AB_Abstract.ICDType when ''T'' then dbo.ICD_ProcFile10.ICD9 end) AS IntervICD9Equivalent, 
    (case AB_Abstract.ICDType when ''T'' then dbo.ICD_ProcFile10.ICD9cm end) AS IntervICD9cmEquivalent, 
    Lookup8.DisplayCode AS IntervLocation, 
    Lookup8.UserDescription AS IntervLocationDesc, 
    dbo.AB_Intervention.IntervOccurrence, 
    Lookup9.DisplayCode AS IntervProviderNumber, 
    Lookup9.UserDescription AS IntervProviderNumberDesc, 
    Lookup15.DisplayCode AS IntervProviderService, 
    Lookup15.UserDescription AS IntervProviderServiceDesc, 
    Lookup10.DisplayCode AS IntervProviderSpecialty, 
    Lookup10.UserDescription AS IntervProviderSpecialtyDesc, 
    dbo.AB_Intervention.IntervTimeIn, 
    dbo.AB_Intervention.IntervTimeMinutes AS IntervTimeinMinutes, 
    dbo.AB_Intervention.IntervTimeOut, 
    Lookup11.DisplayCode AS OOHIndicator, 
    Lookup11.UserDescription AS OOHIndicatorDesc, 
    (case when AB_Abstract.ICDType = ''T'' then Lookup12.DisplayCode 
          else LU_Institution_9.DisplayCode end) AS OOHInstitutionNumber, 
    (case when AB_Abstract.ICDType = ''T'' then Lookup12.UserDescription 
          else LU_Institution_9.UserDescription end) AS OOHInstitutionNumberDesc, 
    Lookup13.DisplayCode AS TissueCode, 
    Lookup13.UserDescription AS TissueCodeDesc, 
    Lookup14.DisplayCode AS UnplannedReturntoOR, 
    Lookup14.UserDescription AS UnplannedReturntoORDesc, 
    dbo.AB_Intervention.AbstractID AS zzAbstractLink
FROM  AB_Abstract with (nolock) inner join        
    dbo.AB_Intervention with (nolock) on AB_Abstract.AbstractID = AB_Intervention.AbstractID LEFT OUTER JOIN
    dbo.ICD_ProcFile10 with (nolock) on dbo.AB_Intervention.IntervCode = dbo.ICD_ProcFile10.Code LEFT OUTER JOIN
    dbo.ICD_ProcFile9 with (nolock) on dbo.AB_Intervention.IntervCode = dbo.ICD_ProcFile9.Code LEFT OUTER JOIN
    dbo.ICD_ProcFile9cm with (nolock) on dbo.AB_Intervention.IntervCode = dbo.ICD_ProcFile9cm.Code LEFT OUTER JOIN
    dbo.LU_AnaestTechnique Lookup1 with (nolock) on dbo.AB_Intervention.IntervAnaestTechnique = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_Provider Lookup2 with (nolock) on dbo.AB_Intervention.IntervAnaestID = Lookup2.Code LEFT OUTER JOIN
    dbo.LU_IntervEUL Lookup3 with (nolock) on dbo.AB_Intervention.IntervEUL = Lookup3.Code LEFT OUTER JOIN
    dbo.LU_IntervExtra Lookup4 with (nolock) on dbo.AB_Intervention.IntervExtra = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_IntervAttExtent Lookup5 with (nolock) on dbo.AB_Intervention.IntervAttribExtent = Lookup5.Code LEFT OUTER JOIN
    dbo.LU_IntervAttLocation Lookup6 with (nolock) on dbo.AB_Intervention.IntervAttribLocation = Lookup6.Code LEFT OUTER JOIN
    dbo.LU_IntervAttStatus Lookup7 with (nolock) on dbo.AB_Intervention.IntervAttribStatus = Lookup7.Code LEFT OUTER JOIN
    dbo.LU_IntervLocation_AI Lookup8 with (nolock) on dbo.AB_Intervention.IntervLocation = Lookup8.Code LEFT OUTER JOIN
    dbo.LU_Provider Lookup9 with (nolock) on dbo.AB_Intervention.IntervProviderNumber = Lookup9.Code LEFT OUTER JOIN
    dbo.LU_ProviderSpecialty Lookup10 with (nolock) on dbo.AB_Intervention.IntervProviderService = Lookup10.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup11 with (nolock) on dbo.AB_Intervention.IntervOOHIndicator = Lookup11.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 Lookup12 with (nolock) on dbo.AB_Intervention.IntervOOHInstitution = Lookup12.Code LEFT OUTER JOIN
    dbo.LU_Institution_9 with (nolock) on dbo.AB_Intervention.IntervOOHInstitution = LU_Institution_9.Code LEFT OUTER JOIN
    dbo.LU_IntervTissue Lookup13 with (nolock) on dbo.AB_Intervention.IntervTissueCode = Lookup13.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup14 with (nolock) on dbo.AB_Intervention.IntervUnplanReturn = Lookup14.Code LEFT OUTER JOIN
    dbo.LU_ProviderService Lookup15 with (nolock) on dbo.AB_Intervention.IntervProviderService = Lookup15.Code
Where   AB_Abstract.CareType in (1, 2)  









' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_MB_ALC_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[DAD_MB_ALC_VR]
AS 
SELECT     
    dbo.AB_MB_ALC.ALCDays, 
    dbo.AB_MB_ALC.Occurrence AS ALCOccurrence, 
    dbo.LU_CodeFile.DisplayCode AS ALCReasonCode, 
    dbo.LU_CodeFile.UserDescription AS ALCReasonCodeDesc, 
    dbo.AB_MB_ALC.DateDesignatedALC, dbo.AB_MB_ALC.DateReassignedAcute, 
    dbo.AB_MB_ALC.AbstractID AS zzAbstractLink
FROM dbo.AB_MB_ALC with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile with (nolock) on dbo.AB_MB_ALC.ALCReasonCode = dbo.LU_CodeFile.Code







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_MB_FacilityStudy_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[DAD_MB_FacilityStudy_VR]
AS 
SELECT     
    FacilityDateStudy, 
    FacilityStudyCode, 
    Occurrence AS FacilityStudyOccurrence, 
    AbstractID AS zzAbstractLink
FROM         dbo.AB_MB_FacilityStudy with (nolock)





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_MB_NonALC_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[DAD_MB_NonALC_VR]
AS 
SELECT     
    dbo.AB_MB_NonALC.DaysNonALCDelay, 
    dbo.LU_CodeFile.DisplayCode AS NonALCDelayReason, 
    dbo.LU_CodeFile.UserDescription AS NonALCDelayReasonDesc, 
    dbo.AB_MB_NonALC.Occurrence AS NonALCOccurrence, 
    dbo.AB_MB_NonALC.AbstractID AS zzAbstractLink
FROM dbo.AB_MB_NonALC with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile with (nolock) ON dbo.AB_MB_NonALC.NonALCDelayReason = dbo.LU_CodeFile.Code







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_PatientService_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE  VIEW [dbo].[DAD_PatientService_VR]
AS
SELECT     
    LEFT(Lookup1.DisplayCode, 2) AS PatientService, 
    Lookup1.DisplayCode AS PatientServiceSubService, 
    Lookup1.UserDescription AS PatientServiceSubServiceDesc, 
    dbo.AB_PatientService.ServiceDays AS PatientServiceDays, 
    dbo.AB_PatientService.ServiceOccurrence AS PatientServiceOccurrence, 
    Lookup2.DisplayCode AS PatientServiceType, 
    Lookup2.UserDescription AS PatientServiceTypeDesc, 
    Lookup3.DisplayCode AS ServiceNurseAreaUnitLoc, 
    Lookup3.UserDescription AS ServiceNursAreaUnitLocDesc, 
    dbo.AB_PatientService.ServiceNursingUnits, 
    dbo.AB_PatientService.ServiceTransferInDate AS TransferInDate, 
    dbo.AB_PatientService.ServiceTransferInTime AS TransferInTime, 
    dbo.AB_PatientService.ServiceTransferOutDate AS TransferOutDate, 
    dbo.AB_PatientService.ServiceTransferOutTime AS TransferOutTime, 
    dbo.AB_PatientService.AbstractID AS zzAbstractLink
FROM AB_Abstract with (nolock) inner join
    dbo.AB_PatientService with (nolock) on AB_PatientService.AbstractID = Ab_Abstract.AbstractID LEFT OUTER JOIN
    dbo.LU_PatientService Lookup1 with (nolock) on dbo.AB_PatientService.PatientService = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_PatientServiceType Lookup2 with (nolock) on dbo.AB_PatientService.ServiceType = Lookup2.Code LEFT OUTER JOIN
    dbo.LU_NurseArea Lookup3 with (nolock) on dbo.AB_PatientService.ServiceNursingArea = Lookup3.Code
Where AB_Abstract.CareType in (1, 2)






' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_Projects_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'





CREATE   VIEW [dbo].[DAD_Projects_VR]
AS
SELECT     
    Lookup1.DisplayCode AS ProjectNumber, 
    Lookup1.UserDescription AS ProjectNumberDesc, 
    dbo.AB_Project.ProjectOccurrence, 
    Lookup2.DisplayCode AS Question1,  Lookup2.UserDescription AS Question1Desc, 
    Lookup3.DisplayCode AS Question10, Lookup3.UserDescription AS Question10Desc, 
    Lookup4.DisplayCode AS Question11, Lookup4.UserDescription AS Question11Desc, 
    Lookup5.DisplayCode AS Question12, Lookup5.UserDescription AS Question12Desc, 
    Lookup6.DisplayCode AS Question13, Lookup6.UserDescription AS Question13Desc, 
    dbo.AB_Project.Question14, dbo.AB_Project.Question15, 
    dbo.AB_Project.Question16, dbo.AB_Project.Question17, 
    Lookup7.DisplayCode AS Question2,  Lookup7.UserDescription AS Question2Desc, 
    Lookup8.DisplayCode AS Question3,  Lookup8.UserDescription AS Question3Desc, 
    Lookup9.DisplayCode AS Question4,  Lookup9.UserDescription AS Question4Desc, 
    Lookup10.DisplayCode AS Question5, Lookup10.UserDescription AS Question5Desc, 
    Lookup11.DisplayCode AS Question6, Lookup11.UserDescription AS Question6Desc, 
    Lookup12.DisplayCode AS Question7, Lookup12.UserDescription AS Question7Desc, 
    Lookup13.DisplayCode AS Question8, Lookup13.UserDescription AS Question8Desc, 
    Lookup14.DisplayCode AS Question9, Lookup14.UserDescription AS Question9Desc, 
    dbo.AB_Project.AbstractID AS zzAbstractLink
FROM AB_Abstract with (nolock) inner join 
    dbo.AB_Project with (nolock) on AB_Abstract.AbstractID = AB_Project.AbstractID LEFT OUTER JOIN
    dbo.LU_Project Lookup1 with (nolock) on dbo.AB_Project.ProjectNumber = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1 Lookup2 with (nolock) on dbo.AB_Project.Question1 = Lookup2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 Lookup3 with (nolock) on dbo.AB_Project.Question10 = Lookup3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 Lookup4 with (nolock) on dbo.AB_Project.Question11 = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 Lookup5 with (nolock) on dbo.AB_Project.Question12 = Lookup5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 Lookup6 with (nolock) on dbo.AB_Project.Question13 = Lookup6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2 Lookup7 with (nolock) on dbo.AB_Project.Question2 = Lookup7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3 Lookup8 with (nolock) on dbo.AB_Project.Question3 = Lookup8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4 Lookup9 with (nolock) on dbo.AB_Project.Question4 = Lookup9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5 Lookup10 with (nolock) on dbo.AB_Project.Question5 = Lookup10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6 Lookup11 with (nolock) on dbo.AB_Project.Question6 = Lookup11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7 Lookup12 with (nolock) on dbo.AB_Project.Question7 = Lookup12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8 Lookup13 with (nolock) on dbo.AB_Project.Question8 = Lookup13.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9 Lookup14 with (nolock) on dbo.AB_Project.Question9 = Lookup14.Code
where AB_Abstract.CareType in (1, 2)






' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_Provider_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[DAD_Provider_VR]
AS
SELECT     
    Lookup1.DisplayCode AS ProviderNumber, 
    Lookup1.UserDescription AS ProviderNumberDesc, 
    dbo.AB_Provider.ProviderOccurrence, 
    dbo.LU_ProviderService.DisplayCode AS ProviderService, 
    dbo.LU_ProviderService.UserDescription AS ProviderServiceDesc, 
    Lookup3.DisplayCode AS ProviderType, 
    Lookup3.UserDescription AS ProviderTypeDesc, 
    dbo.AB_Provider.AbstractID AS zzAbstractLink
FROM AB_Abstract with (nolock) inner join         
    dbo.AB_Provider with (nolock) on AB_Abstract.AbstractID = AB_Provider.AbstractID LEFT OUTER JOIN
    dbo.LU_ProviderService with (nolock) on dbo.AB_Provider.ProviderService = dbo.LU_ProviderService.Code LEFT OUTER JOIN
    dbo.LU_Provider Lookup1 with (nolock) on dbo.AB_Provider.ProviderNumber = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_ProviderType Lookup3 with (nolock) on dbo.AB_Provider.ProviderType = Lookup3.Code
Where AB_Abstract.CareType in (1, 2)





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DAD_SpecialCareUnits_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE  VIEW [dbo].[DAD_SpecialCareUnits_VR]
AS
SELECT     
    dbo.AB_SpecialCareUnit.SCUAdmitDate AS SCUAdmissionDate, 
    dbo.AB_SpecialCareUnit.SCUAdmitTime AS SCUAdmissionTime, 
    (case AB_Abstract.ICDType when ''T'' then dbo.ICD_DiagFile10.DisplayCode 
                              when ''9'' then dbo.ICD_DiagFile10.DisplayCode 
                              when ''C'' then dbo.ICD_DiagFile10.DisplayCode 
     end) AS SCUDiagnosis, 
    (case AB_Abstract.ICDType when ''T'' then dbo.ICD_DiagFile10.UserDescription 
                              when ''9'' then dbo.ICD_DiagFile10.UserDescription 
                              when ''C'' then dbo.ICD_DiagFile10.UserDescription 
     end) AS SCUDiagnosisDesc, 
    ICD_DiagFile10.ShortDescription as DiagnosisCodeShortDesc,
    dbo.AB_SpecialCareUnit.SCUDischDate AS SCUDischargeDate, 
    dbo.AB_SpecialCareUnit.SCUDischTime AS SCUDischargeTime, 
    dbo.AB_SpecialCareUnit.SCULOS, dbo.AB_SpecialCareUnit.SCUHours, 
    Lookup1.DisplayCode AS SCUNumber, 
    Lookup1.UserDescription AS SCUNumberDesc, 
    dbo.AB_SpecialCareUnit.SCUOccurrence, 
    dbo.AB_SpecialCareUnit.AbstractID AS zzAbstractLink
FROM AB_Abstract with (nolock) inner join
    dbo.AB_SpecialCareUnit with (nolock) on AB_Abstract.AbstractID = AB_SpecialCareUnit.AbstractID LEFT OUTER JOIN
    dbo.ICD_DiagFile10 with (nolock) on dbo.AB_SpecialCareUnit.SCUDiagCode = dbo.ICD_DiagFile10.Code LEFT OUTER JOIN
    dbo.ICD_DiagFile9 with (nolock) on dbo.AB_SpecialCareUnit.SCUDiagCode = dbo.ICD_DiagFile9.Code LEFT OUTER JOIN
    dbo.ICD_DiagFile9cm with (nolock) on dbo.AB_SpecialCareUnit.SCUDiagCode = dbo.ICD_DiagFile9cm.Code LEFT OUTER JOIN
    dbo.LU_SCUNumber Lookup1 with (nolock) on dbo.AB_SpecialCareUnit.SCUNumber = Lookup1.Code
Where AB_Abstract.CareType in (1, 2)





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[EMT_Edits_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[EMT_Edits_VR]
AS 
select 
  [Edit Name] = e.EditName
, Module = CASE WHEN e.ModuleID IS NOT NULL THEN  dbo.EMT_GetModuleDescription(e.ModuleID) ELSE '''' END
, [Edit Rule severity] = CASE WHEN e.EditType IS NOT NULL THEN dbo.EMT_GetRuleSeverity(e.EditType) ELSE '''' END
, [Condition type to evaluate edit] = CASE WHEN e.RuleType IS NOT NULL Then dbo.EMT_GetConditionComparisonType(e.RuleType) ELSE '''' END
, [Message content] = e.MessageText
, [Valid From] =  e.ValidFrom
, [Valid To] = e.ValidTo
, zzEditLink = e.RuleID
from ENGN_Edit e with (nolock)
left join ENGN_FieldCondition fc on e.RuleID = fc.RecordID 
where e.IsDelete <> 1 and e.ModuleID in (200, 201, 202, 401) and e.RuleType = 1 --FieldConditions
union
select 
  [Edit Name] = e.EditName
, Module = CASE WHEN e.ModuleID IS NOT NULL THEN  dbo.EMT_GetModuleDescription(e.ModuleID) ELSE '''' END
, [Edit Rule severity] =  CASE WHEN e.EditType IS NOT NULL THEN dbo.EMT_GetRuleSeverity(e.EditType) ELSE '''' END
, [Condition type to evaluate edit] =  CASE WHEN e.RuleType IS NOT NULL Then dbo.EMT_GetConditionComparisonType(e.RuleType) ELSE '''' END
, [Message content] = e.MessageText
, [Valid From] =  e.ValidFrom
, [Valid To] = e.ValidTo
, zzEditLink = e.RuleID
from ENGN_Edit e with (nolock)
left join ENGN_LogicalCondition lc on e.RuleID = lc.RecordID 
where e.IsDelete <> 1 and e.ModuleID in (200, 201, 202, 401) and e.RuleType = 2 --LogicalConditions' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[EMT_FieldConditions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[EMT_FieldConditions_VR]
AS 
SELECT  
zzConditionLink = fc.RecordID
, Module = CASE WHEN fc.ModuleID IS NOT NULL THEN dbo.EMT_GetModuleDescription(fc.ModuleID) ELSE '''' END
, [Field Condition Name] = fc.EditName
, [Field 1] = CASE WHEN fc.Field1 IS NOT NULL AND isnumeric(replace(fc.Field1, ''FK'', '''')) = 1 THEN field1.Header_User
                           WHEN fc.Field1 IS NOT NULL AND isnumeric(replace(fc.Field1, ''FK'', '''')) = 0 THEN  dbo.EMT_GetGrouperHeader(fc.Field1)
                           ELSE '''' END
, [Use Field 1 occurrence] = CASE WHEN fc.OccType1 IS NOT NULL THEN dbo.EMT_GetFieldOccurrence (fc.OccType1) ELSE '''' END
, [Field 1 Occurrence Number] = CASE WHEN fc.OccType1 IS NOT NULL AND fc.OccType1 = 623 THEN convert(varchar, fc.Occurrence1, 50) ELSE ''n/a'' END
, [Field condition operator] =  CASE WHEN fc.OperatorType IS NOT NULL THEN dbo.EMT_GetFieldConditionOperator(fc.OperatorType) ELSE '''' END
, [Comparison Type] = CASE WHEN fc.CompareType IS NOT NULL THEN dbo.EMT_GetFieldComparisonType (fc.CompareType) ELSE '''' END
, [Field 1 Value] = fv.[FieldValue]
, [Field 1 Value Description] = fv.[FieldDescription]

, Field2 =    CASE WHEN fc.Field1  IS NOT NULL AND isnumeric(replace(fc.Field2, ''FK'', '''')) = 1 THEN field2.Header_User
                           WHEN field1.Header_User IS NOT NULL AND isnumeric(replace(fc.Field2, ''FK'', '''')) = 0 THEN dbo.EMT_GetGrouperHeader(fc.Field2)              
                     END
, [Use Field 2 occurence] = CASE WHEN fc.OccType2 IS NOT NULL THEN dbo.EMT_GetFieldOccurrence (fc.OccType2) ELSE '''' END
, [Field 2 Occurrence Number] = CASE WHEN fc.OccType2 IS NOT NULL AND fc.OccType1 = 623 THEN convert(varchar, fc.Occurrence2, 50) ELSE ''n/a'' END
, [Between From] = BetweenFrom
, [Between To] = BetweenTo 
from ENGN_FieldCondition fc with (nolock) 
left join ENGN_FieldValues fv on fc.RecordID = fv.RecordID and fc.ModuleID in (200, 201, 202, 401) 
left join dbo.U_UsersFields field1 with (nolock) 
        on field1.UserID = 1 and fc.ModuleID = field1.AppID and 
        (case when isnumeric(replace(fc.Field1, ''FK'', '''')) = 1 
              then replace(fc.Field1, ''FK'', '''')
              else 0 end) = field1.FieldID 
left join dbo.U_UsersFields field2 with (nolock) 
        on field2.UserID = 1 and fc.ModuleID = field2.AppID and 
        (case when isnumeric(replace(fc.Field2, ''FK'', '''')) = 1 
              then replace(fc.Field2, ''FK'', '''')
              else 0 end) = field2.FieldID 
where fc.IsDelete <> 1

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[EMT_Logical_Conditions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[EMT_Logical_Conditions_VR]
as
SELECT 
zzEditLink = lr.RecordID
, zzConditionLink = lr.RuleID
--, RegionID
--, HospitalID
, Module = CASE WHEN lc.ModuleID IS NOT NULL THEN dbo.EMT_GetModuleDescription(lc.ModuleID) ELSE '''' END
, [Logical Condition Name] = lc.EditName
, [Logical Operator] = CASE WHEN lc.OperatorType IS NOT NULL THEN convert(varchar, dbo.EMT_GetLogicalConditionOperator(lc.OperatorType), 50) ELSE '''' END
, [Same Occurrence (MultiForms)] = CASE WHEN lc.MultipleIndex IS NOT NULL THEN dbo.EMT_GetSameOccurrenceMultiFormDescription(lc.MultipleIndex, lc.ModuleID) ELSE NULL END
, [Condition Type] = CASE lr.RuleType 
						WHEN ''1'' THEN ''FLD''
						WHEN ''2'' THEN ''LOG''
					 END
, [Valid MultiForm Condition] = CASE WHEN lc.MultipleIndex IS NOT NULL THEN ''Y'' ELSE '''' END
, [Name] = fc.EditName
from ENGN_LogicalCondition lc with (nolock)
join ENGN_LogicalRules lr with (nolock) on lc.RecordID = lr.RecordID
join ENGN_FieldCondition fc with (nolock) on lr.RuleID = fc.RecordID
WHERE lc.IsDelete <> 1 and fc.IsDelete <> 1 and lc.ModuleID in (200, 201, 202, 401) 
union 
SELECT 
zzEditLink = lr.RuleID
,zzConditionLink = lr.RuleID
--, RegionID
--, HospitalID
, Module = CASE WHEN lc.ModuleID IS NOT NULL THEN dbo.EMT_GetModuleDescription(lc.ModuleID) ELSE '''' END
, [Logical Condition Name] = lc.EditName
, [Logical Operator] = CASE WHEN lc.OperatorType IS NOT NULL THEN convert(varchar, dbo.EMT_GetLogicalConditionOperator(lc.OperatorType), 50) ELSE '''' END
, [Same Occurrence (MultiForms)] = CASE WHEN lc.MultipleIndex IS NOT NULL THEN dbo.EMT_GetSameOccurrenceMultiFormDescription(lc.MultipleIndex, lc.ModuleID) ELSE NULL END
, [Condition Type] = CASE lr.RuleType 
						WHEN ''1'' THEN ''FLD''
						WHEN ''2'' THEN ''LOG''
					 END
, [Valid MultiForm Condition] = CASE WHEN lc.MultipleIndex IS NOT NULL THEN ''Y'' ELSE '''' END
, [Name] = lc2.EditName
from ENGN_LogicalCondition lc with (nolock)
join ENGN_LogicalRules lr with (nolock) on lc.RecordID = lr.RecordID
join ENGN_LogicalCondition lc2 with (nolock) on lr.RuleID = lc2.RecordID
WHERE lc.IsDelete <> 1 and lc2.IsDelete <> 1 and lc.ModuleID in (200, 201, 202, 401)

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Grouper_Audit_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[Grouper_Audit_VR]
AS
SELECT     DateGrouped, FieldChanged, GroupingYear, OldValue AS ValueOld, NewValue AS ValueNew, AbstractID AS zzAbstractLink
FROM         dbo.AB_GrouperAudit with (nolock)





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_CACS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_Abstract_CACS_VR]
AS
SELECT     dbo.AB_CACS.OccurrenceNumber, 
	dbo.AB_CACS.BatchGroupDate,
	dbo.AB_CACS.CACS_Year AS CACSYear, dbo.AB_CACS.MAC, 
        (case when dbo.AB_CACS.CACS_Year < 2011
              then
                  (CASE dbo.AB_CACS.MAC 
                        WHEN 1 THEN ''Diseases and Disorders of the Nervous System'' 
                        WHEN 2 THEN ''Diseases and Disorders of the Eye'' 
                        WHEN 3 THEN ''Diseases and Disorders of the Ear, Nose, Mouth and Throat'' 
                        WHEN 4 THEN ''Diseases and Disorders of the Respiratory System'' 
                        WHEN 5 THEN ''Diseases and Disorders of the Circulatory System'' 
                        WHEN 6 THEN ''Diseases and Disorders of the Digestive System'' 
                        WHEN 7 THEN ''Diseases and Disorders of the Hepatobiliary System and Pancreas''
                        WHEN 8 THEN ''Diseases and Disorders of the Musculoskeletal System and Connective Tissue'' 
                        WHEN 9 THEN ''Diseases and Disorders of the Skin and Subcutaneous Tissue and Breast''
                        WHEN 10 THEN ''Endocrine, Nutritional, and Metabolic Diseases and Disorders'' 
                        WHEN 11 THEN ''Diseases and Disorders of Kidney and Genitourinary Tract''
                        WHEN 14 THEN ''Pregnancy, Childbirth, Newborns and Neonates'' 
                        WHEN 16 THEN ''Haematology Including Lymphoma, Leukaemia and Unspecified Site Neoplasms''
                        WHEN 17 THEN ''Oncological Diseases and Disorders'' 
                        WHEN 18 THEN ''Systemic Infections Including HIV'' 
                        WHEN 19 THEN ''Mental Diseases and Disorders''
                        WHEN 20 THEN ''Examination and Other Health Factors'' 
                        WHEN 21 THEN ''Trauma, Coma and Toxic Effects'' 
                        WHEN 99 THEN ''Ungroupable'' ELSE '''' END)
              else 
                (select top 1 mac_long_e_desc from dbo.tGrouper_CACS_MAC where tGrouper_CACS_MAC.methodology_year = dbo.AB_CACS.CACS_Year and dbo.AB_CACS.MAC = tGrouper_CACS_MAC.mac_code)
              end) AS MACDescription, 
        dbo.AB_CACS.CACSCell, dbo.AB_CACS.ACW, dbo.AB_CACS.CACSDescription, 
        dbo.ICD_ProcFile10.DisplayCode AS InterventionCode, dbo.ICD_ProcFile10.UserDescription AS IntervCodeDescription, 
        dbo.ICD_ProcFile10.ShortDescription AS InterventionCodeShortDesc, 
        dbo.AB_CACS.AgeCategory, dbo.tGrouper_CACS_Age_Category.cacs_age_category_e_desc as AgeCategoryDesc,
        dbo.AB_CACS.AnaestheticCategory, dbo.tGrouper_CACS_Aanaesthetic.cacs_anaesthetic_e_desc as AnaestheticCategoryDesc,
        dbo.AB_CACS.MITTotalCount AS InvestigativeTechnologyTotalCount,
        ACW_HBAM as CACSHBAM,
        ACW_Base as CACSBaseRIW,
        CACSPartition, 
        MIT_Category_01 as InvestigativeTechnologyCategory_01, MIT_Category_Count_01 as InvestigativeTechnologyCategoryCount_01, 
        MIT_Category_02 as InvestigativeTechnologyCategory_02, MIT_Category_Count_02 as InvestigativeTechnologyCategoryCount_02, 
        MIT_Category_03 as InvestigativeTechnologyCategory_03, MIT_Category_Count_03 as InvestigativeTechnologyCategoryCount_03, 
        MIT_Category_04 as InvestigativeTechnologyCategory_04, MIT_Category_Count_04 as InvestigativeTechnologyCategoryCount_04, 
        MIT_Category_05 as InvestigativeTechnologyCategory_05, MIT_Category_Count_05 as InvestigativeTechnologyCategoryCount_05, 
        MIT_Category_06 as InvestigativeTechnologyCategory_06, MIT_Category_Count_06 as InvestigativeTechnologyCategoryCount_06, 
        MIT_Category_07 as InvestigativeTechnologyCategory_07, MIT_Category_Count_07 as InvestigativeTechnologyCategoryCount_07, 
        MIT_Category_08 as InvestigativeTechnologyCategory_08, MIT_Category_Count_08 as InvestigativeTechnologyCategoryCount_08, 
        MIT_Category_09 as InvestigativeTechnologyCategory_09, MIT_Category_Count_09 as InvestigativeTechnologyCategoryCount_09, 
        MIT_Category_10 as InvestigativeTechnologyCategory_10, MIT_Category_Count_10 as InvestigativeTechnologyCategoryCount_10,
        
        dbo.AB_Abstract.AbstractID AS zzAbstractLink
FROM    dbo.AB_CACS with (nolock) inner JOIN
		dbo.AB_Abstract with (nolock) ON dbo.AB_CACS.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
		dbo.ICD_ProcFile10 with (nolock) ON dbo.AB_CACS.InterventionCode = dbo.ICD_ProcFile10.Code LEFT OUTER JOIN
		dbo.tGrouper_CACS_Age_Category with (nolock) ON dbo.AB_CACS.AgeCategory = dbo.tGrouper_CACS_Age_Category.cacs_age_category_code
						and dbo.AB_CACS.CACS_Year = dbo.tGrouper_CACS_Age_Category.methodology_year LEFT OUTER JOIN
		dbo.tGrouper_CACS_Aanaesthetic with (nolock) ON dbo.AB_CACS.AnaestheticCategory = dbo.tGrouper_CACS_Aanaesthetic.cacs_anaesthetic_code
						and dbo.AB_CACS.CACS_Year = dbo.tGrouper_CACS_Aanaesthetic.methodology_year LEFT OUTER JOIN
        dbo.AB_CACS_Investigative with (nolock) ON 	AB_CACS.AbstractID = AB_CACS_Investigative.AbstractID
						and AB_CACS.OccurrenceNumber = AB_CACS_Investigative.OccurrenceNumber 
						and AB_CACS.CACS_Year = AB_CACS_Investigative.CACS_Year
WHERE  dbo.AB_Abstract.DischargeDate > ''2006/03/31'' AND (dbo.AB_Abstract.CareType = 2) AND (dbo.AB_CACS.OccurrenceNumber = 1)

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_CJRR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE view [dbo].[I10_Abstract_CJRR]
as
select
    Cement, LU_CJRR_Cement.UserDescription as CementDesc,
    CementOther, 
    CementProductNumber, 
    CementLotNumber,
    Occurrence as CJRROccurrence,      
    Component1, LU_CJRR_Component1.UserDescription as Component1Desc,
    Component2, LU_CJRR_Component2.UserDescription as Component2Desc,
    Component3, LU_CJRR_Component3.UserDescription as Component3Desc,
    JointIdentifier, 
    Side,  LU_CJRR_Side.UserDescription as SideDesc,
    AB_CJRR.AbstractID as zzAbstractLink
from dbo.AB_CJRR with (nolock)
    left join LU_CJRR_Side with (nolock) on AB_CJRR.Side = LU_CJRR_Side.CIHIValue
    left join LU_CJRR_Component LU_CJRR_Component1 with (nolock) on AB_CJRR.Component1 = LU_CJRR_Component1.CIHIValue
    left join LU_CJRR_Component LU_CJRR_Component2 with (nolock) on AB_CJRR.Component2 = LU_CJRR_Component2.CIHIValue
    left join LU_CJRR_Component LU_CJRR_Component3 with (nolock) on AB_CJRR.Component3 = LU_CJRR_Component3.CIHIValue
    left join LU_CJRR_Cement with (nolock) on AB_CJRR.Cement = LU_CJRR_Cement.CIHIValue
    

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_CJRR_Parts]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'create view [dbo].[I10_Abstract_CJRR_Parts]
as
select
    AB_CJRR_Parts.CJRROccurrence,
    AB_CJRR_Parts.ComponentOccurrence, 
    AB_CJRR_Parts.PartOccurrence,
    AB_CJRR_Parts.Manufacturer, LU_CJRR_Manufacturer.UserDescription as ManufacturerDesc,
    AB_CJRR_Parts.ManufacturerOther, 
    AB_CJRR_Parts.ProductNumber as ManufacturerProductNumber,
    AB_CJRR_Parts.LotNumber  as ManufacturerLotNumber,

    AB_CJRR_Parts.AbstractID as zzAbstractLink

from dbo.AB_CJRR_Parts with (nolock)
    left join LU_CJRR_Manufacturer with (nolock) on AB_CJRR_Parts.Manufacturer = LU_CJRR_Manufacturer.CIHIValue' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AbstractCIHIErrors_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[I10_AbstractCIHIErrors_VR]
AS
SELECT     AbstractNumber, BatchNumber, FiscalPeriod AS BatchPeriod, FiscalYear AS BatchYear, ChartNumber, CoderNumber, DischargeDate, ErrorFileName, 
                      ErrorMessage, ErrorNumber, FacilityNumber AS InstitutionNumber, GroupFieldOcc, ImportDateTime, OriginalData, TypeOfAbstract, TypeOfError, 
                      AbstractID AS zzAbstractLink
FROM         dbo.AB_CIHIErrors with (nolock)




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstracting]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE  VIEW [dbo].[I10_Abstracting]
AS
SELECT     dbo.AB_ReproductiveCare.PrevTermDelivery AS [#ofPreviousDeliveries], 
    dbo.AB_ReproductiveCare.PrevLiveBirths AS [#ofPreviousLiveBirths], 
    dbo.AB_ReproductiveCare.PrevPreTermDelivery AS [#ofPreviousPreTermDeliveries], 
    dbo.AB_ReproductiveCare.PrevSpontAbortions AS [#ofPrevSpontaneousAbortions], 
    dbo.AB_ReproductiveCare.PrevInduceAbortions AS [#ofPrevTherapueticAbortions], 
    --'''' AS AbstractNotes, PR - 05199
    dbo.AB_Abstract.AbstractNumber, 
    Lookup2.DisplayCode AS AbstractOverflow, Lookup2.UserDescription AS AbstractOverflowDesc, LU_AbstractType.DisplayCode AS AbstractType, 
    LU_AbstractType.UserDescription AS AbstractTypeDesc, dbo.AB_Abstract.AcuteLOS, dbo.AB_Abstract.AdmitDate AS AdmissionDate, 
    dbo.AB_Abstract.AdmitTime AS AdmissionTime, 
    --PR - 05489
    LU_AdmitTimeUnknown.DisplayCode as AdmissionTimeUnknown, LU_AdmitTimeUnknown.UserDescription as AdmissionTimeUnknownDesc,
    Lookup3.DisplayCode AS AdmitbyAmbulance, Lookup3.UserDescription AS AdmitbyAmbulanceDesc, 
    Lookup4.DisplayCode AS AdmitCategory, Lookup4.UserDescription AS AdmitCategoryDesc, Lookup5.DisplayCode AS AdmitNursingAreaUnitLocation, 
    Lookup5.UserDescription AS AdmittingNursingAreaUnitLDesc, Lookup6.DisplayCode AS AgeCode, Lookup6.UserDescription AS AgeCodeDesc, 
    dbo.AB_Abstract.AgeGroup, dbo.AB_Abstract.AgeNumber, dbo.AB_Abstract.DischargeAge AS AgeUponDischarge, 
    Lookup7.DisplayCode AS AgeUponDischargeCode, Lookup7.UserDescription AS AgeUponDischargeCodeDesc, Lookup8.DisplayCode AS Albumin, 
    Lookup9.DisplayCode AS AlbuminCrossMatched, Lookup9.UserDescription AS AlbuminCrossMatchedDesc, Lookup8.UserDescription AS AlbuminDesc, 
    Lookup10.DisplayCode AS AlbuminTyped, Lookup10.UserDescription AS AlbuminTypedDesc, dbo.AB_Blood.AlbuminUnits, dbo.AB_Abstract.ALCLOS, 
    LU_AlcoholDuringPregnancy.DisplayCode AS AlcoholDuringPregnancy, LU_AlcoholDuringPregnancy.UserDescription AS AlcoholDuringPregnancyDesc, 
    AlcoholQuitDate,
    LU_AlcoholQuitDateUnknown.DisplayCode AS AlcoholQuitDateUnknown, LU_AlcoholQuitDateUnknown.UserDescription AS AlcoholQuitDateUnknownDesc, 
    Lookup11.DisplayCode AS AncillaryField1, Lookup11.UserDescription AS AncillaryField1Desc, Lookup12.DisplayCode AS AncillaryField10, 
    Lookup12.UserDescription AS AncillaryField10Desc, Lookup13.DisplayCode AS AncillaryField11, Lookup13.UserDescription AS AncillaryField11Desc, 
    Lookup14.DisplayCode AS AncillaryField12, Lookup14.UserDescription AS AncillaryField12Desc, Lookup15.DisplayCode AS AncillaryField13, 
    Lookup15.UserDescription AS AncillaryField13Desc, Lookup16.DisplayCode AS AncillaryField14, Lookup16.UserDescription AS AncillaryField14Desc, 
    Lookup17.DisplayCode AS AncillaryField15, Lookup17.UserDescription AS AncillaryField15Desc, Lookup18.DisplayCode AS AncillaryField16, 
    Lookup18.UserDescription AS AncillaryField16Desc, Lookup19.DisplayCode AS AncillaryField17, Lookup19.UserDescription AS AncillaryField17Desc, 
    Lookup20.DisplayCode AS AncillaryField2, Lookup20.UserDescription AS AncillaryField2Desc, Lookup21.DisplayCode AS AncillaryField3, 
    Lookup21.UserDescription AS AncillaryField3Desc, Lookup22.DisplayCode AS AncillaryField4, Lookup22.UserDescription AS AncillaryField4Desc, 
    Lookup23.DisplayCode AS AncillaryField5, Lookup23.UserDescription AS AncillaryField5Desc, Lookup24.DisplayCode AS AncillaryField6, 
    Lookup24.UserDescription AS AncillaryField6Desc, Lookup25.DisplayCode AS AncillaryField7, Lookup25.UserDescription AS AncillaryField7Desc, 
    Lookup26.DisplayCode AS AncillaryField8, Lookup26.UserDescription AS AncillaryField8Desc, Lookup27.DisplayCode AS AncillaryField9, 
    Lookup27.UserDescription AS AncillaryField9Desc,
    --ED - 01750
    LU_AnestheticLabor.DisplayCode as AnalgesicAnestheticDuringLabor, LU_AnestheticLabor.UserDescription as AnalgesicAnestheticDuringLaborDesc,
    dbo.AB_Manitoba.Apgar1Min, dbo.AB_Manitoba.Apgar5Min, 
    dbo.AB_Abstract.ArrivalDate AS ArrivalDateInER, dbo.AB_Abstract.ArrivalTime AS ArrivalTimeInER, Lookup28.DisplayCode AS AttendingPhysician, 
    Lookup28.UserDescription AS AttendingPhysicianDesc, Lookup30.DisplayCode AS AutopsyPerformed, 
    Lookup30.UserDescription AS AutopsyPerformedDesc, Lookup29.DisplayCode AS AutoTransfusion, 
    Lookup29.UserDescription AS AutoTransfusionDesc, Lookup1.DisplayCode AS AWOL, Lookup1.UserDescription AS AWOLDesc, 
    LU_BagVentilation.DisplayCode AS BagVentilation, LU_BagVentilation.UserDescription AS BagVentilationDesc, 
    Lookup31.DisplayCode AS BasicOption1, Lookup31.UserDescription AS BasicOption1Desc, Lookup32.DisplayCode AS BasicOption10, 
    Lookup32.UserDescription AS BasicOption10Desc, Lookup33.DisplayCode AS BasicOption11, Lookup33.UserDescription AS BasicOption11Desc, 
    Lookup34.DisplayCode AS BasicOption12, Lookup34.UserDescription AS BasicOption12Desc, Lookup35.DisplayCode AS BasicOption13, 
    Lookup35.UserDescription AS BasicOption13Desc, Lookup36.DisplayCode AS BasicOption14, Lookup36.UserDescription AS BasicOption14Desc, 
    Lookup37.DisplayCode AS BasicOption15, Lookup37.UserDescription AS BasicOption15Desc, Lookup38.DisplayCode AS BasicOption16, 
    Lookup38.UserDescription AS BasicOption16Desc, Lookup39.DisplayCode AS BasicOption17, Lookup39.UserDescription AS BasicOption17Desc, 
    Lookup40.DisplayCode AS BasicOption18, Lookup40.UserDescription AS BasicOption18Desc, Lookup41.DisplayCode AS BasicOption19, 
    Lookup41.UserDescription AS BasicOption19Desc, Lookup42.DisplayCode AS BasicOption2, Lookup42.UserDescription AS BasicOption2Desc, 
    Lookup43.DisplayCode AS BasicOption3, Lookup43.UserDescription AS BasicOption3Desc, Lookup44.DisplayCode AS BasicOption4, 
    Lookup44.UserDescription AS BasicOption4Desc, Lookup45.DisplayCode AS BasicOption5, Lookup45.UserDescription AS BasicOption5Desc, 
    Lookup46.DisplayCode AS BasicOption6, Lookup46.UserDescription AS BasicOption6Desc, Lookup47.DisplayCode AS BasicOption7, 
    Lookup47.UserDescription AS BasicOption7Desc, Lookup48.DisplayCode AS BasicOption8, Lookup48.UserDescription AS BasicOption8Desc, 
    Lookup49.DisplayCode AS BasicOption9, Lookup49.UserDescription AS BasicOption9Desc, dbo.AB_Abstract.BatchNumber, 
    Lookup50.DisplayCode AS BatchPeriod, Lookup50.UserDescription AS BatchPeriodDesc, 

	LU_AntithrombinIII.DisplayCode AS Blood_AntithrombinIII, LU_AntithrombinIII.UserDescription AS Blood_AntithrombinIIIDesc,
	LU_C1Inhibitor.DisplayCode AS Blood_C1Inhibitor, LU_C1Inhibitor.UserDescription AS Blood_C1InhibitorDesc,
	LU_CryoprecipitatePlasma.DisplayCode AS Blood_CryoprecipitatePlasma, LU_CryoprecipitatePlasma.UserDescription AS Blood_CryoprecipitatePlasmaDesc,
	LU_CryosupernatantPlasma.DisplayCode AS Blood_CryosupernatantPlasma, LU_CryosupernatantPlasma.UserDescription AS Blood_CryosupernatantPlasmaDesc,
	LU_FEIBA.DisplayCode AS Blood_FEIBA, LU_FEIBA.UserDescription AS Blood_FEIBADesc,
	LU_Fibrinogen.DisplayCode AS Blood_Fibrinogen, LU_Fibrinogen.UserDescription AS Blood_FibrinogenDesc,
	LU_IVIG_SCIG.DisplayCode AS Blood_IVIG_SCIG, LU_IVIG_SCIG.UserDescription AS Blood_IVIG_SCIGDesc,
	LU_PCC.DisplayCode AS Blood_PCC, LU_PCC.UserDescription AS Blood_PCCDesc,
	LU_ProteinC_OtherFactors.DisplayCode AS Blood_ProteinC_OtherFactors, LU_ProteinC_OtherFactors.UserDescription AS Blood_ProteinC_OtherFactorsDesc,



    --PR - 06087
    BatchPeriod_BC = (case when left(Lookup111.CIHIValue, 1) <> ''9'' then null
                         when Lookup50.DisplayCode is not null then Lookup50.DisplayCode 
                         when DischargeDate is null then null
                         else (select top 1 DisplayCode from LU_BatchPeriod where DischargeDate between CIHIDateFrom and CIHIDateTo)
                    end),
    dbo.AB_Abstract.BatchYear, 
    Lookup51.DisplayCode AS Between210DaysPostOp, Lookup51.UserDescription AS Between210DaysPostOpDesc, dbo.AB_Abstract.BirthDate, 
    Lookup52.DisplayCode AS BreastFeedingonDischarge, Lookup52.UserDescription AS BreastFeedingonDischargeDesc, 
    dbo.LU_CareType.DisplayCode AS CareType, dbo.LU_CareType.UserDescription AS CareTypeDesc, Lookup53.DisplayCode AS ChangeinLegalStatus, 
    Lookup53.UserDescription AS ChangeinLegalStatusDesc, dbo.AB_Abstract.ChartNumber, LU_ChestCompressions.DisplayCode AS ChestCompressions,
    LU_ChestCompressions.UserDescription AS ChestCompressionsDesc, dbo.AB_Abstract.ChiefComplaint AS ChiefComplaintUponAdmission, 
    dbo.AB_CancerStaging.ClinicalMetastasis, dbo.AB_CancerStaging.ClinicalNode, dbo.AB_CancerStaging.ClinicalTumor, 
    Lookup54.DisplayCode AS CoderNumber, Lookup54.UserDescription AS CoderNumberDesc, Lookup55.DisplayCode AS Comorbidity, 
    Lookup55.UserDescription AS ComorbidityDesc, Lookup55.DisplayCode AS Complication, Lookup55.UserDescription AS ComplicationDesc, 
    Lookup56.DisplayCode AS Complication1, Lookup56.UserDescription AS Complication1Desc, Lookup57.DisplayCode AS Complication2, 
    Lookup57.UserDescription AS Complication2Desc, Lookup58.DisplayCode AS Complication3, Lookup58.UserDescription AS Complication3Desc, 
    Lookup58.DefaultDescription AS Complication3Desc_D, Lookup59.DisplayCode AS CoronerCase, Lookup59.UserDescription AS CoronerCaseDesc, 
    Lookup60.DisplayCode AS DataEntryCoder, Lookup60.UserDescription AS DataEntryCoderDesc, 
    dbo.AB_ReproductiveCare.LastMensesDate AS DateofLastMenses, dbo.AB_Abstract.DateReadyDischarge AS DateReadyForDischarge, 
    dbo.AB_Abstract.CIHIDateSent AS DateSenttoCIHI, LU_Days_WeekAlcoholConsumed.DisplayCode AS Days_WeekAlcoholConsumed, 
    LU_Days_WeekAlcoholConsumed.UserDescription AS Days_WeekAlcoholConsumedDesc, Lookup61.DisplayCode AS DeathInOR, 
    Lookup61.UserDescription AS DeathInORDesc, Lookup62.DisplayCode AS DeathInSCU, Lookup62.UserDescription AS DeathInSCUDesc, 
    dbo.AB_Manitoba.DeclarationNumber, dbo.AB_ReproductiveCare.DeliveryDate, dbo.AB_ReproductiveCare.DeliveryTime, 
    dbo.AB_Abstract.DischargeDate, Lookup63.DisplayCode AS DischargeDisposition, Lookup63.UserDescription AS DischargeDispositionDesc, 
    Lookup64.DisplayCode AS DischNursingAreaUnitLocation, Lookup64.UserDescription AS DischargeNursingAreaUnitDesc, 
    Lookup65.DisplayCode AS DischargePlanning, Lookup65.UserDescription AS DischargePlanningDesc, 
    dbo.AB_Abstract.DischargeTime, 
    --PR - 05489
    LU_DischargeTimeUnknown.DisplayCode AS DischargeTimeUnknown, LU_DischargeTimeUnknown.UserDescription AS DischargeTimeUnknownDesc, 

    dbo.AB_Manitoba.DrinksPerday, dbo.AB_Manitoba.ALC_TotalDays AS DurationALCDays, Lookup66.DisplayCode AS ECTTreatment, 
    Lookup66.UserDescription AS ECTTreatmentDesc, Lookup67.DisplayCode AS Education, Lookup67.UserDescription AS EducationDesc, 
    LU_Elopements.DisplayCode AS Elopements, LU_Elopements.UserDescription AS ElopementsDesc, dbo.AB_Manitoba.EmployerName, 
    Lookup68.DisplayCode AS Employment, Lookup68.UserDescription AS EmploymentDesc, dbo.AB_Abstract.EncounterNumber, 
    Lookup69.DisplayCode AS EntryCode, Lookup69.UserDescription AS EntryCodeDesc, dbo.AB_Abstract.DateLeftER AS ERDatePatientLeft, 
    dbo.AB_Abstract.DecisionAdmitDate AS ERDecisiontoAdmitDate, dbo.AB_Abstract.DecisionAdmitTime AS ERDecisiontoAdmitTime, 
    LU_DecAdmitTimeUnknown.DisplayCode AS ERDecisionAdmitTimeUnknown, 
    LU_DecAdmitTimeUnknown.UserDescription AS ERDecisionAdmitTimeUnknownDesc, dbo.AB_Abstract.TimeLeftER AS ERTimePatientLeft, 
    LU_TimeLeftERUnknown.DisplayCode AS ERTimePatientLeftUnknown, LU_TimeLeftERUnknown.UserDescription AS ERTimePatientLeftUnknownDesc, 
    LU_Feeding.DisplayCode AS Feeding, LU_Feeding.UserDescription AS FeedingDesc, Lookup70.DisplayCode AS FinancialSupport, 
    Lookup70.UserDescription AS FinancialSupportDesc, dbo.AB_Abstract.FinishDate, dbo.AB_Abstract.FinishTime, dbo.AB_Abstract.FirstName, 
    Lookup71.DisplayCode AS FirstOptionalTherapy, Lookup71.UserDescription AS FirstOptionalTherapyDesc, 
    dbo.AB_Therapeutic.FirstOptionUnits AS FirstOptionalUnits, dbo.AB_Manitoba.FirstStageDuration, 
    FixedChartNumber,
    LU_FreeFlowOxygen.DisplayCode AS FreeFlowOxygen, LU_FreeFlowOxygen.UserDescription AS FreeFlowOxygenDesc, 
    Lookup72.DisplayCode AS Gender, Lookup72.UserDescription AS GenderDesc, dbo.AB_Manitoba.Gestation, 
    dbo.AB_ReproductiveCare.GestationalAge AS GestationalAgeinweeks, Lookup73.DisplayCode AS GlasgowComaScale, 
    Lookup73.UserDescription AS GlasgowComaScaleDesc, dbo.AB_Manitoba.Gravida, Lookup74.DisplayCode AS Greaterthan10DaysPostOp, 
    Lookup74.UserDescription AS Greaterthan10DaysPostOpDesc, Lookup75.DisplayCode AS HCNProvince, 
    Lookup75.UserDescription AS HCNProvinceDesc, dbo.AB_Abstract.HCNVersion, dbo.AB_Abstract.HealthCareNumber, 
	AB_Abstract.Height,
    dbo.H_HospitalProfile.DisplayCode AS Hospital, dbo.H_HospitalProfile.UserDescription AS HospitalDesc, 
    dbo.AB_Abstract.HospitalAccountRecord,
    dbo.AB_Abstract.ICDType, 
    Lookup76.DisplayCode AS InitialOR, Lookup76.UserDescription AS InitialORDesc, dbo.AB_Abstract.InputDate, dbo.AB_Abstract.InputTime, 
    
	Lookup77.InstCareType AS InstFromCareType, Lookup77.HospitalType AS InstFromHospType, 
	Lookup77.DisplayCode AS InstitutionFrom, Lookup77.UserDescription AS InstitutionFromDesc, 
	LU_InstitutionFrom_Type.DisplayCode AS InstitutionFromType, LU_InstitutionFrom_Type.UserDescription AS InstitutionFromTypeDesc, 

	Lookup78.DisplayCode AS InstitutionTo, Lookup78.UserDescription AS InstitutionToDesc, 
	LU_InstitutionTo_Type.DisplayCode AS InstitutionToType, LU_InstitutionTo_Type.UserDescription AS InstitutionToTypeDesc, 
    Lookup78.InstCareType AS InstToCareType, Lookup78.HospitalType AS InstToHospType, 
	
	Lookup79.DisplayCode AS InterfaceCoder, 
    Lookup79.UserDescription AS InterfaceCoderDesc, dbo.AB_Abstract.InterfaceDate, dbo.AB_Abstract.InterfaceTime, 
    LU_IntubationNotMeconium.DisplayCode AS IntubationNotMeconium, LU_IntubationNotMeconium.UserDescription AS IntubationNotMeconiumDesc, 
    Lookup80.DisplayCode AS IsAbstractCompleted, Lookup80.UserDescription AS IsAbstractCompletedDesc, 
    Lookup81.DisplayCode AS IsAbstractCorrected, Lookup81.UserDescription AS IsAbstractCorrectedDesc, Lookup82.DisplayCode AS IsAbstractDeleted, 
    Lookup82.UserDescription AS IsAbstractDeletedDesc, Lookup83.DisplayCode AS IsAbstractSubmited, 
    Lookup83.UserDescription AS IsAbstractSubmitedDesc, Lookup84.DisplayCode AS IsAbstractValidated, 
    Lookup84.UserDescription AS IsAbstractValidatedDesc, 
	Lookup85.DisplayCode AS IsBirthdateEstimated,  Lookup85.UserDescription AS IsBirthdateEstimatedDesc, 
	LU_CustomStatus.DisplayCode AS IsCustomValidated, LU_CustomStatus.UserDescription AS IsCustomValidatedDesc, 

	dbo.AB_Abstract.LastName, LU_LeaveCertificates.DisplayCode AS LeaveCertificates, 
    LU_LeaveCertificates.UserDescription AS LeaveCertificatesDesc, Lookup86.DisplayCode AS Lessthan2DaysAfterAdmission, 
    Lookup86.UserDescription AS Lessthan2DaysAfterAdmitDesc, Lookup87.DisplayCode AS Lessthan2DaysPostOp, 
    Lookup87.UserDescription AS Lessthan2DaysPostOpDesc, dbo.AB_Abstract.LOSDays, dbo.AB_Abstract.LOSMinutes, 
    dbo.AB_Abstract.LOSTime AS LOSTimeinHours, dbo.AB_Abstract.MaidenName, Lookup88.DisplayCode AS MaritalStatus, 
    Lookup88.UserDescription AS MaritalStatusDesc, dbo.AB_Abstract.NewbornChart AS MaternalNewbornChartNumber, 
    dbo.AB_Abstract.NewbornDischargeDate AS MaternalNewbornDischargeDate, LU_MB_Autopsy.DisplayCode AS MB_Autopsy, 
    LU_MB_Autopsy.UserDescription AS MB_AutopsyDesc, 
	dbo.AB_Manitoba.MB_Weight, 
	LU_MBEducation.DisplayCode AS MBEducation, 
    LU_MBEducation.UserDescription AS MBEducationDesc, LU_Meconium.DisplayCode AS Meconium, 
    LU_Meconium.UserDescription AS MeconiumDesc, LU_MedicationResuscitation.DisplayCode AS MedicationResuscitation, 
    LU_MedicationResuscitation.UserDescription AS MedicationResuscitationDesc, 
	
	LU_MentalLegalStatusUponArrivalED.DisplayCode as MentalHealth_LegalStatusUponArrivaltoED, 
	LU_MentalLegalStatusUponArrivalED.UserDescription as MentalHealth_LegalStatusUponArrivaltoEDDesc,
	LU_MentalLegalStatusAdmission.DisplayCode as MentalHealth_LegalStatusAtAdmission, 
	LU_MentalLegalStatusAdmission.UserDescription as MentalHealth_LegalStatusAtAdmissionDesc,
	LU_MentalTypeRestraint_1.DisplayCode as MentalHealth_TypeOfRestraint_01,
	LU_MentalTypeRestraint_1.UserDescription as MentalHealth_TypeOfRestraint_01Desc,
	LU_MentalTypeRestraint_2.DisplayCode as MentalHealth_TypeOfRestraint_02,
	LU_MentalTypeRestraint_2.UserDescription as MentalHealth_TypeOfRestraint_02Desc,
	LU_MentalTypeRestraint_3.DisplayCode as MentalHealth_TypeOfRestraint_03,
	LU_MentalTypeRestraint_3.UserDescription as MentalHealth_TypeOfRestraint_03Desc,
	LU_MentalTypeRestraint_4.DisplayCode as MentalHealth_TypeOfRestraint_04,
	LU_MentalTypeRestraint_4.UserDescription as MentalHealth_TypeOfRestraint_04Desc,
	LU_MentalFrequencyRestraintUse_1.DisplayCode as MentalHealth_FrequencyOfRestraint_01,
	LU_MentalFrequencyRestraintUse_1.UserDescription as MentalHealth_FrequencyOfRestraint_01Desc,
	LU_MentalFrequencyRestraintUse_2.DisplayCode as MentalHealth_FrequencyOfRestraint_02,
	LU_MentalFrequencyRestraintUse_2.UserDescription as MentalHealth_FrequencyOfRestraint_02Desc,
	LU_MentalFrequencyRestraintUse_3.DisplayCode as MentalHealth_FrequencyOfRestraint_03,
	LU_MentalFrequencyRestraintUse_3.UserDescription as MentalHealth_FrequencyOfRestraint_03Desc,
	LU_MentalFrequencyRestraintUse_4.DisplayCode as MentalHealth_FrequencyOfRestraint_04,
	LU_MentalFrequencyRestraintUse_4.UserDescription as MentalHealth_FrequencyOfRestraint_04Desc,

	Lookup89.DisplayCode AS MethodofAdmission, Lookup89.UserDescription AS MethodofAdmissionDesc, LU_MHInstFrom.DisplayCode AS MHFacilityTransferFrom, 
    LU_MHInstFrom.UserDescription AS MHFacilityTransferFromDesc, LU_MHInstTo.DisplayCode AS MHFacilityTransferTo, 
    LU_MHInstTo.UserDescription AS MHFacilityTransferToDesc, dbo.AB_Abstract.MiddleName, dbo.AB_Manitoba.MotherPHIN, 
    ISNULL(dbo.AB_Abstract.LastName, '' '') + '', '' + ISNULL(dbo.AB_Abstract.FirstName, '''') + '' '' + ISNULL(dbo.AB_Abstract.MiddleName, '''') AS NameFull, 
    LU_NarconMaloxone.DisplayCode AS NarconMaloxone, LU_NarconMaloxone.UserDescription AS NarconMaloxoneDesc, 
    dbo.AB_MentalHealth.MentalNumberECT AS NumberofECT, Lookup90.DisplayCode AS OccupationalTherapy, 
    Lookup90.UserDescription AS OccupationalTherapyDesc, dbo.AB_Therapeutic.OccupationalUnits, Lookup92.DisplayCode AS OtherBlood, 
    Lookup92.UserDescription AS OtherBloodDesc, Lookup93.DisplayCode AS OtherBloodCrossMatched, 
    Lookup93.UserDescription AS OtherBloodCrossMatchedDesc, Lookup94.DisplayCode AS OtherBloodTyped, 
    Lookup94.UserDescription AS OtherBloodTypedDesc, dbo.AB_Blood.OtherBloodUnits, Lookup91.DisplayCode AS OtherMedicalDeath, 
    Lookup91.UserDescription AS OtherMedicalDeathDesc, 
    dbo.AB_Manitoba.HCNExpiredDate  as OutProvinceHealthInsuranceExpiryDate,
    dbo.AB_Manitoba.Parity, dbo.AB_CancerStaging.PathMetastasis AS PathologicalMetastasis, 
    dbo.AB_CancerStaging.PathNode AS PathologicalNode, dbo.AB_CancerStaging.PathTumor AS PathologicalTumor, 
    Lookup95.DisplayCode AS Physiotherapy, Lookup95.UserDescription AS PhysiotherapyDesc, dbo.AB_Therapeutic.PhysioUnits, 
    Lookup96.DisplayCode AS Plasma, Lookup96.UserDescription AS PlasmaDesc, Lookup97.DisplayCode AS PlasmaCrossMatched, 
    Lookup97.UserDescription AS PlasmaCrossMatchedDesc, Lookup98.DisplayCode AS PlasmaTyped, Lookup98.UserDescription AS PlasmaTypedDesc, 
    dbo.AB_Blood.PlasmaUnits, Lookup99.DisplayCode AS Platelets, Lookup99.UserDescription AS PlateletsDesc, 
    Lookup100.DisplayCode AS PlateletsCrossMatched, Lookup100.UserDescription AS PlateletsCrossMatchedDesc, 
    Lookup101.DisplayCode AS PlateletsTyped, Lookup101.UserDescription AS PlateletsTypedDesc, dbo.AB_Blood.PlateletsUnits, 
    dbo.AB_Abstract.PostalCode, 

    -- ED - 01682
    dbo.GetPostalDescription(isnull(dbo.AB_Abstract.PostalCode, ''''), isnull(dbo.AB_Abstract.DischargeDate, dbo.AB_Abstract.AdmitDate)) AS PostalCodeDesc, -- ED - 01682

    --PR - 03622
    LU_PositionDelviery.DisplayCode as PositionatDelivery, LU_PositionDelviery.UserDescription as PositionatDeliveryDesc, 

    LU_PostConceptionalFolicAcid.DisplayCode AS PostConceptionalFolicAcid, 
    LU_PostConceptionalFolicAcid.UserDescription AS PostConceptionalFolicAcidDesc, dbo.AB_Abstract.PostOpDays, 
    Lookup103.DisplayCode AS PreAdmitWorkup, Lookup103.UserDescription AS PreAdmitWorkupDesc, 
    LU_PreConceptionalFolicAcid.DisplayCode AS PreConceptionalFolicAcid, 
    LU_PreConceptionalFolicAcid.UserDescription AS PreConceptionalFolicAcidDesc, Lookup104.DisplayCode AS Pregnancy, 
    Lookup104.UserDescription AS PregnancyDesc, dbo.AB_Manitoba.PrenatalVisitDate, 
    LU_PrenatalVisitDateUnknown.DisplayCode AS PrenatalVisitDateUnknown, 
    LU_PrenatalVisitDateUnknown.UserDescription AS PrenatalVisitDateUnknownDesc, 
    --ED - 01702
    -- dbo.AB_Manitoba.NumberPrenatalVisits AS PrenatalVisitsNumber, 
    (case when isnull(DischargeDate, AdmitDate) < ''2008/04/01'' then dbo.AB_Manitoba.NumberPrenatalVisits else dbo.AB_Manitoba.NumberPrenatal end) AS PrenatalVisitsNumber, 

    dbo.AB_Abstract.PreOpDays, LU_Presentation.DisplayCode AS Presentation, LU_Presentation.UserDescription AS PresentationDesc, 
    --PR - 03622
    LU_PresentDelivery.DisplayCode as PresentationatDelivery, LU_PresentDelivery.UserDescription as PresentationatDeliveryDesc, 

    dbo.AB_Manitoba.PreviousName, Lookup105.DisplayCode AS PreviousPsychiartricAdmissions, 
    Lookup105.UserDescription AS PreviousPsychiartricAdmDesc, dbo.AB_Manitoba.PrimaryAddress, dbo.AB_Manitoba.PrimaryAddress2, 
    dbo.AB_Manitoba.PrimaryPhone, Lookup106.DisplayCode AS ReAdmitCode, Lookup106.UserDescription AS ReAdmitCodeDesc, 
    --PR - 04577
    LU_ReciprocalBillingStatus.DisplayCode AS ReciprocalBillingStatus, LU_ReciprocalBillingStatus.UserDescription AS ReciprocalBillingStatusDesc,

    Lookup107.DisplayCode AS RedBloodCell, Lookup107.UserDescription AS RedBloodCellDesc, 
    Lookup108.DisplayCode AS RedBloodCellCrossMatched, Lookup108.UserDescription AS RedBloodCellCrossMatchedDesc, 
    Lookup109.DisplayCode AS RedBloodCellTyped, Lookup109.UserDescription AS RedBloodCellTypedDesc, 
    dbo.AB_Blood.RedCellUnits AS RedBloodCellUnits, Lookup110.DisplayCode AS ReferredTo, Lookup110.UserDescription AS ReferredToDesc, 
    LU_RefProvider.DisplayCode AS ReferringProvider, LU_RefProvider.UserDescription AS ReferringProviderDesc, dbo.AB_Abstract.RegisterNumber, 
    dbo.AB_Manitoba.RegistrantFirstName AS RegistrantGivenName, dbo.AB_Manitoba.RegistrantLastName AS RegistrantSurname, 
    Lookup111.DisplayCode AS ReportingProvInstNumber, Lookup111.UserDescription AS ReportingProvInstNumberDesc, 
    dbo.AB_ReproductiveCare.ReprodComments AS ReproductiveCareComments, Lookup112.DisplayCode AS ResidenceCode, 
    Lookup112.UserDescription AS ResidenceCodeDesc, LUResidenceProvince.DisplayCode AS ResidenceProvince, 
    LUResidenceProvince.UserDescription AS ResidenceProvinceDesc, LUResidenceRegion.DisplayCode AS ResidenceRegion, 
    LUResidenceRegion.UserDescription AS ResidenceRegionDesc, Lookup113.DisplayCode AS RespiratoryTherapy, 
    Lookup113.UserDescription AS RespiratoryTherapyDesc, dbo.AB_Therapeutic.RespiratoryUnits, Lookup114.DisplayCode AS ResponsiblityForPayment,
    Lookup114.UserDescription AS ResponsiblityForPaymentDesc, LU_RoutineCare.DisplayCode AS RoutineCare, 
    LU_RoutineCare.UserDescription AS RoutineCareDesc, dbo.AB_Abstract.SecondChartRegNumber AS SecondChartRegisterNumber, 
    Lookup115.DisplayCode AS SecondOptionalTherapy, Lookup115.UserDescription AS SecondOptionalTherapyDesc, 
    dbo.AB_Therapeutic.SecondOptionUnits AS SecondOptionalUnits, dbo.AB_Manitoba.SecondStageDuration, 
    Lookup116.DisplayCode AS SecretVIPPatient, Lookup116.UserDescription AS SecretVIPPatientDesc, Lookup117.DisplayCode AS SiteNumber, 
    Lookup117.UserDescription AS SiteNumberDesc, 
    LU_SmokingInPregnancy.DisplayCode AS SmokingInPregnancy, LU_SmokingInPregnancy.UserDescription AS SmokingInPregnancyDesc, 
    dbo.AB_Manitoba.SmokingPerDay, dbo.AB_Manitoba.SmokingQuitDate, 
    LU_SmokingQuitDateUnknown.DisplayCode AS SmokingQuitDateUnknown, 
    LU_SmokingQuitDateUnknown.UserDescription AS SmokingQuitDateUnknownDesc, Lookup118.DisplayCode AS SocialServices, 
    Lookup118.UserDescription AS SocialServicesDesc, Lookup119.DisplayCode AS SourceofReferral, 
    Lookup119.UserDescription AS SourceofReferralDesc, Lookup120.DisplayCode AS SpeechTherapy, 
    Lookup120.UserDescription AS SpeechTherapyDesc, dbo.AB_Therapeutic.SpeechUnits, LU_CodeFile_1.DisplayCode AS StakeholderType, 
    LU_CodeFile_1.UserDescription AS StakeholderTypeDesc, dbo.AB_Manitoba.FirstStageDate AS StartFirstStageDate, 
    LU_FirstStageDateUnknown.DisplayCode AS StartFirstStageDateUnknown, 
    LU_FirstStageDateUnknown.UserDescription AS StartFirstStageDateUnknownDes, dbo.AB_Manitoba.FirstStageTime AS StartFirstStageTime, 
    dbo.AB_Manitoba.SecondStageDate AS StartSecondStageDate, LU_SecondStageDateUnknown.DisplayCode AS StartSecondStageDateUnknown, 
    LU_SecondStageDateUnknown.UserDescription AS StartSecondStageDateUnknown_D, dbo.AB_Manitoba.SecondStageTime AS StartSecondStageTime, 
    Lookup121.DisplayCode AS Sterilization, Lookup121.UserDescription AS SterilizationDesc, dbo.AB_Abstract.RecordType AS SubmissionType, 
    Lookup122.DisplayCode AS SubsequentOR, Lookup122.UserDescription AS SubsequentORDesc, Lookup123.DisplayCode AS Suicide, 
    Lookup123.UserDescription AS SuicideDesc, dbo.AB_CancerStaging.SummaryStage, Lookup124.DisplayCode AS SurgicalCase, 
    Lookup124.UserDescription AS SurgicalCaseDesc, Lookup125.DisplayCode AS TransfusionGiven, 
    Lookup125.UserDescription AS TransfusionGivenDesc, Lookup126.DisplayCode AS Trauma, Lookup126.UserDescription AS TraumaDesc, 
    Lookup127.DisplayCode AS TSICoder, Lookup127.UserDescription AS TSICoderDesc, dbo.AB_Abstract.TSIDate, dbo.AB_Abstract.TSITime, 
    dbo.AB_Abstract.UniqiueLifetimeID AS ULI, Lookup128.DisplayCode AS UnplannedReadmission, 
    Lookup128.UserDescription AS UnplannedReadmissionDesc, 
	dbo.AB_Abstract.UniversalEpisodeIdentifier,
    dbo.AB_Abstract.WaitTimeER AS WaitTimeInEmerg, 
    dbo.AB_Abstract.WaitTimeERHour AS WaitTimeInEmergHour, 
    dbo.AB_Abstract.Weight AS Weightingrams, 
	(case when isnumeric(replace(AB_Abstract.WeightKilo, '','', ''.'')) = 1 then cast(replace(AB_Abstract.WeightKilo, '','', ''.'') as dec(7, 3)) else null end) as WeightKG,
    dbo.AB_Abstract.AbstractID AS zzAbstractLink, 
    dbo.AB_Abstract.RegionalPatientID as zzRegionalPatientID,
    dbo.AB_Abstract.VolumeID AS zzVolumeLink
FROM         
    dbo.AB_Abstract with (nolock) LEFT OUTER JOIN
    dbo.LU_Provider LU_RefProvider with (nolock) on dbo.AB_Abstract.RefPhysician = LU_RefProvider.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_DecAdmitTimeUnknown with (nolock) on dbo.AB_Abstract.DecisionAdmitTimeUnknown = LU_DecAdmitTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_1 with (nolock) on dbo.AB_Abstract.StakeHolder = LU_CodeFile_1.Code LEFT OUTER JOIN
    dbo.AB_Manitoba with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Manitoba.AbstractID left join
    dbo.LU_CodeFile LU_Meconium with (nolock) on LU_Meconium.Code = dbo.AB_Manitoba.Meconium LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Feeding with (nolock) on dbo.AB_Manitoba.Feeding = LU_Feeding.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_ChestCompressions with (nolock) on dbo.AB_Manitoba.ChestCompressions = LU_ChestCompressions.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_NarconMaloxone with (nolock) on dbo.AB_Manitoba.NarconMaloxone = LU_NarconMaloxone.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_MedicationResuscitation with (nolock) on 
    dbo.AB_Manitoba.MedicationResuscitation = LU_MedicationResuscitation.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_IntubationNotMeconium with (nolock) on dbo.AB_Manitoba.IntubationNotMeconium = LU_IntubationNotMeconium.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_BagVentilation with (nolock) on dbo.AB_Manitoba.BagVentilation = LU_BagVentilation.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_FreeFlowOxygen with (nolock) on dbo.AB_Manitoba.FreeFlowOxygen = LU_FreeFlowOxygen.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_RoutineCare with (nolock) on dbo.AB_Manitoba.RoutineCare = LU_RoutineCare.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Presentation with (nolock) on dbo.AB_Manitoba.Presentation = LU_Presentation.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_SecondStageDateUnknown with (nolock) on 
    dbo.AB_Manitoba.SecondStageDateUnknown = LU_SecondStageDateUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_FirstStageDateUnknown with (nolock) on dbo.AB_Manitoba.FirstStageDateUnknown = LU_FirstStageDateUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PostConceptionalFolicAcid with (nolock) on 
    dbo.AB_Manitoba.PostConceptionalFolicAcid = LU_PostConceptionalFolicAcid.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PreConceptionalFolicAcid with (nolock) on dbo.AB_Manitoba.PreConceptionalFolicAcid = LU_PreConceptionalFolicAcid.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Days_WeekAlcoholConsumed with (nolock) on 
    dbo.AB_Manitoba.Days_WeekAlcoholConsumed = LU_Days_WeekAlcoholConsumed.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_AlcoholDuringPregnancy with (nolock) on dbo.AB_Manitoba.AlcoholDuringPregnancy = LU_AlcoholDuringPregnancy.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_SmokingQuitDateUnknown with (nolock) on 
    dbo.AB_Manitoba.SmokingQuitDateUnknown = LU_SmokingQuitDateUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_MBEducation with (nolock) on dbo.AB_Manitoba.ObsEducation = LU_MBEducation.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PrenatalVisitDateUnknown with (nolock) on 
    dbo.AB_Manitoba.PrenatalVisitDateUnknown = LU_PrenatalVisitDateUnknown.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_LeaveCertificates with (nolock) on dbo.AB_Manitoba.LeaveCertificates = LU_LeaveCertificates.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_Elopements with (nolock) on dbo.AB_Manitoba.Elopements = LU_Elopements.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_MB_Autopsy with (nolock) on dbo.AB_Manitoba.MB_Autopsy = LU_MB_Autopsy.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_MHInstTo with (nolock) on dbo.AB_Manitoba.MHInstTo = LU_MHInstTo.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_MHInstFrom with (nolock) on dbo.AB_Manitoba.MHInstFrom = LU_MHInstFrom.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_AbstractType with (nolock) on dbo.AB_Manitoba.AbstractType = LU_AbstractType.Code LEFT OUTER JOIN
    dbo.LU_CareType with (nolock) on dbo.AB_Abstract.CareType = dbo.LU_CareType.Code LEFT OUTER JOIN
    dbo.LU_AbstractOverflow Lookup2 with (nolock) on dbo.AB_Abstract.AbstractOverflow = Lookup2.Code LEFT OUTER JOIN
    dbo.LU_AdmitAmbulance Lookup3 with (nolock) on dbo.AB_Abstract.AdmitAmbulance = Lookup3.Code LEFT OUTER JOIN
    dbo.LU_AdmitCategory Lookup4 with (nolock) on dbo.AB_Abstract.AdmitCategory = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_NurseArea Lookup5 with (nolock) on dbo.AB_Abstract.AdmittingNurseArea = Lookup5.Code LEFT OUTER JOIN
    dbo.LU_AgeCode Lookup6 with (nolock) on dbo.AB_Abstract.AgeCode = Lookup6.Code LEFT OUTER JOIN
    dbo.LU_AgeCode Lookup7 with (nolock) on dbo.AB_Abstract.DischargeAgeCode = Lookup7.Code LEFT OUTER JOIN
    dbo.LU_Provider Lookup28 with (nolock) on dbo.AB_Abstract.AttendingPhysician = Lookup28.Code LEFT OUTER JOIN
    dbo.LU_BatchPeriod Lookup50 with (nolock) on dbo.AB_Abstract.BatchPeriod = Lookup50.Code LEFT OUTER JOIN
    dbo.U_Users Lookup54 with (nolock) on dbo.AB_Abstract.CoderNumber = Lookup54.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem Lookup55 with (nolock) on dbo.AB_Abstract.Complication = Lookup55.Code LEFT OUTER JOIN
    dbo.U_Users Lookup60 with (nolock) on dbo.AB_Abstract.DataEntryCoder = Lookup60.Code LEFT OUTER JOIN
    dbo.LU_DispositionCode_I Lookup63 with (nolock) on dbo.AB_Abstract.DispositionCode = Lookup63.Code LEFT OUTER JOIN
    dbo.LU_NurseArea Lookup64 with (nolock) on dbo.AB_Abstract.DischargeNurseArea = Lookup64.Code LEFT OUTER JOIN
    dbo.LU_TherDischPlan Lookup65 with (nolock) on dbo.AB_Abstract.DischargePlanning = Lookup65.Code LEFT OUTER JOIN
    dbo.LU_EntryCode Lookup69 with (nolock) on dbo.AB_Abstract.EntryCode = Lookup69.Code LEFT OUTER JOIN
    dbo.LU_Gender_I Lookup72 with (nolock) on dbo.AB_Abstract.Gender = Lookup72.Code LEFT OUTER JOIN
    dbo.LU_Glasgow Lookup73 with (nolock) on dbo.AB_Abstract.GlasgowComaScale = Lookup73.Code LEFT OUTER JOIN
    dbo.LU_HCNProvince Lookup75 with (nolock) on dbo.AB_Abstract.HCNProvince = Lookup75.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 Lookup77 with (nolock) on dbo.AB_Abstract.InstitutionFrom = Lookup77.Code LEFT OUTER JOIN
	LU_Institution_TypeCode LU_InstitutionFrom_Type with (nolock) on dbo.AB_Abstract.InstitutionFromType = LU_InstitutionFrom_Type.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 Lookup78 with (nolock) on dbo.AB_Abstract.InstitutionTo = Lookup78.Code LEFT OUTER JOIN
	LU_Institution_TypeCode LU_InstitutionTo_Type with (nolock) on dbo.AB_Abstract.InstitutionToType = LU_InstitutionTo_Type.Code LEFT OUTER JOIN

    dbo.U_Users Lookup79 with (nolock) on dbo.AB_Abstract.InterfaceCoder = Lookup79.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus Lookup80 with (nolock) on dbo.AB_Abstract.IsCompleted = Lookup80.Code LEFT OUTER JOIN
    dbo.LU_CIHICorrect Lookup81 with (nolock) on dbo.AB_Abstract.IsCorrected = Lookup81.Code LEFT OUTER JOIN
    dbo.LU_DeleteStatus Lookup82 with (nolock) on dbo.AB_Abstract.IsDeleted = Lookup82.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem Lookup83 with (nolock) on dbo.AB_Abstract.IsSubmited = Lookup83.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus Lookup84 with (nolock) on dbo.AB_Abstract.IsValidated = Lookup84.Code LEFT OUTER JOIN
    dbo.LU_CustomStatus with (nolock) on dbo.AB_Abstract.IsCustomValidated = LU_CustomStatus.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup85 with (nolock) on dbo.AB_Abstract.BirthDateEstimated = Lookup85.Code LEFT OUTER JOIN
    dbo.LU_MaritalStatus Lookup88 with (nolock) on dbo.AB_Abstract.MaritalStatus = Lookup88.Code LEFT OUTER JOIN
    dbo.LU_TherPreAdmitWorkUp Lookup103 with (nolock) on dbo.AB_Abstract.PreAdmitWorkUp = Lookup103.Code LEFT OUTER JOIN
    dbo.LU_ReAdmitCode Lookup106 with (nolock) on dbo.AB_Abstract.ReAdmitCode = Lookup106.Code LEFT OUTER JOIN
    dbo.H_InstitutionProfile Lookup111 with (nolock) on dbo.AB_Abstract.InstitutionNumber = Lookup111.Code LEFT OUTER JOIN
    dbo.LU_ResidenceCode Lookup112 with (nolock) on dbo.AB_Abstract.ResidenceCode = Lookup112.Code LEFT OUTER JOIN
    dbo.LU_Region LUResidenceRegion with (nolock) on Lookup112.RegionCode = LUResidenceRegion.Code LEFT OUTER JOIN
    dbo.LU_Province LUResidenceProvince with (nolock) on Lookup112.ProvinceCode = LUResidenceProvince.Code LEFT OUTER JOIN
    dbo.LU_RespPayment Lookup114 with (nolock) on dbo.AB_Abstract.ResponsiblePayment = Lookup114.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup116 with (nolock) on dbo.AB_Abstract.Secret = Lookup116.Code LEFT OUTER JOIN
    dbo.LU_Site Lookup117 with (nolock) on dbo.AB_Abstract.SiteNumber = Lookup117.Code LEFT OUTER JOIN
    dbo.LU_TherSocialService Lookup118 with (nolock) on dbo.AB_Abstract.SocialService = Lookup118.Code LEFT OUTER JOIN
    dbo.LU_SurgicalCode Lookup124 with (nolock) on dbo.AB_Abstract.SurgicalCase = Lookup124.Code LEFT OUTER JOIN
    dbo.U_Users Lookup127 with (nolock) on dbo.AB_Abstract.TSICoder = Lookup127.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup128 with (nolock) on dbo.AB_Abstract.UnplanReAdmit = Lookup128.Code LEFT OUTER JOIN
    dbo.AB_Ancillary with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Ancillary.AbstractID LEFT OUTER JOIN
    dbo.LU_Ancillary1 Lookup11 with (nolock) on dbo.AB_Ancillary.AncillaryField1 = Lookup11.Code LEFT OUTER JOIN
    dbo.LU_Ancillary10 Lookup12 with (nolock) on dbo.AB_Ancillary.AncillaryField10 = Lookup12.Code LEFT OUTER JOIN
    dbo.LU_Ancillary11 Lookup13 with (nolock) on dbo.AB_Ancillary.AncillaryField11 = Lookup13.Code LEFT OUTER JOIN
    dbo.LU_Ancillary12 Lookup14 with (nolock) on dbo.AB_Ancillary.AncillaryField12 = Lookup14.Code LEFT OUTER JOIN
    dbo.LU_Ancillary13 Lookup15 with (nolock) on dbo.AB_Ancillary.AncillaryField13 = Lookup15.Code LEFT OUTER JOIN
    dbo.LU_Ancillary14 Lookup16 with (nolock) on dbo.AB_Ancillary.AncillaryField14 = Lookup16.Code LEFT OUTER JOIN
    dbo.LU_Ancillary15 Lookup17 with (nolock) on dbo.AB_Ancillary.AncillaryField15 = Lookup17.Code LEFT OUTER JOIN
    dbo.LU_Ancillary16 Lookup18 with (nolock) on dbo.AB_Ancillary.AncillaryField16 = Lookup18.Code LEFT OUTER JOIN
    dbo.LU_Ancillary17 Lookup19 with (nolock) on dbo.AB_Ancillary.AncillaryField17 = Lookup19.Code LEFT OUTER JOIN
    dbo.LU_Ancillary2 Lookup20 with (nolock) on dbo.AB_Ancillary.AncillaryField2 = Lookup20.Code LEFT OUTER JOIN
    dbo.LU_Ancillary3 Lookup21 with (nolock) on dbo.AB_Ancillary.AncillaryField3 = Lookup21.Code LEFT OUTER JOIN
    dbo.LU_Ancillary4 Lookup22 with (nolock) on dbo.AB_Ancillary.AncillaryField4 = Lookup22.Code LEFT OUTER JOIN
    dbo.LU_Ancillary5 Lookup23 with (nolock) on dbo.AB_Ancillary.AncillaryField5 = Lookup23.Code LEFT OUTER JOIN
    dbo.LU_Ancillary6 Lookup24 with (nolock) on dbo.AB_Ancillary.AncillaryField6 = Lookup24.Code LEFT OUTER JOIN
    dbo.LU_Ancillary7 Lookup25 with (nolock) on dbo.AB_Ancillary.AncillaryField7 = Lookup25.Code LEFT OUTER JOIN
    dbo.LU_Ancillary8 Lookup26 with (nolock) on dbo.AB_Ancillary.AncillaryField8 = Lookup26.Code LEFT OUTER JOIN
    dbo.LU_Ancillary9 Lookup27 with (nolock) on dbo.AB_Ancillary.AncillaryField9 = Lookup27.Code LEFT OUTER JOIN
    dbo.AB_BasicOption with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_BasicOption.AbstractID LEFT OUTER JOIN
    dbo.LU_BasicOption1 Lookup31 with (nolock) on dbo.AB_BasicOption.BasicOption1 = Lookup31.Code LEFT OUTER JOIN
    dbo.LU_BasicOption10 Lookup32 with (nolock) on dbo.AB_BasicOption.BasicOption10 = Lookup32.Code LEFT OUTER JOIN
    dbo.LU_BasicOption11 Lookup33 with (nolock) on dbo.AB_BasicOption.BasicOption11 = Lookup33.Code LEFT OUTER JOIN
    dbo.LU_BasicOption12 Lookup34 with (nolock) on dbo.AB_BasicOption.BasicOption12 = Lookup34.Code LEFT OUTER JOIN
    dbo.LU_BasicOption13 Lookup35 with (nolock) on dbo.AB_BasicOption.BasicOption13 = Lookup35.Code LEFT OUTER JOIN
    dbo.LU_BasicOption14 Lookup36 with (nolock) on dbo.AB_BasicOption.BasicOption14 = Lookup36.Code LEFT OUTER JOIN
    dbo.LU_BasicOption15 Lookup37 with (nolock) on dbo.AB_BasicOption.BasicOption15 = Lookup37.Code LEFT OUTER JOIN
    dbo.LU_BasicOption16 Lookup38 with (nolock) on dbo.AB_BasicOption.BasicOption16 = Lookup38.Code LEFT OUTER JOIN
    dbo.LU_BasicOption17 Lookup39 with (nolock) on dbo.AB_BasicOption.BasicOption17 = Lookup39.Code LEFT OUTER JOIN
    dbo.LU_BasicOption18 Lookup40 with (nolock) on dbo.AB_BasicOption.BasicOption18 = Lookup40.Code LEFT OUTER JOIN
    dbo.LU_BasicOption19 Lookup41 with (nolock) on dbo.AB_BasicOption.BasicOption19 = Lookup41.Code LEFT OUTER JOIN
    dbo.LU_BasicOption2 Lookup42 with (nolock) on dbo.AB_BasicOption.BasicOption2 = Lookup42.Code LEFT OUTER JOIN
    dbo.LU_BasicOption3 Lookup43 with (nolock) on dbo.AB_BasicOption.BasicOption3 = Lookup43.Code LEFT OUTER JOIN
    dbo.LU_BasicOption4 Lookup44 with (nolock) on dbo.AB_BasicOption.BasicOption4 = Lookup44.Code LEFT OUTER JOIN
    dbo.LU_BasicOption5 Lookup45 with (nolock) on dbo.AB_BasicOption.BasicOption5 = Lookup45.Code LEFT OUTER JOIN
    dbo.LU_BasicOption6 Lookup46 with (nolock) on dbo.AB_BasicOption.BasicOption6 = Lookup46.Code LEFT OUTER JOIN
    dbo.LU_BasicOption7 Lookup47 with (nolock) on dbo.AB_BasicOption.BasicOption7 = Lookup47.Code LEFT OUTER JOIN
    dbo.LU_BasicOption8 Lookup48 with (nolock) on dbo.AB_BasicOption.BasicOption8 = Lookup48.Code LEFT OUTER JOIN
    dbo.LU_BasicOption9 Lookup49 with (nolock) on dbo.AB_BasicOption.BasicOption9 = Lookup49.Code LEFT OUTER JOIN
    dbo.AB_Blood with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Blood.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup8 with (nolock) on dbo.AB_Blood.Albumin = Lookup8.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup9 with (nolock) on dbo.AB_Blood.AlbuminXMatch = Lookup9.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup10 with (nolock) on dbo.AB_Blood.AlbuminTyped = Lookup10.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup29 with (nolock) on dbo.AB_Blood.AutoTransfusion = Lookup29.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup92 with (nolock) on dbo.AB_Blood.OtherBlood = Lookup92.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup93 with (nolock) on dbo.AB_Blood.OtherBloodXMatch = Lookup93.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup94 with (nolock) on dbo.AB_Blood.OtherBloodTyped = Lookup94.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup96 with (nolock) on dbo.AB_Blood.Plasma = Lookup96.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup97 with (nolock) on dbo.AB_Blood.PlasmaXMatch = Lookup97.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup98 with (nolock) on dbo.AB_Blood.PlasmaTyped = Lookup98.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup99 with (nolock) on dbo.AB_Blood.Platelets = Lookup99.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup100 with (nolock) on dbo.AB_Blood.PlateletsXMatch = Lookup100.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup101 with (nolock) on dbo.AB_Blood.PlateletsTyped = Lookup101.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup107 with (nolock) on dbo.AB_Blood.RedBloodCell = Lookup107.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup108 with (nolock) on dbo.AB_Blood.RedCellXMatch = Lookup108.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup109 with (nolock) on dbo.AB_Blood.RedCellTyped = Lookup109.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup125 with (nolock) on dbo.AB_Blood.TransfusionIndicator = Lookup125.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_AntithrombinIII with (nolock) on dbo.AB_Blood.AntithrombinIII = LU_AntithrombinIII.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_C1Inhibitor with (nolock) on dbo.AB_Blood.C1Inhibitor = LU_C1Inhibitor.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_CryoprecipitatePlasma with (nolock) on dbo.AB_Blood.CryoprecipitatePlasma = LU_CryoprecipitatePlasma.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_CryosupernatantPlasma with (nolock) on dbo.AB_Blood.CryosupernatantPlasma = LU_CryosupernatantPlasma.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_FEIBA with (nolock) on dbo.AB_Blood.FEIBA = LU_FEIBA.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_Fibrinogen with (nolock) on dbo.AB_Blood.Fibrinogen = LU_Fibrinogen.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_IVIG_SCIG with (nolock) on dbo.AB_Blood.IVIG_SCIG = LU_IVIG_SCIG.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_PCC with (nolock) on dbo.AB_Blood.PCC = LU_PCC.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_ProteinC_OtherFactors with (nolock) on dbo.AB_Blood.ProteinC_OtherFactors = LU_ProteinC_OtherFactors.Code LEFT OUTER JOIN


    dbo.AB_DeathInformation with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_DeathInformation.AbstractID LEFT OUTER JOIN
    dbo.LU_AutopsyDeath Lookup30 with (nolock) on dbo.AB_DeathInformation.AutopsyPerformed = Lookup30.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup51 with (nolock) on dbo.AB_DeathInformation.DeathTwoTenPO = Lookup51.Code LEFT OUTER JOIN
    dbo.LU_CoronerCase Lookup59 with (nolock) on dbo.AB_DeathInformation.CoronerCase = Lookup59.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup61 with (nolock) on dbo.AB_DeathInformation.DeathInOR = Lookup61.Code left join
    dbo.LU_SCU_Death Lookup62 with (nolock) on Lookup62.Code = dbo.AB_DeathInformation.DeathInSCU LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup74 with (nolock) on dbo.AB_DeathInformation.DeathGreaterTenPO = Lookup74.Code left join
    dbo.LU_YesBlank Lookup86 with (nolock) on Lookup86.Code = dbo.AB_DeathInformation.DeathAfterAdmit LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup87 with (nolock) on dbo.AB_DeathInformation.DeathLessTwoPO = Lookup87.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup91 with (nolock) on dbo.AB_DeathInformation.OtherDeath = Lookup91.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup104 with (nolock) on dbo.AB_DeathInformation.PregnancyDeath = Lookup104.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup126 with (nolock) on dbo.AB_DeathInformation.TraumaDeath = Lookup126.Code left join
    
	dbo.AB_MentalHealth with (nolock) on dbo.AB_MentalHealth.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup1 with (nolock) on dbo.AB_MentalHealth.MentalAWOL = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_MentalLegalStatus Lookup53 with (nolock) on dbo.AB_MentalHealth.MentalLegalStatus = Lookup53.Code left join
    dbo.LU_YesNoNumeric Lookup66 with (nolock) on Lookup66.Code = dbo.AB_MentalHealth.MentalECTTreatment LEFT OUTER JOIN
    dbo.LU_MentalEducation Lookup67 with (nolock) on dbo.AB_MentalHealth.MentalEducation = Lookup67.Code LEFT OUTER JOIN
    dbo.LU_MentalEmployment Lookup68 with (nolock) on dbo.AB_MentalHealth.MentalEmployment = Lookup68.Code LEFT OUTER JOIN
    dbo.LU_MentalFinancial Lookup70 with (nolock) on dbo.AB_MentalHealth.MentalFinancial = Lookup70.Code LEFT OUTER JOIN
    dbo.LU_MentalAdmitMethod Lookup89 with (nolock) on dbo.AB_MentalHealth.MentalAdmitMethod = Lookup89.Code LEFT OUTER JOIN
    dbo.LU_MentalPrevPsych Lookup105 with (nolock) on dbo.AB_MentalHealth.MentalPrevPsych = Lookup105.Code left join
    dbo.LU_MentalReferral Lookup110 with (nolock) on Lookup110.Code = dbo.AB_MentalHealth.MentalReferralTo LEFT OUTER JOIN
    dbo.LU_MentalReferral Lookup119 with (nolock) on dbo.AB_MentalHealth.MentalReferralSource = Lookup119.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup123 with (nolock) on dbo.AB_MentalHealth.MentalSuicide = Lookup123.Code LEFT OUTER JOIN

	dbo.LU_MentalLegalStatusUponArrivalED with (nolock) on dbo.AB_MentalHealth.LegalStatusUponArrivaltoED = LU_MentalLegalStatusUponArrivalED.Code LEFT OUTER JOIN
	dbo.LU_MentalLegalStatusAdmission with (nolock) on dbo.AB_MentalHealth.LegalStatusAtAdmission = LU_MentalLegalStatusAdmission.Code LEFT OUTER JOIN
	dbo.LU_MentalTypeRestraint LU_MentalTypeRestraint_1 with (nolock) on dbo.AB_MentalHealth.TypeOfRestraint01 = LU_MentalTypeRestraint_1.Code LEFT OUTER JOIN
	dbo.LU_MentalFrequencyRestraintUse LU_MentalFrequencyRestraintUse_1 with (nolock) on dbo.AB_MentalHealth.FrequencyOfRestraint01 = LU_MentalFrequencyRestraintUse_1.Code LEFT OUTER JOIN
	dbo.LU_MentalTypeRestraint LU_MentalTypeRestraint_2 with (nolock) on dbo.AB_MentalHealth.TypeOfRestraint02 = LU_MentalTypeRestraint_2.Code LEFT OUTER JOIN
	dbo.LU_MentalFrequencyRestraintUse LU_MentalFrequencyRestraintUse_2 with (nolock) on dbo.AB_MentalHealth.FrequencyOfRestraint02 = LU_MentalFrequencyRestraintUse_2.Code LEFT OUTER JOIN
	dbo.LU_MentalTypeRestraint LU_MentalTypeRestraint_3 with (nolock) on dbo.AB_MentalHealth.TypeOfRestraint03 = LU_MentalTypeRestraint_3.Code LEFT OUTER JOIN
	dbo.LU_MentalFrequencyRestraintUse LU_MentalFrequencyRestraintUse_3 with (nolock) on dbo.AB_MentalHealth.FrequencyOfRestraint03 = LU_MentalFrequencyRestraintUse_3.Code LEFT OUTER JOIN
	dbo.LU_MentalTypeRestraint LU_MentalTypeRestraint_4 with (nolock) on dbo.AB_MentalHealth.TypeOfRestraint04 = LU_MentalTypeRestraint_4.Code LEFT OUTER JOIN
	dbo.LU_MentalFrequencyRestraintUse LU_MentalFrequencyRestraintUse_4 with (nolock) on dbo.AB_MentalHealth.FrequencyOfRestraint04 = LU_MentalFrequencyRestraintUse_4.Code LEFT OUTER JOIN


    dbo.AB_Therapeutic with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Therapeutic.AbstractID LEFT OUTER JOIN
    dbo.LU_TherOption1 Lookup71 with (nolock) on dbo.AB_Therapeutic.FirstOptionTherapy = Lookup71.Code LEFT OUTER JOIN
    dbo.LU_TherOccupation Lookup90 with (nolock) on dbo.AB_Therapeutic.OccupationalTherapy = Lookup90.Code left join
    dbo.LU_TherPhysio Lookup95 with (nolock) on Lookup95.Code = dbo.AB_Therapeutic.PhysioTherapy LEFT OUTER JOIN
    dbo.LU_TherRespiratory Lookup113 with (nolock) on dbo.AB_Therapeutic.RespiratoryTherapy = Lookup113.Code LEFT OUTER JOIN
    dbo.LU_TherOption2 Lookup115 with (nolock) on dbo.AB_Therapeutic.SecondOptionTherapy = Lookup115.Code LEFT OUTER JOIN
    dbo.LU_TherSpeech Lookup120 with (nolock) on dbo.AB_Therapeutic.SpeechTherapy = Lookup120.Code LEFT OUTER JOIN
    dbo.AB_ReproductiveCare with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_ReproductiveCare.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup52 with (nolock) on dbo.AB_ReproductiveCare.BreastFeeding = Lookup52.Code left join
    dbo.LU_ReprodComplication Lookup56 with (nolock) on Lookup56.Code = dbo.AB_ReproductiveCare.Complication1 left join
    dbo.LU_ReprodComplication Lookup57 with (nolock) on Lookup57.Code = dbo.AB_ReproductiveCare.Complication2 LEFT OUTER JOIN
    dbo.LU_ReprodComplication Lookup58 with (nolock) on dbo.AB_ReproductiveCare.Complication3 = Lookup58.Code LEFT OUTER JOIN
    dbo.LU_ReprodOR Lookup76 with (nolock) on dbo.AB_ReproductiveCare.InitialOR = Lookup76.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup121 with (nolock) on dbo.AB_ReproductiveCare.Sterilization = Lookup121.Code LEFT OUTER JOIN
    dbo.LU_ReprodOR Lookup122 with (nolock) on dbo.AB_ReproductiveCare.SubsequentOR = Lookup122.Code LEFT OUTER JOIN
    dbo.AB_CancerStaging with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_CancerStaging.AbstractID LEFT OUTER JOIN
    dbo.H_HospitalProfile with (nolock) on dbo.AB_Abstract.HospitalID = dbo.H_HospitalProfile.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_TimeLeftERUnknown with (nolock) on dbo.AB_Abstract.TimeLeftERUnknown = LU_TimeLeftERUnknown.Code 
    --PR - 03622
    LEFT OUTER JOIN dbo.LU_CodeFile LU_PresentDelivery with (nolock) on dbo.AB_Manitoba.PresentDelivery = LU_PresentDelivery.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_PositionDelviery with (nolock) on dbo.AB_Manitoba.PositionDelviery = LU_PositionDelviery.Code 
--ED - 01750
    LEFT OUTER JOIN dbo.LU_CodeFile LU_AnestheticLabor with (nolock) on dbo.AB_Manitoba.AnestheticLabor = LU_AnestheticLabor.Code 
--PR - 04577
    LEFT OUTER JOIN dbo.LU_ReciprocalBillingStatus with (nolock) on dbo.AB_Abstract.IsReciprocalBilling = LU_ReciprocalBillingStatus.Code 
--PR - 05489
    LEFT OUTER JOIN dbo.LU_CodeFile LU_AdmitTimeUnknown with (nolock) on dbo.AB_Abstract.AdmitTimeUnknown = LU_AdmitTimeUnknown.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_DischargeTimeUnknown with (nolock) on dbo.AB_Abstract.DischargeTimeUnknown = LU_DischargeTimeUnknown.Code 
    
    LEFT OUTER JOIN dbo.LU_CodeFile LU_SmokingInPregnancy with (nolock) on dbo.AB_Manitoba.SmokingInPregnancy = LU_SmokingInPregnancy.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_AlcoholQuitDateUnknown with (nolock) on dbo.AB_Manitoba.AlcoholQuitDateUnknown = LU_AlcoholQuitDateUnknown.Code 
WHERE     (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType IN (1, 2)) 
--QA - 00032 disable the domain securite issue
----PR - 07485
--    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB_ABstract.HospitalID is null or AB_ABstract.HospitalID = 0
----EN - 00666
--        or Is_Member(nullif(ReportGroup, '''')) = 1)
----        or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB_ABstract.HospitalID, 0))



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstracting_Profile_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE  VIEW [dbo].[I10_Abstracting_Profile_VR]
AS
SELECT     dbo.AB_ReproductiveCare.PrevTermDelivery AS [#ofPreviousDeliveries], 
    dbo.AB_ReproductiveCare.PrevLiveBirths AS [#ofPreviousLiveBirths], 
    dbo.AB_ReproductiveCare.PrevPreTermDelivery AS [#ofPreviousPreTermDeliveries], 
    dbo.AB_ReproductiveCare.PrevSpontAbortions AS [#ofPrevSpontaneousAbortions], 
    dbo.AB_ReproductiveCare.PrevInduceAbortions AS [#ofPrevTherapueticAbortions], 
    --'''' AS AbstractNotes, PR - 05199
    dbo.AB_Abstract.AbstractNumber, 
    Lookup2.DisplayCode AS AbstractOverflow, Lookup2.UserDescription AS AbstractOverflowDesc, LU_AbstractType.DisplayCode AS AbstractType, 
    LU_AbstractType.UserDescription AS AbstractTypeDesc, dbo.AB_Abstract.AcuteLOS, dbo.AB_Abstract.AdmitDate AS AdmissionDate, 
    dbo.AB_Abstract.AdmitTime AS AdmissionTime, 
    --PR - 05489
    LU_AdmitTimeUnknown.DisplayCode as AdmissionTimeUnknown, LU_AdmitTimeUnknown.UserDescription as AdmissionTimeUnknownDesc,
    Lookup3.DisplayCode AS AdmitbyAmbulance, Lookup3.UserDescription AS AdmitbyAmbulanceDesc, 
    Lookup4.DisplayCode AS AdmitCategory, Lookup4.UserDescription AS AdmitCategoryDesc, Lookup5.DisplayCode AS AdmitNursingAreaUnitLocation, 
    Lookup5.UserDescription AS AdmittingNursingAreaUnitLDesc, Lookup6.DisplayCode AS AgeCode, Lookup6.UserDescription AS AgeCodeDesc, 
    dbo.AB_Abstract.AgeGroup, dbo.AB_Abstract.AgeNumber, dbo.AB_Abstract.DischargeAge AS AgeUponDischarge, 
    Lookup7.DisplayCode AS AgeUponDischargeCode, Lookup7.UserDescription AS AgeUponDischargeCodeDesc, Lookup8.DisplayCode AS Albumin, 
    Lookup9.DisplayCode AS AlbuminCrossMatched, Lookup9.UserDescription AS AlbuminCrossMatchedDesc, Lookup8.UserDescription AS AlbuminDesc, 
    Lookup10.DisplayCode AS AlbuminTyped, Lookup10.UserDescription AS AlbuminTypedDesc, dbo.AB_Blood.AlbuminUnits, dbo.AB_Abstract.ALCLOS, 
    LU_AlcoholDuringPregnancy.DisplayCode AS AlcoholDuringPregnancy, LU_AlcoholDuringPregnancy.UserDescription AS AlcoholDuringPregnancyDesc, 
    AlcoholQuitDate,
    LU_AlcoholQuitDateUnknown.DisplayCode AS AlcoholQuitDateUnknown, LU_AlcoholQuitDateUnknown.UserDescription AS AlcoholQuitDateUnknownDesc, 
    Lookup11.DisplayCode AS AncillaryField1, Lookup11.UserDescription AS AncillaryField1Desc, Lookup12.DisplayCode AS AncillaryField10, 
    Lookup12.UserDescription AS AncillaryField10Desc, Lookup13.DisplayCode AS AncillaryField11, Lookup13.UserDescription AS AncillaryField11Desc, 
    Lookup14.DisplayCode AS AncillaryField12, Lookup14.UserDescription AS AncillaryField12Desc, Lookup15.DisplayCode AS AncillaryField13, 
    Lookup15.UserDescription AS AncillaryField13Desc, Lookup16.DisplayCode AS AncillaryField14, Lookup16.UserDescription AS AncillaryField14Desc, 
    Lookup17.DisplayCode AS AncillaryField15, Lookup17.UserDescription AS AncillaryField15Desc, Lookup18.DisplayCode AS AncillaryField16, 
    Lookup18.UserDescription AS AncillaryField16Desc, Lookup19.DisplayCode AS AncillaryField17, Lookup19.UserDescription AS AncillaryField17Desc, 
    Lookup20.DisplayCode AS AncillaryField2, Lookup20.UserDescription AS AncillaryField2Desc, Lookup21.DisplayCode AS AncillaryField3, 
    Lookup21.UserDescription AS AncillaryField3Desc, Lookup22.DisplayCode AS AncillaryField4, Lookup22.UserDescription AS AncillaryField4Desc, 
    Lookup23.DisplayCode AS AncillaryField5, Lookup23.UserDescription AS AncillaryField5Desc, Lookup24.DisplayCode AS AncillaryField6, 
    Lookup24.UserDescription AS AncillaryField6Desc, Lookup25.DisplayCode AS AncillaryField7, Lookup25.UserDescription AS AncillaryField7Desc, 
    Lookup26.DisplayCode AS AncillaryField8, Lookup26.UserDescription AS AncillaryField8Desc, Lookup27.DisplayCode AS AncillaryField9, 
    Lookup27.UserDescription AS AncillaryField9Desc,
    --ED - 01750
    LU_AnestheticLabor.DisplayCode as AnalgesicAnestheticDuringLabor, LU_AnestheticLabor.UserDescription as AnalgesicAnestheticDuringLaborDesc,
    dbo.AB_Manitoba.Apgar1Min, dbo.AB_Manitoba.Apgar5Min, 
    dbo.AB_Abstract.ArrivalDate AS ArrivalDateInER, dbo.AB_Abstract.ArrivalTime AS ArrivalTimeInER, Lookup28.DisplayCode AS AttendingPhysician, 
    Lookup28.UserDescription AS AttendingPhysicianDesc, Lookup30.DisplayCode AS AutopsyPerformed, 
    Lookup30.UserDescription AS AutopsyPerformedDesc, Lookup29.DisplayCode AS AutoTransfusion, 
    Lookup29.UserDescription AS AutoTransfusionDesc, Lookup1.DisplayCode AS AWOL, Lookup1.UserDescription AS AWOLDesc, 
    LU_BagVentilation.DisplayCode AS BagVentilation, LU_BagVentilation.UserDescription AS BagVentilationDesc, 
    Lookup31.DisplayCode AS BasicOption1, Lookup31.UserDescription AS BasicOption1Desc, Lookup32.DisplayCode AS BasicOption10, 
    Lookup32.UserDescription AS BasicOption10Desc, Lookup33.DisplayCode AS BasicOption11, Lookup33.UserDescription AS BasicOption11Desc, 
    Lookup34.DisplayCode AS BasicOption12, Lookup34.UserDescription AS BasicOption12Desc, Lookup35.DisplayCode AS BasicOption13, 
    Lookup35.UserDescription AS BasicOption13Desc, Lookup36.DisplayCode AS BasicOption14, Lookup36.UserDescription AS BasicOption14Desc, 
    Lookup37.DisplayCode AS BasicOption15, Lookup37.UserDescription AS BasicOption15Desc, Lookup38.DisplayCode AS BasicOption16, 
    Lookup38.UserDescription AS BasicOption16Desc, Lookup39.DisplayCode AS BasicOption17, Lookup39.UserDescription AS BasicOption17Desc, 
    Lookup40.DisplayCode AS BasicOption18, Lookup40.UserDescription AS BasicOption18Desc, Lookup41.DisplayCode AS BasicOption19, 
    Lookup41.UserDescription AS BasicOption19Desc, Lookup42.DisplayCode AS BasicOption2, Lookup42.UserDescription AS BasicOption2Desc, 
    Lookup43.DisplayCode AS BasicOption3, Lookup43.UserDescription AS BasicOption3Desc, Lookup44.DisplayCode AS BasicOption4, 
    Lookup44.UserDescription AS BasicOption4Desc, Lookup45.DisplayCode AS BasicOption5, Lookup45.UserDescription AS BasicOption5Desc, 
    Lookup46.DisplayCode AS BasicOption6, Lookup46.UserDescription AS BasicOption6Desc, Lookup47.DisplayCode AS BasicOption7, 
    Lookup47.UserDescription AS BasicOption7Desc, Lookup48.DisplayCode AS BasicOption8, Lookup48.UserDescription AS BasicOption8Desc, 
    Lookup49.DisplayCode AS BasicOption9, Lookup49.UserDescription AS BasicOption9Desc, dbo.AB_Abstract.BatchNumber, 
    Lookup50.DisplayCode AS BatchPeriod, Lookup50.UserDescription AS BatchPeriodDesc, 

	LU_AntithrombinIII.DisplayCode AS Blood_AntithrombinIII, LU_AntithrombinIII.UserDescription AS Blood_AntithrombinIIIDesc,
	LU_C1Inhibitor.DisplayCode AS Blood_C1Inhibitor, LU_C1Inhibitor.UserDescription AS Blood_C1InhibitorDesc,
	LU_CryoprecipitatePlasma.DisplayCode AS Blood_CryoprecipitatePlasma, LU_CryoprecipitatePlasma.UserDescription AS Blood_CryoprecipitatePlasmaDesc,
	LU_CryosupernatantPlasma.DisplayCode AS Blood_CryosupernatantPlasma, LU_CryosupernatantPlasma.UserDescription AS Blood_CryosupernatantPlasmaDesc,
	LU_FEIBA.DisplayCode AS Blood_FEIBA, LU_FEIBA.UserDescription AS Blood_FEIBADesc,
	LU_Fibrinogen.DisplayCode AS Blood_Fibrinogen, LU_Fibrinogen.UserDescription AS Blood_FibrinogenDesc,
	LU_IVIG_SCIG.DisplayCode AS Blood_IVIG_SCIG, LU_IVIG_SCIG.UserDescription AS Blood_IVIG_SCIGDesc,
	LU_PCC.DisplayCode AS Blood_PCC, LU_PCC.UserDescription AS Blood_PCCDesc,
	LU_ProteinC_OtherFactors.DisplayCode AS Blood_ProteinC_OtherFactors, LU_ProteinC_OtherFactors.UserDescription AS Blood_ProteinC_OtherFactorsDesc,



    --PR - 06087
    BatchPeriod_BC = (case when left(Lookup111.CIHIValue, 1) <> ''9'' then null
                         when Lookup50.DisplayCode is not null then Lookup50.DisplayCode 
                         when DischargeDate is null then null
                         else (select top 1 DisplayCode from LU_BatchPeriod where DischargeDate between CIHIDateFrom and CIHIDateTo)
                    end),
    dbo.AB_Abstract.BatchYear, 
    Lookup51.DisplayCode AS Between210DaysPostOp, Lookup51.UserDescription AS Between210DaysPostOpDesc, dbo.AB_Abstract.BirthDate, 
    Lookup52.DisplayCode AS BreastFeedingonDischarge, Lookup52.UserDescription AS BreastFeedingonDischargeDesc, 
    dbo.LU_CareType.DisplayCode AS CareType, dbo.LU_CareType.UserDescription AS CareTypeDesc, Lookup53.DisplayCode AS ChangeinLegalStatus, 
    Lookup53.UserDescription AS ChangeinLegalStatusDesc, dbo.AB_Abstract.ChartNumber, LU_ChestCompressions.DisplayCode AS ChestCompressions,
    LU_ChestCompressions.UserDescription AS ChestCompressionsDesc, dbo.AB_Abstract.ChiefComplaint AS ChiefComplaintUponAdmission, 
    dbo.AB_CancerStaging.ClinicalMetastasis, dbo.AB_CancerStaging.ClinicalNode, dbo.AB_CancerStaging.ClinicalTumor, 
    Lookup54.DisplayCode AS CoderNumber, Lookup54.UserDescription AS CoderNumberDesc, Lookup55.DisplayCode AS Comorbidity, 
    Lookup55.UserDescription AS ComorbidityDesc, Lookup55.DisplayCode AS Complication, Lookup55.UserDescription AS ComplicationDesc, 
    Lookup56.DisplayCode AS Complication1, Lookup56.UserDescription AS Complication1Desc, Lookup57.DisplayCode AS Complication2, 
    Lookup57.UserDescription AS Complication2Desc, Lookup58.DisplayCode AS Complication3, Lookup58.UserDescription AS Complication3Desc, 
    Lookup58.DefaultDescription AS Complication3Desc_D, Lookup59.DisplayCode AS CoronerCase, Lookup59.UserDescription AS CoronerCaseDesc, 
    Lookup60.DisplayCode AS DataEntryCoder, Lookup60.UserDescription AS DataEntryCoderDesc, 
    dbo.AB_ReproductiveCare.LastMensesDate AS DateofLastMenses, dbo.AB_Abstract.DateReadyDischarge AS DateReadyForDischarge, 
    dbo.AB_Abstract.CIHIDateSent AS DateSenttoCIHI, LU_Days_WeekAlcoholConsumed.DisplayCode AS Days_WeekAlcoholConsumed, 
    LU_Days_WeekAlcoholConsumed.UserDescription AS Days_WeekAlcoholConsumedDesc, Lookup61.DisplayCode AS DeathInOR, 
    Lookup61.UserDescription AS DeathInORDesc, Lookup62.DisplayCode AS DeathInSCU, Lookup62.UserDescription AS DeathInSCUDesc, 
    dbo.AB_Manitoba.DeclarationNumber, dbo.AB_ReproductiveCare.DeliveryDate, dbo.AB_ReproductiveCare.DeliveryTime, 
    dbo.AB_Abstract.DischargeDate, Lookup63.DisplayCode AS DischargeDisposition, Lookup63.UserDescription AS DischargeDispositionDesc, 
    Lookup64.DisplayCode AS DischNursingAreaUnitLocation, Lookup64.UserDescription AS DischargeNursingAreaUnitDesc, 
    Lookup65.DisplayCode AS DischargePlanning, Lookup65.UserDescription AS DischargePlanningDesc, 
    dbo.AB_Abstract.DischargeTime, 
    --PR - 05489
    LU_DischargeTimeUnknown.DisplayCode AS DischargeTimeUnknown, LU_DischargeTimeUnknown.UserDescription AS DischargeTimeUnknownDesc, 

    dbo.AB_Manitoba.DrinksPerday, dbo.AB_Manitoba.ALC_TotalDays AS DurationALCDays, Lookup66.DisplayCode AS ECTTreatment, 
    Lookup66.UserDescription AS ECTTreatmentDesc, Lookup67.DisplayCode AS Education, Lookup67.UserDescription AS EducationDesc, 
    LU_Elopements.DisplayCode AS Elopements, LU_Elopements.UserDescription AS ElopementsDesc, dbo.AB_Manitoba.EmployerName, 
    Lookup68.DisplayCode AS Employment, Lookup68.UserDescription AS EmploymentDesc, dbo.AB_Abstract.EncounterNumber, 
    Lookup69.DisplayCode AS EntryCode, Lookup69.UserDescription AS EntryCodeDesc, dbo.AB_Abstract.DateLeftER AS ERDatePatientLeft, 
    dbo.AB_Abstract.DecisionAdmitDate AS ERDecisiontoAdmitDate, dbo.AB_Abstract.DecisionAdmitTime AS ERDecisiontoAdmitTime, 
    LU_DecAdmitTimeUnknown.DisplayCode AS ERDecisionAdmitTimeUnknown, 
    LU_DecAdmitTimeUnknown.UserDescription AS ERDecisionAdmitTimeUnknownDesc, dbo.AB_Abstract.TimeLeftER AS ERTimePatientLeft, 
    LU_TimeLeftERUnknown.DisplayCode AS ERTimePatientLeftUnknown, LU_TimeLeftERUnknown.UserDescription AS ERTimePatientLeftUnknownDesc, 
    LU_Feeding.DisplayCode AS Feeding, LU_Feeding.UserDescription AS FeedingDesc, Lookup70.DisplayCode AS FinancialSupport, 
    Lookup70.UserDescription AS FinancialSupportDesc, dbo.AB_Abstract.FinishDate, dbo.AB_Abstract.FinishTime, dbo.AB_Abstract.FirstName, 
    Lookup71.DisplayCode AS FirstOptionalTherapy, Lookup71.UserDescription AS FirstOptionalTherapyDesc, 
    dbo.AB_Therapeutic.FirstOptionUnits AS FirstOptionalUnits, dbo.AB_Manitoba.FirstStageDuration, 
    FixedChartNumber,
    LU_FreeFlowOxygen.DisplayCode AS FreeFlowOxygen, LU_FreeFlowOxygen.UserDescription AS FreeFlowOxygenDesc, 
    Lookup72.DisplayCode AS Gender, Lookup72.UserDescription AS GenderDesc, dbo.AB_Manitoba.Gestation, 
    dbo.AB_ReproductiveCare.GestationalAge AS GestationalAgeinweeks, Lookup73.DisplayCode AS GlasgowComaScale, 
    Lookup73.UserDescription AS GlasgowComaScaleDesc, dbo.AB_Manitoba.Gravida, Lookup74.DisplayCode AS Greaterthan10DaysPostOp, 
    Lookup74.UserDescription AS Greaterthan10DaysPostOpDesc, Lookup75.DisplayCode AS HCNProvince, 
    Lookup75.UserDescription AS HCNProvinceDesc, dbo.AB_Abstract.HCNVersion, dbo.AB_Abstract.HealthCareNumber, 
	AB_Abstract.Height,
    dbo.H_HospitalProfile.DisplayCode AS Hospital, dbo.H_HospitalProfile.UserDescription AS HospitalDesc, 
    dbo.AB_Abstract.HospitalAccountRecord,
    dbo.AB_Abstract.ICDType, 
    Lookup76.DisplayCode AS InitialOR, Lookup76.UserDescription AS InitialORDesc, dbo.AB_Abstract.InputDate, dbo.AB_Abstract.InputTime, 
    
	Lookup77.InstCareType AS InstFromCareType, Lookup77.HospitalType AS InstFromHospType, 
	Lookup77.DisplayCode AS InstitutionFrom, Lookup77.UserDescription AS InstitutionFromDesc, 
	LU_InstitutionFrom_Type.DisplayCode AS InstitutionFromType, LU_InstitutionFrom_Type.UserDescription AS InstitutionFromTypeDesc, 

	Lookup78.DisplayCode AS InstitutionTo, Lookup78.UserDescription AS InstitutionToDesc, 
	LU_InstitutionTo_Type.DisplayCode AS InstitutionToType, LU_InstitutionTo_Type.UserDescription AS InstitutionToTypeDesc, 
    Lookup78.InstCareType AS InstToCareType, Lookup78.HospitalType AS InstToHospType, 
	
	Lookup79.DisplayCode AS InterfaceCoder, 
    Lookup79.UserDescription AS InterfaceCoderDesc, dbo.AB_Abstract.InterfaceDate, dbo.AB_Abstract.InterfaceTime, 
    LU_IntubationNotMeconium.DisplayCode AS IntubationNotMeconium, LU_IntubationNotMeconium.UserDescription AS IntubationNotMeconiumDesc, 
    Lookup80.DisplayCode AS IsAbstractCompleted, Lookup80.UserDescription AS IsAbstractCompletedDesc, 
    Lookup81.DisplayCode AS IsAbstractCorrected, Lookup81.UserDescription AS IsAbstractCorrectedDesc, Lookup82.DisplayCode AS IsAbstractDeleted, 
    Lookup82.UserDescription AS IsAbstractDeletedDesc, Lookup83.DisplayCode AS IsAbstractSubmited, 
    Lookup83.UserDescription AS IsAbstractSubmitedDesc, Lookup84.DisplayCode AS IsAbstractValidated, 
    Lookup84.UserDescription AS IsAbstractValidatedDesc, 
	Lookup85.DisplayCode AS IsBirthdateEstimated,  Lookup85.UserDescription AS IsBirthdateEstimatedDesc, 
	LU_CustomStatus.DisplayCode AS IsCustomValidated, LU_CustomStatus.UserDescription AS IsCustomValidatedDesc, 

	dbo.AB_Abstract.LastName, LU_LeaveCertificates.DisplayCode AS LeaveCertificates, 
    LU_LeaveCertificates.UserDescription AS LeaveCertificatesDesc, Lookup86.DisplayCode AS Lessthan2DaysAfterAdmission, 
    Lookup86.UserDescription AS Lessthan2DaysAfterAdmitDesc, Lookup87.DisplayCode AS Lessthan2DaysPostOp, 
    Lookup87.UserDescription AS Lessthan2DaysPostOpDesc, dbo.AB_Abstract.LOSDays, dbo.AB_Abstract.LOSMinutes, 
    dbo.AB_Abstract.LOSTime AS LOSTimeinHours, dbo.AB_Abstract.MaidenName, Lookup88.DisplayCode AS MaritalStatus, 
    Lookup88.UserDescription AS MaritalStatusDesc, dbo.AB_Abstract.NewbornChart AS MaternalNewbornChartNumber, 
    dbo.AB_Abstract.NewbornDischargeDate AS MaternalNewbornDischargeDate, LU_MB_Autopsy.DisplayCode AS MB_Autopsy, 
    LU_MB_Autopsy.UserDescription AS MB_AutopsyDesc, 
	dbo.AB_Manitoba.MB_Weight, 
	LU_MBEducation.DisplayCode AS MBEducation, 
    LU_MBEducation.UserDescription AS MBEducationDesc, LU_Meconium.DisplayCode AS Meconium, 
    LU_Meconium.UserDescription AS MeconiumDesc, LU_MedicationResuscitation.DisplayCode AS MedicationResuscitation, 
    LU_MedicationResuscitation.UserDescription AS MedicationResuscitationDesc, 
	
	LU_MentalLegalStatusUponArrivalED.DisplayCode as MentalHealth_LegalStatusUponArrivaltoED, 
	LU_MentalLegalStatusUponArrivalED.UserDescription as MentalHealth_LegalStatusUponArrivaltoEDDesc,
	LU_MentalLegalStatusAdmission.DisplayCode as MentalHealth_LegalStatusAtAdmission, 
	LU_MentalLegalStatusAdmission.UserDescription as MentalHealth_LegalStatusAtAdmissionDesc,
	LU_MentalTypeRestraint_1.DisplayCode as MentalHealth_TypeOfRestraint_01,
	LU_MentalTypeRestraint_1.UserDescription as MentalHealth_TypeOfRestraint_01Desc,
	LU_MentalTypeRestraint_2.DisplayCode as MentalHealth_TypeOfRestraint_02,
	LU_MentalTypeRestraint_2.UserDescription as MentalHealth_TypeOfRestraint_02Desc,
	LU_MentalTypeRestraint_3.DisplayCode as MentalHealth_TypeOfRestraint_03,
	LU_MentalTypeRestraint_3.UserDescription as MentalHealth_TypeOfRestraint_03Desc,
	LU_MentalTypeRestraint_4.DisplayCode as MentalHealth_TypeOfRestraint_04,
	LU_MentalTypeRestraint_4.UserDescription as MentalHealth_TypeOfRestraint_04Desc,
	LU_MentalFrequencyRestraintUse_1.DisplayCode as MentalHealth_FrequencyOfRestraint_01,
	LU_MentalFrequencyRestraintUse_1.UserDescription as MentalHealth_FrequencyOfRestraint_01Desc,
	LU_MentalFrequencyRestraintUse_2.DisplayCode as MentalHealth_FrequencyOfRestraint_02,
	LU_MentalFrequencyRestraintUse_2.UserDescription as MentalHealth_FrequencyOfRestraint_02Desc,
	LU_MentalFrequencyRestraintUse_3.DisplayCode as MentalHealth_FrequencyOfRestraint_03,
	LU_MentalFrequencyRestraintUse_3.UserDescription as MentalHealth_FrequencyOfRestraint_03Desc,
	LU_MentalFrequencyRestraintUse_4.DisplayCode as MentalHealth_FrequencyOfRestraint_04,
	LU_MentalFrequencyRestraintUse_4.UserDescription as MentalHealth_FrequencyOfRestraint_04Desc,

	Lookup89.DisplayCode AS MethodofAdmission, Lookup89.UserDescription AS MethodofAdmissionDesc, LU_MHInstFrom.DisplayCode AS MHFacilityTransferFrom, 
    LU_MHInstFrom.UserDescription AS MHFacilityTransferFromDesc, LU_MHInstTo.DisplayCode AS MHFacilityTransferTo, 
    LU_MHInstTo.UserDescription AS MHFacilityTransferToDesc, dbo.AB_Abstract.MiddleName, dbo.AB_Manitoba.MotherPHIN, 
    ISNULL(dbo.AB_Abstract.LastName, '' '') + '', '' + ISNULL(dbo.AB_Abstract.FirstName, '''') + '' '' + ISNULL(dbo.AB_Abstract.MiddleName, '''') AS NameFull, 
    LU_NarconMaloxone.DisplayCode AS NarconMaloxone, LU_NarconMaloxone.UserDescription AS NarconMaloxoneDesc, 
    dbo.AB_MentalHealth.MentalNumberECT AS NumberofECT, Lookup90.DisplayCode AS OccupationalTherapy, 
    Lookup90.UserDescription AS OccupationalTherapyDesc, dbo.AB_Therapeutic.OccupationalUnits, Lookup92.DisplayCode AS OtherBlood, 
    Lookup92.UserDescription AS OtherBloodDesc, Lookup93.DisplayCode AS OtherBloodCrossMatched, 
    Lookup93.UserDescription AS OtherBloodCrossMatchedDesc, Lookup94.DisplayCode AS OtherBloodTyped, 
    Lookup94.UserDescription AS OtherBloodTypedDesc, dbo.AB_Blood.OtherBloodUnits, Lookup91.DisplayCode AS OtherMedicalDeath, 
    Lookup91.UserDescription AS OtherMedicalDeathDesc, 
    dbo.AB_Manitoba.HCNExpiredDate  as OutProvinceHealthInsuranceExpiryDate,
    dbo.AB_Manitoba.Parity, dbo.AB_CancerStaging.PathMetastasis AS PathologicalMetastasis, 
    dbo.AB_CancerStaging.PathNode AS PathologicalNode, dbo.AB_CancerStaging.PathTumor AS PathologicalTumor, 
    Lookup95.DisplayCode AS Physiotherapy, Lookup95.UserDescription AS PhysiotherapyDesc, dbo.AB_Therapeutic.PhysioUnits, 
    Lookup96.DisplayCode AS Plasma, Lookup96.UserDescription AS PlasmaDesc, Lookup97.DisplayCode AS PlasmaCrossMatched, 
    Lookup97.UserDescription AS PlasmaCrossMatchedDesc, Lookup98.DisplayCode AS PlasmaTyped, Lookup98.UserDescription AS PlasmaTypedDesc, 
    dbo.AB_Blood.PlasmaUnits, Lookup99.DisplayCode AS Platelets, Lookup99.UserDescription AS PlateletsDesc, 
    Lookup100.DisplayCode AS PlateletsCrossMatched, Lookup100.UserDescription AS PlateletsCrossMatchedDesc, 
    Lookup101.DisplayCode AS PlateletsTyped, Lookup101.UserDescription AS PlateletsTypedDesc, dbo.AB_Blood.PlateletsUnits, 
    dbo.AB_Abstract.PostalCode, 

    -- ED - 01682
    dbo.GetPostalDescription(isnull(dbo.AB_Abstract.PostalCode, ''''), isnull(dbo.AB_Abstract.DischargeDate, dbo.AB_Abstract.AdmitDate)) AS PostalCodeDesc, -- ED - 01682

    --PR - 03622
    LU_PositionDelviery.DisplayCode as PositionatDelivery, LU_PositionDelviery.UserDescription as PositionatDeliveryDesc, 

    LU_PostConceptionalFolicAcid.DisplayCode AS PostConceptionalFolicAcid, 
    LU_PostConceptionalFolicAcid.UserDescription AS PostConceptionalFolicAcidDesc, dbo.AB_Abstract.PostOpDays, 
    Lookup103.DisplayCode AS PreAdmitWorkup, Lookup103.UserDescription AS PreAdmitWorkupDesc, 
    LU_PreConceptionalFolicAcid.DisplayCode AS PreConceptionalFolicAcid, 
    LU_PreConceptionalFolicAcid.UserDescription AS PreConceptionalFolicAcidDesc, Lookup104.DisplayCode AS Pregnancy, 
    Lookup104.UserDescription AS PregnancyDesc, dbo.AB_Manitoba.PrenatalVisitDate, 
    LU_PrenatalVisitDateUnknown.DisplayCode AS PrenatalVisitDateUnknown, 
    LU_PrenatalVisitDateUnknown.UserDescription AS PrenatalVisitDateUnknownDesc, 
    --ED - 01702
    -- dbo.AB_Manitoba.NumberPrenatalVisits AS PrenatalVisitsNumber, 
    (case when isnull(DischargeDate, AdmitDate) < ''2008/04/01'' then dbo.AB_Manitoba.NumberPrenatalVisits else dbo.AB_Manitoba.NumberPrenatal end) AS PrenatalVisitsNumber, 

    dbo.AB_Abstract.PreOpDays, LU_Presentation.DisplayCode AS Presentation, LU_Presentation.UserDescription AS PresentationDesc, 
    --PR - 03622
    LU_PresentDelivery.DisplayCode as PresentationatDelivery, LU_PresentDelivery.UserDescription as PresentationatDeliveryDesc, 

    dbo.AB_Manitoba.PreviousName, Lookup105.DisplayCode AS PreviousPsychiartricAdmissions, 
    Lookup105.UserDescription AS PreviousPsychiartricAdmDesc, dbo.AB_Manitoba.PrimaryAddress, dbo.AB_Manitoba.PrimaryAddress2, 
    dbo.AB_Manitoba.PrimaryPhone, Lookup106.DisplayCode AS ReAdmitCode, Lookup106.UserDescription AS ReAdmitCodeDesc, 
    --PR - 04577
    LU_ReciprocalBillingStatus.DisplayCode AS ReciprocalBillingStatus, LU_ReciprocalBillingStatus.UserDescription AS ReciprocalBillingStatusDesc,

    Lookup107.DisplayCode AS RedBloodCell, Lookup107.UserDescription AS RedBloodCellDesc, 
    Lookup108.DisplayCode AS RedBloodCellCrossMatched, Lookup108.UserDescription AS RedBloodCellCrossMatchedDesc, 
    Lookup109.DisplayCode AS RedBloodCellTyped, Lookup109.UserDescription AS RedBloodCellTypedDesc, 
    dbo.AB_Blood.RedCellUnits AS RedBloodCellUnits, Lookup110.DisplayCode AS ReferredTo, Lookup110.UserDescription AS ReferredToDesc, 
    LU_RefProvider.DisplayCode AS ReferringProvider, LU_RefProvider.UserDescription AS ReferringProviderDesc, dbo.AB_Abstract.RegisterNumber, 
    dbo.AB_Manitoba.RegistrantFirstName AS RegistrantGivenName, dbo.AB_Manitoba.RegistrantLastName AS RegistrantSurname, 
    Lookup111.DisplayCode AS ReportingProvInstNumber, Lookup111.UserDescription AS ReportingProvInstNumberDesc, 
    dbo.AB_ReproductiveCare.ReprodComments AS ReproductiveCareComments, Lookup112.DisplayCode AS ResidenceCode, 
    Lookup112.UserDescription AS ResidenceCodeDesc, LUResidenceProvince.DisplayCode AS ResidenceProvince, 
    LUResidenceProvince.UserDescription AS ResidenceProvinceDesc, LUResidenceRegion.DisplayCode AS ResidenceRegion, 
    LUResidenceRegion.UserDescription AS ResidenceRegionDesc, Lookup113.DisplayCode AS RespiratoryTherapy, 
    Lookup113.UserDescription AS RespiratoryTherapyDesc, dbo.AB_Therapeutic.RespiratoryUnits, Lookup114.DisplayCode AS ResponsiblityForPayment,
    Lookup114.UserDescription AS ResponsiblityForPaymentDesc, LU_RoutineCare.DisplayCode AS RoutineCare, 
    LU_RoutineCare.UserDescription AS RoutineCareDesc, dbo.AB_Abstract.SecondChartRegNumber AS SecondChartRegisterNumber, 
    Lookup115.DisplayCode AS SecondOptionalTherapy, Lookup115.UserDescription AS SecondOptionalTherapyDesc, 
    dbo.AB_Therapeutic.SecondOptionUnits AS SecondOptionalUnits, dbo.AB_Manitoba.SecondStageDuration, 
    Lookup116.DisplayCode AS SecretVIPPatient, Lookup116.UserDescription AS SecretVIPPatientDesc, Lookup117.DisplayCode AS SiteNumber, 
    Lookup117.UserDescription AS SiteNumberDesc, 
    LU_SmokingInPregnancy.DisplayCode AS SmokingInPregnancy, LU_SmokingInPregnancy.UserDescription AS SmokingInPregnancyDesc, 
    dbo.AB_Manitoba.SmokingPerDay, dbo.AB_Manitoba.SmokingQuitDate, 
    LU_SmokingQuitDateUnknown.DisplayCode AS SmokingQuitDateUnknown, 
    LU_SmokingQuitDateUnknown.UserDescription AS SmokingQuitDateUnknownDesc, Lookup118.DisplayCode AS SocialServices, 
    Lookup118.UserDescription AS SocialServicesDesc, Lookup119.DisplayCode AS SourceofReferral, 
    Lookup119.UserDescription AS SourceofReferralDesc, Lookup120.DisplayCode AS SpeechTherapy, 
    Lookup120.UserDescription AS SpeechTherapyDesc, dbo.AB_Therapeutic.SpeechUnits, LU_CodeFile_1.DisplayCode AS StakeholderType, 
    LU_CodeFile_1.UserDescription AS StakeholderTypeDesc, dbo.AB_Manitoba.FirstStageDate AS StartFirstStageDate, 
    LU_FirstStageDateUnknown.DisplayCode AS StartFirstStageDateUnknown, 
    LU_FirstStageDateUnknown.UserDescription AS StartFirstStageDateUnknownDes, dbo.AB_Manitoba.FirstStageTime AS StartFirstStageTime, 
    dbo.AB_Manitoba.SecondStageDate AS StartSecondStageDate, LU_SecondStageDateUnknown.DisplayCode AS StartSecondStageDateUnknown, 
    LU_SecondStageDateUnknown.UserDescription AS StartSecondStageDateUnknown_D, dbo.AB_Manitoba.SecondStageTime AS StartSecondStageTime, 
    Lookup121.DisplayCode AS Sterilization, Lookup121.UserDescription AS SterilizationDesc, dbo.AB_Abstract.RecordType AS SubmissionType, 
    Lookup122.DisplayCode AS SubsequentOR, Lookup122.UserDescription AS SubsequentORDesc, Lookup123.DisplayCode AS Suicide, 
    Lookup123.UserDescription AS SuicideDesc, dbo.AB_CancerStaging.SummaryStage, Lookup124.DisplayCode AS SurgicalCase, 
    Lookup124.UserDescription AS SurgicalCaseDesc, Lookup125.DisplayCode AS TransfusionGiven, 
    Lookup125.UserDescription AS TransfusionGivenDesc, Lookup126.DisplayCode AS Trauma, Lookup126.UserDescription AS TraumaDesc, 
    Lookup127.DisplayCode AS TSICoder, Lookup127.UserDescription AS TSICoderDesc, dbo.AB_Abstract.TSIDate, dbo.AB_Abstract.TSITime, 
    dbo.AB_Abstract.UniqiueLifetimeID AS ULI, Lookup128.DisplayCode AS UnplannedReadmission, 
    Lookup128.UserDescription AS UnplannedReadmissionDesc, 
	dbo.AB_Abstract.UniversalEpisodeIdentifier,
    dbo.AB_Abstract.WaitTimeER AS WaitTimeInEmerg, 
    dbo.AB_Abstract.WaitTimeERHour AS WaitTimeInEmergHour, 
    dbo.AB_Abstract.Weight AS Weightingrams, 
	(case when isnumeric(replace(AB_Abstract.WeightKilo, '','', ''.'')) = 1 then cast(replace(AB_Abstract.WeightKilo, '','', ''.'') as dec(7, 3)) else null end) as WeightKG,
    dbo.AB_Abstract.AbstractID AS zzAbstractLink, 
    dbo.AB_Abstract.RegionalPatientID as zzRegionalPatientID,
    dbo.AB_Abstract.VolumeID AS zzVolumeLink
FROM         
    dbo.AB_Abstract with (nolock) LEFT OUTER JOIN
    dbo.LU_Provider LU_RefProvider with (nolock) on dbo.AB_Abstract.RefPhysician = LU_RefProvider.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_DecAdmitTimeUnknown with (nolock) on dbo.AB_Abstract.DecisionAdmitTimeUnknown = LU_DecAdmitTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_1 with (nolock) on dbo.AB_Abstract.StakeHolder = LU_CodeFile_1.Code LEFT OUTER JOIN
    dbo.AB_Manitoba with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Manitoba.AbstractID left join
    dbo.LU_CodeFile LU_Meconium with (nolock) on LU_Meconium.Code = dbo.AB_Manitoba.Meconium LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Feeding with (nolock) on dbo.AB_Manitoba.Feeding = LU_Feeding.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_ChestCompressions with (nolock) on dbo.AB_Manitoba.ChestCompressions = LU_ChestCompressions.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_NarconMaloxone with (nolock) on dbo.AB_Manitoba.NarconMaloxone = LU_NarconMaloxone.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_MedicationResuscitation with (nolock) on 
    dbo.AB_Manitoba.MedicationResuscitation = LU_MedicationResuscitation.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_IntubationNotMeconium with (nolock) on dbo.AB_Manitoba.IntubationNotMeconium = LU_IntubationNotMeconium.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_BagVentilation with (nolock) on dbo.AB_Manitoba.BagVentilation = LU_BagVentilation.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_FreeFlowOxygen with (nolock) on dbo.AB_Manitoba.FreeFlowOxygen = LU_FreeFlowOxygen.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_RoutineCare with (nolock) on dbo.AB_Manitoba.RoutineCare = LU_RoutineCare.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Presentation with (nolock) on dbo.AB_Manitoba.Presentation = LU_Presentation.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_SecondStageDateUnknown with (nolock) on 
    dbo.AB_Manitoba.SecondStageDateUnknown = LU_SecondStageDateUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_FirstStageDateUnknown with (nolock) on dbo.AB_Manitoba.FirstStageDateUnknown = LU_FirstStageDateUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PostConceptionalFolicAcid with (nolock) on 
    dbo.AB_Manitoba.PostConceptionalFolicAcid = LU_PostConceptionalFolicAcid.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PreConceptionalFolicAcid with (nolock) on dbo.AB_Manitoba.PreConceptionalFolicAcid = LU_PreConceptionalFolicAcid.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Days_WeekAlcoholConsumed with (nolock) on 
    dbo.AB_Manitoba.Days_WeekAlcoholConsumed = LU_Days_WeekAlcoholConsumed.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_AlcoholDuringPregnancy with (nolock) on dbo.AB_Manitoba.AlcoholDuringPregnancy = LU_AlcoholDuringPregnancy.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_SmokingQuitDateUnknown with (nolock) on 
    dbo.AB_Manitoba.SmokingQuitDateUnknown = LU_SmokingQuitDateUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_MBEducation with (nolock) on dbo.AB_Manitoba.ObsEducation = LU_MBEducation.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PrenatalVisitDateUnknown with (nolock) on 
    dbo.AB_Manitoba.PrenatalVisitDateUnknown = LU_PrenatalVisitDateUnknown.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_LeaveCertificates with (nolock) on dbo.AB_Manitoba.LeaveCertificates = LU_LeaveCertificates.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_Elopements with (nolock) on dbo.AB_Manitoba.Elopements = LU_Elopements.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_MB_Autopsy with (nolock) on dbo.AB_Manitoba.MB_Autopsy = LU_MB_Autopsy.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_MHInstTo with (nolock) on dbo.AB_Manitoba.MHInstTo = LU_MHInstTo.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_MHInstFrom with (nolock) on dbo.AB_Manitoba.MHInstFrom = LU_MHInstFrom.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_AbstractType with (nolock) on dbo.AB_Manitoba.AbstractType = LU_AbstractType.Code LEFT OUTER JOIN
    dbo.LU_CareType with (nolock) on dbo.AB_Abstract.CareType = dbo.LU_CareType.Code LEFT OUTER JOIN
    dbo.LU_AbstractOverflow Lookup2 with (nolock) on dbo.AB_Abstract.AbstractOverflow = Lookup2.Code LEFT OUTER JOIN
    dbo.LU_AdmitAmbulance Lookup3 with (nolock) on dbo.AB_Abstract.AdmitAmbulance = Lookup3.Code LEFT OUTER JOIN
    dbo.LU_AdmitCategory Lookup4 with (nolock) on dbo.AB_Abstract.AdmitCategory = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_NurseArea Lookup5 with (nolock) on dbo.AB_Abstract.AdmittingNurseArea = Lookup5.Code LEFT OUTER JOIN
    dbo.LU_AgeCode Lookup6 with (nolock) on dbo.AB_Abstract.AgeCode = Lookup6.Code LEFT OUTER JOIN
    dbo.LU_AgeCode Lookup7 with (nolock) on dbo.AB_Abstract.DischargeAgeCode = Lookup7.Code LEFT OUTER JOIN
    dbo.LU_Provider Lookup28 with (nolock) on dbo.AB_Abstract.AttendingPhysician = Lookup28.Code LEFT OUTER JOIN
    dbo.LU_BatchPeriod Lookup50 with (nolock) on dbo.AB_Abstract.BatchPeriod = Lookup50.Code LEFT OUTER JOIN
    dbo.U_Users Lookup54 with (nolock) on dbo.AB_Abstract.CoderNumber = Lookup54.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem Lookup55 with (nolock) on dbo.AB_Abstract.Complication = Lookup55.Code LEFT OUTER JOIN
    dbo.U_Users Lookup60 with (nolock) on dbo.AB_Abstract.DataEntryCoder = Lookup60.Code LEFT OUTER JOIN
    dbo.LU_DispositionCode_I Lookup63 with (nolock) on dbo.AB_Abstract.DispositionCode = Lookup63.Code LEFT OUTER JOIN
    dbo.LU_NurseArea Lookup64 with (nolock) on dbo.AB_Abstract.DischargeNurseArea = Lookup64.Code LEFT OUTER JOIN
    dbo.LU_TherDischPlan Lookup65 with (nolock) on dbo.AB_Abstract.DischargePlanning = Lookup65.Code LEFT OUTER JOIN
    dbo.LU_EntryCode Lookup69 with (nolock) on dbo.AB_Abstract.EntryCode = Lookup69.Code LEFT OUTER JOIN
    dbo.LU_Gender_I Lookup72 with (nolock) on dbo.AB_Abstract.Gender = Lookup72.Code LEFT OUTER JOIN
    dbo.LU_Glasgow Lookup73 with (nolock) on dbo.AB_Abstract.GlasgowComaScale = Lookup73.Code LEFT OUTER JOIN
    dbo.LU_HCNProvince Lookup75 with (nolock) on dbo.AB_Abstract.HCNProvince = Lookup75.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 Lookup77 with (nolock) on dbo.AB_Abstract.InstitutionFrom = Lookup77.Code LEFT OUTER JOIN
	LU_Institution_TypeCode LU_InstitutionFrom_Type with (nolock) on dbo.AB_Abstract.InstitutionFromType = LU_InstitutionFrom_Type.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 Lookup78 with (nolock) on dbo.AB_Abstract.InstitutionTo = Lookup78.Code LEFT OUTER JOIN
	LU_Institution_TypeCode LU_InstitutionTo_Type with (nolock) on dbo.AB_Abstract.InstitutionToType = LU_InstitutionTo_Type.Code LEFT OUTER JOIN

    dbo.U_Users Lookup79 with (nolock) on dbo.AB_Abstract.InterfaceCoder = Lookup79.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus Lookup80 with (nolock) on dbo.AB_Abstract.IsCompleted = Lookup80.Code LEFT OUTER JOIN
    dbo.LU_CIHICorrect Lookup81 with (nolock) on dbo.AB_Abstract.IsCorrected = Lookup81.Code LEFT OUTER JOIN
    dbo.LU_DeleteStatus Lookup82 with (nolock) on dbo.AB_Abstract.IsDeleted = Lookup82.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem Lookup83 with (nolock) on dbo.AB_Abstract.IsSubmited = Lookup83.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus Lookup84 with (nolock) on dbo.AB_Abstract.IsValidated = Lookup84.Code LEFT OUTER JOIN
    dbo.LU_CustomStatus with (nolock) on dbo.AB_Abstract.IsCustomValidated = LU_CustomStatus.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup85 with (nolock) on dbo.AB_Abstract.BirthDateEstimated = Lookup85.Code LEFT OUTER JOIN
    dbo.LU_MaritalStatus Lookup88 with (nolock) on dbo.AB_Abstract.MaritalStatus = Lookup88.Code LEFT OUTER JOIN
    dbo.LU_TherPreAdmitWorkUp Lookup103 with (nolock) on dbo.AB_Abstract.PreAdmitWorkUp = Lookup103.Code LEFT OUTER JOIN
    dbo.LU_ReAdmitCode Lookup106 with (nolock) on dbo.AB_Abstract.ReAdmitCode = Lookup106.Code LEFT OUTER JOIN
    dbo.H_InstitutionProfile Lookup111 with (nolock) on dbo.AB_Abstract.InstitutionNumber = Lookup111.Code LEFT OUTER JOIN
    dbo.LU_ResidenceCode Lookup112 with (nolock) on dbo.AB_Abstract.ResidenceCode = Lookup112.Code LEFT OUTER JOIN
    dbo.LU_Region LUResidenceRegion with (nolock) on Lookup112.RegionCode = LUResidenceRegion.Code LEFT OUTER JOIN
    dbo.LU_Province LUResidenceProvince with (nolock) on Lookup112.ProvinceCode = LUResidenceProvince.Code LEFT OUTER JOIN
    dbo.LU_RespPayment Lookup114 with (nolock) on dbo.AB_Abstract.ResponsiblePayment = Lookup114.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup116 with (nolock) on dbo.AB_Abstract.Secret = Lookup116.Code LEFT OUTER JOIN
    dbo.LU_Site Lookup117 with (nolock) on dbo.AB_Abstract.SiteNumber = Lookup117.Code LEFT OUTER JOIN
    dbo.LU_TherSocialService Lookup118 with (nolock) on dbo.AB_Abstract.SocialService = Lookup118.Code LEFT OUTER JOIN
    dbo.LU_SurgicalCode Lookup124 with (nolock) on dbo.AB_Abstract.SurgicalCase = Lookup124.Code LEFT OUTER JOIN
    dbo.U_Users Lookup127 with (nolock) on dbo.AB_Abstract.TSICoder = Lookup127.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup128 with (nolock) on dbo.AB_Abstract.UnplanReAdmit = Lookup128.Code LEFT OUTER JOIN
    dbo.AB_Ancillary with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Ancillary.AbstractID LEFT OUTER JOIN
    dbo.LU_Ancillary1 Lookup11 with (nolock) on dbo.AB_Ancillary.AncillaryField1 = Lookup11.Code LEFT OUTER JOIN
    dbo.LU_Ancillary10 Lookup12 with (nolock) on dbo.AB_Ancillary.AncillaryField10 = Lookup12.Code LEFT OUTER JOIN
    dbo.LU_Ancillary11 Lookup13 with (nolock) on dbo.AB_Ancillary.AncillaryField11 = Lookup13.Code LEFT OUTER JOIN
    dbo.LU_Ancillary12 Lookup14 with (nolock) on dbo.AB_Ancillary.AncillaryField12 = Lookup14.Code LEFT OUTER JOIN
    dbo.LU_Ancillary13 Lookup15 with (nolock) on dbo.AB_Ancillary.AncillaryField13 = Lookup15.Code LEFT OUTER JOIN
    dbo.LU_Ancillary14 Lookup16 with (nolock) on dbo.AB_Ancillary.AncillaryField14 = Lookup16.Code LEFT OUTER JOIN
    dbo.LU_Ancillary15 Lookup17 with (nolock) on dbo.AB_Ancillary.AncillaryField15 = Lookup17.Code LEFT OUTER JOIN
    dbo.LU_Ancillary16 Lookup18 with (nolock) on dbo.AB_Ancillary.AncillaryField16 = Lookup18.Code LEFT OUTER JOIN
    dbo.LU_Ancillary17 Lookup19 with (nolock) on dbo.AB_Ancillary.AncillaryField17 = Lookup19.Code LEFT OUTER JOIN
    dbo.LU_Ancillary2 Lookup20 with (nolock) on dbo.AB_Ancillary.AncillaryField2 = Lookup20.Code LEFT OUTER JOIN
    dbo.LU_Ancillary3 Lookup21 with (nolock) on dbo.AB_Ancillary.AncillaryField3 = Lookup21.Code LEFT OUTER JOIN
    dbo.LU_Ancillary4 Lookup22 with (nolock) on dbo.AB_Ancillary.AncillaryField4 = Lookup22.Code LEFT OUTER JOIN
    dbo.LU_Ancillary5 Lookup23 with (nolock) on dbo.AB_Ancillary.AncillaryField5 = Lookup23.Code LEFT OUTER JOIN
    dbo.LU_Ancillary6 Lookup24 with (nolock) on dbo.AB_Ancillary.AncillaryField6 = Lookup24.Code LEFT OUTER JOIN
    dbo.LU_Ancillary7 Lookup25 with (nolock) on dbo.AB_Ancillary.AncillaryField7 = Lookup25.Code LEFT OUTER JOIN
    dbo.LU_Ancillary8 Lookup26 with (nolock) on dbo.AB_Ancillary.AncillaryField8 = Lookup26.Code LEFT OUTER JOIN
    dbo.LU_Ancillary9 Lookup27 with (nolock) on dbo.AB_Ancillary.AncillaryField9 = Lookup27.Code LEFT OUTER JOIN
    dbo.AB_BasicOption with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_BasicOption.AbstractID LEFT OUTER JOIN
    dbo.LU_BasicOption1 Lookup31 with (nolock) on dbo.AB_BasicOption.BasicOption1 = Lookup31.Code LEFT OUTER JOIN
    dbo.LU_BasicOption10 Lookup32 with (nolock) on dbo.AB_BasicOption.BasicOption10 = Lookup32.Code LEFT OUTER JOIN
    dbo.LU_BasicOption11 Lookup33 with (nolock) on dbo.AB_BasicOption.BasicOption11 = Lookup33.Code LEFT OUTER JOIN
    dbo.LU_BasicOption12 Lookup34 with (nolock) on dbo.AB_BasicOption.BasicOption12 = Lookup34.Code LEFT OUTER JOIN
    dbo.LU_BasicOption13 Lookup35 with (nolock) on dbo.AB_BasicOption.BasicOption13 = Lookup35.Code LEFT OUTER JOIN
    dbo.LU_BasicOption14 Lookup36 with (nolock) on dbo.AB_BasicOption.BasicOption14 = Lookup36.Code LEFT OUTER JOIN
    dbo.LU_BasicOption15 Lookup37 with (nolock) on dbo.AB_BasicOption.BasicOption15 = Lookup37.Code LEFT OUTER JOIN
    dbo.LU_BasicOption16 Lookup38 with (nolock) on dbo.AB_BasicOption.BasicOption16 = Lookup38.Code LEFT OUTER JOIN
    dbo.LU_BasicOption17 Lookup39 with (nolock) on dbo.AB_BasicOption.BasicOption17 = Lookup39.Code LEFT OUTER JOIN
    dbo.LU_BasicOption18 Lookup40 with (nolock) on dbo.AB_BasicOption.BasicOption18 = Lookup40.Code LEFT OUTER JOIN
    dbo.LU_BasicOption19 Lookup41 with (nolock) on dbo.AB_BasicOption.BasicOption19 = Lookup41.Code LEFT OUTER JOIN
    dbo.LU_BasicOption2 Lookup42 with (nolock) on dbo.AB_BasicOption.BasicOption2 = Lookup42.Code LEFT OUTER JOIN
    dbo.LU_BasicOption3 Lookup43 with (nolock) on dbo.AB_BasicOption.BasicOption3 = Lookup43.Code LEFT OUTER JOIN
    dbo.LU_BasicOption4 Lookup44 with (nolock) on dbo.AB_BasicOption.BasicOption4 = Lookup44.Code LEFT OUTER JOIN
    dbo.LU_BasicOption5 Lookup45 with (nolock) on dbo.AB_BasicOption.BasicOption5 = Lookup45.Code LEFT OUTER JOIN
    dbo.LU_BasicOption6 Lookup46 with (nolock) on dbo.AB_BasicOption.BasicOption6 = Lookup46.Code LEFT OUTER JOIN
    dbo.LU_BasicOption7 Lookup47 with (nolock) on dbo.AB_BasicOption.BasicOption7 = Lookup47.Code LEFT OUTER JOIN
    dbo.LU_BasicOption8 Lookup48 with (nolock) on dbo.AB_BasicOption.BasicOption8 = Lookup48.Code LEFT OUTER JOIN
    dbo.LU_BasicOption9 Lookup49 with (nolock) on dbo.AB_BasicOption.BasicOption9 = Lookup49.Code LEFT OUTER JOIN
    dbo.AB_Blood with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Blood.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup8 with (nolock) on dbo.AB_Blood.Albumin = Lookup8.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup9 with (nolock) on dbo.AB_Blood.AlbuminXMatch = Lookup9.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup10 with (nolock) on dbo.AB_Blood.AlbuminTyped = Lookup10.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup29 with (nolock) on dbo.AB_Blood.AutoTransfusion = Lookup29.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup92 with (nolock) on dbo.AB_Blood.OtherBlood = Lookup92.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup93 with (nolock) on dbo.AB_Blood.OtherBloodXMatch = Lookup93.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup94 with (nolock) on dbo.AB_Blood.OtherBloodTyped = Lookup94.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup96 with (nolock) on dbo.AB_Blood.Plasma = Lookup96.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup97 with (nolock) on dbo.AB_Blood.PlasmaXMatch = Lookup97.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup98 with (nolock) on dbo.AB_Blood.PlasmaTyped = Lookup98.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup99 with (nolock) on dbo.AB_Blood.Platelets = Lookup99.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup100 with (nolock) on dbo.AB_Blood.PlateletsXMatch = Lookup100.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup101 with (nolock) on dbo.AB_Blood.PlateletsTyped = Lookup101.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup107 with (nolock) on dbo.AB_Blood.RedBloodCell = Lookup107.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup108 with (nolock) on dbo.AB_Blood.RedCellXMatch = Lookup108.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup109 with (nolock) on dbo.AB_Blood.RedCellTyped = Lookup109.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup125 with (nolock) on dbo.AB_Blood.TransfusionIndicator = Lookup125.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_AntithrombinIII with (nolock) on dbo.AB_Blood.AntithrombinIII = LU_AntithrombinIII.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_C1Inhibitor with (nolock) on dbo.AB_Blood.C1Inhibitor = LU_C1Inhibitor.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_CryoprecipitatePlasma with (nolock) on dbo.AB_Blood.CryoprecipitatePlasma = LU_CryoprecipitatePlasma.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_CryosupernatantPlasma with (nolock) on dbo.AB_Blood.CryosupernatantPlasma = LU_CryosupernatantPlasma.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_FEIBA with (nolock) on dbo.AB_Blood.FEIBA = LU_FEIBA.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_Fibrinogen with (nolock) on dbo.AB_Blood.Fibrinogen = LU_Fibrinogen.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_IVIG_SCIG with (nolock) on dbo.AB_Blood.IVIG_SCIG = LU_IVIG_SCIG.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_PCC with (nolock) on dbo.AB_Blood.PCC = LU_PCC.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_ProteinC_OtherFactors with (nolock) on dbo.AB_Blood.ProteinC_OtherFactors = LU_ProteinC_OtherFactors.Code LEFT OUTER JOIN


    dbo.AB_DeathInformation with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_DeathInformation.AbstractID LEFT OUTER JOIN
    dbo.LU_AutopsyDeath Lookup30 with (nolock) on dbo.AB_DeathInformation.AutopsyPerformed = Lookup30.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup51 with (nolock) on dbo.AB_DeathInformation.DeathTwoTenPO = Lookup51.Code LEFT OUTER JOIN
    dbo.LU_CoronerCase Lookup59 with (nolock) on dbo.AB_DeathInformation.CoronerCase = Lookup59.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup61 with (nolock) on dbo.AB_DeathInformation.DeathInOR = Lookup61.Code left join
    dbo.LU_SCU_Death Lookup62 with (nolock) on Lookup62.Code = dbo.AB_DeathInformation.DeathInSCU LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup74 with (nolock) on dbo.AB_DeathInformation.DeathGreaterTenPO = Lookup74.Code left join
    dbo.LU_YesBlank Lookup86 with (nolock) on Lookup86.Code = dbo.AB_DeathInformation.DeathAfterAdmit LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup87 with (nolock) on dbo.AB_DeathInformation.DeathLessTwoPO = Lookup87.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup91 with (nolock) on dbo.AB_DeathInformation.OtherDeath = Lookup91.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup104 with (nolock) on dbo.AB_DeathInformation.PregnancyDeath = Lookup104.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup126 with (nolock) on dbo.AB_DeathInformation.TraumaDeath = Lookup126.Code left join
    
	dbo.AB_MentalHealth with (nolock) on dbo.AB_MentalHealth.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup1 with (nolock) on dbo.AB_MentalHealth.MentalAWOL = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_MentalLegalStatus Lookup53 with (nolock) on dbo.AB_MentalHealth.MentalLegalStatus = Lookup53.Code left join
    dbo.LU_YesNoNumeric Lookup66 with (nolock) on Lookup66.Code = dbo.AB_MentalHealth.MentalECTTreatment LEFT OUTER JOIN
    dbo.LU_MentalEducation Lookup67 with (nolock) on dbo.AB_MentalHealth.MentalEducation = Lookup67.Code LEFT OUTER JOIN
    dbo.LU_MentalEmployment Lookup68 with (nolock) on dbo.AB_MentalHealth.MentalEmployment = Lookup68.Code LEFT OUTER JOIN
    dbo.LU_MentalFinancial Lookup70 with (nolock) on dbo.AB_MentalHealth.MentalFinancial = Lookup70.Code LEFT OUTER JOIN
    dbo.LU_MentalAdmitMethod Lookup89 with (nolock) on dbo.AB_MentalHealth.MentalAdmitMethod = Lookup89.Code LEFT OUTER JOIN
    dbo.LU_MentalPrevPsych Lookup105 with (nolock) on dbo.AB_MentalHealth.MentalPrevPsych = Lookup105.Code left join
    dbo.LU_MentalReferral Lookup110 with (nolock) on Lookup110.Code = dbo.AB_MentalHealth.MentalReferralTo LEFT OUTER JOIN
    dbo.LU_MentalReferral Lookup119 with (nolock) on dbo.AB_MentalHealth.MentalReferralSource = Lookup119.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup123 with (nolock) on dbo.AB_MentalHealth.MentalSuicide = Lookup123.Code LEFT OUTER JOIN

	dbo.LU_MentalLegalStatusUponArrivalED with (nolock) on dbo.AB_MentalHealth.LegalStatusUponArrivaltoED = LU_MentalLegalStatusUponArrivalED.Code LEFT OUTER JOIN
	dbo.LU_MentalLegalStatusAdmission with (nolock) on dbo.AB_MentalHealth.LegalStatusAtAdmission = LU_MentalLegalStatusAdmission.Code LEFT OUTER JOIN
	dbo.LU_MentalTypeRestraint LU_MentalTypeRestraint_1 with (nolock) on dbo.AB_MentalHealth.TypeOfRestraint01 = LU_MentalTypeRestraint_1.Code LEFT OUTER JOIN
	dbo.LU_MentalFrequencyRestraintUse LU_MentalFrequencyRestraintUse_1 with (nolock) on dbo.AB_MentalHealth.FrequencyOfRestraint01 = LU_MentalFrequencyRestraintUse_1.Code LEFT OUTER JOIN
	dbo.LU_MentalTypeRestraint LU_MentalTypeRestraint_2 with (nolock) on dbo.AB_MentalHealth.TypeOfRestraint02 = LU_MentalTypeRestraint_2.Code LEFT OUTER JOIN
	dbo.LU_MentalFrequencyRestraintUse LU_MentalFrequencyRestraintUse_2 with (nolock) on dbo.AB_MentalHealth.FrequencyOfRestraint02 = LU_MentalFrequencyRestraintUse_2.Code LEFT OUTER JOIN
	dbo.LU_MentalTypeRestraint LU_MentalTypeRestraint_3 with (nolock) on dbo.AB_MentalHealth.TypeOfRestraint03 = LU_MentalTypeRestraint_3.Code LEFT OUTER JOIN
	dbo.LU_MentalFrequencyRestraintUse LU_MentalFrequencyRestraintUse_3 with (nolock) on dbo.AB_MentalHealth.FrequencyOfRestraint03 = LU_MentalFrequencyRestraintUse_3.Code LEFT OUTER JOIN
	dbo.LU_MentalTypeRestraint LU_MentalTypeRestraint_4 with (nolock) on dbo.AB_MentalHealth.TypeOfRestraint04 = LU_MentalTypeRestraint_4.Code LEFT OUTER JOIN
	dbo.LU_MentalFrequencyRestraintUse LU_MentalFrequencyRestraintUse_4 with (nolock) on dbo.AB_MentalHealth.FrequencyOfRestraint04 = LU_MentalFrequencyRestraintUse_4.Code LEFT OUTER JOIN


    dbo.AB_Therapeutic with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Therapeutic.AbstractID LEFT OUTER JOIN
    dbo.LU_TherOption1 Lookup71 with (nolock) on dbo.AB_Therapeutic.FirstOptionTherapy = Lookup71.Code LEFT OUTER JOIN
    dbo.LU_TherOccupation Lookup90 with (nolock) on dbo.AB_Therapeutic.OccupationalTherapy = Lookup90.Code left join
    dbo.LU_TherPhysio Lookup95 with (nolock) on Lookup95.Code = dbo.AB_Therapeutic.PhysioTherapy LEFT OUTER JOIN
    dbo.LU_TherRespiratory Lookup113 with (nolock) on dbo.AB_Therapeutic.RespiratoryTherapy = Lookup113.Code LEFT OUTER JOIN
    dbo.LU_TherOption2 Lookup115 with (nolock) on dbo.AB_Therapeutic.SecondOptionTherapy = Lookup115.Code LEFT OUTER JOIN
    dbo.LU_TherSpeech Lookup120 with (nolock) on dbo.AB_Therapeutic.SpeechTherapy = Lookup120.Code LEFT OUTER JOIN
    dbo.AB_ReproductiveCare with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_ReproductiveCare.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup52 with (nolock) on dbo.AB_ReproductiveCare.BreastFeeding = Lookup52.Code left join
    dbo.LU_ReprodComplication Lookup56 with (nolock) on Lookup56.Code = dbo.AB_ReproductiveCare.Complication1 left join
    dbo.LU_ReprodComplication Lookup57 with (nolock) on Lookup57.Code = dbo.AB_ReproductiveCare.Complication2 LEFT OUTER JOIN
    dbo.LU_ReprodComplication Lookup58 with (nolock) on dbo.AB_ReproductiveCare.Complication3 = Lookup58.Code LEFT OUTER JOIN
    dbo.LU_ReprodOR Lookup76 with (nolock) on dbo.AB_ReproductiveCare.InitialOR = Lookup76.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup121 with (nolock) on dbo.AB_ReproductiveCare.Sterilization = Lookup121.Code LEFT OUTER JOIN
    dbo.LU_ReprodOR Lookup122 with (nolock) on dbo.AB_ReproductiveCare.SubsequentOR = Lookup122.Code LEFT OUTER JOIN
    dbo.AB_CancerStaging with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_CancerStaging.AbstractID LEFT OUTER JOIN
    dbo.H_HospitalProfile with (nolock) on dbo.AB_Abstract.HospitalID = dbo.H_HospitalProfile.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_TimeLeftERUnknown with (nolock) on dbo.AB_Abstract.TimeLeftERUnknown = LU_TimeLeftERUnknown.Code 
    --PR - 03622
    LEFT OUTER JOIN dbo.LU_CodeFile LU_PresentDelivery with (nolock) on dbo.AB_Manitoba.PresentDelivery = LU_PresentDelivery.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_PositionDelviery with (nolock) on dbo.AB_Manitoba.PositionDelviery = LU_PositionDelviery.Code 
--ED - 01750
    LEFT OUTER JOIN dbo.LU_CodeFile LU_AnestheticLabor with (nolock) on dbo.AB_Manitoba.AnestheticLabor = LU_AnestheticLabor.Code 
--PR - 04577
    LEFT OUTER JOIN dbo.LU_ReciprocalBillingStatus with (nolock) on dbo.AB_Abstract.IsReciprocalBilling = LU_ReciprocalBillingStatus.Code 
--PR - 05489
    LEFT OUTER JOIN dbo.LU_CodeFile LU_AdmitTimeUnknown with (nolock) on dbo.AB_Abstract.AdmitTimeUnknown = LU_AdmitTimeUnknown.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_DischargeTimeUnknown with (nolock) on dbo.AB_Abstract.DischargeTimeUnknown = LU_DischargeTimeUnknown.Code 
    
    LEFT OUTER JOIN dbo.LU_CodeFile LU_SmokingInPregnancy with (nolock) on dbo.AB_Manitoba.SmokingInPregnancy = LU_SmokingInPregnancy.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_AlcoholQuitDateUnknown with (nolock) on dbo.AB_Manitoba.AlcoholQuitDateUnknown = LU_AlcoholQuitDateUnknown.Code 
WHERE     (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType IN (101, 102)) 
--QA - 00032 disable the domain securite issue
----PR - 07485
--    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB_ABstract.HospitalID is null or AB_ABstract.HospitalID = 0
----EN - 00666
--        or Is_Member(nullif(ReportGroup, '''')) = 1)
----        or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB_ABstract.HospitalID, 0))




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AbstractingBasics1_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE  VIEW [dbo].[I10_AbstractingBasics1_VR]
AS
SELECT     
	dbo.AB_Abstract.ALCLOS, dbo.AB_Abstract.AbstractNumber, Lookup2.DisplayCode AS AbstractOverflow, 
	Lookup2.UserDescription AS AbstractOverflowDesc, dbo.AB_Abstract.AcuteLOS, dbo.AB_Abstract.AdmitDate AS AdmissionDate, 
	dbo.AB_Abstract.AdmitTime AS AdmissionTime, 
	--PR - 05489
	LU_AdmitTimeUnknown.DisplayCode as AdmissionTimeUnknown, LU_AdmitTimeUnknown.UserDescription as AdmissionTimeUnknownDesc,
                      
	Lookup3.DisplayCode AS AdmitbyAmbulance, Lookup3.UserDescription AS AdmitbyAmbulanceDesc, 
	Lookup4.DisplayCode AS AdmitCategory, Lookup4.UserDescription AS AdmitCategoryDesc, Lookup5.DisplayCode AS AdmitNursingAreaUnitLocation, 
	Lookup5.UserDescription AS AdmittingNursingAreaUnitLDesc, Lookup6.DisplayCode AS AgeCode, Lookup6.UserDescription AS AgeCodeDesc, 
	dbo.AB_Abstract.AgeGroup, dbo.AB_Abstract.AgeNumber, dbo.AB_Abstract.DischargeAge AS AgeUponDischarge, 
	Lookup7.DisplayCode AS AgeUponDischargeCode, Lookup7.UserDescription AS AgeUponDischargeCodeDesc, 
	Lookup28.DisplayCode AS AttendingPhysician, Lookup28.UserDescription AS AttendingPhysicianDesc, Lookup30.DisplayCode AS AutopsyPerformed, 
	Lookup30.UserDescription AS AutopsyPerformedDesc, dbo.AB_Abstract.BatchNumber, Lookup50.DisplayCode AS BatchPeriod, 
	Lookup50.UserDescription AS BatchPeriodDesc, dbo.AB_Abstract.BatchYear, Lookup51.DisplayCode AS Between210DaysPostOp, 
	Lookup51.UserDescription AS Between210DaysPostOpDesc, dbo.AB_Abstract.BirthDate, dbo.LU_CareType.DisplayCode AS CareType, 
	dbo.LU_CareType.UserDescription AS CareTypeDesc, dbo.AB_Abstract.ChartNumber, 
	dbo.AB_Abstract.ChiefComplaint AS ChiefComplaintUponAdmission, Lookup54.DisplayCode AS CoderNumber, 
	Lookup54.UserDescription AS CoderNumberDesc, Lookup55.DisplayCode AS Complication, Lookup55.UserDescription AS ComplicationDesc, 
	Lookup59.DisplayCode AS CoronerCase, Lookup59.UserDescription AS CoronerCaseDesc, Lookup60.DisplayCode AS DataEntryCoder, 
	Lookup60.UserDescription AS DataEntryCoderDesc, dbo.AB_Abstract.DateReadyDischarge AS DateReadyForDischarge, 
	dbo.AB_Abstract.CIHIDateSent AS DateSenttoCIHI, Lookup61.DisplayCode AS DeathInOR, Lookup61.UserDescription AS DeathInORDesc, 
	Lookup62.DisplayCode AS DeathInSCU, Lookup62.UserDescription AS DeathInSCUDesc, dbo.AB_Abstract.DischargeDate, 
	Lookup63.DisplayCode AS DischargeDisposition, Lookup63.UserDescription AS DischargeDispositionDesc, 
	Lookup64.DisplayCode AS DischNursingAreaUnitLocation, Lookup64.UserDescription AS DischargeNursingAreaUnitDesc, 
	Lookup65.DisplayCode AS DischargePlanning, Lookup65.UserDescription AS DischargePlanningDesc, dbo.AB_Abstract.DischargeTime, 
	--PR - 05489
	LU_DischargeTimeUnknown.DisplayCode AS DischargeTimeUnknown, LU_DischargeTimeUnknown.UserDescription AS DischargeTimeUnknownDesc, 
                      
	dbo.AB_Abstract.DateLeftER AS ERDatePatientLeft, dbo.AB_Abstract.DecisionAdmitDate AS ERDecisiontoAdmitDate, 
	dbo.AB_Abstract.DecisionAdmitTime AS ERDecisiontoAdmitTime, dbo.AB_Abstract.TimeLeftER AS ERTimePatientLeft, 
	dbo.AB_Abstract.EncounterNumber, Lookup69.DisplayCode AS EntryCode, Lookup69.UserDescription AS EntryCodeDesc, dbo.AB_Abstract.FinishDate, 
	dbo.AB_Abstract.FinishTime, dbo.AB_Abstract.FirstName, 
	FixedChartNumber,
	Lookup72.DisplayCode AS Gender, Lookup72.UserDescription AS GenderDesc, 
	Lookup73.DisplayCode AS GlasgowComaScale, Lookup73.UserDescription AS GlasgowComaScaleDesc, 
	Lookup74.DisplayCode AS Greaterthan10DaysPostOp, Lookup74.UserDescription AS Greaterthan10DaysPostOpDesc, 
	Lookup75.DisplayCode AS HCNProvince, Lookup75.UserDescription AS HCNProvinceDesc, dbo.AB_Abstract.HCNVersion, 
	dbo.AB_Abstract.HealthCareNumber, LU_Hospital.DisplayCode AS Hospital, LU_Hospital.UserDescription AS HospitalDesc, dbo.AB_Abstract.ICDType, 
	dbo.AB_Abstract.InputDate, dbo.AB_Abstract.InputTime, 
	
	Lookup77.DisplayCode AS InstitutionFrom, Lookup77.UserDescription AS InstitutionFromDesc, 
	LU_InstitutionFrom_Type.DisplayCode AS InstitutionFromType, LU_InstitutionFrom_Type.UserDescription AS InstitutionFromTypeDesc, 
	Lookup77.InstCareType AS InstFromCareType, Lookup77.HospitalType AS InstFromHospType, 

	Lookup78.DisplayCode AS InstitutionTo, 	Lookup78.UserDescription AS InstitutionToDesc, 
	LU_InstitutionTo_Type.DisplayCode AS InstitutionToType, LU_InstitutionTo_Type.UserDescription AS InstitutionToTypeDesc, 
	Lookup78.InstCareType AS InstToCareType, Lookup78.HospitalType AS InstToHospType, 

	Lookup79.DisplayCode AS InterfaceCoder, Lookup79.UserDescription AS InterfaceCoderDesc, dbo.AB_Abstract.InterfaceDate, 
	dbo.AB_Abstract.InterfaceTime, Lookup80.DisplayCode AS IsAbstractCompleted, Lookup80.UserDescription AS IsAbstractCompletedDesc, 
	Lookup81.DisplayCode AS IsAbstractCorrected, Lookup81.UserDescription AS IsAbstractCorrectedDesc, Lookup82.DisplayCode AS IsAbstractDeleted, 
	Lookup82.UserDescription AS IsAbstractDeletedDesc, Lookup83.DisplayCode AS IsAbstractSubmited, 
	Lookup83.UserDescription AS IsAbstractSubmitedDesc, Lookup84.DisplayCode AS IsAbstractValidated, 
	Lookup84.UserDescription AS IsAbstractValidatedDesc, Lookup85.DisplayCode AS IsBirthdateEstimated, 
	Lookup85.UserDescription AS IsBirthdateEstimatedDesc, 
	LU_CustomStatus.DisplayCode AS IsCustomValidated, LU_CustomStatus.UserDescription AS IsCustomValidatedDesc, 
					  
	dbo.AB_Abstract.LOSDays, dbo.AB_Abstract.LOSMinutes, 
	dbo.AB_Abstract.LOSTime AS LOSTimeinHours, dbo.AB_Abstract.LastName, Lookup86.DisplayCode AS Lessthan2DaysAfterAdmission, 
	Lookup86.UserDescription AS Lessthan2DaysAfterAdmitDesc, Lookup87.DisplayCode AS Lessthan2DaysPostOp, 
	Lookup87.UserDescription AS Lessthan2DaysPostOpDesc, dbo.AB_Abstract.MaidenName, Lookup88.DisplayCode AS MaritalStatus, 
	Lookup88.UserDescription AS MaritalStatusDesc, dbo.AB_Abstract.NewbornChart AS MaternalNewbornChartNumber, 
	dbo.AB_Abstract.NewbornDischargeDate AS MaternalNewbornDischargeDate, dbo.AB_Abstract.MiddleName, ISNULL(dbo.AB_Abstract.LastName, '' '') 
	+ '', '' + ISNULL(dbo.AB_Abstract.FirstName, '''') + '' '' + ISNULL(dbo.AB_Abstract.MiddleName, '''') AS NameFull, 
	Lookup91.DisplayCode AS OtherMedicalDeath, Lookup91.UserDescription AS OtherMedicalDeathDesc, dbo.AB_Abstract.PostalCode, 

	-- ED - 01682
	dbo.GetPostalDescription(isnull(dbo.AB_Abstract.PostalCode, ''''), isnull(dbo.AB_Abstract.DischargeDate, dbo.AB_Abstract.AdmitDate)) AS PostalDescription, -- ED - 01682

	dbo.AB_Abstract.PostOpDays, Lookup103.DisplayCode AS PreAdmitWorkup, Lookup103.UserDescription AS PreAdmitWorkupDesc, 
	Lookup104.DisplayCode AS Pregnancy, Lookup104.UserDescription AS PregnancyDesc, dbo.AB_Abstract.PreOpDays, 
	Lookup106.DisplayCode AS ReAdmitCode, Lookup106.UserDescription AS ReAdmitCodeDesc, dbo.AB_Abstract.RegisterNumber, 
	Lookup111.DisplayCode AS ReportingProvInstNumber, Lookup111.UserDescription AS ReportingProvInstNumberDesc, 
	Lookup112.DisplayCode AS ResidenceCode, Lookup112.UserDescription AS ResidenceCodeDesc, 
	Lookup114.DisplayCode AS ResponsiblityForPayment, Lookup114.UserDescription AS ResponsiblityForPaymentDesc, 
	dbo.AB_Abstract.SecondChartRegNumber AS SecondChartRegisterNumber, Lookup116.DisplayCode AS SecretVIPPatient, 
	Lookup116.UserDescription AS SecretVIPPatientDesc, Lookup117.DisplayCode AS SiteNumber, Lookup117.UserDescription AS SiteNumberDesc, 
	Lookup118.DisplayCode AS SocialServices, Lookup118.UserDescription AS SocialServicesDesc, 
	LU_StakeholderType.DisplayCode AS StakeholderType, LU_StakeholderType.UserDescription AS StakeholderTypeDesc, 
	dbo.AB_Abstract.RecordType AS SubmissionType, Lookup124.DisplayCode AS SurgicalCase, Lookup124.UserDescription AS SurgicalCaseDesc, 
	Lookup126.DisplayCode AS Trauma, Lookup126.UserDescription AS TraumaDesc, Lookup127.DisplayCode AS TSICoder, 
	Lookup127.UserDescription AS TSICoderDesc, dbo.AB_Abstract.TSIDate, dbo.AB_Abstract.TSITime, dbo.AB_Abstract.UniqiueLifetimeID AS ULI, 
	Lookup128.DisplayCode AS UnplannedReadmission, Lookup128.UserDescription AS UnplannedReadmissionDesc, 
	dbo.AB_Abstract.Weight AS Weightingrams, 
	dbo.AB_Abstract.AbstractID AS zzAbstractLink, 
	dbo.AB_Abstract.RegionalPatientID as zzRegionalPatientID, 
                      dbo.AB_Abstract.VolumeID AS zzVolumeLink
FROM         dbo.AB_Abstract with (nolock) LEFT OUTER JOIN
	dbo.LU_CodeFile LU_StakeholderType with (nolock) on dbo.AB_Abstract.StakeHolder = LU_StakeholderType.Code LEFT OUTER JOIN
	dbo.H_HospitalProfile LU_Hospital with (nolock) on dbo.AB_Abstract.HospitalID = LU_Hospital.Code LEFT OUTER JOIN
	dbo.LU_CareType with (nolock) on dbo.AB_Abstract.CareType = dbo.LU_CareType.Code LEFT OUTER JOIN
	dbo.LU_AbstractOverflow Lookup2 with (nolock) on dbo.AB_Abstract.AbstractOverflow = Lookup2.Code LEFT OUTER JOIN
	dbo.LU_AdmitAmbulance Lookup3 with (nolock) on dbo.AB_Abstract.AdmitAmbulance = Lookup3.Code LEFT OUTER JOIN
	dbo.LU_AdmitCategory Lookup4 with (nolock) on dbo.AB_Abstract.AdmitCategory = Lookup4.Code LEFT OUTER JOIN
	dbo.LU_NurseArea Lookup5 with (nolock) on dbo.AB_Abstract.AdmittingNurseArea = Lookup5.Code LEFT OUTER JOIN
	dbo.LU_AgeCode Lookup6 with (nolock) on dbo.AB_Abstract.AgeCode = Lookup6.Code LEFT OUTER JOIN
	dbo.LU_AgeCode Lookup7 with (nolock) on dbo.AB_Abstract.DischargeAgeCode = Lookup7.Code LEFT OUTER JOIN
	dbo.LU_Provider Lookup28 with (nolock) on dbo.AB_Abstract.AttendingPhysician = Lookup28.Code LEFT OUTER JOIN
	dbo.LU_BatchPeriod Lookup50 with (nolock) on dbo.AB_Abstract.BatchPeriod = Lookup50.Code LEFT OUTER JOIN
	dbo.U_Users Lookup54 with (nolock) on dbo.AB_Abstract.CoderNumber = Lookup54.Code LEFT OUTER JOIN
	dbo.LU_YesBlank Lookup55 with (nolock) on dbo.AB_Abstract.Complication = Lookup55.Code LEFT OUTER JOIN
	dbo.U_Users Lookup60 with (nolock) on dbo.AB_Abstract.DataEntryCoder = Lookup60.Code LEFT OUTER JOIN
	dbo.LU_DispositionCode_I Lookup63 with (nolock) on dbo.AB_Abstract.DispositionCode = Lookup63.Code LEFT OUTER JOIN
	dbo.LU_NurseArea Lookup64 with (nolock) on dbo.AB_Abstract.DischargeNurseArea = Lookup64.Code LEFT OUTER JOIN
	dbo.LU_TherDischPlan Lookup65 with (nolock) on dbo.AB_Abstract.DischargePlanning = Lookup65.Code LEFT OUTER JOIN
	dbo.LU_EntryCode Lookup69 with (nolock) on dbo.AB_Abstract.EntryCode = Lookup69.Code LEFT OUTER JOIN
	dbo.LU_Gender_I Lookup72 with (nolock) on dbo.AB_Abstract.Gender = Lookup72.Code LEFT OUTER JOIN
	dbo.LU_YesBlank Lookup73 with (nolock) on dbo.AB_Abstract.GlasgowComaScale = Lookup73.Code LEFT OUTER JOIN
	dbo.LU_HCNProvince Lookup75 with (nolock) on dbo.AB_Abstract.HCNProvince = Lookup75.Code LEFT OUTER JOIN
	
	dbo.LU_Institution_10 Lookup77 with (nolock) on dbo.AB_Abstract.InstitutionFrom = Lookup77.Code LEFT OUTER JOIN
	LU_Institution_TypeCode LU_InstitutionFrom_Type with (nolock) on dbo.AB_Abstract.InstitutionFromType = LU_InstitutionFrom_Type.Code LEFT OUTER JOIN
	dbo.LU_Institution_10 Lookup78 with (nolock) on dbo.AB_Abstract.InstitutionTo = Lookup78.Code LEFT OUTER JOIN
	LU_Institution_TypeCode LU_InstitutionTo_Type with (nolock) on dbo.AB_Abstract.InstitutionToType = LU_InstitutionTo_Type.Code LEFT OUTER JOIN

	dbo.U_Users Lookup79 with (nolock) on dbo.AB_Abstract.InterfaceCoder = Lookup79.Code LEFT OUTER JOIN
	dbo.LU_AbstractStatus Lookup80 with (nolock) on dbo.AB_Abstract.IsCompleted = Lookup80.Code LEFT OUTER JOIN
	dbo.LU_CIHICorrect Lookup81 with (nolock) on dbo.AB_Abstract.IsCorrected = Lookup81.Code LEFT OUTER JOIN
	dbo.LU_YesNoSystem Lookup82 with (nolock) on dbo.AB_Abstract.IsDeleted = Lookup82.Code LEFT OUTER JOIN
	dbo.LU_YesNoSystem Lookup83 with (nolock) on dbo.AB_Abstract.IsSubmited = Lookup83.Code LEFT OUTER JOIN
	dbo.LU_AbstractStatus Lookup84 with (nolock) on dbo.AB_Abstract.IsValidated = Lookup84.Code LEFT OUTER JOIN
    dbo.LU_CustomStatus with (nolock) on dbo.AB_Abstract.IsCustomValidated = LU_CustomStatus.Code LEFT OUTER JOIN
	dbo.LU_YesBlank Lookup85 with (nolock) on dbo.AB_Abstract.BirthDateEstimated = Lookup85.Code LEFT OUTER JOIN
	dbo.LU_MaritalStatus Lookup88 with (nolock) on dbo.AB_Abstract.MaritalStatus = Lookup88.Code LEFT OUTER JOIN
	dbo.LU_TherPreAdmitWorkUp Lookup103 with (nolock) on dbo.AB_Abstract.PreAdmitWorkUp = Lookup103.Code LEFT OUTER JOIN
	dbo.LU_ReAdmitCode Lookup106 with (nolock) on dbo.AB_Abstract.ReAdmitCode = Lookup106.Code LEFT OUTER JOIN
	dbo.H_InstitutionProfile Lookup111 with (nolock) on dbo.AB_Abstract.InstitutionNumber = Lookup111.Code LEFT OUTER JOIN
	dbo.LU_ResidenceCode Lookup112 with (nolock) on dbo.AB_Abstract.ResidenceCode = Lookup112.Code LEFT OUTER JOIN
	dbo.LU_RespPayment Lookup114 with (nolock) on dbo.AB_Abstract.ResponsiblePayment = Lookup114.Code LEFT OUTER JOIN
	dbo.LU_YesBlank Lookup116 with (nolock) on dbo.AB_Abstract.Secret = Lookup116.Code LEFT OUTER JOIN
	dbo.LU_Site Lookup117 with (nolock) on dbo.AB_Abstract.SiteNumber = Lookup117.Code LEFT OUTER JOIN
	dbo.LU_TherSocialService Lookup118 with (nolock) on dbo.AB_Abstract.SocialService = Lookup118.Code LEFT OUTER JOIN
	dbo.LU_SurgicalCode Lookup124 with (nolock) on dbo.AB_Abstract.SurgicalCase = Lookup124.Code LEFT OUTER JOIN
	dbo.U_Users Lookup127 with (nolock) on dbo.AB_Abstract.TSICoder = Lookup127.Code LEFT OUTER JOIN
	dbo.LU_YesBlank Lookup128 with (nolock) on dbo.AB_Abstract.UnplanReAdmit = Lookup128.Code LEFT OUTER JOIN
	dbo.AB_DeathInformation with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_DeathInformation.AbstractID LEFT OUTER JOIN
	dbo.LU_YesBlank Lookup30 with (nolock) on dbo.AB_DeathInformation.AutopsyPerformed = Lookup30.Code LEFT OUTER JOIN
	dbo.LU_YesBlank Lookup51 with (nolock) on dbo.AB_DeathInformation.DeathTwoTenPO = Lookup51.Code LEFT OUTER JOIN
	dbo.LU_CoronerCase Lookup59 with (nolock) on dbo.AB_DeathInformation.CoronerCase = Lookup59.Code LEFT OUTER JOIN
	dbo.LU_YesBlank Lookup61 with (nolock) on dbo.AB_DeathInformation.DeathInOR = Lookup61.Code LEFT OUTER JOIN
	dbo.LU_SCU_Death Lookup62 with (nolock) on dbo.AB_DeathInformation.DeathInSCU = Lookup62.Code LEFT OUTER JOIN
	dbo.LU_YesBlank Lookup74 with (nolock) on dbo.AB_DeathInformation.DeathGreaterTenPO = Lookup74.Code LEFT OUTER JOIN
	dbo.LU_YesBlank Lookup86 with (nolock) on dbo.AB_DeathInformation.DeathAfterAdmit = Lookup86.Code LEFT OUTER JOIN
	dbo.LU_YesBlank Lookup87 with (nolock) on dbo.AB_DeathInformation.DeathLessTwoPO = Lookup87.Code LEFT OUTER JOIN
	dbo.LU_YesBlank Lookup91 with (nolock) on dbo.AB_DeathInformation.OtherDeath = Lookup91.Code LEFT OUTER JOIN
	dbo.LU_YesBlank Lookup104 with (nolock) on dbo.AB_DeathInformation.PregnancyDeath = Lookup104.Code LEFT OUTER JOIN
	dbo.LU_YesBlank Lookup126 with (nolock) on dbo.AB_DeathInformation.TraumaDeath = Lookup126.Code
    LEFT OUTER JOIN dbo.LU_CodeFile LU_AdmitTimeUnknown with (nolock) on dbo.AB_Abstract.AdmitTimeUnknown = LU_AdmitTimeUnknown.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_DischargeTimeUnknown with (nolock) on dbo.AB_Abstract.DischargeTimeUnknown = LU_DischargeTimeUnknown.Code 
--                       inner join dbo.CheckLogin() login 
--                         with (nolock) on login.HospitalID in (0, isnull(dbo.AB_Abstract.HospitalID, login.HospitalID))  
--                             or isnull(dbo.AB_Abstract.HospitalID, 0) in (0, login.HospitalID)
WHERE     (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType IN (1, 2))
--QA - 00032 disable the domain securite issue
----PR - 07485
--    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB_ABstract.HospitalID is null or AB_ABstract.HospitalID = 0
--    --EN - 00666
--        or Is_Member(nullif(ReportGroup, '''')) = 1)
----        or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB_ABstract.HospitalID, 0))





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AbstractingGeneral_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE  VIEW [dbo].[I10_AbstractingGeneral_VR]
AS
SELECT 
    dbo.AB_Abstract.ALCLOS, dbo.AB_Abstract.AcuteLOS, dbo.AB_Abstract.AdmitDate AS AdmissionDate, dbo.AB_Abstract.AdmitTime AS AdmissionTime, 
	--PR - 05489
	LU_AdmitTimeUnknown.DisplayCode as AdmissionTimeUnknown, LU_AdmitTimeUnknown.UserDescription as AdmissionTimeUnknownDesc,
    
    Lookup4.DisplayCode AS AdmitCategory, Lookup4.UserDescription AS AdmitCategoryDesc, 
    LU_AdmitNurse.DisplayCode as AdmitNurseArea, LU_AdmitNurse.UserDescription as AdmitNurseAreaDesc,
    Lookup6.DisplayCode AS AgeCode,     Lookup6.UserDescription AS AgeCodeDesc, dbo.AB_Abstract.AgeGroup, dbo.AB_Abstract.AgeNumber, 
    
    LU_BatchPeriod.DisplayCode AS BatchPeriod, LU_BatchPeriod.UserDescription AS BatchPeriodDesc, 
    --PR - 06087
    BatchPeriod_BC = (case when left(H_InstitutionProfile.CIHIValue, 1) <> ''9'' then null
                           when LU_BatchPeriod.DisplayCode is not null then LU_BatchPeriod.DisplayCode 
                           when DischargeDate is null then null
                           else (select top 1 DisplayCode from LU_BatchPeriod where DischargeDate between CIHIDateFrom and CIHIDateTo)
                      end),
    dbo.AB_Abstract.BatchYear, 

    dbo.AB_Abstract.BirthDate, 
    LU_CareType.DisplayCode as CareType, LU_CareType.UserDescription as CareTypeDesc,  dbo.AB_Abstract.ChartNumber, 
    
    Lookup54.DisplayCode AS CoderNumber, Lookup54.UserDescription AS CoderNumberDesc, 
    
    dbo.ICD_DiagFile10.DisplayCode AS DiagnosisMostResp, 
    dbo.ICD_DiagFile10.UserDescription AS DiagnosisMostRespDesc, dbo.AB_Abstract.DischargeDate, Lookup63.DisplayCode AS DischargeDisposition, 
    Lookup63.UserDescription AS DischargeDispositionDesc, dbo.AB_Abstract.DischargeTime, 
	--PR - 05489
	LU_DischargeTimeUnknown.DisplayCode AS DischargeTimeUnknown, LU_DischargeTimeUnknown.UserDescription AS DischargeTimeUnknownDesc, 
    LU_DischargeNurse.DisplayCode as DischNurseArea, LU_DischargeNurse.UserDescription as DischNurseAreaDesc,

    dbo.AB_Abstract.EncounterNumber, 
    Lookup69.DisplayCode AS EntryCode, Lookup69.UserDescription AS EntryCodeDesc, dbo.AB_Abstract.FirstName,
    FixedChartNumber,
    Lookup72.DisplayCode AS Gender, Lookup72.UserDescription AS GenderDesc, 
    Lookup75.DisplayCode AS HCNProvince, Lookup75.UserDescription AS HCNProvinceDesc, 
    dbo.AB_Abstract.HCNVersion, dbo.AB_Abstract.HealthCareNumber, 
    LU_Hospital.DisplayCode AS Hospital,     LU_Hospital.UserDescription AS HospitalDesc, 
    dbo.AB_Abstract.HospitalAccountRecord,
    dbo.AB_Abstract.ICDType, dbo.ICD_ProcFile10.DisplayCode AS InterventionCode, 
    dbo.ICD_ProcFile10.UserDescription AS InterventionCodeDesc, dbo.AB_Abstract.LOSDays, dbo.AB_Abstract.LOSMinutes, 
    dbo.AB_Abstract.LOSTime AS LOSTimeinHours, dbo.AB_Abstract.LastName, dbo.LU_PatientService.DisplayCode AS MainPatientService, 
    dbo.LU_PatientService.UserDescription AS MainPatientServiceDesc, dbo.AB_Abstract.MiddleName, ISNULL(dbo.AB_Abstract.LastName, '' '') 
    + '', '' + ISNULL(dbo.AB_Abstract.FirstName, '''') + '' '' + ISNULL(dbo.AB_Abstract.MiddleName, '''') AS NameFull, 
    dbo.AB_Manitoba.HCNExpiredDate  as OutProvinceHealthInsuranceExpiryDate,
    dbo.AB_Abstract.PostalCode, 
    -- ED - 01682
    dbo.GetPostalDescription(isnull(dbo.AB_Abstract.PostalCode, ''''), isnull(dbo.AB_Abstract.DischargeDate, dbo.AB_Abstract.AdmitDate)) AS PostalDescription, -- ED - 01682

    dbo.LU_Provider.DisplayCode AS ProviderNumber, dbo.LU_Provider.UserDescription AS ProviderNumberDesc, 
    dbo.LU_ProviderService.DisplayCode AS ProviderService, dbo.LU_ProviderService.UserDescription AS ProviderServiceDesc, 
    --PR - 04577
    LU_ReciprocalBillingStatus.DisplayCode AS ReciprocalBillingStatus, LU_ReciprocalBillingStatus.UserDescription AS ReciprocalBillingStatusDesc,

    AB_Abstract.RegisterNumber,
    dbo.H_InstitutionProfile.DisplayCode AS ReportingProvInstNumber, dbo.H_InstitutionProfile.UserDescription AS ReportingProvInstNumberDesc, 
    Lookup112.DisplayCode AS ResidenceCode, Lookup112.UserDescription AS ResidenceCodeDesc, 
    Lookup114.DisplayCode AS ResponsiblityForPayment, Lookup114.UserDescription AS ResponsiblityForPaymentDesc, 
    --PR - 03606
    dbo.AB_Abstract.SecondChartRegNumber AS SecondChartRegisterNumber, 

	dbo.AB_Abstract.UniversalEpisodeIdentifier,
    dbo.AB_Abstract.UniqiueLifetimeID AS ULI, 
    dbo.AB_Abstract.WaitTimeER AS WaitTimeInEmerg, 
    dbo.AB_Abstract.WaitTimeERHour AS WaitTimeInEmergHour, 
    dbo.AB_Abstract.Weight AS Weightingrams, 
    dbo.AB_Abstract.AbstractID AS zzAbstractLink, 
    dbo.AB_Abstract.RegionalPatientID as zzRegionalPatientID, 
    dbo.AB_Abstract.VolumeID AS zzVolumeLink, 
    ISNULL(dbo.AB_Diagnosis.DiagnosisOccurrence, 1) 
    AS DiagnosisOccurrence, ISNULL(dbo.AB_Intervention.IntervOccurrence, 1) AS IntervOccurrence, ISNULL(dbo.AB_PatientService.ServiceOccurrence, 1) 
    AS ServiceOccurrence, ISNULL(dbo.AB_Provider.ProviderOccurrence, 1) AS ProviderOccurrence
FROM
     
    dbo.AB_Abstract with (nolock) left join
    dbo.AB_Provider with (nolock) on dbo.AB_Provider.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
    dbo.LU_ProviderService with (nolock) on dbo.LU_ProviderService.Code = dbo.AB_Provider.ProviderService LEFT OUTER JOIN
    dbo.LU_Provider with (nolock) on dbo.LU_Provider.Code = dbo.AB_Provider.ProviderNumber left OUTER JOIN
    
    dbo.H_HospitalProfile LU_Hospital with (nolock) on dbo.AB_Abstract.HospitalID = LU_Hospital.Code left OUTER JOIN
    dbo.H_InstitutionProfile with (nolock) on dbo.H_InstitutionProfile.Code = dbo.AB_Abstract.InstitutionNumber LEFT OUTER JOIN
    dbo.AB_Intervention with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Intervention.AbstractID left join
    dbo.ICD_ProcFile10 with (nolock) on dbo.ICD_ProcFile10.Code = dbo.AB_Intervention.IntervCode LEFT OUTER JOIN

    dbo.AB_PatientService with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_PatientService.AbstractID LEFT OUTER JOIN
    dbo.LU_PatientService with (nolock) on dbo.AB_PatientService.PatientService = dbo.LU_PatientService.Code LEFT OUTER JOIN
    dbo.LU_AdmitCategory Lookup4 with (nolock) on dbo.AB_Abstract.AdmitCategory = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_AgeCode Lookup6 with (nolock) on dbo.AB_Abstract.AgeCode = Lookup6.Code left join
    dbo.LU_DispositionCode_I Lookup63 with (nolock) on Lookup63.Code = dbo.AB_Abstract.DispositionCode LEFT OUTER JOIN
    dbo.LU_EntryCode Lookup69 with (nolock) on dbo.AB_Abstract.EntryCode = Lookup69.Code LEFT OUTER JOIN
    dbo.LU_Gender_I Lookup72 with (nolock) on dbo.AB_Abstract.Gender = Lookup72.Code LEFT OUTER JOIN
    dbo.LU_HCNProvince Lookup75 with (nolock) on dbo.AB_Abstract.HCNProvince = Lookup75.Code LEFT OUTER JOIN
    dbo.LU_ResidenceCode Lookup112 with (nolock) on dbo.AB_Abstract.ResidenceCode = Lookup112.Code LEFT OUTER JOIN
    dbo.LU_RespPayment Lookup114 with (nolock) on dbo.AB_Abstract.ResponsiblePayment = Lookup114.Code LEFT OUTER JOIN
    dbo.AB_Diagnosis with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Diagnosis.AbstractID LEFT OUTER JOIN

    dbo.ICD_DiagFile10 with (nolock) on dbo.ICD_DiagFile10.Code = dbo.AB_Diagnosis.DiagnosisCode  LEFT OUTER JOIN
    dbo.LU_NurseArea LU_AdmitNurse with (nolock) on dbo.AB_Abstract.AdmittingNurseArea = LU_AdmitNurse.Code LEFT OUTER JOIN
    dbo.LU_NurseArea LU_DischargeNurse with (nolock) on dbo.AB_Abstract.DischargeNurseArea = LU_DischargeNurse.Code LEFT OUTER JOIN
    dbo.LU_CareType LU_CareType with (nolock) on dbo.AB_Abstract.CareType = LU_CareType.Code 
--PR - 04577
    LEFT OUTER JOIN dbo.LU_ReciprocalBillingStatus with (nolock) on dbo.AB_Abstract.IsReciprocalBilling = LU_ReciprocalBillingStatus.Code 

    LEFT OUTER JOIN dbo.LU_CodeFile LU_AdmitTimeUnknown with (nolock) on dbo.AB_Abstract.AdmitTimeUnknown = LU_AdmitTimeUnknown.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_DischargeTimeUnknown with (nolock) on dbo.AB_Abstract.DischargeTimeUnknown = LU_DischargeTimeUnknown.Code 
    Left OUTER JOIN dbo.AB_Manitoba with (nolock) on dbo.AB_Manitoba.AbstractID = dbo.AB_Abstract.AbstractID
    LEFT OUTER JOIN dbo.LU_BatchPeriod with (nolock) on dbo.AB_Abstract.BatchPeriod = LU_BatchPeriod.Code 
    LEFT OUTER JOIN dbo.U_Users Lookup54 with (nolock) on dbo.AB_Abstract.CoderNumber = Lookup54.Code 

WHERE     (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType IN (1, 2)) AND (ISNULL(dbo.AB_Diagnosis.DiagnosisOccurrence, 1) = 1) AND 
                      (ISNULL(dbo.AB_Intervention.IntervOccurrence, 1) = 1) AND (ISNULL(dbo.AB_PatientService.ServiceOccurrence, 1) = 1) AND 
                      (ISNULL(dbo.AB_Provider.ProviderOccurrence, 1) = 1)
--QA - 00032 disable the domain securite issue
----PR - 07485
--    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB_ABstract.HospitalID is null or AB_ABstract.HospitalID = 0
--    --EN - 00666
--        or Is_Member(nullif(ReportGroup, '''')) = 1)
----        or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB_ABstract.HospitalID, 0))
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AbstractingInterventionReplicate_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_AbstractingInterventionReplicate_VR]
AS
SELECT 
    dbo.AB_Abstract.ALCLOS, dbo.AB_Abstract.AcuteLOS, dbo.AB_Abstract.AdmitDate AS AdmissionDate, dbo.AB_Abstract.AdmitTime AS AdmissionTime, 
    Lookup4.DisplayCode AS AdmitCategory, Lookup4.UserDescription AS AdmitCategoryDesc, 
    LU_AdmitNurse.DisplayCode as AdmitNurseArea, LU_AdmitNurse.UserDescription as AdmitNurseAreaDesc,
    dbo.LU_AgeCode.DisplayCode AS AgeCode, dbo.LU_AgeCode.UserDescription AS AgeCodeDesc, 
    dbo.AB_Abstract.AgeGroup, dbo.AB_Abstract.AgeNumber, dbo.AB_Abstract.BirthDate, 
    LU_CareType.DisplayCode as CareType, LU_CareType.UserDescription as CareTypeDesc,  dbo.AB_Abstract.ChartNumber, 
    
    AB_Intervention_Replicate.IntervJointIdentifier as CJRRJointIdentifier,
    LU_CJRR_RevisionReason.DisplayCode AS CJRRRevisionReason, LU_CJRR_RevisionReason.UserDescription AS CJRRRevisionReasonDesc,

    dbo.ICD_DiagFile10.DisplayCode AS DiagnosisMostResp, 
    dbo.ICD_DiagFile10.UserDescription AS DiagnosisMostRespDesc, dbo.AB_Abstract.DischargeDate, 
    
    dbo.LU_DispositionCode_I.DisplayCode AS DischargeDisposition, dbo.LU_DispositionCode_I.UserDescription AS DischargeDispositionDesc, 
    dbo.AB_Abstract.DischargeTime, 
    LU_DischargeNurse.DisplayCode as DischNurseArea, LU_DischargeNurse.UserDescription as DischNurseAreaDesc,

    dbo.AB_Abstract.EncounterNumber, 
    Lookup69.DisplayCode AS EntryCode, Lookup69.UserDescription AS EntryCodeDesc, dbo.AB_Abstract.FirstName, Lookup72.DisplayCode AS Gender, 
    Lookup72.UserDescription AS GenderDesc, Lookup75.DisplayCode AS HCNProvince, Lookup75.UserDescription AS HCNProvinceDesc, 
    dbo.AB_Abstract.HCNVersion, dbo.AB_Abstract.HealthCareNumber, LU_Hospital.DisplayCode AS Hospital, 
    LU_Hospital.UserDescription AS HospitalDesc, dbo.AB_Abstract.ICDType, 
    dbo.AB_Abstract.LOSDays, dbo.AB_Abstract.LOSMinutes, 
    dbo.AB_Abstract.LOSTime AS LOSTimeinHours, dbo.AB_Abstract.LastName, dbo.LU_PatientService.DisplayCode AS MainPatientService, 
    dbo.LU_PatientService.UserDescription AS MainPatientServiceDesc, dbo.AB_Abstract.MiddleName, ISNULL(dbo.AB_Abstract.LastName, '' '') 
    + '', '' + ISNULL(dbo.AB_Abstract.FirstName, '''') + '' '' + ISNULL(dbo.AB_Abstract.MiddleName, '''') AS NameFull, dbo.AB_Abstract.PostalCode, 

    -- ED - 01682
    dbo.GetPostalDescription(isnull(dbo.AB_Abstract.PostalCode, ''''), isnull(dbo.AB_Abstract.DischargeDate, dbo.AB_Abstract.AdmitDate)) AS PostalDescription, -- ED - 01682

    dbo.LU_Provider.DisplayCode AS ProviderNumber, dbo.LU_Provider.UserDescription AS ProviderNumberDesc, 
    dbo.LU_ProviderService.DisplayCode AS ProviderService, dbo.LU_ProviderService.UserDescription AS ProviderServiceDesc, 
    dbo.H_InstitutionProfile.DisplayCode AS ReportingProvInstNumber, dbo.H_InstitutionProfile.UserDescription AS ReportingProvInstNumberDesc, 
    Lookup112.DisplayCode AS ResidenceCode, Lookup112.UserDescription AS ResidenceCodeDesc, 
    Lookup114.DisplayCode AS ResponsiblityForPayment, Lookup114.UserDescription AS ResponsiblityForPaymentDesc, 
    --PR - 03606
    dbo.AB_Abstract.SecondChartRegNumber AS SecondChartRegisterNumber, 

    dbo.AB_Abstract.UniqiueLifetimeID AS ULI, dbo.AB_Abstract.WaitTimeER AS WaitTimeInEmerg, dbo.AB_Abstract.Weight AS Weightingrams, 
    ISNULL(dbo.AB_Diagnosis.DiagnosisOccurrence, 1) AS DiagnosisOccurrence, 
    ISNULL(dbo.AB_PatientService.ServiceOccurrence, 1) AS ServiceOccurrence, 
    ISNULL(dbo.AB_Provider.ProviderOccurrence, 1) AS ProviderOccurrence,

    --Intervention Replicate 
    LU_AnaestTechnique.DisplayCode AS AnaestheticTechnique, LU_AnaestTechnique.UserDescription AS AnaestheticTechniqueDesc,
    LU_AnaesthetistID.DisplayCode AS AnaesthetistID, LU_AnaesthetistID.UserDescription AS AnaesthetistIDDesc,
    LU_EUL.DisplayCode AS EUL, LU_EUL.UserDescription AS EULDesc,
    LU_Extra.DisplayCode AS Extra, LU_Extra.UserDescription AS ExtraDesc,
    Lookup5.DisplayCode AS IntervAttribExtent,   Lookup5.UserDescription AS IntervAttribExtentDesc, 
    Lookup6.DisplayCode AS IntervAttribLocation, Lookup6.UserDescription AS IntervAttribLocationDesc, 
    Lookup7.DisplayCode AS IntervAttribStatus,   Lookup7.UserDescription AS IntervAttribStatusDesc, 
    dbo.ICD_ProcFile10.CIHIValue AS IntervCIHIValue, dbo.ICD_ProcFile10.DisplayCode AS IntervCode,
    dbo.ICD_ProcFile10.UserDescription AS IntervCodeDesc, dbo.ICD_ProcFile10.ShortDescription AS IntervCodeShortDesc, 
    AB_Intervention_Replicate.IntervDate, 
    AB_Intervention_Replicate.IntervDateIn, 
    AB_Intervention_Replicate.IntervDateOut, 

    LU_TimeInUnknown.DisplayCode as IntervEpisodeStartTimeUnknown, LU_TimeInUnknown.UserDescription as IntervEpisodeStartTimeUnknownDesc,
    LU_TimeOutUnknown.DisplayCode as IntervEpisodeEndTimeUnknown, LU_TimeOutUnknown.UserDescription as IntervEpisodeEndTimeUnknownDesc,
    LU_Flagged.DisplayCode AS IntervFlaggedCategory, LU_Flagged.UserDescription AS IntervFlaggedCategoryDesc, 
    
    LU_Suffix.DisplayCode as Suffix, LU_Suffix.UserDescription as SuffixDesc,

    LU_IntervLocation.DisplayCode as IntervLocation, LU_IntervLocation.UserDescription as IntervLocationDesc,

    dbo.AB_Intervention_Replicate.IntervOccurrence, 
    
    LU_IntervPreAdmitFlag.DisplayCode as IntervPreAdmitFlag, LU_IntervPreAdmitFlag.UserDescription as IntervPreAdmitFlagDesc, 
    
    
    lp.DisplayCode as IntervProviderNumber, lp.UserDescription as IntervProviderNumberDesc, 
    (case when dbo.AB_Abstract.Caretype = 5 then '''' else lsv.DisplayCode end) as IntervProviderService, 
    (case when dbo.AB_Abstract.Caretype = 5 then '''' else lsv.UserDescription end) as IntervProviderServiceDesc, 
    (case when dbo.AB_Abstract.Caretype = 5 then lsp.DisplayCode else '''' end) as IntervProviderSpecialty, 
    (case when dbo.AB_Abstract.Caretype = 5 then lsp.UserDescription else '''' end) as IntervProviderSpecialtyDesc, 
    
    --PR - 04074
    AB_Intervention_Replicate.IntervTimeIn, 
    AB_Intervention_Replicate.IntervTimeMinutes AS IntervTimeinMinutes, 
    AB_Intervention_Replicate.IntervTimeOut, 

    LU_OOH.DisplayCode AS OOHIndicator, LU_OOH.UserDescription AS OOHIndicatorDesc, 
    LU_OOH_Inst.DisplayCode as OOHInstitutionNumber, LU_OOH_Inst.UserDescription AS OOHInstitutionNumberDesc, 
    AB_Intervention_Replicate.IntervTripNumber as ORTripNumber,  
    
    LU_IntervTissue.DisplayCode as TissueCode, LU_IntervTissue.UserDescription as TissueCodeDesc, 
    LU_IntervTissue.DefaultDescription as TissueCodeDesc_D, 
    LU_IntervUnplanReturn.DisplayCode AS UnplannedReturntoOR, LU_IntervUnplanReturn.UserDescription AS UnplannedReturntoORDesc,
    dbo.ICD_ProcFile10.ICD9 AS ICD9Equivalent, dbo.ICD_ProcFile10.ICD9cm AS ICD9cmEquivalent, 

    dbo.AB_Abstract.AbstractID AS zzAbstractLink, dbo.AB_Abstract.VolumeID AS zzVolumeLink
FROM
    dbo.AB_Abstract with (nolock) LEFT OUTER JOIN
    dbo.AB_Provider with (nolock) on dbo.AB_Provider.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
    dbo.LU_Provider with (nolock) on dbo.LU_Provider.Code = dbo.AB_Provider.ProviderNumber Left OUTER JOIN
    dbo.LU_ProviderService with (nolock) on dbo.LU_ProviderService.Code = dbo.AB_Provider.ProviderService LEFT OUTER JOIN
    dbo.H_HospitalProfile LU_Hospital with (nolock) on dbo.AB_Abstract.HospitalID = LU_Hospital.Code LEFT OUTER JOIN
    dbo.H_InstitutionProfile with (nolock) on dbo.H_InstitutionProfile.Code = dbo.AB_Abstract.InstitutionNumber LEFT OUTER JOIN
    dbo.AB_PatientService with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_PatientService.AbstractID LEFT OUTER JOIN
    dbo.LU_PatientService with (nolock) on dbo.AB_PatientService.PatientService = dbo.LU_PatientService.Code LEFT OUTER JOIN
    dbo.LU_AdmitCategory Lookup4 with (nolock) on dbo.AB_Abstract.AdmitCategory = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_AgeCode with (nolock) on dbo.AB_Abstract.AgeCode = dbo.LU_AgeCode.Code LEFT OUTER JOIN
    dbo.LU_DispositionCode_I with (nolock) on dbo.LU_DispositionCode_I.Code = dbo.AB_Abstract.DispositionCode LEFT OUTER JOIN
    dbo.LU_EntryCode Lookup69 with (nolock) on dbo.AB_Abstract.EntryCode = Lookup69.Code LEFT OUTER JOIN
    dbo.LU_Gender_I Lookup72 with (nolock) on dbo.AB_Abstract.Gender = Lookup72.Code LEFT OUTER JOIN
    dbo.LU_HCNProvince Lookup75 with (nolock) on dbo.AB_Abstract.HCNProvince = Lookup75.Code LEFT OUTER JOIN
    dbo.LU_ResidenceCode Lookup112 with (nolock) on dbo.AB_Abstract.ResidenceCode = Lookup112.Code LEFT OUTER JOIN
    dbo.LU_RespPayment Lookup114 with (nolock) on dbo.AB_Abstract.ResponsiblePayment = Lookup114.Code LEFT OUTER JOIN
    dbo.AB_Diagnosis with (nolock) on  dbo.AB_Abstract.AbstractID = dbo.AB_Diagnosis.AbstractID LEFT OUTER JOIN
    dbo.ICD_DiagFile10 with (nolock) on dbo.ICD_DiagFile10.Code = dbo.AB_Diagnosis.DiagnosisCode left OUTER JOIN
    dbo.LU_NurseArea LU_AdmitNurse with (nolock) on dbo.AB_Abstract.AdmittingNurseArea = LU_AdmitNurse.Code LEFT OUTER JOIN
    dbo.LU_NurseArea LU_DischargeNurse with (nolock) on dbo.AB_Abstract.DischargeNurseArea = LU_DischargeNurse.Code LEFT OUTER JOIN
    dbo.LU_CareType LU_CareType with (nolock) on dbo.AB_Abstract.CareType = LU_CareType.Code LEFT OUTER JOIN
    --Intervention Reciplicate
    dbo.AB_Intervention_Replicate with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Intervention_Replicate.AbstractID LEFT OUTER JOIN
    dbo.ICD_ProcFile10 with (nolock) on dbo.ICD_ProcFile10.Code = dbo.AB_Intervention_Replicate.IntervCode LEFT OUTER JOIN
    dbo.LU_IntervAttExtent Lookup5 with (nolock) on dbo.AB_Intervention_Replicate.IntervAttribExtent = Lookup5.Code LEFT OUTER JOIN
    dbo.LU_IntervAttLocation Lookup6 with (nolock) on dbo.AB_Intervention_Replicate.IntervAttribLocation = Lookup6.Code LEFT OUTER JOIN
    dbo.LU_IntervAttStatus Lookup7 with (nolock) on dbo.AB_Intervention_Replicate.IntervAttribStatus = Lookup7.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS LU_IntervPreAdmitFlag with (nolock) on dbo.AB_Intervention_Replicate.IntervPreAdmitFlag = LU_IntervPreAdmitFlag.Code LEFT OUTER JOIN
    
    --Intervention Provider
    dbo.LU_Provider Lp with (nolock) on AB_Intervention_Replicate.IntervProviderNumber = lp.Code Left Join
    --Intervention Provider Service/Specialty
	dbo.LU_ProviderService Lsv with (nolock) on AB_Intervention_Replicate.IntervProviderService = lsv.Code left join
	dbo.LU_ProviderSpecialty Lsp with (nolock) on AB_Intervention_Replicate.IntervProviderService = lsp.Code Left Join 
    --Intervention Tissue Code
    dbo.LU_IntervTissue with (nolock) on AB_Intervention_Replicate.IntervTissueCode = LU_IntervTissue.Code Left Join
    --Intervention Location
    dbo.LU_IntervLocation_AI LU_IntervLocation with (nolock) ON AB_Intervention_Replicate.IntervLocation = LU_IntervLocation.Code Left Join
    --Intervention IntervAnaestID
    dbo.LU_Provider LU_AnaesthetistID with (nolock) ON AB_Intervention_Replicate.IntervAnaestID = LU_AnaesthetistID.Code Left Join
    --Intervention Anaesthetic Technique
     dbo.LU_AnaestTechnique ON AB_Intervention_Replicate.IntervAnaestTechnique = LU_AnaestTechnique.Code Left Join
	--IntervUnplanReturn
    dbo.LU_YesBlankAlpha LU_IntervUnplanReturn with (nolock) ON AB_Intervention_Replicate.IntervUnplanReturn = LU_IntervUnplanReturn.Code Left join
    --Intervention OOH
     dbo.LU_YesBlank LU_OOH with (nolock) ON AB_Intervention_Replicate.IntervOOHIndicator = LU_OOH.Code Left join
     dbo.LU_Institution_10 LU_OOH_Inst ON AB_Intervention_Replicate.IntervOOHInstitution = LU_OOH_Inst.Code Left join

    --Intervention EUL
    dbo.LU_IntervEUL LU_EUL with (nolock) ON AB_Intervention_Replicate.IntervEUL = LU_EUL.Code Left Join
    --Intervention Extra      
    dbo.LU_IntervExtra LU_Extra ON AB_Intervention_Replicate.IntervExtra = LU_Extra.Code Left Join
    dbo.LU_CodeFile LU_TimeInUnknown ON AB_Intervention_Replicate.IntervTimeInUnknown = LU_TimeInUnknown.Code  Left Join

    --Intervention Time Out Unknown -- PR - 04332
    dbo.LU_CodeFile LU_TimeOutUnknown with (nolock) ON AB_Intervention_Replicate.IntervTimeOutUnknown = LU_TimeOutUnknown.Code Left Join

    --Intervention Suffix -- PR - 05248
    dbo.LU_IntervSuffix LU_Suffix ON AB_Intervention_Replicate.IntervSuffix = lU_Suffix.Code left join

    --Intervention PreAdmitFlag -- PR - 05413
    dbo.LU_codeFile LU_PreAdmitFlag with (nolock) ON AB_Intervention_Replicate.IntervPreAdmitFlag = LU_PreAdmitFlag.Code  LEFT OUTER JOIN
    dbo.LU_CodeFile AS LU_Flagged with (nolock) on dbo.AB_Intervention_Replicate.FlaggedIntervention = LU_Flagged.Code LEFT OUTER JOIN
    LU_CJRR_RevisionReason with (nolock) on dbo.AB_Intervention_Replicate.IntervRevisionReason = LU_CJRR_RevisionReason.Code

WHERE (dbo.AB_Abstract.DischargeDate > ''2001/03/31'' or dbo.AB_Abstract.AdmitDate > ''2001/03/31'') and
    (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType IN (1, 2)) AND 
    (ISNULL(dbo.AB_Diagnosis.DiagnosisOccurrence, 1) = 1) AND 
    (ISNULL(dbo.AB_PatientService.ServiceOccurrence, 1) = 1) AND 
    (ISNULL(dbo.AB_Provider.ProviderOccurrence, 1) = 1)
----PR - 07485    
--    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB_ABstract.HospitalID is null or AB_ABstract.HospitalID = 0
--        or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB_ABstract.HospitalID, 0))
--    --EN - 00666
--        or Is_Member(nullif(ReportGroup, '''')) = 1)

/*  Old Logic
SELECT 
    dbo.AB_Abstract.ALCLOS, dbo.AB_Abstract.AcuteLOS, dbo.AB_Abstract.AdmitDate AS AdmissionDate, dbo.AB_Abstract.AdmitTime AS AdmissionTime, 
    Lookup4.DisplayCode AS AdmitCategory, Lookup4.UserDescription AS AdmitCategoryDesc, 
    LU_AdmitNurse.DisplayCode as AdmitNurseArea, LU_AdmitNurse.UserDescription as AdmitNurseAreaDesc,
    dbo.LU_AgeCode.DisplayCode AS AgeCode, dbo.LU_AgeCode.UserDescription AS AgeCodeDesc, 
    dbo.AB_Abstract.AgeGroup, dbo.AB_Abstract.AgeNumber, dbo.AB_Abstract.BirthDate, 
    LU_CareType.DisplayCode as CareType, LU_CareType.UserDescription as CareTypeDesc,  dbo.AB_Abstract.ChartNumber, dbo.ICD_DiagFile10.DisplayCode AS DiagnosisMostResp, 
    dbo.ICD_DiagFile10.UserDescription AS DiagnosisMostRespDesc, dbo.AB_Abstract.DischargeDate, 
    
    dbo.LU_DispositionCode_I.DisplayCode AS DischargeDisposition, dbo.LU_DispositionCode_I.UserDescription AS DischargeDispositionDesc, 
    dbo.AB_Abstract.DischargeTime, 
    LU_DischargeNurse.DisplayCode as DischNurseArea, LU_DischargeNurse.UserDescription as DischNurseAreaDesc,

    dbo.AB_Abstract.EncounterNumber, 
    Lookup69.DisplayCode AS EntryCode, Lookup69.UserDescription AS EntryCodeDesc, dbo.AB_Abstract.FirstName, Lookup72.DisplayCode AS Gender, 
    Lookup72.UserDescription AS GenderDesc, Lookup75.DisplayCode AS HCNProvince, Lookup75.UserDescription AS HCNProvinceDesc, 
    dbo.AB_Abstract.HCNVersion, dbo.AB_Abstract.HealthCareNumber, LU_Hospital.DisplayCode AS Hospital, 
    LU_Hospital.UserDescription AS HospitalDesc, dbo.AB_Abstract.ICDType, 
    dbo.AB_Abstract.LOSDays, dbo.AB_Abstract.LOSMinutes, 
    dbo.AB_Abstract.LOSTime AS LOSTimeinHours, dbo.AB_Abstract.LastName, dbo.LU_PatientService.DisplayCode AS MainPatientService, 
    dbo.LU_PatientService.UserDescription AS MainPatientServiceDesc, dbo.AB_Abstract.MiddleName, ISNULL(dbo.AB_Abstract.LastName, '' '') 
    + '', '' + ISNULL(dbo.AB_Abstract.FirstName, '''') + '' '' + ISNULL(dbo.AB_Abstract.MiddleName, '''') AS NameFull, dbo.AB_Abstract.PostalCode, 

    -- ED - 01682
    dbo.GetPostalDescription(isnull(dbo.AB_Abstract.PostalCode, ''''), isnull(dbo.AB_Abstract.DischargeDate, dbo.AB_Abstract.AdmitDate)) AS PostalDescription, -- ED - 01682

    dbo.LU_Provider.DisplayCode AS ProviderNumber, dbo.LU_Provider.UserDescription AS ProviderNumberDesc, 
    dbo.LU_ProviderService.DisplayCode AS ProviderService, dbo.LU_ProviderService.UserDescription AS ProviderServiceDesc, 
    dbo.H_InstitutionProfile.DisplayCode AS ReportingProvInstNumber, dbo.H_InstitutionProfile.UserDescription AS ReportingProvInstNumberDesc, 
    Lookup112.DisplayCode AS ResidenceCode, Lookup112.UserDescription AS ResidenceCodeDesc, 
    Lookup114.DisplayCode AS ResponsiblityForPayment, Lookup114.UserDescription AS ResponsiblityForPaymentDesc, 
    --PR - 03606
    dbo.AB_Abstract.SecondChartRegNumber AS SecondChartRegisterNumber, 

    dbo.AB_Abstract.UniqiueLifetimeID AS ULI, dbo.AB_Abstract.WaitTimeER AS WaitTimeInEmerg, dbo.AB_Abstract.Weight AS Weightingrams, 
    ISNULL(dbo.AB_Diagnosis.DiagnosisOccurrence, 1) AS DiagnosisOccurrence, 
    ISNULL(dbo.AB_PatientService.ServiceOccurrence, 1) AS ServiceOccurrence, 
    ISNULL(dbo.AB_Provider.ProviderOccurrence, 1) AS ProviderOccurrence,

    --Intervention Replicate 
    at.AnaestheticTechnique, at.AnaestheticTechniqueDesc, 
    a.AnaesthetistID, a.AnaesthetistIDDesc, 
    eul.EUL, eul.EULDesc, 
    ex.Extra, ex.ExtraDesc, 
    Lookup5.DisplayCode AS IntervAttribExtent,   Lookup5.UserDescription AS IntervAttribExtentDesc, 
    Lookup6.DisplayCode AS IntervAttribLocation, Lookup6.UserDescription AS IntervAttribLocationDesc, 
    Lookup7.DisplayCode AS IntervAttribStatus,   Lookup7.UserDescription AS IntervAttribStatusDesc, 
    dbo.ICD_ProcFile10.CIHIValue AS IntervCIHIValue, dbo.ICD_ProcFile10.DisplayCode AS IntervCode,
    dbo.ICD_ProcFile10.UserDescription AS IntervCodeDesc, dbo.ICD_ProcFile10.ShortDescription AS IntervCodeShortDesc, 
    e.IntervDate, 
    --PR - 04074
    DateIn.IntervDateIn, --ISNULL(dbo.AB_Intervention.IntervDateIn, e.IntervDateIn) AS IntervDateIn, 
    DateOut.IntervDateOut, --ISNULL(dbo.AB_Intervention.IntervDateOut, e.IntervDateOut) AS IntervDateOut, 
    --e.IntervDateIn, --ISNULL(dbo.AB_Intervention.IntervDateIn, e.IntervDateIn) AS IntervDateIn, 
    --e.IntervDateOut, --ISNULL(dbo.AB_Intervention.IntervDateOut, e.IntervDateOut) AS IntervDateOut, 

    --PR - 04332
    TimeInUnknown.IntervEpisodeStartTimeUnknown, TimeInUnknown.IntervEpisodeStartTimeUnknownDesc,
    TimeOutUnknown.IntervEpisodeEndTimeUnknown, TimeOutUnknown.IntervEpisodeEndTimeUnknownDesc,
    --PR - 05248
    Suffix.IntervSuffix, Suffix.IntervSuffixDesc, 

    l.IntervLocation, l.IntervLocationDesc, 
    dbo.AB_Intervention.IntervOccurrence, 
    --PR - 05413
    --LU_IntervPreAdmitFlag.DisplayCode as IntervPreAdmitFlag, LU_IntervPreAdmitFlag.UserDescription as IntervPreAdmitFlagDesc, 
    PreAdmit.IntervPreAdmitFlag, PreAdmit.IntervPreAdmitFlagDesc, 
    
    p.IntervProviderNumber, p.IntervProviderNumberDesc, 
    (case when dbo.AB_Abstract.Caretype = 5 then '''' else s.IntervProviderService end) as IntervProviderService, 
    (case when dbo.AB_Abstract.Caretype = 5 then '''' else s.IntervProviderServiceDesc end) as IntervProviderServiceDesc, 
    (case when dbo.AB_Abstract.Caretype = 5 then s.IntervProviderSpecialty else '''' end) as IntervProviderSpecialty, 
    (case when dbo.AB_Abstract.Caretype = 5 then s.IntervProviderSpecialtyDesc else '''' end) as IntervProviderSpecialtyDesc, 
    --PR - 04074
    TimeIn.IntervTimeIn, 
    e.IntervTimeMinutes AS IntervTimeinMinutes, --ISNULL(dbo.AB_Intervention.IntervTimeMinutes, e.IntervTimeMinutes) AS IntervTimeinMinutes, 
    TimeOut.IntervTimeOut, 
    --e.IntervTimeIn, --ISNULL(dbo.AB_Intervention.IntervTimeIn, e.IntervTimeIn) AS IntervTimeIn, 
    --e.IntervTimeOut, --ISNULL(dbo.AB_Intervention.IntervTimeOut, e.IntervTimeOut) AS IntervTimeOut, 

    e.OOHIndicator, --ISNULL(Lookup11.DisplayCode, e.OOHIndicator) AS OOHIndicator, 
    e.OOHIndicatorDesc, --ISNULL(Lookup11.UserDescription, e.OOHIndicatorDesc) AS OOHIndicatorDesc, 
    e.OOHInstitutionNumber, --ISNULL(Lookup12.DisplayCode, e.OOHInstitutionNumber) AS OOHInstitutionNumber, 
    e.OOHInstitutionNumberDesc, --ISNULL(Lookup12.UserDescription, e.OOHInstitutionNumberDesc) AS OOHInstitutionNumberDesc, 
    trip.ORTripNumber,  
    t.TissueCode, t.TissueCodeDesc, t.TissueCodeDesc_D, 
    r.UnplannedReturntoOR, r.UnplannedReturntoORDesc, 
    dbo.ICD_ProcFile10.ICD9 AS ICD9Equivalent, dbo.ICD_ProcFile10.ICD9cm AS ICD9cmEquivalent, 

    dbo.AB_Abstract.AbstractID AS zzAbstractLink, dbo.AB_Abstract.VolumeID AS zzVolumeLink
FROM
    dbo.AB_Abstract with (nolock) LEFT OUTER JOIN
    dbo.AB_Provider with (nolock) on dbo.AB_Provider.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
    dbo.LU_Provider with (nolock) on dbo.LU_Provider.Code = dbo.AB_Provider.ProviderNumber Left OUTER JOIN
    dbo.LU_ProviderService with (nolock) on dbo.LU_ProviderService.Code = dbo.AB_Provider.ProviderService LEFT OUTER JOIN
    dbo.H_HospitalProfile LU_Hospital with (nolock) on dbo.AB_Abstract.HospitalID = LU_Hospital.Code LEFT OUTER JOIN
    dbo.H_InstitutionProfile with (nolock) on dbo.H_InstitutionProfile.Code = dbo.AB_Abstract.InstitutionNumber LEFT OUTER JOIN
    dbo.AB_PatientService with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_PatientService.AbstractID LEFT OUTER JOIN
    dbo.LU_PatientService with (nolock) on dbo.AB_PatientService.PatientService = dbo.LU_PatientService.Code LEFT OUTER JOIN
    dbo.LU_AdmitCategory Lookup4 with (nolock) on dbo.AB_Abstract.AdmitCategory = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_AgeCode with (nolock) on dbo.AB_Abstract.AgeCode = dbo.LU_AgeCode.Code LEFT OUTER JOIN
    dbo.LU_DispositionCode_I with (nolock) on dbo.LU_DispositionCode_I.Code = dbo.AB_Abstract.DispositionCode LEFT OUTER JOIN
    dbo.LU_EntryCode Lookup69 with (nolock) on dbo.AB_Abstract.EntryCode = Lookup69.Code LEFT OUTER JOIN
    dbo.LU_Gender_I Lookup72 with (nolock) on dbo.AB_Abstract.Gender = Lookup72.Code LEFT OUTER JOIN
    dbo.LU_HCNProvince Lookup75 with (nolock) on dbo.AB_Abstract.HCNProvince = Lookup75.Code LEFT OUTER JOIN
    dbo.LU_ResidenceCode Lookup112 with (nolock) on dbo.AB_Abstract.ResidenceCode = Lookup112.Code LEFT OUTER JOIN
    dbo.LU_RespPayment Lookup114 with (nolock) on dbo.AB_Abstract.ResponsiblePayment = Lookup114.Code LEFT OUTER JOIN
    dbo.AB_Diagnosis with (nolock) on  dbo.AB_Abstract.AbstractID = dbo.AB_Diagnosis.AbstractID LEFT OUTER JOIN
    dbo.ICD_DiagFile10 with (nolock) on dbo.ICD_DiagFile10.Code = dbo.AB_Diagnosis.DiagnosisCode left OUTER JOIN
    dbo.LU_NurseArea LU_AdmitNurse with (nolock) on dbo.AB_Abstract.AdmittingNurseArea = LU_AdmitNurse.Code LEFT OUTER JOIN
    dbo.LU_NurseArea LU_DischargeNurse with (nolock) on dbo.AB_Abstract.DischargeNurseArea = LU_DischargeNurse.Code LEFT OUTER JOIN
    dbo.LU_CareType LU_CareType with (nolock) on dbo.AB_Abstract.CareType = LU_CareType.Code LEFT OUTER JOIN
    --Intervention Reciplicate
    dbo.AB_Intervention with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Intervention.AbstractID LEFT OUTER JOIN
    dbo.ICD_ProcFile10 with (nolock) on dbo.ICD_ProcFile10.Code = dbo.AB_Intervention.IntervCode LEFT OUTER JOIN
    dbo.LU_IntervAttExtent Lookup5 with (nolock) on dbo.AB_Intervention.IntervAttribExtent = Lookup5.Code LEFT OUTER JOIN
    dbo.LU_IntervAttLocation Lookup6 with (nolock) on dbo.AB_Intervention.IntervAttribLocation = Lookup6.Code LEFT OUTER JOIN
    dbo.LU_IntervAttStatus Lookup7 with (nolock) on dbo.AB_Intervention.IntervAttribStatus = Lookup7.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS LU_IntervPreAdmitFlag with (nolock) on dbo.AB_Intervention.IntervPreAdmitFlag = LU_IntervPreAdmitFlag.Code LEFT OUTER JOIN
    --Intervention Provider
      (SELECT    p.AbstractID, v.IntervOccurrence, 
                 lp.DisplayCode AS IntervProviderNumber, lp.UserDescription AS IntervProviderNumberDesc
        FROM dbo.AB_Intervention p with (nolock) INNER JOIN
             dbo.AB_Abstract with (nolock) on p.AbstractID = AB_Abstract.AbstractID inner join
             dbo.InterventionEpisode_Provider_VR v on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  Left Join
             dbo.LU_Provider Lp with (nolock) on p.IntervProviderNumber = lp.Code 
        WHERE      AB_Abstract.ICDType = ''T'' 

      ) p ON dbo.AB_Intervention.AbstractID = p.AbstractID AND dbo.AB_Intervention.IntervOccurrence = p.IntervOccurrence  Left Join
    --Intervention Provider Service/Specialty
      (SELECT    p.AbstractID, v.IntervOccurrence, 
                 lsv.DisplayCode AS IntervProviderService,   lsv.UserDescription AS IntervProviderServiceDesc,
                 lsp.DisplayCode AS IntervProviderSpecialty, lsp.UserDescription AS IntervProviderSpecialtyDesc
        FROM dbo.AB_Intervention p with (nolock) INNER JOIN
             dbo.AB_Abstract with (nolock) on p.AbstractID = AB_Abstract.AbstractID inner join
             dbo.InterventionEpisode_Service_VR v on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  Left Join
             dbo.LU_ProviderService Lsv with (nolock) on p.IntervProviderService = lsv.Code left join
             dbo.LU_ProviderSpecialty Lsp with (nolock) on p.IntervProviderService = lsp.Code 
        WHERE      AB_Abstract.ICDType = ''T'' 

      ) s ON dbo.AB_Intervention.AbstractID = s.AbstractID AND dbo.AB_Intervention.IntervOccurrence = s.IntervOccurrence Left Join 
    --Intervention Tissue Code
      (SELECT    p.AbstractID, v.IntervOccurrence, 
                 lt.DisplayCode AS TissueCode, lt.UserDescription AS TissueCodeDesc, lt.DefaultDescription AS TissueCodeDesc_D
        FROM dbo.AB_Intervention p with (nolock) INNER JOIN
             dbo.AB_Abstract with (nolock) on p.AbstractID = AB_Abstract.AbstractID inner join
             dbo.InterventionEpisode_Tissue_VR v with (nolock) on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  Left Join
             dbo.LU_IntervTissue Lt with (nolock) on p.IntervTissueCode = lt.Code 
        WHERE AB_Abstract.ICDType = ''T'' 
      ) t ON dbo.AB_Intervention.AbstractID = t.AbstractID AND dbo.AB_Intervention.IntervOccurrence = t.IntervOccurrence Left Join
    --Intervention Location
      (SELECT    p.AbstractID, v.IntervOccurrence, 
                 lt.DisplayCode AS IntervLocation, lt.UserDescription AS IntervLocationDesc
        FROM dbo.AB_Intervention p with (nolock) INNER JOIN
             dbo.AB_Abstract with (nolock) on p.AbstractID = AB_Abstract.AbstractID inner join
             dbo.InterventionEpisode_Location_VR v on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  Left Join
             dbo.LU_IntervLocation_AI Lt with (nolock) ON p.IntervLocation = lt.Code 
        WHERE AB_Abstract.ICDType = ''T'' 
      ) l ON dbo.AB_Intervention.AbstractID = l.AbstractID AND dbo.AB_Intervention.IntervOccurrence = l.IntervOccurrence Left Join
    --Intervention IntervAnaestID
      (SELECT    p.AbstractID, v.IntervOccurrence, 
                 lt.DisplayCode AS AnaesthetistID, lt.UserDescription AS AnaesthetistIDDesc
        FROM dbo.AB_Intervention p with (nolock) INNER JOIN
             dbo.AB_Abstract with (nolock) on p.AbstractID = AB_Abstract.AbstractID inner join
             dbo.InterventionEpisode_Anaesthetist_VR v on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  Left Join
             dbo.LU_Provider Lt with (nolock) ON p.IntervAnaestID = lt.Code 
        WHERE AB_Abstract.ICDType = ''T'' 
      ) a ON dbo.AB_Intervention.AbstractID = a.AbstractID AND dbo.AB_Intervention.IntervOccurrence = a.IntervOccurrence Left Join
    --Intervention Anaesthetic Technique
      (SELECT    p.AbstractID, v.IntervOccurrence, 
                 lt.DisplayCode AS AnaestheticTechnique, lt.UserDescription AS AnaestheticTechniqueDesc
        FROM dbo.AB_Intervention p INNER JOIN
             dbo.AB_Abstract on p.AbstractID = AB_Abstract.AbstractID inner join
             dbo.InterventionEpisode_Technique_VR v on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  Left Join
             dbo.LU_AnaestTechnique Lt ON p.IntervAnaestTechnique = lt.Code 
        WHERE AB_Abstract.ICDType = ''T'' 
      ) at ON dbo.AB_Intervention.AbstractID = at.AbstractID AND dbo.AB_Intervention.IntervOccurrence = at.IntervOccurrence Left Join
    --Intervention Unplanned Return To OR
      (SELECT    p.AbstractID, v.IntervOccurrence, 
                 lt.DisplayCode AS UnplannedReturntoOR, lt.UserDescription AS UnplannedReturntoORDesc
        FROM dbo.AB_Intervention p with (nolock) INNER JOIN
             dbo.AB_Abstract with (nolock) on p.AbstractID = AB_Abstract.AbstractID inner join
             dbo.InterventionEpisode_UnplanReturn_VR v on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  Left Join
             dbo.LU_YesBlankAlpha Lt with (nolock) ON p.IntervUnplanReturn = lt.Code 
        WHERE AB_Abstract.ICDType = ''T'' 
      ) r ON dbo.AB_Intervention.AbstractID = r.AbstractID AND dbo.AB_Intervention.IntervOccurrence = r.IntervOccurrence Left Join
    --Intervention Episode
      (SELECT    p.AbstractID, v.IntervOccurrence, p.IntervDate, p.IntervDateIn, p.IntervTimeIn, p.IntervDateOut, p.IntervTimeOut, p.IntervTimeMinutes,
                 lt.DisplayCode AS OOHIndicator, lt.UserDescription AS OOHIndicatorDesc,
                 i.DisplayCode AS OOHInstitutionNumber, i.UserDescription AS OOHInstitutionNumberDesc
        FROM dbo.AB_Intervention p with (nolock) INNER JOIN
             dbo.AB_Abstract with (nolock) on p.AbstractID = AB_Abstract.AbstractID inner join
             dbo.InterventionEpisode_VR v on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  Left Join
             dbo.LU_YesBlank Lt with (nolock) ON p.IntervOOHIndicator = lt.Code Left join
             dbo.LU_Institution_10 i ON p.IntervOOHInstitution = i.Code 
        WHERE AB_Abstract.ICDType = ''T'' 
      ) e ON dbo.AB_Intervention.AbstractID = e.AbstractID AND dbo.AB_Intervention.IntervOccurrence = e.IntervOccurrence Left Join
    --Intervention EUL
      (SELECT    p.AbstractID, v.IntervOccurrence, 
                 lt.DisplayCode AS EUL, lt.UserDescription AS EULDesc
        FROM dbo.AB_Intervention p with (nolock) INNER JOIN
             dbo.AB_Abstract with (nolock) on p.AbstractID = AB_Abstract.AbstractID inner join
             dbo.InterventionEpisode_EUL_VR v on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  Left Join
             dbo.LU_IntervEUL Lt with (nolock) ON p.IntervEUL = lt.Code 
        WHERE AB_Abstract.ICDType = ''T'' 
      ) eul ON dbo.AB_Intervention.AbstractID = eul.AbstractID AND dbo.AB_Intervention.IntervOccurrence = eul.IntervOccurrence Left Join
    --Intervention Extra      
      (SELECT    p.AbstractID, v.IntervOccurrence, 
                 lt.DisplayCode AS Extra, lt.UserDescription AS ExtraDesc
        FROM dbo.AB_Intervention p INNER JOIN
             dbo.AB_Abstract on p.AbstractID = AB_Abstract.AbstractID inner join
             dbo.InterventionEpisode_Extra_VR v on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  Left Join
             dbo.LU_IntervExtra Lt ON p.IntervEUL = lt.Code 
        WHERE AB_Abstract.ICDType = ''T'' 
      ) ex ON dbo.AB_Intervention.AbstractID = ex.AbstractID AND dbo.AB_Intervention.IntervOccurrence = ex.IntervOccurrence Left Join
    --Intervention Trip Number      
      (SELECT    p.AbstractID, v.IntervOccurrence, IntervTripNumber as ORTripNumber
        FROM dbo.AB_Intervention p with (nolock) INNER JOIN
             dbo.AB_Abstract with (nolock) on p.AbstractID = AB_Abstract.AbstractID inner join
             dbo.InterventionEpisode_TripNumber_VR v on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  
        WHERE AB_Abstract.ICDType = ''T'' 
      ) trip ON dbo.AB_Intervention.AbstractID = trip.AbstractID AND dbo.AB_Intervention.IntervOccurrence = trip.IntervOccurrence left join
    --Intervention Pre Admit Flag PR - 04313 Intervention Pre Admit Flag is not replicated.
--      (SELECT    p.AbstractID, v.IntervOccurrence, 
--                 lt.DisplayCode AS InterventionPreAdmitFlag, lt.UserDescription AS InterventionPreAdmitFlagDesc
--        FROM dbo.AB_Intervention p INNER JOIN
--             dbo.AB_Abstract on p.AbstractID = AB_Abstract.AbstractID inner join
--             dbo.InterventionEpisode_IntervPreAdmitFlag_VR v on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  Left Join
--             dbo.LU_CodeFile Lt ON p.IntervPreAdmitFlag = lt.Code 
--        WHERE AB_Abstract.ICDType = ''T'' 
--      ) pa ON dbo.AB_Intervention.AbstractID = pa.AbstractID AND dbo.AB_Intervention.IntervOccurrence = pa.IntervOccurrence Left Join
    --Intervention Date In --PR - 04074 CSR want to add this
      (SELECT    p.AbstractID, v.IntervOccurrence, IntervDateIn 
        FROM dbo.AB_Intervention p with (nolock) INNER JOIN
             dbo.AB_Abstract with (nolock) on p.AbstractID = AB_Abstract.AbstractID inner join
             dbo.InterventionEpisode_IntervDateIn_VR v on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  
        WHERE AB_Abstract.ICDType = ''T'' 
      ) DateIn ON dbo.AB_Intervention.AbstractID = DateIn.AbstractID AND dbo.AB_Intervention.IntervOccurrence = DateIn.IntervOccurrence left join
    --Intervention Time In --PR - 04074 CSR want to add this
      (SELECT    p.AbstractID, v.IntervOccurrence, IntervTimeIn 
        FROM dbo.AB_Intervention p with (nolock) INNER JOIN
             dbo.AB_Abstract with (nolock) on p.AbstractID = AB_Abstract.AbstractID inner join
             dbo.InterventionEpisode_IntervTimeIn_VR v on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  
        WHERE AB_Abstract.ICDType = ''T'' 
      ) TimeIn ON dbo.AB_Intervention.AbstractID = TimeIn.AbstractID AND dbo.AB_Intervention.IntervOccurrence = TimeIn.IntervOccurrence left join
    --Intervention Date Out --PR - 04074 CSR want to add this
      (SELECT    p.AbstractID, v.IntervOccurrence, IntervDateOut 
        FROM dbo.AB_Intervention p with (nolock) INNER JOIN
             dbo.AB_Abstract with (nolock) on p.AbstractID = AB_Abstract.AbstractID inner join
             dbo.InterventionEpisode_IntervDateOut_VR v on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  
        WHERE AB_Abstract.ICDType = ''T'' 
      ) DateOut ON dbo.AB_Intervention.AbstractID = DateOut.AbstractID AND dbo.AB_Intervention.IntervOccurrence = DateOut.IntervOccurrence left join
    --Intervention Time Out --PR - 04074 CSR want to add this
      (SELECT    p.AbstractID, v.IntervOccurrence, IntervTimeOut 
        FROM dbo.AB_Intervention p with (nolock) INNER JOIN
             dbo.AB_Abstract with (nolock) on p.AbstractID = AB_Abstract.AbstractID inner join
             dbo.InterventionEpisode_IntervTimeOut_VR v on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  
        WHERE AB_Abstract.ICDType = ''T'' 
      ) TimeOut ON dbo.AB_Intervention.AbstractID = TimeOut.AbstractID AND dbo.AB_Intervention.IntervOccurrence = TimeOut.IntervOccurrence left join
    --Intervention Time In Unknown -- PR - 04332
      (SELECT    p.AbstractID, v.IntervOccurrence, 
                 lt.DisplayCode AS IntervEpisodeStartTimeUnknown, lt.UserDescription AS IntervEpisodeStartTimeUnknownDesc
        FROM dbo.AB_Intervention p with (nolock) INNER JOIN
             dbo.AB_Abstract with (nolock) on p.AbstractID = AB_Abstract.AbstractID inner join
             dbo.InterventionEpisode_TimeInUnknown_VR v on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  Left Join
             dbo.LU_CodeFile Lt ON p.IntervTimeInUnknown = lt.Code 
        WHERE AB_Abstract.ICDType = ''T'' 
      ) TimeInUnknown ON dbo.AB_Intervention.AbstractID = TimeInUnknown.AbstractID AND dbo.AB_Intervention.IntervOccurrence = TimeInUnknown.IntervOccurrence Left Join

    --Intervention Time Out Unknown -- PR - 04332
      (SELECT    p.AbstractID, v.IntervOccurrence, 
                 lt.DisplayCode AS IntervEpisodeEndTimeUnknown, lt.UserDescription AS IntervEpisodeEndTimeUnknownDesc
        FROM dbo.AB_Intervention p with (nolock) INNER JOIN
             dbo.AB_Abstract with (nolock) on p.AbstractID = AB_Abstract.AbstractID inner join
             dbo.InterventionEpisode_TimeOutUnknown_VR v on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  Left Join
             dbo.LU_CodeFile Lt with (nolock) ON p.IntervTimeOutUnknown = lt.Code 
        WHERE AB_Abstract.ICDType = ''T'' 
      ) TimeOutUnknown ON dbo.AB_Intervention.AbstractID = TimeOutUnknown.AbstractID AND dbo.AB_Intervention.IntervOccurrence = TimeOutUnknown.IntervOccurrence Left Join

    --Intervention Suffix -- PR - 05248
      (SELECT    p.AbstractID, v.IntervOccurrence, 
                 lt.DisplayCode AS IntervSuffix, lt.UserDescription AS IntervSuffixDesc
        FROM dbo.AB_Intervention p with (nolock) INNER JOIN
             dbo.AB_Abstract with (nolock) on p.AbstractID = AB_Abstract.AbstractID inner join
             dbo.InterventionEpisode_Suffix_VR v on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  Left Join
             dbo.LU_IntervSuffix Lt ON p.IntervSuffix = lt.Code 
        WHERE AB_Abstract.ICDType = ''T'' 
      ) Suffix ON dbo.AB_Intervention.AbstractID = Suffix.AbstractID AND dbo.AB_Intervention.IntervOccurrence = Suffix.IntervOccurrence  left join

    --Intervention PreAdmitFlag -- PR - 05413
      (SELECT    p.AbstractID, v.IntervOccurrence, 
                 lp.DisplayCode AS IntervPreAdmitFlag, lp.UserDescription AS IntervPreAdmitFlagDesc
        FROM dbo.AB_Intervention p with (nolock) INNER JOIN
             dbo.AB_Abstract with (nolock) on p.AbstractID = AB_Abstract.AbstractID inner join
             dbo.InterventionEpisode_PreAdmitFlag_VR v on p.AbstractID = v.AbstractID and p.IntervOccurrence = v.IntervOccurrence - v.MinOcc  Left Join
             dbo.LU_codeFile Lp with (nolock) ON p.IntervPreAdmitFlag = lp.Code 
        WHERE AB_Abstract.ICDType = ''T'' 
      ) PreAdmit ON dbo.AB_Intervention.AbstractID = PreAdmit.AbstractID AND dbo.AB_Intervention.IntervOccurrence = PreAdmit.IntervOccurrence  

WHERE (dbo.AB_Abstract.DischargeDate > ''2001/03/31'' or dbo.AB_Abstract.AdmitDate > ''2001/03/31'') and
    (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType IN (1, 2)) AND 
    (ISNULL(dbo.AB_Diagnosis.DiagnosisOccurrence, 1) = 1) AND 
    (ISNULL(dbo.AB_PatientService.ServiceOccurrence, 1) = 1) AND 
    (ISNULL(dbo.AB_Provider.ProviderOccurrence, 1) = 1)
*/    



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AbstractingRecordKey_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE  VIEW [dbo].[I10_AbstractingRecordKey_VR]
AS
SELECT
    dbo.AB_Abstract.AdmitDate AS AdmissionDate, dbo.AB_Abstract.AdmitTime AS AdmissionTime, 
	--PR - 05489
	LU_AdmitTimeUnknown.DisplayCode as AdmissionTimeUnknown, LU_AdmitTimeUnknown.UserDescription as AdmissionTimeUnknownDesc,
	----PR - 06060
	LU_AdmitCategory.DisplayCode AS AdmitCategory, LU_AdmitCategory.UserDescription AS AdmitCategoryDesc, 

	--PR - 07231
	LU_AdmitNurseArea.DisplayCode AS AdmitNurseAreaUnitLoc, LU_AdmitNurseArea.UserDescription AS AdmitNurseAreaUnitLocDesc, 

    dbo.AB_Abstract.ChartNumber, 
	U_Users.DisplayCode AS CoderNumber, U_Users.UserDescription AS CoderNumberDesc, --ED - 02401
    dbo.AB_Abstract.DischargeDate, dbo.AB_Abstract.DischargeTime, 
	--PR - 05489
	LU_DischargeTimeUnknown.DisplayCode AS DischargeTimeUnknown, LU_DischargeTimeUnknown.UserDescription AS DischargeTimeUnknownDesc, 
    LU_DispositionCode_I.DisplayCode AS DischargeDisposition, LU_DispositionCode_I.UserDescription AS DischargeDispositionDesc, 

	--PR - 07231
	LU_DischargeNurseArea.DisplayCode AS DischNurseAreaUnitLoc, LU_DischargeNurseArea.UserDescription AS DischNurseAreaUnitLocDesc, 

    dbo.AB_Abstract.EncounterNumber,
    LU_EntryCode.DisplayCode AS EntryCode, LU_EntryCode.UserDescription AS EntryCodeDesc, 
    ISNULL(dbo.AB_Abstract.LastName, '' '') + '', '' + ISNULL(dbo.AB_Abstract.FirstName, '''') + '' '' + ISNULL(dbo.AB_Abstract.MiddleName, '''') AS FullName,     
    FixedChartNumber,
    dbo.AB_Abstract.HealthCareNumber, 
    H_InstitutionProfile.DisplayCode AS InstitutionNumber, H_InstitutionProfile.UserDescription AS InstitutionNumberDesc, 
    ReAdmitDifferenceDaysForDAD = dbo.CalculateReAdmitDifferenceDaysForDAD(ChartNumber, AdmitDate, AbstractID),
    dbo.AB_Abstract.RegisterNumber,
    dbo.AB_Abstract.AbstractID AS zzAbstractLink,
    dbo.AB_Abstract.RegionalPatientID as zzRegionalPatientID 
FROM         
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.H_InstitutionProfile with (nolock) ON dbo.AB_Abstract.InstitutionNumber = H_InstitutionProfile.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_AdmitTimeUnknown with (nolock) on dbo.AB_Abstract.AdmitTimeUnknown = LU_AdmitTimeUnknown.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_DischargeTimeUnknown with (nolock) on dbo.AB_Abstract.DischargeTimeUnknown = LU_DischargeTimeUnknown.Code 
    --ED - 02401
	left join U_Users with (nolock) on AB_Abstract.CoderNumber = U_Users.Code 
	--PR - 06060
	left join dbo.LU_AdmitCategory with (nolock) on dbo.AB_Abstract.AdmitCategory = LU_AdmitCategory.Code 
    left join dbo.LU_EntryCode with (nolock) on dbo.AB_Abstract.EntryCode = LU_EntryCode.Code 
    left join dbo.LU_DispositionCode_I with (nolock) on dbo.AB_Abstract.DispositionCode = LU_DispositionCode_I.Code 
    --PR - 07231
    left join dbo.LU_NurseArea LU_AdmitNurseArea with (nolock) on dbo.AB_Abstract.AdmittingNurseArea = LU_AdmitNurseArea.Code 
    left join dbo.LU_NurseArea LU_DischargeNurseArea with (nolock) on dbo.AB_Abstract.DischargeNurseArea = LU_DischargeNurseArea.Code 
    left join dbo.H_HospitalProfile with (nolock) on dbo.AB_Abstract.HospitalID = H_HospitalProfile.Code 
WHERE     (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 1)
--QA - 00032 disable the domain securite issue
----PR - 07485
--    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB_ABstract.HospitalID is null or AB_ABstract.HospitalID = 0
--    --EN - 00666
--        or Is_Member(nullif(ReportGroup, '''')) = 1)
----        or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB_ABstract.HospitalID, 0))


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AbstractNotes_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_AbstractNotes_VR]
AS
SELECT     
   RecordID AS zzAbstractLink,
   LogNote  as AbstractNotes,
   LogDate  as DateLogged,
   LogTime  as TimeLogged,
   U.DisplayCode as CreateBy,
   U.UserDescription as CreatorName        
from dbo.REC_Notes r with (nolock) left join U_users U with (nolock) on r.LogCoder=u.code
where AppID in ( 200, 201, 202, 401 )


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AllAbstractingGeneral1_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE  VIEW [dbo].[I10_AllAbstractingGeneral1_VR]
AS
SELECT
    dbo.AB_Abstract.AdmitDate AS AdmissionDate, dbo.AB_Abstract.AdmitTime AS AdmissionTime, 
	--PR - 05489
	LU_AdmitTimeUnknown.DisplayCode as AdmissionTimeUnknown, LU_AdmitTimeUnknown.UserDescription as AdmissionTimeUnknownDesc,
    Lookup4.DisplayCode AS AdmitCategory, Lookup4.UserDescription AS AdmitCategoryDesc, 
    LU_AdmitNurse.DisplayCode as AdmitNurseArea, LU_AdmitNurse.UserDescription as AdmitNurseAreaDesc,
    Lookup6.DisplayCode AS AgeCode, 
    Lookup6.UserDescription AS AgeCodeDesc, dbo.AB_Abstract.AgeGroup, dbo.AB_Abstract.AgeNumber, dbo.AB_Abstract.BatchNumber, 
    Lookup50.DisplayCode AS BatchPeriod, Lookup50.UserDescription AS BatchPeriodDesc, dbo.AB_Abstract.BatchYear, dbo.AB_Abstract.BirthDate, 
    dbo.LU_CareType.DisplayCode AS CareType, dbo.LU_CareType.UserDescription AS CareTypeDesc, dbo.AB_Abstract.ChartNumber, 
    Lookup54.DisplayCode AS CoderNumber, Lookup54.UserDescription AS CoderNumberDesc, Lookup60.DisplayCode AS DataEntryCoder, 
    Lookup60.UserDescription AS DataEntryCoderDesc, dbo.AB_Abstract.CIHIDateSent AS DateSenttoCIHI, 
    LU_DischargeNurse.DisplayCode as DischNurseArea, LU_DischargeNurse.UserDescription as DischNurseAreaDesc,
    dbo.AB_Abstract.DischargeDate, 
    --ED - 02929
    (case when caretype = 5 then LU_DispositionCode_A.DisplayCode else LU_DispositionCode_I.DisplayCode end) AS DischargeDisposition, 
    (case when caretype = 5 then LU_DispositionCode_A.UserDescription else LU_DispositionCode_I.UserDescription end) AS DischargeDispositionDesc, 

    dbo.AB_Abstract.DischargeTime, 
	--PR - 05489
	LU_DischargeTimeUnknown.DisplayCode AS DischargeTimeUnknown, LU_DischargeTimeUnknown.UserDescription AS DischargeTimeUnknownDesc, 
    dbo.AB_Abstract.EncounterNumber, 
    Lookup69.DisplayCode AS EntryCode, Lookup69.UserDescription AS EntryCodeDesc,
    dbo.AB_Abstract.FinishDate, dbo.AB_Abstract.FinishTime, 
    dbo.AB_Abstract.FirstName, Lookup72.DisplayCode AS Gender, Lookup72.UserDescription AS GenderDesc, Lookup75.DisplayCode AS HCNProvince, 
    Lookup75.UserDescription AS HCNProvinceDesc, dbo.AB_Abstract.HCNVersion, dbo.AB_Abstract.HealthCareNumber, 
    LU_Hospital.DisplayCode AS Hospital, LU_Hospital.UserDescription AS HospitalDesc, dbo.AB_Abstract.InputDate, dbo.AB_Abstract.InputTime, 
    
	Lookup77.DisplayCode AS InstitutionFrom, Lookup77.UserDescription AS InstitutionFromDesc, 
	LU_InstitutionFrom_Type.DisplayCode AS InstitutionFromType, LU_InstitutionFrom_Type.UserDescription AS InstitutionFromTypeDesc, 
	Lookup78.DisplayCode AS InstitutionTo,     Lookup78.UserDescription AS InstitutionToDesc, 
	LU_InstitutionTo_Type.DisplayCode AS InstitutionToType, LU_InstitutionTo_Type.UserDescription AS InstitutionToTypeDesc, 
	
	Lookup79.DisplayCode AS InterfaceCoder, Lookup79.UserDescription AS InterfaceCoderDesc, 
    
    dbo.AB_Abstract.InterfaceDate, dbo.AB_Abstract.InterfaceTime, 
    
    Lookup80.DisplayCode AS IsAbstractCompleted,                  Lookup80.UserDescription AS IsAbstractCompletedDesc, 
    LU_Level1_Completed.DisplayCode AS IsAbstractCompletedLevel1, LU_Level1_Completed.UserDescription AS IsAbstractCompletedLevel1Desc, 
    LU_Level1_Completed.DisplayCode AS IsAbstractCompletedLevel2, LU_Level1_Completed.UserDescription AS IsAbstractCompletedLevel2Desc, 
    LU_Level1_Completed.DisplayCode AS IsAbstractCompletedLite,   LU_Level1_Completed.UserDescription AS IsAbstractCompletedLiteDesc, 

    Lookup81.DisplayCode AS IsAbstractCorrected,                   Lookup81.UserDescription AS IsAbstractCorrectedDesc, 
    LU_Level1_Correction.DisplayCode AS IsAbstractCorrectedLevel1, LU_Level1_Correction.UserDescription AS IsAbstractCorrectedLevel1Desc, 
    LU_Level1_Correction.DisplayCode AS IsAbstractCorrectedLevel2, LU_Level1_Correction.UserDescription AS IsAbstractCorrectedLevel2Desc, 
    LU_Level1_Correction.DisplayCode AS IsAbstractCorrectedLite,   LU_Level1_Correction.UserDescription AS IsAbstractCorrectedLiteDesc, 

    Lookup82.DisplayCode AS IsAbstractDeleted,       Lookup82.UserDescription AS IsAbstractDeletedDesc, 

    Lookup83.DisplayCode AS IsAbstractSubmited,                    Lookup83.UserDescription AS IsAbstractSubmitedDesc, 
    LU_Level1_Submission.DisplayCode AS IsAbstractSubmittedLevel1, LU_Level1_Submission.UserDescription AS IsAbstractSubmittedLevel1Desc, 
    LU_Level1_Submission.DisplayCode AS IsAbstractSubmittedLevel2, LU_Level1_Submission.UserDescription AS IsAbstractSubmittedLevel2Desc, 
    LU_Level1_Submission.DisplayCode AS IsAbstractSubmittedLite,   LU_Level1_Submission.UserDescription AS IsAbstractSubmittedLiteDesc, 

    Lookup84.DisplayCode AS IsAbstractValidated,                   Lookup84.UserDescription AS IsAbstractValidatedDesc, 
    LU_Level1_Validation.DisplayCode AS IsAbstractValidatedLevel1, LU_Level1_Validation.UserDescription AS IsAbstractValidatedLevel1Desc, 
    LU_Level1_Validation.DisplayCode AS IsAbstractValidatedLevel2, LU_Level1_Validation.UserDescription AS IsAbstractValidatedLevel2Desc, 
    LU_Level1_Validation.DisplayCode AS IsAbstractValidatedLite,   LU_Level1_Validation.UserDescription AS IsAbstractValidatedLiteDesc, 
    
    
    Lookup85.DisplayCode AS IsBirthdateEstimated, 
    Lookup85.UserDescription AS IsBirthdateEstimatedDesc, 
	LU_CustomStatus.DisplayCode AS IsCustomValidated, LU_CustomStatus.UserDescription AS IsCustomValidatedDesc, 
	dbo.AB_Abstract.LOSDays, dbo.AB_Abstract.LOSMinutes, 
    dbo.AB_Abstract.LOSTime AS LOSTimeinHours, dbo.AB_Abstract.LastName, dbo.AB_Abstract.MaidenName, Lookup88.DisplayCode AS MaritalStatus, 
    Lookup88.UserDescription AS MaritalStatusDesc, dbo.AB_Abstract.NewbornChart AS MaternalNewbornChartNumber, 
    dbo.AB_Abstract.NewbornDischargeDate AS MaternalNewbornDischargeDate, dbo.AB_Abstract.MiddleName, 
    dbo.LU_MISCode.DisplayCode AS MISCode, dbo.LU_MISCode.UserDescription AS MISCodeDesc, ISNULL(dbo.AB_Abstract.LastName, '' '') 
    + '', '' + ISNULL(dbo.AB_Abstract.FirstName, '''') + '' '' + ISNULL(dbo.AB_Abstract.MiddleName, '''') AS NameFull, 
    dbo.AB_Manitoba.HCNExpiredDate  as OutProvinceHealthInsuranceExpiryDate,
    dbo.AB_Abstract.PostalCode, 
    -- ED - 01682
    dbo.GetPostalDescription(isnull(dbo.AB_Abstract.PostalCode, ''''), isnull(dbo.AB_Abstract.DischargeDate, dbo.AB_Abstract.AdmitDate)) AS PostalDescription, -- ED - 01682

    dbo.AB_Abstract.RegisterNumber, Lookup111.DisplayCode AS ReportingProvInstNumber, 
    Lookup111.UserDescription AS ReportingProvInstNumberDesc, Lookup112.DisplayCode AS ResidenceCode, 
    Lookup112.UserDescription AS ResidenceCodeDesc, Lookup114.DisplayCode AS ResponsiblityForPayment, 
    Lookup114.UserDescription AS ResponsiblityForPaymentDesc, 
    --PR - 03606
    dbo.AB_Abstract.SecondChartRegNumber AS SecondChartRegisterNumber, 
    Lookup116.DisplayCode AS SecretVIPPatient, 
    Lookup116.UserDescription AS SecretVIPPatientDesc, Lookup117.DisplayCode AS SiteNumber, Lookup117.UserDescription AS SiteNumberDesc, 
    dbo.AB_Abstract.RecordType AS SubmissionType, dbo.AB_Abstract.UniqiueLifetimeID AS ULI, dbo.AB_Abstract.Weight AS Weightingrams, 
    dbo.AB_Abstract.AbstractID AS zzAbstractLink, dbo.AB_Abstract.VolumeID AS zzVolumeLink
FROM        
    dbo.AB_Abstract with (nolock) LEFT OUTER JOIN
    dbo.H_HospitalProfile LU_Hospital with (nolock) on dbo.AB_Abstract.HospitalID = LU_Hospital.Code LEFT OUTER JOIN
    dbo.LU_MISCode with (nolock) on dbo.AB_Abstract.MISCode = dbo.LU_MISCode.Code LEFT OUTER JOIN
    dbo.LU_CareType with (nolock) on dbo.AB_Abstract.CareType = dbo.LU_CareType.Code LEFT OUTER JOIN
    dbo.LU_AdmitCategory Lookup4 with (nolock) on dbo.AB_Abstract.AdmitCategory = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_AgeCode Lookup6 with (nolock) on dbo.AB_Abstract.AgeCode = Lookup6.Code LEFT OUTER JOIN
    dbo.LU_BatchPeriod Lookup50 with (nolock) on dbo.AB_Abstract.BatchPeriod = Lookup50.Code LEFT OUTER JOIN
    dbo.U_Users Lookup54 with (nolock) on dbo.AB_Abstract.CoderNumber = Lookup54.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup55 with (nolock) on dbo.AB_Abstract.Complication = Lookup55.Code LEFT OUTER JOIN
    dbo.U_Users Lookup60 with (nolock) on dbo.AB_Abstract.DataEntryCoder = Lookup60.Code LEFT OUTER JOIN
    dbo.LU_Gender_I Lookup72 with (nolock) on dbo.AB_Abstract.Gender = Lookup72.Code LEFT OUTER JOIN
    dbo.LU_HCNProvince Lookup75 with (nolock) on dbo.AB_Abstract.HCNProvince = Lookup75.Code LEFT OUTER JOIN

    dbo.LU_Institution_10 Lookup77 with (nolock) on dbo.AB_Abstract.InstitutionFrom = Lookup77.Code LEFT OUTER JOIN
	LU_Institution_TypeCode LU_InstitutionFrom_Type with (nolock) on dbo.AB_Abstract.InstitutionFromType = LU_InstitutionFrom_Type.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 Lookup78 with (nolock) on dbo.AB_Abstract.InstitutionTo = Lookup78.Code LEFT OUTER JOIN
	LU_Institution_TypeCode LU_InstitutionTo_Type with (nolock) on dbo.AB_Abstract.InstitutionToType = LU_InstitutionTo_Type.Code LEFT OUTER JOIN

    dbo.U_Users Lookup79 with (nolock) on dbo.AB_Abstract.InterfaceCoder = Lookup79.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus Lookup80 with (nolock) on dbo.AB_Abstract.IsCompleted = Lookup80.Code LEFT OUTER JOIN
    dbo.LU_CIHICorrect Lookup81 with (nolock) on dbo.AB_Abstract.IsCorrected = Lookup81.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem Lookup82 with (nolock) on dbo.AB_Abstract.IsDeleted = Lookup82.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem Lookup83 with (nolock) on dbo.AB_Abstract.IsSubmited = Lookup83.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus Lookup84 with (nolock) on dbo.AB_Abstract.IsValidated = Lookup84.Code LEFT OUTER JOIN
    dbo.LU_CustomStatus with (nolock) on dbo.AB_Abstract.IsCustomValidated = LU_CustomStatus.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup85 with (nolock) on dbo.AB_Abstract.BirthDateEstimated = Lookup85.Code LEFT OUTER JOIN
    dbo.LU_MaritalStatus Lookup88 with (nolock) on dbo.AB_Abstract.MaritalStatus = Lookup88.Code LEFT OUTER JOIN
    dbo.H_InstitutionProfile Lookup111 with (nolock) on dbo.AB_Abstract.InstitutionNumber = Lookup111.Code LEFT OUTER JOIN
    dbo.LU_ResidenceCode Lookup112 with (nolock) on dbo.AB_Abstract.ResidenceCode = Lookup112.Code LEFT OUTER JOIN
    dbo.LU_RespPayment Lookup114 with (nolock) on dbo.AB_Abstract.ResponsiblePayment = Lookup114.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup116 with (nolock) on dbo.AB_Abstract.Secret = Lookup116.Code LEFT OUTER JOIN
    dbo.LU_Site Lookup117 with (nolock) on dbo.AB_Abstract.SiteNumber = Lookup117.Code LEFT OUTER JOIN
    dbo.LU_NurseArea LU_AdmitNurse with (nolock) on dbo.AB_Abstract.AdmittingNurseArea = LU_AdmitNurse.Code LEFT OUTER JOIN
    dbo.LU_NurseArea LU_DischargeNurse with (nolock) on dbo.AB_Abstract.DischargeNurseArea = LU_DischargeNurse.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_AdmitTimeUnknown with (nolock) on dbo.AB_Abstract.AdmitTimeUnknown = LU_AdmitTimeUnknown.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_DischargeTimeUnknown with (nolock) on dbo.AB_Abstract.DischargeTimeUnknown = LU_DischargeTimeUnknown.Code 
    --ED - 02929
    LEFT OUTER JOIN dbo.LU_DispositionCode_I with (nolock) on LU_DispositionCode_I.Code = dbo.AB_Abstract.DispositionCode 
    LEFT OUTER JOIN dbo.LU_DispositionCode_A with (nolock) on LU_DispositionCode_A.Code = dbo.AB_Abstract.DispositionCode 
    Left OUTER JOIN dbo.AB_Manitoba with (nolock) on dbo.AB_Manitoba.AbstractID = dbo.AB_Abstract.AbstractID
    LEFT OUTER JOIN dbo.LU_CIHICorrect LU_Level1_Correction with (nolock) on dbo.AB_Abstract.IsCorrectLevel1 = LU_Level1_Correction.Code 
    LEFT OUTER JOIN dbo.LU_YesNoSystem LU_Level1_Submission with (nolock) on dbo.AB_Abstract.IsSubmitLevel1 = LU_Level1_Submission.Code 
    LEFT OUTER JOIN dbo.LU_AbstractStatus LU_Level1_Validation with (nolock) on dbo.AB_Abstract.IsValidLevel1 = LU_Level1_Validation.Code 
    LEFT OUTER JOIN dbo.LU_AbstractStatus LU_Level1_Completed with (nolock) on dbo.AB_Abstract.IsCompleteLevel1 = LU_Level1_Completed.Code 
    LEFT OUTER JOIN dbo.LU_EntryCode Lookup69 with (nolock) on dbo.AB_Abstract.EntryCode = Lookup69.Code 
WHERE     (dbo.AB_Abstract.ICDType = ''T'')
--QA - 00032 disable the domain securite issue
--    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB_ABstract.HospitalID is null or AB_ABstract.HospitalID = 0
--    --EN - 00666
--        or Is_Member(nullif(ReportGroup, '''')) = 1)
----        or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB_ABstract.HospitalID, 0)))
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AmCare_CACS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[I10_AmCare_CACS_VR]
AS
SELECT     dbo.AB_CACS.OccurrenceNumber, 
	dbo.AB_CACS.BatchGroupDate,
	dbo.AB_CACS.CACS_Year AS CACSYear, dbo.AB_CACS.MAC, 
        (case when dbo.AB_CACS.CACS_Year < 2011
              then
                  (CASE (case when isnumeric(dbo.AB_CACS.MAC) = 0 then 0 else cast(dbo.AB_CACS.MAC as int) end)
                        WHEN 1 THEN ''Diseases and Disorders of the Nervous System'' 
                        WHEN 2 THEN ''Diseases and Disorders of the Eye'' 
                        WHEN 3 THEN ''Diseases and Disorders of the Ear, Nose, Mouth and Throat'' 
                        WHEN 4 THEN ''Diseases and Disorders of the Respiratory System'' 
                        WHEN 5 THEN ''Diseases and Disorders of the Circulatory System'' 
                        WHEN 6 THEN ''Diseases and Disorders of the Digestive System'' 
                        WHEN 7 THEN ''Diseases and Disorders of the Hepatobiliary System and Pancreas''
                        WHEN 8 THEN ''Diseases and Disorders of the Musculoskeletal System and Connective Tissue'' 
                        WHEN 9 THEN ''Diseases and Disorders of the Skin and Subcutaneous Tissue and Breast''
                        WHEN 10 THEN ''Endocrine, Nutritional, and Metabolic Diseases and Disorders'' 
                        WHEN 11 THEN ''Diseases and Disorders of Kidney and Genitourinary Tract''
                        WHEN 14 THEN ''Pregnancy, Childbirth, Newborns and Neonates'' 
                        WHEN 16 THEN ''Haematology Including Lymphoma, Leukaemia and Unspecified Site Neoplasms''
                        WHEN 17 THEN ''Oncological Diseases and Disorders'' 
                        WHEN 18 THEN ''Systemic Infections Including HIV'' 
                        WHEN 19 THEN ''Mental Diseases and Disorders''
                        WHEN 20 THEN ''Examination and Other Health Factors'' 
                        WHEN 21 THEN ''Trauma, Coma and Toxic Effects'' 
                        WHEN 99 THEN ''Ungroupable'' ELSE '''' END)
              else 
                (select top 1 mac_long_e_desc from dbo.tGrouper_CACS_MAC where tGrouper_CACS_MAC.methodology_year = dbo.AB_CACS.CACS_Year and dbo.AB_CACS.MAC = tGrouper_CACS_MAC.mac_code)
              end) AS MACDescription, 
        dbo.AB_CACS.CACSCell, dbo.AB_CACS.ACW, dbo.AB_CACS.CACSDescription, 
        dbo.ICD_ProcFile10.DisplayCode AS InterventionCode, dbo.ICD_ProcFile10.UserDescription AS IntervCodeDescription, 
        dbo.ICD_ProcFile10.ShortDescription AS InterventionCodeShortDesc, 
        dbo.AB_CACS.AgeCategory, dbo.tGrouper_CACS_Age_Category.cacs_age_category_e_desc as AgeCategoryDesc,
        dbo.AB_CACS.AnaestheticCategory, dbo.tGrouper_CACS_Aanaesthetic.cacs_anaesthetic_e_desc as AnaestheticCategoryDesc,
        dbo.AB_CACS.MITTotalCount AS InvestigativeTechnologyTotalCount,
        ACW_HBAM as CACSHBAM,
        ACW_Base as CACSBaseRIW,
        CACSPartition, 
        MIT_Category_01 as InvestigativeTechnologyCategory_01, MIT_Category_Count_01 as InvestigativeTechnologyCategoryCount_01, 
        MIT_Category_02 as InvestigativeTechnologyCategory_02, MIT_Category_Count_02 as InvestigativeTechnologyCategoryCount_02, 
        MIT_Category_03 as InvestigativeTechnologyCategory_03, MIT_Category_Count_03 as InvestigativeTechnologyCategoryCount_03, 
        MIT_Category_04 as InvestigativeTechnologyCategory_04, MIT_Category_Count_04 as InvestigativeTechnologyCategoryCount_04, 
        MIT_Category_05 as InvestigativeTechnologyCategory_05, MIT_Category_Count_05 as InvestigativeTechnologyCategoryCount_05, 
        MIT_Category_06 as InvestigativeTechnologyCategory_06, MIT_Category_Count_06 as InvestigativeTechnologyCategoryCount_06, 
        MIT_Category_07 as InvestigativeTechnologyCategory_07, MIT_Category_Count_07 as InvestigativeTechnologyCategoryCount_07, 
        MIT_Category_08 as InvestigativeTechnologyCategory_08, MIT_Category_Count_08 as InvestigativeTechnologyCategoryCount_08, 
        MIT_Category_09 as InvestigativeTechnologyCategory_09, MIT_Category_Count_09 as InvestigativeTechnologyCategoryCount_09, 
        MIT_Category_10 as InvestigativeTechnologyCategory_10, MIT_Category_Count_10 as InvestigativeTechnologyCategoryCount_10,
		dbo.AB_Abstract.AbstractID AS zzAbstractLink
FROM         dbo.AB_CACS with (nolock) RIGHT OUTER JOIN
                      dbo.AB_Abstract with (nolock) ON dbo.AB_CACS.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
                      dbo.ICD_ProcFile10 with (nolock) ON dbo.AB_CACS.InterventionCode = dbo.ICD_ProcFile10.Code LEFT OUTER JOIN
		dbo.tGrouper_CACS_Age_Category with (nolock) ON dbo.AB_CACS.AgeCategory = dbo.tGrouper_CACS_Age_Category.cacs_age_category_code
						and dbo.AB_CACS.CACS_Year = dbo.tGrouper_CACS_Age_Category.methodology_year LEFT OUTER JOIN
		dbo.tGrouper_CACS_Aanaesthetic with (nolock) ON dbo.AB_CACS.AnaestheticCategory = dbo.tGrouper_CACS_Aanaesthetic.cacs_anaesthetic_code
						and dbo.AB_CACS.CACS_Year = dbo.tGrouper_CACS_Aanaesthetic.methodology_year LEFT OUTER JOIN
        dbo.AB_CACS_Investigative with (nolock) ON 	AB_CACS.AbstractID = AB_CACS_Investigative.AbstractID
						and AB_CACS.OccurrenceNumber = AB_CACS_Investigative.OccurrenceNumber 
						and AB_CACS.CACS_Year = AB_CACS_Investigative.CACS_Year
WHERE     (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5) AND (dbo.AB_CACS.OccurrenceNumber = 1)
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AmCare_CCM_SystemicDrug_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE view [dbo].[I10_AmCare_CCM_SystemicDrug_VR]
AS  
select
    BodySurfaceArea = dbo.AB_CCM_SystemicDrug.BodySurfaceArea,
    CCODrugCode = dbo.AB_CCM_SystemicDrug.CCODrugCode, 
    CCORegimen = LU_CCORegimen.DisplayCode, CCORegimenDesc = LU_CCORegimen.UserDescription,
    CMIRSeverity = LU_CMIRSeverity.DisplayCode, CMIRSeverityDesc = LU_CMIRSeverity.UserDescription,
    DIN = dbo.AB_CCM_SystemicDrug.CCMDIN,
    DoseAdministered = dbo.AB_CCM_SystemicDrug.DoseAdministered,
    DrugOriginFlag = LU_DrugOriginFlag.DisplayCode, DrugOriginFlagDesc = LU_DrugOriginFlag.UserDescription,
    IntentOfSystemicTreatment = LU_IntentOfSystemicTreatment.DisplayCode, IntentOfSystemicTreatmentDesc = LU_IntentOfSystemicTreatment.UserDescription,
    LineOfTherapy = dbo.AB_CCM_SystemicDrug.LineOfTherapy,
    MeasurementUnit = LU_MeasurementUnit.DisplayCode, MeasurementUnitDesc = LU_MeasurementUnit.UserDescription,
    Route = LU_Route.DisplayCode, RouteDesc = LU_Route.UserDescription,

    dbo.AB_CCM_SystemicDrug.Occurrence as DrugOccurrence,
    dbo.AB_CCM_SystemicDrug.AbstractID as zzNACRSLink
from dbo.AB_CCM_SystemicDrug with (nolock) left join
    dbo.LU_CodeFile LU_CCORegimen with (nolock) on dbo.AB_CCM_SystemicDrug.CCORegimen = LU_CCORegimen.Code left join
    dbo.LU_YesNoAlpha LU_DrugOriginFlag with (nolock) on dbo.AB_CCM_SystemicDrug.DrugOriginFlag = LU_DrugOriginFlag.Code left join
    dbo.LU_CodeFile LU_MeasurementUnit with (nolock) on dbo.AB_CCM_SystemicDrug.MeasurementUnit = LU_MeasurementUnit.Code left join
    dbo.LU_CodeFile LU_Route with (nolock) on dbo.AB_CCM_SystemicDrug.[Route] = LU_Route.Code left join
    dbo.LU_CodeFile LU_IntentOfSystemicTreatment with (nolock) on dbo.AB_CCM_SystemicDrug.IntentOfSystemicTreatment = LU_IntentOfSystemicTreatment.Code left join
    dbo.LU_CodeFile LU_CMIRSeverity with (nolock) on dbo.AB_CCM_SystemicDrug.CMIRSeverity = LU_CMIRSeverity.Code 



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AmCare_CCM_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'




CREATE VIEW [dbo].[I10_AmCare_CCM_VR]
AS
SELECT     
    ArrivedByNotTreatedFlag = LU_ArrivedByNotTreatedFlag.DisplayCode, ArrivedByNotTreatedFlagDesc = LU_ArrivedByNotTreatedFlag.UserDescription,
    BodyRegionCode = LU_CCM_BodyRegion.DisplayCode, BodyRegionCodeDesc = LU_CCM_BodyRegion.UserDescription,
    CCM_DiseaseSequenceNumber = dbo.CC_DiseaseRegister.DiseaseSequenceNum,
    CCM_Hospital_Number = right(H_InstitutionProfile_submit.CIHIValue, 4), CCM_Hospital_NumberDesc = H_InstitutionProfile_submit.UserDescription,
    CCM_RegistrationDate = dbo.CC_DiseaseRegister.RegisterDate,
    dbo.CC_Demographic.ChartNumber, 
    ChemoFlag = LU_ChemoFlag.DisplayCode, ChemoFlagDesc = LU_ChemoFlag.UserDescription,
    ClinicalTrialFlag = LU_ClinicalTrialFlag.DisplayCode, ClinicalTrialFlagDesc = LU_ClinicalTrialFlag.UserDescription,
    CourseOfRadiationTreatment = dbo.AB_CCM_Radiation.CourseOfRadiationTreatment,
    CourseCompleteFlag = LU_CourseCompleteFlag.DisplayCode, CourseCompleteFlagDesc = LU_CourseCompleteFlag.UserDescription,
    DecisionToTreatDate = dbo.AB_CCM_Radiation.DecisionToTreatDate,
    DosePerFraction = dbo.AB_CCM_Radiation.DosePerFraction, 
    HealthCareProviderNumber = LU_Provider.DisplayCode, HealthCareProviderNumberDesc = LU_Provider.UserDescription, 
    InpatientFlag = LU_InpatientFlag.DisplayCode, InpatientFlagDesc = LU_InpatientFlag.UserDescription,
    InstitutionNumber = H_InstitutionProfile_visit.DisplayCode, InstitutionNumberDesc = H_InstitutionProfile_visit.UserDescription,
    IntentOfRadiationTreatment = LU_IntentOfRadiationTreatment.DisplayCode, IntentOfRadiationTreatmentDesc = LU_IntentOfRadiationTreatment.UserDescription,
    MISFunctionalCentre = LU_MISCode.DisplayCode, MISFunctionalCentreDesc = LU_MISCode.UserDescription,
    NHPIPCode = LU_CCM_NHPIP_Code.DisplayCode, NHPIPCodeDesc = LU_CCM_NHPIP_Code.UserDescription,
    AB_Abstract.PostalCode,
    ReadyToTreatDate = dbo.AB_CCM_Radiation.ReadyToTreatDate, 
    RadiationRreviewFlag = LU_RadiationReviewFlag.DisplayCode, RadiationRreviewFlagDesc = LU_RadiationReviewFlag.UserDescription, 
    RegistrationVisitDate = AB_Abstract.AdmitDate, RegistrationVisitTime = AB_Abstract.AdmitTime,
    ResidenceCode = LU_ResidenceCode.DisplayCode, ResidenceCodeDesc = LU_ResidenceCode.UserDescription,
    AB_CCM_Radiation.RTProtocol,
    TreatmentUnitName = dbo.AB_CCM_Radiation.TreatmentUnitName,
    UrgencyCategory = LU_UrgencyCategory.DisplayCode, UrgencyCategoryDesc = LU_UrgencyCategory.UserDescription,
    VisitProgramCode = LU_VisitProgramCode.DisplayCode, VisitProgramCodeDesc = LU_VisitProgramCode.UserDescription,
    VisitType = LU_CCMVisitType.DisplayCode, VisitTypeDesc = LU_CCMVisitType.UserDescription, 

    dbo.AB_CCM_CancerCareInformation.AbstractID as zzNACRSLink,
    dbo.CC_Demographic.AbstractID as zzCCMDiseaseLink
FROM
    dbo.AB_Abstract with (nolock) inner join 
    dbo.H_InstitutionProfile H_InstitutionProfile_visit with (nolock) on H_InstitutionProfile_visit.Code = dbo.AB_Abstract.InstitutionNumber inner JOIN
    dbo.AB_CCM_CancerCareInformation with (nolock) on dbo.AB_ABstract.AbstractId = dbo.AB_CCM_CancerCareInformation.AbstractID inner join
    AB_Main with (nolock) on dbo.AB_CCM_CancerCareInformation.CancerCareVisit = AB_Main.UniversalID inner join
    dbo.CC_Demographic with (nolock) on AB_Main.AbstractID = dbo.CC_Demographic.AbstractID inner join 
    dbo.CC_DiseaseRegister with (nolock) on dbo.CC_Demographic.AbstractID = dbo.CC_DiseaseRegister.AbstractID LEFT OUTER JOIN
    dbo.H_InstitutionProfile H_InstitutionProfile_submit with (nolock) on H_InstitutionProfile_submit.Code = dbo.CC_Demographic.InstitutionNumber LEFT OUTER JOIN
    dbo.AB_CCM_Radiation with (nolock) on dbo.AB_CCM_CancerCareInformation.AbstractID = dbo.AB_CCM_Radiation.AbstractID left join

    dbo.LU_MISCode with (nolock) on dbo.AB_ABstract.MISCode = lu_MISCode.Code left join
    dbo.LU_ResidenceCode with (nolock) on dbo.AB_ABstract.ResidenceCode = LU_ResidenceCode.Code left join
    dbo.LU_CodeFile LU_VisitProgramCode with (nolock) on dbo.AB_CCM_CancerCareInformation.VisitProgramCode = LU_VisitProgramCode.Code left join
    dbo.LU_CodeFile LU_CCMVisitType with (nolock) on dbo.AB_CCM_CancerCareInformation.CCMVisitType = LU_CCMVisitType.Code left join
    dbo.LU_YesNoAlpha LU_InpatientFlag with (nolock) on dbo.AB_CCM_CancerCareInformation.InpatientFlag = LU_InpatientFlag.Code Left join
    dbo.LU_CodeFile LU_RadiationReviewFlag with (nolock) on dbo.AB_CCM_CancerCareInformation.RadiationReviewFlag = LU_RadiationReviewFlag.Code Left join
    dbo.LU_Provider with (nolock) on dbo.AB_CCM_CancerCareInformation.HealthCareProviderNumber = LU_Provider.Code left join
    dbo.LU_YesNoAlpha LU_ArrivedByNotTreatedFlag with (nolock) on dbo.AB_CCM_CancerCareInformation.ArrivedByNotTreatedFlag = LU_ArrivedByNotTreatedFlag.Code left join

    dbo.LU_YesNoAlpha LU_ChemoFlag with (nolock) on dbo.AB_CCM_CancerCareInformation.ChemoFlag = LU_ChemoFlag.Code Left join
    dbo.LU_YesNoAlpha LU_ClinicalTrialFlag with (nolock) on dbo.AB_CCM_CancerCareInformation.ClinicalTrialFlag = LU_ClinicalTrialFlag.Code Left join

    dbo.LU_YesNoAlpha LU_CourseCompleteFlag with (nolock) on dbo.AB_CCM_Radiation.CourseCompleteFlag = LU_CourseCompleteFlag.Code left join
    dbo.LU_CCM_NHPIP_Code with (nolock) on dbo.AB_CCM_Radiation.NHPIPCode = LU_CCM_NHPIP_Code.Code left join
    dbo.LU_CCM_BodyRegion with (nolock) on dbo.AB_CCM_Radiation.BodyRegionCode = LU_CCM_BodyRegion.code left join
    dbo.LU_CodeFile LU_IntentOfRadiationTreatment with (nolock) on dbo.AB_CCM_Radiation.IntentOfRadiationTreatment = LU_IntentOfRadiationTreatment.Code left join
    dbo.LU_CodeFile LU_UrgencyCategory with (nolock) on dbo.AB_CCM_Radiation.UrgencyCategory = LU_UrgencyCategory.Code 





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Consult_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_Amcare_Consult_VR]
AS
SELECT
    ConsultOccurrence = Occurrence,
    ConsultArrivalDate, ConsultArrivalTime,
    ConsultArrivalTimeUnknown = LU_ConsultArrivalTimeUnknown.DisplayCode, ConsultArrivalTimeUnknownDesc = LU_ConsultArrivalTimeUnknown.UserDescription,
    ConsultNumber = LU_Provider.DisplayCode, ConsultNumberDesc = LU_Provider.UserDescription, 
    ConsultRequestDate, ConsultRequestTime,
    ConsultRequestTimeUnknown = LU_ConsultRequestTimeUnknown.DisplayCode, ConsultRequestTimeUnknownDesc = LU_ConsultRequestTimeUnknown.UserDescription,
    ConsultService = LU_ProviderSpecialty.DisplayCode, ConsultServiceDesc = LU_ProviderSpecialty.UserDescription, 
    dbo.AB_Consult.AbstractID AS zzAbstractLink
FROM dbo.AB_Consult with (nolock)     
    left join dbo.LU_Provider with (nolock) on dbo.AB_Consult.ConsultNumber = LU_Provider.Code
    left join dbo.LU_ProviderSpecialty with (nolock) on dbo.AB_Consult.ConsultService = LU_ProviderSpecialty.Code
    left join dbo.LU_CodeFile LU_ConsultRequestTimeUnknown with (nolock) on dbo.AB_Consult.ConsultRequestTimeUnknown = LU_ConsultRequestTimeUnknown.Code
    left join dbo.LU_CodeFile LU_ConsultArrivalTimeUnknown with (nolock) on dbo.AB_Consult.ConsultArrivalTimeUnknown = LU_ConsultArrivalTimeUnknown.Code
    
    




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_Amcare_Diagnosis_VR]
AS
SELECT  
    dbo.AB_Diagnosis.DiagnosisCluster,
    dbo.ICD_DiagFile10.CIHIValue AS DiagnosisCIHIValue, dbo.ICD_DiagFile10.DisplayCode AS DiagnosisCode, 
    dbo.ICD_DiagFile10.UserDescription AS DiagnosisCodeDesc, dbo.ICD_DiagFile10.ShortDescription AS DiagnosisCodeShortDesc, 
    dbo.ICD_DiagFile10.ICD9 AS DiagnosisICD9Equivalent, dbo.ICD_DiagFile10.ICD9cm AS DiagnosisICD9cmEquivalent, 
    dbo.AB_Diagnosis.DiagnosisOccurrence, Lookup55.DisplayCode AS DiagnosisPrefix, Lookup55.UserDescription AS DiagnosisPrefixDesc, 
    Lookup56.DisplayCode AS DiagnosisSuffix, Lookup56.UserDescription AS DiagnosisSuffixDesc, Lookup57.DisplayCode AS DiagnosisType, 
    Lookup57.UserDescription AS DiagnosisTypeDesc, dbo.AB_Diagnosis.AbstractID AS zzAbstractLink
FROM         dbo.AB_Diagnosis with (nolock) LEFT OUTER JOIN
                      dbo.ICD_DiagFile10 with (nolock) on dbo.AB_Diagnosis.DiagnosisCode = dbo.ICD_DiagFile10.Code RIGHT OUTER JOIN
                      dbo.AB_Abstract with (nolock) on dbo.AB_Diagnosis.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
                      dbo.LU_DiagnosisPrefix Lookup55 with (nolock) on dbo.AB_Diagnosis.DiagnosisPrefix = Lookup55.Code LEFT OUTER JOIN
                      dbo.LU_DiagnosisSuffix Lookup56 with (nolock) on dbo.AB_Diagnosis.DiagnosisSuffix = Lookup56.Code LEFT OUTER JOIN
                      dbo.LU_DiagnosisType Lookup57 with (nolock) on dbo.AB_Diagnosis.DiagnosisType = Lookup57.Code
WHERE     (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5) AND (dbo.AB_Diagnosis.DiagnosisOccurrence IS NOT NULL)




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_DischargeDiagnosis]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE view [dbo].[I10_Amcare_DischargeDiagnosis]
as
select
	AbstractID as zzAbstractLink,
	Occurrence as DischargeDiagnosisOccurrence,
	LU_DischargeDiagnosis.DisplayCode as DischargeDiagnosis,
	LU_DischargeDiagnosis.UserDescription as DischargeDiagnosisDesc
from dbo.AB_DischargeDiagnosis with (nolock)
	left join ICD_DiagFile10 LU_DischargeDiagnosis with (nolock) on DischargeDiagnosis = LU_DischargeDiagnosis.Code


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_EDInterventionPicklist_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE view [dbo].[I10_Amcare_EDInterventionPicklist_VR]
as
select
	LU_EDIntervnetionPickList.DisplayCode as EDIntervnetionPickList, LU_EDIntervnetionPickList.UserDescription as EDIntervnetionPickListDesc, 
	[Occurrence] as EDIntervnetionPickListOccurrence,
	[AbstractID] as zzAbstractLink
from [dbo].[AB_EDInterventionPicklist]
	left join LU_EDIntervnetionPickList on [AB_EDInterventionPicklist].[EDInterventionPickList] = LU_EDIntervnetionPickList.Code
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_EDInvestigativeTechnology_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE view [dbo].[I10_Amcare_EDInvestigativeTechnology_VR]
as
select
	LU_EDInvestigativeTechnology.DisplayCode as EDInvestigativeTechnology, LU_EDInvestigativeTechnology.UserDescription as EDInvestigativeTechnologyDesc, 
	[Occurrence] as EDInvestigativeTechnologyOccurrence,
	[NumberInvestigativeTechnologyPerformed] as [NumberEDInvestigativeTechnologyPerformed],
	[AbstractID] as zzAbstractLink
from [dbo].[AB_InvestigativeTechnology]
	left join LU_EDInvestigativeTechnology on [AB_InvestigativeTechnology].[InvestigativeTechnology] = LU_EDInvestigativeTechnology.Code
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_InterventionReplication_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[I10_Amcare_InterventionReplication_VR]
AS
SELECT     ISNULL(Lookup20.DisplayCode, OCC.AnestheticTechnique) AS AnestheticTechnique, ISNULL(Lookup20.UserDescription, 
                      OCC.AnestheticTechniqueDesc) AS AnestheticTechniqueDesc, ISNULL(Lookup21.DisplayCode, OCC.AnesthetistID) AS AnesthetistID, 
                      ISNULL(Lookup21.UserDescription, OCC.AnesthetistIDDesc) AS AnesthetistIDDesc, ISNULL(Lookup62.DisplayCode, OCC.EUL) AS EUL, 
                      ISNULL(Lookup62.UserDescription, OCC.EULDesc) AS EULDesc, ISNULL(Lookup66.DisplayCode, OCC.Extra) AS Extra, 
                      ISNULL(Lookup66.UserDescription, OCC.ExtraDesc) AS ExtraDesc, dbo.ICD_ProcFile10.CIHIValue AS InterventionCIHIValue, 
                      dbo.ICD_ProcFile10.DisplayCode AS InterventionCode, dbo.ICD_ProcFile10.UserDescription AS InterventionCodeDesc, 
                      dbo.ICD_ProcFile10.ShortDescription AS InterventionCodeShortDesc, ISNULL(dbo.AB_Intervention.IntervDateIn, OCC.IntervDateIn) AS IntervDateIn, 
                      ISNULL(dbo.AB_Intervention.IntervDateOut, OCC.IntervDateOut) AS IntervDateOut, Lookup77.DisplayCode AS InterventionAttributeExtent, 
                      Lookup77.UserDescription AS IntervAttribExtentDesc, Lookup78.DisplayCode AS InterventionAttributeLocation, 
                      Lookup78.UserDescription AS IntervAttribLocationDesc, Lookup79.DisplayCode AS InterventionAttributeStatus, 
                      Lookup79.UserDescription AS IntervAttribStatusDesc, ISNULL(dbo.AB_Intervention.IntervDate, OCC.InterventionDate) AS InterventionDate, 
                      ISNULL(Lookup80.DisplayCode, OCC.InterventionLocation) AS InterventionLocation, ISNULL(Lookup80.UserDescription, OCC.InterventionLocationDesc) 
                      AS InterventionLocationDesc, dbo.AB_Intervention.IntervOccurrence AS InterventionOccurrence, ISNULL(Lookup81.DisplayCode, 
                      OCC.InterventionProviderNumber) AS InterventionProviderNumber, ISNULL(Lookup81.UserDescription, OCC.InterventionProviderNumberDesc) 
                      AS InterventionProviderNumberDesc, ISNULL(Lookup82.DisplayCode, OCC.InterventionProviderSpecialty) AS InterventionProviderSpecialty, 
                      ISNULL(Lookup82.UserDescription, OCC.InterventionProviderSpecialtyDesc) AS IntervProviderSpecialtyDesc, ISNULL(Lookup83.DisplayCode, 
                      OCC.InterventionSuffix) AS InterventionSuffix, ISNULL(Lookup83.UserDescription, OCC.InterventionSuffixDesc) AS InterventionSuffixDesc, 
                      ISNULL(dbo.AB_Intervention.IntervTimeIn, OCC.InterventionTimeIn) AS InterventionTimeIn, ISNULL(dbo.AB_Intervention.IntervTimeMinutes, 
                      OCC.InterventionTimeinMinutes) AS InterventionTimeinMinutes, ISNULL(dbo.AB_Intervention.IntervTimeOut, OCC.InterventionTimeOut) 
                      AS InterventionTimeOut, ISNULL(Lookup97.DisplayCode, OCC.OOHIndicator) AS OOHIndicator, ISNULL(Lookup97.UserDescription, 
                      OCC.OOHIndicatorDesc) AS OOHIndicatorDesc, ISNULL(Lookup98.DisplayCode, OCC.OOHInstitutionNumber) AS OOHInstitutionNumber, 
                      ISNULL(Lookup98.UserDescription, OCC.OOHInstitutionNumberDesc) AS OOHInstitutionNumberDesc, ISNULL(Lookup149.DisplayCode, 
                      OCC.TissueCode) AS TissueCode, ISNULL(Lookup149.UserDescription, OCC.TissueCodeDesc) AS TissueCodeDesc, ISNULL(Lookup154.DisplayCode, 
                      OCC.UnplannedReturntoOR) AS UnplannedReturntoOR, ISNULL(Lookup154.UserDescription, OCC.UnplannedReturntoORDesc) 
                      AS UnplannedReturntoORDesc, dbo.ICD_ProcFile10.ICD9 AS ICD9Equivalent, dbo.ICD_ProcFile10.ICD9cm AS ICD9cmEquivalent, 
                      dbo.AB_Intervention.AbstractID AS zzAbstractLink
FROM         dbo.AB_Intervention with (nolock) LEFT OUTER JOIN
                      dbo.ICD_ProcFile10 with (nolock) on dbo.AB_Intervention.IntervCode = dbo.ICD_ProcFile10.Code RIGHT OUTER JOIN
                      dbo.AB_Abstract with (nolock) on dbo.AB_Intervention.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
                      dbo.LU_AnaestTechnique Lookup20 with (nolock) on dbo.AB_Intervention.IntervAnaestTechnique = Lookup20.Code LEFT OUTER JOIN
                      dbo.LU_Provider Lookup21 with (nolock) on dbo.AB_Intervention.IntervAnaestID = Lookup21.Code LEFT OUTER JOIN
                      dbo.LU_IntervEUL Lookup62 with (nolock) on dbo.AB_Intervention.IntervEUL = Lookup62.Code LEFT OUTER JOIN
                      dbo.LU_IntervExtra Lookup66 with (nolock) on dbo.AB_Intervention.IntervExtra = Lookup66.Code LEFT OUTER JOIN
                      dbo.LU_IntervAttExtent Lookup77 with (nolock) on dbo.AB_Intervention.IntervAttribExtent = Lookup77.Code LEFT OUTER JOIN
                      dbo.LU_IntervAttLocation Lookup78 with (nolock) on dbo.AB_Intervention.IntervAttribLocation = Lookup78.Code LEFT OUTER JOIN
                      dbo.LU_IntervAttStatus Lookup79 with (nolock) on dbo.AB_Intervention.IntervAttribStatus = Lookup79.Code LEFT OUTER JOIN
                      dbo.LU_IntervLocation_AI Lookup80 with (nolock) on dbo.AB_Intervention.IntervLocation = Lookup80.Code LEFT OUTER JOIN
                      dbo.LU_Provider Lookup81 with (nolock) on dbo.AB_Intervention.IntervProviderNumber = Lookup81.Code LEFT OUTER JOIN
                      dbo.LU_ProviderSpecialty Lookup82 with (nolock) on dbo.AB_Intervention.IntervProviderService = Lookup82.Code LEFT OUTER JOIN
                      dbo.LU_IntervSuffix Lookup83 with (nolock) on dbo.AB_Intervention.IntervSuffix = Lookup83.Code LEFT OUTER JOIN
                      dbo.LU_YesBlankAlpha Lookup97 with (nolock) on dbo.AB_Intervention.IntervOOHIndicator = Lookup97.Code LEFT OUTER JOIN
                      dbo.LU_Institution_10 Lookup98 with (nolock) on dbo.AB_Intervention.IntervOOHInstitution = Lookup98.Code LEFT OUTER JOIN
                      dbo.LU_IntervTissue Lookup149 with (nolock) on dbo.AB_Intervention.IntervTissueCode = Lookup149.Code LEFT OUTER JOIN
                      dbo.LU_YesBlank Lookup154 with (nolock) on dbo.AB_Intervention.IntervUnplanReturn = Lookup154.Code INNER JOIN
                          (SELECT     Lookup20.DisplayCode AS AnestheticTechnique, Lookup20.UserDescription AS AnestheticTechniqueDesc, 
                                                   Lookup21.DisplayCode AS AnesthetistID, Lookup21.UserDescription AS AnesthetistIDDesc, Lookup62.DisplayCode AS EUL, 
                                                   Lookup62.UserDescription AS EULDesc, Lookup66.DisplayCode AS Extra, Lookup66.UserDescription AS ExtraDesc, 
                                                   dbo.AB_Intervention.IntervDateIn, dbo.AB_Intervention.IntervDateOut, dbo.AB_Intervention.IntervDate AS InterventionDate, 
                                                   Lookup80.DisplayCode AS InterventionLocation, Lookup80.UserDescription AS InterventionLocationDesc, 
                                                   dbo.AB_Intervention.IntervOccurrence AS InterventionOccurrence, Lookup81.DisplayCode AS InterventionProviderNumber, 
                                                   Lookup81.UserDescription AS InterventionProviderNumberDesc, Lookup82.DisplayCode AS InterventionProviderSpecialty, 
                                                   Lookup82.UserDescription AS InterventionProviderSpecialtyDesc, Lookup83.DisplayCode AS InterventionSuffix, 
                                                   Lookup83.UserDescription AS InterventionSuffixDesc, dbo.AB_Intervention.IntervTimeIn AS InterventionTimeIn, 
                                                   dbo.AB_Intervention.IntervTimeMinutes AS InterventionTimeinMinutes, dbo.AB_Intervention.IntervTimeOut AS InterventionTimeOut, 
                                                   Lookup97.DisplayCode AS OOHIndicator, Lookup97.UserDescription AS OOHIndicatorDesc, 
                                                   Lookup98.DisplayCode AS OOHInstitutionNumber, Lookup98.UserDescription AS OOHInstitutionNumberDesc, 
                                                   Lookup149.DisplayCode AS TissueCode, Lookup149.UserDescription AS TissueCodeDesc, 
                                                   Lookup154.DisplayCode AS UnplannedReturntoOR, Lookup154.UserDescription AS UnplannedReturntoORDesc, 
                                                   dbo.AB_Intervention.AbstractID
                            FROM          dbo.AB_Intervention with (nolock) RIGHT OUTER JOIN
                                                   dbo.AB_Abstract with (nolock) on dbo.AB_Intervention.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
                                                   dbo.LU_AnaestTechnique Lookup20 with (nolock) on dbo.AB_Intervention.IntervAnaestTechnique = Lookup20.Code LEFT OUTER JOIN
                                                   dbo.LU_Provider Lookup21 with (nolock) on dbo.AB_Intervention.IntervAnaestID = Lookup21.Code LEFT OUTER JOIN
                                                   dbo.LU_IntervEUL Lookup62 with (nolock) on dbo.AB_Intervention.IntervEUL = Lookup62.Code LEFT OUTER JOIN
                                                   dbo.LU_IntervExtra Lookup66 with (nolock) on dbo.AB_Intervention.IntervExtra = Lookup66.Code LEFT OUTER JOIN
                                                   dbo.LU_IntervLocation_AI Lookup80 with (nolock) on dbo.AB_Intervention.IntervLocation = Lookup80.Code LEFT OUTER JOIN
                                                   dbo.LU_Provider Lookup81 with (nolock) on dbo.AB_Intervention.IntervProviderNumber = Lookup81.Code LEFT OUTER JOIN
                                                   dbo.LU_ProviderSpecialty Lookup82 with (nolock) on dbo.AB_Intervention.IntervProviderService = Lookup82.Code LEFT OUTER JOIN
                                                   dbo.LU_IntervSuffix Lookup83 with (nolock) on dbo.AB_Intervention.IntervSuffix = Lookup83.Code LEFT OUTER JOIN
                                                   dbo.LU_YesBlankAlpha Lookup97 with (nolock) on dbo.AB_Intervention.IntervOOHIndicator = Lookup97.Code LEFT OUTER JOIN
                                                   dbo.LU_Institution_10 Lookup98 with (nolock) on dbo.AB_Intervention.IntervOOHInstitution = Lookup98.Code LEFT OUTER JOIN
                                                   dbo.LU_IntervTissue Lookup149 with (nolock) on dbo.AB_Intervention.IntervTissueCode = Lookup149.Code LEFT OUTER JOIN
                                                   dbo.LU_YesBlank Lookup154 with (nolock) on dbo.AB_Intervention.IntervUnplanReturn = Lookup154.Code
                            WHERE      (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5) AND (dbo.AB_Intervention.IntervOccurrence = 1)) OCC ON 
                      dbo.AB_Intervention.AbstractID = OCC.AbstractID
WHERE     (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5) AND (dbo.AB_Intervention.IntervOccurrence IS NOT NULL)




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Interventions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[I10_Amcare_Interventions_VR]
AS
SELECT     
    Lookup20.DisplayCode AS AnestheticTechnique, Lookup20.UserDescription AS AnestheticTechniqueDesc, Lookup21.DisplayCode AS AnesthetistID, 
    Lookup21.UserDescription AS AnesthetistIDDesc, Lookup62.DisplayCode AS EUL, Lookup62.UserDescription AS EULDesc, 
    Lookup66.DisplayCode AS Extra, Lookup66.UserDescription AS ExtraDesc, 
    dbo.ICD_ProcFile10.CIHIValue AS InterventionCIHIValue, 
    dbo.ICD_ProcFile10.DisplayCode AS InterventionCode, 
    dbo.ICD_ProcFile10.UserDescription AS InterventionCodeDesc, 
    dbo.ICD_ProcFile10.ShortDescription AS InterventionCodeShortDesc, 
    dbo.ICD_IntervClinicianTitle.CCI_ClinicianTitle as InterventionCodeClinicianTitle,
	IntervComments as InterventionComments,
    dbo.AB_Intervention.IntervDateIn, dbo.AB_Intervention.IntervDateOut, 
    Lookup77.DisplayCode AS InterventionAttributeExtent, Lookup77.UserDescription AS IntervAttributeExtentDesc, 
    Lookup78.DisplayCode AS InterventionAttributeLocation, Lookup78.UserDescription AS IntervAttributeLocationDesc, 
    Lookup79.DisplayCode AS InterventionAttributeStatus, Lookup79.UserDescription AS IntervAttributeStatusDesc, 
    dbo.AB_Intervention.IntervDate AS InterventionDate, dbo.ICD_ProcFile10.ICD9 AS IntervICD9Equivalent, 
    dbo.ICD_ProcFile10.ICD9cm AS IntervICD9cmEquivalent, 
    Lookup80.DisplayCode AS InterventionLocation, Lookup80.UserDescription AS InterventionLocationDesc, 
    dbo.AB_Intervention.IntervOccurrence AS InterventionOccurrence, 
    Lookup81.DisplayCode AS InterventionProviderNumber, Lookup81.UserDescription AS InterventionProviderNumberDesc, 
    Lookup82.DisplayCode AS InterventionProviderSpecialty, Lookup82.UserDescription AS IntervProviderSpecialtyDesc, 
    Lookup83.DisplayCode AS InterventionSuffix, Lookup83.UserDescription AS InterventionSuffixDesc, 

    dbo.AB_Intervention.IntervTimeIn AS InterventionTimeIn, 
    LU_IntervTimeInUnknown.DisplayCode AS InterventionTimeInUnknown, LU_IntervTimeInUnknown.UserDescription AS InterventionTimeInUnknownDesc, 
    dbo.AB_Intervention.IntervTimeMinutes AS InterventionTimeinMinutes, 
    dbo.AB_Intervention.IntervTimeOut AS InterventionTimeOut, 
    LU_IntervTimeOutUnknown.DisplayCode AS InterventionTimeOutUnknown, LU_IntervTimeOutUnknown.UserDescription AS InterventionTimeOutUnknownDesc, 
    
    Lookup97.DisplayCode AS OOHIndicator, Lookup97.UserDescription AS OOHIndicatorDesc, 
    Lookup98.DisplayCode AS OOHInstitutionNumber, Lookup98.UserDescription AS OOHInstitutionNumberDesc, 
    dbo.AB_Intervention.IntervTripNumber AS ORTripNumber, dbo.LU_YesNoSystem.DisplayCode AS SurgicalCode, 
    dbo.LU_YesNoSystem.UserDescription AS SurgicalCodeDesc, Lookup149.DisplayCode AS TissueCode, 
    Lookup149.UserDescription AS TissueCodeDesc, Lookup154.DisplayCode AS UnplannedReturntoOR, 
    Lookup154.UserDescription AS UnplannedReturntoORDesc, dbo.AB_Intervention.AbstractID AS zzAbstractLink
FROM           
    dbo.AB_Abstract with (nolock)  LEFT OUTER JOIN
    dbo.AB_Intervention with (nolock) on dbo.AB_Intervention.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
    dbo.ICD_ProcFile10 with (nolock) on dbo.ICD_ProcFile10.Code = dbo.AB_Intervention.IntervCode left OUTER JOIN
    dbo.ICD_IntervClinicianTitle with (nolock) on dbo.ICD_IntervClinicianTitle.CCICode = dbo.ICD_ProcFile10.CIHIValue left OUTER JOIN

    dbo.LU_YesNoSystem with (nolock) on dbo.LU_YesNoSystem.Code = dbo.ICD_ProcFile10.SurgicalCode left OUTER JOIN

    dbo.LU_AnaestTechnique AS Lookup20 with (nolock) on dbo.AB_Intervention.IntervAnaestTechnique = Lookup20.Code LEFT OUTER JOIN
    dbo.LU_Provider AS Lookup21 with (nolock) on dbo.AB_Intervention.IntervAnaestID = Lookup21.Code LEFT OUTER JOIN
    dbo.LU_IntervEUL AS Lookup62 with (nolock) on dbo.AB_Intervention.IntervEUL = Lookup62.Code LEFT OUTER JOIN
    dbo.LU_IntervExtra AS Lookup66 with (nolock) on dbo.AB_Intervention.IntervExtra = Lookup66.Code LEFT OUTER JOIN
    dbo.LU_IntervAttExtent AS Lookup77 with (nolock) on dbo.AB_Intervention.IntervAttribExtent = Lookup77.Code LEFT OUTER JOIN
    dbo.LU_IntervAttLocation AS Lookup78 with (nolock) on dbo.AB_Intervention.IntervAttribLocation = Lookup78.Code LEFT OUTER JOIN
    dbo.LU_IntervAttStatus AS Lookup79 with (nolock) on dbo.AB_Intervention.IntervAttribStatus = Lookup79.Code LEFT OUTER JOIN
    dbo.LU_IntervLocation_AI AS Lookup80 with (nolock) on dbo.AB_Intervention.IntervLocation = Lookup80.Code LEFT OUTER JOIN
    dbo.LU_Provider AS Lookup81 with (nolock) on dbo.AB_Intervention.IntervProviderNumber = Lookup81.Code LEFT OUTER JOIN
    dbo.LU_ProviderSpecialty AS Lookup82 with (nolock) on dbo.AB_Intervention.IntervProviderService = Lookup82.Code LEFT OUTER JOIN
    dbo.LU_IntervSuffix AS Lookup83 with (nolock) on dbo.AB_Intervention.IntervSuffix = Lookup83.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha AS Lookup97 with (nolock) on dbo.AB_Intervention.IntervOOHIndicator = Lookup97.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 AS Lookup98 with (nolock) on dbo.AB_Intervention.IntervOOHInstitution = Lookup98.Code LEFT OUTER JOIN
    dbo.LU_IntervTissue AS Lookup149 with (nolock) on dbo.AB_Intervention.IntervTissueCode = Lookup149.Code LEFT OUTER JOIN
    dbo.LU_YesBlank AS Lookup154 with (nolock) on dbo.AB_Intervention.IntervUnplanReturn = Lookup154.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS LU_IntervTimeInUnknown with (nolock) on dbo.AB_Intervention.IntervTimeInUnknown = LU_IntervTimeInUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS LU_IntervTimeOutUnknown with (nolock) on dbo.AB_Intervention.IntervTimeOutUnknown = LU_IntervTimeOutUnknown.Code 
WHERE     (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5) AND (dbo.AB_Intervention.IntervOccurrence IS NOT NULL)
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Level1_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_Amcare_Level1_VR]
AS
SELECT
    LU_AccessPrimaryHealthCareCode.DisplayCode as AccessPrimaryHealthCareCode,  LU_AccessPrimaryHealthCareCode.UserDescription as AccessPrimaryHealthCareCodeDesc,
    Lookup3.DisplayCode AS AdmitbyAmbulance, Lookup3.UserDescription AS AdmitbyAmbulanceDesc, 
    AmbulanceArrDate as AmbulanceArrivalDate, AmbulanceArrTime as AmbulanceArrivalTime, 
    LU_AmbulanceArrTimeUnknown.DisplayCode as AmbulanceArrivalTimeUnknown,  LU_AmbulanceArrTimeUnknown.UserDescription as AmbulanceArrivalTimeUnknownDesc,
    AmbulanceTranDate as AmbulanceTransferCareDate, AmbulanceTranTime as AmbulanceTransferCareTime,
    LU_AmbulanceTranTimeUnknown.DisplayCode as AmbulanceTransferCareTimeUnknown,  LU_AmbulanceTranTimeUnknown.UserDescription as AmbulanceTransferCareTimeUnknownDesc,
    LU_AmCareGroup.DisplayCode AS AmCareGroup, LU_AmCareGroup.UserDescription AS AmCareGroupDesc, 
    LU_AmCareTypeCode.DisplayCode AS AmcareTypeCode, LU_AmCareTypeCode.UserDescription AS AmcareTypeCodeDesc, 
    dbo.AB_Abstract.ArrivalDate, 
    dbo.AB_Abstract.ArrivalTime, 
    dbo.AB_Abstract.AssessmentDate, dbo.AB_Abstract.AssessmentTime, 
    Lookup159.DisplayCode AS AssessmentTimeUnknown, Lookup159.UserDescription AS AssessmentTimeUnknownDesc, 
    
    dbo.AB_Abstract.BatchNumber, 
    Lookup44.DisplayCode AS BatchPeriod, Lookup44.UserDescription AS BatchPeriodDesc, 
    dbo.AB_Abstract.BatchYear, 
    dbo.AB_Abstract.BirthDate, 
    LU_CDUFlag.Displaycode as ClinicalDecisionUnitFlag,    LU_CDUFlag.UserDescription as ClinicalDecisionUnitFlagDesc,
    CDUArrivalDate as ClinicalDecisionUnitDateIn, CDUArrivalTime as ClinicalDecisionUnitTimeIn,
    LU_CDUInTimeUnknown.Displaycode as ClinicalDecisionUnitTimeInUnknown,    LU_CDUInTimeUnknown.UserDescription as ClinicalDecisionUnitTimeInUnknownDesc,
    CDUOutDate as ClinicalDecisionUnitDateOut, CDUOutTime as ClinicalDecisionUnitTimeOut,
    LU_CDUOutTimeUnknown.Displaycode as ClinicalDecisionUnitTimeOutUnknown,    LU_CDUOutTimeUnknown.UserDescription as ClinicalDecisionUnitTimeOutUnknownDesc,

    dbo.AB_Abstract.ChartNumber, 
    Lookup46.DisplayCode AS CoderNumber, Lookup46.UserDescription AS CoderNumberDesc, 
    dbo.AB_Abstract.DateLeftER, 

    dbo.AB_Abstract.CIHIDateSent AS DateSentToCIHI, 
    Lookup60.DisplayCode AS DischargeDisposition, Lookup60.UserDescription AS DischargeDispositionDesc, 
    dbo.AB_Abstract.DischargeDate AS DispositionDate, 
    dbo.AB_Abstract.DischargeTime AS DispositionTime, 
    LUDischargeTimeUnknown.DisplayCode AS DispositionTimeUnknown, LUDischargeTimeUnknown.UserDescription AS DispositionTimeUnknownDesc, 
    --ED - 02289
    LU_EDVisitIndicator.DisplayCode AS EDVisitIndicator, LU_EDVisitIndicator.UserDescription AS EDVisitIndicatorDesc,
    
    ISNULL(dbo.AB_Abstract.LastName, '' '') + '', '' + ISNULL(dbo.AB_Abstract.FirstName, '''') + '' '' + ISNULL(dbo.AB_Abstract.MiddleName, '''') AS FullName, 
    Lookup69.DisplayCode AS Gender, Lookup69.UserDescription AS GenderDesc, 
    Lookup70.DisplayCode AS HCNProvince, Lookup70.UserDescription AS HCNProvinceDesc, 
    dbo.AB_Abstract.HCNVersion, dbo.AB_Abstract.HealthCareNumber, 
    Lookup74.DisplayCode AS InstitutionNumber, Lookup74.UserDescription AS InstitutionNumberDesc, 
    dbo.AB_Abstract.InterfaceDate, dbo.AB_Abstract.InterfaceTime, 
    LU_InterfaceInCoder.DisplayCode as InterfaceCoder, LU_InterfaceInCoder.UserDescription as InterfaceCoderDesc, 

    LU_Level1_Completed.DisplayCode AS IsAbstractCompletedLevel1, LU_Level1_Completed.UserDescription AS IsAbstractCompletedLevel1Desc, 
    LU_Level1_Correction.DisplayCode AS IsAbstractCorrectedLevel1, LU_Level1_Correction.UserDescription AS IsAbstractCorrectedLevel1Desc, 
    Lookup85.DisplayCode AS IsAbstractDeleted,   Lookup85.UserDescription AS IsAbstractDeletedDesc, 
    LU_Level1_Submission.DisplayCode AS IsAbstractSubmittedLevel1, LU_Level1_Submission.UserDescription AS IsAbstractSubmittedLevel1Desc, 
    LU_Level1_Validation.DisplayCode AS IsAbstractValidatedLevel1, LU_Level1_Validation.UserDescription AS IsAbstractValidatedLevel1Desc, 
	LU_IsCustomValidated.DisplayCode AS IsCustomValidated, LU_IsCustomValidated.UserDescription AS IsCustomValidatedDesc, 

    Lookup93.DisplayCode AS MISCode, Lookup93.UserDescription AS MISCodeDesc, 
    
	AB_NACRS.NonPhysicianAssessmentDate, AB_NACRS.NonPhysicianAssessmentTime, 
	LU_NonPhysicianAssessmentTimeUnknown.DisplayCode AS NonPhysicianAssessmentTimeUnknown, LU_NonPhysicianAssessmentTimeUnknown.UserDescription AS NonPhysicianAssessmentTimeUnknownDesc,
	LU_NonPhysicianNumber.DisplayCode AS NonPhysicianNumber, LU_NonPhysicianNumber.UserDescription AS NonPhysicianNumberDesc,
	LU_NonPhysicianService.DisplayCode AS NonPhysicianService, LU_NonPhysicianService.UserDescription AS NonPhysicianServiceDesc,
   
    dbo.AB_Abstract.PostalCode, 
    dbo.GetPostalDescription(isnull(dbo.AB_Abstract.PostalCode, ''''), dbo.AB_Abstract.AdmitDate) AS PostalCodeDesc, -- ED - 01682
    dbo.AB_Abstract.EncounterNumber AS RegistrationNumber, dbo.AB_Abstract.EncounterSequence AS RegistrationSequenceNumber, 
    dbo.AB_Abstract.AdmitDate AS RegistrationVisitDate, dbo.AB_Abstract.AdmitTime AS RegistrationVisitTime, 
    Lookup138.DisplayCode AS ResidenceCode, Lookup138.UserDescription AS ResidenceCodeDesc, 
    Lookup140.DisplayCode AS ResponsiblityForPayment, Lookup140.UserDescription AS ResponsiblityForPaymentDesc, 
    Lookup153.DisplayCode AS SchedEDVisit, Lookup153.UserDescription AS SchedEDVisitDesc, 

	LU_SpecialistNumber.DisplayCode AS SpecialistNumber, LU_SpecialistNumber.UserDescription AS SpecialistNumberDesc,
	AB_NACRS.SpecialistRequestDate, 
	LU_SpecialistService.DisplayCode AS SpecialistRequestService, LU_SpecialistService.UserDescription AS SpecialistRequestServiceDesc,
	AB_NACRS.SpecialistRequestTime, 
	LU_SpecialistRequestTimeUnknown.DisplayCode AS SpecialistRequestTimeUnknown, LU_SpecialistRequestTimeUnknown.UserDescription AS SpecialistRequestTimeUnknownDesc,
    --ED - 02289
    LU_StatusAfterTriage.DisplayCode as StatusAfterTriage, LU_StatusAfterTriage.UserDescription as StatusAfterTriageDesc,
	
    SubmissionLevel as SubmissionLevelCode, 
    AbstractNumber as SubmissionRecordID,
    dbo.AB_Abstract.TimeLeftER, 
    LU_TimeLeftERUnknown.DisplayCode AS TimeLeftERUnknown, LU_TimeLeftERUnknown.UserDescription AS TimeLeftERUnknownDEsc, 
    dbo.AB_Abstract.TriageDate, 
    Lookup151.DisplayCode AS TriageLevel, Lookup151.UserDescription AS TriageLevelDesc, 
    dbo.AB_Abstract.TriageTime, 
    LU_TriageTimeUnknown.DisplayCode AS TriageTimeUnknown, LU_TriageTimeUnknown.UserDescription AS TriageTimeUnknownDesc, 
    dbo.AB_Abstract.AbstractID AS zzAbstractLink, dbo.AB_Abstract.VolumeID AS zzVolumeLink
FROM         
    dbo.AB_Abstract with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile LU_TriageTimeUnknown with (nolock) on dbo.AB_Abstract.TriageTimeUnknown = LU_TriageTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_TimeLeftERUnknown with (nolock) on dbo.AB_Abstract.TimeLeftERUnknown = LU_TimeLeftERUnknown.Code LEFT OUTER JOIN
    dbo.LU_AdmitAmbulance Lookup3 with (nolock) on dbo.AB_Abstract.AdmitAmbulance = Lookup3.Code LEFT OUTER JOIN
    dbo.LU_BatchPeriod Lookup44 with (nolock) on dbo.AB_Abstract.BatchPeriod = Lookup44.Code LEFT OUTER JOIN
    dbo.U_Users Lookup46 with (nolock) on dbo.AB_Abstract.CoderNumber = Lookup46.Code LEFT OUTER JOIN
    dbo.LU_DispositionCode_A Lookup60 with (nolock) on dbo.AB_Abstract.DispositionCode = Lookup60.Code LEFT OUTER JOIN
    dbo.LU_Gender_I Lookup69 with (nolock) on dbo.AB_Abstract.Gender = Lookup69.Code LEFT OUTER JOIN
    dbo.LU_HCNProvince Lookup70 with (nolock) on dbo.AB_Abstract.HCNProvince = Lookup70.Code LEFT OUTER JOIN
    dbo.H_InstitutionProfile Lookup74 with (nolock) on dbo.AB_Abstract.InstitutionNumber = Lookup74.Code LEFT OUTER JOIN
    dbo.LU_DeleteStatus Lookup85 with (nolock) on dbo.AB_Abstract.IsDeleted = Lookup85.Code LEFT OUTER JOIN
    dbo.LU_MISCode Lookup93 with (nolock) on dbo.AB_Abstract.MISCode = Lookup93.Code LEFT OUTER JOIN
    
    dbo.LU_ResidenceCode Lookup138 with (nolock) on dbo.AB_Abstract.ResidenceCode = Lookup138.Code LEFT OUTER JOIN
    dbo.LU_RespPayment Lookup140 with (nolock) on dbo.AB_Abstract.ResponsiblePayment = Lookup140.Code LEFT OUTER JOIN
    dbo.LU_TriageLevel Lookup151 with (nolock) on dbo.AB_Abstract.TriageLevel = Lookup151.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup153 with (nolock) on dbo.AB_Abstract.SchedEDVisit = Lookup153.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup159 with (nolock) on dbo.AB_Abstract.AssessmentTimeUnknown = Lookup159.Code AND Lookup159.LookupID = 1 LEFT OUTER JOIN
    dbo.LU_CodeFile LUDischargeTimeUnknown with (nolock) on dbo.AB_Abstract.DischargeTimeUnknown = LUDischargeTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_AmbulanceArrTimeUnknown with (nolock) on dbo.AB_Abstract.AmbulanceArrTimeUnknown = LU_AmbulanceArrTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_AmbulanceTranTimeUnknown with (nolock) on dbo.AB_Abstract.AmbulanceTranTimeUnknown = LU_AmbulanceTranTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_AccessPrimaryHealthCareCode with (nolock) on dbo.AB_Abstract.AccessCareCode = dbo.LU_AccessPrimaryHealthCareCode.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_CDUFlag with (nolock) on dbo.AB_Abstract.CDUFlag = LU_CDUFlag.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CDUInTimeUnknown with (nolock) on dbo.AB_Abstract.CDUInTimeUnknown = LU_CDUInTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CDUOutTimeUnknown with (nolock) on dbo.AB_Abstract.CDUOutTimeUnknown = LU_CDUOutTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_CIHICorrect LU_Level1_Correction with (nolock) on dbo.AB_Abstract.IsCorrectLevel1 = LU_Level1_Correction.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_Level1_Submission with (nolock) on dbo.AB_Abstract.IsSubmitLevel1 = LU_Level1_Submission.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus LU_Level1_Validation with (nolock) on dbo.AB_Abstract.IsValidLevel1 = LU_Level1_Validation.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus LU_IsCustomValidated with (nolock) on dbo.AB_Abstract.IsCustomValidated = LU_IsCustomValidated.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus LU_Level1_Completed with (nolock) on dbo.AB_Abstract.IsCompleteLevel1 = LU_Level1_Completed.Code 
	left join dbo.AB_NACRS with (nolock) on AB_Abstract.AbstractID = AB_NACRS.AbstractID
	left join dbo.LU_Provider LU_SpecialistNumber with (nolock) on AB_NACRS.SpecialistNumber = LU_SpecialistNumber.Code
	left join dbo.LU_ProviderSpecialty LU_SpecialistService with (nolock) on AB_NACRS.SpecialistService = LU_SpecialistService.Code
	left join dbo.LU_CodeFile LU_SpecialistRequestTimeUnknown with (nolock) on AB_NACRS.SpecialistRequestTimeUnknown = LU_SpecialistRequestTimeUnknown.Code
	left join dbo.LU_Provider LU_NonPhysicianNumber with (nolock) on AB_NACRS.NonPhysicianNumber = LU_NonPhysicianNumber.Code
	left join dbo.LU_ProviderSpecialty LU_NonPhysicianService with (nolock) on AB_NACRS.NonPhysicianService = LU_NonPhysicianService.Code
	left join dbo.LU_CodeFile LU_NonPhysicianAssessmentTimeUnknown with (nolock) on AB_NACRS.NonPhysicianAssessmentTimeUnknown = LU_NonPhysicianAssessmentTimeUnknown.Code
	
	left join dbo.LU_CodeFile LU_AmCareTypeCode with (nolock) on AB_NACRS.AmCareTypeCode = LU_AmCareTypeCode.Code
	left join dbo.LU_CodeFile LU_AmCareGroup with (nolock) on AB_NACRS.AmCareGroup = LU_AmCareGroup.Code
    left join U_Users LU_InterfaceInCoder with (nolock) on AB_Abstract.InterfaceCoder = LU_InterfaceInCoder.code

    --ED - 02298
    left join dbo.LU_YesNoSystem LU_EDVisitIndicator with (nolock) on dbo.AB_NACRS.EDVisitIndicator = LU_EDVisitIndicator.Code
    left join dbo.LU_StatusAfterTriage with (nolock) on dbo.AB_NACRS.StatusAfterTriage = LU_StatusAfterTriage.Code
     
WHERE  ((Lookup93.CIHIValue like ''7_310%'' and Admitdate < ''2010/04/01'') or Lookup93.AmcareGroup = ''ED'')
    and (dbo.AB_Abstract.CareType = 5)
    and ICDType = ''T''
       
--WHERE  ((AdmitDate >= ''2009/04/01'' and Lookup74.CIHIValue not like ''5%'' and Lookup74.LevelCode in (1, 2))
--        or 
--        (AdmitDate >= ''2009/11/01'' and Lookup74.CIHIValue like ''5%'' and Lookup74.LevelCode in (4, 5)
--            and ((Lookup93.CIHIValue like ''7_310%'' and Admitdate < ''2010/04/01'') or Lookup93.AmcareGroup = ''ED''))
--       )




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_MIS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'





CREATE VIEW [dbo].[I10_Amcare_MIS_VR]
AS
SELECT     dbo.AB_MIS.DirectCost AS DirectCosts, dbo.AB_MIS.IndirectCost AS IndirectCosts, dbo.LU_MISCode.DisplayCode AS MISCode, 
                      dbo.LU_MISCode.UserDescription AS MISCodeDesc, dbo.AB_MIS.MISOccurrence, dbo.AB_MIS.SupplyCost AS SupplyCosts, 
                      dbo.AB_MIS.AbstractID AS zzAbstractLink
FROM         dbo.AB_MIS with (nolock) RIGHT OUTER JOIN
                      dbo.AB_Abstract with (nolock) ON dbo.AB_MIS.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
                      dbo.LU_MISCode with (nolock) ON dbo.AB_MIS.MISCode = dbo.LU_MISCode.Code
WHERE     (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5) AND (dbo.AB_MIS.MISOccurrence IS NOT NULL)







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_PresentingComplaint]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE view [dbo].[I10_Amcare_PresentingComplaint]
as
select
	AbstractID as zzAbstractLink,
	Occurrence as PresentingComplaintOccurrence,
	LU_PresentingComplaint.DisplayCode as PresentingComplaint,
	LU_PresentingComplaint.UserDescription as PresentingComplaintDesc
from dbo.AB_PresentingComplaints with (nolock)
	left join LU_CodeFile LU_PresentingComplaint with (nolock) on PresentingComplaint = LU_PresentingComplaint.Code



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Profile_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[I10_Amcare_Profile_VR]
AS
SELECT
    dbo.AB_ReproductiveCare.PrevPreTermDelivery AS [#ofPreviousPreTermDeliveries], 
    dbo.AB_ReproductiveCare.PrevSpontAbortions AS [#ofPrevSpontaneousAbortions], 
    dbo.AB_ReproductiveCare.PrevTermDelivery AS [#ofPreviousTermDeliveries], 
    --ED - 01910
    LU_AccessPrimaryHealthCareCode.DisplayCode as AccessPrimaryHealthCareCode,  LU_AccessPrimaryHealthCareCode.UserDescription as AccessPrimaryHealthCareCodeDesc,
    AmbulanceArrDate as AmbulanceArrivalDate, AmbulanceArrTime as AmbulanceArrivalTime, 
    LU_AmbulanceArrTimeUnknown.DisplayCode as AmbulanceArrivalTimeUnknown,  LU_AmbulanceArrTimeUnknown.UserDescription as AmbulanceArrivalTimeUnknownDesc,
    AmbulanceTranDate as AmbulanceTransferCareDate, AmbulanceTranTime as AmbulanceTransferCareTime,
    LU_AmbulanceTranTimeUnknown.DisplayCode as AmbulanceTransferCareTimeUnknown,  LU_AmbulanceTranTimeUnknown.UserDescription as AmbulanceTransferCareTimeUnknownDesc,

    dbo.AB_ReproductiveCare.PrevInduceAbortions AS [#ofPrevTherapeuticAbortions], Lookup1.DisplayCode AS AWOL, 
    Lookup1.UserDescription AS AWOLDesc, dbo.AB_ReproductiveCare.AbortionDate AS AbortDate, dbo.AB_Abstract.AbstractNumber, 
    dbo.LU_AbstractOverflow.DisplayCode AS AbstractOverflow, dbo.LU_AbstractOverflow.UserDescription AS AbstractOverflowDesc, 
    dbo.AB_Abstract.InjuryActivityDescription AS ActivityDescription, Lookup2.DisplayCode AS ActivityWhenInjured, 
    Lookup2.UserDescription AS ActivityWhenInjuredDesc, dbo.AB_Abstract.AcuteLOS AS ActueLOS, Lookup3.DisplayCode AS AdmitbyAmbulance, 
    Lookup3.UserDescription AS AdmitbyAmbulanceDesc, dbo.AB_Abstract.AdmitCategory, 
    dbo.AB_Abstract.AdmittingDiagnosis AS AdmitDiagnosis, 
    LU_AdmitNurse.DisplayCode AS AdmitNursingArea, LU_AdmitNurse.UserDescription AS AdmitNursingAreaDesc, 
    dbo.AB_DeathInformation.DeathAfterAdmit AS AfterAdmit, 
    Lookup4.DisplayCode AS AgeCode, Lookup4.UserDescription AS AgeCodeDesc, dbo.AB_Abstract.AgeGroup, dbo.AB_Abstract.AgeNumber, 
    Lookup5.DisplayCode AS Albumin, Lookup5.UserDescription AS AlbuminDesc, Lookup6.DisplayCode AS AlbuminCrossMatched, 
    Lookup6.UserDescription AS AlbuminCrossMatchedDesc, Lookup7.DisplayCode AS AlbuminTyped, Lookup7.UserDescription AS AlbuminTypedDesc, 
    dbo.AB_Blood.AlbuminUnits, dbo.AB_Abstract.ALCLOS, 
    dbo.AB_Abstract.AmbulanceReportNumber, 
    --ED-02091 & ED - 02130
    isnull(LU_AmCareGroup.DisplayCode, LU_AmCareGroup_FromMISCode.DisplayCode) AS AmCareGroup, 
    isnull(LU_AmCareGroup.UserDescription, LU_AmCareGroup_FromMISCode.UserDescription) AS AmCareGroupDesc, 
    --PR - 03010
    LU_AmCareType.DisplayCode AS AmcareCareType, LU_AmCareType.UserDescription AS AmcareCareTypeDesc, 
    --ED-02091  & ED - 02130
    isnull(LU_AmCareTypeCode.DisplayCode, LU_AmCareTypeCode_FromMISCode.DisplayCode) AS AmcareTypeCode, 
    isnull(LU_AmCareTypeCode.UserDescription, LU_AmCareTypeCode_FromMISCode.UserDescription) AS AmcareTypeCodeDesc, 
    
    dbo.AB_Ancillary.AncillaryField13 AS Ancil13, 
    dbo.AB_Ancillary.AncillaryField14 AS Ancil14, dbo.AB_Ancillary.AncillaryField15 AS Ancil15, dbo.AB_Ancillary.AncillaryField16 AS Ancil16, 
    dbo.AB_Ancillary.AncillaryField17 AS Ancil17, Lookup8.DisplayCode AS AncillaryField1, Lookup8.UserDescription AS AncillaryField1Desc, 
    Lookup9.DisplayCode AS AncillaryField10, Lookup9.UserDescription AS AncillaryField10Desc, Lookup10.DisplayCode AS AncillaryField11, 
    Lookup10.UserDescription AS AncillaryField11Desc, Lookup11.DisplayCode AS AncillaryField12, Lookup11.UserDescription AS AncillaryField12Desc, 
    Lookup12.DisplayCode AS AncillaryField2, Lookup12.UserDescription AS AncillaryField2Desc, Lookup13.DisplayCode AS AncillaryField3, 
    Lookup13.UserDescription AS AncillaryField3Desc, Lookup14.DisplayCode AS AncillaryField4, Lookup14.UserDescription AS AncillaryField4Desc, 
    Lookup15.DisplayCode AS AncillaryField5, Lookup15.UserDescription AS AncillaryField5Desc, Lookup16.DisplayCode AS AncillaryField6, 
    Lookup16.UserDescription AS AncillaryField6Desc, Lookup17.DisplayCode AS AncillaryField7, Lookup17.UserDescription AS AncillaryField7Desc, 
    Lookup18.DisplayCode AS AncillaryField8, Lookup18.UserDescription AS AncillaryField8Desc, Lookup19.DisplayCode AS AncillaryField9, 
    Lookup19.UserDescription AS AncillaryField9Desc, dbo.AB_Abstract.ArrivalDate, Lookup22.DisplayCode AS ArrivalMode, 
    Lookup22.UserDescription AS ArrivalModeDesc, dbo.AB_Abstract.ArrivalTime, dbo.AB_Abstract.ArrivalTriageDifference AS ArrivaltoTriageTime, 
    dbo.AB_Abstract.AssessmentDate, dbo.AB_Abstract.AssessmentTime, Lookup159.DisplayCode AS AssessmentTimeUnknown, 
    Lookup159.UserDescription AS AssessmentTimeUnknownDesc, LU_AttendingPhysician.DisplayCode AS AttendingPhysician, 
    LU_AttendingPhysician.UserDescription AS AttendingPhysicianDesc, Lookup23.DisplayCode AS AutoTransfusion, 
    Lookup23.UserDescription AS AutoTransfusionDesc, Lookup24.DisplayCode AS AutopsyPerformed, 
    Lookup24.UserDescription AS AutopsyPerformedDesc, Lookup25.DisplayCode AS BasicOption1, Lookup25.UserDescription AS BasicOption1Desc, 
    Lookup26.DisplayCode AS BasicOption10, Lookup26.UserDescription AS BasicOption10Desc, Lookup27.DisplayCode AS BasicOption11, 
    Lookup27.UserDescription AS BasicOption11Desc, Lookup28.DisplayCode AS BasicOption12, Lookup28.UserDescription AS BasicOption12Desc, 
    Lookup29.DisplayCode AS BasicOption13, Lookup29.UserDescription AS BasicOption13Desc, Lookup30.DisplayCode AS BasicOption14, 
    Lookup30.UserDescription AS BasicOption14Desc, Lookup31.DisplayCode AS BasicOption15, Lookup31.UserDescription AS BasicOption15Desc, 
    Lookup32.DisplayCode AS BasicOption16, Lookup32.UserDescription AS BasicOption16Desc, Lookup33.DisplayCode AS BasicOption17, 
    Lookup33.UserDescription AS BasicOption17Desc, Lookup34.DisplayCode AS BasicOption18, Lookup34.UserDescription AS BasicOption18Desc, 
    Lookup35.DisplayCode AS BasicOption19, Lookup35.UserDescription AS BasicOption19Desc, Lookup36.DisplayCode AS BasicOption2, 
    Lookup36.UserDescription AS BasicOption2Desc, Lookup37.DisplayCode AS BasicOption3, Lookup37.UserDescription AS BasicOption3Desc, 
    Lookup38.DisplayCode AS BasicOption4, Lookup38.UserDescription AS BasicOption4Desc, Lookup39.DisplayCode AS BasicOption5, 
    Lookup39.UserDescription AS BasicOption5Desc, Lookup40.DisplayCode AS BasicOption6, Lookup40.UserDescription AS BasicOption6Desc, 
    Lookup41.DisplayCode AS BasicOption7, Lookup41.UserDescription AS BasicOption7Desc, Lookup42.DisplayCode AS BasicOption8, 
    Lookup42.UserDescription AS BasicOption8Desc, Lookup43.DisplayCode AS BasicOption9, Lookup43.UserDescription AS BasicOption9Desc, 
    dbo.AB_Abstract.BatchNumber, Lookup44.DisplayCode AS BatchPeriod, Lookup44.UserDescription AS BatchPeriodDesc, 
    --PR - 06087
    BatchPeriod_BC = (case when left(Lookup74.CIHIValue, 1) <> ''9'' then null
                           when Lookup44.DisplayCode is not null then Lookup44.DisplayCode 
                           when AdmitDate is null then null
                           else (select top 1 DisplayCode from LU_BatchPeriod where AdmitDate between CIHIDateFrom and CIHIDateTo)
                      end),
    dbo.AB_Abstract.BatchYear,     dbo.AB_Abstract.BirthDate, 
	
	LU_AntithrombinIII.DisplayCode AS Blood_AntithrombinIII, LU_AntithrombinIII.UserDescription AS Blood_AntithrombinIIIDesc,
	LU_C1Inhibitor.DisplayCode AS Blood_C1Inhibitor, LU_C1Inhibitor.UserDescription AS Blood_C1InhibitorDesc,
	LU_CryoprecipitatePlasma.DisplayCode AS Blood_CryoprecipitatePlasma, LU_CryoprecipitatePlasma.UserDescription AS Blood_CryoprecipitatePlasmaDesc,
	LU_CryosupernatantPlasma.DisplayCode AS Blood_CryosupernatantPlasma, LU_CryosupernatantPlasma.UserDescription AS Blood_CryosupernatantPlasmaDesc,
	LU_FEIBA.DisplayCode AS Blood_FEIBA, LU_FEIBA.UserDescription AS Blood_FEIBADesc,
	LU_Fibrinogen.DisplayCode AS Blood_Fibrinogen, LU_Fibrinogen.UserDescription AS Blood_FibrinogenDesc,
	LU_IVIG_SCIG.DisplayCode AS Blood_IVIG_SCIG, LU_IVIG_SCIG.UserDescription AS Blood_IVIG_SCIGDesc,
	LU_PCC.DisplayCode AS Blood_PCC, LU_PCC.UserDescription AS Blood_PCCDesc,
	LU_ProteinC_OtherFactors.DisplayCode AS Blood_ProteinC_OtherFactors, LU_ProteinC_OtherFactors.UserDescription AS Blood_ProteinC_OtherFactorsDesc,

	dbo.AB_ReproductiveCare.BreastFeeding, 
    --ED - 01910
    LU_CDUFlag.Displaycode as ClinicalDecisionUnitFlag,    LU_CDUFlag.UserDescription as ClinicalDecisionUnitFlagDesc,
    CDUArrivalDate as ClinicalDecisionUnitDateIn, CDUArrivalTime as ClinicalDecisionUnitTimeIn,
    LU_CDUInTimeUnknown.Displaycode as ClinicalDecisionUnitTimeInUnknown,    LU_CDUInTimeUnknown.UserDescription as ClinicalDecisionUnitTimeInUnknownDesc,
    CDUOutDate as ClinicalDecisionUnitDateOut, CDUOutTime as ClinicalDecisionUnitTimeOut,
    LU_CDUOutTimeUnknown.Displaycode as ClinicalDecisionUnitTimeOutUnknown,    LU_CDUOutTimeUnknown.UserDescription as ClinicalDecisionUnitTimeOutUnknownDesc,

    Lookup45.DisplayCode AS ChangeinLegalStatus, 
    Lookup45.UserDescription AS ChangeinLegalStatusDesc, dbo.AB_Abstract.ChartNumber, dbo.AB_Abstract.ChiefComplaint, 
    Lookup46.DisplayCode AS CoderNumber, Lookup46.UserDescription AS CoderNumberDesc, LUCompleteRecord.DisplayCode AS CompleteRecord, 
    LUCompleteRecord.UserDescription AS CompleteRecordDesc, LUComplication.DisplayCode AS Complication, 
    LUComplication.UserDescription AS ComplicationDesc, Lookup47.DisplayCode AS Complication1, Lookup47.UserDescription AS Complication1Desc, 
    Lookup48.DisplayCode AS Complication2, Lookup48.UserDescription AS Complication2Desc, Lookup49.DisplayCode AS Complication3, 
    Lookup49.UserDescription AS Complication3Desc, Lookup50.DisplayCode AS ContactMode, Lookup50.UserDescription AS ContactModeDesc, 
    Lookup51.DisplayCode AS CoronerCase, Lookup51.UserDescription AS CoronerCaseDesc, Lookup52.DisplayCode AS DataEntryCoder, 
    Lookup52.UserDescription AS DataEntryCoderDesc, dbo.AB_Abstract.DateLeftER, dbo.AB_ReproductiveCare.LastMensesDate AS DateofLastMenses, 
    dbo.AB_Abstract.DateReadyDischarge AS DateReadyforDisch, 

    dbo.AB_Abstract.CIHIDateSent AS DateSentToCIHI, 
    --NP - 00125
    dbo.AB_Abstract.CIHIDateSentLevel1 AS DateSentToCIHILevel1, 
    --ED - 02102
    dbo.AB_Abstract.CIHIDateSentLevel1 AS DateSentToCIHILevel2, 
    --2.x-0282
    dbo.AB_Abstract.CIHIDateSentLevel1 AS DateSentToCIHILite, 

    Lookup53.DisplayCode AS DeathInER,
    Lookup53.UserDescription AS DeathInERDesc, Lookup54.DisplayCode AS DeathOnArrival, Lookup54.UserDescription AS DeathOnArrivalDesc, 
    dbo.AB_Abstract.DecisionAdmitDifference, dbo.AB_Abstract.DecisionAdmitDate AS DecisiontoAdmitDate, 
    dbo.AB_Abstract.DecisionAdmitTime AS DecisiontoAdmitTime, Lookup158.DisplayCode AS DecisionAdmitTimeUnknown, 
    Lookup158.UserDescription AS DecisionAdmitTimeUnknownDesc, dbo.AB_ReproductiveCare.DeliveryDate, dbo.AB_ReproductiveCare.DeliveryTime, 
    Lookup58.DisplayCode AS DiedDuringIntervention, Lookup58.UserDescription AS DiedDuringInterventionDesc, 
    LU_DischargeNurse.DisplayCode AS DischNursingArea, LU_DischargeNurse.UserDescription AS DischNursingAreaDesc, 
    Lookup59.DisplayCode AS DischPlanning, 
    Lookup59.UserDescription AS DischPlanningDesc, dbo.AB_Abstract.DischargeAge, Lookup60.DisplayCode AS DischargeDisposition, 
    Lookup60.UserDescription AS DischargeDispositionDesc, dbo.AB_Abstract.DischargeDate AS DispositionDate, 
    dbo.AB_Abstract.DischargeTime AS DispositionTime, LUDischargeTimeUnknown.DisplayCode AS DispositionTimeUnknown, 
    LUDischargeTimeUnknown.UserDescription AS DispositionTimeUnknownDesc, Lookup61.DisplayCode AS ECTTreatment, 
    Lookup61.UserDescription AS ECTTreatmentDesc, Lookup64.DisplayCode AS Education, Lookup64.UserDescription AS EducationDesc, 
    --ED - 02289
    LU_EDVisitIndicator.DisplayCode AS EDVisitIndicator, LU_EDVisitIndicator.UserDescription AS EDVisitIndicatorDesc,
    
    Lookup65.DisplayCode AS Employment, Lookup65.UserDescription AS EmploymentDesc, dbo.AB_Abstract.EntryCode, 
    dbo.AB_Abstract.EstimatedDischargeDate AS EstimateDischDate, dbo.AB_Abstract.ExitCode, Lookup67.DisplayCode AS FamilyPhysicianFlag, 
    Lookup67.UserDescription AS FamilyPhysicianFlagDesc, Lookup68.DisplayCode AS FinancialSupport, 
    Lookup68.UserDescription AS FinancialSupportDesc, dbo.AB_Abstract.FinishDate, dbo.AB_Abstract.FinishTime, dbo.AB_Abstract.FirstName, 
    ISNULL(dbo.AB_Abstract.LastName, '' '') + '', '' + ISNULL(dbo.AB_Abstract.FirstName, '''') + '' '' + ISNULL(dbo.AB_Abstract.MiddleName, '''') AS FullName, 
    FixedChartNumber,
    Lookup69.DisplayCode AS Gender, Lookup69.UserDescription AS GenderDesc, dbo.AB_ReproductiveCare.GestationalAge AS GestationalAgeinweeks, 
    Lookup157.DisplayCode AS GlasgowScale, Lookup157.UserDescription AS GlasgowScaleDesc, 
    dbo.AB_DeathInformation.DeathGreaterTenPO AS GreaterTenPO, Lookup70.DisplayCode AS HCNProvince, 
    Lookup70.UserDescription AS HCNProvinceDesc, dbo.AB_Abstract.HCNVersion, dbo.AB_Abstract.HealthCareNumber, 
    LU_Hospital.DisplayCode AS Hospital, LU_Hospital.UserDescription AS HospitalDesc, 
    dbo.AB_Abstract.HospitalAccountRecord,
    LUHelmetIndicator.DisplayCode AS HelmetIndicator, 
    LUHelmetIndicator.UserDescription AS HelmetIndicatorDesc, dbo.AB_DeathInformation.DeathInSCU AS InSCU, Lookup71.DisplayCode AS InitialOR, 
    Lookup71.UserDescription AS InitialORDesc, dbo.AB_Abstract.InjuryDate, Lookup72.DisplayCode AS Injury, Lookup72.UserDescription AS InjuryDesc, 
    dbo.AB_Abstract.InputDate, dbo.AB_Abstract.InputTime, 
	
	Lookup73.DisplayCode AS InstitutionFrom, Lookup73.UserDescription AS InstitutionFromDesc, 
	LU_InstitutionFrom_Type.DisplayCode AS InstitutionFromType, LU_InstitutionFrom_Type.UserDescription AS InstitutionFromTypeDesc, 
    Lookup73.InstCareType AS InstFromCareType, Lookup73.HospitalType AS InstFromHospType, 
	
	Lookup74.DisplayCode AS InstitutionNumber, Lookup74.UserDescription AS InstitutionNumberDesc, 
	
	Lookup75.DisplayCode AS InstitutionTo, Lookup75.UserDescription AS InstitutionToDesc, 
	LU_InstitutionTo_Type.DisplayCode AS InstitutionToType, LU_InstitutionTo_Type.UserDescription AS InstitutionToTypeDesc, 
    Lookup75.InstCareType AS InstToCareType, Lookup75.HospitalType AS InstToHospType, dbo.AB_Abstract.InterfaceDate, 
    
	dbo.AB_Abstract.InterfaceTime, 

    Lookup83.DisplayCode AS IsAbstractCompleted, Lookup83.UserDescription AS IsAbstractCompletedDesc, 
    --NP - 00125
    LU_Level1_Completed.DisplayCode AS IsAbstractCompletedLevel1, LU_Level1_Completed.UserDescription AS IsAbstractCompletedLevel1Desc, 
    --ED - 02102
    LU_Level1_Completed.DisplayCode AS IsAbstractCompletedLevel2, LU_Level1_Completed.UserDescription AS IsAbstractCompletedLevel2Desc, 
    --2.x-0282
    LU_Level1_Completed.DisplayCode AS IsAbstractCompletedLite, LU_Level1_Completed.UserDescription AS IsAbstractCompletedLiteDesc, 

    Lookup84.DisplayCode AS IsAbstractCorrected, Lookup84.UserDescription AS IsAbstractCorrectedDesc, 
    --NP - 00125
    LU_Level1_Correction.DisplayCode AS IsAbstractCorrectedLevel1, LU_Level1_Correction.UserDescription AS IsAbstractCorrectedLevel1Desc, 
    --ED - 02102
    LU_Level1_Correction.DisplayCode AS IsAbstractCorrectedLevel2, LU_Level1_Correction.UserDescription AS IsAbstractCorrectedLevel2Desc, 
    --2.x-0282
    LU_Level1_Correction.DisplayCode AS IsAbstractCorrectedLite, LU_Level1_Correction.UserDescription AS IsAbstractCorrectedLiteDesc, 

    Lookup85.DisplayCode AS IsAbstractDeleted,   Lookup85.UserDescription AS IsAbstractDeletedDesc, 

    Lookup86.DisplayCode AS IsAbstractSubmitted, Lookup86.UserDescription AS IsAbstractSubmittedDesc,
    --NP - 00125 
    LU_Level1_Submission.DisplayCode AS IsAbstractSubmittedLevel1, LU_Level1_Submission.UserDescription AS IsAbstractSubmittedLevel1Desc, 
    --ED - 02102 
    LU_Level1_Submission.DisplayCode AS IsAbstractSubmittedLevel2, LU_Level1_Submission.UserDescription AS IsAbstractSubmittedLevel2Desc, 
    --2.x-0282
    LU_Level1_Submission.DisplayCode AS IsAbstractSubmittedLite, LU_Level1_Submission.UserDescription AS IsAbstractSubmittedLiteDesc, 

    Lookup87.DisplayCode AS IsAbstractValidated, Lookup87.UserDescription AS IsAbstractValidatedDesc, 
    --NP - 00125 
    LU_Level1_Validation.DisplayCode AS IsAbstractValidatedLevel1, LU_Level1_Validation.UserDescription AS IsAbstractValidatedLevel1Desc, 
    --ED - 02102 
    LU_Level1_Validation.DisplayCode AS IsAbstractValidatedLevel2, LU_Level1_Validation.UserDescription AS IsAbstractValidatedLevel2Desc, 
    --2.x-0282
    LU_Level1_Validation.DisplayCode AS IsAbstractValidatedLite, LU_Level1_Validation.UserDescription AS IsAbstractValidatedLiteDesc, 

    Lookup88.DisplayCode AS IsBirthdateEstimated,     Lookup88.UserDescription AS IsBirthdateEstimatedDesc, 
	LU_IsCustomValidated.DisplayCode AS IsCustomValidated, LU_IsCustomValidated.UserDescription AS IsCustomValidatedDesc, 
	
	dbo.AB_Abstract.LOSDays, dbo.AB_Abstract.LOSTotal AS LOSTime, 
    dbo.AB_Abstract.LOSTime AS LOSTimeinHours, dbo.AB_Abstract.LOSMinutes AS LOSTotalMinutes, Lookup89.DisplayCode AS [Language], 
    Lookup89.UserDescription AS LanguageDesc, dbo.AB_Abstract.LastName, dbo.AB_DeathInformation.DeathLessTwoPO AS LessTwoPO, 
    Lookup90.DisplayCode AS LivingArrangement, Lookup90.UserDescription AS LivingArrangementDesc, Lookup91.DisplayCode AS LocationofInjury, 
    Lookup91.UserDescription AS LocationofInjuryDesc, Lookup93.DisplayCode AS MISCode, Lookup93.UserDescription AS MISCodeDesc, 
    dbo.AB_Abstract.MaidenName, Lookup94.DisplayCode AS MaritalStatus, Lookup94.UserDescription AS MaritalStatusDesc, 

	LU_MentalLegalStatusUponArrivalED.DisplayCode as MentalHealth_LegalStatusUponArrivaltoED, 
	LU_MentalLegalStatusUponArrivalED.UserDescription as MentalHealth_LegalStatusUponArrivaltoEDDesc,
	--LU_MentalLegalStatusAdmission.DisplayCode as MentalHealth_LegalStatusAtAdmission, 
	--LU_MentalLegalStatusAdmission.UserDescription as MentalHealth_LegalStatusAtAdmissionDesc,
	LU_MentalTypeRestraint_1.DisplayCode as MentalHealth_TypeOfRestraint_01,
	LU_MentalTypeRestraint_1.UserDescription as MentalHealth_TypeOfRestraint_01Desc,
	LU_MentalTypeRestraint_2.DisplayCode as MentalHealth_TypeOfRestraint_02,
	LU_MentalTypeRestraint_2.UserDescription as MentalHealth_TypeOfRestraint_02Desc,
	LU_MentalTypeRestraint_3.DisplayCode as MentalHealth_TypeOfRestraint_03,
	LU_MentalTypeRestraint_3.UserDescription as MentalHealth_TypeOfRestraint_03Desc,
	LU_MentalTypeRestraint_4.DisplayCode as MentalHealth_TypeOfRestraint_04,
	LU_MentalTypeRestraint_4.UserDescription as MentalHealth_TypeOfRestraint_04Desc,
	LU_MentalFrequencyRestraintUse_1.DisplayCode as MentalHealth_FrequencyOfRestraint_01,
	LU_MentalFrequencyRestraintUse_1.UserDescription as MentalHealth_FrequencyOfRestraint_01Desc,
	LU_MentalFrequencyRestraintUse_2.DisplayCode as MentalHealth_FrequencyOfRestraint_02,
	LU_MentalFrequencyRestraintUse_2.UserDescription as MentalHealth_FrequencyOfRestraint_02Desc,
	LU_MentalFrequencyRestraintUse_3.DisplayCode as MentalHealth_FrequencyOfRestraint_03,
	LU_MentalFrequencyRestraintUse_3.UserDescription as MentalHealth_FrequencyOfRestraint_03Desc,
	LU_MentalFrequencyRestraintUse_4.DisplayCode as MentalHealth_FrequencyOfRestraint_04,
	LU_MentalFrequencyRestraintUse_4.UserDescription as MentalHealth_FrequencyOfRestraint_04Desc,


    Lookup95.DisplayCode AS MethodofAdmission, Lookup95.UserDescription AS MethodofAdmissionDesc, dbo.AB_Abstract.MiddleName, 
    dbo.AB_Abstract.NewbornChart, dbo.AB_Abstract.NewbornDischargeDate AS NewbornDischDate, 
    dbo.AB_Abstract.NextSchedVisitDate AS NextScheduledVisitDate, dbo.AB_Abstract.NextSchedVisitTime AS NextScheduledVisitTime, 
    --ED-02091 
	AB_NACRS.NonPhysicianAssessmentDate, AB_NACRS.NonPhysicianAssessmentTime, 
	LU_NonPhysicianAssessmentTimeUnknown.DisplayCode AS NonPhysicianAssessmentTimeUnknown, LU_NonPhysicianAssessmentTimeUnknown.UserDescription AS NonPhysicianAssessmentTimeUnknownDesc,
	LU_NonPhysicianNumber.DisplayCode AS NonPhysicianNumber, LU_NonPhysicianNumber.UserDescription AS NonPhysicianNumberDesc,
	LU_NonPhysicianService.DisplayCode AS NonPhysicianService, LU_NonPhysicianService.UserDescription AS NonPhysicianServiceDesc,
    
    dbo.AB_MentalHealth.MentalNumberECT AS NumberofECT, dbo.AB_Abstract.NurseAssessDate AS NursingAssessmentDate, 
    dbo.AB_Abstract.NurseAssessTime AS NursingAssessmentTime, Lookup98.DisplayCode AS Occupation, 
    Lookup98.UserDescription AS OccupationDesc, Lookup99.DisplayCode AS OtherMedicalDeath, Lookup99.UserDescription AS OtherMedicalDeathDesc, 
    Lookup100.DisplayCode AS OtherBlood, Lookup100.UserDescription AS OtherBloodDesc, Lookup101.DisplayCode AS OtherBloodCrossMatched, 
    Lookup101.UserDescription AS OtherBloodCrossMatchedDesc, Lookup102.DisplayCode AS OtherBloodTyped, 
    Lookup102.UserDescription AS OtherBloodTypedDesc, dbo.AB_Blood.OtherBloodUnits, Lookup148.DisplayCode AS PCTASIndicator, 
    Lookup148.UserDescription AS PCTASIndicatorDesc, dbo.AB_Abstract.PhysicianEstimatedLOS AS PhysicianEstLOS, 
    Lookup103.DisplayCode AS Plasma, Lookup103.UserDescription AS PlasmaDesc, Lookup104.DisplayCode AS PlasmaCrossMatched, 
    Lookup104.UserDescription AS PlasmaCrossMatchedDesc, Lookup105.DisplayCode AS PlasmaTyped, 
    Lookup105.UserDescription AS PlasmaTypedDesc, dbo.AB_Blood.PlasmaUnits, Lookup106.DisplayCode AS Platelets, 
    Lookup106.UserDescription AS PlateletsDesc, Lookup107.DisplayCode AS PlateletsCrossMatched, 
    Lookup107.UserDescription AS PlateletsCrossMatchedDesc, Lookup108.DisplayCode AS PlateletsTyped, 
    Lookup108.UserDescription AS PlateletsTypedDesc, dbo.AB_Blood.PlateletsUnits, dbo.AB_Abstract.PostalCode, 

    -- ED - 01682
    dbo.GetPostalDescription(isnull(dbo.AB_Abstract.PostalCode, ''''), dbo.AB_Abstract.AdmitDate) AS PostalCodeDesc, -- ED - 01682

    dbo.AB_Abstract.PostOpDays, dbo.AB_Abstract.PreOpDays, Lookup110.DisplayCode AS PreamditWorkUp, Lookup110.UserDescription AS PreamditWorkUpDesc, 
    Lookup111.DisplayCode AS Pregnancy, Lookup111.UserDescription AS PregnancyDesc, dbo.AB_ReproductiveCare.PrevLiveBirths AS PrevLiveBirth, 
    Lookup112.DisplayCode AS PreviousPsychiartricAdmissions, Lookup112.UserDescription AS PreviousPsychiartricAdmDesc, 
    Lookup113.DisplayCode AS Program, Lookup113.UserDescription AS ProgramDesc, Lookup118.DisplayCode AS ProvinceNumber, 
    Lookup118.UserDescription AS ProvinceNumberDesc, LUReasonForVisit.DisplayCode AS ReasonForVisit, 
    LUReasonForVisit.UserDescription AS ReasonForVisitDesc, dbo.AB_Abstract.ReAdmitCode, 
	--PR - 04577
	LU_ReciprocalBillingStatus.DisplayCode AS ReciprocalBillingStatus, LU_ReciprocalBillingStatus.UserDescription AS ReciprocalBillingStatusDesc,

    Lookup132.DisplayCode AS RedBloodCell, 
    Lookup132.UserDescription AS RedBloodCellDesc, Lookup133.DisplayCode AS RedBloodCellCrossMatched, 
    Lookup133.UserDescription AS RedBloodCellCrossMatchedDesc, Lookup134.DisplayCode AS RedBloodCellTyped, 
    Lookup134.UserDescription AS RedBloodCellTypedDesc, dbo.AB_Blood.RedCellUnits AS RedBloodCellUnits, dbo.AB_Abstract.ReferralDate, 
    Lookup135.DisplayCode AS ReferredFrom, Lookup135.UserDescription AS ReferredFromDesc, Lookup136.DisplayCode AS ReferredTo, 
    Lookup136.UserDescription AS ReferredToDesc, LU_RefProvider.DisplayCode AS ReferringProvider, 
    LU_RefProvider.UserDescription AS ReferringProviderDesc, dbo.AB_Abstract.RegisterNumber, 
    dbo.AB_Abstract.EncounterNumber AS RegistrationNumber, dbo.AB_Abstract.EncounterSequence AS RegistrationSequenceNumber, 
    dbo.AB_Abstract.AdmitDate AS RegistrationVisitDate, dbo.AB_Abstract.AdmitTime AS RegistrationVisitTime, 
    dbo.AB_ReproductiveCare.ReprodComments AS ReproductiveCareComments, dbo.AB_Abstract.Reserved AS ReserveField, 
    Lookup138.DisplayCode AS ResidenceCode, Lookup138.UserDescription AS ResidenceCodeDesc, 
    LUResidenceProvince.DisplayCode AS ResidenceProvince, LUResidenceProvince.UserDescription AS ResidenceProvinceDesc, 
    LUResidenceRegion.DisplayCode AS ResidenceRegion, LUResidenceRegion.UserDescription AS ResidenceRegionDesc, 
    Lookup139.DisplayCode AS ResidenceType, Lookup139.UserDescription AS ResidenceTypeDesc, 
    Lookup140.DisplayCode AS ResponsiblityForPayment, Lookup140.UserDescription AS ResponsiblityForPaymentDesc, 
    Lookup153.DisplayCode AS SchedEDVisit, Lookup153.UserDescription AS SchedEDVisitDesc, Lookup156.DisplayCode AS SeatbeltIndicator, 
    Lookup156.UserDescription AS SeatbeltIndicatorDesc, dbo.AB_Abstract.SecondChartRegNumber AS SecondChartRegisterNumber, 
    Lookup141.DisplayCode AS SecretVIPPatient, Lookup141.UserDescription AS SecretVIPPatientDesc, Lookup142.DisplayCode AS SiteNumber, 
    Lookup142.UserDescription AS SiteNumberDesc, Lookup143.DisplayCode AS SocialService, Lookup143.UserDescription AS SocialServiceDesc, 
    Lookup144.DisplayCode AS SourceofReferral, Lookup144.UserDescription AS SourceofReferralDesc, 
	--ED-02091
	LU_SpecialistNumber.DisplayCode AS SpecialistNumber, LU_SpecialistNumber.UserDescription AS SpecialistNumberDesc,
	AB_NACRS.SpecialistRequestDate, 
	LU_SpecialistService.DisplayCode AS SpecialistRequestService, LU_SpecialistService.UserDescription AS SpecialistRequestServiceDesc,
	AB_NACRS.SpecialistRequestTime, 
	LU_SpecialistRequestTimeUnknown.DisplayCode AS SpecialistRequestTimeUnknown, LU_SpecialistRequestTimeUnknown.UserDescription AS SpecialistRequestTimeUnknownDesc,
    
    LU_StakeholderType.DisplayCode AS StakeholderType, LU_StakeholderType.UserDescription AS StakeholderTypeDesc, 
    --ED - 02289
    LU_StatusAfterTriage.DisplayCode as StatusAfterTriage, LU_StatusAfterTriage.UserDescription as StatusAfterTriageDesc,
    
    Lookup145.DisplayCode AS Sterilization, Lookup145.UserDescription AS SterilizationDesc, 

    SubmissionLevel as SubmissionLevelCode, --ED - 01910
    AbstractNumber as SubmissionRecordID,

    Lookup146.DisplayCode AS SubsequentOR, 
    Lookup146.UserDescription AS SubsequentORDesc, Lookup147.DisplayCode AS Suicide, Lookup147.UserDescription AS SuicideDesc, 
    LUSurgicalCase.DisplayCode AS SurgicalCase, LUSurgicalCase.UserDescription AS SurgicalCaseDesc, dbo.AB_Abstract.TimeLeftER, 
    LU_TimeLeftERUnknown.DisplayCode AS TimeLeftERUnknown, LU_TimeLeftERUnknown.UserDescription AS TimeLeftERUnknownDEsc, 
    dbo.AB_Abstract.TransferOverloadDate, dbo.AB_Abstract.TransferOverloadTime, 
    dbo.AB_Abstract.TransferOverloadDifference AS TransferOverloadTimeDifference, Lookup149.DisplayCode AS TransfusionGiven, 
    Lookup149.UserDescription AS TransfusionGivenDesc, Lookup150.DisplayCode AS Trauma, Lookup150.UserDescription AS TraumaDesc, 
    dbo.AB_Abstract.TriageDate, Lookup151.DisplayCode AS TriageLevel, Lookup151.UserDescription AS TriageLevelDesc, dbo.AB_Abstract.TriageTime, 
    LU_TriageTimeUnknown.DisplayCode AS TriageTimeUnknown, LU_TriageTimeUnknown.UserDescription AS TriageTimeUnknownDesc, 
    Lookup152.DisplayCode AS TSICoder, Lookup152.UserDescription AS TSICoderDesc, dbo.AB_Abstract.TSIDate, dbo.AB_Abstract.TSITime, 
    dbo.AB_DeathInformation.DeathTwoTenPO AS TwoTenPO, dbo.AB_Abstract.UniqiueLifetimeID AS ULI, 
    dbo.AB_Abstract.UnplanReAdmit AS UnplannedReadmit, Lookup154.DisplayCode AS VisitStatus, Lookup154.UserDescription AS VisitStatusDesc, 
    Lookup155.DisplayCode AS VisitType, Lookup155.UserDescription AS VisitTypeDesc, 
	dbo.AB_Abstract.UniversalEpisodeIdentifier,
	dbo.AB_Abstract.WaitTimeER AS WaitTimeinER, 
    dbo.AB_Abstract.WaitAssessmentDifference AS WaittoAssessmentinMinutes, dbo.AB_Abstract.NurseAssessDiff AS WaittoNursingAssessmentDiff, 
    dbo.AB_Abstract.Weight, 
    dbo.AB_Abstract.AbstractID AS zzAbstractLink, 
    dbo.AB_Abstract.RegionalPatientID as zzRegionalPatientID, 
    dbo.AB_Abstract.VolumeID AS zzVolumeLink
FROM         
    dbo.AB_Abstract with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile LU_TriageTimeUnknown with (nolock) on dbo.AB_Abstract.TriageTimeUnknown = LU_TriageTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_Provider LU_RefProvider with (nolock) on dbo.AB_Abstract.RefPhysician = LU_RefProvider.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_TimeLeftERUnknown with (nolock) on dbo.AB_Abstract.TimeLeftERUnknown = LU_TimeLeftERUnknown.Code LEFT OUTER JOIN
    dbo.LU_Provider LU_AttendingPhysician with (nolock) on dbo.AB_Abstract.AttendingPhysician = LU_AttendingPhysician.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_StakeholderType with (nolock) on dbo.AB_Abstract.StakeHolder = LU_StakeholderType.Code LEFT OUTER JOIN
    dbo.H_HospitalProfile LU_Hospital with (nolock) on dbo.AB_Abstract.HospitalID = LU_Hospital.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LUCompleteRecord with (nolock) on dbo.AB_Abstract.CompleteRecord = LUCompleteRecord.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LUHelmetIndicator with (nolock) on dbo.AB_Abstract.HelmetIndicator = LUHelmetIndicator.Code LEFT OUTER JOIN
    dbo.LU_InjuryActivity Lookup2 with (nolock) on dbo.AB_Abstract.InjuryActivity = Lookup2.Code LEFT OUTER JOIN
    dbo.LU_AdmitAmbulance Lookup3 with (nolock) on dbo.AB_Abstract.AdmitAmbulance = Lookup3.Code LEFT OUTER JOIN
    dbo.LU_AgeCode Lookup4 with (nolock) on dbo.AB_Abstract.AgeCode = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_ArrivalMode Lookup22 with (nolock) on dbo.AB_Abstract.ArrivalMode = Lookup22.Code LEFT OUTER JOIN
    dbo.LU_BatchPeriod Lookup44 with (nolock) on dbo.AB_Abstract.BatchPeriod = Lookup44.Code LEFT OUTER JOIN
    dbo.U_Users Lookup46 with (nolock) on dbo.AB_Abstract.CoderNumber = Lookup46.Code LEFT OUTER JOIN
    dbo.LU_ContactMode Lookup50 with (nolock) on dbo.AB_Abstract.ContactMode = Lookup50.Code LEFT OUTER JOIN
    dbo.U_Users Lookup52 with (nolock) on dbo.AB_Abstract.DataEntryCoder = Lookup52.Code LEFT OUTER JOIN
    dbo.LU_TherDischPlan Lookup59 with (nolock) on dbo.AB_Abstract.DischargePlanning = Lookup59.Code LEFT OUTER JOIN
    dbo.LU_DispositionCode_A Lookup60 with (nolock) on dbo.AB_Abstract.DispositionCode = Lookup60.Code LEFT OUTER JOIN
    dbo.LU_Education Lookup64 with (nolock) on dbo.AB_Abstract.EducationLevel = Lookup64.Code LEFT OUTER JOIN
    dbo.LU_FamilyPhysician Lookup67 with (nolock) on dbo.AB_Abstract.FamilyPhysician = Lookup67.Code LEFT OUTER JOIN
    dbo.LU_Gender_I Lookup69 with (nolock) on dbo.AB_Abstract.Gender = Lookup69.Code LEFT OUTER JOIN
    dbo.LU_HCNProvince Lookup70 with (nolock) on dbo.AB_Abstract.HCNProvince = Lookup70.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup72 with (nolock) on dbo.AB_Abstract.Injury = Lookup72.Code LEFT OUTER JOIN
    
	dbo.LU_Institution_10 Lookup73 with (nolock) on dbo.AB_Abstract.InstitutionFrom = Lookup73.Code LEFT OUTER JOIN
	LU_Institution_TypeCode LU_InstitutionFrom_Type with (nolock) on dbo.AB_Abstract.InstitutionFromType = LU_InstitutionFrom_Type.Code LEFT OUTER JOIN
    dbo.H_InstitutionProfile Lookup74 with (nolock) on dbo.AB_Abstract.InstitutionNumber = Lookup74.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 Lookup75 with (nolock) on dbo.AB_Abstract.InstitutionTo = Lookup75.Code LEFT OUTER JOIN
	LU_Institution_TypeCode LU_InstitutionTo_Type with (nolock) on dbo.AB_Abstract.InstitutionToType = LU_InstitutionTo_Type.Code LEFT OUTER JOIN

    dbo.LU_AbstractStatus Lookup83 with (nolock) on dbo.AB_Abstract.IsCompleted = Lookup83.Code LEFT OUTER JOIN
    dbo.LU_CIHICorrect Lookup84 with (nolock) on dbo.AB_Abstract.IsCorrected = Lookup84.Code LEFT OUTER JOIN
    dbo.LU_DeleteStatus Lookup85 with (nolock) on dbo.AB_Abstract.IsDeleted = Lookup85.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem Lookup86 with (nolock) on dbo.AB_Abstract.IsSubmited = Lookup86.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus Lookup87 with (nolock) on dbo.AB_Abstract.IsValidated = Lookup87.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus LU_IsCustomValidated with (nolock) on dbo.AB_Abstract.IsCustomValidated = LU_IsCustomValidated.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup88 with (nolock) on dbo.AB_Abstract.BirthDateEstimated = Lookup88.Code LEFT OUTER JOIN
    dbo.LU_Language Lookup89 with (nolock) on dbo.AB_Abstract.LanguageCode = Lookup89.Code LEFT OUTER JOIN
    dbo.LU_LivingArrangement Lookup90 with (nolock) on dbo.AB_Abstract.LivingArrangement = Lookup90.Code LEFT OUTER JOIN
    dbo.LU_InjuryLocation Lookup91 with (nolock) on dbo.AB_Abstract.InjuryLocation = Lookup91.Code LEFT OUTER JOIN
    dbo.LU_MISCode Lookup93 with (nolock) on dbo.AB_Abstract.MISCode = Lookup93.Code LEFT OUTER JOIN
    
    --PR - 03012
    dbo.LU_CodeFile LU_AmCareType with (nolock) on Lookup93.AmCareType = LU_AmCareType.Code LEFT OUTER JOIN
    
    dbo.LU_MaritalStatus Lookup94 with (nolock) on dbo.AB_Abstract.MaritalStatus = Lookup94.Code LEFT OUTER JOIN
    dbo.LU_Occupation Lookup98 with (nolock) on dbo.AB_Abstract.Occupation = Lookup98.Code LEFT OUTER JOIN
    dbo.LU_TherPreAdmitWorkUp Lookup110 with (nolock) on dbo.AB_Abstract.PreAdmitWorkUp = Lookup110.Code LEFT OUTER JOIN
    dbo.LU_Program Lookup113 with (nolock) on dbo.AB_Abstract.Program = Lookup113.Code LEFT OUTER JOIN
    dbo.LU_Province Lookup118 with (nolock) on dbo.AB_Abstract.ProvinceNumber = Lookup118.Code LEFT OUTER JOIN
    dbo.LU_Referral Lookup135 with (nolock) on dbo.AB_Abstract.ReferredFrom = Lookup135.Code LEFT OUTER JOIN
    dbo.LU_Referral Lookup136 with (nolock) on dbo.AB_Abstract.ReferredTo = Lookup136.Code LEFT OUTER JOIN
    dbo.LU_ResidenceCode Lookup138 with (nolock) on dbo.AB_Abstract.ResidenceCode = Lookup138.Code LEFT OUTER JOIN
    dbo.LU_Region LUResidenceRegion with (nolock) on Lookup138.RegionCode = LUResidenceRegion.Code LEFT OUTER JOIN
    dbo.LU_Province LUResidenceProvince with (nolock) on Lookup138.ProvinceCode = LUResidenceProvince.Code LEFT OUTER JOIN
    dbo.LU_ResidenceType Lookup139 with (nolock) on dbo.AB_Abstract.ResidenceType = Lookup139.Code LEFT OUTER JOIN
    dbo.LU_RespPayment Lookup140 with (nolock) on dbo.AB_Abstract.ResponsiblePayment = Lookup140.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup141 with (nolock) on dbo.AB_Abstract.Secret = Lookup141.Code LEFT OUTER JOIN
    dbo.LU_Site Lookup142 with (nolock) on dbo.AB_Abstract.SiteNumber = Lookup142.Code LEFT OUTER JOIN
    dbo.LU_TherSocialService Lookup143 with (nolock) on dbo.AB_Abstract.SocialService = Lookup143.Code LEFT OUTER JOIN
    dbo.LU_TriageLevel Lookup151 with (nolock) on dbo.AB_Abstract.TriageLevel = Lookup151.Code LEFT OUTER JOIN
    dbo.U_Users Lookup152 with (nolock) on dbo.AB_Abstract.TSICoder = Lookup152.Code LEFT OUTER JOIN
    dbo.LU_VisitType Lookup154 with (nolock) on dbo.AB_Abstract.VisitStatus = Lookup154.Code LEFT OUTER JOIN
    dbo.LU_VisitType_10 Lookup155 with (nolock) on dbo.AB_Abstract.VisitType = Lookup155.Code LEFT OUTER JOIN
    dbo.AB_Ancillary with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Ancillary.AbstractID LEFT OUTER JOIN
    dbo.LU_Ancillary1 Lookup8 with (nolock) on dbo.AB_Ancillary.AncillaryField1 = Lookup8.Code LEFT OUTER JOIN
    dbo.LU_Ancillary10 Lookup9 with (nolock) on dbo.AB_Ancillary.AncillaryField10 = Lookup9.Code LEFT OUTER JOIN
    dbo.LU_Ancillary11 Lookup10 with (nolock) on dbo.AB_Ancillary.AncillaryField11 = Lookup10.Code LEFT OUTER JOIN
    dbo.LU_Ancillary12 Lookup11 with (nolock) on dbo.AB_Ancillary.AncillaryField12 = Lookup11.Code LEFT OUTER JOIN
    dbo.LU_Ancillary2 Lookup12 with (nolock) on dbo.AB_Ancillary.AncillaryField2 = Lookup12.Code LEFT OUTER JOIN
    dbo.LU_Ancillary3 Lookup13 with (nolock) on dbo.AB_Ancillary.AncillaryField3 = Lookup13.Code LEFT OUTER JOIN
    dbo.LU_Ancillary4 Lookup14 with (nolock) on dbo.AB_Ancillary.AncillaryField4 = Lookup14.Code LEFT OUTER JOIN
    dbo.LU_Ancillary5 Lookup15 with (nolock) on dbo.AB_Ancillary.AncillaryField5 = Lookup15.Code LEFT OUTER JOIN
    dbo.LU_Ancillary6 Lookup16 with (nolock) on dbo.AB_Ancillary.AncillaryField6 = Lookup16.Code LEFT OUTER JOIN
    dbo.LU_Ancillary7 Lookup17 with (nolock) on dbo.AB_Ancillary.AncillaryField7 = Lookup17.Code LEFT OUTER JOIN
    dbo.LU_Ancillary8 Lookup18 with (nolock) on dbo.AB_Ancillary.AncillaryField8 = Lookup18.Code LEFT OUTER JOIN
    dbo.LU_Ancillary9 Lookup19 with (nolock) on dbo.AB_Ancillary.AncillaryField9 = Lookup19.Code LEFT OUTER JOIN
    dbo.AB_BasicOption with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_BasicOption.AbstractID LEFT OUTER JOIN
    dbo.LU_BasicOption1 Lookup25 with (nolock) on dbo.AB_BasicOption.BasicOption1 = Lookup25.Code LEFT OUTER JOIN
    dbo.LU_BasicOption10 Lookup26 with (nolock) on dbo.AB_BasicOption.BasicOption10 = Lookup26.Code LEFT OUTER JOIN
    dbo.LU_BasicOption11 Lookup27 with (nolock) on dbo.AB_BasicOption.BasicOption11 = Lookup27.Code LEFT OUTER JOIN
    dbo.LU_BasicOption12 Lookup28 with (nolock) on dbo.AB_BasicOption.BasicOption12 = Lookup28.Code LEFT OUTER JOIN
    dbo.LU_BasicOption13 Lookup29 with (nolock) on dbo.AB_BasicOption.BasicOption13 = Lookup29.Code LEFT OUTER JOIN
    dbo.LU_BasicOption14 Lookup30 with (nolock) on dbo.AB_BasicOption.BasicOption14 = Lookup30.Code LEFT OUTER JOIN
    dbo.LU_BasicOption15 Lookup31 with (nolock) on dbo.AB_BasicOption.BasicOption15 = Lookup31.Code LEFT OUTER JOIN
    dbo.LU_BasicOption16 Lookup32 with (nolock) on dbo.AB_BasicOption.BasicOption16 = Lookup32.Code LEFT OUTER JOIN
    dbo.LU_BasicOption17 Lookup33 with (nolock) on dbo.AB_BasicOption.BasicOption17 = Lookup33.Code LEFT OUTER JOIN
    dbo.LU_BasicOption18 Lookup34 with (nolock) on dbo.AB_BasicOption.BasicOption18 = Lookup34.Code LEFT OUTER JOIN
    dbo.LU_BasicOption19 Lookup35 with (nolock) on dbo.AB_BasicOption.BasicOption19 = Lookup35.Code LEFT OUTER JOIN
    dbo.LU_BasicOption2 Lookup36 with (nolock) on dbo.AB_BasicOption.BasicOption2 = Lookup36.Code LEFT OUTER JOIN
    dbo.LU_BasicOption3 Lookup37 with (nolock) on dbo.AB_BasicOption.BasicOption3 = Lookup37.Code LEFT OUTER JOIN
    dbo.LU_BasicOption4 Lookup38 with (nolock) on dbo.AB_BasicOption.BasicOption4 = Lookup38.Code LEFT OUTER JOIN
    dbo.LU_BasicOption5 Lookup39 with (nolock) on dbo.AB_BasicOption.BasicOption5 = Lookup39.Code LEFT OUTER JOIN
    dbo.LU_BasicOption6 Lookup40 with (nolock) on dbo.AB_BasicOption.BasicOption6 = Lookup40.Code LEFT OUTER JOIN
    dbo.LU_BasicOption7 Lookup41 with (nolock) on dbo.AB_BasicOption.BasicOption7 = Lookup41.Code LEFT OUTER JOIN
    dbo.LU_BasicOption8 Lookup42 with (nolock) on dbo.AB_BasicOption.BasicOption8 = Lookup42.Code LEFT OUTER JOIN
    dbo.LU_BasicOption9 Lookup43 with (nolock) on dbo.AB_BasicOption.BasicOption9 = Lookup43.Code LEFT OUTER JOIN
    dbo.AB_Blood with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Blood.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup5 with (nolock) on dbo.AB_Blood.Albumin = Lookup5.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup6 with (nolock) on dbo.AB_Blood.AlbuminXMatch = Lookup6.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup7 with (nolock) on dbo.AB_Blood.AlbuminTyped = Lookup7.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup23 with (nolock) on dbo.AB_Blood.AutoTransfusion = Lookup23.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup100 with (nolock) on dbo.AB_Blood.OtherBlood = Lookup100.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup101 with (nolock) on dbo.AB_Blood.OtherBloodXMatch = Lookup101.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup102 with (nolock) on dbo.AB_Blood.OtherBloodTyped = Lookup102.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup103 with (nolock) on dbo.AB_Blood.Plasma = Lookup103.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup104 with (nolock) on dbo.AB_Blood.PlasmaXMatch = Lookup104.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup105 with (nolock) on dbo.AB_Blood.PlasmaTyped = Lookup105.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup106 with (nolock) on dbo.AB_Blood.Platelets = Lookup106.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup107 with (nolock) on dbo.AB_Blood.PlateletsXMatch = Lookup107.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup108 with (nolock) on dbo.AB_Blood.PlateletsTyped = Lookup108.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup132 with (nolock) on dbo.AB_Blood.RedBloodCell = Lookup132.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup133 with (nolock) on dbo.AB_Blood.RedCellXMatch = Lookup133.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup134 with (nolock) on dbo.AB_Blood.RedCellTyped = Lookup134.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup149 with (nolock) on dbo.AB_Blood.TransfusionIndicator = Lookup149.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_AntithrombinIII with (nolock) on dbo.AB_Blood.AntithrombinIII = LU_AntithrombinIII.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_C1Inhibitor with (nolock) on dbo.AB_Blood.C1Inhibitor = LU_C1Inhibitor.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_CryoprecipitatePlasma with (nolock) on dbo.AB_Blood.CryoprecipitatePlasma = LU_CryoprecipitatePlasma.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_CryosupernatantPlasma with (nolock) on dbo.AB_Blood.CryosupernatantPlasma = LU_CryosupernatantPlasma.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_FEIBA with (nolock) on dbo.AB_Blood.FEIBA = LU_FEIBA.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_Fibrinogen with (nolock) on dbo.AB_Blood.Fibrinogen = LU_Fibrinogen.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_IVIG_SCIG with (nolock) on dbo.AB_Blood.IVIG_SCIG = LU_IVIG_SCIG.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_PCC with (nolock) on dbo.AB_Blood.PCC = LU_PCC.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_ProteinC_OtherFactors with (nolock) on dbo.AB_Blood.ProteinC_OtherFactors = LU_ProteinC_OtherFactors.Code LEFT OUTER JOIN

    dbo.AB_DeathInformation with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_DeathInformation.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup24 with (nolock) on dbo.AB_DeathInformation.AutopsyPerformed = Lookup24.Code LEFT OUTER JOIN
    dbo.LU_CoronerCase Lookup51 with (nolock) on dbo.AB_DeathInformation.CoronerCase = Lookup51.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup53 with (nolock) on dbo.AB_DeathInformation.DeathInER = Lookup53.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup54 with (nolock) on dbo.AB_DeathInformation.DeathOnArrival = Lookup54.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup58 with (nolock) on dbo.AB_DeathInformation.DeathInOR = Lookup58.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup99 with (nolock) on dbo.AB_DeathInformation.OtherDeath = Lookup99.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup111 with (nolock) on dbo.AB_DeathInformation.PregnancyDeath = Lookup111.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup150 with (nolock) on dbo.AB_DeathInformation.TraumaDeath = Lookup150.Code LEFT OUTER JOIN
    dbo.AB_MentalHealth with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_MentalHealth.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup1 with (nolock) on dbo.AB_MentalHealth.MentalAWOL = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_MentalLegalStatus Lookup45 with (nolock) on dbo.AB_MentalHealth.MentalLegalStatus = Lookup45.Code LEFT OUTER JOIN
    dbo.LU_MentalECTTreat Lookup61 with (nolock) on dbo.AB_MentalHealth.MentalECTTreatment = Lookup61.Code LEFT OUTER JOIN
    dbo.LU_MentalEducation Lookup63 with (nolock) on dbo.AB_MentalHealth.MentalEducation = Lookup63.Code LEFT OUTER JOIN
    dbo.LU_MentalEmployment Lookup65 with (nolock) on dbo.AB_MentalHealth.MentalEmployment = Lookup65.Code LEFT OUTER JOIN
    dbo.LU_MentalFinancial Lookup68 with (nolock) on dbo.AB_MentalHealth.MentalFinancial = Lookup68.Code LEFT OUTER JOIN
    dbo.LU_MentalAdmitMethod Lookup95 with (nolock) on dbo.AB_MentalHealth.MentalAdmitMethod = Lookup95.Code LEFT OUTER JOIN
    dbo.LU_MentalPrevPsych Lookup112 with (nolock) on dbo.AB_MentalHealth.MentalPrevPsych = Lookup112.Code LEFT OUTER JOIN
    dbo.LU_MentalReferral Lookup137 with (nolock) on dbo.AB_MentalHealth.MentalReferralTo = Lookup137.Code LEFT OUTER JOIN
    dbo.LU_MentalReferral Lookup144 with (nolock) on dbo.AB_MentalHealth.MentalReferralSource = Lookup144.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup147 with (nolock) on dbo.AB_MentalHealth.MentalSuicide = Lookup147.Code LEFT OUTER JOIN
	dbo.LU_MentalLegalStatusUponArrivalED with (nolock) on dbo.AB_MentalHealth.LegalStatusUponArrivaltoED = LU_MentalLegalStatusUponArrivalED.Code LEFT OUTER JOIN
	--dbo.LU_MentalLegalStatusAdmission with (nolock) on dbo.AB_MentalHealth.LegalStatusAtAdmission = LU_MentalLegalStatusAdmission.Code LEFT OUTER JOIN
	dbo.LU_MentalTypeRestraint LU_MentalTypeRestraint_1 with (nolock) on dbo.AB_MentalHealth.TypeOfRestraint01 = LU_MentalTypeRestraint_1.Code LEFT OUTER JOIN
	dbo.LU_MentalFrequencyRestraintUse LU_MentalFrequencyRestraintUse_1 with (nolock) on dbo.AB_MentalHealth.FrequencyOfRestraint01 = LU_MentalFrequencyRestraintUse_1.Code LEFT OUTER JOIN
	dbo.LU_MentalTypeRestraint LU_MentalTypeRestraint_2 with (nolock) on dbo.AB_MentalHealth.TypeOfRestraint02 = LU_MentalTypeRestraint_2.Code LEFT OUTER JOIN
	dbo.LU_MentalFrequencyRestraintUse LU_MentalFrequencyRestraintUse_2 with (nolock) on dbo.AB_MentalHealth.FrequencyOfRestraint02 = LU_MentalFrequencyRestraintUse_2.Code LEFT OUTER JOIN
	dbo.LU_MentalTypeRestraint LU_MentalTypeRestraint_3 with (nolock) on dbo.AB_MentalHealth.TypeOfRestraint03 = LU_MentalTypeRestraint_3.Code LEFT OUTER JOIN
	dbo.LU_MentalFrequencyRestraintUse LU_MentalFrequencyRestraintUse_3 with (nolock) on dbo.AB_MentalHealth.FrequencyOfRestraint03 = LU_MentalFrequencyRestraintUse_3.Code LEFT OUTER JOIN
	dbo.LU_MentalTypeRestraint LU_MentalTypeRestraint_4 with (nolock) on dbo.AB_MentalHealth.TypeOfRestraint04 = LU_MentalTypeRestraint_4.Code LEFT OUTER JOIN
	dbo.LU_MentalFrequencyRestraintUse LU_MentalFrequencyRestraintUse_4 with (nolock) on dbo.AB_MentalHealth.FrequencyOfRestraint04 = LU_MentalFrequencyRestraintUse_4.Code LEFT OUTER JOIN


    dbo.AB_ReproductiveCare with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_ReproductiveCare.AbstractID LEFT OUTER JOIN
    dbo.LU_ReprodComplication Lookup47 with (nolock) on dbo.AB_ReproductiveCare.Complication1 = Lookup47.Code LEFT OUTER JOIN
    dbo.LU_ReprodComplication Lookup48 with (nolock) on dbo.AB_ReproductiveCare.Complication2 = Lookup48.Code LEFT OUTER JOIN
    dbo.LU_ReprodComplication Lookup49 with (nolock) on dbo.AB_ReproductiveCare.Complication3 = Lookup49.Code left join
    dbo.LU_ReprodOR Lookup71 with (nolock) on Lookup71.Code = dbo.AB_ReproductiveCare.InitialOR left join
    dbo.LU_YesBlank Lookup145 with (nolock) on Lookup145.Code = dbo.AB_ReproductiveCare.Sterilization LEFT OUTER JOIN
    dbo.LU_ReprodOR Lookup146 with (nolock) on dbo.AB_ReproductiveCare.SubsequentOR = Lookup146.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup148 with (nolock) on dbo.AB_Abstract.PCTASIndicator = Lookup148.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup153 with (nolock) on dbo.AB_Abstract.SchedEDVisit = Lookup153.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup156 with (nolock) on dbo.AB_Abstract.SeatbeltIndicator = Lookup156.Code AND Lookup156.LookupID = 2 LEFT OUTER JOIN
    dbo.LU_Glasgow Lookup157 with (nolock) on dbo.AB_Abstract.GlasgowComaScale = Lookup157.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup158 with (nolock) on dbo.AB_Abstract.DecisionAdmitTimeUnknown = Lookup158.Code AND Lookup158.LookupID = 1 LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup159 with (nolock) on dbo.AB_Abstract.AssessmentTimeUnknown = Lookup159.Code AND Lookup159.LookupID = 1 LEFT OUTER JOIN
    dbo.LU_AbstractOverflow with (nolock) on dbo.AB_Abstract.AbstractOverflow = dbo.LU_AbstractOverflow.Code LEFT OUTER JOIN
    dbo.LU_YesBlank LUSurgicalCase with (nolock) on dbo.AB_Abstract.SurgicalCase = LUSurgicalCase.Code LEFT OUTER JOIN
    dbo.LU_YesBlank LUComplication with (nolock) on dbo.AB_Abstract.Complication = LUComplication.Code LEFT OUTER JOIN
    dbo.ICD_DiagFile10 LUReasonForVisit with (nolock) on dbo.AB_Abstract.ReasonForVisit = LUReasonForVisit.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LUDischargeTimeUnknown with (nolock) on dbo.AB_Abstract.DischargeTimeUnknown = LUDischargeTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_NurseArea LU_AdmitNurse with (nolock) on dbo.AB_Abstract.AdmittingNurseArea = LU_AdmitNurse.Code LEFT OUTER JOIN
    dbo.LU_NurseArea LU_DischargeNurse with (nolock) on dbo.AB_Abstract.DischargeNurseArea = LU_DischargeNurse.Code LEFT OUTER JOIN
    --ED - 01910
    dbo.LU_CodeFile LU_AmbulanceArrTimeUnknown with (nolock) on dbo.AB_Abstract.AmbulanceArrTimeUnknown = LU_AmbulanceArrTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_AmbulanceTranTimeUnknown with (nolock) on dbo.AB_Abstract.AmbulanceTranTimeUnknown = LU_AmbulanceTranTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_AccessPrimaryHealthCareCode with (nolock) on dbo.AB_Abstract.AccessCareCode = dbo.LU_AccessPrimaryHealthCareCode.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_CDUFlag with (nolock) on dbo.AB_Abstract.CDUFlag = LU_CDUFlag.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CDUInTimeUnknown with (nolock) on dbo.AB_Abstract.CDUInTimeUnknown = LU_CDUInTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CDUOutTimeUnknown with (nolock) on dbo.AB_Abstract.CDUOutTimeUnknown = LU_CDUOutTimeUnknown.Code LEFT OUTER JOIN
    --NP - 00125
    dbo.LU_CIHICorrect LU_Level1_Correction with (nolock) on dbo.AB_Abstract.IsCorrectLevel1 = LU_Level1_Correction.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_Level1_Submission with (nolock) on dbo.AB_Abstract.IsSubmitLevel1 = LU_Level1_Submission.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus LU_Level1_Validation with (nolock) on dbo.AB_Abstract.IsValidLevel1 = LU_Level1_Validation.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus LU_Level1_Completed with (nolock) on dbo.AB_Abstract.IsCompleteLevel1 = LU_Level1_Completed.Code 
--PR - 04577
    LEFT OUTER JOIN dbo.LU_ReciprocalBillingStatus with (nolock) on dbo.AB_Abstract.IsReciprocalBilling = LU_ReciprocalBillingStatus.Code 
--ED-02091 
	left join dbo.AB_NACRS with (nolock) on AB_Abstract.AbstractID = AB_NACRS.AbstractID
	left join dbo.LU_Provider LU_SpecialistNumber with (nolock) on AB_NACRS.SpecialistNumber = LU_SpecialistNumber.Code
	left join dbo.LU_ProviderSpecialty LU_SpecialistService with (nolock) on AB_NACRS.SpecialistService = LU_SpecialistService.Code
	left join dbo.LU_CodeFile LU_SpecialistRequestTimeUnknown with (nolock) on AB_NACRS.SpecialistRequestTimeUnknown = LU_SpecialistRequestTimeUnknown.Code
	left join dbo.LU_Provider LU_NonPhysicianNumber with (nolock) on AB_NACRS.NonPhysicianNumber = LU_NonPhysicianNumber.Code
	left join dbo.LU_ProviderSpecialty LU_NonPhysicianService with (nolock) on AB_NACRS.NonPhysicianService = LU_NonPhysicianService.Code
	left join dbo.LU_CodeFile LU_NonPhysicianAssessmentTimeUnknown with (nolock) on AB_NACRS.NonPhysicianAssessmentTimeUnknown = LU_NonPhysicianAssessmentTimeUnknown.Code
	
	left join dbo.LU_CodeFile LU_AmCareTypeCode with (nolock) on AB_NACRS.AmCareTypeCode = LU_AmCareTypeCode.Code
	left join dbo.LU_CodeFile LU_AmCareGroup with (nolock) on AB_NACRS.AmCareGroup = LU_AmCareGroup.Code
	--ED - 02130
	left join dbo.LU_CodeFile LU_AmCareTypeCode_FromMISCode with (nolock) on Lookup93.AmCareTypeCode = LU_AmCareTypeCode_FromMISCode.CIHIValue and LU_AmCareTypeCode_FromMISCode.LookUpID = 1101 and LU_AmCareTypeCode_FromMISCode.code between 203501 and 203513
	left join dbo.LU_CodeFile LU_AmCareGroup_FromMISCode with (nolock) on Lookup93.AmCareGroup = LU_AmCareGroup_FromMISCode.CIHIValue and LU_AmCareGroup_FromMISCode.LookUPID = 1102 and LU_AmCareGroup_FromMISCode.code between 203601 and 203605
    
    --ED - 02298
    left join dbo.LU_YesNoSystem LU_EDVisitIndicator with (nolock) on dbo.AB_NACRS.EDVisitIndicator = LU_EDVisitIndicator.Code
    left join dbo.LU_StatusAfterTriage with (nolock) on dbo.AB_NACRS.StatusAfterTriage = LU_StatusAfterTriage.Code
WHERE     (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 105)
--QA - 00032 disable the domain securite issue
----PR - 07485
--    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB_ABstract.HospitalID is null or AB_ABstract.HospitalID = 0
--    --EN - 00666
--        or Is_Member(nullif(ReportGroup, '''')) = 1)
----        or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB_ABstract.HospitalID, 0))











' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_060_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Amcare_Projects_060_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 

    InpatientRehabilitation = LU_ProjectQuestion1.DisplayCode, InpatientRehabilitationDesc = LU_ProjectQuestion1.UserDescription, 
    InpatientRehabilitationFacilityNumber =  isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, '''') + isnull(LU_ProjectQuestion5.CIHIValue, '''')  + isnull(LU_ProjectQuestion6.CIHIValue, ''''), 
    InpatientRehabilitationFacilityNumberDesc = (select top 1 UserDescription from LU_Institution_10 where cihivalue = (LU_ProjectQuestion2.CIHIValue + LU_ProjectQuestion3.CIHIValue + LU_ProjectQuestion4.CIHIValue + LU_ProjectQuestion5.CIHIValue + LU_ProjectQuestion6.CIHIValue) order by validto desc), 

    HomeCareRehabilitation = LU_ProjectQuestion7.DisplayCode,HomeCareRehabilitationDesc = LU_ProjectQuestion7.UserDescription, 
    HomeCareRehabilitationLHINNumber = isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''') + isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''') + isnull(LU_ProjectQuestion12.CIHIValue, ''''), 
    HomeCareRehabilitationLHINNumberDesc = (select top 1 UserDescription from LU_Institution_10 where cihivalue = (LU_ProjectQuestion8.CIHIValue + LU_ProjectQuestion9.CIHIValue +  LU_ProjectQuestion10.CIHIValue  + LU_ProjectQuestion11.CIHIValue  + LU_ProjectQuestion12.CIHIValue) order by validto desc), 

    OutpatientRehabilitation = LU_ProjectQuestion13.DisplayCode, OutpatientRehabilitationDesc = LU_ProjectQuestion13.UserDescription, 
    OutpatientRehabilitationFacilityNumber = isnull(p.Question14, '''') + isnull(p.Question15, '''') + isnull(p.Question16, '''') + isnull(p.Question17, '''') + isnull(p.Question18, ''''),
    OutpatientRehabilitationFacilityNumberDesc = (select top 1 UserDescription from LU_Institution_10 where cihivalue = (isnull(p.Question14, '''') + isnull(p.Question15, '''') + isnull(p.Question16, '''') + isnull(p.Question17, '''') + isnull(p.Question18, '''')) order by validto desc), 

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''060'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_065_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Amcare_Projects_065_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 

    BundledCareType = (case when len(LU_ProjectQuestion1.CIHIValue) = 6 
                            then LU_ProjectQuestion1.CIHIValue                           
                            else isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, '''') + isnull(LU_ProjectQuestion5.CIHIValue, '''') + isnull(LU_ProjectQuestion6.CIHIValue, '''')
                       end), 
    BundledCareTypeDesc = (case when len(LU_ProjectQuestion1.CIHIValue) = 6 
                            then LU_ProjectQuestion1.UserDescription                           
                            else ''''
                       end), 

    InpatientRehabilitation = isnull(LU_ProjectQuestion7.DisplayCode, ''''), 
    InpatientRehabilitationDesc = isnull(LU_ProjectQuestion7.UserDescription, ''''), 
    InpatientRehabilitationInstitutionNumber =  isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''') + isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, ''''), 
    InpatientRehabilitationInstitutionNumberDesc = (select top 1 UserDescription from LU_Institution_10 where cihivalue = (''5'' + isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''') + isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''')) order by validto desc), 

    HomeCare = LU_ProjectQuestion12.DisplayCode,
    HomeCareRehabilitationDesc = LU_ProjectQuestion12.UserDescription, 
    HomeCareLHINNumber = isnull(LU_ProjectQuestion13.CIHIValue, '''') + isnull(p.Question14, '''') + isnull(p.Question15, '''') + isnull(p.Question16, ''''), 
    HomeCareLHINNumberDesc = (select top 1 UserDescription from LU_Institution_10 where cihivalue = (''5'' + isnull(LU_ProjectQuestion13.CIHIValue, '''') + isnull(p.Question14, '''') + isnull(p.Question15, '''') + isnull(p.Question16, '''')) order by validto desc), 

    OutpatientRehabilitation = isnull(p.Question17, ''''), 
    OutpatientRehabilitationDesc = (case p.Question17 when ''Y'' then ''Outpatient rehabilitation planned for the patient'' 
                                                      when ''N'' then ''Outpatient rehabilitation not planned for this patient''
                                                      when ''D'' then ''Declined''
                                                      when ''9'' then ''Unknown ''
                                                      else ''''
                                    end),
    OutpatientRehabilitationInstitutionNumber = isnull(p.Question18, '''') + isnull(p.Question19, '''') + isnull(p.Question20, '''') + isnull(p.Question21, ''''),
    OutpatientRehabilitationInstitutionNumberDesc = (select top 1 UserDescription from LU_Institution_10 where cihivalue = (''5'' + isnull(p.Question18, '''') + isnull(p.Question19, '''') + isnull(p.Question20, '''') + isnull(p.Question21, '''')) order by validto desc), 

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''065'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_100_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Amcare_Projects_100_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 
    LU_ProjectQuestion1.DisplayCode AS CompleteRecordFlag, LU_ProjectQuestion1.UserDescription AS CompleteRecordFlagDesc, 
    LU_ProjectQuestion2.DisplayCode AS RecordAvailable, LU_ProjectQuestion2.UserDescription AS RecordAvailableDesc, 
    LU_ProjectQuestion3.DisplayCode AS OperativeReportAvailable, LU_ProjectQuestion3.UserDescription AS OperativeReportAvailableDesc, 
    LU_ProjectQuestion7.DisplayCode AS RecordSubsequentlyReviewedAfterCompletion, LU_ProjectQuestion7.UserDescription AS RecordSubsequentlyReviewedAfterCompletionDesc, 
    LU_ProjectQuestion8.DisplayCode AS DataChangedFromOriginalSubmission, LU_ProjectQuestion8.UserDescription AS DataChangedFromOriginalSubmissionDesc, 
    LU_ProjectQuestion9.DisplayCode AS PathologyReportAvailable, LU_ProjectQuestion9.UserDescription AS PathologyReportAvailableDesc, 
    DateofSubsequentReview = (case when Admitdate < ''2009/04/01'' or ProjectNumber = 3 then dbo.ConvertToDate(LU_ProjectQuestion13.CIHIValue + p.Question14 + p.Question15 + p.Question16 + p.Question17 + p.Question18 + p.Question19 + p.Question20)
                                   else dbo.ConvertToDate(LU_ProjectQuestion13.CIHIValue + p.Question21 + p.Question22 + p.Question23 + p.Question24 + p.Question16 + p.Question17 + p.Question14 + p.Question15)
                             end),
    DateofSubsequentReview_InValidate = (case when Admitdate < ''2009/04/01'' or ProjectNumber = 3 then dbo.CheckInvalidateDate(LU_ProjectQuestion13.CIHIValue + p.Question14 + p.Question15 + p.Question16 + p.Question17 + p.Question18 + p.Question19 + p.Question20)
                                              else dbo.CheckInvalidateDate(LU_ProjectQuestion13.CIHIValue + p.Question21 + p.Question22 + p.Question23 + p.Question24 + p.Question16 + p.Question17 + p.Question14 + p.Question15)
                                         end),
    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion4  with (nolock) on dbo.AB_Project.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion5  with (nolock) on dbo.AB_Project.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion6  with (nolock) on dbo.AB_Project.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion11 with (nolock) on dbo.AB_Project.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion12 with (nolock) on dbo.AB_Project.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE  AdmitDate > ''2006/03/31'' and LU_Project.CIHIValue = ''100'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_150_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Amcare_Projects_150_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 
    InterventionLineNumber = LU_ProjectQuestion1.CIHIValue + LU_ProjectQuestion1.CIHIValue, 
    DateCompletedReferralReceived = dbo.ConvertToDate(LU_ProjectQuestion1.CIHIValue + LU_ProjectQuestion2.CIHIValue + LU_ProjectQuestion3.CIHIValue + LU_ProjectQuestion4.CIHIValue + LU_ProjectQuestion5.CIHIValue + LU_ProjectQuestion6.CIHIValue + LU_ProjectQuestion7.CIHIValue + LU_ProjectQuestion8.CIHIValue + LU_ProjectQuestion9.CIHIValue + LU_ProjectQuestion10.CIHIValue),
    TypeOfSeverityPriorityUrgencyScoreUsed = LU_ProjectQuestion11.DisplayCode, TypeOfSeverityPriorityUrgencyScoreUsedDesc = LU_ProjectQuestion2.UserDescription, 
    SeverityPriorityUrgencyScore = isnull(LU_ProjectQuestion12.CIHIValue, '''') + isnull(LU_ProjectQuestion13.CIHIValue, '''') + isnull(p.Question14, '''') + isnull(p.Question15, ''''),
    DateType = p.Question16,
    OtherDate = dbo.ConvertToTime(p.Question17 + p.Question18 + p.Question19 + p.Question20 + p.Question21 + p.Question22 + p.Question23 + p.Question24), 

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''150'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = (5))
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_202_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Amcare_Projects_202_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 
    Kidneys = LU_ProjectQuestion1.DisplayCode, KidneysDesc = LU_ProjectQuestion1.UserDescription, 
    Liver = LU_ProjectQuestion2.DisplayCode, LiverDesc = LU_ProjectQuestion2.UserDescription, 
    Heart = LU_ProjectQuestion3.DisplayCode, HeartDesc = LU_ProjectQuestion3.UserDescription, 
    Pancreas = LU_ProjectQuestion4.DisplayCode, PancreascDesc = LU_ProjectQuestion4.UserDescription, 
    PancreaticIsletCells = LU_ProjectQuestion5.DisplayCode, PancreaticIsletCellsDesc = LU_ProjectQuestion5.UserDescription, 
    Heartvalves = LU_ProjectQuestion6.DisplayCode, HeartvalvesDesc = LU_ProjectQuestion6.UserDescription, 
    Bowel = LU_ProjectQuestion7.DisplayCode, BowelDesc = LU_ProjectQuestion7.UserDescription, 
    Cornea = LU_ProjectQuestion8.DisplayCode, CorneaDesc = LU_ProjectQuestion8.UserDescription, 
    Skin = LU_ProjectQuestion9.DisplayCode, SkinDesc = LU_ProjectQuestion9.UserDescription, 
    Bone = LU_ProjectQuestion10.DisplayCode, BoneDesc = LU_ProjectQuestion10.UserDescription, 
    Other = LU_ProjectQuestion11.DisplayCode, OtherDesc = LU_ProjectQuestion11.UserDescription, 
    Lung = LU_ProjectQuestion13.DisplayCode, LungDesc = LU_ProjectQuestion13.UserDescription, 
   
    HoursBetweenDeathAndHarvesting = isnull(p.Question14, '''') + isnull(p.Question15, ''''),
    NumberOfOrgansIssueRetrieveved = isnull(p.Question16, '''') + isnull(p.Question17, ''''),
    ORTime = isnull(p.Question18, '''') + isnull(p.Question19, '''') + isnull(p.Question20, ''''),

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''202'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_250_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Amcare_Projects_250_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 

    MetalStent = LU_ProjectQuestion1.DisplayCode, MetalStentDesc = LU_ProjectQuestion1.UserDescription, 
    NumberEsophagealPolyps =  cast((case when isnumeric(isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''')) = 1 then isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') end) as int), 
    NumberStomachPolyps =  cast((case when isnumeric(isnull(LU_ProjectQuestion4.CIHIValue, '''') + isnull(LU_ProjectQuestion5.CIHIValue, '''')) = 1 then isnull(LU_ProjectQuestion4.CIHIValue, '''') + isnull(LU_ProjectQuestion5.CIHIValue, '''') end) as int), 
    NumberSmallIntestinePolyps =  cast((case when isnumeric(isnull(LU_ProjectQuestion6.CIHIValue, '''') + isnull(LU_ProjectQuestion7.CIHIValue, '''')) = 1 then isnull(LU_ProjectQuestion6.CIHIValue, '''') + isnull(LU_ProjectQuestion7.CIHIValue, '''') end) as int), 
    NumberLargeIntestinePolyps =  cast((case when isnumeric(isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''')) = 1 then isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''') end) as int), 
    NumberRectalPolyps =  cast((case when isnumeric(isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''')) = 1 then isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''') end) as int), 

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code 
    --dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''250'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_315_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_Amcare_Projects_315_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 

    NumberMetalStents_Esophagus      = LU_ProjectQuestion1.CIHIValue,
    NumberMetalStents_SmallIntestine = LU_ProjectQuestion2.CIHIValue,
    NumberMetalStents_LargeIntestine = LU_ProjectQuestion3.CIHIValue,
    NumberMetalStents_Rectum         = LU_ProjectQuestion4.CIHIValue,
    NumberMetalStents_BileDucts      = LU_ProjectQuestion5.CIHIValue,

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code 
    --dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''315'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_316_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[I10_Amcare_Projects_316_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 

    SizeLargestExcisedPolyp = (case when isnumeric(ltrim(isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, ''''))) = 1 then cast(ltrim(isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, '''')) as int) end),
    NumberPolypsMediumExcised = (case when isnumeric(ltrim(isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, ''''))) = 1 then cast(ltrim(isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, '''')) as int) end),

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code --LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''316'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_340_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Amcare_Projects_340_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 
    LU_ProjectQuestion1.DisplayCode AS CT_MRIScanWithin24HoursEDArrival, LU_ProjectQuestion1.UserDescription AS CT_MRIScanWithin24HoursEDArrivalDesc, 
    LU_ProjectQuestion2.DisplayCode AS ReferralToStrokePreventionServicesEDDischarge, LU_ProjectQuestion2.UserDescription AS ReferralToStrokePreventionServicesEDDischargeDesc, 
    LU_ProjectQuestion3.DisplayCode AS AdministrationAcuteThrombolysis, LU_ProjectQuestion3.UserDescription AS AdministrationAcuteThrombolysisDesc, 
    MonthOfAcuteThrombolysisAdministration = isnull(LU_ProjectQuestion4.CIHIValue, '''') + isnull(LU_ProjectQuestion5.CIHIValue, ''''),
    DayOfAcuteThrombolysisAdministration = isnull(LU_ProjectQuestion6.CIHIValue, '''') + isnull(LU_ProjectQuestion7.CIHIValue, ''''),
    HourOfAcuteThrombolysisAdministration = isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, ''''),
    MinuteOfAcuteThrombolysisAdministration = isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, ''''),
    
    LU_ProjectQuestion12.DisplayCode AS PrescriptionForAntithromboticMedicationDischarge, LU_ProjectQuestion12.UserDescription AS PrescriptionForAntithromboticMedicationDischargeDesc, 

    StrokeSymptomOnsetDate = dbo.ConvertToDate(LU_ProjectQuestion13.CIHIValue + p.Question14 + p.Question15 + p.Question16 + p.Question17 + p.Question18 + p.Question19 + p.Question20),
    StrokeSymptomOnsetDateUnknown = dbo.CheckUnknownDate(LU_ProjectQuestion13.CIHIValue + p.Question14 + p.Question15 + p.Question16 + p.Question17 + p.Question18 + p.Question19 + p.Question20),

    StrokeSymptomOnsetTime = dbo.ConvertToTime(p.Question21 + p.Question22 + p.Question23 + p.Question24),
    StrokeSymptomOnsetTimeUnknown = dbo.CheckUnknownTime(p.Question21 + p.Question22 + p.Question23 + p.Question24),

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE AdmitDate > ''2010/03/31'' and LU_Project.CIHIValue = ''340'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = (5))
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_640_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Amcare_Projects_640_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 
    LU_ProjectQuestion1.DisplayCode AS DysphagiaScreening, LU_ProjectQuestion1.UserDescription AS DysphagiaScreeningDesc, 
    LU_ProjectQuestion2.DisplayCode AS TelestrokeConsultation, LU_ProjectQuestion2.UserDescription AS TelestrokeConsultationDesc, 
    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code 
WHERE AdmitDate > ''2015/03/31'' and LU_Project.CIHIValue = ''640'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_740_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Amcare_Projects_740_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 
    LU_ProjectQuestion1.DisplayCode AS DocumentationAlphaFIM, LU_ProjectQuestion1.UserDescription AS DocumentationAlphaFIMDesc, 

    (case when isdate(LU_ProjectQuestion2.DisplayCode + LU_ProjectQuestion3.DisplayCode + LU_ProjectQuestion4.DisplayCode + LU_ProjectQuestion5.DisplayCode + ''/'' + LU_ProjectQuestion6.DisplayCode + LU_ProjectQuestion7.DisplayCode + ''/'' + LU_ProjectQuestion8.DisplayCode + LU_ProjectQuestion9.DisplayCode) = 1
          then   cast(LU_ProjectQuestion2.DisplayCode + LU_ProjectQuestion3.DisplayCode + LU_ProjectQuestion4.DisplayCode + LU_ProjectQuestion5.DisplayCode + ''/'' + LU_ProjectQuestion6.DisplayCode + LU_ProjectQuestion7.DisplayCode + ''/'' + LU_ProjectQuestion8.DisplayCode + LU_ProjectQuestion9.DisplayCode as datetime)
          else null
     end) AS AlphaFIMScoreCompletionDate, 

    isnull(LU_ProjectQuestion10.DisplayCode, '''') + isnull(LU_ProjectQuestion11.DisplayCode, '''') as ProjectFIMRawMotorRating,
    isnull(LU_ProjectQuestion12.DisplayCode, '''') + isnull(LU_ProjectQuestion13.DisplayCode, '''') as ProjectFIMRawCognitiveRating,

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE AdmitDate > ''2013/03/31'' and LU_Project.CIHIValue = ''740'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_960_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Amcare_Projects_960_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 

    DateOfFirstVisit = (case when isdate(LU_ProjectQuestion1.CIHIValue + LU_ProjectQuestion2.CIHIValue + LU_ProjectQuestion3.CIHIValue + LU_ProjectQuestion4.CIHIValue + LU_ProjectQuestion5.CIHIValue + LU_ProjectQuestion6.CIHIValue + LU_ProjectQuestion7.CIHIValue + LU_ProjectQuestion8.CIHIValue) = 1 then cast(LU_ProjectQuestion1.CIHIValue + LU_ProjectQuestion2.CIHIValue + LU_ProjectQuestion3.CIHIValue + LU_ProjectQuestion4.CIHIValue + LU_ProjectQuestion5.CIHIValue + LU_ProjectQuestion6.CIHIValue + LU_ProjectQuestion7.CIHIValue + LU_ProjectQuestion8.CIHIValue as datetime) end), 
    ReasonForDischarge =  LU_ProjectQuestion9.DisplayCode, ReasonForDischargeDesc = LU_ProjectQuestion9.UserDescription, 

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code --LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code 
    --dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''960'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_961_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Amcare_Projects_961_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 

    Surgical_NonSurgicalStatus   =  LU_ProjectQuestion1.DisplayCode, Surgical_NonSurgicalStatusDesc = LU_ProjectQuestion1.UserDescription, 
    Traumatic_NonTraumaticStatus =  LU_ProjectQuestion2.DisplayCode, Traumatic_NonTraumaticStatusDesc = LU_ProjectQuestion2.UserDescription, 
    ExtremityInvolvement         =  LU_ProjectQuestion3.DisplayCode, ExtremityInvolvementDesc = LU_ProjectQuestion3.UserDescription, 
    HipFractureSurgicalStatus    =  LU_ProjectQuestion4.DisplayCode, HipFractureSurgicalStatusDesc = LU_ProjectQuestion4.UserDescription, 
    KneeHipReplacementPrimaryRevision  =  LU_ProjectQuestion5.DisplayCode, KneeHipReplacementPrimaryRevisionDesc  = LU_ProjectQuestion5.UserDescription, 
    BurnsPercentTotalBodySurfaceArea   =  LU_ProjectQuestion6.DisplayCode, BurnsPercentTotalBodySurfaceAreaDesc   = LU_ProjectQuestion6.UserDescription, 
    BilateralUpperLimbAmputationLevels =  LU_ProjectQuestion7.DisplayCode, BilateralUpperLimbAmputationLevelsDesc = LU_ProjectQuestion7.UserDescription, 
    BilateralLowerLimbAmputationLevels =  LU_ProjectQuestion8.DisplayCode, BilateralLowerLimbAmputationLevelsDesc = LU_ProjectQuestion8.UserDescription, 
    DementiainNeurological             =  LU_ProjectQuestion9.DisplayCode, DementiainNeurologicalDesc             = LU_ProjectQuestion9.UserDescription, 

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code --LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code 
    --dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''961'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_962_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Amcare_Projects_962_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 

    TotalVisits_RegisteredNurse =  cast((case when isnumeric(isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, '''')) = 1 
											  then isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, '''') 
										end) as int), 
	TotalVisits_RegisteredNurseAlpha = ltrim(rtrim(isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, ''''))),

	ServiceDuration_RegisteredNurse =  cast((case when isnumeric(isnull(LU_ProjectQuestion5.CIHIValue, '''') + isnull(LU_ProjectQuestion6.CIHIValue, '''') + isnull(LU_ProjectQuestion7.CIHIValue, '''') + isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''')) = 1 
												 then isnull(LU_ProjectQuestion5.CIHIValue, '''') + isnull(LU_ProjectQuestion6.CIHIValue, '''') + isnull(LU_ProjectQuestion7.CIHIValue, '''') + isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''') 
										     end) as int), 

    TotalVisits_RegisteredPracticalNurse =  cast((case when isnumeric(isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''') + isnull(LU_ProjectQuestion12.CIHIValue, '''') + isnull(LU_ProjectQuestion13.CIHIValue, '''')) = 1 
											           then isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''') + isnull(LU_ProjectQuestion12.CIHIValue, '''') + isnull(LU_ProjectQuestion13.CIHIValue, '''') 
												  end) as int), 
	TotalVisits_RegisteredPracticalNurseAlpha = ltrim(rtrim(isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''') + isnull(LU_ProjectQuestion12.CIHIValue, '''') + isnull(LU_ProjectQuestion13.CIHIValue, '''') )),

	ServiceDuration_RegisteredPracticalNurse =  cast((case when isnumeric(isnull(p.Question14, '''') + isnull(p.Question15, '''') + isnull(p.Question16, '''') + isnull(p.Question17, '''') + isnull(p.Question18, '''')) = 1 
												           then isnull(p.Question14, '''') + isnull(p.Question15, '''') + isnull(p.Question16, '''') + isnull(p.Question17, '''') + isnull(p.Question18, '''')
										              end) as int), 

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''962'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_963_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Amcare_Projects_963_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 

    TotalVisits_OccupationalTherapist =  cast((case when isnumeric(isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, '''')) = 1 
											  then isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, '''') 
										end) as int), 
	TotalVisits_OccupationalTherapistAlpha = ltrim(rtrim(isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, ''''))),

	ServiceDuration_OccupationalTherapist =  cast((case when isnumeric(isnull(LU_ProjectQuestion5.CIHIValue, '''') + isnull(LU_ProjectQuestion6.CIHIValue, '''') + isnull(LU_ProjectQuestion7.CIHIValue, '''') + isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''')) = 1 
												 then isnull(LU_ProjectQuestion5.CIHIValue, '''') + isnull(LU_ProjectQuestion6.CIHIValue, '''') + isnull(LU_ProjectQuestion7.CIHIValue, '''') + isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''') 
										     end) as int), 

    TotalVisits_OccupationalTherapyAssistant =  cast((case when isnumeric(isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''') + isnull(LU_ProjectQuestion12.CIHIValue, '''') + isnull(LU_ProjectQuestion13.CIHIValue, '''')) = 1 
											           then isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''') + isnull(LU_ProjectQuestion12.CIHIValue, '''') + isnull(LU_ProjectQuestion13.CIHIValue, '''') 
												  end) as int), 
	TotalVisits_OccupationalTherapyAssistantAlpha = ltrim(rtrim(isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''') + isnull(LU_ProjectQuestion12.CIHIValue, '''') + isnull(LU_ProjectQuestion13.CIHIValue, '''') )),

	ServiceDuration_OccupationalTherapyAssistant =  cast((case when isnumeric(isnull(p.Question14, '''') + isnull(p.Question15, '''') + isnull(p.Question16, '''') + isnull(p.Question17, '''') + isnull(p.Question18, '''')) = 1 
												           then isnull(p.Question14, '''') + isnull(p.Question15, '''') + isnull(p.Question16, '''') + isnull(p.Question17, '''') + isnull(p.Question18, '''')
										              end) as int), 

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''963'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_964_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Amcare_Projects_964_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 

    TotalVisits_Physiotherapist =  cast((case when isnumeric(isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, '''')) = 1 
											  then isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, '''') 
										end) as int), 
	TotalVisits_PhysiotherapistAlpha = ltrim(rtrim(isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, ''''))),

	ServiceDuration_Physiotherapist =  cast((case when isnumeric(isnull(LU_ProjectQuestion5.CIHIValue, '''') + isnull(LU_ProjectQuestion6.CIHIValue, '''') + isnull(LU_ProjectQuestion7.CIHIValue, '''') + isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''')) = 1 
												 then isnull(LU_ProjectQuestion5.CIHIValue, '''') + isnull(LU_ProjectQuestion6.CIHIValue, '''') + isnull(LU_ProjectQuestion7.CIHIValue, '''') + isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''') 
										     end) as int), 

    TotalVisits_PhysiotherapyAssistant =  cast((case when isnumeric(isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''') + isnull(LU_ProjectQuestion12.CIHIValue, '''') + isnull(LU_ProjectQuestion13.CIHIValue, '''')) = 1 
											           then isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''') + isnull(LU_ProjectQuestion12.CIHIValue, '''') + isnull(LU_ProjectQuestion13.CIHIValue, '''') 
												  end) as int), 
	TotalVisits_PhysiotherapyAssistantAlpha = ltrim(rtrim(isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''') + isnull(LU_ProjectQuestion12.CIHIValue, '''') + isnull(LU_ProjectQuestion13.CIHIValue, '''') )),

	ServiceDuration_PhysiotherapyAssistant =  cast((case when isnumeric(isnull(p.Question14, '''') + isnull(p.Question15, '''') + isnull(p.Question16, '''') + isnull(p.Question17, '''') + isnull(p.Question18, '''')) = 1 
												           then isnull(p.Question14, '''') + isnull(p.Question15, '''') + isnull(p.Question16, '''') + isnull(p.Question17, '''') + isnull(p.Question18, '''')
										              end) as int), 

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''964'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_965_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Amcare_Projects_965_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 

    TotalVisits_SpeechLanguagePathologist =  cast((case when isnumeric(isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, '''')) = 1 
											  then isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, '''') 
										end) as int), 
	TotalVisits_SpeechLanguagePathologistAlpha = ltrim(rtrim(isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, ''''))),

	ServiceDuration_SpeechLanguagePathologist =  cast((case when isnumeric(isnull(LU_ProjectQuestion5.CIHIValue, '''') + isnull(LU_ProjectQuestion6.CIHIValue, '''') + isnull(LU_ProjectQuestion7.CIHIValue, '''') + isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''')) = 1 
												 then isnull(LU_ProjectQuestion5.CIHIValue, '''') + isnull(LU_ProjectQuestion6.CIHIValue, '''') + isnull(LU_ProjectQuestion7.CIHIValue, '''') + isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''') 
										     end) as int), 

    TotalVisits_CommunicationDisordersAssistant =  cast((case when isnumeric(isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''') + isnull(LU_ProjectQuestion12.CIHIValue, '''') + isnull(LU_ProjectQuestion13.CIHIValue, '''')) = 1 
											           then isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''') + isnull(LU_ProjectQuestion12.CIHIValue, '''') + isnull(LU_ProjectQuestion13.CIHIValue, '''') 
												  end) as int), 
	TotalVisits_CommunicationDisordersAssistantAlpha = ltrim(rtrim(isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''') + isnull(LU_ProjectQuestion12.CIHIValue, '''') + isnull(LU_ProjectQuestion13.CIHIValue, '''') )),

	ServiceDuration_CommunicationDisordersAssistant =  cast((case when isnumeric(isnull(p.Question14, '''') + isnull(p.Question15, '''') + isnull(p.Question16, '''') + isnull(p.Question17, '''') + isnull(p.Question18, '''')) = 1 
												           then isnull(p.Question14, '''') + isnull(p.Question15, '''') + isnull(p.Question16, '''') + isnull(p.Question17, '''') + isnull(p.Question18, '''')
										              end) as int), 

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''965'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_966_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Amcare_Projects_966_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 

    TotalVisits_SocialWorker =  cast((case when isnumeric(isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, '''')) = 1 
										   then isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, '''') 
									  end) as int), 
	TotalVisits_SocialWorkerAlpha = ltrim(rtrim(isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, ''''))),

	ServiceDuration_SocialWorker =  cast((case when isnumeric(isnull(LU_ProjectQuestion5.CIHIValue, '''') + isnull(LU_ProjectQuestion6.CIHIValue, '''') + isnull(LU_ProjectQuestion7.CIHIValue, '''') + isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''')) = 1 
											   then isnull(LU_ProjectQuestion5.CIHIValue, '''') + isnull(LU_ProjectQuestion6.CIHIValue, '''') + isnull(LU_ProjectQuestion7.CIHIValue, '''') + isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''') 
										  end) as int), 

    TotalVisits_Other =  cast((case when isnumeric(isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''') + isnull(LU_ProjectQuestion12.CIHIValue, '''') + isnull(LU_ProjectQuestion13.CIHIValue, '''')) = 1 
									then isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''') + isnull(LU_ProjectQuestion12.CIHIValue, '''') + isnull(LU_ProjectQuestion13.CIHIValue, '''') 
							   end) as int), 
	TotalVisits_OtherAlpha = ltrim(rtrim(isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''') + isnull(LU_ProjectQuestion12.CIHIValue, '''') + isnull(LU_ProjectQuestion13.CIHIValue, '''') )),

	ServiceDuration_Other =  cast((case when isnumeric(isnull(p.Question14, '''') + isnull(p.Question15, '''') + isnull(p.Question16, '''') + isnull(p.Question17, '''') + isnull(p.Question18, '''')) = 1 
										then isnull(p.Question14, '''') + isnull(p.Question15, '''') + isnull(p.Question16, '''') + isnull(p.Question17, '''') + isnull(p.Question18, '''')
								   end) as int), 

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''966'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_Question_24_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_Amcare_Projects_Question_24_VR]
AS
SELECT     
    Lookup115.DisplayCode AS ProjectNumber, Lookup115.UserDescription AS ProjectNumberDesc, 
    dbo.AB_Project.ProjectOccurrence, 
    Lookup120.DisplayCode AS Question1, Lookup120.UserDescription AS Question1Desc, 
    Lookup125.DisplayCode AS Question2, Lookup125.UserDescription AS Question2Desc, 
    Lookup126.DisplayCode AS Question3, Lookup126.UserDescription AS Question3Desc, 
    Lookup127.DisplayCode AS Question4, Lookup127.UserDescription AS Question4Desc, 
    Lookup128.DisplayCode AS Question5, Lookup128.UserDescription AS Question5Desc, 
    Lookup129.DisplayCode AS Question6, Lookup129.UserDescription AS Question6Desc, 
    Lookup130.DisplayCode AS Question7, Lookup130.UserDescription AS Question7Desc, 
    Lookup131.DisplayCode AS Question8, Lookup131.UserDescription AS Question8Desc, 
    Lookup132.DisplayCode AS Question9, Lookup132.UserDescription AS Question9Desc, 
    Lookup121.DisplayCode AS Question10, Lookup121.UserDescription AS Question10Desc, 
    Lookup122.DisplayCode AS Question11, Lookup122.UserDescription AS Question11Desc, 
    Lookup123.DisplayCode AS Question12, Lookup123.UserDescription AS Question12Desc, 
    Lookup124.DisplayCode AS Question13, Lookup124.UserDescription AS Question13Desc, 
    dbo.AB_Project.Question14, 
    dbo.AB_Project.Question15, 
    dbo.AB_Project.Question16, 
    dbo.AB_Project.Question17, 
    dbo.AB_Project.Question18, 
    dbo.AB_Project.Question19, 
    dbo.AB_Project.Question20, 
    dbo.AB_Project.Question21, 
    dbo.AB_Project.Question22, 
    dbo.AB_Project.Question23, 
    dbo.AB_Project.Question24, 
    dbo.AB_Project.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) left OUTER JOIN
    dbo.AB_Project with (nolock) on dbo.AB_Project.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
    dbo.LU_Project Lookup115 with (nolock) on dbo.AB_Project.ProjectNumber = Lookup115.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1 Lookup120 with (nolock) on dbo.AB_Project.Question1 = Lookup120.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 Lookup121 with (nolock) on dbo.AB_Project.Question10 = Lookup121.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 Lookup122 with (nolock) on dbo.AB_Project.Question11 = Lookup122.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 Lookup123 with (nolock) on dbo.AB_Project.Question12 = Lookup123.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 Lookup124 with (nolock) on dbo.AB_Project.Question13 = Lookup124.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2 Lookup125 with (nolock) on dbo.AB_Project.Question2 = Lookup125.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3 Lookup126 with (nolock) on dbo.AB_Project.Question3 = Lookup126.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4 Lookup127 with (nolock) on dbo.AB_Project.Question4 = Lookup127.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5 Lookup128 with (nolock) on dbo.AB_Project.Question5 = Lookup128.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6 Lookup129 with (nolock) on dbo.AB_Project.Question6 = Lookup129.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7 Lookup130 with (nolock) on dbo.AB_Project.Question7 = Lookup130.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8 Lookup131 with (nolock) on dbo.AB_Project.Question8 = Lookup131.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9 Lookup132 with (nolock) on dbo.AB_Project.Question9 = Lookup132.Code
WHERE     (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)










' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Projects_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[I10_Amcare_Projects_VR]
AS
SELECT     
    Lookup115.DisplayCode AS ProjectNumber, Lookup115.UserDescription AS ProjectNumberDesc, 
    dbo.AB_Project.ProjectOccurrence, 
    Lookup120.DisplayCode AS Question1, Lookup120.UserDescription AS Question1Desc, 
    Lookup125.DisplayCode AS Question2, Lookup125.UserDescription AS Question2Desc, 
    Lookup126.DisplayCode AS Question3, Lookup126.UserDescription AS Question3Desc, 
    Lookup127.DisplayCode AS Question4, Lookup127.UserDescription AS Question4Desc, 
    Lookup128.DisplayCode AS Question5, Lookup128.UserDescription AS Question5Desc, 
    Lookup129.DisplayCode AS Question6, Lookup129.UserDescription AS Question6Desc, 
    Lookup130.DisplayCode AS Question7, Lookup130.UserDescription AS Question7Desc, 
    Lookup131.DisplayCode AS Question8, Lookup131.UserDescription AS Question8Desc, 
    Lookup132.DisplayCode AS Question9, Lookup132.UserDescription AS Question9Desc, 
    Lookup121.DisplayCode AS Question10, Lookup121.UserDescription AS Question10Desc, 
    Lookup122.DisplayCode AS Question11, Lookup122.UserDescription AS Question11Desc, 
    Lookup123.DisplayCode AS Question12, Lookup123.UserDescription AS Question12Desc, 
    Lookup124.DisplayCode AS Question13, Lookup124.UserDescription AS Question13Desc, 
    Question14 = isnull(dbo.AB_Project.Question14, '''') + isnull(dbo.AB_Project.Question15, ''''), 
    Question15 = isnull(dbo.AB_Project.Question16, '''') + isnull(dbo.AB_Project.Question17, ''''), 
    Question16 = isnull(dbo.AB_Project.Question18, '''') + isnull(dbo.AB_Project.Question19, '''') + isnull(dbo.AB_Project.Question20, ''''), 
    Question17 = isnull(dbo.AB_Project.Question21, '''') + isnull(dbo.AB_Project.Question22, '''') + isnull(dbo.AB_Project.Question23, '''') + isnull(dbo.AB_Project.Question24, ''''), 
    --dbo.AB_Project.Question18, 
    --dbo.AB_Project.Question19, 
    --dbo.AB_Project.Question20, 
    --dbo.AB_Project.Question21, 
    --dbo.AB_Project.Question22, 
    --dbo.AB_Project.Question23, 
    --dbo.AB_Project.Question24, 
    dbo.AB_Project.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) left OUTER JOIN
    dbo.AB_Project with (nolock) on dbo.AB_Project.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
    dbo.LU_Project Lookup115 with (nolock) on dbo.AB_Project.ProjectNumber = Lookup115.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1 Lookup120 with (nolock) on dbo.AB_Project.Question1 = Lookup120.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 Lookup121 with (nolock) on dbo.AB_Project.Question10 = Lookup121.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 Lookup122 with (nolock) on dbo.AB_Project.Question11 = Lookup122.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 Lookup123 with (nolock) on dbo.AB_Project.Question12 = Lookup123.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 Lookup124 with (nolock) on dbo.AB_Project.Question13 = Lookup124.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2 Lookup125 with (nolock) on dbo.AB_Project.Question2 = Lookup125.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3 Lookup126 with (nolock) on dbo.AB_Project.Question3 = Lookup126.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4 Lookup127 with (nolock) on dbo.AB_Project.Question4 = Lookup127.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5 Lookup128 with (nolock) on dbo.AB_Project.Question5 = Lookup128.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6 Lookup129 with (nolock) on dbo.AB_Project.Question6 = Lookup129.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7 Lookup130 with (nolock) on dbo.AB_Project.Question7 = Lookup130.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8 Lookup131 with (nolock) on dbo.AB_Project.Question8 = Lookup131.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9 Lookup132 with (nolock) on dbo.AB_Project.Question9 = Lookup132.Code
WHERE     (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)









' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_Providers_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[I10_Amcare_Providers_VR]
AS
SELECT     dbo.AB_Provider.ProviderArriveDate AS ProviderArrivedDate, dbo.AB_Provider.ProviderArriveTime AS ProviderArrivedTime, 
                      dbo.AB_Provider.ProviderCallDate AS ProviderCalledDate, dbo.AB_Provider.ProviderCallTime AS ProviderCalledTime, 
                      Lookup116.DisplayCode AS ProviderNumber, Lookup116.UserDescription AS ProviderNumberDesc, dbo.AB_Provider.ProviderOccurrence, 
                      dbo.AB_Provider.ProviderService, Lookup117.DisplayCode AS ProviderSpecialty, Lookup117.UserDescription AS ProviderSpecialtyDesc, 
                      dbo.AB_Provider.ProviderTotalTime, Lookup118.DisplayCode AS ProviderType, Lookup118.UserDescription AS ProviderTypeDesc, 
                      dbo.AB_Provider.AbstractID AS zzAbstractLink
FROM           
    dbo.AB_Abstract with (nolock) left OUTER JOIN
    dbo.AB_Provider with (nolock) ON dbo.AB_Provider.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
    dbo.LU_Provider Lookup116 with (nolock) ON dbo.AB_Provider.ProviderNumber = Lookup116.Code LEFT OUTER JOIN
    dbo.LU_ProviderSpecialty Lookup117 with (nolock) ON dbo.AB_Provider.ProviderSpecialty = Lookup117.Code LEFT OUTER JOIN
    dbo.LU_ProviderType Lookup118 with (nolock) ON dbo.AB_Provider.ProviderType = Lookup118.Code
WHERE     (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5) AND (dbo.AB_Provider.ProviderOccurrence IS NOT NULL)







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_statistic_Reporting]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE view [dbo].[I10_Amcare_statistic_Reporting]
as
select aa.InstitutionNumber, InstitutionNumbereDesc, aa.BatchYear, aa.BatchPeriod, 
	AmCareGroup, AmCareGroupDesc,
	TotalRecords = TotalSubmitted + TotalSubmitted_None,
	TotalSubmitted,
	TotalSubmitted_None,

	Total_Emergency, Total_Emergency_Submitted,
	Total_UCC, Total_UCC_Submitted,
	Total_ED_MentalHealth, Total_ED_MentalHealth_Submitted,

	Total_DaySurgical, Total_DaySurgical_Submitted,
	Total_Endoscopy, Total_Endoscopy_Submitted
	Total_Cystoscopy, Total_Cystoscopy_Submitted,
	
	Total_Clinic, Total_Clinic_Submitted,
	Total_CardiacCatheterization, Total_CardiacCatheterization_Submitted,
	Total_Oncology, Total_Oncology_Submitted,
	--Total_CancerCareOntario, TotalCancerCareOntario_Submitted,
	Total_RenalDialysis, Total_RenalDialysis_Submitted,
	Total_MentalHealth, Total_MentalHealth_Submitted,
	
	Total_Diagnostic, Total_Diagnostic_Submitted,

	Total_Other, Total_Other_Submitted,

	TotalPurged = isnull(p.TotalPurged, 0), 
	TotalPurgedCorrection = isnull(p.TotalPurgedCorrection, 0),
	TotalPurgedNoCorrection = isnull(p.TotalPurgedNoCorrection, 0)
from 
(select 
	InstitutionNumber = H_Institutionprofile.CIHIValue,
	InstitutionNumbereDesc = H_Institutionprofile.UserDescription,
	BatchYear = Datepart(year, admitdate) - (case when datepart(month, admitdate) in (1, 2, 3) then 1 else 0 end),
	BatchPeriod = right(''00'' + cast(datepart(month, admitdate) - (case when datepart(month, admitdate) in (1, 2, 3) then -9 else 3 end) as varchar(2)), 2),
	
	AmCareGroup = LU_MISCode.AmCareGroup, AmCareGroupDesc = LU_AmCareGroup.UserDescription,
	
	TotalSubmitted = sum(case when IsSubmited = 1 then 1 else 0 end),
	TotalSubmitted_None = sum(case when IsSubmited = 1 then 0 else 1 end),
	
	Total_Emergency = sum(case when LU_MISCode.AmCareTypeCode = ''10'' then 1 else 0 end),
	Total_Emergency_Submitted = sum(case when IsSubmited = 1 and LU_MISCode.AmCareTypeCode = ''10'' then 1 else 0 end),
	
	Total_UCC = sum(case when LU_MISCode.AmCareTypeCode = ''11'' then 1 else 0 end),
	Total_UCC_Submitted = sum(case when IsSubmited = 1 and LU_MISCode.AmCareTypeCode = ''11'' then 1 else 0 end),

	Total_ED_MentalHealth = sum(case when LU_MISCode.AmCareTypeCode = ''12'' then 1 else 0 end),
	Total_ED_MentalHealth_Submitted = sum(case when IsSubmited = 1 and LU_MISCode.AmCareTypeCode = ''12'' then 1 else 0 end),

	Total_DaySurgical = sum(case when LU_MISCode.AmCareTypeCode = ''20'' then 1 else 0 end),
	Total_DaySurgical_Submitted = sum(case when IsSubmited = 1 and LU_MISCode.AmCareTypeCode = ''20'' then 1 else 0 end),

	Total_Endoscopy = sum(case when LU_MISCode.AmCareTypeCode = ''21'' then 1 else 0 end),
	Total_Endoscopy_Submitted = sum(case when IsSubmited = 1 and LU_MISCode.AmCareTypeCode = ''21'' then 1 else 0 end),

	Total_Cystoscopy = sum(case when LU_MISCode.AmCareTypeCode = ''22'' then 1 else 0 end),
	Total_Cystoscopy_Submitted = sum(case when IsSubmited = 1 and LU_MISCode.AmCareTypeCode = ''22'' then 1 else 0 end),

	Total_Clinic = sum(case when LU_MISCode.AmCareTypeCode = ''30'' then 1 else 0 end),
	Total_Clinic_Submitted = sum(case when IsSubmited = 1 and LU_MISCode.AmCareTypeCode = ''30'' then 1 else 0 end),

	Total_CardiacCatheterization = sum(case when LU_MISCode.AmCareTypeCode = ''31'' then 1 else 0 end),
	Total_CardiacCatheterization_Submitted = sum(case when LU_MISCode.AmCareTypeCode = ''31'' and IsSubmited = 1 then 1 else 0 end),
	
	Total_Oncology = sum(case when LU_MISCode.AmCareTypeCode = ''32'' then 1 else 0 end),
	Total_Oncology_Submitted = sum(case when LU_MISCode.AmCareTypeCode = ''32'' and IsSubmited = 1 then 1 else 0 end),
	
	Total_CancerCareOntario= sum(case when H_Institutionprofile.CIHIValue like ''5%'' and CIHI_AbstractID >= 9000000 then 1 
									 else 0 end),
	Total_CancerCareOntario_Submitted = sum(case when H_Institutionprofile.CIHIValue like ''5%'' and CIHI_AbstractID >= 9000000 and IsSubmited = 1 then 1 
												else 0 end),

	Total_RenalDialysis = sum(case when LU_MISCode.AmCareTypeCode = ''33'' then 1 else 0 end),
	Total_RenalDialysis_Submitted = sum(case when LU_MISCode.AmCareTypeCode = ''33'' and IsSubmited = 1 then 1 else 0 end),

	Total_MentalHealth = sum(case when LU_MISCode.AmCareTypeCode = ''34'' then 1 else 0 end),
	Total_MentalHealth_Submitted = sum(case when LU_MISCode.AmCareTypeCode = ''34'' and IsSubmited = 1 then 1 else 0 end),

	Total_Diagnostic = sum(case when LU_MISCode.AmCareTypeCode = ''80'' then 1 else 0 end),
	Total_Diagnostic_Submitted = sum(case when LU_MISCode.AmCareTypeCode = ''80'' and IsSubmited = 1 then 1 else 0 end),

	Total_Other = sum(case when LU_MISCode.AmCareTypeCode = ''90'' then 1 else 0 end),
	Total_Other_Submitted = sum(case when LU_MISCode.AmCareTypeCode = ''90'' and IsSubmited = 1 then 1 else 0 end)

from AB_Abstract  with (nolock)
	inner join H_Institutionprofile with (nolock) on AB_Abstract.InstitutionNumber = H_Institutionprofile.code
	left  join LU_MISCode with (nolock) on LU_MISCode.Code = AB_Abstract.MISCode
	left  join LU_CodeFile LU_AmCareGroup with (nolock) on LU_MISCode.AmCareGroup = LU_AmCareGroup.CIHIValue and LU_AmCareGroup.LookupID = 1102
where AdmitDate >= ''2010/04/01'' and Caretype = 5 and ICDType = ''T''
group by H_Institutionprofile.CIHIValue, H_Institutionprofile.UserDescription, 
	Datepart(year, admitdate) - (case when datepart(month, admitdate) in (1, 2, 3) then 1 else 0 end),
	right(''00'' + cast(datepart(month, admitdate) - (case when datepart(month, admitdate) in (1, 2, 3) then -9 else 3 end) as varchar(2)), 2),
	LU_MISCode.AmCareGroup, LU_AmCareGroup.UserDescription
) aa
left join 
(select InstNumber as InstitutionNumber, BatchYear, BatchPeriod, 
	TotalPurged = count(*), 
	TotalPurgedCorrection = sum((case when IsSubmitted = ''Y'' and IsCorrected in (''R'', ''C'') then 1 else 0 end)),
	TotalPurgedNoCorrection = sum((case when IsSubmitted = ''Y'' and IsCorrected not in (''R'', ''C'') then 1 else 0 end))
 from dbo.REC_Purge with (nolock)
 where AppID = 401 
 group by InstNumber, BatchYear, BatchPeriod) P 
	on aa.InstitutionNumber = p.InstitutionNumber and aa.BatchYear = p.BatchYear and aa.BatchPeriod = p.BatchPeriod





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_statistic_Reporting_2009]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE view [dbo].[I10_Amcare_statistic_Reporting_2009]
as
select aa.InstitutionNumber, InstitutionNumbereDesc, aa.BatchYear, aa.BatchPeriod, 
	TotalRecords = TotalSubmitted + TotalSubmitted_None,
	TotalSubmitted,
	TotalSubmitted_None,
	TotalEmergency,
	TotalEmergency_Submitted,
	TotalDaySurgical,
	TotalDaySurgical_Submitted,
	TotalCardiacCatheterization,
	TotalCardiacCatheterization_Submitted,
	TotalOncology,
	TotalOncology_Submitted,
	TotalCancerCareOntario,
	TotalCancerCareOntario_Submitted,
	TotalRenalDialysis,
	TotalRenalDialysis_Submitted,
	TotalOthers = TotalSubmitted + TotalSubmitted_None - TotalEmergency - TotalDaySurgical
					- TotalCardiacCatheterization - TotalOncology - TotalCancerCareOntario
					- TotalRenalDialysis,
	TotalOthers_Submitted = TotalSubmitted - TotalEmergency_Submitted - TotalDaySurgical_Submitted
					- TotalCardiacCatheterization_Submitted - TotalOncology_Submitted 
					- TotalCancerCareOntario_Submitted - TotalRenalDialysis_Submitted,
	TotalPurged = isnull(p.TotalPurged, 0), 
	TotalPurgedCorrection = isnull(p.TotalPurgedCorrection, 0),
	TotalPurgedNoCorrection = isnull(p.TotalPurgedNoCorrection, 0)
from 
(select 
	InstitutionNumber = H_Institutionprofile.CIHIValue,
	InstitutionNumbereDesc = H_Institutionprofile.UserDescription,
	BatchYear = Datepart(year, admitdate) - (case when datepart(month, admitdate) in (1, 2, 3) then 1 else 0 end),
	BatchPeriod = right(''00'' + cast(datepart(month, admitdate) - (case when datepart(month, admitdate) in (1, 2, 3) then -9 else 3 end) as varchar(2)), 2),
	TotalSubmitted = sum(case when IsSubmited = 1 then 1 else 0 end),
	TotalSubmitted_None = sum(case when IsSubmited = 1 then 0 else 1 end),
	TotalEmergency = sum(case when LU_MISCode.CIHIValue like ''7_310%'' then 1 else 0 end),
	TotalEmergency_Submitted = sum(case when IsSubmited = 1 and LU_MISCode.CIHIValue like ''7_310%'' then 1 else 0 end),
	
	TotalDaySurgical = sum(case when LU_MISCode.CIHIValue like ''7_34055'' then 1 
								when LU_MISCode.CIHIValue like ''7_34025'' and AdmitDate < ''2009/04/01'' then 1 --For Abstract before 2009
								when LU_MISCode.CIHIValue like ''7_34020'' and AdmitDate < ''2009/04/01'' then 1 --For Abstract before 2009
								when LU_MISCode.CIHIValue like ''7_260%'' or 
									 LU_MISCode.CIHIValue like ''7_262%'' or
									 LU_MISCode.CIHIValue like ''7_265%'' or
									 LU_MISCode.CIHIValue like ''7_360%'' or
									 LU_MISCode.CIHIValue like ''7_362%'' or
									 LU_MISCode.CIHIValue like ''7_365%'' or
									 LU_MISCode.CIHIValue like ''7_369%'' or
									 LU_MISCode.CIHIValue like ''7_396%'' then 1
								else 0 end),

	TotalDaySurgical_Submitted = sum(case when IsSubmited = 1 then
						   (case when LU_MISCode.CIHIValue like ''7_34055'' then 1 
								when LU_MISCode.CIHIValue like ''7_34025'' and AdmitDate < ''2009/04/01'' then 1 --For Abstract before 2009
								when LU_MISCode.CIHIValue like ''7_34020'' and AdmitDate < ''2009/04/01'' then 1 --For Abstract before 2009
								when LU_MISCode.CIHIValue like ''7_260%'' or 
									 LU_MISCode.CIHIValue like ''7_262%'' or
									 LU_MISCode.CIHIValue like ''7_265%'' or
									 LU_MISCode.CIHIValue like ''7_360%'' or
									 LU_MISCode.CIHIValue like ''7_362%'' or
									 LU_MISCode.CIHIValue like ''7_365%'' or
									 LU_MISCode.CIHIValue like ''7_369%'' or
									 LU_MISCode.CIHIValue like ''7_396%'' then 1
								else 0 end)
							else 0 end),

	TotalCardiacCatheterization = sum(case when LU_MISCode.CIHIValue like ''7_41544%'' then 1 else 0 end),
	TotalCardiacCatheterization_Submitted = sum(case when LU_MISCode.CIHIValue like ''7_41544%'' and IsSubmited = 1 then 1 else 0 end),
	
	TotalOncology = sum(case when LU_MISCode.CIHIValue like ''7_34066%'' then 1 
							 when LU_MISCode.CIHIValue like ''7_466%'' then 1 
							 else 0 end),
	TotalOncology_Submitted = sum(case when LU_MISCode.CIHIValue like ''7_34066%'' and IsSubmited = 1 then 1 
									   when LU_MISCode.CIHIValue like ''7_466%''  and IsSubmited = 1 then 1 
									   else 0 end),
	TotalCancerCareOntario= sum(case when H_Institutionprofile.CIHIValue like ''5%'' and CIHI_AbstractID >= 9000000 then 1 
									 else 0 end),
	TotalCancerCareOntario_Submitted = sum(case when H_Institutionprofile.CIHIValue like ''5%'' and CIHI_AbstractID >= 9000000 and IsSubmited = 1 then 1 
												else 0 end),
	TotalRenalDialysis = sum(case when LU_MISCode.CIHIValue like ''7_34086%'' then 1 
						 		  when LU_MISCode.CIHIValue like ''7_53086%'' then 1 
								  else 0 end),
	TotalRenalDialysis_Submitted = sum(case when LU_MISCode.CIHIValue like ''7_34086%'' and IsSubmited = 1 then 1 
						 					when LU_MISCode.CIHIValue like ''7_53086%'' and IsSubmited = 1 then 1 
											else 0 end)
from AB_Abstract  with (nolock)
	inner join H_Institutionprofile with (nolock) on AB_Abstract.InstitutionNumber = H_Institutionprofile.code
	left join LU_MISCode with (nolock) on AB_Abstract.MISCode = LU_MISCode.Code
where AdmitDate <= ''2010/03/31'' and Caretype = 5 and ICDType = ''T''
group by H_Institutionprofile.CIHIValue, H_Institutionprofile.UserDescription, 
	Datepart(year, admitdate) - (case when datepart(month, admitdate) in (1, 2, 3) then 1 else 0 end),
	right(''00'' + cast(datepart(month, admitdate) - (case when datepart(month, admitdate) in (1, 2, 3) then -9 else 3 end) as varchar(2)), 2)
) aa
left join 
(select InstNumber as InstitutionNumber, BatchYear, BatchPeriod, 
	TotalPurged = count(*), 
	TotalPurgedCorrection = sum((case when IsSubmitted = ''Y'' and IsCorrected in (''R'', ''C'') then 1 else 0 end)),
	TotalPurgedNoCorrection = sum((case when IsSubmitted = ''Y'' and IsCorrected not in (''R'', ''C'') then 1 else 0 end))
 from dbo.REC_Purge with (nolock)
 where AppID = 401 
 group by InstNumber, BatchYear, BatchPeriod) P 
	on aa.InstitutionNumber = p.InstitutionNumber and aa.BatchYear = p.BatchYear and aa.BatchPeriod = p.BatchPeriod




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_statistic_Reporting_BC]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE view [dbo].[I10_Amcare_statistic_Reporting_BC]
as
select aa.InstitutionNumber, InstitutionNumbereDesc, aa.BatchYear, aa.BatchPeriod, 
	AmCareGroup, AmCareGroupDesc,
	TotalRecords = TotalSubmitted + TotalSubmitted_None,
	TotalSubmitted,
	TotalSubmitted_None,

	Total_Emergency, Total_Emergency_Submitted,
	Total_UCC, Total_UCC_Submitted,
	Total_ED_MentalHealth, Total_ED_MentalHealth_Submitted,

	Total_DaySurgical, Total_DaySurgical_Submitted,
	Total_Endoscopy, Total_Endoscopy_Submitted
	Total_Cystoscopy, Total_Cystoscopy_Submitted,
	
	Total_Clinic, Total_Clinic_Submitted,
	Total_CardiacCatheterization, Total_CardiacCatheterization_Submitted,
	Total_Oncology, Total_Oncology_Submitted,
	--Total_CancerCareOntario, TotalCancerCareOntario_Submitted,
	Total_RenalDialysis, Total_RenalDialysis_Submitted,
	Total_MentalHealth, Total_MentalHealth_Submitted,
	
	Total_Diagnostic, Total_Diagnostic_Submitted,

	Total_Other, Total_Other_Submitted,

	TotalPurged = isnull(p.TotalPurged, 0), 
	TotalPurgedCorrection = isnull(p.TotalPurgedCorrection, 0),
	TotalPurgedNoCorrection = isnull(p.TotalPurgedNoCorrection, 0)
from 
(select 
	InstitutionNumber = H_Institutionprofile.CIHIValue,
	InstitutionNumbereDesc = H_Institutionprofile.UserDescription,
	BatchYear = Datepart(year, admitdate) - (case when datepart(month, admitdate) in (1, 2, 3) then 1 else 0 end),
	BatchPeriod = lu_BatchPeriod.CIHIValue,
	
	AmCareGroup = LU_MISCode.AmCareGroup, AmCareGroupDesc = LU_AmCareGroup.UserDescription,
	
	TotalSubmitted = sum(case when IsSubmited = 1 then 1 else 0 end),
	TotalSubmitted_None = sum(case when IsSubmited = 1 then 0 else 1 end),
	
	Total_Emergency = sum(case when LU_MISCode.AmCareTypeCode = ''10'' then 1 else 0 end),
	Total_Emergency_Submitted = sum(case when IsSubmited = 1 and LU_MISCode.AmCareTypeCode = ''10'' then 1 else 0 end),
	
	Total_UCC = sum(case when LU_MISCode.AmCareTypeCode = ''11'' then 1 else 0 end),
	Total_UCC_Submitted = sum(case when IsSubmited = 1 and LU_MISCode.AmCareTypeCode = ''11'' then 1 else 0 end),

	Total_ED_MentalHealth = sum(case when LU_MISCode.AmCareTypeCode = ''12'' then 1 else 0 end),
	Total_ED_MentalHealth_Submitted = sum(case when IsSubmited = 1 and LU_MISCode.AmCareTypeCode = ''12'' then 1 else 0 end),

	Total_DaySurgical = sum(case when LU_MISCode.AmCareTypeCode = ''20'' then 1 else 0 end),
	Total_DaySurgical_Submitted = sum(case when IsSubmited = 1 and LU_MISCode.AmCareTypeCode = ''20'' then 1 else 0 end),

	Total_Endoscopy = sum(case when LU_MISCode.AmCareTypeCode = ''21'' then 1 else 0 end),
	Total_Endoscopy_Submitted = sum(case when IsSubmited = 1 and LU_MISCode.AmCareTypeCode = ''21'' then 1 else 0 end),

	Total_Cystoscopy = sum(case when LU_MISCode.AmCareTypeCode = ''22'' then 1 else 0 end),
	Total_Cystoscopy_Submitted = sum(case when IsSubmited = 1 and LU_MISCode.AmCareTypeCode = ''22'' then 1 else 0 end),

	Total_Clinic = sum(case when LU_MISCode.AmCareTypeCode = ''30'' then 1 else 0 end),
	Total_Clinic_Submitted = sum(case when IsSubmited = 1 and LU_MISCode.AmCareTypeCode = ''30'' then 1 else 0 end),

	Total_CardiacCatheterization = sum(case when LU_MISCode.AmCareTypeCode = ''31'' then 1 else 0 end),
	Total_CardiacCatheterization_Submitted = sum(case when LU_MISCode.AmCareTypeCode = ''31'' and IsSubmited = 1 then 1 else 0 end),
	
	Total_Oncology = sum(case when LU_MISCode.AmCareTypeCode = ''32'' then 1 else 0 end),
	Total_Oncology_Submitted = sum(case when LU_MISCode.AmCareTypeCode = ''32'' and IsSubmited = 1 then 1 else 0 end),
	
	Total_CancerCareOntario= sum(case when H_Institutionprofile.CIHIValue like ''5%'' and CIHI_AbstractID >= 9000000 then 1 
									 else 0 end),
	Total_CancerCareOntario_Submitted = sum(case when H_Institutionprofile.CIHIValue like ''5%'' and CIHI_AbstractID >= 9000000 and IsSubmited = 1 then 1 
												else 0 end),

	Total_RenalDialysis = sum(case when LU_MISCode.AmCareTypeCode = ''33'' then 1 else 0 end),
	Total_RenalDialysis_Submitted = sum(case when LU_MISCode.AmCareTypeCode = ''33'' and IsSubmited = 1 then 1 else 0 end),

	Total_MentalHealth = sum(case when LU_MISCode.AmCareTypeCode = ''34'' then 1 else 0 end),
	Total_MentalHealth_Submitted = sum(case when LU_MISCode.AmCareTypeCode = ''34'' and IsSubmited = 1 then 1 else 0 end),

	Total_Diagnostic = sum(case when LU_MISCode.AmCareTypeCode = ''80'' then 1 else 0 end),
	Total_Diagnostic_Submitted = sum(case when LU_MISCode.AmCareTypeCode = ''80'' and IsSubmited = 1 then 1 else 0 end),

	Total_Other = sum(case when LU_MISCode.AmCareTypeCode = ''90'' then 1 else 0 end),
	Total_Other_Submitted = sum(case when LU_MISCode.AmCareTypeCode = ''90'' and IsSubmited = 1 then 1 else 0 end)

from AB_Abstract  with (nolock)
	inner join H_Institutionprofile with (nolock) on AB_Abstract.InstitutionNumber = H_Institutionprofile.code
	inner join lu_BatchPeriod with (nolock) on AB_Abstract.AdmitDate between LU_BatchPeriod.CIHIDateFrom and LU_BatchPeriod.CIHIDateTo
	left  join LU_MISCode with (nolock) on LU_MISCode.Code = AB_Abstract.MISCode
	left  join LU_CodeFile LU_AmCareGroup with (nolock) on LU_MISCode.AmCareGroup = LU_AmCareGroup.CIHIValue and LU_AmCareGroup.LookupID = 1102
where AdmitDate >= ''2010/04/01'' and Caretype = 5 and ICDType = ''T''
group by H_Institutionprofile.CIHIValue, H_Institutionprofile.UserDescription, 
	Datepart(year, admitdate) - (case when datepart(month, admitdate) in (1, 2, 3) then 1 else 0 end),
	lu_BatchPeriod.CIHIValue,
	LU_MISCode.AmCareGroup, LU_AmCareGroup.UserDescription
) aa
left join 
(select InstNumber as InstitutionNumber, BatchYear, BatchPeriod, 
	TotalPurged = count(*), 
	TotalPurgedCorrection = sum((case when IsSubmitted = ''Y'' and IsCorrected in (''R'', ''C'') then 1 else 0 end)),
	TotalPurgedNoCorrection = sum((case when IsSubmitted = ''Y'' and IsCorrected not in (''R'', ''C'') then 1 else 0 end))
 from dbo.REC_Purge with (nolock)
 where AppID = 401 
 group by InstNumber, BatchYear, BatchPeriod) P 
	on aa.InstitutionNumber = p.InstitutionNumber and aa.BatchYear = p.BatchYear and aa.BatchPeriod = p.BatchPeriod




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_statistic_Reporting_BC_2009]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE view [dbo].[I10_Amcare_statistic_Reporting_BC_2009]
as 
select aa.InstitutionNumber, InstitutionNumbereDesc, aa.BatchYear, aa.BatchPeriod, 
	TotalRecords = TotalSubmitted + TotalSubmitted_None,
	TotalSubmitted,
	TotalSubmitted_None,
	TotalEmergency,
	TotalEmergency_Submitted,
	TotalDaySurgical,
	TotalDaySurgical_Submitted,
	TotalCardiacCatheterization,
	TotalCardiacCatheterization_Submitted,
	TotalOncology,
	TotalOncology_Submitted,
	TotalCancerCareOntario,
	TotalCancerCareOntario_Submitted,
	TotalRenalDialysis,
	TotalRenalDialysis_Submitted,
	TotalOthers = TotalSubmitted + TotalSubmitted_None - TotalEmergency - TotalDaySurgical
					- TotalCardiacCatheterization - TotalOncology - TotalCancerCareOntario
					- TotalRenalDialysis,
	TotalOthers_Submitted = TotalSubmitted - TotalEmergency_Submitted - TotalDaySurgical_Submitted
					- TotalCardiacCatheterization_Submitted - TotalOncology_Submitted 
					- TotalCancerCareOntario_Submitted - TotalRenalDialysis_Submitted,
	TotalPurged = isnull(p.TotalPurged, 0), 
	TotalPurgedCorrection = isnull(p.TotalPurgedCorrection, 0),
	TotalPurgedNoCorrection = isnull(p.TotalPurgedNoCorrection, 0)
from 
(select 
	InstitutionNumber = H_Institutionprofile.CIHIValue,
	InstitutionNumbereDesc = H_Institutionprofile.UserDescription,
	BatchYear = Datepart(year, admitdate) - (case when datepart(month, admitdate) in (1, 2, 3) then 1 else 0 end),
	BatchPeriod = lu_BatchPeriod.CIHIValue,
	TotalSubmitted = sum(case when IsSubmited = 1 then 1 else 0 end),
	TotalSubmitted_None = sum(case when IsSubmited = 1 then 0 else 1 end),
	TotalEmergency = sum(case when LU_MISCode.CIHIValue like ''7_310%'' then 1 else 0 end),
	TotalEmergency_Submitted = sum(case when IsSubmited = 1 and LU_MISCode.CIHIValue like ''7_310%'' then 1 else 0 end),
	
	TotalDaySurgical = sum(case when LU_MISCode.CIHIValue like ''7_34055'' then 1 
								when LU_MISCode.CIHIValue like ''7_34025'' and AdmitDate < ''2009/04/01'' then 1 --For Abstract before 2009
								when LU_MISCode.CIHIValue like ''7_34020'' and AdmitDate < ''2009/04/01'' then 1 --For Abstract before 2009
								when LU_MISCode.CIHIValue like ''7_260%'' or 
									 LU_MISCode.CIHIValue like ''7_262%'' or
									 LU_MISCode.CIHIValue like ''7_265%'' or
									 LU_MISCode.CIHIValue like ''7_360%'' or
									 LU_MISCode.CIHIValue like ''7_362%'' or
									 LU_MISCode.CIHIValue like ''7_365%'' or
									 LU_MISCode.CIHIValue like ''7_369%'' or
									 LU_MISCode.CIHIValue like ''7_396%'' then 1
								else 0 end),

	TotalDaySurgical_Submitted = sum(case when IsSubmited = 1 then
						   (case when LU_MISCode.CIHIValue like ''7_34055'' then 1 
								when LU_MISCode.CIHIValue like ''7_34025'' and AdmitDate < ''2009/04/01'' then 1 --For Abstract before 2009
								when LU_MISCode.CIHIValue like ''7_34020'' and AdmitDate < ''2009/04/01'' then 1 --For Abstract before 2009
								when LU_MISCode.CIHIValue like ''7_260%'' or 
									 LU_MISCode.CIHIValue like ''7_262%'' or
									 LU_MISCode.CIHIValue like ''7_265%'' or
									 LU_MISCode.CIHIValue like ''7_360%'' or
									 LU_MISCode.CIHIValue like ''7_362%'' or
									 LU_MISCode.CIHIValue like ''7_365%'' or
									 LU_MISCode.CIHIValue like ''7_369%'' or
									 LU_MISCode.CIHIValue like ''7_396%'' then 1
								else 0 end)
							else 0 end),

	TotalCardiacCatheterization = sum(case when LU_MISCode.CIHIValue like ''7_41544%'' then 1 else 0 end),
	TotalCardiacCatheterization_Submitted = sum(case when LU_MISCode.CIHIValue like ''7_41544%'' and IsSubmited = 1 then 1 else 0 end),
	
	TotalOncology = sum(case when LU_MISCode.CIHIValue like ''7_34066%'' then 1 
							 when LU_MISCode.CIHIValue like ''7_466%'' then 1 
							 else 0 end),
	TotalOncology_Submitted = sum(case when LU_MISCode.CIHIValue like ''7_34066%'' and IsSubmited = 1 then 1 
									   when LU_MISCode.CIHIValue like ''7_466%''  and IsSubmited = 1 then 1 
									   else 0 end),
	TotalCancerCareOntario= sum(case when H_Institutionprofile.CIHIValue like ''5%'' and CIHI_AbstractID >= 9000000 then 1 
									 else 0 end),
	TotalCancerCareOntario_Submitted = sum(case when H_Institutionprofile.CIHIValue like ''5%'' and CIHI_AbstractID >= 9000000 and IsSubmited = 1 then 1 
												else 0 end),
	TotalRenalDialysis = sum(case when LU_MISCode.CIHIValue like ''7_34086%'' then 1 
						 		  when LU_MISCode.CIHIValue like ''7_53086%'' then 1 
								  else 0 end),
	TotalRenalDialysis_Submitted = sum(case when LU_MISCode.CIHIValue like ''7_34086%'' and IsSubmited = 1 then 1 
						 					when LU_MISCode.CIHIValue like ''7_53086%'' and IsSubmited = 1 then 1 
											else 0 end)
from AB_Abstract with (nolock) 
	inner join H_Institutionprofile with (nolock) on AB_Abstract.InstitutionNumber = H_Institutionprofile.code
	inner join lu_BatchPeriod with (nolock) on AB_Abstract.AdmitDate between LU_BatchPeriod.CIHIDateFrom and LU_BatchPeriod.CIHIDateTo
	left join LU_MISCode with (nolock) on AB_Abstract.MISCode = LU_MISCode.Code
where AdmitDate <=''2010/03/31'' and Caretype = 5 and ICDType = ''T''
group by H_Institutionprofile.CIHIValue, H_Institutionprofile.UserDescription, 
	Datepart(year, admitdate) - (case when datepart(month, admitdate) in (1, 2, 3) then 1 else 0 end),
	lu_BatchPeriod.CIHIValue
) aa
left join 
(select InstNumber as InstitutionNumber, BatchYear, BatchPeriod, 
	TotalPurged = count(*), 
	TotalPurgedCorrection = sum((case when IsSubmitted = ''Y'' and IsCorrected in (''R'', ''C'') then 1 else 0 end)),
	TotalPurgedNoCorrection = sum((case when IsSubmitted = ''Y'' and IsCorrected not in (''R'', ''C'') then 1 else 0 end))
 from dbo.REC_Purge with (nolock)
 where AppID = 401 
 group by InstNumber, BatchYear, BatchPeriod) P 
	on aa.InstitutionNumber = p.InstitutionNumber and aa.BatchYear = p.BatchYear and aa.BatchPeriod = p.BatchPeriod





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_Amcare_VR]
AS
SELECT
    dbo.AB_ReproductiveCare.PrevPreTermDelivery AS [#ofPreviousPreTermDeliveries], 
    dbo.AB_ReproductiveCare.PrevSpontAbortions AS [#ofPrevSpontaneousAbortions], 
    dbo.AB_ReproductiveCare.PrevTermDelivery AS [#ofPreviousTermDeliveries], 
    --ED - 01910
    LU_AccessPrimaryHealthCareCode.DisplayCode as AccessPrimaryHealthCareCode,  LU_AccessPrimaryHealthCareCode.UserDescription as AccessPrimaryHealthCareCodeDesc,
    AmbulanceArrDate as AmbulanceArrivalDate, AmbulanceArrTime as AmbulanceArrivalTime, 
    LU_AmbulanceArrTimeUnknown.DisplayCode as AmbulanceArrivalTimeUnknown,  LU_AmbulanceArrTimeUnknown.UserDescription as AmbulanceArrivalTimeUnknownDesc,
    AmbulanceTranDate as AmbulanceTransferCareDate, AmbulanceTranTime as AmbulanceTransferCareTime,
    LU_AmbulanceTranTimeUnknown.DisplayCode as AmbulanceTransferCareTimeUnknown,  LU_AmbulanceTranTimeUnknown.UserDescription as AmbulanceTransferCareTimeUnknownDesc,

    dbo.AB_ReproductiveCare.PrevInduceAbortions AS [#ofPrevTherapeuticAbortions], Lookup1.DisplayCode AS AWOL, 
    Lookup1.UserDescription AS AWOLDesc, dbo.AB_ReproductiveCare.AbortionDate AS AbortDate, dbo.AB_Abstract.AbstractNumber, 
    dbo.LU_AbstractOverflow.DisplayCode AS AbstractOverflow, dbo.LU_AbstractOverflow.UserDescription AS AbstractOverflowDesc, 
    dbo.AB_Abstract.InjuryActivityDescription AS ActivityDescription, Lookup2.DisplayCode AS ActivityWhenInjured, 
    Lookup2.UserDescription AS ActivityWhenInjuredDesc, dbo.AB_Abstract.AcuteLOS AS ActueLOS, Lookup3.DisplayCode AS AdmitbyAmbulance, 
    Lookup3.UserDescription AS AdmitbyAmbulanceDesc, dbo.AB_Abstract.AdmitCategory, 
    dbo.AB_Abstract.AdmittingDiagnosis AS AdmitDiagnosis, 
    LU_AdmitNurse.DisplayCode AS AdmitNursingArea, LU_AdmitNurse.UserDescription AS AdmitNursingAreaDesc, 
    dbo.AB_DeathInformation.DeathAfterAdmit AS AfterAdmit, 
    Lookup4.DisplayCode AS AgeCode, Lookup4.UserDescription AS AgeCodeDesc, dbo.AB_Abstract.AgeGroup, dbo.AB_Abstract.AgeNumber, 
    Lookup5.DisplayCode AS Albumin, Lookup5.UserDescription AS AlbuminDesc, Lookup6.DisplayCode AS AlbuminCrossMatched, 
    Lookup6.UserDescription AS AlbuminCrossMatchedDesc, Lookup7.DisplayCode AS AlbuminTyped, Lookup7.UserDescription AS AlbuminTypedDesc, 
    dbo.AB_Blood.AlbuminUnits, dbo.AB_Abstract.ALCLOS, 
    dbo.AB_Abstract.AmbulanceReportNumber, 
    --ED-02091 & ED - 02130
    isnull(LU_AmCareGroup.DisplayCode, LU_AmCareGroup_FromMISCode.DisplayCode) AS AmCareGroup, 
    isnull(LU_AmCareGroup.UserDescription, LU_AmCareGroup_FromMISCode.UserDescription) AS AmCareGroupDesc, 
    --PR - 03010
    LU_AmCareType.DisplayCode AS AmcareCareType, LU_AmCareType.UserDescription AS AmcareCareTypeDesc, 
    --ED-02091  & ED - 02130
    isnull(LU_AmCareTypeCode.DisplayCode, LU_AmCareTypeCode_FromMISCode.DisplayCode) AS AmcareTypeCode, 
    isnull(LU_AmCareTypeCode.UserDescription, LU_AmCareTypeCode_FromMISCode.UserDescription) AS AmcareTypeCodeDesc, 
    
    dbo.AB_Ancillary.AncillaryField13 AS Ancil13, 
    dbo.AB_Ancillary.AncillaryField14 AS Ancil14, dbo.AB_Ancillary.AncillaryField15 AS Ancil15, dbo.AB_Ancillary.AncillaryField16 AS Ancil16, 
    dbo.AB_Ancillary.AncillaryField17 AS Ancil17, Lookup8.DisplayCode AS AncillaryField1, Lookup8.UserDescription AS AncillaryField1Desc, 
    Lookup9.DisplayCode AS AncillaryField10, Lookup9.UserDescription AS AncillaryField10Desc, Lookup10.DisplayCode AS AncillaryField11, 
    Lookup10.UserDescription AS AncillaryField11Desc, Lookup11.DisplayCode AS AncillaryField12, Lookup11.UserDescription AS AncillaryField12Desc, 
    Lookup12.DisplayCode AS AncillaryField2, Lookup12.UserDescription AS AncillaryField2Desc, Lookup13.DisplayCode AS AncillaryField3, 
    Lookup13.UserDescription AS AncillaryField3Desc, Lookup14.DisplayCode AS AncillaryField4, Lookup14.UserDescription AS AncillaryField4Desc, 
    Lookup15.DisplayCode AS AncillaryField5, Lookup15.UserDescription AS AncillaryField5Desc, Lookup16.DisplayCode AS AncillaryField6, 
    Lookup16.UserDescription AS AncillaryField6Desc, Lookup17.DisplayCode AS AncillaryField7, Lookup17.UserDescription AS AncillaryField7Desc, 
    Lookup18.DisplayCode AS AncillaryField8, Lookup18.UserDescription AS AncillaryField8Desc, Lookup19.DisplayCode AS AncillaryField9, 
    Lookup19.UserDescription AS AncillaryField9Desc, dbo.AB_Abstract.ArrivalDate, Lookup22.DisplayCode AS ArrivalMode, 
    Lookup22.UserDescription AS ArrivalModeDesc, dbo.AB_Abstract.ArrivalTime, dbo.AB_Abstract.ArrivalTriageDifference AS ArrivaltoTriageTime, 
    dbo.AB_Abstract.AssessmentDate, dbo.AB_Abstract.AssessmentTime, Lookup159.DisplayCode AS AssessmentTimeUnknown, 
    Lookup159.UserDescription AS AssessmentTimeUnknownDesc, LU_AttendingPhysician.DisplayCode AS AttendingPhysician, 
    LU_AttendingPhysician.UserDescription AS AttendingPhysicianDesc, Lookup23.DisplayCode AS AutoTransfusion, 
    Lookup23.UserDescription AS AutoTransfusionDesc, Lookup24.DisplayCode AS AutopsyPerformed, 
    Lookup24.UserDescription AS AutopsyPerformedDesc, Lookup25.DisplayCode AS BasicOption1, Lookup25.UserDescription AS BasicOption1Desc, 
    Lookup26.DisplayCode AS BasicOption10, Lookup26.UserDescription AS BasicOption10Desc, Lookup27.DisplayCode AS BasicOption11, 
    Lookup27.UserDescription AS BasicOption11Desc, Lookup28.DisplayCode AS BasicOption12, Lookup28.UserDescription AS BasicOption12Desc, 
    Lookup29.DisplayCode AS BasicOption13, Lookup29.UserDescription AS BasicOption13Desc, Lookup30.DisplayCode AS BasicOption14, 
    Lookup30.UserDescription AS BasicOption14Desc, Lookup31.DisplayCode AS BasicOption15, Lookup31.UserDescription AS BasicOption15Desc, 
    Lookup32.DisplayCode AS BasicOption16, Lookup32.UserDescription AS BasicOption16Desc, Lookup33.DisplayCode AS BasicOption17, 
    Lookup33.UserDescription AS BasicOption17Desc, Lookup34.DisplayCode AS BasicOption18, Lookup34.UserDescription AS BasicOption18Desc, 
    Lookup35.DisplayCode AS BasicOption19, Lookup35.UserDescription AS BasicOption19Desc, Lookup36.DisplayCode AS BasicOption2, 
    Lookup36.UserDescription AS BasicOption2Desc, Lookup37.DisplayCode AS BasicOption3, Lookup37.UserDescription AS BasicOption3Desc, 
    Lookup38.DisplayCode AS BasicOption4, Lookup38.UserDescription AS BasicOption4Desc, Lookup39.DisplayCode AS BasicOption5, 
    Lookup39.UserDescription AS BasicOption5Desc, Lookup40.DisplayCode AS BasicOption6, Lookup40.UserDescription AS BasicOption6Desc, 
    Lookup41.DisplayCode AS BasicOption7, Lookup41.UserDescription AS BasicOption7Desc, Lookup42.DisplayCode AS BasicOption8, 
    Lookup42.UserDescription AS BasicOption8Desc, Lookup43.DisplayCode AS BasicOption9, Lookup43.UserDescription AS BasicOption9Desc, 
    dbo.AB_Abstract.BatchNumber, Lookup44.DisplayCode AS BatchPeriod, Lookup44.UserDescription AS BatchPeriodDesc, 
    --PR - 06087
    BatchPeriod_BC = (case when left(Lookup74.CIHIValue, 1) <> ''9'' then null
                           when Lookup44.DisplayCode is not null then Lookup44.DisplayCode 
                           when AdmitDate is null then null
                           else (select top 1 DisplayCode from LU_BatchPeriod where AdmitDate between CIHIDateFrom and CIHIDateTo)
                      end),
    dbo.AB_Abstract.BatchYear,     dbo.AB_Abstract.BirthDate, 
	
	LU_AntithrombinIII.DisplayCode AS Blood_AntithrombinIII, LU_AntithrombinIII.UserDescription AS Blood_AntithrombinIIIDesc,
	LU_C1Inhibitor.DisplayCode AS Blood_C1Inhibitor, LU_C1Inhibitor.UserDescription AS Blood_C1InhibitorDesc,
	LU_CryoprecipitatePlasma.DisplayCode AS Blood_CryoprecipitatePlasma, LU_CryoprecipitatePlasma.UserDescription AS Blood_CryoprecipitatePlasmaDesc,
	LU_CryosupernatantPlasma.DisplayCode AS Blood_CryosupernatantPlasma, LU_CryosupernatantPlasma.UserDescription AS Blood_CryosupernatantPlasmaDesc,
	LU_FEIBA.DisplayCode AS Blood_FEIBA, LU_FEIBA.UserDescription AS Blood_FEIBADesc,
	LU_Fibrinogen.DisplayCode AS Blood_Fibrinogen, LU_Fibrinogen.UserDescription AS Blood_FibrinogenDesc,
	LU_IVIG_SCIG.DisplayCode AS Blood_IVIG_SCIG, LU_IVIG_SCIG.UserDescription AS Blood_IVIG_SCIGDesc,
	LU_PCC.DisplayCode AS Blood_PCC, LU_PCC.UserDescription AS Blood_PCCDesc,
	LU_ProteinC_OtherFactors.DisplayCode AS Blood_ProteinC_OtherFactors, LU_ProteinC_OtherFactors.UserDescription AS Blood_ProteinC_OtherFactorsDesc,

	dbo.AB_ReproductiveCare.BreastFeeding, 
    --ED - 01910
    LU_CDUFlag.Displaycode as ClinicalDecisionUnitFlag,    LU_CDUFlag.UserDescription as ClinicalDecisionUnitFlagDesc,
    CDUArrivalDate as ClinicalDecisionUnitDateIn, CDUArrivalTime as ClinicalDecisionUnitTimeIn,
    LU_CDUInTimeUnknown.Displaycode as ClinicalDecisionUnitTimeInUnknown,    LU_CDUInTimeUnknown.UserDescription as ClinicalDecisionUnitTimeInUnknownDesc,
    CDUOutDate as ClinicalDecisionUnitDateOut, CDUOutTime as ClinicalDecisionUnitTimeOut,
    LU_CDUOutTimeUnknown.Displaycode as ClinicalDecisionUnitTimeOutUnknown,    LU_CDUOutTimeUnknown.UserDescription as ClinicalDecisionUnitTimeOutUnknownDesc,

    Lookup45.DisplayCode AS ChangeinLegalStatus, 
    Lookup45.UserDescription AS ChangeinLegalStatusDesc, dbo.AB_Abstract.ChartNumber, dbo.AB_Abstract.ChiefComplaint, 
    Lookup46.DisplayCode AS CoderNumber, Lookup46.UserDescription AS CoderNumberDesc, LUCompleteRecord.DisplayCode AS CompleteRecord, 
    LUCompleteRecord.UserDescription AS CompleteRecordDesc, LUComplication.DisplayCode AS Complication, 
    LUComplication.UserDescription AS ComplicationDesc, Lookup47.DisplayCode AS Complication1, Lookup47.UserDescription AS Complication1Desc, 
    Lookup48.DisplayCode AS Complication2, Lookup48.UserDescription AS Complication2Desc, Lookup49.DisplayCode AS Complication3, 
    Lookup49.UserDescription AS Complication3Desc, Lookup50.DisplayCode AS ContactMode, Lookup50.UserDescription AS ContactModeDesc, 
    Lookup51.DisplayCode AS CoronerCase, Lookup51.UserDescription AS CoronerCaseDesc, Lookup52.DisplayCode AS DataEntryCoder, 
    Lookup52.UserDescription AS DataEntryCoderDesc, dbo.AB_Abstract.DateLeftER, dbo.AB_ReproductiveCare.LastMensesDate AS DateofLastMenses, 
    dbo.AB_Abstract.DateReadyDischarge AS DateReadyforDisch, 

    dbo.AB_Abstract.CIHIDateSent AS DateSentToCIHI, 
    --NP - 00125
    dbo.AB_Abstract.CIHIDateSentLevel1 AS DateSentToCIHILevel1, 
    --ED - 02102
    dbo.AB_Abstract.CIHIDateSentLevel1 AS DateSentToCIHILevel2, 
    --2.x-0282
    dbo.AB_Abstract.CIHIDateSentLevel1 AS DateSentToCIHILite, 

    Lookup53.DisplayCode AS DeathInER,
    Lookup53.UserDescription AS DeathInERDesc, Lookup54.DisplayCode AS DeathOnArrival, Lookup54.UserDescription AS DeathOnArrivalDesc, 
    dbo.AB_Abstract.DecisionAdmitDifference, dbo.AB_Abstract.DecisionAdmitDate AS DecisiontoAdmitDate, 
    dbo.AB_Abstract.DecisionAdmitTime AS DecisiontoAdmitTime, Lookup158.DisplayCode AS DecisionAdmitTimeUnknown, 
    Lookup158.UserDescription AS DecisionAdmitTimeUnknownDesc, dbo.AB_ReproductiveCare.DeliveryDate, dbo.AB_ReproductiveCare.DeliveryTime, 
    Lookup58.DisplayCode AS DiedDuringIntervention, Lookup58.UserDescription AS DiedDuringInterventionDesc, 
    LU_DischargeNurse.DisplayCode AS DischNursingArea, LU_DischargeNurse.UserDescription AS DischNursingAreaDesc, 
    Lookup59.DisplayCode AS DischPlanning, 
    Lookup59.UserDescription AS DischPlanningDesc, dbo.AB_Abstract.DischargeAge, Lookup60.DisplayCode AS DischargeDisposition, 
    Lookup60.UserDescription AS DischargeDispositionDesc, dbo.AB_Abstract.DischargeDate AS DispositionDate, 
    dbo.AB_Abstract.DischargeTime AS DispositionTime, LUDischargeTimeUnknown.DisplayCode AS DispositionTimeUnknown, 
    LUDischargeTimeUnknown.UserDescription AS DispositionTimeUnknownDesc, Lookup61.DisplayCode AS ECTTreatment, 
    Lookup61.UserDescription AS ECTTreatmentDesc, Lookup64.DisplayCode AS Education, Lookup64.UserDescription AS EducationDesc, 
    --ED - 02289
    LU_EDVisitIndicator.DisplayCode AS EDVisitIndicator, LU_EDVisitIndicator.UserDescription AS EDVisitIndicatorDesc,
    
    Lookup65.DisplayCode AS Employment, Lookup65.UserDescription AS EmploymentDesc, dbo.AB_Abstract.EntryCode, 
    dbo.AB_Abstract.EstimatedDischargeDate AS EstimateDischDate, dbo.AB_Abstract.ExitCode, Lookup67.DisplayCode AS FamilyPhysicianFlag, 
    Lookup67.UserDescription AS FamilyPhysicianFlagDesc, Lookup68.DisplayCode AS FinancialSupport, 
    Lookup68.UserDescription AS FinancialSupportDesc, dbo.AB_Abstract.FinishDate, dbo.AB_Abstract.FinishTime, dbo.AB_Abstract.FirstName, 
    ISNULL(dbo.AB_Abstract.LastName, '' '') + '', '' + ISNULL(dbo.AB_Abstract.FirstName, '''') + '' '' + ISNULL(dbo.AB_Abstract.MiddleName, '''') AS FullName, 
    FixedChartNumber,
    Lookup69.DisplayCode AS Gender, Lookup69.UserDescription AS GenderDesc, dbo.AB_ReproductiveCare.GestationalAge AS GestationalAgeinweeks, 
    Lookup157.DisplayCode AS GlasgowScale, Lookup157.UserDescription AS GlasgowScaleDesc, 
    dbo.AB_DeathInformation.DeathGreaterTenPO AS GreaterTenPO, Lookup70.DisplayCode AS HCNProvince, 
    Lookup70.UserDescription AS HCNProvinceDesc, dbo.AB_Abstract.HCNVersion, dbo.AB_Abstract.HealthCareNumber, 
    LU_Hospital.DisplayCode AS Hospital, LU_Hospital.UserDescription AS HospitalDesc, 
    dbo.AB_Abstract.HospitalAccountRecord,
    LUHelmetIndicator.DisplayCode AS HelmetIndicator, 
    LUHelmetIndicator.UserDescription AS HelmetIndicatorDesc, dbo.AB_DeathInformation.DeathInSCU AS InSCU, Lookup71.DisplayCode AS InitialOR, 
    Lookup71.UserDescription AS InitialORDesc, dbo.AB_Abstract.InjuryDate, Lookup72.DisplayCode AS Injury, Lookup72.UserDescription AS InjuryDesc, 
    dbo.AB_Abstract.InputDate, dbo.AB_Abstract.InputTime, 
	
	Lookup73.DisplayCode AS InstitutionFrom, Lookup73.UserDescription AS InstitutionFromDesc, 
	LU_InstitutionFrom_Type.DisplayCode AS InstitutionFromType, LU_InstitutionFrom_Type.UserDescription AS InstitutionFromTypeDesc, 
    Lookup73.InstCareType AS InstFromCareType, Lookup73.HospitalType AS InstFromHospType, 
	
	Lookup74.DisplayCode AS InstitutionNumber, Lookup74.UserDescription AS InstitutionNumberDesc, 
	
	Lookup75.DisplayCode AS InstitutionTo, Lookup75.UserDescription AS InstitutionToDesc, 
	LU_InstitutionTo_Type.DisplayCode AS InstitutionToType, LU_InstitutionTo_Type.UserDescription AS InstitutionToTypeDesc, 
    Lookup75.InstCareType AS InstToCareType, Lookup75.HospitalType AS InstToHospType, dbo.AB_Abstract.InterfaceDate, 
    
	dbo.AB_Abstract.InterfaceTime, 

    Lookup83.DisplayCode AS IsAbstractCompleted, Lookup83.UserDescription AS IsAbstractCompletedDesc, 
    --NP - 00125
    LU_Level1_Completed.DisplayCode AS IsAbstractCompletedLevel1, LU_Level1_Completed.UserDescription AS IsAbstractCompletedLevel1Desc, 
    --ED - 02102
    LU_Level1_Completed.DisplayCode AS IsAbstractCompletedLevel2, LU_Level1_Completed.UserDescription AS IsAbstractCompletedLevel2Desc, 
    --2.x-0282
    LU_Level1_Completed.DisplayCode AS IsAbstractCompletedLite, LU_Level1_Completed.UserDescription AS IsAbstractCompletedLiteDesc, 

    Lookup84.DisplayCode AS IsAbstractCorrected, Lookup84.UserDescription AS IsAbstractCorrectedDesc, 
    --NP - 00125
    LU_Level1_Correction.DisplayCode AS IsAbstractCorrectedLevel1, LU_Level1_Correction.UserDescription AS IsAbstractCorrectedLevel1Desc, 
    --ED - 02102
    LU_Level1_Correction.DisplayCode AS IsAbstractCorrectedLevel2, LU_Level1_Correction.UserDescription AS IsAbstractCorrectedLevel2Desc, 
    --2.x-0282
    LU_Level1_Correction.DisplayCode AS IsAbstractCorrectedLite, LU_Level1_Correction.UserDescription AS IsAbstractCorrectedLiteDesc, 

    Lookup85.DisplayCode AS IsAbstractDeleted,   Lookup85.UserDescription AS IsAbstractDeletedDesc, 

    Lookup86.DisplayCode AS IsAbstractSubmitted, Lookup86.UserDescription AS IsAbstractSubmittedDesc,
    --NP - 00125 
    LU_Level1_Submission.DisplayCode AS IsAbstractSubmittedLevel1, LU_Level1_Submission.UserDescription AS IsAbstractSubmittedLevel1Desc, 
    --ED - 02102 
    LU_Level1_Submission.DisplayCode AS IsAbstractSubmittedLevel2, LU_Level1_Submission.UserDescription AS IsAbstractSubmittedLevel2Desc, 
    --2.x-0282
    LU_Level1_Submission.DisplayCode AS IsAbstractSubmittedLite, LU_Level1_Submission.UserDescription AS IsAbstractSubmittedLiteDesc, 

    Lookup87.DisplayCode AS IsAbstractValidated, Lookup87.UserDescription AS IsAbstractValidatedDesc, 
    --NP - 00125 
    LU_Level1_Validation.DisplayCode AS IsAbstractValidatedLevel1, LU_Level1_Validation.UserDescription AS IsAbstractValidatedLevel1Desc, 
    --ED - 02102 
    LU_Level1_Validation.DisplayCode AS IsAbstractValidatedLevel2, LU_Level1_Validation.UserDescription AS IsAbstractValidatedLevel2Desc, 
    --2.x-0282
    LU_Level1_Validation.DisplayCode AS IsAbstractValidatedLite, LU_Level1_Validation.UserDescription AS IsAbstractValidatedLiteDesc, 

    Lookup88.DisplayCode AS IsBirthdateEstimated,     Lookup88.UserDescription AS IsBirthdateEstimatedDesc, 
	LU_IsCustomValidated.DisplayCode AS IsCustomValidated, LU_IsCustomValidated.UserDescription AS IsCustomValidatedDesc, 
	
	dbo.AB_Abstract.LOSDays, dbo.AB_Abstract.LOSTotal AS LOSTime, 
    dbo.AB_Abstract.LOSTime AS LOSTimeinHours, dbo.AB_Abstract.LOSMinutes AS LOSTotalMinutes, Lookup89.DisplayCode AS [Language], 
    Lookup89.UserDescription AS LanguageDesc, dbo.AB_Abstract.LastName, dbo.AB_DeathInformation.DeathLessTwoPO AS LessTwoPO, 
    Lookup90.DisplayCode AS LivingArrangement, Lookup90.UserDescription AS LivingArrangementDesc, Lookup91.DisplayCode AS LocationofInjury, 
    Lookup91.UserDescription AS LocationofInjuryDesc, Lookup93.DisplayCode AS MISCode, Lookup93.UserDescription AS MISCodeDesc, 
    dbo.AB_Abstract.MaidenName, Lookup94.DisplayCode AS MaritalStatus, Lookup94.UserDescription AS MaritalStatusDesc, 

	LU_MentalLegalStatusUponArrivalED.DisplayCode as MentalHealth_LegalStatusUponArrivaltoED, 
	LU_MentalLegalStatusUponArrivalED.UserDescription as MentalHealth_LegalStatusUponArrivaltoEDDesc,
	--LU_MentalLegalStatusAdmission.DisplayCode as MentalHealth_LegalStatusAtAdmission, 
	--LU_MentalLegalStatusAdmission.UserDescription as MentalHealth_LegalStatusAtAdmissionDesc,
	LU_MentalTypeRestraint_1.DisplayCode as MentalHealth_TypeOfRestraint_01,
	LU_MentalTypeRestraint_1.UserDescription as MentalHealth_TypeOfRestraint_01Desc,
	LU_MentalTypeRestraint_2.DisplayCode as MentalHealth_TypeOfRestraint_02,
	LU_MentalTypeRestraint_2.UserDescription as MentalHealth_TypeOfRestraint_02Desc,
	LU_MentalTypeRestraint_3.DisplayCode as MentalHealth_TypeOfRestraint_03,
	LU_MentalTypeRestraint_3.UserDescription as MentalHealth_TypeOfRestraint_03Desc,
	LU_MentalTypeRestraint_4.DisplayCode as MentalHealth_TypeOfRestraint_04,
	LU_MentalTypeRestraint_4.UserDescription as MentalHealth_TypeOfRestraint_04Desc,
	LU_MentalFrequencyRestraintUse_1.DisplayCode as MentalHealth_FrequencyOfRestraint_01,
	LU_MentalFrequencyRestraintUse_1.UserDescription as MentalHealth_FrequencyOfRestraint_01Desc,
	LU_MentalFrequencyRestraintUse_2.DisplayCode as MentalHealth_FrequencyOfRestraint_02,
	LU_MentalFrequencyRestraintUse_2.UserDescription as MentalHealth_FrequencyOfRestraint_02Desc,
	LU_MentalFrequencyRestraintUse_3.DisplayCode as MentalHealth_FrequencyOfRestraint_03,
	LU_MentalFrequencyRestraintUse_3.UserDescription as MentalHealth_FrequencyOfRestraint_03Desc,
	LU_MentalFrequencyRestraintUse_4.DisplayCode as MentalHealth_FrequencyOfRestraint_04,
	LU_MentalFrequencyRestraintUse_4.UserDescription as MentalHealth_FrequencyOfRestraint_04Desc,


    Lookup95.DisplayCode AS MethodofAdmission, Lookup95.UserDescription AS MethodofAdmissionDesc, dbo.AB_Abstract.MiddleName, 

    LU_IsLiteSubmission.DisplayCode AS NACRSClinicLiteSubmission, LU_IsLiteSubmission.UserDescription AS NACRSClinicLiteSubmissionDesc, 
    
    dbo.AB_Abstract.NewbornChart, dbo.AB_Abstract.NewbornDischargeDate AS NewbornDischDate, 
    dbo.AB_Abstract.NextSchedVisitDate AS NextScheduledVisitDate, dbo.AB_Abstract.NextSchedVisitTime AS NextScheduledVisitTime, 
    --ED-02091 
	AB_NACRS.NonPhysicianAssessmentDate, AB_NACRS.NonPhysicianAssessmentTime, 
	LU_NonPhysicianAssessmentTimeUnknown.DisplayCode AS NonPhysicianAssessmentTimeUnknown, LU_NonPhysicianAssessmentTimeUnknown.UserDescription AS NonPhysicianAssessmentTimeUnknownDesc,
	LU_NonPhysicianNumber.DisplayCode AS NonPhysicianNumber, LU_NonPhysicianNumber.UserDescription AS NonPhysicianNumberDesc,
	LU_NonPhysicianService.DisplayCode AS NonPhysicianService, LU_NonPhysicianService.UserDescription AS NonPhysicianServiceDesc,
    
    dbo.AB_MentalHealth.MentalNumberECT AS NumberofECT, dbo.AB_Abstract.NurseAssessDate AS NursingAssessmentDate, 
    dbo.AB_Abstract.NurseAssessTime AS NursingAssessmentTime, Lookup98.DisplayCode AS Occupation, 
    Lookup98.UserDescription AS OccupationDesc, Lookup99.DisplayCode AS OtherMedicalDeath, Lookup99.UserDescription AS OtherMedicalDeathDesc, 
    Lookup100.DisplayCode AS OtherBlood, Lookup100.UserDescription AS OtherBloodDesc, Lookup101.DisplayCode AS OtherBloodCrossMatched, 
    Lookup101.UserDescription AS OtherBloodCrossMatchedDesc, Lookup102.DisplayCode AS OtherBloodTyped, 
    Lookup102.UserDescription AS OtherBloodTypedDesc, dbo.AB_Blood.OtherBloodUnits, Lookup148.DisplayCode AS PCTASIndicator, 
    Lookup148.UserDescription AS PCTASIndicatorDesc, dbo.AB_Abstract.PhysicianEstimatedLOS AS PhysicianEstLOS, 
    Lookup103.DisplayCode AS Plasma, Lookup103.UserDescription AS PlasmaDesc, Lookup104.DisplayCode AS PlasmaCrossMatched, 
    Lookup104.UserDescription AS PlasmaCrossMatchedDesc, Lookup105.DisplayCode AS PlasmaTyped, 
    Lookup105.UserDescription AS PlasmaTypedDesc, dbo.AB_Blood.PlasmaUnits, Lookup106.DisplayCode AS Platelets, 
    Lookup106.UserDescription AS PlateletsDesc, Lookup107.DisplayCode AS PlateletsCrossMatched, 
    Lookup107.UserDescription AS PlateletsCrossMatchedDesc, Lookup108.DisplayCode AS PlateletsTyped, 
    Lookup108.UserDescription AS PlateletsTypedDesc, dbo.AB_Blood.PlateletsUnits, dbo.AB_Abstract.PostalCode, 

    -- ED - 01682
    dbo.GetPostalDescription(isnull(dbo.AB_Abstract.PostalCode, ''''), dbo.AB_Abstract.AdmitDate) AS PostalCodeDesc, -- ED - 01682

    dbo.AB_Abstract.PostOpDays, dbo.AB_Abstract.PreOpDays, Lookup110.DisplayCode AS PreamditWorkUp, Lookup110.UserDescription AS PreamditWorkUpDesc, 
    Lookup111.DisplayCode AS Pregnancy, Lookup111.UserDescription AS PregnancyDesc, dbo.AB_ReproductiveCare.PrevLiveBirths AS PrevLiveBirth, 
    Lookup112.DisplayCode AS PreviousPsychiartricAdmissions, Lookup112.UserDescription AS PreviousPsychiartricAdmDesc, 
    Lookup113.DisplayCode AS Program, Lookup113.UserDescription AS ProgramDesc, Lookup118.DisplayCode AS ProvinceNumber, 
    Lookup118.UserDescription AS ProvinceNumberDesc, LUReasonForVisit.DisplayCode AS ReasonForVisit, 
    LUReasonForVisit.UserDescription AS ReasonForVisitDesc, dbo.AB_Abstract.ReAdmitCode, 
	--PR - 04577
	LU_ReciprocalBillingStatus.DisplayCode AS ReciprocalBillingStatus, LU_ReciprocalBillingStatus.UserDescription AS ReciprocalBillingStatusDesc,

    Lookup132.DisplayCode AS RedBloodCell, 
    Lookup132.UserDescription AS RedBloodCellDesc, Lookup133.DisplayCode AS RedBloodCellCrossMatched, 
    Lookup133.UserDescription AS RedBloodCellCrossMatchedDesc, Lookup134.DisplayCode AS RedBloodCellTyped, 
    Lookup134.UserDescription AS RedBloodCellTypedDesc, dbo.AB_Blood.RedCellUnits AS RedBloodCellUnits, dbo.AB_Abstract.ReferralDate, 
    Lookup135.DisplayCode AS ReferredFrom, Lookup135.UserDescription AS ReferredFromDesc, Lookup136.DisplayCode AS ReferredTo, 
    Lookup136.UserDescription AS ReferredToDesc, LU_RefProvider.DisplayCode AS ReferringProvider, 
    LU_RefProvider.UserDescription AS ReferringProviderDesc, dbo.AB_Abstract.RegisterNumber, 
    dbo.AB_Abstract.EncounterNumber AS RegistrationNumber, dbo.AB_Abstract.EncounterSequence AS RegistrationSequenceNumber, 
    dbo.AB_Abstract.AdmitDate AS RegistrationVisitDate, dbo.AB_Abstract.AdmitTime AS RegistrationVisitTime, 
    dbo.AB_ReproductiveCare.ReprodComments AS ReproductiveCareComments, dbo.AB_Abstract.Reserved AS ReserveField, 
    Lookup138.DisplayCode AS ResidenceCode, Lookup138.UserDescription AS ResidenceCodeDesc, 
    LUResidenceProvince.DisplayCode AS ResidenceProvince, LUResidenceProvince.UserDescription AS ResidenceProvinceDesc, 
    LUResidenceRegion.DisplayCode AS ResidenceRegion, LUResidenceRegion.UserDescription AS ResidenceRegionDesc, 
    Lookup139.DisplayCode AS ResidenceType, Lookup139.UserDescription AS ResidenceTypeDesc, 
    Lookup140.DisplayCode AS ResponsiblityForPayment, Lookup140.UserDescription AS ResponsiblityForPaymentDesc, 
    Lookup153.DisplayCode AS SchedEDVisit, Lookup153.UserDescription AS SchedEDVisitDesc, Lookup156.DisplayCode AS SeatbeltIndicator, 
    Lookup156.UserDescription AS SeatbeltIndicatorDesc, dbo.AB_Abstract.SecondChartRegNumber AS SecondChartRegisterNumber, 
    Lookup141.DisplayCode AS SecretVIPPatient, Lookup141.UserDescription AS SecretVIPPatientDesc, Lookup142.DisplayCode AS SiteNumber, 
    Lookup142.UserDescription AS SiteNumberDesc, Lookup143.DisplayCode AS SocialService, Lookup143.UserDescription AS SocialServiceDesc, 
    Lookup144.DisplayCode AS SourceofReferral, Lookup144.UserDescription AS SourceofReferralDesc, 
	--ED-02091
	LU_SpecialistNumber.DisplayCode AS SpecialistNumber, LU_SpecialistNumber.UserDescription AS SpecialistNumberDesc,
	AB_NACRS.SpecialistRequestDate, 
	LU_SpecialistService.DisplayCode AS SpecialistRequestService, LU_SpecialistService.UserDescription AS SpecialistRequestServiceDesc,
	AB_NACRS.SpecialistRequestTime, 
	LU_SpecialistRequestTimeUnknown.DisplayCode AS SpecialistRequestTimeUnknown, LU_SpecialistRequestTimeUnknown.UserDescription AS SpecialistRequestTimeUnknownDesc,
    
    LU_StakeholderType.DisplayCode AS StakeholderType, LU_StakeholderType.UserDescription AS StakeholderTypeDesc, 
    --ED - 02289
    LU_StatusAfterTriage.DisplayCode as StatusAfterTriage, LU_StatusAfterTriage.UserDescription as StatusAfterTriageDesc,
    
    Lookup145.DisplayCode AS Sterilization, Lookup145.UserDescription AS SterilizationDesc, 

    SubmissionLevel as SubmissionLevelCode, --ED - 01910
    AbstractNumber as SubmissionRecordID,

    Lookup146.DisplayCode AS SubsequentOR, 
    Lookup146.UserDescription AS SubsequentORDesc, Lookup147.DisplayCode AS Suicide, Lookup147.UserDescription AS SuicideDesc, 
    LUSurgicalCase.DisplayCode AS SurgicalCase, LUSurgicalCase.UserDescription AS SurgicalCaseDesc, dbo.AB_Abstract.TimeLeftER, 
    LU_TimeLeftERUnknown.DisplayCode AS TimeLeftERUnknown, LU_TimeLeftERUnknown.UserDescription AS TimeLeftERUnknownDEsc, 
    dbo.AB_Abstract.TransferOverloadDate, dbo.AB_Abstract.TransferOverloadTime, 
    dbo.AB_Abstract.TransferOverloadDifference AS TransferOverloadTimeDifference, Lookup149.DisplayCode AS TransfusionGiven, 
    Lookup149.UserDescription AS TransfusionGivenDesc, Lookup150.DisplayCode AS Trauma, Lookup150.UserDescription AS TraumaDesc, 
    dbo.AB_Abstract.TriageDate, Lookup151.DisplayCode AS TriageLevel, Lookup151.UserDescription AS TriageLevelDesc, dbo.AB_Abstract.TriageTime, 
    LU_TriageTimeUnknown.DisplayCode AS TriageTimeUnknown, LU_TriageTimeUnknown.UserDescription AS TriageTimeUnknownDesc, 
    Lookup152.DisplayCode AS TSICoder, Lookup152.UserDescription AS TSICoderDesc, dbo.AB_Abstract.TSIDate, dbo.AB_Abstract.TSITime, 
    dbo.AB_DeathInformation.DeathTwoTenPO AS TwoTenPO, dbo.AB_Abstract.UniqiueLifetimeID AS ULI, 
    dbo.AB_Abstract.UnplanReAdmit AS UnplannedReadmit, Lookup154.DisplayCode AS VisitStatus, Lookup154.UserDescription AS VisitStatusDesc, 
    Lookup155.DisplayCode AS VisitType, Lookup155.UserDescription AS VisitTypeDesc, 
	dbo.AB_Abstract.UniversalEpisodeIdentifier,
	dbo.AB_Abstract.WaitTimeER AS WaitTimeinER, 
    dbo.AB_Abstract.WaitAssessmentDifference AS WaittoAssessmentinMinutes, dbo.AB_Abstract.NurseAssessDiff AS WaittoNursingAssessmentDiff, 
    dbo.AB_Abstract.Weight, 
    dbo.AB_Abstract.AbstractID AS zzAbstractLink, 
    dbo.AB_Abstract.RegionalPatientID as zzRegionalPatientID, 
    dbo.AB_Abstract.VolumeID AS zzVolumeLink
FROM         
    dbo.AB_Abstract with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile LU_TriageTimeUnknown with (nolock) on dbo.AB_Abstract.TriageTimeUnknown = LU_TriageTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_Provider LU_RefProvider with (nolock) on dbo.AB_Abstract.RefPhysician = LU_RefProvider.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_TimeLeftERUnknown with (nolock) on dbo.AB_Abstract.TimeLeftERUnknown = LU_TimeLeftERUnknown.Code LEFT OUTER JOIN
    dbo.LU_Provider LU_AttendingPhysician with (nolock) on dbo.AB_Abstract.AttendingPhysician = LU_AttendingPhysician.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_StakeholderType with (nolock) on dbo.AB_Abstract.StakeHolder = LU_StakeholderType.Code LEFT OUTER JOIN
    dbo.H_HospitalProfile LU_Hospital with (nolock) on dbo.AB_Abstract.HospitalID = LU_Hospital.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LUCompleteRecord with (nolock) on dbo.AB_Abstract.CompleteRecord = LUCompleteRecord.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LUHelmetIndicator with (nolock) on dbo.AB_Abstract.HelmetIndicator = LUHelmetIndicator.Code LEFT OUTER JOIN
    dbo.LU_InjuryActivity Lookup2 with (nolock) on dbo.AB_Abstract.InjuryActivity = Lookup2.Code LEFT OUTER JOIN
    dbo.LU_AdmitAmbulance Lookup3 with (nolock) on dbo.AB_Abstract.AdmitAmbulance = Lookup3.Code LEFT OUTER JOIN
    dbo.LU_AgeCode Lookup4 with (nolock) on dbo.AB_Abstract.AgeCode = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_ArrivalMode Lookup22 with (nolock) on dbo.AB_Abstract.ArrivalMode = Lookup22.Code LEFT OUTER JOIN
    dbo.LU_BatchPeriod Lookup44 with (nolock) on dbo.AB_Abstract.BatchPeriod = Lookup44.Code LEFT OUTER JOIN
    dbo.U_Users Lookup46 with (nolock) on dbo.AB_Abstract.CoderNumber = Lookup46.Code LEFT OUTER JOIN
    dbo.LU_ContactMode Lookup50 with (nolock) on dbo.AB_Abstract.ContactMode = Lookup50.Code LEFT OUTER JOIN
    dbo.U_Users Lookup52 with (nolock) on dbo.AB_Abstract.DataEntryCoder = Lookup52.Code LEFT OUTER JOIN
    dbo.LU_TherDischPlan Lookup59 with (nolock) on dbo.AB_Abstract.DischargePlanning = Lookup59.Code LEFT OUTER JOIN
    dbo.LU_DispositionCode_A Lookup60 with (nolock) on dbo.AB_Abstract.DispositionCode = Lookup60.Code LEFT OUTER JOIN
    dbo.LU_Education Lookup64 with (nolock) on dbo.AB_Abstract.EducationLevel = Lookup64.Code LEFT OUTER JOIN
    dbo.LU_FamilyPhysician Lookup67 with (nolock) on dbo.AB_Abstract.FamilyPhysician = Lookup67.Code LEFT OUTER JOIN
    dbo.LU_Gender_I Lookup69 with (nolock) on dbo.AB_Abstract.Gender = Lookup69.Code LEFT OUTER JOIN
    dbo.LU_HCNProvince Lookup70 with (nolock) on dbo.AB_Abstract.HCNProvince = Lookup70.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup72 with (nolock) on dbo.AB_Abstract.Injury = Lookup72.Code LEFT OUTER JOIN
    
	dbo.LU_Institution_10 Lookup73 with (nolock) on dbo.AB_Abstract.InstitutionFrom = Lookup73.Code LEFT OUTER JOIN
	LU_Institution_TypeCode LU_InstitutionFrom_Type with (nolock) on dbo.AB_Abstract.InstitutionFromType = LU_InstitutionFrom_Type.Code LEFT OUTER JOIN
    dbo.H_InstitutionProfile Lookup74 with (nolock) on dbo.AB_Abstract.InstitutionNumber = Lookup74.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 Lookup75 with (nolock) on dbo.AB_Abstract.InstitutionTo = Lookup75.Code LEFT OUTER JOIN
	LU_Institution_TypeCode LU_InstitutionTo_Type with (nolock) on dbo.AB_Abstract.InstitutionToType = LU_InstitutionTo_Type.Code LEFT OUTER JOIN

    dbo.LU_AbstractStatus Lookup83 with (nolock) on dbo.AB_Abstract.IsCompleted = Lookup83.Code LEFT OUTER JOIN
    dbo.LU_CIHICorrect Lookup84 with (nolock) on dbo.AB_Abstract.IsCorrected = Lookup84.Code LEFT OUTER JOIN
    dbo.LU_DeleteStatus Lookup85 with (nolock) on dbo.AB_Abstract.IsDeleted = Lookup85.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem Lookup86 with (nolock) on dbo.AB_Abstract.IsSubmited = Lookup86.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus Lookup87 with (nolock) on dbo.AB_Abstract.IsValidated = Lookup87.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus LU_IsCustomValidated with (nolock) on dbo.AB_Abstract.IsCustomValidated = LU_IsCustomValidated.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup88 with (nolock) on dbo.AB_Abstract.BirthDateEstimated = Lookup88.Code LEFT OUTER JOIN
    dbo.LU_Language Lookup89 with (nolock) on dbo.AB_Abstract.LanguageCode = Lookup89.Code LEFT OUTER JOIN
    dbo.LU_LivingArrangement Lookup90 with (nolock) on dbo.AB_Abstract.LivingArrangement = Lookup90.Code LEFT OUTER JOIN
    dbo.LU_InjuryLocation Lookup91 with (nolock) on dbo.AB_Abstract.InjuryLocation = Lookup91.Code LEFT OUTER JOIN
    dbo.LU_MISCode Lookup93 with (nolock) on dbo.AB_Abstract.MISCode = Lookup93.Code LEFT OUTER JOIN
    
    --PR - 03012
    dbo.LU_CodeFile LU_AmCareType with (nolock) on Lookup93.AmCareType = LU_AmCareType.Code LEFT OUTER JOIN
    
    dbo.LU_MaritalStatus Lookup94 with (nolock) on dbo.AB_Abstract.MaritalStatus = Lookup94.Code LEFT OUTER JOIN
    dbo.LU_Occupation Lookup98 with (nolock) on dbo.AB_Abstract.Occupation = Lookup98.Code LEFT OUTER JOIN
    dbo.LU_TherPreAdmitWorkUp Lookup110 with (nolock) on dbo.AB_Abstract.PreAdmitWorkUp = Lookup110.Code LEFT OUTER JOIN
    dbo.LU_Program Lookup113 with (nolock) on dbo.AB_Abstract.Program = Lookup113.Code LEFT OUTER JOIN
    dbo.LU_Province Lookup118 with (nolock) on dbo.AB_Abstract.ProvinceNumber = Lookup118.Code LEFT OUTER JOIN
    dbo.LU_Referral Lookup135 with (nolock) on dbo.AB_Abstract.ReferredFrom = Lookup135.Code LEFT OUTER JOIN
    dbo.LU_Referral Lookup136 with (nolock) on dbo.AB_Abstract.ReferredTo = Lookup136.Code LEFT OUTER JOIN
    dbo.LU_ResidenceCode Lookup138 with (nolock) on dbo.AB_Abstract.ResidenceCode = Lookup138.Code LEFT OUTER JOIN
    dbo.LU_Region LUResidenceRegion with (nolock) on Lookup138.RegionCode = LUResidenceRegion.Code LEFT OUTER JOIN
    dbo.LU_Province LUResidenceProvince with (nolock) on Lookup138.ProvinceCode = LUResidenceProvince.Code LEFT OUTER JOIN
    dbo.LU_ResidenceType Lookup139 with (nolock) on dbo.AB_Abstract.ResidenceType = Lookup139.Code LEFT OUTER JOIN
    dbo.LU_RespPayment Lookup140 with (nolock) on dbo.AB_Abstract.ResponsiblePayment = Lookup140.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup141 with (nolock) on dbo.AB_Abstract.Secret = Lookup141.Code LEFT OUTER JOIN
    dbo.LU_Site Lookup142 with (nolock) on dbo.AB_Abstract.SiteNumber = Lookup142.Code LEFT OUTER JOIN
    dbo.LU_TherSocialService Lookup143 with (nolock) on dbo.AB_Abstract.SocialService = Lookup143.Code LEFT OUTER JOIN
    dbo.LU_TriageLevel Lookup151 with (nolock) on dbo.AB_Abstract.TriageLevel = Lookup151.Code LEFT OUTER JOIN
    dbo.U_Users Lookup152 with (nolock) on dbo.AB_Abstract.TSICoder = Lookup152.Code LEFT OUTER JOIN
    dbo.LU_VisitType Lookup154 with (nolock) on dbo.AB_Abstract.VisitStatus = Lookup154.Code LEFT OUTER JOIN
    dbo.LU_VisitType_10 Lookup155 with (nolock) on dbo.AB_Abstract.VisitType = Lookup155.Code LEFT OUTER JOIN
    dbo.AB_Ancillary with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Ancillary.AbstractID LEFT OUTER JOIN
    dbo.LU_Ancillary1 Lookup8 with (nolock) on dbo.AB_Ancillary.AncillaryField1 = Lookup8.Code LEFT OUTER JOIN
    dbo.LU_Ancillary10 Lookup9 with (nolock) on dbo.AB_Ancillary.AncillaryField10 = Lookup9.Code LEFT OUTER JOIN
    dbo.LU_Ancillary11 Lookup10 with (nolock) on dbo.AB_Ancillary.AncillaryField11 = Lookup10.Code LEFT OUTER JOIN
    dbo.LU_Ancillary12 Lookup11 with (nolock) on dbo.AB_Ancillary.AncillaryField12 = Lookup11.Code LEFT OUTER JOIN
    dbo.LU_Ancillary2 Lookup12 with (nolock) on dbo.AB_Ancillary.AncillaryField2 = Lookup12.Code LEFT OUTER JOIN
    dbo.LU_Ancillary3 Lookup13 with (nolock) on dbo.AB_Ancillary.AncillaryField3 = Lookup13.Code LEFT OUTER JOIN
    dbo.LU_Ancillary4 Lookup14 with (nolock) on dbo.AB_Ancillary.AncillaryField4 = Lookup14.Code LEFT OUTER JOIN
    dbo.LU_Ancillary5 Lookup15 with (nolock) on dbo.AB_Ancillary.AncillaryField5 = Lookup15.Code LEFT OUTER JOIN
    dbo.LU_Ancillary6 Lookup16 with (nolock) on dbo.AB_Ancillary.AncillaryField6 = Lookup16.Code LEFT OUTER JOIN
    dbo.LU_Ancillary7 Lookup17 with (nolock) on dbo.AB_Ancillary.AncillaryField7 = Lookup17.Code LEFT OUTER JOIN
    dbo.LU_Ancillary8 Lookup18 with (nolock) on dbo.AB_Ancillary.AncillaryField8 = Lookup18.Code LEFT OUTER JOIN
    dbo.LU_Ancillary9 Lookup19 with (nolock) on dbo.AB_Ancillary.AncillaryField9 = Lookup19.Code LEFT OUTER JOIN
    dbo.AB_BasicOption with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_BasicOption.AbstractID LEFT OUTER JOIN
    dbo.LU_BasicOption1 Lookup25 with (nolock) on dbo.AB_BasicOption.BasicOption1 = Lookup25.Code LEFT OUTER JOIN
    dbo.LU_BasicOption10 Lookup26 with (nolock) on dbo.AB_BasicOption.BasicOption10 = Lookup26.Code LEFT OUTER JOIN
    dbo.LU_BasicOption11 Lookup27 with (nolock) on dbo.AB_BasicOption.BasicOption11 = Lookup27.Code LEFT OUTER JOIN
    dbo.LU_BasicOption12 Lookup28 with (nolock) on dbo.AB_BasicOption.BasicOption12 = Lookup28.Code LEFT OUTER JOIN
    dbo.LU_BasicOption13 Lookup29 with (nolock) on dbo.AB_BasicOption.BasicOption13 = Lookup29.Code LEFT OUTER JOIN
    dbo.LU_BasicOption14 Lookup30 with (nolock) on dbo.AB_BasicOption.BasicOption14 = Lookup30.Code LEFT OUTER JOIN
    dbo.LU_BasicOption15 Lookup31 with (nolock) on dbo.AB_BasicOption.BasicOption15 = Lookup31.Code LEFT OUTER JOIN
    dbo.LU_BasicOption16 Lookup32 with (nolock) on dbo.AB_BasicOption.BasicOption16 = Lookup32.Code LEFT OUTER JOIN
    dbo.LU_BasicOption17 Lookup33 with (nolock) on dbo.AB_BasicOption.BasicOption17 = Lookup33.Code LEFT OUTER JOIN
    dbo.LU_BasicOption18 Lookup34 with (nolock) on dbo.AB_BasicOption.BasicOption18 = Lookup34.Code LEFT OUTER JOIN
    dbo.LU_BasicOption19 Lookup35 with (nolock) on dbo.AB_BasicOption.BasicOption19 = Lookup35.Code LEFT OUTER JOIN
    dbo.LU_BasicOption2 Lookup36 with (nolock) on dbo.AB_BasicOption.BasicOption2 = Lookup36.Code LEFT OUTER JOIN
    dbo.LU_BasicOption3 Lookup37 with (nolock) on dbo.AB_BasicOption.BasicOption3 = Lookup37.Code LEFT OUTER JOIN
    dbo.LU_BasicOption4 Lookup38 with (nolock) on dbo.AB_BasicOption.BasicOption4 = Lookup38.Code LEFT OUTER JOIN
    dbo.LU_BasicOption5 Lookup39 with (nolock) on dbo.AB_BasicOption.BasicOption5 = Lookup39.Code LEFT OUTER JOIN
    dbo.LU_BasicOption6 Lookup40 with (nolock) on dbo.AB_BasicOption.BasicOption6 = Lookup40.Code LEFT OUTER JOIN
    dbo.LU_BasicOption7 Lookup41 with (nolock) on dbo.AB_BasicOption.BasicOption7 = Lookup41.Code LEFT OUTER JOIN
    dbo.LU_BasicOption8 Lookup42 with (nolock) on dbo.AB_BasicOption.BasicOption8 = Lookup42.Code LEFT OUTER JOIN
    dbo.LU_BasicOption9 Lookup43 with (nolock) on dbo.AB_BasicOption.BasicOption9 = Lookup43.Code LEFT OUTER JOIN
    dbo.AB_Blood with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Blood.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup5 with (nolock) on dbo.AB_Blood.Albumin = Lookup5.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup6 with (nolock) on dbo.AB_Blood.AlbuminXMatch = Lookup6.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup7 with (nolock) on dbo.AB_Blood.AlbuminTyped = Lookup7.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup23 with (nolock) on dbo.AB_Blood.AutoTransfusion = Lookup23.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup100 with (nolock) on dbo.AB_Blood.OtherBlood = Lookup100.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup101 with (nolock) on dbo.AB_Blood.OtherBloodXMatch = Lookup101.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup102 with (nolock) on dbo.AB_Blood.OtherBloodTyped = Lookup102.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup103 with (nolock) on dbo.AB_Blood.Plasma = Lookup103.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup104 with (nolock) on dbo.AB_Blood.PlasmaXMatch = Lookup104.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup105 with (nolock) on dbo.AB_Blood.PlasmaTyped = Lookup105.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup106 with (nolock) on dbo.AB_Blood.Platelets = Lookup106.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup107 with (nolock) on dbo.AB_Blood.PlateletsXMatch = Lookup107.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup108 with (nolock) on dbo.AB_Blood.PlateletsTyped = Lookup108.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup132 with (nolock) on dbo.AB_Blood.RedBloodCell = Lookup132.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup133 with (nolock) on dbo.AB_Blood.RedCellXMatch = Lookup133.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup134 with (nolock) on dbo.AB_Blood.RedCellTyped = Lookup134.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup149 with (nolock) on dbo.AB_Blood.TransfusionIndicator = Lookup149.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_AntithrombinIII with (nolock) on dbo.AB_Blood.AntithrombinIII = LU_AntithrombinIII.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_C1Inhibitor with (nolock) on dbo.AB_Blood.C1Inhibitor = LU_C1Inhibitor.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_CryoprecipitatePlasma with (nolock) on dbo.AB_Blood.CryoprecipitatePlasma = LU_CryoprecipitatePlasma.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_CryosupernatantPlasma with (nolock) on dbo.AB_Blood.CryosupernatantPlasma = LU_CryosupernatantPlasma.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_FEIBA with (nolock) on dbo.AB_Blood.FEIBA = LU_FEIBA.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_Fibrinogen with (nolock) on dbo.AB_Blood.Fibrinogen = LU_Fibrinogen.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_IVIG_SCIG with (nolock) on dbo.AB_Blood.IVIG_SCIG = LU_IVIG_SCIG.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_PCC with (nolock) on dbo.AB_Blood.PCC = LU_PCC.Code LEFT OUTER JOIN
	dbo.LU_YesNoAlpha LU_ProteinC_OtherFactors with (nolock) on dbo.AB_Blood.ProteinC_OtherFactors = LU_ProteinC_OtherFactors.Code LEFT OUTER JOIN

    dbo.AB_DeathInformation with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_DeathInformation.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup24 with (nolock) on dbo.AB_DeathInformation.AutopsyPerformed = Lookup24.Code LEFT OUTER JOIN
    dbo.LU_CoronerCase Lookup51 with (nolock) on dbo.AB_DeathInformation.CoronerCase = Lookup51.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup53 with (nolock) on dbo.AB_DeathInformation.DeathInER = Lookup53.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup54 with (nolock) on dbo.AB_DeathInformation.DeathOnArrival = Lookup54.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup58 with (nolock) on dbo.AB_DeathInformation.DeathInOR = Lookup58.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup99 with (nolock) on dbo.AB_DeathInformation.OtherDeath = Lookup99.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup111 with (nolock) on dbo.AB_DeathInformation.PregnancyDeath = Lookup111.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup150 with (nolock) on dbo.AB_DeathInformation.TraumaDeath = Lookup150.Code LEFT OUTER JOIN
    dbo.AB_MentalHealth with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_MentalHealth.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup1 with (nolock) on dbo.AB_MentalHealth.MentalAWOL = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_MentalLegalStatus Lookup45 with (nolock) on dbo.AB_MentalHealth.MentalLegalStatus = Lookup45.Code LEFT OUTER JOIN
    dbo.LU_MentalECTTreat Lookup61 with (nolock) on dbo.AB_MentalHealth.MentalECTTreatment = Lookup61.Code LEFT OUTER JOIN
    dbo.LU_MentalEducation Lookup63 with (nolock) on dbo.AB_MentalHealth.MentalEducation = Lookup63.Code LEFT OUTER JOIN
    dbo.LU_MentalEmployment Lookup65 with (nolock) on dbo.AB_MentalHealth.MentalEmployment = Lookup65.Code LEFT OUTER JOIN
    dbo.LU_MentalFinancial Lookup68 with (nolock) on dbo.AB_MentalHealth.MentalFinancial = Lookup68.Code LEFT OUTER JOIN
    dbo.LU_MentalAdmitMethod Lookup95 with (nolock) on dbo.AB_MentalHealth.MentalAdmitMethod = Lookup95.Code LEFT OUTER JOIN
    dbo.LU_MentalPrevPsych Lookup112 with (nolock) on dbo.AB_MentalHealth.MentalPrevPsych = Lookup112.Code LEFT OUTER JOIN
    dbo.LU_MentalReferral Lookup137 with (nolock) on dbo.AB_MentalHealth.MentalReferralTo = Lookup137.Code LEFT OUTER JOIN
    dbo.LU_MentalReferral Lookup144 with (nolock) on dbo.AB_MentalHealth.MentalReferralSource = Lookup144.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup147 with (nolock) on dbo.AB_MentalHealth.MentalSuicide = Lookup147.Code LEFT OUTER JOIN
	dbo.LU_MentalLegalStatusUponArrivalED with (nolock) on dbo.AB_MentalHealth.LegalStatusUponArrivaltoED = LU_MentalLegalStatusUponArrivalED.Code LEFT OUTER JOIN
	--dbo.LU_MentalLegalStatusAdmission with (nolock) on dbo.AB_MentalHealth.LegalStatusAtAdmission = LU_MentalLegalStatusAdmission.Code LEFT OUTER JOIN
	dbo.LU_MentalTypeRestraint LU_MentalTypeRestraint_1 with (nolock) on dbo.AB_MentalHealth.TypeOfRestraint01 = LU_MentalTypeRestraint_1.Code LEFT OUTER JOIN
	dbo.LU_MentalFrequencyRestraintUse LU_MentalFrequencyRestraintUse_1 with (nolock) on dbo.AB_MentalHealth.FrequencyOfRestraint01 = LU_MentalFrequencyRestraintUse_1.Code LEFT OUTER JOIN
	dbo.LU_MentalTypeRestraint LU_MentalTypeRestraint_2 with (nolock) on dbo.AB_MentalHealth.TypeOfRestraint02 = LU_MentalTypeRestraint_2.Code LEFT OUTER JOIN
	dbo.LU_MentalFrequencyRestraintUse LU_MentalFrequencyRestraintUse_2 with (nolock) on dbo.AB_MentalHealth.FrequencyOfRestraint02 = LU_MentalFrequencyRestraintUse_2.Code LEFT OUTER JOIN
	dbo.LU_MentalTypeRestraint LU_MentalTypeRestraint_3 with (nolock) on dbo.AB_MentalHealth.TypeOfRestraint03 = LU_MentalTypeRestraint_3.Code LEFT OUTER JOIN
	dbo.LU_MentalFrequencyRestraintUse LU_MentalFrequencyRestraintUse_3 with (nolock) on dbo.AB_MentalHealth.FrequencyOfRestraint03 = LU_MentalFrequencyRestraintUse_3.Code LEFT OUTER JOIN
	dbo.LU_MentalTypeRestraint LU_MentalTypeRestraint_4 with (nolock) on dbo.AB_MentalHealth.TypeOfRestraint04 = LU_MentalTypeRestraint_4.Code LEFT OUTER JOIN
	dbo.LU_MentalFrequencyRestraintUse LU_MentalFrequencyRestraintUse_4 with (nolock) on dbo.AB_MentalHealth.FrequencyOfRestraint04 = LU_MentalFrequencyRestraintUse_4.Code LEFT OUTER JOIN


    dbo.AB_ReproductiveCare with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_ReproductiveCare.AbstractID LEFT OUTER JOIN
    dbo.LU_ReprodComplication Lookup47 with (nolock) on dbo.AB_ReproductiveCare.Complication1 = Lookup47.Code LEFT OUTER JOIN
    dbo.LU_ReprodComplication Lookup48 with (nolock) on dbo.AB_ReproductiveCare.Complication2 = Lookup48.Code LEFT OUTER JOIN
    dbo.LU_ReprodComplication Lookup49 with (nolock) on dbo.AB_ReproductiveCare.Complication3 = Lookup49.Code left join
    dbo.LU_ReprodOR Lookup71 with (nolock) on Lookup71.Code = dbo.AB_ReproductiveCare.InitialOR left join
    dbo.LU_YesBlank Lookup145 with (nolock) on Lookup145.Code = dbo.AB_ReproductiveCare.Sterilization LEFT OUTER JOIN
    dbo.LU_ReprodOR Lookup146 with (nolock) on dbo.AB_ReproductiveCare.SubsequentOR = Lookup146.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup148 with (nolock) on dbo.AB_Abstract.PCTASIndicator = Lookup148.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup153 with (nolock) on dbo.AB_Abstract.SchedEDVisit = Lookup153.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup156 with (nolock) on dbo.AB_Abstract.SeatbeltIndicator = Lookup156.Code AND Lookup156.LookupID = 2 LEFT OUTER JOIN
    dbo.LU_Glasgow Lookup157 with (nolock) on dbo.AB_Abstract.GlasgowComaScale = Lookup157.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup158 with (nolock) on dbo.AB_Abstract.DecisionAdmitTimeUnknown = Lookup158.Code AND Lookup158.LookupID = 1 LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup159 with (nolock) on dbo.AB_Abstract.AssessmentTimeUnknown = Lookup159.Code AND Lookup159.LookupID = 1 LEFT OUTER JOIN
    dbo.LU_AbstractOverflow with (nolock) on dbo.AB_Abstract.AbstractOverflow = dbo.LU_AbstractOverflow.Code LEFT OUTER JOIN
    dbo.LU_YesBlank LUSurgicalCase with (nolock) on dbo.AB_Abstract.SurgicalCase = LUSurgicalCase.Code LEFT OUTER JOIN
    dbo.LU_YesBlank LUComplication with (nolock) on dbo.AB_Abstract.Complication = LUComplication.Code LEFT OUTER JOIN
    dbo.ICD_DiagFile10 LUReasonForVisit with (nolock) on dbo.AB_Abstract.ReasonForVisit = LUReasonForVisit.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LUDischargeTimeUnknown with (nolock) on dbo.AB_Abstract.DischargeTimeUnknown = LUDischargeTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_NurseArea LU_AdmitNurse with (nolock) on dbo.AB_Abstract.AdmittingNurseArea = LU_AdmitNurse.Code LEFT OUTER JOIN
    dbo.LU_NurseArea LU_DischargeNurse with (nolock) on dbo.AB_Abstract.DischargeNurseArea = LU_DischargeNurse.Code LEFT OUTER JOIN
    --ED - 01910
    dbo.LU_CodeFile LU_AmbulanceArrTimeUnknown with (nolock) on dbo.AB_Abstract.AmbulanceArrTimeUnknown = LU_AmbulanceArrTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_AmbulanceTranTimeUnknown with (nolock) on dbo.AB_Abstract.AmbulanceTranTimeUnknown = LU_AmbulanceTranTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_AccessPrimaryHealthCareCode with (nolock) on dbo.AB_Abstract.AccessCareCode = dbo.LU_AccessPrimaryHealthCareCode.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_CDUFlag with (nolock) on dbo.AB_Abstract.CDUFlag = LU_CDUFlag.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CDUInTimeUnknown with (nolock) on dbo.AB_Abstract.CDUInTimeUnknown = LU_CDUInTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CDUOutTimeUnknown with (nolock) on dbo.AB_Abstract.CDUOutTimeUnknown = LU_CDUOutTimeUnknown.Code LEFT OUTER JOIN
    --NP - 00125
    dbo.LU_CIHICorrect LU_Level1_Correction with (nolock) on dbo.AB_Abstract.IsCorrectLevel1 = LU_Level1_Correction.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_Level1_Submission with (nolock) on dbo.AB_Abstract.IsSubmitLevel1 = LU_Level1_Submission.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus LU_Level1_Validation with (nolock) on dbo.AB_Abstract.IsValidLevel1 = LU_Level1_Validation.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus LU_Level1_Completed with (nolock) on dbo.AB_Abstract.IsCompleteLevel1 = LU_Level1_Completed.Code 
--PR - 04577
    LEFT OUTER JOIN dbo.LU_ReciprocalBillingStatus with (nolock) on dbo.AB_Abstract.IsReciprocalBilling = LU_ReciprocalBillingStatus.Code 
--ED-02091 
	left join dbo.AB_NACRS with (nolock) on AB_Abstract.AbstractID = AB_NACRS.AbstractID
	left join dbo.LU_Provider LU_SpecialistNumber with (nolock) on AB_NACRS.SpecialistNumber = LU_SpecialistNumber.Code
	left join dbo.LU_ProviderSpecialty LU_SpecialistService with (nolock) on AB_NACRS.SpecialistService = LU_SpecialistService.Code
	left join dbo.LU_CodeFile LU_SpecialistRequestTimeUnknown with (nolock) on AB_NACRS.SpecialistRequestTimeUnknown = LU_SpecialistRequestTimeUnknown.Code
	left join dbo.LU_Provider LU_NonPhysicianNumber with (nolock) on AB_NACRS.NonPhysicianNumber = LU_NonPhysicianNumber.Code
	left join dbo.LU_ProviderSpecialty LU_NonPhysicianService with (nolock) on AB_NACRS.NonPhysicianService = LU_NonPhysicianService.Code
	left join dbo.LU_CodeFile LU_NonPhysicianAssessmentTimeUnknown with (nolock) on AB_NACRS.NonPhysicianAssessmentTimeUnknown = LU_NonPhysicianAssessmentTimeUnknown.Code
	
	left join dbo.LU_CodeFile LU_AmCareTypeCode with (nolock) on AB_NACRS.AmCareTypeCode = LU_AmCareTypeCode.Code
	left join dbo.LU_CodeFile LU_AmCareGroup with (nolock) on AB_NACRS.AmCareGroup = LU_AmCareGroup.Code
	--ED - 02130
	left join dbo.LU_CodeFile LU_AmCareTypeCode_FromMISCode with (nolock) on Lookup93.AmCareTypeCode = LU_AmCareTypeCode_FromMISCode.CIHIValue and LU_AmCareTypeCode_FromMISCode.LookUpID = 1101 and LU_AmCareTypeCode_FromMISCode.code between 203501 and 203513
	left join dbo.LU_CodeFile LU_AmCareGroup_FromMISCode with (nolock) on Lookup93.AmCareGroup = LU_AmCareGroup_FromMISCode.CIHIValue and LU_AmCareGroup_FromMISCode.LookUPID = 1102 and LU_AmCareGroup_FromMISCode.code between 203601 and 203605
    
    --ED - 02298
    left join dbo.LU_YesNoSystem LU_EDVisitIndicator with (nolock) on dbo.AB_NACRS.EDVisitIndicator = LU_EDVisitIndicator.Code
    left join dbo.LU_StatusAfterTriage with (nolock) on dbo.AB_NACRS.StatusAfterTriage = LU_StatusAfterTriage.Code

    left join dbo.LU_YesNoSystem LU_IsLiteSubmission with (nolock) on dbo.AB_Abstract.IsLiteSubmission = LU_IsLiteSubmission.Code
WHERE     (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)
--QA - 00032 disable the domain securite issue
----PR - 07485
--    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB_ABstract.HospitalID is null or AB_ABstract.HospitalID = 0
--    --EN - 00666
--        or Is_Member(nullif(ReportGroup, '''')) = 1)
----        or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB_ABstract.HospitalID, 0))










' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AmcareCIHIErrors]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[I10_AmcareCIHIErrors]
AS
SELECT distinct
    dbo.AB_NACRS10_Errors.BatchPeriod, 
    dbo.AB_NACRS10_Errors.BatchYear, 
    dbo.M_AmcareErrors.ErrorDescription, 
    dbo.AB_NACRS10_Errors.ErrorFileName, 
    dbo.AB_NACRS10_Errors.ErrorID, 
    dbo.AB_NACRS10_Errors.ImportDateTime, 
    dbo.H_InstitutionProfile.DisplayCode AS InstitutionNumber, 
    dbo.H_InstitutionProfile.UserDescription AS InstitutionNumberDesc, 
    dbo.AB_NACRS10_Errors.AbstractID AS zzAbstractLink
FROM dbo.AB_NACRS10_Errors  with (nolock)
    join AB_Abstract with (nolock) on AB_Abstract.AbstractID = AB_NACRS10_Errors.AbstractID
        LEFT OUTER JOIN dbo.H_InstitutionProfile  with (nolock)
            ON dbo.AB_NACRS10_Errors.InstitutionNumber = dbo.H_InstitutionProfile.Code 
        LEFT OUTER JOIN dbo.M_AmcareErrors  with (nolock)
            ON ltrim(dbo.AB_NACRS10_Errors.ErrorID) = dbo.M_AmcareErrors.ErrorNumber
            and (case when AB_Abstract.BatchYear < 2004 then 2004 else AB_Abstract.BatchYear end) = M_AmcareErrors.BatchYear




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AmcareGeneral_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE  VIEW [dbo].[I10_AmcareGeneral_VR]
AS
SELECT     
    dbo.AB_Abstract.AbstractNumber, dbo.AB_Abstract.AbstractOverflow, 
    --PR - 04386
    LU_AccessPrimaryHealthCareCode.DisplayCode as AccessPrimaryHealthCareCode,  LU_AccessPrimaryHealthCareCode.UserDescription as AccessPrimaryHealthCareCodeDesc,
    AmbulanceArrDate as AmbulanceArrivalDate, AmbulanceArrTime as AmbulanceArrivalTime, 
    LU_AmbulanceArrTimeUnknown.DisplayCode as AmbulanceArrivalTimeUnknown,  LU_AmbulanceArrTimeUnknown.UserDescription as AmbulanceArrivalTimeUnknownDesc,
    AmbulanceTranDate as AmbulanceTransferCareDate, AmbulanceTranTime as AmbulanceTransferCareTime,
    LU_AmbulanceTranTimeUnknown.DisplayCode as AmbulanceTransferCareTimeUnknown,  LU_AmbulanceTranTimeUnknown.UserDescription as AmbulanceTransferCareTimeUnknownDesc,


    dbo.AB_Abstract.InjuryActivityDescription AS ActivityDescription, 
    Lookup2.DisplayCode AS ActivityWhenInjured, Lookup2.UserDescription AS ActivityWhenInjuredDesc, 
    -- dbo.AB_Abstract.AcuteLOS AS ActueLOS, PR - 03013
    Lookup3.DisplayCode AS AdmitbyAmbulance, Lookup3.UserDescription AS AdmitbyAmbulanceDesc, 
    -- dbo.AB_Abstract.AdmitCategory, PR - 03013
    -- dbo.AB_Abstract.AdmittingDiagnosis AS AdmitDiagnosis, 
    LU_AdmitNurse.DisplayCode AS AdmitNursingArea, LU_AdmitNurse.UserDescription AS AdmitNursingAreaDesc, 
    
    Lookup4.DisplayCode AS AgeCode, Lookup4.UserDescription AS AgeCodeDesc, 
    dbo.AB_Abstract.AgeGroup, dbo.AB_Abstract.AgeNumber, 
    -- dbo.AB_Abstract.ALCLOS,   PR - 03013
    dbo.AB_Abstract.AmbulanceReportNumber, 
    --PR - 05147 --ED-02091 & ED - 02130
    isnull(LU_AmCareGroup.DisplayCode, LU_AmCareGroup_FromMISCode.DisplayCode) AS AmCareGroup, 
    isnull(LU_AmCareGroup.UserDescription, LU_AmCareGroup_FromMISCode.UserDescription) AS AmCareGroupDesc, 
    --PR - 03012
    LU_AmCareType.DisplayCode AS AmcareCareType, LU_AmCareType.UserDescription AS AmcareCareTypeDesc, 
    --PR - 05147 --ED-02091  & ED - 02130
    isnull(LU_AmCareTypeCode.DisplayCode, LU_AmCareTypeCode_FromMISCode.DisplayCode) AS AmcareTypeCode, 
    isnull(LU_AmCareTypeCode.UserDescription, LU_AmCareTypeCode_FromMISCode.UserDescription) AS AmcareTypeCodeDesc, 

    dbo.AB_Abstract.ArrivalDate, Lookup22.DisplayCode AS ArrivalMode, 
    Lookup22.UserDescription AS ArrivalModeDesc, dbo.AB_Abstract.ArrivalTime, dbo.AB_Abstract.ArrivalTriageDifference AS ArrivaltoTriageTime, 
    dbo.AB_Abstract.AssessmentDate, dbo.AB_Abstract.AssessmentTime, Lookup159.DisplayCode AS AssessmentTimeUnknown, 
    Lookup159.UserDescription AS AssessmentTimeUnknownDesc, dbo.AB_Abstract.AttendingPhysician, dbo.AB_Abstract.BatchNumber, 
    Lookup44.DisplayCode AS BatchPeriod, Lookup44.UserDescription AS BatchPeriodDesc, dbo.AB_Abstract.BatchYear, dbo.AB_Abstract.BirthDate, 
    dbo.AB_Abstract.ChartNumber, dbo.AB_Abstract.ChiefComplaint, 
    --PR - 04386
    LU_CDUFlag.Displaycode as ClinicalDecisionUnitFlag,    LU_CDUFlag.UserDescription as ClinicalDecisionUnitFlagDesc,
    CDUArrivalDate as ClinicalDecisionUnitDateIn, CDUArrivalTime as ClinicalDecisionUnitTimeIn,
    LU_CDUInTimeUnknown.Displaycode as ClinicalDecisionUnitTimeInUnknown,    LU_CDUInTimeUnknown.UserDescription as ClinicalDecisionUnitTimeInUnknownDesc,
    CDUOutDate as ClinicalDecisionUnitDateOut, CDUOutTime as ClinicalDecisionUnitTimeOut,
    LU_CDUOutTimeUnknown.Displaycode as ClinicalDecisionUnitTimeOutUnknown,    LU_CDUOutTimeUnknown.UserDescription as ClinicalDecisionUnitTimeOutUnknownDesc,

    Lookup46.DisplayCode AS CoderNumber, 
    Lookup46.UserDescription AS CoderNumberDesc, LUCompleteRecord.DisplayCode AS CompleteRecord, 
    LUCompleteRecord.UserDescription AS CompleteRecordDesc, dbo.AB_Abstract.Complication, Lookup50.DisplayCode AS ContactMode, 
    Lookup50.UserDescription AS ContactModeDesc, Lookup52.DisplayCode AS DataEntryCoder, Lookup52.UserDescription AS DataEntryCoderDesc, 
    dbo.AB_Abstract.DateLeftER, dbo.AB_Abstract.DateReadyDischarge AS DateReadyforDisch, 

    dbo.AB_Abstract.CIHIDateSent AS DateSenttoCIHI, 
    --NP - 00125
    dbo.AB_Abstract.CIHIDateSentLevel1 AS DateSentToCIHILevel1, 
    --ED - 02102
    dbo.AB_Abstract.CIHIDateSentLevel1 AS DateSentToCIHILevel2, 
    --2.x-0282
    dbo.AB_Abstract.CIHIDateSentLevel1 AS DateSentToCIHILite, 

    dbo.AB_Abstract.DecisionAdmitDifference, dbo.AB_Abstract.DecisionAdmitDate AS DecisiontoAdmitDate, 
    dbo.AB_Abstract.DecisionAdmitTime AS DecisiontoAdmitTime, Lookup158.DisplayCode AS DecisionAdmitTimeUnknown, 
    Lookup158.UserDescription AS DecisionAdmitTimeUnknownDesc, 
    
    LU_DischargeNurse.DisplayCode AS DischNursingArea, LU_DischargeNurse.UserDescription AS DischNursingAreaDesc, 
    Lookup59.DisplayCode AS DischPlanning, Lookup59.UserDescription AS DischPlanningDesc, dbo.AB_Abstract.DischargeAge, 
    Lookup60.DisplayCode AS DischargeDisposition, Lookup60.UserDescription AS DischargeDispositionDesc, 
    dbo.AB_Abstract.DischargeDate AS DispositionDate, 
    dbo.AB_Abstract.DischargeTime AS DispositionTime, 
    -- PR - 01600
    LUDischargeTimeUnknown.DisplayCode as DispositionTimeUnknown, LUDischargeTimeUnknown.UserDescription as DispositionTimeUnknownDesc,
    
    Lookup64.DisplayCode AS Education, 
    Lookup64.UserDescription AS EducationDesc, 
    --ED - 02289
    LU_EDVisitIndicator.DisplayCode AS EDVisitIndicator, LU_EDVisitIndicator.UserDescription AS EDVisitIndicatorDesc,

    dbo.AB_Abstract.EncounterNumber, dbo.AB_Abstract.EncounterSequence,
    --dbo.AB_Abstract.EntryCode,  PR - 03013
    dbo.AB_Abstract.EstimatedDischargeDate AS EstimateDischDate, 
    --dbo.AB_Abstract.ExitCode, PR - 03013
    Lookup67.DisplayCode AS FamilyPhysicianFlag, Lookup67.UserDescription AS FamilyPhysicianFlagDesc, 
    dbo.AB_Abstract.FinishDate, dbo.AB_Abstract.FinishTime, dbo.AB_Abstract.FirstName, ISNULL(dbo.AB_Abstract.LastName, '' '') 
    + '', '' + ISNULL(dbo.AB_Abstract.FirstName, '''') + '' '' + ISNULL(dbo.AB_Abstract.MiddleName, '''') AS FullName, 
    FixedChartNumber,
    Lookup69.DisplayCode AS Gender, 
    Lookup69.UserDescription AS GenderDesc, Lookup157.DisplayCode AS GlasgowScale, Lookup157.UserDescription AS GlasgowScaleDesc, 
    Lookup70.DisplayCode AS HCNProvince, Lookup70.UserDescription AS HCNProvinceDesc, dbo.AB_Abstract.HCNVersion, 
    dbo.AB_Abstract.HealthCareNumber, LUHelmetIndicator.DisplayCode AS HelmetIndicator, LUHelmetIndicator.UserDescription AS HelmetIndicatorDesc, 
    LU_Hospital.DisplayCode AS Hospital, LU_Hospital.UserDescription AS HospitalDesc, 
    dbo.AB_Abstract.HospitalAccountRecord,
    dbo.AB_Abstract.ICDType, dbo.AB_Abstract.InjuryDate, Lookup72.DisplayCode AS Injury, 
	Lookup72.UserDescription AS InjuryDesc, dbo.AB_Abstract.InputDate, dbo.AB_Abstract.InputTime, 

	Lookup73.DisplayCode AS InstitutionFrom,     Lookup73.UserDescription AS InstitutionFromDesc, 
	LU_InstitutionFrom_Type.DisplayCode AS InstitutionFromType, LU_InstitutionFrom_Type.UserDescription AS InstitutionFromTypeDesc, 
	Lookup73.InstCareType AS InstFromCareType, Lookup73.HospitalType AS InstFromHospType, 
	LU_InstitutionTo_Type.DisplayCode AS InstitutionToType, LU_InstitutionTo_Type.UserDescription AS InstitutionToTypeDesc, 

    Lookup74.DisplayCode AS InstitutionNumber, Lookup74.UserDescription AS InstitutionNumberDesc, 
	
	Lookup75.DisplayCode AS InstitutionTo,     Lookup75.UserDescription AS InstitutionToDesc, 
	Lookup75.InstCareType AS InstToCareType, Lookup75.HospitalType AS InstToHospType, 
    
	dbo.AB_Abstract.InterfaceDate, dbo.AB_Abstract.InterfaceTime, 

    Lookup83.DisplayCode AS IsAbstractCompleted, Lookup83.UserDescription AS IsAbstractCompletedDesc, 
    --NP - 00125
    LU_Level1_Completed.DisplayCode AS IsAbstractCompletedLevel1, LU_Level1_Completed.UserDescription AS IsAbstractCompletedLevel1Desc, 
    --ED - 02102
    LU_Level1_Completed.DisplayCode AS IsAbstractCompletedLevel2, LU_Level1_Completed.UserDescription AS IsAbstractCompletedLevel2Desc, 
    --2.x-0282
    LU_Level1_Completed.DisplayCode AS IsAbstractCompletedLite, LU_Level1_Completed.UserDescription AS IsAbstractCompletedLiteDesc, 

    Lookup84.DisplayCode AS IsAbstractCorrected,     Lookup84.UserDescription AS IsAbstractCorrectedDesc, 
    --NP - 00125
    LU_Level1_Correction.DisplayCode AS IsAbstractCorrectedLevel1, LU_Level1_Correction.UserDescription AS IsAbstractCorrectedLevel1Desc, 
    --ED - 02102
    LU_Level1_Correction.DisplayCode AS IsAbstractCorrectedLevel2, LU_Level1_Correction.UserDescription AS IsAbstractCorrectedLevel2Desc, 
    --2.x-0282
    LU_Level1_Correction.DisplayCode AS IsAbstractCorrectedLite, LU_Level1_Correction.UserDescription AS IsAbstractCorrectedLiteDesc, 

    Lookup85.DisplayCode AS IsAbstractDeleted,     Lookup85.UserDescription AS IsAbstractDeletedDesc, 

    Lookup86.DisplayCode AS IsAbstractSubmitted,    Lookup86.UserDescription AS IsAbstractSubmittedDesc, 
    --NP - 00125 
    LU_Level1_Submission.DisplayCode AS IsAbstractSubmittedLevel1, LU_Level1_Submission.UserDescription AS IsAbstractSubmittedLevel1Desc, 
    --ED - 02102 
    LU_Level1_Submission.DisplayCode AS IsAbstractSubmittedLevel2, LU_Level1_Submission.UserDescription AS IsAbstractSubmittedLevel2Desc, 
    --2.x-0282
    LU_Level1_Submission.DisplayCode AS IsAbstractSubmittedLite, LU_Level1_Submission.UserDescription AS IsAbstractSubmittedLiteDesc, 

    Lookup87.DisplayCode AS IsAbstractValidated,    Lookup87.UserDescription AS IsAbstractValidatedDesc, 
    --NP - 00125 
    LU_Level1_Validation.DisplayCode AS IsAbstractValidatedLevel1, LU_Level1_Validation.UserDescription AS IsAbstractValidatedLevel1Desc, 
    --ED - 02102 
    LU_Level1_Validation.DisplayCode AS IsAbstractValidatedLevel2, LU_Level1_Validation.UserDescription AS IsAbstractValidatedLevel2Desc, 
    --2.x-0282
    LU_Level1_Validation.DisplayCode AS IsAbstractValidatedLite, LU_Level1_Validation.UserDescription AS IsAbstractValidatedLiteDesc, 

    Lookup88.DisplayCode AS IsBirthdateEstimated,     Lookup88.UserDescription AS IsBirthdateEstimatedDesc, 
	LU_CustomStatus.DisplayCode AS IsCustomValidated, LU_CustomStatus.UserDescription AS IsCustomValidatedDesc, 

	dbo.AB_Abstract.LOSDays, dbo.AB_Abstract.LOSTotal AS LOSTime, 
    dbo.AB_Abstract.LOSTime AS LOSTimeinHours, dbo.AB_Abstract.LOSMinutes AS LOSTotalMinutes, Lookup89.DisplayCode AS [Language], 
    Lookup89.UserDescription AS LanguageDesc, dbo.AB_Abstract.LastName, Lookup90.DisplayCode AS LivingArrangement, 
    Lookup90.UserDescription AS LivingArrangementDesc, Lookup91.DisplayCode AS LocationofInjury, 
    Lookup91.UserDescription AS LocationofInjuryDesc, 
    --PR - 03013
    LU_MainDiagnosis.DisplayCode as MainDiagnosisCode, LU_MainDiagnosis.UserDescription as MainDiagnosisCodeDesc,
    LU_MainDiagnosis.CIHIValue as MainDiagnosisCodeCIHI,

    LU_MainIntervention.DisplayCode as MainInterventionCode, LU_MainIntervention.UserDescription as MainInterventionCodeDesc,
    LU_MainIntervention.CIHIValue as MainInterventionCodeCIHI,

    LU_MainProvider.DisplayCode as MainProviderNumberCode, LU_MainProvider.UserDescription as MainProviderNumberDesc,
    LU_MainProviderSpecialty.DisplayCode as MainProviderSpecialty, LU_MainProviderSpecialty.UserDescription as MainProviderSpecialtyDesc,

    Lookup93.DisplayCode AS MISCode, Lookup93.UserDescription AS MISCodeDesc, 

    dbo.AB_Abstract.MaidenName, Lookup94.DisplayCode AS MaritalStatus, Lookup94.UserDescription AS MaritalStatusDesc, 
    dbo.AB_Abstract.MiddleName, 

    LU_IsLiteSubmission.DisplayCode AS NACRSClinicLiteSubmission, LU_IsLiteSubmission.UserDescription AS NACRSClinicLiteSubmissionDesc, 
    
    dbo.AB_Abstract.NewbornChart, dbo.AB_Abstract.NewbornDischargeDate AS NewbornDischDate, 
    dbo.AB_Abstract.NextSchedVisitDate AS NextScheduledVisitDate, dbo.AB_Abstract.NextSchedVisitTime AS NextScheduledVisitTime, 
    dbo.AB_Abstract.NurseAssessDate AS NursingAssessmentDate, dbo.AB_Abstract.NurseAssessTime AS NursingAssessmentTime, 
    Lookup98.DisplayCode AS Occupation, Lookup98.UserDescription AS OccupationDesc, Lookup148.DisplayCode AS PCTASIndicator, 
    Lookup148.UserDescription AS PCTASIndicatorDesc, dbo.AB_Abstract.PhysicianEstimatedLOS AS PhysicianEstLOS, dbo.AB_Abstract.PostalCode, 

    -- ED - 01682
    dbo.GetPostalDescription(isnull(dbo.AB_Abstract.PostalCode, ''''), dbo.AB_Abstract.AdmitDate) AS PostalDescription, -- ED - 01682

    dbo.AB_Abstract.PostOpDays, dbo.AB_Abstract.PreOpDays, Lookup110.DisplayCode AS PreamditWorkUp, 
    Lookup110.UserDescription AS PreamditWorkUpDesc, Lookup113.DisplayCode AS Program, Lookup113.UserDescription AS ProgramDesc, 
    Lookup118.DisplayCode AS ProvinceNumber, Lookup118.UserDescription AS ProvinceNumberDesc, 

    --PR - 03013
    LU_ReasonDiagnosis.DisplayCode as ReasonForVisitDxCode, LU_ReasonDiagnosis.UserDescription as ReasonForVisitDxCodeDesc,
    LU_ReasonDiagnosis.CIHIValue as ReasonForVisitDxCodeCIHI,

    dbo.AB_Abstract.ReAdmitCode, 
    --PR - 04577
    LU_ReciprocalBillingStatus.DisplayCode AS ReciprocalBillingStatus, LU_ReciprocalBillingStatus.UserDescription AS ReciprocalBillingStatusDesc,

    dbo.AB_Abstract.ReferralDate, Lookup135.DisplayCode AS ReferredFrom, Lookup135.UserDescription AS ReferredFromDesc, 
    Lookup136.DisplayCode AS ReferredTo, Lookup136.UserDescription AS ReferredToDesc, dbo.AB_Abstract.RegisterNumber, 
    dbo.AB_Abstract.EncounterNumber AS RegistrationNumber, dbo.AB_Abstract.EncounterSequence AS RegistrationSequenceNumber, 
    dbo.AB_Abstract.AdmitDate AS RegistrationVisitDate, dbo.AB_Abstract.AdmitTime AS RegistrationVisitTime, 
    dbo.AB_Abstract.Reserved AS ReserveField, Lookup138.DisplayCode AS ResidenceCode, Lookup138.UserDescription AS ResidenceCodeDesc, 
    Lookup139.DisplayCode AS ResidenceType, Lookup139.UserDescription AS ResidenceTypeDesc, 
    Lookup140.DisplayCode AS ResponsiblityForPayment, Lookup140.UserDescription AS ResponsiblityForPaymentDesc, 
    Lookup153.DisplayCode AS SchedEDVisit, Lookup153.UserDescription AS SchedEDVisitDesc, Lookup156.DisplayCode AS SeatbeltIndicator, 
    Lookup156.UserDescription AS SeatbeltIndicatorDesc, dbo.AB_Abstract.SecondChartRegNumber AS SecondChartRegisterNumber, 
    Lookup141.DisplayCode AS SecretVIPPatient, Lookup141.UserDescription AS SecretVIPPatientDesc, Lookup142.DisplayCode AS SiteNumber, 
    Lookup142.UserDescription AS SiteNumberDesc, Lookup143.DisplayCode AS SocialService, Lookup143.UserDescription AS SocialServiceDesc, 
    LU_StakeholderType.DisplayCode AS StakeholderType, LU_StakeholderType.UserDescription AS StakeholderTypeDesc, 
    --ED - 02289
    LU_StatusAfterTriage.DisplayCode as StatusAfterTriage, LU_StatusAfterTriage.UserDescription as StatusAfterTriageDesc,

    dbo.AB_Abstract.SurgicalCase, dbo.AB_Abstract.TimeLeftER, dbo.AB_Abstract.TransferOverloadDate, dbo.AB_Abstract.TransferOverloadTime, 
    dbo.AB_Abstract.TransferOverloadDifference AS TransferOverloadTimeDifference, dbo.AB_Abstract.TriageDate, 
    Lookup151.DisplayCode AS TriageLevel, Lookup151.UserDescription AS TriageLevelDesc, dbo.AB_Abstract.TriageTime, 
    Lookup152.DisplayCode AS TSICoder, Lookup152.UserDescription AS TSICoderDesc, dbo.AB_Abstract.TSIDate, dbo.AB_Abstract.TSITime, 
    dbo.AB_Abstract.UniqiueLifetimeID AS ULI, 
	AB_Abstract.UniversalEpisodeIdentifier,

	dbo.AB_Abstract.UnplanReAdmit AS UnplannedReadmit, Lookup154.DisplayCode AS VisitStatus, 
    Lookup154.UserDescription AS VisitStatusDesc, Lookup155.DisplayCode AS VisitType, Lookup155.UserDescription AS VisitTypeDesc, 
    -- dbo.AB_Abstract.WaitTimeER AS WaitTimeinER, PR - 03013

    dbo.AB_Abstract.WaitAssessmentDifference AS WaittoAssessmentinMinutes, 
    dbo.AB_Abstract.NurseAssessDiff AS WaittoNursingAssessmentDiff, dbo.AB_Abstract.Weight, 
    dbo.AB_Abstract.AbstractID AS zzAbstractLink, 
    dbo.AB_Abstract.RegionalPatientID as zzRegionalPatientID, 
    dbo.AB_Abstract.VolumeID AS zzVolumeLink
FROM         
    dbo.AB_Abstract with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile LU_StakeholderType with (nolock) on dbo.AB_Abstract.StakeHolder = LU_StakeholderType.Code LEFT OUTER JOIN
    dbo.H_HospitalProfile LU_Hospital with (nolock) on dbo.AB_Abstract.HospitalID = LU_Hospital.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LUCompleteRecord with (nolock) on dbo.AB_Abstract.CompleteRecord = LUCompleteRecord.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LUHelmetIndicator with (nolock) on dbo.AB_Abstract.HelmetIndicator = LUHelmetIndicator.Code LEFT OUTER JOIN
    dbo.LU_InjuryActivity Lookup2 with (nolock) on dbo.AB_Abstract.InjuryActivity = Lookup2.Code LEFT OUTER JOIN
    dbo.LU_AdmitAmbulance Lookup3 with (nolock) on dbo.AB_Abstract.AdmitAmbulance = Lookup3.Code LEFT OUTER JOIN
    dbo.LU_AgeCode Lookup4 with (nolock) on dbo.AB_Abstract.AgeCode = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_ArrivalMode Lookup22 with (nolock) on dbo.AB_Abstract.ArrivalMode = Lookup22.Code LEFT OUTER JOIN
    dbo.LU_BatchPeriod Lookup44 with (nolock) on dbo.AB_Abstract.BatchPeriod = Lookup44.Code LEFT OUTER JOIN

    dbo.U_Users Lookup46 with (nolock) on dbo.AB_Abstract.CoderNumber = Lookup46.Code LEFT OUTER JOIN
    dbo.LU_ContactMode Lookup50 with (nolock) on dbo.AB_Abstract.ContactMode = Lookup50.Code LEFT OUTER JOIN
    dbo.U_Users Lookup52 with (nolock) on dbo.AB_Abstract.DataEntryCoder = Lookup52.Code LEFT OUTER JOIN
    dbo.LU_TherDischPlan Lookup59 with (nolock) on dbo.AB_Abstract.DischargePlanning = Lookup59.Code LEFT OUTER JOIN
    dbo.LU_DispositionCode_A Lookup60 with (nolock) on dbo.AB_Abstract.DispositionCode = Lookup60.Code LEFT OUTER JOIN
    dbo.LU_Education Lookup64 with (nolock) on dbo.AB_Abstract.EducationLevel = Lookup64.Code LEFT OUTER JOIN
    dbo.LU_FamilyPhysician Lookup67 with (nolock) on dbo.AB_Abstract.FamilyPhysician = Lookup67.Code LEFT OUTER JOIN
    dbo.LU_Gender_I Lookup69 with (nolock) on dbo.AB_Abstract.Gender = Lookup69.Code LEFT OUTER JOIN
    dbo.LU_HCNProvince Lookup70 with (nolock) on dbo.AB_Abstract.HCNProvince = Lookup70.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup72 with (nolock) on dbo.AB_Abstract.Injury = Lookup72.Code LEFT OUTER JOIN

    dbo.LU_Institution_10 Lookup73 with (nolock) on dbo.AB_Abstract.InstitutionFrom = Lookup73.Code LEFT OUTER JOIN
	LU_Institution_TypeCode LU_InstitutionFrom_Type with (nolock) on dbo.AB_Abstract.InstitutionFromType = LU_InstitutionFrom_Type.Code LEFT OUTER JOIN
    dbo.H_InstitutionProfile Lookup74 with (nolock) on dbo.AB_Abstract.InstitutionNumber = Lookup74.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 Lookup75 with (nolock) on dbo.AB_Abstract.InstitutionTo = Lookup75.Code LEFT OUTER JOIN
	LU_Institution_TypeCode LU_InstitutionTo_Type with (nolock) on dbo.AB_Abstract.InstitutionToType = LU_InstitutionTo_Type.Code LEFT OUTER JOIN

    dbo.LU_AbstractStatus Lookup83 with (nolock) on dbo.AB_Abstract.IsCompleted = Lookup83.Code LEFT OUTER JOIN
    dbo.LU_CIHICorrect Lookup84 with (nolock) on dbo.AB_Abstract.IsCorrected = Lookup84.Code LEFT OUTER JOIN
    dbo.LU_DeleteStatus Lookup85 with (nolock) on dbo.AB_Abstract.IsDeleted = Lookup85.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem Lookup86 with (nolock) on dbo.AB_Abstract.IsSubmited = Lookup86.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus Lookup87 with (nolock) on dbo.AB_Abstract.IsValidated = Lookup87.Code LEFT OUTER JOIN
    dbo.LU_CustomStatus with (nolock) on dbo.AB_Abstract.IsCustomValidated = LU_CustomStatus.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup88 with (nolock) on dbo.AB_Abstract.BirthDateEstimated = Lookup88.Code LEFT OUTER JOIN
    dbo.LU_Language Lookup89 with (nolock) on dbo.AB_Abstract.LanguageCode = Lookup89.Code LEFT OUTER JOIN
    dbo.LU_LivingArrangement Lookup90 with (nolock) on dbo.AB_Abstract.LivingArrangement = Lookup90.Code LEFT OUTER JOIN
    dbo.LU_InjuryLocation Lookup91 with (nolock) on dbo.AB_Abstract.InjuryLocation = Lookup91.Code LEFT OUTER JOIN
    dbo.LU_MISCode Lookup93 with (nolock) on dbo.AB_Abstract.MISCode = Lookup93.Code LEFT OUTER JOIN
    --PR - 03012
    dbo.LU_CodeFile LU_AmCareType with (nolock) on Lookup93.AmCareType = LU_AmCareType.Code LEFT OUTER JOIN

    dbo.LU_MaritalStatus Lookup94 with (nolock) on dbo.AB_Abstract.MaritalStatus = Lookup94.Code LEFT OUTER JOIN
    dbo.LU_Occupation Lookup98 with (nolock) on dbo.AB_Abstract.Occupation = Lookup98.Code LEFT OUTER JOIN
    dbo.LU_TherPreAdmitWorkUp Lookup110 with (nolock) on dbo.AB_Abstract.PreAdmitWorkUp = Lookup110.Code LEFT OUTER JOIN
    dbo.LU_Program Lookup113 with (nolock) on dbo.AB_Abstract.Program = Lookup113.Code LEFT OUTER JOIN
    dbo.LU_Province Lookup118 with (nolock) on dbo.AB_Abstract.ProvinceNumber = Lookup118.Code LEFT OUTER JOIN
    dbo.LU_Referral Lookup135 with (nolock) on dbo.AB_Abstract.ReferredFrom = Lookup135.Code LEFT OUTER JOIN
    dbo.LU_Referral Lookup136 with (nolock) on dbo.AB_Abstract.ReferredTo = Lookup136.Code LEFT OUTER JOIN
    dbo.LU_ResidenceCode Lookup138 with (nolock) on dbo.AB_Abstract.ResidenceCode = Lookup138.Code LEFT OUTER JOIN
    dbo.LU_ResidenceType Lookup139 with (nolock) on dbo.AB_Abstract.ResidenceType = Lookup139.Code LEFT OUTER JOIN
    dbo.LU_RespPayment Lookup140 with (nolock) on dbo.AB_Abstract.ResponsiblePayment = Lookup140.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup141 with (nolock) on dbo.AB_Abstract.Secret = Lookup141.Code LEFT OUTER JOIN
    dbo.LU_Site Lookup142 with (nolock) on dbo.AB_Abstract.SiteNumber = Lookup142.Code LEFT OUTER JOIN
    dbo.LU_TherSocialService Lookup143 with (nolock) on dbo.AB_Abstract.SocialService = Lookup143.Code LEFT OUTER JOIN
    dbo.LU_TriageLevel Lookup151 with (nolock) on dbo.AB_Abstract.TriageLevel = Lookup151.Code LEFT OUTER JOIN
    dbo.U_Users Lookup152 with (nolock) on dbo.AB_Abstract.TSICoder = Lookup152.Code LEFT OUTER JOIN
    dbo.LU_VisitType Lookup154 with (nolock) on dbo.AB_Abstract.VisitStatus = Lookup154.Code LEFT OUTER JOIN
    dbo.LU_VisitType_10 Lookup155 with (nolock) on dbo.AB_Abstract.VisitType = Lookup155.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup148 with (nolock) on dbo.AB_Abstract.PCTASIndicator = Lookup148.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha Lookup153 with (nolock) on dbo.AB_Abstract.SchedEDVisit = Lookup153.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup156 with (nolock) on dbo.AB_Abstract.SeatbeltIndicator = Lookup156.Code AND Lookup156.LookupID = 2 LEFT OUTER JOIN
    dbo.LU_Glasgow Lookup157 with (nolock) on dbo.AB_Abstract.GlasgowComaScale = Lookup157.Code left join
    dbo.LU_CodeFile Lookup158 with (nolock) on Lookup158.Code = dbo.AB_Abstract.DecisionAdmitTimeUnknown AND Lookup158.LookupID = 1 left join
    dbo.LU_CodeFile Lookup159 with (nolock) on Lookup159.Code = dbo.AB_Abstract.AssessmentTimeUnknown AND Lookup159.LookupID = 1 Left Join
    -- PR - 01600
    LU_CodeFile LUDischargeTimeUnknown with (nolock) on dbo.AB_Abstract.DischargeTimeUnknown = LUDischargeTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_NurseArea LU_AdmitNurse with (nolock) on dbo.AB_Abstract.AdmittingNurseArea = LU_AdmitNurse.Code LEFT OUTER JOIN
    dbo.LU_NurseArea LU_DischargeNurse with (nolock) on dbo.AB_Abstract.DischargeNurseArea = LU_DischargeNurse.Code LEFT JOIN
    -- PR - 03013
    dbo.AB_Diagnosis AB_MainDiagnosis with (nolock) on dbo.AB_Abstract.AbstractID = AB_MainDiagnosis.AbstractID and AB_MainDiagnosis.DiagnosisOccurrence = 1 LEFT JOIN
    dbo.ICD_DiagFile10 LU_MainDiagnosis with (nolock) on AB_MainDiagnosis.DiagnosisCode = LU_MainDiagnosis.Code LEFT OUTER JOIN
    dbo.AB_Provider AB_MainProvider with (nolock) on dbo.AB_Abstract.AbstractID = AB_MainProvider.AbstractID and AB_MainProvider.ProviderOccurrence = 1 LEFT JOIN
    dbo.LU_Provider LU_MainProvider with (nolock) on AB_MainProvider.ProviderNumber = LU_MainProvider.Code LEFT OUTER JOIN
    dbo.LU_ProviderSpecialty LU_MainProviderSpecialty with (nolock) on AB_MainProvider.ProviderSpecialty = LU_MainProviderSpecialty.Code LEFT OUTER JOIN

    dbo.AB_Intervention AB_MainIntervention with (nolock) on dbo.AB_Abstract.AbstractID = AB_MainIntervention.AbstractID and AB_MainIntervention.IntervOccurrence = 1 LEFT JOIN
    dbo.ICD_ProcFile10 LU_MainIntervention with (nolock) on AB_MainIntervention.IntervCode = LU_MainIntervention.Code LEFT OUTER JOIN

    dbo.AB_Diagnosis AB_ReasonDiagnosis with (nolock) on dbo.AB_Abstract.AbstractID = AB_ReasonDiagnosis.AbstractID and dbo.AB_Abstract.Admitdate > ''2006/03/31'' 
        and AB_ReasonDiagnosis.DiagnosisPrefix in (select code from dbo.LU_DiagnosisPrefix LU_ReasonVisit where LU_ReasonVisit.CIHIValue = ''R'') LEFT OUTER JOIN
    dbo.ICD_DiagFile10 LU_ReasonDiagnosis with (nolock) on AB_ReasonDiagnosis.DiagnosisCode = LU_ReasonDiagnosis.Code LEFT OUTER JOIN
    --PR - 04386
    dbo.LU_CodeFile LU_AmbulanceArrTimeUnknown with (nolock) on dbo.AB_Abstract.AmbulanceArrTimeUnknown = LU_AmbulanceArrTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_AmbulanceTranTimeUnknown with (nolock) on dbo.AB_Abstract.AmbulanceTranTimeUnknown = LU_AmbulanceTranTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_AccessPrimaryHealthCareCode with (nolock) on dbo.AB_Abstract.AccessCareCode = dbo.LU_AccessPrimaryHealthCareCode.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_CDUFlag with (nolock) on dbo.AB_Abstract.CDUFlag = LU_CDUFlag.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CDUInTimeUnknown with (nolock) on dbo.AB_Abstract.CDUInTimeUnknown = LU_CDUInTimeUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CDUOutTimeUnknown with (nolock) on dbo.AB_Abstract.CDUOutTimeUnknown = LU_CDUOutTimeUnknown.Code LEFT OUTER JOIN
    --NP - 00125
    dbo.LU_CIHICorrect LU_Level1_Correction with (nolock) on dbo.AB_Abstract.IsCorrectLevel1 = LU_Level1_Correction.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_Level1_Submission with (nolock) on dbo.AB_Abstract.IsSubmitLevel1 = LU_Level1_Submission.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus LU_Level1_Validation with (nolock) on dbo.AB_Abstract.IsValidLevel1 = LU_Level1_Validation.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus LU_Level1_Completed with (nolock) on dbo.AB_Abstract.IsCompleteLevel1 = LU_Level1_Completed.Code 
--PR - 04577
    LEFT OUTER JOIN dbo.LU_ReciprocalBillingStatus with (nolock) on dbo.AB_Abstract.IsReciprocalBilling = LU_ReciprocalBillingStatus.Code 

--PR - 05147 
	left join dbo.AB_NACRS with (nolock) on AB_Abstract.AbstractID = AB_NACRS.AbstractID
	left join dbo.LU_CodeFile LU_AmCareTypeCode with (nolock) on AB_NACRS.AmCareTypeCode = LU_AmCareTypeCode.Code
	left join dbo.LU_CodeFile LU_AmCareGroup with (nolock) on AB_NACRS.AmCareGroup = LU_AmCareGroup.Code
	left join dbo.LU_CodeFile LU_AmCareTypeCode_FromMISCode with (nolock) on Lookup93.AmCareTypeCode = LU_AmCareTypeCode_FromMISCode.CIHIValue and LU_AmCareTypeCode_FromMISCode.LookUpID = 1101 and LU_AmCareTypeCode_FromMISCode.code between 203501 and 203513
	left join dbo.LU_CodeFile LU_AmCareGroup_FromMISCode with (nolock) on Lookup93.AmCareGroup = LU_AmCareGroup_FromMISCode.CIHIValue and LU_AmCareGroup_FromMISCode.LookUPID = 1102 and LU_AmCareGroup_FromMISCode.code between 203601 and 203605
    --ED - 02298
    left join dbo.LU_YesNoSystem LU_EDVisitIndicator with (nolock) on dbo.AB_NACRS.EDVisitIndicator = LU_EDVisitIndicator.Code
    left join dbo.LU_StatusAfterTriage with (nolock) on dbo.AB_NACRS.StatusAfterTriage = LU_StatusAfterTriage.Code
    left join dbo.LU_YesNoSystem LU_IsLiteSubmission with (nolock) on dbo.AB_Abstract.IsLiteSubmission = LU_IsLiteSubmission.Code

WHERE     (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)
--QA - 00032 disable the domain securite issue
----PR - 07485
--    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB_ABstract.HospitalID is null or AB_ABstract.HospitalID = 0
--    --EN - 00666
--        or Is_Member(nullif(ReportGroup, '''')) = 1)
----        or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB_ABstract.HospitalID, 0))








' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AmcareRecordKey_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE  VIEW [dbo].[I10_AmcareRecordKey_VR]
AS
SELECT
	--PR - 07231
	LU_AdmitNurseArea.DisplayCode AS AdmitNurseAreaUnitLoc, LU_AdmitNurseArea.UserDescription AS AdmitNurseAreaUnitLocDesc, 

    LU_AmCareGroup_FromMISCode.DisplayCode AS AmCareGroup,          LU_AmCareGroup_FromMISCode.UserDescription AS AmCareGroupDesc, 
    LU_AmCareTypeCode_FromMISCode.DisplayCode AS AmcareTypeCode,    LU_AmCareTypeCode_FromMISCode.UserDescription AS AmcareTypeCodeDesc, 

    dbo.AB_Abstract.ChartNumber, 
	U_Users.DisplayCode AS CoderNumber, U_Users.UserDescription AS CoderNumberDesc, --ED - 02401
    DateLeftER as DatePatientLeftED, 
    LU_DispositionCode_A.DisplayCode AS DischargeDisposition, LU_DispositionCode_A.UserDescription AS DischargeDispositionDesc, 
    dbo.AB_Abstract.DischargeDate AS DispositionDate, dbo.AB_Abstract.DischargeTime AS DispositionTime, 
	--PR - 07231
	LU_DischargeNurseArea.DisplayCode AS DischNurseAreaUnitLoc, LU_DischargeNurseArea.UserDescription AS DischNurseAreaUnitLocDesc, 

    ISNULL(dbo.AB_Abstract.LastName, '' '') + '', '' + ISNULL(dbo.AB_Abstract.FirstName, '''') + '' '' + ISNULL(dbo.AB_Abstract.MiddleName, '''') AS FullName,     
    FixedChartNumber,
    dbo.AB_Abstract.HealthCareNumber, 
    H_InstitutionProfile.DisplayCode AS InstitutionNumber, H_InstitutionProfile.UserDescription AS InstitutionNumberDesc, 
    LU_MISCode.DisplayCode AS MISCode, LU_MISCode.UserDescription AS MISCodeDesc, 
    ReAdmitDifferenceDaysForNACRS = dbo.CalculateReAdmitDifferenceDaysForNACRS(ChartNumber, AdmitDate, AbstractID),
    dbo.AB_Abstract.EncounterNumber as RegistrationNumber,
    dbo.AB_Abstract.AdmitDate AS RegistrationVisitDate, dbo.AB_Abstract.AdmitTime AS RegistrationVisitTime, 
    TimeLeftER as TimePatientLeftED,
    dbo.AB_Abstract.AbstractID AS zzAbstractLink,
    dbo.AB_Abstract.RegionalPatientID as zzRegionalPatientID
FROM         
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.H_InstitutionProfile with (nolock) ON dbo.AB_Abstract.InstitutionNumber = H_InstitutionProfile.Code 
    left join LU_MISCode with (nolock) on LU_MISCode.Code = MISCode
    --ED - 02401
	left join U_Users with (nolock) on AB_Abstract.CoderNumber = U_Users.Code 
    left join dbo.LU_DispositionCode_A with (nolock) on dbo.AB_Abstract.DispositionCode = LU_DispositionCode_A.Code 
    --PR - 07231
    left join dbo.LU_NurseArea LU_AdmitNurseArea with (nolock) on dbo.AB_Abstract.AdmittingNurseArea = LU_AdmitNurseArea.Code 
    left join dbo.LU_NurseArea LU_DischargeNurseArea with (nolock) on dbo.AB_Abstract.DischargeNurseArea = LU_DischargeNurseArea.Code 
    left join dbo.H_HospitalProfile with (nolock) on dbo.AB_Abstract.HospitalID = H_HospitalProfile.Code 

--	left join dbo.LU_CodeFile LU_AmCareTypeCode with (nolock) on AB_NACRS.AmCareTypeCode = LU_AmCareTypeCode.Code
--	left join dbo.LU_CodeFile LU_AmCareGroup with (nolock) on AB_NACRS.AmCareGroup = LU_AmCareGroup.Code
	left join dbo.LU_CodeFile LU_AmCareTypeCode_FromMISCode with (nolock) on LU_MISCode.AmCareTypeCode = LU_AmCareTypeCode_FromMISCode.CIHIValue and LU_AmCareTypeCode_FromMISCode.LookUpID = 1101 and LU_AmCareTypeCode_FromMISCode.code between 203501 and 203513
	left join dbo.LU_CodeFile LU_AmCareGroup_FromMISCode with (nolock) on LU_MISCode.AmCareGroup = LU_AmCareGroup_FromMISCode.CIHIValue and LU_AmCareGroup_FromMISCode.LookUPID = 1102 and LU_AmCareGroup_FromMISCode.code between 203601 and 203605

WHERE     (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 5)
--QA - 00032 disable the domain securite issue
----PR - 07485
--    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB_ABstract.HospitalID is null or AB_ABstract.HospitalID = 0
--    --EN - 00666
--        or Is_Member(nullif(ReportGroup, '''')) = 1)
----        or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB_ABstract.HospitalID, 0))
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_BasicOption_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE view [dbo].[I10_BasicOption_VR]
as
select
    BasicOption1  = dbo.lu_BasicOption1.DisplayCode,  BasicOption1Desc  = dbo.lu_BasicOption1.UserDescription,
    BasicOption2  = dbo.lu_BasicOption2.DisplayCode,  BasicOption2Desc  = dbo.lu_BasicOption2.UserDescription,
    BasicOption3  = dbo.lu_BasicOption3.DisplayCode,  BasicOption3Desc  = dbo.lu_BasicOption3.UserDescription,
    BasicOption4  = dbo.lu_BasicOption4.DisplayCode,  BasicOption4Desc  = dbo.lu_BasicOption4.UserDescription,
    BasicOption5  = dbo.lu_BasicOption5.DisplayCode,  BasicOption5Desc  = dbo.lu_BasicOption5.UserDescription,
    BasicOption6  = dbo.lu_BasicOption6.DisplayCode,  BasicOption6Desc  = dbo.lu_BasicOption6.UserDescription,
    BasicOption7  = dbo.lu_BasicOption7.DisplayCode,  BasicOption7Desc  = dbo.lu_BasicOption7.UserDescription,
    BasicOption8  = dbo.lu_BasicOption8.DisplayCode,  BasicOption8Desc  = dbo.lu_BasicOption8.UserDescription,
    BasicOption9  = dbo.lu_BasicOption9.DisplayCode,  BasicOption9Desc  = dbo.lu_BasicOption9.UserDescription,
    BasicOption10 = dbo.lu_BasicOption10.DisplayCode, BasicOption10Desc = dbo.lu_BasicOption10.UserDescription,
    BasicOption11 = dbo.lu_BasicOption11.DisplayCode, BasicOption11Desc = dbo.lu_BasicOption11.UserDescription,
    BasicOption12 = dbo.lu_BasicOption12.DisplayCode, BasicOption12Desc = dbo.lu_BasicOption12.UserDescription,
    BasicOption13 = dbo.lu_BasicOption13.DisplayCode, BasicOption13Desc = dbo.lu_BasicOption13.UserDescription,
    BasicOption14 = dbo.lu_BasicOption14.DisplayCode, BasicOption14Desc = dbo.lu_BasicOption14.UserDescription,
    BasicOption15 = dbo.lu_BasicOption15.DisplayCode, BasicOption15Desc = dbo.lu_BasicOption15.UserDescription,
    BasicOption16 = dbo.lu_BasicOption16.DisplayCode, BasicOption16Desc = dbo.lu_BasicOption16.UserDescription,
    BasicOption17 = dbo.lu_BasicOption17.DisplayCode, BasicOption17Desc = dbo.lu_BasicOption17.UserDescription,
    BasicOption18 = dbo.lu_BasicOption18.DisplayCode, BasicOption18Desc = dbo.lu_BasicOption18.UserDescription,
    BasicOption19 = dbo.lu_BasicOption19.DisplayCode, BasicOption19Desc = dbo.lu_BasicOption19.UserDescription,
    dbo.AB_BasicOption.AbstractID as zzabstractlink
from dbo.ab_abstract with (nolock) inner join 
    dbo.AB_BasicOption with (nolock) on dbo.ab_abstract.AbstractID = dbo.AB_BasicOption.AbstractID
    left join dbo.lu_BasicOption1  with (nolock) on dbo.AB_BasicOption.BasicOption1  =  dbo.lu_BasicOption1.Code
    left join dbo.lu_BasicOption2  with (nolock) on dbo.AB_BasicOption.BasicOption2  =  dbo.lu_BasicOption2.Code
    left join dbo.lu_BasicOption3  with (nolock) on dbo.AB_BasicOption.BasicOption3  =  dbo.lu_BasicOption3.Code
    left join dbo.lu_BasicOption4  with (nolock) on dbo.AB_BasicOption.BasicOption4  =  dbo.lu_BasicOption4.Code
    left join dbo.lu_BasicOption5  with (nolock) on dbo.AB_BasicOption.BasicOption5  =  dbo.lu_BasicOption5.Code
    left join dbo.lu_BasicOption6  with (nolock) on dbo.AB_BasicOption.BasicOption6  =  dbo.lu_BasicOption6.Code
    left join dbo.lu_BasicOption7  with (nolock) on dbo.AB_BasicOption.BasicOption7  =  dbo.lu_BasicOption7.Code
    left join dbo.lu_BasicOption8  with (nolock) on dbo.AB_BasicOption.BasicOption8  =  dbo.lu_BasicOption8.Code
    left join dbo.lu_BasicOption9  with (nolock) on dbo.AB_BasicOption.BasicOption9  =  dbo.lu_BasicOption9.Code
    left join dbo.lu_BasicOption10 with (nolock) on dbo.AB_BasicOption.BasicOption10 =  dbo.lu_BasicOption10.Code
    left join dbo.lu_BasicOption11 with (nolock) on dbo.AB_BasicOption.BasicOption11 =  dbo.lu_BasicOption11.Code
    left join dbo.lu_BasicOption12 with (nolock) on dbo.AB_BasicOption.BasicOption12 =  dbo.lu_BasicOption12.Code
    left join dbo.lu_BasicOption13 with (nolock) on dbo.AB_BasicOption.BasicOption13 =  dbo.lu_BasicOption13.Code
    left join dbo.lu_BasicOption14 with (nolock) on dbo.AB_BasicOption.BasicOption14 =  dbo.lu_BasicOption14.Code
    left join dbo.lu_BasicOption15 with (nolock) on dbo.AB_BasicOption.BasicOption15 =  dbo.lu_BasicOption15.Code
    left join dbo.lu_BasicOption16 with (nolock) on dbo.AB_BasicOption.BasicOption16 =  dbo.lu_BasicOption16.Code
    left join dbo.lu_BasicOption17 with (nolock) on dbo.AB_BasicOption.BasicOption17 =  dbo.lu_BasicOption17.Code
    left join dbo.lu_BasicOption18 with (nolock) on dbo.AB_BasicOption.BasicOption18 =  dbo.lu_BasicOption18.Code
    left join dbo.lu_BasicOption19 with (nolock) on dbo.AB_BasicOption.BasicOption19 =  dbo.lu_BasicOption19.Code
where ICDType = ''T''


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_CMG_2002Percentile]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'





CREATE   VIEW [dbo].[I10_CMG_2002Percentile]
AS
SELECT     dbo.CMG_ETC_2002T.ModelType, dbo.CMG_ETC_2002T.TenthPercent, dbo.CMG_ETC_2002T.TwentyFifthPercent, 
                      dbo.CMG_ETC_2002T.FiftiethPercent, AB_CMG.CMG_Year, dbo.AB_CMG.AbstractID AS zzAbstractLink
FROM         dbo.AB_CMG with (nolock) LEFT OUTER JOIN
                      dbo.AB_Abstract with (nolock) ON dbo.AB_CMG.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
                      dbo.CMG_ETC_2002T with (nolock) ON dbo.AB_CMG.Complexity = dbo.CMG_ETC_2002T.cicpxlvl AND dbo.AB_CMG.CMG = dbo.CMG_ETC_2002T.cmgcode
WHERE     (dbo.AB_CMG.CMG_Year = 2002) AND (dbo.AB_Abstract.AgeCode = 3) AND (dbo.AB_Abstract.AgeNumber BETWEEN 18 AND 68) AND 
                      (dbo.CMG_ETC_2002T.ciagegroup = 2)
union all
SELECT     dbo.CMG_ETC_2002T.ModelType, dbo.CMG_ETC_2002T.TenthPercent, dbo.CMG_ETC_2002T.TwentyFifthPercent, 
                      dbo.CMG_ETC_2002T.FiftiethPercent, AB_CMG.CMG_Year, dbo.AB_CMG.AbstractID AS zzAbstractLink
FROM         dbo.AB_CMG with (nolock) LEFT OUTER JOIN
                      dbo.AB_Abstract with (nolock) ON dbo.AB_CMG.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
                      dbo.CMG_ETC_2002T with (nolock) ON dbo.AB_CMG.Complexity = dbo.CMG_ETC_2002T.cicpxlvl AND dbo.AB_CMG.CMG = dbo.CMG_ETC_2002T.cmgcode
WHERE     (dbo.AB_CMG.CMG_Year = 2002) AND (dbo.AB_Abstract.AgeCode = 3) AND (dbo.AB_Abstract.AgeNumber BETWEEN 0 AND 17) AND 
                      (dbo.CMG_ETC_2002T.ciagegroup = 1) OR
                      (dbo.AB_CMG.CMG_Year = 2002) AND (dbo.AB_Abstract.AgeCode <> 3) AND (dbo.CMG_ETC_2002T.ciagegroup = 1)
union all
SELECT     dbo.CMG_ETC_2002T.ModelType, dbo.CMG_ETC_2002T.TenthPercent, dbo.CMG_ETC_2002T.TwentyFifthPercent, 
                      dbo.CMG_ETC_2002T.FiftiethPercent, AB_CMG.CMG_Year, dbo.AB_CMG.AbstractID AS zzAbstractLink
FROM         dbo.AB_CMG with (nolock) LEFT OUTER JOIN
                      dbo.AB_Abstract with (nolock) ON dbo.AB_CMG.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
                      dbo.CMG_ETC_2002T with (nolock) ON dbo.AB_CMG.Complexity = dbo.CMG_ETC_2002T.cicpxlvl AND dbo.AB_CMG.CMG = dbo.CMG_ETC_2002T.cmgcode
WHERE     (dbo.AB_CMG.CMG_Year = 2002) AND (dbo.AB_Abstract.AgeCode = 3) AND (dbo.AB_Abstract.AgeNumber > 68) AND 
                      (dbo.CMG_ETC_2002T.ciagegroup = 3)







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_CMG_NonComplex_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_CMG_NonComplex_VR]
AS
SELECT DISTINCT 
                      dbo.CMG_NonReporting.ciagelos AS MOHELOS, dbo.CMG_NonReporting.ciagtrim AS MOHTrim, dbo.AB_Abstract.AbstractID AS zzAbstractLink, 
                      dbo.AB_CMG.CMG_Year AS CMG_YearNonComplex
FROM         dbo.AB_CMG with (nolock) LEFT OUTER JOIN
    dbo.AB_Abstract with (nolock) INNER JOIN
    dbo.CMG_NonReporting with (nolock) ON dbo.AB_Abstract.AgeGroup = dbo.CMG_NonReporting.ciagegroup ON 
    dbo.AB_CMG.AbstractID = dbo.AB_Abstract.AbstractID AND dbo.AB_CMG.CMG_Year = dbo.CMG_NonReporting.CMGNonYear AND 
    dbo.AB_CMG.CMG = dbo.CMG_NonReporting.CMGCode and 
    ((AB_Abstract.DischargeDate > ''2009/03/31'' and dbo.CMG_NonReporting.FiscalYear = 2008) or
     (AB_Abstract.DischargeDate between ''2007/04/01'' and ''2009/03/31'' and dbo.CMG_NonReporting.FiscalYear = 2007) or 
     (AB_Abstract.DischargeDate < ''2007/04/01'' and dbo.CMG_NonReporting.FiscalYear = 2006) or
     dbo.AB_CMG.CMG_Year < 2006 )
WHERE     (dbo.AB_CMG.CMG_Year > 2001) AND (dbo.AB_Abstract.AbstractID IS NOT NULL) AND (dbo.AB_CMG.OccurrenceNumber = 1)



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_CMG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_CMG_VR]
AS
SELECT     dbo.AB_CMG.AcuteQuartile AS Acute_Quartile, 
	dbo.AB_CMG.BatchGroupDate,
	dbo.AB_CMG.CMG, dbo.AB_CMG.CMG_Description, 
	dbo.AB_CMG_FI.MedicalCMG, dbo.tGrouper_CMG_CMG.cmg_long_e_desc as MedicalCMGDesciption,
	dbo.AB_CMG.CMG_ELOS, dbo.AB_CMG.CMG_Split, 
    dbo.AB_CMG.CMG_Year, 
    dbo.AB_CMG.CMGAgeCategory, dbo.tGrouper_CMG_CMG_AGE_CATEGORY.CMG_AGE_CATEGORY_E_DESC AS CMGAgeCategoryDesc, 
    dbo.AB_CMG_FI.CMGReturnCode, 
    dbo.AB_CMG.ComorbidityLevel, dbo.tGrouper_CMG_COMORBIDITY_LEVEL.COMORBIDITY_LEVEL_E_DESC AS ComorbidityLevelDesc, 
    dbo.AB_CMG_FI.ComorbidityTotalFactor,
    dbo.AB_CMG.Complexity, dbo.CMG_LU_Complexity.UserDescription AS Complexity_Description, 
    dbo.ICD_DiagFile10.CIHIValue AS Diagnosis_CIHIValue, 
    dbo.ICD_DiagFile10.DisplayCode AS Diagnosis_Code, dbo.ICD_DiagFile10.UserDescription AS Diagnosis_Description, 
    dbo.ICD_DiagFile10.ShortDescription AS Diagnosis_CodeShortDesc, dbo.LU_DiagnosisType.DisplayCode AS Diagnosis_Type, 
    dbo.LU_DiagnosisType.UserDescription AS Diagnosis_Type_Desc, dbo.tGrouper_CMG_MCC_PARTITION.MCC_PARTITION_CODE AS DxIntervPartition, 
    dbo.tGrouper_CMG_MCC_PARTITION.MCC_PARTITION_E_DESC AS DxIntervPartitionDesc, 
    dbo.AB_CMG_FI.FI_BiopsyFlag,    --PR - 04306
    dbo.AB_CMG_FI.FI_CardioversionFlag, 
    dbo.AB_CMG_FI.FI_CellSaverFlag, 
	dbo.AB_CMG_FI.FI_ChemotherapyFlag, 
	dbo.AB_CMG_FI.FI_DialysisFlag, 
	dbo.AB_CMG_FI.FI_ECMOFlag,
    dbo.AB_CMG_FI.FI_EndoscopyFlag,    --PR - 04306 
    dbo.AB_CMG_FI.FI_FeedingTubeFlag, 
    dbo.AB_CMG_FI.FI_HeartResuscitationFlag, 
	FI_InvasiveVentilationGreat96Hours = dbo.AB_CMG_FI.FI_MechanicalVentGreat96Hours, 
	FI_InvasiveVentilationLess96Hours = dbo.AB_CMG_FI.FI_MechanicalVentLess96Hours, 
    dbo.AB_CMG_FI.FI_MechanicalVentGreat96Hours, 
    dbo.AB_CMG_FI.FI_MechanicalVentLess96Hours, 
	dbo.AB_CMG_FI.FI_ParacentesisFlag, 
	dbo.AB_CMG_FI.FI_ParenteralNutritionFlag, 
    dbo.AB_CMG_FI.FI_PleurocentesisFlag, 
	dbo.AB_CMG_FI.FI_RadiotherapyFlag, 
	dbo.AB_CMG_FI.FI_TracheostomyFlag, 
    dbo.AB_CMG_FI.FI_VascularAccessDdeviceFlag, 
    dbo.AB_CMG.CMGFiftiethPercent AS FiftiethPercentile, 
    
    FlaggedIntervFactorCount = (case when AB_CMG.CMG_year < 2015 then dbo.AB_CMG.FlaggedIntervFactorCount else null end), 
    FlaggedIntervFactorCountDesc = (case when AB_CMG.CMG_year < 2015 then dbo.tGrouper_CMG_FLAGGED_INTERV_CNT.FLAGGED_INTERV_E_DESC else null end), 
	--2.x-0549
	FlaggedInterventionGroup1 = (case when FI_MechanicalVentGreat96Hours = 1  or FI_ECMOFlag =  1 then ''Y'' else ''N'' end),
	FlaggedInterventionGroup2 = (case when FI_FeedingTubeFlag = 1 or FI_MechanicalVentLess96Hours = 1 or FI_ParenteralNutritionFlag = 1 or FI_TracheostomyFlag = 1 or
										   FI_VascularAccessDdeviceFlag = 1 then ''Y'' else ''N'' end),
	FlaggedInterventionGroup3 = (case when FI_CardioversionFlag = 1 or FI_CellSaverFlag = 1 or FI_ChemotherapyFlag = 1 or FI_DialysisFlag = 1 or FI_HeartResuscitationFlag = 1 or
										   FI_ParacentesisFlag = 1 or FI_PleurocentesisFlag = 1 or FI_RadiotherapyFlag = 1 or FI_BiopsyFlag =  1 or FI_EndoscopyFlag =  1
									  then ''Y'' else ''N'' end),

    FlaggedInterventionStatusCode = (case when AB_CMG.CMG_year >= 2015 then dbo.AB_CMG.FlaggedIntervFactorCount else null end), 
    FlaggedInterventionStatusCodeDesc = (case when AB_CMG.CMG_year >= 2015 then dbo.tGrouper_CMG_FLAGGED_INTERV_STATUS.flagged_interv_status_e_desc else null end), 
    
    dbo.AB_CMG.ICD_Type, 
    dbo.AB_CMG.InpatientRILevel, dbo.tGrouper_CMG_IP_RI_LEVEL.IP_RI_LEVEL_E_DESC AS InpatientRILevelDesc, 
    dbo.AB_CMG_FI.InpatientRITotalFactor,
    dbo.AB_CMG.InpatientRIWAtypicalCode, dbo.tGrouper_CMG_IP_RIW_ATYPICAL.IP_RIW_ATYPICAL_E_DESC AS InpatientRIWAtypicalCodeDesc, 
    LU_Intervention.DisplayCode AS InterventionAssignment, LU_Intervention.CIHIValue AS InterventionAssignmentCIHI, 
    LU_Intervention.UserDescription AS InterventionAssignmentDesc, 
    dbo.AB_CMG_FI.IntervAttStatus as InterventionAttributeStatus, 
    dbo.AB_CMG_FI.IntervAttLocation as InterventionAttributeLocation,
    dbo.AB_CMG_FI.IntervAttExtent as InterventionAttributeExtent,
    dbo.AB_CMG_FI.IntervEpisode as InterventionEpisode,
    dbo.AB_CMG.InterventionEventCount, 
    dbo.tGrouper_CMG_INTERVENTION_EVENT_CNT.INTERV_EVENT_CNT_E_DESC AS InterventionEventCountDesc, dbo.AB_CMG.InterventionOOHCount, 
    dbo.tGrouper_CMG_INTERVENTION_OOH_CNT.INTERV_OOH_CNT_E_DESC AS InterventionOOHCountDesc, dbo.AB_CMG.MCC, 
    dbo.tGrouper_CMG_MCC_LOGIC.mcc_long_e_desc AS MCC_Description, dbo.AB_CMG.MCC_Surg, dbo.AB_CMG.CMGModelType AS ModelType, 
    dbo.AB_CMG.MOH_Dollar, 
    dbo.AB_CMG.MOH_RIW,
    dbo.AB_CMG.OccurrenceNumber AS Occurrence_Number, 
    PercentileAgeGroup = (case when dbo.AB_CMG.CMGAgeCategory in (''A'', ''B'', ''C'', ''F'', ''G'', ''H'') then 1
                               when dbo.AB_CMG.CMGAgeCategory = ''R'' then 2
                               when dbo.AB_CMG.CMGAgeCategory = ''S'' then 3
                               when dbo.AB_CMG.CMGAgeCategory = ''T'' then 4
                          end),                          
    dbo.AB_CMG.CMG_RIW AS RIW, dbo.AB_CMG_FI.InpatientTypicalRIW,
    dbo.AB_CMG.RIW_Dollar, dbo.AB_CMG.CMGTenthPercent AS TenthPercentile, dbo.AB_CMG.CMG_Trim AS Trim, 
    dbo.AB_CMG.CMGTwentyFifthPercent AS TwentyFifthPercentile, 
    HIG_Code, HIG_Description, HIG_Weight, 
    HIG_AgeCategory, HIG_AgeCategoryDesc = (select top 1 hig_age_category_e_desc from dbo.tGrouper_HIG_Age_Category a where a.hig_age_category_code = HIG_AgeCategory and a.methodology_year = AB_HIG.GrouperYear),
    HIG_AtypicalCode, HIG_AtypicalCodeDesc = (select top 1 hig_atypical_e_desc from dbo.tGrouper_HIG_Atypical b where b.hig_atypical_code = HIG_AtypicalCode and b.methodology_year = AB_HIG.GrouperYear),
    HIG_ELOS, HIG_FI_TotalCount, 
    HIG_HomeCareFlag, HIG_MaternalAgeFlag, HIG_PalliativeCareFlag, HIG_OOHFlag, HIG_SCUFlag, HIG_LongStayTrimDays, HIG_ShortStayTrimDays, 
    dbo.AB_CMG.AbstractID AS zzAbstractLink
FROM         dbo.AB_CMG with (nolock) LEFT OUTER JOIN
      dbo.AB_CMG_FI with (nolock) on dbo.AB_CMG.AbstractID = dbo.AB_CMG_FI.AbstractID and dbo.AB_CMG.CMG_year = dbo.AB_CMG_FI.CMG_year
            and dbo.AB_CMG.OccurrenceNumber = dbo.AB_CMG_FI.OccurrenceNumber LEFT OUTER JOIN
      dbo.tGrouper_CMG_MCC_PARTITION with (nolock) on dbo.AB_CMG.CMG_Partition = dbo.tGrouper_CMG_MCC_PARTITION.MCC_PARTITION_CODE 
            and dbo.AB_CMG.CMG_Year = dbo.tGrouper_CMG_MCC_PARTITION.METHODOLOGY_YEAR LEFT OUTER JOIN
      dbo.tGrouper_CMG_IP_RI_LEVEL with (nolock) on dbo.AB_CMG.CMG_Year = dbo.tGrouper_CMG_IP_RI_LEVEL.METHODOLOGY_YEAR AND 
      dbo.AB_CMG.InpatientRILevel = dbo.tGrouper_CMG_IP_RI_LEVEL.IP_RI_LEVEL_CODE LEFT OUTER JOIN
      dbo.tGrouper_CMG_INTERVENTION_OOH_CNT with (nolock) on 
          dbo.AB_CMG.CMG_Year = dbo.tGrouper_CMG_INTERVENTION_OOH_CNT.METHODOLOGY_YEAR AND 
          dbo.AB_CMG.InterventionOOHCount = dbo.tGrouper_CMG_INTERVENTION_OOH_CNT.INTERV_OOH_CNT_CODE LEFT OUTER JOIN
      dbo.tGrouper_CMG_INTERVENTION_EVENT_CNT with (nolock) on 
      dbo.AB_CMG.CMG_Year = dbo.tGrouper_CMG_INTERVENTION_EVENT_CNT.METHODOLOGY_YEAR AND 
      dbo.AB_CMG.InterventionEventCount = dbo.tGrouper_CMG_INTERVENTION_EVENT_CNT.INTERV_EVENT_CNT_CODE LEFT OUTER JOIN
      
      dbo.tGrouper_CMG_FLAGGED_INTERV_CNT with (nolock) on dbo.AB_CMG.FlaggedIntervFactorCount = dbo.tGrouper_CMG_FLAGGED_INTERV_CNT.FLAGGED_INTERV_CODE LEFT OUTER JOIN
      dbo.tGrouper_CMG_FLAGGED_INTERV_STATUS with (nolock) on dbo.AB_CMG.CMG_Year = dbo.tGrouper_CMG_FLAGGED_INTERV_STATUS.METHODOLOGY_YEAR and dbo.AB_CMG.FlaggedIntervFactorCount = dbo.tGrouper_CMG_FLAGGED_INTERV_STATUS.flagged_interv_status_code LEFT OUTER JOIN
      
      dbo.tGrouper_CMG_COMORBIDITY_LEVEL with (nolock) on dbo.AB_CMG.CMG_Year = dbo.tGrouper_CMG_COMORBIDITY_LEVEL.METHODOLOGY_YEAR AND 
      dbo.AB_CMG.ComorbidityLevel = dbo.tGrouper_CMG_COMORBIDITY_LEVEL.COMORBIDITY_LEVEL_CODE LEFT OUTER JOIN
      dbo.tGrouper_CMG_CMG_AGE_CATEGORY with (nolock) on dbo.AB_CMG.CMG_Year = dbo.tGrouper_CMG_CMG_AGE_CATEGORY.METHODOLOGY_YEAR AND 
        dbo.AB_CMG.CMGAgeCategory = dbo.tGrouper_CMG_CMG_AGE_CATEGORY.CMG_AGE_CATEGORY_CODE LEFT OUTER JOIN
      dbo.tGrouper_CMG_IP_RIW_ATYPICAL with (nolock) on dbo.AB_CMG.InpatientRIWAtypicalCode = dbo.tGrouper_CMG_IP_RIW_ATYPICAL.IP_RIW_ATYPICAL_CODE 
            and dbo.AB_CMG.CMG_Year = dbo.tGrouper_CMG_IP_RIW_ATYPICAL.METHODOLOGY_YEAR LEFT OUTER JOIN

      dbo.tGrouper_CMG_MCC_LOGIC with (nolock) on dbo.AB_CMG.CMG_Year = dbo.tGrouper_CMG_MCC_LOGIC.methodology_year AND 
          dbo.AB_CMG.MCC = dbo.tGrouper_CMG_MCC_LOGIC.mcc_code LEFT OUTER JOIN
      dbo.ICD_ProcFile10 AS LU_Intervention with (nolock) on dbo.AB_CMG.IntervCode = LU_Intervention.Code LEFT OUTER JOIN
      dbo.CMG_LU_Complexity with (nolock) on dbo.AB_CMG.Complexity = dbo.CMG_LU_Complexity.DisplayCode LEFT OUTER JOIN
      dbo.ICD_DiagFile10 with (nolock) on dbo.AB_CMG.Diagnosis_Code = dbo.ICD_DiagFile10.Code LEFT OUTER JOIN
      dbo.LU_DiagnosisType with (nolock) on dbo.AB_CMG.Diagnosis_Type = dbo.LU_DiagnosisType.Code left JOIN
      dbo.tGrouper_CMG_CMG with (nolock) on dbo.AB_CMG.CMG_Year = dbo.tGrouper_CMG_CMG.METHODOLOGY_YEAR and dbo.AB_CMG_FI.MedicalCMG = dbo.tGrouper_CMG_CMG.cmg_code left join
      AB_HIG with (nolock) on dbo.AB_CMG.AbstractID = AB_HIG.ABstractID and dbo.AB_CMG.OccurrenceNumber = AB_HIG.OccurrenceNumber
            and dbo.AB_CMG.CMG_Year = AB_HIG.GrouperYear
            
WHERE     (dbo.AB_CMG.ICD_Type = ''T'') 


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_CMGAverages_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'





CREATE VIEW [dbo].[I10_CMGAverages_VR]
AS
SELECT     TOP 100 PERCENT dbo.AB_CMG.CMG AS CMGs, dbo.AB_CMG.CMG_Year AS CMGYears, AVG(dbo.AB_CMG.CMG_ELOS) AS ELOSAvg, 
                      COUNT(dbo.AB_CMG.AbstractID) AS HospitalCases, AVG(dbo.AB_CMG.CMG_RIW) AS RIWAvg, AVG(CAST(dbo.AB_CMG.CMG_Trim AS int)) AS TrimAvg, 
                      dbo.AB_CMG.Complexity, dbo.AB_Abstract.AgeGroup, cast(avg(cast(LOSDays as decimal(8,2))) as decimal(8,2)) as LOSDaysAvg
FROM         dbo.AB_CMG with (nolock) LEFT OUTER JOIN
                      dbo.AB_Abstract with (nolock) ON dbo.AB_CMG.AbstractID = dbo.AB_Abstract.AbstractID
WHERE     (dbo.AB_CMG.OccurrenceNumber = ''1'') AND (dbo.AB_CMG.ICD_Type = ''T'') and CMG_YEAR = (CASE When datepart(mm, dischargedate) < 4 THEN datepart(yyyy, dischargedate) - 1 
When datepart(mm, dischargedate) > 3 THEN datepart(yyyy, dischargedate) END)
GROUP BY dbo.AB_CMG.CMG_Year, dbo.AB_CMG.CMG, dbo.AB_CMG.Complexity, dbo.AB_Abstract.AgeGroup









' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_CMGOntPerc2002_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'




CREATE  VIEW [dbo].[I10_CMGOntPerc2002_VR]
AS
SELECT  AB_CMG.CMG, AB_CMG.CMG_Year, 
        dbo.CMG_ETC_2002O.TenthPercent, dbo.CMG_ETC_2002O.TwentyFifthPercent, 
        dbo.CMG_ETC_2002O.FiftiethPercent, dbo.AB_CMG.AbstractID AS zzAbstractLink
FROM         dbo.AB_CMG LEFT OUTER JOIN
    dbo.AB_Abstract with (nolock) ON dbo.AB_CMG.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
    dbo.CMG_ETC_2002O with (nolock) ON dbo.AB_CMG.Complexity = dbo.CMG_ETC_2002O.cicpxlvl AND dbo.AB_CMG.CMG = dbo.CMG_ETC_2002O.cmgcode
WHERE     (dbo.AB_CMG.CMG_Year IN (2002, 2003, 2004)) AND 
(((dbo.AB_Abstract.AgeCode = 3) AND (dbo.AB_Abstract.AgeNumber BETWEEN 18 AND 68) 
    AND (dbo.CMG_ETC_2002O.ciagegroup = 2))
or ((((dbo.AB_Abstract.AgeCode = 3) AND (dbo.AB_Abstract.AgeNumber BETWEEN 0 AND 17)) 
    or (dbo.AB_Abstract.AgeCode <> 3)) AND (dbo.CMG_ETC_2002O.ciagegroup = 1))
or ((dbo.AB_Abstract.AgeCode = 3) AND (dbo.AB_Abstract.AgeNumber > 68) 
    AND (dbo.CMG_ETC_2002O.ciagegroup = 3))
)

--Old Stuff
-- SELECT  AB_CMG.CMG, AB_CMG.CMG_Year, 
--         dbo.CMG_ETC_2002O.TenthPercent, dbo.CMG_ETC_2002O.TwentyFifthPercent, 
--         dbo.CMG_ETC_2002O.FiftiethPercent, dbo.AB_CMG.AbstractID AS zzAbstractLink
-- FROM         dbo.AB_CMG LEFT OUTER JOIN
--     dbo.AB_Abstract ON dbo.AB_CMG.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
--     dbo.CMG_ETC_2002O ON dbo.AB_CMG.Complexity = dbo.CMG_ETC_2002O.cicpxlvl AND dbo.AB_CMG.CMG = dbo.CMG_ETC_2002O.cmgcode
-- WHERE     (dbo.AB_CMG.CMG_Year IN (2002, 2003, 2004)) AND (dbo.AB_Abstract.AgeCode = 3) AND (dbo.AB_Abstract.AgeNumber BETWEEN 18 AND 68) AND 
--                       (dbo.CMG_ETC_2002O.ciagegroup = 2)
-- union all
-- SELECT  AB_CMG.CMG, AB_CMG.CMG_Year, 
--         dbo.CMG_ETC_2002O.TenthPercent, dbo.CMG_ETC_2002O.TwentyFifthPercent, 
--         dbo.CMG_ETC_2002O.FiftiethPercent, dbo.AB_CMG.AbstractID AS zzAbstractLink
-- FROM         dbo.AB_CMG LEFT OUTER JOIN
--     dbo.AB_Abstract ON dbo.AB_CMG.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
--     dbo.CMG_ETC_2002O ON dbo.AB_CMG.Complexity = dbo.CMG_ETC_2002O.cicpxlvl AND dbo.AB_CMG.CMG = dbo.CMG_ETC_2002O.cmgcode
-- WHERE     (dbo.AB_CMG.CMG_Year IN (2002, 2003, 2004)) AND (dbo.AB_Abstract.AgeCode = 3) AND (dbo.AB_Abstract.AgeNumber BETWEEN 0 AND 17) AND 
--                       (dbo.CMG_ETC_2002O.ciagegroup = 1) OR
--                       (dbo.AB_CMG.CMG_Year in (2002, 2003, 2004)) AND (dbo.AB_Abstract.AgeCode <> 3) AND (dbo.CMG_ETC_2002O.ciagegroup = 1)
-- union all
-- SELECT  AB_CMG.CMG, AB_CMG.CMG_Year, 
--         dbo.CMG_ETC_2002O.TenthPercent, dbo.CMG_ETC_2002O.TwentyFifthPercent, 
--         dbo.CMG_ETC_2002O.FiftiethPercent, dbo.AB_CMG.AbstractID AS zzAbstractLink
-- FROM         dbo.AB_CMG LEFT OUTER JOIN
--     dbo.AB_Abstract ON dbo.AB_CMG.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
--     dbo.CMG_ETC_2002O ON dbo.AB_CMG.Complexity = dbo.CMG_ETC_2002O.cicpxlvl AND dbo.AB_CMG.CMG = dbo.CMG_ETC_2002O.cmgcode
-- WHERE     (dbo.AB_CMG.CMG_Year IN (2002, 2003, 2004)) AND (dbo.AB_Abstract.AgeCode = 3) AND (dbo.AB_Abstract.AgeNumber > 68) AND 
--                       (dbo.CMG_ETC_2002O.ciagegroup = 3)








' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_CRS_General_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE   VIEW [dbo].[I10_CRS_General_VR]
AS
SELECT     
--Demographic
    dbo.CRS_Demographic.AbstractID AS zzAbstractLink, dbo.CRS_Demographic.LinkID AS zzLinkBackgroudID, LU_AA8.DisplayCode AS AA8, 
    LU_AA8.UserDescription AS AA8_Desc, dbo.CRS_Demographic.AA1, dbo.CRS_Demographic.ChartNumber, dbo.CRS_Demographic.RegisterNumber, 
    dbo.CRS_Demographic.AdmitDate, dbo.CRS_Demographic.Z7, dbo.CRS_Demographic.A3, dbo.CRS_Demographic.DischargeDate, 
    dbo.CRS_Demographic.AB1b, dbo.CRS_Demographic.MaidenName, dbo.CRS_Demographic.LastName, dbo.CRS_Demographic.MiddleName, 
    dbo.CRS_Demographic.FirstName, dbo.LU_NurseArea.DisplayCode AS AdmittingNurseArea, 
    dbo.LU_NurseArea.UserDescription AS AdmittingNurseArea_Desc, dbo.CRS_Demographic.RoomNumber, LU_Gender.DisplayCode AS Gender, 
    LU_Gender.UserDescription AS Gender_Desc, dbo.CRS_Demographic.BirthDate, dbo.CRS_Demographic.AA4a, 
    LU_MaritalStatus.DisplayCode AS MaritalStatus, LU_MaritalStatus.UserDescription AS MaritalStatus_Desc, dbo.CRS_Demographic.HealthCareNumber, 
    dbo.LU_HCNProvince.DisplayCode AS HCNProvince, dbo.LU_HCNProvince.UserDescription AS HCNProvince_Desc, 
    dbo.H_InstitutionProfile.DisplayCode AS InstitutionNumber, dbo.H_InstitutionProfile.UserDescription AS InstitutionNumber_Desc, 
    LU_AB2a.DisplayCode AS AB2a, LU_AB2a.UserDescription AS AB2a_Desc, LU_AB2c.DisplayCode AS AB2c, LU_AB2c.UserDescription AS AB2c_Desc, 
    LU_Inst_From.DisplayCode AS InstitutionFrom, LU_Inst_From.UserDescription AS InstitutionFrom_Desc, LU_R3a.DisplayCode AS R3a, 
    LU_R3a.UserDescription AS R3a_Desc, LU_Inst_To.DisplayCode AS InstitutionTo, LU_Inst_To.UserDescription AS InstitutionTo_Desc, 
    LU_Z1.DisplayCode AS Z1, LU_Z1.UserDescription AS Z1_Desc, dbo.CRS_Demographic.IsCurrent, LU_IsSubmited.DisplayCode AS IsSubmited, 
    LU_IsSubmited.UserDescription AS IsSubmited_Desc, LU_IsValidated.DisplayCode AS IsValidated, 
    LU_IsValidated.UserDescription AS IsValidated_Desc, LU_IsCompleted.DisplayCode AS IsCompleted, 
    LU_IsCompleted.UserDescription AS IsCompleted_Desc, LU_IsDeleted.DisplayCode AS IsDeleted, LU_IsDeleted.UserDescription AS IsDeleted_Desc, 
    dbo.LU_Site.DisplayCode AS SiteNumber, dbo.LU_Site.UserDescription AS SiteNumber_Desc, LU_Coder.DisplayCode AS CoderNumber, 
    LU_Coder.UserDescription AS CoderNumber_Desc, dbo.CRS_Demographic.HCNVersion, dbo.CRS_Demographic.ZA6b, dbo.CRS_Demographic.ZAB1, 
    dbo.CRS_Demographic.ZR4, dbo.CRS_Demographic.InterfaceDate, dbo.CRS_Demographic.InterfaceTime, 
    U_InterfaceCoder.DisplayCode AS InterfaceCoder, U_InterfaceCoder.UserDescription AS InterfaceCoder_Desc, dbo.CRS_Demographic.InputDate, 
    dbo.CRS_Demographic.InputTime, U_DataEntryCoder.DisplayCode AS DataEntryCoder, U_DataEntryCoder.UserDescription AS DataEntryCoder_Desc, 
    dbo.CRS_Demographic.FinishDate, dbo.CRS_Demographic.FinishTime, LU_Secret.DisplayCode AS Secret, LU_Secret.UserDescription AS Secret_Desc,
     dbo.CRS_Demographic.TSIDate, dbo.CRS_Demographic.TSITime, U_TSICoder.DisplayCode AS TSICoder, 
    U_TSICoder.UserDescription AS TSICoder_Desc, LU_BirthDateEstimated.DisplayCode AS BirthDateEstimated, 
    LU_BirthDateEstimated.UserDescription AS BirthDateEstimated_Desc,
--Full 1
    (case CRS_AssessFull1.A7a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as A7a, 
    (case CRS_AssessFull1.A7a when 1 then Y.UserDescription when 2 then N.UserDescription end) as A7a_Desc, 
    (case CRS_AssessFull1.A7b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as A7b, 
    (case CRS_AssessFull1.A7b when 1 then Y.UserDescription when 2 then N.UserDescription end) as A7b_Desc, 
    (case CRS_AssessFull1.A7c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as A7c, 
    (case CRS_AssessFull1.A7c when 1 then Y.UserDescription when 2 then N.UserDescription end) as A7c_Desc, 
    (case CRS_AssessFull1.A7d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as A7d, 
    (case CRS_AssessFull1.A7d when 1 then Y.UserDescription when 2 then N.UserDescription end) as A7d_Desc, 
    (case CRS_AssessFull1.A7e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as A7e, 
    (case CRS_AssessFull1.A7e when 1 then Y.UserDescription when 2 then N.UserDescription end) as A7e_Desc, 
    (case CRS_AssessFull1.A7f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as A7f, 
    (case CRS_AssessFull1.A7f when 1 then Y.UserDescription when 2 then N.UserDescription end) as A7f_Desc, 
    (case CRS_AssessFull1.A7g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as A7g, 
    (case CRS_AssessFull1.A7g when 1 then Y.UserDescription when 2 then N.UserDescription end) as A7g_Desc, 
    (case CRS_AssessFull1.A7h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as A7h, 
    (case CRS_AssessFull1.A7h when 1 then Y.UserDescription when 2 then N.UserDescription end) as A7h_Desc, 
    (case CRS_AssessFull1.A7I when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as A7I, 
    (case CRS_AssessFull1.A7I when 1 then Y.UserDescription when 2 then N.UserDescription end) as A7I_Desc, 
    (case CRS_AssessFull1.A7j when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as A7j, 
    (case CRS_AssessFull1.A7j when 1 then Y.UserDescription when 2 then N.UserDescription end) as A7j_Desc, 
    (case CRS_AssessFull1.A7k when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as A7k, 
    (case CRS_AssessFull1.A7k when 1 then Y.UserDescription when 2 then N.UserDescription end) as A7k_Desc, 

    LU_C1.DisplayCode AS C1, LU_C1.UserDescription AS C1_Desc, 
    (case when CRS_AssessFull1.C2All > 0 then Y1.DisplayCode end) as C2All, 
    (case when CRS_AssessFull1.C2All > 0 then Y1.UserDescription end) as C2All_Desc, 
    LU_C2a.DisplayCode AS C2a, LU_C2a.UserDescription AS C2a_Desc, 
    LU_C2b.DisplayCode AS C2b, LU_C2b.UserDescription AS C2b_Desc, 
    LU_C2c.DisplayCode AS C2c, LU_C2c.UserDescription AS C2c_Desc, 
    (case when CRS_AssessFull1.C3All > 0 then Y1.DisplayCode end) as C3All, 
    (case when CRS_AssessFull1.C3All > 0 then Y1.UserDescription end) as C3All_Desc, 
    LU_C3a.DisplayCode AS C3a, LU_C3a.UserDescription AS C3a_Desc, 
    LU_C3b.DisplayCode AS C3b, LU_C3b.UserDescription AS C3b_Desc, LU_C3c.DisplayCode AS C3c, LU_C3c.UserDescription AS C3c_Desc, 
    LU_C3d.DisplayCode AS C3d, LU_C3d.UserDescription AS C3d_Desc, LU_C3e.DisplayCode AS C3e, LU_C3e.UserDescription AS C3e_Desc, 
    LU_C3f.DisplayCode AS C3f, LU_C3f.UserDescription AS C3f_Desc, LU_C5.DisplayCode AS C5, LU_C5.UserDescription AS C5_Desc, 
    LU_D1.DisplayCode AS D1, LU_D1.UserDescription AS D1_Desc, LU_D2a.DisplayCode AS D2a, LU_D2a.UserDescription AS D2a_Desc, 
    LU_D2b.DisplayCode AS D2b, LU_D2b.UserDescription AS D2b_Desc, LU_D3.DisplayCode AS D3, LU_D3.UserDescription AS D3_Desc, 
    (case when CRS_AssessFull1.F2All > 0 then Y1.DisplayCode end) as F2All, 
    (case when CRS_AssessFull1.F2All > 0 then Y1.UserDescription end) as F2All_Desc, 
    LU_F2a.DisplayCode AS F2a, LU_F2a.UserDescription AS F2a_Desc, 
    LU_F2b.DisplayCode AS F2b, LU_F2b.UserDescription AS F2b_Desc, LU_F2c.DisplayCode AS F2c, LU_F2c.UserDescription AS F2c_Desc, 
    LU_F2d.DisplayCode AS F2d, LU_F2d.UserDescription AS F2d_Desc, LU_F2e.DisplayCode AS F2e, LU_F2e.UserDescription AS F2e_Desc, 
    LU_F2f.DisplayCode AS F2f, LU_F2f.UserDescription AS F2f_Desc, LU_F2g.DisplayCode AS F2g, LU_F2g.UserDescription AS F2g_Desc, 
    LU_F3a.DisplayCode AS F3a, LU_F3a.UserDescription AS F3a_Desc, LU_F3b.DisplayCode AS F3b, LU_F3b.UserDescription AS F3b_Desc, 
    LU_F3c.DisplayCode AS F3c, LU_F3c.UserDescription AS F3c_Desc, 

    (case when CRS_AssessFull1.G5All > 0 then Y1.DisplayCode end) as G5All, 
    (case when CRS_AssessFull1.G5All > 0 then Y1.UserDescription end) as G5All_Desc, 
    (case CRS_AssessFull1.G5a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as G5a, 
    (case CRS_AssessFull1.G5a when 1 then Y.UserDescription when 2 then N.UserDescription end) as G5a_Desc, 
    (case CRS_AssessFull1.G5b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as G5b, 
    (case CRS_AssessFull1.G5b when 1 then Y.UserDescription when 2 then N.UserDescription end) as G5b_Desc, 
    (case CRS_AssessFull1.G5c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as G5c, 
    (case CRS_AssessFull1.G5c when 1 then Y.UserDescription when 2 then N.UserDescription end) as G5c_Desc, 
    (case CRS_AssessFull1.G5d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as G5d, 
    (case CRS_AssessFull1.G5d when 1 then Y.UserDescription when 2 then N.UserDescription end) as G5d_Desc, 

    (case when CRS_AssessFull1.G8All > 0 then Y1.DisplayCode end) as G8All, 
    (case when CRS_AssessFull1.G8All > 0 then Y1.UserDescription end) as G8All_Desc, 
    (case CRS_AssessFull1.G8a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as G8a, 
    (case CRS_AssessFull1.G8a when 1 then Y.UserDescription when 2 then N.UserDescription end) as G8a_Desc, 
    (case CRS_AssessFull1.G8b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as G8b, 
    (case CRS_AssessFull1.G8b when 1 then Y.UserDescription when 2 then N.UserDescription end) as G8b_Desc, 
    (case CRS_AssessFull1.G8c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as G8c, 
    (case CRS_AssessFull1.G8c when 1 then Y.UserDescription when 2 then N.UserDescription end) as G8c_Desc, 
    (case CRS_AssessFull1.G8d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as G8d, 
    (case CRS_AssessFull1.G8d when 1 then Y.UserDescription when 2 then N.UserDescription end) as G8d_Desc, 

    LU_J3a.DisplayCode AS J3a, LU_J3a.UserDescription AS J3a_Desc, 
    LU_J3b.DisplayCode AS J3b, LU_J3b.UserDescription AS J3b_Desc, LU_J3c.DisplayCode AS J3c, LU_J3c.UserDescription AS J3c_Desc, 
    LU_J3d.DisplayCode AS J3d, LU_J3d.UserDescription AS J3d_Desc, LU_J3e.DisplayCode AS J3e, LU_J3e.UserDescription AS J3e_Desc, 
    LU_J3f.DisplayCode AS J3f, LU_J3f.UserDescription AS J3f_Desc, LU_J3g.DisplayCode AS J3g, LU_J3g.UserDescription AS J3g_Desc, 
    LU_J3h.DisplayCode AS J3h, LU_J3h.UserDescription AS J3h_Desc, LU_J3I.DisplayCode AS J3I, LU_J3I.UserDescription AS J3I_Desc, 
    LU_J3j.DisplayCode AS J3j, LU_J3j.UserDescription AS J3j_Desc, 
--Full 2
    (case when CRS_AssessFull2.L1All > 0 then Y1.DisplayCode end) as L1All, 
    (case when CRS_AssessFull2.L1All > 0 then Y1.UserDescription end) as L1All_Desc, 
    (case CRS_AssessFull2.L1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as L1a, 
    (case CRS_AssessFull2.L1a when 1 then Y.UserDescription when 2 then N.UserDescription end) as L1a_Desc, 
    (case CRS_AssessFull2.L1b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as L1b, 
    (case CRS_AssessFull2.L1b when 1 then Y.UserDescription when 2 then N.UserDescription end) as L1b_Desc, 
    (case CRS_AssessFull2.L1c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as L1c, 
    (case CRS_AssessFull2.L1c when 1 then Y.UserDescription when 2 then N.UserDescription end) as L1c_Desc, 
    (case CRS_AssessFull2.L1d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as L1d, 
    (case CRS_AssessFull2.L1d when 1 then Y.UserDescription when 2 then N.UserDescription end) as L1d_Desc, 
    (case CRS_AssessFull2.L1e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as L1e, 
    (case CRS_AssessFull2.L1e when 1 then Y.UserDescription when 2 then N.UserDescription end) as L1e_Desc, 
    (case CRS_AssessFull2.L1f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as L1f, 
    (case CRS_AssessFull2.L1f when 1 then Y.UserDescription when 2 then N.UserDescription end) as L1f_Desc, 
    (case CRS_AssessFull2.M3 when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M3, 
    (case CRS_AssessFull2.M3 when 1 then Y.UserDescription when 2 then N.UserDescription end) as M3_Desc, 

    (case when CRS_AssessFull2.N3All > 0 then Y1.DisplayCode end) as N3All, 
    (case when CRS_AssessFull2.N3All > 0 then Y1.UserDescription end) as N3All_Desc, 
    LU_N3a.DisplayCode AS N3a, LU_N3a.UserDescription AS N3a_Desc, 
    LU_N3b.DisplayCode AS N3b, LU_N3b.UserDescription AS N3b_Desc, LU_N3c.DisplayCode AS N3c, LU_N3c.UserDescription AS N3c_Desc, 
    LU_N3d.DisplayCode AS N3d, LU_N3d.UserDescription AS N3d_Desc, 
    (case when CRS_AssessFull2.N4All > 0 then Y1.DisplayCode end) as N4All, 
    (case when CRS_AssessFull2.N4All > 0 then Y1.UserDescription end) as N4All_Desc, 
    LU_N4a.DisplayCode AS N4a, LU_N4a.UserDescription AS N4a_Desc, LU_N4b.DisplayCode AS N4b, LU_N4b.UserDescription AS N4b_Desc, 
    LU_N4c.DisplayCode AS N4c, LU_N4c.UserDescription AS N4c_Desc, LU_N4d.DisplayCode AS N4d, LU_N4d.UserDescription AS N4d_Desc, 
    LU_N4e.DisplayCode AS N4e, LU_N4e.UserDescription AS N4e_Desc, LU_N4f.DisplayCode AS N4f, LU_N4f.UserDescription AS N4f_Desc, 
    LU_N4g.DisplayCode AS N4g, LU_N4g.UserDescription AS N4g_Desc, LU_N4h.DisplayCode AS N4h, LU_N4h.UserDescription AS N4h_Desc, 
    LU_N4I.DisplayCode AS N4I, LU_N4I.UserDescription AS N4I_Desc, LU_N4j.DisplayCode AS N4j, LU_N4j.UserDescription AS N4j_Desc, 
    LU_N4k.DisplayCode AS N4k, LU_N4k.UserDescription AS N4k_Desc, LU_N4l.DisplayCode AS N4l, LU_N4l.UserDescription AS N4l_Desc, 
    LU_N5a.DisplayCode AS N5a, LU_N5a.UserDescription AS N5a_Desc, LU_N5b.DisplayCode AS N5b, LU_N5b.UserDescription AS N5b_Desc, 
    LU_O2.DisplayCode AS O2, LU_O2.UserDescription AS O2_Desc, 

    (case when CRS_AssessFull2.P2All > 0 then Y1.DisplayCode end) as P2All, 
    (case when CRS_AssessFull2.P2All > 0 then Y1.UserDescription end) as P2All_Desc, 
    (case CRS_AssessFull2.P2a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P2a, 
    (case CRS_AssessFull2.P2a when 1 then Y.UserDescription when 2 then N.UserDescription end) as P2a_Desc, 
    (case CRS_AssessFull2.P2b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P2b, 
    (case CRS_AssessFull2.P2b when 1 then Y.UserDescription when 2 then N.UserDescription end) as P2b_Desc, 
    (case CRS_AssessFull2.P2c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P2c, 
    (case CRS_AssessFull2.P2c when 1 then Y.UserDescription when 2 then N.UserDescription end) as P2c_Desc, 
    (case CRS_AssessFull2.P2d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P2d, 
    (case CRS_AssessFull2.P2d when 1 then Y.UserDescription when 2 then N.UserDescription end) as P2d_Desc, 
    (case CRS_AssessFull2.P2e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P2e, 
    (case CRS_AssessFull2.P2e when 1 then Y.UserDescription when 2 then N.UserDescription end) as P2e_Desc, 

    dbo.CRS_AssessFull2.P5, dbo.CRS_AssessFull2.P6, 
    (case CRS_AssessFull2.P9 when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P9, 
    (case CRS_AssessFull2.P9 when 1 then Y.UserDescription when 2 then N.UserDescription end) as P9_Desc, 
    (case CRS_AssessFull2.Q1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Q1a, 
    (case CRS_AssessFull2.Q1a when 1 then Y.UserDescription when 2 then N.UserDescription end) as Q1a_Desc, 
    (case CRS_AssessFull2.Q1b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Q1b, 
    (case CRS_AssessFull2.Q1b when 1 then Y.UserDescription when 2 then N.UserDescription end) as Q1b_Desc, 
    LU_Q1c.DisplayCode AS Q1c, LU_Q1c.UserDescription AS Q1c_Desc, 
    (case CRS_AssessFull2.R1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as R1a, 
    (case CRS_AssessFull2.R1a when 1 then Y.UserDescription when 2 then N.UserDescription end) as R1a_Desc, 
    LU_R1b.DisplayCode AS R1b, LU_R1b.UserDescription AS R1b_Desc, LU_R1c.DisplayCode AS R1c, 
    LU_R1c.UserDescription AS R1c_Desc, 

--Share 1

    (case when CRS_AssessShare1.A9All > 0 then Y1.DisplayCode end) as A9All, 
    (case when CRS_AssessShare1.A9All > 0 then Y1.UserDescription end) as A9All_Desc, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9a_Q.DisplayCode else (case CRS_AssessShare1.A9a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS A9a, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9a_Q.UserDescription else (case CRS_AssessShare1.A9a when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS A9a_Desc, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9b_Q.DisplayCode else (case CRS_AssessShare1.A9b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS A9b, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9b_Q.UserDescription else (case CRS_AssessShare1.A9b when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS A9b_Desc, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9c_Q.DisplayCode else (case CRS_AssessShare1.A9c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS A9c, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9c_Q.UserDescription else (case CRS_AssessShare1.A9c when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS A9c_Desc, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9d_Q.DisplayCode else (case CRS_AssessShare1.A9d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS A9d, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9d_Q.UserDescription else (case CRS_AssessShare1.A9d when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS A9d_Desc, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9e_Q.DisplayCode else (case CRS_AssessShare1.A9e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS A9e, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9e_Q.UserDescription else (case CRS_AssessShare1.A9e when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS A9e_Desc, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9f_Q.DisplayCode else (case CRS_AssessShare1.A9f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS A9f, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9f_Q.UserDescription else (case CRS_AssessShare1.A9f when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS A9f_Desc, 

    (case when CRS_AssessShare1.A10All > 0 then Y1.DisplayCode end) as A10All, 
    (case when CRS_AssessShare1.A10All > 0 then Y1.UserDescription end) as A10All_Desc, 

    (case when LU_AA8.CIHIValue = ''05'' then LU_A10a_Q.DisplayCode else (case CRS_AssessShare1.A10a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS A10a, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10a_Q.UserDescription else (case CRS_AssessShare1.A10a when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS A10a_Desc, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10b_Q.DisplayCode else (case CRS_AssessShare1.A10b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS A10b, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10b_Q.UserDescription else (case CRS_AssessShare1.A10b when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS A10b_Desc, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10c_Q.DisplayCode else (case CRS_AssessShare1.A10c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS A10c, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10c_Q.UserDescription else (case CRS_AssessShare1.A10c when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS A10c_Desc, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10d_Q.DisplayCode else (case CRS_AssessShare1.A10d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS A10d, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10d_Q.UserDescription else (case CRS_AssessShare1.A10d when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS A10d_Desc, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10e_Q.DisplayCode else (case CRS_AssessShare1.A10e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS A10e, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10e_Q.UserDescription else (case CRS_AssessShare1.A10e when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS A10e_Desc, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10f_Q.DisplayCode else (case CRS_AssessShare1.A10f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS A10f, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10f_Q.UserDescription else (case CRS_AssessShare1.A10f when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS A10f_Desc, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10g_Q.DisplayCode else (case CRS_AssessShare1.A10g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS A10g, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10g_Q.UserDescription else (case CRS_AssessShare1.A10g when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS A10g_Desc, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10h_Q.DisplayCode else (case CRS_AssessShare1.A10h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS A10h, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10h_Q.UserDescription else (case CRS_AssessShare1.A10h when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS A10h_Desc, 

    (case CRS_AssessShare1.B1 when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS B1, 
    (case CRS_AssessShare1.B1 when 1 then Y.UserDescription when 2 then N.UserDescription end) AS B1_Desc, 

    LU_B2a.DisplayCode AS B2a, LU_B2a.UserDescription AS B2a_Desc, 
    LU_B2b.DisplayCode AS B2b, LU_B2b.UserDescription AS B2b_Desc, 
    (case when CRS_AssessShare1.B3All > 0 then Y1.DisplayCode end) as B3All, 
    (case when CRS_AssessShare1.B3All > 0 then Y1.UserDescription end) as B3All_Desc, 
    LU_B3a.DisplayCode AS B3a, LU_B3a.UserDescription AS B3a_Desc, LU_B3b.DisplayCode AS B3b, LU_B3b.UserDescription AS B3b_Desc, 
    LU_B3c.DisplayCode AS B3c, LU_B3c.UserDescription AS B3c_Desc, LU_B3d.DisplayCode AS B3d, LU_B3d.UserDescription AS B3d_Desc, 
    LU_B4.DisplayCode AS B4, LU_B4.UserDescription AS B4_Desc, LU_B5a.DisplayCode AS B5a, LU_B5a.UserDescription AS B5a_Desc, 
    LU_B5b.DisplayCode AS B5b, LU_B5b.UserDescription AS B5b_Desc, LU_B5c.DisplayCode AS B5c, LU_B5c.UserDescription AS B5c_Desc, 
    LU_B5d.DisplayCode AS B5d, LU_B5d.UserDescription AS B5d_Desc, LU_B5e.DisplayCode AS B5e, LU_B5e.UserDescription AS B5e_Desc, 
    LU_B5f.DisplayCode AS B5f, LU_B5f.UserDescription AS B5f_Desc, LU_B6.DisplayCode AS B6, LU_B6.UserDescription AS B6_Desc, 
    LU_C4.DisplayCode AS C4, LU_C4.UserDescription AS C4_Desc, LU_C6.DisplayCode AS C6, LU_C6.UserDescription AS C6_Desc, 
    LU_C7.DisplayCode AS C7, LU_C7.UserDescription AS C7_Desc, LU_E1a.DisplayCode AS E1a, LU_E1a.UserDescription AS E1a_Desc, 
    LU_E1b.DisplayCode AS E1b, LU_E1b.UserDescription AS E1b_Desc, LU_E1c.DisplayCode AS E1c, LU_E1c.UserDescription AS E1c_Desc, 
    LU_E1d.DisplayCode AS E1d, LU_E1d.UserDescription AS E1d_Desc, LU_E1e.DisplayCode AS E1e, LU_E1e.UserDescription AS E1e_Desc, 
    LU_E1f.DisplayCode AS E1f, LU_E1f.UserDescription AS E1f_Desc, LU_E1g.DisplayCode AS E1g, LU_E1g.UserDescription AS E1g_Desc, 
    LU_E1h.DisplayCode AS E1h, LU_E1h.UserDescription AS E1h_Desc, LU_E1I.DisplayCode AS E1I, LU_E1I.UserDescription AS E1I_Desc, 
    LU_E1j.DisplayCode AS E1j, LU_E1j.UserDescription AS E1j_Desc, LU_E1k.DisplayCode AS E1k, LU_E1k.UserDescription AS E1k_Desc, 
    LU_E1l.DisplayCode AS E1l, LU_E1l.UserDescription AS E1l_Desc, LU_E1m.DisplayCode AS E1m, LU_E1m.UserDescription AS E1m_Desc, 
    LU_E1n.DisplayCode AS E1n, LU_E1n.UserDescription AS E1n_Desc, LU_E1o.DisplayCode AS E1o, LU_E1o.UserDescription AS E1o_Desc, 
    LU_E1p.DisplayCode AS E1p, LU_E1p.UserDescription AS E1p_Desc, LU_E2.DisplayCode AS E2, LU_E2.UserDescription AS E2_Desc, 
    LU_E3.DisplayCode AS E3, LU_E3.UserDescription AS E3_Desc, LU_E4aA.DisplayCode AS E4aA, LU_E4aA.UserDescription AS E4aA_Desc, 
    LU_E4aB.DisplayCode AS E4aB, LU_E4aB.UserDescription AS E4aB_Desc, LU_E4bA.DisplayCode AS E4bA, LU_E4bA.UserDescription AS E4bA_Desc, 
    LU_E4bB.DisplayCode AS E4bB, LU_E4bB.UserDescription AS E4bB_Desc, LU_E4cA.DisplayCode AS E4cA, LU_E4cA.UserDescription AS E4cA_Desc, 
    LU_E4cB.DisplayCode AS E4cB, LU_E4cB.UserDescription AS E4cB_Desc, LU_E4dA.DisplayCode AS E4dA, LU_E4dA.UserDescription AS E4dA_Desc, 
    LU_E4dB.DisplayCode AS E4dB, LU_E4dB.UserDescription AS E4dB_Desc, LU_E4eA.DisplayCode AS E4eA, LU_E4eA.UserDescription AS E4eA_Desc, 
    LU_E4eB.DisplayCode AS E4eB, LU_E4eB.UserDescription AS E4eB_Desc, LU_E5.DisplayCode AS E5, LU_E5.UserDescription AS E5_Desc, 

--Share 2
    (case when CRS_AssessShare2.F1All > 0 then Y1.DisplayCode end) as F1All, 
    (case when CRS_AssessShare2.F1All > 0 then Y1.UserDescription end) as F1All_Desc, 
    LU_F1a.DisplayCode AS F1a, LU_F1a.UserDescription AS F1a_Desc, LU_F1b.DisplayCode AS F1b, LU_F1b.UserDescription AS F1b_Desc, 
    LU_F1c.DisplayCode AS F1c, LU_F1c.UserDescription AS F1c_Desc, LU_F1d.DisplayCode AS F1d, LU_F1d.UserDescription AS F1d_Desc, 
    LU_F1e.DisplayCode AS F1e, LU_F1e.UserDescription AS F1e_Desc, LU_F1f.DisplayCode AS F1f, LU_F1f.UserDescription AS F1f_Desc, 
    LU_G1aA.DisplayCode AS G1aA, LU_G1aA.UserDescription AS G1aA_Desc, LU_G1aB.DisplayCode AS G1aB, 
    LU_G1aB.UserDescription AS G1aB_Desc, LU_G1bA.DisplayCode AS G1bA, LU_G1bA.UserDescription AS G1bA_Desc, 
    LU_G1bB.DisplayCode AS G1bB, LU_G1bB.UserDescription AS G1bB_Desc, LU_G1cA.DisplayCode AS G1cA, LU_G1cA.UserDescription AS G1cA_Desc,
    LU_G1cB.DisplayCode AS G1cB, LU_G1cB.UserDescription AS G1cB_Desc, LU_G1dA.DisplayCode AS G1dA, 
    LU_G1dA.UserDescription AS G1dA_Desc, LU_G1dB.DisplayCode AS G1dB, LU_G1dB.UserDescription AS G1dB_Desc, 
    LU_G1eA.DisplayCode AS G1eA, LU_G1eA.UserDescription AS G1eA_Desc, LU_G1eB.DisplayCode AS G1eB, 
    LU_G1eB.UserDescription AS G1eB_Desc, LU_G1fA.DisplayCode AS G1fA, LU_G1fA.UserDescription AS G1fA_Desc, LU_G1fB.DisplayCode AS G1fB, 
    LU_G1fB.UserDescription AS G1fB_Desc, LU_G1gA.DisplayCode AS G1gA, LU_G1gA.UserDescription AS G1gA_Desc, LU_G1gB.DisplayCode AS G1gB, 
    LU_G1gB.UserDescription AS G1gB_Desc, LU_G1hA.DisplayCode AS G1hA, LU_G1hA.UserDescription AS G1hA_Desc, 
    LU_G1hB.DisplayCode AS G1hB, LU_G1hB.UserDescription AS G1hB_Desc, LU_G1IA.DisplayCode AS G1IA, LU_G1IA.UserDescription AS G1IA_Desc, 
    LU_G1IB.DisplayCode AS G1IB, LU_G1IB.UserDescription AS G1IB_Desc, LU_G1jA.DisplayCode AS G1jA, LU_G1jA.UserDescription AS G1jA_Desc, 
    LU_G1jB.DisplayCode AS G1jB, LU_G1jB.UserDescription AS G1jB_Desc, LU_G2A.DisplayCode AS G2A, LU_G2A.UserDescription AS G2A_Desc, 
    LU_G2B.DisplayCode AS G2B, LU_G2B.UserDescription AS G2B_Desc, LU_G3a.DisplayCode AS G3a, LU_G3a.UserDescription AS G3a_Desc, 
    LU_G3b.DisplayCode AS G3b, LU_G3b.UserDescription AS G3b_Desc, LU_G4aA.DisplayCode AS G4aA, LU_G4aA.UserDescription AS G4aA_Desc, 
    LU_G4aB.DisplayCode AS G4aB, LU_G4aB.UserDescription AS G4aB_Desc, LU_G4bA.DisplayCode AS G4bA, 
    LU_G4bA.UserDescription AS G4bA_Desc, LU_G4bB.DisplayCode AS G4bB, LU_G4bB.UserDescription AS G4bB_Desc, 
    LU_G4cA.DisplayCode AS G4cA, LU_G4cA.UserDescription AS G4cA_Desc, LU_G4cB.DisplayCode AS G4cB, LU_G4cB.UserDescription AS G4cB_Desc, 
    LU_G4dA.DisplayCode AS G4dA, LU_G4dA.UserDescription AS G4dA_Desc, LU_G4dB.DisplayCode AS G4dB, 
    LU_G4dB.UserDescription AS G4dB_Desc, LU_G4eA.DisplayCode AS G4eA, LU_G4eA.UserDescription AS G4eA_Desc, 
    LU_G4eB.DisplayCode AS G4eB, LU_G4eB.UserDescription AS G4eB_Desc, LU_G4fA.DisplayCode AS G4fA, LU_G4fA.UserDescription AS G4fA_Desc, 
    LU_G4fB.DisplayCode AS G4fB, LU_G4fB.UserDescription AS G4fB_Desc, 

    (case when CRS_AssessShare2.G6All > 0 then Y1.DisplayCode end) as G6All, 
    (case when CRS_AssessShare2.G6All > 0 then Y1.UserDescription end) as G6All_Desc, 

    (case CRS_AssessShare2.G6a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS G6a, 
    (case CRS_AssessShare2.G6a when 1 then Y.UserDescription when 2 then N.UserDescription end) AS G6a_Desc, 
    (case CRS_AssessShare2.G6b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS G6b, 
    (case CRS_AssessShare2.G6b when 1 then Y.UserDescription when 2 then N.UserDescription end) AS G6b_Desc, 
    (case CRS_AssessShare2.G6c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS G6c, 
    (case CRS_AssessShare2.G6c when 1 then Y.UserDescription when 2 then N.UserDescription end) AS G6c_Desc, 
    (case CRS_AssessShare2.G6d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS G6d,
    (case CRS_AssessShare2.G6d when 1 then Y.UserDescription when 2 then N.UserDescription end) AS G6d_Desc, 
    (case CRS_AssessShare2.G6e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS G6e, 
    (case CRS_AssessShare2.G6e when 1 then Y.UserDescription when 2 then N.UserDescription end) AS G6e_Desc, 
    (case CRS_AssessShare2.G7 when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS G7, 
    (case CRS_AssessShare2.G7 when 1 then Y.UserDescription when 2 then N.UserDescription end) AS G7_Desc, 

    LU_G9.DisplayCode AS G9, LU_G9.UserDescription AS G9_Desc, 

    LU_H1a.DisplayCode AS H1a, LU_H1a.UserDescription AS H1a_Desc, 
    LU_H1b.DisplayCode AS H1b, LU_H1b.UserDescription AS H1b_Desc, 
    (case when CRS_AssessShare2.H2All > 0 then Y1.DisplayCode end) as H2All, 
    (case when CRS_AssessShare2.H2All > 0 then Y1.UserDescription end) as H2All_Desc, 
    (case CRS_AssessShare2.H2a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS H2a, 
    (case CRS_AssessShare2.H2a when 1 then Y.UserDescription when 2 then N.UserDescription end) AS H2a_Desc, 
    (case CRS_AssessShare2.H2b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS H2b, 
    (case CRS_AssessShare2.H2b when 1 then Y.UserDescription when 2 then N.UserDescription end) AS H2b_Desc, 
    (case CRS_AssessShare2.H2c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS H2c, 
    (case CRS_AssessShare2.H2c when 1 then Y.UserDescription when 2 then N.UserDescription end) AS H2c_Desc, 
    (case CRS_AssessShare2.H2d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS H2d, 
    (case CRS_AssessShare2.H2d when 1 then Y.UserDescription when 2 then N.UserDescription end) AS H2d_Desc, 

    (case when CRS_AssessShare2.H3All > 0 then Y1.DisplayCode end) as H3All, 
    (case when CRS_AssessShare2.H3All > 0 then Y1.UserDescription end) as H3All_Desc, 
    (case CRS_AssessShare2.H3a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS H3a, 
    (case CRS_AssessShare2.H3a when 1 then Y.UserDescription when 2 then N.UserDescription end) AS H3a_Desc, 
    (case CRS_AssessShare2.H3b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS H3b, 
    (case CRS_AssessShare2.H3b when 1 then Y.UserDescription when 2 then N.UserDescription end) AS H3b_Desc, 
    (case CRS_AssessShare2.H3c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS H3c, 
    (case CRS_AssessShare2.H3c when 1 then Y.UserDescription when 2 then N.UserDescription end) AS H3c_Desc, 
    (case CRS_AssessShare2.H3d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS H3d, 
    (case CRS_AssessShare2.H3d when 1 then Y.UserDescription when 2 then N.UserDescription end) AS H3d_Desc, 
    (case CRS_AssessShare2.H3e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS H3e, 
    (case CRS_AssessShare2.H3e when 1 then Y.UserDescription when 2 then N.UserDescription end) AS H3e_Desc, 
    (case CRS_AssessShare2.H3f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS H3f, 
    (case CRS_AssessShare2.H3f when 1 then Y.UserDescription when 2 then N.UserDescription end) AS H3f_Desc, 
    (case CRS_AssessShare2.H3g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS H3g, 
    (case CRS_AssessShare2.H3g when 1 then Y.UserDescription when 2 then N.UserDescription end) AS H3g_Desc, 
    (case CRS_AssessShare2.H3h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS H3h, 
    (case CRS_AssessShare2.H3h when 1 then Y.UserDescription when 2 then N.UserDescription end) AS H3h_Desc, 
    (case CRS_AssessShare2.H3i when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS H3i, 
    (case CRS_AssessShare2.H3i when 1 then Y.UserDescription when 2 then N.UserDescription end) AS H3i_Desc, 
    LU_H4.DisplayCode AS H4, LU_H4.UserDescription AS H4_Desc, 
--Share 3
    (case when CRS_AssessShare3.I1All > 0 then Y1.DisplayCode end) as I1All, 
    (case when CRS_AssessShare3.I1All > 0 then Y1.UserDescription end) as I1All_Desc, 
    (case CRS_AssessShare3.I1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1a, 
    (case CRS_AssessShare3.I1a when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1a_Desc, 
    (case CRS_AssessShare3.I1b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1b, 
    (case CRS_AssessShare3.I1b when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1b_Desc, 
    (case CRS_AssessShare3.I1c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1c, 
    (case CRS_AssessShare3.I1c when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1c_Desc, 
    (case CRS_AssessShare3.I1d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1d, 
    (case CRS_AssessShare3.I1d when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1d_Desc, 
    (case CRS_AssessShare3.I1e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1e, 
    (case CRS_AssessShare3.I1e when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1e_Desc, 
    (case CRS_AssessShare3.I1f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1f, 
    (case CRS_AssessShare3.I1f when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1f_Desc, 
    (case CRS_AssessShare3.I1g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1g, 
    (case CRS_AssessShare3.I1g when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1g_Desc, 
    (case CRS_AssessShare3.I1h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1h, 
    (case CRS_AssessShare3.I1h when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1h_Desc, 
    (case CRS_AssessShare3.I1I when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1I, 
    (case CRS_AssessShare3.I1I when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1I_Desc, 
    (case CRS_AssessShare3.I1j when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1j, 
    (case CRS_AssessShare3.I1j when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1j_Desc, 
    (case CRS_AssessShare3.I1k when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1k, 
    (case CRS_AssessShare3.I1k when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1k_Desc, 
    (case CRS_AssessShare3.I1l when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1l, 
    (case CRS_AssessShare3.I1l when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1l_Desc, 
    (case CRS_AssessShare3.I1m when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1m, 
    (case CRS_AssessShare3.I1m when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1m_Desc, 
    (case CRS_AssessShare3.I1n when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1n, 
    (case CRS_AssessShare3.I1n when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1n_Desc, 
    (case CRS_AssessShare3.I1o when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1o, 
    (case CRS_AssessShare3.I1o when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1o_Desc, 
    (case CRS_AssessShare3.I1p when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1p, 
    (case CRS_AssessShare3.I1p when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1p_Desc, 
    (case CRS_AssessShare3.I1q when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1q, 
    (case CRS_AssessShare3.I1q when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1q_Desc, 
    (case CRS_AssessShare3.I1r when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1r, 
    (case CRS_AssessShare3.I1r when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1r_Desc, 
    (case CRS_AssessShare3.I1s when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1s, 
    (case CRS_AssessShare3.I1s when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1s_Desc, 
    (case CRS_AssessShare3.I1t when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1t, 
    (case CRS_AssessShare3.I1t when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1t_Desc, 
    (case CRS_AssessShare3.I1u when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1u, 
    (case CRS_AssessShare3.I1u when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1u_Desc, 
    (case CRS_AssessShare3.I1v when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1v, 
    (case CRS_AssessShare3.I1v when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1v_Desc, 
    (case CRS_AssessShare3.I1w when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1w, 
    (case CRS_AssessShare3.I1w when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1w_Desc, 
    (case CRS_AssessShare3.I1x when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1x, 
    (case CRS_AssessShare3.I1x when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1x_Desc, 
    (case CRS_AssessShare3.I1y when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1y, 
    (case CRS_AssessShare3.I1y when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1y_Desc, 
    (case CRS_AssessShare3.I1z when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1z, 
    (case CRS_AssessShare3.I1z when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1z_Desc, 
    (case CRS_AssessShare3.I1aa when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1aa, 
    (case CRS_AssessShare3.I1aa when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1aa_Desc, 
    (case CRS_AssessShare3.I1bb when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1bb, 
    (case CRS_AssessShare3.I1bb when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1bb_Desc, 
    (case CRS_AssessShare3.I1cc when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1cc, 
    (case CRS_AssessShare3.I1cc when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1cc_Desc, 
    (case CRS_AssessShare3.I1dd when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1dd, 
    (case CRS_AssessShare3.I1dd when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1dd_Desc, 
    (case CRS_AssessShare3.I1ee when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1ee, 
    (case CRS_AssessShare3.I1ee when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1ee_Desc, 
    (case CRS_AssessShare3.I1ff when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1ff, 
    (case CRS_AssessShare3.I1ff when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1ff_Desc, 
    (case CRS_AssessShare3.I1gg when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1gg, 
    (case CRS_AssessShare3.I1gg when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1gg_Desc, 
    (case CRS_AssessShare3.I1hh when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1hh, 
    (case CRS_AssessShare3.I1hh when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1hh_Desc, 
    (case CRS_AssessShare3.I1ii when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1ii, 
    (case CRS_AssessShare3.I1ii when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1ii_Desc, 
    (case CRS_AssessShare3.I1jj when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1jj, 
    (case CRS_AssessShare3.I1jj when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1jj_Desc, 
    (case CRS_AssessShare3.I1kk when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1kk, 
    (case CRS_AssessShare3.I1kk when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1kk_Desc, 
    (case CRS_AssessShare3.I1ll when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1ll, 
    (case CRS_AssessShare3.I1ll when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1ll_Desc, 
    (case CRS_AssessShare3.I1mm when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1mm, 
    (case CRS_AssessShare3.I1mm when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1mm_Desc, 
    (case CRS_AssessShare3.I1nn when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1nn, 
    (case CRS_AssessShare3.I1nn when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1nn_Desc, 
    (case CRS_AssessShare3.I1oo when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1oo, 
    (case CRS_AssessShare3.I1oo when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1oo_Desc, 
    (case CRS_AssessShare3.I1pp when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1pp, 
    (case CRS_AssessShare3.I1pp when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1pp_Desc, 
    (case CRS_AssessShare3.I1qq when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1qq, 
    (case CRS_AssessShare3.I1qq when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1qq_Desc, 
    (case CRS_AssessShare3.I1rr when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS I1rr, 
    (case CRS_AssessShare3.I1rr when 1 then Y.UserDescription when 2 then N.UserDescription end) AS I1rr_Desc, 
    (case CRS_AssessShare3.I1ss when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as I1ss, 
    (case CRS_AssessShare3.I1ss when 1 then Y.UserDescription when 2 then N.UserDescription end) as I1ss_Desc, 
    (case CRS_AssessShare3.I1tt when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as I1tt, 
    (case CRS_AssessShare3.I1tt when 1 then Y.UserDescription when 2 then N.UserDescription end) as I1tt_Desc, 
    (case CRS_AssessShare3.I1uu when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as I1uu, 
    (case CRS_AssessShare3.I1uu when 1 then Y.UserDescription when 2 then N.UserDescription end) as I1uu_Desc, 

    (case when CRS_AssessShare3.I2All > 0 then Y1.DisplayCode end) as I2All, 
    (case when CRS_AssessShare3.I2All > 0 then Y1.UserDescription end) as I2All_Desc, 
    (case CRS_AssessShare3.I2a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as I2a, 
    (case CRS_AssessShare3.I2a when 1 then Y.UserDescription when 2 then N.UserDescription end) as I2a_Desc, 
    (case CRS_AssessShare3.I2b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as I2b, 
    (case CRS_AssessShare3.I2b when 1 then Y.UserDescription when 2 then N.UserDescription end) as I2b_Desc, 
    (case CRS_AssessShare3.I2c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as I2c, 
    (case CRS_AssessShare3.I2c when 1 then Y.UserDescription when 2 then N.UserDescription end) as I2c_Desc, 
    (case CRS_AssessShare3.I2d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as I2d, 
    (case CRS_AssessShare3.I2d when 1 then Y.UserDescription when 2 then N.UserDescription end) as I2d_Desc, 
    (case CRS_AssessShare3.I2e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as I2e, 
    (case CRS_AssessShare3.I2e when 1 then Y.UserDescription when 2 then N.UserDescription end) as I2e_Desc, 
    (case CRS_AssessShare3.I2f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as I2f, 
    (case CRS_AssessShare3.I2f when 1 then Y.UserDescription when 2 then N.UserDescription end) as I2f_Desc, 
    (case CRS_AssessShare3.I2g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as I2g, 
    (case CRS_AssessShare3.I2g when 1 then Y.UserDescription when 2 then N.UserDescription end) as I2g_Desc, 
    (case CRS_AssessShare3.I2h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as I2h, 
    (case CRS_AssessShare3.I2h when 1 then Y.UserDescription when 2 then N.UserDescription end) as I2h_Desc, 
    (case CRS_AssessShare3.I2I when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as I2I, 
    (case CRS_AssessShare3.I2I when 1 then Y.UserDescription when 2 then N.UserDescription end) as I2I_Desc, 
    (case CRS_AssessShare3.I2j when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as I2j, 
    (case CRS_AssessShare3.I2j when 1 then Y.UserDescription when 2 then N.UserDescription end) as I2j_Desc, 
    (case CRS_AssessShare3.I2k when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as I2k, 
    (case CRS_AssessShare3.I2k when 1 then Y.UserDescription when 2 then N.UserDescription end) as I2k_Desc, 
    (case CRS_AssessShare3.I2l when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as I2l, 
    (case CRS_AssessShare3.I2l when 1 then Y.UserDescription when 2 then N.UserDescription end) as I2l_Desc, 
    (case CRS_AssessShare3.I2m when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as I2m, 
    (case CRS_AssessShare3.I2m when 1 then Y.UserDescription when 2 then N.UserDescription end) as I2m_Desc, 

    (case when CRS_AssessShare3.J1All > 0 then Y1.DisplayCode end) as J1All, 
    (case when CRS_AssessShare3.J1All > 0 then Y1.UserDescription end) as J1All_Desc, 
    (case CRS_AssessShare3.J1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J1a, 
    (case CRS_AssessShare3.J1a when 1 then Y.UserDescription when 2 then N.UserDescription end) as J1a_Desc, 
    (case CRS_AssessShare3.J1b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J1b, 
    (case CRS_AssessShare3.J1b when 1 then Y.UserDescription when 2 then N.UserDescription end) as J1b_Desc, 
    (case CRS_AssessShare3.J1c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J1c, 
    (case CRS_AssessShare3.J1c when 1 then Y.UserDescription when 2 then N.UserDescription end) as J1c_Desc, 
    (case CRS_AssessShare3.J1d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J1d, 
    (case CRS_AssessShare3.J1d when 1 then Y.UserDescription when 2 then N.UserDescription end) as J1d_Desc, 
    (case CRS_AssessShare3.J1e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J1e, 
    (case CRS_AssessShare3.J1e when 1 then Y.UserDescription when 2 then N.UserDescription end) as J1e_Desc, 
    (case CRS_AssessShare3.J1f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J1f, 
    (case CRS_AssessShare3.J1f when 1 then Y.UserDescription when 2 then N.UserDescription end) as J1f_Desc, 
    (case CRS_AssessShare3.J1g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J1g, 
    (case CRS_AssessShare3.J1g when 1 then Y.UserDescription when 2 then N.UserDescription end) as J1g_Desc, 
    (case CRS_AssessShare3.J1h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J1h, 
    (case CRS_AssessShare3.J1h when 1 then Y.UserDescription when 2 then N.UserDescription end) as J1h_Desc, 
    (case CRS_AssessShare3.J1I when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J1I, 
    (case CRS_AssessShare3.J1I when 1 then Y.UserDescription when 2 then N.UserDescription end) as J1I_Desc, 
    (case CRS_AssessShare3.J1j when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J1j, 
    (case CRS_AssessShare3.J1j when 1 then Y.UserDescription when 2 then N.UserDescription end) as J1j_Desc, 
    (case CRS_AssessShare3.J1k when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J1k, 
    (case CRS_AssessShare3.J1k when 1 then Y.UserDescription when 2 then N.UserDescription end) as J1k_Desc, 
    (case CRS_AssessShare3.J1l when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J1l, 
    (case CRS_AssessShare3.J1l when 1 then Y.UserDescription when 2 then N.UserDescription end) as J1l_Desc, 
    (case CRS_AssessShare3.J1m when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J1m, 
    (case CRS_AssessShare3.J1m when 1 then Y.UserDescription when 2 then N.UserDescription end) as J1m_Desc, 
    (case CRS_AssessShare3.J1n when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J1n, 
    (case CRS_AssessShare3.J1n when 1 then Y.UserDescription when 2 then N.UserDescription end) as J1n_Desc, 
    (case CRS_AssessShare3.J1o when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J1o, 
    (case CRS_AssessShare3.J1o when 1 then Y.UserDescription when 2 then N.UserDescription end) as J1o_Desc, 
    LU_J2a.DisplayCode AS J2a, LU_J2a.UserDescription AS J2a_Desc, 
    LU_J2b.DisplayCode AS J2b, LU_J2b.UserDescription AS J2b_Desc, 

    (case when CRS_AssessShare3.J4All > 0 then Y1.DisplayCode end) as J4All, 
    (case when CRS_AssessShare3.J4All > 0 then Y1.UserDescription end) as J4All_Desc, 
    (case CRS_AssessShare3.J4a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J4a, 
    (case CRS_AssessShare3.J4a when 1 then Y.UserDescription when 2 then N.UserDescription end) as J4a_Desc, 
    (case CRS_AssessShare3.J4b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J4b, 
    (case CRS_AssessShare3.J4b when 1 then Y.UserDescription when 2 then N.UserDescription end) as J4b_Desc, 
    (case CRS_AssessShare3.J4c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J4c, 
    (case CRS_AssessShare3.J4c when 1 then Y.UserDescription when 2 then N.UserDescription end) as J4c_Desc, 
    (case CRS_AssessShare3.J4d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J4d, 
    (case CRS_AssessShare3.J4d when 1 then Y.UserDescription when 2 then N.UserDescription end) as J4d_Desc, 

    (case when CRS_AssessShare3.J5All > 0 then Y1.DisplayCode end) as J5All, 
    (case when CRS_AssessShare3.J5All > 0 then Y1.UserDescription end) as J5All_Desc, 
    (case CRS_AssessShare3.J5a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J5a, 
    (case CRS_AssessShare3.J5a when 1 then Y.UserDescription when 2 then N.UserDescription end) as J5a_Desc, 
    (case CRS_AssessShare3.J5b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J5b, 
    (case CRS_AssessShare3.J5b when 1 then Y.UserDescription when 2 then N.UserDescription end) as J5b_Desc, 
    (case CRS_AssessShare3.J5c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as J5c, 
    (case CRS_AssessShare3.J5c when 1 then Y.UserDescription when 2 then N.UserDescription end) as J5c_Desc, 
--Share 4
    (case when CRS_AssessShare4.K1All > 0 then Y1.DisplayCode end) as K1All, 
    (case when CRS_AssessShare4.K1All > 0 then Y1.UserDescription end) as K1All_Desc, 
    (case CRS_AssessShare4.K1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as K1a, 
    (case CRS_AssessShare4.K1a when 1 then Y.UserDescription when 2 then N.UserDescription end) as K1a_Desc, 
    (case CRS_AssessShare4.K1b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as K1b, 
    (case CRS_AssessShare4.K1b when 1 then Y.UserDescription when 2 then N.UserDescription end) as K1b_Desc, 
    (case CRS_AssessShare4.K1c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as K1c, 
    (case CRS_AssessShare4.K1c when 1 then Y.UserDescription when 2 then N.UserDescription end) as K1c_Desc, 

    dbo.CRS_AssessShare4.K2a, dbo.CRS_AssessShare4.K2b, 

    (case when LU_AA8.CIHIValue = ''05'' then LU_K3a_Q.DisplayCode else (case CRS_AssessShare4.K3a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS K3a, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_K3a_Q.UserDescription else (case CRS_AssessShare4.K3a when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS K3a_Desc, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_K3b_Q.DisplayCode else (case CRS_AssessShare4.K3b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS K3b, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_K3b_Q.UserDescription else (case CRS_AssessShare4.K3b when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS K3b_Desc, 

    (case when CRS_AssessShare4.K4All > 0 then Y1.DisplayCode end) as K4All, 
    (case when CRS_AssessShare4.K4All > 0 then Y1.UserDescription end) as K4All_Desc, 
    (case CRS_AssessShare4.K4a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as K4a, 
    (case CRS_AssessShare4.K4a when 1 then Y.UserDescription when 2 then N.UserDescription end) as K4a_Desc, 
    (case CRS_AssessShare4.K4b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as K4b, 
    (case CRS_AssessShare4.K4b when 1 then Y.UserDescription when 2 then N.UserDescription end) as K4b_Desc, 
    (case CRS_AssessShare4.K4c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as K4c, 
    (case CRS_AssessShare4.K4c when 1 then Y.UserDescription when 2 then N.UserDescription end) as K4c_Desc, 

    (case when CRS_AssessShare4.K5All > 0 then Y1.DisplayCode end) as K5All, 
    (case when CRS_AssessShare4.K5All > 0 then Y1.UserDescription end) as K5All_Desc, 
    (case CRS_AssessShare4.K5a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as K5a, 
    (case CRS_AssessShare4.K5a when 1 then Y.UserDescription when 2 then N.UserDescription end) as K5a_Desc, 
    (case CRS_AssessShare4.K5b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as K5b, 
    (case CRS_AssessShare4.K5b when 1 then Y.UserDescription when 2 then N.UserDescription end) as K5b_Desc, 
    (case CRS_AssessShare4.K5c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as K5c, 
    (case CRS_AssessShare4.K5c when 1 then Y.UserDescription when 2 then N.UserDescription end) as K5c_Desc, 
    (case CRS_AssessShare4.K5d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as K5d, 
    (case CRS_AssessShare4.K5d when 1 then Y.UserDescription when 2 then N.UserDescription end) as K5d_Desc, 
    (case CRS_AssessShare4.K5e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as K5e, 
    (case CRS_AssessShare4.K5e when 1 then Y.UserDescription when 2 then N.UserDescription end) as K5e_Desc, 
    (case CRS_AssessShare4.K5f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as K5f, 
    (case CRS_AssessShare4.K5f when 1 then Y.UserDescription when 2 then N.UserDescription end) as K5f_Desc, 
    (case CRS_AssessShare4.K5g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as K5g, 
    (case CRS_AssessShare4.K5g when 1 then Y.UserDescription when 2 then N.UserDescription end) as K5g_Desc, 
    (case CRS_AssessShare4.K5h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as K5h, 
    (case CRS_AssessShare4.K5h when 1 then Y.UserDescription when 2 then N.UserDescription end) as K5h_Desc, 

    LU_K6a.DisplayCode AS K6a, LU_K6a.UserDescription AS K6a_Desc, 
    LU_K6b.DisplayCode AS K6b, LU_K6b.UserDescription AS K6b_Desc, 
    dbo.CRS_AssessShare4.M1a, dbo.CRS_AssessShare4.M1b, 
    dbo.CRS_AssessShare4.M1c, dbo.CRS_AssessShare4.M1d, 
    LU_M2a.DisplayCode AS M2a, LU_M2a.UserDescription AS M2a_Desc, 
    LU_M2b.DisplayCode AS M2b, LU_M2b.UserDescription AS M2b_Desc, 

    (case when CRS_AssessShare4.M4All > 0 then Y1.DisplayCode end) as M4All, 
    (case when CRS_AssessShare4.M4All > 0 then Y1.UserDescription end) as M4All_Desc, 
    (case CRS_AssessShare4.M4a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M4a, 
    (case CRS_AssessShare4.M4a when 1 then Y.UserDescription when 2 then N.UserDescription end) as M4a_Desc, 
    (case CRS_AssessShare4.M4b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M4b, 
    (case CRS_AssessShare4.M4b when 1 then Y.UserDescription when 2 then N.UserDescription end) as M4b_Desc, 
    (case CRS_AssessShare4.M4c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M4c, 
    (case CRS_AssessShare4.M4c when 1 then Y.UserDescription when 2 then N.UserDescription end) as M4c_Desc, 
    (case CRS_AssessShare4.M4d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M4d, 
    (case CRS_AssessShare4.M4d when 1 then Y.UserDescription when 2 then N.UserDescription end) as M4d_Desc, 
    (case CRS_AssessShare4.M4e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M4e, 
    (case CRS_AssessShare4.M4e when 1 then Y.UserDescription when 2 then N.UserDescription end) as M4e_Desc, 
    (case CRS_AssessShare4.M4f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M4f, 
    (case CRS_AssessShare4.M4f when 1 then Y.UserDescription when 2 then N.UserDescription end) as M4f_Desc, 
    (case CRS_AssessShare4.M4g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M4g, 
    (case CRS_AssessShare4.M4g when 1 then Y.UserDescription when 2 then N.UserDescription end) as M4g_Desc, 

    (case when CRS_AssessShare4.M5All > 0 then Y1.DisplayCode end) as M5All, 
    (case when CRS_AssessShare4.M5All > 0 then Y1.UserDescription end) as M5All_Desc, 
    (case CRS_AssessShare4.M5a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M5a, 
    (case CRS_AssessShare4.M5a when 1 then Y.UserDescription when 2 then N.UserDescription end) as M5a_Desc, 
    (case CRS_AssessShare4.M5b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M5b, 
    (case CRS_AssessShare4.M5b when 1 then Y.UserDescription when 2 then N.UserDescription end) as M5b_Desc, 
    (case CRS_AssessShare4.M5c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M5c, 
    (case CRS_AssessShare4.M5c when 1 then Y.UserDescription when 2 then N.UserDescription end) as M5c_Desc, 
    (case CRS_AssessShare4.M5d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M5d, 
    (case CRS_AssessShare4.M5d when 1 then Y.UserDescription when 2 then N.UserDescription end) as M5d_Desc, 
    (case CRS_AssessShare4.M5e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M5e, 
    (case CRS_AssessShare4.M5e when 1 then Y.UserDescription when 2 then N.UserDescription end) as M5e_Desc, 
    (case CRS_AssessShare4.M5f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M5f, 
    (case CRS_AssessShare4.M5f when 1 then Y.UserDescription when 2 then N.UserDescription end) as M5f_Desc, 
    (case CRS_AssessShare4.M5g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M5g, 
    (case CRS_AssessShare4.M5g when 1 then Y.UserDescription when 2 then N.UserDescription end) as M5g_Desc, 
    (case CRS_AssessShare4.M5h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M5h, 
    (case CRS_AssessShare4.M5h when 1 then Y.UserDescription when 2 then N.UserDescription end) as M5h_Desc, 
    (case CRS_AssessShare4.M5I when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M5I, 
    (case CRS_AssessShare4.M5I when 1 then Y.UserDescription when 2 then N.UserDescription end) as M5I_Desc, 

    (case when CRS_AssessShare4.M6All > 0 then Y1.DisplayCode end) as M6All, 
    (case when CRS_AssessShare4.M6All > 0 then Y1.UserDescription end) as M6All_Desc, 
    (case CRS_AssessShare4.M6a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M6a, 
    (case CRS_AssessShare4.M6a when 1 then Y.UserDescription when 2 then N.UserDescription end) as M6a_Desc, 
    (case CRS_AssessShare4.M6b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M6b, 
    (case CRS_AssessShare4.M6b when 1 then Y.UserDescription when 2 then N.UserDescription end) as M6b_Desc, 
    (case CRS_AssessShare4.M6c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M6c, 
    (case CRS_AssessShare4.M6c when 1 then Y.UserDescription when 2 then N.UserDescription end) as M6c_Desc, 
    (case CRS_AssessShare4.M6d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M6d, 
    (case CRS_AssessShare4.M6d when 1 then Y.UserDescription when 2 then N.UserDescription end) as M6d_Desc, 
    (case CRS_AssessShare4.M6e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M6e, 
    (case CRS_AssessShare4.M6e when 1 then Y.UserDescription when 2 then N.UserDescription end) as M6e_Desc, 
    (case CRS_AssessShare4.M6f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as M6f, 
    (case CRS_AssessShare4.M6f when 1 then Y.UserDescription when 2 then N.UserDescription end) as M6f_Desc, 

    (case when CRS_AssessShare4.N1All > 0 then Y1.DisplayCode end) as N1All, 
    (case when CRS_AssessShare4.N1All > 0 then Y1.UserDescription end) as N1All_Desc, 
    (case CRS_AssessShare4.N1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as N1a, 
    (case CRS_AssessShare4.N1a when 1 then Y.UserDescription when 2 then N.UserDescription end) as N1a_Desc, 
    (case CRS_AssessShare4.N1b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as N1b, 
    (case CRS_AssessShare4.N1b when 1 then Y.UserDescription when 2 then N.UserDescription end) as N1b_Desc, 
    (case CRS_AssessShare4.N1c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as N1c, 
    (case CRS_AssessShare4.N1c when 1 then Y.UserDescription when 2 then N.UserDescription end) as N1c_Desc, 

    LU_N2.DisplayCode AS N2, LU_N2.UserDescription AS N2_Desc, dbo.CRS_AssessShare4.O1, dbo.CRS_AssessShare4.O3, 
    dbo.CRS_AssessShare4.O4a, dbo.CRS_AssessShare4.O4b, dbo.CRS_AssessShare4.O4c, dbo.CRS_AssessShare4.O4d, dbo.CRS_AssessShare4.O4e, 
    dbo.CRS_AssessShare4.O4f,
--Share 5
    LU_P1All.DisplayCode AS P1aAll, LU_P1All.UserDescription AS P1aAll_Desc, 
    (case CRS_AssessShare5.P1aa when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P1aa, 
    (case CRS_AssessShare5.P1aa when 1 then Y.UserDescription when 2 then N.UserDescription end) as P1aa_Desc, 
    (case CRS_AssessShare5.P1ab when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P1ab, 
    (case CRS_AssessShare5.P1ab when 1 then Y.UserDescription when 2 then N.UserDescription end) as P1ab_Desc, 
    (case CRS_AssessShare5.P1ac when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P1ac, 
    (case CRS_AssessShare5.P1ac when 1 then Y.UserDescription when 2 then N.UserDescription end) as P1ac_Desc, 
    (case CRS_AssessShare5.P1ad when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P1ad, 
    (case CRS_AssessShare5.P1ad when 1 then Y.UserDescription when 2 then N.UserDescription end) as P1ad_Desc, 
    (case CRS_AssessShare5.P1ae when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P1ae, 
    (case CRS_AssessShare5.P1ae when 1 then Y.UserDescription when 2 then N.UserDescription end) as P1ae_Desc, 
    (case CRS_AssessShare5.P1af when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P1af, 
    (case CRS_AssessShare5.P1af when 1 then Y.UserDescription when 2 then N.UserDescription end) as P1af_Desc, 
    (case CRS_AssessShare5.P1ag when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P1ag, 
    (case CRS_AssessShare5.P1ag when 1 then Y.UserDescription when 2 then N.UserDescription end) as P1ag_Desc, 
    (case CRS_AssessShare5.P1ah when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P1ah, 
    (case CRS_AssessShare5.P1ah when 1 then Y.UserDescription when 2 then N.UserDescription end) as P1ah_Desc, 
    (case CRS_AssessShare5.P1ai when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P1ai, 
    (case CRS_AssessShare5.P1ai when 1 then Y.UserDescription when 2 then N.UserDescription end) as P1ai_Desc, 
    (case CRS_AssessShare5.P1aj when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P1aj, 
    (case CRS_AssessShare5.P1aj when 1 then Y.UserDescription when 2 then N.UserDescription end) as P1aj_Desc, 
    (case CRS_AssessShare5.P1ak when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P1ak, 
    (case CRS_AssessShare5.P1ak when 1 then Y.UserDescription when 2 then N.UserDescription end) as P1ak_Desc, 
    (case CRS_AssessShare5.P1al when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P1al, 
    (case CRS_AssessShare5.P1al when 1 then Y.UserDescription when 2 then N.UserDescription end) as P1al_Desc, 
    (case CRS_AssessShare5.P1am when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P1am, 
    (case CRS_AssessShare5.P1am when 1 then Y.UserDescription when 2 then N.UserDescription end) as P1am_Desc, 
    (case CRS_AssessShare5.P1an when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P1an, 
    (case CRS_AssessShare5.P1an when 1 then Y.UserDescription when 2 then N.UserDescription end) as P1an_Desc, 
    (case CRS_AssessShare5.P1ao when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P1ao, 
    (case CRS_AssessShare5.P1ao when 1 then Y.UserDescription when 2 then N.UserDescription end) as P1ao_Desc, 
    (case CRS_AssessShare5.P1ap when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P1ap, 
    (case CRS_AssessShare5.P1ap when 1 then Y.UserDescription when 2 then N.UserDescription end) as P1ap_Desc, 
    (case CRS_AssessShare5.P1aq when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P1aq, 
    (case CRS_AssessShare5.P1aq when 1 then Y.UserDescription when 2 then N.UserDescription end) as P1aq_Desc, 
    (case CRS_AssessShare5.P1ar when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as P1ar, 
    (case CRS_AssessShare5.P1ar when 1 then Y.UserDescription when 2 then N.UserDescription end) as P1ar_Desc, 

    dbo.CRS_AssessShare5.P1baA, dbo.CRS_AssessShare5.P1baB, 
    dbo.CRS_AssessShare5.P1bbA, dbo.CRS_AssessShare5.P1bbB, dbo.CRS_AssessShare5.P1bcA, dbo.CRS_AssessShare5.P1bcB, 
    dbo.CRS_AssessShare5.P1bdA, dbo.CRS_AssessShare5.P1bdB, dbo.CRS_AssessShare5.P1beA, dbo.CRS_AssessShare5.P1beB, 
    dbo.CRS_AssessShare5.P1bfA, dbo.CRS_AssessShare5.P1bfB, dbo.CRS_AssessShare5.P3a, dbo.CRS_AssessShare5.P3b, 
    dbo.CRS_AssessShare5.P3c, dbo.CRS_AssessShare5.P3d, dbo.CRS_AssessShare5.P3e, dbo.CRS_AssessShare5.P3f, dbo.CRS_AssessShare5.P3g, 
    dbo.CRS_AssessShare5.P3h, dbo.CRS_AssessShare5.P3I, dbo.CRS_AssessShare5.P3j, dbo.CRS_AssessShare5.P3k, LU_P4a.DisplayCode AS P4a, 
    LU_P4a.UserDescription AS P4a_Desc, LU_P4b.DisplayCode AS P4b, LU_P4b.UserDescription AS P4b_Desc, LU_P4c.DisplayCode AS P4c, 
    LU_P4c.UserDescription AS P4c_Desc, LU_P4d.DisplayCode AS P4d, LU_P4d.UserDescription AS P4d_Desc, LU_P4e.DisplayCode AS P4e, 
    LU_P4e.UserDescription AS P4e_Desc, dbo.CRS_AssessShare5.P7, dbo.CRS_AssessShare5.P8, LU_Q2.DisplayCode AS Q2, 
    LU_Q2.UserDescription AS Q2_Desc, dbo.CRS_AssessShare5.R2b,

--Diagnosis
    I3a, I3b, I3c, I3d, I3e, I3f
FROM     
    dbo.CRS_Demographic with (nolock) INNER JOIN
    dbo.LU_CodeFile LU_AA8 with (nolock) on dbo.CRS_Demographic.AA8 = LU_AA8.Code LEFT JOIN
    dbo.LU_CodeFile LU_Gender with (nolock) on dbo.CRS_Demographic.Gender = LU_Gender.Code LEFT JOIN
    dbo.H_InstitutionProfile with (nolock) on dbo.CRS_Demographic.InstitutionNumber = dbo.H_InstitutionProfile.Code LEFT OUTER JOIN
    dbo.LU_HCNProvince with (nolock) on dbo.LU_HCNProvince.Code = dbo.CRS_Demographic.HCNProvince LEFT OUTER JOIN
    dbo.U_Users U_TSICoder with (nolock) on dbo.CRS_Demographic.TSICoder = U_TSICoder.Code LEFT OUTER JOIN
    dbo.LU_YesBlank LU_Secret with (nolock) on dbo.CRS_Demographic.Secret = LU_Secret.Code LEFT OUTER JOIN
    dbo.U_Users U_DataEntryCoder with (nolock) on dbo.CRS_Demographic.DataEntryCoder = U_DataEntryCoder.Code LEFT OUTER JOIN
    dbo.U_Users U_InterfaceCoder with (nolock) on dbo.CRS_Demographic.InterfaceCoder = U_InterfaceCoder.Code LEFT OUTER JOIN
    dbo.U_Users LU_Coder with (nolock) on dbo.CRS_Demographic.CoderNumber = LU_Coder.Code LEFT OUTER JOIN
    dbo.LU_Site with (nolock) on dbo.CRS_Demographic.SiteNumber = dbo.LU_Site.Code LEFT OUTER JOIN
    dbo.LU_DeleteStatus LU_IsDeleted with (nolock) on dbo.CRS_Demographic.IsDeleted = LU_IsDeleted.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus LU_IsCompleted with (nolock) on dbo.CRS_Demographic.IsCompleted = LU_IsCompleted.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus LU_IsValidated with (nolock) on dbo.CRS_Demographic.IsValidated = LU_IsValidated.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_IsSubmited with (nolock) on dbo.CRS_Demographic.IsSubmited = LU_IsSubmited.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Z1 with (nolock) on dbo.CRS_Demographic.Z1 = LU_Z1.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 LU_Inst_To with (nolock) on dbo.CRS_Demographic.InstitutionTo = LU_Inst_To.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_R3a with (nolock) on LU_R3a.Code = dbo.CRS_Demographic.R3a LEFT OUTER JOIN
    dbo.LU_Institution_10 LU_Inst_From with (nolock) on dbo.CRS_Demographic.InstitutionFrom = LU_Inst_From.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_AB2c with (nolock) on dbo.CRS_Demographic.AB2c = LU_AB2c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_AB2a with (nolock) on dbo.CRS_Demographic.AB2a = LU_AB2a.Code LEFT OUTER JOIN
    dbo.LU_NurseArea with (nolock) on dbo.CRS_Demographic.AdmittingNurseArea = dbo.LU_NurseArea.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_BirthDateEstimated with (nolock) on dbo.CRS_Demographic.BirthDateEstimated = LU_BirthDateEstimated.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_MaritalStatus with (nolock) on dbo.CRS_Demographic.MaritalStatus = LU_MaritalStatus.Code LEFT OUTER JOIN
-- Full 1
    dbo.CRS_AssessFull1 with (nolock) on CRS_Demographic.AbstractID = CRS_AssessFull1.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J3j with (nolock) on dbo.CRS_AssessFull1.J3j = LU_J3j.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J3I with (nolock) on dbo.CRS_AssessFull1.J3I = LU_J3I.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J3h with (nolock) on dbo.CRS_AssessFull1.J3h = LU_J3h.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J3g with (nolock) on dbo.CRS_AssessFull1.J3g = LU_J3g.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J3f with (nolock) on dbo.CRS_AssessFull1.J3f = LU_J3f.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J3e with (nolock) on dbo.CRS_AssessFull1.J3e = LU_J3e.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J3d with (nolock) on dbo.CRS_AssessFull1.J3d = LU_J3d.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J3c with (nolock) on dbo.CRS_AssessFull1.J3c = LU_J3c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J3b with (nolock) on dbo.CRS_AssessFull1.J3b = LU_J3b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J3a with (nolock) on dbo.CRS_AssessFull1.J3a = LU_J3a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F3c with (nolock) on dbo.CRS_AssessFull1.F3c = LU_F3c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F3b with (nolock) on dbo.CRS_AssessFull1.F3b = LU_F3b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F3a with (nolock) on dbo.CRS_AssessFull1.F3a = LU_F3a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F2g with (nolock) on dbo.CRS_AssessFull1.F2g = LU_F2g.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F2f with (nolock) on dbo.CRS_AssessFull1.F2f = LU_F2f.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F2e with (nolock) on dbo.CRS_AssessFull1.F2e = LU_F2e.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F2d with (nolock) on dbo.CRS_AssessFull1.F2d = LU_F2d.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F2c with (nolock) on dbo.CRS_AssessFull1.F2c = LU_F2c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F2b with (nolock) on dbo.CRS_AssessFull1.F2b = LU_F2b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F2a with (nolock) on dbo.CRS_AssessFull1.F2a = LU_F2a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_D3 with (nolock) on dbo.CRS_AssessFull1.D3 = LU_D3.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_D2b with (nolock) on dbo.CRS_AssessFull1.D2b = LU_D2b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_D2a with (nolock) on dbo.CRS_AssessFull1.D2a = LU_D2a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_D1 with (nolock) on dbo.CRS_AssessFull1.D1 = LU_D1.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C5 with (nolock) on dbo.CRS_AssessFull1.C5 = LU_C5.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C3f with (nolock) on dbo.CRS_AssessFull1.C3f = LU_C3f.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C3e with (nolock) on dbo.CRS_AssessFull1.C3e = LU_C3e.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C3d with (nolock) on dbo.CRS_AssessFull1.C3d = LU_C3d.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C3c with (nolock) on dbo.CRS_AssessFull1.C3c = LU_C3c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C3b with (nolock) on dbo.CRS_AssessFull1.C3b = LU_C3b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C3a with (nolock) on dbo.CRS_AssessFull1.C3a = LU_C3a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C2c with (nolock) on dbo.CRS_AssessFull1.C2c = LU_C2c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C2b with (nolock) on dbo.CRS_AssessFull1.C2b = LU_C2b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C2a with (nolock) on dbo.CRS_AssessFull1.C2a = LU_C2a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C1 with (nolock) on dbo.CRS_AssessFull1.C1 = LU_C1.Code LEFT OUTER JOIN
--Full 2
    dbo.CRS_AssessFull2 with (nolock) on CRS_Demographic.AbstractID = CRS_AssessFull2.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_R1c with (nolock) on dbo.CRS_AssessFull2.R1c = LU_R1c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_R1b with (nolock) on dbo.CRS_AssessFull2.R1b = LU_R1b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Q1c with (nolock) on dbo.CRS_AssessFull2.Q1c = LU_Q1c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_O2 with (nolock) on dbo.CRS_AssessFull2.O2 = LU_O2.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N5b with (nolock) on dbo.CRS_AssessFull2.N5b = LU_N5b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N5a with (nolock) on dbo.CRS_AssessFull2.N5a = LU_N5a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4l with (nolock) on dbo.CRS_AssessFull2.N4l = LU_N4l.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4k with (nolock) on dbo.CRS_AssessFull2.N4k = LU_N4k.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4j with (nolock) on dbo.CRS_AssessFull2.N4j = LU_N4j.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4I with (nolock) on dbo.CRS_AssessFull2.N4I = LU_N4I.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4h with (nolock) on dbo.CRS_AssessFull2.N4h = LU_N4h.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4g with (nolock) on dbo.CRS_AssessFull2.N4g = LU_N4g.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4f with (nolock) on dbo.CRS_AssessFull2.N4f = LU_N4f.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4e with (nolock) on dbo.CRS_AssessFull2.N4e = LU_N4e.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4d with (nolock) on dbo.CRS_AssessFull2.N4d = LU_N4d.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4c with (nolock) on dbo.CRS_AssessFull2.N4c = LU_N4c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4b with (nolock) on LU_N4b.Code = dbo.CRS_AssessFull2.N4b LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4a with (nolock) on dbo.CRS_AssessFull2.N4a = LU_N4a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N3d with (nolock) on dbo.CRS_AssessFull2.N3d = LU_N3d.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N3c with (nolock) on LU_N3c.Code = dbo.CRS_AssessFull2.N3c LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N3b with (nolock) on dbo.CRS_AssessFull2.N3b = LU_N3b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N3a with (nolock) on dbo.CRS_AssessFull2.N3a = LU_N3a.Code LEFT OUTER JOIN 

--Share 1
    dbo.CRS_AssessShare1 with (nolock) on CRS_AssessShare1.AbstractID = CRS_Demographic.AbstractID LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E5 with (nolock) on dbo.CRS_AssessShare1.E5 = LU_E5.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E4eB with (nolock) on dbo.CRS_AssessShare1.E4eB = LU_E4eB.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E4eA with (nolock) on LU_E4eA.Code = dbo.CRS_AssessShare1.E4eA LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E4dB with (nolock) on dbo.CRS_AssessShare1.E4dB = LU_E4dB.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E4dA with (nolock) on dbo.CRS_AssessShare1.E4dA = LU_E4dA.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E4cB with (nolock) on dbo.CRS_AssessShare1.E4cB = LU_E4cB.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E4cA with (nolock) on LU_E4cA.Code = dbo.CRS_AssessShare1.E4cA LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E4bB with (nolock) on dbo.CRS_AssessShare1.E4bB = LU_E4bB.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E4bA with (nolock) on LU_E4bA.Code = dbo.CRS_AssessShare1.E4bA LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E4aB with (nolock) on dbo.CRS_AssessShare1.E4aB = LU_E4aB.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E4aA with (nolock) on dbo.CRS_AssessShare1.E4aA = LU_E4aA.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E3 with (nolock) on dbo.CRS_AssessShare1.E3 = LU_E3.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E2 with (nolock) on dbo.CRS_AssessShare1.E2 = LU_E2.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E1p with (nolock) on dbo.CRS_AssessShare1.E1p = LU_E1p.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E1o with (nolock) on LU_E1o.Code = dbo.CRS_AssessShare1.E1o LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E1n with (nolock) on dbo.CRS_AssessShare1.E1n = LU_E1n.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E1m with (nolock) on dbo.CRS_AssessShare1.E1m = LU_E1m.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E1l with (nolock) on dbo.CRS_AssessShare1.E1l = LU_E1l.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E1k with (nolock) on dbo.CRS_AssessShare1.E1k = LU_E1k.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E1j with (nolock) on dbo.CRS_AssessShare1.E1j = LU_E1j.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E1I with (nolock) on LU_E1I.Code = dbo.CRS_AssessShare1.E1I LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E1h with (nolock) on dbo.CRS_AssessShare1.E1h = LU_E1h.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E1g with (nolock) on dbo.CRS_AssessShare1.E1g = LU_E1g.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E1f with (nolock) on dbo.CRS_AssessShare1.E1f = LU_E1f.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E1e with (nolock) on dbo.CRS_AssessShare1.E1e = LU_E1e.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E1d with (nolock) on dbo.CRS_AssessShare1.E1d = LU_E1d.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E1c with (nolock) on dbo.CRS_AssessShare1.E1c = LU_E1c.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E1b with (nolock) on dbo.CRS_AssessShare1.E1b = LU_E1b.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_E1a with (nolock) on dbo.CRS_AssessShare1.E1a = LU_E1a.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_C7 with (nolock) on dbo.CRS_AssessShare1.C7 = LU_C7.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_C6 with (nolock) on dbo.CRS_AssessShare1.C6 = LU_C6.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_C4 with (nolock) on dbo.CRS_AssessShare1.C4 = LU_C4.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_B6 with (nolock) on dbo.CRS_AssessShare1.B6 = LU_B6.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_B5f with (nolock) on dbo.CRS_AssessShare1.B5f = LU_B5f.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_B5e with (nolock) on dbo.CRS_AssessShare1.B5e = LU_B5e.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_B5d with (nolock) on LU_B5d.Code = dbo.CRS_AssessShare1.B5d LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_B5c with (nolock) on dbo.CRS_AssessShare1.B5c = LU_B5c.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_B5b with (nolock) on dbo.CRS_AssessShare1.B5b = LU_B5b.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_B5a with (nolock) on dbo.CRS_AssessShare1.B5a = LU_B5a.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_B4 with (nolock) on LU_B4.Code = dbo.CRS_AssessShare1.B4 LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_B3a with (nolock) on dbo.CRS_AssessShare1.B3a = LU_B3a.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_B3b with (nolock) on LU_B3b.Code = dbo.CRS_AssessShare1.B3b LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_B3c with (nolock) on LU_B3c.Code = dbo.CRS_AssessShare1.B3c LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_B3d with (nolock) on dbo.CRS_AssessShare1.B3d = LU_B3d.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_B2b with (nolock) on dbo.CRS_AssessShare1.B2b = LU_B2b.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_B2a with (nolock) on dbo.CRS_AssessShare1.B2a = LU_B2a.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_A10h_Q with (nolock) on dbo.CRS_AssessShare1.A10h = LU_A10h_Q.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_A10g_Q with (nolock) on dbo.CRS_AssessShare1.A10g = LU_A10g_Q.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_A10f_Q with (nolock) on dbo.CRS_AssessShare1.A10f = LU_A10f_Q.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_A10e_Q with (nolock) on dbo.CRS_AssessShare1.A10e = LU_A10e_Q.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_A10d_Q with (nolock) on dbo.CRS_AssessShare1.A10d = LU_A10d_Q.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_A10c_Q with (nolock) on dbo.CRS_AssessShare1.A10c = LU_A10c_Q.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_A10b_Q with (nolock) on dbo.CRS_AssessShare1.A10b = LU_A10b_Q.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_A10a_Q with (nolock) on dbo.CRS_AssessShare1.A10a = LU_A10a_Q.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_A9f_Q with (nolock) on dbo.CRS_AssessShare1.A9f = LU_A9f_Q.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_A9e_Q with (nolock) on dbo.CRS_AssessShare1.A9e = LU_A9e_Q.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_A9d_Q with (nolock) on dbo.CRS_AssessShare1.A9d = LU_A9d_Q.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_A9c_Q with (nolock) on dbo.CRS_AssessShare1.A9c = LU_A9c_Q.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_A9b_Q with (nolock) on dbo.CRS_AssessShare1.A9b = LU_A9b_Q.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_A9a_Q with (nolock) on dbo.CRS_AssessShare1.A9a = LU_A9a_Q.Code LEFT OUTER JOIN 

--Share 2
    dbo.CRS_AssessShare2 with (nolock) on CRS_Demographic.AbstractID = CRS_AssessShare2.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_H4 with (nolock) on dbo.CRS_AssessShare2.H4 = LU_H4.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_H1b with (nolock) on dbo.CRS_AssessShare2.H1b = LU_H1b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_H1a with (nolock) on dbo.CRS_AssessShare2.H1a = LU_H1a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G9 with (nolock) on dbo.CRS_AssessShare2.G9 = LU_G9.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4fB with (nolock) on LU_G4fB.Code = dbo.CRS_AssessShare2.G4fB LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4fA with (nolock) on dbo.CRS_AssessShare2.G4fA = LU_G4fA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4eB with (nolock) on LU_G4eB.Code = dbo.CRS_AssessShare2.G4eB LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4eA with (nolock) on LU_G4eA.Code = dbo.CRS_AssessShare2.G4eA LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4dB with (nolock) on LU_G4dB.Code = dbo.CRS_AssessShare2.G4dB LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4dA with (nolock) on dbo.CRS_AssessShare2.G4dA = LU_G4dA.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_G4cB with (nolock) on LU_G4cB.Code = dbo.CRS_AssessShare2.G4cB LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4cA with (nolock) on dbo.CRS_AssessShare2.G4cA = LU_G4cA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4bB with (nolock) on dbo.CRS_AssessShare2.G4bB = LU_G4bB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4bA with (nolock) on dbo.CRS_AssessShare2.G4bA = LU_G4bA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4aB with (nolock) on dbo.CRS_AssessShare2.G4aB = LU_G4aB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4aA with (nolock) on dbo.CRS_AssessShare2.G4aA = LU_G4aA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G3b with (nolock) on dbo.CRS_AssessShare2.G3b = LU_G3b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G3a with (nolock) on dbo.CRS_AssessShare2.G3a = LU_G3a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G2B with (nolock) on dbo.CRS_AssessShare2.G2B = LU_G2B.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G2A with (nolock) on dbo.CRS_AssessShare2.G2A = LU_G2A.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1jB with (nolock) on dbo.CRS_AssessShare2.G1jB = LU_G1jB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1jA with (nolock) on dbo.CRS_AssessShare2.G1jA = LU_G1jA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1IB with (nolock) on dbo.CRS_AssessShare2.G1iB = LU_G1IB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1IA with (nolock) on dbo.CRS_AssessShare2.G1iA = LU_G1IA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1hB with (nolock) on dbo.CRS_AssessShare2.G1hB = LU_G1hB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1hA with (nolock) on dbo.CRS_AssessShare2.G1hA = LU_G1hA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1gB with (nolock) on dbo.CRS_AssessShare2.G1gB = LU_G1gB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1gA with (nolock) on dbo.CRS_AssessShare2.G1gA = LU_G1gA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1fB with (nolock) on dbo.CRS_AssessShare2.G1fB = LU_G1fB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1fA with (nolock) on dbo.CRS_AssessShare2.G1fA = LU_G1fA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1eB with (nolock) on dbo.CRS_AssessShare2.G1eB = LU_G1eB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1eA with (nolock) on dbo.CRS_AssessShare2.G1eA = LU_G1eA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1dA with (nolock) on dbo.CRS_AssessShare2.G1dA = LU_G1dA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1dB with (nolock) on dbo.CRS_AssessShare2.G1dB = LU_G1dB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1cB with (nolock) on dbo.CRS_AssessShare2.G1cB = LU_G1cB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1cA with (nolock) on dbo.CRS_AssessShare2.G1cA = LU_G1cA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1bB with (nolock) on dbo.CRS_AssessShare2.G1bB = LU_G1bB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1bA with (nolock) on dbo.CRS_AssessShare2.G1bA = LU_G1bA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1aB with (nolock) on dbo.CRS_AssessShare2.G1aB = LU_G1aB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1aA with (nolock) on dbo.CRS_AssessShare2.G1aA = LU_G1aA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F1f with (nolock) on dbo.CRS_AssessShare2.F1f = LU_F1f.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F1e with (nolock) on dbo.CRS_AssessShare2.F1e = LU_F1e.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F1d with (nolock) on dbo.CRS_AssessShare2.F1d = LU_F1d.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F1c with (nolock) on dbo.CRS_AssessShare2.F1c = LU_F1c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F1b with (nolock) on dbo.CRS_AssessShare2.F1b = LU_F1b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F1a with (nolock) on dbo.CRS_AssessShare2.F1a = LU_F1a.Code LEFT OUTER JOIN
--Share 3
    dbo.CRS_AssessShare3 with (nolock) on dbo.CRS_AssessShare3.AbstractID = dbo.CRS_Demographic.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J2b with (nolock) on dbo.CRS_AssessShare3.J2b = LU_J2b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J2a with (nolock) on dbo.CRS_AssessShare3.J2a = LU_J2a.Code LEFT OUTER JOIN
--Share 4
    dbo.CRS_AssessShare4 with (nolock) on CRS_Demographic.AbstractID = CRS_AssessShare4.AbstractID LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_N2 with (nolock) on LU_N2.Code = dbo.CRS_AssessShare4.N2 LEFT OUTER JOIN
    dbo.LU_CodeFile LU_M2b with (nolock) on dbo.CRS_AssessShare4.M2b = LU_M2b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_M2a with (nolock) on dbo.CRS_AssessShare4.M2a = LU_M2a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_K6b with (nolock) on dbo.CRS_AssessShare4.K6b = LU_K6b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_K6a with (nolock) on dbo.CRS_AssessShare4.K6a = LU_K6a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_K3b_Q with (nolock) on LU_K3b_Q.Code = dbo.CRS_AssessShare4.K3b LEFT OUTER JOIN
    dbo.LU_CodeFile LU_K3a_Q with (nolock) on LU_K3a_Q.Code = dbo.CRS_AssessShare4.K3a LEFT OUTER JOIN  
--Share 5
    dbo.CRS_AssessShare5 with (nolock) on CRS_Demographic.AbstractID = CRS_AssessShare5.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Q2 with (nolock) on dbo.CRS_AssessShare5.Q2 = LU_Q2.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_P4e with (nolock) on dbo.CRS_AssessShare5.P4e = LU_P4e.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_P4d with (nolock) on dbo.CRS_AssessShare5.P4d = LU_P4d.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_P4c with (nolock) on dbo.CRS_AssessShare5.P4c = LU_P4c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_P4b with (nolock) on dbo.CRS_AssessShare5.P4b = LU_P4b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_P4a with (nolock) on dbo.CRS_AssessShare5.P4a = LU_P4a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_P1All with (nolock) on dbo.CRS_AssessShare5.P1aAll = LU_P1All.Code LEFT OUTER JOIN

--Diagnosis
    dbo.CRS_Diagnosis with (nolock) on CRS_Demographic.AbstractID = CRS_Diagnosis.AbstractID
    cross join ( select top 1 DisplayCode, UserDescription from LU_YesNoSystem where code = 1 ) Y
    cross join ( select top 1 DisplayCode, UserDescription from LU_YesNoSystem where code = 2 ) N
    cross join ( select top 1 DisplayCode, UserDescription from LU_CodeFile where LookUpID = 1 ) Y1

/*
where 
    (isnull( CRS_Diagnosis.AbstractID, 0) + 
    isnull( CRS_AssessShare1.AbstractID, 0) +
    isnull( CRS_AssessShare2.AbstractID, 0) +
    isnull( CRS_AssessShare3.AbstractID, 0) +
    isnull( CRS_AssessShare4.AbstractID, 0) +
    isnull( CRS_AssessShare5.AbstractID, 0) +
    isnull( CRS_AssessFull1.AbstractID, 0) +
    isnull( CRS_AssessFull2.AbstractID, 0) ) > 0
*/




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

/*d(bo.AB_Diagnosis.DiagnosisICDType = ''T'')*/
CREATE VIEW [dbo].[I10_Diagnosis_VR]
AS
SELECT     TOP 100 PERCENT dbo.AB_Diagnosis.DiagnosisCluster, dbo.ICD_DiagFile10.CIHIValue AS DiagnosisCIHIValue, 
                      dbo.ICD_DiagFile10.DisplayCode AS DiagnosisCode, dbo.ICD_DiagFile10.UserDescription AS DiagnosisCodeDesc, 
                      dbo.ICD_DiagFile10.ShortDescription AS DiagnosisCodeShortDesc, dbo.ICD_DiagFile10.ICD9cm AS DiagnosisICD9cmEquivalent, 
                      dbo.ICD_DiagFile10.ICD9 AS DiagnosisICD9Equivalent, dbo.AB_Diagnosis.DiagnosisOccurrence, Lookup1.DisplayCode AS DiagnosisPrefix, 
                      Lookup1.UserDescription AS DiagnosisPrefixDesc, Lookup2.DisplayCode AS DiagnosisType, Lookup2.UserDescription AS DiagnosisTypeDesc, 
                      dbo.AB_Diagnosis.AbstractID AS zzAbstractLink
FROM         dbo.AB_Diagnosis with (nolock) INNER JOIN
                      dbo.AB_Abstract with (nolock) ON dbo.AB_Diagnosis.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
                      dbo.ICD_DiagFile10 with (nolock) ON dbo.AB_Diagnosis.DiagnosisCode = dbo.ICD_DiagFile10.Code LEFT OUTER JOIN
                      dbo.LU_DiagnosisPrefix Lookup1 with (nolock) ON dbo.AB_Diagnosis.DiagnosisPrefix = Lookup1.Code LEFT OUTER JOIN
                      dbo.LU_DiagnosisType AS Lookup2 with (nolock) ON dbo.AB_Diagnosis.DiagnosisType = Lookup2.Code
WHERE     (dbo.AB_Abstract.ICDType = ''T'')


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_DiagnosisToICD9cm_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[I10_DiagnosisToICD9cm_VR]
AS
SELECT     TOP 100 PERCENT dbo.ICD_DiagFile10.DisplayCode AS DiagnosisCode, dbo.ICD_DiagFile10.UserDescription AS DiagnosisCodeDesc, 
                      dbo.ICD_DiagFile10.ShortDescription AS DiagnosisCodeShortDesc, Lookup1.DisplayCode AS DiagnosisPrefix, 
                      Lookup1.UserDescription AS DiagnosisPrefixDesc, Lookup2.DisplayCode AS DiagnosisType, Lookup2.UserDescription AS DiagnosisTypeDesc, 
                      dbo.ICD_DiagFile10.ICD9 AS ICD9Equivalent, dbo.ICD_DiagFile10.ICD9cm AS ICD9cmEquivalent, AB_Diagnosis_1.DiagnosisICDType, 
                      AB_Diagnosis_1.AbstractID AS zzAbstractLinkICD9cm
FROM         dbo.AB_Diagnosis with (nolock) LEFT OUTER JOIN
                      dbo.ICD_DiagFile10 with (nolock) LEFT OUTER JOIN
                      dbo.ICD_DiagFile9cm with (nolock) ON dbo.ICD_DiagFile10.ICD9cm = dbo.ICD_DiagFile9cm.CIHIValue RIGHT OUTER JOIN
                      dbo.AB_Diagnosis AB_Diagnosis_1 with (nolock) ON dbo.ICD_DiagFile9cm.Code = AB_Diagnosis_1.DiagnosisCode ON 
                      dbo.AB_Diagnosis.DiagnosisCode = dbo.ICD_DiagFile10.Code LEFT OUTER JOIN
                      dbo.LU_DiagnosisPrefix Lookup1 with (nolock) ON dbo.AB_Diagnosis.DiagnosisPrefix = Lookup1.Code LEFT OUTER JOIN
                      dbo.LU_DiagnosisType Lookup2 with (nolock) ON dbo.AB_Diagnosis.DiagnosisType = Lookup2.Code
WHERE     (AB_Diagnosis_1.DiagnosisICDType = ''C'')




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_DPG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE view [dbo].[I10_DPG_VR]
as
select 
    DPGOccurrence = dpg.OccurrenceNumber, 
    DPG_Year, 
    DPG, 
    DPG_RIW, 
    DPG_MOH_RIW, 
    DPG_Description, 
    DPGReturnCode,
    p.DisplayCode as InterventionCode, p.UserDescription as InterventionCodeDesc,
    zzAbstractLink = dpg.AbstractID
from AB_DPG dpg with (nolock) 
    inner join AB_Abstract ab with (nolock) on dpg.AbstractID = ab.AbstractID
    left join icd_procfile10 p with (nolock) on dpg.InterventionCode = p.code
where ab.ICDType = ''T''



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_HIG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[I10_HIG_VR]
AS
SELECT   
    AB_HIG.GrouperYear, 
    AB_HIG.OccurrenceNumber AS Occurrence_Number, 
    HIG_Code, HIG_Description, HIG_Weight, 
    HIG_AgeCategory, HIG_AgeCategoryDesc = (select top 1 hig_age_category_e_desc from dbo.tGrouper_HIG_Age_Category a where a.hig_age_category_code = HIG_AgeCategory and a.methodology_year = AB_HIG.GrouperYear),
    HIG_AtypicalCode, HIG_AtypicalCodeDesc = (select top 1 hig_atypical_e_desc from dbo.tGrouper_HIG_Atypical b where b.hig_atypical_code = HIG_AtypicalCode and b.methodology_year = AB_HIG.GrouperYear),
    HIG_ELOS, HIG_FI_TotalCount, 
    HIG_HomeCareFlag, HIG_MaternalAgeFlag, HIG_PalliativeCareFlag, HIG_OOHFlag, HIG_SCUFlag, HIG_LongStayTrimDays, HIG_ShortStayTrimDays, 
    dbo.AB_HIG.AbstractID AS zzAbstractLink
FROM  AB_HIG with (nolock) 
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_InterventionReplicate_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_InterventionReplicate_VR]
AS
SELECT
    ISNULL(Lookup1.DisplayCode, OCC.AnaestheticTechnique) AS AnaestheticTechnique, ISNULL(Lookup1.UserDescription, 
    OCC.AnaestheticTechniqueDesc) AS AnaestheticTechniqueDesc, 
    ISNULL(Lookup2.DisplayCode, OCC.AnaesthetistID) AS AnaesthetistID, 
    ISNULL(Lookup2.UserDescription, OCC.AnaesthetistIDDesc) AS AnaesthetistIDDesc, 
    
    
    isnull(AB_Intervention.IntervJointIdentifier, OCC.CJRRJointIdentifier)  as CJRRJointIdentifier,
    isnull(LU_CJRR_RevisionReason.DisplayCode, OCC.CJRRRevisionReason) AS CJRRRevisionReason, 
    isnull(LU_CJRR_RevisionReason.UserDescription, OCC.CJRRRevisionReasonDesc) AS CJRRRevisionReasonDesc,

    ISNULL(Lookup3.DisplayCode, OCC.EUL) AS EUL, 
    ISNULL(Lookup3.UserDescription, OCC.EULDesc) AS EULDesc, ISNULL(Lookup4.DisplayCode, OCC.Extra) AS Extra, ISNULL(Lookup4.UserDescription, 
    OCC.ExtraDesc) AS ExtraDesc, Lookup5.DisplayCode AS IntervAttribExtent, Lookup5.UserDescription AS IntervAttribExtentDesc, 
    Lookup6.DisplayCode AS IntervAttribLocation, Lookup6.UserDescription AS IntervAttribLocationDesc, Lookup7.DisplayCode AS IntervAttribStatus, 
    Lookup7.UserDescription AS IntervAttribStatusDesc, dbo.ICD_ProcFile10.CIHIValue AS IntervCIHIValue, dbo.ICD_ProcFile10.DisplayCode AS IntervCode,
    dbo.ICD_ProcFile10.UserDescription AS IntervCodeDesc, dbo.ICD_ProcFile10.ShortDescription AS IntervCodeShortDesc, 
    ISNULL(dbo.AB_Intervention.IntervDate, OCC.IntervDate) AS IntervDate, ISNULL(dbo.AB_Intervention.IntervDateIn, OCC.IntervDateIn) AS IntervDateIn, 
    ISNULL(dbo.AB_Intervention.IntervDateOut, OCC.IntervDateOut) AS IntervDateOut, 

    --PR - 04332
    ISNULL(LU_IntervTimeInUnknown.DisplayCode, OCC.IntervEpisodeStartTimeUnknown)  AS IntervEpisodeStartTimeUnknown, 
    ISNULL(LU_IntervTimeInUnknown.UserDescription, OCC.IntervEpisodeStartTimeUnknownDesc) AS IntervEpisodeStartTimeUnknownDesc, 
    ISNULL(LU_IntervTimeOutUnknown.DisplayCode, OCC.IntervEpisodeEndTimeUnknown)  AS IntervEpisodeEndTimeUnknown, 
    ISNULL(LU_IntervTimeOutUnknown.UserDescription, OCC.IntervEpisodeEndTimeUnknownDesc) AS IntervEpisodeEndTimeUnknownDesc, 

    LU_Flagged.DisplayCode AS IntervFlaggedCategory, LU_Flagged.UserDescription AS IntervFlaggedCategoryDesc, 

    ISNULL(Lookup8.DisplayCode, OCC.IntervLocation)  AS IntervLocation, ISNULL(Lookup8.UserDescription, OCC.IntervLocationDesc) AS IntervLocationDesc, dbo.AB_Intervention.IntervOccurrence, 
    LU_IntervPreAdmitFlag.DisplayCode as IntervPreAdmitFlag, LU_IntervPreAdmitFlag.UserDescription as IntervPreAdmitFlagDesc, 
    ISNULL(Lookup9.DisplayCode, OCC.IntervProviderNumber) AS IntervProviderNumber, ISNULL(Lookup9.UserDescription, OCC.IntervProviderNumberDesc) AS IntervProviderNumberDesc, 
    ISNULL(Lookup15.DisplayCode, OCC.IntervProviderService) AS IntervProviderService, ISNULL(Lookup15.UserDescription, OCC.IntervProviderServiceDesc) AS IntervProviderServiceDesc, 
    ISNULL(Lookup10.DisplayCode, OCC.IntervProviderSpecialty) AS IntervProviderSpecialty, ISNULL(Lookup10.UserDescription, OCC.IntervProviderSpecialtyDesc) AS IntervProviderSpecialtyDesc, 
    --PR - 05248
    ISNULL(LU_IntervSuffix.DisplayCode, OCC.IntervSuffix) AS IntervSuffix, 
    ISNULL(LU_IntervSuffix.UserDescription, OCC.IntervSuffixDesc) AS IntervSuffixDesc, 

    ISNULL(dbo.AB_Intervention.IntervTimeIn, OCC.IntervTimeIn) AS IntervTimeIn, 
    ISNULL(dbo.AB_Intervention.IntervTimeMinutes, OCC.IntervTimeinMinutes) AS IntervTimeinMinutes, 
    ISNULL(dbo.AB_Intervention.IntervTimeOut, OCC.IntervTimeOut) AS IntervTimeOut, 
    ISNULL(Lookup11.DisplayCode, OCC.OOHIndicator) AS OOHIndicator, ISNULL(Lookup11.UserDescription, OCC.OOHIndicatorDesc) AS OOHIndicatorDesc, 
    ISNULL(Lookup12.DisplayCode, OCC.OOHInstitutionNumber) AS OOHInstitutionNumber, 
    ISNULL(Lookup12.UserDescription, OCC.OOHInstitutionNumberDesc) AS OOHInstitutionNumberDesc, 
    ISNULL(Lookup13.DisplayCode, OCC.TissueCode) AS TissueCode, ISNULL(Lookup13.UserDescription, OCC.TissueCodeDesc) AS TissueCodeDesc, 
    ISNULL(Lookup13.DefaultDescription, OCC.TissueCodeDesc_D) AS TissueCodeDesc_D, 
    ISNULL(Lookup14.DisplayCode, OCC.UnplannedReturntoOR) AS UnplannedReturntoOR, 
    ISNULL(Lookup14.UserDescription, OCC.UnplannedReturntoORDesc) AS UnplannedReturntoORDesc, 
    dbo.ICD_ProcFile10.ICD9 AS ICD9Equivalent, dbo.ICD_ProcFile10.ICD9cm AS ICD9cmEquivalent, 
    dbo.AB_Intervention.ORURN,
    dbo.AB_Intervention.AbstractID AS zzAbstractLink
FROM         dbo.AB_Intervention with (nolock) INNER JOIN
                      dbo.AB_Abstract with (nolock) on dbo.AB_Intervention.AbstractID = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
                      dbo.ICD_ProcFile10 with (nolock) on dbo.AB_Intervention.IntervCode = dbo.ICD_ProcFile10.Code LEFT OUTER JOIN
                      dbo.LU_AnaestTechnique Lookup1 with (nolock) on dbo.AB_Intervention.IntervAnaestTechnique = Lookup1.Code LEFT OUTER JOIN
                      dbo.LU_Provider Lookup2 with (nolock) on dbo.AB_Intervention.IntervAnaestID = Lookup2.Code LEFT OUTER JOIN
                      dbo.LU_IntervEUL Lookup3 with (nolock) on dbo.AB_Intervention.IntervEUL = Lookup3.Code LEFT OUTER JOIN
                      dbo.LU_IntervExtra Lookup4 with (nolock) on dbo.AB_Intervention.IntervExtra = Lookup4.Code LEFT OUTER JOIN
                      dbo.LU_IntervAttExtent Lookup5 with (nolock) on dbo.AB_Intervention.IntervAttribExtent = Lookup5.Code LEFT OUTER JOIN
                      dbo.LU_IntervAttLocation Lookup6 with (nolock) on dbo.AB_Intervention.IntervAttribLocation = Lookup6.Code LEFT OUTER JOIN
                      dbo.LU_IntervAttStatus Lookup7 with (nolock) on dbo.AB_Intervention.IntervAttribStatus = Lookup7.Code LEFT OUTER JOIN
                      dbo.LU_IntervLocation_AI Lookup8 with (nolock) on dbo.AB_Intervention.IntervLocation = Lookup8.Code LEFT OUTER JOIN
                      dbo.LU_Provider Lookup9 with (nolock) on dbo.AB_Intervention.IntervProviderNumber = Lookup9.Code LEFT OUTER JOIN
                      dbo.LU_ProviderSpecialty Lookup10 with (nolock) on dbo.AB_Intervention.IntervProviderService = Lookup10.Code LEFT OUTER JOIN
                      dbo.LU_YesBlank Lookup11 with (nolock) on dbo.AB_Intervention.IntervOOHIndicator = Lookup11.Code LEFT OUTER JOIN
                      dbo.LU_Institution_10 Lookup12 with (nolock) on dbo.AB_Intervention.IntervOOHInstitution = Lookup12.Code LEFT OUTER JOIN
                      dbo.LU_IntervTissue Lookup13 with (nolock) on dbo.AB_Intervention.IntervTissueCode = Lookup13.Code LEFT OUTER JOIN
                      dbo.LU_YesBlankAlpha Lookup14 with (nolock) on dbo.AB_Intervention.IntervUnplanReturn = Lookup14.Code LEFT OUTER JOIN
                      dbo.LU_ProviderService Lookup15 with (nolock) on dbo.AB_Intervention.IntervProviderService = Lookup15.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS LU_IntervPreAdmitFlag with (nolock) on dbo.AB_Intervention.IntervPreAdmitFlag = LU_IntervPreAdmitFlag.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS LU_IntervTimeInUnknown with (nolock) on dbo.AB_Intervention.IntervTimeInUnknown = LU_IntervTimeInUnknown.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS LU_IntervTimeOutUnknown with (nolock) on dbo.AB_Intervention.IntervTimeOutUnknown = LU_IntervTimeOutUnknown.Code  LEFT OUTER JOIN
                      --PR - 05248
                      dbo.LU_IntervSuffix with (nolock) on dbo.AB_Intervention.IntervSuffix = LU_IntervSuffix.Code LEFT OUTER JOIN

    dbo.LU_CodeFile AS LU_Flagged with (nolock) on dbo.AB_Intervention.FlaggedIntervention = LU_Flagged.Code LEFT OUTER JOIN
    LU_CJRR_RevisionReason with (nolock) on dbo.AB_Intervention.IntervRevisionReason = LU_CJRR_RevisionReason.Code LEFT OUTER JOIN
                          (SELECT     S.AbstractID, S.IntervOccurrence, MIN(S.IntervOccurrence - T .IntervOccurrence) AS MinOcc
                            FROM          AB_Intervention s INNER JOIN
                                                       (SELECT     AbstractID, IntervOccurrence
                                                         FROM          AB_Intervention with (nolock)
                                                         WHERE      IntervDate IS NOT NULL) T ON S.AbstractID = T .AbstractID AND S.IntervOccurrence >= T .IntervOccurrence
                            GROUP BY S.AbstractID, S.IntervOccurrence) Dif ON dbo.AB_Intervention.AbstractID = Dif.AbstractID AND 
                      dbo.AB_Intervention.IntervOccurrence = Dif.IntervOccurrence LEFT OUTER JOIN
                          (SELECT     Lookup1.DisplayCode AS AnaestheticTechnique, Lookup1.UserDescription AS AnaestheticTechniqueDesc, 
                                                   Lookup2.DisplayCode AS AnaesthetistID, Lookup2.UserDescription AS AnaesthetistIDDesc, 
                                                    AB_Intervention.IntervJointIdentifier as CJRRJointIdentifier,
                                                   LU_CJRR_RevisionReason.DisplayCode AS CJRRRevisionReason, LU_CJRR_RevisionReason.UserDescription AS CJRRRevisionReasonDesc,
                                                   Lookup3.DisplayCode AS EUL, 
                                                   Lookup3.UserDescription AS EULDesc, Lookup4.DisplayCode AS Extra, Lookup4.UserDescription AS ExtraDesc, 
                                                   dbo.AB_Intervention.IntervDate, dbo.AB_Intervention.IntervDateIn, dbo.AB_Intervention.IntervDateOut, 
                                                   Lookup8.DisplayCode AS IntervLocation, Lookup8.UserDescription AS IntervLocationDesc, dbo.AB_Intervention.IntervOccurrence, 
                                                   Lookup9.DisplayCode AS IntervProviderNumber, Lookup9.UserDescription AS IntervProviderNumberDesc, 
                                                   Lookup15.DisplayCode AS IntervProviderService, Lookup15.UserDescription AS IntervProviderServiceDesc, 
                                                   Lookup10.DisplayCode AS IntervProviderSpecialty, Lookup10.UserDescription AS IntervProviderSpecialtyDesc, 
                                                   dbo.AB_Intervention.IntervTimeIn, dbo.AB_Intervention.IntervTimeMinutes AS IntervTimeinMinutes, dbo.AB_Intervention.IntervTimeOut, 
                                                   Lookup11.DisplayCode AS OOHIndicator, Lookup11.UserDescription AS OOHIndicatorDesc, 
                                                   Lookup12.DisplayCode AS OOHInstitutionNumber, Lookup12.UserDescription AS OOHInstitutionNumberDesc, 
                                                   Lookup13.DisplayCode AS TissueCode, Lookup13.UserDescription AS TissueCodeDesc, 
                                                   Lookup13.DefaultDescription AS TissueCodeDesc_D, Lookup14.DisplayCode AS UnplannedReturntoOR, 
                                                   Lookup14.UserDescription AS UnplannedReturntoORDesc, dbo.AB_Intervention.AbstractID,
                                                   --PR - 04332
                                                   LU_IntervTimeInUnknown.DisplayCode as IntervEpisodeStartTimeUnknown, LU_IntervTimeInUnknown.UserDescription as IntervEpisodeStartTimeUnknownDesc,
                                                   LU_IntervTimeOutUnknown.DisplayCode as IntervEpisodeEndTimeUnknown, LU_IntervTimeOutUnknown.UserDescription as IntervEpisodeEndTimeUnknownDesc,
                                                   LU_IntervSuffix.DisplayCode as IntervSuffix, LU_IntervSuffix.UserDescription as IntervSuffixDesc
    
                            FROM          dbo.AB_Intervention with (nolock) INNER JOIN
                                                   AB_Abstract with (nolock) on AB_Intervention.AbstractID = AB_Abstract.AbstractID LEFT OUTER JOIN
                                                   dbo.ICD_ProcFile10 with (nolock) on dbo.AB_Intervention.IntervCode = dbo.ICD_ProcFile10.Code LEFT OUTER JOIN
                                                   dbo.LU_AnaestTechnique Lookup1 with (nolock) on dbo.AB_Intervention.IntervAnaestTechnique = Lookup1.Code LEFT OUTER JOIN
                                                   dbo.LU_Provider Lookup2 with (nolock) on dbo.AB_Intervention.IntervAnaestID = Lookup2.Code LEFT OUTER JOIN
                                                   dbo.LU_IntervEUL Lookup3 with (nolock) on dbo.AB_Intervention.IntervEUL = Lookup3.Code LEFT OUTER JOIN
                                                   dbo.LU_IntervExtra Lookup4 with (nolock) on dbo.AB_Intervention.IntervExtra = Lookup4.Code LEFT OUTER JOIN
                                                   dbo.LU_IntervAttExtent Lookup5 with (nolock) on dbo.AB_Intervention.IntervAttribExtent = Lookup5.Code LEFT OUTER JOIN
                                                   dbo.LU_IntervAttLocation Lookup6 with (nolock) on dbo.AB_Intervention.IntervAttribLocation = Lookup6.Code LEFT OUTER JOIN
                                                   dbo.LU_IntervAttStatus Lookup7 with (nolock) on dbo.AB_Intervention.IntervAttribStatus = Lookup7.Code LEFT OUTER JOIN
                                                   dbo.LU_IntervLocation_AI Lookup8 with (nolock) on dbo.AB_Intervention.IntervLocation = Lookup8.Code LEFT OUTER JOIN
                                                   dbo.LU_Provider Lookup9 with (nolock) on dbo.AB_Intervention.IntervProviderNumber = Lookup9.Code LEFT OUTER JOIN
                                                   dbo.LU_ProviderSpecialty Lookup10 with (nolock) on dbo.AB_Intervention.IntervProviderService = Lookup10.Code LEFT OUTER JOIN
                                                   dbo.LU_YesBlank Lookup11 with (nolock) on dbo.AB_Intervention.IntervOOHIndicator = Lookup11.Code LEFT OUTER JOIN
                                                   dbo.LU_Institution_10 Lookup12 with (nolock) on dbo.AB_Intervention.IntervOOHInstitution = Lookup12.Code LEFT OUTER JOIN
                                                   dbo.LU_IntervTissue Lookup13 with (nolock) on dbo.AB_Intervention.IntervTissueCode = Lookup13.Code LEFT OUTER JOIN
                                                   dbo.LU_YesBlankAlpha Lookup14 with (nolock) on dbo.AB_Intervention.IntervUnplanReturn = Lookup14.Code LEFT OUTER JOIN
                                                   dbo.LU_ProviderService Lookup15 with (nolock) on dbo.AB_Intervention.IntervProviderService = Lookup15.Code LEFT OUTER JOIN
                                                   dbo.LU_CodeFile AS LU_IntervTimeInUnknown with (nolock) on dbo.AB_Intervention.IntervTimeInUnknown = LU_IntervTimeInUnknown.Code LEFT OUTER JOIN
                                                   dbo.LU_CodeFile AS LU_IntervTimeOutUnknown with (nolock) on dbo.AB_Intervention.IntervTimeOutUnknown = LU_IntervTimeOutUnknown.Code LEFT OUTER JOIN
                                                   --PR - 05248
                                                   dbo.LU_IntervSuffix with (nolock) on dbo.AB_Intervention.IntervSuffix = LU_IntervSuffix.Code LEFT OUTER JOIN
                                                   LU_CJRR_RevisionReason with (nolock) on dbo.AB_Intervention.IntervRevisionReason = LU_CJRR_RevisionReason.Code 
                            WHERE      AB_Abstract.ICDType = ''T'' AND AB_Intervention.IntervDate IS NOT NULL) OCC ON dbo.AB_Intervention.AbstractID = OCC.AbstractID AND 
                      dbo.AB_Intervention.IntervOccurrence >= OCC.IntervOccurrence AND dbo.AB_Intervention.IntervOccurrence - OCC.IntervOccurrence = Dif.MinOcc
WHERE     (dbo.AB_Abstract.ICDType = ''T'')
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Interventions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[I10_Interventions_VR]
AS
SELECT     
    Lookup1.DisplayCode AS AnaestheticTechnique, Lookup1.UserDescription AS AnaestheticTechniqueDesc, Lookup2.DisplayCode AS AnaesthetistID, 
    Lookup2.UserDescription AS AnaesthetistIDDesc, 
    
    AB_Intervention.IntervJointIdentifier as CJRRJointIdentifier,
    LU_CJRR_RevisionReason.DisplayCode AS CJRRRevisionReason, LU_CJRR_RevisionReason.UserDescription AS CJRRRevisionReasonDesc,

    Lookup3.DisplayCode AS EUL, Lookup3.UserDescription AS EULDesc, 
    Lookup4.DisplayCode AS Extra, Lookup4.UserDescription AS ExtraDesc, Lookup5.DisplayCode AS IntervAttribExtent, 
    Lookup5.UserDescription AS IntervAttribExtentDesc, Lookup6.DisplayCode AS IntervAttribLocation, 
    Lookup6.UserDescription AS IntervAttribLocationDesc, Lookup7.DisplayCode AS IntervAttribStatus, Lookup7.UserDescription AS IntervAttribStatusDesc, 
    dbo.ICD_ProcFile10.CIHIValue AS IntervCIHIValue, 
    dbo.ICD_ProcFile10.DisplayCode AS IntervCode, 
    dbo.ICD_ProcFile10.UserDescription AS IntervCodeDesc, 
    dbo.ICD_ProcFile10.ShortDescription AS IntervCodeShortDesc, 
    dbo.ICD_IntervClinicianTitle.CCI_ClinicianTitle as IntervCodeClinicianTitle,
	IntervComments,
    
    dbo.AB_Intervention.IntervDate, dbo.AB_Intervention.IntervDateIn, dbo.AB_Intervention.IntervDateOut,    
    --PR - 04332
    LU_IntervTimeInUnknown.DisplayCode as IntervEpisodeStartTimeUnknown, LU_IntervTimeInUnknown.UserDescription as IntervEpisodeStartTimeUnknownDesc,
    LU_IntervTimeOutUnknown.DisplayCode as IntervEpisodeEndTimeUnknown, LU_IntervTimeOutUnknown.UserDescription as IntervEpisodeEndTimeUnknownDesc,
    LU_Flagged.DisplayCode AS IntervFlaggedCategory, LU_Flagged.UserDescription AS IntervFlaggedCategoryDesc, 

    dbo.ICD_ProcFile10.ICD9 AS IntervICD9Equivalent, dbo.ICD_ProcFile10.ICD9cm AS IntervICD9cmEquivalent, Lookup8.DisplayCode AS IntervLocation, 
    Lookup8.UserDescription AS IntervLocationDesc, dbo.AB_Intervention.IntervOccurrence, 
    LU_IntervPreAdmitFlag.DisplayCode AS IntervPreAdmitFlag, LU_IntervPreAdmitFlag.UserDescription AS IntervPreAdmitFlagDesc, 
    Lookup9.DisplayCode AS IntervProviderNumber, 
    Lookup9.UserDescription AS IntervProviderNumberDesc, 
	(case when Caretype <> 5 then Lookup15.DisplayCode else '''' end) AS IntervProviderService,     
	(case when Caretype <> 5 then Lookup15.UserDescription else '''' end) AS IntervProviderServiceDesc, 
	(case when Caretype = 5 then Lookup10.DisplayCode else '''' end) AS IntervProviderSpecialty,     
	(case when Caretype = 5 then Lookup10.UserDescription else '''' end) AS IntervProviderSpecialtyDesc, 
    dbo.AB_Intervention.IntervTimeIn, 
    dbo.AB_Intervention.IntervTimeMinutes AS IntervTimeinMinutes, dbo.AB_Intervention.IntervTimeOut, Lookup11.DisplayCode AS OOHIndicator, 
    Lookup11.UserDescription AS OOHIndicatorDesc, Lookup12.DisplayCode AS OOHInstitutionNumber, 
    Lookup12.UserDescription AS OOHInstitutionNumberDesc, dbo.LU_YesNoSystem.DisplayCode AS SurgicalCode, 
    dbo.AB_Intervention.IntervTripNumber AS ORTripNumber, dbo.LU_YesNoSystem.UserDescription AS SurgicalCodeDesc, 
    Lookup13.DisplayCode AS TissueCode, Lookup13.UserDescription AS TissueCodeDesc, Lookup13.DefaultDescription AS TissueCodeDesc_D, 
    Lookup14.DisplayCode AS UnplannedReturntoOR, Lookup14.UserDescription AS UnplannedReturntoORDesc, 
    dbo.LU_IntervSuffix.DisplayCode AS IntervSuffix, dbo.LU_IntervSuffix.UserDescription AS IntervSuffixDesc,
    dbo.AB_Intervention.ORURN,
    dbo.AB_Intervention.AbstractID AS zzAbstractLink
    
FROM          
	dbo.AB_Abstract with (nolock) inner join 
    dbo.AB_Intervention with (nolock) on AB_Intervention.AbstractID = AB_Abstract.AbstractID LEFT OUTER JOIN
    dbo.ICD_ProcFile10 with (nolock) on dbo.ICD_ProcFile10.Code = dbo.AB_Intervention.IntervCode LEFT OUTER JOIN
    dbo.ICD_IntervClinicianTitle with (nolock) on dbo.ICD_IntervClinicianTitle.CCICode = dbo.ICD_ProcFile10.CIHIValue left OUTER JOIN

    dbo.LU_YesNoSystem with (nolock) on dbo.LU_YesNoSystem.Code = dbo.ICD_ProcFile10.SurgicalCode left OUTER JOIN
    dbo.LU_IntervSuffix with (nolock) on dbo.AB_Intervention.IntervSuffix = dbo.LU_IntervSuffix.Code left join
    dbo.LU_AnaestTechnique AS Lookup1 with (nolock) on dbo.AB_Intervention.IntervAnaestTechnique = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_Provider AS Lookup2 with (nolock) on dbo.AB_Intervention.IntervAnaestID = Lookup2.Code LEFT OUTER JOIN
    dbo.LU_IntervEUL AS Lookup3 with (nolock) on dbo.AB_Intervention.IntervEUL = Lookup3.Code LEFT OUTER JOIN
    dbo.LU_IntervExtra AS Lookup4 with (nolock) on dbo.AB_Intervention.IntervExtra = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_IntervAttExtent AS Lookup5 with (nolock) on dbo.AB_Intervention.IntervAttribExtent = Lookup5.Code LEFT OUTER JOIN
    dbo.LU_IntervAttLocation AS Lookup6 with (nolock) on dbo.AB_Intervention.IntervAttribLocation = Lookup6.Code LEFT OUTER JOIN
    dbo.LU_IntervAttStatus AS Lookup7 with (nolock) on dbo.AB_Intervention.IntervAttribStatus = Lookup7.Code LEFT OUTER JOIN
    dbo.LU_IntervLocation_AI AS Lookup8 with (nolock) on dbo.AB_Intervention.IntervLocation = Lookup8.Code LEFT OUTER JOIN
    dbo.LU_Provider AS Lookup9 with (nolock) on dbo.AB_Intervention.IntervProviderNumber = Lookup9.Code LEFT OUTER JOIN
    dbo.LU_ProviderSpecialty AS Lookup10 with (nolock) on dbo.AB_Intervention.IntervProviderService = Lookup10.Code LEFT OUTER JOIN
    dbo.LU_YesBlank AS Lookup11 with (nolock) on dbo.AB_Intervention.IntervOOHIndicator = Lookup11.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 AS Lookup12 with (nolock) on dbo.AB_Intervention.IntervOOHInstitution = Lookup12.Code LEFT OUTER JOIN
    dbo.LU_IntervTissue AS Lookup13 with (nolock) on dbo.AB_Intervention.IntervTissueCode = Lookup13.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha AS Lookup14 with (nolock) on dbo.AB_Intervention.IntervUnplanReturn = Lookup14.Code LEFT OUTER JOIN
    dbo.LU_ProviderService AS Lookup15 with (nolock) on dbo.AB_Intervention.IntervProviderService = Lookup15.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS LU_IntervPreAdmitFlag with (nolock) on dbo.AB_Intervention.IntervPreAdmitFlag = LU_IntervPreAdmitFlag.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS LU_IntervTimeInUnknown with (nolock) on dbo.AB_Intervention.IntervTimeInUnknown = LU_IntervTimeInUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS LU_IntervTimeOutUnknown with (nolock) on dbo.AB_Intervention.IntervTimeOutUnknown = LU_IntervTimeOutUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS LU_Flagged with (nolock) on dbo.AB_Intervention.FlaggedIntervention = LU_Flagged.Code LEFT OUTER JOIN
    LU_CJRR_RevisionReason with (nolock) on dbo.AB_Intervention.IntervRevisionReason = LU_CJRR_RevisionReason.Code

WHERE     (dbo.AB_Intervention.IntervICDType = ''T'')

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_MB_ALC_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[I10_MB_ALC_VR]
AS 
SELECT     dbo.AB_MB_ALC.ALCDays, dbo.AB_MB_ALC.Occurrence AS ALCOccurrence, dbo.LU_CodeFile.DisplayCode AS ALCReasonCode, 
                      dbo.LU_CodeFile.UserDescription AS ALCReasonCodeDesc, dbo.AB_MB_ALC.DateDesignatedALC, dbo.AB_MB_ALC.DateReassignedAcute, 
                      dbo.AB_MB_ALC.AbstractID AS zzAbstractLink
FROM         dbo.AB_MB_ALC with (nolock) LEFT OUTER JOIN
                      dbo.LU_CodeFile with (nolock) ON dbo.AB_MB_ALC.ALCReasonCode = dbo.LU_CodeFile.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_MB_FacilityStudy_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[I10_MB_FacilityStudy_VR]
AS 
SELECT     FacilityDateStudy, FacilityStudyCode, Occurrence AS FacilityStudyOccurrence, AbstractID AS zzAbstractLink
FROM         dbo.AB_MB_FacilityStudy with (nolock)

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_MB_NonALC_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'





CREATE VIEW [dbo].[I10_MB_NonALC_VR]
AS 
SELECT     dbo.AB_MB_NonALC.DaysNonALCDelay, dbo.LU_CodeFile.DisplayCode AS NonALCDelayReason, 
                      dbo.LU_CodeFile.UserDescription AS NonALCDelayReasonDesc, dbo.AB_MB_NonALC.Occurrence AS NonALCOccurrence, 
                      dbo.AB_MB_NonALC.AbstractID AS zzAbstractLink
FROM         dbo.AB_MB_NonALC with (nolock) LEFT OUTER JOIN
                      dbo.LU_CodeFile with (nolock) ON dbo.AB_MB_NonALC.NonALCDelayReason = dbo.LU_CodeFile.Code










' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_MB_ReproductiveNewborn_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE  VIEW [dbo].[I10_MB_ReproductiveNewborn_VR]
AS
SELECT 
    --CIHI
    [CIHI Reproductive Information Section] = '''',
    dbo.AB_ReproductiveCare.PrevTermDelivery AS [#ofPreviousDeliveries], 
    dbo.AB_ReproductiveCare.PrevLiveBirths AS [#ofPreviousLiveBirths], 
    dbo.AB_ReproductiveCare.PrevPreTermDelivery AS [#ofPreviousPreTermDeliveries], 
    dbo.AB_ReproductiveCare.PrevSpontAbortions AS [#ofPrevSpontaneousAbortions], 
    dbo.AB_ReproductiveCare.PrevInduceAbortions AS [#ofPrevTherapueticAbortions], 
    dbo.AB_ReproductiveCare.GestationalAge AS GestationalAgeInWeeks,
    dbo.AB_Manitoba.DeclarationNumber, 
    dbo.AB_ReproductiveCare.DeliveryDate, dbo.AB_ReproductiveCare.DeliveryTime, 
    LU_DeliveryTimeUnknown.DisplayCode as DeliveryTimeUnknown, LU_DeliveryTimeUnknown.UserDescription as DeliveryTimeUnknownDesc, 
    dbo.AB_ReproductiveCare.LastMensesDate AS DateofLastMenses, 
    LU_BreastFeeding.DisplayCode AS BreastFeedingonDischarge, LU_BreastFeeding.UserDescription AS BreastFeedingonDischargeDesc, 
    LU_InitialOR.DisplayCode AS InitialOR, LU_InitialOR.UserDescription AS InitialORDesc,     
    LU_ReprodOR.DisplayCode AS SubsequentOR, LU_ReprodOR.UserDescription AS SubsequentORDesc, 
    LU_ReprodSterilization.DisplayCode AS Sterilization, LU_ReprodSterilization.UserDescription AS SterilizationDesc, 

    LU_Complication1.DisplayCode AS Complication1, LU_Complication1.UserDescription AS Complication1Desc, 
    LU_Complication2.DisplayCode AS Complication2, LU_Complication2.UserDescription AS Complication2Desc, 
    LU_Complication3.DisplayCode AS Complication3, LU_Complication3.UserDescription AS Complication3Desc, 
    dbo.AB_ReproductiveCare.ReprodComments AS ReproductiveCareComments,
    --New born
    [MB New born Information Section] = '''',
    LU_AbstractType.DisplayCode AS AbstractType, LU_AbstractType.UserDescription AS AbstractTypeDesc, 
    
    LU_Presentation.DisplayCode AS Presentation, LU_Presentation.UserDescription AS PresentationDesc, 
    LU_PositionDelviery.DisplayCode as PositionatDelivery, LU_PositionDelviery.UserDescription as PositionatDeliveryDesc, 
    LU_PresentDelivery.DisplayCode as PresentationAtDelivery, LU_PresentDelivery.UserDescription as PresentationAtDeliveryDesc, 
    LU_RoutineCare.DisplayCode AS RoutineCare,     LU_RoutineCare.UserDescription AS RoutineCareDesc, 
    LU_FreeFlowOxygen.DisplayCode AS FreeFlowOxygen, LU_FreeFlowOxygen.UserDescription AS FreeFlowOxygenDesc, 
    LU_BagVentilation.DisplayCode AS BagVentilation, LU_BagVentilation.UserDescription AS BagVentilationDesc, 
    LU_IntubationNotMeconium.DisplayCode AS IntubationNotMeconium, LU_IntubationNotMeconium.UserDescription AS IntubationNotMeconiumDesc, 
    LU_MedicationResuscitation.DisplayCode AS MedicationResuscitation, LU_MedicationResuscitation.UserDescription AS MedicationResuscitationDesc,
    LU_NarconMaloxone.DisplayCode AS NarconMaloxone, LU_NarconMaloxone.UserDescription AS NarconMaloxoneDesc, 
    LU_ChestCompressions.DisplayCode AS ChestCompressions, LU_ChestCompressions.UserDescription AS ChestCompressionsDesc, 
    LU_Feeding.DisplayCode AS Feeding, LU_Feeding.UserDescription AS FeedingDesc, 
    LU_Meconium.DisplayCode AS Meconium, LU_Meconium.UserDescription AS MeconiumDesc, 
    dbo.AB_Manitoba.Apgar1Min, dbo.AB_Manitoba.Apgar5Min, 
    dbo.AB_Manitoba.Gestation as GestationAge_MB, 
    dbo.AB_Manitoba.MotherPHIN, 
    dbo.AB_Abstract.Weight AS Weightingrams, 
    --Mother
    [Mother Information Section] = '''',
    LU_AlcoholDuringPregnancy.DisplayCode AS AlcoholDuringPregnancy, LU_AlcoholDuringPregnancy.UserDescription AS AlcoholDuringPregnancyDesc, 
    LU_AnestheticLabor.DisplayCode as AnalgesicAnestheticDuringLabor, LU_AnestheticLabor.UserDescription as AnalgesicAnestheticDuringLaborDesc,
    LU_Days_WeekAlcoholConsumed.DisplayCode AS Days_WeekAlcoholConsumed, LU_Days_WeekAlcoholConsumed.UserDescription AS Days_WeekAlcoholConsumedDesc,
    dbo.AB_Manitoba.DrinksPerday, 
    --LU_Elopements.DisplayCode AS Elopements, LU_Elopements.UserDescription AS ElopementsDesc, 
    dbo.AB_Manitoba.FirstStageDuration, 
    dbo.AB_Manitoba.Gravida, 
    --LU_LeaveCertificates.DisplayCode AS LeaveCertificates, LU_LeaveCertificates.UserDescription AS LeaveCertificatesDesc, 
    LU_MBEducation.DisplayCode AS MBEducation, LU_MBEducation.UserDescription AS MBEducationDesc, 
    (case when isnull(DischargeDate, AdmitDate) < ''2008/04/01'' then dbo.AB_Manitoba.NumberPrenatalVisits else dbo.AB_Manitoba.NumberPrenatal end) AS PrenatalVisitsNumber, 
    dbo.AB_Manitoba.Parity,
    LU_PostConceptionalFolicAcid.DisplayCode AS PostConceptionalFolicAcid, LU_PostConceptionalFolicAcid.UserDescription AS PostConceptionalFolicAcidDesc,    
    LU_PreConceptionalFolicAcid.DisplayCode AS PreConceptionalFolicAcid, LU_PreConceptionalFolicAcid.UserDescription AS PreConceptionalFolicAcidDesc, 
                      
    dbo.AB_Manitoba.PrenatalVisitDate, 
    LU_PrenatalVisitDateUnknown.DisplayCode AS PrenatalVisitDateUnknown, LU_PrenatalVisitDateUnknown.UserDescription AS PrenatalVisitDateUnknownDesc,
    dbo.AB_Manitoba.SecondStageDuration,
    dbo.AB_Manitoba.SmokingPerDay, dbo.AB_Manitoba.SmokingQuitDate, 
    LU_SmokingQuitDateUnknown.DisplayCode AS SmokingQuitDateUnknown, LU_SmokingQuitDateUnknown.UserDescription AS SmokingQuitDateUnknownDesc,
    dbo.AB_Manitoba.FirstStageDate AS StartFirstStageDate, 
    LU_FirstStageDateUnknown.DisplayCode AS StartFirstStageDateUnknown, LU_FirstStageDateUnknown.UserDescription AS StartFirstStageDateUnknownDes, 
    dbo.AB_Manitoba.FirstStageTime AS StartFirstStageTime, 
    dbo.AB_Manitoba.SecondStageDate AS StartSecondStageDate, 
    LU_SecondStageDateUnknown.DisplayCode AS StartSecondStageDateUnknown, LU_SecondStageDateUnknown.UserDescription AS StartSecondStageDateUnknown_D, 
    dbo.AB_Manitoba.SecondStageTime AS StartSecondStageTime, 
    
    
    dbo.AB_Abstract.AbstractID AS zzAbstractLink
FROM         
    dbo.AB_Abstract with (nolock) inner JOIN

    dbo.AB_Manitoba with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Manitoba.AbstractID left join
    --Mother
    dbo.LU_CodeFile LU_SecondStageDateUnknown with (nolock) on dbo.AB_Manitoba.SecondStageDateUnknown = LU_SecondStageDateUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_FirstStageDateUnknown with (nolock) on dbo.AB_Manitoba.FirstStageDateUnknown = LU_FirstStageDateUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PostConceptionalFolicAcid with (nolock) on dbo.AB_Manitoba.PostConceptionalFolicAcid = LU_PostConceptionalFolicAcid.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PreConceptionalFolicAcid with (nolock) on dbo.AB_Manitoba.PreConceptionalFolicAcid = LU_PreConceptionalFolicAcid.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Days_WeekAlcoholConsumed with (nolock) on dbo.AB_Manitoba.Days_WeekAlcoholConsumed = LU_Days_WeekAlcoholConsumed.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_AlcoholDuringPregnancy with (nolock) on dbo.AB_Manitoba.AlcoholDuringPregnancy = LU_AlcoholDuringPregnancy.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_SmokingQuitDateUnknown with (nolock) on dbo.AB_Manitoba.SmokingQuitDateUnknown = LU_SmokingQuitDateUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_MBEducation with (nolock) on dbo.AB_Manitoba.ObsEducation = LU_MBEducation.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PrenatalVisitDateUnknown with (nolock) on dbo.AB_Manitoba.PrenatalVisitDateUnknown = LU_PrenatalVisitDateUnknown.Code LEFT OUTER JOIN
    --dbo.LU_YesNoAlpha LU_LeaveCertificates with (nolock) on dbo.AB_Manitoba.LeaveCertificates = LU_LeaveCertificates.Code LEFT OUTER JOIN
    --dbo.LU_YesNoAlpha LU_Elopements with (nolock) on dbo.AB_Manitoba.Elopements = LU_Elopements.Code LEFT OUTER JOIN
    --dbo.LU_CodeFile LU_MB_Autopsy with (nolock) on dbo.AB_Manitoba.MB_Autopsy = LU_MB_Autopsy.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_AnestheticLabor with (nolock) on dbo.AB_Manitoba.AnestheticLabor = LU_AnestheticLabor.Code LEFT OUTER JOIN 
    --New Born
    dbo.LU_CodeFile LU_AbstractType with (nolock) on dbo.AB_Manitoba.AbstractType = LU_AbstractType.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Presentation with (nolock) on dbo.AB_Manitoba.Presentation = LU_Presentation.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PresentDelivery with (nolock) on dbo.AB_Manitoba.PresentDelivery = LU_PresentDelivery.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_PositionDelviery with (nolock) on dbo.AB_Manitoba.PositionDelviery = LU_PositionDelviery.Code LEFT OUTER JOIN 
    dbo.LU_YesNoAlpha LU_RoutineCare with (nolock) on dbo.AB_Manitoba.RoutineCare = LU_RoutineCare.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_FreeFlowOxygen with (nolock) on dbo.AB_Manitoba.FreeFlowOxygen = LU_FreeFlowOxygen.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_BagVentilation with (nolock) on dbo.AB_Manitoba.BagVentilation = LU_BagVentilation.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_IntubationNotMeconium with (nolock) on dbo.AB_Manitoba.IntubationNotMeconium = LU_IntubationNotMeconium.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_MedicationResuscitation with (nolock) on dbo.AB_Manitoba.MedicationResuscitation = LU_MedicationResuscitation.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_NarconMaloxone with (nolock) on dbo.AB_Manitoba.NarconMaloxone = LU_NarconMaloxone.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_ChestCompressions with (nolock) on dbo.AB_Manitoba.ChestCompressions = LU_ChestCompressions.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Feeding with (nolock) on dbo.AB_Manitoba.Feeding = LU_Feeding.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Meconium with (nolock) on LU_Meconium.Code = dbo.AB_Manitoba.Meconium LEFT OUTER JOIN
    
    dbo.AB_ReproductiveCare with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_ReproductiveCare.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlank LU_BreastFeeding with (nolock) on dbo.AB_ReproductiveCare.BreastFeeding = LU_BreastFeeding.Code left join
    dbo.LU_ReprodComplication LU_Complication1 with (nolock) on LU_Complication1.Code = dbo.AB_ReproductiveCare.Complication1 left join
    dbo.LU_ReprodComplication LU_Complication2 with (nolock) on LU_Complication2.Code = dbo.AB_ReproductiveCare.Complication2 LEFT OUTER JOIN
    dbo.LU_ReprodComplication LU_Complication3 with (nolock) on dbo.AB_ReproductiveCare.Complication3 = LU_Complication3.Code LEFT OUTER JOIN
    dbo.LU_ReprodOR LU_InitialOR with (nolock) on dbo.AB_ReproductiveCare.InitialOR = LU_InitialOR.Code LEFT OUTER JOIN
    dbo.LU_YesBlank LU_ReprodSterilization with (nolock) on dbo.AB_ReproductiveCare.Sterilization = LU_ReprodSterilization.Code LEFT OUTER JOIN
    dbo.LU_ReprodOR LU_ReprodOR with (nolock) on dbo.AB_ReproductiveCare.SubsequentOR = LU_ReprodOR.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_DeliveryTimeUnknown with (nolock) on dbo.AB_ReproductiveCare.DeliveryTimeUnknown = LU_DeliveryTimeUnknown.Code LEFT OUTER JOIN


    dbo.LU_CareType with (nolock) on dbo.AB_Abstract.CareType = dbo.LU_CareType.Code 

WHERE  DischargeDate > ''2012/04/01'' AND (dbo.AB_Abstract.CareType IN (1, 2)) 


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_MB_TransferWorksheet_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[I10_MB_TransferWorksheet_VR]
AS
SELECT     dbo.AB_TransferService.TransDays AS TransferDays, dbo.AB_TransferService.TransInDate AS TransferInDate, 
                      dbo.AB_TransferService.TransInTime AS TransferInTime, LU_TransferNurseArea.DisplayCode AS TransferNursingArea, 
                      LU_TransferNurseArea.UserDescription AS TransferNursingAreaDesc, dbo.AB_TransferService.TransNursingUnits AS TransferNursingUnits, 
                      dbo.AB_TransferService.Occurrence AS TransferOccurrence, dbo.AB_TransferService.TransOutDate AS TransferOutDate, 
                      dbo.AB_TransferService.TransOutTime AS TransferOutTime, LU_TransferPriority.DisplayCode AS TransferPriority, 
                      LU_TransferPriority.UserDescription AS TransferPriorityDesc, LU_TransferService.DisplayCode AS TransferService, 
                      LU_TransferService.UserDescription AS TransferServiceDesc, LU_TransferServiceType.DisplayCode AS TransferServiceType, 
                      LU_TransferServiceType.UserDescription AS TransferServiceTypeDesc, dbo.AB_TransferService.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_TransferService LEFT OUTER JOIN
    dbo.LU_NurseArea LU_TransferNurseArea ON dbo.AB_TransferService.TransNursingArea = LU_TransferNurseArea.Code  LEFT OUTER JOIN
    dbo.LU_CodeFile LU_TransferPriority ON LU_TransferPriority.Code = dbo.AB_TransferService.TransPriority  LEFT OUTER JOIN
    dbo.LU_PatientServiceType LU_TransferServiceType ON LU_TransferServiceType.Code = dbo.AB_TransferService.TransType LEFT OUTER JOIN
    dbo.LU_PatientService LU_TransferService ON dbo.AB_TransferService.TransService = LU_TransferService.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Obstetrics_Newborn_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Obstetrics_Newborn_VR]
AS
SELECT     

dbo.AB_ReproductiveCare.PrevTermDelivery AS [#ofPreviousDeliveries], 
dbo.AB_ReproductiveCare.PrevLiveBirths AS [#ofPreviousLiveBirths], 
dbo.AB_ReproductiveCare.PrevPreTermDelivery AS [#ofPreviousPreTermDeliveries], 
dbo.AB_ReproductiveCare.PrevSpontAbortions AS [#ofPrevSpontaneousAbortions], 
dbo.AB_ReproductiveCare.PrevInduceAbortions AS [#ofPrevTherapueticAbortions], 
LU_AbstractType.DisplayCode AS AbstractType, LU_AbstractType.UserDescription AS AbstractTypeDesc, 
dbo.AB_Abstract.AdmitDate AS AdmissionDate, 
dbo.AB_Abstract.AdmitTime AS AdmissionTime, 


LU_AnestheticLabor.DisplayCode as AnalgesicAnestheticDuringLabor, LU_AnestheticLabor.UserDescription as AnalgesicAnestheticDuringLaborDesc,
Lookup6.DisplayCode AS AgeCode, Lookup6.UserDescription AS AgeCodeDesc, 
dbo.AB_Abstract.AgeNumber, 
LU_AlcoholDuringPregnancy.DisplayCode AS AlcoholDuringPregnancy, LU_AlcoholDuringPregnancy.UserDescription AS AlcoholDuringPregnancyDesc, 
dbo.AB_Manitoba.Apgar1Min, dbo.AB_Manitoba.Apgar5Min, 
LU_BagVentilation.DisplayCode AS BagVentilation, LU_BagVentilation.UserDescription AS BagVentilationDesc, 
dbo.AB_Abstract.BirthDate, 
Lookup52.DisplayCode AS BreastFeedingonDischarge, Lookup52.UserDescription AS BreastFeedingonDischargeDesc, 
dbo.AB_Abstract.ChartNumber,
LU_ChestCompressions.DisplayCode AS ChestCompressions, LU_ChestCompressions.UserDescription AS ChestCompressionsDesc, 
Lookup54.DisplayCode AS CoderNumber, Lookup54.UserDescription AS CoderNumberDesc, 
dbo.AB_ReproductiveCare.LastMensesDate AS DateOfLastMenses, 
LU_Days_WeekAlcoholConsumed.DisplayCode AS Days_WeekAlcoholConsumed, LU_Days_WeekAlcoholConsumed.UserDescription AS Days_WeekAlcoholConsumedDesc, 
dbo.AB_ReproductiveCare.DeliveryDate, dbo.AB_ReproductiveCare.DeliveryTime, 
dbo.AB_Abstract.DischargeDate, 
Lookup63.DisplayCode AS DischargeDisposition, Lookup63.UserDescription AS DischargeDispositionDesc, 
dbo.AB_Abstract.DischargeTime, 
dbo.AB_Manitoba.DrinksPerday, 
dbo.AB_Abstract.EncounterNumber, 
LU_Feeding.DisplayCode AS Feeding, LU_Feeding.UserDescription AS FeedingDesc, 
dbo.AB_Manitoba.FirstStageDuration, 
LU_FreeFlowOxygen.DisplayCode AS FreeFlowOxygen, LU_FreeFlowOxygen.UserDescription AS FreeFlowOxygenDesc, 
Lookup72.DisplayCode AS Gender, Lookup72.UserDescription AS GenderDesc, 
dbo.AB_Manitoba.Gestation, 
dbo.AB_ReproductiveCare.GestationalAge AS GestationalAgeInWeeks, 
dbo.AB_Manitoba.Gravida, 
LU_IntubationNotMeconium.DisplayCode AS IntubationNotMeconium, LU_IntubationNotMeconium.UserDescription AS IntubationNotMeconiumDesc, 
dbo.AB_Abstract.NewbornChart AS MaternalNewbornChartNumber, 
dbo.AB_Abstract.NewbornDischargeDate AS MaternalNewbornDischargeDate, 
dbo.AB_Manitoba.MB_Weight, 
LU_MBEducation.DisplayCode AS MBEducation, LU_MBEducation.UserDescription AS MBEducationDesc, 
LU_Meconium.DisplayCode AS Meconium, LU_Meconium.UserDescription AS MeconiumDesc, 
LU_MedicationResuscitation.DisplayCode AS MedicationResuscitation, LU_MedicationResuscitation.UserDescription AS MedicationResuscitationDesc, 
LU_MHInstFrom.DisplayCode AS MHFacilityTransferFrom, LU_MHInstFrom.UserDescription AS MHFacilityTransferFromDesc, 
LU_MHInstTo.DisplayCode AS MHFacilityTransferTo, LU_MHInstTo.UserDescription AS MHFacilityTransferToDesc, 
dbo.AB_Manitoba.MotherPHIN, 
ISNULL(dbo.AB_Abstract.LastName, '' '') + '', '' + ISNULL(dbo.AB_Abstract.FirstName, '''') + '' '' + ISNULL(dbo.AB_Abstract.MiddleName, '''') AS NameFull, 
LU_NarconMaloxone.DisplayCode AS NarconMaloxone, LU_NarconMaloxone.UserDescription AS NarconMaloxoneDesc, 
dbo.AB_Manitoba.Parity, 
LU_PositionDelviery.DisplayCode as PositionatDelivery, LU_PositionDelviery.UserDescription as PositionatDeliveryDesc, 
LU_PostConceptionalFolicAcid.DisplayCode AS PostConceptionalFolicAcid, LU_PostConceptionalFolicAcid.UserDescription AS PostConceptionalFolicAcidDesc, 
LU_PreConceptionalFolicAcid.DisplayCode AS PreConceptionalFolicAcid, LU_PreConceptionalFolicAcid.UserDescription AS PreConceptionalFolicAcidDesc, 
dbo.AB_Manitoba.PrenatalVisitDate, 
LU_PrenatalVisitDateUnknown.DisplayCode AS PrenatalVisitDateUnknown, LU_PrenatalVisitDateUnknown.UserDescription AS PrenatalVisitDateUnknownDesc, 
--ED - 01702
-- dbo.AB_Manitoba.NumberPrenatalVisits AS PrenatalVisitsNumber, 
(case when isnull(DischargeDate, AdmitDate) < ''2008/04/01'' then dbo.AB_Manitoba.NumberPrenatalVisits else dbo.AB_Manitoba.NumberPrenatal end) AS PrenatalVisitsNumber, 
LU_Presentation.DisplayCode AS Presentation, LU_Presentation.UserDescription AS PresentationDesc, 
LU_PresentDelivery.DisplayCode as PresentationatDelivery, LU_PresentDelivery.UserDescription as PresentationatDeliveryDesc, 
Lookup111.DisplayCode AS ReportingProvInstNumber, Lookup111.UserDescription AS ReportingProvInstNumberDesc, 
LU_RoutineCare.DisplayCode AS RoutineCare, LU_RoutineCare.UserDescription AS RoutineCareDesc, 
dbo.AB_Manitoba.SecondStageDuration, 
dbo.AB_Manitoba.SmokingPerDay, dbo.AB_Manitoba.SmokingQuitDate, 
LU_SmokingQuitDateUnknown.DisplayCode AS SmokingQuitDateUnknown, LU_SmokingQuitDateUnknown.UserDescription AS SmokingQuitDateUnknownDesc, 
dbo.AB_Manitoba.FirstStageDate AS StartFirstStageDate, 
LU_FirstStageDateUnknown.DisplayCode AS StartFirstStageDateUnknown, LU_FirstStageDateUnknown.UserDescription AS StartFirstStageDateUnknownDes, 
dbo.AB_Manitoba.FirstStageTime AS StartFirstStageTime, 
dbo.AB_Manitoba.SecondStageDate AS StartSecondStageDate, 
LU_SecondStageDateUnknown.DisplayCode AS StartSecondStageDateUnknown, LU_SecondStageDateUnknown.UserDescription AS StartSecondStageDateUnknown_D, 
dbo.AB_Manitoba.SecondStageTime AS StartSecondStageTime, 
Lookup121.DisplayCode AS Sterilization, Lookup121.UserDescription AS SterilizationDesc, 
dbo.AB_Abstract.Weight AS WeightinGrams, 
dbo.AB_Abstract.AbstractID AS zzAbstractLink
FROM         
    dbo.AB_Abstract with (nolock) LEFT OUTER JOIN
    dbo.AB_Manitoba with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_Manitoba.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Meconium with (nolock) on LU_Meconium.Code = dbo.AB_Manitoba.Meconium LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Feeding with (nolock) on dbo.AB_Manitoba.Feeding = LU_Feeding.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_ChestCompressions with (nolock) on dbo.AB_Manitoba.ChestCompressions = LU_ChestCompressions.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_NarconMaloxone with (nolock) on dbo.AB_Manitoba.NarconMaloxone = LU_NarconMaloxone.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_MedicationResuscitation with (nolock) on  dbo.AB_Manitoba.MedicationResuscitation = LU_MedicationResuscitation.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_IntubationNotMeconium with (nolock) on dbo.AB_Manitoba.IntubationNotMeconium = LU_IntubationNotMeconium.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_BagVentilation with (nolock) on dbo.AB_Manitoba.BagVentilation = LU_BagVentilation.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_FreeFlowOxygen with (nolock) on dbo.AB_Manitoba.FreeFlowOxygen = LU_FreeFlowOxygen.Code LEFT OUTER JOIN
    dbo.LU_YesNoAlpha LU_RoutineCare with (nolock) on dbo.AB_Manitoba.RoutineCare = LU_RoutineCare.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Presentation with (nolock) on dbo.AB_Manitoba.Presentation = LU_Presentation.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_SecondStageDateUnknown with (nolock) on dbo.AB_Manitoba.SecondStageDateUnknown = LU_SecondStageDateUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_FirstStageDateUnknown with (nolock) on dbo.AB_Manitoba.FirstStageDateUnknown = LU_FirstStageDateUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PostConceptionalFolicAcid with (nolock) on dbo.AB_Manitoba.PostConceptionalFolicAcid = LU_PostConceptionalFolicAcid.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PreConceptionalFolicAcid with (nolock) on dbo.AB_Manitoba.PreConceptionalFolicAcid = LU_PreConceptionalFolicAcid.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Days_WeekAlcoholConsumed with (nolock) on dbo.AB_Manitoba.Days_WeekAlcoholConsumed = LU_Days_WeekAlcoholConsumed.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_AlcoholDuringPregnancy with (nolock) on dbo.AB_Manitoba.AlcoholDuringPregnancy = LU_AlcoholDuringPregnancy.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_SmokingQuitDateUnknown with (nolock) on dbo.AB_Manitoba.SmokingQuitDateUnknown = LU_SmokingQuitDateUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_MBEducation with (nolock) on dbo.AB_Manitoba.ObsEducation = LU_MBEducation.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PrenatalVisitDateUnknown with (nolock) on dbo.AB_Manitoba.PrenatalVisitDateUnknown = LU_PrenatalVisitDateUnknown.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_MHInstTo with (nolock) on dbo.AB_Manitoba.MHInstTo = LU_MHInstTo.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_MHInstFrom with (nolock) on dbo.AB_Manitoba.MHInstFrom = LU_MHInstFrom.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_AbstractType with (nolock) on dbo.AB_Manitoba.AbstractType = LU_AbstractType.Code LEFT OUTER JOIN
    dbo.LU_AgeCode Lookup6 with (nolock) on dbo.AB_Abstract.AgeCode = Lookup6.Code LEFT OUTER JOIN
    dbo.U_Users Lookup54 with (nolock) on dbo.AB_Abstract.CoderNumber = Lookup54.Code LEFT OUTER JOIN
    dbo.LU_DispositionCode_I Lookup63 with (nolock) on dbo.AB_Abstract.DispositionCode = Lookup63.Code LEFT OUTER JOIN
    dbo.LU_Gender_I Lookup72 with (nolock) on dbo.AB_Abstract.Gender = Lookup72.Code LEFT OUTER JOIN
    dbo.H_InstitutionProfile Lookup111 with (nolock) on dbo.AB_Abstract.InstitutionNumber = Lookup111.Code LEFT OUTER JOIN
    dbo.AB_ReproductiveCare with (nolock) on dbo.AB_Abstract.AbstractID = dbo.AB_ReproductiveCare.AbstractID LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup52 with (nolock) on dbo.AB_ReproductiveCare.BreastFeeding = Lookup52.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup121 with (nolock) on dbo.AB_ReproductiveCare.Sterilization = Lookup121.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PresentDelivery with (nolock) on dbo.AB_Manitoba.PresentDelivery = LU_PresentDelivery.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PositionDelviery with (nolock) on dbo.AB_Manitoba.PositionDelviery = LU_PositionDelviery.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_AnestheticLabor with (nolock) on dbo.AB_Manitoba.AnestheticLabor = LU_AnestheticLabor.Code LEFT OUTER JOIN
    dbo.H_HospitalProfile with (nolock) on dbo.AB_Abstract.HospitalID = H_HospitalProfile.Code 
WHERE  (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType IN (1, 2)) 
--PR - 07485
    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB_ABstract.HospitalID is null or AB_ABstract.HospitalID = 0
        or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB_ABstract.HospitalID, 0))
    --EN - 00666
        or Is_Member(nullif(ReportGroup, '''')) = 1)

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_PatientService_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'





CREATE VIEW [dbo].[I10_PatientService_VR]
AS
SELECT     LEFT(Lookup1.DisplayCode, 2) AS PatientService, Lookup1.DisplayCode AS PatientServiceSubService, 
                      Lookup1.UserDescription AS PatientServiceSubServiceDesc, dbo.AB_PatientService.ServiceDays AS PatientServiceDays, 
                      dbo.AB_PatientService.ServiceOccurrence AS PatientServiceOccurrence, Lookup2.DisplayCode AS PatientServiceType, 
                      Lookup2.UserDescription AS PatientServiceTypeDesc, Lookup3.DisplayCode AS ServiceNurseAreaUnitLoc, 
                      Lookup3.UserDescription AS ServiceNursAreaUnitLocDesc, dbo.AB_PatientService.ServiceNursingUnits, 
                      dbo.AB_PatientService.ServiceTransferInDate AS TransferInDate, dbo.AB_PatientService.ServiceTransferInTime AS TransferInTime, 
                      dbo.AB_PatientService.ServiceTransferOutDate AS TransferOutDate, dbo.AB_PatientService.ServiceTransferOutTime AS TransferOutTime, 
                      dbo.AB_PatientService.AbstractID AS zzAbstractLink
FROM         dbo.AB_PatientService with (nolock) LEFT OUTER JOIN
                      dbo.LU_PatientService Lookup1 with (nolock) ON dbo.AB_PatientService.PatientService = Lookup1.Code LEFT OUTER JOIN
                      dbo.LU_PatientServiceType Lookup2 with (nolock) ON dbo.AB_PatientService.ServiceType = Lookup2.Code LEFT OUTER JOIN
                      dbo.LU_NurseArea Lookup3 with (nolock) ON dbo.AB_PatientService.ServiceNursingArea = Lookup3.Code







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_060_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Projects_060_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 

    InpatientRehabilitation = LU_ProjectQuestion1.DisplayCode, InpatientRehabilitationDesc = LU_ProjectQuestion1.UserDescription, 
    InpatientRehabilitationFacilityNumber =  isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, '''') + isnull(LU_ProjectQuestion5.CIHIValue, '''')  + isnull(LU_ProjectQuestion6.CIHIValue, ''''), 
    InpatientRehabilitationFacilityNumberDesc = (select top 1 UserDescription from LU_Institution_10 where cihivalue = (LU_ProjectQuestion2.CIHIValue + LU_ProjectQuestion3.CIHIValue + LU_ProjectQuestion4.CIHIValue + LU_ProjectQuestion5.CIHIValue + LU_ProjectQuestion6.CIHIValue) order by validto desc), 

    HomeCareRehabilitation = LU_ProjectQuestion7.DisplayCode,HomeCareRehabilitationDesc = LU_ProjectQuestion7.UserDescription, 
    HomeCareRehabilitationLHINNumber = isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''') + isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''') + isnull(LU_ProjectQuestion12.CIHIValue, ''''), 
    HomeCareRehabilitationLHINNumberDesc = (select top 1 UserDescription from LU_Institution_10 where cihivalue = (LU_ProjectQuestion8.CIHIValue + LU_ProjectQuestion9.CIHIValue +  LU_ProjectQuestion10.CIHIValue  + LU_ProjectQuestion11.CIHIValue  + LU_ProjectQuestion12.CIHIValue) order by validto desc), 

    OutpatientRehabilitation = LU_ProjectQuestion13.DisplayCode, OutpatientRehabilitationDesc = LU_ProjectQuestion13.UserDescription, 
    OutpatientRehabilitationFacilityNumber = isnull(p.Question14, '''') + isnull(p.Question15, '''') + isnull(p.Question16, '''') + isnull(p.Question17, '''') + isnull(p.Question18, ''''),
    OutpatientRehabilitationFacilityNumberDesc = (select top 1 UserDescription from LU_Institution_10 where cihivalue = (isnull(p.Question14, '''') + isnull(p.Question15, '''') + isnull(p.Question16, '''') + isnull(p.Question17, '''') + isnull(p.Question18, '''')) order by validto desc), 

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''060'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType in (1, 2))

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_065_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Projects_065_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 

    BundledCareType = (case when len(LU_ProjectQuestion1.CIHIValue) = 6 
                            then LU_ProjectQuestion1.CIHIValue                           
                            else isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, '''') + isnull(LU_ProjectQuestion5.CIHIValue, '''') + isnull(LU_ProjectQuestion6.CIHIValue, '''')
                       end), 
    BundledCareTypeDesc = (case when len(LU_ProjectQuestion1.CIHIValue) = 6 
                            then LU_ProjectQuestion1.UserDescription                           
                            else ''''
                       end), 

    InpatientRehabilitation = isnull(LU_ProjectQuestion7.DisplayCode, ''''), 
    InpatientRehabilitationDesc = isnull(LU_ProjectQuestion7.UserDescription, ''''), 
    InpatientRehabilitationInstitutionNumber =  isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''') + isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, ''''), 
    InpatientRehabilitationInstitutionNumberDesc = (select top 1 UserDescription from LU_Institution_10 where cihivalue = (''5'' + isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''') + isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''')) order by validto desc), 

    HomeCare = LU_ProjectQuestion12.DisplayCode,
    HomeCareRehabilitationDesc = LU_ProjectQuestion12.UserDescription, 
    HomeCareLHINNumber = isnull(LU_ProjectQuestion13.CIHIValue, '''') + isnull(p.Question14, '''') + isnull(p.Question15, '''') + isnull(p.Question16, ''''), 
    HomeCareLHINNumberDesc = (select top 1 UserDescription from LU_Institution_10 where cihivalue = (''5'' + isnull(LU_ProjectQuestion13.CIHIValue, '''') + isnull(p.Question14, '''') + isnull(p.Question15, '''') + isnull(p.Question16, '''')) order by validto desc), 

    OutpatientRehabilitation = isnull(p.Question17, ''''), 
    OutpatientRehabilitationDesc = (case p.Question17 when ''Y'' then ''Outpatient rehabilitation planned for the patient'' 
                                                      when ''N'' then ''Outpatient rehabilitation not planned for this patient''
                                                      when ''D'' then ''Declined''
                                                      when ''9'' then ''Unknown ''
                                                      else ''''
                                    end),
    OutpatientRehabilitationInstitutionNumber = isnull(p.Question18, '''') + isnull(p.Question19, '''') + isnull(p.Question20, '''') + isnull(p.Question21, ''''),
    OutpatientRehabilitationInstitutionNumberDesc = (select top 1 UserDescription from LU_Institution_10 where cihivalue = (''5'' + isnull(p.Question18, '''') + isnull(p.Question19, '''') + isnull(p.Question20, '''') + isnull(p.Question21, '''')) order by validto desc), 

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''065'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 1)

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_100_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Projects_100_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 
    LU_ProjectQuestion1.DisplayCode AS CompleteRecordFlag, LU_ProjectQuestion1.UserDescription AS CompleteRecordFlagDesc, 
    LU_ProjectQuestion2.DisplayCode AS RecordAvailable, LU_ProjectQuestion2.UserDescription AS RecordAvailableDesc, 
    LU_ProjectQuestion3.DisplayCode AS OperativeReportAvailable, LU_ProjectQuestion3.UserDescription AS OperativeReportAvailableDesc, 
    LU_ProjectQuestion4.DisplayCode AS DischargeSummaryAvailable, LU_ProjectQuestion4.UserDescription AS DischargeSummaryAvailableDesc, 
    LU_ProjectQuestion5.DisplayCode AS ObstetricalLabourAndDeliverySummaryAvailable, LU_ProjectQuestion4.UserDescription AS ObstetricalLabourAndDeliverySummaryAvailableDesc, 
    LU_ProjectQuestion6.DisplayCode AS SummarySheetAvailable, LU_ProjectQuestion6.UserDescription AS SummarySheetAvailableDesc, 
    LU_ProjectQuestion7.DisplayCode AS RecordSubsequentlyReviewedAfterCompletion, LU_ProjectQuestion7.UserDescription AS RecordSubsequentlyReviewedAfterCompletionDesc, 
    LU_ProjectQuestion8.DisplayCode AS DataChangedFromOriginalSubmission, LU_ProjectQuestion8.UserDescription AS DataChangedFromOriginalSubmissionDesc, 
    LU_ProjectQuestion9.DisplayCode AS PathologyReportAvailable, LU_ProjectQuestion9.UserDescription AS PathologyReportAvailableDesc, 
    DateofSubsequentReview = (case when DischargeDate < ''2009/04/01'' or ProjectNumber = 4 
                                   then dbo.ConvertToDate(LU_ProjectQuestion13.CIHIValue + p.Question14 + p.Question15 + p.Question16 + p.Question17 + p.Question18 + p.Question19 + p.Question20)
                                   else dbo.ConvertToDate(LU_ProjectQuestion13.CIHIValue + p.Question21 + p.Question22 + p.Question23 + p.Question24 + p.Question16 + p.Question17 + p.Question14 + p.Question15)
                             end),
    DateofSubsequentReview_InValidate = (case when DischargeDate < ''2009/04/01'' or ProjectNumber = 4 
                                              then dbo.CheckInvalidateDate(LU_ProjectQuestion13.CIHIValue + p.Question14 + p.Question15 + p.Question16 + p.Question17 + p.Question18 + p.Question19 + p.Question20)
                                              else dbo.CheckInvalidateDate(LU_ProjectQuestion13.CIHIValue + p.Question21 + p.Question22 + p.Question23 + p.Question24 + p.Question16 + p.Question17 + p.Question14 + p.Question15)
                                         end),
    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion11 with (nolock) on dbo.AB_Project.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion12 with (nolock) on dbo.AB_Project.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE DischargeDate > ''2006/03/31'' and LU_Project.CIHIValue = ''100'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType = 1)
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_150_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Projects_150_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 
    InterventionLineNumber = LU_ProjectQuestion1.CIHIValue + LU_ProjectQuestion1.CIHIValue, 
    DateCompletedReferralReceived = dbo.ConvertToDate(LU_ProjectQuestion1.CIHIValue + LU_ProjectQuestion2.CIHIValue + LU_ProjectQuestion3.CIHIValue + LU_ProjectQuestion4.CIHIValue + LU_ProjectQuestion5.CIHIValue + LU_ProjectQuestion6.CIHIValue + LU_ProjectQuestion7.CIHIValue + LU_ProjectQuestion8.CIHIValue + LU_ProjectQuestion9.CIHIValue + LU_ProjectQuestion10.CIHIValue),
    TypeOfSeverityPriorityUrgencyScoreUsed = LU_ProjectQuestion11.DisplayCode, TypeOfSeverityPriorityUrgencyScoreUsedDesc = LU_ProjectQuestion2.UserDescription, 
    SeverityPriorityUrgencyScore = isnull(LU_ProjectQuestion12.CIHIValue, '''') + isnull(LU_ProjectQuestion13.CIHIValue, '''') + isnull(p.Question14, '''') + isnull(p.Question15, ''''),
    DateType = p.Question16,
    OtherDate = dbo.ConvertToTime(p.Question17 + p.Question18 + p.Question19 + p.Question20 + p.Question21 + p.Question22 + p.Question23 + p.Question24), 

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''150'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType in (1, 2))
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_202_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Projects_202_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 
    Kidneys = LU_ProjectQuestion1.DisplayCode, KidneysDesc = LU_ProjectQuestion1.UserDescription, 
    Liver = LU_ProjectQuestion2.DisplayCode, LiverDesc = LU_ProjectQuestion2.UserDescription, 
    Heart = LU_ProjectQuestion3.DisplayCode, HeartDesc = LU_ProjectQuestion3.UserDescription, 
    Pancreas = LU_ProjectQuestion4.DisplayCode, PancreascDesc = LU_ProjectQuestion4.UserDescription, 
    PancreaticIsletCells = LU_ProjectQuestion5.DisplayCode, PancreaticIsletCellsDesc = LU_ProjectQuestion5.UserDescription, 
    Heartvalves = LU_ProjectQuestion6.DisplayCode, HeartvalvesDesc = LU_ProjectQuestion6.UserDescription, 
    Bowel = LU_ProjectQuestion7.DisplayCode, BowelDesc = LU_ProjectQuestion7.UserDescription, 
    Cornea = LU_ProjectQuestion8.DisplayCode, CorneaDesc = LU_ProjectQuestion8.UserDescription, 
    Skin = LU_ProjectQuestion9.DisplayCode, SkinDesc = LU_ProjectQuestion9.UserDescription, 
    Bone = LU_ProjectQuestion10.DisplayCode, BoneDesc = LU_ProjectQuestion10.UserDescription, 
    Other = LU_ProjectQuestion11.DisplayCode, OtherDesc = LU_ProjectQuestion11.UserDescription, 
    Lung = LU_ProjectQuestion13.DisplayCode, LungDesc = LU_ProjectQuestion13.UserDescription, 
   
    HoursBetweenDeathAndHarvesting = isnull(p.Question14, '''') + isnull(p.Question15, ''''),
    NumberOfOrgansIssueRetrieveved = isnull(p.Question16, '''') + isnull(p.Question17, ''''),
    ORTime = isnull(p.Question18, '''') + isnull(p.Question19, '''') + isnull(p.Question20, ''''),

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''202'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType in (1, 2))
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_250_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Projects_250_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 

    MetalStent = LU_ProjectQuestion1.DisplayCode, MetalStentDesc = LU_ProjectQuestion1.UserDescription, 
    NumberEsophagealPolyps_Episode_1 =  cast((case when isnumeric(isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''')) = 1 then isnull(LU_ProjectQuestion2.CIHIValue, '''') + isnull(LU_ProjectQuestion3.CIHIValue, '''') end) as int), 
    NumberStomachPolyps_Episode_1 =  cast((case when isnumeric(isnull(LU_ProjectQuestion4.CIHIValue, '''') + isnull(LU_ProjectQuestion5.CIHIValue, '''')) = 1 then isnull(LU_ProjectQuestion4.CIHIValue, '''') + isnull(LU_ProjectQuestion5.CIHIValue, '''') end) as int), 
    NumberSmallIntestinePolyps_Episode_1 =  cast((case when isnumeric(isnull(LU_ProjectQuestion6.CIHIValue, '''') + isnull(LU_ProjectQuestion7.CIHIValue, '''')) = 1 then isnull(LU_ProjectQuestion6.CIHIValue, '''') + isnull(LU_ProjectQuestion7.CIHIValue, '''') end) as int), 
    NumberLargeIntestinePolyps_Episode_1 =  cast((case when isnumeric(isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''')) = 1 then isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, '''') end) as int), 
    NumberRectalPolyps_Episode_1 =  cast((case when isnumeric(isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''')) = 1 then isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, '''') end) as int), 

    NumberEsophagealPolyps_Episode_2 =  cast((case when isnumeric(isnull(LU_ProjectQuestion12.CIHIValue, '''') + isnull(LU_ProjectQuestion13.CIHIValue, '''')) = 1 then isnull(LU_ProjectQuestion12.CIHIValue, '''') + isnull(LU_ProjectQuestion13.CIHIValue, '''') end) as int), 
    NumberStomachPolyps_Episode_2 =  cast((case when isnumeric(isnull(p.Question14, '''') + isnull(p.Question15, '''')) = 1 then isnull(p.Question14, '''') + isnull(p.Question15, '''') end) as int), 
    NumberSmallIntestinePolyps_Episode_2 =  cast((case when isnumeric(isnull(p.Question16, '''') + isnull(p.Question17, '''')) = 1 then isnull(p.Question16, '''') + isnull(p.Question17, '''') end) as int), 
    NumberLargeIntestinePolyps_Episode_2 =  cast((case when isnumeric(isnull(p.Question18, '''') + isnull(p.Question19, '''')) = 1 then isnull(p.Question18, '''') + isnull(p.Question19, '''') end) as int), 
    NumberRectalPolyps_Episode_2 =  cast((case when isnumeric(isnull(p.Question20, '''') + isnull(p.Question21, '''')) = 1 then isnull(p.Question20, '''') + isnull(p.Question21, '''') end) as int), 

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''250'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType in (1, 2))
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_315_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Projects_315_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 

    NumberMetalStents_Esophagus      = LU_ProjectQuestion1.CIHIValue,
    NumberMetalStents_SmallIntestine = LU_ProjectQuestion2.CIHIValue,
    NumberMetalStents_LargeIntestine = LU_ProjectQuestion3.CIHIValue,
    NumberMetalStents_Rectum         = LU_ProjectQuestion4.CIHIValue,
    NumberMetalStents_BileDucts      = LU_ProjectQuestion5.CIHIValue,

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code 
    --dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    --dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''315'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType in (1, 2))

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_316_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Projects_316_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 

    SizeLargestExcisedPolyp_Episode_1 = (case when isnumeric(ltrim(isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, ''''))) = 1 then cast(ltrim(isnull(LU_ProjectQuestion1.CIHIValue, '''') + isnull(LU_ProjectQuestion2.CIHIValue, '''')) as int) end),
    NumberPolypsMediumExcised_Episode_1 = (case when isnumeric(ltrim(isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, ''''))) = 1 then cast(ltrim(isnull(LU_ProjectQuestion3.CIHIValue, '''') + isnull(LU_ProjectQuestion4.CIHIValue, '''')) as int) end),
    SizeLargestExcisedPolyp_Episode_2 = (case when isnumeric(ltrim(isnull(LU_ProjectQuestion5.CIHIValue, '''') + isnull(LU_ProjectQuestion6.CIHIValue, ''''))) = 1 then cast(ltrim(isnull(LU_ProjectQuestion5.CIHIValue, '''') + isnull(LU_ProjectQuestion6.CIHIValue, '''')) as int) end),
    NumberPolypsMediumExcised_Episode_2 = (case when isnumeric(ltrim(isnull(LU_ProjectQuestion7.CIHIValue, '''') + isnull(LU_ProjectQuestion8.CIHIValue, ''''))) = 1 then cast(ltrim(isnull(LU_ProjectQuestion7.CIHIValue, '''') + isnull(LU_ProjectQuestion8.CIHIValue, '''')) as int) end),
    SizeLargestExcisedPolyp_Episode_3 = (case when isnumeric(ltrim(isnull(LU_ProjectQuestion9.CIHIValue, '''') + isnull(LU_ProjectQuestion10.CIHIValue, ''''))) = 1 then cast(ltrim(isnull(LU_ProjectQuestion9.CIHIValue, '''') + isnull(LU_ProjectQuestion10.CIHIValue, '''')) as int) end),
    NumberPolypsMediumExcised_Episode_3 = (case when isnumeric(ltrim(isnull(LU_ProjectQuestion11.CIHIValue, '''') + isnull(LU_ProjectQuestion12.CIHIValue, ''''))) = 1 then cast(ltrim(isnull(LU_ProjectQuestion11.CIHIValue, '''') + isnull(LU_ProjectQuestion12.CIHIValue, '''')) as int) end),
    SizeLargestExcisedPolyp_Episode_4 = (case when isnumeric(ltrim(isnull(LU_ProjectQuestion13.CIHIValue, '''') + isnull(p.Question14, ''''))) = 1 then cast(ltrim(isnull(LU_ProjectQuestion13.CIHIValue, '''') + isnull(p.Question14, '''')) as int) end),
    NumberPolypsMediumExcised_Episode_4 = (case when isnumeric(ltrim(isnull(p.Question15, '''') + isnull(p.Question16, ''''))) = 1 then cast(ltrim(isnull(p.Question15, '''') + isnull(p.Question16, '''')) as int) end),

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE LU_Project.CIHIValue = ''316'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType in (1, 2))

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_340_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Projects_340_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 
    LU_ProjectQuestion1.DisplayCode AS CTScanMRIScanCompletedWithin24Hours, LU_ProjectQuestion1.UserDescription AS CTScanMRIScanCompletedWithin24HoursDesc, 
    LU_ProjectQuestion2.DisplayCode AS AdmissionToStrokeUnit, LU_ProjectQuestion2.UserDescription AS AdmissionToStrokeUnitDesc, 
    LU_ProjectQuestion3.DisplayCode AS AdministrationAcuteThrombolysis, LU_ProjectQuestion3.UserDescription AS AdministrationAcuteThrombolysisDesc, 
    MonthOfAcuteThrombolysisAdministration = isnull(LU_ProjectQuestion4.CIHIValue, '''') + isnull(LU_ProjectQuestion5.CIHIValue, ''''),
    DayOfAcuteThrombolysisAdministration = isnull(LU_ProjectQuestion6.CIHIValue, '''') + isnull(LU_ProjectQuestion7.CIHIValue, ''''),
    HourOfAcuteThrombolysisAdministration = isnull(LU_ProjectQuestion8.CIHIValue, '''') + isnull(LU_ProjectQuestion9.CIHIValue, ''''),
    MinuteOfAcuteThrombolysisAdministration = isnull(LU_ProjectQuestion10.CIHIValue, '''') + isnull(LU_ProjectQuestion11.CIHIValue, ''''),
    
    LU_ProjectQuestion12.DisplayCode AS PrescriptionForAntithromboticMedicationDischarge, LU_ProjectQuestion12.UserDescription AS PrescriptionForAntithromboticMedicationDischargeDesc, 

    StrokeSymptomOnsetDate = dbo.ConvertToDate(LU_ProjectQuestion13.CIHIValue + p.Question14 + p.Question15 + p.Question16 + p.Question17 + p.Question18 + p.Question19 + p.Question20),
    StrokeSymptomOnsetDateUnknown = dbo.CheckUnknownDate(LU_ProjectQuestion13.CIHIValue + p.Question14 + p.Question15 + p.Question16 + p.Question17 + p.Question18 + p.Question19 + p.Question20),

    StrokeSymptomOnsetTime = dbo.ConvertToTime(p.Question21 + p.Question22 + p.Question23 + p.Question24),
    StrokeSymptomOnsetTimeUnknown = dbo.CheckUnknownTime(p.Question21 + p.Question22 + p.Question23 + p.Question24),

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE DischargeDate > ''2010/03/31'' and LU_Project.CIHIValue = ''340'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType in (1, 2))
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_640_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Projects_640_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 
    LU_ProjectQuestion1.DisplayCode AS DysphagiaScreening, LU_ProjectQuestion1.UserDescription AS DysphagiaScreeningDesc, 
    LU_ProjectQuestion2.DisplayCode AS TelestrokeConsultation, LU_ProjectQuestion2.UserDescription AS TelestrokeConsultationDesc, 
    isnull(LU_ProjectQuestion3.DisplayCode, '''') + isnull(LU_ProjectQuestion4.DisplayCode, '''') AS MonthOfStrokeUnitAdmission, 
    isnull(LU_ProjectQuestion5.DisplayCode, '''') + isnull(LU_ProjectQuestion6.DisplayCode, '''') AS DayOfStrokeUnitAdmission, 
    isnull(LU_ProjectQuestion7.DisplayCode, '''') + isnull(LU_ProjectQuestion8.DisplayCode, '''') AS MonthOfStrokeUnitDischarge, 
    isnull(LU_ProjectQuestion9.DisplayCode, '''') + isnull(LU_ProjectQuestion10.DisplayCode, '''') AS DayOfStrokeUnitDischarge, 

    (case when isdate(''20'' + LU_ProjectQuestion11.DisplayCode + LU_ProjectQuestion12.DisplayCode + ''/'' + LU_ProjectQuestion13.DisplayCode + p.Question14 + ''/'' + p.Question15 + p.Question16) = 1
          then   cast(''20'' + LU_ProjectQuestion11.DisplayCode + LU_ProjectQuestion12.DisplayCode + ''/'' + LU_ProjectQuestion13.DisplayCode + p.Question14 + ''/'' + p.Question15 + p.Question16 as datetime)
          else null
     end) AS TriageDate, 

    (case when LU_ProjectQuestion11.DisplayCode + LU_ProjectQuestion12.DisplayCode + LU_ProjectQuestion13.DisplayCode + p.Question14 + p.Question15 + p.Question16 = ''999999'' Then ''Y''
          else ''''
     end) AS TriageDateUnknown, 

    (case when isdate(''1900/01/01 '' + p.Question17 + p.Question18 + '':'' + p.Question19 + p.Question20) = 1
          then   cast(''1900/01/01 '' + p.Question17 + p.Question18 + '':'' + p.Question19 + p.Question20 as datetime)
          else null
     end) AS TriageTime, 

    (case when p.Question17 + p.Question18 + '':'' + p.Question19 + p.Question20 = ''99:99''
          then ''Y''
          else ''''
     end) AS TriageTimeUnknown, 

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE DischargeDate > ''2015/03/31'' and LU_Project.CIHIValue = ''640'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType in (1, 2))
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_740_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[I10_Projects_740_VR]
AS
SELECT     
    LU_Project.DisplayCode AS ProjectNumber, LU_Project.UserDescription AS ProjectNumberDesc, 
    p.ProjectOccurrence, 
    LU_ProjectQuestion1.DisplayCode AS DocumentationAlphaFIM, LU_ProjectQuestion1.UserDescription AS DocumentationAlphaFIMDesc, 

    (case when isdate(LU_ProjectQuestion2.DisplayCode + LU_ProjectQuestion3.DisplayCode + LU_ProjectQuestion4.DisplayCode + LU_ProjectQuestion5.DisplayCode + ''/'' + LU_ProjectQuestion6.DisplayCode + LU_ProjectQuestion7.DisplayCode + ''/'' + LU_ProjectQuestion8.DisplayCode + LU_ProjectQuestion9.DisplayCode) = 1
          then   cast(LU_ProjectQuestion2.DisplayCode + LU_ProjectQuestion3.DisplayCode + LU_ProjectQuestion4.DisplayCode + LU_ProjectQuestion5.DisplayCode + ''/'' + LU_ProjectQuestion6.DisplayCode + LU_ProjectQuestion7.DisplayCode + ''/'' + LU_ProjectQuestion8.DisplayCode + LU_ProjectQuestion9.DisplayCode as datetime)
          else null
     end) AS AlphaFIMScoreCompletionDate, 

    isnull(LU_ProjectQuestion10.DisplayCode, '''') + isnull(LU_ProjectQuestion11.DisplayCode, '''') as ProjectFIMRawMotorRating,
    isnull(LU_ProjectQuestion12.DisplayCode, '''') + isnull(LU_ProjectQuestion13.DisplayCode, '''') as ProjectFIMRawCognitiveRating,

    p.AbstractID AS zzAbstractLink
FROM          
    dbo.AB_Abstract with (nolock) inner JOIN
    dbo.AB_Project p with (nolock) on p.AbstractID = dbo.AB_Abstract.AbstractID inner JOIN
    dbo.LU_Project with (nolock) on p.ProjectNumber = LU_Project.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1  with (nolock) on p.Question1 = LU_ProjectQuestion1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2  with (nolock) on p.Question2 = LU_ProjectQuestion2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3  with (nolock) on p.Question3 = LU_ProjectQuestion3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4  with (nolock) on p.Question4 = LU_ProjectQuestion4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5  with (nolock) on p.Question5 = LU_ProjectQuestion5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6  with (nolock) on p.Question6 = LU_ProjectQuestion6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7  with (nolock) on p.Question7 = LU_ProjectQuestion7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8  with (nolock) on p.Question8 = LU_ProjectQuestion8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9  with (nolock) on p.Question9 = LU_ProjectQuestion9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 with (nolock) on p.Question10 = LU_ProjectQuestion10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 with (nolock) on p.Question11 = LU_ProjectQuestion11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 with (nolock) on p.Question12 = LU_ProjectQuestion12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 with (nolock) on p.Question13 = LU_ProjectQuestion13.Code 
WHERE DischargeDate > ''2013/03/31'' and LU_Project.CIHIValue = ''740'' and (dbo.AB_Abstract.ICDType = ''T'') AND (dbo.AB_Abstract.CareType in (1, 2))


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_Question_24_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[I10_Projects_Question_24_VR]
AS
SELECT     
    Lookup1.DisplayCode AS ProjectNumber, Lookup1.UserDescription AS ProjectNumberDesc, 
    dbo.AB_Project.ProjectOccurrence, 
    Lookup2.DisplayCode AS Question1, Lookup2.UserDescription AS Question1Desc, 
    Lookup7.DisplayCode AS Question2, Lookup7.UserDescription AS Question2Desc, 
    Lookup8.DisplayCode AS Question3, Lookup8.UserDescription AS Question3Desc, 
    Lookup9.DisplayCode AS Question4, Lookup9.UserDescription AS Question4Desc, 
    Lookup10.DisplayCode AS Question5, Lookup10.UserDescription AS Question5Desc, 
    Lookup11.DisplayCode AS Question6, Lookup11.UserDescription AS Question6Desc, 
    Lookup12.DisplayCode AS Question7, Lookup12.UserDescription AS Question7Desc, 
    Lookup13.DisplayCode AS Question8, Lookup13.UserDescription AS Question8Desc, 
    Lookup14.DisplayCode AS Question9, Lookup14.UserDescription AS Question9Desc, 
    Lookup3.DisplayCode AS Question10, Lookup3.UserDescription AS Question10Desc, 
    Lookup4.DisplayCode AS Question11, Lookup4.UserDescription AS Question11Desc, 
    Lookup5.DisplayCode AS Question12, Lookup5.UserDescription AS Question12Desc, 
    Lookup6.DisplayCode AS Question13, Lookup6.UserDescription AS Question13Desc, 
    dbo.AB_Project.Question14, 
    dbo.AB_Project.Question15, 
    dbo.AB_Project.Question16, 
    dbo.AB_Project.Question17, 
    dbo.AB_Project.Question18, 
    dbo.AB_Project.Question19, 
    dbo.AB_Project.Question20, 
    dbo.AB_Project.Question21, 
    dbo.AB_Project.Question22, 
    dbo.AB_Project.Question23, 
    dbo.AB_Project.Question24, 
    dbo.AB_Project.AbstractID AS zzAbstractLink
FROM         dbo.AB_Project with (nolock) LEFT OUTER JOIN
    dbo.LU_Project Lookup1 with (nolock) on dbo.AB_Project.ProjectNumber = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1 Lookup2 with (nolock) on dbo.AB_Project.Question1 = Lookup2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 Lookup3 with (nolock) on dbo.AB_Project.Question10 = Lookup3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 Lookup4 with (nolock) on dbo.AB_Project.Question11 = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 Lookup5 with (nolock) on dbo.AB_Project.Question12 = Lookup5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 Lookup6 with (nolock) on dbo.AB_Project.Question13 = Lookup6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2 Lookup7 with (nolock) on dbo.AB_Project.Question2 = Lookup7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3 Lookup8 with (nolock) on dbo.AB_Project.Question3 = Lookup8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4 Lookup9 with (nolock) on dbo.AB_Project.Question4 = Lookup9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5 Lookup10 with (nolock) on dbo.AB_Project.Question5 = Lookup10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6 Lookup11 with (nolock) on dbo.AB_Project.Question6 = Lookup11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7 Lookup12 with (nolock) on dbo.AB_Project.Question7 = Lookup12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8 Lookup13 with (nolock) on dbo.AB_Project.Question8 = Lookup13.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9 Lookup14 with (nolock) on dbo.AB_Project.Question9 = Lookup14.Code










' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Projects_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_Projects_VR]
AS
SELECT     
    Lookup1.DisplayCode AS ProjectNumber, Lookup1.UserDescription AS ProjectNumberDesc, 
    dbo.AB_Project.ProjectOccurrence, 
    Lookup2.DisplayCode AS Question1, Lookup2.UserDescription AS Question1Desc, 
    Lookup7.DisplayCode AS Question2, Lookup7.UserDescription AS Question2Desc, 
    Lookup8.DisplayCode AS Question3, Lookup8.UserDescription AS Question3Desc, 
    Lookup9.DisplayCode AS Question4, Lookup9.UserDescription AS Question4Desc, 
    Lookup10.DisplayCode AS Question5, Lookup10.UserDescription AS Question5Desc, 
    Lookup11.DisplayCode AS Question6, Lookup11.UserDescription AS Question6Desc, 
    Lookup12.DisplayCode AS Question7, Lookup12.UserDescription AS Question7Desc, 
    Lookup13.DisplayCode AS Question8, Lookup13.UserDescription AS Question8Desc, 
    Lookup14.DisplayCode AS Question9, Lookup14.UserDescription AS Question9Desc, 
    Lookup3.DisplayCode AS Question10, Lookup3.UserDescription AS Question10Desc, 
    Lookup4.DisplayCode AS Question11, Lookup4.UserDescription AS Question11Desc, 
    Lookup5.DisplayCode AS Question12, Lookup5.UserDescription AS Question12Desc, 
    Lookup6.DisplayCode AS Question13, Lookup6.UserDescription AS Question13Desc, 
    Question14 = isnull(dbo.AB_Project.Question14, '''') + isnull(dbo.AB_Project.Question15, ''''), 
    Question15 = isnull(dbo.AB_Project.Question16, '''') + isnull(dbo.AB_Project.Question17, ''''), 
    Question16 = isnull(dbo.AB_Project.Question18, '''') + isnull(dbo.AB_Project.Question19, '''') + isnull(dbo.AB_Project.Question20, ''''), 
    Question17 = isnull(dbo.AB_Project.Question21, '''') + isnull(dbo.AB_Project.Question22, '''') + isnull(dbo.AB_Project.Question23, '''') + isnull(dbo.AB_Project.Question24, ''''), 
    --dbo.AB_Project.Question18, 
    --dbo.AB_Project.Question19, 
    --dbo.AB_Project.Question20, 
    --dbo.AB_Project.Question21, 
    --dbo.AB_Project.Question22, 
    --dbo.AB_Project.Question23, 
    --dbo.AB_Project.Question24, 
    dbo.AB_Project.AbstractID AS zzAbstractLink
FROM         dbo.AB_Project with (nolock) LEFT OUTER JOIN
    dbo.LU_Project Lookup1 with (nolock) on dbo.AB_Project.ProjectNumber = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1 Lookup2 with (nolock) on dbo.AB_Project.Question1 = Lookup2.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 Lookup3 with (nolock) on dbo.AB_Project.Question10 = Lookup3.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 Lookup4 with (nolock) on dbo.AB_Project.Question11 = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 Lookup5 with (nolock) on dbo.AB_Project.Question12 = Lookup5.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 Lookup6 with (nolock) on dbo.AB_Project.Question13 = Lookup6.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2 Lookup7 with (nolock) on dbo.AB_Project.Question2 = Lookup7.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3 Lookup8 with (nolock) on dbo.AB_Project.Question3 = Lookup8.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4 Lookup9 with (nolock) on dbo.AB_Project.Question4 = Lookup9.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5 Lookup10 with (nolock) on dbo.AB_Project.Question5 = Lookup10.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6 Lookup11 with (nolock) on dbo.AB_Project.Question6 = Lookup11.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7 Lookup12 with (nolock) on dbo.AB_Project.Question7 = Lookup12.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8 Lookup13 with (nolock) on dbo.AB_Project.Question8 = Lookup13.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9 Lookup14 with (nolock) on dbo.AB_Project.Question9 = Lookup14.Code









' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Provider_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[I10_Provider_VR]
AS
SELECT     Lookup1.DisplayCode AS ProviderNumber, Lookup1.UserDescription AS ProviderNumberDesc, dbo.AB_Provider.ProviderOccurrence, 
                      dbo.LU_ProviderService.DisplayCode AS ProviderService, dbo.LU_ProviderService.UserDescription AS ProviderServiceDesc, 
                      Lookup3.DisplayCode AS ProviderType, Lookup3.UserDescription AS ProviderTypeDesc, dbo.AB_Provider.AbstractID AS zzAbstractLink
FROM         dbo.AB_Provider with (nolock) LEFT OUTER JOIN
                      dbo.LU_ProviderService with (nolock) ON dbo.AB_Provider.ProviderService = dbo.LU_ProviderService.Code LEFT OUTER JOIN
                      dbo.LU_Provider Lookup1 with (nolock) ON dbo.AB_Provider.ProviderNumber = Lookup1.Code LEFT OUTER JOIN
                      dbo.LU_ProviderType Lookup3 with (nolock) ON dbo.AB_Provider.ProviderType = Lookup3.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_QBP_Flag]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'create view [dbo].[I10_QBP_Flag]
as
select 
    LU_QBP_BilateralJointReplacement.DisplayCode as QBP_BilateralJointReplacement, LU_QBP_BilateralJointReplacement.UserDescription as QBP_BilateralJointReplacementDesc, 
    LU_QBP_ChronicObstructivePulmonary.DisplayCode as QBP_ChronicObstructivePulmonary, LU_QBP_ChronicObstructivePulmonary.UserDescription as QBP_ChronicObstructivePulmonaryDesc, 
    LU_QBP_CongestiveHeartFailure.DisplayCode as QBP_CongestiveHeartFailure, LU_QBP_CongestiveHeartFailure.UserDescription as QBP_CongestiveHeartFailureDesc, 
    LU_QBP_CS_Abdominal.DisplayCode as QBP_CS_Abdominal, LU_QBP_CS_Abdominal.UserDescription as QBP_CS_AbdominalDesc, 
    LU_QBP_CSBone.DisplayCode as QBP_CSBone, LU_QBP_CSBone.UserDescription as QBP_CSBoneDesc, 
    LU_QBP_CSBreastDelayedReconstruction.DisplayCode as QBP_CSBreastDelayedReconstruction, LU_QBP_CSBreastDelayedReconstruction.UserDescription as QBP_CSBreastDelayedReconstructionDesc, 
    LU_QBP_CSBreastImmediateReconstruction.DisplayCode as QBP_CSBreastImmediateReconstruction, LU_QBP_CSBreastImmediateReconstruction.UserDescription as QBP_CSBreastImmediateReconstructionDesc, 
    LU_QBP_CSBreastNoReconstruction.DisplayCode as QBP_CSBreastNoReconstruction, LU_QBP_CSBreastNoReconstruction.UserDescription as QBP_CSBreastNoReconstructionDesc, 
    LU_QBP_CSColorectal.DisplayCode as QBP_CSColorectal, LU_QBP_CSColorectal.UserDescription as QBP_CSColorectalDesc, 
    LU_QBP_CSEndocrineOther.DisplayCode as QBP_CSEndocrineOther, LU_QBP_CSEndocrineOther.UserDescription as QBP_CSEndocrineOtherDesc, 
    LU_QBP_CSEsophagus.DisplayCode as QBP_CSEsophagus, LU_QBP_CSEsophagus.UserDescription as QBP_CSEsophagusDesc, 
    LU_QBP_CSGastric.DisplayCode as QBP_CSGastric, LU_QBP_CSGastric.UserDescription as QBP_CSGastricDesc, 
    LU_QBP_CSGentourinary.DisplayCode as QBP_CSGentourinary, LU_QBP_CSGentourinary.UserDescription as QBP_CSGentourinaryDesc, 
    LU_QBP_CSGynecology.DisplayCode as QBP_CSGynecology, LU_QBP_CSGynecology.UserDescription as QBP_CSGynecologyDesc, 
    LU_QBP_CSHNK.DisplayCode as QBP_CSHNK, LU_QBP_CSHNK.UserDescription as QBP_CSHNKDesc, 
    LU_QBP_CSLiver.DisplayCode as QBP_CSLiver, LU_QBP_CSLiver.UserDescription as QBP_CSLiverDesc, 
    LU_QBP_CSLung.DisplayCode as QBP_CSLung, LU_QBP_CSLung.UserDescription as QBP_CSLungDesc, 
    LU_QBP_CSNeuroBrain.DisplayCode as QBP_CSNeuroBrain, LU_QBP_CSNeuroBrain.UserDescription as QBP_CSNeuroBrainDesc, 
    LU_QBP_CSNeuroSpinal.DisplayCode as QBP_CSNeuroSpinal, LU_QBP_CSNeuroSpinal.UserDescription as QBP_CSNeuroSpinalDesc, 
    LU_QBP_CSNonSiteSpecific.DisplayCode as QBP_CSNonSiteSpecific, LU_QBP_CSNonSiteSpecific.UserDescription as QBP_CSNonSiteSpecificDesc, 
    LU_QBP_CSPancreas.DisplayCode as QBP_CSPancreas, LU_QBP_CSPancreas.UserDescription as QBP_CSPancreasDesc, 
    LU_QBP_CSProstate.DisplayCode as QBP_CSProstate, LU_QBP_CSProstate.UserDescription as QBP_CSProstateDesc, 
    LU_QBP_CSSkinLymphNode.DisplayCode as QBP_CSSkinLymphNode, LU_QBP_CSSkinLymphNode.UserDescription as QBP_CSSkinLymphNodeDesc, 
    LU_QBP_CSSkinSoftTissue.DisplayCode as QBP_CSSkinSoftTissue, LU_QBP_CSSkinSoftTissue.UserDescription as QBP_CSSkinSoftTissueDesc, 
    LU_QBP_CSSoftTissue.DisplayCode as QBP_CSSoftTissue, LU_QBP_CSSoftTissue.UserDescription as QBP_CSSoftTissueDesc, 
    LU_QBP_CSThorax.DisplayCode as QBP_CSThorax, LU_QBP_CSThorax.UserDescription as QBP_CSThoraxDesc, 
    LU_QBP_CSThyroid.DisplayCode as QBP_CSThyroid, LU_QBP_CSThyroid.UserDescription as QBP_CSThyroidDesc, 
    LU_QBP_HipFracture.DisplayCode as QBP_HipFracture, LU_QBP_HipFracture.UserDescription as QBP_HipFractureDesc, 
    LU_QBP_CornealTransplant.DisplayCode as QBP_CornealTransplant, LU_QBP_CornealTransplant.UserDescription as QBP_CornealTransplantDesc, 
    LU_QBP_KneeAthroscopy.DisplayCode as QBP_KneeAthroscopy, LU_QBP_KneeAthroscopy.UserDescription as QBP_KneeAthroscopyDesc, 
    LU_QBP_VascularLower.DisplayCode as QBP_VascularLower, LU_QBP_VascularLower.UserDescription as QBP_VascularLowerDesc, 
    LU_QBP_VascularAortic.DisplayCode as QBP_VascularAortic, LU_QBP_VascularAortic.UserDescription as QBP_VascularAorticDesc, 
    LU_QBP_SpineInstruIP.DisplayCode as QBP_SpineInstruIP, LU_QBP_SpineInstruIP.UserDescription as QBP_SpineInstruIPDesc, 
    LU_QBP_SpineNonInstruDay.DisplayCode as QBP_SpineNonInstruDay, LU_QBP_SpineNonInstruDay.UserDescription as QBP_SpineNonInstruDayDesc, 
    LU_QBP_SpineNonInstruIP.DisplayCode as QBP_SpineNonInstruIP, LU_QBP_SpineNonInstruIP.UserDescription as QBP_SpineNonInstruIPDesc, 
    LU_QBP_BilateralCataracts.DisplayCode as QBP_BilateralCataracts, LU_QBP_BilateralCataracts.UserDescription as QBP_BilateralCataractsDesc, 
    LU_QBP_Pneumonia.DisplayCode as QBP_Pneumonia, LU_QBP_Pneumonia.UserDescription as QBP_PneumoniaDesc, 
    LU_QBP_ShoulderArthroplasties.DisplayCode as QBP_ShoulderArthroplasties, LU_QBP_ShoulderArthroplasties.UserDescription as QBP_ShoulderArthroplastiesDesc, 
    LU_QBP_ShoulderOther.DisplayCode as QBP_ShoulderOther, LU_QBP_ShoulderOther.UserDescription as QBP_ShoulderOtherDesc, 
    LU_QBP_ShoulderRepairs.DisplayCode as QBP_ShoulderRepairs, LU_QBP_ShoulderRepairs.UserDescription as QBP_ShoulderRepairsDesc, 
    LU_QBP_ShoulderReverseArthroplaties.DisplayCode as QBP_ShoulderReverseArthroplaties, LU_QBP_ShoulderReverseArthroplaties.UserDescription as QBP_ShoulderReverseArthroplatiesDesc, 
    LU_QBP_StrokeAcuteHemorrhage.DisplayCode as QBP_StrokeAcuteHemorrhage, LU_QBP_StrokeAcuteHemorrhage.UserDescription as QBP_StrokeAcuteHemorrhageDesc, 
    LU_QBP_StrokeAcuteIschemic.DisplayCode as QBP_StrokeAcuteIschemic, LU_QBP_StrokeAcuteIschemic.UserDescription as QBP_StrokeAcuteIschemicDesc, 
    LU_QBP_StrokeAcuteTransient.DisplayCode as QBP_StrokeAcuteTransient, LU_QBP_StrokeAcuteTransient.UserDescription as QBP_StrokeAcuteTransientDesc, 
    LU_QBP_StrokeEndovascularTherapy.DisplayCode as QBP_StrokeEndovascularTherapy, LU_QBP_StrokeEndovascularTherapy.UserDescription as QBP_StrokeEndovascularTherapyDesc, 
    LU_QBP_UnilateralHipReplacement.DisplayCode as QBP_UnilateralHipReplacement, LU_QBP_UnilateralHipReplacement.UserDescription as QBP_UnilateralHipReplacementDesc, 
    LU_QBP_UnilateralKneeReplacement.DisplayCode as QBP_UnilateralKneeReplacement, LU_QBP_UnilateralKneeReplacement.UserDescription as QBP_UnilateralKneeReplacementDesc,     
    AbstractID as zzabstractlink
from AB_QBP_Flag with (nolock) 
    left join LU_QBP_Flag LU_QBP_BilateralJointReplacement with (nolock) on AB_QBP_Flag.QBP_BilateralJointReplacement = LU_QBP_BilateralJointReplacement.Code 
    left join LU_QBP_Flag LU_QBP_ChronicObstructivePulmonary with (nolock) on AB_QBP_Flag.QBP_ChronicObstructivePulmonary = LU_QBP_ChronicObstructivePulmonary.Code 
    left join LU_QBP_Flag LU_QBP_CongestiveHeartFailure with (nolock) on AB_QBP_Flag.QBP_CongestiveHeartFailure = LU_QBP_CongestiveHeartFailure.Code 
    left join LU_QBP_Flag LU_QBP_CS_Abdominal with (nolock) on AB_QBP_Flag.QBP_CS_Abdominal = LU_QBP_CS_Abdominal.Code 
    left join LU_QBP_Flag LU_QBP_CSBone with (nolock) on AB_QBP_Flag.QBP_CSBone = LU_QBP_CSBone.Code 
    left join LU_QBP_Flag LU_QBP_CSBreastDelayedReconstruction with (nolock) on AB_QBP_Flag.QBP_CSBreastDelayedReconstruction = LU_QBP_CSBreastDelayedReconstruction.Code 
    left join LU_QBP_Flag LU_QBP_CSBreastImmediateReconstruction with (nolock) on AB_QBP_Flag.QBP_CSBreastImmediateReconstruction = LU_QBP_CSBreastImmediateReconstruction.Code 
    left join LU_QBP_Flag LU_QBP_CSBreastNoReconstruction with (nolock) on AB_QBP_Flag.QBP_CSBreastNoReconstruction = LU_QBP_CSBreastNoReconstruction.Code 
    left join LU_QBP_Flag LU_QBP_CSColorectal with (nolock) on AB_QBP_Flag.QBP_CSColorectal = LU_QBP_CSColorectal.Code 
    left join LU_QBP_Flag LU_QBP_CSEndocrineOther with (nolock) on AB_QBP_Flag.QBP_CSEndocrineOther = LU_QBP_CSEndocrineOther.Code 
    left join LU_QBP_Flag LU_QBP_CSEsophagus with (nolock) on AB_QBP_Flag.QBP_CSEsophagus = LU_QBP_CSEsophagus.Code 
    left join LU_QBP_Flag LU_QBP_CSGastric with (nolock) on AB_QBP_Flag.QBP_CSGastric = LU_QBP_CSGastric.Code 
    left join LU_QBP_Flag LU_QBP_CSGentourinary with (nolock) on AB_QBP_Flag.QBP_CSGentourinary = LU_QBP_CSGentourinary.Code 
    left join LU_QBP_Flag LU_QBP_CSGynecology with (nolock) on AB_QBP_Flag.QBP_CSGynecology = LU_QBP_CSGynecology.Code 
    left join LU_QBP_Flag LU_QBP_CSHNK with (nolock) on AB_QBP_Flag.QBP_CSHNK = LU_QBP_CSHNK.Code 
    left join LU_QBP_Flag LU_QBP_CSLiver with (nolock) on AB_QBP_Flag.QBP_CSLiver = LU_QBP_CSLiver.Code 
    left join LU_QBP_Flag LU_QBP_CSLung with (nolock) on AB_QBP_Flag.QBP_CSLung = LU_QBP_CSLung.Code 
    left join LU_QBP_Flag LU_QBP_CSNeuroBrain with (nolock) on AB_QBP_Flag.QBP_CSNeuroBrain = LU_QBP_CSNeuroBrain.Code 
    left join LU_QBP_Flag LU_QBP_CSNeuroSpinal with (nolock) on AB_QBP_Flag.QBP_CSNeuroSpinal = LU_QBP_CSNeuroSpinal.Code 
    left join LU_QBP_Flag LU_QBP_CSNonSiteSpecific with (nolock) on AB_QBP_Flag.QBP_CSNonSiteSpecific = LU_QBP_CSNonSiteSpecific.Code 
    left join LU_QBP_Flag LU_QBP_CSPancreas with (nolock) on AB_QBP_Flag.QBP_CSPancreas = LU_QBP_CSPancreas.Code 
    left join LU_QBP_Flag LU_QBP_CSProstate with (nolock) on AB_QBP_Flag.QBP_CSProstate = LU_QBP_CSProstate.Code 
    left join LU_QBP_Flag LU_QBP_CSSkinLymphNode with (nolock) on AB_QBP_Flag.QBP_CSSkinLymphNode = LU_QBP_CSSkinLymphNode.Code 
    left join LU_QBP_Flag LU_QBP_CSSkinSoftTissue with (nolock) on AB_QBP_Flag.QBP_CSSkinSoftTissue = LU_QBP_CSSkinSoftTissue.Code 
    left join LU_QBP_Flag LU_QBP_CSSoftTissue with (nolock) on AB_QBP_Flag.QBP_CSSoftTissue = LU_QBP_CSSoftTissue.Code 
    left join LU_QBP_Flag LU_QBP_CSThorax with (nolock) on AB_QBP_Flag.QBP_CSThorax = LU_QBP_CSThorax.Code 
    left join LU_QBP_Flag LU_QBP_CSThyroid with (nolock) on AB_QBP_Flag.QBP_CSThyroid = LU_QBP_CSThyroid.Code 
    left join LU_QBP_Flag LU_QBP_HipFracture with (nolock) on AB_QBP_Flag.QBP_HipFracture = LU_QBP_HipFracture.Code 
    left join LU_QBP_Flag LU_QBP_CornealTransplant with (nolock) on AB_QBP_Flag.QBP_CornealTransplant = LU_QBP_CornealTransplant.Code 
    left join LU_QBP_Flag LU_QBP_KneeAthroscopy with (nolock) on AB_QBP_Flag.QBP_KneeAthroscopy = LU_QBP_KneeAthroscopy.Code 
    left join LU_QBP_Flag LU_QBP_VascularLower with (nolock) on AB_QBP_Flag.QBP_VascularLower = LU_QBP_VascularLower.Code 
    left join LU_QBP_Flag LU_QBP_VascularAortic with (nolock) on AB_QBP_Flag.QBP_VascularAortic = LU_QBP_VascularAortic.Code 
    left join LU_QBP_Flag LU_QBP_SpineInstruIP with (nolock) on AB_QBP_Flag.QBP_SpineInstruIP = LU_QBP_SpineInstruIP.Code 
    left join LU_QBP_Flag LU_QBP_SpineNonInstruDay with (nolock) on AB_QBP_Flag.QBP_SpineNonInstruDay = LU_QBP_SpineNonInstruDay.Code 
    left join LU_QBP_Flag LU_QBP_SpineNonInstruIP with (nolock) on AB_QBP_Flag.QBP_SpineNonInstruIP = LU_QBP_SpineNonInstruIP.Code 
    left join LU_QBP_Flag LU_QBP_BilateralCataracts with (nolock) on AB_QBP_Flag.QBP_BilateralCataracts = LU_QBP_BilateralCataracts.Code 
    left join LU_QBP_Flag LU_QBP_Pneumonia with (nolock) on AB_QBP_Flag.QBP_Pneumonia = LU_QBP_Pneumonia.Code 
    left join LU_QBP_Flag LU_QBP_ShoulderArthroplasties with (nolock) on AB_QBP_Flag.QBP_ShoulderArthroplasties = LU_QBP_ShoulderArthroplasties.Code 
    left join LU_QBP_Flag LU_QBP_ShoulderOther with (nolock) on AB_QBP_Flag.QBP_ShoulderOther = LU_QBP_ShoulderOther.Code 
    left join LU_QBP_Flag LU_QBP_ShoulderRepairs with (nolock) on AB_QBP_Flag.QBP_ShoulderRepairs = LU_QBP_ShoulderRepairs.Code 
    left join LU_QBP_Flag LU_QBP_ShoulderReverseArthroplaties with (nolock) on AB_QBP_Flag.QBP_ShoulderReverseArthroplaties = LU_QBP_ShoulderReverseArthroplaties.Code 
    left join LU_QBP_Flag LU_QBP_StrokeAcuteHemorrhage with (nolock) on AB_QBP_Flag.QBP_StrokeAcuteHemorrhage = LU_QBP_StrokeAcuteHemorrhage.Code 
    left join LU_QBP_Flag LU_QBP_StrokeAcuteIschemic with (nolock) on AB_QBP_Flag.QBP_StrokeAcuteIschemic = LU_QBP_StrokeAcuteIschemic.Code 
    left join LU_QBP_Flag LU_QBP_StrokeAcuteTransient with (nolock) on AB_QBP_Flag.QBP_StrokeAcuteTransient = LU_QBP_StrokeAcuteTransient.Code 
    left join LU_QBP_Flag LU_QBP_StrokeEndovascularTherapy with (nolock) on AB_QBP_Flag.QBP_StrokeEndovascularTherapy = LU_QBP_StrokeEndovascularTherapy.Code 
    left join LU_QBP_Flag LU_QBP_UnilateralHipReplacement with (nolock) on AB_QBP_Flag.QBP_UnilateralHipReplacement = LU_QBP_UnilateralHipReplacement.Code 
    left join LU_QBP_Flag LU_QBP_UnilateralKneeReplacement with (nolock) on AB_QBP_Flag.QBP_UnilateralKneeReplacement = LU_QBP_UnilateralKneeReplacement.Code 
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_SpecialCareUnits_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[I10_SpecialCareUnits_VR]
AS
SELECT
	dbo.AB_SpecialCareUnit.SCUAdmitDate AS SCUAdmissionDate, dbo.AB_SpecialCareUnit.SCUAdmitTime AS SCUAdmissionTime, 
	LU_AT_Unknown.DisplayCode AS SCUAdmissionTimeUnknown, LU_AT_Unknown.UserDescription AS SCUAdmissionTimeUnknownDesc, 
	
	dbo.ICD_DiagFile10.DisplayCode AS SCUDiagnosis, dbo.ICD_DiagFile10.UserDescription AS SCUDiagnosisDesc, 
	dbo.ICD_DiagFile10.ShortDescription AS SCUDiagnosisShortDesc, 
	dbo.AB_SpecialCareUnit.SCUDischDate AS SCUDischargeDate, dbo.AB_SpecialCareUnit.SCUDischTime AS SCUDischargeTime, 
	LU_DT_Unknown.DisplayCode AS SCUDischargeTimeUnknown, LU_DT_Unknown.UserDescription AS SCUDischargeTimeUnknownDesc, 

	dbo.AB_SpecialCareUnit.SCULOS, dbo.AB_SpecialCareUnit.SCUHours, 
	Lookup1.DisplayCode AS SCUNumber, Lookup1.UserDescription AS SCUNumberDesc, dbo.AB_SpecialCareUnit.SCUOccurrence, 
	dbo.AB_SpecialCareUnit.AbstractID AS zzAbstractLink
FROM         dbo.AB_SpecialCareUnit with (nolock) LEFT OUTER JOIN
	dbo.ICD_DiagFile10 with (nolock) ON dbo.AB_SpecialCareUnit.SCUDiagCode = dbo.ICD_DiagFile10.Code LEFT OUTER JOIN
	dbo.LU_SCUNumber Lookup1 with (nolock) ON dbo.AB_SpecialCareUnit.SCUNumber = Lookup1.Code LEFT OUTER JOIN
	dbo.LU_CodeFile LU_AT_Unknown with (nolock) ON dbo.AB_SpecialCareUnit.SCUAdmitTimeUnknown = LU_AT_Unknown.Code LEFT OUTER JOIN
	dbo.LU_CodeFile LU_DT_Unknown with (nolock) ON dbo.AB_SpecialCareUnit.SCUDischTimeUnknown = LU_DT_Unknown.Code


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Submissions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE View [dbo].[I10_Submissions_VR]
as
select
    AbstractNumber,
    BatchNumber,
    BatchPeriod = (case when AppType in (1, 2, 5) then lu_batchPeriod.DisplayCode else lu_codeFile.DisplayCode end),
    BatchPeriodDesc = (case when AppType in (1, 2, 5) then lu_batchPeriod.UserDescription else lu_codeFile.UserDescription end),
    BatchYear,
    IsSubmitted = LU_IsSubmited.DisplayCode, IsSubmitedDesc = LU_IsSubmited.UserDescription,
    IsCorrected = LU_CIHICorrect.DisplayCode, IsCorrectedDesc = LU_CIHICorrect.UserDescription,
    DateSentToCIHI = CIHIDateSent,
    dbo.AB_Main.AbstractID as zzAbstractlink,
    dbo.AB_Main.UniversalID AS zzUniversalLink
from dbo.ab_main  with (nolock)
    inner join
    (select abstractid, caretype, IsCorrected, IsSubmited, CIHIDateSent, BatchYear, 
        BatchPeriod, BatchNumber, AbstractNumber
     from ab_abstract  with (nolock)
     where ICDType = ''T''
     union 
     select abstractid, caretype = 4, IsCorrected = 0, IsSubmited, CIHIDateSent, BatchYear, 
        BatchPeriod, BatchNumber = null, AbstractNumber = null
     from dbo.CRS_Demographic  with (nolock)
     union
     select abstractid, caretype, IsCorrected, IsSubmited, CIHIDateSent, BatchYear, 
        BatchPeriod, BatchNumber = null, AbstractNumber = null
     from dbo.RH_ClientInfo with (nolock)
     union
     select dbo.OMHRS_SecAA.abstractid, caretype = 7, IsCorrected, IsSubmited, CIHIDateSent, BatchYear, 
        BatchPeriod, BatchNumber = null, AbstractNumber = null
     from dbo.OMHRS_SecAA  with (nolock)
        inner join dbo.OMHRS_RecInfo on dbo.OMHRS_SecAA.AbstractID = dbo.OMHRS_RecInfo.AbstractID
    ) ab on dbo.ab_main.AbstractID = ab.AbstractID and dbo.ab_main.AppType = ab.caretype
    left join lu_batchPeriod with (nolock) on ab.BatchPeriod = lu_batchPeriod.code
    left join lu_codeFile with (nolock) on ab.BatchPeriod = lu_codeFile.code
    --left join LU_CareType on AppType = lu_CareType.Code
    left join LU_YesNoSystem LU_IsSubmited with (nolock) on LU_IsSubmited.code = IsSubmited
    left join LU_CIHICorrect with (nolock) on LU_CIHICorrect.Code = IsCorrected



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'





CREATE VIEW [dbo].[I10_UpdateHistory_VR]
AS
SELECT     coder.DisplayCode AS UpdateCoder, coder.UserDescription AS UpdateCoderDesc, upHis.Updated AS UpdateDate, upHis.UpdateType, 
                      upHis.AbstractID AS zzAbstractLink
FROM         dbo.AB_UpdateHistory upHis with (nolock) INNER JOIN
                      dbo.AB_Abstract ab with (nolock) ON upHis.AbstractID = ab.AbstractID INNER JOIN
                      dbo.U_Users coder with (nolock) ON upHis.Coder = coder.Code
WHERE     (ab.ICDType = ''T'')






' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE view [dbo].[LU_Diagnosis_VR]
as
select 
	ICD_DiagFile10.AgeLow,
	ICD_DiagFile10.AgeHigh,
	ICD_DiagFile10.CIHIValue,
	ICD_DiagFile10.DefaultDescription,
	ICD_DiagFile10.TypeCode as DiagnosisType,
	ICD_DiagFile10.DisplayCode,
	ICD_DiagFile10.DiagnosisGender as Gender,
	H_HospitalProfile.DisplayCode as Hopsital, H_HospitalProfile.DisplayCode as HopsitalDescription, 
	ICD_DiagFile10.ICD9 as ICD9_DiagnosisCode,
	ICD_DiagFile10.ICD9cm as ICD9cm_DiagnosisCode,
	ICD_DiagFile10.ICDNotes,
	ICD_DiagFile10.InterfaceIn,
	(case when ICD_DiagFile10.IsDischarge = 1 then ''Yes'' end) as IsDischargeDiagnosisCode,
	ICD_ProcFile10.DisplayCode as LinkedProcedureCode, ICD_ProcFile10.DisplayCode as LinkedProcedureCodeDescription, 
	LU_Project.DisplayCode as LinkedProject, LU_Project.DisplayCode as LinkedProjectDescription, 
	ICD_DiagFile10.MRDxFlag as MainDiagnosisCodeFlag,
	ICD_DiagFile10.NewbornFlag,
	ICD_DiagFile10.LUText as Notes,
	ICD_DiagFile10.ShortDescription,
	ICD_DiagFile10.ValidFrom,
	ICD_DiagFile10.ValidTo,
	ICD_DiagFile10.UserDescription,

	ICD_DiagFile10.Code as zzDiagnosisLink, 
	ICD_ProcFile10.Code as zzProcedureLink,
	LU_Project.Code as zzProjectLink
from dbo.ICD_DiagFile10 
    left join LU_Project  on ICD_DiagFile10.ProjectLink = LU_Project.Code
    left join ICD_ProcFile10 on ICD_DiagFile10.ICDLink = ICD_ProcFile10.Code
    left join H_HospitalProfile on ICD_DiagFile10.HospitalID = H_HospitalProfile.Code
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_DiagnosisCat_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE   VIEW [dbo].[LU_DiagnosisCat_VR]
AS
SELECT 
    dbo.ICD_DiagCat.DiagCat, dbo.ICD_DiagCat.DiagCatDescription, 
    dbo.ICD_DiagFile10.DisplayCode AS DiagCode
FROM         dbo.ICD_DiagCat INNER JOIN
    dbo.ICD_DiagFile10 ON dbo.ICD_DiagCat.DiagCat = LEFT(dbo.ICD_DiagFile10.CIHIValue, 3) 
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_Intervention_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE view [dbo].[LU_Intervention_VR]
as
select 
	ICD_ProcFile10.AgeLow,
	ICD_ProcFile10.AgeHigh,
	ICD_ProcFile10.CIHIValue,
	ICD_ProcFile10.DefaultDescription,
	ICD_ProcFile10.DisplayCode,
	ICD_ProcFile10.DiagnosisGender as Gender,
	H_HospitalProfile.DisplayCode as Hopsital, H_HospitalProfile.DisplayCode as HopsitalDescription, 
	ICD_ProcFile10.ICD9 as ICD9_ProcudureCode,
	ICD_ProcFile10.ICD9cm as ICD9cm_ProcedureCode,
	ICD_ProcFile10.ICDNotes,
	ICD_ProcFile10.InterfaceIn,
	ICD_DiagFile10.DisplayCode as LinkedDiagnosisCode, ICD_DiagFile10.DisplayCode as LinkedDiagnosisCodeDescription, 
	LU_Project.DisplayCode as LinkedProject, LU_Project.DisplayCode as LinkedProjectDescription, 
	ICD_ProcFile10.LUText as Notes,
	ICD_ProcFile10.ShortDescription,
	ICD_ProcFile10.ValidFrom,
	ICD_ProcFile10.ValidTo,
	ICD_ProcFile10.UserDescription,
    ICD_IntervClinicianTitle.CCI_ClinicianTitle as ClinicianFriendlyTitle,
	ICD_DiagFile10.Code as zzDiagnosisLink, 
	ICD_ProcFile10.Code as zzProcedureLink,
	LU_Project.Code as zzProjectLink
from dbo.ICD_ProcFile10 
    left join LU_Project  on ICD_ProcFile10.ProjectLink = LU_Project.Code
    left join ICD_DiagFile10 on ICD_ProcFile10.ICDLink = ICD_DiagFile10.Code
    left join H_HospitalProfile on ICD_ProcFile10.HospitalID = H_HospitalProfile.Code
    left join ICD_IntervClinicianTitle on ICD_ProcFile10.CIHIValue = ICD_IntervClinicianTitle.CCICode 
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_InterventionCat_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[LU_InterventionCat_VR]
AS
SELECT     
    isnull(dbo.ICD_IntervCat.IntervCat, '''') as IntervCat, 
    isnull(dbo.ICD_IntervCat.IntervCatDescription, '''') as  IntervCatDescription,
    isnull(dbo.ICD_IntervClass.IntervClass, '''') as IntervClass, 
    isnull(dbo.ICD_IntervClass.IntervClassDescription, '''') as IntervClassDescription, 
    dbo.ICD_ProcFile10.DisplayCode AS IntervCode
FROM  dbo.ICD_ProcFile10 Left JOIN
      dbo.ICD_IntervCat ON dbo.ICD_IntervCat.IntervCat = LEFT(dbo.ICD_ProcFile10.CIHIValue, 3) Left JOIN
      dbo.ICD_IntervClass ON dbo.ICD_IntervClass.IntervClass in (LEFT(dbo.ICD_ProcFile10.CIHIValue, 5), LEFT(dbo.ICD_ProcFile10.CIHIValue, 4))
Where dbo.ICD_IntervCat.IntervCat is not null or dbo.ICD_IntervClass.IntervClass is not null


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_LookUpTableName_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'




CREATE View [dbo].[LU_LookUpTableName_VR] 
as
select 
    Distinct
    Coder = U.DisplayCode,
    CoderName = U.UserDescription,
    LookUpTable = Header_User
from  U_UsersFields UF  with (nolock)
    inner join U_Users U with (nolock) on UF.UserID = U.Code
where U.DisplayCode not in (''HL7'', ''99'', ''99999'') and appid in (1100, 1120)
    and isnull(LookUpTable, '''') <> ''''
union
select 
    Distinct
    Coder = U.DisplayCode,
    CoderDesc = U.UserDescription,
    Header_User
from  U_UsersFields UF with (nolock)  
    inner join U_Users U with (nolock) on UF.UserID = U.Code
where U.DisplayCode not in (''HL7'', ''99'', ''99999'') and appid = 201
    and (lookuptable like ''LU_BasicOption%'' or
    Lookuptable like ''LU_ProjectQuestion%'')
union
select 
    Distinct
    Coder = U.DisplayCode,
    CoderDesc = U.UserDescription,
    Header_User = ''Report''
from  U_UsersFields UF with (nolock) 
    inner join U_Users U with (nolock) on UF.UserID = U.Code
where U.DisplayCode not in (''HL7'', ''99'', ''99999'') and appid = 201








' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_PostalCode_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE view [dbo].[LU_PostalCode_VR]
as
select 
	LU_PostalCode.CIHIValue,
	LU_PostalCode.DefaultDescription,
	LU_PostalCode.DisplayCode,
	H_HospitalProfile.DisplayCode as Hopsital, H_HospitalProfile.DisplayCode as HopsitalDescription, 
	LU_PostalCode.InterfaceIn,
	LU_ResidenceCode.DisplayCode as Residencode, LU_ResidenceCode.CIHIValue as ResidencodeCIHIValue, LU_ResidenceCode.UserDescription as ResidencodeDescription, 
	LU_PostalCode.LUText as Notes,
	LU_PostalCode.ValidFrom,
	LU_PostalCode.ValidTo,
	LU_PostalCode.UserDescription
from dbo.LU_PostalCode
    left join LU_ResidenceCode  on LU_PostalCode.LinkCode = LU_ResidenceCode.Code
    left join H_HospitalProfile on LU_PostalCode.HospitalID = H_HospitalProfile.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_Provider_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[LU_Provider_VR]
AS
SELECT     
    dbo.LU_Provider.ProvdrAddress AS Address, LU_Authentication.DisplayCode AS AuthenticationRights, 
    LU_Authentication.UserDescription AS AuthenticationRightsDesc, dbo.LU_Provider.ProvdrBorrower AS BorrowerCode, 
    dbo.LU_Provider.ProvdrCellPhone AS CellPhone, Lookup1.DisplayCode AS ChiefOfStaff, Lookup1.UserDescription AS ChiefOfStaffDesc, 
    Lookup1.DefaultDescription AS ChiefOfStaffDesc_D, dbo.LU_Provider.CIHIValue AS CIHICodeValue, dbo.LU_Provider.ProvdrCity AS City, 
    dbo.LU_Provider.ProvdrCredentials AS Credentials, dbo.LU_Provider.DefaultDescription, dbo.LU_Provider.DisplayCode, 
    dbo.LU_Provider.ProvdrEMail AS EMail, dbo.LU_Provider.EnglishDesc AS EnglishDescription, dbo.LU_Provider.ProvdrFax AS FaxNumber, 
    dbo.LU_Provider.ProvdrFirstName AS FirstName,
    dbo.LU_Provider.FrenchDesc AS FrenchDescription, dbo.LU_Provider.ProvdrHomePhone AS HomePhone, LU_Hospital.DisplayCode AS Hospital, 
    LU_Hospital.UserDescription AS HospitalDesc, dbo.LU_Provider.ProvdrHospitalPhone AS HospitalPhone, 
    
    LU_HCPProgramCode.DisplayCode AS ICP_ProgramCode, LU_HCPProgramCode.UserDescription AS ICP_ProgramCodeDesc, 
    LU_HCPStatus.DisplayCode AS ICD_ProviderStatus,LU_HCPStatus.UserDescription AS ICD_ProviderStatusDesc,

    dbo.LU_Provider.InterfaceIn, 
    dbo.LU_Provider.ProvdrSurName AS LastName,
    dbo.LU_Provider.ProvdrLastVisitDate AS LastVisitDate, Lookup3.DisplayCode AS MaxDeficiency, Lookup3.UserDescription AS MaxDeficiencyDesc, 
    Lookup3.DefaultDescription AS MaxDeficiencyDesc_D, dbo.LU_Provider.MoHCode, dbo.LU_Provider.ProvdrOfficePhone AS OfficePhone, 

    dbo.LU_Provider.ProvdrMiddleName AS MiddleName,
    dbo.LU_Provider.MinDeficiency, dbo.LU_Provider.ProvdrPostal AS PostalCode, LU_PreferReciept.DisplayCode AS PreferredInfoReceipt, 
    LU_PreferReciept.UserDescription AS PreferredInfoReceiptDesc, LU_ProviderBillingSpecialty.DisplayCode AS ProviderBillingSpecialty, 
    LU_ProviderBillingSpecialty.UserDescription AS ProviderBillingSpecialtyDesc, LU_LetterLevel.DisplayCode AS ProviderCurrentLetter, 
    LU_LetterLevel.UserDescription AS ProviderCurrentLetterDesc, LU_CurrentLevel.DisplayCode AS ProviderCurrentLevel, 
    LU_CurrentLevel.UserDescription AS ProviderCurrentLevelDesc, dbo.LLU_Provider_Language.DisplayCode AS ProviderLanguage, 
    dbo.LLU_Provider_Language.UserDescription AS ProviderLanguageDesc, dbo.LU_Provider.ProvdrLastUpdateDate AS ProviderLastUpdateDate, 
    LU_ProviderMISCode.DisplayCode AS ProviderMISCode, LU_ProviderMISCode.UserDescription AS ProviderMISCodeDesc, 
    LU_ProviderProgramCode.DisplayCode AS ProviderProgramCode, LU_ProviderProgramCode.UserDescription AS ProviderProgramCodeDesc, 
    LU_ProviderRequestor.DisplayCode AS ProviderRequestor, LU_ProviderRequestor.UserDescription AS ProviderRequestorDesc, 
    dbo.LU_Provider.ProvdrState AS ProviderStatus, dbo.LU_Provider.ProvdrProvince AS Province, Lookup6.DisplayCode AS Resident, 
    Lookup6.UserDescription AS ResidentDesc, dbo.LU_Provider.SpanishDesc AS SpanishDescription, dbo.LU_Provider.ProvdrTitle AS Title, 
    dbo.LU_Provider.TransInitials AS TranscriptionInitials, dbo.LU_Provider.UserDescription, dbo.LU_Provider.ValidFrom AS ValidFromDate, 
    dbo.LU_Provider.ValidTo AS ValidToDate, dbo.LU_Provider.Code AS zzProviderLink
FROM
    dbo.LU_Provider LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_Authentication ON dbo.LU_Provider.ProvdrAuthent = LU_Authentication.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PreferReciept ON dbo.LU_Provider.PrefReciept = LU_PreferReciept.Code LEFT OUTER JOIN
    dbo.DefLU_LetterLevel LU_CurrentLevel ON dbo.LU_Provider.ProvdrCurLevel = LU_CurrentLevel.Code LEFT OUTER JOIN
    dbo.LLU_Provider_Language ON dbo.LU_Provider.ProvdrLanguage = dbo.LLU_Provider_Language.Code LEFT OUTER JOIN
    dbo.LU_ROI_Requesters LU_ProviderRequestor ON dbo.LU_Provider.ProvdrRequestor = LU_ProviderRequestor.Code LEFT OUTER JOIN
    dbo.DefLU_LetterLevel LU_LetterLevel ON dbo.LU_Provider.ProvdrCurLetter = LU_LetterLevel.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_ProviderProgramCode ON dbo.LU_Provider.ProgramCode = LU_ProviderProgramCode.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_ProviderBillingSpecialty ON dbo.LU_Provider.ProvdrBillSpecialty = LU_ProviderBillingSpecialty.Code LEFT OUTER JOIN
    dbo.LU_MISCode LU_ProviderMISCode ON dbo.LU_Provider.ProvdrMISCode = LU_ProviderMISCode.Code LEFT OUTER JOIN
    dbo.H_HospitalProfile LU_Hospital ON dbo.LU_Provider.HospitalID = LU_Hospital.Code LEFT OUTER JOIN
    dbo.DefLU_LetterLevel Lookup3 ON dbo.LU_Provider.ProvdrMaxLetter = Lookup3.Code LEFT OUTER JOIN
    dbo.LU_Provider Lookup1 ON dbo.LU_Provider.ProvdrChiefOfStaff = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem Lookup6 ON dbo.LU_Provider.ProvdrResident = Lookup6.Code LEFT OUTER JOIN

    dbo.LU_CodeFile LU_HCPProgramCode on dbo.LU_Provider.HCPProgramCode = LU_HCPProgramCode.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_HCPStatus on dbo.LU_Provider.HCPStatus = LU_HCPStatus.Code




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_ProviderLog_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'




CREATE VIEW [dbo].[LU_ProviderLog_VR]
AS
SELECT     dbo.U_Users.DisplayCode AS Coder, dbo.U_Users.UserDescription AS CoderDescription, dbo.REC_Notes.LogNote, dbo.REC_Notes.LogDate, 
                      dbo.REC_Notes.LogTime, dbo.REC_Notes.RecordID AS zzProviderLink
FROM         dbo.REC_Notes LEFT OUTER JOIN
                      dbo.U_Users ON dbo.REC_Notes.LogCoder = dbo.U_Users.Code
WHERE     (dbo.REC_Notes.AppID = 1104)





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_ProviderServices_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'




CREATE VIEW [dbo].[LU_ProviderServices_VR]
AS
SELECT     dbo.LU_ProviderService.DisplayCode AS ProviderService, dbo.LU_ProviderService.UserDescription AS ProviderServiceDesc, 
                      LU_ProvServType_1.DisplayCode AS ProviderServiceType, LU_ProvServType_1.UserDescription AS ProviderServiceTypeDesc, 
                      dbo.LLU_ProviderServices.ValidFrom AS ProvServiceValdFrom, dbo.LLU_ProviderServices.ValidTo AS ProvServiceValdTo, 
                      LU_ProvServType_1.DisplayCode AS ProviderSpecialtyType, LU_ProvServType_1.UserDescription AS ProviderSpecialtyTypeDesc, 
                      dbo.LU_Provider.Code AS zzProviderLink
FROM         dbo.LU_Provider LEFT OUTER JOIN
                      dbo.LU_ProvServType LU_ProvServType_1 RIGHT OUTER JOIN
                      dbo.LU_ProviderService RIGHT OUTER JOIN
                      dbo.LLU_ProviderServices ON dbo.LU_ProviderService.Code = dbo.LLU_ProviderServices.Code ON 
                      LU_ProvServType_1.Code = dbo.LLU_ProviderServices.Type ON dbo.LU_Provider.Code = dbo.LLU_ProviderServices.AssociationID






' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_ProviderSpecialties_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'




CREATE VIEW [dbo].[LU_ProviderSpecialties_VR]
AS
SELECT     dbo.LU_ProviderSpecialty.DisplayCode AS ProviderSpecialty, dbo.LU_ProviderSpecialty.UserDescription AS ProviderSpecialtyDesc, 
                      dbo.LLU_ProviderSpecialty.ValidFrom AS ProvSpecialtyValdFrom, dbo.LLU_ProviderSpecialty.ValidTo AS ProvSpecialtyValdTo, 
                      dbo.LU_Provider.Code AS zzProviderLink, LU_ProvServType_2.DisplayCode AS ProvSpecialtyType, 
                      LU_ProvServType_2.UserDescription AS ProvSpecialtyTypeDesc
FROM         dbo.LU_Provider LEFT OUTER JOIN
                      dbo.LU_ProviderSpecialty RIGHT OUTER JOIN
                      dbo.LLU_ProviderSpecialty ON dbo.LU_ProviderSpecialty.Code = dbo.LLU_ProviderSpecialty.Code LEFT OUTER JOIN
                      dbo.LU_ProvServType LU_ProvServType_2 ON dbo.LLU_ProviderSpecialty.Type = LU_ProvServType_2.Code ON 
                      dbo.LU_Provider.Code = dbo.LLU_ProviderSpecialty.AssociationID





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LU_ProviderUnavailable_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[LU_ProviderUnavailable_VR]
AS
SELECT dbo.LLU_Provider_UnAvailable.DateFrom AS Provider_Unavailablity_Date_From, 
               dbo.LLU_Provider_UnAvailable.DateTo AS Provider_Unavailablity_Date_To, 
               dbo.LLU_Provider_UnAvailable.Occurrence AS Provider_Unavailablity_Occ, dbo.DefLU_UnAvailType.DisplayCode AS Provider_Unavailablity_Type, 
               dbo.DefLU_UnAvailType.UserDescription AS Provider_Unavailablity_TypeDesc, dbo.LLU_Provider_UnAvailable.ProviderID AS zzProviderLink
FROM  dbo.LLU_Provider_UnAvailable LEFT OUTER JOIN
               dbo.DefLU_UnAvailType ON dbo.LLU_Provider_UnAvailable.UnAvailableType = dbo.DefLU_UnAvailType.Code



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LUProviderSuspension_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[LUProviderSuspension_VR]
AS
SELECT     dbo.LLU_Provider_Suspention.DateFrom AS SuspensionFrom, dbo.LLU_Provider_Suspention.DateTo AS SuspensionTo, 
                      dbo.LLU_Provider_Suspention.Occurance AS SuspensionOccurrence, dbo.DefLU_SuspensionType.DisplayCode AS SuspensionType, 
                      dbo.DefLU_SuspensionType.UserDescription AS SuspensionTypeDesc, dbo.LLU_Provider_Suspention.ProviderID AS zzProviderLink
FROM         dbo.LLU_Provider_Suspention LEFT OUTER JOIN
                      dbo.DefLU_SuspensionType ON dbo.LLU_Provider_Suspention.SuspensionType = dbo.DefLU_SuspensionType.Code



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[M_DatabaseUpdates_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'




CREATE VIEW [dbo].[M_DatabaseUpdates_VR]
AS
SELECT     dbo.M_DBULogging.EndTime AS Ended, dbo.M_DBULogging.ExecPath AS ExecutionPath, dbo.M_DBULogging.StartTime AS Started, 
                      dbo.M_DBULogging.TicketID, dbo.M_DBULogging.CreationDate AS UpdateCreationDate, dbo.M_DBULogging.UpdateDescription AS UpdateInformation, 
                      dbo.M_DBULogging.UpdateName AS UpdateName, dbo.U_Users.DisplayCode AS UserUpdatingCode, 
                      dbo.U_Users.UserDescription AS UserUpdatingDesc, dbo.M_DBULogging.WRVersion AS Version
FROM         dbo.M_DBULogging LEFT OUTER JOIN
                      dbo.U_Users ON dbo.M_DBULogging.UserID = dbo.U_Users.Code





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDAS_AuditTrail_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[MDAS_AuditTrail_VR]
AS
SELECT     dbo.U_UsersFields.Header_User AS FieldName, dbo.tMDAS_Audit.NewValue, dbo.tMDAS_Audit.OldValue, dbo.tMDAS_Audit.Updated, 
                      dbo.U_Users.UserDescription AS UserName, dbo.tMDAS_Audit.RecordID AS zzMDASLink
FROM         dbo.tMDAS_Audit with (nolock) LEFT OUTER JOIN
                      dbo.U_UsersFields with (nolock) ON dbo.tMDAS_Audit.Fieldid = dbo.U_UsersFields.FieldID LEFT OUTER JOIN
                      dbo.U_Users with (nolock) ON dbo.tMDAS_Audit.UserID = dbo.U_Users.Code
WHERE     (dbo.U_UsersFields.AppID = 41) AND (dbo.U_UsersFields.UserID = 1) AND (dbo.U_UsersFields.FieldVisible = 1)





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDAS_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[MDAS_UpdateHistory_VR]
AS
SELECT     dbo.tMDAS_UpdateHistory.ActionDate, dbo.U_Users.UserDescription AS UserName, dbo.tMDAS_LU_System.DisplayDescription AS UpdateType, 
                      dbo.tMDAS_UpdateHistory.ID AS zzMDASLink
FROM         dbo.U_Users with (nolock) RIGHT OUTER JOIN
                      dbo.tMDAS_UpdateHistory with (nolock) ON dbo.U_Users.Code = dbo.tMDAS_UpdateHistory.UserID LEFT OUTER JOIN
                      dbo.tMDAS_LU_System with (nolock) ON dbo.tMDAS_UpdateHistory.UpdateType = dbo.tMDAS_LU_System.Code





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_2010_QI_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


--ED - 02172 
CREATE view [dbo].[MDS20_2010_QI_VR]
as
select 
	selection.A3, selection.AdmitDate, 
	AssessmentType = LU_AA8.DisplayCode, AssessmentType_Desc = LU_AA8.UserDescription,
	selection.CalendarYear, selection.CalendarQuarter, 
	FiscalYear = selection.CalendarYear - (case when selection.CalendarQuarter = 1 then 1 else 0 end),
	FiscalQuarter = (case when selection.CalendarQuarter = 1 then 4 else selection.CalendarQuarter - 1 end),


	H_InstitutionProfile.DisplayCode as InstitutionNumber,  
	H_InstitutionProfile.UserDescription as InstitutionNumberDesc, 
	selection.AbstractID as zzAbstractLink,
	selection.LinkID as zzAssessmentLink,
	Prev_Ax_Flag as zzPrevQuarterAbstractLink,
	
	--Assessment Selection for Prevalence indicators
	PV_QI_Flag, 
	--Assessment Selection for Incidence Indicators
	Inc_QI_Flag, 
	--
	(case when Prev_Ax_Flag > 0 then 1 else 0 end) as Prev_Ax_Flag,
	
	--ADL01 – Percent of residents who had an unexpected loss of function in
	QI_ADL01_D = dbo.MDS20_QI_ADL01(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_G1aA.CIHIValue, LU_G1bA.CIHIValue, LU_G1hA.CIHIValue, LU_G1iA.CIHIValue, LU_Prev_G1aA.CIHIValue, LU_Prev_G1bA.CIHIValue, LU_Prev_G1hA.CIHIValue, LU_Prev_G1iA.CIHIValue),
	QI_ADL01_N = dbo.MDS20_QI_ADL01(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_G1aA.CIHIValue, LU_G1bA.CIHIValue, LU_G1hA.CIHIValue, LU_G1iA.CIHIValue, LU_Prev_G1aA.CIHIValue, LU_Prev_G1bA.CIHIValue, LU_Prev_G1hA.CIHIValue, LU_Prev_G1iA.CIHIValue),
	
	--ADL05 – Percent of residents who improve status on mid-loss ADL functioning (transfer, locomotion) or remain completely independent in mid-loss ADLs
	QI_ADL05_D = dbo.MDS20_QI_ADL05(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_G1bA.CIHIValue, LU_G1dA.CIHIValue, LU_G1eA.CIHIValue, LU_Prev_G1bA.CIHIValue, LU_Prev_G1dA.CIHIValue, LU_Prev_G1eA.CIHIValue),
	QI_ADL05_N = dbo.MDS20_QI_ADL05(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_G1bA.CIHIValue, LU_G1dA.CIHIValue, LU_G1eA.CIHIValue, LU_Prev_G1bA.CIHIValue, LU_Prev_G1dA.CIHIValue, LU_Prev_G1eA.CIHIValue),

    --ADL06 – Percent of residents who improve status on early-loss ADL functioning (dressing and personal hygiene) or remain completely independent in early-loss ADLs
	QI_ADL06_D = dbo.MDS20_QI_ADL06(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_G1gA.CIHIValue, LU_G1jA.CIHIValue, LU_Prev_G1gA.CIHIValue, LU_Prev_G1jA.CIHIValue),
	QI_ADL06_N = dbo.MDS20_QI_ADL06(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_G1gA.CIHIValue, LU_G1jA.CIHIValue, LU_Prev_G1gA.CIHIValue, LU_Prev_G1jA.CIHIValue),

    --ADL1A – Percent of residents who had an improvement of function in some basic daily activities
	QI_ADL1A_D = dbo.MDS20_QI_ADL1A(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_G1aA.CIHIValue, LU_G1bA.CIHIValue, LU_G1hA.CIHIValue, LU_G1iA.CIHIValue, LU_Prev_G1aA.CIHIValue, LU_Prev_G1bA.CIHIValue, LU_Prev_G1hA.CIHIValue, LU_Prev_G1iA.CIHIValue),
	QI_ADL1A_N = dbo.MDS20_QI_ADL1A(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_G1aA.CIHIValue, LU_G1bA.CIHIValue, LU_G1hA.CIHIValue, LU_G1iA.CIHIValue, LU_Prev_G1aA.CIHIValue, LU_Prev_G1bA.CIHIValue, LU_Prev_G1hA.CIHIValue, LU_Prev_G1iA.CIHIValue),

    --ADL5A – Percent of residents who declined status on mid-loss ADL functioning (transfer, locomotion) or remain completely dependent in mid-loss ADLs
	QI_ADL5A_D = dbo.MDS20_QI_ADL5A(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_G1bA.CIHIValue, LU_G1dA.CIHIValue, LU_G1eA.CIHIValue, LU_Prev_G1bA.CIHIValue, LU_Prev_G1dA.CIHIValue, LU_Prev_G1eA.CIHIValue),
	QI_ADL5A_N = dbo.MDS20_QI_ADL5A(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_G1bA.CIHIValue, LU_G1dA.CIHIValue, LU_G1eA.CIHIValue, LU_Prev_G1bA.CIHIValue, LU_Prev_G1dA.CIHIValue, LU_Prev_G1eA.CIHIValue),
    
    --ADL6A – Percent of residents who declined status on early-loss ADL functioning (dressing and personal hygiene) or remain completely dependent in early-loss ADLs)
	QI_ADL6A_D = dbo.MDS20_QI_ADL6A(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_G1gA.CIHIValue, LU_G1jA.CIHIValue, LU_Prev_G1gA.CIHIValue, LU_Prev_G1jA.CIHIValue),
	QI_ADL6A_N = dbo.MDS20_QI_ADL6A(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_G1gA.CIHIValue, LU_G1jA.CIHIValue, LU_Prev_G1gA.CIHIValue, LU_Prev_G1jA.CIHIValue),
    
    --ADLD7 – Percent of residents who have declined in ADLs
	QI_ADLD7_D = dbo.MDS20_QI_ADLD7(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, CRS_OutcomeScale.ADL_Long, Prev_CRS_OutcomeScale.ADL_Long),
	QI_ADLD7_N = dbo.MDS20_QI_ADLD7(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, CRS_OutcomeScale.ADL_Long, Prev_CRS_OutcomeScale.ADL_Long), 

    --BEHD4 – Percent of residents who have declining behavioral symptoms
	QI_BEHD4_D = dbo.MDS20_QI_BEHD4(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_E4aA.CIHIValue, LU_E4bA.CIHIValue, LU_E4cA.CIHIValue, LU_E4dA.CIHIValue, LU_Prev_E4aA.CIHIValue, LU_Prev_E4bA.CIHIValue, LU_Prev_E4cA.CIHIValue, LU_Prev_E4dA.CIHIValue),
	QI_BEHD4_N = dbo.MDS20_QI_BEHD4(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_E4aA.CIHIValue, LU_E4bA.CIHIValue, LU_E4cA.CIHIValue, LU_E4dA.CIHIValue, LU_Prev_E4aA.CIHIValue, LU_Prev_E4bA.CIHIValue, LU_Prev_E4cA.CIHIValue, LU_Prev_E4dA.CIHIValue),

    --BEHI4 – Percent of residents who have improved behavioural symptoms
	QI_BEHI4_D = dbo.MDS20_QI_BEHI4(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_E4aA.CIHIValue, LU_E4bA.CIHIValue, LU_E4cA.CIHIValue, LU_E4dA.CIHIValue, LU_Prev_E4aA.CIHIValue, LU_Prev_E4bA.CIHIValue, LU_Prev_E4cA.CIHIValue, LU_Prev_E4dA.CIHIValue),
	QI_BEHI4_N = dbo.MDS20_QI_BEHI4(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_E4aA.CIHIValue, LU_E4bA.CIHIValue, LU_E4cA.CIHIValue, LU_E4dA.CIHIValue, LU_Prev_E4aA.CIHIValue, LU_Prev_E4bA.CIHIValue, LU_Prev_E4cA.CIHIValue, LU_Prev_E4dA.CIHIValue),
    
    --CAT02 – Percent of residents with indwelling catheters
	QI_CAT02_D = dbo.MDS20_QI_CAT02(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_H3d.CIHIValue),
	QI_CAT02_N = dbo.MDS20_QI_CAT02(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_H3d.CIHIValue),

    --CNT02 – Percent of residents with worsening bowel continence
	QI_CNT02_D = dbo.MDS20_QI_CNT02(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_H1a.CIHIValue, LU_H3i.CIHIValue, LU_Prev_H1a.CIHIValue),
	QI_CNT02_N = dbo.MDS20_QI_CNT02(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_H1a.CIHIValue, LU_H3i.CIHIValue, LU_Prev_H1a.CIHIValue),
    
    --CNT03 – Percent of residents with worsening bladder continence
	QI_CNT03_D = dbo.MDS20_QI_CNT03(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_H1b.CIHIValue, LU_H3i.CIHIValue, LU_Prev_H1b.CIHIValue),
	QI_CNT03_N = dbo.MDS20_QI_CNT03(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_H1b.CIHIValue, LU_H3i.CIHIValue, LU_Prev_H1b.CIHIValue),
    
    --CNT04 – Percent of residents with urinary tract infections
	QI_CNT04_D = dbo.MDS20_QI_CNT04(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_I2k.CIHIValue),
	QI_CNT04_N = dbo.MDS20_QI_CNT04(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_I2k.CIHIValue), 
    
    --CNT2A – Percent of residents with improving bowel continence
	QI_CNT2A_D = dbo.MDS20_QI_CNT2A(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_H1a.CIHIValue, LU_H3i.CIHIValue, LU_Prev_H1a.CIHIValue),
	QI_CNT2A_N = dbo.MDS20_QI_CNT2A(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_H1a.CIHIValue, LU_H3i.CIHIValue, LU_Prev_H1a.CIHIValue),

    --CNT3A – Percent of residents with improving bladder continence
	QI_CNT3A_D = dbo.MDS20_QI_CNT3A(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_H1b.CIHIValue, LU_H3i.CIHIValue, LU_Prev_H1b.CIHIValue),
	QI_CNT3A_N = dbo.MDS20_QI_CNT3A(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_H1b.CIHIValue, LU_H3i.CIHIValue, LU_Prev_H1b.CIHIValue),
        
    --COG01 – Percent of residents whose cognitive ability has worsened
	QI_COG01_D = dbo.MDS20_QI_COG01(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, CRS_OutcomeScale.CPS, Prev_CRS_OutcomeScale.CPS),
	QI_COG01_N = dbo.MDS20_QI_COG01(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, CRS_OutcomeScale.CPS, Prev_CRS_OutcomeScale.CPS),

    --COG1A – Percent of residents whose cognitive ability has improved
	QI_COG1A_D = dbo.MDS20_QI_COG1A(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, CRS_OutcomeScale.CPS, Prev_CRS_OutcomeScale.CPS),
	QI_COG1A_N = dbo.MDS20_QI_COG1A(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, CRS_OutcomeScale.CPS, Prev_CRS_OutcomeScale.CPS),

    --COM01 – Percent of residents whose ability to communicate has worsened
	QI_COM01_D = dbo.MDS20_QI_COM01(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_C4.CIHIValue, LU_C6.CIHIValue, LU_Prev_C4.CIHIValue, LU_Prev_C6.CIHIValue),
	QI_COM01_N = dbo.MDS20_QI_COM01(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_C4.CIHIValue, LU_C6.CIHIValue, LU_Prev_C4.CIHIValue, LU_Prev_C6.CIHIValue),

    --COM1A – Percent of residents whose ability to communicate has improved        
	QI_COM1A_D = dbo.MDS20_QI_COM1A(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_C4.CIHIValue, LU_C6.CIHIValue, LU_Prev_C4.CIHIValue, LU_Prev_C6.CIHIValue),
	QI_COM1A_N = dbo.MDS20_QI_COM1A(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_C4.CIHIValue, LU_C6.CIHIValue, LU_Prev_C4.CIHIValue, LU_Prev_C6.CIHIValue),

    --DEL0X – Percent of residents with symptoms of delirium
	QI_DEL0X_D = dbo.MDS20_QI_DEL0X(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_B5a.CIHIValue, LU_B5b.CIHIValue, LU_B5c.CIHIValue, LU_B5d.CIHIValue, LU_B5e.CIHIValue, LU_B5f.CIHIValue, LU_Prev_B5a.CIHIValue, LU_Prev_B5b.CIHIValue, LU_Prev_B5c.CIHIValue, LU_Prev_B5d.CIHIValue, LU_Prev_B5e.CIHIValue, LU_Prev_B5f.CIHIValue, CRS_OutcomeScale.CPS),
	QI_DEL0X_N = dbo.MDS20_QI_DEL0X(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_B5a.CIHIValue, LU_B5b.CIHIValue, LU_B5c.CIHIValue, LU_B5d.CIHIValue, LU_B5e.CIHIValue, LU_B5f.CIHIValue, LU_Prev_B5a.CIHIValue, LU_Prev_B5b.CIHIValue, LU_Prev_B5c.CIHIValue, LU_Prev_B5d.CIHIValue, LU_Prev_B5e.CIHIValue, LU_Prev_B5f.CIHIValue, CRS_OutcomeScale.CPS),
    
    --DRG01 – Percent of residents on antipsychotics without a diagnosis of psychosis
	QI_DRG01_D = dbo.MDS20_QI_DRG01(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_J1i.CIHIValue, LU_J1e.CIHIValue, CRS_AssessShare4.O4a, LU_I1ii.CIHIValue, LU_I1x.CIHIValue),
	QI_DRG01_N = dbo.MDS20_QI_DRG01(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_J1i.CIHIValue, LU_J1e.CIHIValue, CRS_AssessShare4.O4a, LU_I1ii.CIHIValue, LU_I1x.CIHIValue),
    
    --FAL02 – Percent of residents who have fallen in the last 30 days
	QI_FAL02_D = dbo.MDS20_QI_FAL02(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_J4a.CIHIValue),
	QI_FAL02_N = dbo.MDS20_QI_FAL02(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_J4a.CIHIValue),
	
	--INF0X – Percent of residents with infections
	QI_INF0X_D = dbo.MDS20_QI_INF0X(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_I2f.CIHIValue, LU_I2g.CIHIValue, LU_I2h.CIHIValue, LU_I2k.CIHIValue, LU_I2l.CIHIValue, LU_I2m.CIHIValue, LU_J1h.CIHIValue, LU_J1k.CIHIValue),
	QI_INF0X_N = dbo.MDS20_QI_INF0X(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_I2f.CIHIValue, LU_I2g.CIHIValue, LU_I2h.CIHIValue, LU_I2k.CIHIValue, LU_I2l.CIHIValue, LU_I2m.CIHIValue, LU_J1h.CIHIValue, LU_J1k.CIHIValue),
    
    --MOB01 – Percent of residents who have declined in their ability to locomote
	QI_MOB01_D = dbo.MDS20_QI_MOB01(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_G1eA.CIHIValue, LU_Prev_G1eA.CIHIValue),
	QI_MOB01_N = dbo.MDS20_QI_MOB01(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_G1eA.CIHIValue, LU_Prev_G1eA.CIHIValue),

    --MOB1A – Percent of residents who have improved in their ability to locomote    
	QI_MOB1A_D = dbo.MDS20_QI_MOB1A(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_G1eA.CIHIValue, LU_Prev_G1eA.CIHIValue),
	QI_MOB1A_N = dbo.MDS20_QI_MOB1A(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_G1eA.CIHIValue, LU_Prev_G1eA.CIHIValue),

    --MOD4A – Percent of residents who decline in mood from symptoms of
	QI_MOD4A_D = dbo.MDS20_QI_MOD4A(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, CRS_OutcomeScale.DRS, Prev_CRS_OutcomeScale.DRS),
	QI_MOD4A_N = dbo.MDS20_QI_MOD4A(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, CRS_OutcomeScale.DRS, Prev_CRS_OutcomeScale.DRS),
	
	--NUT01 – Percent of residents with a feeding tube
	QI_NUT01_D = dbo.MDS20_QI_NUT01(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_K5b.CIHIValue),
	QI_NUT01_N = dbo.MDS20_QI_NUT01(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, LU_K5b.CIHIValue),
	
	--PAI0X – Percent of residents with pain
	QI_PAI0X_D = dbo.MDS20_QI_PAI0X(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_J2a.CIHIValue, LU_J2b.CIHIValue, LU_AA8.CIHIValue),
	QI_PAI0X_N = dbo.MDS20_QI_PAI0X(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_J2a.CIHIValue, LU_J2b.CIHIValue, LU_AA8.CIHIValue),
	
	--PAN01 – Percent of residents with worsening pain
	QI_PAN01_D = dbo.MDS20_QI_PAN01(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, CRS_OutcomeScale.Pain, Prev_CRS_OutcomeScale.Pain),
	QI_PAN01_N = dbo.MDS20_QI_PAN01(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, CRS_OutcomeScale.Pain, Prev_CRS_OutcomeScale.Pain),
	
    --PRU05 – Percent of residents who have a pressure ulcer stage 2 to 4
	QI_PRU05_D = dbo.MDS20_QI_PRU05(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_M2a.CIHIValue),
	QI_PRU05_N = dbo.MDS20_QI_PRU05(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_M2a.CIHIValue),

    --PRU06 – Percent of residents with worsening stage 2-4 pressure sores
	QI_PRU06_D = dbo.MDS20_QI_PRU06(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_M2a.CIHIValue, LU_Prev_M2a.CIHIValue),
	QI_PRU06_N = dbo.MDS20_QI_PRU06(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_M2a.CIHIValue, LU_Prev_M2a.CIHIValue),
	
	--PRU09 – Percent of residents with newly occurring pressure ulcer stage 2 to 4
	QI_PRU09_D = dbo.MDS20_QI_PRU09(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_M2a.CIHIValue, LU_Prev_M2a.CIHIValue),
	QI_PRU09_N = dbo.MDS20_QI_PRU09(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_M2a.CIHIValue, LU_Prev_M2a.CIHIValue),

    --RES01 – Percent of residents with daily physical restraints
	QI_RES01_D = dbo.MDS20_QI_RES01(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_I1bb.CIHIValue, LU_P4c.CIHIValue, LU_P4d.CIHIValue, LU_P4e.CIHIValue),
	QI_RES01_N = dbo.MDS20_QI_RES01(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_B1.CIHIValue, LU_I1bb.CIHIValue, LU_P4c.CIHIValue, LU_P4d.CIHIValue, LU_P4e.CIHIValue),
	
	--RSPX2 – Percent of residents who have developed a respiratory infection or have not gotten better
	QI_RSPX2_D = dbo.MDS20_QI_RSPX2(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_I2f.CIHIValue, LU_J1b.CIHIValue, LU_J1l.CIHIValue, LU_J1k.CIHIValue, LU_Prev_I2f.CIHIValue, LU_Prev_J1b.CIHIValue, LU_Prev_J1l.CIHIValue, LU_Prev_J1k.CIHIValue),
	QI_RSPX2_N = dbo.MDS20_QI_RSPX2(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_I2f.CIHIValue, LU_J1b.CIHIValue, LU_J1l.CIHIValue, LU_J1k.CIHIValue, LU_Prev_I2f.CIHIValue, LU_Prev_J1b.CIHIValue, LU_Prev_J1l.CIHIValue, LU_Prev_J1k.CIHIValue),
    
    --WGT01 – Percent of residents who have unexplained weight loss
	QI_WGT01_D = dbo.MDS20_QI_WGT01(1, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, isnull(LU_K3a_472.CIHIValue, LU_K3a_473.CIHIValue), LU_K5h.CIHIValue),
	QI_WGT01_N = dbo.MDS20_QI_WGT01(0, PV_QI_Flag, Inc_QI_Flag, Prev_Ax_Flag, LU_J5c.CIHIValue, LU_P1ao.CIHIValue, isnull(LU_K3a_472.CIHIValue, LU_K3a_473.CIHIValue), LU_K5h.CIHIValue)
    
        
from	
	(select  main.LinkID, main.CalendarYear, main.CalendarQuarter, main.A3, main.AdmitDate, main.AbstractID,
		PV_QI_Flag = (case when datediff(day, AdmitDate, A3) >= 93 then 1 else 0 end), 
		--cc_IP_Flag = (case when datediff(day, AdmitDate, A3) <= 92 and Reentry.LinkID is null then 1 else 0 end), 
		
		Inc_QI_Flag = (case when dbo.MDS20_QI_GetPreviousID(main.LinkID, main.CalendarYear, main.CalendarQuarter, main.A3, main.AdmitDate) > 0
		                        and datediff(day, AdmitDate, A3) >= 93
							then 1
							else 0
					   end),
		--T_Has_Prev_Ax = (select top 1 AbstractID from CRS_Demographic p 
		--					where main.LinkID = p.LinkID 
		--						and datepart(year, p.A3) = (case when main.CalendarQuarter = 1 then main.CalendarYear - 1 else main.CalendarYear end)
		--						and datepart(quarter, p.A3) = (case when main.CalendarQuarter = 1 then 4 else main.CalendarQuarter - 1 end)
		--						and p.AA8 in (14502, 14503, 14504, 14505, 14506, 14511)
		--					order by AbstractID desc),
		Prev_Ax_Flag = dbo.MDS20_QI_GetPreviousID(main.LinkID, main.CalendarYear, main.CalendarQuarter, main.A3, main.AdmitDate)
							
	from 
	(
		select d.LinkID, aa.CalendarYear, aa.CalendarQuarter, d.A3, a.AdmitDate, max(d.AbstractID) as AbstractID 
		from CRS_Demographic d with (nolock)
			inner join
			(select LinkID, Datepart(Year, A3) as CalendarYear, 
				Datepart(Quarter, A3) as CalendarQuarter, max(A3) as maxA3
			from CRS_Demographic with (nolock)
			where A3 is not null and IsDeleted = 2 and AA8 in (14503, 14504, 14505, 14506, 14511)
			group by LinkID, Datepart(Year, A3), Datepart(Quarter, A3)
			) aa on d.LinkID = aa.LinkID and d.A3 = aa.maxA3
			inner join CRS_Demographic a on d.LinkID = a.AbstractID
		where d.IsDeleted = 2 and d.AA8 in (14503, 14504, 14505, 14506, 14511)
		group by d.LinkID, aa.CalendarYear, aa.CalendarQuarter, d.A3, a.AdmitDate
	) main
	) selection
	inner join CRS_Demographic with (nolock) on selection.AbstractID = CRS_Demographic.AbstractID
	inner join LU_CodeFile LU_AA8 with (nolock) on CRS_Demographic.AA8 = LU_AA8.Code
	inner join H_InstitutionProfile with (nolock) on CRS_Demographic.InstitutionNumber = H_InstitutionProfile.Code
	
	left join CRS_AssessShare1 with (nolock) on CRS_AssessShare1.AbstractID = CRS_Demographic.AbstractID
	left join LU_YesNoSystem LU_B1 with (nolock) on CRS_AssessShare1.B1 = LU_B1.Code
	left join LU_CodeFile LU_B2a with (nolock) on CRS_AssessShare1.B2a = LU_B2a.Code

	left join LU_CodeFile LU_B5a with (nolock) on CRS_AssessShare1.B5a = LU_B5a.Code
	left join LU_CodeFile LU_B5b with (nolock) on CRS_AssessShare1.B5b = LU_B5b.Code
	left join LU_CodeFile LU_B5c with (nolock) on CRS_AssessShare1.B5c = LU_B5c.Code
	left join LU_CodeFile LU_B5d with (nolock) on CRS_AssessShare1.B5d = LU_B5d.Code
	left join LU_CodeFile LU_B5e with (nolock) on CRS_AssessShare1.B5e = LU_B5e.Code
	left join LU_CodeFile LU_B5f with (nolock) on CRS_AssessShare1.B5f = LU_B5f.Code


	left join LU_CodeFile LU_C4 with (nolock) on CRS_AssessShare1.C4 = LU_C4.Code
	left join LU_CodeFile LU_C6 with (nolock) on CRS_AssessShare1.C6 = LU_C6.Code
	
	left join LU_CodeFile LU_E4aA with (nolock) on CRS_AssessShare1.E4aA = LU_E4aA.Code
	left join LU_CodeFile LU_E4bA with (nolock) on CRS_AssessShare1.E4bA = LU_E4bA.Code
	left join LU_CodeFile LU_E4cA with (nolock) on CRS_AssessShare1.E4cA = LU_E4cA.Code
	left join LU_CodeFile LU_E4dA with (nolock) on CRS_AssessShare1.E4dA = LU_E4dA.Code

	left join CRS_AssessShare2 with (nolock) on CRS_AssessShare2.ABstractID = CRS_Demographic.AbstractID

	left join LU_CodeFile LU_G1aA with (nolock) on CRS_AssessShare2.G1aA = LU_G1aA.Code
	left join LU_CodeFile LU_G1bA with (nolock) on CRS_AssessShare2.G1bA = LU_G1bA.Code
	left join LU_CodeFile LU_G1dA with (nolock) on CRS_AssessShare2.G1dA = LU_G1dA.Code
	left join LU_CodeFile LU_G1eA with (nolock) on CRS_AssessShare2.G1eA = LU_G1eA.Code
	left join LU_CodeFile LU_G1gA with (nolock) on CRS_AssessShare2.G1gA = LU_G1gA.Code
	left join LU_CodeFile LU_G1hA with (nolock) on CRS_AssessShare2.G1hA = LU_G1hA.Code
	left join LU_CodeFile LU_G1iA with (nolock) on CRS_AssessShare2.G1iA = LU_G1iA.Code
	left join LU_CodeFile LU_G1jA with (nolock) on CRS_AssessShare2.G1jA = LU_G1jA.Code
	
	left join LU_CodeFile LU_H1a with (nolock) on CRS_AssessShare2.H1a = LU_H1a.Code
	left join LU_CodeFile LU_H1b with (nolock) on CRS_AssessShare2.H1b = LU_H1b.Code

	left join LU_YesNoSystem LU_H3d with (nolock) on CRS_AssessShare2.H3d = LU_H3d.Code
	left join LU_YesNoSystem LU_H3i with (nolock) on CRS_AssessShare2.H3i = LU_H3i.Code

	left join CRS_AssessShare3 with (nolock) on CRS_AssessShare3.ABstractID = CRS_Demographic.AbstractID
	left join LU_YesNoSystem LU_I1x with (nolock) on CRS_AssessShare3.I1x = LU_I1x.Code

	left join LU_YesNoSystem LU_I1bb with (nolock) on CRS_AssessShare3.I1bb = LU_I1bb.Code
	left join LU_YesNoSystem LU_I1ii with (nolock) on CRS_AssessShare3.I1ii = LU_I1ii.Code

	left join LU_YesNoSystem LU_I2f with (nolock) on CRS_AssessShare3.I2f = LU_I2f.Code
	left join LU_YesNoSystem LU_I2g with (nolock) on CRS_AssessShare3.I2g = LU_I2g.Code
	left join LU_YesNoSystem LU_I2h with (nolock) on CRS_AssessShare3.I2h = LU_I2h.Code
	left join LU_YesNoSystem LU_I2k with (nolock) on CRS_AssessShare3.I2k = LU_I2k.Code
	left join LU_YesNoSystem LU_I2l with (nolock) on CRS_AssessShare3.I2l = LU_I2l.Code
	left join LU_YesNoSystem LU_I2m with (nolock) on CRS_AssessShare3.I2m = LU_I2m.Code
	
	left join LU_YesNoSystem LU_J1b with (nolock) on CRS_AssessShare3.J1h = LU_J1b.code

	left join LU_YesNoSystem LU_J1h with (nolock) on CRS_AssessShare3.J1h = LU_J1h.code
	left join LU_YesNoSystem LU_J1e with (nolock) on CRS_AssessShare3.J1e = LU_J1e.code
	left join LU_YesNoSystem LU_J1i with (nolock) on CRS_AssessShare3.J1i = LU_J1i.code
	left join LU_YesNoSystem LU_J1l with (nolock) on CRS_AssessShare3.J1l = LU_J1l.code
	left join LU_YesNoSystem LU_J1k with (nolock) on CRS_AssessShare3.J1k = LU_J1k.code

	left join LU_CodeFile LU_J2a with (nolock) on CRS_AssessShare3.J2a = LU_J2a.code
	left join LU_CodeFile LU_J2b with (nolock) on CRS_AssessShare3.J2b = LU_J2b.code

	left join LU_YesNoSystem LU_J4a with (nolock) on CRS_AssessShare3.J4a = LU_J4a.code

	left join LU_YesNoSystem LU_J5c with (nolock) on CRS_AssessShare3.J5c = LU_J5c.code

	left join CRS_AssessShare4 with (nolock) on CRS_AssessShare4.ABstractID = CRS_Demographic.AbstractID
	left join LU_YesNoSystem LU_K3a_472 with (nolock) on CRS_AssessShare4.K3a = LU_K3a_472.code
	left join LU_CodeFile LU_K3a_473 with (nolock) on CRS_AssessShare4.K3a = LU_K3a_473.code

	left join LU_YesNoSystem LU_K5b with (nolock) on CRS_AssessShare4.K5b = LU_K5b.code
	left join LU_YesNoSystem LU_K5h with (nolock) on CRS_AssessShare4.K5h = LU_K5h.code
	left join LU_CodeFile LU_M2a with (nolock) on CRS_AssessShare4.M2a = LU_M2a.code
	
	left join CRS_AssessShare5 with (nolock) on CRS_AssessShare5.ABstractID = CRS_Demographic.AbstractID
	left join LU_YesNoSystem LU_P1ao with (nolock) on CRS_AssessShare5.P1ao = LU_P1ao.code
	left join LU_CodeFile LU_P4c with (nolock) on CRS_AssessShare5.P4c = LU_P4c.code
	left join LU_CodeFile LU_P4d with (nolock) on CRS_AssessShare5.P4d = LU_P4d.code
	left join LU_CodeFile LU_P4e with (nolock) on CRS_AssessShare5.P4e = LU_P4e.code

    left join CRS_OutcomeScale with (nolock) on CRS_OutcomeScale.AbstractID = CRS_Demographic.AbstractID

	
--Previous Quarter
	left join CRS_AssessShare1 prev_CRS_AssessShare1 with (nolock) on selection.Prev_Ax_Flag = prev_CRS_AssessShare1.AbstractID

	left join LU_CodeFile LU_Prev_B5a with (nolock) on prev_CRS_AssessShare1.B5a = LU_Prev_B5a.Code
	left join LU_CodeFile LU_Prev_B5b with (nolock) on prev_CRS_AssessShare1.B5b = LU_Prev_B5b.Code
	left join LU_CodeFile LU_Prev_B5c with (nolock) on prev_CRS_AssessShare1.B5c = LU_Prev_B5c.Code
	left join LU_CodeFile LU_Prev_B5d with (nolock) on prev_CRS_AssessShare1.B5d = LU_Prev_B5d.Code
	left join LU_CodeFile LU_Prev_B5e with (nolock) on prev_CRS_AssessShare1.B5e = LU_Prev_B5e.Code
	left join LU_CodeFile LU_Prev_B5f with (nolock) on prev_CRS_AssessShare1.B5f = LU_Prev_B5f.Code

	left join LU_CodeFile LU_Prev_C4 with (nolock) on prev_CRS_AssessShare1.C4 = LU_Prev_C4.Code
	left join LU_CodeFile LU_Prev_C6 with (nolock) on prev_CRS_AssessShare1.C6 = LU_Prev_C6.Code

	left join LU_CodeFile LU_Prev_E4aA with (nolock) on prev_CRS_AssessShare1.E4aA = LU_Prev_E4aA.Code
	left join LU_CodeFile LU_Prev_E4bA with (nolock) on prev_CRS_AssessShare1.E4bA = LU_Prev_E4bA.Code
	left join LU_CodeFile LU_Prev_E4cA with (nolock) on prev_CRS_AssessShare1.E4cA = LU_Prev_E4cA.Code
	left join LU_CodeFile LU_Prev_E4dA with (nolock) on prev_CRS_AssessShare1.E4dA = LU_Prev_E4dA.Code


	left join CRS_AssessShare2 prev_CRS_AssessShare2 with (nolock) on selection.Prev_Ax_Flag = prev_CRS_AssessShare2.AbstractID
	left join LU_CodeFile LU_Prev_G1aA with (nolock) on prev_CRS_AssessShare2.G1aA = LU_Prev_G1aA.Code
	left join LU_CodeFile LU_Prev_G1bA with (nolock) on prev_CRS_AssessShare2.G1bA = LU_Prev_G1bA.Code
	left join LU_CodeFile LU_Prev_G1dA with (nolock) on prev_CRS_AssessShare2.G1dA = LU_Prev_G1dA.Code    
	left join LU_CodeFile LU_Prev_G1eA with (nolock) on prev_CRS_AssessShare2.G1eA = LU_Prev_G1eA.Code    
	left join LU_CodeFile LU_Prev_G1fA with (nolock) on prev_CRS_AssessShare2.G1fA = LU_Prev_G1fA.Code    
	left join LU_CodeFile LU_Prev_G1gA with (nolock) on prev_CRS_AssessShare2.G1gA = LU_Prev_G1gA.Code    
	left join LU_CodeFile LU_Prev_G1hA with (nolock) on prev_CRS_AssessShare2.G1hA = LU_Prev_G1hA.Code
	left join LU_CodeFile LU_Prev_G1iA with (nolock) on prev_CRS_AssessShare2.G1iA = LU_Prev_G1iA.Code
	left join LU_CodeFile LU_Prev_G1jA with (nolock) on prev_CRS_AssessShare2.G1jA = LU_Prev_G1jA.Code    

	left join LU_CodeFile LU_Prev_H1a with (nolock) on Prev_CRS_AssessShare2.H1a = LU_Prev_H1a.Code
	left join LU_CodeFile LU_Prev_H1b with (nolock) on Prev_CRS_AssessShare2.H1b = LU_Prev_H1b.Code


	left join CRS_AssessShare3 prev_CRS_AssessShare3 with (nolock) on selection.Prev_Ax_Flag = prev_CRS_AssessShare3.AbstractID
	left join LU_YesNoSystem LU_Prev_I2f with (nolock) on prev_CRS_AssessShare3.I2f = LU_Prev_I2f.Code 
	left join LU_YesNoSystem LU_Prev_J1b with (nolock) on prev_CRS_AssessShare3.J1b = LU_Prev_J1b.Code 
	left join LU_YesNoSystem LU_Prev_J1l with (nolock) on prev_CRS_AssessShare3.J1l = LU_Prev_J1l.Code 
	left join LU_YesNoSystem LU_Prev_J1k with (nolock) on prev_CRS_AssessShare3.J1k = LU_Prev_J1k.Code 

	left join CRS_AssessShare4 prev_CRS_AssessShare4 with (nolock) on selection.Prev_Ax_Flag = prev_CRS_AssessShare4.AbstractID
	left join LU_CodeFile LU_Prev_M2a with (nolock) on prev_CRS_AssessShare4.M2a = LU_Prev_M2a.code

    left join CRS_OutcomeScale Prev_CRS_OutcomeScale with (nolock) on Prev_CRS_OutcomeScale.AbstractID = selection.Prev_Ax_Flag



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Admission_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE  VIEW [dbo].[MDS20_Admission_VR]
AS
SELECT     LU_AB3.DisplayCode AS LivedAlone_AB3, LU_AB3.UserDescription AS LivedAloneDesc_AB3, dbo.CRS_Admission.AB4 AS PostalCode_AB4,
--                           (SELECT     TOP 1 UserDescription
--                             FROM          LU_PostalCode
--                             WHERE      InterfaceIn = AB4) AS PostalCodeDesc_AB4,
 
	-- ED - 01682
	dbo.GetPostalDescription(isnull(dbo.CRS_Admission.AB4, ''''), getdate()) AS PostalCodeDesc_AB4, -- ED - 01682

	LU_AB5ALL.DisplayCode AS ResidentialHistory_None_AB5f, LU_AB5ALL.UserDescription AS ResidentialHistory_N_Desc_AB5f, 
	LU_AB5a.DisplayCode AS ResidentialHistory_This_AB5a, LU_AB5a.UserDescription AS ResidentialHistory_T_Desc_AB5a, 
	LU_AB5b.DisplayCode AS ResidentialHistorySimilar_AB5b, LU_AB5b.UserDescription AS ResidentialHistory_S_Desc_AB5b, 
	LU_AB5c.DisplayCode AS ResidentialHistory_Other_AB5c, LU_AB5c.UserDescription AS ResidentialHistory_O_Desc_AB5c, 
	LU_AB5d.DisplayCode AS ResidentialHistory_Psych_AB5d, LU_AB5d.UserDescription AS ResidentialHistory_P_Desc_AB5d, 
	LU_AB5e.DisplayCode AS ResidentialHistory_Dev_AB5e, LU_AB5e.UserDescription AS ResidentialHistoryDevDesc_AB5e, 
    LU_ResidenceCode.DisplayCode AS ResidenceCode, LU_ResidenceCode.UserDescription AS ResidenceCodeDesc, 
	LU_AB7.DisplayCode AS Education_AB7, LU_AB7.UserDescription AS EducationDesc_AB7, 
	LU_AB8.DisplayCode AS Language_AB8, LU_AB8.UserDescription AS LanguageDesc_AB8, 
	LU_AB9.DisplayCode AS MentalHealthHistory_AB9, LU_AB9.UserDescription AS MentalHealthHistoryDesc_AB9, 
	LU_AB10a.DisplayCode AS ConditionNA_AB10a, LU_AB10a.UserDescription AS ConditionNADesc_AB10a, 
	LU_AB10b.DisplayCode AS ConditionDwons_AB10b, LU_AB10b.UserDescription AS ConditionDwonsDesc_AB10b, 
	LU_AB10c.DisplayCode AS ConditionAutism_AB10c, LU_AB10c.UserDescription AS ConditionAutismDesc_AB10c, 
	LU_AB10d.DisplayCode AS ConditionEpilepsy_AB10d, LU_AB10d.UserDescription AS ConditionEpilepsyDesc_AB10d, 
	LU_AB10e.DisplayCode AS ConditionOther_AB10e, LU_AB10e.UserDescription AS ConditionOtherDesc_AB10e, 
	LU_AB10f.DisplayCode AS ConditionDev_AB10f, LU_AB10f.UserDescription AS ConditionDevDesc_AB10f, 
	LU_AB10All.DisplayCode AS ConditionNone_AB10g, LU_AB10All.UserDescription AS ConditionNoneDesc_AB10g, 
	LU_AC1a.DisplayCode AS DailyEventLate_AC1a, LU_AC1a.UserDescription AS DailyEventLateDesc_AC1a, 
	LU_AC1b.DisplayCode AS DailyEventNap_AC1b, LU_AC1b.UserDescription AS DailyEventNapDesc_AC1b, 
	LU_AC1c.DisplayCode AS DailyEventGoOut_AC1c, LU_AC1c.UserDescription AS DailyEventGoOutDesc_AC1c, 
	LU_AC1d.DisplayCode AS DailyEventBusy_AC1d, LU_AC1d.UserDescription AS DailyEventBusyDesc_AC1d, 
	LU_AC1e.DisplayCode AS DailyEventAlone_AC1e, LU_AC1e.UserDescription AS DailyEventAloneDesc_AC1e, 
	LU_AC1f.DisplayCode AS DailyEventIndoor_AC1f, LU_AC1f.UserDescription AS DailyEventIndoorDesc_AC1f, 
	LU_AC1g.DisplayCode AS DailyEventSmokes_AC1g, LU_AC1g.UserDescription AS DailyEventSmokesDesc_AC1g, 
	LU_AC1i.DisplayCode AS EatingDistinct_AC1i, LU_AC1i.UserDescription AS EatingDistinctDesc_AC1i, 
	LU_AC1j.DisplayCode AS EatingBetween_AC1j,  LU_AC1j.UserDescription AS EatingBetweenDesc_AC1j, 
	LU_AC1k.DisplayCode AS EatingWAlcoholicBev_AC1k, LU_AC1k.UserDescription AS EatingWAlcoholicBevDesc_AC1k, 
	LU_AC1m.DisplayCode AS ADL_InBedClothes_AC1m, LU_AC1m.UserDescription AS ADL_InBedClothesDesc_AC1m, 
	LU_AC1n.DisplayCode AS ADL_WakensToilet_AC1n, LU_AC1n.UserDescription AS ADL_WakensToiletDesc_AC1n, 
	LU_AC1o.DisplayCode AS ADL_IrregularBM_AC1o,  LU_AC1o.UserDescription AS ADL_IrregularBMDesc_AC1o, 
	LU_AC1p.DisplayCode AS ADL_Shower_AC1p, LU_AC1p.UserDescription AS ADL_ShowerDesc_AC1p, 
	LU_AC1q.DisplayCode AS ADL_BathPM_AC1q, LU_AC1q.UserDescription AS ADL_BathPMDesc_AC1q, 
	LU_AC1s.DisplayCode AS InvolveContact_AC1s, LU_AC1s.UserDescription AS InvolveContactDesc_AC1s, 
	LU_AC1t.DisplayCode AS InvolveAttend_AC1t, LU_AC1t.UserDescription AS InvolveAttendDesc_AC1t, 
	LU_AC1u.DisplayCode AS InvolveFaith_AC1u,  LU_AC1u.UserDescription AS InvolveFaithDesc_AC1u, 
	LU_AC1v.DisplayCode AS InvolveAnimal_AC1v, LU_AC1v.UserDescription AS InvolveAnimalDesc_AC1v, 
	LU_AC1w.DisplayCode AS InvolveGroup_AC1w,  LU_AC1w.UserDescription AS InvolveGroupDesc_AC1w, 
	dbo.CRS_Admission.AbstractID AS zzAbstractLink
FROM         dbo.CRS_Admission with (nolock) LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1w with (nolock) on dbo.CRS_Admission.AC1w = LU_AC1w.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1v with (nolock) on dbo.CRS_Admission.AC1v = LU_AC1v.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1u with (nolock) on dbo.CRS_Admission.AC1u = LU_AC1u.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1t with (nolock) on dbo.CRS_Admission.AC1t = LU_AC1t.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1s with (nolock) on dbo.CRS_Admission.AC1s = LU_AC1s.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1q with (nolock) on dbo.CRS_Admission.AC1q = LU_AC1q.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1p with (nolock) on dbo.CRS_Admission.AC1p = LU_AC1p.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1o with (nolock) on dbo.CRS_Admission.AC1o = LU_AC1o.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1n with (nolock) on dbo.CRS_Admission.AC1n = LU_AC1n.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1m with (nolock) on dbo.CRS_Admission.AC1m = LU_AC1m.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1k with (nolock) on dbo.CRS_Admission.AC1k = LU_AC1k.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1j with (nolock) on dbo.CRS_Admission.AC1j = LU_AC1j.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1i with (nolock) on dbo.CRS_Admission.AC1I = LU_AC1i.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1g with (nolock) on dbo.CRS_Admission.AC1g = LU_AC1g.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1f with (nolock) on dbo.CRS_Admission.AC1f = LU_AC1f.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1e with (nolock) on dbo.CRS_Admission.AC1e = LU_AC1e.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1d with (nolock) on dbo.CRS_Admission.AC1d = LU_AC1d.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1b with (nolock) on dbo.CRS_Admission.AC1b = LU_AC1b.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1a with (nolock) on dbo.CRS_Admission.AC1a = LU_AC1a.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AB10f with (nolock) on dbo.CRS_Admission.AB10f = LU_AB10f.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AB10e with (nolock) on dbo.CRS_Admission.AB10e = LU_AB10e.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AB10d with (nolock) on dbo.CRS_Admission.AB10d = LU_AB10d.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AB10c with (nolock) on dbo.CRS_Admission.AB10c = LU_AB10c.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AB10b with (nolock) on dbo.CRS_Admission.AB10b = LU_AB10b.Code LEFT OUTER JOIN
                      dbo.LU_YesNoSystem LU_AB10a with (nolock) on dbo.CRS_Admission.AB10a = LU_AB10a.Code LEFT OUTER JOIN
                      dbo.LU_YesNoSystem LU_AB10All with (nolock) on dbo.CRS_Admission.AB10All = LU_AB10All.Code LEFT OUTER JOIN
                      dbo.LU_YesNoSystem LU_AB9 with (nolock) on dbo.CRS_Admission.AB9 = LU_AB9.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AB3 with (nolock) on dbo.CRS_Admission.AB3 = LU_AB3.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AB8 with (nolock) on dbo.CRS_Admission.AB8 = LU_AB8.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AB5e with (nolock) on dbo.CRS_Admission.AB5e = LU_AB5e.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AB5c with (nolock) on dbo.CRS_Admission.AB5c = LU_AB5c.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AB5a with (nolock) on dbo.CRS_Admission.AB5a = LU_AB5a.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AB5ALL with (nolock) on dbo.CRS_Admission.AB5All = LU_AB5ALL.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AB5b with (nolock) on dbo.CRS_Admission.AB5b = LU_AB5b.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AB5d with (nolock) on dbo.CRS_Admission.AB5d = LU_AB5d.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AB7 with (nolock) on dbo.CRS_Admission.AB7 = LU_AB7.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1c with (nolock) on dbo.CRS_Admission.AC1c = LU_AC1c.Code LEFT OUTER JOIN
                      dbo.LU_ResidenceCode with (nolock) on dbo.CRS_Admission.ResidenceCode = LU_ResidenceCode.Code 


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_BasicOption_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE view [dbo].[MDS20_BasicOption_VR]
as
select
    BasicOption1  = dbo.lu_BasicOption1.DisplayCode,  BasicOption1Desc  = dbo.lu_BasicOption1.UserDescription,
    BasicOption2  = dbo.lu_BasicOption2.DisplayCode,  BasicOption2Desc  = dbo.lu_BasicOption2.UserDescription,
    BasicOption3  = dbo.lu_BasicOption3.DisplayCode,  BasicOption3Desc  = dbo.lu_BasicOption3.UserDescription,
    BasicOption4  = dbo.lu_BasicOption4.DisplayCode,  BasicOption4Desc  = dbo.lu_BasicOption4.UserDescription,
    BasicOption5  = dbo.lu_BasicOption5.DisplayCode,  BasicOption5Desc  = dbo.lu_BasicOption5.UserDescription,
    BasicOption6  = dbo.lu_BasicOption6.DisplayCode,  BasicOption6Desc  = dbo.lu_BasicOption6.UserDescription,
    BasicOption7  = dbo.lu_BasicOption7.DisplayCode,  BasicOption7Desc  = dbo.lu_BasicOption7.UserDescription,
    BasicOption8  = dbo.lu_BasicOption8.DisplayCode,  BasicOption8Desc  = dbo.lu_BasicOption8.UserDescription,
    BasicOption9  = dbo.lu_BasicOption9.DisplayCode,  BasicOption9Desc  = dbo.lu_BasicOption9.UserDescription,
    BasicOption10 = dbo.lu_BasicOption10.DisplayCode, BasicOption10Desc = dbo.lu_BasicOption10.UserDescription,
    BasicOption11 = dbo.lu_BasicOption11.DisplayCode, BasicOption11Desc = dbo.lu_BasicOption11.UserDescription,
    BasicOption12 = dbo.lu_BasicOption12.DisplayCode, BasicOption12Desc = dbo.lu_BasicOption12.UserDescription,
    BasicOption13 = dbo.lu_BasicOption13.DisplayCode, BasicOption13Desc = dbo.lu_BasicOption13.UserDescription,
    BasicOption14 = dbo.lu_BasicOption14.DisplayCode, BasicOption14Desc = dbo.lu_BasicOption14.UserDescription,
    BasicOption15 = dbo.lu_BasicOption15.DisplayCode, BasicOption15Desc = dbo.lu_BasicOption15.UserDescription,
    BasicOption16 = dbo.lu_BasicOption16.DisplayCode, BasicOption16Desc = dbo.lu_BasicOption16.UserDescription,
    BasicOption17 = dbo.lu_BasicOption17.DisplayCode, BasicOption17Desc = dbo.lu_BasicOption17.UserDescription,
    BasicOption18 = dbo.lu_BasicOption18.DisplayCode, BasicOption18Desc = dbo.lu_BasicOption18.UserDescription,
    BasicOption19 = dbo.lu_BasicOption19.DisplayCode, BasicOption19Desc = dbo.lu_BasicOption19.UserDescription,
    dbo.CRS_BasicOption.AbstractID as zzAbstractLink
from dbo.CRS_BasicOption with (nolock) 
    left join dbo.lu_BasicOption1  with (nolock) on dbo.CRS_BasicOption.BasicOption1  =  dbo.lu_BasicOption1.Code
    left join dbo.lu_BasicOption2  with (nolock) on dbo.CRS_BasicOption.BasicOption2  =  dbo.lu_BasicOption2.Code
    left join dbo.lu_BasicOption3  with (nolock) on dbo.CRS_BasicOption.BasicOption3  =  dbo.lu_BasicOption3.Code
    left join dbo.lu_BasicOption4  with (nolock) on dbo.CRS_BasicOption.BasicOption4  =  dbo.lu_BasicOption4.Code
    left join dbo.lu_BasicOption5  with (nolock) on dbo.CRS_BasicOption.BasicOption5  =  dbo.lu_BasicOption5.Code
    left join dbo.lu_BasicOption6  with (nolock) on dbo.CRS_BasicOption.BasicOption6  =  dbo.lu_BasicOption6.Code
    left join dbo.lu_BasicOption7  with (nolock) on dbo.CRS_BasicOption.BasicOption7  =  dbo.lu_BasicOption7.Code
    left join dbo.lu_BasicOption8  with (nolock) on dbo.CRS_BasicOption.BasicOption8  =  dbo.lu_BasicOption8.Code
    left join dbo.lu_BasicOption9  with (nolock) on dbo.CRS_BasicOption.BasicOption9  =  dbo.lu_BasicOption9.Code
    left join dbo.lu_BasicOption10 with (nolock) on dbo.CRS_BasicOption.BasicOption10 =  dbo.lu_BasicOption10.Code
    left join dbo.lu_BasicOption11 with (nolock) on dbo.CRS_BasicOption.BasicOption11 =  dbo.lu_BasicOption11.Code
    left join dbo.lu_BasicOption12 with (nolock) on dbo.CRS_BasicOption.BasicOption12 =  dbo.lu_BasicOption12.Code
    left join dbo.lu_BasicOption13 with (nolock) on dbo.CRS_BasicOption.BasicOption13 =  dbo.lu_BasicOption13.Code
    left join dbo.lu_BasicOption14 with (nolock) on dbo.CRS_BasicOption.BasicOption14 =  dbo.lu_BasicOption14.Code
    left join dbo.lu_BasicOption15 with (nolock) on dbo.CRS_BasicOption.BasicOption15 =  dbo.lu_BasicOption15.Code
    left join dbo.lu_BasicOption16 with (nolock) on dbo.CRS_BasicOption.BasicOption16 =  dbo.lu_BasicOption16.Code
    left join dbo.lu_BasicOption17 with (nolock) on dbo.CRS_BasicOption.BasicOption17 =  dbo.lu_BasicOption17.Code
    left join dbo.lu_BasicOption18 with (nolock) on dbo.CRS_BasicOption.BasicOption18 =  dbo.lu_BasicOption18.Code
    left join dbo.lu_BasicOption19 with (nolock) on dbo.CRS_BasicOption.BasicOption19 =  dbo.lu_BasicOption19.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_CAP_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE view [dbo].[MDS20_CAP_VR]
as
select
    CAP_ActivitiesDailyLiving = LU_CAP_ActivitiesDailyLiving.DisplayCode, CAP_ActivitiesDailyLivingDesc = LU_CAP_ActivitiesDailyLiving.UserDescription,
    CAP_PhysicalRestraints = LU_CAP_PhysicalRestraints.DisplayCode, CAP_PhysicalRestraintsDesc = LU_CAP_PhysicalRestraints.UserDescription,
    CAP_CognitiveLoss = LU_CAP_CognitiveLoss.DisplayCode, CAP_CognitiveLossDesc = LU_CAP_CognitiveLoss.UserDescription,
    CAP_Delirium = LU_CAP_Delirium.DisplayCode, CAP_DeliriumDesc = LU_CAP_Delirium.UserDescription,
    CAP_Communication = LU_CAP_Communication.DisplayCode, CAP_CommunicationDesc = LU_CAP_Communication.UserDescription,
    CAP_Mood = LU_CAP_Mood.DisplayCode, CAP_MoodDesc = LU_CAP_Mood.UserDescription,
    CAP_Behaviour = LU_CAP_Behaviour.DisplayCode, CAP_BehaviourDesc = LU_CAP_Behaviour.UserDescription,
    CAP_Activities = LU_CAP_Activities.DisplayCode, CAP_ActivitiesDesc = LU_CAP_Activities.UserDescription,
    CAP_SocialRelationship = LU_CAP_SocialRelationship.DisplayCode, CAP_SocialRelationshipDesc = LU_CAP_SocialRelationship.UserDescription,
    CAP_Falls = LU_CAP_Falls.DisplayCode, CAP_FallsDesc = LU_CAP_Falls.UserDescription,
    CAP_Pain = LU_CAP_Pain.DisplayCode, CAP_PainDesc = LU_CAP_Pain.UserDescription,
    CAP_PressureUlcers = LU_CAP_PressureUlcers.DisplayCode, CAP_PressureUlcersDesc = LU_CAP_PressureUlcers.UserDescription,
    CAP_CardioRespiratoryConditions = LU_CAP_CardioRespiratoryConditions.DisplayCode, CAP_CardioRespiratoryConditionsDesc = LU_CAP_CardioRespiratoryConditions.UserDescription,
    CAP_UnderNutrition = LU_CAP_UnderNutrition.DisplayCode, CAP_UnderNutritionDesc = LU_CAP_UnderNutrition.UserDescription,
    CAP_Dehydration = LU_CAP_Dehydration.DisplayCode, CAP_DehydrationDesc = LU_CAP_Dehydration.UserDescription,
    CAP_FeedingTube = LU_CAP_FeedingTube.DisplayCode, CAP_FeedingTubeDesc = LU_CAP_FeedingTube.UserDescription,
    CAP_AppropriateMedications = LU_CAP_AppropriateMedications.DisplayCode, CAP_AppropriateMedicationsDesc = LU_CAP_AppropriateMedications.UserDescription,
    CAP_UrinaryIncontinence = LU_CAP_UrinaryIncontinence.DisplayCode, CAP_UrinaryIncontinenceDesc = LU_CAP_UrinaryIncontinence.UserDescription,
    CAP_BowelConditions = LU_CAP_BowelConditions.DisplayCode, CAP_BowelConditionsDesc = LU_CAP_BowelConditions.UserDescription,

    dbo.CRS_Demographic.A3 AS AssessmentDate_A3, 
    dbo.CRS_Demographic.ChartNumber AS HealthRecordNumber_A6a,
    dbo.CRS_Demographic.AA1 AS URI_AA1, 
    dbo.H_InstitutionProfile.DisplayCode AS FacilityNumber_AA6, dbo.H_InstitutionProfile.UserDescription AS FacilityNumberDesc_AA6, 
    LU_AA8.DisplayCode AS ReasonAssessment_AA8, LU_AA8.CIHIValue AS AA8_CIHI, LU_AA8.UserDescription AS ReasonAssessmentDesc_AA8, 
    dbo.CRS_Demographic.AdmitDate AS AdmissionDate_AB1, 

    LU_B1.DisplayCode AS Comatose_B1,               LU_B1.UserDescription AS ComatoseDesc_B1, 
    LU_B4.DisplayCode AS CognitiveSkills_B4,        LU_B4.UserDescription AS CognitiveSkillsDesc_B4, 

    LU_B5a.DisplayCode AS DisorderEasily_B5a,       LU_B5a.UserDescription AS DisorderEasilyDesc_B5a, 
    LU_B5b.DisplayCode AS DisorderPerception_B5b,   LU_B5b.UserDescription AS DisorderPerceptionDesc_B5b, 
    LU_B5c.DisplayCode AS DisorderSpeech_B5c,       LU_B5c.UserDescription AS DisorderSpeechDesc_B5c, 
    LU_B5d.DisplayCode AS DisorderRestless_B5d,     LU_B5d.UserDescription AS DisorderRestlessDesc_B5d, 
    LU_B5e.DisplayCode AS DisorderLethargy_B5e,     LU_B5e.UserDescription AS DisorderLethargyDesc_B5e, 
    LU_B5f.DisplayCode AS DisorderMental_B5f,       LU_B5f.UserDescription AS DisorderMentalDesc_B5f, 

    LU_B6.DisplayCode AS ChangeCognitive_B6,        LU_B6.UserDescription AS ChangeCognitiveDesc_B6, 
    LU_C4.DisplayCode AS UnderStood_C4,             LU_C4.UserDescription AS UnderStoodDesc_C4, 
    LU_C6.DisplayCode AS AbilityUnderStood_C6,      LU_C6.UserDescription AS AbilityUnderStoodDesc_C6, 

    LU_E1b.DisplayCode AS DepressionRepeatQues_E1b, LU_E1b.UserDescription AS DepressionRepeatQuesDesc_E1b, 
    LU_E1c.DisplayCode AS DepressionRepeatVerb_E1c, LU_E1c.UserDescription AS DepressionRepeatVerbDesc_E1c, 
    LU_E1o.DisplayCode AS DepressionInterest_E1o,   LU_E1o.UserDescription AS DepressionInterestDesc_E1o, 
    LU_E1p.DisplayCode AS DepressionInteraction_E1p, LU_E1p.UserDescription AS DepressionInteractionDesc_E1p, 

    LU_E4aA.DisplayCode AS BehaviorWanderingFre_E4aA, LU_E4aA.UserDescription AS BehaviorWanderingFreDesc_E4aA, 
    LU_E4bA.DisplayCode AS BehaviorVerballyFre_E4bA, LU_E4bA.UserDescription AS BehaviorVerballyFreDesc_E4bA, 
    LU_E4cA.DisplayCode AS BehaviorPhysicallyFre_E4cA, LU_E4cA.UserDescription AS BehaviorPhysicalFreDesc_E4cA, 
    LU_E4dA.DisplayCode AS BehaviorSociallyFre_E4dA, LU_E4dA.UserDescription AS BehaviorSociallyFreDesc_E4dA, 
    LU_E4eA.DisplayCode AS BehaviorResistsFre_E4eA, LU_E4eA.UserDescription AS BehaviorResistsFreDesc_E4eA, 

    LU_F1a.DisplayCode AS Interacting_F1a,          LU_F1a.UserDescription AS InteractingDesc_F1a, 
    LU_F1b.DisplayCode AS PlanActivity_F1b,         LU_F1b.UserDescription AS PlanActivityDesc_F1b, 
    LU_F1c.DisplayCode AS SelfActivity_F1c,         LU_F1c.UserDescription AS SelfActivityDesc_F1c, 
    LU_F1e.DisplayCode AS Pursues_F1e,              LU_F1e.UserDescription AS PursuesDesc_F1e, 

    LU_G1aA.DisplayCode AS BedMobilitySelf_G1aA,    LU_G1aA.UserDescription AS BedMobilitySelfDesc_G1aA, 
    LU_G1bA.DisplayCode AS TransferSelf_G1bA,       LU_G1bA.UserDescription AS TransferSelfDesc_G1bA, 
    LU_G1cA.DisplayCode AS WalkInRoomSelf_G1cA,     LU_G1cA.UserDescription AS WalkInRoomSelfDesc_G1cA,
    LU_G1hA.DisplayCode AS EatingSelf_G1hA,         LU_G1hA.UserDescription AS EatingSelfDesc_G1hA, 
    LU_G1IA.DisplayCode AS ToiletSelf_G1iA,         LU_G1IA.UserDescription AS ToiletSelfDesc_G1iA, 
    LU_G8b.DisplayCode as ADL_Staff_G8b,            LU_G8b.UserDescription as ADL_StaffDesc_G8b, 
    LU_G9.DisplayCode AS ChangeADL_G9,              LU_G9.UserDescription AS ChangeADLDesc_G9, 

    LU_H1a.DisplayCode AS BowlContinence_H1a,       LU_H1a.UserDescription AS BowlContinenceDesc_H1a,     
    LU_H1b.DisplayCode AS BladderContinence_H1b,    LU_H1b.UserDescription AS BladderContinenceDesc_H1b, 
    LU_H2b.DisplayCode AS BowelConstipation_H2b,    LU_H2b.UserDescription AS BowelConstipationDesc_H2b, 
    LU_H2c.DisplayCode AS BowelDiarrhea_H2c,        LU_H2c.UserDescription AS BowelDiarrheaDesc_H2c, 
    LU_H3a.DisplayCode AS ApplianceScheduled_H3a,   LU_H3a.UserDescription AS ApplianceScheduledDesc_H3a, 
    LU_H3d.DisplayCode AS ApplianceIndCatheter_H3d, LU_H3d.UserDescription AS ApplianceIndCatheterDesc_H3d, 

    LU_I1r.DisplayCode AS DiseaseAlzheimer_I1r,     LU_I1r.UserDescription AS DiseaseAlzheimerDesc_I1r, 
    LU_I1v.DisplayCode AS DiseaseDementia_I1v,      LU_I1v.UserDescription AS DiseaseDementiaDesc_I1v, 
    LU_I1bb.DisplayCode AS DiseaseQuadriplegia_I1bb,LU_I1bb.UserDescription AS DiseaseQuadriplegiaDesc_I1bb, 
    LU_I2f.DisplayCode as InfectionPneumonia_I2f,   LU_I2f.UserDescription as InfectionPneumoniaDesc_I2f, 
    --LU_I2k.DisplayCode as InfectionUrinary_I2k,     LU_I2k.UserDescription as InfectionUrinaryDesc_I2k, 

--    LU_I3a.DisplayCode AS Diagnosis_I3a, LU_I3a.UserDescription AS DiagnosisDesc_I3a, LU_I3a.ShortDescription AS DiagnosisShortDesc_I3a, 
--    LU_I3b.DisplayCode AS Diagnosis_I3b, LU_I3b.UserDescription AS DiagnosisDesc_I3b, LU_I3b.ShortDescription AS DiagnosisShortDesc_I3b, 
--    LU_I3c.DisplayCode AS Diagnosis_I3c, LU_I3c.UserDescription AS DiagnosisDesc_I3c, LU_I3c.ShortDescription AS DiagnosisShortDesc_I3c, 
--    LU_I3d.DisplayCode AS Diagnosis_I3d, LU_I3d.UserDescription AS DiagnosisDesc_I3d, LU_I3d.ShortDescription AS DiagnosisShortDesc_I3d, 
--    LU_I3e.DisplayCode AS Diagnosis_I3e, LU_I3e.UserDescription AS DiagnosisDesc_I3e, LU_I3e.ShortDescription AS DiagnosisShortDesc_I3e, 
--    LU_I3f.DisplayCode AS Diagnosis_I3f, LU_I3f.UserDescription AS DiagnosisDesc_I3f, LU_I3f.ShortDescription AS DiagnosisShortDesc_I3f,

--    LU_J1a.DisplayCode as ProblemWeight_J1a,        LU_J1a.UserDescription as ProblemWeightDesc_J1a, 
    LU_J1c.DisplayCode as ProblemDehydrated_J1c,    LU_J1c.UserDescription as ProblemDehydratedDesc_J1c, 
    LU_J1d.DisplayCode as ProblemFluid_J1d,         LU_J1d.UserDescription as ProblemFluidDesc_J1d, 
    LU_J1f.DisplayCode as ProblemDizziness_J1f,     LU_J1f.UserDescription as ProblemDizzinessDesc_J1f, 
    LU_J1g.DisplayCode as ProblemEdema_J1g,         LU_J1g.UserDescription as ProblemEdemaDesc_J1g, 
    LU_J1h.DisplayCode as ProblemFever_J1h,         LU_J1h.UserDescription as ProblemFeverDesc_J1h, 
    --LU_J1j.DisplayCode as ProblemBleeding_J1j,      LU_J1j.UserDescription as ProblemBleedingDesc_J1j, 
    LU_J1l.DisplayCode as ProblemBreath_J1l,        LU_J1l.UserDescription as ProblemBreathDesc_J1l, 
    LU_J1m.DisplayCode as ProblemSyncope_J1m,       LU_J1m.UserDescription as ProblemSyncopeDesc_J1m, 
    LU_J1o.DisplayCode as ProblemVomiting_J1o,      LU_J1o.UserDescription as ProblemVomitingDesc_J1o, 

    LU_J2a.DisplayCode AS Pain_Frequency_J2a,       LU_J2a.UserDescription AS Pain_FrequencyDesc_J2a, 
    LU_J2b.DisplayCode AS Pain_Intensity_J2b,       LU_J2b.UserDescription AS Pain_IntensityDesc_J2b, 
    LU_J3c.DisplayCode AS PainSiteChest_J3c,        LU_J3c.UserDescription AS PainSiteChestDesc_J3c, 
    LU_J4a.DisplayCode as AccidentFell30_J4a,       LU_J4a.UserDescription as AccidentFell30Desc_J4a, 
    LU_J4b.DisplayCode as AccidentFell180_J4b,      LU_J4b.UserDescription as AccidentFell180Desc_J4b, 

    LU_J4c.DisplayCode as AccidentHipFracture_J4c,  LU_J4c.UserDescription as AccidentHipFractureDesc_J4c, 
    LU_J5b.DisplayCode as Stability_Acute_J5b,      LU_J5b.UserDescription as Stability_AcuteDesc_J5b, 
    LU_J5c.DisplayCode as Stability_EndStage_J5c,   LU_J5c.UserDescription as Stability_EndStageDesc_J5c, 

    --LU_K1c.DisplayCode as OralEndStage_K1c,         LU_K1c.UserDescription as OralEndStageDesc_K1c, 
    dbo.CRS_AssessShare4.K2a as Height_K2a,         dbo.CRS_AssessShare4.K2b as Weight_K2b, 

    (case when LU_AA8.CIHIValue in (''05'', ''10'') then LU_K3a_Q.DisplayCode else LU_K3a_F.DisplayCode end) AS WeightGain_K3a, 
    (case when LU_AA8.CIHIValue in (''05'', ''10'') then LU_K3a_Q.UserDescription else LU_K3a_F.UserDescription end) AS WeightGainDesc_K3a, 

--    LU_K5a.DisplayCode as NutritionalAppPatenteral_K5a, LU_K5a.UserDescription as NutritionalAppPatentDesc_K5a, 
    LU_K5b.DisplayCode as NutritionalAppFeedTube_K5b,   LU_K5b.UserDescription as NutritionalAppFeedTDesc_K5b, 

    --LU_L1a.DisplayCode as OralDebris_L1a,           LU_L1a.UserDescription as OralDebrisDesc_L1a, 
    --LU_L1c.DisplayCode as OralLost_L1c,             LU_L1c.UserDescription as OralLostDesc_L1c, 
    --LU_L1d.DisplayCode as OralBroken_L1d,           LU_L1d.UserDescription as OralBrokenDesc_L1d, 
    --LU_L1e.DisplayCode as OralGum_L1e,              LU_L1e.UserDescription as OralGumDesc_L1e, 
    --LU_L1f.DisplayCode as OralCleaning_L1f,         LU_L1f.UserDescription as OralCleaningDesc_L1f, 

    LU_M2a.DisplayCode AS UlcerTypePressure_M2a,    LU_M2a.UserDescription AS UlcerType_PressureDesc_M2a, 
    LU_M2b.DisplayCode AS UlcerType_Stasis_M2b,     LU_M2b.UserDescription AS UlcerType_StasisDesc_M2b, 
    LU_M3.DisplayCode as ResolveUlcers_M3,          LU_M3.UserDescription as ResolveUlcersDesc_M3, 
    LU_M5e.DisplayCode as SkinTreat_Ulcer_M5e,      LU_M5e.UserDescription as SkinTreat_UlcerDesc_M5e, 

    LU_N2.DisplayCode AS AverageTime_N2,            LU_N2.UserDescription AS AverageTimeDesc_N2, 

    dbo.CRS_AssessShare4.O1 as NumberMedication_O1, 
    --dbo.CRS_AssessShare4.O4e as Days_Diuretic_O4e, 
    dbo.CRS_AssessShare5.P1bcA as TherapyPhysicalDay_P1bcA, 
    LU_P4c.DisplayCode AS DeviceTrunk_P4c,          LU_P4c.UserDescription AS DeviceTrunkDesc_P4c, 
    LU_P4e.DisplayCode AS DeviceChair_P4e,          LU_P4e.UserDescription AS DeviceChairDesc_P4e, 
    dbo.CRS_AssessFull2.P5 as HospitalStay_P5,
    LU_Q2.DisplayCode AS OverallChange_Q2,          LU_Q2.UserDescription AS OverallChangeDesc_Q2, 

    dbo.CRS_Demographic.DischargeDate AS DischargeDate_R4, 
    dbo.CRS_Demographic.AbstractID AS zzAbstractLink, dbo.CRS_Demographic.LinkID AS zzLinkBackgroundID

from dbo.CRS_CAPS with (nolock)
    left join dbo.lu_codefile LU_CAP_ActivitiesDailyLiving with (nolock) on dbo.CRS_CAPS.CAP_ActivitiesDailyLiving = LU_CAP_ActivitiesDailyLiving.Code
    left join dbo.lu_codefile LU_CAP_PhysicalRestraints with (nolock) on dbo.CRS_CAPS.CAP_PhysicalRestraints = LU_CAP_PhysicalRestraints.Code
    left join dbo.lu_codefile LU_CAP_CognitiveLoss with (nolock) on dbo.CRS_CAPS.CAP_CognitiveLoss = LU_CAP_CognitiveLoss.Code
    left join dbo.lu_codefile LU_CAP_Delirium with (nolock) on dbo.CRS_CAPS.CAP_Delirium = LU_CAP_Delirium.Code
    left join dbo.lu_codefile LU_CAP_Communication with (nolock) on dbo.CRS_CAPS.CAP_Communication = LU_CAP_Communication.Code
    left join dbo.lu_codefile LU_CAP_Mood with (nolock) on dbo.CRS_CAPS.CAP_Mood = LU_CAP_Mood.Code
    left join dbo.lu_codefile LU_CAP_Behaviour with (nolock) on dbo.CRS_CAPS.CAP_Behaviour = LU_CAP_Behaviour.Code
    left join dbo.lu_codefile LU_CAP_Activities with (nolock) on dbo.CRS_CAPS.CAP_Activities = LU_CAP_Activities.Code
    left join dbo.lu_codefile LU_CAP_SocialRelationship with (nolock) on dbo.CRS_CAPS.CAP_SocialRelationship = LU_CAP_SocialRelationship.Code
    left join dbo.lu_codefile LU_CAP_Falls with (nolock) on dbo.CRS_CAPS.CAP_Falls = LU_CAP_Falls.Code
    left join dbo.lu_codefile LU_CAP_Pain with (nolock) on dbo.CRS_CAPS.CAP_Pain = LU_CAP_Pain.Code
    left join dbo.lu_codefile LU_CAP_PressureUlcers with (nolock) on dbo.CRS_CAPS.CAP_PressureUlcers = LU_CAP_PressureUlcers.Code
    left join dbo.lu_codefile LU_CAP_CardioRespiratoryConditions with (nolock) on dbo.CRS_CAPS.CAP_CardioRespiratoryConditions = LU_CAP_CardioRespiratoryConditions.Code
    left join dbo.lu_codefile LU_CAP_UnderNutrition with (nolock) on dbo.CRS_CAPS.CAP_UnderNutrition = LU_CAP_UnderNutrition.Code
    left join dbo.lu_codefile LU_CAP_Dehydration with (nolock) on dbo.CRS_CAPS.CAP_Dehydration = LU_CAP_Dehydration.Code
    left join dbo.lu_codefile LU_CAP_FeedingTube with (nolock) on dbo.CRS_CAPS.CAP_FeedingTube = LU_CAP_FeedingTube.Code
    left join dbo.lu_codefile LU_CAP_AppropriateMedications with (nolock) on dbo.CRS_CAPS.CAP_AppropriateMedications = LU_CAP_AppropriateMedications.Code
    left join dbo.lu_codefile LU_CAP_UrinaryIncontinence with (nolock) on dbo.CRS_CAPS.CAP_UrinaryIncontinence = LU_CAP_UrinaryIncontinence.Code
    left join dbo.lu_codefile LU_CAP_BowelConditions with (nolock) on dbo.CRS_CAPS.CAP_BowelConditions = LU_CAP_BowelConditions.Code

    inner join dbo.CRS_Demographic with (nolock) on dbo.CRS_CAPS.AbstractID = dbo.CRS_Demographic.AbstractID
    inner join dbo.LU_CodeFile LU_AA8 with (nolock) on dbo.CRS_Demographic.AA8 = LU_AA8.Code 
    left join  dbo.H_InstitutionProfile with (nolock) on dbo.CRS_Demographic.InstitutionNumber = dbo.H_InstitutionProfile.Code 

    left join dbo.CRS_AssessShare1 with (nolock) on CRS_AssessShare1.AbstractID = dbo.CRS_Demographic.AbstractID
    left join dbo.LU_YesNoSystem LU_B1 with (nolock) on LU_B1.code = dbo.CRS_AssessShare1.B1
    left join dbo.LU_CodeFile LU_B4 with (nolock) on LU_B4.Code = dbo.CRS_AssessShare1.B4 
    left join dbo.LU_CodeFile LU_B5a with (nolock) on LU_B5a.code = dbo.CRS_AssessShare1.B5a
    left join dbo.LU_CodeFile LU_B5b with (nolock) on LU_B5b.code = dbo.CRS_AssessShare1.B5b
    left join dbo.LU_CodeFile LU_B5c with (nolock) on LU_B5c.Code = dbo.CRS_AssessShare1.B5c
    left join dbo.LU_CodeFile LU_B5d with (nolock) on LU_B5d.Code = dbo.CRS_AssessShare1.B5d 
    left join dbo.LU_CodeFile LU_B5e with (nolock) on dbo.CRS_AssessShare1.B5e = LU_B5e.Code 
    left join dbo.LU_CodeFile LU_B5f with (nolock) on dbo.CRS_AssessShare1.B5f = LU_B5f.Code 
    left join dbo.LU_CodeFile LU_B6 with (nolock) on dbo.CRS_AssessShare1.B6 = LU_B6.Code 
    left join dbo.LU_CodeFile LU_C4 with (nolock) on dbo.CRS_AssessShare1.C4 = LU_C4.Code 
    left join dbo.LU_CodeFile LU_C6 with (nolock) on dbo.CRS_AssessShare1.C6 = LU_C6.Code 
    left join dbo.LU_CodeFile LU_E1b with (nolock) on dbo.CRS_AssessShare1.E1b = LU_E1b.Code 
    left join dbo.LU_CodeFile LU_E1c with (nolock) on dbo.CRS_AssessShare1.E1c = LU_E1c.Code 
    left join dbo.LU_CodeFile LU_E1o with (nolock) on LU_E1o.Code = dbo.CRS_AssessShare1.E1o 
    left join dbo.LU_CodeFile LU_E1p with (nolock) on dbo.CRS_AssessShare1.E1p = LU_E1p.Code 
    left join dbo.LU_CodeFile LU_E4aA with (nolock) on dbo.CRS_AssessShare1.E4aA = LU_E4aA.Code 
    left join dbo.LU_CodeFile LU_E4bA with (nolock) on LU_E4bA.Code = dbo.CRS_AssessShare1.E4bA 
    left join dbo.LU_CodeFile LU_E4cA with (nolock) on LU_E4cA.Code = dbo.CRS_AssessShare1.E4cA 
    left join dbo.LU_CodeFile LU_E4dA with (nolock) on dbo.CRS_AssessShare1.E4dA = LU_E4dA.Code 
    left join dbo.LU_CodeFile LU_E4eA with (nolock) on LU_E4eA.Code = dbo.CRS_AssessShare1.E4eA 

    left join dbo.CRS_AssessShare2 with (nolock) on CRS_AssessShare2.AbstractID = dbo.CRS_Demographic.AbstractID
    left join dbo.LU_CodeFile LU_F1a with (nolock) on dbo.CRS_AssessShare2.F1a = LU_F1a.Code 
    left join dbo.LU_CodeFile LU_F1b with (nolock) on dbo.CRS_AssessShare2.F1b = LU_F1b.Code 
    left join dbo.LU_CodeFile LU_F1c with (nolock) on dbo.CRS_AssessShare2.F1c = LU_F1c.Code 
    left join dbo.LU_CodeFile LU_F1e with (nolock) on dbo.CRS_AssessShare2.F1e = LU_F1e.Code 
    left join dbo.LU_CodeFile LU_G1aA with (nolock) on dbo.CRS_AssessShare2.G1aA = LU_G1aA.Code 
    left join dbo.LU_CodeFile LU_G1bA with (nolock) on dbo.CRS_AssessShare2.G1bA = LU_G1bA.Code 
    left join dbo.LU_CodeFile LU_G1cA with (nolock) on dbo.CRS_AssessShare2.G1cA = LU_G1cA.Code 
    left join dbo.LU_CodeFile LU_G1hA with (nolock) on dbo.CRS_AssessShare2.G1hA = LU_G1hA.Code 
    left join dbo.LU_CodeFile LU_G1IA with (nolock) on dbo.CRS_AssessShare2.G1iA = LU_G1IA.Code 
    left join dbo.LU_CodeFile LU_G9 with (nolock) on LU_G9.code = CRS_AssessShare2.G9
    left join dbo.LU_CodeFile LU_H1a with (nolock) on dbo.CRS_AssessShare2.H1a = LU_H1a.Code 
    left join dbo.LU_CodeFile LU_H1b with (nolock) on dbo.CRS_AssessShare2.H1b = LU_H1b.Code 
    left join dbo.LU_YesNoSystem LU_H2b with (nolock) on LU_H2b.code = CRS_AssessShare2.H2b
    left join dbo.LU_YesNoSystem LU_H2c with (nolock) on LU_H2c.code = CRS_AssessShare2.H2c
    left join dbo.LU_YesNoSystem LU_H3a with (nolock) on LU_H3a.code = CRS_AssessShare2.H3a
    left join dbo.LU_YesNoSystem LU_H3d with (nolock) on LU_H3d.code = CRS_AssessShare2.H3d

    left join dbo.CRS_AssessShare3 with (nolock) on CRS_AssessShare3.AbstractID = dbo.CRS_Demographic.AbstractID
    left join dbo.LU_YesNoSystem LU_I1r with (nolock) on LU_I1r.code = CRS_AssessShare3.I1r
    left join dbo.LU_YesNoSystem LU_I1v with (nolock) on LU_I1v.code = CRS_AssessShare3.I1v
    left join dbo.LU_YesNoSystem LU_I1bb with (nolock) on LU_I1bb.code = CRS_AssessShare3.I1bb
    left join dbo.LU_YesNoSystem LU_I2f with (nolock) on LU_I2f.code = CRS_AssessShare3.I2f
--    left join dbo.LU_YesNoSystem LU_I2k with (nolock) on LU_I2k.code = CRS_AssessShare3.I2k
--
--    left join dbo.LU_YesNoSystem LU_J1a with (nolock) on LU_J1a.code = CRS_AssessShare3.J1a
    left join dbo.LU_YesNoSystem LU_J1c with (nolock) on LU_J1c.code = CRS_AssessShare3.J1c
    left join dbo.LU_YesNoSystem LU_J1d with (nolock) on LU_J1d.code = CRS_AssessShare3.J1d
    left join dbo.LU_YesNoSystem LU_J1f with (nolock) on LU_J1f.code = CRS_AssessShare3.J1f
    left join dbo.LU_YesNoSystem LU_J1g with (nolock) on LU_J1g.code = CRS_AssessShare3.J1g
    left join dbo.LU_YesNoSystem LU_J1h with (nolock) on LU_J1h.code = CRS_AssessShare3.J1h
--    left join dbo.LU_YesNoSystem LU_J1j with (nolock) on LU_J1j.code = CRS_AssessShare3.J1j
    left join dbo.LU_YesNoSystem LU_J1l with (nolock) on LU_J1l.code = CRS_AssessShare3.J1l
    left join dbo.LU_YesNoSystem LU_J1m with (nolock) on LU_J1m.code = CRS_AssessShare3.J1m
    left join dbo.LU_YesNoSystem LU_J1o with (nolock) on LU_J1o.code = CRS_AssessShare3.J1o

    left join dbo.LU_CodeFile LU_J2a with (nolock) on dbo.CRS_AssessShare3.J2a = LU_J2a.Code 
    left join dbo.LU_CodeFile LU_J2b with (nolock) on dbo.CRS_AssessShare3.J2b = LU_J2b.Code 
    left join dbo.LU_YesNoSystem LU_J4a with (nolock) on LU_J4a.code = CRS_AssessShare3.J4a
    left join dbo.LU_YesNoSystem LU_J4b with (nolock) on LU_J4b.code = CRS_AssessShare3.J4b
    left join dbo.LU_YesNoSystem LU_J4c with (nolock) on LU_J4c.code = CRS_AssessShare3.J4c
    left join dbo.LU_YesNoSystem LU_J5b with (nolock) on LU_J5b.code = CRS_AssessShare3.J5b
    left join dbo.LU_YesNoSystem LU_J5c with (nolock) on LU_J5c.code = CRS_AssessShare3.J5c

    left join dbo.CRS_AssessShare4 with (nolock) on CRS_AssessShare4.AbstractID = dbo.CRS_Demographic.AbstractID
--    left join dbo.LU_YesNoSystem LU_K1c with (nolock) on LU_K1c.code = CRS_AssessShare4.K1c
    left join dbo.LU_CodeFile LU_K3a_Q with (nolock) on LU_K3a_Q.Code = dbo.CRS_AssessShare4.K3a 
    left join dbo.LU_YesNoSystem LU_K3a_F with (nolock) on LU_K3a_F.code = CRS_AssessShare4.K3a
--    left join dbo.LU_YesNoSystem LU_K5a with (nolock) on LU_K5a.code = CRS_AssessShare4.K5a
    left join dbo.LU_YesNoSystem LU_K5b with (nolock) on LU_K5b.code = CRS_AssessShare4.K5b
    left join dbo.LU_CodeFile LU_N2 with (nolock) on LU_N2.Code = dbo.CRS_AssessShare4.N2 
    left join dbo.LU_CodeFile LU_M2a with (nolock) on dbo.CRS_AssessShare4.M2a = LU_M2a.Code 
    left join dbo.LU_CodeFile LU_M2b with (nolock) on dbo.CRS_AssessShare4.M2b = LU_M2b.Code 
    left join dbo.LU_YesNoSystem LU_M5e with (nolock) on LU_M5e.code = CRS_AssessShare4.M5e

    left join dbo.CRS_AssessShare5 with (nolock) on CRS_AssessShare5.AbstractID = dbo.CRS_Demographic.AbstractID
    left join LU_CodeFile LU_P4c with (nolock) on LU_P4c.code = CRS_AssessShare5.P4c
    left join LU_CodeFile LU_P4e with (nolock) on LU_P4e.code = CRS_AssessShare5.P4e
    left join LU_CodeFile LU_Q2 with (nolock) on LU_Q2.code = CRS_AssessShare5.Q2

    left join dbo.CRS_AssessFull1 with (nolock) on CRS_AssessFull1.AbstractID = dbo.CRS_Demographic.AbstractID
    left join dbo.LU_CodeFile LU_J3c with (nolock) on dbo.CRS_AssessFull1.J3c = LU_J3c.Code 
    left join dbo.LU_YesNoSystem LU_G8b with (nolock) on LU_G8b.code = CRS_AssessFull1.G8b

    left join dbo.CRS_AssessFull2 with (nolock) on CRS_AssessFull2.AbstractID = dbo.CRS_Demographic.AbstractID
--    left join dbo.LU_YesNoSystem LU_L1a with (nolock) on LU_L1a.code = CRS_AssessFull2.L1a
--    left join dbo.LU_YesNoSystem LU_L1c with (nolock) on LU_L1c.code = CRS_AssessFull2.L1c
--    left join dbo.LU_YesNoSystem LU_L1d with (nolock) on LU_L1d.code = CRS_AssessFull2.L1d
--    left join dbo.LU_YesNoSystem LU_L1e with (nolock) on LU_L1e.code = CRS_AssessFull2.L1e
--    left join dbo.LU_YesNoSystem LU_L1f with (nolock) on LU_L1f.code = CRS_AssessFull2.L1f
    left join dbo.LU_YesNoSystem LU_M3 with (nolock) on LU_M3.code = CRS_AssessFull2.M3
--
--    left join dbo.CRS_Diagnosis with (nolock) on CRS_Diagnosis.AbstractID = dbo.CRS_Demographic.AbstractID
--    left join dbo.ICD_DiagFile10 LU_I3a with (nolock) on dbo.CRS_Diagnosis.I3a = LU_I3a.Code
--    left join dbo.ICD_DiagFile10 LU_I3b with (nolock) on dbo.CRS_Diagnosis.I3b = LU_I3b.Code 
--    left join dbo.ICD_DiagFile10 LU_I3c with (nolock) on dbo.CRS_Diagnosis.I3c = LU_I3c.Code 
--    left join dbo.ICD_DiagFile10 LU_I3d with (nolock) on dbo.CRS_Diagnosis.I3d = LU_I3d.Code 
--    left join dbo.ICD_DiagFile10 LU_I3e with (nolock) on dbo.CRS_Diagnosis.I3e = LU_I3e.Code 
--    left join dbo.ICD_DiagFile10 LU_I3f with (nolock) on dbo.CRS_Diagnosis.I3f = LU_I3f.Code 




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[MDS20_Diagnosis_VR]
AS
SELECT     dbo.CRS_Diagnosis.AbstractID AS zzAbstractLink, LU_I3a.DisplayCode AS Diagnosis_I3a, LU_I3a.UserDescription AS DiagnosisDesc_I3a, 
                      LU_I3a.ShortDescription AS DiagnosisShortDesc_I3a, LU_I3b.DisplayCode AS Diagnosis_I3b, LU_I3b.UserDescription AS DiagnosisDesc_I3b, 
                      LU_I3b.ShortDescription AS DiagnosisShortDesc_I3b, LU_I3c.DisplayCode AS Diagnosis_I3c, LU_I3c.UserDescription AS DiagnosisDesc_I3c, 
                      LU_I3c.ShortDescription AS DiagnosisShortDesc_I3c, LU_I3d.DisplayCode AS Diagnosis_I3d, LU_I3d.UserDescription AS DiagnosisDesc_I3d, 
                      LU_I3d.ShortDescription AS DiagnosisShortDesc_I3d, LU_I3e.DisplayCode AS Diagnosis_I3e, LU_I3e.UserDescription AS DiagnosisDesc_I3e, 
                      LU_I3e.ShortDescription AS DiagnosisShortDesc_I3e, LU_I3f.DisplayCode AS Diagnosis_I3f, LU_I3f.UserDescription AS DiagnosisDesc_I3f, 
                      LU_I3f.ShortDescription AS DiagnosisShortDesc_I3f
FROM         
                      dbo.CRS_Diagnosis with (nolock) LEFT OUTER JOIN
                      dbo.ICD_DiagFile10 LU_I3f with (nolock) ON dbo.CRS_Diagnosis.I3f = LU_I3f.Code LEFT OUTER JOIN
                      dbo.ICD_DiagFile10 LU_I3e with (nolock) ON dbo.CRS_Diagnosis.I3e = LU_I3e.Code LEFT OUTER JOIN
                      dbo.ICD_DiagFile10 LU_I3d with (nolock) ON dbo.CRS_Diagnosis.I3d = LU_I3d.Code LEFT OUTER JOIN
                      dbo.ICD_DiagFile10 LU_I3c with (nolock) ON dbo.CRS_Diagnosis.I3c = LU_I3c.Code LEFT OUTER JOIN
                      dbo.ICD_DiagFile10 LU_I3b with (nolock) ON dbo.CRS_Diagnosis.I3b = LU_I3b.Code LEFT OUTER JOIN
                      dbo.ICD_DiagFile10 LU_I3a with (nolock) ON LU_I3a.Code = dbo.CRS_Diagnosis.I3a






' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_ErrorsWarnings_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[MDS20_ErrorsWarnings_VR]
AS
SELECT 
    CIHI_ElementID = U_UsersFields.CIHI_ID,
    FieldName = U_UsersFields.Header_User, 
    --ErrorMessage = dbo.MG_Messages.MessageText, 
    MessageLevel = CASE AB_ErrorMessages.MessageType WHEN 1 THEN ''Warning'' 
                                    WHEN 2 THEN ''Error'' 
                                    WHEN 3 THEN ''Critical'' 
                                    WHEN 0 THEN ''Information'' 
                                    WHEN 5 THEN ''Question'' END, 
    AB_ErrorMessages.MessageText, 
    AB_ErrorMessages.SaveDate, 
    AB_ErrorMessages.AbstractID AS zzAbstractLink
FROM dbo.AB_ErrorMessages with (nolock)
    --left join dbo.MG_Messages with (nolock)
    --    on dbo.AB_ErrorMessages.MessageKey = dbo.MG_Messages.MessageKey
    left join dbo.AB_ErrorMessageFields with (nolock)
        on dbo.AB_ErrorMessages.AppID = dbo.AB_ErrorMessageFields.AppID
            and dbo.AB_ErrorMessages.AbstractID = dbo.AB_ErrorMessageFields.AbstractID 
            and dbo.AB_ErrorMessages.MessageKey = dbo.AB_ErrorMessageFields.MessageKey
    left join dbo.U_UsersFields with (nolock) 
        on UserID = 1 and dbo.AB_ErrorMessages.AppID = dbo.U_UsersFields.AppID and 
        (case when isnumeric(replace(dbo.AB_ErrorMessageFields.FieldKey, ''FK'', '''')) = 1 
              then replace(dbo.AB_ErrorMessageFields.FieldKey, ''FK'', '''')
              else 0 end) = dbo.U_UsersFields.FieldID 
Where AB_ErrorMessages.appid between 470 and 475

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_First_Assessment_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'







CREATE view [dbo].[MDS20_First_Assessment_VR]
as
select 
    CCRS.AbstractID as zzAbstractLink
from CRS_Demographic CCRS  with (nolock)
where AbstractID = LinkID









' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_1_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[MDS20_FULL_1_VR]
AS
SELECT  
    (case CRS_AssessFull1.A7a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Provincial_A7a, 
    (case CRS_AssessFull1.A7a when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_ProvincialDesc_A7a, 
    (case CRS_AssessFull1.A7b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Other_Prov_A7b, 
    (case CRS_AssessFull1.A7b when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_Other_ProvDesc_A7b, 
    (case CRS_AssessFull1.A7c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Federal_V_A7c, 
    (case CRS_AssessFull1.A7c when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_Federal_VDesc_A7c, 
    (case CRS_AssessFull1.A7d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Federal_F_A7d, 
    (case CRS_AssessFull1.A7d when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_Federal_FDesc_A7d, 
    (case CRS_AssessFull1.A7e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Federal_O_A7e, 
    (case CRS_AssessFull1.A7e when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_Federal_ODesc_A7e, 
    (case CRS_AssessFull1.A7f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_WCB_A7f, 
    (case CRS_AssessFull1.A7f when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_WCBDesc_A7f, 
    (case CRS_AssessFull1.A7g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Insurance_A7g, 
    (case CRS_AssessFull1.A7g when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_InsuranceDesc_A7g, 
    (case CRS_AssessFull1.A7h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Public_A7h, 
    (case CRS_AssessFull1.A7h when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_PublicDesc_A7h, 
    (case CRS_AssessFull1.A7I when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Self_A7i, 
    (case CRS_AssessFull1.A7I when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_SelfDesc_A7i, 
    (case CRS_AssessFull1.A7j when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Other_Country_A7j, 
    (case CRS_AssessFull1.A7j when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_Other_CountryDesc_A7j, 
    (case CRS_AssessFull1.A7k when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Unkown_A7k, 
    (case CRS_AssessFull1.A7k when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_UnkownDesc_A7k, 

    LU_C1.DisplayCode AS Hearing_C1, LU_C1.UserDescription AS HearingDesc_C1, 

    LU_C2a.DisplayCode AS CommAidReg_C2a, LU_C2a.UserDescription AS CommAidRegDesc_C2a, 
    LU_C2b.DisplayCode AS CommAidNoReg_C2b, LU_C2b.UserDescription AS CommAidNoRegDesc_C2b, 
    LU_C2c.DisplayCode AS CommOther_C2c, LU_C2c.UserDescription AS CommOtherDesc_C2c, 
    (case when CRS_AssessFull1.C2All > 0 then Y1.DisplayCode end) as CommNone_C2d, 
    (case when CRS_AssessFull1.C2All > 0 then Y1.UserDescription end) as CommNoneDesc_C2d, 

    LU_C3a.DisplayCode AS ExpressSpeech_C3a, LU_C3a.UserDescription AS ExpressSpeechDesc_C3a, 
    LU_C3b.DisplayCode AS ExpressWrite_C3b,  LU_C3b.UserDescription AS ExpressWriteDesc_C3b, 
    LU_C3c.DisplayCode AS ExpressLanguage_C3c, LU_C3c.UserDescription AS ExpressLanguageDesc_C3c, 
    LU_C3d.DisplayCode AS ExpressSigns_C3d, LU_C3d.UserDescription AS ExpressSignsDesc_C3d, 
    LU_C3e.DisplayCode AS ExpressBoard_C3e, LU_C3e.UserDescription AS ExpressBoardDesc_C3e, 
    LU_C3f.DisplayCode AS ExpressOther_C3f, LU_C3f.UserDescription AS ExpressOtherDesc_C3f, 
    (case when CRS_AssessFull1.C3All > 0 then Y1.DisplayCode end) as ExpressNone_C3g, 
    (case when CRS_AssessFull1.C3All > 0 then Y1.UserDescription end) as ExpressNoneDesc_C3g, 

    LU_C5.DisplayCode AS SpeechClarity_C5, LU_C5.UserDescription AS SpeechClarityDesc_C5, 

    LU_D1.DisplayCode AS Vision_D1, LU_D1.UserDescription AS VisionDesc_D1, 
    LU_D2a.DisplayCode AS SideVision_D2a, LU_D2a.UserDescription AS SideVisionDesc_D2a, 
    LU_D2b.DisplayCode AS HaloVision_D2b, LU_D2b.UserDescription AS HaloVisionDesc_D2b, 
    LU_D3.DisplayCode AS VisualApp_D3, LU_D3.UserDescription AS VisualAppDesc_D3, 

    LU_F2a.DisplayCode AS UnsettledStaff_F2a, LU_F2a.UserDescription AS UnsettledStaffDesc_F2a, 
    LU_F2b.DisplayCode AS UnsettledRoommate_F2b, LU_F2b.UserDescription AS UnsettledRoommateDesc_F2b, 
    LU_F2c.DisplayCode AS UnsettledResident_F2c, LU_F2c.UserDescription AS UnsettledResidentDesc_F2c, 
    LU_F2d.DisplayCode AS UnsettledFamily_F2d, LU_F2d.UserDescription AS UnsettledFamilyDesc_F2d, 
    LU_F2e.DisplayCode AS UnsettledAbsence_F2e, LU_F2e.UserDescription AS UnsettledAbsenceDesc_F2e, 
    LU_F2f.DisplayCode AS UnsettledLoss_F2f, LU_F2f.UserDescription AS UnsettledLossDesc_F2f, 
    LU_F2g.DisplayCode AS UnsettledChange_F2g, LU_F2g.UserDescription AS UnsettledChangeDesc_F2g, 
    (case when CRS_AssessFull1.F2All > 0 then Y1.DisplayCode end) as UnsettledNone_F2h, 
    (case when CRS_AssessFull1.F2All > 0 then Y1.UserDescription end) as UnsettledNoneDesc_F2h, 

    LU_F3a.DisplayCode AS PastRoleIden_F3a, LU_F3a.UserDescription AS PastRoleIdenDesc_F3a, 
    LU_F3b.DisplayCode AS PastRoleExpress_F3b, LU_F3b.UserDescription AS PastRoleExpressDesc_F3b, 
    LU_F3c.DisplayCode AS PastRolePerceive_F3c, LU_F3c.UserDescription AS PastRolePerceiveDesc_F3c, 

    (case CRS_AssessFull1.G5a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as LocomotionWalker_G5a, 
    (case CRS_AssessFull1.G5a when 1 then Y.UserDescription when 2 then N.UserDescription end) as LocomotionWalkerDesc_G5a, 
    (case CRS_AssessFull1.G5b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as LocomotionWheelSelf_G5b, 
    (case CRS_AssessFull1.G5b when 1 then Y.UserDescription when 2 then N.UserDescription end) as LocomotionWheelSelfDesc_G5b, 
    (case CRS_AssessFull1.G5c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as LocomotionWheelOther_G5c, 
    (case CRS_AssessFull1.G5c when 1 then Y.UserDescription when 2 then N.UserDescription end) as LocomotionWheelOtherDesc_G5c, 
    (case CRS_AssessFull1.G5d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as LocomotionWheelChair_G5d, 
    (case CRS_AssessFull1.G5d when 1 then Y.UserDescription when 2 then N.UserDescription end) as LocomotionWheelChairDesc_G5d, 
    (case when CRS_AssessFull1.G5All > 0 then Y1.DisplayCode end) as LocomotionNone_G5e, 
    (case when CRS_AssessFull1.G5All > 0 then Y1.UserDescription end) as LocomotionNoneDesc_G5e, 

    (case CRS_AssessFull1.G8a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ADL_Resident_G8a, 
    (case CRS_AssessFull1.G8a when 1 then Y.UserDescription when 2 then N.UserDescription end) as ADL_ResidentDesc_G8a, 
    (case CRS_AssessFull1.G8b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ADL_Staff_G8b, 
    (case CRS_AssessFull1.G8b when 1 then Y.UserDescription when 2 then N.UserDescription end) as ADL_StaffDesc_G8b, 
    (case CRS_AssessFull1.G8c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ADL_Slow_G8c, 
    (case CRS_AssessFull1.G8c when 1 then Y.UserDescription when 2 then N.UserDescription end) as ADL_SlowDesc_G8c, 
    (case CRS_AssessFull1.G8d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ADL_Diff_G8d, 
    (case CRS_AssessFull1.G8d when 1 then Y.UserDescription when 2 then N.UserDescription end) as ADL_DiffDesc_G8d, 
    (case when CRS_AssessFull1.G8All > 0 then Y1.DisplayCode end) as ADL_None_G8e, 
    (case when CRS_AssessFull1.G8All > 0 then Y1.UserDescription end) as ADL_NoneDesc_G8e, 

    LU_J3a.DisplayCode AS PainSiteBack_J3a, LU_J3a.UserDescription AS PainSiteBackDesc_J3a, 
    LU_J3b.DisplayCode AS PainSiteBone_J3b, LU_J3b.UserDescription AS PainSiteBoneDesc_J3b, 
    LU_J3c.DisplayCode AS PainSiteChest_J3c, LU_J3c.UserDescription AS PainSiteChestDesc_J3c, 
    LU_J3d.DisplayCode AS PainSiteHead_J3d, LU_J3d.UserDescription AS PainSiteHeadDesc_J3d, 
    LU_J3e.DisplayCode AS PainSiteHip_J3e, LU_J3e.UserDescription AS PainSiteHipDesc_J3e, 
    LU_J3f.DisplayCode AS PainSiteIncision_J3f, LU_J3f.UserDescription AS PainSiteIncisionDesc_J3f, 
    LU_J3g.DisplayCode AS PainSiteJoint_J3g, LU_J3g.UserDescription AS PainSiteJointDesc_J3g, 
    LU_J3h.DisplayCode AS PainSiteTissue_J3h, LU_J3h.UserDescription AS PainSiteTissueDesc_J3h, 
    LU_J3I.DisplayCode AS PainSiteStomach_J3i, LU_J3I.UserDescription AS PainSiteStomachDesc_J3i, 
    LU_J3j.DisplayCode AS PainSiteOther_J3j, LU_J3j.UserDescription AS PainSiteOtherDesc_J3j, 

    CRS_AssessFull1.AbstractID as zzAbstractLink
FROM     
    dbo.CRS_AssessFull1 with (nolock) LEFT JOIN
    dbo.LU_CodeFile LU_J3j with (nolock) on dbo.CRS_AssessFull1.J3j = LU_J3j.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J3I with (nolock) on dbo.CRS_AssessFull1.J3I = LU_J3I.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J3h with (nolock) on dbo.CRS_AssessFull1.J3h = LU_J3h.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J3g with (nolock) on dbo.CRS_AssessFull1.J3g = LU_J3g.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J3f with (nolock) on dbo.CRS_AssessFull1.J3f = LU_J3f.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J3e with (nolock) on dbo.CRS_AssessFull1.J3e = LU_J3e.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J3d with (nolock) on dbo.CRS_AssessFull1.J3d = LU_J3d.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J3c with (nolock) on dbo.CRS_AssessFull1.J3c = LU_J3c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J3b with (nolock) on dbo.CRS_AssessFull1.J3b = LU_J3b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J3a with (nolock) on dbo.CRS_AssessFull1.J3a = LU_J3a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F3c with (nolock) on dbo.CRS_AssessFull1.F3c = LU_F3c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F3b with (nolock) on dbo.CRS_AssessFull1.F3b = LU_F3b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F3a with (nolock) on dbo.CRS_AssessFull1.F3a = LU_F3a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F2g with (nolock) on dbo.CRS_AssessFull1.F2g = LU_F2g.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F2f with (nolock) on dbo.CRS_AssessFull1.F2f = LU_F2f.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F2e with (nolock) on dbo.CRS_AssessFull1.F2e = LU_F2e.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F2d with (nolock) on dbo.CRS_AssessFull1.F2d = LU_F2d.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F2c with (nolock) on dbo.CRS_AssessFull1.F2c = LU_F2c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F2b with (nolock) on dbo.CRS_AssessFull1.F2b = LU_F2b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F2a with (nolock) on dbo.CRS_AssessFull1.F2a = LU_F2a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_D3 with (nolock) on dbo.CRS_AssessFull1.D3 = LU_D3.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_D2b with (nolock) on dbo.CRS_AssessFull1.D2b = LU_D2b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_D2a with (nolock) on dbo.CRS_AssessFull1.D2a = LU_D2a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_D1 with (nolock) on dbo.CRS_AssessFull1.D1 = LU_D1.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C5 with (nolock) on dbo.CRS_AssessFull1.C5 = LU_C5.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C3f with (nolock) on dbo.CRS_AssessFull1.C3f = LU_C3f.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C3e with (nolock) on dbo.CRS_AssessFull1.C3e = LU_C3e.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C3d with (nolock) on dbo.CRS_AssessFull1.C3d = LU_C3d.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C3c with (nolock) on dbo.CRS_AssessFull1.C3c = LU_C3c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C3b with (nolock) on dbo.CRS_AssessFull1.C3b = LU_C3b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C3a with (nolock) on dbo.CRS_AssessFull1.C3a = LU_C3a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C2c with (nolock) on dbo.CRS_AssessFull1.C2c = LU_C2c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C2b with (nolock) on dbo.CRS_AssessFull1.C2b = LU_C2b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C2a with (nolock) on dbo.CRS_AssessFull1.C2a = LU_C2a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C1 with (nolock) on dbo.CRS_AssessFull1.C1 = LU_C1.Code 
    cross join ( select top 1 DisplayCode, UserDescription from LU_YesNoSystem where code = 1 ) Y
    cross join ( select top 1 DisplayCode, UserDescription from LU_YesNoSystem where code = 2 ) N
    cross join ( select top 1 DisplayCode, UserDescription from LU_CodeFile where LookUpID = 1 ) Y1

/*
    dbo.LU_CodeFile LU_G8All with (nolock) on dbo.CRS_AssessFull1.G8All = LU_G8All.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G5All with (nolock) on dbo.CRS_AssessFull1.G5All = LU_G5All.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F2All with (nolock) on dbo.CRS_AssessFull1.F2All = LU_F2All.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C3All with (nolock) on dbo.CRS_AssessFull1.C3All = LU_C3All.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C2All with (nolock) on dbo.CRS_AssessFull1.C2All = LU_C2All.Code LEFT OUTER JOIN

    dbo.LU_YesNoSystem LU_G8d with (nolock) on dbo.CRS_AssessFull1.G8d = LU_G8d.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_G8c with (nolock) on dbo.CRS_AssessFull1.G8c = LU_G8c.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_G8b with (nolock) on dbo.CRS_AssessFull1.G8b = LU_G8b.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_G8a with (nolock) on LU_G8a.Code = dbo.CRS_AssessFull1.G8a LEFT OUTER JOIN

    dbo.LU_YesNoSystem LU_G5d with (nolock) on dbo.CRS_AssessFull1.G5d = LU_G5d.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_G5c with (nolock) on dbo.CRS_AssessFull1.G5c = LU_G5c.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_G5b with (nolock) on LU_G5b.Code = dbo.CRS_AssessFull1.G5b LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_G5a with (nolock) on dbo.CRS_AssessFull1.G5a = LU_G5a.Code LEFT OUTER JOIN

    dbo.LU_YesNoSystem LU_A7k with (nolock) on dbo.CRS_AssessFull1.A7k = LU_A7k.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_A7j with (nolock) on dbo.CRS_AssessFull1.A7j = LU_A7j.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_A7I with (nolock) on LU_A7I.Code = dbo.CRS_AssessFull1.A7I LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_A7h with (nolock) on dbo.CRS_AssessFull1.A7h = LU_A7h.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_A7g with (nolock) on dbo.CRS_AssessFull1.A7g = LU_A7g.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_A7f with (nolock) on dbo.CRS_AssessFull1.A7f = LU_A7f.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_A7e with (nolock) on dbo.CRS_AssessFull1.A7e = LU_A7e.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_A7d with (nolock) on dbo.CRS_AssessFull1.A7d = LU_A7d.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_A7c with (nolock) on dbo.CRS_AssessFull1.A7c = LU_A7c.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_A7b with (nolock) on dbo.CRS_AssessFull1.A7b = LU_A7b.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_A7a with (nolock) on dbo.CRS_AssessFull1.A7a = LU_A7a.Code
*/

















' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_2_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'







CREATE VIEW [dbo].[MDS20_FULL_2_VR]
AS
SELECT 
    (case CRS_AssessFull2.L1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as OralDebris_L1a, 
    (case CRS_AssessFull2.L1a when 1 then Y.UserDescription when 2 then N.UserDescription end) as OralDebrisDesc_L1a, 
    (case CRS_AssessFull2.L1b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as OralDentures_L1b, 
    (case CRS_AssessFull2.L1b when 1 then Y.UserDescription when 2 then N.UserDescription end) as OralDenturesDesc_L1b, 
    (case CRS_AssessFull2.L1c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as OralLost_L1c, 
    (case CRS_AssessFull2.L1c when 1 then Y.UserDescription when 2 then N.UserDescription end) as OralLostDesc_L1c, 
    (case CRS_AssessFull2.L1d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as OralBroken_L1d, 
    (case CRS_AssessFull2.L1d when 1 then Y.UserDescription when 2 then N.UserDescription end) as OralBrokenDesc_L1d, 
    (case CRS_AssessFull2.L1e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as OralGum_L1e, 
    (case CRS_AssessFull2.L1e when 1 then Y.UserDescription when 2 then N.UserDescription end) as OralGumDesc_L1e, 
    (case CRS_AssessFull2.L1f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as OralCleaning_L1f, 
    (case CRS_AssessFull2.L1f when 1 then Y.UserDescription when 2 then N.UserDescription end) as OralCleaningDesc_L1f, 
    (case when CRS_AssessFull2.L1All > 0 then Y1.DisplayCode end) as OralNone_L1g, 
    (case when CRS_AssessFull2.L1All > 0 then Y1.UserDescription end) as OralNoneDesc_L1g, 

    (case CRS_AssessFull2.M3 when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ResolveUlcers_M3, 
    (case CRS_AssessFull2.M3 when 1 then Y.UserDescription when 2 then N.UserDescription end) as ResolveUlcersDesc_M3, 

    LU_N3a.DisplayCode AS ActSetOwn_N3a, LU_N3a.UserDescription AS ActSetOwnDesc_N3a, 
    LU_N3b.DisplayCode AS ActSetDay_N3b, LU_N3b.UserDescription AS ActSetDayDesc_N3b, 
    LU_N3c.DisplayCode AS ActSetInside_N3c, LU_N3c.UserDescription AS ActSetInsideDesc_N3c, 
    LU_N3d.DisplayCode AS ActSetOutside_N3d, LU_N3d.UserDescription AS ActSetOutsideDesc_N3d, 
    (case when CRS_AssessFull2.N3All > 0 then Y1.DisplayCode end) as ActSetNone_N3e, 
    (case when CRS_AssessFull2.N3All > 0 then Y1.UserDescription end) as ActSetNoneDesc_N3e, 

    LU_N4a.DisplayCode AS ActPreferCards_N4a, LU_N4a.UserDescription AS ActPreferCardsDesc_N4a, 
    LU_N4b.DisplayCode AS ActPreferCrafts_N4b, LU_N4b.UserDescription AS ActPreferCraftsDesc_N4b, 
    LU_N4c.DisplayCode AS ActPreferSports_N4c, LU_N4c.UserDescription AS ActPreferSportsDesc_N4c, 
    LU_N4d.DisplayCode AS ActPreferMusic_N4d, LU_N4d.UserDescription AS ActPreferMusicDesc_N4d, 
    LU_N4e.DisplayCode AS ActPreferReading_N4e, LU_N4e.UserDescription AS ActPreferReadingDesc_N4e, 
    LU_N4f.DisplayCode AS ActPreferReligious_N4f, LU_N4f.UserDescription AS ActPreferReligiousDesc_N4f, 
    LU_N4g.DisplayCode AS ActPreferShopping_N4g, LU_N4g.UserDescription AS ActPreferShoppingDesc_N4g, 
    LU_N4h.DisplayCode AS ActPreferWalk_N4h, LU_N4h.UserDescription AS ActPreferWalkDesc_N4h, 
    LU_N4I.DisplayCode AS ActPreferTV_N4i, LU_N4I.UserDescription AS ActPreferTVDesc_N4i, 
    LU_N4j.DisplayCode AS ActPreferGarden_N4j, LU_N4j.UserDescription AS ActPreferGardenDesc_N4j, 
    LU_N4k.DisplayCode AS ActPreferTalking_N4k, LU_N4k.UserDescription AS ActPreferTalkingDesc_N4k, 
    LU_N4l.DisplayCode AS ActPreferHelping_N4l, LU_N4l.UserDescription AS ActPreferHelpingDesc_N4l, 
    (case when CRS_AssessFull2.N4All > 0 then Y1.DisplayCode end) as ActPreferNone_N4m, 
    (case when CRS_AssessFull2.N4All > 0 then Y1.UserDescription end) as ActPreferNoneDesc_N4m, 


    LU_N5a.DisplayCode AS PreferChangeType_N5a, LU_N5a.UserDescription AS PreferChangeTypeDesc_N5a, 
    LU_N5b.DisplayCode AS PreferChangeExtent_N5b, LU_N5b.UserDescription AS PreferChangeExtentDesc_N5b, 

    LU_O2.DisplayCode AS NewMedication_O2, LU_O2.UserDescription AS NewMedicationDesc_O2, 

    (case CRS_AssessFull2.P2a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as IntervSpecial_P2a, 
    (case CRS_AssessFull2.P2a when 1 then Y.UserDescription when 2 then N.UserDescription end) as IntervSpecialDesc_P2a, 
    (case CRS_AssessFull2.P2b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as IntervSpecialist_P2b, 
    (case CRS_AssessFull2.P2b when 1 then Y.UserDescription when 2 then N.UserDescription end) as IntervSpecialistDesc_P2b, 
    (case CRS_AssessFull2.P2c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as IntervGroup_P2c, 
    (case CRS_AssessFull2.P2c when 1 then Y.UserDescription when 2 then N.UserDescription end) as IntervGroupDesc_P2c, 
    (case CRS_AssessFull2.P2d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as IntervChange_P2d, 
    (case CRS_AssessFull2.P2d when 1 then Y.UserDescription when 2 then N.UserDescription end) as IntervChangeDesc_P2d, 
    (case CRS_AssessFull2.P2e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as IntervReorientation_P2e, 
    (case CRS_AssessFull2.P2e when 1 then Y.UserDescription when 2 then N.UserDescription end) as IntervReorientationDesc_P2e, 
    (case when CRS_AssessFull2.P2All > 0 then Y1.DisplayCode end) as IntervNone_P2f, 
    (case when CRS_AssessFull2.P2All > 0 then Y1.UserDescription end) as IntervNoneDesc_P2f, 

    dbo.CRS_AssessFull2.P5 as HospitalStay_P5, dbo.CRS_AssessFull2.P6 as EmergencyRoom_P6, 
    (case CRS_AssessFull2.P9 when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as AbnormalLabValues_P9, 
    (case CRS_AssessFull2.P9 when 1 then Y.UserDescription when 2 then N.UserDescription end) as AbnormalLabValuesDesc_P9, 
    (case CRS_AssessFull2.Q1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as DischargeExpress_Q1a, 
    (case CRS_AssessFull2.Q1a when 1 then Y.UserDescription when 2 then N.UserDescription end) as DischargeExpressDesc_Q1a, 
    (case CRS_AssessFull2.Q1b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as DischargeSupport_Q1b, 
    (case CRS_AssessFull2.Q1b when 1 then Y.UserDescription when 2 then N.UserDescription end) as DischargeSupportDesc_Q1b, 
    LU_Q1c.DisplayCode AS DischargeProject_Q1c, LU_Q1c.UserDescription AS DischargeProjectDesc_Q1c, 

    (case CRS_AssessFull2.R1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ParticipationResident_R1a, 
    (case CRS_AssessFull2.R1a when 1 then Y.UserDescription when 2 then N.UserDescription end) as ParticipationResidentDesc_R1a, 
    LU_R1b.DisplayCode AS ParticipationFamily_R1b, LU_R1b.UserDescription AS ParticipationFamilyDesc_R1b, 
    LU_R1c.DisplayCode AS ParticipationOther_R1c, LU_R1c.UserDescription AS ParticipationOtherDesc_R1c, 
    CRS_AssessFull2.AbstractID as zzAbstractLink
FROM     
    dbo.CRS_AssessFull2 with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile LU_R1c with (nolock) on dbo.CRS_AssessFull2.R1c = LU_R1c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_R1b with (nolock) on dbo.CRS_AssessFull2.R1b = LU_R1b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Q1c with (nolock) on dbo.CRS_AssessFull2.Q1c = LU_Q1c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_O2 with (nolock) on dbo.CRS_AssessFull2.O2 = LU_O2.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N5b with (nolock) on dbo.CRS_AssessFull2.N5b = LU_N5b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N5a with (nolock) on dbo.CRS_AssessFull2.N5a = LU_N5a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4l with (nolock) on dbo.CRS_AssessFull2.N4l = LU_N4l.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4k with (nolock) on dbo.CRS_AssessFull2.N4k = LU_N4k.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4j with (nolock) on dbo.CRS_AssessFull2.N4j = LU_N4j.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4I with (nolock) on dbo.CRS_AssessFull2.N4I = LU_N4I.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4h with (nolock) on dbo.CRS_AssessFull2.N4h = LU_N4h.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4g with (nolock) on dbo.CRS_AssessFull2.N4g = LU_N4g.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4f with (nolock) on dbo.CRS_AssessFull2.N4f = LU_N4f.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4e with (nolock) on dbo.CRS_AssessFull2.N4e = LU_N4e.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4d with (nolock) on dbo.CRS_AssessFull2.N4d = LU_N4d.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4c with (nolock) on dbo.CRS_AssessFull2.N4c = LU_N4c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4b with (nolock) on LU_N4b.Code = dbo.CRS_AssessFull2.N4b LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4a with (nolock) on dbo.CRS_AssessFull2.N4a = LU_N4a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N3d with (nolock) on dbo.CRS_AssessFull2.N3d = LU_N3d.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N3c with (nolock) on LU_N3c.Code = dbo.CRS_AssessFull2.N3c LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N3b with (nolock) on dbo.CRS_AssessFull2.N3b = LU_N3b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N3a with (nolock) on dbo.CRS_AssessFull2.N3a = LU_N3a.Code 
    cross join ( select top 1 DisplayCode, UserDescription from LU_YesNoSystem where code = 1 ) Y
    cross join ( select top 1 DisplayCode, UserDescription from LU_YesNoSystem where code = 2 ) N
    cross join ( select top 1 DisplayCode, UserDescription from LU_CodeFile where LookUpID = 1 ) Y1

/*
    dbo.LU_CodeFile LU_P2All with (nolock) on dbo.CRS_AssessFull2.P2All = LU_P2All.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N4All with (nolock) on LU_N4All.Code = dbo.CRS_AssessFull2.N4All LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N3All with (nolock) on dbo.CRS_AssessFull2.N3All = LU_N3All.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_L1All with (nolock) on dbo.CRS_AssessFull2.L1All = LU_L1All.Code

    dbo.LU_YesNoSystem LU_R1a with (nolock) on dbo.CRS_AssessFull2.R1a = LU_R1a.Code LEFT OUTER JOIN

    dbo.LU_YesNoSystem LU_Q1b with (nolock) on dbo.CRS_AssessFull2.Q1b = LU_Q1b.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_Q1a with (nolock) on dbo.CRS_AssessFull2.Q1a = LU_Q1a.Code LEFT OUTER JOIN

    dbo.LU_YesNoSystem LU_P9 with (nolock) on dbo.CRS_AssessFull2.P9 = LU_P9.Code LEFT OUTER JOIN

    dbo.LU_YesNoSystem LU_P2e with (nolock) on dbo.CRS_AssessFull2.P2e = LU_P2e.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_P2d with (nolock) on dbo.CRS_AssessFull2.P2d = LU_P2d.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_P2c with (nolock) on dbo.CRS_AssessFull2.P2c = LU_P2c.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_P2b with (nolock) on dbo.CRS_AssessFull2.P2b = LU_P2b.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_P2a with (nolock) on dbo.CRS_AssessFull2.P2a = LU_P2a.Code LEFT OUTER JOIN

    dbo.LU_YesNoSystem LU_M3 with (nolock) on dbo.CRS_AssessFull2.M3 = LU_M3.Code LEFT OUTER JOIN

    dbo.LU_YesNoSystem LU_L1f with (nolock) on dbo.CRS_AssessFull2.L1f = LU_L1f.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_L1e with (nolock) on dbo.CRS_AssessFull2.L1e = LU_L1e.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_L1d with (nolock) on dbo.CRS_AssessFull2.L1d = LU_L1d.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_L1c with (nolock) on dbo.CRS_AssessFull2.L1c = LU_L1c.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_L1b with (nolock) on dbo.CRS_AssessFull2.L1b = LU_L1b.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_L1a with (nolock) on dbo.CRS_AssessFull2.L1a = LU_L1a.Code LEFT OUTER JOIN
*/












' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_General_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE  VIEW [dbo].[MDS20_General_VR]
AS
SELECT
--Demographic
    dbo.CRS_Demographic.AbstractID AS zzAbstractLink, dbo.CRS_Demographic.LinkID AS zzLinkBackgroundID, 
    LU_AA8.DisplayCode AS ReasonAssessment_AA8, LU_AA8.CIHIValue AS AA8_CIHI, LU_AA8.UserDescription AS ReasonAssessmentDesc_AA8, 
    dbo.CRS_Demographic.AA1 AS URI_AA1, dbo.CRS_Demographic.ChartNumber AS HealthRecordNumber_A6a, 
    FixedChartNumber,
    
    AboriginalIdentityFirstNations_AA4a = (case CRS_Demographic.AA4a when 1 then Y.DisplayCode when 2 then N.DisplayCode end), 
    AboriginalIdentityFirstNationsDesc_AA4a = (case CRS_Demographic.AA4a when 1 then Y.UserDescription when 2 then N.UserDescription end), 
    AboriginalIdentityMetiis_AA4b = (case CRS_Demographic.AA4b when 1 then Y.DisplayCode when 2 then N.DisplayCode end), 
    AboriginalIdentityMetiisDesc_AA4b = (case CRS_Demographic.AA4b when 1 then Y.UserDescription when 2 then N.UserDescription end),  
    AboriginalIdentityInuit_AA4c = (case CRS_Demographic.AA4c when 1 then Y.DisplayCode when 2 then N.DisplayCode end), 
    AboriginalIdentityInuitDesc_AA4c = (case CRS_Demographic.AA4c when 1 then Y.UserDescription when 2 then N.UserDescription end), 

    dbo.CRS_Demographic.RegisterNumber AS HealthRegisterNumber_A6b, dbo.CRS_Demographic.AdmitDate AS AdmissionDate_AB1, 
    -- PR - 02377
    AttendingPhysician = LU_AttProvider.DisplayCode, AttendingPhysicianDesc = LU_AttProvider.UserDescription, 

    dbo.CRS_Demographic.Z7 AS ChangedDate_Z7, dbo.CRS_Demographic.A3 AS AssessmentDate_A3, 
    dbo.CRS_Demographic.NextAssessmentDate,
    dbo.CRS_Demographic.DischargeDate AS DischargeDate_R4, dbo.CRS_Demographic.AB1b AS ReEntryDate_AB1b, 
    dbo.CRS_Demographic.MaidenName, dbo.CRS_Demographic.LastName, dbo.CRS_Demographic.MiddleName, dbo.CRS_Demographic.FirstName, 
    dbo.LU_NurseArea.DisplayCode AS RoomUnit, dbo.LU_NurseArea.UserDescription AS RoomUnitDesc, dbo.CRS_Demographic.RoomNumber, 
    LU_Gender.DisplayCode AS Gender_AA2, LU_Gender.UserDescription AS GenderDesc_AA2, 
    dbo.CRS_Demographic.BirthDate AS Birthdate_AA3a, 
    (case when CRS_Demographic.BirthdateEstimated > 0 then Y1.DisplayCode end) as BirthdateEstimated_AA3b, 
    --(case when CRS_Demographic.BirthdateEstimated > 0 then Y1.UserDescription end) as BirthDateEstimatedDesc_AA3b, 

    dbo.CRS_Demographic.AA4a AS Treaty_band_AA4a, LU_MaritalStatus.DisplayCode AS MaritalStatus_A5, 
    LU_MaritalStatus.UserDescription AS MaritalStatusDesc_A5, dbo.CRS_Demographic.HealthCareNumber AS HealthCareNumber_AA5a, 
    dbo.LU_HCNProvince.DisplayCode AS HCNProvince_AA5b, dbo.LU_HCNProvince.UserDescription AS HCNProvinceDesc_AA5b, 
    dbo.H_InstitutionProfile.DisplayCode AS FacilityNumber_AA6, dbo.H_InstitutionProfile.UserDescription AS FacilityNumberDesc_AA6, 
    LU_AB2a.DisplayCode AS CareLevelFrom_AB2a, LU_AB2a.UserDescription AS CareLevelFromDesc_AB2a, 
    LU_AB2c.DisplayCode AS CareLevelFrom_AB2c, LU_AB2c.UserDescription AS CareLevelFromDesc_AB2c, 
    LU_Inst_From.DisplayCode AS FacilityFrom_AB2b, LU_Inst_From.UserDescription AS FacilityFromDesc_AB2b, 
    LU_R3a.DisplayCode AS CareLevelTo_R3a, LU_R3a.UserDescription AS CareLevelToDesc_R3a, 
    LU_Inst_To.DisplayCode AS FacilityTo_R3b, LU_Inst_To.UserDescription AS FacilityToDesc_R3b, 
	LU_R3c.DisplayCode AS COVID19Status_R3c, LU_R3c.UserDescription AS COVID19StatusDesc_R3c,
    -- PR - 02377
    dbo.CRS_Demographic.EncounterNumber, 

    LU_Hospital.DisplayCode as Hospital, LU_Hospital.UserDescription as HospitalDesc, 
    dbo.CRS_Demographic.HospitalAccountRecord,
    dbo.CRS_Demographic.IsCurrent, 
    --PR - 06321
    CRS_Demographic.BatchYear,
    BatchPeriod = LU_BatchPeriod.DisplayCode, --BatchPeriodDesc = LU_BatchPeriod.UserDescription, 
	CRS_Demographic.CIHIDateSent,
    LU_IsSubmited.DisplayCode AS IsSubmited, --LU_IsSubmited.UserDescription AS IsSubmitedDesc, 
    --(case when CRS_Demographic.IsSubmited > 0 then Y1.DisplayCode end) as IsSubmited, 
    --(case when CRS_Demographic.IsSubmited > 0 then Y1.UserDescription end) as IsSubmitedDesc, 

    LU_IsValidated.DisplayCode AS IsValidated, LU_IsValidated.UserDescription AS IsValidatedDesc, LU_IsCompleted.DisplayCode AS IsCompleted, 
    LU_IsCompleted.UserDescription AS IsCompletedDesc, LU_IsDeleted.DisplayCode AS IsDeleted, --LU_IsDeleted.UserDescription AS IsDeletedDesc, 
    LU_CIHICorrect.DisplayCode AS IsCorrected, LU_CIHICorrect.UserDescription AS IsCorrectedDesc, 

    LU_Z1.DisplayCode AS RecordType_Z1, LU_Z1.UserDescription AS RecordTypeDesc_Z1, 

    SubmissionType_Y3 = LU_Y3.DisplayCode, SubmissionTypeDesc_Y3 = LU_Y3.UserDescription, 

    -- PR - 02377
    MISCode = LU_MISCode.DisplayCode, MISCodeDesc = LU_MISCode.UserDescription, 
    -- PR - 02377
    NursingArea = LU_AdmitNurse.DisplayCode, NursingAreaDesc = LU_AdmitNurse.UserDescription, 

    dbo.LU_Site.DisplayCode AS SiteNumber, --dbo.LU_Site.UserDescription AS SiteNumberDesc, 
    LU_Coder.DisplayCode AS CoderNumber, LU_Coder.UserDescription AS CoderNumberDesc, 
    dbo.CRS_Demographic.HCNVersion, 
    dbo.CRS_Demographic.ZA6b AS NewHealthRegisterNumber_ZA6b, dbo.CRS_Demographic.ZAB1 AS NewAdmissionDate_ZAB1, 
    dbo.CRS_Demographic.ZR4 AS NewDischargeDate_ZR4, dbo.CRS_Demographic.InterfaceDate, dbo.CRS_Demographic.InterfaceTime, 
    U_InterfaceCoder.DisplayCode AS InterfaceCoder, U_InterfaceCoder.UserDescription AS InterfaceCoderDesc, dbo.CRS_Demographic.InputDate, 
    dbo.CRS_Demographic.InputTime, U_DataEntryCoder.DisplayCode AS DataEntryCoder, U_DataEntryCoder.UserDescription AS DataEntryCoderDesc, 
    dbo.CRS_Demographic.FinishDate, dbo.CRS_Demographic.FinishTime, 
    -- PR - 02377
    ReferringProvider = LU_RefProvider.DisplayCode, ReferringProviderDesc = LU_RefProvider.UserDescription, 
    --PR-02377
    dbo.CRS_Demographic.SecondChartRegNumber as SecondChartRegisterNumber,

    LU_Secret.DisplayCode AS Secret, LU_Secret.UserDescription AS SecretDesc, 
    dbo.CRS_Demographic.TSIDate, dbo.CRS_Demographic.TSITime, U_TSICoder.DisplayCode AS TSICoder, 
    U_TSICoder.UserDescription AS TSICoderDesc, 
--Admission
    --LU_AB3.DisplayCode AS LivedAlone_AB3, LU_AB3.UserDescription AS LivedAloneDesc_AB3, 
    (case dbo.CRS_Admission.AB3 when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as LivedAlone_AB3, 
    (case dbo.CRS_Admission.AB3 when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as LivedAloneDesc_AB3, 

    dbo.CRS_Admission.AB4 AS PostalCode_AB4,
--       (SELECT     TOP 1 UserDescription
--         FROM          LU_PostalCode
--         WHERE      InterfaceIn = AB4) AS PostalCodeDesc_AB4, 

      -- ED - 01682
      dbo.GetPostalDescription(isnull(dbo.CRS_Admission.AB4, ''''), isnull(dbo.CRS_Demographic.DischargeDate, dbo.CRS_Demographic.AdmitDate)) AS PostalCodeDesc_AB4, -- ED - 01682
      LU_ResidenceCode.DisplayCode AS ResidenceCode, LU_ResidenceCode.UserDescription AS ResidenceCodeDesc, 
    (case when CRS_Admission.AB5ALL > 0 then Y1.DisplayCode end) as ResidentialHistory_None_AB5f, 
    --(case when CRS_Admission.AB5ALL > 0 then Y1.UserDescription end) as ResidentialHistory_N_Desc_AB5f, 


--     LU_AB5a.DisplayCode AS ResidentialHistory_This_AB5a, 
--     LU_AB5a.UserDescription AS ResidentialHistory_T_Desc_AB5a, 
--     LU_AB5b.DisplayCode AS ResidentialHistorySimilar_AB5b, 
--     LU_AB5b.UserDescription AS ResidentialHistory_S_Desc_AB5b, 
--     LU_AB5c.DisplayCode AS ResidentialHistory_Other_AB5c, 
--     LU_AB5c.UserDescription AS ResidentialHistory_O_Desc_AB5c, 
--     LU_AB5d.DisplayCode AS ResidentialHistory_Psych_AB5d, 
--     LU_AB5d.UserDescription AS ResidentialHistory_P_Desc_AB5d, 
--     LU_AB5e.DisplayCode AS ResidentialHistory_Dev_AB5e, 
--     LU_AB5e.UserDescription AS ResidentialHistoryDevDesc_AB5e, 
    (case dbo.CRS_Admission.AB5a when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as ResidentialHistory_This_AB5a, 
    --(case dbo.CRS_Admission.AB5a when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as ResidentialHistory_T_Desc_AB5a, 
    (case dbo.CRS_Admission.AB5b when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as ResidentialHistorySimilar_AB5b, 
    --(case dbo.CRS_Admission.AB5b when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as ResidentialHistory_S_Desc_AB5b, 
    (case dbo.CRS_Admission.AB5c when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as ResidentialHistory_Other_AB5c, 
    --(case dbo.CRS_Admission.AB5c when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as ResidentialHistory_O_Desc_AB5c, 
    (case dbo.CRS_Admission.AB5d when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as ResidentialHistory_Psych_AB5d, 
    --(case dbo.CRS_Admission.AB5d when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as ResidentialHistory_P_Desc_AB5d, 
    (case dbo.CRS_Admission.AB5e when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as ResidentialHistory_Dev_AB5e, 
    --(case dbo.CRS_Admission.AB5e when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as ResidentialHistoryDevDesc_AB5e, 

    LU_AB7.DisplayCode AS Education_AB7, 

    LU_AB7.UserDescription AS EducationDesc_AB7, LU_AB8.DisplayCode AS Language_AB8, LU_AB8.UserDescription AS LanguageDesc_AB8, 

    (case CRS_Admission.AB9 when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as MentalHealthHistory_AB9, 
    (case CRS_Admission.AB9 when 1 then Y.UserDescription when 2 then N.UserDescription end) as MentalHealthHistoryDesc_AB9, 

    (case CRS_Admission.AB10a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ConditionNA_AB10a, 
    (case CRS_Admission.AB10a when 1 then Y.UserDescription when 2 then N.UserDescription end) as ConditionNADesc_AB10a, 

--     LU_AB10b.DisplayCode AS ConditionDwons_AB10b, LU_AB10b.UserDescription AS ConditionDwonsDesc_AB10b, 
--     LU_AB10c.DisplayCode AS ConditionAutism_AB10c, LU_AB10c.UserDescription AS ConditionAutismDesc_AB10c, 
--     LU_AB10d.DisplayCode AS ConditionEpilepsy_AB10d, LU_AB10d.UserDescription AS ConditionEpilepsyDesc_AB10d, 
--     LU_AB10e.DisplayCode AS ConditionOther_AB10e, LU_AB10e.UserDescription AS ConditionOtherDesc_AB10e, 
--     LU_AB10f.DisplayCode AS ConditionDev_AB10f, LU_AB10f.UserDescription AS ConditionDevDesc_AB10f, 

    (case dbo.CRS_Admission.AB10b when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ConditionDwons_AB10b, 
    (case dbo.CRS_Admission.AB10b when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ConditionDwonsDesc_AB10b, 
    (case dbo.CRS_Admission.AB10c when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ConditionAutism_AB10c, 
    (case dbo.CRS_Admission.AB10c when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ConditionAutismDesc_AB10c, 
    (case dbo.CRS_Admission.AB10d when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ConditionEpilepsy_AB10d, 
    (case dbo.CRS_Admission.AB10d when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ConditionEpilepsyDesc_AB10d, 
    (case dbo.CRS_Admission.AB10e when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ConditionOther_AB10e, 
    (case dbo.CRS_Admission.AB10e when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ConditionOtherDesc_AB10e, 
    (case dbo.CRS_Admission.AB10f when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ConditionDev_AB10f, 
    (case dbo.CRS_Admission.AB10f when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ConditionDevDesc_AB10f, 

    (case when CRS_Admission.AB10All > 0 then Y1.DisplayCode end) as ConditionNone_AB10g, 
    --(case when CRS_Admission.AB10All > 0 then Y1.UserDescription end) as ConditionNoneDesc_AB10g, 
    DecisionMakerForPersonalCare_A11a = LU_A11a.DisplayCode, DecisionMakerForPersonalCareDesc_A11a = LU_A11a.UserDescription, 
    DecisionMakerForProperty_A11b = LU_A11b.DisplayCode,     DecisionMakerForPropertyDesc_A11b = LU_A11b.UserDescription, 
    AdvanceDirectivesResuscitating_A12a = LU_A12a.DisplayCode, AdvanceDirectivesResuscitatingDesc_A12a = LU_A12a.UserDescription, 
    AdvanceDirectivesHospitalizing_A12b = LU_A12b.DisplayCode, AdvanceDirectivesHospitalizingDesc_A12b = LU_A12b.UserDescription, 

--     LU_AC1a.DisplayCode AS DailyEventLate_AC1a, LU_AC1a.UserDescription AS DailyEventLateDesc_AC1a, 
--     LU_AC1b.DisplayCode AS DailyEventNap_AC1b, LU_AC1b.UserDescription AS DailyEventNapDesc_AC1b, 
--     LU_AC1c.DisplayCode AS DailyEventGoOut_AC1c, LU_AC1c.UserDescription AS DailyEventGoOutDesc_AC1c, 
--     LU_AC1d.UserDescription AS DailyEventBusy_AC1d, LU_AC1d.DisplayCode AS DailyEventBusyDesc_AC1d, 
--     LU_AC1e.DisplayCode AS DailyEventAlone_AC1e, LU_AC1e.UserDescription AS DailyEventAloneDesc_AC1e, 
--     LU_AC1f.DisplayCode AS DailyEventIndoor_AC1f, LU_AC1f.UserDescription AS DailyEventIndoorDesc_AC1f, 
--     LU_AC1g.DisplayCode AS DailyEventSmokes_AC1g, LU_AC1g.UserDescription AS DailyEventSmokesDesc_AC1g, 
--     LU_AC1i.DisplayCode AS EatingDistinct_AC1i, LU_AC1i.UserDescription AS EatingDistinctDesc_AC1i, LU_AC1j.DisplayCode AS EatingBetween_AC1j, 
--     LU_AC1j.UserDescription AS EatingBetweenDesc_AC1j, LU_AC1k.DisplayCode AS EatingWAlcoholicBev_AC1k, 
--     LU_AC1k.UserDescription AS EatingWAlcoholicBevDesc_AC1k, LU_AC1m.DisplayCode AS ADL_InBedClothes_AC1m, 
--     LU_AC1m.UserDescription AS ADL_InBedClothesDesc_AC1m, LU_AC1n.DisplayCode AS ADL_WakensToilet_AC1n, 
--     LU_AC1n.UserDescription AS ADL_WakensToiletDesc_AC1n, LU_AC1o.DisplayCode AS ADL_IrregularBM_AC1o, 
--     LU_AC1o.UserDescription AS ADL_IrregularBMDesc_AC1o, LU_AC1p.DisplayCode AS ADL_Shower_AC1p, 
--     LU_AC1p.UserDescription AS ADL_ShowerDesc_AC1p, LU_AC1q.DisplayCode AS ADL_BathPM_AC1q, 
--     LU_AC1q.UserDescription AS ADL_BathPMDesc_AC1q, LU_AC1s.DisplayCode AS InvolveContact_AC1s, 
--     LU_AC1s.UserDescription AS InvolveContactDesc_AC1s, LU_AC1t.DisplayCode AS InvolveAttend_AC1t, 
--     LU_AC1t.UserDescription AS InvolveAttendDesc_AC1t, LU_AC1u.DisplayCode AS InvolveFaith_AC1u, 
--     LU_AC1u.UserDescription AS InvolveFaithDesc_AC1u, LU_AC1v.DisplayCode AS InvolveAnimal_AC1v, 
--     LU_AC1v.UserDescription AS InvolveAnimalDesc_AC1v, LU_AC1w.DisplayCode AS InvolveGroup_AC1w, 
--     LU_AC1w.UserDescription AS InvolveGroupDesc_AC1w, 
    (case dbo.CRS_Admission.AC1a when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as DailyEventLate_AC1a, 
    (case dbo.CRS_Admission.AC1a when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as DailyEventLateDesc_AC1a, 
    (case dbo.CRS_Admission.AC1b when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as DailyEventNap_AC1b, 
    (case dbo.CRS_Admission.AC1b when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as DailyEventNapDesc_AC1b, 
    (case dbo.CRS_Admission.AC1c when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as DailyEventGoOut_AC1c, 
    (case dbo.CRS_Admission.AC1c when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as DailyEventGoOutDesc_AC1c, 
    (case dbo.CRS_Admission.AC1d when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as DailyEventBusy_AC1d, 
    (case dbo.CRS_Admission.AC1d when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as DailyEventBusyDesc_AC1d, 
    (case dbo.CRS_Admission.AC1e when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as DailyEventAlone_AC1e, 
    (case dbo.CRS_Admission.AC1e when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as DailyEventAloneDesc_AC1e, 
    (case dbo.CRS_Admission.AC1f when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as DailyEventIndoor_AC1f, 
    (case dbo.CRS_Admission.AC1f when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as DailyEventIndoorDesc_AC1f, 
    (case dbo.CRS_Admission.AC1g when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as DailyEventSmokes_AC1g, 
    (case dbo.CRS_Admission.AC1g when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as DailyEventSmokesDesc_AC1g, 
    (case dbo.CRS_Admission.AC1i when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as EatingDistinct_AC1i, 
    (case dbo.CRS_Admission.AC1i when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as EatingDistinctDesc_AC1i, 
    (case dbo.CRS_Admission.AC1j when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as EatingBetween_AC1j, 
    (case dbo.CRS_Admission.AC1j when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as EatingBetweenDesc_AC1j, 
    (case dbo.CRS_Admission.AC1k when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as EatingWAlcoholicBev_AC1k, 
    (case dbo.CRS_Admission.AC1k when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as EatingWAlcoholicBevDesc_AC1k, 
    (case dbo.CRS_Admission.AC1m when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as ADL_InBedClothes_AC1m, 
    (case dbo.CRS_Admission.AC1m when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as ADL_InBedClothesDesc_AC1m, 
    (case dbo.CRS_Admission.AC1n when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as ADL_WakensToilet_AC1n, 
    (case dbo.CRS_Admission.AC1n when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as ADL_WakensToiletDesc_AC1n, 
    (case dbo.CRS_Admission.AC1o when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as ADL_IrregularBM_AC1o, 
    (case dbo.CRS_Admission.AC1o when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as ADL_IrregularBMDesc_AC1o, 
    (case dbo.CRS_Admission.AC1p when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as ADL_Shower_AC1p, 
    (case dbo.CRS_Admission.AC1p when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as ADL_ShowerDesc_AC1p, 
    (case dbo.CRS_Admission.AC1q when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as ADL_BathPM_AC1q, 
    (case dbo.CRS_Admission.AC1q when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as ADL_BathPMDesc_AC1q, 
    (case dbo.CRS_Admission.AC1s when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as InvolveContact_AC1s, 
    (case dbo.CRS_Admission.AC1s when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as InvolveContactDesc_AC1s, 
    (case dbo.CRS_Admission.AC1t when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as InvolveAttend_AC1t, 
    (case dbo.CRS_Admission.AC1t when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as InvolveAttendDesc_AC1t, 
    (case dbo.CRS_Admission.AC1u when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as InvolveFaith_AC1u, 
    (case dbo.CRS_Admission.AC1u when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as InvolveFaithDesc_AC1u, 
    (case dbo.CRS_Admission.AC1v when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as InvolveAnimal_AC1v, 
    (case dbo.CRS_Admission.AC1v when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as InvolveAnimalDesc_AC1v, 
    (case dbo.CRS_Admission.AC1w when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as InvolveGroup_AC1w, 
    (case dbo.CRS_Admission.AC1w when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as InvolveGroupDesc_AC1w, 

--Diagnosis
    I3a AS Diagnosis_I3a, I3b AS Diagnosis_I3b, I3c AS Diagnosis_I3c, I3d AS Diagnosis_I3d, 
    I3e AS Diagnosis_I3e, I3f AS Diagnosis_I3f,
--Full1
    (case CRS_AssessFull1.A7a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Provincial_A7a, 
    (case CRS_AssessFull1.A7a when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_ProvincialDesc_A7a, 
    (case CRS_AssessFull1.A7b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Other_Prov_A7b, 
    (case CRS_AssessFull1.A7b when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_Other_ProvDesc_A7b, 
    (case CRS_AssessFull1.A7c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Federal_V_A7c, 
    (case CRS_AssessFull1.A7c when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_Federal_VDesc_A7c, 
    (case CRS_AssessFull1.A7d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Federal_F_A7d, 
    (case CRS_AssessFull1.A7d when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_Federal_FDesc_A7d, 
    (case CRS_AssessFull1.A7e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Federal_O_A7e, 
    (case CRS_AssessFull1.A7e when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_Federal_ODesc_A7e, 
    (case CRS_AssessFull1.A7f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_WCB_A7f, 
    (case CRS_AssessFull1.A7f when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_WCBDesc_A7f, 
    (case CRS_AssessFull1.A7g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Insurance_A7g, 
    (case CRS_AssessFull1.A7g when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_InsuranceDesc_A7g, 
    (case CRS_AssessFull1.A7h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Public_A7h, 
    (case CRS_AssessFull1.A7h when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_PublicDesc_A7h, 
    (case CRS_AssessFull1.A7I when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Self_A7i, 
    (case CRS_AssessFull1.A7I when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_SelfDesc_A7i, 
    (case CRS_AssessFull1.A7j when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Other_Country_A7j, 
    (case CRS_AssessFull1.A7j when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_Other_CountryDesc_A7j, 
    (case CRS_AssessFull1.A7k when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as RFP_Unkown_A7k, 
    (case CRS_AssessFull1.A7k when 1 then Y.UserDescription when 2 then N.UserDescription end) as RFP_UnkownDesc_A7k, 

    LU_C1.DisplayCode AS Hearing_C1, LU_C1.UserDescription AS HearingDesc_C1, 

--     LU_C2a.DisplayCode AS CommAidReg_C2a, LU_C2a.UserDescription AS CommAidRegDesc_C2a, 
--     LU_C2b.DisplayCode AS CommAidNoReg_C2b, LU_C2b.UserDescription AS CommAidNoRegDesc_C2b, 
--     LU_C2c.DisplayCode AS CommOther_C2c, LU_C2c.UserDescription AS CommOtherDesc_C2c, 
    (case dbo.CRS_AssessFull1.C2a when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as CommAidReg_C2a, 
    (case dbo.CRS_AssessFull1.C2a when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as CommAidRegDesc_C2a, 
    (case dbo.CRS_AssessFull1.C2b when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as CommAidNoReg_C2b, 
    (case dbo.CRS_AssessFull1.C2b when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as CommAidNoRegDesc_C2b, 
    (case dbo.CRS_AssessFull1.C2c when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as CommOther_C2c, 
    (case dbo.CRS_AssessFull1.C2c when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as CommOtherDesc_C2c, 

    (case when CRS_AssessFull1.C2All > 0 then Y1.DisplayCode end) as CommNone_C2d, 
    --(case when CRS_AssessFull1.C2All > 0 then Y1.UserDescription end) as CommNoneDesc_C2d, 

--     LU_C3a.DisplayCode AS ExpressSpeech_C3a, LU_C3a.UserDescription AS ExpressSpeechDesc_C3a, 
--     LU_C3b.DisplayCode AS ExpressWrite_C3b,  LU_C3b.UserDescription AS ExpressWriteDesc_C3b, 
--     LU_C3c.DisplayCode AS ExpressLanguage_C3c, LU_C3c.UserDescription AS ExpressLanguageDesc_C3c, 
--     LU_C3d.DisplayCode AS ExpressSigns_C3d, LU_C3d.UserDescription AS ExpressSignsDesc_C3d, 
--     LU_C3e.DisplayCode AS ExpressBoard_C3e, LU_C3e.UserDescription AS ExpressBoardDesc_C3e, 
--     LU_C3f.DisplayCode AS ExpressOther_C3f, LU_C3f.UserDescription AS ExpressOtherDesc_C3f, 
    (case dbo.CRS_AssessFull1.C3a when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ExpressSpeech_C3a, 
    (case dbo.CRS_AssessFull1.C3a when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ExpressSpeechDesc_C3a, 
    (case dbo.CRS_AssessFull1.C3b when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ExpressWrite_C3b, 
    (case dbo.CRS_AssessFull1.C3b when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ExpressWriteDesc_C3b, 
    (case dbo.CRS_AssessFull1.C3c when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ExpressLanguage_C3c, 
    (case dbo.CRS_AssessFull1.C3c when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ExpressLanguageDesc_C3c, 
    (case dbo.CRS_AssessFull1.C3d when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ExpressSigns_C3d, 
    (case dbo.CRS_AssessFull1.C3d when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ExpressSignsDesc_C3d, 
    (case dbo.CRS_AssessFull1.C3e when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ExpressBoard_C3e, 
    (case dbo.CRS_AssessFull1.C3e when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ExpressBoardDesc_C3e, 
    (case dbo.CRS_AssessFull1.C3f when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ExpressOther_C3f, 
    (case dbo.CRS_AssessFull1.C3f when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ExpressOtherDesc_C3f, 

    (case when CRS_AssessFull1.C3All > 0 then Y1.DisplayCode end) as ExpressNone_C3g, 
    --(case when CRS_AssessFull1.C3All > 0 then Y1.UserDescription end) as ExpressNoneDesc_C3g, 

    LU_C5.DisplayCode AS SpeechClarity_C5, LU_C5.UserDescription AS SpeechClarityDesc_C5, 

    LU_D1.DisplayCode AS Vision_D1, LU_D1.UserDescription AS VisionDesc_D1, 
--     LU_D2a.DisplayCode AS SideVision_D2a, LU_D2a.UserDescription AS SideVisionDesc_D2a, 
--     LU_D2b.DisplayCode AS HaloVision_D2b, LU_D2b.UserDescription AS HaloVisionDesc_D2b, 
--     LU_D3.DisplayCode AS VisualApp_D3, LU_D3.UserDescription AS VisualAppDesc_D3, 
    (case dbo.CRS_AssessFull1.D2a when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as SideVision_D2a, 
    (case dbo.CRS_AssessFull1.D2a when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as SideVisionDesc_D2a, 
    (case dbo.CRS_AssessFull1.D2b when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as HaloVision_D2b, 
    (case dbo.CRS_AssessFull1.D2b when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as HaloVisionDesc_D2b, 
    (case dbo.CRS_AssessFull1.D3 when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as VisualApp_D3, 
    (case dbo.CRS_AssessFull1.D3 when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as VisualAppDesc_D3, 

--     LU_F2a.DisplayCode AS UnsettledStaff_F2a, LU_F2a.UserDescription AS UnsettledStaffDesc_F2a, 
--     LU_F2b.DisplayCode AS UnsettledRoommate_F2b, LU_F2b.UserDescription AS UnsettledRoommateDesc_F2b, 
--     LU_F2c.DisplayCode AS UnsettledResident_F2c, LU_F2c.UserDescription AS UnsettledResidentDesc_F2c, 
--     LU_F2d.DisplayCode AS UnsettledFamily_F2d, LU_F2d.UserDescription AS UnsettledFamilyDesc_F2d, 
--     LU_F2e.DisplayCode AS UnsettledAbsence_F2e, LU_F2e.UserDescription AS UnsettledAbsenceDesc_F2e, 
--     LU_F2f.DisplayCode AS UnsettledLoss_F2f, LU_F2f.UserDescription AS UnsettledLossDesc_F2f, 
--     LU_F2g.DisplayCode AS UnsettledChange_F2g, LU_F2g.UserDescription AS UnsettledChangeDesc_F2g, 
    (case dbo.CRS_AssessFull1.F2a when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as UnsettledStaff_F2a, 
    (case dbo.CRS_AssessFull1.F2a when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as UnsettledStaffDesc_F2a, 
    (case dbo.CRS_AssessFull1.F2b when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as UnsettledRoommate_F2b, 
    (case dbo.CRS_AssessFull1.F2b when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as UnsettledRoommateDesc_F2b, 
    (case dbo.CRS_AssessFull1.F2c when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as UnsettledResident_F2c, 
    (case dbo.CRS_AssessFull1.F2c when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as UnsettledResidentDesc_F2c, 
    (case dbo.CRS_AssessFull1.F2d when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as UnsettledFamily_F2d, 
    (case dbo.CRS_AssessFull1.F2d when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as UnsettledFamilyDesc_F2d, 
    (case dbo.CRS_AssessFull1.F2e when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as UnsettledAbsence_F2e, 
    (case dbo.CRS_AssessFull1.F2e when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as UnsettledAbsenceDesc_F2e, 
    (case dbo.CRS_AssessFull1.F2f when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as UnsettledLoss_F2f, 
    (case dbo.CRS_AssessFull1.F2f when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as UnsettledLossDesc_F2f, 
    (case dbo.CRS_AssessFull1.F2g when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as UnsettledChange_F2g, 
    (case dbo.CRS_AssessFull1.F2g when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as UnsettledChangeDesc_F2g, 

    (case when CRS_AssessFull1.F2All > 0 then Y1.DisplayCode end) as UnsettledNone_F2h, 
    --(case when CRS_AssessFull1.F2All > 0 then Y1.UserDescription end) as UnsettledNoneDesc_F2h, 

    LU_F3a.DisplayCode AS PastRoleIden_F3a, LU_F3a.UserDescription AS PastRoleIdenDesc_F3a, 
    LU_F3b.DisplayCode AS PastRoleExpress_F3b, LU_F3b.UserDescription AS PastRoleExpressDesc_F3b, 
    LU_F3c.DisplayCode AS PastRolePerceive_F3c, LU_F3c.UserDescription AS PastRolePerceiveDesc_F3c, 

    (case CRS_AssessFull1.G5a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as LocomotionWalker_G5a, 
    (case CRS_AssessFull1.G5a when 1 then Y.UserDescription when 2 then N.UserDescription end) as LocomotionWalkerDesc_G5a, 
    (case CRS_AssessFull1.G5b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as LocomotionWheelSelf_G5b, 
    (case CRS_AssessFull1.G5b when 1 then Y.UserDescription when 2 then N.UserDescription end) as LocomotionWheelSelfDesc_G5b, 
    (case CRS_AssessFull1.G5c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as LocomotionWheelOther_G5c, 
    (case CRS_AssessFull1.G5c when 1 then Y.UserDescription when 2 then N.UserDescription end) as LocomotionWheelOtherDesc_G5c, 
    (case CRS_AssessFull1.G5d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as LocomotionWheelChair_G5d, 
    (case CRS_AssessFull1.G5d when 1 then Y.UserDescription when 2 then N.UserDescription end) as LocomotionWheelChairDesc_G5d, 
    (case when CRS_AssessFull1.G5All > 0 then Y1.DisplayCode end) as LocomotionNone_G5e, 
    --(case when CRS_AssessFull1.G5All > 0 then Y1.UserDescription end) as LocomotionNoneDesc_G5e, 

    (case CRS_AssessFull1.G8a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ADL_Resident_G8a, 
    (case CRS_AssessFull1.G8a when 1 then Y.UserDescription when 2 then N.UserDescription end) as ADL_ResidentDesc_G8a, 
    (case CRS_AssessFull1.G8b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ADL_Staff_G8b, 
    (case CRS_AssessFull1.G8b when 1 then Y.UserDescription when 2 then N.UserDescription end) as ADL_StaffDesc_G8b, 
    (case CRS_AssessFull1.G8c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ADL_Slow_G8c, 
    (case CRS_AssessFull1.G8c when 1 then Y.UserDescription when 2 then N.UserDescription end) as ADL_SlowDesc_G8c, 
    (case CRS_AssessFull1.G8d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ADL_Diff_G8d, 
    (case CRS_AssessFull1.G8d when 1 then Y.UserDescription when 2 then N.UserDescription end) as ADL_DiffDesc_G8d, 
    (case when CRS_AssessFull1.G8All > 0 then Y1.DisplayCode end) as ADL_None_G8e, 
    --(case when CRS_AssessFull1.G8All > 0 then Y1.UserDescription end) as ADL_NoneDesc_G8e, 

--     LU_J3a.DisplayCode AS PainSiteBack_J3a, LU_J3a.UserDescription AS PainSiteBackDesc_J3a, 
--     LU_J3b.DisplayCode AS PainSiteBone_J3b, LU_J3b.UserDescription AS PainSiteBoneDesc_J3b, 
--     LU_J3c.DisplayCode AS PainSiteChest_J3c, LU_J3c.UserDescription AS PainSiteChestDesc_J3c, 
--     LU_J3d.DisplayCode AS PainSiteHead_J3d, LU_J3d.UserDescription AS PainSiteHeadDesc_J3d, 
--     LU_J3e.DisplayCode AS PainSiteHip_J3e, LU_J3e.UserDescription AS PainSiteHipDesc_J3e, 
--     LU_J3f.DisplayCode AS PainSiteIncision_J3f, LU_J3f.UserDescription AS PainSiteIncisionDesc_J3f, 
--     LU_J3g.DisplayCode AS PainSiteJoint_J3g, LU_J3g.UserDescription AS PainSiteJointDesc_J3g, 
--     LU_J3h.DisplayCode AS PainSiteTissue_J3h, LU_J3h.UserDescription AS PainSiteTissueDesc_J3h, 
--     LU_J3I.DisplayCode AS PainSiteStomach_J3i, LU_J3I.UserDescription AS PainSiteStomachDesc_J3i, 
--     LU_J3j.DisplayCode AS PainSiteOther_J3j, LU_J3j.UserDescription AS PainSiteOtherDesc_J3j, 
    (case dbo.CRS_AssessFull1.J3a when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as PainSiteBack_J3a, 
    (case dbo.CRS_AssessFull1.J3a when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as PainSiteBackDesc_J3a, 
    (case dbo.CRS_AssessFull1.J3b when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as PainSiteBone_J3b, 
    (case dbo.CRS_AssessFull1.J3b when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as PainSiteBoneDesc_J3b, 
    (case dbo.CRS_AssessFull1.J3c when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as PainSiteChest_J3c, 
    (case dbo.CRS_AssessFull1.J3c when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as PainSiteChestDesc_J3c, 
    (case dbo.CRS_AssessFull1.J3d when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as PainSiteHead_J3d, 
    (case dbo.CRS_AssessFull1.J3d when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as PainSiteHeadDesc_J3d, 
    (case dbo.CRS_AssessFull1.J3e when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as PainSiteHip_J3e, 
    (case dbo.CRS_AssessFull1.J3e when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as PainSiteHipDesc_J3e, 
    (case dbo.CRS_AssessFull1.J3f when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as PainSiteIncision_J3f, 
    (case dbo.CRS_AssessFull1.J3f when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as PainSiteIncisionDesc_J3f, 
    (case dbo.CRS_AssessFull1.J3g when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as PainSiteJoint_J3g, 
    (case dbo.CRS_AssessFull1.J3g when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as PainSiteJointDesc_J3g, 
    (case dbo.CRS_AssessFull1.J3h when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as PainSiteTissue_J3h, 
    (case dbo.CRS_AssessFull1.J3h when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as PainSiteTissueDesc_J3h, 
    (case dbo.CRS_AssessFull1.J3i when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as PainSiteStomach_J3i, 
    (case dbo.CRS_AssessFull1.J3i when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as PainSiteStomachDesc_J3i, 
    (case dbo.CRS_AssessFull1.J3j when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as PainSiteOther_J3j, 
    (case dbo.CRS_AssessFull1.J3j when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as PainSiteOtherDesc_J3j, 

--Full2
    (case CRS_AssessFull2.L1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as OralDebris_L1a, 
    (case CRS_AssessFull2.L1a when 1 then Y.UserDescription when 2 then N.UserDescription end) as OralDebrisDesc_L1a, 
    (case CRS_AssessFull2.L1b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as OralDentures_L1b, 
    (case CRS_AssessFull2.L1b when 1 then Y.UserDescription when 2 then N.UserDescription end) as OralDenturesDesc_L1b, 
    (case CRS_AssessFull2.L1c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as OralLost_L1c, 
    (case CRS_AssessFull2.L1c when 1 then Y.UserDescription when 2 then N.UserDescription end) as OralLostDesc_L1c, 
    (case CRS_AssessFull2.L1d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as OralBroken_L1d, 
    (case CRS_AssessFull2.L1d when 1 then Y.UserDescription when 2 then N.UserDescription end) as OralBrokenDesc_L1d, 
    (case CRS_AssessFull2.L1e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as OralGum_L1e, 
    (case CRS_AssessFull2.L1e when 1 then Y.UserDescription when 2 then N.UserDescription end) as OralGumDesc_L1e, 
    (case CRS_AssessFull2.L1f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as OralCleaning_L1f, 
    (case CRS_AssessFull2.L1f when 1 then Y.UserDescription when 2 then N.UserDescription end) as OralCleaningDesc_L1f, 
    (case when CRS_AssessFull2.L1All > 0 then Y1.DisplayCode end) as OralNone_L1g, 
    --(case when CRS_AssessFull2.L1All > 0 then Y1.UserDescription end) as OralNoneDesc_L1g, 

    (case CRS_AssessFull2.M3 when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ResolveUlcers_M3, 
    (case CRS_AssessFull2.M3 when 1 then Y.UserDescription when 2 then N.UserDescription end) as ResolveUlcersDesc_M3, 

--     LU_N3a.DisplayCode AS ActSetOwn_N3a, LU_N3a.UserDescription AS ActSetOwnDesc_N3a, 
--     LU_N3b.DisplayCode AS ActSetDay_N3b, LU_N3b.UserDescription AS ActSetDayDesc_N3b, 
--     LU_N3c.DisplayCode AS ActSetInside_N3c, LU_N3c.UserDescription AS ActSetInsideDesc_N3c, 
--     LU_N3d.DisplayCode AS ActSetOutside_N3d, LU_N3d.UserDescription AS ActSetOutsideDesc_N3d, 
    (case dbo.CRS_AssessFull2.N3a when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ActSetOwn_N3a, 
    (case dbo.CRS_AssessFull2.N3a when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ActSetOwnDesc_N3a, 
    (case dbo.CRS_AssessFull2.N3b when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ActSetDay_N3b, 
    (case dbo.CRS_AssessFull2.N3b when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ActSetDayDesc_N3b, 
    (case dbo.CRS_AssessFull2.N3c when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ActSetInside_N3c, 
    (case dbo.CRS_AssessFull2.N3c when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ActSetInsideDesc_N3c, 
    (case dbo.CRS_AssessFull2.N3d when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ActSetOutside_N3d, 
    (case dbo.CRS_AssessFull2.N3d when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ActSetOutsideDesc_N3d, 

    (case when CRS_AssessFull2.N3All > 0 then Y1.DisplayCode end) as ActSetNone_N3e, 
    --(case when CRS_AssessFull2.N3All > 0 then Y1.UserDescription end) as ActSetNoneDesc_N3e, 

--     LU_N4a.DisplayCode AS ActPreferCards_N4a, LU_N4a.UserDescription AS ActPreferCardsDesc_N4a, 
--     LU_N4b.DisplayCode AS ActPreferCrafts_N4b, LU_N4b.UserDescription AS ActPreferCraftsDesc_N4b, 
--     LU_N4c.DisplayCode AS ActPreferSports_N4c, LU_N4c.UserDescription AS ActPreferSportsDesc_N4c, 
--     LU_N4d.DisplayCode AS ActPreferMusic_N4d, LU_N4d.UserDescription AS ActPreferMusicDesc_N4d, 
--     LU_N4e.DisplayCode AS ActPreferReading_N4e, LU_N4e.UserDescription AS ActPreferReadingDesc_N4e, 
--     LU_N4f.DisplayCode AS ActPreferReligious_N4f, LU_N4f.UserDescription AS ActPreferReligiousDesc_N4f, 
--     LU_N4g.DisplayCode AS ActPreferShopping_N4g, LU_N4g.UserDescription AS ActPreferShoppingDesc_N4g, 
--     LU_N4h.DisplayCode AS ActPreferWalk_N4h, LU_N4h.UserDescription AS ActPreferWalkDesc_N4h, 
--     LU_N4I.DisplayCode AS ActPreferTV_N4i, LU_N4I.UserDescription AS ActPreferTVDesc_N4i, 
--     LU_N4j.DisplayCode AS ActPreferGarden_N4j, LU_N4j.UserDescription AS ActPreferGardenDesc_N4j, 
--     LU_N4k.DisplayCode AS ActPreferTalking_N4k, LU_N4k.UserDescription AS ActPreferTalkingDesc_N4k, 
--     LU_N4l.DisplayCode AS ActPreferHelping_N4l, LU_N4l.UserDescription AS ActPreferHelpingDesc_N4l, 
    (case dbo.CRS_AssessFull2.N4a when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ActPreferCards_N4a, 
    (case dbo.CRS_AssessFull2.N4a when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ActPreferCardsDesc_N4a, 
    (case dbo.CRS_AssessFull2.N4b when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ActPreferCrafts_N4b, 
    (case dbo.CRS_AssessFull2.N4b when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ActPreferCraftsDesc_N4b, 
    (case dbo.CRS_AssessFull2.N4c when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ActPreferSports_N4c, 
    (case dbo.CRS_AssessFull2.N4c when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ActPreferSportsDesc_N4c, 
    (case dbo.CRS_AssessFull2.N4d when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ActPreferMusic_N4d, 
    (case dbo.CRS_AssessFull2.N4d when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ActPreferMusicDesc_N4d, 
    (case dbo.CRS_AssessFull2.N4e when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ActPreferReading_N4e, 
    (case dbo.CRS_AssessFull2.N4e when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ActPreferReadingDesc_N4e, 
    (case dbo.CRS_AssessFull2.N4f when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ActPreferReligious_N4f, 
    (case dbo.CRS_AssessFull2.N4f when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ActPreferReligiousDesc_N4f, 
    (case dbo.CRS_AssessFull2.N4g when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ActPreferShopping_N4g, 
    (case dbo.CRS_AssessFull2.N4g when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ActPreferShoppingDesc_N4g, 
    (case dbo.CRS_AssessFull2.N4h when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ActPreferWalk_N4h, 
    (case dbo.CRS_AssessFull2.N4h when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ActPreferWalkDesc_N4h, 
    (case dbo.CRS_AssessFull2.N4i when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ActPreferTV_N4i, 
    (case dbo.CRS_AssessFull2.N4i when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ActPreferTVDesc_N4i, 
    (case dbo.CRS_AssessFull2.N4j when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ActPreferGarden_N4j, 
    (case dbo.CRS_AssessFull2.N4j when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ActPreferGardenDesc_N4j, 
    (case dbo.CRS_AssessFull2.N4k when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ActPreferTalking_N4k, 
    (case dbo.CRS_AssessFull2.N4k when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ActPreferTalkingDesc_N4k, 
    (case dbo.CRS_AssessFull2.N4l when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as ActPreferHelping_N4l, 
    (case dbo.CRS_AssessFull2.N4l when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as ActPreferHelpingDesc_N4l, 

    (case when CRS_AssessFull2.N4All > 0 then Y1.DisplayCode end) as ActPreferNone_N4m, 
    --(case when CRS_AssessFull2.N4All > 0 then Y1.UserDescription end) as ActPreferNoneDesc_N4m, 

    LU_N5a.DisplayCode AS PreferChangeType_N5a, LU_N5a.UserDescription AS PreferChangeTypeDesc_N5a, 
    LU_N5b.DisplayCode AS PreferChangeExtent_N5b, LU_N5b.UserDescription AS PreferChangeExtentDesc_N5b, 

--    LU_O2.DisplayCode AS NewMedication_O2, LU_O2.UserDescription AS NewMedicationDesc_O2, 
    (case dbo.CRS_AssessFull2.O2 when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) as NewMedication_O2, 
    (case dbo.CRS_AssessFull2.O2 when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) as NewMedicationDesc_O2, 

    (case CRS_AssessFull2.P2a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as IntervSpecial_P2a, 
    (case CRS_AssessFull2.P2a when 1 then Y.UserDescription when 2 then N.UserDescription end) as IntervSpecialDesc_P2a, 
    (case CRS_AssessFull2.P2b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as IntervSpecialist_P2b, 
    (case CRS_AssessFull2.P2b when 1 then Y.UserDescription when 2 then N.UserDescription end) as IntervSpecialistDesc_P2b, 
    (case CRS_AssessFull2.P2c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as IntervGroup_P2c, 
    (case CRS_AssessFull2.P2c when 1 then Y.UserDescription when 2 then N.UserDescription end) as IntervGroupDesc_P2c, 
    (case CRS_AssessFull2.P2d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as IntervChange_P2d, 
    (case CRS_AssessFull2.P2d when 1 then Y.UserDescription when 2 then N.UserDescription end) as IntervChangeDesc_P2d, 
    (case CRS_AssessFull2.P2e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as IntervReorientation_P2e, 
    (case CRS_AssessFull2.P2e when 1 then Y.UserDescription when 2 then N.UserDescription end) as IntervReorientationDesc_P2e, 
    (case when CRS_AssessFull2.P2All > 0 then Y1.DisplayCode end) as IntervNone_P2f, 
    --(case when CRS_AssessFull2.P2All > 0 then Y1.UserDescription end) as IntervNoneDesc_P2f, 

    dbo.CRS_AssessFull2.P5 as HospitalStay_P5, dbo.CRS_AssessFull2.P6 as EmergencyRoom_P6, 
    (case CRS_AssessFull2.P9 when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as AbnormalLabValues_P9, 
    (case CRS_AssessFull2.P9 when 1 then Y.UserDescription when 2 then N.UserDescription end) as AbnormalLabValuesDesc_P9, 
    (case CRS_AssessFull2.Q1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as DischargeExpress_Q1a, 
    (case CRS_AssessFull2.Q1a when 1 then Y.UserDescription when 2 then N.UserDescription end) as DischargeExpressDesc_Q1a, 
    (case CRS_AssessFull2.Q1b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as DischargeSupport_Q1b, 
    (case CRS_AssessFull2.Q1b when 1 then Y.UserDescription when 2 then N.UserDescription end) as DischargeSupportDesc_Q1b, 
    LU_Q1c.DisplayCode AS DischargeProject_Q1c, LU_Q1c.UserDescription AS DischargeProjectDesc_Q1c, 

    (case CRS_AssessFull2.R1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ParticipationResident_R1a, 
    (case CRS_AssessFull2.R1a when 1 then Y.UserDescription when 2 then N.UserDescription end) as ParticipationResidentDesc_R1a, 
    LU_R1b.DisplayCode AS ParticipationFamily_R1b, LU_R1b.UserDescription AS ParticipationFamilyDesc_R1b, 

    LU_R1c.DisplayCode AS ParticipationOther_R1c, LU_R1c.UserDescription AS ParticipationOtherDesc_R1c, 
--Rugs
    RUG_Group1, 
    CMI_Weight1 = (case when isnumeric(CMI_Weight1) = 1 then cast(CMI_Weight1 as dec(8, 4)) else null end), --PR - 06957
    RUG_Description1, 
    RUG_Group2, 
    CMI_Weight2 = (case when isnumeric(CMI_Weight2) = 1 then cast(CMI_Weight2 as dec(8, 4)) else null end), --PR - 06957
    RUG_Description2, 
    ADL,
--Share1
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A9a_Q.DisplayCode else (case CRS_AssessShare1.A9a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS GuardianLegal_A9a, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A9a_Q.UserDescription else (case CRS_AssessShare1.A9a when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS GuardianLegalDesc_A9a, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A9b_Q.DisplayCode else (case CRS_AssessShare1.A9b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS GuardianAttorney_A9b, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A9b_Q.UserDescription else (case CRS_AssessShare1.A9b when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS GuardianAttorneyDesc_A9b, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A9c_Q.DisplayCode else (case CRS_AssessShare1.A9c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS GuardianOther_A9c, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A9c_Q.UserDescription else (case CRS_AssessShare1.A9c when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS GuardianOtherDesc_A9c, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A9d_Q.DisplayCode else (case CRS_AssessShare1.A9d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS GuardianFamily_A9d, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A9d_Q.UserDescription else (case CRS_AssessShare1.A9d when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS GuardianFamilyDesc_A9d, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A9e_Q.DisplayCode else (case CRS_AssessShare1.A9e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS GuardianHealth_A9e, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A9e_Q.UserDescription else (case CRS_AssessShare1.A9e when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS GuardianHealthDesc_A9e, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A9f_Q.DisplayCode else (case CRS_AssessShare1.A9f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS GuardianSelf_A9f, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A9f_Q.UserDescription else (case CRS_AssessShare1.A9f when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS GuardianSelfDesc_A9f, 
--     (case when CRS_AssessShare1.A9All > 0 then Y1.DisplayCode end) as GuardianNone_A9g, 
--     (case when CRS_AssessShare1.A9All > 0 then Y1.UserDescription end) as GuardianNoneDesc_A9g, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A9a when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) 
                                       else (case CRS_AssessShare1.A9a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS GuardianLegal_A9a, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A9a when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end)
                                       else (case CRS_AssessShare1.A9a when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS GuardianLegalDesc_A9a, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A9b when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end)
                                       else (case CRS_AssessShare1.A9b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS GuardianAttorney_A9b, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A9b when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end)
                                       else (case CRS_AssessShare1.A9b when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS GuardianAttorneyDesc_A9b, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A9c when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end)
                                       else (case CRS_AssessShare1.A9c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS GuardianOther_A9c, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A9c when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end)
                                       else (case CRS_AssessShare1.A9c when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS GuardianOtherDesc_A9c, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A9d when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end)
                                       else (case CRS_AssessShare1.A9d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS GuardianFamily_A9d, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A9d when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end)
                                       else (case CRS_AssessShare1.A9d when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS GuardianFamilyDesc_A9d, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A9e when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end)
                                       else (case CRS_AssessShare1.A9e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS GuardianHealth_A9e, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A9e when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end)
                                       else (case CRS_AssessShare1.A9e when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS GuardianHealthDesc_A9e, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A9f when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end)
                                       else (case CRS_AssessShare1.A9f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS GuardianSelf_A9f, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A9f when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end)
                                       else (case CRS_AssessShare1.A9f when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS GuardianSelfDesc_A9f, 
    (case when CRS_AssessShare1.A9All > 0 then Y1.DisplayCode end) as GuardianNone_A9g, 
    --(case when CRS_AssessShare1.A9All > 0 then Y1.UserDescription end) as GuardianNoneDesc_A9g, 


--     (case when LU_AA8.CIHIValue = ''05'' then LU_A10a_Q.DisplayCode else (case CRS_AssessShare1.A10a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirLiving_A10a, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A10a_Q.UserDescription else (case CRS_AssessShare1.A10a when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirLivingDesc_A10a, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A10b_Q.DisplayCode else (case CRS_AssessShare1.A10b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirNoResuscitate_A10b, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A10b_Q.UserDescription else (case CRS_AssessShare1.A10b when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirNoResuscitateDesc_A10b, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A10c_Q.DisplayCode else (case CRS_AssessShare1.A10c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirNoHospitalize_A10c, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A10c_Q.UserDescription else (case CRS_AssessShare1.A10c when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirNoHospitalizeDesc_A10c, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A10d_Q.DisplayCode else (case CRS_AssessShare1.A10d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirOrgan_A10d, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A10d_Q.UserDescription else (case CRS_AssessShare1.A10d when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirOrganDesc_A10d, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A10e_Q.DisplayCode else (case CRS_AssessShare1.A10e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirAutopsy_A10e, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A10e_Q.UserDescription else (case CRS_AssessShare1.A10e when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirAutopsyDesc_A10e, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A10f_Q.DisplayCode else (case CRS_AssessShare1.A10f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirFeeding_A10f, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A10f_Q.UserDescription else (case CRS_AssessShare1.A10f when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirFeedingDesc_A10f, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A10g_Q.DisplayCode else (case CRS_AssessShare1.A10g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirMedication_A10g, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A10g_Q.UserDescription else (case CRS_AssessShare1.A10g when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirMedicationDesc_A10g, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A10h_Q.DisplayCode else (case CRS_AssessShare1.A10h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirOther_A10h, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_A10h_Q.UserDescription else (case CRS_AssessShare1.A10h when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirOtherDesc_A10h, 

    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A10a when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end)
                                       else (case CRS_AssessShare1.A10a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirLiving_A10a, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A10a when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end)
                                       else (case CRS_AssessShare1.A10a when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirLivingDesc_A10a, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A10b when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) 
                                       else (case CRS_AssessShare1.A10b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirNoResuscitate_A10b, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A10b when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end)
                                       else (case CRS_AssessShare1.A10b when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirNoResuscitateDesc_A10b, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A10c when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) 
                                       else (case CRS_AssessShare1.A10c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirNoHospitalize_A10c, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A10c when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end)
                                       else (case CRS_AssessShare1.A10c when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirNoHospitalizeDesc_A10c, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A10d when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) 
                                       else (case CRS_AssessShare1.A10d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirOrgan_A10d, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A10d when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end)
                                       else (case CRS_AssessShare1.A10d when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirOrganDesc_A10d, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A10e when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) 
                                       else (case CRS_AssessShare1.A10e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirAutopsy_A10e, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A10e when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end)
                                       else (case CRS_AssessShare1.A10e when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirAutopsyDesc_A10e, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A10f when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) 
                                       else (case CRS_AssessShare1.A10f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirFeeding_A10f, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A10f when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) 
                                       else (case CRS_AssessShare1.A10f when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirFeedingDesc_A10f, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A10g when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) 
                                       else (case CRS_AssessShare1.A10g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirMedication_A10g, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A10g when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) 
                                       else (case CRS_AssessShare1.A10g when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirMedicationDesc_A10g, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A10h when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) 
                                       else (case CRS_AssessShare1.A10h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirOther_A10h, 
    (case when LU_AA8.CIHIValue = ''05'' then (case CRS_AssessShare1.A10h when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) 
                                       else (case CRS_AssessShare1.A10h when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirOtherDesc_A10h, 

    (case when CRS_AssessShare1.A10All > 0 then Y1.DisplayCode end) as AdvDirNone_A10i, 
    --(case when CRS_AssessShare1.A10All > 0 then Y1.UserDescription end) as AdvDirNoneDesc_A10i, 

    (case CRS_AssessShare1.B1 when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS Comatose_B1, 
    (case CRS_AssessShare1.B1 when 1 then Y.UserDescription when 2 then N.UserDescription end) AS ComatoseDesc_B1, 

    LU_B2a.DisplayCode AS MemoryShort_B2a, LU_B2a.UserDescription AS MemoryShortDesc_B2a, 
    LU_B2b.DisplayCode AS MemoryLong_B2b, LU_B2b.UserDescription AS MemoryLongDesc_B2b, 

--     LU_B3a.DisplayCode AS MemAbilityCurrent_B3a, LU_B3a.UserDescription AS MemAbilityCurrentDesc_B3a, 
--     LU_B3b.DisplayCode AS MemAbilityOwnRoom_B3b, LU_B3b.UserDescription AS MemAbilityOwnRoomDesc_B3b, 
--     LU_B3c.DisplayCode AS MemAbilityStaff_B3c, LU_B3c.UserDescription AS MemAbilityStaffDesc_B3c, 
--     LU_B3d.DisplayCode AS MemAbilityFacility_B3d, LU_B3d.UserDescription AS MemAbilityFacilityDesc_B3d, 

    (case dbo.CRS_AssessShare1.B3a when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as MemAbilityCurrent_B3a, 
    (case dbo.CRS_AssessShare1.B3a when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as MemAbilityCurrentDesc_B3a, 
    (case dbo.CRS_AssessShare1.B3b when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as MemAbilityOwnRoom_B3b, 
    (case dbo.CRS_AssessShare1.B3b when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as MemAbilityOwnRoomDesc_B3b, 
    (case dbo.CRS_AssessShare1.B3c when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as MemAbilityStaff_B3c, 
    (case dbo.CRS_AssessShare1.B3c when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as MemAbilityStaffDesc_B3c, 
    (case dbo.CRS_AssessShare1.B3d when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as MemAbilityFacility_B3d, 
    (case dbo.CRS_AssessShare1.B3d when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as MemAbilityFacilityDesc_B3d, 

    (case when CRS_AssessShare1.B3All > 0 then Y1.DisplayCode end) as MemAbilityNone_B3e, 
    --(case when CRS_AssessShare1.B3All > 0 then Y1.UserDescription end) as MemAbilityNoneDesc_B3e, 

    LU_B4.DisplayCode AS CognitiveSkills_B4, LU_B4.UserDescription AS CognitiveSkillsDesc_B4, 

    LU_B5a.DisplayCode AS DisorderEasily_B5a, LU_B5a.UserDescription AS DisorderEasilyDesc_B5a, 
    LU_B5b.DisplayCode AS DisorderPerception_B5b, LU_B5b.UserDescription AS DisorderPerceptionDesc_B5b, 
    LU_B5c.DisplayCode AS DisorderSpeech_B5c, LU_B5c.UserDescription AS DisorderSpeechDesc_B5c, 
    LU_B5d.DisplayCode AS DisorderRestless_B5d, LU_B5d.UserDescription AS DisorderRestlessDesc_B5d, 
    LU_B5e.DisplayCode AS DisorderLethargy_B5e, LU_B5e.UserDescription AS DisorderLethargyDesc_B5e, 
    LU_B5f.DisplayCode AS DisorderMental_B5f, LU_B5f.UserDescription AS DisorderMentalDesc_B5f, 

    LU_B6.DisplayCode AS ChangeCognitive_B6, LU_B6.UserDescription AS ChangeCognitiveDesc_B6, 

    LU_C4.DisplayCode AS UnderStood_C4, LU_C4.UserDescription AS UnderStoodDesc_C4, 
    LU_C6.DisplayCode AS AbilityUnderStood_C6, LU_C6.UserDescription AS AbilityUnderStoodDesc_C6, 
    LU_C7.DisplayCode AS ChangeComm_C7, LU_C7.UserDescription AS ChangeCommDesc_C7, 

    LU_E1a.DisplayCode AS DepressionNegative_E1a, LU_E1a.UserDescription AS DepressionNegativeDesc_E1a, 
    LU_E1b.DisplayCode AS DepressionRepeatQues_E1b, LU_E1b.UserDescription AS DepressionRepeatQuesDesc_E1b, 
    LU_E1c.DisplayCode AS DepressionRepeatVerb_E1c, LU_E1c.UserDescription AS DepressionRepeatVerbDesc_E1c, 
    LU_E1d.DisplayCode AS DepressionAnger_E1d, LU_E1d.UserDescription AS DepressionAngerDesc_E1d, 
    LU_E1e.DisplayCode AS DepressionDeprecation_E1e, LU_E1e.UserDescription AS DepressionDeprecationDesc_E1e, 
    LU_E1f.DisplayCode AS DepressionUnrealistic_E1f, LU_E1f.UserDescription AS DepressionUnrealisticDesc_E1f, 
    LU_E1g.DisplayCode AS DepressionTerrible_E1g, LU_E1g.UserDescription AS DepressionTerribleDesc_E1g, 
    LU_E1h.DisplayCode AS DepressionComplaints_E1h, LU_E1h.UserDescription AS DepressionComplaintsDesc_E1h, 
    LU_E1I.DisplayCode AS DepressionNonHealth_E1i, LU_E1I.UserDescription AS DepressionNonHealthDesc_E1i, 
    LU_E1j.DisplayCode AS DepressionUnpleasant_E1j, LU_E1j.UserDescription AS DepressionUnpleasantDesc_E1j, 
    LU_E1k.DisplayCode AS DepressionChange_E1k, LU_E1k.UserDescription AS DepressionChangeDesc_E1k, 
    LU_E1l.DisplayCode AS DepressionSad_E1l, LU_E1l.UserDescription AS DepressionSadDesc_E1l, 
    LU_E1m.DisplayCode AS DepressionCrying_E1m, LU_E1m.UserDescription AS DepressionCryingDesc_E1m, 
    LU_E1n.DisplayCode AS DepressionPhysical_E1n, LU_E1n.UserDescription AS DepressionPhysicalDesc_E1n, 
    LU_E1o.DisplayCode AS DepressionInterest_E1o, LU_E1o.UserDescription AS DepressionInterestDesc_E1o, 
    LU_E1p.DisplayCode AS DepressionInteraction_E1p, LU_E1p.UserDescription AS DepressionInteractionDesc_E1p, 

    LU_E2.DisplayCode AS Persistence_E2, LU_E2.UserDescription AS PersistenceDesc_E2, 
    LU_E3.DisplayCode AS ChangeMood_E3, LU_E3.UserDescription AS ChangeMoodDesc_E3, 

    LU_E4aA.DisplayCode AS BehaviorWanderingFre_E4aA, LU_E4aA.UserDescription AS BehaviorWanderingFreDesc_E4aA, 
    LU_E4aB.DisplayCode AS BehaviorWanderingAlt_E4aB, LU_E4aB.UserDescription AS BehaviorWanderingAltDesc_E4aB, 
    LU_E4bA.DisplayCode AS BehaviorVerballyFre_E4bA, LU_E4bA.UserDescription AS BehaviorVerballyFreDesc_E4bA, 
    LU_E4bB.DisplayCode AS BehaviorVerballyAlt_E4bB, LU_E4bB.UserDescription AS BehaviorVerballyAltDesc_E4bB, 
    LU_E4cA.DisplayCode AS BehaviorPhysicallyFre_E4cA, LU_E4cA.UserDescription AS BehaviorPhysicalFreDesc_E4cA, 
    LU_E4cB.DisplayCode AS BehaviorPhysicallyAlt_E4cB, LU_E4cB.UserDescription AS BehaviorPhysicalAltDesc_E4cB, 
    LU_E4dA.DisplayCode AS BehaviorSociallyFre_E4dA, LU_E4dA.UserDescription AS BehaviorSociallyFreDesc_E4dA, 
    LU_E4dB.DisplayCode AS BehaviorSociallyAlt_E4dB, LU_E4dB.UserDescription AS BehaviorSociallyAltDesc_E4dB, 
    LU_E4eA.DisplayCode AS BehaviorResistsFre_E4eA, LU_E4eA.UserDescription AS BehaviorResistsFreDesc_E4eA, 
    LU_E4eB.DisplayCode AS BehaviorResistsAlt_E4eB, LU_E4eB.UserDescription AS BehaviorResistsAltDesc_E4eB, 

    LU_E5.DisplayCode AS ChangeBehave_E5, LU_E5.UserDescription AS ChangeBehaveDesc_E5, 
--Share2
--     LU_F1a.DisplayCode AS Interacting_F1a, LU_F1a.UserDescription AS InteractingDesc_F1a, 
--     LU_F1b.DisplayCode AS PlanActivity_F1b, LU_F1b.UserDescription AS PlanActivityDesc_F1b, 
--     LU_F1c.DisplayCode AS SelfActivity_F1c, LU_F1c.UserDescription AS SelfActivityDesc_F1c, 
--     LU_F1d.DisplayCode AS Goals_F1d, LU_F1d.UserDescription AS GoalsDesc_F1d, 
--     LU_F1e.DisplayCode AS Pursues_F1e, LU_F1e.UserDescription AS PursuesDesc_F1e, 
--     LU_F1f.DisplayCode AS Accepts_F1f, LU_F1f.UserDescription AS AcceptsDesc_F1f, 
    (case dbo.CRS_AssessShare2.F1a when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as Interacting_F1a, 
    (case dbo.CRS_AssessShare2.F1a when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as InteractingDesc_F1a, 
    (case dbo.CRS_AssessShare2.F1b when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as PlanActivity_F1b, 
    (case dbo.CRS_AssessShare2.F1b when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as PlanActivityDesc_F1b, 
    (case dbo.CRS_AssessShare2.F1c when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as SelfActivity_F1c, 
    (case dbo.CRS_AssessShare2.F1c when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as SelfActivityDesc_F1c, 
    (case dbo.CRS_AssessShare2.F1d when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as Goals_F1d, 
    (case dbo.CRS_AssessShare2.F1d when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as GoalsDesc_F1d, 
    (case dbo.CRS_AssessShare2.F1e when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as Pursues_F1e, 
    (case dbo.CRS_AssessShare2.F1e when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as PursuesDesc_F1e, 
    (case dbo.CRS_AssessShare2.F1f when 15383 then N47081.DisplayCode when 15384 then Y47081.DisplayCode when 15385 then U47081.DisplayCode end) as Accepts_F1f, 
    (case dbo.CRS_AssessShare2.F1f when 15383 then N47081.UserDescription when 15384 then Y47081.UserDescription when 15385 then U47081.UserDescription end) as AcceptsDesc_F1f, 

    (case when CRS_AssessShare2.F1All > 0 then Y1.DisplayCode end) as SenseNone_F1g, 
    --(case when CRS_AssessShare2.F1All > 0 then Y1.UserDescription end) as SenseNoneDesc_F1g, 

    LU_G1aA.DisplayCode AS BedMobilitySelf_G1aA, LU_G1aA.UserDescription AS BedMobilitySelfDesc_G1aA, 
    LU_G1aB.DisplayCode AS BedMobilitySupport_G1aB, LU_G1aB.UserDescription AS BedMobilitySupportDesc_G1aB, 
    LU_G1bA.DisplayCode AS TransferSelf_G1bA, LU_G1bA.UserDescription AS TransferSelfDesc_G1bA, 
    LU_G1bB.DisplayCode AS TransferSupport_G1bB, LU_G1bB.UserDescription AS TransferSupportDesc_G1bB, 
    LU_G1cA.DisplayCode AS WalkInRoomSelf_G1cA, LU_G1cA.UserDescription AS WalkInRoomSelfDesc_G1cA,
    LU_G1cB.DisplayCode AS WalkInRoomSupport_G1cB, LU_G1cB.UserDescription AS WalkInRoomSupportDesc_G1cB, 
    LU_G1dA.DisplayCode AS RorridorSelf_G1dA, LU_G1dA.UserDescription AS RorridorSelfDesc_G1dA, 
    LU_G1dB.DisplayCode AS RorridorSupport_G1dB, LU_G1dB.UserDescription AS RorridorSupportDesc_G1dB, 
    LU_G1eA.DisplayCode AS OnUnitSelf_G1eA, LU_G1eA.UserDescription AS OnUnitSelfDesc_G1eA, 
    LU_G1eB.DisplayCode AS OnUnitSupport_G1eB, LU_G1eB.UserDescription AS OnUnitSupportDesc_G1eB, 
    LU_G1fA.DisplayCode AS OffUnitSelf_G1fA, LU_G1fA.UserDescription AS OffUnitSelfDesc_G1fA, 
    LU_G1fB.DisplayCode AS OffUnitSupport_G1fB, LU_G1fB.UserDescription AS OffUnitSupportDesc_G1fB, 
    LU_G1gA.DisplayCode AS DressingSelf_G1gA, LU_G1gA.UserDescription AS DressingSelfDesc_G1gA, 
    LU_G1gB.DisplayCode AS DressingSupport_G1gB, LU_G1gB.UserDescription AS DressingSupportDesc_G1gB, 
    LU_G1hA.DisplayCode AS EatingSelf_G1hA, LU_G1hA.UserDescription AS EatingSelfDesc_G1hA, 
    LU_G1hB.DisplayCode AS EatingSupport_G1hB, LU_G1hB.UserDescription AS EatingSupportDesc_G1hB, 
    LU_G1IA.DisplayCode AS ToiletSelf_G1iA, LU_G1IA.UserDescription AS ToiletSelfDesc_G1iA, 
    LU_G1IB.DisplayCode AS ToiletSupport_G1iB, LU_G1IB.UserDescription AS ToiletSupportDesc_G1iB, 
    LU_G1jA.DisplayCode AS HygieneSelf_G1jA, LU_G1jA.UserDescription AS HygieneSelfDesc_G1jA, 
    LU_G1jB.DisplayCode AS HygieneSupport_G1jB, LU_G1jB.UserDescription AS HygieneSupportDesc_G1jB, 

    LU_G2A.DisplayCode AS BathingSelf_G2A, LU_G2A.UserDescription AS BathingSelfDesc_G2A, 
    LU_G2B.DisplayCode AS BathingSupport_G2B, LU_G2B.UserDescription AS BathingSupportDesc_G2B, 

    LU_G3a.DisplayCode AS BalanceStanding_G3a, LU_G3a.UserDescription AS BalanceStandingDesc_G3a, 
    LU_G3b.DisplayCode AS BalanceSitting_G3b, LU_G3b.UserDescription AS BalanceSupportDesc_G3b, 

    LU_G4aA.DisplayCode AS LimitRangeNeck_G4aA, LU_G4aA.UserDescription AS LimitRangeNeckDesc_G4aA, 
    LU_G4aB.DisplayCode AS LimitVoluntaryNeck_G4aB, LU_G4aB.UserDescription AS LimitVoluntaryNeckDesc_G4aB, 
    LU_G4bA.DisplayCode AS LimitRangeArm_G4bA, LU_G4bA.UserDescription AS LimitRangeArmDesc_G4bA, 
    LU_G4bB.DisplayCode AS LimitVoluntaryArm_G4bB, LU_G4bB.UserDescription AS LimitVoluntaryArmDesc_G4bB, 
    LU_G4cA.DisplayCode AS LimitRangeHand_G4cA, LU_G4cA.UserDescription AS LimitRangeHandDesc_G4cA, 
    LU_G4cB.DisplayCode AS LimitVoluntaryHand_G4cB, LU_G4cB.UserDescription AS LimitVoluntaryHandDesc_G4cB, 
    LU_G4dA.DisplayCode AS LimitRangeLeg_G4dA, LU_G4dA.UserDescription AS LimitRangeLegDesc_G4dA, 
    LU_G4dB.DisplayCode AS LimitVoluntaryLeg_G4dB, LU_G4dB.UserDescription AS LimitVoluntaryLegDesc_G4dB, 
    LU_G4eA.DisplayCode AS LimitRangeFoot_G4eA, LU_G4eA.UserDescription AS LimitRangeFootDesc_G4eA, 
    LU_G4eB.DisplayCode AS LimitVoluntaryFoot_G4eB, LU_G4eB.UserDescription AS LimitVoluntaryFootDesc_G4eB, 
    LU_G4fA.DisplayCode AS LimitRangeOther_G4fA, LU_G4fA.UserDescription AS LimitRangeOtherDesc_G4fA, 
    LU_G4fB.DisplayCode AS LimitVoluntaryOther_G4fB, LU_G4fB.UserDescription AS LimitVoluntaryOtherDesc_G4fB, 

    (case CRS_AssessShare2.G6a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS TransferBedfast_G6a, 
    (case CRS_AssessShare2.G6a when 1 then Y.UserDescription when 2 then N.UserDescription end) AS TransferBedfastDesc_G6a, 
    (case CRS_AssessShare2.G6b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS TransferBedrail_G6b, 
    (case CRS_AssessShare2.G6b when 1 then Y.UserDescription when 2 then N.UserDescription end) AS TransferBedrailDesc_G6b, 
    (case CRS_AssessShare2.G6c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS TransferManually_G6c, 
    (case CRS_AssessShare2.G6c when 1 then Y.UserDescription when 2 then N.UserDescription end) AS TransferManuallyDesc_G6c, 
    (case CRS_AssessShare2.G6d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS TransferMechanically_G6d,
    (case CRS_AssessShare2.G6d when 1 then Y.UserDescription when 2 then N.UserDescription end) AS TransferMechanicallyDesc_G6d, 
    (case CRS_AssessShare2.G6e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS TransferAid_G6e, 
    (case CRS_AssessShare2.G6e when 1 then Y.UserDescription when 2 then N.UserDescription end) AS TransferAidDesc_G6e, 
    (case when CRS_AssessShare2.G6All > 0 then Y1.DisplayCode end) as TransferNone_G6f, 
    --(case when CRS_AssessShare2.G6All > 0 then Y1.UserDescription end) as TransferNoneDesc_G6f, 

    (case CRS_AssessShare2.G7 when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS Task_G7, 
    (case CRS_AssessShare2.G7 when 1 then Y.UserDescription when 2 then N.UserDescription end) AS TaskDesc_G7, 

    LU_G9.DisplayCode AS ChangeADL_G9, LU_G9.UserDescription AS ChangeADLDesc_G9, 

    LU_H1a.DisplayCode AS BowlContinence_H1a, LU_H1a.UserDescription AS BowlContinenceDesc_H1a, 
    LU_H1b.DisplayCode AS BladderContinence_H1b, LU_H1b.UserDescription AS BladderContinenceDesc_H1b, 

    (case CRS_AssessShare2.H2a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS BowelRegular_H2a, 
    (case CRS_AssessShare2.H2a when 1 then Y.UserDescription when 2 then N.UserDescription end) AS BowelRegularDesc_H2a, 
    (case CRS_AssessShare2.H2b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS BowelConstipation_H2b, 
    (case CRS_AssessShare2.H2b when 1 then Y.UserDescription when 2 then N.UserDescription end) AS BowelConstipationDesc_H2b, 
    (case CRS_AssessShare2.H2c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS BowelDiarrhea_H2c, 
    (case CRS_AssessShare2.H2c when 1 then Y.UserDescription when 2 then N.UserDescription end) AS BowelDiarrheaDesc_H2c, 
    (case CRS_AssessShare2.H2d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS BowelFecalImpaction_H2d, 
    (case CRS_AssessShare2.H2d when 1 then Y.UserDescription when 2 then N.UserDescription end) AS BowelFecalImpactionDesc_H2d, 
    (case when CRS_AssessShare2.H2All > 0 then Y1.DisplayCode end) as BowelNone_H2e, 
    --(case when CRS_AssessShare2.H2All > 0 then Y1.UserDescription end) as BowelNoneDesc_H2e, 

    (case CRS_AssessShare2.H3a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS ApplianceScheduled_H3a, 
    (case CRS_AssessShare2.H3a when 1 then Y.UserDescription when 2 then N.UserDescription end) AS ApplianceScheduledDesc_H3a, 
    (case CRS_AssessShare2.H3b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS ApplianceBladder_H3b, 
    (case CRS_AssessShare2.H3b when 1 then Y.UserDescription when 2 then N.UserDescription end) AS ApplianceBladderDesc_H3b, 
    (case CRS_AssessShare2.H3c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS ApplianceExCatheter_H3c, 
    (case CRS_AssessShare2.H3c when 1 then Y.UserDescription when 2 then N.UserDescription end) AS ApplianceExCatheterDesc_H3c, 
    (case CRS_AssessShare2.H3d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS ApplianceIndCatheter_H3d, 
    (case CRS_AssessShare2.H3d when 1 then Y.UserDescription when 2 then N.UserDescription end) AS ApplianceIndCatheterDesc_H3d, 
    (case CRS_AssessShare2.H3e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS ApplianceIntCatheter_H3e, 
    (case CRS_AssessShare2.H3e when 1 then Y.UserDescription when 2 then N.UserDescription end) AS ApplianceIntCatheterDesc_H3e, 
    (case CRS_AssessShare2.H3f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS ApplianceNotUse_H3f, 
    (case CRS_AssessShare2.H3f when 1 then Y.UserDescription when 2 then N.UserDescription end) AS ApplianceNotUseDesc_H3f, 
    (case CRS_AssessShare2.H3g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS AppliancePads_H3g, 
    (case CRS_AssessShare2.H3g when 1 then Y.UserDescription when 2 then N.UserDescription end) AS AppliancePadsDesc_H3g, 
    (case CRS_AssessShare2.H3h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS ApplianceIrrigation_H3h, 
    (case CRS_AssessShare2.H3h when 1 then Y.UserDescription when 2 then N.UserDescription end) AS ApplianceIrrigationDesc_H3h, 
    (case CRS_AssessShare2.H3i when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS ApplianceOstomy_H3i, 
    (case CRS_AssessShare2.H3i when 1 then Y.UserDescription when 2 then N.UserDescription end) AS ApplianceOstomyDesc_H3i, 
    (case when CRS_AssessShare2.H3All > 0 then Y1.DisplayCode end) as ApplianceNone_H3j, 
    --(case when CRS_AssessShare2.H3All > 0 then Y1.UserDescription end) as ApplianceNoneDesc_H3j, 

    LU_H4.DisplayCode AS UrinaryContinence_H4, LU_H4.UserDescription AS UrinaryContinenceDesc_H4, 
--Share3
    (case CRS_AssessShare3.I1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseDiabMellitus_I1a, 
    (case CRS_AssessShare3.I1a when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseDiabMellitusDesc_I1a, 
    (case CRS_AssessShare3.I1b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseHyperthyroidism_I1b, 
    (case CRS_AssessShare3.I1b when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseHyperthyroidDesc_I1b, 
    (case CRS_AssessShare3.I1c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseHypothyroidism_I1c, 
    (case CRS_AssessShare3.I1c when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseHypothyroidismDesc_I1c, 
    (case CRS_AssessShare3.I1d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseASHD_I1d, 
    (case CRS_AssessShare3.I1d when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseASHDDesc_I1d, 
    (case CRS_AssessShare3.I1e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseCardiac_I1e, 
    (case CRS_AssessShare3.I1e when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseCardiacDesc_I1e, 
    (case CRS_AssessShare3.I1f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseCongestive_I1f, 
    (case CRS_AssessShare3.I1f when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseCongestiveDesc_I1f, 
    (case CRS_AssessShare3.I1g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseThrombosis_I1g, 
    (case CRS_AssessShare3.I1g when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseThrombosisDesc_I1g, 
    (case CRS_AssessShare3.I1h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseHypertension_I1h, 
    (case CRS_AssessShare3.I1h when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseHypertensionDesc_I1h, 
    (case CRS_AssessShare3.I1I when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseHypotension_I1i, 
    (case CRS_AssessShare3.I1I when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseHypotensionDesc_I1i, 
    (case CRS_AssessShare3.I1j when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseVascular_I1j, 
    (case CRS_AssessShare3.I1j when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseVascularDesc_I1j, 
    (case CRS_AssessShare3.I1k when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseCardiovascular_I1k, 
    (case CRS_AssessShare3.I1k when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseCardiovascularDesc_I1k, 
    (case CRS_AssessShare3.I1l when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseArthritis_I1l, 
    (case CRS_AssessShare3.I1l when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseArthritisDesc_I1l, 
    (case CRS_AssessShare3.I1m when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseHipFracture_I1m, 
    (case CRS_AssessShare3.I1m when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseHipFractureDesc_I1m, 
    (case CRS_AssessShare3.I1n when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseLimb_I1n, 
    (case CRS_AssessShare3.I1n when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseLimbDesc_I1n, 
    (case CRS_AssessShare3.I1o when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseOsteoporosis_I1o, 
    (case CRS_AssessShare3.I1o when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseOsteoporosisDesc_I1o, 
    (case CRS_AssessShare3.I1p when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseBoneFracture_I1p, 
    (case CRS_AssessShare3.I1p when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseBoneFractureDesc_I1p, 
    (case CRS_AssessShare3.I1q when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseALS_I1q, 
    (case CRS_AssessShare3.I1q when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseALSDesc_I1q, 
    (case CRS_AssessShare3.I1r when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseAlzheimer_I1r, 
    (case CRS_AssessShare3.I1r when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseAlzheimerDesc_I1r, 
    (case CRS_AssessShare3.I1s when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseAphasia_I1s, 
    (case CRS_AssessShare3.I1s when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseAphasiaDesc_I1s, 
    (case CRS_AssessShare3.I1t when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseCerebralPalsy_I1t, 
    (case CRS_AssessShare3.I1t when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseCerebralPalsyDesc_I1t, 
    (case CRS_AssessShare3.I1u when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseCerebro_I1u, 
    (case CRS_AssessShare3.I1u when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseCerebroDesc_I1u, 
    (case CRS_AssessShare3.I1v when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseDementia_I1v, 
    (case CRS_AssessShare3.I1v when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseDementiaDesc_I1v, 
    (case CRS_AssessShare3.I1w when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseHemiplegia_I1w, 
    (case CRS_AssessShare3.I1w when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseHemiplegiaDesc_I1w, 
    (case CRS_AssessShare3.I1x when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseChorea_I1x, 
    (case CRS_AssessShare3.I1x when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseChoreaDesc_I1x, 
    (case CRS_AssessShare3.I1y when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseSclerosis_I1y, 
    (case CRS_AssessShare3.I1y when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseSclerosisDesc_I1y, 
    (case CRS_AssessShare3.I1z when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseParaplegia_I1z, 
    (case CRS_AssessShare3.I1z when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseParaplegiaDesc_I1z, 
    (case CRS_AssessShare3.I1aa when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseParkinson_I1aa, 
    (case CRS_AssessShare3.I1aa when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseParkinsonDesc_I1aa, 
    (case CRS_AssessShare3.I1bb when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseQuadriplegia_I1bb, 
    (case CRS_AssessShare3.I1bb when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseQuadriplegiaDesc_I1bb, 
    (case CRS_AssessShare3.I1cc when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseSeizureDisorder_I1cc, 
    (case CRS_AssessShare3.I1cc when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseSeizeDisorderDesc_I1cc, 
    (case CRS_AssessShare3.I1dd when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseIschemic_I1dd, 
    (case CRS_AssessShare3.I1dd when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseIschemicDesc_I1dd, 
    (case CRS_AssessShare3.I1ee when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseTraumaticBrain_I1ee, 
    (case CRS_AssessShare3.I1ee when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseTraumaBrainDesc_I1ee, 
    (case CRS_AssessShare3.I1ff when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseAnxietyDisorder_I1ff, 
    (case CRS_AssessShare3.I1ff when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseAnxietyDisDesc_I1ff, 
    (case CRS_AssessShare3.I1gg when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseDepression_I1gg, 
    (case CRS_AssessShare3.I1gg when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseDepressionDesc_I1gg, 
    (case CRS_AssessShare3.I1hh when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseManicDepressive_I1hh, 
    (case CRS_AssessShare3.I1hh when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseManicDepressDesc_I1hh, 
    (case CRS_AssessShare3.I1ii when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseSchizophrenia_I1ii, 
    (case CRS_AssessShare3.I1ii when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseSchizophreniaDesc_I1ii, 
    (case CRS_AssessShare3.I1jj when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseAsthma_I1jj, 
    (case CRS_AssessShare3.I1jj when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseAsthmaDesc_I1jj, 
    (case CRS_AssessShare3.I1kk when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseEmphysema_I1kk, 
    (case CRS_AssessShare3.I1kk when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseEmphysemaDesc_I1kk, 
    (case CRS_AssessShare3.I1ll when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseCatarats_I1ll, 
    (case CRS_AssessShare3.I1ll when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseCataratsDesc_I1ll, 
    (case CRS_AssessShare3.I1mm when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseDiabRetino_I1mm, 
    (case CRS_AssessShare3.I1mm when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseDiabRetinoDesc_I1mm, 
    (case CRS_AssessShare3.I1nn when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseGlaucoma_I1nn, 
    (case CRS_AssessShare3.I1nn when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseGlaucomaDesc_I1nn, 
    (case CRS_AssessShare3.I1oo when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseMacularDegenerate_I1oo, 
    (case CRS_AssessShare3.I1oo when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseMacularDegenDesc_I1oo, 
    (case CRS_AssessShare3.I1pp when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseAllergies_I1pp, 
    (case CRS_AssessShare3.I1pp when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseAllergiesDesc_I1pp, 
    (case CRS_AssessShare3.I1qq when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseAnemia_I1qq, 
    (case CRS_AssessShare3.I1qq when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseAnemiaDesc_I1qq, 
    (case CRS_AssessShare3.I1rr when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseCancer_I1rr, 
    (case CRS_AssessShare3.I1rr when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseCancerDesc_I1rr, 
    (case CRS_AssessShare3.I1ss when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as DiseaseGastrointestinal_I1ss, 
    (case CRS_AssessShare3.I1ss when 1 then Y.UserDescription when 2 then N.UserDescription end) as DiseaseGastroDesc_I1ss, 
    (case CRS_AssessShare3.I1tt when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as DiseaseLiver_I1tt, 
    (case CRS_AssessShare3.I1tt when 1 then Y.UserDescription when 2 then N.UserDescription end) as DiseaseLiverDesc_I1tt, 
    (case CRS_AssessShare3.I1uu when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as DiseaseRenalFailure_I1uu, 
    (case CRS_AssessShare3.I1uu when 1 then Y.UserDescription when 2 then N.UserDescription end) as DiseaseRenalFailureDesc_I1uu, 
    (case when CRS_AssessShare3.I1All > 0 then Y1.DisplayCode end) as DiseaseNone_I1vv, 
    --(case when CRS_AssessShare3.I1All > 0 then Y1.UserDescription end) as DiseaseNoneDesc_I1vv, 

    (case CRS_AssessShare3.I2a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionAntibiotic_I2a, 
    (case CRS_AssessShare3.I2a when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionAntibioticDesc_I2a, 
    (case CRS_AssessShare3.I2b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionCellulitis_I2b, 
    (case CRS_AssessShare3.I2b when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionCellulitisDesc_I2b, 
    (case CRS_AssessShare3.I2c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionClostridium_I2c, 
    (case CRS_AssessShare3.I2c when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionClostridiumDesc_I2c, 
    (case CRS_AssessShare3.I2d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionConjunctivitis_I2d, 
    (case CRS_AssessShare3.I2d when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionConjunctivaDesc_I2d, 
    (case CRS_AssessShare3.I2e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionHIV_I2e, 
    (case CRS_AssessShare3.I2e when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionHIVDesc_I2e, 
    (case CRS_AssessShare3.I2f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionPneumonia_I2f, 
    (case CRS_AssessShare3.I2f when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionPneumoniaDesc_I2f, 
    (case CRS_AssessShare3.I2g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionRespiratory_I2g, 
    (case CRS_AssessShare3.I2g when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionRespiratoryDesc_I2g, 
    (case CRS_AssessShare3.I2h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionSepticemia_I2h, 
    (case CRS_AssessShare3.I2h when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionSepticemiaDesc_I2h, 
    (case CRS_AssessShare3.I2I when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionSexually_I2i, 
    (case CRS_AssessShare3.I2I when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionSexuallyDesc_I2i, 
    (case CRS_AssessShare3.I2j when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionTuberculosis_I2j, 
    (case CRS_AssessShare3.I2j when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionTuberculosisDesc_I2j, 
    (case CRS_AssessShare3.I2k when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionUrinary_I2k, 
    (case CRS_AssessShare3.I2k when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionUrinaryDesc_I2k, 
    (case CRS_AssessShare3.I2l when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionHepatitis_I2l, 
    (case CRS_AssessShare3.I2l when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionHepatitisDesc_I2l, 
    (case CRS_AssessShare3.I2m when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionWound_I2m, 
    (case CRS_AssessShare3.I2m when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionWoundDesc_I2m, 
    (case when CRS_AssessShare3.I2All > 0 then Y1.DisplayCode end) as InfectionNone_I2n, 
    --(case when CRS_AssessShare3.I2All > 0 then Y1.UserDescription end) as InfectionNoneDesc_I2n, 

    (case CRS_AssessShare3.J1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemWeight_J1a, 
    (case CRS_AssessShare3.J1a when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemWeightDesc_J1a, 
    (case CRS_AssessShare3.J1b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemLieFlat_J1b, 
    (case CRS_AssessShare3.J1b when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemLieFlatDesc_J1b, 
    (case CRS_AssessShare3.J1c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemDehydrated_J1c, 
    (case CRS_AssessShare3.J1c when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemDehydratedDesc_J1c, 
    (case CRS_AssessShare3.J1d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemFluid_J1d, 
    (case CRS_AssessShare3.J1d when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemFluidDesc_J1d, 
    (case CRS_AssessShare3.J1e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemDelusions_J1e, 
    (case CRS_AssessShare3.J1e when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemDelusionsDesc_J1e, 
    (case CRS_AssessShare3.J1f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemDizziness_J1f, 
    (case CRS_AssessShare3.J1f when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemDizzinessDesc_J1f, 
    (case CRS_AssessShare3.J1g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemEdema_J1g, 
    (case CRS_AssessShare3.J1g when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemEdemaDesc_J1g, 
    (case CRS_AssessShare3.J1h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemFever_J1h, 
    (case CRS_AssessShare3.J1h when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemFeverDesc_J1h, 
    (case CRS_AssessShare3.J1I when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemHallucinations_J1i, 
    (case CRS_AssessShare3.J1I when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemHallucinationsDesc_J1i, 
    (case CRS_AssessShare3.J1j when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemBleeding_J1j, 
    (case CRS_AssessShare3.J1j when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemBleedingDesc_J1j, 
    (case CRS_AssessShare3.J1k when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemLung_J1k, 
    (case CRS_AssessShare3.J1k when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemLungDesc_J1k, 
    (case CRS_AssessShare3.J1l when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemBreath_J1l, 
    (case CRS_AssessShare3.J1l when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemBreathDesc_J1l, 
    (case CRS_AssessShare3.J1m when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemSyncope_J1m, 
    (case CRS_AssessShare3.J1m when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemSyncopeDesc_J1m, 
    (case CRS_AssessShare3.J1n when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemUnsteadyGait_J1n, 
    (case CRS_AssessShare3.J1n when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemUnsteadyGaitDesc_J1n, 
    (case CRS_AssessShare3.J1o when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemVomiting_J1o, 
    (case CRS_AssessShare3.J1o when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemVomitingDesc_J1o, 
    (case when CRS_AssessShare3.J1All > 0 then Y1.DisplayCode end) as ProblemNone_J1p, 
    --(case when CRS_AssessShare3.J1All > 0 then Y1.UserDescription end) as ProblemNoneDesc_J1p, 

    LU_J2a.DisplayCode AS Pain_Frequency_J2a, LU_J2a.UserDescription AS Pain_FrequencyDesc_J2a, 
    LU_J2b.DisplayCode AS Pain_Intensity_J2b, LU_J2b.UserDescription AS Pain_IntensityDesc_J2b, 

    (case CRS_AssessShare3.J4a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as AccidentFell30_J4a, 
    (case CRS_AssessShare3.J4a when 1 then Y.UserDescription when 2 then N.UserDescription end) as AccidentFell30Desc_J4a, 
    (case CRS_AssessShare3.J4b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as AccidentFell180_J4b, 
    (case CRS_AssessShare3.J4b when 1 then Y.UserDescription when 2 then N.UserDescription end) as AccidentFell180Desc_J4b, 
    (case CRS_AssessShare3.J4c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as AccidentHipFracture_J4c, 
    (case CRS_AssessShare3.J4c when 1 then Y.UserDescription when 2 then N.UserDescription end) as AccidentHipFractureDesc_J4c, 
    (case CRS_AssessShare3.J4d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as AccidentOtherFracture_J4d, 
    (case CRS_AssessShare3.J4d when 1 then Y.UserDescription when 2 then N.UserDescription end) as AccidentOtherFractureDesc_J4d, 
    (case when CRS_AssessShare3.J4All > 0 then Y1.DisplayCode end) as AccidentNone_J4e, 
    --(case when CRS_AssessShare3.J4All > 0 then Y1.UserDescription end) as AccidentNoneDesc_J4e, 

    (case CRS_AssessShare3.J5a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Stability_Unstable_J5a, 
    (case CRS_AssessShare3.J5a when 1 then Y.UserDescription when 2 then N.UserDescription end) as Stability_UnstableDesc_J5a, 
    (case CRS_AssessShare3.J5b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Stability_Acute_J5b, 
    (case CRS_AssessShare3.J5b when 1 then Y.UserDescription when 2 then N.UserDescription end) as Stability_AcuteDesc_J5b, 
    (case CRS_AssessShare3.J5c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Stability_EndStage_J5c, 
    (case CRS_AssessShare3.J5c when 1 then Y.UserDescription when 2 then N.UserDescription end) as Stability_EndStageDesc_J5c, 
    (case when CRS_AssessShare3.J5All > 0 then Y1.DisplayCode end) as Stability_None_J5d, 
    --(case when CRS_AssessShare3.J5All > 0 then Y1.UserDescription end) as Stability_None_Desc_J5d,
--Share4
    (case CRS_AssessShare4.K1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as OralUnstable_K1a, 
    (case CRS_AssessShare4.K1a when 1 then Y.UserDescription when 2 then N.UserDescription end) as OralUnstableDesc_K1a, 
    (case CRS_AssessShare4.K1b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as OralAcute_K1b, 
    (case CRS_AssessShare4.K1b when 1 then Y.UserDescription when 2 then N.UserDescription end) as OralAcuteDesc_K1b, 
    (case CRS_AssessShare4.K1c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as OralEndStage_K1c, 
    (case CRS_AssessShare4.K1c when 1 then Y.UserDescription when 2 then N.UserDescription end) as OralEndStageDesc_K1c, 
    (case when CRS_AssessShare4.K1All > 0 then Y1.DisplayCode end) as OralNone_K1d, 
    --(case when CRS_AssessShare4.K1All > 0 then Y1.UserDescription end) as OralDesc_K1d, 

    dbo.CRS_AssessShare4.K2a as Height_K2a, dbo.CRS_AssessShare4.K2b as Weight_K2b, 


--     (case when LU_AA8.CIHIValue = ''05'' then LU_K3a_Q.DisplayCode else (case CRS_AssessShare4.K3a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS WeightGain_K3a, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_K3a_Q.UserDescription else (case CRS_AssessShare4.K3a when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS WeightGainDesc_K3a, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_K3b_Q.DisplayCode else (case CRS_AssessShare4.K3b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS WeightLoss_K3b, 
--     (case when LU_AA8.CIHIValue = ''05'' then LU_K3b_Q.UserDescription else (case CRS_AssessShare4.K3b when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS WeightLossDesc_K3b, 
--PR - 05185
    --(case when LU_AA8.CIHIValue not in (''05'', ''10'') then (case CRS_AssessShare4.K3a when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end)
    --                                   else (case CRS_AssessShare4.K3a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS WeightLoss_K3a, 
    (case when LU_AA8.CIHIValue not in (''05'', ''10'') then (case CRS_AssessShare4.K3a when 15380 then N47080.CIHIValue when 15381 then Y47080.CIHIValue when 15382 then U47080.CIHIValue end)
                                       else (case CRS_AssessShare4.K3a when 1 then Y.CIHIValue when 2 then N.CIHIValue end) end) AS WeightLoss_K3a, 
    (case when LU_AA8.CIHIValue not in (''05'', ''10'') then (case CRS_AssessShare4.K3a when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end) 
                                       else (case CRS_AssessShare4.K3a when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS WeightLossDesc_K3a, 
    --(case when LU_AA8.CIHIValue not in (''05'', ''10'') then (case CRS_AssessShare4.K3b when 15380 then N47080.DisplayCode when 15381 then Y47080.DisplayCode when 15382 then U47080.DisplayCode end) 
    --                                   else (case CRS_AssessShare4.K3b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS WeightGain_K3b, 
    (case when LU_AA8.CIHIValue not in (''05'', ''10'') then (case CRS_AssessShare4.K3b when 15380 then N47080.CIHIValue when 15381 then Y47080.CIHIValue when 15382 then U47080.CIHIValue end) 
                                       else (case CRS_AssessShare4.K3b when 1 then Y.CIHIValue when 2 then N.CIHIValue end) end) AS WeightGain_K3b, 
    (case when LU_AA8.CIHIValue not in (''05'', ''10'') then (case CRS_AssessShare4.K3b when 15380 then N47080.UserDescription when 15381 then Y47080.UserDescription when 15382 then U47080.UserDescription end)
                                       else (case CRS_AssessShare4.K3b when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS WeightGainDesc_K3b, 

    (case CRS_AssessShare4.K4a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Nutritional_Taste_K4a, 
    (case CRS_AssessShare4.K4a when 1 then Y.UserDescription when 2 then N.UserDescription end) as Nutritional_TasteDesc_K4a, 
    (case CRS_AssessShare4.K4b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Nutritional_Hunger_K4b, 
    (case CRS_AssessShare4.K4b when 1 then Y.UserDescription when 2 then N.UserDescription end) as Nutritional_HungerDesc_K4b, 
    (case CRS_AssessShare4.K4c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Nutritional_LeaveFood_K4c, 
    (case CRS_AssessShare4.K4c when 1 then Y.UserDescription when 2 then N.UserDescription end) as Nutritional_LeaveFoodDesc_K4c, 
    (case when CRS_AssessShare4.K4All > 0 then Y1.DisplayCode end) as Nutritional_None_K4d, 
    --(case when CRS_AssessShare4.K4All > 0 then Y1.UserDescription end) as Nutritional_NoneDesc_K4d, 

    (case CRS_AssessShare4.K5a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as NutritionalAppPatenteral_K5a, 
    (case CRS_AssessShare4.K5a when 1 then Y.UserDescription when 2 then N.UserDescription end) as NutritionalAppPatentDesc_K5a, 
    (case CRS_AssessShare4.K5b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as NutritionalAppFeedTube_K5b, 
    (case CRS_AssessShare4.K5b when 1 then Y.UserDescription when 2 then N.UserDescription end) as NutritionalAppFeedTDesc_K5b, 
    (case CRS_AssessShare4.K5c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as NutritionalAppDiet_K5c, 
    (case CRS_AssessShare4.K5c when 1 then Y.UserDescription when 2 then N.UserDescription end) as NutritionalAppDietDesc_K5c, 
    (case CRS_AssessShare4.K5d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as NutritionalAppSyringe_K5d, 
    (case CRS_AssessShare4.K5d when 1 then Y.UserDescription when 2 then N.UserDescription end) as NutritionalAppSyringeDesc_K5d, 
    (case CRS_AssessShare4.K5e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as NutritionalAppTherapeutic_K5e, 
    (case CRS_AssessShare4.K5e when 1 then Y.UserDescription when 2 then N.UserDescription end) as NutritionalAppTherapeDesc_K5e, 
    (case CRS_AssessShare4.K5f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as NutritionalAppSupplement_K5f, 
    (case CRS_AssessShare4.K5f when 1 then Y.UserDescription when 2 then N.UserDescription end) as NutritionalAppSupplyDesc_K5f, 
    (case CRS_AssessShare4.K5g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as NutritionalAppUtensil_K5g, 
    (case CRS_AssessShare4.K5g when 1 then Y.UserDescription when 2 then N.UserDescription end) as NutritionalAppUtensilDesc_K5g, 
    (case CRS_AssessShare4.K5h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as NutritionalAppWeight_K5h, 
    (case CRS_AssessShare4.K5h when 1 then Y.UserDescription when 2 then N.UserDescription end) as NutritionalAppWeightDesc_K5h, 
    (case when CRS_AssessShare4.K5All > 0 then Y1.DisplayCode end) as NutritionalAppNone_K5i, 
    --(case when CRS_AssessShare4.K5All > 0 then Y1.UserDescription end) as NutritionalAppNoneDesc_K5i, 

    LU_K6a.DisplayCode AS ParenteralProportion_K6a, LU_K6a.UserDescription AS ParenteralProportionDesc_K6a, 
    LU_K6b.DisplayCode AS ParenteralAverage_K6b, LU_K6b.UserDescription AS ParenteralAverageDesc_K6b, 

    dbo.CRS_AssessShare4.M1a as Ulcers_Stage1_M1a, 
    dbo.CRS_AssessShare4.M1b as Ulcers_Stage2_M1b, 
    dbo.CRS_AssessShare4.M1c as Ulcers_Stage3_M1c, 
    dbo.CRS_AssessShare4.M1d as Ulcers_Stage4_M1d, 

    LU_M2a.DisplayCode AS UlcerTypePressure_M2a, LU_M2a.UserDescription AS UlcerType_PressureDesc_M2a, 
    LU_M2b.DisplayCode AS UlcerType_Stasis_M2b, LU_M2b.UserDescription AS UlcerType_StasisDesc_M2b, 

    (case CRS_AssessShare4.M4a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinAbrasions_M4a, 
    (case CRS_AssessShare4.M4a when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinAbrasionsDesc_M4a, 
    (case CRS_AssessShare4.M4b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinBurn_M4b, 
    (case CRS_AssessShare4.M4b when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinBurnDesc_M4b, 
    (case CRS_AssessShare4.M4c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinLesions_M4c, 
    (case CRS_AssessShare4.M4c when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinLesionsDesc_M4c, 
    (case CRS_AssessShare4.M4d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinRashes_M4d, 
    (case CRS_AssessShare4.M4d when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinRashesDesc_M4d, 
    (case CRS_AssessShare4.M4e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinDesensitized_M4e, 
    (case CRS_AssessShare4.M4e when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinDesensitizedDesc_M4e, 
    (case CRS_AssessShare4.M4f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTears_M4f, 
    (case CRS_AssessShare4.M4f when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTearsDesc_M4f, 
    (case CRS_AssessShare4.M4g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinSurgical_M4g, 
    (case CRS_AssessShare4.M4g when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinSurgicalDesc_M4g, 
    (case when CRS_AssessShare4.M4All > 0 then Y1.DisplayCode end) as SkinNone_M4h, 
    --(case when CRS_AssessShare4.M4All > 0 then Y1.UserDescription end) as SkinNoneDesc_M4h, 

    (case CRS_AssessShare4.M5a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTreat_Chair_M5a, 
    (case CRS_AssessShare4.M5a when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTreat_ChairDesc_M5a, 
    (case CRS_AssessShare4.M5b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTreat_Bed_M5b, 
    (case CRS_AssessShare4.M5b when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTreat_BedDesc_M5b, 
    (case CRS_AssessShare4.M5c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTreat_Turning_M5c, 
    (case CRS_AssessShare4.M5c when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTreat_TurningDesc_M5c, 
    (case CRS_AssessShare4.M5d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTreat_Nutrition_M5d, 
    (case CRS_AssessShare4.M5d when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTreat_NutritionDesc_M5d, 
    (case CRS_AssessShare4.M5e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTreat_Ulcer_M5e, 
    (case CRS_AssessShare4.M5e when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTreat_UlcerDesc_M5e, 
    (case CRS_AssessShare4.M5f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTreat_Surgical_M5f, 
    (case CRS_AssessShare4.M5f when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTreat_SurgicalDesc_M5f, 
    (case CRS_AssessShare4.M5g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTreat_Dressing_M5g, 
    (case CRS_AssessShare4.M5g when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTreat_DressingDesc_M5g, 
    (case CRS_AssessShare4.M5h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTreat_Ointment_M5h, 
    (case CRS_AssessShare4.M5h when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTreat_OintmentDesc_M5h, 
    (case CRS_AssessShare4.M5I when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTreat_Other_M5i, 
    (case CRS_AssessShare4.M5I when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTreat_OtherDesc_M5i, 
    (case when CRS_AssessShare4.M5All > 0 then Y1.DisplayCode end) as SkinTreat_None_M5j, 
    --(case when CRS_AssessShare4.M5All > 0 then Y1.UserDescription end) as SkinTreat_NoneDesc_M5j, 

    (case CRS_AssessShare4.M6a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Foot_Problem_M6a, 
    (case CRS_AssessShare4.M6a when 1 then Y.UserDescription when 2 then N.UserDescription end) as Foot_ProblemDesc_M6a, 
    (case CRS_AssessShare4.M6b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Foot_Infection_M6b, 
    (case CRS_AssessShare4.M6b when 1 then Y.UserDescription when 2 then N.UserDescription end) as Foot_InfectionDesc_M6b, 
    (case CRS_AssessShare4.M6c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Foot_Lesion_M6c, 
    (case CRS_AssessShare4.M6c when 1 then Y.UserDescription when 2 then N.UserDescription end) as Foot_LesionDesc_M6c, 
    (case CRS_AssessShare4.M6d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Foot_Nail_M6d, 
    (case CRS_AssessShare4.M6d when 1 then Y.UserDescription when 2 then N.UserDescription end) as Foot_NailDesc_M6d, 
    (case CRS_AssessShare4.M6e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Foot_Preventative_M6e, 
    (case CRS_AssessShare4.M6e when 1 then Y.UserDescription when 2 then N.UserDescription end) as Foot_PreventativeDesc_M6e, 
    (case CRS_AssessShare4.M6f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Foot_Dressing_M6f, 
    (case CRS_AssessShare4.M6f when 1 then Y.UserDescription when 2 then N.UserDescription end) as Foot_DressingDesc_M6f, 
    (case when CRS_AssessShare4.M6All > 0 then Y1.DisplayCode end) as Foot_None_M6g, 
    --(case when CRS_AssessShare4.M6All > 0 then Y1.UserDescription end) as Foot_NoneDesc_M6g, 

    (case CRS_AssessShare4.N1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Awake_Morning_N1a, 
    (case CRS_AssessShare4.N1a when 1 then Y.UserDescription when 2 then N.UserDescription end) as Awake_MorningDesc_N1a, 
    (case CRS_AssessShare4.N1b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Awake_Afternoon_N1b, 
    (case CRS_AssessShare4.N1b when 1 then Y.UserDescription when 2 then N.UserDescription end) as Awake_AfternoonDesc_N1b, 
    (case CRS_AssessShare4.N1c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Awake_Evening_N1c, 
    (case CRS_AssessShare4.N1c when 1 then Y.UserDescription when 2 then N.UserDescription end) as Awake_EveningDesc_N1c, 
    (case when CRS_AssessShare4.N1All > 0 then Y1.DisplayCode end) as Awake_None_N1d, 
    --(case when CRS_AssessShare4.N1All > 0 then Y1.UserDescription end) as Awake_NoneDesc_N1d, 

    LU_N2.DisplayCode AS AverageTime_N2, LU_N2.UserDescription AS AverageTimeDesc_N2, 

    dbo.CRS_AssessShare4.O1 as NumberMedication_O1, 
    dbo.CRS_AssessShare4.O3 as Injection_O3, 
    dbo.CRS_AssessShare4.O4a as Days_Antipsychotic_O4a, 
    dbo.CRS_AssessShare4.O4b as Days_Antianxiety_O4b, 
    dbo.CRS_AssessShare4.O4c as Days_Antidepressant_O4c, 
    dbo.CRS_AssessShare4.O4d as Days_Hypnotic_O4d, 
    dbo.CRS_AssessShare4.O4e as Days_Diuretic_O4e, 
    dbo.CRS_AssessShare4.O4f as Days_Analgesic_O4f,
--Share 5
    (case CRS_AssessShare5.P1aa when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialChemotherapy_P1aa, 
    (case CRS_AssessShare5.P1aa when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialChemotherapyDesc_P1aa, 
    (case CRS_AssessShare5.P1ab when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialDialysis_P1ab, 
    (case CRS_AssessShare5.P1ab when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialDialysisDesc_P1ab, 
    (case CRS_AssessShare5.P1ac when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialIV_P1ac, 
    (case CRS_AssessShare5.P1ac when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialIVDesc_P1ac, 
    (case CRS_AssessShare5.P1ad when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialIntake_P1ad, 
    (case CRS_AssessShare5.P1ad when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialIntakeDesc_P1ad, 
    (case CRS_AssessShare5.P1ae when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialMonitor_P1ae, 
    (case CRS_AssessShare5.P1ae when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialMonitorDesc_P1ae, 
    (case CRS_AssessShare5.P1af when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialOstomy_P1af, 
    (case CRS_AssessShare5.P1af when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialOstomyDesc_P1af, 
    (case CRS_AssessShare5.P1ag when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialOxygen_P1ag, 
    (case CRS_AssessShare5.P1ag when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialOxygenDesc_P1ag, 
    (case CRS_AssessShare5.P1ah when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialRadiation_P1ah, 
    (case CRS_AssessShare5.P1ah when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialRadiationDesc_P1ah, 
    (case CRS_AssessShare5.P1ai when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialSuction_P1ai, 
    (case CRS_AssessShare5.P1ai when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialSuctionDesc_P1ai, 
    (case CRS_AssessShare5.P1aj when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialTrash_P1aj, 
    (case CRS_AssessShare5.P1aj when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialTrashDesc_P1aj, 
    (case CRS_AssessShare5.P1ak when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialTransfusion_P1ak, 
    (case CRS_AssessShare5.P1ak when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialTransfusionDesc_P1ak, 
    (case CRS_AssessShare5.P1al when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialVentilator_P1al, 
    (case CRS_AssessShare5.P1al when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialVentilatorDesc_P1al, 
    (case CRS_AssessShare5.P1am when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialAlcohol_P1am, 
    (case CRS_AssessShare5.P1am when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialAlcoholDesc_P1am, 
    (case CRS_AssessShare5.P1an when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialAlzheimer_P1an, 
    (case CRS_AssessShare5.P1an when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialAlzheimerDesc_P1an, 
    (case CRS_AssessShare5.P1ao when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialHospice_P1ao, 
    (case CRS_AssessShare5.P1ao when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialHospiceDesc_P1ao, 
    (case CRS_AssessShare5.P1ap when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialPediatric_P1ap, 
    (case CRS_AssessShare5.P1ap when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialPediatricDesc_P1ap, 
    (case CRS_AssessShare5.P1aq when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialRespite_P1aq, 
    (case CRS_AssessShare5.P1aq when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialRespiteDesc_P1aq, 
    (case CRS_AssessShare5.P1ar when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialTraining_P1ar, 
    (case CRS_AssessShare5.P1ar when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialTrainingDesc_P1ar, 
    (case when CRS_AssessShare5.P1aAll > 0 then Y1.DisplayCode end) as SpecialNone_P1as, 
    --(case when CRS_AssessShare5.P1aAll > 0 then Y1.UserDescription end) as SpecialNoneDesc_P1as, 

    dbo.CRS_AssessShare5.P1baA as TherapySpeechDay_P1baA, 
    dbo.CRS_AssessShare5.P1baB as TherapySpeechMinute_P1baB, 
    dbo.CRS_AssessShare5.P1bbA as TherapyOccupationDay_P1bbA, 
    dbo.CRS_AssessShare5.P1bbB as TherapyOccupationMinute_P1bbB, 

    dbo.CRS_AssessShare5.P1bcA as TherapyPhysicalDay_P1bcA, 
    dbo.CRS_AssessShare5.P1bcB as TherapyPhysicalMinute_P1bcB, 
    dbo.CRS_AssessShare5.P1bdA as TherapyRespiratoryDay_P1bdA, 
    dbo.CRS_AssessShare5.P1bdB as TherapyRespiratoryMin_P1bdB, 
    dbo.CRS_AssessShare5.P1beA as TherapyPsychologicalDay_P1beA, 
    dbo.CRS_AssessShare5.P1beB as TherapyPsychologicalMin_P1beB, 
    dbo.CRS_AssessShare5.P1bfA as TherapyRecreationDay_P1bfA, 
    dbo.CRS_AssessShare5.P1bfB as TherapyRecreationMinute_P1bfB, 
    dbo.CRS_AssessShare5.P3a as RehabPassive_P3a, 
    dbo.CRS_AssessShare5.P3b as RehabActive_P3b, 
    dbo.CRS_AssessShare5.P3c as RehabSplint_P3c, 
    dbo.CRS_AssessShare5.P3d as RehabBed_P3d, 
    dbo.CRS_AssessShare5.P3e as RehabTransfer_P3e, 
    dbo.CRS_AssessShare5.P3f as RehabWalking_P3f, 
    dbo.CRS_AssessShare5.P3g as RehabDressing_P3g, 
    dbo.CRS_AssessShare5.P3h as RehabEating_P3h, 
    dbo.CRS_AssessShare5.P3I as RehabAmputation_P3i, 
    dbo.CRS_AssessShare5.P3j as RehabCommunication_P3j, 
    dbo.CRS_AssessShare5.P3k as RehabOther_P3k, 
    LU_P4a.DisplayCode AS DeviceFullBed_P4a, LU_P4a.UserDescription AS DeviceFullBedDesc_P4a, 
    LU_P4b.DisplayCode AS DeviceOther_P4b, LU_P4b.UserDescription AS DeviceOtherDesc_P4b, 
    LU_P4c.DisplayCode AS DeviceTrunk_P4c, LU_P4c.UserDescription AS DeviceTrunkDesc_P4c, 
    LU_P4d.DisplayCode AS DeviceLimb_P4d, LU_P4d.UserDescription AS DeviceLimbDesc_P4d, 
    LU_P4e.DisplayCode AS DeviceChair_P4e, LU_P4e.UserDescription AS DeviceChairDesc_P4e, 
    dbo.CRS_AssessShare5.P7 as PhysicianVisit_P7, 
    dbo.CRS_AssessShare5.P8 as PhysicianOrder_P8, 
    LU_Q2.DisplayCode AS OverallChange_Q2, LU_Q2.UserDescription AS OverallChangeDesc_Q2, 
    dbo.CRS_AssessShare5.R2b as CompleteDate_R2b,
--Hobic     NP - 00099
    LU_Fatigue.DisplayCode as Fatigue, LU_Fatigue.UserDescription as FatigueDesc,
    LU_Dyspnea.DisplayCode as Dyspnea, LU_Dyspnea.UserDescription as Dyspneaesc,
    LU_Nausea.DisplayCode  as Nausea,  LU_Nausea.UserDescription  as NauseaDesc,
--Update Records
    BedType_AD2 = LU_AD2.DisplayCode, BedTypeDesc_AD2 = LU_AD2.UserDescription, 
    ElementEffectiveDate_Z12 = dbo.CRS_Demographic.Z12,
    PrivatePayResidentFlag_AD1 = LU_AD1.DisplayCode, --PrivatePayResidentFlagDesc_AD1 = LU_AD2.UserDescription, 
    ProgramType_AD4 = LU_AD4.DisplayCode, 

    SpecialProjectTriggerDate_Z13 = dbo.CRS_Demographic.Z13,

	CRS_Demographic.UniversalEpisodeIdentifier

FROM         dbo.CRS_Demographic with (nolock) INNER JOIN
                      dbo.LU_CodeFile LU_AA8 with (nolock) on dbo.CRS_Demographic.AA8 = LU_AA8.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_Gender with (nolock) on dbo.CRS_Demographic.Gender = LU_Gender.Code LEFT OUTER JOIN
                      dbo.H_InstitutionProfile with (nolock) on dbo.CRS_Demographic.InstitutionNumber = dbo.H_InstitutionProfile.Code LEFT OUTER JOIN
                      dbo.LU_HCNProvince with (nolock) on dbo.LU_HCNProvince.Code = dbo.CRS_Demographic.HCNProvince LEFT OUTER JOIN
                      dbo.U_Users U_TSICoder with (nolock) on dbo.CRS_Demographic.TSICoder = U_TSICoder.Code LEFT OUTER JOIN
                      dbo.LU_YesBlank LU_Secret with (nolock) on dbo.CRS_Demographic.Secret = LU_Secret.Code LEFT OUTER JOIN
                      dbo.U_Users U_DataEntryCoder with (nolock) on dbo.CRS_Demographic.DataEntryCoder = U_DataEntryCoder.Code LEFT OUTER JOIN
                      dbo.U_Users U_InterfaceCoder with (nolock) on dbo.CRS_Demographic.InterfaceCoder = U_InterfaceCoder.Code LEFT OUTER JOIN
                      dbo.U_Users LU_Coder with (nolock) on dbo.CRS_Demographic.CoderNumber = LU_Coder.Code LEFT OUTER JOIN
                      dbo.LU_Site with (nolock) on dbo.CRS_Demographic.SiteNumber = dbo.LU_Site.Code LEFT OUTER JOIN
                      dbo.LU_DeleteStatus LU_IsDeleted with (nolock) on dbo.CRS_Demographic.IsDeleted = LU_IsDeleted.Code LEFT OUTER JOIN
                      dbo.LU_AbstractStatus LU_IsCompleted with (nolock) on dbo.CRS_Demographic.IsCompleted = LU_IsCompleted.Code LEFT OUTER JOIN
                      dbo.LU_AbstractStatus LU_IsValidated with (nolock) on dbo.CRS_Demographic.IsValidated = LU_IsValidated.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_Z1 with (nolock) on dbo.CRS_Demographic.Z1 = LU_Z1.Code LEFT OUTER JOIN
                      dbo.LU_Institution_10 LU_Inst_To with (nolock) on dbo.CRS_Demographic.InstitutionTo = LU_Inst_To.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_R3a with (nolock) on LU_R3a.Code = dbo.CRS_Demographic.R3a LEFT OUTER JOIN
                      dbo.LU_Institution_10 LU_Inst_From with (nolock) on dbo.CRS_Demographic.InstitutionFrom = LU_Inst_From.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AB2c with (nolock) on dbo.CRS_Demographic.AB2c = LU_AB2c.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AB2a with (nolock) on dbo.CRS_Demographic.AB2a = LU_AB2a.Code LEFT OUTER JOIN
                      dbo.LU_NurseArea with (nolock) on dbo.CRS_Demographic.AdmittingNurseArea = dbo.LU_NurseArea.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_MaritalStatus with (nolock) on dbo.CRS_Demographic.MaritalStatus = LU_MaritalStatus.Code LEFT OUTER JOIN
                      dbo.H_HospitalProfile LU_Hospital with (nolock) on dbo.CRS_Demographic.HospitalID = LU_Hospital.Code LEFT OUTER JOIN
                      dbo.LU_CIHICorrect with (nolock) on dbo.CRS_Demographic.IsCorrected = LU_CIHICorrect.Code  left join
                      dbo.LU_CodeFile LU_Y3 with (nolock) on dbo.CRS_Demographic.Y3 = LU_Y3.Code left join
                      dbo.LU_YesNoSystem LU_IsSubmited with (nolock) on dbo.CRS_Demographic.IsSubmited = LU_IsSubmited.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_BatchPeriod with (nolock) on dbo.CRS_Demographic.BatchPeriod = LU_BatchPeriod.Code left join
                      dbo.LU_CodeFile LU_R3c with (nolock) on dbo.CRS_Demographic.R3c = LU_R3c.Code left join
--Admission
             dbo.CRS_Admission with (nolock) on dbo.CRS_Demographic.AbstractID = dbo.CRS_Admission.AbstractID LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AC1w with (nolock) on dbo.CRS_Admission.AC1w = LU_AC1w.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AC1v with (nolock) on dbo.CRS_Admission.AC1v = LU_AC1v.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AC1u with (nolock) on dbo.CRS_Admission.AC1u = LU_AC1u.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AC1t with (nolock) on dbo.CRS_Admission.AC1t = LU_AC1t.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AC1s with (nolock) on dbo.CRS_Admission.AC1s = LU_AC1s.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AC1q with (nolock) on dbo.CRS_Admission.AC1q = LU_AC1q.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AC1p with (nolock) on dbo.CRS_Admission.AC1p = LU_AC1p.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AC1o with (nolock) on dbo.CRS_Admission.AC1o = LU_AC1o.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AC1n with (nolock) on dbo.CRS_Admission.AC1n = LU_AC1n.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AC1m with (nolock) on dbo.CRS_Admission.AC1m = LU_AC1m.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AC1k with (nolock) on dbo.CRS_Admission.AC1k = LU_AC1k.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AC1j with (nolock) on dbo.CRS_Admission.AC1j = LU_AC1j.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AC1i with (nolock) on dbo.CRS_Admission.AC1I = LU_AC1i.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AC1g with (nolock) on dbo.CRS_Admission.AC1g = LU_AC1g.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AC1f with (nolock) on dbo.CRS_Admission.AC1f = LU_AC1f.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AC1e with (nolock) on dbo.CRS_Admission.AC1e = LU_AC1e.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AC1d with (nolock) on dbo.CRS_Admission.AC1d = LU_AC1d.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AC1b with (nolock) on dbo.CRS_Admission.AC1b = LU_AC1b.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AC1a with (nolock) on dbo.CRS_Admission.AC1a = LU_AC1a.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AB10f with (nolock) on dbo.CRS_Admission.AB10f = LU_AB10f.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AB10e with (nolock) on dbo.CRS_Admission.AB10e = LU_AB10e.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AB10d with (nolock) on dbo.CRS_Admission.AB10d = LU_AB10d.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AB10c with (nolock) on dbo.CRS_Admission.AB10c = LU_AB10c.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AB10b with (nolock) on dbo.CRS_Admission.AB10b = LU_AB10b.Code LEFT OUTER JOIN
                      --dbo.LU_CodeFile LU_AB3 with (nolock) on dbo.CRS_Admission.AB3 = LU_AB3.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AB8 with (nolock) on dbo.CRS_Admission.AB8 = LU_AB8.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AB5ALL with (nolock) on dbo.CRS_Admission.AB5All = LU_AB5ALL.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AB5a with (nolock) on dbo.CRS_Admission.AB5a = LU_AB5a.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AB5b with (nolock) on dbo.CRS_Admission.AB5b = LU_AB5b.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AB5c with (nolock) on dbo.CRS_Admission.AB5c = LU_AB5c.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AB5d with (nolock) on dbo.CRS_Admission.AB5d = LU_AB5d.Code LEFT OUTER JOIN
--                       dbo.LU_CodeFile LU_AB5e with (nolock) on dbo.CRS_Admission.AB5e = LU_AB5e.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AB7 with (nolock) on dbo.CRS_Admission.AB7 = LU_AB7.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_AC1c with (nolock) on dbo.CRS_Admission.AC1c = LU_AC1c.Code LEFT OUTER JOIN
                      dbo.LU_ResidenceCode with (nolock) on dbo.CRS_Admission.ResidenceCode = LU_ResidenceCode.Code LEFT OUTER JOIN

--Diagnosis
            dbo.CRS_Diagnosis with (nolock) on dbo.CRS_Demographic.AbstractID = dbo.CRS_Diagnosis.AbstractID LEFT OUTER JOIN
--Full1
    dbo.CRS_AssessFull1 with (nolock) on dbo.CRS_Demographic.AbstractID = dbo.CRS_AssessFull1.AbstractID LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_J3j with (nolock) on dbo.CRS_AssessFull1.J3j = LU_J3j.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_J3I with (nolock) on dbo.CRS_AssessFull1.J3I = LU_J3I.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_J3h with (nolock) on dbo.CRS_AssessFull1.J3h = LU_J3h.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_J3g with (nolock) on dbo.CRS_AssessFull1.J3g = LU_J3g.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_J3f with (nolock) on dbo.CRS_AssessFull1.J3f = LU_J3f.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_J3e with (nolock) on dbo.CRS_AssessFull1.J3e = LU_J3e.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_J3d with (nolock) on dbo.CRS_AssessFull1.J3d = LU_J3d.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_J3c with (nolock) on dbo.CRS_AssessFull1.J3c = LU_J3c.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_J3b with (nolock) on dbo.CRS_AssessFull1.J3b = LU_J3b.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_J3a with (nolock) on dbo.CRS_AssessFull1.J3a = LU_J3a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F3c with (nolock) on dbo.CRS_AssessFull1.F3c = LU_F3c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F3b with (nolock) on dbo.CRS_AssessFull1.F3b = LU_F3b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F3a with (nolock) on dbo.CRS_AssessFull1.F3a = LU_F3a.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_F2g with (nolock) on dbo.CRS_AssessFull1.F2g = LU_F2g.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_F2f with (nolock) on dbo.CRS_AssessFull1.F2f = LU_F2f.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_F2e with (nolock) on dbo.CRS_AssessFull1.F2e = LU_F2e.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_F2d with (nolock) on dbo.CRS_AssessFull1.F2d = LU_F2d.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_F2c with (nolock) on dbo.CRS_AssessFull1.F2c = LU_F2c.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_F2b with (nolock) on dbo.CRS_AssessFull1.F2b = LU_F2b.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_F2a with (nolock) on dbo.CRS_AssessFull1.F2a = LU_F2a.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_D3 with (nolock) on dbo.CRS_AssessFull1.D3 = LU_D3.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_D2b with (nolock) on dbo.CRS_AssessFull1.D2b = LU_D2b.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_D2a with (nolock) on dbo.CRS_AssessFull1.D2a = LU_D2a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_D1 with (nolock) on dbo.CRS_AssessFull1.D1 = LU_D1.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C5 with (nolock) on dbo.CRS_AssessFull1.C5 = LU_C5.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_C3f with (nolock) on dbo.CRS_AssessFull1.C3f = LU_C3f.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_C3e with (nolock) on dbo.CRS_AssessFull1.C3e = LU_C3e.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_C3d with (nolock) on dbo.CRS_AssessFull1.C3d = LU_C3d.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_C3c with (nolock) on dbo.CRS_AssessFull1.C3c = LU_C3c.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_C3b with (nolock) on dbo.CRS_AssessFull1.C3b = LU_C3b.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_C3a with (nolock) on dbo.CRS_AssessFull1.C3a = LU_C3a.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_C2c with (nolock) on dbo.CRS_AssessFull1.C2c = LU_C2c.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_C2b with (nolock) on dbo.CRS_AssessFull1.C2b = LU_C2b.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_C2a with (nolock) on dbo.CRS_AssessFull1.C2a = LU_C2a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_C1 with (nolock) on dbo.CRS_AssessFull1.C1 = LU_C1.Code LEFT OUTER JOIN
--Full2
    dbo.CRS_AssessFull2 with (nolock) on dbo.CRS_Demographic.AbstractID = dbo.CRS_AssessFull2.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_R1c with (nolock) on dbo.CRS_AssessFull2.R1c = LU_R1c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_R1b with (nolock) on dbo.CRS_AssessFull2.R1b = LU_R1b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Q1c with (nolock) on dbo.CRS_AssessFull2.Q1c = LU_Q1c.Code LEFT OUTER JOIN
--    dbo.LU_CodeFile LU_O2 with (nolock) on dbo.CRS_AssessFull2.O2 = LU_O2.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N5b with (nolock) on dbo.CRS_AssessFull2.N5b = LU_N5b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N5a with (nolock) on dbo.CRS_AssessFull2.N5a = LU_N5a.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_N4l with (nolock) on dbo.CRS_AssessFull2.N4l = LU_N4l.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_N4k with (nolock) on dbo.CRS_AssessFull2.N4k = LU_N4k.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_N4j with (nolock) on dbo.CRS_AssessFull2.N4j = LU_N4j.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_N4I with (nolock) on dbo.CRS_AssessFull2.N4I = LU_N4I.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_N4h with (nolock) on dbo.CRS_AssessFull2.N4h = LU_N4h.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_N4g with (nolock) on dbo.CRS_AssessFull2.N4g = LU_N4g.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_N4f with (nolock) on dbo.CRS_AssessFull2.N4f = LU_N4f.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_N4e with (nolock) on dbo.CRS_AssessFull2.N4e = LU_N4e.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_N4d with (nolock) on dbo.CRS_AssessFull2.N4d = LU_N4d.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_N4c with (nolock) on dbo.CRS_AssessFull2.N4c = LU_N4c.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_N4b with (nolock) on LU_N4b.Code = dbo.CRS_AssessFull2.N4b LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_N4a with (nolock) on dbo.CRS_AssessFull2.N4a = LU_N4a.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_N3d with (nolock) on dbo.CRS_AssessFull2.N3d = LU_N3d.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_N3c with (nolock) on LU_N3c.Code = dbo.CRS_AssessFull2.N3c LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_N3b with (nolock) on dbo.CRS_AssessFull2.N3b = LU_N3b.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_N3a with (nolock) on dbo.CRS_AssessFull2.N3a = LU_N3a.Code LEFT OUTER JOIN
--Rugs
    dbo.CRS_RUGS with (nolock) on dbo.CRS_Demographic.AbstractID = dbo.CRS_RUGS.AbstractId LEFT OUTER JOIN 
--Share1
    dbo.CRS_AssessShare1 with (nolock) on dbo.CRS_Demographic.AbstractID = dbo.CRS_AssessShare1.AbstractID
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E5 with (nolock) on dbo.CRS_AssessShare1.E5 = LU_E5.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4eB with (nolock) on dbo.CRS_AssessShare1.E4eB = LU_E4eB.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4eA with (nolock) on LU_E4eA.Code = dbo.CRS_AssessShare1.E4eA 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4dB with (nolock) on dbo.CRS_AssessShare1.E4dB = LU_E4dB.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4dA with (nolock) on dbo.CRS_AssessShare1.E4dA = LU_E4dA.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4cB with (nolock) on dbo.CRS_AssessShare1.E4cB = LU_E4cB.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4cA with (nolock) on LU_E4cA.Code = dbo.CRS_AssessShare1.E4cA 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4bB with (nolock) on dbo.CRS_AssessShare1.E4bB = LU_E4bB.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4bA with (nolock) on LU_E4bA.Code = dbo.CRS_AssessShare1.E4bA 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4aB with (nolock) on dbo.CRS_AssessShare1.E4aB = LU_E4aB.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4aA with (nolock) on dbo.CRS_AssessShare1.E4aA = LU_E4aA.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E3 with (nolock) on dbo.CRS_AssessShare1.E3 = LU_E3.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E2 with (nolock) on dbo.CRS_AssessShare1.E2 = LU_E2.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1p with (nolock) on dbo.CRS_AssessShare1.E1p = LU_E1p.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1o with (nolock) on LU_E1o.Code = dbo.CRS_AssessShare1.E1o 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1n with (nolock) on dbo.CRS_AssessShare1.E1n = LU_E1n.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1m with (nolock) on dbo.CRS_AssessShare1.E1m = LU_E1m.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1l with (nolock) on dbo.CRS_AssessShare1.E1l = LU_E1l.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1k with (nolock) on dbo.CRS_AssessShare1.E1k = LU_E1k.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1j with (nolock) on dbo.CRS_AssessShare1.E1j = LU_E1j.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1I with (nolock) on LU_E1I.Code = dbo.CRS_AssessShare1.E1I 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1h with (nolock) on dbo.CRS_AssessShare1.E1h = LU_E1h.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1g with (nolock) on dbo.CRS_AssessShare1.E1g = LU_E1g.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1f with (nolock) on dbo.CRS_AssessShare1.E1f = LU_E1f.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1e with (nolock) on dbo.CRS_AssessShare1.E1e = LU_E1e.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1d with (nolock) on dbo.CRS_AssessShare1.E1d = LU_E1d.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1c with (nolock) on dbo.CRS_AssessShare1.E1c = LU_E1c.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1b with (nolock) on dbo.CRS_AssessShare1.E1b = LU_E1b.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1a with (nolock) on dbo.CRS_AssessShare1.E1a = LU_E1a.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_C7 with (nolock) on dbo.CRS_AssessShare1.C7 = LU_C7.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_C6 with (nolock) on dbo.CRS_AssessShare1.C6 = LU_C6.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_C4 with (nolock) on dbo.CRS_AssessShare1.C4 = LU_C4.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B6 with (nolock) on dbo.CRS_AssessShare1.B6 = LU_B6.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B5f with (nolock) on dbo.CRS_AssessShare1.B5f = LU_B5f.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B5e with (nolock) on dbo.CRS_AssessShare1.B5e = LU_B5e.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B5d with (nolock) on LU_B5d.Code = dbo.CRS_AssessShare1.B5d 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B5c with (nolock) on dbo.CRS_AssessShare1.B5c = LU_B5c.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B5b with (nolock) on dbo.CRS_AssessShare1.B5b = LU_B5b.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B5a with (nolock) on dbo.CRS_AssessShare1.B5a = LU_B5a.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B4 with (nolock) on LU_B4.Code = dbo.CRS_AssessShare1.B4 
--     LEFT OUTER JOIN dbo.LU_CodeFile LU_B3a with (nolock) on dbo.CRS_AssessShare1.B3a = LU_B3a.Code 
--     LEFT OUTER JOIN dbo.LU_CodeFile LU_B3b with (nolock) on LU_B3b.Code = dbo.CRS_AssessShare1.B3b 
--     LEFT OUTER JOIN dbo.LU_CodeFile LU_B3c with (nolock) on LU_B3c.Code = dbo.CRS_AssessShare1.B3c 
--     LEFT OUTER JOIN dbo.LU_CodeFile LU_B3d with (nolock) on dbo.CRS_AssessShare1.B3d = LU_B3d.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B2b with (nolock) on dbo.CRS_AssessShare1.B2b = LU_B2b.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B2a with (nolock) on dbo.CRS_AssessShare1.B2a = LU_B2a.Code 

    LEFT OUTER JOIN dbo.LU_CodeFile LU_A11a with (nolock) on dbo.CRS_AssessShare1.A11a = LU_A11a.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A11b with (nolock) on dbo.CRS_AssessShare1.A11b = LU_A11b.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A12a with (nolock) on dbo.CRS_AssessShare1.A12a = LU_A12a.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A12b with (nolock) on dbo.CRS_AssessShare1.A12b = LU_A12b.Code 

--     LEFT OUTER JOIN dbo.LU_CodeFile LU_A10h_Q with (nolock) on dbo.CRS_AssessShare1.A10h = LU_A10h_Q.Code 
--     LEFT OUTER JOIN dbo.LU_CodeFile LU_A10g_Q with (nolock) on dbo.CRS_AssessShare1.A10g = LU_A10g_Q.Code 
--     LEFT OUTER JOIN dbo.LU_CodeFile LU_A10f_Q with (nolock) on dbo.CRS_AssessShare1.A10f = LU_A10f_Q.Code 
--     LEFT OUTER JOIN dbo.LU_CodeFile LU_A10e_Q with (nolock) on dbo.CRS_AssessShare1.A10e = LU_A10e_Q.Code 
--     LEFT OUTER JOIN dbo.LU_CodeFile LU_A10d_Q with (nolock) on dbo.CRS_AssessShare1.A10d = LU_A10d_Q.Code 
--     LEFT OUTER JOIN dbo.LU_CodeFile LU_A10c_Q with (nolock) on dbo.CRS_AssessShare1.A10c = LU_A10c_Q.Code 
--     LEFT OUTER JOIN dbo.LU_CodeFile LU_A10b_Q with (nolock) on dbo.CRS_AssessShare1.A10b = LU_A10b_Q.Code 
--     LEFT OUTER JOIN dbo.LU_CodeFile LU_A10a_Q with (nolock) on dbo.CRS_AssessShare1.A10a = LU_A10a_Q.Code 
--     LEFT OUTER JOIN dbo.LU_CodeFile LU_A9f_Q with (nolock) on dbo.CRS_AssessShare1.A9f = LU_A9f_Q.Code 
--     LEFT OUTER JOIN dbo.LU_CodeFile LU_A9e_Q with (nolock) on dbo.CRS_AssessShare1.A9e = LU_A9e_Q.Code 
--     LEFT OUTER JOIN dbo.LU_CodeFile LU_A9d_Q with (nolock) on dbo.CRS_AssessShare1.A9d = LU_A9d_Q.Code 
--     LEFT OUTER JOIN dbo.LU_CodeFile LU_A9c_Q with (nolock) on dbo.CRS_AssessShare1.A9c = LU_A9c_Q.Code 
--     LEFT OUTER JOIN dbo.LU_CodeFile LU_A9b_Q with (nolock) on dbo.CRS_AssessShare1.A9b = LU_A9b_Q.Code 
--     LEFT OUTER JOIN dbo.LU_CodeFile LU_A9a_Q with (nolock) on dbo.CRS_AssessShare1.A9a = LU_A9a_Q.Code 
    LEFT OUTER JOIN
--Share2
    dbo.CRS_AssessShare2 with (nolock) on dbo.CRS_Demographic.AbstractID = dbo.CRS_AssessShare2.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_H4 with (nolock) on dbo.CRS_AssessShare2.H4 = LU_H4.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_H1b with (nolock) on dbo.CRS_AssessShare2.H1b = LU_H1b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_H1a with (nolock) on dbo.CRS_AssessShare2.H1a = LU_H1a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G9 with (nolock) on dbo.CRS_AssessShare2.G9 = LU_G9.Code LEFT OUTER JOIN

    dbo.LU_CodeFile LU_G4fB with (nolock) on LU_G4fB.Code = dbo.CRS_AssessShare2.G4fB LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4fA with (nolock) on dbo.CRS_AssessShare2.G4fA = LU_G4fA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4eB with (nolock) on LU_G4eB.Code = dbo.CRS_AssessShare2.G4eB LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4eA with (nolock) on LU_G4eA.Code = dbo.CRS_AssessShare2.G4eA LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4dB with (nolock) on LU_G4dB.Code = dbo.CRS_AssessShare2.G4dB LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4dA with (nolock) on dbo.CRS_AssessShare2.G4dA = LU_G4dA.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_G4cB with (nolock) on LU_G4cB.Code = dbo.CRS_AssessShare2.G4cB LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4cA with (nolock) on dbo.CRS_AssessShare2.G4cA = LU_G4cA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4bB with (nolock) on dbo.CRS_AssessShare2.G4bB = LU_G4bB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4bA with (nolock) on dbo.CRS_AssessShare2.G4bA = LU_G4bA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4aB with (nolock) on dbo.CRS_AssessShare2.G4aB = LU_G4aB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4aA with (nolock) on dbo.CRS_AssessShare2.G4aA = LU_G4aA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G3b with (nolock) on dbo.CRS_AssessShare2.G3b = LU_G3b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G3a with (nolock) on dbo.CRS_AssessShare2.G3a = LU_G3a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G2B with (nolock) on dbo.CRS_AssessShare2.G2B = LU_G2B.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G2A with (nolock) on dbo.CRS_AssessShare2.G2A = LU_G2A.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1jB with (nolock) on dbo.CRS_AssessShare2.G1jB = LU_G1jB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1jA with (nolock) on dbo.CRS_AssessShare2.G1jA = LU_G1jA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1IB with (nolock) on dbo.CRS_AssessShare2.G1iB = LU_G1IB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1IA with (nolock) on dbo.CRS_AssessShare2.G1iA = LU_G1IA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1hB with (nolock) on dbo.CRS_AssessShare2.G1hB = LU_G1hB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1hA with (nolock) on dbo.CRS_AssessShare2.G1hA = LU_G1hA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1gB with (nolock) on dbo.CRS_AssessShare2.G1gB = LU_G1gB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1gA with (nolock) on dbo.CRS_AssessShare2.G1gA = LU_G1gA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1fB with (nolock) on dbo.CRS_AssessShare2.G1fB = LU_G1fB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1fA with (nolock) on dbo.CRS_AssessShare2.G1fA = LU_G1fA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1eB with (nolock) on dbo.CRS_AssessShare2.G1eB = LU_G1eB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1eA with (nolock) on dbo.CRS_AssessShare2.G1eA = LU_G1eA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1dA with (nolock) on dbo.CRS_AssessShare2.G1dA = LU_G1dA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1dB with (nolock) on dbo.CRS_AssessShare2.G1dB = LU_G1dB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1cB with (nolock) on dbo.CRS_AssessShare2.G1cB = LU_G1cB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1cA with (nolock) on dbo.CRS_AssessShare2.G1cA = LU_G1cA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1bB with (nolock) on dbo.CRS_AssessShare2.G1bB = LU_G1bB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1bA with (nolock) on dbo.CRS_AssessShare2.G1bA = LU_G1bA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1aB with (nolock) on dbo.CRS_AssessShare2.G1aB = LU_G1aB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1aA with (nolock) on dbo.CRS_AssessShare2.G1aA = LU_G1aA.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_F1f with (nolock) on dbo.CRS_AssessShare2.F1f = LU_F1f.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_F1e with (nolock) on dbo.CRS_AssessShare2.F1e = LU_F1e.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_F1d with (nolock) on dbo.CRS_AssessShare2.F1d = LU_F1d.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_F1c with (nolock) on dbo.CRS_AssessShare2.F1c = LU_F1c.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_F1b with (nolock) on dbo.CRS_AssessShare2.F1b = LU_F1b.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_F1a with (nolock) on dbo.CRS_AssessShare2.F1a = LU_F1a.Code LEFT OUTER JOIN
--Share 3
    dbo.CRS_AssessShare3 with (nolock) on dbo.CRS_Demographic.AbstractID = dbo.CRS_AssessShare3.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J2b with (nolock) on dbo.CRS_AssessShare3.J2b = LU_J2b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J2a with (nolock) on dbo.CRS_AssessShare3.J2a = LU_J2a.Code LEFT OUTER JOIN
--Share 4
    dbo.CRS_AssessShare4 with (nolock) on CRS_Demographic.AbstractID = CRS_AssessShare4.AbstractID left join
    dbo.LU_CodeFile LU_N2 with (nolock) on LU_N2.Code = dbo.CRS_AssessShare4.N2 LEFT OUTER JOIN
    dbo.LU_CodeFile LU_M2b with (nolock) on dbo.CRS_AssessShare4.M2b = LU_M2b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_M2a with (nolock) on dbo.CRS_AssessShare4.M2a = LU_M2a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_K6b with (nolock) on dbo.CRS_AssessShare4.K6b = LU_K6b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_K6a with (nolock) on dbo.CRS_AssessShare4.K6a = LU_K6a.Code LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_K3b_Q with (nolock) on LU_K3b_Q.Code = dbo.CRS_AssessShare4.K3b LEFT OUTER JOIN
--     dbo.LU_CodeFile LU_K3a_Q with (nolock) on LU_K3a_Q.Code = dbo.CRS_AssessShare4.K3a LEFT OUTER JOIN
--Share 5
    dbo.CRS_AssessShare5 with (nolock) on CRS_Demographic.AbstractID = CRS_AssessShare5.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Q2 with (nolock) on dbo.CRS_AssessShare5.Q2 = LU_Q2.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_P4e with (nolock) on dbo.CRS_AssessShare5.P4e = LU_P4e.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_P4d with (nolock) on dbo.CRS_AssessShare5.P4d = LU_P4d.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_P4c with (nolock) on dbo.CRS_AssessShare5.P4c = LU_P4c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_P4b with (nolock) on dbo.CRS_AssessShare5.P4b = LU_P4b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_P4a with (nolock) on dbo.CRS_AssessShare5.P4a = LU_P4a.Code LEFT JOIN
--PR - 02377
    LU_Provider LU_AttProvider with (nolock) on dbo.CRS_Demographic.AttendingPhysician = LU_AttProvider.Code LEFT JOIN
    LU_Provider LU_RefProvider with (nolock) on dbo.CRS_Demographic.RefPhysician = LU_RefProvider.Code LEFT JOIN
    LU_MisCode LU_MisCode with (nolock) on dbo.CRS_Demographic.MISCode = LU_MisCode.Code LEFT JOIN
    LU_NurseArea LU_AdmitNurse with (nolock) on dbo.CRS_Demographic.AdmittingNurseArea = LU_AdmitNurse.Code LEFT OUTER JOIN
--NP - 00099 
    dbo.CRS_Hobic with (nolock) on dbo.CRS_Demographic.AbstractID = dbo.CRS_Hobic.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Fatigue with (nolock) on dbo.CRS_Hobic.Fatigue = LU_Fatigue.Code  LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Dyspnea with (nolock) on dbo.CRS_Hobic.Dyspnea = LU_Dyspnea.Code  LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Nausea  with (nolock) on dbo.CRS_Hobic.Nausea  = LU_Nausea.Code LEFT OUTER JOIN

--No tickets
    dbo.CRS_UpdateRecord with (nolock) on dbo.CRS_Demographic.AbstractID = dbo.CRS_UpdateRecord.AbstractID left join
    LU_CodeFile LU_AD1 with (nolock) on dbo.CRS_UpdateRecord.AD1 = LU_AD1.Code left join
    LU_CodeFile LU_AD2 with (nolock) on dbo.CRS_UpdateRecord.AD2 = LU_AD2.Code left join
    LU_CodeFile LU_AD4 with (nolock) on dbo.CRS_UpdateRecord.AD4 = LU_AD4.Code --2.x-0505

--Common
    cross join ( select top 1 DisplayCode, CIHIValue, UserDescription from LU_YesNoSystem where code = 1 ) Y
    cross join ( select top 1 DisplayCode, CIHIValue, UserDescription from LU_YesNoSystem where code = 2 ) N
    cross join ( select top 1 DisplayCode, CIHIValue, UserDescription from LU_CodeFile where LookUpID = 1 ) Y1

    cross join ( select top 1 DisplayCode, CIHIValue, UserDescription from LU_CodeFile where code = 15380 ) N47080
    cross join ( select top 1 DisplayCode, CIHIValue, UserDescription from LU_CodeFile where code = 15381 ) Y47080
    cross join ( select top 1 DisplayCode, CIHIValue, UserDescription from LU_CodeFile where code = 15382 ) U47080

    cross join ( select top 1 DisplayCode, CIHIValue, UserDescription from LU_CodeFile where code = 15383 ) N47081
    cross join ( select top 1 DisplayCode, CIHIValue, UserDescription from LU_CodeFile where code = 15384 ) Y47081
    cross join ( select top 1 DisplayCode, CIHIValue, UserDescription from LU_CodeFile where code = 15385 ) U47081
--QA - 00032 disable the domain securite issue
----PR - 07485
--where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or CRS_Demographic.HospitalID is null or CRS_Demographic.HospitalID = 0
----EN - 00666
--    or Is_Member(nullif(ReportGroup, '''')) = 1
----    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(CRS_Demographic.HospitalID, 0))





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Hobic_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



--Hobic     NP - 00099
CREATE view [dbo].[MDS20_Hobic_VR] 
as
select
    LU_Dyspnea.DisplayCode as Dyspnea, LU_Dyspnea.UserDescription as Dyspneaesc,
    LU_Fatigue.DisplayCode as Fatigue, LU_Fatigue.UserDescription as FatigueDesc,
    LU_Nausea.DisplayCode  as Nausea,  LU_Nausea.UserDescription  as NauseaDesc,
    dbo.CRS_Hobic.AbstractID as zzAbstractLink
FROM         
    dbo.CRS_Hobic with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Fatigue with (nolock) ON dbo.CRS_Hobic.Fatigue = LU_Fatigue.Code  LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Dyspnea with (nolock) ON dbo.CRS_Hobic.Dyspnea = LU_Dyspnea.Code  LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Nausea with (nolock)  ON dbo.CRS_Hobic.Nausea  = LU_Nausea.Code 




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_In_Hospital_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE  view [dbo].[MDS20_In_Hospital_VR]
as
select 
    CCRS.AbstractID as zzAbstractLink,
    CCRS.LinkID as zzLinkBackgroundID
from CRS_Demographic CCRS  with (nolock)
    inner join LU_CodeFile Type with (nolock) on CCRS.AA8 = Type.Code
    left join
    (select LinkID, max( DischargeDate ) as DDate, max( AdmitDate ) as ADate
        from CRS_Demographic Demo with (nolock) inner join LU_CodeFile LU with (nolock) on Demo.AA8 = LU.Code 
        where LU.CIHIValue in (''06'', ''07'', ''08'')
        group by LinkID ) Discharge on CCRS.LinkID = Discharge.LinkID
    left join
    (select LinkID, max( AdmitDate ) as RDate
        from CRS_Demographic Demo with (nolock) inner join LU_CodeFile LU with (nolock) on Demo.AA8 = LU.Code 
        where LU.CIHIValue = ''09''
        group by LinkID ) Re_Entry on CCRS.LinkID = Re_Entry.LinkID

where ( Re_Entry.RDate is null and Discharge.DDate is null) 
    or Discharge.DDate < Re_Entry.RDate
	or (Discharge.DDate = Re_Entry.RDate and Discharge.ADate < Re_Entry.RDate)


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Last_Assessment_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'







CREATE view [dbo].[MDS20_Last_Assessment_VR]
as
select 
    max( CCRS.AbstractID ) as zzAbstractLink,
    CCRS.LinkID as zzLinkBackgroundID
from CRS_Demographic CCRS  with (nolock)
group by CCRS.LinkID








' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Last_Submitted_Assessment_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'







CREATE view [dbo].[MDS20_Last_Submitted_Assessment_VR]
as
select 
    max( CCRS.AbstractID ) as zzAbstractLink,
    CCRS.LinkID as zzLinkBackgroundID
from CRS_Demographic CCRS with (nolock) inner join LU_YesNoSystem YN  with (nolock)
    on CCRS.IsSubmited = YN.Code
where YN.CIHIValue in ( ''1'', ''Y'' )
group by CCRS.LinkID








' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Medication_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'







CREATE VIEW [dbo].[MDS20_Medication_VR]
AS
SELECT     dbo.CRS_Medication.AbstractID AS zzAbstractLink, 
        dbo.CRS_Medication.Occurrence as MedicationOccurrence, 
        dbo.CRS_Medication.U1 AS MedicationName_U1, 
                      LU_U2.DisplayCode AS Route_Administration_U2, LU_U2.UserDescription AS Route_AdministrationDesc_U2, LU_U3.DisplayCode AS Frequency_U3, 
                      LU_U3.UserDescription AS FrequencyDesc_U3, dbo.CRS_Medication.U4 AS AmountAdministered_U4, dbo.CRS_Medication.U5 AS Doses_U5, 
                      dbo.CRS_Medication.U6 AS DIN_U6
FROM         dbo.CRS_Medication with (nolock) LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_U3 with (nolock) ON dbo.CRS_Medication.U3 = LU_U3.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile LU_U2 with (nolock) ON dbo.CRS_Medication.U2 = LU_U2.Code










' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Next_Assessment_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'






CREATE View [dbo].[MDS20_Next_Assessment_VR]
as
select zzLinkID as LinkID, zzChartNumber as ChartNumber, zzAdmitDate as AdmitDate, 
    zzInstitutionNumber as InstitutionNumber,
    zzInstitutionDesc as InstitutionDesc,
    NextAssessmentType = 
    (select DisplayCode from LU_CodeFile 
     where Code = (case when zzLastAssessmentType = ''0'' then 14502    --Admit Full
                        when zzLastAssessmentType in (''1'', ''9'', ''2'' ) then 14506 --Quarter
                        when zzLastAssessmentDate is null and zzLastFullAssessment is null
                        then 14502 --Admit Full
                        when zzLastAssessmentDate is not null and zzLastFullAssessment is null 
                        then (case when datediff( day, zzLastAssessmentDate, zzAdmitDate) > 180 then 14503
                                   else 14506
                             end)
                        else (case when datediff( day, zzLastAssessmentDate, zzLastFullAssessment) < 181 then 14506
                                   else 14503
                             end)
                  end)),
    NextAssessmentTypeDesc = 
    (select UserDescription from LU_CodeFile 
     where Code = (case when zzLastAssessmentType = ''0'' then 14502    --Admit Full
                        when zzLastAssessmentType in (''1'', ''9'', ''2'' ) then 14506 --Quarter
                        when zzLastAssessmentDate is null and zzLastFullAssessment is null
                        then 14502 --Admit Full
                        when zzLastAssessmentDate is not null and zzLastFullAssessment is null 
                        then (case when datediff( day, zzLastAssessmentDate, zzAdmitDate) > 180 then 14503
                                   else 14506
                             end)
                        else (case when datediff( day, zzLastAssessmentDate, zzLastFullAssessment) < 181 then 14506
                                   else 14503
                             end)
                  end)),
    NextAssessmentDate = 
    (case when zzLastAssessmentType = ''0'' then dateadd( day, 14, zzAdmitDate )    --Admit Full
--          when zzLastAssessmentType in (''1'', ''9'', ''2'' ) then dateadd( day, 90, zzLastAssessmentDate ) --Quarter
          when zzLastAssessmentDate is null and zzLastFullAssessment is null
          then dateadd( day, 14, zzAdmitDate ) --Admit Full
          else dateadd( day, 90, zzLastAssessmentDate )
    end),
    LatestAssessmentType = 
    (select DisplayCode from LU_CodeFile 
     where Code = (case when zzLastAssessmentType = ''0'' then 14501    --Admit BackGround
                        when zzLastAssessmentType = ''1'' then 14502    --Admit Full
                        when zzLastAssessmentType = ''9'' then 14510    --ReEntry
                        when zzLastAssessmentType = ''2'' then 14503    --Annual
                        when zzLastAssessmentType = ''5'' then 14506    --Quarter
                  end)),
    LatestAssessmentTypeDesc = 
    (select UserDescription from LU_CodeFile 
     where Code = (case when zzLastAssessmentType = ''0'' then 14501    --Admit BackGround
                        when zzLastAssessmentType = ''1'' then 14502    --Admit Full
                        when zzLastAssessmentType = ''9'' then 14510    --ReEntry
                        when zzLastAssessmentType = ''2'' then 14503    --Annual
                        when zzLastAssessmentType = ''5'' then 14506    --Quarter
                  end)),
    zzLastAssessmentDate as LatestAssessmentDate
from MDS20_TempCalculating_VR







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Notes_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[MDS20_Notes_VR]
AS
SELECT     
   RecordID AS zzAbstractLink,
   LogNote  as AbstractNotes,
   LogDate  as DateLogged,
   LogTime  as TimeLogged,
   U.DisplayCode as CreateBy,
   U.UserDescription as CreatorName        
from dbo.REC_Notes r with (nolock) left join U_users U with (nolock) on r.LogCoder=u.code
where AppID between 470 and 476
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Out_Hospital_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'








CREATE  view [dbo].[MDS20_Out_Hospital_VR]
as
select 
    CCRS.AbstractID as zzAbstractLink,
    CCRS.LinkID as zzLinkBackgroundID
from CRS_Demographic CCRS  with (nolock)
    inner join LU_CodeFile Type  with (nolock) on CCRS.AA8 = Type.Code
    inner join
    (select LinkID, max( DischargeDate ) as DDate
        from CRS_Demographic Demo with (nolock) inner join LU_CodeFile LU with (nolock) on Demo.AA8 = LU.Code 
        where LU.CIHIValue in (''06'', ''07'', ''08'')
        group by LinkID ) Discharge on CCRS.LinkID = Discharge.LinkID
    left join
    (select LinkID, max( AB1b ) as RDate
        from CRS_Demographic Demo with (nolock) inner join LU_CodeFile LU with (nolock) on Demo.AA8 = LU.Code 
        where LU.CIHIValue = ''09''
        group by LinkID ) Re_Entry on CCRS.LinkID = Re_Entry.LinkID

where (Re_Entry.RDate is null and Discharge.DDate is not null) 
    or Discharge.DDate > Re_Entry.RDate












' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Outcome_Scales]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE view [dbo].[MDS20_Outcome_Scales]
as
select
    ADL_Long, ADL_Short, 
    ADL_Self = LU_ADL_Self.DisplayCode,             ADL_Self_Desc = LU_ADL_Self.UserDescription, 
    [ABS], CHESS, 
    CPS = LU_CPS.DisplayCode,                       CPS_Desc = LU_CPS.UserDescription, 
    DRS, ISE,
    Pain = LU_Pain.DisplayCode,                     Pain_Desc = LU_Pain.UserDescription, 
    PSI, PURS, FRS,

    dbo.CRS_Demographic.A3 AS AssessmentDate_A3, 
    dbo.CRS_Demographic.ChartNumber AS HealthRecordNumber_A6a,
    dbo.CRS_Demographic.AA1 AS URI_AA1, 
    dbo.CRS_Demographic.BirthDate AS Birthdate_AA3a, 
    dbo.H_InstitutionProfile.DisplayCode AS FacilityNumber_AA6, dbo.H_InstitutionProfile.UserDescription AS FacilityNumberDesc_AA6, 
    LU_AA8.DisplayCode AS ReasonAssessment_AA8, LU_AA8.CIHIValue AS AA8_CIHI, LU_AA8.UserDescription AS ReasonAssessmentDesc_AA8, 
    dbo.CRS_Demographic.AdmitDate AS AdmissionDate_AB1, 

    LU_B1.DisplayCode AS Comatose_B1,               LU_B1.UserDescription AS ComatoseDesc_B1, 
    LU_B2a.DisplayCode AS MemoryShort_B2a,          LU_B2a.UserDescription AS MemoryShortDesc_B2a, 
    LU_B4.DisplayCode AS CognitiveSkills_B4,        LU_B4.UserDescription AS CognitiveSkillsDesc_B4, 
    LU_B5e.DisplayCode AS DisorderLethargy_B5e,     LU_B5e.UserDescription AS DisorderLethargyDesc_B5e, 
    LU_B6.DisplayCode AS ChangeCognitive_B6,        LU_B6.UserDescription AS ChangeCognitiveDesc_B6, 
    LU_C4.DisplayCode AS UnderStood_C4,             LU_C4.UserDescription AS UnderStoodDesc_C4, 
    LU_C6.DisplayCode AS AbilityUnderStood_C6,      LU_C6.UserDescription AS AbilityUnderStoodDesc_C6, 

    LU_E1a.DisplayCode AS DepressionNegative_E1a,   LU_E1a.UserDescription AS DepressionNegativeDesc_E1a, 
    LU_E1c.DisplayCode AS DepressionRepeatVerb_E1c, LU_E1c.UserDescription AS DepressionRepeatVerbDesc_E1c, 
    LU_E1d.DisplayCode AS DepressionAnger_E1d,      LU_E1d.UserDescription AS DepressionAngerDesc_E1d, 
    LU_E1f.DisplayCode AS DepressionUnrealistic_E1f, LU_E1f.UserDescription AS DepressionUnrealisticDesc_E1f, 
    LU_E1g.DisplayCode AS DepressionTerrible_E1g,   LU_E1g.UserDescription AS DepressionTerribleDesc_E1g, 
    LU_E1h.DisplayCode AS DepressionComplaints_E1h, LU_E1h.UserDescription AS DepressionComplaintsDesc_E1h, 
    LU_E1I.DisplayCode AS DepressionNonHealth_E1i,  LU_E1I.UserDescription AS DepressionNonHealthDesc_E1i, 
    LU_E1l.DisplayCode AS DepressionSad_E1l,        LU_E1l.UserDescription AS DepressionSadDesc_E1l, 
    LU_E1m.DisplayCode AS DepressionCrying_E1m,     LU_E1m.UserDescription AS DepressionCryingDesc_E1m, 

    LU_E4aA.DisplayCode AS BehaviorWanderingFre_E4aA, LU_E4aA.UserDescription AS BehaviorWanderingFreDesc_E4aA, 
    LU_E4bA.DisplayCode AS BehaviorVerballyFre_E4bA, LU_E4bA.UserDescription AS BehaviorVerballyFreDesc_E4bA, 
    LU_E4cA.DisplayCode AS BehaviorPhysicallyFre_E4cA, LU_E4cA.UserDescription AS BehaviorPhysicalFreDesc_E4cA, 
    LU_E4dA.DisplayCode AS BehaviorSociallyFre_E4dA, LU_E4dA.UserDescription AS BehaviorSociallyFreDesc_E4dA, 
    LU_E4eA.DisplayCode AS BehaviorResistsFre_E4eA, LU_E4eA.UserDescription AS BehaviorResistsFreDesc_E4eA, 

    LU_F1a.DisplayCode AS Interacting_F1a,          LU_F1a.UserDescription AS InteractingDesc_F1a, 
    LU_F1b.DisplayCode AS PlanActivity_F1b,         LU_F1b.UserDescription AS PlanActivityDesc_F1b, 
    LU_F1c.DisplayCode AS SelfActivity_F1c,         LU_F1c.UserDescription AS SelfActivityDesc_F1c, 
    LU_F1d.DisplayCode AS Goals_F1d,                LU_F1d.UserDescription AS GoalsDesc_F1d, 
    LU_F1e.DisplayCode AS Pursues_F1e,              LU_F1e.UserDescription AS PursuesDesc_F1e, 
    LU_F1f.DisplayCode AS Accepts_F1f,              LU_F1f.UserDescription AS AcceptsDesc_F1f, 



    LU_G1aA.DisplayCode AS BedMobilitySelf_G1aA,    LU_G1aA.UserDescription AS BedMobilitySelfDesc_G1aA, 
    LU_G1bA.DisplayCode AS TransferSelf_G1bA,       LU_G1bA.UserDescription AS TransferSelfDesc_G1bA, 
    LU_G1dA.DisplayCode AS RorridorSelf_G1dA, LU_G1dA.UserDescription AS RorridorSelfDesc_G1dA, 
    LU_G1eA.DisplayCode AS OnUnitSelf_G1eA,         LU_G1eA.UserDescription AS OnUnitSelfDesc_G1eA, 
    LU_G1gA.DisplayCode AS DressingSelf_G1gA,       LU_G1gA.UserDescription AS DressingSelfDesc_G1gA, 
    LU_G1hA.DisplayCode AS EatingSelf_G1hA,         LU_G1hA.UserDescription AS EatingSelfDesc_G1hA, 
    LU_G1IA.DisplayCode AS ToiletSelf_G1iA,         LU_G1IA.UserDescription AS ToiletSelfDesc_G1iA, 
    LU_G1jA.DisplayCode AS HygieneSelf_G1jA,        LU_G1jA.UserDescription AS HygieneSelfDesc_G1jA, 
    LU_G9.DisplayCode AS ChangeADL_G9,              LU_G9.UserDescription AS ChangeADLDesc_G9, 

    LU_H1a.DisplayCode AS BowlContinence_H1a,       LU_H1a.UserDescription AS BowlContinenceDesc_H1a,     

    LU_J1c.DisplayCode as ProblemDehydrated_J1c,    LU_J1c.UserDescription as ProblemDehydratedDesc_J1c, 
    LU_J1g.DisplayCode as ProblemEdema_J1g,         LU_J1g.UserDescription as ProblemEdemaDesc_J1g, 
    LU_J1l.DisplayCode as ProblemBreath_J1l,        LU_J1l.UserDescription as ProblemBreathDesc_J1l, 
    LU_J1o.DisplayCode as ProblemVomiting_J1o,      LU_J1o.UserDescription as ProblemVomitingDesc_J1o, 
    LU_J2a.DisplayCode AS Pain_Frequency_J2a,       LU_J2a.UserDescription AS Pain_FrequencyDesc_J2a, 
    LU_J2b.DisplayCode AS Pain_Intensity_J2b,       LU_J2b.UserDescription AS Pain_IntensityDesc_J2b, 

    LU_J4a.DisplayCode as AccidentFell30_J4a, LU_J4a.UserDescription as AccidentFell30Desc_J4a, 
    LU_J4b.DisplayCode as AccidentFell180_J4b, LU_J4b.UserDescription as AccidentFell180Desc_J4b, 
    LU_J4c.DisplayCode as AccidentHipFracture_J4c,   LU_J4c.UserDescription as AccidentHipFractureDesc_J4c, 
    LU_J4d.DisplayCode as AccidentOtherFracture_J4d, LU_J4d.UserDescription as AccidentOtherFractureDesc_J4d, 

    LU_J5a.DisplayCode as Stability_Unstable_J5a,   LU_J5a.UserDescription as Stability_UnstableDesc_J5a, 
    LU_J5b.DisplayCode as Stability_Acute_J5b,      LU_J5b.UserDescription as Stability_AcuteDesc_J5b, 
    LU_J5c.DisplayCode as Stability_EndStage_J5c,   LU_J5c.UserDescription as Stability_EndStageDesc_J5c, 

    --PR - 05185    two lookup table has different displaycode.
    (case when LU_AA8.CIHIValue in (''05'', ''10'') then LU_K3a_Q.CIHIValue else LU_K3a_F.CIHIValue end) AS WeightLoss_K3a, 
    (case when LU_AA8.CIHIValue in (''05'', ''10'') then LU_K3a_Q.UserDescription else LU_K3a_F.UserDescription end) AS WeightLossDesc_K3a, 

    dbo.CRS_AssessShare4.K2a as Height_K2a, dbo.CRS_AssessShare4.K2b as Weight_K2b, 
    LU_K4c.DisplayCode as Nutritional_LeaveFood_K4c, LU_K4c.UserDescription as Nutritional_LeaveFoodDesc_K4c, 

    LU_M2a.DisplayCode AS UlcerTypePressure_M2a,    LU_M2a.UserDescription AS UlcerType_PressureDesc_M2a, 
    LU_M2b.DisplayCode AS UlcerType_Stasis_M2b,     LU_M2b.UserDescription AS UlcerType_StasisDesc_M2b, 

    LU_Q2.DisplayCode AS OverallChange_Q2,          LU_Q2.UserDescription AS OverallChangeDesc_Q2, 

    dbo.CRS_Demographic.AbstractID AS zzAbstractLink, dbo.CRS_Demographic.LinkID AS zzLinkBackgroundID

from dbo.CRS_OutcomeScale with (nolock)
    left join dbo.lu_codefile LU_ADL_Self with (nolock) on dbo.CRS_OutcomeScale.ADL_Self = LU_ADL_Self.Code
    left join dbo.lu_codefile LU_CPS with (nolock) on dbo.CRS_OutcomeScale.CPS = LU_CPS.Code
    left join dbo.lu_codefile LU_Pain with (nolock) on dbo.CRS_OutcomeScale.Pain = LU_Pain.Code

    inner join dbo.CRS_Demographic with (nolock) on dbo.CRS_OutcomeScale.AbstractID = dbo.CRS_Demographic.AbstractID
    inner join dbo.LU_CodeFile LU_AA8 with (nolock) on dbo.CRS_Demographic.AA8 = LU_AA8.Code 
    left join  dbo.H_InstitutionProfile with (nolock) on dbo.CRS_Demographic.InstitutionNumber = dbo.H_InstitutionProfile.Code 

    left join dbo.CRS_AssessShare1 with (nolock) on CRS_AssessShare1.AbstractID = dbo.CRS_Demographic.AbstractID
    left join dbo.LU_YesNoSystem LU_B1 with (nolock) on LU_B1.code = dbo.CRS_AssessShare1.B1
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B2a with (nolock) on dbo.CRS_AssessShare1.B2a = LU_B2a.Code 
    left join dbo.LU_CodeFile LU_B4 with (nolock) on LU_B4.Code = dbo.CRS_AssessShare1.B4 
    left join dbo.LU_CodeFile LU_B5e with (nolock) on dbo.CRS_AssessShare1.B5e = LU_B5e.Code 
    left join dbo.LU_CodeFile LU_B6 with (nolock) on dbo.CRS_AssessShare1.B6 = LU_B6.Code 
    left join dbo.LU_CodeFile LU_C4 with (nolock) on dbo.CRS_AssessShare1.C4 = LU_C4.Code 
    left join dbo.LU_CodeFile LU_C6 with (nolock) on dbo.CRS_AssessShare1.C6 = LU_C6.Code 

    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1a with (nolock) on dbo.CRS_AssessShare1.E1a = LU_E1a.Code 
    left join dbo.LU_CodeFile LU_E1c with (nolock) on dbo.CRS_AssessShare1.E1c = LU_E1c.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1d with (nolock) on dbo.CRS_AssessShare1.E1d = LU_E1d.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1f with (nolock) on dbo.CRS_AssessShare1.E1f = LU_E1f.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1g with (nolock) on dbo.CRS_AssessShare1.E1g = LU_E1g.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1h with (nolock) on dbo.CRS_AssessShare1.E1h = LU_E1h.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1I with (nolock) on dbo.CRS_AssessShare1.E1I = LU_E1I.Code
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1l with (nolock) on dbo.CRS_AssessShare1.E1l = LU_E1l.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1m with (nolock) on dbo.CRS_AssessShare1.E1m = LU_E1m.Code 


    LEFT JOIN dbo.LU_CodeFile LU_E4aA with (nolock) on dbo.CRS_AssessShare1.E4aA = LU_E4aA.Code 
    left join dbo.LU_CodeFile LU_E4bA with (nolock) on LU_E4bA.Code = dbo.CRS_AssessShare1.E4bA 
    left join dbo.LU_CodeFile LU_E4cA with (nolock) on LU_E4cA.Code = dbo.CRS_AssessShare1.E4cA 
    left join dbo.LU_CodeFile LU_E4dA with (nolock) on dbo.CRS_AssessShare1.E4dA = LU_E4dA.Code 
    left join dbo.LU_CodeFile LU_E4eA with (nolock) on LU_E4eA.Code = dbo.CRS_AssessShare1.E4eA 

    left join dbo.CRS_AssessShare2 with (nolock) on CRS_AssessShare2.AbstractID = dbo.CRS_Demographic.AbstractID
    left join dbo.LU_CodeFile LU_F1a with (nolock) on dbo.CRS_AssessShare2.F1a = LU_F1a.Code 
    left join dbo.LU_CodeFile LU_F1b with (nolock) on dbo.CRS_AssessShare2.F1b = LU_F1b.Code 
    left join dbo.LU_CodeFile LU_F1c with (nolock) on dbo.CRS_AssessShare2.F1c = LU_F1c.Code 
    left join dbo.LU_CodeFile LU_F1d with (nolock) on dbo.CRS_AssessShare2.F1d = LU_F1d.Code 
    left join dbo.LU_CodeFile LU_F1e with (nolock) on dbo.CRS_AssessShare2.F1e = LU_F1e.Code 
    left join dbo.LU_CodeFile LU_F1f with (nolock) on dbo.CRS_AssessShare2.F1f = LU_F1f.Code 

    left join dbo.LU_CodeFile LU_G1aA with (nolock) on dbo.CRS_AssessShare2.G1aA = LU_G1aA.Code 
    left join dbo.LU_CodeFile LU_G1bA with (nolock) on dbo.CRS_AssessShare2.G1bA = LU_G1bA.Code 
    left join dbo.LU_CodeFile LU_G1dA with (nolock) on dbo.CRS_AssessShare2.G1dA = LU_G1dA.Code
    left join dbo.LU_CodeFile LU_G1eA with (nolock) on dbo.CRS_AssessShare2.G1eA = LU_G1eA.Code 
    left join dbo.LU_CodeFile LU_G1gA with (nolock) on dbo.CRS_AssessShare2.G1gA = LU_G1gA.Code 
    left join dbo.LU_CodeFile LU_G1hA with (nolock) on dbo.CRS_AssessShare2.G1hA = LU_G1hA.Code 
    left join dbo.LU_CodeFile LU_G1IA with (nolock) on dbo.CRS_AssessShare2.G1iA = LU_G1IA.Code 
    left join dbo.LU_CodeFile LU_G1jA with (nolock) on dbo.CRS_AssessShare2.G1jA = LU_G1jA.Code 
    left join dbo.LU_CodeFile LU_G9 with (nolock) on LU_G9.code = CRS_AssessShare2.G9
    left join dbo.LU_CodeFile LU_H1a with (nolock) on dbo.CRS_AssessShare2.H1a = LU_H1a.Code 

    left join dbo.CRS_AssessShare3 with (nolock) on CRS_AssessShare3.AbstractID = dbo.CRS_Demographic.AbstractID
    left join dbo.LU_YesNoSystem LU_J1c with (nolock) on LU_J1c.code = CRS_AssessShare3.J1c
    left join dbo.LU_YesNoSystem LU_J1g with (nolock) on LU_J1g.code = CRS_AssessShare3.J1g
    left join dbo.LU_YesNoSystem LU_J1l with (nolock) on LU_J1l.code = CRS_AssessShare3.J1l
    left join dbo.LU_YesNoSystem LU_J1o with (nolock) on LU_J1o.code = CRS_AssessShare3.J1o
    left join dbo.LU_CodeFile LU_J2a with (nolock) on dbo.CRS_AssessShare3.J2a = LU_J2a.Code 
    left join dbo.LU_CodeFile LU_J2b with (nolock) on dbo.CRS_AssessShare3.J2b = LU_J2b.Code 

    left join dbo.LU_YesNoSystem LU_J4a with (nolock) on LU_J4a.code = CRS_AssessShare3.J4a
    left join dbo.LU_YesNoSystem LU_J4b with (nolock) on LU_J4b.code = CRS_AssessShare3.J4b
    left join dbo.LU_YesNoSystem LU_J4c with (nolock) on LU_J4c.code = CRS_AssessShare3.J4c
    left join dbo.LU_YesNoSystem LU_J4d with (nolock) on LU_J4d.code = CRS_AssessShare3.J4d
    left join dbo.LU_YesNoSystem LU_J5a with (nolock) on LU_J5a.code = CRS_AssessShare3.J5a
    left join dbo.LU_YesNoSystem LU_J5b with (nolock) on LU_J5b.code = CRS_AssessShare3.J5b
    left join dbo.LU_YesNoSystem LU_J5c with (nolock) on LU_J5c.code = CRS_AssessShare3.J5c

    left join dbo.CRS_AssessShare4 with (nolock) on CRS_AssessShare4.AbstractID = dbo.CRS_Demographic.AbstractID
    left join dbo.LU_CodeFile LU_K3a_F  with (nolock) on LU_K3a_F.Code = dbo.CRS_AssessShare4.K3a 
    left join dbo.LU_YesNoSystem LU_K3a_Q with (nolock) on LU_K3a_Q.code = CRS_AssessShare4.K3a

    left join dbo.LU_YesNoSystem LU_K4c with (nolock) on LU_K4c.code = CRS_AssessShare4.K4c
    left join dbo.LU_CodeFile LU_M2a with (nolock) on dbo.CRS_AssessShare4.M2a = LU_M2a.Code 
    left join dbo.LU_CodeFile LU_M2b with (nolock) on dbo.CRS_AssessShare4.M2b = LU_M2b.Code 

    left join dbo.CRS_AssessShare5 with (nolock) on CRS_AssessShare5.AbstractID = dbo.CRS_Demographic.AbstractID
    left join LU_CodeFile LU_Q2 with (nolock) on LU_Q2.code = CRS_AssessShare5.Q2





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_PURS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE View [dbo].[MDS20_PURS_VR] 
as
select
    LU_G1aA.DisplayCode AS BedMobilitySelf_G1aA, LU_G1aA.UserDescription AS BedMobilitySelfDesc_G1aA, 
    LU_H1a.DisplayCode AS BowlContinence_H1a,    LU_H1a.UserDescription AS BowlContinenceDesc_H1a, 

    LU_J2a.DisplayCode AS Pain_Frequency_J2a,    LU_J2a.UserDescription AS Pain_FrequencyDesc_J2a, 
    LU_J1l.DisplayCode as ProblemBreath_J1l,     LU_J1l.UserDescription as ProblemBreathDesc_J1l, 
    dbo.CRS_OutcomeScale.PURS,

    LU_AA8.DisplayCode AS ReasonAssessment_AA8,    LU_AA8.UserDescription AS ReasonAssessmentDesc_AA8, 

    LU_M3.DisplayCode as ResolveUlcers_M3,       LU_M3.UserDescription as ResolveUlcersDesc_M3, 
    LU_M2a.DisplayCode AS UlcerTypePressure_M2a, LU_M2a.UserDescription AS UlcerType_PressureDesc_M2a, 
    LU_M2b.DisplayCode AS UlcerType_Stasis_M2b,  LU_M2b.UserDescription AS UlcerType_StasisDesc_M2b, 
    LU_G1cA.DisplayCode AS WalkInRoomSelf_G1cA,  LU_G1cA.UserDescription AS WalkInRoomSelfDesc_G1cA,
    --PR - 05186 K3a use CIHIValue instead of displaycode because the displaycode value are different between two table
    (case when LU_AA8.CIHIValue in (''05'', ''10'') then LU_K3a_Q.CIHIValue else LU_K3a_F.CIHIValue  end) AS WeightLoss_K3a, 
    (case when LU_AA8.CIHIValue in (''05'', ''10'') then LU_K3a_Q.UserDescription else LU_K3a_F.UserDescription end) AS WeightLossDesc_K3a, 
    dbo.CRS_Demographic.AbstractID as zzAbstractLink, dbo.CRS_Demographic.LinkID AS zzLinkBackgroundID
from dbo.CRS_Demographic with (nolock) inner JOIN
    LU_CodeFile LU_AA8 with (nolock) on dbo.CRS_Demographic.AA8 = LU_AA8.code LEFT OUTER JOIN
    dbo.CRS_AssessShare4 with (nolock) on dbo.CRS_AssessShare4.AbstractID = dbo.CRS_Demographic.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_M2b with (nolock) on dbo.CRS_AssessShare4.M2b = LU_M2b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_M2a with (nolock) on dbo.CRS_AssessShare4.M2a = LU_M2a.Code LEFT OUTER JOIN
    
    dbo.LU_CodeFile LU_K3a_F with (nolock) on LU_K3a_F.Code = dbo.CRS_AssessShare4.K3a LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_K3a_Q with (nolock) on dbo.CRS_AssessShare4.K3a = LU_K3a_Q.Code LEFT OUTER JOIN

    dbo.CRS_AssessFull2 with (nolock) on dbo.CRS_AssessFull2.AbstractID = dbo.CRS_Demographic.AbstractID LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M3 with (nolock) on dbo.CRS_AssessFull2.M3 = LU_M3.Code LEFT OUTER JOIN

    dbo.CRS_AssessShare3 with (nolock) on dbo.CRS_AssessShare3.AbstractID = dbo.CRS_Demographic.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J2a with (nolock) on dbo.CRS_AssessShare3.J2a = LU_J2a.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J1l with (nolock) on dbo.CRS_AssessShare3.J1l = LU_J1l.Code LEFT OUTER JOIN

    dbo.CRS_AssessShare2 with (nolock) on dbo.CRS_AssessShare2.AbstractID = dbo.CRS_Demographic.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1cA with (nolock) on dbo.CRS_AssessShare2.G1cA = LU_G1cA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1aA with (nolock) on dbo.CRS_AssessShare2.G1aA = LU_G1aA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_H1a with (nolock) on dbo.CRS_AssessShare2.H1a = LU_H1a.Code inner JOIN
    
    dbo.CRS_OutcomeScale with (nolock) on CRS_OutcomeScale.AbstractID = CRS_Demographic.AbstractID
    
where LU_AA8.CIHIValue in (''02'', ''03'', ''04'', ''05'', ''10'') or (LU_AA8.CIHIValue = ''01'' and dbo.CRS_Demographic.AA8 = 14502)



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quality_Indicators_Detail_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
--ED - 01967
CREATE view [dbo].[MDS20_Quality_Indicators_Detail_VR]
as
select 
	selection.A3, selection.AdmitDate, 
	AssessmentType = LU_AA8.DisplayCode, AssessmentType_Desc = LU_AA8.UserDescription,
	selection.CalendarYear, selection.CalendarQuarter, 
	FiscalYear = selection.CalendarYear - (case when selection.CalendarQuarter = 1 then 1 else 0 end),
	FiscalQuarter = (case when selection.CalendarQuarter = 1 then 4 else selection.CalendarQuarter - 1 end),


	H_InstitutionProfile.DisplayCode as InstitutionNumber,  
	H_InstitutionProfile.UserDescription as InstitutionNumberDesc, 
	selection.AbstractID as zzAbstractLink,
	selection.LinkID as zzAssessmentLink,
	cc_Prev_Ax_Flag as zzPrevQuarterAbstractLink,
	
	--Assessment Selection for Prevalence Quality and Intake Profile Indicators
	cc_QI_Flag, cc_IP_Flag, cc_Inc_QI_Flag, 
	(case when cc_Prev_Ax_Flag > 0 then 1 else 0 end) as cc_Prev_Ax_Flag,
	--Prevalence of Falls
	cc_Fall_D = 1,
	cc_Fall_N = (case when LU_J4a.CIHIValue = ''1'' then 1 else 0 end),
	--Prevalence of Behavioural Symptoms Affecting Others
	cc_BehavSymptoms_D = 1,
	cc_BehavSymptoms_N = (case when LU_E4bA.CIHIValue in (''1'', ''2'', ''3'') then 1
							   when LU_E4cA.CIHIValue in (''1'', ''2'', ''3'') then 1
							   when LU_E4dA.CIHIValue in (''1'', ''2'', ''3'') then 1
						       else 0 end),
	cc_BehavSymptoms_Risk =	(case when LU_B4.CIHIValue in (''1'', ''2'', ''3'') and LU_B2a.CIHIValue = ''1'' then 1
							      when LU_I1ii.CIHIValue = ''1'' then 1
							      when LU_I1hh.CIHIValue = ''1'' then 1
							      else 0 end),
	--Prevalence of Symptoms of Depression
	cc_DepressionSymptoms_D = 1,
	cc_DepressionSymptoms_N = (case when ((case when LU_E1a.CIHIValue in (''1'', ''2'') then 1 else 0 end) +
										  (case when LU_E1n.CIHIValue in (''1'', ''2'') or 
													 LU_E4eA.CIHIValue in (''1'', ''2'', ''3'') or
													 LU_E1o.CIHIValue in (''1'', ''2'') or
													 LU_E1p.CIHIValue in (''1'', ''2'') then 1 else 0 end) +
										  (case when LU_E1j.CIHIValue in (''1'', ''2'') or
  													 (cast(isnull(LU_N1a.CIHIValue, ''0'') as int) +
													  cast(isnull(LU_N1b.CIHIValue, ''0'') as int) +
													  cast(isnull(LU_N1c.CIHIValue, ''0'') as int)) = 0 or
													 ((cast(isnull(LU_N1a.CIHIValue, ''0'') as int) +
													  cast(isnull(LU_N1b.CIHIValue, ''0'') as int) +
													  cast(isnull(LU_N1c.CIHIValue, ''0'') as int)) <= 1 
														and LU_B1.CIHIValue = ''0'')
												then 1 else 0 end) +
										   (case when LU_E1g.CIHIValue in (''1'', ''2'') then 1 else 0 end) +
										   (case when LU_K3a_472.CIHIValue = ''1'' or LU_K3a_473.CIHIValue = ''1''
												 then 1 else 0 end)) >= 2 and LU_E2.CIHIValue in (''1'', ''2'') 
									then 1 else 0 end),

	--Prevalence of Depression Without Anti-Depressant Therapy
	cc_DepWOAntiDepThpy_D = 1,									
	cc_DepWOAntiDepThpy_N = (case when isnull(CRS_AssessShare4.O4c, 0) = 0 and
										((case when LU_E1a.CIHIValue in (''1'', ''2'') then 1 else 0 end) +
										 (case when LU_E1n.CIHIValue in (''1'', ''2'') or 
													LU_E4eA.CIHIValue in (''1'', ''2'', ''3'') or
													LU_E1o.CIHIValue in (''1'', ''2'') or
													LU_E1p.CIHIValue in (''1'', ''2'') then 1 else 0 end) +
										 (case when LU_E1j.CIHIValue in (''1'', ''2'') or
  														 (cast(isnull(LU_N1a.CIHIValue, ''0'') as int) +
														  cast(isnull(LU_N1b.CIHIValue, ''0'') as int) +
														  cast(isnull(LU_N1c.CIHIValue, ''0'') as int)) = 0 or
														 ((cast(isnull(LU_N1a.CIHIValue, ''0'') as int) +
														  cast(isnull(LU_N1b.CIHIValue, ''0'') as int) +
														  cast(isnull(LU_N1c.CIHIValue, ''0'') as int)) <= 1 
															and LU_B1.CIHIValue = ''0'')
													then 1 else 0 end) +
										 (case when LU_E1g.CIHIValue in (''1'', ''2'') then 1 else 0 end) +
										 (case when LU_K3a_472.CIHIValue = ''1'' or LU_K3a_473.CIHIValue = ''1''
										         then 1 else 0 end)) >= 2 
								  then 1 else 0 end),
	--Prevalence of Use of 9 or More Different Medications
	cc_NinePlusMedications_D = 1,					   
	cc_NinePlusMedications_N = (case when CRS_AssessShare4.O1 >= 9 
									 then 1
									 else 0 end),
	--Prevalence of Bladder or Bowel Incontinence
	cc_Incontinence_D = (case when LU_B1.CIHIValue = ''1'' OR LU_H3d.CIHIValue = ''1'' OR LU_H3i.CIHIValue = ''1''
							  then 0
							  else 1 end),
	cc_Incontinence_N = (case when not (LU_B1.CIHIValue = ''1'' OR LU_H3d.CIHIValue = ''1'' OR LU_H3i.CIHIValue = ''1'')
							  then (case when (LU_H1b.CIHIValue in (''3'', ''4'') OR LU_H1a.CIHIValue in (''3'', ''4'')) then 1 else 0 end)
							  else null end), --ED - 02171 change 0 to null
	cc_Incontinence_Risk = (case when (LU_B4.CIHIValue = ''3'' AND LU_B2a.CIHIValue = ''1'') 
									OR (LU_G1aA.CIHIValue in (''4'', ''8'') AND LU_G1bA.CIHIValue in (''4'', ''8'')
										AND LU_G1eA.CIHIValue in (''4'', ''8''))
								 then 1 else 0 end),
	--Prevalence of Occasional or Frequent Bladder or Bowel Incontinence Without a Toileting Plan
	cc_IncWOToiletPlan_D = (case when LU_H1b.CIHIValue in (''2'', ''3'') OR LU_H1a.CIHIValue in (''2'', ''3'')
								 then 1 else 0 end), 
	cc_IncWOToiletPlan_N = (case when (LU_H1b.CIHIValue in (''2'', ''3'') OR LU_H1a.CIHIValue in (''2'', ''3''))
								 then (case when LU_H3a.CIHIValue = ''0'' AND LU_H3b.CIHIValue = ''0'' then 1 else 0 end)
								 else null end), --ED - 02171 change 0 to null
	--Prevalence of Indwelling Catheters
	cc_Catheter_D = 1,
	cc_Catheter_N = (case when LU_H3d.CIHIValue = ''1'' then 1 else 0 end),
	--Prevalence of Fecal Impaction
	cc_FecalImpaction_D = 1,
	cc_FecalImpaction_N = (case when LU_H2d.CIHIValue = ''1'' then 1 else 0 end),
	--Prevalence of Urinary Tract Infections
	cc_UrinaryTractInfection_D = 1,
	cc_UrinaryTractInfection_N = (case when LU_I2k.CIHIValue = ''1'' then 1 else 0 end),
	--Prevalence of Weight Loss
	cc_WeightLoss_D = (case when LU_K3a_473.CIHIValue = ''9'' then 0 else 1 end),
	cc_WeightLoss_N = (case when LU_K3a_472.CIHIValue = ''1'' or LU_K3a_473.CIHIValue = ''1'' then 1 else 0 end),
	--Prevalence of Tube Feeding
	cc_TubeFeed_D = 1,
	cc_TubeFeed_N = (case when LU_K5b.CIHIValue = ''1'' then 1 else 0 end),
	--Prevalence of Dehydration
	cc_Dehydration_D = 1,
	cc_Dehydration_N = (case when LU_J1c.CIHIValue = ''1'' OR LU_I3a.CIHIValue = ''E860'' OR LU_I3b.CIHIValue = ''E860'' 
								OR LU_I3c.CIHIValue = ''E860'' OR LU_I3d.CIHIValue = ''E860''
								OR LU_I3e.CIHIValue = ''E860'' OR LU_I3f.CIHIValue = ''E860'' 
							 then 1 else 0 end),
	--Prevalence of Bedfast Residents
	cc_BedfastResidents_D = 1,
	cc_BedfastResidents_N = (case when LU_G6a.CIHIValue = ''1'' then 1 else 0 end),
	--Prevalence of Anti-Psychotic Drug Use in the Absence of Psychotic and Related Conditions
	cc_AntiPsychoticDrug_D = (case when LU_I1ii.CIHIValue = ''1'' OR LU_I1x.CIHIValue = ''1'' OR LU_J1i.CIHIValue = ''1''
								   then 0 else 1 end),
	cc_AntiPsychoticDrug_N = (case when not (LU_I1ii.CIHIValue = ''1'' OR LU_I1x.CIHIValue = ''1'' OR LU_J1i.CIHIValue = ''1'')
									then (case when O4a >= 1 then 1 else 0 end)
									else null end),    --ED - 02171 change 0 to null
	cc_AntiPsychoticDrug_Risk = (case when (LU_B4.CIHIValue in (''1'',''2'', ''3'') AND LU_B2a.CIHIValue = ''1'') AND 
										(LU_E4bA.CIHIValue in (''1'', ''2'', ''3'') OR LU_E4ca.CIHIValue in (''1'', ''2'', ''3'') 
											OR LU_E4dA.CIHIValue in (''1'', ''2'', ''3''))		
									  then 1 else 0 end),
	--Prevalence of Anti-Anxiety/Hypnotic Drug Use
	cc_AntiAnxietyDrug_D = (case when LU_I1ii.CIHIValue = ''1'' OR LU_I1x.CIHIValue = ''1'' OR LU_J1i.CIHIValue = ''1''					   
								 then 0 else 1 end),
	cc_AntiAnxietyDrug_N = (case when not (LU_I1ii.CIHIValue = ''1'' OR LU_I1x.CIHIValue = ''1'' OR LU_J1i.CIHIValue = ''1'')
								 then (case when (O4b >= 1 OR O4d >= 1) then 1 else 0 end)
								 else null end),    --ED - 02171 change 0 to null
	--Prevalence of Hypnotic Drug Use More Than Two Days in Past Week
	cc_TwoPlusHypnoticDrugDays_D = 1,
	cc_TwoPlusHypnoticDrugDays_N = (case when O4d >= 3 then 1 else 0 end),
	--Prevalence of Daily Physical Restraints
	cc_PhysicalRestraints_D = 1,
	cc_PhysicalRestraints_N = (case when LU_P4c.CIHIValue = ''2'' OR LU_P4d.CIHIValue = ''2'' OR LU_P4e.CIHIValue = ''2''
									then 1 else 0 end),
	--Prevalence of Little or No Activity
	cc_NoActivity_D = (case when LU_B1.CIHIValue = ''0'' then 1 else 0 end),
	cc_NoActivity_N = (case when LU_B1.CIHIValue = ''0'' 
	                        then (case when LU_N2.CIHIValue in (''2'', ''3'') then 1 else 0 end)
	                        else null end),    --ED - 02171 change 0 to null
	--Prevalence of Stage 1–4 Pressure Ulcers
	cc_PressureUlcers_D = 1,
	cc_PressureUlcers_N = (case when isnumeric(LU_M2a.CIHIvalue) = 1 
								then (case when cast(LU_M2a.CIHIValue as int) >= 1 then 1 else 0 end)
								else 0 end),
	cc_PressureUlcers_Risk = (case when LU_G1aA.CIHIValue in (''3'', ''4'', ''8'') 
									OR LU_G1bA.CIHIValue in (''3'', ''4'', ''8'') OR LU_B1.CIHIValue = ''1'' 
									OR LU_K4C.CIHIValue = ''1'' OR LU_J5c.CIHIValue = ''1''
								   then 1 else 0 end),
	--Incidence of New Fractures
	cc_NewFractures_D = (case when cc_Inc_QI_Flag = 1 and LU_Prev_J4c.CIHIValue = ''0''
									and LU_Prev_J4d.CIHIValue = ''0''
							  then 1 else 0 end),
	cc_NewFractures_N = (case when cc_Inc_QI_Flag = 1 and LU_Prev_J4c.CIHIValue = ''0''
									and LU_Prev_J4d.CIHIValue = ''0''
							  then (case when (LU_J4c.CIHIValue = ''1'' OR LU_J4d.CIHIValue = ''1'') then 1 else 0 end)
							  else null end), --ED - 02171 change 0 to null
	--Incidence of Cognitive Impairment
	cc_CognitiveImpairment_D = (case when cc_Inc_QI_Flag = 1 AND LU_Prev_B4.CIHIValue in (''0'', ''8'') 
										AND LU_Prev_B2a.CIHIValue in (''0'', ''8'') --ED - 02870 add value 8
									 then 1 else 0 end),
	cc_CognitiveImpairment_N = (case when cc_Inc_QI_Flag = 1 AND LU_Prev_B4.CIHIValue in (''0'', ''8'') 
										AND LU_Prev_B2a.CIHIValue in (''0'', ''8'')     --ED - 02870 add value 8
									 then (case when LU_B4.CIHIValue in (''1'', ''2'', ''3'') AND LU_B2a.CIHIValue = ''1'' then 1 else 0 end)
									 else null end), --ED - 02171 change 0 to null
	--Incidence of Decline in Late Loss ADLs
	cc_LateLossADLs_D = (case when cc_Inc_QI_Flag = 1
							  then (case when (LU_Prev_G1aA.CIHIValue in (''4'', ''8'') 
							                AND LU_Prev_G1bA.CIHIValue in (''4'', ''8'') 
							                AND LU_Prev_G1cA.CIHIValue in (''4'', ''8'')    --ED - 02171
							                AND LU_Prev_G1dA.CIHIValue in (''4'', ''8'')    --ED - 02171 
							                AND LU_Prev_G1eA.CIHIValue in (''4'', ''8'')     --ED - 02171
							                AND LU_Prev_G1fA.CIHIValue in (''4'', ''8'')     --ED - 02171
							                AND LU_Prev_G1gA.CIHIValue in (''4'', ''8'')     --ED - 02171
											AND LU_Prev_G1hA.CIHIValue in (''4'', ''8'')
											AND LU_Prev_G1iA.CIHIValue in (''4'', ''8'')
							                AND LU_Prev_G1jA.CIHIValue in (''4'', ''8'')     --ED - 02171
											) OR LU_Prev_B1.CIHIValue = ''1''
										 then 0 else 1 end)
							  else 0 end),
	cc_LateLossADLs_N = (case when cc_Inc_QI_Flag = 1 and 
									not ( (LU_Prev_G1aA.CIHIValue in (''4'', ''8'') 
							                AND LU_Prev_G1bA.CIHIValue in (''4'', ''8'') 
							                AND LU_Prev_G1cA.CIHIValue in (''4'', ''8'')    --ED - 02171
							                AND LU_Prev_G1dA.CIHIValue in (''4'', ''8'')    --ED - 02171 
							                AND LU_Prev_G1eA.CIHIValue in (''4'', ''8'')     --ED - 02171
							                AND LU_Prev_G1fA.CIHIValue in (''4'', ''8'')     --ED - 02171
							                AND LU_Prev_G1gA.CIHIValue in (''4'', ''8'')     --ED - 02171
											AND LU_Prev_G1hA.CIHIValue in (''4'', ''8'')
											AND LU_Prev_G1iA.CIHIValue in (''4'', ''8'')
							                AND LU_Prev_G1jA.CIHIValue in (''4'', ''8'')     --ED - 02171
											) OR LU_Prev_B1.CIHIValue = ''1''
										)
							  then
								(case when 
								   (
								   (case when (dbo.ToNumber(LU_G1aA.CIHIValue) - dbo.ToNumber(LU_Prev_G1aA.CIHIValue) >= 1) 
												AND (LU_Prev_G1aA.CIHIValue <> ''8'' AND LU_G1aA.CIHIValue <> ''8'') 
										 THEN 1 else 0 end) + 
								   (case when (dbo.ToNumber(LU_G1bA.CIHIValue) - dbo.ToNumber(LU_Prev_G1bA.CIHIValue) >= 1) 
												AND (LU_Prev_G1bA.CIHIValue <> ''8'' AND LU_G1bA.CIHIValue <> ''8'') 
										 THEN 1 else 0 end) +
								   (case when (dbo.ToNumber(LU_G1hA.CIHIValue) - dbo.ToNumber(LU_Prev_G1hA.CIHIValue) >= 1) 
												AND (LU_Prev_G1hA.CIHIValue <> ''8'' AND LU_G1hA.CIHIValue <> ''8'') 
										 THEN 1 else 0 end) + 
								   (case when (dbo.ToNumber(LU_G1iA.CIHIValue) - dbo.ToNumber(LU_Prev_G1iA.CIHIValue) >= 1) 
												AND (LU_Prev_G1iA.CIHIValue <> ''8'' AND LU_G1iA.CIHIValue <> ''8'') 
										 THEN 1 else 0 end)
								   ) >= 2 or 
								   (
								   (case when (dbo.ToNumber(LU_G1aA.CIHIValue) - dbo.ToNumber(LU_Prev_G1aA.CIHIValue) >= 2) 
												AND (LU_Prev_G1aA.CIHIValue <> ''8'' AND LU_G1aA.CIHIValue <> ''8'') 
										 THEN 1 else 0 end) +
								   (case when (dbo.ToNumber(LU_G1bA.CIHIValue) - dbo.ToNumber(LU_Prev_G1bA.CIHIValue) >= 2) 
												AND (LU_Prev_G1bA.CIHIValue <> ''8'' AND LU_G1bA.CIHIValue <> ''8'') 
										 THEN 1 else 0 end) +
								   (case when (dbo.ToNumber(LU_G1hA.CIHIValue) - dbo.ToNumber(LU_Prev_G1hA.CIHIValue)>= 2) 
												AND (LU_Prev_G1hA.CIHIValue <> ''8'' AND LU_G1hA.CIHIValue <> ''8'') 
										 THEN 1 else 0 end) + 
								   (case when (dbo.ToNumber(LU_G1iA.CIHIValue) - dbo.ToNumber(LU_Prev_G1iA.CIHIValue) >= 2) 
												AND (LU_Prev_G1iA.CIHIValue <> ''8'' AND LU_G1iA.CIHIValue <> ''8'')
										 then 1 else 0 end)  
								   ) = 1 
									  then 1 else 0 end)
								else null end), --ED - 02171 change 0 to null
	--Incidence of Decline in Range of Motion
	cc_ROMDecline_D = (case when cc_Inc_QI_Flag = 1
							then (case when isnull(dbo.ToNumber(LU_Prev_G4aA.CIHIValue), 0) + 
											isnull(dbo.ToNumber(LU_Prev_G4bA.CIHIValue), 0) + 
											isnull(dbo.ToNumber(LU_Prev_G4cA.CIHIValue), 0) + 
											isnull(dbo.ToNumber(LU_Prev_G4dA.CIHIValue), 0) +
											isnull(dbo.ToNumber(LU_Prev_G4eA.CIHIValue), 0) +
											isnull(dbo.ToNumber(LU_Prev_G4fA.CIHIValue), 0)	= 12
									   then 0 else 1 end)
							else 0 end),
	cc_ROMDecline_N = (case when (case when cc_Inc_QI_Flag = 1
										then (case when isnull(dbo.ToNumber(LU_Prev_G4aA.CIHIValue), 0) + 
														isnull(dbo.ToNumber(LU_Prev_G4bA.CIHIValue), 0) + 
														isnull(dbo.ToNumber(LU_Prev_G4cA.CIHIValue), 0) + 
														isnull(dbo.ToNumber(LU_Prev_G4dA.CIHIValue), 0) +
														isnull(dbo.ToNumber(LU_Prev_G4eA.CIHIValue), 0) +
														isnull(dbo.ToNumber(LU_Prev_G4fA.CIHIValue), 0)	= 12
												   then 0 else 1 end)
										else 0 end) = 1
							then (case when (isnull(dbo.ToNumber(LU_G4aA.CIHIValue), 0) +  
											 isnull(dbo.ToNumber(LU_G4bA.CIHIValue), 0) +  
											 isnull(dbo.ToNumber(LU_G4cA.CIHIValue), 0) +  
											 isnull(dbo.ToNumber(LU_G4dA.CIHIValue), 0) +  
											 isnull(dbo.ToNumber(LU_G4eA.CIHIValue), 0) +  
											 isnull(dbo.ToNumber(LU_G4fA.CIHIValue), 0)) 
											-
											(isnull(dbo.ToNumber(LU_Prev_G4aA.CIHIValue), 0) + 
											 isnull(dbo.ToNumber(LU_Prev_G4bA.CIHIValue), 0) + 
											 isnull(dbo.ToNumber(LU_Prev_G4cA.CIHIValue), 0) + 
											 isnull(dbo.ToNumber(LU_Prev_G4dA.CIHIValue), 0) +
											 isnull(dbo.ToNumber(LU_Prev_G4eA.CIHIValue), 0) +
											 isnull(dbo.ToNumber(LU_Prev_G4fA.CIHIValue), 0)) > = 1
									   then 1 else 0 end)
							else null end) --ED - 02171 change 0 to null
from	
	(select  main.LinkID, main.CalendarYear, main.CalendarQuarter, main.A3, main.AdmitDate, main.AbstractID,
		cc_QI_Flag = (case when datediff(day, AdmitDate, A3) >= 93 and Reentry.LinkID is null then 1 
						   when Reentry.LinkID is not null  then 1
						   else 0 end), 
		cc_IP_Flag = (case when datediff(day, AdmitDate, A3) <= 92 and Reentry.LinkID is null then 1 else 0 end), 
		
		cc_Inc_QI_Flag = (case when exists (select a3 from CRS_Demographic p 
									where main.LinkID = p.LinkID and datediff(day, main.AdmitDate, p.A3) >= 93 
										and datepart(year, p.A3) = (case when main.CalendarQuarter = 1 then main.CalendarYear - 1 else main.CalendarYear end)
										and datepart(quarter, p.A3) = (case when main.CalendarQuarter = 1 then 4 else main.CalendarQuarter - 1 end)
										and p.AA8 in (14502, 14503, 14504, 14505, 14506, 14511))
							   then 1
							   else 0
						   end),
		cc_Prev_Ax_Flag = (select top 1 AbstractID from CRS_Demographic p 
							where main.LinkID = p.LinkID 
								and datepart(year, p.A3) = (case when main.CalendarQuarter = 1 then main.CalendarYear - 1 else main.CalendarYear end)
								and datepart(quarter, p.A3) = (case when main.CalendarQuarter = 1 then 4 else main.CalendarQuarter - 1 end)
								and p.AA8 in (14502, 14503, 14504, 14505, 14506, 14511)
							order by AbstractID desc)
	from 
	(
		select d.LinkID, aa.CalendarYear, aa.CalendarQuarter, d.A3, a.AdmitDate, max(d.AbstractID) as AbstractID 
		from CRS_Demographic d with (nolock)
			inner join
			(select LinkID, Datepart(Year, A3) as CalendarYear, 
				Datepart(Quarter, A3) as CalendarQuarter, max(A3) as maxA3
			from CRS_Demographic with (nolock)
			where A3 < ''2017/04/01'' and A3 is not null and IsDeleted = 2 and AA8 in (14502, 14503, 14504, 14505, 14506, 14511)  --0846 CIHI no longer to support this method
			group by LinkID, Datepart(Year, A3), Datepart(Quarter, A3)
			) aa on d.LinkID = aa.LinkID and d.A3 = aa.maxA3
			inner join CRS_Demographic a with (nolock) on d.LinkID = a.AbstractID
		where d.IsDeleted = 2 and d.AA8 in (14502, 14503, 14504, 14505, 14506, 14511)
		group by d.LinkID, aa.CalendarYear, aa.CalendarQuarter, d.A3, a.AdmitDate
	) main
	left join (select distinct linkid from CRS_Demographic with (nolock) where AA8 = 14510) Reentry on main.LinkID = Reentry.LinkID
	) selection
	inner join CRS_Demographic with (nolock) on selection.AbstractID = CRS_Demographic.AbstractID
	inner join LU_CodeFile LU_AA8 with (nolock) on CRS_Demographic.AA8 = LU_AA8.Code
	inner join H_InstitutionProfile with (nolock) on CRS_Demographic.InstitutionNumber = H_InstitutionProfile.Code
	
	left join CRS_AssessShare1 with (nolock) on CRS_AssessShare1.AbstractID = CRS_Demographic.AbstractID
	left join LU_YesNoSystem LU_B1 with (nolock) on CRS_AssessShare1.B1 = LU_B1.Code
	left join LU_CodeFile LU_B2a with (nolock) on CRS_AssessShare1.B2a = LU_B2a.Code
	left join LU_CodeFile LU_B4 with (nolock) on CRS_AssessShare1.B4 = LU_B4.Code
	
	left join LU_CodeFile LU_E1a with (nolock) on CRS_AssessShare1.E1a = LU_E1a.Code
	

	left join LU_CodeFile LU_E1g with (nolock) on CRS_AssessShare1.E1g = LU_E1g.Code
	left join LU_CodeFile LU_E1n with (nolock) on CRS_AssessShare1.E1n = LU_E1n.Code
	left join LU_CodeFile LU_E1o with (nolock) on CRS_AssessShare1.E1o = LU_E1o.Code
	left join LU_CodeFile LU_E1p with (nolock) on CRS_AssessShare1.E1p = LU_E1p.Code
	left join LU_CodeFile LU_E1j with (nolock) on CRS_AssessShare1.E1j = LU_E1j.Code
	left join LU_CodeFile LU_E2 with (nolock) on CRS_AssessShare1.E2 = LU_E2.Code

	--left join LU_CodeFile LU_ with (nolock) on CRS_AssessShare1. = LU_.Code
	
	
	left join LU_CodeFile LU_E4bA with (nolock) on CRS_AssessShare1.E4bA = LU_E4bA.Code
	left join LU_CodeFile LU_E4cA with (nolock) on CRS_AssessShare1.E4cA = LU_E4cA.Code
	left join LU_CodeFile LU_E4dA with (nolock) on CRS_AssessShare1.E4dA = LU_E4dA.Code
	left join LU_CodeFile LU_E4eA with (nolock) on CRS_AssessShare1.E4eA = LU_E4eA.Code

	left join CRS_AssessShare2 with (nolock) on CRS_AssessShare2.ABstractID = CRS_Demographic.AbstractID
	--left join LU_CodeFile LU_ with (nolock) on CRS_AssessShare2. = LU_.Code
	left join LU_CodeFile LU_G1aA with (nolock) on CRS_AssessShare2.G1aA = LU_G1aA.Code
	left join LU_CodeFile LU_G1bA with (nolock) on CRS_AssessShare2.G1bA = LU_G1bA.Code
	left join LU_CodeFile LU_G1eA with (nolock) on CRS_AssessShare2.G1eA = LU_G1eA.Code
	left join LU_CodeFile LU_G1hA with (nolock) on CRS_AssessShare2.G1hA = LU_G1hA.Code
	left join LU_CodeFile LU_G1iA with (nolock) on CRS_AssessShare2.G1iA = LU_G1iA.Code
	left join LU_CodeFile LU_G4aA with (nolock) on CRS_AssessShare2.G4aA = LU_G4aA.Code
	left join LU_CodeFile LU_G4bA with (nolock) on CRS_AssessShare2.G4bA = LU_G4bA.Code
	left join LU_CodeFile LU_G4cA with (nolock) on CRS_AssessShare2.G4cA = LU_G4cA.Code
	left join LU_CodeFile LU_G4dA with (nolock) on CRS_AssessShare2.G4dA = LU_G4dA.Code
	left join LU_CodeFile LU_G4eA with (nolock) on CRS_AssessShare2.G4eA = LU_G4eA.Code
	left join LU_CodeFile LU_G4fA with (nolock) on CRS_AssessShare2.G4fA = LU_G4fA.Code

	left join LU_YesNoSystem LU_G6a with (nolock) on CRS_AssessShare2.G6a = LU_G6a.Code

	left join LU_CodeFile LU_H1a with (nolock) on CRS_AssessShare2.H1a = LU_H1a.Code
	left join LU_CodeFile LU_H1b with (nolock) on CRS_AssessShare2.H1b = LU_H1b.Code
	left join LU_YesNoSystem LU_H2d with (nolock) on CRS_AssessShare2.H2d = LU_H2d.Code
	left join LU_YesNoSystem LU_H3a with (nolock) on CRS_AssessShare2.H3a = LU_H3a.Code
	left join LU_YesNoSystem LU_H3b with (nolock) on CRS_AssessShare2.H3b = LU_H3b.Code
	left join LU_YesNoSystem LU_H3d with (nolock) on CRS_AssessShare2.H3d = LU_H3d.Code
	left join LU_YesNoSystem LU_H3i with (nolock) on CRS_AssessShare2.H3i = LU_H3i.Code


	left join CRS_AssessShare3 with (nolock) on CRS_AssessShare3.ABstractID = CRS_Demographic.AbstractID
	left join LU_YesNoSystem LU_I1x with (nolock) on CRS_AssessShare3.I1x = LU_I1x.Code

	left join LU_YesNoSystem LU_I1ii with (nolock) on CRS_AssessShare3.I1ii = LU_I1ii.Code
	left join LU_YesNoSystem LU_I1hh with (nolock) on CRS_AssessShare3.I1hh = LU_I1hh.Code
	left join LU_YesNoSystem LU_I2k with (nolock) on CRS_AssessShare3.I2k = LU_I2k.Code
	
	
	left join LU_YesNoSystem LU_J1c with (nolock) on CRS_AssessShare3.J1c = LU_J1c.code
	left join LU_YesNoSystem LU_J1i with (nolock) on CRS_AssessShare3.J1i = LU_J1i.code

	left join LU_YesNoSystem LU_J4a with (nolock) on CRS_AssessShare3.J4a = LU_J4a.code
	left join LU_YesNoSystem LU_J4c with (nolock) on CRS_AssessShare3.J4c = LU_J4c.code
	left join LU_YesNoSystem LU_J4d with (nolock) on CRS_AssessShare3.J4d = LU_J4d.code
	left join LU_YesNoSystem LU_J5c with (nolock) on CRS_AssessShare3.J5c = LU_J5c.code

	left join CRS_AssessShare4 with (nolock) on CRS_AssessShare4.ABstractID = CRS_Demographic.AbstractID
	left join LU_YesNoSystem LU_K3a_472 with (nolock) on CRS_AssessShare4.K3a = LU_K3a_472.code
	left join LU_CodeFile LU_K3a_473 with (nolock) on CRS_AssessShare4.K3a = LU_K3a_473.code
	left join LU_YesNoSystem LU_K4c with (nolock) on CRS_AssessShare4.K4c = LU_K4c.code
	left join LU_YesNoSystem LU_K5b with (nolock) on CRS_AssessShare4.K5b = LU_K5b.code
	left join LU_CodeFile LU_M2a with (nolock) on CRS_AssessShare4.M2a = LU_M2a.code
	
	left join LU_YesNoSystem LU_N1a with (nolock) on CRS_AssessShare4.N1a = LU_N1a.code
	left join LU_YesNoSystem LU_N1b with (nolock) on CRS_AssessShare4.N1b = LU_N1b.code
	left join LU_YesNoSystem LU_N1c with (nolock) on CRS_AssessShare4.N1c = LU_N1c.code
	left join LU_CodeFile LU_N2 with (nolock) on CRS_AssessShare4.N2 = LU_N2.code

	--left join LU_YesNoSystem LU_ with (nolock) on CRS_AssessShare4. = LU_.code

	left join CRS_AssessShare5 with (nolock) on CRS_AssessShare5.ABstractID = CRS_Demographic.AbstractID
	left join LU_CodeFile LU_P4c with (nolock) on CRS_AssessShare5.P4c = LU_P4c.code
	left join LU_CodeFile LU_P4d with (nolock) on CRS_AssessShare5.P4d = LU_P4d.code
	left join LU_CodeFile LU_P4e with (nolock) on CRS_AssessShare5.P4e = LU_P4e.code

	left join CRS_Diagnosis with (nolock) on CRS_Diagnosis.ABstractID = CRS_Demographic.AbstractID
	left join ICD_DiagFile10 LU_I3a with (nolock) on CRS_Diagnosis.I3a = LU_I3a.code
	left join ICD_DiagFile10 LU_I3b with (nolock) on CRS_Diagnosis.I3b = LU_I3b.code
	left join ICD_DiagFile10 LU_I3c with (nolock) on CRS_Diagnosis.I3c = LU_I3c.code
	left join ICD_DiagFile10 LU_I3d with (nolock) on CRS_Diagnosis.I3d = LU_I3d.code
	left join ICD_DiagFile10 LU_I3e with (nolock) on CRS_Diagnosis.I3e = LU_I3e.code
	left join ICD_DiagFile10 LU_I3f with (nolock) on CRS_Diagnosis.I3f = LU_I3f.code

	
--Previous Quarter
	left join CRS_AssessShare1 prev_CRS_AssessShare1 with (nolock) on selection.cc_Prev_Ax_Flag = prev_CRS_AssessShare1.AbstractID
	left join LU_CodeFile LU_Prev_B1 with (nolock) on prev_CRS_AssessShare1.B1 = LU_Prev_B1.Code
	left join LU_CodeFile LU_Prev_B2a with (nolock) on prev_CRS_AssessShare1.B2a = LU_Prev_B2a.Code
	left join LU_CodeFile LU_Prev_B4 with (nolock) on prev_CRS_AssessShare1.B4 = LU_Prev_B4.Code


	left join CRS_AssessShare2 prev_CRS_AssessShare2 with (nolock) on selection.cc_Prev_Ax_Flag = prev_CRS_AssessShare2.AbstractID
	left join LU_CodeFile LU_Prev_G1aA with (nolock) on prev_CRS_AssessShare2.G1aA = LU_Prev_G1aA.Code
	left join LU_CodeFile LU_Prev_G1bA with (nolock) on prev_CRS_AssessShare2.G1bA = LU_Prev_G1bA.Code
	left join LU_CodeFile LU_Prev_G1cA with (nolock) on prev_CRS_AssessShare2.G1cA = LU_Prev_G1cA.Code    --ED - 02171
	left join LU_CodeFile LU_Prev_G1dA with (nolock) on prev_CRS_AssessShare2.G1dA = LU_Prev_G1dA.Code    --ED - 02171
	left join LU_CodeFile LU_Prev_G1eA with (nolock) on prev_CRS_AssessShare2.G1eA = LU_Prev_G1eA.Code    --ED - 02171
	left join LU_CodeFile LU_Prev_G1fA with (nolock) on prev_CRS_AssessShare2.G1fA = LU_Prev_G1fA.Code    --ED - 02171
	left join LU_CodeFile LU_Prev_G1gA with (nolock) on prev_CRS_AssessShare2.G1gA = LU_Prev_G1gA.Code    --ED - 02171
	left join LU_CodeFile LU_Prev_G1hA with (nolock) on prev_CRS_AssessShare2.G1hA = LU_Prev_G1hA.Code
	left join LU_CodeFile LU_Prev_G1iA with (nolock) on prev_CRS_AssessShare2.G1iA = LU_Prev_G1iA.Code
	left join LU_CodeFile LU_Prev_G1jA with (nolock) on prev_CRS_AssessShare2.G1jA = LU_Prev_G1jA.Code    --ED - 02171

	left join LU_CodeFile LU_Prev_G4aA with (nolock) on Prev_CRS_AssessShare2.G4aA = LU_Prev_G4aA.Code
	left join LU_CodeFile LU_Prev_G4bA with (nolock) on Prev_CRS_AssessShare2.G4bA = LU_Prev_G4bA.Code
	left join LU_CodeFile LU_Prev_G4cA with (nolock) on Prev_CRS_AssessShare2.G4cA = LU_Prev_G4cA.Code
	left join LU_CodeFile LU_Prev_G4dA with (nolock) on Prev_CRS_AssessShare2.G4dA = LU_Prev_G4dA.Code
	left join LU_CodeFile LU_Prev_G4eA with (nolock) on Prev_CRS_AssessShare2.G4eA = LU_Prev_G4eA.Code
	left join LU_CodeFile LU_Prev_G4fA with (nolock) on Prev_CRS_AssessShare2.G4fA = LU_Prev_G4fA.Code


	left join CRS_AssessShare3 prev_CRS_AssessShare3 with (nolock) on selection.cc_Prev_Ax_Flag = prev_CRS_AssessShare3.AbstractID
	left join LU_YesNoSystem LU_Prev_J4c with (nolock) on prev_CRS_AssessShare3.J4c = LU_Prev_J4c.Code 
	left join LU_YesNoSystem LU_Prev_J4d with (nolock) on prev_CRS_AssessShare3.J4d = LU_Prev_J4d.Code 





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_RAP_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[MDS20_RAP_VR]
AS
SELECT 
    dbo.CRS_RAPS2.AbstractID AS zzAbstractLink, 
    --PR - 04872 use CRS_RAPS2 instead of CRS_RAPS
    --dbo.CRS_RAPS.Occurrence as RAPOccurrence, LU_RAP.DisplayCode AS RAP, 
    --LU_RAP.UserDescription AS RAPDesc, dbo.CRS_RAPS.RAPNote
    RAP_01_Delirium = (case when Delirium in (1, 15373) then ''Y'' end), RAP_01_DeliriumDesc = (case when Delirium in (1, 15373) then ''Yes'' end), 
    RAP_01_DeliriumNotes = LU_DeliriumNotes.LogNote, 
    RAP_01_DeliriumNotesLogDate = LU_DeliriumNotes.LogDate,
    RAP_01_DeliriumNotesLogTime = LU_DeliriumNotes.LogTime,
    RAP_01_DeliriumNotesLogCoder = LU_DeliriumNotesCoder.DisplayCode,
    RAP_01_DeliriumNotesLogCoderDesc = LU_DeliriumNotesCoder.UserDescription,

    RAP_02_Cognitive = (case when Cognitive in (1, 15373) then ''Y'' end), RAP_02_CognitiveDesc = (case when Cognitive in (1, 15373) then ''Yes'' end), 
    RAP_02_CognitiveNotes = LU_CognitiveNotes.LogNote, 
    RAP_02_CognitiveNotesLogDate = LU_CognitiveNotes.LogDate,
    RAP_02_CognitiveNotesLogTime = LU_CognitiveNotes.LogTime,
    RAP_02_CognitiveNotesLogCoder = LU_CognitiveNotesCoder.DisplayCode,
    RAP_02_CognitiveNotesLogCoderDesc = LU_CognitiveNotesCoder.UserDescription,

    RAP_03_Visual = (case when Visual in (1, 15373) then ''Y'' end), RAP_03_VisualDesc = (case when Visual in (1, 15373) then ''Yes'' end), 
    RAP_03_VisualNotes = LU_VisualNotes.LogNote, 
    RAP_03_VisualNotesLogDate = LU_VisualNotes.LogDate,
    RAP_03_VisualNotesLogTime = LU_VisualNotes.LogTime,
    RAP_03_VisualNotesLogCoder = LU_VisualNotesCoder.DisplayCode,
    RAP_03_VisualNotesLogCoderDesc = LU_VisualNotesCoder.UserDescription,

    RAP_04_Communication = (case when Communication in (1, 15373) then ''Y'' end), RAP_04_CommunicationDesc = (case when Communication in (1, 15373) then ''Yes'' end), 
    RAP_04_CommunicationNotes = LU_CommunicationNotes.LogNote, 
    RAP_04_CommunicationNotesLogDate = LU_CommunicationNotes.LogDate,
    RAP_04_CommunicationNotesLogTime = LU_CommunicationNotes.LogTime,
    RAP_04_CommunicationNotesLogCoder = LU_CommunicationNotesCoder.DisplayCode,
    RAP_04_CommunicationNotesLogCoderDesc = LU_CommunicationNotesCoder.UserDescription,

    RAP_05_ADL_Function = (case when ADL_Function in (1, 15373) then ''Y'' end), RAP_05_ADL_FunctionDesc = (case when ADL_Function in (1, 15373) then ''Yes'' end), 
    RAP_05_ADL_FunctionNotes = LU_ADL_FunctionNotes.LogNote, 
    RAP_05_ADL_FunctionNotesLogDate = LU_ADL_FunctionNotes.LogDate,
    RAP_05_ADL_FunctionNotesLogTime = LU_ADL_FunctionNotes.LogTime,
    RAP_05_ADL_FunctionNotesLogCoder = LU_ADL_FunctionNotesCoder.DisplayCode,
    RAP_05_ADL_FunctionNotesLogCoderDesc = LU_ADL_FunctionNotesCoder.UserDescription,

    RAP_06_Urinary = (case when Urinary in (1, 15373) then ''Y'' end), RAP_06_UrinaryDesc = (case when Urinary in (1, 15373) then ''Yes'' end), 
    RAP_06_UrinaryNotes = LU_UrinaryNotes.LogNote, 
    RAP_06_UrinaryNotesLogDate = LU_UrinaryNotes.LogDate,
    RAP_06_UrinaryNotesLogTime = LU_UrinaryNotes.LogTime,
    RAP_06_UrinaryNotesLogCoder = LU_UrinaryNotesCoder.DisplayCode,
    RAP_06_UrinaryNotesLogCoderDesc = LU_UrinaryNotesCoder.UserDescription,

    RAP_07_Psychosocial = (case when Psychosocial in (1, 15373) then ''Y'' end), RAP_07_PsychosocialDesc = (case when Psychosocial in (1, 15373) then ''Yes'' end), 
    RAP_07_PsychosocialNotes = LU_PsychosocialNotes.LogNote, 
    RAP_07_PsychosocialNotesLogDate = LU_PsychosocialNotes.LogDate,
    RAP_07_PsychosocialNotesLogTime = LU_PsychosocialNotes.LogTime,
    RAP_07_PsychosocialNotesLogCoder = LU_PsychosocialNotesCoder.DisplayCode,
    RAP_07_PsychosocialNotesLogCoderDesc = LU_PsychosocialNotesCoder.UserDescription,

    RAP_08_Mood = (case when Mood in (1, 15373) then ''Y'' end), RAP_08_MoodDesc = (case when Mood in (1, 15373) then ''Yes'' end), 
    RAP_08_MoodNotes = LU_MoodNotes.LogNote, 
    RAP_08_MoodNotesLogDate = LU_MoodNotes.LogDate,
    RAP_08_MoodNotesLogTime = LU_MoodNotes.LogTime,
    RAP_08_MoodNotesLogCoder = LU_MoodNotesCoder.DisplayCode,
    RAP_08_MoodNotesLogCoderDesc = LU_MoodNotesCoder.UserDescription,

    RAP_09_Behavioural = (case when Behavioural in (1, 15373) then ''Y'' end), RAP_09_BehaviouralDesc = (case when Behavioural in (1, 15373) then ''Yes'' end), 
    RAP_09_BehaviouralNotes = LU_BehaviouralNotes.LogNote, 
    RAP_09_BehaviouralNotesLogDate = LU_BehaviouralNotes.LogDate,
    RAP_09_BehaviouralNotesLogTime = LU_BehaviouralNotes.LogTime,
    RAP_09_BehaviouralNotesLogCoder = LU_BehaviouralNotesCoder.DisplayCode,
    RAP_09_BehaviouralNotesLogCoderDesc = LU_BehaviouralNotesCoder.UserDescription,

    RAP_10_Activities = (case when Activities in (1, 15373) then ''Y'' end), RAP_10_ActivitiesDesc = (case when Activities in (1, 15373) then ''Yes'' end), 
    RAP_10_ActivitiesNotes = LU_ActivitiesNotes.LogNote, 
    RAP_10_ActivitiesNotesLogDate = LU_ActivitiesNotes.LogDate,
    RAP_10_ActivitiesNotesLogTime = LU_ActivitiesNotes.LogTime,
    RAP_10_ActivitiesNotesLogCoder = LU_ActivitiesNotesCoder.DisplayCode,
    RAP_10_ActivitiesNotesLogCoderDesc = LU_ActivitiesNotesCoder.UserDescription,

    RAP_11_Falls = (case when Falls in (1, 15373) then ''Y'' end), RAP_11_FallsDesc = (case when Falls in (1, 15373) then ''Yes'' end), 
    RAP_11_FallsNotes = LU_FallsNotes.LogNote, 
    RAP_11_FallsNotesLogDate = LU_FallsNotes.LogDate,
    RAP_11_FallsNotesLogTime = LU_FallsNotes.LogTime,
    RAP_11_FallsNotesLogCoder = LU_FallsNotesCoder.DisplayCode,
    RAP_11_FallsNotesLogCoderDesc = LU_FallsNotesCoder.UserDescription,

    RAP_12_Nutritional = (case when Nutritional in (1, 15373) then ''Y'' end), RAP_12_NutritionalDesc = (case when Nutritional in (1, 15373) then ''Yes'' end), 
    RAP_12_NutritionalNotes = LU_NutritionalNotes.LogNote, 
    RAP_12_NutritionalNotesLogDate = LU_NutritionalNotes.LogDate,
    RAP_12_NutritionalNotesLogTime = LU_NutritionalNotes.LogTime,
    RAP_12_NutritionalNotesLogCoder = LU_NutritionalNotesCoder.DisplayCode,
    RAP_12_NutritionalNotesLogCoderDesc = LU_NutritionalNotesCoder.UserDescription,

    RAP_13_Feeding = (case when Feeding in (1, 15373) then ''Y'' end), RAP_13_FeedingDesc = (case when Feeding in (1, 15373) then ''Yes'' end), 
    RAP_13_FeedingNotes = LU_FeedingNotes.LogNote, 
    RAP_13_FeedingNotesLogDate = LU_FeedingNotes.LogDate,
    RAP_13_FeedingNotesLogTime = LU_FeedingNotes.LogTime,
    RAP_13_FeedingNotesLogCoder = LU_FeedingNotesCoder.DisplayCode,
    RAP_13_FeedingNotesLogCoderDesc = LU_FeedingNotesCoder.UserDescription,

    RAP_14_Dehydration = (case when Dehydration in (1, 15373) then ''Y'' end), RAP_14_DehydrationDesc = (case when Dehydration in (1, 15373) then ''Yes'' end), 
    RAP_14_DehydrationNotes = LU_DehydrationNotes.LogNote, 
    RAP_14_DehydrationNotesLogDate = LU_DehydrationNotes.LogDate,
    RAP_14_DehydrationNotesLogTime = LU_DehydrationNotes.LogTime,
    RAP_14_DehydrationNotesLogCoder = LU_DehydrationNotesCoder.DisplayCode,
    RAP_14_DehydrationNotesLogCoderDesc = LU_DehydrationNotesCoder.UserDescription,

    RAP_15_Dental = (case when Dental in (1, 15373) then ''Y'' end), RAP_15_DentalDesc = (case when Dental in (1, 15373) then ''Yes'' end), 
    RAP_15_DentalNotes = LU_DentalNotes.LogNote, 
    RAP_15_DentalNotesLogDate = LU_DentalNotes.LogDate,
    RAP_15_DentalNotesLogTime = LU_DentalNotes.LogTime,
    RAP_15_DentalNotesLogCoder = LU_DentalNotesCoder.DisplayCode,
    RAP_15_DentalNotesLogCoderDesc = LU_DentalNotesCoder.UserDescription,

    RAP_16_Ulcers = (case when Ulcers in (1, 15373) then ''Y'' end), RAP_16_UlcersDesc = (case when Ulcers in (1, 15373) then ''Yes'' end), 
    RAP_16_UlcersNotes = LU_UlcersNotes.LogNote, 
    RAP_16_UlcersNotesLogDate = LU_UlcersNotes.LogDate,
    RAP_16_UlcersNotesLogTime = LU_UlcersNotes.LogTime,
    RAP_16_UlcersNotesLogCoder = LU_UlcersNotesCoder.DisplayCode,
    RAP_16_UlcersNotesLogCoderDesc = LU_UlcersNotesCoder.UserDescription,

    RAP_17_Drugs = (case when Drugs in (1, 15373) then ''Y'' end), RAP_17_DrugsDesc = (case when Drugs in (1, 15373) then ''Yes'' end), 
    RAP_17_DrugsNotes = LU_DrugsNotes.LogNote, 
    RAP_17_DrugsNotesLogDate = LU_DrugsNotes.LogDate,
    RAP_17_DrugsNotesLogTime = LU_DrugsNotes.LogTime,
    RAP_17_DrugsNotesLogCoder = LU_DrugsNotesCoder.DisplayCode,
    RAP_17_DrugsNotesLogCoderDesc = LU_DrugsNotesCoder.UserDescription,

    RAP_18_Restraints = (case when Restraints in (1, 15373) then ''Y'' end), RAP_18_RestraintsDesc = (case when Restraints in (1, 15373) then ''Yes'' end), 
    RAP_18_RestraintsNotes = LU_RestraintsNotes.LogNote, 
    RAP_18_RestraintsNotesLogDate = LU_RestraintsNotes.LogDate,
    RAP_18_RestraintsNotesLogTime = LU_RestraintsNotes.LogTime,
    RAP_18_RestraintsNotesLogCoder = LU_RestraintsNotesCoder.DisplayCode,
    RAP_18_RestraintsNotesLogCoderDesc = LU_RestraintsNotesCoder.UserDescription
    
FROM dbo.CRS_RAPS2 with (nolock) LEFT OUTER JOIN
    --dbo.LU_CodeFile LU_RAP ON dbo.CRS_RAPS.RAP = LU_RAP.Code
    (select * from dbo.Rec_Notes with (nolock) where AppID between 470 and 479 and FieldID = 5532) LU_DeliriumNotes on LU_DeliriumNotes.RecordID = AbstractID LEFT OUTER JOIN
    dbo.U_Users LU_DeliriumNotesCoder with (nolock) on LU_DeliriumNotes.LogCoder = LU_DeliriumNotesCoder.Code LEFT OUTER JOIN   
    (select * from dbo.Rec_Notes with (nolock) where AppID between 470 and 479 and FieldID = 5534) LU_CognitiveNotes on LU_CognitiveNotes.RecordID = AbstractID LEFT OUTER JOIN
    dbo.U_Users LU_CognitiveNotesCoder with (nolock) on LU_CognitiveNotes.LogCoder = LU_CognitiveNotesCoder.Code LEFT OUTER JOIN   
    (select * from dbo.Rec_Notes with (nolock) where AppID between 470 and 479 and FieldID = 5536) LU_VisualNotes on LU_VisualNotes.RecordID = AbstractID LEFT OUTER JOIN
    dbo.U_Users LU_VisualNotesCoder with (nolock) on LU_VisualNotes.LogCoder = LU_VisualNotesCoder.Code  LEFT OUTER JOIN
    (select * from dbo.Rec_Notes with (nolock) where AppID between 470 and 479 and FieldID = 5538) LU_CommunicationNotes on LU_CommunicationNotes.RecordID = AbstractID LEFT OUTER JOIN
    dbo.U_Users LU_CommunicationNotesCoder with (nolock) on LU_CommunicationNotes.LogCoder = LU_CommunicationNotesCoder.Code  LEFT OUTER JOIN
    (select * from dbo.Rec_Notes with (nolock) where AppID between 470 and 479 and FieldID = 5540) LU_ADL_FunctionNotes on LU_ADL_FunctionNotes.RecordID = AbstractID LEFT OUTER JOIN
    dbo.U_Users LU_ADL_FunctionNotesCoder with (nolock) on LU_ADL_FunctionNotes.LogCoder = LU_ADL_FunctionNotesCoder.Code  LEFT OUTER JOIN
    (select * from dbo.Rec_Notes with (nolock) where AppID between 470 and 479 and FieldID = 5542) LU_UrinaryNotes on LU_UrinaryNotes.RecordID = AbstractID LEFT OUTER JOIN
    dbo.U_Users LU_UrinaryNotesCoder with (nolock) on LU_UrinaryNotes.LogCoder = LU_UrinaryNotesCoder.Code  LEFT OUTER JOIN
    (select * from dbo.Rec_Notes with (nolock) where AppID between 470 and 479 and FieldID = 5544) LU_PsychosocialNotes on LU_PsychosocialNotes.RecordID = AbstractID LEFT OUTER JOIN
    dbo.U_Users LU_PsychosocialNotesCoder with (nolock) on LU_PsychosocialNotes.LogCoder = LU_PsychosocialNotesCoder.Code  LEFT OUTER JOIN
    (select * from dbo.Rec_Notes with (nolock) where AppID between 470 and 479 and FieldID = 5546) LU_MoodNotes on LU_MoodNotes.RecordID = AbstractID LEFT OUTER JOIN
    dbo.U_Users LU_MoodNotesCoder with (nolock) on LU_MoodNotes.LogCoder = LU_MoodNotesCoder.Code  LEFT OUTER JOIN
    (select * from dbo.Rec_Notes with (nolock) where AppID between 470 and 479 and FieldID = 5548) LU_BehaviouralNotes on LU_BehaviouralNotes.RecordID = AbstractID LEFT OUTER JOIN
    dbo.U_Users LU_BehaviouralNotesCoder with (nolock) on LU_BehaviouralNotes.LogCoder = LU_BehaviouralNotesCoder.Code  LEFT OUTER JOIN
    (select * from dbo.Rec_Notes with (nolock) where AppID between 470 and 479 and FieldID = 5550) LU_ActivitiesNotes on LU_ActivitiesNotes.RecordID = AbstractID LEFT OUTER JOIN
    dbo.U_Users LU_ActivitiesNotesCoder with (nolock) on LU_ActivitiesNotes.LogCoder = LU_ActivitiesNotesCoder.Code  LEFT OUTER JOIN
    (select * from dbo.Rec_Notes with (nolock) where AppID between 470 and 479 and FieldID = 5552) LU_FallsNotes on LU_FallsNotes.RecordID = AbstractID LEFT OUTER JOIN
    dbo.U_Users LU_FallsNotesCoder with (nolock) on LU_FallsNotes.LogCoder = LU_FallsNotesCoder.Code  LEFT OUTER JOIN
    (select * from dbo.Rec_Notes with (nolock) where AppID between 470 and 479 and FieldID = 5554) LU_NutritionalNotes on LU_NutritionalNotes.RecordID = AbstractID LEFT OUTER JOIN
    dbo.U_Users LU_NutritionalNotesCoder with (nolock) on LU_NutritionalNotes.LogCoder = LU_NutritionalNotesCoder.Code  LEFT OUTER JOIN
    (select * from dbo.Rec_Notes with (nolock) where AppID between 470 and 479 and FieldID = 5556) LU_FeedingNotes on LU_FeedingNotes.RecordID = AbstractID LEFT OUTER JOIN
    dbo.U_Users LU_FeedingNotesCoder with (nolock) on LU_FeedingNotes.LogCoder = LU_FeedingNotesCoder.Code  LEFT OUTER JOIN
    (select * from dbo.Rec_Notes with (nolock) where AppID between 470 and 479 and FieldID = 5558) LU_DehydrationNotes on LU_DehydrationNotes.RecordID = AbstractID LEFT OUTER JOIN
    dbo.U_Users LU_DehydrationNotesCoder with (nolock) on LU_DehydrationNotes.LogCoder = LU_DehydrationNotesCoder.Code  LEFT OUTER JOIN
    (select * from dbo.Rec_Notes with (nolock) where AppID between 470 and 479 and FieldID = 5560) LU_DentalNotes on LU_DentalNotes.RecordID = AbstractID LEFT OUTER JOIN
    dbo.U_Users LU_DentalNotesCoder with (nolock) on LU_DentalNotes.LogCoder = LU_DentalNotesCoder.Code  LEFT OUTER JOIN
    (select * from dbo.Rec_Notes with (nolock) where AppID between 470 and 479 and FieldID = 5562) LU_UlcersNotes on LU_UlcersNotes.RecordID = AbstractID LEFT OUTER JOIN
    dbo.U_Users LU_UlcersNotesCoder with (nolock) on LU_UlcersNotes.LogCoder = LU_UlcersNotesCoder.Code  LEFT OUTER JOIN
    (select * from dbo.Rec_Notes with (nolock) where AppID between 470 and 479 and FieldID = 5564) LU_DrugsNotes on LU_DrugsNotes.RecordID = AbstractID LEFT OUTER JOIN
    dbo.U_Users LU_DrugsNotesCoder with (nolock) on LU_DrugsNotes.LogCoder = LU_DrugsNotesCoder.Code  LEFT OUTER JOIN
    (select * from dbo.Rec_Notes with (nolock) where AppID between 470 and 479 and FieldID = 5566) LU_RestraintsNotes on LU_RestraintsNotes.RecordID = AbstractID LEFT OUTER JOIN
    dbo.U_Users LU_RestraintsNotesCoder  with (nolock)on LU_RestraintsNotes.LogCoder = LU_RestraintsNotesCoder.Code  
   



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_RUGS_34_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[MDS20_RUGS_34_VR]
AS
SELECT     
    AbstractID AS zzAbstractLink, 
    RUG_Group1, 
    CMI_Weight1 = (case when isnumeric(CMI_Weight1) = 1 then cast(CMI_Weight1 as dec(8, 4)) else null end), --PR - 06957
    RUG_Description1, 
    RUG_Group2, 
    CMI_Weight2 = (case when isnumeric(CMI_Weight2) = 1 then cast(CMI_Weight2 as dec(8, 4)) else null end), --PR - 06957
    RUG_Description2, 
    ADL
FROM dbo.CRS_RUGS_34 with (nolock)
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_RUGS_Plus_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[MDS20_RUGS_Plus_VR]
AS
SELECT     
    AbstractID AS zzAbstractLink, 
    RUG_Group1, 
    CMI_Weight1 = (case when isnumeric(CMI_Weight1) = 1 then cast(CMI_Weight1 as dec(8, 4)) else null end), --PR - 06957
    RUG_Description1, 
    RUG_Group2, 
    CMI_Weight2 = (case when isnumeric(CMI_Weight2) = 1 then cast(CMI_Weight2 as dec(8, 4)) else null end), --PR - 06957
    RUG_Description2, 
    ADL
FROM dbo.CRS_RUGS_Plus with (nolock)

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_RUGS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[MDS20_RUGS_VR]
AS
SELECT     
    AbstractID AS zzAbstractLink, 
    RUG_Group1, 
    CMI_Weight1 = (case when isnumeric(CMI_Weight1) = 1 then cast(CMI_Weight1 as dec(8, 4)) else null end), --PR - 06957
    RUG_Description1, 
    RUG_Group2, 
    CMI_Weight2 = (case when isnumeric(CMI_Weight2) = 1 then cast(CMI_Weight2 as dec(8, 4)) else null end), --PR - 06957
    RUG_Description2, 
    ADL
FROM dbo.CRS_RUGS with (nolock)
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Shared_1_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[MDS20_Shared_1_VR]
AS
SELECT 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9a_Q.DisplayCode else (case CRS_AssessShare1.A9a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS GuardianLegal_A9a, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9a_Q.UserDescription else (case CRS_AssessShare1.A9a when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS GuardianLegalDesc_A9a, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9b_Q.DisplayCode else (case CRS_AssessShare1.A9b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS GuardianAttorney_A9b, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9b_Q.UserDescription else (case CRS_AssessShare1.A9b when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS GuardianAttorneyDesc_A9b, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9c_Q.DisplayCode else (case CRS_AssessShare1.A9c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS GuardianOther_A9c, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9c_Q.UserDescription else (case CRS_AssessShare1.A9c when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS GuardianOtherDesc_A9c, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9d_Q.DisplayCode else (case CRS_AssessShare1.A9d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS GuardianFamily_A9d, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9d_Q.UserDescription else (case CRS_AssessShare1.A9d when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS GuardianFamilyDesc_A9d, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9e_Q.DisplayCode else (case CRS_AssessShare1.A9e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS GuardianHealth_A9e, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9e_Q.UserDescription else (case CRS_AssessShare1.A9e when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS GuardianHealthDesc_A9e, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9f_Q.DisplayCode else (case CRS_AssessShare1.A9f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS GuardianSelf_A9f, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A9f_Q.UserDescription else (case CRS_AssessShare1.A9f when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS GuardianSelfDesc_A9f, 
    (case when CRS_AssessShare1.A9All > 0 then Y1.DisplayCode end) as GuardianNone_A9g, 
    (case when CRS_AssessShare1.A9All > 0 then Y1.UserDescription end) as GuardianNoneDesc_A9g, 


    (case when LU_AA8.CIHIValue = ''05'' then LU_A10a_Q.DisplayCode else (case CRS_AssessShare1.A10a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirLiving_A10a, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10a_Q.UserDescription else (case CRS_AssessShare1.A10a when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirLivingDesc_A10a, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10b_Q.DisplayCode else (case CRS_AssessShare1.A10b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirNoResuscitate_A10b, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10b_Q.UserDescription else (case CRS_AssessShare1.A10b when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirNoResuscitateDesc_A10b, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10c_Q.DisplayCode else (case CRS_AssessShare1.A10c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirNoHospitalize_A10c, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10c_Q.UserDescription else (case CRS_AssessShare1.A10c when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirNoHospitalizeDesc_A10c, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10d_Q.DisplayCode else (case CRS_AssessShare1.A10d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirOrgan_A10d, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10d_Q.UserDescription else (case CRS_AssessShare1.A10d when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirOrganDesc_A10d, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10e_Q.DisplayCode else (case CRS_AssessShare1.A10e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirAutopsy_A10e, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10e_Q.UserDescription else (case CRS_AssessShare1.A10e when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirAutopsyDesc_A10e, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10f_Q.DisplayCode else (case CRS_AssessShare1.A10f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirFeeding_A10f, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10f_Q.UserDescription else (case CRS_AssessShare1.A10f when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirFeedingDesc_A10f, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10g_Q.DisplayCode else (case CRS_AssessShare1.A10g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirMedication_A10g, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10g_Q.UserDescription else (case CRS_AssessShare1.A10g when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirMedicationDesc_A10g, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10h_Q.DisplayCode else (case CRS_AssessShare1.A10h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS AdvDirOther_A10h, 
    (case when LU_AA8.CIHIValue = ''05'' then LU_A10h_Q.UserDescription else (case CRS_AssessShare1.A10h when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS AdvDirOtherDesc_A10h, 
    (case when CRS_AssessShare1.A10All > 0 then Y1.DisplayCode end) as AdvDirNone_A10i, 
    (case when CRS_AssessShare1.A10All > 0 then Y1.UserDescription end) as AdvDirNoneDesc_A10i, 
    
    DecisionMakerForPersonalCare_A11a = LU_A11a.DisplayCode, DecisionMakerForPersonalCareDesc_A11a = LU_A11a.UserDescription, 
    DecisionMakerForProperty_A11b = LU_A11b.DisplayCode,     DecisionMakerForPropertyDesc_A11b = LU_A11b.UserDescription, 
    AdvanceDirectivesResuscitating_A12a = LU_A12a.DisplayCode, AdvanceDirectivesResuscitatingDesc_A12a = LU_A12a.UserDescription, 
    AdvanceDirectivesHospitalizing_A12b = LU_A12b.DisplayCode, AdvanceDirectivesHospitalizingDesc_A12b = LU_A12b.UserDescription, 
    
    (case CRS_AssessShare1.B1 when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS Comatose_B1, 
    (case CRS_AssessShare1.B1 when 1 then Y.UserDescription when 2 then N.UserDescription end) AS ComatoseDesc_B1, 

    LU_B2a.DisplayCode AS MemoryShort_B2a, LU_B2a.UserDescription AS MemoryShortDesc_B2a, 
    LU_B2b.DisplayCode AS MemoryLong_B2b, LU_B2b.UserDescription AS MemoryLongDesc_B2b, 

    LU_B3a.DisplayCode AS MemAbilityCurrent_B3a, LU_B3a.UserDescription AS MemAbilityCurrentDesc_B3a, 
    LU_B3b.DisplayCode AS MemAbilityOwnRoom_B3b, LU_B3b.UserDescription AS MemAbilityOwnRoomDesc_B3b, 
    LU_B3c.DisplayCode AS MemAbilityStaff_B3c, LU_B3c.UserDescription AS MemAbilityStaffDesc_B3c, 
    LU_B3d.DisplayCode AS MemAbilityFacility_B3d, LU_B3d.UserDescription AS MemAbilityFacilityDesc_B3d, 
    (case when CRS_AssessShare1.B3All > 0 then Y1.DisplayCode end) as MemAbilityNone_B3e, 
    (case when CRS_AssessShare1.B3All > 0 then Y1.UserDescription end) as MemAbilityNoneDesc_B3e, 

    LU_B4.DisplayCode AS CognitiveSkills_B4, LU_B4.UserDescription AS CognitiveSkillsDesc_B4, 

    LU_B5a.DisplayCode AS DisorderEasily_B5a, LU_B5a.UserDescription AS DisorderEasilyDesc_B5a, 
    LU_B5b.DisplayCode AS DisorderPerception_B5b, LU_B5b.UserDescription AS DisorderPerceptionDesc_B5b, 
    LU_B5c.DisplayCode AS DisorderSpeech_B5c, LU_B5c.UserDescription AS DisorderSpeechDesc_B5c, 
    LU_B5d.DisplayCode AS DisorderRestless_B5d, LU_B5d.UserDescription AS DisorderRestlessDesc_B5d, 
    LU_B5e.DisplayCode AS DisorderLethargy_B5e, LU_B5e.UserDescription AS DisorderLethargyDesc_B5e, 
    LU_B5f.DisplayCode AS DisorderMental_B5f, LU_B5f.UserDescription AS DisorderMentalDesc_B5f, 

    LU_B6.DisplayCode AS ChangeCognitive_B6, LU_B6.UserDescription AS ChangeCognitiveDesc_B6, 

    LU_C4.DisplayCode AS UnderStood_C4, LU_C4.UserDescription AS UnderStoodDesc_C4, 
    LU_C6.DisplayCode AS AbilityUnderStood_C6, LU_C6.UserDescription AS AbilityUnderStoodDesc_C6, 
    LU_C7.DisplayCode AS ChangeComm_C7, LU_C7.UserDescription AS ChangeCommDesc_C7, 

    LU_E1a.DisplayCode AS DepressionNegative_E1a, LU_E1a.UserDescription AS DepressionNegativeDesc_E1a, 
    LU_E1b.DisplayCode AS DepressionRepeatQues_E1b, LU_E1b.UserDescription AS DepressionRepeatQuesDesc_E1b, 
    LU_E1c.DisplayCode AS DepressionRepeatVerb_E1c, LU_E1c.UserDescription AS DepressionRepeatVerbDesc_E1c, 
    LU_E1d.DisplayCode AS DepressionAnger_E1d, LU_E1d.UserDescription AS DepressionAngerDesc_E1d, 
    LU_E1e.DisplayCode AS DepressionDeprecation_E1e, LU_E1e.UserDescription AS DepressionDeprecationDesc_E1e, 
    LU_E1f.DisplayCode AS DepressionUnrealistic_E1f, LU_E1f.UserDescription AS DepressionUnrealisticDesc_E1f, 
    LU_E1g.DisplayCode AS DepressionTerrible_E1g, LU_E1g.UserDescription AS DepressionTerribleDesc_E1g, 
    LU_E1h.DisplayCode AS DepressionComplaints_E1h, LU_E1h.UserDescription AS DepressionComplaintsDesc_E1h, 
    LU_E1I.DisplayCode AS DepressionNonHealth_E1i, LU_E1I.UserDescription AS DepressionNonHealthDesc_E1i, 
    LU_E1j.DisplayCode AS DepressionUnpleasant_E1j, LU_E1j.UserDescription AS DepressionUnpleasantDesc_E1j, 
    LU_E1k.DisplayCode AS DepressionChange_E1k, LU_E1k.UserDescription AS DepressionChangeDesc_E1k, 
    LU_E1l.DisplayCode AS DepressionSad_E1l, LU_E1l.UserDescription AS DepressionSadDesc_E1l, 
    LU_E1m.DisplayCode AS DepressionCrying_E1m, LU_E1m.UserDescription AS DepressionCryingDesc_E1m, 
    LU_E1n.DisplayCode AS DepressionPhysical_E1n, LU_E1n.UserDescription AS DepressionPhysicalDesc_E1n, 
    LU_E1o.DisplayCode AS DepressionInterest_E1o, LU_E1o.UserDescription AS DepressionInterestDesc_E1o, 
    LU_E1p.DisplayCode AS DepressionInteraction_E1p, LU_E1p.UserDescription AS DepressionInteractionDesc_E1p, 

    LU_E2.DisplayCode AS Persistence_E2, LU_E2.UserDescription AS PersistenceDesc_E2, 
    LU_E3.DisplayCode AS ChangeMood_E3, LU_E3.UserDescription AS ChangeMoodDesc_E3, 

    LU_E4aA.DisplayCode AS BehaviorWanderingFre_E4aA, LU_E4aA.UserDescription AS BehaviorWanderingFreDesc_E4aA, 
    LU_E4aB.DisplayCode AS BehaviorWanderingAlt_E4aB, LU_E4aB.UserDescription AS BehaviorWanderingAltDesc_E4aB, 
    LU_E4bA.DisplayCode AS BehaviorVerballyFre_E4bA, LU_E4bA.UserDescription AS BehaviorVerballyFreDesc_E4bA, 
    LU_E4bB.DisplayCode AS BehaviorVerballyAlt_E4bB, LU_E4bB.UserDescription AS BehaviorVerballyAltDesc_E4bB, 
    LU_E4cA.DisplayCode AS BehaviorPhysicallyFre_E4cA, LU_E4cA.UserDescription AS BehaviorPhysicalFreDesc_E4cA, 
    LU_E4cB.DisplayCode AS BehaviorPhysicallyAlt_E4cB, LU_E4cB.UserDescription AS BehaviorPhysicalAltDesc_E4cB, 
    LU_E4dA.DisplayCode AS BehaviorSociallyFre_E4dA, LU_E4dA.UserDescription AS BehaviorSociallyFreDesc_E4dA, 
    LU_E4dB.DisplayCode AS BehaviorSociallyAlt_E4dB, LU_E4dB.UserDescription AS BehaviorSociallyAltDesc_E4dB, 
    LU_E4eA.DisplayCode AS BehaviorResistsFre_E4eA, LU_E4eA.UserDescription AS BehaviorResistsFreDesc_E4eA, 
    LU_E4eB.DisplayCode AS BehaviorResistsAlt_E4eB, LU_E4eB.UserDescription AS BehaviorResistsAltDesc_E4eB, 

    LU_E5.DisplayCode AS ChangeBehave_E5, LU_E5.UserDescription AS ChangeBehaveDesc_E5, 
    dbo.CRS_AssessShare1.AbstractID AS zzAbstractLink
FROM dbo.CRS_AssessShare1  with (nolock)
    inner join CRS_Demographic with (nolock) on CRS_AssessShare1.AbstractID = CRS_Demographic.AbstractID
    inner join LU_CodeFile LU_AA8 with (nolock) on CRS_Demographic.AA8 = LU_AA8.Code
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E5 with (nolock) on dbo.CRS_AssessShare1.E5 = LU_E5.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4eB with (nolock) on dbo.CRS_AssessShare1.E4eB = LU_E4eB.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4eA with (nolock) on LU_E4eA.Code = dbo.CRS_AssessShare1.E4eA 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4dB with (nolock) on dbo.CRS_AssessShare1.E4dB = LU_E4dB.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4dA with (nolock) on dbo.CRS_AssessShare1.E4dA = LU_E4dA.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4cB with (nolock) on dbo.CRS_AssessShare1.E4cB = LU_E4cB.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4cA with (nolock) on LU_E4cA.Code = dbo.CRS_AssessShare1.E4cA 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4bB with (nolock) on dbo.CRS_AssessShare1.E4bB = LU_E4bB.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4bA with (nolock) on LU_E4bA.Code = dbo.CRS_AssessShare1.E4bA 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4aB with (nolock) on dbo.CRS_AssessShare1.E4aB = LU_E4aB.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E4aA with (nolock) on dbo.CRS_AssessShare1.E4aA = LU_E4aA.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E3 with (nolock) on dbo.CRS_AssessShare1.E3 = LU_E3.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E2 with (nolock) on dbo.CRS_AssessShare1.E2 = LU_E2.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1p with (nolock) on dbo.CRS_AssessShare1.E1p = LU_E1p.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1o with (nolock) on LU_E1o.Code = dbo.CRS_AssessShare1.E1o 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1n with (nolock) on dbo.CRS_AssessShare1.E1n = LU_E1n.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1m with (nolock) on dbo.CRS_AssessShare1.E1m = LU_E1m.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1l with (nolock) on dbo.CRS_AssessShare1.E1l = LU_E1l.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1k with (nolock) on dbo.CRS_AssessShare1.E1k = LU_E1k.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1j with (nolock) on dbo.CRS_AssessShare1.E1j = LU_E1j.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1I with (nolock) on LU_E1I.Code = dbo.CRS_AssessShare1.E1I 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1h with (nolock) on dbo.CRS_AssessShare1.E1h = LU_E1h.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1g with (nolock) on dbo.CRS_AssessShare1.E1g = LU_E1g.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1f with (nolock) on dbo.CRS_AssessShare1.E1f = LU_E1f.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1e with (nolock) on dbo.CRS_AssessShare1.E1e = LU_E1e.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1d with (nolock) on dbo.CRS_AssessShare1.E1d = LU_E1d.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1c with (nolock) on dbo.CRS_AssessShare1.E1c = LU_E1c.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1b with (nolock) on dbo.CRS_AssessShare1.E1b = LU_E1b.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_E1a with (nolock) on dbo.CRS_AssessShare1.E1a = LU_E1a.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_C7 with (nolock) on dbo.CRS_AssessShare1.C7 = LU_C7.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_C6 with (nolock) on dbo.CRS_AssessShare1.C6 = LU_C6.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_C4 with (nolock) on dbo.CRS_AssessShare1.C4 = LU_C4.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B6 with (nolock) on dbo.CRS_AssessShare1.B6 = LU_B6.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B5f with (nolock) on dbo.CRS_AssessShare1.B5f = LU_B5f.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B5e with (nolock) on dbo.CRS_AssessShare1.B5e = LU_B5e.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B5d with (nolock) on LU_B5d.Code = dbo.CRS_AssessShare1.B5d 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B5c with (nolock) on dbo.CRS_AssessShare1.B5c = LU_B5c.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B5b with (nolock) on dbo.CRS_AssessShare1.B5b = LU_B5b.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B5a with (nolock) on dbo.CRS_AssessShare1.B5a = LU_B5a.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B4 with (nolock) on LU_B4.Code = dbo.CRS_AssessShare1.B4 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B3a with (nolock) on dbo.CRS_AssessShare1.B3a = LU_B3a.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B3b with (nolock) on LU_B3b.Code = dbo.CRS_AssessShare1.B3b 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B3c with (nolock) on LU_B3c.Code = dbo.CRS_AssessShare1.B3c 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B3d with (nolock) on dbo.CRS_AssessShare1.B3d = LU_B3d.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B2b with (nolock) on dbo.CRS_AssessShare1.B2b = LU_B2b.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_B2a with (nolock) on dbo.CRS_AssessShare1.B2a = LU_B2a.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A10h_Q with (nolock) on dbo.CRS_AssessShare1.A10h = LU_A10h_Q.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A10g_Q with (nolock) on dbo.CRS_AssessShare1.A10g = LU_A10g_Q.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A10f_Q with (nolock) on dbo.CRS_AssessShare1.A10f = LU_A10f_Q.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A10e_Q with (nolock) on dbo.CRS_AssessShare1.A10e = LU_A10e_Q.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A10d_Q with (nolock) on dbo.CRS_AssessShare1.A10d = LU_A10d_Q.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A10c_Q with (nolock) on dbo.CRS_AssessShare1.A10c = LU_A10c_Q.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A10b_Q with (nolock) on dbo.CRS_AssessShare1.A10b = LU_A10b_Q.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A10a_Q with (nolock) on dbo.CRS_AssessShare1.A10a = LU_A10a_Q.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A9f_Q with (nolock) on dbo.CRS_AssessShare1.A9f = LU_A9f_Q.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A9e_Q with (nolock) on dbo.CRS_AssessShare1.A9e = LU_A9e_Q.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A9d_Q with (nolock) on dbo.CRS_AssessShare1.A9d = LU_A9d_Q.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A9c_Q with (nolock) on dbo.CRS_AssessShare1.A9c = LU_A9c_Q.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A9b_Q with (nolock) on dbo.CRS_AssessShare1.A9b = LU_A9b_Q.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A9a_Q with (nolock) on dbo.CRS_AssessShare1.A9a = LU_A9a_Q.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A11a with (nolock) on dbo.CRS_AssessShare1.A11a = LU_A11a.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A11b with (nolock) on dbo.CRS_AssessShare1.A11b = LU_A11b.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A12a with (nolock) on dbo.CRS_AssessShare1.A12a = LU_A12a.Code 
    LEFT OUTER JOIN dbo.LU_CodeFile LU_A12b with (nolock) on dbo.CRS_AssessShare1.A12b = LU_A12b.Code 

    cross join ( select top 1 DisplayCode, UserDescription from LU_YesNoSystem where code = 1 ) Y
    cross join ( select top 1 DisplayCode, UserDescription from LU_YesNoSystem where code = 2 ) N
    cross join ( select top 1 DisplayCode, UserDescription from LU_CodeFile where LookUpID = 1 ) Y1

--    LEFT OUTER JOIN dbo.LU_CodeFile LU_A9All with (nolock) on dbo.CRS_AssessShare1.A9All = LU_A9All.Code
--    LEFT OUTER JOIN dbo.LU_CodeFile LU_A10All with (nolock) on dbo.CRS_AssessShare1.A10All = LU_A10All.Code 
--    LEFT OUTER JOIN dbo.LU_CodeFile LU_B3All with (nolock) on dbo.CRS_AssessShare1.B3All = LU_B3All.Code 

--    LEFT OUTER JOIN dbo.LU_YesNoSystem LU_A9a_F with (nolock) on dbo.CRS_AssessShare1.A9a = LU_A9a_F.Code 
--    LEFT OUTER JOIN dbo.LU_YesNoSystem LU_A9b_F with (nolock) on dbo.CRS_AssessShare1.A9b = LU_A9b_F.Code 
--    LEFT OUTER JOIN dbo.LU_YesNoSystem LU_A9c_F with (nolock) on dbo.CRS_AssessShare1.A9c = LU_A9c_F.Code 
--    LEFT OUTER JOIN dbo.LU_YesNoSystem LU_A9d_F with (nolock) on dbo.CRS_AssessShare1.A9d = LU_A9d_F.Code 
--    LEFT OUTER JOIN dbo.LU_YesNoSystem LU_A9e_F with (nolock) on dbo.CRS_AssessShare1.A9e = LU_A9e_F.Code 
--    LEFT OUTER JOIN dbo.LU_YesNoSystem LU_A9f_F with (nolock) on dbo.CRS_AssessShare1.A9f = LU_A9f_F.Code 
--    LEFT OUTER JOIN dbo.LU_YesNoSystem LU_A10a_F with (nolock) on dbo.CRS_AssessShare1.A10a = LU_A10a_F.Code 
--    LEFT OUTER JOIN dbo.LU_YesNoSystem LU_A10b_F with (nolock) on dbo.CRS_AssessShare1.A10b = LU_A10b_F.Code 
--    LEFT OUTER JOIN dbo.LU_YesNoSystem LU_A10c_F with (nolock) on dbo.CRS_AssessShare1.A10c = LU_A10c_F.Code 
--    LEFT OUTER JOIN dbo.LU_YesNoSystem LU_A10d_F with (nolock) on dbo.CRS_AssessShare1.A10d = LU_A10d_F.Code 
--    LEFT OUTER JOIN dbo.LU_YesNoSystem LU_A10e_F with (nolock) on dbo.CRS_AssessShare1.A10e = LU_A10e_F.Code 
--    LEFT OUTER JOIN dbo.LU_YesNoSystem LU_A10f_F with (nolock) on dbo.CRS_AssessShare1.A10f = LU_A10f_F.Code 
--    LEFT OUTER JOIN dbo.LU_YesNoSystem LU_A10g_F with (nolock) on dbo.CRS_AssessShare1.A10g = LU_A10g_F.Code 
--    LEFT OUTER JOIN dbo.LU_YesNoSystem LU_A10h_F with (nolock) on dbo.CRS_AssessShare1.A10h = LU_A10h_F.Code 
--    LEFT OUTER JOIN dbo.LU_YesNoSystem LU_B1 with (nolock) on dbo.CRS_AssessShare1.B1 = LU_B1.Code 
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Shared_2_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'







CREATE VIEW [dbo].[MDS20_Shared_2_VR]
AS
SELECT 
    LU_F1a.DisplayCode AS Interacting_F1a, LU_F1a.UserDescription AS InteractingDesc_F1a, 
    LU_F1b.DisplayCode AS PlanActivity_F1b, LU_F1b.UserDescription AS PlanActivityDesc_F1b, 
    LU_F1c.DisplayCode AS SelfActivity_F1c, LU_F1c.UserDescription AS SelfActivityDesc_F1c, 
    LU_F1d.DisplayCode AS Goals_F1d, LU_F1d.UserDescription AS GoalsDesc_F1d, 
    LU_F1e.DisplayCode AS Pursues_F1e, LU_F1e.UserDescription AS PursuesDesc_F1e, 
    LU_F1f.DisplayCode AS Accepts_F1f, LU_F1f.UserDescription AS AcceptsDesc_F1f, 
    (case when CRS_AssessShare2.F1All > 0 then Y1.DisplayCode end) as SenseNone_F1g, 
    (case when CRS_AssessShare2.F1All > 0 then Y1.UserDescription end) as SenseNoneDesc_F1g, 

    LU_G1aA.DisplayCode AS BedMobilitySelf_G1aA, LU_G1aA.UserDescription AS BedMobilitySelfDesc_G1aA, 
    LU_G1aB.DisplayCode AS BedMobilitySupport_G1aB, LU_G1aB.UserDescription AS BedMobilitySupportDesc_G1aB, 
    LU_G1bA.DisplayCode AS TransferSelf_G1bA, LU_G1bA.UserDescription AS TransferSelfDesc_G1bA, 
    LU_G1bB.DisplayCode AS TransferSupport_G1bB, LU_G1bB.UserDescription AS TransferSupportDesc_G1bB, 
    LU_G1cA.DisplayCode AS WalkInRoomSelf_G1cA, LU_G1cA.UserDescription AS WalkInRoomSelfDesc_G1cA,
    LU_G1cB.DisplayCode AS WalkInRoomSupport_G1cB, LU_G1cB.UserDescription AS WalkInRoomSupportDesc_G1cB, 
    LU_G1dA.DisplayCode AS RorridorSelf_G1dA, LU_G1dA.UserDescription AS RorridorSelfDesc_G1dA, 
    LU_G1dB.DisplayCode AS RorridorSupport_G1dB, LU_G1dB.UserDescription AS RorridorSupportDesc_G1dB, 
    LU_G1eA.DisplayCode AS OnUnitSelf_G1eA, LU_G1eA.UserDescription AS OnUnitSelfDesc_G1eA, 
    LU_G1eB.DisplayCode AS OnUnitSupport_G1eB, LU_G1eB.UserDescription AS OnUnitSupportDesc_G1eB, 
    LU_G1fA.DisplayCode AS OffUnitSelf_G1fA, LU_G1fA.UserDescription AS OffUnitSelfDesc_G1fA, 
    LU_G1fB.DisplayCode AS OffUnitSupport_G1fB, LU_G1fB.UserDescription AS OffUnitSupportDesc_G1fB, 
    LU_G1gA.DisplayCode AS DressingSelf_G1gA, LU_G1gA.UserDescription AS DressingSelfDesc_G1gA, 
    LU_G1gB.DisplayCode AS DressingSupport_G1gB, LU_G1gB.UserDescription AS DressingSupportDesc_G1gB, 
    LU_G1hA.DisplayCode AS EatingSelf_G1hA, LU_G1hA.UserDescription AS EatingSelfDesc_G1hA, 
    LU_G1hB.DisplayCode AS EatingSupport_G1hB, LU_G1hB.UserDescription AS EatingSupportDesc_G1hB, 
    LU_G1IA.DisplayCode AS ToiletSelf_G1iA, LU_G1IA.UserDescription AS ToiletSelfDesc_G1iA, 
    LU_G1IB.DisplayCode AS ToiletSupport_G1iB, LU_G1IB.UserDescription AS ToiletSupportDesc_G1iB, 
    LU_G1jA.DisplayCode AS HygieneSelf_G1jA, LU_G1jA.UserDescription AS HygieneSelfDesc_G1jA, 
    LU_G1jB.DisplayCode AS HygieneSupport_G1jB, LU_G1jB.UserDescription AS HygieneSupportDesc_G1jB, 

    LU_G2A.DisplayCode AS BathingSelf_G2A, LU_G2A.UserDescription AS BathingSelfDesc_G2A, 
    LU_G2B.DisplayCode AS BathingSupport_G2B, LU_G2B.UserDescription AS BathingSupportDesc_G2B, 

    LU_G3a.DisplayCode AS BalanceStanding_G3a, LU_G3a.UserDescription AS BalanceStandingDesc_G3a, 
    LU_G3b.DisplayCode AS BalanceSitting_G3b, LU_G3b.UserDescription AS BalanceSupportDesc_G3b, 

    LU_G4aA.DisplayCode AS LimitRangeNeck_G4aA, LU_G4aA.UserDescription AS LimitRangeNeckDesc_G4aA, 
    LU_G4aB.DisplayCode AS LimitVoluntaryNeck_G4aB, LU_G4aB.UserDescription AS LimitVoluntaryNeckDesc_G4aB, 
    LU_G4bA.DisplayCode AS LimitRangeArm_G4bA, LU_G4bA.UserDescription AS LimitRangeArmDesc_G4bA, 
    LU_G4bB.DisplayCode AS LimitVoluntaryArm_G4bB, LU_G4bB.UserDescription AS LimitVoluntaryArmDesc_G4bB, 
    LU_G4cA.DisplayCode AS LimitRangeHand_G4cA, LU_G4cA.UserDescription AS LimitRangeHandDesc_G4cA, 
    LU_G4cB.DisplayCode AS LimitVoluntaryHand_G4cB, LU_G4cB.UserDescription AS LimitVoluntaryHandDesc_G4cB, 
    LU_G4dA.DisplayCode AS LimitRangeLeg_G4dA, LU_G4dA.UserDescription AS LimitRangeLegDesc_G4dA, 
    LU_G4dB.DisplayCode AS LimitVoluntaryLeg_G4dB, LU_G4dB.UserDescription AS LimitVoluntaryLegDesc_G4dB, 
    LU_G4eA.DisplayCode AS LimitRangeFoot_G4eA, LU_G4eA.UserDescription AS LimitRangeFootDesc_G4eA, 
    LU_G4eB.DisplayCode AS LimitVoluntaryFoot_G4eB, LU_G4eB.UserDescription AS LimitVoluntaryFootDesc_G4eB, 
    LU_G4fA.DisplayCode AS LimitRangeOther_G4fA, LU_G4fA.UserDescription AS LimitRangeOtherDesc_G4fA, 
    LU_G4fB.DisplayCode AS LimitVoluntaryOther_G4fB, LU_G4fB.UserDescription AS LimitVoluntaryOtherDesc_G4fB, 

    (case CRS_AssessShare2.G6a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS TransferBedfast_G6a, 
    (case CRS_AssessShare2.G6a when 1 then Y.UserDescription when 2 then N.UserDescription end) AS TransferBedfastDesc_G6a, 
    (case CRS_AssessShare2.G6b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS TransferBedrail_G6b, 
    (case CRS_AssessShare2.G6b when 1 then Y.UserDescription when 2 then N.UserDescription end) AS TransferBedrailDesc_G6b, 
    (case CRS_AssessShare2.G6c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS TransferManually_G6c, 
    (case CRS_AssessShare2.G6c when 1 then Y.UserDescription when 2 then N.UserDescription end) AS TransferManuallyDesc_G6c, 
    (case CRS_AssessShare2.G6d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS TransferMechanically_G6d,
    (case CRS_AssessShare2.G6d when 1 then Y.UserDescription when 2 then N.UserDescription end) AS TransferMechanicallyDesc_G6d, 
    (case CRS_AssessShare2.G6e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS TransferAid_G6e, 
    (case CRS_AssessShare2.G6e when 1 then Y.UserDescription when 2 then N.UserDescription end) AS TransferAidDesc_G6e, 
    (case when CRS_AssessShare2.G6All > 0 then Y1.DisplayCode end) as TransferNone_G6f, 
    (case when CRS_AssessShare2.G6All > 0 then Y1.UserDescription end) as TransferNoneDesc_G6f, 

    (case CRS_AssessShare2.G7 when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS Task_G7, 
    (case CRS_AssessShare2.G7 when 1 then Y.UserDescription when 2 then N.UserDescription end) AS TaskDesc_G7, 

    LU_G9.DisplayCode AS ChangeADL_G9, LU_G9.UserDescription AS ChangeADLDesc_G9, 

    LU_H1a.DisplayCode AS BowlContinence_H1a, LU_H1a.UserDescription AS BowlContinenceDesc_H1a, 
    LU_H1b.DisplayCode AS BladderContinence_H1b, LU_H1b.UserDescription AS BladderContinenceDesc_H1b, 

    (case CRS_AssessShare2.H2a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS BowelRegular_H2a, 
    (case CRS_AssessShare2.H2a when 1 then Y.UserDescription when 2 then N.UserDescription end) AS BowelRegularDesc_H2a, 
    (case CRS_AssessShare2.H2b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS BowelConstipation_H2b, 
    (case CRS_AssessShare2.H2b when 1 then Y.UserDescription when 2 then N.UserDescription end) AS BowelConstipationDesc_H2b, 
    (case CRS_AssessShare2.H2c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS BowelDiarrhea_H2c, 
    (case CRS_AssessShare2.H2c when 1 then Y.UserDescription when 2 then N.UserDescription end) AS BowelDiarrheaDesc_H2c, 
    (case CRS_AssessShare2.H2d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS BowelFecalImpaction_H2d, 
    (case CRS_AssessShare2.H2d when 1 then Y.UserDescription when 2 then N.UserDescription end) AS BowelFecalImpactionDesc_H2d, 
    (case when CRS_AssessShare2.H2All > 0 then Y1.DisplayCode end) as BowelNone_H2e, 
    (case when CRS_AssessShare2.H2All > 0 then Y1.UserDescription end) as BowelNoneDesc_H2e, 

    (case CRS_AssessShare2.H3a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS ApplianceScheduled_H3a, 
    (case CRS_AssessShare2.H3a when 1 then Y.UserDescription when 2 then N.UserDescription end) AS ApplianceScheduledDesc_H3a, 
    (case CRS_AssessShare2.H3b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS ApplianceBladder_H3b, 
    (case CRS_AssessShare2.H3b when 1 then Y.UserDescription when 2 then N.UserDescription end) AS ApplianceBladderDesc_H3b, 
    (case CRS_AssessShare2.H3c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS ApplianceExCatheter_H3c, 
    (case CRS_AssessShare2.H3c when 1 then Y.UserDescription when 2 then N.UserDescription end) AS ApplianceExCatheterDesc_H3c, 
    (case CRS_AssessShare2.H3d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS ApplianceIndCatheter_H3d, 
    (case CRS_AssessShare2.H3d when 1 then Y.UserDescription when 2 then N.UserDescription end) AS ApplianceIndCatheterDesc_H3d, 
    (case CRS_AssessShare2.H3e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS ApplianceIntCatheter_H3e, 
    (case CRS_AssessShare2.H3e when 1 then Y.UserDescription when 2 then N.UserDescription end) AS ApplianceIntCatheterDesc_H3e, 
    (case CRS_AssessShare2.H3f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS ApplianceNotUse_H3f, 
    (case CRS_AssessShare2.H3f when 1 then Y.UserDescription when 2 then N.UserDescription end) AS ApplianceNotUseDesc_H3f, 
    (case CRS_AssessShare2.H3g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS AppliancePads_H3g, 
    (case CRS_AssessShare2.H3g when 1 then Y.UserDescription when 2 then N.UserDescription end) AS AppliancePadsDesc_H3g, 
    (case CRS_AssessShare2.H3h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS ApplianceIrrigation_H3h, 
    (case CRS_AssessShare2.H3h when 1 then Y.UserDescription when 2 then N.UserDescription end) AS ApplianceIrrigationDesc_H3h, 
    (case CRS_AssessShare2.H3i when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS ApplianceOstomy_H3i, 
    (case CRS_AssessShare2.H3i when 1 then Y.UserDescription when 2 then N.UserDescription end) AS ApplianceOstomyDesc_H3i, 
    (case when CRS_AssessShare2.H3All > 0 then Y1.DisplayCode end) as ApplianceNone_H3j, 
    (case when CRS_AssessShare2.H3All > 0 then Y1.UserDescription end) as ApplianceNoneDesc_H3j, 

    LU_H4.DisplayCode AS UrinaryContinence_H4, LU_H4.UserDescription AS UrinaryContinenceDesc_H4, 

    dbo.CRS_AssessShare2.AbstractID AS zzAbstractLink
FROM  
--    dbo.CRS_Demographic INNER JOIN dbo.LU_CodeFile LU_AA8 with (nolock) on LU_AA8.Code = dbo.CRS_Demographic.AA8 
--    INNER JOIN  CRS_AssessShare2 with (nolock) on dbo.CRS_AssessShare2.AbstractID = dbo.CRS_Demographic.AbstractID 

    dbo.CRS_AssessShare2 with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile LU_H4 with (nolock) on dbo.CRS_AssessShare2.H4 = LU_H4.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_H1b with (nolock) on dbo.CRS_AssessShare2.H1b = LU_H1b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_H1a with (nolock) on dbo.CRS_AssessShare2.H1a = LU_H1a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G9 with (nolock) on dbo.CRS_AssessShare2.G9 = LU_G9.Code LEFT OUTER JOIN

    dbo.LU_CodeFile LU_G4fB with (nolock) on LU_G4fB.Code = dbo.CRS_AssessShare2.G4fB LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4fA with (nolock) on dbo.CRS_AssessShare2.G4fA = LU_G4fA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4eB with (nolock) on LU_G4eB.Code = dbo.CRS_AssessShare2.G4eB LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4eA with (nolock) on LU_G4eA.Code = dbo.CRS_AssessShare2.G4eA LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4dB with (nolock) on LU_G4dB.Code = dbo.CRS_AssessShare2.G4dB LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4dA with (nolock) on dbo.CRS_AssessShare2.G4dA = LU_G4dA.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_G4cB with (nolock) on LU_G4cB.Code = dbo.CRS_AssessShare2.G4cB LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4cA with (nolock) on dbo.CRS_AssessShare2.G4cA = LU_G4cA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4bB with (nolock) on dbo.CRS_AssessShare2.G4bB = LU_G4bB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4bA with (nolock) on dbo.CRS_AssessShare2.G4bA = LU_G4bA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4aB with (nolock) on dbo.CRS_AssessShare2.G4aB = LU_G4aB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G4aA with (nolock) on dbo.CRS_AssessShare2.G4aA = LU_G4aA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G3b with (nolock) on dbo.CRS_AssessShare2.G3b = LU_G3b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G3a with (nolock) on dbo.CRS_AssessShare2.G3a = LU_G3a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G2B with (nolock) on dbo.CRS_AssessShare2.G2B = LU_G2B.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G2A with (nolock) on dbo.CRS_AssessShare2.G2A = LU_G2A.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1jB with (nolock) on dbo.CRS_AssessShare2.G1jB = LU_G1jB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1jA with (nolock) on dbo.CRS_AssessShare2.G1jA = LU_G1jA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1IB with (nolock) on dbo.CRS_AssessShare2.G1iB = LU_G1IB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1IA with (nolock) on dbo.CRS_AssessShare2.G1iA = LU_G1IA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1hB with (nolock) on dbo.CRS_AssessShare2.G1hB = LU_G1hB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1hA with (nolock) on dbo.CRS_AssessShare2.G1hA = LU_G1hA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1gB with (nolock) on dbo.CRS_AssessShare2.G1gB = LU_G1gB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1gA with (nolock) on dbo.CRS_AssessShare2.G1gA = LU_G1gA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1fB with (nolock) on dbo.CRS_AssessShare2.G1fB = LU_G1fB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1fA with (nolock) on dbo.CRS_AssessShare2.G1fA = LU_G1fA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1eB with (nolock) on dbo.CRS_AssessShare2.G1eB = LU_G1eB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1eA with (nolock) on dbo.CRS_AssessShare2.G1eA = LU_G1eA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1dA with (nolock) on dbo.CRS_AssessShare2.G1dA = LU_G1dA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1dB with (nolock) on dbo.CRS_AssessShare2.G1dB = LU_G1dB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1cB with (nolock) on dbo.CRS_AssessShare2.G1cB = LU_G1cB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1cA with (nolock) on dbo.CRS_AssessShare2.G1cA = LU_G1cA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1bB with (nolock) on dbo.CRS_AssessShare2.G1bB = LU_G1bB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1bA with (nolock) on dbo.CRS_AssessShare2.G1bA = LU_G1bA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1aB with (nolock) on dbo.CRS_AssessShare2.G1aB = LU_G1aB.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_G1aA with (nolock) on dbo.CRS_AssessShare2.G1aA = LU_G1aA.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F1f with (nolock) on dbo.CRS_AssessShare2.F1f = LU_F1f.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F1e with (nolock) on dbo.CRS_AssessShare2.F1e = LU_F1e.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F1d with (nolock) on dbo.CRS_AssessShare2.F1d = LU_F1d.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F1c with (nolock) on dbo.CRS_AssessShare2.F1c = LU_F1c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F1b with (nolock) on dbo.CRS_AssessShare2.F1b = LU_F1b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F1a with (nolock) on dbo.CRS_AssessShare2.F1a = LU_F1a.Code 
    cross join ( select top 1 DisplayCode, UserDescription from LU_YesNoSystem where code = 1 ) Y
    cross join ( select top 1 DisplayCode, UserDescription from LU_YesNoSystem where code = 2 ) N
    cross join ( select top 1 DisplayCode, UserDescription from LU_CodeFile where LookUpID = 1 ) Y1

/*
    dbo.LU_CodeFile LU_H3All with (nolock) on dbo.CRS_AssessShare2.H3All = LU_H3All.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_H2All with (nolock) on dbo.CRS_AssessShare2.H2All = LU_H2All.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_F1All with (nolock) on dbo.CRS_AssessShare2.F1All = LU_F1All.Code 
    dbo.LU_CodeFile LU_G6All with (nolock) on LU_G6All.Code = dbo.CRS_AssessShare2.G6All LEFT OUTER JOIN

    dbo.LU_YesNoSystem LU_H2d with (nolock) on dbo.CRS_AssessShare2.H2d = LU_H2d.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_H2c with (nolock) on dbo.CRS_AssessShare2.H2c = LU_H2c.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_H2b with (nolock) on dbo.CRS_AssessShare2.H2b = LU_H2b.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_H2a with (nolock) on dbo.CRS_AssessShare2.H2a = LU_H2a.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_H3i with (nolock) on dbo.CRS_AssessShare2.H3I = LU_H3i.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_H3h with (nolock) on dbo.CRS_AssessShare2.H3h = LU_H3h.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_H3g with (nolock) on dbo.CRS_AssessShare2.H3g = LU_H3g.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_H3f with (nolock) on dbo.CRS_AssessShare2.H3f = LU_H3f.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_H3e with (nolock) on dbo.CRS_AssessShare2.H3e = LU_H3e.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_H3d with (nolock) on dbo.CRS_AssessShare2.H3d = LU_H3d.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_H3c with (nolock) on dbo.CRS_AssessShare2.H3c = LU_H3c.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_H3b with (nolock) on dbo.CRS_AssessShare2.H3b = LU_H3b.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_H3a with (nolock) on dbo.CRS_AssessShare2.H3a = LU_H3a.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_G7 with (nolock) on dbo.CRS_AssessShare2.G7 = LU_G7.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_G6e with (nolock) on dbo.CRS_AssessShare2.G6e = LU_G6e.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_G6d with (nolock) on dbo.CRS_AssessShare2.G6d = LU_G6d.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_G6c with (nolock) on dbo.CRS_AssessShare2.G6c = LU_G6c.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_G6b with (nolock) on dbo.CRS_AssessShare2.G6b = LU_G6b.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_G6a with (nolock) on dbo.CRS_AssessShare2.G6a = LU_G6a.Code LEFT OUTER JOIN
*/















' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Shared_3_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[MDS20_Shared_3_VR]
AS
SELECT 
    dbo.CRS_AssessShare3.AbstractID AS zzAbstractLink, 
    (case CRS_AssessShare3.I1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseDiabMellitus_I1a, 
    (case CRS_AssessShare3.I1a when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseDiabMellitusDesc_I1a, 
    (case CRS_AssessShare3.I1b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseHyperthyroidism_I1b, 
    (case CRS_AssessShare3.I1b when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseHyperthyroidDesc_I1b, 
    (case CRS_AssessShare3.I1c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseHypothyroidism_I1c, 
    (case CRS_AssessShare3.I1c when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseHypothyroidismDesc_I1c, 
    (case CRS_AssessShare3.I1d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseASHD_I1d, 
    (case CRS_AssessShare3.I1d when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseASHDDesc_I1d, 
    (case CRS_AssessShare3.I1e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseCardiac_I1e, 
    (case CRS_AssessShare3.I1e when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseCardiacDesc_I1e, 
    (case CRS_AssessShare3.I1f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseCongestive_I1f, 
    (case CRS_AssessShare3.I1f when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseCongestiveDesc_I1f, 
    (case CRS_AssessShare3.I1g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseThrombosis_I1g, 
    (case CRS_AssessShare3.I1g when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseThrombosisDesc_I1g, 
    (case CRS_AssessShare3.I1h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseHypertension_I1h, 
    (case CRS_AssessShare3.I1h when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseHypertensionDesc_I1h, 
    (case CRS_AssessShare3.I1I when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseHypotension_I1i, 
    (case CRS_AssessShare3.I1I when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseHypotensionDesc_I1i, 
    (case CRS_AssessShare3.I1j when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseVascular_I1j, 
    (case CRS_AssessShare3.I1j when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseVascularDesc_I1j, 
    (case CRS_AssessShare3.I1k when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseCardiovascular_I1k, 
    (case CRS_AssessShare3.I1k when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseCardiovascularDesc_I1k, 
    (case CRS_AssessShare3.I1l when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseArthritis_I1l, 
    (case CRS_AssessShare3.I1l when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseArthritisDesc_I1l, 
    (case CRS_AssessShare3.I1m when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseHipFracture_I1m, 
    (case CRS_AssessShare3.I1m when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseHipFractureDesc_I1m, 
    (case CRS_AssessShare3.I1n when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseLimb_I1n, 
    (case CRS_AssessShare3.I1n when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseLimbDesc_I1n, 
    (case CRS_AssessShare3.I1o when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseOsteoporosis_I1o, 
    (case CRS_AssessShare3.I1o when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseOsteoporosisDesc_I1o, 
    (case CRS_AssessShare3.I1p when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseBoneFracture_I1p, 
    (case CRS_AssessShare3.I1p when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseBoneFractureDesc_I1p, 
    (case CRS_AssessShare3.I1q when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseALS_I1q, 
    (case CRS_AssessShare3.I1q when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseALSDesc_I1q, 
    (case CRS_AssessShare3.I1r when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseAlzheimer_I1r, 
    (case CRS_AssessShare3.I1r when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseAlzheimerDesc_I1r, 
    (case CRS_AssessShare3.I1s when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseAphasia_I1s, 
    (case CRS_AssessShare3.I1s when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseAphasiaDesc_I1s, 
    (case CRS_AssessShare3.I1t when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseCerebralPalsy_I1t, 
    (case CRS_AssessShare3.I1t when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseCerebralPalsyDesc_I1t, 
    (case CRS_AssessShare3.I1u when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseCerebro_I1u, 
    (case CRS_AssessShare3.I1u when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseCerebroDesc_I1u, 
    (case CRS_AssessShare3.I1v when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseDementia_I1v, 
    (case CRS_AssessShare3.I1v when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseDementiaDesc_I1v, 
    (case CRS_AssessShare3.I1w when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseHemiplegia_I1w, 
    (case CRS_AssessShare3.I1w when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseHemiplegiaDesc_I1w, 
    (case CRS_AssessShare3.I1x when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseChorea_I1x, 
    (case CRS_AssessShare3.I1x when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseChoreaDesc_I1x, 
    (case CRS_AssessShare3.I1y when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseSclerosis_I1y, 
    (case CRS_AssessShare3.I1y when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseSclerosisDesc_I1y, 
    (case CRS_AssessShare3.I1z when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseParaplegia_I1z, 
    (case CRS_AssessShare3.I1z when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseParaplegiaDesc_I1z, 
    (case CRS_AssessShare3.I1aa when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseParkinson_I1aa, 
    (case CRS_AssessShare3.I1aa when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseParkinsonDesc_I1aa, 
    (case CRS_AssessShare3.I1bb when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseQuadriplegia_I1bb, 
    (case CRS_AssessShare3.I1bb when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseQuadriplegiaDesc_I1bb, 
    (case CRS_AssessShare3.I1cc when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseSeizureDisorder_I1cc, 
    (case CRS_AssessShare3.I1cc when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseSeizeDisorderDesc_I1cc, 
    (case CRS_AssessShare3.I1dd when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseIschemic_I1dd, 
    (case CRS_AssessShare3.I1dd when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseIschemicDesc_I1dd, 
    (case CRS_AssessShare3.I1ee when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseTraumaticBrain_I1ee, 
    (case CRS_AssessShare3.I1ee when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseTraumaBrainDesc_I1ee, 
    (case CRS_AssessShare3.I1ff when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseAnxietyDisorder_I1ff, 
    (case CRS_AssessShare3.I1ff when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseAnxietyDisDesc_I1ff, 
    (case CRS_AssessShare3.I1gg when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseDepression_I1gg, 
    (case CRS_AssessShare3.I1gg when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseDepressionDesc_I1gg, 
    (case CRS_AssessShare3.I1hh when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseManicDepressive_I1hh, 
    (case CRS_AssessShare3.I1hh when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseManicDepressDesc_I1hh, 
    (case CRS_AssessShare3.I1ii when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseSchizophrenia_I1ii, 
    (case CRS_AssessShare3.I1ii when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseSchizophreniaDesc_I1ii, 
    (case CRS_AssessShare3.I1jj when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseAsthma_I1jj, 
    (case CRS_AssessShare3.I1jj when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseAsthmaDesc_I1jj, 
    (case CRS_AssessShare3.I1kk when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseEmphysema_I1kk, 
    (case CRS_AssessShare3.I1kk when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseEmphysemaDesc_I1kk, 
    (case CRS_AssessShare3.I1ll when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseCatarats_I1ll, 
    (case CRS_AssessShare3.I1ll when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseCataratsDesc_I1ll, 
    (case CRS_AssessShare3.I1mm when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseDiabRetino_I1mm, 
    (case CRS_AssessShare3.I1mm when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseDiabRetinoDesc_I1mm, 
    (case CRS_AssessShare3.I1nn when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseGlaucoma_I1nn, 
    (case CRS_AssessShare3.I1nn when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseGlaucomaDesc_I1nn, 
    (case CRS_AssessShare3.I1oo when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseMacularDegenerate_I1oo, 
    (case CRS_AssessShare3.I1oo when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseMacularDegenDesc_I1oo, 
    (case CRS_AssessShare3.I1pp when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseAllergies_I1pp, 
    (case CRS_AssessShare3.I1pp when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseAllergiesDesc_I1pp, 
    (case CRS_AssessShare3.I1qq when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseAnemia_I1qq, 
    (case CRS_AssessShare3.I1qq when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseAnemiaDesc_I1qq, 
    (case CRS_AssessShare3.I1rr when 1 then Y.DisplayCode when 2 then N.DisplayCode end) AS DiseaseCancer_I1rr, 
    (case CRS_AssessShare3.I1rr when 1 then Y.UserDescription when 2 then N.UserDescription end) AS DiseaseCancerDesc_I1rr, 
    (case CRS_AssessShare3.I1ss when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as DiseaseGastrointestinal_I1ss, 
    (case CRS_AssessShare3.I1ss when 1 then Y.UserDescription when 2 then N.UserDescription end) as DiseaseGastroDesc_I1ss, 
    (case CRS_AssessShare3.I1tt when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as DiseaseLiver_I1tt, 
    (case CRS_AssessShare3.I1tt when 1 then Y.UserDescription when 2 then N.UserDescription end) as DiseaseLiverDesc_I1tt, 
    (case CRS_AssessShare3.I1uu when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as DiseaseRenalFailure_I1uu, 
    (case CRS_AssessShare3.I1uu when 1 then Y.UserDescription when 2 then N.UserDescription end) as DiseaseRenalFailureDesc_I1uu, 
    (case when CRS_AssessShare3.I1All > 0 then Y1.DisplayCode end) as DiseaseNone_I1vv, 
    (case when CRS_AssessShare3.I1All > 0 then Y1.UserDescription end) as DiseaseNoneDesc_I1vv, 

    (case CRS_AssessShare3.I2a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionAntibiotic_I2a, 
    (case CRS_AssessShare3.I2a when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionAntibioticDesc_I2a, 
    (case CRS_AssessShare3.I2b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionCellulitis_I2b, 
    (case CRS_AssessShare3.I2b when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionCellulitisDesc_I2b, 
    (case CRS_AssessShare3.I2c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionClostridium_I2c, 
    (case CRS_AssessShare3.I2c when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionClostridiumDesc_I2c, 
    (case CRS_AssessShare3.I2d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionConjunctivitis_I2d, 
    (case CRS_AssessShare3.I2d when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionConjunctivaDesc_I2d, 
    (case CRS_AssessShare3.I2e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionHIV_I2e, 
    (case CRS_AssessShare3.I2e when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionHIVDesc_I2e, 
    (case CRS_AssessShare3.I2f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionPneumonia_I2f, 
    (case CRS_AssessShare3.I2f when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionPneumoniaDesc_I2f, 
    (case CRS_AssessShare3.I2g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionRespiratory_I2g, 
    (case CRS_AssessShare3.I2g when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionRespiratoryDesc_I2g, 
    (case CRS_AssessShare3.I2h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionSepticemia_I2h, 
    (case CRS_AssessShare3.I2h when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionSepticemiaDesc_I2h, 
    (case CRS_AssessShare3.I2I when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionSexually_I2i, 
    (case CRS_AssessShare3.I2I when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionSexuallyDesc_I2i, 
    (case CRS_AssessShare3.I2j when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionTuberculosis_I2j, 
    (case CRS_AssessShare3.I2j when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionTuberculosisDesc_I2j, 
    (case CRS_AssessShare3.I2k when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionUrinary_I2k, 
    (case CRS_AssessShare3.I2k when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionUrinaryDesc_I2k, 
    (case CRS_AssessShare3.I2l when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionHepatitis_I2l, 
    (case CRS_AssessShare3.I2l when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionHepatitisDesc_I2l, 
    (case CRS_AssessShare3.I2m when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as InfectionWound_I2m, 
    (case CRS_AssessShare3.I2m when 1 then Y.UserDescription when 2 then N.UserDescription end) as InfectionWoundDesc_I2m, 
    (case when CRS_AssessShare3.I2All > 0 then Y1.DisplayCode end) as InfectionNone_I2n, 
    (case when CRS_AssessShare3.I2All > 0 then Y1.UserDescription end) as InfectionNoneDesc_I2n, 

    (case CRS_AssessShare3.J1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemWeight_J1a, 
    (case CRS_AssessShare3.J1a when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemWeightDesc_J1a, 
    (case CRS_AssessShare3.J1b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemLieFlat_J1b, 
    (case CRS_AssessShare3.J1b when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemLieFlatDesc_J1b, 
    (case CRS_AssessShare3.J1c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemDehydrated_J1c, 
    (case CRS_AssessShare3.J1c when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemDehydratedDesc_J1c, 
    (case CRS_AssessShare3.J1d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemFluid_J1d, 
    (case CRS_AssessShare3.J1d when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemFluidDesc_J1d, 
    (case CRS_AssessShare3.J1e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemDelusions_J1e, 
    (case CRS_AssessShare3.J1e when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemDelusionsDesc_J1e, 
    (case CRS_AssessShare3.J1f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemDizziness_J1f, 
    (case CRS_AssessShare3.J1f when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemDizzinessDesc_J1f, 
    (case CRS_AssessShare3.J1g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemEdema_J1g, 
    (case CRS_AssessShare3.J1g when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemEdemaDesc_J1g, 
    (case CRS_AssessShare3.J1h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemFever_J1h, 
    (case CRS_AssessShare3.J1h when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemFeverDesc_J1h, 
    (case CRS_AssessShare3.J1I when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemHallucinations_J1i, 
    (case CRS_AssessShare3.J1I when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemHallucinationsDesc_J1i, 
    (case CRS_AssessShare3.J1j when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemBleeding_J1j, 
    (case CRS_AssessShare3.J1j when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemBleedingDesc_J1j, 
    (case CRS_AssessShare3.J1k when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemLung_J1k, 
    (case CRS_AssessShare3.J1k when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemLungDesc_J1k, 
    (case CRS_AssessShare3.J1l when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemBreath_J1l, 
    (case CRS_AssessShare3.J1l when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemBreathDesc_J1l, 
    (case CRS_AssessShare3.J1m when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemSyncope_J1m, 
    (case CRS_AssessShare3.J1m when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemSyncopeDesc_J1m, 
    (case CRS_AssessShare3.J1n when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemUnsteadyGait_J1n, 
    (case CRS_AssessShare3.J1n when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemUnsteadyGaitDesc_J1n, 
    (case CRS_AssessShare3.J1o when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as ProblemVomiting_J1o, 
    (case CRS_AssessShare3.J1o when 1 then Y.UserDescription when 2 then N.UserDescription end) as ProblemVomitingDesc_J1o, 
    (case when CRS_AssessShare3.J1All > 0 then Y1.DisplayCode end) as ProblemNone_J1p, 
    (case when CRS_AssessShare3.J1All > 0 then Y1.UserDescription end) as ProblemNoneDesc_J1p, 

    LU_J2a.DisplayCode AS Pain_Frequency_J2a, LU_J2a.UserDescription AS Pain_FrequencyDesc_J2a, 
    LU_J2b.DisplayCode AS Pain_Intensity_J2b, LU_J2b.UserDescription AS Pain_IntensityDesc_J2b, 

    (case CRS_AssessShare3.J4a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as AccidentFell30_J4a, 
    (case CRS_AssessShare3.J4a when 1 then Y.UserDescription when 2 then N.UserDescription end) as AccidentFell30Desc_J4a, 
    (case CRS_AssessShare3.J4b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as AccidentFell180_J4b, 
    (case CRS_AssessShare3.J4b when 1 then Y.UserDescription when 2 then N.UserDescription end) as AccidentFell180Desc_J4b, 
    (case CRS_AssessShare3.J4c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as AccidentHipFracture_J4c, 
    (case CRS_AssessShare3.J4c when 1 then Y.UserDescription when 2 then N.UserDescription end) as AccidentHipFractureDesc_J4c, 
    (case CRS_AssessShare3.J4d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as AccidentOtherFracture_J4d, 
    (case CRS_AssessShare3.J4d when 1 then Y.UserDescription when 2 then N.UserDescription end) as AccidentOtherFractureDesc_J4d, 
    (case when CRS_AssessShare3.J4All > 0 then Y1.DisplayCode end) as AccidentNone_J4e, 
    (case when CRS_AssessShare3.J4All > 0 then Y1.UserDescription end) as AccidentNoneDesc_J4e, 

    (case CRS_AssessShare3.J5a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Stability_Unstable_J5a, 
    (case CRS_AssessShare3.J5a when 1 then Y.UserDescription when 2 then N.UserDescription end) as Stability_UnstableDesc_J5a, 
    (case CRS_AssessShare3.J5b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Stability_Acute_J5b, 
    (case CRS_AssessShare3.J5b when 1 then Y.UserDescription when 2 then N.UserDescription end) as Stability_AcuteDesc_J5b, 
    (case CRS_AssessShare3.J5c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Stability_EndStage_J5c, 
    (case CRS_AssessShare3.J5c when 1 then Y.UserDescription when 2 then N.UserDescription end) as Stability_EndStageDesc_J5c, 
    (case when CRS_AssessShare3.J5All > 0 then Y1.DisplayCode end) as Stability_None_J5d, 
    (case when CRS_AssessShare3.J5All > 0 then Y1.UserDescription end) as Stability_None_Desc_J5d
    --dbo.CRS_AssessShare3.PURS
FROM  
--    dbo.CRS_AssessShare3 INNER JOIN
--    dbo.CRS_Demographic with (nolock) on dbo.CRS_AssessShare3.AbstractID = dbo.CRS_Demographic.AbstractID 
--    dbo.CRS_AssessShare3 with (nolock) on LU_AA8.Code = dbo.CRS_Demographic.AA8 

    dbo.CRS_AssessShare3 with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J2b with (nolock) on dbo.CRS_AssessShare3.J2b = LU_J2b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J2a with (nolock) on dbo.CRS_AssessShare3.J2a = LU_J2a.Code 
    cross join ( select top 1 DisplayCode, UserDescription from LU_YesNoSystem where code = 1 ) Y
    cross join ( select top 1 DisplayCode, UserDescription from LU_YesNoSystem where code = 2 ) N
    cross join ( select top 1 DisplayCode, UserDescription from LU_CodeFile where LookUpID = 1 ) Y1

/*
    dbo.LU_CodeFile LU_J1All with (nolock) on dbo.CRS_AssessShare3.J1All = LU_J1All.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J4All with (nolock) on dbo.CRS_AssessShare3.J4All = LU_J4All.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_J5All with (nolock) on dbo.CRS_AssessShare3.J5All = LU_J5All.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_I1All with (nolock) on dbo.CRS_AssessShare3.I1All = LU_I1All.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_I2All with (nolock) on dbo.CRS_AssessShare3.I2All = LU_I2All.Code 

    dbo.LU_YesNoSystem LU_J5c with (nolock) on dbo.CRS_AssessShare3.J5c = LU_J5c.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J5b with (nolock) on dbo.CRS_AssessShare3.J5b = LU_J5b.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J5a with (nolock) on dbo.CRS_AssessShare3.J5a = LU_J5a.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J4d with (nolock) on dbo.CRS_AssessShare3.J4d = LU_J4d.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J4c with (nolock) on dbo.CRS_AssessShare3.J4c = LU_J4c.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J4b with (nolock) on dbo.CRS_AssessShare3.J4b = LU_J4b.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J4a with (nolock) on dbo.CRS_AssessShare3.J4a = LU_J4a.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J1o with (nolock) on dbo.CRS_AssessShare3.J1o = LU_J1o.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J1n with (nolock) on dbo.CRS_AssessShare3.J1n = LU_J1n.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J1m with (nolock) on dbo.CRS_AssessShare3.J1m = LU_J1m.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J1l with (nolock) on dbo.CRS_AssessShare3.J1l = LU_J1l.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J1k with (nolock) on dbo.CRS_AssessShare3.J1k = LU_J1k.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J1j with (nolock) on dbo.CRS_AssessShare3.J1j = LU_J1j.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J1I with (nolock) on dbo.CRS_AssessShare3.J1i = LU_J1I.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J1h with (nolock) on dbo.CRS_AssessShare3.J1h = LU_J1h.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J1g with (nolock) on dbo.CRS_AssessShare3.J1g = LU_J1g.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J1f with (nolock) on dbo.CRS_AssessShare3.J1f = LU_J1f.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J1e with (nolock) on dbo.CRS_AssessShare3.J1e = LU_J1e.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J1d with (nolock) on dbo.CRS_AssessShare3.J1d = LU_J1d.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J1c with (nolock) on dbo.CRS_AssessShare3.J1c = LU_J1c.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J1b with (nolock) on dbo.CRS_AssessShare3.J1b = LU_J1b.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_J1a with (nolock) on dbo.CRS_AssessShare3.J1a = LU_J1a.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I2m with (nolock) on dbo.CRS_AssessShare3.I2m = LU_I2m.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I2l with (nolock) on dbo.CRS_AssessShare3.I2l = LU_I2l.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I2k with (nolock) on dbo.CRS_AssessShare3.I2k = LU_I2k.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I2j with (nolock) on dbo.CRS_AssessShare3.I2j = LU_I2j.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I2I with (nolock) on dbo.CRS_AssessShare3.I2I = LU_I2I.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I2h with (nolock) on dbo.CRS_AssessShare3.I2h = LU_I2h.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I2g with (nolock) on dbo.CRS_AssessShare3.I2g = LU_I2g.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I2f with (nolock) on dbo.CRS_AssessShare3.I2f = LU_I2f.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I2e with (nolock) on dbo.CRS_AssessShare3.I2e = LU_I2e.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I2d with (nolock) on dbo.CRS_AssessShare3.I2d = LU_I2d.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I2c with (nolock) on dbo.CRS_AssessShare3.I2c = LU_I2c.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I2b with (nolock) on dbo.CRS_AssessShare3.I2b = LU_I2b.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I2a with (nolock) on dbo.CRS_AssessShare3.I2a = LU_I2a.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1uu with (nolock) on dbo.CRS_AssessShare3.I1uu = LU_I1uu.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1tt with (nolock) on dbo.CRS_AssessShare3.I1tt = LU_I1tt.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1ss with (nolock) on dbo.CRS_AssessShare3.I1ss = LU_I1ss.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1rr with (nolock) on dbo.CRS_AssessShare3.I1rr = LU_I1rr.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1qq with (nolock) on dbo.CRS_AssessShare3.I1qq = LU_I1qq.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1pp with (nolock) on dbo.CRS_AssessShare3.I1pp = LU_I1pp.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1oo with (nolock) on dbo.CRS_AssessShare3.I1oo = LU_I1oo.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1nn with (nolock) on dbo.CRS_AssessShare3.I1nn = LU_I1nn.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1mm with (nolock) on dbo.CRS_AssessShare3.I1mm = LU_I1mm.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1ll with (nolock) on dbo.CRS_AssessShare3.I1ll = LU_I1ll.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1kk with (nolock) on dbo.CRS_AssessShare3.I1kk = LU_I1kk.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1jj with (nolock) on dbo.CRS_AssessShare3.I1jj = LU_I1jj.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1ii with (nolock) on dbo.CRS_AssessShare3.I1ii = LU_I1ii.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1hh with (nolock) on dbo.CRS_AssessShare3.I1hh = LU_I1hh.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1gg with (nolock) on dbo.CRS_AssessShare3.I1gg = LU_I1gg.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1ff with (nolock) on dbo.CRS_AssessShare3.I1ff = LU_I1ff.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1ee with (nolock) on dbo.CRS_AssessShare3.I1ee = LU_I1ee.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1dd with (nolock) on dbo.CRS_AssessShare3.I1dd = LU_I1dd.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1cc with (nolock) on dbo.CRS_AssessShare3.I1cc = LU_I1cc.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1bb with (nolock) on dbo.CRS_AssessShare3.I1bb = LU_I1bb.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1aa with (nolock) on dbo.CRS_AssessShare3.I1aa = LU_I1aa.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1z with (nolock) on dbo.CRS_AssessShare3.I1z = LU_I1z.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1y with (nolock) on dbo.CRS_AssessShare3.I1y = LU_I1y.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1x with (nolock) on dbo.CRS_AssessShare3.I1x = LU_I1x.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1w with (nolock) on dbo.CRS_AssessShare3.I1w = LU_I1w.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1v with (nolock) on dbo.CRS_AssessShare3.I1v = LU_I1v.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1u with (nolock) on dbo.CRS_AssessShare3.I1u = LU_I1u.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1t with (nolock) on dbo.CRS_AssessShare3.I1t = LU_I1t.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1s with (nolock) on dbo.CRS_AssessShare3.I1s = LU_I1s.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1r with (nolock) on dbo.CRS_AssessShare3.I1r = LU_I1r.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1q with (nolock) on dbo.CRS_AssessShare3.I1q = LU_I1q.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1p with (nolock) on dbo.CRS_AssessShare3.I1p = LU_I1p.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1o with (nolock) on dbo.CRS_AssessShare3.I1o = LU_I1o.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1n with (nolock) on dbo.CRS_AssessShare3.I1n = LU_I1n.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1m with (nolock) on dbo.CRS_AssessShare3.I1m = LU_I1m.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1l with (nolock) on dbo.CRS_AssessShare3.I1l = LU_I1l.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1k with (nolock) on dbo.CRS_AssessShare3.I1k = LU_I1k.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1j with (nolock) on dbo.CRS_AssessShare3.I1j = LU_I1j.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1I with (nolock) on dbo.CRS_AssessShare3.I1i = LU_I1I.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1h with (nolock) on dbo.CRS_AssessShare3.I1h = LU_I1h.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1g with (nolock) on dbo.CRS_AssessShare3.I1g = LU_I1g.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1f with (nolock) on dbo.CRS_AssessShare3.I1f = LU_I1f.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1e with (nolock) on dbo.CRS_AssessShare3.I1e = LU_I1e.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1d with (nolock) on dbo.CRS_AssessShare3.I1d = LU_I1d.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1c with (nolock) on dbo.CRS_AssessShare3.I1c = LU_I1c.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1b with (nolock) on dbo.CRS_AssessShare3.I1b = LU_I1b.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_I1a with (nolock) on dbo.CRS_AssessShare3.I1a = LU_I1a.Code LEFT OUTER JOIN
*/

















' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Shared_4_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[MDS20_Shared_4_VR]
AS
SELECT   
    dbo.CRS_AssessShare4.AbstractID AS zzAbstractLink, 
    (case CRS_AssessShare4.K1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as OralUnstable_K1a, 
    (case CRS_AssessShare4.K1a when 1 then Y.UserDescription when 2 then N.UserDescription end) as OralUnstableDesc_K1a, 
    (case CRS_AssessShare4.K1b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as OralAcute_K1b, 
    (case CRS_AssessShare4.K1b when 1 then Y.UserDescription when 2 then N.UserDescription end) as OralAcuteDesc_K1b, 
    (case CRS_AssessShare4.K1c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as OralEndStage_K1c, 
    (case CRS_AssessShare4.K1c when 1 then Y.UserDescription when 2 then N.UserDescription end) as OralEndStageDesc_K1c, 
    (case when CRS_AssessShare4.K1All > 0 then Y1.DisplayCode end) as OralNone_K1d, 
    (case when CRS_AssessShare4.K1All > 0 then Y1.UserDescription end) as OralDesc_K1d, 

    dbo.CRS_AssessShare4.K2a as Height_K2a, dbo.CRS_AssessShare4.K2b as Weight_K2b, 

    --PR - 05185 to use cihivalue
    --(case when LU_AA8.CIHIValue not in (''05'', ''10'') then LU_K3a_Q.DisplayCode else (case CRS_AssessShare4.K3a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS WeightLoss_K3a, 
    (case when LU_AA8.CIHIValue not in (''05'', ''10'') then LU_K3a_F.CIHIValue else (case CRS_AssessShare4.K3a when 1 then Y.CIHIValue when 2 then N.CIHIValue end) end) AS WeightLoss_K3a, 
    (case when LU_AA8.CIHIValue not in (''05'', ''10'') then LU_K3a_F.UserDescription else (case CRS_AssessShare4.K3a when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS WeightLossDesc_K3a, 
    --(case when LU_AA8.CIHIValue not in (''05'', ''10'') then LU_K3b_Q.DisplayCode else (case CRS_AssessShare4.K3b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) end) AS WeightGain_K3b,
    (case when LU_AA8.CIHIValue not in (''05'', ''10'') then LU_K3b_F.CIHIValue else (case CRS_AssessShare4.K3b when 1 then Y.CIHIValue when 2 then N.CIHIValue end) end) AS WeightGain_K3b,
    (case when LU_AA8.CIHIValue not in (''05'', ''10'') then LU_K3b_F.UserDescription else (case CRS_AssessShare4.K3b when 1 then Y.UserDescription when 2 then N.UserDescription end) end) AS WeightGainDesc_K3b, 
    
    (case CRS_AssessShare4.K4a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Nutritional_Taste_K4a, 
    (case CRS_AssessShare4.K4a when 1 then Y.UserDescription when 2 then N.UserDescription end) as Nutritional_TasteDesc_K4a, 
    (case CRS_AssessShare4.K4b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Nutritional_Hunger_K4b, 
    (case CRS_AssessShare4.K4b when 1 then Y.UserDescription when 2 then N.UserDescription end) as Nutritional_HungerDesc_K4b, 
    (case CRS_AssessShare4.K4c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Nutritional_LeaveFood_K4c, 
    (case CRS_AssessShare4.K4c when 1 then Y.UserDescription when 2 then N.UserDescription end) as Nutritional_LeaveFoodDesc_K4c, 
    (case when CRS_AssessShare4.K4All > 0 then Y1.DisplayCode end) as Nutritional_None_K4d, 
    (case when CRS_AssessShare4.K4All > 0 then Y1.UserDescription end) as Nutritional_NoneDesc_K4d, 

    (case CRS_AssessShare4.K5a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as NutritionalAppPatenteral_K5a, 
    (case CRS_AssessShare4.K5a when 1 then Y.UserDescription when 2 then N.UserDescription end) as NutritionalAppPatentDesc_K5a, 
    (case CRS_AssessShare4.K5b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as NutritionalAppFeedTube_K5b, 
    (case CRS_AssessShare4.K5b when 1 then Y.UserDescription when 2 then N.UserDescription end) as NutritionalAppFeedTDesc_K5b, 
    (case CRS_AssessShare4.K5c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as NutritionalAppDiet_K5c, 
    (case CRS_AssessShare4.K5c when 1 then Y.UserDescription when 2 then N.UserDescription end) as NutritionalAppDietDesc_K5c, 
    (case CRS_AssessShare4.K5d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as NutritionalAppSyringe_K5d, 
    (case CRS_AssessShare4.K5d when 1 then Y.UserDescription when 2 then N.UserDescription end) as NutritionalAppSyringeDesc_K5d, 
    (case CRS_AssessShare4.K5e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as NutritionalAppTherapeutic_K5e, 
    (case CRS_AssessShare4.K5e when 1 then Y.UserDescription when 2 then N.UserDescription end) as NutritionalAppTherapeDesc_K5e, 
    (case CRS_AssessShare4.K5f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as NutritionalAppSupplement_K5f, 
    (case CRS_AssessShare4.K5f when 1 then Y.UserDescription when 2 then N.UserDescription end) as NutritionalAppSupplyDesc_K5f, 
    (case CRS_AssessShare4.K5g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as NutritionalAppUtensil_K5g, 
    (case CRS_AssessShare4.K5g when 1 then Y.UserDescription when 2 then N.UserDescription end) as NutritionalAppUtensilDesc_K5g, 
    (case CRS_AssessShare4.K5h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as NutritionalAppWeight_K5h, 
    (case CRS_AssessShare4.K5h when 1 then Y.UserDescription when 2 then N.UserDescription end) as NutritionalAppWeightDesc_K5h, 
    (case when CRS_AssessShare4.K5All > 0 then Y1.DisplayCode end) as NutritionalAppNone_K5i, 
    (case when CRS_AssessShare4.K5All > 0 then Y1.UserDescription end) as NutritionalAppNoneDesc_K5i, 

    LU_K6a.DisplayCode AS ParenteralProportion_K6a, LU_K6a.UserDescription AS ParenteralProportionDesc_K6a, 
    LU_K6b.DisplayCode AS ParenteralAverage_K6b, LU_K6b.UserDescription AS ParenteralAverageDesc_K6b, 

    dbo.CRS_AssessShare4.M1a as Ulcers_Stage1_M1a, 
    dbo.CRS_AssessShare4.M1b as Ulcers_Stage2_M1b, 
    dbo.CRS_AssessShare4.M1c as Ulcers_Stage3_M1c, 
    dbo.CRS_AssessShare4.M1d as Ulcers_Stage4_M1d, 

    LU_M2a.DisplayCode AS UlcerTypePressure_M2a, LU_M2a.UserDescription AS UlcerType_PressureDesc_M2a, 
    LU_M2b.DisplayCode AS UlcerType_Stasis_M2b, LU_M2b.UserDescription AS UlcerType_StasisDesc_M2b, 

    (case CRS_AssessShare4.M4a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinAbrasions_M4a, 
    (case CRS_AssessShare4.M4a when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinAbrasionsDesc_M4a, 
    (case CRS_AssessShare4.M4b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinBurn_M4b, 
    (case CRS_AssessShare4.M4b when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinBurnDesc_M4b, 
    (case CRS_AssessShare4.M4c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinLesions_M4c, 
    (case CRS_AssessShare4.M4c when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinLesionsDesc_M4c, 
    (case CRS_AssessShare4.M4d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinRashes_M4d, 
    (case CRS_AssessShare4.M4d when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinRashesDesc_M4d, 
    (case CRS_AssessShare4.M4e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinDesensitized_M4e, 
    (case CRS_AssessShare4.M4e when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinDesensitizedDesc_M4e, 
    (case CRS_AssessShare4.M4f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTears_M4f, 
    (case CRS_AssessShare4.M4f when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTearsDesc_M4f, 
    (case CRS_AssessShare4.M4g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinSurgical_M4g, 
    (case CRS_AssessShare4.M4g when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinSurgicalDesc_M4g, 
    (case when CRS_AssessShare4.M4All > 0 then Y1.DisplayCode end) as SkinNone_M4h, 
    (case when CRS_AssessShare4.M4All > 0 then Y1.UserDescription end) as SkinNoneDesc_M4h, 

    (case CRS_AssessShare4.M5a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTreat_Chair_M5a, 
    (case CRS_AssessShare4.M5a when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTreat_ChairDesc_M5a, 
    (case CRS_AssessShare4.M5b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTreat_Bed_M5b, 
    (case CRS_AssessShare4.M5b when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTreat_BedDesc_M5b, 
    (case CRS_AssessShare4.M5c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTreat_Turning_M5c, 
    (case CRS_AssessShare4.M5c when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTreat_TurningDesc_M5c, 
    (case CRS_AssessShare4.M5d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTreat_Nutrition_M5d, 
    (case CRS_AssessShare4.M5d when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTreat_NutritionDesc_M5d, 
    (case CRS_AssessShare4.M5e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTreat_Ulcer_M5e, 
    (case CRS_AssessShare4.M5e when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTreat_UlcerDesc_M5e, 
    (case CRS_AssessShare4.M5f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTreat_Surgical_M5f, 
    (case CRS_AssessShare4.M5f when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTreat_SurgicalDesc_M5f, 
    (case CRS_AssessShare4.M5g when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTreat_Dressing_M5g, 
    (case CRS_AssessShare4.M5g when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTreat_DressingDesc_M5g, 
    (case CRS_AssessShare4.M5h when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTreat_Ointment_M5h, 
    (case CRS_AssessShare4.M5h when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTreat_OintmentDesc_M5h, 
    (case CRS_AssessShare4.M5I when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SkinTreat_Other_M5i, 
    (case CRS_AssessShare4.M5I when 1 then Y.UserDescription when 2 then N.UserDescription end) as SkinTreat_OtherDesc_M5i, 
    (case when CRS_AssessShare4.M5All > 0 then Y1.DisplayCode end) as SkinTreat_None_M5j, 
    (case when CRS_AssessShare4.M5All > 0 then Y1.UserDescription end) as SkinTreat_NoneDesc_M5j, 

    (case CRS_AssessShare4.M6a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Foot_Problem_M6a, 
    (case CRS_AssessShare4.M6a when 1 then Y.UserDescription when 2 then N.UserDescription end) as Foot_ProblemDesc_M6a, 
    (case CRS_AssessShare4.M6b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Foot_Infection_M6b, 
    (case CRS_AssessShare4.M6b when 1 then Y.UserDescription when 2 then N.UserDescription end) as Foot_InfectionDesc_M6b, 
    (case CRS_AssessShare4.M6c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Foot_Lesion_M6c, 
    (case CRS_AssessShare4.M6c when 1 then Y.UserDescription when 2 then N.UserDescription end) as Foot_LesionDesc_M6c, 
    (case CRS_AssessShare4.M6d when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Foot_Nail_M6d, 
    (case CRS_AssessShare4.M6d when 1 then Y.UserDescription when 2 then N.UserDescription end) as Foot_NailDesc_M6d, 
    (case CRS_AssessShare4.M6e when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Foot_Preventative_M6e, 
    (case CRS_AssessShare4.M6e when 1 then Y.UserDescription when 2 then N.UserDescription end) as Foot_PreventativeDesc_M6e, 
    (case CRS_AssessShare4.M6f when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Foot_Dressing_M6f, 
    (case CRS_AssessShare4.M6f when 1 then Y.UserDescription when 2 then N.UserDescription end) as Foot_DressingDesc_M6f, 
    (case when CRS_AssessShare4.M6All > 0 then Y1.DisplayCode end) as Foot_None_M6g, 
    (case when CRS_AssessShare4.M6All > 0 then Y1.UserDescription end) as Foot_NoneDesc_M6g, 

    (case CRS_AssessShare4.N1a when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Awake_Morning_N1a, 
    (case CRS_AssessShare4.N1a when 1 then Y.UserDescription when 2 then N.UserDescription end) as Awake_MorningDesc_N1a, 
    (case CRS_AssessShare4.N1b when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Awake_Afternoon_N1b, 
    (case CRS_AssessShare4.N1b when 1 then Y.UserDescription when 2 then N.UserDescription end) as Awake_AfternoonDesc_N1b, 
    (case CRS_AssessShare4.N1c when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as Awake_Evening_N1c, 
    (case CRS_AssessShare4.N1c when 1 then Y.UserDescription when 2 then N.UserDescription end) as Awake_EveningDesc_N1c, 
    (case when CRS_AssessShare4.N1All > 0 then Y1.DisplayCode end) as Awake_None_N1d, 
    (case when CRS_AssessShare4.N1All > 0 then Y1.UserDescription end) as Awake_NoneDesc_N1d, 

    LU_N2.DisplayCode AS AverageTime_N2, LU_N2.UserDescription AS AverageTimeDesc_N2, 

    dbo.CRS_AssessShare4.O1 as NumberMedication_O1, 
    dbo.CRS_AssessShare4.O3 as Injection_O3, 
    dbo.CRS_AssessShare4.O4a as Days_Antipsychotic_O4a, 
    dbo.CRS_AssessShare4.O4b as Days_Antianxiety_O4b, 
    dbo.CRS_AssessShare4.O4c as Days_Antidepressant_O4c, 
    dbo.CRS_AssessShare4.O4d as Days_Hypnotic_O4d, 
    dbo.CRS_AssessShare4.O4e as Days_Diuretic_O4e, 
    dbo.CRS_AssessShare4.O4f as Days_Analgesic_O4f
FROM      
    dbo.CRS_AssessShare4 with (nolock) inner join 
    dbo.CRS_Demographic with (nolock) on CRS_Demographic.AbstractID = CRS_AssessShare4.AbstractID inner join
    dbo.LU_CodeFile LU_AA8 with (nolock) on CRS_Demographic.AA8 = LU_AA8.Code LEFT OUTER JOIN 
    dbo.LU_CodeFile LU_N2 with (nolock) on LU_N2.Code = dbo.CRS_AssessShare4.N2 LEFT OUTER JOIN
    dbo.LU_CodeFile LU_M2b with (nolock) on dbo.CRS_AssessShare4.M2b = LU_M2b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_M2a with (nolock) on dbo.CRS_AssessShare4.M2a = LU_M2a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_K6b with (nolock) on dbo.CRS_AssessShare4.K6b = LU_K6b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_K6a with (nolock) on dbo.CRS_AssessShare4.K6a = LU_K6a.Code LEFT OUTER JOIN
    --PR - 05185 change LU_K3b_Q to LU_K3b_F
    dbo.LU_CodeFile LU_K3b_F with (nolock) on LU_K3b_F.Code = dbo.CRS_AssessShare4.K3b LEFT OUTER JOIN
    dbo.LU_CodeFile LU_K3a_F with (nolock) on LU_K3a_F.Code = dbo.CRS_AssessShare4.K3a 

    cross join ( select top 1 DisplayCode, CIHIValue, UserDescription from LU_YesNoSystem where code = 1 ) Y
    cross join ( select top 1 DisplayCode, CIHIValue, UserDescription from LU_YesNoSystem where code = 2 ) N
    cross join ( select top 1 DisplayCode, CIHIValue, UserDescription from LU_CodeFile where LookUpID = 1 ) Y1
/*
    dbo.LU_CodeFile LU_K1All with (nolock) on dbo.CRS_AssessShare4.K1All = LU_K1All.Code
    dbo.LU_CodeFile LU_K5All with (nolock) on dbo.CRS_AssessShare4.K5All = LU_K5All.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_K4All with (nolock) on dbo.CRS_AssessShare4.K4All = LU_K4All.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_M4All with (nolock) on dbo.CRS_AssessShare4.M4All = LU_M4All.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_N1All with (nolock) on dbo.CRS_AssessShare4.N1All = LU_N1All.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_M6All with (nolock) on dbo.CRS_AssessShare4.M6All = LU_M6All.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_M5All with (nolock) on dbo.CRS_AssessShare4.M5All = LU_M5All.Code LEFT OUTER JOIN

    dbo.LU_YesNoSystem LU_N1c with (nolock) on dbo.CRS_AssessShare4.N1c = LU_N1c.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_N1b with (nolock) on dbo.CRS_AssessShare4.N1b = LU_N1b.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_N1a with (nolock) on dbo.CRS_AssessShare4.N1a = LU_N1a.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M6f with (nolock) on dbo.CRS_AssessShare4.M6f = LU_M6f.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M6e with (nolock) on dbo.CRS_AssessShare4.M6e = LU_M6e.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M6d with (nolock) on dbo.CRS_AssessShare4.M6d = LU_M6d.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M6c with (nolock) on dbo.CRS_AssessShare4.M6c = LU_M6c.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M6b with (nolock) on dbo.CRS_AssessShare4.M6b = LU_M6b.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M6a with (nolock) on dbo.CRS_AssessShare4.M6a = LU_M6a.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M5i with (nolock) on dbo.CRS_AssessShare4.M5I = LU_M5i.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M5h with (nolock) on dbo.CRS_AssessShare4.M5h = LU_M5h.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M5g with (nolock) on dbo.CRS_AssessShare4.M5g = LU_M5g.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M5f with (nolock) on dbo.CRS_AssessShare4.M5f = LU_M5f.Code LEFT OUTER JOIN 
    dbo.LU_YesNoSystem LU_M5e with (nolock) on LU_M5e.Code = dbo.CRS_AssessShare4.M5e LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M5d with (nolock) on dbo.CRS_AssessShare4.M5d = LU_M5d.Code LEFT OUTER JOIN 
    dbo.LU_YesNoSystem LU_M5c with (nolock) on LU_M5c.Code = dbo.CRS_AssessShare4.M5c LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M5b with (nolock) on dbo.CRS_AssessShare4.M5b = LU_M5b.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M5a with (nolock) on dbo.CRS_AssessShare4.M5a = LU_M5a.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M4g with (nolock) on dbo.CRS_AssessShare4.M4g = LU_M4g.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M4f with (nolock) on dbo.CRS_AssessShare4.M4f = LU_M4f.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M4e with (nolock) on dbo.CRS_AssessShare4.M4e = LU_M4e.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M4d with (nolock) on dbo.CRS_AssessShare4.M4d = LU_M4d.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M4c with (nolock) on dbo.CRS_AssessShare4.M4c = LU_M4c.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M4b with (nolock) on dbo.CRS_AssessShare4.M4b = LU_M4b.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_M4a with (nolock) on dbo.CRS_AssessShare4.M4a = LU_M4a.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_K5h with (nolock) on dbo.CRS_AssessShare4.K5h = LU_K5h.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_K5g with (nolock) on dbo.CRS_AssessShare4.K5g = LU_K5g.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_K5f with (nolock) on dbo.CRS_AssessShare4.K5f = LU_K5f.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_K5e with (nolock) on dbo.CRS_AssessShare4.K5e = LU_K5e.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_K5d with (nolock) on dbo.CRS_AssessShare4.K5d = LU_K5d.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_K5c with (nolock) on dbo.CRS_AssessShare4.K5c = LU_K5c.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_K5b with (nolock) on dbo.CRS_AssessShare4.K5b = LU_K5b.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_K5a with (nolock) on LU_K5a.Code = dbo.CRS_AssessShare4.K5a LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_K4c with (nolock) on dbo.CRS_AssessShare4.K4c = LU_K4c.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_K4b with (nolock) on dbo.CRS_AssessShare4.K4b = LU_K4b.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_K4a with (nolock) on dbo.CRS_AssessShare4.K4a = LU_K4a.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_K3b_F with (nolock) on LU_K3b_F.Code = dbo.CRS_AssessShare4.K3b LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_K3a_F with (nolock) on dbo.CRS_AssessShare4.K3a = LU_K3a_F.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_K1c with (nolock) on dbo.CRS_AssessShare4.K1c = LU_K1c.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_K1b with (nolock) on LU_K1b.Code = dbo.CRS_AssessShare4.K1b LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_K1a with (nolock) on dbo.CRS_AssessShare4.K1a = LU_K1a.Code LEFT OUTER JOIN
*/





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Shared_5_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'







CREATE VIEW [dbo].[MDS20_Shared_5_VR]
AS
SELECT 
    dbo.CRS_AssessShare5.AbstractID AS zzAbstractLink, 
    (case CRS_AssessShare5.P1aa when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialChemotherapy_P1aa, 
    (case CRS_AssessShare5.P1aa when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialChemotherapyDesc_P1aa, 
    (case CRS_AssessShare5.P1ab when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialDialysis_P1ab, 
    (case CRS_AssessShare5.P1ab when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialDialysisDesc_P1ab, 
    (case CRS_AssessShare5.P1ac when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialIV_P1ac, 
    (case CRS_AssessShare5.P1ac when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialIVDesc_P1ac, 
    (case CRS_AssessShare5.P1ad when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialIntake_P1ad, 
    (case CRS_AssessShare5.P1ad when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialIntakeDesc_P1ad, 
    (case CRS_AssessShare5.P1ae when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialMonitor_P1ae, 
    (case CRS_AssessShare5.P1ae when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialMonitorDesc_P1ae, 
    (case CRS_AssessShare5.P1af when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialOstomy_P1af, 
    (case CRS_AssessShare5.P1af when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialOstomyDesc_P1af, 
    (case CRS_AssessShare5.P1ag when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialOxygen_P1ag, 
    (case CRS_AssessShare5.P1ag when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialOxygenDesc_P1ag, 
    (case CRS_AssessShare5.P1ah when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialRadiation_P1ah, 
    (case CRS_AssessShare5.P1ah when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialRadiationDesc_P1ah, 
    (case CRS_AssessShare5.P1ai when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialSuction_P1ai, 
    (case CRS_AssessShare5.P1ai when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialSuctionDesc_P1ai, 
    (case CRS_AssessShare5.P1aj when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialTrash_P1aj, 
    (case CRS_AssessShare5.P1aj when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialTrashDesc_P1aj, 
    (case CRS_AssessShare5.P1ak when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialTransfusion_P1ak, 
    (case CRS_AssessShare5.P1ak when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialTransfusionDesc_P1ak, 
    (case CRS_AssessShare5.P1al when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialVentilator_P1al, 
    (case CRS_AssessShare5.P1al when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialVentilatorDesc_P1al, 
    (case CRS_AssessShare5.P1am when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialAlcohol_P1am, 
    (case CRS_AssessShare5.P1am when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialAlcoholDesc_P1am, 
    (case CRS_AssessShare5.P1an when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialAlzheimer_P1an, 
    (case CRS_AssessShare5.P1an when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialAlzheimerDesc_P1an, 
    (case CRS_AssessShare5.P1ao when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialHospice_P1ao, 
    (case CRS_AssessShare5.P1ao when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialHospiceDesc_P1ao, 
    (case CRS_AssessShare5.P1ap when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialPediatric_P1ap, 
    (case CRS_AssessShare5.P1ap when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialPediatricDesc_P1ap, 
    (case CRS_AssessShare5.P1aq when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialRespite_P1aq, 
    (case CRS_AssessShare5.P1aq when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialRespiteDesc_P1aq, 
    (case CRS_AssessShare5.P1ar when 1 then Y.DisplayCode when 2 then N.DisplayCode end) as SpecialTraining_P1ar, 
    (case CRS_AssessShare5.P1ar when 1 then Y.UserDescription when 2 then N.UserDescription end) as SpecialTrainingDesc_P1ar, 
    LU_P1All.DisplayCode AS SpecialNone_P1as, LU_P1All.UserDescription AS SpecialNoneDesc_P1as, 

    dbo.CRS_AssessShare5.P1baA as TherapySpeechDay_P1baA, 
    dbo.CRS_AssessShare5.P1baB as TherapySpeechMinute_P1baB, 
    dbo.CRS_AssessShare5.P1bbA as TherapyOccupationDay_P1bbA, 
    dbo.CRS_AssessShare5.P1bbB as TherapyOccupationMinute_P1bbB, 
    dbo.CRS_AssessShare5.P1bcA as TherapyPhysicalDay_P1bcA, 
    dbo.CRS_AssessShare5.P1bcB as TherapyPhysicalMinute_P1bcB, 
    dbo.CRS_AssessShare5.P1bdA as TherapyRespiratoryDay_P1bdA, 
    dbo.CRS_AssessShare5.P1bdB as TherapyRespiratoryMin_P1bdB, 
    dbo.CRS_AssessShare5.P1beA as TherapyPsychologicalDay_P1beA, 
    dbo.CRS_AssessShare5.P1beB as TherapyPsychologicalMin_P1beB, 
    dbo.CRS_AssessShare5.P1bfA as TherapyRecreationDay_P1bfA, 
    dbo.CRS_AssessShare5.P1bfB as TherapyRecreationMinute_P1bfB, 
    dbo.CRS_AssessShare5.P3a as RehabPassive_P3a, 
    dbo.CRS_AssessShare5.P3b as RehabActive_P3b, 
    dbo.CRS_AssessShare5.P3c as RehabSplint_P3c, 
    dbo.CRS_AssessShare5.P3d as RehabBed_P3d, 
    dbo.CRS_AssessShare5.P3e as RehabTransfer_P3e, 
    dbo.CRS_AssessShare5.P3f as RehabWalking_P3f, 
    dbo.CRS_AssessShare5.P3g as RehabDressing_P3g, 
    dbo.CRS_AssessShare5.P3h as RehabEating_P3h, 
    dbo.CRS_AssessShare5.P3I as RehabAmputation_P3i, 
    dbo.CRS_AssessShare5.P3j as RehabCommunication_P3j, 
    dbo.CRS_AssessShare5.P3k as RehabOther_P3k, 
    LU_P4a.DisplayCode AS DeviceFullBed_P4a, LU_P4a.UserDescription AS DeviceFullBedDesc_P4a, 
    LU_P4b.DisplayCode AS DeviceOther_P4b, LU_P4b.UserDescription AS DeviceOtherDesc_P4b, 
    LU_P4c.DisplayCode AS DeviceTrunk_P4c, LU_P4c.UserDescription AS DeviceTrunkDesc_P4c, 
    LU_P4d.DisplayCode AS DeviceLimb_P4d, LU_P4d.UserDescription AS DeviceLimbDesc_P4d, 
    LU_P4e.DisplayCode AS DeviceChair_P4e, LU_P4e.UserDescription AS DeviceChairDesc_P4e, 
    dbo.CRS_AssessShare5.P7 as PhysicianVisit_P7, 
    dbo.CRS_AssessShare5.P8 as PhysicianOrder_P8, 
    LU_Q2.DisplayCode AS OverallChange_Q2, LU_Q2.UserDescription AS OverallChangeDesc_Q2, 
    dbo.CRS_AssessShare5.R2b as CompleteDate_R2b
FROM     
    dbo.CRS_AssessShare5 with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Q2 with (nolock) on dbo.CRS_AssessShare5.Q2 = LU_Q2.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_P4e with (nolock) on dbo.CRS_AssessShare5.P4e = LU_P4e.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_P4d with (nolock) on dbo.CRS_AssessShare5.P4d = LU_P4d.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_P4c with (nolock) on dbo.CRS_AssessShare5.P4c = LU_P4c.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_P4b with (nolock) on dbo.CRS_AssessShare5.P4b = LU_P4b.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_P4a with (nolock) on dbo.CRS_AssessShare5.P4a = LU_P4a.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_P1All with (nolock) on dbo.CRS_AssessShare5.P1aAll = LU_P1All.Code
    cross join ( select top 1 DisplayCode, UserDescription from LU_YesNoSystem where code = 1 ) Y
    cross join ( select top 1 DisplayCode, UserDescription from LU_YesNoSystem where code = 2 ) N
/*
    dbo.LU_YesNoSystem LU_P1ar with (nolock) on dbo.CRS_AssessShare5.P1ar = LU_P1ar.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_P1aq with (nolock) on dbo.CRS_AssessShare5.P1aq = LU_P1aq.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_P1ap with (nolock) on dbo.CRS_AssessShare5.P1ap = LU_P1ap.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_P1ao with (nolock) on dbo.CRS_AssessShare5.P1ao = LU_P1ao.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_P1an with (nolock) on dbo.CRS_AssessShare5.P1an = LU_P1an.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_P1am with (nolock) on dbo.CRS_AssessShare5.P1am = LU_P1am.Code LEFT OUTER JOIN 
    dbo.LU_YesNoSystem LU_P1al with (nolock) on dbo.CRS_AssessShare5.P1al = LU_P1al.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_P1ak with (nolock) on dbo.CRS_AssessShare5.P1ak = LU_P1ak.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_P1aj with (nolock) on dbo.CRS_AssessShare5.P1aj = LU_P1aj.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_P1ai with (nolock) on dbo.CRS_AssessShare5.P1ai = LU_P1ai.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_P1ah with (nolock) on dbo.CRS_AssessShare5.P1ah = LU_P1ah.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_P1ag with (nolock) on dbo.CRS_AssessShare5.P1ag = LU_P1ag.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_P1af with (nolock) on dbo.CRS_AssessShare5.P1af = LU_P1af.Code LEFT OUTER JOIN 
    dbo.LU_YesNoSystem LU_P1ae with (nolock) on dbo.CRS_AssessShare5.P1ae = LU_P1ae.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_P1ad with (nolock) on dbo.CRS_AssessShare5.P1ad = LU_P1ad.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_P1ac with (nolock) on dbo.CRS_AssessShare5.P1ac = LU_P1ac.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_P1ab with (nolock) on dbo.CRS_AssessShare5.P1ab = LU_P1ab.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_P1aa with (nolock) on dbo.CRS_AssessShare5.P1aa = LU_P1aa.Code LEFT OUTER JOIN
*/















' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Signature_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'








CREATE  VIEW [dbo].[MDS20_Signature_VR]
AS
SELECT     dbo.CRS_Signature.AbstractID AS zzAbstractLink, dbo.CRS_Signature.ProviderOccurrence, dbo.CRS_Signature.R2b AS SignDate, 
                      dbo.LU_Provider.DisplayCode AS Signature, dbo.LU_Provider.UserDescription AS Signature_Desc, 
                      dbo.LU_ProviderService.DisplayCode AS ProviderServiceType, dbo.LU_ProviderService.UserDescription AS ProviderServiceType_Desc
FROM         dbo.LU_ProviderService with (nolock) RIGHT OUTER JOIN
                      dbo.CRS_Signature with (nolock) ON dbo.LU_ProviderService.Code = dbo.CRS_Signature.ProviderService LEFT OUTER JOIN
                      dbo.LU_Provider with (nolock) ON dbo.CRS_Signature.ProviderNumber = dbo.LU_Provider.Code










' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_UD_Abstracting_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[MDS20_UD_Abstracting_VR]
AS
SELECT
    dbo.CRS_UDAbstracting.UDDate1 AS Date1UD, dbo.CRS_UDAbstracting.UDDate2 AS Date2UD, 
    dbo.CRS_UDAbstracting.UDDate3 AS Date3UD, dbo.CRS_UDAbstracting.UDDate4 AS Date4UD, 
    dbo.CRS_UDAbstracting.UDDate5 AS Date5UD, 
    dbo.CRS_UDFieldsDate.UDDate6 AS Date6UD,
    dbo.CRS_UDFieldsDate.UDDate7 AS Date7UD,  dbo.CRS_UDFieldsDate.UDDate8 AS Date8UD,
    dbo.CRS_UDFieldsDate.UDDate9 AS Date9UD,  dbo.CRS_UDFieldsDate.UDDate10 AS Date10UD,
    dbo.CRS_UDFieldsDate.UDDate11 AS Date11UD,  dbo.CRS_UDFieldsDate.UDDate12 AS Date12UD,
    dbo.CRS_UDFieldsDate.UDDate13 AS Date13UD,  dbo.CRS_UDFieldsDate.UDDate14 AS Date14UD,
    dbo.CRS_UDFieldsDate.UDDate15 AS Date15UD,  dbo.CRS_UDFieldsDate.UDDate16 AS Date16UD,
    dbo.CRS_UDFieldsDate.UDDate17 AS Date17UD,  dbo.CRS_UDFieldsDate.UDDate18 AS Date18UD,
    dbo.CRS_UDFieldsDate.UDDate19 AS Date19UD,  dbo.CRS_UDFieldsDate.UDDate20 AS Date20UD,
    dbo.CRS_UDFieldsDate.UDDate21 AS Date21UD,  dbo.CRS_UDFieldsDate.UDDate22 AS Date22UD,
    dbo.CRS_UDFieldsDate.UDDate23 AS Date23UD,  dbo.CRS_UDFieldsDate.UDDate24 AS Date24UD,
    dbo.CRS_UDFieldsDate.UDDate25 AS Date25UD,  
    
    LU_CodeFile.DisplayCode AS Lookup1UD, dbo.LU_CodeFile.UserDescription AS Lookup1UDDesc, 
    LU_CodeFile_1.DisplayCode AS Lookup2UD, LU_CodeFile_1.UserDescription AS Lookup2UDDesc, 
    LU_CodeFile_2.DisplayCode AS Lookup3UD, LU_CodeFile_2.UserDescription AS Lookup3UDDesc, 
    LU_CodeFile_3.DisplayCode AS Lookup4UD, LU_CodeFile_3.UserDescription AS Lookup4UDDesc,
    LU_CodeFile_4.DisplayCode AS Lookup5UD, LU_CodeFile_4.UserDescription AS Lookup5UDDesc,
    LU_CodeFile_6.DisplayCode AS Lookup6UD, LU_CodeFile_6.UserDescription AS Lookup6UDDesc, 
    LU_CodeFile_7.DisplayCode AS Lookup7UD, LU_CodeFile_7.UserDescription AS Lookup7UDDesc, 
    LU_CodeFile_8.DisplayCode AS Lookup8UD, LU_CodeFile_8.UserDescription AS Lookup8UDDesc, 
    LU_CodeFile_9.DisplayCode AS Lookup9UD, LU_CodeFile_9.UserDescription AS Lookup9UDDesc, 
    LU_CodeFile_10.DisplayCode AS Lookup10UD, LU_CodeFile_10.UserDescription AS Lookup10UDDesc, 
    LU_CodeFile_11.DisplayCode AS Lookup11UD, LU_CodeFile_11.UserDescription AS Lookup11UDDesc, 
    LU_CodeFile_12.DisplayCode AS Lookup12UD, LU_CodeFile_12.UserDescription AS Lookup12UDDesc, 
    LU_CodeFile_13.DisplayCode AS Lookup13UD, LU_CodeFile_13.UserDescription AS Lookup13UDDesc, 
    LU_CodeFile_14.DisplayCode AS Lookup14UD, LU_CodeFile_14.UserDescription AS Lookup14UDDesc, 
    LU_CodeFile_15.DisplayCode AS Lookup15UD, LU_CodeFile_15.UserDescription AS Lookup15UDDesc, 
    LU_CodeFile_16.DisplayCode AS Lookup16UD, LU_CodeFile_16.UserDescription AS Lookup16UDDesc, 
    LU_CodeFile_17.DisplayCode AS Lookup17UD, LU_CodeFile_17.UserDescription AS Lookup17UDDesc, 
    LU_CodeFile_18.DisplayCode AS Lookup18UD, LU_CodeFile_18.UserDescription AS Lookup18UDDesc, 
    LU_CodeFile_19.DisplayCode AS Lookup19UD, LU_CodeFile_19.UserDescription AS Lookup19UDDesc, 
    LU_CodeFile_20.DisplayCode AS Lookup20UD, LU_CodeFile_20.UserDescription AS Lookup20UDDesc, 
    LU_CodeFile_21.DisplayCode AS Lookup21UD, LU_CodeFile_21.UserDescription AS Lookup21UDDesc, 
    LU_CodeFile_22.DisplayCode AS Lookup22UD, LU_CodeFile_22.UserDescription AS Lookup22UDDesc, 
    LU_CodeFile_23.DisplayCode AS Lookup23UD, LU_CodeFile_23.UserDescription AS Lookup23UDDesc, 
    LU_CodeFile_24.DisplayCode AS Lookup24UD, LU_CodeFile_24.UserDescription AS Lookup24UDDesc, 
    LU_CodeFile_25.DisplayCode AS Lookup25UD, LU_CodeFile_25.UserDescription AS Lookup25UDDesc, 
     
    dbo.CRS_UDAbstracting.UDInteger1 AS Numeric1UD, dbo.CRS_UDAbstracting.UDInteger2 AS Numeric2UD, 
    dbo.CRS_UDAbstracting.UDInteger3 AS Numeric3UD, dbo.CRS_UDAbstracting.UDInteger4 AS Numeric4UD, 
    dbo.CRS_UDAbstracting.UDInteger5 AS Numeric5UD, 
    dbo.CRS_UDFieldsInteger.UDInteger6 AS Numeric6UD, 
    dbo.CRS_UDFieldsInteger.UDInteger7 AS Numeric7UD, 
    dbo.CRS_UDFieldsInteger.UDInteger8 AS Numeric8UD, 
    dbo.CRS_UDFieldsInteger.UDInteger9 AS Numeric9UD, 
    dbo.CRS_UDFieldsInteger.UDInteger10 AS Numeric10UD, 
    dbo.CRS_UDFieldsInteger.UDInteger11 AS Numeric11UD, 
    dbo.CRS_UDFieldsInteger.UDInteger12 AS Numeric12UD, 
    dbo.CRS_UDFieldsInteger.UDInteger13 AS Numeric13UD, 
    dbo.CRS_UDFieldsInteger.UDInteger14 AS Numeric14UD, 
    dbo.CRS_UDFieldsInteger.UDInteger15 AS Numeric15UD, 
    dbo.CRS_UDFieldsInteger.UDInteger16 AS Numeric16UD, 
    dbo.CRS_UDFieldsInteger.UDInteger17 AS Numeric17UD, 
    dbo.CRS_UDFieldsInteger.UDInteger18 AS Numeric18UD, 
    dbo.CRS_UDFieldsInteger.UDInteger19 AS Numeric19UD, 
    dbo.CRS_UDFieldsInteger.UDInteger20 AS Numeric20UD, 
    dbo.CRS_UDFieldsInteger.UDInteger21 AS Numeric21UD, 
    dbo.CRS_UDFieldsInteger.UDInteger22 AS Numeric22UD, 
    dbo.CRS_UDFieldsInteger.UDInteger23 AS Numeric23UD, 
    dbo.CRS_UDFieldsInteger.UDInteger24 AS Numeric24UD, 
    dbo.CRS_UDFieldsInteger.UDInteger25 AS Numeric25UD, 

    dbo.CRS_UDAbstracting.UDText1 AS Notes1UD, dbo.CRS_UDAbstracting.UDText2 AS Notes2UD, 
    dbo.CRS_UDAbstracting.UDText3 AS Notes3UD, dbo.CRS_UDAbstracting.UDText4 AS Notes4UD, 
    dbo.CRS_UDAbstracting.UDText5 AS Notes5UD, 
    dbo.CRS_UDFieldsText.UDText6 AS Notes6UD,
    dbo.CRS_UDFieldsText.UDText7 AS Notes7UD,
    dbo.CRS_UDFieldsText.UDText8 AS Notes8UD,
    dbo.CRS_UDFieldsText.UDText9 AS Notes9UD,
    dbo.CRS_UDFieldsText.UDText10 AS Notes10UD,
    dbo.CRS_UDFieldsText.UDText11 AS Notes11UD,
    dbo.CRS_UDFieldsText.UDText12 AS Notes12UD,
    dbo.CRS_UDFieldsText.UDText13 AS Notes13UD,
    dbo.CRS_UDFieldsText.UDText14 AS Notes14UD,
    dbo.CRS_UDFieldsText.UDText15 AS Notes15UD,
    dbo.CRS_UDFieldsText.UDText16 AS Notes16UD,
    dbo.CRS_UDFieldsText.UDText17 AS Notes17UD,
    dbo.CRS_UDFieldsText.UDText18 AS Notes18UD,
    dbo.CRS_UDFieldsText.UDText19 AS Notes19UD,
    dbo.CRS_UDFieldsText.UDText20 AS Notes20UD,
    dbo.CRS_UDFieldsText.UDText21 AS Notes21UD,
    dbo.CRS_UDFieldsText.UDText22 AS Notes22UD,
    dbo.CRS_UDFieldsText.UDText23 AS Notes23UD,
    dbo.CRS_UDFieldsText.UDText24 AS Notes24UD,
    dbo.CRS_UDFieldsText.UDText25 AS Notes25UD,
    
    dbo.CRS_UDAbstracting.UDSmallText1 AS Text1UD, dbo.CRS_UDAbstracting.UDSmallText2 AS Text2UD, 
    dbo.CRS_UDAbstracting.UDSmallText3 AS Text3UD, dbo.CRS_UDAbstracting.UDSmallText4 AS Text4UD, 
    dbo.CRS_UDAbstracting.UDSmallText5 AS Text5UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText6 AS Text6UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText7 AS Text7UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText8 AS Text8UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText9 AS Text9UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText10 AS Text10UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText11 AS Text11UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText12 AS Text12UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText13 AS Text13UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText14 AS Text14UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText15 AS Text15UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText16 AS Text16UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText17 AS Text17UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText18 AS Text18UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText19 AS Text19UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText20 AS Text20UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText21 AS Text21UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText22 AS Text22UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText23 AS Text23UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText24 AS Text24UD, 
    dbo.CRS_UDFieldsSmallText.UDSmallText25 AS Text25UD, 
    
    dbo.CRS_UDAbstracting.UDTime1 AS Time1UD, dbo.CRS_UDAbstracting.UDTime2 AS Time2UD, 
    dbo.CRS_UDAbstracting.UDTime3 AS Time3UD, dbo.CRS_UDAbstracting.UDTime4 AS Time4UD, 
    dbo.CRS_UDAbstracting.UDTime5 AS Time5UD, 
    dbo.CRS_UDFieldsTime.UDTime6 AS Time6UD, 
    dbo.CRS_UDFieldsTime.UDTime7 AS Time7UD, 
    dbo.CRS_UDFieldsTime.UDTime8 AS Time8UD, 
    dbo.CRS_UDFieldsTime.UDTime9 AS Time9UD, 
    dbo.CRS_UDFieldsTime.UDTime10 AS Time10UD, 
    dbo.CRS_UDFieldsTime.UDTime11 AS Time11UD, 
    dbo.CRS_UDFieldsTime.UDTime12 AS Time12UD, 
    dbo.CRS_UDFieldsTime.UDTime13 AS Time13UD, 
    dbo.CRS_UDFieldsTime.UDTime14 AS Time14UD, 
    dbo.CRS_UDFieldsTime.UDTime15 AS Time15UD, 
    dbo.CRS_UDFieldsTime.UDTime16 AS Time16UD, 
    dbo.CRS_UDFieldsTime.UDTime17 AS Time17UD, 
    dbo.CRS_UDFieldsTime.UDTime18 AS Time18UD, 
    dbo.CRS_UDFieldsTime.UDTime19 AS Time19UD, 
    dbo.CRS_UDFieldsTime.UDTime20 AS Time20UD, 
    dbo.CRS_UDFieldsTime.UDTime21 AS Time21UD, 
    dbo.CRS_UDFieldsTime.UDTime22 AS Time22UD, 
    dbo.CRS_UDFieldsTime.UDTime23 AS Time23UD, 
    dbo.CRS_UDFieldsTime.UDTime24 AS Time24UD, 
    dbo.CRS_UDFieldsTime.UDTime25 AS Time25UD, 
    
    dbo.CRS_UDAbstracting.Abstractid AS zzAbstractLink
FROM         
    dbo.CRS_UDAbstracting with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_4 with (nolock) ON dbo.CRS_UDAbstracting.UDLookup5 = LU_CodeFile_4.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_3 with (nolock) ON dbo.CRS_UDAbstracting.UDLookup4 = LU_CodeFile_3.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_2 with (nolock) ON dbo.CRS_UDAbstracting.UDLookup3 = LU_CodeFile_2.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_1 with (nolock) ON dbo.CRS_UDAbstracting.UDLookup2 = LU_CodeFile_1.Code LEFT OUTER JOIN
    dbo.LU_CodeFile with (nolock) ON dbo.CRS_UDAbstracting.UDLookup1 = dbo.LU_CodeFile.Code LEFT OUTER JOIN
    dbo.CRS_UDFieldsDate with (nolock) ON dbo.CRS_UDAbstracting.AbstractiD = dbo.CRS_UDFieldsDate.AbstractID LEFT OUTER JOIN
    dbo.CRS_UDFieldsInteger with (nolock) ON dbo.CRS_UDAbstracting.AbstractiD = dbo.CRS_UDFieldsInteger.AbstractID LEFT OUTER JOIN
    dbo.CRS_UDFieldsLookUp with (nolock) ON dbo.CRS_UDAbstracting.AbstractiD = dbo.CRS_UDFieldsLookUp.AbstractID LEFT OUTER JOIN
    dbo.CRS_UDFieldsSmallText with (nolock) ON dbo.CRS_UDAbstracting.AbstractiD = dbo.CRS_UDFieldsSmallText.AbstractID LEFT OUTER JOIN
    dbo.CRS_UDFieldsText with (nolock) ON dbo.CRS_UDAbstracting.AbstractiD = dbo.CRS_UDFieldsText.AbstractID LEFT OUTER JOIN
    dbo.CRS_UDFieldsTime with (nolock) ON dbo.CRS_UDAbstracting.AbstractiD = dbo.CRS_UDFieldsTime.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_6 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup6 = LU_CodeFile_6.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_7 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup7 = LU_CodeFile_7.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_8 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup8 = LU_CodeFile_8.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_9 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup9 = LU_CodeFile_9.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_10 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup10 = LU_CodeFile_10.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_11 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup11 = LU_CodeFile_11.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_12 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup12 = LU_CodeFile_12.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_13 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup13 = LU_CodeFile_13.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_14 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup14 = LU_CodeFile_14.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_15 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup15 = LU_CodeFile_15.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_16 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup16 = LU_CodeFile_16.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_17 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup17 = LU_CodeFile_17.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_18 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup18 = LU_CodeFile_18.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_19 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup19 = LU_CodeFile_19.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_20 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup20 = LU_CodeFile_20.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_21 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup21 = LU_CodeFile_21.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_22 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup22 = LU_CodeFile_22.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_23 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup23 = LU_CodeFile_23.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_24 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup24 = LU_CodeFile_24.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_25 with (nolock) ON dbo.CRS_UDFieldsLookUp.UDLookup25 = LU_CodeFile_25.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[MDS20_UpdateHistory_VR]
AS
SELECT     dbo.U_Users.DisplayCode AS UpdateCoder, dbo.U_Users.UserDescription AS UpdateCoder_Desc, dbo.CRS_UpdateHistory.Updated, 
                      dbo.CRS_UpdateHistory.UpdateType, dbo.CRS_UpdateHistory.AbstractID AS zzAbstractLink
FROM         dbo.CRS_UpdateHistory with (nolock) LEFT OUTER JOIN
                      dbo.U_Users with (nolock) ON dbo.CRS_UpdateHistory.Coder = dbo.U_Users.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[MDS20_VR]
AS
SELECT     
    dbo.CRS_Demographic.AbstractID AS zzAbstractLink, dbo.CRS_Demographic.LinkID AS zzLinkBackgroundID, 
    LU_AA8.DisplayCode AS ReasonAssessment_AA8, LU_AA8.CIHIValue AS AA8_CIHI, LU_AA8.UserDescription AS ReasonAssessmentDesc_AA8, 
    dbo.CRS_Demographic.AA1 AS URI_AA1, dbo.CRS_Demographic.ChartNumber AS HealthRecordNumber_A6a, 
    FixedChartNumber,
    
    AboriginalIdentityFirstNations_AA4a = LU_AA4a.DisplayCode, AboriginalIdentityFirstNationsDesc_AA4a = LU_AA4a.UserDescription, 
    AboriginalIdentityMetiis_AA4b = LU_AA4b.DisplayCode, AboriginalIdentityMetiisDesc_AA4b = LU_AA4b.UserDescription, 
    AboriginalIdentityInuit_AA4c = LU_AA4c.DisplayCode, AboriginalIdentityInuitDesc_AA4c = LU_AA4c.UserDescription, 
    
    dbo.CRS_Demographic.RegisterNumber AS HealthRegisterNumber_A6b, dbo.CRS_Demographic.AdmitDate AS AdmissionDate_AB1, 
    dbo.CRS_Demographic.Z7 AS ChangedDate_Z7, dbo.CRS_Demographic.A3 AS AssessmentDate_A3, 
    dbo.CRS_Demographic.NextAssessmentDate,
    -- PR - 02377
    AttendingPhysician = LU_AttProvider.DisplayCode, AttendingPhysicianDesc = LU_AttProvider.UserDescription, 
    --PR - 06321
    CRS_Demographic.BatchYear,
    BatchPeriod = LU_BatchPeriod.DisplayCode, BatchPeriodDesc = LU_BatchPeriod.UserDescription, 

    BedType_AD2 = LU_AD2.DisplayCode, BedTypeDesc_AD2 = LU_AD2.UserDescription, 

	LU_BirthDateEstimated.DisplayCode AS BirthdateEstimated_AA3b, LU_BirthDateEstimated.UserDescription AS BirthDateEstimatedDesc_AA3b,
    
    CRS_Demographic.CIHIDateSent,

	LU_R3c.DisplayCode AS COVID19Status_R3c, LU_R3c.UserDescription AS COVID19StatusDesc_R3c,

    dbo.CRS_Demographic.DischargeDate AS DischargeDate_R4, 

    ElementEffectiveDate_Z12 = dbo.CRS_Demographic.Z12,
    -- PR - 02377
    dbo.CRS_Demographic.EncounterNumber, 

    dbo.CRS_Demographic.AB1b AS ReEntryDate_AB1b, 
    dbo.CRS_Demographic.MaidenName, dbo.CRS_Demographic.LastName, dbo.CRS_Demographic.MiddleName, dbo.CRS_Demographic.FirstName, 
    dbo.LU_NurseArea.DisplayCode AS RoomUnit, dbo.LU_NurseArea.UserDescription AS RoomUnitDesc, dbo.CRS_Demographic.RoomNumber, 
    LU_Gender.DisplayCode AS Gender_AA2, LU_Gender.UserDescription AS GenderDesc_AA2, dbo.CRS_Demographic.BirthDate AS Birthdate_AA3a, 
    dbo.CRS_Demographic.AA4a AS Treaty_band_AA4a, LU_MaritalStatus.DisplayCode AS MaritalStatus_A5, 
    LU_MaritalStatus.UserDescription AS MaritalStatusDesc_A5, 
    -- PR - 02377
    MISCode = LU_MISCode.DisplayCode, MISCodeDesc = LU_MISCode.UserDescription, 
    -- PR - 02377
    NursingArea = LU_AdmitNurse.DisplayCode, NursingAreaDesc = LU_AdmitNurse.UserDescription, 

    dbo.CRS_Demographic.HealthCareNumber AS HealthCareNumber_AA5a, 
    dbo.LU_HCNProvince.DisplayCode AS HCNProvince_AA5b, dbo.LU_HCNProvince.UserDescription AS HCNProvinceDesc_AA5b, 
    dbo.H_InstitutionProfile.DisplayCode AS FacilityNumber_AA6, dbo.H_InstitutionProfile.UserDescription AS FacilityNumberDesc_AA6, 
    LU_AB2a.DisplayCode AS CareLevelFrom_AB2a, LU_AB2a.UserDescription AS CareLevelFromDesc_AB2a, 
    LU_AB2c.DisplayCode AS CareLevelFrom_AB2c, LU_AB2c.UserDescription AS CareLevelFromDesc_AB2c, 
    LU_Inst_From.DisplayCode AS FacilityFrom_AB2b, LU_Inst_From.UserDescription AS FacilityFromDesc_AB2b, 
    LU_R3a.DisplayCode AS CareLevelTo_R3a, LU_R3a.UserDescription AS CareLevelToDesc_R3a, LU_Inst_To.DisplayCode AS FacilityTo_R3b, 
    LU_Inst_To.UserDescription AS FacilityToDesc_R3b, LU_Z1.DisplayCode AS RecordType_Z1, 
    LU_Z1.UserDescription AS RecordTypeDesc_Z1, LU_Z1.CIHIValue AS RecordTypeCIHI_Z1,
    dbo.CRS_Demographic.IsCurrent, 
    LU_CIHICorrect.DisplayCode AS IsCorrected, LU_CIHICorrect.UserDescription AS IsCorrectedDesc, 
    LU_IsCompleted.DisplayCode AS IsCompleted, LU_IsCompleted.UserDescription AS IsCompletedDesc, 
    LU_IsDeleted.DisplayCode AS IsDeleted, LU_IsDeleted.UserDescription AS IsDeletedDesc, 
    LU_IsSubmited.DisplayCode AS IsSubmited, LU_IsSubmited.UserDescription AS IsSubmitedDesc, 
    LU_IsValidated.DisplayCode AS IsValidated, LU_IsValidated.UserDescription AS IsValidatedDesc, 
    
    dbo.LU_Site.DisplayCode AS SiteNumber, dbo.LU_Site.UserDescription AS SiteNumberDesc, LU_Coder.DisplayCode AS CoderNumber, 
    LU_Coder.UserDescription AS CoderNumberDesc, dbo.CRS_Demographic.HCNVersion, 
    LU_Hospital.DisplayCode as Hospital, LU_Hospital.UserDescription as HospitalDesc, 
    dbo.CRS_Demographic.HospitalAccountRecord,
    dbo.CRS_Demographic.ZA6b AS NewHealthRegisterNumber_ZA6b, dbo.CRS_Demographic.ZAB1 AS NewAdmissionDate_ZAB1, 
    dbo.CRS_Demographic.ZR4 AS NewDischargeDate_ZR4, dbo.CRS_Demographic.InterfaceDate, dbo.CRS_Demographic.InterfaceTime, 
    U_InterfaceCoder.DisplayCode AS InterfaceCoder, U_InterfaceCoder.UserDescription AS InterfaceCoderDesc, dbo.CRS_Demographic.InputDate, 
    dbo.CRS_Demographic.InputTime, U_DataEntryCoder.DisplayCode AS DataEntryCoder, U_DataEntryCoder.UserDescription AS DataEntryCoderDesc, 
    dbo.CRS_Demographic.FinishDate, dbo.CRS_Demographic.FinishTime, 
    
    PrivatePayResidentFlag_AD1 = LU_AD1.DisplayCode, PrivatePayResidentFlagDesc_AD1 = LU_AD2.UserDescription, 
    ProgramType_AD4 = LU_AD4.DisplayCode, ProgramTypeDesc_AD4 = LU_AD4.UserDescription, 
    
    -- PR - 02377
    ReferringProvider = LU_RefProvider.DisplayCode, ReferringProviderDesc = LU_RefProvider.UserDescription, 
    -- PR - 02377
    SecondChartRegNumber as SecondChartRegisterNumber,

    LU_Secret.DisplayCode AS Secret, LU_Secret.UserDescription AS SecretDesc, 

    SubmissionType_Y3 = LU_Y3.DisplayCode, SubmissionTypeDesc_Y3 = LU_Y3.UserDescription, 

    SpecialProjectTriggerDate_Z13 = dbo.CRS_Demographic.Z13,

    dbo.CRS_Demographic.TSIDate, dbo.CRS_Demographic.TSITime, U_TSICoder.DisplayCode AS TSICoder, 

    U_TSICoder.UserDescription AS TSICoderDesc, 
	CRS_Demographic.UniversalEpisodeIdentifier
FROM         dbo.CRS_Demographic with (nolock) INNER JOIN
      dbo.LU_CodeFile LU_AA8 with (nolock) on dbo.CRS_Demographic.AA8 = LU_AA8.Code LEFT OUTER JOIN
      dbo.LU_CodeFile LU_Gender with (nolock) on dbo.CRS_Demographic.Gender = LU_Gender.Code LEFT OUTER JOIN
      dbo.H_InstitutionProfile with (nolock) on dbo.CRS_Demographic.InstitutionNumber = dbo.H_InstitutionProfile.Code LEFT OUTER JOIN
      dbo.LU_HCNProvince with (nolock) on dbo.LU_HCNProvince.Code = dbo.CRS_Demographic.HCNProvince LEFT OUTER JOIN
      dbo.U_Users U_TSICoder with (nolock) on dbo.CRS_Demographic.TSICoder = U_TSICoder.Code LEFT OUTER JOIN
      dbo.LU_YesBlank LU_Secret with (nolock) on dbo.CRS_Demographic.Secret = LU_Secret.Code LEFT OUTER JOIN
      dbo.U_Users U_DataEntryCoder with (nolock) on dbo.CRS_Demographic.DataEntryCoder = U_DataEntryCoder.Code LEFT OUTER JOIN
      dbo.U_Users U_InterfaceCoder with (nolock) on dbo.CRS_Demographic.InterfaceCoder = U_InterfaceCoder.Code LEFT OUTER JOIN
      dbo.U_Users LU_Coder with (nolock) on dbo.CRS_Demographic.CoderNumber = LU_Coder.Code LEFT OUTER JOIN
      dbo.LU_Site with (nolock) on dbo.CRS_Demographic.SiteNumber = dbo.LU_Site.Code LEFT OUTER JOIN
      dbo.LU_DeleteStatus LU_IsDeleted with (nolock) on dbo.CRS_Demographic.IsDeleted = LU_IsDeleted.Code LEFT OUTER JOIN
      dbo.LU_AbstractStatus LU_IsCompleted with (nolock) on dbo.CRS_Demographic.IsCompleted = LU_IsCompleted.Code LEFT OUTER JOIN
      dbo.LU_AbstractStatus LU_IsValidated with (nolock) on dbo.CRS_Demographic.IsValidated = LU_IsValidated.Code LEFT OUTER JOIN
      dbo.LU_YesNoSystem LU_IsSubmited with (nolock) on dbo.CRS_Demographic.IsSubmited = LU_IsSubmited.Code LEFT OUTER JOIN
      dbo.LU_CodeFile LU_Z1 with (nolock) on dbo.CRS_Demographic.Z1 = LU_Z1.Code LEFT OUTER JOIN
      dbo.LU_Institution_10 LU_Inst_To with (nolock) on dbo.CRS_Demographic.InstitutionTo = LU_Inst_To.Code LEFT OUTER JOIN
      dbo.LU_CodeFile LU_R3a with (nolock) on LU_R3a.Code = dbo.CRS_Demographic.R3a LEFT OUTER JOIN
      dbo.LU_Institution_10 LU_Inst_From with (nolock) on dbo.CRS_Demographic.InstitutionFrom = LU_Inst_From.Code LEFT OUTER JOIN
      dbo.LU_CodeFile LU_AB2c with (nolock) on dbo.CRS_Demographic.AB2c = LU_AB2c.Code LEFT OUTER JOIN
      dbo.LU_CodeFile LU_AB2a with (nolock) on dbo.CRS_Demographic.AB2a = LU_AB2a.Code LEFT OUTER JOIN
      dbo.LU_NurseArea with (nolock) on dbo.CRS_Demographic.AdmittingNurseArea = dbo.LU_NurseArea.Code LEFT OUTER JOIN
      dbo.LU_YesNoSystem LU_BirthDateEstimated with (nolock) on dbo.CRS_Demographic.BirthDateEstimated = LU_BirthDateEstimated.Code LEFT OUTER JOIN
      dbo.LU_CodeFile LU_MaritalStatus with (nolock) on dbo.CRS_Demographic.MaritalStatus = LU_MaritalStatus.Code LEFT OUTER JOIN
      dbo.H_HospitalProfile LU_Hospital with (nolock) on dbo.CRS_Demographic.HospitalID = LU_Hospital.Code LEFT OUTER JOIN
    -- PR - 02377
    LU_Provider LU_AttProvider with (nolock) on dbo.CRS_Demographic.AttendingPhysician = LU_AttProvider.Code LEFT JOIN
    LU_Provider LU_RefProvider with (nolock) on dbo.CRS_Demographic.RefPhysician = LU_RefProvider.Code LEFT JOIN
    LU_MisCode LU_MisCode with (nolock) on dbo.CRS_Demographic.MISCode = LU_MisCode.Code LEFT JOIN
    LU_NurseArea LU_AdmitNurse with (nolock) on dbo.CRS_Demographic.AdmittingNurseArea = LU_AdmitNurse.Code Left join
    
    dbo.CRS_UpdateRecord with (nolock) on dbo.CRS_Demographic.AbstractID = dbo.CRS_UpdateRecord.AbstractID left join
    LU_CodeFile LU_AD1 with (nolock) on dbo.CRS_UpdateRecord.AD1 = LU_AD1.Code left join
    LU_CodeFile LU_AD2 with (nolock) on dbo.CRS_UpdateRecord.AD2 = LU_AD2.Code LEFT OUTER JOIN
    LU_CodeFile LU_AD4 with (nolock) on dbo.CRS_UpdateRecord.AD4 = LU_AD4.Code LEFT OUTER JOIN

      dbo.LU_YesNoSystem LU_AA4a with (nolock) on dbo.CRS_Demographic.AA4a = LU_AA4a.Code LEFT OUTER JOIN
      dbo.LU_YesNoSystem LU_AA4b with (nolock) on dbo.CRS_Demographic.AA4b = LU_AA4b.Code LEFT OUTER JOIN
      dbo.LU_YesNoSystem LU_AA4c with (nolock) on dbo.CRS_Demographic.AA4c = LU_AA4c.Code left join
    LU_CodeFile LU_Y3 with (nolock) on dbo.CRS_Demographic.Y3 = LU_Y3.Code left join
      dbo.LU_CIHICorrect with (nolock) on dbo.CRS_Demographic.IsCorrected = LU_CIHICorrect.Code left join
      dbo.LU_CodeFile LU_BatchPeriod with (nolock) on dbo.CRS_Demographic.BatchPeriod = LU_BatchPeriod.Code left join
      dbo.LU_CodeFile LU_R3c with (nolock) on dbo.CRS_Demographic.R3c = LU_R3c.Code
--QA - 00032 disable the domain securite issue
---- PR - 07485
--where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or CRS_Demographic.HospitalID is null or CRS_Demographic.HospitalID = 0
----EN - 00666
--    or Is_Member(nullif(ReportGroup, '''')) = 1
----    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(CRS_Demographic.HospitalID, 0))






' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Merge_Deficiency_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[Merge_Deficiency_VR]
AS
SELECT     DeficiencyID AS zzDefID, ID AS zzMergeID
FROM         dbo.MRG_Deficiency with (nolock)




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Merge_Main_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[Merge_Main_VR]
AS
SELECT     dbo.MRG_Main.ChartNumberFrom, dbo.MRG_Main.ChartNumberTo, dbo.U_Users.DisplayCode AS Coder, 
                      dbo.U_Users.UserDescription AS CoderDescription, dbo.MRG_Main.OrgFirstName AS OriginalFirstName, 
                      dbo.MRG_Main.OrgLastName AS OriginalLastName, dbo.MRG_Main.UpdateType, dbo.MRG_Main.DateMerged, dbo.MRG_Main.ID AS zzMergeLink, 
                      dbo.MRG_Main.PatientIDFrom AS zzPatientIDFrom, dbo.MRG_Main.PatientIDTo AS zzPatientIDTo
FROM         dbo.MRG_Main with (nolock) LEFT OUTER JOIN
                      dbo.U_Users with (nolock) ON dbo.MRG_Main.CoderNumber = dbo.U_Users.Code




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Merge_Records_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[Merge_Records_VR]
AS
SELECT     ID AS zzMergeLink, UniversalID AS zzUniversalLink
FROM         dbo.MRG_Record with (nolock)




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Merge_ROI_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[Merge_ROI_VR]
AS
SELECT     ID AS zzMergeLink, ROIID AS zzROILink
FROM         dbo.MRG_ROI with (nolock)




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Merge_Volume_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[Merge_Volume_VR]
AS
SELECT     ID AS zzMergeLink, VolumeID AS zzVolumeLink
FROM         dbo.MRG_Volume with (nolock)




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Messages_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[Messages_VR]
AS
SELECT 
    CIHI_ElementID = U_UsersFields.CIHI_ID,
    FieldName = U_UsersFields.Header_User, 
    MessageLevel = CASE MG_Messages.MessageType 
						WHEN 1 THEN ''Warning'' 
						WHEN 2 THEN ''Error'' 
						WHEN 3 THEN ''Critical'' 
						WHEN 0 THEN ''Information'' 
						WHEN 5 THEN ''Question'' END, 
    MessageDescription = MG_Messages.MessageText, 
    Module = (case when dbo.MG_Messages.MessageKey like ''H%'' then ''Hospital Profile''
				   when dbo.MG_Messages.MessageKey like ''U%'' then ''User Profile''
				   when dbo.MG_Messages.MessageKey like ''A%'' then ''NACRS''
				   when dbo.MG_Messages.MessageKey like ''O%'' then ''OMHRS''
				   when dbo.MG_Messages.MessageKey like ''R%'' then ''NRS''
				   when dbo.MG_Messages.MessageKey like ''T%'' then ''DAD''
				   when dbo.MG_Messages.MessageKey like ''CP%'' then ''CPI''
			       when dbo.MG_Messages.MessageKey like ''V%'' then ''VisitHistory''
			       else ''''
			  end)
FROM dbo.MG_Messages with (nolock)
	left join dbo.MG_MessageFields with (nolock) on MG_Messages.MessageKey = MG_MessageFields.MessageKey
    left join dbo.U_UsersFields with (nolock) 
        on UserID = 1 and MG_MessageFields.FieldKey = ''FK'' + cast(U_UsersFields.FieldID as varchar(10)) and
			((dbo.MG_Messages.MessageKey like ''H%'' and U_UsersFields.AppID = 1000) or
			 (dbo.MG_Messages.MessageKey like ''U%'' and U_UsersFields.AppID = 1002) or
			 (dbo.MG_Messages.MessageKey like ''A%'' and U_UsersFields.AppID = 401) or
			 (dbo.MG_Messages.MessageKey like ''O%'' and U_UsersFields.AppID between 650 and 655) or
			 (dbo.MG_Messages.MessageKey like ''R%'' and U_UsersFields.AppID between 250 and 254) or
			 (dbo.MG_Messages.MessageKey like ''T%'' and U_UsersFields.AppID in (200, 201, 202)) or
			 (dbo.MG_Messages.MessageKey like ''CP%'' and U_UsersFields.AppID = 0) or
			 (dbo.MG_Messages.MessageKey like ''V%'' and U_UsersFields.AppID = 3))
Where dbo.MG_Messages.MessageKey not like ''N%''

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_AncillaryField_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[OMHRS_AncillaryField_VR]
AS
SELECT     dbo.LU_Ancillary1.DisplayCode AS AncillaryField1, dbo.LU_Ancillary1.UserDescription AS AncillaryField1Desc, 
                      dbo.LU_Ancillary2.DisplayCode AS AncillaryField2, dbo.LU_Ancillary2.UserDescription AS AncillaryField2Desc, 
                      dbo.LU_Ancillary3.DisplayCode AS AncillaryField3, dbo.LU_Ancillary3.UserDescription AS AncillaryField3Desc, 
                      dbo.LU_Ancillary4.DisplayCode AS AncillaryField4, dbo.LU_Ancillary4.UserDescription AS AncillaryField4Desc, 
                      dbo.LU_Ancillary5.DisplayCode AS AncillaryField5, dbo.LU_Ancillary5.UserDescription AS AncillaryField5Desc, 
                      dbo.LU_Ancillary6.DisplayCode AS AncillaryField6, dbo.LU_Ancillary6.UserDescription AS AncillaryField6Desc, 
                      dbo.LU_Ancillary7.DisplayCode AS AncillaryField7, dbo.LU_Ancillary7.UserDescription AS AncillaryField7Desc, 
                      dbo.LU_Ancillary8.DisplayCode AS AncillaryField8, dbo.LU_Ancillary8.UserDescription AS AncillaryField8Desc, 
                      dbo.LU_Ancillary9.DisplayCode AS AncillaryField9, dbo.LU_Ancillary9.UserDescription AS AncillaryField9Desc, 
                      dbo.LU_Ancillary10.DisplayCode AS AncillaryField10, dbo.LU_Ancillary10.UserDescription AS AncillaryField10Desc, 
                      dbo.LU_Ancillary11.DisplayCode AS AncillaryField11, dbo.LU_Ancillary11.UserDescription AS AncillaryField11Desc, 
                      dbo.LU_Ancillary12.DisplayCode AS AncillaryField12, dbo.LU_Ancillary12.UserDescription AS AncillaryField12Desc, 
                      dbo.LU_Ancillary13.DisplayCode AS AncillaryField13, dbo.LU_Ancillary13.UserDescription AS AncillaryField13Desc, 
                      dbo.LU_Ancillary14.DisplayCode AS AncillaryField14, dbo.LU_Ancillary14.UserDescription AS AncillaryField14Desc, 
                      dbo.LU_Ancillary15.DisplayCode AS AncillaryField15, dbo.LU_Ancillary15.UserDescription AS AncillaryField15Desc, 
                      dbo.LU_Ancillary16.DisplayCode AS AncillaryField16, dbo.LU_Ancillary16.UserDescription AS AncillaryField16Desc, 
                      dbo.LU_Ancillary17.DisplayCode AS AncillaryField17, dbo.LU_Ancillary17.UserDescription AS AncillaryField17Desc, 
                      dbo.OMHRS_Ancillary.AbstractID AS zzAbstractLink
FROM         
    dbo.OMHRS_Ancillary LEFT OUTER JOIN
    dbo.LU_Ancillary17 ON dbo.OMHRS_Ancillary.AncillaryField17 = dbo.LU_Ancillary17.Code LEFT OUTER JOIN
    dbo.LU_Ancillary16 ON dbo.OMHRS_Ancillary.AncillaryField16 = dbo.LU_Ancillary16.Code LEFT OUTER JOIN
    dbo.LU_Ancillary15 ON dbo.OMHRS_Ancillary.AncillaryField15 = dbo.LU_Ancillary15.Code LEFT OUTER JOIN
    dbo.LU_Ancillary14 ON dbo.OMHRS_Ancillary.AncillaryField14 = dbo.LU_Ancillary14.Code LEFT OUTER JOIN
    dbo.LU_Ancillary13 ON dbo.OMHRS_Ancillary.AncillaryField13 = dbo.LU_Ancillary13.Code LEFT OUTER JOIN
    dbo.LU_Ancillary12 ON dbo.LU_Ancillary12.Code = dbo.OMHRS_Ancillary.AncillaryField12 LEFT OUTER JOIN
    dbo.LU_Ancillary11 ON dbo.OMHRS_Ancillary.AncillaryField11 = dbo.LU_Ancillary11.Code LEFT OUTER JOIN
    dbo.LU_Ancillary10 ON dbo.OMHRS_Ancillary.AncillaryField10 = dbo.LU_Ancillary10.Code LEFT OUTER JOIN
    dbo.LU_Ancillary9 ON dbo.OMHRS_Ancillary.AncillaryField9 = dbo.LU_Ancillary9.Code LEFT OUTER JOIN
    dbo.LU_Ancillary8 ON dbo.OMHRS_Ancillary.AncillaryField8 = dbo.LU_Ancillary8.Code LEFT OUTER JOIN
    dbo.LU_Ancillary7 ON dbo.OMHRS_Ancillary.AncillaryField7 = dbo.LU_Ancillary7.Code LEFT OUTER JOIN
    dbo.LU_Ancillary6 ON dbo.OMHRS_Ancillary.AncillaryField6 = dbo.LU_Ancillary6.Code LEFT OUTER JOIN 
    dbo.LU_Ancillary5 ON dbo.LU_Ancillary5.Code = dbo.OMHRS_Ancillary.AncillaryField5 LEFT OUTER JOIN
    dbo.LU_Ancillary4 ON dbo.OMHRS_Ancillary.AncillaryField4 = dbo.LU_Ancillary4.Code LEFT OUTER JOIN 
    dbo.LU_Ancillary3 ON dbo.LU_Ancillary3.Code = dbo.OMHRS_Ancillary.AncillaryField3 LEFT OUTER JOIN
    dbo.LU_Ancillary2 ON dbo.OMHRS_Ancillary.AncillaryField2 = dbo.LU_Ancillary2.Code LEFT OUTER JOIN 
    dbo.LU_Ancillary1 ON dbo.LU_Ancillary1.Code = dbo.OMHRS_Ancillary.AncillaryField1




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_BasicOption_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'




CREATE VIEW [dbo].[OMHRS_BasicOption_VR]
AS
SELECT     dbo.LU_BasicOption1.DisplayCode AS BasicOption1, dbo.LU_BasicOption1.UserDescription AS BasicOption1Desc, 
                      dbo.LU_BasicOption2.DisplayCode AS BasicOption2, dbo.LU_BasicOption2.UserDescription AS BasicOption2Desc, 
                      dbo.LU_BasicOption3.DisplayCode AS BasicOption3, dbo.LU_BasicOption3.UserDescription AS BasicOption3Desc, 
                      dbo.LU_BasicOption4.DisplayCode AS BasicOption4, dbo.LU_BasicOption4.UserDescription AS BasicOption4Desc, 
                      dbo.LU_BasicOption5.DisplayCode AS BasicOption5, dbo.LU_BasicOption5.UserDescription AS BasicOption5Desc, 
                      dbo.LU_BasicOption6.DisplayCode AS BasicOption6, dbo.LU_BasicOption6.UserDescription AS BasicOption6Desc, 
                      dbo.LU_BasicOption7.DisplayCode AS BasicOption7, dbo.LU_BasicOption7.UserDescription AS BasicOption7Desc, 
                      dbo.LU_BasicOption8.DisplayCode AS BasicOption8, dbo.LU_BasicOption8.UserDescription AS BasicOption8Desc, 
                      dbo.LU_BasicOption9.DisplayCode AS BasicOption9, dbo.LU_BasicOption9.UserDescription AS BasicOption9Desc, 
                      dbo.LU_BasicOption10.DisplayCode AS BasicOption10, dbo.LU_BasicOption10.UserDescription AS BasicOption10Desc, 
                      dbo.LU_BasicOption11.DisplayCode AS BasicOption11, dbo.LU_BasicOption11.UserDescription AS BasicOption11Desc, 
                      dbo.LU_BasicOption12.DisplayCode AS BasicOption12, dbo.LU_BasicOption12.UserDescription AS BasicOption12Desc, 
                      dbo.LU_BasicOption13.DisplayCode AS BasicOption13, dbo.LU_BasicOption13.UserDescription AS BasicOption13Desc, 
                      dbo.LU_BasicOption14.DisplayCode AS BasicOption14, dbo.LU_BasicOption14.UserDescription AS BasicOption14Desc, 
                      dbo.LU_BasicOption15.DisplayCode AS BasicOption15, dbo.LU_BasicOption15.UserDescription AS BasicOption15Desc, 
                      dbo.LU_BasicOption16.DisplayCode AS BasicOption16, dbo.LU_BasicOption16.UserDescription AS BasicOption16Desc, 
                      dbo.LU_BasicOption17.DisplayCode AS BasicOption17, dbo.LU_BasicOption17.UserDescription AS BasicOption17Desc, 
                      dbo.LU_BasicOption18.DisplayCode AS BasicOption18, dbo.LU_BasicOption18.UserDescription AS BasicOption18Desc, 
                      dbo.LU_BasicOption19.DisplayCode AS BasicOption19, dbo.LU_BasicOption19.UserDescription AS BasicOption19Desc, 
                      dbo.OMHRS_BasicOption.AbstractID AS zzAbstractLink
FROM 
    dbo.OMHRS_BasicOption with (nolock) LEFT OUTER JOIN
    dbo.LU_BasicOption19 with (nolock) on dbo.LU_BasicOption19.Code = dbo.OMHRS_BasicOption.BasicOption19 LEFT OUTER JOIN
    dbo.LU_BasicOption18 with (nolock) on dbo.OMHRS_BasicOption.BasicOption18 = dbo.LU_BasicOption18.Code LEFT OUTER JOIN
    dbo.LU_BasicOption17 with (nolock) on dbo.OMHRS_BasicOption.BasicOption17 = dbo.LU_BasicOption17.Code LEFT OUTER JOIN
    dbo.LU_BasicOption16 with (nolock) on dbo.OMHRS_BasicOption.BasicOption16 = dbo.LU_BasicOption16.Code LEFT OUTER JOIN
    dbo.LU_BasicOption15 with (nolock) on dbo.OMHRS_BasicOption.BasicOption15 = dbo.LU_BasicOption15.Code LEFT OUTER JOIN
    dbo.LU_BasicOption14 with (nolock) on dbo.OMHRS_BasicOption.BasicOption14 = dbo.LU_BasicOption14.Code LEFT OUTER JOIN
    dbo.LU_BasicOption13 with (nolock) on dbo.OMHRS_BasicOption.BasicOption13 = dbo.LU_BasicOption13.Code LEFT OUTER JOIN
    dbo.LU_BasicOption12 with (nolock) on dbo.OMHRS_BasicOption.BasicOption12 = dbo.LU_BasicOption12.Code LEFT OUTER JOIN
    dbo.LU_BasicOption11 with (nolock) on dbo.OMHRS_BasicOption.BasicOption11 = dbo.LU_BasicOption11.Code LEFT OUTER JOIN
    dbo.LU_BasicOption10 with (nolock) on dbo.OMHRS_BasicOption.BasicOption10 = dbo.LU_BasicOption10.Code LEFT OUTER JOIN
    dbo.LU_BasicOption9 with (nolock) on dbo.OMHRS_BasicOption.BasicOption9 = dbo.LU_BasicOption9.Code LEFT OUTER JOIN
    dbo.LU_BasicOption8 with (nolock) on dbo.OMHRS_BasicOption.BasicOption8 = dbo.LU_BasicOption8.Code LEFT OUTER JOIN
    dbo.LU_BasicOption7 with (nolock) on dbo.OMHRS_BasicOption.BasicOption7 = dbo.LU_BasicOption7.Code LEFT OUTER JOIN
    dbo.LU_BasicOption6 with (nolock) on dbo.OMHRS_BasicOption.BasicOption6 = dbo.LU_BasicOption6.Code LEFT OUTER JOIN
    dbo.LU_BasicOption5 with (nolock) on dbo.OMHRS_BasicOption.BasicOption5 = dbo.LU_BasicOption5.Code LEFT OUTER JOIN
    dbo.LU_BasicOption4 with (nolock) on dbo.OMHRS_BasicOption.BasicOption4 = dbo.LU_BasicOption4.Code LEFT OUTER JOIN
    dbo.LU_BasicOption3 with (nolock) on dbo.OMHRS_BasicOption.BasicOption3 = dbo.LU_BasicOption3.Code LEFT OUTER JOIN
    dbo.LU_BasicOption2 with (nolock) on dbo.OMHRS_BasicOption.BasicOption2 = dbo.LU_BasicOption2.Code LEFT OUTER JOIN
    dbo.LU_BasicOption1 with (nolock) on dbo.LU_BasicOption1.Code = dbo.OMHRS_BasicOption.BasicOption1 





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_CIHIErrors_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE  view [dbo].[OMHRS_CIHIErrors_VR]
as
select 
    AssessmentDate as AssessmentReferenceDate, 
    CaseRecordNumber, 
    ChartNumber, 
    ElementCode, 
    ErrorFileName, 
    ErrorMessage,
    FiscalPeriod, 
    FiscalYear, 
    ImportDateTime, 
    FacilityNumber as InstitutionNumber, 
    RecordID, 
    RecordType, 
    RuleNumber, 
    RuleType, 
    SubmittedValue, 
    AbstractID as zzAbstractLink 
from dbo.OMHRS_CIHIErrors with (nolock)







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_DSM_5_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[OMHRS_DSM_5_Diagnosis_VR]
AS
SELECT     
	dbo.LU_DSM_5.DisplayCode AS DSM_5_Code_Q2, 
	dbo.LU_DSM_5.UserDescription AS DSM_5_Code_Q2Desc, 
    dbo.OMHRS_DSM_5.Q2Text AS DSM_5_Text, 
	dbo.OMHRS_DSM_5.Occurrence AS DSM_5_Occurrence, 
    dbo.OMHRS_SecAA.LinkID AS zzAbstractAdmitLinkID, 
	dbo.OMHRS_SecAA.AbstractID AS zzAbstractLink
FROM         
	dbo.OMHRS_SecAA with (nolock) 
    LEFT OUTER JOIN dbo.OMHRS_DSM_5 with (nolock) ON dbo.OMHRS_DSM_5.AbstractID = dbo.OMHRS_SecAA.AbstractID 
    LEFT OUTER JOIN dbo.LU_DSM_5 with (nolock) ON dbo.OMHRS_DSM_5.Q2 = dbo.LU_DSM_5.Code
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_DSM_Diag_AxisII_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE view [dbo].[OMHRS_DSM_Diag_AxisII_VR]
as
select
    AxisII_DSM_IVCode_Q2d = lu_Q2d.DisplayCode, AxisII_DSM_IVCodeDesc_Q2d = lu_Q2d.UserDescription, 
    AxisII_DSM_IVText = OMHRS_DSM_Diag_II.Q2dText, 
    dbo.OMHRS_DSM_Diag_II.Occurrence AS DSM_Diag_Occurrence, 
    dbo.OMHRS_SecAA.LinkID AS zzAbstractAdmitLinkID, dbo.OMHRS_SecAA.AbstractID AS zzAbstractLink
from  dbo.OMHRS_SecAA  with (nolock)  
    left join dbo.OMHRS_DSM_Diag_II with (nolock) ON OMHRS_SecAA.AbstractID = OMHRS_DSM_Diag_II.AbstractID 
    LEFT JOIN LU_DSM_IV lu_Q2d with (nolock) ON OMHRS_DSM_Diag_II.Q2d = lu_Q2d.Code 


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_DSM_Diag_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[OMHRS_DSM_Diag_VR]
AS
SELECT     dbo.LU_DSM_IV.DisplayCode AS Axis_I_DSM_IV_Code_Q2, dbo.LU_DSM_IV.UserDescription AS Axis_I_DSM_IV_Code_Q2Desc, 
                      dbo.OMHRS_DSM_Diag.Q2Text AS Axis_I_DSM_IV_Text, dbo.OMHRS_DSM_Diag.Occurrence AS DSM_Diag_Occurrence, 
                      dbo.OMHRS_SecAA.LinkID AS zzAbstractAdmitLinkID, dbo.OMHRS_SecAA.AbstractID AS zzAbstractLink
FROM         dbo.OMHRS_DSM_Diag with (nolock) RIGHT OUTER JOIN
                      dbo.OMHRS_SecAA with (nolock) ON dbo.OMHRS_DSM_Diag.AbstractID = dbo.OMHRS_SecAA.AbstractID LEFT OUTER JOIN
                      dbo.LU_DSM_IV with (nolock) ON dbo.OMHRS_DSM_Diag.Q2 = dbo.LU_DSM_IV.Code



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_IAR_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
create view [dbo].[OMHRS_IAR_VR]
as
select 
    LU_ConsentFlag.DisplayCode as IARAssessmentConsentFlag, LU_ConsentFlag.UserDescription as IARAssessmentConsentFlagDesc, 
    DateEffected as DateConsentCameIntoEffect,
    DateConsentGiven as DateInformationWasRequested,
    TimeConsentGiven as TimeInformationWasRequested,
    LU_WhoObtainedConsent.DisplayCode as WhoObtainedIARConsent, LU_WhoObtainedConsent.UserDescription as WhoObtainedIARConsentDesc, 
    DateInformationEnter as DateInformationWasEntered, 
    TimeInformationEnter as TimeInformationWasEntered, 

    LU_IsSubmitted.DisplayCode as IsIARCCIMSubmitted, LU_IsSubmitted.UserDescription as IsIARCCIMSubmittedDesc, 
    DateSubmittedToCCIM as DateSubmissionSentToCCIM, 
    LU_IsCorrected.DisplayCode as IsIARCCIMCorrected, LU_IsCorrected.UserDescription as IsIARCCIMCorrectedDesc, 
    DateCorrectedToCCIM as DateCorrectionSentToCCIM, 

    OMHRS_IAR_CCIM.AbstractID as zzAbstractLink
from dbo.OMHRS_IAR_CCIM with (nolock) left join
    LU_CodeFile LU_ConsentFlag with (nolock) on OMHRS_IAR_CCIM.IAR_ConsentFlag = LU_ConsentFlag.Code left join
    LU_CodeFile LU_IsSubmitted with (nolock) on OMHRS_IAR_CCIM.IAR_CCIM_IsSubmitted = LU_IsSubmitted.Code left join
    LU_CodeFile LU_IsCorrected with (nolock) on OMHRS_IAR_CCIM.IAR_CCIM_IsCorrected = LU_IsCorrected.Code left join
    LU_Provider LU_WhoObtainedConsent with (nolock) on OMHRS_IAR_CCIM.WhoObtainedConsent = LU_WhoObtainedConsent.Code 


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_InHospital_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE view [dbo].[OMHRS_InHospital_VR]
as
select a.AbstractID as zzAbstractAdmitLinkID
from dbo.OMHRS_SecAA a with (nolock)
    left join (select LinkID
    from dbo.OMHRS_SecAA with (nolock)
    where AppID = 654) d on a.AbstractID = d.LinkID
where A.appID = 650 and D.LinkID is null


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_Interventions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[OMHRS_Interventions_VR]
AS
SELECT     Lookup1.DisplayCode AS AnaestheticTechnique, Lookup1.UserDescription AS AnaestheticTechniqueDesc, Lookup2.DisplayCode AS AnaesthetistID, 
                      Lookup2.UserDescription AS AnaesthetistIDDesc, Lookup3.DisplayCode AS EUL, Lookup3.UserDescription AS EULDesc, 
                      Lookup4.DisplayCode AS Extra, Lookup4.UserDescription AS ExtraDesc, Lookup5.DisplayCode AS IntervAttribExtent, 
                      Lookup5.UserDescription AS IntervAttribExtentDesc, Lookup6.DisplayCode AS IntervAttribLocation, 
                      Lookup6.UserDescription AS IntervAttribLocationDesc, Lookup7.DisplayCode AS IntervAttribStatus, Lookup7.UserDescription AS IntervAttribStatusDesc, 
                      dbo.ICD_ProcFile10.DisplayCode AS IntervCode, dbo.ICD_ProcFile10.UserDescription AS IntervCodeDesc, 
                      dbo.ICD_ProcFile10.ShortDescription AS IntervCodeShortDesc, dbo.OMHRS_Intervention.IntervDate, dbo.OMHRS_Intervention.IntervDateIn, 
                      dbo.OMHRS_Intervention.IntervDateOut, dbo.ICD_ProcFile10.ICD9 AS IntervICD9Equivalent, dbo.ICD_ProcFile10.ICD9cm AS IntervICD9cmEquivalent, 
                      Lookup8.DisplayCode AS IntervLocation, Lookup8.UserDescription AS IntervLocationDesc, dbo.OMHRS_Intervention.IntervOccurrence, 
                      Lookup9.DisplayCode AS IntervProviderNumber, Lookup9.UserDescription AS IntervProviderNumberDesc, 
                      Lookup15.DisplayCode AS IntervProviderService, Lookup15.UserDescription AS IntervProviderServiceDesc, 
                      Lookup10.DisplayCode AS IntervProviderSpecialty, Lookup10.UserDescription AS IntervProviderSpecialtyDesc, dbo.OMHRS_Intervention.IntervTimeIn, 
                      dbo.OMHRS_Intervention.IntervTimeMinutes AS IntervTimeinMinutes, dbo.OMHRS_Intervention.IntervTimeOut, 
                      Lookup11.DisplayCode AS OOHIndicator, Lookup11.UserDescription AS OOHIndicatorDesc, Lookup12.DisplayCode AS OOHInstitutionNumber, 
                      Lookup12.UserDescription AS OOHInstitutionNumberDesc, dbo.LU_YesNoSystem.DisplayCode AS SurgicalCode, 
                      dbo.LU_YesNoSystem.UserDescription AS SurgicalCodeDesc, Lookup13.DisplayCode AS TissueCode, Lookup13.UserDescription AS TissueCodeDesc, 
                      Lookup13.DefaultDescription AS TissueCodeDesc_D, Lookup14.DisplayCode AS UnplannedReturntoOR, 
                      Lookup14.UserDescription AS UnplannedReturntoORDesc, dbo.OMHRS_SecAA.LinkID AS zzAbstractAdmitLinkID, 
                      dbo.OMHRS_SecAA.AbstractID AS zzAbstractLink
FROM         dbo.OMHRS_SecAA with (nolock) LEFT OUTER JOIN
    dbo.OMHRS_Intervention with (nolock) on dbo.OMHRS_SecAA.AbstractID = dbo.OMHRS_Intervention.AbstractID LEFT OUTER JOIN
    dbo.ICD_ProcFile10 with (nolock) on dbo.OMHRS_Intervention.IntervCode = dbo.ICD_ProcFile10.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem with (nolock) on dbo.LU_YesNoSystem.Code = dbo.ICD_ProcFile10.SurgicalCode LEFT OUTER JOIN
    dbo.LU_AnaestTechnique Lookup1 with (nolock) on dbo.OMHRS_Intervention.IntervAnaestTechnique = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_Provider Lookup2 with (nolock) on dbo.OMHRS_Intervention.IntervAnaestID = Lookup2.Code LEFT OUTER JOIN
    dbo.LU_IntervEUL Lookup3 with (nolock) on dbo.OMHRS_Intervention.IntervEUL = Lookup3.Code LEFT OUTER JOIN
    dbo.LU_IntervExtra Lookup4 with (nolock) on dbo.OMHRS_Intervention.IntervExtra = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_IntervAttExtent Lookup5 with (nolock) on dbo.OMHRS_Intervention.IntervAttribExtent = Lookup5.Code LEFT OUTER JOIN
    dbo.LU_IntervAttLocation Lookup6 with (nolock) on dbo.OMHRS_Intervention.IntervAttribLocation = Lookup6.Code LEFT OUTER JOIN
    dbo.LU_IntervAttStatus Lookup7 with (nolock) on dbo.OMHRS_Intervention.IntervAttribStatus = Lookup7.Code LEFT OUTER JOIN
    dbo.LU_IntervLocation_AI Lookup8 with (nolock) on dbo.OMHRS_Intervention.IntervLocation = Lookup8.Code LEFT OUTER JOIN
    dbo.LU_Provider Lookup9 with (nolock) on dbo.OMHRS_Intervention.IntervProviderNumber = Lookup9.Code LEFT OUTER JOIN
    dbo.LU_ProviderSpecialty Lookup10 with (nolock) on dbo.OMHRS_Intervention.IntervProviderService = Lookup10.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup11 with (nolock) on dbo.OMHRS_Intervention.IntervOOHIndicator = Lookup11.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 Lookup12 with (nolock) on dbo.OMHRS_Intervention.IntervOOHInstitution = Lookup12.Code LEFT OUTER JOIN
    dbo.LU_IntervTissue Lookup13 with (nolock) on dbo.OMHRS_Intervention.IntervTissueCode = Lookup13.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup14 with (nolock) on dbo.OMHRS_Intervention.IntervUnplanReturn = Lookup14.Code LEFT OUTER JOIN
    dbo.LU_ProviderService Lookup15 with (nolock) on dbo.OMHRS_Intervention.IntervProviderService = Lookup15.Code



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_MedicalDiagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[OMHRS_MedicalDiagnosis_VR]
AS
SELECT     dbo.ICD_DiagFile10.DisplayCode AS MedicalDiagnosis, dbo.ICD_DiagFile10.UserDescription AS MedicalDiagnosisDesc, 
                      dbo.OMHRS_Med_Diag.Occurrence AS MedicalDiagnosisOccurrence, dbo.OMHRS_SecAA.LinkID AS zzAbstractAdmitLinkID, 
                      dbo.OMHRS_SecAA.AbstractID AS zzAbstractLink
FROM         dbo.OMHRS_Med_Diag RIGHT OUTER JOIN
                      dbo.OMHRS_SecAA ON dbo.OMHRS_Med_Diag.AbstractID = dbo.OMHRS_SecAA.AbstractID LEFT OUTER JOIN
                      dbo.ICD_DiagFile10 ON dbo.OMHRS_Med_Diag.I11 = dbo.ICD_DiagFile10.Code


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_Medication_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[OMHRS_Medication_VR]
AS
SELECT     LU_R2f.DisplayCode AS Discontinued_R2f, LU_R2f.UserDescription AS DiscontinuedDesc_R2f, 
        dbo.OMHRS_Medication.X70 AS DrugIdentificationNumber_X70, dbo.OMHRS_Medication.X1 AS DrugRecordID_X1, 
        dbo.OMHRS_Medication.X70Text AS DrugText, 
        LU_R2c.DisplayCode AS FormRoute_R2c, LU_R2c.UserDescription AS FormRouteDesc_R2c, 
        LU_R2d.DisplayCode AS Frequency_R2d, LU_R2d.UserDescription AS FrequencyDesc_R2d, 
        dbo.OMHRS_Medication.R2b AS MedicationDose_R2b, 
        dbo.OMHRS_Medication.Occurrence AS MedicationOccurrence, 
        LU_R2e.DisplayCode AS PRN_R2e, LU_R2e.UserDescription AS PRNDesc_R2e, dbo.OMHRS_SecAA.LinkID AS zzAbstractAdmitLinkID, 
                      dbo.OMHRS_SecAA.AbstractID AS zzAbstractLink
FROM         
  dbo.OMHRS_SecAA with (nolock) LEFT OUTER JOIN
  dbo.OMHRS_Medication with (nolock) on dbo.OMHRS_SecAA.AbstractID = dbo.OMHRS_Medication.AbstractID LEFT OUTER JOIN
  dbo.LU_CodeFile LU_R2f with (nolock) on dbo.OMHRS_Medication.R2f = LU_R2f.Code LEFT OUTER JOIN
  dbo.LU_CodeFile LU_R2e with (nolock) on LU_R2e.Code = dbo.OMHRS_Medication.R2e LEFT OUTER JOIN
  dbo.LU_CodeFile LU_R2d with (nolock) on dbo.OMHRS_Medication.R2d = LU_R2d.Code LEFT OUTER JOIN
  dbo.LU_CodeFile LU_R2c with (nolock) on dbo.OMHRS_Medication.R2c = LU_R2c.Code


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_MHAPS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE view [dbo].[OMHRS_MHAPS_VR]
as
select
AcuteControlMedication        = (case when isnull(AcuteControlMedication, 0) = 0 then '''' else YN.DisplayCode end) ,
AcuteControlMedicationDesc    = (case when isnull(AcuteControlMedication, 0) = 0 then '''' else YN.UserDescription end) ,
AcuteControlMedicationNotes, -- 8528),
AcuteControlMedicationLogDate, AcuteControlMedicationLogTime, AcuteControlMedicationLogBy, 

AddictiveBehaviours           = (case when isnull(AddictiveBehaviours, 0) = 0 then '''' else YN.DisplayCode end) ,
AddictiveBehavioursDesc       = (case when isnull(AddictiveBehaviours, 0) = 0 then '''' else YN.UserDescription end) ,
AddictiveBehavioursNotes, --     8534),
AddictiveBehavioursLogDate, AddictiveBehavioursLogTime, AddictiveBehavioursLogBy, 

Adherence                     = (case when isnull(Adherence, 0) = 0 then '''' else YN.DisplayCode end) ,
AdherenceDesc                 = (case when isnull(Adherence, 0) = 0 then '''' else YN.UserDescription end) ,
AdherenceNotes, --               8522),
AdherenceLogLogDate, AdherenceLogLogTime, AdherenceLogLogBy, 

AbuseByOthers                 = (case when isnull(AbuseByOthers, 0) = 0 then '''' else YN.DisplayCode end) ,
AbuseByOthersDesc             = (case when isnull(AbuseByOthers, 0) = 0 then '''' else YN.UserDescription end) ,
AbuseByOthersNotes, --           8506),
AbuseByOthersLogDate, AbuseByOthersLogTime, AbuseByOthersLogBy, 

BehaviourDisturbance          = (case when isnull(BehaviourDisturbance, 0) = 0 then '''' else YN.DisplayCode end) ,
BehaviourDisturbanceDesc      = (case when isnull(BehaviourDisturbance, 0) = 0 then '''' else YN.UserDescription end) ,
BehaviourDisturbanceNotes, --    8554),
BehaviourDisturbanceLogDate, BehaviourDisturbanceLogTime, BehaviourDisturbanceLogBy, 

BladderBowelFunctioning       = (case when isnull(BladderBowelFunctioning, 0) = 0 then '''' else YN.DisplayCode end) ,
BladderBowelFunctioningDesc   = (case when isnull(BladderBowelFunctioning, 0) = 0 then '''' else YN.UserDescription end) ,
BladderBowelFunctioningNotes, -- 8548),
BladderBowelFunctioningLogDate, BladderBowelFunctioningLogTime, BladderBowelFunctioningLogBy, 

Cognition                     = (case when isnull(Cognition, 0) = 0 then '''' else YN.DisplayCode end) ,
CognitionDesc                 = (case when isnull(Cognition, 0) = 0 then '''' else YN.UserDescription end) ,
CognitionNotes, --               8550),
CognitionLogDate, CognitionLogtime, CognitionLogBy, 

CommunicationDisorder         = (case when isnull(CommunicationDisorder, 0) = 0 then '''' else YN.DisplayCode end) ,
CommunicationDisorderDesc     = (case when isnull(CommunicationDisorder, 0) = 0 then '''' else YN.UserDescription end) ,
CommunicationDisorderNotes, --   8552),
CommunicationDisorderLogDate, CommunicationDisorderLogTime, CommunicationDisorderLogBy, 

CriminalActivity              = (case when isnull(CriminalActivity, 0) = 0 then '''' else YN.DisplayCode end) ,
CriminalActivityDesc          = (case when isnull(CriminalActivity, 0) = 0 then '''' else YN.UserDescription end) ,
CriminalActivityNotes, --        8508),
CriminalActivityLogDate, CriminalActivityLogTime, CriminalActivityLogBy, 

DecisionalIntegrity           = (case when isnull(DecisionalIntegrity, 0) = 0 then '''' else YN.DisplayCode end) , 
DecisionalIntegrityDesc       = (case when isnull(DecisionalIntegrity, 0) = 0 then '''' else YN.UserDescription end) , 
DecisionalIntegrityNotes, --     8556),
DecisionalIntegrityLogDate, DecisionalIntegrityLogTime, DecisionalIntegrityLogBy, 

Dehydration                   = (case when isnull(Dehydration, 0) = 0 then '''' else YN.DisplayCode end) ,
DehydrationDesc               = (case when isnull(Dehydration, 0) = 0 then '''' else YN.UserDescription end) ,
DehydrationNotes, --             8538),
DehydrationLogDate, DehydrationLogTime, DehydrationLogBy, 

DischargeResources            = (case when isnull(DischargeResources, 0) = 0 then '''' else YN.DisplayCode end) ,
DischargeResourcesDesc        = (case when isnull(DischargeResources, 0) = 0 then '''' else YN.UserDescription end) ,
DischargeResourcesNotes, --      8532),
DischargeResourcesLogDate, DischargeResourcesLogTime, DischargeResourcesLogBy, 

EconomicStatus                = (case when isnull(EconomicStatus, 0) = 0 then '''' else YN.DisplayCode end) ,
EconomicStatusDesc            = (case when isnull(EconomicStatus, 0) = 0 then '''' else YN.UserDescription end) ,
EconomicStatusNotes, --          8520),
EconomicStatusLogDate, EconomicStatusLogTime, EconomicStatusLogBy, 

InterpersonalConflict         = (case when isnull(InterpersonalConflict, 0) = 0 then '''' else YN.DisplayCode end) ,
InterpersonalConflictDesc     = (case when isnull(InterpersonalConflict, 0) = 0 then '''' else YN.UserDescription end) ,
InterpersonalConflictNotes, --   8514),
InterpersonalConflictLogDate, InterpersonalConflictLogtime, InterpersonalConflictLogBy, 

Nutrition                     = (case when isnull(Nutrition, 0) = 0 then '''' else YN.DisplayCode end) ,
NutritionDesc                 = (case when isnull(Nutrition, 0) = 0 then '''' else YN.UserDescription end) ,
NutritionNotes, --               8536),
NutritionLogDate, NutritionLogTime, NutritionLogBy, 

OralHealth                    = (case when isnull(OralHealth, 0) = 0 then '''' else YN.DisplayCode end) ,
OralHealthDesc                = (case when isnull(OralHealth, 0) = 0 then '''' else YN.UserDescription end) ,
OralHealthNotes, --              8544),
OralHealthLogDate, OralHealthLogTime, OralHealthLogBy, 

Pain                          = (case when isnull(Pain, 0) = 0 then '''' else YN.DisplayCode end) ,
PainDesc                      = (case when isnull(Pain, 0) = 0 then '''' else YN.UserDescription end) ,
PainNotes, --                    8546),
PainLogDate, PainLogTime, PainLogBy, 

PhysicalRestraintSeclusion    = (case when isnull(PhysicalRestraintsSeclusions, 0) = 0 then '''' else YN.DisplayCode end) ,
PhysicalRestraintSeclusionDesc= (case when isnull(PhysicalRestraintsSeclusions, 0) = 0 then '''' else YN.UserDescription end) ,
PhysicalRestraintSeclusionNote, -- 8526),
PhysicalRestraintSeclusionDate, PhysicalRestraintSeclusionTime, PhysicalRestraintSeclusionBy, 

Polydipsia                    = (case when isnull(Polydipsia, 0) = 0 then '''' else YN.DisplayCode end) ,
PolydipsiaDesc                = (case when isnull(Polydipsia, 0) = 0 then '''' else YN.UserDescription end) ,
PolydipsiaNotes, --              8540),
PolydipsiaLogDate, PolydipsiaLogTime, PolydipsiaLogBy, 

PsychotropicDrugReview        = (case when isnull(PsychotropicDrugReview, 0) = 0 then '''' else YN.DisplayCode end) ,
PsychotropicDrugReviewDesc    = (case when isnull(PsychotropicDrugReview, 0) = 0 then '''' else YN.UserDescription end) ,
PsychotropicDrugReviewNotes, --  8524),
PsychotropicDrugReviewLogDate, PsychotropicDrugReviewLogTime, PsychotropicDrugReviewLogBy, 

RevolvingDoor                 = (case when isnull(RevolvingDoor, 0) = 0 then '''' else YN.DisplayCode end) ,
RevolvingDoorDesc             = (case when isnull(RevolvingDoor, 0) = 0 then '''' else YN.UserDescription end) ,
RevolvingDoorNotes, --           8530),
RevolvingDoorLogDate, RevolvingDoorLogTime, RevolvingDoorLogBy, 

SelfCare                      = (case when isnull(SelfCare, 0) = 0 then '''' else YN.DisplayCode end) ,
SelfCareDesc                  = (case when isnull(SelfCare, 0) = 0 then '''' else YN.UserDescription end) ,
SelfCareNotes, --                8510),
SelfCareLogDate, SelfCareLogTime, SelfCareLogBy, 

SelfHarm                      = (case when isnull(SelfHarm, 0) = 0 then '''' else YN.DisplayCode end) ,
SelfHarmDesc                  = (case when isnull(SelfHarm, 0) = 0 then '''' else YN.UserDescription end) ,
SelfHarmNotes, --                  8504),
SelfHarmLogDate, SelfHarmLogTime, SelfHarmLogBy, 

SkinFootConditions            = (case when isnull(SkinFootConditions, 0) = 0 then '''' else YN.DisplayCode end) ,
SkinFootConditionsDesc        = (case when isnull(SkinFootConditions, 0) = 0 then '''' else YN.UserDescription end) ,
SkinFootConditionsNotes, --        8542),
SkinFootConditionsLogDate, SkinFootConditionsLogTime, SkinFootConditionsLogBy, 

SocialFunction                = (case when isnull(SocialFunction, 0) = 0 then '''' else YN.DisplayCode end) ,
SocialFunctionDesc            = (case when isnull(SocialFunction, 0) = 0 then '''' else YN.UserDescription end) ,
SocialFunctionNotes, --            8512),
SocialFunctionLogDate, SocialFunctionLogTime, SocialFunctionLogBy, 

SupportSystems                = (case when isnull(SupportSystems, 0) = 0 then '''' else YN.DisplayCode end) ,
SupportSystemsDesc            = (case when isnull(SupportSystems, 0) = 0 then '''' else YN.UserDescription end) ,
SupportSystemsNotes, --            8518),
SupportSystemsLogDate, SupportSystemsLogTime, SupportSystemsLogBy, 

Violence                      = (case when isnull(Violence, 0) = 0 then '''' else YN.DisplayCode end),
ViolenceDesc                  = (case when isnull(Violence, 0) = 0 then '''' else YN.UserDescription end),
ViolenceNotes, --                  8502),
ViolenceLogDate, ViolenceLogTime, ViolenceLogBy, 

VocationalRehabilitation      = (case when isnull(VocationalRehabilitation, 0) = 0 then '''' else YN.DisplayCode end) ,
VocationalRehabilitationDesc  = (case when isnull(VocationalRehabilitation, 0) = 0 then '''' else YN.UserDescription end) ,
VocationalRehabilitationNotes, -- 8516),
VocationalRehabilitationDate, VocationalRehabilitationTime, VocationalRehabilitationBy, 
zzAbstractLink                = OMHRS_MHAPS.AbstractID, isnull(REC_Notes_OMHRS_Reporting.Occurrence, 1) as Occurrence
from dbo.OMHRS_MHAPS with (nolock)
    left join REC_Notes_OMHRS_Reporting with (nolock) on OMHRS_MHAPS.AbstractID = REC_Notes_OMHRS_Reporting.AbstractID, 
    (select * from lu_CodeFile with (nolock) where lookupid = 1) YN



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_Notes_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[OMHRS_Notes_VR]
AS
SELECT     
   RecordID AS zzAbstractLink,
   LogNote  as AbstractNotes,
   LogDate  as DateLogged,
   LogTime  as TimeLogged,
   U.DisplayCode as CreateBy,
   U.UserDescription as CreatorName        
from dbo.REC_Notes r with (nolock) left join U_users U with (nolock) on r.LogCoder=u.code
where AppID between 650 and 654
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_Projects_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[OMHRS_Projects_VR]
AS
SELECT     Lookup1.DisplayCode AS ProjectNumber, Lookup1.UserDescription AS ProjectNumberDesc, dbo.OMHRS_Project.ProjectOccurrence, 
                      Lookup2.DisplayCode AS Question1, Lookup2.UserDescription AS Question1Desc, Lookup3.DisplayCode AS Question10, 
                      Lookup3.UserDescription AS Question10Desc, Lookup4.DisplayCode AS Question11, Lookup4.UserDescription AS Question11Desc, 
                      Lookup5.DisplayCode AS Question12, Lookup5.UserDescription AS Question12Desc, Lookup6.DisplayCode AS Question13, 
                      Lookup6.UserDescription AS Question13Desc, dbo.OMHRS_Project.Question14, dbo.OMHRS_Project.Question15, dbo.OMHRS_Project.Question16, 
                      dbo.OMHRS_Project.Question17, Lookup7.DisplayCode AS Question2, Lookup7.UserDescription AS Question2Desc, 
                      Lookup8.DisplayCode AS Question3, Lookup8.UserDescription AS Question3Desc, Lookup9.DisplayCode AS Question4, 
                      Lookup9.UserDescription AS Question4Desc, Lookup10.DisplayCode AS Question5, Lookup10.UserDescription AS Question5Desc, 
                      Lookup11.DisplayCode AS Question6, Lookup11.UserDescription AS Question6Desc, Lookup12.DisplayCode AS Question7, 
                      Lookup12.UserDescription AS Question7Desc, Lookup13.DisplayCode AS Question8, Lookup13.UserDescription AS Question8Desc, 
                      Lookup14.DisplayCode AS Question9, Lookup14.UserDescription AS Question9Desc, dbo.OMHRS_SecAA.LinkID AS zzAbstractAdmitLinkID, 
                      dbo.OMHRS_SecAA.AbstractID AS zzAbstractLink
FROM         dbo.OMHRS_Project with (nolock) RIGHT OUTER JOIN
                      dbo.OMHRS_SecAA with (nolock) on dbo.OMHRS_Project.AbstractID = dbo.OMHRS_SecAA.AbstractID LEFT OUTER JOIN
                      dbo.LU_Project Lookup1 with (nolock) on dbo.OMHRS_Project.ProjectNumber = Lookup1.Code LEFT OUTER JOIN
                      dbo.LU_ProjectQuestion1 Lookup2 with (nolock) on dbo.OMHRS_Project.Question1 = Lookup2.Code LEFT OUTER JOIN
                      dbo.LU_ProjectQuestion10 Lookup3 with (nolock) on dbo.OMHRS_Project.Question10 = Lookup3.Code LEFT OUTER JOIN
                      dbo.LU_ProjectQuestion11 Lookup4 with (nolock) on dbo.OMHRS_Project.Question11 = Lookup4.Code LEFT OUTER JOIN
                      dbo.LU_ProjectQuestion12 Lookup5 with (nolock) on dbo.OMHRS_Project.Question12 = Lookup5.Code LEFT OUTER JOIN
                      dbo.LU_ProjectQuestion13 Lookup6 with (nolock) on dbo.OMHRS_Project.Question13 = Lookup6.Code LEFT OUTER JOIN
                      dbo.LU_ProjectQuestion2 Lookup7 with (nolock) on dbo.OMHRS_Project.Question2 = Lookup7.Code LEFT OUTER JOIN
                      dbo.LU_ProjectQuestion3 Lookup8 with (nolock) on dbo.OMHRS_Project.Question3 = Lookup8.Code LEFT OUTER JOIN
                      dbo.LU_ProjectQuestion4 Lookup9 with (nolock) on dbo.OMHRS_Project.Question4 = Lookup9.Code LEFT OUTER JOIN
                      dbo.LU_ProjectQuestion5 Lookup10 with (nolock) on dbo.OMHRS_Project.Question5 = Lookup10.Code LEFT OUTER JOIN
                      dbo.LU_ProjectQuestion6 Lookup11 with (nolock) on dbo.OMHRS_Project.Question6 = Lookup11.Code LEFT OUTER JOIN
                      dbo.LU_ProjectQuestion7 Lookup12 with (nolock) on dbo.OMHRS_Project.Question7 = Lookup12.Code LEFT OUTER JOIN
                      dbo.LU_ProjectQuestion8 Lookup13 with (nolock) on dbo.OMHRS_Project.Question8 = Lookup13.Code LEFT OUTER JOIN
                      dbo.LU_ProjectQuestion9 Lookup14 with (nolock) on dbo.OMHRS_Project.Question9 = Lookup14.Code



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_Providers_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[OMHRS_Providers_VR]
AS
SELECT     Lookup116.DisplayCode AS ProviderNumber, Lookup116.UserDescription AS ProviderNumberDesc, dbo.OMHRS_Provider.ProviderOccurrence, 
                      Lookup117.DisplayCode AS ProviderSpecialty, Lookup117.UserDescription AS ProviderSpecialtyDesc, Lookup118.DisplayCode AS ProviderType, 
                      Lookup118.UserDescription AS ProviderTypeDesc, dbo.OMHRS_SecAA.LinkID AS zzAbstractAdmitLinkID, 
                      dbo.OMHRS_SecAA.AbstractID AS zzAbstractLink
FROM         dbo.OMHRS_Provider with (nolock) RIGHT OUTER JOIN
                      dbo.OMHRS_SecAA with (nolock) ON dbo.OMHRS_Provider.AbstractID = dbo.OMHRS_SecAA.AbstractID LEFT OUTER JOIN
                      dbo.LU_Provider Lookup116 with (nolock) ON dbo.OMHRS_Provider.ProviderNumber = Lookup116.Code LEFT OUTER JOIN
                      dbo.LU_ProviderSpecialty Lookup117 with (nolock) ON dbo.OMHRS_Provider.ProviderSpecialty = Lookup117.Code LEFT OUTER JOIN
                      dbo.LU_ProviderType Lookup118 with (nolock) ON dbo.OMHRS_Provider.ProviderType = Lookup118.Code



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_QualityIndicators_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE view [dbo].[OMHRS_QualityIndicators_VR]
as
select 
	ReHospitalization = isnull(ReHospitalization / 
						nullif((select count(*) from OMHRS_SecAA inner join OMHRS_SecA 
									on  OMHRS_SecAA.AbstractID = OMHRS_SecA.AbstractID
								where OMHRS_SecAA.AppID in (650, 651) 
									and Datepart(Year, A1) =  FiscalYear + (case when FiscalQuarter = 4 then 1 else 0 end)
									and Datepart(Quarter, A1) = (case when FiscalQuarter = 4 then 1 else FiscalQuarter + 1 end)
									and OMHRS_SecAA.InstitutionNumber = z.InstitutionCode), 0), 0),
	ReHospitalization_Total_Number = ReHospitalization,
	ReHospitalization_Total_Denominator	= (select count(*) from OMHRS_SecAA inner join OMHRS_SecA 
									on  OMHRS_SecAA.AbstractID = OMHRS_SecA.AbstractID
								where OMHRS_SecAA.AppID in (650, 651) 
									and Datepart(Year, A1) =  FiscalYear + (case when FiscalQuarter = 4 then 1 else 0 end)
									and Datepart(Quarter, A1) = (case when FiscalQuarter = 4 then 1 else FiscalQuarter + 1 end)
									and OMHRS_SecAA.InstitutionNumber = z.InstitutionCode),
	ChemicalRestraintUse,
    ChemicalRestraintUse_Total_Number,
    ChemicalRestraintUse_Total_Denominator,

    FailureImproveManageMedication,
    FailureImproveManageMedication_Total_Number,
    FailureImproveManageMedication_Denominator,
    
    ImprovementManageMedication,
    ImprovementManageMedication_Total_Number,
    ImprovementManageMedication_Denominator,
    
    FailureImproveManageFinance,
    FailureImproveManageFinance_Total_Number,
    FailureImproveManageFinance_Denominator,
    
    ImprovementManageFinance,
    ImprovementManageFinance_Total_Number,
    ImprovementManageFinance_Denominator,

	PhysicalRestraintUse,
    PhysicalRestraintUse_Total_Number,
    PhysicalRestraintUse_Total_Denominator,

	PainWithoutPainManagement,	
    PainWithoutPainManagement_Total_Number,
    PainWithoutPainManagement_Total_Denominator,

	SignsSubstanceAbuseWithoutTherapy,
    SignsSubstanceAbuseWithoutTherapy_Total_Number,
    SignsSubstanceAbuseWithoutTherapy_Total_Denominator,

	SignsSelfInjury_NonSuicidal,
    SignsSelfInjury_NonSuicidal_Total_Number,
    SignsSelfInjury_NonSuicidal_Total_Denominator,

	InstitutionNumber,							
	InstitutionNumberDesc,
	FiscalYear,
	FiscalQuarter
from 								
(select
	ReHospitalization = cast(sum(case when LU_DD3.CIHIValue = ''4'' then 1 else 0 end) as float(53)), 
	
	ChemicalRestraintUse = cast(sum(case when OMHRS_SecK.K5 >= 1 then 1 else 0 end) as float(53)) / count(*),
	ChemicalRestraintUse_Total_Number = sum(case when OMHRS_SecK.K5 >= 1 then 1 else 0 end),
    ChemicalRestraintUse_Total_Denominator = count(*),
    --ED - 02813
    FailureImproveManageMedication = isnull(cast(sum(case when cast(LU_G2b.CIHIValue as int) >= cast(Prev_LU_G2b.CIHIValue as int) and cast(Prev_LU_G2b.CIHIValue as int) > 1 then 1
                                                    when cast(LU_G2b.CIHIValue as int) > 1 and cast(Prev_LU_G2b.CIHIValue as int) <= 1 then 1    
                                                    else 0 end) as float(53)) / nullif(sum(case when OMHRS_SecG.G2b > 0 and Prev_OMHRS_SecG.G2b > 0 then 1 else 0 end), 0), 0),
    FailureImproveManageMedication_Total_Number = sum(case when cast(LU_G2b.CIHIValue as int) >= cast(Prev_LU_G2b.CIHIValue as int) and cast(Prev_LU_G2b.CIHIValue as int) > 1 then 1
                                                    when cast(LU_G2b.CIHIValue as int) > 1 and cast(Prev_LU_G2b.CIHIValue as int) <= 1 then 1    
                                                    else 0 end),
    FailureImproveManageMedication_Denominator = sum(case when OMHRS_SecG.G2b > 0 and Prev_OMHRS_SecG.G2b > 0 then 1 else 0 end),
    
    ImprovementManageMedication = isnull(cast(sum(case when cast(LU_G2b.CIHIValue as int) < cast(Prev_LU_G2b.CIHIValue as int) then 1 else 0 end) as float(53)) / nullif(sum(case when LU_G2b.CIHIValue in (''0'',''1'',''2'',''3'',''4'',''5'',''6'') and Prev_LU_G2b.CIHIValue in (''2'',''3'',''4'',''5'',''6'') then 1 else 0 end), 0), 0),
    ImprovementManageMedication_Total_Number = sum(case when cast(LU_G2b.CIHIValue as int) < cast(Prev_LU_G2b.CIHIValue as int) then 1 else 0 end),
    ImprovementManageMedication_Denominator = sum(case when LU_G2b.CIHIValue in (''0'',''1'',''2'',''3'',''4'',''5'',''6'') and Prev_LU_G2b.CIHIValue in (''2'',''3'',''4'',''5'',''6'') then 1 else 0 end),

    FailureImproveManageFinance = isnull(cast(sum(case when cast(LU_G2d.CIHIValue as int) >= cast(Prev_LU_G2d.CIHIValue as int) and cast(Prev_LU_G2d.CIHIValue as int) > 1 then 1
                                                    when cast(LU_G2d.CIHIValue as int) > 1 and cast(Prev_LU_G2d.CIHIValue as int) <= 1 then 1    
                                                    else 0 end) as float(53)) / nullif(sum(case when OMHRS_SecG.G2d > 0 and Prev_OMHRS_SecG.G2d > 0 then 1 else 0 end), 0), 0),
    FailureImproveManageFinance_Total_Number = sum(case when cast(LU_G2d.CIHIValue as int) >= cast(Prev_LU_G2d.CIHIValue as int) and cast(Prev_LU_G2d.CIHIValue as int) > 1 then 1
                                                    when cast(LU_G2d.CIHIValue as int) > 1 and cast(Prev_LU_G2d.CIHIValue as int) <= 1 then 1    
                                                    else 0 end),
    FailureImproveManageFinance_Denominator = sum(case when OMHRS_SecG.G2d > 0 and Prev_OMHRS_SecG.G2d > 0 then 1 else 0 end),
    
    ImprovementManageFinance = isnull(cast(sum(case when cast(LU_G2d.CIHIValue as int) < cast(Prev_LU_G2d.CIHIValue as int) then 1 else 0 end) as float(53)) / nullif(sum(case when LU_G2d.CIHIValue in (''0'',''1'',''2'',''3'',''4'',''5'',''6'') and Prev_LU_G2d.CIHIValue in (''2'',''3'',''4'',''5'',''6'') then 1 else 0 end), 0), 0),
    ImprovementManageFinance_Total_Number = sum(case when cast(LU_G2d.CIHIValue as int) < cast(Prev_LU_G2d.CIHIValue as int) then 1 else 0 end),
    ImprovementManageFinance_Denominator = sum(case when LU_G2d.CIHIValue in (''0'',''1'',''2'',''3'',''4'',''5'',''6'') and Prev_LU_G2d.CIHIValue in (''2'',''3'',''4'',''5'',''6'') then 1 else 0 end),
    
    
    --End ED - 02813
    
	PhysicalRestraintUse = cast(sum(case when dbo.ToNumber(LU_M1a.CIHIValue) >= 1 or dbo.ToNumber(LU_M1b.CIHIValue) >= 1 
											or dbo.ToNumber(LU_M1c.CIHIValue) >= 1 
										 then 1 else 0 end) as float(53)) / count(*),
    PhysicalRestraintUse_Total_Number = sum(case when dbo.ToNumber(LU_M1a.CIHIValue) >= 1 
													or dbo.ToNumber(LU_M1b.CIHIValue) >= 1 
													or dbo.ToNumber(LU_M1c.CIHIValue) >= 1 
										 then 1 else 0 end),
    PhysicalRestraintUse_Total_Denominator = count(*),
    
	PainWithoutPainManagement = isnull(cast(sum(case when LU_I8b.CIHIValue in (''1'', ''2'', ''3'', ''4'') and
													LU_L4k.CIHIValue = ''0''
											  then 1 else 0 end) as float(53)) / 
								nullif(sum(case when LU_I8b.CIHIValue in (''1'', ''2'', ''3'', ''4'') and
													LU_L4k.CIHIValue is not null
											    then 1 else 0 end) , 0), 0),
    PainWithoutPainManagement_Total_Number = sum(case when LU_I8b.CIHIValue in (''1'', ''2'', ''3'', ''4'') and
													LU_L4k.CIHIValue = ''0''
							 then 1 else 0 end),
    PainWithoutPainManagement_Total_Denominator = sum(case when LU_I8b.CIHIValue in (''1'', ''2'', ''3'', ''4'') and
													LU_L4k.CIHIValue is not null
								  then 1 else 0 end),
    											    
	SignsSubstanceAbuseWithoutTherapy = isnull(cast(sum(case when isnull(dbo.ToNumber(LU_C4a.CIHIValue), 0) + 
																  isnull(dbo.ToNumber(LU_C4b.CIHIValue), 0) +
																  isnull(dbo.ToNumber(LU_C4c.CIHIValue), 0) +
																  isnull(dbo.ToNumber(LU_C4d.CIHIValue), 0) >= 2
																  and LU_L4e.CIHIValue = ''0''
															 then 1 else 0 end) as float(53)) /
										 nullif(sum(case when isnull(dbo.ToNumber(LU_C4a.CIHIValue), 0) + 
															  isnull(dbo.ToNumber(LU_C4b.CIHIValue), 0) +
															  isnull(dbo.ToNumber(LU_C4c.CIHIValue), 0) +
															  isnull(dbo.ToNumber(LU_C4d.CIHIValue), 0) >= 2
															  and LU_L4e.CIHIValue is not null
														 then 1 else 0 end), 0), 0),
														 
    SignsSubstanceAbuseWithoutTherapy_Total_Number = sum(case when isnull(dbo.ToNumber(LU_C4a.CIHIValue), 0) + 
																  isnull(dbo.ToNumber(LU_C4b.CIHIValue), 0) +
																  isnull(dbo.ToNumber(LU_C4c.CIHIValue), 0) +
																  isnull(dbo.ToNumber(LU_C4d.CIHIValue), 0) >= 2
																  and LU_L4e.CIHIValue = ''0''
															 then 1 else 0 end),
    SignsSubstanceAbuseWithoutTherapy_Total_Denominator = sum(case when isnull(dbo.ToNumber(LU_C4a.CIHIValue), 0) + 
															  isnull(dbo.ToNumber(LU_C4b.CIHIValue), 0) +
															  isnull(dbo.ToNumber(LU_C4c.CIHIValue), 0) +
															  isnull(dbo.ToNumber(LU_C4d.CIHIValue), 0) >= 2
															  and LU_L4e.CIHIValue is not null
														 then 1 else 0 end),
    
    SignsSelfInjury_NonSuicidal = cast(sum(case when LU_D1a.CIHIValue in (''4'', ''5'') and LU_D1b.CIHIValue in (''0'', ''8'') then 1 else 0 end) as float(53)) / count(*),
    SignsSelfInjury_NonSuicidal_Total_Number = sum(case when LU_D1a.CIHIValue in (''4'', ''5'') and LU_D1b.CIHIValue in (''0'', ''8'') then 1 else 0 end),
    SignsSelfInjury_NonSuicidal_Total_Denominator = count(*),
    	
	H_InstitutionProfile.DisplayCode as InstitutionNumber, H_InstitutionProfile.UserDescription as InstitutionNumberDesc,
	FiscalYear = selection.CalendarYear - (case when selection.CalendarQuarter = 1 then 1 else 0 end),
	FiscalQuarter = (case when selection.CalendarQuarter = 1 then 4 else selection.CalendarQuarter - 1 end),
	OMHRS_SecAA.InstitutionNumber as InstitutionCode

from	
	(select d.LinkID, aa.CalendarYear, aa.CalendarQuarter, OMHRS_SecA.A1, d.AdmitDate, max(d.AbstractID) as AbstractID 
	 from OMHRS_SecAA d with (nolock)
		inner join OMHRS_SecA with (nolock) on d.AbstractID = OMHRS_SecA.AbstractID
		inner join
		(select LinkID, Datepart(Year, A1) as CalendarYear, 
			Datepart(Quarter, A1) as CalendarQuarter, max(A1) as maxA1 
		from OMHRS_SecAA with (nolock)
			inner join OMHRS_SecA with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecA.AbstractID
			left  join OMHRS_RecInfo with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_RecInfo.AbstractID
		where A1 is not null and IsDeleted not in (1, 3) --and Z1 in (200374, 200375) 
		group by LinkID, Datepart(Year, A1), Datepart(Quarter, A1)
		) aa on d.LinkID = aa.LinkID and OMHRS_SecA.A1 = aa.maxA1
		--inner join OMHRS_SecAA a on d.LinkID = a.AbstractID
		left  join OMHRS_RecInfo with (nolock) on d.AbstractID = OMHRS_RecInfo.AbstractID
		where IsDeleted not in (1, 3) --and Z1 in (200374, 200375)
	 group by d.LinkID, aa.CalendarYear, aa.CalendarQuarter, OMHRS_SecA.A1, d.AdmitDate
	) selection

	inner join OMHRS_SecAA with (nolock) on selection.AbstractID = OMHRS_SecAA.AbstractID
	inner join H_InstitutionProfile with (nolock) on OMHRS_SecAA.InstitutionNumber = H_InstitutionProfile.Code

	left join OMHRS_SecC with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecC.AbstractID
	left join lu_codefile LU_C4a with (nolock) on OMHRS_SecC.C4a = LU_C4a.Code
	left join lu_codefile LU_C4b with (nolock) on OMHRS_SecC.C4b = LU_C4b.Code
	left join lu_codefile LU_C4c with (nolock) on OMHRS_SecC.C4c = LU_C4c.Code
	left join lu_codefile LU_C4d with (nolock) on OMHRS_SecC.C4d = LU_C4d.Code
	
	left join OMHRS_SecD with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecD.AbstractID
	left join lu_codefile LU_D1a with (nolock) on OMHRS_SecD.D1a = LU_D1a.Code
	left join lu_codefile LU_D1b with (nolock) on OMHRS_SecD.D1b = LU_D1b.Code

	left join OMHRS_SecG with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecG.AbstractID
	left join lu_codefile LU_G2b with (nolock) on OMHRS_SecG.G2b = LU_G2b.Code
	left join lu_codefile LU_G2d with (nolock) on OMHRS_SecG.G2d = LU_G2d.Code

	left join OMHRS_SecDD with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecDD.AbstractID
	left join lu_codefile LU_DD3 with (nolock) on OMHRS_SecDD.DD3 = LU_DD3.Code

	left join OMHRS_SecI with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecI.AbstractID
	left join lu_codefile LU_I8b with (nolock) on OMHRS_SecI.I8b = LU_I8b.Code
		
	left join OMHRS_SecK with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecK.AbstractID
	left join OMHRS_SecL with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecL.AbstractID
	left join lu_codefile LU_L4k with (nolock) on OMHRS_SecL.L4k = LU_L4k.Code
	left join lu_codefile LU_L4e with (nolock) on OMHRS_SecL.L4e = LU_L4e.Code
	
	left join OMHRS_SecM with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecM.AbstractID
	left join lu_codefile LU_M1a with (nolock) on OMHRS_SecM.M1a = LU_M1a.Code
	left join lu_codefile LU_M1b with (nolock) on OMHRS_SecM.M1b = LU_M1b.Code
	left join lu_codefile LU_M1c with (nolock) on OMHRS_SecM.M1c = LU_M1c.Code
	
    --ED - 02813 Previous Assessment
    left join
	(select d.LinkID, p.CurrentA1, OMHRS_SecA.A1, d.AdmitDate, max(d.AbstractID) as AbstractID 
	 from OMHRS_SecAA d with (nolock)
		inner join OMHRS_SecA with (nolock) on d.AbstractID = OMHRS_SecA.AbstractID
		inner join
	     (select d.LinkID, aa.maxA1 as CurrentA1, max(A1) as maxA1 
	     from OMHRS_SecAA d with (nolock)
		    inner join OMHRS_SecA with (nolock) on d.AbstractID = OMHRS_SecA.AbstractID
		    inner join
		    (select LinkID, Datepart(Year, A1) as CalendarYear, 
			    Datepart(Quarter, A1) as CalendarQuarter, max(A1) as maxA1 
		    from OMHRS_SecAA with (nolock)
			    inner join OMHRS_SecA with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecA.AbstractID
			    left  join OMHRS_RecInfo with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_RecInfo.AbstractID
		    where A1 is not null and IsDeleted not in (1, 3) --and Z1 in (200374, 200375) 
		    group by LinkID, Datepart(Year, A1), Datepart(Quarter, A1)
		    ) aa on d.LinkID = aa.LinkID and OMHRS_SecA.A1 < aa.maxA1
		    --inner join OMHRS_SecAA a on d.LinkID = a.AbstractID
		    left  join OMHRS_RecInfo with (nolock) on d.AbstractID = OMHRS_RecInfo.AbstractID
		    where IsDeleted not in (1, 3) --and Z1 in (200374, 200375)
	     group by d.LinkID, aa.maxA1
	     ) p on d.LinkID = p.LinkID and OMHRS_SecA.A1 = p.maxA1
		left  join OMHRS_RecInfo with (nolock) on d.AbstractID = OMHRS_RecInfo.AbstractID
		where IsDeleted not in (1, 3) --and Z1 in (200374, 200375)
	 group by d.LinkID, p.CurrentA1, OMHRS_SecA.A1, d.AdmitDate
	     
	) previous on selection.LinkID = previous.LinkID and selection.A1 = previous.CurrentA1 

	left join OMHRS_SecAA Prev_OMHRS_SecAA with (nolock) on previous.AbstractID = Prev_OMHRS_SecAA.AbstractID
	left join OMHRS_SecG Prev_OMHRS_SecG with (nolock) on Prev_OMHRS_SecAA.AbstractID = Prev_OMHRS_SecG.AbstractID
	left join lu_codefile Prev_LU_G2b with (nolock) on Prev_OMHRS_SecG.G2b = Prev_LU_G2b.Code
	left join lu_codefile Prev_LU_G2d with (nolock) on Prev_OMHRS_SecG.G2d = Prev_LU_G2d.Code
	
group by H_InstitutionProfile.DisplayCode, H_InstitutionProfile.UserDescription,
	selection.CalendarYear - (case when selection.CalendarQuarter = 1 then 1 else 0 end),
	(case when selection.CalendarQuarter = 1 then 4 else selection.CalendarQuarter - 1 end),
	OMHRS_SecAA.InstitutionNumber
 ) Z



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_RecordInformation_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[OMHRS_RecordInformation_VR]
AS
SELECT     LU_BatchPeriod.DisplayCode AS BatchPeriod, LU_BatchPeriod.UserDescription AS BatchPeriodDesc, dbo.OMHRS_RecInfo.BatchYear, 
                      dbo.OMHRS_RecInfo.CIHIDateSent, LU_DataEntryCoder.DisplayCode AS DataEntryCoder, 
                      LU_DataEntryCoder.UserDescription AS DataEntryCoderDesc, dbo.OMHRS_RecInfo.FinishDate, dbo.OMHRS_RecInfo.FinishTime, 
                      dbo.OMHRS_RecInfo.InputDate, dbo.OMHRS_RecInfo.InputTime, LU_InterfaceCoder.DisplayCode AS InterfaceCoder, 
                      LU_InterfaceCoder.UserDescription AS InterfaceCoderDesc, dbo.OMHRS_RecInfo.InterfaceDate, dbo.OMHRS_RecInfo.InterfaceTime, 
                      LU_IsCompleted.DisplayCode AS IsCompleted, LU_IsCompleted.UserDescription AS IsCompletedDesc, 
                      dbo.LU_CIHICorrect.DisplayCode AS IsCorrected, dbo.LU_CIHICorrect.UserDescription AS IsCorrectedDesc, LU_IsDeleted.DisplayCode AS IsDeleted, 
                      LU_IsDeleted.UserDescription AS IsDeletedDesc, LU_IsSubmited.DisplayCode AS IsSubmited, LU_IsSubmited.UserDescription AS IsSubmitedDesc, 
                      LU_IsValidated.DisplayCode AS IsValidated, LU_IsValidated.UserDescription AS IsValidatedDesc, LU_Secret.DisplayCode AS Secret, 
                      LU_Secret.UserDescription AS SecretDesc, dbo.OMHRS_RecInfo.AbstractID AS zzAbstractLink
FROM         dbo.LU_CodeFile LU_BatchPeriod with (nolock) RIGHT OUTER JOIN
                      dbo.OMHRS_RecInfo with (nolock) on LU_BatchPeriod.Code = dbo.OMHRS_RecInfo.BatchPeriod LEFT OUTER JOIN
                      dbo.LU_YesBlank LU_Secret with (nolock) on dbo.OMHRS_RecInfo.Secret = LU_Secret.Code LEFT OUTER JOIN
                      dbo.U_Users LU_DataEntryCoder with (nolock) on dbo.OMHRS_RecInfo.DataEntryCoder = LU_DataEntryCoder.Code LEFT OUTER JOIN
                      dbo.U_Users LU_InterfaceCoder with (nolock) on dbo.OMHRS_RecInfo.InterfaceCoder = LU_InterfaceCoder.Code LEFT OUTER JOIN
                      dbo.LU_DeleteStatus LU_IsDeleted with (nolock) on dbo.OMHRS_RecInfo.IsDeleted = LU_IsDeleted.Code LEFT OUTER JOIN
                      dbo.LU_CIHICorrect with (nolock) on dbo.OMHRS_RecInfo.IsCorrected = dbo.LU_CIHICorrect.Code LEFT OUTER JOIN
                      dbo.LU_AbstractStatus LU_IsCompleted with (nolock) on dbo.OMHRS_RecInfo.IsCompleted = LU_IsCompleted.Code LEFT OUTER JOIN
                      dbo.LU_YesNoSystem LU_IsSubmited with (nolock) on dbo.OMHRS_RecInfo.IsSubmited = LU_IsSubmited.Code LEFT OUTER JOIN
                      dbo.LU_AbstractStatus LU_IsValidated with (nolock) on dbo.OMHRS_RecInfo.IsValidated = LU_IsValidated.Code
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_ReferenceDate_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'create view [dbo].[OMHRS_ReferenceDate_VR]
as
select 
    zzAbstractAdmitLinkID = LinkID,
    AdmitDate,
    DischargeDate = max(X80),
    MinumeReferenceDate = min(A1),
    MaximumReferenceDate = max(A1),
    TotalAssessment = count(*)
from OMHRS_SecAA aa
    inner join OMHRS_SecA a on aa.AbstractID = a.AbstractID
    left  join OMHRS_SecS s on aa.AbstractID = s.AbstractID
group by aa.LinkID, AdmitDate
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_ResDischarge_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[OMHRS_ResDischarge_VR]
AS
SELECT 
    Lookup1.DisplayCode AS CrisisSupport_P1c, Lookup1.UserDescription AS CrisisSupportDesc_P1c, 
    Lookup2.DisplayCode AS DischargedtoFacility_X140, Lookup2.UserDescription AS DischargedtoFacilityDesc_X140, 

    DischargedSupportHomeCare_X141 = Lookup_X141.DisplayCode,
    DischargedSupportHomeCareDesc_X141 = Lookup_X141.UserDescription, 

    Lookup3.DisplayCode AS HelpwithChildcare_P1a, Lookup3.UserDescription AS HelpwithChildcareDesc_P1a, 
    Lookup4.DisplayCode AS LivingArrangement_P5, Lookup4.UserDescription AS LivingArrangementDesc_P5, 
    Lookup5.DisplayCode AS OverallChangeinCareNeeds_P4, Lookup5.UserDescription AS OverallChangeinCareNDesc_P4, 
    Lookup6.DisplayCode AS ProjectedtimeToPlanDisch_P3, Lookup6.UserDescription AS ProjectedtimeToPlanDischDesc_P3, 
    Lookup7.DisplayCode AS PtExprsPrefReturntoCom_P2a, Lookup7.UserDescription AS PtExprsPrefReturntoComDesc_P2a, 
    Lookup8.DisplayCode AS PthasSupportforDisch_P2b, Lookup8.UserDescription AS PthasSupportforDischDesc_P2b, 
    Lookup9.DisplayCode AS SectionPSignoffCarePr_SignCoder, Lookup9.UserDescription AS SectionPSignoffCPrDesc_SignCoder, 
    dbo.OMHRS_SecP.SignDate AS SectionPSignOffDate, Lookup10.DisplayCode AS SectionPSignedOff_SignOff, 
    Lookup10.UserDescription AS SectionPSignedOffDesc_SignOff, Lookup11.DisplayCode AS SupervisionforPersSafety_P1b, 
    Lookup11.UserDescription AS SupervisionforPersSafetyDesc_P1b, Lookup12.DisplayCode AS SupportwithADLIADLs_P1d, 
    Lookup12.UserDescription AS SupportwithADLIADLsDesc_P1d, 
    
    dbo.OMHRS_SecP.AbstractID AS zzAbstractLink
FROM  dbo.OMHRS_SecP with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile AS Lookup1 with (nolock) on dbo.OMHRS_SecP.P1c = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 AS Lookup2 with (nolock) on dbo.OMHRS_SecP.X140 = Lookup2.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS Lookup3 with (nolock) on dbo.OMHRS_SecP.P1a = Lookup3.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS Lookup4 with (nolock) on dbo.OMHRS_SecP.P5 = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS Lookup5 with (nolock) on dbo.OMHRS_SecP.P4 = Lookup5.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS Lookup6 with (nolock) on dbo.OMHRS_SecP.P3 = Lookup6.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS Lookup7 with (nolock) on dbo.OMHRS_SecP.P2a = Lookup7.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS Lookup8 with (nolock) on dbo.OMHRS_SecP.P2b = Lookup8.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS Lookup11 with (nolock) on dbo.OMHRS_SecP.P1b = Lookup11.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS Lookup12 with (nolock) on dbo.OMHRS_SecP.P1d = Lookup12.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS Lookup_X141 with (nolock) on dbo.OMHRS_SecP.X141 = Lookup_X141.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS Lookup10 with (nolock) on dbo.OMHRS_SecP.SignOff = Lookup10.Code LEFT OUTER JOIN
    dbo.U_Users AS Lookup9 with (nolock) on dbo.OMHRS_SecP.SignCoder = Lookup9.Code





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_RoleRelations_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[OMHRS_RoleRelations_VR]
AS
SELECT     Lookup1.DisplayCode AS ContactwithSocialRFamily_O6c, Lookup1.UserDescription AS ContactwithSocialRFamilyDesc_O6c, 
                      Lookup2.DisplayCode AS EmploymentStatus_O3, Lookup2.UserDescription AS EmploymentStatusDesc_O3, 
                      Lookup3.DisplayCode AS FamilyHostileTowardPt_O2e, Lookup3.UserDescription AS FamilyHostileTowardPtDesc_O2e, 
                      Lookup4.DisplayCode AS FamilyOverwbyPtIllness_O2b, Lookup4.UserDescription AS FamilyOverwbyPtIllnessDesc_O2b, 
                      Lookup5.DisplayCode AS FamilyReqUAmtofStaffT_O2g, Lookup5.UserDescription AS FamilyReqUAmtofStaffTDesc_O2g, 
                      Lookup6.DisplayCode AS FamilyRoles_O1, Lookup6.UserDescription AS FamilyRolesDesc_O1, 
                      Lookup7.DisplayCode AS IncreaseinLateAbsenteeism_O4a, Lookup7.UserDescription AS IncreaseinLateAbsDesc_O4a, 
                      Lookup8.DisplayCode AS IntenttoQuitWorkSchool_O4c, Lookup8.UserDescription AS IntenttoQuitWorkSchoolDesc_O4c, 
                      Lookup9.DisplayCode AS NoConfidant_O2a, Lookup9.UserDescription AS NoConfidantDesc_O2a, 
                      Lookup10.DisplayCode AS ParticipationinSocialActivities_O6a, Lookup10.UserDescription AS ParticipationinSocialActDesc_O6a, 
                      Lookup11.DisplayCode AS PersistentUnemployment_O4d, Lookup11.UserDescription AS PersistentUnemploymentDesc_O4d, 
                      Lookup12.DisplayCode AS PoorProdDisatSchoolWork_O4b, Lookup12.UserDescription AS PoorProdDisatSchoolWorkDesc_O4b, 
                      Lookup13.DisplayCode AS PtHostileTowardFamily_O2c, Lookup13.UserDescription AS PtHostileTowardFamilyDesc_O2c, 
                      Lookup14.DisplayCode AS PtHostileTowardPtorStaff_O2d, Lookup14.UserDescription AS PtHostileTowardPtorStaffDesc_O2d, 
                      Lookup15.DisplayCode AS SectionOSCareProvider_SignCoder, Lookup15.UserDescription AS SectionOSCareProvDesc_SignCoder, 
                      dbo.OMHRS_SecO.SignDate AS SectionOSignOffDate, Lookup16.DisplayCode AS SectionOSignedOff_SignOff, 
                      Lookup16.UserDescription AS SectionOSignedOffDesc_SignOff, Lookup17.DisplayCode AS StaffFrustrationwithPt_O2f, 
                      Lookup17.UserDescription AS StaffFrustrationwithPtDesc_O2f, Lookup18.DisplayCode AS Tradeoffs_O5, 
                      Lookup18.UserDescription AS TradeoffsDesc_O5, Lookup19.DisplayCode AS VisitbySocRelationFamily_O6b, 
                      Lookup19.UserDescription AS VisitbySocRelationFamilyDesc_O6b, dbo.OMHRS_SecO.AbstractID AS zzAbstractLink
FROM         dbo.OMHRS_SecO with (nolock) LEFT OUTER JOIN
                      dbo.LU_CodeFile AS Lookup1 with (nolock) on dbo.OMHRS_SecO.O6c = Lookup1.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS Lookup2 with (nolock) on dbo.OMHRS_SecO.O3 = Lookup2.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS Lookup3 with (nolock) on dbo.OMHRS_SecO.O2e = Lookup3.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS Lookup4 with (nolock) on dbo.OMHRS_SecO.O2b = Lookup4.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS Lookup5 with (nolock) on dbo.OMHRS_SecO.O2g = Lookup5.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS Lookup6 with (nolock) on dbo.OMHRS_SecO.O1 = Lookup6.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS Lookup7 with (nolock) on dbo.OMHRS_SecO.O4a = Lookup7.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS Lookup8 with (nolock) on dbo.OMHRS_SecO.O4c = Lookup8.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS Lookup9 with (nolock) on dbo.OMHRS_SecO.O2a = Lookup9.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS Lookup10 with (nolock) on dbo.OMHRS_SecO.O6a = Lookup10.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS Lookup11 with (nolock) on dbo.OMHRS_SecO.O4d = Lookup11.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS Lookup12 with (nolock) on dbo.OMHRS_SecO.O4b = Lookup12.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS Lookup13 with (nolock) on dbo.OMHRS_SecO.O2c = Lookup13.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS Lookup14 with (nolock) on dbo.OMHRS_SecO.O2d = Lookup14.Code LEFT OUTER JOIN
                      dbo.U_Users AS Lookup15 with (nolock) on dbo.OMHRS_SecO.SignCoder = Lookup15.Code LEFT OUTER JOIN
                      dbo.LU_YesNoSystem AS Lookup16 with (nolock) on dbo.OMHRS_SecO.SignOff = Lookup16.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS Lookup17 with (nolock) on dbo.OMHRS_SecO.O2f = Lookup17.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS Lookup18 with (nolock) on dbo.OMHRS_SecO.O5 = Lookup18.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS Lookup19 with (nolock) on dbo.OMHRS_SecO.O6b = Lookup19.Code




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_SCIPP_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE view [dbo].[OMHRS_SCIPP_VR]
as
select
    SCIPP_Order = OMHRS_SCIPP.SCIPP_ID,
    SCIPP_Category = SCIPP_Main.SCIPP_Category,
    OMHRS_SCIPP.SCIPP_Group,
    OMHRS_SCIPP.CMI_Weight,

RecordType_Z1 = lu_z1.DisplayCode,                  RecordTypeDesc_Z1 = lu_z1.UserDescription, 
AdmitDate_CC1 = OMHRS_SecAA.AdmitDate,
DischargeDate_X80 = (select top 1 OMHRS_SecS.X80 from OMHRS_SecS with (nolock) inner join OMHRS_SecAA AA on OMHRS_SecS.AbstractID = AA.AbstractID where AA.LinkID = OMHRS_SecAA.LinkID and AA.AppID in (651, 654)),
ChartNumber = OMHRS_SecAA.ChartNumber, 
CaseRecordNumber_AA3 = OMHRS_SecAA.AA3, 


ReasonAdmitThreatSelf_CC2a = LU_CC2a.DisplayCode,   ReasonAdmitThreatSelfDesc_CC2a = LU_CC2a.UserDescription,
NumberPsychAdmitLifetime_DD2 = lu_DD2.DisplayCode,  NumberPsychAdmitLifetimeD_DD2 = lu_DD2.UserDescription, 

AssessmentReferenceDate_A1 = dbo.OMHRS_SecA.A1,
ActualNextAssessmentDate = OMHRS_SecA.ActualNextAssessdate, 
OMHRS_SecA.NextAssessDate,
HistoryViolentCrime_A5a = lu_A5a.DisplayCode,       HistoryViolentCrimDesce_A5a = lu_A5a.UserDescription,


FacialExpression_B1a = LU_B1a.DisplayCode,          FacialExpressionDesc_B1a = LU_B1a.UserDescription, 
Tearfulness_B1b = LU_B1b.DisplayCode,               TearfulnessDesc_B1b = LU_B1b.UserDescription, 
MadeNegativeStatement_B1d = LU_B1d.DisplayCode,     MadeNegativeStatementDesc_B1d = LU_B1d.UserDescription, 
Hopelessness_B1g = LU_B1g.DisplayCode,              HopelessnessDesc_B1g = LU_B1g.UserDescription, 
InflatedSelfWorth_B1h = LU_B1h.DisplayCode,         InflatedSelfWorthDesc_B1h = LU_B1h.UserDescription, 
HyperArousal_B1i = LU_B1i.DisplayCode,              HyperArousalDesc_B1i = LU_B1i.UserDescription, 
PressuredSpeech_B1l = LU_B1l.DisplayCode,           PressuredSpeechDesc_B1l = LU_B1l.UserDescription, 
LabileAffect_B1m = LU_B1m.DisplayCode,              LabileAffectDesc_B1m = LU_B1m.UserDescription, 
FlatOrBluntedAffect_B1n = LU_B1n.DisplayCode,       FlatOrBluntedAffectDesc_B1n = LU_B1n.UserDescription, 
AnxiousComplaints_B1o = LU_B1o.DisplayCode,         AnxiousComplaintsDesc_B1o = LU_B1o.UserDescription, 
FearsPhobias_B1p = LU_B1p.DisplayCode,              FearsPhobiasDesc_B1p = LU_B1p.UserDescription, 
Hallucinations_B1u = LU_B1u.DisplayCode,            HallucinationsDesc_B1u = LU_B1u.UserDescription, 
CommandHallucinations_B1v = LU_B1v.DisplayCode,     CommandHallucinationsDesc_B1v = LU_B1v.UserDescription, 
Delusions_B1w = LU_B1w.DisplayCode,                 DelusionsDesc_B1w = LU_B1w.UserDescription, 
AbnormalThoughtProc_B1x = LU_B1x.DisplayCode,       AbnormalThoughtProcDesc_B1x = LU_B1x.UserDescription, 
Anhedonia_B1y = LU_B1y.DisplayCode,                 AnhedoniaDesc_B1y = LU_B1y.UserDescription, 
HealthComplaints_B1cc = LU_B1cc.DisplayCode,        HealthComplaintsDesc_B1cc = LU_B1cc.UserDescription, 
Anger_B1dd = LU_B1dd.DisplayCode,                   AngerDesc_B1dd = LU_B1dd.UserDescription, 
SleepProblems_B1gg = LU_B1gg.DisplayCode,           SleepProblemsDesc_B1gg = LU_B1gg.UserDescription, 
InsightMentalHealth_B2 = lu_B2.DisplayCode,         InsightMentalHealthDesc_B2 = lu_B2.UserDescription,    

SelfInjuryAttempts_D1a = lu_D1a.DisplayCode,        SelfInjuryAttemptsDesc_D1a = lu_D1a.UserDescription, 
SelfInjuryIntent_D1b = lu_D1b.DisplayCode,          SelfInjuryIntentDesc_D1b = lu_D1b.UserDescription, 
SelfInjuryConsidered_D1c = lu_D1c.DisplayCode,      SelfInjuryConsideredDesc_D1c = lu_D1c.UserDescription, 
ConcernRiskForSelfInjury_D1da = LU_D1da.DisplayCode, ConcernRiskForSelfInjuryDesc_D1da = lu_D1da.UserDescription, 
ViolenceToOthers_D2a = lu_D2a.DisplayCode,          ViolenceToOthersDesc_D2a = lu_D2a.UserDescription,
ViolenceIntimidation_D2b = lu_D2b.DisplayCode,      ViolenceIntimidationDesc_D2b = lu_D2b.UserDescription, 
ViolenceIdeation_D2c = lu_D2c.DisplayCode,          ViolenceIdeationDesc_D2c = lu_D2c.UserDescription, 
SexualViolence_D3 = LU_D3.DisplayCode,              SexualViolenceDesc_D3 = LU_D3.UserDescription, 

BehaviourSymWandering_E1a = lu_E1a.DisplayCode,     BehaviourSymWanderingDesc_E1a = lu_E1a.UserDescription, 
BehaviourShymVerbal_E1b = lu_E1b.DisplayCode,       BehaviourSymVerbalDesc_E1b = lu_E1b.UserDescription, 
BehaviourSymPhysical_E1c = lu_E1c.DisplayCode,      BehaviourSymPhysicalDesc_E1c = lu_E1c.UserDescription, 
BehaviourSymSocially_E1d = lu_E1d.DisplayCode,      BehaviourSymSociallyDesc_E1d = lu_E1d.UserDescription, 
BehaviourSymPubSexual_E1e = lu_E1e.DisplayCode,     BehaviourSymPubSexualDesc_E1e = lu_E1e.UserDescription, 
BehaviourSymResists_E1f = lu_E1f.DisplayCode,       BehaviourSymResistsDesc_E1f = lu_E1f.UserDescription, 
BehaviourSymElopement_E1g = lu_E1g.DisplayCode,     BehaviourSymElopementDesc_E1g = lu_E1g.UserDescription, 
ExtremeBehaviourDisturb_E2 = lu_E2.DisplayCode,     ExtremeBehaviourDisturbDesc_E2 = lu_E2.UserDescription, 

MemoryRecallShortTerm_F1a = lu_F1a.DisplayCode,     MemoryRecallShortTermDesc_F1a = lu_F1a.UserDescription, 
CognitiveSkills_F2 = lu_F2.DisplayCode,             CognitiveSkillsDesc_F2 = lu_F2.UserDescription, 

ADLHygiene_G1a = lu_G1a.DisplayCode,                ADLHygieneDesc_G1a = lu_G1a.UserDescription, 
ADLWalking_G1b = lu_G1b.DisplayCode,                ADLWalkingDesc_G1b = lu_G1b.UserDescription, 
ADLWheeling_G1c = lu_G1c.DisplayCode,               ADLWheelingDesc_G1c = lu_G1c.UserDescription,
ADLToiletUse_G1d = lu_G1d.DisplayCode,              ADLToiletUseDesc_G1d = lu_G1d.UserDescription, 
ADLEating_G1e = lu_G1e.DisplayCode,                 ADLEatingDesc_G1e = lu_G1e.UserDescription, 
IADLMealPrep_G2a = lu_G2a.DisplayCode,              IADLMealPrepDesc_G2a = lu_G2a.UserDescription, 
IADLManagingMeds_G2b = lu_G2b.DisplayCode,          IADLManagingMedsDesc_G2b = lu_G2b.UserDescription, 
IADLTransportation_G2c = lu_G2c.DisplayCode,        IADLTransportationDesc_G2c = lu_G2c.UserDescription, 
IADLManagingFinances_G2d = lu_G2d.DisplayCode,      IADLManagingFinancesDesc_G2d = lu_G2d.UserDescription, 
IADLPhoneUse_G2e = lu_G2e.DisplayCode,              IADLPhoneUseDesc_G2e = lu_G2e.UserDescription, 

MakingSelfUnderstood_H3 = lu_H3.DisplayCode, MakingSelfUnderstoodDesc_H3 = lu_H3.UserDescription,

Headache_I1a = LU_I1a.DisplayCode,                  HeadacheDesc_I1a = LU_I1a.UserDescription, 
DizzinessVertigo_I1b = LU_I1b.DisplayCode,          DizzinessVertigoDesc_I1b = LU_I1b.UserDescription, 
ShortnessOfBreath_I1c = LU_I1c.DisplayCode,         ShortnessOfBreathDesc_I1c = LU_I1c.UserDescription, 
ChestPainPressure_I1d = LU_I1d.DisplayCode,         ChestPainPressureDesc_I1d = LU_I1d.UserDescription, 
BlurredVision_I1e = LU_I1e.DisplayCode,             BlurredVisionDesc_I1e = LU_I1e.UserDescription, 
DryMouth_I1f = LU_I1f.DisplayCode,                  DryMouthDesc_I1f = LU_I1f.UserDescription, 
InOrDecreaseAppetite_I1g = LU_I1g.DisplayCode,      InOrDecreaseAppetiteDesc_I1g = LU_I1g.UserDescription,
DifficultyUrinating_I1h = LU_I1h.DisplayCode,       DifficultyUrinatingDesc_I1h = LU_I1h.UserDescription, 
Nausea_I1i = LU_I1i.DisplayCode,                    NauseaDesc_I1i = LU_I1i.UserDescription, 
Vomiting_I1j = LU_I1j.DisplayCode,                  Vomiting_Desc_I1j = LU_I1j.UserDescription, 
Constipation_I1k = LU_I1k.DisplayCode,              ConstipationDesc_I1k = LU_I1k.UserDescription, 
Diarrhea_I1l = LU_I1l.DisplayCode,                  DiarrheaDesc_I1l = LU_I1l.UserDescription, 
DaytimeDrowsiness_I1m = LU_I1m.DisplayCode,         DaytimeDrowsinessDesc_I1m = LU_I1m.UserDescription, 
FatigueWeakness_I1n = LU_I1n.DisplayCode,           FatigueWeaknessDesc_I1n = LU_I1n.UserDescription, 
ImpariedBalanceAtaxia_I1o = LU_I1o.DisplayCode,     ImpariedBalanceAtaxiaDesc_I1o = LU_I1o.UserDescription, 
EmergentConditions_I1p = LU_I1p.DisplayCode,        EmergentConditionsDesc_I1p = LU_I1p.UserDescription, 
Edema_I1q = LU_I1q.DisplayCode,                     EdemaDesc_I1q = LU_I1q.UserDescription, 

LifeEventSexualAbuse_J1m_2009 = LU_J1m_2009.DisplayCode,    LifeEventSexualAbuseDesc_J1m_2009 = LU_J1m_2009.UserDescription, 
LifeEventPhysicalAbuse_J1n_2009 = LU_J1n_2009.DisplayCode,  LifeEventPhysicalAbuseDesc_J1n_2009 = LU_J1n_2009.UserDescription, 
LifeEventEmotional_J1o_2009 = LU_J1o_2009.DisplayCode,      LifeEventEmotionalDesc_J1o_2009 = LU_J1o_2009.UserDescription, 

PtHostileTowardPt_O2d = LU_O2d.DisplayCode,         PtHostileTowardPtDesc_O2d = LU_O2d.UserDescription,
EmploymentStatus_O3 = lu_O3.DisplayCode,            EmploymentStatusDesc_O3 = lu_O3.UserDescription, 
TradeOffs_O5 = LU_O5.DisplayCode,                   TradeOffsDesc_O5 = LU_O5.UserDescription,

DSMDisorderChildhood_Q1a = LU_Q1a.DisplayCode,      DSMDisorderChildhoodDesc_Q1a = LU_Q1a.UserDescription, 
DSMDeliriumDisorder_Q1b = LU_Q1b.DisplayCode,       DSMDeliriumDisorderDesc_Q1b = LU_Q1b.UserDescription, 
DSMMentalDisorder_Q1c = LU_Q1c.DisplayCode,         DSMMentalDisorderDesc_Q1c = LU_Q1c.UserDescription, 
DSMSubstanceRelated_Q1d = LU_Q1d.DisplayCode,       DSMSubstanceRelatedDesc_Q1d = LU_Q1d.UserDescription, 
DSMSchizophrenia_Q1e = LU_Q1e.DisplayCode,          DSMSchizophreniaDesc_Q1e = LU_Q1e.UserDescription, 
DSMMoodDisorder_Q1f = LU_Q1f.DisplayCode,           DSMMoodDisorderDesc_Q1f = LU_Q1f.UserDescription, 
DSMAnxietyDisorder_Q1g = LU_Q1g.DisplayCode,        DSMAnxietyDisorderDesc_Q1g = LU_Q1g.UserDescription, 
DSMSomatoformDisorder_Q1h = LU_Q1h.DisplayCode,     DSMSomatoformDisorderDesc_Q1h = LU_Q1h.UserDescription, 
DSMFactitiousDisorder_Q1i = LU_Q1i.DisplayCode,     DSMFactitiousDisorderDesc_Q1i = LU_Q1i.UserDescription, 
DSMDissociative_Q1j = LU_Q1j.DisplayCode,           DSMDissociativeDesc_Q1j = LU_Q1j.UserDescription, 
DSMSexualDisorder_Q1k = LU_Q1k.DisplayCode,         DSMSexualDisorderDesc_Q1k = LU_Q1k.UserDescription, 
DSMEatingDisorder_Q1l = LU_Q1l.DisplayCode,         DSMEatingDisorderDesc_Q1l = LU_Q1l.UserDescription, 
DSMSleepDisorder_Q1m = LU_Q1m.DisplayCode,          DSMSleepDisorderDesc_Q1m = LU_Q1m.UserDescription, 
DSMImpulseDisorder_Q1n = LU_Q1n.DisplayCode,        DSMImpulseDisorderDesc_Q1n = LU_Q1n.UserDescription, 
DSMAdjustmentDisorder_Q1o = LU_Q1o.DisplayCode,     DSMAdjustmentDisorderDesc_Q1o = LU_Q1o.UserDescription, 
DSMPersonalityDisorder_Q1p = LU_Q1p.DisplayCode,    DSMPersonalityDisorderDesc_Q1p = LU_Q1p.UserDescription, 
DSMNotApplicable_Q1q = LU_Q1q.DisplayCode,          DSMNotApplicableDesc_Q1q = LU_Q1q.UserDescription, 
CurrentPatientType_Q5 = lu_Q5.DisplayCode,          CurrentPatientTypeDesc_Q5 = lu_Q5.UserDescription, 


zzAbstractLink = OMHRS_SecAA.AbstractID, zzAbstractAdmitLinkID = LinkID
from dbo.OMHRS_SCIPP with (nolock) left join
    SCIPP_Main on SCIPP_Main.SCIPP_Group = OMHRS_SCIPP.SCIPP_Group inner join 
    OMHRS_SecAA with (nolock) on OMHRS_SCIPP.AbstractID = OMHRS_SecAA.AbstractID LEFT JOIN
    lu_CodeFile lu_Z1 with (nolock) on OMHRS_SecAA.Z1 = lu_Z1.Code LEFT JOIN

    OMHRS_SecCC with (nolock) on OMHRS_SecCC.AbstractID = OMHRS_SecAA.AbstractID LEFT JOIN
    LU_CodeFile LU_CC2a with (nolock) on LU_CC2a.Code = OMHRS_SecCC.CC2a LEFT JOIN

    dbo.OMHRS_SecDD with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecDD.AbstractID LEFT JOIN
    lu_CodeFile lu_DD2 with (nolock) on OMHRS_SecDD.DD2 = lu_DD2.Code LEFT JOIN

    OMHRS_SecA with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecA.AbstractID LEFT JOIN
    lu_CodeFile lu_A5a with (nolock) on OMHRS_SecA.A5a = lu_A5a.Code LEFT JOIN

    OMHRS_SecB with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecB.AbstractID LEFT JOIN
    lu_CodeFile lu_B1a with (nolock) on OMHRS_SecB.B1a = lu_B1a.Code LEFT JOIN
    lu_CodeFile lu_B1b with (nolock) on OMHRS_SecB.B1b = lu_B1b.Code LEFT JOIN
    lu_CodeFile lu_B1d with (nolock) on OMHRS_SecB.B1d = lu_B1d.Code LEFT JOIN
    lu_CodeFile lu_B1g with (nolock) on OMHRS_SecB.B1g = lu_B1g.Code LEFT JOIN
    lu_CodeFile lu_B1h with (nolock) on OMHRS_SecB.B1h = lu_B1h.Code LEFT JOIN
    lu_CodeFile lu_B1i with (nolock) on OMHRS_SecB.B1i = lu_B1i.Code LEFT JOIN
    lu_CodeFile lu_B1l with (nolock) on OMHRS_SecB.B1l = lu_B1l.Code LEFT JOIN
    lu_CodeFile lu_B1m with (nolock) on OMHRS_SecB.B1m = lu_B1m.Code LEFT JOIN
    lu_CodeFile lu_B1n with (nolock) on OMHRS_SecB.B1n = lu_B1n.Code LEFT JOIN
    lu_CodeFile lu_B1o with (nolock) on OMHRS_SecB.B1o = lu_B1o.Code LEFT JOIN
    lu_CodeFile lu_B1p with (nolock) on OMHRS_SecB.B1p = lu_B1p.Code LEFT JOIN
    lu_CodeFile lu_B1u with (nolock) on OMHRS_SecB.B1u = lu_B1u.Code LEFT JOIN
    lu_CodeFile lu_B1v with (nolock) on OMHRS_SecB.B1v = lu_B1v.Code LEFT JOIN
    lu_CodeFile lu_B1w with (nolock) on OMHRS_SecB.B1w = lu_B1w.Code LEFT JOIN
    lu_CodeFile lu_B1x with (nolock) on OMHRS_SecB.B1x = lu_B1x.Code LEFT JOIN
    lu_CodeFile lu_B1y with (nolock) on OMHRS_SecB.B1y = lu_B1y.Code LEFT JOIN
    lu_CodeFile lu_B1cc with (nolock) on OMHRS_SecB.B1cc = lu_B1cc.Code LEFT JOIN
    lu_CodeFile lu_B1dd with (nolock) on OMHRS_SecB.B1dd = lu_B1dd.Code LEFT JOIN
    lu_CodeFile lu_B1gg with (nolock) on OMHRS_SecB.B1gg = lu_B1gg.Code LEFT JOIN
    lu_CodeFile lu_B2 with (nolock) on OMHRS_SecB.B2 = lu_B2.Code LEFT JOIN

    OMHRS_SecD with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecD.AbstractID LEFT JOIN
    lu_CodeFile lu_D1a with (nolock) on OMHRS_SecD.D1a = lu_D1a.Code LEFT JOIN
    lu_CodeFile lu_D1b with (nolock) on OMHRS_SecD.D1b = lu_D1b.Code LEFT JOIN
    lu_CodeFile lu_D1c with (nolock) on OMHRS_SecD.D1c = lu_D1c.Code LEFT JOIN
    lu_CodeFile lu_D1da with (nolock) on OMHRS_SecD.D1da = lu_D1da.Code LEFT JOIN
    lu_CodeFile lu_D2a with (nolock) on OMHRS_SecD.D2a = lu_D2a.Code LEFT JOIN
    lu_CodeFile lu_D2b with (nolock) on OMHRS_SecD.D2b = lu_D2b.Code LEFT JOIN
    lu_CodeFile lu_D2c with (nolock) on OMHRS_SecD.D2c = lu_D2c.Code LEFT JOIN
    lu_CodeFile lu_D3 with (nolock) on OMHRS_SecD.D3 = lu_D3.Code LEFT JOIN

    dbo.OMHRS_SecE with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecE.AbstractID LEFT JOIN
    lu_CodeFile lu_E1a with (nolock) on OMHRS_SecE.E1a = lu_E1a.Code LEFT JOIN
    lu_CodeFile lu_E1b with (nolock) on OMHRS_SecE.E1b = lu_E1b.Code LEFT JOIN
    lu_CodeFile lu_E1c with (nolock) on OMHRS_SecE.E1c = lu_E1c.Code LEFT JOIN
    lu_CodeFile lu_E1d with (nolock) on OMHRS_SecE.E1d = lu_E1d.Code LEFT JOIN
    lu_CodeFile lu_E1e with (nolock) on OMHRS_SecE.E1e = lu_E1e.Code LEFT JOIN
    lu_CodeFile lu_E1f with (nolock) on OMHRS_SecE.E1f = lu_E1f.Code LEFT JOIN
    lu_CodeFile lu_E1g with (nolock) on OMHRS_SecE.E1g = lu_E1g.Code LEFT JOIN
    lu_CodeFile lu_E2 with (nolock) on OMHRS_SecE.E2 = lu_E2.Code LEFT JOIN

    dbo.OMHRS_SecF with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecF.AbstractID LEFT JOIN
    lu_CodeFile lu_F1a with (nolock) on OMHRS_SecF.F1a = lu_F1a.Code LEFT JOIN
    lu_CodeFile lu_F2 with (nolock) on OMHRS_SecF.F2 = lu_F2.Code LEFT JOIN

    dbo.OMHRS_SecG with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecG.AbstractID LEFT JOIN
    lu_CodeFile lu_G1a with (nolock) on OMHRS_SecG.G1a = lu_G1a.Code LEFT JOIN
    lu_CodeFile lu_G1b with (nolock) on OMHRS_SecG.G1b = lu_G1b.Code LEFT JOIN
    lu_CodeFile lu_G1c with (nolock) on OMHRS_SecG.G1c = lu_G1c.Code LEFT JOIN
    lu_CodeFile lu_G1d with (nolock) on OMHRS_SecG.G1d = lu_G1d.Code LEFT JOIN
    lu_CodeFile lu_G1e with (nolock) on OMHRS_SecG.G1e = lu_G1e.Code LEFT JOIN
    lu_CodeFile lu_G2a with (nolock) on OMHRS_SecG.G2a = lu_G2a.Code LEFT JOIN
    lu_CodeFile lu_G2b with (nolock) on OMHRS_SecG.G2b = lu_G2b.Code LEFT JOIN
    lu_CodeFile lu_G2c with (nolock) on OMHRS_SecG.G2c = lu_G2c.Code LEFT JOIN
    lu_CodeFile lu_G2d with (nolock) on OMHRS_SecG.G2d = lu_G2d.Code LEFT JOIN
    lu_CodeFile lu_G2e with (nolock) on OMHRS_SecG.G2e = lu_G2e.Code LEFT JOIN

    dbo.OMHRS_SecH with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecH.AbstractID LEFT JOIN
    lu_CodeFile lu_H3 with (nolock) on OMHRS_SecH.H3 = lu_H3.Code LEFT JOIN

    dbo.OMHRS_SecI with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecI.AbstractID LEFT JOIN
    lu_CodeFile lu_I1a with (nolock) on OMHRS_SecI.I1a = lu_I1a.Code LEFT JOIN
    lu_CodeFile lu_I1b with (nolock) on OMHRS_SecI.I1b = lu_I1b.Code LEFT JOIN
    lu_CodeFile lu_I1c with (nolock) on OMHRS_SecI.I1c = lu_I1c.Code LEFT JOIN
    lu_CodeFile lu_I1d with (nolock) on OMHRS_SecI.I1d = lu_I1d.Code LEFT JOIN
    lu_CodeFile lu_I1e with (nolock) on OMHRS_SecI.I1e = lu_I1e.Code LEFT JOIN
    lu_CodeFile lu_I1f with (nolock) on OMHRS_SecI.I1f = lu_I1f.Code LEFT JOIN
    lu_CodeFile lu_I1g with (nolock) on OMHRS_SecI.I1g = lu_I1g.Code LEFT JOIN
    lu_CodeFile lu_I1h with (nolock) on OMHRS_SecI.I1h = lu_I1h.Code LEFT JOIN
    lu_CodeFile lu_I1i with (nolock) on OMHRS_SecI.I1i = lu_I1i.Code LEFT JOIN
    lu_CodeFile lu_I1j with (nolock) on OMHRS_SecI.I1j = lu_I1j.Code LEFT JOIN
    lu_CodeFile lu_I1k with (nolock) on OMHRS_SecI.I1k = lu_I1k.Code LEFT JOIN
    lu_CodeFile lu_I1l with (nolock) on OMHRS_SecI.I1l = lu_I1l.Code LEFT JOIN
    lu_CodeFile lu_I1m with (nolock) on OMHRS_SecI.I1m = lu_I1m.Code LEFT JOIN
    lu_CodeFile lu_I1n with (nolock) on OMHRS_SecI.I1n = lu_I1n.Code LEFT JOIN
    lu_CodeFile lu_I1o with (nolock) on OMHRS_SecI.I1o = lu_I1o.Code LEFT JOIN
    lu_CodeFile lu_I1p with (nolock) on OMHRS_SecI.I1p = lu_I1p.Code LEFT JOIN
    lu_CodeFile lu_I1q with (nolock) on OMHRS_SecI.I1q = lu_I1q.Code LEFT JOIN

    dbo.OMHRS_SecJ with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecJ.AbstractID LEFT JOIN
    lu_CodeFile lu_J1m_2009 with (nolock) on OMHRS_SecJ.J1m_2009 = lu_J1m_2009.Code LEFT JOIN
    lu_CodeFile lu_J1n_2009 with (nolock) on OMHRS_SecJ.J1n_2009 = lu_J1n_2009.Code LEFT JOIN
    lu_CodeFile lu_J1o_2009 with (nolock) on OMHRS_SecJ.J1o_2009 = lu_J1o_2009.Code LEFT JOIN

    dbo.OMHRS_SecO with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecO.AbstractID LEFT JOIN
    lu_CodeFile lu_O2d with (nolock) on OMHRS_SecO.O2d = lu_O2d.Code LEFT JOIN
    lu_CodeFile lu_O3 with (nolock) on OMHRS_SecO.O3 = lu_O3.Code LEFT JOIN
    lu_CodeFile lu_O5 with (nolock) on OMHRS_SecO.O5 = lu_O5.Code LEFT JOIN

    dbo.OMHRS_SecQ with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecQ.AbstractID LEFT JOIN
    lu_CodeFile lu_Q1a with (nolock) on OMHRS_SecQ.Q1a = lu_Q1a.Code LEFT JOIN
    lu_CodeFile lu_Q1b with (nolock) on OMHRS_SecQ.Q1b = lu_Q1b.Code LEFT JOIN
    lu_CodeFile lu_Q1c with (nolock) on OMHRS_SecQ.Q1c = lu_Q1c.Code LEFT JOIN
    lu_CodeFile lu_Q1d with (nolock) on OMHRS_SecQ.Q1d = lu_Q1d.Code LEFT JOIN
    lu_CodeFile lu_Q1e with (nolock) on OMHRS_SecQ.Q1e = lu_Q1e.Code LEFT JOIN
    lu_CodeFile lu_Q1f with (nolock) on OMHRS_SecQ.Q1f = lu_Q1f.Code LEFT JOIN
    lu_CodeFile lu_Q1g with (nolock) on OMHRS_SecQ.Q1g = lu_Q1g.Code LEFT JOIN
    lu_CodeFile lu_Q1h with (nolock) on OMHRS_SecQ.Q1h = lu_Q1h.Code LEFT JOIN
    lu_CodeFile lu_Q1i with (nolock) on OMHRS_SecQ.Q1i = lu_Q1i.Code LEFT JOIN
    lu_CodeFile lu_Q1j with (nolock) on OMHRS_SecQ.Q1j = lu_Q1j.Code LEFT JOIN
    lu_CodeFile lu_Q1k with (nolock) on OMHRS_SecQ.Q1k = lu_Q1k.Code LEFT JOIN
    lu_CodeFile lu_Q1l with (nolock) on OMHRS_SecQ.Q1l = lu_Q1l.Code LEFT JOIN
    lu_CodeFile lu_Q1m with (nolock) on OMHRS_SecQ.Q1m = lu_Q1m.Code LEFT JOIN
    lu_CodeFile lu_Q1n with (nolock) on OMHRS_SecQ.Q1n = lu_Q1n.Code LEFT JOIN
    lu_CodeFile lu_Q1o with (nolock) on OMHRS_SecQ.Q1o = lu_Q1o.Code LEFT JOIN
    lu_CodeFile lu_Q1p with (nolock) on OMHRS_SecQ.Q1p = lu_Q1p.Code LEFT JOIN
    lu_CodeFile lu_Q1q with (nolock) on OMHRS_SecQ.Q1q = lu_Q1q.Code LEFT JOIN
    lu_CodeFile lu_Q5 with (nolock) on OMHRS_SecQ.Q5 = lu_Q5.Code 

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_Serv_Interrupt_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[OMHRS_Serv_Interrupt_VR]
AS
SELECT     dbo.OMHRS_Serv_Interrupt.Occurrence AS InterruptOccurrence, dbo.OMHRS_Serv_Interrupt.X100 AS InterruptionStartDate_X100, 
                      dbo.OMHRS_Serv_Interrupt.X110 AS InterruptionEndDate_X110, Lookup1.DisplayCode AS InterruptionReason_X120, 
                      Lookup1.UserDescription AS InterruptionReasonDesc_X120, dbo.OMHRS_Serv_Interrupt.InteruptLOS AS InterruptLOS, 
                      dbo.OMHRS_SecAA.LinkID AS zzAbstractAdmitLinkID, dbo.OMHRS_SecAA.AbstractID AS zzAbstractLink
FROM         dbo.OMHRS_Serv_Interrupt with (nolock) RIGHT OUTER JOIN
                      dbo.OMHRS_SecAA with (nolock) ON dbo.OMHRS_Serv_Interrupt.AbstractID = dbo.OMHRS_SecAA.AbstractID LEFT OUTER JOIN
                      dbo.LU_CodeFile Lookup1 with (nolock) ON dbo.OMHRS_Serv_Interrupt.X120 = Lookup1.Code



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_UD_Abstracting_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[OMHRS_UD_Abstracting_VR]
AS
SELECT
    dbo.OMHRS_UserDefined.UDDate1 AS Date1UD, dbo.OMHRS_UserDefined.UDDate2 AS Date2UD, 
    dbo.OMHRS_UserDefined.UDDate3 AS Date3UD, dbo.OMHRS_UserDefined.UDDate4 AS Date4UD, 
    dbo.OMHRS_UserDefined.UDDate5 AS Date5UD, dbo.OMHRS_UDFieldsDate.UDDate6 AS Date6UD,
    dbo.OMHRS_UDFieldsDate.UDDate7 AS Date7UD,  dbo.OMHRS_UDFieldsDate.UDDate8 AS Date8UD,
    dbo.OMHRS_UDFieldsDate.UDDate9 AS Date9UD,  dbo.OMHRS_UDFieldsDate.UDDate10 AS Date10UD,
    dbo.OMHRS_UDFieldsDate.UDDate11 AS Date11UD,  dbo.OMHRS_UDFieldsDate.UDDate12 AS Date12UD,
    dbo.OMHRS_UDFieldsDate.UDDate13 AS Date13UD,  dbo.OMHRS_UDFieldsDate.UDDate14 AS Date14UD,
    dbo.OMHRS_UDFieldsDate.UDDate15 AS Date15UD,  dbo.OMHRS_UDFieldsDate.UDDate16 AS Date16UD,
    dbo.OMHRS_UDFieldsDate.UDDate17 AS Date17UD,  dbo.OMHRS_UDFieldsDate.UDDate18 AS Date18UD,
    dbo.OMHRS_UDFieldsDate.UDDate19 AS Date19UD,  dbo.OMHRS_UDFieldsDate.UDDate20 AS Date20UD,
    dbo.OMHRS_UDFieldsDate.UDDate21 AS Date21UD,  dbo.OMHRS_UDFieldsDate.UDDate22 AS Date22UD,
    dbo.OMHRS_UDFieldsDate.UDDate23 AS Date23UD,  dbo.OMHRS_UDFieldsDate.UDDate24 AS Date24UD,
    dbo.OMHRS_UDFieldsDate.UDDate25 AS Date25UD, 
    
    LU_CodeFile.DisplayCode AS Lookup1UD, dbo.LU_CodeFile.UserDescription AS Lookup1UDDesc, 
    LU_CodeFile_1.DisplayCode AS Lookup2UD, LU_CodeFile_1.UserDescription AS Lookup2UDDesc, 
    LU_CodeFile_2.DisplayCode AS Lookup3UD, LU_CodeFile_2.UserDescription AS Lookup3UDDesc, 
    LU_CodeFile_3.DisplayCode AS Lookup4UD, LU_CodeFile_3.UserDescription AS Lookup4UDDesc, 
    LU_CodeFile_4.DisplayCode AS Lookup5UD, LU_CodeFile_4.UserDescription AS Lookup5UDDesc, 
    LU_CodeFile_6.DisplayCode AS Lookup6UD, LU_CodeFile_6.UserDescription AS Lookup6UDDesc, 
    LU_CodeFile_7.DisplayCode AS Lookup7UD, LU_CodeFile_7.UserDescription AS Lookup7UDDesc, 
    LU_CodeFile_8.DisplayCode AS Lookup8UD, LU_CodeFile_8.UserDescription AS Lookup8UDDesc, 
    LU_CodeFile_9.DisplayCode AS Lookup9UD, LU_CodeFile_9.UserDescription AS Lookup9UDDesc, 
    LU_CodeFile_10.DisplayCode AS Lookup10UD, LU_CodeFile_10.UserDescription AS Lookup10UDDesc, 
    LU_CodeFile_11.DisplayCode AS Lookup11UD, LU_CodeFile_11.UserDescription AS Lookup11UDDesc, 
    LU_CodeFile_12.DisplayCode AS Lookup12UD, LU_CodeFile_12.UserDescription AS Lookup12UDDesc, 
    LU_CodeFile_13.DisplayCode AS Lookup13UD, LU_CodeFile_13.UserDescription AS Lookup13UDDesc, 
    LU_CodeFile_14.DisplayCode AS Lookup14UD, LU_CodeFile_14.UserDescription AS Lookup14UDDesc, 
    LU_CodeFile_15.DisplayCode AS Lookup15UD, LU_CodeFile_15.UserDescription AS Lookup15UDDesc, 
    LU_CodeFile_16.DisplayCode AS Lookup16UD, LU_CodeFile_16.UserDescription AS Lookup16UDDesc, 
    LU_CodeFile_17.DisplayCode AS Lookup17UD, LU_CodeFile_17.UserDescription AS Lookup17UDDesc, 
    LU_CodeFile_18.DisplayCode AS Lookup18UD, LU_CodeFile_18.UserDescription AS Lookup18UDDesc, 
    LU_CodeFile_19.DisplayCode AS Lookup19UD, LU_CodeFile_19.UserDescription AS Lookup19UDDesc, 
    LU_CodeFile_20.DisplayCode AS Lookup20UD, LU_CodeFile_20.UserDescription AS Lookup20UDDesc, 
    LU_CodeFile_21.DisplayCode AS Lookup21UD, LU_CodeFile_21.UserDescription AS Lookup21UDDesc, 
    LU_CodeFile_22.DisplayCode AS Lookup22UD, LU_CodeFile_22.UserDescription AS Lookup22UDDesc, 
    LU_CodeFile_23.DisplayCode AS Lookup23UD, LU_CodeFile_23.UserDescription AS Lookup23UDDesc, 
    LU_CodeFile_24.DisplayCode AS Lookup24UD, LU_CodeFile_24.UserDescription AS Lookup24UDDesc, 
    LU_CodeFile_25.DisplayCode AS Lookup25UD, LU_CodeFile_25.UserDescription AS Lookup25UDDesc, 

    dbo.OMHRS_UserDefined.UDInteger1 AS Numeric1UD, dbo.OMHRS_UserDefined.UDInteger2 AS Numeric2UD, 
    dbo.OMHRS_UserDefined.UDInteger3 AS Numeric3UD, dbo.OMHRS_UserDefined.UDInteger4 AS Numeric4UD, 
    dbo.OMHRS_UserDefined.UDInteger5 AS Numeric5UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger6 AS Numeric6UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger7 AS Numeric7UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger8 AS Numeric8UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger9 AS Numeric9UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger10 AS Numeric10UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger11 AS Numeric11UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger12 AS Numeric12UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger13 AS Numeric13UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger14 AS Numeric14UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger15 AS Numeric15UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger16 AS Numeric16UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger17 AS Numeric17UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger18 AS Numeric18UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger19 AS Numeric19UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger20 AS Numeric20UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger21 AS Numeric21UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger22 AS Numeric22UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger23 AS Numeric23UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger24 AS Numeric24UD, 
    dbo.OMHRS_UDFieldsInteger.UDInteger25 AS Numeric25UD, 
    
    dbo.OMHRS_UserDefined.UDText1 AS Notes1UD, dbo.OMHRS_UserDefined.UDText2 AS Notes2UD, 
    dbo.OMHRS_UserDefined.UDText3 AS Notes3UD, dbo.OMHRS_UserDefined.UDText4 AS Notes4UD, 
    dbo.OMHRS_UserDefined.UDText5 AS Notes5UD, 
    dbo.OMHRS_UDFieldsText.UDText6 AS Notes6UD,
    dbo.OMHRS_UDFieldsText.UDText7 AS Notes7UD,
    dbo.OMHRS_UDFieldsText.UDText8 AS Notes8UD,
    dbo.OMHRS_UDFieldsText.UDText9 AS Notes9UD,
    dbo.OMHRS_UDFieldsText.UDText10 AS Notes10UD,
    dbo.OMHRS_UDFieldsText.UDText11 AS Notes11UD,
    dbo.OMHRS_UDFieldsText.UDText12 AS Notes12UD,
    dbo.OMHRS_UDFieldsText.UDText13 AS Notes13UD,
    dbo.OMHRS_UDFieldsText.UDText14 AS Notes14UD,
    dbo.OMHRS_UDFieldsText.UDText15 AS Notes15UD,
    dbo.OMHRS_UDFieldsText.UDText16 AS Notes16UD,
    dbo.OMHRS_UDFieldsText.UDText17 AS Notes17UD,
    dbo.OMHRS_UDFieldsText.UDText18 AS Notes18UD,
    dbo.OMHRS_UDFieldsText.UDText19 AS Notes19UD,
    dbo.OMHRS_UDFieldsText.UDText20 AS Notes20UD,
    dbo.OMHRS_UDFieldsText.UDText21 AS Notes21UD,
    dbo.OMHRS_UDFieldsText.UDText22 AS Notes22UD,
    dbo.OMHRS_UDFieldsText.UDText23 AS Notes23UD,
    dbo.OMHRS_UDFieldsText.UDText24 AS Notes24UD,
    dbo.OMHRS_UDFieldsText.UDText25 AS Notes25UD,
    
    dbo.OMHRS_UserDefined.UDSmallText1 AS Text1UD, dbo.OMHRS_UserDefined.UDSmallText2 AS Text2UD, 
    dbo.OMHRS_UserDefined.UDSmallText3 AS Text3UD, dbo.OMHRS_UserDefined.UDSmallText4 AS Text4UD, 
    dbo.OMHRS_UserDefined.UDSmallText5 AS Text5UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText6 AS Text6UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText7 AS Text7UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText8 AS Text8UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText9 AS Text9UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText10 AS Text10UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText11 AS Text11UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText12 AS Text12UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText13 AS Text13UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText14 AS Text14UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText15 AS Text15UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText16 AS Text16UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText17 AS Text17UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText18 AS Text18UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText19 AS Text19UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText20 AS Text20UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText21 AS Text21UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText22 AS Text22UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText23 AS Text23UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText24 AS Text24UD, 
    dbo.OMHRS_UDFieldsSmallText.UDSmallText25 AS Text25UD, 
    
    dbo.OMHRS_UserDefined.UDTime1 AS Time1UD, dbo.OMHRS_UserDefined.UDTime2 AS Time2UD, 
    dbo.OMHRS_UserDefined.UDTime3 AS Time3UD, dbo.OMHRS_UserDefined.UDTime4 AS Time4UD, 
    dbo.OMHRS_UserDefined.UDTime5 AS Time5UD,
    dbo.OMHRS_UDFieldsTime.UDTime6 AS Time6UD, 
    dbo.OMHRS_UDFieldsTime.UDTime7 AS Time7UD, 
    dbo.OMHRS_UDFieldsTime.UDTime8 AS Time8UD, 
    dbo.OMHRS_UDFieldsTime.UDTime9 AS Time9UD, 
    dbo.OMHRS_UDFieldsTime.UDTime10 AS Time10UD, 
    dbo.OMHRS_UDFieldsTime.UDTime11 AS Time11UD, 
    dbo.OMHRS_UDFieldsTime.UDTime12 AS Time12UD, 
    dbo.OMHRS_UDFieldsTime.UDTime13 AS Time13UD, 
    dbo.OMHRS_UDFieldsTime.UDTime14 AS Time14UD, 
    dbo.OMHRS_UDFieldsTime.UDTime15 AS Time15UD, 
    dbo.OMHRS_UDFieldsTime.UDTime16 AS Time16UD, 
    dbo.OMHRS_UDFieldsTime.UDTime17 AS Time17UD, 
    dbo.OMHRS_UDFieldsTime.UDTime18 AS Time18UD, 
    dbo.OMHRS_UDFieldsTime.UDTime19 AS Time19UD, 
    dbo.OMHRS_UDFieldsTime.UDTime20 AS Time20UD, 
    dbo.OMHRS_UDFieldsTime.UDTime21 AS Time21UD, 
    dbo.OMHRS_UDFieldsTime.UDTime22 AS Time22UD, 
    dbo.OMHRS_UDFieldsTime.UDTime23 AS Time23UD, 
    dbo.OMHRS_UDFieldsTime.UDTime24 AS Time24UD, 
    dbo.OMHRS_UDFieldsTime.UDTime25 AS Time25UD, 

    dbo.OMHRS_UserDefined.Abstractid AS zzAbstractLink
FROM         
    dbo.OMHRS_UserDefined with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_4 with (nolock) ON dbo.OMHRS_UserDefined.UDLookup5 = LU_CodeFile_4.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_3 with (nolock) ON dbo.OMHRS_UserDefined.UDLookup4 = LU_CodeFile_3.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_2 with (nolock) ON dbo.OMHRS_UserDefined.UDLookup3 = LU_CodeFile_2.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_1 with (nolock) ON dbo.OMHRS_UserDefined.UDLookup2 = LU_CodeFile_1.Code LEFT OUTER JOIN
    dbo.LU_CodeFile with (nolock) ON dbo.OMHRS_UserDefined.UDLookup1 = dbo.LU_CodeFile.Code LEFT OUTER JOIN
    dbo.OMHRS_UDFieldsDate with (nolock) ON dbo.OMHRS_UserDefined.AbstractiD = dbo.OMHRS_UDFieldsDate.AbstractID LEFT OUTER JOIN
    dbo.OMHRS_UDFieldsInteger with (nolock) ON dbo.OMHRS_UserDefined.AbstractiD = dbo.OMHRS_UDFieldsInteger.AbstractID LEFT OUTER JOIN
    dbo.OMHRS_UDFieldsLookUp with (nolock) ON dbo.OMHRS_UserDefined.AbstractiD = dbo.OMHRS_UDFieldsLookUp.AbstractID LEFT OUTER JOIN
    dbo.OMHRS_UDFieldsSmallText with (nolock) ON dbo.OMHRS_UserDefined.AbstractiD = dbo.OMHRS_UDFieldsSmallText.AbstractID LEFT OUTER JOIN
    dbo.OMHRS_UDFieldsText with (nolock) ON dbo.OMHRS_UserDefined.AbstractiD = dbo.OMHRS_UDFieldsText.AbstractID LEFT OUTER JOIN
    dbo.OMHRS_UDFieldsTime with (nolock) ON dbo.OMHRS_UserDefined.AbstractiD = dbo.OMHRS_UDFieldsTime.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_6 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup6 = LU_CodeFile_6.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_7 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup7 = LU_CodeFile_7.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_8 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup8 = LU_CodeFile_8.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_9 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup9 = LU_CodeFile_9.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_10 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup10 = LU_CodeFile_10.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_11 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup11 = LU_CodeFile_11.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_12 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup12 = LU_CodeFile_12.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_13 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup13 = LU_CodeFile_13.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_14 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup14 = LU_CodeFile_14.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_15 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup15 = LU_CodeFile_15.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_16 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup16 = LU_CodeFile_16.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_17 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup17 = LU_CodeFile_17.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_18 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup18 = LU_CodeFile_18.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_19 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup19 = LU_CodeFile_19.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_20 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup20 = LU_CodeFile_20.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_21 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup21 = LU_CodeFile_21.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_22 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup22 = LU_CodeFile_22.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_23 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup23 = LU_CodeFile_23.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_24 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup24 = LU_CodeFile_24.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_25 with (nolock) ON dbo.OMHRS_UDFieldsLookUp.UDLookup25 = LU_CodeFile_25.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'




CREATE  VIEW [dbo].[OMHRS_UpdateHistory_VR]
AS
SELECT     AbstractID As zzAbstractLink , 
           Lookup1.Displaycode AS UpdateHistoryCoder,
 	   Lookup1.UserDescription AS UpdateHistoryCoderDesc,
	   Updated As UpdateHistoryUpdated, 
	   UpdateType As UpdateHistoryUpdateType
FROM       dbo.OMHRS_UpdateHistory with (nolock)
	   LEFT JOIN U_USERS LookUp1 with (nolock) ON 
	   dbo.OMHRS_UpdateHistory.Coder = Lookup1.Code




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE view [dbo].[OMHRS_VR]
as
SELECT     
[    **** SECTION AA ****] = '''',
    FirstName = OMHRS_SecAA.FirstName, LastName = OMHRS_SecAA.LastName, MiddleName = OMHRS_SecAA.MiddleName, 
    CountryOfResidence_X10 = lu_X10.DisplayCode, CountryOfResidenceDesc_X10 = lu_X10.UserDescription, 
    HCNProvince_X20 = LU_HCNProvince.DisplayCode, HCNProvinceDesc_X20 = LU_HCNProvince.UserDescription, 
    --ED - 02156
    HealthCareNumberStatus_X4 = LU_X4.DisplayCode, HealthCareNumberStatusDesc_X4 = LU_X4.UserDescription, 
    ChartNumber = OMHRS_SecAA.ChartNumber, --X30
    FixedChartNumber,
    
    HealthCareNumber = OMHRS_SecAA.HealthCareNumber, --AA2
    CaseRecordNumber = OMHRS_SecAA.AA3, 
    -- PR - 02377
    EncounterNumber = dbo.OMHRS_SecAA.EncounterNumber,  --AA3, 
    InstitutionNumber = H_InstitutionProfile.DisplayCode, InstitutionNumberDesc = H_InstitutionProfile.UserDescription, --AA4 
    UnitIdentifier_AA5 = lu_AA5.DisplayCode, UnitIdentifierDesc_AA5 = lu_AA5.UserDescription, 
    
    AssessmentSignOff = (CASE OMHRS_SecAA.ASignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    AssessmentSignOff_Desc = (CASE OMHRS_SecAA.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    AssessmentSignOffCoder = LU_SignOffCoder_T.DisplayCode, AssessmentSignOffCoderDesc = LU_SignOffCoder_T.UserDescription, 
    AssessmentSignOffDate = OMHRS_SecAA.ASignDate, 
    -- PR - 02377
    AttendingPhysician = LU_AttProvider.DisplayCode, AttendingPhysicianDesc = LU_AttProvider.UserDescription, 

    SectionAASignedOff = (CASE WHEN OMHRS_SecAA.SignOff = 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN OMHRS_SecAA.SignOff = 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionAASignedOff_Desc = (CASE WHEN OMHRS_SecAA.SignOff = 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN OMHRS_SecAA.SignOff = 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionAASignedOffCoder = LU_SignOffCoder_AA.DisplayCode, 
    SectionAASignedOffCoderDesc = LU_SignOffCoder_AA.UserDescription, SectionAASignedOffDate = OMHRS_SecAA.SignDate, 

[    **** SECTION IAR CCIM Assessment Consent ****] = '''',
    IAR_AssessmentConsentFlag = (case when OMHRS_IAR_CCIM.IAR_ConsentFlag = 302141 then ''N'' when OMHRS_IAR_CCIM.IAR_ConsentFlag = 302142 then ''Y'' end),
    IAR_AssessmentConsentFlagDesc = (case when OMHRS_IAR_CCIM.IAR_ConsentFlag = 302141 then ''No - The patient has requested that this visit not be shared within the IAR'' 
                                          when OMHRS_IAR_CCIM.IAR_ConsentFlag = 302142 then ''The patient has agreed to allow the sharing of their visit within the IAR'' 
                                     end),
    IAR_DateConsentGiven = OMHRS_IAR_CCIM.DateConsentGiven,
    IAR_IsCCIMSubmitted = (case when OMHRS_IAR_CCIM.IAR_CCIM_IsSubmitted = 302151 then ''N'' when OMHRS_IAR_CCIM.IAR_CCIM_IsSubmitted = 302152 then ''Y'' end), 
    IAR_IsCCIMSubmittedDesc = (case when OMHRS_IAR_CCIM.IAR_CCIM_IsSubmitted = 302151 then ''No - Not Submitted to CCIM'' when OMHRS_IAR_CCIM.IAR_CCIM_IsSubmitted = 302152 then ''Yes - Submitted to CCIM'' end), 
    IAR_DateSubmissionSentToCCIM = OMHRS_IAR_CCIM.DateSubmittedToCCIM,
    IAR_IsCCIMCorrected = (case when OMHRS_IAR_CCIM.IAR_CCIM_IsCorrected = 302161 then ''N'' when OMHRS_IAR_CCIM.IAR_CCIM_IsCorrected = 302162 then ''C'' when OMHRS_IAR_CCIM.IAR_CCIM_IsCorrected = 302163 then ''D'' end), 
    IAR_IsCCIMCorrectedDesc = (case when OMHRS_IAR_CCIM.IAR_CCIM_IsCorrected = 302161 then ''New'' when OMHRS_IAR_CCIM.IAR_CCIM_IsCorrected = 302162 then ''Correction'' when OMHRS_IAR_CCIM.IAR_CCIM_IsCorrected = 302163 then ''Deletion'' end), 
    IAR_DateCorrectionSentToCCIM = OMHRS_IAR_CCIM.DateCorrectedToCCIM,

[    **** SECTION BB ****] = '''',
    Sex_BB1 = lu_BB1.DisplayCode, SexDesc_BB1 = lu_BB1.UserDescription, 
    Birthdate_BB2 = BB2, 
    EstimatedBirthdate_X40 = (CASE dbo.OMHRS_SecBB.X40 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    EstimatedBirthdateDesc_X40 = (CASE dbo.OMHRS_SecBB.X40 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription  ELSE '''' END), 
    MaritalStatus_BB3 = lu_BB3.DisplayCode, MaritalStatusDesc_BB3 = lu_BB3.UserDescription, 
    Language_BB4 = lu_BB4.DisplayCode, LanguageDesc_BB4 = lu_BB4.UserDescription, 
    Education_BB5 = lu_BB5.DisplayCode, EducationDesc_BB5 = lu_BB5.UserDescription, 
    
    IncomeEmployment_BB6a = (CASE dbo.OMHRS_SecBB.BB6a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    IncomeEmploymentDesc_BB6a = (CASE dbo.OMHRS_SecBB.BB6a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    IncomeEmploymentInsu_BB6b = (CASE dbo.OMHRS_SecBB.BB6b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    IncomeEmploymentInsuDesc_BB6b = (CASE dbo.OMHRS_SecBB.BB6b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    IncomePension_BB6c = (CASE dbo.OMHRS_SecBB.BB6c WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    IncomePensionDesc_BB6c = (CASE dbo.OMHRS_SecBB.BB6c WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    IncomeSocialAssist_BB6d = (CASE dbo.OMHRS_SecBB.BB6d WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    IncomeSocialAssistDesc_BB6d = (CASE dbo.OMHRS_SecBB.BB6d WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    IncomeDisabilityInsu_BB6e = (CASE dbo.OMHRS_SecBB.BB6e WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    IncomeDisabilityInsuDesc_BB6e = (CASE dbo.OMHRS_SecBB.BB6e WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    IncomeOther_BB6f = (CASE dbo.OMHRS_SecBB.BB6f WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    IncomeOtherDesc_BB6f = (CASE dbo.OMHRS_SecBB.BB6f WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    IncomeNo_BB6g = (CASE dbo.OMHRS_SecBB.BB6g WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    IncomeNoDesc_BB6g = (CASE dbo.OMHRS_SecBB.BB6g WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    ResponsePayProvince_X50a = (CASE dbo.OMHRS_SecBB.X50a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    ResponsePayProvinceDesc_X50a = (CASE dbo.OMHRS_SecBB.X50a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    ResponsePayWCB_X50b = (CASE dbo.OMHRS_SecBB.X50b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    ResponsePayWCBDesc_X50b = (CASE dbo.OMHRS_SecBB.X50b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    ResponsePayOtherProv_X50c = (CASE dbo.OMHRS_SecBB.X50c WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    ResponsePayOtherProvDesc_X50c = (CASE dbo.OMHRS_SecBB.X50c WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    ResponsePayDVA_X50d = (CASE dbo.OMHRS_SecBB.X50d WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    ResponsePayDVADesc_X50d = (CASE dbo.OMHRS_SecBB.X50d WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    ResponsePayFNIHB_X50e = (CASE dbo.OMHRS_SecBB.X50e WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    ResponsePayFNIHBDesc_X50e = (CASE dbo.OMHRS_SecBB.X50e WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    ResponsePayOther_X50f = (CASE dbo.OMHRS_SecBB.X50f WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    ResponsePayOtherDesc_X50f = (CASE dbo.OMHRS_SecBB.X50f WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    ResponsePaySelfPay_X50g = (CASE dbo.OMHRS_SecBB.X50g WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    ResponsePaySelfPayDesc_X50g = (CASE dbo.OMHRS_SecBB.X50g WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    ResponsePayOtherCountry_X50h = (CASE dbo.OMHRS_SecBB.X50h WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    ResponsePayOtherCountryD_X50h = (CASE dbo.OMHRS_SecBB.X50h WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    ResponsePayUnknown_X50i = (CASE dbo.OMHRS_SecBB.X50i WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    ResponsePayUnknownDesc_X50i = (CASE dbo.OMHRS_SecBB.X50i WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    AboriginalOrigin_BB7 = (CASE dbo.OMHRS_SecBB.BB7 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    AboriginalOriginDesc_BB7 = (CASE dbo.OMHRS_SecBB.BB7 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    AboriginalFirstNation_BB7a = (CASE dbo.OMHRS_SecBB.BB7a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    AboriginalFirstNationDesc_BB7a = (CASE dbo.OMHRS_SecBB.BB7a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    AboriginalMetis_BB7b = (CASE dbo.OMHRS_SecBB.BB7b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    AboriginalMetisDesc_BB7b = (CASE dbo.OMHRS_SecBB.BB7b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    AboriginalInuit_BB7c = (CASE dbo.OMHRS_SecBB.BB7c WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    AboriginalInuitDesc_BB7c = (CASE dbo.OMHRS_SecBB.BB7c WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 

    SectionBBSignedOff = (CASE OMHRS_SecBB.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionBBSignedOff_Desc = (CASE OMHRS_SecBB.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionBBSignedOffCoder = LU_SignOffCoder_BB.DisplayCode, 
    SectionBBSignedOffCoderDesc = LU_SignOffCoder_BB.UserDescription, SectionBBSignedOffDate = OMHRS_SecBB.SignDate, 

[    **** SECTION CC ****] = '''',
    AdmitDate = OMHRS_SecAA.AdmitDate, --CC1
    AdmitTime = OMHRS_SecAA.AdmitTime, 
    DateAdmittedToMentalHealthBed_X8 = OMHRS_SecCC.X8,    ----ED - 02274
    --ED - 01914
    WaitTime_X5a = (CASE dbo.OMHRS_SecA.X5a WHEN 200834 THEN ''0'' WHEN 200835 THEN ''1'' when 200836 then ''8'' ELSE '''' END), 
    WaitTimeDesc_X5a = (CASE dbo.OMHRS_SecA.X5a WHEN 200834 THEN ''No'' WHEN 200835 THEN ''Yes'' when 200836 then ''Unknown'' ELSE '''' END), 
    DateWaitBegan_X5b = OMHRS_SecA.X5b,
    ReasonAdmitThreatSelf_CC2a = (CASE dbo.OMHRS_SecCC.CC2a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    ReasonAdmitThreatSelfDesc_CC2a = (CASE dbo.OMHRS_SecCC.CC2a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    ReasonAdmitThreatOther_CC2b = (CASE dbo.OMHRS_SecCC.CC2b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    ReasonAdmThreatOthDesc_CC2b = (CASE dbo.OMHRS_SecCC.CC2b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    ReasonAdmitInability__CC2c = (CASE dbo.OMHRS_SecCC.CC2c WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    ReasonAdmitInabilityDesc__CC2c = (CASE dbo.OMHRS_SecCC.CC2c WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    ReasonAdmitProblem_CC2d = (CASE dbo.OMHRS_SecCC.CC2d WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    ReasonAdmitProblemDesc_CC2d = (CASE dbo.OMHRS_SecCC.CC2d WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    ReasonAdmitSpecific_CC2e = (CASE dbo.OMHRS_SecCC.CC2e WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    ReasonAdmitSpecificDesc_CC2e = (CASE dbo.OMHRS_SecCC.CC2e WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    ReasonAdmitJustice_CC2f = (CASE dbo.OMHRS_SecCC.CC2f WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    ReasonAdmitJusticeDesc_CC2f = (CASE dbo.OMHRS_SecCC.CC2f WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    ReasonAdmitOther_CC2g = (CASE dbo.OMHRS_SecCC.CC2g WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    ReasonAdmitOtherDesc_CC2g = (CASE dbo.OMHRS_SecCC.CC2g WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    --ED - 02275
    ForensicAssessment_CC2h = (CASE dbo.OMHRS_SecCC.CC2h WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    ForensicAssessmentDesc_CC2h = (CASE dbo.OMHRS_SecCC.CC2h WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    -- ED - 01682
    -- PostalCodeDesc_X60 = dbo.GetPostalDescription(isnull(OMHRS_SecCC.X60, ''''), isnull(OMHRS_SecS.X80, OMHRS_SecAA.AdmitDate)), -- ED - 01682
    PostalCode_X60 = OMHRS_SecCC.X60, 
    WhoLivedwithAtAdmission_CC3 = lu_CC3.DisplayCode, WhoLivedwithAtAdmitDesc_CC3 = lu_CC3.UserDescription, 
    PriorResidentialStatus_CC4 = lu_CC4.DisplayCode, PriorResidentialStatusDesc_CC4 = lu_CC4.UserDescription, 
    --ED - 01914
    AdmittedFrom_CC4a = LU_CC4a.DisplayCode, AdmittedFromDesc_CC4a = LU_CC4a.UserDescription,
    UsualResidentialStatus_CC4b = LU_CC4b.DisplayCode, UsualResidentialStatusDesc_CC4b = LU_CC4b.UserDescription, 
    ReferredFromFacility_X65 = lu_X65.DisplayCode, ReferredFromFacilityDesc_X65 = lu_X65.UserDescription, 
    ResidentialStability_CC5 = (CASE dbo.OMHRS_SecCC.CC5 WHEN 200951 THEN ''0'' WHEN 200952 THEN ''1'' ELSE '''' END), 
    ResidentialStabilityDesc_CC5 = (CASE dbo.OMHRS_SecCC.CC5 WHEN 200951 THEN ''living arrangement is stable'' WHEN 200952 THEN ''living arrangement is considered unstable'' ELSE '''' END), 

    SectionCCSignedOff = (CASE OMHRS_SecCC.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionCCSignedOff_Desc = (CASE OMHRS_SecCC.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionCCSignedOffCoder = LU_SignOffCoder_CC.DisplayCode, SectionCCSignedOffCoderDesc = LU_SignOffCoder_CC.UserDescription, 
    SectionCCSignedOffDate = OMHRS_SecCC.SignDate, 
    
[    **** SECTION DD ****] = '''',
    NumberPsychAdmitRecent_DD1 = lu_DD1.DisplayCode, NumberPsychAdmitRecentDes_DD1 = lu_DD1.UserDescription, 
    NumberPsychAdmitLifetime_DD2 = lu_DD2.DisplayCode, NumberPsychAdmitLifetimeD_DD2 = lu_DD2.UserDescription, 
    TimeSinceLastDischarge_DD3 = lu_DD3.DisplayCode, TimeSinceLastDischargeDes_DD3 = lu_DD3.UserDescription, 
    AmountTimeHospitalized_DD4 = lu_DD4.DisplayCode, AmountTimeHospitalizedDes_DD4 = lu_DD4.UserDescription, 
    ContactCommunityMental_DD5 = lu_DD5.DisplayCode, ContactCommunityMentalDes_DD5 = lu_DD5.UserDescription, 
    AgeAtFirstHospital_DD6 = lu_DD6.DisplayCode, AgeAtFirstHospitalDesc_DD6 = lu_DD6.UserDescription, 

    SectionDDSignedOff = (CASE OMHRS_SecDD.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionDDSignedOff_Desc = (CASE OMHRS_SecDD.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionDDSignedOffCoder = LU_SignOffCoder_DD.DisplayCode, 
    SectionDDSignedOffCoderDesc = LU_SignOffCoder_DD.UserDescription, SectionDDSignedOffDate = OMHRS_SecDD.SignDate, 


[    **** SECTION A ****] = '''',
    AssessmentReferenceDate = dbo.OMHRS_SecA.A1, AssessmentReferenceTime = dbo.OMHRS_SecA.AssessTime, 
    ReasonForAssessment_A2 = lu_A2.DisplayCode, ReasonForAssessmentDesc_A2 = lu_A2.UserDescription, 
    CurrentInpatientStatus_A3 = lu_A3.DisplayCode, CurrentInpatientStatusDesc_A3 = lu_A3.UserDescription, 
    --ED - 01914
    StatusAtTimeAdmission_A3a = LU_A3a.DisplayCode, StatusAtTimeAdmissionDesc_A3a = LU_A3a.UserDescription,
    StatusAtTimeAssessment_A3b = LU_A3b.DisplayCode, StatusAtTimeAssessmentDesc_A3b = LU_A3b.UserDescription,
    CC_ConsentToTreatment_A4a = (CASE WHEN OMHRS_SecA.A4a = 200379 THEN LU_570_Yes.DisplayCode WHEN OMHRS_SecA.A4a = 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    CC_ConsentToTreatmentDesc_A4a = (CASE WHEN OMHRS_SecA.A4a = 200379 THEN LU_570_Yes.UserDescription WHEN OMHRS_SecA.A4a = 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    CC_ManageProperty_A4b = (CASE WHEN OMHRS_SecA.A4b = 200379 THEN LU_570_Yes.DisplayCode WHEN OMHRS_SecA.A4b = 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    CC_ManagePropertyDesc_A4b = (CASE WHEN OMHRS_SecA.A4b = 200379 THEN LU_570_Yes.UserDescription WHEN OMHRS_SecA.A4b = 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    CC_DiscloseInformation_A4c = (CASE WHEN OMHRS_SecA.A4c = 200379 THEN LU_570_Yes.DisplayCode WHEN OMHRS_SecA.A4c = 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    CC_DiscloseInformationDes_A4c = (CASE WHEN OMHRS_SecA.A4c = 200379 THEN LU_570_Yes.UserDescription WHEN OMHRS_SecA.A4c = 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    CC_LegalGuardianDecMaker_A4d = (CASE WHEN OMHRS_SecA.A4d = 200379 THEN LU_570_Yes.DisplayCode WHEN OMHRS_SecA.A4d = 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    CC_LegalGuardianDecMakerD_A4d = (CASE WHEN OMHRS_SecA.A4d = 200379 THEN LU_570_Yes.UserDescription WHEN OMHRS_SecA.A4d = 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    HistoryViolentCrime_A5a = lu_A5a.DisplayCode, HistoryViolentCrimDesce_A5a = lu_A5a.UserDescription, 
    HistoryNonViolentCrime_A5b = lu_A5b.DisplayCode, HistoryNonViolentCrimDesce_A5b = lu_A5b.UserDescription, 

    SectionASignedOff = (CASE WHEN OMHRS_SecA.SignOff = 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN OMHRS_SecA.SignOff = 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionASignedOff_Desc = (CASE WHEN OMHRS_SecA.SignOff = 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN OMHRS_SecA.SignOff = 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionASignedOffCoder = LU_SignOffCoder_A.DisplayCode, 
    SectionASignedOffCoderDesc = LU_SignOffCoder_A.UserDescription, SectionASignedOffDate = OMHRS_SecA.SignDate, 
    

[    **** SECTION B ****] = '''',
    FacialExpression_B1a = (CASE OMHRS_SecB.B1a WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    FacialExpressionDesc_B1a = (CASE OMHRS_SecB.B1a WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    Tearfulness_B1b = (CASE OMHRS_SecB.B1b WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    TearfulnessDesc_B1b = (CASE OMHRS_SecB.B1b WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    DecreasedEnergy_B1c = (CASE OMHRS_SecB.B1c WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    DecreasedEnergyDesc_B1c = (CASE OMHRS_SecB.B1c WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    MadeNegativeStatement_B1d = (CASE OMHRS_SecB.B1d WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    MadeNegativeStatementDesc_B1d = (CASE OMHRS_SecB.B1d WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    SelfDeprecation_B1e = (CASE OMHRS_SecB.B1e WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    SelfDeprecationDesc_B1e = (CASE OMHRS_SecB.B1e WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    GuiltShame_B1f = (CASE OMHRS_SecB.B1f WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    GuiltShameDesc_B1f = (CASE OMHRS_SecB.B1f WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    Hopelessness_B1g = (CASE OMHRS_SecB.B1g WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    HopelessnessDesc_B1g = (CASE OMHRS_SecB.B1g WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    InflatedSelfWorth_B1h = (CASE OMHRS_SecB.B1h WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    InflatedSelfWorthDesc_B1h = (CASE OMHRS_SecB.B1h WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    HyperArousal_B1i = (CASE OMHRS_SecB.B1i WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    HyperArousalDesc_B1i = (CASE OMHRS_SecB.B1i WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    Irritability_B1j = (CASE OMHRS_SecB.B1j WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    IrritabilityDesc_B1j = (CASE OMHRS_SecB.B1j WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    IncreasedSociability_B1k = (CASE OMHRS_SecB.B1k WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    IncreasedSociabilityDesc_B1k = (CASE OMHRS_SecB.B1k WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    PressuredSpeech_B1l = (CASE OMHRS_SecB.B1l WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    PressuredSpeechDesc_B1l = (CASE OMHRS_SecB.B1l WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    LabileAffect_B1m = (CASE OMHRS_SecB.B1m WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    LabileAffectDesc_B1m = (CASE OMHRS_SecB.B1m WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    FlatOrBluntedAffect_B1n = (CASE OMHRS_SecB.B1n WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    FlatOrBluntedAffectDesc_B1n = (CASE OMHRS_SecB.B1n WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    AnxiousComplaints_B1o = (CASE OMHRS_SecB.B1o WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    AnxiousComplaintsDesc_B1o = (CASE OMHRS_SecB.B1o WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    FearsPhobias_B1p = (CASE OMHRS_SecB.B1p WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    FearsPhobiasDesc_B1p = (CASE OMHRS_SecB.B1p WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    ObsessiveThoughts_B1q = (CASE OMHRS_SecB.B1q WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    ObsessiveThoughtsDesc_B1q = (CASE OMHRS_SecB.B1q WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    CompulsiveBehaviour_B1r = (CASE OMHRS_SecB.B1r WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    CompulsiveBehaviourDesc_B1r = (CASE OMHRS_SecB.B1r WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    InstrusiveThoughts_B1s = (CASE OMHRS_SecB.B1s WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    InstrusiveThoughtsDesc_B1s = (CASE OMHRS_SecB.B1s WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    EpisodesOfPanic_B1t = (CASE OMHRS_SecB.B1t WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    EpisodesOfPanicDesc_B1t = (CASE OMHRS_SecB.B1t WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    Hallucinations_B1u = (CASE OMHRS_SecB.B1u WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    HallucinationsDesc_B1u = (CASE OMHRS_SecB.B1u WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    CommandHallucinations_B1v = (CASE OMHRS_SecB.B1v WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    CommandHallucinationsDesc_B1v = (CASE OMHRS_SecB.B1v WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    Delusions_B1w = (CASE OMHRS_SecB.B1w WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    DelusionsDesc_B1w = (CASE OMHRS_SecB.B1w WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    AbnormalThoughtProc_B1x = (CASE OMHRS_SecB.B1x WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    AbnormalThoughtProcDesc_B1x = (CASE OMHRS_SecB.B1x WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    Anhedonia_B1y = (CASE OMHRS_SecB.B1y WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    AnhedoniaDesc_B1y = (CASE OMHRS_SecB.B1y WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    LossOfInterest_B1z = (CASE OMHRS_SecB.B1z WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    LossOfInterestDesc_B1z = (CASE OMHRS_SecB.B1z WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 

    LackOfMotivation_B1aa = (CASE OMHRS_SecB.B1aa WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    LackOfMotivationDesc_B1aa = (CASE OMHRS_SecB.B1aa WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    ReducedInteraction_B1bb = (CASE OMHRS_SecB.B1bb WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    ReducedInteractionDesc_B1bb = (CASE OMHRS_SecB.B1bb WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    HealthComplaints_B1cc = (CASE OMHRS_SecB.B1cc WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    HealthComplaintsDesc_B1cc = (CASE OMHRS_SecB.B1cc WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    Anger_B1dd = (CASE OMHRS_SecB.B1dd WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    AngerDesc_B1dd = (CASE OMHRS_SecB.B1dd WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    UnusualphysicalMove_B1ee = (CASE OMHRS_SecB.B1ee WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    UnusualphysicalMoveDesc_B1ee = (CASE OMHRS_SecB.B1ee WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    Hygiene_B1ff = (CASE OMHRS_SecB.B1ff WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    HygieneDesc_B1ff = (CASE OMHRS_SecB.B1ff WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    SleepProblems_B1gg = (CASE OMHRS_SecB.B1gg WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    SleepProblemsDesc_B1gg = (CASE OMHRS_SecB.B1gg WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    InsightMentalHealth_B2 = lu_B2.DisplayCode, InsightMentalHealthDesc_B2 = lu_B2.UserDescription, 

    SectionBSignedOff = (CASE OMHRS_SecB.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionBSignedOff_Desc = (CASE OMHRS_SecB.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionBSignedOffCoder = LU_SignOffCoder_B.DisplayCode, SectionBSignedOffCoderDesc = LU_SignOffCoder_B.UserDescription, 
    SectionBSignedOffDate = OMHRS_SecB.SignDate, 

[    **** SECTION C ****] = '''',
    Alcohol_C1 = lu_C1.DisplayCode, AlcoholDesc_C1 = lu_C1.UserDescription, 
    SubstanceUseInhalants_C2a = lu_C2a.DisplayCode, 
    SubstanceUseInhalantsDes_C2a = lu_C2a.UserDescription, 
    SubstanceUseHallucinogend_C2b = lu_C2b.UserDescription, 
    SubstanceUseHallucinogen_C2b = lu_C2b.DisplayCode, 
    SubstanceUseCocaine_C2c = lu_C2c.DisplayCode, 
    SubstanceUseCocaineDesc_C2c = lu_C2c.UserDescription, 
    SubstanceUseStimulants_C2d = lu_C2d.DisplayCode, 
    SubstanceUseStimulantsDes_C2d = lu_C2d.UserDescription, 
    SubstanceUseOpiates_C2e = lu_C2e.DisplayCode, 
    SubstanceUseOpiatesDesc_C2e = lu_C2e.UserDescription, 
    SubstanceUseCannabis_C2f = lu_C2f.DisplayCode, 
    SubstanceUseCannabisDesc_C2f = lu_C2f.UserDescription, 
    WithdrawalSymptoms_C3 = lu_C3.DisplayCode, WithdrawalSymptomsDesc_C3 = lu_C3.UserDescription, 
    DrinkingConcerns_C4a = (CASE dbo.OMHRS_SecC.C4a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    DrinkingConcernsDesc_C4a = (CASE dbo.OMHRS_SecC.C4a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription  ELSE '''' END), 
    DrinkingCriticism_C4b = (CASE dbo.OMHRS_SecC.C4b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    DrinkingCriticismDesc_C4b = (CASE dbo.OMHRS_SecC.C4b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    DrinkingFeelingsGuilt_C4c = (CASE dbo.OMHRS_SecC.C4c WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode  ELSE '''' END), 
    DrinkingFeelingsGuiltDes_C4c = (CASE dbo.OMHRS_SecC.C4c WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    DrinkingNerves_C4d = (CASE dbo.OMHRS_SecC.C4d WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    DrinkingNervesDesc_C4d = (CASE dbo.OMHRS_SecC.C4d WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription  ELSE '''' END), 
    Smoking_C5 = lu_C5.DisplayCode, SmokingDesc_C5 = lu_C5.UserDescription, 
    Gambling_C6 = (CASE dbo.OMHRS_SecC.C6 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    GamblingDesc_C6 = (CASE dbo.OMHRS_SecC.C6 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 

    SectionCSignedOff = (CASE OMHRS_SecC.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionCSignedOff_Desc = (CASE OMHRS_SecC.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionCSignedOffCoder = LU_SignOffCoder_C.DisplayCode, SectionCSignedOffCoderDesc = LU_SignOffCoder_C.UserDescription, 
    SectionCSignedOffDate = OMHRS_SecC.SignDate, 

[    **** SECTION D ****] = '''',
    SelfInjuryAttempts_D1a = lu_D1a.DisplayCode, SelfInjuryAttemptsDesc_D1a = lu_D1a.UserDescription, 
    SelfInjuryIntent_D1b = lu_D1b.DisplayCode, SelfInjuryIntentDesc_D1b = lu_D1b.UserDescription, 
    SelfInjuryConsidered_D1c = lu_D1c.DisplayCode, SelfInjuryConsideredDesc_D1c = lu_D1c.UserDescription, 
    SelfInjuryOthers_D1d = lu_D1d.DisplayCode, SelfInjuryOthersDesc_D1d = lu_D1d.UserDescription, 
    
    --ED - 01914
    ConcernRiskForSelfInjury_D1da = (CASE OMHRS_SecD.D1da WHEN 200366 THEN ''0'' WHEN 200367 THEN ''1'' else '''' END), 
    ConcernRiskForSelfInjuryDesc_D1da = (CASE OMHRS_SecD.D1da WHEN 200366 THEN ''No'' WHEN 200367 THEN ''Yes'' ELSE '''' END), 
    SuicidePlanInLast30Days_D1db = (CASE OMHRS_SecD.D1db WHEN 200366 THEN ''0'' WHEN 200367 THEN ''1'' else '''' END), 
    SuicidePlanInLast30DaysDesc_D1db = (CASE OMHRS_SecD.D1db WHEN 200366 THEN ''No'' WHEN 200367 THEN ''Yes'' ELSE '''' END), 
    ViolenceToOthers_D2a = lu_D2a.DisplayCode, ViolenceToOthersDesc_D2a = lu_D2a.UserDescription, 
    ViolenceIntimidation_D2b = lu_D2b.DisplayCode, ViolenceIntimidationDesc_D2b = lu_D2b.UserDescription, 
    ViolenceIdeation_D2c = lu_D2c.DisplayCode, ViolenceIdeationDesc_D2c = lu_D2c.UserDescription, 
    SexualViolence_D3 = (CASE dbo.OMHRS_SecD.D3 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    SexualViolenceDesc_D3 = (CASE dbo.OMHRS_SecD.D3 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 

    SectionDSignedOff = (CASE OMHRS_SecD.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionDSignedOff_Desc = (CASE OMHRS_SecD.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionDSignedOffCoder = LU_SignOffCoder_D.DisplayCode, SectionDSignedOffCoderDesc = LU_SignOffCoder_D.UserDescription, 
    SectionDSignedOffDate = OMHRS_SecD.SignDate, 

[    **** SECTION E ****] = '''',
    BehaviourSymWandering_E1a = lu_E1a.DisplayCode, BehaviourSymWanderingDesc_E1a = lu_E1a.UserDescription, 
    BehaviourShymVerbal_E1b = lu_E1b.DisplayCode, BehaviourSymVerbalDesc_E1b = lu_E1b.UserDescription, 
    BehaviourSymPhysical_E1c = lu_E1c.DisplayCode, BehaviourSymPhysicalDesc_E1c = lu_E1c.UserDescription, 
    BehaviourSymSocially_E1d = lu_E1d.DisplayCode, BehaviourSymSociallyDesc_E1d = lu_E1d.UserDescription, 
    BehaviourSymPubSexual_E1e = lu_E1e.DisplayCode, BehaviourSymPubSexualDesc_E1e = lu_E1e.UserDescription, 
    BehaviourSymResists_E1f = lu_E1f.DisplayCode, BehaviourSymResistsDesc_E1f = lu_E1f.UserDescription, 
    BehaviourSymElopement_E1g = lu_E1g.DisplayCode, BehaviourSymElopementDesc_E1g = lu_E1g.UserDescription, 
    ExtremeBehaviourDisturb_E2 = lu_E2.DisplayCode, ExtremeBehaviourDisturbDesc_E2 = lu_E2.UserDescription, 

    SectionESignedOff = (CASE OMHRS_SecE.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionESignedOff_Desc = (CASE OMHRS_SecE.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionESignedOffCoder = LU_SignOffCoder_E.DisplayCode, SectionESignedOffCoderDesc = LU_SignOffCoder_E.UserDescription, 
    SectionESignedOffDate = OMHRS_SecE.SignDate, 

[    **** SECTION F ****] = '''',
    MemoryRecallShortTerm_F1a = lu_F1a.DisplayCode, MemoryRecallShortTermDesc_F1a = lu_F1a.UserDescription, 
    MemoryRecallProcedure_F1b = lu_F1b.DisplayCode, MemoryRecallProcedureDesc_F1b = lu_F1b.UserDescription, 
    CognitiveSkills_F2 = lu_F2.DisplayCode, CognitiveSkillsDesc_F2 = lu_F2.UserDescription, 
    IndicatorsEasyDistract_F3a = lu_F3a.DisplayCode, IndicatorsEasyDistractDesc_F3a = lu_F3a.UserDescription, 
    IndicatorsAlteredPerce_F3b = lu_F3b.DisplayCode, IndicatorsAlteredPerceDesc_F3b = lu_F3b.UserDescription, 
    IndicatorsDisSpeech_F3c = lu_F3c.DisplayCode, IndicatorsDisSpeechDesc_F3c = lu_F3c.UserDescription, 
    IndicatorsRestlessness_F3d = lu_F3d.DisplayCode, IndicatorsRestlessnessDesc_F3d = lu_F3d.UserDescription, 
    IndicatorsLethargy_F3e = lu_F3e.DisplayCode, IndicatorsLethargyDesc_F3e = lu_F3e.UserDescription, 
    IndicatorsMentalFunc_F3f = lu_F3f.DisplayCode, IndicatorsMentalFuncDesc_F3f = lu_F3f.UserDescription, 
    CognitiveDecline_F4 = LU_F4.DisplayCode, CognitiveDeclineDesc_F4 = LU_F4.UserDescription, 

    SectionFSignedOff = (CASE OMHRS_SecF.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionFSignedOff_Desc = (CASE OMHRS_SecF.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionFSignedOffCoder = LU_SignOffCoder_F.DisplayCode, SectionFSignedOffCoderDesc = LU_SignOffCoder_F.UserDescription, 
    SectionFSignedOffDate = OMHRS_SecF.SignDate, 

[    **** SECTION G ****] = '''',
    ADLHygiene_G1a = lu_G1a.DisplayCode, ADLHygieneDesc_G1a = lu_G1a.UserDescription, 
    ADLWalking_G1b = lu_G1b.DisplayCode, ADLWalkingDesc_G1b = lu_G1b.UserDescription, 
    ADLWheeling_G1c = lu_G1c.DisplayCode, ADLWheelingDesc_G1c = lu_G1c.UserDescription, 
    ADLToiletUse_G1d = lu_G1d.DisplayCode, ADLToiletUseDesc_G1d = lu_G1d.UserDescription, 
    ADLEating_G1e = lu_G1e.DisplayCode, ADLEatingDesc_G1e = lu_G1e.UserDescription, 
    IADLMealPrep_G2a = lu_G2a.DisplayCode, IADLMealPrepDesc_G2a = lu_G2a.UserDescription, 
    IADLManagingMeds_G2b = lu_G2b.DisplayCode, IADLManagingMedsDesc_G2b = lu_G2b.UserDescription, 
    IADLTransportation_G2c = lu_G2c.DisplayCode, IADLTransportationDesc_G2c = lu_G2c.UserDescription, 
    IADLManagingFinances_G2d = lu_G2d.DisplayCode, IADLManagingFinancesDesc_G2d = lu_G2d.UserDescription, 
    IADLPhoneUse_G2e = lu_G2e.DisplayCode, IADLPhoneUseDesc_G2e = lu_G2e.UserDescription, 
    Stamina_G3 = lu_G3.DisplayCode, StaminaDesc_G3 = lu_G3.UserDescription, 
    ADLDecline_G4 = (CASE dbo.OMHRS_SecG.G4 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    ADLDeclineDesc_G4 = (CASE dbo.OMHRS_SecG.G4 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    
    SectionGSignedOff = (CASE OMHRS_SecG.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionGSignedOff_Desc = (CASE OMHRS_SecG.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionGSignedOffCoder = LU_SignOffCoder_G.DisplayCode, SectionGSignedOffCoderDesc = LU_SignOffCoder_G.UserDescription, 
    SectionGSignedOffDate = OMHRS_SecG.SignDate, 

[    **** SECTION H ****] = '''',
    Hearing_H1 = lu_H1.DisplayCode, HearingDesc_H1 = lu_H1.UserDescription, 
    Vision_H2 = lu_H2.DisplayCode, VisionDesc_H2 = lu_H2.UserDescription, 
    MakingSelfUnderstood_H3 = lu_H3.DisplayCode, MakingSelfUnderstoodDesc_H3 = lu_H3.UserDescription, 

    SectionHSignedOff = (CASE OMHRS_SecH.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionHSignedOff_Desc = (CASE OMHRS_SecH.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionHSignedOffCoder = LU_SignOffCoder_H.DisplayCode, SectionHSignedOffCoderDesc = LU_SignOffCoder_H.UserDescription, 
    SectionHSignedOffDate = OMHRS_SecH.SignDate, 

[    **** SECTION I ****] = '''',
    Headache_I1a = (CASE dbo.OMHRS_SecI.I1a WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    HeadacheDesc_I1a = (CASE dbo.OMHRS_SecI.I1a WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    DizzinessVertigo_I1b = (CASE dbo.OMHRS_SecI.I1b WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    DizzinessVertigoDesc_I1b = (CASE dbo.OMHRS_SecI.I1b WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    ShortnessOfBreath_I1c = (CASE dbo.OMHRS_SecI.I1c WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    ShortnessOfBreathDesc_I1c = (CASE dbo.OMHRS_SecI.I1c WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    ChestPainPressure_I1d = (CASE dbo.OMHRS_SecI.I1d WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    ChestPainPressureDesc_I1d = (CASE dbo.OMHRS_SecI.I1d WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    BlurredVision_I1e = (CASE dbo.OMHRS_SecI.I1e WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    BlurredVisionDesc_I1e = (CASE dbo.OMHRS_SecI.I1e WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    DryMouth_I1f = (CASE dbo.OMHRS_SecI.I1f WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN  LU_538_2.DisplayCode ELSE '''' END), 
    DryMouthDesc_I1f = (CASE dbo.OMHRS_SecI.I1f WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN  200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    InOrDecreaseAppetite_I1g = (CASE dbo.OMHRS_SecI.I1g WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    InOrDecreaseAppetiteDesc_I1g = (CASE dbo.OMHRS_SecI.I1g WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    DifficultyUrinating_I1h = (CASE dbo.OMHRS_SecI.I1h WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    DifficultyUrinatingDesc_I1h = (CASE dbo.OMHRS_SecI.I1h WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    Nausea_I1i = (CASE dbo.OMHRS_SecI.I1i WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    NauseaDesc_I1i = (CASE dbo.OMHRS_SecI.I1i WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    Vomiting_I1j = (CASE dbo.OMHRS_SecI.I1j WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    Vomiting_Desc_I1j = (CASE dbo.OMHRS_SecI.I1j WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    Constipation_I1k = (CASE dbo.OMHRS_SecI.I1k WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    ConstipationDesc_I1k = (CASE dbo.OMHRS_SecI.I1k WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    Diarrhea_I1l = (CASE dbo.OMHRS_SecI.I1l WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    DiarrheaDesc_I1l = (CASE dbo.OMHRS_SecI.I1l WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    DaytimeDrowsiness_I1m = (CASE dbo.OMHRS_SecI.I1m WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    DaytimeDrowsinessDesc_I1m = (CASE dbo.OMHRS_SecI.I1m WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    FatigueWeakness_I1n = (CASE dbo.OMHRS_SecI.I1n WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    FatigueWeaknessDesc_I1n = (CASE dbo.OMHRS_SecI.I1n WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    ImpariedBalanceAtaxia_I1o = (CASE dbo.OMHRS_SecI.I1o WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    ImpariedBalanceAtaxiaDesc_I1o = (CASE dbo.OMHRS_SecI.I1o WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    EmergentConditions_I1p = (CASE dbo.OMHRS_SecI.I1p WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    EmergentConditionsDesc_I1p = (CASE dbo.OMHRS_SecI.I1p WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    Edema_I1q = (CASE dbo.OMHRS_SecI.I1q WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    EdemaDesc_I1q = (CASE dbo.OMHRS_SecI.I1q WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 

    Akathisia_I2a = (CASE dbo.OMHRS_SecI.I2a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    AkathisiaDesc_I2a = (CASE dbo.OMHRS_SecI.I2a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    Dyskinesia_I2b = (CASE dbo.OMHRS_SecI.I2b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    DyskinesiaDesc_I2b = (CASE dbo.OMHRS_SecI.I2b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    Tremor_I2c = (CASE dbo.OMHRS_SecI.I2c WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    TremorDesc_I2c = (CASE dbo.OMHRS_SecI.I2c WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    Rigidity_I2d = (CASE dbo.OMHRS_SecI.I2d WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    RigidityDesc_I2d = (CASE dbo.OMHRS_SecI.I2d WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    SlowShufflingGait_I2e = (CASE dbo.OMHRS_SecI.I2e WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    SlowShufflingGaitDesc_I2e = (CASE dbo.OMHRS_SecI.I2e WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    Bradykinesia_I2f = (CASE dbo.OMHRS_SecI.I2f WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    BradykinesiaDesc_I2f = (CASE dbo.OMHRS_SecI.I2f WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    Dystonia_I2g = (CASE dbo.OMHRS_SecI.I2g WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    DystoniaDesc_I2g = (CASE dbo.OMHRS_SecI.I2g WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 

    SexualFunctioning_I3 = (CASE dbo.OMHRS_SecI.I3 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    SexualFunctioningDesc_I3 = (CASE dbo.OMHRS_SecI.I3 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    
    --SelfRatedHealth_I4 = (CASE dbo.OMHRS_SecI.I4 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    --SelfRatedHealthDesc_I4 = (CASE dbo.OMHRS_SecI.I4 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    SelfRatedHealth_I4 = LU_I4.DisplayCode, SelfRatedHealthDesc_I4 = LU_I4.UserDescription, 
    
    ChewingSwallowing_I5 = (CASE dbo.OMHRS_SecI.I5 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    ChewingSwallowingDesc_I5 = (CASE dbo.OMHRS_SecI.I5 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    SkinOrFootProblem_I6 = (CASE dbo.OMHRS_SecI.I6 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    SkinOrFootProblemDesc_I6 = (CASE dbo.OMHRS_SecI.I6 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    --ED - 02277
    MajorSkinProblems_I6aa = (CASE dbo.OMHRS_SecI.I6aa WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    MajorSkinProblemsDesc_I6aa = (CASE dbo.OMHRS_SecI.I6aa WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    OtherSkinProblems_I6ab = (CASE dbo.OMHRS_SecI.I6ab WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    OtherSkinProblemsDesc_I6ab = (CASE dbo.OMHRS_SecI.I6ab WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    FootProblems_I6b = LU_I6b.DisplayCode, FootProblemsDesc_I6b = LU_I6b.UserDescription, 
    
    Falls_I7 = (CASE dbo.OMHRS_SecI.I7 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    FallsDesc_I7 = (CASE dbo.OMHRS_SecI.I7 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    --ED - 01914
    HistoryOfFalls_I7a = LU_I7a.DisplayCode, HistoryOfFallsDesc_I7a = LU_I7a.UserDescription, 
    --ED - 01914
    RecentFalls_I7b = (CASE dbo.OMHRS_SecI.I7b WHEN 200913 THEN ''0'' WHEN 200914 THEN ''1'' When 200915 then ''8'' ELSE '''' END), 
    RecentFallsDesc_I7b = (CASE dbo.OMHRS_SecI.I7b WHEN 200913 THEN ''No'' WHEN 200914 THEN ''Yes'' when 200915 then ''Not applicable (first assessment, or more than 30 days since last assessment)'' ELSE '''' END),

    PainFrequency_I8a = lu_I8a.DisplayCode, PainFrequencyDesc_I8a = lu_I8a.UserDescription, 
    PainIntensity_I8b = lu_I8b.DisplayCode, PainIntensityDesc_I8b = lu_I8b.UserDescription, 
    BladderContinence_I9 = lu_I9.DisplayCode, BladderContinenceDesc_I9 = lu_I9.UserDescription, 
    BowelContinence_I10 = lu_I10.DisplayCode, BowelContinenceDesc_I10 = lu_I10.UserDescription, 

    PresenceMedicalDiag_X11 = (CASE dbo.OMHRS_SecI.X11 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    PresenceMedicalDiagDesc_X11 = (CASE dbo.OMHRS_SecI.X11 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    --ED - 01914
    MedicalDiagnose_DiabetesType1_I11a = (CASE dbo.OMHRS_SecI.I11a WHEN 200907 THEN LU_576_1.DisplayCode WHEN 200906 THEN LU_576_0.DisplayCode WHEN 200908 THEN LU_576_8.DisplayCode ELSE '''' END), 
    MedicalDiagnose_DiabetesType1Desc_I11a = (CASE dbo.OMHRS_SecI.I11a WHEN 200907 THEN LU_576_1.UserDescription WHEN 200906 THEN LU_576_0.UserDescription WHEN 200908 THEN LU_576_8.UserDescription  ELSE '''' END), 
    MedicalDiagnose_DiabetesType2_I11b = (CASE dbo.OMHRS_SecI.I11b WHEN 200907 THEN LU_576_1.DisplayCode WHEN 200906 THEN LU_576_0.DisplayCode WHEN 200908 THEN LU_576_8.DisplayCode ELSE '''' END), 
    MedicalDiagnose_DiabetesType2Desc_I11b = (CASE dbo.OMHRS_SecI.I11b WHEN 200907 THEN LU_576_1.UserDescription WHEN 200906 THEN LU_576_0.UserDescription WHEN 200908 THEN LU_576_8.UserDescription  ELSE '''' END), 
    MedicalDiagnose_ChronicObstructivePulmonaryDisease_I11c = (CASE dbo.OMHRS_SecI.I11c WHEN 200907 THEN LU_576_1.DisplayCode WHEN 200906 THEN LU_576_0.DisplayCode WHEN 200908 THEN LU_576_8.DisplayCode ELSE '''' END), 
    MedicalDiagnose_ChronicObstructivePulmonaryDiseaseDesc_I11c = (CASE dbo.OMHRS_SecI.I11c WHEN 200907 THEN LU_576_1.UserDescription WHEN 200906 THEN LU_576_0.UserDescription WHEN 200908 THEN LU_576_8.UserDescription  ELSE '''' END), 
    MedicalDiagnose_CongestiveHeartFailure_I11d = (CASE dbo.OMHRS_SecI.I11d WHEN 200907 THEN LU_576_1.DisplayCode WHEN 200906 THEN LU_576_0.DisplayCode WHEN 200908 THEN LU_576_8.DisplayCode ELSE '''' END), 
    MedicalDiagnose_CongestiveHeartFailureDesc_I11d = (CASE dbo.OMHRS_SecI.I11d WHEN 200907 THEN LU_576_1.UserDescription WHEN 200906 THEN LU_576_0.UserDescription WHEN 200908 THEN LU_576_8.UserDescription  ELSE '''' END), 
    MedicalDiagnose_ChronicRenalFailureDialysis_I11e = (CASE dbo.OMHRS_SecI.I11e WHEN 200907 THEN LU_576_1.DisplayCode WHEN 200906 THEN LU_576_0.DisplayCode WHEN 200908 THEN LU_576_8.DisplayCode ELSE '''' END), 
    MedicalDiagnose_ChronicRenalFailureDialysisDesc_I11e = (CASE dbo.OMHRS_SecI.I11e WHEN 200907 THEN LU_576_1.UserDescription WHEN 200906 THEN LU_576_0.UserDescription WHEN 200908 THEN LU_576_8.UserDescription  ELSE '''' END), 
    MedicalDiagnose_HIV_I11f = (CASE dbo.OMHRS_SecI.I11f WHEN 200907 THEN LU_576_1.DisplayCode WHEN 200906 THEN LU_576_0.DisplayCode WHEN 200908 THEN LU_576_8.DisplayCode ELSE '''' END), 
    MedicalDiagnose_HIVDesc_I11f = (CASE dbo.OMHRS_SecI.I11f WHEN 200907 THEN LU_576_1.UserDescription WHEN 200906 THEN LU_576_0.UserDescription WHEN 200908 THEN LU_576_8.UserDescription  ELSE '''' END), 
    MedicalDiagnose_HepatitisC_I11g = (CASE dbo.OMHRS_SecI.I11g WHEN 200907 THEN LU_576_1.DisplayCode WHEN 200906 THEN LU_576_0.DisplayCode WHEN 200908 THEN LU_576_8.DisplayCode ELSE '''' END), 
    MedicalDiagnose_HepatitisCDesc_I11g = (CASE dbo.OMHRS_SecI.I11g WHEN 200907 THEN LU_576_1.UserDescription WHEN 200906 THEN LU_576_0.UserDescription WHEN 200908 THEN LU_576_8.UserDescription  ELSE '''' END), 

    SectionISignedOff = (CASE OMHRS_SecI.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionISignedOff_Desc = (CASE OMHRS_SecI.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionISignedOffCoder = LU_SignOffCoder_I.DisplayCode, SectionISignedOffCoderDesc = LU_SignOffCoder_I.UserDescription, 
    SectionISignedOffDate = OMHRS_SecI.SignDate, 

[    **** SECTION J ****] = '''',
    LifeEventAccident_J1a = (CASE dbo.OMHRS_SecJ.J1a WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventAccidentDesc_J1a = (CASE dbo.OMHRS_SecJ.J1a WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    LifeEventDistressed_J1b = (CASE dbo.OMHRS_SecJ.J1b WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventDistressedDesc_J1b = (CASE dbo.OMHRS_SecJ.J1b WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    LifeEventDeathFamily_J1c = (CASE dbo.OMHRS_SecJ.J1c WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventDeathFamilyDesc_J1c = (CASE dbo.OMHRS_SecJ.J1c WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    LifeEventChildCustody_J1d = (CASE dbo.OMHRS_SecJ.J1d WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventChildCustodyDesc_J1d = (CASE dbo.OMHRS_SecJ.J1d WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    LifeEventConflictLaden_J1e = (CASE dbo.OMHRS_SecJ.J1e WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventConflictLadenDesc_J1e = (CASE dbo.OMHRS_SecJ.J1e WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    LifeEventFailedEducate_J1f = (CASE dbo.OMHRS_SecJ.J1f WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventFailedEducateDesc_J1f = (CASE dbo.OMHRS_SecJ.J1f WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    LifeEventLossIncome_J1g = (CASE dbo.OMHRS_SecJ.J1g WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventLossIncomeDesc_J1g = (CASE dbo.OMHRS_SecJ.J1g WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    LifeEventOrganizational_J1h = (CASE dbo.OMHRS_SecJ.J1h WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventOrganizationalDes_J1h = (CASE dbo.OMHRS_SecJ.J1h WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    --ED - 01914
    LifeEventReviewHearing_J1h_2009 = (CASE dbo.OMHRS_SecJ.J1h_2009 WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventReviewHearingDesc_J1h_2009 = (CASE dbo.OMHRS_SecJ.J1h_2009 WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 

    LifeEventReviewHearing_J1i = (CASE dbo.OMHRS_SecJ.J1i WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventReviewHearingDesc_J1i = (CASE dbo.OMHRS_SecJ.J1i WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    --ED - 01914
    LifeEventImmigration_J1i_2009 = (CASE dbo.OMHRS_SecJ.J1i_2009 WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventImmigrationDesc_J1i_2009 = (CASE dbo.OMHRS_SecJ.J1i_2009 WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 

    LifeEventImmigration_J1j = (CASE dbo.OMHRS_SecJ.J1j WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventImmigrationDesc_J1j = (CASE dbo.OMHRS_SecJ.J1j WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    --ED - 01914
    LifeEventLivedWarZone_J1j_2009 = (CASE dbo.OMHRS_SecJ.J1j_2009 WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventLivedWarZoneDesc_J1j_2009 = (CASE dbo.OMHRS_SecJ.J1j_2009 WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 

    LifeEventLivedWarZone_J1k = (CASE dbo.OMHRS_SecJ.J1k WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventLivedWarZoneDesc_J1k = (CASE dbo.OMHRS_SecJ.J1k WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    --ED - 01914
    LifeEventWitness_J1k_2009 = (CASE dbo.OMHRS_SecJ.J1k_2009 WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventWitnessDesc_J1k_2009 = (CASE dbo.OMHRS_SecJ.J1k_2009 WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 

    LifeEventWitness_J1l = (CASE dbo.OMHRS_SecJ.J1l WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventWitnessDesc_J1l = (CASE dbo.OMHRS_SecJ.J1l WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    --ED - 01914
    LifeEventVictimCrime_J1l_2009 = (CASE dbo.OMHRS_SecJ.J1l_2009 WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventVictimCrimeDesc_J1l_2009 = (CASE dbo.OMHRS_SecJ.J1l_2009 WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 

    LifeEventSexualAbuse_J1n = (CASE dbo.OMHRS_SecJ.J1n WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventSexualAbuseDesc_J1n = (CASE dbo.OMHRS_SecJ.J1n WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    --ED - 01914
    LifeEventPhysicalAbuse_J1n_2009 = (CASE dbo.OMHRS_SecJ.J1h_2009 WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventPhysicalAbuseDesc_J1n_2009 = (CASE dbo.OMHRS_SecJ.J1n_2009 WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 

    LifeEventVictimCrime_J1m = (CASE dbo.OMHRS_SecJ.J1m WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventVictimCrimeDesc_J1m = (CASE dbo.OMHRS_SecJ.J1m WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    --ED - 01914
    LifeEventSexualAbuse_J1m_2009 = (CASE dbo.OMHRS_SecJ.J1m_2009 WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventSexualAbuseDesc_J1m_2009 = (CASE dbo.OMHRS_SecJ.J1m_2009 WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 

    LifeEventPhysicalAbuse_J1o = (CASE dbo.OMHRS_SecJ.J1o WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventPhysicalAbuseDesc_J1o = (CASE dbo.OMHRS_SecJ.J1o WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    --ED - 01914
    LifeEventEmotional_J1o_2009 = (CASE dbo.OMHRS_SecJ.J1o_2009 WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventEmotionalDesc_J1o_2009 = (CASE dbo.OMHRS_SecJ.J1o_2009 WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 

    LifeEventEmotional_J1p = (CASE dbo.OMHRS_SecJ.J1p WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventEmotionalDesc_J1p = (CASE dbo.OMHRS_SecJ.J1p WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    --ED - 01914
    LifeEventParentalAbuse_J1p_2009 = (CASE dbo.OMHRS_SecJ.J1p_2009 WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    LifeEventParentalAbuseDesc_J1p_2009 = (CASE dbo.OMHRS_SecJ.J1p_2009 WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 

    ResponseToLifeEvents_J2 = (CASE dbo.OMHRS_SecJ.J2 when 200897	then ''0'' when 200898 then ''1'' when 200899 then ''8'' else '''' end), 
    ResponseToLifeEventsDesc_J2 = (CASE dbo.OMHRS_SecJ.J2 when 200897	then ''No or not applicable'' when 200898	then ''Yes'' when 200899 then ''Could not (would not) respond'' else '''' end), 
    OtherIndicatorsHistory_J3a = (CASE dbo.OMHRS_SecJ.J3a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    OtherIndicatorsHistoryDesc_J3a = (CASE dbo.OMHRS_SecJ.J3a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    OtherIndicatorsFearful_J3b = (CASE dbo.OMHRS_SecJ.J3b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    OtherIndicatorsFearfulDesc_J3b = (CASE dbo.OMHRS_SecJ.J3b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 

    SectionJSignedOff = (CASE OMHRS_SecJ.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionJSignedOff_Desc = (CASE OMHRS_SecJ.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionJSignedOffCoder = LU_SignOffCoder_J.DisplayCode, SectionJSignedOffCoderDesc = LU_SignOffCoder_J.UserDescription, 
    SectionJSignedOffDate = OMHRS_SecJ.SignDate, 

[    **** SECTION K ****] = '''',
    HistoryOfMedication_K1 = lu_K1.DisplayCode, HistoryOfMedicationDesc_K1 = lu_K1.UserDescription, 
    MedicalRefusal_K2 = (CASE dbo.OMHRS_SecK.K2 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    MedicalRefusalDesc_K2 = (CASE dbo.OMHRS_SecK.K2 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    --ED - 02278
    PastMedicationSide_K3 = lu_K3.DisplayCode, PastMedicationSideDesc_K3 = lu_K3.UserDescription, 
    --PastMedicationSide_K3 = (CASE dbo.OMHRS_SecK.K3 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    --PastMedicationSideDesc_K3 = (CASE dbo.OMHRS_SecK.K3 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    
    IntentionalMisuseMed_K4 = (CASE dbo.OMHRS_SecK.K4 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    IntentionalMisuseMedDesc_K4 = (CASE dbo.OMHRS_SecK.K4 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    AcuteControlMedications_K5 = OMHRS_SecK.K5, 
    AllergyToDrugs_K6 = (CASE dbo.OMHRS_SecK.K6 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    AllergyToDrugsDesc_K6 = (CASE dbo.OMHRS_SecK.K6 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    
    SectionKSignedOff = (CASE OMHRS_SecK.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionKSignedOff_Desc = (CASE OMHRS_SecK.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionKSignedOffCoder = LU_SignOffCoder_K.DisplayCode, SectionKSignedOffCoderDesc = LU_SignOffCoder_K.UserDescription, 
    SectionKSignedOffDate = OMHRS_SecK.SignDate, 

[    **** SECTION L ****] = '''',
    FormalCarePsychiatr_L1a = lu_L1a.DisplayCode, FormalCarePsychiatrDesc_L1a = lu_L1a.UserDescription, 
    FormalCareNursePrac_L1b = lu_L1b.DisplayCode, FormalCareNursePracDesc_L1b = lu_L1b.UserDescription, 
    FormalCareSocialWorker_L1c = lu_L1c.DisplayCode, FormalCareSocialWorkerDesc_L1c = lu_L1c.UserDescription, 
    FormalCarePsychologist_L1d = lu_L1d.DisplayCode, FormalCarePsychologistDesc_L1d = lu_L1d.UserDescription, 
    FormalCareOccupational_L1e = lu_L1e.DisplayCode, FormalCareOccupationalDesc_L1e = lu_L1e.UserDescription, 
    FormalCareRecreation_L1f = lu_L1f.DisplayCode, FormalCareRecreationDesc_L1f = lu_L1f.UserDescription, 
    FormalCareCousellor_L1g = lu_L1g.DisplayCode, FormalCareCousellorDesc_L1g = lu_L1g.UserDescription, 
    FormalCareDietician_L1h = lu_L1h.DisplayCode, FormalCareDieticianDesc_L1h = lu_L1h.UserDescription, 
    NursingMedicalInterv_L2a = lu_L2a.DisplayCode, NursingMedicalIntervDesc_L2a = lu_L2a.UserDescription, 
    NursingCounselling_L2b = lu_L2b.DisplayCode, NursingCounsellingDesc_L2b = lu_L2b.UserDescription, 
    NursingCrisisInterv_L2c = lu_L2c.DisplayCode, NursingCrisisIntervDesc_L2c = lu_L2c.UserDescription, 
    NursingFamilySupport_L2d = lu_L2d.DisplayCode, NursingFamilySupportDesc_L2d = lu_L2d.UserDescription, 
    TreatmentIndividTher_L3a = lu_L3a.DisplayCode, TreatmentIndividTherDesc_L3a = lu_L3a.UserDescription, 
    TreatmentGroupTherapy_L3b = lu_L3b.DisplayCode, TreatmentGroupTherapyDesc_L3b = lu_L3b.UserDescription, 
    TreatmentFamilyTher_L3c = lu_L3c.DisplayCode, TreatmentFamilyTherDesc_L3c = lu_L3c.UserDescription, 
    TreatmentSelfHelp_L3d = lu_L3d.DisplayCode, TreatmentSelfHelpDesc_L3d = lu_L3d.UserDescription, 
    FocusIntervCommunity_L4a = (CASE dbo.OMHRS_SecL.L4a WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    FocusIntervCommunityDesc_L4a = (CASE dbo.OMHRS_SecL.L4a WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200219 THEN LU_546_3.UserDescription ELSE '''' END), 
    FocusIntervSocial_L4b = (CASE dbo.OMHRS_SecL.L4b WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    FocusIntervSocialDesc_L4b = (CASE dbo.OMHRS_SecL.L4b WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200219 THEN LU_546_3.UserDescription ELSE '''' END), 
    FocusIntervPsych_L4c = (CASE dbo.OMHRS_SecL.L4c WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    FocusIntervPsychDesc_L4c = (CASE dbo.OMHRS_SecL.L4c WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200219 THEN LU_546_3.UserDescription ELSE '''' END), 
    FocusIntervDetoxific_L4d = (CASE dbo.OMHRS_SecL.L4d WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    FocusIntervDetoxificDesc_L4d = (CASE dbo.OMHRS_SecL.L4d WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200219 THEN LU_546_3.UserDescription ELSE '''' END), 
    FocusIntervAlcohol_L4e = (CASE dbo.OMHRS_SecL.L4e WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    FocusIntervAlcoholDesc_L4e = (CASE dbo.OMHRS_SecL.L4e WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200219 THEN LU_546_3.UserDescription ELSE '''' END), 
    FocusIntervVocational_L4f = (CASE dbo.OMHRS_SecL.L4f WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    FocusIntervVocationalDesc_L4f = (CASE dbo.OMHRS_SecL.L4f WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200219 THEN LU_546_3.UserDescription ELSE '''' END), 
    FocusIntervAngerMgmt_L4g = (CASE dbo.OMHRS_SecL.L4g WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    FocusIntervAngerMgmtDesc_L4g = (CASE dbo.OMHRS_SecL.L4g WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200219 THEN LU_546_3.UserDescription ELSE '''' END), 
    FocusIntervEatingDis_L4h = (CASE dbo.OMHRS_SecL.L4h WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    FocusIntervEatingDisDesc_L4h = (CASE dbo.OMHRS_SecL.L4h WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200219 THEN LU_546_3.UserDescription ELSE '''' END), 
    FocusIntervBehaviour_L4i = (CASE dbo.OMHRS_SecL.L4i WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    FocusIntervBehaviourDesc_L4i = (CASE dbo.OMHRS_SecL.L4i WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200219 THEN LU_546_3.UserDescription ELSE '''' END), 
    FocusIntervStress_L4j = (CASE dbo.OMHRS_SecL.L4j WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    FocusIntervStressDesc_L4j = (CASE dbo.OMHRS_SecL.L4j WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200219 THEN LU_546_3.UserDescription ELSE '''' END), 
    FocusIntervPainMgmt_L4k = (CASE dbo.OMHRS_SecL.L4k WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    FocusIntervPainMgmtDesc_L4k = (CASE dbo.OMHRS_SecL.L4k WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200219 THEN LU_546_3.UserDescription ELSE '''' END), 
    FocusInterveTherapy_L4l = (CASE dbo.OMHRS_SecL.L4l WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    FocusInterveTherapyDesc_L4l = (CASE dbo.OMHRS_SecL.L4l WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200219 THEN LU_546_3.UserDescription ELSE '''' END), 
    AdherenceTreatments_L5 = lu_L5.DisplayCode, AdherenceTreatmentsDesc_L5 = lu_L5.UserDescription, 
    ECT_L6 = lu_L6.DisplayCode, ECTDesc_L6 = lu_L6.UserDescription, 
    --PR - 04999 
    NumberOfECTs_X6 = OMHRS_SecA.X6, 

    SectionLSignedOff = (CASE OMHRS_SecL.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionLSignedOff_Desc = (CASE OMHRS_SecL.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionLSignedOffCoder = LU_SignOffCoder_L.DisplayCode, SectionLSignedOffCoderDesc = LU_SignOffCoder_L.UserDescription, 
    SectionLSignedOffDate = OMHRS_SecL.SignDate, 

[    **** SECTION M ****] = '''',
    MechanicalRestraint_M1a = lu_M1a.DisplayCode, MechanicalRestraintDesc_M1a = lu_M1a.UserDescription, 
    ChairPreventsRising_M1b = lu_M1b.DisplayCode, ChairPreventsRisingDesc_M1b = lu_M1b.UserDescription, 
    PhysicalRestraints_M1c = lu_M1c.DisplayCode, PhysicalRestraintsDesc_M1c = lu_M1c.UserDescription, 
    ConfinementToUnit_M1d = lu_M1d.DisplayCode, ConfinementToUnitDesc_M1d = lu_M1d.UserDescription, 
    ConfinementToRoom_M1e = lu_M1e.DisplayCode, ConfinementToRoomDesc_M1e = lu_M1e.UserDescription, 
    SeclusionRoom_M1f = lu_M1f.DisplayCode, SeclusionRoomDesc_M1f = lu_M1f.UserDescription, 
    Observation15Min_M2a = lu_M2a.DisplayCode, Observation15MinDesc_M2a = lu_M2a.UserDescription, 
    Observation5Min_M2b = lu_M2b.DisplayCode, Observation5MinDesc_M2b = lu_M2b.UserDescription, 
    ObservationLess1Hour_M2c = lu_M2c.DisplayCode, ObservationLess1HourDesc_M2c = lu_M2c.UserDescription, 
    ObservationMore1Hour_M2d = lu_M2d.DisplayCode, ObservationMore1HourDesc_M2d = lu_M2d.UserDescription,
    PyschICU_M3 = lu_M3.DisplayCode, PyschICUDesc_M3 = lu_M3.UserDescription, 
    AuthActOutFacWith_M4a = lu_M4a.DisplayCode, AuthActOutFacWithDesc_M4a = lu_M4a.UserDescription, 
    AuthActOutFacWithout_M4b = lu_M4b.DisplayCode, AuthActOutFacWithoutDesc_M4b = lu_M4b.UserDescription, 

    SectionMSignedOff = (CASE OMHRS_SecM.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionMSignedOff_Desc = (CASE OMHRS_SecM.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionMSignedOffCoder = LU_SignOffCoder_M.DisplayCode, SectionMSignedOffCoderDesc = LU_SignOffCoder_M.UserDescription, 
    SectionMSignedOffDate = OMHRS_SecM.SignDate, 

[    **** SECTION N ****] = '''',
    Height_N1a = OMHRS_SecN.N1a, 
    Weight_N1b = OMHRS_SecN.N1b, 
    WeightLoss_N2a = (CASE dbo.OMHRS_SecN.N2a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    WeightLossDesc_N2a = (CASE dbo.OMHRS_SecN.N2a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    WeightGain_N2b = (CASE dbo.OMHRS_SecN.N2b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    WeightGainDesc_N2b = (CASE dbo.OMHRS_SecN.N2b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    InsufficientFluid_N2c = (CASE dbo.OMHRS_SecN.N2c WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    InsufficientFluidDesc_N2c = (CASE dbo.OMHRS_SecN.N2c WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    DecreaseInFood_N2d = (CASE dbo.OMHRS_SecN.N2d WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    DecreaseInFoodDesc_N2d = (CASE dbo.OMHRS_SecN.N2d WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    BingeEating_N3a = (CASE dbo.OMHRS_SecN.N3a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    BingeEatingDesc_N3a = (CASE dbo.OMHRS_SecN.N3a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    FearWeightGain_N3b = (CASE dbo.OMHRS_SecN.N3b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    FearWeightGainDesc_N3b = (CASE dbo.OMHRS_SecN.N3b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    Fasting_N3c = (CASE dbo.OMHRS_SecN.N3c WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    FastingDesc_N3c = (CASE dbo.OMHRS_SecN.N3c WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    Polydipsia_N4 = (CASE dbo.OMHRS_SecN.N4 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    PolydipsiaDesc_N4 = (CASE dbo.OMHRS_SecN.N4 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 

    SectionNSignedOff = (CASE OMHRS_SecN.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionNSignedOff_Desc = (CASE OMHRS_SecN.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionNSignedOffCoder = LU_SignOffCoder_N.DisplayCode, SectionNSignedOffCoderDesc = LU_SignOffCoder_N.UserDescription, 
    SectionNSignedOffDate = OMHRS_SecN.SignDate, 

[    **** SECTION O ****] = '''',
    FamilyRoles_O1 = lu_O1.DisplayCode, FamilyRolesDesc_O1 = lu_O1.UserDescription, 
    NoConfidant_O2a = (CASE dbo.OMHRS_SecO.O2a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    NoConfidantDesc_O2a = (CASE dbo.OMHRS_SecO.O2a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    FamilyOverwhelmed_O2b = (CASE dbo.OMHRS_SecO.O2b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    FamilyOverwhelmedDesc_O2b = (CASE dbo.OMHRS_SecO.O2b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    PtHostileTowardFamily_O2c = (CASE dbo.OMHRS_SecO.O2c WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    PtHostileTowardFamilyDesc_O2c = (CASE dbo.OMHRS_SecO.O2c WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    PtHostileTowardPt_O2d = (CASE dbo.OMHRS_SecO.O2d WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    PtHostileTowardPtDesc_O2d = (CASE dbo.OMHRS_SecO.O2d WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    FamilyHostileTowardPt_O2e = (CASE dbo.OMHRS_SecO.O2e WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    FamilyHostileTowardPtDesc_O2e = (CASE dbo.OMHRS_SecO.O2e WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    StaffFrustrationPt_O2f = (CASE dbo.OMHRS_SecO.O2f WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    StaffFrustrationPtDesc_O2f = (CASE dbo.OMHRS_SecO.O2f WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    --PR - 04246
    FamilyReqUAmtofStaffT_O2g = (CASE dbo.OMHRS_SecO.O2g WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    FamilyReqUAmtofStaffTDesc_O2g = (CASE dbo.OMHRS_SecO.O2g WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    EmploymentStatus_O3 = lu_O3.DisplayCode, EmploymentStatusDesc_O3 = lu_O3.UserDescription, 
    IncreaseInLateness_O4a = lu_O4a.DisplayCode, IncreaseInLatenessDesc_O4a = lu_O4a.UserDescription, 
    PoorProductivity_O4b = lu_O4b.DisplayCode, PoorProductivityDesc_O4b = lu_O4b.UserDescription, 
    IntentToQuitWork_O4c = lu_O4c.DisplayCode, IntentToQuitWorkDesc_O4c = lu_O4c.UserDescription, 
    PersistentUnemploy_O4d = lu_O4d.DisplayCode, PersistentUnemployDesc_O4d = lu_O4d.UserDescription, 
    TradeOffs_O5 = (CASE dbo.OMHRS_SecO.O5 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    TradeOffsDesc_O5 = (CASE dbo.OMHRS_SecO.O5 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    ParticipateActivities_O6a = lu_O6a.DisplayCode, ParticipateActivitiesDesc_O6a = lu_O6a.UserDescription, 
    VisitByRelationFamily_O6b = lu_O6b.DisplayCode, VisitByRelationFamilyDesc_O6b = lu_O6b.UserDescription, 
    ContactRelationFamily_O6c = lu_O6c.DisplayCode, ContactRelationFamilyDesc_O6c = lu_O6c.UserDescription, 


    SectionOSignedOff = (CASE OMHRS_SecO.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionOSignedOff_Desc = (CASE OMHRS_SecO.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionOSignedOffCoder = LU_SignOffCoder_O.DisplayCode, SectionOSignedOffCoderDesc = LU_SignOffCoder_O.UserDescription, 
    SectionOSignedOffDate = OMHRS_SecO.SignDate, 

[    **** SECTION P ****] = '''',
    HelpWithChildcare_P1a = lu_P1a.DisplayCode, HelpWithChildcareDesc_P1a = lu_P1a.UserDescription, 
    SupervisePersonSafety_P1b = lu_P1b.DisplayCode, SupervisePersonSafetyDesc_P1b = lu_P1b.UserDescription, 
    CrisisSupport_P1c = lu_P1c.DisplayCode, CrisisSupportDesc_P1c = lu_P1c.UserDescription, 
    SupportWithADL_IADLs_P1d = lu_P1d.DisplayCode, SupportWithADL_IADLsDesc_P1d = lu_P1d.UserDescription, 
    PtExpressesReturnComm_P2a = lu_P2a.DisplayCode, PtExpressesReturnCommDesc_P2a = lu_P2a.UserDescription, 
    PtSupportDischarge_P2b = lu_P2b.DisplayCode, PtSupportDischargeDesc_P2b = lu_P2b.UserDescription, 
    --PR-02515 change TimePlannedDischarge_P3 to ProjTimePlannedDisch_P3
    ProjTimePlannedDisch_P3 = lu_P3.DisplayCode, ProjTimePlannedDischDesc_P3 = lu_P3.UserDescription, 
    OverallChangeCareNeeds_P4 = lu_P4.DisplayCode, OverallChangeCareNeedsDesc_P4 = lu_P4.UserDescription, 
    LivingArrangement_P5 = lu_P5.DisplayCode, LivingArrangementDesc_P5 = lu_P5.UserDescription, 
    DischargedToFacility_X140 = lu_X140.DisplayCode, DischargedToFacilityDesc_X140 = lu_X140.UserDescription, 

    DischargedSupportHomeCare_X141 = (CASE dbo.OMHRS_SecP.X141 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    DischargedSupportHomeCareDesc_X141 = (CASE dbo.OMHRS_SecP.X141 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 

    SectionPSignedOff = (CASE OMHRS_SecP.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionPSignedOff_Desc = (CASE OMHRS_SecP.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionPSignedOffCoder = LU_SignOffCoder_P.DisplayCode, SectionPSignedOffCoderDesc = LU_SignOffCoder_P.UserDescription, 
    SectionPSignedOffDate = OMHRS_SecP.SignDate, 

[    **** SECTION Q ****] = '''',
    DSMDisorderChildhood_Q1a = (CASE dbo.OMHRS_SecQ.Q1a WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSMDisorderChildhoodDesc_Q1a = (CASE dbo.OMHRS_SecQ.Q1a WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    DSMDeliriumDisorder_Q1b = (CASE dbo.OMHRS_SecQ.Q1b WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSMDeliriumDisorderDesc_Q1b = (CASE dbo.OMHRS_SecQ.Q1b WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    DSMMentalDisorder_Q1c = (CASE dbo.OMHRS_SecQ.Q1c WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSMMentalDisorderDesc_Q1c = (CASE dbo.OMHRS_SecQ.Q1c WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    DSMSubstanceRelated_Q1d = (CASE dbo.OMHRS_SecQ.Q1d WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSMSubstanceRelatedDesc_Q1d = (CASE dbo.OMHRS_SecQ.Q1d WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    DSMSchizophrenia_Q1e = (CASE dbo.OMHRS_SecQ.Q1e WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSMSchizophreniaDesc_Q1e = (CASE dbo.OMHRS_SecQ.Q1e WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    DSMMoodDisorder_Q1f = (CASE dbo.OMHRS_SecQ.Q1f WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSMMoodDisorderDesc_Q1f = (CASE dbo.OMHRS_SecQ.Q1f WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    DSMAnxietyDisorder_Q1g = (CASE dbo.OMHRS_SecQ.Q1g WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSMAnxietyDisorderDesc_Q1g = (CASE dbo.OMHRS_SecQ.Q1g WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    DSMSomatoformDisorder_Q1h = (CASE dbo.OMHRS_SecQ.Q1h WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSMSomatoformDisorderDesc_Q1h = (CASE dbo.OMHRS_SecQ.Q1h WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    DSMFactitiousDisorder_Q1i = (CASE dbo.OMHRS_SecQ.Q1i WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSMFactitiousDisorderDesc_Q1i = (CASE dbo.OMHRS_SecQ.Q1i WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    DSMDissociative_Q1j = (CASE dbo.OMHRS_SecQ.Q1j WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSMDissociativeDesc_Q1j = (CASE dbo.OMHRS_SecQ.Q1j WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    DSMSexualDisorder_Q1k = (CASE dbo.OMHRS_SecQ.Q1k WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSMSexualDisorderDesc_Q1k = (CASE dbo.OMHRS_SecQ.Q1k WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    DSMEatingDisorder_Q1l = (CASE dbo.OMHRS_SecQ.Q1l WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSMEatingDisorderDesc_Q1l = (CASE dbo.OMHRS_SecQ.Q1l WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    DSMSleepDisorder_Q1m = (CASE dbo.OMHRS_SecQ.Q1m WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSMSleepDisorderDesc_Q1m = (CASE dbo.OMHRS_SecQ.Q1m WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    DSMImpulseDisorder_Q1n = (CASE dbo.OMHRS_SecQ.Q1n WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSMImpulseDisorderDesc_Q1n = (CASE dbo.OMHRS_SecQ.Q1n WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    DSMAdjustmentDisorder_Q1o = (CASE dbo.OMHRS_SecQ.Q1o WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSMAdjustmentDisorderDesc_Q1o = (CASE dbo.OMHRS_SecQ.Q1o WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    DSMPersonalityDisorder_Q1p = (CASE dbo.OMHRS_SecQ.Q1p WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSMPersonalityDisorderDesc_Q1p = (CASE dbo.OMHRS_SecQ.Q1p WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    -- PR - 03738
    DSMNotApplicable_Q1q = (CASE dbo.OMHRS_SecQ.Q1q WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSMNotApplicableDesc_Q1q = (CASE dbo.OMHRS_SecQ.Q1q WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	--2.x-0295
	DSM_5_NeurodevelopmentalDisorders_Q1a = (CASE dbo.OMHRS_SecQ.Q1a2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_NeurodevelopmentalDisordersDesc_Q1a = (CASE dbo.OMHRS_SecQ.Q1a2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_SchizophreniaSpectrumDisorders_Q1b = (CASE dbo.OMHRS_SecQ.Q1b2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_SchizophreniaSpectrumDisordersDesc_Q1b = (CASE dbo.OMHRS_SecQ.Q1b2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_BipolarDisorders_Q1c = (CASE dbo.OMHRS_SecQ.Q1c2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_BipolarDisordersDesc_Q1c = (CASE dbo.OMHRS_SecQ.Q1c2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_DepressiveDisorders_Q1d = (CASE dbo.OMHRS_SecQ.Q1d2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_DepressiveDisordersDesc_Q1d = (CASE dbo.OMHRS_SecQ.Q1d2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_AnxietyDisorders_Q1e = (CASE dbo.OMHRS_SecQ.Q1e2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_AnxietyDisordersDesc_Q1e = (CASE dbo.OMHRS_SecQ.Q1e2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_ObsessiveCompulsiveDisorders_Q1f = (CASE dbo.OMHRS_SecQ.Q1f2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_ObsessiveCompulsiveDisordersDesc_Q1f = (CASE dbo.OMHRS_SecQ.Q1f2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_TraumaStressorDisorders_Q1g = (CASE dbo.OMHRS_SecQ.Q1g2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_TraumaStressorDisordersDesc_Q1g = (CASE dbo.OMHRS_SecQ.Q1g2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_DissociativetechDisorders_Q1h = (CASE dbo.OMHRS_SecQ.Q1h2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_DissociativeDisordersDesc_Q1h = (CASE dbo.OMHRS_SecQ.Q1h2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_SomaticSymptomDisorders_Q1i = (CASE dbo.OMHRS_SecQ.Q1i2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_SomaticSymptomDisordersDesc_Q1i = (CASE dbo.OMHRS_SecQ.Q1i2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_FeedingEatingDisorders_Q1j = (CASE dbo.OMHRS_SecQ.Q1j2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_FeedingEatingDisordersDesc_Q1j = (CASE dbo.OMHRS_SecQ.Q1j2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_EliminationDisorders_Q1k = (CASE dbo.OMHRS_SecQ.Q1k2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_EliminationDisordersDesc_Q1k = (CASE dbo.OMHRS_SecQ.Q1k2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_SleepWakeDisorders_Q1l = (CASE dbo.OMHRS_SecQ.Q1l2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_SleepWakeDisordersDesc_Q1l = (CASE dbo.OMHRS_SecQ.Q1l2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_SexualDysfunctions_Q1m = (CASE dbo.OMHRS_SecQ.Q1m2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_SexualDysfunctionsDesc_Q1m = (CASE dbo.OMHRS_SecQ.Q1m2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_GenderDysphoria_Q1n = (CASE dbo.OMHRS_SecQ.Q1n2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_GenderDysphoriaDesc_Q1n = (CASE dbo.OMHRS_SecQ.Q1n2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_DisruptiveDisorders_Q1o = (CASE dbo.OMHRS_SecQ.Q1o2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_DisruptiveDisordersDesc_Q1o = (CASE dbo.OMHRS_SecQ.Q1o2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_SubstanceAddictiveDisorders_Q1p = (CASE dbo.OMHRS_SecQ.Q1p2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_SubstanceAddictiveDisordersDesc_Q1p = (CASE dbo.OMHRS_SecQ.Q1p2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_NeurocognitiveDisorders_Q1q = (CASE dbo.OMHRS_SecQ.Q1q2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_NeurocognitiveDisordersDesc_Q1q = (CASE dbo.OMHRS_SecQ.Q1q2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_PersonalityDisorders_Q1r = (CASE dbo.OMHRS_SecQ.Q1r2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_PersonalityDisordersDesc_Q1r = (CASE dbo.OMHRS_SecQ.Q1r2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_ParaphilicDisorders_Q1s = (CASE dbo.OMHRS_SecQ.Q1s2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_ParaphilicDisordersDesc_Q1s = (CASE dbo.OMHRS_SecQ.Q1s2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_OtherMentalDisorders_Q1t = (CASE dbo.OMHRS_SecQ.Q1t2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_OtherMentalDisordersDesc_Q1t = (CASE dbo.OMHRS_SecQ.Q1t2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_MedicationInducedDisorders_Q1u = (CASE dbo.OMHRS_SecQ.Q1u2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_MedicationInducedDisordersDesc_Q1u = (CASE dbo.OMHRS_SecQ.Q1u2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	DSM_5_NotApplicable_Q1v = (CASE dbo.OMHRS_SecQ.Q1v2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    DSM_5_NotApplicableDesc_Q1v = (CASE dbo.OMHRS_SecQ.Q1v2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 

    --ED - 02279 Move to view OMHRS_DSM_Diag_AxisII_VR
    --AxisII_DSM_IVCode_Q2d = lu_Q2d.DisplayCode, AxisII_DSM_IVCodeDesc_Q2d = lu_Q2d.UserDescription, 
    --AxisII_DSM_IVText = OMHRS_SecQ.Q2dText, 
    --ED - 02156
    PrimaryDiagnosis_X7 = LU_X7.DisplayCode, PrimaryDiagnosisDesc_X7 = LU_X7.UserDescription, 

    IntellectualDisability_Q3 = (CASE dbo.OMHRS_SecQ.Q3 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    IntellectualDisabilityDesc_Q3 = (CASE dbo.OMHRS_SecQ.Q3 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    GAFScore_Q4 = OMHRS_SecQ.Q4, 
    CurrentPatientType_Q5 = lu_Q5.DisplayCode, CurrentPatientTypeDesc_Q5 = lu_Q5.UserDescription, 

    SectionQSignedOff = (CASE OMHRS_SecQ.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionQSignedOff_Desc = (CASE OMHRS_SecQ.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionQSignedOffCoder = LU_SignOffCoder_Q.DisplayCode, SectionQSignedOffCoderDesc = LU_SignOffCoder_Q.UserDescription, 
    SectionQSignedOffDate = OMHRS_SecQ.SignDate, 

[    **** SECTION R ****] = '''',
    PrescribedMedications_R1 = (CASE dbo.OMHRS_Secr.R1 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    PrescribedMedicationsDesc_R1 = (CASE dbo.OMHRS_SecR.R1 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 

    SectionRSignedOff = (CASE OMHRS_SecR.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionRSignedOff_Desc = (CASE OMHRS_SecR.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionRSignedOffCoder = LU_SignOffCoder_R.DisplayCode, SectionRSignedOffCoderDesc = LU_SignOffCoder_R.UserDescription, 
    SectionRSignedOffDate = OMHRS_SecR.SignDate, 

[    **** SECTION S ****] = '''',
    TotalDaysAlternativeLevel_X75 = OMHRS_SecS.X75, 
    DischargeDate_X80 = OMHRS_SecS.X80, 
    DischargeTime = OMHRS_SecS.DischargeTime, 

    AdmittedThroughEmergency_X8a = (CASE OMHRS_SecS.X8a WHEN 302111 THEN LU_606_0.DisplayCode WHEN 302112 THEN LU_606_1.DisplayCode ELSE '''' END), 
    AdmittedThroughEmergencyDesc_X8a = (CASE OMHRS_SecS.X8a WHEN 302111 THEN LU_606_0.UserDescription WHEN 302112 THEN LU_606_1.UserDescription ELSE '''' END), 
    ArrivedOnInpatientUnit_X8b = (CASE OMHRS_SecS.X8b WHEN 302111 THEN LU_606_0.DisplayCode WHEN 302112 THEN LU_606_1.DisplayCode ELSE '''' END), 
    ArrivedOnInpatientUnitDesc_X8b = (CASE OMHRS_SecS.X8b WHEN 302111 THEN LU_606_0.UserDescription WHEN 302112 THEN LU_606_1.UserDescription ELSE '''' END), 
    DateArrivedOnInpatientUnit_X8c = OMHRS_SecS.X8c, 

    DischargeReason_X90 = lu_X90.DisplayCode, DischargeReasonDesc_X90 = lu_X90.UserDescription, 
    
    ServiceInterruptAcute_X121a = (CASE OMHRS_SecS.X121a WHEN 302101 THEN LU_605_0.DisplayCode WHEN 302102 THEN LU_605_1.DisplayCode ELSE '''' END), 
    ServiceInterruptAcuteDesc_X121a = (CASE OMHRS_SecS.X121a WHEN 302101 THEN LU_605_0.UserDescription WHEN 302102 THEN LU_605_1.UserDescription ELSE '''' END), 
    ServiceInterruptRehab_X121b = (CASE OMHRS_SecS.X121b WHEN 302101 THEN LU_605_0.DisplayCode WHEN 302102 THEN LU_605_1.DisplayCode ELSE '''' END), 
    ServiceInterruptRehabDesc_X121b = (CASE OMHRS_SecS.X121b WHEN 302101 THEN LU_605_0.UserDescription WHEN 302102 THEN LU_605_1.UserDescription ELSE '''' END), 
    ServiceInterruptLTC_X121c = (CASE OMHRS_SecS.X121c WHEN 302101 THEN LU_605_0.DisplayCode WHEN 302102 THEN LU_605_1.DisplayCode ELSE '''' END), 
    ServiceInterruptLTCDesc_X121c = (CASE OMHRS_SecS.X121c WHEN 302101 THEN LU_605_0.UserDescription WHEN 302102 THEN LU_605_1.UserDescription ELSE '''' END), 
    ServiceInterruptMH_X121d = (CASE OMHRS_SecS.X121d WHEN 302101 THEN LU_605_0.DisplayCode WHEN 302102 THEN LU_605_1.DisplayCode ELSE '''' END), 
    ServiceInterruptMHDesc_X121d = (CASE OMHRS_SecS.X121d WHEN 302101 THEN LU_605_0.UserDescription WHEN 302102 THEN LU_605_1.UserDescription ELSE '''' END), 
    ServiceInterruptCorrectional_X121e = (CASE OMHRS_SecS.X121e WHEN 302101 THEN LU_605_0.DisplayCode WHEN 302102 THEN LU_605_1.DisplayCode ELSE '''' END), 
    ServiceInterruptCorrectionalDesc_X121e = (CASE OMHRS_SecS.X121e WHEN 302101 THEN LU_605_0.UserDescription WHEN 302102 THEN LU_605_1.UserDescription ELSE '''' END), 
    ServiceInterruptAWOL30_X121f = (CASE OMHRS_SecS.X121f WHEN 302101 THEN LU_605_0.DisplayCode WHEN 302102 THEN LU_605_1.DisplayCode ELSE '''' END), 
    ServiceInterruptAWOL30Desc_X121f = (CASE OMHRS_SecS.X121f WHEN 302101 THEN LU_605_0.UserDescription WHEN 302102 THEN LU_605_1.UserDescription ELSE '''' END), 
    ServiceInterruptLOA90_X121g = (CASE OMHRS_SecS.X121g WHEN 302101 THEN LU_605_0.DisplayCode WHEN 302102 THEN LU_605_1.DisplayCode ELSE '''' END), 
    ServiceInterruptLOA90Desc_X121g = (CASE OMHRS_SecS.X121g WHEN 302101 THEN LU_605_0.UserDescription WHEN 302102 THEN LU_605_1.UserDescription ELSE '''' END), 
    ServiceInterruptOther_X121h = (CASE OMHRS_SecS.X121h WHEN 302101 THEN LU_605_0.DisplayCode WHEN 302102 THEN LU_605_1.DisplayCode ELSE '''' END), 
    ServiceInterruptOtherDesc_X121h = (CASE OMHRS_SecS.X121h WHEN 302101 THEN LU_605_0.UserDescription WHEN 302102 THEN LU_605_1.UserDescription ELSE '''' END), 

    TotalDaysAwayFromBed_X130 = OMHRS_SecS.X130, 
    TotalDaysAwayFromBedInQ4_X131 = OMHRS_SecS.X131, 
    TotalServiceInterruptions_X150 = OMHRS_SecS.X150, 
    TotalServiceInterruptionsInQ4_X151 = OMHRS_SecS.X151, 

    SectionSSignedOff = (CASE OMHRS_SecS.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.DisplayCode ELSE '''' END), 
    SectionSSignedOff_Desc = (CASE OMHRS_SecS.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionSSignedOffCoder = LU_SignOffCoder_S.DisplayCode, SectionSSignedOffCoderDesc = LU_SignOffCoder_S.UserDescription, 
    SectionSSignedOffDate = OMHRS_SecS.SignDate, 
    
[    **** SECTION X ****] = '''',
    RecordID_X1 = OMHRS_SecAA.X1, 
    SubmissionType_X2 = lu_X2.DisplayCode, 
    SubmissionTypeDesc_X2 = lu_X2.UserDescription, 
    RecordType_Z1 = lu_z1.DisplayCode, RecordTypeDesc_Z1 = lu_z1.UserDescription, 

----------------------------------
[    **** SECTION Outcome Scales ****] = '''',
    --ED - 01914
    AggressiveBehaviourScale_ABS = dbo.OMHRS_OutcomeScale.[ABS],
    CognitivePerformanceScale_CPS = dbo.OMHRS_OutcomeScale.CPS,
    DepressionRatingScale_DRS = dbo.OMHRS_OutcomeScale.DRS,
    ActivityDailyLivSelfPerformHierachy_ADLH = dbo.OMHRS_OutcomeScale.ADL_H,
    ActivityDailyLiviShortForm_ADLS = dbo.OMHRS_OutcomeScale.ADL_S,
    DepressiveSeverityIndex_DSI = dbo.OMHRS_OutcomeScale.DSI,
    RiskOfHarmToOthersScale_RHO = dbo.OMHRS_OutcomeScale.RHO,
    SelfCareIndex_SCI = dbo.OMHRS_OutcomeScale.SCI,
    SeverityOfSelfHarmScale_SOS = dbo.OMHRS_OutcomeScale.SOS,

[    **** SECTION CAPs ****] = '''',
    --ED - 02373
    HarmToOthers_HARMMOTH = OMHRS_CAPs.HARMOTH,
    SuicidalityAndPurposefulSelfHarm_SELFHARM = OMHRS_CAPs.SELFHARM,
    SelfCare_SELFCR = OMHRS_CAPs.SELFCR,
    SocialRelationships_SOCREL = OMHRS_CAPs.SOCREL,
    SupportSystemsForDischarge_SSDIS = OMHRS_CAPs.SSDIS,
    InterpersonalConflict_IPCON = OMHRS_CAPs.IPCON,
    TraumaticLifeEvents_TRAUMA = OMHRS_CAPs.TRAUMA,
    CriminalActivity_CRIM = OMHRS_CAPs.CRIM,
    FinancialIssues_FINAN = OMHRS_CAPs.FINAN,
    VocationalRehabilitation_VOCREH = OMHRS_CAPs.VOCREH,
    ControlInterventions_CTRLINT = OMHRS_CAPs.CTRLINT,
    MedicationManagementAndAdherence_MEDMGT = OMHRS_CAPs.MEDMGT,
    Rehospitalization_REHOSP = OMHRS_CAPs.REHOSP,
    TobaccoUse_TOBUSE = OMHRS_CAPs.TOBUSE,
    SubstanceUse_SUBUSE = OMHRS_CAPs.SUBUSE,
    WeightManagement_WTMGT = OMHRS_CAPs.WTMGT,
    Exercise_EXER = OMHRS_CAPs.EXER,
    SleepDisturbance_SLEEP = OMHRS_CAPs.SLEEP,
    Pain_PAIN = OMHRS_CAPs.PAIN,
    Falls_FALLS = OMHRS_CAPs.FALLS,

[    **** SECTION Others ****] = '''',
    AgeCode = lu_AgeCode.DisplayCode, AgeCodeDesc = lu_AgeCode.UserDescription, AgeNumber = dbo.OMHRS_SecBB.AgeNumber, 
    dbo.OMHRS_SecAA.HospitalAccountRecord,
    LOSDays = dbo.OMHRS_SecA.LOSDays, LOSTotal = dbo.OMHRS_SecA.LOSTotal, 
    
    -- PR - 02377
    MISCode = LU_MISCode.DisplayCode, MISCodeDesc = LU_MISCode.UserDescription, 
    ActualNextAssessmentDate = OMHRS_SecA.ActualNextAssessdate, 
    NextAssessDate = OMHRS_SecA.NextAssessDate, 
    NursingArea = LU_AdmitNurse.DisplayCode, NursingAreaDesc = LU_AdmitNurse.UserDescription, 
    ReferringProvider = LU_RefProvider.DisplayCode, ReferringProviderDesc = LU_RefProvider.UserDescription, 
    dbo.OMHRS_SecAA.RegisterNumber,
    ResidenceCode = LU_ResidenceCode.DisplayCode, ResidenceCodeDesc = LU_ResidenceCode.UserDescription, 
    ResidenceProvince = LU_ResidenceProvince.DisplayCode, ResidenceProvinceDesc = LU_ResidenceProvince.UserDescription, 
    ResidenceRegion = LUResidenceRegion.DisplayCode, ResidenceRegionDesc = LUResidenceRegion.UserDescription, 
    SecondChartRegisterNumber = dbo.OMHRS_SecAA.SecondChartRegNumber,
	dbo.OMHRS_SecAA.UniversalEpisodeIdentifier,
    zzAbstractLinkID = OMHRS_SecAA.AbstractID, zzAbstractAdmitLinkID = LinkID
FROM         
    OMHRS_SecAA with (nolock) LEFT JOIN
    lu_CodeFile lu_Z1 with (nolock) on OMHRS_SecAA.Z1 = lu_Z1.Code LEFT JOIN
    lu_CodeFile lu_X2 with (nolock) on OMHRS_SecAA.X2 = lu_X2.Code LEFT JOIN
    lu_CodeFile lu_X10 with (nolock) on OMHRS_SecAA.X10 = lu_X10.Code LEFT JOIN
    LU_HCNProvince with (nolock) on OMHRS_SecAA.HCNProvince = LU_HCNProvince.Code LEFT JOIN
    H_InstitutionProfile with (nolock) on OMHRS_SecAA.InstitutionNumber = H_InstitutionProfile.Code LEFT JOIN
    lu_CodeFile lu_AA5 with (nolock) on OMHRS_SecAA.AA5 = lu_AA5.Code LEFT JOIN
    U_Users LU_SignOffCoder_AA with (nolock) on OMHRS_SecAA.SignCoder = LU_SignOffCoder_AA.Code LEFT JOIN
    U_Users LU_SignOffCoder_T with (nolock) on OMHRS_SecAA.ASignCoder = LU_SignOffCoder_T.Code LEFT JOIN
    OMHRS_SecA with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecA.AbstractID LEFT JOIN
    lu_CodeFile lu_A2 with (nolock) on OMHRS_SecA.A2 = lu_A2.Code LEFT JOIN
    lu_CodeFile lu_A3 with (nolock) on OMHRS_SecA.A3 = lu_A3.Code LEFT JOIN
    lu_CodeFile lu_A5a with (nolock) on OMHRS_SecA.A5a = lu_A5a.Code LEFT JOIN
    lu_CodeFile lu_A5b with (nolock) on OMHRS_SecA.A5b = lu_A5b.Code LEFT JOIN
    U_Users LU_SignOffCoder_A with (nolock) on OMHRS_SecA.SignCoder = LU_SignOffCoder_A.Code LEFT JOIN
    dbo.OMHRS_SecB with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecB.AbstractID LEFT JOIN
    lu_CodeFile lu_B2 with (nolock) on OMHRS_SecB.B2 = lu_B2.Code LEFT JOIN
    U_Users LU_SignOffCoder_B with (nolock) on OMHRS_SecB.SignCoder = LU_SignOffCoder_B.Code LEFT JOIN
    dbo.OMHRS_SecBB with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecBB.AbstractID LEFT JOIN
    lu_CodeFile lu_BB1 with (nolock) on OMHRS_SecBB.BB1 = lu_BB1.Code LEFT JOIN
    lu_CodeFile lu_BB3 with (nolock) on OMHRS_SecBB.BB3 = lu_BB3.Code LEFT JOIN
    lu_CodeFile lu_BB4 with (nolock) on OMHRS_SecBB.BB4 = lu_BB4.Code LEFT JOIN
    lu_CodeFile lu_BB5 with (nolock) on OMHRS_SecBB.BB5 = lu_BB5.Code LEFT JOIN
    LU_AgeCode with (nolock) on OMHRS_SecBB.AgeCode = LU_AgeCode.Code LEFT JOIN
    U_Users LU_SignOffCoder_BB with (nolock) on OMHRS_SecBB.SignCoder = LU_SignOffCoder_BB.Code LEFT JOIN
    dbo.OMHRS_SecC with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecC.AbstractID LEFT JOIN
    lu_CodeFile lu_C1 with (nolock) on OMHRS_SecC.C1 = lu_C1.Code LEFT JOIN
    lu_CodeFile lu_C2a with (nolock) on OMHRS_SecC.C2a = lu_C2a.Code LEFT JOIN
    lu_CodeFile lu_C2b with (nolock) on OMHRS_SecC.C2b = lu_C2b.Code LEFT JOIN
    lu_CodeFile lu_C2c with (nolock) on OMHRS_SecC.C2c = lu_C2c.Code LEFT JOIN
    lu_CodeFile lu_C2d with (nolock) on OMHRS_SecC.C2d = lu_C2d.Code LEFT JOIN
    lu_CodeFile lu_C2e with (nolock) on OMHRS_SecC.C2e = lu_C2e.Code LEFT JOIN
    lu_CodeFile lu_C2f with (nolock) on OMHRS_SecC.C2f = lu_C2f.Code LEFT JOIN
    lu_CodeFile lu_C3 with (nolock) on OMHRS_SecC.C3 = lu_C3.Code LEFT JOIN
    lu_CodeFile lu_C5 with (nolock) on OMHRS_SecC.C5 = lu_C5.Code LEFT JOIN
    U_Users LU_SignOffCoder_C with (nolock) on OMHRS_SecC.SignCoder = LU_SignOffCoder_C.Code LEFT JOIN
    dbo.OMHRS_SecCC with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecCC.AbstractID LEFT JOIN
    LU_ResidenceCode with (nolock) on OMHRS_SecCC.ResidenceCode = LU_ResidenceCode.Code LEFT JOIN
    LU_Region LUResidenceRegion with (nolock) on LU_ResidenceCode.RegionCode = LUResidenceRegion.Code LEFT JOIN
    LU_Province LU_ResidenceProvince with (nolock) on LU_ResidenceCode.ProvinceCode = LU_ResidenceProvince.Code LEFT JOIN
    lu_CodeFile lu_CC3 with (nolock) on OMHRS_SecCC.CC3 = lu_CC3.Code LEFT JOIN
    lu_CodeFile lu_CC4 with (nolock) on OMHRS_SecCC.CC4 = lu_CC4.Code LEFT JOIN
    --lu_CodeFile lu_CC5 with (nolock) on OMHRS_SecCC.CC5 = lu_CC5.Code LEFT JOIN
    LU_Institution_10 lu_X65 with (nolock) on OMHRS_SecCC.X65 = lu_X65.Code LEFT JOIN
    U_Users LU_SignOffCoder_CC with (nolock) on OMHRS_SecCC.SignCoder = LU_SignOffCoder_CC.Code LEFT JOIN
    dbo.OMHRS_SecD with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecD.AbstractID LEFT JOIN
    lu_CodeFile lu_D1a with (nolock) on OMHRS_SecD.D1a = lu_D1a.Code LEFT JOIN
    lu_CodeFile lu_D1b with (nolock) on OMHRS_SecD.D1b = lu_D1b.Code LEFT JOIN
    lu_CodeFile lu_D1c with (nolock) on OMHRS_SecD.D1c = lu_D1c.Code LEFT JOIN
    lu_CodeFile lu_D1d with (nolock) on OMHRS_SecD.D1d = lu_D1d.Code LEFT JOIN
    lu_CodeFile lu_D2a with (nolock) on OMHRS_SecD.D2a = lu_D2a.Code LEFT JOIN
    lu_CodeFile lu_D2b with (nolock) on OMHRS_SecD.D2b = lu_D2b.Code LEFT JOIN
    lu_CodeFile lu_D2c with (nolock) on OMHRS_SecD.D2c = lu_D2c.Code LEFT JOIN
    U_Users LU_SignOffCoder_D with (nolock) on OMHRS_SecD.SignCoder = LU_SignOffCoder_D.Code LEFT JOIN
    dbo.OMHRS_SecDD with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecDD.AbstractID LEFT JOIN
    lu_CodeFile lu_DD1 with (nolock) on OMHRS_SecDD.DD1 = lu_DD1.Code LEFT JOIN
    lu_CodeFile lu_DD2 with (nolock) on OMHRS_SecDD.DD2 = lu_DD2.Code LEFT JOIN
    lu_CodeFile lu_DD3 with (nolock) on OMHRS_SecDD.DD3 = lu_DD3.Code LEFT JOIN
    lu_CodeFile lu_DD4 with (nolock) on OMHRS_SecDD.DD4 = lu_DD4.Code LEFT JOIN
    lu_CodeFile lu_DD5 with (nolock) on OMHRS_SecDD.DD5 = lu_DD5.Code LEFT JOIN
    lu_CodeFile lu_DD6 with (nolock) on OMHRS_SecDD.DD6 = lu_DD6.Code LEFT JOIN
    U_Users LU_SignOffCoder_DD with (nolock) on OMHRS_SecDD.SignCoder = LU_SignOffCoder_DD.Code LEFT JOIN
    dbo.OMHRS_SecE with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecE.AbstractID LEFT JOIN
    lu_CodeFile lu_E1a with (nolock) on OMHRS_SecE.E1a = lu_E1a.Code LEFT JOIN
    lu_CodeFile lu_E1b with (nolock) on OMHRS_SecE.E1b = lu_E1b.Code LEFT JOIN
    lu_CodeFile lu_E1c with (nolock) on OMHRS_SecE.E1c = lu_E1c.Code LEFT JOIN
    lu_CodeFile lu_E1d with (nolock) on OMHRS_SecE.E1d = lu_E1d.Code LEFT JOIN
    lu_CodeFile lu_E1e with (nolock) on OMHRS_SecE.E1e = lu_E1e.Code LEFT JOIN
    lu_CodeFile lu_E1f with (nolock) on OMHRS_SecE.E1f = lu_E1f.Code LEFT JOIN
    lu_CodeFile lu_E1g with (nolock) on OMHRS_SecE.E1g = lu_E1g.Code LEFT JOIN
    lu_CodeFile lu_E2 with (nolock) on OMHRS_SecE.E2 = lu_E2.Code LEFT JOIN
    U_Users LU_SignOffCoder_E with (nolock) on OMHRS_SecE.SignCoder = LU_SignOffCoder_E.Code LEFT JOIN
    dbo.OMHRS_SecF with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecF.AbstractID LEFT JOIN
    lu_CodeFile lu_F1a with (nolock) on OMHRS_SecF.F1a = lu_F1a.Code LEFT JOIN
    lu_CodeFile lu_F1b with (nolock) on OMHRS_SecF.F1b = lu_F1b.Code LEFT JOIN
    lu_CodeFile lu_F2 with (nolock) on OMHRS_SecF.F2 = lu_F2.Code LEFT JOIN
    lu_CodeFile lu_F3a with (nolock) on OMHRS_SecF.F3a = lu_F3a.Code LEFT JOIN
    lu_CodeFile lu_F3b with (nolock) on OMHRS_SecF.F3b = lu_F3b.Code LEFT JOIN
    lu_CodeFile lu_F3c with (nolock) on OMHRS_SecF.F3c = lu_F3c.Code LEFT JOIN
    lu_CodeFile lu_F3d with (nolock) on OMHRS_SecF.F3d = lu_F3d.Code LEFT JOIN
    lu_CodeFile lu_F3e with (nolock) on OMHRS_SecF.F3e = lu_F3e.Code LEFT JOIN
    lu_CodeFile lu_F3f with (nolock) on OMHRS_SecF.F3f = lu_F3f.Code LEFT JOIN
    lu_CodeFile lu_F4 with (nolock) on OMHRS_SecF.F4 = lu_F4.Code LEFT JOIN
    
    U_Users LU_SignOffCoder_F with (nolock) on OMHRS_SecF.SignCoder = LU_SignOffCoder_F.Code LEFT JOIN
    dbo.OMHRS_SecG with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecG.AbstractID LEFT JOIN
    lu_CodeFile lu_G1a with (nolock) on OMHRS_SecG.G1a = lu_G1a.Code LEFT JOIN
    lu_CodeFile lu_G1b with (nolock) on OMHRS_SecG.G1b = lu_G1b.Code LEFT JOIN
    lu_CodeFile lu_G1c with (nolock) on OMHRS_SecG.G1c = lu_G1c.Code LEFT JOIN
    lu_CodeFile lu_G1d with (nolock) on OMHRS_SecG.G1d = lu_G1d.Code LEFT JOIN
    lu_CodeFile lu_G1e with (nolock) on OMHRS_SecG.G1e = lu_G1e.Code LEFT JOIN
    lu_CodeFile lu_G2a with (nolock) on OMHRS_SecG.G2a = lu_G2a.Code LEFT JOIN
    lu_CodeFile lu_G2b with (nolock) on OMHRS_SecG.G2b = lu_G2b.Code LEFT JOIN
    lu_CodeFile lu_G2c with (nolock) on OMHRS_SecG.G2c = lu_G2c.Code LEFT JOIN
    lu_CodeFile lu_G2d with (nolock) on OMHRS_SecG.G2d = lu_G2d.Code LEFT JOIN
    lu_CodeFile lu_G2e with (nolock) on OMHRS_SecG.G2e = lu_G2e.Code LEFT JOIN
    lu_CodeFile lu_G3 with (nolock) on OMHRS_SecG.G3 = lu_G3.Code LEFT JOIN
    U_Users LU_SignOffCoder_G with (nolock) on OMHRS_SecG.SignCoder = LU_SignOffCoder_G.Code LEFT JOIN
    dbo.OMHRS_SecH with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecH.AbstractID LEFT JOIN
    lu_CodeFile lu_H1 with (nolock) on OMHRS_SecH.H1 = lu_H1.Code LEFT JOIN
    lu_CodeFile lu_H2 with (nolock) on OMHRS_SecH.H2 = lu_H2.Code LEFT JOIN
    lu_CodeFile lu_H3 with (nolock) on OMHRS_SecH.H3 = lu_H3.Code LEFT JOIN
    U_Users LU_SignOffCoder_H with (nolock) on OMHRS_SecH.SignCoder = LU_SignOffCoder_H.Code LEFT JOIN
    dbo.OMHRS_SecI with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecI.AbstractID LEFT JOIN
    lu_CodeFile lu_I4 with (nolock) on OMHRS_SecI.I4 = lu_I4.Code LEFT JOIN
    lu_CodeFile lu_I6b with (nolock) on OMHRS_SecI.I6b = lu_I6b.Code LEFT JOIN
    lu_CodeFile lu_I8a with (nolock) on OMHRS_SecI.I8a = lu_I8a.Code LEFT JOIN
    lu_CodeFile lu_I8b with (nolock) on OMHRS_SecI.I8b = lu_I8b.Code LEFT JOIN
    lu_CodeFile lu_I9 with (nolock) on OMHRS_SecI.I9 = lu_I9.Code LEFT JOIN
    lu_CodeFile lu_I10 with (nolock) on OMHRS_SecI.I10 = lu_I10.Code LEFT JOIN
    U_Users LU_SignOffCoder_I with (nolock) on OMHRS_SecI.SignCoder = LU_SignOffCoder_I.Code LEFT JOIN
    dbo.OMHRS_SecJ with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecJ.AbstractID LEFT JOIN
    U_Users LU_SignOffCoder_J with (nolock) on OMHRS_SecJ.SignCoder = LU_SignOffCoder_J.Code LEFT JOIN
    dbo.OMHRS_SecK with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecK.AbstractID LEFT JOIN
    lu_CodeFile lu_K1 with (nolock) on OMHRS_SecK.K1 = lu_K1.Code LEFT JOIN
    lu_CodeFile lu_K3 with (nolock) on OMHRS_SecK.K3 = lu_K3.Code LEFT JOIN
    U_Users LU_SignOffCoder_K with (nolock) on OMHRS_SecK.SignCoder = LU_SignOffCoder_K.Code LEFT JOIN
    
    dbo.OMHRS_SecL with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecL.AbstractID LEFT JOIN
    lu_CodeFile lu_L1a with (nolock) on OMHRS_SecL.L1a = lu_L1a.Code LEFT JOIN
    lu_CodeFile lu_L1b with (nolock) on OMHRS_SecL.L1b = lu_L1b.Code LEFT JOIN
    lu_CodeFile lu_L1c with (nolock) on OMHRS_SecL.L1c = lu_L1c.Code LEFT JOIN
    lu_CodeFile lu_L1d with (nolock) on OMHRS_SecL.L1d = lu_L1d.Code LEFT JOIN
    lu_CodeFile lu_L1e with (nolock) on OMHRS_SecL.L1e = lu_L1e.Code LEFT JOIN
    lu_CodeFile lu_L1f with (nolock) on OMHRS_SecL.L1f = lu_L1f.Code LEFT JOIN
    lu_CodeFile lu_L1g with (nolock) on OMHRS_SecL.L1g = lu_L1g.Code LEFT JOIN
    lu_CodeFile lu_L1h with (nolock) on OMHRS_SecL.L1h = lu_L1h.Code LEFT JOIN
    lu_CodeFile lu_L2a with (nolock) on OMHRS_SecL.L2a = lu_L2a.Code LEFT JOIN
    lu_CodeFile lu_L2b with (nolock) on OMHRS_SecL.L2b = lu_L2b.Code LEFT JOIN
    lu_CodeFile lu_L2c with (nolock) on OMHRS_SecL.L2c = lu_L2c.Code LEFT JOIN
    lu_CodeFile lu_L2d with (nolock) on OMHRS_SecL.L2d = lu_L2d.Code LEFT JOIN
    lu_CodeFile lu_L3a with (nolock) on OMHRS_SecL.L3a = lu_L3a.Code LEFT JOIN
    lu_CodeFile lu_L3b with (nolock) on OMHRS_SecL.L3b = lu_L3b.Code LEFT JOIN
    lu_CodeFile lu_L3c with (nolock) on OMHRS_SecL.L3c = lu_L3c.Code LEFT JOIN
    lu_CodeFile lu_L3d with (nolock) on OMHRS_SecL.L3d = lu_L3d.Code LEFT JOIN
    lu_CodeFile lu_L5 with (nolock) on OMHRS_SecL.L5 = lu_L5.Code LEFT JOIN
    lu_CodeFile lu_L6 with (nolock) on OMHRS_SecL.L6 = lu_L6.Code LEFT JOIN
    U_Users LU_SignOffCoder_L with (nolock) on OMHRS_SecL.SignCoder = LU_SignOffCoder_L.Code LEFT JOIN
    dbo.OMHRS_SecM with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecM.AbstractID LEFT JOIN
    lu_CodeFile lu_M1a with (nolock) on OMHRS_SecM.M1a = lu_M1a.Code LEFT JOIN
    lu_CodeFile lu_M1b with (nolock) on OMHRS_SecM.M1b = lu_M1b.Code LEFT JOIN
    lu_CodeFile lu_M1c with (nolock) on OMHRS_SecM.M1c = lu_M1c.Code LEFT JOIN
    lu_CodeFile lu_M1d with (nolock) on OMHRS_SecM.M1d = lu_M1d.Code LEFT JOIN
    lu_CodeFile lu_M1e with (nolock) on OMHRS_SecM.M1e = lu_M1e.Code LEFT JOIN
    lu_CodeFile lu_M1f with (nolock) on OMHRS_SecM.M1f = lu_M1f.Code LEFT JOIN
    lu_CodeFile lu_M2a with (nolock) on OMHRS_SecM.M2a = lu_M2a.Code LEFT JOIN
    lu_CodeFile lu_M2b with (nolock) on OMHRS_SecM.M2b = lu_M2b.Code LEFT JOIN
    lu_CodeFile lu_M2c with (nolock) on OMHRS_SecM.M2c = lu_M2c.Code LEFT JOIN
    lu_CodeFile lu_M2d with (nolock) on OMHRS_SecM.M2d = lu_M2d.Code LEFT JOIN
    lu_CodeFile lu_M3 with (nolock) on OMHRS_SecM.M3 = lu_M3.Code LEFT JOIN
    lu_CodeFile lu_M4a with (nolock) on OMHRS_SecM.M4a = lu_M4a.Code LEFT JOIN
    lu_CodeFile lu_M4b with (nolock) on OMHRS_SecM.M4b = lu_M4b.Code LEFT JOIN
    U_Users LU_SignOffCoder_M with (nolock) on OMHRS_SecM.SignCoder = LU_SignOffCoder_M.Code LEFT JOIN
    dbo.OMHRS_SecN with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecN.AbstractID LEFT JOIN
    U_Users LU_SignOffCoder_N with (nolock) on OMHRS_SecN.SignCoder = LU_SignOffCoder_N.Code LEFT JOIN
    dbo.OMHRS_SecO with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecO.AbstractID LEFT JOIN
    lu_CodeFile lu_O1 with (nolock) on OMHRS_SecO.O1 = lu_O1.Code LEFT JOIN
    lu_CodeFile lu_O3 with (nolock) on OMHRS_SecO.O3 = lu_O3.Code LEFT JOIN
    lu_CodeFile lu_O5 with (nolock) on OMHRS_SecO.O5 = lu_O5.Code LEFT JOIN
    lu_CodeFile lu_O4a with (nolock) on OMHRS_SecO.O4a = lu_O4a.Code LEFT JOIN
    lu_CodeFile lu_O4b with (nolock) on OMHRS_SecO.O4b = lu_O4b.Code LEFT JOIN
    lu_CodeFile lu_O4c with (nolock) on OMHRS_SecO.O4c = lu_O4c.Code LEFT JOIN
    lu_CodeFile lu_O4d with (nolock) on OMHRS_SecO.O4d = lu_O4d.Code LEFT JOIN
    lu_CodeFile lu_O6a with (nolock) on OMHRS_SecO.O6a = lu_O6a.Code LEFT JOIN
    lu_CodeFile lu_O6b with (nolock) on OMHRS_SecO.O6b = lu_O6b.Code LEFT JOIN
    lu_CodeFile lu_O6c with (nolock) on OMHRS_SecO.O6c = lu_O6c.Code LEFT JOIN
    U_Users LU_SignOffCoder_O with (nolock) on OMHRS_SecO.SignCoder = LU_SignOffCoder_O.Code LEFT JOIN
    dbo.OMHRS_SecP with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecP.AbstractID LEFT JOIN
    lu_CodeFile lu_P1a with (nolock) on OMHRS_SecP.P1a = lu_P1a.Code LEFT JOIN
    lu_CodeFile lu_P1b with (nolock) on OMHRS_SecP.P1b = lu_P1b.Code LEFT JOIN
    lu_CodeFile lu_P1c with (nolock) on OMHRS_SecP.P1c = lu_P1c.Code LEFT JOIN
    lu_CodeFile lu_P1d with (nolock) on OMHRS_SecP.P1d = lu_P1d.Code LEFT JOIN
    lu_CodeFile lu_P2a with (nolock) on OMHRS_SecP.P2a = lu_P2a.Code LEFT JOIN
    lu_CodeFile lu_P2b with (nolock) on OMHRS_SecP.P2b = lu_P2b.Code LEFT JOIN
    lu_CodeFile lu_P3 with (nolock) on OMHRS_SecP.P3 = lu_P3.Code LEFT JOIN
    lu_CodeFile lu_P4 with (nolock) on OMHRS_SecP.P4 = lu_P4.Code LEFT JOIN
    lu_CodeFile lu_P5 with (nolock) on OMHRS_SecP.P5 = lu_P5.Code LEFT JOIN
    LU_Institution_10 lu_X140 with (nolock) on OMHRS_SecP.X140 = lu_X140.Code LEFT JOIN
    U_Users LU_SignOffCoder_P with (nolock) on OMHRS_SecP.SignCoder = LU_SignOffCoder_P.Code LEFT JOIN
    dbo.OMHRS_SecQ with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecQ.AbstractID LEFT JOIN
    lu_CodeFile lu_Q5 with (nolock) on OMHRS_SecQ.Q5 = lu_Q5.Code LEFT JOIN
    --LU_DSM_IV lu_Q2d with (nolock) on OMHRS_SecQ.Q2d = lu_Q2d.Code LEFT JOIN
    U_Users LU_SignOffCoder_Q with (nolock) on OMHRS_SecQ.SignCoder = LU_SignOffCoder_Q.Code LEFT JOIN
    dbo.OMHRS_SecR with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecR.AbstractID LEFT JOIN
    U_Users LU_SignOffCoder_R with (nolock) on OMHRS_SecR.SignCoder = LU_SignOffCoder_R.Code LEFT JOIN
    dbo.OMHRS_SecS with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecS.AbstractID LEFT JOIN
    lu_CodeFile lu_X90 with (nolock) on OMHRS_SecS.X90 = lu_X90.Code LEFT JOIN
    U_Users LU_SignOffCoder_S with (nolock) on OMHRS_SecS.SignCoder = LU_SignOffCoder_S.Code LEFT JOIN
    LU_Provider LU_AttProvider with (nolock) on dbo.OMHRS_SecAA.AttendingPhysician = LU_AttProvider.Code LEFT JOIN
    LU_Provider LU_RefProvider with (nolock) on dbo.OMHRS_SecAA.RefPhysician = LU_RefProvider.Code LEFT JOIN
    LU_MisCode LU_MisCode with (nolock) on dbo.OMHRS_SecAA.MISCode = LU_MisCode.Code LEFT JOIN
    LU_NurseArea LU_AdmitNurse with (nolock) on dbo.OMHRS_SecAA.AdmittingNurseArea = LU_AdmitNurse.Code LEFT JOIN
--ED - 01914
    LU_CodeFile LU_CC4a with (nolock) on dbo.OMHRS_SecCC.CC4a = LU_CC4a.Code LEFT JOIN
    LU_CodeFile LU_CC4b with (nolock) on dbo.OMHRS_SecCC.CC4b = LU_CC4b.Code LEFT JOIN
    LU_CodeFile LU_A3a with (nolock) on dbo.OMHRS_SecA.A3a = LU_A3a.Code LEFT JOIN
    LU_CodeFile LU_A3b with (nolock) on dbo.OMHRS_SecA.A3b = LU_A3b.Code LEFT JOIN
    LU_CodeFile LU_I7a with (nolock) on dbo.OMHRS_SecI.I7a = LU_I7a.Code LEFT JOIN
--ED - 02156
    LU_CodeFile LU_X4 with (nolock) on dbo.OMHRS_SecAA.X4 = LU_X4.Code LEFT JOIN
    LU_CodeFile LU_X7 with (nolock) on dbo.OMHRS_SecQ.X7 = LU_X7.Code LEFT JOIN
--ED - 02373
    OMHRS_OutcomeScale with (nolock) on dbo.OMHRS_SecAA.AbstractID = OMHRS_OutcomeScale.AbstractID  LEFT JOIN 
    OMHRS_CAPs with (nolock) on dbo.OMHRS_SecAA.AbstractID = OMHRS_CAPs.AbstractID Left join
--PR - 05833
    dbo.OMHRS_IAR_CCIM with (nolock) on dbo.OMHRS_SecAA.AbstractID = OMHRS_IAR_CCIM.AbstractID 
    
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_YesNoSystem WHERE code = 1) LU_YesNoSystem_Yes 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_YesNoSystem WHERE code = 2) LU_YesNoSystem_No 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200379) LU_570_Yes 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200380) LU_570_No 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200103) LU_B_519_0 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200104) LU_B_519_1 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200105) LU_B_519_2 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200106) LU_B_519_3 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200183) LU_538_0 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200184) LU_538_1 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200185) LU_538_2 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200202) LU_542_0 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200203) LU_542_1 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200204) LU_542_2 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200205) LU_542_3 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200216) LU_546_0 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200217) LU_546_1 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200218) LU_546_2 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200219) LU_546_3 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200268) LU_560_1 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200269) LU_560_2 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200270) LU_560_3 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200906) LU_576_0 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200907) LU_576_1 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 200908) LU_576_8 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 302101) LU_605_0 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 302102) LU_605_1 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 302111) LU_606_0 
    CROSS JOIN (SELECT DisplayCode, UserDescription FROM LU_CodeFile WHERE code = 302112) LU_606_1
--QA - 00032 disable the domain securite issue
---- PR - 07485
--where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or OMHRS_SecAA.HospitalID is null or OMHRS_SecAA.HospitalID = 0
----EN - 00666
--    or Is_Member(nullif(ReportGroup, '''')) = 1
    



/*
    left join lu_CodeFile lu_ with (nolock) on OMHRS_SecA. = lu_.Code
 = lu_.DisplayCode, 
Desc_ = lu_.UserDescription,

_ = (case dbo.OMHRS_SecO when 200379 then LU_570_Yes.DisplayCode when 200380 then LU_570_No.DisplayCode else '''' end),
Desc_ = (case dbo.OMHRS_SecO when 200379 then LU_570_Yes.UserDescription when 200380 then LU_570_No.UserDescription else '''' end),

_ = (case dbo.OMHRS_SecI.I when 200183 then LU_538_0.DisplayCode when 200184 then LU_538_1.DisplayCode when 200185 then LU_538_2.DisplayCode else '''' end),
Desc_ = (case dbo.OMHRS_SecI.I when 200183 then LU_538_0.UserDescription when 200184 then LU_538_1.UserDescription when 200185 then LU_538_2.UserDescription else '''' end),

_ = (case dbo.OMHRS_SecL when 200216 then LU_546_0.DisplayCode when 200217 then LU_546_1.DisplayCode when 200218 then LU_546_2.DisplayCode when 200219 then LU_546_3.DisplayCode else '''' end),
Desc_ = (case dbo.OMHRS_SecL when 200216 then LU_546_0.UserDescription when 200217 then LU_546_1.UserDescription when 200218 then LU_546_2.UserDescription when 200219 THEN LU_546_3.UserDescription else '''' end),

_ = (case dbo.OMHRS_SecQ. when 200268 then LU_560_1.DisplayCode when 200269 then LU_560_2.DisplayCode when 200270 then LU_560_3.DisplayCode else '''' end),
Desc_ = (case dbo.OMHRS_SecQ. when 200268 then LU_560_1.UserDescription when 200269 then LU_560_2.UserDescription when 200270 then LU_560_3.UserDescription else '''' end),

*/

--  select * from lu_codefile where lookupid = 560

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRSbyElementID_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE view [dbo].[OMHRSbyElementID_VR]
as
SELECT     
[    **** SECTION AA ****] = '''',
    AA1a_LastName = OMHRS_SecAA.LastName, 
    AA1b_FirstName = OMHRS_SecAA.FirstName, 
    AA1c_MiddleName = OMHRS_SecAA.MiddleName, 
    X10_CountryOfResidence = lu_X10.DisplayCode, X10_CountryOfResidenceDesc = lu_X10.UserDescription, 
    X20_HCNProvince = LU_HCNProvince.DisplayCode, X20_HCNProvinceDesc = LU_HCNProvince.UserDescription, 
    --ED - 02156
    X4_HealthCareNumberStatus = LU_X4.DisplayCode, X4_HealthCareNumberStatusDesc = LU_X4.UserDescription, 
    AA2_HealthCareNumber = OMHRS_SecAA.HealthCareNumber, --AA2
    X30_ChartNumber = OMHRS_SecAA.ChartNumber, --X30
    AA3_CaseRecordNumber = OMHRS_SecAA.AA3, 
    AA4_FacilityNumber = H_InstitutionProfile.DisplayCode, AA4_InstitutionNumberDesc = H_InstitutionProfile.UserDescription, --AA4 
    AA5_UnitIdentifier = lu_AA5.DisplayCode, AA5_UnitIdentifierDesc = lu_AA5.UserDescription, 
    
    AssessmentSignOff = (CASE OMHRS_SecAA.ASignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    AssessmentSignOff_Desc = (CASE OMHRS_SecAA.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    AssessmentSignOffCoder = LU_SignOffCoder_T.DisplayCode, AssessmentSignOffCoderDesc = LU_SignOffCoder_T.UserDescription, 
    AssessmentSignOffDate = OMHRS_SecAA.ASignDate, 

    SectionAASignedOff = (CASE WHEN OMHRS_SecAA.SignOff = 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN OMHRS_SecAA.SignOff = 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionAASignedOff_Desc = (CASE WHEN OMHRS_SecAA.SignOff = 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN OMHRS_SecAA.SignOff = 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionAASignedOffCoder = LU_SignOffCoder_AA.DisplayCode, 
    SectionAASignedOffCoderDesc = LU_SignOffCoder_AA.UserDescription, SectionAASignedOffDate = OMHRS_SecAA.SignDate, 

[    **** SECTION IAR CCIM Assessment Consent ****] = '''',
    IAR_AssessmentConsentFlag = (case when OMHRS_IAR_CCIM.IAR_ConsentFlag = 302141 then ''N'' when OMHRS_IAR_CCIM.IAR_ConsentFlag = 302142 then ''Y'' end),
    IAR_AssessmentConsentFlagDesc = (case when OMHRS_IAR_CCIM.IAR_ConsentFlag = 302141 then ''No - The patient has requested that this visit not be shared within the IAR'' 
                                          when OMHRS_IAR_CCIM.IAR_ConsentFlag = 302142 then ''The patient has agreed to allow the sharing of their visit within the IAR'' 
                                     end),
    IAR_DateConsentGiven = OMHRS_IAR_CCIM.DateConsentGiven,
    IAR_IsCCIMSubmitted = (case when OMHRS_IAR_CCIM.IAR_CCIM_IsSubmitted = 302151 then ''N'' when OMHRS_IAR_CCIM.IAR_CCIM_IsSubmitted = 302152 then ''Y'' end), 
    IAR_IsCCIMSubmittedDesc = (case when OMHRS_IAR_CCIM.IAR_CCIM_IsSubmitted = 302151 then ''No - Not Submitted to CCIM'' when OMHRS_IAR_CCIM.IAR_CCIM_IsSubmitted = 302152 then ''Yes - Submitted to CCIM'' end), 
    IAR_DateSubmissionSentToCCIM = OMHRS_IAR_CCIM.DateSubmittedToCCIM,
    IAR_IsCCIMCorrected = (case when OMHRS_IAR_CCIM.IAR_CCIM_IsCorrected = 302161 then ''N'' when OMHRS_IAR_CCIM.IAR_CCIM_IsCorrected = 302162 then ''C'' when OMHRS_IAR_CCIM.IAR_CCIM_IsCorrected = 302163 then ''D'' end), 
    IAR_IsCCIMCorrectedDesc = (case when OMHRS_IAR_CCIM.IAR_CCIM_IsCorrected = 302161 then ''New'' when OMHRS_IAR_CCIM.IAR_CCIM_IsCorrected = 302162 then ''Correction'' when OMHRS_IAR_CCIM.IAR_CCIM_IsCorrected = 302163 then ''Deletion'' end), 
    IAR_DateCorrectionSentToCCIM = OMHRS_IAR_CCIM.DateCorrectedToCCIM,

[    **** SECTION BB ****] = '''',
    BB1_Sex = lu_BB1.DisplayCode, BB1_SexDesc = lu_BB1.UserDescription, 
    BB2_Birthdate = BB2, 
    X40_EstimatedBirthdate = (CASE dbo.OMHRS_SecBB.X40 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    X40_EstimatedBirthdateDesc = (CASE dbo.OMHRS_SecBB.X40 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription  ELSE '''' END), 
    BB3_MaritalStatus = lu_BB3.DisplayCode, BB3_MaritalStatusDesc = lu_BB3.UserDescription, 
    BB4_Language = lu_BB4.DisplayCode, BB4_LanguageDesc = lu_BB4.UserDescription, 
    BB5_Education = lu_BB5.DisplayCode, BB5_EducationDesc = lu_BB5.UserDescription, 
    
    BB6a_IncomeEmployment = (CASE dbo.OMHRS_SecBB.BB6a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    BB6a_IncomeEmploymentDesc = (CASE dbo.OMHRS_SecBB.BB6a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    BB6b_IncomeEmploymentInsurance = (CASE dbo.OMHRS_SecBB.BB6b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    BB6b_IncomeEmploymentInsuranceDesc = (CASE dbo.OMHRS_SecBB.BB6b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    BB6c_IncomePension = (CASE dbo.OMHRS_SecBB.BB6c WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    BB6c_IncomePensionDesc = (CASE dbo.OMHRS_SecBB.BB6c WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    BB6d_IncomeSocialAssistance = (CASE dbo.OMHRS_SecBB.BB6d WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    BB6d_IncomeSocialAssistanceDesc = (CASE dbo.OMHRS_SecBB.BB6d WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    BB6e_IncomeDisabilityInsurance = (CASE dbo.OMHRS_SecBB.BB6e WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    BB6e_IncomeDisabilityInsuranceDesc = (CASE dbo.OMHRS_SecBB.BB6e WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    BB6f_IncomeOther = (CASE dbo.OMHRS_SecBB.BB6f WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    BB6f_IncomeOtherDesc = (CASE dbo.OMHRS_SecBB.BB6f WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    BB6g_IncomeNo = (CASE dbo.OMHRS_SecBB.BB6g WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    BB6g_IncomeNoDesc = (CASE dbo.OMHRS_SecBB.BB6g WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    X50a_ResponsePayProvince = (CASE dbo.OMHRS_SecBB.X50a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    X50a_ResponsePayProvinceDesc = (CASE dbo.OMHRS_SecBB.X50a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    X50b_ResponsePayWCB = (CASE dbo.OMHRS_SecBB.X50b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    X50b_ResponsePayWCBDesc = (CASE dbo.OMHRS_SecBB.X50b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    X50c_ResponsePayOtherProvince = (CASE dbo.OMHRS_SecBB.X50c WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    X50c_ResponsePayOtherProvinceDesc = (CASE dbo.OMHRS_SecBB.X50c WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    X50d_ResponsePayVAC = (CASE dbo.OMHRS_SecBB.X50d WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    X50d_ResponsePayVACDesc = (CASE dbo.OMHRS_SecBB.X50d WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    X50e_ResponsePayFNIHB = (CASE dbo.OMHRS_SecBB.X50e WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    X50e_ResponsePayFNIHBDesc = (CASE dbo.OMHRS_SecBB.X50e WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    X50f_ResponsePayOther = (CASE dbo.OMHRS_SecBB.X50f WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    X50f_ResponsePayOtherDesc = (CASE dbo.OMHRS_SecBB.X50f WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    X50g_ResponsePaySelfPay = (CASE dbo.OMHRS_SecBB.X50g WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    X50g_ResponsePaySelfPayDesc = (CASE dbo.OMHRS_SecBB.X50g WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    X50h_ResponsePayOtherCountry = (CASE dbo.OMHRS_SecBB.X50h WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    X50h_ResponsePayOtherCountryDesc = (CASE dbo.OMHRS_SecBB.X50h WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    X50i_ResponsePayUnknown = (CASE dbo.OMHRS_SecBB.X50i WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    X50i_ResponsePayUnknownDesc = (CASE dbo.OMHRS_SecBB.X50i WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    BB7_AboriginalOrigin = (CASE dbo.OMHRS_SecBB.BB7 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    BB7_AboriginalOriginDesc = (CASE dbo.OMHRS_SecBB.BB7 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    BB7a_AboriginalFirstNation = (CASE dbo.OMHRS_SecBB.BB7a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    BB7a_AboriginalFirstNationDesc = (CASE dbo.OMHRS_SecBB.BB7a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    BB7b_AboriginalMetis = (CASE dbo.OMHRS_SecBB.BB7b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    BB7b_AboriginalMetisDesc = (CASE dbo.OMHRS_SecBB.BB7b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    BB7c_AboriginalInuit = (CASE dbo.OMHRS_SecBB.BB7c WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    BB7c_AboriginalInuitDesc = (CASE dbo.OMHRS_SecBB.BB7c WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 

    SectionBBSignedOff = (CASE OMHRS_SecBB.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionBBSignedOff_Desc = (CASE OMHRS_SecBB.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionBBSignedOffCoder = LU_SignOffCoder_BB.DisplayCode, 
    SectionBBSignedOffCoderDesc = LU_SignOffCoder_BB.UserDescription, SectionBBSignedOffDate = OMHRS_SecBB.SignDate, 

[    **** SECTION CC ****] = '''',
    CC1_DateStayBegan = OMHRS_SecAA.AdmitDate, --CC1
    TimeStayBegan = OMHRS_SecAA.AdmitTime, 
    X8_DateAdmittedToMentalHealthBed = OMHRS_SecCC.X8,    ----ED - 02274
    --ED - 01914
    X5a_WaitTime = (CASE dbo.OMHRS_SecA.X5a WHEN 200834 THEN ''0'' WHEN 200835 THEN ''1'' when 200836 then ''8'' ELSE '''' END), 
    X5a_WaitTimeDesc = (CASE dbo.OMHRS_SecA.X5a WHEN 200834 THEN ''No'' WHEN 200835 THEN ''Yes'' when 200836 then ''Unknown'' ELSE '''' END), 
    X5b_DateWaitBegan = OMHRS_SecA.X5b,
    CC2a_ReasonAdmitThreatSelf = (CASE dbo.OMHRS_SecCC.CC2a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    CC2a_ReasonAdmitThreatSelfDesc = (CASE dbo.OMHRS_SecCC.CC2a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    CC2b_ReasonAdmitThreatOther = (CASE dbo.OMHRS_SecCC.CC2b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    CC2b_ReasonAdmThreatOthDesc = (CASE dbo.OMHRS_SecCC.CC2b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    CC2c_ReasonAdmitInability = (CASE dbo.OMHRS_SecCC.CC2c WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    CC2c_ReasonAdmitInabilityDesc = (CASE dbo.OMHRS_SecCC.CC2c WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    CC2d_ReasonAdmitProblem = (CASE dbo.OMHRS_SecCC.CC2d WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    CC2d_ReasonAdmitProblemDesc = (CASE dbo.OMHRS_SecCC.CC2d WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    CC2e_ReasonAdmitSpecific = (CASE dbo.OMHRS_SecCC.CC2e WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    CC2e_ReasonAdmitSpecificDesc = (CASE dbo.OMHRS_SecCC.CC2e WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    CC2f_ReasonAdmitJustice = (CASE dbo.OMHRS_SecCC.CC2f WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    CC2f_ReasonAdmitJusticeDesc = (CASE dbo.OMHRS_SecCC.CC2f WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    CC2g_ReasonAdmitOther = (CASE dbo.OMHRS_SecCC.CC2g WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    CC2g_ReasonAdmitOtherDesc = (CASE dbo.OMHRS_SecCC.CC2g WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    --ED - 02275
    CC2h_ForensicAssessment = (CASE dbo.OMHRS_SecCC.CC2h WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    CC2h_ForensicAssessmentDesc = (CASE dbo.OMHRS_SecCC.CC2h WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 

    -- ED - 01682
    -- PostalCodeDesc_X60 = dbo.GetPostalDescription(isnull(OMHRS_SecCC.X60, ''''), isnull(OMHRS_SecS.X80, OMHRS_SecAA.AdmitDate)), -- ED - 01682
    X60_PostalCode = OMHRS_SecCC.X60, 
    CC3_WhoLivedWithAtAdmission = lu_CC3.DisplayCode, CC3_WhoLivedWithAtAdmitDesc = lu_CC3.UserDescription, 
    CC4_PriorResidentialStatus = lu_CC4.DisplayCode, CC4_PriorResidentialStatusDesc = lu_CC4.UserDescription, 
    --ED - 01914
    CC4a_AdmittedFrom = LU_CC4a.DisplayCode, CC4a_AdmittedFromDesc = LU_CC4a.UserDescription,
    CC4b_UsualResidential = LU_CC4b.DisplayCode, CC4b_UsualResidentialDesc = LU_CC4b.UserDescription, 
    X65_ReferredFromFacility = lu_X65.DisplayCode, X65_ReferredFromFacilityDesc = lu_X65.UserDescription, 
    CC5_ResidentialStability = (CASE dbo.OMHRS_SecCC.CC5 WHEN 200951 THEN ''0'' WHEN 200952 THEN ''1'' ELSE '''' END), 
    CC5_ResidentialStabilityDesc = (CASE dbo.OMHRS_SecCC.CC5 WHEN 200951 THEN ''living arrangement is stable'' WHEN 200952 THEN ''living arrangement is considered unstable'' ELSE '''' END), 

    SectionCCSignedOff = (CASE OMHRS_SecCC.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionCCSignedOff_Desc = (CASE OMHRS_SecCC.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionCCSignedOffCoder = LU_SignOffCoder_CC.DisplayCode, SectionCCSignedOffCoderDesc = LU_SignOffCoder_CC.UserDescription, 
    SectionCCSignedOffDate = OMHRS_SecCC.SignDate, 
    
[    **** SECTION DD ****] = '''',
    DD1_NumberPsychAdmitRecent = lu_DD1.DisplayCode, DD1_NumberPsychAdmitRecentDesc = lu_DD1.UserDescription, 
    DD2_NumberPsychAdmitLifetime = lu_DD2.DisplayCode, DD2_NumberPsychAdmitLifetimeDesc = lu_DD2.UserDescription, 
    DD3_TimeSinceLastDischarge = lu_DD3.DisplayCode, DD3_TimeSinceLastDischargeDesc = lu_DD3.UserDescription, 
    DD4_AmountTimeHospitalized = lu_DD4.DisplayCode, DD4_AmountTimeHospitalizedDesc = lu_DD4.UserDescription, 
    DD5_ContactCommunityMental = lu_DD5.DisplayCode, DD5_ContactCommunityMentalDesc = lu_DD5.UserDescription, 
    DD6_AgeAtFirstHospitalization = lu_DD6.DisplayCode, DD6_AgeAtFirstHospitalizationDesc = lu_DD6.UserDescription, 

    SectionDDSignedOff = (CASE OMHRS_SecDD.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionDDSignedOff_Desc = (CASE OMHRS_SecDD.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionDDSignedOffCoder = LU_SignOffCoder_DD.DisplayCode, 
    SectionDDSignedOffCoderDesc = LU_SignOffCoder_DD.UserDescription, SectionDDSignedOffDate = OMHRS_SecDD.SignDate, 

[    **** SECTION A ****] = '''',
    A1_AssessmentReferenceDate = dbo.OMHRS_SecA.A1, AssessmentReferenceTime = dbo.OMHRS_SecA.AssessTime, 
    A2_ReasonForAssessment = lu_A2.DisplayCode, A2_ReasonForAssessmentDesc = lu_A2.UserDescription, 
    A3_InpatientStatus = lu_A3.DisplayCode, A3_InpatientStatusDesc = lu_A3.UserDescription, 
    --ED - 01914
    A3a_StatusAtTimeAdmission = LU_A3a.DisplayCode, A3a_StatusAtTimeAdmissionDesc = LU_A3a.UserDescription,
    A3b_StatusAtTimeAssessment = LU_A3b.DisplayCode, A3b_StatusAtTimeAssessmentDesc = LU_A3b.UserDescription,
    A4a_CC_ConsentToTreatment = (CASE WHEN OMHRS_SecA.A4a = 200379 THEN LU_570_Yes.DisplayCode WHEN OMHRS_SecA.A4a = 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    A4a_CC_ConsentToTreatmentDesc = (CASE WHEN OMHRS_SecA.A4a = 200379 THEN LU_570_Yes.UserDescription WHEN OMHRS_SecA.A4a = 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    A4b_CC_ManageProperty = (CASE WHEN OMHRS_SecA.A4b = 200379 THEN LU_570_Yes.DisplayCode WHEN OMHRS_SecA.A4b = 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    A4b_CC_ManagePropertyDesc = (CASE WHEN OMHRS_SecA.A4b = 200379 THEN LU_570_Yes.UserDescription WHEN OMHRS_SecA.A4b = 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    A4c_CC_DiscloseInformation = (CASE WHEN OMHRS_SecA.A4c = 200379 THEN LU_570_Yes.DisplayCode WHEN OMHRS_SecA.A4c = 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    A4c_CC_DiscloseInformationDesc = (CASE WHEN OMHRS_SecA.A4c = 200379 THEN LU_570_Yes.UserDescription WHEN OMHRS_SecA.A4c = 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    A4d_CC_LegalGuardianDecisionMaker = (CASE WHEN OMHRS_SecA.A4d = 200379 THEN LU_570_Yes.DisplayCode WHEN OMHRS_SecA.A4d = 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    A4d_CC_LegalGuardianDecisionMakerDesc = (CASE WHEN OMHRS_SecA.A4d = 200379 THEN LU_570_Yes.UserDescription WHEN OMHRS_SecA.A4d = 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    A5a_PoliceInterventionViolentBehaviour = lu_A5a.DisplayCode, A5a_PoliceInterventionViolentBehaviourDesce = lu_A5a.UserDescription, 
    A5b_PoliceInterventionNonViolentBehaviour = lu_A5b.DisplayCode, AA5b_PoliceInterventionNonViolentBehaviourDesc = lu_A5b.UserDescription, 

    SectionASignedOff = (CASE WHEN OMHRS_SecA.SignOff = 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN OMHRS_SecA.SignOff = 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionASignedOff_Desc = (CASE WHEN OMHRS_SecA.SignOff = 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN OMHRS_SecA.SignOff = 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionASignedOffCoder = LU_SignOffCoder_A.DisplayCode, 
    SectionASignedOffCoderDesc = LU_SignOffCoder_A.UserDescription, SectionASignedOffDate = OMHRS_SecA.SignDate, 
    
[    **** SECTION B ****] = '''',
    B1a_FacialExpression = (CASE OMHRS_SecB.B1a WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1a_FacialExpressionDesc = (CASE OMHRS_SecB.B1a WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1b_Tearfulness = (CASE OMHRS_SecB.B1b WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1b_TearfulnessDesc = (CASE OMHRS_SecB.B1b WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1c_DecreasedEnergy = (CASE OMHRS_SecB.B1c WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1c_DecreasedEnergyDesc = (CASE OMHRS_SecB.B1c WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1d_MadeNegativeStatement = (CASE OMHRS_SecB.B1d WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1d_MadeNegativeStatementDesc = (CASE OMHRS_SecB.B1d WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1e_SelfDeprecation = (CASE OMHRS_SecB.B1e WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1e_SelfDeprecationDesc = (CASE OMHRS_SecB.B1e WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1f_GuiltShame = (CASE OMHRS_SecB.B1f WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1f_GuiltShameDesc = (CASE OMHRS_SecB.B1f WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1g_Hopelessness = (CASE OMHRS_SecB.B1g WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1g_HopelessnessDesc = (CASE OMHRS_SecB.B1g WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1h_InflatedSelfWorth = (CASE OMHRS_SecB.B1h WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1h_InflatedSelfWorthDesc = (CASE OMHRS_SecB.B1h WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1i_HyperArousal = (CASE OMHRS_SecB.B1i WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1i_HyperArousalDesc = (CASE OMHRS_SecB.B1i WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1j_Irritability = (CASE OMHRS_SecB.B1j WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1j_IrritabilityDesc = (CASE OMHRS_SecB.B1j WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1k_IncreasedSociability = (CASE OMHRS_SecB.B1k WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1k_IncreasedSociabilityDesc = (CASE OMHRS_SecB.B1k WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1l_PressuredSpeech = (CASE OMHRS_SecB.B1l WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1l_PressuredSpeechDesc = (CASE OMHRS_SecB.B1l WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1m_LabileAffect = (CASE OMHRS_SecB.B1m WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1m_LabileAffectDesc = (CASE OMHRS_SecB.B1m WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1n_FlatOrBluntedAffect = (CASE OMHRS_SecB.B1n WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1n_FlatOrBluntedAffectDesc = (CASE OMHRS_SecB.B1n WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1o_AnxiousComplaints = (CASE OMHRS_SecB.B1o WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1o_AnxiousComplaintsDesc = (CASE OMHRS_SecB.B1o WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1p_FearsOrPhobias = (CASE OMHRS_SecB.B1p WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1p_FearsOrPhobiasDesc = (CASE OMHRS_SecB.B1p WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1q_ObsessiveThoughts = (CASE OMHRS_SecB.B1q WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1q_ObsessiveThoughtsDesc = (CASE OMHRS_SecB.B1q WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1r_CompulsiveBehaviour = (CASE OMHRS_SecB.B1r WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1r_CompulsiveBehaviourDesc = (CASE OMHRS_SecB.B1r WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1s_InstrusiveThoughts = (CASE OMHRS_SecB.B1s WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1s_InstrusiveThoughtsDesc = (CASE OMHRS_SecB.B1s WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1t_EpisodesOfPanic = (CASE OMHRS_SecB.B1t WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1t_EpisodesOfPanicDesc = (CASE OMHRS_SecB.B1t WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1u_Hallucinations = (CASE OMHRS_SecB.B1u WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1u_HallucinationsDesc = (CASE OMHRS_SecB.B1u WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1v_CommandHallucinations = (CASE OMHRS_SecB.B1v WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1v_CommandHallucinationsDesc = (CASE OMHRS_SecB.B1v WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1w_Delusions = (CASE OMHRS_SecB.B1w WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1w_DelusionsDesc = (CASE OMHRS_SecB.B1w WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1x_AbnormalThoughtProcessOrForm = (CASE OMHRS_SecB.B1x WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1x_AbnormalThoughtProcessOrFormDesc = (CASE OMHRS_SecB.B1x WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1y_Anhedonia = (CASE OMHRS_SecB.B1y WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1y_AnhedoniaDesc = (CASE OMHRS_SecB.B1y WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1z_LossOfInterest = (CASE OMHRS_SecB.B1z WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1z_LossOfInterestDesc = (CASE OMHRS_SecB.B1z WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 

    B1aa_LackOfMotivation = (CASE OMHRS_SecB.B1aa WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1aa_LackOfMotivationDesc = (CASE OMHRS_SecB.B1aa WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1bb_ReducedInteraction = (CASE OMHRS_SecB.B1bb WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1bb_ReducedInteractionDesc = (CASE OMHRS_SecB.B1bb WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1cc_HealthComplaints = (CASE OMHRS_SecB.B1cc WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1cc_HealthComplaintsDesc = (CASE OMHRS_SecB.B1cc WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1dd_Anger = (CASE OMHRS_SecB.B1dd WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1dd_AngerDesc = (CASE OMHRS_SecB.B1dd WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1ee_UnusualOrAbnormalPhysicalMove = (CASE OMHRS_SecB.B1ee WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1ee_UnusualOrAbnormalPhysicalMoveDesc = (CASE OMHRS_SecB.B1ee WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1ff_Hygiene = (CASE OMHRS_SecB.B1ff WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1ff_HygieneDesc = (CASE OMHRS_SecB.B1ff WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B1gg_SleepProblems = (CASE OMHRS_SecB.B1gg WHEN 200103 THEN LU_B_519_0.DisplayCode WHEN 200104 THEN LU_B_519_1.DisplayCode WHEN 200105 THEN LU_B_519_2.DisplayCode WHEN 200106 THEN LU_B_519_3.DisplayCode ELSE '''' END), 
    B1gg_SleepProblemsDesc = (CASE OMHRS_SecB.B1gg WHEN 200103 THEN LU_B_519_0.UserDescription WHEN 200104 THEN LU_B_519_1.UserDescription WHEN 200105 THEN LU_B_519_2.UserDescription WHEN 200106 THEN LU_B_519_3.UserDescription ELSE '''' END), 
    B2_InsightIntoMentalHealth = lu_B2.DisplayCode, B2_InsightIntoMentalHealthDesc = lu_B2.UserDescription, 

    SectionBSignedOff = (CASE OMHRS_SecB.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionBSignedOff_Desc = (CASE OMHRS_SecB.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionBSignedOffCoder = LU_SignOffCoder_B.DisplayCode, SectionBSignedOffCoderDesc = LU_SignOffCoder_B.UserDescription, 
    SectionBSignedOffDate = OMHRS_SecB.SignDate, 


[    **** SECTION C ****] = '''',
    C1_Alcohol = lu_C1.DisplayCode, C1_AlcoholDesc = lu_C1.UserDescription, 
    C2a_SubstanceUseInhalants = lu_C2a.DisplayCode,     C2a_SubstanceUseInhalantsDesc = lu_C2a.UserDescription, 
    C2b_SubstanceUseHallucinogens = lu_C2b.DisplayCode,     C2b_SubstanceUseHallucinogensDesc = lu_C2b.UserDescription, 
    C2c_SubstanceUseCocaine = lu_C2c.DisplayCode,     C2c_SubstanceUseCocaineDesc = lu_C2c.UserDescription, 
    C2d_SubstanceUseStimulants = lu_C2d.DisplayCode,     C2d_SubstanceUseStimulantsDesc = lu_C2d.UserDescription, 
    C2e_SubstanceUseOpiates = lu_C2e.DisplayCode,     C2e_SubstanceUseOpiatesDesc = lu_C2e.UserDescription, 
    C2f_SubstanceUseCannabis = lu_C2f.DisplayCode,     C2f_SubstanceUseCannabisDesc = lu_C2f.UserDescription, 
    C3_WithdrawalSymptoms = lu_C3.DisplayCode, C3_WithdrawalSymptomsDesc = lu_C3.UserDescription, 
    C4a_DrinkingConcerns = (CASE dbo.OMHRS_SecC.C4a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    C4a_DrinkingConcernsDesc = (CASE dbo.OMHRS_SecC.C4a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription  ELSE '''' END), 
    C4b_DrinkingCriticism = (CASE dbo.OMHRS_SecC.C4b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    C4b_DrinkingCriticismDesc = (CASE dbo.OMHRS_SecC.C4b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    C4c_DrinkingFeelingsGuilt = (CASE dbo.OMHRS_SecC.C4c WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode  ELSE '''' END), 
    C4c_DrinkingFeelingsGuiltDesc = (CASE dbo.OMHRS_SecC.C4c WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    C4d_DrinkingNerves = (CASE dbo.OMHRS_SecC.C4d WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    C4d_DrinkingNervesDesc = (CASE dbo.OMHRS_SecC.C4d WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription  ELSE '''' END), 
    C5_Smoking = lu_C5.DisplayCode, C5_SmokingDesc = lu_C5.UserDescription, 
    C6_Gambling = (CASE dbo.OMHRS_SecC.C6 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    C6_GamblingDesc = (CASE dbo.OMHRS_SecC.C6 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 

    SectionCSignedOff = (CASE OMHRS_SecC.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionCSignedOff_Desc = (CASE OMHRS_SecC.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionCSignedOffCoder = LU_SignOffCoder_C.DisplayCode, SectionCSignedOffCoderDesc = LU_SignOffCoder_C.UserDescription, 
    SectionCSignedOffDate = OMHRS_SecC.SignDate, 

[    **** SECTION D ****] = '''',
    D1a_SelfInjuryAttempts = lu_D1a.DisplayCode, D1a_SelfInjuryAttemptsDesc = lu_D1a.UserDescription, 
    D1b_SelfInjuryIntent = lu_D1b.DisplayCode, D1b_SelfInjuryIntentDesc = lu_D1b.UserDescription, 
    D1c_SelfInjuryConsidered = lu_D1c.DisplayCode, D1c_SelfInjuryConsideredDesc = lu_D1c.UserDescription, 
    D1d_SelfInjuryOthers = lu_D1d.DisplayCode, D1d_SelfInjuryOthersDesc = lu_D1d.UserDescription, 
    --ED - 01914
    D1da_ConcernRiskForSelfInjury = (CASE OMHRS_SecD.D1da WHEN 200366 THEN ''0'' WHEN 200367 THEN ''1'' else '''' END), 
    D1da_ConcernRiskForSelfInjuryDesc = (CASE OMHRS_SecD.D1da WHEN 200366 THEN ''No'' WHEN 200367 THEN ''Yes'' ELSE '''' END), 
    D1db_SuicidePlanInLast30Days = (CASE OMHRS_SecD.D1db WHEN 200366 THEN ''0'' WHEN 200367 THEN ''1'' else '''' END), 
    D1db_SuicidePlanInLast30DaysDesc = (CASE OMHRS_SecD.D1db WHEN 200366 THEN ''No'' WHEN 200367 THEN ''Yes'' ELSE '''' END), 
    D2a_ViolenceToOthers = lu_D2a.DisplayCode, D2a_ViolenceToOthersDesc = lu_D2a.UserDescription, 
    D2b_ViolenceIntimidation = lu_D2b.DisplayCode, D2b_ViolenceIntimidationDesc = lu_D2b.UserDescription, 
    D2c_ViolenceIdeation = lu_D2c.DisplayCode, D2c_ViolenceIdeationDesc = lu_D2c.UserDescription, 
    D3_SexualViolence = (CASE dbo.OMHRS_SecD.D3 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    D3_SexualViolenceDesc = (CASE dbo.OMHRS_SecD.D3 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 

    SectionDSignedOff = (CASE OMHRS_SecD.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionDSignedOff_Desc = (CASE OMHRS_SecD.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionDSignedOffCoder = LU_SignOffCoder_D.DisplayCode, SectionDSignedOffCoderDesc = LU_SignOffCoder_D.UserDescription, 
    SectionDSignedOffDate = OMHRS_SecD.SignDate, 

[    **** SECTION E ****] = '''',
    E1a_BehaviourSymptomsWandering = lu_E1a.DisplayCode, E1a_BehaviourSymptomsWanderingDesc = lu_E1a.UserDescription, 
    E1b_BehaviourSymptomsVerbal = lu_E1b.DisplayCode, E1b_BehaviourSymptomsVerbalDesc = lu_E1b.UserDescription, 
    E1c_BehaviourSymptomsPhysical = lu_E1c.DisplayCode, E1c_BehaviourSymptomsPhysicalDesc = lu_E1c.UserDescription, 
    E1d_BehaviourSymptomsSocially = lu_E1d.DisplayCode, E1d_BehaviourSymptomsSociallyDesc = lu_E1d.UserDescription, 
    E1e_BehaviourSymptomsPublicSexual = lu_E1e.DisplayCode, E1e_BehaviourSymptomsPublicSexualDesc = lu_E1e.UserDescription, 
    E1f_BehaviourSymptomsResists = lu_E1f.DisplayCode, E1f_BehaviourSymptomsResistsDesc = lu_E1f.UserDescription, 
    E1g_BehaviourSymptomsElopement = lu_E1g.DisplayCode, E1g_BehaviourSymptomsElopementDesc = lu_E1g.UserDescription, 
    E2_ExtremeBehaviourDisturb = lu_E2.DisplayCode, E2_ExtremeBehaviourDisturbDesc = lu_E2.UserDescription, 

    SectionESignedOff = (CASE OMHRS_SecE.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionESignedOff_Desc = (CASE OMHRS_SecE.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionESignedOffCoder = LU_SignOffCoder_E.DisplayCode, SectionESignedOffCoderDesc = LU_SignOffCoder_E.UserDescription, 
    SectionESignedOffDate = OMHRS_SecE.SignDate, 

[    **** SECTION F ****] = '''',
    F1a_MemoryRecallShortTerm = lu_F1a.DisplayCode, F1a_MemoryRecallShortTermDesc = lu_F1a.UserDescription, 
    F1b_MemoryRecallProcedure = lu_F1b.DisplayCode, F1b_MemoryRecallProcedureDesc = lu_F1b.UserDescription, 
    F2_CognitiveSkills = lu_F2.DisplayCode, F2_CognitiveSkillsDesc = lu_F2.UserDescription, 
    F3a_IndicatorsEasyDistract = lu_F3a.DisplayCode, F3a_IndicatorsEasyDistractDesc = lu_F3a.UserDescription, 
    F3b_IndicatorsAlteredPerception = lu_F3b.DisplayCode, F3b_IndicatorsAlteredPerceptionDesc = lu_F3b.UserDescription, 
    F3c_IndicatorsDisorganizedSpeech = lu_F3c.DisplayCode, F3c_IndicatorsDisorganizedSpeechDesc = lu_F3c.UserDescription, 
    F3d_IndicatorsRestlessness = lu_F3d.DisplayCode, F3d_IndicatorsRestlessnessDesc = lu_F3d.UserDescription, 
    F3e_IndicatorsLethargy = lu_F3e.DisplayCode, F3e_IndicatorsLethargyDesc = lu_F3e.UserDescription, 
    F3f_IndicatorsMentalFunction = lu_F3f.DisplayCode, F3f_IndicatorsMentalFunctionDesc = lu_F3f.UserDescription, 
    F4_CognitiveDecline = LU_F4.DisplayCode, F4_CognitiveDeclineDesc = LU_F4.UserDescription, 

    SectionFSignedOff = (CASE OMHRS_SecF.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionFSignedOff_Desc = (CASE OMHRS_SecF.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionFSignedOffCoder = LU_SignOffCoder_F.DisplayCode, SectionFSignedOffCoderDesc = LU_SignOffCoder_F.UserDescription, 
    SectionFSignedOffDate = OMHRS_SecF.SignDate, 

[    **** SECTION G ****] = '''',
    G1a_ADLPersonalHygiene = lu_G1a.DisplayCode, G1a_ADLPersonalHygieneDesc = lu_G1a.UserDescription, 
    G1b_ADLWalking = lu_G1b.DisplayCode, G1b_ADLWalkingDesc = lu_G1b.UserDescription, 
    G1c_ADLWheeling = lu_G1c.DisplayCode, G1c_ADLWheelingDesc = lu_G1c.UserDescription, 
    G1d_ADLToiletUse = lu_G1d.DisplayCode, G1d_ADLToiletUseDesc = lu_G1d.UserDescription, 
    G1e_ADLEating = lu_G1e.DisplayCode, G1e_ADLEatingDesc = lu_G1e.UserDescription, 
    G2a_IADLMealPreparation = lu_G2a.DisplayCode, G2a_IADLMealPreparationDesc = lu_G2a.UserDescription, 
    G2b_IADLManagingMedications = lu_G2b.DisplayCode, G2b_IADLManagingMedicationsDesc = lu_G2b.UserDescription, 
    G2c_IADLTransportation = lu_G2c.DisplayCode, G2c_IADLTransportationDesc = lu_G2c.UserDescription, 
    G2d_IADLManagingFinances = lu_G2d.DisplayCode, G2d_IADLManagingFinancesDesc = lu_G2d.UserDescription, 
    G2e_IADLPhoneUse = lu_G2e.DisplayCode, G2e_IADLPhoneUseDesc = lu_G2e.UserDescription, 
    G3_Stamina = lu_G3.DisplayCode, G3_StaminaDesc = lu_G3.UserDescription, 
    G4_ADLDecline = (CASE dbo.OMHRS_SecG.G4 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    G4_ADLDeclineDesc = (CASE dbo.OMHRS_SecG.G4 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    
    SectionGSignedOff = (CASE OMHRS_SecG.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionGSignedOff_Desc = (CASE OMHRS_SecG.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionGSignedOffCoder = LU_SignOffCoder_G.DisplayCode, SectionGSignedOffCoderDesc = LU_SignOffCoder_G.UserDescription, 
    SectionGSignedOffDate = OMHRS_SecG.SignDate, 

[    **** SECTION H ****] = '''',
    H1_Hearing = lu_H1.DisplayCode, H1_HearingDesc = lu_H1.UserDescription, 
    H2_Vision = lu_H2.DisplayCode, H2_VisionDesc = lu_H2.UserDescription, 
    H3_MakingSelfUnderstood = lu_H3.DisplayCode, H3_MakingSelfUnderstoodDesc = lu_H3.UserDescription, 

    SectionHSignedOff = (CASE OMHRS_SecH.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionHSignedOff_Desc = (CASE OMHRS_SecH.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionHSignedOffCoder = LU_SignOffCoder_H.DisplayCode, SectionHSignedOffCoderDesc = LU_SignOffCoder_H.UserDescription, 
    SectionHSignedOffDate = OMHRS_SecH.SignDate, 

[    **** SECTION I ****] = '''',
    I1a_Headache = (CASE dbo.OMHRS_SecI.I1a WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    I1a_HeadacheDesc = (CASE dbo.OMHRS_SecI.I1a WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    I1b_DizzinessVertigo = (CASE dbo.OMHRS_SecI.I1b WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    I1b_DizzinessVertigoDesc = (CASE dbo.OMHRS_SecI.I1b WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    I1c_ShortnessOfBreath = (CASE dbo.OMHRS_SecI.I1c WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    I1c_ShortnessOfBreathDesc = (CASE dbo.OMHRS_SecI.I1c WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    I1d_ChestPainPressure = (CASE dbo.OMHRS_SecI.I1d WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    I1d_ChestPainPressureDesc = (CASE dbo.OMHRS_SecI.I1d WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    I1e_BlurredVision = (CASE dbo.OMHRS_SecI.I1e WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    I1e_BlurredVisionDesc = (CASE dbo.OMHRS_SecI.I1e WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    I1f_DryMouth = (CASE dbo.OMHRS_SecI.I1f WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN  LU_538_2.DisplayCode ELSE '''' END), 
    I1f_DryMouthDesc = (CASE dbo.OMHRS_SecI.I1f WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN  200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    I1g_InOrDecreaseAppetite = (CASE dbo.OMHRS_SecI.I1g WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    I1g_InOrDecreaseAppetiteDesc = (CASE dbo.OMHRS_SecI.I1g WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    I1h_DifficultyUrinating = (CASE dbo.OMHRS_SecI.I1h WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    I1h_DifficultyUrinatingDesc = (CASE dbo.OMHRS_SecI.I1h WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    I1i_Nausea = (CASE dbo.OMHRS_SecI.I1i WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    I1i_NauseaDesc = (CASE dbo.OMHRS_SecI.I1i WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    I1j_Vomiting = (CASE dbo.OMHRS_SecI.I1j WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    I1j_VomitingDesc = (CASE dbo.OMHRS_SecI.I1j WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    I1k_Constipation = (CASE dbo.OMHRS_SecI.I1k WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    I1k_ConstipationDesc = (CASE dbo.OMHRS_SecI.I1k WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    I1l_Diarrhea = (CASE dbo.OMHRS_SecI.I1l WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    I1l_DiarrheaDesc = (CASE dbo.OMHRS_SecI.I1l WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    I1m_DaytimeDrowsiness = (CASE dbo.OMHRS_SecI.I1m WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    I1m_DaytimeDrowsinessDesc = (CASE dbo.OMHRS_SecI.I1m WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    I1n_FatigueWeakness = (CASE dbo.OMHRS_SecI.I1n WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    I1n_FatigueWeaknessDesc = (CASE dbo.OMHRS_SecI.I1n WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    I1o_ImpariedBalanceAtaxia = (CASE dbo.OMHRS_SecI.I1o WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    I1o_ImpariedBalanceAtaxiaDesc = (CASE dbo.OMHRS_SecI.I1o WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    I1p_EmergentConditions = (CASE dbo.OMHRS_SecI.I1p WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    I1p_EmergentConditionsDesc = (CASE dbo.OMHRS_SecI.I1p WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 
    I1q_Edema = (CASE dbo.OMHRS_SecI.I1q WHEN 200183 THEN LU_538_0.DisplayCode WHEN 200184 THEN LU_538_1.DisplayCode WHEN 200185 THEN LU_538_2.DisplayCode ELSE '''' END), 
    I1q_EdemaDesc = (CASE dbo.OMHRS_SecI.I1q WHEN 200183 THEN LU_538_0.UserDescription WHEN 200184 THEN LU_538_1.UserDescription WHEN 200185 THEN LU_538_2.UserDescription ELSE '''' END), 

    I2a_Akathisia = (CASE dbo.OMHRS_SecI.I2a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    I2a_AkathisiaDesc = (CASE dbo.OMHRS_SecI.I2a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    I2b_Dyskinesia = (CASE dbo.OMHRS_SecI.I2b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    I2b_DyskinesiaDesc = (CASE dbo.OMHRS_SecI.I2b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    I2c_Tremor = (CASE dbo.OMHRS_SecI.I2c WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    I2c_TremorDesc = (CASE dbo.OMHRS_SecI.I2c WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    I2d_Rigidity = (CASE dbo.OMHRS_SecI.I2d WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    I2d_RigidityDesc = (CASE dbo.OMHRS_SecI.I2d WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    I2e_SlowShufflingGait = (CASE dbo.OMHRS_SecI.I2e WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    I2e_SlowShufflingGaitDesc = (CASE dbo.OMHRS_SecI.I2e WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    I2f_Bradykinesia = (CASE dbo.OMHRS_SecI.I2f WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    I2f_BradykinesiaDesc = (CASE dbo.OMHRS_SecI.I2f WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    I2g_Dystonia = (CASE dbo.OMHRS_SecI.I2g WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    I2g_DystoniaDesc = (CASE dbo.OMHRS_SecI.I2g WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 

    I3_SexualFunctioning = (CASE dbo.OMHRS_SecI.I3 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    I3_SexualFunctioningDesc = (CASE dbo.OMHRS_SecI.I3 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    I4_SelfRatedHealth = (CASE dbo.OMHRS_SecI.I4 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    I4_SelfRatedHealthDesc = (CASE dbo.OMHRS_SecI.I4 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    I5_ChewingSwallowing = (CASE dbo.OMHRS_SecI.I5 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    I5_ChewingSwallowingDesc = (CASE dbo.OMHRS_SecI.I5 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    I6_SkinOrFootProblem = (CASE dbo.OMHRS_SecI.I6 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    I6_SkinOrFootProblemDesc = (CASE dbo.OMHRS_SecI.I6 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    --ED - 02277
    I6aa_MajorSkinProblems = (CASE dbo.OMHRS_SecI.I6aa WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    I6aa_MajorSkinProblemsDesc = (CASE dbo.OMHRS_SecI.I6aa WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    I6ab_OtherSkinProblems = (CASE dbo.OMHRS_SecI.I6ab WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    I6ab_OtherSkinProblemsDesc = (CASE dbo.OMHRS_SecI.I6ab WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    I6b_FootProblems = LU_I6b.DisplayCode, I6b_FootProblemsDesc = LU_I6b.UserDescription, 
    
    I7_Falls = (CASE dbo.OMHRS_SecI.I7 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    I7_FallsDesc = (CASE dbo.OMHRS_SecI.I7 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    --ED - 01914
    I7a_HistoryOfFalls = LU_I7a.DisplayCode, I7a_HistoryOfFallsDesc = LU_I7a.UserDescription, 
    --ED - 01914
    I7b_RecentFalls = (CASE dbo.OMHRS_SecI.I7b WHEN 200913 THEN ''0'' WHEN 200914 THEN ''1'' When 200915 then ''8'' ELSE '''' END), 
    I7b_RecentFallsDesc = (CASE dbo.OMHRS_SecI.I7b WHEN 200913 THEN ''No'' WHEN 200914 THEN ''Yes'' when 200915 then ''Not applicable (first assessment, or more than 30 days since last assessment)'' ELSE '''' END),

    I8a_PainFrequency = lu_I8a.DisplayCode, I8a_PainFrequencyDesc = lu_I8a.UserDescription, 
    I8b_PainIntensity = lu_I8b.DisplayCode, I8b_PainIntensityDesc = lu_I8b.UserDescription, 
    I9_BladderContinence = lu_I9.DisplayCode, I9_BladderContinenceDesc = lu_I9.UserDescription, 
    I10_BowelContinence = lu_I10.DisplayCode, I10_BowelContinenceDesc = lu_I10.UserDescription, 

    X11_PresenceMedicalDiag = (CASE dbo.OMHRS_SecI.X11 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    X11_PresenceMedicalDiagDesc = (CASE dbo.OMHRS_SecI.X11 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    --ED - 01914
    I11a_MedicalDiagnoseDiabetesType1 = (CASE dbo.OMHRS_SecI.I11a WHEN 200907 THEN LU_576_1.DisplayCode WHEN 200906 THEN LU_576_0.DisplayCode WHEN 200908 THEN LU_576_8.DisplayCode ELSE '''' END), 
    I11a_MedicalDiagnoseDiabetesType1Desc = (CASE dbo.OMHRS_SecI.I11a WHEN 200907 THEN LU_576_1.UserDescription WHEN 200906 THEN LU_576_0.UserDescription WHEN 200908 THEN LU_576_8.UserDescription  ELSE '''' END), 
    I11b_MedicalDiagnoseDiabetesType2 = (CASE dbo.OMHRS_SecI.I11b WHEN 200907 THEN LU_576_1.DisplayCode WHEN 200906 THEN LU_576_0.DisplayCode WHEN 200908 THEN LU_576_8.DisplayCode ELSE '''' END), 
    I11b_MedicalDiagnoseDiabetesType2Desc = (CASE dbo.OMHRS_SecI.I11b WHEN 200907 THEN LU_576_1.UserDescription WHEN 200906 THEN LU_576_0.UserDescription WHEN 200908 THEN LU_576_8.UserDescription  ELSE '''' END), 
    I11c_MedicalDiagnoseChronicObstructivePulmonaryDisease = (CASE dbo.OMHRS_SecI.I11c WHEN 200907 THEN LU_576_1.DisplayCode WHEN 200906 THEN LU_576_0.DisplayCode WHEN 200908 THEN LU_576_8.DisplayCode ELSE '''' END), 
    I11c_MedicalDiagnoseChronicObstructivePulmonaryDiseaseDesc = (CASE dbo.OMHRS_SecI.I11c WHEN 200907 THEN LU_576_1.UserDescription WHEN 200906 THEN LU_576_0.UserDescription WHEN 200908 THEN LU_576_8.UserDescription  ELSE '''' END), 
    I11d_MedicalDiagnoseCongestiveHeartFailure = (CASE dbo.OMHRS_SecI.I11d WHEN 200907 THEN LU_576_1.DisplayCode WHEN 200906 THEN LU_576_0.DisplayCode WHEN 200908 THEN LU_576_8.DisplayCode ELSE '''' END), 
    I11d_MedicalDiagnoseCongestiveHeartFailureDesc = (CASE dbo.OMHRS_SecI.I11d WHEN 200907 THEN LU_576_1.UserDescription WHEN 200906 THEN LU_576_0.UserDescription WHEN 200908 THEN LU_576_8.UserDescription  ELSE '''' END), 
    I11e_MedicalDiagnoseChronicRenalFailureDialysis = (CASE dbo.OMHRS_SecI.I11e WHEN 200907 THEN LU_576_1.DisplayCode WHEN 200906 THEN LU_576_0.DisplayCode WHEN 200908 THEN LU_576_8.DisplayCode ELSE '''' END), 
    I11e_MedicalDiagnoseChronicRenalFailureDialysisDesc = (CASE dbo.OMHRS_SecI.I11e WHEN 200907 THEN LU_576_1.UserDescription WHEN 200906 THEN LU_576_0.UserDescription WHEN 200908 THEN LU_576_8.UserDescription  ELSE '''' END), 
    I11f_MedicalDiagnoseHIV = (CASE dbo.OMHRS_SecI.I11f WHEN 200907 THEN LU_576_1.DisplayCode WHEN 200906 THEN LU_576_0.DisplayCode WHEN 200908 THEN LU_576_8.DisplayCode ELSE '''' END), 
    I11f_MedicalDiagnoseHIVDesc = (CASE dbo.OMHRS_SecI.I11f WHEN 200907 THEN LU_576_1.UserDescription WHEN 200906 THEN LU_576_0.UserDescription WHEN 200908 THEN LU_576_8.UserDescription  ELSE '''' END), 
    I11g_MedicalDiagnoseHepatitisC = (CASE dbo.OMHRS_SecI.I11g WHEN 200907 THEN LU_576_1.DisplayCode WHEN 200906 THEN LU_576_0.DisplayCode WHEN 200908 THEN LU_576_8.DisplayCode ELSE '''' END), 
    I11g_MedicalDiagnoseHepatitisCDesc = (CASE dbo.OMHRS_SecI.I11g WHEN 200907 THEN LU_576_1.UserDescription WHEN 200906 THEN LU_576_0.UserDescription WHEN 200908 THEN LU_576_8.UserDescription  ELSE '''' END), 

    SectionISignedOff = (CASE OMHRS_SecI.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionISignedOff_Desc = (CASE OMHRS_SecI.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionISignedOffCoder = LU_SignOffCoder_I.DisplayCode, SectionISignedOffCoderDesc = LU_SignOffCoder_I.UserDescription, 
    SectionISignedOffDate = OMHRS_SecI.SignDate, 

[    **** SECTION J ****] = '''',
    J1a_LifeEventAccident = (CASE dbo.OMHRS_SecJ.J1a WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1a_LifeEventAccidentDesc = (CASE dbo.OMHRS_SecJ.J1a WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    J1b_LifeEventDistressed = (CASE dbo.OMHRS_SecJ.J1b WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1b_LifeEventDistressedDesc = (CASE dbo.OMHRS_SecJ.J1b WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    J1c_LifeEventDeathFamily = (CASE dbo.OMHRS_SecJ.J1c WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1c_LifeEventDeathFamilyDesc = (CASE dbo.OMHRS_SecJ.J1c WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    J1d_LifeEventChildCustody = (CASE dbo.OMHRS_SecJ.J1d WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1d_LifeEventChildCustodyDesc = (CASE dbo.OMHRS_SecJ.J1d WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    J1e_LifeEventConflictLaden = (CASE dbo.OMHRS_SecJ.J1e WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1e_LifeEventConflictLadenDesc = (CASE dbo.OMHRS_SecJ.J1e WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    J1f_LifeEventFailedEducate = (CASE dbo.OMHRS_SecJ.J1f WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1f_LifeEventFailedEducateDesc = (CASE dbo.OMHRS_SecJ.J1f WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    J1g_LifeEventLossIncome = (CASE dbo.OMHRS_SecJ.J1g WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1g_LifeEventLossIncomeDesc = (CASE dbo.OMHRS_SecJ.J1g WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    J1h_LifeEventOrganizational = (CASE dbo.OMHRS_SecJ.J1h WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1h_LifeEventOrganizationalDesc = (CASE dbo.OMHRS_SecJ.J1h WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    --ED - 01914
    J1h_2009_LifeEventReviewHearing = (CASE dbo.OMHRS_SecJ.J1h_2009 WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1h_2009_LifeEventReviewHearingDesc = (CASE dbo.OMHRS_SecJ.J1h_2009 WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 

    J1i_LifeEventReviewHearing = (CASE dbo.OMHRS_SecJ.J1i WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1i_LifeEventReviewHearingDesc = (CASE dbo.OMHRS_SecJ.J1i WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    --ED - 01914
    J1i_2009_LifeEventImmigration = (CASE dbo.OMHRS_SecJ.J1i_2009 WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1i_2009_LifeEventImmigrationDesc = (CASE dbo.OMHRS_SecJ.J1i_2009 WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 

    J1j_LifeEventImmigration = (CASE dbo.OMHRS_SecJ.J1j WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1j_LifeEventImmigrationDesc = (CASE dbo.OMHRS_SecJ.J1j WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    --ED - 01914
    J1j_2009_LifeEventLivedWarZone = (CASE dbo.OMHRS_SecJ.J1j_2009 WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1j_2009_LifeEventLivedWarZoneDesc = (CASE dbo.OMHRS_SecJ.J1j_2009 WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 

    J1k_LifeEventLivedWarZone = (CASE dbo.OMHRS_SecJ.J1k WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1k_LifeEventLivedWarZoneDesc = (CASE dbo.OMHRS_SecJ.J1k WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    --ED - 01914
    J1k_2009_LifeEventWitness = (CASE dbo.OMHRS_SecJ.J1k_2009 WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1k_2009_LifeEventWitnessDesc = (CASE dbo.OMHRS_SecJ.J1k_2009 WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 

    J1l_LifeEventWitness = (CASE dbo.OMHRS_SecJ.J1l WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1l_LifeEventWitnessDesc = (CASE dbo.OMHRS_SecJ.J1l WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    --ED - 01914
    J1l_2009_LifeEventVictimCrime = (CASE dbo.OMHRS_SecJ.J1l_2009 WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1l_2009_LifeEventVictimCrimeDesc = (CASE dbo.OMHRS_SecJ.J1l_2009 WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 

    J1n_LifeEventSexualAbuse = (CASE dbo.OMHRS_SecJ.J1n WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1n_LifeEventSexualAbuseDesc = (CASE dbo.OMHRS_SecJ.J1n WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    --ED - 01914
    J1n_2009_LifeEventPhysicalAbuse = (CASE dbo.OMHRS_SecJ.J1h_2009 WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1n_2009_LifeEventPhysicalAbuseDesc = (CASE dbo.OMHRS_SecJ.J1n_2009 WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 

    J1m_LifeEventVictimCrime = (CASE dbo.OMHRS_SecJ.J1m WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1m_LifeEventVictimCrimeDesc = (CASE dbo.OMHRS_SecJ.J1m WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    --ED - 01914
    J1m_2009_LifeEventSexualAbuse = (CASE dbo.OMHRS_SecJ.J1m_2009 WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1m_2009_LifeEventSexualAbuseDesc = (CASE dbo.OMHRS_SecJ.J1m_2009 WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 

    J1o_LifeEventPhysicalAbuse = (CASE dbo.OMHRS_SecJ.J1o WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1o_LifeEventPhysicalAbuseDesc = (CASE dbo.OMHRS_SecJ.J1o WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    --ED - 01914
    J1o_2009_LifeEventEmotional = (CASE dbo.OMHRS_SecJ.J1o_2009 WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1o_2009_LifeEventEmotionalDesc = (CASE dbo.OMHRS_SecJ.J1o_2009 WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 

    J1p_LifeEventEmotional = (CASE dbo.OMHRS_SecJ.J1p WHEN 200202 THEN LU_542_0.DisplayCode WHEN 200203 THEN LU_542_1.DisplayCode WHEN 200204 THEN LU_542_2.DisplayCode WHEN 200205 THEN LU_542_3.DisplayCode WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1p_LifeEventEmotionalDesc = (CASE dbo.OMHRS_SecJ.J1p WHEN 200202 THEN LU_542_0.UserDescription WHEN 200203 THEN LU_542_1.UserDescription WHEN 200204 THEN LU_542_2.UserDescription WHEN 200205 THEN LU_542_3.UserDescription WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 
    --ED - 01914
    J1p_2009_LifeEventParentalAbuse = (CASE dbo.OMHRS_SecJ.J1p_2009 WHEN 200900 THEN ''0'' WHEN 200901 THEN ''1'' WHEN 200902 THEN ''2'' WHEN 200903 THEN ''3'' WHEN 200904 THEN ''4'' WHEN 200905 THEN ''5'' ELSE '''' END), 
    J1p_2009_LifeEventParentalAbuseDesc = (CASE dbo.OMHRS_SecJ.J1p_2009 WHEN 200900 THEN ''Never'' WHEN 200901 THEN ''More than 1 year ago'' WHEN 200902 THEN ''31 days – 1 year ago'' WHEN 200903 THEN ''8 – 30 days ago'' WHEN 200904 THEN ''4 – 7 days ago'' WHEN 200905 THEN ''In last 3 days'' ELSE '''' END), 

    J2_ResponseToLifeEvents = (CASE dbo.OMHRS_SecJ.J2 when 200897	then ''0'' when 200898 then ''1'' when 200899 then ''8'' else '''' end), 
    J2_ResponseToLifeEventsDesc = (CASE dbo.OMHRS_SecJ.J2 when 200897	then ''No or not applicable'' when 200898	then ''Yes'' when 200899 then ''Could not (would not) respond'' else '''' end), 
    J3a_OtherIndicatorsHistory = (CASE dbo.OMHRS_SecJ.J3a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    J3a_OtherIndicatorsHistoryDesc = (CASE dbo.OMHRS_SecJ.J3a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    J3b_OtherIndicatorsFearful = (CASE dbo.OMHRS_SecJ.J3b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    J3b_OtherIndicatorsFearfulDesc = (CASE dbo.OMHRS_SecJ.J3b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 

    SectionJSignedOff = (CASE OMHRS_SecJ.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionJSignedOff_Desc = (CASE OMHRS_SecJ.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionJSignedOffCoder = LU_SignOffCoder_J.DisplayCode, SectionJSignedOffCoderDesc = LU_SignOffCoder_J.UserDescription, 
    SectionJSignedOffDate = OMHRS_SecJ.SignDate, 

[    **** SECTION K ****] = '''',
    K1_HistoryOfMedicationAdherence = lu_K1.DisplayCode, K1_HistoryOfMedicationAdherenceDesc = lu_K1.UserDescription, 
    K2_MedicalRefusal = (CASE dbo.OMHRS_SecK.K2 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    K2_MedicalRefusalDesc = (CASE dbo.OMHRS_SecK.K2 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    --ED - 02278
    K3_PastMedicationSideEffects = lu_K3.DisplayCode, K3_PastMedicationSideEffectsDesc = lu_K3.UserDescription, 
    --K3_PastMedicationSideEffects = (CASE dbo.OMHRS_SecK.K3 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    --K3_PastMedicationSideEffectsDesc = (CASE dbo.OMHRS_SecK.K3 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    K4_IntentionalMisuseMedication = (CASE dbo.OMHRS_SecK.K4 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    K4_IntentionalMisuseMedicationDesc = (CASE dbo.OMHRS_SecK.K4 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    K5_AcuteControlMedications = OMHRS_SecK.K5, 
    K6_AllergyToDrugs = (CASE dbo.OMHRS_SecK.K6 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    K6_AllergyToDrugsDesc = (CASE dbo.OMHRS_SecK.K6 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    
    SectionKSignedOff = (CASE OMHRS_SecK.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionKSignedOff_Desc = (CASE OMHRS_SecK.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionKSignedOffCoder = LU_SignOffCoder_K.DisplayCode, SectionKSignedOffCoderDesc = LU_SignOffCoder_K.UserDescription, 
    SectionKSignedOffDate = OMHRS_SecK.SignDate, 

[    **** SECTION L ****] = '''',
    L1a_FormalCarePsychiatr = lu_L1a.DisplayCode, L1a_FormalCarePsychiatrDesc = lu_L1a.UserDescription, 
    L1b_FormalCareNursePractitioner = lu_L1b.DisplayCode, L1b_FormalCareNursePractitionerDesc = lu_L1b.UserDescription, 
    L1c_FormalCareSocialWorker = lu_L1c.DisplayCode, L1c_FormalCareSocialWorkerDesc = lu_L1c.UserDescription, 
    L1d_FormalCarePsychologist = lu_L1d.DisplayCode, L1d_FormalCarePsychologistDesc = lu_L1d.UserDescription, 
    L1e_FormalCareOccupationalTherapist = lu_L1e.DisplayCode, L1e_FormalCareOccupationalTherapistDesc = lu_L1e.UserDescription, 
    L1f_FormalCareRecreationTherapist = lu_L1f.DisplayCode, L1f_FormalCareRecreationTherapistDesc = lu_L1f.UserDescription, 
    L1g_FormalCareAddictionCousellor = lu_L1g.DisplayCode, L1g_FormalCareAddictionCousellorDesc = lu_L1g.UserDescription, 
    L1h_FormalCareDietician = lu_L1h.DisplayCode, L1h_FormalCareDieticianDesc = lu_L1h.UserDescription, 
    L2a_NursingMedicalIntervention = lu_L2a.DisplayCode, L2a_NursingMedicalInterventionDesc = lu_L2a.UserDescription, 
    L2b_NursingCounselling = lu_L2b.DisplayCode, L2b_NursingCounsellingDesc = lu_L2b.UserDescription, 
    L2c_NursingCrisisIntervention = lu_L2c.DisplayCode, L2c_NursingCrisisInterventionDesc = lu_L2c.UserDescription, 
    L2d_NursingFamilySupport = lu_L2d.DisplayCode, L2d_NursingFamilySupportDesc = lu_L2d.UserDescription, 
    L3a_TreatmentIndividTherapy = lu_L3a.DisplayCode, L3a_TreatmentIndividTherapyDesc = lu_L3a.UserDescription, 
    L3b_TreatmentGroupTherapy = lu_L3b.DisplayCode, L3b_TreatmentGroupTherapyDesc = lu_L3b.UserDescription, 
    L3c_TreatmentFamilyTherapy = lu_L3c.DisplayCode, L3c_TreatmentFamilyTherapyDesc = lu_L3c.UserDescription, 
    L3d_TreatmentSelfHelp = lu_L3d.DisplayCode, L3d_TreatmentSelfHelpDesc = lu_L3d.UserDescription, 
    L4a_FocusInterventionCommunity = (CASE dbo.OMHRS_SecL.L4a WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    L4a_FocusInterventionCommunityDesc = (CASE dbo.OMHRS_SecL.L4a WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200216 THEN LU_546_3.UserDescription ELSE '''' END), 
    L4b_FocusInterventionSocial = (CASE dbo.OMHRS_SecL.L4b WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    L4b_FocusInterventionSocialDesc = (CASE dbo.OMHRS_SecL.L4b WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200216 THEN LU_546_3.UserDescription ELSE '''' END), 
    L4c_FocusInterventionPsychosocial = (CASE dbo.OMHRS_SecL.L4c WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    L4c_FocusInterventionPsychosocialDesc = (CASE dbo.OMHRS_SecL.L4c WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200216 THEN LU_546_3.UserDescription ELSE '''' END), 
    L4d_FocusInterventionDetoxification = (CASE dbo.OMHRS_SecL.L4d WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    L4d_FocusInterventionDetoxificationDesc = (CASE dbo.OMHRS_SecL.L4d WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200216 THEN LU_546_3.UserDescription ELSE '''' END), 
    L4e_FocusInterventionAlcohol = (CASE dbo.OMHRS_SecL.L4e WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    L4e_FocusInterventionAlcoholDesc = (CASE dbo.OMHRS_SecL.L4e WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200216 THEN LU_546_3.UserDescription ELSE '''' END), 
    L4f_FocusInterventionVocational = (CASE dbo.OMHRS_SecL.L4f WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    L4f_FocusInterventionVocationalDesc = (CASE dbo.OMHRS_SecL.L4f WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200216 THEN LU_546_3.UserDescription ELSE '''' END), 
    L4g_FocusInterventionAngerManagement = (CASE dbo.OMHRS_SecL.L4g WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    L4g_FocusInterventionAngerManagementDesc = (CASE dbo.OMHRS_SecL.L4g WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200216 THEN LU_546_3.UserDescription ELSE '''' END), 
    L4h_FocusInterventionEatingDisorder = (CASE dbo.OMHRS_SecL.L4h WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    L4h_FocusInterventionEatingDisorderDesc = (CASE dbo.OMHRS_SecL.L4h WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200216 THEN LU_546_3.UserDescription ELSE '''' END), 
    L4i_FocusInterventionBehaviour = (CASE dbo.OMHRS_SecL.L4i WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    L4i_FocusInterventionBehaviourDesc = (CASE dbo.OMHRS_SecL.L4i WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200216 THEN LU_546_3.UserDescription ELSE '''' END), 
    L4j_FocusInterventionStress = (CASE dbo.OMHRS_SecL.L4j WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    L4j_FocusInterventionStressDesc = (CASE dbo.OMHRS_SecL.L4j WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200216 THEN LU_546_3.UserDescription ELSE '''' END), 
    L4k_FocusInterventionPainManagement = (CASE dbo.OMHRS_SecL.L4k WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    L4k_FocusInterventionPainManagementDesc = (CASE dbo.OMHRS_SecL.L4k WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200216 THEN LU_546_3.UserDescription ELSE '''' END), 
    L4l_FocusInterventioneAlternative = (CASE dbo.OMHRS_SecL.L4l WHEN 200216 THEN LU_546_0.DisplayCode WHEN 200217 THEN LU_546_1.DisplayCode WHEN 200218 THEN LU_546_2.DisplayCode WHEN 200219 THEN LU_546_3.DisplayCode ELSE '''' END), 
    L4l_FocusInterventioneAlternativeDesc = (CASE dbo.OMHRS_SecL.L4l WHEN 200216 THEN LU_546_0.UserDescription WHEN 200217 THEN LU_546_1.UserDescription WHEN 200218 THEN LU_546_2.UserDescription WHEN 200216 THEN LU_546_3.UserDescription ELSE '''' END), 
    L5_AdherenceTreatments = lu_L5.DisplayCode, L5_AdherenceTreatmentsDesc = lu_L5.UserDescription, 
    L6_ECT = lu_L6.DisplayCode, L6_ECTDesc = lu_L6.UserDescription, 
    --PR - 04999 
    X6_NumberOfECTs = OMHRS_SecA.X6, 

    SectionLSignedOff = (CASE OMHRS_SecL.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionLSignedOff_Desc = (CASE OMHRS_SecL.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionLSignedOffCoder = LU_SignOffCoder_L.DisplayCode, SectionLSignedOffCoderDesc = LU_SignOffCoder_L.UserDescription, 
    SectionLSignedOffDate = OMHRS_SecL.SignDate, 

[    **** SECTION M ****] = '''',
    M1a_MechanicalRestraint = lu_M1a.DisplayCode, M1a_MechanicalRestraintDesc = lu_M1a.UserDescription, 
    M1b_ChairPreventsRising = lu_M1b.DisplayCode, M1b_ChairPreventsRisingDesc = lu_M1b.UserDescription, 
    M1c_PhysicalRestraints = lu_M1c.DisplayCode, M1c_PhysicalRestraintsDesc = lu_M1c.UserDescription, 
    M1d_ConfinementToUnit = lu_M1d.DisplayCode, M1d_ConfinementToUnitDesc = lu_M1d.UserDescription, 
    M1e_ConfinementToRoom = lu_M1e.DisplayCode, M1e_ConfinementToRoomDesc = lu_M1e.UserDescription, 
    M1f_SeclusionRoom = lu_M1f.DisplayCode, M1f_SeclusionRoomDesc = lu_M1f.UserDescription, 
    M2a_Observation15Min = lu_M2a.DisplayCode, M2a_Observation15MinDesc = lu_M2a.UserDescription, 
    M2b_Observation5Min = lu_M2b.DisplayCode, M2b_Observation5MinDesc = lu_M2b.UserDescription, 
    M2c_ObservationLess1Hour = lu_M2c.DisplayCode, M2c_ObservationLess1HourDesc = lu_M2c.UserDescription, 
    M2d_ObservationMore1Hour = lu_M2d.DisplayCode, M2d_ObservationMore1HourDesc = lu_M2d.UserDescription,
    M3_PyschiatricICU = lu_M3.DisplayCode, M3_PyschiatricICUDesc = lu_M3.UserDescription, 
    M4a_AuthActivityOutFacilityWithStaff = lu_M4a.DisplayCode, M4a_AuthActivityOutFacilityWithStaffDesc = lu_M4a.UserDescription, 
    M4b_AuthActivityOutFacilityWithoutStaff = lu_M4b.DisplayCode, M4b_AuthActivityOutFacilityWithoutStaffDesc = lu_M4b.UserDescription, 

    SectionMSignedOff = (CASE OMHRS_SecM.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionMSignedOff_Desc = (CASE OMHRS_SecM.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionMSignedOffCoder = LU_SignOffCoder_M.DisplayCode, SectionMSignedOffCoderDesc = LU_SignOffCoder_M.UserDescription, 
    SectionMSignedOffDate = OMHRS_SecM.SignDate, 

[    **** SECTION N ****] = '''',
    N1a_Height = OMHRS_SecN.N1a, 
    N1b_Weight = OMHRS_SecN.N1b, 
    N2a_WeightLoss = (CASE dbo.OMHRS_SecN.N2a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    N2a_WeightLossDesc = (CASE dbo.OMHRS_SecN.N2a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    N2b_WeightGain = (CASE dbo.OMHRS_SecN.N2b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    N2b_WeightGainDesc = (CASE dbo.OMHRS_SecN.N2b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    N2c_InsufficientFluid = (CASE dbo.OMHRS_SecN.N2c WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    N2c_InsufficientFluidDesc = (CASE dbo.OMHRS_SecN.N2c WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    N2d_DecreaseInFood = (CASE dbo.OMHRS_SecN.N2d WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    N2d_DecreaseInFoodDesc = (CASE dbo.OMHRS_SecN.N2d WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    N3a_BingeEating = (CASE dbo.OMHRS_SecN.N3a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    N3a_BingeEatingDesc = (CASE dbo.OMHRS_SecN.N3a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    N3b_FearWeightGain = (CASE dbo.OMHRS_SecN.N3b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    N3b_FearWeightGainDesc = (CASE dbo.OMHRS_SecN.N3b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    N3c_Fasting = (CASE dbo.OMHRS_SecN.N3c WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    N3c_FastingDesc = (CASE dbo.OMHRS_SecN.N3c WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    N4_Polydipsia = (CASE dbo.OMHRS_SecN.N4 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    N4_PolydipsiaDesc = (CASE dbo.OMHRS_SecN.N4 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 

    SectionNSignedOff = (CASE OMHRS_SecN.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionNSignedOff_Desc = (CASE OMHRS_SecN.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionNSignedOffCoder = LU_SignOffCoder_N.DisplayCode, SectionNSignedOffCoderDesc = LU_SignOffCoder_N.UserDescription, 
    SectionNSignedOffDate = OMHRS_SecN.SignDate, 

[    **** SECTION O ****] = '''',
    O1_FamilyRoles = lu_O1.DisplayCode, O1_FamilyRolesDesc = lu_O1.UserDescription, 
    O2a_NoConfidant = (CASE dbo.OMHRS_SecO.O2a WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    O2a_NoConfidantDesc = (CASE dbo.OMHRS_SecO.O2a WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    O2b_FamilyOverwhelmed = (CASE dbo.OMHRS_SecO.O2b WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    O2b_FamilyOverwhelmedDesc = (CASE dbo.OMHRS_SecO.O2b WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    O2c_PatientHostileTowardFamily = (CASE dbo.OMHRS_SecO.O2c WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    O2c_PatientHostileTowardFamilyDesc = (CASE dbo.OMHRS_SecO.O2c WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    O2d_PatientHostileTowardPatient = (CASE dbo.OMHRS_SecO.O2d WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    O2d_PatientHostileTowardPatientDesc = (CASE dbo.OMHRS_SecO.O2d WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    O2e_FamilyHostileTowardPt = (CASE dbo.OMHRS_SecO.O2e WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    O2e_FamilyHostileTowardPtDesc = (CASE dbo.OMHRS_SecO.O2e WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    O2f_StaffFrustrationPatient = (CASE dbo.OMHRS_SecO.O2f WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    O2f_StaffFrustrationPatientDesc = (CASE dbo.OMHRS_SecO.O2f WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    --PR - 04246
    O2g_FamilyRequireUnusaulStaffTime = (CASE dbo.OMHRS_SecO.O2g WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    O2g_FamilyRequireUnusaulStaffTimeDesc = (CASE dbo.OMHRS_SecO.O2g WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    O3_EmploymentStatus = lu_O3.DisplayCode, O3_EmploymentStatusDesc = lu_O3.UserDescription, 
    O4a_IncreaseInLateness = lu_O4a.DisplayCode, O4a_IncreaseInLatenessDesc = lu_O4a.UserDescription, 
    O4b_PoorProductivity = lu_O4b.DisplayCode, O4b_PoorProductivityDesc = lu_O4b.UserDescription, 
    O4c_IntentToQuitWork = lu_O4c.DisplayCode, O4c_IntentToQuitWorkDesc = lu_O4c.UserDescription, 
    O4d_PersistentUnemployment = lu_O4d.DisplayCode, O4d_PersistentUnemploymentDesc = lu_O4d.UserDescription, 
    O5_TradeOffs = (CASE dbo.OMHRS_SecO.O5 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    O5_TradeOffsDesc = (CASE dbo.OMHRS_SecO.O5 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    O6a_ParticipateActivities = lu_O6a.DisplayCode, O6a_ParticipateActivitiesDesc = lu_O6a.UserDescription, 
    O6b_VisitByRelationFamily = lu_O6b.DisplayCode, O6b_VisitByRelationFamilyDesc = lu_O6b.UserDescription, 
    O6c_ContactRelationFamily = lu_O6c.DisplayCode, O6c_ContactRelationFamilyDesc = lu_O6c.UserDescription, 

    SectionOSignedOff = (CASE OMHRS_SecO.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionOSignedOff_Desc = (CASE OMHRS_SecO.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionOSignedOffCoder = LU_SignOffCoder_O.DisplayCode, SectionOSignedOffCoderDesc = LU_SignOffCoder_O.UserDescription, 
    SectionOSignedOffDate = OMHRS_SecO.SignDate, 

[    **** SECTION P ****] = '''',
    P1a_HelpWithChildcare = lu_P1a.DisplayCode, P1a_HelpWithChildcareDesc = lu_P1a.UserDescription, 
    P1b_SupervisePersonSafety = lu_P1b.DisplayCode, P1b_SupervisePersonSafetyDesc = lu_P1b.UserDescription, 
    P1c_CrisisSupport = lu_P1c.DisplayCode, P1c_CrisisSupportDesc = lu_P1c.UserDescription, 
    P1d_SupportWithADL_IADLs = lu_P1d.DisplayCode, P1d_SupportWithADL_IADLsDesc = lu_P1d.UserDescription, 
    P2a_DischargeReadinessReturnCommunity = lu_P2a.DisplayCode, P2a_DischargeReadinessReturnCommunityDesc = lu_P2a.UserDescription, 
    P2b_DischargeReadinessSupport = lu_P2b.DisplayCode, P2b_DischargeReadinessSupportDesc = lu_P2b.UserDescription, 
    --PR-02515 change TimePlannedDischarge_P3 to ProjTimePlannedDisch_P3
    P3_ProjectedTimePlannedDischarge = lu_P3.DisplayCode, P3_ProjectedTimePlannedDischargeDesc = lu_P3.UserDescription, 
    P4_OverallChangeCareNeeds = lu_P4.DisplayCode, P4_OverallChangeCareNeedsDesc = lu_P4.UserDescription, 
    P5_DischargedTo = lu_P5.DisplayCode, P5_DischargedToDesc = lu_P5.UserDescription, 
    X140_DischargedToFacility = lu_X140.DisplayCode, X140_DischargedToFacilityDesc = lu_X140.UserDescription, 

    X141_DischargedSupportHomeCare = (CASE dbo.OMHRS_SecP.X141 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END),
    X141_DischargedSupportHomeCareDesc = (CASE dbo.OMHRS_SecP.X141 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 

    SectionPSignedOff = (CASE OMHRS_SecP.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionPSignedOff_Desc = (CASE OMHRS_SecP.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionPSignedOffCoder = LU_SignOffCoder_P.DisplayCode, SectionPSignedOffCoderDesc = LU_SignOffCoder_P.UserDescription, 
    SectionPSignedOffDate = OMHRS_SecP.SignDate, 

[    **** SECTION Q ****] = '''',
    Q1a_DSMDisorderChildhood = (CASE dbo.OMHRS_SecQ.Q1a WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1a_DSMDisorderChildhoodDesc = (CASE dbo.OMHRS_SecQ.Q1a WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    Q1b_DSMDeliriumDisorder = (CASE dbo.OMHRS_SecQ.Q1b WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1b_DSMDeliriumDisorderDesc = (CASE dbo.OMHRS_SecQ.Q1b WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    Q1c_DSMMentalDisorder = (CASE dbo.OMHRS_SecQ.Q1c WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1c_DSMMentalDisorderDesc = (CASE dbo.OMHRS_SecQ.Q1c WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    Q1d_DSMSubstanceRelated = (CASE dbo.OMHRS_SecQ.Q1d WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1d_DSMSubstanceRelatedDesc = (CASE dbo.OMHRS_SecQ.Q1d WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    Q1e_DSMSchizophrenia = (CASE dbo.OMHRS_SecQ.Q1e WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1e_DSMSchizophreniaDesc = (CASE dbo.OMHRS_SecQ.Q1e WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    Q1f_DSMMoodDisorder = (CASE dbo.OMHRS_SecQ.Q1f WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1f_DSMMoodDisorderDesc = (CASE dbo.OMHRS_SecQ.Q1f WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    Q1g_DSMAnxietyDisorder = (CASE dbo.OMHRS_SecQ.Q1g WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1g_DSMAnxietyDisorderDesc = (CASE dbo.OMHRS_SecQ.Q1g WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    Q1h_DSMSomatoformDisorder = (CASE dbo.OMHRS_SecQ.Q1h WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1h_DSMSomatoformDisorderDesc = (CASE dbo.OMHRS_SecQ.Q1h WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    Q1i_DSMFactitiousDisorder = (CASE dbo.OMHRS_SecQ.Q1i WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1i_DSMFactitiousDisorderDesc = (CASE dbo.OMHRS_SecQ.Q1i WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    Q1j_DSMDissociative = (CASE dbo.OMHRS_SecQ.Q1j WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1j_DSMDissociativeDesc = (CASE dbo.OMHRS_SecQ.Q1j WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    Q1k_DSMSexualDisorder = (CASE dbo.OMHRS_SecQ.Q1k WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1k_DSMSexualDisorderDesc = (CASE dbo.OMHRS_SecQ.Q1k WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    Q1l_DSMEatingDisorder = (CASE dbo.OMHRS_SecQ.Q1l WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1l_DSMEatingDisorderDesc = (CASE dbo.OMHRS_SecQ.Q1l WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    Q1m_DSMSleepDisorder = (CASE dbo.OMHRS_SecQ.Q1m WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1m_DSMSleepDisorderDesc = (CASE dbo.OMHRS_SecQ.Q1m WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    Q1n_DSMImpulseDisorder = (CASE dbo.OMHRS_SecQ.Q1n WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1n_DSMImpulseDisorderDesc = (CASE dbo.OMHRS_SecQ.Q1n WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    Q1o_DSMAdjustmentDisorder = (CASE dbo.OMHRS_SecQ.Q1o WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1o_DSMAdjustmentDisorderDesc = (CASE dbo.OMHRS_SecQ.Q1o WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    Q1p_DSMPersonalityDisorder = (CASE dbo.OMHRS_SecQ.Q1p WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1p_DSMPersonalityDisorderDesc = (CASE dbo.OMHRS_SecQ.Q1p WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
    -- PR - 03738
    Q1q_DSMNotApplicable = (CASE dbo.OMHRS_SecQ.Q1q WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1q_DSMNotApplicableDesc = (CASE dbo.OMHRS_SecQ.Q1q WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	--2.x-0295
	Q1a_DSM_5_NeurodevelopmentalDisorders = (CASE dbo.OMHRS_SecQ.Q1a2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1a_DSM_5_NeurodevelopmentalDisordersDesc = (CASE dbo.OMHRS_SecQ.Q1a2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1b_DSM_5_SchizophreniaSpectrumDisorders = (CASE dbo.OMHRS_SecQ.Q1b2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1b_DSM_5_SchizophreniaSpectrumDisordersDesc = (CASE dbo.OMHRS_SecQ.Q1b2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1c_DSM_5_BipolarDisorders = (CASE dbo.OMHRS_SecQ.Q1c2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1c_DSM_5_BipolarDisordersDesc = (CASE dbo.OMHRS_SecQ.Q1c2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1d_DSM_5_DepressiveDisorders = (CASE dbo.OMHRS_SecQ.Q1d2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1d_DSM_5_DepressiveDisordersDesc = (CASE dbo.OMHRS_SecQ.Q1d2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1e_DSM_5_AnxietyDisorders = (CASE dbo.OMHRS_SecQ.Q1e2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1e_DSM_5_AnxietyDisordersDesc = (CASE dbo.OMHRS_SecQ.Q1e2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1f_DSM_5_ObsessiveCompulsiveDisorders = (CASE dbo.OMHRS_SecQ.Q1f2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1f_DSM_5_ObsessiveCompulsiveDisordersDesc = (CASE dbo.OMHRS_SecQ.Q1f2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1g_DSM_5_TraumaStressorDisorders = (CASE dbo.OMHRS_SecQ.Q1g2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1g_DSM_5_TraumaStressorDisordersDesc = (CASE dbo.OMHRS_SecQ.Q1g2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1h_DSM_5_DissociativetechDisorders = (CASE dbo.OMHRS_SecQ.Q1h2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1h_DSM_5_DissociativeDisordersDesc = (CASE dbo.OMHRS_SecQ.Q1h2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1i_DSM_5_SomaticSymptomDisorders = (CASE dbo.OMHRS_SecQ.Q1i2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1i_DSM_5_SomaticSymptomDisordersDesc = (CASE dbo.OMHRS_SecQ.Q1i2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1j_DSM_5_FeedingEatingDisorders = (CASE dbo.OMHRS_SecQ.Q1j2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1j_DSM_5_FeedingEatingDisordersDesc = (CASE dbo.OMHRS_SecQ.Q1j2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1k_DSM_5_EliminationDisorders = (CASE dbo.OMHRS_SecQ.Q1k2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1k_DSM_5_EliminationDisordersDesc = (CASE dbo.OMHRS_SecQ.Q1k2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1l_DSM_5_SleepWakeDisorders = (CASE dbo.OMHRS_SecQ.Q1l2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1l_DSM_5_SleepWakeDisordersDesc = (CASE dbo.OMHRS_SecQ.Q1l2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1m_DSM_5_SexualDysfunctions = (CASE dbo.OMHRS_SecQ.Q1m2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1m_DSM_5_SexualDysfunctionsDesc = (CASE dbo.OMHRS_SecQ.Q1m2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1n_DSM_5_GenderDysphoria = (CASE dbo.OMHRS_SecQ.Q1n2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1n_DSM_5_GenderDysphoriaDesc = (CASE dbo.OMHRS_SecQ.Q1n2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1o_DSM_5_DisruptiveDisorders = (CASE dbo.OMHRS_SecQ.Q1o2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1o_DSM_5_DisruptiveDisordersDesc = (CASE dbo.OMHRS_SecQ.Q1o2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1p_DSM_5_SubstanceAddictiveDisorders = (CASE dbo.OMHRS_SecQ.Q1p2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1p_DSM_5_SubstanceAddictiveDisordersDesc = (CASE dbo.OMHRS_SecQ.Q1p2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1q_DSM_5_NeurocognitiveDisorders = (CASE dbo.OMHRS_SecQ.Q1q2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1q_DSM_5_NeurocognitiveDisordersDesc = (CASE dbo.OMHRS_SecQ.Q1q2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1r_DSM_5_PersonalityDisorders = (CASE dbo.OMHRS_SecQ.Q1r2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1r_DSM_5_PersonalityDisordersDesc = (CASE dbo.OMHRS_SecQ.Q1r2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1s_DSM_5_ParaphilicDisorders = (CASE dbo.OMHRS_SecQ.Q1s2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1s_DSM_5_ParaphilicDisordersDesc = (CASE dbo.OMHRS_SecQ.Q1s2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1t_DSM_5_OtherMentalDisorders = (CASE dbo.OMHRS_SecQ.Q1t2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1t_DSM_5_OtherMentalDisordersDesc = (CASE dbo.OMHRS_SecQ.Q1t2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1u_DSM_5_MedicationInducedDisorders = (CASE dbo.OMHRS_SecQ.Q1u2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1u_DSM_5_MedicationInducedDisordersDesc = (CASE dbo.OMHRS_SecQ.Q1u2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 
	Q1v_DSM_5_NotApplicable = (CASE dbo.OMHRS_SecQ.Q1v2016 WHEN 200268 THEN LU_560_1.DisplayCode WHEN 200269 THEN LU_560_2.DisplayCode WHEN 200270 THEN LU_560_3.DisplayCode ELSE '''' END), 
    Q1v_DSM_5_NotApplicableDesc = (CASE dbo.OMHRS_SecQ.Q1v2016 WHEN 200268 THEN LU_560_1.UserDescription WHEN 200269 THEN LU_560_2.UserDescription WHEN 200270 THEN LU_560_3.UserDescription ELSE '''' END), 

    --ED - 02279
    --Q2d_AxisII_DSM_IVCode = lu_Q2d.DisplayCode, Q2d_AxisII_DSM_IVCodeDesc = lu_Q2d.UserDescription, 
    --Q2d_AxisII_DSM_IVText = OMHRS_SecQ.Q2dText, 
    --ED - 02156
    X7_PrimaryDiagnosis = LU_X7.DisplayCode, X7_PrimaryDiagnosisDesc = LU_X7.UserDescription, 

    Q3_IntellectualDisability = (CASE dbo.OMHRS_SecQ.Q3 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    Q3_IntellectualDisabilityDesc = (CASE dbo.OMHRS_SecQ.Q3 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 
    Q4_GAFScore = OMHRS_SecQ.Q4, 
    Q5_CurrentPatientType = lu_Q5.DisplayCode, Q5_CurrentPatientTypeDesc = lu_Q5.UserDescription, 

    SectionQSignedOff = (CASE OMHRS_SecQ.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionQSignedOff_Desc = (CASE OMHRS_SecQ.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionQSignedOffCoder = LU_SignOffCoder_Q.DisplayCode, SectionQSignedOffCoderDesc = LU_SignOffCoder_Q.UserDescription, 
    SectionQSignedOffDate = OMHRS_SecQ.SignDate, 

[    **** SECTION R ****] = '''',
    R1_PrescribedMedications = (CASE dbo.OMHRS_Secr.R1 WHEN 200379 THEN LU_570_Yes.DisplayCode WHEN 200380 THEN LU_570_No.DisplayCode ELSE '''' END), 
    R1_PrescribedMedicationsDesc = (CASE dbo.OMHRS_SecR.R1 WHEN 200379 THEN LU_570_Yes.UserDescription WHEN 200380 THEN LU_570_No.UserDescription ELSE '''' END), 

    SectionRSignedOff = (CASE OMHRS_SecR.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionRSignedOff_Desc = (CASE OMHRS_SecR.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionRSignedOffCoder = LU_SignOffCoder_R.DisplayCode, SectionRSignedOffCoderDesc = LU_SignOffCoder_R.UserDescription, 
    SectionRSignedOffDate = OMHRS_SecR.SignDate, 

[    **** SECTION S ****] = '''',
    X8a_AdmittedThroughEmergency = (CASE OMHRS_SecS.X8a WHEN 302111 THEN LU_606_0.DisplayCode WHEN 302112 THEN LU_606_1.DisplayCode ELSE '''' END), 
    X8a_AdmittedThroughEmergencyDesc = (CASE OMHRS_SecS.X8a WHEN 302111 THEN LU_606_0.UserDescription WHEN 302112 THEN LU_606_1.UserDescription ELSE '''' END), 
    X8b_ArrivedOnInpatientUnit = (CASE OMHRS_SecS.X8b WHEN 302111 THEN LU_606_0.DisplayCode WHEN 302112 THEN LU_606_1.DisplayCode ELSE '''' END), 
    X8b_ArrivedOnInpatientUnitDesc = (CASE OMHRS_SecS.X8b WHEN 302111 THEN LU_606_0.UserDescription WHEN 302112 THEN LU_606_1.UserDescription ELSE '''' END), 
    X8c_DateArrivedOnInpatientUnit = OMHRS_SecS.X8c, 

    X75_TotalDaysAlternativeLevel = OMHRS_SecS.X75, 
    X80_DischargeDate = OMHRS_SecS.X80, DischargeTime = OMHRS_SecS.DischargeTime, 
    X90_ReasonForDischarge = lu_X90.DisplayCode, X90_ReasonForDischargeDesc = lu_X90.UserDescription, 
    X121a_ServiceInterruptAcute = (CASE OMHRS_SecS.X121a WHEN 302101 THEN LU_605_0.DisplayCode WHEN 302102 THEN LU_605_1.DisplayCode ELSE '''' END), 
    X121a_ServiceInterruptAcuteDesc = (CASE OMHRS_SecS.X121a WHEN 302101 THEN LU_605_0.UserDescription WHEN 302102 THEN LU_605_1.UserDescription ELSE '''' END), 
    X121b_ServiceInterruptRehab = (CASE OMHRS_SecS.X121b WHEN 302101 THEN LU_605_0.DisplayCode WHEN 302102 THEN LU_605_1.DisplayCode ELSE '''' END), 
    X121b_ServiceInterruptRehabDesc = (CASE OMHRS_SecS.X121b WHEN 302101 THEN LU_605_0.UserDescription WHEN 302102 THEN LU_605_1.UserDescription ELSE '''' END), 
    X121c_ServiceInterruptLTC = (CASE OMHRS_SecS.X121c WHEN 302101 THEN LU_605_0.DisplayCode WHEN 302102 THEN LU_605_1.DisplayCode ELSE '''' END), 
    X121c_ServiceInterruptLTCDesc = (CASE OMHRS_SecS.X121c WHEN 302101 THEN LU_605_0.UserDescription WHEN 302102 THEN LU_605_1.UserDescription ELSE '''' END), 
    X121d_ServiceInterruptMH = (CASE OMHRS_SecS.X121d WHEN 302101 THEN LU_605_0.DisplayCode WHEN 302102 THEN LU_605_1.DisplayCode ELSE '''' END), 
    X121d_ServiceInterruptMHDesc = (CASE OMHRS_SecS.X121d WHEN 302101 THEN LU_605_0.UserDescription WHEN 302102 THEN LU_605_1.UserDescription ELSE '''' END), 
    X121e_ServiceInterruptCorrectional = (CASE OMHRS_SecS.X121e WHEN 302101 THEN LU_605_0.DisplayCode WHEN 302102 THEN LU_605_1.DisplayCode ELSE '''' END), 
    X121e_ServiceInterruptCorrectionalDesc = (CASE OMHRS_SecS.X121e WHEN 302101 THEN LU_605_0.UserDescription WHEN 302102 THEN LU_605_1.UserDescription ELSE '''' END), 
    X121f_ServiceInterruptAWOL30 = (CASE OMHRS_SecS.X121f WHEN 302101 THEN LU_605_0.DisplayCode WHEN 302102 THEN LU_605_1.DisplayCode ELSE '''' END), 
    X121f_ServiceInterruptAWOL30Desc = (CASE OMHRS_SecS.X121f WHEN 302101 THEN LU_605_0.UserDescription WHEN 302102 THEN LU_605_1.UserDescription ELSE '''' END), 
    X121g_ServiceInterruptLOA90 = (CASE OMHRS_SecS.X121g WHEN 302101 THEN LU_605_0.DisplayCode WHEN 302102 THEN LU_605_1.DisplayCode ELSE '''' END), 
    X121g_ServiceInterruptLOA90Desc = (CASE OMHRS_SecS.X121g WHEN 302101 THEN LU_605_0.UserDescription WHEN 302102 THEN LU_605_1.UserDescription ELSE '''' END), 
    X121h_ServiceInterruptOther = (CASE OMHRS_SecS.X121h WHEN 302101 THEN LU_605_0.DisplayCode WHEN 302102 THEN LU_605_1.DisplayCode ELSE '''' END), 
    X121h_ServiceInterruptOtherDesc = (CASE OMHRS_SecS.X121h WHEN 302101 THEN LU_605_0.UserDescription WHEN 302102 THEN LU_605_1.UserDescription ELSE '''' END), 

    X130_TotalDaysAwayFromBed = OMHRS_SecS.X130, 

    SectionSSignedOff = (CASE OMHRS_SecS.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.DisplayCode WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionSSignedOff_Desc = (CASE OMHRS_SecS.SignOff WHEN 1 THEN LU_YesNoSystem_Yes.UserDescription WHEN 2 THEN LU_YesNoSystem_No.UserDescription ELSE '''' END), 
    SectionSSignedOffCoder = LU_SignOffCoder_S.DisplayCode, SectionSSignedOffCoderDesc = LU_SignOffCoder_S.UserDescription, 
    SectionSSignedOffDate = OMHRS_SecS.SignDate, 
    
[    **** SECTION X ****] = '''',
    X1_RecordID = OMHRS_SecAA.X1, 
    X2_SubmissionType = lu_X2.DisplayCode, 
    X2_SubmissionTypeDesc = lu_X2.UserDescription, 
    Z1_RecordType = lu_z1.DisplayCode, Z1_RecordTypeDesc = lu_z1.UserDescription, 

----------------------------------
[    **** SECTION Outcome Scales ****] = '''',
    --ED - 01914
    AggressiveBehaviourScale_ABS = dbo.OMHRS_OutcomeScale.[ABS],
    CognitivePerformanceScale_CPS = dbo.OMHRS_OutcomeScale.CPS,
    DepressionRatingScale_DRS = dbo.OMHRS_OutcomeScale.DRS,
    ActivityDailyLivSelfPerformHierachy_ADLH = dbo.OMHRS_OutcomeScale.ADL_H,
    ActivityDailyLiviShortForm_ADLS = dbo.OMHRS_OutcomeScale.ADL_S,
    DepressiveSeverityIndex_DSI = dbo.OMHRS_OutcomeScale.DSI,
    RiskOfHarmToOthersScale_RHO = dbo.OMHRS_OutcomeScale.RHO,
    SelfCareIndex_SCI = dbo.OMHRS_OutcomeScale.SCI,
    SeverityOfSelfHarmScale_SOS = dbo.OMHRS_OutcomeScale.SOS,

[    **** SECTION CAPs ****] = '''',
    --ED - 02373
    HarmToOthers_HARMMOTH = OMHRS_CAPs.HARMOTH,
    SuicidalityAndPurposefulSelfHarm_SELFHARM = OMHRS_CAPs.SELFHARM,
    SelfCare_SELFCR = OMHRS_CAPs.SELFCR,
    SocialRelationships_SOCREL = OMHRS_CAPs.SOCREL,
    SupportSystemsForDischarge_SSDIS = OMHRS_CAPs.SSDIS,
    InterpersonalConflict_IPCON = OMHRS_CAPs.IPCON,
    TraumaticLifeEvents_TRAUMA = OMHRS_CAPs.TRAUMA,
    CriminalActivity_CRIM = OMHRS_CAPs.CRIM,
    FinancialIssues_FINAN = OMHRS_CAPs.FINAN,
    VocationalRehabilitation_VOCREH = OMHRS_CAPs.VOCREH,
    ControlInterventions_CTRLINT = OMHRS_CAPs.CTRLINT,
    MedicationManagementAndAdherence_MEDMGT = OMHRS_CAPs.MEDMGT,
    Rehospitalization_REHOSP = OMHRS_CAPs.REHOSP,
    TobaccoUse_TOBUSE = OMHRS_CAPs.TOBUSE,
    SubstanceUse_SUBUSE = OMHRS_CAPs.SUBUSE,
    WeightManagement_WTMGT = OMHRS_CAPs.WTMGT,
    Exercise_EXER = OMHRS_CAPs.EXER,
    SleepDisturbance_SLEEP = OMHRS_CAPs.SLEEP,
    Pain_PAIN = OMHRS_CAPs.PAIN,
    Falls_FALLS = OMHRS_CAPs.FALLS,

[    **** SECTION Others ****] = '''',
    AgeCode = lu_AgeCode.DisplayCode, AgeCodeDesc = lu_AgeCode.UserDescription, AgeNumber = dbo.OMHRS_SecBB.AgeNumber, 
    -- PR - 02377
    AttendingPhysician = LU_AttProvider.DisplayCode, AttendingPhysicianDesc = LU_AttProvider.UserDescription, 
    -- PR - 02377
    EncounterNumber = dbo.OMHRS_SecAA.AA3, 
    dbo.OMHRS_SecAA.HospitalAccountRecord,
    LOSDays = dbo.OMHRS_SecA.LOSDays, LOSTotal = dbo.OMHRS_SecA.LOSTotal, 
    
    -- PR - 02377
    MISCode = LU_MISCode.DisplayCode, MISCodeDesc = LU_MISCode.UserDescription, 
    NextAssessDate = OMHRS_SecA.NextAssessDate, 
    NursingArea = LU_AdmitNurse.DisplayCode, NursingAreaDesc = LU_AdmitNurse.UserDescription, 
    ReferringProvider = LU_RefProvider.DisplayCode, ReferringProviderDesc = LU_RefProvider.UserDescription, 
    dbo.OMHRS_SecAA.RegisterNumber,
    ResidenceCode = LU_ResidenceCode.DisplayCode, ResidenceCodeDesc = LU_ResidenceCode.UserDescription, 
    ResidenceProvince = LUResidenceProvince.DisplayCode, ResidenceProvinceDesc = LUResidenceRegion.UserDescription, 
    ResidenceRegion = LUResidenceRegion.DisplayCode, ResidenceRegionDesc = LUResidenceRegion.UserDescription, 
    SecondChartRegisterNumber = dbo.OMHRS_SecAA.SecondChartRegNumber,
	OMHRS_SecAA.UniversalEpisodeIdentifier,
    zzAbstractLinkID = OMHRS_SecAA.AbstractID, zzAbstractAdmitLinkID = LinkID
FROM         
    OMHRS_SecAA with (nolock) LEFT JOIN
    lu_CodeFile lu_Z1 with (nolock) on OMHRS_SecAA.Z1 = lu_Z1.Code LEFT JOIN
    lu_CodeFile lu_X2 with (nolock) on OMHRS_SecAA.X2 = lu_X2.Code LEFT JOIN
    lu_CodeFile lu_X10 with (nolock) on OMHRS_SecAA.X10 = lu_X10.Code LEFT JOIN
    LU_HCNProvince with (nolock) on OMHRS_SecAA.HCNProvince = LU_HCNProvince.Code LEFT JOIN
    H_InstitutionProfile with (nolock) on OMHRS_SecAA.InstitutionNumber = H_InstitutionProfile.Code LEFT JOIN
    lu_CodeFile lu_AA5 with (nolock) on OMHRS_SecAA.AA5 = lu_AA5.Code LEFT JOIN
    U_Users LU_SignOffCoder_AA with (nolock) on OMHRS_SecAA.SignCoder = LU_SignOffCoder_AA.Code LEFT JOIN
    U_Users LU_SignOffCoder_T with (nolock) on OMHRS_SecAA.ASignCoder = LU_SignOffCoder_T.Code LEFT JOIN
    OMHRS_SecA with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecA.AbstractID LEFT JOIN
    lu_CodeFile lu_A2 with (nolock) on OMHRS_SecA.A2 = lu_A2.Code LEFT JOIN
    lu_CodeFile lu_A3 with (nolock) on OMHRS_SecA.A3 = lu_A3.Code LEFT JOIN
    lu_CodeFile lu_A5a with (nolock) on OMHRS_SecA.A5a = lu_A5a.Code LEFT JOIN
    lu_CodeFile lu_A5b with (nolock) on OMHRS_SecA.A5b = lu_A5b.Code LEFT JOIN
    U_Users LU_SignOffCoder_A with (nolock) on OMHRS_SecA.SignCoder = LU_SignOffCoder_A.Code LEFT JOIN
    dbo.OMHRS_SecB with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecB.AbstractID LEFT JOIN
    lu_CodeFile lu_B2 with (nolock) on OMHRS_SecB.B2 = lu_B2.Code LEFT JOIN
    U_Users LU_SignOffCoder_B with (nolock) on OMHRS_SecB.SignCoder = LU_SignOffCoder_B.Code LEFT JOIN
    dbo.OMHRS_SecBB with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecBB.AbstractID LEFT JOIN
    lu_CodeFile lu_BB1 with (nolock) on OMHRS_SecBB.BB1 = lu_BB1.Code LEFT JOIN
    lu_CodeFile lu_BB3 with (nolock) on OMHRS_SecBB.BB3 = lu_BB3.Code LEFT JOIN
    lu_CodeFile lu_BB4 with (nolock) on OMHRS_SecBB.BB4 = lu_BB4.Code LEFT JOIN
    lu_CodeFile lu_BB5 with (nolock) on OMHRS_SecBB.BB5 = lu_BB5.Code LEFT JOIN
    LU_AgeCode with (nolock) on OMHRS_SecBB.AgeCode = LU_AgeCode.Code LEFT JOIN
    U_Users LU_SignOffCoder_BB with (nolock) on OMHRS_SecBB.SignCoder = LU_SignOffCoder_BB.Code LEFT JOIN
    dbo.OMHRS_SecC with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecC.AbstractID LEFT JOIN
    lu_CodeFile lu_C1 with (nolock) on OMHRS_SecC.C1 = lu_C1.Code LEFT JOIN
    lu_CodeFile lu_C2a with (nolock) on OMHRS_SecC.C2a = lu_C2a.Code LEFT JOIN
    lu_CodeFile lu_C2b with (nolock) on OMHRS_SecC.C2b = lu_C2b.Code LEFT JOIN
    lu_CodeFile lu_C2c with (nolock) on OMHRS_SecC.C2c = lu_C2c.Code LEFT JOIN
    lu_CodeFile lu_C2d with (nolock) on OMHRS_SecC.C2d = lu_C2d.Code LEFT JOIN
    lu_CodeFile lu_C2e with (nolock) on OMHRS_SecC.C2e = lu_C2e.Code LEFT JOIN
    lu_CodeFile lu_C2f with (nolock) on OMHRS_SecC.C2f = lu_C2f.Code LEFT JOIN
    lu_CodeFile lu_C3 with (nolock) on OMHRS_SecC.C3 = lu_C3.Code LEFT JOIN
    lu_CodeFile lu_C5 with (nolock) on OMHRS_SecC.C5 = lu_C5.Code LEFT JOIN
    U_Users LU_SignOffCoder_C with (nolock) on OMHRS_SecC.SignCoder = LU_SignOffCoder_C.Code LEFT JOIN
    dbo.OMHRS_SecCC with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecCC.AbstractID LEFT JOIN
    LU_ResidenceCode with (nolock) on OMHRS_SecCC.ResidenceCode = LU_ResidenceCode.Code LEFT JOIN
    LU_Region LUResidenceRegion with (nolock) on LU_ResidenceCode.RegionCode = LUResidenceRegion.Code LEFT JOIN
    LU_Province LUResidenceProvince with (nolock) on LU_ResidenceCode.ProvinceCode = LUResidenceProvince.Code LEFT JOIN
    lu_CodeFile lu_CC3 with (nolock) on OMHRS_SecCC.CC3 = lu_CC3.Code LEFT JOIN
    lu_CodeFile lu_CC4 with (nolock) on OMHRS_SecCC.CC4 = lu_CC4.Code LEFT JOIN
    LU_Institution_10 lu_X65 with (nolock) on OMHRS_SecCC.X65 = lu_X65.Code LEFT JOIN
    U_Users LU_SignOffCoder_CC with (nolock) on OMHRS_SecCC.SignCoder = LU_SignOffCoder_CC.Code LEFT JOIN
    dbo.OMHRS_SecD with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecD.AbstractID LEFT JOIN
    lu_CodeFile lu_D1a with (nolock) on OMHRS_SecD.D1a = lu_D1a.Code LEFT JOIN
    lu_CodeFile lu_D1b with (nolock) on OMHRS_SecD.D1b = lu_D1b.Code LEFT JOIN
    lu_CodeFile lu_D1c with (nolock) on OMHRS_SecD.D1c = lu_D1c.Code LEFT JOIN
    lu_CodeFile lu_D1d with (nolock) on OMHRS_SecD.D1d = lu_D1d.Code LEFT JOIN
    lu_CodeFile lu_D2a with (nolock) on OMHRS_SecD.D2a = lu_D2a.Code LEFT JOIN
    lu_CodeFile lu_D2b with (nolock) on OMHRS_SecD.D2b = lu_D2b.Code LEFT JOIN
    lu_CodeFile lu_D2c with (nolock) on OMHRS_SecD.D2c = lu_D2c.Code LEFT JOIN
    U_Users LU_SignOffCoder_D with (nolock) on OMHRS_SecD.SignCoder = LU_SignOffCoder_D.Code LEFT JOIN
    dbo.OMHRS_SecDD with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecDD.AbstractID LEFT JOIN
    lu_CodeFile lu_DD1 with (nolock) on OMHRS_SecDD.DD1 = lu_DD1.Code LEFT JOIN
    lu_CodeFile lu_DD2 with (nolock) on OMHRS_SecDD.DD2 = lu_DD2.Code LEFT JOIN
    lu_CodeFile lu_DD3 with (nolock) on OMHRS_SecDD.DD3 = lu_DD3.Code LEFT JOIN
    lu_CodeFile lu_DD4 with (nolock) on OMHRS_SecDD.DD4 = lu_DD4.Code LEFT JOIN
    lu_CodeFile lu_DD5 with (nolock) on OMHRS_SecDD.DD5 = lu_DD5.Code LEFT JOIN
    lu_CodeFile lu_DD6 with (nolock) on OMHRS_SecDD.DD6 = lu_DD6.Code LEFT JOIN
    U_Users LU_SignOffCoder_DD with (nolock) on OMHRS_SecDD.SignCoder = LU_SignOffCoder_DD.Code LEFT JOIN
    dbo.OMHRS_SecE with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecE.AbstractID LEFT JOIN
    lu_CodeFile lu_E1a with (nolock) on OMHRS_SecE.E1a = lu_E1a.Code LEFT JOIN
    lu_CodeFile lu_E1b with (nolock) on OMHRS_SecE.E1b = lu_E1b.Code LEFT JOIN
    lu_CodeFile lu_E1c with (nolock) on OMHRS_SecE.E1c = lu_E1c.Code LEFT JOIN
    lu_CodeFile lu_E1d with (nolock) on OMHRS_SecE.E1d = lu_E1d.Code LEFT JOIN
    lu_CodeFile lu_E1e with (nolock) on OMHRS_SecE.E1e = lu_E1e.Code LEFT JOIN
    lu_CodeFile lu_E1f with (nolock) on OMHRS_SecE.E1f = lu_E1f.Code LEFT JOIN
    lu_CodeFile lu_E1g with (nolock) on OMHRS_SecE.E1g = lu_E1g.Code LEFT JOIN
    lu_CodeFile lu_E2 with (nolock) on OMHRS_SecE.E2 = lu_E2.Code LEFT JOIN
    U_Users LU_SignOffCoder_E with (nolock) on OMHRS_SecE.SignCoder = LU_SignOffCoder_E.Code LEFT JOIN
    dbo.OMHRS_SecF with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecF.AbstractID LEFT JOIN
    lu_CodeFile lu_F1a with (nolock) on OMHRS_SecF.F1a = lu_F1a.Code LEFT JOIN
    lu_CodeFile lu_F1b with (nolock) on OMHRS_SecF.F1b = lu_F1b.Code LEFT JOIN
    lu_CodeFile lu_F2 with (nolock) on OMHRS_SecF.F2 = lu_F2.Code LEFT JOIN
    lu_CodeFile lu_F3a with (nolock) on OMHRS_SecF.F3a = lu_F3a.Code LEFT JOIN
    lu_CodeFile lu_F3b with (nolock) on OMHRS_SecF.F3b = lu_F3b.Code LEFT JOIN
    lu_CodeFile lu_F3c with (nolock) on OMHRS_SecF.F3c = lu_F3c.Code LEFT JOIN
    lu_CodeFile lu_F3d with (nolock) on OMHRS_SecF.F3d = lu_F3d.Code LEFT JOIN
    lu_CodeFile lu_F3e with (nolock) on OMHRS_SecF.F3e = lu_F3e.Code LEFT JOIN
    lu_CodeFile lu_F3f with (nolock) on OMHRS_SecF.F3f = lu_F3f.Code LEFT JOIN
    lu_CodeFile lu_F4 with (nolock) on OMHRS_SecF.F4 = lu_F4.Code LEFT JOIN
    
    U_Users LU_SignOffCoder_F with (nolock) on OMHRS_SecF.SignCoder = LU_SignOffCoder_F.Code LEFT JOIN
    dbo.OMHRS_SecG with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecG.AbstractID LEFT JOIN
    lu_CodeFile lu_G1a with (nolock) on OMHRS_SecG.G1a = lu_G1a.Code LEFT JOIN
    lu_CodeFile lu_G1b with (nolock) on OMHRS_SecG.G1b = lu_G1b.Code LEFT JOIN
    lu_CodeFile lu_G1c with (nolock) on OMHRS_SecG.G1c = lu_G1c.Code LEFT JOIN
    lu_CodeFile lu_G1d with (nolock) on OMHRS_SecG.G1d = lu_G1d.Code LEFT JOIN
    lu_CodeFile lu_G1e with (nolock) on OMHRS_SecG.G1e = lu_G1e.Code LEFT JOIN
    lu_CodeFile lu_G2a with (nolock) on OMHRS_SecG.G2a = lu_G2a.Code LEFT JOIN
    lu_CodeFile lu_G2b with (nolock) on OMHRS_SecG.G2b = lu_G2b.Code LEFT JOIN
    lu_CodeFile lu_G2c with (nolock) on OMHRS_SecG.G2c = lu_G2c.Code LEFT JOIN
    lu_CodeFile lu_G2d with (nolock) on OMHRS_SecG.G2d = lu_G2d.Code LEFT JOIN
    lu_CodeFile lu_G2e with (nolock) on OMHRS_SecG.G2e = lu_G2e.Code LEFT JOIN
    lu_CodeFile lu_G3 with (nolock) on OMHRS_SecG.G3 = lu_G3.Code LEFT JOIN
    U_Users LU_SignOffCoder_G with (nolock) on OMHRS_SecG.SignCoder = LU_SignOffCoder_G.Code LEFT JOIN
    dbo.OMHRS_SecH with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecH.AbstractID LEFT JOIN
    lu_CodeFile lu_H1 with (nolock) on OMHRS_SecH.H1 = lu_H1.Code LEFT JOIN
    lu_CodeFile lu_H2 with (nolock) on OMHRS_SecH.H2 = lu_H2.Code LEFT JOIN
    lu_CodeFile lu_H3 with (nolock) on OMHRS_SecH.H3 = lu_H3.Code LEFT JOIN
    U_Users LU_SignOffCoder_H with (nolock) on OMHRS_SecH.SignCoder = LU_SignOffCoder_H.Code LEFT JOIN
    dbo.OMHRS_SecI with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecI.AbstractID LEFT JOIN
    lu_CodeFile lu_I6b with (nolock) on OMHRS_SecI.I6b = lu_I6b.Code LEFT JOIN
    lu_CodeFile lu_I8a with (nolock) on OMHRS_SecI.I8a = lu_I8a.Code LEFT JOIN
    lu_CodeFile lu_I8b with (nolock) on OMHRS_SecI.I8b = lu_I8b.Code LEFT JOIN
    lu_CodeFile lu_I9 with (nolock) on OMHRS_SecI.I9 = lu_I9.Code LEFT JOIN
    lu_CodeFile lu_I10 with (nolock) on OMHRS_SecI.I10 = lu_I10.Code LEFT JOIN
    U_Users LU_SignOffCoder_I with (nolock) on OMHRS_SecI.SignCoder = LU_SignOffCoder_I.Code LEFT JOIN
    dbo.OMHRS_SecJ with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecJ.AbstractID LEFT JOIN
    U_Users LU_SignOffCoder_J with (nolock) on OMHRS_SecJ.SignCoder = LU_SignOffCoder_J.Code LEFT JOIN
    dbo.OMHRS_SecK with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecK.AbstractID LEFT JOIN
    lu_CodeFile lu_K1 with (nolock) on OMHRS_SecK.K1 = lu_K1.Code LEFT JOIN
    lu_CodeFile lu_K3 with (nolock) on OMHRS_SecK.K3 = lu_K3.Code LEFT JOIN
    U_Users LU_SignOffCoder_K with (nolock) on OMHRS_SecK.SignCoder = LU_SignOffCoder_K.Code LEFT JOIN
    dbo.OMHRS_SecL with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecL.AbstractID LEFT JOIN
    lu_CodeFile lu_L1a with (nolock) on OMHRS_SecL.L1a = lu_L1a.Code LEFT JOIN
    lu_CodeFile lu_L1b with (nolock) on OMHRS_SecL.L1b = lu_L1b.Code LEFT JOIN
    lu_CodeFile lu_L1c with (nolock) on OMHRS_SecL.L1c = lu_L1c.Code LEFT JOIN
    lu_CodeFile lu_L1d with (nolock) on OMHRS_SecL.L1d = lu_L1d.Code LEFT JOIN
    lu_CodeFile lu_L1e with (nolock) on OMHRS_SecL.L1e = lu_L1e.Code LEFT JOIN
    lu_CodeFile lu_L1f with (nolock) on OMHRS_SecL.L1f = lu_L1f.Code LEFT JOIN
    lu_CodeFile lu_L1g with (nolock) on OMHRS_SecL.L1g = lu_L1g.Code LEFT JOIN
    lu_CodeFile lu_L1h with (nolock) on OMHRS_SecL.L1h = lu_L1h.Code LEFT JOIN
    lu_CodeFile lu_L2a with (nolock) on OMHRS_SecL.L2a = lu_L2a.Code LEFT JOIN
    lu_CodeFile lu_L2b with (nolock) on OMHRS_SecL.L2b = lu_L2b.Code LEFT JOIN
    lu_CodeFile lu_L2c with (nolock) on OMHRS_SecL.L2c = lu_L2c.Code LEFT JOIN
    lu_CodeFile lu_L2d with (nolock) on OMHRS_SecL.L2d = lu_L2d.Code LEFT JOIN
    lu_CodeFile lu_L3a with (nolock) on OMHRS_SecL.L3a = lu_L3a.Code LEFT JOIN
    lu_CodeFile lu_L3b with (nolock) on OMHRS_SecL.L3b = lu_L3b.Code LEFT JOIN
    lu_CodeFile lu_L3c with (nolock) on OMHRS_SecL.L3c = lu_L3c.Code LEFT JOIN
    lu_CodeFile lu_L3d with (nolock) on OMHRS_SecL.L3d = lu_L3d.Code LEFT JOIN
    lu_CodeFile lu_L5 with (nolock) on OMHRS_SecL.L5 = lu_L5.Code LEFT JOIN
    lu_CodeFile lu_L6 with (nolock) on OMHRS_SecL.L6 = lu_L6.Code LEFT JOIN
    U_Users LU_SignOffCoder_L with (nolock) on OMHRS_SecL.SignCoder = LU_SignOffCoder_L.Code LEFT JOIN
    dbo.OMHRS_SecM with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecM.AbstractID LEFT JOIN
    lu_CodeFile lu_M1a with (nolock) on OMHRS_SecM.M1a = lu_M1a.Code LEFT JOIN
    lu_CodeFile lu_M1b with (nolock) on OMHRS_SecM.M1b = lu_M1b.Code LEFT JOIN
    lu_CodeFile lu_M1c with (nolock) on OMHRS_SecM.M1c = lu_M1c.Code LEFT JOIN
    lu_CodeFile lu_M1d with (nolock) on OMHRS_SecM.M1d = lu_M1d.Code LEFT JOIN
    lu_CodeFile lu_M1e with (nolock) on OMHRS_SecM.M1e = lu_M1e.Code LEFT JOIN
    lu_CodeFile lu_M1f with (nolock) on OMHRS_SecM.M1f = lu_M1f.Code LEFT JOIN
    lu_CodeFile lu_M2a with (nolock) on OMHRS_SecM.M2a = lu_M2a.Code LEFT JOIN
    lu_CodeFile lu_M2b with (nolock) on OMHRS_SecM.M2b = lu_M2b.Code LEFT JOIN
    lu_CodeFile lu_M2c with (nolock) on OMHRS_SecM.M2c = lu_M2c.Code LEFT JOIN
    lu_CodeFile lu_M2d with (nolock) on OMHRS_SecM.M2d = lu_M2d.Code LEFT JOIN
    lu_CodeFile lu_M3 with (nolock) on OMHRS_SecM.M3 = lu_M3.Code LEFT JOIN
    lu_CodeFile lu_M4a with (nolock) on OMHRS_SecM.M4a = lu_M4a.Code LEFT JOIN
    lu_CodeFile lu_M4b with (nolock) on OMHRS_SecM.M4b = lu_M4b.Code LEFT JOIN
    U_Users LU_SignOffCoder_M with (nolock) on OMHRS_SecM.SignCoder = LU_SignOffCoder_M.Code LEFT JOIN
    dbo.OMHRS_SecN with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecN.AbstractID LEFT JOIN
    U_Users LU_SignOffCoder_N with (nolock) on OMHRS_SecN.SignCoder = LU_SignOffCoder_N.Code LEFT JOIN
    dbo.OMHRS_SecO with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecO.AbstractID LEFT JOIN
    lu_CodeFile lu_O1 with (nolock) on OMHRS_SecO.O1 = lu_O1.Code LEFT JOIN
    lu_CodeFile lu_O3 with (nolock) on OMHRS_SecO.O3 = lu_O3.Code LEFT JOIN
    lu_CodeFile lu_O5 with (nolock) on OMHRS_SecO.O5 = lu_O5.Code LEFT JOIN
    lu_CodeFile lu_O4a with (nolock) on OMHRS_SecO.O4a = lu_O4a.Code LEFT JOIN
    lu_CodeFile lu_O4b with (nolock) on OMHRS_SecO.O4b = lu_O4b.Code LEFT JOIN
    lu_CodeFile lu_O4c with (nolock) on OMHRS_SecO.O4c = lu_O4c.Code LEFT JOIN
    lu_CodeFile lu_O4d with (nolock) on OMHRS_SecO.O4d = lu_O4d.Code LEFT JOIN
    lu_CodeFile lu_O6a with (nolock) on OMHRS_SecO.O6a = lu_O6a.Code LEFT JOIN
    lu_CodeFile lu_O6b with (nolock) on OMHRS_SecO.O6b = lu_O6b.Code LEFT JOIN
    lu_CodeFile lu_O6c with (nolock) on OMHRS_SecO.O6c = lu_O6c.Code LEFT JOIN
    U_Users LU_SignOffCoder_O with (nolock) on OMHRS_SecO.SignCoder = LU_SignOffCoder_O.Code LEFT JOIN
    dbo.OMHRS_SecP with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecP.AbstractID LEFT JOIN
    lu_CodeFile lu_P1a with (nolock) on OMHRS_SecP.P1a = lu_P1a.Code LEFT JOIN
    lu_CodeFile lu_P1b with (nolock) on OMHRS_SecP.P1b = lu_P1b.Code LEFT JOIN
    lu_CodeFile lu_P1c with (nolock) on OMHRS_SecP.P1c = lu_P1c.Code LEFT JOIN
    lu_CodeFile lu_P1d with (nolock) on OMHRS_SecP.P1d = lu_P1d.Code LEFT JOIN
    lu_CodeFile lu_P2a with (nolock) on OMHRS_SecP.P2a = lu_P2a.Code LEFT JOIN
    lu_CodeFile lu_P2b with (nolock) on OMHRS_SecP.P2b = lu_P2b.Code LEFT JOIN
    lu_CodeFile lu_P3 with (nolock) on OMHRS_SecP.P3 = lu_P3.Code LEFT JOIN
    lu_CodeFile lu_P4 with (nolock) on OMHRS_SecP.P4 = lu_P4.Code LEFT JOIN
    lu_CodeFile lu_P5 with (nolock) on OMHRS_SecP.P5 = lu_P5.Code LEFT JOIN
    LU_Institution_10 lu_X140 with (nolock) on OMHRS_SecP.X140 = lu_X140.Code LEFT JOIN
    U_Users LU_SignOffCoder_P with (nolock) on OMHRS_SecP.SignCoder = LU_SignOffCoder_P.Code LEFT JOIN
    dbo.OMHRS_SecQ with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecQ.AbstractID LEFT JOIN
    lu_CodeFile lu_Q5 with (nolock) on OMHRS_SecQ.Q5 = lu_Q5.Code LEFT JOIN
    --LU_DSM_IV lu_Q2d with (nolock) on OMHRS_SecQ.Q2d = lu_Q2d.Code LEFT JOIN
    U_Users LU_SignOffCoder_Q with (nolock) on OMHRS_SecQ.SignCoder = LU_SignOffCoder_Q.Code LEFT JOIN
    dbo.OMHRS_SecR with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecR.AbstractID LEFT JOIN
    U_Users LU_SignOffCoder_R with (nolock) on OMHRS_SecR.SignCoder = LU_SignOffCoder_R.Code LEFT JOIN
    dbo.OMHRS_SecS with (nolock) on OMHRS_SecAA.AbstractID = OMHRS_SecS.AbstractID LEFT JOIN
    lu_CodeFile lu_X90 with (nolock) on OMHRS_SecS.X90 = lu_X90.Code LEFT JOIN
    U_Users LU_SignOffCoder_S with (nolock) on OMHRS_SecS.SignCoder = LU_SignOffCoder_S.Code LEFT JOIN
    LU_Provider LU_AttProvider with (nolock) on dbo.OMHRS_SecAA.AttendingPhysician = LU_AttProvider.Code LEFT JOIN
    LU_Provider LU_RefProvider with (nolock) on dbo.OMHRS_SecAA.RefPhysician = LU_RefProvider.Code LEFT JOIN
    LU_MisCode LU_MisCode with (nolock) on dbo.OMHRS_SecAA.MISCode = LU_MisCode.Code LEFT JOIN
    LU_NurseArea LU_AdmitNurse with (nolock) on dbo.OMHRS_SecAA.AdmittingNurseArea = LU_AdmitNurse.Code LEFT JOIN
--ED - 01914
    LU_CodeFile LU_CC4a with (nolock) on dbo.OMHRS_SecCC.CC4a = LU_CC4a.Code LEFT JOIN
    LU_CodeFile LU_CC4b with (nolock) on dbo.OMHRS_SecCC.CC4b = LU_CC4b.Code LEFT JOIN
    LU_CodeFile LU_A3a with (nolock) on dbo.OMHRS_SecA.A3a = LU_A3a.Code LEFT JOIN
    LU_CodeFile LU_A3b with (nolock) on dbo.OMHRS_SecA.A3b = LU_A3b.Code LEFT JOIN
    LU_CodeFile LU_I7a with (nolock) on dbo.OMHRS_SecI.I7a = LU_I7a.Code LEFT JOIN
--ED - 02156
    LU_CodeFile LU_X4 with (nolock) on dbo.OMHRS_SecAA.X4 = LU_X4.Code LEFT JOIN
    LU_CodeFile LU_X7 with (nolock) on dbo.OMHRS_SecQ.X7 = LU_X7.Code LEFT JOIN
--ED - 02373
    OMHRS_OutcomeScale with (nolock) on dbo.OMHRS_SecAA.AbstractID = OMHRS_OutcomeScale.AbstractID  LEFT JOIN 
    OMHRS_CAPs with (nolock) on dbo.OMHRS_SecAA.AbstractID = OMHRS_CAPs.AbstractID Left join
--PR - 05833
    dbo.OMHRS_IAR_CCIM with (nolock) on dbo.OMHRS_SecAA.AbstractID = OMHRS_IAR_CCIM.AbstractID 
    
    CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_YesNoSystem
            WHERE      code = 1) LU_YesNoSystem_Yes CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_YesNoSystem
            WHERE      code = 2) LU_YesNoSystem_No CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200379) LU_570_Yes CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200380) LU_570_No CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200103) LU_B_519_0 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200104) LU_B_519_1 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200105) LU_B_519_2 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200106) LU_B_519_3 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200183) LU_538_0 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200184) LU_538_1 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200185) LU_538_2 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200202) LU_542_0 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200203) LU_542_1 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200204) LU_542_2 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200205) LU_542_3 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200216) LU_546_0 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200217) LU_546_1 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200218) LU_546_2 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200219) LU_546_3 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200268) LU_560_1 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200269) LU_560_2 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200270) LU_560_3 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200906) LU_576_0 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200907) LU_576_1 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 200908) LU_576_8 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 302101) LU_605_0 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 302102) LU_605_1 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 302111) LU_606_0 CROSS JOIN
          (SELECT     DisplayCode, UserDescription
            FROM          LU_CodeFile
            WHERE      code = 302112) LU_606_1
    
/*
    left join lu_CodeFile lu_ with (nolock) on OMHRS_SecA. = lu_.Code
 = lu_.DisplayCode, 
Desc_ = lu_.UserDescription,

_ = (case dbo.OMHRS_SecO when 200379 then LU_570_Yes.DisplayCode when 200380 then LU_570_No.DisplayCode else '''' end),
Desc_ = (case dbo.OMHRS_SecO when 200379 then LU_570_Yes.UserDescription when 200380 then LU_570_No.UserDescription else '''' end),

_ = (case dbo.OMHRS_SecI.I when 200183 then LU_538_0.DisplayCode when 200184 then LU_538_1.DisplayCode when 200185 then LU_538_2.DisplayCode else '''' end),
Desc_ = (case dbo.OMHRS_SecI.I when 200183 then LU_538_0.UserDescription when 200184 then LU_538_1.UserDescription when 200185 then LU_538_2.UserDescription else '''' end),

_ = (case dbo.OMHRS_SecL when 200216 then LU_546_0.DisplayCode when 200217 then LU_546_1.DisplayCode when 200218 then LU_546_2.DisplayCode when 200219 then LU_546_3.DisplayCode else '''' end),
Desc_ = (case dbo.OMHRS_SecL when 200216 then LU_546_0.UserDescription when 200217 then LU_546_1.UserDescription when 200218 then LU_546_2.UserDescription when 200216 then LU_546_3.UserDescription else '''' end),

_ = (case dbo.OMHRS_SecQ. when 200268 then LU_560_1.DisplayCode when 200269 then LU_560_2.DisplayCode when 200270 then LU_560_3.DisplayCode else '''' end),
Desc_ = (case dbo.OMHRS_SecQ. when 200268 then LU_560_1.UserDescription when 200269 then LU_560_2.UserDescription when 200270 then LU_560_3.UserDescription else '''' end),

*/

--  select * from lu_codefile where lookupid = 560

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[OMHRSErrorsWarnings_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE  VIEW [dbo].[OMHRSErrorsWarnings_VR]
AS
SELECT 
    CIHI_ElementID = U_UsersFields.CIHI_ID,
    FieldName = U_UsersFields.Header_User, 
    --ErrorMessage = dbo.MG_Messages.MessageText, 
    MessageLevel = CASE AB_ErrorMessages.MessageType WHEN 1 THEN ''Warning'' 
                                    WHEN 2 THEN ''Error'' 
                                    WHEN 3 THEN ''Critical'' 
                                    WHEN 0 THEN ''Information'' 
                                    WHEN 5 THEN ''Question'' END, 
    AB_ErrorMessages.MessageText, 
    AB_ErrorMessages.SaveDate, 
    AB_ErrorMessages.AbstractID AS zzAbstractLink
FROM dbo.AB_ErrorMessages with (nolock)
    --left join dbo.MG_Messages with (nolock)
    --    on dbo.AB_ErrorMessages.MessageKey = dbo.MG_Messages.MessageKey
    left join dbo.AB_ErrorMessageFields with (nolock)
        on dbo.AB_ErrorMessages.AppID = dbo.AB_ErrorMessageFields.AppID
            and dbo.AB_ErrorMessages.AbstractID = dbo.AB_ErrorMessageFields.AbstractID 
            and dbo.AB_ErrorMessages.MessageKey = dbo.AB_ErrorMessageFields.MessageKey
    left join dbo.U_UsersFields with (nolock) 
        on UserID = 1 and dbo.AB_ErrorMessages.AppID = dbo.U_UsersFields.AppID and 
        (case when isnumeric(replace(dbo.AB_ErrorMessageFields.FieldKey, ''FK'', '''')) = 1 
              then replace(dbo.AB_ErrorMessageFields.FieldKey, ''FK'', '''')
              else 0 end) = dbo.U_UsersFields.FieldID 
Where AB_ErrorMessages.appid between 650 and 654

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[PAC10_CACS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[PAC10_CACS_VR]
AS
SELECT     CACS_Year, ACWON AS PAC10ACW, AbstractID AS zzAbstractLink
FROM         dbo.AB_CACSON with (nolock)



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Purged_Record_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[Purged_Record_VR]
AS
SELECT     AbstNumber AS AbstractNumber, BatchNumber, BatchPeriod, BatchYear, CareType, ChartNumber, CIHIDateSent AS DateSenttoCIHI, DeleteCoder, 
                      DeleteDate, DeleteTime, EncounterNumber, EncounterSequence, FullName, ICDType, InstNumber AS InstitutionNumber, IsCompleted, IsCorrected, 
                      IsSubmitted, IsValidated, PurgeCoder, PurgeDate, PurgeTime, VisitDate, VisitTime,
                      [DeleteReason] 
FROM         dbo.REC_Purge with (nolock)
    left join dbo.REC_DeleteReason with (nolock) 
        on dbo.REC_Purge.AppID = dbo.REC_DeleteReason.AppID and dbo.REC_Purge.[RecordID] = dbo.REC_DeleteReason.[RecordID]

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_Ancillary_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[Rehab_Ancillary_VR]
AS
SELECT     
    dbo.LU_Ancillary1.DisplayCode AS AncillaryField1, dbo.LU_Ancillary1.UserDescription AS AncillaryField1Desc, 
    dbo.LU_Ancillary2.DisplayCode AS AncillaryField2, dbo.LU_Ancillary2.UserDescription AS AncillaryField2Desc, 
    dbo.LU_Ancillary3.DisplayCode AS AncillaryField3, dbo.LU_Ancillary3.UserDescription AS AncillaryField3Desc, 
    dbo.LU_Ancillary4.DisplayCode AS AncillaryField4, dbo.LU_Ancillary4.UserDescription AS AncillaryField4Desc, 
    dbo.LU_Ancillary5.DisplayCode AS AncillaryField5, dbo.LU_Ancillary5.UserDescription AS AncillaryField5Desc, 
    dbo.LU_Ancillary6.DisplayCode AS AncillaryField6, dbo.LU_Ancillary6.UserDescription AS AncillaryField6Desc, 
    dbo.LU_Ancillary7.DisplayCode AS AncillaryField7, dbo.LU_Ancillary7.UserDescription AS AncillaryField7Desc, 
    dbo.LU_Ancillary8.DisplayCode AS AncillaryField8, dbo.LU_Ancillary8.UserDescription AS AncillaryField8Desc, 
    dbo.LU_Ancillary9.DisplayCode AS AncillaryField9, dbo.LU_Ancillary9.UserDescription AS AncillaryField9Desc, 
    dbo.LU_Ancillary10.DisplayCode AS AncillaryField10, dbo.LU_Ancillary10.UserDescription AS AncillaryField10Desc, 
    dbo.LU_Ancillary11.DisplayCode AS AncillaryField11, dbo.LU_Ancillary11.UserDescription AS AncillaryField11Desc, 
    dbo.LU_Ancillary12.DisplayCode AS AncillaryField12, dbo.LU_Ancillary12.UserDescription AS AncillaryField12Desc, 
    dbo.LU_Ancillary13.DisplayCode AS AncillaryField13, dbo.LU_Ancillary13.UserDescription AS AncillaryField13Desc, 
    dbo.LU_Ancillary14.DisplayCode AS AncillaryField14, dbo.LU_Ancillary14.UserDescription AS AncillaryField14Desc, 
    dbo.LU_Ancillary15.DisplayCode AS AncillaryField15, dbo.LU_Ancillary15.UserDescription AS AncillaryField15Desc, 
    dbo.LU_Ancillary16.DisplayCode AS AncillaryField16, dbo.LU_Ancillary16.UserDescription AS AncillaryField16Desc, 
    dbo.LU_Ancillary17.DisplayCode AS AncillaryField17, dbo.LU_Ancillary17.UserDescription AS AncillaryField17Desc, 
    dbo.RH_Ancillary.AbstractID AS zzRehabLink
FROM  dbo.RH_Ancillary with (nolock) LEFT OUTER JOIN
      dbo.LU_Ancillary17 with (nolock) on dbo.RH_Ancillary.AncillaryField17 = dbo.LU_Ancillary17.Code LEFT OUTER JOIN
      dbo.LU_Ancillary16 with (nolock) on dbo.RH_Ancillary.AncillaryField16 = dbo.LU_Ancillary16.Code LEFT OUTER JOIN
      dbo.LU_Ancillary15 with (nolock) on dbo.RH_Ancillary.AncillaryField15 = dbo.LU_Ancillary15.Code LEFT OUTER JOIN
      dbo.LU_Ancillary14 with (nolock) on dbo.RH_Ancillary.AncillaryField14 = dbo.LU_Ancillary14.Code LEFT OUTER JOIN
      dbo.LU_Ancillary13 with (nolock) on dbo.RH_Ancillary.AncillaryField13 = dbo.LU_Ancillary13.Code LEFT OUTER JOIN
      dbo.LU_Ancillary12 with (nolock) on dbo.RH_Ancillary.AncillaryField12 = dbo.LU_Ancillary12.Code LEFT OUTER JOIN
      dbo.LU_Ancillary11 with (nolock) on dbo.RH_Ancillary.AncillaryField11 = dbo.LU_Ancillary11.Code LEFT OUTER JOIN
      dbo.LU_Ancillary10 with (nolock) on dbo.RH_Ancillary.AncillaryField10 = dbo.LU_Ancillary10.Code LEFT OUTER JOIN
      dbo.LU_Ancillary9 with (nolock) on dbo.RH_Ancillary.AncillaryField9 = dbo.LU_Ancillary9.Code LEFT OUTER JOIN
      dbo.LU_Ancillary8 with (nolock) on dbo.RH_Ancillary.AncillaryField8 = dbo.LU_Ancillary8.Code LEFT OUTER JOIN
      dbo.LU_Ancillary7 with (nolock) on dbo.RH_Ancillary.AncillaryField7 = dbo.LU_Ancillary7.Code LEFT OUTER JOIN
      dbo.LU_Ancillary6 with (nolock) on dbo.RH_Ancillary.AncillaryField6 = dbo.LU_Ancillary6.Code LEFT OUTER JOIN
      dbo.LU_Ancillary5 with (nolock) on dbo.RH_Ancillary.AncillaryField5 = dbo.LU_Ancillary5.Code LEFT OUTER JOIN
      dbo.LU_Ancillary4 with (nolock) on dbo.RH_Ancillary.AncillaryField4 = dbo.LU_Ancillary4.Code LEFT OUTER JOIN
      dbo.LU_Ancillary3 with (nolock) on dbo.RH_Ancillary.AncillaryField3 = dbo.LU_Ancillary3.Code LEFT OUTER JOIN
      dbo.LU_Ancillary2 with (nolock) on dbo.RH_Ancillary.AncillaryField2 = dbo.LU_Ancillary2.Code LEFT OUTER JOIN
      dbo.LU_Ancillary1 with (nolock) on dbo.RH_Ancillary.AncillaryField1 = dbo.LU_Ancillary1.Code


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_BasicOption_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE view [dbo].[Rehab_BasicOption_VR]
as
select
    BasicOption1  = dbo.lu_BasicOption1.DisplayCode,  BasicOption1Desc  = dbo.lu_BasicOption1.UserDescription,
    BasicOption2  = dbo.lu_BasicOption2.DisplayCode,  BasicOption2Desc  = dbo.lu_BasicOption2.UserDescription,
    BasicOption3  = dbo.lu_BasicOption3.DisplayCode,  BasicOption3Desc  = dbo.lu_BasicOption3.UserDescription,
    BasicOption4  = dbo.lu_BasicOption4.DisplayCode,  BasicOption4Desc  = dbo.lu_BasicOption4.UserDescription,
    BasicOption5  = dbo.lu_BasicOption5.DisplayCode,  BasicOption5Desc  = dbo.lu_BasicOption5.UserDescription,
    BasicOption6  = dbo.lu_BasicOption6.DisplayCode,  BasicOption6Desc  = dbo.lu_BasicOption6.UserDescription,
    BasicOption7  = dbo.lu_BasicOption7.DisplayCode,  BasicOption7Desc  = dbo.lu_BasicOption7.UserDescription,
    BasicOption8  = dbo.lu_BasicOption8.DisplayCode,  BasicOption8Desc  = dbo.lu_BasicOption8.UserDescription,
    BasicOption9  = dbo.lu_BasicOption9.DisplayCode,  BasicOption9Desc  = dbo.lu_BasicOption9.UserDescription,
    BasicOption10 = dbo.lu_BasicOption10.DisplayCode, BasicOption10Desc = dbo.lu_BasicOption10.UserDescription,
    BasicOption11 = dbo.lu_BasicOption11.DisplayCode, BasicOption11Desc = dbo.lu_BasicOption11.UserDescription,
    BasicOption12 = dbo.lu_BasicOption12.DisplayCode, BasicOption12Desc = dbo.lu_BasicOption12.UserDescription,
    BasicOption13 = dbo.lu_BasicOption13.DisplayCode, BasicOption13Desc = dbo.lu_BasicOption13.UserDescription,
    BasicOption14 = dbo.lu_BasicOption14.DisplayCode, BasicOption14Desc = dbo.lu_BasicOption14.UserDescription,
    BasicOption15 = dbo.lu_BasicOption15.DisplayCode, BasicOption15Desc = dbo.lu_BasicOption15.UserDescription,
    BasicOption16 = dbo.lu_BasicOption16.DisplayCode, BasicOption16Desc = dbo.lu_BasicOption16.UserDescription,
    BasicOption17 = dbo.lu_BasicOption17.DisplayCode, BasicOption17Desc = dbo.lu_BasicOption17.UserDescription,
    BasicOption18 = dbo.lu_BasicOption18.DisplayCode, BasicOption18Desc = dbo.lu_BasicOption18.UserDescription,
    BasicOption19 = dbo.lu_BasicOption19.DisplayCode, BasicOption19Desc = dbo.lu_BasicOption19.UserDescription,
    dbo.RH_BasicOption.AbstractID as zzRehabLink
from dbo.RH_BasicOption with (nolock) 
    left join dbo.lu_BasicOption1  with (nolock) on dbo.RH_BasicOption.BasicOption1  =  dbo.lu_BasicOption1.Code
    left join dbo.lu_BasicOption2  with (nolock) on dbo.RH_BasicOption.BasicOption2  =  dbo.lu_BasicOption2.Code
    left join dbo.lu_BasicOption3  with (nolock) on dbo.RH_BasicOption.BasicOption3  =  dbo.lu_BasicOption3.Code
    left join dbo.lu_BasicOption4  with (nolock) on dbo.RH_BasicOption.BasicOption4  =  dbo.lu_BasicOption4.Code
    left join dbo.lu_BasicOption5  with (nolock) on dbo.RH_BasicOption.BasicOption5  =  dbo.lu_BasicOption5.Code
    left join dbo.lu_BasicOption6  with (nolock) on dbo.RH_BasicOption.BasicOption6  =  dbo.lu_BasicOption6.Code
    left join dbo.lu_BasicOption7  with (nolock) on dbo.RH_BasicOption.BasicOption7  =  dbo.lu_BasicOption7.Code
    left join dbo.lu_BasicOption8  with (nolock) on dbo.RH_BasicOption.BasicOption8  =  dbo.lu_BasicOption8.Code
    left join dbo.lu_BasicOption9  with (nolock) on dbo.RH_BasicOption.BasicOption9  =  dbo.lu_BasicOption9.Code
    left join dbo.lu_BasicOption10 with (nolock) on dbo.RH_BasicOption.BasicOption10 =  dbo.lu_BasicOption10.Code
    left join dbo.lu_BasicOption11 with (nolock) on dbo.RH_BasicOption.BasicOption11 =  dbo.lu_BasicOption11.Code
    left join dbo.lu_BasicOption12 with (nolock) on dbo.RH_BasicOption.BasicOption12 =  dbo.lu_BasicOption12.Code
    left join dbo.lu_BasicOption13 with (nolock) on dbo.RH_BasicOption.BasicOption13 =  dbo.lu_BasicOption13.Code
    left join dbo.lu_BasicOption14 with (nolock) on dbo.RH_BasicOption.BasicOption14 =  dbo.lu_BasicOption14.Code
    left join dbo.lu_BasicOption15 with (nolock) on dbo.RH_BasicOption.BasicOption15 =  dbo.lu_BasicOption15.Code
    left join dbo.lu_BasicOption16 with (nolock) on dbo.RH_BasicOption.BasicOption16 =  dbo.lu_BasicOption16.Code
    left join dbo.lu_BasicOption17 with (nolock) on dbo.RH_BasicOption.BasicOption17 =  dbo.lu_BasicOption17.Code
    left join dbo.lu_BasicOption18 with (nolock) on dbo.RH_BasicOption.BasicOption18 =  dbo.lu_BasicOption18.Code
    left join dbo.lu_BasicOption19 with (nolock) on dbo.RH_BasicOption.BasicOption19 =  dbo.lu_BasicOption19.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[Rehab_Diagnosis_VR]
AS
SELECT     Lookup1.DisplayCode AS DiagnosticConditionCode, Lookup1.UserDescription AS DiagnosticConditionCodeDesc, 
                      dbo.ICD_DiagFileNRS.DisplayCode AS DiagnosticConditionCodeICD, dbo.ICD_DiagFileNRS.UserDescription AS DiagnosticConditionCodeICDDesc, 
                      dbo.RH_Diagnosis.DiagnosisOccurrence AS DiagnosticOccurrence, Lookup2.DisplayCode AS DiagnosticType, 
                      Lookup2.UserDescription AS DiagnosticTypeDesc, dbo.RH_Diagnosis.AbstractID AS zzRehabLink
FROM         dbo.RH_Diagnosis with (nolock) LEFT OUTER JOIN
                      dbo.ICD_DiagFileNRS with (nolock) ON dbo.RH_Diagnosis.DiagnosisICD = dbo.ICD_DiagFileNRS.Code LEFT OUTER JOIN
                      dbo.LU_CodeFile AS Lookup1 with (nolock) ON dbo.RH_Diagnosis.DiagnosisCode = Lookup1.Code LEFT OUTER JOIN
                      dbo.LU_DiagnosisType AS Lookup2 with (nolock) ON dbo.RH_Diagnosis.DiagnosisType = Lookup2.Code



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_FIM_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE View [dbo].[Rehab_FIM_VR]
as
    select AbstractID as zzRehabLink, FIM_Score as FIM
    from dbo.RH_FIM_Score with (nolock)



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_InHospital_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE View [dbo].[Rehab_InHospital_VR]
as
select 
    RH_ClientInfo.AbstractID as zzAssessmentLink
from dbo.RH_ClientInfo with (nolock)
    left join 
    (select LinkID
     from dbo.RH_ClientInfo with (nolock)
     where AssessmentType = 135
     group by LinkID) S on RH_ClientInfo.AbstractID = S.LinkID
where AssessmentType = 134 and S.LinkID is null and DischargeDate is null






' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_Interrupt_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[Rehab_Interrupt_VR]
AS
SELECT 
    dbo.RH_ServiceInterupt.InteruptLOS AS InterruptionLos, dbo.RH_ServiceInterupt.InteruptOccurrence AS InterruptionOccurrenceNumber, 
    Lookup1.DisplayCode AS InterruptionReason, Lookup1.UserDescription AS InterruptionReasonDesc, 
    dbo.ICD_DiagFileNRS.DisplayCode AS InterruptionReasonICD, dbo.ICD_DiagFileNRS.UserDescription AS InterruptionReasonICDDesc, 
    dbo.RH_ServiceInterupt.InteruptReturnDate AS InterruptionReturnDate, dbo.RH_ServiceInterupt.InteruptStartDate AS InterruptionStartDate, 
    Lookup2.DisplayCode AS InterruptionTransferred, Lookup2.UserDescription AS InterruptionTransferredDesc, 
    RH_ClientInfo.LinkID as [zzAssessmentLink],
    dbo.RH_ServiceInterupt.AbstractID AS zzRehabLink
FROM RH_ClientInfo with (nolock) inner join 
    dbo.RH_ServiceInterupt with (nolock) on RH_ClientInfo.ABstractID = RH_ServiceInterupt.AbstractID LEFT OUTER JOIN
    dbo.ICD_DiagFileNRS with (nolock) ON dbo.RH_ServiceInterupt.InteruptReasonICD = dbo.ICD_DiagFileNRS.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS Lookup1 with (nolock) ON dbo.RH_ServiceInterupt.InteruptReason = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS Lookup2 with (nolock) ON dbo.RH_ServiceInterupt.InteruptTransfer = Lookup2.Code
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_Interventions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[Rehab_Interventions_VR]
AS
SELECT     
Lookup20.DisplayCode AS AnestheticTechnique, Lookup20.UserDescription AS AnestheticTechniqueDesc, Lookup21.DisplayCode AS AnesthetistID, 
Lookup21.UserDescription AS AnesthetistIDDesc, 
--Lookup62.DisplayCode AS EUL, Lookup62.UserDescription AS EULDesc, 
--Lookup66.DisplayCode AS Extra, Lookup66.UserDescription AS ExtraDesc, 
dbo.ICD_ProcFileNRS.CIHIValue AS InterventionCIHIValue, 
dbo.ICD_ProcFileNRS.DisplayCode AS InterventionCode, dbo.ICD_ProcFileNRS.UserDescription AS InterventionCodeDesc, 
dbo.ICD_ProcFileNRS.ShortDescription AS InterventionCodeShortDesc, dbo.RH_Intervention.IntervDateIn, dbo.RH_Intervention.IntervDateOut, 
Lookup77.DisplayCode AS InterventionAttributeExtent, Lookup77.UserDescription AS IntervAttributeExtentDesc, 
Lookup78.DisplayCode AS InterventionAttributeLocation, Lookup78.UserDescription AS IntervAttributeLocationDesc, 
Lookup79.DisplayCode AS InterventionAttributeStatus, Lookup79.UserDescription AS IntervAttributeStatusDesc, 
dbo.RH_Intervention.IntervDate AS InterventionDate, 
Lookup80.DisplayCode AS InterventionLocation, 
Lookup80.UserDescription AS InterventionLocationDesc, dbo.RH_Intervention.IntervOccurrence AS InterventionOccurrence, 
Lookup81.DisplayCode AS InterventionProviderNumber, Lookup81.UserDescription AS InterventionProviderNumberDesc, 
Lookup82.DisplayCode AS InterventionProviderSpecialty, Lookup82.UserDescription AS IntervProviderSpecialtyDesc, 
--Lookup83.DisplayCode AS InterventionSuffix, Lookup83.UserDescription AS InterventionSuffixDesc, 
dbo.RH_Intervention.IntervTimeIn AS InterventionTimeIn, dbo.RH_Intervention.IntervTimeMinutes AS InterventionTimeinMinutes, 
dbo.RH_Intervention.IntervTimeOut AS InterventionTimeOut, Lookup97.DisplayCode AS OOHIndicator, Lookup97.UserDescription AS OOHIndicatorDesc, 
Lookup98.DisplayCode AS OOHInstitutionNumber, Lookup98.UserDescription AS OOHInstitutionNumberDesc, 
Lookup149.DisplayCode AS TissueCode, Lookup149.UserDescription AS TissueCodeDesc, Lookup154.DisplayCode AS UnplannedReturntoOR, 
Lookup154.UserDescription AS UnplannedReturntoORDesc, 
dbo.RH_Intervention.AbstractID AS zzRehabLink
FROM       
    dbo.RH_Intervention with (nolock) left join 
    dbo.ICD_ProcFileNRS with (nolock) ON dbo.ICD_ProcFileNRS.Code = dbo.RH_Intervention.IntervCode  LEFT OUTER JOIN
    dbo.LU_AnaestTechnique Lookup20 with (nolock) ON dbo.RH_Intervention.IntervAnaestTechnique = Lookup20.Code LEFT OUTER JOIN
    dbo.LU_Provider Lookup21 with (nolock) ON dbo.RH_Intervention.IntervAnaestID = Lookup21.Code LEFT OUTER JOIN
    --dbo.LU_IntervEUL Lookup62 ON dbo.RH_Intervention.IntervEUL = Lookup62.Code LEFT OUTER JOIN
    --dbo.LU_IntervExtra Lookup66 ON dbo.RH_Intervention.IntervExtra = Lookup66.Code LEFT OUTER JOIN
    dbo.LU_IntervAttExtent Lookup77 with (nolock) ON dbo.RH_Intervention.IntervAttribExtent = Lookup77.Code LEFT OUTER JOIN
    dbo.LU_IntervAttLocation Lookup78 with (nolock) ON dbo.RH_Intervention.IntervAttribLocation = Lookup78.Code LEFT OUTER JOIN
    dbo.LU_IntervAttStatus Lookup79 with (nolock) ON dbo.RH_Intervention.IntervAttribStatus = Lookup79.Code LEFT OUTER JOIN
    dbo.LU_IntervLocation_AI Lookup80 with (nolock) ON dbo.RH_Intervention.IntervLocation = Lookup80.Code LEFT OUTER JOIN
    dbo.LU_Provider Lookup81 with (nolock) ON dbo.RH_Intervention.IntervProviderNumber = Lookup81.Code LEFT OUTER JOIN
    dbo.LU_ProviderSpecialty Lookup82 with (nolock) ON dbo.RH_Intervention.IntervProviderService = Lookup82.Code LEFT OUTER JOIN
    --dbo.LU_IntervSuffix Lookup83 ON dbo.RH_Intervention.IntervSuffix = Lookup83.Code LEFT OUTER JOIN
    dbo.LU_YesBlankAlpha Lookup97 with (nolock) ON dbo.RH_Intervention.IntervOOHIndicator = Lookup97.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 Lookup98 with (nolock) ON dbo.RH_Intervention.IntervOOHInstitution = Lookup98.Code LEFT OUTER JOIN
    dbo.LU_IntervTissue Lookup149 with (nolock) ON dbo.RH_Intervention.IntervTissueCode = Lookup149.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup154 with (nolock) ON dbo.RH_Intervention.IntervUnplanReturn = Lookup154.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_Notes_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[Rehab_Notes_VR]
AS
SELECT     
   RecordID AS zzRehabLink,
   LogNote  as AbstractNotes,
   LogDate  as DateLogged,
   LogTime  as TimeLogged,
   U.DisplayCode as CreateBy,
   U.UserDescription as CreatorName        
from dbo.REC_Notes r with (nolock) left join U_users U with (nolock) on r.LogCoder=u.code
where AppID in ( 250, 251, 252 )

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_Projects_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[Rehab_Projects_VR]
AS
SELECT     
    Lookup115.DisplayCode AS ProjectNumber, Lookup115.UserDescription AS ProjectNumberDesc, 
    dbo.RH_Project.ProjectOccurrence, 
    Lookup120.DisplayCode AS Question1, Lookup120.UserDescription AS Question1Desc, Lookup121.DisplayCode AS Question10, 
    Lookup121.UserDescription AS Question10Desc, Lookup122.DisplayCode AS Question11, Lookup122.UserDescription AS Question11Desc, 
    Lookup123.DisplayCode AS Question12, Lookup123.UserDescription AS Question12Desc, Lookup124.DisplayCode AS Question13, 
    Lookup124.UserDescription AS Question13Desc, dbo.RH_Project.Question14, dbo.RH_Project.Question15, dbo.RH_Project.Question16, 
    dbo.RH_Project.Question17, Lookup125.DisplayCode AS Question2, Lookup125.UserDescription AS Question2Desc, 
    Lookup126.DisplayCode AS Question3, Lookup126.UserDescription AS Question3Desc, Lookup127.DisplayCode AS Question4, 
    Lookup127.UserDescription AS Question4Desc, Lookup128.DisplayCode AS Question5, Lookup128.UserDescription AS Question5Desc, 
    Lookup129.DisplayCode AS Question6, Lookup129.UserDescription AS Question6Desc, Lookup130.DisplayCode AS Question7, 
    Lookup130.UserDescription AS Question7Desc, Lookup131.DisplayCode AS Question8, Lookup131.UserDescription AS Question8Desc, 
    Lookup132.DisplayCode AS Question9, Lookup132.UserDescription AS Question9Desc, dbo.RH_Project.AbstractID AS zzRehabLink
FROM
    dbo.RH_Project with (nolock) LEFT OUTER JOIN
    dbo.LU_Project Lookup115 with (nolock) on dbo.RH_Project.ProjectNumber = Lookup115.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion1 Lookup120 with (nolock) on dbo.RH_Project.Question1 = Lookup120.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion10 Lookup121 with (nolock) on dbo.RH_Project.Question10 = Lookup121.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion11 Lookup122 with (nolock) on dbo.RH_Project.Question11 = Lookup122.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion12 Lookup123 with (nolock) on dbo.RH_Project.Question12 = Lookup123.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion13 Lookup124 with (nolock) on dbo.RH_Project.Question13 = Lookup124.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion2 Lookup125 with (nolock) on dbo.RH_Project.Question2 = Lookup125.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion3 Lookup126 with (nolock) on dbo.RH_Project.Question3 = Lookup126.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion4 Lookup127 with (nolock) on dbo.RH_Project.Question4 = Lookup127.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion5 Lookup128 with (nolock) on dbo.RH_Project.Question5 = Lookup128.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion6 Lookup129 with (nolock) on dbo.RH_Project.Question6 = Lookup129.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion7 Lookup130 with (nolock) on dbo.RH_Project.Question7 = Lookup130.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion8 Lookup131 with (nolock) on dbo.RH_Project.Question8 = Lookup131.Code LEFT OUTER JOIN
    dbo.LU_ProjectQuestion9 Lookup132 with (nolock) on dbo.RH_Project.Question9 = Lookup132.Code



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_Providers_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'




CREATE VIEW [dbo].[Rehab_Providers_VR]
AS
SELECT     Lookup1.DisplayCode AS ProviderNumber, Lookup1.UserDescription AS ProviderNumberDesc, 
                      dbo.RH_Provider.ProviderOccurrence AS ProviderOccurrenceNumber, LU_ProviderType.DisplayCode AS ProviderType, 
                      LU_ProviderType.UserDescription AS ProviderTypeDesc, dbo.RH_Provider.AbstractID AS zzRehabLink
FROM         dbo.RH_Provider with (nolock) LEFT OUTER JOIN
                      dbo.LU_ProviderService LU_ProviderType with (nolock) ON dbo.RH_Provider.ProviderType = LU_ProviderType.Code LEFT OUTER JOIN
                      dbo.LU_Provider Lookup1 with (nolock) ON dbo.RH_Provider.ProviderNumber = Lookup1.Code





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_RecordInformation_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[Rehab_RecordInformation_VR]
AS
SELECT  
    Lookup6.DisplayCode AS BatchPeriod, Lookup6.UserDescription AS BatchPeriodDesc, dbo.RH_ClientInfo.BatchYear, 
    Lookup151.DisplayCode as DataEntryCoder, Lookup151.UserDescription as DataEntryCoderDesc,
    dbo.RH_ClientInfo.CIHIDateSent AS DateSenttoCIHI,
    RH_ClientInfo.FinishDate, RH_ClientInfo.FinishTime, 
    RH_ClientInfo.InputDate, RH_ClientInfo.InputTime, 
    RH_ClientInfo.InterfaceDate, RH_ClientInfo.InterfaceTime, 
    Lookup150.DisplayCode as InterfaceCoder, Lookup150.UserDescription as InterfaceCoderDesc,
    Lookup51.DisplayCode AS IsAbstractCompleted, Lookup51.UserDescription AS IsAbstractCompletedDesc, 
    Lookup52.DisplayCode AS IsAbstractCorrected, Lookup52.UserDescription AS IsAbstractCorrectedDesc, 
    Lookup54.DisplayCode AS IsAbstractSubmitted, Lookup54.UserDescription AS IsAbstractSubmittedDesc, 
    Lookup55.DisplayCode AS IsAbstractValidated, Lookup55.UserDescription AS IsAbstractValidatedDesc,
    Lookup153.DisplayCode AS Secret, Lookup153.UserDescription AS SecretDesc, 
    dbo.RH_ClientInfo.AbstractID AS zzRehabLink
FROM        
 dbo.RH_ClientInfo with (nolock) LEFT OUTER JOIN
--PR - 04073
    dbo.LU_YesNoSystem Lookup54 with (nolock) on dbo.RH_ClientInfo.IsSubmited = Lookup54.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus Lookup51 with (nolock) on dbo.RH_ClientInfo.IsCompleted = Lookup51.Code LEFT OUTER JOIN
    dbo.LU_CIHICorrect Lookup52 with (nolock) on dbo.RH_ClientInfo.IsCorrected = Lookup52.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus Lookup55 with (nolock) on dbo.RH_ClientInfo.IsValidated = Lookup55.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup153 with (nolock) on dbo.RH_ClientInfo.Secret = Lookup153.Code LEFT OUTER JOIN
    dbo.U_Users Lookup151 with (nolock) on dbo.RH_ClientInfo.DataEntryCoder = Lookup151.Code LEFT OUTER JOIN
    dbo.U_Users Lookup150 with (nolock) on dbo.RH_ClientInfo.InterfaceCoder = Lookup150.Code LEFT OUTER JOIN
    dbo.LU_BatchPeriod Lookup6 with (nolock) on dbo.RH_ClientInfo.BatchPeriod = Lookup6.Code 


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_RPG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE View [dbo].[Rehab_RPG_VR]
as
select
    r.FIM_Cognitive, 
    r.FIM_Motor, 
    r.LongStay as LongStayOutlier,   --PR - 03591
    r.LOS,
    p.AverageLOS as ProvincialALOS,  --PR - 03591
    p.Volume as ProvincialVolume,    --PR - 03591
    r.Weight as RCW,  --PR - 03591
    r.RG as RehabGroup, 
    r.RPG as RehabPatientGroup, 
    r.ShortStay as ShortStayOutlier, --PR - 03591
    cast(w.Trim as dec(10, 2)) as Trim,     --PR - 04277    
    --cast(w.Trim as int) as Trim,     --PR - 04277      --PR - 03591
    r.LinkID as zzAssessmentLink
from dbo.RH_FIM_RPG r with (nolock)
    inner join (select LinkID, max(isnull(dischargedate, admitdate)) VisitDate from RH_ClientInfo with (nolock) group by LinkID) y on r.LinkID = y.LinkID
    left join dbo.RPG_RPW w with (nolock) on r.RPG = w.RPG 
        and w.FiscalYear = (case when isnull(y.VisitDate, ''1900/01/01'') < ''2009/04/01'' then 2008 else 
        Datepart(year, y.VisitDate) - (case when Datepart(month, y.VisitDate) < 4 then 1 else 0 end) end)
    left join dbo.RPG_Provincial p with (nolock) on r.RPG = p.RPG



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_UD_Abstracting_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[Rehab_UD_Abstracting_VR]
AS
SELECT
    dbo.RH_UDAbstracting.UDDate1 AS Date1UD, dbo.RH_UDAbstracting.UDDate2 AS Date2UD, 
    dbo.RH_UDAbstracting.UDDate3 AS Date3UD, dbo.RH_UDAbstracting.UDDate4 AS Date4UD,
    dbo.RH_UDAbstracting.UDDate5 AS Date5UD, dbo.RH_UDFieldsDate.UDDate6 AS Date6UD,
    dbo.RH_UDFieldsDate.UDDate7 AS Date7UD,  dbo.RH_UDFieldsDate.UDDate8 AS Date8UD,
    dbo.RH_UDFieldsDate.UDDate9 AS Date9UD,  dbo.RH_UDFieldsDate.UDDate10 AS Date10UD,
    dbo.RH_UDFieldsDate.UDDate11 AS Date11UD,  dbo.RH_UDFieldsDate.UDDate12 AS Date12UD,
    dbo.RH_UDFieldsDate.UDDate13 AS Date13UD,  dbo.RH_UDFieldsDate.UDDate14 AS Date14UD,
    dbo.RH_UDFieldsDate.UDDate15 AS Date15UD,  dbo.RH_UDFieldsDate.UDDate16 AS Date16UD,
    dbo.RH_UDFieldsDate.UDDate17 AS Date17UD,  dbo.RH_UDFieldsDate.UDDate18 AS Date18UD,
    dbo.RH_UDFieldsDate.UDDate19 AS Date19UD,  dbo.RH_UDFieldsDate.UDDate20 AS Date20UD,
    dbo.RH_UDFieldsDate.UDDate21 AS Date21UD,  dbo.RH_UDFieldsDate.UDDate22 AS Date22UD,
    dbo.RH_UDFieldsDate.UDDate23 AS Date23UD,  dbo.RH_UDFieldsDate.UDDate24 AS Date24UD,
    dbo.RH_UDFieldsDate.UDDate25 AS Date25UD,  
    
    LU_CodeFile.DisplayCode AS Lookup1UD, dbo.LU_CodeFile.UserDescription AS Lookup1UDDesc, 
    LU_CodeFile_1.DisplayCode AS Lookup2UD, LU_CodeFile_1.UserDescription AS Lookup2UDDesc, 
    LU_CodeFile_2.DisplayCode AS Lookup3UD, LU_CodeFile_2.UserDescription AS Lookup3UDDesc, 
    LU_CodeFile_3.DisplayCode AS Lookup4UD, LU_CodeFile_3.UserDescription AS Lookup4UDDesc, 
    LU_Lookup5UD.DisplayCode AS Lookup5UD, LU_Lookup5UD.UserDescription AS Lookup5UDDesc, 
    LU_CodeFile_6.DisplayCode AS Lookup6UD, LU_CodeFile_6.UserDescription AS Lookup6UDDesc, 
    LU_CodeFile_7.DisplayCode AS Lookup7UD, LU_CodeFile_7.UserDescription AS Lookup7UDDesc, 
    LU_CodeFile_8.DisplayCode AS Lookup8UD, LU_CodeFile_8.UserDescription AS Lookup8UDDesc, 
    LU_CodeFile_9.DisplayCode AS Lookup9UD, LU_CodeFile_9.UserDescription AS Lookup9UDDesc, 
    LU_CodeFile_10.DisplayCode AS Lookup10UD, LU_CodeFile_10.UserDescription AS Lookup10UDDesc, 
    LU_CodeFile_11.DisplayCode AS Lookup11UD, LU_CodeFile_11.UserDescription AS Lookup11UDDesc, 
    LU_CodeFile_12.DisplayCode AS Lookup12UD, LU_CodeFile_12.UserDescription AS Lookup12UDDesc, 
    LU_CodeFile_13.DisplayCode AS Lookup13UD, LU_CodeFile_13.UserDescription AS Lookup13UDDesc, 
    LU_CodeFile_14.DisplayCode AS Lookup14UD, LU_CodeFile_14.UserDescription AS Lookup14UDDesc, 
    LU_CodeFile_15.DisplayCode AS Lookup15UD, LU_CodeFile_15.UserDescription AS Lookup15UDDesc, 
    LU_CodeFile_16.DisplayCode AS Lookup16UD, LU_CodeFile_16.UserDescription AS Lookup16UDDesc, 
    LU_CodeFile_17.DisplayCode AS Lookup17UD, LU_CodeFile_17.UserDescription AS Lookup17UDDesc, 
    LU_CodeFile_18.DisplayCode AS Lookup18UD, LU_CodeFile_18.UserDescription AS Lookup18UDDesc, 
    LU_CodeFile_19.DisplayCode AS Lookup19UD, LU_CodeFile_19.UserDescription AS Lookup19UDDesc, 
    LU_CodeFile_20.DisplayCode AS Lookup20UD, LU_CodeFile_20.UserDescription AS Lookup20UDDesc, 
    LU_CodeFile_21.DisplayCode AS Lookup21UD, LU_CodeFile_21.UserDescription AS Lookup21UDDesc, 
    LU_CodeFile_22.DisplayCode AS Lookup22UD, LU_CodeFile_22.UserDescription AS Lookup22UDDesc, 
    LU_CodeFile_23.DisplayCode AS Lookup23UD, LU_CodeFile_23.UserDescription AS Lookup23UDDesc, 
    LU_CodeFile_24.DisplayCode AS Lookup24UD, LU_CodeFile_24.UserDescription AS Lookup24UDDesc, 
    LU_CodeFile_25.DisplayCode AS Lookup25UD, LU_CodeFile_25.UserDescription AS Lookup25UDDesc, 
    
    dbo.RH_UDAbstracting.UDInteger1 AS Numeric1UD, dbo.RH_UDAbstracting.UDInteger2 AS Numeric2UD, 
    dbo.RH_UDAbstracting.UDInteger3 AS Numeric3UD, dbo.RH_UDAbstracting.UDInteger4 AS Numeric4UD, 
    dbo.RH_UDAbstracting.UDInteger5 AS Numeric5UD, 
    dbo.RH_UDFieldsInteger.UDInteger6 AS Numeric6UD, 
    dbo.RH_UDFieldsInteger.UDInteger7 AS Numeric7UD, 
    dbo.RH_UDFieldsInteger.UDInteger8 AS Numeric8UD, 
    dbo.RH_UDFieldsInteger.UDInteger9 AS Numeric9UD, 
    dbo.RH_UDFieldsInteger.UDInteger10 AS Numeric10UD, 
    dbo.RH_UDFieldsInteger.UDInteger11 AS Numeric11UD, 
    dbo.RH_UDFieldsInteger.UDInteger12 AS Numeric12UD, 
    dbo.RH_UDFieldsInteger.UDInteger13 AS Numeric13UD, 
    dbo.RH_UDFieldsInteger.UDInteger14 AS Numeric14UD, 
    dbo.RH_UDFieldsInteger.UDInteger15 AS Numeric15UD, 
    dbo.RH_UDFieldsInteger.UDInteger16 AS Numeric16UD, 
    dbo.RH_UDFieldsInteger.UDInteger17 AS Numeric17UD, 
    dbo.RH_UDFieldsInteger.UDInteger18 AS Numeric18UD, 
    dbo.RH_UDFieldsInteger.UDInteger19 AS Numeric19UD, 
    dbo.RH_UDFieldsInteger.UDInteger20 AS Numeric20UD, 
    dbo.RH_UDFieldsInteger.UDInteger21 AS Numeric21UD, 
    dbo.RH_UDFieldsInteger.UDInteger22 AS Numeric22UD, 
    dbo.RH_UDFieldsInteger.UDInteger23 AS Numeric23UD, 
    dbo.RH_UDFieldsInteger.UDInteger24 AS Numeric24UD, 
    dbo.RH_UDFieldsInteger.UDInteger25 AS Numeric25UD, 
    
    dbo.RH_UDAbstracting.UDText1 AS Notes1UD, dbo.RH_UDAbstracting.UDText2 AS Notes2UD, 
    dbo.RH_UDAbstracting.UDText3 AS Notes3UD, dbo.RH_UDAbstracting.UDText4 AS Notes4UD, 
    dbo.RH_UDAbstracting.UDText5 AS Notes5UD, 
    dbo.RH_UDFieldsText.UDText6 AS Notes6UD,
    dbo.RH_UDFieldsText.UDText7 AS Notes7UD,
    dbo.RH_UDFieldsText.UDText8 AS Notes8UD,
    dbo.RH_UDFieldsText.UDText9 AS Notes9UD,
    dbo.RH_UDFieldsText.UDText10 AS Notes10UD,
    dbo.RH_UDFieldsText.UDText11 AS Notes11UD,
    dbo.RH_UDFieldsText.UDText12 AS Notes12UD,
    dbo.RH_UDFieldsText.UDText13 AS Notes13UD,
    dbo.RH_UDFieldsText.UDText14 AS Notes14UD,
    dbo.RH_UDFieldsText.UDText15 AS Notes15UD,
    dbo.RH_UDFieldsText.UDText16 AS Notes16UD,
    dbo.RH_UDFieldsText.UDText17 AS Notes17UD,
    dbo.RH_UDFieldsText.UDText18 AS Notes18UD,
    dbo.RH_UDFieldsText.UDText19 AS Notes19UD,
    dbo.RH_UDFieldsText.UDText20 AS Notes20UD,
    dbo.RH_UDFieldsText.UDText21 AS Notes21UD,
    dbo.RH_UDFieldsText.UDText22 AS Notes22UD,
    dbo.RH_UDFieldsText.UDText23 AS Notes23UD,
    dbo.RH_UDFieldsText.UDText24 AS Notes24UD,
    dbo.RH_UDFieldsText.UDText25 AS Notes25UD,
    
    dbo.RH_UDAbstracting.UDSmallText1 AS Text1UD, dbo.RH_UDAbstracting.UDSmallText2 AS Text2UD, 
    dbo.RH_UDAbstracting.UDSmallText3 AS Text3UD, dbo.RH_UDAbstracting.UDSmallText4 AS Text4UD, 
    dbo.RH_UDAbstracting.UDSmallText5 AS Text5UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText6 AS Text6UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText7 AS Text7UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText8 AS Text8UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText9 AS Text9UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText10 AS Text10UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText11 AS Text11UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText12 AS Text12UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText13 AS Text13UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText14 AS Text14UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText15 AS Text15UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText16 AS Text16UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText17 AS Text17UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText18 AS Text18UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText19 AS Text19UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText20 AS Text20UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText21 AS Text21UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText22 AS Text22UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText23 AS Text23UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText24 AS Text24UD, 
    dbo.RH_UDFieldsSmallText.UDSmallText25 AS Text25UD, 
    
    dbo.RH_UDAbstracting.UDTime1 AS Time1UD, dbo.RH_UDAbstracting.UDTime2 AS Time2UD, 
    dbo.RH_UDAbstracting.UDTime3 AS Time3UD, dbo.RH_UDAbstracting.UDTime4 AS Time4UD, 
    dbo.RH_UDAbstracting.UDTime5 AS Time5UD, 
    dbo.RH_UDFieldsTime.UDTime6 AS Time6UD, 
    dbo.RH_UDFieldsTime.UDTime7 AS Time7UD, 
    dbo.RH_UDFieldsTime.UDTime8 AS Time8UD, 
    dbo.RH_UDFieldsTime.UDTime9 AS Time9UD, 
    dbo.RH_UDFieldsTime.UDTime10 AS Time10UD, 
    dbo.RH_UDFieldsTime.UDTime11 AS Time11UD, 
    dbo.RH_UDFieldsTime.UDTime12 AS Time12UD, 
    dbo.RH_UDFieldsTime.UDTime13 AS Time13UD, 
    dbo.RH_UDFieldsTime.UDTime14 AS Time14UD, 
    dbo.RH_UDFieldsTime.UDTime15 AS Time15UD, 
    dbo.RH_UDFieldsTime.UDTime16 AS Time16UD, 
    dbo.RH_UDFieldsTime.UDTime17 AS Time17UD, 
    dbo.RH_UDFieldsTime.UDTime18 AS Time18UD, 
    dbo.RH_UDFieldsTime.UDTime19 AS Time19UD, 
    dbo.RH_UDFieldsTime.UDTime20 AS Time20UD, 
    dbo.RH_UDFieldsTime.UDTime21 AS Time21UD, 
    dbo.RH_UDFieldsTime.UDTime22 AS Time22UD, 
    dbo.RH_UDFieldsTime.UDTime23 AS Time23UD, 
    dbo.RH_UDFieldsTime.UDTime24 AS Time24UD, 
    dbo.RH_UDFieldsTime.UDTime25 AS Time25UD, 
        
    dbo.RH_UDAbstracting.Abstractid AS zzRehabLink
FROM         
    dbo.RH_UDAbstracting with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_3 with (nolock) ON dbo.RH_UDAbstracting.UDLookup4 = LU_CodeFile_3.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_2 with (nolock) ON dbo.RH_UDAbstracting.UDLookup3 = LU_CodeFile_2.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_1 with (nolock) ON dbo.RH_UDAbstracting.UDLookup2 = LU_CodeFile_1.Code LEFT OUTER JOIN
    dbo.LU_CodeFile with (nolock) ON dbo.RH_UDAbstracting.UDLookup1 = dbo.LU_CodeFile.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_Lookup5UD with (nolock) ON dbo.RH_UDAbstracting.UDLookup5 = LU_Lookup5UD.Code LEFT OUTER JOIN

    dbo.RH_UDFieldsDate with (nolock) ON dbo.RH_UDAbstracting.AbstractiD = dbo.RH_UDFieldsDate.AbstractID LEFT OUTER JOIN
    dbo.RH_UDFieldsInteger with (nolock) ON dbo.RH_UDAbstracting.AbstractiD = dbo.RH_UDFieldsInteger.AbstractID LEFT OUTER JOIN
    dbo.RH_UDFieldsLookUp with (nolock) ON dbo.RH_UDAbstracting.AbstractiD = dbo.RH_UDFieldsLookUp.AbstractID LEFT OUTER JOIN
    dbo.RH_UDFieldsSmallText with (nolock) ON dbo.RH_UDAbstracting.AbstractiD = dbo.RH_UDFieldsSmallText.AbstractID LEFT OUTER JOIN
    dbo.RH_UDFieldsText with (nolock) ON dbo.RH_UDAbstracting.AbstractiD = dbo.RH_UDFieldsText.AbstractID LEFT OUTER JOIN
    dbo.RH_UDFieldsTime with (nolock) ON dbo.RH_UDAbstracting.AbstractiD = dbo.RH_UDFieldsTime.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_6 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup6 = LU_CodeFile_6.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_7 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup7 = LU_CodeFile_7.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_8 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup8 = LU_CodeFile_8.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_9 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup9 = LU_CodeFile_9.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_10 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup10 = LU_CodeFile_10.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_11 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup11 = LU_CodeFile_11.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_12 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup12 = LU_CodeFile_12.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_13 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup13 = LU_CodeFile_13.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_14 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup14 = LU_CodeFile_14.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_15 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup15 = LU_CodeFile_15.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_16 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup16 = LU_CodeFile_16.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_17 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup17 = LU_CodeFile_17.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_18 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup18 = LU_CodeFile_18.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_19 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup19 = LU_CodeFile_19.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_20 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup20 = LU_CodeFile_20.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_21 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup21 = LU_CodeFile_21.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_22 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup22 = LU_CodeFile_22.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_23 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup23 = LU_CodeFile_23.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_24 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup24 = LU_CodeFile_24.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_25 with (nolock) ON dbo.RH_UDFieldsLookUp.UDLookup25 = LU_CodeFile_25.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[Rehab_UpdateHistory_VR]
AS
SELECT     coder.DisplayCode AS UpdateCoder, coder.UserDescription AS UpdateCoderDesc, upHis.Updated AS UpdateDate, upHis.UpdateType, 
                      upHis.AbstractID AS zzRehabLink
FROM         dbo.RH_UpdateHistory upHis with (nolock) INNER JOIN
                      dbo.U_Users coder with (nolock) ON upHis.Coder = coder.Code




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[Rehab_VR]
AS
SELECT 
    LU_AboriginalStatus.DisplayCode AS AboriginalStatus, LU_AboriginalStatus.UserDescription AS AboriginalStatusDesc, 
    --dbo.RH_ClientInfo.AbstractNumber, PR - 04458 removed. abstract number is useless
    Lookup1.DisplayCode AS AdmissionClass, Lookup1.UserDescription AS AdmissionClassDesc, 
    dbo.RH_ClientInfo.AdmitDate AS AdmissionDate, Lookup2.DisplayCode AS AgeCode, Lookup2.UserDescription AS AgeCodeDesc, 
    dbo.RH_Demographic.AgeNumber, Lookup3.DisplayCode AS ASIAImpairmentScale, Lookup3.UserDescription AS ASIAImpairmentScaleDesc, 
    Lookup4.DisplayCode AS AssessmentType, Lookup4.UserDescription AS AssessmentTypeDesc, 
    -- PR - 02377
    AttendingPhysician = LU_AttProvider.DisplayCode, AttendingPhysicianDesc = LU_AttProvider.UserDescription, 

    Lookup5.DisplayCode AS AuditoryorNonAuditoryComm, Lookup5.UserDescription AS AuditoryorNonAuditoryCommDesc, 

    dbo.LU_BasicOption1.DisplayCode  AS BasicOption1,  dbo.LU_BasicOption1.UserDescription  AS BasicOption1Desc, 
    dbo.LU_BasicOption2.DisplayCode  AS BasicOption2,  dbo.LU_BasicOption2.UserDescription  AS BasicOption2Desc, 
    dbo.LU_BasicOption3.DisplayCode  AS BasicOption3,  dbo.LU_BasicOption3.UserDescription  AS BasicOption3Desc, 
    dbo.LU_BasicOption4.DisplayCode  AS BasicOption4,  dbo.LU_BasicOption4.UserDescription  AS BasicOption4Desc, 
    dbo.LU_BasicOption5.DisplayCode  AS BasicOption5,  dbo.LU_BasicOption5.UserDescription  AS BasicOption5Desc, 
    dbo.LU_BasicOption6.DisplayCode  AS BasicOption6,  dbo.LU_BasicOption6.UserDescription  AS BasicOption6Desc, 
    dbo.LU_BasicOption7.DisplayCode  AS BasicOption7,  dbo.LU_BasicOption7.UserDescription  AS BasicOption7Desc, 
    dbo.LU_BasicOption8.DisplayCode  AS BasicOption8,  dbo.LU_BasicOption8.UserDescription  AS BasicOption8Desc, 
    dbo.LU_BasicOption9.DisplayCode  AS BasicOption9,  dbo.LU_BasicOption9.UserDescription  AS BasicOption9Desc, 
    dbo.LU_BasicOption10.DisplayCode AS BasicOption10, dbo.LU_BasicOption10.UserDescription AS BasicOption10Desc, 
    dbo.LU_BasicOption11.DisplayCode AS BasicOption11, dbo.LU_BasicOption11.UserDescription AS BasicOption11Desc, 
    dbo.LU_BasicOption12.DisplayCode AS BasicOption12, dbo.LU_BasicOption12.UserDescription AS BasicOption12Desc, 
    dbo.LU_BasicOption13.DisplayCode AS BasicOption13, dbo.LU_BasicOption13.UserDescription AS BasicOption13Desc, 
    dbo.LU_BasicOption14.DisplayCode AS BasicOption14, dbo.LU_BasicOption14.UserDescription AS BasicOption14Desc, 
    dbo.LU_BasicOption15.DisplayCode AS BasicOption15, dbo.LU_BasicOption15.UserDescription AS BasicOption15Desc, 
    dbo.LU_BasicOption16.DisplayCode AS BasicOption16, dbo.LU_BasicOption16.UserDescription AS BasicOption16Desc, 
    dbo.LU_BasicOption17.DisplayCode AS BasicOption17, dbo.LU_BasicOption17.UserDescription AS BasicOption17Desc, 
    dbo.LU_BasicOption18.DisplayCode AS BasicOption18, dbo.LU_BasicOption18.UserDescription AS BasicOption18Desc, 
    dbo.LU_BasicOption19.DisplayCode AS BasicOption19, dbo.LU_BasicOption19.UserDescription AS BasicOption19Desc, 

    Lookup6.DisplayCode AS BatchPeriod, Lookup6.UserDescription AS BatchPeriodDesc, dbo.RH_ClientInfo.BatchYear, Lookup7.DisplayCode AS Bathing,
    Lookup7.UserDescription AS BathingDesc, Lookup8.DisplayCode AS BedChairWheelchair, Lookup8.UserDescription AS BedChairWheelchairDesc, 
    dbo.RH_Demographic.BirthDate, Lookup9.DisplayCode AS BladderManagement, Lookup9.UserDescription AS BladderManagementDesc, 
    Lookup10.DisplayCode AS BowelManagement, Lookup10.UserDescription AS BowelManagementDesc, 
    Lookup11.DisplayCode AS CanadianResidentInsPay, Lookup11.UserDescription AS CanadianResidentInsPayDesc, 
    Lookup12.DisplayCode AS CanadianResidentSelfPay, Lookup12.UserDescription AS CanadianResidentSelfPayDesc, dbo.RH_ClientInfo.ChartNumber, 
    dbo.U_Users.DisplayCode AS CoderNumber, dbo.U_Users.UserDescription AS CoderNumberDesc, Lookup13.DisplayCode AS CognitiveDiscipline, 
    Lookup13.UserDescription AS CognitiveDisciplineDesc, Lookup14.DisplayCode AS CognitiveType, Lookup14.UserDescription AS CognitiveTypeDesc, 
    Lookup15.DisplayCode AS CommunicationDiscipline, Lookup15.UserDescription AS CommunicationDisciplineDesc, 
    Lookup16.DisplayCode AS CommunicationType, Lookup16.UserDescription AS CommunicationTypeDesc, Lookup17.DisplayCode AS Comprehension, 
    Lookup17.UserDescription AS ComprehensionDesc, Lookup18.DisplayCode AS ComprehensionMode, 
    Lookup18.UserDescription AS ComprehensionModeDesc, Lookup19.DisplayCode AS ConsultationDiscipline, 
    Lookup19.UserDescription AS ConsultationDisciplineDesc, Lookup20.DisplayCode AS ConsultationType, 
    Lookup20.UserDescription AS ConsultationTypeDesc, Lookup21.DisplayCode AS CountryofResidence, 
    Lookup21.UserDescription AS CountryofResidenceDesc, 
    Lookup151.DisplayCode as DataEntryCoder, Lookup151.UserDescription as DataEntryCoderDesc,
    dbo.RH_Health.DateOnset AS DateofOnset, 
    dbo.RH_Administrative.ReadyAdmitDate AS DateReadyForAdmission, Lookup22.DisplayCode AS DateReadyForAdmitKnown, 
    Lookup22.UserDescription AS DateReadyForAdmitKnownDesc, dbo.RH_Administrative.DateReadyDischarge AS DateReadyforDischarge, 
    dbo.RH_ClientInfo.CIHIDateSent AS DateSenttoCIHI, dbo.RH_Health.HospDays AS DaysinHospitaltotalnumber, 
    Lookup23.DisplayCode AS DealWithLifeEvents, Lookup23.UserDescription AS DealWithLifeEventsDesc, 

    (case when Lookup4.CIHIValue in (''2'', ''3'') or (Lookup4.CIHIValue = ''1'' and Lookup1.CIHIValue = ''4'') then dbo.RH_ClientInfo.DischargeDate else null end) as DischargeDate, 

    Lookup24.DisplayCode AS DressingLowerBody, Lookup24.UserDescription AS DressingLowerBodyDesc, 
    Lookup25.DisplayCode AS DressingUpperBody, Lookup25.UserDescription AS DressingUpperBodyDesc, Lookup26.DisplayCode AS Eating, 
    Lookup26.UserDescription AS EatingDesc, Lookup27.DisplayCode AS EducationDiscipline, Lookup27.UserDescription AS EducationDisciplineDesc, 
    Lookup28.DisplayCode AS EducationType, Lookup28.UserDescription AS EducationTypeDesc, dbo.RH_ClientInfo.EncounterNumber, 
    Lookup29.DisplayCode AS EquipmentDiscipline, Lookup29.UserDescription AS EquipmentDisciplineDesc, Lookup30.DisplayCode AS EquipmentType, 
    Lookup30.UserDescription AS EquipmentTypeDesc, Lookup31.DisplayCode AS EstimatedBirthdate, 
    Lookup31.UserDescription AS EstimatedBirthdateDesc, Lookup32.DisplayCode AS Expression, Lookup32.UserDescription AS ExpressionDesc, 
    Lookup33.DisplayCode AS ExpressionMode, Lookup33.UserDescription AS ExpressionModeDesc, Lookup34.DisplayCode AS FacilityIdentifier, 
    Lookup34.UserDescription AS FacilityIdentifierDesc, Lookup35.DisplayCode AS FamilyRole, Lookup35.UserDescription AS FamilyRoleDesc, 
    Lookup36.DisplayCode AS FederalGovtDVA, Lookup36.UserDescription AS FederalGovtDVADesc, Lookup37.DisplayCode AS FederalGovtFNIHB, 
    Lookup37.UserDescription AS FederalGovtFNIHBDesc, Lookup38.DisplayCode AS FederalGovtOther, 
    Lookup38.UserDescription AS FederalGovtOtherDesc, 
    --Begin Calculate FIM
    CAST(ISNULL(Lookup26.DisplayCode, ''0'') AS int) + CAST(ISNULL(Lookup41.DisplayCode, ''0'') AS int) + 
    CAST(ISNULL(Lookup7.DisplayCode, ''0'') AS int) + CAST(ISNULL(Lookup24.DisplayCode, ''0'') AS int) + 
    CAST(ISNULL(Lookup25.DisplayCode, ''0'') AS int) + CAST(ISNULL(Lookup131.DisplayCode, ''0'') AS int) + 
    CAST(ISNULL(Lookup9.DisplayCode, ''0'') AS int) + CAST(ISNULL(Lookup10.DisplayCode, ''0'') AS int) + 
    CAST(ISNULL(Lookup8.DisplayCode, ''0'') AS int) + CAST(ISNULL(Lookup130.DisplayCode, ''0'') AS int) +
    CAST(ISNULL(Lookup133.DisplayCode, ''0'') AS int) + CAST(ISNULL(Lookup141.DisplayCode, ''0'') AS int) + 
    CAST(ISNULL(Lookup125.DisplayCode, ''0'') AS int) + CAST(ISNULL(Lookup17.DisplayCode, ''0'') AS int) + 
    CAST(ISNULL(Lookup32.DisplayCode, ''0'') AS int) + CAST(ISNULL(Lookup122.DisplayCode, ''0'') AS int) + 
    CAST(ISNULL(Lookup91.DisplayCode, ''0'') AS int) + CAST(ISNULL(Lookup66.DisplayCode, ''0'') AS int) AS FIM, 
    --End Calculate FIM
    Lookup39.DisplayCode AS FinancialManagement, Lookup39.UserDescription AS FinancialManagementDesc, 
    RH_ClientInfo.FinishDate, RH_ClientInfo.FinishTime, 
    dbo.RH_Demographic.FirstName, 
    FixedChartNumber,
    dbo.RH_ClientInfo.FollowUpDate AS FollowUpAssessmentDate, Lookup40.DisplayCode AS Gender, 
--ED - 01568
    LU_GlassHear.DisplayCode as GlassesHearingAidFlag, LU_GlassHear.UserDescription as GlassesHearingAidFlagDesc, 

    Lookup40.UserDescription AS GenderDesc, Lookup41.DisplayCode AS Grooming, Lookup41.UserDescription AS GroomingDesc, 

    dbo.RH_ClientInfo.HCNVersion AS HCNVersion, dbo.RH_ClientInfo.HealthCareNumber AS HealthCardNumber, 
    Lookup42.DisplayCode AS HeavyHouseworkoptional, 
    Lookup42.UserDescription AS HeavyHouseworkoptionalDesc, dbo.RH_Health.Height AS Heightoptional, 

    LU_Hospital.DisplayCode as Hospital, LU_Hospital.UserDescription as HospitalDesc, 
    dbo.RH_ClientInfo.HospitalAccountRecord,
    Lookup43.DisplayCode AS HospitalizationSinceDisch, Lookup43.UserDescription AS HospitalizationSinceDischDesc, 
    Lookup44.DisplayCode AS ImpactofPainOnActivities, Lookup44.UserDescription AS ImpactofPainOnActivitiesDesc, 
    Lookup45.DisplayCode AS InformalSupportReceived, Lookup45.UserDescription AS InformalSupportReceivedDesc, 
    Lookup46.DisplayCode AS InitialDiscipline, Lookup46.UserDescription AS InitialDisciplineDesc, Lookup47.DisplayCode AS InitialType, 
    Lookup47.UserDescription AS InitialTypeDesc, Lookup48.DisplayCode AS InjectionsDiscipline, Lookup48.UserDescription AS InjectionsDisciplineDesc, 
    Lookup49.DisplayCode AS InjectionsType, Lookup49.UserDescription AS InjectionsTypeDesc, 
    
    RH_ClientInfo.InputDate, RH_ClientInfo.InputTime, 

    (case when Lookup4.CIHIValue = ''IA'' then dbo.RH_ClientInfo.DischargeDate else null end) as  InterimDate, 


    Lookup50.DisplayCode AS IntensityofPain, Lookup50.UserDescription AS IntensityofPainDesc, 
    
    RH_ClientInfo.InterfaceDate, RH_ClientInfo.InterfaceTime, 
    Lookup150.DisplayCode as InterfaceCoder, Lookup150.UserDescription as InterfaceCoderDesc,
    
    Lookup51.DisplayCode AS IsAbstractCompleted, 
    Lookup51.UserDescription AS IsAbstractCompletedDesc, Lookup52.DisplayCode AS IsAbstractCorrected, 
    Lookup52.UserDescription AS IsAbstractCorrectedDesc, Lookup53.DisplayCode AS IsAbstractDeleted, 
    Lookup53.UserDescription AS IsAbstractDeletedDesc, Lookup54.DisplayCode AS IsAbstractSubmitted, 
    Lookup54.UserDescription AS IsAbstractSubmittedDesc, Lookup55.DisplayCode AS IsAbstractValidated, 
    Lookup55.UserDescription AS IsAbstractValidatedDesc, dbo.RH_Demographic.LastName, Lookup56.DisplayCode AS LightHouseworkoptional, 
    Lookup56.UserDescription AS LightHouseworkoptionalDesc, dbo.RH_ClientInfo.LinkID, Lookup57.DisplayCode AS LivingAlone, 
    Lookup57.UserDescription AS LivingAloneDesc, 
--ED - 01568
    LU_LivingInAcute.DisplayCode as LivingInAcuteCare, LU_LivingInAcute.UserDescription as LivingInAcuteCareDesc, 

    Lookup58.DisplayCode AS LivingInFacilityAllLevels, Lookup58.UserDescription AS LivingInFacilityAllLevelsDesc, 
    Lookup59.DisplayCode AS LivingwithFamily, Lookup59.UserDescription AS LivingwithFamilyDesc, 
    -- PR - 03792 Duplicate with PreHospitalLivingSetting
    Lookup87.DisplayCode AS [LivingSetting(Pre/Post/FU)], Lookup87.UserDescription AS [LivingSettingDesc(Pre/Post/FU)], 
    
    Lookup60.DisplayCode AS LivingwithNonFamilyUnpaid, 
    Lookup60.UserDescription AS LivingwithNonFamilyUnpaidDesc, Lookup61.DisplayCode AS LivingwithPaidAttendant, 
    Lookup61.UserDescription AS LivingwithPaidAttendantDesc, Lookup62.DisplayCode AS LivingwithSpousePartner, 
    Lookup62.UserDescription AS LivingwithSpousePartnerDesc, 
    --ED - 01556
    (Case when DischargeDate is not null and  dbo.RH_ClientInfo.LOSDays > 0 then dbo.RH_ClientInfo.LOSDays
          else dbo.GetRehabActiveLos(dbo.RH_ClientInfo.AbstractID, Lookup4.CIHIValue, dbo.RH_ClientInfo.AdmitDate, 
               dbo.RH_ClientInfo.DischargeDate, dbo.RH_ClientInfo.Followupdate, getdate()) 
     end) as LOSDays,

    dbo.RH_Demographic.MaidenName, 
    dbo.RH_Health.WrittenConditionMain AS MainWrittenHealthCondition, Lookup63.DisplayCode AS ManualTechDiscipline, 
    Lookup63.UserDescription AS ManualTechDisciplineDesc, Lookup64.DisplayCode AS ManualTechniquesType, 
    Lookup64.UserDescription AS ManualTechniquesTypeDesc, Lookup65.DisplayCode AS MealPreparationoptional, 
    Lookup65.UserDescription AS MealPreparationoptionalDesc, Lookup66.DisplayCode AS Memory, Lookup66.UserDescription AS MemoryDesc, 
    dbo.RH_Demographic.MiddleName, 
    -- PR - 02377
    MISCode = LU_MISCode.DisplayCode, MISCodeDesc = LU_MISCode.UserDescription, 

    Lookup67.DisplayCode AS MobilityinCommunity, Lookup67.UserDescription AS MobilityinCommunityDesc, 
    Lookup68.DisplayCode AS MobilityinLivingQuarters, Lookup68.UserDescription AS MobilityinLivingQuartersDesc, 
    dbo.RH_Demographic.LastName + '', '' + dbo.RH_Demographic.FirstName + '' '' + dbo.RH_Demographic.MiddleName AS NameFull, 
    dbo.RH_ClientInfo.NextAssessDate as NextAssessmentDate,
    Lookup69.DisplayCode AS NoneoftheAbove, Lookup69.UserDescription AS NoneoftheAboveDesc, 
    -- PR - 02377
    NursingArea = LU_AdmitNurse.DisplayCode, NursingAreaDesc = LU_AdmitNurse.UserDescription, 

    Lookup70.DisplayCode AS NutritionalDiscipline, 
    Lookup70.UserDescription AS NutritionalDisciplineDesc, Lookup71.DisplayCode AS NutritionalType, 
    Lookup71.UserDescription AS NutritionalTypeDesc, Lookup72.DisplayCode AS Orientation, Lookup72.UserDescription AS OrientationDesc, 
    Lookup73.DisplayCode AS OtherCountrySelfPay, Lookup73.UserDescription AS OtherCountrySelfPayDesc, 
    Lookup74.DisplayCode AS OtherLivingArrangements, Lookup74.UserDescription AS OtherLivingArrangementsDesc, 
    Lookup75.DisplayCode AS OtherProvTerritoryResidant, Lookup75.UserDescription AS OtherProvTerritoryResidantDesc, 
    Lookup76.DisplayCode AS OutofTownTrips, Lookup76.UserDescription AS OutofTownTripsDesc, 

    LUPaidAdjusted.DisplayCode as PaidEmployAdjustedMod, LUPaidAdjusted.UserDescription as PaidEmployAdjustedModDesc, 
    Lookup77.DisplayCode AS PaidEmploymentFullTime, 
    Lookup77.UserDescription AS PaidEmploymentFullTimeDesc, Lookup78.DisplayCode AS PaidEmploymentPartTime, 
    Lookup78.UserDescription AS PaidEmploymentPartTimeDesc, Lookup79.DisplayCode AS PersonalComfortwithOthers, 
    Lookup79.UserDescription AS PersonalComfortwithOthersDesc, Lookup80.DisplayCode AS PersonalRelationships, 
    Lookup80.UserDescription AS PersonalRelationshipsDesc, Lookup81.DisplayCode AS PhysicalDiscipline, 
    Lookup81.UserDescription AS PhysicalDisciplineDesc, Lookup82.DisplayCode AS PhysicalModalitiesDiscipline, 
    Lookup82.UserDescription AS PhysicalModalitiesDiscDesc, Lookup83.DisplayCode AS PhysicalModalitiesType, 
    Lookup83.UserDescription AS PhysicalModalitiesTypeDesc, Lookup84.DisplayCode AS PhysicalType, 
    Lookup84.UserDescription AS PhysicalTypeDesc, Lookup85.DisplayCode AS PlannedReAdmission, 
    Lookup85.UserDescription AS PlannedReAdmissionDesc, dbo.RH_Demographic.PostalCode, 

    -- ED - 01682
    dbo.GetPostalDescription(isnull(dbo.RH_Demographic.PostalCode, ''''), isnull(dbo.RH_ClientInfo.DischargeDate, dbo.RH_ClientInfo.AdmitDate)) AS PostalCodeDesc, -- ED - 01682

    dbo.RH_Health.WrittenCondition1 AS PrePostAdmitWrittenHCond1, dbo.RH_Health.WrittenCondition2 AS PrePostAdmitWrittenHCond2, 
    dbo.RH_Health.WrittenCondition3 AS PrePostAdmitWrittenHCond3, 
    Lookup87.DisplayCode AS PreHospitalLivingSetting, Lookup87.UserDescription AS PreHospitalLivingSettingDesc, 
    Lookup88.DisplayCode AS PresenceofCognitiveImpair, 
    Lookup88.UserDescription AS PresenceofCognitiveImpairDesc, Lookup89.DisplayCode AS PresenceofPain, 
    Lookup89.UserDescription AS PresenceofPainDesc, 

    Lookup90.DisplayCode AS PrimaryLanguage, Lookup90.UserDescription AS PrimaryLanguageDesc, 
    --ED - 01602
    LU_LanguageISO.DisplayCode AS PrimaryLanguageISO, LU_LanguageISO.UserDescription AS PrimaryLanguageISODesc, 
    --ED - 02265, ED - 02266
    LU_PrimaryReasonWaiting.DisplayCode AS PrimaryReasonWaitingDischarge, LU_PrimaryReasonWaiting.UserDescription AS PrimaryReasonWaitingDischargeDesc, 

    Lookup91.DisplayCode AS ProblemSolving, Lookup91.UserDescription AS ProblemSolvingDesc, 
    Lookup92.DisplayCode AS ProgramType, Lookup92.UserDescription AS ProgramTypeDesc, Lookup93.DisplayCode AS ProvinceIssuingHCN, 
    Lookup93.UserDescription AS ProvinceIssuingHCNDesc, Lookup94.DisplayCode AS ProvinceofResidence, 
    Lookup94.UserDescription AS ProvinceofResidenceDesc, Lookup95.DisplayCode AS ProvinceTerritorialPlan, 
    Lookup95.UserDescription AS ProvinceTerritorialPlanDesc, Lookup96.DisplayCode AS ProvincialDefinition, 
    Lookup96.UserDescription AS ProvincialDefinitionDesc, Lookup97.DisplayCode AS PsychoSocialDiscipline, 
    Lookup97.UserDescription AS PsychoSocialDisciplineDesc, Lookup98.DisplayCode AS PsychoSocialType, 
    Lookup98.UserDescription AS PsychoSocialTypeDesc, Lookup99.DisplayCode AS ReadingCommunication, 
    Lookup99.UserDescription AS ReadingCommunicationDesc, Lookup100.DisplayCode AS ReAdmit1MonthSinceDisch, 
    Lookup100.UserDescription AS ReAdmit1MonthSinceDischDesc, Lookup101.DisplayCode AS ReasonforDischarge, 
    Lookup101.UserDescription AS ReasonforDischargeDesc, Lookup102.DisplayCode AS ReassessmentDiscipline, 
    Lookup102.UserDescription AS ReassessmentDisciplineDesc, Lookup103.DisplayCode AS ReassessmentType, 
    Lookup103.UserDescription AS ReassessmentTypeDesc, Lookup104.DisplayCode AS RecreationalActivities, 
    Lookup104.UserDescription AS RecreationalActivitiesDesc, Lookup105.DisplayCode AS ReferralSource, 
    Lookup105.UserDescription AS ReferralSourceDesc, Lookup106.DisplayCode AS ReferralSourceFacilityNum, 
    Lookup106.UserDescription AS ReferralSourceFacilityNumDesc, Lookup107.DisplayCode AS ReferralSourceProvTerritory, 
    Lookup107.UserDescription AS ReferralSourceProvTerrDesc, Lookup108.DisplayCode AS ReferredTo, 
    Lookup108.UserDescription AS ReferredToDesc, Lookup109.DisplayCode AS ReferredToFacilityNumber, 
    Lookup109.UserDescription AS ReferredToFacilityNumberDesc, Lookup110.DisplayCode AS ReferredToProvTerr, 
    Lookup110.UserDescription AS ReferredToProvTerrDesc, 
    -- PR - 02377
    ReferringProvider = LU_RefProvider.DisplayCode, ReferringProviderDesc = LU_RefProvider.UserDescription, 

    dbo.RH_ClientInfo.RegisterNumber, Lookup111.DisplayCode AS RehabilitationClientGroup, 
    Lookup111.UserDescription AS RehabilitationClientGroupDesc, Lookup112.DisplayCode AS Respondent, 
    Lookup112.UserDescription AS RespondentDesc, Lookup113.DisplayCode AS RespondentType, Lookup113.UserDescription AS RespondentTypeDesc, 
    LU_ResidenceCode.DisplayCode AS ResidenceCode, LU_ResidenceCode.UserDescription AS ResidenceCodeDesc, 
    Lookup114.DisplayCode AS RetiredforAge, Lookup114.UserDescription AS RetiredforAgeDesc, Lookup115.DisplayCode AS RetiredforDisability, 
    Lookup115.UserDescription AS RetiredforDisabilityDesc, 
    -- PR - 02377
    SecondChartRegNumber as SecondChartRegisterNumber,
    --ED - 02265, ED - 02266
    LU_SecondaryReasonWaiting.DisplayCode AS SecondaryReasonWaitingDischarge, LU_SecondaryReasonWaiting.UserDescription AS SecondaryReasonWaitingDischargeDesc, 

    Lookup116.DisplayCode AS ScreeningDiscipline, 
    Lookup116.UserDescription AS ScreeningDisciplineDesc, Lookup117.DisplayCode AS ScreeningType, 
    Lookup117.UserDescription AS ScreeningTypeDesc, 
    Lookup153.DisplayCode AS Secret, Lookup153.UserDescription AS SecretDesc, 
    
    Lookup118.DisplayCode AS SelfCareNeeds, Lookup118.UserDescription AS SelfCareNeedsDesc, 
    Lookup119.DisplayCode AS ServicePlanningDiscipline, Lookup119.UserDescription AS ServicePlanningDisciplineDesc, 
    Lookup120.DisplayCode AS ServicePlanningType, Lookup120.UserDescription AS ServicePlanningTypeDesc, 

    LU_Site.DisplayCode as SiteNumber, LU_Site.UserDescription as SiteNumberDesc,

    Lookup121.DisplayCode AS SocialActivities, Lookup121.UserDescription AS SocialActivitiesDesc, Lookup122.DisplayCode AS SocialInteraction, 
    Lookup122.UserDescription AS SocialInteractionDesc, Lookup123.DisplayCode AS SocialParticDiscipline, 
    Lookup123.UserDescription AS SocialParticDisciplineDesc, Lookup124.DisplayCode AS SocialParticipationType, 
    Lookup124.UserDescription AS SocialParticipationTypeDesc, 
    Lookup125.DisplayCode AS Stairs, Lookup125.UserDescription AS StairsDesc, 
    Lookup126.DisplayCode AS Status, Lookup126.UserDescription AS StatusDesc, Lookup127.DisplayCode AS StudentAdjustedModified, 
    Lookup127.UserDescription AS StudentAdjustedModifiedDesc, Lookup128.DisplayCode AS StudentFullTime, 
    Lookup128.UserDescription AS StudentFullTimeDesc, Lookup129.DisplayCode AS StudentPartTime, 
    Lookup129.UserDescription AS StudentPartTimeDesc, 
    (case when Lookup4.CIHIValue=''1'' then dbo.RH_Administrative.TherapyDate else null end) AS TherapyStartDateOptional,
    (case when Lookup4.CIHIValue=''2'' then dbo.RH_Administrative.TherapyDate else null end) AS TherapyEndDateOptional,
    --292-0012
    TherapyTimeOT as TherapyTimeOccupationalTherapist, 
    TherapyTimePT as TherapyTimePhysiotherapist, 
    TherapyTimeSLP as TherapyTimeSpeechLanguagePathologist, 
    TherapyTimeOTA as TherapyTimeOccupationalTherapistAssistant, 
    TherapyTimePTA as TherapyTimePhysiotherapistAssistant, 
    TherapyTimeCDA as TherapyTimeCommunicativeDisordersAssistant,
    
    Lookup130.DisplayCode AS Toilet, Lookup130.UserDescription AS ToiletDesc, Lookup131.DisplayCode AS Toileting, 
    Lookup131.UserDescription AS ToiletingDesc, dbo.RH_Health.WrittenConditionTrans AS TransferWrittenHealthCondtn1, 
    Lookup132.DisplayCode AS TranslTempLivingArrangemnt, Lookup132.UserDescription AS TransTempLivingArrangemntDesc, 
    
    RH_ClientInfo.TSIDate, RH_ClientInfo.TSITime, 
    Lookup152.DisplayCode as TSICoder, Lookup152.UserDescription as TSICoderDesc,
    
    Lookup133.DisplayCode AS TubShower, Lookup133.UserDescription AS TubShowerDesc, Lookup134.DisplayCode AS Unemployed, 
    Lookup134.UserDescription AS UnemployedDesc, 
	RH_ClientInfo.UniversalEpisodeIdentifier,
	Lookup135.DisplayCode AS UnpaidEmployAdjustedMod, 
    Lookup135.UserDescription AS UnpaidEmployAdjustedModDesc, Lookup136.DisplayCode AS UnpaidEmploymentFullTime, 
    Lookup136.UserDescription AS UnpaidEmploymentFullTimeDesc, Lookup137.DisplayCode AS UnpaidEmploymentPartTime, 
    Lookup137.UserDescription AS UnpaidEmploymentPartTimeDesc, Lookup138.DisplayCode AS VerbalorNonVerbal, 
    Lookup138.UserDescription AS VerbalorNonVerbalDesc, Lookup139.DisplayCode AS VocationalDiscipline, 
    Lookup139.UserDescription AS VocationalDisciplineDesc, Lookup140.DisplayCode AS VocationalType, 
    Lookup140.UserDescription AS VocationalTypeDesc, Lookup141.DisplayCode AS WalkWheelchair, 
    Lookup141.UserDescription AS WalkWheelchairDesc, Lookup142.DisplayCode AS WalkWheelchairMode, 
    Lookup142.UserDescription AS WalkWheelchairModeDesc, Lookup143.DisplayCode AS WCBWSIB, Lookup143.UserDescription AS WCBWSIBDesc, 
    dbo.RH_Health.Weight AS Weightoptional, Lookup144.DisplayCode AS WorkActivity, Lookup144.UserDescription AS WorkActivityDesc, 
    Lookup145.DisplayCode AS WrittenCommunication, Lookup145.UserDescription AS WrittenCommunicationDesc, 
    dbo.RH_ClientInfo.LinkID AS zzAssessmentLink, dbo.RH_Demographic.AbstractID AS zzRehabLink
FROM        
    dbo.RH_Demographic with (nolock) LEFT OUTER JOIN
    dbo.LU_AgeCode Lookup2 with (nolock) on dbo.RH_Demographic.AgeCode = Lookup2.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup21 with (nolock) on dbo.RH_Demographic.ResidenceCountry = Lookup21.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup31 with (nolock) on dbo.RH_Demographic.BirthDateEstimated = Lookup31.Code LEFT OUTER JOIN
    dbo.LU_Gender_I Lookup40 with (nolock) on dbo.RH_Demographic.Gender = Lookup40.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup45 with (nolock) on dbo.RH_Demographic.InformalSupport = Lookup45.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup57 with (nolock) on dbo.RH_Demographic.LivingAlone = Lookup57.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup58 with (nolock) on dbo.RH_Demographic.LivingHospital = Lookup58.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup59 with (nolock) on dbo.RH_Demographic.LivingFamily = Lookup59.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup60 with (nolock) on dbo.RH_Demographic.LivingUnPaid = Lookup60.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup61 with (nolock) on dbo.RH_Demographic.LivingPaid = Lookup61.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup62 with (nolock) on dbo.RH_Demographic.LivingSpouse = Lookup62.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup69 with (nolock) on dbo.RH_Demographic.VocationNone = Lookup69.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup74 with (nolock) on dbo.RH_Demographic.LivingOther = Lookup74.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup77 with (nolock) on dbo.RH_Demographic.PaidFullTime = Lookup77.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup78 with (nolock) on dbo.RH_Demographic.PaidPartTime = Lookup78.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup87 with (nolock) on dbo.RH_Demographic.LivingSetting = Lookup87.Code LEFT OUTER JOIN
    dbo.LU_Language Lookup90 with (nolock) on dbo.RH_Demographic.LanguageCode = Lookup90.Code LEFT OUTER JOIN
    dbo.LU_HCNProvince Lookup94 with (nolock) on dbo.RH_Demographic.Province = Lookup94.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup114 with (nolock) on dbo.RH_Demographic.RetiredAge = Lookup114.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup115 with (nolock) on dbo.RH_Demographic.RetiredDisable = Lookup115.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup127 with (nolock) on dbo.RH_Demographic.StudentAdjusted = Lookup127.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup128 with (nolock) on dbo.RH_Demographic.StudentFullTime = Lookup128.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup129 with (nolock) on dbo.RH_Demographic.StudentPartTime = Lookup129.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup132 with (nolock) on dbo.RH_Demographic.LivingTemp = Lookup132.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup134 with (nolock) on dbo.RH_Demographic.UnEmployed = Lookup134.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup135 with (nolock) on dbo.RH_Demographic.UnPaidAdjusted = Lookup135.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup136 with (nolock) on dbo.RH_Demographic.UnPaidFullTime = Lookup136.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup137 with (nolock) on dbo.RH_Demographic.UnPaidPartTime = Lookup137.Code LEFT OUTER JOIN
    dbo.LU_ResidenceCode with (nolock) on dbo.RH_Demographic.ResidenceCode = LU_ResidenceCode.Code LEFT OUTER JOIN
--ED - 01568
    dbo.LU_CodeFile LU_LivingInAcute with (nolock) on dbo.RH_Demographic.LivingAcute = LU_LivingInAcute.Code LEFT OUTER JOIN

    dbo.RH_Activity with (nolock) on dbo.RH_Demographic.AbstractID = dbo.RH_Activity.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup5 with (nolock) on dbo.RH_Activity.AuditoryCom = Lookup5.Code LEFT OUTER JOIN
    dbo.LU_FIM_Bathing Lookup7 with (nolock) on dbo.RH_Activity.Bathing = Lookup7.Code LEFT OUTER JOIN    --PR - 04305 Replace LU_CodeFile with FIM Lookup table 
    dbo.LU_FIM_Bed_Chair Lookup8 with (nolock) on dbo.RH_Activity.BedTransfer = Lookup8.Code LEFT OUTER JOIN --PR - 04305
    dbo.LU_FIM_Bladder Lookup9 with (nolock) on dbo.RH_Activity.Bladder = Lookup9.Code LEFT OUTER JOIN --PR - 04305
    dbo.LU_FIM_Bowel Lookup10 with (nolock) on dbo.RH_Activity.Bowel = Lookup10.Code LEFT OUTER JOIN --PR - 04305
    dbo.LU_FIM_Comprehension Lookup17 with (nolock) on dbo.RH_Activity.Comprehension = Lookup17.Code LEFT OUTER JOIN --PR - 04305
    dbo.LU_CodeFile Lookup18 with (nolock) on dbo.RH_Activity.ComprehensionMode = Lookup18.Code LEFT OUTER JOIN
    dbo.LU_FIM_Dress_Lower Lookup24 with (nolock) on dbo.RH_Activity.DressLower = Lookup24.Code LEFT OUTER JOIN --PR - 04305
    dbo.LU_FIM_Dress_Upper Lookup25 with (nolock) on dbo.RH_Activity.DressUpper = Lookup25.Code LEFT OUTER JOIN --PR - 04305
    dbo.LU_FIM_Eating Lookup26 with (nolock) on dbo.RH_Activity.Eating = Lookup26.Code LEFT OUTER JOIN --PR - 04305
    dbo.LU_FIM_Expression Lookup32 with (nolock) on dbo.RH_Activity.Expression = Lookup32.Code LEFT OUTER JOIN --PR - 04305
    dbo.LU_CodeFile Lookup33 with (nolock) on dbo.RH_Activity.ExpressionMode = Lookup33.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup39 with (nolock) on dbo.RH_Activity.FinanceManage = Lookup39.Code LEFT OUTER JOIN
    dbo.LU_FIM_Grooming Lookup41 with (nolock) on dbo.RH_Activity.Grooming = Lookup41.Code LEFT OUTER JOIN --PR - 04305
    dbo.LU_CodeFile Lookup42 with (nolock) on dbo.RH_Activity.HouseworkHeavy = Lookup42.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup44 with (nolock) on dbo.RH_Activity.PainImpact = Lookup44.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup50 with (nolock) on dbo.RH_Activity.PainIntensity = Lookup50.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup56 with (nolock) on dbo.RH_Activity.HouseworkLight = Lookup56.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup65 with (nolock) on dbo.RH_Activity.MealPreparation = Lookup65.Code LEFT OUTER JOIN
    dbo.LU_FIM_Memory Lookup66 with (nolock) on dbo.RH_Activity.Memory = Lookup66.Code LEFT OUTER JOIN --PR - 04305
    dbo.LU_CodeFile Lookup72 with (nolock) on dbo.RH_Activity.Orientation = Lookup72.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup88 with (nolock) on dbo.RH_Activity.ImpairmentPresence = Lookup88.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup89 with (nolock) on dbo.RH_Activity.PainPresence = Lookup89.Code LEFT OUTER JOIN
    dbo.LU_FIM_ProblemSolve Lookup91 with (nolock) on dbo.RH_Activity.ProblemSolve = Lookup91.Code LEFT OUTER JOIN --PR - 04305
    dbo.LU_CodeFile Lookup99 with (nolock) on dbo.RH_Activity.ReadingCom = Lookup99.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup112 with (nolock) on dbo.RH_Activity.HealthStatRespondent = Lookup112.Code LEFT OUTER JOIN 
    dbo.LU_FIM_Social Lookup122 with (nolock) on dbo.RH_Activity.SocialInteract = Lookup122.Code LEFT OUTER JOIN --PR - 04305
    dbo.LU_FIM_Stairs Lookup125 with (nolock) on dbo.RH_Activity.Stairs = Lookup125.Code LEFT OUTER JOIN --PR - 04305
    dbo.LU_CodeFile Lookup126 with (nolock) on dbo.RH_Activity.HealthStatus = Lookup126.Code LEFT OUTER JOIN --PR - 04305
    dbo.LU_FIM_TransToilet Lookup130 with (nolock) on dbo.RH_Activity.ToiletTransfer = Lookup130.Code LEFT OUTER JOIN --PR - 04305
    dbo.LU_FIM_Toilet Lookup131 with (nolock) on dbo.RH_Activity.Toileting = Lookup131.Code LEFT OUTER JOIN --PR - 04305
    dbo.LU_FIM_TransTub Lookup133 with (nolock) on dbo.RH_Activity.ShowerTransfer = Lookup133.Code LEFT OUTER JOIN --PR - 04305
    dbo.LU_CodeFile Lookup138 with (nolock) on dbo.RH_Activity.VerbalCom = Lookup138.Code LEFT OUTER JOIN
    dbo.LU_FIM_Walk_Wheel Lookup141 with (nolock) on dbo.RH_Activity.Walk = Lookup141.Code LEFT OUTER JOIN --PR - 04305
    dbo.LU_CodeFile Lookup142 with (nolock) on dbo.RH_Activity.WalkMode = Lookup142.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup145 with (nolock) on dbo.RH_Activity.WrittenCom = Lookup145.Code LEFT OUTER JOIN
    --PR - 04300
    --ED - 01568
    --dbo.LU_YesNoSystem LU_GlassHear with (nolock) on dbo.RH_Activity.GlassHear = LU_GlassHear.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_GlassHear with (nolock) on dbo.RH_Activity.GlassHear = LU_GlassHear.Code LEFT OUTER JOIN

    dbo.RH_Administrative with (nolock) on dbo.RH_Demographic.AbstractID = dbo.RH_Administrative.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup1 with (nolock) on dbo.RH_Administrative.AdmitClass = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup11 with (nolock) on dbo.RH_Administrative.RP_CanadaInsure = Lookup11.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup12 with (nolock) on dbo.RH_Administrative.RP_CanadaSelf = Lookup12.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup22 with (nolock) on dbo.RH_Administrative.ReadyAdmitKnown = Lookup22.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup36 with (nolock) on dbo.RH_Administrative.RP_Fed_DVA = Lookup36.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup37 with (nolock) on dbo.RH_Administrative.RP_Fed_FNIHB = Lookup37.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup38 with (nolock) on dbo.RH_Administrative.RP_Fed_Other = Lookup38.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup73 with (nolock) on dbo.RH_Administrative.RP_OtherSelf = Lookup73.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup75 with (nolock) on dbo.RH_Administrative.RP_OtherProvince = Lookup75.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup85 with (nolock) on dbo.RH_Administrative.PlanReAdmit = Lookup85.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup95 with (nolock) on dbo.RH_Administrative.RP_ProvincePlan = Lookup95.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup96 with (nolock) on dbo.RH_Administrative.RP_ProvinceDefinition = Lookup96.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup100 with (nolock) on dbo.RH_Administrative.ReAdmit = Lookup100.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup101 with (nolock) on dbo.RH_Administrative.DischReason = Lookup101.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup105 with (nolock) on dbo.RH_Administrative.ReferredFrom = Lookup105.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 Lookup106 with (nolock) on dbo.RH_Administrative.InstitutionFrom = Lookup106.Code LEFT OUTER JOIN
    dbo.LU_HCNProvince Lookup107 with (nolock) on dbo.RH_Administrative.ReferralProvince = Lookup107.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup108 with (nolock) on dbo.RH_Administrative.ReferredTo = Lookup108.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 Lookup109 with (nolock) on dbo.RH_Administrative.InstitutionTo = Lookup109.Code LEFT OUTER JOIN
    dbo.LU_HCNProvince Lookup110 with (nolock) on dbo.RH_Administrative.ReferredProvince = Lookup110.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup143 with (nolock) on dbo.RH_Administrative.RP_WCB_WSIB = Lookup143.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_PrimaryReasonWaiting with (nolock) on dbo.RH_Administrative.PrimaryReasonWaiting = LU_PrimaryReasonWaiting.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_SecondaryReasonWaiting with (nolock) on dbo.RH_Administrative.SecondaryReasonWaiting = LU_SecondaryReasonWaiting.Code LEFT OUTER JOIN
    dbo.RH_ClientInfo with (nolock) on dbo.RH_ClientInfo.AbstractID = dbo.RH_Demographic.AbstractID LEFT OUTER JOIN
    dbo.U_Users with (nolock) on dbo.U_Users.Code = dbo.RH_ClientInfo.CoderNumber LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup4 with (nolock) on dbo.RH_ClientInfo.AssessmentType = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup6 with (nolock) on dbo.RH_ClientInfo.BatchPeriod = Lookup6.Code LEFT OUTER JOIN
    dbo.H_InstitutionProfile Lookup34 with (nolock) on dbo.RH_ClientInfo.InstitutionNumber = Lookup34.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus Lookup51 with (nolock) on dbo.RH_ClientInfo.IsCompleted = Lookup51.Code LEFT OUTER JOIN
    dbo.LU_CIHICorrect Lookup52 with (nolock) on dbo.RH_ClientInfo.IsCorrected = Lookup52.Code LEFT OUTER JOIN
    dbo.LU_DeleteStatus Lookup53 with (nolock) on dbo.RH_ClientInfo.IsDeleted = Lookup53.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem Lookup54 with (nolock) on dbo.RH_ClientInfo.IsSubmited = Lookup54.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus Lookup55 with (nolock) on dbo.RH_ClientInfo.IsValidated = Lookup55.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup92 with (nolock) on dbo.RH_ClientInfo.ProgramType = Lookup92.Code LEFT OUTER JOIN
    dbo.LU_HCNProvince Lookup93 with (nolock) on dbo.RH_ClientInfo.HCNProvince = Lookup93.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup113 with (nolock) on dbo.RH_ClientInfo.RespondentType = Lookup113.Code LEFT OUTER JOIN
    dbo.RH_FollowUpAssess with (nolock) on dbo.RH_Demographic.AbstractID = dbo.RH_FollowUpAssess.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup23 with (nolock) on dbo.RH_FollowUpAssess.LifeEvents = Lookup23.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup35 with (nolock) on dbo.RH_FollowUpAssess.FamilyRole = Lookup35.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup67 with (nolock) on dbo.RH_FollowUpAssess.Community = Lookup67.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup68 with (nolock) on dbo.RH_FollowUpAssess.LivingQuarters = Lookup68.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup76 with (nolock) on dbo.RH_FollowUpAssess.TownTrips = Lookup76.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup79 with (nolock) on dbo.RH_FollowUpAssess.PersonalComfort = Lookup79.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup80 with (nolock) on dbo.RH_FollowUpAssess.PersonalRelation = Lookup80.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup104 with (nolock) on dbo.RH_FollowUpAssess.Recreational = Lookup104.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup118 with (nolock) on dbo.RH_FollowUpAssess.SelfCare = Lookup118.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup121 with (nolock) on dbo.RH_FollowUpAssess.SocialActivity = Lookup121.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup144 with (nolock) on dbo.RH_FollowUpAssess.WorkActivity = Lookup144.Code LEFT OUTER JOIN
    dbo.RH_Rehabilitation with (nolock) on dbo.RH_Demographic.AbstractID = dbo.RH_Rehabilitation.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup13 with (nolock) on dbo.RH_Rehabilitation.SD_Cognitive = Lookup13.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup14 with (nolock) on dbo.RH_Rehabilitation.ST_Cognitive = Lookup14.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup15 with (nolock) on dbo.RH_Rehabilitation.SD_Communicate = Lookup15.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup16 with (nolock) on dbo.RH_Rehabilitation.ST_Communicate = Lookup16.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup19 with (nolock) on dbo.RH_Rehabilitation.SD_Consultation = Lookup19.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup20 with (nolock) on dbo.RH_Rehabilitation.ST_Consultation = Lookup20.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup27 with (nolock) on dbo.RH_Rehabilitation.SD_Education = Lookup27.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup28 with (nolock) on dbo.RH_Rehabilitation.ST_Education = Lookup28.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup29 with (nolock) on dbo.RH_Rehabilitation.SD_Equipment = Lookup29.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup30 with (nolock) on dbo.RH_Rehabilitation.ST_Equipment = Lookup30.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup46 with (nolock) on dbo.RH_Rehabilitation.SD_Initial = Lookup46.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup47 with (nolock) on dbo.RH_Rehabilitation.ST_Initial = Lookup47.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup48 with (nolock) on dbo.RH_Rehabilitation.SD_Injections = Lookup48.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup49 with (nolock) on dbo.RH_Rehabilitation.ST_Injections = Lookup49.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup63 with (nolock) on dbo.RH_Rehabilitation.SD_Manual = Lookup63.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup64 with (nolock) on dbo.RH_Rehabilitation.ST_Manual = Lookup64.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup70 with (nolock) on dbo.RH_Rehabilitation.SD_Nutrition = Lookup70.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup71 with (nolock) on dbo.RH_Rehabilitation.ST_Nutrition = Lookup71.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup81 with (nolock) on dbo.RH_Rehabilitation.SD_Physical = Lookup81.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup82 with (nolock) on dbo.RH_Rehabilitation.SD_Modalities = Lookup82.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup83 with (nolock) on dbo.RH_Rehabilitation.ST_Modalities = Lookup83.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup84 with (nolock) on dbo.RH_Rehabilitation.ST_Physical = Lookup84.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup97 with (nolock) on dbo.RH_Rehabilitation.SD_PsychoSocial = Lookup97.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup98 with (nolock) on dbo.RH_Rehabilitation.ST_PsychoSocial = Lookup98.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup102 with (nolock) on dbo.RH_Rehabilitation.SD_ReAssess = Lookup102.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup103 with (nolock) on dbo.RH_Rehabilitation.ST_ReAssess = Lookup103.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup116 with (nolock) on dbo.RH_Rehabilitation.SD_Screening = Lookup116.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup117 with (nolock) on dbo.RH_Rehabilitation.ST_Screening = Lookup117.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup119 with (nolock) on dbo.RH_Rehabilitation.SD_Planning = Lookup119.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup120 with (nolock) on dbo.RH_Rehabilitation.ST_Planning = Lookup120.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup123 with (nolock) on dbo.RH_Rehabilitation.SD_Social = Lookup123.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup124 with (nolock) on dbo.RH_Rehabilitation.ST_Social = Lookup124.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup139 with (nolock) on dbo.RH_Rehabilitation.SD_Vocational = Lookup139.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup140 with (nolock) on dbo.RH_Rehabilitation.ST_Vocational = Lookup140.Code LEFT OUTER JOIN
    dbo.RH_Health with (nolock) on dbo.RH_Demographic.AbstractID = dbo.RH_Health.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup3 with (nolock) on dbo.RH_Health.ASIAScale = Lookup3.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup43 with (nolock) on dbo.RH_Health.HospDischarge = Lookup43.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup111 with (nolock) on dbo.RH_Health.ClientGroup = Lookup111.Code LEFT OUTER JOIN
    dbo.U_Users Lookup150 with (nolock) on dbo.RH_ClientInfo.InterfaceCoder = Lookup150.Code LEFT OUTER JOIN
    dbo.U_Users Lookup151 with (nolock) on dbo.RH_ClientInfo.DataEntryCoder = Lookup151.Code LEFT OUTER JOIN
    dbo.U_Users Lookup152 with (nolock) on dbo.RH_ClientInfo.TSICoder = Lookup152.Code LEFT OUTER JOIN
    dbo.LU_YesBlank Lookup153 with (nolock) on dbo.RH_ClientInfo.Secret = Lookup153.Code LEFT OUTER JOIN
    dbo.H_HospitalProfile LU_Hospital with (nolock) on dbo.RH_ClientInfo.HospitalID = LU_Hospital.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LUPaidAdjusted with (nolock) on dbo.RH_Demographic.PaidAdjusted = LUPaidAdjusted.Code LEFT OUTER JOIN
    dbo.LU_Site LU_Site with (nolock) on dbo.RH_ClientInfo.SiteNumber = LU_Site.Code LEFT OUTER JOIN
--PR - 02377
    LU_Provider LU_AttProvider with (nolock) on dbo.RH_ClientInfo.AttendingPhysician = LU_AttProvider.Code LEFT JOIN
    LU_Provider LU_RefProvider with (nolock) on dbo.RH_ClientInfo.RefPhysician = LU_RefProvider.Code LEFT JOIN
    LU_MisCode LU_MisCode with (nolock) on dbo.RH_ClientInfo.MISCode = LU_MisCode.Code LEFT JOIN
    LU_NurseArea LU_AdmitNurse with (nolock) on dbo.RH_ClientInfo.AdmittingNurseArea = LU_AdmitNurse.Code LEFT JOIN
--PR - 03270
    dbo.RH_BasicOption with (nolock) on dbo.RH_ClientInfo.AbstractID = dbo.RH_BasicOption.AbstractID LEFT JOIN
    dbo.LU_BasicOption1  with (nolock) on dbo.RH_BasicOption.BasicOption1  = dbo.LU_BasicOption1.Code LEFT JOIN
    dbo.LU_BasicOption2  with (nolock) on dbo.RH_BasicOption.BasicOption2  = dbo.LU_BasicOption2.Code LEFT JOIN
    dbo.LU_BasicOption3  with (nolock) on dbo.RH_BasicOption.BasicOption3  = dbo.LU_BasicOption3.Code LEFT JOIN
    dbo.LU_BasicOption4  with (nolock) on dbo.RH_BasicOption.BasicOption4  = dbo.LU_BasicOption4.Code LEFT JOIN
    dbo.LU_BasicOption5  with (nolock) on dbo.RH_BasicOption.BasicOption5  = dbo.LU_BasicOption5.Code LEFT JOIN
    dbo.LU_BasicOption6  with (nolock) on dbo.RH_BasicOption.BasicOption6  = dbo.LU_BasicOption6.Code LEFT JOIN
    dbo.LU_BasicOption7  with (nolock) on dbo.RH_BasicOption.BasicOption7  = dbo.LU_BasicOption7.Code LEFT JOIN
    dbo.LU_BasicOption8  with (nolock) on dbo.RH_BasicOption.BasicOption8  = dbo.LU_BasicOption8.Code LEFT JOIN
    dbo.LU_BasicOption9  with (nolock) on dbo.RH_BasicOption.BasicOption9  = dbo.LU_BasicOption9.Code LEFT JOIN
    dbo.LU_BasicOption10 with (nolock) on dbo.RH_BasicOption.BasicOption10 = dbo.LU_BasicOption10.Code LEFT JOIN
    dbo.LU_BasicOption11 with (nolock) on dbo.RH_BasicOption.BasicOption11 = dbo.LU_BasicOption11.Code LEFT JOIN
    dbo.LU_BasicOption12 with (nolock) on dbo.RH_BasicOption.BasicOption12 = dbo.LU_BasicOption12.Code LEFT JOIN
    dbo.LU_BasicOption13 with (nolock) on dbo.RH_BasicOption.BasicOption13 = dbo.LU_BasicOption13.Code LEFT JOIN
    dbo.LU_BasicOption14 with (nolock) on dbo.RH_BasicOption.BasicOption14 = dbo.LU_BasicOption14.Code LEFT JOIN
    dbo.LU_BasicOption15 with (nolock) on dbo.RH_BasicOption.BasicOption15 = dbo.LU_BasicOption15.Code LEFT JOIN
    dbo.LU_BasicOption16 with (nolock) on dbo.RH_BasicOption.BasicOption16 = dbo.LU_BasicOption16.Code LEFT JOIN
    dbo.LU_BasicOption17 with (nolock) on dbo.RH_BasicOption.BasicOption17 = dbo.LU_BasicOption17.Code LEFT JOIN
    dbo.LU_BasicOption18 with (nolock) on dbo.RH_BasicOption.BasicOption18 = dbo.LU_BasicOption18.Code LEFT JOIN
    dbo.LU_BasicOption19 with (nolock) on dbo.RH_BasicOption.BasicOption19 = dbo.LU_BasicOption19.Code LEFT JOIN
--ED - 01602
    dbo.LU_CodeFile LU_LanguageISO with (nolock) on dbo.RH_Demographic.LanguageISO = LU_LanguageISO.Code LEFT JOIN
--ED - 01911
    dbo.LU_CodeFile LU_AboriginalStatus with (nolock) on dbo.RH_Demographic.AboriginalStatus = LU_AboriginalStatus.Code LEFT JOIN
    
    --292-0012
    dbo.RH_Therapy on dbo.RH_Therapy.AbstractID = dbo.RH_ClientInfo.AbstractID
    
--QA - 00032 disable the domain securite issue
----PR - 07485    
--where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or RH_ClientInfo.HospitalID is null or RH_ClientInfo.HospitalID = 0
----EN - 00666
--    or Is_Member(nullif(ReportGroup, '''')) = 1
----    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(RH_ClientInfo.HospitalID, 0))




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[RehabAdmission_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[RehabAdmission_VR]
AS
SELECT  
    Lookup1.DisplayCode AS AdmissionClass, Lookup1.UserDescription AS AdmissionClassDesc, 
    dbo.RH_ClientInfo.AdmitDate AS AdmissionDate, 
    Lookup4.DisplayCode AS AssessmentType, Lookup4.UserDescription AS AssessmentTypeDesc, 
    Lookup5.DisplayCode AS AuditoryOrNonAuditoryComm, Lookup5.UserDescription AS AuditoryOrNonAuditoryCommDesc, 
    dbo.RH_Health.DateOnset AS DateofOnset, 
    dbo.RH_Administrative.ReadyAdmitDate AS DateReadyForAdmission, 
    Lookup22.DisplayCode AS DateReadyForAdmitKnown, Lookup22.UserDescription AS DateReadyForAdmitKnownDesc, 
    (case when Lookup4.CIHIValue in (''2'', ''3'') or (Lookup4.CIHIValue = ''1'' and Lookup1.CIHIValue = ''4'') then dbo.RH_ClientInfo.DischargeDate else null end) as DischargeDate, 
    Lookup39.DisplayCode AS FinancialManagement, Lookup39.UserDescription AS FinancialManagementDesc, 
    LU_GlassHear.DisplayCode as GlassesHearingAidFlag, LU_GlassHear.UserDescription as GlassesHearingAidFlagDesc, 
    Lookup42.DisplayCode AS HeavyHouseworkoptional, Lookup42.UserDescription AS HeavyHouseworkoptionalDesc, 
    dbo.RH_Health.Height AS Height,
    Lookup44.DisplayCode AS ImpactofPainOnActivities, Lookup44.UserDescription AS ImpactofPainOnActivitiesDesc, 
    Lookup45.DisplayCode AS InformalSupportReceived, Lookup45.UserDescription AS InformalSupportReceivedDesc, 
    Lookup50.DisplayCode AS IntensityOfPain, Lookup50.UserDescription AS IntensityOfPainDesc, 
    Lookup56.DisplayCode AS LightHouseworkoptional, Lookup56.UserDescription AS LightHouseworkoptionalDesc, 
    Lookup57.DisplayCode AS LivingAlone, Lookup57.UserDescription AS LivingAloneDesc, 
    LU_LivingInAcute.DisplayCode as LivingInAcuteCare, LU_LivingInAcute.UserDescription as LivingInAcuteCareDesc, 
    Lookup58.DisplayCode AS LivingInFacilityAllLevels, Lookup58.UserDescription AS LivingInFacilityAllLevelsDesc, 
    Lookup59.DisplayCode AS LivingwithFamily, Lookup59.UserDescription AS LivingwithFamilyDesc, 
    Lookup60.DisplayCode AS LivingwithNonFamilyUnpaid, Lookup60.UserDescription AS LivingwithNonFamilyUnpaidDesc, 
    Lookup61.DisplayCode AS LivingwithPaidAttendant, Lookup61.UserDescription AS LivingwithPaidAttendantDesc, 
    Lookup62.DisplayCode AS LivingwithSpousePartner, Lookup62.UserDescription AS LivingwithSpousePartnerDesc, 
    Lookup65.DisplayCode AS MealPreparationoptional, Lookup65.UserDescription AS MealPreparationoptionalDesc, 
    Lookup69.DisplayCode AS NoneoftheAbove, Lookup69.UserDescription AS NoneoftheAboveDesc, 
    Lookup72.DisplayCode AS Orientation, Lookup72.UserDescription AS OrientationDesc, 
    Lookup74.DisplayCode AS OtherLivingArrangements, Lookup74.UserDescription AS OtherLivingArrangementsDesc, 
    LUPaidAdjusted.DisplayCode as PaidEmployAdjustedMod, LUPaidAdjusted.UserDescription as PaidEmployAdjustedModDesc, 
    Lookup77.DisplayCode AS PaidEmploymentFullTime, Lookup77.UserDescription AS PaidEmploymentFullTimeDesc, 
    Lookup78.DisplayCode AS PaidEmploymentPartTime, Lookup78.UserDescription AS PaidEmploymentPartTimeDesc, 
    Lookup85.DisplayCode AS PlannedReAdmission, Lookup85.UserDescription AS PlannedReAdmissionDesc, 
    Lookup87.DisplayCode AS PreHospitalLivingSetting, Lookup87.UserDescription AS PreHospitalLivingSettingDesc, 
    Lookup88.DisplayCode AS PresenceofCognitiveImpair, Lookup88.UserDescription AS PresenceofCognitiveImpairDesc, 
    Lookup89.DisplayCode AS PresenceofPain, Lookup89.UserDescription AS PresenceofPainDesc, 
    Lookup99.DisplayCode AS ReadingCommunication, Lookup99.UserDescription AS ReadingCommunicationDesc, 
    Lookup100.DisplayCode AS ReAdmit1MonthSinceDisch, Lookup100.UserDescription AS ReAdmit1MonthSinceDischDesc, 
    Lookup105.DisplayCode AS ReferralSource, Lookup105.UserDescription AS ReferralSourceDesc, 
    Lookup106.DisplayCode AS ReferralSourceFacilityNum, Lookup106.UserDescription AS ReferralSourceFacilityNumDesc, 
    Lookup107.DisplayCode AS ReferralSourceProvTerritory, Lookup107.UserDescription AS ReferralSourceProvTerrDesc, 
    Lookup111.DisplayCode AS RehabilitationClientGroup, Lookup111.UserDescription AS RehabilitationClientGroupDesc, 
    Lookup112.DisplayCode AS Respondent, Lookup112.UserDescription AS RespondentDesc, 
    Lookup114.DisplayCode AS RetiredforAge, Lookup114.UserDescription AS RetiredforAgeDesc, 
    Lookup115.DisplayCode AS RetiredforDisability, Lookup115.UserDescription AS RetiredforDisabilityDesc, 
    Lookup126.DisplayCode AS Status, Lookup126.UserDescription AS StatusDesc, 
    Lookup127.DisplayCode AS StudentAdjustedModified, Lookup127.UserDescription AS StudentAdjustedModifiedDesc, 
    Lookup128.DisplayCode AS StudentFullTime, Lookup128.UserDescription AS StudentFullTimeDesc, 
    Lookup129.DisplayCode AS StudentPartTime, Lookup129.UserDescription AS StudentPartTimeDesc, 
    Lookup134.DisplayCode AS Unemployed, Lookup134.UserDescription AS UnemployedDesc, 
    Lookup135.DisplayCode AS UnpaidEmployAdjustedMod, Lookup135.UserDescription AS UnpaidEmployAdjustedModDesc, 
    Lookup136.DisplayCode AS UnpaidEmploymentFullTime, Lookup136.UserDescription AS UnpaidEmploymentFullTimeDesc, 
    Lookup137.DisplayCode AS UnpaidEmploymentPartTime, Lookup137.UserDescription AS UnpaidEmploymentPartTimeDesc, 
    Lookup138.DisplayCode AS VerbalorNonVerbal, Lookup138.UserDescription AS VerbalorNonVerbalDesc, 
    dbo.RH_Health.Weight AS Weight,
    Lookup145.DisplayCode AS WrittenCommunication, Lookup145.UserDescription AS WrittenCommunicationDesc, 
    dbo.RH_ClientInfo.LinkID AS zzAssessmentLink, dbo.RH_Demographic.AbstractID AS zzRehabLink
FROM        
 dbo.RH_ClientInfo with (nolock) LEFT OUTER JOIN
    dbo.RH_Demographic with (nolock) on dbo.RH_ClientInfo.AbstractID = dbo.RH_Demographic.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup45 with (nolock) on dbo.RH_Demographic.InformalSupport = Lookup45.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup57 with (nolock) on dbo.RH_Demographic.LivingAlone = Lookup57.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup58 with (nolock) on dbo.RH_Demographic.LivingHospital = Lookup58.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup59 with (nolock) on dbo.RH_Demographic.LivingFamily = Lookup59.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup60 with (nolock) on dbo.RH_Demographic.LivingUnPaid = Lookup60.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup61 with (nolock) on dbo.RH_Demographic.LivingPaid = Lookup61.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup62 with (nolock) on dbo.RH_Demographic.LivingSpouse = Lookup62.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup69 with (nolock) on dbo.RH_Demographic.VocationNone = Lookup69.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup74 with (nolock) on dbo.RH_Demographic.LivingOther = Lookup74.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup77 with (nolock) on dbo.RH_Demographic.PaidFullTime = Lookup77.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup78 with (nolock) on dbo.RH_Demographic.PaidPartTime = Lookup78.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup87 with (nolock) on dbo.RH_Demographic.LivingSetting = Lookup87.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup114 with (nolock) on dbo.RH_Demographic.RetiredAge = Lookup114.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup115 with (nolock) on dbo.RH_Demographic.RetiredDisable = Lookup115.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup127 with (nolock) on dbo.RH_Demographic.StudentAdjusted = Lookup127.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup128 with (nolock) on dbo.RH_Demographic.StudentFullTime = Lookup128.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup129 with (nolock) on dbo.RH_Demographic.StudentPartTime = Lookup129.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup134 with (nolock) on dbo.RH_Demographic.UnEmployed = Lookup134.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup135 with (nolock) on dbo.RH_Demographic.UnPaidAdjusted = Lookup135.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup136 with (nolock) on dbo.RH_Demographic.UnPaidFullTime = Lookup136.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup137 with (nolock) on dbo.RH_Demographic.UnPaidPartTime = Lookup137.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_LivingInAcute with (nolock) on dbo.RH_Demographic.LivingAcute = LU_LivingInAcute.Code LEFT OUTER JOIN

    dbo.RH_Activity with (nolock) on dbo.RH_Demographic.AbstractID = dbo.RH_Activity.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup5 with (nolock) on dbo.RH_Activity.AuditoryCom = Lookup5.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup39 with (nolock) on dbo.RH_Activity.FinanceManage = Lookup39.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup42 with (nolock) on dbo.RH_Activity.HouseworkHeavy = Lookup42.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup44 with (nolock) on dbo.RH_Activity.PainImpact = Lookup44.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup50 with (nolock) on dbo.RH_Activity.PainIntensity = Lookup50.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup56 with (nolock) on dbo.RH_Activity.HouseworkLight = Lookup56.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup65 with (nolock) on dbo.RH_Activity.MealPreparation = Lookup65.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup72 with (nolock) on dbo.RH_Activity.Orientation = Lookup72.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup88 with (nolock) on dbo.RH_Activity.ImpairmentPresence = Lookup88.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup89 with (nolock) on dbo.RH_Activity.PainPresence = Lookup89.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup99 with (nolock) on dbo.RH_Activity.ReadingCom = Lookup99.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup112 with (nolock) on dbo.RH_Activity.HealthStatRespondent = Lookup112.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup126 with (nolock) on dbo.RH_Activity.HealthStatus = Lookup126.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup138 with (nolock) on dbo.RH_Activity.VerbalCom = Lookup138.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup145 with (nolock) on dbo.RH_Activity.WrittenCom = Lookup145.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem LU_GlassHear with (nolock) on dbo.RH_Activity.GlassHear = LU_GlassHear.Code LEFT OUTER JOIN

    dbo.RH_Administrative with (nolock) on dbo.RH_Demographic.AbstractID = dbo.RH_Administrative.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup1 with (nolock) on dbo.RH_Administrative.AdmitClass = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup22 with (nolock) on dbo.RH_Administrative.ReadyAdmitKnown = Lookup22.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup85 with (nolock) on dbo.RH_Administrative.PlanReAdmit = Lookup85.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup100 with (nolock) on dbo.RH_Administrative.ReAdmit = Lookup100.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup105 with (nolock) on dbo.RH_Administrative.ReferredFrom = Lookup105.Code LEFT OUTER JOIN
    dbo.LU_Institution_10 Lookup106 with (nolock) on dbo.RH_Administrative.InstitutionFrom = Lookup106.Code LEFT OUTER JOIN
    dbo.LU_HCNProvince Lookup107 with (nolock) on dbo.RH_Administrative.ReferralProvince = Lookup107.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup4 with (nolock) on dbo.RH_ClientInfo.AssessmentType = Lookup4.Code LEFT OUTER JOIN

    dbo.RH_Health with (nolock) on dbo.RH_Demographic.AbstractID = dbo.RH_Health.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup111 with (nolock) on dbo.RH_Health.ClientGroup = Lookup111.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LUPaidAdjusted with (nolock) on dbo.RH_Demographic.PaidAdjusted = LUPaidAdjusted.Code LEFT OUTER JOIN
    dbo.H_HospitalProfile with (nolock) on dbo.RH_ClientInfo.HospitalID = H_HospitalProfile.Code 
Where  dbo.RH_ClientInfo.AssessmentType = 134
--PR - 07485
    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or RH_ClientInfo.HospitalID is null or RH_ClientInfo.HospitalID = 0
    --EN - 00666
        or Is_Member(nullif(ReportGroup, '''')) = 1)
--        or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(RH_ClientInfo.HospitalID, 0))
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[RehabAdmissionFIM_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[RehabAdmissionFIM_VR]
AS
SELECT 
    dbo.RH_ClientInfo.AdmitDate AS AdmissionDate,
    Lookup4.DisplayCode AS AssessmentType, Lookup4.UserDescription AS AssessmentTypeDesc, 
    Lookup7.DisplayCode AS Bathing,    Lookup7.UserDescription AS BathingDesc, 
    Lookup8.DisplayCode AS BedChairWheelchair, Lookup8.UserDescription AS BedChairWheelchairDesc, 
    Lookup9.DisplayCode AS BladderManagement, Lookup9.UserDescription AS BladderManagementDesc, 
    Lookup10.DisplayCode AS BowelManagement, Lookup10.UserDescription AS BowelManagementDesc, 
    Lookup17.DisplayCode AS Comprehension,     Lookup17.UserDescription AS ComprehensionDesc, 
    Lookup18.DisplayCode AS ComprehensionMode,     Lookup18.UserDescription AS ComprehensionModeDesc, 
    
    Lookup24.DisplayCode AS DressingLowerBody, Lookup24.UserDescription AS DressingLowerBodyDesc, 
    Lookup25.DisplayCode AS DressingUpperBody, Lookup25.UserDescription AS DressingUpperBodyDesc, 
    Lookup26.DisplayCode AS Eating,     Lookup26.UserDescription AS EatingDesc, 
    Lookup32.DisplayCode AS Expression, Lookup32.UserDescription AS ExpressionDesc, 
    Lookup33.DisplayCode AS ExpressionMode, Lookup33.UserDescription AS ExpressionModeDesc, 
    --Begin Calculate FIM
    CAST(ISNULL(Lookup26.DisplayCode, ''0'') AS int) + CAST(ISNULL(Lookup41.DisplayCode, ''0'') AS int) + 
    CAST(ISNULL(Lookup7.DisplayCode, ''0'') AS int) + CAST(ISNULL(Lookup24.DisplayCode, ''0'') AS int) + 
    CAST(ISNULL(Lookup25.DisplayCode, ''0'') AS int) + CAST(ISNULL(Lookup131.DisplayCode, ''0'') AS int) + 
    CAST(ISNULL(Lookup9.DisplayCode, ''0'') AS int) + CAST(ISNULL(Lookup10.DisplayCode, ''0'') AS int) + 
    CAST(ISNULL(Lookup8.DisplayCode, ''0'') AS int) + CAST(ISNULL(Lookup130.DisplayCode, ''0'') AS int) +
    CAST(ISNULL(Lookup133.DisplayCode, ''0'') AS int) + CAST(ISNULL(Lookup141.DisplayCode, ''0'') AS int) + 
    CAST(ISNULL(Lookup125.DisplayCode, ''0'') AS int) + CAST(ISNULL(Lookup17.DisplayCode, ''0'') AS int) + 
    CAST(ISNULL(Lookup32.DisplayCode, ''0'') AS int) + CAST(ISNULL(Lookup122.DisplayCode, ''0'') AS int) + 
    CAST(ISNULL(Lookup91.DisplayCode, ''0'') AS int) + CAST(ISNULL(Lookup66.DisplayCode, ''0'') AS int) AS FIM, 
    --End Calculate FIM
    Lookup41.DisplayCode AS Grooming, Lookup41.UserDescription AS GroomingDesc, 
    
    Lookup66.DisplayCode AS Memory, Lookup66.UserDescription AS MemoryDesc, 
    Lookup91.DisplayCode AS ProblemSolving, Lookup91.UserDescription AS ProblemSolvingDesc, 
    Lookup122.DisplayCode AS SocialInteraction,     Lookup122.UserDescription AS SocialInteractionDesc, 
    Lookup125.DisplayCode AS Stairs, Lookup125.UserDescription AS StairsDesc, 
    Lookup130.DisplayCode AS Toilet, Lookup130.UserDescription AS ToiletDesc, 
    Lookup131.DisplayCode AS Toileting,     Lookup131.UserDescription AS ToiletingDesc, 
    
    Lookup133.DisplayCode AS TubShower, Lookup133.UserDescription AS TubShowerDesc, 
    Lookup141.DisplayCode AS WalkWheelchair,     Lookup141.UserDescription AS WalkWheelchairDesc, 
    Lookup142.DisplayCode AS WalkWheelchairMode,    Lookup142.UserDescription AS WalkWheelchairModeDesc, 
    dbo.RH_ClientInfo.LinkID AS zzAssessmentLink, dbo.RH_ClientInfo.AbstractID AS zzRehabLink
FROM
    dbo.RH_ClientInfo with (nolock) LEFT OUTER JOIN
    dbo.RH_Activity with (nolock) on dbo.RH_ClientInfo.AbstractID = dbo.RH_Activity.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup4 with (nolock) on dbo.RH_ClientInfo.AssessmentType = Lookup4.Code LEFT OUTER JOIN
    
    dbo.LU_FIM_Bathing Lookup7 with (nolock) on dbo.RH_Activity.Bathing = Lookup7.Code LEFT OUTER JOIN 
    dbo.LU_FIM_Bed_Chair Lookup8 with (nolock) on dbo.RH_Activity.BedTransfer = Lookup8.Code LEFT OUTER JOIN
    dbo.LU_FIM_Bladder Lookup9 with (nolock) on dbo.RH_Activity.Bladder = Lookup9.Code LEFT OUTER JOIN
    dbo.LU_FIM_Bowel Lookup10 with (nolock) on dbo.RH_Activity.Bowel = Lookup10.Code LEFT OUTER JOIN
    dbo.LU_FIM_Comprehension Lookup17 with (nolock) on dbo.RH_Activity.Comprehension = Lookup17.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup18 with (nolock) on dbo.RH_Activity.ComprehensionMode = Lookup18.Code LEFT OUTER JOIN
    dbo.LU_FIM_Dress_Lower Lookup24 with (nolock) on dbo.RH_Activity.DressLower = Lookup24.Code LEFT OUTER JOIN
    dbo.LU_FIM_Dress_Upper Lookup25 with (nolock) on dbo.RH_Activity.DressUpper = Lookup25.Code LEFT OUTER JOIN
    dbo.LU_FIM_Eating Lookup26 with (nolock) on dbo.RH_Activity.Eating = Lookup26.Code LEFT OUTER JOIN
    dbo.LU_FIM_Expression Lookup32 with (nolock) on dbo.RH_Activity.Expression = Lookup32.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup33 with (nolock) on dbo.RH_Activity.ExpressionMode = Lookup33.Code LEFT OUTER JOIN
    dbo.LU_FIM_Grooming Lookup41 with (nolock) on dbo.RH_Activity.Grooming = Lookup41.Code LEFT OUTER JOIN
    dbo.LU_FIM_Memory Lookup66 with (nolock) on dbo.RH_Activity.Memory = Lookup66.Code LEFT OUTER JOIN
    dbo.LU_FIM_ProblemSolve Lookup91 with (nolock) on dbo.RH_Activity.ProblemSolve = Lookup91.Code LEFT OUTER JOIN
    dbo.LU_FIM_Social Lookup122 with (nolock) on dbo.RH_Activity.SocialInteract = Lookup122.Code LEFT OUTER JOIN
    dbo.LU_FIM_Stairs Lookup125 with (nolock) on dbo.RH_Activity.Stairs = Lookup125.Code LEFT OUTER JOIN
    dbo.LU_FIM_TransToilet Lookup130 with (nolock) on dbo.RH_Activity.ToiletTransfer = Lookup130.Code LEFT OUTER JOIN
    dbo.LU_FIM_Toilet Lookup131 with (nolock) on dbo.RH_Activity.Toileting = Lookup131.Code LEFT OUTER JOIN
    dbo.LU_FIM_TransTub Lookup133 with (nolock) on dbo.RH_Activity.ShowerTransfer = Lookup133.Code LEFT OUTER JOIN
    dbo.LU_FIM_Walk_Wheel Lookup141 with (nolock) on dbo.RH_Activity.Walk = Lookup141.Code LEFT OUTER JOIN
    dbo.LU_CodeFile Lookup142 with (nolock) on dbo.RH_Activity.WalkMode = Lookup142.Code LEFT OUTER JOIN
    dbo.H_HospitalProfile with (nolock) on dbo.RH_ClientInfo.HospitalID = H_HospitalProfile.Code 
where Lookup4.DisplayCode = ''1''
--2.x-0177
----PR - 07485
--    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or RH_ClientInfo.HospitalID is null or RH_ClientInfo.HospitalID = 0
----EN - 00666
--        or Is_Member(nullif(ReportGroup, '''')) = 1)
----        or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(RH_ClientInfo.HospitalID, 0))

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[RehabErrorsWarnings_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[RehabErrorsWarnings_VR]
AS
SELECT 
    CIHI_ElementID = U_UsersFields.CIHI_ID,
    FieldName = U_UsersFields.Header_User, 
    --ErrorMessage = dbo.MG_Messages.MessageText, 
    MessageLevel = CASE AB_ErrorMessages.MessageType WHEN 1 THEN ''Warning'' 
                                    WHEN 2 THEN ''Error'' 
                                    WHEN 3 THEN ''Critical'' 
                                    WHEN 0 THEN ''Information'' 
                                    WHEN 5 THEN ''Question'' END, 
    AB_ErrorMessages.MessageText, 
    AB_ErrorMessages.SaveDate, 
    AB_ErrorMessages.AbstractID AS zzRehabLink
FROM dbo.AB_ErrorMessages with (nolock)
    --left join dbo.MG_Messages with (nolock)
    --    on dbo.AB_ErrorMessages.MessageKey = dbo.MG_Messages.MessageKey
    left join dbo.AB_ErrorMessageFields with (nolock)
        on dbo.AB_ErrorMessages.AppID = dbo.AB_ErrorMessageFields.AppID
            and dbo.AB_ErrorMessages.AbstractID = dbo.AB_ErrorMessageFields.AbstractID 
            and dbo.AB_ErrorMessages.MessageKey = dbo.AB_ErrorMessageFields.MessageKey
    left join dbo.U_UsersFields with (nolock) 
        on UserID = 1 and dbo.AB_ErrorMessages.AppID = dbo.U_UsersFields.AppID and 
        (case when isnumeric(replace(dbo.AB_ErrorMessageFields.FieldKey, ''FK'', '''')) = 1 
              then replace(dbo.AB_ErrorMessageFields.FieldKey, ''FK'', '''')
              else 0 end) = dbo.U_UsersFields.FieldID 
Where AB_ErrorMessages.appid between 250 and 259


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ReIOIDocument_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[ReIOIDocument_VR]
AS
SELECT  
	OccurrenceNumber as DocumentOccurrence, 
	DocumentStartDate, 
	DocumentEndDate, 
	LU_ROI_DocumentCode.DisplayCode as DocumentCode, 	LU_ROI_DocumentCode.UserDescription as DocumentCodeDesc, 
	DocumentComments,
	ROIID as zzROILink
from [dbo].[ROI_Document]
	left join LU_ROI_DocumentCode on LU_ROI_DocumentCode.code = ROI_Document.DocumentCode
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ReIOIMain_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[ReIOIMain_VR]
AS
SELECT     
    LU_AgeCode.DisplayCode AS AgeCode, LU_AgeCode.UserDescription AS AgeCodeDescription, 
    dbo.ROI_Main.AgeNumber, 
    dbo.ROI_Main.AccountNumber, ROI_RequesterInfo.Address, dbo.ROI_Main.AmountPaid AS AmountPaidToDate, 
    Lookup1.DisplayCode AS AuthorizationReceived, Lookup1.UserDescription AS AuthorizationReceivedDesc, 
    Lookup2.DisplayCode AS AuthorizationRequired, Lookup2.UserDescription AS AuthorizationRequiredDesc, 
    Lookup3.DisplayCode AS AuthorizationSignedBy, Lookup3.UserDescription AS AuthorizationSignedByDesc, 
    Lookup4.DisplayCode AS AuthorizationType,     Lookup4.UserDescription AS AuthorizationTypeDesc, 
    ROI_RequesterInfo.BillingAddress, ROI_RequesterInfo.BillingCity, 
    LU_CPI_Country_1.DisplayCode AS BillingCountry, LU_CPI_Country_1.UserDescription AS BillingCountryDesc, ROI_RequesterInfo.BillingPostalCode, 
    dbo.LU_CPI_Province.DisplayCode AS BillingProvince, dbo.LU_CPI_Province.UserDescription AS BillingProvinceDesc, 
	dbo.ROI_Main.BirthDate,
    Lookup5.DisplayCode AS ChargeableRequest, Lookup5.UserDescription AS ChargeableRequestDesc, dbo.ROI_Main.ChartNumber, ROI_RequesterInfo.City, 

    --PR - 05814
    LU_Confidential.DisplayCode AS Confidential, LU_Confidential.UserDescription AS ConfidentialDesc, 

    Lookup6.DisplayCode AS Contact, Lookup6.UserDescription AS ContactDesc, dbo.ROI_Main.ContactEMail, 
    dbo.ROI_Main.ContactFax AS ContactFaxNumber, dbo.ROI_Main.ContactExtention AS ContactPhoneExtension, 
    dbo.ROI_Main.ContactPhone AS ContactPhoneNumber, Lookup7.DisplayCode AS CostLevel, Lookup7.UserDescription AS CostLevelDesc, 
    LUCountry.DisplayCode AS Country, LUCountry.UserDescription AS CountryDesc, dbo.ROI_Main.DueDate, 
    dbo.ROI_Main.RequestDuration AS DurationSinceRequestReceived, 
    
    dbo.ROI_Main.ExtensionDays,
    LU_ExtensionNoticeRequired.DisplayCode as ExtensionNoticeRequired, LU_ExtensionNoticeRequired.UserDescription as ExtensionNoticeRequiredDesc,
    --PR - 04476
    ROI_RequesterInfo.Fax as FaxNumber,

    dbo.ROI_Main.FirstName, dbo.ROI_Main.GSTNumber, 
    LU_Hospital.DisplayCode AS Hospital, LU_Hospital.UserDescription AS HospitalDesc, dbo.ROI_Main.InvoiceDate, dbo.ROI_Main.InvoiceNumber, 
                      
    --PR - 05164
    lu_Deletion.DisplayCode as IsDeleted, lu_Deletion.UserDescription as IsDeletedDesc,                     
    dbo.ROI_Main.InvoiceTime, dbo.ROI_Main.InvoiceTotal, dbo.ROI_Main.LastName, 

    --PR - 04476
    ROI_RequesterInfo.PhoneExt as PhoneExtension, ROI_RequesterInfo.Phone as PhoneNumber, 

    ROI_RequesterInfo.PostalCode, LUProvince.DisplayCode AS Province, 
    LUProvince.UserDescription AS ProvinceDesc, Lookup8.DisplayCode AS RequestCoder, Lookup8.UserDescription AS RequestCoderDesc, 
    dbo.ROI_Main.RequestComments, dbo.ROI_Main.RequestDate AS RequestDated, 
    Lookup11.DisplayCode AS RequesterID, Lookup11.UserDescription AS RequesterIDDesc, 
    Lookup12.DisplayCode AS RequesterType, Lookup12.UserDescription AS RequesterTypeDesc, 
    --dbo.ROI_Payments.ROIID AS RequestID, PR - 07266
    Lookup9.DisplayCode AS RequestMethod, Lookup9.UserDescription AS RequestMethodDesc, 
    dbo.ROI_Main.RequestNumber, dbo.ROI_Main.RequestReceived AS RequestReceivedDate, dbo.ROI_Main.RequestReceivedTime, 
    Lookup10.DisplayCode AS RequestType, Lookup10.UserDescription AS RequestTypeDesc, LU_RequestUrgency.DisplayCode AS RequestUrgency, 
    LU_RequestUrgency.UserDescription AS RequestUrgencyDesc, 
    ROILegalComments = (select top 1 CM_CPI.ROILegalComments from CM_CPI 
                        where CM_CPI.ChartNumber = ROI_Main.ChartNumber and isnull(CM_CPI.HospitalID, 0) in (0, isnull(ROI_Main.HospitalID, 0)) 
                        order by isnull((case when ROI_Main.HospitalID > 0 then 0 - CM_CPI.HospitalID else CM_CPI.HospitalID end), 0)
                        ),
    Lookup13.DisplayCode AS ROIStatus, Lookup13.UserDescription AS ROIStatusDesc, 
    ROITaxRate1, ROITaxRate2,
    Lookup14.DisplayCode AS SentBy, Lookup14.UserDescription AS SentByDesc, Lookup15.DisplayCode AS SentCoder, 
    Lookup15.UserDescription AS SentCoderDesc, dbo.ROI_Main.SentDate, dbo.ROI_Main.SentTime, 
    dbo.ROI_Main.SpecialHandling AS SpecialHandlingInstructions, 
    lu_Site.DisplayCode as SiteNumber, lu_Site.UserDescription as SiteNumberDesc,                     
    dbo.ROI_Main.AmountOwed AS TotalAmountDue, dbo.ROI_Main.TrackingNumber, 
    dbo.ROI_Main.ROIID AS zzROILink
FROM         
    dbo.ROI_Main with (nolock) LEFT OUTER JOIN
    dbo.ROI_RequesterInfo with (nolock) ON dbo.ROI_Main. ROIID= ROI_RequesterInfo.ROIID LEFT OUTER JOIN
    dbo.LU_CodeFile AS LU_RequestUrgency with (nolock) ON dbo.ROI_Main.RequestUrgency = LU_RequestUrgency.Code LEFT OUTER JOIN
    dbo.H_HospitalProfile AS LU_Hospital with (nolock)ON dbo.ROI_Main.HospitalID = LU_Hospital.Code LEFT OUTER JOIN
    --dbo.ROI_Payments with (nolock)ON dbo.ROI_Main.ROIID = dbo.ROI_Payments.ROIID LEFT OUTER JOIN  --PR - 07266
    dbo.LU_YesNoSystem AS Lookup1 with (nolock)ON dbo.ROI_Main.AuthorizationReceived = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS Lookup2 with (nolock)ON dbo.ROI_Main.AuthorizationRequired = Lookup2.Code LEFT OUTER JOIN
    dbo.LU_ROI_SignedBy AS Lookup3 with (nolock)ON dbo.ROI_Main.AuthorizationSignedID = Lookup3.Code LEFT OUTER JOIN
    dbo.LU_ROI_AuthorizationType AS Lookup4 with (nolock)ON dbo.ROI_Main.AuthorizationType = Lookup4.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS Lookup5 with (nolock)ON dbo.ROI_Main.RequestChargeable = Lookup5.Code LEFT OUTER JOIN
    dbo.LU_ROI_Contacts AS Lookup6 with (nolock)ON dbo.ROI_Main.ContactID = Lookup6.Code LEFT OUTER JOIN
    dbo.LU_ROI_CostLevel AS Lookup7 with (nolock)ON dbo.ROI_Main.CostLevel = Lookup7.Code LEFT OUTER JOIN
    dbo.U_Users AS Lookup8 with (nolock) ON dbo.ROI_Main.RequestCoder = Lookup8.Code LEFT OUTER JOIN
    dbo.LU_ROI_RequestMethod AS Lookup9 with (nolock)ON Lookup9.Code = dbo.ROI_Main.RequestMethod LEFT OUTER JOIN
    dbo.LU_ROI_RequestTypes AS Lookup10 with (nolock)ON Lookup10.Code = dbo.ROI_Main.RequestType LEFT OUTER JOIN
    dbo.LU_ROI_Requesters AS Lookup11 with (nolock)ON dbo.ROI_Main.RequesterID = Lookup11.Code LEFT OUTER JOIN
    
    dbo.LU_CPI_Country AS LU_CPI_Country_1 with (nolock)ON LU_CPI_Country_1.Code = ROI_RequesterInfo.BillingCountry LEFT OUTER JOIN
    dbo.LU_CPI_Province with (nolock)ON ROI_RequesterInfo.BillingProvince = dbo.LU_CPI_Province.Code LEFT OUTER JOIN
    dbo.LU_CPI_Country AS LUCountry with (nolock)ON ROI_RequesterInfo.Country = LUCountry.Code LEFT OUTER JOIN
    dbo.LU_CPI_Province AS LUProvince with (nolock)ON ROI_RequesterInfo.Province = LUProvince.Code LEFT OUTER JOIN

    dbo.LU_ROI_RequesterTypes AS Lookup12 with (nolock)ON Lookup12.Code = dbo.ROI_Main.RequesterType LEFT OUTER JOIN
    dbo.LU_ROI_Status AS Lookup13 with (nolock)ON dbo.ROI_Main.ROIStatus = Lookup13.Code LEFT OUTER JOIN
    dbo.LU_ROI_CourierID AS Lookup14 with (nolock)ON Lookup14.Code = dbo.ROI_Main.SentBy LEFT OUTER JOIN
    dbo.U_Users AS Lookup15 with (nolock)ON dbo.ROI_Main.SentCoder = Lookup15.Code LEFT OUTER JOIN
    dbo.LU_DeleteStatus as lu_Deletion with (nolock)on LU_Deletion.code = ROI_main.IsDeleted LEFT OUTER JOIN
    dbo.LU_CodeFile as LU_Confidential with (nolock)on ROI_main.Confidential = LU_Confidential.Code  LEFT OUTER JOIN
    dbo.LU_YesNoSystem as LU_ExtensionNoticeRequired with (nolock) on ROI_main.ExtensionNoticeRequired = LU_ExtensionNoticeRequired.Code LEFT OUTER JOIN
    dbo.LU_AgeCode with (nolock) on ROI_main.AgeCode = LU_AgeCode.Code  LEFT OUTER JOIN
    dbo.LU_Site with (nolock) on ROI_main.SiteNumber = LU_Site.Code 
--PR - 07485
--where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or ROI_Main.HospitalID is null or ROI_Main.HospitalID = 0
----EN - 00666
--    or Is_Member(nullif(ReportGroup, '''')) = 1
--    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(ROI_Main.HospitalID, 0))




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[RelOIActions_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE  VIEW [dbo].[RelOIActions_VR]
AS
SELECT     
    Lookup1.DisplayCode AS ActionCoder, Lookup1.UserDescription AS ActionCoderDesc, 
    dbo.ROI_Actions.ActionsComments as ActionComments, dbo.ROI_Actions.ActionDate, 
    dbo.ROI_Actions.OccurrenceNumber AS ActionOccurrence, dbo.ROI_Actions.ActionTime, 
    Lookup2.DisplayCode AS ActionType, Lookup2.UserDescription AS ActionTypeDesc, 
    dbo.ROI_Actions.ActionFollowUpDays AS FollowUpDays, Lookup3.DisplayCode AS NextAction, 
    Lookup3.UserDescription AS NextActionDesc, dbo.ROI_Actions.ROIID AS zzROILink
FROM dbo.ROI_Actions with (nolock) LEFT OUTER JOIN
    dbo.U_Users Lookup1 with (nolock) ON dbo.ROI_Actions.ActionCoder = Lookup1.Code LEFT OUTER JOIN
    dbo.LU_ROI_ActionType Lookup2 with (nolock) ON dbo.ROI_Actions.ActionType = Lookup2.Code LEFT OUTER JOIN
    dbo.LU_ROI_ActionType Lookup3 with (nolock) ON dbo.ROI_Actions.NextAction = Lookup3.Code
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[RelOIPayments_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[RelOIPayments_VR]
AS
SELECT     dbo.ROI_Payments.PaymentAmount, dbo.ROI_Payments.PaymentCheque, dbo.ROI_Payments.PaymentDate, dbo.ROI_Payments.PaymentTime, 
                      dbo.LU_ROI_PaymentMethod.DisplayCode AS PaymentMethod, dbo.LU_ROI_PaymentMethod.UserDescription AS PaymentMethodDesc, 
                      dbo.ROI_Payments.OccurrenceNumber AS PaymentOccurrence, dbo.ROI_Payments.ROIID AS zzROILink
FROM         dbo.ROI_Payments with (nolock) LEFT OUTER JOIN
    dbo.LU_ROI_PaymentMethod with (nolock) ON dbo.ROI_Payments.PaymentMethod = dbo.LU_ROI_PaymentMethod.Code




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[RelOISentItems_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE  VIEW [dbo].[RelOISentItems_VR]
AS
SELECT     Lookup1.DisplayCode AS ItemCode, Lookup1.UserDescription AS ItemCodeDesc, dbo.ROI_SentItems.OccurrenceNumber AS ItemOccurrence, 
                      dbo.ROI_SentItems.Price AS ItemPrice, dbo.ROI_SentItems.Quantity AS ItemQuantity, dbo.ROI_SentItems.SentDate AS ItemSentDate, 
                      Lookup2.DisplayCode AS ItemTaxType, Lookup2.UserDescription AS ItemTaxTypeDesc, dbo.ROI_SentItems.Amount AS ItemTotalAmount, 
                      dbo.ROI_SentItems.SentDate, dbo.ROI_SentItems.SentComments AS SentItemComments, dbo.ROI_SentItems.ROIID AS zzROILink
FROM         dbo.ROI_SentItems with (nolock) LEFT OUTER JOIN
                      dbo.LU_ROI_SentItemTypes Lookup1 with (nolock) ON dbo.ROI_SentItems.ItemCode = Lookup1.Code LEFT OUTER JOIN
                      dbo.LU_ROI_TaxType Lookup2 with (nolock) ON dbo.ROI_SentItems.TaxCode = Lookup2.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[RelOIUpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'




CREATE VIEW [dbo].[RelOIUpdateHistory_VR]
AS
SELECT     dbo.U_Users.DisplayCode AS UpdateCoder, dbo.U_Users.UserDescription AS UpdateCoderDescription, 
                      dbo.ROI_UpdateHistory.Updated AS UpdateDate, dbo.ROI_UpdateHistory.UpdateType, dbo.ROI_UpdateHistory.ROIID AS zzROILink
FROM         dbo.ROI_UpdateHistory with (nolock) LEFT OUTER JOIN
                      dbo.U_Users with (nolock) ON dbo.ROI_UpdateHistory.Coder = dbo.U_Users.Code





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_AbstractAudit_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[Sec_AbstractAudit_VR]
AS
SELECT     dbo.AB_Abstract.AdmitDate, dbo.AB_Abstract.AdmitTime, dbo.U_Appids.ModuleName AS Application, dbo.AB_Abstract.ChartNumber, 
                      dbo.U_Users.DisplayCode AS Coder, dbo.U_Users.UserDescription AS CoderDescription, dbo.AB_Abstract.DischargeDate, 
                      dbo.AB_Abstract.DischargeTime, dbo.AB_Abstract.EncounterNumber, dbo.AB_Abstract.EncounterSequence, 
                      dbo.U_UsersFields.Header_User AS FieldName, dbo.AB_Abstract.FirstName, dbo.AB_Abstract.LastName, dbo.AB_UpdateAudit.NewValue, 
                      dbo.AB_UpdateAudit.Occurrence, dbo.AB_UpdateAudit.OldValue, dbo.AB_UpdateAudit.Updated, 
                      AB_UpdateAudit.AbstractID as zzAbstractLink
FROM         dbo.AB_UpdateAudit with (nolock) LEFT OUTER JOIN
                      dbo.U_Appids with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_Appids.AppID LEFT OUTER JOIN
                      dbo.U_UsersFields with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_UsersFields.AppID AND 
                      dbo.AB_UpdateAudit.Fieldid = dbo.U_UsersFields.FieldID LEFT OUTER JOIN
                      dbo.AB_Abstract with (nolock) ON dbo.AB_UpdateAudit.Abstractid = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
                      dbo.U_Users with (nolock) ON dbo.AB_UpdateAudit.Coder = dbo.U_Users.Code
WHERE     (dbo.U_UsersFields.UserID = 1) AND (dbo.AB_UpdateAudit.Appid in (100, 101, 102, 200, 201, 202, 401, 301))
    and not (Occurrence < 0 and OldValue = '''' and NewValue = ''DELETED'')
Union All
SELECT     NULL AS AdmitDate, NULL AS AdmitTime, dbo.U_Appids.ModuleName AS Application, dbo.CM_CPI.ChartNumber, dbo.U_Users.DisplayCode AS Coder, 
                      dbo.U_Users.UserDescription AS CoderDescription, NULL AS DischargeDate, NULL AS DischargeTime, '''' AS EncounterNumber, 
                      '''' AS EncounterSequence, dbo.U_UsersFields.Header_User AS FieldName, dbo.CM_CPI.FirstName, dbo.CM_CPI.LastName, 
                      dbo.AB_UpdateAudit.NewValue, dbo.AB_UpdateAudit.Occurrence, dbo.AB_UpdateAudit.OldValue, dbo.AB_UpdateAudit.Updated, 
                      AB_UpdateAudit.AbstractID as zzAbstractLink
FROM         dbo.AB_UpdateAudit with (nolock) RIGHT OUTER JOIN
                      dbo.U_Appids with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_Appids.AppID RIGHT OUTER JOIN
                      dbo.CM_CPI with (nolock) ON dbo.AB_UpdateAudit.Abstractid = dbo.CM_CPI.PatientID LEFT OUTER JOIN
                      dbo.U_UsersFields with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_UsersFields.AppID AND 
                      dbo.AB_UpdateAudit.Fieldid = dbo.U_UsersFields.FieldID LEFT OUTER JOIN
                      dbo.AB_Abstract with (nolock) ON dbo.AB_UpdateAudit.Abstractid = dbo.AB_Abstract.AbstractID LEFT OUTER JOIN
                      dbo.U_Users with (nolock) ON dbo.AB_UpdateAudit.Coder = dbo.U_Users.Code
WHERE     (dbo.U_UsersFields.UserID = 1) AND (dbo.AB_UpdateAudit.Appid = 0)
    and not (Occurrence < 0 and OldValue = '''' and NewValue = ''DELETED'')
Union All
SELECT     dbo.CRS_Demographic.AdmitDate, Null as AdmitTime, dbo.U_Appids.ModuleName AS Application, dbo.CRS_Demographic.ChartNumber, 
                      dbo.U_Users.DisplayCode AS Coder, dbo.U_Users.UserDescription AS CoderDescription, dbo.CRS_Demographic.DischargeDate, 
                      Null as DischargeTime, Null as EncounterNumber, Null as EncounterSequence, 
                      dbo.U_UsersFields.Header_User AS FieldName, dbo.CRS_Demographic.FirstName, dbo.CRS_Demographic.LastName, dbo.AB_UpdateAudit.NewValue, 
                      dbo.AB_UpdateAudit.Occurrence, dbo.AB_UpdateAudit.OldValue, dbo.AB_UpdateAudit.Updated, 
                      AB_UpdateAudit.AbstractID as zzAbstractLink
FROM         dbo.AB_UpdateAudit with (nolock) LEFT OUTER JOIN
                      dbo.U_Appids with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_Appids.AppID LEFT OUTER JOIN
                      dbo.U_UsersFields with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_UsersFields.AppID AND 
                      dbo.AB_UpdateAudit.Fieldid = dbo.U_UsersFields.FieldID LEFT OUTER JOIN
                      dbo.CRS_Demographic with (nolock) ON dbo.AB_UpdateAudit.Abstractid = dbo.CRS_Demographic.AbstractID LEFT OUTER JOIN
                      dbo.U_Users with (nolock) ON dbo.AB_UpdateAudit.Coder = dbo.U_Users.Code
WHERE     (dbo.U_UsersFields.UserID = 1) AND (dbo.AB_UpdateAudit.Appid between 470 and 480)
    and not (Occurrence < 0 and OldValue = '''' and NewValue = ''DELETED'')
Union All
--PR - 02848
-- SELECT     dbo.CR_Visit.AdmitDate AS AdmitDate, dbo.CR_Visit.AdmitTime AS AdmitTime, dbo.U_AppIDs.ModuleName AS Application, 
--                       dbo.CR_Demographic.ChartNumber, dbo.U_Users.DisplayCode AS Coder, dbo.U_Users.UserDescription AS CoderDescription, '''' AS DischargeDate, 
--                       dbo.CR_Visit.DischargeTime AS DischargeTime, dbo.CR_Visit.EncounterNumber AS EncounterNumber, 
--                       dbo.CR_Visit.EncounterSequence AS EncounterSequence, dbo.U_UsersFields.Header_User AS FieldName, dbo.CR_Demographic.FirstName, 
--                       dbo.CR_Demographic.LastName, dbo.AB_UpdateAudit.NewValue, dbo.AB_UpdateAudit.Occurrence, dbo.AB_UpdateAudit.OldValue, 
--                       dbo.AB_UpdateAudit.Updated
-- FROM         dbo.CR_Visit RIGHT OUTER JOIN
--                       dbo.CR_Demographic ON dbo.CR_Visit.AbstractID = dbo.CR_Demographic.AbstractID RIGHT OUTER JOIN
--                       dbo.AB_UpdateAudit LEFT OUTER JOIN
--                       dbo.U_AppIDs ON dbo.AB_UpdateAudit.Appid = dbo.U_AppIDs.AppID LEFT OUTER JOIN
--                       dbo.U_UsersFields ON dbo.AB_UpdateAudit.Appid = dbo.U_UsersFields.AppID AND dbo.AB_UpdateAudit.Fieldid = dbo.U_UsersFields.FieldID ON 
--                       dbo.CR_Demographic.AbstractID = dbo.AB_UpdateAudit.Abstractid LEFT OUTER JOIN
--                       dbo.U_Users ON dbo.AB_UpdateAudit.Coder = dbo.U_Users.Code
SELECT     dbo.RH_ClientInfo.AdmitDate, Null as AdmitTime, dbo.U_Appids.ModuleName AS Application, dbo.RH_ClientInfo.ChartNumber, 
                      dbo.U_Users.DisplayCode AS Coder, dbo.U_Users.UserDescription AS CoderDescription, dbo.RH_ClientInfo.DischargeDate, 
                      Null as DischargeTime, RH_ClientInfo.EncounterNumber, Null as EncounterSequence, 
                      dbo.U_UsersFields.Header_User AS FieldName, dbo.RH_Demographic.FirstName, dbo.RH_Demographic.LastName, dbo.AB_UpdateAudit.NewValue, 
                      dbo.AB_UpdateAudit.Occurrence, dbo.AB_UpdateAudit.OldValue, dbo.AB_UpdateAudit.Updated, 
                      AB_UpdateAudit.AbstractID as zzAbstractLink
FROM         dbo.AB_UpdateAudit with (nolock) LEFT OUTER JOIN
                      dbo.U_Appids with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_Appids.AppID LEFT OUTER JOIN
                      dbo.U_UsersFields with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_UsersFields.AppID AND 
                      dbo.AB_UpdateAudit.Fieldid = dbo.U_UsersFields.FieldID LEFT OUTER JOIN
                      dbo.RH_ClientInfo with (nolock) ON dbo.AB_UpdateAudit.Abstractid = dbo.RH_ClientInfo.AbstractID LEFT OUTER JOIN
                      dbo.RH_Demographic with (nolock) ON dbo.AB_UpdateAudit.Abstractid = dbo.RH_Demographic.AbstractID LEFT OUTER JOIN
                      dbo.U_Users with (nolock) ON dbo.AB_UpdateAudit.Coder = dbo.U_Users.Code 
WHERE     (dbo.U_UsersFields.UserID = 1) AND (dbo.AB_UpdateAudit.Appid IN (250, 251, 252, 253))
    and not (Occurrence < 0 and OldValue = '''' and NewValue = ''DELETED'')
Union All
SELECT     dbo.OMHRS_SecAA.AdmitDate, OMHRS_SecAA.AdmitTime, dbo.U_Appids.ModuleName AS Application, dbo.OMHRS_SecAA.ChartNumber, 
                      dbo.U_Users.DisplayCode AS Coder, dbo.U_Users.UserDescription AS CoderDescription, DischargeDate = dbo.OMHRS_SecS.X80, 
                      OMHRS_SecS.DischargeTime, EncounterNumber = OMHRS_SecAA.AA3, Null as EncounterSequence, 
                      dbo.U_UsersFields.Header_User AS FieldName, dbo.OMHRS_SecAA.FirstName, dbo.OMHRS_SecAA.LastName, dbo.AB_UpdateAudit.NewValue, 
                      dbo.AB_UpdateAudit.Occurrence, dbo.AB_UpdateAudit.OldValue, dbo.AB_UpdateAudit.Updated, 
                      AB_UpdateAudit.AbstractID as zzAbstractLink
FROM         dbo.AB_UpdateAudit with (nolock) LEFT OUTER JOIN
                      dbo.U_Appids with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_Appids.AppID LEFT OUTER JOIN
                      dbo.U_UsersFields with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_UsersFields.AppID AND 
                      dbo.AB_UpdateAudit.Fieldid = dbo.U_UsersFields.FieldID LEFT OUTER JOIN
                      dbo.OMHRS_SecAA with (nolock) ON dbo.AB_UpdateAudit.Abstractid = dbo.OMHRS_SecAA.AbstractID LEFT OUTER JOIN
                      dbo.OMHRS_SecS with (nolock) ON dbo.AB_UpdateAudit.Abstractid = dbo.OMHRS_SecS.AbstractID LEFT OUTER JOIN
                      dbo.U_Users with (nolock) ON dbo.AB_UpdateAudit.Coder = dbo.U_Users.Code 
WHERE     (dbo.U_UsersFields.UserID = 1) AND (dbo.AB_UpdateAudit.Appid between 650 and 659)
    and not (Occurrence < 0 and OldValue = '''' and NewValue = ''DELETED'')
Union All
SELECT dbo.CJRR_Abstract.AdmitDate, CJRR_Abstract.AdmitTime, dbo.U_Appids.ModuleName AS Application, dbo.CJRR_Abstract.ChartNumber, 
    dbo.U_Users.DisplayCode AS Coder, dbo.U_Users.UserDescription AS CoderDescription, 
    DischargeDate = dbo.CJRR_Abstract.DischargeDate, 
    CJRR_Abstract.DischargeTime, EncounterNumber = null, Null as EncounterSequence, 
    dbo.U_UsersFields.Header_User AS FieldName, dbo.CJRR_Abstract.FirstName, dbo.CJRR_Abstract.LastName, dbo.AB_UpdateAudit.NewValue, 
    dbo.AB_UpdateAudit.Occurrence, dbo.AB_UpdateAudit.OldValue, dbo.AB_UpdateAudit.Updated, 
    AB_UpdateAudit.AbstractID as zzAbstractLink
FROM         dbo.AB_UpdateAudit with (nolock) LEFT OUTER JOIN
      dbo.U_Appids with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_Appids.AppID LEFT OUTER JOIN
      dbo.U_UsersFields with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_UsersFields.AppID AND 
      dbo.AB_UpdateAudit.Fieldid = dbo.U_UsersFields.FieldID LEFT OUTER JOIN
      dbo.CJRR_Abstract with (nolock) ON dbo.AB_UpdateAudit.Abstractid = dbo.CJRR_Abstract.RecordID LEFT OUTER JOIN
      dbo.U_Users with (nolock) ON dbo.AB_UpdateAudit.Coder = dbo.U_Users.Code 
WHERE     (dbo.U_UsersFields.UserID = 1) AND (dbo.AB_UpdateAudit.Appid in (40000, 40001))
    and not (Occurrence < 0 and OldValue = '''' and NewValue = ''DELETED'')
union all
SELECT dbo.CC_DiseaseRegister.RegisterDate as AdmitDate, null as AdmitTime, dbo.U_Appids.ModuleName AS Application, dbo.CC_Demographic.ChartNumber, 
    dbo.U_Users.DisplayCode AS Coder, dbo.U_Users.UserDescription AS CoderDescription, 
    null as DischargeDate, null as DischargeTime, EncounterNumber = null, Null as EncounterSequence, 
    dbo.U_UsersFields.Header_User AS FieldName, dbo.CC_Demographic.FirstName, dbo.CC_Demographic.LastName, dbo.AB_UpdateAudit.NewValue, 
    dbo.AB_UpdateAudit.Occurrence, dbo.AB_UpdateAudit.OldValue, dbo.AB_UpdateAudit.Updated, 
    AB_UpdateAudit.AbstractID as zzAbstractLink
FROM         dbo.AB_UpdateAudit with (nolock) LEFT OUTER JOIN
      dbo.U_Appids with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_Appids.AppID LEFT OUTER JOIN
      dbo.U_UsersFields with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_UsersFields.AppID AND 
      dbo.AB_UpdateAudit.Fieldid = dbo.U_UsersFields.FieldID LEFT OUTER JOIN
      dbo.CC_Demographic with (nolock) ON dbo.AB_UpdateAudit.Abstractid = dbo.CC_Demographic.AbstractID LEFT OUTER JOIN
      dbo.CC_DiseaseRegister with (nolock) ON dbo.AB_UpdateAudit.Abstractid = dbo.CC_Demographic.AbstractID LEFT OUTER JOIN
      dbo.U_Users with (nolock) ON dbo.AB_UpdateAudit.Coder = dbo.U_Users.Code 
WHERE     (dbo.U_UsersFields.UserID = 1) AND (dbo.AB_UpdateAudit.Appid in (675, 676))
    and not (Occurrence < 0 and OldValue = '''' and NewValue = ''DELETED'')
--0753 add Chart Location, Deficiency and ROI
union all
--ROI
SELECT dbo.ROI_Main.RequestDate as AdmitDate, dbo.ROI_Main.RequestReceivedTime as AdmitTime, 
	dbo.U_Appids.ModuleName AS Application, dbo.ROI_Main.ChartNumber, 
    dbo.U_Users.DisplayCode AS Coder, dbo.U_Users.UserDescription AS CoderDescription, 
    dbo.ROI_Main.[SentDate] as DischargeDate, dbo.ROI_Main.[SentTime] as DischargeTime, EncounterNumber = null, Null as EncounterSequence, 
    dbo.U_UsersFields.Header_User AS FieldName, dbo.ROI_Main.FirstName, dbo.ROI_Main.LastName, dbo.AB_UpdateAudit.NewValue, 
    dbo.AB_UpdateAudit.Occurrence, dbo.AB_UpdateAudit.OldValue, dbo.AB_UpdateAudit.Updated, 
    AB_UpdateAudit.AbstractID as zzAbstractLink
FROM         dbo.AB_UpdateAudit with (nolock) LEFT OUTER JOIN
      dbo.U_Appids with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_Appids.AppID LEFT OUTER JOIN
      dbo.U_UsersFields with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_UsersFields.AppID AND 
      dbo.AB_UpdateAudit.Fieldid = dbo.U_UsersFields.FieldID LEFT OUTER JOIN
      dbo.ROI_Main with (nolock) ON dbo.AB_UpdateAudit.Abstractid = dbo.ROI_Main.ROIID LEFT OUTER JOIN
      dbo.U_Users with (nolock) ON dbo.AB_UpdateAudit.Coder = dbo.U_Users.Code 
WHERE     (dbo.U_UsersFields.UserID = 1) AND (dbo.AB_UpdateAudit.Appid = 30)
    and not (Occurrence < 0 and OldValue = '''' and NewValue = ''DELETED'')
union all
--Deficiency
SELECT dbo.Def_SlipMain.DefStartDate as AdmitDate, null as AdmitTime, 
	dbo.U_Appids.ModuleName AS Application, dbo.CM_CPI.ChartNumber, 
    dbo.U_Users.DisplayCode AS Coder, dbo.U_Users.UserDescription AS CoderDescription, 
    Def_SlipMain.DefEndDate as DischargeDate, null as DischargeTime, EncounterNumber = null, Null as EncounterSequence, 
    dbo.U_UsersFields.Header_User AS FieldName, dbo.Def_SlipMain.DefPatFirstName, dbo.Def_SlipMain.DefPatLastName, dbo.AB_UpdateAudit.NewValue, 
    dbo.AB_UpdateAudit.Occurrence, dbo.AB_UpdateAudit.OldValue, dbo.AB_UpdateAudit.Updated, 
    AB_UpdateAudit.AbstractID as zzAbstractLink
FROM dbo.AB_UpdateAudit with (nolock) LEFT OUTER JOIN
      dbo.U_Appids with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_Appids.AppID LEFT OUTER JOIN
      dbo.U_UsersFields with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_UsersFields.AppID AND 
      dbo.AB_UpdateAudit.Fieldid = dbo.U_UsersFields.FieldID LEFT OUTER JOIN
      dbo.Def_SlipMain with (nolock) ON dbo.AB_UpdateAudit.Abstractid = dbo.Def_SlipMain.DefID LEFT OUTER JOIN
	  dbo.CM_CPI with (nolock) ON dbo.CM_CPI.PatientID = dbo.Def_SlipMain.DefPatientID LEFT OUTER JOIN
      dbo.U_Users with (nolock) ON dbo.AB_UpdateAudit.Coder = dbo.U_Users.Code 
WHERE     (dbo.U_UsersFields.UserID = 1) AND (dbo.AB_UpdateAudit.Appid = 15)
    and not (Occurrence < 0 and OldValue = '''' and NewValue = ''DELETED'')
union all
--PullList and Chart Locator
SELECT dbo.CL_PullList.[PullDate] as AdmitDate, dbo.CL_PullList.[PullTime] as AdmitTime, 
	dbo.U_Appids.ModuleName AS Application, dbo.CM_CPI.ChartNumber, 
    dbo.U_Users.DisplayCode AS Coder, dbo.U_Users.UserDescription AS CoderDescription, 
    dbo.CL_PullList.[LoanDate] as DischargeDate, dbo.CL_PullList.[LoanTime] as DischargeTime, EncounterNumber = null, Null as EncounterSequence, 
    dbo.U_UsersFields.Header_User AS FieldName, dbo.CM_CPI.FirstName, dbo.CM_CPI.LastName, dbo.AB_UpdateAudit.NewValue, 
    dbo.AB_UpdateAudit.Occurrence, dbo.AB_UpdateAudit.OldValue, dbo.AB_UpdateAudit.Updated, 
    AB_UpdateAudit.AbstractID as zzAbstractLink
FROM dbo.AB_UpdateAudit with (nolock) LEFT OUTER JOIN
      dbo.U_Appids with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_Appids.AppID LEFT OUTER JOIN
      dbo.U_UsersFields with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_UsersFields.AppID AND 
      dbo.AB_UpdateAudit.Fieldid = dbo.U_UsersFields.FieldID LEFT OUTER JOIN
      dbo.CL_PullList with (nolock) ON dbo.AB_UpdateAudit.Abstractid = dbo.CL_PullList.PullID LEFT OUTER JOIN
	  dbo.CM_CPI_Volume with (nolock) ON dbo.CM_CPI_Volume.VolumeID = dbo.CL_PullList.VolumeID LEFT OUTER JOIN
	  dbo.CM_CPI with (nolock) ON dbo.CM_CPI.PatientID = dbo.CM_CPI_Volume.PatientID LEFT OUTER JOIN
      dbo.U_Users with (nolock) ON dbo.AB_UpdateAudit.Coder = dbo.U_Users.Code 
WHERE     (dbo.U_UsersFields.UserID = 1) AND (dbo.AB_UpdateAudit.Appid in (10, 11))
--    and not (Occurrence < 0 and OldValue = '''' and NewValue = ''DELETED'')
union all
--Control File 2.x-0897
SELECT null as AdmitDate, null as AdmitTime, 
	''Control File'' AS Application, AB_UpdateAudit.extra as ChartNumber, 
    dbo.U_Users.DisplayCode AS Coder, dbo.U_Users.UserDescription AS CoderDescription, 
    null as DischargeDate, null as DischargeTime, EncounterNumber = null, Null as EncounterSequence, 
    (select top 1 InHouseDesc from u_fields where fieldid = AB_UpdateAudit.Fieldid) AS FieldName, 
    '''' as FirstName, 
    (select top 1 isnull(nullif(InHouseDesc, ''''), SystemName) from u_fields where fieldid = AB_UpdateAudit.AbstractID) as LastName, dbo.AB_UpdateAudit.NewValue, 
    dbo.AB_UpdateAudit.Occurrence, dbo.AB_UpdateAudit.OldValue, dbo.AB_UpdateAudit.Updated, 
    AB_UpdateAudit.AbstractID as zzAbstractLink
FROM dbo.AB_UpdateAudit with (nolock) LEFT OUTER JOIN
      --dbo.U_Appids with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_Appids.AppID LEFT OUTER JOIN
      --dbo.U_UsersFields with (nolock) ON dbo.AB_UpdateAudit.Appid = dbo.U_UsersFields.AppID AND 
      --dbo.AB_UpdateAudit.Fieldid = dbo.U_UsersFields.FieldID left join
      dbo.U_Users with (nolock) ON dbo.AB_UpdateAudit.Coder = dbo.U_Users.Code 
WHERE      dbo.AB_UpdateAudit.Appid = 1200 --(dbo.U_UsersFields.UserID = 1) AND


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_EncoderLog_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE view [dbo].[Sec_EncoderLog_VR]
as
select 
    zzAbstractLink = [RecordID],
    [Occurrence],
    Coder = U_Users.DisplayCode,
    CoderDesc = U_Users.UserDescription,
	Module = (case [ModuleID] when 201 then ''Inpatient''
                              when 200 then ''CCR''
                              when 202 then ''SDS''
                              when 401 then ''NACRS''
                              else ''OMHRS''
              end),
	[EncoderType] = (case when EncoderType = 1 then ''Folio'' else ''3M'' end),
    [StartDateTime] = [StartTime], 
    [EndDateTime] = [EndTime],
	DurationMinutes = [TimeMinutes],
	DurationSeconds = [TimeSeconds],
	[Status] = (case when [Status] = 1 then ''Completed'' else ''Cancelled'' end)
from AB_EncoderLog 
    left join U_Users on UserID = Code
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_LoginAudit_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[Sec_LoginAudit_VR]
AS
SELECT     LoginTime, PasswordEntered, Successful, UserName AS UserNameEntered, LogoutTime
FROM         dbo.M_Login with (nolock)







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_Purged_Information_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE  VIEW [dbo].[Sec_Purged_Information_VR]
AS
SELECT     AbstNumber AS AbstractNumber, dbo.U_Appids.ModuleName AS Application, BatchNumber, BatchPeriod, BatchYear, CareType, ChartNumber, CIHIDateSent AS DateSenttoCIHI, DeleteCoder, 
                      DeleteDate, DeleteTime, EncounterNumber, EncounterSequence, FullName, ICDType, InstNumber AS InstitutionNumber, IsCompleted, IsCorrected, 
                      IsSubmitted, IsValidated, PurgeCoder, PurgeDate, PurgeTime, VisitDate, VisitTime
FROM dbo.REC_Purge with (nolock)
    left join dbo.U_AppIDs with (nolock) on REC_Purge.AppID = U_AppIDs.AppID



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_ReportHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'




CREATE VIEW [dbo].[Sec_ReportHistory_VR]
AS
SELECT     dbo.RP_History.ActionType, dbo.RP_History.ActionLocation, dbo.RP_History.ReportName, dbo.RP_History.ReportSQL, 
                      dbo.RP_History.ReportExecution AS Report_Access, dbo.U_Users.DisplayCode AS User_Number, 
                      dbo.U_Users.UserDescription AS User_Description
FROM         dbo.RP_History with (nolock) LEFT OUTER JOIN
                      dbo.U_Users with (nolock) ON dbo.RP_History.Userid = dbo.U_Users.Code





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_Search_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'






CREATE VIEW [dbo].[Sec_Search_VR]
AS
SELECT     dbo.U_Appids.ModuleName AS Application, dbo.U_Users.DisplayCode AS Coder, dbo.U_Users.UserDescription AS CoderDesription, 
                      dbo.AU_Search.FieldSearched, dbo.AU_Search.SearchString, dbo.AU_Search.Updated
FROM         dbo.AU_Search with (nolock) LEFT OUTER JOIN
                      dbo.U_Users with (nolock) ON dbo.AU_Search.Userid = dbo.U_Users.Code LEFT OUTER JOIN
                      dbo.U_Appids with (nolock) ON dbo.AU_Search.Appid = dbo.U_Appids.AppID







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_SearchDetail_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'





CREATE VIEW [dbo].[Sec_SearchDetail_VR]
AS
SELECT     dbo.U_AppIDs.ModuleName AS Application, dbo.U_Users.DisplayCode AS Coder, dbo.U_Users.UserDescription AS CoderDetails, 
                      dbo.AU_SearchDetail.SearchedDate AS Searched, dbo.AU_SearchDetail.Abstractid AS zzAbstractLink
FROM         dbo.AU_SearchDetail with (nolock) LEFT OUTER JOIN
                      dbo.U_AppIDs with (nolock) ON dbo.AU_SearchDetail.AppID = dbo.U_AppIDs.AppID LEFT OUTER JOIN
                      dbo.U_Users with (nolock) ON dbo.AU_SearchDetail.Coder = dbo.U_Users.Code
WHERE     (dbo.AU_SearchDetail.AppID <> 0)






' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_SearchDetailCPI_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'





CREATE VIEW [dbo].[Sec_SearchDetailCPI_VR]
AS
SELECT     dbo.U_Users.DisplayCode AS Coder, dbo.U_Users.UserDescription AS CoderDetails, dbo.AU_SearchDetail.SearchedDate AS Searched, 
                      dbo.AU_SearchDetail.Abstractid AS zzPatientID
FROM         dbo.AU_SearchDetail with (nolock) LEFT OUTER JOIN
                      dbo.U_Users with (nolock) ON dbo.AU_SearchDetail.Coder = dbo.U_Users.Code
WHERE     (dbo.AU_SearchDetail.AppID = 0)






' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_SubmissionAudit]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[Sec_SubmissionAudit]
AS
SELECT     
    dbo.U_AppIDs.ModuleName AS Applicaiton, 
    (case when U_AppIDs.AppID in (101, 102, 201, 202, 301, 401, 40000, 40001) then dbo.LU_BatchPeriod.DisplayCode 
		  else LU_BatchPeriod_L.DisplayCode
	 end) AS BatchPeriod, 
    (case when U_AppIDs.AppID in (101, 102, 201, 202, 301, 401, 40000, 40001) then dbo.LU_BatchPeriod.UserDescription
		  else LU_BatchPeriod_L.UserDescription
	 end) AS BatchPeriodDescription,
    dbo.SU_ExecProperties.BatchYear, dbo.U_Users.DisplayCode AS Coder, 
    dbo.U_Users.UserDescription AS CoderDescription, dbo.SU_ExecProperties.DateStart AS DateFrom, 
    dbo.SU_ExecProperties.ExecutionDate AS DateRun, dbo.SU_ExecProperties.DateEnd AS DateTo, 
    dbo.H_InstitutionProfile.DisplayCode AS Institution, dbo.H_InstitutionProfile.UserDescription AS InstitutionDescription, 
    dbo.SU_ExecProperties.NameOfFile, dbo.SU_ExecProperties.RecordCount,
    dbo.SU_ExecProperties.TerminateSuccess,
    ExecutionID as zzSubmissionLink
FROM  dbo.SU_ExecProperties with (nolock) LEFT OUTER JOIN
      dbo.LU_BatchPeriod with (nolock) ON dbo.SU_ExecProperties.BatchPeriod = dbo.LU_BatchPeriod.Code LEFT OUTER JOIN
      dbo.LU_CodeFile LU_BatchPeriod_L with (nolock) ON 
		(case when AppID between 650 and 659 
		      then (case when datepart(year, DateStart) = datepart(year, DateEnd) and datepart(month, DateStart) = datepart(month, DateEnd) 
				         then 15650 + datepart(month, DateStart) + (case when datepart(month, DateStart) < 4 then 9 else -3 end)
				         else 15400 + dbo.SU_ExecProperties.BatchPeriod
				    end)
		      else dbo.SU_ExecProperties.BatchPeriod end) = LU_BatchPeriod_L.Code LEFT OUTER JOIN
      dbo.U_AppIDs with (nolock) ON dbo.SU_ExecProperties.AppID = dbo.U_AppIDs.AppID LEFT OUTER JOIN
      dbo.H_InstitutionProfile with (nolock) ON dbo.SU_ExecProperties.InstNoCode = dbo.H_InstitutionProfile.Code LEFT OUTER JOIN
      dbo.U_Users with (nolock) ON dbo.SU_ExecProperties.CoderNumber = dbo.U_Users.Code
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Sec_SubmissionRecord_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[Sec_SubmissionRecord_VR]
as
select 
    AbstractID as zzAbstractLink,
    ExecutionID as zzSubmissionLink
from dbo.SU_RecordHistory with (nolock)



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Signature_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'





CREATE VIEW [dbo].[Signature_VR]
AS
SELECT
    dbo.CRS_Signature.AbstractID AS zzAbstractLink, dbo.CRS_Signature.ProviderOccurrence AS Occurrence, dbo.CRS_Signature.R2b, 
    dbo.LU_Provider.DisplayCode AS ProviderNumber, dbo.LU_Provider.UserDescription AS Provider_Desc, 
    dbo.LU_ProviderService.DisplayCode AS ProviderService, dbo.LU_ProviderService.UserDescription AS ProviderService_DEsc, 
    dbo.CRS_Signature.ProviderNotes
FROM         
    dbo.LU_ProviderService with (nolock) RIGHT OUTER JOIN
    dbo.CRS_Signature with (nolock) ON dbo.LU_ProviderService.Code = dbo.CRS_Signature.ProviderService LEFT OUTER JOIN
    dbo.LU_Provider with (nolock) ON dbo.CRS_Signature.ProviderNumber = dbo.LU_Provider.Code








' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[UD_Abstracting_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[UD_Abstracting_VR]
AS
SELECT
    dbo.AB_UDAbstracting.UDDate1 AS Date1UD, dbo.AB_UDAbstracting.UDDate2 AS Date2UD, 
    dbo.AB_UDAbstracting.UDDate3 AS Date3UD, dbo.AB_UDAbstracting.UDDate4 AS Date4UD, 
    dbo.AB_UDAbstracting.UDDate5 AS Date5UD, dbo.AB_UDFieldsDate.UDDate6 AS Date6UD,
    dbo.AB_UDFieldsDate.UDDate7 AS Date7UD,  dbo.AB_UDFieldsDate.UDDate8 AS Date8UD,
    dbo.AB_UDFieldsDate.UDDate9 AS Date9UD,  dbo.AB_UDFieldsDate.UDDate10 AS Date10UD,
    dbo.AB_UDFieldsDate.UDDate11 AS Date11UD,  dbo.AB_UDFieldsDate.UDDate12 AS Date12UD,
    dbo.AB_UDFieldsDate.UDDate13 AS Date13UD,  dbo.AB_UDFieldsDate.UDDate14 AS Date14UD,
    dbo.AB_UDFieldsDate.UDDate15 AS Date15UD,  dbo.AB_UDFieldsDate.UDDate16 AS Date16UD,
    dbo.AB_UDFieldsDate.UDDate17 AS Date17UD,  dbo.AB_UDFieldsDate.UDDate18 AS Date18UD,
    dbo.AB_UDFieldsDate.UDDate19 AS Date19UD,  dbo.AB_UDFieldsDate.UDDate20 AS Date20UD,
    dbo.AB_UDFieldsDate.UDDate21 AS Date21UD,  dbo.AB_UDFieldsDate.UDDate22 AS Date22UD,
    dbo.AB_UDFieldsDate.UDDate23 AS Date23UD,  dbo.AB_UDFieldsDate.UDDate24 AS Date24UD,
    dbo.AB_UDFieldsDate.UDDate25 AS Date25UD,  
    
    dbo.LU_CodeFile.DisplayCode AS Lookup1UD, dbo.LU_CodeFile.UserDescription AS Lookup1UDDesc, 
    LU_CodeFile_1.DisplayCode AS Lookup2UD, LU_CodeFile_1.UserDescription AS Lookup2UDDesc, 
    LU_CodeFile_2.DisplayCode AS Lookup3UD, LU_CodeFile_2.UserDescription AS Lookup3UDDesc, 
    LU_CodeFile_3.DisplayCode AS Lookup4UD, LU_CodeFile_3.UserDescription AS Lookup4UDDesc, 
    LU_CodeFile_4.DisplayCode AS Lookup5UD, LU_CodeFile_4.UserDescription AS Lookup5UDDesc, 
    LU_CodeFile_6.DisplayCode AS Lookup6UD, LU_CodeFile_6.UserDescription AS Lookup6UDDesc, 
    LU_CodeFile_7.DisplayCode AS Lookup7UD, LU_CodeFile_7.UserDescription AS Lookup7UDDesc, 
    LU_CodeFile_8.DisplayCode AS Lookup8UD, LU_CodeFile_8.UserDescription AS Lookup8UDDesc, 
    LU_CodeFile_9.DisplayCode AS Lookup9UD, LU_CodeFile_9.UserDescription AS Lookup9UDDesc, 
    LU_CodeFile_10.DisplayCode AS Lookup10UD, LU_CodeFile_10.UserDescription AS Lookup10UDDesc, 
    LU_CodeFile_11.DisplayCode AS Lookup11UD, LU_CodeFile_11.UserDescription AS Lookup11UDDesc, 
    LU_CodeFile_12.DisplayCode AS Lookup12UD, LU_CodeFile_12.UserDescription AS Lookup12UDDesc, 
    LU_CodeFile_13.DisplayCode AS Lookup13UD, LU_CodeFile_13.UserDescription AS Lookup13UDDesc, 
    LU_CodeFile_14.DisplayCode AS Lookup14UD, LU_CodeFile_14.UserDescription AS Lookup14UDDesc, 
    LU_CodeFile_15.DisplayCode AS Lookup15UD, LU_CodeFile_15.UserDescription AS Lookup15UDDesc, 
    LU_CodeFile_16.DisplayCode AS Lookup16UD, LU_CodeFile_16.UserDescription AS Lookup16UDDesc, 
    LU_CodeFile_17.DisplayCode AS Lookup17UD, LU_CodeFile_17.UserDescription AS Lookup17UDDesc, 
    LU_CodeFile_18.DisplayCode AS Lookup18UD, LU_CodeFile_18.UserDescription AS Lookup18UDDesc, 
    LU_CodeFile_19.DisplayCode AS Lookup19UD, LU_CodeFile_19.UserDescription AS Lookup19UDDesc, 
    LU_CodeFile_20.DisplayCode AS Lookup20UD, LU_CodeFile_20.UserDescription AS Lookup20UDDesc, 
    LU_CodeFile_21.DisplayCode AS Lookup21UD, LU_CodeFile_21.UserDescription AS Lookup21UDDesc, 
    LU_CodeFile_22.DisplayCode AS Lookup22UD, LU_CodeFile_22.UserDescription AS Lookup22UDDesc, 
    LU_CodeFile_23.DisplayCode AS Lookup23UD, LU_CodeFile_23.UserDescription AS Lookup23UDDesc, 
    LU_CodeFile_24.DisplayCode AS Lookup24UD, LU_CodeFile_24.UserDescription AS Lookup24UDDesc, 
    LU_CodeFile_25.DisplayCode AS Lookup25UD, LU_CodeFile_25.UserDescription AS Lookup25UDDesc, 

    dbo.AB_UDAbstracting.UDInteger1 AS Numeric1UD, dbo.AB_UDAbstracting.UDInteger2 AS Numeric2UD, 
    dbo.AB_UDAbstracting.UDInteger3 AS Numeric3UD, dbo.AB_UDAbstracting.UDInteger4 AS Numeric4UD, 
    dbo.AB_UDAbstracting.UDInteger5 AS Numeric5UD, 
    dbo.AB_UDFieldsInteger.UDInteger6 AS Numeric6UD, 
    dbo.AB_UDFieldsInteger.UDInteger7 AS Numeric7UD, 
    dbo.AB_UDFieldsInteger.UDInteger8 AS Numeric8UD, 
    dbo.AB_UDFieldsInteger.UDInteger9 AS Numeric9UD, 
    dbo.AB_UDFieldsInteger.UDInteger10 AS Numeric10UD, 
    dbo.AB_UDFieldsInteger.UDInteger11 AS Numeric11UD, 
    dbo.AB_UDFieldsInteger.UDInteger12 AS Numeric12UD, 
    dbo.AB_UDFieldsInteger.UDInteger13 AS Numeric13UD, 
    dbo.AB_UDFieldsInteger.UDInteger14 AS Numeric14UD, 
    dbo.AB_UDFieldsInteger.UDInteger15 AS Numeric15UD, 
    dbo.AB_UDFieldsInteger.UDInteger16 AS Numeric16UD, 
    dbo.AB_UDFieldsInteger.UDInteger17 AS Numeric17UD, 
    dbo.AB_UDFieldsInteger.UDInteger18 AS Numeric18UD, 
    dbo.AB_UDFieldsInteger.UDInteger19 AS Numeric19UD, 
    dbo.AB_UDFieldsInteger.UDInteger20 AS Numeric20UD, 
    dbo.AB_UDFieldsInteger.UDInteger21 AS Numeric21UD, 
    dbo.AB_UDFieldsInteger.UDInteger22 AS Numeric22UD, 
    dbo.AB_UDFieldsInteger.UDInteger23 AS Numeric23UD, 
    dbo.AB_UDFieldsInteger.UDInteger24 AS Numeric24UD, 
    dbo.AB_UDFieldsInteger.UDInteger25 AS Numeric25UD, 
    
    dbo.AB_UDAbstracting.UDText1 AS Notes1UD, dbo.AB_UDAbstracting.UDText2 AS Notes2UD, 
    dbo.AB_UDAbstracting.UDText3 AS Notes3UD, dbo.AB_UDAbstracting.UDText4 AS Notes4UD,  
    dbo.AB_UDAbstracting.UDText5 AS Notes5UD,
    dbo.AB_UDFieldsText.UDText6 AS Notes6UD,
    dbo.AB_UDFieldsText.UDText7 AS Notes7UD,
    dbo.AB_UDFieldsText.UDText8 AS Notes8UD,
    dbo.AB_UDFieldsText.UDText9 AS Notes9UD,
    dbo.AB_UDFieldsText.UDText10 AS Notes10UD,
    dbo.AB_UDFieldsText.UDText11 AS Notes11UD,
    dbo.AB_UDFieldsText.UDText12 AS Notes12UD,
    dbo.AB_UDFieldsText.UDText13 AS Notes13UD,
    dbo.AB_UDFieldsText.UDText14 AS Notes14UD,
    dbo.AB_UDFieldsText.UDText15 AS Notes15UD,
    dbo.AB_UDFieldsText.UDText16 AS Notes16UD,
    dbo.AB_UDFieldsText.UDText17 AS Notes17UD,
    dbo.AB_UDFieldsText.UDText18 AS Notes18UD,
    dbo.AB_UDFieldsText.UDText19 AS Notes19UD,
    dbo.AB_UDFieldsText.UDText20 AS Notes20UD,
    dbo.AB_UDFieldsText.UDText21 AS Notes21UD,
    dbo.AB_UDFieldsText.UDText22 AS Notes22UD,
    dbo.AB_UDFieldsText.UDText23 AS Notes23UD,
    dbo.AB_UDFieldsText.UDText24 AS Notes24UD,
    dbo.AB_UDFieldsText.UDText25 AS Notes25UD,

    dbo.AB_UDAbstracting.UDSmallText1 AS Text1UD, dbo.AB_UDAbstracting.UDSmallText2 AS Text2UD, 
    dbo.AB_UDAbstracting.UDSmallText3 AS Text3UD, dbo.AB_UDAbstracting.UDSmallText4 AS Text4UD, 
    dbo.AB_UDAbstracting.UDSmallText5 AS Text5UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText6 AS Text6UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText7 AS Text7UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText8 AS Text8UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText9 AS Text9UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText10 AS Text10UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText11 AS Text11UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText12 AS Text12UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText13 AS Text13UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText14 AS Text14UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText15 AS Text15UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText16 AS Text16UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText17 AS Text17UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText18 AS Text18UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText19 AS Text19UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText20 AS Text20UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText21 AS Text21UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText22 AS Text22UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText23 AS Text23UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText24 AS Text24UD, 
    dbo.AB_UDFieldsSmallText.UDSmallText25 AS Text25UD, 

    dbo.AB_UDAbstracting.UDTime1 AS Time1UD, dbo.AB_UDAbstracting.UDTime2 AS Time2UD, 
    dbo.AB_UDAbstracting.UDTime3 AS Time3UD, dbo.AB_UDAbstracting.UDTime4 AS Time4UD, 
    dbo.AB_UDAbstracting.UDTime5 AS Time5UD, 
    dbo.AB_UDFieldsTime.UDTime6 AS Time6UD, 
    dbo.AB_UDFieldsTime.UDTime7 AS Time7UD, 
    dbo.AB_UDFieldsTime.UDTime8 AS Time8UD, 
    dbo.AB_UDFieldsTime.UDTime9 AS Time9UD, 
    dbo.AB_UDFieldsTime.UDTime10 AS Time10UD, 
    dbo.AB_UDFieldsTime.UDTime11 AS Time11UD, 
    dbo.AB_UDFieldsTime.UDTime12 AS Time12UD, 
    dbo.AB_UDFieldsTime.UDTime13 AS Time13UD, 
    dbo.AB_UDFieldsTime.UDTime14 AS Time14UD, 
    dbo.AB_UDFieldsTime.UDTime15 AS Time15UD, 
    dbo.AB_UDFieldsTime.UDTime16 AS Time16UD, 
    dbo.AB_UDFieldsTime.UDTime17 AS Time17UD, 
    dbo.AB_UDFieldsTime.UDTime18 AS Time18UD, 
    dbo.AB_UDFieldsTime.UDTime19 AS Time19UD, 
    dbo.AB_UDFieldsTime.UDTime20 AS Time20UD, 
    dbo.AB_UDFieldsTime.UDTime21 AS Time21UD, 
    dbo.AB_UDFieldsTime.UDTime22 AS Time22UD, 
    dbo.AB_UDFieldsTime.UDTime23 AS Time23UD, 
    dbo.AB_UDFieldsTime.UDTime24 AS Time24UD, 
    dbo.AB_UDFieldsTime.UDTime25 AS Time25UD, 

    dbo.AB_UDAbstracting.Abstractid AS zzAbstractLink
FROM  dbo.AB_UDAbstracting with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_4 with (nolock) ON dbo.AB_UDAbstracting.UDLookup5 = LU_CodeFile_4.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_3 with (nolock) ON dbo.AB_UDAbstracting.UDLookup4 = LU_CodeFile_3.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_2 with (nolock) ON dbo.AB_UDAbstracting.UDLookup3 = LU_CodeFile_2.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_1 with (nolock) ON dbo.AB_UDAbstracting.UDLookup2 = LU_CodeFile_1.Code LEFT OUTER JOIN
    dbo.LU_CodeFile with (nolock) ON dbo.AB_UDAbstracting.UDLookup1 = dbo.LU_CodeFile.Code LEFT OUTER JOIN
    dbo.AB_UDFieldsDate with (nolock) ON dbo.AB_UDAbstracting.AbstractiD = dbo.AB_UDFieldsDate.AbstractID LEFT OUTER JOIN
    dbo.AB_UDFieldsInteger with (nolock) ON dbo.AB_UDAbstracting.AbstractiD = dbo.AB_UDFieldsInteger.AbstractID LEFT OUTER JOIN
    dbo.AB_UDFieldsLookUp with (nolock) ON dbo.AB_UDAbstracting.AbstractiD = dbo.AB_UDFieldsLookUp.AbstractID LEFT OUTER JOIN
    dbo.AB_UDFieldsSmallText with (nolock) ON dbo.AB_UDAbstracting.AbstractiD = dbo.AB_UDFieldsSmallText.AbstractID LEFT OUTER JOIN
    dbo.AB_UDFieldsText with (nolock) ON dbo.AB_UDAbstracting.AbstractiD = dbo.AB_UDFieldsText.AbstractID LEFT OUTER JOIN
    dbo.AB_UDFieldsTime with (nolock) ON dbo.AB_UDAbstracting.AbstractiD = dbo.AB_UDFieldsTime.AbstractID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_6 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup6 = LU_CodeFile_6.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_7 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup7 = LU_CodeFile_7.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_8 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup8 = LU_CodeFile_8.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_9 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup9 = LU_CodeFile_9.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_10 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup10 = LU_CodeFile_10.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_11 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup11 = LU_CodeFile_11.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_12 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup12 = LU_CodeFile_12.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_13 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup13 = LU_CodeFile_13.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_14 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup14 = LU_CodeFile_14.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_15 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup15 = LU_CodeFile_15.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_16 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup16 = LU_CodeFile_16.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_17 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup17 = LU_CodeFile_17.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_18 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup18 = LU_CodeFile_18.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_19 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup19 = LU_CodeFile_19.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_20 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup20 = LU_CodeFile_20.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_21 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup21 = LU_CodeFile_21.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_22 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup22 = LU_CodeFile_22.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_23 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup23 = LU_CodeFile_23.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_24 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup24 = LU_CodeFile_24.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_25 with (nolock) ON dbo.AB_UDFieldsLookUp.UDLookup25 = LU_CodeFile_25.Code

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[UD_Central_Patient_Index_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[UD_Central_Patient_Index_VR]
AS
SELECT     
    dbo.CM_UserDefined.UDDate1, dbo.CM_UserDefined.UDDate2, dbo.CM_UserDefined.UDDate3, 
    dbo.CM_UserDefined.UDDate4, dbo.CM_UserDefined.UDDate5, 
    dbo.CM_UDFieldsDate.UDDate6,
    dbo.CM_UDFieldsDate.UDDate7,  dbo.CM_UDFieldsDate.UDDate8,
    dbo.CM_UDFieldsDate.UDDate9,  dbo.CM_UDFieldsDate.UDDate10,
    dbo.CM_UDFieldsDate.UDDate11,  dbo.CM_UDFieldsDate.UDDate12,
    dbo.CM_UDFieldsDate.UDDate13,  dbo.CM_UDFieldsDate.UDDate14,
    dbo.CM_UDFieldsDate.UDDate15,  dbo.CM_UDFieldsDate.UDDate16,
    dbo.CM_UDFieldsDate.UDDate17,  dbo.CM_UDFieldsDate.UDDate18,
    dbo.CM_UDFieldsDate.UDDate19,  dbo.CM_UDFieldsDate.UDDate20,
    dbo.CM_UDFieldsDate.UDDate21,  dbo.CM_UDFieldsDate.UDDate22,
    dbo.CM_UDFieldsDate.UDDate23,  dbo.CM_UDFieldsDate.UDDate24,
    dbo.CM_UDFieldsDate.UDDate25,  
    
    dbo.CM_UserDefined.UDInteger1, dbo.CM_UserDefined.UDInteger2, dbo.CM_UserDefined.UDInteger3, 
    dbo.CM_UserDefined.UDInteger4, dbo.CM_UserDefined.UDInteger5, 
    dbo.CM_UDFieldsInteger.UDInteger6, 
    dbo.CM_UDFieldsInteger.UDInteger7, 
    dbo.CM_UDFieldsInteger.UDInteger8, 
    dbo.CM_UDFieldsInteger.UDInteger9, 
    dbo.CM_UDFieldsInteger.UDInteger10, 
    dbo.CM_UDFieldsInteger.UDInteger11, 
    dbo.CM_UDFieldsInteger.UDInteger12, 
    dbo.CM_UDFieldsInteger.UDInteger13, 
    dbo.CM_UDFieldsInteger.UDInteger14, 
    dbo.CM_UDFieldsInteger.UDInteger15, 
    dbo.CM_UDFieldsInteger.UDInteger16, 
    dbo.CM_UDFieldsInteger.UDInteger17, 
    dbo.CM_UDFieldsInteger.UDInteger18, 
    dbo.CM_UDFieldsInteger.UDInteger19, 
    dbo.CM_UDFieldsInteger.UDInteger20, 
    dbo.CM_UDFieldsInteger.UDInteger21, 
    dbo.CM_UDFieldsInteger.UDInteger22, 
    dbo.CM_UDFieldsInteger.UDInteger23, 
    dbo.CM_UDFieldsInteger.UDInteger24, 
    dbo.CM_UDFieldsInteger.UDInteger25,
    
    LU_UD1.DisplayCode AS UDLookup1, LU_UD1.UserDescription AS UDLookup1Desc, 
    LU_UD2.DisplayCode AS UDLookup2, LU_UD2.UserDescription AS UDLookup2Desc, 
    LU_UD3.DisplayCode AS UDLookup3, LU_UD3.UserDescription AS UDLookup3Desc, 
    LU_UD4.DisplayCode AS UDLookup4, LU_UD4.UserDescription AS UDLookup4Desc, 
    LU_UD5.DisplayCode AS UDLookup5, LU_UD4.UserDescription AS UDLookup5Desc, 
    LU_CodeFile_6.DisplayCode AS UDLookUp6, LU_CodeFile_6.UserDescription AS UDLookUp6Desc, 
    LU_CodeFile_7.DisplayCode AS UDLookUp7, LU_CodeFile_7.UserDescription AS UDLookUp7Desc, 
    LU_CodeFile_8.DisplayCode AS UDLookUp8, LU_CodeFile_8.UserDescription AS UDLookUp8Desc, 
    LU_CodeFile_9.DisplayCode AS UDLookUp9, LU_CodeFile_9.UserDescription AS UDLookUp9Desc, 
    LU_CodeFile_10.DisplayCode AS UDLookUp10, LU_CodeFile_10.UserDescription AS UDLookUp10Desc, 
    LU_CodeFile_11.DisplayCode AS UDLookUp11, LU_CodeFile_11.UserDescription AS UDLookUp11Desc, 
    LU_CodeFile_12.DisplayCode AS UDLookUp12, LU_CodeFile_12.UserDescription AS UDLookUp12Desc, 
    LU_CodeFile_13.DisplayCode AS UDLookUp13, LU_CodeFile_13.UserDescription AS UDLookUp13Desc, 
    LU_CodeFile_14.DisplayCode AS UDLookUp14, LU_CodeFile_14.UserDescription AS UDLookUp14Desc, 
    LU_CodeFile_15.DisplayCode AS UDLookUp15, LU_CodeFile_15.UserDescription AS UDLookUp15Desc, 
    LU_CodeFile_16.DisplayCode AS UDLookUp16, LU_CodeFile_16.UserDescription AS UDLookUp16Desc, 
    LU_CodeFile_17.DisplayCode AS UDLookUp17, LU_CodeFile_17.UserDescription AS UDLookUp17Desc, 
    LU_CodeFile_18.DisplayCode AS UDLookUp18, LU_CodeFile_18.UserDescription AS UDLookUp18Desc, 
    LU_CodeFile_19.DisplayCode AS UDLookUp19, LU_CodeFile_19.UserDescription AS UDLookUp19Desc, 
    LU_CodeFile_20.DisplayCode AS UDLookUp20, LU_CodeFile_20.UserDescription AS UDLookUp20Desc, 
    LU_CodeFile_21.DisplayCode AS UDLookUp21, LU_CodeFile_21.UserDescription AS UDLookUp21Desc, 
    LU_CodeFile_22.DisplayCode AS UDLookUp22, LU_CodeFile_22.UserDescription AS UDLookUp22Desc, 
    LU_CodeFile_23.DisplayCode AS UDLookUp23, LU_CodeFile_23.UserDescription AS UDLookUp23Desc, 
    LU_CodeFile_24.DisplayCode AS UDLookUp24, LU_CodeFile_24.UserDescription AS UDLookUp24Desc, 
    LU_CodeFile_25.DisplayCode AS UDLookUp25, LU_CodeFile_25.UserDescription AS UDLookUp25Desc, 

    dbo.CM_UserDefined.UDSmallText1, dbo.CM_UserDefined.UDSmallText2, dbo.CM_UserDefined.UDSmallText3, 
    dbo.CM_UserDefined.UDSmallText4, dbo.CM_UserDefined.UDSmallText5, 
    dbo.CM_UDFieldsSmallText.UDSmallText6, 
    dbo.CM_UDFieldsSmallText.UDSmallText7, 
    dbo.CM_UDFieldsSmallText.UDSmallText8, 
    dbo.CM_UDFieldsSmallText.UDSmallText9, 
    dbo.CM_UDFieldsSmallText.UDSmallText10, 
    dbo.CM_UDFieldsSmallText.UDSmallText11, 
    dbo.CM_UDFieldsSmallText.UDSmallText12, 
    dbo.CM_UDFieldsSmallText.UDSmallText13, 
    dbo.CM_UDFieldsSmallText.UDSmallText14, 
    dbo.CM_UDFieldsSmallText.UDSmallText15, 
    dbo.CM_UDFieldsSmallText.UDSmallText16, 
    dbo.CM_UDFieldsSmallText.UDSmallText17, 
    dbo.CM_UDFieldsSmallText.UDSmallText18, 
    dbo.CM_UDFieldsSmallText.UDSmallText19, 
    dbo.CM_UDFieldsSmallText.UDSmallText20, 
    dbo.CM_UDFieldsSmallText.UDSmallText21, 
    dbo.CM_UDFieldsSmallText.UDSmallText22, 
    dbo.CM_UDFieldsSmallText.UDSmallText23, 
    dbo.CM_UDFieldsSmallText.UDSmallText24, 
    dbo.CM_UDFieldsSmallText.UDSmallText25,     
    dbo.CM_UserDefined.UDText1, dbo.CM_UserDefined.UDText2, dbo.CM_UserDefined.UDText3, 
    dbo.CM_UserDefined.UDText4, dbo.CM_UserDefined.UDText5, 
    dbo.CM_UDFieldsText.UDText6,
    dbo.CM_UDFieldsText.UDText7,
    dbo.CM_UDFieldsText.UDText8,
    dbo.CM_UDFieldsText.UDText9, 
    dbo.CM_UDFieldsText.UDText10,
    dbo.CM_UDFieldsText.UDText11,
    dbo.CM_UDFieldsText.UDText12,
    dbo.CM_UDFieldsText.UDText13,
    dbo.CM_UDFieldsText.UDText14,
    dbo.CM_UDFieldsText.UDText15,
    dbo.CM_UDFieldsText.UDText16,
    dbo.CM_UDFieldsText.UDText17,
    dbo.CM_UDFieldsText.UDText18,
    dbo.CM_UDFieldsText.UDText19,
    dbo.CM_UDFieldsText.UDText20,
    dbo.CM_UDFieldsText.UDText21,
    dbo.CM_UDFieldsText.UDText22,
    dbo.CM_UDFieldsText.UDText23,
    dbo.CM_UDFieldsText.UDText24,
    dbo.CM_UDFieldsText.UDText25,
    
    dbo.CM_UserDefined.UDTime1, dbo.CM_UserDefined.UDTime2, dbo.CM_UserDefined.UDTime3, 
    dbo.CM_UserDefined.UDTime4, dbo.CM_UserDefined.UDTime5, 
    dbo.CM_UDFieldsTime.UDTime6, 
    dbo.CM_UDFieldsTime.UDTime7, 
    dbo.CM_UDFieldsTime.UDTime8, 
    dbo.CM_UDFieldsTime.UDTime9, 
    dbo.CM_UDFieldsTime.UDTime10, 
    dbo.CM_UDFieldsTime.UDTime11, 
    dbo.CM_UDFieldsTime.UDTime12, 
    dbo.CM_UDFieldsTime.UDTime13, 
    dbo.CM_UDFieldsTime.UDTime14, 
    dbo.CM_UDFieldsTime.UDTime15, 
    dbo.CM_UDFieldsTime.UDTime16, 
    dbo.CM_UDFieldsTime.UDTime17, 
    dbo.CM_UDFieldsTime.UDTime18, 
    dbo.CM_UDFieldsTime.UDTime19, 
    dbo.CM_UDFieldsTime.UDTime20, 
    dbo.CM_UDFieldsTime.UDTime21, 
    dbo.CM_UDFieldsTime.UDTime22, 
    dbo.CM_UDFieldsTime.UDTime23, 
    dbo.CM_UDFieldsTime.UDTime24, 
    dbo.CM_UDFieldsTime.UDTime25, 
    
    dbo.CM_UserDefined.PatientID AS zzPatientLink
FROM         
    dbo.CM_UserDefined with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD5 with (nolock) ON dbo.CM_UserDefined.UDLookup5 = LU_UD5.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD4 with (nolock) ON dbo.CM_UserDefined.UDLookup4 = LU_UD4.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD3 with (nolock) ON dbo.CM_UserDefined.UDLookup3 = LU_UD3.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD2 with (nolock) ON LU_UD2.Code = dbo.CM_UserDefined.UDLookup2 LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD1 with (nolock) ON LU_UD1.Code = dbo.CM_UserDefined.UDLookup1 LEFT OUTER JOIN
    dbo.CM_UDFieldsDate with (nolock) ON dbo.CM_UserDefined.PatientID = dbo.CM_UDFieldsDate.PatientID LEFT OUTER JOIN
    dbo.CM_UDFieldsInteger with (nolock) ON dbo.CM_UserDefined.PatientID = dbo.CM_UDFieldsInteger.PatientID LEFT OUTER JOIN
    dbo.CM_UDFieldsLookUp with (nolock) ON dbo.CM_UserDefined.PatientID = dbo.CM_UDFieldsLookUp.PatientID LEFT OUTER JOIN
    dbo.CM_UDFieldsSmallText with (nolock) ON dbo.CM_UserDefined.PatientID = dbo.CM_UDFieldsSmallText.PatientID LEFT OUTER JOIN
    dbo.CM_UDFieldsText with (nolock) ON dbo.CM_UserDefined.PatientID = dbo.CM_UDFieldsText.PatientID LEFT OUTER JOIN
    dbo.CM_UDFieldsTime with (nolock) ON dbo.CM_UserDefined.PatientID = dbo.CM_UDFieldsTime.PatientID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_6 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup6 = LU_CodeFile_6.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_7 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup7 = LU_CodeFile_7.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_8 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup8 = LU_CodeFile_8.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_9 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup9 = LU_CodeFile_9.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_10 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup10 = LU_CodeFile_10.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_11 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup11 = LU_CodeFile_11.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_12 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup12 = LU_CodeFile_12.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_13 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup13 = LU_CodeFile_13.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_14 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup14 = LU_CodeFile_14.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_15 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup15 = LU_CodeFile_15.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_16 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup16 = LU_CodeFile_16.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_17 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup17 = LU_CodeFile_17.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_18 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup18 = LU_CodeFile_18.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_19 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup19 = LU_CodeFile_19.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_20 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup20 = LU_CodeFile_20.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_21 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup21 = LU_CodeFile_21.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_22 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup22 = LU_CodeFile_22.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_23 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup23 = LU_CodeFile_23.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_24 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup24 = LU_CodeFile_24.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_25 with (nolock) ON dbo.CM_UDFieldsLookUp.UDLookup25 = LU_CodeFile_25.Code 

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[UD_I9_AbstractingMB_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'





create view [dbo].[UD_I9_AbstractingMB_VR]
as
select
    LU_AbstractType.DisplayCode as AbstractType,
    LU_AbstractType.UserDescription as AbstractTypeDesc,
    LU_AnestheticLabor.DisplayCode as AnestheticLabor,
    LU_AnestheticLabor.UserDescription as AnestheticLaborDesc,
    AB_Manitoba.Apgar1Min,
    AB_Manitoba.Apgar5Min,
    AB_Manitoba.DeclarationNumber,
    LU_Feeding.DisplayCode as Feeding,
    LU_Feeding.UserDescription as FeedingDesc,
    AB_Manitoba.Gestation,
    AB_Manitoba.Gravida,
    AB_Manitoba.MB_Weight,
    LU_MHInstFrom.DisplayCode as MHInstFrom,
    LU_MHInstFrom.UserDescription as MHInstFromDesc,
    LU_MHInstTo.DisplayCode as MHInstTo,
    LU_MHInstTo.UserDescription as MHInstToDesc,
    AB_Manitoba.NumberPrenatalVisits,
    AB_Manitoba.Parity,
    LU_Presentation.DisplayCode as Presentation,
    LU_Presentation.UserDescription as PresentationDesc,
    AB_UDAbstracting.UDInteger1,
    AB_UDAbstracting.UDInteger2,
    AB_UDAbstracting.UDInteger3,
    AB_Abstract.AbstractID as zzAbstractLink
from AB_Abstract 
    left join AB_Manitoba on AB_Manitoba.AbstractID = AB_Abstract.AbstractID
    left join AB_UDAbstracting on AB_UDAbstracting.AbstractID = AB_Abstract.AbstractID
    left join LU_CodeFile LU_AbstractType on AB_Manitoba.AbstractType = LU_AbstractType.Code
    left join LU_CodeFile LU_AnestheticLabor on AB_Manitoba.AnestheticLabor = LU_AnestheticLabor.Code
    left join LU_CodeFile LU_Feeding on AB_Manitoba.Feeding = LU_Feeding.Code
    left join LU_CodeFile LU_MHInstFrom on AB_Manitoba.MHInstFrom = LU_MHInstFrom.Code
    left join LU_CodeFile LU_MHInstTo on AB_Manitoba.MHInstTo = LU_MHInstTo.Code
    left join LU_CodeFile LU_Presentation on AB_Manitoba.Presentation = LU_Presentation.Code
where AB_Abstract.ICDType <> ''T'' and 
    (AB_Manitoba.AbstractID is not null or AB_UDAbstracting.AbstractID is not null)


--AB_Manitoba	AbstractType
--AB_Manitoba	AnestheticLabor
-- AB_Manitoba	Apgar1Min
-- AB_Manitoba	Apgar5Min
--AB_Manitoba	DeclarationNumber
--AB_Manitoba	Feeding
--AB_Manitoba	Gestation
--AB_Manitoba	Gravida
--AB_Manitoba	MB_Weight
--AB_Manitoba	MHInstFrom
--AB_Manitoba	MHInstTo
--AB_Manitoba	NumberPrenatalVisits
--AB_Manitoba	Parity
--AB_Manitoba	Presentation
--AB_UDAbstracting	UDInteger1
--AB_UDAbstracting	UDInteger2
--AB_UDAbstracting	UDInteger3







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[UD_RelOI_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[UD_RelOI_VR]
AS
SELECT     
    dbo.ROI_UserDefined.UDDate1, dbo.ROI_UserDefined.UDDate2, dbo.ROI_UserDefined.UDDate3, 
    dbo.ROI_UserDefined.UDDate4, dbo.ROI_UserDefined.UDDate5, 
    dbo.ROI_UDFieldsDate.UDDate6,
    dbo.ROI_UDFieldsDate.UDDate7,  dbo.ROI_UDFieldsDate.UDDate8,
    dbo.ROI_UDFieldsDate.UDDate9,  dbo.ROI_UDFieldsDate.UDDate10,
    dbo.ROI_UDFieldsDate.UDDate11,  dbo.ROI_UDFieldsDate.UDDate12,
    dbo.ROI_UDFieldsDate.UDDate13,  dbo.ROI_UDFieldsDate.UDDate14,
    dbo.ROI_UDFieldsDate.UDDate15,  dbo.ROI_UDFieldsDate.UDDate16,
    dbo.ROI_UDFieldsDate.UDDate17,  dbo.ROI_UDFieldsDate.UDDate18,
    dbo.ROI_UDFieldsDate.UDDate19,  dbo.ROI_UDFieldsDate.UDDate20,
    dbo.ROI_UDFieldsDate.UDDate21,  dbo.ROI_UDFieldsDate.UDDate22,
    dbo.ROI_UDFieldsDate.UDDate23,  dbo.ROI_UDFieldsDate.UDDate24,
    dbo.ROI_UDFieldsDate.UDDate25,  
    
    LU_UD1.DisplayCode AS UDLookUp1, LU_UD1.UserDescription AS UDLookUp1Desc, 
    LU_UD2.DisplayCode AS UDLookUp2, LU_UD2.UserDescription AS UDLookUp2Desc, 
    LU_UD3.DisplayCode AS UDLookUp3, LU_UD3.UserDescription AS UDLookUp3Desc, 
    LU_UD4.DisplayCode AS UDLookUp4, LU_UD4.UserDescription AS UDLookUp4Desc, 
    LU_UD5.DisplayCode AS UDLookUp5, LU_UD5.UserDescription AS UDLookUp5Desc, 
    LU_CodeFile_6.DisplayCode AS UDLookUp6, LU_CodeFile_6.UserDescription AS UDLookUp6Desc, 
    LU_CodeFile_7.DisplayCode AS UDLookUp7, LU_CodeFile_7.UserDescription AS UDLookUp7Desc, 
    LU_CodeFile_8.DisplayCode AS UDLookUp8, LU_CodeFile_8.UserDescription AS UDLookUp8Desc, 
    LU_CodeFile_9.DisplayCode AS UDLookUp9, LU_CodeFile_9.UserDescription AS UDLookUp9Desc, 
    LU_CodeFile_10.DisplayCode AS UDLookUp10, LU_CodeFile_10.UserDescription AS UDLookUp10Desc, 
    LU_CodeFile_11.DisplayCode AS UDLookUp11, LU_CodeFile_11.UserDescription AS UDLookUp11Desc, 
    LU_CodeFile_12.DisplayCode AS UDLookUp12, LU_CodeFile_12.UserDescription AS UDLookUp12Desc, 
    LU_CodeFile_13.DisplayCode AS UDLookUp13, LU_CodeFile_13.UserDescription AS UDLookUp13Desc, 
    LU_CodeFile_14.DisplayCode AS UDLookUp14, LU_CodeFile_14.UserDescription AS UDLookUp14Desc, 
    LU_CodeFile_15.DisplayCode AS UDLookUp15, LU_CodeFile_15.UserDescription AS UDLookUp15Desc, 
    LU_CodeFile_16.DisplayCode AS UDLookUp16, LU_CodeFile_16.UserDescription AS UDLookUp16Desc, 
    LU_CodeFile_17.DisplayCode AS UDLookUp17, LU_CodeFile_17.UserDescription AS UDLookUp17Desc, 
    LU_CodeFile_18.DisplayCode AS UDLookUp18, LU_CodeFile_18.UserDescription AS UDLookUp18Desc, 
    LU_CodeFile_19.DisplayCode AS UDLookUp19, LU_CodeFile_19.UserDescription AS UDLookUp19Desc, 
    LU_CodeFile_20.DisplayCode AS UDLookUp20, LU_CodeFile_20.UserDescription AS UDLookUp20Desc, 
    LU_CodeFile_21.DisplayCode AS UDLookUp21, LU_CodeFile_21.UserDescription AS UDLookUp21Desc, 
    LU_CodeFile_22.DisplayCode AS UDLookUp22, LU_CodeFile_22.UserDescription AS UDLookUp22Desc, 
    LU_CodeFile_23.DisplayCode AS UDLookUp23, LU_CodeFile_23.UserDescription AS UDLookUp23Desc, 
    LU_CodeFile_24.DisplayCode AS UDLookUp24, LU_CodeFile_24.UserDescription AS UDLookUp24Desc, 
    LU_CodeFile_25.DisplayCode AS UDLookUp25, LU_CodeFile_25.UserDescription AS UDLookUp25Desc, 

    dbo.ROI_UserDefined.UDInteger1, dbo.ROI_UserDefined.UDInteger2, dbo.ROI_UserDefined.UDInteger3, 
    dbo.ROI_UserDefined.UDInteger4, dbo.ROI_UserDefined.UDInteger5, 
    dbo.ROI_UDFieldsInteger.UDInteger6, 
    dbo.ROI_UDFieldsInteger.UDInteger7, 
    dbo.ROI_UDFieldsInteger.UDInteger8, 
    dbo.ROI_UDFieldsInteger.UDInteger9, 
    dbo.ROI_UDFieldsInteger.UDInteger10, 
    dbo.ROI_UDFieldsInteger.UDInteger11, 
    dbo.ROI_UDFieldsInteger.UDInteger12, 
    dbo.ROI_UDFieldsInteger.UDInteger13, 
    dbo.ROI_UDFieldsInteger.UDInteger14, 
    dbo.ROI_UDFieldsInteger.UDInteger15, 
    dbo.ROI_UDFieldsInteger.UDInteger16, 
    dbo.ROI_UDFieldsInteger.UDInteger17, 
    dbo.ROI_UDFieldsInteger.UDInteger18, 
    dbo.ROI_UDFieldsInteger.UDInteger19, 
    dbo.ROI_UDFieldsInteger.UDInteger20, 
    dbo.ROI_UDFieldsInteger.UDInteger21, 
    dbo.ROI_UDFieldsInteger.UDInteger22, 
    dbo.ROI_UDFieldsInteger.UDInteger23, 
    dbo.ROI_UDFieldsInteger.UDInteger24, 
    dbo.ROI_UDFieldsInteger.UDInteger25, 
    
    dbo.ROI_UserDefined.UDText1, dbo.ROI_UserDefined.UDText2, dbo.ROI_UserDefined.UDText3, 
    dbo.ROI_UserDefined.UDText4, dbo.ROI_UserDefined.UDText5, 
    dbo.ROI_UDFieldsText.UDText6,
    dbo.ROI_UDFieldsText.UDText7,
    dbo.ROI_UDFieldsText.UDText8,
    dbo.ROI_UDFieldsText.UDText9,
    dbo.ROI_UDFieldsText.UDText10,
    dbo.ROI_UDFieldsText.UDText11,
    dbo.ROI_UDFieldsText.UDText12,
    dbo.ROI_UDFieldsText.UDText13,
    dbo.ROI_UDFieldsText.UDText14,
    dbo.ROI_UDFieldsText.UDText15,
    dbo.ROI_UDFieldsText.UDText16,
    dbo.ROI_UDFieldsText.UDText17,
    dbo.ROI_UDFieldsText.UDText18,
    dbo.ROI_UDFieldsText.UDText19,
    dbo.ROI_UDFieldsText.UDText20,
    dbo.ROI_UDFieldsText.UDText21,
    dbo.ROI_UDFieldsText.UDText22,
    dbo.ROI_UDFieldsText.UDText23,
    dbo.ROI_UDFieldsText.UDText24,
    dbo.ROI_UDFieldsText.UDText25,

    dbo.ROI_UserDefined.UDSmallText1, dbo.ROI_UserDefined.UDSmallText2, dbo.ROI_UserDefined.UDSmallText3, 
    dbo.ROI_UserDefined.UDSmallText4, dbo.ROI_UserDefined.UDSmallText5, 
    dbo.ROI_UDFieldsSmallText.UDSmallText6, 
    dbo.ROI_UDFieldsSmallText.UDSmallText7, 
    dbo.ROI_UDFieldsSmallText.UDSmallText8, 
    dbo.ROI_UDFieldsSmallText.UDSmallText9, 
    dbo.ROI_UDFieldsSmallText.UDSmallText10, 
    dbo.ROI_UDFieldsSmallText.UDSmallText11, 
    dbo.ROI_UDFieldsSmallText.UDSmallText12, 
    dbo.ROI_UDFieldsSmallText.UDSmallText13, 
    dbo.ROI_UDFieldsSmallText.UDSmallText14, 
    dbo.ROI_UDFieldsSmallText.UDSmallText15, 
    dbo.ROI_UDFieldsSmallText.UDSmallText16, 
    dbo.ROI_UDFieldsSmallText.UDSmallText17, 
    dbo.ROI_UDFieldsSmallText.UDSmallText18, 
    dbo.ROI_UDFieldsSmallText.UDSmallText19, 
    dbo.ROI_UDFieldsSmallText.UDSmallText20, 
    dbo.ROI_UDFieldsSmallText.UDSmallText21, 
    dbo.ROI_UDFieldsSmallText.UDSmallText22, 
    dbo.ROI_UDFieldsSmallText.UDSmallText23, 
    dbo.ROI_UDFieldsSmallText.UDSmallText24, 
    dbo.ROI_UDFieldsSmallText.UDSmallText25, 

    dbo.ROI_UserDefined.UDTime1, dbo.ROI_UserDefined.UDTime2, 
    dbo.ROI_UserDefined.UDTime3, dbo.ROI_UserDefined.UDTime4, 
    dbo.ROI_UserDefined.UDTime5, 
    dbo.ROI_UDFieldsTime.UDTime6, 
    dbo.ROI_UDFieldsTime.UDTime7, 
    dbo.ROI_UDFieldsTime.UDTime8, 
    dbo.ROI_UDFieldsTime.UDTime9, 
    dbo.ROI_UDFieldsTime.UDTime10, 
    dbo.ROI_UDFieldsTime.UDTime11, 
    dbo.ROI_UDFieldsTime.UDTime12, 
    dbo.ROI_UDFieldsTime.UDTime13, 
    dbo.ROI_UDFieldsTime.UDTime14, 
    dbo.ROI_UDFieldsTime.UDTime15, 
    dbo.ROI_UDFieldsTime.UDTime16, 
    dbo.ROI_UDFieldsTime.UDTime17, 
    dbo.ROI_UDFieldsTime.UDTime18, 
    dbo.ROI_UDFieldsTime.UDTime19, 
    dbo.ROI_UDFieldsTime.UDTime20, 
    dbo.ROI_UDFieldsTime.UDTime21, 
    dbo.ROI_UDFieldsTime.UDTime22, 
    dbo.ROI_UDFieldsTime.UDTime23, 
    dbo.ROI_UDFieldsTime.UDTime24, 
    dbo.ROI_UDFieldsTime.UDTime25, 
    
    dbo.ROI_UserDefined.ROIID AS zzROILink
FROM 
    dbo.ROI_UserDefined with (nolock) LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD1 with (nolock) ON dbo.ROI_UserDefined.UDLookup1 = LU_UD1.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD2 with (nolock) ON dbo.ROI_UserDefined.UDLookup2 = LU_UD2.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD3 with (nolock) ON dbo.ROI_UserDefined.UDLookup3 = LU_UD3.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD4 with (nolock) ON dbo.ROI_UserDefined.UDLookup4 = LU_UD4.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_UD5 with (nolock) ON dbo.ROI_UserDefined.UDLookup5 = LU_UD5.Code LEFT OUTER JOIN
    dbo.ROI_UDFieldsDate with (nolock) ON dbo.ROI_UserDefined.ROIID = dbo.ROI_UDFieldsDate.ROIID LEFT OUTER JOIN
    dbo.ROI_UDFieldsInteger with (nolock) ON dbo.ROI_UserDefined.ROIID = dbo.ROI_UDFieldsInteger.ROIID LEFT OUTER JOIN
    dbo.ROI_UDFieldsLookUp with (nolock) ON dbo.ROI_UserDefined.ROIID = dbo.ROI_UDFieldsLookUp.ROIID LEFT OUTER JOIN
    dbo.ROI_UDFieldsSmallText with (nolock) ON dbo.ROI_UserDefined.ROIID = dbo.ROI_UDFieldsSmallText.ROIID LEFT OUTER JOIN
    dbo.ROI_UDFieldsText with (nolock) ON dbo.ROI_UserDefined.ROIID = dbo.ROI_UDFieldsText.ROIID LEFT OUTER JOIN
    dbo.ROI_UDFieldsTime with (nolock) ON dbo.ROI_UserDefined.ROIID = dbo.ROI_UDFieldsTime.ROIID LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_6 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup6 = LU_CodeFile_6.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_7 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup7 = LU_CodeFile_7.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_8 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup8 = LU_CodeFile_8.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_9 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup9 = LU_CodeFile_9.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_10 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup10 = LU_CodeFile_10.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_11 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup11 = LU_CodeFile_11.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_12 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup12 = LU_CodeFile_12.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_13 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup13 = LU_CodeFile_13.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_14 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup14 = LU_CodeFile_14.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_15 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup15 = LU_CodeFile_15.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_16 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup16 = LU_CodeFile_16.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_17 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup17 = LU_CodeFile_17.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_18 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup18 = LU_CodeFile_18.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_19 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup19 = LU_CodeFile_19.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_20 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup20 = LU_CodeFile_20.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_21 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup21 = LU_CodeFile_21.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_22 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup22 = LU_CodeFile_22.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_23 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup23 = LU_CodeFile_23.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_24 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup24 = LU_CodeFile_24.Code LEFT OUTER JOIN
    dbo.LU_CodeFile LU_CodeFile_25 with (nolock) ON dbo.ROI_UDFieldsLookUp.UDLookup25 = LU_CodeFile_25.Code 



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[UserProfile_UpdateHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[UserProfile_UpdateHistory_VR]
AS
select 
    coder.DisplayCode AS UpdateCoder, 
    coder.UserDescription AS UpdateCoderDesc, 
    H_UpdateHistory.Updated AS UpdateDate,
    RecordID as zzUserLink
from dbo.H_UpdateHistory
    left join dbo.U_Users coder with (nolock) ON H_UpdateHistory.Coder = coder.Code
where appid = 1002
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[UserProfile_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[UserProfile_VR]
AS
SELECT    
    LU_PromptLoc.DisplayCode as AbstractPromptForChartLocator,    --PR - 03882
    LU_PromptDef.DisplayCode as AbstractPromptForChartDeficiency, --PR - 03882

    LU_AccessLockChart.DisplayCode as AccessLockedSourceCharts,   --PR - 03882
 
    LU_YesNoSystem_6.DisplayCode AS AutoCalculate_CACS, LU_YesNoSystem_1.DisplayCode AS AutoCalculate_DPG, 
    LU_YesNoSystem_2.DisplayCode AS AutoCalculate_FIM, LU_YesNoSystem_3.DisplayCode AS AutoCalculate_RUGS, 
    LU_AutoCalculateGrouper.DisplayCode AS AutoCalculateGrouper, LU_AutoCalculateGrouper.UserDescription AS AutoCalculateGrouperDesc, 
    LU_AutoShowCloneVisitList.DisplayCode AS AutoShowCloneVisitList, LU_AutoShowCloneVisitList.UserDescription AS AutoShowCloneVisitListDesc, 
    LU_AutoShowLookUp.DisplayCode AS AutoShowLookUp, LU_AutoShowLookUp.UserDescription AS AutoShowLookUpDesc, 
    LU_CanModifyChart.DisplayCode AS CanModifyChart, LU_CanModifyChart.UserDescription AS CanModifyChartDesc, 
    LU_YesNoSystem_8.DisplayCode AS CanReSetSubmitStatusNACRS, LU_YesNoSystem_4.DisplayCode AS CanReSetSubmitStatusNRS, 
    --PR - 03882
    --LU_YesNoSystem_5.DisplayCode AS CanReSetSubmitStatusCCRS, 
    LU_YesNoSystem_5.DisplayCode AS CanReSetSubmitStatusMDS, 

    LU_YesNoSystem_7.DisplayCode AS CanReSetSubmitStatusOMHRS, 
    dbo.U_Users.PasswordChanged AS ChangePasswordDate, dbo.U_Users.ChangePasswordDays, 
    LU_PermitChartVolume.DisplayCode as ChartVolumes, LU_PermitChartVolume.UserDescription as ChartVolumesDesc,   --PR - 03882
    dbo.U_Users.DisplayCode AS Coder, 
    dbo.U_Users.CIHIValue AS CoderCIHIValue, dbo.U_Users.DefaultDescription AS CoderDefaultDescription, 
    dbo.U_Users.UserDescription AS CoderDescription, dbo.U_Users.FirstName AS CoderFirstName, 
    CoderFullName = isnull(U_Users.FirstName, '''') + rtrim(isnull('' '' + U_Users.MiddleName, '''')) + rtrim(isnull('' '' + U_Users.LastName, '''')), --PR - 03882
    LU_Hospital.DisplayCode AS CoderHospital, LU_Hospital.UserDescription AS CoderHospitalDesc, dbo.U_Users.MiddleName AS CoderMiddleName, 
    dbo.U_Users.LastName AS CoderLastName, 
    dbo.U_Users.UserName AS CoderUsername,  --CoderFullName,  PR - 03882

    LU_DADSepFile.DisplayCode as    CreateDADSeperationFile,    --PR - 03882
    LU_CCRSAuditFile.DisplayCode as CreateMDSAuditFile,         --PR - 03882
    LU_CCRSFacFile.DisplayCode as   CreateMDSFacilityFile,      --PR - 03882
    LU_AmCareFacFile.DisplayCode as CreateNACRSFacilityFile,    --PR - 03882
    LU_RehabFacFile.DisplayCode as  CreateNRSFacilityFile,      --PR - 03882
    LU_OMHRSFacFile.DisplayCode as  CreateOMHRSFacilityFile,    --PR - 03882

    LU_PermitWRUUpdates.DisplayCode as DatabaseUpdateHistory, LU_PermitWRUUpdates.UserDescription as DatabaseUpdateHistoryDesc,       --PR - 03882
    H_HospitalProfile_1.UserDescription AS DefaultHospitalLink, 
    LU_DisplayMultiUserMessage.DisplayCode AS DisplayMultiUserMessage, 
    LU_DisplayMultiUserMessage.UserDescription AS DisplayMultiUserMessageDesc, dbo.U_Users.NTAuthority AS DomainUserName, 
    LU_EnableQuickSearch.DisplayCode AS EnableQuickSearch, LU_EnableQuickSearch.UserDescription AS EnableQuickSearchDesc, 
    dbo.U_Users.FontSize, dbo.H_HospitalProfile.UserDescription AS HospitalLink, 

    LU_ImportDADErrors.DisplayCode as ImportDADCIHIErrorFile,        --PR - 03882
    LU_ImportOMHRSErrors.DisplayCode as ImportOMHRSCIHIErrorFile,    --PR - 03882

    dbo.U_Users.FolioCAFile as FolioDirectory_CA, dbo.U_Users.FolioCCIFile as FolioDirectory_CCI,
   
    dbo.U_Users.InterfaceIn, LU_IsAdmin.DisplayCode AS IsAdministrator, 
    LU_IsAdmin.UserDescription AS IsAdministratorDesc, LU_LanguageCode.DisplayCode AS LanguageCode, 
    LU_LanguageCode.UserDescription AS LanguageCodeDesc, dbo.U_Users.LUText AS LookupNote, 
    --dbo.U_Users.PasswordAttempt, --PR - 03882 No longed used in user profile. Used in hospital profile
    dbo.U_Users.ChangePasswordDate AS PasswordExpiryDate, LU_PermitActivityScheduler.DisplayCode AS PermitActivityScheduler, 
    LU_PermitActivityScheduler.UserDescription AS PermitActivitySchedulerDesc, LU_PermitAmCare10.DisplayCode AS PermitAmCareICD10, 
    LU_PermitAmCare10.UserDescription AS PermitAmCareICD10Desc, LU_PermitAmCareICD9.DisplayCode AS PermitAmCareICD9, 
    LU_PermitAmCareICD9.UserDescription AS PermitAmCareICD9Desc, LU_PermitBatchGrouper.DisplayCode AS PermitBatchGrouper, 
    LU_PermitBatchGrouper.UserDescription AS PermitBatchGrouperDesc, LU_PermitBatchInterface.DisplayCode AS PermitBatchInterface, 
    LU_PermitBatchInterface.UserDescription AS PermitBatchInterfaceDesc, LU_PermitBilling.DisplayCode AS PermitBilling, 
    LU_PermitBilling.UserDescription AS PermitBillingDesc, 

    LU_PermitCCM.DisplayCode as PermitCancerCare,  LU_PermitCCM.UserDescription as PermitCancerCareDesc,      --PR - 03882
    LU_PermitCareMap.DisplayCode AS PermitCareMap, LU_PermitCareMap.UserDescription AS PermitCareMapDesc, 
    --PR - 03882
    --LU_PermitMDS.DisplayCode AS PermitCCRSICD10, LU_PermitMDS.UserDescription AS PermitCCRSICD10Desc, 
    LU_PermitMDS.DisplayCode AS PermitMDS, LU_PermitMDS.UserDescription AS PermitMDSDesc, 

    LU_PermitCIHISubmission.DisplayCode AS PermitCIHISubmission, 
    LU_PermitChartDeficiency.DisplayCode AS PermitChartDeficiency, LU_PermitChartDeficiency.UserDescription AS PermitChartDeficiencyDesc, 
    LU_PermitChartLocation.DisplayCode AS PermitChartLocation, LU_PermitChartLocation.UserDescription AS PermitChartLocationDesc, 
    LU_PermitCIHISubmission.UserDescription AS PermitCIHISubmissionDesc, LU_PermitCIHICorrection.DisplayCode AS PermitCIHICorrection, 
    LU_PermitCIHICorrection.UserDescription AS PermitCIHICorrectionDesc, LU_PermitClinic.DisplayCode AS PermitClinic, 
    LU_PermitClinic.UserDescription AS PermitClinicDesc, LU_PermitControlMaintenance.DisplayCode AS PermitControlMaintenance, 
    LU_PermitControlMaintenance.UserDescription AS PermitControlMaintenanceDesc, LU_PermitCPI.DisplayCode AS PermitCPI, 
    LU_PermitCPI.UserDescription AS PermitCPIDesc, dbo.LU_Permission.DisplayCode AS PermitDAS, 
    LU_PermitInpatientCCRICD10.DisplayCode AS PermitInpatientCCRICD10, 
    LU_PermitInpatientCCRICD10.UserDescription AS PermitInpatientCCRICD10Desc, 
    LU_PermitInpatientCCRICD9.DisplayCode AS PermitInpatientCCRICD9, LU_PermitInpatientCCRICD9.UserDescription AS PermitInpatientCCRICD9Desc, 
    LU_PermitInpatientICD10.DisplayCode AS PermitInpatientICD10, LU_PermitInpatientICD10.UserDescription AS PermitInpatientICD10Desc, 
    LU_PermitInpatientICD9.DisplayCode AS PermitInpatientICD9, LU_PermitInpatientICD9.UserDescription AS PermitInpatientICD9Desc, 
    LU_PermitReportGenerator.DisplayCode AS PermitReportGenerator, LU_PermitReportGenerator.UserDescription AS PermitReportGeneratorDesc, 
    LU_PermitHL7Interface.DisplayCode AS PermitHL7Interface, LU_PermitHL7Interface.UserDescription AS PermitHL7InterfaceDesc, 
    LU_PermitHospitalProfile.DisplayCode AS PermitHospitalProfile, LU_PermitHospitalProfile.UserDescription AS PermitHospitalProfileDesc, 
    LU_PermitInstitutionProfile.DisplayCode AS PermitInstitutionProfile, LU_PermitInstitutionProfile.UserDescription AS PermitInstitutionProfileDesc, 
    LU_PermitLookUpMaintenance.DisplayCode AS PermitLookUpMaintenance, 
    LU_PermitLookUpMaintenance.UserDescription AS PermitLookUpMaintenanceDesc, LU_Permission_2.DisplayCode AS PermitOMHRS, 
    LU_PermitPurgeUndelete.DisplayCode AS PermitPurgeUndelete, LU_PermitPurgeUndelete.UserDescription AS PermitPurgeUndeleteDesc, 
    LU_PermitRehabICD10.DisplayCode AS PermitRehabICD10, LU_PermitRehabICD10.UserDescription AS PermitRehabICD10Desc, 
    LU_PermitROI.DisplayCode AS PermitROI, LU_PermitROI.UserDescription AS PermitROIDesc, LU_PermitSDSICD10.DisplayCode AS PermitSDSICD10, 
    LU_PermitSDSICD10.UserDescription AS PermitSDSICD10Desc, LU_PermitSDSICD9.DisplayCode AS PermitSDSICD9, 
    LU_PermitSDSICD9.UserDescription AS PermitSDSICD9Desc, LU_PermitTranscription.DisplayCode AS PermitTranscription, 
    LU_PermitTranscription.UserDescription AS PermitTranscriptionDesc, LU_PermitUserProfile.DisplayCode AS PermitUserProfile, 
    LU_PermitUserProfile.UserDescription AS PermitUserProfileDesc, LU_Permission_1.DisplayCode AS PermitVisitHistory, 
    LU_CanPurgeVolQue.DisplayCode as PurgeVolumePrintingQueue,   --PR - 03882
    LU_PermitRegionProf.DisplayCode as RegionalProfile, LU_PermitRegionProf.DisplayCode as RegionalProfileDesc,     --PR - 03882
    LU_ROLEID.DisplayCode AS RoleID, LU_ROLEID.UserDescription AS RoleIDDesc, dbo.U_Users.SearchChartPrefix, 

    LU_ShowAllRegion.DisplayCode as ShowAllRegionalData,         --PR - 03882
    LU_DisplayChrtLinks.DisplayCode as ShowChartLinkages,        --PR - 03882
    LU_CanSubmitCCM.DisplayCode as ShowCompleteCancerCare,       --PR - 03882
    --PR - 03882
    --LU_ShowCompleteAbscareICD10_1.DisplayCode AS ShowCompleteAbscareICD10,  LU_ShowCompleteAbscareICD10_1.UserDescription AS ShowCompleteAbscareICD10Desc, 
    LU_ShowCompleteAbscareICD10_1.DisplayCode AS ShowCompleteInpatientICD10,  LU_ShowCompleteAbscareICD10_1.UserDescription AS ShowCompleteInpatientICD10Desc, 

    LU_ShowCompleteAbscareICD9.DisplayCode AS ShowCompleteAbscareICD9, 
    LU_ShowCompleteAbscareICD9.UserDescription AS ShowCompleteAbscareICD9Desc, 
    LU_ShowCompleteAmcareICD10.DisplayCode AS ShowCompleteAmcareICD10, 
    LU_ShowCompleteAmcareICD10.UserDescription AS ShowCompleteAmcareICD10Desc, 
    LU_ShowCompleteAmcareICD9.DisplayCode AS ShowCompleteAmCareICD9, 
    LU_ShowCompleteAmcareICD9.UserDescription AS ShowCompleteAmCareICD9Desc, 
    --PR - 03882
    --LU_ShowCompleteMDS.DisplayCode AS ShowCompleteCCRSICD10, LU_ShowCompleteMDS.UserDescription AS ShowCompleteCCRSICD10Desc, 
    LU_ShowCompleteMDS.DisplayCode AS ShowCompleteMDS, LU_ShowCompleteMDS.UserDescription AS ShowCompleteMDSDesc, 

    LU_ShowCompleteClinic.DisplayCode AS ShowCompleteClinic, 
    LU_ShowCompleteClinic.UserDescription AS ShowCompleteClinicDesc, dbo.LU_YesNoSystem.DisplayCode AS ShowCompleteOMHRS, 
    dbo.LU_YesNoSystem.UserDescription AS ShowCompleteOMHRSDesc, LU_ShowCompleteRehabICD10.DisplayCode AS ShowCompleteRehabICD10, 
    LU_ShowCompleteRehabICD10.UserDescription AS ShowCompleteRehabICD10Desc, 
    LU_ShowCompleteSDSICD10.DisplayCode AS ShowCompleteSDSICD10, 
    LU_ShowCompleteSDSICD10.UserDescription AS ShowCompleteSDSICD10Desc, LU_ShowCompleteSDSICD9.DisplayCode AS ShowCompleteSDSICD9, 
    LU_ShowCompleteSDSICD9.UserDescription AS ShowCompleteSDSICD9Desc, LU_ShowMessages.DisplayCode AS ShowMessages, 
    LU_ShowMessages.UserDescription AS ShowMessagesDesc, 
    --PR - 05814
    LU_ShowConfidentialRequest.DisplayCode as ShowConfidentialRequest,  LU_ShowConfidentialRequest.UserDescription as ShowConfidentialRequestDesc, 
    
    LU_ShowVIPChart.DisplayCode AS ShowVIPChart, 
    LU_ShowVIPChart.UserDescription AS ShowVIPChartDesc, 
    LU_SkipLoginScreen.DisplayCode as SkipLoginScreen, LU_SkipLoginScreen.UserDescription as SkipLoginScreenDesc, 
    
    LU_ExecTermChrt.DisplayCode as SetChartTerminalDigit,        --PR - 03882
    dbo.U_Users.TransInitials AS TranscriptionInitials, 
    LU_UserDateFormat.DisplayCode AS UserDateFormat, dbo.U_Users.ValidFrom, dbo.U_Users.ValidTo,


    LU_PermitViewChartAct.DisplayCode as ViewChartActivity,  LU_PermitViewChartAct.UserDescription as ViewChartActivityDesc,    --PR - 03882
    LU_PermitViewChartDef.DisplayCode as ViewChartDeficiency, LU_PermitViewChartDef.UserDescription as ViewChartDeficiencyDesc,  --PR - 03882
    LU_CanViewWho.DisplayCode AS ViewLoggedInUsers, --PR - 03882
    U_Users.code as zzUserLink
FROM dbo.U_Users with (nolock) LEFT OUTER JOIN
    dbo.LU_YesNoSystem with (nolock) on dbo.U_Users.CanSubmitM10 = dbo.LU_YesNoSystem.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_Permission_1 with (nolock) on dbo.U_Users.PermitVisitHist = LU_Permission_1.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_Permission_2 with (nolock) on dbo.U_Users.PermitOMHRS10 = LU_Permission_2.Code LEFT OUTER JOIN
    dbo.LU_Permission with (nolock) on dbo.U_Users.PermitDAS = dbo.LU_Permission.Code LEFT OUTER JOIN
    dbo.H_HospitalProfile with (nolock) on dbo.U_Users.HospitalID = dbo.H_HospitalProfile.Code LEFT OUTER JOIN
    dbo.H_HospitalProfile AS H_HospitalProfile_1 with (nolock) on dbo.U_Users.DefaultHospID = H_HospitalProfile_1.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_YesNoSystem_7 with (nolock) on dbo.U_Users.CanReSetM = LU_YesNoSystem_7.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_YesNoSystem_5 with (nolock) on dbo.U_Users.CanReSetC = LU_YesNoSystem_5.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_YesNoSystem_4 with (nolock) on dbo.U_Users.CanReSetR = LU_YesNoSystem_4.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_YesNoSystem_8 with (nolock) on dbo.U_Users.CanReSetA = LU_YesNoSystem_8.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_YesNoSystem_3 with (nolock) on dbo.U_Users.FlyCalcRUG = LU_YesNoSystem_3.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_YesNoSystem_2 with (nolock) on dbo.U_Users.FlyCalcFIM = LU_YesNoSystem_2.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_YesNoSystem_1 with (nolock) on dbo.U_Users.FlyCalcDPG = LU_YesNoSystem_1.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_YesNoSystem_6 with (nolock) on dbo.U_Users.FlyCalcCACS = LU_YesNoSystem_6.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_ShowCompleteMDS with (nolock) on dbo.U_Users.CanSubmitC10 = LU_ShowCompleteMDS.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_ShowCompleteAmcareICD10 with (nolock) on dbo.U_Users.CanSubmitA10 = LU_ShowCompleteAmcareICD10.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_DisplayMultiUserMessage with (nolock) on dbo.U_Users.DisplayMultUser = LU_DisplayMultiUserMessage.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_AutoCalculateGrouper with (nolock) on dbo.U_Users.FlyCalcGrouper = LU_AutoCalculateGrouper.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_CanModifyChart with (nolock) on dbo.U_Users.CanModifyCharts = LU_CanModifyChart.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_ShowVIPChart with (nolock) on dbo.U_Users.ShowVIP = LU_ShowVIPChart.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_EnableQuickSearch with (nolock) on dbo.U_Users.EnableQuickSearch = LU_EnableQuickSearch.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_ShowCompleteCCRS10 with (nolock) on dbo.U_Users.CanSubmitC10 = LU_ShowCompleteCCRS10.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitMDS with (nolock) on dbo.U_Users.PermitCCRS10 = LU_PermitMDS.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_AutoShowCloneVisitList with (nolock) on dbo.U_Users.AutoShowClone = LU_AutoShowCloneVisitList.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_AutoShowLookUp with (nolock) on dbo.U_Users.AutoShowLookUp = LU_AutoShowLookUp.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitActivityScheduler with (nolock) on dbo.U_Users.PermitScheduler = LU_PermitActivityScheduler.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_ShowCompleteClinic with (nolock) on dbo.U_Users.CanSubmitCL = LU_ShowCompleteClinic.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitBilling with (nolock) on dbo.U_Users.PermitBilling = LU_PermitBilling.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitClinic with (nolock) on dbo.U_Users.PermitClinic = LU_PermitClinic.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_ShowCompleteRehabICD10 with (nolock) on dbo.U_Users.CanSubmitR10 = LU_ShowCompleteRehabICD10.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitRehabICD10 with (nolock) on dbo.U_Users.PermitRehab10 = LU_PermitRehabICD10.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_ShowCompleteSDSICD10 with (nolock) on dbo.U_Users.CanSubmitS10 = LU_ShowCompleteSDSICD10.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_ShowCompleteAbscareICD10_1 with (nolock) on dbo.U_Users.CanSubmitI10 = LU_ShowCompleteAbscareICD10_1.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitAmCare10 with (nolock) on dbo.U_Users.PermitAmcare10 = LU_PermitAmCare10.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitInpatientICD10 with (nolock) on dbo.U_Users.PermitInPat10 = LU_PermitInpatientICD10.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitSDSICD10 with (nolock) on dbo.U_Users.PermitSDS10 = LU_PermitSDSICD10.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitInpatientCCRICD10 with (nolock) on dbo.U_Users.PermitCCR10 = LU_PermitInpatientCCRICD10.Code LEFT OUTER JOIN
    dbo.U_Users AS LU_ROLEID with (nolock) on dbo.U_Users.RoleID = LU_ROLEID.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitControlMaintenance with (nolock) on dbo.U_Users.PermitControlFile = LU_PermitControlMaintenance.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitLookUpMaintenance with (nolock) on dbo.U_Users.PermitLookUpMaint = LU_PermitLookUpMaintenance.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitUserProfile with (nolock) on dbo.U_Users.PermitUserProf = LU_PermitUserProfile.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitInstitutionProfile with (nolock) on dbo.U_Users.PermitInstProf = LU_PermitInstitutionProfile.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitHospitalProfile with (nolock) on dbo.U_Users.PermitHospProf = LU_PermitHospitalProfile.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitPurgeUndelete with (nolock) on dbo.U_Users.PermitUndelete = LU_PermitPurgeUndelete.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitHL7Interface with (nolock) on dbo.U_Users.PermitHL7Interface = LU_PermitHL7Interface.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitBatchInterface with (nolock) on dbo.U_Users.PermitBatchInterface = LU_PermitBatchInterface.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitCIHICorrection with (nolock) on dbo.U_Users.PermitCIHICorrect = LU_PermitCIHICorrection.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitCIHISubmission with (nolock) on dbo.U_Users.PermitCIHISubmit = LU_PermitCIHISubmission.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitReportGenerator with (nolock) on dbo.U_Users.PermitReportGen = LU_PermitReportGenerator.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitCareMap with (nolock) on dbo.U_Users.PermitCareMap = LU_PermitCareMap.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitBatchGrouper with (nolock) on dbo.U_Users.PermitBatchGrouper = LU_PermitBatchGrouper.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitAmCareICD9 with (nolock) on dbo.U_Users.PermitAmcare = LU_PermitAmCareICD9.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitSDSICD9 with (nolock) on dbo.U_Users.PermitSDS = LU_PermitSDSICD9.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitInpatientICD9 with (nolock) on dbo.U_Users.PermitInPat = LU_PermitInpatientICD9.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitInpatientCCRICD9 with (nolock) on dbo.U_Users.PermitCCR = LU_PermitInpatientCCRICD9.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitROI with (nolock) on dbo.U_Users.PermitROI = LU_PermitROI.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitTranscription with (nolock) on dbo.U_Users.PermitTranscription = LU_PermitTranscription.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitChartDeficiency with (nolock) on dbo.U_Users.PermitChartDef = LU_PermitChartDeficiency.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitChartLocation with (nolock) on dbo.U_Users.PermitChartLoc = LU_PermitChartLocation.Code LEFT OUTER JOIN
    dbo.LU_Permission AS LU_PermitCPI with (nolock) on dbo.U_Users.PermitCPI = LU_PermitCPI.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_ShowMessages with (nolock) on dbo.U_Users.DisplayMessages = LU_ShowMessages.Code LEFT OUTER JOIN
    dbo.LU_SystemLanguage AS LU_LanguageCode with (nolock) on dbo.U_Users.LanguageID = LU_LanguageCode.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_ShowCompleteAmcareICD9 with (nolock) on dbo.U_Users.CanSubmitA = LU_ShowCompleteAmcareICD9.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_ShowCompleteAbscareICD9 with (nolock) on dbo.U_Users.CanSubmitI = LU_ShowCompleteAbscareICD9.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_ShowCompleteSDSICD9 with (nolock) on dbo.U_Users.CanSubmitS = LU_ShowCompleteSDSICD9.Code LEFT OUTER JOIN
    dbo.LU_YesNoSystem AS LU_IsAdmin with (nolock) on dbo.U_Users.IsAdmin = LU_IsAdmin.Code LEFT OUTER JOIN
    dbo.H_HospitalProfile AS LU_Hospital with (nolock) on (CASE WHEN isnull(dbo.U_Users.HospitalID, 0) = 0 THEN dbo.U_Users.DefaultHospID ELSE dbo.U_Users.HospitalID END) = LU_Hospital.Code LEFT OUTER JOIN
    dbo.LU_CodeFile AS LU_UserDateFormat with (nolock) on dbo.U_Users.UserDateFormat = LU_UserDateFormat.Code Left Join
    --PR - 03882
    dbo.LU_YesNoSystem as LU_CanViewWho with (nolock) on LU_CanViewWho.Code = U_Users.CanViewWho Left Join
    dbo.LU_YesNoSystem as LU_AccessLockChart with (nolock) on LU_AccessLockChart.Code = U_Users.AccessLockChart Left Join
    dbo.LU_YesNoSystem as LU_PromptLoc with (nolock) on LU_PromptLoc.Code = U_Users.PromptLoc Left Join
    dbo.LU_YesNoSystem as LU_PromptDef with (nolock) on LU_PromptDef.Code = U_Users.PromptDef Left Join
    dbo.LU_YesNoSystem as LU_AmCareFacFile with (nolock) on LU_AmCareFacFile.Code = U_Users.AmCareFacFile Left Join
    dbo.LU_YesNoSystem as LU_CCRSFacFile with (nolock) on LU_CCRSFacFile.Code = U_Users.CCRSFacFile Left Join
    dbo.LU_YesNoSystem as LU_RehabFacFile with (nolock) on LU_RehabFacFile.Code = U_Users.RehabFacFile Left Join
    dbo.LU_YesNoSystem as LU_OMHRSFacFile with (nolock) on LU_OMHRSFacFile.Code = U_Users.OMHRSFacFile Left Join
    dbo.LU_YesNoSystem as LU_DADSepFile with (nolock) on LU_DADSepFile.Code = U_Users.DADSepFile Left Join
    dbo.LU_YesNoSystem as LU_CCRSAuditFile with (nolock) on LU_CCRSAuditFile.Code = U_Users.CCRSAuditFile Left Join
    dbo.LU_YesNoSystem as LU_ImportDADErrors with (nolock) on LU_ImportDADErrors.Code = U_Users.ImportDADErrors Left Join
    dbo.LU_YesNoSystem as LU_ImportOMHRSErrors with (nolock) on LU_ImportOMHRSErrors.Code = U_Users.ImportOMHRSErrors Left Join
    dbo.LU_YesNoSystem as LU_ExecTermChrt with (nolock) on LU_ExecTermChrt.Code = U_Users.ExecTermChrt Left Join
    dbo.LU_YesNoSystem as LU_ShowAllRegion with (nolock) on LU_ShowAllRegion.Code = U_Users.ShowAllRegion Left Join
    dbo.LU_YesNoSystem as LU_CanPurgeVolQue with (nolock) on LU_CanPurgeVolQue.Code = U_Users.CanPurgeVolQue Left Join
    dbo.LU_YesNoSystem as LU_CanSubmitCCM with (nolock) on LU_CanSubmitCCM.Code = U_Users.CanSubmitCCM Left Join
    dbo.LU_YesNoSystem as LU_DisplayChrtLinks with (nolock) on LU_DisplayChrtLinks.Code = U_Users.DisplayChrtLinks Left Join
    dbo.LU_Permission as LU_PermitChartVolume with (nolock) on LU_PermitChartVolume.Code = U_Users.PermitChartVolume Left Join
    dbo.LU_Permission as LU_PermitViewChartAct with (nolock) on LU_PermitViewChartAct.Code = U_Users.PermitViewChartAct Left Join
    dbo.LU_Permission as LU_PermitViewChartDef with (nolock) on LU_PermitViewChartDef.Code = U_Users.PermitViewChartDef Left Join
    dbo.LU_Permission as LU_PermitCCM with (nolock) on LU_PermitCCM.Code = U_Users.PermitCCM Left Join
    dbo.LU_Permission as LU_PermitWRUUpdates with (nolock) on LU_PermitWRUUpdates.Code = U_Users.PermitWRUUpdates Left Join
    dbo.LU_Permission as LU_PermitRegionProf with (nolock) on LU_PermitRegionProf.Code = U_Users.PermitRegionProf Left Join
    dbo.LU_YesNoSystem as LU_ShowConfidentialRequest with (nolock) on LU_ShowConfidentialRequest.Code = U_Users.ShowConfidentialRequest left join
    dbo.LU_YesNoSystem as LU_SkipLoginScreen on LU_SkipLoginScreen.Code = U_Users.SkipLoginScreen
WHERE     (dbo.U_Users.Code NOT IN (1, 2, 55555, 77777, 88888, 99999))
--PR - 07485
    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or U_Users.HospitalID is null or U_Users.HospitalID = 0
--EN - 00666
        or Is_Member(nullif(H_HospitalProfile.ReportGroup, '''')) = 1
        or Is_Member(nullif(H_HospitalProfile_1.ReportGroup, '''')) = 1)
--        or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(U_Users.HospitalID, 0))


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[View_Report_Dictionary]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'





create view [dbo].[View_Report_Dictionary]
AS

select top 100 percent
    ViewName  = c.table_name,  
    FieldName = c.column_name,
    DataType  = c.data_type + case when character_maximum_length is not null then ''('' + ltrim(str(character_maximum_length)) + '')'' else '''' end
from information_schema.columns c 
join information_schema.tables  t on c.table_name = t.table_name
where 
    t.table_type = ''view''
    and 
    t.table_name like ''%[_]VR''
order by c.table_name, c.column_name







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ViewsStructure_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[ViewsStructure_VR]
AS
SELECT     TOP 100 PERCENT Table_Name AS View_Name, Column_Name, Data_Type, character_Maximum_Length AS CharacterLength
FROM         information_schema.columns
WHERE     (table_name IN
      (SELECT     table_name
        FROM          INFORMATION_SCHEMA.views)) AND ((table_name LIKE ''%[_]VR'') 
        or Table_Name in (''I10_Abstracting'', ''I10_AmcareCIHIErrors'', ''I9_Abstract_And_Projects'', ''I10_CMG_2002Percentile'',
            ''Sec_SubmissionAudit'', ''View_Report_Dictionary''))
ORDER BY Table_name, column_name


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[VisitHistory_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[VisitHistory_VR]
AS
SELECT     
    dbo.AB_Main.AdmitDate, dbo.AB_Main.AdmitTime, dbo.LU_NurseArea.DisplayCode AS AdmittingNurseArea, 
    dbo.LU_NurseArea.UserDescription AS AdmittingNurseAreaDesc, dbo.LU_Provider.DisplayCode AS AttendingPhysician, 
    dbo.LU_Provider.UserDescription AS AttendingPhysicianDesc, dbo.AB_Main.Birthdate, dbo.LU_CareType.DisplayCode AS CareType, 
    dbo.LU_CareType.UserDescription AS CareTypeDesc, dbo.AB_Main.ChartNumber, LU_DeathIndicator.DisplayCode AS DeathIndicator, 
    LU_DeathIndicator.UserDescription AS DeathIndicatorDesc, dbo.AB_Main.DischargeDate, dbo.AB_Main.DischargeTime, 
    dbo.AB_Main.EncounterNumber, dbo.AB_Main.EncounterSequence,
    FixedChartNumber,
    dbo.LU_Gender_I.DisplayCode AS Gender, 
    dbo.LU_Gender_I.UserDescription AS GenderDesc, LU_YesBlank_1.DisplayCode AS HasTranscription, dbo.LU_YesBlank.DisplayCode AS HasDAS, 
    dbo.AB_Main.HealthCareNumber, dbo.AB_Main.ICDType, dbo.H_HospitalProfile.DisplayCode AS Hospital, 
    dbo.H_HospitalProfile.UserDescription AS HospitalDesc, 
    dbo.AB_Main.HospitalAccountRecord,
    dbo.ICD_DiagFile10.DisplayCode AS ICD10_DiagnosisCode, dbo.ICD_DiagFile10.UserDescription AS ICD10_DiagnosisCodeDesc, 
    dbo.ICD_ProcFile10.DisplayCode AS ICD10_InterventionCode, dbo.ICD_ProcFile10.UserDescription AS ICD10_InterventionCodeDesc, 

    dbo.ICD_DiagFile9.DisplayCode AS ICD9_DiagnosisCode, dbo.ICD_DiagFile9.UserDescription AS ICD9_DiagnosisCodeDesc, 
    dbo.ICD_ProcFile9.DisplayCode AS ICD9_InterventionCode, dbo.ICD_ProcFile9.UserDescription AS ICD9_InterventionCodeDesc, 

    dbo.ICD_DiagFile9cm.DisplayCode AS ICD9cm_DiagnosisCode, dbo.ICD_DiagFile9cm.UserDescription AS ICD9cm_DiagnosisCodeDesc, 
    dbo.ICD_ProcFile9cm.DisplayCode AS ICD9cm_InterventionCode, dbo.ICD_ProcFile9cm.UserDescription AS ICD9cm_InterventionCodeDesc, 

    dbo.H_InstitutionProfile.DisplayCode AS InstNumber, 
    dbo.H_InstitutionProfile.UserDescription AS InstNumberDesc, LU_AbstractStatus_1.DisplayCode AS IsValidated, 
    LU_AbstractStatus_1.UserDescription AS IsValidatedDesc, dbo.LU_PatientService.DisplayCode AS MainPatientService, 
    dbo.LU_PatientService.UserDescription AS MainPatientServiceDesc, 
    --PR - 02423
    (case when ab_main.AppType in (1, 2, 5) then LU_MainProvider.DisplayCode 
          when ab_main.AppType = 4 then LU_CCRSProvider.DisplayCode
          when ab_main.AppType = 3 then LU_RehabProvider.DisplayCode
          when ab_main.AppType = 7 then LU_OMHRSProvider.DisplayCode
    end) AS MainProviderNumber, 
    (case when ab_main.AppType in (1, 2, 5) then LU_MainProvider.UserDescription 
          when ab_main.AppType = 4 then LU_CCRSProvider.UserDescription
          when ab_main.AppType = 3 then LU_RehabProvider.UserDescription
          when ab_main.AppType = 7 then LU_OMHRSProvider.UserDescription
    end) AS MainProviderNumberDesc, 

    -- LU_MainProvider.DisplayCode AS MainProviderNumber,        LU_MainProvider.UserDescription AS MainProviderNumberDesc, 
    -- LU_CCRSProvider.DisplayCode AS MainProviderNumber_CCRS,   LU_CCRSProvider.UserDescription AS MainProviderNumberDesc_CCRS, 
    -- LU_OMHRSProvider.DisplayCode AS MainProviderNumber_OMHRS, LU_OMHRSProvider.UserDescription AS MainProviderNumberDEsc_OMHRS, 
    -- LU_RehabProvider.DisplayCode AS MainProviderNumber_Rehab, LU_RehabProvider.UserDescription AS MainProviderNumberDesc_Rehab, 

    LU_MISCode.DisplayCode as MISCode, LU_MISCode.UserDescription as MISCodeDesc,

    dbo.LU_AppIDs.UserDescription AS ModuleName, 
    dbo.AB_Main.FirstName AS NameFirst, ISNULL(dbo.AB_Main.LastName, '' '') + '', '' + ISNULL(dbo.AB_Main.FirstName, '''') 
    + '' '' + ISNULL(dbo.AB_Main.MiddleName, '''') AS NameFull, dbo.AB_Main.LastName AS NameLast, dbo.AB_Main.MaidenName AS NameMaiden, 
    dbo.AB_Main.MiddleName AS NameMiddle, dbo.AB_Main.NewbornChart, dbo.LU_PatientType.DisplayCode AS PatientType, 
    dbo.LU_PatientType.UserDescription AS PatientTypeDesc, LU_Provider_1.DisplayCode AS ReferringProvider, 
    LU_Provider_1.UserDescription AS ReferringProviderDesc, dbo.AB_Main.RegisterNumber, dbo.AB_Main.SecondChartRegNumber, 
    dbo.LU_AbstractStatus.DisplayCode AS Satus, dbo.LU_AbstractStatus.UserDescription AS StatusDesc, 
    
    dbo.AB_Main.RegionalPatientID, --PR - 5543
	dbo.AB_Main.UniversalEpisodeIdentifier,
    dbo.AB_Main.VisitDate, dbo.AB_Main.VisitTime, --PR - 05192
    dbo.AB_Main.AbstractID AS zzAbstractLink, 
    dbo.AB_Main.PatientID AS zzPatientLink, dbo.AB_Main.VolumeID AS zzVolumeLink, dbo.AB_Main.UniversalID AS zzUniversalLink
FROM         
    dbo.AB_Main with (nolock) left join
    dbo.RH_Provider with (nolock) on dbo.RH_Provider.AbstractID = dbo.AB_Main.AbstractID AND dbo.RH_Provider.ProviderOccurrence = 1 and AppType = 3 LEFT OUTER JOIN
    dbo.LU_Provider LU_RehabProvider with (nolock) on dbo.RH_Provider.ProviderNumber = LU_RehabProvider.Code LEFT OUTER JOIN

    
    dbo.OMHRS_Provider with (nolock) on dbo.AB_Main.AbstractID = dbo.OMHRS_Provider.AbstractID AND dbo.OMHRS_Provider.ProviderOccurrence = 1 and AppType = 7 LEFT OUTER JOIN
    dbo.LU_Provider LU_OMHRSProvider with (nolock) on  LU_OMHRSProvider.Code = dbo.OMHRS_Provider.ProviderNumber LEFT OUTER JOIN
    
    dbo.CRS_Signature with (nolock) on dbo.AB_Main.AbstractID = dbo.CRS_Signature.AbstractID AND dbo.CRS_Signature.ProviderOccurrence = 1 and AppType = 4 LEFT OUTER JOIN
    dbo.LU_Provider LU_CCRSProvider with (nolock) on LU_CCRSProvider.Code = dbo.CRS_Signature.ProviderNumber LEFT OUTER JOIN
    
    dbo.AB_PatientService with (nolock) on dbo.AB_Main.AbstractID = dbo.AB_PatientService.AbstractID AND dbo.AB_PatientService.ServiceOccurrence = 1 and AppType in (1, 2, 5) LEFT OUTER JOIN
    dbo.LU_PatientService with (nolock) on dbo.LU_PatientService.Code = dbo.AB_PatientService.PatientService LEFT OUTER JOIN
    
     
    dbo.AB_Provider with (nolock) on dbo.AB_Main.AbstractID = dbo.AB_Provider.AbstractID AND 
        dbo.AB_Provider.ProviderOccurrence = 1 and AppType in (1, 2, 5) LEFT OUTER JOIN
    dbo.LU_Provider LU_MainProvider on LU_MainProvider.Code = dbo.AB_Provider.ProviderNumber LEFT OUTER JOIN
        
    dbo.LU_YesNoSystem LU_DeathIndicator with (nolock) on dbo.AB_Main.DeathIndicator = LU_DeathIndicator.Code LEFT OUTER JOIN
    dbo.LU_PatientType with (nolock) on dbo.AB_Main.PatientType = dbo.LU_PatientType.Code LEFT OUTER JOIN
    dbo.H_HospitalProfile with (nolock) on dbo.AB_Main.HospitalID = dbo.H_HospitalProfile.Code LEFT OUTER JOIN
    dbo.LU_Provider LU_Provider_1 with (nolock) on dbo.AB_Main.RefPhysician = LU_Provider_1.Code LEFT OUTER JOIN
    dbo.ICD_ProcFile9 with (nolock) on dbo.AB_Main.IntervCode = dbo.ICD_ProcFile9.Code AND dbo.AB_Main.ICDType = ''9'' LEFT OUTER JOIN
    dbo.ICD_ProcFile10 with (nolock) on dbo.AB_Main.IntervCode = dbo.ICD_ProcFile10.Code AND dbo.AB_Main.ICDType = ''T'' LEFT OUTER JOIN
    dbo.ICD_ProcFile9cm with (nolock) on dbo.AB_Main.IntervCode = dbo.ICD_ProcFile9cm.Code AND dbo.AB_Main.ICDType = ''C'' LEFT OUTER JOIN
    dbo.ICD_DiagFile9cm with (nolock) on dbo.ICD_DiagFile9cm.Code = dbo.AB_Main.DiagnosisCode AND dbo.AB_Main.ICDType = ''C'' LEFT OUTER JOIN
    dbo.ICD_DiagFile10 with (nolock) on dbo.AB_Main.DiagnosisCode = dbo.ICD_DiagFile10.Code AND dbo.AB_Main.ICDType = ''T'' LEFT OUTER JOIN
    dbo.ICD_DiagFile9 with (nolock) on dbo.AB_Main.DiagnosisCode = dbo.ICD_DiagFile9.Code AND dbo.AB_Main.ICDType = ''9'' LEFT OUTER JOIN
    dbo.LU_Provider with (nolock) on dbo.AB_Main.AttendingPhysician = dbo.LU_Provider.Code LEFT OUTER JOIN
    dbo.LU_NurseArea with (nolock) on dbo.AB_Main.AdmittingNurseArea = dbo.LU_NurseArea.Code LEFT OUTER JOIN
    dbo.LU_AbstractStatus LU_AbstractStatus_1 with (nolock) on dbo.AB_Main.IsValidated = LU_AbstractStatus_1.Code LEFT OUTER JOIN
    dbo.LU_Gender_I with (nolock) on dbo.LU_Gender_I.Code = dbo.AB_Main.Gender LEFT OUTER JOIN
    dbo.LU_YesBlank with (nolock) on dbo.AB_Main.HasDAS = dbo.LU_YesBlank.Code LEFT OUTER JOIN
    dbo.LU_MISCode with (nolock) on dbo.LU_MISCode.Code = dbo.AB_Main.MISCode LEFT OUTER JOIN
    dbo.H_InstitutionProfile with (nolock) on dbo.AB_Main.InstitutionNumber = dbo.H_InstitutionProfile.Code LEFT OUTER JOIN
    dbo.LU_YesBlank LU_YesBlank_1 with (nolock) on LU_YesBlank_1.Code = dbo.AB_Main.HasTrans LEFT OUTER JOIN
    dbo.LU_AbstractStatus with (nolock) on dbo.AB_Main.IsCompleted = dbo.LU_AbstractStatus.Code LEFT OUTER JOIN
    dbo.LU_CareType with (nolock) on dbo.LU_CareType.Code = dbo.AB_Main.AppType LEFT OUTER JOIN
    dbo.LU_AppIDs with (nolock) on dbo.AB_Main.AppID = dbo.LU_AppIDs.Code
WHERE     (dbo.AB_Main.IsDeleted = 2)
--QA - 00032 disable the domain securite issue
----PR - 07485
--    and (Suser_Sname() in (''MED2020Main'', ''WinRecs'') or AB_Main.HospitalID is null or AB_Main.HospitalID = 0
--    --EN - 00666
--        or Is_Member(nullif(ReportGroup, '''')) = 1)
----        or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(AB_Main.HospitalID, 0))



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[WorkloadMeasurement_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[WorkloadMeasurement_VR]
AS
SELECT     TOP 100 PERCENT dbo.U_AppIDs.ModuleName, dbo.LU_CodeFile.DisplayCode AS OptionType, dbo.LU_CodeFile.UserDescription AS OptionTypeDesc, 
                      dbo.WM_WorkLoad.OpTime AS OptionTime, dbo.WM_WorkLoad.OpLen AS OptionLength, dbo.WM_WorkLoad.OpID AS RecordOPID, 
                      dbo.WM_WorkLoad.LogID AS SessionID, dbo.U_Users.DisplayCode AS UserName, dbo.U_Users.UserDescription AS UserNameDesc, 
                      dbo.AB_Main.UniversalID AS zzUniversalID
FROM  dbo.U_Users with (nolock) INNER JOIN
      dbo.WM_WorkLoad with (nolock) ON dbo.U_Users.Code = dbo.WM_WorkLoad.UserID LEFT OUTER JOIN
      dbo.U_AppIDs with (nolock) ON dbo.U_AppIDs.AppID = dbo.WM_WorkLoad.AppID LEFT OUTER JOIN
      dbo.LU_CodeFile with (nolock) ON dbo.WM_WorkLoad.OpType = dbo.LU_CodeFile.Code LEFT OUTER JOIN
      dbo.AB_Main with (nolock) ON dbo.WM_WorkLoad.AppID = dbo.AB_Main.AppID AND dbo.WM_WorkLoad.LinkID = dbo.AB_Main.AbstractID LEFT OUTER JOIN
      dbo.H_HospitalProfile with (nolock) ON dbo.U_Users.HospitalID = dbo.H_HospitalProfile.Code 
--QA - 00032 disable the domain securite issue
----PR - 07485
--where Suser_Sname() in (''MED2020Main'', ''WinRecs'') or U_Users.HospitalID is null or U_Users.HospitalID = 0
----EN - 00666
--    or Is_Member(nullif(ReportGroup, '''')) = 1
----    or (select isnull(HospitalID, 0) from U_Users where NTAuthority = Suser_Sname()) in (0, isnull(U_Users.HospitalID, 0))
ORDER BY dbo.WM_WorkLoad.LogID, dbo.WM_WorkLoad.OpTime




' 
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_And_Providers_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_And_Providers_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_And_Project_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_And_Project_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_And_Intervention_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_And_Intervention_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_And_Interrupt_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_And_Interrupt_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_And_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[Rehab_And_Diagnosis_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_UpdateRecord_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_UpdateRecord_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_Signature_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Quarterly_Assessment_Signature_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_Rugs_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Quarterly_Assessment_Rugs_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_RAP_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Quarterly_Assessment_RAP_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_Medication_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Quarterly_Assessment_Medication_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_Diagnosis_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Quarterly_Assessment_Diagnosis_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_6_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Quarterly_Assessment_6_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_5_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Quarterly_Assessment_5_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_4_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Quarterly_Assessment_4_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_3_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Quarterly_Assessment_3_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_2_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Quarterly_Assessment_2_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_1_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Quarterly_Assessment_1_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quality_Indicators_ByYear_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Quality_Indicators_ByYear_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quality_Indicators_ByQuarter_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Quality_Indicators_ByQuarter_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Hobic_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Hobic_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_Signature_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_FULL_Assessment_Signature_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_Rugs_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_FULL_Assessment_Rugs_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_RAP_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_FULL_Assessment_RAP_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_Medication_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_FULL_Assessment_Medication_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_Diagnosis_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_FULL_Assessment_Diagnosis_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_6_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_FULL_Assessment_6_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_5_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_FULL_Assessment_5_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_4_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_FULL_Assessment_4_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_3_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_FULL_Assessment_3_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_2_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_FULL_Assessment_2_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_1_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_FULL_Assessment_1_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_DemographicChange_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_DemographicChange_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_2010_QI_ByYear_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_2010_QI_ByYear_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_2010_QI_ByQuarter_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_2010_QI_ByQuarter_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Provider_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_And_Provider_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Project_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_And_Project_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Project_Question_24_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_And_Project_Question_24_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Project_740_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_And_Project_740_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Project_640_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_And_Project_640_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Project_340_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_And_Project_340_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Project_202_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_And_Project_202_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Project_150_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_And_Project_150_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Project_100_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_And_Project_100_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_PresentingComplaint]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_And_PresentingComplaint]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_MIS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_And_MIS_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Intervention_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_And_Intervention_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_EDInvestigativeTechnology_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_And_EDInvestigativeTechnology_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_EDInterventionPicklist_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_And_EDInterventionPicklist_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_DischargeDiagnosis]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_And_DischargeDiagnosis]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_And_Diagnosis_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AmCare_And_Consult_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_AmCare_And_Consult_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_CACS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_And_CACS_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_AbstractNotes_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Amcare_And_AbstractNotes_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_SCU_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_SCU_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Provider_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_Provider_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Projects_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_Projects_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Projects_Question_24_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_Projects_Question_24_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Projects_740_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_Projects_740_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Projects_640_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_Projects_640_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Projects_340_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_Projects_340_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Projects_202_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_Projects_202_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Projects_150_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_Projects_150_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Projects_100_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_Projects_100_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_PatientService_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_PatientService_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_MB_TransferWorksheet_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_MB_TransferWorksheet_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_MB_NonALC_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_MB_NonALC_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_MB_FacilityStudy_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_MB_FacilityStudy_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_MB_ALC_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_MB_ALC_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Intervention_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_Intervention_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_DPG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_DPG_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_Diagnosis_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_CMG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_CMG_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_CACS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_CACS_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_AbstractNotes_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[I10_Abstract_And_AbstractNotes_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[EMT_Edit_AND_Conditionss_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[EMT_Edit_AND_Conditionss_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Reentry_Signature_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Reentry_Signature_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Reentry_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_Reentry_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_DischargeTracking_Signature_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_DischargeTracking_Signature_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_DischargeTracking_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_DischargeTracking_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_AdmissionBackground_Signature_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_AdmissionBackground_Signature_Form_VR]
GO
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_AdmissionBackground_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[MDS20_AdmissionBackground_Form_VR]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_AdmissionBackground_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[MDS20_AdmissionBackground_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.zzLinkBackgroundID, dbo.MDS20_VR.ReasonAssessment_AA8, 
                      dbo.MDS20_VR.ReasonAssessmentDesc_AA8, dbo.MDS20_VR.URI_AA1, dbo.MDS20_VR.HealthRecordNumber_A6a, 
                      dbo.MDS20_VR.HealthRegisterNumber_A6b, dbo.MDS20_VR.AdmissionDate_AB1, NextAssessmentDate, dbo.MDS20_VR.Gender_AA2, dbo.MDS20_VR.GenderDesc_AA2, 
                      dbo.MDS20_VR.RoomNumber, dbo.MDS20_VR.MaidenName, dbo.MDS20_VR.LastName, dbo.MDS20_VR.MiddleName, dbo.MDS20_VR.FirstName, 
                      dbo.MDS20_VR.Birthdate_AA3a, dbo.MDS20_VR.BirthdateEstimated_AA3b, dbo.MDS20_VR.BirthDateEstimatedDesc_AA3b, 
                      dbo.MDS20_VR.Treaty_band_AA4a, dbo.MDS20_VR.MaritalStatus_A5, dbo.MDS20_VR.MaritalStatusDesc_A5, dbo.MDS20_VR.HealthCareNumber_AA5a, 
                      dbo.MDS20_VR.HCNVersion, dbo.MDS20_VR.HCNProvince_AA5b, dbo.MDS20_VR.HCNProvinceDesc_AA5b, dbo.MDS20_VR.Hospital, 
                      dbo.MDS20_VR.HospitalDesc, dbo.MDS20_VR.FacilityNumber_AA6, dbo.MDS20_VR.FacilityNumberDesc_AA6, dbo.MDS20_VR.FacilityFrom_AB2b, 
                      dbo.MDS20_VR.FacilityFromDesc_AB2b, dbo.MDS20_VR.CareLevelFrom_AB2a, dbo.MDS20_VR.CareLevelFromDesc_AB2a, 
                      dbo.MDS20_Admission_VR.LivedAlone_AB3, dbo.MDS20_Admission_VR.LivedAloneDesc_AB3, dbo.MDS20_Admission_VR.PostalCode_AB4, 
                      dbo.MDS20_Admission_VR.PostalCodeDesc_AB4, dbo.MDS20_Admission_VR.ResidentialHistory_This_AB5a, 
                      dbo.MDS20_Admission_VR.ResidentialHistory_T_Desc_AB5a, dbo.MDS20_Admission_VR.ResidentialHistorySimilar_AB5b, 
                      dbo.MDS20_Admission_VR.ResidentialHistory_S_Desc_AB5b, dbo.MDS20_Admission_VR.ResidentialHistory_Other_AB5c, 
                      dbo.MDS20_Admission_VR.ResidentialHistory_O_Desc_AB5c, dbo.MDS20_Admission_VR.ResidentialHistory_Psych_AB5d, 
                      dbo.MDS20_Admission_VR.ResidentialHistory_P_Desc_AB5d, dbo.MDS20_Admission_VR.ResidentialHistory_Dev_AB5e, 
                      dbo.MDS20_Admission_VR.ResidentialHistoryDevDesc_AB5e, dbo.MDS20_Admission_VR.ResidentialHistory_None_AB5f, 
                      dbo.MDS20_Admission_VR.ResidentialHistory_N_Desc_AB5f, dbo.MDS20_Admission_VR.Education_AB7, dbo.MDS20_Admission_VR.EducationDesc_AB7, 
                      dbo.MDS20_VR.IsSubmited, dbo.MDS20_VR.IsSubmitedDesc, dbo.MDS20_VR.IsValidated, dbo.MDS20_VR.IsValidatedDesc, dbo.MDS20_VR.IsCompleted, 
                      dbo.MDS20_VR.IsCompletedDesc, dbo.MDS20_VR.IsDeleted, dbo.MDS20_VR.IsDeletedDesc, dbo.MDS20_VR.CoderNumber, 
                      dbo.MDS20_VR.CoderNumberDesc, dbo.MDS20_VR.InterfaceDate, dbo.MDS20_VR.InterfaceTime, dbo.MDS20_VR.InterfaceCoder, 
                      dbo.MDS20_VR.InterfaceCoderDesc, dbo.MDS20_VR.InputDate, dbo.MDS20_VR.InputTime, dbo.MDS20_VR.DataEntryCoder, 
                      dbo.MDS20_VR.DataEntryCoderDesc, dbo.MDS20_VR.FinishDate, dbo.MDS20_VR.FinishTime, dbo.MDS20_VR.Secret, dbo.MDS20_VR.SecretDesc, 
                      dbo.MDS20_VR.RoomUnit, dbo.MDS20_VR.RoomUnitDesc, dbo.MDS20_Admission_VR.Language_AB8, dbo.MDS20_Admission_VR.LanguageDesc_AB8, 
                      dbo.MDS20_Admission_VR.MentalHealthHistory_AB9, dbo.MDS20_Admission_VR.MentalHealthHistoryDesc_AB9, 
                      dbo.MDS20_Admission_VR.ConditionNA_AB10a, dbo.MDS20_Admission_VR.ConditionNADesc_AB10a, dbo.MDS20_Admission_VR.ConditionDwons_AB10b, 
                      dbo.MDS20_Admission_VR.ConditionDwonsDesc_AB10b, dbo.MDS20_Admission_VR.ConditionAutism_AB10c, 
                      dbo.MDS20_Admission_VR.ConditionAutismDesc_AB10c, dbo.MDS20_Admission_VR.ConditionEpilepsy_AB10d, 
                      dbo.MDS20_Admission_VR.ConditionEpilepsyDesc_AB10d, dbo.MDS20_Admission_VR.ConditionOther_AB10e, 
                      dbo.MDS20_Admission_VR.ConditionOtherDesc_AB10e, dbo.MDS20_Admission_VR.ConditionDev_AB10f, 
                      dbo.MDS20_Admission_VR.ConditionDevDesc_AB10f, dbo.MDS20_Admission_VR.ConditionNone_AB10g, 
                      dbo.MDS20_Admission_VR.ConditionNoneDesc_AB10g, dbo.MDS20_Admission_VR.DailyEventLate_AC1a, 
                      dbo.MDS20_Admission_VR.DailyEventLateDesc_AC1a, dbo.MDS20_Admission_VR.DailyEventNap_AC1b, 
                      dbo.MDS20_Admission_VR.DailyEventNapDesc_AC1b, dbo.MDS20_Admission_VR.DailyEventGoOut_AC1c, 
                      dbo.MDS20_Admission_VR.DailyEventGoOutDesc_AC1c, dbo.MDS20_Admission_VR.DailyEventBusy_AC1d, 
                      dbo.MDS20_Admission_VR.DailyEventBusyDesc_AC1d, dbo.MDS20_Admission_VR.DailyEventAlone_AC1e, 
                      dbo.MDS20_Admission_VR.DailyEventAloneDesc_AC1e, dbo.MDS20_Admission_VR.DailyEventIndoor_AC1f, 
                      dbo.MDS20_Admission_VR.DailyEventIndoorDesc_AC1f, dbo.MDS20_Admission_VR.DailyEventSmokes_AC1g, 
                      dbo.MDS20_Admission_VR.DailyEventSmokesDesc_AC1g, dbo.MDS20_Admission_VR.EatingDistinct_AC1i, 
                      dbo.MDS20_Admission_VR.EatingDistinctDesc_AC1i, dbo.MDS20_Admission_VR.EatingBetween_AC1j, 
                      dbo.MDS20_Admission_VR.EatingBetweenDesc_AC1j, dbo.MDS20_Admission_VR.EatingWAlcoholicBev_AC1k, 
                      dbo.MDS20_Admission_VR.EatingWAlcoholicBevDesc_AC1k, dbo.MDS20_Admission_VR.ADL_InBedClothes_AC1m, 
                      dbo.MDS20_Admission_VR.ADL_InBedClothesDesc_AC1m, dbo.MDS20_Admission_VR.ADL_WakensToilet_AC1n, 
                      dbo.MDS20_Admission_VR.ADL_WakensToiletDesc_AC1n, dbo.MDS20_Admission_VR.ADL_IrregularBM_AC1o, 
                      dbo.MDS20_Admission_VR.ADL_IrregularBMDesc_AC1o, dbo.MDS20_Admission_VR.ADL_Shower_AC1p, 
                      dbo.MDS20_Admission_VR.ADL_ShowerDesc_AC1p, dbo.MDS20_Admission_VR.ADL_BathPM_AC1q, dbo.MDS20_Admission_VR.ADL_BathPMDesc_AC1q, 
                      dbo.MDS20_Admission_VR.InvolveContact_AC1s, dbo.MDS20_Admission_VR.InvolveContactDesc_AC1s, dbo.MDS20_Admission_VR.InvolveAttend_AC1t, 
                      dbo.MDS20_Admission_VR.InvolveAttendDesc_AC1t, dbo.MDS20_Admission_VR.InvolveFaith_AC1u, dbo.MDS20_Admission_VR.InvolveFaithDesc_AC1u, 
                      dbo.MDS20_Admission_VR.InvolveAnimal_AC1v, dbo.MDS20_Admission_VR.InvolveAnimalDesc_AC1v, dbo.MDS20_Admission_VR.InvolveGroup_AC1w, 
                      dbo.MDS20_Admission_VR.InvolveGroupDesc_AC1w,
					  dbo.MDS20_VR.ProgramType_AD4, dbo.MDS20_VR.ProgramTypeDesc_AD4
FROM         dbo.MDS20_VR LEFT OUTER JOIN
                      dbo.MDS20_Admission_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Admission_VR.zzAbstractLink
WHERE     (dbo.MDS20_VR.zzLinkBackgroundID = dbo.MDS20_VR.zzAbstractLink)

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_AdmissionBackground_Signature_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE  VIEW [dbo].[MDS20_AdmissionBackground_Signature_Form_VR]
AS
SELECT     dbo.MDS20_AdmissionBackground_Form_VR.zzAbstractLink, dbo.MDS20_Signature_VR.ProviderOccurrence, dbo.MDS20_Signature_VR.SignDate, 
                      dbo.MDS20_Signature_VR.Signature, dbo.MDS20_Signature_VR.Signature_Desc, dbo.MDS20_Signature_VR.ProviderServiceType, 
                      dbo.MDS20_Signature_VR.ProviderServiceType_Desc
FROM         dbo.MDS20_AdmissionBackground_Form_VR LEFT OUTER JOIN
                      dbo.MDS20_Signature_VR ON dbo.MDS20_AdmissionBackground_Form_VR.zzAbstractLink = dbo.MDS20_Signature_VR.zzAbstractLink

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_DischargeTracking_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[MDS20_DischargeTracking_Form_VR]
AS
SELECT     
    zzAbstractLink, zzLinkBackgroundID, 
    ReasonAssessment_AA8,       ReasonAssessmentDesc_AA8, 
    URI_AA1, 
    HealthRecordNumber_A6a, 
    HealthRegisterNumber_A6b, 
    Gender_AA2,                 GenderDesc_AA2, 
    MaidenName, LastName, MiddleName, FirstName, 
    Birthdate_AA3a,     
    BirthdateEstimated_AA3b,    BirthDateEstimatedDesc_AA3b, 
    Treaty_band_AA4a, 
    HealthCareNumber_AA5a, 
    HCNProvince_AA5b,           HCNProvinceDesc_AA5b, 
    HCNVersion, 
    Hospital,                   HospitalDesc, 
    FacilityNumber_AA6,         FacilityNumberDesc_AA6, 
    FacilityTo_R3b,             FacilityToDesc_R3b, 
    CareLevelTo_R3a,            CareLevelToDesc_R3a, 
    COVID19Status_R3c,          COVID19StatusDesc_R3c,
    IsSubmited,                 IsSubmitedDesc, 
    IsValidated,                IsValidatedDesc, 
    IsCompleted,                IsCompletedDesc, 
    IsDeleted,                  IsDeletedDesc, 
    CoderNumber,                CoderNumberDesc, 
    InterfaceDate, 
    InterfaceTime, 
    InterfaceCoder,             InterfaceCoderDesc, 
    InputDate, 
    InputTime, 
    DataEntryCoder,             DataEntryCoderDesc, 
    FinishDate, 
    FinishTime, 
    Secret,                     SecretDesc, 
    DischargeDate_R4
FROM         dbo.MDS20_VR
WHERE     (AA8_CIHI IN (''06'', ''07'', ''08''))

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_DischargeTracking_Signature_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'





CREATE  VIEW [dbo].[MDS20_DischargeTracking_Signature_VR]
AS
SELECT     dbo.MDS20_DischargeTracking_Form_VR.zzAbstractLink, dbo.MDS20_Signature_VR.ProviderOccurrence, dbo.MDS20_Signature_VR.SignDate, 
                      dbo.MDS20_Signature_VR.Signature, dbo.MDS20_Signature_VR.Signature_Desc, dbo.MDS20_Signature_VR.ProviderServiceType, 
                      dbo.MDS20_Signature_VR.ProviderServiceType_Desc
FROM         dbo.MDS20_DischargeTracking_Form_VR LEFT OUTER JOIN
                      dbo.MDS20_Signature_VR ON dbo.MDS20_DischargeTracking_Form_VR.zzAbstractLink = dbo.MDS20_Signature_VR.zzAbstractLink









' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Reentry_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'






CREATE VIEW [dbo].[MDS20_Reentry_Form_VR]
AS
SELECT     zzAbstractLink, zzLinkBackgroundID, ReasonAssessment_AA8, ReasonAssessmentDesc_AA8, URI_AA1, HealthRecordNumber_A6a, 
                      HealthRegisterNumber_A6b, ReEntryDate_AB1b, NextAssessmentDate, Gender_AA2, GenderDesc_AA2, MaidenName, LastName, MiddleName, FirstName, Birthdate_AA3a, 
                      BirthdateEstimated_AA3b, BirthDateEstimatedDesc_AA3b, Treaty_band_AA4a, HealthCareNumber_AA5a, HCNProvince_AA5b, HCNProvinceDesc_AA5b, 
                      HCNVersion, Hospital, HospitalDesc, FacilityNumber_AA6, FacilityNumberDesc_AA6, FacilityFrom_AB2b AS FacilityFrom_AB2d, 
                      FacilityFromDesc_AB2b AS FacilityFromDesc_AB2d, CareLevelFrom_AB2c, CareLevelFromDesc_AB2c, IsSubmited, IsSubmitedDesc, IsValidated, 
                      IsValidatedDesc, IsCompleted, IsCompletedDesc, IsDeleted, IsDeletedDesc, CoderNumber, CoderNumberDesc, InterfaceDate, InterfaceTime, 
                      InterfaceCoder, InterfaceCoderDesc, InputDate, InputTime, DataEntryCoder, DataEntryCoderDesc, FinishDate, FinishTime, Secret, SecretDesc
FROM         dbo.MDS20_VR
WHERE     (AA8_CIHI = ''09'')







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Reentry_Signature_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'






CREATE VIEW [dbo].[MDS20_Reentry_Signature_Form_VR]
AS
SELECT     dbo.MDS20_Reentry_Form_VR.zzAbstractLink, dbo.MDS20_Signature_VR.ProviderOccurrence, dbo.MDS20_Signature_VR.SignDate, dbo.MDS20_Signature_VR.Signature,
                       dbo.MDS20_Signature_VR.Signature_Desc, dbo.MDS20_Signature_VR.ProviderServiceType, dbo.MDS20_Signature_VR.ProviderServiceType_Desc
FROM         dbo.MDS20_Reentry_Form_VR LEFT OUTER JOIN
                      dbo.MDS20_Signature_VR ON dbo.MDS20_Reentry_Form_VR.zzAbstractLink = dbo.MDS20_Signature_VR.zzAbstractLink







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[EMT_Edit_AND_Conditionss_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[EMT_Edit_AND_Conditionss_VR]
AS 
select 
e.[Edit Name]
, e.[Module]
, e.[Edit Rule severity]
, e.[Condition type to evaluate edit] 
, e.[Message content]
, e.[Valid From]
, e.[Valid To]
, lc.[Logical Condition Name]
, lc.[zzConditionLink]
, lc.[Logical Operator] 
, lc.[Same Occurrence (MultiForms)]
, lc.[Condition Type]
, lc.[Valid MultiForm Condition]
, lc.[Name]
from [dbo].[EMT_Edits_VR] e
join EMT_Logical_Conditions_VR lc 
on e.zzEditLink = lc.zzEditLink

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_AbstractNotes_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[I10_Abstract_And_AbstractNotes_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.HospitalAccountRecord,
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, 
                         dbo.I10_Abstracting.InputTime, dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, dbo.I10_Abstracting.InstitutionFromType, dbo.I10_Abstracting.InstitutionFromTypeDesc, 
                         dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType, dbo.I10_Abstracting.InstitutionTo, dbo.I10_Abstracting.InstitutionToDesc, dbo.I10_Abstracting.InstitutionToType, 
                         dbo.I10_Abstracting.InstitutionToTypeDesc, dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, 
                         dbo.I10_Abstracting.InterfaceDate, dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, 
                         dbo.I10_Abstracting.IsAbstractCompletedDesc, dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, 
                         dbo.I10_Abstracting.IsAbstractSubmited, dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, 
                         dbo.I10_Abstracting.IsBirthdateEstimatedDesc, dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, 
                         dbo.I10_Abstracting.IsCustomValidatedDesc, dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, 
                         dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, 
                         dbo.I10_Abstracting.MaritalStatusDesc, dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, 
                         dbo.I10_Abstracting.MB_Weight, dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, 
                         dbo.I10_Abstracting.MedicationResuscitation, dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, 
                         dbo.I10_Abstracting.MHFacilityTransferTo, dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, 
                         dbo.I10_Abstracting.NarconMaloxone, dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, 
                         dbo.I10_Abstracting.OccupationalUnits, dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, 
                         dbo.I10_Abstracting.OtherBloodCrossMatched, dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, dbo.I10_Abstracting.UniversalEpisodeIdentifier, dbo.I10_Abstracting.UnplannedReadmission, 
                         dbo.I10_Abstracting.UnplannedReadmissionDesc, dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 
                         dbo.I10_AbstractNotes_VR.AbstractNotes, dbo.I10_AbstractNotes_VR.CreateBy, dbo.I10_AbstractNotes_VR.CreatorName, dbo.I10_AbstractNotes_VR.DateLogged, dbo.I10_AbstractNotes_VR.TimeLogged, 
                         dbo.I10_Abstracting.zzAbstractLink, dbo.I10_Abstracting.zzRegionalPatientID, dbo.I10_Abstracting.zzVolumeLink
FROM            dbo.I10_Abstracting LEFT OUTER JOIN
                         dbo.I10_AbstractNotes_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_AbstractNotes_VR.zzAbstractLink

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_CACS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[I10_Abstract_And_CACS_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.HospitalAccountRecord,  
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, 
                         dbo.I10_Abstracting.InputTime, dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, dbo.I10_Abstracting.InstitutionFromType, dbo.I10_Abstracting.InstitutionFromTypeDesc, 
                         dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType, dbo.I10_Abstracting.InstitutionTo, dbo.I10_Abstracting.InstitutionToDesc, dbo.I10_Abstracting.InstitutionToType, 
                         dbo.I10_Abstracting.InstitutionToTypeDesc, dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, 
                         dbo.I10_Abstracting.InterfaceDate, dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, 
                         dbo.I10_Abstracting.IsAbstractCompletedDesc, dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, 
                         dbo.I10_Abstracting.IsAbstractSubmited, dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, 
                         dbo.I10_Abstracting.IsBirthdateEstimatedDesc, dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, 
                         dbo.I10_Abstracting.IsCustomValidatedDesc, dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, 
                         dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, 
                         dbo.I10_Abstracting.MaritalStatusDesc, dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, 
                         dbo.I10_Abstracting.MB_Weight, dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, 
                         dbo.I10_Abstracting.MedicationResuscitation, dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, 
                         dbo.I10_Abstracting.MHFacilityTransferTo, dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, 
                         dbo.I10_Abstracting.NarconMaloxone, dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, 
                         dbo.I10_Abstracting.OccupationalUnits, dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, 
                         dbo.I10_Abstracting.OtherBloodCrossMatched, dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, dbo.I10_Abstracting.UniversalEpisodeIdentifier, dbo.I10_Abstracting.UnplannedReadmission, 
                         dbo.I10_Abstracting.UnplannedReadmissionDesc, dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 
                         dbo.I10_Abstracting.zzAbstractLink, dbo.I10_Abstracting.zzRegionalPatientID, dbo.I10_Abstracting.zzVolumeLink, dbo.I10_Abstract_CACS_VR.OccurrenceNumber, dbo.I10_Abstract_CACS_VR.BatchGroupDate, 
                         dbo.I10_Abstract_CACS_VR.CACSYear, dbo.I10_Abstract_CACS_VR.MAC, dbo.I10_Abstract_CACS_VR.MACDescription, dbo.I10_Abstract_CACS_VR.CACSCell, dbo.I10_Abstract_CACS_VR.ACW, 
                         dbo.I10_Abstract_CACS_VR.CACSDescription, dbo.I10_Abstract_CACS_VR.InterventionCode, dbo.I10_Abstract_CACS_VR.IntervCodeDescription, dbo.I10_Abstract_CACS_VR.InterventionCodeShortDesc, 
                         dbo.I10_Abstract_CACS_VR.AgeCategory, dbo.I10_Abstract_CACS_VR.AgeCategoryDesc, dbo.I10_Abstract_CACS_VR.AnaestheticCategory, dbo.I10_Abstract_CACS_VR.AnaestheticCategoryDesc, 
                         dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyTotalCount, dbo.I10_Abstract_CACS_VR.CACSHBAM, dbo.I10_Abstract_CACS_VR.CACSBaseRIW, dbo.I10_Abstract_CACS_VR.CACSPartition, 
                         dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategory_01, dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategoryCount_01, dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategory_02, 
                         dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategoryCount_02, dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategory_03, dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategoryCount_03, 
                         dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategory_04, dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategoryCount_04, dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategory_05, 
                         dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategoryCount_05, dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategory_06, dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategoryCount_06, 
                         dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategory_07, dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategoryCount_07, dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategory_08, 
                         dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategoryCount_08, dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategory_09, dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategoryCount_09, 
                         dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategory_10, dbo.I10_Abstract_CACS_VR.InvestigativeTechnologyCategoryCount_10
FROM            dbo.I10_Abstracting LEFT OUTER JOIN
                         dbo.I10_Abstract_CACS_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_Abstract_CACS_VR.zzAbstractLink

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_CMG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[I10_Abstract_And_CMG_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.HospitalAccountRecord,
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, 
                         dbo.I10_Abstracting.InputTime, dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, dbo.I10_Abstracting.InstitutionFromType, dbo.I10_Abstracting.InstitutionFromTypeDesc, 
                         dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType, dbo.I10_Abstracting.InstitutionTo, dbo.I10_Abstracting.InstitutionToDesc, dbo.I10_Abstracting.InstitutionToType, 
                         dbo.I10_Abstracting.InstitutionToTypeDesc, dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, 
                         dbo.I10_Abstracting.InterfaceDate, dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, 
                         dbo.I10_Abstracting.IsAbstractCompletedDesc, dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, 
                         dbo.I10_Abstracting.IsAbstractSubmited, dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, 
                         dbo.I10_Abstracting.IsBirthdateEstimatedDesc, dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, 
                         dbo.I10_Abstracting.IsCustomValidatedDesc, dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, 
                         dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, 
                         dbo.I10_Abstracting.MaritalStatusDesc, dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, 
                         dbo.I10_Abstracting.MB_Weight, dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, 
                         dbo.I10_Abstracting.MedicationResuscitation, dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, 
                         dbo.I10_Abstracting.MHFacilityTransferTo, dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, 
                         dbo.I10_Abstracting.NarconMaloxone, dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, 
                         dbo.I10_Abstracting.OccupationalUnits, dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, 
                         dbo.I10_Abstracting.OtherBloodCrossMatched, dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, dbo.I10_Abstracting.UniversalEpisodeIdentifier, dbo.I10_Abstracting.UnplannedReadmission, 
                         dbo.I10_Abstracting.UnplannedReadmissionDesc, dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 
                         dbo.I10_CMG_VR.Acute_Quartile, dbo.I10_CMG_VR.BatchGroupDate, dbo.I10_CMG_VR.CMG, dbo.I10_CMG_VR.CMG_Description, dbo.I10_CMG_VR.MedicalCMG, dbo.I10_CMG_VR.MedicalCMGDesciption, 
                         dbo.I10_CMG_VR.CMG_ELOS, dbo.I10_CMG_VR.CMG_Split, dbo.I10_CMG_VR.CMG_Year, dbo.I10_CMG_VR.CMGAgeCategory, dbo.I10_CMG_VR.CMGAgeCategoryDesc, dbo.I10_CMG_VR.CMGReturnCode, 
                         dbo.I10_CMG_VR.Complexity, dbo.I10_CMG_VR.Complexity_Description, dbo.I10_CMG_VR.ComorbidityLevel, dbo.I10_CMG_VR.ComorbidityLevelDesc, dbo.I10_CMG_VR.ComorbidityTotalFactor, 
                         dbo.I10_CMG_VR.Diagnosis_CIHIValue, dbo.I10_CMG_VR.Diagnosis_Code, dbo.I10_CMG_VR.Diagnosis_CodeShortDesc, dbo.I10_CMG_VR.Diagnosis_Description, dbo.I10_CMG_VR.Diagnosis_Type, 
                         dbo.I10_CMG_VR.Diagnosis_Type_Desc, dbo.I10_CMG_VR.DxIntervPartition, dbo.I10_CMG_VR.DxIntervPartitionDesc, dbo.I10_CMG_VR.FI_BiopsyFlag, dbo.I10_CMG_VR.FI_CardioversionFlag, 
                         dbo.I10_CMG_VR.FI_CellSaverFlag, dbo.I10_CMG_VR.FI_ChemotherapyFlag, dbo.I10_CMG_VR.FI_DialysisFlag, dbo.I10_CMG_VR.FI_ECMOFlag, dbo.I10_CMG_VR.FI_EndoscopyFlag, dbo.I10_CMG_VR.FI_FeedingTubeFlag, 
                         dbo.I10_CMG_VR.FI_HeartResuscitationFlag, dbo.I10_CMG_VR.FI_InvasiveVentilationGreat96Hours, dbo.I10_CMG_VR.FI_InvasiveVentilationLess96Hours, dbo.I10_CMG_VR.FI_MechanicalVentGreat96Hours, 
                         dbo.I10_CMG_VR.FI_MechanicalVentLess96Hours, dbo.I10_CMG_VR.FI_ParacentesisFlag, dbo.I10_CMG_VR.FI_ParenteralNutritionFlag, dbo.I10_CMG_VR.FI_PleurocentesisFlag, dbo.I10_CMG_VR.FI_RadiotherapyFlag, 
                         dbo.I10_CMG_VR.FI_TracheostomyFlag, dbo.I10_CMG_VR.FI_VascularAccessDdeviceFlag, dbo.I10_CMG_VR.FiftiethPercentile, dbo.I10_CMG_VR.FlaggedIntervFactorCount, dbo.I10_CMG_VR.FlaggedIntervFactorCountDesc, 
                         dbo.I10_CMG_VR.FlaggedInterventionGroup1, dbo.I10_CMG_VR.FlaggedInterventionGroup2, dbo.I10_CMG_VR.FlaggedInterventionGroup3, dbo.I10_CMG_VR.FlaggedInterventionStatusCode, 
                         dbo.I10_CMG_VR.FlaggedInterventionStatusCodeDesc, dbo.I10_CMG_VR.ICD_Type, dbo.I10_CMG_VR.InpatientRILevel, dbo.I10_CMG_VR.InpatientRILevelDesc, dbo.I10_CMG_VR.InpatientRITotalFactor, 
                         dbo.I10_CMG_VR.InpatientRIWAtypicalCode, dbo.I10_CMG_VR.InpatientRIWAtypicalCodeDesc, dbo.I10_CMG_VR.InterventionAssignment, dbo.I10_CMG_VR.InterventionAssignmentCIHI, 
                         dbo.I10_CMG_VR.InterventionAssignmentDesc, dbo.I10_CMG_VR.InterventionAttributeStatus, dbo.I10_CMG_VR.InterventionAttributeLocation, dbo.I10_CMG_VR.InterventionAttributeExtent, dbo.I10_CMG_VR.InterventionEpisode, 
                         dbo.I10_CMG_VR.InterventionEventCount, dbo.I10_CMG_VR.InterventionEventCountDesc, dbo.I10_CMG_VR.InterventionOOHCount, dbo.I10_CMG_VR.InterventionOOHCountDesc, dbo.I10_CMG_VR.MCC, 
                         dbo.I10_CMG_VR.MCC_Description, dbo.I10_CMG_VR.MCC_Surg, dbo.I10_CMG_VR.ModelType, dbo.I10_CMG_VR.MOH_Dollar, dbo.I10_CMG_VR.MOH_RIW, dbo.I10_CMG_VR.Occurrence_Number, 
                         dbo.I10_CMG_VR.PercentileAgeGroup, dbo.I10_CMG_VR.RIW, dbo.I10_CMG_VR.InpatientTypicalRIW, dbo.I10_CMG_VR.RIW_Dollar, dbo.I10_CMG_VR.TenthPercentile, dbo.I10_CMG_VR.Trim, 
                         dbo.I10_CMG_VR.TwentyFifthPercentile, dbo.I10_CMG_VR.HIG_Code, dbo.I10_CMG_VR.HIG_Description, dbo.I10_CMG_VR.HIG_Weight, dbo.I10_CMG_VR.HIG_AgeCategory, dbo.I10_CMG_VR.HIG_AgeCategoryDesc, 
                         dbo.I10_CMG_VR.HIG_AtypicalCode, dbo.I10_CMG_VR.HIG_AtypicalCodeDesc, dbo.I10_CMG_VR.HIG_ELOS, dbo.I10_CMG_VR.HIG_FI_TotalCount, dbo.I10_CMG_VR.HIG_HomeCareFlag, dbo.I10_CMG_VR.HIG_MaternalAgeFlag, 
                         dbo.I10_CMG_VR.HIG_PalliativeCareFlag, dbo.I10_CMG_VR.HIG_OOHFlag, dbo.I10_CMG_VR.HIG_SCUFlag, dbo.I10_CMG_VR.HIG_LongStayTrimDays, dbo.I10_CMG_VR.HIG_ShortStayTrimDays, 
                         dbo.I10_Abstracting.zzAbstractLink, dbo.I10_Abstracting.zzRegionalPatientID, dbo.I10_Abstracting.zzVolumeLink
FROM            dbo.I10_Abstracting LEFT OUTER JOIN
                         dbo.I10_CMG_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_CMG_VR.zzAbstractLink

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[I10_Abstract_And_Diagnosis_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.HospitalAccountRecord,
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, 
                         dbo.I10_Abstracting.InputTime, dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, dbo.I10_Abstracting.InstitutionFromType, dbo.I10_Abstracting.InstitutionFromTypeDesc, 
                         dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType, dbo.I10_Abstracting.InstitutionTo, dbo.I10_Abstracting.InstitutionToDesc, dbo.I10_Abstracting.InstitutionToType, 
                         dbo.I10_Abstracting.InstitutionToTypeDesc, dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, 
                         dbo.I10_Abstracting.InterfaceDate, dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, 
                         dbo.I10_Abstracting.IsAbstractCompletedDesc, dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, 
                         dbo.I10_Abstracting.IsAbstractSubmited, dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, 
                         dbo.I10_Abstracting.IsBirthdateEstimatedDesc, dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, 
                         dbo.I10_Abstracting.IsCustomValidatedDesc, dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, 
                         dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, 
                         dbo.I10_Abstracting.MaritalStatusDesc, dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, 
                         dbo.I10_Abstracting.MB_Weight, dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, 
                         dbo.I10_Abstracting.MedicationResuscitation, dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, 
                         dbo.I10_Abstracting.MHFacilityTransferTo, dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, 
                         dbo.I10_Abstracting.NarconMaloxone, dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, 
                         dbo.I10_Abstracting.OccupationalUnits, dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, 
                         dbo.I10_Abstracting.OtherBloodCrossMatched, dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, dbo.I10_Abstracting.UniversalEpisodeIdentifier, dbo.I10_Abstracting.UnplannedReadmission, 
                         dbo.I10_Abstracting.UnplannedReadmissionDesc, dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 
                         dbo.I10_Diagnosis_VR.DiagnosisCluster, dbo.I10_Diagnosis_VR.DiagnosisCIHIValue, dbo.I10_Diagnosis_VR.DiagnosisCode, dbo.I10_Diagnosis_VR.DiagnosisCodeDesc, dbo.I10_Diagnosis_VR.DiagnosisCodeShortDesc, 
                         dbo.I10_Diagnosis_VR.DiagnosisICD9cmEquivalent, dbo.I10_Diagnosis_VR.DiagnosisICD9Equivalent, dbo.I10_Diagnosis_VR.DiagnosisOccurrence, dbo.I10_Diagnosis_VR.DiagnosisPrefix, 
                         dbo.I10_Diagnosis_VR.DiagnosisPrefixDesc, dbo.I10_Diagnosis_VR.DiagnosisType, dbo.I10_Diagnosis_VR.DiagnosisTypeDesc, dbo.I10_Abstracting.zzAbstractLink, dbo.I10_Abstracting.zzRegionalPatientID, 
                         dbo.I10_Abstracting.zzVolumeLink
FROM            dbo.I10_Abstracting LEFT OUTER JOIN
                         dbo.I10_Diagnosis_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_Diagnosis_VR.zzAbstractLink

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_DPG_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'




CREATE VIEW [dbo].[I10_Abstract_And_DPG_VR]
AS
SELECT     dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], 
                      dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.AbstractNumber, 
                      dbo.I10_Abstracting.AbstractOverflow, dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, 
                      dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, 
                      dbo.I10_Abstracting.AdmissionTime, 
                      dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, 
                      dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                      dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, 
                      dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, 
                      dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                      dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, 
                      dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, 
                      dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, 
                      dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, 
                      dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, dbo.I10_Abstracting.AncillaryField11Desc, 
                      dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, 
                      dbo.I10_Abstracting.AncillaryField13Desc, dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, 
                      dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                      dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, 
                      dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, dbo.I10_Abstracting.AncillaryField3, 
                      dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, 
                      dbo.I10_Abstracting.AncillaryField5, dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, 
                      dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                      dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, 
                      dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, dbo.I10_Abstracting.ArrivalDateInER, 
                      dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, 
                      dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.AutoTransfusion, 
                      dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.BagVentilation, 
                      dbo.I10_Abstracting.BagVentilationDesc, dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, 
                      dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                      dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, 
                      dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, dbo.I10_Abstracting.BasicOption14, 
                      dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, 
                      dbo.I10_Abstracting.BasicOption16, dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, 
                      dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                      dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, 
                      dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, 
                      dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                      dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, 
                      dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, 
                      dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, dbo.I10_Abstracting.Between210DaysPostOp, 
                      dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.BreastFeedingonDischarge, 
                      dbo.I10_Abstracting.BreastFeedingonDischargeDesc, dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, 
                      dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                      dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, 
                      dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, 
                      dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                      dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, 
                      dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, dbo.I10_Abstracting.Complication3, 
                      dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, 
                      dbo.I10_Abstracting.DataEntryCoder, dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, 
                      dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                      dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, 
                      dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, 
                      dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                      dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, 
                      dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, dbo.I10_Abstracting.DischargePlanningDesc, 
                      dbo.I10_Abstracting.DischargeTime, 
                      dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, 
                      dbo.I10_Abstracting.DrinksPerday, dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, 
                      dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                      dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, 
                      dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, 
                      dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                      dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, 
                      dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, 
                      dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                      dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, 
                      dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                      dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, 
                      dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                      dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, 
                      dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, 
                      dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                      dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, 
                      dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, dbo.I10_Abstracting.InputTime, dbo.I10_Abstracting.InstFromCareType, 
                      dbo.I10_Abstracting.InstFromHospType, dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, 
                      dbo.I10_Abstracting.InstitutionTo, dbo.I10_Abstracting.InstitutionToDesc, dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, 
                      dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, dbo.I10_Abstracting.InterfaceDate, dbo.I10_Abstracting.InterfaceTime, 
                      dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, 
                      dbo.I10_Abstracting.IsAbstractCompletedDesc, dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, 
                      dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, dbo.I10_Abstracting.IsAbstractSubmited, 
                      dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, 
                      dbo.I10_Abstracting.IsBirthdateEstimated, dbo.I10_Abstracting.IsBirthdateEstimatedDesc, dbo.I10_Abstracting.LastName, 
                      dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, 
                      dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, 
                      dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.MaidenName, 
                      dbo.I10_Abstracting.MaritalStatus, dbo.I10_Abstracting.MaritalStatusDesc, dbo.I10_Abstracting.MaternalNewbornChartNumber, 
                      dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, 
                      dbo.I10_Abstracting.MB_Weight, dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.Meconium, 
                      dbo.I10_Abstracting.MeconiumDesc, dbo.I10_Abstracting.MedicationResuscitation, dbo.I10_Abstracting.MedicationResuscitationDesc, 
                      dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, 
                      dbo.I10_Abstracting.MHFacilityTransferFromDesc, dbo.I10_Abstracting.MHFacilityTransferTo, dbo.I10_Abstracting.MHFacilityTransferToDesc, 
                      dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, dbo.I10_Abstracting.NarconMaloxone, 
                      dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, 
                      dbo.I10_Abstracting.OccupationalTherapyDesc, dbo.I10_Abstracting.OccupationalUnits, dbo.I10_Abstracting.OtherBlood, 
                      dbo.I10_Abstracting.OtherBloodDesc, dbo.I10_Abstracting.OtherBloodCrossMatched, dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, 
                      dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                      dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.Parity, 
                      dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                      dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Plasma, 
                      dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, dbo.I10_Abstracting.PlasmaCrossMatchedDesc, 
                      dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, 
                      dbo.I10_Abstracting.PlateletsDesc, dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, 
                      dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                      dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, 
                      dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, 
                      dbo.I10_Abstracting.PostOpDays, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                      dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, 
                      dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, 
                      dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PreOpDays, 
                      dbo.I10_Abstracting.Presentation, dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, 
                      dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                      dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, 
                      dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.ReAdmitCode, dbo.I10_Abstracting.ReAdmitCodeDesc, 
                      dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, 
                      dbo.I10_Abstracting.RedBloodCellDesc, dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, 
                      dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, dbo.I10_Abstracting.RedBloodCellUnits, 
                      dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, 
                      dbo.I10_Abstracting.ReferringProviderDesc, dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, 
                      dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                      dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, 
                      dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, dbo.I10_Abstracting.ResidenceRegion, 
                      dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, 
                      dbo.I10_Abstracting.RespiratoryUnits, dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, 
                      dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                      dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, 
                      dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                      dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, 
                      dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, dbo.I10_Abstracting.SocialServices, 
                      dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, 
                      dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, dbo.I10_Abstracting.SpeechUnits, 
                      dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, 
                      dbo.I10_Abstracting.StartFirstStageDateUnknown, dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, 
                      dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                      dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, 
                      dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, dbo.I10_Abstracting.SubsequentOR, 
                      dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, 
                      dbo.I10_Abstracting.SurgicalCase, dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, 
                      dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                      dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, 
                      dbo.I10_Abstracting.UnplannedReadmission, dbo.I10_Abstracting.UnplannedReadmissionDesc, dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, 
                      dbo.I10_Abstracting.Weightingrams, dbo.I10_DPG_VR.DPG, dbo.I10_DPG_VR.DPGOccurrence, dbo.I10_DPG_VR.DPG_Description, 
                      dbo.I10_DPG_VR.DPG_MOH_RIW, dbo.I10_DPG_VR.DPG_RIW, dbo.I10_DPG_VR.DPG_Year, dbo.I10_DPG_VR.DPGReturnCode, 
                      dbo.I10_DPG_VR.InterventionCode, dbo.I10_DPG_VR.InterventionCodeDesc,
                      dbo.I10_Abstracting.zzAbstractLink, 
                      dbo.I10_Abstracting.zzRegionalPatientID,
                      dbo.I10_Abstracting.zzVolumeLink 

FROM         dbo.I10_Abstracting LEFT OUTER JOIN
                      dbo.I10_DPG_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_DPG_VR.zzAbstractLink






' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Intervention_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_Abstract_And_Intervention_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.HospitalAccountRecord,
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, dbo.I10_Abstracting.InputTime, 
						 dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, 
						 dbo.I10_Abstracting.InstitutionFromType, dbo.I10_Abstracting.InstitutionFromTypeDesc, 
						 dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType, 
						 dbo.I10_Abstracting.InstitutionTo,  dbo.I10_Abstracting.InstitutionToDesc, 
						 dbo.I10_Abstracting.InstitutionToType, dbo.I10_Abstracting.InstitutionToTypeDesc, 
						 dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, 
						 dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, dbo.I10_Abstracting.InterfaceDate, 
                         dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, dbo.I10_Abstracting.IsAbstractCompletedDesc, 
                         dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, dbo.I10_Abstracting.IsAbstractSubmited, 
                         dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, dbo.I10_Abstracting.IsBirthdateEstimatedDesc, 
                         dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, dbo.I10_Abstracting.IsCustomValidatedDesc, 
                         dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, 
                         dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, dbo.I10_Abstracting.MaritalStatusDesc, 
                         dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, dbo.I10_Abstracting.MB_Weight, 
                         dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, dbo.I10_Abstracting.MedicationResuscitation, 
                         dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, dbo.I10_Abstracting.MHFacilityTransferTo, 
                         dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, dbo.I10_Abstracting.NarconMaloxone, 
                         dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, dbo.I10_Abstracting.OccupationalUnits, 
                         dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, dbo.I10_Abstracting.OtherBloodCrossMatched, 
                         dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, 
						 dbo.I10_Abstracting.UniversalEpisodeIdentifier,
						 dbo.I10_Abstracting.UnplannedReadmission, dbo.I10_Abstracting.UnplannedReadmissionDesc, 
                         dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 

						dbo.I10_Interventions_VR.AnaestheticTechnique, 
                         dbo.I10_Interventions_VR.AnaestheticTechniqueDesc, dbo.I10_Interventions_VR.AnaesthetistID, dbo.I10_Interventions_VR.AnaesthetistIDDesc, 
                         dbo.I10_Interventions_VR.CJRRJointIdentifier, dbo.I10_Interventions_VR.CJRRRevisionReason, dbo.I10_Interventions_VR.CJRRRevisionReasonDesc,
                         dbo.I10_Interventions_VR.EUL, 
                         dbo.I10_Interventions_VR.EULDesc, dbo.I10_Interventions_VR.Extra, dbo.I10_Interventions_VR.ExtraDesc, dbo.I10_Interventions_VR.IntervAttribExtent, dbo.I10_Interventions_VR.IntervAttribExtentDesc, 
                         dbo.I10_Interventions_VR.IntervAttribLocation, dbo.I10_Interventions_VR.IntervAttribLocationDesc, dbo.I10_Interventions_VR.IntervAttribStatus, dbo.I10_Interventions_VR.IntervAttribStatusDesc, 
                         dbo.I10_Interventions_VR.IntervCIHIValue, dbo.I10_Interventions_VR.IntervCode, dbo.I10_Interventions_VR.IntervCodeClinicianTitle, dbo.I10_Interventions_VR.IntervCodeDesc, 
                         dbo.I10_Interventions_VR.IntervCodeShortDesc, 
						 dbo.I10_Interventions_VR.IntervComments,
						 dbo.I10_Interventions_VR.IntervDate, dbo.I10_Interventions_VR.IntervDateIn, dbo.I10_Interventions_VR.IntervDateOut, 
                         dbo.I10_Interventions_VR.IntervEpisodeStartTimeUnknown, dbo.I10_Interventions_VR.IntervEpisodeStartTimeUnknownDesc, dbo.I10_Interventions_VR.IntervEpisodeEndTimeUnknown, 
                         dbo.I10_Interventions_VR.IntervEpisodeEndTimeUnknownDesc, dbo.I10_Interventions_VR.IntervFlaggedCategory, dbo.I10_Interventions_VR.IntervFlaggedCategoryDesc, 
                         dbo.I10_Interventions_VR.IntervICD9Equivalent, dbo.I10_Interventions_VR.IntervICD9cmEquivalent, dbo.I10_Interventions_VR.IntervLocation, dbo.I10_Interventions_VR.IntervLocationDesc, 
                         dbo.I10_Interventions_VR.IntervOccurrence, dbo.I10_Interventions_VR.IntervPreAdmitFlag, dbo.I10_Interventions_VR.IntervPreAdmitFlagDesc, dbo.I10_Interventions_VR.IntervProviderNumber, 
                         dbo.I10_Interventions_VR.IntervProviderNumberDesc, dbo.I10_Interventions_VR.IntervProviderService, dbo.I10_Interventions_VR.IntervProviderServiceDesc, dbo.I10_Interventions_VR.IntervProviderSpecialty, 
                         dbo.I10_Interventions_VR.IntervProviderSpecialtyDesc, dbo.I10_Interventions_VR.IntervSuffix, dbo.I10_Interventions_VR.IntervSuffixDesc, dbo.I10_Interventions_VR.IntervTimeIn, 
                         dbo.I10_Interventions_VR.IntervTimeinMinutes, dbo.I10_Interventions_VR.IntervTimeOut, dbo.I10_Interventions_VR.OOHIndicator, dbo.I10_Interventions_VR.OOHIndicatorDesc, 
                         dbo.I10_Interventions_VR.OOHInstitutionNumber, dbo.I10_Interventions_VR.OOHInstitutionNumberDesc, dbo.I10_Interventions_VR.ORTripNumber, dbo.I10_Interventions_VR.SurgicalCode, 
                         dbo.I10_Interventions_VR.SurgicalCodeDesc, dbo.I10_Interventions_VR.TissueCode, dbo.I10_Interventions_VR.TissueCodeDesc, dbo.I10_Interventions_VR.TissueCodeDesc_D, 
                         dbo.I10_Interventions_VR.UnplannedReturntoOR, dbo.I10_Interventions_VR.UnplannedReturntoORDesc, dbo.I10_Interventions_VR.ORURN, dbo.I10_Abstracting.zzAbstractLink, 
                         dbo.I10_Abstracting.zzRegionalPatientID, dbo.I10_Abstracting.zzVolumeLink
FROM            dbo.I10_Abstracting LEFT OUTER JOIN
                         dbo.I10_Interventions_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_Interventions_VR.zzAbstractLink




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_MB_ALC_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_Abstract_And_MB_ALC_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.HospitalAccountRecord,
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, dbo.I10_Abstracting.InputTime, 
						 dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, 
						 dbo.I10_Abstracting.InstitutionFromType, dbo.I10_Abstracting.InstitutionFromTypeDesc, 
						 dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType,
						 dbo.I10_Abstracting.InstitutionTo,  dbo.I10_Abstracting.InstitutionToDesc, 
						 dbo.I10_Abstracting.InstitutionToType, dbo.I10_Abstracting.InstitutionToTypeDesc, 
						 dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, 
						 dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, dbo.I10_Abstracting.InterfaceDate, 
                         dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, dbo.I10_Abstracting.IsAbstractCompletedDesc, 
                         dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, dbo.I10_Abstracting.IsAbstractSubmited, 
                         dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, dbo.I10_Abstracting.IsBirthdateEstimatedDesc, 
                         dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, dbo.I10_Abstracting.IsCustomValidatedDesc, 
                         dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, 
                         dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, dbo.I10_Abstracting.MaritalStatusDesc, 
                         dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, dbo.I10_Abstracting.MB_Weight, 
                         dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, 
						 dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, 
						 dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
						 dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, dbo.I10_Abstracting.MedicationResuscitation, 
                         dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, dbo.I10_Abstracting.MHFacilityTransferTo, 
                         dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, dbo.I10_Abstracting.NarconMaloxone, 
                         dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, dbo.I10_Abstracting.OccupationalUnits, 
                         dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, dbo.I10_Abstracting.OtherBloodCrossMatched, 
                         dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, 
						 dbo.I10_Abstracting.UniversalEpisodeIdentifier, dbo.I10_Abstracting.UnplannedReadmission, dbo.I10_Abstracting.UnplannedReadmissionDesc, 
                         dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 
						dbo.I10_MB_ALC_VR.ALCDays, 
                      dbo.I10_MB_ALC_VR.ALCOccurrence, dbo.I10_MB_ALC_VR.ALCReasonCode, dbo.I10_MB_ALC_VR.ALCReasonCodeDesc, dbo.I10_MB_ALC_VR.DateDesignatedALC, 
                      dbo.I10_MB_ALC_VR.DateReassignedAcute, 
                      dbo.I10_Abstracting.zzAbstractLink, 
                      dbo.I10_Abstracting.zzRegionalPatientID,
                      dbo.I10_Abstracting.zzVolumeLink
FROM         dbo.I10_Abstracting LEFT OUTER JOIN
                      dbo.I10_MB_ALC_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_MB_ALC_VR.zzAbstractLink


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_MB_FacilityStudy_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_Abstract_And_MB_FacilityStudy_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.HospitalAccountRecord,
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, dbo.I10_Abstracting.InputTime, 
						 dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc,
						 dbo.I10_Abstracting.InstitutionFromType, dbo.I10_Abstracting.InstitutionFromTypeDesc, 
						 dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType, 
						 dbo.I10_Abstracting.InstitutionTo, dbo.I10_Abstracting.InstitutionToDesc, 
						 dbo.I10_Abstracting.InstitutionToType, dbo.I10_Abstracting.InstitutionToTypeDesc, 
						 dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, 
						 dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, dbo.I10_Abstracting.InterfaceDate, 
                         dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, dbo.I10_Abstracting.IsAbstractCompletedDesc, 
                         dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, dbo.I10_Abstracting.IsAbstractSubmited, 
                         dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, dbo.I10_Abstracting.IsBirthdateEstimatedDesc, 
                         dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, dbo.I10_Abstracting.IsCustomValidatedDesc, 
                         dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, 
                         dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, dbo.I10_Abstracting.MaritalStatusDesc, 
                         dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, dbo.I10_Abstracting.MB_Weight, 
                         dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, dbo.I10_Abstracting.MedicationResuscitation, 
                         dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, dbo.I10_Abstracting.MHFacilityTransferTo, 
                         dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, dbo.I10_Abstracting.NarconMaloxone, 
                         dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, dbo.I10_Abstracting.OccupationalUnits, 
                         dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, dbo.I10_Abstracting.OtherBloodCrossMatched, 
                         dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, 
						 dbo.I10_Abstracting.UniversalEpisodeIdentifier, dbo.I10_Abstracting.UnplannedReadmission, dbo.I10_Abstracting.UnplannedReadmissionDesc, 
                         dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 
						dbo.I10_MB_FacilityStudy_VR.FacilityDateStudy, dbo.I10_MB_FacilityStudy_VR.FacilityStudyCode, 
                      dbo.I10_MB_FacilityStudy_VR.FacilityStudyOccurrence, 
                      dbo.I10_Abstracting.zzAbstractLink, 
                      dbo.I10_Abstracting.zzRegionalPatientID,
                      dbo.I10_Abstracting.zzVolumeLink
FROM         dbo.I10_Abstracting LEFT OUTER JOIN
                      dbo.I10_MB_FacilityStudy_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_MB_FacilityStudy_VR.zzAbstractLink


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_MB_NonALC_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_Abstract_And_MB_NonALC_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.HospitalAccountRecord,
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, dbo.I10_Abstracting.InputTime, 
						 dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, 
						 dbo.I10_Abstracting.InstitutionFromType, dbo.I10_Abstracting.InstitutionFromTypeDesc, 
						 dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType, 
						 dbo.I10_Abstracting.InstitutionTo,   dbo.I10_Abstracting.InstitutionToDesc, 
						 dbo.I10_Abstracting.InstitutionToType, dbo.I10_Abstracting.InstitutionToTypeDesc, 
						 dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, 
						 dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, dbo.I10_Abstracting.InterfaceDate, 
                         dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, dbo.I10_Abstracting.IsAbstractCompletedDesc, 
                         dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, dbo.I10_Abstracting.IsAbstractSubmited, 
                         dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, dbo.I10_Abstracting.IsBirthdateEstimatedDesc, 
                         dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, dbo.I10_Abstracting.IsCustomValidatedDesc, 
                         dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, 
                         dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, dbo.I10_Abstracting.MaritalStatusDesc, 
                         dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, dbo.I10_Abstracting.MB_Weight, 
                         dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, dbo.I10_Abstracting.MedicationResuscitation, 
                         dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, dbo.I10_Abstracting.MHFacilityTransferTo, 
                         dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, dbo.I10_Abstracting.NarconMaloxone, 
                         dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, dbo.I10_Abstracting.OccupationalUnits, 
                         dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, dbo.I10_Abstracting.OtherBloodCrossMatched, 
                         dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, 
						 dbo.I10_Abstracting.UniversalEpisodeIdentifier, dbo.I10_Abstracting.UnplannedReadmission, dbo.I10_Abstracting.UnplannedReadmissionDesc, 
                         dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 
						dbo.I10_MB_NonALC_VR.DaysNonALCDelay, dbo.I10_MB_NonALC_VR.NonALCDelayReason, 
                      dbo.I10_MB_NonALC_VR.NonALCDelayReasonDesc, dbo.I10_MB_NonALC_VR.NonALCOccurrence, 
                      dbo.I10_Abstracting.zzAbstractLink, 
                      dbo.I10_Abstracting.zzRegionalPatientID,
                      dbo.I10_Abstracting.zzVolumeLink
FROM         dbo.I10_Abstracting LEFT OUTER JOIN
                      dbo.I10_MB_NonALC_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_MB_NonALC_VR.zzAbstractLink


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_MB_TransferWorksheet_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_Abstract_And_MB_TransferWorksheet_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.HospitalAccountRecord,
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, dbo.I10_Abstracting.InputTime, 
						 dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, 
						 dbo.I10_Abstracting.InstitutionFromType, dbo.I10_Abstracting.InstitutionFromTypeDesc, 
						 dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType, 
						 dbo.I10_Abstracting.InstitutionTo, dbo.I10_Abstracting.InstitutionToDesc, 
						 dbo.I10_Abstracting.InstitutionToType, dbo.I10_Abstracting.InstitutionToTypeDesc, 
						 dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, 
						 dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, dbo.I10_Abstracting.InterfaceDate, 
                         dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, dbo.I10_Abstracting.IsAbstractCompletedDesc, 
                         dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, dbo.I10_Abstracting.IsAbstractSubmited, 
                         dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, dbo.I10_Abstracting.IsBirthdateEstimatedDesc, 
                         dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, dbo.I10_Abstracting.IsCustomValidatedDesc, 
                         dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, 
                         dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, dbo.I10_Abstracting.MaritalStatusDesc, 
                         dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, dbo.I10_Abstracting.MB_Weight, 
                         dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, dbo.I10_Abstracting.MedicationResuscitation, 
                         dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, dbo.I10_Abstracting.MHFacilityTransferTo, 
                         dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, dbo.I10_Abstracting.NarconMaloxone, 
                         dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, dbo.I10_Abstracting.OccupationalUnits, 
                         dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, dbo.I10_Abstracting.OtherBloodCrossMatched, 
                         dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, 
						 dbo.I10_Abstracting.UniversalEpisodeIdentifier, dbo.I10_Abstracting.UnplannedReadmission, dbo.I10_Abstracting.UnplannedReadmissionDesc, 
                         dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 
						dbo.I10_MB_TransferWorksheet_VR.TransferDays, dbo.I10_MB_TransferWorksheet_VR.TransferInDate, 
                      dbo.I10_MB_TransferWorksheet_VR.TransferInTime, dbo.I10_MB_TransferWorksheet_VR.TransferNursingArea, 
                      dbo.I10_MB_TransferWorksheet_VR.TransferNursingAreaDesc, dbo.I10_MB_TransferWorksheet_VR.TransferNursingUnits, 
                      dbo.I10_MB_TransferWorksheet_VR.TransferOccurrence, dbo.I10_MB_TransferWorksheet_VR.TransferOutDate, dbo.I10_MB_TransferWorksheet_VR.TransferOutTime,
                       dbo.I10_MB_TransferWorksheet_VR.TransferPriority, dbo.I10_MB_TransferWorksheet_VR.TransferPriorityDesc, 
                      dbo.I10_MB_TransferWorksheet_VR.TransferService, dbo.I10_MB_TransferWorksheet_VR.TransferServiceDesc, 
                      dbo.I10_MB_TransferWorksheet_VR.TransferServiceType, dbo.I10_MB_TransferWorksheet_VR.TransferServiceTypeDesc, 
                      dbo.I10_Abstracting.zzAbstractLink, 
                      dbo.I10_Abstracting.zzRegionalPatientID,
                      dbo.I10_Abstracting.zzVolumeLink
FROM         dbo.I10_Abstracting LEFT OUTER JOIN
                      dbo.I10_MB_TransferWorksheet_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_MB_TransferWorksheet_VR.zzAbstractLink


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_PatientService_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_Abstract_And_PatientService_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.HospitalAccountRecord,
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, dbo.I10_Abstracting.InputTime, 
						 dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, 
						 dbo.I10_Abstracting.InstitutionFromType, dbo.I10_Abstracting.InstitutionFromTypeDesc, 
						 dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType, 
						 dbo.I10_Abstracting.InstitutionTo,  dbo.I10_Abstracting.InstitutionToDesc, 
						 dbo.I10_Abstracting.InstitutionToType, dbo.I10_Abstracting.InstitutionToTypeDesc, 
						 dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, 
						 dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, dbo.I10_Abstracting.InterfaceDate, 
                         dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, dbo.I10_Abstracting.IsAbstractCompletedDesc, 
                         dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, dbo.I10_Abstracting.IsAbstractSubmited, 
                         dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, dbo.I10_Abstracting.IsBirthdateEstimatedDesc, 
                         dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, dbo.I10_Abstracting.IsCustomValidatedDesc, 
                         dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, 
                         dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, dbo.I10_Abstracting.MaritalStatusDesc, 
                         dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, dbo.I10_Abstracting.MB_Weight, 
                         dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, dbo.I10_Abstracting.MedicationResuscitation, 
                         dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, dbo.I10_Abstracting.MHFacilityTransferTo, 
                         dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, dbo.I10_Abstracting.NarconMaloxone, 
                         dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, dbo.I10_Abstracting.OccupationalUnits, 
                         dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, dbo.I10_Abstracting.OtherBloodCrossMatched, 
                         dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, 
						 dbo.I10_Abstracting.UniversalEpisodeIdentifier, dbo.I10_Abstracting.UnplannedReadmission, dbo.I10_Abstracting.UnplannedReadmissionDesc, 
                         dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 
					  dbo.I10_PatientService_VR.PatientService, dbo.I10_PatientService_VR.PatientServiceSubService, 
                      dbo.I10_PatientService_VR.PatientServiceSubServiceDesc, dbo.I10_PatientService_VR.PatientServiceDays, dbo.I10_PatientService_VR.PatientServiceOccurrence, 
                      dbo.I10_PatientService_VR.PatientServiceType, dbo.I10_PatientService_VR.PatientServiceTypeDesc, dbo.I10_PatientService_VR.ServiceNurseAreaUnitLoc, 
                      dbo.I10_PatientService_VR.ServiceNursAreaUnitLocDesc, dbo.I10_PatientService_VR.ServiceNursingUnits, dbo.I10_PatientService_VR.TransferInDate, 
                      dbo.I10_PatientService_VR.TransferInTime, dbo.I10_PatientService_VR.TransferOutDate, dbo.I10_PatientService_VR.TransferOutTime, 
                      dbo.I10_Abstracting.zzAbstractLink, 
                      dbo.I10_Abstracting.zzRegionalPatientID,
                      dbo.I10_Abstracting.zzVolumeLink
FROM         dbo.I10_Abstracting LEFT OUTER JOIN
                      dbo.I10_PatientService_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_PatientService_VR.zzAbstractLink


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Projects_100_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_Abstract_And_Projects_100_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.HospitalAccountRecord,
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, dbo.I10_Abstracting.InputTime, 
						 dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, 
						 dbo.I10_Abstracting.InstitutionFromType, dbo.I10_Abstracting.InstitutionFromTypeDesc, 
						 dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType, 
						 dbo.I10_Abstracting.InstitutionTo,  dbo.I10_Abstracting.InstitutionToDesc, 
						 dbo.I10_Abstracting.InstitutionToType, dbo.I10_Abstracting.InstitutionToTypeDesc, 
						 dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, 
						 dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, dbo.I10_Abstracting.InterfaceDate, 
                         dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, dbo.I10_Abstracting.IsAbstractCompletedDesc, 
                         dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, dbo.I10_Abstracting.IsAbstractSubmited, 
                         dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, dbo.I10_Abstracting.IsBirthdateEstimatedDesc, 
                         dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, dbo.I10_Abstracting.IsCustomValidatedDesc, 
                         dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, 
                         dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, dbo.I10_Abstracting.MaritalStatusDesc, 
                         dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, dbo.I10_Abstracting.MB_Weight, 
                         dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, dbo.I10_Abstracting.MedicationResuscitation, 
                         dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, dbo.I10_Abstracting.MHFacilityTransferTo, 
                         dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, dbo.I10_Abstracting.NarconMaloxone, 
                         dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, dbo.I10_Abstracting.OccupationalUnits, 
                         dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, dbo.I10_Abstracting.OtherBloodCrossMatched, 
                         dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, 
						 dbo.I10_Abstracting.UniversalEpisodeIdentifier, dbo.I10_Abstracting.UnplannedReadmission, dbo.I10_Abstracting.UnplannedReadmissionDesc, 
                         dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 
 
                      dbo.I10_Projects_100_VR.ProjectNumber, dbo.I10_Projects_100_VR.ProjectNumberDesc, dbo.I10_Projects_100_VR.ProjectOccurrence, 
                      dbo.I10_Projects_100_VR.CompleteRecordFlag, dbo.I10_Projects_100_VR.CompleteRecordFlagDesc, dbo.I10_Projects_100_VR.RecordAvailable, 
                      dbo.I10_Projects_100_VR.RecordAvailableDesc, dbo.I10_Projects_100_VR.OperativeReportAvailable, dbo.I10_Projects_100_VR.OperativeReportAvailableDesc, 
                      dbo.I10_Projects_100_VR.DischargeSummaryAvailable, dbo.I10_Projects_100_VR.DischargeSummaryAvailableDesc, 
                      dbo.I10_Projects_100_VR.ObstetricalLabourAndDeliverySummaryAvailable, dbo.I10_Projects_100_VR.ObstetricalLabourAndDeliverySummaryAvailableDesc, 
                      dbo.I10_Projects_100_VR.SummarySheetAvailable, dbo.I10_Projects_100_VR.SummarySheetAvailableDesc, 
                      dbo.I10_Projects_100_VR.RecordSubsequentlyReviewedAfterCompletion, dbo.I10_Projects_100_VR.RecordSubsequentlyReviewedAfterCompletionDesc, 
                      dbo.I10_Projects_100_VR.DataChangedFromOriginalSubmission, dbo.I10_Projects_100_VR.DataChangedFromOriginalSubmissionDesc, 
                      dbo.I10_Projects_100_VR.PathologyReportAvailable, dbo.I10_Projects_100_VR.PathologyReportAvailableDesc, dbo.I10_Projects_100_VR.DateofSubsequentReview, 
                      dbo.I10_Projects_100_VR.DateofSubsequentReview_InValidate, dbo.I10_Abstracting.zzAbstractLink, dbo.I10_Abstracting.zzRegionalPatientID, 
                      dbo.I10_Abstracting.zzVolumeLink
FROM         dbo.I10_Abstracting INNER JOIN
                      dbo.I10_Projects_100_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_Projects_100_VR.zzAbstractLink


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Projects_150_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_Abstract_And_Projects_150_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.HospitalAccountRecord,
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, dbo.I10_Abstracting.InputTime, 
						 dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, 
						 dbo.I10_Abstracting.InstitutionFromType, dbo.I10_Abstracting.InstitutionFromTypeDesc, 
						 dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType, 
						 dbo.I10_Abstracting.InstitutionTo,  dbo.I10_Abstracting.InstitutionToDesc, 
						 dbo.I10_Abstracting.InstitutionToType, dbo.I10_Abstracting.InstitutionToTypeDesc, 
						 dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, 
						 dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, dbo.I10_Abstracting.InterfaceDate, 
                         dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, dbo.I10_Abstracting.IsAbstractCompletedDesc, 
                         dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, dbo.I10_Abstracting.IsAbstractSubmited, 
                         dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, dbo.I10_Abstracting.IsBirthdateEstimatedDesc, 
                         dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, dbo.I10_Abstracting.IsCustomValidatedDesc, 
                         dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, 
                         dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, dbo.I10_Abstracting.MaritalStatusDesc, 
                         dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, dbo.I10_Abstracting.MB_Weight, 
                         dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, dbo.I10_Abstracting.MedicationResuscitation, 
                         dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, dbo.I10_Abstracting.MHFacilityTransferTo, 
                         dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, dbo.I10_Abstracting.NarconMaloxone, 
                         dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, dbo.I10_Abstracting.OccupationalUnits, 
                         dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, dbo.I10_Abstracting.OtherBloodCrossMatched, 
                         dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, 
						 dbo.I10_Abstracting.UniversalEpisodeIdentifier, dbo.I10_Abstracting.UnplannedReadmission, dbo.I10_Abstracting.UnplannedReadmissionDesc, 
                         dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 

                      dbo.I10_Projects_150_VR.ProjectNumber, dbo.I10_Projects_150_VR.ProjectNumberDesc, dbo.I10_Projects_150_VR.ProjectOccurrence, 
                      dbo.I10_Projects_150_VR.InterventionLineNumber, dbo.I10_Projects_150_VR.DateCompletedReferralReceived, 
                      dbo.I10_Projects_150_VR.TypeOfSeverityPriorityUrgencyScoreUsed, dbo.I10_Projects_150_VR.TypeOfSeverityPriorityUrgencyScoreUsedDesc, 
                      dbo.I10_Projects_150_VR.SeverityPriorityUrgencyScore, dbo.I10_Projects_150_VR.DateType, dbo.I10_Projects_150_VR.OtherDate, 
                      dbo.I10_Abstracting.zzAbstractLink, dbo.I10_Abstracting.zzRegionalPatientID, dbo.I10_Abstracting.zzVolumeLink
FROM         dbo.I10_Abstracting INNER JOIN
                      dbo.I10_Projects_150_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_Projects_150_VR.zzAbstractLink


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Projects_202_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_Abstract_And_Projects_202_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.HospitalAccountRecord,
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, dbo.I10_Abstracting.InputTime, 
						 dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, 
						 dbo.I10_Abstracting.InstitutionFromType, dbo.I10_Abstracting.InstitutionFromTypeDesc, 
						 dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType, 
						 dbo.I10_Abstracting.InstitutionTo,  dbo.I10_Abstracting.InstitutionToDesc, 
						 dbo.I10_Abstracting.InstitutionToType, dbo.I10_Abstracting.InstitutionToTypeDesc, 
						 dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, 
						 dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, dbo.I10_Abstracting.InterfaceDate, 
                         dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, dbo.I10_Abstracting.IsAbstractCompletedDesc, 
                         dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, dbo.I10_Abstracting.IsAbstractSubmited, 
                         dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, dbo.I10_Abstracting.IsBirthdateEstimatedDesc, 
                         dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, dbo.I10_Abstracting.IsCustomValidatedDesc, 
                         dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, 
                         dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, dbo.I10_Abstracting.MaritalStatusDesc, 
                         dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, dbo.I10_Abstracting.MB_Weight, 
                         dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, dbo.I10_Abstracting.MedicationResuscitation, 
                         dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, dbo.I10_Abstracting.MHFacilityTransferTo, 
                         dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, dbo.I10_Abstracting.NarconMaloxone, 
                         dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, dbo.I10_Abstracting.OccupationalUnits, 
                         dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, dbo.I10_Abstracting.OtherBloodCrossMatched, 
                         dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, 
						 dbo.I10_Abstracting.UniversalEpisodeIdentifier, dbo.I10_Abstracting.UnplannedReadmission, dbo.I10_Abstracting.UnplannedReadmissionDesc, 
                         dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 
 
                      dbo.I10_Projects_202_VR.ProjectNumber, dbo.I10_Projects_202_VR.ProjectNumberDesc, dbo.I10_Projects_202_VR.ProjectOccurrence, 
                      dbo.I10_Projects_202_VR.Kidneys, dbo.I10_Projects_202_VR.KidneysDesc, dbo.I10_Projects_202_VR.Liver, dbo.I10_Projects_202_VR.LiverDesc, 
                      dbo.I10_Projects_202_VR.Heart, dbo.I10_Projects_202_VR.HeartDesc, dbo.I10_Projects_202_VR.Pancreas, dbo.I10_Projects_202_VR.PancreascDesc, 
                      dbo.I10_Projects_202_VR.PancreaticIsletCells, dbo.I10_Projects_202_VR.PancreaticIsletCellsDesc, dbo.I10_Projects_202_VR.Heartvalves, 
                      dbo.I10_Projects_202_VR.HeartvalvesDesc, dbo.I10_Projects_202_VR.Bowel, dbo.I10_Projects_202_VR.BowelDesc, dbo.I10_Projects_202_VR.Cornea, 
                      dbo.I10_Projects_202_VR.CorneaDesc, dbo.I10_Projects_202_VR.Skin, dbo.I10_Projects_202_VR.SkinDesc, dbo.I10_Projects_202_VR.Bone, 
                      dbo.I10_Projects_202_VR.BoneDesc, dbo.I10_Projects_202_VR.Other, dbo.I10_Projects_202_VR.OtherDesc, dbo.I10_Projects_202_VR.Lung, 
                      dbo.I10_Projects_202_VR.LungDesc, dbo.I10_Projects_202_VR.HoursBetweenDeathAndHarvesting, dbo.I10_Projects_202_VR.NumberOfOrgansIssueRetrieveved, 
                      dbo.I10_Projects_202_VR.ORTime, dbo.I10_Abstracting.zzAbstractLink, dbo.I10_Abstracting.zzRegionalPatientID, dbo.I10_Abstracting.zzVolumeLink
FROM         dbo.I10_Abstracting INNER JOIN
                      dbo.I10_Projects_202_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_Projects_202_VR.zzAbstractLink


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Projects_340_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_Abstract_And_Projects_340_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.HospitalAccountRecord,
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, dbo.I10_Abstracting.InputTime, 
						 dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, 
						 dbo.I10_Abstracting.InstitutionFromType, dbo.I10_Abstracting.InstitutionFromTypeDesc, 
						 dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType, 
						 dbo.I10_Abstracting.InstitutionTo,  dbo.I10_Abstracting.InstitutionToDesc, 
						 dbo.I10_Abstracting.InstitutionToType, dbo.I10_Abstracting.InstitutionToTypeDesc, 
						 dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType,
						 dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, dbo.I10_Abstracting.InterfaceDate, 
                         dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, dbo.I10_Abstracting.IsAbstractCompletedDesc, 
                         dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, dbo.I10_Abstracting.IsAbstractSubmited, 
                         dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, dbo.I10_Abstracting.IsBirthdateEstimatedDesc, 
                         dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, dbo.I10_Abstracting.IsCustomValidatedDesc, 
                         dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, 
                         dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, dbo.I10_Abstracting.MaritalStatusDesc, 
                         dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, dbo.I10_Abstracting.MB_Weight, 
                         dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, dbo.I10_Abstracting.MedicationResuscitation, 
                         dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, dbo.I10_Abstracting.MHFacilityTransferTo, 
                         dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, dbo.I10_Abstracting.NarconMaloxone, 
                         dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, dbo.I10_Abstracting.OccupationalUnits, 
                         dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, dbo.I10_Abstracting.OtherBloodCrossMatched, 
                         dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, 
						 dbo.I10_Abstracting.UniversalEpisodeIdentifier, dbo.I10_Abstracting.UnplannedReadmission, dbo.I10_Abstracting.UnplannedReadmissionDesc, 
                         dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 
 
                      dbo.I10_Projects_340_VR.ProjectNumber, dbo.I10_Projects_340_VR.ProjectNumberDesc, dbo.I10_Projects_340_VR.ProjectOccurrence, 
                      dbo.I10_Projects_340_VR.CTScanMRIScanCompletedWithin24Hours, dbo.I10_Projects_340_VR.CTScanMRIScanCompletedWithin24HoursDesc, 
                      dbo.I10_Projects_340_VR.AdmissionToStrokeUnit, dbo.I10_Projects_340_VR.AdmissionToStrokeUnitDesc, 
                      dbo.I10_Projects_340_VR.AdministrationAcuteThrombolysis, dbo.I10_Projects_340_VR.AdministrationAcuteThrombolysisDesc, 
                      dbo.I10_Projects_340_VR.MonthOfAcuteThrombolysisAdministration, dbo.I10_Projects_340_VR.DayOfAcuteThrombolysisAdministration, 
                      dbo.I10_Projects_340_VR.HourOfAcuteThrombolysisAdministration, dbo.I10_Projects_340_VR.MinuteOfAcuteThrombolysisAdministration, 
                      dbo.I10_Projects_340_VR.PrescriptionForAntithromboticMedicationDischarge, dbo.I10_Projects_340_VR.PrescriptionForAntithromboticMedicationDischargeDesc, 
                      dbo.I10_Projects_340_VR.StrokeSymptomOnsetDate, dbo.I10_Projects_340_VR.StrokeSymptomOnsetDateUnknown, 
                      dbo.I10_Projects_340_VR.StrokeSymptomOnsetTime, dbo.I10_Projects_340_VR.StrokeSymptomOnsetTimeUnknown, dbo.I10_Abstracting.zzAbstractLink, 
                      dbo.I10_Abstracting.zzRegionalPatientID, dbo.I10_Abstracting.zzVolumeLink
FROM         dbo.I10_Abstracting INNER JOIN
                      dbo.I10_Projects_340_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_Projects_340_VR.zzAbstractLink







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Projects_640_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_Abstract_And_Projects_640_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.HospitalAccountRecord,
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, dbo.I10_Abstracting.InputTime, 
						 dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, 
						 dbo.I10_Abstracting.InstitutionFromType, dbo.I10_Abstracting.InstitutionFromTypeDesc, 
						 dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType, 
						 dbo.I10_Abstracting.InstitutionTo,  dbo.I10_Abstracting.InstitutionToDesc, 
						 dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, 
						 dbo.I10_Abstracting.InstitutionToType, dbo.I10_Abstracting.InstitutionToTypeDesc, 
						 dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, dbo.I10_Abstracting.InterfaceDate, 
                         dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, dbo.I10_Abstracting.IsAbstractCompletedDesc, 
                         dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, dbo.I10_Abstracting.IsAbstractSubmited, 
                         dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, dbo.I10_Abstracting.IsBirthdateEstimatedDesc, 
                         dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, dbo.I10_Abstracting.IsCustomValidatedDesc, 
                         dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, 
                         dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, dbo.I10_Abstracting.MaritalStatusDesc, 
                         dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, dbo.I10_Abstracting.MB_Weight, 
                         dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, dbo.I10_Abstracting.MedicationResuscitation, 
                         dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, dbo.I10_Abstracting.MHFacilityTransferTo, 
                         dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, dbo.I10_Abstracting.NarconMaloxone, 
                         dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, dbo.I10_Abstracting.OccupationalUnits, 
                         dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, dbo.I10_Abstracting.OtherBloodCrossMatched, 
                         dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, 
						 dbo.I10_Abstracting.UniversalEpisodeIdentifier, dbo.I10_Abstracting.UnplannedReadmission, dbo.I10_Abstracting.UnplannedReadmissionDesc, 
                         dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 
						 dbo.I10_Projects_640_VR.ProjectNumber, 
                         dbo.I10_Projects_640_VR.ProjectNumberDesc, dbo.I10_Projects_640_VR.ProjectOccurrence, dbo.I10_Projects_640_VR.DysphagiaScreening, dbo.I10_Projects_640_VR.DysphagiaScreeningDesc, 
                         dbo.I10_Projects_640_VR.TelestrokeConsultation, dbo.I10_Projects_640_VR.TelestrokeConsultationDesc, dbo.I10_Projects_640_VR.MonthOfStrokeUnitAdmission, 
                         dbo.I10_Projects_640_VR.DayOfStrokeUnitAdmission, dbo.I10_Projects_640_VR.MonthOfStrokeUnitDischarge, dbo.I10_Projects_640_VR.DayOfStrokeUnitDischarge, dbo.I10_Projects_640_VR.TriageDate, TriageDateUnknown,
                         dbo.I10_Projects_640_VR.TriageTime, dbo.I10_Projects_640_VR.TriageTimeUnknown, dbo.I10_Abstracting.zzAbstractLink, dbo.I10_Abstracting.zzRegionalPatientID, dbo.I10_Abstracting.zzVolumeLink
FROM dbo.I10_Abstracting LEFT OUTER JOIN
	dbo.I10_Projects_640_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_Projects_640_VR.zzAbstractLink


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Projects_740_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_Abstract_And_Projects_740_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.HospitalAccountRecord,
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, dbo.I10_Abstracting.InputTime, 
						 dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, 
						 dbo.I10_Abstracting.InstitutionFromType, dbo.I10_Abstracting.InstitutionFromTypeDesc, 
						 dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType, 
						 dbo.I10_Abstracting.InstitutionTo,  dbo.I10_Abstracting.InstitutionToDesc, 
						 dbo.I10_Abstracting.InstitutionToType, dbo.I10_Abstracting.InstitutionToTypeDesc, 
						 dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, 
						 dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, dbo.I10_Abstracting.InterfaceDate, 
                         dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, dbo.I10_Abstracting.IsAbstractCompletedDesc, 
                         dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, dbo.I10_Abstracting.IsAbstractSubmited, 
                         dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, dbo.I10_Abstracting.IsBirthdateEstimatedDesc, 
                         dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, dbo.I10_Abstracting.IsCustomValidatedDesc, 
                         dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, 
                         dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, dbo.I10_Abstracting.MaritalStatusDesc, 
                         dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, dbo.I10_Abstracting.MB_Weight, 
                         dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, dbo.I10_Abstracting.MedicationResuscitation, 
                         dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, dbo.I10_Abstracting.MHFacilityTransferTo, 
                         dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, dbo.I10_Abstracting.NarconMaloxone, 
                         dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, dbo.I10_Abstracting.OccupationalUnits, 
                         dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, dbo.I10_Abstracting.OtherBloodCrossMatched, 
                         dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, 
						 dbo.I10_Abstracting.UniversalEpisodeIdentifier,  dbo.I10_Abstracting.UnplannedReadmission, dbo.I10_Abstracting.UnplannedReadmissionDesc, 
                         dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 
						 dbo.I10_Projects_740_VR.ProjectNumber, 
                         dbo.I10_Projects_740_VR.ProjectNumberDesc, dbo.I10_Projects_740_VR.ProjectOccurrence, dbo.I10_Projects_740_VR.DocumentationAlphaFIM, dbo.I10_Projects_740_VR.DocumentationAlphaFIMDesc, 
                         dbo.I10_Projects_740_VR.AlphaFIMScoreCompletionDate, dbo.I10_Projects_740_VR.ProjectFIMRawMotorRating, dbo.I10_Projects_740_VR.ProjectFIMRawCognitiveRating, dbo.I10_Abstracting.zzAbstractLink, 
                         dbo.I10_Abstracting.zzRegionalPatientID, dbo.I10_Abstracting.zzVolumeLink
FROM            dbo.I10_Abstracting LEFT OUTER JOIN
                         dbo.I10_Projects_740_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_Projects_740_VR.zzAbstractLink






' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Projects_Question_24_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_Abstract_And_Projects_Question_24_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.HospitalAccountRecord,
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, 
                         dbo.I10_Abstracting.InputTime, dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType, dbo.I10_Abstracting.InstitutionTo, 
                         dbo.I10_Abstracting.InstitutionToDesc, dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, dbo.I10_Abstracting.InterfaceDate, 
                         dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, dbo.I10_Abstracting.IsAbstractCompletedDesc, 
                         dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, dbo.I10_Abstracting.IsAbstractSubmited, 
                         dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, dbo.I10_Abstracting.IsBirthdateEstimatedDesc, 
                         dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, dbo.I10_Abstracting.IsCustomValidatedDesc, 
                         dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, 
                         dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, dbo.I10_Abstracting.MaritalStatusDesc, 
                         dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, dbo.I10_Abstracting.MB_Weight, 
                         dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, dbo.I10_Abstracting.MedicationResuscitation, 
                         dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, dbo.I10_Abstracting.MHFacilityTransferTo, 
                         dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, dbo.I10_Abstracting.NarconMaloxone, 
                         dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, dbo.I10_Abstracting.OccupationalUnits, 
                         dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, dbo.I10_Abstracting.OtherBloodCrossMatched, 
                         dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, 
						 dbo.I10_Abstracting.UniversalEpisodeIdentifier, dbo.I10_Abstracting.UnplannedReadmission, dbo.I10_Abstracting.UnplannedReadmissionDesc, 
                         dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 
						 dbo.I10_Projects_Question_24_VR.ProjectNumber, 
                      dbo.I10_Projects_Question_24_VR.ProjectNumberDesc, dbo.I10_Projects_Question_24_VR.ProjectOccurrence, dbo.I10_Projects_Question_24_VR.Question1, dbo.I10_Projects_Question_24_VR.Question1Desc, 
                      dbo.I10_Projects_Question_24_VR.Question2, dbo.I10_Projects_Question_24_VR.Question2Desc, dbo.I10_Projects_Question_24_VR.Question3, dbo.I10_Projects_Question_24_VR.Question3Desc, 
                      dbo.I10_Projects_Question_24_VR.Question4, dbo.I10_Projects_Question_24_VR.Question4Desc, dbo.I10_Projects_Question_24_VR.Question5, dbo.I10_Projects_Question_24_VR.Question5Desc, 
                      dbo.I10_Projects_Question_24_VR.Question6, dbo.I10_Projects_Question_24_VR.Question6Desc, dbo.I10_Projects_Question_24_VR.Question7, dbo.I10_Projects_Question_24_VR.Question7Desc, 
                      dbo.I10_Projects_Question_24_VR.Question8, dbo.I10_Projects_Question_24_VR.Question8Desc, dbo.I10_Projects_Question_24_VR.Question9, dbo.I10_Projects_Question_24_VR.Question9Desc, 
                      dbo.I10_Projects_Question_24_VR.Question10, dbo.I10_Projects_Question_24_VR.Question10Desc, dbo.I10_Projects_Question_24_VR.Question11, dbo.I10_Projects_Question_24_VR.Question11Desc, 
                      dbo.I10_Projects_Question_24_VR.Question12, dbo.I10_Projects_Question_24_VR.Question12Desc, dbo.I10_Projects_Question_24_VR.Question13, dbo.I10_Projects_Question_24_VR.Question13Desc, 
                      dbo.I10_Projects_Question_24_VR.Question14, dbo.I10_Projects_Question_24_VR.Question15, dbo.I10_Projects_Question_24_VR.Question16, dbo.I10_Projects_Question_24_VR.Question17, 
                      dbo.I10_Projects_Question_24_VR.Question18, dbo.I10_Projects_Question_24_VR.Question19, dbo.I10_Projects_Question_24_VR.Question20, dbo.I10_Projects_Question_24_VR.Question21, 
                      dbo.I10_Projects_Question_24_VR.Question22, dbo.I10_Projects_Question_24_VR.Question23, dbo.I10_Projects_Question_24_VR.Question24, 
                      dbo.I10_Abstracting.zzAbstractLink, 
                      dbo.I10_Abstracting.zzRegionalPatientID,
                      dbo.I10_Abstracting.zzVolumeLink
FROM         dbo.I10_Abstracting LEFT OUTER JOIN
                      dbo.I10_Projects_Question_24_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_Projects_Question_24_VR.zzAbstractLink









' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Projects_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_Abstract_And_Projects_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc,  dbo.I10_Abstracting.HospitalAccountRecord,
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, dbo.I10_Abstracting.InputTime, 
						 dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, 
						 dbo.I10_Abstracting.InstitutionFromType, dbo.I10_Abstracting.InstitutionFromTypeDesc, 
						 dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType, 
						 dbo.I10_Abstracting.InstitutionTo,  dbo.I10_Abstracting.InstitutionToDesc, 
						 dbo.I10_Abstracting.InstitutionToType, dbo.I10_Abstracting.InstitutionToTypeDesc, 
						 dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, 
						 dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, dbo.I10_Abstracting.InterfaceDate, 
                         dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, dbo.I10_Abstracting.IsAbstractCompletedDesc, 
                         dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, dbo.I10_Abstracting.IsAbstractSubmited, 
                         dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, dbo.I10_Abstracting.IsBirthdateEstimatedDesc, 
                         dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, dbo.I10_Abstracting.IsCustomValidatedDesc, 
                         dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, 
                         dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, dbo.I10_Abstracting.MaritalStatusDesc, 
                         dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, dbo.I10_Abstracting.MB_Weight, 
                         dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, dbo.I10_Abstracting.MedicationResuscitation, 
                         dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, dbo.I10_Abstracting.MHFacilityTransferTo, 
                         dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, dbo.I10_Abstracting.NarconMaloxone, 
                         dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, dbo.I10_Abstracting.OccupationalUnits, 
                         dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, dbo.I10_Abstracting.OtherBloodCrossMatched, 
                         dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, 
						 dbo.I10_Abstracting.UniversalEpisodeIdentifier, dbo.I10_Abstracting.UnplannedReadmission, dbo.I10_Abstracting.UnplannedReadmissionDesc, 
                         dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 
						dbo.I10_Projects_VR.ProjectNumber, 
                      dbo.I10_Projects_VR.ProjectNumberDesc, dbo.I10_Projects_VR.ProjectOccurrence, dbo.I10_Projects_VR.Question1, dbo.I10_Projects_VR.Question1Desc, 
                      dbo.I10_Projects_VR.Question2, dbo.I10_Projects_VR.Question2Desc, dbo.I10_Projects_VR.Question3, dbo.I10_Projects_VR.Question3Desc, 
                      dbo.I10_Projects_VR.Question4, dbo.I10_Projects_VR.Question4Desc, dbo.I10_Projects_VR.Question5, dbo.I10_Projects_VR.Question5Desc, 
                      dbo.I10_Projects_VR.Question6, dbo.I10_Projects_VR.Question6Desc, dbo.I10_Projects_VR.Question7, dbo.I10_Projects_VR.Question7Desc, 
                      dbo.I10_Projects_VR.Question8, dbo.I10_Projects_VR.Question8Desc, dbo.I10_Projects_VR.Question9, dbo.I10_Projects_VR.Question9Desc, 
                      dbo.I10_Projects_VR.Question10, dbo.I10_Projects_VR.Question10Desc, dbo.I10_Projects_VR.Question11, dbo.I10_Projects_VR.Question11Desc, 
                      dbo.I10_Projects_VR.Question12, dbo.I10_Projects_VR.Question12Desc, dbo.I10_Projects_VR.Question13, dbo.I10_Projects_VR.Question13Desc, 
                      dbo.I10_Projects_VR.Question14, dbo.I10_Projects_VR.Question15, dbo.I10_Projects_VR.Question16, dbo.I10_Projects_VR.Question17, 
                      --dbo.I10_Projects_VR.Question18, dbo.I10_Projects_VR.Question19, dbo.I10_Projects_VR.Question20, dbo.I10_Projects_VR.Question21, 
                      --dbo.I10_Projects_VR.Question22, dbo.I10_Projects_VR.Question23, dbo.I10_Projects_VR.Question24, 
                      dbo.I10_Abstracting.zzAbstractLink, 
                      dbo.I10_Abstracting.zzRegionalPatientID,
                      dbo.I10_Abstracting.zzVolumeLink
FROM         dbo.I10_Abstracting LEFT OUTER JOIN
                      dbo.I10_Projects_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_Projects_VR.zzAbstractLink




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_Provider_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_Abstract_And_Provider_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.HospitalAccountRecord,
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, dbo.I10_Abstracting.InputTime, 
						 dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, 
						 dbo.I10_Abstracting.InstitutionFromType, dbo.I10_Abstracting.InstitutionFromTypeDesc, 
						 dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType, 
						 dbo.I10_Abstracting.InstitutionTo, dbo.I10_Abstracting.InstitutionToDesc, 
						 dbo.I10_Abstracting.InstitutionToType, dbo.I10_Abstracting.InstitutionToTypeDesc, 
						 dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, 
						 dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, dbo.I10_Abstracting.InterfaceDate, 
                         dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, dbo.I10_Abstracting.IsAbstractCompletedDesc, 
                         dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, dbo.I10_Abstracting.IsAbstractSubmited, 
                         dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, dbo.I10_Abstracting.IsBirthdateEstimatedDesc, 
                         dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, dbo.I10_Abstracting.IsCustomValidatedDesc, 
                         dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, 
                         dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, dbo.I10_Abstracting.MaritalStatusDesc, 
                         dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, dbo.I10_Abstracting.MB_Weight, 
                         dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, dbo.I10_Abstracting.MedicationResuscitation, 
                         dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, dbo.I10_Abstracting.MHFacilityTransferTo, 
                         dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, dbo.I10_Abstracting.NarconMaloxone, 
                         dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, dbo.I10_Abstracting.OccupationalUnits, 
                         dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, dbo.I10_Abstracting.OtherBloodCrossMatched, 
                         dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, 
						 dbo.I10_Abstracting.UniversalEpisodeIdentifier, dbo.I10_Abstracting.UnplannedReadmission, dbo.I10_Abstracting.UnplannedReadmissionDesc, 
                         dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 
						 dbo.I10_Provider_VR.ProviderNumber, dbo.I10_Provider_VR.ProviderNumberDesc, dbo.I10_Provider_VR.ProviderOccurrence, 
                      dbo.I10_Provider_VR.ProviderService, dbo.I10_Provider_VR.ProviderServiceDesc, dbo.I10_Provider_VR.ProviderType, dbo.I10_Provider_VR.ProviderTypeDesc, 
                      dbo.I10_Abstracting.zzAbstractLink, 
                      dbo.I10_Abstracting.zzRegionalPatientID,
                      dbo.I10_Abstracting.zzVolumeLink
FROM         dbo.I10_Abstracting LEFT OUTER JOIN
                      dbo.I10_Provider_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_Provider_VR.zzAbstractLink


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Abstract_And_SCU_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[I10_Abstract_And_SCU_VR]
AS
SELECT        dbo.I10_Abstracting.[#ofPreviousDeliveries], dbo.I10_Abstracting.[#ofPreviousLiveBirths], dbo.I10_Abstracting.[#ofPreviousPreTermDeliveries], dbo.I10_Abstracting.[#ofPrevSpontaneousAbortions], 
                         dbo.I10_Abstracting.[#ofPrevTherapueticAbortions], dbo.I10_Abstracting.ALCLOS, dbo.I10_Abstracting.AWOL, dbo.I10_Abstracting.AWOLDesc, dbo.I10_Abstracting.AbstractNumber, dbo.I10_Abstracting.AbstractOverflow, 
                         dbo.I10_Abstracting.AbstractOverflowDesc, dbo.I10_Abstracting.AbstractType, dbo.I10_Abstracting.AbstractTypeDesc, dbo.I10_Abstracting.AcuteLOS, dbo.I10_Abstracting.AdmissionDate, dbo.I10_Abstracting.AdmissionTime, 
                         dbo.I10_Abstracting.AdmissionTimeUnknown, dbo.I10_Abstracting.AdmissionTimeUnknownDesc, dbo.I10_Abstracting.AdmitbyAmbulance, dbo.I10_Abstracting.AdmitbyAmbulanceDesc, dbo.I10_Abstracting.AdmitCategory, 
                         dbo.I10_Abstracting.AdmitCategoryDesc, dbo.I10_Abstracting.AdmitNursingAreaUnitLocation, dbo.I10_Abstracting.AdmittingNursingAreaUnitLDesc, dbo.I10_Abstracting.AgeCode, dbo.I10_Abstracting.AgeCodeDesc, 
                         dbo.I10_Abstracting.AgeGroup, dbo.I10_Abstracting.AgeNumber, dbo.I10_Abstracting.AgeUponDischarge, dbo.I10_Abstracting.AgeUponDischargeCode, dbo.I10_Abstracting.AgeUponDischargeCodeDesc, 
                         dbo.I10_Abstracting.Albumin, dbo.I10_Abstracting.AlbuminCrossMatched, dbo.I10_Abstracting.AlbuminCrossMatchedDesc, dbo.I10_Abstracting.AlbuminDesc, dbo.I10_Abstracting.AlbuminTyped, 
                         dbo.I10_Abstracting.AlbuminTypedDesc, dbo.I10_Abstracting.AlbuminUnits, dbo.I10_Abstracting.AlcoholDuringPregnancy, dbo.I10_Abstracting.AlcoholDuringPregnancyDesc, dbo.I10_Abstracting.AlcoholQuitDate, 
                         dbo.I10_Abstracting.AlcoholQuitDateUnknown, dbo.I10_Abstracting.AlcoholQuitDateUnknownDesc, dbo.I10_Abstracting.AnalgesicAnestheticDuringLabor, dbo.I10_Abstracting.AnalgesicAnestheticDuringLaborDesc, 
                         dbo.I10_Abstracting.AncillaryField1, dbo.I10_Abstracting.AncillaryField1Desc, dbo.I10_Abstracting.AncillaryField10, dbo.I10_Abstracting.AncillaryField10Desc, dbo.I10_Abstracting.AncillaryField11, 
                         dbo.I10_Abstracting.AncillaryField11Desc, dbo.I10_Abstracting.AncillaryField12, dbo.I10_Abstracting.AncillaryField12Desc, dbo.I10_Abstracting.AncillaryField13, dbo.I10_Abstracting.AncillaryField13Desc, 
                         dbo.I10_Abstracting.AncillaryField14, dbo.I10_Abstracting.AncillaryField14Desc, dbo.I10_Abstracting.AncillaryField15, dbo.I10_Abstracting.AncillaryField15Desc, dbo.I10_Abstracting.AncillaryField16, 
                         dbo.I10_Abstracting.AncillaryField16Desc, dbo.I10_Abstracting.AncillaryField17, dbo.I10_Abstracting.AncillaryField17Desc, dbo.I10_Abstracting.AncillaryField2, dbo.I10_Abstracting.AncillaryField2Desc, 
                         dbo.I10_Abstracting.AncillaryField3, dbo.I10_Abstracting.AncillaryField3Desc, dbo.I10_Abstracting.AncillaryField4, dbo.I10_Abstracting.AncillaryField4Desc, dbo.I10_Abstracting.AncillaryField5, 
                         dbo.I10_Abstracting.AncillaryField5Desc, dbo.I10_Abstracting.AncillaryField6, dbo.I10_Abstracting.AncillaryField6Desc, dbo.I10_Abstracting.AncillaryField7, dbo.I10_Abstracting.AncillaryField7Desc, 
                         dbo.I10_Abstracting.AncillaryField8, dbo.I10_Abstracting.AncillaryField8Desc, dbo.I10_Abstracting.AncillaryField9, dbo.I10_Abstracting.AncillaryField9Desc, dbo.I10_Abstracting.Apgar1Min, dbo.I10_Abstracting.Apgar5Min, 
                         dbo.I10_Abstracting.ArrivalDateInER, dbo.I10_Abstracting.ArrivalTimeInER, dbo.I10_Abstracting.AttendingPhysician, dbo.I10_Abstracting.AttendingPhysicianDesc, dbo.I10_Abstracting.AutoTransfusion, 
                         dbo.I10_Abstracting.AutoTransfusionDesc, dbo.I10_Abstracting.AutopsyPerformed, dbo.I10_Abstracting.AutopsyPerformedDesc, dbo.I10_Abstracting.BagVentilation, dbo.I10_Abstracting.BagVentilationDesc, 
                         dbo.I10_Abstracting.BasicOption1, dbo.I10_Abstracting.BasicOption1Desc, dbo.I10_Abstracting.BasicOption10, dbo.I10_Abstracting.BasicOption10Desc, dbo.I10_Abstracting.BasicOption11, 
                         dbo.I10_Abstracting.BasicOption11Desc, dbo.I10_Abstracting.BasicOption12, dbo.I10_Abstracting.BasicOption12Desc, dbo.I10_Abstracting.BasicOption13, dbo.I10_Abstracting.BasicOption13Desc, 
                         dbo.I10_Abstracting.BasicOption14, dbo.I10_Abstracting.BasicOption14Desc, dbo.I10_Abstracting.BasicOption15, dbo.I10_Abstracting.BasicOption15Desc, dbo.I10_Abstracting.BasicOption16, 
                         dbo.I10_Abstracting.BasicOption16Desc, dbo.I10_Abstracting.BasicOption17, dbo.I10_Abstracting.BasicOption17Desc, dbo.I10_Abstracting.BasicOption18, dbo.I10_Abstracting.BasicOption18Desc, 
                         dbo.I10_Abstracting.BasicOption19, dbo.I10_Abstracting.BasicOption19Desc, dbo.I10_Abstracting.BasicOption2, dbo.I10_Abstracting.BasicOption2Desc, dbo.I10_Abstracting.BasicOption3, 
                         dbo.I10_Abstracting.BasicOption3Desc, dbo.I10_Abstracting.BasicOption4, dbo.I10_Abstracting.BasicOption4Desc, dbo.I10_Abstracting.BasicOption5, dbo.I10_Abstracting.BasicOption5Desc, dbo.I10_Abstracting.BasicOption6, 
                         dbo.I10_Abstracting.BasicOption6Desc, dbo.I10_Abstracting.BasicOption7, dbo.I10_Abstracting.BasicOption7Desc, dbo.I10_Abstracting.BasicOption8, dbo.I10_Abstracting.BasicOption8Desc, dbo.I10_Abstracting.BasicOption9, 
                         dbo.I10_Abstracting.BasicOption9Desc, dbo.I10_Abstracting.BatchNumber, dbo.I10_Abstracting.BatchPeriod, dbo.I10_Abstracting.BatchPeriodDesc, dbo.I10_Abstracting.BatchPeriod_BC, dbo.I10_Abstracting.BatchYear, 
                         dbo.I10_Abstracting.Between210DaysPostOp, dbo.I10_Abstracting.Between210DaysPostOpDesc, dbo.I10_Abstracting.BirthDate, dbo.I10_Abstracting.Blood_AntithrombinIII, dbo.I10_Abstracting.Blood_AntithrombinIIIDesc, 
                         dbo.I10_Abstracting.Blood_C1Inhibitor, dbo.I10_Abstracting.Blood_C1InhibitorDesc, dbo.I10_Abstracting.Blood_CryoprecipitatePlasma, dbo.I10_Abstracting.Blood_CryoprecipitatePlasmaDesc, 
                         dbo.I10_Abstracting.Blood_CryosupernatantPlasma, dbo.I10_Abstracting.Blood_CryosupernatantPlasmaDesc, dbo.I10_Abstracting.Blood_FEIBA, dbo.I10_Abstracting.Blood_FEIBADesc, dbo.I10_Abstracting.Blood_Fibrinogen, 
                         dbo.I10_Abstracting.Blood_FibrinogenDesc, dbo.I10_Abstracting.Blood_IVIG_SCIG, dbo.I10_Abstracting.Blood_IVIG_SCIGDesc, dbo.I10_Abstracting.Blood_PCC, dbo.I10_Abstracting.Blood_PCCDesc, 
                         dbo.I10_Abstracting.Blood_ProteinC_OtherFactors, dbo.I10_Abstracting.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Abstracting.BreastFeedingonDischarge, dbo.I10_Abstracting.BreastFeedingonDischargeDesc, 
                         dbo.I10_Abstracting.CareType, dbo.I10_Abstracting.CareTypeDesc, dbo.I10_Abstracting.ChangeinLegalStatus, dbo.I10_Abstracting.ChangeinLegalStatusDesc, dbo.I10_Abstracting.ChartNumber, 
                         dbo.I10_Abstracting.ChestCompressions, dbo.I10_Abstracting.ChestCompressionsDesc, dbo.I10_Abstracting.ChiefComplaintUponAdmission, dbo.I10_Abstracting.ClinicalMetastasis, dbo.I10_Abstracting.ClinicalNode, 
                         dbo.I10_Abstracting.ClinicalTumor, dbo.I10_Abstracting.CoderNumber, dbo.I10_Abstracting.CoderNumberDesc, dbo.I10_Abstracting.Comorbidity, dbo.I10_Abstracting.ComorbidityDesc, dbo.I10_Abstracting.Complication, 
                         dbo.I10_Abstracting.ComplicationDesc, dbo.I10_Abstracting.Complication1, dbo.I10_Abstracting.Complication1Desc, dbo.I10_Abstracting.Complication2, dbo.I10_Abstracting.Complication2Desc, 
                         dbo.I10_Abstracting.Complication3, dbo.I10_Abstracting.Complication3Desc, dbo.I10_Abstracting.CoronerCase, dbo.I10_Abstracting.CoronerCaseDesc, dbo.I10_Abstracting.DataEntryCoder, 
                         dbo.I10_Abstracting.DataEntryCoderDesc, dbo.I10_Abstracting.DateofLastMenses, dbo.I10_Abstracting.DateReadyForDischarge, dbo.I10_Abstracting.DateSenttoCIHI, dbo.I10_Abstracting.Days_WeekAlcoholConsumed, 
                         dbo.I10_Abstracting.Days_WeekAlcoholConsumedDesc, dbo.I10_Abstracting.DeathInOR, dbo.I10_Abstracting.DeathInORDesc, dbo.I10_Abstracting.DeathInSCU, dbo.I10_Abstracting.DeathInSCUDesc, 
                         dbo.I10_Abstracting.DeclarationNumber, dbo.I10_Abstracting.DeliveryDate, dbo.I10_Abstracting.DeliveryTime, dbo.I10_Abstracting.DischargeDate, dbo.I10_Abstracting.DischargeDisposition, 
                         dbo.I10_Abstracting.DischargeDispositionDesc, dbo.I10_Abstracting.DischNursingAreaUnitLocation, dbo.I10_Abstracting.DischargeNursingAreaUnitDesc, dbo.I10_Abstracting.DischargePlanning, 
                         dbo.I10_Abstracting.DischargePlanningDesc, dbo.I10_Abstracting.DischargeTime, dbo.I10_Abstracting.DischargeTimeUnknown, dbo.I10_Abstracting.DischargeTimeUnknownDesc, dbo.I10_Abstracting.DrinksPerday, 
                         dbo.I10_Abstracting.DurationALCDays, dbo.I10_Abstracting.ECTTreatment, dbo.I10_Abstracting.ECTTreatmentDesc, dbo.I10_Abstracting.Education, dbo.I10_Abstracting.EducationDesc, dbo.I10_Abstracting.Elopements, 
                         dbo.I10_Abstracting.ElopementsDesc, dbo.I10_Abstracting.EmployerName, dbo.I10_Abstracting.Employment, dbo.I10_Abstracting.EmploymentDesc, dbo.I10_Abstracting.EncounterNumber, dbo.I10_Abstracting.EntryCode, 
                         dbo.I10_Abstracting.EntryCodeDesc, dbo.I10_Abstracting.ERDatePatientLeft, dbo.I10_Abstracting.ERDecisiontoAdmitDate, dbo.I10_Abstracting.ERDecisiontoAdmitTime, dbo.I10_Abstracting.ERDecisionAdmitTimeUnknown, 
                         dbo.I10_Abstracting.ERDecisionAdmitTimeUnknownDesc, dbo.I10_Abstracting.ERTimePatientLeft, dbo.I10_Abstracting.ERTimePatientLeftUnknown, dbo.I10_Abstracting.ERTimePatientLeftUnknownDesc, 
                         dbo.I10_Abstracting.Feeding, dbo.I10_Abstracting.FeedingDesc, dbo.I10_Abstracting.FinancialSupport, dbo.I10_Abstracting.FinancialSupportDesc, dbo.I10_Abstracting.FinishDate, dbo.I10_Abstracting.FinishTime, 
                         dbo.I10_Abstracting.FirstName, dbo.I10_Abstracting.FirstOptionalTherapy, dbo.I10_Abstracting.FirstOptionalTherapyDesc, dbo.I10_Abstracting.FirstOptionalUnits, dbo.I10_Abstracting.FirstStageDuration, 
                         dbo.I10_Abstracting.FixedChartNumber, dbo.I10_Abstracting.FreeFlowOxygen, dbo.I10_Abstracting.FreeFlowOxygenDesc, dbo.I10_Abstracting.Gender, dbo.I10_Abstracting.GenderDesc, dbo.I10_Abstracting.Gestation, 
                         dbo.I10_Abstracting.GestationalAgeinweeks, dbo.I10_Abstracting.GlasgowComaScale, dbo.I10_Abstracting.GlasgowComaScaleDesc, dbo.I10_Abstracting.Gravida, dbo.I10_Abstracting.Greaterthan10DaysPostOp, 
                         dbo.I10_Abstracting.Greaterthan10DaysPostOpDesc, dbo.I10_Abstracting.HCNProvince, dbo.I10_Abstracting.HCNProvinceDesc, dbo.I10_Abstracting.HCNVersion, dbo.I10_Abstracting.HealthCareNumber, 
                         dbo.I10_Abstracting.Height, dbo.I10_Abstracting.Hospital, dbo.I10_Abstracting.HospitalDesc, dbo.I10_Abstracting.HospitalAccountRecord,
                         dbo.I10_Abstracting.ICDType, dbo.I10_Abstracting.InitialOR, dbo.I10_Abstracting.InitialORDesc, dbo.I10_Abstracting.InputDate, dbo.I10_Abstracting.InputTime, 
						 dbo.I10_Abstracting.InstitutionFrom, dbo.I10_Abstracting.InstitutionFromDesc, 
						 dbo.I10_Abstracting.InstitutionFromType, dbo.I10_Abstracting.InstitutionFromTypeDesc, 
						 dbo.I10_Abstracting.InstFromCareType, dbo.I10_Abstracting.InstFromHospType, 
						 dbo.I10_Abstracting.InstitutionTo,   dbo.I10_Abstracting.InstitutionToDesc, 
						 dbo.I10_Abstracting.InstitutionToType, dbo.I10_Abstracting.InstitutionToTypeDesc, 
						 dbo.I10_Abstracting.InstToCareType, dbo.I10_Abstracting.InstToHospType, 
						 dbo.I10_Abstracting.InterfaceCoder, dbo.I10_Abstracting.InterfaceCoderDesc, dbo.I10_Abstracting.InterfaceDate, 
                         dbo.I10_Abstracting.InterfaceTime, dbo.I10_Abstracting.IntubationNotMeconium, dbo.I10_Abstracting.IntubationNotMeconiumDesc, dbo.I10_Abstracting.IsAbstractCompleted, dbo.I10_Abstracting.IsAbstractCompletedDesc, 
                         dbo.I10_Abstracting.IsAbstractCorrected, dbo.I10_Abstracting.IsAbstractCorrectedDesc, dbo.I10_Abstracting.IsAbstractDeleted, dbo.I10_Abstracting.IsAbstractDeletedDesc, dbo.I10_Abstracting.IsAbstractSubmited, 
                         dbo.I10_Abstracting.IsAbstractSubmitedDesc, dbo.I10_Abstracting.IsAbstractValidated, dbo.I10_Abstracting.IsAbstractValidatedDesc, dbo.I10_Abstracting.IsBirthdateEstimated, dbo.I10_Abstracting.IsBirthdateEstimatedDesc, 
                         dbo.I10_Abstracting.LeaveCertificates, dbo.I10_Abstracting.LeaveCertificatesDesc, dbo.I10_Abstracting.LOSDays, dbo.I10_Abstracting.IsCustomValidated, dbo.I10_Abstracting.IsCustomValidatedDesc, 
                         dbo.I10_Abstracting.LOSMinutes, dbo.I10_Abstracting.LOSTimeinHours, dbo.I10_Abstracting.LastName, dbo.I10_Abstracting.Lessthan2DaysAfterAdmission, dbo.I10_Abstracting.Lessthan2DaysAfterAdmitDesc, 
                         dbo.I10_Abstracting.Lessthan2DaysPostOp, dbo.I10_Abstracting.Lessthan2DaysPostOpDesc, dbo.I10_Abstracting.MaidenName, dbo.I10_Abstracting.MaritalStatus, dbo.I10_Abstracting.MaritalStatusDesc, 
                         dbo.I10_Abstracting.MaternalNewbornChartNumber, dbo.I10_Abstracting.MaternalNewbornDischargeDate, dbo.I10_Abstracting.MB_Autopsy, dbo.I10_Abstracting.MB_AutopsyDesc, dbo.I10_Abstracting.MB_Weight, 
                         dbo.I10_Abstracting.MBEducation, dbo.I10_Abstracting.MBEducationDesc, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoED, dbo.I10_Abstracting.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
                         dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmission, dbo.I10_Abstracting.MentalHealth_LegalStatusAtAdmissionDesc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04, dbo.I10_Abstracting.MentalHealth_TypeOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_02Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04, dbo.I10_Abstracting.MentalHealth_FrequencyOfRestraint_04Desc, 
                         dbo.I10_Abstracting.MethodofAdmission, dbo.I10_Abstracting.MethodofAdmissionDesc, dbo.I10_Abstracting.Meconium, dbo.I10_Abstracting.MeconiumDesc, dbo.I10_Abstracting.MedicationResuscitation, 
                         dbo.I10_Abstracting.MedicationResuscitationDesc, dbo.I10_Abstracting.MHFacilityTransferFrom, dbo.I10_Abstracting.MHFacilityTransferFromDesc, dbo.I10_Abstracting.MHFacilityTransferTo, 
                         dbo.I10_Abstracting.MHFacilityTransferToDesc, dbo.I10_Abstracting.MiddleName, dbo.I10_Abstracting.MotherPHIN, dbo.I10_Abstracting.NameFull, dbo.I10_Abstracting.NarconMaloxone, 
                         dbo.I10_Abstracting.NarconMaloxoneDesc, dbo.I10_Abstracting.NumberofECT, dbo.I10_Abstracting.OccupationalTherapy, dbo.I10_Abstracting.OccupationalTherapyDesc, dbo.I10_Abstracting.OccupationalUnits, 
                         dbo.I10_Abstracting.OtherMedicalDeath, dbo.I10_Abstracting.OtherMedicalDeathDesc, dbo.I10_Abstracting.OtherBlood, dbo.I10_Abstracting.OtherBloodDesc, dbo.I10_Abstracting.OtherBloodCrossMatched, 
                         dbo.I10_Abstracting.OtherBloodCrossMatchedDesc, dbo.I10_Abstracting.OtherBloodTyped, dbo.I10_Abstracting.OtherBloodTypedDesc, dbo.I10_Abstracting.OtherBloodUnits, 
                         dbo.I10_Abstracting.OutProvinceHealthInsuranceExpiryDate, dbo.I10_Abstracting.Parity, dbo.I10_Abstracting.PathologicalMetastasis, dbo.I10_Abstracting.PathologicalNode, dbo.I10_Abstracting.PathologicalTumor, 
                         dbo.I10_Abstracting.PhysioUnits, dbo.I10_Abstracting.Physiotherapy, dbo.I10_Abstracting.PhysiotherapyDesc, dbo.I10_Abstracting.Plasma, dbo.I10_Abstracting.PlasmaDesc, dbo.I10_Abstracting.PlasmaCrossMatched, 
                         dbo.I10_Abstracting.PlasmaCrossMatchedDesc, dbo.I10_Abstracting.PlasmaTyped, dbo.I10_Abstracting.PlasmaTypedDesc, dbo.I10_Abstracting.PlasmaUnits, dbo.I10_Abstracting.Platelets, dbo.I10_Abstracting.PlateletsDesc, 
                         dbo.I10_Abstracting.PlateletsCrossMatched, dbo.I10_Abstracting.PlateletsCrossMatchedDesc, dbo.I10_Abstracting.PlateletsTyped, dbo.I10_Abstracting.PlateletsTypedDesc, dbo.I10_Abstracting.PlateletsUnits, 
                         dbo.I10_Abstracting.PositionatDelivery, dbo.I10_Abstracting.PositionatDeliveryDesc, dbo.I10_Abstracting.PostalCode, dbo.I10_Abstracting.PostalCodeDesc, dbo.I10_Abstracting.PostOpDays, 
                         dbo.I10_Abstracting.PostConceptionalFolicAcid, dbo.I10_Abstracting.PostConceptionalFolicAcidDesc, dbo.I10_Abstracting.PreAdmitWorkup, dbo.I10_Abstracting.PreAdmitWorkupDesc, 
                         dbo.I10_Abstracting.PreConceptionalFolicAcid, dbo.I10_Abstracting.PreConceptionalFolicAcidDesc, dbo.I10_Abstracting.Pregnancy, dbo.I10_Abstracting.PregnancyDesc, dbo.I10_Abstracting.PreOpDays, 
                         dbo.I10_Abstracting.PrenatalVisitsNumber, dbo.I10_Abstracting.PrenatalVisitDate, dbo.I10_Abstracting.PrenatalVisitDateUnknown, dbo.I10_Abstracting.PrenatalVisitDateUnknownDesc, dbo.I10_Abstracting.Presentation, 
                         dbo.I10_Abstracting.PresentationDesc, dbo.I10_Abstracting.PresentationatDelivery, dbo.I10_Abstracting.PresentationatDeliveryDesc, dbo.I10_Abstracting.PreviousName, dbo.I10_Abstracting.PreviousPsychiartricAdmissions, 
                         dbo.I10_Abstracting.PreviousPsychiartricAdmDesc, dbo.I10_Abstracting.PrimaryPhone, dbo.I10_Abstracting.PrimaryAddress, dbo.I10_Abstracting.PrimaryAddress2, dbo.I10_Abstracting.ReAdmitCode, 
                         dbo.I10_Abstracting.ReAdmitCodeDesc, dbo.I10_Abstracting.ReciprocalBillingStatus, dbo.I10_Abstracting.ReciprocalBillingStatusDesc, dbo.I10_Abstracting.RedBloodCell, dbo.I10_Abstracting.RedBloodCellDesc, 
                         dbo.I10_Abstracting.RedBloodCellCrossMatched, dbo.I10_Abstracting.RedBloodCellCrossMatchedDesc, dbo.I10_Abstracting.RedBloodCellTyped, dbo.I10_Abstracting.RedBloodCellTypedDesc, 
                         dbo.I10_Abstracting.RedBloodCellUnits, dbo.I10_Abstracting.ReferredTo, dbo.I10_Abstracting.ReferredToDesc, dbo.I10_Abstracting.ReferringProvider, dbo.I10_Abstracting.ReferringProviderDesc, 
                         dbo.I10_Abstracting.RegisterNumber, dbo.I10_Abstracting.RegistrantGivenName, dbo.I10_Abstracting.RegistrantSurname, dbo.I10_Abstracting.ReportingProvInstNumber, dbo.I10_Abstracting.ReportingProvInstNumberDesc, 
                         dbo.I10_Abstracting.ReproductiveCareComments, dbo.I10_Abstracting.ResidenceCode, dbo.I10_Abstracting.ResidenceCodeDesc, dbo.I10_Abstracting.ResidenceProvince, dbo.I10_Abstracting.ResidenceProvinceDesc, 
                         dbo.I10_Abstracting.ResidenceRegion, dbo.I10_Abstracting.ResidenceRegionDesc, dbo.I10_Abstracting.RespiratoryTherapy, dbo.I10_Abstracting.RespiratoryTherapyDesc, dbo.I10_Abstracting.RespiratoryUnits, 
                         dbo.I10_Abstracting.ResponsiblityForPayment, dbo.I10_Abstracting.ResponsiblityForPaymentDesc, dbo.I10_Abstracting.RoutineCare, dbo.I10_Abstracting.RoutineCareDesc, dbo.I10_Abstracting.SecondChartRegisterNumber, 
                         dbo.I10_Abstracting.SecondOptionalTherapy, dbo.I10_Abstracting.SecondOptionalTherapyDesc, dbo.I10_Abstracting.SecondOptionalUnits, dbo.I10_Abstracting.SecretVIPPatient, dbo.I10_Abstracting.SecretVIPPatientDesc, 
                         dbo.I10_Abstracting.SiteNumber, dbo.I10_Abstracting.SiteNumberDesc, dbo.I10_Abstracting.SocialServices, dbo.I10_Abstracting.SocialServicesDesc, dbo.I10_Abstracting.SmokingInPregnancy, 
                         dbo.I10_Abstracting.SmokingInPregnancyDesc, dbo.I10_Abstracting.SmokingPerDay, dbo.I10_Abstracting.SmokingQuitDate, dbo.I10_Abstracting.SmokingQuitDateUnknown, dbo.I10_Abstracting.SmokingQuitDateUnknownDesc, 
                         dbo.I10_Abstracting.SecondStageDuration, dbo.I10_Abstracting.SourceofReferral, dbo.I10_Abstracting.SourceofReferralDesc, dbo.I10_Abstracting.SpeechTherapy, dbo.I10_Abstracting.SpeechTherapyDesc, 
                         dbo.I10_Abstracting.SpeechUnits, dbo.I10_Abstracting.StakeholderType, dbo.I10_Abstracting.StakeholderTypeDesc, dbo.I10_Abstracting.StartFirstStageDate, dbo.I10_Abstracting.StartFirstStageDateUnknown, 
                         dbo.I10_Abstracting.StartFirstStageDateUnknownDes, dbo.I10_Abstracting.StartFirstStageTime, dbo.I10_Abstracting.StartSecondStageDate, dbo.I10_Abstracting.StartSecondStageDateUnknown, 
                         dbo.I10_Abstracting.StartSecondStageDateUnknown_D, dbo.I10_Abstracting.StartSecondStageTime, dbo.I10_Abstracting.Sterilization, dbo.I10_Abstracting.SterilizationDesc, dbo.I10_Abstracting.SubmissionType, 
                         dbo.I10_Abstracting.SubsequentOR, dbo.I10_Abstracting.SubsequentORDesc, dbo.I10_Abstracting.Suicide, dbo.I10_Abstracting.SuicideDesc, dbo.I10_Abstracting.SummaryStage, dbo.I10_Abstracting.SurgicalCase, 
                         dbo.I10_Abstracting.SurgicalCaseDesc, dbo.I10_Abstracting.TransfusionGiven, dbo.I10_Abstracting.TransfusionGivenDesc, dbo.I10_Abstracting.Trauma, dbo.I10_Abstracting.TraumaDesc, dbo.I10_Abstracting.TSICoder, 
                         dbo.I10_Abstracting.TSICoderDesc, dbo.I10_Abstracting.TSIDate, dbo.I10_Abstracting.TSITime, dbo.I10_Abstracting.ULI, 
						 dbo.I10_Abstracting.UniversalEpisodeIdentifier, dbo.I10_Abstracting.UnplannedReadmission, dbo.I10_Abstracting.UnplannedReadmissionDesc, 
                         dbo.I10_Abstracting.WaitTimeInEmerg, dbo.I10_Abstracting.WaitTimeInEmergHour, dbo.I10_Abstracting.Weightingrams, dbo.I10_Abstracting.WeightKG, 
						 dbo.I10_SpecialCareUnits_VR.SCUAdmissionDate, dbo.I10_SpecialCareUnits_VR.SCUAdmissionTime, 
                      dbo.I10_SpecialCareUnits_VR.SCUAdmissionTimeUnknown, dbo.I10_SpecialCareUnits_VR.SCUAdmissionTimeUnknownDesc, 
                      dbo.I10_SpecialCareUnits_VR.SCUDiagnosis, dbo.I10_SpecialCareUnits_VR.SCUDiagnosisDesc, dbo.I10_SpecialCareUnits_VR.SCUDiagnosisShortDesc, 
                      dbo.I10_SpecialCareUnits_VR.SCUDischargeDate, dbo.I10_SpecialCareUnits_VR.SCUDischargeTime, dbo.I10_SpecialCareUnits_VR.SCUDischargeTimeUnknown, 
                      dbo.I10_SpecialCareUnits_VR.SCUDischargeTimeUnknownDesc, dbo.I10_SpecialCareUnits_VR.SCUHours, dbo.I10_SpecialCareUnits_VR.SCULOS, 
                      dbo.I10_SpecialCareUnits_VR.SCUNumber, dbo.I10_SpecialCareUnits_VR.SCUNumberDesc, dbo.I10_SpecialCareUnits_VR.SCUOccurrence, 
                      dbo.I10_Abstracting.zzAbstractLink, 
                      dbo.I10_Abstracting.zzRegionalPatientID,
                      dbo.I10_Abstracting.zzVolumeLink
FROM         dbo.I10_Abstracting LEFT OUTER JOIN
                      dbo.I10_SpecialCareUnits_VR ON dbo.I10_Abstracting.zzAbstractLink = dbo.I10_SpecialCareUnits_VR.zzAbstractLink




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_AbstractNotes_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_Amcare_And_AbstractNotes_VR]
AS
SELECT        dbo.I10_Amcare_VR.[#ofPreviousPreTermDeliveries], dbo.I10_Amcare_VR.[#ofPrevSpontaneousAbortions], dbo.I10_Amcare_VR.[#ofPreviousTermDeliveries], dbo.I10_Amcare_VR.AccessPrimaryHealthCareCode, 
                         dbo.I10_Amcare_VR.AccessPrimaryHealthCareCodeDesc, dbo.I10_Amcare_VR.AmbulanceArrivalDate, dbo.I10_Amcare_VR.AmbulanceArrivalTime, dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknown, 
                         dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknownDesc, dbo.I10_Amcare_VR.AmbulanceTransferCareDate, dbo.I10_Amcare_VR.AmbulanceTransferCareTime, dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknown, 
                         dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknownDesc, dbo.I10_Amcare_VR.[#ofPrevTherapeuticAbortions], dbo.I10_Amcare_VR.AWOL, dbo.I10_Amcare_VR.AWOLDesc, dbo.I10_Amcare_VR.AbortDate, 
                         dbo.I10_Amcare_VR.AbstractNumber, dbo.I10_Amcare_VR.AbstractOverflow, dbo.I10_Amcare_VR.AbstractOverflowDesc, dbo.I10_Amcare_VR.ActivityDescription, dbo.I10_Amcare_VR.ActivityWhenInjured, 
                         dbo.I10_Amcare_VR.ActivityWhenInjuredDesc, dbo.I10_Amcare_VR.ActueLOS, dbo.I10_Amcare_VR.AdmitbyAmbulance, dbo.I10_Amcare_VR.AdmitbyAmbulanceDesc, dbo.I10_Amcare_VR.AdmitCategory, 
                         dbo.I10_Amcare_VR.AdmitDiagnosis, dbo.I10_Amcare_VR.AdmitNursingArea, dbo.I10_Amcare_VR.AdmitNursingAreaDesc, dbo.I10_Amcare_VR.AfterAdmit, dbo.I10_Amcare_VR.AgeCode, dbo.I10_Amcare_VR.AgeCodeDesc, 
                         dbo.I10_Amcare_VR.AgeGroup, dbo.I10_Amcare_VR.AgeNumber, dbo.I10_Amcare_VR.Albumin, dbo.I10_Amcare_VR.AlbuminDesc, dbo.I10_Amcare_VR.AlbuminCrossMatched, dbo.I10_Amcare_VR.AlbuminCrossMatchedDesc, 
                         dbo.I10_Amcare_VR.AlbuminTyped, dbo.I10_Amcare_VR.AlbuminTypedDesc, dbo.I10_Amcare_VR.AlbuminUnits, dbo.I10_Amcare_VR.ALCLOS, dbo.I10_Amcare_VR.AmbulanceReportNumber, dbo.I10_Amcare_VR.AmCareGroup, 
                         dbo.I10_Amcare_VR.AmCareGroupDesc, dbo.I10_Amcare_VR.AmcareCareType, dbo.I10_Amcare_VR.AmcareCareTypeDesc, dbo.I10_Amcare_VR.AmcareTypeCode, dbo.I10_Amcare_VR.AmcareTypeCodeDesc, 
                         dbo.I10_Amcare_VR.Ancil13, dbo.I10_Amcare_VR.Ancil14, dbo.I10_Amcare_VR.Ancil15, dbo.I10_Amcare_VR.Ancil16, dbo.I10_Amcare_VR.Ancil17, dbo.I10_Amcare_VR.AncillaryField1, dbo.I10_Amcare_VR.AncillaryField1Desc, 
                         dbo.I10_Amcare_VR.AncillaryField10, dbo.I10_Amcare_VR.AncillaryField10Desc, dbo.I10_Amcare_VR.AncillaryField11, dbo.I10_Amcare_VR.AncillaryField11Desc, dbo.I10_Amcare_VR.AncillaryField12, 
                         dbo.I10_Amcare_VR.AncillaryField12Desc, dbo.I10_Amcare_VR.AncillaryField2, dbo.I10_Amcare_VR.AncillaryField2Desc, dbo.I10_Amcare_VR.AncillaryField3, dbo.I10_Amcare_VR.AncillaryField3Desc, 
                         dbo.I10_Amcare_VR.AncillaryField4, dbo.I10_Amcare_VR.AncillaryField4Desc, dbo.I10_Amcare_VR.AncillaryField5, dbo.I10_Amcare_VR.AncillaryField5Desc, dbo.I10_Amcare_VR.AncillaryField6, 
                         dbo.I10_Amcare_VR.AncillaryField6Desc, dbo.I10_Amcare_VR.AncillaryField7, dbo.I10_Amcare_VR.AncillaryField7Desc, dbo.I10_Amcare_VR.AncillaryField8, dbo.I10_Amcare_VR.AncillaryField8Desc, 
                         dbo.I10_Amcare_VR.AncillaryField9, dbo.I10_Amcare_VR.AncillaryField9Desc, dbo.I10_Amcare_VR.ArrivalDate, dbo.I10_Amcare_VR.ArrivalMode, dbo.I10_Amcare_VR.ArrivalModeDesc, dbo.I10_Amcare_VR.ArrivalTime, 
                         dbo.I10_Amcare_VR.ArrivaltoTriageTime, dbo.I10_Amcare_VR.AssessmentDate, dbo.I10_Amcare_VR.AssessmentTime, dbo.I10_Amcare_VR.AssessmentTimeUnknown, dbo.I10_Amcare_VR.AssessmentTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.AttendingPhysician, dbo.I10_Amcare_VR.AttendingPhysicianDesc, dbo.I10_Amcare_VR.AutoTransfusion, dbo.I10_Amcare_VR.AutoTransfusionDesc, dbo.I10_Amcare_VR.AutopsyPerformed, 
                         dbo.I10_Amcare_VR.AutopsyPerformedDesc, dbo.I10_Amcare_VR.BasicOption1, dbo.I10_Amcare_VR.BasicOption1Desc, dbo.I10_Amcare_VR.BasicOption10, dbo.I10_Amcare_VR.BasicOption10Desc, 
                         dbo.I10_Amcare_VR.BasicOption11, dbo.I10_Amcare_VR.BasicOption11Desc, dbo.I10_Amcare_VR.BasicOption12, dbo.I10_Amcare_VR.BasicOption12Desc, dbo.I10_Amcare_VR.BasicOption13, 
                         dbo.I10_Amcare_VR.BasicOption13Desc, dbo.I10_Amcare_VR.BasicOption14, dbo.I10_Amcare_VR.BasicOption14Desc, dbo.I10_Amcare_VR.BasicOption15, dbo.I10_Amcare_VR.BasicOption15Desc, 
                         dbo.I10_Amcare_VR.BasicOption16, dbo.I10_Amcare_VR.BasicOption16Desc, dbo.I10_Amcare_VR.BasicOption17, dbo.I10_Amcare_VR.BasicOption17Desc, dbo.I10_Amcare_VR.BasicOption18, 
                         dbo.I10_Amcare_VR.BasicOption18Desc, dbo.I10_Amcare_VR.BasicOption19, dbo.I10_Amcare_VR.BasicOption19Desc, dbo.I10_Amcare_VR.BasicOption2, dbo.I10_Amcare_VR.BasicOption2Desc, 
                         dbo.I10_Amcare_VR.BasicOption3, dbo.I10_Amcare_VR.BasicOption3Desc, dbo.I10_Amcare_VR.BasicOption4, dbo.I10_Amcare_VR.BasicOption4Desc, dbo.I10_Amcare_VR.BasicOption5, dbo.I10_Amcare_VR.BasicOption5Desc, 
                         dbo.I10_Amcare_VR.BasicOption6, dbo.I10_Amcare_VR.BasicOption6Desc, dbo.I10_Amcare_VR.BasicOption7, dbo.I10_Amcare_VR.BasicOption7Desc, dbo.I10_Amcare_VR.BasicOption8, dbo.I10_Amcare_VR.BasicOption8Desc, 
                         dbo.I10_Amcare_VR.BasicOption9, dbo.I10_Amcare_VR.BasicOption9Desc, dbo.I10_Amcare_VR.BatchNumber, dbo.I10_Amcare_VR.BatchPeriod, dbo.I10_Amcare_VR.BatchPeriodDesc, dbo.I10_Amcare_VR.BatchPeriod_BC, 
                         dbo.I10_Amcare_VR.BatchYear, dbo.I10_Amcare_VR.BirthDate, dbo.I10_Amcare_VR.Blood_AntithrombinIII, dbo.I10_Amcare_VR.Blood_AntithrombinIIIDesc, dbo.I10_Amcare_VR.Blood_C1Inhibitor, 
                         dbo.I10_Amcare_VR.Blood_C1InhibitorDesc, dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasma, dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasmaDesc, dbo.I10_Amcare_VR.Blood_CryosupernatantPlasma, 
                         dbo.I10_Amcare_VR.Blood_CryosupernatantPlasmaDesc, dbo.I10_Amcare_VR.Blood_FEIBA, dbo.I10_Amcare_VR.Blood_FEIBADesc, dbo.I10_Amcare_VR.Blood_Fibrinogen, dbo.I10_Amcare_VR.Blood_FibrinogenDesc, 
                         dbo.I10_Amcare_VR.Blood_IVIG_SCIG, dbo.I10_Amcare_VR.Blood_IVIG_SCIGDesc, dbo.I10_Amcare_VR.Blood_PCC, dbo.I10_Amcare_VR.Blood_PCCDesc, dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactors, 
                         dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactorsDesc, dbo.I10_Amcare_VR.BreastFeeding, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlag, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlagDesc, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitDateIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknown, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknownDesc, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitDateOut, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOut, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknown, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknownDesc, 
                         dbo.I10_Amcare_VR.ChangeinLegalStatus, dbo.I10_Amcare_VR.ChangeinLegalStatusDesc, dbo.I10_Amcare_VR.ChartNumber, dbo.I10_Amcare_VR.ChiefComplaint, dbo.I10_Amcare_VR.CoderNumber, 
                         dbo.I10_Amcare_VR.CoderNumberDesc, dbo.I10_Amcare_VR.CompleteRecord, dbo.I10_Amcare_VR.CompleteRecordDesc, dbo.I10_Amcare_VR.Complication, dbo.I10_Amcare_VR.ComplicationDesc, 
                         dbo.I10_Amcare_VR.Complication1, dbo.I10_Amcare_VR.Complication1Desc, dbo.I10_Amcare_VR.Complication2, dbo.I10_Amcare_VR.Complication2Desc, dbo.I10_Amcare_VR.Complication3, 
                         dbo.I10_Amcare_VR.Complication3Desc, dbo.I10_Amcare_VR.ContactMode, dbo.I10_Amcare_VR.ContactModeDesc, dbo.I10_Amcare_VR.CoronerCase, dbo.I10_Amcare_VR.CoronerCaseDesc, 
                         dbo.I10_Amcare_VR.DataEntryCoder, dbo.I10_Amcare_VR.DataEntryCoderDesc, dbo.I10_Amcare_VR.DateLeftER, dbo.I10_Amcare_VR.DateofLastMenses, dbo.I10_Amcare_VR.DateReadyforDisch, 
                         dbo.I10_Amcare_VR.DateSentToCIHI, dbo.I10_Amcare_VR.DateSentToCIHILevel1, dbo.I10_Amcare_VR.DateSentToCIHILevel2, dbo.I10_Amcare_VR.DateSentToCIHILite, dbo.I10_Amcare_VR.DeathInER, 
                         dbo.I10_Amcare_VR.DeathInERDesc, dbo.I10_Amcare_VR.DeathOnArrival, dbo.I10_Amcare_VR.DeathOnArrivalDesc, dbo.I10_Amcare_VR.DecisionAdmitDifference, dbo.I10_Amcare_VR.DecisiontoAdmitDate, 
                         dbo.I10_Amcare_VR.DecisiontoAdmitTime, dbo.I10_Amcare_VR.DecisionAdmitTimeUnknown, dbo.I10_Amcare_VR.DecisionAdmitTimeUnknownDesc, dbo.I10_Amcare_VR.DeliveryDate, dbo.I10_Amcare_VR.DeliveryTime, 
                         dbo.I10_Amcare_VR.DiedDuringIntervention, dbo.I10_Amcare_VR.DiedDuringInterventionDesc, dbo.I10_Amcare_VR.DischNursingArea, dbo.I10_Amcare_VR.DischNursingAreaDesc, dbo.I10_Amcare_VR.DischPlanning, 
                         dbo.I10_Amcare_VR.DischPlanningDesc, dbo.I10_Amcare_VR.DischargeAge, dbo.I10_Amcare_VR.DischargeDisposition, dbo.I10_Amcare_VR.DischargeDispositionDesc, dbo.I10_Amcare_VR.DispositionDate, 
                         dbo.I10_Amcare_VR.DispositionTime, dbo.I10_Amcare_VR.DispositionTimeUnknown, dbo.I10_Amcare_VR.DispositionTimeUnknownDesc, dbo.I10_Amcare_VR.ECTTreatment, dbo.I10_Amcare_VR.ECTTreatmentDesc, 
                         dbo.I10_Amcare_VR.Education, dbo.I10_Amcare_VR.EducationDesc, dbo.I10_Amcare_VR.EDVisitIndicator, dbo.I10_Amcare_VR.EDVisitIndicatorDesc, dbo.I10_Amcare_VR.Employment, dbo.I10_Amcare_VR.EmploymentDesc, 
                         dbo.I10_Amcare_VR.EntryCode, dbo.I10_Amcare_VR.EstimateDischDate, dbo.I10_Amcare_VR.ExitCode, dbo.I10_Amcare_VR.FamilyPhysicianFlag, dbo.I10_Amcare_VR.FamilyPhysicianFlagDesc, 
                         dbo.I10_Amcare_VR.FinancialSupport, dbo.I10_Amcare_VR.FinancialSupportDesc, dbo.I10_Amcare_VR.FinishDate, dbo.I10_Amcare_VR.FinishTime, dbo.I10_Amcare_VR.FirstName, dbo.I10_Amcare_VR.FullName, 
                         dbo.I10_Amcare_VR.FixedChartNumber, dbo.I10_Amcare_VR.Gender, dbo.I10_Amcare_VR.GenderDesc, dbo.I10_Amcare_VR.GestationalAgeinweeks, dbo.I10_Amcare_VR.GlasgowScale, dbo.I10_Amcare_VR.GlasgowScaleDesc, 
                         dbo.I10_Amcare_VR.GreaterTenPO, dbo.I10_Amcare_VR.HCNProvince, dbo.I10_Amcare_VR.HCNProvinceDesc, dbo.I10_Amcare_VR.HCNVersion, dbo.I10_Amcare_VR.HealthCareNumber, dbo.I10_Amcare_VR.Hospital, 
                         dbo.I10_Amcare_VR.HospitalAccountRecord,
                         dbo.I10_Amcare_VR.HospitalDesc, dbo.I10_Amcare_VR.HelmetIndicator, dbo.I10_Amcare_VR.HelmetIndicatorDesc, dbo.I10_Amcare_VR.InSCU, dbo.I10_Amcare_VR.InitialOR, dbo.I10_Amcare_VR.InitialORDesc, 
                         dbo.I10_Amcare_VR.InjuryDate, dbo.I10_Amcare_VR.Injury, dbo.I10_Amcare_VR.InjuryDesc, dbo.I10_Amcare_VR.InputDate, dbo.I10_Amcare_VR.InputTime, 
						 dbo.I10_Amcare_VR.InstitutionFrom,  dbo.I10_Amcare_VR.InstitutionFromDesc, 
						 dbo.I10_Amcare_VR.InstitutionFromType, dbo.I10_Amcare_VR.InstitutionFromTypeDesc, 
						 dbo.I10_Amcare_VR.InstFromCareType, dbo.I10_Amcare_VR.InstFromHospType, 
						 dbo.I10_Amcare_VR.InstitutionNumber, dbo.I10_Amcare_VR.InstitutionNumberDesc, 
                         dbo.I10_Amcare_VR.InstitutionTo, dbo.I10_Amcare_VR.InstitutionToDesc, 
						 dbo.I10_Amcare_VR.InstitutionToType, dbo.I10_Amcare_VR.InstitutionToTypeDesc, 
						 dbo.I10_Amcare_VR.InstToCareType, dbo.I10_Amcare_VR.InstToHospType,
						 dbo.I10_Amcare_VR.InterfaceDate, dbo.I10_Amcare_VR.InterfaceTime, 
                         dbo.I10_Amcare_VR.IsAbstractCompleted, dbo.I10_Amcare_VR.IsAbstractCompletedDesc, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCompletedLevel2, dbo.I10_Amcare_VR.IsAbstractCompletedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCompletedLite, dbo.I10_Amcare_VR.IsAbstractCompletedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrected, dbo.I10_Amcare_VR.IsAbstractCorrectedDesc, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCorrectedLite, dbo.I10_Amcare_VR.IsAbstractCorrectedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractDeleted, dbo.I10_Amcare_VR.IsAbstractDeletedDesc, dbo.I10_Amcare_VR.IsAbstractSubmitted, dbo.I10_Amcare_VR.IsAbstractSubmittedDesc, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractSubmittedLite, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLiteDesc, dbo.I10_Amcare_VR.IsAbstractValidated, dbo.I10_Amcare_VR.IsAbstractValidatedDesc, dbo.I10_Amcare_VR.IsAbstractValidatedLevel1, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractValidatedLite, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLiteDesc, dbo.I10_Amcare_VR.IsBirthdateEstimated, dbo.I10_Amcare_VR.IsBirthdateEstimatedDesc, dbo.I10_Amcare_VR.IsCustomValidated, dbo.I10_Amcare_VR.IsCustomValidatedDesc, 
                         dbo.I10_Amcare_VR.LOSDays, dbo.I10_Amcare_VR.LOSTime, dbo.I10_Amcare_VR.LOSTimeinHours, dbo.I10_Amcare_VR.LOSTotalMinutes, dbo.I10_Amcare_VR.Language, dbo.I10_Amcare_VR.LanguageDesc, 
                         dbo.I10_Amcare_VR.LastName, dbo.I10_Amcare_VR.LessTwoPO, dbo.I10_Amcare_VR.LivingArrangement, dbo.I10_Amcare_VR.LivingArrangementDesc, dbo.I10_Amcare_VR.LocationofInjury, 
                         dbo.I10_Amcare_VR.LocationofInjuryDesc, dbo.I10_Amcare_VR.MISCode, dbo.I10_Amcare_VR.MISCodeDesc, dbo.I10_Amcare_VR.MaidenName, dbo.I10_Amcare_VR.MaritalStatus, dbo.I10_Amcare_VR.MaritalStatusDesc, 
                         dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoED, dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01, dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02, dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02Desc, dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03Desc, dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04, dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04Desc, 
                         dbo.I10_Amcare_VR.MethodofAdmission, dbo.I10_Amcare_VR.MethodofAdmissionDesc, dbo.I10_Amcare_VR.MiddleName,
                         dbo.I10_Amcare_VR.NACRSClinicLiteSubmission, dbo.I10_Amcare_VR.NACRSClinicLiteSubmissionDesc, 
                         dbo.I10_Amcare_VR.NewbornChart, dbo.I10_Amcare_VR.NewbornDischDate, 
                         dbo.I10_Amcare_VR.NextScheduledVisitDate, dbo.I10_Amcare_VR.NextScheduledVisitTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentDate, dbo.I10_Amcare_VR.NonPhysicianAssessmentTime, 
                         dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknown, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknownDesc, dbo.I10_Amcare_VR.NonPhysicianNumber, dbo.I10_Amcare_VR.NonPhysicianNumberDesc, 
                         dbo.I10_Amcare_VR.NonPhysicianService, dbo.I10_Amcare_VR.NonPhysicianServiceDesc, dbo.I10_Amcare_VR.NumberofECT, dbo.I10_Amcare_VR.NursingAssessmentDate, dbo.I10_Amcare_VR.NursingAssessmentTime, 
                         dbo.I10_Amcare_VR.Occupation, dbo.I10_Amcare_VR.OccupationDesc, dbo.I10_Amcare_VR.OtherMedicalDeath, dbo.I10_Amcare_VR.OtherMedicalDeathDesc, dbo.I10_Amcare_VR.OtherBlood, 
                         dbo.I10_Amcare_VR.OtherBloodDesc, dbo.I10_Amcare_VR.OtherBloodCrossMatched, dbo.I10_Amcare_VR.OtherBloodCrossMatchedDesc, dbo.I10_Amcare_VR.OtherBloodTyped, dbo.I10_Amcare_VR.OtherBloodTypedDesc, 
                         dbo.I10_Amcare_VR.OtherBloodUnits, dbo.I10_Amcare_VR.PCTASIndicator, dbo.I10_Amcare_VR.PCTASIndicatorDesc, dbo.I10_Amcare_VR.PhysicianEstLOS, dbo.I10_Amcare_VR.Plasma, dbo.I10_Amcare_VR.PlasmaDesc, 
                         dbo.I10_Amcare_VR.PlasmaCrossMatched, dbo.I10_Amcare_VR.PlasmaCrossMatchedDesc, dbo.I10_Amcare_VR.PlasmaTyped, dbo.I10_Amcare_VR.PlasmaTypedDesc, dbo.I10_Amcare_VR.PlasmaUnits, 
                         dbo.I10_Amcare_VR.Platelets, dbo.I10_Amcare_VR.PlateletsDesc, dbo.I10_Amcare_VR.PlateletsCrossMatched, dbo.I10_Amcare_VR.PlateletsCrossMatchedDesc, dbo.I10_Amcare_VR.PlateletsTyped, 
                         dbo.I10_Amcare_VR.PlateletsTypedDesc, dbo.I10_Amcare_VR.PlateletsUnits, dbo.I10_Amcare_VR.PostalCode, dbo.I10_Amcare_VR.PostalCodeDesc, dbo.I10_Amcare_VR.PostOpDays, dbo.I10_Amcare_VR.PreOpDays, 
                         dbo.I10_Amcare_VR.PreamditWorkUp, dbo.I10_Amcare_VR.PreamditWorkUpDesc, dbo.I10_Amcare_VR.Pregnancy, dbo.I10_Amcare_VR.PregnancyDesc, dbo.I10_Amcare_VR.PrevLiveBirth, 
                         dbo.I10_Amcare_VR.PreviousPsychiartricAdmissions, dbo.I10_Amcare_VR.PreviousPsychiartricAdmDesc, dbo.I10_Amcare_VR.Program, dbo.I10_Amcare_VR.ProgramDesc, dbo.I10_Amcare_VR.ProvinceNumber, 
                         dbo.I10_Amcare_VR.ProvinceNumberDesc, dbo.I10_Amcare_VR.ReasonForVisit, dbo.I10_Amcare_VR.ReasonForVisitDesc, dbo.I10_Amcare_VR.ReAdmitCode, dbo.I10_Amcare_VR.ReciprocalBillingStatus, 
                         dbo.I10_Amcare_VR.ReciprocalBillingStatusDesc, dbo.I10_Amcare_VR.RedBloodCell, dbo.I10_Amcare_VR.RedBloodCellDesc, dbo.I10_Amcare_VR.RedBloodCellCrossMatched, 
                         dbo.I10_Amcare_VR.RedBloodCellCrossMatchedDesc, dbo.I10_Amcare_VR.RedBloodCellTyped, dbo.I10_Amcare_VR.RedBloodCellTypedDesc, dbo.I10_Amcare_VR.RedBloodCellUnits, dbo.I10_Amcare_VR.ReferralDate, 
                         dbo.I10_Amcare_VR.ReferredFrom, dbo.I10_Amcare_VR.ReferredFromDesc, dbo.I10_Amcare_VR.ReferredTo, dbo.I10_Amcare_VR.ReferredToDesc, dbo.I10_Amcare_VR.ReferringProvider, 
                         dbo.I10_Amcare_VR.ReferringProviderDesc, dbo.I10_Amcare_VR.RegisterNumber, dbo.I10_Amcare_VR.RegistrationNumber, dbo.I10_Amcare_VR.RegistrationSequenceNumber, dbo.I10_Amcare_VR.RegistrationVisitDate, 
                         dbo.I10_Amcare_VR.RegistrationVisitTime, dbo.I10_Amcare_VR.ReproductiveCareComments, dbo.I10_Amcare_VR.ReserveField, dbo.I10_Amcare_VR.ResidenceCode, dbo.I10_Amcare_VR.ResidenceCodeDesc, 
                         dbo.I10_Amcare_VR.ResidenceProvince, dbo.I10_Amcare_VR.ResidenceProvinceDesc, dbo.I10_Amcare_VR.ResidenceRegion, dbo.I10_Amcare_VR.ResidenceRegionDesc, dbo.I10_Amcare_VR.ResidenceType, 
                         dbo.I10_Amcare_VR.ResidenceTypeDesc, dbo.I10_Amcare_VR.ResponsiblityForPayment, dbo.I10_Amcare_VR.ResponsiblityForPaymentDesc, dbo.I10_Amcare_VR.SchedEDVisit, dbo.I10_Amcare_VR.SchedEDVisitDesc, 
                         dbo.I10_Amcare_VR.SeatbeltIndicator, dbo.I10_Amcare_VR.SeatbeltIndicatorDesc, dbo.I10_Amcare_VR.SecondChartRegisterNumber, dbo.I10_Amcare_VR.SecretVIPPatient, dbo.I10_Amcare_VR.SecretVIPPatientDesc, 
                         dbo.I10_Amcare_VR.SiteNumber, dbo.I10_Amcare_VR.SiteNumberDesc, dbo.I10_Amcare_VR.SocialService, dbo.I10_Amcare_VR.SocialServiceDesc, dbo.I10_Amcare_VR.SourceofReferral, 
                         dbo.I10_Amcare_VR.SourceofReferralDesc, dbo.I10_Amcare_VR.SpecialistNumber, dbo.I10_Amcare_VR.SpecialistNumberDesc, dbo.I10_Amcare_VR.SpecialistRequestDate, dbo.I10_Amcare_VR.SpecialistRequestService, 
                         dbo.I10_Amcare_VR.SpecialistRequestServiceDesc, dbo.I10_Amcare_VR.SpecialistRequestTime, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknown, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.StakeholderType, dbo.I10_Amcare_VR.StakeholderTypeDesc, dbo.I10_Amcare_VR.StatusAfterTriage, dbo.I10_Amcare_VR.StatusAfterTriageDesc, dbo.I10_Amcare_VR.Sterilization, 
                         dbo.I10_Amcare_VR.SterilizationDesc, dbo.I10_Amcare_VR.SubmissionLevelCode, dbo.I10_Amcare_VR.SubmissionRecordID, dbo.I10_Amcare_VR.SubsequentOR, dbo.I10_Amcare_VR.SubsequentORDesc, 
                         dbo.I10_Amcare_VR.Suicide, dbo.I10_Amcare_VR.SuicideDesc, dbo.I10_Amcare_VR.SurgicalCase, dbo.I10_Amcare_VR.SurgicalCaseDesc, dbo.I10_Amcare_VR.TimeLeftER, dbo.I10_Amcare_VR.TimeLeftERUnknown, 
                         dbo.I10_Amcare_VR.TimeLeftERUnknownDEsc, dbo.I10_Amcare_VR.TransferOverloadDate, dbo.I10_Amcare_VR.TransferOverloadTime, dbo.I10_Amcare_VR.TransferOverloadTimeDifference, 
                         dbo.I10_Amcare_VR.TransfusionGiven, dbo.I10_Amcare_VR.TransfusionGivenDesc, dbo.I10_Amcare_VR.Trauma, dbo.I10_Amcare_VR.TraumaDesc, dbo.I10_Amcare_VR.TriageDate, dbo.I10_Amcare_VR.TriageLevel, 
                         dbo.I10_Amcare_VR.TriageLevelDesc, dbo.I10_Amcare_VR.TriageTime, dbo.I10_Amcare_VR.TriageTimeUnknown, dbo.I10_Amcare_VR.TriageTimeUnknownDesc, dbo.I10_Amcare_VR.TSICoder, 
                         dbo.I10_Amcare_VR.TSICoderDesc, dbo.I10_Amcare_VR.TSIDate, dbo.I10_Amcare_VR.TSITime, dbo.I10_Amcare_VR.TwoTenPO, dbo.I10_Amcare_VR.ULI, 
						 dbo.I10_Amcare_VR.UniversalEpisodeIdentifier, dbo.I10_Amcare_VR.UnplannedReadmit, dbo.I10_Amcare_VR.VisitStatus, 
                         dbo.I10_Amcare_VR.VisitStatusDesc, dbo.I10_Amcare_VR.VisitType, dbo.I10_Amcare_VR.VisitTypeDesc, dbo.I10_Amcare_VR.WaitTimeinER, dbo.I10_Amcare_VR.WaittoAssessmentinMinutes, 
                         dbo.I10_Amcare_VR.WaittoNursingAssessmentDiff, dbo.I10_Amcare_VR.Weight, dbo.I10_Amcare_VR.zzAbstractLink, dbo.I10_Amcare_VR.zzRegionalPatientID, dbo.I10_Amcare_VR.zzVolumeLink, 
                         dbo.I10_AbstractNotes_VR.AbstractNotes, dbo.I10_AbstractNotes_VR.DateLogged, dbo.I10_AbstractNotes_VR.TimeLogged, dbo.I10_AbstractNotes_VR.CreateBy, dbo.I10_AbstractNotes_VR.CreatorName
FROM            dbo.I10_AbstractNotes_VR RIGHT OUTER JOIN
                         dbo.I10_Amcare_VR ON dbo.I10_AbstractNotes_VR.zzAbstractLink = dbo.I10_Amcare_VR.zzAbstractLink





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_CACS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'



CREATE VIEW [dbo].[I10_Amcare_And_CACS_VR]
AS
SELECT        dbo.I10_Amcare_VR.[#ofPreviousPreTermDeliveries], dbo.I10_Amcare_VR.[#ofPrevSpontaneousAbortions], dbo.I10_Amcare_VR.[#ofPreviousTermDeliveries], dbo.I10_Amcare_VR.AccessPrimaryHealthCareCode, 
                         dbo.I10_Amcare_VR.AccessPrimaryHealthCareCodeDesc, dbo.I10_Amcare_VR.AmbulanceArrivalDate, dbo.I10_Amcare_VR.AmbulanceArrivalTime, dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknown, 
                         dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknownDesc, dbo.I10_Amcare_VR.AmbulanceTransferCareDate, dbo.I10_Amcare_VR.AmbulanceTransferCareTime, 
                         dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknown, dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknownDesc, dbo.I10_Amcare_VR.[#ofPrevTherapeuticAbortions], dbo.I10_Amcare_VR.AWOL, 
                         dbo.I10_Amcare_VR.AWOLDesc, dbo.I10_Amcare_VR.AbortDate, dbo.I10_Amcare_VR.AbstractNumber, dbo.I10_Amcare_VR.AbstractOverflow, dbo.I10_Amcare_VR.AbstractOverflowDesc, 
                         dbo.I10_Amcare_VR.ActivityDescription, dbo.I10_Amcare_VR.ActivityWhenInjured, dbo.I10_Amcare_VR.ActivityWhenInjuredDesc, dbo.I10_Amcare_VR.ActueLOS, dbo.I10_Amcare_VR.AdmitbyAmbulance, 
                         dbo.I10_Amcare_VR.AdmitbyAmbulanceDesc, dbo.I10_Amcare_VR.AdmitCategory, dbo.I10_Amcare_VR.AdmitDiagnosis, dbo.I10_Amcare_VR.AdmitNursingArea, dbo.I10_Amcare_VR.AdmitNursingAreaDesc, 
                         dbo.I10_Amcare_VR.AfterAdmit, dbo.I10_Amcare_VR.AgeCode, dbo.I10_Amcare_VR.AgeCodeDesc, dbo.I10_Amcare_VR.AgeGroup, dbo.I10_Amcare_VR.AgeNumber, dbo.I10_Amcare_VR.Albumin, 
                         dbo.I10_Amcare_VR.AlbuminDesc, dbo.I10_Amcare_VR.AlbuminCrossMatched, dbo.I10_Amcare_VR.AlbuminCrossMatchedDesc, dbo.I10_Amcare_VR.AlbuminTyped, dbo.I10_Amcare_VR.AlbuminTypedDesc, 
                         dbo.I10_Amcare_VR.AlbuminUnits, dbo.I10_Amcare_VR.ALCLOS, dbo.I10_Amcare_VR.AmbulanceReportNumber, dbo.I10_Amcare_VR.AmCareGroup, dbo.I10_Amcare_VR.AmCareGroupDesc, 
                         dbo.I10_Amcare_VR.AmcareCareType, dbo.I10_Amcare_VR.AmcareCareTypeDesc, dbo.I10_Amcare_VR.AmcareTypeCode, dbo.I10_Amcare_VR.AmcareTypeCodeDesc, dbo.I10_Amcare_VR.Ancil13, 
                         dbo.I10_Amcare_VR.Ancil14, dbo.I10_Amcare_VR.Ancil15, dbo.I10_Amcare_VR.Ancil16, dbo.I10_Amcare_VR.Ancil17, dbo.I10_Amcare_VR.AncillaryField1, dbo.I10_Amcare_VR.AncillaryField1Desc, 
                         dbo.I10_Amcare_VR.AncillaryField10, dbo.I10_Amcare_VR.AncillaryField10Desc, dbo.I10_Amcare_VR.AncillaryField11, dbo.I10_Amcare_VR.AncillaryField11Desc, dbo.I10_Amcare_VR.AncillaryField12, 
                         dbo.I10_Amcare_VR.AncillaryField12Desc, dbo.I10_Amcare_VR.AncillaryField2, dbo.I10_Amcare_VR.AncillaryField2Desc, dbo.I10_Amcare_VR.AncillaryField3, dbo.I10_Amcare_VR.AncillaryField3Desc, 
                         dbo.I10_Amcare_VR.AncillaryField4, dbo.I10_Amcare_VR.AncillaryField4Desc, dbo.I10_Amcare_VR.AncillaryField5, dbo.I10_Amcare_VR.AncillaryField5Desc, dbo.I10_Amcare_VR.AncillaryField6, 
                         dbo.I10_Amcare_VR.AncillaryField6Desc, dbo.I10_Amcare_VR.AncillaryField7, dbo.I10_Amcare_VR.AncillaryField7Desc, dbo.I10_Amcare_VR.AncillaryField8, dbo.I10_Amcare_VR.AncillaryField8Desc, 
                         dbo.I10_Amcare_VR.AncillaryField9, dbo.I10_Amcare_VR.AncillaryField9Desc, dbo.I10_Amcare_VR.ArrivalDate, dbo.I10_Amcare_VR.ArrivalMode, dbo.I10_Amcare_VR.ArrivalModeDesc, 
                         dbo.I10_Amcare_VR.ArrivalTime, dbo.I10_Amcare_VR.ArrivaltoTriageTime, dbo.I10_Amcare_VR.AssessmentDate, dbo.I10_Amcare_VR.AssessmentTime, dbo.I10_Amcare_VR.AssessmentTimeUnknown, 
                         dbo.I10_Amcare_VR.AssessmentTimeUnknownDesc, dbo.I10_Amcare_VR.AttendingPhysician, dbo.I10_Amcare_VR.AttendingPhysicianDesc, dbo.I10_Amcare_VR.AutoTransfusion, 
                         dbo.I10_Amcare_VR.AutoTransfusionDesc, dbo.I10_Amcare_VR.AutopsyPerformed, dbo.I10_Amcare_VR.AutopsyPerformedDesc, dbo.I10_Amcare_VR.BasicOption1, dbo.I10_Amcare_VR.BasicOption1Desc, 
                         dbo.I10_Amcare_VR.BasicOption10, dbo.I10_Amcare_VR.BasicOption10Desc, dbo.I10_Amcare_VR.BasicOption11, dbo.I10_Amcare_VR.BasicOption11Desc, dbo.I10_Amcare_VR.BasicOption12, 
                         dbo.I10_Amcare_VR.BasicOption12Desc, dbo.I10_Amcare_VR.BasicOption13, dbo.I10_Amcare_VR.BasicOption13Desc, dbo.I10_Amcare_VR.BasicOption14, dbo.I10_Amcare_VR.BasicOption14Desc, 
                         dbo.I10_Amcare_VR.BasicOption15, dbo.I10_Amcare_VR.BasicOption15Desc, dbo.I10_Amcare_VR.BasicOption16, dbo.I10_Amcare_VR.BasicOption16Desc, dbo.I10_Amcare_VR.BasicOption17, 
                         dbo.I10_Amcare_VR.BasicOption17Desc, dbo.I10_Amcare_VR.BasicOption18, dbo.I10_Amcare_VR.BasicOption18Desc, dbo.I10_Amcare_VR.BasicOption19, dbo.I10_Amcare_VR.BasicOption19Desc, 
                         dbo.I10_Amcare_VR.BasicOption2, dbo.I10_Amcare_VR.BasicOption2Desc, dbo.I10_Amcare_VR.BasicOption3, dbo.I10_Amcare_VR.BasicOption3Desc, dbo.I10_Amcare_VR.BasicOption4, 
                         dbo.I10_Amcare_VR.BasicOption4Desc, dbo.I10_Amcare_VR.BasicOption5, dbo.I10_Amcare_VR.BasicOption5Desc, dbo.I10_Amcare_VR.BasicOption6, dbo.I10_Amcare_VR.BasicOption6Desc, 
                         dbo.I10_Amcare_VR.BasicOption7, dbo.I10_Amcare_VR.BasicOption7Desc, dbo.I10_Amcare_VR.BasicOption8, dbo.I10_Amcare_VR.BasicOption8Desc, dbo.I10_Amcare_VR.BasicOption9, 
                         dbo.I10_Amcare_VR.BasicOption9Desc, dbo.I10_Amcare_VR.BatchNumber, dbo.I10_Amcare_VR.BatchPeriod, dbo.I10_Amcare_VR.BatchPeriodDesc, dbo.I10_Amcare_VR.BatchPeriod_BC, 
                         dbo.I10_Amcare_VR.BatchYear, dbo.I10_Amcare_VR.BirthDate, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIII, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIIIDesc, 
						 dbo.I10_Amcare_VR.Blood_C1Inhibitor, 
                         dbo.I10_Amcare_VR.Blood_C1InhibitorDesc, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasma, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_CryosupernatantPlasma, 
                         dbo.I10_Amcare_VR.Blood_CryosupernatantPlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_FEIBA, 
						 dbo.I10_Amcare_VR.Blood_FEIBADesc, 
						 dbo.I10_Amcare_VR.Blood_Fibrinogen, 
						 dbo.I10_Amcare_VR.Blood_FibrinogenDesc, 
                         dbo.I10_Amcare_VR.Blood_IVIG_SCIG, 
						 dbo.I10_Amcare_VR.Blood_IVIG_SCIGDesc, 
						 dbo.I10_Amcare_VR.Blood_PCC, 
						 dbo.I10_Amcare_VR.Blood_PCCDesc, 
						 dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactors, 
                         dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactorsDesc, 
						 dbo.I10_Amcare_VR.BreastFeeding, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlag, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlagDesc, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitDateIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknown, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknownDesc, dbo.I10_Amcare_VR.ClinicalDecisionUnitDateOut, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOut, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknown, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknownDesc, dbo.I10_Amcare_VR.ChangeinLegalStatus, 
                         dbo.I10_Amcare_VR.ChangeinLegalStatusDesc, dbo.I10_Amcare_VR.ChartNumber, dbo.I10_Amcare_VR.ChiefComplaint, dbo.I10_Amcare_VR.CoderNumber, dbo.I10_Amcare_VR.CoderNumberDesc, 
                         dbo.I10_Amcare_VR.CompleteRecord, dbo.I10_Amcare_VR.CompleteRecordDesc, dbo.I10_Amcare_VR.Complication, dbo.I10_Amcare_VR.ComplicationDesc, dbo.I10_Amcare_VR.Complication1, 
                         dbo.I10_Amcare_VR.Complication1Desc, dbo.I10_Amcare_VR.Complication2, dbo.I10_Amcare_VR.Complication2Desc, dbo.I10_Amcare_VR.Complication3, dbo.I10_Amcare_VR.Complication3Desc, 
                         dbo.I10_Amcare_VR.ContactMode, dbo.I10_Amcare_VR.ContactModeDesc, dbo.I10_Amcare_VR.CoronerCase, dbo.I10_Amcare_VR.CoronerCaseDesc, dbo.I10_Amcare_VR.DataEntryCoder, 
                         dbo.I10_Amcare_VR.DataEntryCoderDesc, dbo.I10_Amcare_VR.DateLeftER, dbo.I10_Amcare_VR.DateofLastMenses, dbo.I10_Amcare_VR.DateReadyforDisch, dbo.I10_Amcare_VR.DateSentToCIHI, 
                         dbo.I10_Amcare_VR.DateSentToCIHILevel1, dbo.I10_Amcare_VR.DateSentToCIHILevel2, dbo.I10_Amcare_VR.DateSentToCIHILite, dbo.I10_Amcare_VR.DeathInER, dbo.I10_Amcare_VR.DeathInERDesc, 
                         dbo.I10_Amcare_VR.DeathOnArrival, dbo.I10_Amcare_VR.DeathOnArrivalDesc, dbo.I10_Amcare_VR.DecisionAdmitDifference, dbo.I10_Amcare_VR.DecisiontoAdmitDate, dbo.I10_Amcare_VR.DecisiontoAdmitTime, 
                         dbo.I10_Amcare_VR.DecisionAdmitTimeUnknown, dbo.I10_Amcare_VR.DecisionAdmitTimeUnknownDesc, dbo.I10_Amcare_VR.DeliveryDate, dbo.I10_Amcare_VR.DeliveryTime, 
                         dbo.I10_Amcare_VR.DiedDuringIntervention, dbo.I10_Amcare_VR.DiedDuringInterventionDesc, dbo.I10_Amcare_VR.DischNursingArea, dbo.I10_Amcare_VR.DischNursingAreaDesc, 
                         dbo.I10_Amcare_VR.DischPlanning, dbo.I10_Amcare_VR.DischPlanningDesc, dbo.I10_Amcare_VR.DischargeAge, dbo.I10_Amcare_VR.DischargeDisposition, dbo.I10_Amcare_VR.DischargeDispositionDesc, 
                         dbo.I10_Amcare_VR.DispositionDate, dbo.I10_Amcare_VR.DispositionTime, dbo.I10_Amcare_VR.DispositionTimeUnknown, dbo.I10_Amcare_VR.DispositionTimeUnknownDesc, dbo.I10_Amcare_VR.ECTTreatment, 
                         dbo.I10_Amcare_VR.ECTTreatmentDesc, dbo.I10_Amcare_VR.Education, dbo.I10_Amcare_VR.EducationDesc, dbo.I10_Amcare_VR.EDVisitIndicator, dbo.I10_Amcare_VR.EDVisitIndicatorDesc, 
                         dbo.I10_Amcare_VR.Employment, dbo.I10_Amcare_VR.EmploymentDesc, dbo.I10_Amcare_VR.EntryCode, dbo.I10_Amcare_VR.EstimateDischDate, dbo.I10_Amcare_VR.ExitCode, 
                         dbo.I10_Amcare_VR.FamilyPhysicianFlag, dbo.I10_Amcare_VR.FamilyPhysicianFlagDesc, dbo.I10_Amcare_VR.FinancialSupport, dbo.I10_Amcare_VR.FinancialSupportDesc, dbo.I10_Amcare_VR.FinishDate, 
                         dbo.I10_Amcare_VR.FinishTime, dbo.I10_Amcare_VR.FirstName, dbo.I10_Amcare_VR.FullName, dbo.I10_Amcare_VR.FixedChartNumber, dbo.I10_Amcare_VR.Gender, dbo.I10_Amcare_VR.GenderDesc, 
                         dbo.I10_Amcare_VR.GestationalAgeinweeks, dbo.I10_Amcare_VR.GlasgowScale, dbo.I10_Amcare_VR.GlasgowScaleDesc, dbo.I10_Amcare_VR.GreaterTenPO, dbo.I10_Amcare_VR.HCNProvince, 
                         dbo.I10_Amcare_VR.HCNProvinceDesc, dbo.I10_Amcare_VR.HCNVersion, dbo.I10_Amcare_VR.HealthCareNumber, dbo.I10_Amcare_VR.Hospital, dbo.I10_Amcare_VR.HospitalDesc, 
                         dbo.I10_Amcare_VR.HospitalAccountRecord,
                         dbo.I10_Amcare_VR.HelmetIndicator, dbo.I10_Amcare_VR.HelmetIndicatorDesc, dbo.I10_Amcare_VR.InSCU, dbo.I10_Amcare_VR.InitialOR, dbo.I10_Amcare_VR.InitialORDesc, dbo.I10_Amcare_VR.InjuryDate, 
                         dbo.I10_Amcare_VR.Injury, dbo.I10_Amcare_VR.InjuryDesc, dbo.I10_Amcare_VR.InputDate, dbo.I10_Amcare_VR.InputTime, 
						 dbo.I10_Amcare_VR.InstitutionFrom, dbo.I10_Amcare_VR.InstitutionFromDesc, 
						 dbo.I10_Amcare_VR.InstitutionFromType, dbo.I10_Amcare_VR.InstitutionFromTypeDesc,
                         dbo.I10_Amcare_VR.InstFromCareType, dbo.I10_Amcare_VR.InstFromHospType, 
						 dbo.I10_Amcare_VR.InstitutionNumber, dbo.I10_Amcare_VR.InstitutionNumberDesc, 
						 dbo.I10_Amcare_VR.InstitutionTo, dbo.I10_Amcare_VR.InstitutionToDesc, 
						 dbo.I10_Amcare_VR.InstToCareType, dbo.I10_Amcare_VR.InstToHospType, 
						 dbo.I10_Amcare_VR.InstitutionToType, dbo.I10_Amcare_VR.InstitutionToTypeDesc, 
						 dbo.I10_Amcare_VR.InterfaceDate, dbo.I10_Amcare_VR.InterfaceTime, 
                         dbo.I10_Amcare_VR.IsAbstractCompleted, dbo.I10_Amcare_VR.IsAbstractCompletedDesc, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCompletedLevel2, dbo.I10_Amcare_VR.IsAbstractCompletedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCompletedLite, dbo.I10_Amcare_VR.IsAbstractCompletedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrected, dbo.I10_Amcare_VR.IsAbstractCorrectedDesc, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCorrectedLite, dbo.I10_Amcare_VR.IsAbstractCorrectedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractDeleted, dbo.I10_Amcare_VR.IsAbstractDeletedDesc, dbo.I10_Amcare_VR.IsAbstractSubmitted, dbo.I10_Amcare_VR.IsAbstractSubmittedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLite, dbo.I10_Amcare_VR.IsAbstractSubmittedLiteDesc, dbo.I10_Amcare_VR.IsAbstractValidated, dbo.I10_Amcare_VR.IsAbstractValidatedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLevel1, dbo.I10_Amcare_VR.IsAbstractValidatedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLite, dbo.I10_Amcare_VR.IsAbstractValidatedLiteDesc, dbo.I10_Amcare_VR.IsBirthdateEstimated, dbo.I10_Amcare_VR.IsBirthdateEstimatedDesc, 
						 dbo.I10_Amcare_VR.IsCustomValidated, dbo.I10_Amcare_VR.IsCustomValidatedDesc,
                         dbo.I10_Amcare_VR.LOSDays, dbo.I10_Amcare_VR.LOSTime, dbo.I10_Amcare_VR.LOSTimeinHours, dbo.I10_Amcare_VR.LOSTotalMinutes, dbo.I10_Amcare_VR.Language, dbo.I10_Amcare_VR.LanguageDesc, 
                         dbo.I10_Amcare_VR.LastName, dbo.I10_Amcare_VR.LessTwoPO, dbo.I10_Amcare_VR.LivingArrangement, dbo.I10_Amcare_VR.LivingArrangementDesc, dbo.I10_Amcare_VR.LocationofInjury, 
                         dbo.I10_Amcare_VR.LocationofInjuryDesc, dbo.I10_Amcare_VR.MISCode, dbo.I10_Amcare_VR.MISCodeDesc, dbo.I10_Amcare_VR.MaidenName, dbo.I10_Amcare_VR.MaritalStatus, 
                         dbo.I10_Amcare_VR.MaritalStatusDesc, 
                         dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoED, 
						 dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04Desc, 
						 
						 dbo.I10_Amcare_VR.MethodofAdmission, dbo.I10_Amcare_VR.MethodofAdmissionDesc, dbo.I10_Amcare_VR.MiddleName, 
                         dbo.I10_Amcare_VR.NACRSClinicLiteSubmission, dbo.I10_Amcare_VR.NACRSClinicLiteSubmissionDesc, 
                         dbo.I10_Amcare_VR.NewbornChart, 
                         dbo.I10_Amcare_VR.NewbornDischDate, dbo.I10_Amcare_VR.NextScheduledVisitDate, dbo.I10_Amcare_VR.NextScheduledVisitTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentDate, 
                         dbo.I10_Amcare_VR.NonPhysicianAssessmentTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknown, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.NonPhysicianNumber, dbo.I10_Amcare_VR.NonPhysicianNumberDesc, dbo.I10_Amcare_VR.NonPhysicianService, dbo.I10_Amcare_VR.NonPhysicianServiceDesc, 
                         dbo.I10_Amcare_VR.NumberofECT, dbo.I10_Amcare_VR.NursingAssessmentDate, dbo.I10_Amcare_VR.NursingAssessmentTime, dbo.I10_Amcare_VR.Occupation, dbo.I10_Amcare_VR.OccupationDesc, 
                         dbo.I10_Amcare_VR.OtherMedicalDeath, dbo.I10_Amcare_VR.OtherMedicalDeathDesc, dbo.I10_Amcare_VR.OtherBlood, dbo.I10_Amcare_VR.OtherBloodDesc, dbo.I10_Amcare_VR.OtherBloodCrossMatched, 
                         dbo.I10_Amcare_VR.OtherBloodCrossMatchedDesc, dbo.I10_Amcare_VR.OtherBloodTyped, dbo.I10_Amcare_VR.OtherBloodTypedDesc, dbo.I10_Amcare_VR.OtherBloodUnits, dbo.I10_Amcare_VR.PCTASIndicator, 
                         dbo.I10_Amcare_VR.PCTASIndicatorDesc, dbo.I10_Amcare_VR.PhysicianEstLOS, dbo.I10_Amcare_VR.Plasma, dbo.I10_Amcare_VR.PlasmaDesc, dbo.I10_Amcare_VR.PlasmaCrossMatched, 
                         dbo.I10_Amcare_VR.PlasmaCrossMatchedDesc, dbo.I10_Amcare_VR.PlasmaTyped, dbo.I10_Amcare_VR.PlasmaTypedDesc, dbo.I10_Amcare_VR.PlasmaUnits, dbo.I10_Amcare_VR.Platelets, 
                         dbo.I10_Amcare_VR.PlateletsDesc, dbo.I10_Amcare_VR.PlateletsCrossMatched, dbo.I10_Amcare_VR.PlateletsCrossMatchedDesc, dbo.I10_Amcare_VR.PlateletsTyped, dbo.I10_Amcare_VR.PlateletsTypedDesc, 
                         dbo.I10_Amcare_VR.PlateletsUnits, dbo.I10_Amcare_VR.PostalCode, dbo.I10_Amcare_VR.PostalCodeDesc, dbo.I10_Amcare_VR.PostOpDays, dbo.I10_Amcare_VR.PreOpDays, 
                         dbo.I10_Amcare_VR.PreamditWorkUp, dbo.I10_Amcare_VR.PreamditWorkUpDesc, dbo.I10_Amcare_VR.Pregnancy, dbo.I10_Amcare_VR.PregnancyDesc, dbo.I10_Amcare_VR.PrevLiveBirth, 
                         dbo.I10_Amcare_VR.PreviousPsychiartricAdmissions, dbo.I10_Amcare_VR.PreviousPsychiartricAdmDesc, dbo.I10_Amcare_VR.Program, dbo.I10_Amcare_VR.ProgramDesc, dbo.I10_Amcare_VR.ProvinceNumber, 
                         dbo.I10_Amcare_VR.ProvinceNumberDesc, dbo.I10_Amcare_VR.ReasonForVisit, dbo.I10_Amcare_VR.ReasonForVisitDesc, dbo.I10_Amcare_VR.ReAdmitCode, dbo.I10_Amcare_VR.ReciprocalBillingStatus, 
                         dbo.I10_Amcare_VR.ReciprocalBillingStatusDesc, dbo.I10_Amcare_VR.RedBloodCell, dbo.I10_Amcare_VR.RedBloodCellDesc, dbo.I10_Amcare_VR.RedBloodCellCrossMatched, 
                         dbo.I10_Amcare_VR.RedBloodCellCrossMatchedDesc, dbo.I10_Amcare_VR.RedBloodCellTyped, dbo.I10_Amcare_VR.RedBloodCellTypedDesc, dbo.I10_Amcare_VR.RedBloodCellUnits, 
                         dbo.I10_Amcare_VR.ReferralDate, dbo.I10_Amcare_VR.ReferredFrom, dbo.I10_Amcare_VR.ReferredFromDesc, dbo.I10_Amcare_VR.ReferredTo, dbo.I10_Amcare_VR.ReferredToDesc, 
                         dbo.I10_Amcare_VR.ReferringProvider, dbo.I10_Amcare_VR.ReferringProviderDesc, dbo.I10_Amcare_VR.RegisterNumber, dbo.I10_Amcare_VR.RegistrationNumber, 
                         dbo.I10_Amcare_VR.RegistrationSequenceNumber, dbo.I10_Amcare_VR.RegistrationVisitDate, dbo.I10_Amcare_VR.RegistrationVisitTime, dbo.I10_Amcare_VR.ReproductiveCareComments, 
                         dbo.I10_Amcare_VR.ReserveField, dbo.I10_Amcare_VR.ResidenceCode, dbo.I10_Amcare_VR.ResidenceCodeDesc, dbo.I10_Amcare_VR.ResidenceProvince, dbo.I10_Amcare_VR.ResidenceProvinceDesc, 
                         dbo.I10_Amcare_VR.ResidenceRegion, dbo.I10_Amcare_VR.ResidenceRegionDesc, dbo.I10_Amcare_VR.ResidenceType, dbo.I10_Amcare_VR.ResidenceTypeDesc, dbo.I10_Amcare_VR.ResponsiblityForPayment,
                          dbo.I10_Amcare_VR.ResponsiblityForPaymentDesc, dbo.I10_Amcare_VR.SchedEDVisit, dbo.I10_Amcare_VR.SchedEDVisitDesc, dbo.I10_Amcare_VR.SeatbeltIndicator, dbo.I10_Amcare_VR.SeatbeltIndicatorDesc, 
                         dbo.I10_Amcare_VR.SecondChartRegisterNumber, dbo.I10_Amcare_VR.SecretVIPPatient, dbo.I10_Amcare_VR.SecretVIPPatientDesc, dbo.I10_Amcare_VR.SiteNumber, dbo.I10_Amcare_VR.SiteNumberDesc, 
                         dbo.I10_Amcare_VR.SocialService, dbo.I10_Amcare_VR.SocialServiceDesc, dbo.I10_Amcare_VR.SourceofReferral, dbo.I10_Amcare_VR.SourceofReferralDesc, dbo.I10_Amcare_VR.SpecialistNumber, 
                         dbo.I10_Amcare_VR.SpecialistNumberDesc, dbo.I10_Amcare_VR.SpecialistRequestDate, dbo.I10_Amcare_VR.SpecialistRequestService, dbo.I10_Amcare_VR.SpecialistRequestServiceDesc, 
                         dbo.I10_Amcare_VR.SpecialistRequestTime, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknown, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknownDesc, dbo.I10_Amcare_VR.StakeholderType, 
                         dbo.I10_Amcare_VR.StakeholderTypeDesc, dbo.I10_Amcare_VR.StatusAfterTriage, dbo.I10_Amcare_VR.StatusAfterTriageDesc, dbo.I10_Amcare_VR.Sterilization, dbo.I10_Amcare_VR.SterilizationDesc, 
                         dbo.I10_Amcare_VR.SubmissionLevelCode, dbo.I10_Amcare_VR.SubmissionRecordID, dbo.I10_Amcare_VR.SubsequentOR, dbo.I10_Amcare_VR.SubsequentORDesc, dbo.I10_Amcare_VR.Suicide, 
                         dbo.I10_Amcare_VR.SuicideDesc, dbo.I10_Amcare_VR.SurgicalCase, dbo.I10_Amcare_VR.SurgicalCaseDesc, dbo.I10_Amcare_VR.TimeLeftER, dbo.I10_Amcare_VR.TimeLeftERUnknown, 
                         dbo.I10_Amcare_VR.TimeLeftERUnknownDEsc, dbo.I10_Amcare_VR.TransferOverloadDate, dbo.I10_Amcare_VR.TransferOverloadTime, dbo.I10_Amcare_VR.TransferOverloadTimeDifference, 
                         dbo.I10_Amcare_VR.TransfusionGiven, dbo.I10_Amcare_VR.TransfusionGivenDesc, dbo.I10_Amcare_VR.Trauma, dbo.I10_Amcare_VR.TraumaDesc, dbo.I10_Amcare_VR.TriageDate, 
                         dbo.I10_Amcare_VR.TriageLevel, dbo.I10_Amcare_VR.TriageLevelDesc, dbo.I10_Amcare_VR.TriageTime, dbo.I10_Amcare_VR.TriageTimeUnknown, dbo.I10_Amcare_VR.TriageTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.TSICoder, dbo.I10_Amcare_VR.TSICoderDesc, dbo.I10_Amcare_VR.TSIDate, dbo.I10_Amcare_VR.TSITime, dbo.I10_Amcare_VR.TwoTenPO, dbo.I10_Amcare_VR.ULI, 
                         dbo.I10_Amcare_VR.UniversalEpisodeIdentifier, dbo.I10_Amcare_VR.UnplannedReadmit, dbo.I10_Amcare_VR.VisitStatus, dbo.I10_Amcare_VR.VisitStatusDesc, dbo.I10_Amcare_VR.VisitType, dbo.I10_Amcare_VR.VisitTypeDesc, 
                         dbo.I10_Amcare_VR.WaitTimeinER, dbo.I10_Amcare_VR.WaittoAssessmentinMinutes, dbo.I10_Amcare_VR.WaittoNursingAssessmentDiff, dbo.I10_Amcare_VR.Weight, dbo.I10_Amcare_VR.zzAbstractLink, 
                         dbo.I10_Amcare_VR.zzRegionalPatientID, dbo.I10_Amcare_VR.zzVolumeLink, dbo.I10_AmCare_CACS_VR.OccurrenceNumber, dbo.I10_AmCare_CACS_VR.BatchGroupDate, dbo.I10_AmCare_CACS_VR.CACSYear, 
                         dbo.I10_AmCare_CACS_VR.MAC, dbo.I10_AmCare_CACS_VR.MACDescription, dbo.I10_AmCare_CACS_VR.CACSCell, dbo.I10_AmCare_CACS_VR.ACW, dbo.I10_AmCare_CACS_VR.CACSDescription, 
                         dbo.I10_AmCare_CACS_VR.InterventionCode, dbo.I10_AmCare_CACS_VR.IntervCodeDescription, dbo.I10_AmCare_CACS_VR.InterventionCodeShortDesc, dbo.I10_AmCare_CACS_VR.AgeCategory, 
                         dbo.I10_AmCare_CACS_VR.AgeCategoryDesc, dbo.I10_AmCare_CACS_VR.AnaestheticCategory, dbo.I10_AmCare_CACS_VR.AnaestheticCategoryDesc, 
                         dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyTotalCount, dbo.I10_AmCare_CACS_VR.CACSHBAM, dbo.I10_AmCare_CACS_VR.CACSBaseRIW, dbo.I10_AmCare_CACS_VR.CACSPartition, 
                         dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategory_01, dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategoryCount_01, dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategory_02, 
                         dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategoryCount_02, dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategory_03, dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategoryCount_03, 
                         dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategory_04, dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategoryCount_04, dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategory_05, 
                         dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategoryCount_05, dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategory_06, dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategoryCount_06, 
                         dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategory_07, dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategoryCount_07, dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategory_08, 
                         dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategoryCount_08, dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategory_09, dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategoryCount_09, 
                         dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategory_10, dbo.I10_AmCare_CACS_VR.InvestigativeTechnologyCategoryCount_10
FROM            dbo.I10_Amcare_VR LEFT OUTER JOIN
                         dbo.I10_AmCare_CACS_VR ON dbo.I10_Amcare_VR.zzAbstractLink = dbo.I10_AmCare_CACS_VR.zzAbstractLink







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_AmCare_And_Consult_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_AmCare_And_Consult_VR]
AS
SELECT        dbo.I10_Amcare_VR.[#ofPreviousPreTermDeliveries], dbo.I10_Amcare_VR.[#ofPrevSpontaneousAbortions], dbo.I10_Amcare_VR.[#ofPreviousTermDeliveries], dbo.I10_Amcare_VR.AccessPrimaryHealthCareCode, 
                         dbo.I10_Amcare_VR.AccessPrimaryHealthCareCodeDesc, dbo.I10_Amcare_VR.AmbulanceArrivalDate, dbo.I10_Amcare_VR.AmbulanceArrivalTime, dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknown, 
                         dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknownDesc, dbo.I10_Amcare_VR.AmbulanceTransferCareDate, dbo.I10_Amcare_VR.AmbulanceTransferCareTime, 
                         dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknown, dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknownDesc, dbo.I10_Amcare_VR.[#ofPrevTherapeuticAbortions], dbo.I10_Amcare_VR.AWOL, 
                         dbo.I10_Amcare_VR.AWOLDesc, dbo.I10_Amcare_VR.AbortDate, dbo.I10_Amcare_VR.AbstractNumber, dbo.I10_Amcare_VR.AbstractOverflow, dbo.I10_Amcare_VR.AbstractOverflowDesc, 
                         dbo.I10_Amcare_VR.ActivityDescription, dbo.I10_Amcare_VR.ActivityWhenInjured, dbo.I10_Amcare_VR.ActivityWhenInjuredDesc, dbo.I10_Amcare_VR.ActueLOS, dbo.I10_Amcare_VR.AdmitbyAmbulance, 
                         dbo.I10_Amcare_VR.AdmitbyAmbulanceDesc, dbo.I10_Amcare_VR.AdmitCategory, dbo.I10_Amcare_VR.AdmitDiagnosis, dbo.I10_Amcare_VR.AdmitNursingArea, dbo.I10_Amcare_VR.AdmitNursingAreaDesc, 
                         dbo.I10_Amcare_VR.AfterAdmit, dbo.I10_Amcare_VR.AgeCode, dbo.I10_Amcare_VR.AgeCodeDesc, dbo.I10_Amcare_VR.AgeGroup, dbo.I10_Amcare_VR.AgeNumber, dbo.I10_Amcare_VR.Albumin, 
                         dbo.I10_Amcare_VR.AlbuminDesc, dbo.I10_Amcare_VR.AlbuminCrossMatched, dbo.I10_Amcare_VR.AlbuminCrossMatchedDesc, dbo.I10_Amcare_VR.AlbuminTyped, dbo.I10_Amcare_VR.AlbuminTypedDesc, 
                         dbo.I10_Amcare_VR.AlbuminUnits, dbo.I10_Amcare_VR.ALCLOS, dbo.I10_Amcare_VR.AmbulanceReportNumber, dbo.I10_Amcare_VR.AmCareGroup, dbo.I10_Amcare_VR.AmCareGroupDesc, 
                         dbo.I10_Amcare_VR.AmcareCareType, dbo.I10_Amcare_VR.AmcareCareTypeDesc, dbo.I10_Amcare_VR.AmcareTypeCode, dbo.I10_Amcare_VR.AmcareTypeCodeDesc, dbo.I10_Amcare_VR.Ancil13, 
                         dbo.I10_Amcare_VR.Ancil14, dbo.I10_Amcare_VR.Ancil15, dbo.I10_Amcare_VR.Ancil16, dbo.I10_Amcare_VR.Ancil17, dbo.I10_Amcare_VR.AncillaryField1, dbo.I10_Amcare_VR.AncillaryField1Desc, 
                         dbo.I10_Amcare_VR.AncillaryField10, dbo.I10_Amcare_VR.AncillaryField10Desc, dbo.I10_Amcare_VR.AncillaryField11, dbo.I10_Amcare_VR.AncillaryField11Desc, dbo.I10_Amcare_VR.AncillaryField12, 
                         dbo.I10_Amcare_VR.AncillaryField12Desc, dbo.I10_Amcare_VR.AncillaryField2, dbo.I10_Amcare_VR.AncillaryField2Desc, dbo.I10_Amcare_VR.AncillaryField3, dbo.I10_Amcare_VR.AncillaryField3Desc, 
                         dbo.I10_Amcare_VR.AncillaryField4, dbo.I10_Amcare_VR.AncillaryField4Desc, dbo.I10_Amcare_VR.AncillaryField5, dbo.I10_Amcare_VR.AncillaryField5Desc, dbo.I10_Amcare_VR.AncillaryField6, 
                         dbo.I10_Amcare_VR.AncillaryField6Desc, dbo.I10_Amcare_VR.AncillaryField7, dbo.I10_Amcare_VR.AncillaryField7Desc, dbo.I10_Amcare_VR.AncillaryField8, dbo.I10_Amcare_VR.AncillaryField8Desc, 
                         dbo.I10_Amcare_VR.AncillaryField9, dbo.I10_Amcare_VR.AncillaryField9Desc, dbo.I10_Amcare_VR.ArrivalDate, dbo.I10_Amcare_VR.ArrivalMode, dbo.I10_Amcare_VR.ArrivalModeDesc, 
                         dbo.I10_Amcare_VR.ArrivalTime, dbo.I10_Amcare_VR.ArrivaltoTriageTime, dbo.I10_Amcare_VR.AssessmentDate, dbo.I10_Amcare_VR.AssessmentTime, dbo.I10_Amcare_VR.AssessmentTimeUnknown, 
                         dbo.I10_Amcare_VR.AssessmentTimeUnknownDesc, dbo.I10_Amcare_VR.AttendingPhysician, dbo.I10_Amcare_VR.AttendingPhysicianDesc, dbo.I10_Amcare_VR.AutoTransfusion, 
                         dbo.I10_Amcare_VR.AutoTransfusionDesc, dbo.I10_Amcare_VR.AutopsyPerformed, dbo.I10_Amcare_VR.AutopsyPerformedDesc, dbo.I10_Amcare_VR.BasicOption1, dbo.I10_Amcare_VR.BasicOption1Desc, 
                         dbo.I10_Amcare_VR.BasicOption10, dbo.I10_Amcare_VR.BasicOption10Desc, dbo.I10_Amcare_VR.BasicOption11, dbo.I10_Amcare_VR.BasicOption11Desc, dbo.I10_Amcare_VR.BasicOption12, 
                         dbo.I10_Amcare_VR.BasicOption12Desc, dbo.I10_Amcare_VR.BasicOption13, dbo.I10_Amcare_VR.BasicOption13Desc, dbo.I10_Amcare_VR.BasicOption14, dbo.I10_Amcare_VR.BasicOption14Desc, 
                         dbo.I10_Amcare_VR.BasicOption15, dbo.I10_Amcare_VR.BasicOption15Desc, dbo.I10_Amcare_VR.BasicOption16, dbo.I10_Amcare_VR.BasicOption16Desc, dbo.I10_Amcare_VR.BasicOption17, 
                         dbo.I10_Amcare_VR.BasicOption17Desc, dbo.I10_Amcare_VR.BasicOption18, dbo.I10_Amcare_VR.BasicOption18Desc, dbo.I10_Amcare_VR.BasicOption19, dbo.I10_Amcare_VR.BasicOption19Desc, 
                         dbo.I10_Amcare_VR.BasicOption2, dbo.I10_Amcare_VR.BasicOption2Desc, dbo.I10_Amcare_VR.BasicOption3, dbo.I10_Amcare_VR.BasicOption3Desc, dbo.I10_Amcare_VR.BasicOption4, 
                         dbo.I10_Amcare_VR.BasicOption4Desc, dbo.I10_Amcare_VR.BasicOption5, dbo.I10_Amcare_VR.BasicOption5Desc, dbo.I10_Amcare_VR.BasicOption6, dbo.I10_Amcare_VR.BasicOption6Desc, 
                         dbo.I10_Amcare_VR.BasicOption7, dbo.I10_Amcare_VR.BasicOption7Desc, dbo.I10_Amcare_VR.BasicOption8, dbo.I10_Amcare_VR.BasicOption8Desc, dbo.I10_Amcare_VR.BasicOption9, 
                         dbo.I10_Amcare_VR.BasicOption9Desc, dbo.I10_Amcare_VR.BatchNumber, dbo.I10_Amcare_VR.BatchPeriod, dbo.I10_Amcare_VR.BatchPeriodDesc, dbo.I10_Amcare_VR.BatchPeriod_BC, 
                         dbo.I10_Amcare_VR.BatchYear, dbo.I10_Amcare_VR.BirthDate, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIII, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIIIDesc, 
						 dbo.I10_Amcare_VR.Blood_C1Inhibitor, 
                         dbo.I10_Amcare_VR.Blood_C1InhibitorDesc, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasma, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_CryosupernatantPlasma, 
                         dbo.I10_Amcare_VR.Blood_CryosupernatantPlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_FEIBA, 
						 dbo.I10_Amcare_VR.Blood_FEIBADesc, 
						 dbo.I10_Amcare_VR.Blood_Fibrinogen, 
						 dbo.I10_Amcare_VR.Blood_FibrinogenDesc, 
                         dbo.I10_Amcare_VR.Blood_IVIG_SCIG, 
						 dbo.I10_Amcare_VR.Blood_IVIG_SCIGDesc, 
						 dbo.I10_Amcare_VR.Blood_PCC, 
						 dbo.I10_Amcare_VR.Blood_PCCDesc, 
						 dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactors, 
                         dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactorsDesc, 

						 dbo.I10_Amcare_VR.BreastFeeding, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlag, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlagDesc, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitDateIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknown, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknownDesc, dbo.I10_Amcare_VR.ClinicalDecisionUnitDateOut, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOut, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknown, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknownDesc, dbo.I10_Amcare_VR.ChangeinLegalStatus, 
                         dbo.I10_Amcare_VR.ChangeinLegalStatusDesc, dbo.I10_Amcare_VR.ChartNumber, dbo.I10_Amcare_VR.ChiefComplaint, dbo.I10_Amcare_VR.CoderNumber, dbo.I10_Amcare_VR.CoderNumberDesc, 
                         dbo.I10_Amcare_VR.CompleteRecord, dbo.I10_Amcare_VR.CompleteRecordDesc, dbo.I10_Amcare_VR.Complication, dbo.I10_Amcare_VR.ComplicationDesc, dbo.I10_Amcare_VR.Complication1, 
                         dbo.I10_Amcare_VR.Complication1Desc, dbo.I10_Amcare_VR.Complication2, dbo.I10_Amcare_VR.Complication2Desc, dbo.I10_Amcare_VR.Complication3, dbo.I10_Amcare_VR.Complication3Desc, 
                         dbo.I10_Amcare_VR.ContactMode, dbo.I10_Amcare_VR.ContactModeDesc, dbo.I10_Amcare_VR.CoronerCase, dbo.I10_Amcare_VR.CoronerCaseDesc, dbo.I10_Amcare_VR.DataEntryCoder, 
                         dbo.I10_Amcare_VR.DataEntryCoderDesc, dbo.I10_Amcare_VR.DateLeftER, dbo.I10_Amcare_VR.DateofLastMenses, dbo.I10_Amcare_VR.DateReadyforDisch, dbo.I10_Amcare_VR.DateSentToCIHI, 
                         dbo.I10_Amcare_VR.DateSentToCIHILevel1, dbo.I10_Amcare_VR.DateSentToCIHILevel2, dbo.I10_Amcare_VR.DateSentToCIHILite, dbo.I10_Amcare_VR.DeathInER, dbo.I10_Amcare_VR.DeathInERDesc, 
                         dbo.I10_Amcare_VR.DeathOnArrival, dbo.I10_Amcare_VR.DeathOnArrivalDesc, dbo.I10_Amcare_VR.DecisionAdmitDifference, dbo.I10_Amcare_VR.DecisiontoAdmitDate, dbo.I10_Amcare_VR.DecisiontoAdmitTime, 
                         dbo.I10_Amcare_VR.DecisionAdmitTimeUnknown, dbo.I10_Amcare_VR.DecisionAdmitTimeUnknownDesc, dbo.I10_Amcare_VR.DeliveryDate, dbo.I10_Amcare_VR.DeliveryTime, 
                         dbo.I10_Amcare_VR.DiedDuringIntervention, dbo.I10_Amcare_VR.DiedDuringInterventionDesc, dbo.I10_Amcare_VR.DischNursingArea, dbo.I10_Amcare_VR.DischNursingAreaDesc, 
                         dbo.I10_Amcare_VR.DischPlanning, dbo.I10_Amcare_VR.DischPlanningDesc, dbo.I10_Amcare_VR.DischargeAge, dbo.I10_Amcare_VR.DischargeDisposition, dbo.I10_Amcare_VR.DischargeDispositionDesc, 
                         dbo.I10_Amcare_VR.DispositionDate, dbo.I10_Amcare_VR.DispositionTime, dbo.I10_Amcare_VR.DispositionTimeUnknown, dbo.I10_Amcare_VR.DispositionTimeUnknownDesc, dbo.I10_Amcare_VR.ECTTreatment, 
                         dbo.I10_Amcare_VR.ECTTreatmentDesc, dbo.I10_Amcare_VR.Education, dbo.I10_Amcare_VR.EducationDesc, dbo.I10_Amcare_VR.EDVisitIndicator, dbo.I10_Amcare_VR.EDVisitIndicatorDesc, 
                         dbo.I10_Amcare_VR.Employment, dbo.I10_Amcare_VR.EmploymentDesc, dbo.I10_Amcare_VR.EntryCode, dbo.I10_Amcare_VR.EstimateDischDate, dbo.I10_Amcare_VR.ExitCode, 
                         dbo.I10_Amcare_VR.FamilyPhysicianFlag, dbo.I10_Amcare_VR.FamilyPhysicianFlagDesc, dbo.I10_Amcare_VR.FinancialSupport, dbo.I10_Amcare_VR.FinancialSupportDesc, dbo.I10_Amcare_VR.FinishDate, 
                         dbo.I10_Amcare_VR.FinishTime, dbo.I10_Amcare_VR.FirstName, dbo.I10_Amcare_VR.FullName, dbo.I10_Amcare_VR.FixedChartNumber, dbo.I10_Amcare_VR.Gender, dbo.I10_Amcare_VR.GenderDesc, 
                         dbo.I10_Amcare_VR.GestationalAgeinweeks, dbo.I10_Amcare_VR.GlasgowScale, dbo.I10_Amcare_VR.GlasgowScaleDesc, dbo.I10_Amcare_VR.GreaterTenPO, dbo.I10_Amcare_VR.HCNProvince, 
                         dbo.I10_Amcare_VR.HCNProvinceDesc, dbo.I10_Amcare_VR.HCNVersion, dbo.I10_Amcare_VR.HealthCareNumber, dbo.I10_Amcare_VR.Hospital, dbo.I10_Amcare_VR.HospitalDesc, 
                         dbo.I10_Amcare_VR.HospitalAccountRecord,
                         dbo.I10_Amcare_VR.HelmetIndicator, dbo.I10_Amcare_VR.HelmetIndicatorDesc, dbo.I10_Amcare_VR.InSCU, dbo.I10_Amcare_VR.InitialOR, dbo.I10_Amcare_VR.InitialORDesc, dbo.I10_Amcare_VR.InjuryDate, 
                         dbo.I10_Amcare_VR.Injury, dbo.I10_Amcare_VR.InjuryDesc, dbo.I10_Amcare_VR.InputDate, dbo.I10_Amcare_VR.InputTime, 
						 

						 dbo.I10_Amcare_VR.InstitutionFrom, dbo.I10_Amcare_VR.InstitutionFromDesc, 
						 dbo.I10_Amcare_VR.InstitutionFromType, dbo.I10_Amcare_VR.InstitutionFromTypeDesc,
                         dbo.I10_Amcare_VR.InstFromCareType, dbo.I10_Amcare_VR.InstFromHospType, 
						 dbo.I10_Amcare_VR.InstitutionNumber, dbo.I10_Amcare_VR.InstitutionNumberDesc, 
						 dbo.I10_Amcare_VR.InstitutionTo, dbo.I10_Amcare_VR.InstitutionToDesc, 
						 dbo.I10_Amcare_VR.InstToCareType, dbo.I10_Amcare_VR.InstToHospType, 
						 dbo.I10_Amcare_VR.InstitutionToType, dbo.I10_Amcare_VR.InstitutionToTypeDesc, 
						 
						 dbo.I10_Amcare_VR.InterfaceDate, dbo.I10_Amcare_VR.InterfaceTime, 
                         dbo.I10_Amcare_VR.IsAbstractCompleted, dbo.I10_Amcare_VR.IsAbstractCompletedDesc, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCompletedLevel2, dbo.I10_Amcare_VR.IsAbstractCompletedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCompletedLite, dbo.I10_Amcare_VR.IsAbstractCompletedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrected, dbo.I10_Amcare_VR.IsAbstractCorrectedDesc, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCorrectedLite, dbo.I10_Amcare_VR.IsAbstractCorrectedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractDeleted, dbo.I10_Amcare_VR.IsAbstractDeletedDesc, dbo.I10_Amcare_VR.IsAbstractSubmitted, dbo.I10_Amcare_VR.IsAbstractSubmittedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLite, dbo.I10_Amcare_VR.IsAbstractSubmittedLiteDesc, dbo.I10_Amcare_VR.IsAbstractValidated, dbo.I10_Amcare_VR.IsAbstractValidatedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLevel1, dbo.I10_Amcare_VR.IsAbstractValidatedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLite, dbo.I10_Amcare_VR.IsAbstractValidatedLiteDesc, dbo.I10_Amcare_VR.IsBirthdateEstimated, dbo.I10_Amcare_VR.IsBirthdateEstimatedDesc, 
						 dbo.I10_Amcare_VR.IsCustomValidated, dbo.I10_Amcare_VR.IsCustomValidatedDesc,
                         dbo.I10_Amcare_VR.LOSDays, dbo.I10_Amcare_VR.LOSTime, dbo.I10_Amcare_VR.LOSTimeinHours, dbo.I10_Amcare_VR.LOSTotalMinutes, dbo.I10_Amcare_VR.Language, dbo.I10_Amcare_VR.LanguageDesc, 
                         dbo.I10_Amcare_VR.LastName, dbo.I10_Amcare_VR.LessTwoPO, dbo.I10_Amcare_VR.LivingArrangement, dbo.I10_Amcare_VR.LivingArrangementDesc, dbo.I10_Amcare_VR.LocationofInjury, 
                         dbo.I10_Amcare_VR.LocationofInjuryDesc, dbo.I10_Amcare_VR.MISCode, dbo.I10_Amcare_VR.MISCodeDesc, dbo.I10_Amcare_VR.MaidenName, dbo.I10_Amcare_VR.MaritalStatus, 
                         dbo.I10_Amcare_VR.MaritalStatusDesc, 
                         dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoED, 
						 dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04Desc, 

						 dbo.I10_Amcare_VR.MethodofAdmission, dbo.I10_Amcare_VR.MethodofAdmissionDesc, dbo.I10_Amcare_VR.MiddleName, 
                         dbo.I10_Amcare_VR.NACRSClinicLiteSubmission, dbo.I10_Amcare_VR.NACRSClinicLiteSubmissionDesc, 
                         dbo.I10_Amcare_VR.NewbornChart, 
                         dbo.I10_Amcare_VR.NewbornDischDate, dbo.I10_Amcare_VR.NextScheduledVisitDate, dbo.I10_Amcare_VR.NextScheduledVisitTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentDate, 
                         dbo.I10_Amcare_VR.NonPhysicianAssessmentTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknown, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.NonPhysicianNumber, dbo.I10_Amcare_VR.NonPhysicianNumberDesc, dbo.I10_Amcare_VR.NonPhysicianService, dbo.I10_Amcare_VR.NonPhysicianServiceDesc, 
                         dbo.I10_Amcare_VR.NumberofECT, dbo.I10_Amcare_VR.NursingAssessmentDate, dbo.I10_Amcare_VR.NursingAssessmentTime, dbo.I10_Amcare_VR.Occupation, dbo.I10_Amcare_VR.OccupationDesc, 
                         dbo.I10_Amcare_VR.OtherMedicalDeath, dbo.I10_Amcare_VR.OtherMedicalDeathDesc, dbo.I10_Amcare_VR.OtherBlood, dbo.I10_Amcare_VR.OtherBloodDesc, dbo.I10_Amcare_VR.OtherBloodCrossMatched, 
                         dbo.I10_Amcare_VR.OtherBloodCrossMatchedDesc, dbo.I10_Amcare_VR.OtherBloodTyped, dbo.I10_Amcare_VR.OtherBloodTypedDesc, dbo.I10_Amcare_VR.OtherBloodUnits, dbo.I10_Amcare_VR.PCTASIndicator, 
                         dbo.I10_Amcare_VR.PCTASIndicatorDesc, dbo.I10_Amcare_VR.PhysicianEstLOS, dbo.I10_Amcare_VR.Plasma, dbo.I10_Amcare_VR.PlasmaDesc, dbo.I10_Amcare_VR.PlasmaCrossMatched, 
                         dbo.I10_Amcare_VR.PlasmaCrossMatchedDesc, dbo.I10_Amcare_VR.PlasmaTyped, dbo.I10_Amcare_VR.PlasmaTypedDesc, dbo.I10_Amcare_VR.PlasmaUnits, dbo.I10_Amcare_VR.Platelets, 
                         dbo.I10_Amcare_VR.PlateletsDesc, dbo.I10_Amcare_VR.PlateletsCrossMatched, dbo.I10_Amcare_VR.PlateletsCrossMatchedDesc, dbo.I10_Amcare_VR.PlateletsTyped, dbo.I10_Amcare_VR.PlateletsTypedDesc, 
                         dbo.I10_Amcare_VR.PlateletsUnits, dbo.I10_Amcare_VR.PostalCode, dbo.I10_Amcare_VR.PostalCodeDesc, dbo.I10_Amcare_VR.PostOpDays, dbo.I10_Amcare_VR.PreOpDays, 
                         dbo.I10_Amcare_VR.PreamditWorkUp, dbo.I10_Amcare_VR.PreamditWorkUpDesc, dbo.I10_Amcare_VR.Pregnancy, dbo.I10_Amcare_VR.PregnancyDesc, dbo.I10_Amcare_VR.PrevLiveBirth, 
                         dbo.I10_Amcare_VR.PreviousPsychiartricAdmissions, dbo.I10_Amcare_VR.PreviousPsychiartricAdmDesc, dbo.I10_Amcare_VR.Program, dbo.I10_Amcare_VR.ProgramDesc, dbo.I10_Amcare_VR.ProvinceNumber, 
                         dbo.I10_Amcare_VR.ProvinceNumberDesc, dbo.I10_Amcare_VR.ReasonForVisit, dbo.I10_Amcare_VR.ReasonForVisitDesc, dbo.I10_Amcare_VR.ReAdmitCode, dbo.I10_Amcare_VR.ReciprocalBillingStatus, 
                         dbo.I10_Amcare_VR.ReciprocalBillingStatusDesc, dbo.I10_Amcare_VR.RedBloodCell, dbo.I10_Amcare_VR.RedBloodCellDesc, dbo.I10_Amcare_VR.RedBloodCellCrossMatched, 
                         dbo.I10_Amcare_VR.RedBloodCellCrossMatchedDesc, dbo.I10_Amcare_VR.RedBloodCellTyped, dbo.I10_Amcare_VR.RedBloodCellTypedDesc, dbo.I10_Amcare_VR.RedBloodCellUnits, 
                         dbo.I10_Amcare_VR.ReferralDate, dbo.I10_Amcare_VR.ReferredFrom, dbo.I10_Amcare_VR.ReferredFromDesc, dbo.I10_Amcare_VR.ReferredTo, dbo.I10_Amcare_VR.ReferredToDesc, 
                         dbo.I10_Amcare_VR.ReferringProvider, dbo.I10_Amcare_VR.ReferringProviderDesc, dbo.I10_Amcare_VR.RegisterNumber, dbo.I10_Amcare_VR.RegistrationNumber, 
                         dbo.I10_Amcare_VR.RegistrationSequenceNumber, dbo.I10_Amcare_VR.RegistrationVisitDate, dbo.I10_Amcare_VR.RegistrationVisitTime, dbo.I10_Amcare_VR.ReproductiveCareComments, 
                         dbo.I10_Amcare_VR.ReserveField, dbo.I10_Amcare_VR.ResidenceCode, dbo.I10_Amcare_VR.ResidenceCodeDesc, dbo.I10_Amcare_VR.ResidenceProvince, dbo.I10_Amcare_VR.ResidenceProvinceDesc, 
                         dbo.I10_Amcare_VR.ResidenceRegion, dbo.I10_Amcare_VR.ResidenceRegionDesc, dbo.I10_Amcare_VR.ResidenceType, dbo.I10_Amcare_VR.ResidenceTypeDesc, dbo.I10_Amcare_VR.ResponsiblityForPayment,
                          dbo.I10_Amcare_VR.ResponsiblityForPaymentDesc, dbo.I10_Amcare_VR.SchedEDVisit, dbo.I10_Amcare_VR.SchedEDVisitDesc, dbo.I10_Amcare_VR.SeatbeltIndicator, dbo.I10_Amcare_VR.SeatbeltIndicatorDesc, 
                         dbo.I10_Amcare_VR.SecondChartRegisterNumber, dbo.I10_Amcare_VR.SecretVIPPatient, dbo.I10_Amcare_VR.SecretVIPPatientDesc, dbo.I10_Amcare_VR.SiteNumber, dbo.I10_Amcare_VR.SiteNumberDesc, 
                         dbo.I10_Amcare_VR.SocialService, dbo.I10_Amcare_VR.SocialServiceDesc, dbo.I10_Amcare_VR.SourceofReferral, dbo.I10_Amcare_VR.SourceofReferralDesc, dbo.I10_Amcare_VR.SpecialistNumber, 
                         dbo.I10_Amcare_VR.SpecialistNumberDesc, dbo.I10_Amcare_VR.SpecialistRequestDate, dbo.I10_Amcare_VR.SpecialistRequestService, dbo.I10_Amcare_VR.SpecialistRequestServiceDesc, 
                         dbo.I10_Amcare_VR.SpecialistRequestTime, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknown, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknownDesc, dbo.I10_Amcare_VR.StakeholderType, 
                         dbo.I10_Amcare_VR.StakeholderTypeDesc, dbo.I10_Amcare_VR.StatusAfterTriage, dbo.I10_Amcare_VR.StatusAfterTriageDesc, dbo.I10_Amcare_VR.Sterilization, dbo.I10_Amcare_VR.SterilizationDesc, 
                         dbo.I10_Amcare_VR.SubmissionLevelCode, dbo.I10_Amcare_VR.SubmissionRecordID, dbo.I10_Amcare_VR.SubsequentOR, dbo.I10_Amcare_VR.SubsequentORDesc, dbo.I10_Amcare_VR.Suicide, 
                         dbo.I10_Amcare_VR.SuicideDesc, dbo.I10_Amcare_VR.SurgicalCase, dbo.I10_Amcare_VR.SurgicalCaseDesc, dbo.I10_Amcare_VR.TimeLeftER, dbo.I10_Amcare_VR.TimeLeftERUnknown, 
                         dbo.I10_Amcare_VR.TimeLeftERUnknownDEsc, dbo.I10_Amcare_VR.TransferOverloadDate, dbo.I10_Amcare_VR.TransferOverloadTime, dbo.I10_Amcare_VR.TransferOverloadTimeDifference, 
                         dbo.I10_Amcare_VR.TransfusionGiven, dbo.I10_Amcare_VR.TransfusionGivenDesc, dbo.I10_Amcare_VR.Trauma, dbo.I10_Amcare_VR.TraumaDesc, dbo.I10_Amcare_VR.TriageDate, 
                         dbo.I10_Amcare_VR.TriageLevel, dbo.I10_Amcare_VR.TriageLevelDesc, dbo.I10_Amcare_VR.TriageTime, dbo.I10_Amcare_VR.TriageTimeUnknown, dbo.I10_Amcare_VR.TriageTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.TSICoder, dbo.I10_Amcare_VR.TSICoderDesc, dbo.I10_Amcare_VR.TSIDate, dbo.I10_Amcare_VR.TSITime, dbo.I10_Amcare_VR.TwoTenPO, dbo.I10_Amcare_VR.ULI, 
                         dbo.I10_Amcare_VR.UniversalEpisodeIdentifier, dbo.I10_Amcare_VR.UnplannedReadmit, dbo.I10_Amcare_VR.VisitStatus, dbo.I10_Amcare_VR.VisitStatusDesc, dbo.I10_Amcare_VR.VisitType, dbo.I10_Amcare_VR.VisitTypeDesc, 
                         dbo.I10_Amcare_VR.WaitTimeinER, dbo.I10_Amcare_VR.WaittoAssessmentinMinutes, dbo.I10_Amcare_VR.WaittoNursingAssessmentDiff, dbo.I10_Amcare_VR.Weight, dbo.I10_Amcare_VR.zzAbstractLink, 
                         dbo.I10_Amcare_VR.zzRegionalPatientID, dbo.I10_Amcare_VR.zzVolumeLink, dbo.I10_Amcare_Consult_VR.ConsultOccurrence, dbo.I10_Amcare_Consult_VR.ConsultArrivalDate, 
                         dbo.I10_Amcare_Consult_VR.ConsultArrivalTime, dbo.I10_Amcare_Consult_VR.ConsultArrivalTimeUnknown, dbo.I10_Amcare_Consult_VR.ConsultArrivalTimeUnknownDesc, 
                         dbo.I10_Amcare_Consult_VR.ConsultNumber, dbo.I10_Amcare_Consult_VR.ConsultNumberDesc, dbo.I10_Amcare_Consult_VR.ConsultRequestDate, dbo.I10_Amcare_Consult_VR.ConsultRequestTime, 
                         dbo.I10_Amcare_Consult_VR.ConsultRequestTimeUnknown, dbo.I10_Amcare_Consult_VR.ConsultRequestTimeUnknownDesc, dbo.I10_Amcare_Consult_VR.ConsultService, 
                         dbo.I10_Amcare_Consult_VR.ConsultServiceDesc
FROM            dbo.I10_Amcare_VR LEFT OUTER JOIN
                         dbo.I10_Amcare_Consult_VR ON dbo.I10_Amcare_VR.zzAbstractLink = dbo.I10_Amcare_Consult_VR.zzAbstractLink







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_Amcare_And_Diagnosis_VR]
AS
SELECT        dbo.I10_Amcare_VR.[#ofPreviousPreTermDeliveries], dbo.I10_Amcare_VR.[#ofPrevSpontaneousAbortions], dbo.I10_Amcare_VR.[#ofPreviousTermDeliveries], dbo.I10_Amcare_VR.AccessPrimaryHealthCareCode, 
                         dbo.I10_Amcare_VR.AccessPrimaryHealthCareCodeDesc, dbo.I10_Amcare_VR.AmbulanceArrivalDate, dbo.I10_Amcare_VR.AmbulanceArrivalTime, dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknown, 
                         dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknownDesc, dbo.I10_Amcare_VR.AmbulanceTransferCareDate, dbo.I10_Amcare_VR.AmbulanceTransferCareTime, 
                         dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknown, dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknownDesc, dbo.I10_Amcare_VR.[#ofPrevTherapeuticAbortions], dbo.I10_Amcare_VR.AWOL, 
                         dbo.I10_Amcare_VR.AWOLDesc, dbo.I10_Amcare_VR.AbortDate, dbo.I10_Amcare_VR.AbstractNumber, dbo.I10_Amcare_VR.AbstractOverflow, dbo.I10_Amcare_VR.AbstractOverflowDesc, 
                         dbo.I10_Amcare_VR.ActivityDescription, dbo.I10_Amcare_VR.ActivityWhenInjured, dbo.I10_Amcare_VR.ActivityWhenInjuredDesc, dbo.I10_Amcare_VR.ActueLOS, dbo.I10_Amcare_VR.AdmitbyAmbulance, 
                         dbo.I10_Amcare_VR.AdmitbyAmbulanceDesc, dbo.I10_Amcare_VR.AdmitCategory, dbo.I10_Amcare_VR.AdmitDiagnosis, dbo.I10_Amcare_VR.AdmitNursingArea, dbo.I10_Amcare_VR.AdmitNursingAreaDesc, 
                         dbo.I10_Amcare_VR.AfterAdmit, dbo.I10_Amcare_VR.AgeCode, dbo.I10_Amcare_VR.AgeCodeDesc, dbo.I10_Amcare_VR.AgeGroup, dbo.I10_Amcare_VR.AgeNumber, dbo.I10_Amcare_VR.Albumin, 
                         dbo.I10_Amcare_VR.AlbuminDesc, dbo.I10_Amcare_VR.AlbuminCrossMatched, dbo.I10_Amcare_VR.AlbuminCrossMatchedDesc, dbo.I10_Amcare_VR.AlbuminTyped, dbo.I10_Amcare_VR.AlbuminTypedDesc, 
                         dbo.I10_Amcare_VR.AlbuminUnits, dbo.I10_Amcare_VR.ALCLOS, dbo.I10_Amcare_VR.AmbulanceReportNumber, dbo.I10_Amcare_VR.AmCareGroup, dbo.I10_Amcare_VR.AmCareGroupDesc, 
                         dbo.I10_Amcare_VR.AmcareCareType, dbo.I10_Amcare_VR.AmcareCareTypeDesc, dbo.I10_Amcare_VR.AmcareTypeCode, dbo.I10_Amcare_VR.AmcareTypeCodeDesc, dbo.I10_Amcare_VR.Ancil13, 
                         dbo.I10_Amcare_VR.Ancil14, dbo.I10_Amcare_VR.Ancil15, dbo.I10_Amcare_VR.Ancil16, dbo.I10_Amcare_VR.Ancil17, dbo.I10_Amcare_VR.AncillaryField1, dbo.I10_Amcare_VR.AncillaryField1Desc, 
                         dbo.I10_Amcare_VR.AncillaryField10, dbo.I10_Amcare_VR.AncillaryField10Desc, dbo.I10_Amcare_VR.AncillaryField11, dbo.I10_Amcare_VR.AncillaryField11Desc, dbo.I10_Amcare_VR.AncillaryField12, 
                         dbo.I10_Amcare_VR.AncillaryField12Desc, dbo.I10_Amcare_VR.AncillaryField2, dbo.I10_Amcare_VR.AncillaryField2Desc, dbo.I10_Amcare_VR.AncillaryField3, dbo.I10_Amcare_VR.AncillaryField3Desc, 
                         dbo.I10_Amcare_VR.AncillaryField4, dbo.I10_Amcare_VR.AncillaryField4Desc, dbo.I10_Amcare_VR.AncillaryField5, dbo.I10_Amcare_VR.AncillaryField5Desc, dbo.I10_Amcare_VR.AncillaryField6, 
                         dbo.I10_Amcare_VR.AncillaryField6Desc, dbo.I10_Amcare_VR.AncillaryField7, dbo.I10_Amcare_VR.AncillaryField7Desc, dbo.I10_Amcare_VR.AncillaryField8, dbo.I10_Amcare_VR.AncillaryField8Desc, 
                         dbo.I10_Amcare_VR.AncillaryField9, dbo.I10_Amcare_VR.AncillaryField9Desc, dbo.I10_Amcare_VR.ArrivalDate, dbo.I10_Amcare_VR.ArrivalMode, dbo.I10_Amcare_VR.ArrivalModeDesc, 
                         dbo.I10_Amcare_VR.ArrivalTime, dbo.I10_Amcare_VR.ArrivaltoTriageTime, dbo.I10_Amcare_VR.AssessmentDate, dbo.I10_Amcare_VR.AssessmentTime, dbo.I10_Amcare_VR.AssessmentTimeUnknown, 
                         dbo.I10_Amcare_VR.AssessmentTimeUnknownDesc, dbo.I10_Amcare_VR.AttendingPhysician, dbo.I10_Amcare_VR.AttendingPhysicianDesc, dbo.I10_Amcare_VR.AutoTransfusion, 
                         dbo.I10_Amcare_VR.AutoTransfusionDesc, dbo.I10_Amcare_VR.AutopsyPerformed, dbo.I10_Amcare_VR.AutopsyPerformedDesc, dbo.I10_Amcare_VR.BasicOption1, dbo.I10_Amcare_VR.BasicOption1Desc, 
                         dbo.I10_Amcare_VR.BasicOption10, dbo.I10_Amcare_VR.BasicOption10Desc, dbo.I10_Amcare_VR.BasicOption11, dbo.I10_Amcare_VR.BasicOption11Desc, dbo.I10_Amcare_VR.BasicOption12, 
                         dbo.I10_Amcare_VR.BasicOption12Desc, dbo.I10_Amcare_VR.BasicOption13, dbo.I10_Amcare_VR.BasicOption13Desc, dbo.I10_Amcare_VR.BasicOption14, dbo.I10_Amcare_VR.BasicOption14Desc, 
                         dbo.I10_Amcare_VR.BasicOption15, dbo.I10_Amcare_VR.BasicOption15Desc, dbo.I10_Amcare_VR.BasicOption16, dbo.I10_Amcare_VR.BasicOption16Desc, dbo.I10_Amcare_VR.BasicOption17, 
                         dbo.I10_Amcare_VR.BasicOption17Desc, dbo.I10_Amcare_VR.BasicOption18, dbo.I10_Amcare_VR.BasicOption18Desc, dbo.I10_Amcare_VR.BasicOption19, dbo.I10_Amcare_VR.BasicOption19Desc, 
                         dbo.I10_Amcare_VR.BasicOption2, dbo.I10_Amcare_VR.BasicOption2Desc, dbo.I10_Amcare_VR.BasicOption3, dbo.I10_Amcare_VR.BasicOption3Desc, dbo.I10_Amcare_VR.BasicOption4, 
                         dbo.I10_Amcare_VR.BasicOption4Desc, dbo.I10_Amcare_VR.BasicOption5, dbo.I10_Amcare_VR.BasicOption5Desc, dbo.I10_Amcare_VR.BasicOption6, dbo.I10_Amcare_VR.BasicOption6Desc, 
                         dbo.I10_Amcare_VR.BasicOption7, dbo.I10_Amcare_VR.BasicOption7Desc, dbo.I10_Amcare_VR.BasicOption8, dbo.I10_Amcare_VR.BasicOption8Desc, dbo.I10_Amcare_VR.BasicOption9, 
                         dbo.I10_Amcare_VR.BasicOption9Desc, dbo.I10_Amcare_VR.BatchNumber, dbo.I10_Amcare_VR.BatchPeriod, dbo.I10_Amcare_VR.BatchPeriodDesc, dbo.I10_Amcare_VR.BatchPeriod_BC, 
                         dbo.I10_Amcare_VR.BatchYear, dbo.I10_Amcare_VR.BirthDate, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIII, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIIIDesc, 
						 dbo.I10_Amcare_VR.Blood_C1Inhibitor, 
                         dbo.I10_Amcare_VR.Blood_C1InhibitorDesc, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasma, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_CryosupernatantPlasma, 
                         dbo.I10_Amcare_VR.Blood_CryosupernatantPlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_FEIBA, 
						 dbo.I10_Amcare_VR.Blood_FEIBADesc, 
						 dbo.I10_Amcare_VR.Blood_Fibrinogen, 
						 dbo.I10_Amcare_VR.Blood_FibrinogenDesc, 
                         dbo.I10_Amcare_VR.Blood_IVIG_SCIG, 
						 dbo.I10_Amcare_VR.Blood_IVIG_SCIGDesc, 
						 dbo.I10_Amcare_VR.Blood_PCC, 
						 dbo.I10_Amcare_VR.Blood_PCCDesc, 
						 dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactors, 
                         dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactorsDesc, 
						 
						 dbo.I10_Amcare_VR.BreastFeeding, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlag, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlagDesc, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitDateIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknown, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknownDesc, dbo.I10_Amcare_VR.ClinicalDecisionUnitDateOut, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOut, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknown, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknownDesc, dbo.I10_Amcare_VR.ChangeinLegalStatus, 
                         dbo.I10_Amcare_VR.ChangeinLegalStatusDesc, dbo.I10_Amcare_VR.ChartNumber, dbo.I10_Amcare_VR.ChiefComplaint, dbo.I10_Amcare_VR.CoderNumber, dbo.I10_Amcare_VR.CoderNumberDesc, 
                         dbo.I10_Amcare_VR.CompleteRecord, dbo.I10_Amcare_VR.CompleteRecordDesc, dbo.I10_Amcare_VR.Complication, dbo.I10_Amcare_VR.ComplicationDesc, dbo.I10_Amcare_VR.Complication1, 
                         dbo.I10_Amcare_VR.Complication1Desc, dbo.I10_Amcare_VR.Complication2, dbo.I10_Amcare_VR.Complication2Desc, dbo.I10_Amcare_VR.Complication3, dbo.I10_Amcare_VR.Complication3Desc, 
                         dbo.I10_Amcare_VR.ContactMode, dbo.I10_Amcare_VR.ContactModeDesc, dbo.I10_Amcare_VR.CoronerCase, dbo.I10_Amcare_VR.CoronerCaseDesc, dbo.I10_Amcare_VR.DataEntryCoder, 
                         dbo.I10_Amcare_VR.DataEntryCoderDesc, dbo.I10_Amcare_VR.DateLeftER, dbo.I10_Amcare_VR.DateofLastMenses, dbo.I10_Amcare_VR.DateReadyforDisch, dbo.I10_Amcare_VR.DateSentToCIHI, 
                         dbo.I10_Amcare_VR.DateSentToCIHILevel1, dbo.I10_Amcare_VR.DateSentToCIHILevel2, dbo.I10_Amcare_VR.DateSentToCIHILite, dbo.I10_Amcare_VR.DeathInER, dbo.I10_Amcare_VR.DeathInERDesc, 
                         dbo.I10_Amcare_VR.DeathOnArrival, dbo.I10_Amcare_VR.DeathOnArrivalDesc, dbo.I10_Amcare_VR.DecisionAdmitDifference, dbo.I10_Amcare_VR.DecisiontoAdmitDate, dbo.I10_Amcare_VR.DecisiontoAdmitTime, 
                         dbo.I10_Amcare_VR.DecisionAdmitTimeUnknown, dbo.I10_Amcare_VR.DecisionAdmitTimeUnknownDesc, dbo.I10_Amcare_VR.DeliveryDate, dbo.I10_Amcare_VR.DeliveryTime, 
                         dbo.I10_Amcare_VR.DiedDuringIntervention, dbo.I10_Amcare_VR.DiedDuringInterventionDesc, dbo.I10_Amcare_VR.DischNursingArea, dbo.I10_Amcare_VR.DischNursingAreaDesc, 
                         dbo.I10_Amcare_VR.DischPlanning, dbo.I10_Amcare_VR.DischPlanningDesc, dbo.I10_Amcare_VR.DischargeAge, dbo.I10_Amcare_VR.DischargeDisposition, dbo.I10_Amcare_VR.DischargeDispositionDesc, 
                         dbo.I10_Amcare_VR.DispositionDate, dbo.I10_Amcare_VR.DispositionTime, dbo.I10_Amcare_VR.DispositionTimeUnknown, dbo.I10_Amcare_VR.DispositionTimeUnknownDesc, dbo.I10_Amcare_VR.ECTTreatment, 
                         dbo.I10_Amcare_VR.ECTTreatmentDesc, dbo.I10_Amcare_VR.Education, dbo.I10_Amcare_VR.EducationDesc, dbo.I10_Amcare_VR.EDVisitIndicator, dbo.I10_Amcare_VR.EDVisitIndicatorDesc, 
                         dbo.I10_Amcare_VR.Employment, dbo.I10_Amcare_VR.EmploymentDesc, dbo.I10_Amcare_VR.EntryCode, dbo.I10_Amcare_VR.EstimateDischDate, dbo.I10_Amcare_VR.ExitCode, 
                         dbo.I10_Amcare_VR.FamilyPhysicianFlag, dbo.I10_Amcare_VR.FamilyPhysicianFlagDesc, dbo.I10_Amcare_VR.FinancialSupport, dbo.I10_Amcare_VR.FinancialSupportDesc, dbo.I10_Amcare_VR.FinishDate, 
                         dbo.I10_Amcare_VR.FinishTime, dbo.I10_Amcare_VR.FirstName, dbo.I10_Amcare_VR.FullName, dbo.I10_Amcare_VR.FixedChartNumber, dbo.I10_Amcare_VR.Gender, dbo.I10_Amcare_VR.GenderDesc, 
                         dbo.I10_Amcare_VR.GestationalAgeinweeks, dbo.I10_Amcare_VR.GlasgowScale, dbo.I10_Amcare_VR.GlasgowScaleDesc, dbo.I10_Amcare_VR.GreaterTenPO, dbo.I10_Amcare_VR.HCNProvince, 
                         dbo.I10_Amcare_VR.HCNProvinceDesc, dbo.I10_Amcare_VR.HCNVersion, dbo.I10_Amcare_VR.HealthCareNumber, dbo.I10_Amcare_VR.Hospital, dbo.I10_Amcare_VR.HospitalDesc, 
                         dbo.I10_Amcare_VR.HospitalAccountRecord,
                         dbo.I10_Amcare_VR.HelmetIndicator, dbo.I10_Amcare_VR.HelmetIndicatorDesc, dbo.I10_Amcare_VR.InSCU, dbo.I10_Amcare_VR.InitialOR, dbo.I10_Amcare_VR.InitialORDesc, dbo.I10_Amcare_VR.InjuryDate, 
                         dbo.I10_Amcare_VR.Injury, dbo.I10_Amcare_VR.InjuryDesc, dbo.I10_Amcare_VR.InputDate, dbo.I10_Amcare_VR.InputTime,

						 dbo.I10_Amcare_VR.InstitutionFrom, dbo.I10_Amcare_VR.InstitutionFromDesc, 
						 dbo.I10_Amcare_VR.InstitutionFromType, dbo.I10_Amcare_VR.InstitutionFromTypeDesc,
                         dbo.I10_Amcare_VR.InstFromCareType, dbo.I10_Amcare_VR.InstFromHospType, 
						 dbo.I10_Amcare_VR.InstitutionNumber, dbo.I10_Amcare_VR.InstitutionNumberDesc, 
						 dbo.I10_Amcare_VR.InstitutionTo, dbo.I10_Amcare_VR.InstitutionToDesc, 
						 dbo.I10_Amcare_VR.InstToCareType, dbo.I10_Amcare_VR.InstToHospType, 
						 dbo.I10_Amcare_VR.InstitutionToType, dbo.I10_Amcare_VR.InstitutionToTypeDesc, 
						 
						 dbo.I10_Amcare_VR.InterfaceDate, dbo.I10_Amcare_VR.InterfaceTime, 
                         dbo.I10_Amcare_VR.IsAbstractCompleted, dbo.I10_Amcare_VR.IsAbstractCompletedDesc, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCompletedLevel2, dbo.I10_Amcare_VR.IsAbstractCompletedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCompletedLite, dbo.I10_Amcare_VR.IsAbstractCompletedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrected, dbo.I10_Amcare_VR.IsAbstractCorrectedDesc, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCorrectedLite, dbo.I10_Amcare_VR.IsAbstractCorrectedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractDeleted, dbo.I10_Amcare_VR.IsAbstractDeletedDesc, dbo.I10_Amcare_VR.IsAbstractSubmitted, dbo.I10_Amcare_VR.IsAbstractSubmittedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLite, dbo.I10_Amcare_VR.IsAbstractSubmittedLiteDesc, dbo.I10_Amcare_VR.IsAbstractValidated, dbo.I10_Amcare_VR.IsAbstractValidatedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLevel1, dbo.I10_Amcare_VR.IsAbstractValidatedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLite, dbo.I10_Amcare_VR.IsAbstractValidatedLiteDesc, dbo.I10_Amcare_VR.IsBirthdateEstimated, dbo.I10_Amcare_VR.IsBirthdateEstimatedDesc, 
						 dbo.I10_Amcare_VR.IsCustomValidated, dbo.I10_Amcare_VR.IsCustomValidatedDesc,
                         dbo.I10_Amcare_VR.LOSDays, dbo.I10_Amcare_VR.LOSTime, dbo.I10_Amcare_VR.LOSTimeinHours, dbo.I10_Amcare_VR.LOSTotalMinutes, dbo.I10_Amcare_VR.Language, dbo.I10_Amcare_VR.LanguageDesc, 
                         dbo.I10_Amcare_VR.LastName, dbo.I10_Amcare_VR.LessTwoPO, dbo.I10_Amcare_VR.LivingArrangement, dbo.I10_Amcare_VR.LivingArrangementDesc, dbo.I10_Amcare_VR.LocationofInjury, 
                         dbo.I10_Amcare_VR.LocationofInjuryDesc, dbo.I10_Amcare_VR.MISCode, dbo.I10_Amcare_VR.MISCodeDesc, dbo.I10_Amcare_VR.MaidenName, dbo.I10_Amcare_VR.MaritalStatus, 
                         dbo.I10_Amcare_VR.MaritalStatusDesc, 
                         dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoED, 
						 dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04Desc, 
						 
						 dbo.I10_Amcare_VR.MethodofAdmission, dbo.I10_Amcare_VR.MethodofAdmissionDesc, dbo.I10_Amcare_VR.MiddleName, 
                         dbo.I10_Amcare_VR.NACRSClinicLiteSubmission, dbo.I10_Amcare_VR.NACRSClinicLiteSubmissionDesc, 
                         dbo.I10_Amcare_VR.NewbornChart, 
                         dbo.I10_Amcare_VR.NewbornDischDate, dbo.I10_Amcare_VR.NextScheduledVisitDate, dbo.I10_Amcare_VR.NextScheduledVisitTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentDate, 
                         dbo.I10_Amcare_VR.NonPhysicianAssessmentTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknown, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.NonPhysicianNumber, dbo.I10_Amcare_VR.NonPhysicianNumberDesc, dbo.I10_Amcare_VR.NonPhysicianService, dbo.I10_Amcare_VR.NonPhysicianServiceDesc, 
                         dbo.I10_Amcare_VR.NumberofECT, dbo.I10_Amcare_VR.NursingAssessmentDate, dbo.I10_Amcare_VR.NursingAssessmentTime, dbo.I10_Amcare_VR.Occupation, dbo.I10_Amcare_VR.OccupationDesc, 
                         dbo.I10_Amcare_VR.OtherMedicalDeath, dbo.I10_Amcare_VR.OtherMedicalDeathDesc, dbo.I10_Amcare_VR.OtherBlood, dbo.I10_Amcare_VR.OtherBloodDesc, dbo.I10_Amcare_VR.OtherBloodCrossMatched, 
                         dbo.I10_Amcare_VR.OtherBloodCrossMatchedDesc, dbo.I10_Amcare_VR.OtherBloodTyped, dbo.I10_Amcare_VR.OtherBloodTypedDesc, dbo.I10_Amcare_VR.OtherBloodUnits, dbo.I10_Amcare_VR.PCTASIndicator, 
                         dbo.I10_Amcare_VR.PCTASIndicatorDesc, dbo.I10_Amcare_VR.PhysicianEstLOS, dbo.I10_Amcare_VR.Plasma, dbo.I10_Amcare_VR.PlasmaDesc, dbo.I10_Amcare_VR.PlasmaCrossMatched, 
                         dbo.I10_Amcare_VR.PlasmaCrossMatchedDesc, dbo.I10_Amcare_VR.PlasmaTyped, dbo.I10_Amcare_VR.PlasmaTypedDesc, dbo.I10_Amcare_VR.PlasmaUnits, dbo.I10_Amcare_VR.Platelets, 
                         dbo.I10_Amcare_VR.PlateletsDesc, dbo.I10_Amcare_VR.PlateletsCrossMatched, dbo.I10_Amcare_VR.PlateletsCrossMatchedDesc, dbo.I10_Amcare_VR.PlateletsTyped, dbo.I10_Amcare_VR.PlateletsTypedDesc, 
                         dbo.I10_Amcare_VR.PlateletsUnits, dbo.I10_Amcare_VR.PostalCode, dbo.I10_Amcare_VR.PostalCodeDesc, dbo.I10_Amcare_VR.PostOpDays, dbo.I10_Amcare_VR.PreOpDays, 
                         dbo.I10_Amcare_VR.PreamditWorkUp, dbo.I10_Amcare_VR.PreamditWorkUpDesc, dbo.I10_Amcare_VR.Pregnancy, dbo.I10_Amcare_VR.PregnancyDesc, dbo.I10_Amcare_VR.PrevLiveBirth, 
                         dbo.I10_Amcare_VR.PreviousPsychiartricAdmissions, dbo.I10_Amcare_VR.PreviousPsychiartricAdmDesc, dbo.I10_Amcare_VR.Program, dbo.I10_Amcare_VR.ProgramDesc, dbo.I10_Amcare_VR.ProvinceNumber, 
                         dbo.I10_Amcare_VR.ProvinceNumberDesc, dbo.I10_Amcare_VR.ReasonForVisit, dbo.I10_Amcare_VR.ReasonForVisitDesc, dbo.I10_Amcare_VR.ReAdmitCode, dbo.I10_Amcare_VR.ReciprocalBillingStatus, 
                         dbo.I10_Amcare_VR.ReciprocalBillingStatusDesc, dbo.I10_Amcare_VR.RedBloodCell, dbo.I10_Amcare_VR.RedBloodCellDesc, dbo.I10_Amcare_VR.RedBloodCellCrossMatched, 
                         dbo.I10_Amcare_VR.RedBloodCellCrossMatchedDesc, dbo.I10_Amcare_VR.RedBloodCellTyped, dbo.I10_Amcare_VR.RedBloodCellTypedDesc, dbo.I10_Amcare_VR.RedBloodCellUnits, 
                         dbo.I10_Amcare_VR.ReferralDate, dbo.I10_Amcare_VR.ReferredFrom, dbo.I10_Amcare_VR.ReferredFromDesc, dbo.I10_Amcare_VR.ReferredTo, dbo.I10_Amcare_VR.ReferredToDesc, 
                         dbo.I10_Amcare_VR.ReferringProvider, dbo.I10_Amcare_VR.ReferringProviderDesc, dbo.I10_Amcare_VR.RegisterNumber, dbo.I10_Amcare_VR.RegistrationNumber, 
                         dbo.I10_Amcare_VR.RegistrationSequenceNumber, dbo.I10_Amcare_VR.RegistrationVisitDate, dbo.I10_Amcare_VR.RegistrationVisitTime, dbo.I10_Amcare_VR.ReproductiveCareComments, 
                         dbo.I10_Amcare_VR.ReserveField, dbo.I10_Amcare_VR.ResidenceCode, dbo.I10_Amcare_VR.ResidenceCodeDesc, dbo.I10_Amcare_VR.ResidenceProvince, dbo.I10_Amcare_VR.ResidenceProvinceDesc, 
                         dbo.I10_Amcare_VR.ResidenceRegion, dbo.I10_Amcare_VR.ResidenceRegionDesc, dbo.I10_Amcare_VR.ResidenceType, dbo.I10_Amcare_VR.ResidenceTypeDesc, dbo.I10_Amcare_VR.ResponsiblityForPayment,
                          dbo.I10_Amcare_VR.ResponsiblityForPaymentDesc, dbo.I10_Amcare_VR.SchedEDVisit, dbo.I10_Amcare_VR.SchedEDVisitDesc, dbo.I10_Amcare_VR.SeatbeltIndicator, dbo.I10_Amcare_VR.SeatbeltIndicatorDesc, 
                         dbo.I10_Amcare_VR.SecondChartRegisterNumber, dbo.I10_Amcare_VR.SecretVIPPatient, dbo.I10_Amcare_VR.SecretVIPPatientDesc, dbo.I10_Amcare_VR.SiteNumber, dbo.I10_Amcare_VR.SiteNumberDesc, 
                         dbo.I10_Amcare_VR.SocialService, dbo.I10_Amcare_VR.SocialServiceDesc, dbo.I10_Amcare_VR.SourceofReferral, dbo.I10_Amcare_VR.SourceofReferralDesc, dbo.I10_Amcare_VR.SpecialistNumber, 
                         dbo.I10_Amcare_VR.SpecialistNumberDesc, dbo.I10_Amcare_VR.SpecialistRequestDate, dbo.I10_Amcare_VR.SpecialistRequestService, dbo.I10_Amcare_VR.SpecialistRequestServiceDesc, 
                         dbo.I10_Amcare_VR.SpecialistRequestTime, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknown, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknownDesc, dbo.I10_Amcare_VR.StakeholderType, 
                         dbo.I10_Amcare_VR.StakeholderTypeDesc, dbo.I10_Amcare_VR.StatusAfterTriage, dbo.I10_Amcare_VR.StatusAfterTriageDesc, dbo.I10_Amcare_VR.Sterilization, dbo.I10_Amcare_VR.SterilizationDesc, 
                         dbo.I10_Amcare_VR.SubmissionLevelCode, dbo.I10_Amcare_VR.SubmissionRecordID, dbo.I10_Amcare_VR.SubsequentOR, dbo.I10_Amcare_VR.SubsequentORDesc, dbo.I10_Amcare_VR.Suicide, 
                         dbo.I10_Amcare_VR.SuicideDesc, dbo.I10_Amcare_VR.SurgicalCase, dbo.I10_Amcare_VR.SurgicalCaseDesc, dbo.I10_Amcare_VR.TimeLeftER, dbo.I10_Amcare_VR.TimeLeftERUnknown, 
                         dbo.I10_Amcare_VR.TimeLeftERUnknownDEsc, dbo.I10_Amcare_VR.TransferOverloadDate, dbo.I10_Amcare_VR.TransferOverloadTime, dbo.I10_Amcare_VR.TransferOverloadTimeDifference, 
                         dbo.I10_Amcare_VR.TransfusionGiven, dbo.I10_Amcare_VR.TransfusionGivenDesc, dbo.I10_Amcare_VR.Trauma, dbo.I10_Amcare_VR.TraumaDesc, dbo.I10_Amcare_VR.TriageDate, 
                         dbo.I10_Amcare_VR.TriageLevel, dbo.I10_Amcare_VR.TriageLevelDesc, dbo.I10_Amcare_VR.TriageTime, dbo.I10_Amcare_VR.TriageTimeUnknown, dbo.I10_Amcare_VR.TriageTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.TSICoder, dbo.I10_Amcare_VR.TSICoderDesc, dbo.I10_Amcare_VR.TSIDate, dbo.I10_Amcare_VR.TSITime, dbo.I10_Amcare_VR.TwoTenPO, dbo.I10_Amcare_VR.ULI, 
                         dbo.I10_Amcare_VR.UniversalEpisodeIdentifier, dbo.I10_Amcare_VR.UnplannedReadmit, dbo.I10_Amcare_VR.VisitStatus, dbo.I10_Amcare_VR.VisitStatusDesc, dbo.I10_Amcare_VR.VisitType, dbo.I10_Amcare_VR.VisitTypeDesc, 
                         dbo.I10_Amcare_VR.WaitTimeinER, dbo.I10_Amcare_VR.WaittoAssessmentinMinutes, dbo.I10_Amcare_VR.WaittoNursingAssessmentDiff, dbo.I10_Amcare_VR.Weight, dbo.I10_Amcare_VR.zzAbstractLink, 
                         dbo.I10_Amcare_VR.zzRegionalPatientID, dbo.I10_Amcare_VR.zzVolumeLink, dbo.I10_Amcare_Diagnosis_VR.DiagnosisCluster, dbo.I10_Amcare_Diagnosis_VR.DiagnosisCIHIValue, 
                         dbo.I10_Amcare_Diagnosis_VR.DiagnosisCode, dbo.I10_Amcare_Diagnosis_VR.DiagnosisCodeDesc, dbo.I10_Amcare_Diagnosis_VR.DiagnosisCodeShortDesc, 
                         dbo.I10_Amcare_Diagnosis_VR.DiagnosisICD9Equivalent, dbo.I10_Amcare_Diagnosis_VR.DiagnosisICD9cmEquivalent, dbo.I10_Amcare_Diagnosis_VR.DiagnosisOccurrence, 
                         dbo.I10_Amcare_Diagnosis_VR.DiagnosisPrefix, dbo.I10_Amcare_Diagnosis_VR.DiagnosisPrefixDesc, dbo.I10_Amcare_Diagnosis_VR.DiagnosisSuffix, dbo.I10_Amcare_Diagnosis_VR.DiagnosisSuffixDesc, 
                         dbo.I10_Amcare_Diagnosis_VR.DiagnosisType, dbo.I10_Amcare_Diagnosis_VR.DiagnosisTypeDesc
FROM            dbo.I10_Amcare_VR LEFT OUTER JOIN
                         dbo.I10_Amcare_Diagnosis_VR ON dbo.I10_Amcare_VR.zzAbstractLink = dbo.I10_Amcare_Diagnosis_VR.zzAbstractLink



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_DischargeDiagnosis]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_Amcare_And_DischargeDiagnosis]
AS
SELECT        dbo.I10_Amcare_VR.[#ofPreviousPreTermDeliveries], dbo.I10_Amcare_VR.[#ofPrevSpontaneousAbortions], dbo.I10_Amcare_VR.[#ofPreviousTermDeliveries], dbo.I10_Amcare_VR.AccessPrimaryHealthCareCode, 
                         dbo.I10_Amcare_VR.AccessPrimaryHealthCareCodeDesc, dbo.I10_Amcare_VR.AmbulanceArrivalDate, dbo.I10_Amcare_VR.AmbulanceArrivalTime, dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknown, 
                         dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknownDesc, dbo.I10_Amcare_VR.AmbulanceTransferCareDate, dbo.I10_Amcare_VR.AmbulanceTransferCareTime, 
                         dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknown, dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknownDesc, dbo.I10_Amcare_VR.[#ofPrevTherapeuticAbortions], dbo.I10_Amcare_VR.AWOL, 
                         dbo.I10_Amcare_VR.AWOLDesc, dbo.I10_Amcare_VR.AbortDate, dbo.I10_Amcare_VR.AbstractNumber, dbo.I10_Amcare_VR.AbstractOverflow, dbo.I10_Amcare_VR.AbstractOverflowDesc, 
                         dbo.I10_Amcare_VR.ActivityDescription, dbo.I10_Amcare_VR.ActivityWhenInjured, dbo.I10_Amcare_VR.ActivityWhenInjuredDesc, dbo.I10_Amcare_VR.ActueLOS, dbo.I10_Amcare_VR.AdmitbyAmbulance, 
                         dbo.I10_Amcare_VR.AdmitbyAmbulanceDesc, dbo.I10_Amcare_VR.AdmitCategory, dbo.I10_Amcare_VR.AdmitDiagnosis, dbo.I10_Amcare_VR.AdmitNursingArea, dbo.I10_Amcare_VR.AdmitNursingAreaDesc, 
                         dbo.I10_Amcare_VR.AfterAdmit, dbo.I10_Amcare_VR.AgeCode, dbo.I10_Amcare_VR.AgeCodeDesc, dbo.I10_Amcare_VR.AgeGroup, dbo.I10_Amcare_VR.AgeNumber, dbo.I10_Amcare_VR.Albumin, 
                         dbo.I10_Amcare_VR.AlbuminDesc, dbo.I10_Amcare_VR.AlbuminCrossMatched, dbo.I10_Amcare_VR.AlbuminCrossMatchedDesc, dbo.I10_Amcare_VR.AlbuminTyped, dbo.I10_Amcare_VR.AlbuminTypedDesc, 
                         dbo.I10_Amcare_VR.AlbuminUnits, dbo.I10_Amcare_VR.ALCLOS, dbo.I10_Amcare_VR.AmbulanceReportNumber, dbo.I10_Amcare_VR.AmCareGroup, dbo.I10_Amcare_VR.AmCareGroupDesc, 
                         dbo.I10_Amcare_VR.AmcareCareType, dbo.I10_Amcare_VR.AmcareCareTypeDesc, dbo.I10_Amcare_VR.AmcareTypeCode, dbo.I10_Amcare_VR.AmcareTypeCodeDesc, dbo.I10_Amcare_VR.Ancil13, 
                         dbo.I10_Amcare_VR.Ancil14, dbo.I10_Amcare_VR.Ancil15, dbo.I10_Amcare_VR.Ancil16, dbo.I10_Amcare_VR.Ancil17, dbo.I10_Amcare_VR.AncillaryField1, dbo.I10_Amcare_VR.AncillaryField1Desc, 
                         dbo.I10_Amcare_VR.AncillaryField10, dbo.I10_Amcare_VR.AncillaryField10Desc, dbo.I10_Amcare_VR.AncillaryField11, dbo.I10_Amcare_VR.AncillaryField11Desc, dbo.I10_Amcare_VR.AncillaryField12, 
                         dbo.I10_Amcare_VR.AncillaryField12Desc, dbo.I10_Amcare_VR.AncillaryField2, dbo.I10_Amcare_VR.AncillaryField2Desc, dbo.I10_Amcare_VR.AncillaryField3, dbo.I10_Amcare_VR.AncillaryField3Desc, 
                         dbo.I10_Amcare_VR.AncillaryField4, dbo.I10_Amcare_VR.AncillaryField4Desc, dbo.I10_Amcare_VR.AncillaryField5, dbo.I10_Amcare_VR.AncillaryField5Desc, dbo.I10_Amcare_VR.AncillaryField6, 
                         dbo.I10_Amcare_VR.AncillaryField6Desc, dbo.I10_Amcare_VR.AncillaryField7, dbo.I10_Amcare_VR.AncillaryField7Desc, dbo.I10_Amcare_VR.AncillaryField8, dbo.I10_Amcare_VR.AncillaryField8Desc, 
                         dbo.I10_Amcare_VR.AncillaryField9, dbo.I10_Amcare_VR.AncillaryField9Desc, dbo.I10_Amcare_VR.ArrivalDate, dbo.I10_Amcare_VR.ArrivalMode, dbo.I10_Amcare_VR.ArrivalModeDesc, 
                         dbo.I10_Amcare_VR.ArrivalTime, dbo.I10_Amcare_VR.ArrivaltoTriageTime, dbo.I10_Amcare_VR.AssessmentDate, dbo.I10_Amcare_VR.AssessmentTime, dbo.I10_Amcare_VR.AssessmentTimeUnknown, 
                         dbo.I10_Amcare_VR.AssessmentTimeUnknownDesc, dbo.I10_Amcare_VR.AttendingPhysician, dbo.I10_Amcare_VR.AttendingPhysicianDesc, dbo.I10_Amcare_VR.AutoTransfusion, 
                         dbo.I10_Amcare_VR.AutoTransfusionDesc, dbo.I10_Amcare_VR.AutopsyPerformed, dbo.I10_Amcare_VR.AutopsyPerformedDesc, dbo.I10_Amcare_VR.BasicOption1, dbo.I10_Amcare_VR.BasicOption1Desc, 
                         dbo.I10_Amcare_VR.BasicOption10, dbo.I10_Amcare_VR.BasicOption10Desc, dbo.I10_Amcare_VR.BasicOption11, dbo.I10_Amcare_VR.BasicOption11Desc, dbo.I10_Amcare_VR.BasicOption12, 
                         dbo.I10_Amcare_VR.BasicOption12Desc, dbo.I10_Amcare_VR.BasicOption13, dbo.I10_Amcare_VR.BasicOption13Desc, dbo.I10_Amcare_VR.BasicOption14, dbo.I10_Amcare_VR.BasicOption14Desc, 
                         dbo.I10_Amcare_VR.BasicOption15, dbo.I10_Amcare_VR.BasicOption15Desc, dbo.I10_Amcare_VR.BasicOption16, dbo.I10_Amcare_VR.BasicOption16Desc, dbo.I10_Amcare_VR.BasicOption17, 
                         dbo.I10_Amcare_VR.BasicOption17Desc, dbo.I10_Amcare_VR.BasicOption18, dbo.I10_Amcare_VR.BasicOption18Desc, dbo.I10_Amcare_VR.BasicOption19, dbo.I10_Amcare_VR.BasicOption19Desc, 
                         dbo.I10_Amcare_VR.BasicOption2, dbo.I10_Amcare_VR.BasicOption2Desc, dbo.I10_Amcare_VR.BasicOption3, dbo.I10_Amcare_VR.BasicOption3Desc, dbo.I10_Amcare_VR.BasicOption4, 
                         dbo.I10_Amcare_VR.BasicOption4Desc, dbo.I10_Amcare_VR.BasicOption5, dbo.I10_Amcare_VR.BasicOption5Desc, dbo.I10_Amcare_VR.BasicOption6, dbo.I10_Amcare_VR.BasicOption6Desc, 
                         dbo.I10_Amcare_VR.BasicOption7, dbo.I10_Amcare_VR.BasicOption7Desc, dbo.I10_Amcare_VR.BasicOption8, dbo.I10_Amcare_VR.BasicOption8Desc, dbo.I10_Amcare_VR.BasicOption9, 
                         dbo.I10_Amcare_VR.BasicOption9Desc, dbo.I10_Amcare_VR.BatchNumber, dbo.I10_Amcare_VR.BatchPeriod, dbo.I10_Amcare_VR.BatchPeriodDesc, dbo.I10_Amcare_VR.BatchPeriod_BC, 
                         dbo.I10_Amcare_VR.BatchYear, dbo.I10_Amcare_VR.BirthDate, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIII, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIIIDesc, 
						 dbo.I10_Amcare_VR.Blood_C1Inhibitor, 
                         dbo.I10_Amcare_VR.Blood_C1InhibitorDesc, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasma, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_CryosupernatantPlasma, 
                         dbo.I10_Amcare_VR.Blood_CryosupernatantPlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_FEIBA, 
						 dbo.I10_Amcare_VR.Blood_FEIBADesc, 
						 dbo.I10_Amcare_VR.Blood_Fibrinogen, 
						 dbo.I10_Amcare_VR.Blood_FibrinogenDesc, 
                         dbo.I10_Amcare_VR.Blood_IVIG_SCIG, 
						 dbo.I10_Amcare_VR.Blood_IVIG_SCIGDesc, 
						 dbo.I10_Amcare_VR.Blood_PCC, 
						 dbo.I10_Amcare_VR.Blood_PCCDesc, 
						 dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactors, 
                         dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactorsDesc,						 
						 dbo.I10_Amcare_VR.BreastFeeding, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlag, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlagDesc, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitDateIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknown, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknownDesc, dbo.I10_Amcare_VR.ClinicalDecisionUnitDateOut, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOut, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknown, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknownDesc, dbo.I10_Amcare_VR.ChangeinLegalStatus, 
                         dbo.I10_Amcare_VR.ChangeinLegalStatusDesc, dbo.I10_Amcare_VR.ChartNumber, dbo.I10_Amcare_VR.ChiefComplaint, dbo.I10_Amcare_VR.CoderNumber, dbo.I10_Amcare_VR.CoderNumberDesc, 
                         dbo.I10_Amcare_VR.CompleteRecord, dbo.I10_Amcare_VR.CompleteRecordDesc, dbo.I10_Amcare_VR.Complication, dbo.I10_Amcare_VR.ComplicationDesc, dbo.I10_Amcare_VR.Complication1, 
                         dbo.I10_Amcare_VR.Complication1Desc, dbo.I10_Amcare_VR.Complication2, dbo.I10_Amcare_VR.Complication2Desc, dbo.I10_Amcare_VR.Complication3, dbo.I10_Amcare_VR.Complication3Desc, 
                         dbo.I10_Amcare_VR.ContactMode, dbo.I10_Amcare_VR.ContactModeDesc, dbo.I10_Amcare_VR.CoronerCase, dbo.I10_Amcare_VR.CoronerCaseDesc, dbo.I10_Amcare_VR.DataEntryCoder, 
                         dbo.I10_Amcare_VR.DataEntryCoderDesc, dbo.I10_Amcare_VR.DateLeftER, dbo.I10_Amcare_VR.DateofLastMenses, dbo.I10_Amcare_VR.DateReadyforDisch, dbo.I10_Amcare_VR.DateSentToCIHI, 
                         dbo.I10_Amcare_VR.DateSentToCIHILevel1, dbo.I10_Amcare_VR.DateSentToCIHILevel2, dbo.I10_Amcare_VR.DateSentToCIHILite, dbo.I10_Amcare_VR.DeathInER, dbo.I10_Amcare_VR.DeathInERDesc, 
                         dbo.I10_Amcare_VR.DeathOnArrival, dbo.I10_Amcare_VR.DeathOnArrivalDesc, dbo.I10_Amcare_VR.DecisionAdmitDifference, dbo.I10_Amcare_VR.DecisiontoAdmitDate, dbo.I10_Amcare_VR.DecisiontoAdmitTime, 
                         dbo.I10_Amcare_VR.DecisionAdmitTimeUnknown, dbo.I10_Amcare_VR.DecisionAdmitTimeUnknownDesc, dbo.I10_Amcare_VR.DeliveryDate, dbo.I10_Amcare_VR.DeliveryTime, 
                         dbo.I10_Amcare_VR.DiedDuringIntervention, dbo.I10_Amcare_VR.DiedDuringInterventionDesc, dbo.I10_Amcare_VR.DischNursingArea, dbo.I10_Amcare_VR.DischNursingAreaDesc, 
                         dbo.I10_Amcare_VR.DischPlanning, dbo.I10_Amcare_VR.DischPlanningDesc, dbo.I10_Amcare_VR.DischargeAge, dbo.I10_Amcare_VR.DischargeDisposition, dbo.I10_Amcare_VR.DischargeDispositionDesc, 
                         dbo.I10_Amcare_VR.DispositionDate, dbo.I10_Amcare_VR.DispositionTime, dbo.I10_Amcare_VR.DispositionTimeUnknown, dbo.I10_Amcare_VR.DispositionTimeUnknownDesc, dbo.I10_Amcare_VR.ECTTreatment, 
                         dbo.I10_Amcare_VR.ECTTreatmentDesc, dbo.I10_Amcare_VR.Education, dbo.I10_Amcare_VR.EducationDesc, dbo.I10_Amcare_VR.EDVisitIndicator, dbo.I10_Amcare_VR.EDVisitIndicatorDesc, 
                         dbo.I10_Amcare_VR.Employment, dbo.I10_Amcare_VR.EmploymentDesc, dbo.I10_Amcare_VR.EntryCode, dbo.I10_Amcare_VR.EstimateDischDate, dbo.I10_Amcare_VR.ExitCode, 
                         dbo.I10_Amcare_VR.FamilyPhysicianFlag, dbo.I10_Amcare_VR.FamilyPhysicianFlagDesc, dbo.I10_Amcare_VR.FinancialSupport, dbo.I10_Amcare_VR.FinancialSupportDesc, dbo.I10_Amcare_VR.FinishDate, 
                         dbo.I10_Amcare_VR.FinishTime, dbo.I10_Amcare_VR.FirstName, dbo.I10_Amcare_VR.FullName, dbo.I10_Amcare_VR.FixedChartNumber, dbo.I10_Amcare_VR.Gender, dbo.I10_Amcare_VR.GenderDesc, 
                         dbo.I10_Amcare_VR.GestationalAgeinweeks, dbo.I10_Amcare_VR.GlasgowScale, dbo.I10_Amcare_VR.GlasgowScaleDesc, dbo.I10_Amcare_VR.GreaterTenPO, dbo.I10_Amcare_VR.HCNProvince, 
                         dbo.I10_Amcare_VR.HCNProvinceDesc, dbo.I10_Amcare_VR.HCNVersion, dbo.I10_Amcare_VR.HealthCareNumber, dbo.I10_Amcare_VR.Hospital, dbo.I10_Amcare_VR.HospitalDesc, 
                         dbo.I10_Amcare_VR.HospitalAccountRecord,
                         dbo.I10_Amcare_VR.HelmetIndicator, dbo.I10_Amcare_VR.HelmetIndicatorDesc, dbo.I10_Amcare_VR.InSCU, dbo.I10_Amcare_VR.InitialOR, dbo.I10_Amcare_VR.InitialORDesc, dbo.I10_Amcare_VR.InjuryDate, 
                         dbo.I10_Amcare_VR.Injury, dbo.I10_Amcare_VR.InjuryDesc, dbo.I10_Amcare_VR.InputDate, dbo.I10_Amcare_VR.InputTime, 

						 dbo.I10_Amcare_VR.InstitutionFrom, dbo.I10_Amcare_VR.InstitutionFromDesc, 
						 dbo.I10_Amcare_VR.InstitutionFromType, dbo.I10_Amcare_VR.InstitutionFromTypeDesc,
                         dbo.I10_Amcare_VR.InstFromCareType, dbo.I10_Amcare_VR.InstFromHospType, 
						 dbo.I10_Amcare_VR.InstitutionNumber, dbo.I10_Amcare_VR.InstitutionNumberDesc, 
						 dbo.I10_Amcare_VR.InstitutionTo, dbo.I10_Amcare_VR.InstitutionToDesc, 
						 dbo.I10_Amcare_VR.InstToCareType, dbo.I10_Amcare_VR.InstToHospType, 
						 dbo.I10_Amcare_VR.InstitutionToType, dbo.I10_Amcare_VR.InstitutionToTypeDesc, 
						 
						 dbo.I10_Amcare_VR.InterfaceDate, dbo.I10_Amcare_VR.InterfaceTime, 
                         dbo.I10_Amcare_VR.IsAbstractCompleted, dbo.I10_Amcare_VR.IsAbstractCompletedDesc, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCompletedLevel2, dbo.I10_Amcare_VR.IsAbstractCompletedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCompletedLite, dbo.I10_Amcare_VR.IsAbstractCompletedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrected, dbo.I10_Amcare_VR.IsAbstractCorrectedDesc, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCorrectedLite, dbo.I10_Amcare_VR.IsAbstractCorrectedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractDeleted, dbo.I10_Amcare_VR.IsAbstractDeletedDesc, dbo.I10_Amcare_VR.IsAbstractSubmitted, dbo.I10_Amcare_VR.IsAbstractSubmittedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLite, dbo.I10_Amcare_VR.IsAbstractSubmittedLiteDesc, dbo.I10_Amcare_VR.IsAbstractValidated, dbo.I10_Amcare_VR.IsAbstractValidatedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLevel1, dbo.I10_Amcare_VR.IsAbstractValidatedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLite, dbo.I10_Amcare_VR.IsAbstractValidatedLiteDesc, dbo.I10_Amcare_VR.IsBirthdateEstimated, dbo.I10_Amcare_VR.IsBirthdateEstimatedDesc, 
						 dbo.I10_Amcare_VR.IsCustomValidated, dbo.I10_Amcare_VR.IsCustomValidatedDesc,
                         dbo.I10_Amcare_VR.LOSDays, dbo.I10_Amcare_VR.LOSTime, dbo.I10_Amcare_VR.LOSTimeinHours, dbo.I10_Amcare_VR.LOSTotalMinutes, dbo.I10_Amcare_VR.Language, dbo.I10_Amcare_VR.LanguageDesc, 
                         dbo.I10_Amcare_VR.LastName, dbo.I10_Amcare_VR.LessTwoPO, dbo.I10_Amcare_VR.LivingArrangement, dbo.I10_Amcare_VR.LivingArrangementDesc, dbo.I10_Amcare_VR.LocationofInjury, 
                         dbo.I10_Amcare_VR.LocationofInjuryDesc, dbo.I10_Amcare_VR.MISCode, dbo.I10_Amcare_VR.MISCodeDesc, dbo.I10_Amcare_VR.MaidenName, dbo.I10_Amcare_VR.MaritalStatus, 
                         dbo.I10_Amcare_VR.MaritalStatusDesc, 
                         dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoED, 
						 dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04Desc, 

						 dbo.I10_Amcare_VR.MethodofAdmission, dbo.I10_Amcare_VR.MethodofAdmissionDesc, dbo.I10_Amcare_VR.MiddleName, 
                         dbo.I10_Amcare_VR.NACRSClinicLiteSubmission, dbo.I10_Amcare_VR.NACRSClinicLiteSubmissionDesc, 
                         dbo.I10_Amcare_VR.NewbornChart, 
                         dbo.I10_Amcare_VR.NewbornDischDate, dbo.I10_Amcare_VR.NextScheduledVisitDate, dbo.I10_Amcare_VR.NextScheduledVisitTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentDate, 
                         dbo.I10_Amcare_VR.NonPhysicianAssessmentTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknown, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.NonPhysicianNumber, dbo.I10_Amcare_VR.NonPhysicianNumberDesc, dbo.I10_Amcare_VR.NonPhysicianService, dbo.I10_Amcare_VR.NonPhysicianServiceDesc, 
                         dbo.I10_Amcare_VR.NumberofECT, dbo.I10_Amcare_VR.NursingAssessmentDate, dbo.I10_Amcare_VR.NursingAssessmentTime, dbo.I10_Amcare_VR.Occupation, dbo.I10_Amcare_VR.OccupationDesc, 
                         dbo.I10_Amcare_VR.OtherMedicalDeath, dbo.I10_Amcare_VR.OtherMedicalDeathDesc, dbo.I10_Amcare_VR.OtherBlood, dbo.I10_Amcare_VR.OtherBloodDesc, dbo.I10_Amcare_VR.OtherBloodCrossMatched, 
                         dbo.I10_Amcare_VR.OtherBloodCrossMatchedDesc, dbo.I10_Amcare_VR.OtherBloodTyped, dbo.I10_Amcare_VR.OtherBloodTypedDesc, dbo.I10_Amcare_VR.OtherBloodUnits, dbo.I10_Amcare_VR.PCTASIndicator, 
                         dbo.I10_Amcare_VR.PCTASIndicatorDesc, dbo.I10_Amcare_VR.PhysicianEstLOS, dbo.I10_Amcare_VR.Plasma, dbo.I10_Amcare_VR.PlasmaDesc, dbo.I10_Amcare_VR.PlasmaCrossMatched, 
                         dbo.I10_Amcare_VR.PlasmaCrossMatchedDesc, dbo.I10_Amcare_VR.PlasmaTyped, dbo.I10_Amcare_VR.PlasmaTypedDesc, dbo.I10_Amcare_VR.PlasmaUnits, dbo.I10_Amcare_VR.Platelets, 
                         dbo.I10_Amcare_VR.PlateletsDesc, dbo.I10_Amcare_VR.PlateletsCrossMatched, dbo.I10_Amcare_VR.PlateletsCrossMatchedDesc, dbo.I10_Amcare_VR.PlateletsTyped, dbo.I10_Amcare_VR.PlateletsTypedDesc, 
                         dbo.I10_Amcare_VR.PlateletsUnits, dbo.I10_Amcare_VR.PostalCode, dbo.I10_Amcare_VR.PostalCodeDesc, dbo.I10_Amcare_VR.PostOpDays, dbo.I10_Amcare_VR.PreOpDays, 
                         dbo.I10_Amcare_VR.PreamditWorkUp, dbo.I10_Amcare_VR.PreamditWorkUpDesc, dbo.I10_Amcare_VR.Pregnancy, dbo.I10_Amcare_VR.PregnancyDesc, dbo.I10_Amcare_VR.PrevLiveBirth, 
                         dbo.I10_Amcare_VR.PreviousPsychiartricAdmissions, dbo.I10_Amcare_VR.PreviousPsychiartricAdmDesc, dbo.I10_Amcare_VR.Program, dbo.I10_Amcare_VR.ProgramDesc, dbo.I10_Amcare_VR.ProvinceNumber, 
                         dbo.I10_Amcare_VR.ProvinceNumberDesc, dbo.I10_Amcare_VR.ReasonForVisit, dbo.I10_Amcare_VR.ReasonForVisitDesc, dbo.I10_Amcare_VR.ReAdmitCode, dbo.I10_Amcare_VR.ReciprocalBillingStatus, 
                         dbo.I10_Amcare_VR.ReciprocalBillingStatusDesc, dbo.I10_Amcare_VR.RedBloodCell, dbo.I10_Amcare_VR.RedBloodCellDesc, dbo.I10_Amcare_VR.RedBloodCellCrossMatched, 
                         dbo.I10_Amcare_VR.RedBloodCellCrossMatchedDesc, dbo.I10_Amcare_VR.RedBloodCellTyped, dbo.I10_Amcare_VR.RedBloodCellTypedDesc, dbo.I10_Amcare_VR.RedBloodCellUnits, 
                         dbo.I10_Amcare_VR.ReferralDate, dbo.I10_Amcare_VR.ReferredFrom, dbo.I10_Amcare_VR.ReferredFromDesc, dbo.I10_Amcare_VR.ReferredTo, dbo.I10_Amcare_VR.ReferredToDesc, 
                         dbo.I10_Amcare_VR.ReferringProvider, dbo.I10_Amcare_VR.ReferringProviderDesc, dbo.I10_Amcare_VR.RegisterNumber, dbo.I10_Amcare_VR.RegistrationNumber, 
                         dbo.I10_Amcare_VR.RegistrationSequenceNumber, dbo.I10_Amcare_VR.RegistrationVisitDate, dbo.I10_Amcare_VR.RegistrationVisitTime, dbo.I10_Amcare_VR.ReproductiveCareComments, 
                         dbo.I10_Amcare_VR.ReserveField, dbo.I10_Amcare_VR.ResidenceCode, dbo.I10_Amcare_VR.ResidenceCodeDesc, dbo.I10_Amcare_VR.ResidenceProvince, dbo.I10_Amcare_VR.ResidenceProvinceDesc, 
                         dbo.I10_Amcare_VR.ResidenceRegion, dbo.I10_Amcare_VR.ResidenceRegionDesc, dbo.I10_Amcare_VR.ResidenceType, dbo.I10_Amcare_VR.ResidenceTypeDesc, dbo.I10_Amcare_VR.ResponsiblityForPayment,
                          dbo.I10_Amcare_VR.ResponsiblityForPaymentDesc, dbo.I10_Amcare_VR.SchedEDVisit, dbo.I10_Amcare_VR.SchedEDVisitDesc, dbo.I10_Amcare_VR.SeatbeltIndicator, dbo.I10_Amcare_VR.SeatbeltIndicatorDesc, 
                         dbo.I10_Amcare_VR.SecondChartRegisterNumber, dbo.I10_Amcare_VR.SecretVIPPatient, dbo.I10_Amcare_VR.SecretVIPPatientDesc, dbo.I10_Amcare_VR.SiteNumber, dbo.I10_Amcare_VR.SiteNumberDesc, 
                         dbo.I10_Amcare_VR.SocialService, dbo.I10_Amcare_VR.SocialServiceDesc, dbo.I10_Amcare_VR.SourceofReferral, dbo.I10_Amcare_VR.SourceofReferralDesc, dbo.I10_Amcare_VR.SpecialistNumber, 
                         dbo.I10_Amcare_VR.SpecialistNumberDesc, dbo.I10_Amcare_VR.SpecialistRequestDate, dbo.I10_Amcare_VR.SpecialistRequestService, dbo.I10_Amcare_VR.SpecialistRequestServiceDesc, 
                         dbo.I10_Amcare_VR.SpecialistRequestTime, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknown, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknownDesc, dbo.I10_Amcare_VR.StakeholderType, 
                         dbo.I10_Amcare_VR.StakeholderTypeDesc, dbo.I10_Amcare_VR.StatusAfterTriage, dbo.I10_Amcare_VR.StatusAfterTriageDesc, dbo.I10_Amcare_VR.Sterilization, dbo.I10_Amcare_VR.SterilizationDesc, 
                         dbo.I10_Amcare_VR.SubmissionLevelCode, dbo.I10_Amcare_VR.SubmissionRecordID, dbo.I10_Amcare_VR.SubsequentOR, dbo.I10_Amcare_VR.SubsequentORDesc, dbo.I10_Amcare_VR.Suicide, 
                         dbo.I10_Amcare_VR.SuicideDesc, dbo.I10_Amcare_VR.SurgicalCase, dbo.I10_Amcare_VR.SurgicalCaseDesc, dbo.I10_Amcare_VR.TimeLeftER, dbo.I10_Amcare_VR.TimeLeftERUnknown, 
                         dbo.I10_Amcare_VR.TimeLeftERUnknownDEsc, dbo.I10_Amcare_VR.TransferOverloadDate, dbo.I10_Amcare_VR.TransferOverloadTime, dbo.I10_Amcare_VR.TransferOverloadTimeDifference, 
                         dbo.I10_Amcare_VR.TransfusionGiven, dbo.I10_Amcare_VR.TransfusionGivenDesc, dbo.I10_Amcare_VR.Trauma, dbo.I10_Amcare_VR.TraumaDesc, dbo.I10_Amcare_VR.TriageDate, 
                         dbo.I10_Amcare_VR.TriageLevel, dbo.I10_Amcare_VR.TriageLevelDesc, dbo.I10_Amcare_VR.TriageTime, dbo.I10_Amcare_VR.TriageTimeUnknown, dbo.I10_Amcare_VR.TriageTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.TSICoder, dbo.I10_Amcare_VR.TSICoderDesc, dbo.I10_Amcare_VR.TSIDate, dbo.I10_Amcare_VR.TSITime, dbo.I10_Amcare_VR.TwoTenPO, dbo.I10_Amcare_VR.ULI, 
                         dbo.I10_Amcare_VR.UniversalEpisodeIdentifier, dbo.I10_Amcare_VR.UnplannedReadmit, dbo.I10_Amcare_VR.VisitStatus, dbo.I10_Amcare_VR.VisitStatusDesc, dbo.I10_Amcare_VR.VisitType, dbo.I10_Amcare_VR.VisitTypeDesc, 
                         dbo.I10_Amcare_VR.WaitTimeinER, dbo.I10_Amcare_VR.WaittoAssessmentinMinutes, dbo.I10_Amcare_VR.WaittoNursingAssessmentDiff, dbo.I10_Amcare_VR.Weight, dbo.I10_Amcare_VR.zzAbstractLink, 
                         dbo.I10_Amcare_VR.zzRegionalPatientID, dbo.I10_Amcare_VR.zzVolumeLink, dbo.I10_Amcare_DischargeDiagnosis.DischargeDiagnosisOccurrence, dbo.I10_Amcare_DischargeDiagnosis.DischargeDiagnosis, 
                         dbo.I10_Amcare_DischargeDiagnosis.DischargeDiagnosisDesc
FROM            dbo.I10_Amcare_VR LEFT OUTER JOIN
                         dbo.I10_Amcare_DischargeDiagnosis ON dbo.I10_Amcare_VR.zzAbstractLink = dbo.I10_Amcare_DischargeDiagnosis.zzAbstractLink



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_EDInterventionPicklist_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE view [dbo].[I10_Amcare_And_EDInterventionPicklist_VR]
as
select I10_Amcare_VR.*,
	I10_Amcare_EDInterventionPicklist_VR.EDIntervnetionPickList,
	I10_Amcare_EDInterventionPicklist_VR.EDIntervnetionPickListDesc,
	I10_Amcare_EDInterventionPicklist_VR.EDIntervnetionPickListOccurrence
from I10_Amcare_VR
	left join I10_Amcare_EDInterventionPicklist_VR on I10_Amcare_VR.zzAbstractLink = I10_Amcare_EDInterventionPicklist_VR.zzAbstractLink



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_EDInvestigativeTechnology_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE view [dbo].[I10_Amcare_And_EDInvestigativeTechnology_VR]
as
select I10_Amcare_VR.*,
	I10_Amcare_EDInvestigativeTechnology_VR.EDInvestigativeTechnology,
	I10_Amcare_EDInvestigativeTechnology_VR.EDInvestigativeTechnologyDesc,
	I10_Amcare_EDInvestigativeTechnology_VR.EDInvestigativeTechnologyOccurrence,
	I10_Amcare_EDInvestigativeTechnology_VR.NumberEDInvestigativeTechnologyPerformed
from I10_Amcare_VR
	left join I10_Amcare_EDInvestigativeTechnology_VR on I10_Amcare_VR.zzAbstractLink = I10_Amcare_EDInvestigativeTechnology_VR.zzAbstractLink



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Intervention_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_Amcare_And_Intervention_VR]
AS
SELECT        dbo.I10_Amcare_VR.[#ofPreviousPreTermDeliveries], dbo.I10_Amcare_VR.[#ofPrevSpontaneousAbortions], dbo.I10_Amcare_VR.[#ofPreviousTermDeliveries], dbo.I10_Amcare_VR.AccessPrimaryHealthCareCode, 
                         dbo.I10_Amcare_VR.AccessPrimaryHealthCareCodeDesc, dbo.I10_Amcare_VR.AmbulanceArrivalDate, dbo.I10_Amcare_VR.AmbulanceArrivalTime, dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknown, 
                         dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknownDesc, dbo.I10_Amcare_VR.AmbulanceTransferCareDate, dbo.I10_Amcare_VR.AmbulanceTransferCareTime, 
                         dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknown, dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknownDesc, dbo.I10_Amcare_VR.[#ofPrevTherapeuticAbortions], dbo.I10_Amcare_VR.AWOL, 
                         dbo.I10_Amcare_VR.AWOLDesc, dbo.I10_Amcare_VR.AbortDate, dbo.I10_Amcare_VR.AbstractNumber, dbo.I10_Amcare_VR.AbstractOverflow, dbo.I10_Amcare_VR.AbstractOverflowDesc, 
                         dbo.I10_Amcare_VR.ActivityDescription, dbo.I10_Amcare_VR.ActivityWhenInjured, dbo.I10_Amcare_VR.ActivityWhenInjuredDesc, dbo.I10_Amcare_VR.ActueLOS, dbo.I10_Amcare_VR.AdmitbyAmbulance, 
                         dbo.I10_Amcare_VR.AdmitbyAmbulanceDesc, dbo.I10_Amcare_VR.AdmitCategory, dbo.I10_Amcare_VR.AdmitDiagnosis, dbo.I10_Amcare_VR.AdmitNursingArea, dbo.I10_Amcare_VR.AdmitNursingAreaDesc, 
                         dbo.I10_Amcare_VR.AfterAdmit, dbo.I10_Amcare_VR.AgeCode, dbo.I10_Amcare_VR.AgeCodeDesc, dbo.I10_Amcare_VR.AgeGroup, dbo.I10_Amcare_VR.AgeNumber, dbo.I10_Amcare_VR.Albumin, 
                         dbo.I10_Amcare_VR.AlbuminDesc, dbo.I10_Amcare_VR.AlbuminCrossMatched, dbo.I10_Amcare_VR.AlbuminCrossMatchedDesc, dbo.I10_Amcare_VR.AlbuminTyped, dbo.I10_Amcare_VR.AlbuminTypedDesc, 
                         dbo.I10_Amcare_VR.AlbuminUnits, dbo.I10_Amcare_VR.ALCLOS, dbo.I10_Amcare_VR.AmbulanceReportNumber, dbo.I10_Amcare_VR.AmCareGroup, dbo.I10_Amcare_VR.AmCareGroupDesc, 
                         dbo.I10_Amcare_VR.AmcareCareType, dbo.I10_Amcare_VR.AmcareCareTypeDesc, dbo.I10_Amcare_VR.AmcareTypeCode, dbo.I10_Amcare_VR.AmcareTypeCodeDesc, dbo.I10_Amcare_VR.Ancil13, 
                         dbo.I10_Amcare_VR.Ancil14, dbo.I10_Amcare_VR.Ancil15, dbo.I10_Amcare_VR.Ancil16, dbo.I10_Amcare_VR.Ancil17, dbo.I10_Amcare_VR.AncillaryField1, dbo.I10_Amcare_VR.AncillaryField1Desc, 
                         dbo.I10_Amcare_VR.AncillaryField10, dbo.I10_Amcare_VR.AncillaryField10Desc, dbo.I10_Amcare_VR.AncillaryField11, dbo.I10_Amcare_VR.AncillaryField11Desc, dbo.I10_Amcare_VR.AncillaryField12, 
                         dbo.I10_Amcare_VR.AncillaryField12Desc, dbo.I10_Amcare_VR.AncillaryField2, dbo.I10_Amcare_VR.AncillaryField2Desc, dbo.I10_Amcare_VR.AncillaryField3, dbo.I10_Amcare_VR.AncillaryField3Desc, 
                         dbo.I10_Amcare_VR.AncillaryField4, dbo.I10_Amcare_VR.AncillaryField4Desc, dbo.I10_Amcare_VR.AncillaryField5, dbo.I10_Amcare_VR.AncillaryField5Desc, dbo.I10_Amcare_VR.AncillaryField6, 
                         dbo.I10_Amcare_VR.AncillaryField6Desc, dbo.I10_Amcare_VR.AncillaryField7, dbo.I10_Amcare_VR.AncillaryField7Desc, dbo.I10_Amcare_VR.AncillaryField8, dbo.I10_Amcare_VR.AncillaryField8Desc, 
                         dbo.I10_Amcare_VR.AncillaryField9, dbo.I10_Amcare_VR.AncillaryField9Desc, dbo.I10_Amcare_VR.ArrivalDate, dbo.I10_Amcare_VR.ArrivalMode, dbo.I10_Amcare_VR.ArrivalModeDesc, 
                         dbo.I10_Amcare_VR.ArrivalTime, dbo.I10_Amcare_VR.ArrivaltoTriageTime, dbo.I10_Amcare_VR.AssessmentDate, dbo.I10_Amcare_VR.AssessmentTime, dbo.I10_Amcare_VR.AssessmentTimeUnknown, 
                         dbo.I10_Amcare_VR.AssessmentTimeUnknownDesc, dbo.I10_Amcare_VR.AttendingPhysician, dbo.I10_Amcare_VR.AttendingPhysicianDesc, dbo.I10_Amcare_VR.AutoTransfusion, 
                         dbo.I10_Amcare_VR.AutoTransfusionDesc, dbo.I10_Amcare_VR.AutopsyPerformed, dbo.I10_Amcare_VR.AutopsyPerformedDesc, dbo.I10_Amcare_VR.BasicOption1, dbo.I10_Amcare_VR.BasicOption1Desc, 
                         dbo.I10_Amcare_VR.BasicOption10, dbo.I10_Amcare_VR.BasicOption10Desc, dbo.I10_Amcare_VR.BasicOption11, dbo.I10_Amcare_VR.BasicOption11Desc, dbo.I10_Amcare_VR.BasicOption12, 
                         dbo.I10_Amcare_VR.BasicOption12Desc, dbo.I10_Amcare_VR.BasicOption13, dbo.I10_Amcare_VR.BasicOption13Desc, dbo.I10_Amcare_VR.BasicOption14, dbo.I10_Amcare_VR.BasicOption14Desc, 
                         dbo.I10_Amcare_VR.BasicOption15, dbo.I10_Amcare_VR.BasicOption15Desc, dbo.I10_Amcare_VR.BasicOption16, dbo.I10_Amcare_VR.BasicOption16Desc, dbo.I10_Amcare_VR.BasicOption17, 
                         dbo.I10_Amcare_VR.BasicOption17Desc, dbo.I10_Amcare_VR.BasicOption18, dbo.I10_Amcare_VR.BasicOption18Desc, dbo.I10_Amcare_VR.BasicOption19, dbo.I10_Amcare_VR.BasicOption19Desc, 
                         dbo.I10_Amcare_VR.BasicOption2, dbo.I10_Amcare_VR.BasicOption2Desc, dbo.I10_Amcare_VR.BasicOption3, dbo.I10_Amcare_VR.BasicOption3Desc, dbo.I10_Amcare_VR.BasicOption4, 
                         dbo.I10_Amcare_VR.BasicOption4Desc, dbo.I10_Amcare_VR.BasicOption5, dbo.I10_Amcare_VR.BasicOption5Desc, dbo.I10_Amcare_VR.BasicOption6, dbo.I10_Amcare_VR.BasicOption6Desc, 
                         dbo.I10_Amcare_VR.BasicOption7, dbo.I10_Amcare_VR.BasicOption7Desc, dbo.I10_Amcare_VR.BasicOption8, dbo.I10_Amcare_VR.BasicOption8Desc, dbo.I10_Amcare_VR.BasicOption9, 
                         dbo.I10_Amcare_VR.BasicOption9Desc, dbo.I10_Amcare_VR.BatchNumber, dbo.I10_Amcare_VR.BatchPeriod, dbo.I10_Amcare_VR.BatchPeriodDesc, dbo.I10_Amcare_VR.BatchPeriod_BC, 
                         dbo.I10_Amcare_VR.BatchYear, dbo.I10_Amcare_VR.BirthDate, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIII, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIIIDesc, 
						 dbo.I10_Amcare_VR.Blood_C1Inhibitor, 
                         dbo.I10_Amcare_VR.Blood_C1InhibitorDesc, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasma, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_CryosupernatantPlasma, 
                         dbo.I10_Amcare_VR.Blood_CryosupernatantPlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_FEIBA, 
						 dbo.I10_Amcare_VR.Blood_FEIBADesc, 
						 dbo.I10_Amcare_VR.Blood_Fibrinogen, 
						 dbo.I10_Amcare_VR.Blood_FibrinogenDesc, 
                         dbo.I10_Amcare_VR.Blood_IVIG_SCIG, 
						 dbo.I10_Amcare_VR.Blood_IVIG_SCIGDesc, 
						 dbo.I10_Amcare_VR.Blood_PCC, 
						 dbo.I10_Amcare_VR.Blood_PCCDesc, 
						 dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactors, 
                         dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactorsDesc,						 
						 dbo.I10_Amcare_VR.BreastFeeding, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlag, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlagDesc, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitDateIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknown, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknownDesc, dbo.I10_Amcare_VR.ClinicalDecisionUnitDateOut, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOut, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknown, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknownDesc, dbo.I10_Amcare_VR.ChangeinLegalStatus, 
                         dbo.I10_Amcare_VR.ChangeinLegalStatusDesc, dbo.I10_Amcare_VR.ChartNumber, dbo.I10_Amcare_VR.ChiefComplaint, dbo.I10_Amcare_VR.CoderNumber, dbo.I10_Amcare_VR.CoderNumberDesc, 
                         dbo.I10_Amcare_VR.CompleteRecord, dbo.I10_Amcare_VR.CompleteRecordDesc, dbo.I10_Amcare_VR.Complication, dbo.I10_Amcare_VR.ComplicationDesc, dbo.I10_Amcare_VR.Complication1, 
                         dbo.I10_Amcare_VR.Complication1Desc, dbo.I10_Amcare_VR.Complication2, dbo.I10_Amcare_VR.Complication2Desc, dbo.I10_Amcare_VR.Complication3, dbo.I10_Amcare_VR.Complication3Desc, 
                         dbo.I10_Amcare_VR.ContactMode, dbo.I10_Amcare_VR.ContactModeDesc, dbo.I10_Amcare_VR.CoronerCase, dbo.I10_Amcare_VR.CoronerCaseDesc, dbo.I10_Amcare_VR.DataEntryCoder, 
                         dbo.I10_Amcare_VR.DataEntryCoderDesc, dbo.I10_Amcare_VR.DateLeftER, dbo.I10_Amcare_VR.DateofLastMenses, dbo.I10_Amcare_VR.DateReadyforDisch, dbo.I10_Amcare_VR.DateSentToCIHI, 
                         dbo.I10_Amcare_VR.DateSentToCIHILevel1, dbo.I10_Amcare_VR.DateSentToCIHILevel2, dbo.I10_Amcare_VR.DateSentToCIHILite, dbo.I10_Amcare_VR.DeathInER, dbo.I10_Amcare_VR.DeathInERDesc, 
                         dbo.I10_Amcare_VR.DeathOnArrival, dbo.I10_Amcare_VR.DeathOnArrivalDesc, dbo.I10_Amcare_VR.DecisionAdmitDifference, dbo.I10_Amcare_VR.DecisiontoAdmitDate, dbo.I10_Amcare_VR.DecisiontoAdmitTime, 
                         dbo.I10_Amcare_VR.DecisionAdmitTimeUnknown, dbo.I10_Amcare_VR.DecisionAdmitTimeUnknownDesc, dbo.I10_Amcare_VR.DeliveryDate, dbo.I10_Amcare_VR.DeliveryTime, 
                         dbo.I10_Amcare_VR.DiedDuringIntervention, dbo.I10_Amcare_VR.DiedDuringInterventionDesc, dbo.I10_Amcare_VR.DischNursingArea, dbo.I10_Amcare_VR.DischNursingAreaDesc, 
                         dbo.I10_Amcare_VR.DischPlanning, dbo.I10_Amcare_VR.DischPlanningDesc, dbo.I10_Amcare_VR.DischargeAge, dbo.I10_Amcare_VR.DischargeDisposition, dbo.I10_Amcare_VR.DischargeDispositionDesc, 
                         dbo.I10_Amcare_VR.DispositionDate, dbo.I10_Amcare_VR.DispositionTime, dbo.I10_Amcare_VR.DispositionTimeUnknown, dbo.I10_Amcare_VR.DispositionTimeUnknownDesc, dbo.I10_Amcare_VR.ECTTreatment, 
                         dbo.I10_Amcare_VR.ECTTreatmentDesc, dbo.I10_Amcare_VR.Education, dbo.I10_Amcare_VR.EducationDesc, dbo.I10_Amcare_VR.EDVisitIndicator, dbo.I10_Amcare_VR.EDVisitIndicatorDesc, 
                         dbo.I10_Amcare_VR.Employment, dbo.I10_Amcare_VR.EmploymentDesc, dbo.I10_Amcare_VR.EntryCode, dbo.I10_Amcare_VR.EstimateDischDate, dbo.I10_Amcare_VR.ExitCode, 
                         dbo.I10_Amcare_VR.FamilyPhysicianFlag, dbo.I10_Amcare_VR.FamilyPhysicianFlagDesc, dbo.I10_Amcare_VR.FinancialSupport, dbo.I10_Amcare_VR.FinancialSupportDesc, dbo.I10_Amcare_VR.FinishDate, 
                         dbo.I10_Amcare_VR.FinishTime, dbo.I10_Amcare_VR.FirstName, dbo.I10_Amcare_VR.FullName, dbo.I10_Amcare_VR.FixedChartNumber, dbo.I10_Amcare_VR.Gender, dbo.I10_Amcare_VR.GenderDesc, 
                         dbo.I10_Amcare_VR.GestationalAgeinweeks, dbo.I10_Amcare_VR.GlasgowScale, dbo.I10_Amcare_VR.GlasgowScaleDesc, dbo.I10_Amcare_VR.GreaterTenPO, dbo.I10_Amcare_VR.HCNProvince, 
                         dbo.I10_Amcare_VR.HCNProvinceDesc, dbo.I10_Amcare_VR.HCNVersion, dbo.I10_Amcare_VR.HealthCareNumber, dbo.I10_Amcare_VR.Hospital, dbo.I10_Amcare_VR.HospitalDesc, 
                         dbo.I10_Amcare_VR.HospitalAccountRecord,
                         dbo.I10_Amcare_VR.HelmetIndicator, dbo.I10_Amcare_VR.HelmetIndicatorDesc, dbo.I10_Amcare_VR.InSCU, dbo.I10_Amcare_VR.InitialOR, dbo.I10_Amcare_VR.InitialORDesc, dbo.I10_Amcare_VR.InjuryDate, 
                         dbo.I10_Amcare_VR.Injury, dbo.I10_Amcare_VR.InjuryDesc, dbo.I10_Amcare_VR.InputDate, dbo.I10_Amcare_VR.InputTime, 

						 dbo.I10_Amcare_VR.InstitutionFrom, dbo.I10_Amcare_VR.InstitutionFromDesc, 
						 dbo.I10_Amcare_VR.InstitutionFromType, dbo.I10_Amcare_VR.InstitutionFromTypeDesc,
                         dbo.I10_Amcare_VR.InstFromCareType, dbo.I10_Amcare_VR.InstFromHospType, 
						 dbo.I10_Amcare_VR.InstitutionNumber, dbo.I10_Amcare_VR.InstitutionNumberDesc, 
						 dbo.I10_Amcare_VR.InstitutionTo, dbo.I10_Amcare_VR.InstitutionToDesc, 
						 dbo.I10_Amcare_VR.InstToCareType, dbo.I10_Amcare_VR.InstToHospType, 
						 dbo.I10_Amcare_VR.InstitutionToType, dbo.I10_Amcare_VR.InstitutionToTypeDesc, 
						 
						 dbo.I10_Amcare_VR.InterfaceDate, dbo.I10_Amcare_VR.InterfaceTime, 
                         dbo.I10_Amcare_VR.IsAbstractCompleted, dbo.I10_Amcare_VR.IsAbstractCompletedDesc, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCompletedLevel2, dbo.I10_Amcare_VR.IsAbstractCompletedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCompletedLite, dbo.I10_Amcare_VR.IsAbstractCompletedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrected, dbo.I10_Amcare_VR.IsAbstractCorrectedDesc, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCorrectedLite, dbo.I10_Amcare_VR.IsAbstractCorrectedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractDeleted, dbo.I10_Amcare_VR.IsAbstractDeletedDesc, dbo.I10_Amcare_VR.IsAbstractSubmitted, dbo.I10_Amcare_VR.IsAbstractSubmittedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLite, dbo.I10_Amcare_VR.IsAbstractSubmittedLiteDesc, dbo.I10_Amcare_VR.IsAbstractValidated, dbo.I10_Amcare_VR.IsAbstractValidatedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLevel1, dbo.I10_Amcare_VR.IsAbstractValidatedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLite, dbo.I10_Amcare_VR.IsAbstractValidatedLiteDesc, dbo.I10_Amcare_VR.IsBirthdateEstimated, dbo.I10_Amcare_VR.IsBirthdateEstimatedDesc, 
                         dbo.I10_Amcare_VR.IsCustomValidated, dbo.I10_Amcare_VR.IsCustomValidatedDesc, dbo.I10_Amcare_VR.LOSDays, dbo.I10_Amcare_VR.LOSTime, dbo.I10_Amcare_VR.LOSTimeinHours, 
                         dbo.I10_Amcare_VR.LOSTotalMinutes, dbo.I10_Amcare_VR.Language, dbo.I10_Amcare_VR.LanguageDesc, dbo.I10_Amcare_VR.LastName, dbo.I10_Amcare_VR.LessTwoPO, 
                         dbo.I10_Amcare_VR.LivingArrangement, dbo.I10_Amcare_VR.LivingArrangementDesc, dbo.I10_Amcare_VR.LocationofInjury, dbo.I10_Amcare_VR.LocationofInjuryDesc, dbo.I10_Amcare_VR.MISCode, 
                         dbo.I10_Amcare_VR.MISCodeDesc, dbo.I10_Amcare_VR.MaidenName, dbo.I10_Amcare_VR.MaritalStatus, dbo.I10_Amcare_VR.MaritalStatusDesc, 
                         dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoED, 
						 dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04Desc, 
						 
						 dbo.I10_Amcare_VR.MethodofAdmission, 
                         dbo.I10_Amcare_VR.MethodofAdmissionDesc, dbo.I10_Amcare_VR.MiddleName, 
                         dbo.I10_Amcare_VR.NACRSClinicLiteSubmission, dbo.I10_Amcare_VR.NACRSClinicLiteSubmissionDesc, 
                         dbo.I10_Amcare_VR.NewbornChart, dbo.I10_Amcare_VR.NewbornDischDate, dbo.I10_Amcare_VR.NextScheduledVisitDate, 
                         dbo.I10_Amcare_VR.NextScheduledVisitTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentDate, dbo.I10_Amcare_VR.NonPhysicianAssessmentTime, 
                         dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknown, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknownDesc, dbo.I10_Amcare_VR.NonPhysicianNumber, 
                         dbo.I10_Amcare_VR.NonPhysicianNumberDesc, dbo.I10_Amcare_VR.NonPhysicianService, dbo.I10_Amcare_VR.NonPhysicianServiceDesc, dbo.I10_Amcare_VR.NumberofECT, 
                         dbo.I10_Amcare_VR.NursingAssessmentDate, dbo.I10_Amcare_VR.NursingAssessmentTime, dbo.I10_Amcare_VR.Occupation, dbo.I10_Amcare_VR.OccupationDesc, dbo.I10_Amcare_VR.OtherMedicalDeath, 
                         dbo.I10_Amcare_VR.OtherMedicalDeathDesc, dbo.I10_Amcare_VR.OtherBlood, dbo.I10_Amcare_VR.OtherBloodDesc, dbo.I10_Amcare_VR.OtherBloodCrossMatched, 
                         dbo.I10_Amcare_VR.OtherBloodCrossMatchedDesc, dbo.I10_Amcare_VR.OtherBloodTyped, dbo.I10_Amcare_VR.OtherBloodTypedDesc, dbo.I10_Amcare_VR.OtherBloodUnits, dbo.I10_Amcare_VR.PCTASIndicator, 
                         dbo.I10_Amcare_VR.PCTASIndicatorDesc, dbo.I10_Amcare_VR.PhysicianEstLOS, dbo.I10_Amcare_VR.Plasma, dbo.I10_Amcare_VR.PlasmaDesc, dbo.I10_Amcare_VR.PlasmaCrossMatched, 
                         dbo.I10_Amcare_VR.PlasmaCrossMatchedDesc, dbo.I10_Amcare_VR.PlasmaTyped, dbo.I10_Amcare_VR.PlasmaTypedDesc, dbo.I10_Amcare_VR.PlasmaUnits, dbo.I10_Amcare_VR.Platelets, 
                         dbo.I10_Amcare_VR.PlateletsDesc, dbo.I10_Amcare_VR.PlateletsCrossMatched, dbo.I10_Amcare_VR.PlateletsCrossMatchedDesc, dbo.I10_Amcare_VR.PlateletsTyped, dbo.I10_Amcare_VR.PlateletsTypedDesc, 
                         dbo.I10_Amcare_VR.PlateletsUnits, dbo.I10_Amcare_VR.PostalCode, dbo.I10_Amcare_VR.PostalCodeDesc, dbo.I10_Amcare_VR.PostOpDays, dbo.I10_Amcare_VR.PreOpDays, 
                         dbo.I10_Amcare_VR.PreamditWorkUp, dbo.I10_Amcare_VR.PreamditWorkUpDesc, dbo.I10_Amcare_VR.Pregnancy, dbo.I10_Amcare_VR.PregnancyDesc, dbo.I10_Amcare_VR.PrevLiveBirth, 
                         dbo.I10_Amcare_VR.PreviousPsychiartricAdmissions, dbo.I10_Amcare_VR.PreviousPsychiartricAdmDesc, dbo.I10_Amcare_VR.Program, dbo.I10_Amcare_VR.ProgramDesc, dbo.I10_Amcare_VR.ProvinceNumber, 
                         dbo.I10_Amcare_VR.ProvinceNumberDesc, dbo.I10_Amcare_VR.ReasonForVisit, dbo.I10_Amcare_VR.ReasonForVisitDesc, dbo.I10_Amcare_VR.ReAdmitCode, dbo.I10_Amcare_VR.ReciprocalBillingStatus, 
                         dbo.I10_Amcare_VR.ReciprocalBillingStatusDesc, dbo.I10_Amcare_VR.RedBloodCell, dbo.I10_Amcare_VR.RedBloodCellDesc, dbo.I10_Amcare_VR.RedBloodCellCrossMatched, 
                         dbo.I10_Amcare_VR.RedBloodCellCrossMatchedDesc, dbo.I10_Amcare_VR.RedBloodCellTyped, dbo.I10_Amcare_VR.RedBloodCellTypedDesc, dbo.I10_Amcare_VR.RedBloodCellUnits, 
                         dbo.I10_Amcare_VR.ReferralDate, dbo.I10_Amcare_VR.ReferredFrom, dbo.I10_Amcare_VR.ReferredFromDesc, dbo.I10_Amcare_VR.ReferredTo, dbo.I10_Amcare_VR.ReferredToDesc, 
                         dbo.I10_Amcare_VR.ReferringProvider, dbo.I10_Amcare_VR.ReferringProviderDesc, dbo.I10_Amcare_VR.RegisterNumber, dbo.I10_Amcare_VR.RegistrationNumber, 
                         dbo.I10_Amcare_VR.RegistrationSequenceNumber, dbo.I10_Amcare_VR.RegistrationVisitDate, dbo.I10_Amcare_VR.RegistrationVisitTime, dbo.I10_Amcare_VR.ReproductiveCareComments, 
                         dbo.I10_Amcare_VR.ReserveField, dbo.I10_Amcare_VR.ResidenceCode, dbo.I10_Amcare_VR.ResidenceCodeDesc, dbo.I10_Amcare_VR.ResidenceProvince, dbo.I10_Amcare_VR.ResidenceProvinceDesc, 
                         dbo.I10_Amcare_VR.ResidenceRegion, dbo.I10_Amcare_VR.ResidenceRegionDesc, dbo.I10_Amcare_VR.ResidenceType, dbo.I10_Amcare_VR.ResidenceTypeDesc, dbo.I10_Amcare_VR.ResponsiblityForPayment,
                          dbo.I10_Amcare_VR.ResponsiblityForPaymentDesc, dbo.I10_Amcare_VR.SchedEDVisit, dbo.I10_Amcare_VR.SchedEDVisitDesc, dbo.I10_Amcare_VR.SeatbeltIndicator, dbo.I10_Amcare_VR.SeatbeltIndicatorDesc, 
                         dbo.I10_Amcare_VR.SecondChartRegisterNumber, dbo.I10_Amcare_VR.SecretVIPPatient, dbo.I10_Amcare_VR.SecretVIPPatientDesc, dbo.I10_Amcare_VR.SiteNumber, dbo.I10_Amcare_VR.SiteNumberDesc, 
                         dbo.I10_Amcare_VR.SocialService, dbo.I10_Amcare_VR.SocialServiceDesc, dbo.I10_Amcare_VR.SourceofReferral, dbo.I10_Amcare_VR.SourceofReferralDesc, dbo.I10_Amcare_VR.SpecialistNumber, 
                         dbo.I10_Amcare_VR.SpecialistNumberDesc, dbo.I10_Amcare_VR.SpecialistRequestDate, dbo.I10_Amcare_VR.SpecialistRequestService, dbo.I10_Amcare_VR.SpecialistRequestServiceDesc, 
                         dbo.I10_Amcare_VR.SpecialistRequestTime, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknown, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknownDesc, dbo.I10_Amcare_VR.StakeholderType, 
                         dbo.I10_Amcare_VR.StakeholderTypeDesc, dbo.I10_Amcare_VR.StatusAfterTriage, dbo.I10_Amcare_VR.StatusAfterTriageDesc, dbo.I10_Amcare_VR.Sterilization, dbo.I10_Amcare_VR.SterilizationDesc, 
                         dbo.I10_Amcare_VR.SubmissionLevelCode, dbo.I10_Amcare_VR.SubmissionRecordID, dbo.I10_Amcare_VR.SubsequentOR, dbo.I10_Amcare_VR.SubsequentORDesc, dbo.I10_Amcare_VR.Suicide, 
                         dbo.I10_Amcare_VR.SuicideDesc, dbo.I10_Amcare_VR.SurgicalCase, dbo.I10_Amcare_VR.SurgicalCaseDesc, dbo.I10_Amcare_VR.TimeLeftER, dbo.I10_Amcare_VR.TimeLeftERUnknown, 
                         dbo.I10_Amcare_VR.TimeLeftERUnknownDEsc, dbo.I10_Amcare_VR.TransferOverloadDate, dbo.I10_Amcare_VR.TransferOverloadTime, dbo.I10_Amcare_VR.TransferOverloadTimeDifference, 
                         dbo.I10_Amcare_VR.TransfusionGiven, dbo.I10_Amcare_VR.TransfusionGivenDesc, dbo.I10_Amcare_VR.Trauma, dbo.I10_Amcare_VR.TraumaDesc, dbo.I10_Amcare_VR.TriageDate, 
                         dbo.I10_Amcare_VR.TriageLevel, dbo.I10_Amcare_VR.TriageLevelDesc, dbo.I10_Amcare_VR.TriageTime, dbo.I10_Amcare_VR.TriageTimeUnknown, dbo.I10_Amcare_VR.TriageTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.TSICoder, dbo.I10_Amcare_VR.TSICoderDesc, dbo.I10_Amcare_VR.TSIDate, dbo.I10_Amcare_VR.TSITime, dbo.I10_Amcare_VR.TwoTenPO, dbo.I10_Amcare_VR.ULI, 
                         dbo.I10_Amcare_VR.UniversalEpisodeIdentifier, dbo.I10_Amcare_VR.UnplannedReadmit, dbo.I10_Amcare_VR.VisitStatus, dbo.I10_Amcare_VR.VisitStatusDesc, dbo.I10_Amcare_VR.VisitType, dbo.I10_Amcare_VR.VisitTypeDesc, 
                         dbo.I10_Amcare_VR.WaitTimeinER, dbo.I10_Amcare_VR.WaittoAssessmentinMinutes, dbo.I10_Amcare_VR.WaittoNursingAssessmentDiff, dbo.I10_Amcare_VR.Weight, 
                         dbo.I10_Amcare_Interventions_VR.AnestheticTechnique, dbo.I10_Amcare_Interventions_VR.AnestheticTechniqueDesc, 
                         dbo.I10_Amcare_Interventions_VR.AnesthetistID, dbo.I10_Amcare_Interventions_VR.AnesthetistIDDesc, dbo.I10_Amcare_Interventions_VR.EUL, dbo.I10_Amcare_Interventions_VR.EULDesc, 
                         dbo.I10_Amcare_Interventions_VR.Extra, dbo.I10_Amcare_Interventions_VR.ExtraDesc, dbo.I10_Amcare_Interventions_VR.InterventionCIHIValue, dbo.I10_Amcare_Interventions_VR.InterventionCode, 
                         dbo.I10_Amcare_Interventions_VR.InterventionCodeClinicianTitle, dbo.I10_Amcare_Interventions_VR.InterventionCodeDesc, dbo.I10_Amcare_Interventions_VR.InterventionCodeShortDesc, 
                         dbo.I10_Amcare_Interventions_VR.IntervDateIn, dbo.I10_Amcare_Interventions_VR.IntervDateOut, dbo.I10_Amcare_Interventions_VR.InterventionAttributeExtent, 
                         dbo.I10_Amcare_Interventions_VR.IntervAttributeExtentDesc, dbo.I10_Amcare_Interventions_VR.InterventionAttributeLocation, dbo.I10_Amcare_Interventions_VR.IntervAttributeLocationDesc, 
                         dbo.I10_Amcare_Interventions_VR.InterventionAttributeStatus, dbo.I10_Amcare_Interventions_VR.IntervAttributeStatusDesc, 
						  dbo.I10_Amcare_Interventions_VR.InterventionComments,
						 dbo.I10_Amcare_Interventions_VR.InterventionDate, 
                         dbo.I10_Amcare_Interventions_VR.IntervICD9Equivalent, dbo.I10_Amcare_Interventions_VR.IntervICD9cmEquivalent, dbo.I10_Amcare_Interventions_VR.InterventionLocation, 
                         dbo.I10_Amcare_Interventions_VR.InterventionLocationDesc, dbo.I10_Amcare_Interventions_VR.InterventionOccurrence, dbo.I10_Amcare_Interventions_VR.InterventionProviderNumber, 
                         dbo.I10_Amcare_Interventions_VR.InterventionProviderNumberDesc, dbo.I10_Amcare_Interventions_VR.InterventionProviderSpecialty, dbo.I10_Amcare_Interventions_VR.IntervProviderSpecialtyDesc, 
                         dbo.I10_Amcare_Interventions_VR.InterventionSuffix, dbo.I10_Amcare_Interventions_VR.InterventionSuffixDesc, dbo.I10_Amcare_Interventions_VR.InterventionTimeIn, 
                         dbo.I10_Amcare_Interventions_VR.InterventionTimeInUnknown, dbo.I10_Amcare_Interventions_VR.InterventionTimeInUnknownDesc, dbo.I10_Amcare_Interventions_VR.InterventionTimeinMinutes, 
                         dbo.I10_Amcare_Interventions_VR.InterventionTimeOut, dbo.I10_Amcare_Interventions_VR.InterventionTimeOutUnknown, dbo.I10_Amcare_Interventions_VR.InterventionTimeOutUnknownDesc, 
                         dbo.I10_Amcare_Interventions_VR.OOHIndicator, dbo.I10_Amcare_Interventions_VR.OOHIndicatorDesc, dbo.I10_Amcare_Interventions_VR.OOHInstitutionNumber, 
                         dbo.I10_Amcare_Interventions_VR.OOHInstitutionNumberDesc, dbo.I10_Amcare_Interventions_VR.ORTripNumber, dbo.I10_Amcare_Interventions_VR.SurgicalCode, 
                         dbo.I10_Amcare_Interventions_VR.SurgicalCodeDesc, dbo.I10_Amcare_Interventions_VR.TissueCode, dbo.I10_Amcare_Interventions_VR.TissueCodeDesc, 
                         dbo.I10_Amcare_Interventions_VR.UnplannedReturntoOR, dbo.I10_Amcare_Interventions_VR.UnplannedReturntoORDesc,
                         dbo.I10_Amcare_VR.zzAbstractLink, 
                         dbo.I10_Amcare_VR.zzRegionalPatientID, 
                         dbo.I10_Amcare_VR.zzVolumeLink
FROM            dbo.I10_Amcare_Interventions_VR RIGHT OUTER JOIN
                       dbo.I10_Amcare_VR ON dbo.I10_Amcare_Interventions_VR.zzAbstractLink = dbo.I10_Amcare_VR.zzAbstractLink




' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_MIS_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_Amcare_And_MIS_VR]
AS
SELECT        dbo.I10_Amcare_VR.[#ofPreviousPreTermDeliveries], dbo.I10_Amcare_VR.[#ofPrevSpontaneousAbortions], dbo.I10_Amcare_VR.[#ofPreviousTermDeliveries], dbo.I10_Amcare_VR.AccessPrimaryHealthCareCode, 
                         dbo.I10_Amcare_VR.AccessPrimaryHealthCareCodeDesc, dbo.I10_Amcare_VR.AmbulanceArrivalDate, dbo.I10_Amcare_VR.AmbulanceArrivalTime, dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknown, 
                         dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknownDesc, dbo.I10_Amcare_VR.AmbulanceTransferCareDate, dbo.I10_Amcare_VR.AmbulanceTransferCareTime, 
                         dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknown, dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknownDesc, dbo.I10_Amcare_VR.[#ofPrevTherapeuticAbortions], dbo.I10_Amcare_VR.AWOL, 
                         dbo.I10_Amcare_VR.AWOLDesc, dbo.I10_Amcare_VR.AbortDate, dbo.I10_Amcare_VR.AbstractNumber, dbo.I10_Amcare_VR.AbstractOverflow, dbo.I10_Amcare_VR.AbstractOverflowDesc, 
                         dbo.I10_Amcare_VR.ActivityDescription, dbo.I10_Amcare_VR.ActivityWhenInjured, dbo.I10_Amcare_VR.ActivityWhenInjuredDesc, dbo.I10_Amcare_VR.ActueLOS, dbo.I10_Amcare_VR.AdmitbyAmbulance, 
                         dbo.I10_Amcare_VR.AdmitbyAmbulanceDesc, dbo.I10_Amcare_VR.AdmitCategory, dbo.I10_Amcare_VR.AdmitDiagnosis, dbo.I10_Amcare_VR.AdmitNursingArea, dbo.I10_Amcare_VR.AdmitNursingAreaDesc, 
                         dbo.I10_Amcare_VR.AfterAdmit, dbo.I10_Amcare_VR.AgeCode, dbo.I10_Amcare_VR.AgeCodeDesc, dbo.I10_Amcare_VR.AgeGroup, dbo.I10_Amcare_VR.AgeNumber, dbo.I10_Amcare_VR.Albumin, 
                         dbo.I10_Amcare_VR.AlbuminDesc, dbo.I10_Amcare_VR.AlbuminCrossMatched, dbo.I10_Amcare_VR.AlbuminCrossMatchedDesc, dbo.I10_Amcare_VR.AlbuminTyped, dbo.I10_Amcare_VR.AlbuminTypedDesc, 
                         dbo.I10_Amcare_VR.AlbuminUnits, dbo.I10_Amcare_VR.ALCLOS, dbo.I10_Amcare_VR.AmbulanceReportNumber, dbo.I10_Amcare_VR.AmCareGroup, dbo.I10_Amcare_VR.AmCareGroupDesc, 
                         dbo.I10_Amcare_VR.AmcareCareType, dbo.I10_Amcare_VR.AmcareCareTypeDesc, dbo.I10_Amcare_VR.AmcareTypeCode, dbo.I10_Amcare_VR.AmcareTypeCodeDesc, dbo.I10_Amcare_VR.Ancil13, 
                         dbo.I10_Amcare_VR.Ancil14, dbo.I10_Amcare_VR.Ancil15, dbo.I10_Amcare_VR.Ancil16, dbo.I10_Amcare_VR.Ancil17, dbo.I10_Amcare_VR.AncillaryField1, dbo.I10_Amcare_VR.AncillaryField1Desc, 
                         dbo.I10_Amcare_VR.AncillaryField10, dbo.I10_Amcare_VR.AncillaryField10Desc, dbo.I10_Amcare_VR.AncillaryField11, dbo.I10_Amcare_VR.AncillaryField11Desc, dbo.I10_Amcare_VR.AncillaryField12, 
                         dbo.I10_Amcare_VR.AncillaryField12Desc, dbo.I10_Amcare_VR.AncillaryField2, dbo.I10_Amcare_VR.AncillaryField2Desc, dbo.I10_Amcare_VR.AncillaryField3, dbo.I10_Amcare_VR.AncillaryField3Desc, 
                         dbo.I10_Amcare_VR.AncillaryField4, dbo.I10_Amcare_VR.AncillaryField4Desc, dbo.I10_Amcare_VR.AncillaryField5, dbo.I10_Amcare_VR.AncillaryField5Desc, dbo.I10_Amcare_VR.AncillaryField6, 
                         dbo.I10_Amcare_VR.AncillaryField6Desc, dbo.I10_Amcare_VR.AncillaryField7, dbo.I10_Amcare_VR.AncillaryField7Desc, dbo.I10_Amcare_VR.AncillaryField8, dbo.I10_Amcare_VR.AncillaryField8Desc, 
                         dbo.I10_Amcare_VR.AncillaryField9, dbo.I10_Amcare_VR.AncillaryField9Desc, dbo.I10_Amcare_VR.ArrivalDate, dbo.I10_Amcare_VR.ArrivalMode, dbo.I10_Amcare_VR.ArrivalModeDesc, 
                         dbo.I10_Amcare_VR.ArrivalTime, dbo.I10_Amcare_VR.ArrivaltoTriageTime, dbo.I10_Amcare_VR.AssessmentDate, dbo.I10_Amcare_VR.AssessmentTime, dbo.I10_Amcare_VR.AssessmentTimeUnknown, 
                         dbo.I10_Amcare_VR.AssessmentTimeUnknownDesc, dbo.I10_Amcare_VR.AttendingPhysician, dbo.I10_Amcare_VR.AttendingPhysicianDesc, dbo.I10_Amcare_VR.AutoTransfusion, 
                         dbo.I10_Amcare_VR.AutoTransfusionDesc, dbo.I10_Amcare_VR.AutopsyPerformed, dbo.I10_Amcare_VR.AutopsyPerformedDesc, dbo.I10_Amcare_VR.BasicOption1, dbo.I10_Amcare_VR.BasicOption1Desc, 
                         dbo.I10_Amcare_VR.BasicOption10, dbo.I10_Amcare_VR.BasicOption10Desc, dbo.I10_Amcare_VR.BasicOption11, dbo.I10_Amcare_VR.BasicOption11Desc, dbo.I10_Amcare_VR.BasicOption12, 
                         dbo.I10_Amcare_VR.BasicOption12Desc, dbo.I10_Amcare_VR.BasicOption13, dbo.I10_Amcare_VR.BasicOption13Desc, dbo.I10_Amcare_VR.BasicOption14, dbo.I10_Amcare_VR.BasicOption14Desc, 
                         dbo.I10_Amcare_VR.BasicOption15, dbo.I10_Amcare_VR.BasicOption15Desc, dbo.I10_Amcare_VR.BasicOption16, dbo.I10_Amcare_VR.BasicOption16Desc, dbo.I10_Amcare_VR.BasicOption17, 
                         dbo.I10_Amcare_VR.BasicOption17Desc, dbo.I10_Amcare_VR.BasicOption18, dbo.I10_Amcare_VR.BasicOption18Desc, dbo.I10_Amcare_VR.BasicOption19, dbo.I10_Amcare_VR.BasicOption19Desc, 
                         dbo.I10_Amcare_VR.BasicOption2, dbo.I10_Amcare_VR.BasicOption2Desc, dbo.I10_Amcare_VR.BasicOption3, dbo.I10_Amcare_VR.BasicOption3Desc, dbo.I10_Amcare_VR.BasicOption4, 
                         dbo.I10_Amcare_VR.BasicOption4Desc, dbo.I10_Amcare_VR.BasicOption5, dbo.I10_Amcare_VR.BasicOption5Desc, dbo.I10_Amcare_VR.BasicOption6, dbo.I10_Amcare_VR.BasicOption6Desc, 
                         dbo.I10_Amcare_VR.BasicOption7, dbo.I10_Amcare_VR.BasicOption7Desc, dbo.I10_Amcare_VR.BasicOption8, dbo.I10_Amcare_VR.BasicOption8Desc, dbo.I10_Amcare_VR.BasicOption9, 
                         dbo.I10_Amcare_VR.BasicOption9Desc, dbo.I10_Amcare_VR.BatchNumber, dbo.I10_Amcare_VR.BatchPeriod, dbo.I10_Amcare_VR.BatchPeriodDesc, dbo.I10_Amcare_VR.BatchPeriod_BC, 
                         dbo.I10_Amcare_VR.BatchYear, dbo.I10_Amcare_VR.BirthDate, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIII, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIIIDesc, 
						 dbo.I10_Amcare_VR.Blood_C1Inhibitor, 
                         dbo.I10_Amcare_VR.Blood_C1InhibitorDesc, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasma, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_CryosupernatantPlasma, 
                         dbo.I10_Amcare_VR.Blood_CryosupernatantPlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_FEIBA, 
						 dbo.I10_Amcare_VR.Blood_FEIBADesc, 
						 dbo.I10_Amcare_VR.Blood_Fibrinogen, 
						 dbo.I10_Amcare_VR.Blood_FibrinogenDesc, 
                         dbo.I10_Amcare_VR.Blood_IVIG_SCIG, 
						 dbo.I10_Amcare_VR.Blood_IVIG_SCIGDesc, 
						 dbo.I10_Amcare_VR.Blood_PCC, 
						 dbo.I10_Amcare_VR.Blood_PCCDesc, 
						 dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactors, 
                         dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactorsDesc, 
						 
						 dbo.I10_Amcare_VR.BreastFeeding, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlag, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlagDesc, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitDateIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknown, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknownDesc, dbo.I10_Amcare_VR.ClinicalDecisionUnitDateOut, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOut, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknown, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknownDesc, dbo.I10_Amcare_VR.ChangeinLegalStatus, 
                         dbo.I10_Amcare_VR.ChangeinLegalStatusDesc, dbo.I10_Amcare_VR.ChartNumber, dbo.I10_Amcare_VR.ChiefComplaint, dbo.I10_Amcare_VR.CoderNumber, dbo.I10_Amcare_VR.CoderNumberDesc, 
                         dbo.I10_Amcare_VR.CompleteRecord, dbo.I10_Amcare_VR.CompleteRecordDesc, dbo.I10_Amcare_VR.Complication, dbo.I10_Amcare_VR.ComplicationDesc, dbo.I10_Amcare_VR.Complication1, 
                         dbo.I10_Amcare_VR.Complication1Desc, dbo.I10_Amcare_VR.Complication2, dbo.I10_Amcare_VR.Complication2Desc, dbo.I10_Amcare_VR.Complication3, dbo.I10_Amcare_VR.Complication3Desc, 
                         dbo.I10_Amcare_VR.ContactMode, dbo.I10_Amcare_VR.ContactModeDesc, dbo.I10_Amcare_VR.CoronerCase, dbo.I10_Amcare_VR.CoronerCaseDesc, dbo.I10_Amcare_VR.DataEntryCoder, 
                         dbo.I10_Amcare_VR.DataEntryCoderDesc, dbo.I10_Amcare_VR.DateLeftER, dbo.I10_Amcare_VR.DateofLastMenses, dbo.I10_Amcare_VR.DateReadyforDisch, dbo.I10_Amcare_VR.DateSentToCIHI, 
                         dbo.I10_Amcare_VR.DateSentToCIHILevel1, dbo.I10_Amcare_VR.DateSentToCIHILevel2, dbo.I10_Amcare_VR.DateSentToCIHILite, dbo.I10_Amcare_VR.DeathInER, dbo.I10_Amcare_VR.DeathInERDesc, 
                         dbo.I10_Amcare_VR.DeathOnArrival, dbo.I10_Amcare_VR.DeathOnArrivalDesc, dbo.I10_Amcare_VR.DecisionAdmitDifference, dbo.I10_Amcare_VR.DecisiontoAdmitDate, dbo.I10_Amcare_VR.DecisiontoAdmitTime, 
                         dbo.I10_Amcare_VR.DecisionAdmitTimeUnknown, dbo.I10_Amcare_VR.DecisionAdmitTimeUnknownDesc, dbo.I10_Amcare_VR.DeliveryDate, dbo.I10_Amcare_VR.DeliveryTime, 
                         dbo.I10_Amcare_VR.DiedDuringIntervention, dbo.I10_Amcare_VR.DiedDuringInterventionDesc, dbo.I10_Amcare_VR.DischNursingArea, dbo.I10_Amcare_VR.DischNursingAreaDesc, 
                         dbo.I10_Amcare_VR.DischPlanning, dbo.I10_Amcare_VR.DischPlanningDesc, dbo.I10_Amcare_VR.DischargeAge, dbo.I10_Amcare_VR.DischargeDisposition, dbo.I10_Amcare_VR.DischargeDispositionDesc, 
                         dbo.I10_Amcare_VR.DispositionDate, dbo.I10_Amcare_VR.DispositionTime, dbo.I10_Amcare_VR.DispositionTimeUnknown, dbo.I10_Amcare_VR.DispositionTimeUnknownDesc, dbo.I10_Amcare_VR.ECTTreatment, 
                         dbo.I10_Amcare_VR.ECTTreatmentDesc, dbo.I10_Amcare_VR.Education, dbo.I10_Amcare_VR.EducationDesc, dbo.I10_Amcare_VR.EDVisitIndicator, dbo.I10_Amcare_VR.EDVisitIndicatorDesc, 
                         dbo.I10_Amcare_VR.Employment, dbo.I10_Amcare_VR.EmploymentDesc, dbo.I10_Amcare_VR.EntryCode, dbo.I10_Amcare_VR.EstimateDischDate, dbo.I10_Amcare_VR.ExitCode, 
                         dbo.I10_Amcare_VR.FamilyPhysicianFlag, dbo.I10_Amcare_VR.FamilyPhysicianFlagDesc, dbo.I10_Amcare_VR.FinancialSupport, dbo.I10_Amcare_VR.FinancialSupportDesc, dbo.I10_Amcare_VR.FinishDate, 
                         dbo.I10_Amcare_VR.FinishTime, dbo.I10_Amcare_VR.FirstName, dbo.I10_Amcare_VR.FullName, dbo.I10_Amcare_VR.FixedChartNumber, dbo.I10_Amcare_VR.Gender, dbo.I10_Amcare_VR.GenderDesc, 
                         dbo.I10_Amcare_VR.GestationalAgeinweeks, dbo.I10_Amcare_VR.GlasgowScale, dbo.I10_Amcare_VR.GlasgowScaleDesc, dbo.I10_Amcare_VR.GreaterTenPO, dbo.I10_Amcare_VR.HCNProvince, 
                         dbo.I10_Amcare_VR.HCNProvinceDesc, dbo.I10_Amcare_VR.HCNVersion, dbo.I10_Amcare_VR.HealthCareNumber, dbo.I10_Amcare_VR.Hospital, dbo.I10_Amcare_VR.HospitalDesc, 
                         dbo.I10_Amcare_VR.HospitalAccountRecord,
                         dbo.I10_Amcare_VR.HelmetIndicator, dbo.I10_Amcare_VR.HelmetIndicatorDesc, dbo.I10_Amcare_VR.InSCU, dbo.I10_Amcare_VR.InitialOR, dbo.I10_Amcare_VR.InitialORDesc, dbo.I10_Amcare_VR.InjuryDate, 
                         dbo.I10_Amcare_VR.Injury, dbo.I10_Amcare_VR.InjuryDesc, dbo.I10_Amcare_VR.InputDate, dbo.I10_Amcare_VR.InputTime, 

						 dbo.I10_Amcare_VR.InstitutionFrom, dbo.I10_Amcare_VR.InstitutionFromDesc, 
						 dbo.I10_Amcare_VR.InstitutionFromType, dbo.I10_Amcare_VR.InstitutionFromTypeDesc,
                         dbo.I10_Amcare_VR.InstFromCareType, dbo.I10_Amcare_VR.InstFromHospType, 
						 dbo.I10_Amcare_VR.InstitutionNumber, dbo.I10_Amcare_VR.InstitutionNumberDesc, 
						 dbo.I10_Amcare_VR.InstitutionTo, dbo.I10_Amcare_VR.InstitutionToDesc, 
						 dbo.I10_Amcare_VR.InstToCareType, dbo.I10_Amcare_VR.InstToHospType, 
						 dbo.I10_Amcare_VR.InstitutionToType, dbo.I10_Amcare_VR.InstitutionToTypeDesc, 
						 
						 dbo.I10_Amcare_VR.InterfaceDate, dbo.I10_Amcare_VR.InterfaceTime, 
                         dbo.I10_Amcare_VR.IsAbstractCompleted, dbo.I10_Amcare_VR.IsAbstractCompletedDesc, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCompletedLevel2, dbo.I10_Amcare_VR.IsAbstractCompletedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCompletedLite, dbo.I10_Amcare_VR.IsAbstractCompletedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrected, dbo.I10_Amcare_VR.IsAbstractCorrectedDesc, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCorrectedLite, dbo.I10_Amcare_VR.IsAbstractCorrectedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractDeleted, dbo.I10_Amcare_VR.IsAbstractDeletedDesc, dbo.I10_Amcare_VR.IsAbstractSubmitted, dbo.I10_Amcare_VR.IsAbstractSubmittedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLite, dbo.I10_Amcare_VR.IsAbstractSubmittedLiteDesc, dbo.I10_Amcare_VR.IsAbstractValidated, dbo.I10_Amcare_VR.IsAbstractValidatedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLevel1, dbo.I10_Amcare_VR.IsAbstractValidatedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLite, dbo.I10_Amcare_VR.IsAbstractValidatedLiteDesc, dbo.I10_Amcare_VR.IsBirthdateEstimated, dbo.I10_Amcare_VR.IsBirthdateEstimatedDesc, 
						 dbo.I10_Amcare_VR.IsCustomValidated, dbo.I10_Amcare_VR.IsCustomValidatedDesc,
                         dbo.I10_Amcare_VR.LOSDays, dbo.I10_Amcare_VR.LOSTime, dbo.I10_Amcare_VR.LOSTimeinHours, dbo.I10_Amcare_VR.LOSTotalMinutes, dbo.I10_Amcare_VR.Language, dbo.I10_Amcare_VR.LanguageDesc, 
                         dbo.I10_Amcare_VR.LastName, dbo.I10_Amcare_VR.LessTwoPO, dbo.I10_Amcare_VR.LivingArrangement, dbo.I10_Amcare_VR.LivingArrangementDesc, dbo.I10_Amcare_VR.LocationofInjury, 
                         dbo.I10_Amcare_VR.LocationofInjuryDesc, dbo.I10_Amcare_VR.MISCode, dbo.I10_Amcare_VR.MISCodeDesc, dbo.I10_Amcare_VR.MaidenName, dbo.I10_Amcare_VR.MaritalStatus, 
                         dbo.I10_Amcare_VR.MaritalStatusDesc, 
                         dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoED, 
						 dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04Desc, 
						 
						 dbo.I10_Amcare_VR.MethodofAdmission, dbo.I10_Amcare_VR.MethodofAdmissionDesc, dbo.I10_Amcare_VR.MiddleName, 
                         dbo.I10_Amcare_VR.NACRSClinicLiteSubmission, dbo.I10_Amcare_VR.NACRSClinicLiteSubmissionDesc, 
                         dbo.I10_Amcare_VR.NewbornChart, 
                         dbo.I10_Amcare_VR.NewbornDischDate, dbo.I10_Amcare_VR.NextScheduledVisitDate, dbo.I10_Amcare_VR.NextScheduledVisitTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentDate, 
                         dbo.I10_Amcare_VR.NonPhysicianAssessmentTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknown, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.NonPhysicianNumber, dbo.I10_Amcare_VR.NonPhysicianNumberDesc, dbo.I10_Amcare_VR.NonPhysicianService, dbo.I10_Amcare_VR.NonPhysicianServiceDesc, 
                         dbo.I10_Amcare_VR.NumberofECT, dbo.I10_Amcare_VR.NursingAssessmentDate, dbo.I10_Amcare_VR.NursingAssessmentTime, dbo.I10_Amcare_VR.Occupation, dbo.I10_Amcare_VR.OccupationDesc, 
                         dbo.I10_Amcare_VR.OtherMedicalDeath, dbo.I10_Amcare_VR.OtherMedicalDeathDesc, dbo.I10_Amcare_VR.OtherBlood, dbo.I10_Amcare_VR.OtherBloodDesc, dbo.I10_Amcare_VR.OtherBloodCrossMatched, 
                         dbo.I10_Amcare_VR.OtherBloodCrossMatchedDesc, dbo.I10_Amcare_VR.OtherBloodTyped, dbo.I10_Amcare_VR.OtherBloodTypedDesc, dbo.I10_Amcare_VR.OtherBloodUnits, dbo.I10_Amcare_VR.PCTASIndicator, 
                         dbo.I10_Amcare_VR.PCTASIndicatorDesc, dbo.I10_Amcare_VR.PhysicianEstLOS, dbo.I10_Amcare_VR.Plasma, dbo.I10_Amcare_VR.PlasmaDesc, dbo.I10_Amcare_VR.PlasmaCrossMatched, 
                         dbo.I10_Amcare_VR.PlasmaCrossMatchedDesc, dbo.I10_Amcare_VR.PlasmaTyped, dbo.I10_Amcare_VR.PlasmaTypedDesc, dbo.I10_Amcare_VR.PlasmaUnits, dbo.I10_Amcare_VR.Platelets, 
                         dbo.I10_Amcare_VR.PlateletsDesc, dbo.I10_Amcare_VR.PlateletsCrossMatched, dbo.I10_Amcare_VR.PlateletsCrossMatchedDesc, dbo.I10_Amcare_VR.PlateletsTyped, dbo.I10_Amcare_VR.PlateletsTypedDesc, 
                         dbo.I10_Amcare_VR.PlateletsUnits, dbo.I10_Amcare_VR.PostalCode, dbo.I10_Amcare_VR.PostalCodeDesc, dbo.I10_Amcare_VR.PostOpDays, dbo.I10_Amcare_VR.PreOpDays, 
                         dbo.I10_Amcare_VR.PreamditWorkUp, dbo.I10_Amcare_VR.PreamditWorkUpDesc, dbo.I10_Amcare_VR.Pregnancy, dbo.I10_Amcare_VR.PregnancyDesc, dbo.I10_Amcare_VR.PrevLiveBirth, 
                         dbo.I10_Amcare_VR.PreviousPsychiartricAdmissions, dbo.I10_Amcare_VR.PreviousPsychiartricAdmDesc, dbo.I10_Amcare_VR.Program, dbo.I10_Amcare_VR.ProgramDesc, dbo.I10_Amcare_VR.ProvinceNumber, 
                         dbo.I10_Amcare_VR.ProvinceNumberDesc, dbo.I10_Amcare_VR.ReasonForVisit, dbo.I10_Amcare_VR.ReasonForVisitDesc, dbo.I10_Amcare_VR.ReAdmitCode, dbo.I10_Amcare_VR.ReciprocalBillingStatus, 
                         dbo.I10_Amcare_VR.ReciprocalBillingStatusDesc, dbo.I10_Amcare_VR.RedBloodCell, dbo.I10_Amcare_VR.RedBloodCellDesc, dbo.I10_Amcare_VR.RedBloodCellCrossMatched, 
                         dbo.I10_Amcare_VR.RedBloodCellCrossMatchedDesc, dbo.I10_Amcare_VR.RedBloodCellTyped, dbo.I10_Amcare_VR.RedBloodCellTypedDesc, dbo.I10_Amcare_VR.RedBloodCellUnits, 
                         dbo.I10_Amcare_VR.ReferralDate, dbo.I10_Amcare_VR.ReferredFrom, dbo.I10_Amcare_VR.ReferredFromDesc, dbo.I10_Amcare_VR.ReferredTo, dbo.I10_Amcare_VR.ReferredToDesc, 
                         dbo.I10_Amcare_VR.ReferringProvider, dbo.I10_Amcare_VR.ReferringProviderDesc, dbo.I10_Amcare_VR.RegisterNumber, dbo.I10_Amcare_VR.RegistrationNumber, 
                         dbo.I10_Amcare_VR.RegistrationSequenceNumber, dbo.I10_Amcare_VR.RegistrationVisitDate, dbo.I10_Amcare_VR.RegistrationVisitTime, dbo.I10_Amcare_VR.ReproductiveCareComments, 
                         dbo.I10_Amcare_VR.ReserveField, dbo.I10_Amcare_VR.ResidenceCode, dbo.I10_Amcare_VR.ResidenceCodeDesc, dbo.I10_Amcare_VR.ResidenceProvince, dbo.I10_Amcare_VR.ResidenceProvinceDesc, 
                         dbo.I10_Amcare_VR.ResidenceRegion, dbo.I10_Amcare_VR.ResidenceRegionDesc, dbo.I10_Amcare_VR.ResidenceType, dbo.I10_Amcare_VR.ResidenceTypeDesc, dbo.I10_Amcare_VR.ResponsiblityForPayment,
                          dbo.I10_Amcare_VR.ResponsiblityForPaymentDesc, dbo.I10_Amcare_VR.SchedEDVisit, dbo.I10_Amcare_VR.SchedEDVisitDesc, dbo.I10_Amcare_VR.SeatbeltIndicator, dbo.I10_Amcare_VR.SeatbeltIndicatorDesc, 
                         dbo.I10_Amcare_VR.SecondChartRegisterNumber, dbo.I10_Amcare_VR.SecretVIPPatient, dbo.I10_Amcare_VR.SecretVIPPatientDesc, dbo.I10_Amcare_VR.SiteNumber, dbo.I10_Amcare_VR.SiteNumberDesc, 
                         dbo.I10_Amcare_VR.SocialService, dbo.I10_Amcare_VR.SocialServiceDesc, dbo.I10_Amcare_VR.SourceofReferral, dbo.I10_Amcare_VR.SourceofReferralDesc, dbo.I10_Amcare_VR.SpecialistNumber, 
                         dbo.I10_Amcare_VR.SpecialistNumberDesc, dbo.I10_Amcare_VR.SpecialistRequestDate, dbo.I10_Amcare_VR.SpecialistRequestService, dbo.I10_Amcare_VR.SpecialistRequestServiceDesc, 
                         dbo.I10_Amcare_VR.SpecialistRequestTime, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknown, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknownDesc, dbo.I10_Amcare_VR.StakeholderType, 
                         dbo.I10_Amcare_VR.StakeholderTypeDesc, dbo.I10_Amcare_VR.StatusAfterTriage, dbo.I10_Amcare_VR.StatusAfterTriageDesc, dbo.I10_Amcare_VR.Sterilization, dbo.I10_Amcare_VR.SterilizationDesc, 
                         dbo.I10_Amcare_VR.SubmissionLevelCode, dbo.I10_Amcare_VR.SubmissionRecordID, dbo.I10_Amcare_VR.SubsequentOR, dbo.I10_Amcare_VR.SubsequentORDesc, dbo.I10_Amcare_VR.Suicide, 
                         dbo.I10_Amcare_VR.SuicideDesc, dbo.I10_Amcare_VR.SurgicalCase, dbo.I10_Amcare_VR.SurgicalCaseDesc, dbo.I10_Amcare_VR.TimeLeftER, dbo.I10_Amcare_VR.TimeLeftERUnknown, 
                         dbo.I10_Amcare_VR.TimeLeftERUnknownDEsc, dbo.I10_Amcare_VR.TransferOverloadDate, dbo.I10_Amcare_VR.TransferOverloadTime, dbo.I10_Amcare_VR.TransferOverloadTimeDifference, 
                         dbo.I10_Amcare_VR.TransfusionGiven, dbo.I10_Amcare_VR.TransfusionGivenDesc, dbo.I10_Amcare_VR.Trauma, dbo.I10_Amcare_VR.TraumaDesc, dbo.I10_Amcare_VR.TriageDate, 
                         dbo.I10_Amcare_VR.TriageLevel, dbo.I10_Amcare_VR.TriageLevelDesc, dbo.I10_Amcare_VR.TriageTime, dbo.I10_Amcare_VR.TriageTimeUnknown, dbo.I10_Amcare_VR.TriageTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.TSICoder, dbo.I10_Amcare_VR.TSICoderDesc, dbo.I10_Amcare_VR.TSIDate, dbo.I10_Amcare_VR.TSITime, dbo.I10_Amcare_VR.TwoTenPO, dbo.I10_Amcare_VR.ULI, 
                         dbo.I10_Amcare_VR.UniversalEpisodeIdentifier, dbo.I10_Amcare_VR.UnplannedReadmit, dbo.I10_Amcare_VR.VisitStatus, dbo.I10_Amcare_VR.VisitStatusDesc, dbo.I10_Amcare_VR.VisitType, dbo.I10_Amcare_VR.VisitTypeDesc, 
                         dbo.I10_Amcare_VR.WaitTimeinER, dbo.I10_Amcare_VR.WaittoAssessmentinMinutes, dbo.I10_Amcare_VR.WaittoNursingAssessmentDiff, dbo.I10_Amcare_VR.Weight, dbo.I10_Amcare_VR.zzAbstractLink, 
                         dbo.I10_Amcare_VR.zzRegionalPatientID, dbo.I10_Amcare_VR.zzVolumeLink, dbo.I10_Amcare_MIS_VR.DirectCosts, dbo.I10_Amcare_MIS_VR.IndirectCosts, 
						 dbo.I10_Amcare_MIS_VR.MISCode AS MISCodeMulti, 
                         dbo.I10_Amcare_MIS_VR.MISCodeDesc AS MISCodeMultiDesc, dbo.I10_Amcare_MIS_VR.MISOccurrence, dbo.I10_Amcare_MIS_VR.SupplyCosts
FROM            dbo.I10_Amcare_MIS_VR RIGHT OUTER JOIN
                         dbo.I10_Amcare_VR ON dbo.I10_Amcare_MIS_VR.zzAbstractLink = dbo.I10_Amcare_VR.zzAbstractLink



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_PresentingComplaint]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_Amcare_And_PresentingComplaint]
AS
SELECT        dbo.I10_Amcare_VR.[#ofPreviousPreTermDeliveries], dbo.I10_Amcare_VR.[#ofPrevSpontaneousAbortions], dbo.I10_Amcare_VR.[#ofPreviousTermDeliveries], dbo.I10_Amcare_VR.AccessPrimaryHealthCareCode, 
                         dbo.I10_Amcare_VR.AccessPrimaryHealthCareCodeDesc, dbo.I10_Amcare_VR.AmbulanceArrivalDate, dbo.I10_Amcare_VR.AmbulanceArrivalTime, dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknown, 
                         dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknownDesc, dbo.I10_Amcare_VR.AmbulanceTransferCareDate, dbo.I10_Amcare_VR.AmbulanceTransferCareTime, 
                         dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknown, dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknownDesc, dbo.I10_Amcare_VR.[#ofPrevTherapeuticAbortions], dbo.I10_Amcare_VR.AWOL, 
                         dbo.I10_Amcare_VR.AWOLDesc, dbo.I10_Amcare_VR.AbortDate, dbo.I10_Amcare_VR.AbstractNumber, dbo.I10_Amcare_VR.AbstractOverflow, dbo.I10_Amcare_VR.AbstractOverflowDesc, 
                         dbo.I10_Amcare_VR.ActivityDescription, dbo.I10_Amcare_VR.ActivityWhenInjured, dbo.I10_Amcare_VR.ActivityWhenInjuredDesc, dbo.I10_Amcare_VR.ActueLOS, dbo.I10_Amcare_VR.AdmitbyAmbulance, 
                         dbo.I10_Amcare_VR.AdmitbyAmbulanceDesc, dbo.I10_Amcare_VR.AdmitCategory, dbo.I10_Amcare_VR.AdmitDiagnosis, dbo.I10_Amcare_VR.AdmitNursingArea, dbo.I10_Amcare_VR.AdmitNursingAreaDesc, 
                         dbo.I10_Amcare_VR.AfterAdmit, dbo.I10_Amcare_VR.AgeCode, dbo.I10_Amcare_VR.AgeCodeDesc, dbo.I10_Amcare_VR.AgeGroup, dbo.I10_Amcare_VR.AgeNumber, dbo.I10_Amcare_VR.Albumin, 
                         dbo.I10_Amcare_VR.AlbuminDesc, dbo.I10_Amcare_VR.AlbuminCrossMatched, dbo.I10_Amcare_VR.AlbuminCrossMatchedDesc, dbo.I10_Amcare_VR.AlbuminTyped, dbo.I10_Amcare_VR.AlbuminTypedDesc, 
                         dbo.I10_Amcare_VR.AlbuminUnits, dbo.I10_Amcare_VR.ALCLOS, dbo.I10_Amcare_VR.AmbulanceReportNumber, dbo.I10_Amcare_VR.AmCareGroup, dbo.I10_Amcare_VR.AmCareGroupDesc, 
                         dbo.I10_Amcare_VR.AmcareCareType, dbo.I10_Amcare_VR.AmcareCareTypeDesc, dbo.I10_Amcare_VR.AmcareTypeCode, dbo.I10_Amcare_VR.AmcareTypeCodeDesc, dbo.I10_Amcare_VR.Ancil13, 
                         dbo.I10_Amcare_VR.Ancil14, dbo.I10_Amcare_VR.Ancil15, dbo.I10_Amcare_VR.Ancil16, dbo.I10_Amcare_VR.Ancil17, dbo.I10_Amcare_VR.AncillaryField1, dbo.I10_Amcare_VR.AncillaryField1Desc, 
                         dbo.I10_Amcare_VR.AncillaryField10, dbo.I10_Amcare_VR.AncillaryField10Desc, dbo.I10_Amcare_VR.AncillaryField11, dbo.I10_Amcare_VR.AncillaryField11Desc, dbo.I10_Amcare_VR.AncillaryField12, 
                         dbo.I10_Amcare_VR.AncillaryField12Desc, dbo.I10_Amcare_VR.AncillaryField2, dbo.I10_Amcare_VR.AncillaryField2Desc, dbo.I10_Amcare_VR.AncillaryField3, dbo.I10_Amcare_VR.AncillaryField3Desc, 
                         dbo.I10_Amcare_VR.AncillaryField4, dbo.I10_Amcare_VR.AncillaryField4Desc, dbo.I10_Amcare_VR.AncillaryField5, dbo.I10_Amcare_VR.AncillaryField5Desc, dbo.I10_Amcare_VR.AncillaryField6, 
                         dbo.I10_Amcare_VR.AncillaryField6Desc, dbo.I10_Amcare_VR.AncillaryField7, dbo.I10_Amcare_VR.AncillaryField7Desc, dbo.I10_Amcare_VR.AncillaryField8, dbo.I10_Amcare_VR.AncillaryField8Desc, 
                         dbo.I10_Amcare_VR.AncillaryField9, dbo.I10_Amcare_VR.AncillaryField9Desc, dbo.I10_Amcare_VR.ArrivalDate, dbo.I10_Amcare_VR.ArrivalMode, dbo.I10_Amcare_VR.ArrivalModeDesc, 
                         dbo.I10_Amcare_VR.ArrivalTime, dbo.I10_Amcare_VR.ArrivaltoTriageTime, dbo.I10_Amcare_VR.AssessmentDate, dbo.I10_Amcare_VR.AssessmentTime, dbo.I10_Amcare_VR.AssessmentTimeUnknown, 
                         dbo.I10_Amcare_VR.AssessmentTimeUnknownDesc, dbo.I10_Amcare_VR.AttendingPhysician, dbo.I10_Amcare_VR.AttendingPhysicianDesc, dbo.I10_Amcare_VR.AutoTransfusion, 
                         dbo.I10_Amcare_VR.AutoTransfusionDesc, dbo.I10_Amcare_VR.AutopsyPerformed, dbo.I10_Amcare_VR.AutopsyPerformedDesc, dbo.I10_Amcare_VR.BasicOption1, dbo.I10_Amcare_VR.BasicOption1Desc, 
                         dbo.I10_Amcare_VR.BasicOption10, dbo.I10_Amcare_VR.BasicOption10Desc, dbo.I10_Amcare_VR.BasicOption11, dbo.I10_Amcare_VR.BasicOption11Desc, dbo.I10_Amcare_VR.BasicOption12, 
                         dbo.I10_Amcare_VR.BasicOption12Desc, dbo.I10_Amcare_VR.BasicOption13, dbo.I10_Amcare_VR.BasicOption13Desc, dbo.I10_Amcare_VR.BasicOption14, dbo.I10_Amcare_VR.BasicOption14Desc, 
                         dbo.I10_Amcare_VR.BasicOption15, dbo.I10_Amcare_VR.BasicOption15Desc, dbo.I10_Amcare_VR.BasicOption16, dbo.I10_Amcare_VR.BasicOption16Desc, dbo.I10_Amcare_VR.BasicOption17, 
                         dbo.I10_Amcare_VR.BasicOption17Desc, dbo.I10_Amcare_VR.BasicOption18, dbo.I10_Amcare_VR.BasicOption18Desc, dbo.I10_Amcare_VR.BasicOption19, dbo.I10_Amcare_VR.BasicOption19Desc, 
                         dbo.I10_Amcare_VR.BasicOption2, dbo.I10_Amcare_VR.BasicOption2Desc, dbo.I10_Amcare_VR.BasicOption3, dbo.I10_Amcare_VR.BasicOption3Desc, dbo.I10_Amcare_VR.BasicOption4, 
                         dbo.I10_Amcare_VR.BasicOption4Desc, dbo.I10_Amcare_VR.BasicOption5, dbo.I10_Amcare_VR.BasicOption5Desc, dbo.I10_Amcare_VR.BasicOption6, dbo.I10_Amcare_VR.BasicOption6Desc, 
                         dbo.I10_Amcare_VR.BasicOption7, dbo.I10_Amcare_VR.BasicOption7Desc, dbo.I10_Amcare_VR.BasicOption8, dbo.I10_Amcare_VR.BasicOption8Desc, dbo.I10_Amcare_VR.BasicOption9, 
                         dbo.I10_Amcare_VR.BasicOption9Desc, dbo.I10_Amcare_VR.BatchNumber, dbo.I10_Amcare_VR.BatchPeriod, dbo.I10_Amcare_VR.BatchPeriodDesc, dbo.I10_Amcare_VR.BatchPeriod_BC, 
                         dbo.I10_Amcare_VR.BatchYear, dbo.I10_Amcare_VR.BirthDate, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIII, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIIIDesc, 
						 dbo.I10_Amcare_VR.Blood_C1Inhibitor, 
                         dbo.I10_Amcare_VR.Blood_C1InhibitorDesc, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasma, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_CryosupernatantPlasma, 
                         dbo.I10_Amcare_VR.Blood_CryosupernatantPlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_FEIBA, 
						 dbo.I10_Amcare_VR.Blood_FEIBADesc, 
						 dbo.I10_Amcare_VR.Blood_Fibrinogen, 
						 dbo.I10_Amcare_VR.Blood_FibrinogenDesc, 
                         dbo.I10_Amcare_VR.Blood_IVIG_SCIG, 
						 dbo.I10_Amcare_VR.Blood_IVIG_SCIGDesc, 
						 dbo.I10_Amcare_VR.Blood_PCC, 
						 dbo.I10_Amcare_VR.Blood_PCCDesc, 
						 dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactors, 
                         dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactorsDesc, 
						 
						 dbo.I10_Amcare_VR.BreastFeeding, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlag, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlagDesc, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitDateIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknown, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknownDesc, dbo.I10_Amcare_VR.ClinicalDecisionUnitDateOut, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOut, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknown, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknownDesc, dbo.I10_Amcare_VR.ChangeinLegalStatus, 
                         dbo.I10_Amcare_VR.ChangeinLegalStatusDesc, dbo.I10_Amcare_VR.ChartNumber, dbo.I10_Amcare_VR.ChiefComplaint, dbo.I10_Amcare_VR.CoderNumber, dbo.I10_Amcare_VR.CoderNumberDesc, 
                         dbo.I10_Amcare_VR.CompleteRecord, dbo.I10_Amcare_VR.CompleteRecordDesc, dbo.I10_Amcare_VR.Complication, dbo.I10_Amcare_VR.ComplicationDesc, dbo.I10_Amcare_VR.Complication1, 
                         dbo.I10_Amcare_VR.Complication1Desc, dbo.I10_Amcare_VR.Complication2, dbo.I10_Amcare_VR.Complication2Desc, dbo.I10_Amcare_VR.Complication3, dbo.I10_Amcare_VR.Complication3Desc, 
                         dbo.I10_Amcare_VR.ContactMode, dbo.I10_Amcare_VR.ContactModeDesc, dbo.I10_Amcare_VR.CoronerCase, dbo.I10_Amcare_VR.CoronerCaseDesc, dbo.I10_Amcare_VR.DataEntryCoder, 
                         dbo.I10_Amcare_VR.DataEntryCoderDesc, dbo.I10_Amcare_VR.DateLeftER, dbo.I10_Amcare_VR.DateofLastMenses, dbo.I10_Amcare_VR.DateReadyforDisch, dbo.I10_Amcare_VR.DateSentToCIHI, 
                         dbo.I10_Amcare_VR.DateSentToCIHILevel1, dbo.I10_Amcare_VR.DateSentToCIHILevel2, dbo.I10_Amcare_VR.DateSentToCIHILite, dbo.I10_Amcare_VR.DeathInER, dbo.I10_Amcare_VR.DeathInERDesc, 
                         dbo.I10_Amcare_VR.DeathOnArrival, dbo.I10_Amcare_VR.DeathOnArrivalDesc, dbo.I10_Amcare_VR.DecisionAdmitDifference, dbo.I10_Amcare_VR.DecisiontoAdmitDate, dbo.I10_Amcare_VR.DecisiontoAdmitTime, 
                         dbo.I10_Amcare_VR.DecisionAdmitTimeUnknown, dbo.I10_Amcare_VR.DecisionAdmitTimeUnknownDesc, dbo.I10_Amcare_VR.DeliveryDate, dbo.I10_Amcare_VR.DeliveryTime, 
                         dbo.I10_Amcare_VR.DiedDuringIntervention, dbo.I10_Amcare_VR.DiedDuringInterventionDesc, dbo.I10_Amcare_VR.DischNursingArea, dbo.I10_Amcare_VR.DischNursingAreaDesc, 
                         dbo.I10_Amcare_VR.DischPlanning, dbo.I10_Amcare_VR.DischPlanningDesc, dbo.I10_Amcare_VR.DischargeAge, dbo.I10_Amcare_VR.DischargeDisposition, dbo.I10_Amcare_VR.DischargeDispositionDesc, 
                         dbo.I10_Amcare_VR.DispositionDate, dbo.I10_Amcare_VR.DispositionTime, dbo.I10_Amcare_VR.DispositionTimeUnknown, dbo.I10_Amcare_VR.DispositionTimeUnknownDesc, dbo.I10_Amcare_VR.ECTTreatment, 
                         dbo.I10_Amcare_VR.ECTTreatmentDesc, dbo.I10_Amcare_VR.Education, dbo.I10_Amcare_VR.EducationDesc, dbo.I10_Amcare_VR.EDVisitIndicator, dbo.I10_Amcare_VR.EDVisitIndicatorDesc, 
                         dbo.I10_Amcare_VR.Employment, dbo.I10_Amcare_VR.EmploymentDesc, dbo.I10_Amcare_VR.EntryCode, dbo.I10_Amcare_VR.EstimateDischDate, dbo.I10_Amcare_VR.ExitCode, 
                         dbo.I10_Amcare_VR.FamilyPhysicianFlag, dbo.I10_Amcare_VR.FamilyPhysicianFlagDesc, dbo.I10_Amcare_VR.FinancialSupport, dbo.I10_Amcare_VR.FinancialSupportDesc, dbo.I10_Amcare_VR.FinishDate, 
                         dbo.I10_Amcare_VR.FinishTime, dbo.I10_Amcare_VR.FirstName, dbo.I10_Amcare_VR.FullName, dbo.I10_Amcare_VR.FixedChartNumber, dbo.I10_Amcare_VR.Gender, dbo.I10_Amcare_VR.GenderDesc, 
                         dbo.I10_Amcare_VR.GestationalAgeinweeks, dbo.I10_Amcare_VR.GlasgowScale, dbo.I10_Amcare_VR.GlasgowScaleDesc, dbo.I10_Amcare_VR.GreaterTenPO, dbo.I10_Amcare_VR.HCNProvince, 
                         dbo.I10_Amcare_VR.HCNProvinceDesc, dbo.I10_Amcare_VR.HCNVersion, dbo.I10_Amcare_VR.HealthCareNumber, dbo.I10_Amcare_VR.Hospital, dbo.I10_Amcare_VR.HospitalDesc, 
                         dbo.I10_Amcare_VR.HospitalAccountRecord,
                         dbo.I10_Amcare_VR.HelmetIndicator, dbo.I10_Amcare_VR.HelmetIndicatorDesc, dbo.I10_Amcare_VR.InSCU, dbo.I10_Amcare_VR.InitialOR, dbo.I10_Amcare_VR.InitialORDesc, dbo.I10_Amcare_VR.InjuryDate, 
                         dbo.I10_Amcare_VR.Injury, dbo.I10_Amcare_VR.InjuryDesc, dbo.I10_Amcare_VR.InputDate, dbo.I10_Amcare_VR.InputTime, 

						 dbo.I10_Amcare_VR.InstitutionFrom, dbo.I10_Amcare_VR.InstitutionFromDesc, 
						 dbo.I10_Amcare_VR.InstitutionFromType, dbo.I10_Amcare_VR.InstitutionFromTypeDesc,
                         dbo.I10_Amcare_VR.InstFromCareType, dbo.I10_Amcare_VR.InstFromHospType, 
						 dbo.I10_Amcare_VR.InstitutionNumber, dbo.I10_Amcare_VR.InstitutionNumberDesc, 
						 dbo.I10_Amcare_VR.InstitutionTo, dbo.I10_Amcare_VR.InstitutionToDesc, 
						 dbo.I10_Amcare_VR.InstToCareType, dbo.I10_Amcare_VR.InstToHospType, 
						 dbo.I10_Amcare_VR.InstitutionToType, dbo.I10_Amcare_VR.InstitutionToTypeDesc, 
						 
						 dbo.I10_Amcare_VR.InterfaceDate, dbo.I10_Amcare_VR.InterfaceTime, 
                         dbo.I10_Amcare_VR.IsAbstractCompleted, dbo.I10_Amcare_VR.IsAbstractCompletedDesc, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCompletedLevel2, dbo.I10_Amcare_VR.IsAbstractCompletedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCompletedLite, dbo.I10_Amcare_VR.IsAbstractCompletedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrected, dbo.I10_Amcare_VR.IsAbstractCorrectedDesc, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCorrectedLite, dbo.I10_Amcare_VR.IsAbstractCorrectedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractDeleted, dbo.I10_Amcare_VR.IsAbstractDeletedDesc, dbo.I10_Amcare_VR.IsAbstractSubmitted, dbo.I10_Amcare_VR.IsAbstractSubmittedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLite, dbo.I10_Amcare_VR.IsAbstractSubmittedLiteDesc, dbo.I10_Amcare_VR.IsAbstractValidated, dbo.I10_Amcare_VR.IsAbstractValidatedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLevel1, dbo.I10_Amcare_VR.IsAbstractValidatedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLite, dbo.I10_Amcare_VR.IsAbstractValidatedLiteDesc, dbo.I10_Amcare_VR.IsBirthdateEstimated, dbo.I10_Amcare_VR.IsBirthdateEstimatedDesc, 
						 dbo.I10_Amcare_VR.IsCustomValidated, dbo.I10_Amcare_VR.IsCustomValidatedDesc,
                         dbo.I10_Amcare_VR.LOSDays, dbo.I10_Amcare_VR.LOSTime, dbo.I10_Amcare_VR.LOSTimeinHours, dbo.I10_Amcare_VR.LOSTotalMinutes, dbo.I10_Amcare_VR.Language, dbo.I10_Amcare_VR.LanguageDesc, 
                         dbo.I10_Amcare_VR.LastName, dbo.I10_Amcare_VR.LessTwoPO, dbo.I10_Amcare_VR.LivingArrangement, dbo.I10_Amcare_VR.LivingArrangementDesc, dbo.I10_Amcare_VR.LocationofInjury, 
                         dbo.I10_Amcare_VR.LocationofInjuryDesc, dbo.I10_Amcare_VR.MISCode, dbo.I10_Amcare_VR.MISCodeDesc, dbo.I10_Amcare_VR.MaidenName, dbo.I10_Amcare_VR.MaritalStatus, 
                         dbo.I10_Amcare_VR.MaritalStatusDesc, 
                         dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoED, 
						 dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04Desc, 
						 
						 dbo.I10_Amcare_VR.MethodofAdmission, dbo.I10_Amcare_VR.MethodofAdmissionDesc, dbo.I10_Amcare_VR.MiddleName, 
                         dbo.I10_Amcare_VR.NACRSClinicLiteSubmission, dbo.I10_Amcare_VR.NACRSClinicLiteSubmissionDesc, 
                         dbo.I10_Amcare_VR.NewbornChart, 
                         dbo.I10_Amcare_VR.NewbornDischDate, dbo.I10_Amcare_VR.NextScheduledVisitDate, dbo.I10_Amcare_VR.NextScheduledVisitTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentDate, 
                         dbo.I10_Amcare_VR.NonPhysicianAssessmentTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknown, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.NonPhysicianNumber, dbo.I10_Amcare_VR.NonPhysicianNumberDesc, dbo.I10_Amcare_VR.NonPhysicianService, dbo.I10_Amcare_VR.NonPhysicianServiceDesc, 
                         dbo.I10_Amcare_VR.NumberofECT, dbo.I10_Amcare_VR.NursingAssessmentDate, dbo.I10_Amcare_VR.NursingAssessmentTime, dbo.I10_Amcare_VR.Occupation, dbo.I10_Amcare_VR.OccupationDesc, 
                         dbo.I10_Amcare_VR.OtherMedicalDeath, dbo.I10_Amcare_VR.OtherMedicalDeathDesc, dbo.I10_Amcare_VR.OtherBlood, dbo.I10_Amcare_VR.OtherBloodDesc, dbo.I10_Amcare_VR.OtherBloodCrossMatched, 
                         dbo.I10_Amcare_VR.OtherBloodCrossMatchedDesc, dbo.I10_Amcare_VR.OtherBloodTyped, dbo.I10_Amcare_VR.OtherBloodTypedDesc, dbo.I10_Amcare_VR.OtherBloodUnits, dbo.I10_Amcare_VR.PCTASIndicator, 
                         dbo.I10_Amcare_VR.PCTASIndicatorDesc, dbo.I10_Amcare_VR.PhysicianEstLOS, dbo.I10_Amcare_VR.Plasma, dbo.I10_Amcare_VR.PlasmaDesc, dbo.I10_Amcare_VR.PlasmaCrossMatched, 
                         dbo.I10_Amcare_VR.PlasmaCrossMatchedDesc, dbo.I10_Amcare_VR.PlasmaTyped, dbo.I10_Amcare_VR.PlasmaTypedDesc, dbo.I10_Amcare_VR.PlasmaUnits, dbo.I10_Amcare_VR.Platelets, 
                         dbo.I10_Amcare_VR.PlateletsDesc, dbo.I10_Amcare_VR.PlateletsCrossMatched, dbo.I10_Amcare_VR.PlateletsCrossMatchedDesc, dbo.I10_Amcare_VR.PlateletsTyped, dbo.I10_Amcare_VR.PlateletsTypedDesc, 
                         dbo.I10_Amcare_VR.PlateletsUnits, dbo.I10_Amcare_VR.PostalCode, dbo.I10_Amcare_VR.PostalCodeDesc, dbo.I10_Amcare_VR.PostOpDays, dbo.I10_Amcare_VR.PreOpDays, 
                         dbo.I10_Amcare_VR.PreamditWorkUp, dbo.I10_Amcare_VR.PreamditWorkUpDesc, dbo.I10_Amcare_VR.Pregnancy, dbo.I10_Amcare_VR.PregnancyDesc, dbo.I10_Amcare_VR.PrevLiveBirth, 
                         dbo.I10_Amcare_VR.PreviousPsychiartricAdmissions, dbo.I10_Amcare_VR.PreviousPsychiartricAdmDesc, dbo.I10_Amcare_VR.Program, dbo.I10_Amcare_VR.ProgramDesc, dbo.I10_Amcare_VR.ProvinceNumber, 
                         dbo.I10_Amcare_VR.ProvinceNumberDesc, dbo.I10_Amcare_VR.ReasonForVisit, dbo.I10_Amcare_VR.ReasonForVisitDesc, dbo.I10_Amcare_VR.ReAdmitCode, dbo.I10_Amcare_VR.ReciprocalBillingStatus, 
                         dbo.I10_Amcare_VR.ReciprocalBillingStatusDesc, dbo.I10_Amcare_VR.RedBloodCell, dbo.I10_Amcare_VR.RedBloodCellDesc, dbo.I10_Amcare_VR.RedBloodCellCrossMatched, 
                         dbo.I10_Amcare_VR.RedBloodCellCrossMatchedDesc, dbo.I10_Amcare_VR.RedBloodCellTyped, dbo.I10_Amcare_VR.RedBloodCellTypedDesc, dbo.I10_Amcare_VR.RedBloodCellUnits, 
                         dbo.I10_Amcare_VR.ReferralDate, dbo.I10_Amcare_VR.ReferredFrom, dbo.I10_Amcare_VR.ReferredFromDesc, dbo.I10_Amcare_VR.ReferredTo, dbo.I10_Amcare_VR.ReferredToDesc, 
                         dbo.I10_Amcare_VR.ReferringProvider, dbo.I10_Amcare_VR.ReferringProviderDesc, dbo.I10_Amcare_VR.RegisterNumber, dbo.I10_Amcare_VR.RegistrationNumber, 
                         dbo.I10_Amcare_VR.RegistrationSequenceNumber, dbo.I10_Amcare_VR.RegistrationVisitDate, dbo.I10_Amcare_VR.RegistrationVisitTime, dbo.I10_Amcare_VR.ReproductiveCareComments, 
                         dbo.I10_Amcare_VR.ReserveField, dbo.I10_Amcare_VR.ResidenceCode, dbo.I10_Amcare_VR.ResidenceCodeDesc, dbo.I10_Amcare_VR.ResidenceProvince, dbo.I10_Amcare_VR.ResidenceProvinceDesc, 
                         dbo.I10_Amcare_VR.ResidenceRegion, dbo.I10_Amcare_VR.ResidenceRegionDesc, dbo.I10_Amcare_VR.ResidenceType, dbo.I10_Amcare_VR.ResidenceTypeDesc, dbo.I10_Amcare_VR.ResponsiblityForPayment,
                          dbo.I10_Amcare_VR.ResponsiblityForPaymentDesc, dbo.I10_Amcare_VR.SchedEDVisit, dbo.I10_Amcare_VR.SchedEDVisitDesc, dbo.I10_Amcare_VR.SeatbeltIndicator, dbo.I10_Amcare_VR.SeatbeltIndicatorDesc, 
                         dbo.I10_Amcare_VR.SecondChartRegisterNumber, dbo.I10_Amcare_VR.SecretVIPPatient, dbo.I10_Amcare_VR.SecretVIPPatientDesc, dbo.I10_Amcare_VR.SiteNumber, dbo.I10_Amcare_VR.SiteNumberDesc, 
                         dbo.I10_Amcare_VR.SocialService, dbo.I10_Amcare_VR.SocialServiceDesc, dbo.I10_Amcare_VR.SourceofReferral, dbo.I10_Amcare_VR.SourceofReferralDesc, dbo.I10_Amcare_VR.SpecialistNumber, 
                         dbo.I10_Amcare_VR.SpecialistNumberDesc, dbo.I10_Amcare_VR.SpecialistRequestDate, dbo.I10_Amcare_VR.SpecialistRequestService, dbo.I10_Amcare_VR.SpecialistRequestServiceDesc, 
                         dbo.I10_Amcare_VR.SpecialistRequestTime, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknown, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknownDesc, dbo.I10_Amcare_VR.StakeholderType, 
                         dbo.I10_Amcare_VR.StakeholderTypeDesc, dbo.I10_Amcare_VR.StatusAfterTriage, dbo.I10_Amcare_VR.StatusAfterTriageDesc, dbo.I10_Amcare_VR.Sterilization, dbo.I10_Amcare_VR.SterilizationDesc, 
                         dbo.I10_Amcare_VR.SubmissionLevelCode, dbo.I10_Amcare_VR.SubmissionRecordID, dbo.I10_Amcare_VR.SubsequentOR, dbo.I10_Amcare_VR.SubsequentORDesc, dbo.I10_Amcare_VR.Suicide, 
                         dbo.I10_Amcare_VR.SuicideDesc, dbo.I10_Amcare_VR.SurgicalCase, dbo.I10_Amcare_VR.SurgicalCaseDesc, dbo.I10_Amcare_VR.TimeLeftER, dbo.I10_Amcare_VR.TimeLeftERUnknown, 
                         dbo.I10_Amcare_VR.TimeLeftERUnknownDEsc, dbo.I10_Amcare_VR.TransferOverloadDate, dbo.I10_Amcare_VR.TransferOverloadTime, dbo.I10_Amcare_VR.TransferOverloadTimeDifference, 
                         dbo.I10_Amcare_VR.TransfusionGiven, dbo.I10_Amcare_VR.TransfusionGivenDesc, dbo.I10_Amcare_VR.Trauma, dbo.I10_Amcare_VR.TraumaDesc, dbo.I10_Amcare_VR.TriageDate, 
                         dbo.I10_Amcare_VR.TriageLevel, dbo.I10_Amcare_VR.TriageLevelDesc, dbo.I10_Amcare_VR.TriageTime, dbo.I10_Amcare_VR.TriageTimeUnknown, dbo.I10_Amcare_VR.TriageTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.TSICoder, dbo.I10_Amcare_VR.TSICoderDesc, dbo.I10_Amcare_VR.TSIDate, dbo.I10_Amcare_VR.TSITime, dbo.I10_Amcare_VR.TwoTenPO, dbo.I10_Amcare_VR.ULI, 
                         dbo.I10_Amcare_VR.UniversalEpisodeIdentifier, dbo.I10_Amcare_VR.UnplannedReadmit, dbo.I10_Amcare_VR.VisitStatus, dbo.I10_Amcare_VR.VisitStatusDesc, dbo.I10_Amcare_VR.VisitType, dbo.I10_Amcare_VR.VisitTypeDesc, 
                         dbo.I10_Amcare_VR.WaitTimeinER, dbo.I10_Amcare_VR.WaittoAssessmentinMinutes, dbo.I10_Amcare_VR.WaittoNursingAssessmentDiff, dbo.I10_Amcare_VR.Weight, dbo.I10_Amcare_VR.zzAbstractLink, 
                         dbo.I10_Amcare_VR.zzRegionalPatientID, dbo.I10_Amcare_VR.zzVolumeLink, 
						 
						 dbo.I10_Amcare_PresentingComplaint.PresentingComplaintOccurrence, dbo.I10_Amcare_PresentingComplaint.PresentingComplaint, 
                         dbo.I10_Amcare_PresentingComplaint.PresentingComplaintDesc
FROM            dbo.I10_Amcare_VR LEFT OUTER JOIN
                         dbo.I10_Amcare_PresentingComplaint ON dbo.I10_Amcare_VR.zzAbstractLink = dbo.I10_Amcare_PresentingComplaint.zzAbstractLink



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Project_100_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_Amcare_And_Project_100_VR]
AS
SELECT        dbo.I10_Amcare_VR.[#ofPreviousPreTermDeliveries], dbo.I10_Amcare_VR.[#ofPrevSpontaneousAbortions], dbo.I10_Amcare_VR.[#ofPreviousTermDeliveries], dbo.I10_Amcare_VR.AccessPrimaryHealthCareCode, 
                         dbo.I10_Amcare_VR.AccessPrimaryHealthCareCodeDesc, dbo.I10_Amcare_VR.AmbulanceArrivalDate, dbo.I10_Amcare_VR.AmbulanceArrivalTime, dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknown, 
                         dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknownDesc, dbo.I10_Amcare_VR.AmbulanceTransferCareDate, dbo.I10_Amcare_VR.AmbulanceTransferCareTime, 
                         dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknown, dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknownDesc, dbo.I10_Amcare_VR.[#ofPrevTherapeuticAbortions], dbo.I10_Amcare_VR.AWOL, 
                         dbo.I10_Amcare_VR.AWOLDesc, dbo.I10_Amcare_VR.AbortDate, dbo.I10_Amcare_VR.AbstractNumber, dbo.I10_Amcare_VR.AbstractOverflow, dbo.I10_Amcare_VR.AbstractOverflowDesc, 
                         dbo.I10_Amcare_VR.ActivityDescription, dbo.I10_Amcare_VR.ActivityWhenInjured, dbo.I10_Amcare_VR.ActivityWhenInjuredDesc, dbo.I10_Amcare_VR.ActueLOS, dbo.I10_Amcare_VR.AdmitbyAmbulance, 
                         dbo.I10_Amcare_VR.AdmitbyAmbulanceDesc, dbo.I10_Amcare_VR.AdmitCategory, dbo.I10_Amcare_VR.AdmitDiagnosis, dbo.I10_Amcare_VR.AdmitNursingArea, dbo.I10_Amcare_VR.AdmitNursingAreaDesc, 
                         dbo.I10_Amcare_VR.AfterAdmit, dbo.I10_Amcare_VR.AgeCode, dbo.I10_Amcare_VR.AgeCodeDesc, dbo.I10_Amcare_VR.AgeGroup, dbo.I10_Amcare_VR.AgeNumber, dbo.I10_Amcare_VR.Albumin, 
                         dbo.I10_Amcare_VR.AlbuminDesc, dbo.I10_Amcare_VR.AlbuminCrossMatched, dbo.I10_Amcare_VR.AlbuminCrossMatchedDesc, dbo.I10_Amcare_VR.AlbuminTyped, dbo.I10_Amcare_VR.AlbuminTypedDesc, 
                         dbo.I10_Amcare_VR.AlbuminUnits, dbo.I10_Amcare_VR.ALCLOS, dbo.I10_Amcare_VR.AmbulanceReportNumber, dbo.I10_Amcare_VR.AmCareGroup, dbo.I10_Amcare_VR.AmCareGroupDesc, 
                         dbo.I10_Amcare_VR.AmcareCareType, dbo.I10_Amcare_VR.AmcareCareTypeDesc, dbo.I10_Amcare_VR.AmcareTypeCode, dbo.I10_Amcare_VR.AmcareTypeCodeDesc, dbo.I10_Amcare_VR.Ancil13, 
                         dbo.I10_Amcare_VR.Ancil14, dbo.I10_Amcare_VR.Ancil15, dbo.I10_Amcare_VR.Ancil16, dbo.I10_Amcare_VR.Ancil17, dbo.I10_Amcare_VR.AncillaryField1, dbo.I10_Amcare_VR.AncillaryField1Desc, 
                         dbo.I10_Amcare_VR.AncillaryField10, dbo.I10_Amcare_VR.AncillaryField10Desc, dbo.I10_Amcare_VR.AncillaryField11, dbo.I10_Amcare_VR.AncillaryField11Desc, dbo.I10_Amcare_VR.AncillaryField12, 
                         dbo.I10_Amcare_VR.AncillaryField12Desc, dbo.I10_Amcare_VR.AncillaryField2, dbo.I10_Amcare_VR.AncillaryField2Desc, dbo.I10_Amcare_VR.AncillaryField3, dbo.I10_Amcare_VR.AncillaryField3Desc, 
                         dbo.I10_Amcare_VR.AncillaryField4, dbo.I10_Amcare_VR.AncillaryField4Desc, dbo.I10_Amcare_VR.AncillaryField5, dbo.I10_Amcare_VR.AncillaryField5Desc, dbo.I10_Amcare_VR.AncillaryField6, 
                         dbo.I10_Amcare_VR.AncillaryField6Desc, dbo.I10_Amcare_VR.AncillaryField7, dbo.I10_Amcare_VR.AncillaryField7Desc, dbo.I10_Amcare_VR.AncillaryField8, dbo.I10_Amcare_VR.AncillaryField8Desc, 
                         dbo.I10_Amcare_VR.AncillaryField9, dbo.I10_Amcare_VR.AncillaryField9Desc, dbo.I10_Amcare_VR.ArrivalDate, dbo.I10_Amcare_VR.ArrivalMode, dbo.I10_Amcare_VR.ArrivalModeDesc, 
                         dbo.I10_Amcare_VR.ArrivalTime, dbo.I10_Amcare_VR.ArrivaltoTriageTime, dbo.I10_Amcare_VR.AssessmentDate, dbo.I10_Amcare_VR.AssessmentTime, dbo.I10_Amcare_VR.AssessmentTimeUnknown, 
                         dbo.I10_Amcare_VR.AssessmentTimeUnknownDesc, dbo.I10_Amcare_VR.AttendingPhysician, dbo.I10_Amcare_VR.AttendingPhysicianDesc, dbo.I10_Amcare_VR.AutoTransfusion, 
                         dbo.I10_Amcare_VR.AutoTransfusionDesc, dbo.I10_Amcare_VR.AutopsyPerformed, dbo.I10_Amcare_VR.AutopsyPerformedDesc, dbo.I10_Amcare_VR.BasicOption1, dbo.I10_Amcare_VR.BasicOption1Desc, 
                         dbo.I10_Amcare_VR.BasicOption10, dbo.I10_Amcare_VR.BasicOption10Desc, dbo.I10_Amcare_VR.BasicOption11, dbo.I10_Amcare_VR.BasicOption11Desc, dbo.I10_Amcare_VR.BasicOption12, 
                         dbo.I10_Amcare_VR.BasicOption12Desc, dbo.I10_Amcare_VR.BasicOption13, dbo.I10_Amcare_VR.BasicOption13Desc, dbo.I10_Amcare_VR.BasicOption14, dbo.I10_Amcare_VR.BasicOption14Desc, 
                         dbo.I10_Amcare_VR.BasicOption15, dbo.I10_Amcare_VR.BasicOption15Desc, dbo.I10_Amcare_VR.BasicOption16, dbo.I10_Amcare_VR.BasicOption16Desc, dbo.I10_Amcare_VR.BasicOption17, 
                         dbo.I10_Amcare_VR.BasicOption17Desc, dbo.I10_Amcare_VR.BasicOption18, dbo.I10_Amcare_VR.BasicOption18Desc, dbo.I10_Amcare_VR.BasicOption19, dbo.I10_Amcare_VR.BasicOption19Desc, 
                         dbo.I10_Amcare_VR.BasicOption2, dbo.I10_Amcare_VR.BasicOption2Desc, dbo.I10_Amcare_VR.BasicOption3, dbo.I10_Amcare_VR.BasicOption3Desc, dbo.I10_Amcare_VR.BasicOption4, 
                         dbo.I10_Amcare_VR.BasicOption4Desc, dbo.I10_Amcare_VR.BasicOption5, dbo.I10_Amcare_VR.BasicOption5Desc, dbo.I10_Amcare_VR.BasicOption6, dbo.I10_Amcare_VR.BasicOption6Desc, 
                         dbo.I10_Amcare_VR.BasicOption7, dbo.I10_Amcare_VR.BasicOption7Desc, dbo.I10_Amcare_VR.BasicOption8, dbo.I10_Amcare_VR.BasicOption8Desc, dbo.I10_Amcare_VR.BasicOption9, 
                         dbo.I10_Amcare_VR.BasicOption9Desc, dbo.I10_Amcare_VR.BatchNumber, dbo.I10_Amcare_VR.BatchPeriod, dbo.I10_Amcare_VR.BatchPeriodDesc, dbo.I10_Amcare_VR.BatchPeriod_BC, 
                         dbo.I10_Amcare_VR.BatchYear, dbo.I10_Amcare_VR.BirthDate, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIII, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIIIDesc, 
						 dbo.I10_Amcare_VR.Blood_C1Inhibitor, 
                         dbo.I10_Amcare_VR.Blood_C1InhibitorDesc, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasma, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_CryosupernatantPlasma, 
                         dbo.I10_Amcare_VR.Blood_CryosupernatantPlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_FEIBA, 
						 dbo.I10_Amcare_VR.Blood_FEIBADesc, 
						 dbo.I10_Amcare_VR.Blood_Fibrinogen, 
						 dbo.I10_Amcare_VR.Blood_FibrinogenDesc, 
                         dbo.I10_Amcare_VR.Blood_IVIG_SCIG, 
						 dbo.I10_Amcare_VR.Blood_IVIG_SCIGDesc, 
						 dbo.I10_Amcare_VR.Blood_PCC, 
						 dbo.I10_Amcare_VR.Blood_PCCDesc, 
						 dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactors, 
                         dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactorsDesc, 
						 
						 dbo.I10_Amcare_VR.BreastFeeding, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlag, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlagDesc, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitDateIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknown, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknownDesc, dbo.I10_Amcare_VR.ClinicalDecisionUnitDateOut, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOut, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknown, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknownDesc, dbo.I10_Amcare_VR.ChangeinLegalStatus, 
                         dbo.I10_Amcare_VR.ChangeinLegalStatusDesc, dbo.I10_Amcare_VR.ChartNumber, dbo.I10_Amcare_VR.ChiefComplaint, dbo.I10_Amcare_VR.CoderNumber, dbo.I10_Amcare_VR.CoderNumberDesc, 
                         dbo.I10_Amcare_VR.CompleteRecord, dbo.I10_Amcare_VR.CompleteRecordDesc, dbo.I10_Amcare_VR.Complication, dbo.I10_Amcare_VR.ComplicationDesc, dbo.I10_Amcare_VR.Complication1, 
                         dbo.I10_Amcare_VR.Complication1Desc, dbo.I10_Amcare_VR.Complication2, dbo.I10_Amcare_VR.Complication2Desc, dbo.I10_Amcare_VR.Complication3, dbo.I10_Amcare_VR.Complication3Desc, 
                         dbo.I10_Amcare_VR.ContactMode, dbo.I10_Amcare_VR.ContactModeDesc, dbo.I10_Amcare_VR.CoronerCase, dbo.I10_Amcare_VR.CoronerCaseDesc, dbo.I10_Amcare_VR.DataEntryCoder, 
                         dbo.I10_Amcare_VR.DataEntryCoderDesc, dbo.I10_Amcare_VR.DateLeftER, dbo.I10_Amcare_VR.DateofLastMenses, dbo.I10_Amcare_VR.DateReadyforDisch, dbo.I10_Amcare_VR.DateSentToCIHI, 
                         dbo.I10_Amcare_VR.DateSentToCIHILevel1, dbo.I10_Amcare_VR.DateSentToCIHILevel2, dbo.I10_Amcare_VR.DateSentToCIHILite, dbo.I10_Amcare_VR.DeathInER, dbo.I10_Amcare_VR.DeathInERDesc, 
                         dbo.I10_Amcare_VR.DeathOnArrival, dbo.I10_Amcare_VR.DeathOnArrivalDesc, dbo.I10_Amcare_VR.DecisionAdmitDifference, dbo.I10_Amcare_VR.DecisiontoAdmitDate, dbo.I10_Amcare_VR.DecisiontoAdmitTime, 
                         dbo.I10_Amcare_VR.DecisionAdmitTimeUnknown, dbo.I10_Amcare_VR.DecisionAdmitTimeUnknownDesc, dbo.I10_Amcare_VR.DeliveryDate, dbo.I10_Amcare_VR.DeliveryTime, 
                         dbo.I10_Amcare_VR.DiedDuringIntervention, dbo.I10_Amcare_VR.DiedDuringInterventionDesc, dbo.I10_Amcare_VR.DischNursingArea, dbo.I10_Amcare_VR.DischNursingAreaDesc, 
                         dbo.I10_Amcare_VR.DischPlanning, dbo.I10_Amcare_VR.DischPlanningDesc, dbo.I10_Amcare_VR.DischargeAge, dbo.I10_Amcare_VR.DischargeDisposition, dbo.I10_Amcare_VR.DischargeDispositionDesc, 
                         dbo.I10_Amcare_VR.DispositionDate, dbo.I10_Amcare_VR.DispositionTime, dbo.I10_Amcare_VR.DispositionTimeUnknown, dbo.I10_Amcare_VR.DispositionTimeUnknownDesc, dbo.I10_Amcare_VR.ECTTreatment, 
                         dbo.I10_Amcare_VR.ECTTreatmentDesc, dbo.I10_Amcare_VR.Education, dbo.I10_Amcare_VR.EducationDesc, dbo.I10_Amcare_VR.EDVisitIndicator, dbo.I10_Amcare_VR.EDVisitIndicatorDesc, 
                         dbo.I10_Amcare_VR.Employment, dbo.I10_Amcare_VR.EmploymentDesc, dbo.I10_Amcare_VR.EntryCode, dbo.I10_Amcare_VR.EstimateDischDate, dbo.I10_Amcare_VR.ExitCode, 
                         dbo.I10_Amcare_VR.FamilyPhysicianFlag, dbo.I10_Amcare_VR.FamilyPhysicianFlagDesc, dbo.I10_Amcare_VR.FinancialSupport, dbo.I10_Amcare_VR.FinancialSupportDesc, dbo.I10_Amcare_VR.FinishDate, 
                         dbo.I10_Amcare_VR.FinishTime, dbo.I10_Amcare_VR.FirstName, dbo.I10_Amcare_VR.FullName, dbo.I10_Amcare_VR.FixedChartNumber, dbo.I10_Amcare_VR.Gender, dbo.I10_Amcare_VR.GenderDesc, 
                         dbo.I10_Amcare_VR.GestationalAgeinweeks, dbo.I10_Amcare_VR.GlasgowScale, dbo.I10_Amcare_VR.GlasgowScaleDesc, dbo.I10_Amcare_VR.GreaterTenPO, dbo.I10_Amcare_VR.HCNProvince, 
                         dbo.I10_Amcare_VR.HCNProvinceDesc, dbo.I10_Amcare_VR.HCNVersion, dbo.I10_Amcare_VR.HealthCareNumber, dbo.I10_Amcare_VR.Hospital, dbo.I10_Amcare_VR.HospitalDesc, 
                         dbo.I10_Amcare_VR.HospitalAccountRecord,
                         dbo.I10_Amcare_VR.HelmetIndicator, dbo.I10_Amcare_VR.HelmetIndicatorDesc, dbo.I10_Amcare_VR.InSCU, dbo.I10_Amcare_VR.InitialOR, dbo.I10_Amcare_VR.InitialORDesc, dbo.I10_Amcare_VR.InjuryDate, 
                         dbo.I10_Amcare_VR.Injury, dbo.I10_Amcare_VR.InjuryDesc, dbo.I10_Amcare_VR.InputDate, dbo.I10_Amcare_VR.InputTime, 

						 dbo.I10_Amcare_VR.InstitutionFrom, dbo.I10_Amcare_VR.InstitutionFromDesc, 
						 dbo.I10_Amcare_VR.InstitutionFromType, dbo.I10_Amcare_VR.InstitutionFromTypeDesc,
                         dbo.I10_Amcare_VR.InstFromCareType, dbo.I10_Amcare_VR.InstFromHospType, 
						 dbo.I10_Amcare_VR.InstitutionNumber, dbo.I10_Amcare_VR.InstitutionNumberDesc, 
						 dbo.I10_Amcare_VR.InstitutionTo, dbo.I10_Amcare_VR.InstitutionToDesc, 
						 dbo.I10_Amcare_VR.InstToCareType, dbo.I10_Amcare_VR.InstToHospType, 
						 dbo.I10_Amcare_VR.InstitutionToType, dbo.I10_Amcare_VR.InstitutionToTypeDesc, 
						 
						 dbo.I10_Amcare_VR.InterfaceDate, dbo.I10_Amcare_VR.InterfaceTime, 
                         dbo.I10_Amcare_VR.IsAbstractCompleted, dbo.I10_Amcare_VR.IsAbstractCompletedDesc, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCompletedLevel2, dbo.I10_Amcare_VR.IsAbstractCompletedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCompletedLite, dbo.I10_Amcare_VR.IsAbstractCompletedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrected, dbo.I10_Amcare_VR.IsAbstractCorrectedDesc, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCorrectedLite, dbo.I10_Amcare_VR.IsAbstractCorrectedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractDeleted, dbo.I10_Amcare_VR.IsAbstractDeletedDesc, dbo.I10_Amcare_VR.IsAbstractSubmitted, dbo.I10_Amcare_VR.IsAbstractSubmittedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLite, dbo.I10_Amcare_VR.IsAbstractSubmittedLiteDesc, dbo.I10_Amcare_VR.IsAbstractValidated, dbo.I10_Amcare_VR.IsAbstractValidatedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLevel1, dbo.I10_Amcare_VR.IsAbstractValidatedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLite, dbo.I10_Amcare_VR.IsAbstractValidatedLiteDesc, dbo.I10_Amcare_VR.IsBirthdateEstimated, dbo.I10_Amcare_VR.IsBirthdateEstimatedDesc, 
						 dbo.I10_Amcare_VR.IsCustomValidated, dbo.I10_Amcare_VR.IsCustomValidatedDesc,
                         dbo.I10_Amcare_VR.LOSDays, dbo.I10_Amcare_VR.LOSTime, dbo.I10_Amcare_VR.LOSTimeinHours, dbo.I10_Amcare_VR.LOSTotalMinutes, dbo.I10_Amcare_VR.Language, dbo.I10_Amcare_VR.LanguageDesc, 
                         dbo.I10_Amcare_VR.LastName, dbo.I10_Amcare_VR.LessTwoPO, dbo.I10_Amcare_VR.LivingArrangement, dbo.I10_Amcare_VR.LivingArrangementDesc, dbo.I10_Amcare_VR.LocationofInjury, 
                         dbo.I10_Amcare_VR.LocationofInjuryDesc, dbo.I10_Amcare_VR.MISCode, dbo.I10_Amcare_VR.MISCodeDesc, dbo.I10_Amcare_VR.MaidenName, dbo.I10_Amcare_VR.MaritalStatus, 
                         dbo.I10_Amcare_VR.MaritalStatusDesc, 
                         dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoED, 
						 dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01Desc,                          
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04Desc, 

						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04Desc, 
						 
						 dbo.I10_Amcare_VR.MethodofAdmission, dbo.I10_Amcare_VR.MethodofAdmissionDesc, dbo.I10_Amcare_VR.MiddleName, 
                         dbo.I10_Amcare_VR.NACRSClinicLiteSubmission, dbo.I10_Amcare_VR.NACRSClinicLiteSubmissionDesc, 
                         dbo.I10_Amcare_VR.NewbornChart, 
                         dbo.I10_Amcare_VR.NewbornDischDate, dbo.I10_Amcare_VR.NextScheduledVisitDate, dbo.I10_Amcare_VR.NextScheduledVisitTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentDate, 
                         dbo.I10_Amcare_VR.NonPhysicianAssessmentTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknown, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.NonPhysicianNumber, dbo.I10_Amcare_VR.NonPhysicianNumberDesc, dbo.I10_Amcare_VR.NonPhysicianService, dbo.I10_Amcare_VR.NonPhysicianServiceDesc, 
                         dbo.I10_Amcare_VR.NumberofECT, dbo.I10_Amcare_VR.NursingAssessmentDate, dbo.I10_Amcare_VR.NursingAssessmentTime, dbo.I10_Amcare_VR.Occupation, dbo.I10_Amcare_VR.OccupationDesc, 
                         dbo.I10_Amcare_VR.OtherMedicalDeath, dbo.I10_Amcare_VR.OtherMedicalDeathDesc, dbo.I10_Amcare_VR.OtherBlood, dbo.I10_Amcare_VR.OtherBloodDesc, dbo.I10_Amcare_VR.OtherBloodCrossMatched, 
                         dbo.I10_Amcare_VR.OtherBloodCrossMatchedDesc, dbo.I10_Amcare_VR.OtherBloodTyped, dbo.I10_Amcare_VR.OtherBloodTypedDesc, dbo.I10_Amcare_VR.OtherBloodUnits, dbo.I10_Amcare_VR.PCTASIndicator, 
                         dbo.I10_Amcare_VR.PCTASIndicatorDesc, dbo.I10_Amcare_VR.PhysicianEstLOS, dbo.I10_Amcare_VR.Plasma, dbo.I10_Amcare_VR.PlasmaDesc, dbo.I10_Amcare_VR.PlasmaCrossMatched, 
                         dbo.I10_Amcare_VR.PlasmaCrossMatchedDesc, dbo.I10_Amcare_VR.PlasmaTyped, dbo.I10_Amcare_VR.PlasmaTypedDesc, dbo.I10_Amcare_VR.PlasmaUnits, dbo.I10_Amcare_VR.Platelets, 
                         dbo.I10_Amcare_VR.PlateletsDesc, dbo.I10_Amcare_VR.PlateletsCrossMatched, dbo.I10_Amcare_VR.PlateletsCrossMatchedDesc, dbo.I10_Amcare_VR.PlateletsTyped, dbo.I10_Amcare_VR.PlateletsTypedDesc, 
                         dbo.I10_Amcare_VR.PlateletsUnits, dbo.I10_Amcare_VR.PostalCode, dbo.I10_Amcare_VR.PostalCodeDesc, dbo.I10_Amcare_VR.PostOpDays, dbo.I10_Amcare_VR.PreOpDays, 
                         dbo.I10_Amcare_VR.PreamditWorkUp, dbo.I10_Amcare_VR.PreamditWorkUpDesc, dbo.I10_Amcare_VR.Pregnancy, dbo.I10_Amcare_VR.PregnancyDesc, dbo.I10_Amcare_VR.PrevLiveBirth, 
                         dbo.I10_Amcare_VR.PreviousPsychiartricAdmissions, dbo.I10_Amcare_VR.PreviousPsychiartricAdmDesc, dbo.I10_Amcare_VR.Program, dbo.I10_Amcare_VR.ProgramDesc, dbo.I10_Amcare_VR.ProvinceNumber, 
                         dbo.I10_Amcare_VR.ProvinceNumberDesc, dbo.I10_Amcare_VR.ReasonForVisit, dbo.I10_Amcare_VR.ReasonForVisitDesc, dbo.I10_Amcare_VR.ReAdmitCode, dbo.I10_Amcare_VR.ReciprocalBillingStatus, 
                         dbo.I10_Amcare_VR.ReciprocalBillingStatusDesc, dbo.I10_Amcare_VR.RedBloodCell, dbo.I10_Amcare_VR.RedBloodCellDesc, dbo.I10_Amcare_VR.RedBloodCellCrossMatched, 
                         dbo.I10_Amcare_VR.RedBloodCellCrossMatchedDesc, dbo.I10_Amcare_VR.RedBloodCellTyped, dbo.I10_Amcare_VR.RedBloodCellTypedDesc, dbo.I10_Amcare_VR.RedBloodCellUnits, 
                         dbo.I10_Amcare_VR.ReferralDate, dbo.I10_Amcare_VR.ReferredFrom, dbo.I10_Amcare_VR.ReferredFromDesc, dbo.I10_Amcare_VR.ReferredTo, dbo.I10_Amcare_VR.ReferredToDesc, 
                         dbo.I10_Amcare_VR.ReferringProvider, dbo.I10_Amcare_VR.ReferringProviderDesc, dbo.I10_Amcare_VR.RegisterNumber, dbo.I10_Amcare_VR.RegistrationNumber, 
                         dbo.I10_Amcare_VR.RegistrationSequenceNumber, dbo.I10_Amcare_VR.RegistrationVisitDate, dbo.I10_Amcare_VR.RegistrationVisitTime, dbo.I10_Amcare_VR.ReproductiveCareComments, 
                         dbo.I10_Amcare_VR.ReserveField, dbo.I10_Amcare_VR.ResidenceCode, dbo.I10_Amcare_VR.ResidenceCodeDesc, dbo.I10_Amcare_VR.ResidenceProvince, dbo.I10_Amcare_VR.ResidenceProvinceDesc, 
                         dbo.I10_Amcare_VR.ResidenceRegion, dbo.I10_Amcare_VR.ResidenceRegionDesc, dbo.I10_Amcare_VR.ResidenceType, dbo.I10_Amcare_VR.ResidenceTypeDesc, dbo.I10_Amcare_VR.ResponsiblityForPayment,
                          dbo.I10_Amcare_VR.ResponsiblityForPaymentDesc, dbo.I10_Amcare_VR.SchedEDVisit, dbo.I10_Amcare_VR.SchedEDVisitDesc, dbo.I10_Amcare_VR.SeatbeltIndicator, dbo.I10_Amcare_VR.SeatbeltIndicatorDesc, 
                         dbo.I10_Amcare_VR.SecondChartRegisterNumber, dbo.I10_Amcare_VR.SecretVIPPatient, dbo.I10_Amcare_VR.SecretVIPPatientDesc, dbo.I10_Amcare_VR.SiteNumber, dbo.I10_Amcare_VR.SiteNumberDesc, 
                         dbo.I10_Amcare_VR.SocialService, dbo.I10_Amcare_VR.SocialServiceDesc, dbo.I10_Amcare_VR.SourceofReferral, dbo.I10_Amcare_VR.SourceofReferralDesc, dbo.I10_Amcare_VR.SpecialistNumber, 
                         dbo.I10_Amcare_VR.SpecialistNumberDesc, dbo.I10_Amcare_VR.SpecialistRequestDate, dbo.I10_Amcare_VR.SpecialistRequestService, dbo.I10_Amcare_VR.SpecialistRequestServiceDesc, 
                         dbo.I10_Amcare_VR.SpecialistRequestTime, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknown, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknownDesc, dbo.I10_Amcare_VR.StakeholderType, 
                         dbo.I10_Amcare_VR.StakeholderTypeDesc, dbo.I10_Amcare_VR.StatusAfterTriage, dbo.I10_Amcare_VR.StatusAfterTriageDesc, dbo.I10_Amcare_VR.Sterilization, dbo.I10_Amcare_VR.SterilizationDesc, 
                         dbo.I10_Amcare_VR.SubmissionLevelCode, dbo.I10_Amcare_VR.SubmissionRecordID, dbo.I10_Amcare_VR.SubsequentOR, dbo.I10_Amcare_VR.SubsequentORDesc, dbo.I10_Amcare_VR.Suicide, 
                         dbo.I10_Amcare_VR.SuicideDesc, dbo.I10_Amcare_VR.SurgicalCase, dbo.I10_Amcare_VR.SurgicalCaseDesc, dbo.I10_Amcare_VR.TimeLeftER, dbo.I10_Amcare_VR.TimeLeftERUnknown, 
                         dbo.I10_Amcare_VR.TimeLeftERUnknownDEsc, dbo.I10_Amcare_VR.TransferOverloadDate, dbo.I10_Amcare_VR.TransferOverloadTime, dbo.I10_Amcare_VR.TransferOverloadTimeDifference, 
                         dbo.I10_Amcare_VR.TransfusionGiven, dbo.I10_Amcare_VR.TransfusionGivenDesc, dbo.I10_Amcare_VR.Trauma, dbo.I10_Amcare_VR.TraumaDesc, dbo.I10_Amcare_VR.TriageDate, 
                         dbo.I10_Amcare_VR.TriageLevel, dbo.I10_Amcare_VR.TriageLevelDesc, dbo.I10_Amcare_VR.TriageTime, dbo.I10_Amcare_VR.TriageTimeUnknown, dbo.I10_Amcare_VR.TriageTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.TSICoder, dbo.I10_Amcare_VR.TSICoderDesc, dbo.I10_Amcare_VR.TSIDate, dbo.I10_Amcare_VR.TSITime, dbo.I10_Amcare_VR.TwoTenPO, dbo.I10_Amcare_VR.ULI, 
                         dbo.I10_Amcare_VR.UniversalEpisodeIdentifier, dbo.I10_Amcare_VR.UnplannedReadmit, dbo.I10_Amcare_VR.VisitStatus, dbo.I10_Amcare_VR.VisitStatusDesc, dbo.I10_Amcare_VR.VisitType, dbo.I10_Amcare_VR.VisitTypeDesc, 
                         dbo.I10_Amcare_VR.WaitTimeinER, dbo.I10_Amcare_VR.WaittoAssessmentinMinutes, dbo.I10_Amcare_VR.WaittoNursingAssessmentDiff, dbo.I10_Amcare_VR.Weight, dbo.I10_Amcare_VR.zzAbstractLink, 
                         dbo.I10_Amcare_VR.zzRegionalPatientID, dbo.I10_Amcare_VR.zzVolumeLink, 
						 dbo.I10_Amcare_Projects_100_VR.ProjectNumber, dbo.I10_Amcare_Projects_100_VR.ProjectNumberDesc, 
                         dbo.I10_Amcare_Projects_100_VR.ProjectOccurrence, dbo.I10_Amcare_Projects_100_VR.CompleteRecordFlag, dbo.I10_Amcare_Projects_100_VR.CompleteRecordFlagDesc, 
                         dbo.I10_Amcare_Projects_100_VR.RecordAvailable, dbo.I10_Amcare_Projects_100_VR.RecordAvailableDesc, dbo.I10_Amcare_Projects_100_VR.OperativeReportAvailable, 
                         dbo.I10_Amcare_Projects_100_VR.OperativeReportAvailableDesc, dbo.I10_Amcare_Projects_100_VR.RecordSubsequentlyReviewedAfterCompletion, 
                         dbo.I10_Amcare_Projects_100_VR.RecordSubsequentlyReviewedAfterCompletionDesc, dbo.I10_Amcare_Projects_100_VR.DataChangedFromOriginalSubmission, 
                         dbo.I10_Amcare_Projects_100_VR.DataChangedFromOriginalSubmissionDesc, dbo.I10_Amcare_Projects_100_VR.PathologyReportAvailable, dbo.I10_Amcare_Projects_100_VR.PathologyReportAvailableDesc, 
                         dbo.I10_Amcare_Projects_100_VR.DateofSubsequentReview, dbo.I10_Amcare_Projects_100_VR.DateofSubsequentReview_InValidate
FROM            dbo.I10_Amcare_VR INNER JOIN
                         dbo.I10_Amcare_Projects_100_VR ON dbo.I10_Amcare_VR.zzAbstractLink = dbo.I10_Amcare_Projects_100_VR.zzAbstractLink







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Project_150_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE view [dbo].[I10_Amcare_And_Project_150_VR]
as
SELECT        dbo.I10_Amcare_VR.[#ofPreviousPreTermDeliveries], dbo.I10_Amcare_VR.[#ofPrevSpontaneousAbortions], dbo.I10_Amcare_VR.[#ofPreviousTermDeliveries], dbo.I10_Amcare_VR.AccessPrimaryHealthCareCode, 
                         dbo.I10_Amcare_VR.AccessPrimaryHealthCareCodeDesc, dbo.I10_Amcare_VR.AmbulanceArrivalDate, dbo.I10_Amcare_VR.AmbulanceArrivalTime, dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknown, 
                         dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknownDesc, dbo.I10_Amcare_VR.AmbulanceTransferCareDate, dbo.I10_Amcare_VR.AmbulanceTransferCareTime, 
                         dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknown, dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknownDesc, dbo.I10_Amcare_VR.[#ofPrevTherapeuticAbortions], dbo.I10_Amcare_VR.AWOL, 
                         dbo.I10_Amcare_VR.AWOLDesc, dbo.I10_Amcare_VR.AbortDate, dbo.I10_Amcare_VR.AbstractNumber, dbo.I10_Amcare_VR.AbstractOverflow, dbo.I10_Amcare_VR.AbstractOverflowDesc, 
                         dbo.I10_Amcare_VR.ActivityDescription, dbo.I10_Amcare_VR.ActivityWhenInjured, dbo.I10_Amcare_VR.ActivityWhenInjuredDesc, dbo.I10_Amcare_VR.ActueLOS, dbo.I10_Amcare_VR.AdmitbyAmbulance, 
                         dbo.I10_Amcare_VR.AdmitbyAmbulanceDesc, dbo.I10_Amcare_VR.AdmitCategory, dbo.I10_Amcare_VR.AdmitDiagnosis, dbo.I10_Amcare_VR.AdmitNursingArea, dbo.I10_Amcare_VR.AdmitNursingAreaDesc, 
                         dbo.I10_Amcare_VR.AfterAdmit, dbo.I10_Amcare_VR.AgeCode, dbo.I10_Amcare_VR.AgeCodeDesc, dbo.I10_Amcare_VR.AgeGroup, dbo.I10_Amcare_VR.AgeNumber, dbo.I10_Amcare_VR.Albumin, 
                         dbo.I10_Amcare_VR.AlbuminDesc, dbo.I10_Amcare_VR.AlbuminCrossMatched, dbo.I10_Amcare_VR.AlbuminCrossMatchedDesc, dbo.I10_Amcare_VR.AlbuminTyped, dbo.I10_Amcare_VR.AlbuminTypedDesc, 
                         dbo.I10_Amcare_VR.AlbuminUnits, dbo.I10_Amcare_VR.ALCLOS, dbo.I10_Amcare_VR.AmbulanceReportNumber, dbo.I10_Amcare_VR.AmCareGroup, dbo.I10_Amcare_VR.AmCareGroupDesc, 
                         dbo.I10_Amcare_VR.AmcareCareType, dbo.I10_Amcare_VR.AmcareCareTypeDesc, dbo.I10_Amcare_VR.AmcareTypeCode, dbo.I10_Amcare_VR.AmcareTypeCodeDesc, dbo.I10_Amcare_VR.Ancil13, 
                         dbo.I10_Amcare_VR.Ancil14, dbo.I10_Amcare_VR.Ancil15, dbo.I10_Amcare_VR.Ancil16, dbo.I10_Amcare_VR.Ancil17, dbo.I10_Amcare_VR.AncillaryField1, dbo.I10_Amcare_VR.AncillaryField1Desc, 
                         dbo.I10_Amcare_VR.AncillaryField10, dbo.I10_Amcare_VR.AncillaryField10Desc, dbo.I10_Amcare_VR.AncillaryField11, dbo.I10_Amcare_VR.AncillaryField11Desc, dbo.I10_Amcare_VR.AncillaryField12, 
                         dbo.I10_Amcare_VR.AncillaryField12Desc, dbo.I10_Amcare_VR.AncillaryField2, dbo.I10_Amcare_VR.AncillaryField2Desc, dbo.I10_Amcare_VR.AncillaryField3, dbo.I10_Amcare_VR.AncillaryField3Desc, 
                         dbo.I10_Amcare_VR.AncillaryField4, dbo.I10_Amcare_VR.AncillaryField4Desc, dbo.I10_Amcare_VR.AncillaryField5, dbo.I10_Amcare_VR.AncillaryField5Desc, dbo.I10_Amcare_VR.AncillaryField6, 
                         dbo.I10_Amcare_VR.AncillaryField6Desc, dbo.I10_Amcare_VR.AncillaryField7, dbo.I10_Amcare_VR.AncillaryField7Desc, dbo.I10_Amcare_VR.AncillaryField8, dbo.I10_Amcare_VR.AncillaryField8Desc, 
                         dbo.I10_Amcare_VR.AncillaryField9, dbo.I10_Amcare_VR.AncillaryField9Desc, dbo.I10_Amcare_VR.ArrivalDate, dbo.I10_Amcare_VR.ArrivalMode, dbo.I10_Amcare_VR.ArrivalModeDesc, 
                         dbo.I10_Amcare_VR.ArrivalTime, dbo.I10_Amcare_VR.ArrivaltoTriageTime, dbo.I10_Amcare_VR.AssessmentDate, dbo.I10_Amcare_VR.AssessmentTime, dbo.I10_Amcare_VR.AssessmentTimeUnknown, 
                         dbo.I10_Amcare_VR.AssessmentTimeUnknownDesc, dbo.I10_Amcare_VR.AttendingPhysician, dbo.I10_Amcare_VR.AttendingPhysicianDesc, dbo.I10_Amcare_VR.AutoTransfusion, 
                         dbo.I10_Amcare_VR.AutoTransfusionDesc, dbo.I10_Amcare_VR.AutopsyPerformed, dbo.I10_Amcare_VR.AutopsyPerformedDesc, dbo.I10_Amcare_VR.BasicOption1, dbo.I10_Amcare_VR.BasicOption1Desc, 
                         dbo.I10_Amcare_VR.BasicOption10, dbo.I10_Amcare_VR.BasicOption10Desc, dbo.I10_Amcare_VR.BasicOption11, dbo.I10_Amcare_VR.BasicOption11Desc, dbo.I10_Amcare_VR.BasicOption12, 
                         dbo.I10_Amcare_VR.BasicOption12Desc, dbo.I10_Amcare_VR.BasicOption13, dbo.I10_Amcare_VR.BasicOption13Desc, dbo.I10_Amcare_VR.BasicOption14, dbo.I10_Amcare_VR.BasicOption14Desc, 
                         dbo.I10_Amcare_VR.BasicOption15, dbo.I10_Amcare_VR.BasicOption15Desc, dbo.I10_Amcare_VR.BasicOption16, dbo.I10_Amcare_VR.BasicOption16Desc, dbo.I10_Amcare_VR.BasicOption17, 
                         dbo.I10_Amcare_VR.BasicOption17Desc, dbo.I10_Amcare_VR.BasicOption18, dbo.I10_Amcare_VR.BasicOption18Desc, dbo.I10_Amcare_VR.BasicOption19, dbo.I10_Amcare_VR.BasicOption19Desc, 
                         dbo.I10_Amcare_VR.BasicOption2, dbo.I10_Amcare_VR.BasicOption2Desc, dbo.I10_Amcare_VR.BasicOption3, dbo.I10_Amcare_VR.BasicOption3Desc, dbo.I10_Amcare_VR.BasicOption4, 
                         dbo.I10_Amcare_VR.BasicOption4Desc, dbo.I10_Amcare_VR.BasicOption5, dbo.I10_Amcare_VR.BasicOption5Desc, dbo.I10_Amcare_VR.BasicOption6, dbo.I10_Amcare_VR.BasicOption6Desc, 
                         dbo.I10_Amcare_VR.BasicOption7, dbo.I10_Amcare_VR.BasicOption7Desc, dbo.I10_Amcare_VR.BasicOption8, dbo.I10_Amcare_VR.BasicOption8Desc, dbo.I10_Amcare_VR.BasicOption9, 
                         dbo.I10_Amcare_VR.BasicOption9Desc, dbo.I10_Amcare_VR.BatchNumber, dbo.I10_Amcare_VR.BatchPeriod, dbo.I10_Amcare_VR.BatchPeriodDesc, dbo.I10_Amcare_VR.BatchPeriod_BC, 
                         dbo.I10_Amcare_VR.BatchYear, dbo.I10_Amcare_VR.BirthDate, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIII, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIIIDesc, 
						 dbo.I10_Amcare_VR.Blood_C1Inhibitor, 
                         dbo.I10_Amcare_VR.Blood_C1InhibitorDesc, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasma, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_CryosupernatantPlasma, 
                         dbo.I10_Amcare_VR.Blood_CryosupernatantPlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_FEIBA, 
						 dbo.I10_Amcare_VR.Blood_FEIBADesc, 
						 dbo.I10_Amcare_VR.Blood_Fibrinogen, 
						 dbo.I10_Amcare_VR.Blood_FibrinogenDesc, 
                         dbo.I10_Amcare_VR.Blood_IVIG_SCIG, 
						 dbo.I10_Amcare_VR.Blood_IVIG_SCIGDesc, 
						 dbo.I10_Amcare_VR.Blood_PCC, 
						 dbo.I10_Amcare_VR.Blood_PCCDesc, 
						 dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactors, 
                         dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactorsDesc, 
						 
						 dbo.I10_Amcare_VR.BreastFeeding, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlag, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlagDesc, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitDateIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknown, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknownDesc, dbo.I10_Amcare_VR.ClinicalDecisionUnitDateOut, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOut, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknown, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknownDesc, dbo.I10_Amcare_VR.ChangeinLegalStatus, 
                         dbo.I10_Amcare_VR.ChangeinLegalStatusDesc, dbo.I10_Amcare_VR.ChartNumber, dbo.I10_Amcare_VR.ChiefComplaint, dbo.I10_Amcare_VR.CoderNumber, dbo.I10_Amcare_VR.CoderNumberDesc, 
                         dbo.I10_Amcare_VR.CompleteRecord, dbo.I10_Amcare_VR.CompleteRecordDesc, dbo.I10_Amcare_VR.Complication, dbo.I10_Amcare_VR.ComplicationDesc, dbo.I10_Amcare_VR.Complication1, 
                         dbo.I10_Amcare_VR.Complication1Desc, dbo.I10_Amcare_VR.Complication2, dbo.I10_Amcare_VR.Complication2Desc, dbo.I10_Amcare_VR.Complication3, dbo.I10_Amcare_VR.Complication3Desc, 
                         dbo.I10_Amcare_VR.ContactMode, dbo.I10_Amcare_VR.ContactModeDesc, dbo.I10_Amcare_VR.CoronerCase, dbo.I10_Amcare_VR.CoronerCaseDesc, dbo.I10_Amcare_VR.DataEntryCoder, 
                         dbo.I10_Amcare_VR.DataEntryCoderDesc, dbo.I10_Amcare_VR.DateLeftER, dbo.I10_Amcare_VR.DateofLastMenses, dbo.I10_Amcare_VR.DateReadyforDisch, dbo.I10_Amcare_VR.DateSentToCIHI, 
                         dbo.I10_Amcare_VR.DateSentToCIHILevel1, dbo.I10_Amcare_VR.DateSentToCIHILevel2, dbo.I10_Amcare_VR.DateSentToCIHILite, dbo.I10_Amcare_VR.DeathInER, dbo.I10_Amcare_VR.DeathInERDesc, 
                         dbo.I10_Amcare_VR.DeathOnArrival, dbo.I10_Amcare_VR.DeathOnArrivalDesc, dbo.I10_Amcare_VR.DecisionAdmitDifference, dbo.I10_Amcare_VR.DecisiontoAdmitDate, dbo.I10_Amcare_VR.DecisiontoAdmitTime, 
                         dbo.I10_Amcare_VR.DecisionAdmitTimeUnknown, dbo.I10_Amcare_VR.DecisionAdmitTimeUnknownDesc, dbo.I10_Amcare_VR.DeliveryDate, dbo.I10_Amcare_VR.DeliveryTime, 
                         dbo.I10_Amcare_VR.DiedDuringIntervention, dbo.I10_Amcare_VR.DiedDuringInterventionDesc, dbo.I10_Amcare_VR.DischNursingArea, dbo.I10_Amcare_VR.DischNursingAreaDesc, 
                         dbo.I10_Amcare_VR.DischPlanning, dbo.I10_Amcare_VR.DischPlanningDesc, dbo.I10_Amcare_VR.DischargeAge, dbo.I10_Amcare_VR.DischargeDisposition, dbo.I10_Amcare_VR.DischargeDispositionDesc, 
                         dbo.I10_Amcare_VR.DispositionDate, dbo.I10_Amcare_VR.DispositionTime, dbo.I10_Amcare_VR.DispositionTimeUnknown, dbo.I10_Amcare_VR.DispositionTimeUnknownDesc, dbo.I10_Amcare_VR.ECTTreatment, 
                         dbo.I10_Amcare_VR.ECTTreatmentDesc, dbo.I10_Amcare_VR.Education, dbo.I10_Amcare_VR.EducationDesc, dbo.I10_Amcare_VR.EDVisitIndicator, dbo.I10_Amcare_VR.EDVisitIndicatorDesc, 
                         dbo.I10_Amcare_VR.Employment, dbo.I10_Amcare_VR.EmploymentDesc, dbo.I10_Amcare_VR.EntryCode, dbo.I10_Amcare_VR.EstimateDischDate, dbo.I10_Amcare_VR.ExitCode, 
                         dbo.I10_Amcare_VR.FamilyPhysicianFlag, dbo.I10_Amcare_VR.FamilyPhysicianFlagDesc, dbo.I10_Amcare_VR.FinancialSupport, dbo.I10_Amcare_VR.FinancialSupportDesc, dbo.I10_Amcare_VR.FinishDate, 
                         dbo.I10_Amcare_VR.FinishTime, dbo.I10_Amcare_VR.FirstName, dbo.I10_Amcare_VR.FullName, dbo.I10_Amcare_VR.FixedChartNumber, dbo.I10_Amcare_VR.Gender, dbo.I10_Amcare_VR.GenderDesc, 
                         dbo.I10_Amcare_VR.GestationalAgeinweeks, dbo.I10_Amcare_VR.GlasgowScale, dbo.I10_Amcare_VR.GlasgowScaleDesc, dbo.I10_Amcare_VR.GreaterTenPO, dbo.I10_Amcare_VR.HCNProvince, 
                         dbo.I10_Amcare_VR.HCNProvinceDesc, dbo.I10_Amcare_VR.HCNVersion, dbo.I10_Amcare_VR.HealthCareNumber, dbo.I10_Amcare_VR.Hospital, dbo.I10_Amcare_VR.HospitalDesc, 
                         dbo.I10_Amcare_VR.HospitalAccountRecord,
                         dbo.I10_Amcare_VR.HelmetIndicator, dbo.I10_Amcare_VR.HelmetIndicatorDesc, dbo.I10_Amcare_VR.InSCU, dbo.I10_Amcare_VR.InitialOR, dbo.I10_Amcare_VR.InitialORDesc, dbo.I10_Amcare_VR.InjuryDate, 
                         dbo.I10_Amcare_VR.Injury, dbo.I10_Amcare_VR.InjuryDesc, dbo.I10_Amcare_VR.InputDate, dbo.I10_Amcare_VR.InputTime, 

						 dbo.I10_Amcare_VR.InstitutionFrom, dbo.I10_Amcare_VR.InstitutionFromDesc, 
						 dbo.I10_Amcare_VR.InstitutionFromType, dbo.I10_Amcare_VR.InstitutionFromTypeDesc,
                         dbo.I10_Amcare_VR.InstFromCareType, dbo.I10_Amcare_VR.InstFromHospType, 
						 dbo.I10_Amcare_VR.InstitutionNumber, dbo.I10_Amcare_VR.InstitutionNumberDesc, 
						 dbo.I10_Amcare_VR.InstitutionTo, dbo.I10_Amcare_VR.InstitutionToDesc, 
						 dbo.I10_Amcare_VR.InstToCareType, dbo.I10_Amcare_VR.InstToHospType, 
						 dbo.I10_Amcare_VR.InstitutionToType, dbo.I10_Amcare_VR.InstitutionToTypeDesc, 
						 
						 dbo.I10_Amcare_VR.InterfaceDate, dbo.I10_Amcare_VR.InterfaceTime, 
                         dbo.I10_Amcare_VR.IsAbstractCompleted, dbo.I10_Amcare_VR.IsAbstractCompletedDesc, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCompletedLevel2, dbo.I10_Amcare_VR.IsAbstractCompletedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCompletedLite, dbo.I10_Amcare_VR.IsAbstractCompletedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrected, dbo.I10_Amcare_VR.IsAbstractCorrectedDesc, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCorrectedLite, dbo.I10_Amcare_VR.IsAbstractCorrectedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractDeleted, dbo.I10_Amcare_VR.IsAbstractDeletedDesc, dbo.I10_Amcare_VR.IsAbstractSubmitted, dbo.I10_Amcare_VR.IsAbstractSubmittedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLite, dbo.I10_Amcare_VR.IsAbstractSubmittedLiteDesc, dbo.I10_Amcare_VR.IsAbstractValidated, dbo.I10_Amcare_VR.IsAbstractValidatedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLevel1, dbo.I10_Amcare_VR.IsAbstractValidatedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLite, dbo.I10_Amcare_VR.IsAbstractValidatedLiteDesc, dbo.I10_Amcare_VR.IsBirthdateEstimated, dbo.I10_Amcare_VR.IsBirthdateEstimatedDesc, 
						 dbo.I10_Amcare_VR.IsCustomValidated, dbo.I10_Amcare_VR.IsCustomValidatedDesc,
                         dbo.I10_Amcare_VR.LOSDays, dbo.I10_Amcare_VR.LOSTime, dbo.I10_Amcare_VR.LOSTimeinHours, dbo.I10_Amcare_VR.LOSTotalMinutes, dbo.I10_Amcare_VR.Language, dbo.I10_Amcare_VR.LanguageDesc, 
                         dbo.I10_Amcare_VR.LastName, dbo.I10_Amcare_VR.LessTwoPO, dbo.I10_Amcare_VR.LivingArrangement, dbo.I10_Amcare_VR.LivingArrangementDesc, dbo.I10_Amcare_VR.LocationofInjury, 
                         dbo.I10_Amcare_VR.LocationofInjuryDesc, dbo.I10_Amcare_VR.MISCode, dbo.I10_Amcare_VR.MISCodeDesc, dbo.I10_Amcare_VR.MaidenName, dbo.I10_Amcare_VR.MaritalStatus, 
                         dbo.I10_Amcare_VR.MaritalStatusDesc, 
                         dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoED, 
						 dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04Desc, 
						 
						 dbo.I10_Amcare_VR.MethodofAdmission, dbo.I10_Amcare_VR.MethodofAdmissionDesc, dbo.I10_Amcare_VR.MiddleName, 
                         dbo.I10_Amcare_VR.NACRSClinicLiteSubmission, dbo.I10_Amcare_VR.NACRSClinicLiteSubmissionDesc, 
                         dbo.I10_Amcare_VR.NewbornChart, 
                         dbo.I10_Amcare_VR.NewbornDischDate, dbo.I10_Amcare_VR.NextScheduledVisitDate, dbo.I10_Amcare_VR.NextScheduledVisitTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentDate, 
                         dbo.I10_Amcare_VR.NonPhysicianAssessmentTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknown, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.NonPhysicianNumber, dbo.I10_Amcare_VR.NonPhysicianNumberDesc, dbo.I10_Amcare_VR.NonPhysicianService, dbo.I10_Amcare_VR.NonPhysicianServiceDesc, 
                         dbo.I10_Amcare_VR.NumberofECT, dbo.I10_Amcare_VR.NursingAssessmentDate, dbo.I10_Amcare_VR.NursingAssessmentTime, dbo.I10_Amcare_VR.Occupation, dbo.I10_Amcare_VR.OccupationDesc, 
                         dbo.I10_Amcare_VR.OtherMedicalDeath, dbo.I10_Amcare_VR.OtherMedicalDeathDesc, dbo.I10_Amcare_VR.OtherBlood, dbo.I10_Amcare_VR.OtherBloodDesc, dbo.I10_Amcare_VR.OtherBloodCrossMatched, 
                         dbo.I10_Amcare_VR.OtherBloodCrossMatchedDesc, dbo.I10_Amcare_VR.OtherBloodTyped, dbo.I10_Amcare_VR.OtherBloodTypedDesc, dbo.I10_Amcare_VR.OtherBloodUnits, dbo.I10_Amcare_VR.PCTASIndicator, 
                         dbo.I10_Amcare_VR.PCTASIndicatorDesc, dbo.I10_Amcare_VR.PhysicianEstLOS, dbo.I10_Amcare_VR.Plasma, dbo.I10_Amcare_VR.PlasmaDesc, dbo.I10_Amcare_VR.PlasmaCrossMatched, 
                         dbo.I10_Amcare_VR.PlasmaCrossMatchedDesc, dbo.I10_Amcare_VR.PlasmaTyped, dbo.I10_Amcare_VR.PlasmaTypedDesc, dbo.I10_Amcare_VR.PlasmaUnits, dbo.I10_Amcare_VR.Platelets, 
                         dbo.I10_Amcare_VR.PlateletsDesc, dbo.I10_Amcare_VR.PlateletsCrossMatched, dbo.I10_Amcare_VR.PlateletsCrossMatchedDesc, dbo.I10_Amcare_VR.PlateletsTyped, dbo.I10_Amcare_VR.PlateletsTypedDesc, 
                         dbo.I10_Amcare_VR.PlateletsUnits, dbo.I10_Amcare_VR.PostalCode, dbo.I10_Amcare_VR.PostalCodeDesc, dbo.I10_Amcare_VR.PostOpDays, dbo.I10_Amcare_VR.PreOpDays, 
                         dbo.I10_Amcare_VR.PreamditWorkUp, dbo.I10_Amcare_VR.PreamditWorkUpDesc, dbo.I10_Amcare_VR.Pregnancy, dbo.I10_Amcare_VR.PregnancyDesc, dbo.I10_Amcare_VR.PrevLiveBirth, 
                         dbo.I10_Amcare_VR.PreviousPsychiartricAdmissions, dbo.I10_Amcare_VR.PreviousPsychiartricAdmDesc, dbo.I10_Amcare_VR.Program, dbo.I10_Amcare_VR.ProgramDesc, dbo.I10_Amcare_VR.ProvinceNumber, 
                         dbo.I10_Amcare_VR.ProvinceNumberDesc, dbo.I10_Amcare_VR.ReasonForVisit, dbo.I10_Amcare_VR.ReasonForVisitDesc, dbo.I10_Amcare_VR.ReAdmitCode, dbo.I10_Amcare_VR.ReciprocalBillingStatus, 
                         dbo.I10_Amcare_VR.ReciprocalBillingStatusDesc, dbo.I10_Amcare_VR.RedBloodCell, dbo.I10_Amcare_VR.RedBloodCellDesc, dbo.I10_Amcare_VR.RedBloodCellCrossMatched, 
                         dbo.I10_Amcare_VR.RedBloodCellCrossMatchedDesc, dbo.I10_Amcare_VR.RedBloodCellTyped, dbo.I10_Amcare_VR.RedBloodCellTypedDesc, dbo.I10_Amcare_VR.RedBloodCellUnits, 
                         dbo.I10_Amcare_VR.ReferralDate, dbo.I10_Amcare_VR.ReferredFrom, dbo.I10_Amcare_VR.ReferredFromDesc, dbo.I10_Amcare_VR.ReferredTo, dbo.I10_Amcare_VR.ReferredToDesc, 
                         dbo.I10_Amcare_VR.ReferringProvider, dbo.I10_Amcare_VR.ReferringProviderDesc, dbo.I10_Amcare_VR.RegisterNumber, dbo.I10_Amcare_VR.RegistrationNumber, 
                         dbo.I10_Amcare_VR.RegistrationSequenceNumber, dbo.I10_Amcare_VR.RegistrationVisitDate, dbo.I10_Amcare_VR.RegistrationVisitTime, dbo.I10_Amcare_VR.ReproductiveCareComments, 
                         dbo.I10_Amcare_VR.ReserveField, dbo.I10_Amcare_VR.ResidenceCode, dbo.I10_Amcare_VR.ResidenceCodeDesc, dbo.I10_Amcare_VR.ResidenceProvince, dbo.I10_Amcare_VR.ResidenceProvinceDesc, 
                         dbo.I10_Amcare_VR.ResidenceRegion, dbo.I10_Amcare_VR.ResidenceRegionDesc, dbo.I10_Amcare_VR.ResidenceType, dbo.I10_Amcare_VR.ResidenceTypeDesc, dbo.I10_Amcare_VR.ResponsiblityForPayment,
                          dbo.I10_Amcare_VR.ResponsiblityForPaymentDesc, dbo.I10_Amcare_VR.SchedEDVisit, dbo.I10_Amcare_VR.SchedEDVisitDesc, dbo.I10_Amcare_VR.SeatbeltIndicator, dbo.I10_Amcare_VR.SeatbeltIndicatorDesc, 
                         dbo.I10_Amcare_VR.SecondChartRegisterNumber, dbo.I10_Amcare_VR.SecretVIPPatient, dbo.I10_Amcare_VR.SecretVIPPatientDesc, dbo.I10_Amcare_VR.SiteNumber, dbo.I10_Amcare_VR.SiteNumberDesc, 
                         dbo.I10_Amcare_VR.SocialService, dbo.I10_Amcare_VR.SocialServiceDesc, dbo.I10_Amcare_VR.SourceofReferral, dbo.I10_Amcare_VR.SourceofReferralDesc, dbo.I10_Amcare_VR.SpecialistNumber, 
                         dbo.I10_Amcare_VR.SpecialistNumberDesc, dbo.I10_Amcare_VR.SpecialistRequestDate, dbo.I10_Amcare_VR.SpecialistRequestService, dbo.I10_Amcare_VR.SpecialistRequestServiceDesc, 
                         dbo.I10_Amcare_VR.SpecialistRequestTime, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknown, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknownDesc, dbo.I10_Amcare_VR.StakeholderType, 
                         dbo.I10_Amcare_VR.StakeholderTypeDesc, dbo.I10_Amcare_VR.StatusAfterTriage, dbo.I10_Amcare_VR.StatusAfterTriageDesc, dbo.I10_Amcare_VR.Sterilization, dbo.I10_Amcare_VR.SterilizationDesc, 
                         dbo.I10_Amcare_VR.SubmissionLevelCode, dbo.I10_Amcare_VR.SubmissionRecordID, dbo.I10_Amcare_VR.SubsequentOR, dbo.I10_Amcare_VR.SubsequentORDesc, dbo.I10_Amcare_VR.Suicide, 
                         dbo.I10_Amcare_VR.SuicideDesc, dbo.I10_Amcare_VR.SurgicalCase, dbo.I10_Amcare_VR.SurgicalCaseDesc, dbo.I10_Amcare_VR.TimeLeftER, dbo.I10_Amcare_VR.TimeLeftERUnknown, 
                         dbo.I10_Amcare_VR.TimeLeftERUnknownDEsc, dbo.I10_Amcare_VR.TransferOverloadDate, dbo.I10_Amcare_VR.TransferOverloadTime, dbo.I10_Amcare_VR.TransferOverloadTimeDifference, 
                         dbo.I10_Amcare_VR.TransfusionGiven, dbo.I10_Amcare_VR.TransfusionGivenDesc, dbo.I10_Amcare_VR.Trauma, dbo.I10_Amcare_VR.TraumaDesc, dbo.I10_Amcare_VR.TriageDate, 
                         dbo.I10_Amcare_VR.TriageLevel, dbo.I10_Amcare_VR.TriageLevelDesc, dbo.I10_Amcare_VR.TriageTime, dbo.I10_Amcare_VR.TriageTimeUnknown, dbo.I10_Amcare_VR.TriageTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.TSICoder, dbo.I10_Amcare_VR.TSICoderDesc, dbo.I10_Amcare_VR.TSIDate, dbo.I10_Amcare_VR.TSITime, dbo.I10_Amcare_VR.TwoTenPO, dbo.I10_Amcare_VR.ULI, 
                         dbo.I10_Amcare_VR.UniversalEpisodeIdentifier, dbo.I10_Amcare_VR.UnplannedReadmit, dbo.I10_Amcare_VR.VisitStatus, dbo.I10_Amcare_VR.VisitStatusDesc, dbo.I10_Amcare_VR.VisitType, dbo.I10_Amcare_VR.VisitTypeDesc, 
                         dbo.I10_Amcare_VR.WaitTimeinER, dbo.I10_Amcare_VR.WaittoAssessmentinMinutes, dbo.I10_Amcare_VR.WaittoNursingAssessmentDiff, dbo.I10_Amcare_VR.Weight, dbo.I10_Amcare_VR.zzAbstractLink, 
                         dbo.I10_Amcare_VR.zzRegionalPatientID, dbo.I10_Amcare_VR.zzVolumeLink, 
						 
						 dbo.I10_Amcare_Projects_150_VR.ProjectNumber, dbo.I10_Amcare_Projects_150_VR.ProjectNumberDesc, 
                         dbo.I10_Amcare_Projects_150_VR.ProjectOccurrence, dbo.I10_Amcare_Projects_150_VR.InterventionLineNumber, dbo.I10_Amcare_Projects_150_VR.DateCompletedReferralReceived, 
                         dbo.I10_Amcare_Projects_150_VR.TypeOfSeverityPriorityUrgencyScoreUsed, dbo.I10_Amcare_Projects_150_VR.TypeOfSeverityPriorityUrgencyScoreUsedDesc, 
                         dbo.I10_Amcare_Projects_150_VR.SeverityPriorityUrgencyScore, dbo.I10_Amcare_Projects_150_VR.DateType, dbo.I10_Amcare_Projects_150_VR.OtherDate
FROM            dbo.I10_Amcare_VR INNER JOIN
                         dbo.I10_Amcare_Projects_150_VR ON dbo.I10_Amcare_VR.zzAbstractLink = dbo.I10_Amcare_Projects_150_VR.zzAbstractLink



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Project_202_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_Amcare_And_Project_202_VR]
AS
SELECT        dbo.I10_Amcare_VR.[#ofPreviousPreTermDeliveries], dbo.I10_Amcare_VR.[#ofPrevSpontaneousAbortions], dbo.I10_Amcare_VR.[#ofPreviousTermDeliveries], dbo.I10_Amcare_VR.AccessPrimaryHealthCareCode, 
                         dbo.I10_Amcare_VR.AccessPrimaryHealthCareCodeDesc, dbo.I10_Amcare_VR.AmbulanceArrivalDate, dbo.I10_Amcare_VR.AmbulanceArrivalTime, dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknown, 
                         dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknownDesc, dbo.I10_Amcare_VR.AmbulanceTransferCareDate, dbo.I10_Amcare_VR.AmbulanceTransferCareTime, 
                         dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknown, dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknownDesc, dbo.I10_Amcare_VR.[#ofPrevTherapeuticAbortions], dbo.I10_Amcare_VR.AWOL, 
                         dbo.I10_Amcare_VR.AWOLDesc, dbo.I10_Amcare_VR.AbortDate, dbo.I10_Amcare_VR.AbstractNumber, dbo.I10_Amcare_VR.AbstractOverflow, dbo.I10_Amcare_VR.AbstractOverflowDesc, 
                         dbo.I10_Amcare_VR.ActivityDescription, dbo.I10_Amcare_VR.ActivityWhenInjured, dbo.I10_Amcare_VR.ActivityWhenInjuredDesc, dbo.I10_Amcare_VR.ActueLOS, dbo.I10_Amcare_VR.AdmitbyAmbulance, 
                         dbo.I10_Amcare_VR.AdmitbyAmbulanceDesc, dbo.I10_Amcare_VR.AdmitCategory, dbo.I10_Amcare_VR.AdmitDiagnosis, dbo.I10_Amcare_VR.AdmitNursingArea, dbo.I10_Amcare_VR.AdmitNursingAreaDesc, 
                         dbo.I10_Amcare_VR.AfterAdmit, dbo.I10_Amcare_VR.AgeCode, dbo.I10_Amcare_VR.AgeCodeDesc, dbo.I10_Amcare_VR.AgeGroup, dbo.I10_Amcare_VR.AgeNumber, dbo.I10_Amcare_VR.Albumin, 
                         dbo.I10_Amcare_VR.AlbuminDesc, dbo.I10_Amcare_VR.AlbuminCrossMatched, dbo.I10_Amcare_VR.AlbuminCrossMatchedDesc, dbo.I10_Amcare_VR.AlbuminTyped, dbo.I10_Amcare_VR.AlbuminTypedDesc, 
                         dbo.I10_Amcare_VR.AlbuminUnits, dbo.I10_Amcare_VR.ALCLOS, dbo.I10_Amcare_VR.AmbulanceReportNumber, dbo.I10_Amcare_VR.AmCareGroup, dbo.I10_Amcare_VR.AmCareGroupDesc, 
                         dbo.I10_Amcare_VR.AmcareCareType, dbo.I10_Amcare_VR.AmcareCareTypeDesc, dbo.I10_Amcare_VR.AmcareTypeCode, dbo.I10_Amcare_VR.AmcareTypeCodeDesc, dbo.I10_Amcare_VR.Ancil13, 
                         dbo.I10_Amcare_VR.Ancil14, dbo.I10_Amcare_VR.Ancil15, dbo.I10_Amcare_VR.Ancil16, dbo.I10_Amcare_VR.Ancil17, dbo.I10_Amcare_VR.AncillaryField1, dbo.I10_Amcare_VR.AncillaryField1Desc, 
                         dbo.I10_Amcare_VR.AncillaryField10, dbo.I10_Amcare_VR.AncillaryField10Desc, dbo.I10_Amcare_VR.AncillaryField11, dbo.I10_Amcare_VR.AncillaryField11Desc, dbo.I10_Amcare_VR.AncillaryField12, 
                         dbo.I10_Amcare_VR.AncillaryField12Desc, dbo.I10_Amcare_VR.AncillaryField2, dbo.I10_Amcare_VR.AncillaryField2Desc, dbo.I10_Amcare_VR.AncillaryField3, dbo.I10_Amcare_VR.AncillaryField3Desc, 
                         dbo.I10_Amcare_VR.AncillaryField4, dbo.I10_Amcare_VR.AncillaryField4Desc, dbo.I10_Amcare_VR.AncillaryField5, dbo.I10_Amcare_VR.AncillaryField5Desc, dbo.I10_Amcare_VR.AncillaryField6, 
                         dbo.I10_Amcare_VR.AncillaryField6Desc, dbo.I10_Amcare_VR.AncillaryField7, dbo.I10_Amcare_VR.AncillaryField7Desc, dbo.I10_Amcare_VR.AncillaryField8, dbo.I10_Amcare_VR.AncillaryField8Desc, 
                         dbo.I10_Amcare_VR.AncillaryField9, dbo.I10_Amcare_VR.AncillaryField9Desc, dbo.I10_Amcare_VR.ArrivalDate, dbo.I10_Amcare_VR.ArrivalMode, dbo.I10_Amcare_VR.ArrivalModeDesc, 
                         dbo.I10_Amcare_VR.ArrivalTime, dbo.I10_Amcare_VR.ArrivaltoTriageTime, dbo.I10_Amcare_VR.AssessmentDate, dbo.I10_Amcare_VR.AssessmentTime, dbo.I10_Amcare_VR.AssessmentTimeUnknown, 
                         dbo.I10_Amcare_VR.AssessmentTimeUnknownDesc, dbo.I10_Amcare_VR.AttendingPhysician, dbo.I10_Amcare_VR.AttendingPhysicianDesc, dbo.I10_Amcare_VR.AutoTransfusion, 
                         dbo.I10_Amcare_VR.AutoTransfusionDesc, dbo.I10_Amcare_VR.AutopsyPerformed, dbo.I10_Amcare_VR.AutopsyPerformedDesc, dbo.I10_Amcare_VR.BasicOption1, dbo.I10_Amcare_VR.BasicOption1Desc, 
                         dbo.I10_Amcare_VR.BasicOption10, dbo.I10_Amcare_VR.BasicOption10Desc, dbo.I10_Amcare_VR.BasicOption11, dbo.I10_Amcare_VR.BasicOption11Desc, dbo.I10_Amcare_VR.BasicOption12, 
                         dbo.I10_Amcare_VR.BasicOption12Desc, dbo.I10_Amcare_VR.BasicOption13, dbo.I10_Amcare_VR.BasicOption13Desc, dbo.I10_Amcare_VR.BasicOption14, dbo.I10_Amcare_VR.BasicOption14Desc, 
                         dbo.I10_Amcare_VR.BasicOption15, dbo.I10_Amcare_VR.BasicOption15Desc, dbo.I10_Amcare_VR.BasicOption16, dbo.I10_Amcare_VR.BasicOption16Desc, dbo.I10_Amcare_VR.BasicOption17, 
                         dbo.I10_Amcare_VR.BasicOption17Desc, dbo.I10_Amcare_VR.BasicOption18, dbo.I10_Amcare_VR.BasicOption18Desc, dbo.I10_Amcare_VR.BasicOption19, dbo.I10_Amcare_VR.BasicOption19Desc, 
                         dbo.I10_Amcare_VR.BasicOption2, dbo.I10_Amcare_VR.BasicOption2Desc, dbo.I10_Amcare_VR.BasicOption3, dbo.I10_Amcare_VR.BasicOption3Desc, dbo.I10_Amcare_VR.BasicOption4, 
                         dbo.I10_Amcare_VR.BasicOption4Desc, dbo.I10_Amcare_VR.BasicOption5, dbo.I10_Amcare_VR.BasicOption5Desc, dbo.I10_Amcare_VR.BasicOption6, dbo.I10_Amcare_VR.BasicOption6Desc, 
                         dbo.I10_Amcare_VR.BasicOption7, dbo.I10_Amcare_VR.BasicOption7Desc, dbo.I10_Amcare_VR.BasicOption8, dbo.I10_Amcare_VR.BasicOption8Desc, dbo.I10_Amcare_VR.BasicOption9, 
                         dbo.I10_Amcare_VR.BasicOption9Desc, dbo.I10_Amcare_VR.BatchNumber, dbo.I10_Amcare_VR.BatchPeriod, dbo.I10_Amcare_VR.BatchPeriodDesc, dbo.I10_Amcare_VR.BatchPeriod_BC, 
                         dbo.I10_Amcare_VR.BatchYear, dbo.I10_Amcare_VR.BirthDate, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIII, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIIIDesc, 
						 dbo.I10_Amcare_VR.Blood_C1Inhibitor, 
                         dbo.I10_Amcare_VR.Blood_C1InhibitorDesc, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasma, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_CryosupernatantPlasma, 
                         dbo.I10_Amcare_VR.Blood_CryosupernatantPlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_FEIBA, 
						 dbo.I10_Amcare_VR.Blood_FEIBADesc, 
						 dbo.I10_Amcare_VR.Blood_Fibrinogen, 
						 dbo.I10_Amcare_VR.Blood_FibrinogenDesc, 
                         dbo.I10_Amcare_VR.Blood_IVIG_SCIG, 
						 dbo.I10_Amcare_VR.Blood_IVIG_SCIGDesc, 
						 dbo.I10_Amcare_VR.Blood_PCC, 
						 dbo.I10_Amcare_VR.Blood_PCCDesc, 
						 dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactors, 
                         dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactorsDesc, 
						 
						 dbo.I10_Amcare_VR.BreastFeeding, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlag, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlagDesc, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitDateIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknown, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknownDesc, dbo.I10_Amcare_VR.ClinicalDecisionUnitDateOut, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOut, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknown, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknownDesc, dbo.I10_Amcare_VR.ChangeinLegalStatus, 
                         dbo.I10_Amcare_VR.ChangeinLegalStatusDesc, dbo.I10_Amcare_VR.ChartNumber, dbo.I10_Amcare_VR.ChiefComplaint, dbo.I10_Amcare_VR.CoderNumber, dbo.I10_Amcare_VR.CoderNumberDesc, 
                         dbo.I10_Amcare_VR.CompleteRecord, dbo.I10_Amcare_VR.CompleteRecordDesc, dbo.I10_Amcare_VR.Complication, dbo.I10_Amcare_VR.ComplicationDesc, dbo.I10_Amcare_VR.Complication1, 
                         dbo.I10_Amcare_VR.Complication1Desc, dbo.I10_Amcare_VR.Complication2, dbo.I10_Amcare_VR.Complication2Desc, dbo.I10_Amcare_VR.Complication3, dbo.I10_Amcare_VR.Complication3Desc, 
                         dbo.I10_Amcare_VR.ContactMode, dbo.I10_Amcare_VR.ContactModeDesc, dbo.I10_Amcare_VR.CoronerCase, dbo.I10_Amcare_VR.CoronerCaseDesc, dbo.I10_Amcare_VR.DataEntryCoder, 
                         dbo.I10_Amcare_VR.DataEntryCoderDesc, dbo.I10_Amcare_VR.DateLeftER, dbo.I10_Amcare_VR.DateofLastMenses, dbo.I10_Amcare_VR.DateReadyforDisch, dbo.I10_Amcare_VR.DateSentToCIHI, 
                         dbo.I10_Amcare_VR.DateSentToCIHILevel1, dbo.I10_Amcare_VR.DateSentToCIHILevel2, dbo.I10_Amcare_VR.DateSentToCIHILite, dbo.I10_Amcare_VR.DeathInER, dbo.I10_Amcare_VR.DeathInERDesc, 
                         dbo.I10_Amcare_VR.DeathOnArrival, dbo.I10_Amcare_VR.DeathOnArrivalDesc, dbo.I10_Amcare_VR.DecisionAdmitDifference, dbo.I10_Amcare_VR.DecisiontoAdmitDate, dbo.I10_Amcare_VR.DecisiontoAdmitTime, 
                         dbo.I10_Amcare_VR.DecisionAdmitTimeUnknown, dbo.I10_Amcare_VR.DecisionAdmitTimeUnknownDesc, dbo.I10_Amcare_VR.DeliveryDate, dbo.I10_Amcare_VR.DeliveryTime, 
                         dbo.I10_Amcare_VR.DiedDuringIntervention, dbo.I10_Amcare_VR.DiedDuringInterventionDesc, dbo.I10_Amcare_VR.DischNursingArea, dbo.I10_Amcare_VR.DischNursingAreaDesc, 
                         dbo.I10_Amcare_VR.DischPlanning, dbo.I10_Amcare_VR.DischPlanningDesc, dbo.I10_Amcare_VR.DischargeAge, dbo.I10_Amcare_VR.DischargeDisposition, dbo.I10_Amcare_VR.DischargeDispositionDesc, 
                         dbo.I10_Amcare_VR.DispositionDate, dbo.I10_Amcare_VR.DispositionTime, dbo.I10_Amcare_VR.DispositionTimeUnknown, dbo.I10_Amcare_VR.DispositionTimeUnknownDesc, dbo.I10_Amcare_VR.ECTTreatment, 
                         dbo.I10_Amcare_VR.ECTTreatmentDesc, dbo.I10_Amcare_VR.Education, dbo.I10_Amcare_VR.EducationDesc, dbo.I10_Amcare_VR.EDVisitIndicator, dbo.I10_Amcare_VR.EDVisitIndicatorDesc, 
                         dbo.I10_Amcare_VR.Employment, dbo.I10_Amcare_VR.EmploymentDesc, dbo.I10_Amcare_VR.EntryCode, dbo.I10_Amcare_VR.EstimateDischDate, dbo.I10_Amcare_VR.ExitCode, 
                         dbo.I10_Amcare_VR.FamilyPhysicianFlag, dbo.I10_Amcare_VR.FamilyPhysicianFlagDesc, dbo.I10_Amcare_VR.FinancialSupport, dbo.I10_Amcare_VR.FinancialSupportDesc, dbo.I10_Amcare_VR.FinishDate, 
                         dbo.I10_Amcare_VR.FinishTime, dbo.I10_Amcare_VR.FirstName, dbo.I10_Amcare_VR.FullName, dbo.I10_Amcare_VR.FixedChartNumber, dbo.I10_Amcare_VR.Gender, dbo.I10_Amcare_VR.GenderDesc, 
                         dbo.I10_Amcare_VR.GestationalAgeinweeks, dbo.I10_Amcare_VR.GlasgowScale, dbo.I10_Amcare_VR.GlasgowScaleDesc, dbo.I10_Amcare_VR.GreaterTenPO, dbo.I10_Amcare_VR.HCNProvince, 
                         dbo.I10_Amcare_VR.HCNProvinceDesc, dbo.I10_Amcare_VR.HCNVersion, dbo.I10_Amcare_VR.HealthCareNumber, dbo.I10_Amcare_VR.Hospital, dbo.I10_Amcare_VR.HospitalDesc, 
                         dbo.I10_Amcare_VR.HospitalAccountRecord,
                         dbo.I10_Amcare_VR.HelmetIndicator, dbo.I10_Amcare_VR.HelmetIndicatorDesc, dbo.I10_Amcare_VR.InSCU, dbo.I10_Amcare_VR.InitialOR, dbo.I10_Amcare_VR.InitialORDesc, dbo.I10_Amcare_VR.InjuryDate, 
                         dbo.I10_Amcare_VR.Injury, dbo.I10_Amcare_VR.InjuryDesc, dbo.I10_Amcare_VR.InputDate, dbo.I10_Amcare_VR.InputTime, 

						 dbo.I10_Amcare_VR.InstitutionFrom, dbo.I10_Amcare_VR.InstitutionFromDesc, 
						 dbo.I10_Amcare_VR.InstitutionFromType, dbo.I10_Amcare_VR.InstitutionFromTypeDesc,
                         dbo.I10_Amcare_VR.InstFromCareType, dbo.I10_Amcare_VR.InstFromHospType, 
						 dbo.I10_Amcare_VR.InstitutionNumber, dbo.I10_Amcare_VR.InstitutionNumberDesc, 
						 dbo.I10_Amcare_VR.InstitutionTo, dbo.I10_Amcare_VR.InstitutionToDesc, 
						 dbo.I10_Amcare_VR.InstToCareType, dbo.I10_Amcare_VR.InstToHospType, 
						 dbo.I10_Amcare_VR.InstitutionToType, dbo.I10_Amcare_VR.InstitutionToTypeDesc, 
						 
						 dbo.I10_Amcare_VR.InterfaceDate, dbo.I10_Amcare_VR.InterfaceTime, 
                         dbo.I10_Amcare_VR.IsAbstractCompleted, dbo.I10_Amcare_VR.IsAbstractCompletedDesc, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCompletedLevel2, dbo.I10_Amcare_VR.IsAbstractCompletedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCompletedLite, dbo.I10_Amcare_VR.IsAbstractCompletedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrected, dbo.I10_Amcare_VR.IsAbstractCorrectedDesc, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCorrectedLite, dbo.I10_Amcare_VR.IsAbstractCorrectedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractDeleted, dbo.I10_Amcare_VR.IsAbstractDeletedDesc, dbo.I10_Amcare_VR.IsAbstractSubmitted, dbo.I10_Amcare_VR.IsAbstractSubmittedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLite, dbo.I10_Amcare_VR.IsAbstractSubmittedLiteDesc, dbo.I10_Amcare_VR.IsAbstractValidated, dbo.I10_Amcare_VR.IsAbstractValidatedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLevel1, dbo.I10_Amcare_VR.IsAbstractValidatedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLite, dbo.I10_Amcare_VR.IsAbstractValidatedLiteDesc, dbo.I10_Amcare_VR.IsBirthdateEstimated, dbo.I10_Amcare_VR.IsBirthdateEstimatedDesc, 
						 dbo.I10_Amcare_VR.IsCustomValidated, dbo.I10_Amcare_VR.IsCustomValidatedDesc,
                         dbo.I10_Amcare_VR.LOSDays, dbo.I10_Amcare_VR.LOSTime, dbo.I10_Amcare_VR.LOSTimeinHours, dbo.I10_Amcare_VR.LOSTotalMinutes, dbo.I10_Amcare_VR.Language, dbo.I10_Amcare_VR.LanguageDesc, 
                         dbo.I10_Amcare_VR.LastName, dbo.I10_Amcare_VR.LessTwoPO, dbo.I10_Amcare_VR.LivingArrangement, dbo.I10_Amcare_VR.LivingArrangementDesc, dbo.I10_Amcare_VR.LocationofInjury, 
                         dbo.I10_Amcare_VR.LocationofInjuryDesc, dbo.I10_Amcare_VR.MISCode, dbo.I10_Amcare_VR.MISCodeDesc, dbo.I10_Amcare_VR.MaidenName, dbo.I10_Amcare_VR.MaritalStatus, 
                         dbo.I10_Amcare_VR.MaritalStatusDesc, 
                         dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoED, 
						 dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04Desc, 
						 
						 dbo.I10_Amcare_VR.MethodofAdmission, dbo.I10_Amcare_VR.MethodofAdmissionDesc, dbo.I10_Amcare_VR.MiddleName, 
                         dbo.I10_Amcare_VR.NACRSClinicLiteSubmission, dbo.I10_Amcare_VR.NACRSClinicLiteSubmissionDesc, 
                         dbo.I10_Amcare_VR.NewbornChart, 
                         dbo.I10_Amcare_VR.NewbornDischDate, dbo.I10_Amcare_VR.NextScheduledVisitDate, dbo.I10_Amcare_VR.NextScheduledVisitTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentDate, 
                         dbo.I10_Amcare_VR.NonPhysicianAssessmentTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknown, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.NonPhysicianNumber, dbo.I10_Amcare_VR.NonPhysicianNumberDesc, dbo.I10_Amcare_VR.NonPhysicianService, dbo.I10_Amcare_VR.NonPhysicianServiceDesc, 
                         dbo.I10_Amcare_VR.NumberofECT, dbo.I10_Amcare_VR.NursingAssessmentDate, dbo.I10_Amcare_VR.NursingAssessmentTime, dbo.I10_Amcare_VR.Occupation, dbo.I10_Amcare_VR.OccupationDesc, 
                         dbo.I10_Amcare_VR.OtherMedicalDeath, dbo.I10_Amcare_VR.OtherMedicalDeathDesc, dbo.I10_Amcare_VR.OtherBlood, dbo.I10_Amcare_VR.OtherBloodDesc, dbo.I10_Amcare_VR.OtherBloodCrossMatched, 
                         dbo.I10_Amcare_VR.OtherBloodCrossMatchedDesc, dbo.I10_Amcare_VR.OtherBloodTyped, dbo.I10_Amcare_VR.OtherBloodTypedDesc, dbo.I10_Amcare_VR.OtherBloodUnits, dbo.I10_Amcare_VR.PCTASIndicator, 
                         dbo.I10_Amcare_VR.PCTASIndicatorDesc, dbo.I10_Amcare_VR.PhysicianEstLOS, dbo.I10_Amcare_VR.Plasma, dbo.I10_Amcare_VR.PlasmaDesc, dbo.I10_Amcare_VR.PlasmaCrossMatched, 
                         dbo.I10_Amcare_VR.PlasmaCrossMatchedDesc, dbo.I10_Amcare_VR.PlasmaTyped, dbo.I10_Amcare_VR.PlasmaTypedDesc, dbo.I10_Amcare_VR.PlasmaUnits, dbo.I10_Amcare_VR.Platelets, 
                         dbo.I10_Amcare_VR.PlateletsDesc, dbo.I10_Amcare_VR.PlateletsCrossMatched, dbo.I10_Amcare_VR.PlateletsCrossMatchedDesc, dbo.I10_Amcare_VR.PlateletsTyped, dbo.I10_Amcare_VR.PlateletsTypedDesc, 
                         dbo.I10_Amcare_VR.PlateletsUnits, dbo.I10_Amcare_VR.PostalCode, dbo.I10_Amcare_VR.PostalCodeDesc, dbo.I10_Amcare_VR.PostOpDays, dbo.I10_Amcare_VR.PreOpDays, 
                         dbo.I10_Amcare_VR.PreamditWorkUp, dbo.I10_Amcare_VR.PreamditWorkUpDesc, dbo.I10_Amcare_VR.Pregnancy, dbo.I10_Amcare_VR.PregnancyDesc, dbo.I10_Amcare_VR.PrevLiveBirth, 
                         dbo.I10_Amcare_VR.PreviousPsychiartricAdmissions, dbo.I10_Amcare_VR.PreviousPsychiartricAdmDesc, dbo.I10_Amcare_VR.Program, dbo.I10_Amcare_VR.ProgramDesc, dbo.I10_Amcare_VR.ProvinceNumber, 
                         dbo.I10_Amcare_VR.ProvinceNumberDesc, dbo.I10_Amcare_VR.ReasonForVisit, dbo.I10_Amcare_VR.ReasonForVisitDesc, dbo.I10_Amcare_VR.ReAdmitCode, dbo.I10_Amcare_VR.ReciprocalBillingStatus, 
                         dbo.I10_Amcare_VR.ReciprocalBillingStatusDesc, dbo.I10_Amcare_VR.RedBloodCell, dbo.I10_Amcare_VR.RedBloodCellDesc, dbo.I10_Amcare_VR.RedBloodCellCrossMatched, 
                         dbo.I10_Amcare_VR.RedBloodCellCrossMatchedDesc, dbo.I10_Amcare_VR.RedBloodCellTyped, dbo.I10_Amcare_VR.RedBloodCellTypedDesc, dbo.I10_Amcare_VR.RedBloodCellUnits, 
                         dbo.I10_Amcare_VR.ReferralDate, dbo.I10_Amcare_VR.ReferredFrom, dbo.I10_Amcare_VR.ReferredFromDesc, dbo.I10_Amcare_VR.ReferredTo, dbo.I10_Amcare_VR.ReferredToDesc, 
                         dbo.I10_Amcare_VR.ReferringProvider, dbo.I10_Amcare_VR.ReferringProviderDesc, dbo.I10_Amcare_VR.RegisterNumber, dbo.I10_Amcare_VR.RegistrationNumber, 
                         dbo.I10_Amcare_VR.RegistrationSequenceNumber, dbo.I10_Amcare_VR.RegistrationVisitDate, dbo.I10_Amcare_VR.RegistrationVisitTime, dbo.I10_Amcare_VR.ReproductiveCareComments, 
                         dbo.I10_Amcare_VR.ReserveField, dbo.I10_Amcare_VR.ResidenceCode, dbo.I10_Amcare_VR.ResidenceCodeDesc, dbo.I10_Amcare_VR.ResidenceProvince, dbo.I10_Amcare_VR.ResidenceProvinceDesc, 
                         dbo.I10_Amcare_VR.ResidenceRegion, dbo.I10_Amcare_VR.ResidenceRegionDesc, dbo.I10_Amcare_VR.ResidenceType, dbo.I10_Amcare_VR.ResidenceTypeDesc, dbo.I10_Amcare_VR.ResponsiblityForPayment,
                          dbo.I10_Amcare_VR.ResponsiblityForPaymentDesc, dbo.I10_Amcare_VR.SchedEDVisit, dbo.I10_Amcare_VR.SchedEDVisitDesc, dbo.I10_Amcare_VR.SeatbeltIndicator, dbo.I10_Amcare_VR.SeatbeltIndicatorDesc, 
                         dbo.I10_Amcare_VR.SecondChartRegisterNumber, dbo.I10_Amcare_VR.SecretVIPPatient, dbo.I10_Amcare_VR.SecretVIPPatientDesc, dbo.I10_Amcare_VR.SiteNumber, dbo.I10_Amcare_VR.SiteNumberDesc, 
                         dbo.I10_Amcare_VR.SocialService, dbo.I10_Amcare_VR.SocialServiceDesc, dbo.I10_Amcare_VR.SourceofReferral, dbo.I10_Amcare_VR.SourceofReferralDesc, dbo.I10_Amcare_VR.SpecialistNumber, 
                         dbo.I10_Amcare_VR.SpecialistNumberDesc, dbo.I10_Amcare_VR.SpecialistRequestDate, dbo.I10_Amcare_VR.SpecialistRequestService, dbo.I10_Amcare_VR.SpecialistRequestServiceDesc, 
                         dbo.I10_Amcare_VR.SpecialistRequestTime, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknown, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknownDesc, dbo.I10_Amcare_VR.StakeholderType, 
                         dbo.I10_Amcare_VR.StakeholderTypeDesc, dbo.I10_Amcare_VR.StatusAfterTriage, dbo.I10_Amcare_VR.StatusAfterTriageDesc, dbo.I10_Amcare_VR.Sterilization, dbo.I10_Amcare_VR.SterilizationDesc, 
                         dbo.I10_Amcare_VR.SubmissionLevelCode, dbo.I10_Amcare_VR.SubmissionRecordID, dbo.I10_Amcare_VR.SubsequentOR, dbo.I10_Amcare_VR.SubsequentORDesc, dbo.I10_Amcare_VR.Suicide, 
                         dbo.I10_Amcare_VR.SuicideDesc, dbo.I10_Amcare_VR.SurgicalCase, dbo.I10_Amcare_VR.SurgicalCaseDesc, dbo.I10_Amcare_VR.TimeLeftER, dbo.I10_Amcare_VR.TimeLeftERUnknown, 
                         dbo.I10_Amcare_VR.TimeLeftERUnknownDEsc, dbo.I10_Amcare_VR.TransferOverloadDate, dbo.I10_Amcare_VR.TransferOverloadTime, dbo.I10_Amcare_VR.TransferOverloadTimeDifference, 
                         dbo.I10_Amcare_VR.TransfusionGiven, dbo.I10_Amcare_VR.TransfusionGivenDesc, dbo.I10_Amcare_VR.Trauma, dbo.I10_Amcare_VR.TraumaDesc, dbo.I10_Amcare_VR.TriageDate, 
                         dbo.I10_Amcare_VR.TriageLevel, dbo.I10_Amcare_VR.TriageLevelDesc, dbo.I10_Amcare_VR.TriageTime, dbo.I10_Amcare_VR.TriageTimeUnknown, dbo.I10_Amcare_VR.TriageTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.TSICoder, dbo.I10_Amcare_VR.TSICoderDesc, dbo.I10_Amcare_VR.TSIDate, dbo.I10_Amcare_VR.TSITime, dbo.I10_Amcare_VR.TwoTenPO, dbo.I10_Amcare_VR.ULI, 
                         dbo.I10_Amcare_VR.UniversalEpisodeIdentifier, dbo.I10_Amcare_VR.UnplannedReadmit, dbo.I10_Amcare_VR.VisitStatus, dbo.I10_Amcare_VR.VisitStatusDesc, dbo.I10_Amcare_VR.VisitType, dbo.I10_Amcare_VR.VisitTypeDesc, 
                         dbo.I10_Amcare_VR.WaitTimeinER, dbo.I10_Amcare_VR.WaittoAssessmentinMinutes, dbo.I10_Amcare_VR.WaittoNursingAssessmentDiff, dbo.I10_Amcare_VR.Weight, dbo.I10_Amcare_VR.zzAbstractLink, 
                         dbo.I10_Amcare_VR.zzRegionalPatientID, dbo.I10_Amcare_VR.zzVolumeLink, 

				dbo.I10_Amcare_Projects_202_VR.ProjectNumber, dbo.I10_Amcare_Projects_202_VR.ProjectNumberDesc, 
                         dbo.I10_Amcare_Projects_202_VR.ProjectOccurrence, dbo.I10_Amcare_Projects_202_VR.Kidneys, dbo.I10_Amcare_Projects_202_VR.KidneysDesc, dbo.I10_Amcare_Projects_202_VR.Liver, 
                         dbo.I10_Amcare_Projects_202_VR.LiverDesc, dbo.I10_Amcare_Projects_202_VR.Heart, dbo.I10_Amcare_Projects_202_VR.HeartDesc, dbo.I10_Amcare_Projects_202_VR.Pancreas, 
                         dbo.I10_Amcare_Projects_202_VR.PancreascDesc, dbo.I10_Amcare_Projects_202_VR.PancreaticIsletCells, dbo.I10_Amcare_Projects_202_VR.PancreaticIsletCellsDesc, 
                         dbo.I10_Amcare_Projects_202_VR.Heartvalves, dbo.I10_Amcare_Projects_202_VR.HeartvalvesDesc, dbo.I10_Amcare_Projects_202_VR.Bowel, dbo.I10_Amcare_Projects_202_VR.BowelDesc, 
                         dbo.I10_Amcare_Projects_202_VR.Cornea, dbo.I10_Amcare_Projects_202_VR.CorneaDesc, dbo.I10_Amcare_Projects_202_VR.Skin, dbo.I10_Amcare_Projects_202_VR.SkinDesc, 
                         dbo.I10_Amcare_Projects_202_VR.Bone, dbo.I10_Amcare_Projects_202_VR.BoneDesc, dbo.I10_Amcare_Projects_202_VR.Other, dbo.I10_Amcare_Projects_202_VR.OtherDesc, 
                         dbo.I10_Amcare_Projects_202_VR.Lung, dbo.I10_Amcare_Projects_202_VR.LungDesc, dbo.I10_Amcare_Projects_202_VR.HoursBetweenDeathAndHarvesting, 
                         dbo.I10_Amcare_Projects_202_VR.NumberOfOrgansIssueRetrieveved, dbo.I10_Amcare_Projects_202_VR.ORTime
FROM            dbo.I10_Amcare_VR INNER JOIN
                         dbo.I10_Amcare_Projects_202_VR ON dbo.I10_Amcare_VR.zzAbstractLink = dbo.I10_Amcare_Projects_202_VR.zzAbstractLink



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Project_340_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_Amcare_And_Project_340_VR]
AS
SELECT        dbo.I10_Amcare_VR.[#ofPreviousPreTermDeliveries], dbo.I10_Amcare_VR.[#ofPrevSpontaneousAbortions], dbo.I10_Amcare_VR.[#ofPreviousTermDeliveries], dbo.I10_Amcare_VR.AccessPrimaryHealthCareCode, 
                         dbo.I10_Amcare_VR.AccessPrimaryHealthCareCodeDesc, dbo.I10_Amcare_VR.AmbulanceArrivalDate, dbo.I10_Amcare_VR.AmbulanceArrivalTime, dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknown, 
                         dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknownDesc, dbo.I10_Amcare_VR.AmbulanceTransferCareDate, dbo.I10_Amcare_VR.AmbulanceTransferCareTime, 
                         dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknown, dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknownDesc, dbo.I10_Amcare_VR.[#ofPrevTherapeuticAbortions], dbo.I10_Amcare_VR.AWOL, 
                         dbo.I10_Amcare_VR.AWOLDesc, dbo.I10_Amcare_VR.AbortDate, dbo.I10_Amcare_VR.AbstractNumber, dbo.I10_Amcare_VR.AbstractOverflow, dbo.I10_Amcare_VR.AbstractOverflowDesc, 
                         dbo.I10_Amcare_VR.ActivityDescription, dbo.I10_Amcare_VR.ActivityWhenInjured, dbo.I10_Amcare_VR.ActivityWhenInjuredDesc, dbo.I10_Amcare_VR.ActueLOS, dbo.I10_Amcare_VR.AdmitbyAmbulance, 
                         dbo.I10_Amcare_VR.AdmitbyAmbulanceDesc, dbo.I10_Amcare_VR.AdmitCategory, dbo.I10_Amcare_VR.AdmitDiagnosis, dbo.I10_Amcare_VR.AdmitNursingArea, dbo.I10_Amcare_VR.AdmitNursingAreaDesc, 
                         dbo.I10_Amcare_VR.AfterAdmit, dbo.I10_Amcare_VR.AgeCode, dbo.I10_Amcare_VR.AgeCodeDesc, dbo.I10_Amcare_VR.AgeGroup, dbo.I10_Amcare_VR.AgeNumber, dbo.I10_Amcare_VR.Albumin, 
                         dbo.I10_Amcare_VR.AlbuminDesc, dbo.I10_Amcare_VR.AlbuminCrossMatched, dbo.I10_Amcare_VR.AlbuminCrossMatchedDesc, dbo.I10_Amcare_VR.AlbuminTyped, dbo.I10_Amcare_VR.AlbuminTypedDesc, 
                         dbo.I10_Amcare_VR.AlbuminUnits, dbo.I10_Amcare_VR.ALCLOS, dbo.I10_Amcare_VR.AmbulanceReportNumber, dbo.I10_Amcare_VR.AmCareGroup, dbo.I10_Amcare_VR.AmCareGroupDesc, 
                         dbo.I10_Amcare_VR.AmcareCareType, dbo.I10_Amcare_VR.AmcareCareTypeDesc, dbo.I10_Amcare_VR.AmcareTypeCode, dbo.I10_Amcare_VR.AmcareTypeCodeDesc, dbo.I10_Amcare_VR.Ancil13, 
                         dbo.I10_Amcare_VR.Ancil14, dbo.I10_Amcare_VR.Ancil15, dbo.I10_Amcare_VR.Ancil16, dbo.I10_Amcare_VR.Ancil17, dbo.I10_Amcare_VR.AncillaryField1, dbo.I10_Amcare_VR.AncillaryField1Desc, 
                         dbo.I10_Amcare_VR.AncillaryField10, dbo.I10_Amcare_VR.AncillaryField10Desc, dbo.I10_Amcare_VR.AncillaryField11, dbo.I10_Amcare_VR.AncillaryField11Desc, dbo.I10_Amcare_VR.AncillaryField12, 
                         dbo.I10_Amcare_VR.AncillaryField12Desc, dbo.I10_Amcare_VR.AncillaryField2, dbo.I10_Amcare_VR.AncillaryField2Desc, dbo.I10_Amcare_VR.AncillaryField3, dbo.I10_Amcare_VR.AncillaryField3Desc, 
                         dbo.I10_Amcare_VR.AncillaryField4, dbo.I10_Amcare_VR.AncillaryField4Desc, dbo.I10_Amcare_VR.AncillaryField5, dbo.I10_Amcare_VR.AncillaryField5Desc, dbo.I10_Amcare_VR.AncillaryField6, 
                         dbo.I10_Amcare_VR.AncillaryField6Desc, dbo.I10_Amcare_VR.AncillaryField7, dbo.I10_Amcare_VR.AncillaryField7Desc, dbo.I10_Amcare_VR.AncillaryField8, dbo.I10_Amcare_VR.AncillaryField8Desc, 
                         dbo.I10_Amcare_VR.AncillaryField9, dbo.I10_Amcare_VR.AncillaryField9Desc, dbo.I10_Amcare_VR.ArrivalDate, dbo.I10_Amcare_VR.ArrivalMode, dbo.I10_Amcare_VR.ArrivalModeDesc, 
                         dbo.I10_Amcare_VR.ArrivalTime, dbo.I10_Amcare_VR.ArrivaltoTriageTime, dbo.I10_Amcare_VR.AssessmentDate, dbo.I10_Amcare_VR.AssessmentTime, dbo.I10_Amcare_VR.AssessmentTimeUnknown, 
                         dbo.I10_Amcare_VR.AssessmentTimeUnknownDesc, dbo.I10_Amcare_VR.AttendingPhysician, dbo.I10_Amcare_VR.AttendingPhysicianDesc, dbo.I10_Amcare_VR.AutoTransfusion, 
                         dbo.I10_Amcare_VR.AutoTransfusionDesc, dbo.I10_Amcare_VR.AutopsyPerformed, dbo.I10_Amcare_VR.AutopsyPerformedDesc, dbo.I10_Amcare_VR.BasicOption1, dbo.I10_Amcare_VR.BasicOption1Desc, 
                         dbo.I10_Amcare_VR.BasicOption10, dbo.I10_Amcare_VR.BasicOption10Desc, dbo.I10_Amcare_VR.BasicOption11, dbo.I10_Amcare_VR.BasicOption11Desc, dbo.I10_Amcare_VR.BasicOption12, 
                         dbo.I10_Amcare_VR.BasicOption12Desc, dbo.I10_Amcare_VR.BasicOption13, dbo.I10_Amcare_VR.BasicOption13Desc, dbo.I10_Amcare_VR.BasicOption14, dbo.I10_Amcare_VR.BasicOption14Desc, 
                         dbo.I10_Amcare_VR.BasicOption15, dbo.I10_Amcare_VR.BasicOption15Desc, dbo.I10_Amcare_VR.BasicOption16, dbo.I10_Amcare_VR.BasicOption16Desc, dbo.I10_Amcare_VR.BasicOption17, 
                         dbo.I10_Amcare_VR.BasicOption17Desc, dbo.I10_Amcare_VR.BasicOption18, dbo.I10_Amcare_VR.BasicOption18Desc, dbo.I10_Amcare_VR.BasicOption19, dbo.I10_Amcare_VR.BasicOption19Desc, 
                         dbo.I10_Amcare_VR.BasicOption2, dbo.I10_Amcare_VR.BasicOption2Desc, dbo.I10_Amcare_VR.BasicOption3, dbo.I10_Amcare_VR.BasicOption3Desc, dbo.I10_Amcare_VR.BasicOption4, 
                         dbo.I10_Amcare_VR.BasicOption4Desc, dbo.I10_Amcare_VR.BasicOption5, dbo.I10_Amcare_VR.BasicOption5Desc, dbo.I10_Amcare_VR.BasicOption6, dbo.I10_Amcare_VR.BasicOption6Desc, 
                         dbo.I10_Amcare_VR.BasicOption7, dbo.I10_Amcare_VR.BasicOption7Desc, dbo.I10_Amcare_VR.BasicOption8, dbo.I10_Amcare_VR.BasicOption8Desc, dbo.I10_Amcare_VR.BasicOption9, 
                         dbo.I10_Amcare_VR.BasicOption9Desc, dbo.I10_Amcare_VR.BatchNumber, dbo.I10_Amcare_VR.BatchPeriod, dbo.I10_Amcare_VR.BatchPeriodDesc, dbo.I10_Amcare_VR.BatchPeriod_BC, 
                         dbo.I10_Amcare_VR.BatchYear, dbo.I10_Amcare_VR.BirthDate, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIII, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIIIDesc, 
						 dbo.I10_Amcare_VR.Blood_C1Inhibitor, 
                         dbo.I10_Amcare_VR.Blood_C1InhibitorDesc, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasma, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_CryosupernatantPlasma, 
                         dbo.I10_Amcare_VR.Blood_CryosupernatantPlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_FEIBA, 
						 dbo.I10_Amcare_VR.Blood_FEIBADesc, 
						 dbo.I10_Amcare_VR.Blood_Fibrinogen, 
						 dbo.I10_Amcare_VR.Blood_FibrinogenDesc, 
                         dbo.I10_Amcare_VR.Blood_IVIG_SCIG, 
						 dbo.I10_Amcare_VR.Blood_IVIG_SCIGDesc, 
						 dbo.I10_Amcare_VR.Blood_PCC, 
						 dbo.I10_Amcare_VR.Blood_PCCDesc, 
						 dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactors, 
                         dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactorsDesc, 
						 
						 dbo.I10_Amcare_VR.BreastFeeding, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlag, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlagDesc, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitDateIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknown, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknownDesc, dbo.I10_Amcare_VR.ClinicalDecisionUnitDateOut, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOut, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknown, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknownDesc, dbo.I10_Amcare_VR.ChangeinLegalStatus, 
                         dbo.I10_Amcare_VR.ChangeinLegalStatusDesc, dbo.I10_Amcare_VR.ChartNumber, dbo.I10_Amcare_VR.ChiefComplaint, dbo.I10_Amcare_VR.CoderNumber, dbo.I10_Amcare_VR.CoderNumberDesc, 
                         dbo.I10_Amcare_VR.CompleteRecord, dbo.I10_Amcare_VR.CompleteRecordDesc, dbo.I10_Amcare_VR.Complication, dbo.I10_Amcare_VR.ComplicationDesc, dbo.I10_Amcare_VR.Complication1, 
                         dbo.I10_Amcare_VR.Complication1Desc, dbo.I10_Amcare_VR.Complication2, dbo.I10_Amcare_VR.Complication2Desc, dbo.I10_Amcare_VR.Complication3, dbo.I10_Amcare_VR.Complication3Desc, 
                         dbo.I10_Amcare_VR.ContactMode, dbo.I10_Amcare_VR.ContactModeDesc, dbo.I10_Amcare_VR.CoronerCase, dbo.I10_Amcare_VR.CoronerCaseDesc, dbo.I10_Amcare_VR.DataEntryCoder, 
                         dbo.I10_Amcare_VR.DataEntryCoderDesc, dbo.I10_Amcare_VR.DateLeftER, dbo.I10_Amcare_VR.DateofLastMenses, dbo.I10_Amcare_VR.DateReadyforDisch, dbo.I10_Amcare_VR.DateSentToCIHI, 
                         dbo.I10_Amcare_VR.DateSentToCIHILevel1, dbo.I10_Amcare_VR.DateSentToCIHILevel2, dbo.I10_Amcare_VR.DateSentToCIHILite, dbo.I10_Amcare_VR.DeathInER, dbo.I10_Amcare_VR.DeathInERDesc, 
                         dbo.I10_Amcare_VR.DeathOnArrival, dbo.I10_Amcare_VR.DeathOnArrivalDesc, dbo.I10_Amcare_VR.DecisionAdmitDifference, dbo.I10_Amcare_VR.DecisiontoAdmitDate, dbo.I10_Amcare_VR.DecisiontoAdmitTime, 
                         dbo.I10_Amcare_VR.DecisionAdmitTimeUnknown, dbo.I10_Amcare_VR.DecisionAdmitTimeUnknownDesc, dbo.I10_Amcare_VR.DeliveryDate, dbo.I10_Amcare_VR.DeliveryTime, 
                         dbo.I10_Amcare_VR.DiedDuringIntervention, dbo.I10_Amcare_VR.DiedDuringInterventionDesc, dbo.I10_Amcare_VR.DischNursingArea, dbo.I10_Amcare_VR.DischNursingAreaDesc, 
                         dbo.I10_Amcare_VR.DischPlanning, dbo.I10_Amcare_VR.DischPlanningDesc, dbo.I10_Amcare_VR.DischargeAge, dbo.I10_Amcare_VR.DischargeDisposition, dbo.I10_Amcare_VR.DischargeDispositionDesc, 
                         dbo.I10_Amcare_VR.DispositionDate, dbo.I10_Amcare_VR.DispositionTime, dbo.I10_Amcare_VR.DispositionTimeUnknown, dbo.I10_Amcare_VR.DispositionTimeUnknownDesc, dbo.I10_Amcare_VR.ECTTreatment, 
                         dbo.I10_Amcare_VR.ECTTreatmentDesc, dbo.I10_Amcare_VR.Education, dbo.I10_Amcare_VR.EducationDesc, dbo.I10_Amcare_VR.EDVisitIndicator, dbo.I10_Amcare_VR.EDVisitIndicatorDesc, 
                         dbo.I10_Amcare_VR.Employment, dbo.I10_Amcare_VR.EmploymentDesc, dbo.I10_Amcare_VR.EntryCode, dbo.I10_Amcare_VR.EstimateDischDate, dbo.I10_Amcare_VR.ExitCode, 
                         dbo.I10_Amcare_VR.FamilyPhysicianFlag, dbo.I10_Amcare_VR.FamilyPhysicianFlagDesc, dbo.I10_Amcare_VR.FinancialSupport, dbo.I10_Amcare_VR.FinancialSupportDesc, dbo.I10_Amcare_VR.FinishDate, 
                         dbo.I10_Amcare_VR.FinishTime, dbo.I10_Amcare_VR.FirstName, dbo.I10_Amcare_VR.FullName, dbo.I10_Amcare_VR.FixedChartNumber, dbo.I10_Amcare_VR.Gender, dbo.I10_Amcare_VR.GenderDesc, 
                         dbo.I10_Amcare_VR.GestationalAgeinweeks, dbo.I10_Amcare_VR.GlasgowScale, dbo.I10_Amcare_VR.GlasgowScaleDesc, dbo.I10_Amcare_VR.GreaterTenPO, dbo.I10_Amcare_VR.HCNProvince, 
                         dbo.I10_Amcare_VR.HCNProvinceDesc, dbo.I10_Amcare_VR.HCNVersion, dbo.I10_Amcare_VR.HealthCareNumber, dbo.I10_Amcare_VR.Hospital, dbo.I10_Amcare_VR.HospitalDesc,
                         dbo.I10_Amcare_VR.HospitalAccountRecord, 
                         dbo.I10_Amcare_VR.HelmetIndicator, dbo.I10_Amcare_VR.HelmetIndicatorDesc, dbo.I10_Amcare_VR.InSCU, dbo.I10_Amcare_VR.InitialOR, dbo.I10_Amcare_VR.InitialORDesc, dbo.I10_Amcare_VR.InjuryDate, 
                         dbo.I10_Amcare_VR.Injury, dbo.I10_Amcare_VR.InjuryDesc, dbo.I10_Amcare_VR.InputDate, dbo.I10_Amcare_VR.InputTime, 

						 dbo.I10_Amcare_VR.InstitutionFrom, dbo.I10_Amcare_VR.InstitutionFromDesc, 
						 dbo.I10_Amcare_VR.InstitutionFromType, dbo.I10_Amcare_VR.InstitutionFromTypeDesc,
                         dbo.I10_Amcare_VR.InstFromCareType, dbo.I10_Amcare_VR.InstFromHospType, 
						 dbo.I10_Amcare_VR.InstitutionNumber, dbo.I10_Amcare_VR.InstitutionNumberDesc, 
						 dbo.I10_Amcare_VR.InstitutionTo, dbo.I10_Amcare_VR.InstitutionToDesc, 
						 dbo.I10_Amcare_VR.InstToCareType, dbo.I10_Amcare_VR.InstToHospType, 
						 dbo.I10_Amcare_VR.InstitutionToType, dbo.I10_Amcare_VR.InstitutionToTypeDesc, 
						 
						 dbo.I10_Amcare_VR.InterfaceDate, dbo.I10_Amcare_VR.InterfaceTime, 
                         dbo.I10_Amcare_VR.IsAbstractCompleted, dbo.I10_Amcare_VR.IsAbstractCompletedDesc, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCompletedLevel2, dbo.I10_Amcare_VR.IsAbstractCompletedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCompletedLite, dbo.I10_Amcare_VR.IsAbstractCompletedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrected, dbo.I10_Amcare_VR.IsAbstractCorrectedDesc, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCorrectedLite, dbo.I10_Amcare_VR.IsAbstractCorrectedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractDeleted, dbo.I10_Amcare_VR.IsAbstractDeletedDesc, dbo.I10_Amcare_VR.IsAbstractSubmitted, dbo.I10_Amcare_VR.IsAbstractSubmittedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLite, dbo.I10_Amcare_VR.IsAbstractSubmittedLiteDesc, dbo.I10_Amcare_VR.IsAbstractValidated, dbo.I10_Amcare_VR.IsAbstractValidatedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLevel1, dbo.I10_Amcare_VR.IsAbstractValidatedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLite, dbo.I10_Amcare_VR.IsAbstractValidatedLiteDesc, dbo.I10_Amcare_VR.IsBirthdateEstimated, dbo.I10_Amcare_VR.IsBirthdateEstimatedDesc, 
						 dbo.I10_Amcare_VR.IsCustomValidated, dbo.I10_Amcare_VR.IsCustomValidatedDesc,
                         dbo.I10_Amcare_VR.LOSDays, dbo.I10_Amcare_VR.LOSTime, dbo.I10_Amcare_VR.LOSTimeinHours, dbo.I10_Amcare_VR.LOSTotalMinutes, dbo.I10_Amcare_VR.Language, dbo.I10_Amcare_VR.LanguageDesc, 
                         dbo.I10_Amcare_VR.LastName, dbo.I10_Amcare_VR.LessTwoPO, dbo.I10_Amcare_VR.LivingArrangement, dbo.I10_Amcare_VR.LivingArrangementDesc, dbo.I10_Amcare_VR.LocationofInjury, 
                         dbo.I10_Amcare_VR.LocationofInjuryDesc, dbo.I10_Amcare_VR.MISCode, dbo.I10_Amcare_VR.MISCodeDesc, dbo.I10_Amcare_VR.MaidenName, dbo.I10_Amcare_VR.MaritalStatus, 
                         dbo.I10_Amcare_VR.MaritalStatusDesc, 
                         dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoED, 
						 dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04Desc, 
						 
						 dbo.I10_Amcare_VR.MethodofAdmission, dbo.I10_Amcare_VR.MethodofAdmissionDesc, dbo.I10_Amcare_VR.MiddleName, 
                         dbo.I10_Amcare_VR.NACRSClinicLiteSubmission, dbo.I10_Amcare_VR.NACRSClinicLiteSubmissionDesc, 
                         dbo.I10_Amcare_VR.NewbornChart, 
                         dbo.I10_Amcare_VR.NewbornDischDate, dbo.I10_Amcare_VR.NextScheduledVisitDate, dbo.I10_Amcare_VR.NextScheduledVisitTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentDate, 
                         dbo.I10_Amcare_VR.NonPhysicianAssessmentTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknown, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.NonPhysicianNumber, dbo.I10_Amcare_VR.NonPhysicianNumberDesc, dbo.I10_Amcare_VR.NonPhysicianService, dbo.I10_Amcare_VR.NonPhysicianServiceDesc, 
                         dbo.I10_Amcare_VR.NumberofECT, dbo.I10_Amcare_VR.NursingAssessmentDate, dbo.I10_Amcare_VR.NursingAssessmentTime, dbo.I10_Amcare_VR.Occupation, dbo.I10_Amcare_VR.OccupationDesc, 
                         dbo.I10_Amcare_VR.OtherMedicalDeath, dbo.I10_Amcare_VR.OtherMedicalDeathDesc, dbo.I10_Amcare_VR.OtherBlood, dbo.I10_Amcare_VR.OtherBloodDesc, dbo.I10_Amcare_VR.OtherBloodCrossMatched, 
                         dbo.I10_Amcare_VR.OtherBloodCrossMatchedDesc, dbo.I10_Amcare_VR.OtherBloodTyped, dbo.I10_Amcare_VR.OtherBloodTypedDesc, dbo.I10_Amcare_VR.OtherBloodUnits, dbo.I10_Amcare_VR.PCTASIndicator, 
                         dbo.I10_Amcare_VR.PCTASIndicatorDesc, dbo.I10_Amcare_VR.PhysicianEstLOS, dbo.I10_Amcare_VR.Plasma, dbo.I10_Amcare_VR.PlasmaDesc, dbo.I10_Amcare_VR.PlasmaCrossMatched, 
                         dbo.I10_Amcare_VR.PlasmaCrossMatchedDesc, dbo.I10_Amcare_VR.PlasmaTyped, dbo.I10_Amcare_VR.PlasmaTypedDesc, dbo.I10_Amcare_VR.PlasmaUnits, dbo.I10_Amcare_VR.Platelets, 
                         dbo.I10_Amcare_VR.PlateletsDesc, dbo.I10_Amcare_VR.PlateletsCrossMatched, dbo.I10_Amcare_VR.PlateletsCrossMatchedDesc, dbo.I10_Amcare_VR.PlateletsTyped, dbo.I10_Amcare_VR.PlateletsTypedDesc, 
                         dbo.I10_Amcare_VR.PlateletsUnits, dbo.I10_Amcare_VR.PostalCode, dbo.I10_Amcare_VR.PostalCodeDesc, dbo.I10_Amcare_VR.PostOpDays, dbo.I10_Amcare_VR.PreOpDays, 
                         dbo.I10_Amcare_VR.PreamditWorkUp, dbo.I10_Amcare_VR.PreamditWorkUpDesc, dbo.I10_Amcare_VR.Pregnancy, dbo.I10_Amcare_VR.PregnancyDesc, dbo.I10_Amcare_VR.PrevLiveBirth, 
                         dbo.I10_Amcare_VR.PreviousPsychiartricAdmissions, dbo.I10_Amcare_VR.PreviousPsychiartricAdmDesc, dbo.I10_Amcare_VR.Program, dbo.I10_Amcare_VR.ProgramDesc, dbo.I10_Amcare_VR.ProvinceNumber, 
                         dbo.I10_Amcare_VR.ProvinceNumberDesc, dbo.I10_Amcare_VR.ReasonForVisit, dbo.I10_Amcare_VR.ReasonForVisitDesc, dbo.I10_Amcare_VR.ReAdmitCode, dbo.I10_Amcare_VR.ReciprocalBillingStatus, 
                         dbo.I10_Amcare_VR.ReciprocalBillingStatusDesc, dbo.I10_Amcare_VR.RedBloodCell, dbo.I10_Amcare_VR.RedBloodCellDesc, dbo.I10_Amcare_VR.RedBloodCellCrossMatched, 
                         dbo.I10_Amcare_VR.RedBloodCellCrossMatchedDesc, dbo.I10_Amcare_VR.RedBloodCellTyped, dbo.I10_Amcare_VR.RedBloodCellTypedDesc, dbo.I10_Amcare_VR.RedBloodCellUnits, 
                         dbo.I10_Amcare_VR.ReferralDate, dbo.I10_Amcare_VR.ReferredFrom, dbo.I10_Amcare_VR.ReferredFromDesc, dbo.I10_Amcare_VR.ReferredTo, dbo.I10_Amcare_VR.ReferredToDesc, 
                         dbo.I10_Amcare_VR.ReferringProvider, dbo.I10_Amcare_VR.ReferringProviderDesc, dbo.I10_Amcare_VR.RegisterNumber, dbo.I10_Amcare_VR.RegistrationNumber, 
                         dbo.I10_Amcare_VR.RegistrationSequenceNumber, dbo.I10_Amcare_VR.RegistrationVisitDate, dbo.I10_Amcare_VR.RegistrationVisitTime, dbo.I10_Amcare_VR.ReproductiveCareComments, 
                         dbo.I10_Amcare_VR.ReserveField, dbo.I10_Amcare_VR.ResidenceCode, dbo.I10_Amcare_VR.ResidenceCodeDesc, dbo.I10_Amcare_VR.ResidenceProvince, dbo.I10_Amcare_VR.ResidenceProvinceDesc, 
                         dbo.I10_Amcare_VR.ResidenceRegion, dbo.I10_Amcare_VR.ResidenceRegionDesc, dbo.I10_Amcare_VR.ResidenceType, dbo.I10_Amcare_VR.ResidenceTypeDesc, dbo.I10_Amcare_VR.ResponsiblityForPayment,
                          dbo.I10_Amcare_VR.ResponsiblityForPaymentDesc, dbo.I10_Amcare_VR.SchedEDVisit, dbo.I10_Amcare_VR.SchedEDVisitDesc, dbo.I10_Amcare_VR.SeatbeltIndicator, dbo.I10_Amcare_VR.SeatbeltIndicatorDesc, 
                         dbo.I10_Amcare_VR.SecondChartRegisterNumber, dbo.I10_Amcare_VR.SecretVIPPatient, dbo.I10_Amcare_VR.SecretVIPPatientDesc, dbo.I10_Amcare_VR.SiteNumber, dbo.I10_Amcare_VR.SiteNumberDesc, 
                         dbo.I10_Amcare_VR.SocialService, dbo.I10_Amcare_VR.SocialServiceDesc, dbo.I10_Amcare_VR.SourceofReferral, dbo.I10_Amcare_VR.SourceofReferralDesc, dbo.I10_Amcare_VR.SpecialistNumber, 
                         dbo.I10_Amcare_VR.SpecialistNumberDesc, dbo.I10_Amcare_VR.SpecialistRequestDate, dbo.I10_Amcare_VR.SpecialistRequestService, dbo.I10_Amcare_VR.SpecialistRequestServiceDesc, 
                         dbo.I10_Amcare_VR.SpecialistRequestTime, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknown, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknownDesc, dbo.I10_Amcare_VR.StakeholderType, 
                         dbo.I10_Amcare_VR.StakeholderTypeDesc, dbo.I10_Amcare_VR.StatusAfterTriage, dbo.I10_Amcare_VR.StatusAfterTriageDesc, dbo.I10_Amcare_VR.Sterilization, dbo.I10_Amcare_VR.SterilizationDesc, 
                         dbo.I10_Amcare_VR.SubmissionLevelCode, dbo.I10_Amcare_VR.SubmissionRecordID, dbo.I10_Amcare_VR.SubsequentOR, dbo.I10_Amcare_VR.SubsequentORDesc, dbo.I10_Amcare_VR.Suicide, 
                         dbo.I10_Amcare_VR.SuicideDesc, dbo.I10_Amcare_VR.SurgicalCase, dbo.I10_Amcare_VR.SurgicalCaseDesc, dbo.I10_Amcare_VR.TimeLeftER, dbo.I10_Amcare_VR.TimeLeftERUnknown, 
                         dbo.I10_Amcare_VR.TimeLeftERUnknownDEsc, dbo.I10_Amcare_VR.TransferOverloadDate, dbo.I10_Amcare_VR.TransferOverloadTime, dbo.I10_Amcare_VR.TransferOverloadTimeDifference, 
                         dbo.I10_Amcare_VR.TransfusionGiven, dbo.I10_Amcare_VR.TransfusionGivenDesc, dbo.I10_Amcare_VR.Trauma, dbo.I10_Amcare_VR.TraumaDesc, dbo.I10_Amcare_VR.TriageDate, 
                         dbo.I10_Amcare_VR.TriageLevel, dbo.I10_Amcare_VR.TriageLevelDesc, dbo.I10_Amcare_VR.TriageTime, dbo.I10_Amcare_VR.TriageTimeUnknown, dbo.I10_Amcare_VR.TriageTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.TSICoder, dbo.I10_Amcare_VR.TSICoderDesc, dbo.I10_Amcare_VR.TSIDate, dbo.I10_Amcare_VR.TSITime, dbo.I10_Amcare_VR.TwoTenPO, dbo.I10_Amcare_VR.ULI, 
                         dbo.I10_Amcare_VR.UniversalEpisodeIdentifier, dbo.I10_Amcare_VR.UnplannedReadmit, dbo.I10_Amcare_VR.VisitStatus, dbo.I10_Amcare_VR.VisitStatusDesc, dbo.I10_Amcare_VR.VisitType, dbo.I10_Amcare_VR.VisitTypeDesc, 
                         dbo.I10_Amcare_VR.WaitTimeinER, dbo.I10_Amcare_VR.WaittoAssessmentinMinutes, dbo.I10_Amcare_VR.WaittoNursingAssessmentDiff, dbo.I10_Amcare_VR.Weight, dbo.I10_Amcare_VR.zzAbstractLink, 
                         dbo.I10_Amcare_VR.zzRegionalPatientID, dbo.I10_Amcare_VR.zzVolumeLink, 

						 dbo.I10_Amcare_Projects_340_VR.ProjectNumber, dbo.I10_Amcare_Projects_340_VR.ProjectNumberDesc, 
                         dbo.I10_Amcare_Projects_340_VR.ProjectOccurrence, dbo.I10_Amcare_Projects_340_VR.CT_MRIScanWithin24HoursEDArrival, dbo.I10_Amcare_Projects_340_VR.CT_MRIScanWithin24HoursEDArrivalDesc, 
                         dbo.I10_Amcare_Projects_340_VR.ReferralToStrokePreventionServicesEDDischarge, dbo.I10_Amcare_Projects_340_VR.ReferralToStrokePreventionServicesEDDischargeDesc, 
                         dbo.I10_Amcare_Projects_340_VR.AdministrationAcuteThrombolysis, dbo.I10_Amcare_Projects_340_VR.AdministrationAcuteThrombolysisDesc, 
                         dbo.I10_Amcare_Projects_340_VR.MonthOfAcuteThrombolysisAdministration, dbo.I10_Amcare_Projects_340_VR.DayOfAcuteThrombolysisAdministration, 
                         dbo.I10_Amcare_Projects_340_VR.HourOfAcuteThrombolysisAdministration, dbo.I10_Amcare_Projects_340_VR.MinuteOfAcuteThrombolysisAdministration, 
                         dbo.I10_Amcare_Projects_340_VR.PrescriptionForAntithromboticMedicationDischarge, dbo.I10_Amcare_Projects_340_VR.PrescriptionForAntithromboticMedicationDischargeDesc, 
                         dbo.I10_Amcare_Projects_340_VR.StrokeSymptomOnsetDate, dbo.I10_Amcare_Projects_340_VR.StrokeSymptomOnsetDateUnknown, dbo.I10_Amcare_Projects_340_VR.StrokeSymptomOnsetTime, 
                         dbo.I10_Amcare_Projects_340_VR.StrokeSymptomOnsetTimeUnknown
FROM            dbo.I10_Amcare_VR INNER JOIN
                         dbo.I10_Amcare_Projects_340_VR ON dbo.I10_Amcare_VR.zzAbstractLink = dbo.I10_Amcare_Projects_340_VR.zzAbstractLink



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Project_640_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_Amcare_And_Project_640_VR]
AS
SELECT        dbo.I10_Amcare_VR.[#ofPreviousPreTermDeliveries], dbo.I10_Amcare_VR.[#ofPrevSpontaneousAbortions], dbo.I10_Amcare_VR.[#ofPreviousTermDeliveries], dbo.I10_Amcare_VR.AccessPrimaryHealthCareCode, 
                         dbo.I10_Amcare_VR.AccessPrimaryHealthCareCodeDesc, dbo.I10_Amcare_VR.AmbulanceArrivalDate, dbo.I10_Amcare_VR.AmbulanceArrivalTime, dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknown, 
                         dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknownDesc, dbo.I10_Amcare_VR.AmbulanceTransferCareDate, dbo.I10_Amcare_VR.AmbulanceTransferCareTime, 
                         dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknown, dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknownDesc, dbo.I10_Amcare_VR.[#ofPrevTherapeuticAbortions], dbo.I10_Amcare_VR.AWOL, 
                         dbo.I10_Amcare_VR.AWOLDesc, dbo.I10_Amcare_VR.AbortDate, dbo.I10_Amcare_VR.AbstractNumber, dbo.I10_Amcare_VR.AbstractOverflow, dbo.I10_Amcare_VR.AbstractOverflowDesc, 
                         dbo.I10_Amcare_VR.ActivityDescription, dbo.I10_Amcare_VR.ActivityWhenInjured, dbo.I10_Amcare_VR.ActivityWhenInjuredDesc, dbo.I10_Amcare_VR.ActueLOS, dbo.I10_Amcare_VR.AdmitbyAmbulance, 
                         dbo.I10_Amcare_VR.AdmitbyAmbulanceDesc, dbo.I10_Amcare_VR.AdmitCategory, dbo.I10_Amcare_VR.AdmitDiagnosis, dbo.I10_Amcare_VR.AdmitNursingArea, dbo.I10_Amcare_VR.AdmitNursingAreaDesc, 
                         dbo.I10_Amcare_VR.AfterAdmit, dbo.I10_Amcare_VR.AgeCode, dbo.I10_Amcare_VR.AgeCodeDesc, dbo.I10_Amcare_VR.AgeGroup, dbo.I10_Amcare_VR.AgeNumber, dbo.I10_Amcare_VR.Albumin, 
                         dbo.I10_Amcare_VR.AlbuminDesc, dbo.I10_Amcare_VR.AlbuminCrossMatched, dbo.I10_Amcare_VR.AlbuminCrossMatchedDesc, dbo.I10_Amcare_VR.AlbuminTyped, dbo.I10_Amcare_VR.AlbuminTypedDesc, 
                         dbo.I10_Amcare_VR.AlbuminUnits, dbo.I10_Amcare_VR.ALCLOS, dbo.I10_Amcare_VR.AmbulanceReportNumber, dbo.I10_Amcare_VR.AmCareGroup, dbo.I10_Amcare_VR.AmCareGroupDesc, 
                         dbo.I10_Amcare_VR.AmcareCareType, dbo.I10_Amcare_VR.AmcareCareTypeDesc, dbo.I10_Amcare_VR.AmcareTypeCode, dbo.I10_Amcare_VR.AmcareTypeCodeDesc, dbo.I10_Amcare_VR.Ancil13, 
                         dbo.I10_Amcare_VR.Ancil14, dbo.I10_Amcare_VR.Ancil15, dbo.I10_Amcare_VR.Ancil16, dbo.I10_Amcare_VR.Ancil17, dbo.I10_Amcare_VR.AncillaryField1, dbo.I10_Amcare_VR.AncillaryField1Desc, 
                         dbo.I10_Amcare_VR.AncillaryField10, dbo.I10_Amcare_VR.AncillaryField10Desc, dbo.I10_Amcare_VR.AncillaryField11, dbo.I10_Amcare_VR.AncillaryField11Desc, dbo.I10_Amcare_VR.AncillaryField12, 
                         dbo.I10_Amcare_VR.AncillaryField12Desc, dbo.I10_Amcare_VR.AncillaryField2, dbo.I10_Amcare_VR.AncillaryField2Desc, dbo.I10_Amcare_VR.AncillaryField3, dbo.I10_Amcare_VR.AncillaryField3Desc, 
                         dbo.I10_Amcare_VR.AncillaryField4, dbo.I10_Amcare_VR.AncillaryField4Desc, dbo.I10_Amcare_VR.AncillaryField5, dbo.I10_Amcare_VR.AncillaryField5Desc, dbo.I10_Amcare_VR.AncillaryField6, 
                         dbo.I10_Amcare_VR.AncillaryField6Desc, dbo.I10_Amcare_VR.AncillaryField7, dbo.I10_Amcare_VR.AncillaryField7Desc, dbo.I10_Amcare_VR.AncillaryField8, dbo.I10_Amcare_VR.AncillaryField8Desc, 
                         dbo.I10_Amcare_VR.AncillaryField9, dbo.I10_Amcare_VR.AncillaryField9Desc, dbo.I10_Amcare_VR.ArrivalDate, dbo.I10_Amcare_VR.ArrivalMode, dbo.I10_Amcare_VR.ArrivalModeDesc, 
                         dbo.I10_Amcare_VR.ArrivalTime, dbo.I10_Amcare_VR.ArrivaltoTriageTime, dbo.I10_Amcare_VR.AssessmentDate, dbo.I10_Amcare_VR.AssessmentTime, dbo.I10_Amcare_VR.AssessmentTimeUnknown, 
                         dbo.I10_Amcare_VR.AssessmentTimeUnknownDesc, dbo.I10_Amcare_VR.AttendingPhysician, dbo.I10_Amcare_VR.AttendingPhysicianDesc, dbo.I10_Amcare_VR.AutoTransfusion, 
                         dbo.I10_Amcare_VR.AutoTransfusionDesc, dbo.I10_Amcare_VR.AutopsyPerformed, dbo.I10_Amcare_VR.AutopsyPerformedDesc, dbo.I10_Amcare_VR.BasicOption1, dbo.I10_Amcare_VR.BasicOption1Desc, 
                         dbo.I10_Amcare_VR.BasicOption10, dbo.I10_Amcare_VR.BasicOption10Desc, dbo.I10_Amcare_VR.BasicOption11, dbo.I10_Amcare_VR.BasicOption11Desc, dbo.I10_Amcare_VR.BasicOption12, 
                         dbo.I10_Amcare_VR.BasicOption12Desc, dbo.I10_Amcare_VR.BasicOption13, dbo.I10_Amcare_VR.BasicOption13Desc, dbo.I10_Amcare_VR.BasicOption14, dbo.I10_Amcare_VR.BasicOption14Desc, 
                         dbo.I10_Amcare_VR.BasicOption15, dbo.I10_Amcare_VR.BasicOption15Desc, dbo.I10_Amcare_VR.BasicOption16, dbo.I10_Amcare_VR.BasicOption16Desc, dbo.I10_Amcare_VR.BasicOption17, 
                         dbo.I10_Amcare_VR.BasicOption17Desc, dbo.I10_Amcare_VR.BasicOption18, dbo.I10_Amcare_VR.BasicOption18Desc, dbo.I10_Amcare_VR.BasicOption19, dbo.I10_Amcare_VR.BasicOption19Desc, 
                         dbo.I10_Amcare_VR.BasicOption2, dbo.I10_Amcare_VR.BasicOption2Desc, dbo.I10_Amcare_VR.BasicOption3, dbo.I10_Amcare_VR.BasicOption3Desc, dbo.I10_Amcare_VR.BasicOption4, 
                         dbo.I10_Amcare_VR.BasicOption4Desc, dbo.I10_Amcare_VR.BasicOption5, dbo.I10_Amcare_VR.BasicOption5Desc, dbo.I10_Amcare_VR.BasicOption6, dbo.I10_Amcare_VR.BasicOption6Desc, 
                         dbo.I10_Amcare_VR.BasicOption7, dbo.I10_Amcare_VR.BasicOption7Desc, dbo.I10_Amcare_VR.BasicOption8, dbo.I10_Amcare_VR.BasicOption8Desc, dbo.I10_Amcare_VR.BasicOption9, 
                         dbo.I10_Amcare_VR.BasicOption9Desc, dbo.I10_Amcare_VR.BatchNumber, dbo.I10_Amcare_VR.BatchPeriod, dbo.I10_Amcare_VR.BatchPeriodDesc, dbo.I10_Amcare_VR.BatchPeriod_BC, 
                         dbo.I10_Amcare_VR.BatchYear, dbo.I10_Amcare_VR.BirthDate, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIII, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIIIDesc, 
						 dbo.I10_Amcare_VR.Blood_C1Inhibitor, 
                         dbo.I10_Amcare_VR.Blood_C1InhibitorDesc, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasma, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_CryosupernatantPlasma, 
                         dbo.I10_Amcare_VR.Blood_CryosupernatantPlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_FEIBA, 
						 dbo.I10_Amcare_VR.Blood_FEIBADesc, 
						 dbo.I10_Amcare_VR.Blood_Fibrinogen, 
						 dbo.I10_Amcare_VR.Blood_FibrinogenDesc, 
                         dbo.I10_Amcare_VR.Blood_IVIG_SCIG, 
						 dbo.I10_Amcare_VR.Blood_IVIG_SCIGDesc, 
						 dbo.I10_Amcare_VR.Blood_PCC, 
						 dbo.I10_Amcare_VR.Blood_PCCDesc, 
						 dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactors, 
                         dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactorsDesc, 
						 
						 dbo.I10_Amcare_VR.BreastFeeding, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlag, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlagDesc, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitDateIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknown, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknownDesc, dbo.I10_Amcare_VR.ClinicalDecisionUnitDateOut, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOut, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknown, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknownDesc, dbo.I10_Amcare_VR.ChangeinLegalStatus, 
                         dbo.I10_Amcare_VR.ChangeinLegalStatusDesc, dbo.I10_Amcare_VR.ChartNumber, dbo.I10_Amcare_VR.ChiefComplaint, dbo.I10_Amcare_VR.CoderNumber, dbo.I10_Amcare_VR.CoderNumberDesc, 
                         dbo.I10_Amcare_VR.CompleteRecord, dbo.I10_Amcare_VR.CompleteRecordDesc, dbo.I10_Amcare_VR.Complication, dbo.I10_Amcare_VR.ComplicationDesc, dbo.I10_Amcare_VR.Complication1, 
                         dbo.I10_Amcare_VR.Complication1Desc, dbo.I10_Amcare_VR.Complication2, dbo.I10_Amcare_VR.Complication2Desc, dbo.I10_Amcare_VR.Complication3, dbo.I10_Amcare_VR.Complication3Desc, 
                         dbo.I10_Amcare_VR.ContactMode, dbo.I10_Amcare_VR.ContactModeDesc, dbo.I10_Amcare_VR.CoronerCase, dbo.I10_Amcare_VR.CoronerCaseDesc, dbo.I10_Amcare_VR.DataEntryCoder, 
                         dbo.I10_Amcare_VR.DataEntryCoderDesc, dbo.I10_Amcare_VR.DateLeftER, dbo.I10_Amcare_VR.DateofLastMenses, dbo.I10_Amcare_VR.DateReadyforDisch, dbo.I10_Amcare_VR.DateSentToCIHI, 
                         dbo.I10_Amcare_VR.DateSentToCIHILevel1, dbo.I10_Amcare_VR.DateSentToCIHILevel2, dbo.I10_Amcare_VR.DateSentToCIHILite, dbo.I10_Amcare_VR.DeathInER, dbo.I10_Amcare_VR.DeathInERDesc, 
                         dbo.I10_Amcare_VR.DeathOnArrival, dbo.I10_Amcare_VR.DeathOnArrivalDesc, dbo.I10_Amcare_VR.DecisionAdmitDifference, dbo.I10_Amcare_VR.DecisiontoAdmitDate, dbo.I10_Amcare_VR.DecisiontoAdmitTime, 
                         dbo.I10_Amcare_VR.DecisionAdmitTimeUnknown, dbo.I10_Amcare_VR.DecisionAdmitTimeUnknownDesc, dbo.I10_Amcare_VR.DeliveryDate, dbo.I10_Amcare_VR.DeliveryTime, 
                         dbo.I10_Amcare_VR.DiedDuringIntervention, dbo.I10_Amcare_VR.DiedDuringInterventionDesc, dbo.I10_Amcare_VR.DischNursingArea, dbo.I10_Amcare_VR.DischNursingAreaDesc, 
                         dbo.I10_Amcare_VR.DischPlanning, dbo.I10_Amcare_VR.DischPlanningDesc, dbo.I10_Amcare_VR.DischargeAge, dbo.I10_Amcare_VR.DischargeDisposition, dbo.I10_Amcare_VR.DischargeDispositionDesc, 
                         dbo.I10_Amcare_VR.DispositionDate, dbo.I10_Amcare_VR.DispositionTime, dbo.I10_Amcare_VR.DispositionTimeUnknown, dbo.I10_Amcare_VR.DispositionTimeUnknownDesc, dbo.I10_Amcare_VR.ECTTreatment, 
                         dbo.I10_Amcare_VR.ECTTreatmentDesc, dbo.I10_Amcare_VR.Education, dbo.I10_Amcare_VR.EducationDesc, dbo.I10_Amcare_VR.EDVisitIndicator, dbo.I10_Amcare_VR.EDVisitIndicatorDesc, 
                         dbo.I10_Amcare_VR.Employment, dbo.I10_Amcare_VR.EmploymentDesc, dbo.I10_Amcare_VR.EntryCode, dbo.I10_Amcare_VR.EstimateDischDate, dbo.I10_Amcare_VR.ExitCode, 
                         dbo.I10_Amcare_VR.FamilyPhysicianFlag, dbo.I10_Amcare_VR.FamilyPhysicianFlagDesc, dbo.I10_Amcare_VR.FinancialSupport, dbo.I10_Amcare_VR.FinancialSupportDesc, dbo.I10_Amcare_VR.FinishDate, 
                         dbo.I10_Amcare_VR.FinishTime, dbo.I10_Amcare_VR.FirstName, dbo.I10_Amcare_VR.FullName, dbo.I10_Amcare_VR.FixedChartNumber, dbo.I10_Amcare_VR.Gender, dbo.I10_Amcare_VR.GenderDesc, 
                         dbo.I10_Amcare_VR.GestationalAgeinweeks, dbo.I10_Amcare_VR.GlasgowScale, dbo.I10_Amcare_VR.GlasgowScaleDesc, dbo.I10_Amcare_VR.GreaterTenPO, dbo.I10_Amcare_VR.HCNProvince, 
                         dbo.I10_Amcare_VR.HCNProvinceDesc, dbo.I10_Amcare_VR.HCNVersion, dbo.I10_Amcare_VR.HealthCareNumber, dbo.I10_Amcare_VR.Hospital, dbo.I10_Amcare_VR.HospitalDesc, 
                         dbo.I10_Amcare_VR.HospitalAccountRecord,
                         dbo.I10_Amcare_VR.HelmetIndicator, dbo.I10_Amcare_VR.HelmetIndicatorDesc, dbo.I10_Amcare_VR.InSCU, dbo.I10_Amcare_VR.InitialOR, dbo.I10_Amcare_VR.InitialORDesc, dbo.I10_Amcare_VR.InjuryDate, 
                         dbo.I10_Amcare_VR.Injury, dbo.I10_Amcare_VR.InjuryDesc, dbo.I10_Amcare_VR.InputDate, dbo.I10_Amcare_VR.InputTime, 

						 dbo.I10_Amcare_VR.InstitutionFrom, dbo.I10_Amcare_VR.InstitutionFromDesc, 
						 dbo.I10_Amcare_VR.InstitutionFromType, dbo.I10_Amcare_VR.InstitutionFromTypeDesc,
                         dbo.I10_Amcare_VR.InstFromCareType, dbo.I10_Amcare_VR.InstFromHospType, 
						 dbo.I10_Amcare_VR.InstitutionNumber, dbo.I10_Amcare_VR.InstitutionNumberDesc, 
						 dbo.I10_Amcare_VR.InstitutionTo, dbo.I10_Amcare_VR.InstitutionToDesc, 
						 dbo.I10_Amcare_VR.InstToCareType, dbo.I10_Amcare_VR.InstToHospType, 
						 dbo.I10_Amcare_VR.InstitutionToType, dbo.I10_Amcare_VR.InstitutionToTypeDesc, 
						 
						 dbo.I10_Amcare_VR.InterfaceDate, dbo.I10_Amcare_VR.InterfaceTime, 
                         dbo.I10_Amcare_VR.IsAbstractCompleted, dbo.I10_Amcare_VR.IsAbstractCompletedDesc, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCompletedLevel2, dbo.I10_Amcare_VR.IsAbstractCompletedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCompletedLite, dbo.I10_Amcare_VR.IsAbstractCompletedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrected, dbo.I10_Amcare_VR.IsAbstractCorrectedDesc, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCorrectedLite, dbo.I10_Amcare_VR.IsAbstractCorrectedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractDeleted, dbo.I10_Amcare_VR.IsAbstractDeletedDesc, dbo.I10_Amcare_VR.IsAbstractSubmitted, dbo.I10_Amcare_VR.IsAbstractSubmittedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLite, dbo.I10_Amcare_VR.IsAbstractSubmittedLiteDesc, dbo.I10_Amcare_VR.IsAbstractValidated, dbo.I10_Amcare_VR.IsAbstractValidatedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLevel1, dbo.I10_Amcare_VR.IsAbstractValidatedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLite, dbo.I10_Amcare_VR.IsAbstractValidatedLiteDesc, dbo.I10_Amcare_VR.IsBirthdateEstimated, dbo.I10_Amcare_VR.IsBirthdateEstimatedDesc, 
						 dbo.I10_Amcare_VR.IsCustomValidated, dbo.I10_Amcare_VR.IsCustomValidatedDesc,
                         dbo.I10_Amcare_VR.LOSDays, dbo.I10_Amcare_VR.LOSTime, dbo.I10_Amcare_VR.LOSTimeinHours, dbo.I10_Amcare_VR.LOSTotalMinutes, dbo.I10_Amcare_VR.Language, dbo.I10_Amcare_VR.LanguageDesc, 
                         dbo.I10_Amcare_VR.LastName, dbo.I10_Amcare_VR.LessTwoPO, dbo.I10_Amcare_VR.LivingArrangement, dbo.I10_Amcare_VR.LivingArrangementDesc, dbo.I10_Amcare_VR.LocationofInjury, 
                         dbo.I10_Amcare_VR.LocationofInjuryDesc, dbo.I10_Amcare_VR.MISCode, dbo.I10_Amcare_VR.MISCodeDesc, dbo.I10_Amcare_VR.MaidenName, dbo.I10_Amcare_VR.MaritalStatus, 
                         dbo.I10_Amcare_VR.MaritalStatusDesc, 
                         dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoED, 
						 dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04Desc, 
						 
						 dbo.I10_Amcare_VR.MethodofAdmission, dbo.I10_Amcare_VR.MethodofAdmissionDesc, dbo.I10_Amcare_VR.MiddleName, 
                         dbo.I10_Amcare_VR.NACRSClinicLiteSubmission, dbo.I10_Amcare_VR.NACRSClinicLiteSubmissionDesc, 
                         dbo.I10_Amcare_VR.NewbornChart, 
                         dbo.I10_Amcare_VR.NewbornDischDate, dbo.I10_Amcare_VR.NextScheduledVisitDate, dbo.I10_Amcare_VR.NextScheduledVisitTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentDate, 
                         dbo.I10_Amcare_VR.NonPhysicianAssessmentTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknown, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.NonPhysicianNumber, dbo.I10_Amcare_VR.NonPhysicianNumberDesc, dbo.I10_Amcare_VR.NonPhysicianService, dbo.I10_Amcare_VR.NonPhysicianServiceDesc, 
                         dbo.I10_Amcare_VR.NumberofECT, dbo.I10_Amcare_VR.NursingAssessmentDate, dbo.I10_Amcare_VR.NursingAssessmentTime, dbo.I10_Amcare_VR.Occupation, dbo.I10_Amcare_VR.OccupationDesc, 
                         dbo.I10_Amcare_VR.OtherMedicalDeath, dbo.I10_Amcare_VR.OtherMedicalDeathDesc, dbo.I10_Amcare_VR.OtherBlood, dbo.I10_Amcare_VR.OtherBloodDesc, dbo.I10_Amcare_VR.OtherBloodCrossMatched, 
                         dbo.I10_Amcare_VR.OtherBloodCrossMatchedDesc, dbo.I10_Amcare_VR.OtherBloodTyped, dbo.I10_Amcare_VR.OtherBloodTypedDesc, dbo.I10_Amcare_VR.OtherBloodUnits, dbo.I10_Amcare_VR.PCTASIndicator, 
                         dbo.I10_Amcare_VR.PCTASIndicatorDesc, dbo.I10_Amcare_VR.PhysicianEstLOS, dbo.I10_Amcare_VR.Plasma, dbo.I10_Amcare_VR.PlasmaDesc, dbo.I10_Amcare_VR.PlasmaCrossMatched, 
                         dbo.I10_Amcare_VR.PlasmaCrossMatchedDesc, dbo.I10_Amcare_VR.PlasmaTyped, dbo.I10_Amcare_VR.PlasmaTypedDesc, dbo.I10_Amcare_VR.PlasmaUnits, dbo.I10_Amcare_VR.Platelets, 
                         dbo.I10_Amcare_VR.PlateletsDesc, dbo.I10_Amcare_VR.PlateletsCrossMatched, dbo.I10_Amcare_VR.PlateletsCrossMatchedDesc, dbo.I10_Amcare_VR.PlateletsTyped, dbo.I10_Amcare_VR.PlateletsTypedDesc, 
                         dbo.I10_Amcare_VR.PlateletsUnits, dbo.I10_Amcare_VR.PostalCode, dbo.I10_Amcare_VR.PostalCodeDesc, dbo.I10_Amcare_VR.PostOpDays, dbo.I10_Amcare_VR.PreOpDays, 
                         dbo.I10_Amcare_VR.PreamditWorkUp, dbo.I10_Amcare_VR.PreamditWorkUpDesc, dbo.I10_Amcare_VR.Pregnancy, dbo.I10_Amcare_VR.PregnancyDesc, dbo.I10_Amcare_VR.PrevLiveBirth, 
                         dbo.I10_Amcare_VR.PreviousPsychiartricAdmissions, dbo.I10_Amcare_VR.PreviousPsychiartricAdmDesc, dbo.I10_Amcare_VR.Program, dbo.I10_Amcare_VR.ProgramDesc, dbo.I10_Amcare_VR.ProvinceNumber, 
                         dbo.I10_Amcare_VR.ProvinceNumberDesc, dbo.I10_Amcare_VR.ReasonForVisit, dbo.I10_Amcare_VR.ReasonForVisitDesc, dbo.I10_Amcare_VR.ReAdmitCode, dbo.I10_Amcare_VR.ReciprocalBillingStatus, 
                         dbo.I10_Amcare_VR.ReciprocalBillingStatusDesc, dbo.I10_Amcare_VR.RedBloodCell, dbo.I10_Amcare_VR.RedBloodCellDesc, dbo.I10_Amcare_VR.RedBloodCellCrossMatched, 
                         dbo.I10_Amcare_VR.RedBloodCellCrossMatchedDesc, dbo.I10_Amcare_VR.RedBloodCellTyped, dbo.I10_Amcare_VR.RedBloodCellTypedDesc, dbo.I10_Amcare_VR.RedBloodCellUnits, 
                         dbo.I10_Amcare_VR.ReferralDate, dbo.I10_Amcare_VR.ReferredFrom, dbo.I10_Amcare_VR.ReferredFromDesc, dbo.I10_Amcare_VR.ReferredTo, dbo.I10_Amcare_VR.ReferredToDesc, 
                         dbo.I10_Amcare_VR.ReferringProvider, dbo.I10_Amcare_VR.ReferringProviderDesc, dbo.I10_Amcare_VR.RegisterNumber, dbo.I10_Amcare_VR.RegistrationNumber, 
                         dbo.I10_Amcare_VR.RegistrationSequenceNumber, dbo.I10_Amcare_VR.RegistrationVisitDate, dbo.I10_Amcare_VR.RegistrationVisitTime, dbo.I10_Amcare_VR.ReproductiveCareComments, 
                         dbo.I10_Amcare_VR.ReserveField, dbo.I10_Amcare_VR.ResidenceCode, dbo.I10_Amcare_VR.ResidenceCodeDesc, dbo.I10_Amcare_VR.ResidenceProvince, dbo.I10_Amcare_VR.ResidenceProvinceDesc, 
                         dbo.I10_Amcare_VR.ResidenceRegion, dbo.I10_Amcare_VR.ResidenceRegionDesc, dbo.I10_Amcare_VR.ResidenceType, dbo.I10_Amcare_VR.ResidenceTypeDesc, dbo.I10_Amcare_VR.ResponsiblityForPayment,
                          dbo.I10_Amcare_VR.ResponsiblityForPaymentDesc, dbo.I10_Amcare_VR.SchedEDVisit, dbo.I10_Amcare_VR.SchedEDVisitDesc, dbo.I10_Amcare_VR.SeatbeltIndicator, dbo.I10_Amcare_VR.SeatbeltIndicatorDesc, 
                         dbo.I10_Amcare_VR.SecondChartRegisterNumber, dbo.I10_Amcare_VR.SecretVIPPatient, dbo.I10_Amcare_VR.SecretVIPPatientDesc, dbo.I10_Amcare_VR.SiteNumber, dbo.I10_Amcare_VR.SiteNumberDesc, 
                         dbo.I10_Amcare_VR.SocialService, dbo.I10_Amcare_VR.SocialServiceDesc, dbo.I10_Amcare_VR.SourceofReferral, dbo.I10_Amcare_VR.SourceofReferralDesc, dbo.I10_Amcare_VR.SpecialistNumber, 
                         dbo.I10_Amcare_VR.SpecialistNumberDesc, dbo.I10_Amcare_VR.SpecialistRequestDate, dbo.I10_Amcare_VR.SpecialistRequestService, dbo.I10_Amcare_VR.SpecialistRequestServiceDesc, 
                         dbo.I10_Amcare_VR.SpecialistRequestTime, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknown, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknownDesc, dbo.I10_Amcare_VR.StakeholderType, 
                         dbo.I10_Amcare_VR.StakeholderTypeDesc, dbo.I10_Amcare_VR.StatusAfterTriage, dbo.I10_Amcare_VR.StatusAfterTriageDesc, dbo.I10_Amcare_VR.Sterilization, dbo.I10_Amcare_VR.SterilizationDesc, 
                         dbo.I10_Amcare_VR.SubmissionLevelCode, dbo.I10_Amcare_VR.SubmissionRecordID, dbo.I10_Amcare_VR.SubsequentOR, dbo.I10_Amcare_VR.SubsequentORDesc, dbo.I10_Amcare_VR.Suicide, 
                         dbo.I10_Amcare_VR.SuicideDesc, dbo.I10_Amcare_VR.SurgicalCase, dbo.I10_Amcare_VR.SurgicalCaseDesc, dbo.I10_Amcare_VR.TimeLeftER, dbo.I10_Amcare_VR.TimeLeftERUnknown, 
                         dbo.I10_Amcare_VR.TimeLeftERUnknownDEsc, dbo.I10_Amcare_VR.TransferOverloadDate, dbo.I10_Amcare_VR.TransferOverloadTime, dbo.I10_Amcare_VR.TransferOverloadTimeDifference, 
                         dbo.I10_Amcare_VR.TransfusionGiven, dbo.I10_Amcare_VR.TransfusionGivenDesc, dbo.I10_Amcare_VR.Trauma, dbo.I10_Amcare_VR.TraumaDesc, dbo.I10_Amcare_VR.TriageDate, 
                         dbo.I10_Amcare_VR.TriageLevel, dbo.I10_Amcare_VR.TriageLevelDesc, dbo.I10_Amcare_VR.TriageTime, dbo.I10_Amcare_VR.TriageTimeUnknown, dbo.I10_Amcare_VR.TriageTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.TSICoder, dbo.I10_Amcare_VR.TSICoderDesc, dbo.I10_Amcare_VR.TSIDate, dbo.I10_Amcare_VR.TSITime, dbo.I10_Amcare_VR.TwoTenPO, dbo.I10_Amcare_VR.ULI, 
                         dbo.I10_Amcare_VR.UniversalEpisodeIdentifier, dbo.I10_Amcare_VR.UnplannedReadmit, dbo.I10_Amcare_VR.VisitStatus, dbo.I10_Amcare_VR.VisitStatusDesc, dbo.I10_Amcare_VR.VisitType, dbo.I10_Amcare_VR.VisitTypeDesc, 
                         dbo.I10_Amcare_VR.WaitTimeinER, dbo.I10_Amcare_VR.WaittoAssessmentinMinutes, dbo.I10_Amcare_VR.WaittoNursingAssessmentDiff, dbo.I10_Amcare_VR.Weight, dbo.I10_Amcare_VR.zzAbstractLink, 
                         dbo.I10_Amcare_VR.zzRegionalPatientID, dbo.I10_Amcare_VR.zzVolumeLink, 

                         dbo.I10_Amcare_Projects_640_VR.ProjectNumber, dbo.I10_Amcare_Projects_640_VR.ProjectNumberDesc, dbo.I10_Amcare_Projects_640_VR.ProjectOccurrence, 
                         dbo.I10_Amcare_Projects_640_VR.DysphagiaScreening, dbo.I10_Amcare_Projects_640_VR.DysphagiaScreeningDesc, dbo.I10_Amcare_Projects_640_VR.TelestrokeConsultation, 
                         dbo.I10_Amcare_Projects_640_VR.TelestrokeConsultationDesc
FROM            dbo.I10_Amcare_VR LEFT OUTER JOIN
                         dbo.I10_Amcare_Projects_640_VR ON dbo.I10_Amcare_VR.zzAbstractLink = dbo.I10_Amcare_Projects_640_VR.zzAbstractLink



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Project_740_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_Amcare_And_Project_740_VR]
AS
SELECT        dbo.I10_Amcare_VR.[#ofPreviousPreTermDeliveries], dbo.I10_Amcare_VR.[#ofPrevSpontaneousAbortions], dbo.I10_Amcare_VR.[#ofPreviousTermDeliveries], dbo.I10_Amcare_VR.AccessPrimaryHealthCareCode, 
                         dbo.I10_Amcare_VR.AccessPrimaryHealthCareCodeDesc, dbo.I10_Amcare_VR.AmbulanceArrivalDate, dbo.I10_Amcare_VR.AmbulanceArrivalTime, dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknown, 
                         dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknownDesc, dbo.I10_Amcare_VR.AmbulanceTransferCareDate, dbo.I10_Amcare_VR.AmbulanceTransferCareTime, 
                         dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknown, dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknownDesc, dbo.I10_Amcare_VR.[#ofPrevTherapeuticAbortions], dbo.I10_Amcare_VR.AWOL, 
                         dbo.I10_Amcare_VR.AWOLDesc, dbo.I10_Amcare_VR.AbortDate, dbo.I10_Amcare_VR.AbstractNumber, dbo.I10_Amcare_VR.AbstractOverflow, dbo.I10_Amcare_VR.AbstractOverflowDesc, 
                         dbo.I10_Amcare_VR.ActivityDescription, dbo.I10_Amcare_VR.ActivityWhenInjured, dbo.I10_Amcare_VR.ActivityWhenInjuredDesc, dbo.I10_Amcare_VR.ActueLOS, dbo.I10_Amcare_VR.AdmitbyAmbulance, 
                         dbo.I10_Amcare_VR.AdmitbyAmbulanceDesc, dbo.I10_Amcare_VR.AdmitCategory, dbo.I10_Amcare_VR.AdmitDiagnosis, dbo.I10_Amcare_VR.AdmitNursingArea, dbo.I10_Amcare_VR.AdmitNursingAreaDesc, 
                         dbo.I10_Amcare_VR.AfterAdmit, dbo.I10_Amcare_VR.AgeCode, dbo.I10_Amcare_VR.AgeCodeDesc, dbo.I10_Amcare_VR.AgeGroup, dbo.I10_Amcare_VR.AgeNumber, dbo.I10_Amcare_VR.Albumin, 
                         dbo.I10_Amcare_VR.AlbuminDesc, dbo.I10_Amcare_VR.AlbuminCrossMatched, dbo.I10_Amcare_VR.AlbuminCrossMatchedDesc, dbo.I10_Amcare_VR.AlbuminTyped, dbo.I10_Amcare_VR.AlbuminTypedDesc, 
                         dbo.I10_Amcare_VR.AlbuminUnits, dbo.I10_Amcare_VR.ALCLOS, dbo.I10_Amcare_VR.AmbulanceReportNumber, dbo.I10_Amcare_VR.AmCareGroup, dbo.I10_Amcare_VR.AmCareGroupDesc, 
                         dbo.I10_Amcare_VR.AmcareCareType, dbo.I10_Amcare_VR.AmcareCareTypeDesc, dbo.I10_Amcare_VR.AmcareTypeCode, dbo.I10_Amcare_VR.AmcareTypeCodeDesc, dbo.I10_Amcare_VR.Ancil13, 
                         dbo.I10_Amcare_VR.Ancil14, dbo.I10_Amcare_VR.Ancil15, dbo.I10_Amcare_VR.Ancil16, dbo.I10_Amcare_VR.Ancil17, dbo.I10_Amcare_VR.AncillaryField1, dbo.I10_Amcare_VR.AncillaryField1Desc, 
                         dbo.I10_Amcare_VR.AncillaryField10, dbo.I10_Amcare_VR.AncillaryField10Desc, dbo.I10_Amcare_VR.AncillaryField11, dbo.I10_Amcare_VR.AncillaryField11Desc, dbo.I10_Amcare_VR.AncillaryField12, 
                         dbo.I10_Amcare_VR.AncillaryField12Desc, dbo.I10_Amcare_VR.AncillaryField2, dbo.I10_Amcare_VR.AncillaryField2Desc, dbo.I10_Amcare_VR.AncillaryField3, dbo.I10_Amcare_VR.AncillaryField3Desc, 
                         dbo.I10_Amcare_VR.AncillaryField4, dbo.I10_Amcare_VR.AncillaryField4Desc, dbo.I10_Amcare_VR.AncillaryField5, dbo.I10_Amcare_VR.AncillaryField5Desc, dbo.I10_Amcare_VR.AncillaryField6, 
                         dbo.I10_Amcare_VR.AncillaryField6Desc, dbo.I10_Amcare_VR.AncillaryField7, dbo.I10_Amcare_VR.AncillaryField7Desc, dbo.I10_Amcare_VR.AncillaryField8, dbo.I10_Amcare_VR.AncillaryField8Desc, 
                         dbo.I10_Amcare_VR.AncillaryField9, dbo.I10_Amcare_VR.AncillaryField9Desc, dbo.I10_Amcare_VR.ArrivalDate, dbo.I10_Amcare_VR.ArrivalMode, dbo.I10_Amcare_VR.ArrivalModeDesc, 
                         dbo.I10_Amcare_VR.ArrivalTime, dbo.I10_Amcare_VR.ArrivaltoTriageTime, dbo.I10_Amcare_VR.AssessmentDate, dbo.I10_Amcare_VR.AssessmentTime, dbo.I10_Amcare_VR.AssessmentTimeUnknown, 
                         dbo.I10_Amcare_VR.AssessmentTimeUnknownDesc, dbo.I10_Amcare_VR.AttendingPhysician, dbo.I10_Amcare_VR.AttendingPhysicianDesc, dbo.I10_Amcare_VR.AutoTransfusion, 
                         dbo.I10_Amcare_VR.AutoTransfusionDesc, dbo.I10_Amcare_VR.AutopsyPerformed, dbo.I10_Amcare_VR.AutopsyPerformedDesc, dbo.I10_Amcare_VR.BasicOption1, dbo.I10_Amcare_VR.BasicOption1Desc, 
                         dbo.I10_Amcare_VR.BasicOption10, dbo.I10_Amcare_VR.BasicOption10Desc, dbo.I10_Amcare_VR.BasicOption11, dbo.I10_Amcare_VR.BasicOption11Desc, dbo.I10_Amcare_VR.BasicOption12, 
                         dbo.I10_Amcare_VR.BasicOption12Desc, dbo.I10_Amcare_VR.BasicOption13, dbo.I10_Amcare_VR.BasicOption13Desc, dbo.I10_Amcare_VR.BasicOption14, dbo.I10_Amcare_VR.BasicOption14Desc, 
                         dbo.I10_Amcare_VR.BasicOption15, dbo.I10_Amcare_VR.BasicOption15Desc, dbo.I10_Amcare_VR.BasicOption16, dbo.I10_Amcare_VR.BasicOption16Desc, dbo.I10_Amcare_VR.BasicOption17, 
                         dbo.I10_Amcare_VR.BasicOption17Desc, dbo.I10_Amcare_VR.BasicOption18, dbo.I10_Amcare_VR.BasicOption18Desc, dbo.I10_Amcare_VR.BasicOption19, dbo.I10_Amcare_VR.BasicOption19Desc, 
                         dbo.I10_Amcare_VR.BasicOption2, dbo.I10_Amcare_VR.BasicOption2Desc, dbo.I10_Amcare_VR.BasicOption3, dbo.I10_Amcare_VR.BasicOption3Desc, dbo.I10_Amcare_VR.BasicOption4, 
                         dbo.I10_Amcare_VR.BasicOption4Desc, dbo.I10_Amcare_VR.BasicOption5, dbo.I10_Amcare_VR.BasicOption5Desc, dbo.I10_Amcare_VR.BasicOption6, dbo.I10_Amcare_VR.BasicOption6Desc, 
                         dbo.I10_Amcare_VR.BasicOption7, dbo.I10_Amcare_VR.BasicOption7Desc, dbo.I10_Amcare_VR.BasicOption8, dbo.I10_Amcare_VR.BasicOption8Desc, dbo.I10_Amcare_VR.BasicOption9, 
                         dbo.I10_Amcare_VR.BasicOption9Desc, dbo.I10_Amcare_VR.BatchNumber, dbo.I10_Amcare_VR.BatchPeriod, dbo.I10_Amcare_VR.BatchPeriodDesc, dbo.I10_Amcare_VR.BatchPeriod_BC, 
                         dbo.I10_Amcare_VR.BatchYear, dbo.I10_Amcare_VR.BirthDate, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIII, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIIIDesc, 
						 dbo.I10_Amcare_VR.Blood_C1Inhibitor, 
                         dbo.I10_Amcare_VR.Blood_C1InhibitorDesc, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasma, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_CryosupernatantPlasma, 
                         dbo.I10_Amcare_VR.Blood_CryosupernatantPlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_FEIBA, 
						 dbo.I10_Amcare_VR.Blood_FEIBADesc, 
						 dbo.I10_Amcare_VR.Blood_Fibrinogen, 
						 dbo.I10_Amcare_VR.Blood_FibrinogenDesc, 
                         dbo.I10_Amcare_VR.Blood_IVIG_SCIG, 
						 dbo.I10_Amcare_VR.Blood_IVIG_SCIGDesc, 
						 dbo.I10_Amcare_VR.Blood_PCC, 
						 dbo.I10_Amcare_VR.Blood_PCCDesc, 
						 dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactors, 
                         dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactorsDesc, 
						 
						 dbo.I10_Amcare_VR.BreastFeeding, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlag, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlagDesc, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitDateIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknown, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknownDesc, dbo.I10_Amcare_VR.ClinicalDecisionUnitDateOut, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOut, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknown, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknownDesc, dbo.I10_Amcare_VR.ChangeinLegalStatus, 
                         dbo.I10_Amcare_VR.ChangeinLegalStatusDesc, dbo.I10_Amcare_VR.ChartNumber, dbo.I10_Amcare_VR.ChiefComplaint, dbo.I10_Amcare_VR.CoderNumber, dbo.I10_Amcare_VR.CoderNumberDesc, 
                         dbo.I10_Amcare_VR.CompleteRecord, dbo.I10_Amcare_VR.CompleteRecordDesc, dbo.I10_Amcare_VR.Complication, dbo.I10_Amcare_VR.ComplicationDesc, dbo.I10_Amcare_VR.Complication1, 
                         dbo.I10_Amcare_VR.Complication1Desc, dbo.I10_Amcare_VR.Complication2, dbo.I10_Amcare_VR.Complication2Desc, dbo.I10_Amcare_VR.Complication3, dbo.I10_Amcare_VR.Complication3Desc, 
                         dbo.I10_Amcare_VR.ContactMode, dbo.I10_Amcare_VR.ContactModeDesc, dbo.I10_Amcare_VR.CoronerCase, dbo.I10_Amcare_VR.CoronerCaseDesc, dbo.I10_Amcare_VR.DataEntryCoder, 
                         dbo.I10_Amcare_VR.DataEntryCoderDesc, dbo.I10_Amcare_VR.DateLeftER, dbo.I10_Amcare_VR.DateofLastMenses, dbo.I10_Amcare_VR.DateReadyforDisch, dbo.I10_Amcare_VR.DateSentToCIHI, 
                         dbo.I10_Amcare_VR.DateSentToCIHILevel1, dbo.I10_Amcare_VR.DateSentToCIHILevel2, dbo.I10_Amcare_VR.DateSentToCIHILite, dbo.I10_Amcare_VR.DeathInER, dbo.I10_Amcare_VR.DeathInERDesc, 
                         dbo.I10_Amcare_VR.DeathOnArrival, dbo.I10_Amcare_VR.DeathOnArrivalDesc, dbo.I10_Amcare_VR.DecisionAdmitDifference, dbo.I10_Amcare_VR.DecisiontoAdmitDate, dbo.I10_Amcare_VR.DecisiontoAdmitTime, 
                         dbo.I10_Amcare_VR.DecisionAdmitTimeUnknown, dbo.I10_Amcare_VR.DecisionAdmitTimeUnknownDesc, dbo.I10_Amcare_VR.DeliveryDate, dbo.I10_Amcare_VR.DeliveryTime, 
                         dbo.I10_Amcare_VR.DiedDuringIntervention, dbo.I10_Amcare_VR.DiedDuringInterventionDesc, dbo.I10_Amcare_VR.DischNursingArea, dbo.I10_Amcare_VR.DischNursingAreaDesc, 
                         dbo.I10_Amcare_VR.DischPlanning, dbo.I10_Amcare_VR.DischPlanningDesc, dbo.I10_Amcare_VR.DischargeAge, dbo.I10_Amcare_VR.DischargeDisposition, dbo.I10_Amcare_VR.DischargeDispositionDesc, 
                         dbo.I10_Amcare_VR.DispositionDate, dbo.I10_Amcare_VR.DispositionTime, dbo.I10_Amcare_VR.DispositionTimeUnknown, dbo.I10_Amcare_VR.DispositionTimeUnknownDesc, dbo.I10_Amcare_VR.ECTTreatment, 
                         dbo.I10_Amcare_VR.ECTTreatmentDesc, dbo.I10_Amcare_VR.Education, dbo.I10_Amcare_VR.EducationDesc, dbo.I10_Amcare_VR.EDVisitIndicator, dbo.I10_Amcare_VR.EDVisitIndicatorDesc, 
                         dbo.I10_Amcare_VR.Employment, dbo.I10_Amcare_VR.EmploymentDesc, dbo.I10_Amcare_VR.EntryCode, dbo.I10_Amcare_VR.EstimateDischDate, dbo.I10_Amcare_VR.ExitCode, 
                         dbo.I10_Amcare_VR.FamilyPhysicianFlag, dbo.I10_Amcare_VR.FamilyPhysicianFlagDesc, dbo.I10_Amcare_VR.FinancialSupport, dbo.I10_Amcare_VR.FinancialSupportDesc, dbo.I10_Amcare_VR.FinishDate, 
                         dbo.I10_Amcare_VR.FinishTime, dbo.I10_Amcare_VR.FirstName, dbo.I10_Amcare_VR.FullName, dbo.I10_Amcare_VR.FixedChartNumber, dbo.I10_Amcare_VR.Gender, dbo.I10_Amcare_VR.GenderDesc, 
                         dbo.I10_Amcare_VR.GestationalAgeinweeks, dbo.I10_Amcare_VR.GlasgowScale, dbo.I10_Amcare_VR.GlasgowScaleDesc, dbo.I10_Amcare_VR.GreaterTenPO, dbo.I10_Amcare_VR.HCNProvince, 
                         dbo.I10_Amcare_VR.HCNProvinceDesc, dbo.I10_Amcare_VR.HCNVersion, dbo.I10_Amcare_VR.HealthCareNumber, dbo.I10_Amcare_VR.Hospital, dbo.I10_Amcare_VR.HospitalDesc, 
                         dbo.I10_Amcare_VR.HospitalAccountRecord,
                         dbo.I10_Amcare_VR.HelmetIndicator, dbo.I10_Amcare_VR.HelmetIndicatorDesc, dbo.I10_Amcare_VR.InSCU, dbo.I10_Amcare_VR.InitialOR, dbo.I10_Amcare_VR.InitialORDesc, dbo.I10_Amcare_VR.InjuryDate, 
                         dbo.I10_Amcare_VR.Injury, dbo.I10_Amcare_VR.InjuryDesc, dbo.I10_Amcare_VR.InputDate, dbo.I10_Amcare_VR.InputTime, 

						 dbo.I10_Amcare_VR.InstitutionFrom, dbo.I10_Amcare_VR.InstitutionFromDesc, 
						 dbo.I10_Amcare_VR.InstitutionFromType, dbo.I10_Amcare_VR.InstitutionFromTypeDesc,
                         dbo.I10_Amcare_VR.InstFromCareType, dbo.I10_Amcare_VR.InstFromHospType, 
						 dbo.I10_Amcare_VR.InstitutionNumber, dbo.I10_Amcare_VR.InstitutionNumberDesc, 
						 dbo.I10_Amcare_VR.InstitutionTo, dbo.I10_Amcare_VR.InstitutionToDesc, 
						 dbo.I10_Amcare_VR.InstToCareType, dbo.I10_Amcare_VR.InstToHospType, 
						 dbo.I10_Amcare_VR.InstitutionToType, dbo.I10_Amcare_VR.InstitutionToTypeDesc, 
						 
						 dbo.I10_Amcare_VR.InterfaceDate, dbo.I10_Amcare_VR.InterfaceTime, 
                         dbo.I10_Amcare_VR.IsAbstractCompleted, dbo.I10_Amcare_VR.IsAbstractCompletedDesc, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCompletedLevel2, dbo.I10_Amcare_VR.IsAbstractCompletedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCompletedLite, dbo.I10_Amcare_VR.IsAbstractCompletedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrected, dbo.I10_Amcare_VR.IsAbstractCorrectedDesc, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCorrectedLite, dbo.I10_Amcare_VR.IsAbstractCorrectedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractDeleted, dbo.I10_Amcare_VR.IsAbstractDeletedDesc, dbo.I10_Amcare_VR.IsAbstractSubmitted, dbo.I10_Amcare_VR.IsAbstractSubmittedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLite, dbo.I10_Amcare_VR.IsAbstractSubmittedLiteDesc, dbo.I10_Amcare_VR.IsAbstractValidated, dbo.I10_Amcare_VR.IsAbstractValidatedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLevel1, dbo.I10_Amcare_VR.IsAbstractValidatedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLite, dbo.I10_Amcare_VR.IsAbstractValidatedLiteDesc, dbo.I10_Amcare_VR.IsBirthdateEstimated, dbo.I10_Amcare_VR.IsBirthdateEstimatedDesc, 
						 dbo.I10_Amcare_VR.IsCustomValidated, dbo.I10_Amcare_VR.IsCustomValidatedDesc,
                         dbo.I10_Amcare_VR.LOSDays, dbo.I10_Amcare_VR.LOSTime, dbo.I10_Amcare_VR.LOSTimeinHours, dbo.I10_Amcare_VR.LOSTotalMinutes, dbo.I10_Amcare_VR.Language, dbo.I10_Amcare_VR.LanguageDesc, 
                         dbo.I10_Amcare_VR.LastName, dbo.I10_Amcare_VR.LessTwoPO, dbo.I10_Amcare_VR.LivingArrangement, dbo.I10_Amcare_VR.LivingArrangementDesc, dbo.I10_Amcare_VR.LocationofInjury, 
                         dbo.I10_Amcare_VR.LocationofInjuryDesc, dbo.I10_Amcare_VR.MISCode, dbo.I10_Amcare_VR.MISCodeDesc, dbo.I10_Amcare_VR.MaidenName, dbo.I10_Amcare_VR.MaritalStatus, 
                         dbo.I10_Amcare_VR.MaritalStatusDesc, 
                         dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoED, 
						 dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04Desc, 
						 
						 dbo.I10_Amcare_VR.MethodofAdmission, dbo.I10_Amcare_VR.MethodofAdmissionDesc, dbo.I10_Amcare_VR.MiddleName, 
                         dbo.I10_Amcare_VR.NACRSClinicLiteSubmission, dbo.I10_Amcare_VR.NACRSClinicLiteSubmissionDesc, 
                         dbo.I10_Amcare_VR.NewbornChart, 
                         dbo.I10_Amcare_VR.NewbornDischDate, dbo.I10_Amcare_VR.NextScheduledVisitDate, dbo.I10_Amcare_VR.NextScheduledVisitTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentDate, 
                         dbo.I10_Amcare_VR.NonPhysicianAssessmentTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknown, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.NonPhysicianNumber, dbo.I10_Amcare_VR.NonPhysicianNumberDesc, dbo.I10_Amcare_VR.NonPhysicianService, dbo.I10_Amcare_VR.NonPhysicianServiceDesc, 
                         dbo.I10_Amcare_VR.NumberofECT, dbo.I10_Amcare_VR.NursingAssessmentDate, dbo.I10_Amcare_VR.NursingAssessmentTime, dbo.I10_Amcare_VR.Occupation, dbo.I10_Amcare_VR.OccupationDesc, 
                         dbo.I10_Amcare_VR.OtherMedicalDeath, dbo.I10_Amcare_VR.OtherMedicalDeathDesc, dbo.I10_Amcare_VR.OtherBlood, dbo.I10_Amcare_VR.OtherBloodDesc, dbo.I10_Amcare_VR.OtherBloodCrossMatched, 
                         dbo.I10_Amcare_VR.OtherBloodCrossMatchedDesc, dbo.I10_Amcare_VR.OtherBloodTyped, dbo.I10_Amcare_VR.OtherBloodTypedDesc, dbo.I10_Amcare_VR.OtherBloodUnits, dbo.I10_Amcare_VR.PCTASIndicator, 
                         dbo.I10_Amcare_VR.PCTASIndicatorDesc, dbo.I10_Amcare_VR.PhysicianEstLOS, dbo.I10_Amcare_VR.Plasma, dbo.I10_Amcare_VR.PlasmaDesc, dbo.I10_Amcare_VR.PlasmaCrossMatched, 
                         dbo.I10_Amcare_VR.PlasmaCrossMatchedDesc, dbo.I10_Amcare_VR.PlasmaTyped, dbo.I10_Amcare_VR.PlasmaTypedDesc, dbo.I10_Amcare_VR.PlasmaUnits, dbo.I10_Amcare_VR.Platelets, 
                         dbo.I10_Amcare_VR.PlateletsDesc, dbo.I10_Amcare_VR.PlateletsCrossMatched, dbo.I10_Amcare_VR.PlateletsCrossMatchedDesc, dbo.I10_Amcare_VR.PlateletsTyped, dbo.I10_Amcare_VR.PlateletsTypedDesc, 
                         dbo.I10_Amcare_VR.PlateletsUnits, dbo.I10_Amcare_VR.PostalCode, dbo.I10_Amcare_VR.PostalCodeDesc, dbo.I10_Amcare_VR.PostOpDays, dbo.I10_Amcare_VR.PreOpDays, 
                         dbo.I10_Amcare_VR.PreamditWorkUp, dbo.I10_Amcare_VR.PreamditWorkUpDesc, dbo.I10_Amcare_VR.Pregnancy, dbo.I10_Amcare_VR.PregnancyDesc, dbo.I10_Amcare_VR.PrevLiveBirth, 
                         dbo.I10_Amcare_VR.PreviousPsychiartricAdmissions, dbo.I10_Amcare_VR.PreviousPsychiartricAdmDesc, dbo.I10_Amcare_VR.Program, dbo.I10_Amcare_VR.ProgramDesc, dbo.I10_Amcare_VR.ProvinceNumber, 
                         dbo.I10_Amcare_VR.ProvinceNumberDesc, dbo.I10_Amcare_VR.ReasonForVisit, dbo.I10_Amcare_VR.ReasonForVisitDesc, dbo.I10_Amcare_VR.ReAdmitCode, dbo.I10_Amcare_VR.ReciprocalBillingStatus, 
                         dbo.I10_Amcare_VR.ReciprocalBillingStatusDesc, dbo.I10_Amcare_VR.RedBloodCell, dbo.I10_Amcare_VR.RedBloodCellDesc, dbo.I10_Amcare_VR.RedBloodCellCrossMatched, 
                         dbo.I10_Amcare_VR.RedBloodCellCrossMatchedDesc, dbo.I10_Amcare_VR.RedBloodCellTyped, dbo.I10_Amcare_VR.RedBloodCellTypedDesc, dbo.I10_Amcare_VR.RedBloodCellUnits, 
                         dbo.I10_Amcare_VR.ReferralDate, dbo.I10_Amcare_VR.ReferredFrom, dbo.I10_Amcare_VR.ReferredFromDesc, dbo.I10_Amcare_VR.ReferredTo, dbo.I10_Amcare_VR.ReferredToDesc, 
                         dbo.I10_Amcare_VR.ReferringProvider, dbo.I10_Amcare_VR.ReferringProviderDesc, dbo.I10_Amcare_VR.RegisterNumber, dbo.I10_Amcare_VR.RegistrationNumber, 
                         dbo.I10_Amcare_VR.RegistrationSequenceNumber, dbo.I10_Amcare_VR.RegistrationVisitDate, dbo.I10_Amcare_VR.RegistrationVisitTime, dbo.I10_Amcare_VR.ReproductiveCareComments, 
                         dbo.I10_Amcare_VR.ReserveField, dbo.I10_Amcare_VR.ResidenceCode, dbo.I10_Amcare_VR.ResidenceCodeDesc, dbo.I10_Amcare_VR.ResidenceProvince, dbo.I10_Amcare_VR.ResidenceProvinceDesc, 
                         dbo.I10_Amcare_VR.ResidenceRegion, dbo.I10_Amcare_VR.ResidenceRegionDesc, dbo.I10_Amcare_VR.ResidenceType, dbo.I10_Amcare_VR.ResidenceTypeDesc, dbo.I10_Amcare_VR.ResponsiblityForPayment,
                          dbo.I10_Amcare_VR.ResponsiblityForPaymentDesc, dbo.I10_Amcare_VR.SchedEDVisit, dbo.I10_Amcare_VR.SchedEDVisitDesc, dbo.I10_Amcare_VR.SeatbeltIndicator, dbo.I10_Amcare_VR.SeatbeltIndicatorDesc, 
                         dbo.I10_Amcare_VR.SecondChartRegisterNumber, dbo.I10_Amcare_VR.SecretVIPPatient, dbo.I10_Amcare_VR.SecretVIPPatientDesc, dbo.I10_Amcare_VR.SiteNumber, dbo.I10_Amcare_VR.SiteNumberDesc, 
                         dbo.I10_Amcare_VR.SocialService, dbo.I10_Amcare_VR.SocialServiceDesc, dbo.I10_Amcare_VR.SourceofReferral, dbo.I10_Amcare_VR.SourceofReferralDesc, dbo.I10_Amcare_VR.SpecialistNumber, 
                         dbo.I10_Amcare_VR.SpecialistNumberDesc, dbo.I10_Amcare_VR.SpecialistRequestDate, dbo.I10_Amcare_VR.SpecialistRequestService, dbo.I10_Amcare_VR.SpecialistRequestServiceDesc, 
                         dbo.I10_Amcare_VR.SpecialistRequestTime, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknown, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknownDesc, dbo.I10_Amcare_VR.StakeholderType, 
                         dbo.I10_Amcare_VR.StakeholderTypeDesc, dbo.I10_Amcare_VR.StatusAfterTriage, dbo.I10_Amcare_VR.StatusAfterTriageDesc, dbo.I10_Amcare_VR.Sterilization, dbo.I10_Amcare_VR.SterilizationDesc, 
                         dbo.I10_Amcare_VR.SubmissionLevelCode, dbo.I10_Amcare_VR.SubmissionRecordID, dbo.I10_Amcare_VR.SubsequentOR, dbo.I10_Amcare_VR.SubsequentORDesc, dbo.I10_Amcare_VR.Suicide, 
                         dbo.I10_Amcare_VR.SuicideDesc, dbo.I10_Amcare_VR.SurgicalCase, dbo.I10_Amcare_VR.SurgicalCaseDesc, dbo.I10_Amcare_VR.TimeLeftER, dbo.I10_Amcare_VR.TimeLeftERUnknown, 
                         dbo.I10_Amcare_VR.TimeLeftERUnknownDEsc, dbo.I10_Amcare_VR.TransferOverloadDate, dbo.I10_Amcare_VR.TransferOverloadTime, dbo.I10_Amcare_VR.TransferOverloadTimeDifference, 
                         dbo.I10_Amcare_VR.TransfusionGiven, dbo.I10_Amcare_VR.TransfusionGivenDesc, dbo.I10_Amcare_VR.Trauma, dbo.I10_Amcare_VR.TraumaDesc, dbo.I10_Amcare_VR.TriageDate, 
                         dbo.I10_Amcare_VR.TriageLevel, dbo.I10_Amcare_VR.TriageLevelDesc, dbo.I10_Amcare_VR.TriageTime, dbo.I10_Amcare_VR.TriageTimeUnknown, dbo.I10_Amcare_VR.TriageTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.TSICoder, dbo.I10_Amcare_VR.TSICoderDesc, dbo.I10_Amcare_VR.TSIDate, dbo.I10_Amcare_VR.TSITime, dbo.I10_Amcare_VR.TwoTenPO, dbo.I10_Amcare_VR.ULI, 
                         dbo.I10_Amcare_VR.UniversalEpisodeIdentifier, dbo.I10_Amcare_VR.UnplannedReadmit, dbo.I10_Amcare_VR.VisitStatus, dbo.I10_Amcare_VR.VisitStatusDesc, dbo.I10_Amcare_VR.VisitType, dbo.I10_Amcare_VR.VisitTypeDesc, 
                         dbo.I10_Amcare_VR.WaitTimeinER, dbo.I10_Amcare_VR.WaittoAssessmentinMinutes, dbo.I10_Amcare_VR.WaittoNursingAssessmentDiff, dbo.I10_Amcare_VR.Weight, dbo.I10_Amcare_VR.zzAbstractLink, 
                         dbo.I10_Amcare_VR.zzRegionalPatientID, dbo.I10_Amcare_VR.zzVolumeLink, 

                         dbo.I10_Amcare_Projects_740_VR.ProjectNumber, dbo.I10_Amcare_Projects_740_VR.ProjectNumberDesc, dbo.I10_Amcare_Projects_740_VR.ProjectOccurrence, 
                         dbo.I10_Amcare_Projects_740_VR.DocumentationAlphaFIM, dbo.I10_Amcare_Projects_740_VR.DocumentationAlphaFIMDesc, dbo.I10_Amcare_Projects_740_VR.AlphaFIMScoreCompletionDate, 
                         dbo.I10_Amcare_Projects_740_VR.ProjectFIMRawMotorRating, dbo.I10_Amcare_Projects_740_VR.ProjectFIMRawCognitiveRating
FROM            dbo.I10_Amcare_VR LEFT OUTER JOIN
                         dbo.I10_Amcare_Projects_740_VR ON dbo.I10_Amcare_VR.zzAbstractLink = dbo.I10_Amcare_Projects_740_VR.zzAbstractLink



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Project_Question_24_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_Amcare_And_Project_Question_24_VR]
AS
SELECT        dbo.I10_Amcare_VR.[#ofPreviousPreTermDeliveries], dbo.I10_Amcare_VR.[#ofPrevSpontaneousAbortions], dbo.I10_Amcare_VR.[#ofPreviousTermDeliveries], dbo.I10_Amcare_VR.AccessPrimaryHealthCareCode, 
                         dbo.I10_Amcare_VR.AccessPrimaryHealthCareCodeDesc, dbo.I10_Amcare_VR.AmbulanceArrivalDate, dbo.I10_Amcare_VR.AmbulanceArrivalTime, dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknown, 
                         dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknownDesc, dbo.I10_Amcare_VR.AmbulanceTransferCareDate, dbo.I10_Amcare_VR.AmbulanceTransferCareTime, 
                         dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknown, dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknownDesc, dbo.I10_Amcare_VR.[#ofPrevTherapeuticAbortions], dbo.I10_Amcare_VR.AWOL, 
                         dbo.I10_Amcare_VR.AWOLDesc, dbo.I10_Amcare_VR.AbortDate, dbo.I10_Amcare_VR.AbstractNumber, dbo.I10_Amcare_VR.AbstractOverflow, dbo.I10_Amcare_VR.AbstractOverflowDesc, 
                         dbo.I10_Amcare_VR.ActivityDescription, dbo.I10_Amcare_VR.ActivityWhenInjured, dbo.I10_Amcare_VR.ActivityWhenInjuredDesc, dbo.I10_Amcare_VR.ActueLOS, dbo.I10_Amcare_VR.AdmitbyAmbulance, 
                         dbo.I10_Amcare_VR.AdmitbyAmbulanceDesc, dbo.I10_Amcare_VR.AdmitCategory, dbo.I10_Amcare_VR.AdmitDiagnosis, dbo.I10_Amcare_VR.AdmitNursingArea, dbo.I10_Amcare_VR.AdmitNursingAreaDesc, 
                         dbo.I10_Amcare_VR.AfterAdmit, dbo.I10_Amcare_VR.AgeCode, dbo.I10_Amcare_VR.AgeCodeDesc, dbo.I10_Amcare_VR.AgeGroup, dbo.I10_Amcare_VR.AgeNumber, dbo.I10_Amcare_VR.Albumin, 
                         dbo.I10_Amcare_VR.AlbuminDesc, dbo.I10_Amcare_VR.AlbuminCrossMatched, dbo.I10_Amcare_VR.AlbuminCrossMatchedDesc, dbo.I10_Amcare_VR.AlbuminTyped, dbo.I10_Amcare_VR.AlbuminTypedDesc, 
                         dbo.I10_Amcare_VR.AlbuminUnits, dbo.I10_Amcare_VR.ALCLOS, dbo.I10_Amcare_VR.AmbulanceReportNumber, dbo.I10_Amcare_VR.AmCareGroup, dbo.I10_Amcare_VR.AmCareGroupDesc, 
                         dbo.I10_Amcare_VR.AmcareCareType, dbo.I10_Amcare_VR.AmcareCareTypeDesc, dbo.I10_Amcare_VR.AmcareTypeCode, dbo.I10_Amcare_VR.AmcareTypeCodeDesc, dbo.I10_Amcare_VR.Ancil13, 
                         dbo.I10_Amcare_VR.Ancil14, dbo.I10_Amcare_VR.Ancil15, dbo.I10_Amcare_VR.Ancil16, dbo.I10_Amcare_VR.Ancil17, dbo.I10_Amcare_VR.AncillaryField1, dbo.I10_Amcare_VR.AncillaryField1Desc, 
                         dbo.I10_Amcare_VR.AncillaryField10, dbo.I10_Amcare_VR.AncillaryField10Desc, dbo.I10_Amcare_VR.AncillaryField11, dbo.I10_Amcare_VR.AncillaryField11Desc, dbo.I10_Amcare_VR.AncillaryField12, 
                         dbo.I10_Amcare_VR.AncillaryField12Desc, dbo.I10_Amcare_VR.AncillaryField2, dbo.I10_Amcare_VR.AncillaryField2Desc, dbo.I10_Amcare_VR.AncillaryField3, dbo.I10_Amcare_VR.AncillaryField3Desc, 
                         dbo.I10_Amcare_VR.AncillaryField4, dbo.I10_Amcare_VR.AncillaryField4Desc, dbo.I10_Amcare_VR.AncillaryField5, dbo.I10_Amcare_VR.AncillaryField5Desc, dbo.I10_Amcare_VR.AncillaryField6, 
                         dbo.I10_Amcare_VR.AncillaryField6Desc, dbo.I10_Amcare_VR.AncillaryField7, dbo.I10_Amcare_VR.AncillaryField7Desc, dbo.I10_Amcare_VR.AncillaryField8, dbo.I10_Amcare_VR.AncillaryField8Desc, 
                         dbo.I10_Amcare_VR.AncillaryField9, dbo.I10_Amcare_VR.AncillaryField9Desc, dbo.I10_Amcare_VR.ArrivalDate, dbo.I10_Amcare_VR.ArrivalMode, dbo.I10_Amcare_VR.ArrivalModeDesc, 
                         dbo.I10_Amcare_VR.ArrivalTime, dbo.I10_Amcare_VR.ArrivaltoTriageTime, dbo.I10_Amcare_VR.AssessmentDate, dbo.I10_Amcare_VR.AssessmentTime, dbo.I10_Amcare_VR.AssessmentTimeUnknown, 
                         dbo.I10_Amcare_VR.AssessmentTimeUnknownDesc, dbo.I10_Amcare_VR.AttendingPhysician, dbo.I10_Amcare_VR.AttendingPhysicianDesc, dbo.I10_Amcare_VR.AutoTransfusion, 
                         dbo.I10_Amcare_VR.AutoTransfusionDesc, dbo.I10_Amcare_VR.AutopsyPerformed, dbo.I10_Amcare_VR.AutopsyPerformedDesc, dbo.I10_Amcare_VR.BasicOption1, dbo.I10_Amcare_VR.BasicOption1Desc, 
                         dbo.I10_Amcare_VR.BasicOption10, dbo.I10_Amcare_VR.BasicOption10Desc, dbo.I10_Amcare_VR.BasicOption11, dbo.I10_Amcare_VR.BasicOption11Desc, dbo.I10_Amcare_VR.BasicOption12, 
                         dbo.I10_Amcare_VR.BasicOption12Desc, dbo.I10_Amcare_VR.BasicOption13, dbo.I10_Amcare_VR.BasicOption13Desc, dbo.I10_Amcare_VR.BasicOption14, dbo.I10_Amcare_VR.BasicOption14Desc, 
                         dbo.I10_Amcare_VR.BasicOption15, dbo.I10_Amcare_VR.BasicOption15Desc, dbo.I10_Amcare_VR.BasicOption16, dbo.I10_Amcare_VR.BasicOption16Desc, dbo.I10_Amcare_VR.BasicOption17, 
                         dbo.I10_Amcare_VR.BasicOption17Desc, dbo.I10_Amcare_VR.BasicOption18, dbo.I10_Amcare_VR.BasicOption18Desc, dbo.I10_Amcare_VR.BasicOption19, dbo.I10_Amcare_VR.BasicOption19Desc, 
                         dbo.I10_Amcare_VR.BasicOption2, dbo.I10_Amcare_VR.BasicOption2Desc, dbo.I10_Amcare_VR.BasicOption3, dbo.I10_Amcare_VR.BasicOption3Desc, dbo.I10_Amcare_VR.BasicOption4, 
                         dbo.I10_Amcare_VR.BasicOption4Desc, dbo.I10_Amcare_VR.BasicOption5, dbo.I10_Amcare_VR.BasicOption5Desc, dbo.I10_Amcare_VR.BasicOption6, dbo.I10_Amcare_VR.BasicOption6Desc, 
                         dbo.I10_Amcare_VR.BasicOption7, dbo.I10_Amcare_VR.BasicOption7Desc, dbo.I10_Amcare_VR.BasicOption8, dbo.I10_Amcare_VR.BasicOption8Desc, dbo.I10_Amcare_VR.BasicOption9, 
                         dbo.I10_Amcare_VR.BasicOption9Desc, dbo.I10_Amcare_VR.BatchNumber, dbo.I10_Amcare_VR.BatchPeriod, dbo.I10_Amcare_VR.BatchPeriodDesc, dbo.I10_Amcare_VR.BatchPeriod_BC, 
                         dbo.I10_Amcare_VR.BatchYear, dbo.I10_Amcare_VR.BirthDate, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIII, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIIIDesc, 
						 dbo.I10_Amcare_VR.Blood_C1Inhibitor, 
                         dbo.I10_Amcare_VR.Blood_C1InhibitorDesc, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasma, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_CryosupernatantPlasma, 
                         dbo.I10_Amcare_VR.Blood_CryosupernatantPlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_FEIBA, 
						 dbo.I10_Amcare_VR.Blood_FEIBADesc, 
						 dbo.I10_Amcare_VR.Blood_Fibrinogen, 
						 dbo.I10_Amcare_VR.Blood_FibrinogenDesc, 
                         dbo.I10_Amcare_VR.Blood_IVIG_SCIG, 
						 dbo.I10_Amcare_VR.Blood_IVIG_SCIGDesc, 
						 dbo.I10_Amcare_VR.Blood_PCC, 
						 dbo.I10_Amcare_VR.Blood_PCCDesc, 
						 dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactors, 
                         dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactorsDesc, 
						 
						 dbo.I10_Amcare_VR.BreastFeeding, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlag, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlagDesc, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitDateIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknown, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknownDesc, dbo.I10_Amcare_VR.ClinicalDecisionUnitDateOut, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOut, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknown, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknownDesc, dbo.I10_Amcare_VR.ChangeinLegalStatus, 
                         dbo.I10_Amcare_VR.ChangeinLegalStatusDesc, dbo.I10_Amcare_VR.ChartNumber, dbo.I10_Amcare_VR.ChiefComplaint, dbo.I10_Amcare_VR.CoderNumber, dbo.I10_Amcare_VR.CoderNumberDesc, 
                         dbo.I10_Amcare_VR.CompleteRecord, dbo.I10_Amcare_VR.CompleteRecordDesc, dbo.I10_Amcare_VR.Complication, dbo.I10_Amcare_VR.ComplicationDesc, dbo.I10_Amcare_VR.Complication1, 
                         dbo.I10_Amcare_VR.Complication1Desc, dbo.I10_Amcare_VR.Complication2, dbo.I10_Amcare_VR.Complication2Desc, dbo.I10_Amcare_VR.Complication3, dbo.I10_Amcare_VR.Complication3Desc, 
                         dbo.I10_Amcare_VR.ContactMode, dbo.I10_Amcare_VR.ContactModeDesc, dbo.I10_Amcare_VR.CoronerCase, dbo.I10_Amcare_VR.CoronerCaseDesc, dbo.I10_Amcare_VR.DataEntryCoder, 
                         dbo.I10_Amcare_VR.DataEntryCoderDesc, dbo.I10_Amcare_VR.DateLeftER, dbo.I10_Amcare_VR.DateofLastMenses, dbo.I10_Amcare_VR.DateReadyforDisch, dbo.I10_Amcare_VR.DateSentToCIHI, 
                         dbo.I10_Amcare_VR.DateSentToCIHILevel1, dbo.I10_Amcare_VR.DateSentToCIHILevel2, dbo.I10_Amcare_VR.DateSentToCIHILite, dbo.I10_Amcare_VR.DeathInER, dbo.I10_Amcare_VR.DeathInERDesc, 
                         dbo.I10_Amcare_VR.DeathOnArrival, dbo.I10_Amcare_VR.DeathOnArrivalDesc, dbo.I10_Amcare_VR.DecisionAdmitDifference, dbo.I10_Amcare_VR.DecisiontoAdmitDate, dbo.I10_Amcare_VR.DecisiontoAdmitTime, 
                         dbo.I10_Amcare_VR.DecisionAdmitTimeUnknown, dbo.I10_Amcare_VR.DecisionAdmitTimeUnknownDesc, dbo.I10_Amcare_VR.DeliveryDate, dbo.I10_Amcare_VR.DeliveryTime, 
                         dbo.I10_Amcare_VR.DiedDuringIntervention, dbo.I10_Amcare_VR.DiedDuringInterventionDesc, dbo.I10_Amcare_VR.DischNursingArea, dbo.I10_Amcare_VR.DischNursingAreaDesc, 
                         dbo.I10_Amcare_VR.DischPlanning, dbo.I10_Amcare_VR.DischPlanningDesc, dbo.I10_Amcare_VR.DischargeAge, dbo.I10_Amcare_VR.DischargeDisposition, dbo.I10_Amcare_VR.DischargeDispositionDesc, 
                         dbo.I10_Amcare_VR.DispositionDate, dbo.I10_Amcare_VR.DispositionTime, dbo.I10_Amcare_VR.DispositionTimeUnknown, dbo.I10_Amcare_VR.DispositionTimeUnknownDesc, dbo.I10_Amcare_VR.ECTTreatment, 
                         dbo.I10_Amcare_VR.ECTTreatmentDesc, dbo.I10_Amcare_VR.Education, dbo.I10_Amcare_VR.EducationDesc, dbo.I10_Amcare_VR.EDVisitIndicator, dbo.I10_Amcare_VR.EDVisitIndicatorDesc, 
                         dbo.I10_Amcare_VR.Employment, dbo.I10_Amcare_VR.EmploymentDesc, dbo.I10_Amcare_VR.EntryCode, dbo.I10_Amcare_VR.EstimateDischDate, dbo.I10_Amcare_VR.ExitCode, 
                         dbo.I10_Amcare_VR.FamilyPhysicianFlag, dbo.I10_Amcare_VR.FamilyPhysicianFlagDesc, dbo.I10_Amcare_VR.FinancialSupport, dbo.I10_Amcare_VR.FinancialSupportDesc, dbo.I10_Amcare_VR.FinishDate, 
                         dbo.I10_Amcare_VR.FinishTime, dbo.I10_Amcare_VR.FirstName, dbo.I10_Amcare_VR.FullName, dbo.I10_Amcare_VR.FixedChartNumber, dbo.I10_Amcare_VR.Gender, dbo.I10_Amcare_VR.GenderDesc, 
                         dbo.I10_Amcare_VR.GestationalAgeinweeks, dbo.I10_Amcare_VR.GlasgowScale, dbo.I10_Amcare_VR.GlasgowScaleDesc, dbo.I10_Amcare_VR.GreaterTenPO, dbo.I10_Amcare_VR.HCNProvince, 
                         dbo.I10_Amcare_VR.HCNProvinceDesc, dbo.I10_Amcare_VR.HCNVersion, dbo.I10_Amcare_VR.HealthCareNumber, dbo.I10_Amcare_VR.Hospital, dbo.I10_Amcare_VR.HospitalDesc, 
                         dbo.I10_Amcare_VR.HospitalAccountRecord,
                         dbo.I10_Amcare_VR.HelmetIndicator, dbo.I10_Amcare_VR.HelmetIndicatorDesc, dbo.I10_Amcare_VR.InSCU, dbo.I10_Amcare_VR.InitialOR, dbo.I10_Amcare_VR.InitialORDesc, dbo.I10_Amcare_VR.InjuryDate, 
                         dbo.I10_Amcare_VR.Injury, dbo.I10_Amcare_VR.InjuryDesc, dbo.I10_Amcare_VR.InputDate, dbo.I10_Amcare_VR.InputTime, 

						 dbo.I10_Amcare_VR.InstitutionFrom, dbo.I10_Amcare_VR.InstitutionFromDesc, 
						 dbo.I10_Amcare_VR.InstitutionFromType, dbo.I10_Amcare_VR.InstitutionFromTypeDesc,
                         dbo.I10_Amcare_VR.InstFromCareType, dbo.I10_Amcare_VR.InstFromHospType, 
						 dbo.I10_Amcare_VR.InstitutionNumber, dbo.I10_Amcare_VR.InstitutionNumberDesc, 
						 dbo.I10_Amcare_VR.InstitutionTo, dbo.I10_Amcare_VR.InstitutionToDesc, 
						 dbo.I10_Amcare_VR.InstToCareType, dbo.I10_Amcare_VR.InstToHospType, 
						 dbo.I10_Amcare_VR.InstitutionToType, dbo.I10_Amcare_VR.InstitutionToTypeDesc, 
						 
						 dbo.I10_Amcare_VR.InterfaceDate, dbo.I10_Amcare_VR.InterfaceTime, 
                         dbo.I10_Amcare_VR.IsAbstractCompleted, dbo.I10_Amcare_VR.IsAbstractCompletedDesc, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCompletedLevel2, dbo.I10_Amcare_VR.IsAbstractCompletedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCompletedLite, dbo.I10_Amcare_VR.IsAbstractCompletedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrected, dbo.I10_Amcare_VR.IsAbstractCorrectedDesc, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCorrectedLite, dbo.I10_Amcare_VR.IsAbstractCorrectedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractDeleted, dbo.I10_Amcare_VR.IsAbstractDeletedDesc, dbo.I10_Amcare_VR.IsAbstractSubmitted, dbo.I10_Amcare_VR.IsAbstractSubmittedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLite, dbo.I10_Amcare_VR.IsAbstractSubmittedLiteDesc, dbo.I10_Amcare_VR.IsAbstractValidated, dbo.I10_Amcare_VR.IsAbstractValidatedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLevel1, dbo.I10_Amcare_VR.IsAbstractValidatedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLite, dbo.I10_Amcare_VR.IsAbstractValidatedLiteDesc, dbo.I10_Amcare_VR.IsBirthdateEstimated, dbo.I10_Amcare_VR.IsBirthdateEstimatedDesc, 
						 dbo.I10_Amcare_VR.IsCustomValidated, dbo.I10_Amcare_VR.IsCustomValidatedDesc,
                         dbo.I10_Amcare_VR.LOSDays, dbo.I10_Amcare_VR.LOSTime, dbo.I10_Amcare_VR.LOSTimeinHours, dbo.I10_Amcare_VR.LOSTotalMinutes, dbo.I10_Amcare_VR.Language, dbo.I10_Amcare_VR.LanguageDesc, 
                         dbo.I10_Amcare_VR.LastName, dbo.I10_Amcare_VR.LessTwoPO, dbo.I10_Amcare_VR.LivingArrangement, dbo.I10_Amcare_VR.LivingArrangementDesc, dbo.I10_Amcare_VR.LocationofInjury, 
                         dbo.I10_Amcare_VR.LocationofInjuryDesc, dbo.I10_Amcare_VR.MISCode, dbo.I10_Amcare_VR.MISCodeDesc, dbo.I10_Amcare_VR.MaidenName, dbo.I10_Amcare_VR.MaritalStatus, 
                         dbo.I10_Amcare_VR.MaritalStatusDesc, 
                         dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoED, 
						 dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04Desc, 
						 
						 dbo.I10_Amcare_VR.MethodofAdmission, dbo.I10_Amcare_VR.MethodofAdmissionDesc, dbo.I10_Amcare_VR.MiddleName, 
                         dbo.I10_Amcare_VR.NACRSClinicLiteSubmission, dbo.I10_Amcare_VR.NACRSClinicLiteSubmissionDesc, 
                         dbo.I10_Amcare_VR.NewbornChart, 
                         dbo.I10_Amcare_VR.NewbornDischDate, dbo.I10_Amcare_VR.NextScheduledVisitDate, dbo.I10_Amcare_VR.NextScheduledVisitTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentDate, 
                         dbo.I10_Amcare_VR.NonPhysicianAssessmentTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknown, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.NonPhysicianNumber, dbo.I10_Amcare_VR.NonPhysicianNumberDesc, dbo.I10_Amcare_VR.NonPhysicianService, dbo.I10_Amcare_VR.NonPhysicianServiceDesc, 
                         dbo.I10_Amcare_VR.NumberofECT, dbo.I10_Amcare_VR.NursingAssessmentDate, dbo.I10_Amcare_VR.NursingAssessmentTime, dbo.I10_Amcare_VR.Occupation, dbo.I10_Amcare_VR.OccupationDesc, 
                         dbo.I10_Amcare_VR.OtherMedicalDeath, dbo.I10_Amcare_VR.OtherMedicalDeathDesc, dbo.I10_Amcare_VR.OtherBlood, dbo.I10_Amcare_VR.OtherBloodDesc, dbo.I10_Amcare_VR.OtherBloodCrossMatched, 
                         dbo.I10_Amcare_VR.OtherBloodCrossMatchedDesc, dbo.I10_Amcare_VR.OtherBloodTyped, dbo.I10_Amcare_VR.OtherBloodTypedDesc, dbo.I10_Amcare_VR.OtherBloodUnits, dbo.I10_Amcare_VR.PCTASIndicator, 
                         dbo.I10_Amcare_VR.PCTASIndicatorDesc, dbo.I10_Amcare_VR.PhysicianEstLOS, dbo.I10_Amcare_VR.Plasma, dbo.I10_Amcare_VR.PlasmaDesc, dbo.I10_Amcare_VR.PlasmaCrossMatched, 
                         dbo.I10_Amcare_VR.PlasmaCrossMatchedDesc, dbo.I10_Amcare_VR.PlasmaTyped, dbo.I10_Amcare_VR.PlasmaTypedDesc, dbo.I10_Amcare_VR.PlasmaUnits, dbo.I10_Amcare_VR.Platelets, 
                         dbo.I10_Amcare_VR.PlateletsDesc, dbo.I10_Amcare_VR.PlateletsCrossMatched, dbo.I10_Amcare_VR.PlateletsCrossMatchedDesc, dbo.I10_Amcare_VR.PlateletsTyped, dbo.I10_Amcare_VR.PlateletsTypedDesc, 
                         dbo.I10_Amcare_VR.PlateletsUnits, dbo.I10_Amcare_VR.PostalCode, dbo.I10_Amcare_VR.PostalCodeDesc, dbo.I10_Amcare_VR.PostOpDays, dbo.I10_Amcare_VR.PreOpDays, 
                         dbo.I10_Amcare_VR.PreamditWorkUp, dbo.I10_Amcare_VR.PreamditWorkUpDesc, dbo.I10_Amcare_VR.Pregnancy, dbo.I10_Amcare_VR.PregnancyDesc, dbo.I10_Amcare_VR.PrevLiveBirth, 
                         dbo.I10_Amcare_VR.PreviousPsychiartricAdmissions, dbo.I10_Amcare_VR.PreviousPsychiartricAdmDesc, dbo.I10_Amcare_VR.Program, dbo.I10_Amcare_VR.ProgramDesc, dbo.I10_Amcare_VR.ProvinceNumber, 
                         dbo.I10_Amcare_VR.ProvinceNumberDesc, dbo.I10_Amcare_VR.ReasonForVisit, dbo.I10_Amcare_VR.ReasonForVisitDesc, dbo.I10_Amcare_VR.ReAdmitCode, dbo.I10_Amcare_VR.ReciprocalBillingStatus, 
                         dbo.I10_Amcare_VR.ReciprocalBillingStatusDesc, dbo.I10_Amcare_VR.RedBloodCell, dbo.I10_Amcare_VR.RedBloodCellDesc, dbo.I10_Amcare_VR.RedBloodCellCrossMatched, 
                         dbo.I10_Amcare_VR.RedBloodCellCrossMatchedDesc, dbo.I10_Amcare_VR.RedBloodCellTyped, dbo.I10_Amcare_VR.RedBloodCellTypedDesc, dbo.I10_Amcare_VR.RedBloodCellUnits, 
                         dbo.I10_Amcare_VR.ReferralDate, dbo.I10_Amcare_VR.ReferredFrom, dbo.I10_Amcare_VR.ReferredFromDesc, dbo.I10_Amcare_VR.ReferredTo, dbo.I10_Amcare_VR.ReferredToDesc, 
                         dbo.I10_Amcare_VR.ReferringProvider, dbo.I10_Amcare_VR.ReferringProviderDesc, dbo.I10_Amcare_VR.RegisterNumber, dbo.I10_Amcare_VR.RegistrationNumber, 
                         dbo.I10_Amcare_VR.RegistrationSequenceNumber, dbo.I10_Amcare_VR.RegistrationVisitDate, dbo.I10_Amcare_VR.RegistrationVisitTime, dbo.I10_Amcare_VR.ReproductiveCareComments, 
                         dbo.I10_Amcare_VR.ReserveField, dbo.I10_Amcare_VR.ResidenceCode, dbo.I10_Amcare_VR.ResidenceCodeDesc, dbo.I10_Amcare_VR.ResidenceProvince, dbo.I10_Amcare_VR.ResidenceProvinceDesc, 
                         dbo.I10_Amcare_VR.ResidenceRegion, dbo.I10_Amcare_VR.ResidenceRegionDesc, dbo.I10_Amcare_VR.ResidenceType, dbo.I10_Amcare_VR.ResidenceTypeDesc, dbo.I10_Amcare_VR.ResponsiblityForPayment,
                          dbo.I10_Amcare_VR.ResponsiblityForPaymentDesc, dbo.I10_Amcare_VR.SchedEDVisit, dbo.I10_Amcare_VR.SchedEDVisitDesc, dbo.I10_Amcare_VR.SeatbeltIndicator, dbo.I10_Amcare_VR.SeatbeltIndicatorDesc, 
                         dbo.I10_Amcare_VR.SecondChartRegisterNumber, dbo.I10_Amcare_VR.SecretVIPPatient, dbo.I10_Amcare_VR.SecretVIPPatientDesc, dbo.I10_Amcare_VR.SiteNumber, dbo.I10_Amcare_VR.SiteNumberDesc, 
                         dbo.I10_Amcare_VR.SocialService, dbo.I10_Amcare_VR.SocialServiceDesc, dbo.I10_Amcare_VR.SourceofReferral, dbo.I10_Amcare_VR.SourceofReferralDesc, dbo.I10_Amcare_VR.SpecialistNumber, 
                         dbo.I10_Amcare_VR.SpecialistNumberDesc, dbo.I10_Amcare_VR.SpecialistRequestDate, dbo.I10_Amcare_VR.SpecialistRequestService, dbo.I10_Amcare_VR.SpecialistRequestServiceDesc, 
                         dbo.I10_Amcare_VR.SpecialistRequestTime, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknown, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknownDesc, dbo.I10_Amcare_VR.StakeholderType, 
                         dbo.I10_Amcare_VR.StakeholderTypeDesc, dbo.I10_Amcare_VR.StatusAfterTriage, dbo.I10_Amcare_VR.StatusAfterTriageDesc, dbo.I10_Amcare_VR.Sterilization, dbo.I10_Amcare_VR.SterilizationDesc, 
                         dbo.I10_Amcare_VR.SubmissionLevelCode, dbo.I10_Amcare_VR.SubmissionRecordID, dbo.I10_Amcare_VR.SubsequentOR, dbo.I10_Amcare_VR.SubsequentORDesc, dbo.I10_Amcare_VR.Suicide, 
                         dbo.I10_Amcare_VR.SuicideDesc, dbo.I10_Amcare_VR.SurgicalCase, dbo.I10_Amcare_VR.SurgicalCaseDesc, dbo.I10_Amcare_VR.TimeLeftER, dbo.I10_Amcare_VR.TimeLeftERUnknown, 
                         dbo.I10_Amcare_VR.TimeLeftERUnknownDEsc, dbo.I10_Amcare_VR.TransferOverloadDate, dbo.I10_Amcare_VR.TransferOverloadTime, dbo.I10_Amcare_VR.TransferOverloadTimeDifference, 
                         dbo.I10_Amcare_VR.TransfusionGiven, dbo.I10_Amcare_VR.TransfusionGivenDesc, dbo.I10_Amcare_VR.Trauma, dbo.I10_Amcare_VR.TraumaDesc, dbo.I10_Amcare_VR.TriageDate, 
                         dbo.I10_Amcare_VR.TriageLevel, dbo.I10_Amcare_VR.TriageLevelDesc, dbo.I10_Amcare_VR.TriageTime, dbo.I10_Amcare_VR.TriageTimeUnknown, dbo.I10_Amcare_VR.TriageTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.TSICoder, dbo.I10_Amcare_VR.TSICoderDesc, dbo.I10_Amcare_VR.TSIDate, dbo.I10_Amcare_VR.TSITime, dbo.I10_Amcare_VR.TwoTenPO, dbo.I10_Amcare_VR.ULI, 
                         dbo.I10_Amcare_VR.UniversalEpisodeIdentifier, dbo.I10_Amcare_VR.UnplannedReadmit, dbo.I10_Amcare_VR.VisitStatus, dbo.I10_Amcare_VR.VisitStatusDesc, dbo.I10_Amcare_VR.VisitType, dbo.I10_Amcare_VR.VisitTypeDesc, 
                         dbo.I10_Amcare_VR.WaitTimeinER, dbo.I10_Amcare_VR.WaittoAssessmentinMinutes, dbo.I10_Amcare_VR.WaittoNursingAssessmentDiff, dbo.I10_Amcare_VR.Weight, dbo.I10_Amcare_VR.zzAbstractLink, 
                         dbo.I10_Amcare_VR.zzRegionalPatientID, dbo.I10_Amcare_VR.zzVolumeLink, 

						dbo.I10_Amcare_Projects_Question_24_VR.ProjectNumber, dbo.I10_Amcare_Projects_Question_24_VR.ProjectNumberDesc, 
                         dbo.I10_Amcare_Projects_Question_24_VR.ProjectOccurrence, dbo.I10_Amcare_Projects_Question_24_VR.Question1, dbo.I10_Amcare_Projects_Question_24_VR.Question1Desc, 
                         dbo.I10_Amcare_Projects_Question_24_VR.Question2, dbo.I10_Amcare_Projects_Question_24_VR.Question2Desc, dbo.I10_Amcare_Projects_Question_24_VR.Question3, 
                         dbo.I10_Amcare_Projects_Question_24_VR.Question3Desc, dbo.I10_Amcare_Projects_Question_24_VR.Question4, dbo.I10_Amcare_Projects_Question_24_VR.Question4Desc, 
                         dbo.I10_Amcare_Projects_Question_24_VR.Question5, dbo.I10_Amcare_Projects_Question_24_VR.Question5Desc, dbo.I10_Amcare_Projects_Question_24_VR.Question6, 
                         dbo.I10_Amcare_Projects_Question_24_VR.Question6Desc, dbo.I10_Amcare_Projects_Question_24_VR.Question7, dbo.I10_Amcare_Projects_Question_24_VR.Question7Desc, 
                         dbo.I10_Amcare_Projects_Question_24_VR.Question8, dbo.I10_Amcare_Projects_Question_24_VR.Question8Desc, dbo.I10_Amcare_Projects_Question_24_VR.Question9, 
                         dbo.I10_Amcare_Projects_Question_24_VR.Question9Desc, dbo.I10_Amcare_Projects_Question_24_VR.Question10, dbo.I10_Amcare_Projects_Question_24_VR.Question10Desc, 
                         dbo.I10_Amcare_Projects_Question_24_VR.Question11, dbo.I10_Amcare_Projects_Question_24_VR.Question11Desc, dbo.I10_Amcare_Projects_Question_24_VR.Question12, 
                         dbo.I10_Amcare_Projects_Question_24_VR.Question12Desc, dbo.I10_Amcare_Projects_Question_24_VR.Question13, dbo.I10_Amcare_Projects_Question_24_VR.Question13Desc, 
                         dbo.I10_Amcare_Projects_Question_24_VR.Question14, dbo.I10_Amcare_Projects_Question_24_VR.Question15, dbo.I10_Amcare_Projects_Question_24_VR.Question16, 
                         dbo.I10_Amcare_Projects_Question_24_VR.Question17, dbo.I10_Amcare_Projects_Question_24_VR.Question18, dbo.I10_Amcare_Projects_Question_24_VR.Question19, 
                         dbo.I10_Amcare_Projects_Question_24_VR.Question20, dbo.I10_Amcare_Projects_Question_24_VR.Question21, dbo.I10_Amcare_Projects_Question_24_VR.Question22, 
                         dbo.I10_Amcare_Projects_Question_24_VR.Question23, dbo.I10_Amcare_Projects_Question_24_VR.Question24
FROM            dbo.I10_Amcare_Projects_Question_24_VR RIGHT OUTER JOIN
                         dbo.I10_Amcare_VR ON dbo.I10_Amcare_Projects_Question_24_VR.zzAbstractLink = dbo.I10_Amcare_VR.zzAbstractLink



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Project_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_Amcare_And_Project_VR]
AS
SELECT        dbo.I10_Amcare_VR.[#ofPreviousPreTermDeliveries], dbo.I10_Amcare_VR.[#ofPrevSpontaneousAbortions], dbo.I10_Amcare_VR.[#ofPreviousTermDeliveries], dbo.I10_Amcare_VR.AccessPrimaryHealthCareCode, 
                         dbo.I10_Amcare_VR.AccessPrimaryHealthCareCodeDesc, dbo.I10_Amcare_VR.AmbulanceArrivalDate, dbo.I10_Amcare_VR.AmbulanceArrivalTime, dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknown, 
                         dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknownDesc, dbo.I10_Amcare_VR.AmbulanceTransferCareDate, dbo.I10_Amcare_VR.AmbulanceTransferCareTime, 
                         dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknown, dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknownDesc, dbo.I10_Amcare_VR.[#ofPrevTherapeuticAbortions], dbo.I10_Amcare_VR.AWOL, 
                         dbo.I10_Amcare_VR.AWOLDesc, dbo.I10_Amcare_VR.AbortDate, dbo.I10_Amcare_VR.AbstractNumber, dbo.I10_Amcare_VR.AbstractOverflow, dbo.I10_Amcare_VR.AbstractOverflowDesc, 
                         dbo.I10_Amcare_VR.ActivityDescription, dbo.I10_Amcare_VR.ActivityWhenInjured, dbo.I10_Amcare_VR.ActivityWhenInjuredDesc, dbo.I10_Amcare_VR.ActueLOS, dbo.I10_Amcare_VR.AdmitbyAmbulance, 
                         dbo.I10_Amcare_VR.AdmitbyAmbulanceDesc, dbo.I10_Amcare_VR.AdmitCategory, dbo.I10_Amcare_VR.AdmitDiagnosis, dbo.I10_Amcare_VR.AdmitNursingArea, dbo.I10_Amcare_VR.AdmitNursingAreaDesc, 
                         dbo.I10_Amcare_VR.AfterAdmit, dbo.I10_Amcare_VR.AgeCode, dbo.I10_Amcare_VR.AgeCodeDesc, dbo.I10_Amcare_VR.AgeGroup, dbo.I10_Amcare_VR.AgeNumber, dbo.I10_Amcare_VR.Albumin, 
                         dbo.I10_Amcare_VR.AlbuminDesc, dbo.I10_Amcare_VR.AlbuminCrossMatched, dbo.I10_Amcare_VR.AlbuminCrossMatchedDesc, dbo.I10_Amcare_VR.AlbuminTyped, dbo.I10_Amcare_VR.AlbuminTypedDesc, 
                         dbo.I10_Amcare_VR.AlbuminUnits, dbo.I10_Amcare_VR.ALCLOS, dbo.I10_Amcare_VR.AmbulanceReportNumber, dbo.I10_Amcare_VR.AmCareGroup, dbo.I10_Amcare_VR.AmCareGroupDesc, 
                         dbo.I10_Amcare_VR.AmcareCareType, dbo.I10_Amcare_VR.AmcareCareTypeDesc, dbo.I10_Amcare_VR.AmcareTypeCode, dbo.I10_Amcare_VR.AmcareTypeCodeDesc, dbo.I10_Amcare_VR.Ancil13, 
                         dbo.I10_Amcare_VR.Ancil14, dbo.I10_Amcare_VR.Ancil15, dbo.I10_Amcare_VR.Ancil16, dbo.I10_Amcare_VR.Ancil17, dbo.I10_Amcare_VR.AncillaryField1, dbo.I10_Amcare_VR.AncillaryField1Desc, 
                         dbo.I10_Amcare_VR.AncillaryField10, dbo.I10_Amcare_VR.AncillaryField10Desc, dbo.I10_Amcare_VR.AncillaryField11, dbo.I10_Amcare_VR.AncillaryField11Desc, dbo.I10_Amcare_VR.AncillaryField12, 
                         dbo.I10_Amcare_VR.AncillaryField12Desc, dbo.I10_Amcare_VR.AncillaryField2, dbo.I10_Amcare_VR.AncillaryField2Desc, dbo.I10_Amcare_VR.AncillaryField3, dbo.I10_Amcare_VR.AncillaryField3Desc, 
                         dbo.I10_Amcare_VR.AncillaryField4, dbo.I10_Amcare_VR.AncillaryField4Desc, dbo.I10_Amcare_VR.AncillaryField5, dbo.I10_Amcare_VR.AncillaryField5Desc, dbo.I10_Amcare_VR.AncillaryField6, 
                         dbo.I10_Amcare_VR.AncillaryField6Desc, dbo.I10_Amcare_VR.AncillaryField7, dbo.I10_Amcare_VR.AncillaryField7Desc, dbo.I10_Amcare_VR.AncillaryField8, dbo.I10_Amcare_VR.AncillaryField8Desc, 
                         dbo.I10_Amcare_VR.AncillaryField9, dbo.I10_Amcare_VR.AncillaryField9Desc, dbo.I10_Amcare_VR.ArrivalDate, dbo.I10_Amcare_VR.ArrivalMode, dbo.I10_Amcare_VR.ArrivalModeDesc, 
                         dbo.I10_Amcare_VR.ArrivalTime, dbo.I10_Amcare_VR.ArrivaltoTriageTime, dbo.I10_Amcare_VR.AssessmentDate, dbo.I10_Amcare_VR.AssessmentTime, dbo.I10_Amcare_VR.AssessmentTimeUnknown, 
                         dbo.I10_Amcare_VR.AssessmentTimeUnknownDesc, dbo.I10_Amcare_VR.AttendingPhysician, dbo.I10_Amcare_VR.AttendingPhysicianDesc, dbo.I10_Amcare_VR.AutoTransfusion, 
                         dbo.I10_Amcare_VR.AutoTransfusionDesc, dbo.I10_Amcare_VR.AutopsyPerformed, dbo.I10_Amcare_VR.AutopsyPerformedDesc, dbo.I10_Amcare_VR.BasicOption1, dbo.I10_Amcare_VR.BasicOption1Desc, 
                         dbo.I10_Amcare_VR.BasicOption10, dbo.I10_Amcare_VR.BasicOption10Desc, dbo.I10_Amcare_VR.BasicOption11, dbo.I10_Amcare_VR.BasicOption11Desc, dbo.I10_Amcare_VR.BasicOption12, 
                         dbo.I10_Amcare_VR.BasicOption12Desc, dbo.I10_Amcare_VR.BasicOption13, dbo.I10_Amcare_VR.BasicOption13Desc, dbo.I10_Amcare_VR.BasicOption14, dbo.I10_Amcare_VR.BasicOption14Desc, 
                         dbo.I10_Amcare_VR.BasicOption15, dbo.I10_Amcare_VR.BasicOption15Desc, dbo.I10_Amcare_VR.BasicOption16, dbo.I10_Amcare_VR.BasicOption16Desc, dbo.I10_Amcare_VR.BasicOption17, 
                         dbo.I10_Amcare_VR.BasicOption17Desc, dbo.I10_Amcare_VR.BasicOption18, dbo.I10_Amcare_VR.BasicOption18Desc, dbo.I10_Amcare_VR.BasicOption19, dbo.I10_Amcare_VR.BasicOption19Desc, 
                         dbo.I10_Amcare_VR.BasicOption2, dbo.I10_Amcare_VR.BasicOption2Desc, dbo.I10_Amcare_VR.BasicOption3, dbo.I10_Amcare_VR.BasicOption3Desc, dbo.I10_Amcare_VR.BasicOption4, 
                         dbo.I10_Amcare_VR.BasicOption4Desc, dbo.I10_Amcare_VR.BasicOption5, dbo.I10_Amcare_VR.BasicOption5Desc, dbo.I10_Amcare_VR.BasicOption6, dbo.I10_Amcare_VR.BasicOption6Desc, 
                         dbo.I10_Amcare_VR.BasicOption7, dbo.I10_Amcare_VR.BasicOption7Desc, dbo.I10_Amcare_VR.BasicOption8, dbo.I10_Amcare_VR.BasicOption8Desc, dbo.I10_Amcare_VR.BasicOption9, 
                         dbo.I10_Amcare_VR.BasicOption9Desc, dbo.I10_Amcare_VR.BatchNumber, dbo.I10_Amcare_VR.BatchPeriod, dbo.I10_Amcare_VR.BatchPeriodDesc, dbo.I10_Amcare_VR.BatchPeriod_BC, 
                         dbo.I10_Amcare_VR.BatchYear, dbo.I10_Amcare_VR.BirthDate, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIII, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIIIDesc, 
						 dbo.I10_Amcare_VR.Blood_C1Inhibitor, 
                         dbo.I10_Amcare_VR.Blood_C1InhibitorDesc, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasma, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_CryosupernatantPlasma, 
                         dbo.I10_Amcare_VR.Blood_CryosupernatantPlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_FEIBA, 
						 dbo.I10_Amcare_VR.Blood_FEIBADesc, 
						 dbo.I10_Amcare_VR.Blood_Fibrinogen, 
						 dbo.I10_Amcare_VR.Blood_FibrinogenDesc, 
                         dbo.I10_Amcare_VR.Blood_IVIG_SCIG, 
						 dbo.I10_Amcare_VR.Blood_IVIG_SCIGDesc, 
						 dbo.I10_Amcare_VR.Blood_PCC, 
						 dbo.I10_Amcare_VR.Blood_PCCDesc, 
						 dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactors, 
                         dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactorsDesc, 
						 
						 dbo.I10_Amcare_VR.BreastFeeding, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlag, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlagDesc, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitDateIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknown, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknownDesc, dbo.I10_Amcare_VR.ClinicalDecisionUnitDateOut, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOut, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknown, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknownDesc, dbo.I10_Amcare_VR.ChangeinLegalStatus, 
                         dbo.I10_Amcare_VR.ChangeinLegalStatusDesc, dbo.I10_Amcare_VR.ChartNumber, dbo.I10_Amcare_VR.ChiefComplaint, dbo.I10_Amcare_VR.CoderNumber, dbo.I10_Amcare_VR.CoderNumberDesc, 
                         dbo.I10_Amcare_VR.CompleteRecord, dbo.I10_Amcare_VR.CompleteRecordDesc, dbo.I10_Amcare_VR.Complication, dbo.I10_Amcare_VR.ComplicationDesc, dbo.I10_Amcare_VR.Complication1, 
                         dbo.I10_Amcare_VR.Complication1Desc, dbo.I10_Amcare_VR.Complication2, dbo.I10_Amcare_VR.Complication2Desc, dbo.I10_Amcare_VR.Complication3, dbo.I10_Amcare_VR.Complication3Desc, 
                         dbo.I10_Amcare_VR.ContactMode, dbo.I10_Amcare_VR.ContactModeDesc, dbo.I10_Amcare_VR.CoronerCase, dbo.I10_Amcare_VR.CoronerCaseDesc, dbo.I10_Amcare_VR.DataEntryCoder, 
                         dbo.I10_Amcare_VR.DataEntryCoderDesc, dbo.I10_Amcare_VR.DateLeftER, dbo.I10_Amcare_VR.DateofLastMenses, dbo.I10_Amcare_VR.DateReadyforDisch, dbo.I10_Amcare_VR.DateSentToCIHI, 
                         dbo.I10_Amcare_VR.DateSentToCIHILevel1, dbo.I10_Amcare_VR.DateSentToCIHILevel2, dbo.I10_Amcare_VR.DateSentToCIHILite, dbo.I10_Amcare_VR.DeathInER, dbo.I10_Amcare_VR.DeathInERDesc, 
                         dbo.I10_Amcare_VR.DeathOnArrival, dbo.I10_Amcare_VR.DeathOnArrivalDesc, dbo.I10_Amcare_VR.DecisionAdmitDifference, dbo.I10_Amcare_VR.DecisiontoAdmitDate, dbo.I10_Amcare_VR.DecisiontoAdmitTime, 
                         dbo.I10_Amcare_VR.DecisionAdmitTimeUnknown, dbo.I10_Amcare_VR.DecisionAdmitTimeUnknownDesc, dbo.I10_Amcare_VR.DeliveryDate, dbo.I10_Amcare_VR.DeliveryTime, 
                         dbo.I10_Amcare_VR.DiedDuringIntervention, dbo.I10_Amcare_VR.DiedDuringInterventionDesc, dbo.I10_Amcare_VR.DischNursingArea, dbo.I10_Amcare_VR.DischNursingAreaDesc, 
                         dbo.I10_Amcare_VR.DischPlanning, dbo.I10_Amcare_VR.DischPlanningDesc, dbo.I10_Amcare_VR.DischargeAge, dbo.I10_Amcare_VR.DischargeDisposition, dbo.I10_Amcare_VR.DischargeDispositionDesc, 
                         dbo.I10_Amcare_VR.DispositionDate, dbo.I10_Amcare_VR.DispositionTime, dbo.I10_Amcare_VR.DispositionTimeUnknown, dbo.I10_Amcare_VR.DispositionTimeUnknownDesc, dbo.I10_Amcare_VR.ECTTreatment, 
                         dbo.I10_Amcare_VR.ECTTreatmentDesc, dbo.I10_Amcare_VR.Education, dbo.I10_Amcare_VR.EducationDesc, dbo.I10_Amcare_VR.EDVisitIndicator, dbo.I10_Amcare_VR.EDVisitIndicatorDesc, 
                         dbo.I10_Amcare_VR.Employment, dbo.I10_Amcare_VR.EmploymentDesc, dbo.I10_Amcare_VR.EntryCode, dbo.I10_Amcare_VR.EstimateDischDate, dbo.I10_Amcare_VR.ExitCode, 
                         dbo.I10_Amcare_VR.FamilyPhysicianFlag, dbo.I10_Amcare_VR.FamilyPhysicianFlagDesc, dbo.I10_Amcare_VR.FinancialSupport, dbo.I10_Amcare_VR.FinancialSupportDesc, dbo.I10_Amcare_VR.FinishDate, 
                         dbo.I10_Amcare_VR.FinishTime, dbo.I10_Amcare_VR.FirstName, dbo.I10_Amcare_VR.FullName, dbo.I10_Amcare_VR.FixedChartNumber, dbo.I10_Amcare_VR.Gender, dbo.I10_Amcare_VR.GenderDesc, 
                         dbo.I10_Amcare_VR.GestationalAgeinweeks, dbo.I10_Amcare_VR.GlasgowScale, dbo.I10_Amcare_VR.GlasgowScaleDesc, dbo.I10_Amcare_VR.GreaterTenPO, dbo.I10_Amcare_VR.HCNProvince, 
                         dbo.I10_Amcare_VR.HCNProvinceDesc, dbo.I10_Amcare_VR.HCNVersion, dbo.I10_Amcare_VR.HealthCareNumber, dbo.I10_Amcare_VR.Hospital, dbo.I10_Amcare_VR.HospitalDesc, 
                         dbo.I10_Amcare_VR.HospitalAccountRecord,
                         dbo.I10_Amcare_VR.HelmetIndicator, dbo.I10_Amcare_VR.HelmetIndicatorDesc, dbo.I10_Amcare_VR.InSCU, dbo.I10_Amcare_VR.InitialOR, dbo.I10_Amcare_VR.InitialORDesc, dbo.I10_Amcare_VR.InjuryDate, 
                         dbo.I10_Amcare_VR.Injury, dbo.I10_Amcare_VR.InjuryDesc, dbo.I10_Amcare_VR.InputDate, dbo.I10_Amcare_VR.InputTime, 

						 dbo.I10_Amcare_VR.InstitutionFrom, dbo.I10_Amcare_VR.InstitutionFromDesc, 
						 dbo.I10_Amcare_VR.InstitutionFromType, dbo.I10_Amcare_VR.InstitutionFromTypeDesc,
                         dbo.I10_Amcare_VR.InstFromCareType, dbo.I10_Amcare_VR.InstFromHospType, 
						 dbo.I10_Amcare_VR.InstitutionNumber, dbo.I10_Amcare_VR.InstitutionNumberDesc, 
						 dbo.I10_Amcare_VR.InstitutionTo, dbo.I10_Amcare_VR.InstitutionToDesc, 
						 dbo.I10_Amcare_VR.InstToCareType, dbo.I10_Amcare_VR.InstToHospType, 
						 dbo.I10_Amcare_VR.InstitutionToType, dbo.I10_Amcare_VR.InstitutionToTypeDesc, 
						 
						 dbo.I10_Amcare_VR.InterfaceDate, dbo.I10_Amcare_VR.InterfaceTime, 
                         dbo.I10_Amcare_VR.IsAbstractCompleted, dbo.I10_Amcare_VR.IsAbstractCompletedDesc, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCompletedLevel2, dbo.I10_Amcare_VR.IsAbstractCompletedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCompletedLite, dbo.I10_Amcare_VR.IsAbstractCompletedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrected, dbo.I10_Amcare_VR.IsAbstractCorrectedDesc, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCorrectedLite, dbo.I10_Amcare_VR.IsAbstractCorrectedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractDeleted, dbo.I10_Amcare_VR.IsAbstractDeletedDesc, dbo.I10_Amcare_VR.IsAbstractSubmitted, dbo.I10_Amcare_VR.IsAbstractSubmittedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLite, dbo.I10_Amcare_VR.IsAbstractSubmittedLiteDesc, dbo.I10_Amcare_VR.IsAbstractValidated, dbo.I10_Amcare_VR.IsAbstractValidatedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLevel1, dbo.I10_Amcare_VR.IsAbstractValidatedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLite, dbo.I10_Amcare_VR.IsAbstractValidatedLiteDesc, dbo.I10_Amcare_VR.IsBirthdateEstimated, dbo.I10_Amcare_VR.IsBirthdateEstimatedDesc, 
						 dbo.I10_Amcare_VR.IsCustomValidated, dbo.I10_Amcare_VR.IsCustomValidatedDesc,
                         dbo.I10_Amcare_VR.LOSDays, dbo.I10_Amcare_VR.LOSTime, dbo.I10_Amcare_VR.LOSTimeinHours, dbo.I10_Amcare_VR.LOSTotalMinutes, dbo.I10_Amcare_VR.Language, dbo.I10_Amcare_VR.LanguageDesc, 
                         dbo.I10_Amcare_VR.LastName, dbo.I10_Amcare_VR.LessTwoPO, dbo.I10_Amcare_VR.LivingArrangement, dbo.I10_Amcare_VR.LivingArrangementDesc, dbo.I10_Amcare_VR.LocationofInjury, 
                         dbo.I10_Amcare_VR.LocationofInjuryDesc, dbo.I10_Amcare_VR.MISCode, dbo.I10_Amcare_VR.MISCodeDesc, dbo.I10_Amcare_VR.MaidenName, dbo.I10_Amcare_VR.MaritalStatus, 
                         dbo.I10_Amcare_VR.MaritalStatusDesc, 
                         dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoED, 
						 dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04Desc, 
						 
						 dbo.I10_Amcare_VR.MethodofAdmission, dbo.I10_Amcare_VR.MethodofAdmissionDesc, dbo.I10_Amcare_VR.MiddleName, 
                         dbo.I10_Amcare_VR.NACRSClinicLiteSubmission, dbo.I10_Amcare_VR.NACRSClinicLiteSubmissionDesc, 
                         dbo.I10_Amcare_VR.NewbornChart, 
                         dbo.I10_Amcare_VR.NewbornDischDate, dbo.I10_Amcare_VR.NextScheduledVisitDate, dbo.I10_Amcare_VR.NextScheduledVisitTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentDate, 
                         dbo.I10_Amcare_VR.NonPhysicianAssessmentTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknown, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.NonPhysicianNumber, dbo.I10_Amcare_VR.NonPhysicianNumberDesc, dbo.I10_Amcare_VR.NonPhysicianService, dbo.I10_Amcare_VR.NonPhysicianServiceDesc, 
                         dbo.I10_Amcare_VR.NumberofECT, dbo.I10_Amcare_VR.NursingAssessmentDate, dbo.I10_Amcare_VR.NursingAssessmentTime, dbo.I10_Amcare_VR.Occupation, dbo.I10_Amcare_VR.OccupationDesc, 
                         dbo.I10_Amcare_VR.OtherMedicalDeath, dbo.I10_Amcare_VR.OtherMedicalDeathDesc, dbo.I10_Amcare_VR.OtherBlood, dbo.I10_Amcare_VR.OtherBloodDesc, dbo.I10_Amcare_VR.OtherBloodCrossMatched, 
                         dbo.I10_Amcare_VR.OtherBloodCrossMatchedDesc, dbo.I10_Amcare_VR.OtherBloodTyped, dbo.I10_Amcare_VR.OtherBloodTypedDesc, dbo.I10_Amcare_VR.OtherBloodUnits, dbo.I10_Amcare_VR.PCTASIndicator, 
                         dbo.I10_Amcare_VR.PCTASIndicatorDesc, dbo.I10_Amcare_VR.PhysicianEstLOS, dbo.I10_Amcare_VR.Plasma, dbo.I10_Amcare_VR.PlasmaDesc, dbo.I10_Amcare_VR.PlasmaCrossMatched, 
                         dbo.I10_Amcare_VR.PlasmaCrossMatchedDesc, dbo.I10_Amcare_VR.PlasmaTyped, dbo.I10_Amcare_VR.PlasmaTypedDesc, dbo.I10_Amcare_VR.PlasmaUnits, dbo.I10_Amcare_VR.Platelets, 
                         dbo.I10_Amcare_VR.PlateletsDesc, dbo.I10_Amcare_VR.PlateletsCrossMatched, dbo.I10_Amcare_VR.PlateletsCrossMatchedDesc, dbo.I10_Amcare_VR.PlateletsTyped, dbo.I10_Amcare_VR.PlateletsTypedDesc, 
                         dbo.I10_Amcare_VR.PlateletsUnits, dbo.I10_Amcare_VR.PostalCode, dbo.I10_Amcare_VR.PostalCodeDesc, dbo.I10_Amcare_VR.PostOpDays, dbo.I10_Amcare_VR.PreOpDays, 
                         dbo.I10_Amcare_VR.PreamditWorkUp, dbo.I10_Amcare_VR.PreamditWorkUpDesc, dbo.I10_Amcare_VR.Pregnancy, dbo.I10_Amcare_VR.PregnancyDesc, dbo.I10_Amcare_VR.PrevLiveBirth, 
                         dbo.I10_Amcare_VR.PreviousPsychiartricAdmissions, dbo.I10_Amcare_VR.PreviousPsychiartricAdmDesc, dbo.I10_Amcare_VR.Program, dbo.I10_Amcare_VR.ProgramDesc, dbo.I10_Amcare_VR.ProvinceNumber, 
                         dbo.I10_Amcare_VR.ProvinceNumberDesc, dbo.I10_Amcare_VR.ReasonForVisit, dbo.I10_Amcare_VR.ReasonForVisitDesc, dbo.I10_Amcare_VR.ReAdmitCode, dbo.I10_Amcare_VR.ReciprocalBillingStatus, 
                         dbo.I10_Amcare_VR.ReciprocalBillingStatusDesc, dbo.I10_Amcare_VR.RedBloodCell, dbo.I10_Amcare_VR.RedBloodCellDesc, dbo.I10_Amcare_VR.RedBloodCellCrossMatched, 
                         dbo.I10_Amcare_VR.RedBloodCellCrossMatchedDesc, dbo.I10_Amcare_VR.RedBloodCellTyped, dbo.I10_Amcare_VR.RedBloodCellTypedDesc, dbo.I10_Amcare_VR.RedBloodCellUnits, 
                         dbo.I10_Amcare_VR.ReferralDate, dbo.I10_Amcare_VR.ReferredFrom, dbo.I10_Amcare_VR.ReferredFromDesc, dbo.I10_Amcare_VR.ReferredTo, dbo.I10_Amcare_VR.ReferredToDesc, 
                         dbo.I10_Amcare_VR.ReferringProvider, dbo.I10_Amcare_VR.ReferringProviderDesc, dbo.I10_Amcare_VR.RegisterNumber, dbo.I10_Amcare_VR.RegistrationNumber, 
                         dbo.I10_Amcare_VR.RegistrationSequenceNumber, dbo.I10_Amcare_VR.RegistrationVisitDate, dbo.I10_Amcare_VR.RegistrationVisitTime, dbo.I10_Amcare_VR.ReproductiveCareComments, 
                         dbo.I10_Amcare_VR.ReserveField, dbo.I10_Amcare_VR.ResidenceCode, dbo.I10_Amcare_VR.ResidenceCodeDesc, dbo.I10_Amcare_VR.ResidenceProvince, dbo.I10_Amcare_VR.ResidenceProvinceDesc, 
                         dbo.I10_Amcare_VR.ResidenceRegion, dbo.I10_Amcare_VR.ResidenceRegionDesc, dbo.I10_Amcare_VR.ResidenceType, dbo.I10_Amcare_VR.ResidenceTypeDesc, dbo.I10_Amcare_VR.ResponsiblityForPayment,
                          dbo.I10_Amcare_VR.ResponsiblityForPaymentDesc, dbo.I10_Amcare_VR.SchedEDVisit, dbo.I10_Amcare_VR.SchedEDVisitDesc, dbo.I10_Amcare_VR.SeatbeltIndicator, dbo.I10_Amcare_VR.SeatbeltIndicatorDesc, 
                         dbo.I10_Amcare_VR.SecondChartRegisterNumber, dbo.I10_Amcare_VR.SecretVIPPatient, dbo.I10_Amcare_VR.SecretVIPPatientDesc, dbo.I10_Amcare_VR.SiteNumber, dbo.I10_Amcare_VR.SiteNumberDesc, 
                         dbo.I10_Amcare_VR.SocialService, dbo.I10_Amcare_VR.SocialServiceDesc, dbo.I10_Amcare_VR.SourceofReferral, dbo.I10_Amcare_VR.SourceofReferralDesc, dbo.I10_Amcare_VR.SpecialistNumber, 
                         dbo.I10_Amcare_VR.SpecialistNumberDesc, dbo.I10_Amcare_VR.SpecialistRequestDate, dbo.I10_Amcare_VR.SpecialistRequestService, dbo.I10_Amcare_VR.SpecialistRequestServiceDesc, 
                         dbo.I10_Amcare_VR.SpecialistRequestTime, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknown, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknownDesc, dbo.I10_Amcare_VR.StakeholderType, 
                         dbo.I10_Amcare_VR.StakeholderTypeDesc, dbo.I10_Amcare_VR.StatusAfterTriage, dbo.I10_Amcare_VR.StatusAfterTriageDesc, dbo.I10_Amcare_VR.Sterilization, dbo.I10_Amcare_VR.SterilizationDesc, 
                         dbo.I10_Amcare_VR.SubmissionLevelCode, dbo.I10_Amcare_VR.SubmissionRecordID, dbo.I10_Amcare_VR.SubsequentOR, dbo.I10_Amcare_VR.SubsequentORDesc, dbo.I10_Amcare_VR.Suicide, 
                         dbo.I10_Amcare_VR.SuicideDesc, dbo.I10_Amcare_VR.SurgicalCase, dbo.I10_Amcare_VR.SurgicalCaseDesc, dbo.I10_Amcare_VR.TimeLeftER, dbo.I10_Amcare_VR.TimeLeftERUnknown, 
                         dbo.I10_Amcare_VR.TimeLeftERUnknownDEsc, dbo.I10_Amcare_VR.TransferOverloadDate, dbo.I10_Amcare_VR.TransferOverloadTime, dbo.I10_Amcare_VR.TransferOverloadTimeDifference, 
                         dbo.I10_Amcare_VR.TransfusionGiven, dbo.I10_Amcare_VR.TransfusionGivenDesc, dbo.I10_Amcare_VR.Trauma, dbo.I10_Amcare_VR.TraumaDesc, dbo.I10_Amcare_VR.TriageDate, 
                         dbo.I10_Amcare_VR.TriageLevel, dbo.I10_Amcare_VR.TriageLevelDesc, dbo.I10_Amcare_VR.TriageTime, dbo.I10_Amcare_VR.TriageTimeUnknown, dbo.I10_Amcare_VR.TriageTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.TSICoder, dbo.I10_Amcare_VR.TSICoderDesc, dbo.I10_Amcare_VR.TSIDate, dbo.I10_Amcare_VR.TSITime, dbo.I10_Amcare_VR.TwoTenPO, dbo.I10_Amcare_VR.ULI, 
                         dbo.I10_Amcare_VR.UniversalEpisodeIdentifier, dbo.I10_Amcare_VR.UnplannedReadmit, dbo.I10_Amcare_VR.VisitStatus, dbo.I10_Amcare_VR.VisitStatusDesc, dbo.I10_Amcare_VR.VisitType, dbo.I10_Amcare_VR.VisitTypeDesc, 
                         dbo.I10_Amcare_VR.WaitTimeinER, dbo.I10_Amcare_VR.WaittoAssessmentinMinutes, dbo.I10_Amcare_VR.WaittoNursingAssessmentDiff, dbo.I10_Amcare_VR.Weight, dbo.I10_Amcare_VR.zzAbstractLink, 
                         dbo.I10_Amcare_VR.zzRegionalPatientID, dbo.I10_Amcare_VR.zzVolumeLink, 

						dbo.I10_Amcare_Projects_VR.ProjectNumber, dbo.I10_Amcare_Projects_VR.ProjectNumberDesc, 
                         dbo.I10_Amcare_Projects_VR.ProjectOccurrence, dbo.I10_Amcare_Projects_VR.Question1, dbo.I10_Amcare_Projects_VR.Question1Desc, dbo.I10_Amcare_Projects_VR.Question2, 
                         dbo.I10_Amcare_Projects_VR.Question2Desc, dbo.I10_Amcare_Projects_VR.Question3, dbo.I10_Amcare_Projects_VR.Question3Desc, dbo.I10_Amcare_Projects_VR.Question4, 
                         dbo.I10_Amcare_Projects_VR.Question4Desc, dbo.I10_Amcare_Projects_VR.Question5, dbo.I10_Amcare_Projects_VR.Question5Desc, dbo.I10_Amcare_Projects_VR.Question6, 
                         dbo.I10_Amcare_Projects_VR.Question6Desc, dbo.I10_Amcare_Projects_VR.Question7, dbo.I10_Amcare_Projects_VR.Question7Desc, dbo.I10_Amcare_Projects_VR.Question8, 
                         dbo.I10_Amcare_Projects_VR.Question8Desc, dbo.I10_Amcare_Projects_VR.Question9, dbo.I10_Amcare_Projects_VR.Question9Desc, dbo.I10_Amcare_Projects_VR.Question10, 
                         dbo.I10_Amcare_Projects_VR.Question10Desc, dbo.I10_Amcare_Projects_VR.Question11, dbo.I10_Amcare_Projects_VR.Question11Desc, dbo.I10_Amcare_Projects_VR.Question12, 
                         dbo.I10_Amcare_Projects_VR.Question12Desc, dbo.I10_Amcare_Projects_VR.Question13, dbo.I10_Amcare_Projects_VR.Question13Desc, dbo.I10_Amcare_Projects_VR.Question14, 
                         dbo.I10_Amcare_Projects_VR.Question15, dbo.I10_Amcare_Projects_VR.Question16, dbo.I10_Amcare_Projects_VR.Question17
FROM            dbo.I10_Amcare_Projects_VR RIGHT OUTER JOIN
                         dbo.I10_Amcare_VR ON dbo.I10_Amcare_Projects_VR.zzAbstractLink = dbo.I10_Amcare_VR.zzAbstractLink



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[I10_Amcare_And_Provider_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[I10_Amcare_And_Provider_VR]
AS
SELECT        dbo.I10_Amcare_VR.[#ofPreviousPreTermDeliveries], dbo.I10_Amcare_VR.[#ofPrevSpontaneousAbortions], dbo.I10_Amcare_VR.[#ofPreviousTermDeliveries], dbo.I10_Amcare_VR.AccessPrimaryHealthCareCode, 
                         dbo.I10_Amcare_VR.AccessPrimaryHealthCareCodeDesc, dbo.I10_Amcare_VR.AmbulanceArrivalDate, dbo.I10_Amcare_VR.AmbulanceArrivalTime, dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknown, 
                         dbo.I10_Amcare_VR.AmbulanceArrivalTimeUnknownDesc, dbo.I10_Amcare_VR.AmbulanceTransferCareDate, dbo.I10_Amcare_VR.AmbulanceTransferCareTime, 
                         dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknown, dbo.I10_Amcare_VR.AmbulanceTransferCareTimeUnknownDesc, dbo.I10_Amcare_VR.[#ofPrevTherapeuticAbortions], dbo.I10_Amcare_VR.AWOL, 
                         dbo.I10_Amcare_VR.AWOLDesc, dbo.I10_Amcare_VR.AbortDate, dbo.I10_Amcare_VR.AbstractNumber, dbo.I10_Amcare_VR.AbstractOverflow, dbo.I10_Amcare_VR.AbstractOverflowDesc, 
                         dbo.I10_Amcare_VR.ActivityDescription, dbo.I10_Amcare_VR.ActivityWhenInjured, dbo.I10_Amcare_VR.ActivityWhenInjuredDesc, dbo.I10_Amcare_VR.ActueLOS, dbo.I10_Amcare_VR.AdmitbyAmbulance, 
                         dbo.I10_Amcare_VR.AdmitbyAmbulanceDesc, dbo.I10_Amcare_VR.AdmitCategory, dbo.I10_Amcare_VR.AdmitDiagnosis, dbo.I10_Amcare_VR.AdmitNursingArea, dbo.I10_Amcare_VR.AdmitNursingAreaDesc, 
                         dbo.I10_Amcare_VR.AfterAdmit, dbo.I10_Amcare_VR.AgeCode, dbo.I10_Amcare_VR.AgeCodeDesc, dbo.I10_Amcare_VR.AgeGroup, dbo.I10_Amcare_VR.AgeNumber, dbo.I10_Amcare_VR.Albumin, 
                         dbo.I10_Amcare_VR.AlbuminDesc, dbo.I10_Amcare_VR.AlbuminCrossMatched, dbo.I10_Amcare_VR.AlbuminCrossMatchedDesc, dbo.I10_Amcare_VR.AlbuminTyped, dbo.I10_Amcare_VR.AlbuminTypedDesc, 
                         dbo.I10_Amcare_VR.AlbuminUnits, dbo.I10_Amcare_VR.ALCLOS, dbo.I10_Amcare_VR.AmbulanceReportNumber, dbo.I10_Amcare_VR.AmCareGroup, dbo.I10_Amcare_VR.AmCareGroupDesc, 
                         dbo.I10_Amcare_VR.AmcareCareType, dbo.I10_Amcare_VR.AmcareCareTypeDesc, dbo.I10_Amcare_VR.AmcareTypeCode, dbo.I10_Amcare_VR.AmcareTypeCodeDesc, dbo.I10_Amcare_VR.Ancil13, 
                         dbo.I10_Amcare_VR.Ancil14, dbo.I10_Amcare_VR.Ancil15, dbo.I10_Amcare_VR.Ancil16, dbo.I10_Amcare_VR.Ancil17, dbo.I10_Amcare_VR.AncillaryField1, dbo.I10_Amcare_VR.AncillaryField1Desc, 
                         dbo.I10_Amcare_VR.AncillaryField10, dbo.I10_Amcare_VR.AncillaryField10Desc, dbo.I10_Amcare_VR.AncillaryField11, dbo.I10_Amcare_VR.AncillaryField11Desc, dbo.I10_Amcare_VR.AncillaryField12, 
                         dbo.I10_Amcare_VR.AncillaryField12Desc, dbo.I10_Amcare_VR.AncillaryField2, dbo.I10_Amcare_VR.AncillaryField2Desc, dbo.I10_Amcare_VR.AncillaryField3, dbo.I10_Amcare_VR.AncillaryField3Desc, 
                         dbo.I10_Amcare_VR.AncillaryField4, dbo.I10_Amcare_VR.AncillaryField4Desc, dbo.I10_Amcare_VR.AncillaryField5, dbo.I10_Amcare_VR.AncillaryField5Desc, dbo.I10_Amcare_VR.AncillaryField6, 
                         dbo.I10_Amcare_VR.AncillaryField6Desc, dbo.I10_Amcare_VR.AncillaryField7, dbo.I10_Amcare_VR.AncillaryField7Desc, dbo.I10_Amcare_VR.AncillaryField8, dbo.I10_Amcare_VR.AncillaryField8Desc, 
                         dbo.I10_Amcare_VR.AncillaryField9, dbo.I10_Amcare_VR.AncillaryField9Desc, dbo.I10_Amcare_VR.ArrivalDate, dbo.I10_Amcare_VR.ArrivalMode, dbo.I10_Amcare_VR.ArrivalModeDesc, 
                         dbo.I10_Amcare_VR.ArrivalTime, dbo.I10_Amcare_VR.ArrivaltoTriageTime, dbo.I10_Amcare_VR.AssessmentDate, dbo.I10_Amcare_VR.AssessmentTime, dbo.I10_Amcare_VR.AssessmentTimeUnknown, 
                         dbo.I10_Amcare_VR.AssessmentTimeUnknownDesc, dbo.I10_Amcare_VR.AttendingPhysician, dbo.I10_Amcare_VR.AttendingPhysicianDesc, dbo.I10_Amcare_VR.AutoTransfusion, 
                         dbo.I10_Amcare_VR.AutoTransfusionDesc, dbo.I10_Amcare_VR.AutopsyPerformed, dbo.I10_Amcare_VR.AutopsyPerformedDesc, dbo.I10_Amcare_VR.BasicOption1, dbo.I10_Amcare_VR.BasicOption1Desc, 
                         dbo.I10_Amcare_VR.BasicOption10, dbo.I10_Amcare_VR.BasicOption10Desc, dbo.I10_Amcare_VR.BasicOption11, dbo.I10_Amcare_VR.BasicOption11Desc, dbo.I10_Amcare_VR.BasicOption12, 
                         dbo.I10_Amcare_VR.BasicOption12Desc, dbo.I10_Amcare_VR.BasicOption13, dbo.I10_Amcare_VR.BasicOption13Desc, dbo.I10_Amcare_VR.BasicOption14, dbo.I10_Amcare_VR.BasicOption14Desc, 
                         dbo.I10_Amcare_VR.BasicOption15, dbo.I10_Amcare_VR.BasicOption15Desc, dbo.I10_Amcare_VR.BasicOption16, dbo.I10_Amcare_VR.BasicOption16Desc, dbo.I10_Amcare_VR.BasicOption17, 
                         dbo.I10_Amcare_VR.BasicOption17Desc, dbo.I10_Amcare_VR.BasicOption18, dbo.I10_Amcare_VR.BasicOption18Desc, dbo.I10_Amcare_VR.BasicOption19, dbo.I10_Amcare_VR.BasicOption19Desc, 
                         dbo.I10_Amcare_VR.BasicOption2, dbo.I10_Amcare_VR.BasicOption2Desc, dbo.I10_Amcare_VR.BasicOption3, dbo.I10_Amcare_VR.BasicOption3Desc, dbo.I10_Amcare_VR.BasicOption4, 
                         dbo.I10_Amcare_VR.BasicOption4Desc, dbo.I10_Amcare_VR.BasicOption5, dbo.I10_Amcare_VR.BasicOption5Desc, dbo.I10_Amcare_VR.BasicOption6, dbo.I10_Amcare_VR.BasicOption6Desc, 
                         dbo.I10_Amcare_VR.BasicOption7, dbo.I10_Amcare_VR.BasicOption7Desc, dbo.I10_Amcare_VR.BasicOption8, dbo.I10_Amcare_VR.BasicOption8Desc, dbo.I10_Amcare_VR.BasicOption9, 
                         dbo.I10_Amcare_VR.BasicOption9Desc, dbo.I10_Amcare_VR.BatchNumber, dbo.I10_Amcare_VR.BatchPeriod, dbo.I10_Amcare_VR.BatchPeriodDesc, dbo.I10_Amcare_VR.BatchPeriod_BC, 
                         dbo.I10_Amcare_VR.BatchYear, dbo.I10_Amcare_VR.BirthDate, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIII, 
						 dbo.I10_Amcare_VR.Blood_AntithrombinIIIDesc, 
						 dbo.I10_Amcare_VR.Blood_C1Inhibitor, 
                         dbo.I10_Amcare_VR.Blood_C1InhibitorDesc, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasma, 
						 dbo.I10_Amcare_VR.Blood_CryoprecipitatePlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_CryosupernatantPlasma, 
                         dbo.I10_Amcare_VR.Blood_CryosupernatantPlasmaDesc, 
						 dbo.I10_Amcare_VR.Blood_FEIBA, 
						 dbo.I10_Amcare_VR.Blood_FEIBADesc, 
						 dbo.I10_Amcare_VR.Blood_Fibrinogen, 
						 dbo.I10_Amcare_VR.Blood_FibrinogenDesc, 
                         dbo.I10_Amcare_VR.Blood_IVIG_SCIG, 
						 dbo.I10_Amcare_VR.Blood_IVIG_SCIGDesc, 
						 dbo.I10_Amcare_VR.Blood_PCC, 
						 dbo.I10_Amcare_VR.Blood_PCCDesc, 
						 dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactors, 
                         dbo.I10_Amcare_VR.Blood_ProteinC_OtherFactorsDesc, 
						 
						 dbo.I10_Amcare_VR.BreastFeeding, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlag, dbo.I10_Amcare_VR.ClinicalDecisionUnitFlagDesc, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitDateIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeIn, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknown, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeInUnknownDesc, dbo.I10_Amcare_VR.ClinicalDecisionUnitDateOut, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOut, 
                         dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknown, dbo.I10_Amcare_VR.ClinicalDecisionUnitTimeOutUnknownDesc, dbo.I10_Amcare_VR.ChangeinLegalStatus, 
                         dbo.I10_Amcare_VR.ChangeinLegalStatusDesc, dbo.I10_Amcare_VR.ChartNumber, dbo.I10_Amcare_VR.ChiefComplaint, dbo.I10_Amcare_VR.CoderNumber, dbo.I10_Amcare_VR.CoderNumberDesc, 
                         dbo.I10_Amcare_VR.CompleteRecord, dbo.I10_Amcare_VR.CompleteRecordDesc, dbo.I10_Amcare_VR.Complication, dbo.I10_Amcare_VR.ComplicationDesc, dbo.I10_Amcare_VR.Complication1, 
                         dbo.I10_Amcare_VR.Complication1Desc, dbo.I10_Amcare_VR.Complication2, dbo.I10_Amcare_VR.Complication2Desc, dbo.I10_Amcare_VR.Complication3, dbo.I10_Amcare_VR.Complication3Desc, 
                         dbo.I10_Amcare_VR.ContactMode, dbo.I10_Amcare_VR.ContactModeDesc, dbo.I10_Amcare_VR.CoronerCase, dbo.I10_Amcare_VR.CoronerCaseDesc, dbo.I10_Amcare_VR.DataEntryCoder, 
                         dbo.I10_Amcare_VR.DataEntryCoderDesc, dbo.I10_Amcare_VR.DateLeftER, dbo.I10_Amcare_VR.DateofLastMenses, dbo.I10_Amcare_VR.DateReadyforDisch, dbo.I10_Amcare_VR.DateSentToCIHI, 
                         dbo.I10_Amcare_VR.DateSentToCIHILevel1, dbo.I10_Amcare_VR.DateSentToCIHILevel2, dbo.I10_Amcare_VR.DateSentToCIHILite, dbo.I10_Amcare_VR.DeathInER, dbo.I10_Amcare_VR.DeathInERDesc, 
                         dbo.I10_Amcare_VR.DeathOnArrival, dbo.I10_Amcare_VR.DeathOnArrivalDesc, dbo.I10_Amcare_VR.DecisionAdmitDifference, dbo.I10_Amcare_VR.DecisiontoAdmitDate, dbo.I10_Amcare_VR.DecisiontoAdmitTime, 
                         dbo.I10_Amcare_VR.DecisionAdmitTimeUnknown, dbo.I10_Amcare_VR.DecisionAdmitTimeUnknownDesc, dbo.I10_Amcare_VR.DeliveryDate, dbo.I10_Amcare_VR.DeliveryTime, 
                         dbo.I10_Amcare_VR.DiedDuringIntervention, dbo.I10_Amcare_VR.DiedDuringInterventionDesc, dbo.I10_Amcare_VR.DischNursingArea, dbo.I10_Amcare_VR.DischNursingAreaDesc, 
                         dbo.I10_Amcare_VR.DischPlanning, dbo.I10_Amcare_VR.DischPlanningDesc, dbo.I10_Amcare_VR.DischargeAge, dbo.I10_Amcare_VR.DischargeDisposition, dbo.I10_Amcare_VR.DischargeDispositionDesc, 
                         dbo.I10_Amcare_VR.DispositionDate, dbo.I10_Amcare_VR.DispositionTime, dbo.I10_Amcare_VR.DispositionTimeUnknown, dbo.I10_Amcare_VR.DispositionTimeUnknownDesc, dbo.I10_Amcare_VR.ECTTreatment, 
                         dbo.I10_Amcare_VR.ECTTreatmentDesc, dbo.I10_Amcare_VR.Education, dbo.I10_Amcare_VR.EducationDesc, dbo.I10_Amcare_VR.EDVisitIndicator, dbo.I10_Amcare_VR.EDVisitIndicatorDesc, 
                         dbo.I10_Amcare_VR.Employment, dbo.I10_Amcare_VR.EmploymentDesc, dbo.I10_Amcare_VR.EntryCode, dbo.I10_Amcare_VR.EstimateDischDate, dbo.I10_Amcare_VR.ExitCode, 
                         dbo.I10_Amcare_VR.FamilyPhysicianFlag, dbo.I10_Amcare_VR.FamilyPhysicianFlagDesc, dbo.I10_Amcare_VR.FinancialSupport, dbo.I10_Amcare_VR.FinancialSupportDesc, dbo.I10_Amcare_VR.FinishDate, 
                         dbo.I10_Amcare_VR.FinishTime, dbo.I10_Amcare_VR.FirstName, dbo.I10_Amcare_VR.FullName, dbo.I10_Amcare_VR.FixedChartNumber, dbo.I10_Amcare_VR.Gender, dbo.I10_Amcare_VR.GenderDesc, 
                         dbo.I10_Amcare_VR.GestationalAgeinweeks, dbo.I10_Amcare_VR.GlasgowScale, dbo.I10_Amcare_VR.GlasgowScaleDesc, dbo.I10_Amcare_VR.GreaterTenPO, dbo.I10_Amcare_VR.HCNProvince, 
                         dbo.I10_Amcare_VR.HCNProvinceDesc, dbo.I10_Amcare_VR.HCNVersion, dbo.I10_Amcare_VR.HealthCareNumber, dbo.I10_Amcare_VR.Hospital, dbo.I10_Amcare_VR.HospitalDesc, 
                         dbo.I10_Amcare_VR.HospitalAccountRecord,
                         dbo.I10_Amcare_VR.HelmetIndicator, dbo.I10_Amcare_VR.HelmetIndicatorDesc, dbo.I10_Amcare_VR.InSCU, dbo.I10_Amcare_VR.InitialOR, dbo.I10_Amcare_VR.InitialORDesc, dbo.I10_Amcare_VR.InjuryDate, 
                         dbo.I10_Amcare_VR.Injury, dbo.I10_Amcare_VR.InjuryDesc, dbo.I10_Amcare_VR.InputDate, dbo.I10_Amcare_VR.InputTime, 

						 dbo.I10_Amcare_VR.InstitutionFrom, dbo.I10_Amcare_VR.InstitutionFromDesc, 
						 dbo.I10_Amcare_VR.InstitutionFromType, dbo.I10_Amcare_VR.InstitutionFromTypeDesc,
                         dbo.I10_Amcare_VR.InstFromCareType, dbo.I10_Amcare_VR.InstFromHospType, 
						 dbo.I10_Amcare_VR.InstitutionNumber, dbo.I10_Amcare_VR.InstitutionNumberDesc, 
						 dbo.I10_Amcare_VR.InstitutionTo, dbo.I10_Amcare_VR.InstitutionToDesc, 
						 dbo.I10_Amcare_VR.InstToCareType, dbo.I10_Amcare_VR.InstToHospType, 
						 dbo.I10_Amcare_VR.InstitutionToType, dbo.I10_Amcare_VR.InstitutionToTypeDesc, 
						 
						 dbo.I10_Amcare_VR.InterfaceDate, dbo.I10_Amcare_VR.InterfaceTime, 
                         dbo.I10_Amcare_VR.IsAbstractCompleted, dbo.I10_Amcare_VR.IsAbstractCompletedDesc, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1, dbo.I10_Amcare_VR.IsAbstractCompletedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCompletedLevel2, dbo.I10_Amcare_VR.IsAbstractCompletedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCompletedLite, dbo.I10_Amcare_VR.IsAbstractCompletedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrected, dbo.I10_Amcare_VR.IsAbstractCorrectedDesc, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel1Desc, 
                         dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2, dbo.I10_Amcare_VR.IsAbstractCorrectedLevel2Desc, dbo.I10_Amcare_VR.IsAbstractCorrectedLite, dbo.I10_Amcare_VR.IsAbstractCorrectedLiteDesc, 
                         dbo.I10_Amcare_VR.IsAbstractDeleted, dbo.I10_Amcare_VR.IsAbstractDeletedDesc, dbo.I10_Amcare_VR.IsAbstractSubmitted, dbo.I10_Amcare_VR.IsAbstractSubmittedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2, dbo.I10_Amcare_VR.IsAbstractSubmittedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractSubmittedLite, dbo.I10_Amcare_VR.IsAbstractSubmittedLiteDesc, dbo.I10_Amcare_VR.IsAbstractValidated, dbo.I10_Amcare_VR.IsAbstractValidatedDesc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLevel1, dbo.I10_Amcare_VR.IsAbstractValidatedLevel1Desc, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2, dbo.I10_Amcare_VR.IsAbstractValidatedLevel2Desc, 
                         dbo.I10_Amcare_VR.IsAbstractValidatedLite, dbo.I10_Amcare_VR.IsAbstractValidatedLiteDesc, dbo.I10_Amcare_VR.IsBirthdateEstimated, dbo.I10_Amcare_VR.IsBirthdateEstimatedDesc, 
						 dbo.I10_Amcare_VR.IsCustomValidated, dbo.I10_Amcare_VR.IsCustomValidatedDesc,
                         dbo.I10_Amcare_VR.LOSDays, dbo.I10_Amcare_VR.LOSTime, dbo.I10_Amcare_VR.LOSTimeinHours, dbo.I10_Amcare_VR.LOSTotalMinutes, dbo.I10_Amcare_VR.Language, dbo.I10_Amcare_VR.LanguageDesc, 
                         dbo.I10_Amcare_VR.LastName, dbo.I10_Amcare_VR.LessTwoPO, dbo.I10_Amcare_VR.LivingArrangement, dbo.I10_Amcare_VR.LivingArrangementDesc, dbo.I10_Amcare_VR.LocationofInjury, 
                         dbo.I10_Amcare_VR.LocationofInjuryDesc, dbo.I10_Amcare_VR.MISCode, dbo.I10_Amcare_VR.MISCodeDesc, dbo.I10_Amcare_VR.MaidenName, dbo.I10_Amcare_VR.MaritalStatus, 
                         dbo.I10_Amcare_VR.MaritalStatusDesc, 
                         dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoED, 
						 dbo.I10_Amcare_VR.MentalHealth_LegalStatusUponArrivaltoEDDesc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01, 
                         dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_01Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04, dbo.I10_Amcare_VR.MentalHealth_TypeOfRestraint_04Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_01Desc, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_02Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03, 
                         dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_03Desc, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04, 
						 dbo.I10_Amcare_VR.MentalHealth_FrequencyOfRestraint_04Desc, 
						 
						 dbo.I10_Amcare_VR.MethodofAdmission, dbo.I10_Amcare_VR.MethodofAdmissionDesc, dbo.I10_Amcare_VR.MiddleName, 
                         dbo.I10_Amcare_VR.NACRSClinicLiteSubmission, dbo.I10_Amcare_VR.NACRSClinicLiteSubmissionDesc, 
                         dbo.I10_Amcare_VR.NewbornChart, 
                         dbo.I10_Amcare_VR.NewbornDischDate, dbo.I10_Amcare_VR.NextScheduledVisitDate, dbo.I10_Amcare_VR.NextScheduledVisitTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentDate, 
                         dbo.I10_Amcare_VR.NonPhysicianAssessmentTime, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknown, dbo.I10_Amcare_VR.NonPhysicianAssessmentTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.NonPhysicianNumber, dbo.I10_Amcare_VR.NonPhysicianNumberDesc, dbo.I10_Amcare_VR.NonPhysicianService, dbo.I10_Amcare_VR.NonPhysicianServiceDesc, 
                         dbo.I10_Amcare_VR.NumberofECT, dbo.I10_Amcare_VR.NursingAssessmentDate, dbo.I10_Amcare_VR.NursingAssessmentTime, dbo.I10_Amcare_VR.Occupation, dbo.I10_Amcare_VR.OccupationDesc, 
                         dbo.I10_Amcare_VR.OtherMedicalDeath, dbo.I10_Amcare_VR.OtherMedicalDeathDesc, dbo.I10_Amcare_VR.OtherBlood, dbo.I10_Amcare_VR.OtherBloodDesc, dbo.I10_Amcare_VR.OtherBloodCrossMatched, 
                         dbo.I10_Amcare_VR.OtherBloodCrossMatchedDesc, dbo.I10_Amcare_VR.OtherBloodTyped, dbo.I10_Amcare_VR.OtherBloodTypedDesc, dbo.I10_Amcare_VR.OtherBloodUnits, dbo.I10_Amcare_VR.PCTASIndicator, 
                         dbo.I10_Amcare_VR.PCTASIndicatorDesc, dbo.I10_Amcare_VR.PhysicianEstLOS, dbo.I10_Amcare_VR.Plasma, dbo.I10_Amcare_VR.PlasmaDesc, dbo.I10_Amcare_VR.PlasmaCrossMatched, 
                         dbo.I10_Amcare_VR.PlasmaCrossMatchedDesc, dbo.I10_Amcare_VR.PlasmaTyped, dbo.I10_Amcare_VR.PlasmaTypedDesc, dbo.I10_Amcare_VR.PlasmaUnits, dbo.I10_Amcare_VR.Platelets, 
                         dbo.I10_Amcare_VR.PlateletsDesc, dbo.I10_Amcare_VR.PlateletsCrossMatched, dbo.I10_Amcare_VR.PlateletsCrossMatchedDesc, dbo.I10_Amcare_VR.PlateletsTyped, dbo.I10_Amcare_VR.PlateletsTypedDesc, 
                         dbo.I10_Amcare_VR.PlateletsUnits, dbo.I10_Amcare_VR.PostalCode, dbo.I10_Amcare_VR.PostalCodeDesc, dbo.I10_Amcare_VR.PostOpDays, dbo.I10_Amcare_VR.PreOpDays, 
                         dbo.I10_Amcare_VR.PreamditWorkUp, dbo.I10_Amcare_VR.PreamditWorkUpDesc, dbo.I10_Amcare_VR.Pregnancy, dbo.I10_Amcare_VR.PregnancyDesc, dbo.I10_Amcare_VR.PrevLiveBirth, 
                         dbo.I10_Amcare_VR.PreviousPsychiartricAdmissions, dbo.I10_Amcare_VR.PreviousPsychiartricAdmDesc, dbo.I10_Amcare_VR.Program, dbo.I10_Amcare_VR.ProgramDesc, dbo.I10_Amcare_VR.ProvinceNumber, 
                         dbo.I10_Amcare_VR.ProvinceNumberDesc, dbo.I10_Amcare_VR.ReasonForVisit, dbo.I10_Amcare_VR.ReasonForVisitDesc, dbo.I10_Amcare_VR.ReAdmitCode, dbo.I10_Amcare_VR.ReciprocalBillingStatus, 
                         dbo.I10_Amcare_VR.ReciprocalBillingStatusDesc, dbo.I10_Amcare_VR.RedBloodCell, dbo.I10_Amcare_VR.RedBloodCellDesc, dbo.I10_Amcare_VR.RedBloodCellCrossMatched, 
                         dbo.I10_Amcare_VR.RedBloodCellCrossMatchedDesc, dbo.I10_Amcare_VR.RedBloodCellTyped, dbo.I10_Amcare_VR.RedBloodCellTypedDesc, dbo.I10_Amcare_VR.RedBloodCellUnits, 
                         dbo.I10_Amcare_VR.ReferralDate, dbo.I10_Amcare_VR.ReferredFrom, dbo.I10_Amcare_VR.ReferredFromDesc, dbo.I10_Amcare_VR.ReferredTo, dbo.I10_Amcare_VR.ReferredToDesc, 
                         dbo.I10_Amcare_VR.ReferringProvider, dbo.I10_Amcare_VR.ReferringProviderDesc, dbo.I10_Amcare_VR.RegisterNumber, dbo.I10_Amcare_VR.RegistrationNumber, 
                         dbo.I10_Amcare_VR.RegistrationSequenceNumber, dbo.I10_Amcare_VR.RegistrationVisitDate, dbo.I10_Amcare_VR.RegistrationVisitTime, dbo.I10_Amcare_VR.ReproductiveCareComments, 
                         dbo.I10_Amcare_VR.ReserveField, dbo.I10_Amcare_VR.ResidenceCode, dbo.I10_Amcare_VR.ResidenceCodeDesc, dbo.I10_Amcare_VR.ResidenceProvince, dbo.I10_Amcare_VR.ResidenceProvinceDesc, 
                         dbo.I10_Amcare_VR.ResidenceRegion, dbo.I10_Amcare_VR.ResidenceRegionDesc, dbo.I10_Amcare_VR.ResidenceType, dbo.I10_Amcare_VR.ResidenceTypeDesc, dbo.I10_Amcare_VR.ResponsiblityForPayment,
                          dbo.I10_Amcare_VR.ResponsiblityForPaymentDesc, dbo.I10_Amcare_VR.SchedEDVisit, dbo.I10_Amcare_VR.SchedEDVisitDesc, dbo.I10_Amcare_VR.SeatbeltIndicator, dbo.I10_Amcare_VR.SeatbeltIndicatorDesc, 
                         dbo.I10_Amcare_VR.SecondChartRegisterNumber, dbo.I10_Amcare_VR.SecretVIPPatient, dbo.I10_Amcare_VR.SecretVIPPatientDesc, dbo.I10_Amcare_VR.SiteNumber, dbo.I10_Amcare_VR.SiteNumberDesc, 
                         dbo.I10_Amcare_VR.SocialService, dbo.I10_Amcare_VR.SocialServiceDesc, dbo.I10_Amcare_VR.SourceofReferral, dbo.I10_Amcare_VR.SourceofReferralDesc, dbo.I10_Amcare_VR.SpecialistNumber, 
                         dbo.I10_Amcare_VR.SpecialistNumberDesc, dbo.I10_Amcare_VR.SpecialistRequestDate, dbo.I10_Amcare_VR.SpecialistRequestService, dbo.I10_Amcare_VR.SpecialistRequestServiceDesc, 
                         dbo.I10_Amcare_VR.SpecialistRequestTime, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknown, dbo.I10_Amcare_VR.SpecialistRequestTimeUnknownDesc, dbo.I10_Amcare_VR.StakeholderType, 
                         dbo.I10_Amcare_VR.StakeholderTypeDesc, dbo.I10_Amcare_VR.StatusAfterTriage, dbo.I10_Amcare_VR.StatusAfterTriageDesc, dbo.I10_Amcare_VR.Sterilization, dbo.I10_Amcare_VR.SterilizationDesc, 
                         dbo.I10_Amcare_VR.SubmissionLevelCode, dbo.I10_Amcare_VR.SubmissionRecordID, dbo.I10_Amcare_VR.SubsequentOR, dbo.I10_Amcare_VR.SubsequentORDesc, dbo.I10_Amcare_VR.Suicide, 
                         dbo.I10_Amcare_VR.SuicideDesc, dbo.I10_Amcare_VR.SurgicalCase, dbo.I10_Amcare_VR.SurgicalCaseDesc, dbo.I10_Amcare_VR.TimeLeftER, dbo.I10_Amcare_VR.TimeLeftERUnknown, 
                         dbo.I10_Amcare_VR.TimeLeftERUnknownDEsc, dbo.I10_Amcare_VR.TransferOverloadDate, dbo.I10_Amcare_VR.TransferOverloadTime, dbo.I10_Amcare_VR.TransferOverloadTimeDifference, 
                         dbo.I10_Amcare_VR.TransfusionGiven, dbo.I10_Amcare_VR.TransfusionGivenDesc, dbo.I10_Amcare_VR.Trauma, dbo.I10_Amcare_VR.TraumaDesc, dbo.I10_Amcare_VR.TriageDate, 
                         dbo.I10_Amcare_VR.TriageLevel, dbo.I10_Amcare_VR.TriageLevelDesc, dbo.I10_Amcare_VR.TriageTime, dbo.I10_Amcare_VR.TriageTimeUnknown, dbo.I10_Amcare_VR.TriageTimeUnknownDesc, 
                         dbo.I10_Amcare_VR.TSICoder, dbo.I10_Amcare_VR.TSICoderDesc, dbo.I10_Amcare_VR.TSIDate, dbo.I10_Amcare_VR.TSITime, dbo.I10_Amcare_VR.TwoTenPO, dbo.I10_Amcare_VR.ULI, 
                         dbo.I10_Amcare_VR.UniversalEpisodeIdentifier, dbo.I10_Amcare_VR.UnplannedReadmit, dbo.I10_Amcare_VR.VisitStatus, dbo.I10_Amcare_VR.VisitStatusDesc, dbo.I10_Amcare_VR.VisitType, dbo.I10_Amcare_VR.VisitTypeDesc, 
                         dbo.I10_Amcare_VR.WaitTimeinER, dbo.I10_Amcare_VR.WaittoAssessmentinMinutes, dbo.I10_Amcare_VR.WaittoNursingAssessmentDiff, dbo.I10_Amcare_VR.Weight, dbo.I10_Amcare_VR.zzAbstractLink, 
                         dbo.I10_Amcare_VR.zzRegionalPatientID, dbo.I10_Amcare_VR.zzVolumeLink, 

					dbo.I10_Amcare_Providers_VR.ProviderArrivedDate, dbo.I10_Amcare_Providers_VR.ProviderArrivedTime, 
                         dbo.I10_Amcare_Providers_VR.ProviderCalledDate, dbo.I10_Amcare_Providers_VR.ProviderCalledTime, dbo.I10_Amcare_Providers_VR.ProviderNumber, dbo.I10_Amcare_Providers_VR.ProviderNumberDesc, 
                         dbo.I10_Amcare_Providers_VR.ProviderOccurrence, dbo.I10_Amcare_Providers_VR.ProviderService, dbo.I10_Amcare_Providers_VR.ProviderSpecialty, dbo.I10_Amcare_Providers_VR.ProviderSpecialtyDesc, 
                         dbo.I10_Amcare_Providers_VR.ProviderTotalTime, dbo.I10_Amcare_Providers_VR.ProviderType, dbo.I10_Amcare_Providers_VR.ProviderTypeDesc
FROM            dbo.I10_Amcare_Providers_VR RIGHT OUTER JOIN
                         dbo.I10_Amcare_VR ON dbo.I10_Amcare_Providers_VR.zzAbstractLink = dbo.I10_Amcare_VR.zzAbstractLink



' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_2010_QI_ByQuarter_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

--ED - 02172 
CREATE view [dbo].[MDS20_2010_QI_ByQuarter_VR]
as
select 
	InstitutionNumber, InstitutionNumberDesc, FiscalYear, FiscalQuarter, 
	--ADL01 – Percent of residents who had an une*pected loss of function in some basic daily activities
	ADL01   = cast(SUM (QI_ADL01_N) as float(53)) / nullif(SUM (QI_ADL01_D), 0) * 100.00,
    ADL01_D = SUM (QI_ADL01_D),
	ADL01_N = SUM (QI_ADL01_N),
	--ADL05 – Percent of residents who improve status on mid-loss ADL functioning (transfer, locomotion) or remain completely independent in mid-loss ADLs
	ADL05   = cast(SUM (QI_ADL05_N) as float(53)) / nullif(SUM (QI_ADL05_D), 0) * 100.00,
	ADL05_D = SUM (QI_ADL05_D),
	ADL05_N = SUM (QI_ADL05_N),
	--ADL06 – Percent of residents who improve status on early-loss ADL functioning (dressing and personal hygiene) or remain completely independent in early-loss ADLs
	ADL06   = cast(SUM (QI_ADL06_N) as float(53)) / nullif(SUM (QI_ADL06_D), 0) * 100.00,
	ADL06_D = SUM (QI_ADL06_D),
	ADL06_N = SUM (QI_ADL06_N),
	--ADL1A – Percent of residents who had an improvement of function in some basic daily activities
	ADL1A   = cast(SUM (QI_ADL1A_N) as float(53)) / nullif(SUM (QI_ADL1A_D), 0) * 100.00,
	ADL1A_D = SUM (QI_ADL1A_D),
	ADL1A_N = SUM (QI_ADL1A_N),
    --ADL5A – Percent of residents who declined status on mid-loss ADL functioning (transfer, locomotion) or remain completely dependent in mid-loss ADLs
    ADL5A   = cast(SUM (QI_ADL5A_N) as float(53)) / nullif(SUM (QI_ADL5A_D), 0) * 100.00,
    ADL5A_D = SUM (QI_ADL5A_D),
    ADL5A_N = SUM (QI_ADL5A_N),
    --ADL6A – Percent of residents who declined status on early-loss ADL functioning (dressing and personal hygiene) or remain completely dependent in early-loss ADLs)
    ADL6A   = cast(SUM (QI_ADL6A_N) as float(53)) / nullif(SUM (QI_ADL6A_D), 0) * 100.00,
    ADL6A_D = SUM (QI_ADL6A_D),
    ADL6A_N = SUM (QI_ADL6A_N),
    --ADLD7 – Percent of residents who have declined in ADLs   
    ADLD7   = cast(SUM (QI_ADLD7_N) as float(53)) / nullif(SUM (QI_ADLD7_D), 0) * 100.00,
    ADLD7_D = SUM (QI_ADLD7_D),
    ADLD7_N = SUM (QI_ADLD7_N),
    --BEHD4 – Percent of residents who have declining behavioral symptoms
    BEHD4   = cast(SUM (QI_BEHD4_N) as float(53)) / nullif(SUM (QI_BEHD4_D), 0) * 100.00,
    BEHD4_D = SUM (QI_BEHD4_D),
    BEHD4_N = SUM (QI_BEHD4_N),	
    --BEHI4 – Percent of residents who have improved behavioural symptoms
    BEHI4   = cast(SUM (QI_BEHI4_N) as float(53)) / nullif(SUM (QI_BEHI4_D), 0) * 100.00,
    BEHI4_D = SUM (QI_BEHI4_D),
    BEHI4_N = SUM (QI_BEHI4_N),
    --CAT02 – Percent of residents with indwelling catheters
    CAT02   = cast(SUM (QI_CAT02_N) as float(53)) / nullif(SUM (QI_CAT02_D), 0) * 100.00,
    CAT02_D = SUM (QI_CAT02_D),
    CAT02_N = SUM (QI_CAT02_N),
    --CNT02 – Percent of residents with worsening bowel continence
    CNT02   = cast(SUM (QI_CNT02_N) as float(53)) / nullif(SUM (QI_CNT02_D), 0) * 100.00,
    CNT02_D = SUM (QI_CNT02_D),
    CNT02_N = SUM (QI_CNT02_N),
    --CNT03 – Percent of residents with worsening bladder continence
    CNT03   = cast(SUM (QI_CNT03_N) as float(53)) / nullif(SUM (QI_CNT03_D), 0) * 100.00,    
    CNT03_D = SUM (QI_CNT03_D),
    CNT03_N = SUM (QI_CNT03_N), 
    --CNT04 – Percent of residents with urinary tract infections
    CNT04   = cast(SUM (QI_CNT04_N) as float(53)) / nullif(SUM (QI_CNT04_D), 0) * 100.00,
    CNT04_D = SUM (QI_CNT04_D),
    CNT04_N = SUM (QI_CNT04_N),
    --CNT2A – Percent of residents with improving bowel continence
    CNT2A   = cast(SUM (QI_CNT2A_N) as float(53)) / nullif(SUM (QI_CNT2A_D), 0) * 100.00,
    CNT2A_D = SUM (QI_CNT2A_D),
    CNT2A_N = SUM (QI_CNT2A_N),
    --CNT3A – Percent of residents with improving bladder continence
    CNT3A   = cast(SUM (QI_CNT3A_N) as float(53)) / nullif(SUM (QI_CNT3A_D), 0) * 100.00,
    CNT3A_D = SUM (QI_CNT3A_D),
    CNT3A_N = SUM (QI_CNT3A_N),
    --COG01 – Percent of residents whose cognitive ability has worsened
    COG01   = cast(SUM (QI_COG01_N) as float(53)) / nullif(SUM (QI_COG01_D), 0) * 100.00,
    COG01_D = SUM (QI_COG01_D),
    COG01_N = SUM (QI_COG01_N),
    --COG1A – Percent of residents whose cognitive ability has improved
    COG1A   = cast(SUM (QI_COG1A_N) as float(53)) / nullif(SUM (QI_COG1A_D), 0) * 100.00,
    COG1A_D = SUM (QI_COG1A_D),
    COG1A_N = SUM (QI_COG1A_N),
    --COM01 – Percent of residents whose ability to communicate has worsened
    COM01   = cast(SUM (QI_COM01_N) as float(53)) / nullif(SUM (QI_COM01_D), 0) * 100.00,
    COM01_D = SUM (QI_COM01_D),
    COM01_N = SUM (QI_COM01_N),
    --COM1A – Percent of residents whose ability to communicate has improved
    COM1A   = cast(SUM (QI_COM1A_N) as float(53)) / nullif(SUM (QI_COM1A_D), 0) * 100.00,
    COM1A_D = SUM (QI_COM1A_D),
    COM1A_N = SUM (QI_COM1A_N),
    --DEL0X – Percent of residents with symptoms of delirium
    DEL0X   = cast(SUM (QI_DEL0X_N) as float(53)) / nullif(SUM (QI_DEL0X_D), 0) * 100.00,
    DEL0X_D = SUM (QI_DEL0X_D),
    DEL0X_N = SUM (QI_DEL0X_N),
    --DRG01 – Percent of residents on antipsychotics without a diagnosis of psychosis
    DRG01   = cast(SUM (QI_DRG01_N) as float(53)) / nullif(SUM (QI_DRG01_D), 0) * 100.00,
    DRG01_D = SUM (QI_DRG01_D),
    DRG01_N = SUM (QI_DRG01_N),
    --FAL02 – Percent of residents who have fallen in the last 30 days
    FAL02   = cast(SUM (QI_FAL02_N) as float(53)) / nullif(SUM (QI_FAL02_D), 0) * 100.00,
    FAL02_D = SUM (QI_FAL02_D),
    FAL02_N = SUM (QI_FAL02_N),
    --INF0X – Percent of residents with infections
    INF0X   = cast(SUM (QI_INF0X_N) as float(53)) / nullif(SUM (QI_INF0X_D), 0) * 100.00,
    INF0X_D = SUM (QI_INF0X_D),
    INF0X_N = SUM (QI_INF0X_N),
    --MOB01 – Percent of residents who have declined in their ability to locomote
    MOB01   = cast(SUM (QI_MOB01_N) as float(53)) / nullif(SUM (QI_MOB01_D), 0) * 100.00,
    MOB01_D = SUM (QI_MOB01_D),
    MOB01_N = SUM (QI_MOB01_N),
    --MOB1A – Percent of residents who have improved in their ability to locomote
    MOB1A   = cast(SUM (QI_MOB1A_N) as float(53)) / nullif(SUM (QI_MOB1A_D), 0) * 100.00,
    MOB1A_D = SUM (QI_MOB1A_D),
    MOB1A_N = SUM (QI_MOB1A_N),
    --MOD4A – Percent of residents who decline in mood from symptoms of depression
    MOD4A   = cast(SUM (QI_MOD4A_N) as float(53)) / nullif(SUM (QI_MOD4A_D), 0) * 100.00,
    MOD4A_D = SUM (QI_MOD4A_D),
    MOD4A_N = SUM (QI_MOD4A_N),
    --NUT01 – Percent of residents with a feeding tube
    NUT01   = cast(SUM (QI_NUT01_N) as float(53)) / nullif(SUM (QI_NUT01_D), 0) * 100.00,
    NUT01_D = SUM (QI_NUT01_D),
    NUT01_N = SUM (QI_NUT01_N),
    --PAI0X – Percent of residents with pain
    PAI0X   = cast(SUM (QI_PAI0X_N) as float(53)) / nullif(SUM (QI_PAI0X_D), 0) * 100.00,
    PAI0X_D = SUM (QI_PAI0X_D),
    PAI0X_N = SUM (QI_PAI0X_N),
    --PAN01 – Percent of residents with worsening pain
    PAN01   = cast(SUM (QI_PAN01_N) as float(53)) / nullif(SUM (QI_PAN01_D), 0) * 100.00,
    PAN01_D = SUM (QI_PAN01_D),
    PAN01_N = SUM (QI_PAN01_N),
    --PRU05 – Percent of residents who have a pressure ulcer stage 2 to 4
    PRU05   = cast(SUM (QI_PRU05_N) as float(53)) / nullif(SUM (QI_PRU05_D), 0) * 100.00,
    PRU05_D = SUM (QI_PRU05_D),
    PRU05_N = SUM (QI_PRU05_N),
    --PRU06 – Percent of residents with worsening stage 2-4 pressure sores
    PRU06   = cast(SUM (QI_PRU06_N) as float(53)) / nullif(SUM (QI_PRU06_D), 0) * 100.00,
    PRU06_D = SUM (QI_PRU06_D),
    PRU06_N = SUM (QI_PRU06_N),
    --PRU09 – Percent of residents with newly occurring pressure ulcer stage 2 to 4
    PRU09   = cast(SUM (QI_PRU09_N) as float(53)) / nullif(SUM (QI_PRU09_D), 0) * 100.00,
    PRU09_D = SUM (QI_PRU09_D),
    PRU09_N = SUM (QI_PRU09_N),
    --RES01 – Percent of residents with daily physical restraints
    RES01   = cast(SUM (QI_RES01_N) as float(53)) / nullif(SUM (QI_RES01_D), 0) * 100.00,
    RES01_D = SUM (QI_RES01_D),
    RES01_N = SUM (QI_RES01_N),
    --RSPX2 – Percent of residents who have developed a respiratory infection or have not gotten better
    RSPX2   = cast(SUM (QI_RSPX2_N) as float(53)) / nullif(SUM (QI_RSPX2_D), 0) * 100.00,
    RSPX2_D = SUM (QI_RSPX2_D),
    RSPX2_N = SUM (QI_RSPX2_N),
    --WGT01 – Percent of residents who
    WGT01   = cast(SUM (QI_WGT01_N) as float(53))/ nullif(SUM (QI_WGT01_D), 0) * 100.00,
    WGT01_D = SUM (QI_WGT01_D),
    WGT01_N = SUM (QI_WGT01_N)
from [dbo].[MDS20_2010_QI_VR]
group by InstitutionNumber, InstitutionNumberDesc, FiscalYear, FiscalQuarter
	


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_2010_QI_ByYear_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
--ED - 02172 
Create view [dbo].[MDS20_2010_QI_ByYear_VR]
as
select 
	InstitutionNumber, InstitutionNumberDesc, FiscalYear,  
	--ADL01 – Percent of residents who had an une*pected loss of function in some basic daily activities
	ADL01   = cast(SUM (QI_ADL01_N) as float(53)) / nullif(SUM (QI_ADL01_D), 0) * 100.00,
    ADL01_D = SUM (QI_ADL01_D),
	ADL01_N = SUM (QI_ADL01_N),
	--ADL05 – Percent of residents who improve status on mid-loss ADL functioning (transfer, locomotion) or remain completely independent in mid-loss ADLs
	ADL05   = cast(SUM (QI_ADL05_N) as float(53)) / nullif(SUM (QI_ADL05_D), 0) * 100.00,
	ADL05_D = SUM (QI_ADL05_D),
	ADL05_N = SUM (QI_ADL05_N),
	--ADL06 – Percent of residents who improve status on early-loss ADL functioning (dressing and personal hygiene) or remain completely independent in early-loss ADLs
	ADL06   = cast(SUM (QI_ADL06_N) as float(53)) / nullif(SUM (QI_ADL06_D), 0) * 100.00,
	ADL06_D = SUM (QI_ADL06_D),
	ADL06_N = SUM (QI_ADL06_N),
	--ADL1A – Percent of residents who had an improvement of function in some basic daily activities
	ADL1A   = cast(SUM (QI_ADL1A_N) as float(53)) / nullif(SUM (QI_ADL1A_D), 0) * 100.00,
	ADL1A_D = SUM (QI_ADL1A_D),
	ADL1A_N = SUM (QI_ADL1A_N),
    --ADL5A – Percent of residents who declined status on mid-loss ADL functioning (transfer, locomotion) or remain completely dependent in mid-loss ADLs
    ADL5A   = cast(SUM (QI_ADL5A_N) as float(53)) / nullif(SUM (QI_ADL5A_D), 0) * 100.00,
    ADL5A_D = SUM (QI_ADL5A_D),
    ADL5A_N = SUM (QI_ADL5A_N),
    --ADL6A – Percent of residents who declined status on early-loss ADL functioning (dressing and personal hygiene) or remain completely dependent in early-loss ADLs)
    ADL6A   = cast(SUM (QI_ADL6A_N) as float(53)) / nullif(SUM (QI_ADL6A_D), 0) * 100.00,
    ADL6A_D = SUM (QI_ADL6A_D),
    ADL6A_N = SUM (QI_ADL6A_N),
    --ADLD7 – Percent of residents who have declined in ADLs   
    ADLD7   = cast(SUM (QI_ADLD7_N) as float(53)) / nullif(SUM (QI_ADLD7_D), 0) * 100.00,
    ADLD7_D = SUM (QI_ADLD7_D),
    ADLD7_N = SUM (QI_ADLD7_N),
    --BEHD4 – Percent of residents who have declining behavioral symptoms
    BEHD4   = cast(SUM (QI_BEHD4_N) as float(53)) / nullif(SUM (QI_BEHD4_D), 0) * 100.00,
    BEHD4_D = SUM (QI_BEHD4_D),
    BEHD4_N = SUM (QI_BEHD4_N),	
    --BEHI4 – Percent of residents who have improved behavioural symptoms
    BEHI4   = cast(SUM (QI_BEHI4_N) as float(53)) / nullif(SUM (QI_BEHI4_D), 0) * 100.00,
    BEHI4_D = SUM (QI_BEHI4_D),
    BEHI4_N = SUM (QI_BEHI4_N),
    --CAT02 – Percent of residents with indwelling catheters
    CAT02   = cast(SUM (QI_CAT02_N) as float(53)) / nullif(SUM (QI_CAT02_D), 0) * 100.00,
    CAT02_D = SUM (QI_CAT02_D),
    CAT02_N = SUM (QI_CAT02_N),
    --CNT02 – Percent of residents with worsening bowel continence
    CNT02   = cast(SUM (QI_CNT02_N) as float(53)) / nullif(SUM (QI_CNT02_D), 0) * 100.00,
    CNT02_D = SUM (QI_CNT02_D),
    CNT02_N = SUM (QI_CNT02_N),
    --CNT03 – Percent of residents with worsening bladder continence
    CNT03   = cast(SUM (QI_CNT03_N) as float(53)) / nullif(SUM (QI_CNT03_D), 0) * 100.00,    
    CNT03_D = SUM (QI_CNT03_D),
    CNT03_N = SUM (QI_CNT03_N), 
    --CNT04 – Percent of residents with urinary tract infections
    CNT04   = cast(SUM (QI_CNT04_N) as float(53)) / nullif(SUM (QI_CNT04_D), 0) * 100.00,
    CNT04_D = SUM (QI_CNT04_D),
    CNT04_N = SUM (QI_CNT04_N),
    --CNT2A – Percent of residents with improving bowel continence
    CNT2A   = cast(SUM (QI_CNT2A_N) as float(53)) / nullif(SUM (QI_CNT2A_D), 0) * 100.00,
    CNT2A_D = SUM (QI_CNT2A_D),
    CNT2A_N = SUM (QI_CNT2A_N),
    --CNT3A – Percent of residents with improving bladder continence
    CNT3A   = cast(SUM (QI_CNT3A_N) as float(53)) / nullif(SUM (QI_CNT3A_D), 0) * 100.00,
    CNT3A_D = SUM (QI_CNT3A_D),
    CNT3A_N = SUM (QI_CNT3A_N),
    --COG01 – Percent of residents whose cognitive ability has worsened
    COG01   = cast(SUM (QI_COG01_N) as float(53)) / nullif(SUM (QI_COG01_D), 0) * 100.00,
    COG01_D = SUM (QI_COG01_D),
    COG01_N = SUM (QI_COG01_N),
    --COG1A – Percent of residents whose cognitive ability has improved
    COG1A   = cast(SUM (QI_COG1A_N) as float(53)) / nullif(SUM (QI_COG1A_D), 0) * 100.00,
    COG1A_D = SUM (QI_COG1A_D),
    COG1A_N = SUM (QI_COG1A_N),
    --COM01 – Percent of residents whose ability to communicate has worsened
    COM01   = cast(SUM (QI_COM01_N) as float(53)) / nullif(SUM (QI_COM01_D), 0) * 100.00,
    COM01_D = SUM (QI_COM01_D),
    COM01_N = SUM (QI_COM01_N),
    --COM1A – Percent of residents whose ability to communicate has improved
    COM1A   = cast(SUM (QI_COM1A_N) as float(53)) / nullif(SUM (QI_COM1A_D), 0) * 100.00,
    COM1A_D = SUM (QI_COM1A_D),
    COM1A_N = SUM (QI_COM1A_N),
    --DEL0X – Percent of residents with symptoms of delirium
    DEL0X   = cast(SUM (QI_DEL0X_N) as float(53)) / nullif(SUM (QI_DEL0X_D), 0) * 100.00,
    DEL0X_D = SUM (QI_DEL0X_D),
    DEL0X_N = SUM (QI_DEL0X_N),
    --DRG01 – Percent of residents on antipsychotics without a diagnosis of psychosis
    DRG01   = cast(SUM (QI_DRG01_N) as float(53)) / nullif(SUM (QI_DRG01_D), 0) * 100.00,
    DRG01_D = SUM (QI_DRG01_D),
    DRG01_N = SUM (QI_DRG01_N),
    --FAL02 – Percent of residents who have fallen in the last 30 days
    FAL02   = cast(SUM (QI_FAL02_N) as float(53)) / nullif(SUM (QI_FAL02_D), 0) * 100.00,
    FAL02_D = SUM (QI_FAL02_D),
    FAL02_N = SUM (QI_FAL02_N),
    --INF0X – Percent of residents with infections
    INF0X   = cast(SUM (QI_INF0X_N) as float(53)) / nullif(SUM (QI_INF0X_D), 0) * 100.00,
    INF0X_D = SUM (QI_INF0X_D),
    INF0X_N = SUM (QI_INF0X_N),
    --MOB01 – Percent of residents who have declined in their ability to locomote
    MOB01   = cast(SUM (QI_MOB01_N) as float(53)) / nullif(SUM (QI_MOB01_D), 0) * 100.00,
    MOB01_D = SUM (QI_MOB01_D),
    MOB01_N = SUM (QI_MOB01_N),
    --MOB1A – Percent of residents who have improved in their ability to locomote
    MOB1A   = cast(SUM (QI_MOB1A_N) as float(53)) / nullif(SUM (QI_MOB1A_D), 0) * 100.00,
    MOB1A_D = SUM (QI_MOB1A_D),
    MOB1A_N = SUM (QI_MOB1A_N),
    --MOD4A – Percent of residents who decline in mood from symptoms of depression
    MOD4A   = cast(SUM (QI_MOD4A_N) as float(53)) / nullif(SUM (QI_MOD4A_D), 0) * 100.00,
    MOD4A_D = SUM (QI_MOD4A_D),
    MOD4A_N = SUM (QI_MOD4A_N),
    --NUT01 – Percent of residents with a feeding tube
    NUT01   = cast(SUM (QI_NUT01_N) as float(53)) / nullif(SUM (QI_NUT01_D), 0) * 100.00,
    NUT01_D = SUM (QI_NUT01_D),
    NUT01_N = SUM (QI_NUT01_N),
    --PAI0X – Percent of residents with pain
    PAI0X   = cast(SUM (QI_PAI0X_N) as float(53)) / nullif(SUM (QI_PAI0X_D), 0) * 100.00,
    PAI0X_D = SUM (QI_PAI0X_D),
    PAI0X_N = SUM (QI_PAI0X_N),
    --PAN01 – Percent of residents with worsening pain
    PAN01   = cast(SUM (QI_PAN01_N) as float(53)) / nullif(SUM (QI_PAN01_D), 0) * 100.00,
    PAN01_D = SUM (QI_PAN01_D),
    PAN01_N = SUM (QI_PAN01_N),
    --PRU05 – Percent of residents who have a pressure ulcer stage 2 to 4
    PRU05   = cast(SUM (QI_PRU05_N) as float(53)) / nullif(SUM (QI_PRU05_D), 0) * 100.00,
    PRU05_D = SUM (QI_PRU05_D),
    PRU05_N = SUM (QI_PRU05_N),
    --PRU06 – Percent of residents with worsening stage 2-4 pressure sores
    PRU06   = cast(SUM (QI_PRU06_N) as float(53)) / nullif(SUM (QI_PRU06_D), 0) * 100.00,
    PRU06_D = SUM (QI_PRU06_D),
    PRU06_N = SUM (QI_PRU06_N),
    --PRU09 – Percent of residents with newly occurring pressure ulcer stage 2 to 4
    PRU09   = cast(SUM (QI_PRU09_N) as float(53)) / nullif(SUM (QI_PRU09_D), 0) * 100.00,
    PRU09_D = SUM (QI_PRU09_D),
    PRU09_N = SUM (QI_PRU09_N),
    --RES01 – Percent of residents with daily physical restraints
    RES01   = cast(SUM (QI_RES01_N) as float(53)) / nullif(SUM (QI_RES01_D), 0) * 100.00,
    RES01_D = SUM (QI_RES01_D),
    RES01_N = SUM (QI_RES01_N),
    --RSPX2 – Percent of residents who have developed a respiratory infection or have not gotten better
    RSPX2   = cast(SUM (QI_RSPX2_N) as float(53)) / nullif(SUM (QI_RSPX2_D), 0) * 100.00,
    RSPX2_D = SUM (QI_RSPX2_D),
    RSPX2_N = SUM (QI_RSPX2_N),
    --WGT01 – Percent of residents who
    WGT01   = cast(SUM (QI_WGT01_N) as float(53))/ nullif(SUM (QI_WGT01_D), 0) * 100.00,
    WGT01_D = SUM (QI_WGT01_D),
    WGT01_N = SUM (QI_WGT01_N)
from 
(select --Calculate Rolling Average
	InstitutionNumber, InstitutionNumberDesc, FiscalYear, zzAssessmentLink, 
	--ADL01 – Percent of residents who had an une*pected loss of function in some basic daily activities
	QI_ADL01_D = cast(SUM (QI_ADL01_D) as float(53)) / count(*),
	QI_ADL01_N = cast(SUM (QI_ADL01_N) as float(53)) / count(*),
	--ADL05 – Percent of residents who improve status on mid-loss ADL functioning (transfer, locomotion) or remain completely independent in mid-loss ADLs
	QI_ADL05_D = cast(SUM (QI_ADL05_D) as float(53)) / count(*),
	QI_ADL05_N = cast(SUM (QI_ADL05_N) as float(53)) / count(*),
	--ADL06 – Percent of residents who improve status on early-loss ADL functioning (dressing and personal hygiene) or remain completely independent in early-loss ADLs
	QI_ADL06_D = cast(SUM (QI_ADL06_D) as float(53)) / count(*),
	QI_ADL06_N = cast(SUM (QI_ADL06_N) as float(53)) / count(*),
	--ADL1A – Percent of residents who had an improvement of function in some basic daily activities
	QI_ADL1A_D = cast(SUM (QI_ADL1A_D) as float(53)) / count(*),
	QI_ADL1A_N = cast(SUM (QI_ADL1A_N) as float(53)) / count(*),
    --ADL5A – Percent of residents who declined status on mid-loss ADL functioning (transfer, locomotion) or remain completely dependent in mid-loss ADLs
    QI_ADL5A_D = cast(SUM (QI_ADL5A_D) as float(53)) / count(*),
    QI_ADL5A_N = cast(SUM (QI_ADL5A_N) as float(53)) / count(*),
    --ADL6A – Percent of residents who declined status on early-loss ADL functioning (dressing and personal hygiene) or remain completely dependent in early-loss ADLs)
    QI_ADL6A_D = cast(SUM (QI_ADL6A_D) as float(53)) / count(*),
    QI_ADL6A_N = cast(SUM (QI_ADL6A_N) as float(53)) / count(*),
    --ADLD7 – Percent of residents who have declined in ADLs   
    QI_ADLD7_D = cast(SUM (QI_ADLD7_D) as float(53)) / count(*),
    QI_ADLD7_N = cast(SUM (QI_ADLD7_N) as float(53)) / count(*),
    --BEHD4 – Percent of residents who have declining behavioral symptoms
    QI_BEHD4_D = cast(SUM (QI_BEHD4_D) as float(53)) / count(*),
    QI_BEHD4_N = cast(SUM (QI_BEHD4_N) as float(53)) / count(*),	
    --BEHI4 – Percent of residents who have improved behavioural symptoms
    QI_BEHI4_D = cast(SUM (QI_BEHI4_D) as float(53)) / count(*),
    QI_BEHI4_N = cast(SUM (QI_BEHI4_N) as float(53)) / count(*),
    --CAT02 – Percent of residents with indwelling catheters
    QI_CAT02_D = cast(SUM (QI_CAT02_D) as float(53)) / count(*),
    QI_CAT02_N = cast(SUM (QI_CAT02_N) as float(53)) / count(*),
    --CNT02 – Percent of residents with worsening bowel continence
    QI_CNT02_D = cast(SUM (QI_CNT02_D) as float(53)) / count(*),
    QI_CNT02_N = cast(SUM (QI_CNT02_N) as float(53)) / count(*),
    --CNT03 – Percent of residents with worsening bladder continence
    QI_CNT03_D = cast(SUM (QI_CNT03_D) as float(53)) / count(*),
    QI_CNT03_N = cast(SUM (QI_CNT03_N) as float(53)) / count(*), 
    --CNT04 – Percent of residents with urinary tract infections
    QI_CNT04_D = cast(SUM (QI_CNT04_D) as float(53)) / count(*),
    QI_CNT04_N = cast(SUM (QI_CNT04_N) as float(53)) / count(*),
    --CNT2A – Percent of residents with improving bowel continence
    QI_CNT2A_D = cast(SUM (QI_CNT2A_D) as float(53)) / count(*),
    QI_CNT2A_N = cast(SUM (QI_CNT2A_N) as float(53)) / count(*),
    --CNT3A – Percent of residents with improving bladder continence
    QI_CNT3A_D = cast(SUM (QI_CNT3A_D) as float(53)) / count(*),
    QI_CNT3A_N = cast(SUM (QI_CNT3A_N) as float(53)) / count(*),
    --COG01 – Percent of residents whose cognitive ability has worsened
    QI_COG01_D = cast(SUM (QI_COG01_D) as float(53)) / count(*),
    QI_COG01_N = cast(SUM (QI_COG01_N) as float(53)) / count(*),
    --COG1A – Percent of residents whose cognitive ability has improved
    QI_COG1A_D = cast(SUM (QI_COG1A_D) as float(53)) / count(*),
    QI_COG1A_N = cast(SUM (QI_COG1A_N) as float(53)) / count(*),
    --COM01 – Percent of residents whose ability to communicate has worsened
    QI_COM01_D = cast(SUM (QI_COM01_D) as float(53)) / count(*),
    QI_COM01_N = cast(SUM (QI_COM01_N) as float(53)) / count(*),
    --COM1A – Percent of residents whose ability to communicate has improved
    QI_COM1A_D = cast(SUM (QI_COM1A_D) as float(53)) / count(*),
    QI_COM1A_N = cast(SUM (QI_COM1A_N) as float(53)) / count(*),
    --DEL0X – Percent of residents with symptoms of delirium
    QI_DEL0X_D = cast(SUM (QI_DEL0X_D) as float(53)) / count(*),
    QI_DEL0X_N = cast(SUM (QI_DEL0X_N) as float(53)) / count(*),
    --DRG01 – Percent of residents on antipsychotics without a diagnosis of psychosis
    QI_DRG01_D = cast(SUM (QI_DRG01_D) as float(53)) / count(*),
    QI_DRG01_N = cast(SUM (QI_DRG01_N) as float(53)) / count(*),
    --FAL02 – Percent of residents who have fallen in the last 30 days
    QI_FAL02_D = cast(SUM (QI_FAL02_D) as float(53)) / count(*),
    QI_FAL02_N = cast(SUM (QI_FAL02_N) as float(53)) / count(*),
    --INF0X – Percent of residents with infections
    QI_INF0X_D = cast(SUM (QI_INF0X_D) as float(53)) / count(*),
    QI_INF0X_N = cast(SUM (QI_INF0X_N) as float(53)) / count(*),
    --MOB01 – Percent of residents who have declined in their ability to locomote
    QI_MOB01_D = cast(SUM (QI_MOB01_D) as float(53)) / count(*),
    QI_MOB01_N = cast(SUM (QI_MOB01_N) as float(53)) / count(*),
    --MOB1A – Percent of residents who have improved in their ability to locomote
    QI_MOB1A_D = cast(SUM (QI_MOB1A_D) as float(53)) / count(*),
    QI_MOB1A_N = cast(SUM (QI_MOB1A_N) as float(53)) / count(*),
    --MOD4A – Percent of residents who decline in mood from symptoms of depression
    QI_MOD4A_D = cast(SUM (QI_MOD4A_D) as float(53)) / count(*),
    QI_MOD4A_N = cast(SUM (QI_MOD4A_N) as float(53)) / count(*),
    --NUT01 – Percent of residents with a feeding tube
    QI_NUT01_D = cast(SUM (QI_NUT01_D) as float(53)) / count(*),
    QI_NUT01_N = cast(SUM (QI_NUT01_N) as float(53)) / count(*),
    --PAI0X – Percent of residents with pain
    QI_PAI0X_D = cast(SUM (QI_PAI0X_D) as float(53)) / count(*),
    QI_PAI0X_N = cast(SUM (QI_PAI0X_N) as float(53)) / count(*),
    --PAN01 – Percent of residents with worsening pain
    QI_PAN01_D = cast(SUM (QI_PAN01_D) as float(53)) / count(*),
    QI_PAN01_N = cast(SUM (QI_PAN01_N) as float(53)) / count(*),
    --PRU05 – Percent of residents who have a pressure ulcer stage 2 to 4
    QI_PRU05_D = cast(SUM (QI_PRU05_D) as float(53)) / count(*),
    QI_PRU05_N = cast(SUM (QI_PRU05_N) as float(53)) / count(*),
    --PRU06 – Percent of residents with worsening stage 2-4 pressure sores
    QI_PRU06_D = cast(SUM (QI_PRU06_D) as float(53)) / count(*),
    QI_PRU06_N = cast(SUM (QI_PRU06_N) as float(53)) / count(*),
    --PRU09 – Percent of residents with newly occurring pressure ulcer stage 2 to 4
    QI_PRU09_D = cast(SUM (QI_PRU09_D) as float(53)) / count(*),
    QI_PRU09_N = cast(SUM (QI_PRU09_N) as float(53)) / count(*),
    --RES01 – Percent of residents with daily physical restraints
    QI_RES01_D = cast(SUM (QI_RES01_D) as float(53)) / count(*),
    QI_RES01_N = cast(SUM (QI_RES01_N) as float(53)) / count(*),
    --RSPX2 – Percent of residents who have developed a respiratory infection or have not gotten better
    QI_RSPX2_D = cast(SUM (QI_RSPX2_D) as float(53)) / count(*),
    QI_RSPX2_N = cast(SUM (QI_RSPX2_N) as float(53)) / count(*),
    --WGT01 – Percent of residents who
    QI_WGT01_D = cast(SUM (QI_WGT01_D) as float(53)) / count(*),
    QI_WGT01_N = cast(SUM (QI_WGT01_N) as float(53)) / count(*)
from
 [dbo].[MDS20_2010_QI_VR]
group by InstitutionNumber, InstitutionNumberDesc, FiscalYear, zzAssessmentLink) RollingAverage 
group by InstitutionNumber, InstitutionNumberDesc, FiscalYear
	


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_DemographicChange_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'





CREATE VIEW [dbo].[MDS20_DemographicChange_Form_VR]
AS
SELECT     zzAbstractLink, zzLinkBackgroundID, ReasonAssessment_AA8, ReasonAssessmentDesc_AA8, URI_AA1, HealthRecordNumber_A6a, 
                      HealthRegisterNumber_A6b, NewHealthRegisterNumber_ZA6b, AdmissionDate_AB1, NewAdmissionDate_ZAB1, Gender_AA2, GenderDesc_AA2, 
                      MaidenName, LastName, MiddleName, FirstName, Birthdate_AA3a, BirthdateEstimated_AA3b, BirthDateEstimatedDesc_AA3b, 
                      HealthCareNumber_AA5a, HCNVersion, HCNProvince_AA5b, HCNProvinceDesc_AA5b, FacilityNumber_AA6, FacilityNumberDesc_AA6, IsSubmited, 
                      IsSubmitedDesc, IsValidated, IsValidatedDesc, IsCompleted, IsCompletedDesc, IsDeleted, IsDeletedDesc, CoderNumber, CoderNumberDesc, 
                      InterfaceDate, InterfaceTime, InterfaceCoder, InterfaceCoderDesc, InputDate, InputTime, DataEntryCoder, DataEntryCoderDesc, FinishDate, FinishTime, 
                      Secret, SecretDesc, ChangedDate_Z7, DischargeDate_R4, NewDischargeDate_ZR4, Hospital, HospitalDesc
FROM         dbo.MDS20_VR
WHERE     (AA8_CIHI = ''00'')






' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_1_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[MDS20_FULL_Assessment_1_Form_VR]
AS
SELECT     zzAbstractLink, zzLinkBackgroundID, URI_AA1, MaidenName, LastName, MiddleName, FirstName, RoomUnit, RoomUnitDesc, RoomNumber, Gender_AA2, 
                      GenderDesc_AA2, AssessmentDate_A3, NextAssessmentDate, Birthdate_AA3a, BirthdateEstimated_AA3b, BirthDateEstimatedDesc_AA3b, Treaty_band_AA4a, MaritalStatus_A5, 
                      MaritalStatusDesc_A5, FacilityNumber_AA6, FacilityNumberDesc_AA6, HealthCareNumber_AA5a, HCNVersion, HCNProvince_AA5b, HCNProvinceDesc_AA5b, 
                      HealthRecordNumber_A6a, HealthRegisterNumber_A6b, Hospital, HospitalDesc, ReasonAssessment_AA8, ReasonAssessmentDesc_AA8, 
                      AboriginalIdentityFirstNations_AA4a, AboriginalIdentityFirstNationsDesc_AA4a, AboriginalIdentityMetiis_AA4b, AboriginalIdentityMetiisDesc_AA4b, 
                      AboriginalIdentityInuit_AA4c, AboriginalIdentityInuitDesc_AA4c
FROM         dbo.MDS20_VR
WHERE     (AA8_CIHI IN (''01'', ''02'', ''03'', ''04'')) AND (zzLinkBackgroundID <> zzAbstractLink)


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_2_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[MDS20_FULL_Assessment_2_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.ReasonAssessment_AA8, dbo.MDS20_VR.ReasonAssessmentDesc_AA8, 
                      dbo.MDS20_FULL_1_VR.RFP_Provincial_A7a, dbo.MDS20_FULL_1_VR.RFP_ProvincialDesc_A7a, dbo.MDS20_FULL_1_VR.RFP_Other_Prov_A7b, 
                      dbo.MDS20_FULL_1_VR.RFP_Other_ProvDesc_A7b, dbo.MDS20_FULL_1_VR.RFP_Federal_V_A7c, dbo.MDS20_FULL_1_VR.RFP_Federal_VDesc_A7c, 
                      dbo.MDS20_FULL_1_VR.RFP_Federal_F_A7d, dbo.MDS20_FULL_1_VR.RFP_Federal_FDesc_A7d, dbo.MDS20_FULL_1_VR.RFP_Federal_O_A7e, 
                      dbo.MDS20_FULL_1_VR.RFP_Federal_ODesc_A7e, dbo.MDS20_FULL_1_VR.RFP_WCB_A7f, dbo.MDS20_FULL_1_VR.RFP_WCBDesc_A7f, 
                      dbo.MDS20_FULL_1_VR.RFP_Insurance_A7g, dbo.MDS20_FULL_1_VR.RFP_InsuranceDesc_A7g, dbo.MDS20_FULL_1_VR.RFP_Public_A7h, 
                      dbo.MDS20_FULL_1_VR.RFP_PublicDesc_A7h, dbo.MDS20_FULL_1_VR.RFP_Self_A7i, dbo.MDS20_FULL_1_VR.RFP_SelfDesc_A7i, 
                      dbo.MDS20_FULL_1_VR.RFP_Other_Country_A7j, dbo.MDS20_FULL_1_VR.RFP_Other_CountryDesc_A7j, dbo.MDS20_FULL_1_VR.RFP_Unkown_A7k, 
                      dbo.MDS20_FULL_1_VR.RFP_UnkownDesc_A7k, dbo.MDS20_Shared_1_VR.GuardianLegal_A9a, dbo.MDS20_Shared_1_VR.GuardianLegalDesc_A9a, 
                      dbo.MDS20_Shared_1_VR.GuardianAttorney_A9b, dbo.MDS20_Shared_1_VR.GuardianAttorneyDesc_A9b, dbo.MDS20_Shared_1_VR.GuardianOther_A9c, 
                      dbo.MDS20_Shared_1_VR.GuardianOtherDesc_A9c, dbo.MDS20_Shared_1_VR.GuardianFamily_A9d, dbo.MDS20_Shared_1_VR.GuardianFamilyDesc_A9d, 
                      dbo.MDS20_Shared_1_VR.GuardianHealth_A9e, dbo.MDS20_Shared_1_VR.GuardianHealthDesc_A9e, dbo.MDS20_Shared_1_VR.GuardianSelf_A9f, 
                      dbo.MDS20_Shared_1_VR.GuardianSelfDesc_A9f, dbo.MDS20_Shared_1_VR.GuardianNone_A9g, dbo.MDS20_Shared_1_VR.GuardianNoneDesc_A9g, 
                      dbo.MDS20_Shared_1_VR.AdvDirLiving_A10a, dbo.MDS20_Shared_1_VR.AdvDirLivingDesc_A10a, dbo.MDS20_Shared_1_VR.AdvDirNoResuscitate_A10b, 
                      dbo.MDS20_Shared_1_VR.AdvDirNoResuscitateDesc_A10b, dbo.MDS20_Shared_1_VR.AdvDirNoHospitalize_A10c, 
                      dbo.MDS20_Shared_1_VR.AdvDirNoHospitalizeDesc_A10c, dbo.MDS20_Shared_1_VR.AdvDirOrgan_A10d, dbo.MDS20_Shared_1_VR.AdvDirOrganDesc_A10d, 
                      dbo.MDS20_Shared_1_VR.AdvDirAutopsy_A10e, dbo.MDS20_Shared_1_VR.AdvDirAutopsyDesc_A10e, dbo.MDS20_Shared_1_VR.AdvDirFeeding_A10f, 
                      dbo.MDS20_Shared_1_VR.AdvDirFeedingDesc_A10f, dbo.MDS20_Shared_1_VR.AdvDirMedication_A10g, dbo.MDS20_Shared_1_VR.AdvDirMedicationDesc_A10g, 
                      dbo.MDS20_Shared_1_VR.AdvDirOther_A10h, dbo.MDS20_Shared_1_VR.AdvDirOtherDesc_A10h, dbo.MDS20_Shared_1_VR.AdvDirNone_A10i, 
                      dbo.MDS20_Shared_1_VR.AdvDirNoneDesc_A10i, dbo.MDS20_Shared_1_VR.DecisionMakerForPersonalCare_A11a, 
                      dbo.MDS20_Shared_1_VR.DecisionMakerForPersonalCareDesc_A11a, dbo.MDS20_Shared_1_VR.DecisionMakerForProperty_A11b, 
                      dbo.MDS20_Shared_1_VR.DecisionMakerForPropertyDesc_A11b, dbo.MDS20_Shared_1_VR.AdvanceDirectivesResuscitating_A12a, 
                      dbo.MDS20_Shared_1_VR.AdvanceDirectivesResuscitatingDesc_A12a, dbo.MDS20_Shared_1_VR.AdvanceDirectivesHospitalizing_A12b, 
                      dbo.MDS20_Shared_1_VR.AdvanceDirectivesHospitalizingDesc_A12b, dbo.MDS20_Shared_1_VR.Comatose_B1, dbo.MDS20_Shared_1_VR.ComatoseDesc_B1, 
                      dbo.MDS20_Shared_1_VR.MemoryShort_B2a, dbo.MDS20_Shared_1_VR.MemoryShortDesc_B2a, dbo.MDS20_Shared_1_VR.MemoryLong_B2b, 
                      dbo.MDS20_Shared_1_VR.MemoryLongDesc_B2b, dbo.MDS20_Shared_1_VR.MemAbilityCurrent_B3a, dbo.MDS20_Shared_1_VR.MemAbilityCurrentDesc_B3a, 
                      dbo.MDS20_Shared_1_VR.MemAbilityOwnRoom_B3b, dbo.MDS20_Shared_1_VR.MemAbilityOwnRoomDesc_B3b, dbo.MDS20_Shared_1_VR.MemAbilityStaff_B3c, 
                      dbo.MDS20_Shared_1_VR.MemAbilityStaffDesc_B3c, dbo.MDS20_Shared_1_VR.MemAbilityFacility_B3d, dbo.MDS20_Shared_1_VR.MemAbilityFacilityDesc_B3d, 
                      dbo.MDS20_Shared_1_VR.MemAbilityNone_B3e, dbo.MDS20_Shared_1_VR.MemAbilityNoneDesc_B3e, dbo.MDS20_Shared_1_VR.CognitiveSkills_B4, 
                      dbo.MDS20_Shared_1_VR.CognitiveSkillsDesc_B4, dbo.MDS20_Shared_1_VR.DisorderEasily_B5a, dbo.MDS20_Shared_1_VR.DisorderEasilyDesc_B5a, 
                      dbo.MDS20_Shared_1_VR.DisorderPerception_B5b, dbo.MDS20_Shared_1_VR.DisorderPerceptionDesc_B5b, dbo.MDS20_Shared_1_VR.DisorderSpeech_B5c, 
                      dbo.MDS20_Shared_1_VR.DisorderSpeechDesc_B5c, dbo.MDS20_Shared_1_VR.DisorderRestless_B5d, dbo.MDS20_Shared_1_VR.DisorderRestlessDesc_B5d, 
                      dbo.MDS20_Shared_1_VR.DisorderLethargy_B5e, dbo.MDS20_Shared_1_VR.DisorderLethargyDesc_B5e, dbo.MDS20_Shared_1_VR.DisorderMental_B5f, 
                      dbo.MDS20_Shared_1_VR.DisorderMentalDesc_B5f, dbo.MDS20_Shared_1_VR.ChangeCognitive_B6, dbo.MDS20_Shared_1_VR.ChangeCognitiveDesc_B6, 
                      dbo.MDS20_FULL_1_VR.Hearing_C1, dbo.MDS20_FULL_1_VR.HearingDesc_C1, dbo.MDS20_FULL_1_VR.CommAidReg_C2a, 
                      dbo.MDS20_FULL_1_VR.CommAidRegDesc_C2a, dbo.MDS20_FULL_1_VR.CommAidNoReg_C2b, dbo.MDS20_FULL_1_VR.CommAidNoRegDesc_C2b, 
                      dbo.MDS20_FULL_1_VR.CommOther_C2c, dbo.MDS20_FULL_1_VR.CommOtherDesc_C2c, dbo.MDS20_FULL_1_VR.CommNone_C2d, 
                      dbo.MDS20_FULL_1_VR.CommNoneDesc_C2d, dbo.MDS20_FULL_1_VR.ExpressSpeech_C3a, dbo.MDS20_FULL_1_VR.ExpressSpeechDesc_C3a, 
                      dbo.MDS20_FULL_1_VR.ExpressWrite_C3b, dbo.MDS20_FULL_1_VR.ExpressWriteDesc_C3b, dbo.MDS20_FULL_1_VR.ExpressLanguage_C3c, 
                      dbo.MDS20_FULL_1_VR.ExpressLanguageDesc_C3c, dbo.MDS20_FULL_1_VR.ExpressSigns_C3d, dbo.MDS20_FULL_1_VR.ExpressSignsDesc_C3d, 
                      dbo.MDS20_FULL_1_VR.ExpressBoard_C3e, dbo.MDS20_FULL_1_VR.ExpressBoardDesc_C3e, dbo.MDS20_FULL_1_VR.ExpressOther_C3f, 
                      dbo.MDS20_FULL_1_VR.ExpressOtherDesc_C3f, dbo.MDS20_FULL_1_VR.ExpressNone_C3g, dbo.MDS20_FULL_1_VR.ExpressNoneDesc_C3g, 
                      dbo.MDS20_Shared_1_VR.UnderStood_C4, dbo.MDS20_Shared_1_VR.UnderStoodDesc_C4, dbo.MDS20_FULL_1_VR.SpeechClarity_C5, 
                      dbo.MDS20_FULL_1_VR.SpeechClarityDesc_C5, dbo.MDS20_Shared_1_VR.AbilityUnderStood_C6, dbo.MDS20_Shared_1_VR.AbilityUnderStoodDesc_C6, 
                      dbo.MDS20_Shared_1_VR.ChangeComm_C7, dbo.MDS20_Shared_1_VR.ChangeCommDesc_C7, dbo.MDS20_FULL_1_VR.Vision_D1, 
                      dbo.MDS20_FULL_1_VR.VisionDesc_D1, dbo.MDS20_FULL_1_VR.SideVision_D2a, dbo.MDS20_FULL_1_VR.SideVisionDesc_D2a, 
                      dbo.MDS20_FULL_1_VR.HaloVision_D2b, dbo.MDS20_FULL_1_VR.HaloVisionDesc_D2b, dbo.MDS20_FULL_1_VR.VisualApp_D3, 
                      dbo.MDS20_FULL_1_VR.VisualAppDesc_D3, dbo.MDS20_Shared_1_VR.DepressionNegative_E1a, dbo.MDS20_Shared_1_VR.DepressionNegativeDesc_E1a, 
                      dbo.MDS20_Shared_1_VR.DepressionRepeatQues_E1b, dbo.MDS20_Shared_1_VR.DepressionRepeatQuesDesc_E1b, 
                      dbo.MDS20_Shared_1_VR.DepressionRepeatVerb_E1c, dbo.MDS20_Shared_1_VR.DepressionRepeatVerbDesc_E1c, 
                      dbo.MDS20_Shared_1_VR.DepressionAnger_E1d, dbo.MDS20_Shared_1_VR.DepressionAngerDesc_E1d, dbo.MDS20_Shared_1_VR.DepressionDeprecation_E1e, 
                      dbo.MDS20_Shared_1_VR.DepressionDeprecationDesc_E1e, dbo.MDS20_Shared_1_VR.DepressionUnrealistic_E1f, 
                      dbo.MDS20_Shared_1_VR.DepressionUnrealisticDesc_E1f, dbo.MDS20_Shared_1_VR.DepressionTerrible_E1g, 
                      dbo.MDS20_Shared_1_VR.DepressionTerribleDesc_E1g, dbo.MDS20_Shared_1_VR.DepressionComplaints_E1h, 
                      dbo.MDS20_Shared_1_VR.DepressionComplaintsDesc_E1h, dbo.MDS20_Shared_1_VR.DepressionNonHealth_E1i, 
                      dbo.MDS20_Shared_1_VR.DepressionNonHealthDesc_E1i, dbo.MDS20_Shared_1_VR.DepressionUnpleasant_E1j, 
                      dbo.MDS20_Shared_1_VR.DepressionUnpleasantDesc_E1j, dbo.MDS20_Shared_1_VR.DepressionChange_E1k, 
                      dbo.MDS20_Shared_1_VR.DepressionChangeDesc_E1k, dbo.MDS20_Shared_1_VR.DepressionSad_E1l, dbo.MDS20_Shared_1_VR.DepressionSadDesc_E1l, 
                      dbo.MDS20_Shared_1_VR.DepressionCrying_E1m, dbo.MDS20_Shared_1_VR.DepressionCryingDesc_E1m, dbo.MDS20_Shared_1_VR.DepressionPhysical_E1n, 
                      dbo.MDS20_Shared_1_VR.DepressionPhysicalDesc_E1n, dbo.MDS20_Shared_1_VR.DepressionInterest_E1o, 
                      dbo.MDS20_Shared_1_VR.DepressionInterestDesc_E1o, dbo.MDS20_Shared_1_VR.DepressionInteraction_E1p, 
                      dbo.MDS20_Shared_1_VR.DepressionInteractionDesc_E1p, dbo.MDS20_Shared_1_VR.Persistence_E2, dbo.MDS20_Shared_1_VR.PersistenceDesc_E2, 
                      dbo.MDS20_Shared_1_VR.ChangeMood_E3, dbo.MDS20_Shared_1_VR.ChangeMoodDesc_E3, dbo.MDS20_Shared_1_VR.BehaviorWanderingFre_E4aA, 
                      dbo.MDS20_Shared_1_VR.BehaviorWanderingFreDesc_E4aA, dbo.MDS20_Shared_1_VR.BehaviorWanderingAlt_E4aB, 
                      dbo.MDS20_Shared_1_VR.BehaviorWanderingAltDesc_E4aB, dbo.MDS20_Shared_1_VR.BehaviorVerballyFre_E4bA, 
                      dbo.MDS20_Shared_1_VR.BehaviorVerballyFreDesc_E4bA, dbo.MDS20_Shared_1_VR.BehaviorVerballyAlt_E4bB, 
                      dbo.MDS20_Shared_1_VR.BehaviorVerballyAltDesc_E4bB, dbo.MDS20_Shared_1_VR.BehaviorPhysicallyFre_E4cA, 
                      dbo.MDS20_Shared_1_VR.BehaviorPhysicalFreDesc_E4cA, dbo.MDS20_Shared_1_VR.BehaviorPhysicallyAlt_E4cB, 
                      dbo.MDS20_Shared_1_VR.BehaviorPhysicalAltDesc_E4cB, dbo.MDS20_Shared_1_VR.BehaviorSociallyFre_E4dA, 
                      dbo.MDS20_Shared_1_VR.BehaviorSociallyFreDesc_E4dA, dbo.MDS20_Shared_1_VR.BehaviorSociallyAlt_E4dB, 
                      dbo.MDS20_Shared_1_VR.BehaviorSociallyAltDesc_E4dB, dbo.MDS20_Shared_1_VR.BehaviorResistsFre_E4eA, 
                      dbo.MDS20_Shared_1_VR.BehaviorResistsFreDesc_E4eA, dbo.MDS20_Shared_1_VR.BehaviorResistsAlt_E4eB, 
                      dbo.MDS20_Shared_1_VR.BehaviorResistsAltDesc_E4eB, dbo.MDS20_Shared_1_VR.ChangeBehave_E5, dbo.MDS20_Shared_1_VR.ChangeBehaveDesc_E5
FROM         dbo.MDS20_VR LEFT OUTER JOIN
                      dbo.MDS20_FULL_1_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_FULL_1_VR.zzAbstractLink LEFT OUTER JOIN
                      dbo.MDS20_Shared_1_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Shared_1_VR.zzAbstractLink
WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''01'', ''02'', ''03'', ''04'')) AND (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_3_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'






CREATE VIEW [dbo].[MDS20_FULL_Assessment_3_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.ReasonAssessment_AA8, 
                      dbo.MDS20_VR.ReasonAssessmentDesc_AA8, dbo.MDS20_Shared_2_VR.Interacting_F1a, dbo.MDS20_Shared_2_VR.InteractingDesc_F1a, 
                      dbo.MDS20_Shared_2_VR.PlanActivity_F1b, dbo.MDS20_Shared_2_VR.PlanActivityDesc_F1b, dbo.MDS20_Shared_2_VR.SelfActivity_F1c, 
                      dbo.MDS20_Shared_2_VR.SelfActivityDesc_F1c, dbo.MDS20_Shared_2_VR.Goals_F1d, dbo.MDS20_Shared_2_VR.GoalsDesc_F1d, 
                      dbo.MDS20_Shared_2_VR.Pursues_F1e, dbo.MDS20_Shared_2_VR.PursuesDesc_F1e, dbo.MDS20_Shared_2_VR.Accepts_F1f, 
                      dbo.MDS20_Shared_2_VR.AcceptsDesc_F1f, dbo.MDS20_Shared_2_VR.SenseNone_F1g, dbo.MDS20_Shared_2_VR.SenseNoneDesc_F1g, 
                      dbo.MDS20_FULL_1_VR.UnsettledStaff_F2a, dbo.MDS20_FULL_1_VR.UnsettledStaffDesc_F2a, dbo.MDS20_FULL_1_VR.UnsettledRoommate_F2b, 
                      dbo.MDS20_FULL_1_VR.UnsettledRoommateDesc_F2b, dbo.MDS20_FULL_1_VR.UnsettledResident_F2c, 
                      dbo.MDS20_FULL_1_VR.UnsettledResidentDesc_F2c, dbo.MDS20_FULL_1_VR.UnsettledFamily_F2d, dbo.MDS20_FULL_1_VR.UnsettledFamilyDesc_F2d, 
                      dbo.MDS20_FULL_1_VR.UnsettledAbsence_F2e, dbo.MDS20_FULL_1_VR.UnsettledAbsenceDesc_F2e, dbo.MDS20_FULL_1_VR.UnsettledLoss_F2f, 
                      dbo.MDS20_FULL_1_VR.UnsettledLossDesc_F2f, dbo.MDS20_FULL_1_VR.UnsettledChange_F2g, dbo.MDS20_FULL_1_VR.UnsettledChangeDesc_F2g, 
                      dbo.MDS20_FULL_1_VR.UnsettledNone_F2h, dbo.MDS20_FULL_1_VR.UnsettledNoneDesc_F2h, dbo.MDS20_FULL_1_VR.PastRoleIden_F3a, 
                      dbo.MDS20_FULL_1_VR.PastRoleIdenDesc_F3a, dbo.MDS20_FULL_1_VR.PastRoleExpress_F3b, dbo.MDS20_FULL_1_VR.PastRoleExpressDesc_F3b, 
                      dbo.MDS20_FULL_1_VR.PastRolePerceive_F3c, dbo.MDS20_FULL_1_VR.PastRolePerceiveDesc_F3c, dbo.MDS20_Shared_2_VR.BedMobilitySelf_G1aA, 
                      dbo.MDS20_Shared_2_VR.BedMobilitySelfDesc_G1aA, dbo.MDS20_Shared_2_VR.BedMobilitySupport_G1aB, 
                      dbo.MDS20_Shared_2_VR.BedMobilitySupportDesc_G1aB, dbo.MDS20_Shared_2_VR.TransferSelf_G1bA, dbo.MDS20_Shared_2_VR.TransferSelfDesc_G1bA, 
                      dbo.MDS20_Shared_2_VR.TransferSupport_G1bB, dbo.MDS20_Shared_2_VR.TransferSupportDesc_G1bB, dbo.MDS20_Shared_2_VR.WalkInRoomSelf_G1cA, 
                      dbo.MDS20_Shared_2_VR.WalkInRoomSelfDesc_G1cA, dbo.MDS20_Shared_2_VR.WalkInRoomSupport_G1cB, 
                      dbo.MDS20_Shared_2_VR.WalkInRoomSupportDesc_G1cB, dbo.MDS20_Shared_2_VR.RorridorSelf_G1dA, dbo.MDS20_Shared_2_VR.RorridorSelfDesc_G1dA, 
                      dbo.MDS20_Shared_2_VR.RorridorSupport_G1dB, dbo.MDS20_Shared_2_VR.RorridorSupportDesc_G1dB, dbo.MDS20_Shared_2_VR.OnUnitSelf_G1eA, 
                      dbo.MDS20_Shared_2_VR.OnUnitSelfDesc_G1eA, dbo.MDS20_Shared_2_VR.OnUnitSupport_G1eB, dbo.MDS20_Shared_2_VR.OnUnitSupportDesc_G1eB, 
                      dbo.MDS20_Shared_2_VR.OffUnitSelf_G1fA, dbo.MDS20_Shared_2_VR.OffUnitSelfDesc_G1fA, dbo.MDS20_Shared_2_VR.OffUnitSupport_G1fB, 
                      dbo.MDS20_Shared_2_VR.OffUnitSupportDesc_G1fB, dbo.MDS20_Shared_2_VR.DressingSelf_G1gA, dbo.MDS20_Shared_2_VR.DressingSelfDesc_G1gA, 
                      dbo.MDS20_Shared_2_VR.DressingSupport_G1gB, dbo.MDS20_Shared_2_VR.DressingSupportDesc_G1gB, dbo.MDS20_Shared_2_VR.EatingSelf_G1hA, 
                      dbo.MDS20_Shared_2_VR.EatingSelfDesc_G1hA, dbo.MDS20_Shared_2_VR.EatingSupport_G1hB, dbo.MDS20_Shared_2_VR.EatingSupportDesc_G1hB, 
                      dbo.MDS20_Shared_2_VR.ToiletSelf_G1iA, dbo.MDS20_Shared_2_VR.ToiletSelfDesc_G1iA, dbo.MDS20_Shared_2_VR.ToiletSupport_G1iB, 
                      dbo.MDS20_Shared_2_VR.ToiletSupportDesc_G1iB, dbo.MDS20_Shared_2_VR.HygieneSelf_G1jA, dbo.MDS20_Shared_2_VR.HygieneSelfDesc_G1jA, 
                      dbo.MDS20_Shared_2_VR.HygieneSupport_G1jB, dbo.MDS20_Shared_2_VR.HygieneSupportDesc_G1jB, dbo.MDS20_Shared_2_VR.BathingSelf_G2A, 
                      dbo.MDS20_Shared_2_VR.BathingSelfDesc_G2A, dbo.MDS20_Shared_2_VR.BathingSupport_G2B, dbo.MDS20_Shared_2_VR.BathingSupportDesc_G2B, 
                      dbo.MDS20_Shared_2_VR.BalanceStanding_G3a, dbo.MDS20_Shared_2_VR.BalanceStandingDesc_G3a, dbo.MDS20_Shared_2_VR.BalanceSitting_G3b, 
                      dbo.MDS20_Shared_2_VR.BalanceSupportDesc_G3b, dbo.MDS20_Shared_2_VR.LimitRangeNeck_G4aA, 
                      dbo.MDS20_Shared_2_VR.LimitRangeNeckDesc_G4aA, dbo.MDS20_Shared_2_VR.LimitVoluntaryNeck_G4aB, 
                      dbo.MDS20_Shared_2_VR.LimitVoluntaryNeckDesc_G4aB, dbo.MDS20_Shared_2_VR.LimitRangeArm_G4bA, 
                      dbo.MDS20_Shared_2_VR.LimitRangeArmDesc_G4bA, dbo.MDS20_Shared_2_VR.LimitVoluntaryArm_G4bB, 
                      dbo.MDS20_Shared_2_VR.LimitVoluntaryArmDesc_G4bB, dbo.MDS20_Shared_2_VR.LimitRangeHand_G4cA, 
                      dbo.MDS20_Shared_2_VR.LimitRangeHandDesc_G4cA, dbo.MDS20_Shared_2_VR.LimitVoluntaryHand_G4cB, 
                      dbo.MDS20_Shared_2_VR.LimitVoluntaryHandDesc_G4cB, dbo.MDS20_Shared_2_VR.LimitRangeLeg_G4dA, 
                      dbo.MDS20_Shared_2_VR.LimitRangeLegDesc_G4dA, dbo.MDS20_Shared_2_VR.LimitVoluntaryLeg_G4dB, 
                      dbo.MDS20_Shared_2_VR.LimitVoluntaryLegDesc_G4dB, dbo.MDS20_Shared_2_VR.LimitRangeFoot_G4eA, 
                      dbo.MDS20_Shared_2_VR.LimitRangeFootDesc_G4eA, dbo.MDS20_Shared_2_VR.LimitVoluntaryFoot_G4eB, 
                      dbo.MDS20_Shared_2_VR.LimitVoluntaryFootDesc_G4eB, dbo.MDS20_Shared_2_VR.LimitRangeOther_G4fA, 
                      dbo.MDS20_Shared_2_VR.LimitRangeOtherDesc_G4fA, dbo.MDS20_Shared_2_VR.LimitVoluntaryOther_G4fB, 
                      dbo.MDS20_Shared_2_VR.LimitVoluntaryOtherDesc_G4fB, dbo.MDS20_FULL_1_VR.LocomotionWalker_G5a, 
                      dbo.MDS20_FULL_1_VR.LocomotionWalkerDesc_G5a, dbo.MDS20_FULL_1_VR.LocomotionWheelSelf_G5b, 
                      dbo.MDS20_FULL_1_VR.LocomotionWheelSelfDesc_G5b, dbo.MDS20_FULL_1_VR.LocomotionWheelOther_G5c, 
                      dbo.MDS20_FULL_1_VR.LocomotionWheelOtherDesc_G5c, dbo.MDS20_FULL_1_VR.LocomotionWheelChair_G5d, 
                      dbo.MDS20_FULL_1_VR.LocomotionWheelChairDesc_G5d, dbo.MDS20_FULL_1_VR.LocomotionNone_G5e, 
                      dbo.MDS20_FULL_1_VR.LocomotionNoneDesc_G5e, dbo.MDS20_Shared_2_VR.TransferBedfast_G6a, dbo.MDS20_Shared_2_VR.TransferBedfastDesc_G6a, 
                      dbo.MDS20_Shared_2_VR.TransferBedrail_G6b, dbo.MDS20_Shared_2_VR.TransferBedrailDesc_G6b, dbo.MDS20_Shared_2_VR.TransferManually_G6c, 
                      dbo.MDS20_Shared_2_VR.TransferManuallyDesc_G6c, dbo.MDS20_Shared_2_VR.TransferMechanically_G6d, 
                      dbo.MDS20_Shared_2_VR.TransferMechanicallyDesc_G6d, dbo.MDS20_Shared_2_VR.TransferAid_G6e, dbo.MDS20_Shared_2_VR.TransferAidDesc_G6e, 
                      dbo.MDS20_Shared_2_VR.TransferNone_G6f, dbo.MDS20_Shared_2_VR.TransferNoneDesc_G6f, dbo.MDS20_Shared_2_VR.Task_G7, 
                      dbo.MDS20_Shared_2_VR.TaskDesc_G7, dbo.MDS20_FULL_1_VR.ADL_Resident_G8a, dbo.MDS20_FULL_1_VR.ADL_ResidentDesc_G8a, 
                      dbo.MDS20_FULL_1_VR.ADL_Staff_G8b, dbo.MDS20_FULL_1_VR.ADL_StaffDesc_G8b, dbo.MDS20_FULL_1_VR.ADL_Slow_G8c, 
                      dbo.MDS20_FULL_1_VR.ADL_SlowDesc_G8c, dbo.MDS20_FULL_1_VR.ADL_Diff_G8d, dbo.MDS20_FULL_1_VR.ADL_DiffDesc_G8d, 
                      dbo.MDS20_FULL_1_VR.ADL_None_G8e, dbo.MDS20_FULL_1_VR.ADL_NoneDesc_G8e, dbo.MDS20_Shared_2_VR.ChangeADL_G9, 
                      dbo.MDS20_Shared_2_VR.ChangeADLDesc_G9, dbo.MDS20_Shared_2_VR.BowlContinence_H1a, dbo.MDS20_Shared_2_VR.BowlContinenceDesc_H1a, 
                      dbo.MDS20_Shared_2_VR.BladderContinence_H1b, dbo.MDS20_Shared_2_VR.BladderContinenceDesc_H1b, dbo.MDS20_Shared_2_VR.BowelRegular_H2a, 
                      dbo.MDS20_Shared_2_VR.BowelRegularDesc_H2a, dbo.MDS20_Shared_2_VR.BowelConstipation_H2b, 
                      dbo.MDS20_Shared_2_VR.BowelConstipationDesc_H2b, dbo.MDS20_Shared_2_VR.BowelDiarrhea_H2c, dbo.MDS20_Shared_2_VR.BowelDiarrheaDesc_H2c, 
                      dbo.MDS20_Shared_2_VR.BowelFecalImpaction_H2d, dbo.MDS20_Shared_2_VR.BowelFecalImpactionDesc_H2d, dbo.MDS20_Shared_2_VR.BowelNone_H2e, 
                      dbo.MDS20_Shared_2_VR.BowelNoneDesc_H2e, dbo.MDS20_Shared_2_VR.ApplianceScheduled_H3a, 
                      dbo.MDS20_Shared_2_VR.ApplianceScheduledDesc_H3a, dbo.MDS20_Shared_2_VR.ApplianceBladder_H3b, 
                      dbo.MDS20_Shared_2_VR.ApplianceBladderDesc_H3b, dbo.MDS20_Shared_2_VR.ApplianceExCatheter_H3c, 
                      dbo.MDS20_Shared_2_VR.ApplianceExCatheterDesc_H3c, dbo.MDS20_Shared_2_VR.ApplianceIndCatheter_H3d, 
                      dbo.MDS20_Shared_2_VR.ApplianceIndCatheterDesc_H3d, dbo.MDS20_Shared_2_VR.ApplianceIntCatheter_H3e, 
                      dbo.MDS20_Shared_2_VR.ApplianceIntCatheterDesc_H3e, dbo.MDS20_Shared_2_VR.ApplianceNotUse_H3f, 
                      dbo.MDS20_Shared_2_VR.ApplianceNotUseDesc_H3f, dbo.MDS20_Shared_2_VR.AppliancePads_H3g, dbo.MDS20_Shared_2_VR.AppliancePadsDesc_H3g, 
                      dbo.MDS20_Shared_2_VR.ApplianceIrrigation_H3h, dbo.MDS20_Shared_2_VR.ApplianceIrrigationDesc_H3h, dbo.MDS20_Shared_2_VR.ApplianceOstomy_H3i, 
                      dbo.MDS20_Shared_2_VR.ApplianceOstomyDesc_H3i, dbo.MDS20_Shared_2_VR.ApplianceNone_H3j, dbo.MDS20_Shared_2_VR.ApplianceNoneDesc_H3j, 
                      dbo.MDS20_Shared_2_VR.UrinaryContinence_H4, dbo.MDS20_Shared_2_VR.UrinaryContinenceDesc_H4
FROM         dbo.MDS20_VR LEFT OUTER JOIN
                      dbo.MDS20_FULL_1_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_FULL_1_VR.zzAbstractLink LEFT OUTER JOIN
                      dbo.MDS20_Shared_2_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Shared_2_VR.zzAbstractLink
WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''01'', ''02'', ''03'', ''04'')) AND 
                      (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)








' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_4_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[MDS20_FULL_Assessment_4_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.ReasonAssessment_AA8, 
                      dbo.MDS20_VR.ReasonAssessmentDesc_AA8, dbo.MDS20_Shared_3_VR.DiseaseDiabMellitus_I1a, 
                      dbo.MDS20_Shared_3_VR.DiseaseDiabMellitusDesc_I1a, dbo.MDS20_Shared_3_VR.DiseaseHyperthyroidism_I1b, 
                      dbo.MDS20_Shared_3_VR.DiseaseHyperthyroidDesc_I1b, dbo.MDS20_Shared_3_VR.DiseaseHypothyroidism_I1c, 
                      dbo.MDS20_Shared_3_VR.DiseaseHypothyroidismDesc_I1c, dbo.MDS20_Shared_3_VR.DiseaseASHD_I1d, dbo.MDS20_Shared_3_VR.DiseaseASHDDesc_I1d, 
                      dbo.MDS20_Shared_3_VR.DiseaseCardiac_I1e, dbo.MDS20_Shared_3_VR.DiseaseCardiacDesc_I1e, dbo.MDS20_Shared_3_VR.DiseaseCongestive_I1f, 
                      dbo.MDS20_Shared_3_VR.DiseaseCongestiveDesc_I1f, dbo.MDS20_Shared_3_VR.DiseaseThrombosis_I1g, 
                      dbo.MDS20_Shared_3_VR.DiseaseThrombosisDesc_I1g, dbo.MDS20_Shared_3_VR.DiseaseHypertension_I1h, 
                      dbo.MDS20_Shared_3_VR.DiseaseHypertensionDesc_I1h, dbo.MDS20_Shared_3_VR.DiseaseHypotension_I1i, 
                      dbo.MDS20_Shared_3_VR.DiseaseHypotensionDesc_I1i, dbo.MDS20_Shared_3_VR.DiseaseVascular_I1j, 
                      dbo.MDS20_Shared_3_VR.DiseaseVascularDesc_I1j, dbo.MDS20_Shared_3_VR.DiseaseCardiovascular_I1k, 
                      dbo.MDS20_Shared_3_VR.DiseaseCardiovascularDesc_I1k, dbo.MDS20_Shared_3_VR.DiseaseArthritis_I1l, 
                      dbo.MDS20_Shared_3_VR.DiseaseArthritisDesc_I1l, dbo.MDS20_Shared_3_VR.DiseaseHipFracture_I1m, 
                      dbo.MDS20_Shared_3_VR.DiseaseHipFractureDesc_I1m, dbo.MDS20_Shared_3_VR.DiseaseLimb_I1n, dbo.MDS20_Shared_3_VR.DiseaseLimbDesc_I1n, 
                      dbo.MDS20_Shared_3_VR.DiseaseOsteoporosis_I1o, dbo.MDS20_Shared_3_VR.DiseaseOsteoporosisDesc_I1o, 
                      dbo.MDS20_Shared_3_VR.DiseaseBoneFracture_I1p, dbo.MDS20_Shared_3_VR.DiseaseBoneFractureDesc_I1p, dbo.MDS20_Shared_3_VR.DiseaseALS_I1q, 
                      dbo.MDS20_Shared_3_VR.DiseaseALSDesc_I1q, dbo.MDS20_Shared_3_VR.DiseaseAlzheimer_I1r, dbo.MDS20_Shared_3_VR.DiseaseAlzheimerDesc_I1r, 
                      dbo.MDS20_Shared_3_VR.DiseaseAphasia_I1s, dbo.MDS20_Shared_3_VR.DiseaseAphasiaDesc_I1s, dbo.MDS20_Shared_3_VR.DiseaseCerebralPalsy_I1t, 
                      dbo.MDS20_Shared_3_VR.DiseaseCerebralPalsyDesc_I1t, dbo.MDS20_Shared_3_VR.DiseaseCerebro_I1u, 
                      dbo.MDS20_Shared_3_VR.DiseaseCerebroDesc_I1u, dbo.MDS20_Shared_3_VR.DiseaseDementia_I1v, dbo.MDS20_Shared_3_VR.DiseaseDementiaDesc_I1v, 
                      dbo.MDS20_Shared_3_VR.DiseaseHemiplegia_I1w, dbo.MDS20_Shared_3_VR.DiseaseHemiplegiaDesc_I1w, dbo.MDS20_Shared_3_VR.DiseaseChorea_I1x, 
                      dbo.MDS20_Shared_3_VR.DiseaseChoreaDesc_I1x, dbo.MDS20_Shared_3_VR.DiseaseSclerosis_I1y, dbo.MDS20_Shared_3_VR.DiseaseSclerosisDesc_I1y, 
                      dbo.MDS20_Shared_3_VR.DiseaseParaplegia_I1z, dbo.MDS20_Shared_3_VR.DiseaseParaplegiaDesc_I1z, dbo.MDS20_Shared_3_VR.DiseaseParkinson_I1aa, 
                      dbo.MDS20_Shared_3_VR.DiseaseParkinsonDesc_I1aa, dbo.MDS20_Shared_3_VR.DiseaseQuadriplegia_I1bb, 
                      dbo.MDS20_Shared_3_VR.DiseaseQuadriplegiaDesc_I1bb, dbo.MDS20_Shared_3_VR.DiseaseSeizureDisorder_I1cc, 
                      dbo.MDS20_Shared_3_VR.DiseaseSeizeDisorderDesc_I1cc, dbo.MDS20_Shared_3_VR.DiseaseIschemic_I1dd, 
                      dbo.MDS20_Shared_3_VR.DiseaseIschemicDesc_I1dd, dbo.MDS20_Shared_3_VR.DiseaseTraumaticBrain_I1ee, 
                      dbo.MDS20_Shared_3_VR.DiseaseTraumaBrainDesc_I1ee, dbo.MDS20_Shared_3_VR.DiseaseAnxietyDisorder_I1ff, 
                      dbo.MDS20_Shared_3_VR.DiseaseAnxietyDisDesc_I1ff, dbo.MDS20_Shared_3_VR.DiseaseDepression_I1gg, 
                      dbo.MDS20_Shared_3_VR.DiseaseDepressionDesc_I1gg, dbo.MDS20_Shared_3_VR.DiseaseManicDepressive_I1hh, 
                      dbo.MDS20_Shared_3_VR.DiseaseManicDepressDesc_I1hh, dbo.MDS20_Shared_3_VR.DiseaseSchizophrenia_I1ii, 
                      dbo.MDS20_Shared_3_VR.DiseaseSchizophreniaDesc_I1ii, dbo.MDS20_Shared_3_VR.DiseaseAsthma_I1jj, 
                      dbo.MDS20_Shared_3_VR.DiseaseAsthmaDesc_I1jj, dbo.MDS20_Shared_3_VR.DiseaseEmphysema_I1kk, 
                      dbo.MDS20_Shared_3_VR.DiseaseEmphysemaDesc_I1kk, dbo.MDS20_Shared_3_VR.DiseaseCatarats_I1ll, 
                      dbo.MDS20_Shared_3_VR.DiseaseCataratsDesc_I1ll, dbo.MDS20_Shared_3_VR.DiseaseDiabRetino_I1mm, 
                      dbo.MDS20_Shared_3_VR.DiseaseDiabRetinoDesc_I1mm, dbo.MDS20_Shared_3_VR.DiseaseGlaucoma_I1nn, 
                      dbo.MDS20_Shared_3_VR.DiseaseGlaucomaDesc_I1nn, dbo.MDS20_Shared_3_VR.DiseaseMacularDegenerate_I1oo, 
                      dbo.MDS20_Shared_3_VR.DiseaseMacularDegenDesc_I1oo, dbo.MDS20_Shared_3_VR.DiseaseAllergies_I1pp, 
                      dbo.MDS20_Shared_3_VR.DiseaseAllergiesDesc_I1pp, dbo.MDS20_Shared_3_VR.DiseaseAnemia_I1qq, dbo.MDS20_Shared_3_VR.DiseaseAnemiaDesc_I1qq, 
                      dbo.MDS20_Shared_3_VR.DiseaseCancer_I1rr, dbo.MDS20_Shared_3_VR.DiseaseCancerDesc_I1rr, dbo.MDS20_Shared_3_VR.DiseaseGastrointestinal_I1ss, 
                      dbo.MDS20_Shared_3_VR.DiseaseGastroDesc_I1ss, dbo.MDS20_Shared_3_VR.DiseaseLiver_I1tt, dbo.MDS20_Shared_3_VR.DiseaseLiverDesc_I1tt, 
                      dbo.MDS20_Shared_3_VR.DiseaseRenalFailure_I1uu, dbo.MDS20_Shared_3_VR.DiseaseRenalFailureDesc_I1uu, 
                      dbo.MDS20_Shared_3_VR.DiseaseNone_I1vv, dbo.MDS20_Shared_3_VR.DiseaseNoneDesc_I1vv, dbo.MDS20_Shared_3_VR.InfectionAntibiotic_I2a, 
                      dbo.MDS20_Shared_3_VR.InfectionAntibioticDesc_I2a, dbo.MDS20_Shared_3_VR.InfectionCellulitis_I2b, dbo.MDS20_Shared_3_VR.InfectionCellulitisDesc_I2b, 
                      dbo.MDS20_Shared_3_VR.InfectionClostridium_I2c, dbo.MDS20_Shared_3_VR.InfectionClostridiumDesc_I2c, 
                      dbo.MDS20_Shared_3_VR.InfectionConjunctivitis_I2d, dbo.MDS20_Shared_3_VR.InfectionConjunctivaDesc_I2d, dbo.MDS20_Shared_3_VR.InfectionHIV_I2e, 
                      dbo.MDS20_Shared_3_VR.InfectionHIVDesc_I2e, dbo.MDS20_Shared_3_VR.InfectionPneumonia_I2f, dbo.MDS20_Shared_3_VR.InfectionPneumoniaDesc_I2f, 
                      dbo.MDS20_Shared_3_VR.InfectionRespiratory_I2g, dbo.MDS20_Shared_3_VR.InfectionRespiratoryDesc_I2g, 
                      dbo.MDS20_Shared_3_VR.InfectionSepticemia_I2h, dbo.MDS20_Shared_3_VR.InfectionSepticemiaDesc_I2h, dbo.MDS20_Shared_3_VR.InfectionSexually_I2i, 
                      dbo.MDS20_Shared_3_VR.InfectionSexuallyDesc_I2i, dbo.MDS20_Shared_3_VR.InfectionTuberculosis_I2j, 
                      dbo.MDS20_Shared_3_VR.InfectionTuberculosisDesc_I2j, dbo.MDS20_Shared_3_VR.InfectionUrinary_I2k, dbo.MDS20_Shared_3_VR.InfectionUrinaryDesc_I2k, 
                      dbo.MDS20_Shared_3_VR.InfectionHepatitis_I2l, dbo.MDS20_Shared_3_VR.InfectionHepatitisDesc_I2l, dbo.MDS20_Shared_3_VR.InfectionWound_I2m, 
                      dbo.MDS20_Shared_3_VR.InfectionWoundDesc_I2m, dbo.MDS20_Shared_3_VR.InfectionNone_I2n, dbo.MDS20_Shared_3_VR.InfectionNoneDesc_I2n, 
                      dbo.MDS20_Shared_3_VR.ProblemWeight_J1a, dbo.MDS20_Shared_3_VR.ProblemWeightDesc_J1a, dbo.MDS20_Shared_3_VR.ProblemLieFlat_J1b, 
                      dbo.MDS20_Shared_3_VR.ProblemLieFlatDesc_J1b, dbo.MDS20_Shared_3_VR.ProblemDehydrated_J1c, 
                      dbo.MDS20_Shared_3_VR.ProblemDehydratedDesc_J1c, dbo.MDS20_Shared_3_VR.ProblemFluid_J1d, dbo.MDS20_Shared_3_VR.ProblemFluidDesc_J1d, 
                      dbo.MDS20_Shared_3_VR.ProblemDelusions_J1e, dbo.MDS20_Shared_3_VR.ProblemDelusionsDesc_J1e, dbo.MDS20_Shared_3_VR.ProblemDizziness_J1f, 
                      dbo.MDS20_Shared_3_VR.ProblemDizzinessDesc_J1f, dbo.MDS20_Shared_3_VR.ProblemEdema_J1g, dbo.MDS20_Shared_3_VR.ProblemEdemaDesc_J1g, 
                      dbo.MDS20_Shared_3_VR.ProblemFever_J1h, dbo.MDS20_Shared_3_VR.ProblemFeverDesc_J1h, dbo.MDS20_Shared_3_VR.ProblemHallucinations_J1i, 
                      dbo.MDS20_Shared_3_VR.ProblemHallucinationsDesc_J1i, dbo.MDS20_Shared_3_VR.ProblemBleeding_J1j, 
                      dbo.MDS20_Shared_3_VR.ProblemBleedingDesc_J1j, dbo.MDS20_Shared_3_VR.ProblemLung_J1k, dbo.MDS20_Shared_3_VR.ProblemLungDesc_J1k, 
                      dbo.MDS20_Shared_3_VR.ProblemBreath_J1l, dbo.MDS20_Shared_3_VR.ProblemBreathDesc_J1l, dbo.MDS20_Shared_3_VR.ProblemSyncope_J1m, 
                      dbo.MDS20_Shared_3_VR.ProblemSyncopeDesc_J1m, dbo.MDS20_Shared_3_VR.ProblemUnsteadyGait_J1n, 
                      dbo.MDS20_Shared_3_VR.ProblemUnsteadyGaitDesc_J1n, dbo.MDS20_Shared_3_VR.ProblemVomiting_J1o, 
                      dbo.MDS20_Shared_3_VR.ProblemVomitingDesc_J1o, dbo.MDS20_Shared_3_VR.ProblemNone_J1p, dbo.MDS20_Shared_3_VR.ProblemNoneDesc_J1p, 
                      dbo.MDS20_Shared_3_VR.Pain_Frequency_J2a, dbo.MDS20_Shared_3_VR.Pain_FrequencyDesc_J2a, dbo.MDS20_Shared_3_VR.Pain_Intensity_J2b, 
                      dbo.MDS20_Shared_3_VR.Pain_IntensityDesc_J2b, dbo.MDS20_FULL_1_VR.PainSiteBack_J3a, dbo.MDS20_FULL_1_VR.PainSiteBackDesc_J3a, 
                      dbo.MDS20_FULL_1_VR.PainSiteBone_J3b, dbo.MDS20_FULL_1_VR.PainSiteBoneDesc_J3b, dbo.MDS20_FULL_1_VR.PainSiteChest_J3c, 
                      dbo.MDS20_FULL_1_VR.PainSiteChestDesc_J3c, dbo.MDS20_FULL_1_VR.PainSiteHead_J3d, dbo.MDS20_FULL_1_VR.PainSiteHeadDesc_J3d, 
                      dbo.MDS20_FULL_1_VR.PainSiteHip_J3e, dbo.MDS20_FULL_1_VR.PainSiteHipDesc_J3e, dbo.MDS20_FULL_1_VR.PainSiteIncision_J3f, 
                      dbo.MDS20_FULL_1_VR.PainSiteIncisionDesc_J3f, dbo.MDS20_FULL_1_VR.PainSiteJoint_J3g, dbo.MDS20_FULL_1_VR.PainSiteJointDesc_J3g, 
                      dbo.MDS20_FULL_1_VR.PainSiteTissue_J3h, dbo.MDS20_FULL_1_VR.PainSiteTissueDesc_J3h, dbo.MDS20_FULL_1_VR.PainSiteStomach_J3i, 
                      dbo.MDS20_FULL_1_VR.PainSiteStomachDesc_J3i, dbo.MDS20_FULL_1_VR.PainSiteOther_J3j, dbo.MDS20_FULL_1_VR.PainSiteOtherDesc_J3j, 
                      dbo.MDS20_Shared_3_VR.AccidentFell30_J4a, dbo.MDS20_Shared_3_VR.AccidentFell30Desc_J4a, dbo.MDS20_Shared_3_VR.AccidentFell180_J4b, 
                      dbo.MDS20_Shared_3_VR.AccidentFell180Desc_J4b, dbo.MDS20_Shared_3_VR.AccidentHipFracture_J4c, 
                      dbo.MDS20_Shared_3_VR.AccidentHipFractureDesc_J4c, dbo.MDS20_Shared_3_VR.AccidentOtherFracture_J4d, 
                      dbo.MDS20_Shared_3_VR.AccidentOtherFractureDesc_J4d, dbo.MDS20_Shared_3_VR.AccidentNone_J4e, dbo.MDS20_Shared_3_VR.AccidentNoneDesc_J4e, 
                      dbo.MDS20_Shared_3_VR.Stability_Unstable_J5a, dbo.MDS20_Shared_3_VR.Stability_UnstableDesc_J5a, dbo.MDS20_Shared_3_VR.Stability_Acute_J5b, 
                      dbo.MDS20_Shared_3_VR.Stability_AcuteDesc_J5b, dbo.MDS20_Shared_3_VR.Stability_EndStage_J5c, 
                      dbo.MDS20_Shared_3_VR.Stability_EndStageDesc_J5c, dbo.MDS20_Shared_3_VR.Stability_None_J5d, 
                      dbo.MDS20_Shared_3_VR.Stability_None_Desc_J5d,
--Hobic     NP - 00099
    MDS20_Hobic_VR.Dyspnea, MDS20_Hobic_VR.Dyspneaesc,
    MDS20_Hobic_VR.Fatigue, MDS20_Hobic_VR.FatigueDesc,
    MDS20_Hobic_VR.Nausea,  MDS20_Hobic_VR.NauseaDesc
FROM         dbo.MDS20_VR LEFT OUTER JOIN
                      dbo.MDS20_Shared_3_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Shared_3_VR.zzAbstractLink LEFT OUTER JOIN
                      dbo.MDS20_FULL_1_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_FULL_1_VR.zzAbstractLink LEFT OUTER JOIN
--NP - 00099 
    dbo.MDS20_Hobic_VR on dbo.MDS20_VR.zzAbstractLink = MDS20_Hobic_VR.zzAbstractLink
WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''01'', ''02'', ''03'', ''04'')) AND 
                      (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)








' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_5_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[MDS20_FULL_Assessment_5_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.ReasonAssessment_AA8, 
                      dbo.MDS20_VR.ReasonAssessmentDesc_AA8, dbo.MDS20_Shared_4_VR.OralUnstable_K1a, dbo.MDS20_Shared_4_VR.OralUnstableDesc_K1a, 
                      dbo.MDS20_Shared_4_VR.OralAcute_K1b, dbo.MDS20_Shared_4_VR.OralAcuteDesc_K1b, dbo.MDS20_Shared_4_VR.OralEndStage_K1c, 
                      dbo.MDS20_Shared_4_VR.OralEndStageDesc_K1c, dbo.MDS20_Shared_4_VR.OralNone_K1d, dbo.MDS20_Shared_4_VR.OralDesc_K1d, 
                      dbo.MDS20_Shared_4_VR.Height_K2a, dbo.MDS20_Shared_4_VR.Weight_K2b, 
            dbo.MDS20_Shared_4_VR.WeightGain_K3b, dbo.MDS20_Shared_4_VR.WeightGainDesc_K3b, 
            dbo.MDS20_Shared_4_VR.WeightLoss_K3a, dbo.MDS20_Shared_4_VR.WeightLossDesc_K3a, 
                      dbo.MDS20_Shared_4_VR.Nutritional_Taste_K4a, dbo.MDS20_Shared_4_VR.Nutritional_TasteDesc_K4a, dbo.MDS20_Shared_4_VR.Nutritional_Hunger_K4b, 
                      dbo.MDS20_Shared_4_VR.Nutritional_HungerDesc_K4b, dbo.MDS20_Shared_4_VR.Nutritional_LeaveFood_K4c, 
                      dbo.MDS20_Shared_4_VR.Nutritional_LeaveFoodDesc_K4c, dbo.MDS20_Shared_4_VR.Nutritional_None_K4d, 
                      dbo.MDS20_Shared_4_VR.Nutritional_NoneDesc_K4d, dbo.MDS20_Shared_4_VR.NutritionalAppPatenteral_K5a, 
                      dbo.MDS20_Shared_4_VR.NutritionalAppPatentDesc_K5a, dbo.MDS20_Shared_4_VR.NutritionalAppFeedTube_K5b, 
                      dbo.MDS20_Shared_4_VR.NutritionalAppFeedTDesc_K5b, dbo.MDS20_Shared_4_VR.NutritionalAppDiet_K5c, 
                      dbo.MDS20_Shared_4_VR.NutritionalAppDietDesc_K5c, dbo.MDS20_Shared_4_VR.NutritionalAppSyringe_K5d, 
                      dbo.MDS20_Shared_4_VR.NutritionalAppSyringeDesc_K5d, dbo.MDS20_Shared_4_VR.NutritionalAppTherapeutic_K5e, 
                      dbo.MDS20_Shared_4_VR.NutritionalAppTherapeDesc_K5e, dbo.MDS20_Shared_4_VR.NutritionalAppSupplement_K5f, 
                      dbo.MDS20_Shared_4_VR.NutritionalAppSupplyDesc_K5f, dbo.MDS20_Shared_4_VR.NutritionalAppUtensil_K5g, 
                      dbo.MDS20_Shared_4_VR.NutritionalAppUtensilDesc_K5g, dbo.MDS20_Shared_4_VR.NutritionalAppWeight_K5h, 
                      dbo.MDS20_Shared_4_VR.NutritionalAppWeightDesc_K5h, dbo.MDS20_Shared_4_VR.NutritionalAppNone_K5i, 
                      dbo.MDS20_Shared_4_VR.NutritionalAppNoneDesc_K5i, dbo.MDS20_Shared_4_VR.ParenteralProportion_K6a, 
                      dbo.MDS20_Shared_4_VR.ParenteralProportionDesc_K6a, dbo.MDS20_Shared_4_VR.ParenteralAverage_K6b, 
                      dbo.MDS20_Shared_4_VR.ParenteralAverageDesc_K6b, dbo.MDS20_FULL_2_VR.OralDebris_L1a, dbo.MDS20_FULL_2_VR.OralDebrisDesc_L1a, 
                      dbo.MDS20_FULL_2_VR.OralDentures_L1b, dbo.MDS20_FULL_2_VR.OralDenturesDesc_L1b, dbo.MDS20_FULL_2_VR.OralLost_L1c, 
                      dbo.MDS20_FULL_2_VR.OralLostDesc_L1c, dbo.MDS20_FULL_2_VR.OralBroken_L1d, dbo.MDS20_FULL_2_VR.OralBrokenDesc_L1d, 
                      dbo.MDS20_FULL_2_VR.OralGum_L1e, dbo.MDS20_FULL_2_VR.OralGumDesc_L1e, dbo.MDS20_FULL_2_VR.OralCleaning_L1f, 
                      dbo.MDS20_FULL_2_VR.OralCleaningDesc_L1f, dbo.MDS20_FULL_2_VR.OralNone_L1g, dbo.MDS20_FULL_2_VR.OralNoneDesc_L1g, 
                      dbo.MDS20_Shared_4_VR.Ulcers_Stage1_M1a, dbo.MDS20_Shared_4_VR.Ulcers_Stage2_M1b, dbo.MDS20_Shared_4_VR.Ulcers_Stage3_M1c, 
                      dbo.MDS20_Shared_4_VR.Ulcers_Stage4_M1d, dbo.MDS20_Shared_4_VR.UlcerTypePressure_M2a, 
                      dbo.MDS20_Shared_4_VR.UlcerType_PressureDesc_M2a, dbo.MDS20_Shared_4_VR.UlcerType_Stasis_M2b, 
                      dbo.MDS20_Shared_4_VR.UlcerType_StasisDesc_M2b, dbo.MDS20_FULL_2_VR.ResolveUlcers_M3, dbo.MDS20_FULL_2_VR.ResolveUlcersDesc_M3, 
                      dbo.MDS20_Shared_4_VR.SkinAbrasions_M4a, dbo.MDS20_Shared_4_VR.SkinAbrasionsDesc_M4a, dbo.MDS20_Shared_4_VR.SkinBurn_M4b, 
                      dbo.MDS20_Shared_4_VR.SkinBurnDesc_M4b, dbo.MDS20_Shared_4_VR.SkinLesions_M4c, dbo.MDS20_Shared_4_VR.SkinLesionsDesc_M4c, 
                      dbo.MDS20_Shared_4_VR.SkinRashes_M4d, dbo.MDS20_Shared_4_VR.SkinRashesDesc_M4d, dbo.MDS20_Shared_4_VR.SkinDesensitized_M4e, 
                      dbo.MDS20_Shared_4_VR.SkinDesensitizedDesc_M4e, dbo.MDS20_Shared_4_VR.SkinTears_M4f, dbo.MDS20_Shared_4_VR.SkinTearsDesc_M4f, 
                      dbo.MDS20_Shared_4_VR.SkinSurgical_M4g, dbo.MDS20_Shared_4_VR.SkinSurgicalDesc_M4g, dbo.MDS20_Shared_4_VR.SkinNone_M4h, 
                      dbo.MDS20_Shared_4_VR.SkinNoneDesc_M4h, dbo.MDS20_Shared_4_VR.SkinTreat_Chair_M5a, dbo.MDS20_Shared_4_VR.SkinTreat_ChairDesc_M5a, 
                      dbo.MDS20_Shared_4_VR.SkinTreat_Bed_M5b, dbo.MDS20_Shared_4_VR.SkinTreat_BedDesc_M5b, dbo.MDS20_Shared_4_VR.SkinTreat_Turning_M5c, 
                      dbo.MDS20_Shared_4_VR.SkinTreat_TurningDesc_M5c, dbo.MDS20_Shared_4_VR.SkinTreat_Nutrition_M5d, 
                      dbo.MDS20_Shared_4_VR.SkinTreat_NutritionDesc_M5d, dbo.MDS20_Shared_4_VR.SkinTreat_Ulcer_M5e, 
                      dbo.MDS20_Shared_4_VR.SkinTreat_UlcerDesc_M5e, dbo.MDS20_Shared_4_VR.SkinTreat_Surgical_M5f, 
                      dbo.MDS20_Shared_4_VR.SkinTreat_SurgicalDesc_M5f, dbo.MDS20_Shared_4_VR.SkinTreat_Dressing_M5g, 
                      dbo.MDS20_Shared_4_VR.SkinTreat_DressingDesc_M5g, dbo.MDS20_Shared_4_VR.SkinTreat_Ointment_M5h, 
                      dbo.MDS20_Shared_4_VR.SkinTreat_OintmentDesc_M5h, dbo.MDS20_Shared_4_VR.SkinTreat_Other_M5i, 
                      dbo.MDS20_Shared_4_VR.SkinTreat_OtherDesc_M5i, dbo.MDS20_Shared_4_VR.SkinTreat_None_M5j, dbo.MDS20_Shared_4_VR.SkinTreat_NoneDesc_M5j, 
                      dbo.MDS20_Shared_4_VR.Foot_Problem_M6a, dbo.MDS20_Shared_4_VR.Foot_ProblemDesc_M6a, dbo.MDS20_Shared_4_VR.Foot_Infection_M6b, 
                      dbo.MDS20_Shared_4_VR.Foot_InfectionDesc_M6b, dbo.MDS20_Shared_4_VR.Foot_Lesion_M6c, dbo.MDS20_Shared_4_VR.Foot_LesionDesc_M6c, 
                      dbo.MDS20_Shared_4_VR.Foot_Nail_M6d, dbo.MDS20_Shared_4_VR.Foot_NailDesc_M6d, dbo.MDS20_Shared_4_VR.Foot_Preventative_M6e, 
                      dbo.MDS20_Shared_4_VR.Foot_PreventativeDesc_M6e, dbo.MDS20_Shared_4_VR.Foot_Dressing_M6f, dbo.MDS20_Shared_4_VR.Foot_DressingDesc_M6f, 
                      dbo.MDS20_Shared_4_VR.Foot_None_M6g, dbo.MDS20_Shared_4_VR.Foot_NoneDesc_M6g, dbo.MDS20_Shared_4_VR.Awake_Morning_N1a, 
                      dbo.MDS20_Shared_4_VR.Awake_MorningDesc_N1a, dbo.MDS20_Shared_4_VR.Awake_Afternoon_N1b, dbo.MDS20_Shared_4_VR.Awake_AfternoonDesc_N1b, 
                      dbo.MDS20_Shared_4_VR.Awake_Evening_N1c, dbo.MDS20_Shared_4_VR.Awake_EveningDesc_N1c, dbo.MDS20_Shared_4_VR.Awake_None_N1d, 
                      dbo.MDS20_Shared_4_VR.Awake_NoneDesc_N1d, dbo.MDS20_Shared_4_VR.AverageTime_N2, dbo.MDS20_Shared_4_VR.AverageTimeDesc_N2, 
                      dbo.MDS20_FULL_2_VR.ActSetOwn_N3a, dbo.MDS20_FULL_2_VR.ActSetOwnDesc_N3a, dbo.MDS20_FULL_2_VR.ActSetDay_N3b, 
                      dbo.MDS20_FULL_2_VR.ActSetDayDesc_N3b, dbo.MDS20_FULL_2_VR.ActSetInside_N3c, dbo.MDS20_FULL_2_VR.ActSetInsideDesc_N3c, 
                      dbo.MDS20_FULL_2_VR.ActSetOutside_N3d, dbo.MDS20_FULL_2_VR.ActSetOutsideDesc_N3d, dbo.MDS20_FULL_2_VR.ActSetNone_N3e, 
                      dbo.MDS20_FULL_2_VR.ActSetNoneDesc_N3e, dbo.MDS20_FULL_2_VR.ActPreferCards_N4a, dbo.MDS20_FULL_2_VR.ActPreferCardsDesc_N4a, 
                      dbo.MDS20_FULL_2_VR.ActPreferCrafts_N4b, dbo.MDS20_FULL_2_VR.ActPreferCraftsDesc_N4b, dbo.MDS20_FULL_2_VR.ActPreferSports_N4c, 
                      dbo.MDS20_FULL_2_VR.ActPreferSportsDesc_N4c, dbo.MDS20_FULL_2_VR.ActPreferMusic_N4d, dbo.MDS20_FULL_2_VR.ActPreferMusicDesc_N4d, 
                      dbo.MDS20_FULL_2_VR.ActPreferReading_N4e, dbo.MDS20_FULL_2_VR.ActPreferReadingDesc_N4e, dbo.MDS20_FULL_2_VR.ActPreferReligious_N4f, 
                      dbo.MDS20_FULL_2_VR.ActPreferReligiousDesc_N4f, dbo.MDS20_FULL_2_VR.ActPreferShopping_N4g, dbo.MDS20_FULL_2_VR.ActPreferShoppingDesc_N4g, 
                      dbo.MDS20_FULL_2_VR.ActPreferWalk_N4h, dbo.MDS20_FULL_2_VR.ActPreferWalkDesc_N4h, dbo.MDS20_FULL_2_VR.ActPreferTV_N4i, 

                      dbo.MDS20_FULL_2_VR.ActPreferTVDesc_N4i, dbo.MDS20_FULL_2_VR.ActPreferGarden_N4j, dbo.MDS20_FULL_2_VR.ActPreferGardenDesc_N4j, 
                      dbo.MDS20_FULL_2_VR.ActPreferTalking_N4k, dbo.MDS20_FULL_2_VR.ActPreferTalkingDesc_N4k, dbo.MDS20_FULL_2_VR.ActPreferHelping_N4l, 
                      dbo.MDS20_FULL_2_VR.ActPreferHelpingDesc_N4l, dbo.MDS20_FULL_2_VR.ActPreferNone_N4m, dbo.MDS20_FULL_2_VR.ActPreferNoneDesc_N4m, 
                      dbo.MDS20_FULL_2_VR.PreferChangeType_N5a, dbo.MDS20_FULL_2_VR.PreferChangeTypeDesc_N5a, dbo.MDS20_FULL_2_VR.PreferChangeExtent_N5b, 
                      dbo.MDS20_FULL_2_VR.PreferChangeExtentDesc_N5b, dbo.MDS20_Shared_4_VR.NumberMedication_O1, dbo.MDS20_FULL_2_VR.NewMedication_O2, 
                      dbo.MDS20_FULL_2_VR.NewMedicationDesc_O2, dbo.MDS20_Shared_4_VR.Injection_O3, dbo.MDS20_Shared_4_VR.Days_Antipsychotic_O4a, 
                      dbo.MDS20_Shared_4_VR.Days_Antianxiety_O4b, dbo.MDS20_Shared_4_VR.Days_Antidepressant_O4c, dbo.MDS20_Shared_4_VR.Days_Hypnotic_O4d, 
                      dbo.MDS20_Shared_4_VR.Days_Diuretic_O4e, dbo.MDS20_Shared_4_VR.Days_Analgesic_O4f
FROM         dbo.MDS20_VR LEFT OUTER JOIN
                      dbo.MDS20_FULL_2_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_FULL_2_VR.zzAbstractLink LEFT OUTER JOIN
                      dbo.MDS20_Shared_4_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Shared_4_VR.zzAbstractLInk
WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''01'', ''02'', ''03'', ''04'')) AND 
                      (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_6_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'






CREATE VIEW [dbo].[MDS20_FULL_Assessment_6_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.ReasonAssessment_AA8, 
                      dbo.MDS20_VR.ReasonAssessmentDesc_AA8, dbo.MDS20_Shared_5_VR.SpecialChemotherapy_P1aa, 
                      dbo.MDS20_Shared_5_VR.SpecialChemotherapyDesc_P1aa, dbo.MDS20_Shared_5_VR.SpecialDialysis_P1ab, 
                      dbo.MDS20_Shared_5_VR.SpecialDialysisDesc_P1ab, dbo.MDS20_Shared_5_VR.SpecialIV_P1ac, dbo.MDS20_Shared_5_VR.SpecialIVDesc_P1ac, 
                      dbo.MDS20_Shared_5_VR.SpecialIntake_P1ad, dbo.MDS20_Shared_5_VR.SpecialIntakeDesc_P1ad, dbo.MDS20_Shared_5_VR.SpecialMonitor_P1ae, 
                      dbo.MDS20_Shared_5_VR.SpecialMonitorDesc_P1ae, dbo.MDS20_Shared_5_VR.SpecialOstomy_P1af, dbo.MDS20_Shared_5_VR.SpecialOstomyDesc_P1af, 
                      dbo.MDS20_Shared_5_VR.SpecialOxygen_P1ag, dbo.MDS20_Shared_5_VR.SpecialOxygenDesc_P1ag, dbo.MDS20_Shared_5_VR.SpecialRadiation_P1ah, 
                      dbo.MDS20_Shared_5_VR.SpecialRadiationDesc_P1ah, dbo.MDS20_Shared_5_VR.SpecialSuction_P1ai, dbo.MDS20_Shared_5_VR.SpecialSuctionDesc_P1ai, 
                      dbo.MDS20_Shared_5_VR.SpecialTrash_P1aj, dbo.MDS20_Shared_5_VR.SpecialTrashDesc_P1aj, dbo.MDS20_Shared_5_VR.SpecialTransfusion_P1ak, 
                      dbo.MDS20_Shared_5_VR.SpecialTransfusionDesc_P1ak, dbo.MDS20_Shared_5_VR.SpecialVentilator_P1al, 
                      dbo.MDS20_Shared_5_VR.SpecialVentilatorDesc_P1al, dbo.MDS20_Shared_5_VR.SpecialAlcohol_P1am, dbo.MDS20_Shared_5_VR.SpecialAlcoholDesc_P1am, 
                      dbo.MDS20_Shared_5_VR.SpecialAlzheimer_P1an, dbo.MDS20_Shared_5_VR.SpecialAlzheimerDesc_P1an, dbo.MDS20_Shared_5_VR.SpecialHospice_P1ao, 
                      dbo.MDS20_Shared_5_VR.SpecialHospiceDesc_P1ao, dbo.MDS20_Shared_5_VR.SpecialPediatric_P1ap, 
                      dbo.MDS20_Shared_5_VR.SpecialPediatricDesc_P1ap, dbo.MDS20_Shared_5_VR.SpecialRespite_P1aq, dbo.MDS20_Shared_5_VR.SpecialRespiteDesc_P1aq, 
                      dbo.MDS20_Shared_5_VR.SpecialTraining_P1ar, dbo.MDS20_Shared_5_VR.SpecialTrainingDesc_P1ar, dbo.MDS20_Shared_5_VR.SpecialNone_P1as, 
                      dbo.MDS20_Shared_5_VR.SpecialNoneDesc_P1as, dbo.MDS20_Shared_5_VR.TherapySpeechDay_P1baA, 
                      dbo.MDS20_Shared_5_VR.TherapySpeechMinute_P1baB, dbo.MDS20_Shared_5_VR.TherapyOccupationDay_P1bbA, 
                      dbo.MDS20_Shared_5_VR.TherapyOccupationMinute_P1bbB, dbo.MDS20_Shared_5_VR.TherapyPhysicalDay_P1bcA, 
                      dbo.MDS20_Shared_5_VR.TherapyPhysicalMinute_P1bcB, dbo.MDS20_Shared_5_VR.TherapyRespiratoryDay_P1bdA, 
                      dbo.MDS20_Shared_5_VR.TherapyRespiratoryMin_P1bdB, dbo.MDS20_Shared_5_VR.TherapyPsychologicalDay_P1beA, 
                      dbo.MDS20_Shared_5_VR.TherapyPsychologicalMin_P1beB, dbo.MDS20_Shared_5_VR.TherapyRecreationDay_P1bfA, 
                      dbo.MDS20_Shared_5_VR.TherapyRecreationMinute_P1bfB, dbo.MDS20_FULL_2_VR.IntervSpecial_P2a, dbo.MDS20_FULL_2_VR.IntervSpecialDesc_P2a, 
                      dbo.MDS20_FULL_2_VR.IntervSpecialist_P2b, dbo.MDS20_FULL_2_VR.IntervSpecialistDesc_P2b, dbo.MDS20_FULL_2_VR.IntervGroup_P2c, 
                      dbo.MDS20_FULL_2_VR.IntervGroupDesc_P2c, dbo.MDS20_FULL_2_VR.IntervChange_P2d, dbo.MDS20_FULL_2_VR.IntervChangeDesc_P2d, 
                      dbo.MDS20_FULL_2_VR.IntervReorientation_P2e, dbo.MDS20_FULL_2_VR.IntervReorientationDesc_P2e, dbo.MDS20_FULL_2_VR.IntervNone_P2f, 
                      dbo.MDS20_FULL_2_VR.IntervNoneDesc_P2f, dbo.MDS20_Shared_5_VR.RehabPassive_P3a, dbo.MDS20_Shared_5_VR.RehabActive_P3b, 
                      dbo.MDS20_Shared_5_VR.RehabSplint_P3c, dbo.MDS20_Shared_5_VR.RehabBed_P3d, dbo.MDS20_Shared_5_VR.RehabTransfer_P3e, 
                      dbo.MDS20_Shared_5_VR.RehabWalking_P3f, dbo.MDS20_Shared_5_VR.RehabDressing_P3g, dbo.MDS20_Shared_5_VR.RehabEating_P3h, 
                      dbo.MDS20_Shared_5_VR.RehabAmputation_P3i, dbo.MDS20_Shared_5_VR.RehabCommunication_P3j, dbo.MDS20_Shared_5_VR.RehabOther_P3k, 
                      dbo.MDS20_Shared_5_VR.DeviceFullBed_P4a, dbo.MDS20_Shared_5_VR.DeviceFullBedDesc_P4a, dbo.MDS20_Shared_5_VR.DeviceOther_P4b, 
                      dbo.MDS20_Shared_5_VR.DeviceOtherDesc_P4b, dbo.MDS20_Shared_5_VR.DeviceTrunk_P4c, dbo.MDS20_Shared_5_VR.DeviceTrunkDesc_P4c, 
                      dbo.MDS20_Shared_5_VR.DeviceLimb_P4d, dbo.MDS20_Shared_5_VR.DeviceLimbDesc_P4d, dbo.MDS20_Shared_5_VR.DeviceChair_P4e, 
                      dbo.MDS20_Shared_5_VR.DeviceChairDesc_P4e, dbo.MDS20_FULL_2_VR.HospitalStay_P5, dbo.MDS20_FULL_2_VR.EmergencyRoom_P6, 
                      dbo.MDS20_Shared_5_VR.PhysicianVisit_P7, dbo.MDS20_Shared_5_VR.PhysicianOrder_P8, dbo.MDS20_FULL_2_VR.AbnormalLabValues_P9, 
                      dbo.MDS20_FULL_2_VR.AbnormalLabValuesDesc_P9, dbo.MDS20_FULL_2_VR.DischargeExpress_Q1a, dbo.MDS20_FULL_2_VR.DischargeExpressDesc_Q1a, 
                      dbo.MDS20_FULL_2_VR.DischargeSupport_Q1b, dbo.MDS20_FULL_2_VR.DischargeSupportDesc_Q1b, dbo.MDS20_FULL_2_VR.DischargeProject_Q1c, 
                      dbo.MDS20_FULL_2_VR.DischargeProjectDesc_Q1c, dbo.MDS20_Shared_5_VR.OverallChange_Q2, dbo.MDS20_Shared_5_VR.OverallChangeDesc_Q2, 
                      dbo.MDS20_FULL_2_VR.ParticipationResident_R1a, dbo.MDS20_FULL_2_VR.ParticipationResidentDesc_R1a, 
                      dbo.MDS20_FULL_2_VR.ParticipationFamily_R1b, dbo.MDS20_FULL_2_VR.ParticipationFamilyDesc_R1b, dbo.MDS20_FULL_2_VR.ParticipationOther_R1c, 
                      dbo.MDS20_FULL_2_VR.ParticipationOtherDesc_R1c, dbo.MDS20_Shared_5_VR.CompleteDate_R2b
FROM         dbo.MDS20_VR LEFT OUTER JOIN
                      dbo.MDS20_Shared_5_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Shared_5_VR.zzAbstractLink LEFT OUTER JOIN
                      dbo.MDS20_FULL_2_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_FULL_2_VR.zzAbstractLink
WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''01'', ''02'', ''03'', ''04'')) AND 
                      (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)








' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_Diagnosis_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'




CREATE VIEW [dbo].[MDS20_FULL_Assessment_Diagnosis_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.ReasonAssessment_AA8, dbo.MDS20_VR.ReasonAssessmentDesc_AA8, 
                      dbo.MDS20_Diagnosis_VR.Diagnosis_I3a, dbo.MDS20_Diagnosis_VR.DiagnosisDesc_I3a, dbo.MDS20_Diagnosis_VR.DiagnosisShortDesc_I3a, 
                      dbo.MDS20_Diagnosis_VR.Diagnosis_I3b, dbo.MDS20_Diagnosis_VR.DiagnosisDesc_I3b, dbo.MDS20_Diagnosis_VR.DiagnosisShortDesc_I3b, 
                      dbo.MDS20_Diagnosis_VR.Diagnosis_I3c, dbo.MDS20_Diagnosis_VR.DiagnosisDesc_I3c, dbo.MDS20_Diagnosis_VR.DiagnosisShortDesc_I3c, 
                      dbo.MDS20_Diagnosis_VR.Diagnosis_I3d, dbo.MDS20_Diagnosis_VR.DiagnosisDesc_I3d, dbo.MDS20_Diagnosis_VR.DiagnosisShortDesc_I3d, 
                      dbo.MDS20_Diagnosis_VR.Diagnosis_I3e, dbo.MDS20_Diagnosis_VR.DiagnosisDesc_I3e, dbo.MDS20_Diagnosis_VR.DiagnosisShortDesc_I3e, 
                      dbo.MDS20_Diagnosis_VR.Diagnosis_I3f, dbo.MDS20_Diagnosis_VR.DiagnosisDesc_I3f, dbo.MDS20_Diagnosis_VR.DiagnosisShortDesc_I3f
FROM         dbo.MDS20_VR LEFT OUTER JOIN
                      dbo.MDS20_Diagnosis_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Diagnosis_VR.zzAbstractLink
WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''01'', ''02'', ''03'', ''04'')) AND (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_Medication_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'






CREATE VIEW [dbo].[MDS20_FULL_Assessment_Medication_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.ReasonAssessment_AA8, 
                      dbo.MDS20_VR.ReasonAssessmentDesc_AA8, dbo.MDS20_Medication_VR.MedicationOccurrence, dbo.MDS20_Medication_VR.MedicationName_U1, 
                      dbo.MDS20_Medication_VR.Route_Administration_U2, dbo.MDS20_Medication_VR.Route_AdministrationDesc_U2, dbo.MDS20_Medication_VR.Frequency_U3, 
                      dbo.MDS20_Medication_VR.FrequencyDesc_U3, dbo.MDS20_Medication_VR.AmountAdministered_U4, dbo.MDS20_Medication_VR.Doses_U5, 
                      dbo.MDS20_Medication_VR.DIN_U6
FROM         dbo.MDS20_VR LEFT OUTER JOIN
                      dbo.MDS20_Medication_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Medication_VR.zzAbstractLink
WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''01'', ''02'', ''03'', ''04'')) AND 
                      (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)







' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_RAP_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[MDS20_FULL_Assessment_RAP_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.ReasonAssessment_AA8, dbo.MDS20_VR.ReasonAssessmentDesc_AA8, 
                      dbo.MDS20_RAP_VR.RAP_01_Delirium, dbo.MDS20_RAP_VR.RAP_01_DeliriumDesc, dbo.MDS20_RAP_VR.RAP_01_DeliriumNotes, 
                      dbo.MDS20_RAP_VR.RAP_01_DeliriumNotesLogDate, dbo.MDS20_RAP_VR.RAP_01_DeliriumNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_01_DeliriumNotesLogCoder, dbo.MDS20_RAP_VR.RAP_01_DeliriumNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_02_Cognitive, dbo.MDS20_RAP_VR.RAP_02_CognitiveDesc, dbo.MDS20_RAP_VR.RAP_02_CognitiveNotes, 
                      dbo.MDS20_RAP_VR.RAP_02_CognitiveNotesLogDate, dbo.MDS20_RAP_VR.RAP_02_CognitiveNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_02_CognitiveNotesLogCoder, dbo.MDS20_RAP_VR.RAP_02_CognitiveNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_03_Visual, dbo.MDS20_RAP_VR.RAP_03_VisualDesc, dbo.MDS20_RAP_VR.RAP_03_VisualNotes, 
                      dbo.MDS20_RAP_VR.RAP_03_VisualNotesLogDate, dbo.MDS20_RAP_VR.RAP_03_VisualNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_03_VisualNotesLogCoder, dbo.MDS20_RAP_VR.RAP_03_VisualNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_04_Communication, dbo.MDS20_RAP_VR.RAP_04_CommunicationDesc, 
                      dbo.MDS20_RAP_VR.RAP_04_CommunicationNotes, dbo.MDS20_RAP_VR.RAP_04_CommunicationNotesLogDate, 
                      dbo.MDS20_RAP_VR.RAP_04_CommunicationNotesLogTime, dbo.MDS20_RAP_VR.RAP_04_CommunicationNotesLogCoder, 
                      dbo.MDS20_RAP_VR.RAP_04_CommunicationNotesLogCoderDesc, dbo.MDS20_RAP_VR.RAP_05_ADL_Function, 
                      dbo.MDS20_RAP_VR.RAP_05_ADL_FunctionDesc, dbo.MDS20_RAP_VR.RAP_05_ADL_FunctionNotes, 
                      dbo.MDS20_RAP_VR.RAP_05_ADL_FunctionNotesLogDate, dbo.MDS20_RAP_VR.RAP_05_ADL_FunctionNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_05_ADL_FunctionNotesLogCoder, dbo.MDS20_RAP_VR.RAP_05_ADL_FunctionNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_06_Urinary, dbo.MDS20_RAP_VR.RAP_06_UrinaryDesc, dbo.MDS20_RAP_VR.RAP_06_UrinaryNotes, 
                      dbo.MDS20_RAP_VR.RAP_06_UrinaryNotesLogDate, dbo.MDS20_RAP_VR.RAP_06_UrinaryNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_06_UrinaryNotesLogCoder, dbo.MDS20_RAP_VR.RAP_06_UrinaryNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_07_Psychosocial, dbo.MDS20_RAP_VR.RAP_07_PsychosocialDesc, dbo.MDS20_RAP_VR.RAP_07_PsychosocialNotes, 
                      dbo.MDS20_RAP_VR.RAP_07_PsychosocialNotesLogDate, dbo.MDS20_RAP_VR.RAP_07_PsychosocialNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_07_PsychosocialNotesLogCoder, dbo.MDS20_RAP_VR.RAP_07_PsychosocialNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_08_Mood, dbo.MDS20_RAP_VR.RAP_08_MoodDesc, dbo.MDS20_RAP_VR.RAP_08_MoodNotes, 
                      dbo.MDS20_RAP_VR.RAP_08_MoodNotesLogDate, dbo.MDS20_RAP_VR.RAP_08_MoodNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_08_MoodNotesLogCoder, dbo.MDS20_RAP_VR.RAP_08_MoodNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_09_Behavioural, dbo.MDS20_RAP_VR.RAP_09_BehaviouralDesc, dbo.MDS20_RAP_VR.RAP_09_BehaviouralNotes, 
                      dbo.MDS20_RAP_VR.RAP_09_BehaviouralNotesLogDate, dbo.MDS20_RAP_VR.RAP_09_BehaviouralNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_09_BehaviouralNotesLogCoder, dbo.MDS20_RAP_VR.RAP_09_BehaviouralNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_10_Activities, dbo.MDS20_RAP_VR.RAP_10_ActivitiesDesc, dbo.MDS20_RAP_VR.RAP_10_ActivitiesNotes, 
                      dbo.MDS20_RAP_VR.RAP_10_ActivitiesNotesLogDate, dbo.MDS20_RAP_VR.RAP_10_ActivitiesNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_10_ActivitiesNotesLogCoder, dbo.MDS20_RAP_VR.RAP_10_ActivitiesNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_11_Falls, dbo.MDS20_RAP_VR.RAP_11_FallsDesc, dbo.MDS20_RAP_VR.RAP_11_FallsNotes, 
                      dbo.MDS20_RAP_VR.RAP_11_FallsNotesLogDate, dbo.MDS20_RAP_VR.RAP_11_FallsNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_11_FallsNotesLogCoder, dbo.MDS20_RAP_VR.RAP_11_FallsNotesLogCoderDesc, dbo.MDS20_RAP_VR.RAP_12_Nutritional,
                       dbo.MDS20_RAP_VR.RAP_12_NutritionalDesc, dbo.MDS20_RAP_VR.RAP_12_NutritionalNotes, 
                      dbo.MDS20_RAP_VR.RAP_12_NutritionalNotesLogDate, dbo.MDS20_RAP_VR.RAP_12_NutritionalNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_12_NutritionalNotesLogCoder, dbo.MDS20_RAP_VR.RAP_12_NutritionalNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_13_Feeding, dbo.MDS20_RAP_VR.RAP_13_FeedingDesc, dbo.MDS20_RAP_VR.RAP_13_FeedingNotes, 
                      dbo.MDS20_RAP_VR.RAP_13_FeedingNotesLogDate, dbo.MDS20_RAP_VR.RAP_13_FeedingNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_13_FeedingNotesLogCoder, dbo.MDS20_RAP_VR.RAP_13_FeedingNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_14_Dehydration, dbo.MDS20_RAP_VR.RAP_14_DehydrationDesc, dbo.MDS20_RAP_VR.RAP_14_DehydrationNotes, 
                      dbo.MDS20_RAP_VR.RAP_14_DehydrationNotesLogDate, dbo.MDS20_RAP_VR.RAP_14_DehydrationNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_14_DehydrationNotesLogCoder, dbo.MDS20_RAP_VR.RAP_14_DehydrationNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_15_Dental, dbo.MDS20_RAP_VR.RAP_15_DentalDesc, dbo.MDS20_RAP_VR.RAP_15_DentalNotes, 
                      dbo.MDS20_RAP_VR.RAP_15_DentalNotesLogDate, dbo.MDS20_RAP_VR.RAP_15_DentalNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_15_DentalNotesLogCoder, dbo.MDS20_RAP_VR.RAP_15_DentalNotesLogCoderDesc, dbo.MDS20_RAP_VR.RAP_16_Ulcers, 
                      dbo.MDS20_RAP_VR.RAP_16_UlcersDesc, dbo.MDS20_RAP_VR.RAP_16_UlcersNotes, dbo.MDS20_RAP_VR.RAP_16_UlcersNotesLogDate, 
                      dbo.MDS20_RAP_VR.RAP_16_UlcersNotesLogTime, dbo.MDS20_RAP_VR.RAP_16_UlcersNotesLogCoder, 
                      dbo.MDS20_RAP_VR.RAP_16_UlcersNotesLogCoderDesc, dbo.MDS20_RAP_VR.RAP_17_Drugs, dbo.MDS20_RAP_VR.RAP_17_DrugsDesc, 
                      dbo.MDS20_RAP_VR.RAP_17_DrugsNotes, dbo.MDS20_RAP_VR.RAP_17_DrugsNotesLogDate, dbo.MDS20_RAP_VR.RAP_17_DrugsNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_17_DrugsNotesLogCoder, dbo.MDS20_RAP_VR.RAP_17_DrugsNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_18_Restraints, dbo.MDS20_RAP_VR.RAP_18_RestraintsDesc, dbo.MDS20_RAP_VR.RAP_18_RestraintsNotes, 
                      dbo.MDS20_RAP_VR.RAP_18_RestraintsNotesLogDate, dbo.MDS20_RAP_VR.RAP_18_RestraintsNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_18_RestraintsNotesLogCoder, dbo.MDS20_RAP_VR.RAP_18_RestraintsNotesLogCoderDesc
FROM         dbo.MDS20_VR LEFT OUTER JOIN
                      dbo.MDS20_RAP_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_RAP_VR.zzAbstractLink
WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''01'', ''02'', ''03'', ''04'')) AND (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_Rugs_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[MDS20_FULL_Assessment_Rugs_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.ReasonAssessment_AA8, 
                      dbo.MDS20_VR.ReasonAssessmentDesc_AA8, dbo.MDS20_RUGS_VR.RUG_Group1, dbo.MDS20_RUGS_VR.CMI_Weight1, 
                      dbo.MDS20_RUGS_VR.RUG_Description1, dbo.MDS20_RUGS_VR.RUG_Group2, dbo.MDS20_RUGS_VR.CMI_Weight2, dbo.MDS20_RUGS_VR.RUG_Description2, 
                      dbo.MDS20_RUGS_VR.ADL
FROM         dbo.MDS20_RUGS_VR RIGHT OUTER JOIN
                      dbo.MDS20_VR ON dbo.MDS20_RUGS_VR.zzAbstractLink = dbo.MDS20_VR.zzAbstractLink
WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''01'', ''02'', ''03'', ''04'')) AND 
                      (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_FULL_Assessment_Signature_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'






CREATE VIEW [dbo].[MDS20_FULL_Assessment_Signature_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.ReasonAssessment_AA8, 
                      dbo.MDS20_VR.ReasonAssessmentDesc_AA8, dbo.MDS20_Signature_VR.ProviderOccurrence, dbo.MDS20_Signature_VR.SignDate, 
                      dbo.MDS20_Signature_VR.Signature, dbo.MDS20_Signature_VR.Signature_Desc, dbo.MDS20_Signature_VR.ProviderServiceType, 
                      dbo.MDS20_Signature_VR.ProviderServiceType_Desc
FROM         dbo.MDS20_VR LEFT OUTER JOIN
                      dbo.MDS20_Signature_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Signature_VR.zzAbstractLink
WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''01'', ''02'', ''03'', ''04'')) AND 
                      (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)








' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Hobic_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE  VIEW [dbo].[MDS20_Hobic_Form_VR]
AS
SELECT  dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.zzLinkBackgroundID, 
        dbo.MDS20_VR.HealthRecordNumber_A6a, dbo.MDS20_VR.Birthdate_AA3a, 
        dbo.MDS20_VR.ReasonAssessment_AA8, dbo.MDS20_VR.ReasonAssessmentDesc_AA8,
        dbo.MDS20_VR.AdmissionDate_AB1, dbo.MDS20_VR.URI_AA1, 
        dbo.MDS20_VR.FacilityNumber_AA6, dbo.MDS20_VR.FacilityNumberDesc_AA6, 
        dbo.MDS20_VR.RecordType_Z1, dbo.MDS20_VR.RecordTypeDesc_Z1,
        dbo.MDS20_Shared_2_VR.BedMobilitySelf_G1aA, dbo.MDS20_Shared_2_VR.BedMobilitySelfDesc_G1aA, 
        dbo.MDS20_Shared_2_VR.TransferSelf_G1bA, dbo.MDS20_Shared_2_VR.TransferSelfDesc_G1bA,
        dbo.MDS20_Shared_2_VR.WalkInRoomSelf_G1cA, dbo.MDS20_Shared_2_VR.WalkInRoomSelfDesc_G1cA, 
        dbo.MDS20_Shared_2_VR.RorridorSelf_G1dA AS WalkInCorridorSelf_G1dA, 
        dbo.MDS20_Shared_2_VR.RorridorSelfDesc_G1dA AS WalkInCorridorSelfDesc_G1dA, 
        dbo.MDS20_Shared_2_VR.OnUnitSelf_G1eA AS LocomotionOnUnitSelf_G1eA, 
        dbo.MDS20_Shared_2_VR.OnUnitSelfDesc_G1eA AS LocomotionOnUnitSelfDesc_G1eA, 
        dbo.MDS20_Shared_2_VR.DressingSelf_G1gA, dbo.MDS20_Shared_2_VR.DressingSelfDesc_G1gA, 
        dbo.MDS20_Shared_2_VR.EatingSelf_G1hA, dbo.MDS20_Shared_2_VR.EatingSelfDesc_G1hA, 
        dbo.MDS20_Shared_2_VR.ToiletSelf_G1iA, dbo.MDS20_Shared_2_VR.ToiletSelfDesc_G1iA, 
        dbo.MDS20_Shared_2_VR.HygieneSelf_G1jA AS PersonalHygieneSelf_G1jA, 
        dbo.MDS20_Shared_2_VR.HygieneSelfDesc_G1jA AS PersonalHygieneSelfDesc_G1jA, 
        dbo.MDS20_Shared_2_VR.BathingSelf_G2A, dbo.MDS20_Shared_2_VR.BathingSelfDesc_G2A, 
        dbo.MDS20_Shared_2_VR.BladderContinence_H1b, dbo.MDS20_Shared_2_VR.BladderContinenceDesc_H1b, 
        dbo.MDS20_Shared_2_VR.OffUnitSelf_G1fA AS LocomotionOffUnitSelf_G1fA, 
        dbo.MDS20_Shared_2_VR.OffUnitSelfDesc_G1fA AS LocomotionOffUnitSelfDesc_G1fA, 
        dbo.MDS20_Shared_3_VR.Pain_Frequency_J2a, dbo.MDS20_Shared_3_VR.Pain_FrequencyDesc_J2a, 
        dbo.MDS20_Shared_3_VR.Pain_Intensity_J2b, dbo.MDS20_Shared_3_VR.Pain_IntensityDesc_J2b, 
        dbo.MDS20_Shared_3_VR.AccidentFell30_J4a, dbo.MDS20_Shared_3_VR.AccidentFell30Desc_J4a, 
        dbo.MDS20_Shared_3_VR.AccidentFell180_J4b, dbo.MDS20_Shared_3_VR.AccidentFell180Desc_J4b, 
        dbo.MDS20_Shared_4_VR.Ulcers_Stage1_M1a, dbo.MDS20_Shared_4_VR.Ulcers_Stage2_M1b, 
        dbo.MDS20_Shared_4_VR.Ulcers_Stage3_M1c, dbo.MDS20_Shared_4_VR.Ulcers_Stage4_M1d,
        dbo.MDS20_Hobic_VR.Dyspnea, dbo.MDS20_Hobic_VR.Dyspneaesc, 
        dbo.MDS20_Hobic_VR.Nausea, dbo.MDS20_Hobic_VR.NauseaDesc, 
        dbo.MDS20_Hobic_VR.Fatigue, dbo.MDS20_Hobic_VR.FatigueDesc
        
FROM  dbo.MDS20_VR LEFT OUTER JOIN
        dbo.MDS20_Hobic_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Hobic_VR.zzAbstractLink LEFT OUTER JOIN
        dbo.MDS20_Shared_4_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Shared_4_VR.zzAbstractLink LEFT OUTER JOIN
        dbo.MDS20_Shared_3_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Shared_3_VR.zzAbstractLink LEFT OUTER JOIN
        dbo.MDS20_Shared_2_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Shared_2_VR.zzAbstractLink
WHERE dbo.MDS20_VR.RecordTypeCIHI_Z1 in (''12'', ''13'', ''16'', ''FA'', ''QA'', ''DC'')
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quality_Indicators_ByQuarter_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
--ED - 02171 keep the null
CREATE view [dbo].[MDS20_Quality_Indicators_ByQuarter_VR]
as
select
	InstitutionNumber, InstitutionNumberDesc, FiscalYear, FiscalQuarter, 
	--Prevalence of Falls
	cc_Fall = cast(sum((case when cc_QI_Flag = 1 then cc_Fall_N end)) as float(53)) / nullif(sum((case when cc_QI_Flag = 1 then cc_Fall_D end)), 0) * 100, --SUM (cc_Fall_D) * 100,
	cc_Fall_Total_Number = sum((case when cc_QI_Flag = 1 then cc_Fall_N end)),
	cc_Fall_Total_Denominator = sum((case when cc_QI_Flag = 1 then cc_Fall_D end)),
	
	cc_Fall_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_Fall_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_Fall_D end)), 0) * 100, --SUM (cc_Fall_D) * 100,
	cc_Fall_IP_Total_Number = sum((case when cc_IP_Flag = 1 then cc_Fall_N end)),
	cc_Fall_IP_Total_Denominator = sum((case when cc_IP_Flag = 1 then cc_Fall_D end)),

	--Prevalence of Behavioural Symptoms Affecting Others
	cc_BehavSymptoms = cast(SUM ((case when cc_QI_Flag = 1 then cc_BehavSymptoms_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_BehavSymptoms_D end)), 0) * 100, --SUM (cc_BehavSymptoms_D) * 100,
	cc_BehavSymptoms_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_BehavSymptoms_N end)),
	cc_BehavSymptoms_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_BehavSymptoms_D end)),
	
	cc_BehavSymptoms_HR = cast(SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_D end)), 0) * 100, --SUM (cc_BehavSymptoms_D) * 100,
	cc_BehavSymptoms_HR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_N end)),
	cc_BehavSymptoms_HR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_D end)),
	
	cc_BehavSymptoms_LR = cast(SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_D end)), 0) * 100, --SUM (cc_BehavSymptoms_D) * 100,
    cc_BehavSymptoms_LR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_N end)),
    cc_BehavSymptoms_LR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_D end)),

	cc_BehavSymptoms_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_BehavSymptoms_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_BehavSymptoms_D end)), 0) * 100, --SUM (cc_BehavSymptoms_D) * 100,
    cc_BehavSymptoms_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_BehavSymptoms_N end)),
    cc_BehavSymptoms_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_BehavSymptoms_D end)),

	cc_BehavSymptoms_IP_HR = cast(SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_D end)), 0) * 100, --SUM (cc_BehavSymptoms_D) * 100,
    cc_BehavSymptoms_IP_HR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_N end)),
    cc_BehavSymptoms_IP_HR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_D end)),
    
    cc_BehavSymptoms_IP_LR = cast(SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_D end)), 0) * 100, --SUM (cc_BehavSymptoms_D) * 100,
    cc_BehavSymptoms_IP_LR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_N end)),
    cc_BehavSymptoms_IP_LR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_D end)),
    
	--Prevalence of Symptoms of Depression
	cc_DepressionSymptoms = cast(SUM ((case when cc_QI_Flag = 1 then cc_DepressionSymptoms_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_DepressionSymptoms_D end)), 0) * 100, --SUM (cc_DepressionSymptoms_D) * 100,
    cc_DepressionSymptoms_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_DepressionSymptoms_N end)),
    cc_DepressionSymptoms_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_DepressionSymptoms_D end)),

	cc_DepressionSymptoms_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_DepressionSymptoms_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_DepressionSymptoms_D end)), 0) * 100, --SUM (cc_DepressionSymptoms_D) * 100,
    cc_DepressionSymptoms_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_DepressionSymptoms_N end)),
    cc_DepressionSymptoms_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_DepressionSymptoms_D end)),

	--Prevalence of Depression Without Anti-Depressant Therapy
	cc_DepWOAntiDepThpy = cast(SUM ((case when cc_QI_Flag = 1 then cc_DepWOAntiDepThpy_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_DepWOAntiDepThpy_D end)), 0) * 100, --SUM (cc_DepWOAntiDepThpy_D) * 100,
    cc_DepWOAntiDepThpy_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_DepWOAntiDepThpy_N end)),
    cc_DepWOAntiDepThpy_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_DepWOAntiDepThpy_D end)),

	cc_DepWOAntiDepThpy_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_DepWOAntiDepThpy_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_DepWOAntiDepThpy_D end)), 0) * 100, --SUM (cc_DepWOAntiDepThpy_D) * 100,
    cc_DepWOAntiDepThpy_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_DepWOAntiDepThpy_N end)),
    cc_DepWOAntiDepThpy_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_DepWOAntiDepThpy_D end)),

	--Prevalence of Use of 9 or More Different Medications
	cc_NinePlusMedications = cast(SUM ((case when cc_QI_Flag = 1 then cc_NinePlusMedications_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_NinePlusMedications_D end)), 0) * 100, --SUM (cc_NinePlusMedications_D) * 100,
    cc_NinePlusMedications_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_NinePlusMedications_N end)),
    cc_NinePlusMedications_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_NinePlusMedications_D end)),

	cc_NinePlusMedications_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_NinePlusMedications_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_NinePlusMedications_D end)), 0) * 100, --SUM (cc_NinePlusMedications_D) * 100,
    cc_NinePlusMedications_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_NinePlusMedications_N end)),
    cc_NinePlusMedications_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_NinePlusMedications_D end)),

	--Prevalence of Bladder or Bowel Incontinence
	cc_Incontinence = cast(SUM ((case when cc_QI_Flag = 1 then cc_Incontinence_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_Incontinence_D end)), 0) * 100,	--SUM (cc_Incontinence_D)
    cc_Incontinence_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_Incontinence_N end)),
    cc_Incontinence_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_Incontinence_D end)),

	cc_Incontinence_HR = cast(SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 1 then cc_Incontinence_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 1 then cc_Incontinence_D end)), 0) * 100, --SUM (cc_Incontinence_D)
    cc_Incontinence_HR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 1 then cc_Incontinence_N end)),
    cc_Incontinence_HR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 1 then cc_Incontinence_D end)),

	cc_Incontinence_LR = cast(SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 0 then cc_Incontinence_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 0 then cc_Incontinence_D end)), 0) * 100, --SUM (cc_Incontinence_D)
    cc_Incontinence_LR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 0 then cc_Incontinence_N end)),
    cc_Incontinence_LR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 0 then cc_Incontinence_D end)),

	cc_Incontinence_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_Incontinence_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_Incontinence_D end)), 0) * 100, --SUM (cc_Incontinence_D)
    cc_Incontinence_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_Incontinence_N end)),
    cc_Incontinence_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_Incontinence_D end)),

	--Prevalence of Occasional or Frequent Bladder or Bowel Incontinence Without a Toileting Plan
	cc_IncWOToiletPlan = cast(SUM ((case when cc_QI_Flag = 1 then cc_IncWOToiletPlan_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_IncWOToiletPlan_D end)), 0) * 100, --SUM (cc_IncWOToiletPlan_D)
    cc_IncWOToiletPlan_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_IncWOToiletPlan_N end)),
    cc_IncWOToiletPlan_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_IncWOToiletPlan_D end)),

	cc_IncWOToiletPlan_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_IncWOToiletPlan_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_IncWOToiletPlan_D end)), 0) * 100, --SUM (cc_IncWOToiletPlan_D)
    cc_IncWOToiletPlan_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_IncWOToiletPlan_N end)),
    cc_IncWOToiletPlan_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_IncWOToiletPlan_D end)),

	--Prevalence of Indwelling Catheters
	cc_Catheter = cast(SUM ((case when cc_QI_Flag = 1 then cc_Catheter_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_Catheter_D end)), 0) * 100, -- SUM (cc_Catheter_D) * 100, 
    cc_Catheter_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_Catheter_N end)),
    cc_Catheter_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_Catheter_D end)),

	cc_Catheter_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_Catheter_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_Catheter_D end)), 0) * 100, --SUM (cc_Catheter_D) * 100, 
    cc_Catheter_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_Catheter_N end)),
    cc_Catheter_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_Catheter_D end)),

	--Prevalence of Fecal Impaction
	cc_FecalImpaction = cast(SUM ((case when cc_QI_Flag = 1 then cc_FecalImpaction_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_FecalImpaction_D end)), 0) * 100, --SUM (cc_FecalImpaction_D) * 100, 
    cc_FecalImpaction_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_FecalImpaction_N end)),
    cc_FecalImpaction_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_FecalImpaction_D end)),

	cc_FecalImpaction_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_FecalImpaction_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_FecalImpaction_D end)), 0) * 100, --SUM (cc_FecalImpaction_D) * 100,
    cc_FecalImpaction_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_FecalImpaction_N end)),
    cc_FecalImpaction_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_FecalImpaction_D end)),

	--Prevalence of Urinary Tract Infections
	cc_UrinaryTractInfection = cast(SUM ((case when cc_QI_Flag = 1 then cc_UrinaryTractInfection_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_UrinaryTractInfection_D end)), 0) * 100, --SUM (cc_UrinaryTractInfection_D) * 100,
    cc_UrinaryTractInfection_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_UrinaryTractInfection_N end)),
    cc_UrinaryTractInfection_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_UrinaryTractInfection_D end)),

	cc_UrinaryTractInfection_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_UrinaryTractInfection_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_UrinaryTractInfection_D end)), 0) * 100, --SUM (cc_UrinaryTractInfection_D) * 100,
    cc_UrinaryTractInfection_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_UrinaryTractInfection_N end)),
    cc_UrinaryTractInfection_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_UrinaryTractInfection_D end)),

	--Prevalence of Weight Loss
	cc_WeightLoss = cast(SUM ((case when cc_QI_Flag = 1 then cc_WeightLoss_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_WeightLoss_D end)), 0) * 100, --SUM (cc_WeightLoss_D)
    cc_WeightLoss_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_WeightLoss_N end)),
    cc_WeightLoss_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_WeightLoss_D end)),

	cc_WeightLoss_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_WeightLoss_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_WeightLoss_D end)), 0) * 100, --SUM (cc_WeightLoss_D)
    cc_WeightLoss_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_WeightLoss_N end)),
    cc_WeightLoss_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_WeightLoss_D end)),

	--Prevalence of Tube Feeding
	cc_TubeFeed = cast(SUM ((case when cc_QI_Flag = 1 then cc_TubeFeed_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_TubeFeed_D end)), 0) * 100, --SUM (cc_TubeFeed_D) * 100,
    cc_TubeFeed_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_TubeFeed_N end)),
    cc_TubeFeed_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_TubeFeed_D end)),

	cc_TubeFeed_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_TubeFeed_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_TubeFeed_D end)), 0) * 100, --SUM (cc_TubeFeed_D) * 100,
    cc_TubeFeed_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_TubeFeed_N end)),
    cc_TubeFeed_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_TubeFeed_D end)),

	--Prevalence of Dehydration
	cc_Dehydration = cast(SUM ((case when cc_QI_Flag = 1 then cc_Dehydration_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_Dehydration_D end)), 0) * 100, --SUM (cc_Dehydration_D) * 100,
    cc_Dehydration_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_Dehydration_N end)),
    cc_Dehydration_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_Dehydration_D end)),

	cc_Dehydration_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_Dehydration_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_Dehydration_D end)), 0) * 100, --SUM (cc_Dehydration_D) * 100,
    cc_Dehydration_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_Dehydration_N end)),
    cc_Dehydration_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_Dehydration_D end)),

	--Prevalence of Bedfast Residents
	cc_BedfastResidents = cast(SUM ((case when cc_QI_Flag = 1 then cc_BedfastResidents_N end)) as float(53))/ nullif(SUM ((case when cc_QI_Flag = 1 then cc_BedfastResidents_D end)), 0) * 100, --SUM (cc_BedfastResidents_D) * 100,
    cc_BedfastResidents_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_BedfastResidents_N end)),
    cc_BedfastResidents_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_BedfastResidents_D end)),

	cc_BedfastResidents_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_BedfastResidents_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_BedfastResidents_D end)), 0) * 100, --SUM (cc_BedfastResidents_D) * 100,
    cc_BedfastResidents_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_BedfastResidents_N end)),
    cc_BedfastResidents_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_BedfastResidents_D end)),

	--Prevalence of Anti-Psychotic Drug Use in the Absence of Psychotic and Related Conditions
	cc_AntiPsychoticDrug = cast(SUM ((case when cc_QI_Flag = 1 then cc_AntiPsychoticDrug_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_AntiPsychoticDrug_D end)), 0) * 100, --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_AntiPsychoticDrug_N end)),
    cc_AntiPsychoticDrug_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_AntiPsychoticDrug_D end)),

	cc_AntiPsychoticDrug_HR = cast(SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_D end)), 0) * 100, --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_HR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_N end)),
    cc_AntiPsychoticDrug_HR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_D end)),

	cc_AntiPsychoticDrug_LR = cast(SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_D end)), 0) * 100, --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_LR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_N end)),
    cc_AntiPsychoticDrug_LR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_D end)),

	cc_AntiPsychoticDrug_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_AntiPsychoticDrug_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_AntiPsychoticDrug_D end)), 0) * 100, --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_AntiPsychoticDrug_N end)),
    cc_AntiPsychoticDrug_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_AntiPsychoticDrug_D end)),

	cc_AntiPsychoticDrug_IP_HR = cast(SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_D end)), 0) * 100, --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_IP_HR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_N end)),
    cc_AntiPsychoticDrug_IP_HR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_D end)),

	cc_AntiPsychoticDrug_IP_LR = cast(SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_D end)), 0) * 100, --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_IP_LR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_N end)),
    cc_AntiPsychoticDrug_IP_LR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_D end)),

	--Prevalence of Anti-Anxiety/Hypnotic Drug Use
	cc_AntiAnxietyDrug = cast(SUM ((case when cc_QI_Flag = 1 then cc_AntiAnxietyDrug_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_AntiAnxietyDrug_D end)), 0) * 100, --SUM (cc_AntiAnxietyDrug_D)
    cc_AntiAnxietyDrug_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_AntiAnxietyDrug_N end)),
    cc_AntiAnxietyDrug_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_AntiAnxietyDrug_D end)),

	cc_AntiAnxietyDrug_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_AntiAnxietyDrug_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_AntiAnxietyDrug_D end)), 0) * 100, --SUM (cc_AntiAnxietyDrug_D)
    cc_AntiAnxietyDrug_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_AntiAnxietyDrug_N end)),
    cc_AntiAnxietyDrug_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_AntiAnxietyDrug_D end)),

	--Prevalence of Hypnotic Drug Use More Than Two Days in Past Week
	cc_TwoPlusHypnoticDrugDays = cast(SUM ((case when cc_QI_Flag = 1 then cc_TwoPlusHypnoticDrugDays_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_TwoPlusHypnoticDrugDays_D end)), 0) * 100, --SUM (cc_TwoPlusHypnoticDrugDays_D) * 100,
    cc_TwoPlusHypnoticDrugDays_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_TwoPlusHypnoticDrugDays_N end)),
    cc_TwoPlusHypnoticDrugDays_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_TwoPlusHypnoticDrugDays_D end)),

	cc_TwoPlusHypnoticDrugDays_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_TwoPlusHypnoticDrugDays_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_TwoPlusHypnoticDrugDays_D end)), 0) * 100, --SUM (cc_TwoPlusHypnoticDrugDays_D) * 100,
    cc_TwoPlusHypnoticDrugDays_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_TwoPlusHypnoticDrugDays_N end)),
    cc_TwoPlusHypnoticDrugDays_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_TwoPlusHypnoticDrugDays_D end)),

	--Prevalence of Daily Physical Restraints
	cc_PhysicalRestraints = cast(SUM ((case when cc_QI_Flag = 1 then cc_PhysicalRestraints_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_PhysicalRestraints_D end)), 0) * 100, --SUM (cc_PhysicalRestraints_D) * 100,
    cc_PhysicalRestraints_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_PhysicalRestraints_N end)),
    cc_PhysicalRestraints_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_PhysicalRestraints_D end)),

	cc_PhysicalRestraints_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_PhysicalRestraints_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_PhysicalRestraints_D end)), 0) * 100, --SUM (cc_PhysicalRestraints_D) * 100,
    cc_PhysicalRestraints_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_PhysicalRestraints_N end)),
    cc_PhysicalRestraints_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_PhysicalRestraints_D end)),

	--Prevalence of Little or No Activity
	cc_NoActivity = cast(SUM ((case when cc_QI_Flag = 1 then cc_NoActivity_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_NoActivity_D end)), 0) * 100, --SUM (cc_NoActivity_D)
    cc_NoActivity_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_NoActivity_N end)),
    cc_NoActivity_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_NoActivity_D end)),

	cc_NoActivity_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_NoActivity_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_NoActivity_D end)), 0) * 100, --SUM (cc_NoActivity_D)
    cc_NoActivity_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_NoActivity_N end)),
    cc_NoActivity_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_NoActivity_D end)),

	--Prevalence of Stage 1–4 Pressure Ulcers
	cc_PressureUlcers = cast(SUM ((case when cc_QI_Flag = 1 then cc_PressureUlcers_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_PressureUlcers_D end)), 0) * 100, --SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_PressureUlcers_N end)),
    cc_PressureUlcers_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_PressureUlcers_D end)),

	cc_PressureUlcers_HR = cast(SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_D end)), 0) * 100, --SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_HR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_N end)),
    cc_PressureUlcers_HR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_D end)),

	cc_PressureUlcers_LR = cast(SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_D end)), 0) * 100, --SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_LR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_N end)),
    cc_PressureUlcers_LR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_D end)),

	cc_PressureUlcers_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_PressureUlcers_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_PressureUlcers_D end)), 0) * 100, -- SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_PressureUlcers_N end)),
    cc_PressureUlcers_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_PressureUlcers_D end)),

	cc_PressureUlcers_IP_HR = cast(SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_D end)), 0) * 100, --SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_IP_HR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_N end)),
    cc_PressureUlcers_IP_HR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_D end)),

	cc_PressureUlcers_IP_LR = cast(SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_D end)), 0) * 100, --SUM (cc_PressureUlcers_D) * 100, 
    cc_PressureUlcers_IP_LR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_N end)),
    cc_PressureUlcers_IP_LR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_D end)),

	--Incidence of New Fractures
	cc_NewFractures = cast(SUM (cc_NewFractures_N) as float(53)) / nullif(SUM (cc_NewFractures_D), 0) * 100,
    cc_NewFractures_Total_Number = SUM (cc_NewFractures_N),
    cc_NewFractures_Total_Denominator = SUM (cc_NewFractures_D),

	--Incidence of Cognitive Impairment
	cc_CognitiveImpairment = cast(SUM (cc_CognitiveImpairment_N) as float(53)) / nullif(SUM (cc_CognitiveImpairment_D), 0) * 100,
    cc_CognitiveImpairment_Total_Number = SUM (cc_CognitiveImpairment_N),
    cc_CognitiveImpairment_Total_Denominator = SUM (cc_CognitiveImpairment_D),

	--Incidence of Decline in Late Loss ADLs
	cc_LateLossADLs = cast(SUM (cc_LateLossADLs_N) as float(53)) / nullif(SUM (cc_LateLossADLs_D), 0) * 100,
    cc_LateLossADLs_Total_Number = SUM (cc_LateLossADLs_N),
    cc_LateLossADLs_Total_Denominator = SUM (cc_LateLossADLs_D),

	--Incidence of Decline in Range of Motion
	cc_ROMDecline = cast(SUM (cc_ROMDecline_N) as float(53)) / nullif(SUM (cc_ROMDecline_D), 0) * 100,
    cc_ROMDecline_Total_Number = SUM (cc_ROMDecline_N),
    cc_ROMDecline_Total_Denominator = SUM (cc_ROMDecline_D),
	
	TotalCases = count(*),
	Total_QualityIndicators = sum(cc_QI_Flag),
	Total_IntakeProfile = sum(cc_IP_Flag)
from MDS20_Quality_Indicators_Detail_VR
group by InstitutionNumber, InstitutionNumberDesc, FiscalYear, FiscalQuarter
/*  --before ED - 02171 
	--Prevalence of Falls
	cc_Fall = isnull(cast(sum((case when cc_QI_Flag = 1 then cc_Fall_N else 0 end)) as float(53)) / nullif(sum((case when cc_QI_Flag = 1 then cc_Fall_D else 0 end)), 0) * 100, 0), --SUM (cc_Fall_D) * 100,
	cc_Fall_Total_Number = sum((case when cc_QI_Flag = 1 then cc_Fall_N else 0 end)),
	cc_Fall_Total_Denominator = sum((case when cc_QI_Flag = 1 then cc_Fall_D else 0 end)),
	
	cc_Fall_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_Fall_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_Fall_D else 0 end)), 0) * 100, 0), --SUM (cc_Fall_D) * 100,
	cc_Fall_IP_Total_Number = sum((case when cc_IP_Flag = 1 then cc_Fall_N else 0 end)),
	cc_Fall_IP_Total_Denominator = sum((case when cc_IP_Flag = 1 then cc_Fall_D else 0 end)),

	--Prevalence of Behavioural Symptoms Affecting Others
	cc_BehavSymptoms = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_BehavSymptoms_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_BehavSymptoms_D else 0 end)), 0) * 100, 0), --SUM (cc_BehavSymptoms_D) * 100,
	cc_BehavSymptoms_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_BehavSymptoms_N else 0 end)),
	cc_BehavSymptoms_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_BehavSymptoms_D else 0 end)),
	
	cc_BehavSymptoms_HR = isnull(cast(SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_D else 0 end)), 0) * 100, 0), --SUM (cc_BehavSymptoms_D) * 100,
	cc_BehavSymptoms_HR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_N else 0 end)),
	cc_BehavSymptoms_HR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_D else 0 end)),
	
	cc_BehavSymptoms_LR = isnull(cast(SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_D else 0 end)), 0) * 100, 0), --SUM (cc_BehavSymptoms_D) * 100,
    cc_BehavSymptoms_LR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_N else 0 end)),
    cc_BehavSymptoms_LR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_D else 0 end)),

	cc_BehavSymptoms_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_BehavSymptoms_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_BehavSymptoms_D else 0 end)), 0) * 100, 0), --SUM (cc_BehavSymptoms_D) * 100,
    cc_BehavSymptoms_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_BehavSymptoms_N else 0 end)),
    cc_BehavSymptoms_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_BehavSymptoms_D else 0 end)),

	cc_BehavSymptoms_IP_HR = isnull(cast(SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_D else 0 end)), 0) * 100, 0), --SUM (cc_BehavSymptoms_D) * 100,
    cc_BehavSymptoms_IP_HR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_N else 0 end)),
    cc_BehavSymptoms_IP_HR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_D else 0 end)),
    
    cc_BehavSymptoms_IP_LR = isnull(cast(SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_D else 0 end)), 0) * 100, 0), --SUM (cc_BehavSymptoms_D) * 100,
    cc_BehavSymptoms_IP_LR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_N else 0 end)),
    cc_BehavSymptoms_IP_LR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_D else 0 end)),
    
	--Prevalence of Symptoms of Depression
	cc_DepressionSymptoms = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_DepressionSymptoms_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_DepressionSymptoms_D else 0 end)), 0) * 100, 0), --SUM (cc_DepressionSymptoms_D) * 100,
    cc_DepressionSymptoms_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_DepressionSymptoms_N else 0 end)),
    cc_DepressionSymptoms_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_DepressionSymptoms_D else 0 end)),

	cc_DepressionSymptoms_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_DepressionSymptoms_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_DepressionSymptoms_D else 0 end)), 0) * 100, 0), --SUM (cc_DepressionSymptoms_D) * 100,
    cc_DepressionSymptoms_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_DepressionSymptoms_N else 0 end)),
    cc_DepressionSymptoms_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_DepressionSymptoms_D else 0 end)),

	--Prevalence of Depression Without Anti-Depressant Therapy
	cc_DepWOAntiDepThpy = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_DepWOAntiDepThpy_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_DepWOAntiDepThpy_D else 0 end)), 0) * 100, 0), --SUM (cc_DepWOAntiDepThpy_D) * 100,
    cc_DepWOAntiDepThpy_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_DepWOAntiDepThpy_N else 0 end)),
    cc_DepWOAntiDepThpy_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_DepWOAntiDepThpy_D else 0 end)),

	cc_DepWOAntiDepThpy_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_DepWOAntiDepThpy_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_DepWOAntiDepThpy_D else 0 end)), 0) * 100, 0), --SUM (cc_DepWOAntiDepThpy_D) * 100,
    cc_DepWOAntiDepThpy_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_DepWOAntiDepThpy_N else 0 end)),
    cc_DepWOAntiDepThpy_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_DepWOAntiDepThpy_D else 0 end)),

	--Prevalence of Use of 9 or More Different Medications
	cc_NinePlusMedications = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_NinePlusMedications_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_NinePlusMedications_D else 0 end)), 0) * 100, 0), --SUM (cc_NinePlusMedications_D) * 100,
    cc_NinePlusMedications_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_NinePlusMedications_N else 0 end)),
    cc_NinePlusMedications_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_NinePlusMedications_D else 0 end)),

	cc_NinePlusMedications_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_NinePlusMedications_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_NinePlusMedications_D else 0 end)), 0) * 100, 0), --SUM (cc_NinePlusMedications_D) * 100,
    cc_NinePlusMedications_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_NinePlusMedications_N else 0 end)),
    cc_NinePlusMedications_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_NinePlusMedications_D else 0 end)),

	--Prevalence of Bladder or Bowel Incontinence
	cc_Incontinence = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_Incontinence_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_Incontinence_D else 0 end)), 0) * 100, 0),	--SUM (cc_Incontinence_D)
    cc_Incontinence_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_Incontinence_N else 0 end)),
    cc_Incontinence_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_Incontinence_D else 0 end)),

	cc_Incontinence_HR = isnull(cast(SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 1 then cc_Incontinence_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 1 then cc_Incontinence_D else 0 end)), 0) * 100, 0), --SUM (cc_Incontinence_D)
    cc_Incontinence_HR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 1 then cc_Incontinence_N else 0 end)),
    cc_Incontinence_HR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 1 then cc_Incontinence_D else 0 end)),

	cc_Incontinence_LR = isnull(cast(SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 0 then cc_Incontinence_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 0 then cc_Incontinence_D else 0 end)), 0) * 100, 0), --SUM (cc_Incontinence_D)
    cc_Incontinence_LR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 0 then cc_Incontinence_N else 0 end)),
    cc_Incontinence_LR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 0 then cc_Incontinence_D else 0 end)),

	cc_Incontinence_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_Incontinence_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_Incontinence_D else 0 end)), 0) * 100, 0), --SUM (cc_Incontinence_D)
    cc_Incontinence_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_Incontinence_N else 0 end)),
    cc_Incontinence_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_Incontinence_D else 0 end)),

	--Prevalence of Occasional or Frequent Bladder or Bowel Incontinence Without a Toileting Plan
	cc_IncWOToiletPlan = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_IncWOToiletPlan_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_IncWOToiletPlan_D else 0 end)), 0) * 100, 0), --SUM (cc_IncWOToiletPlan_D)
    cc_IncWOToiletPlan_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_IncWOToiletPlan_N else 0 end)),
    cc_IncWOToiletPlan_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_IncWOToiletPlan_D else 0 end)),

	cc_IncWOToiletPlan_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_IncWOToiletPlan_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_IncWOToiletPlan_D else 0 end)), 0) * 100, 0), --SUM (cc_IncWOToiletPlan_D)
    cc_IncWOToiletPlan_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_IncWOToiletPlan_N else 0 end)),
    cc_IncWOToiletPlan_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_IncWOToiletPlan_D else 0 end)),

	--Prevalence of Indwelling Catheters
	cc_Catheter = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_Catheter_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_Catheter_D else 0 end)), 0) * 100, 0), -- SUM (cc_Catheter_D) * 100, 
    cc_Catheter_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_Catheter_N else 0 end)),
    cc_Catheter_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_Catheter_D else 0 end)),

	cc_Catheter_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_Catheter_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_Catheter_D else 0 end)), 0) * 100, 0), --SUM (cc_Catheter_D) * 100, 
    cc_Catheter_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_Catheter_N else 0 end)),
    cc_Catheter_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_Catheter_D else 0 end)),

	--Prevalence of Fecal Impaction
	cc_FecalImpaction = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_FecalImpaction_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_FecalImpaction_D else 0 end)), 0) * 100, 0), --SUM (cc_FecalImpaction_D) * 100, 
    cc_FecalImpaction_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_FecalImpaction_N else 0 end)),
    cc_FecalImpaction_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_FecalImpaction_D else 0 end)),

	cc_FecalImpaction_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_FecalImpaction_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_FecalImpaction_D else 0 end)), 0) * 100, 0), --SUM (cc_FecalImpaction_D) * 100,
    cc_FecalImpaction_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_FecalImpaction_N else 0 end)),
    cc_FecalImpaction_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_FecalImpaction_D else 0 end)),

	--Prevalence of Urinary Tract Infections
	cc_UrinaryTractInfection = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_UrinaryTractInfection_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_UrinaryTractInfection_D else 0 end)), 0) * 100, 0), --SUM (cc_UrinaryTractInfection_D) * 100,
    cc_UrinaryTractInfection_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_UrinaryTractInfection_N else 0 end)),
    cc_UrinaryTractInfection_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_UrinaryTractInfection_D else 0 end)),

	cc_UrinaryTractInfection_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_UrinaryTractInfection_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_UrinaryTractInfection_D else 0 end)), 0) * 100, 0), --SUM (cc_UrinaryTractInfection_D) * 100,
    cc_UrinaryTractInfection_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_UrinaryTractInfection_N else 0 end)),
    cc_UrinaryTractInfection_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_UrinaryTractInfection_D else 0 end)),

	--Prevalence of Weight Loss
	cc_WeightLoss = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_WeightLoss_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_WeightLoss_D else 0 end)), 0) * 100, 0), --SUM (cc_WeightLoss_D)
    cc_WeightLoss_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_WeightLoss_N else 0 end)),
    cc_WeightLoss_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_WeightLoss_D else 0 end)),

	cc_WeightLoss_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_WeightLoss_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_WeightLoss_D else 0 end)), 0) * 100, 0), --SUM (cc_WeightLoss_D)
    cc_WeightLoss_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_WeightLoss_N else 0 end)),
    cc_WeightLoss_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_WeightLoss_D else 0 end)),

	--Prevalence of Tube Feeding
	cc_TubeFeed = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_TubeFeed_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_TubeFeed_D else 0 end)), 0) * 100, 0), --SUM (cc_TubeFeed_D) * 100,
    cc_TubeFeed_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_TubeFeed_N else 0 end)),
    cc_TubeFeed_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_TubeFeed_D else 0 end)),

	cc_TubeFeed_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_TubeFeed_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_TubeFeed_D else 0 end)), 0) * 100, 0), --SUM (cc_TubeFeed_D) * 100,
    cc_TubeFeed_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_TubeFeed_N else 0 end)),
    cc_TubeFeed_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_TubeFeed_D else 0 end)),

	--Prevalence of Dehydration
	cc_Dehydration = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_Dehydration_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_Dehydration_D else 0 end)), 0) * 100, 0), --SUM (cc_Dehydration_D) * 100,
    cc_Dehydration_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_Dehydration_N else 0 end)),
    cc_Dehydration_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_Dehydration_D else 0 end)),

	cc_Dehydration_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_Dehydration_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_Dehydration_D else 0 end)), 0) * 100, 0), --SUM (cc_Dehydration_D) * 100,
    cc_Dehydration_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_Dehydration_N else 0 end)),
    cc_Dehydration_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_Dehydration_D else 0 end)),

	--Prevalence of Bedfast Residents
	cc_BedfastResidents = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_BedfastResidents_N else 0 end)) as float(53))/ nullif(SUM ((case when cc_QI_Flag = 1 then cc_BedfastResidents_D else 0 end)), 0) * 100, 0), --SUM (cc_BedfastResidents_D) * 100,
    cc_BedfastResidents_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_BedfastResidents_N else 0 end)),
    cc_BedfastResidents_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_BedfastResidents_D else 0 end)),

	cc_BedfastResidents_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_BedfastResidents_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_BedfastResidents_D else 0 end)), 0) * 100, 0), --SUM (cc_BedfastResidents_D) * 100,
    cc_BedfastResidents_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_BedfastResidents_N else 0 end)),
    cc_BedfastResidents_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_BedfastResidents_D else 0 end)),

	--Prevalence of Anti-Psychotic Drug Use in the Absence of Psychotic and Related Conditions
	cc_AntiPsychoticDrug = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_AntiPsychoticDrug_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_AntiPsychoticDrug_D else 0 end)), 0) * 100, 0), --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_AntiPsychoticDrug_N else 0 end)),
    cc_AntiPsychoticDrug_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_AntiPsychoticDrug_D else 0 end)),

	cc_AntiPsychoticDrug_HR = isnull(cast(SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_D else 0 end)), 0) * 100, 0), --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_HR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_N else 0 end)),
    cc_AntiPsychoticDrug_HR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_D else 0 end)),

	cc_AntiPsychoticDrug_LR = isnull(cast(SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_D else 0 end)), 0) * 100, 0), --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_LR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_N else 0 end)),
    cc_AntiPsychoticDrug_LR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_D else 0 end)),

	cc_AntiPsychoticDrug_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_AntiPsychoticDrug_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_AntiPsychoticDrug_D else 0 end)), 0) * 100, 0), --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_AntiPsychoticDrug_N else 0 end)),
    cc_AntiPsychoticDrug_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_AntiPsychoticDrug_D else 0 end)),

	cc_AntiPsychoticDrug_IP_HR = isnull(cast(SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_D else 0 end)), 0) * 100, 0), --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_IP_HR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_N else 0 end)),
    cc_AntiPsychoticDrug_IP_HR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_D else 0 end)),

	cc_AntiPsychoticDrug_IP_LR = isnull(cast(SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_D else 0 end)), 0) * 100, 0), --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_IP_LR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_N else 0 end)),
    cc_AntiPsychoticDrug_IP_LR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_D else 0 end)),

	--Prevalence of Anti-Anxiety/Hypnotic Drug Use
	cc_AntiAnxietyDrug = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_AntiAnxietyDrug_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_AntiAnxietyDrug_D else 0 end)), 0) * 100, 0), --SUM (cc_AntiAnxietyDrug_D)
    cc_AntiAnxietyDrug_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_AntiAnxietyDrug_N else 0 end)),
    cc_AntiAnxietyDrug_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_AntiAnxietyDrug_D else 0 end)),

	cc_AntiAnxietyDrug_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_AntiAnxietyDrug_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_AntiAnxietyDrug_D else 0 end)), 0) * 100, 0), --SUM (cc_AntiAnxietyDrug_D)
    cc_AntiAnxietyDrug_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_AntiAnxietyDrug_N else 0 end)),
    cc_AntiAnxietyDrug_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_AntiAnxietyDrug_D else 0 end)),

	--Prevalence of Hypnotic Drug Use More Than Two Days in Past Week
	cc_TwoPlusHypnoticDrugDays = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_TwoPlusHypnoticDrugDays_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_TwoPlusHypnoticDrugDays_D else 0 end)), 0) * 100, 0), --SUM (cc_TwoPlusHypnoticDrugDays_D) * 100,
    cc_TwoPlusHypnoticDrugDays_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_TwoPlusHypnoticDrugDays_N else 0 end)),
    cc_TwoPlusHypnoticDrugDays_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_TwoPlusHypnoticDrugDays_D else 0 end)),

	cc_TwoPlusHypnoticDrugDays_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_TwoPlusHypnoticDrugDays_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_TwoPlusHypnoticDrugDays_D else 0 end)), 0) * 100, 0), --SUM (cc_TwoPlusHypnoticDrugDays_D) * 100,
    cc_TwoPlusHypnoticDrugDays_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_TwoPlusHypnoticDrugDays_N else 0 end)),
    cc_TwoPlusHypnoticDrugDays_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_TwoPlusHypnoticDrugDays_D else 0 end)),

	--Prevalence of Daily Physical Restraints
	cc_PhysicalRestraints = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_PhysicalRestraints_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_PhysicalRestraints_D else 0 end)), 0) * 100, 0), --SUM (cc_PhysicalRestraints_D) * 100,
    cc_PhysicalRestraints_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_PhysicalRestraints_N else 0 end)),
    cc_PhysicalRestraints_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_PhysicalRestraints_D else 0 end)),

	cc_PhysicalRestraints_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_PhysicalRestraints_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_PhysicalRestraints_D else 0 end)), 0) * 100, 0), --SUM (cc_PhysicalRestraints_D) * 100,
    cc_PhysicalRestraints_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_PhysicalRestraints_N else 0 end)),
    cc_PhysicalRestraints_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_PhysicalRestraints_D else 0 end)),

	--Prevalence of Little or No Activity
	cc_NoActivity = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_NoActivity_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_NoActivity_D else 0 end)), 0) * 100, 0), --SUM (cc_NoActivity_D)
    cc_NoActivity_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_NoActivity_N else 0 end)),
    cc_NoActivity_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_NoActivity_D else 0 end)),

	cc_NoActivity_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_NoActivity_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_NoActivity_D else 0 end)), 0) * 100, 0), --SUM (cc_NoActivity_D)
    cc_NoActivity_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_NoActivity_N else 0 end)),
    cc_NoActivity_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_NoActivity_D else 0 end)),

	--Prevalence of Stage 1–4 Pressure Ulcers
	cc_PressureUlcers = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_PressureUlcers_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_PressureUlcers_D else 0 end)), 0) * 100, 0), --SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_PressureUlcers_N else 0 end)),
    cc_PressureUlcers_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_PressureUlcers_D else 0 end)),

	cc_PressureUlcers_HR = isnull(cast(SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_D else 0 end)), 0) * 100, 0), --SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_HR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_N else 0 end)),
    cc_PressureUlcers_HR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_D else 0 end)),

	cc_PressureUlcers_LR = isnull(cast(SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_D else 0 end)), 0) * 100, 0), --SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_LR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_N else 0 end)),
    cc_PressureUlcers_LR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_D else 0 end)),

	cc_PressureUlcers_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_PressureUlcers_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_PressureUlcers_D else 0 end)), 0) * 100, 0), -- SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_PressureUlcers_N else 0 end)),
    cc_PressureUlcers_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_PressureUlcers_D else 0 end)),

	cc_PressureUlcers_IP_HR = isnull(cast(SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_D else 0 end)), 0) * 100, 0), --SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_IP_HR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_N else 0 end)),
    cc_PressureUlcers_IP_HR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_D else 0 end)),

	cc_PressureUlcers_IP_LR = isnull(cast(SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_D else 0 end)), 0) * 100, 0), --SUM (cc_PressureUlcers_D) * 100, 
    cc_PressureUlcers_IP_LR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_N else 0 end)),
    cc_PressureUlcers_IP_LR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_D else 0 end)),

	--Incidence of New Fractures
	cc_NewFractures = isnull(cast(SUM (cc_NewFractures_N) as float(53)) / nullif(SUM (cc_NewFractures_D), 0) * 100, 0),
    cc_NewFractures_Total_Number = SUM (cc_NewFractures_N),
    cc_NewFractures_Total_Denominator = SUM (cc_NewFractures_D),

	--Incidence of Cognitive Impairment
	cc_CognitiveImpairment = isnull(cast(SUM (cc_CognitiveImpairment_N) as float(53)) / nullif(SUM (cc_CognitiveImpairment_D), 0) * 100, 0),
    cc_CognitiveImpairment_Total_Number = SUM (cc_CognitiveImpairment_N),
    cc_CognitiveImpairment_Total_Denominator = SUM (cc_CognitiveImpairment_D),

	--Incidence of Decline in Late Loss ADLs
	cc_LateLossADLs = isnull(cast(SUM (cc_LateLossADLs_N) as float(53)) / nullif(SUM (cc_LateLossADLs_D), 0) * 100, 0),
    cc_LateLossADLs_Total_Number = SUM (cc_LateLossADLs_N),
    cc_LateLossADLs_Total_Denominator = SUM (cc_LateLossADLs_D),

	--Incidence of Decline in Range of Motion
	cc_ROMDecline = isnull(cast(SUM (cc_ROMDecline_N) as float(53)) / nullif(SUM (cc_ROMDecline_D), 0) * 100, 0),
    cc_ROMDecline_Total_Number = SUM (cc_ROMDecline_N),
    cc_ROMDecline_Total_Denominator = SUM (cc_ROMDecline_D),
*/    


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quality_Indicators_ByYear_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
--ED - 02171 keep the null
CREATE view [dbo].[MDS20_Quality_Indicators_ByYear_VR]
as
select
	InstitutionNumber, InstitutionNumberDesc, FiscalYear, 
	--Prevalence of Falls
	cc_Fall = cast(sum((case when cc_QI_Flag = 1 then cc_Fall_N end)) as float(53)) / nullif(sum((case when cc_QI_Flag = 1 then cc_Fall_D end)), 0) * 100, --SUM (cc_Fall_D) * 100,
	cc_Fall_Total_Number = sum((case when cc_QI_Flag = 1 then cc_Fall_N end)),
	cc_Fall_Total_Denominator = sum((case when cc_QI_Flag = 1 then cc_Fall_D end)),
	
	cc_Fall_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_Fall_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_Fall_D end)), 0) * 100, --SUM (cc_Fall_D) * 100,
	cc_Fall_IP_Total_Number = sum((case when cc_IP_Flag = 1 then cc_Fall_N end)),
	cc_Fall_IP_Total_Denominator = sum((case when cc_IP_Flag = 1 then cc_Fall_D end)),

	--Prevalence of Behavioural Symptoms Affecting Others
	cc_BehavSymptoms = cast(SUM ((case when cc_QI_Flag = 1 then cc_BehavSymptoms_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_BehavSymptoms_D end)), 0) * 100, --SUM (cc_BehavSymptoms_D) * 100,
	cc_BehavSymptoms_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_BehavSymptoms_N end)),
	cc_BehavSymptoms_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_BehavSymptoms_D end)),
	
	cc_BehavSymptoms_HR = cast(SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_D end)), 0) * 100, --SUM (cc_BehavSymptoms_D) * 100,
	cc_BehavSymptoms_HR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_N end)),
	cc_BehavSymptoms_HR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_D end)),
	
	cc_BehavSymptoms_LR = cast(SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_D end)), 0) * 100, --SUM (cc_BehavSymptoms_D) * 100,
    cc_BehavSymptoms_LR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_N end)),
    cc_BehavSymptoms_LR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_D end)),

	cc_BehavSymptoms_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_BehavSymptoms_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_BehavSymptoms_D end)), 0) * 100, --SUM (cc_BehavSymptoms_D) * 100,
    cc_BehavSymptoms_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_BehavSymptoms_N end)),
    cc_BehavSymptoms_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_BehavSymptoms_D end)),

	cc_BehavSymptoms_IP_HR = cast(SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_D end)), 0) * 100, --SUM (cc_BehavSymptoms_D) * 100,
    cc_BehavSymptoms_IP_HR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_N end)),
    cc_BehavSymptoms_IP_HR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_D end)),
    
    cc_BehavSymptoms_IP_LR = cast(SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_D end)), 0) * 100, --SUM (cc_BehavSymptoms_D) * 100,
    cc_BehavSymptoms_IP_LR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_N end)),
    cc_BehavSymptoms_IP_LR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_D end)),
    
	--Prevalence of Symptoms of Depression
	cc_DepressionSymptoms = cast(SUM ((case when cc_QI_Flag = 1 then cc_DepressionSymptoms_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_DepressionSymptoms_D end)), 0) * 100, --SUM (cc_DepressionSymptoms_D) * 100,
    cc_DepressionSymptoms_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_DepressionSymptoms_N end)),
    cc_DepressionSymptoms_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_DepressionSymptoms_D end)),

	cc_DepressionSymptoms_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_DepressionSymptoms_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_DepressionSymptoms_D end)), 0) * 100, --SUM (cc_DepressionSymptoms_D) * 100,
    cc_DepressionSymptoms_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_DepressionSymptoms_N end)),
    cc_DepressionSymptoms_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_DepressionSymptoms_D end)),

	--Prevalence of Depression Without Anti-Depressant Therapy
	cc_DepWOAntiDepThpy = cast(SUM ((case when cc_QI_Flag = 1 then cc_DepWOAntiDepThpy_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_DepWOAntiDepThpy_D end)), 0) * 100, --SUM (cc_DepWOAntiDepThpy_D) * 100,
    cc_DepWOAntiDepThpy_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_DepWOAntiDepThpy_N end)),
    cc_DepWOAntiDepThpy_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_DepWOAntiDepThpy_D end)),

	cc_DepWOAntiDepThpy_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_DepWOAntiDepThpy_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_DepWOAntiDepThpy_D end)), 0) * 100, --SUM (cc_DepWOAntiDepThpy_D) * 100,
    cc_DepWOAntiDepThpy_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_DepWOAntiDepThpy_N end)),
    cc_DepWOAntiDepThpy_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_DepWOAntiDepThpy_D end)),

	--Prevalence of Use of 9 or More Different Medications
	cc_NinePlusMedications = cast(SUM ((case when cc_QI_Flag = 1 then cc_NinePlusMedications_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_NinePlusMedications_D end)), 0) * 100, --SUM (cc_NinePlusMedications_D) * 100,
    cc_NinePlusMedications_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_NinePlusMedications_N end)),
    cc_NinePlusMedications_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_NinePlusMedications_D end)),

	cc_NinePlusMedications_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_NinePlusMedications_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_NinePlusMedications_D end)), 0) * 100, --SUM (cc_NinePlusMedications_D) * 100,
    cc_NinePlusMedications_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_NinePlusMedications_N end)),
    cc_NinePlusMedications_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_NinePlusMedications_D end)),

	--Prevalence of Bladder or Bowel Incontinence
	cc_Incontinence = cast(SUM ((case when cc_QI_Flag = 1 then cc_Incontinence_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_Incontinence_D end)), 0) * 100,	--SUM (cc_Incontinence_D)
    cc_Incontinence_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_Incontinence_N end)),
    cc_Incontinence_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_Incontinence_D end)),

	cc_Incontinence_HR = cast(SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 1 then cc_Incontinence_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 1 then cc_Incontinence_D end)), 0) * 100, --SUM (cc_Incontinence_D)
    cc_Incontinence_HR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 1 then cc_Incontinence_N end)),
    cc_Incontinence_HR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 1 then cc_Incontinence_D end)),

	cc_Incontinence_LR = cast(SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 0 then cc_Incontinence_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 0 then cc_Incontinence_D end)), 0) * 100, --SUM (cc_Incontinence_D)
    cc_Incontinence_LR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 0 then cc_Incontinence_N end)),
    cc_Incontinence_LR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 0 then cc_Incontinence_D end)),

	cc_Incontinence_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_Incontinence_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_Incontinence_D end)), 0) * 100, --SUM (cc_Incontinence_D)
    cc_Incontinence_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_Incontinence_N end)),
    cc_Incontinence_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_Incontinence_D end)),

	--Prevalence of Occasional or Frequent Bladder or Bowel Incontinence Without a Toileting Plan
	cc_IncWOToiletPlan = cast(SUM ((case when cc_QI_Flag = 1 then cc_IncWOToiletPlan_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_IncWOToiletPlan_D end)), 0) * 100, --SUM (cc_IncWOToiletPlan_D)
    cc_IncWOToiletPlan_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_IncWOToiletPlan_N end)),
    cc_IncWOToiletPlan_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_IncWOToiletPlan_D end)),

	cc_IncWOToiletPlan_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_IncWOToiletPlan_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_IncWOToiletPlan_D end)), 0) * 100, --SUM (cc_IncWOToiletPlan_D)
    cc_IncWOToiletPlan_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_IncWOToiletPlan_N end)),
    cc_IncWOToiletPlan_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_IncWOToiletPlan_D end)),

	--Prevalence of Indwelling Catheters
	cc_Catheter = cast(SUM ((case when cc_QI_Flag = 1 then cc_Catheter_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_Catheter_D end)), 0) * 100, -- SUM (cc_Catheter_D) * 100, 
    cc_Catheter_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_Catheter_N end)),
    cc_Catheter_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_Catheter_D end)),

	cc_Catheter_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_Catheter_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_Catheter_D end)), 0) * 100, --SUM (cc_Catheter_D) * 100, 
    cc_Catheter_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_Catheter_N end)),
    cc_Catheter_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_Catheter_D end)),

	--Prevalence of Fecal Impaction
	cc_FecalImpaction = cast(SUM ((case when cc_QI_Flag = 1 then cc_FecalImpaction_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_FecalImpaction_D end)), 0) * 100, --SUM (cc_FecalImpaction_D) * 100, 
    cc_FecalImpaction_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_FecalImpaction_N end)),
    cc_FecalImpaction_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_FecalImpaction_D end)),

	cc_FecalImpaction_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_FecalImpaction_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_FecalImpaction_D end)), 0) * 100, --SUM (cc_FecalImpaction_D) * 100,
    cc_FecalImpaction_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_FecalImpaction_N end)),
    cc_FecalImpaction_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_FecalImpaction_D end)),

	--Prevalence of Urinary Tract Infections
	cc_UrinaryTractInfection = cast(SUM ((case when cc_QI_Flag = 1 then cc_UrinaryTractInfection_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_UrinaryTractInfection_D end)), 0) * 100, --SUM (cc_UrinaryTractInfection_D) * 100,
    cc_UrinaryTractInfection_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_UrinaryTractInfection_N end)),
    cc_UrinaryTractInfection_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_UrinaryTractInfection_D end)),

	cc_UrinaryTractInfection_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_UrinaryTractInfection_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_UrinaryTractInfection_D end)), 0) * 100, --SUM (cc_UrinaryTractInfection_D) * 100,
    cc_UrinaryTractInfection_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_UrinaryTractInfection_N end)),
    cc_UrinaryTractInfection_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_UrinaryTractInfection_D end)),

	--Prevalence of Weight Loss
	cc_WeightLoss = cast(SUM ((case when cc_QI_Flag = 1 then cc_WeightLoss_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_WeightLoss_D end)), 0) * 100, --SUM (cc_WeightLoss_D)
    cc_WeightLoss_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_WeightLoss_N end)),
    cc_WeightLoss_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_WeightLoss_D end)),

	cc_WeightLoss_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_WeightLoss_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_WeightLoss_D end)), 0) * 100, --SUM (cc_WeightLoss_D)
    cc_WeightLoss_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_WeightLoss_N end)),
    cc_WeightLoss_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_WeightLoss_D end)),

	--Prevalence of Tube Feeding
	cc_TubeFeed = cast(SUM ((case when cc_QI_Flag = 1 then cc_TubeFeed_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_TubeFeed_D end)), 0) * 100, --SUM (cc_TubeFeed_D) * 100,
    cc_TubeFeed_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_TubeFeed_N end)),
    cc_TubeFeed_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_TubeFeed_D end)),

	cc_TubeFeed_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_TubeFeed_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_TubeFeed_D end)), 0) * 100, --SUM (cc_TubeFeed_D) * 100,
    cc_TubeFeed_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_TubeFeed_N end)),
    cc_TubeFeed_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_TubeFeed_D end)),

	--Prevalence of Dehydration
	cc_Dehydration = cast(SUM ((case when cc_QI_Flag = 1 then cc_Dehydration_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_Dehydration_D end)), 0) * 100, --SUM (cc_Dehydration_D) * 100,
    cc_Dehydration_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_Dehydration_N end)),
    cc_Dehydration_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_Dehydration_D end)),

	cc_Dehydration_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_Dehydration_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_Dehydration_D end)), 0) * 100, --SUM (cc_Dehydration_D) * 100,
    cc_Dehydration_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_Dehydration_N end)),
    cc_Dehydration_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_Dehydration_D end)),

	--Prevalence of Bedfast Residents
	cc_BedfastResidents = cast(SUM ((case when cc_QI_Flag = 1 then cc_BedfastResidents_N end)) as float(53))/ nullif(SUM ((case when cc_QI_Flag = 1 then cc_BedfastResidents_D end)), 0) * 100, --SUM (cc_BedfastResidents_D) * 100,
    cc_BedfastResidents_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_BedfastResidents_N end)),
    cc_BedfastResidents_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_BedfastResidents_D end)),

	cc_BedfastResidents_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_BedfastResidents_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_BedfastResidents_D end)), 0) * 100, --SUM (cc_BedfastResidents_D) * 100,
    cc_BedfastResidents_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_BedfastResidents_N end)),
    cc_BedfastResidents_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_BedfastResidents_D end)),

	--Prevalence of Anti-Psychotic Drug Use in the Absence of Psychotic and Related Conditions
	cc_AntiPsychoticDrug = cast(SUM ((case when cc_QI_Flag = 1 then cc_AntiPsychoticDrug_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_AntiPsychoticDrug_D end)), 0) * 100, --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_AntiPsychoticDrug_N end)),
    cc_AntiPsychoticDrug_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_AntiPsychoticDrug_D end)),

	cc_AntiPsychoticDrug_HR = cast(SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_D end)), 0) * 100, --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_HR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_N end)),
    cc_AntiPsychoticDrug_HR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_D end)),

	cc_AntiPsychoticDrug_LR = cast(SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_D end)), 0) * 100, --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_LR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_N end)),
    cc_AntiPsychoticDrug_LR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_D end)),

	cc_AntiPsychoticDrug_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_AntiPsychoticDrug_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_AntiPsychoticDrug_D end)), 0) * 100, --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_AntiPsychoticDrug_N end)),
    cc_AntiPsychoticDrug_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_AntiPsychoticDrug_D end)),

	cc_AntiPsychoticDrug_IP_HR = cast(SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_D end)), 0) * 100, --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_IP_HR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_N end)),
    cc_AntiPsychoticDrug_IP_HR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_D end)),

	cc_AntiPsychoticDrug_IP_LR = cast(SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_D end)), 0) * 100, --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_IP_LR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_N end)),
    cc_AntiPsychoticDrug_IP_LR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_D end)),

	--Prevalence of Anti-Anxiety/Hypnotic Drug Use
	cc_AntiAnxietyDrug = cast(SUM ((case when cc_QI_Flag = 1 then cc_AntiAnxietyDrug_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_AntiAnxietyDrug_D end)), 0) * 100, --SUM (cc_AntiAnxietyDrug_D)
    cc_AntiAnxietyDrug_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_AntiAnxietyDrug_N end)),
    cc_AntiAnxietyDrug_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_AntiAnxietyDrug_D end)),

	cc_AntiAnxietyDrug_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_AntiAnxietyDrug_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_AntiAnxietyDrug_D end)), 0) * 100, --SUM (cc_AntiAnxietyDrug_D)
    cc_AntiAnxietyDrug_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_AntiAnxietyDrug_N end)),
    cc_AntiAnxietyDrug_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_AntiAnxietyDrug_D end)),

	--Prevalence of Hypnotic Drug Use More Than Two Days in Past Week
	cc_TwoPlusHypnoticDrugDays = cast(SUM ((case when cc_QI_Flag = 1 then cc_TwoPlusHypnoticDrugDays_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_TwoPlusHypnoticDrugDays_D end)), 0) * 100, --SUM (cc_TwoPlusHypnoticDrugDays_D) * 100,
    cc_TwoPlusHypnoticDrugDays_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_TwoPlusHypnoticDrugDays_N end)),
    cc_TwoPlusHypnoticDrugDays_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_TwoPlusHypnoticDrugDays_D end)),

	cc_TwoPlusHypnoticDrugDays_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_TwoPlusHypnoticDrugDays_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_TwoPlusHypnoticDrugDays_D end)), 0) * 100, --SUM (cc_TwoPlusHypnoticDrugDays_D) * 100,
    cc_TwoPlusHypnoticDrugDays_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_TwoPlusHypnoticDrugDays_N end)),
    cc_TwoPlusHypnoticDrugDays_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_TwoPlusHypnoticDrugDays_D end)),

	--Prevalence of Daily Physical Restraints
	cc_PhysicalRestraints = cast(SUM ((case when cc_QI_Flag = 1 then cc_PhysicalRestraints_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_PhysicalRestraints_D end)), 0) * 100, --SUM (cc_PhysicalRestraints_D) * 100,
    cc_PhysicalRestraints_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_PhysicalRestraints_N end)),
    cc_PhysicalRestraints_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_PhysicalRestraints_D end)),

	cc_PhysicalRestraints_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_PhysicalRestraints_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_PhysicalRestraints_D end)), 0) * 100, --SUM (cc_PhysicalRestraints_D) * 100,
    cc_PhysicalRestraints_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_PhysicalRestraints_N end)),
    cc_PhysicalRestraints_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_PhysicalRestraints_D end)),

	--Prevalence of Little or No Activity
	cc_NoActivity = cast(SUM ((case when cc_QI_Flag = 1 then cc_NoActivity_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_NoActivity_D end)), 0) * 100, --SUM (cc_NoActivity_D)
    cc_NoActivity_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_NoActivity_N end)),
    cc_NoActivity_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_NoActivity_D end)),

	cc_NoActivity_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_NoActivity_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_NoActivity_D end)), 0) * 100, --SUM (cc_NoActivity_D)
    cc_NoActivity_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_NoActivity_N end)),
    cc_NoActivity_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_NoActivity_D end)),

	--Prevalence of Stage 1–4 Pressure Ulcers
	cc_PressureUlcers = cast(SUM ((case when cc_QI_Flag = 1 then cc_PressureUlcers_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_PressureUlcers_D end)), 0) * 100, --SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_PressureUlcers_N end)),
    cc_PressureUlcers_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_PressureUlcers_D end)),

	cc_PressureUlcers_HR = cast(SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_D end)), 0) * 100, --SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_HR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_N end)),
    cc_PressureUlcers_HR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_D end)),

	cc_PressureUlcers_LR = cast(SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_N end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_D end)), 0) * 100, --SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_LR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_N end)),
    cc_PressureUlcers_LR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_D end)),

	cc_PressureUlcers_IP = cast(SUM ((case when cc_IP_Flag = 1 then cc_PressureUlcers_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_PressureUlcers_D end)), 0) * 100, -- SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_PressureUlcers_N end)),
    cc_PressureUlcers_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_PressureUlcers_D end)),

	cc_PressureUlcers_IP_HR = cast(SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_D end)), 0) * 100, --SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_IP_HR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_N end)),
    cc_PressureUlcers_IP_HR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_D end)),

	cc_PressureUlcers_IP_LR = cast(SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_N end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_D end)), 0) * 100, --SUM (cc_PressureUlcers_D) * 100, 
    cc_PressureUlcers_IP_LR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_N end)),
    cc_PressureUlcers_IP_LR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_D end)),

	--Incidence of New Fractures
	cc_NewFractures = cast(SUM (cc_NewFractures_N) as float(53)) / nullif(SUM (cc_NewFractures_D), 0) * 100,
    cc_NewFractures_Total_Number = SUM (cc_NewFractures_N),
    cc_NewFractures_Total_Denominator = SUM (cc_NewFractures_D),

	--Incidence of Cognitive Impairment
	cc_CognitiveImpairment = cast(SUM (cc_CognitiveImpairment_N) as float(53)) / nullif(SUM (cc_CognitiveImpairment_D), 0) * 100,
    cc_CognitiveImpairment_Total_Number = SUM (cc_CognitiveImpairment_N),
    cc_CognitiveImpairment_Total_Denominator = SUM (cc_CognitiveImpairment_D),

	--Incidence of Decline in Late Loss ADLs
	cc_LateLossADLs = cast(SUM (cc_LateLossADLs_N) as float(53)) / nullif(SUM (cc_LateLossADLs_D), 0) * 100,
    cc_LateLossADLs_Total_Number = SUM (cc_LateLossADLs_N),
    cc_LateLossADLs_Total_Denominator = SUM (cc_LateLossADLs_D),

	--Incidence of Decline in Range of Motion
	cc_ROMDecline = cast(SUM (cc_ROMDecline_N) as float(53)) / nullif(SUM (cc_ROMDecline_D), 0) * 100,
    cc_ROMDecline_Total_Number = SUM (cc_ROMDecline_N),
    cc_ROMDecline_Total_Denominator = SUM (cc_ROMDecline_D),
	
	TotalCases = count(*),
	Total_QualityIndicators = sum(cc_QI_Flag),
	Total_IntakeProfile = sum(cc_IP_Flag)
from MDS20_Quality_Indicators_Detail_VR
	--Not sure if we need to pick the last assessment for one visit per year.
	--inner join
	--(select zzAssessmentLink, max(A3) as MaxA3 from [dbo].[MDS20_Quality_Indicators_Detail_VR]
	-- group by zzAssessmentLink) z on MDS20_Quality_Indicators_Detail_VR.zzAssessmentLink = z.zzAssessmentLink
	--	and MDS20_Quality_Indicators_Detail_VR.A3 = z.maxA3
group by InstitutionNumber, InstitutionNumberDesc, FiscalYear
/*  --before ED - 02171 
	--Prevalence of Falls
	cc_Fall = isnull(cast(sum((case when cc_QI_Flag = 1 then cc_Fall_N else 0 end)) as float(53)) / nullif(sum((case when cc_QI_Flag = 1 then cc_Fall_D else 0 end)), 0) * 100, 0), --SUM (cc_Fall_D) * 100,
	cc_Fall_Total_Number = sum((case when cc_QI_Flag = 1 then cc_Fall_N else 0 end)),
	cc_Fall_Total_Denominator = sum((case when cc_QI_Flag = 1 then cc_Fall_D else 0 end)),
	
	cc_Fall_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_Fall_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_Fall_D else 0 end)), 0) * 100, 0), --SUM (cc_Fall_D) * 100,
	cc_Fall_IP_Total_Number = sum((case when cc_IP_Flag = 1 then cc_Fall_N else 0 end)),
	cc_Fall_IP_Total_Denominator = sum((case when cc_IP_Flag = 1 then cc_Fall_D else 0 end)),

	--Prevalence of Behavioural Symptoms Affecting Others
	cc_BehavSymptoms = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_BehavSymptoms_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_BehavSymptoms_D else 0 end)), 0) * 100, 0), --SUM (cc_BehavSymptoms_D) * 100,
	cc_BehavSymptoms_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_BehavSymptoms_N else 0 end)),
	cc_BehavSymptoms_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_BehavSymptoms_D else 0 end)),
	
	cc_BehavSymptoms_HR = isnull(cast(SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_D else 0 end)), 0) * 100, 0), --SUM (cc_BehavSymptoms_D) * 100,
	cc_BehavSymptoms_HR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_N else 0 end)),
	cc_BehavSymptoms_HR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_D else 0 end)),
	
	cc_BehavSymptoms_LR = isnull(cast(SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_D else 0 end)), 0) * 100, 0), --SUM (cc_BehavSymptoms_D) * 100,
    cc_BehavSymptoms_LR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_N else 0 end)),
    cc_BehavSymptoms_LR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_D else 0 end)),

	cc_BehavSymptoms_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_BehavSymptoms_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_BehavSymptoms_D else 0 end)), 0) * 100, 0), --SUM (cc_BehavSymptoms_D) * 100,
    cc_BehavSymptoms_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_BehavSymptoms_N else 0 end)),
    cc_BehavSymptoms_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_BehavSymptoms_D else 0 end)),

	cc_BehavSymptoms_IP_HR = isnull(cast(SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_D else 0 end)), 0) * 100, 0), --SUM (cc_BehavSymptoms_D) * 100,
    cc_BehavSymptoms_IP_HR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_N else 0 end)),
    cc_BehavSymptoms_IP_HR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 1 then cc_BehavSymptoms_D else 0 end)),
    
    cc_BehavSymptoms_IP_LR = isnull(cast(SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_D else 0 end)), 0) * 100, 0), --SUM (cc_BehavSymptoms_D) * 100,
    cc_BehavSymptoms_IP_LR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_N else 0 end)),
    cc_BehavSymptoms_IP_LR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_BehavSymptoms_Risk = 0 then cc_BehavSymptoms_D else 0 end)),
    
	--Prevalence of Symptoms of Depression
	cc_DepressionSymptoms = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_DepressionSymptoms_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_DepressionSymptoms_D else 0 end)), 0) * 100, 0), --SUM (cc_DepressionSymptoms_D) * 100,
    cc_DepressionSymptoms_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_DepressionSymptoms_N else 0 end)),
    cc_DepressionSymptoms_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_DepressionSymptoms_D else 0 end)),

	cc_DepressionSymptoms_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_DepressionSymptoms_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_DepressionSymptoms_D else 0 end)), 0) * 100, 0), --SUM (cc_DepressionSymptoms_D) * 100,
    cc_DepressionSymptoms_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_DepressionSymptoms_N else 0 end)),
    cc_DepressionSymptoms_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_DepressionSymptoms_D else 0 end)),

	--Prevalence of Depression Without Anti-Depressant Therapy
	cc_DepWOAntiDepThpy = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_DepWOAntiDepThpy_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_DepWOAntiDepThpy_D else 0 end)), 0) * 100, 0), --SUM (cc_DepWOAntiDepThpy_D) * 100,
    cc_DepWOAntiDepThpy_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_DepWOAntiDepThpy_N else 0 end)),
    cc_DepWOAntiDepThpy_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_DepWOAntiDepThpy_D else 0 end)),

	cc_DepWOAntiDepThpy_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_DepWOAntiDepThpy_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_DepWOAntiDepThpy_D else 0 end)), 0) * 100, 0), --SUM (cc_DepWOAntiDepThpy_D) * 100,
    cc_DepWOAntiDepThpy_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_DepWOAntiDepThpy_N else 0 end)),
    cc_DepWOAntiDepThpy_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_DepWOAntiDepThpy_D else 0 end)),

	--Prevalence of Use of 9 or More Different Medications
	cc_NinePlusMedications = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_NinePlusMedications_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_NinePlusMedications_D else 0 end)), 0) * 100, 0), --SUM (cc_NinePlusMedications_D) * 100,
    cc_NinePlusMedications_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_NinePlusMedications_N else 0 end)),
    cc_NinePlusMedications_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_NinePlusMedications_D else 0 end)),

	cc_NinePlusMedications_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_NinePlusMedications_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_NinePlusMedications_D else 0 end)), 0) * 100, 0), --SUM (cc_NinePlusMedications_D) * 100,
    cc_NinePlusMedications_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_NinePlusMedications_N else 0 end)),
    cc_NinePlusMedications_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_NinePlusMedications_D else 0 end)),

	--Prevalence of Bladder or Bowel Incontinence
	cc_Incontinence = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_Incontinence_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_Incontinence_D else 0 end)), 0) * 100, 0),	--SUM (cc_Incontinence_D)
    cc_Incontinence_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_Incontinence_N else 0 end)),
    cc_Incontinence_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_Incontinence_D else 0 end)),

	cc_Incontinence_HR = isnull(cast(SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 1 then cc_Incontinence_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 1 then cc_Incontinence_D else 0 end)), 0) * 100, 0), --SUM (cc_Incontinence_D)
    cc_Incontinence_HR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 1 then cc_Incontinence_N else 0 end)),
    cc_Incontinence_HR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 1 then cc_Incontinence_D else 0 end)),

	cc_Incontinence_LR = isnull(cast(SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 0 then cc_Incontinence_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 0 then cc_Incontinence_D else 0 end)), 0) * 100, 0), --SUM (cc_Incontinence_D)
    cc_Incontinence_LR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 0 then cc_Incontinence_N else 0 end)),
    cc_Incontinence_LR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_Incontinence_Risk = 0 then cc_Incontinence_D else 0 end)),

	cc_Incontinence_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_Incontinence_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_Incontinence_D else 0 end)), 0) * 100, 0), --SUM (cc_Incontinence_D)
    cc_Incontinence_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_Incontinence_N else 0 end)),
    cc_Incontinence_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_Incontinence_D else 0 end)),

	--Prevalence of Occasional or Frequent Bladder or Bowel Incontinence Without a Toileting Plan
	cc_IncWOToiletPlan = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_IncWOToiletPlan_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_IncWOToiletPlan_D else 0 end)), 0) * 100, 0), --SUM (cc_IncWOToiletPlan_D)
    cc_IncWOToiletPlan_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_IncWOToiletPlan_N else 0 end)),
    cc_IncWOToiletPlan_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_IncWOToiletPlan_D else 0 end)),

	cc_IncWOToiletPlan_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_IncWOToiletPlan_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_IncWOToiletPlan_D else 0 end)), 0) * 100, 0), --SUM (cc_IncWOToiletPlan_D)
    cc_IncWOToiletPlan_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_IncWOToiletPlan_N else 0 end)),
    cc_IncWOToiletPlan_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_IncWOToiletPlan_D else 0 end)),

	--Prevalence of Indwelling Catheters
	cc_Catheter = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_Catheter_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_Catheter_D else 0 end)), 0) * 100, 0), -- SUM (cc_Catheter_D) * 100, 
    cc_Catheter_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_Catheter_N else 0 end)),
    cc_Catheter_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_Catheter_D else 0 end)),

	cc_Catheter_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_Catheter_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_Catheter_D else 0 end)), 0) * 100, 0), --SUM (cc_Catheter_D) * 100, 
    cc_Catheter_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_Catheter_N else 0 end)),
    cc_Catheter_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_Catheter_D else 0 end)),

	--Prevalence of Fecal Impaction
	cc_FecalImpaction = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_FecalImpaction_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_FecalImpaction_D else 0 end)), 0) * 100, 0), --SUM (cc_FecalImpaction_D) * 100, 
    cc_FecalImpaction_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_FecalImpaction_N else 0 end)),
    cc_FecalImpaction_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_FecalImpaction_D else 0 end)),

	cc_FecalImpaction_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_FecalImpaction_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_FecalImpaction_D else 0 end)), 0) * 100, 0), --SUM (cc_FecalImpaction_D) * 100,
    cc_FecalImpaction_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_FecalImpaction_N else 0 end)),
    cc_FecalImpaction_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_FecalImpaction_D else 0 end)),

	--Prevalence of Urinary Tract Infections
	cc_UrinaryTractInfection = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_UrinaryTractInfection_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_UrinaryTractInfection_D else 0 end)), 0) * 100, 0), --SUM (cc_UrinaryTractInfection_D) * 100,
    cc_UrinaryTractInfection_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_UrinaryTractInfection_N else 0 end)),
    cc_UrinaryTractInfection_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_UrinaryTractInfection_D else 0 end)),

	cc_UrinaryTractInfection_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_UrinaryTractInfection_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_UrinaryTractInfection_D else 0 end)), 0) * 100, 0), --SUM (cc_UrinaryTractInfection_D) * 100,
    cc_UrinaryTractInfection_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_UrinaryTractInfection_N else 0 end)),
    cc_UrinaryTractInfection_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_UrinaryTractInfection_D else 0 end)),

	--Prevalence of Weight Loss
	cc_WeightLoss = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_WeightLoss_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_WeightLoss_D else 0 end)), 0) * 100, 0), --SUM (cc_WeightLoss_D)
    cc_WeightLoss_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_WeightLoss_N else 0 end)),
    cc_WeightLoss_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_WeightLoss_D else 0 end)),

	cc_WeightLoss_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_WeightLoss_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_WeightLoss_D else 0 end)), 0) * 100, 0), --SUM (cc_WeightLoss_D)
    cc_WeightLoss_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_WeightLoss_N else 0 end)),
    cc_WeightLoss_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_WeightLoss_D else 0 end)),

	--Prevalence of Tube Feeding
	cc_TubeFeed = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_TubeFeed_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_TubeFeed_D else 0 end)), 0) * 100, 0), --SUM (cc_TubeFeed_D) * 100,
    cc_TubeFeed_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_TubeFeed_N else 0 end)),
    cc_TubeFeed_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_TubeFeed_D else 0 end)),

	cc_TubeFeed_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_TubeFeed_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_TubeFeed_D else 0 end)), 0) * 100, 0), --SUM (cc_TubeFeed_D) * 100,
    cc_TubeFeed_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_TubeFeed_N else 0 end)),
    cc_TubeFeed_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_TubeFeed_D else 0 end)),

	--Prevalence of Dehydration
	cc_Dehydration = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_Dehydration_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_Dehydration_D else 0 end)), 0) * 100, 0), --SUM (cc_Dehydration_D) * 100,
    cc_Dehydration_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_Dehydration_N else 0 end)),
    cc_Dehydration_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_Dehydration_D else 0 end)),

	cc_Dehydration_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_Dehydration_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_Dehydration_D else 0 end)), 0) * 100, 0), --SUM (cc_Dehydration_D) * 100,
    cc_Dehydration_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_Dehydration_N else 0 end)),
    cc_Dehydration_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_Dehydration_D else 0 end)),

	--Prevalence of Bedfast Residents
	cc_BedfastResidents = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_BedfastResidents_N else 0 end)) as float(53))/ nullif(SUM ((case when cc_QI_Flag = 1 then cc_BedfastResidents_D else 0 end)), 0) * 100, 0), --SUM (cc_BedfastResidents_D) * 100,
    cc_BedfastResidents_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_BedfastResidents_N else 0 end)),
    cc_BedfastResidents_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_BedfastResidents_D else 0 end)),

	cc_BedfastResidents_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_BedfastResidents_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_BedfastResidents_D else 0 end)), 0) * 100, 0), --SUM (cc_BedfastResidents_D) * 100,
    cc_BedfastResidents_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_BedfastResidents_N else 0 end)),
    cc_BedfastResidents_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_BedfastResidents_D else 0 end)),

	--Prevalence of Anti-Psychotic Drug Use in the Absence of Psychotic and Related Conditions
	cc_AntiPsychoticDrug = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_AntiPsychoticDrug_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_AntiPsychoticDrug_D else 0 end)), 0) * 100, 0), --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_AntiPsychoticDrug_N else 0 end)),
    cc_AntiPsychoticDrug_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_AntiPsychoticDrug_D else 0 end)),

	cc_AntiPsychoticDrug_HR = isnull(cast(SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_D else 0 end)), 0) * 100, 0), --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_HR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_N else 0 end)),
    cc_AntiPsychoticDrug_HR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_D else 0 end)),

	cc_AntiPsychoticDrug_LR = isnull(cast(SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_D else 0 end)), 0) * 100, 0), --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_LR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_N else 0 end)),
    cc_AntiPsychoticDrug_LR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_D else 0 end)),

	cc_AntiPsychoticDrug_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_AntiPsychoticDrug_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_AntiPsychoticDrug_D else 0 end)), 0) * 100, 0), --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_AntiPsychoticDrug_N else 0 end)),
    cc_AntiPsychoticDrug_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_AntiPsychoticDrug_D else 0 end)),

	cc_AntiPsychoticDrug_IP_HR = isnull(cast(SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_D else 0 end)), 0) * 100, 0), --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_IP_HR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_N else 0 end)),
    cc_AntiPsychoticDrug_IP_HR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 1 then cc_AntiPsychoticDrug_D else 0 end)),

	cc_AntiPsychoticDrug_IP_LR = isnull(cast(SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_D else 0 end)), 0) * 100, 0), --SUM (cc_AntiPsychoticDrug_D)
    cc_AntiPsychoticDrug_IP_LR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_N else 0 end)),
    cc_AntiPsychoticDrug_IP_LR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_AntiPsychoticDrug_Risk = 0 then cc_AntiPsychoticDrug_D else 0 end)),

	--Prevalence of Anti-Anxiety/Hypnotic Drug Use
	cc_AntiAnxietyDrug = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_AntiAnxietyDrug_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_AntiAnxietyDrug_D else 0 end)), 0) * 100, 0), --SUM (cc_AntiAnxietyDrug_D)
    cc_AntiAnxietyDrug_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_AntiAnxietyDrug_N else 0 end)),
    cc_AntiAnxietyDrug_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_AntiAnxietyDrug_D else 0 end)),

	cc_AntiAnxietyDrug_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_AntiAnxietyDrug_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_AntiAnxietyDrug_D else 0 end)), 0) * 100, 0), --SUM (cc_AntiAnxietyDrug_D)
    cc_AntiAnxietyDrug_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_AntiAnxietyDrug_N else 0 end)),
    cc_AntiAnxietyDrug_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_AntiAnxietyDrug_D else 0 end)),

	--Prevalence of Hypnotic Drug Use More Than Two Days in Past Week
	cc_TwoPlusHypnoticDrugDays = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_TwoPlusHypnoticDrugDays_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_TwoPlusHypnoticDrugDays_D else 0 end)), 0) * 100, 0), --SUM (cc_TwoPlusHypnoticDrugDays_D) * 100,
    cc_TwoPlusHypnoticDrugDays_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_TwoPlusHypnoticDrugDays_N else 0 end)),
    cc_TwoPlusHypnoticDrugDays_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_TwoPlusHypnoticDrugDays_D else 0 end)),

	cc_TwoPlusHypnoticDrugDays_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_TwoPlusHypnoticDrugDays_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_TwoPlusHypnoticDrugDays_D else 0 end)), 0) * 100, 0), --SUM (cc_TwoPlusHypnoticDrugDays_D) * 100,
    cc_TwoPlusHypnoticDrugDays_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_TwoPlusHypnoticDrugDays_N else 0 end)),
    cc_TwoPlusHypnoticDrugDays_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_TwoPlusHypnoticDrugDays_D else 0 end)),

	--Prevalence of Daily Physical Restraints
	cc_PhysicalRestraints = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_PhysicalRestraints_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_PhysicalRestraints_D else 0 end)), 0) * 100, 0), --SUM (cc_PhysicalRestraints_D) * 100,
    cc_PhysicalRestraints_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_PhysicalRestraints_N else 0 end)),
    cc_PhysicalRestraints_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_PhysicalRestraints_D else 0 end)),

	cc_PhysicalRestraints_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_PhysicalRestraints_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_PhysicalRestraints_D else 0 end)), 0) * 100, 0), --SUM (cc_PhysicalRestraints_D) * 100,
    cc_PhysicalRestraints_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_PhysicalRestraints_N else 0 end)),
    cc_PhysicalRestraints_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_PhysicalRestraints_D else 0 end)),

	--Prevalence of Little or No Activity
	cc_NoActivity = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_NoActivity_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_NoActivity_D else 0 end)), 0) * 100, 0), --SUM (cc_NoActivity_D)
    cc_NoActivity_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_NoActivity_N else 0 end)),
    cc_NoActivity_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_NoActivity_D else 0 end)),

	cc_NoActivity_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_NoActivity_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_NoActivity_D else 0 end)), 0) * 100, 0), --SUM (cc_NoActivity_D)
    cc_NoActivity_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_NoActivity_N else 0 end)),
    cc_NoActivity_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_NoActivity_D else 0 end)),

	--Prevalence of Stage 1–4 Pressure Ulcers
	cc_PressureUlcers = isnull(cast(SUM ((case when cc_QI_Flag = 1 then cc_PressureUlcers_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 then cc_PressureUlcers_D else 0 end)), 0) * 100, 0), --SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_Total_Number = SUM ((case when cc_QI_Flag = 1 then cc_PressureUlcers_N else 0 end)),
    cc_PressureUlcers_Total_Denominator = SUM ((case when cc_QI_Flag = 1 then cc_PressureUlcers_D else 0 end)),

	cc_PressureUlcers_HR = isnull(cast(SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_D else 0 end)), 0) * 100, 0), --SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_HR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_N else 0 end)),
    cc_PressureUlcers_HR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_D else 0 end)),

	cc_PressureUlcers_LR = isnull(cast(SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_D else 0 end)), 0) * 100, 0), --SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_LR_Total_Number = SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_N else 0 end)),
    cc_PressureUlcers_LR_Total_Denominator = SUM ((case when cc_QI_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_D else 0 end)),

	cc_PressureUlcers_IP = isnull(cast(SUM ((case when cc_IP_Flag = 1 then cc_PressureUlcers_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 then cc_PressureUlcers_D else 0 end)), 0) * 100, 0), -- SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_IP_Total_Number = SUM ((case when cc_IP_Flag = 1 then cc_PressureUlcers_N else 0 end)),
    cc_PressureUlcers_IP_Total_Denominator = SUM ((case when cc_IP_Flag = 1 then cc_PressureUlcers_D else 0 end)),

	cc_PressureUlcers_IP_HR = isnull(cast(SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_D else 0 end)), 0) * 100, 0), --SUM (cc_PressureUlcers_D) * 100,
    cc_PressureUlcers_IP_HR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_N else 0 end)),
    cc_PressureUlcers_IP_HR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 1 then cc_PressureUlcers_D else 0 end)),

	cc_PressureUlcers_IP_LR = isnull(cast(SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_N else 0 end)) as float(53)) / nullif(SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_D else 0 end)), 0) * 100, 0), --SUM (cc_PressureUlcers_D) * 100, 
    cc_PressureUlcers_IP_LR_Total_Number = SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_N else 0 end)),
    cc_PressureUlcers_IP_LR_Total_Denominator = SUM ((case when cc_IP_Flag = 1 AND cc_PressureUlcers_Risk = 0 then cc_PressureUlcers_D else 0 end)),

	--Incidence of New Fractures
	cc_NewFractures = isnull(cast(SUM (cc_NewFractures_N) as float(53)) / nullif(SUM (cc_NewFractures_D), 0) * 100, 0),
    cc_NewFractures_Total_Number = SUM (cc_NewFractures_N),
    cc_NewFractures_Total_Denominator = SUM (cc_NewFractures_D),

	--Incidence of Cognitive Impairment
	cc_CognitiveImpairment = isnull(cast(SUM (cc_CognitiveImpairment_N) as float(53)) / nullif(SUM (cc_CognitiveImpairment_D), 0) * 100, 0),
    cc_CognitiveImpairment_Total_Number = SUM (cc_CognitiveImpairment_N),
    cc_CognitiveImpairment_Total_Denominator = SUM (cc_CognitiveImpairment_D),

	--Incidence of Decline in Late Loss ADLs
	cc_LateLossADLs = isnull(cast(SUM (cc_LateLossADLs_N) as float(53)) / nullif(SUM (cc_LateLossADLs_D), 0) * 100, 0),
    cc_LateLossADLs_Total_Number = SUM (cc_LateLossADLs_N),
    cc_LateLossADLs_Total_Denominator = SUM (cc_LateLossADLs_D),

	--Incidence of Decline in Range of Motion
	cc_ROMDecline = isnull(cast(SUM (cc_ROMDecline_N) as float(53)) / nullif(SUM (cc_ROMDecline_D), 0) * 100, 0),
    cc_ROMDecline_Total_Number = SUM (cc_ROMDecline_N),
    cc_ROMDecline_Total_Denominator = SUM (cc_ROMDecline_D),
*/
    

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_1_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[MDS20_Quarterly_Assessment_1_Form_VR]
AS
SELECT     zzAbstractLink, zzLinkBackgroundID, URI_AA1, MaidenName, LastName, MiddleName, FirstName, RoomUnit, RoomUnitDesc, Gender_AA2, GenderDesc_AA2, 
                      Birthdate_AA3a AS Birthdate_A3a, BirthdateEstimated_AA3b AS BirthdateEstimated_A3b, BirthDateEstimatedDesc_AA3b AS BirthDateEstimatedDesc_A3b, 
                      Treaty_band_AA4a AS Treaty_band_A4a, MaritalStatus_A5, MaritalStatusDesc_A5, FacilityNumber_AA6, FacilityNumberDesc_AA6, HealthCareNumber_AA5a, 
                      HCNProvince_AA5b, HCNProvinceDesc_AA5b, HCNVersion, Hospital, HospitalDesc, HealthRecordNumber_A6a, HealthRegisterNumber_A6b, ReasonAssessment_AA8, 
                      ReasonAssessmentDesc_AA8, IsCurrent, IsSubmited, IsSubmitedDesc, IsValidated, IsValidatedDesc, IsCompleted, IsCompletedDesc, IsDeleted, IsDeletedDesc, 
                      SiteNumber, SiteNumberDesc, CoderNumber, CoderNumberDesc, InterfaceDate, InterfaceTime, InterfaceCoder, InterfaceCoderDesc, InputDate, InputTime, 
                      DataEntryCoder, DataEntryCoderDesc, FinishDate, FinishTime, Secret, SecretDesc, TSIDate, TSITime, TSICoder, TSICoderDesc, AssessmentDate_A3, NextAssessmentDate, 
                      AboriginalIdentityFirstNations_AA4a, AboriginalIdentityFirstNationsDesc_AA4a, AboriginalIdentityMetiis_AA4b, AboriginalIdentityMetiisDesc_AA4b, 
                      AboriginalIdentityInuit_AA4c, AboriginalIdentityInuitDesc_AA4c
FROM         dbo.MDS20_VR
WHERE     (AA8_CIHI IN (''05'', ''10'')) AND (zzLinkBackgroundID <> zzAbstractLink)


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_2_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[MDS20_Quarterly_Assessment_2_Form_VR]
AS
SELECT     dbo.MDS20_VR.ReasonAssessment_AA8, dbo.MDS20_VR.ReasonAssessmentDesc_AA8, dbo.MDS20_VR.zzAbstractLink, 
                      dbo.MDS20_Shared_1_VR.GuardianLegal_A9a, dbo.MDS20_Shared_1_VR.GuardianLegalDesc_A9a, dbo.MDS20_Shared_1_VR.GuardianAttorney_A9b, 
                      dbo.MDS20_Shared_1_VR.GuardianAttorneyDesc_A9b, dbo.MDS20_Shared_1_VR.GuardianOther_A9c, dbo.MDS20_Shared_1_VR.GuardianOtherDesc_A9c, 
                      dbo.MDS20_Shared_1_VR.GuardianFamily_A9d, dbo.MDS20_Shared_1_VR.GuardianFamilyDesc_A9d, dbo.MDS20_Shared_1_VR.GuardianHealth_A9e, 
                      dbo.MDS20_Shared_1_VR.GuardianHealthDesc_A9e, dbo.MDS20_Shared_1_VR.GuardianSelf_A9f, dbo.MDS20_Shared_1_VR.GuardianSelfDesc_A9f, 
                      dbo.MDS20_Shared_1_VR.GuardianNone_A9g, dbo.MDS20_Shared_1_VR.GuardianNoneDesc_A9g, dbo.MDS20_Shared_1_VR.AdvDirLiving_A10a, 
                      dbo.MDS20_Shared_1_VR.AdvDirLivingDesc_A10a, dbo.MDS20_Shared_1_VR.AdvDirNoResuscitate_A10b, 
                      dbo.MDS20_Shared_1_VR.AdvDirNoResuscitateDesc_A10b, dbo.MDS20_Shared_1_VR.AdvDirNoHospitalize_A10c, 
                      dbo.MDS20_Shared_1_VR.AdvDirNoHospitalizeDesc_A10c, dbo.MDS20_Shared_1_VR.AdvDirOrgan_A10d, dbo.MDS20_Shared_1_VR.AdvDirOrganDesc_A10d, 
                      dbo.MDS20_Shared_1_VR.AdvDirAutopsy_A10e, dbo.MDS20_Shared_1_VR.AdvDirAutopsyDesc_A10e, dbo.MDS20_Shared_1_VR.AdvDirFeeding_A10f, 
                      dbo.MDS20_Shared_1_VR.AdvDirFeedingDesc_A10f, dbo.MDS20_Shared_1_VR.AdvDirMedication_A10g, dbo.MDS20_Shared_1_VR.AdvDirMedicationDesc_A10g, 
                      dbo.MDS20_Shared_1_VR.AdvDirOther_A10h, dbo.MDS20_Shared_1_VR.AdvDirOtherDesc_A10h, dbo.MDS20_Shared_1_VR.AdvDirNone_A10i, 
                      dbo.MDS20_Shared_1_VR.AdvDirNoneDesc_A10i, dbo.MDS20_Shared_1_VR.DecisionMakerForPersonalCare_A11a, 
                      dbo.MDS20_Shared_1_VR.DecisionMakerForPersonalCareDesc_A11a, dbo.MDS20_Shared_1_VR.DecisionMakerForProperty_A11b, 
                      dbo.MDS20_Shared_1_VR.DecisionMakerForPropertyDesc_A11b, dbo.MDS20_Shared_1_VR.AdvanceDirectivesResuscitating_A12a, 
                      dbo.MDS20_Shared_1_VR.AdvanceDirectivesResuscitatingDesc_A12a, dbo.MDS20_Shared_1_VR.AdvanceDirectivesHospitalizing_A12b, 
                      dbo.MDS20_Shared_1_VR.AdvanceDirectivesHospitalizingDesc_A12b, dbo.MDS20_Shared_1_VR.Comatose_B1, dbo.MDS20_Shared_1_VR.ComatoseDesc_B1, 
                      dbo.MDS20_Shared_1_VR.MemoryShort_B2a, dbo.MDS20_Shared_1_VR.MemoryShortDesc_B2a, dbo.MDS20_Shared_1_VR.MemoryLong_B2b, 
                      dbo.MDS20_Shared_1_VR.MemoryLongDesc_B2b, dbo.MDS20_Shared_1_VR.MemAbilityCurrent_B3a, dbo.MDS20_Shared_1_VR.MemAbilityCurrentDesc_B3a, 
                      dbo.MDS20_Shared_1_VR.MemAbilityOwnRoom_B3b, dbo.MDS20_Shared_1_VR.MemAbilityOwnRoomDesc_B3b, dbo.MDS20_Shared_1_VR.MemAbilityStaff_B3c, 
                      dbo.MDS20_Shared_1_VR.MemAbilityStaffDesc_B3c, dbo.MDS20_Shared_1_VR.MemAbilityFacility_B3d, dbo.MDS20_Shared_1_VR.MemAbilityFacilityDesc_B3d, 
                      dbo.MDS20_Shared_1_VR.MemAbilityNone_B3e, dbo.MDS20_Shared_1_VR.MemAbilityNoneDesc_B3e, dbo.MDS20_Shared_1_VR.CognitiveSkills_B4, 
                      dbo.MDS20_Shared_1_VR.CognitiveSkillsDesc_B4, dbo.MDS20_Shared_1_VR.DisorderEasily_B5a, dbo.MDS20_Shared_1_VR.DisorderEasilyDesc_B5a, 
                      dbo.MDS20_Shared_1_VR.DisorderPerception_B5b, dbo.MDS20_Shared_1_VR.DisorderPerceptionDesc_B5b, dbo.MDS20_Shared_1_VR.DisorderSpeech_B5c, 
                      dbo.MDS20_Shared_1_VR.DisorderSpeechDesc_B5c, dbo.MDS20_Shared_1_VR.DisorderRestless_B5d, dbo.MDS20_Shared_1_VR.DisorderRestlessDesc_B5d, 
                      dbo.MDS20_Shared_1_VR.DisorderLethargy_B5e, dbo.MDS20_Shared_1_VR.DisorderLethargyDesc_B5e, dbo.MDS20_Shared_1_VR.DisorderMental_B5f, 
                      dbo.MDS20_Shared_1_VR.DisorderMentalDesc_B5f, dbo.MDS20_Shared_1_VR.ChangeCognitive_B6, dbo.MDS20_Shared_1_VR.ChangeCognitiveDesc_B6, 
                      dbo.MDS20_Shared_1_VR.UnderStood_C4, dbo.MDS20_Shared_1_VR.UnderStoodDesc_C4, dbo.MDS20_Shared_1_VR.AbilityUnderStood_C6, 
                      dbo.MDS20_Shared_1_VR.AbilityUnderStoodDesc_C6, dbo.MDS20_Shared_1_VR.ChangeComm_C7, dbo.MDS20_Shared_1_VR.ChangeCommDesc_C7, 
                      dbo.MDS20_Shared_1_VR.DepressionNegative_E1a, dbo.MDS20_Shared_1_VR.DepressionNegativeDesc_E1a, 
                      dbo.MDS20_Shared_1_VR.DepressionRepeatQues_E1b, dbo.MDS20_Shared_1_VR.DepressionRepeatQuesDesc_E1b, 
                      dbo.MDS20_Shared_1_VR.DepressionRepeatVerb_E1c, dbo.MDS20_Shared_1_VR.DepressionRepeatVerbDesc_E1c, 
                      dbo.MDS20_Shared_1_VR.DepressionAnger_E1d, dbo.MDS20_Shared_1_VR.DepressionAngerDesc_E1d, dbo.MDS20_Shared_1_VR.DepressionDeprecation_E1e, 
                      dbo.MDS20_Shared_1_VR.DepressionDeprecationDesc_E1e, dbo.MDS20_Shared_1_VR.DepressionUnrealistic_E1f, 
                      dbo.MDS20_Shared_1_VR.DepressionUnrealisticDesc_E1f, dbo.MDS20_Shared_1_VR.DepressionTerrible_E1g, 
                      dbo.MDS20_Shared_1_VR.DepressionTerribleDesc_E1g, dbo.MDS20_Shared_1_VR.DepressionComplaints_E1h, 
                      dbo.MDS20_Shared_1_VR.DepressionComplaintsDesc_E1h, dbo.MDS20_Shared_1_VR.DepressionNonHealth_E1i, 
                      dbo.MDS20_Shared_1_VR.DepressionNonHealthDesc_E1i, dbo.MDS20_Shared_1_VR.DepressionUnpleasant_E1j, 
                      dbo.MDS20_Shared_1_VR.DepressionUnpleasantDesc_E1j, dbo.MDS20_Shared_1_VR.DepressionChange_E1k, 
                      dbo.MDS20_Shared_1_VR.DepressionChangeDesc_E1k, dbo.MDS20_Shared_1_VR.DepressionSad_E1l, dbo.MDS20_Shared_1_VR.DepressionSadDesc_E1l, 
                      dbo.MDS20_Shared_1_VR.DepressionCrying_E1m, dbo.MDS20_Shared_1_VR.DepressionCryingDesc_E1m, dbo.MDS20_Shared_1_VR.DepressionPhysical_E1n, 
                      dbo.MDS20_Shared_1_VR.DepressionPhysicalDesc_E1n, dbo.MDS20_Shared_1_VR.DepressionInterest_E1o, 
                      dbo.MDS20_Shared_1_VR.DepressionInterestDesc_E1o, dbo.MDS20_Shared_1_VR.DepressionInteraction_E1p, 
                      dbo.MDS20_Shared_1_VR.DepressionInteractionDesc_E1p, dbo.MDS20_Shared_1_VR.Persistence_E2, dbo.MDS20_Shared_1_VR.PersistenceDesc_E2, 
                      dbo.MDS20_Shared_1_VR.ChangeMood_E3, dbo.MDS20_Shared_1_VR.ChangeMoodDesc_E3, dbo.MDS20_Shared_1_VR.BehaviorWanderingFre_E4aA, 
                      dbo.MDS20_Shared_1_VR.BehaviorWanderingFreDesc_E4aA, dbo.MDS20_Shared_1_VR.BehaviorWanderingAlt_E4aB, 
                      dbo.MDS20_Shared_1_VR.BehaviorWanderingAltDesc_E4aB, dbo.MDS20_Shared_1_VR.BehaviorVerballyFre_E4bA, 
                      dbo.MDS20_Shared_1_VR.BehaviorVerballyFreDesc_E4bA, dbo.MDS20_Shared_1_VR.BehaviorVerballyAlt_E4bB, 
                      dbo.MDS20_Shared_1_VR.BehaviorVerballyAltDesc_E4bB, dbo.MDS20_Shared_1_VR.BehaviorPhysicallyFre_E4cA, 
                      dbo.MDS20_Shared_1_VR.BehaviorPhysicalFreDesc_E4cA, dbo.MDS20_Shared_1_VR.BehaviorPhysicallyAlt_E4cB, 
                      dbo.MDS20_Shared_1_VR.BehaviorPhysicalAltDesc_E4cB, dbo.MDS20_Shared_1_VR.BehaviorSociallyFre_E4dA, 
                      dbo.MDS20_Shared_1_VR.BehaviorSociallyFreDesc_E4dA, dbo.MDS20_Shared_1_VR.BehaviorSociallyAlt_E4dB, 
                      dbo.MDS20_Shared_1_VR.BehaviorSociallyAltDesc_E4dB, dbo.MDS20_Shared_1_VR.BehaviorResistsFre_E4eA, 
                      dbo.MDS20_Shared_1_VR.BehaviorResistsFreDesc_E4eA, dbo.MDS20_Shared_1_VR.BehaviorResistsAlt_E4eB, 
                      dbo.MDS20_Shared_1_VR.BehaviorResistsAltDesc_E4eB, dbo.MDS20_Shared_1_VR.ChangeBehave_E5, dbo.MDS20_Shared_1_VR.ChangeBehaveDesc_E5
FROM         dbo.MDS20_VR LEFT OUTER JOIN
                      dbo.MDS20_Shared_1_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Shared_1_VR.zzAbstractLink
WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''05'', ''10'')) AND (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_3_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'







CREATE  VIEW [dbo].[MDS20_Quarterly_Assessment_3_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.ReasonAssessment_AA8, 
                      dbo.MDS20_VR.ReasonAssessmentDesc_AA8, dbo.MDS20_Shared_2_VR.Interacting_F1a, dbo.MDS20_Shared_2_VR.InteractingDesc_F1a, 
                      dbo.MDS20_Shared_2_VR.PlanActivity_F1b, dbo.MDS20_Shared_2_VR.PlanActivityDesc_F1b, dbo.MDS20_Shared_2_VR.SelfActivity_F1c, 
                      dbo.MDS20_Shared_2_VR.SelfActivityDesc_F1c, dbo.MDS20_Shared_2_VR.Goals_F1d, dbo.MDS20_Shared_2_VR.GoalsDesc_F1d, 
                      dbo.MDS20_Shared_2_VR.Pursues_F1e, dbo.MDS20_Shared_2_VR.PursuesDesc_F1e, dbo.MDS20_Shared_2_VR.Accepts_F1f, 
                      dbo.MDS20_Shared_2_VR.AcceptsDesc_F1f, dbo.MDS20_Shared_2_VR.SenseNone_F1g, dbo.MDS20_Shared_2_VR.SenseNoneDesc_F1g, 
                      dbo.MDS20_Shared_2_VR.BedMobilitySelf_G1aA, dbo.MDS20_Shared_2_VR.BedMobilitySelfDesc_G1aA, 
                      dbo.MDS20_Shared_2_VR.BedMobilitySupport_G1aB, dbo.MDS20_Shared_2_VR.BedMobilitySupportDesc_G1aB, 
                      dbo.MDS20_Shared_2_VR.TransferSelf_G1bA, dbo.MDS20_Shared_2_VR.TransferSelfDesc_G1bA, dbo.MDS20_Shared_2_VR.TransferSupport_G1bB, 
                      dbo.MDS20_Shared_2_VR.TransferSupportDesc_G1bB, dbo.MDS20_Shared_2_VR.WalkInRoomSelf_G1cA, 
                      dbo.MDS20_Shared_2_VR.WalkInRoomSelfDesc_G1cA, dbo.MDS20_Shared_2_VR.WalkInRoomSupport_G1cB, 
                      dbo.MDS20_Shared_2_VR.WalkInRoomSupportDesc_G1cB, dbo.MDS20_Shared_2_VR.RorridorSelf_G1dA, dbo.MDS20_Shared_2_VR.RorridorSelfDesc_G1dA, 
                      dbo.MDS20_Shared_2_VR.RorridorSupport_G1dB, dbo.MDS20_Shared_2_VR.RorridorSupportDesc_G1dB, dbo.MDS20_Shared_2_VR.OnUnitSelf_G1eA, 
                      dbo.MDS20_Shared_2_VR.OnUnitSelfDesc_G1eA, dbo.MDS20_Shared_2_VR.OnUnitSupport_G1eB, dbo.MDS20_Shared_2_VR.OnUnitSupportDesc_G1eB, 
                      dbo.MDS20_Shared_2_VR.OffUnitSelf_G1fA, dbo.MDS20_Shared_2_VR.OffUnitSelfDesc_G1fA, dbo.MDS20_Shared_2_VR.OffUnitSupport_G1fB, 
                      dbo.MDS20_Shared_2_VR.OffUnitSupportDesc_G1fB, dbo.MDS20_Shared_2_VR.DressingSelf_G1gA, dbo.MDS20_Shared_2_VR.DressingSelfDesc_G1gA, 
                      dbo.MDS20_Shared_2_VR.DressingSupport_G1gB, dbo.MDS20_Shared_2_VR.DressingSupportDesc_G1gB, dbo.MDS20_Shared_2_VR.EatingSelf_G1hA, 
                      dbo.MDS20_Shared_2_VR.EatingSelfDesc_G1hA, dbo.MDS20_Shared_2_VR.EatingSupport_G1hB, dbo.MDS20_Shared_2_VR.EatingSupportDesc_G1hB, 
                      dbo.MDS20_Shared_2_VR.ToiletSelf_G1iA, dbo.MDS20_Shared_2_VR.ToiletSelfDesc_G1iA, dbo.MDS20_Shared_2_VR.ToiletSupport_G1iB, 
                      dbo.MDS20_Shared_2_VR.ToiletSupportDesc_G1iB, dbo.MDS20_Shared_2_VR.HygieneSelf_G1jA, dbo.MDS20_Shared_2_VR.HygieneSelfDesc_G1jA, 
                      dbo.MDS20_Shared_2_VR.HygieneSupport_G1jB, dbo.MDS20_Shared_2_VR.HygieneSupportDesc_G1jB, dbo.MDS20_Shared_2_VR.BathingSelf_G2A, 
                      dbo.MDS20_Shared_2_VR.BathingSelfDesc_G2A, dbo.MDS20_Shared_2_VR.BathingSupport_G2B, dbo.MDS20_Shared_2_VR.BathingSupportDesc_G2B, 
                      dbo.MDS20_Shared_2_VR.BalanceStanding_G3a, dbo.MDS20_Shared_2_VR.BalanceStandingDesc_G3a, dbo.MDS20_Shared_2_VR.BalanceSitting_G3b, 
                      dbo.MDS20_Shared_2_VR.BalanceSupportDesc_G3b, dbo.MDS20_Shared_2_VR.LimitRangeNeck_G4aA, 
                      dbo.MDS20_Shared_2_VR.LimitRangeNeckDesc_G4aA, dbo.MDS20_Shared_2_VR.LimitVoluntaryNeck_G4aB, 
                      dbo.MDS20_Shared_2_VR.LimitVoluntaryNeckDesc_G4aB, dbo.MDS20_Shared_2_VR.LimitRangeArm_G4bA, 
                      dbo.MDS20_Shared_2_VR.LimitRangeArmDesc_G4bA, dbo.MDS20_Shared_2_VR.LimitVoluntaryArm_G4bB, 
                      dbo.MDS20_Shared_2_VR.LimitVoluntaryArmDesc_G4bB, dbo.MDS20_Shared_2_VR.LimitRangeHand_G4cA, 
                      dbo.MDS20_Shared_2_VR.LimitRangeHandDesc_G4cA, dbo.MDS20_Shared_2_VR.LimitVoluntaryHand_G4cB, 
                      dbo.MDS20_Shared_2_VR.LimitVoluntaryHandDesc_G4cB, dbo.MDS20_Shared_2_VR.LimitRangeLeg_G4dA, 
                      dbo.MDS20_Shared_2_VR.LimitRangeLegDesc_G4dA, dbo.MDS20_Shared_2_VR.LimitVoluntaryLeg_G4dB, 
                      dbo.MDS20_Shared_2_VR.LimitVoluntaryLegDesc_G4dB, dbo.MDS20_Shared_2_VR.LimitRangeFoot_G4eA, 
                      dbo.MDS20_Shared_2_VR.LimitRangeFootDesc_G4eA, dbo.MDS20_Shared_2_VR.LimitVoluntaryFoot_G4eB, 
                      dbo.MDS20_Shared_2_VR.LimitVoluntaryFootDesc_G4eB, dbo.MDS20_Shared_2_VR.LimitRangeOther_G4fA, 
                      dbo.MDS20_Shared_2_VR.LimitRangeOtherDesc_G4fA, dbo.MDS20_Shared_2_VR.LimitVoluntaryOther_G4fB, 
                      dbo.MDS20_Shared_2_VR.LimitVoluntaryOtherDesc_G4fB, dbo.MDS20_Shared_2_VR.TransferBedfast_G6a, 
                      dbo.MDS20_Shared_2_VR.TransferBedfastDesc_G6a, dbo.MDS20_Shared_2_VR.TransferBedrail_G6b, dbo.MDS20_Shared_2_VR.TransferBedrailDesc_G6b, 
                      dbo.MDS20_Shared_2_VR.TransferManually_G6c, dbo.MDS20_Shared_2_VR.TransferManuallyDesc_G6c, 
                      dbo.MDS20_Shared_2_VR.TransferMechanically_G6d, dbo.MDS20_Shared_2_VR.TransferMechanicallyDesc_G6d, dbo.MDS20_Shared_2_VR.TransferAid_G6e, 
                      dbo.MDS20_Shared_2_VR.TransferAidDesc_G6e, dbo.MDS20_Shared_2_VR.TransferNone_G6f, dbo.MDS20_Shared_2_VR.TransferNoneDesc_G6f, 
                      dbo.MDS20_Shared_2_VR.Task_G7, dbo.MDS20_Shared_2_VR.TaskDesc_G7, dbo.MDS20_Shared_2_VR.ChangeADL_G9, 
                      dbo.MDS20_Shared_2_VR.ChangeADLDesc_G9, dbo.MDS20_Shared_2_VR.BowlContinence_H1a, dbo.MDS20_Shared_2_VR.BowlContinenceDesc_H1a, 
                      dbo.MDS20_Shared_2_VR.BladderContinence_H1b, dbo.MDS20_Shared_2_VR.BladderContinenceDesc_H1b, dbo.MDS20_Shared_2_VR.BowelRegular_H2a, 
                      dbo.MDS20_Shared_2_VR.BowelRegularDesc_H2a, dbo.MDS20_Shared_2_VR.BowelConstipation_H2b, 
                      dbo.MDS20_Shared_2_VR.BowelConstipationDesc_H2b, dbo.MDS20_Shared_2_VR.BowelDiarrhea_H2c, dbo.MDS20_Shared_2_VR.BowelDiarrheaDesc_H2c, 
                      dbo.MDS20_Shared_2_VR.BowelFecalImpaction_H2d, dbo.MDS20_Shared_2_VR.BowelFecalImpactionDesc_H2d, dbo.MDS20_Shared_2_VR.BowelNone_H2e, 
                      dbo.MDS20_Shared_2_VR.BowelNoneDesc_H2e, dbo.MDS20_Shared_2_VR.ApplianceScheduled_H3a, 
                      dbo.MDS20_Shared_2_VR.ApplianceScheduledDesc_H3a, dbo.MDS20_Shared_2_VR.ApplianceBladder_H3b, 
                      dbo.MDS20_Shared_2_VR.ApplianceBladderDesc_H3b, dbo.MDS20_Shared_2_VR.ApplianceExCatheter_H3c, 
                      dbo.MDS20_Shared_2_VR.ApplianceExCatheterDesc_H3c, dbo.MDS20_Shared_2_VR.ApplianceIndCatheter_H3d, 
                      dbo.MDS20_Shared_2_VR.ApplianceIndCatheterDesc_H3d, dbo.MDS20_Shared_2_VR.ApplianceIntCatheter_H3e, 
                      dbo.MDS20_Shared_2_VR.ApplianceIntCatheterDesc_H3e, dbo.MDS20_Shared_2_VR.ApplianceNotUse_H3f, 
                      dbo.MDS20_Shared_2_VR.ApplianceNotUseDesc_H3f, dbo.MDS20_Shared_2_VR.AppliancePads_H3g, dbo.MDS20_Shared_2_VR.AppliancePadsDesc_H3g, 
                      dbo.MDS20_Shared_2_VR.ApplianceIrrigation_H3h, dbo.MDS20_Shared_2_VR.ApplianceIrrigationDesc_H3h, dbo.MDS20_Shared_2_VR.ApplianceOstomy_H3i, 
                      dbo.MDS20_Shared_2_VR.ApplianceOstomyDesc_H3i, dbo.MDS20_Shared_2_VR.ApplianceNone_H3j, dbo.MDS20_Shared_2_VR.ApplianceNoneDesc_H3j, 
                      dbo.MDS20_Shared_2_VR.UrinaryContinence_H4, dbo.MDS20_Shared_2_VR.UrinaryContinenceDesc_H4
FROM         dbo.MDS20_VR LEFT OUTER JOIN
                      dbo.MDS20_Shared_2_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Shared_2_VR.zzAbstractLink
WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''05'', ''10'')) AND 
                      (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)








' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_4_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'


CREATE VIEW [dbo].[MDS20_Quarterly_Assessment_4_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.ReasonAssessment_AA8, 
                      dbo.MDS20_VR.ReasonAssessmentDesc_AA8, dbo.MDS20_Shared_3_VR.DiseaseDiabMellitus_I1a, 
                      dbo.MDS20_Shared_3_VR.DiseaseDiabMellitusDesc_I1a, dbo.MDS20_Shared_3_VR.DiseaseHyperthyroidism_I1b, 
                      dbo.MDS20_Shared_3_VR.DiseaseHyperthyroidDesc_I1b, dbo.MDS20_Shared_3_VR.DiseaseHypothyroidism_I1c, 
                      dbo.MDS20_Shared_3_VR.DiseaseHypothyroidismDesc_I1c, dbo.MDS20_Shared_3_VR.DiseaseASHD_I1d, dbo.MDS20_Shared_3_VR.DiseaseASHDDesc_I1d, 
                      dbo.MDS20_Shared_3_VR.DiseaseCardiac_I1e, dbo.MDS20_Shared_3_VR.DiseaseCardiacDesc_I1e, dbo.MDS20_Shared_3_VR.DiseaseCongestive_I1f, 
                      dbo.MDS20_Shared_3_VR.DiseaseCongestiveDesc_I1f, dbo.MDS20_Shared_3_VR.DiseaseThrombosis_I1g, 
                      dbo.MDS20_Shared_3_VR.DiseaseThrombosisDesc_I1g, dbo.MDS20_Shared_3_VR.DiseaseHypertension_I1h, 
                      dbo.MDS20_Shared_3_VR.DiseaseHypertensionDesc_I1h, dbo.MDS20_Shared_3_VR.DiseaseHypotension_I1i, 
                      dbo.MDS20_Shared_3_VR.DiseaseHypotensionDesc_I1i, dbo.MDS20_Shared_3_VR.DiseaseVascular_I1j, 
                      dbo.MDS20_Shared_3_VR.DiseaseVascularDesc_I1j, dbo.MDS20_Shared_3_VR.DiseaseCardiovascular_I1k, 
                      dbo.MDS20_Shared_3_VR.DiseaseCardiovascularDesc_I1k, dbo.MDS20_Shared_3_VR.DiseaseArthritis_I1l, 
                      dbo.MDS20_Shared_3_VR.DiseaseArthritisDesc_I1l, dbo.MDS20_Shared_3_VR.DiseaseHipFracture_I1m, 
                      dbo.MDS20_Shared_3_VR.DiseaseHipFractureDesc_I1m, dbo.MDS20_Shared_3_VR.DiseaseLimb_I1n, dbo.MDS20_Shared_3_VR.DiseaseLimbDesc_I1n, 
                      dbo.MDS20_Shared_3_VR.DiseaseOsteoporosis_I1o, dbo.MDS20_Shared_3_VR.DiseaseOsteoporosisDesc_I1o, 
                      dbo.MDS20_Shared_3_VR.DiseaseBoneFracture_I1p, dbo.MDS20_Shared_3_VR.DiseaseBoneFractureDesc_I1p, dbo.MDS20_Shared_3_VR.DiseaseALS_I1q, 
                      dbo.MDS20_Shared_3_VR.DiseaseALSDesc_I1q, dbo.MDS20_Shared_3_VR.DiseaseAlzheimer_I1r, dbo.MDS20_Shared_3_VR.DiseaseAlzheimerDesc_I1r, 
                      dbo.MDS20_Shared_3_VR.DiseaseAphasia_I1s, dbo.MDS20_Shared_3_VR.DiseaseAphasiaDesc_I1s, dbo.MDS20_Shared_3_VR.DiseaseCerebralPalsy_I1t, 
                      dbo.MDS20_Shared_3_VR.DiseaseCerebralPalsyDesc_I1t, dbo.MDS20_Shared_3_VR.DiseaseCerebro_I1u, 
                      dbo.MDS20_Shared_3_VR.DiseaseCerebroDesc_I1u, dbo.MDS20_Shared_3_VR.DiseaseDementia_I1v, dbo.MDS20_Shared_3_VR.DiseaseDementiaDesc_I1v, 
                      dbo.MDS20_Shared_3_VR.DiseaseHemiplegia_I1w, dbo.MDS20_Shared_3_VR.DiseaseHemiplegiaDesc_I1w, dbo.MDS20_Shared_3_VR.DiseaseChorea_I1x, 
                      dbo.MDS20_Shared_3_VR.DiseaseChoreaDesc_I1x, dbo.MDS20_Shared_3_VR.DiseaseSclerosis_I1y, dbo.MDS20_Shared_3_VR.DiseaseSclerosisDesc_I1y, 
                      dbo.MDS20_Shared_3_VR.DiseaseParaplegia_I1z, dbo.MDS20_Shared_3_VR.DiseaseParaplegiaDesc_I1z, dbo.MDS20_Shared_3_VR.DiseaseParkinson_I1aa, 
                      dbo.MDS20_Shared_3_VR.DiseaseParkinsonDesc_I1aa, dbo.MDS20_Shared_3_VR.DiseaseQuadriplegia_I1bb, 
                      dbo.MDS20_Shared_3_VR.DiseaseQuadriplegiaDesc_I1bb, dbo.MDS20_Shared_3_VR.DiseaseSeizureDisorder_I1cc, 
                      dbo.MDS20_Shared_3_VR.DiseaseSeizeDisorderDesc_I1cc, dbo.MDS20_Shared_3_VR.DiseaseIschemic_I1dd, 
                      dbo.MDS20_Shared_3_VR.DiseaseIschemicDesc_I1dd, dbo.MDS20_Shared_3_VR.DiseaseTraumaticBrain_I1ee, 
                      dbo.MDS20_Shared_3_VR.DiseaseTraumaBrainDesc_I1ee, dbo.MDS20_Shared_3_VR.DiseaseAnxietyDisorder_I1ff, 
                      dbo.MDS20_Shared_3_VR.DiseaseAnxietyDisDesc_I1ff, dbo.MDS20_Shared_3_VR.DiseaseDepression_I1gg, 
                      dbo.MDS20_Shared_3_VR.DiseaseDepressionDesc_I1gg, dbo.MDS20_Shared_3_VR.DiseaseManicDepressive_I1hh, 
                      dbo.MDS20_Shared_3_VR.DiseaseManicDepressDesc_I1hh, dbo.MDS20_Shared_3_VR.DiseaseSchizophrenia_I1ii, 
                      dbo.MDS20_Shared_3_VR.DiseaseSchizophreniaDesc_I1ii, dbo.MDS20_Shared_3_VR.DiseaseAsthma_I1jj, 
                      dbo.MDS20_Shared_3_VR.DiseaseAsthmaDesc_I1jj, dbo.MDS20_Shared_3_VR.DiseaseEmphysema_I1kk, 
                      dbo.MDS20_Shared_3_VR.DiseaseEmphysemaDesc_I1kk, dbo.MDS20_Shared_3_VR.DiseaseCatarats_I1ll, 
                      dbo.MDS20_Shared_3_VR.DiseaseCataratsDesc_I1ll, dbo.MDS20_Shared_3_VR.DiseaseDiabRetino_I1mm, 
                      dbo.MDS20_Shared_3_VR.DiseaseDiabRetinoDesc_I1mm, dbo.MDS20_Shared_3_VR.DiseaseGlaucoma_I1nn, 
                      dbo.MDS20_Shared_3_VR.DiseaseGlaucomaDesc_I1nn, dbo.MDS20_Shared_3_VR.DiseaseMacularDegenerate_I1oo, 
                      dbo.MDS20_Shared_3_VR.DiseaseMacularDegenDesc_I1oo, dbo.MDS20_Shared_3_VR.DiseaseAllergies_I1pp, 
                      dbo.MDS20_Shared_3_VR.DiseaseAllergiesDesc_I1pp, dbo.MDS20_Shared_3_VR.DiseaseAnemia_I1qq, dbo.MDS20_Shared_3_VR.DiseaseAnemiaDesc_I1qq, 
                      dbo.MDS20_Shared_3_VR.DiseaseCancer_I1rr, dbo.MDS20_Shared_3_VR.DiseaseCancerDesc_I1rr, dbo.MDS20_Shared_3_VR.DiseaseGastrointestinal_I1ss, 
                      dbo.MDS20_Shared_3_VR.DiseaseGastroDesc_I1ss, dbo.MDS20_Shared_3_VR.DiseaseLiver_I1tt, dbo.MDS20_Shared_3_VR.DiseaseLiverDesc_I1tt, 
                      dbo.MDS20_Shared_3_VR.DiseaseRenalFailure_I1uu, dbo.MDS20_Shared_3_VR.DiseaseRenalFailureDesc_I1uu, 
                      dbo.MDS20_Shared_3_VR.DiseaseNone_I1vv, dbo.MDS20_Shared_3_VR.DiseaseNoneDesc_I1vv, dbo.MDS20_Shared_3_VR.InfectionAntibiotic_I2a, 
                      dbo.MDS20_Shared_3_VR.InfectionAntibioticDesc_I2a, dbo.MDS20_Shared_3_VR.InfectionCellulitis_I2b, dbo.MDS20_Shared_3_VR.InfectionCellulitisDesc_I2b, 
                      dbo.MDS20_Shared_3_VR.InfectionClostridium_I2c, dbo.MDS20_Shared_3_VR.InfectionClostridiumDesc_I2c, 
                      dbo.MDS20_Shared_3_VR.InfectionConjunctivitis_I2d, dbo.MDS20_Shared_3_VR.InfectionConjunctivaDesc_I2d, dbo.MDS20_Shared_3_VR.InfectionHIV_I2e, 
                      dbo.MDS20_Shared_3_VR.InfectionHIVDesc_I2e, dbo.MDS20_Shared_3_VR.InfectionPneumonia_I2f, dbo.MDS20_Shared_3_VR.InfectionPneumoniaDesc_I2f, 
                      dbo.MDS20_Shared_3_VR.InfectionRespiratory_I2g, dbo.MDS20_Shared_3_VR.InfectionRespiratoryDesc_I2g, 
                      dbo.MDS20_Shared_3_VR.InfectionSepticemia_I2h, dbo.MDS20_Shared_3_VR.InfectionSepticemiaDesc_I2h, dbo.MDS20_Shared_3_VR.InfectionSexually_I2i, 
                      dbo.MDS20_Shared_3_VR.InfectionSexuallyDesc_I2i, dbo.MDS20_Shared_3_VR.InfectionTuberculosis_I2j, 
                      dbo.MDS20_Shared_3_VR.InfectionTuberculosisDesc_I2j, dbo.MDS20_Shared_3_VR.InfectionUrinary_I2k, dbo.MDS20_Shared_3_VR.InfectionUrinaryDesc_I2k, 
                      dbo.MDS20_Shared_3_VR.InfectionHepatitis_I2l, dbo.MDS20_Shared_3_VR.InfectionHepatitisDesc_I2l, dbo.MDS20_Shared_3_VR.InfectionWound_I2m, 
                      dbo.MDS20_Shared_3_VR.InfectionWoundDesc_I2m, dbo.MDS20_Shared_3_VR.InfectionNone_I2n, dbo.MDS20_Shared_3_VR.InfectionNoneDesc_I2n, 
                      dbo.MDS20_Shared_3_VR.ProblemWeight_J1a, dbo.MDS20_Shared_3_VR.ProblemWeightDesc_J1a, dbo.MDS20_Shared_3_VR.ProblemLieFlat_J1b, 
                      dbo.MDS20_Shared_3_VR.ProblemLieFlatDesc_J1b, dbo.MDS20_Shared_3_VR.ProblemDehydrated_J1c, 
                      dbo.MDS20_Shared_3_VR.ProblemDehydratedDesc_J1c, dbo.MDS20_Shared_3_VR.ProblemFluid_J1d, dbo.MDS20_Shared_3_VR.ProblemFluidDesc_J1d, 
                      dbo.MDS20_Shared_3_VR.ProblemDelusions_J1e, dbo.MDS20_Shared_3_VR.ProblemDelusionsDesc_J1e, dbo.MDS20_Shared_3_VR.ProblemDizziness_J1f, 
                      dbo.MDS20_Shared_3_VR.ProblemDizzinessDesc_J1f, dbo.MDS20_Shared_3_VR.ProblemEdema_J1g, dbo.MDS20_Shared_3_VR.ProblemEdemaDesc_J1g, 
                      dbo.MDS20_Shared_3_VR.ProblemFever_J1h, dbo.MDS20_Shared_3_VR.ProblemFeverDesc_J1h, dbo.MDS20_Shared_3_VR.ProblemHallucinations_J1i, 
                      dbo.MDS20_Shared_3_VR.ProblemHallucinationsDesc_J1i, dbo.MDS20_Shared_3_VR.ProblemBleeding_J1j, 
                      dbo.MDS20_Shared_3_VR.ProblemBleedingDesc_J1j, dbo.MDS20_Shared_3_VR.ProblemLung_J1k, dbo.MDS20_Shared_3_VR.ProblemLungDesc_J1k, 
                      dbo.MDS20_Shared_3_VR.ProblemBreath_J1l, dbo.MDS20_Shared_3_VR.ProblemBreathDesc_J1l, dbo.MDS20_Shared_3_VR.ProblemSyncope_J1m, 
                      dbo.MDS20_Shared_3_VR.ProblemSyncopeDesc_J1m, dbo.MDS20_Shared_3_VR.ProblemUnsteadyGait_J1n, 
                      dbo.MDS20_Shared_3_VR.ProblemUnsteadyGaitDesc_J1n, dbo.MDS20_Shared_3_VR.ProblemVomiting_J1o, 
                      dbo.MDS20_Shared_3_VR.ProblemVomitingDesc_J1o, dbo.MDS20_Shared_3_VR.ProblemNone_J1p, dbo.MDS20_Shared_3_VR.ProblemNoneDesc_J1p, 
                      dbo.MDS20_Shared_3_VR.Pain_Frequency_J2a, dbo.MDS20_Shared_3_VR.Pain_FrequencyDesc_J2a, dbo.MDS20_Shared_3_VR.Pain_Intensity_J2b, 
                      dbo.MDS20_Shared_3_VR.Pain_IntensityDesc_J2b, dbo.MDS20_Shared_3_VR.AccidentFell30_J4a, dbo.MDS20_Shared_3_VR.AccidentFell30Desc_J4a, 
                      dbo.MDS20_Shared_3_VR.AccidentFell180_J4b, dbo.MDS20_Shared_3_VR.AccidentFell180Desc_J4b, dbo.MDS20_Shared_3_VR.AccidentHipFracture_J4c, 
                      dbo.MDS20_Shared_3_VR.AccidentHipFractureDesc_J4c, dbo.MDS20_Shared_3_VR.AccidentOtherFracture_J4d, 
                      dbo.MDS20_Shared_3_VR.AccidentOtherFractureDesc_J4d, dbo.MDS20_Shared_3_VR.AccidentNone_J4e, dbo.MDS20_Shared_3_VR.AccidentNoneDesc_J4e, 
                      dbo.MDS20_Shared_3_VR.Stability_Unstable_J5a, dbo.MDS20_Shared_3_VR.Stability_UnstableDesc_J5a, dbo.MDS20_Shared_3_VR.Stability_Acute_J5b, 
                      dbo.MDS20_Shared_3_VR.Stability_AcuteDesc_J5b, dbo.MDS20_Shared_3_VR.Stability_EndStage_J5c, 
                      dbo.MDS20_Shared_3_VR.Stability_EndStageDesc_J5c, dbo.MDS20_Shared_3_VR.Stability_None_J5d, 
                      dbo.MDS20_Shared_3_VR.Stability_None_Desc_J5d,
--Hobic     NP - 00099
    MDS20_Hobic_VR.Dyspnea, MDS20_Hobic_VR.Dyspneaesc,
    MDS20_Hobic_VR.Fatigue, MDS20_Hobic_VR.FatigueDesc,
    MDS20_Hobic_VR.Nausea,  MDS20_Hobic_VR.NauseaDesc

FROM         dbo.MDS20_VR LEFT OUTER JOIN
    dbo.MDS20_Shared_3_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Shared_3_VR.zzAbstractLink LEFT OUTER JOIN
--NP - 00099 
    dbo.MDS20_Hobic_VR on dbo.MDS20_VR.zzAbstractLink = MDS20_Hobic_VR.zzAbstractLink

WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''05'', ''10'')) AND 
                      (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)








' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_5_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[MDS20_Quarterly_Assessment_5_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.ReasonAssessment_AA8, 
                      dbo.MDS20_VR.ReasonAssessmentDesc_AA8, dbo.MDS20_Shared_4_VR.OralUnstable_K1a, dbo.MDS20_Shared_4_VR.OralUnstableDesc_K1a, 
                      dbo.MDS20_Shared_4_VR.OralAcute_K1b, dbo.MDS20_Shared_4_VR.OralAcuteDesc_K1b, dbo.MDS20_Shared_4_VR.OralEndStage_K1c, 
                      dbo.MDS20_Shared_4_VR.OralEndStageDesc_K1c, dbo.MDS20_Shared_4_VR.OralNone_K1d, dbo.MDS20_Shared_4_VR.OralDesc_K1d, 
                      dbo.MDS20_Shared_4_VR.Height_K2a, dbo.MDS20_Shared_4_VR.Weight_K2b, 
            dbo.MDS20_Shared_4_VR.WeightGain_K3b, dbo.MDS20_Shared_4_VR.WeightGainDesc_K3b, 
            dbo.MDS20_Shared_4_VR.WeightLoss_K3a, dbo.MDS20_Shared_4_VR.WeightLossDesc_K3a, 
                      dbo.MDS20_Shared_4_VR.Nutritional_Taste_K4a, dbo.MDS20_Shared_4_VR.Nutritional_TasteDesc_K4a, dbo.MDS20_Shared_4_VR.Nutritional_Hunger_K4b, 
                      dbo.MDS20_Shared_4_VR.Nutritional_HungerDesc_K4b, dbo.MDS20_Shared_4_VR.Nutritional_LeaveFood_K4c, 
                      dbo.MDS20_Shared_4_VR.Nutritional_LeaveFoodDesc_K4c, dbo.MDS20_Shared_4_VR.Nutritional_None_K4d, 
                      dbo.MDS20_Shared_4_VR.Nutritional_NoneDesc_K4d, dbo.MDS20_Shared_4_VR.NutritionalAppPatenteral_K5a, 
                      dbo.MDS20_Shared_4_VR.NutritionalAppPatentDesc_K5a, dbo.MDS20_Shared_4_VR.NutritionalAppFeedTube_K5b, 
                      dbo.MDS20_Shared_4_VR.NutritionalAppFeedTDesc_K5b, dbo.MDS20_Shared_4_VR.NutritionalAppDiet_K5c, 
                      dbo.MDS20_Shared_4_VR.NutritionalAppDietDesc_K5c, dbo.MDS20_Shared_4_VR.NutritionalAppSyringe_K5d, 
                      dbo.MDS20_Shared_4_VR.NutritionalAppSyringeDesc_K5d, dbo.MDS20_Shared_4_VR.NutritionalAppTherapeutic_K5e, 
                      dbo.MDS20_Shared_4_VR.NutritionalAppTherapeDesc_K5e, dbo.MDS20_Shared_4_VR.NutritionalAppSupplement_K5f, 
                      dbo.MDS20_Shared_4_VR.NutritionalAppSupplyDesc_K5f, dbo.MDS20_Shared_4_VR.NutritionalAppUtensil_K5g, 
                      dbo.MDS20_Shared_4_VR.NutritionalAppUtensilDesc_K5g, dbo.MDS20_Shared_4_VR.NutritionalAppWeight_K5h, 
                      dbo.MDS20_Shared_4_VR.NutritionalAppWeightDesc_K5h, dbo.MDS20_Shared_4_VR.NutritionalAppNone_K5i, 
                      dbo.MDS20_Shared_4_VR.NutritionalAppNoneDesc_K5i, dbo.MDS20_Shared_4_VR.ParenteralProportion_K6a, 
                      dbo.MDS20_Shared_4_VR.ParenteralProportionDesc_K6a, dbo.MDS20_Shared_4_VR.ParenteralAverage_K6b, 
                      dbo.MDS20_Shared_4_VR.ParenteralAverageDesc_K6b, dbo.MDS20_Shared_4_VR.Ulcers_Stage1_M1a, dbo.MDS20_Shared_4_VR.Ulcers_Stage2_M1b, 
                      dbo.MDS20_Shared_4_VR.Ulcers_Stage3_M1c, dbo.MDS20_Shared_4_VR.Ulcers_Stage4_M1d, dbo.MDS20_Shared_4_VR.UlcerTypePressure_M2a, 
                      dbo.MDS20_Shared_4_VR.UlcerType_PressureDesc_M2a, dbo.MDS20_Shared_4_VR.UlcerType_Stasis_M2b, 
                      dbo.MDS20_Shared_4_VR.UlcerType_StasisDesc_M2b, dbo.MDS20_Shared_4_VR.SkinAbrasions_M4a, dbo.MDS20_Shared_4_VR.SkinAbrasionsDesc_M4a, 
                      dbo.MDS20_Shared_4_VR.SkinBurn_M4b, dbo.MDS20_Shared_4_VR.SkinBurnDesc_M4b, dbo.MDS20_Shared_4_VR.SkinLesions_M4c, 
                      dbo.MDS20_Shared_4_VR.SkinLesionsDesc_M4c, dbo.MDS20_Shared_4_VR.SkinRashes_M4d, dbo.MDS20_Shared_4_VR.SkinRashesDesc_M4d, 
                      dbo.MDS20_Shared_4_VR.SkinDesensitized_M4e, dbo.MDS20_Shared_4_VR.SkinDesensitizedDesc_M4e, dbo.MDS20_Shared_4_VR.SkinTears_M4f, 
                      dbo.MDS20_Shared_4_VR.SkinTearsDesc_M4f, dbo.MDS20_Shared_4_VR.SkinSurgical_M4g, dbo.MDS20_Shared_4_VR.SkinSurgicalDesc_M4g, 
                      dbo.MDS20_Shared_4_VR.SkinNone_M4h, dbo.MDS20_Shared_4_VR.SkinNoneDesc_M4h, dbo.MDS20_Shared_4_VR.SkinTreat_Chair_M5a, 
                      dbo.MDS20_Shared_4_VR.SkinTreat_ChairDesc_M5a, dbo.MDS20_Shared_4_VR.SkinTreat_Bed_M5b, dbo.MDS20_Shared_4_VR.SkinTreat_BedDesc_M5b, 
                      dbo.MDS20_Shared_4_VR.SkinTreat_Turning_M5c, dbo.MDS20_Shared_4_VR.SkinTreat_TurningDesc_M5c, 
                      dbo.MDS20_Shared_4_VR.SkinTreat_Nutrition_M5d, dbo.MDS20_Shared_4_VR.SkinTreat_NutritionDesc_M5d, dbo.MDS20_Shared_4_VR.SkinTreat_Ulcer_M5e, 
                      dbo.MDS20_Shared_4_VR.SkinTreat_UlcerDesc_M5e, dbo.MDS20_Shared_4_VR.SkinTreat_Surgical_M5f, 
                      dbo.MDS20_Shared_4_VR.SkinTreat_SurgicalDesc_M5f, dbo.MDS20_Shared_4_VR.SkinTreat_Dressing_M5g, 
                      dbo.MDS20_Shared_4_VR.SkinTreat_DressingDesc_M5g, dbo.MDS20_Shared_4_VR.SkinTreat_Ointment_M5h, 
                      dbo.MDS20_Shared_4_VR.SkinTreat_OintmentDesc_M5h, dbo.MDS20_Shared_4_VR.SkinTreat_Other_M5i, 
                      dbo.MDS20_Shared_4_VR.SkinTreat_OtherDesc_M5i, dbo.MDS20_Shared_4_VR.SkinTreat_None_M5j, dbo.MDS20_Shared_4_VR.SkinTreat_NoneDesc_M5j, 
                      dbo.MDS20_Shared_4_VR.Foot_Problem_M6a, dbo.MDS20_Shared_4_VR.Foot_ProblemDesc_M6a, dbo.MDS20_Shared_4_VR.Foot_Infection_M6b, 
                      dbo.MDS20_Shared_4_VR.Foot_InfectionDesc_M6b, dbo.MDS20_Shared_4_VR.Foot_Lesion_M6c, dbo.MDS20_Shared_4_VR.Foot_LesionDesc_M6c, 
                      dbo.MDS20_Shared_4_VR.Foot_Nail_M6d, dbo.MDS20_Shared_4_VR.Foot_NailDesc_M6d, dbo.MDS20_Shared_4_VR.Foot_Preventative_M6e, 
                      dbo.MDS20_Shared_4_VR.Foot_PreventativeDesc_M6e, dbo.MDS20_Shared_4_VR.Foot_Dressing_M6f, dbo.MDS20_Shared_4_VR.Foot_DressingDesc_M6f, 
                      dbo.MDS20_Shared_4_VR.Foot_None_M6g, dbo.MDS20_Shared_4_VR.Foot_NoneDesc_M6g, dbo.MDS20_Shared_4_VR.Awake_Morning_N1a, 
                      dbo.MDS20_Shared_4_VR.Awake_MorningDesc_N1a, dbo.MDS20_Shared_4_VR.Awake_Afternoon_N1b, dbo.MDS20_Shared_4_VR.Awake_AfternoonDesc_N1b, 
                      dbo.MDS20_Shared_4_VR.Awake_Evening_N1c, dbo.MDS20_Shared_4_VR.Awake_EveningDesc_N1c, dbo.MDS20_Shared_4_VR.Awake_None_N1d, 
                      dbo.MDS20_Shared_4_VR.Awake_NoneDesc_N1d, dbo.MDS20_Shared_4_VR.AverageTime_N2, dbo.MDS20_Shared_4_VR.AverageTimeDesc_N2, 
                      dbo.MDS20_Shared_4_VR.NumberMedication_O1, dbo.MDS20_Shared_4_VR.Injection_O3, dbo.MDS20_Shared_4_VR.Days_Antipsychotic_O4a, 
                      dbo.MDS20_Shared_4_VR.Days_Antianxiety_O4b, dbo.MDS20_Shared_4_VR.Days_Antidepressant_O4c, dbo.MDS20_Shared_4_VR.Days_Hypnotic_O4d, 
                      dbo.MDS20_Shared_4_VR.Days_Diuretic_O4e, dbo.MDS20_Shared_4_VR.Days_Analgesic_O4f
FROM         dbo.MDS20_VR LEFT OUTER JOIN
                      dbo.MDS20_Shared_4_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Shared_4_VR.zzAbstractLInk
WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''05'', ''10'')) AND 
                      (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_6_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'






CREATE VIEW [dbo].[MDS20_Quarterly_Assessment_6_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.ReasonAssessment_AA8, 
                      dbo.MDS20_VR.ReasonAssessmentDesc_AA8, dbo.MDS20_Shared_5_VR.SpecialChemotherapy_P1aa, 
                      dbo.MDS20_Shared_5_VR.SpecialChemotherapyDesc_P1aa, dbo.MDS20_Shared_5_VR.SpecialDialysis_P1ab, 
                      dbo.MDS20_Shared_5_VR.SpecialDialysisDesc_P1ab, dbo.MDS20_Shared_5_VR.SpecialIV_P1ac, dbo.MDS20_Shared_5_VR.SpecialIVDesc_P1ac, 
                      dbo.MDS20_Shared_5_VR.SpecialIntake_P1ad, dbo.MDS20_Shared_5_VR.SpecialIntakeDesc_P1ad, dbo.MDS20_Shared_5_VR.SpecialMonitor_P1ae, 
                      dbo.MDS20_Shared_5_VR.SpecialMonitorDesc_P1ae, dbo.MDS20_Shared_5_VR.SpecialOstomy_P1af, dbo.MDS20_Shared_5_VR.SpecialOstomyDesc_P1af, 
                      dbo.MDS20_Shared_5_VR.SpecialOxygen_P1ag, dbo.MDS20_Shared_5_VR.SpecialOxygenDesc_P1ag, dbo.MDS20_Shared_5_VR.SpecialRadiation_P1ah, 
                      dbo.MDS20_Shared_5_VR.SpecialRadiationDesc_P1ah, dbo.MDS20_Shared_5_VR.SpecialSuction_P1ai, dbo.MDS20_Shared_5_VR.SpecialSuctionDesc_P1ai, 
                      dbo.MDS20_Shared_5_VR.SpecialTrash_P1aj, dbo.MDS20_Shared_5_VR.SpecialTrashDesc_P1aj, dbo.MDS20_Shared_5_VR.SpecialTransfusion_P1ak, 
                      dbo.MDS20_Shared_5_VR.SpecialTransfusionDesc_P1ak, dbo.MDS20_Shared_5_VR.SpecialVentilator_P1al, 
                      dbo.MDS20_Shared_5_VR.SpecialVentilatorDesc_P1al, dbo.MDS20_Shared_5_VR.SpecialAlcohol_P1am, dbo.MDS20_Shared_5_VR.SpecialAlcoholDesc_P1am, 
                      dbo.MDS20_Shared_5_VR.SpecialAlzheimer_P1an, dbo.MDS20_Shared_5_VR.SpecialAlzheimerDesc_P1an, dbo.MDS20_Shared_5_VR.SpecialHospice_P1ao, 
                      dbo.MDS20_Shared_5_VR.SpecialHospiceDesc_P1ao, dbo.MDS20_Shared_5_VR.SpecialPediatric_P1ap, 
                      dbo.MDS20_Shared_5_VR.SpecialPediatricDesc_P1ap, dbo.MDS20_Shared_5_VR.SpecialRespite_P1aq, dbo.MDS20_Shared_5_VR.SpecialRespiteDesc_P1aq, 
                      dbo.MDS20_Shared_5_VR.SpecialTraining_P1ar, dbo.MDS20_Shared_5_VR.SpecialTrainingDesc_P1ar, dbo.MDS20_Shared_5_VR.SpecialNone_P1as, 
                      dbo.MDS20_Shared_5_VR.SpecialNoneDesc_P1as, dbo.MDS20_Shared_5_VR.TherapySpeechDay_P1baA, 
                      dbo.MDS20_Shared_5_VR.TherapySpeechMinute_P1baB, dbo.MDS20_Shared_5_VR.TherapyOccupationDay_P1bbA, 
                      dbo.MDS20_Shared_5_VR.TherapyOccupationMinute_P1bbB, dbo.MDS20_Shared_5_VR.TherapyPhysicalDay_P1bcA, 
                      dbo.MDS20_Shared_5_VR.TherapyPhysicalMinute_P1bcB, dbo.MDS20_Shared_5_VR.TherapyRespiratoryDay_P1bdA, 
                      dbo.MDS20_Shared_5_VR.TherapyRespiratoryMin_P1bdB, dbo.MDS20_Shared_5_VR.TherapyPsychologicalDay_P1beA, 
                      dbo.MDS20_Shared_5_VR.TherapyPsychologicalMin_P1beB, dbo.MDS20_Shared_5_VR.TherapyRecreationDay_P1bfA, 
                      dbo.MDS20_Shared_5_VR.TherapyRecreationMinute_P1bfB, dbo.MDS20_Shared_5_VR.RehabPassive_P3a, dbo.MDS20_Shared_5_VR.RehabActive_P3b, 
                      dbo.MDS20_Shared_5_VR.RehabSplint_P3c, dbo.MDS20_Shared_5_VR.RehabBed_P3d, dbo.MDS20_Shared_5_VR.RehabTransfer_P3e, 
                      dbo.MDS20_Shared_5_VR.RehabWalking_P3f, dbo.MDS20_Shared_5_VR.RehabDressing_P3g, dbo.MDS20_Shared_5_VR.RehabEating_P3h, 
                      dbo.MDS20_Shared_5_VR.RehabAmputation_P3i, dbo.MDS20_Shared_5_VR.RehabCommunication_P3j, dbo.MDS20_Shared_5_VR.RehabOther_P3k, 
                      dbo.MDS20_Shared_5_VR.DeviceFullBed_P4a, dbo.MDS20_Shared_5_VR.DeviceFullBedDesc_P4a, dbo.MDS20_Shared_5_VR.DeviceOther_P4b, 
                      dbo.MDS20_Shared_5_VR.DeviceOtherDesc_P4b, dbo.MDS20_Shared_5_VR.DeviceTrunk_P4c, dbo.MDS20_Shared_5_VR.DeviceTrunkDesc_P4c, 
                      dbo.MDS20_Shared_5_VR.DeviceLimb_P4d, dbo.MDS20_Shared_5_VR.DeviceLimbDesc_P4d, dbo.MDS20_Shared_5_VR.DeviceChair_P4e, 
                      dbo.MDS20_Shared_5_VR.DeviceChairDesc_P4e, dbo.MDS20_Shared_5_VR.PhysicianVisit_P7, dbo.MDS20_Shared_5_VR.PhysicianOrder_P8, 
                      dbo.MDS20_Shared_5_VR.OverallChange_Q2, dbo.MDS20_Shared_5_VR.OverallChangeDesc_Q2, dbo.MDS20_Shared_5_VR.CompleteDate_R2b
FROM         dbo.MDS20_VR LEFT OUTER JOIN
                      dbo.MDS20_Shared_5_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Shared_5_VR.zzAbstractLink
WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''05'', ''10'')) AND 
                      (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)








' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_Diagnosis_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'




CREATE VIEW [dbo].[MDS20_Quarterly_Assessment_Diagnosis_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.ReasonAssessment_AA8, dbo.MDS20_VR.ReasonAssessmentDesc_AA8, 
                      dbo.MDS20_Diagnosis_VR.Diagnosis_I3a, dbo.MDS20_Diagnosis_VR.DiagnosisDesc_I3a, dbo.MDS20_Diagnosis_VR.DiagnosisShortDesc_I3a, 
                      dbo.MDS20_Diagnosis_VR.Diagnosis_I3b, dbo.MDS20_Diagnosis_VR.DiagnosisDesc_I3b, dbo.MDS20_Diagnosis_VR.DiagnosisShortDesc_I3b, 
                      dbo.MDS20_Diagnosis_VR.Diagnosis_I3c, dbo.MDS20_Diagnosis_VR.DiagnosisDesc_I3c, dbo.MDS20_Diagnosis_VR.DiagnosisShortDesc_I3c, 
                      dbo.MDS20_Diagnosis_VR.Diagnosis_I3d, dbo.MDS20_Diagnosis_VR.DiagnosisDesc_I3d, dbo.MDS20_Diagnosis_VR.DiagnosisShortDesc_I3d, 
                      dbo.MDS20_Diagnosis_VR.Diagnosis_I3e, dbo.MDS20_Diagnosis_VR.DiagnosisDesc_I3e, dbo.MDS20_Diagnosis_VR.DiagnosisShortDesc_I3e, 
                      dbo.MDS20_Diagnosis_VR.Diagnosis_I3f, dbo.MDS20_Diagnosis_VR.DiagnosisDesc_I3f, dbo.MDS20_Diagnosis_VR.DiagnosisShortDesc_I3f
FROM         dbo.MDS20_VR LEFT OUTER JOIN
                      dbo.MDS20_Diagnosis_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Diagnosis_VR.zzAbstractLink
WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''05'', ''10'')) AND (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)





' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_Medication_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'






CREATE VIEW [dbo].[MDS20_Quarterly_Assessment_Medication_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.ReasonAssessment_AA8, 
                      dbo.MDS20_VR.ReasonAssessmentDesc_AA8, dbo.MDS20_Medication_VR.MedicationOccurrence, dbo.MDS20_Medication_VR.MedicationName_U1, 
                      dbo.MDS20_Medication_VR.Route_Administration_U2, dbo.MDS20_Medication_VR.Route_AdministrationDesc_U2, dbo.MDS20_Medication_VR.Frequency_U3, 
                      dbo.MDS20_Medication_VR.FrequencyDesc_U3, dbo.MDS20_Medication_VR.AmountAdministered_U4, dbo.MDS20_Medication_VR.Doses_U5, 
                      dbo.MDS20_Medication_VR.DIN_U6
FROM         dbo.MDS20_VR LEFT OUTER JOIN
                      dbo.MDS20_Medication_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Medication_VR.zzAbstractLink
WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''05'', ''10'')) AND 
                      (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)








' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_RAP_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[MDS20_Quarterly_Assessment_RAP_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.ReasonAssessment_AA8, dbo.MDS20_VR.ReasonAssessmentDesc_AA8, 
                      dbo.MDS20_RAP_VR.RAP_01_Delirium, dbo.MDS20_RAP_VR.RAP_01_DeliriumDesc, dbo.MDS20_RAP_VR.RAP_01_DeliriumNotes, 
                      dbo.MDS20_RAP_VR.RAP_01_DeliriumNotesLogDate, dbo.MDS20_RAP_VR.RAP_01_DeliriumNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_01_DeliriumNotesLogCoder, dbo.MDS20_RAP_VR.RAP_01_DeliriumNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_02_Cognitive, dbo.MDS20_RAP_VR.RAP_02_CognitiveDesc, dbo.MDS20_RAP_VR.RAP_02_CognitiveNotes, 
                      dbo.MDS20_RAP_VR.RAP_02_CognitiveNotesLogDate, dbo.MDS20_RAP_VR.RAP_02_CognitiveNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_02_CognitiveNotesLogCoder, dbo.MDS20_RAP_VR.RAP_02_CognitiveNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_03_Visual, dbo.MDS20_RAP_VR.RAP_03_VisualDesc, dbo.MDS20_RAP_VR.RAP_03_VisualNotes, 
                      dbo.MDS20_RAP_VR.RAP_03_VisualNotesLogDate, dbo.MDS20_RAP_VR.RAP_03_VisualNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_03_VisualNotesLogCoder, dbo.MDS20_RAP_VR.RAP_03_VisualNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_04_Communication, dbo.MDS20_RAP_VR.RAP_04_CommunicationDesc, 
                      dbo.MDS20_RAP_VR.RAP_04_CommunicationNotes, dbo.MDS20_RAP_VR.RAP_04_CommunicationNotesLogDate, 
                      dbo.MDS20_RAP_VR.RAP_04_CommunicationNotesLogTime, dbo.MDS20_RAP_VR.RAP_04_CommunicationNotesLogCoder, 
                      dbo.MDS20_RAP_VR.RAP_04_CommunicationNotesLogCoderDesc, dbo.MDS20_RAP_VR.RAP_05_ADL_Function, 
                      dbo.MDS20_RAP_VR.RAP_05_ADL_FunctionDesc, dbo.MDS20_RAP_VR.RAP_05_ADL_FunctionNotes, 
                      dbo.MDS20_RAP_VR.RAP_05_ADL_FunctionNotesLogDate, dbo.MDS20_RAP_VR.RAP_05_ADL_FunctionNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_05_ADL_FunctionNotesLogCoder, dbo.MDS20_RAP_VR.RAP_05_ADL_FunctionNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_06_Urinary, dbo.MDS20_RAP_VR.RAP_06_UrinaryDesc, dbo.MDS20_RAP_VR.RAP_06_UrinaryNotes, 
                      dbo.MDS20_RAP_VR.RAP_06_UrinaryNotesLogDate, dbo.MDS20_RAP_VR.RAP_06_UrinaryNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_06_UrinaryNotesLogCoder, dbo.MDS20_RAP_VR.RAP_06_UrinaryNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_07_Psychosocial, dbo.MDS20_RAP_VR.RAP_07_PsychosocialDesc, dbo.MDS20_RAP_VR.RAP_07_PsychosocialNotes, 
                      dbo.MDS20_RAP_VR.RAP_07_PsychosocialNotesLogDate, dbo.MDS20_RAP_VR.RAP_07_PsychosocialNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_07_PsychosocialNotesLogCoder, dbo.MDS20_RAP_VR.RAP_07_PsychosocialNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_08_Mood, dbo.MDS20_RAP_VR.RAP_08_MoodDesc, dbo.MDS20_RAP_VR.RAP_08_MoodNotes, 
                      dbo.MDS20_RAP_VR.RAP_08_MoodNotesLogDate, dbo.MDS20_RAP_VR.RAP_08_MoodNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_08_MoodNotesLogCoder, dbo.MDS20_RAP_VR.RAP_08_MoodNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_09_Behavioural, dbo.MDS20_RAP_VR.RAP_09_BehaviouralDesc, dbo.MDS20_RAP_VR.RAP_09_BehaviouralNotes, 
                      dbo.MDS20_RAP_VR.RAP_09_BehaviouralNotesLogDate, dbo.MDS20_RAP_VR.RAP_09_BehaviouralNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_09_BehaviouralNotesLogCoder, dbo.MDS20_RAP_VR.RAP_09_BehaviouralNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_10_Activities, dbo.MDS20_RAP_VR.RAP_10_ActivitiesDesc, dbo.MDS20_RAP_VR.RAP_10_ActivitiesNotes, 
                      dbo.MDS20_RAP_VR.RAP_10_ActivitiesNotesLogDate, dbo.MDS20_RAP_VR.RAP_10_ActivitiesNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_10_ActivitiesNotesLogCoder, dbo.MDS20_RAP_VR.RAP_10_ActivitiesNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_11_Falls, dbo.MDS20_RAP_VR.RAP_11_FallsDesc, dbo.MDS20_RAP_VR.RAP_11_FallsNotes, 
                      dbo.MDS20_RAP_VR.RAP_11_FallsNotesLogDate, dbo.MDS20_RAP_VR.RAP_11_FallsNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_11_FallsNotesLogCoder, dbo.MDS20_RAP_VR.RAP_11_FallsNotesLogCoderDesc, dbo.MDS20_RAP_VR.RAP_12_Nutritional,
                       dbo.MDS20_RAP_VR.RAP_12_NutritionalDesc, dbo.MDS20_RAP_VR.RAP_12_NutritionalNotes, 
                      dbo.MDS20_RAP_VR.RAP_12_NutritionalNotesLogDate, dbo.MDS20_RAP_VR.RAP_12_NutritionalNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_12_NutritionalNotesLogCoder, dbo.MDS20_RAP_VR.RAP_12_NutritionalNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_13_Feeding, dbo.MDS20_RAP_VR.RAP_13_FeedingDesc, dbo.MDS20_RAP_VR.RAP_13_FeedingNotes, 
                      dbo.MDS20_RAP_VR.RAP_13_FeedingNotesLogDate, dbo.MDS20_RAP_VR.RAP_13_FeedingNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_13_FeedingNotesLogCoder, dbo.MDS20_RAP_VR.RAP_13_FeedingNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_14_Dehydration, dbo.MDS20_RAP_VR.RAP_14_DehydrationDesc, dbo.MDS20_RAP_VR.RAP_14_DehydrationNotes, 
                      dbo.MDS20_RAP_VR.RAP_14_DehydrationNotesLogDate, dbo.MDS20_RAP_VR.RAP_14_DehydrationNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_14_DehydrationNotesLogCoder, dbo.MDS20_RAP_VR.RAP_14_DehydrationNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_15_Dental, dbo.MDS20_RAP_VR.RAP_15_DentalDesc, dbo.MDS20_RAP_VR.RAP_15_DentalNotes, 
                      dbo.MDS20_RAP_VR.RAP_15_DentalNotesLogDate, dbo.MDS20_RAP_VR.RAP_15_DentalNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_15_DentalNotesLogCoder, dbo.MDS20_RAP_VR.RAP_15_DentalNotesLogCoderDesc, dbo.MDS20_RAP_VR.RAP_16_Ulcers, 
                      dbo.MDS20_RAP_VR.RAP_16_UlcersDesc, dbo.MDS20_RAP_VR.RAP_16_UlcersNotes, dbo.MDS20_RAP_VR.RAP_16_UlcersNotesLogDate, 
                      dbo.MDS20_RAP_VR.RAP_16_UlcersNotesLogTime, dbo.MDS20_RAP_VR.RAP_16_UlcersNotesLogCoder, 
                      dbo.MDS20_RAP_VR.RAP_16_UlcersNotesLogCoderDesc, dbo.MDS20_RAP_VR.RAP_17_Drugs, dbo.MDS20_RAP_VR.RAP_17_DrugsDesc, 
                      dbo.MDS20_RAP_VR.RAP_17_DrugsNotes, dbo.MDS20_RAP_VR.RAP_17_DrugsNotesLogDate, dbo.MDS20_RAP_VR.RAP_17_DrugsNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_17_DrugsNotesLogCoder, dbo.MDS20_RAP_VR.RAP_17_DrugsNotesLogCoderDesc, 
                      dbo.MDS20_RAP_VR.RAP_18_Restraints, dbo.MDS20_RAP_VR.RAP_18_RestraintsDesc, dbo.MDS20_RAP_VR.RAP_18_RestraintsNotes, 
                      dbo.MDS20_RAP_VR.RAP_18_RestraintsNotesLogDate, dbo.MDS20_RAP_VR.RAP_18_RestraintsNotesLogTime, 
                      dbo.MDS20_RAP_VR.RAP_18_RestraintsNotesLogCoder, dbo.MDS20_RAP_VR.RAP_18_RestraintsNotesLogCoderDesc
FROM         dbo.MDS20_VR LEFT OUTER JOIN
                      dbo.MDS20_RAP_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_RAP_VR.zzAbstractLink
WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''05'', ''10'')) AND (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_Rugs_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[MDS20_Quarterly_Assessment_Rugs_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.ReasonAssessment_AA8, 
                      dbo.MDS20_VR.ReasonAssessmentDesc_AA8, dbo.MDS20_RUGS_VR.RUG_Group1, dbo.MDS20_RUGS_VR.CMI_Weight1, 
                      dbo.MDS20_RUGS_VR.RUG_Description1, dbo.MDS20_RUGS_VR.RUG_Group2, dbo.MDS20_RUGS_VR.CMI_Weight2, dbo.MDS20_RUGS_VR.RUG_Description2, 
                      dbo.MDS20_RUGS_VR.ADL
FROM         dbo.MDS20_RUGS_VR RIGHT OUTER JOIN
                      dbo.MDS20_VR ON dbo.MDS20_RUGS_VR.zzAbstractLink = dbo.MDS20_VR.zzAbstractLink
WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''05'', ''10'')) AND 
                      (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)

' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_Quarterly_Assessment_Signature_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'







CREATE  VIEW [dbo].[MDS20_Quarterly_Assessment_Signature_Form_VR]
AS
SELECT     dbo.MDS20_VR.zzAbstractLink, dbo.MDS20_VR.ReasonAssessment_AA8, 
                      dbo.MDS20_VR.ReasonAssessmentDesc_AA8, dbo.MDS20_Signature_VR.ProviderOccurrence, dbo.MDS20_Signature_VR.SignDate, 
                      dbo.MDS20_Signature_VR.Signature, dbo.MDS20_Signature_VR.Signature_Desc, dbo.MDS20_Signature_VR.ProviderServiceType, 
                      dbo.MDS20_Signature_VR.ProviderServiceType_Desc
FROM         dbo.MDS20_VR LEFT OUTER JOIN
                      dbo.MDS20_Signature_VR ON dbo.MDS20_VR.zzAbstractLink = dbo.MDS20_Signature_VR.zzAbstractLink
WHERE     (dbo.MDS20_VR.AA8_CIHI IN (''05'', ''10'')) AND 
                      (dbo.MDS20_VR.zzAbstractLink <> dbo.MDS20_VR.zzLinkBackgroundID)









' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MDS20_UpdateRecord_Form_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[MDS20_UpdateRecord_Form_VR]
AS
SELECT     zzAbstractLink, zzLinkBackgroundID, HealthRecordNumber_A6a, Birthdate_AA3a, AdmissionDate_AB1, RecordType_Z1, RecordTypeDesc_Z1, URI_AA1, MaidenName,
                       LastName, MiddleName, FirstName, FacilityNumber_AA6, FacilityNumberDesc_AA6, ReasonAssessment_AA8, AA8_CIHI, ReasonAssessmentDesc_AA8, 
                      ElementEffectiveDate_Z12, PrivatePayResidentFlag_AD1, PrivatePayResidentFlagDesc_AD1, BedType_AD2, BedTypeDesc_AD2, MISCode, MISCodeDesc, 
                      ProgramType_AD4, ProgramTypeDesc_AD4
FROM         dbo.MDS20_VR
WHERE     (RecordTypeCIHI_Z1 = ''17'')


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_And_Diagnosis_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[Rehab_And_Diagnosis_VR]
AS
SELECT     dbo.Rehab_VR.AboriginalStatus, dbo.Rehab_VR.AboriginalStatusDesc, dbo.Rehab_VR.AdmissionClass, dbo.Rehab_VR.AdmissionClassDesc, 
                      dbo.Rehab_VR.AdmissionDate, dbo.Rehab_VR.AgeCode, dbo.Rehab_VR.AgeCodeDesc, dbo.Rehab_VR.AgeNumber, dbo.Rehab_VR.ASIAImpairmentScale, 
                      dbo.Rehab_VR.ASIAImpairmentScaleDesc, dbo.Rehab_VR.AssessmentType, dbo.Rehab_VR.AssessmentTypeDesc, dbo.Rehab_VR.AttendingPhysician, 
                      dbo.Rehab_VR.AttendingPhysicianDesc, dbo.Rehab_VR.AuditoryorNonAuditoryComm, dbo.Rehab_VR.AuditoryorNonAuditoryCommDesc, dbo.Rehab_VR.BasicOption1, 
                      dbo.Rehab_VR.BasicOption1Desc, dbo.Rehab_VR.BasicOption2, dbo.Rehab_VR.BasicOption2Desc, dbo.Rehab_VR.BasicOption3, dbo.Rehab_VR.BasicOption3Desc, 
                      dbo.Rehab_VR.BasicOption4, dbo.Rehab_VR.BasicOption4Desc, dbo.Rehab_VR.BasicOption5, dbo.Rehab_VR.BasicOption5Desc, dbo.Rehab_VR.BasicOption6, 
                      dbo.Rehab_VR.BasicOption6Desc, dbo.Rehab_VR.BasicOption7, dbo.Rehab_VR.BasicOption7Desc, dbo.Rehab_VR.BasicOption8, dbo.Rehab_VR.BasicOption8Desc, 
                      dbo.Rehab_VR.BasicOption9, dbo.Rehab_VR.BasicOption9Desc, dbo.Rehab_VR.BasicOption10, dbo.Rehab_VR.BasicOption10Desc, dbo.Rehab_VR.BasicOption11, 
                      dbo.Rehab_VR.BasicOption11Desc, dbo.Rehab_VR.BasicOption12, dbo.Rehab_VR.BasicOption12Desc, dbo.Rehab_VR.BasicOption13, 
                      dbo.Rehab_VR.BasicOption13Desc, dbo.Rehab_VR.BasicOption14, dbo.Rehab_VR.BasicOption14Desc, dbo.Rehab_VR.BasicOption15, 
                      dbo.Rehab_VR.BasicOption15Desc, dbo.Rehab_VR.BasicOption16, dbo.Rehab_VR.BasicOption16Desc, dbo.Rehab_VR.BasicOption17, 
                      dbo.Rehab_VR.BasicOption17Desc, dbo.Rehab_VR.BasicOption18, dbo.Rehab_VR.BasicOption18Desc, dbo.Rehab_VR.BasicOption19, 
                      dbo.Rehab_VR.BasicOption19Desc, dbo.Rehab_VR.BatchPeriod, dbo.Rehab_VR.BatchPeriodDesc, dbo.Rehab_VR.BatchYear, dbo.Rehab_VR.Bathing, 
                      dbo.Rehab_VR.BathingDesc, dbo.Rehab_VR.BedChairWheelchair, dbo.Rehab_VR.BedChairWheelchairDesc, dbo.Rehab_VR.BirthDate, 
                      dbo.Rehab_VR.BladderManagement, dbo.Rehab_VR.BladderManagementDesc, dbo.Rehab_VR.BowelManagement, dbo.Rehab_VR.BowelManagementDesc, 
                      dbo.Rehab_VR.CanadianResidentInsPay, dbo.Rehab_VR.CanadianResidentInsPayDesc, dbo.Rehab_VR.CanadianResidentSelfPay, 
                      dbo.Rehab_VR.CanadianResidentSelfPayDesc, dbo.Rehab_VR.ChartNumber, dbo.Rehab_VR.CoderNumber, dbo.Rehab_VR.CoderNumberDesc, 
                      dbo.Rehab_VR.CognitiveDiscipline, dbo.Rehab_VR.CognitiveDisciplineDesc, dbo.Rehab_VR.CognitiveType, dbo.Rehab_VR.CognitiveTypeDesc, 
                      dbo.Rehab_VR.CommunicationDiscipline, dbo.Rehab_VR.CommunicationDisciplineDesc, dbo.Rehab_VR.CommunicationType, 
                      dbo.Rehab_VR.CommunicationTypeDesc, dbo.Rehab_VR.Comprehension, dbo.Rehab_VR.ComprehensionDesc, dbo.Rehab_VR.ComprehensionMode, 
                      dbo.Rehab_VR.ComprehensionModeDesc, dbo.Rehab_VR.ConsultationDiscipline, dbo.Rehab_VR.ConsultationDisciplineDesc, dbo.Rehab_VR.ConsultationType, 
                      dbo.Rehab_VR.ConsultationTypeDesc, dbo.Rehab_VR.CountryofResidence, dbo.Rehab_VR.CountryofResidenceDesc, dbo.Rehab_VR.DataEntryCoder, 
                      dbo.Rehab_VR.DataEntryCoderDesc, dbo.Rehab_VR.DateofOnset, dbo.Rehab_VR.DateReadyForAdmission, dbo.Rehab_VR.DateReadyForAdmitKnown, 
                      dbo.Rehab_VR.DateReadyForAdmitKnownDesc, dbo.Rehab_VR.DateReadyforDischarge, dbo.Rehab_VR.DateSenttoCIHI, dbo.Rehab_VR.DaysinHospitaltotalnumber, 
                      dbo.Rehab_VR.DealWithLifeEvents, dbo.Rehab_VR.DealWithLifeEventsDesc, dbo.Rehab_VR.DischargeDate, dbo.Rehab_VR.DressingLowerBody, 
                      dbo.Rehab_VR.DressingLowerBodyDesc, dbo.Rehab_VR.DressingUpperBody, dbo.Rehab_VR.DressingUpperBodyDesc, dbo.Rehab_VR.Eating, 
                      dbo.Rehab_VR.EatingDesc, dbo.Rehab_VR.EducationDiscipline, dbo.Rehab_VR.EducationDisciplineDesc, dbo.Rehab_VR.EducationType, 
                      dbo.Rehab_VR.EducationTypeDesc, dbo.Rehab_VR.EncounterNumber, dbo.Rehab_VR.EquipmentDiscipline, dbo.Rehab_VR.EquipmentDisciplineDesc, 
                      dbo.Rehab_VR.EquipmentType, dbo.Rehab_VR.EquipmentTypeDesc, dbo.Rehab_VR.EstimatedBirthdate, dbo.Rehab_VR.EstimatedBirthdateDesc, 
                      dbo.Rehab_VR.Expression, dbo.Rehab_VR.ExpressionDesc, dbo.Rehab_VR.ExpressionMode, dbo.Rehab_VR.ExpressionModeDesc, dbo.Rehab_VR.FacilityIdentifier, 
                      dbo.Rehab_VR.FacilityIdentifierDesc, dbo.Rehab_VR.FamilyRole, dbo.Rehab_VR.FamilyRoleDesc, dbo.Rehab_VR.FederalGovtDVA, 
                      dbo.Rehab_VR.FederalGovtDVADesc, dbo.Rehab_VR.FederalGovtFNIHB, dbo.Rehab_VR.FederalGovtFNIHBDesc, dbo.Rehab_VR.FederalGovtOther, 
                      dbo.Rehab_VR.FederalGovtOtherDesc, dbo.Rehab_VR.FIM, dbo.Rehab_VR.FinancialManagement, dbo.Rehab_VR.FinancialManagementDesc, 
                      dbo.Rehab_VR.FinishDate, dbo.Rehab_VR.FinishTime, dbo.Rehab_VR.FirstName, dbo.Rehab_VR.FixedChartNumber, dbo.Rehab_VR.FollowUpAssessmentDate, 
                      dbo.Rehab_VR.Gender, dbo.Rehab_VR.GenderDesc, dbo.Rehab_VR.GlassesHearingAidFlag, dbo.Rehab_VR.GlassesHearingAidFlagDesc, dbo.Rehab_VR.Grooming, 
                      dbo.Rehab_VR.GroomingDesc, dbo.Rehab_VR.HCNVersion, dbo.Rehab_VR.HealthCardNumber, dbo.Rehab_VR.HeavyHouseworkoptional, 
                      dbo.Rehab_VR.HeavyHouseworkoptionalDesc, dbo.Rehab_VR.Heightoptional, dbo.Rehab_VR.Hospital, dbo.Rehab_VR.HospitalDesc, 
                      dbo.Rehab_VR.HospitalAccountRecord,
                      dbo.Rehab_VR.HospitalizationSinceDisch, dbo.Rehab_VR.HospitalizationSinceDischDesc, dbo.Rehab_VR.ImpactofPainOnActivities, 
                      dbo.Rehab_VR.ImpactofPainOnActivitiesDesc, dbo.Rehab_VR.InformalSupportReceived, dbo.Rehab_VR.InformalSupportReceivedDesc, 
                      dbo.Rehab_VR.InitialDiscipline, dbo.Rehab_VR.InitialDisciplineDesc, dbo.Rehab_VR.InitialType, dbo.Rehab_VR.InitialTypeDesc, dbo.Rehab_VR.InjectionsDiscipline, 
                      dbo.Rehab_VR.InjectionsDisciplineDesc, dbo.Rehab_VR.InjectionsType, dbo.Rehab_VR.InjectionsTypeDesc, dbo.Rehab_VR.InputDate, dbo.Rehab_VR.InputTime, 
                      dbo.Rehab_VR.InterimDate, dbo.Rehab_VR.IntensityofPain, dbo.Rehab_VR.IntensityofPainDesc, dbo.Rehab_VR.InterfaceDate, dbo.Rehab_VR.InterfaceTime, 
                      dbo.Rehab_VR.InterfaceCoder, dbo.Rehab_VR.InterfaceCoderDesc, dbo.Rehab_VR.IsAbstractCompleted, dbo.Rehab_VR.IsAbstractCompletedDesc, 
                      dbo.Rehab_VR.IsAbstractCorrected, dbo.Rehab_VR.IsAbstractCorrectedDesc, dbo.Rehab_VR.IsAbstractDeleted, dbo.Rehab_VR.IsAbstractDeletedDesc, 
                      dbo.Rehab_VR.IsAbstractSubmitted, dbo.Rehab_VR.IsAbstractSubmittedDesc, dbo.Rehab_VR.IsAbstractValidated, dbo.Rehab_VR.IsAbstractValidatedDesc, 
                      dbo.Rehab_VR.LastName, dbo.Rehab_VR.LightHouseworkoptional, dbo.Rehab_VR.LightHouseworkoptionalDesc, dbo.Rehab_VR.LinkID, dbo.Rehab_VR.LivingAlone, 
                      dbo.Rehab_VR.LivingAloneDesc, dbo.Rehab_VR.LivingInAcuteCare, dbo.Rehab_VR.LivingInAcuteCareDesc, dbo.Rehab_VR.LivingInFacilityAllLevels, 
                      dbo.Rehab_VR.LivingInFacilityAllLevelsDesc, dbo.Rehab_VR.[LivingSetting(Pre/Post/FU)], dbo.Rehab_VR.[LivingSettingDesc(Pre/Post/FU)], 
                      dbo.Rehab_VR.LivingwithFamily, dbo.Rehab_VR.LivingwithFamilyDesc, dbo.Rehab_VR.LivingwithNonFamilyUnpaid, dbo.Rehab_VR.LivingwithNonFamilyUnpaidDesc, 
                      dbo.Rehab_VR.LivingwithPaidAttendant, dbo.Rehab_VR.LivingwithPaidAttendantDesc, dbo.Rehab_VR.LivingwithSpousePartner, 
                      dbo.Rehab_VR.LivingwithSpousePartnerDesc, dbo.Rehab_VR.LOSDays, dbo.Rehab_VR.MaidenName, dbo.Rehab_VR.MainWrittenHealthCondition, 
                      dbo.Rehab_VR.ManualTechDiscipline, dbo.Rehab_VR.ManualTechDisciplineDesc, dbo.Rehab_VR.ManualTechniquesType, 
                      dbo.Rehab_VR.ManualTechniquesTypeDesc, dbo.Rehab_VR.MealPreparationoptional, dbo.Rehab_VR.MealPreparationoptionalDesc, dbo.Rehab_VR.Memory, 
                      dbo.Rehab_VR.MemoryDesc, dbo.Rehab_VR.MiddleName, dbo.Rehab_VR.MISCode, dbo.Rehab_VR.MISCodeDesc, dbo.Rehab_VR.MobilityinCommunity, 
                      dbo.Rehab_VR.MobilityinCommunityDesc, dbo.Rehab_VR.MobilityinLivingQuarters, dbo.Rehab_VR.MobilityinLivingQuartersDesc, dbo.Rehab_VR.NameFull, 
                      dbo.Rehab_VR.NextAssessmentDate, dbo.Rehab_VR.NoneoftheAbove, dbo.Rehab_VR.NoneoftheAboveDesc, dbo.Rehab_VR.NursingArea, 
                      dbo.Rehab_VR.NursingAreaDesc, dbo.Rehab_VR.NutritionalDiscipline, dbo.Rehab_VR.NutritionalDisciplineDesc, dbo.Rehab_VR.NutritionalType, 
                      dbo.Rehab_VR.NutritionalTypeDesc, dbo.Rehab_VR.Orientation, dbo.Rehab_VR.OrientationDesc, dbo.Rehab_VR.OtherCountrySelfPay, 
                      dbo.Rehab_VR.OtherCountrySelfPayDesc, dbo.Rehab_VR.OtherLivingArrangements, dbo.Rehab_VR.OtherLivingArrangementsDesc, 
                      dbo.Rehab_VR.OtherProvTerritoryResidant, dbo.Rehab_VR.OtherProvTerritoryResidantDesc, dbo.Rehab_VR.OutofTownTrips, dbo.Rehab_VR.OutofTownTripsDesc, 
                      dbo.Rehab_VR.PaidEmployAdjustedMod, dbo.Rehab_VR.PaidEmployAdjustedModDesc, dbo.Rehab_VR.PaidEmploymentFullTime, 
                      dbo.Rehab_VR.PaidEmploymentFullTimeDesc, dbo.Rehab_VR.PaidEmploymentPartTime, dbo.Rehab_VR.PaidEmploymentPartTimeDesc, 
                      dbo.Rehab_VR.PersonalComfortwithOthers, dbo.Rehab_VR.PersonalComfortwithOthersDesc, dbo.Rehab_VR.PersonalRelationships, 
                      dbo.Rehab_VR.PersonalRelationshipsDesc, dbo.Rehab_VR.PhysicalDiscipline, dbo.Rehab_VR.PhysicalDisciplineDesc, dbo.Rehab_VR.PhysicalModalitiesDiscipline, 
                      dbo.Rehab_VR.PhysicalModalitiesDiscDesc, dbo.Rehab_VR.PhysicalModalitiesType, dbo.Rehab_VR.PhysicalModalitiesTypeDesc, dbo.Rehab_VR.PhysicalType, 
                      dbo.Rehab_VR.PhysicalTypeDesc, dbo.Rehab_VR.PlannedReAdmission, dbo.Rehab_VR.PlannedReAdmissionDesc, dbo.Rehab_VR.PostalCode, 
                      dbo.Rehab_VR.PostalCodeDesc, dbo.Rehab_VR.PrePostAdmitWrittenHCond1, dbo.Rehab_VR.PrePostAdmitWrittenHCond2, 
                      dbo.Rehab_VR.PrePostAdmitWrittenHCond3, dbo.Rehab_VR.PreHospitalLivingSetting, dbo.Rehab_VR.PreHospitalLivingSettingDesc, 
                      dbo.Rehab_VR.PresenceofCognitiveImpair, dbo.Rehab_VR.PresenceofCognitiveImpairDesc, dbo.Rehab_VR.PresenceofPain, dbo.Rehab_VR.PresenceofPainDesc, 
                      dbo.Rehab_VR.PrimaryLanguage, dbo.Rehab_VR.PrimaryLanguageDesc, dbo.Rehab_VR.PrimaryLanguageISO, dbo.Rehab_VR.PrimaryLanguageISODesc, 
                      dbo.Rehab_VR.PrimaryReasonWaitingDischarge, dbo.Rehab_VR.PrimaryReasonWaitingDischargeDesc, dbo.Rehab_VR.ProblemSolving, 
                      dbo.Rehab_VR.ProblemSolvingDesc, dbo.Rehab_VR.ProgramType, dbo.Rehab_VR.ProgramTypeDesc, dbo.Rehab_VR.ProvinceIssuingHCN, 
                      dbo.Rehab_VR.ProvinceIssuingHCNDesc, dbo.Rehab_VR.ProvinceofResidence, dbo.Rehab_VR.ProvinceofResidenceDesc, dbo.Rehab_VR.ProvinceTerritorialPlan, 
                      dbo.Rehab_VR.ProvinceTerritorialPlanDesc, dbo.Rehab_VR.ProvincialDefinition, dbo.Rehab_VR.ProvincialDefinitionDesc, dbo.Rehab_VR.PsychoSocialDiscipline, 
                      dbo.Rehab_VR.PsychoSocialDisciplineDesc, dbo.Rehab_VR.PsychoSocialType, dbo.Rehab_VR.PsychoSocialTypeDesc, dbo.Rehab_VR.ReadingCommunication, 
                      dbo.Rehab_VR.ReadingCommunicationDesc, dbo.Rehab_VR.ReAdmit1MonthSinceDisch, dbo.Rehab_VR.ReAdmit1MonthSinceDischDesc, 
                      dbo.Rehab_VR.ReasonforDischarge, dbo.Rehab_VR.ReasonforDischargeDesc, dbo.Rehab_VR.ReassessmentDiscipline, 
                      dbo.Rehab_VR.ReassessmentDisciplineDesc, dbo.Rehab_VR.ReassessmentType, dbo.Rehab_VR.ReassessmentTypeDesc, dbo.Rehab_VR.RecreationalActivities, 
                      dbo.Rehab_VR.RecreationalActivitiesDesc, dbo.Rehab_VR.ReferringProvider, dbo.Rehab_VR.ReferringProviderDesc, dbo.Rehab_VR.ReferralSource, 
                      dbo.Rehab_VR.ReferralSourceDesc, dbo.Rehab_VR.ReferralSourceFacilityNum, dbo.Rehab_VR.ReferralSourceFacilityNumDesc, 
                      dbo.Rehab_VR.ReferralSourceProvTerritory, dbo.Rehab_VR.ReferralSourceProvTerrDesc, dbo.Rehab_VR.ReferredTo, dbo.Rehab_VR.ReferredToDesc, 
                      dbo.Rehab_VR.ReferredToFacilityNumber, dbo.Rehab_VR.ReferredToFacilityNumberDesc, dbo.Rehab_VR.ReferredToProvTerr, 
                      dbo.Rehab_VR.ReferredToProvTerrDesc, dbo.Rehab_VR.RegisterNumber, dbo.Rehab_VR.RehabilitationClientGroup, dbo.Rehab_VR.RehabilitationClientGroupDesc, 
                      dbo.Rehab_VR.Respondent, dbo.Rehab_VR.RespondentDesc, dbo.Rehab_VR.RespondentType, dbo.Rehab_VR.RespondentTypeDesc, dbo.Rehab_VR.ResidenceCode, 
                      dbo.Rehab_VR.ResidenceCodeDesc, dbo.Rehab_VR.RetiredforAge, dbo.Rehab_VR.RetiredforAgeDesc, dbo.Rehab_VR.RetiredforDisability, 
                      dbo.Rehab_VR.RetiredforDisabilityDesc, dbo.Rehab_VR.ScreeningDiscipline, dbo.Rehab_VR.ScreeningDisciplineDesc, dbo.Rehab_VR.ScreeningType, 
                      dbo.Rehab_VR.ScreeningTypeDesc, dbo.Rehab_VR.SecondChartRegisterNumber, dbo.Rehab_VR.SecondaryReasonWaitingDischarge, 
                      dbo.Rehab_VR.SecondaryReasonWaitingDischargeDesc, dbo.Rehab_VR.Secret, dbo.Rehab_VR.SecretDesc, dbo.Rehab_VR.SelfCareNeeds, 
                      dbo.Rehab_VR.SelfCareNeedsDesc, dbo.Rehab_VR.ServicePlanningDiscipline, dbo.Rehab_VR.ServicePlanningDisciplineDesc, dbo.Rehab_VR.ServicePlanningType, 
                      dbo.Rehab_VR.ServicePlanningTypeDesc, dbo.Rehab_VR.SiteNumber, dbo.Rehab_VR.SiteNumberDesc, dbo.Rehab_VR.SocialActivities, 
                      dbo.Rehab_VR.SocialActivitiesDesc, dbo.Rehab_VR.SocialInteraction, dbo.Rehab_VR.SocialInteractionDesc, dbo.Rehab_VR.SocialParticDiscipline, 
                      dbo.Rehab_VR.SocialParticDisciplineDesc, dbo.Rehab_VR.SocialParticipationType, dbo.Rehab_VR.SocialParticipationTypeDesc, dbo.Rehab_VR.Stairs, 
                      dbo.Rehab_VR.StairsDesc, dbo.Rehab_VR.Status, dbo.Rehab_VR.StatusDesc, dbo.Rehab_VR.StudentAdjustedModified, dbo.Rehab_VR.StudentAdjustedModifiedDesc, 
                      dbo.Rehab_VR.StudentFullTime, dbo.Rehab_VR.StudentFullTimeDesc, dbo.Rehab_VR.StudentPartTime, dbo.Rehab_VR.StudentPartTimeDesc, 
                      dbo.Rehab_VR.TherapyStartDateOptional, dbo.Rehab_VR.TherapyEndDateOptional, dbo.Rehab_VR.Toilet, dbo.Rehab_VR.ToiletDesc, dbo.Rehab_VR.Toileting, 
                      dbo.Rehab_VR.ToiletingDesc, dbo.Rehab_VR.TransferWrittenHealthCondtn1, dbo.Rehab_VR.TranslTempLivingArrangemnt, 
                      dbo.Rehab_VR.TransTempLivingArrangemntDesc, dbo.Rehab_VR.TSIDate, dbo.Rehab_VR.TSITime, dbo.Rehab_VR.TSICoder, dbo.Rehab_VR.TSICoderDesc, 
                      dbo.Rehab_VR.TubShower, dbo.Rehab_VR.TubShowerDesc, dbo.Rehab_VR.Unemployed, dbo.Rehab_VR.UnemployedDesc, 
					  dbo.Rehab_VR.UniversalEpisodeIdentifier,
                      dbo.Rehab_VR.UnpaidEmployAdjustedMod, dbo.Rehab_VR.UnpaidEmployAdjustedModDesc, dbo.Rehab_VR.UnpaidEmploymentFullTime, 
                      dbo.Rehab_VR.UnpaidEmploymentFullTimeDesc, dbo.Rehab_VR.UnpaidEmploymentPartTime, dbo.Rehab_VR.UnpaidEmploymentPartTimeDesc, 
                      dbo.Rehab_VR.VerbalorNonVerbal, dbo.Rehab_VR.VerbalorNonVerbalDesc, dbo.Rehab_VR.VocationalDiscipline, dbo.Rehab_VR.VocationalDisciplineDesc, 
                      dbo.Rehab_VR.VocationalType, dbo.Rehab_VR.VocationalTypeDesc, dbo.Rehab_VR.WalkWheelchair, dbo.Rehab_VR.WalkWheelchairDesc, 
                      dbo.Rehab_VR.WalkWheelchairMode, dbo.Rehab_VR.WalkWheelchairModeDesc, dbo.Rehab_VR.WCBWSIB, dbo.Rehab_VR.WCBWSIBDesc, 
                      dbo.Rehab_VR.Weightoptional, dbo.Rehab_VR.WorkActivity, dbo.Rehab_VR.WorkActivityDesc, dbo.Rehab_VR.WrittenCommunication, 
                      dbo.Rehab_VR.WrittenCommunicationDesc, dbo.Rehab_Diagnosis_VR.DiagnosticConditionCode, dbo.Rehab_Diagnosis_VR.DiagnosticConditionCodeDesc, 
                      dbo.Rehab_Diagnosis_VR.DiagnosticConditionCodeICD, dbo.Rehab_Diagnosis_VR.DiagnosticConditionCodeICDDesc, 
                      dbo.Rehab_Diagnosis_VR.DiagnosticOccurrence, dbo.Rehab_Diagnosis_VR.DiagnosticType, dbo.Rehab_Diagnosis_VR.DiagnosticTypeDesc, 
                      dbo.Rehab_VR.zzAssessmentLink, dbo.Rehab_VR.zzRehabLink
FROM         dbo.Rehab_VR LEFT OUTER JOIN
                      dbo.Rehab_Diagnosis_VR ON dbo.Rehab_VR.zzRehabLink = dbo.Rehab_Diagnosis_VR.zzRehabLink


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_And_Interrupt_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[Rehab_And_Interrupt_VR]
AS
SELECT     dbo.Rehab_VR.AboriginalStatus, dbo.Rehab_VR.AboriginalStatusDesc, dbo.Rehab_VR.zzRehabLink, dbo.Rehab_VR.zzAssessmentLink, 
                      dbo.Rehab_VR.AdmissionClass, dbo.Rehab_VR.AdmissionClassDesc, dbo.Rehab_VR.AdmissionDate, dbo.Rehab_VR.AgeCode, dbo.Rehab_VR.AgeCodeDesc, 
                      dbo.Rehab_VR.AgeNumber, dbo.Rehab_VR.ASIAImpairmentScale, dbo.Rehab_VR.ASIAImpairmentScaleDesc, dbo.Rehab_VR.AssessmentType, 
                      dbo.Rehab_VR.AssessmentTypeDesc, dbo.Rehab_VR.AttendingPhysician, dbo.Rehab_VR.AttendingPhysicianDesc, dbo.Rehab_VR.AuditoryorNonAuditoryComm, 
                      dbo.Rehab_VR.AuditoryorNonAuditoryCommDesc, dbo.Rehab_VR.BasicOption1, dbo.Rehab_VR.BasicOption1Desc, dbo.Rehab_VR.BasicOption2, 
                      dbo.Rehab_VR.BasicOption2Desc, dbo.Rehab_VR.BasicOption3, dbo.Rehab_VR.BasicOption3Desc, dbo.Rehab_VR.BasicOption4, dbo.Rehab_VR.BasicOption4Desc, 
                      dbo.Rehab_VR.BasicOption5, dbo.Rehab_VR.BasicOption5Desc, dbo.Rehab_VR.BasicOption6, dbo.Rehab_VR.BasicOption6Desc, dbo.Rehab_VR.BasicOption7, 
                      dbo.Rehab_VR.BasicOption7Desc, dbo.Rehab_VR.BasicOption8, dbo.Rehab_VR.BasicOption8Desc, dbo.Rehab_VR.BasicOption9, dbo.Rehab_VR.BasicOption9Desc, 
                      dbo.Rehab_VR.BasicOption10, dbo.Rehab_VR.BasicOption10Desc, dbo.Rehab_VR.BasicOption11, dbo.Rehab_VR.BasicOption11Desc, dbo.Rehab_VR.BasicOption12, 
                      dbo.Rehab_VR.BasicOption12Desc, dbo.Rehab_VR.BasicOption13, dbo.Rehab_VR.BasicOption13Desc, dbo.Rehab_VR.BasicOption14, 
                      dbo.Rehab_VR.BasicOption14Desc, dbo.Rehab_VR.BasicOption15, dbo.Rehab_VR.BasicOption15Desc, dbo.Rehab_VR.BasicOption16, 
                      dbo.Rehab_VR.BasicOption16Desc, dbo.Rehab_VR.BasicOption17, dbo.Rehab_VR.BasicOption17Desc, dbo.Rehab_VR.BasicOption18, 
                      dbo.Rehab_VR.BasicOption18Desc, dbo.Rehab_VR.BasicOption19, dbo.Rehab_VR.BasicOption19Desc, dbo.Rehab_VR.BatchPeriod, dbo.Rehab_VR.BatchPeriodDesc, 
                      dbo.Rehab_VR.BatchYear, dbo.Rehab_VR.Bathing, dbo.Rehab_VR.BathingDesc, dbo.Rehab_VR.BedChairWheelchair, dbo.Rehab_VR.BedChairWheelchairDesc, 
                      dbo.Rehab_VR.BirthDate, dbo.Rehab_VR.BladderManagement, dbo.Rehab_VR.BladderManagementDesc, dbo.Rehab_VR.BowelManagement, 
                      dbo.Rehab_VR.BowelManagementDesc, dbo.Rehab_VR.CanadianResidentInsPay, dbo.Rehab_VR.CanadianResidentInsPayDesc, 
                      dbo.Rehab_VR.CanadianResidentSelfPay, dbo.Rehab_VR.CanadianResidentSelfPayDesc, dbo.Rehab_VR.ChartNumber, dbo.Rehab_VR.CoderNumber, 
                      dbo.Rehab_VR.CoderNumberDesc, dbo.Rehab_VR.CognitiveDiscipline, dbo.Rehab_VR.CognitiveDisciplineDesc, dbo.Rehab_VR.CognitiveType, 
                      dbo.Rehab_VR.CognitiveTypeDesc, dbo.Rehab_VR.CommunicationDiscipline, dbo.Rehab_VR.CommunicationDisciplineDesc, dbo.Rehab_VR.CommunicationType, 
                      dbo.Rehab_VR.CommunicationTypeDesc, dbo.Rehab_VR.Comprehension, dbo.Rehab_VR.ComprehensionDesc, dbo.Rehab_VR.ComprehensionMode, 
                      dbo.Rehab_VR.ComprehensionModeDesc, dbo.Rehab_VR.ConsultationDiscipline, dbo.Rehab_VR.ConsultationDisciplineDesc, dbo.Rehab_VR.ConsultationType, 
                      dbo.Rehab_VR.ConsultationTypeDesc, dbo.Rehab_VR.CountryofResidence, dbo.Rehab_VR.CountryofResidenceDesc, dbo.Rehab_VR.DataEntryCoder, 
                      dbo.Rehab_VR.DataEntryCoderDesc, dbo.Rehab_VR.DateofOnset, dbo.Rehab_VR.DateReadyForAdmission, dbo.Rehab_VR.DateReadyForAdmitKnown, 
                      dbo.Rehab_VR.DateReadyForAdmitKnownDesc, dbo.Rehab_VR.DateReadyforDischarge, dbo.Rehab_VR.DateSenttoCIHI, dbo.Rehab_VR.DaysinHospitaltotalnumber, 
                      dbo.Rehab_VR.DealWithLifeEvents, dbo.Rehab_VR.DealWithLifeEventsDesc, dbo.Rehab_VR.DischargeDate, dbo.Rehab_VR.DressingLowerBody, 
                      dbo.Rehab_VR.DressingLowerBodyDesc, dbo.Rehab_VR.DressingUpperBody, dbo.Rehab_VR.DressingUpperBodyDesc, dbo.Rehab_VR.Eating, 
                      dbo.Rehab_VR.EatingDesc, dbo.Rehab_VR.EducationDiscipline, dbo.Rehab_VR.EducationDisciplineDesc, dbo.Rehab_VR.EducationType, 
                      dbo.Rehab_VR.EducationTypeDesc, dbo.Rehab_VR.EncounterNumber, dbo.Rehab_VR.EquipmentDiscipline, dbo.Rehab_VR.EquipmentDisciplineDesc, 
                      dbo.Rehab_VR.EquipmentType, dbo.Rehab_VR.EquipmentTypeDesc, dbo.Rehab_VR.EstimatedBirthdate, dbo.Rehab_VR.EstimatedBirthdateDesc, 
                      dbo.Rehab_VR.Expression, dbo.Rehab_VR.ExpressionDesc, dbo.Rehab_VR.ExpressionMode, dbo.Rehab_VR.ExpressionModeDesc, dbo.Rehab_VR.FacilityIdentifier, 
                      dbo.Rehab_VR.FacilityIdentifierDesc, dbo.Rehab_VR.FamilyRole, dbo.Rehab_VR.FamilyRoleDesc, dbo.Rehab_VR.FederalGovtDVA, 
                      dbo.Rehab_VR.FederalGovtDVADesc, dbo.Rehab_VR.FederalGovtFNIHB, dbo.Rehab_VR.FederalGovtFNIHBDesc, dbo.Rehab_VR.FederalGovtOther, 
                      dbo.Rehab_VR.FederalGovtOtherDesc, dbo.Rehab_VR.FIM, dbo.Rehab_VR.FinancialManagement, dbo.Rehab_VR.FinancialManagementDesc, 
                      dbo.Rehab_VR.FinishDate, dbo.Rehab_VR.FinishTime, dbo.Rehab_VR.FirstName, dbo.Rehab_VR.FixedChartNumber, dbo.Rehab_VR.FollowUpAssessmentDate, 
                      dbo.Rehab_VR.Gender, dbo.Rehab_VR.GenderDesc, dbo.Rehab_VR.GlassesHearingAidFlag, dbo.Rehab_VR.GlassesHearingAidFlagDesc, dbo.Rehab_VR.Grooming, 
                      dbo.Rehab_VR.GroomingDesc, dbo.Rehab_VR.HCNVersion, dbo.Rehab_VR.HealthCardNumber, dbo.Rehab_VR.HeavyHouseworkoptional, 
                      dbo.Rehab_VR.HeavyHouseworkoptionalDesc, dbo.Rehab_VR.Heightoptional, dbo.Rehab_VR.Hospital, dbo.Rehab_VR.HospitalDesc, 
                      dbo.Rehab_VR.HospitalAccountRecord,
                      dbo.Rehab_VR.HospitalizationSinceDisch, dbo.Rehab_VR.HospitalizationSinceDischDesc, dbo.Rehab_VR.ImpactofPainOnActivities, 
                      dbo.Rehab_VR.ImpactofPainOnActivitiesDesc, dbo.Rehab_VR.InformalSupportReceived, dbo.Rehab_VR.InformalSupportReceivedDesc, 
                      dbo.Rehab_VR.InitialDiscipline, dbo.Rehab_VR.InitialDisciplineDesc, dbo.Rehab_VR.InitialType, dbo.Rehab_VR.InitialTypeDesc, dbo.Rehab_VR.InjectionsDiscipline, 
                      dbo.Rehab_VR.InjectionsDisciplineDesc, dbo.Rehab_VR.InjectionsType, dbo.Rehab_VR.InjectionsTypeDesc, dbo.Rehab_VR.InputDate, dbo.Rehab_VR.InputTime, 
                      dbo.Rehab_VR.InterimDate, dbo.Rehab_VR.IntensityofPain, dbo.Rehab_VR.IntensityofPainDesc, dbo.Rehab_VR.InterfaceDate, dbo.Rehab_VR.InterfaceTime, 
                      dbo.Rehab_VR.InterfaceCoder, dbo.Rehab_VR.InterfaceCoderDesc, dbo.Rehab_VR.IsAbstractCompleted, dbo.Rehab_VR.IsAbstractCompletedDesc, 
                      dbo.Rehab_VR.IsAbstractCorrected, dbo.Rehab_VR.IsAbstractCorrectedDesc, dbo.Rehab_VR.IsAbstractDeleted, dbo.Rehab_VR.IsAbstractDeletedDesc, 
                      dbo.Rehab_VR.IsAbstractSubmitted, dbo.Rehab_VR.IsAbstractSubmittedDesc, dbo.Rehab_VR.IsAbstractValidated, dbo.Rehab_VR.IsAbstractValidatedDesc, 
                      dbo.Rehab_VR.LastName, dbo.Rehab_VR.LightHouseworkoptional, dbo.Rehab_VR.LightHouseworkoptionalDesc, dbo.Rehab_VR.LinkID, dbo.Rehab_VR.LivingAlone, 
                      dbo.Rehab_VR.LivingAloneDesc, dbo.Rehab_VR.LivingInAcuteCare, dbo.Rehab_VR.LivingInAcuteCareDesc, dbo.Rehab_VR.LivingInFacilityAllLevels, 
                      dbo.Rehab_VR.LivingInFacilityAllLevelsDesc, dbo.Rehab_VR.[LivingSetting(Pre/Post/FU)], dbo.Rehab_VR.[LivingSettingDesc(Pre/Post/FU)], 
                      dbo.Rehab_VR.LivingwithFamily, dbo.Rehab_VR.LivingwithFamilyDesc, dbo.Rehab_VR.LivingwithNonFamilyUnpaid, dbo.Rehab_VR.LivingwithNonFamilyUnpaidDesc, 
                      dbo.Rehab_VR.LivingwithPaidAttendant, dbo.Rehab_VR.LivingwithPaidAttendantDesc, dbo.Rehab_VR.LivingwithSpousePartner, 
                      dbo.Rehab_VR.LivingwithSpousePartnerDesc, dbo.Rehab_VR.LOSDays, dbo.Rehab_VR.MaidenName, dbo.Rehab_VR.MainWrittenHealthCondition, 
                      dbo.Rehab_VR.ManualTechDiscipline, dbo.Rehab_VR.ManualTechDisciplineDesc, dbo.Rehab_VR.ManualTechniquesType, 
                      dbo.Rehab_VR.ManualTechniquesTypeDesc, dbo.Rehab_VR.MealPreparationoptional, dbo.Rehab_VR.MealPreparationoptionalDesc, dbo.Rehab_VR.Memory, 
                      dbo.Rehab_VR.MemoryDesc, dbo.Rehab_VR.MiddleName, dbo.Rehab_VR.MISCode, dbo.Rehab_VR.MISCodeDesc, dbo.Rehab_VR.MobilityinCommunity, 
                      dbo.Rehab_VR.MobilityinCommunityDesc, dbo.Rehab_VR.MobilityinLivingQuarters, dbo.Rehab_VR.MobilityinLivingQuartersDesc, dbo.Rehab_VR.NameFull, 
                      dbo.Rehab_VR.NextAssessmentDate, dbo.Rehab_VR.NoneoftheAbove, dbo.Rehab_VR.NoneoftheAboveDesc, dbo.Rehab_VR.NursingArea, 
                      dbo.Rehab_VR.NursingAreaDesc, dbo.Rehab_VR.NutritionalDiscipline, dbo.Rehab_VR.NutritionalDisciplineDesc, dbo.Rehab_VR.NutritionalType, 
                      dbo.Rehab_VR.NutritionalTypeDesc, dbo.Rehab_VR.Orientation, dbo.Rehab_VR.OrientationDesc, dbo.Rehab_VR.OtherCountrySelfPay, 
                      dbo.Rehab_VR.OtherCountrySelfPayDesc, dbo.Rehab_VR.OtherLivingArrangements, dbo.Rehab_VR.OtherLivingArrangementsDesc, 
                      dbo.Rehab_VR.OtherProvTerritoryResidant, dbo.Rehab_VR.OtherProvTerritoryResidantDesc, dbo.Rehab_VR.OutofTownTrips, dbo.Rehab_VR.OutofTownTripsDesc, 
                      dbo.Rehab_VR.PaidEmployAdjustedMod, dbo.Rehab_VR.PaidEmployAdjustedModDesc, dbo.Rehab_VR.PaidEmploymentFullTime, 
                      dbo.Rehab_VR.PaidEmploymentFullTimeDesc, dbo.Rehab_VR.PaidEmploymentPartTime, dbo.Rehab_VR.PaidEmploymentPartTimeDesc, 
                      dbo.Rehab_VR.PersonalComfortwithOthers, dbo.Rehab_VR.PersonalComfortwithOthersDesc, dbo.Rehab_VR.PersonalRelationships, 
                      dbo.Rehab_VR.PersonalRelationshipsDesc, dbo.Rehab_VR.PhysicalDiscipline, dbo.Rehab_VR.PhysicalDisciplineDesc, dbo.Rehab_VR.PhysicalModalitiesDiscipline, 
                      dbo.Rehab_VR.PhysicalModalitiesDiscDesc, dbo.Rehab_VR.PhysicalModalitiesType, dbo.Rehab_VR.PhysicalModalitiesTypeDesc, dbo.Rehab_VR.PhysicalType, 
                      dbo.Rehab_VR.PhysicalTypeDesc, dbo.Rehab_VR.PlannedReAdmission, dbo.Rehab_VR.PlannedReAdmissionDesc, dbo.Rehab_VR.PostalCode, 
                      dbo.Rehab_VR.PostalCodeDesc, dbo.Rehab_VR.PrePostAdmitWrittenHCond1, dbo.Rehab_VR.PrePostAdmitWrittenHCond2, 
                      dbo.Rehab_VR.PrePostAdmitWrittenHCond3, dbo.Rehab_VR.PreHospitalLivingSetting, dbo.Rehab_VR.PreHospitalLivingSettingDesc, 
                      dbo.Rehab_VR.PresenceofCognitiveImpair, dbo.Rehab_VR.PresenceofCognitiveImpairDesc, dbo.Rehab_VR.PresenceofPain, dbo.Rehab_VR.PresenceofPainDesc, 
                      dbo.Rehab_VR.PrimaryLanguage, dbo.Rehab_VR.PrimaryLanguageDesc, dbo.Rehab_VR.PrimaryLanguageISO, dbo.Rehab_VR.PrimaryLanguageISODesc, 
                      dbo.Rehab_VR.PrimaryReasonWaitingDischarge, dbo.Rehab_VR.PrimaryReasonWaitingDischargeDesc, dbo.Rehab_VR.ProblemSolving, 
                      dbo.Rehab_VR.ProblemSolvingDesc, dbo.Rehab_VR.ProgramType, dbo.Rehab_VR.ProgramTypeDesc, dbo.Rehab_VR.ProvinceIssuingHCN, 
                      dbo.Rehab_VR.ProvinceIssuingHCNDesc, dbo.Rehab_VR.ProvinceofResidence, dbo.Rehab_VR.ProvinceofResidenceDesc, dbo.Rehab_VR.ProvinceTerritorialPlan, 
                      dbo.Rehab_VR.ProvinceTerritorialPlanDesc, dbo.Rehab_VR.ProvincialDefinition, dbo.Rehab_VR.ProvincialDefinitionDesc, dbo.Rehab_VR.PsychoSocialDiscipline, 
                      dbo.Rehab_VR.PsychoSocialDisciplineDesc, dbo.Rehab_VR.PsychoSocialType, dbo.Rehab_VR.PsychoSocialTypeDesc, dbo.Rehab_VR.ReadingCommunication, 
                      dbo.Rehab_VR.ReadingCommunicationDesc, dbo.Rehab_VR.ReAdmit1MonthSinceDisch, dbo.Rehab_VR.ReAdmit1MonthSinceDischDesc, 
                      dbo.Rehab_VR.ReasonforDischarge, dbo.Rehab_VR.ReasonforDischargeDesc, dbo.Rehab_VR.ReassessmentDiscipline, 
                      dbo.Rehab_VR.ReassessmentDisciplineDesc, dbo.Rehab_VR.ReassessmentType, dbo.Rehab_VR.ReassessmentTypeDesc, dbo.Rehab_VR.RecreationalActivities, 
                      dbo.Rehab_VR.RecreationalActivitiesDesc, dbo.Rehab_VR.ReferringProvider, dbo.Rehab_VR.ReferringProviderDesc, dbo.Rehab_VR.ReferralSource, 
                      dbo.Rehab_VR.ReferralSourceDesc, dbo.Rehab_VR.ReferralSourceFacilityNum, dbo.Rehab_VR.ReferralSourceFacilityNumDesc, 
                      dbo.Rehab_VR.ReferralSourceProvTerritory, dbo.Rehab_VR.ReferralSourceProvTerrDesc, dbo.Rehab_VR.ReferredTo, dbo.Rehab_VR.ReferredToDesc, 
                      dbo.Rehab_VR.ReferredToFacilityNumber, dbo.Rehab_VR.ReferredToFacilityNumberDesc, dbo.Rehab_VR.ReferredToProvTerr, 
                      dbo.Rehab_VR.ReferredToProvTerrDesc, dbo.Rehab_VR.RegisterNumber, dbo.Rehab_VR.RehabilitationClientGroup, dbo.Rehab_VR.RehabilitationClientGroupDesc, 
                      dbo.Rehab_VR.Respondent, dbo.Rehab_VR.RespondentDesc, dbo.Rehab_VR.RespondentType, dbo.Rehab_VR.RespondentTypeDesc, dbo.Rehab_VR.ResidenceCode, 
                      dbo.Rehab_VR.ResidenceCodeDesc, dbo.Rehab_VR.RetiredforAge, dbo.Rehab_VR.RetiredforAgeDesc, dbo.Rehab_VR.RetiredforDisability, 
                      dbo.Rehab_VR.RetiredforDisabilityDesc, dbo.Rehab_VR.ScreeningDiscipline, dbo.Rehab_VR.ScreeningDisciplineDesc, dbo.Rehab_VR.ScreeningType, 
                      dbo.Rehab_VR.ScreeningTypeDesc, dbo.Rehab_VR.SecondChartRegisterNumber, dbo.Rehab_VR.SecondaryReasonWaitingDischarge, 
                      dbo.Rehab_VR.SecondaryReasonWaitingDischargeDesc, dbo.Rehab_VR.Secret, dbo.Rehab_VR.SecretDesc, dbo.Rehab_VR.SelfCareNeeds, 
                      dbo.Rehab_VR.SelfCareNeedsDesc, dbo.Rehab_VR.ServicePlanningDiscipline, dbo.Rehab_VR.ServicePlanningDisciplineDesc, dbo.Rehab_VR.ServicePlanningType, 
                      dbo.Rehab_VR.ServicePlanningTypeDesc, dbo.Rehab_VR.SiteNumber, dbo.Rehab_VR.SiteNumberDesc, dbo.Rehab_VR.SocialActivities, 
                      dbo.Rehab_VR.SocialActivitiesDesc, dbo.Rehab_VR.SocialInteraction, dbo.Rehab_VR.SocialInteractionDesc, dbo.Rehab_VR.SocialParticDiscipline, 
                      dbo.Rehab_VR.SocialParticDisciplineDesc, dbo.Rehab_VR.SocialParticipationType, dbo.Rehab_VR.SocialParticipationTypeDesc, dbo.Rehab_VR.Stairs, 
                      dbo.Rehab_VR.StairsDesc, dbo.Rehab_VR.Status, dbo.Rehab_VR.StatusDesc, dbo.Rehab_VR.StudentAdjustedModified, dbo.Rehab_VR.StudentAdjustedModifiedDesc, 
                      dbo.Rehab_VR.StudentFullTime, dbo.Rehab_VR.StudentFullTimeDesc, dbo.Rehab_VR.StudentPartTime, dbo.Rehab_VR.StudentPartTimeDesc, 
                      dbo.Rehab_VR.TherapyStartDateOptional, dbo.Rehab_VR.TherapyEndDateOptional, dbo.Rehab_VR.Toilet, dbo.Rehab_VR.ToiletDesc, dbo.Rehab_VR.Toileting, 
                      dbo.Rehab_VR.ToiletingDesc, dbo.Rehab_VR.TransferWrittenHealthCondtn1, dbo.Rehab_VR.TranslTempLivingArrangemnt, 
                      dbo.Rehab_VR.TransTempLivingArrangemntDesc, dbo.Rehab_VR.TSIDate, dbo.Rehab_VR.TSITime, dbo.Rehab_VR.TSICoder, dbo.Rehab_VR.TSICoderDesc, 
                      dbo.Rehab_VR.TubShower, dbo.Rehab_VR.TubShowerDesc, dbo.Rehab_VR.Unemployed, dbo.Rehab_VR.UnemployedDesc, 
                      dbo.Rehab_VR.UniversalEpisodeIdentifier,
					  dbo.Rehab_VR.UnpaidEmployAdjustedMod, dbo.Rehab_VR.UnpaidEmployAdjustedModDesc, dbo.Rehab_VR.UnpaidEmploymentFullTime, 
                      dbo.Rehab_VR.UnpaidEmploymentFullTimeDesc, dbo.Rehab_VR.UnpaidEmploymentPartTime, dbo.Rehab_VR.UnpaidEmploymentPartTimeDesc, 
                      dbo.Rehab_VR.VerbalorNonVerbal, dbo.Rehab_VR.VerbalorNonVerbalDesc, dbo.Rehab_VR.VocationalDiscipline, dbo.Rehab_VR.VocationalDisciplineDesc, 
                      dbo.Rehab_VR.VocationalType, dbo.Rehab_VR.VocationalTypeDesc, dbo.Rehab_VR.WalkWheelchair, dbo.Rehab_VR.WalkWheelchairDesc, 
                      dbo.Rehab_VR.WalkWheelchairMode, dbo.Rehab_VR.WalkWheelchairModeDesc, dbo.Rehab_VR.WCBWSIB, dbo.Rehab_VR.WCBWSIBDesc, 
                      dbo.Rehab_VR.Weightoptional, dbo.Rehab_VR.WorkActivity, dbo.Rehab_VR.WorkActivityDesc, dbo.Rehab_VR.WrittenCommunication, 
                      dbo.Rehab_VR.WrittenCommunicationDesc, dbo.Rehab_Interrupt_VR.InterruptionOccurrenceNumber, dbo.Rehab_Interrupt_VR.InterruptionReason, 
                      dbo.Rehab_Interrupt_VR.InterruptionReasonDesc, dbo.Rehab_Interrupt_VR.InterruptionReasonICD, dbo.Rehab_Interrupt_VR.InterruptionReasonICDDesc, 
                      dbo.Rehab_Interrupt_VR.InterruptionReturnDate, dbo.Rehab_Interrupt_VR.InterruptionStartDate, dbo.Rehab_Interrupt_VR.InterruptionTransferred, 
                      dbo.Rehab_Interrupt_VR.InterruptionTransferredDesc
FROM         dbo.Rehab_VR LEFT OUTER JOIN
                      dbo.Rehab_Interrupt_VR ON dbo.Rehab_VR.zzRehabLink = dbo.Rehab_Interrupt_VR.zzRehabLink


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_And_Intervention_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[Rehab_And_Intervention_VR]
AS
SELECT     dbo.Rehab_VR.AboriginalStatus, dbo.Rehab_VR.AboriginalStatusDesc, dbo.Rehab_VR.AdmissionClass, dbo.Rehab_VR.AdmissionClassDesc, 
                      dbo.Rehab_VR.AdmissionDate, dbo.Rehab_VR.AgeCode, dbo.Rehab_VR.AgeCodeDesc, dbo.Rehab_VR.AgeNumber, dbo.Rehab_VR.ASIAImpairmentScale, 
                      dbo.Rehab_VR.ASIAImpairmentScaleDesc, dbo.Rehab_VR.AssessmentType, dbo.Rehab_VR.AssessmentTypeDesc, dbo.Rehab_VR.AttendingPhysician, 
                      dbo.Rehab_VR.AttendingPhysicianDesc, dbo.Rehab_VR.AuditoryorNonAuditoryComm, dbo.Rehab_VR.AuditoryorNonAuditoryCommDesc, dbo.Rehab_VR.BasicOption1, 
                      dbo.Rehab_VR.BasicOption1Desc, dbo.Rehab_VR.BasicOption2, dbo.Rehab_VR.BasicOption2Desc, dbo.Rehab_VR.BasicOption3, dbo.Rehab_VR.BasicOption3Desc, 
                      dbo.Rehab_VR.BasicOption4, dbo.Rehab_VR.BasicOption4Desc, dbo.Rehab_VR.BasicOption5, dbo.Rehab_VR.BasicOption5Desc, dbo.Rehab_VR.BasicOption6, 
                      dbo.Rehab_VR.BasicOption6Desc, dbo.Rehab_VR.BasicOption7, dbo.Rehab_VR.BasicOption7Desc, dbo.Rehab_VR.BasicOption8, dbo.Rehab_VR.BasicOption8Desc, 
                      dbo.Rehab_VR.BasicOption9, dbo.Rehab_VR.BasicOption9Desc, dbo.Rehab_VR.BasicOption10, dbo.Rehab_VR.BasicOption10Desc, dbo.Rehab_VR.BasicOption11, 
                      dbo.Rehab_VR.BasicOption11Desc, dbo.Rehab_VR.BasicOption12, dbo.Rehab_VR.BasicOption12Desc, dbo.Rehab_VR.BasicOption13, 
                      dbo.Rehab_VR.BasicOption13Desc, dbo.Rehab_VR.BasicOption14, dbo.Rehab_VR.BasicOption14Desc, dbo.Rehab_VR.BasicOption15, 
                      dbo.Rehab_VR.BasicOption15Desc, dbo.Rehab_VR.BasicOption16, dbo.Rehab_VR.BasicOption16Desc, dbo.Rehab_VR.BasicOption17, 
                      dbo.Rehab_VR.BasicOption17Desc, dbo.Rehab_VR.BasicOption18, dbo.Rehab_VR.BasicOption18Desc, dbo.Rehab_VR.BasicOption19, 
                      dbo.Rehab_VR.BasicOption19Desc, dbo.Rehab_VR.BatchPeriod, dbo.Rehab_VR.BatchPeriodDesc, dbo.Rehab_VR.BatchYear, dbo.Rehab_VR.Bathing, 
                      dbo.Rehab_VR.BathingDesc, dbo.Rehab_VR.BedChairWheelchair, dbo.Rehab_VR.BedChairWheelchairDesc, dbo.Rehab_VR.BirthDate, 
                      dbo.Rehab_VR.BladderManagement, dbo.Rehab_VR.BladderManagementDesc, dbo.Rehab_VR.BowelManagement, dbo.Rehab_VR.BowelManagementDesc, 
                      dbo.Rehab_VR.CanadianResidentInsPay, dbo.Rehab_VR.CanadianResidentInsPayDesc, dbo.Rehab_VR.CanadianResidentSelfPay, 
                      dbo.Rehab_VR.CanadianResidentSelfPayDesc, dbo.Rehab_VR.ChartNumber, dbo.Rehab_VR.CoderNumber, dbo.Rehab_VR.CoderNumberDesc, 
                      dbo.Rehab_VR.CognitiveDiscipline, dbo.Rehab_VR.CognitiveDisciplineDesc, dbo.Rehab_VR.CognitiveType, dbo.Rehab_VR.CognitiveTypeDesc, 
                      dbo.Rehab_VR.CommunicationDiscipline, dbo.Rehab_VR.CommunicationDisciplineDesc, dbo.Rehab_VR.CommunicationType, 
                      dbo.Rehab_VR.CommunicationTypeDesc, dbo.Rehab_VR.Comprehension, dbo.Rehab_VR.ComprehensionDesc, dbo.Rehab_VR.ComprehensionMode, 
                      dbo.Rehab_VR.ComprehensionModeDesc, dbo.Rehab_VR.ConsultationDiscipline, dbo.Rehab_VR.ConsultationDisciplineDesc, dbo.Rehab_VR.ConsultationType, 
                      dbo.Rehab_VR.ConsultationTypeDesc, dbo.Rehab_VR.CountryofResidence, dbo.Rehab_VR.CountryofResidenceDesc, dbo.Rehab_VR.DataEntryCoder, 
                      dbo.Rehab_VR.DataEntryCoderDesc, dbo.Rehab_VR.DateofOnset, dbo.Rehab_VR.DateReadyForAdmission, dbo.Rehab_VR.DateReadyForAdmitKnown, 
                      dbo.Rehab_VR.DateReadyForAdmitKnownDesc, dbo.Rehab_VR.DateReadyforDischarge, dbo.Rehab_VR.DateSenttoCIHI, dbo.Rehab_VR.DaysinHospitaltotalnumber, 
                      dbo.Rehab_VR.DealWithLifeEvents, dbo.Rehab_VR.DealWithLifeEventsDesc, dbo.Rehab_VR.DischargeDate, dbo.Rehab_VR.DressingLowerBody, 
                      dbo.Rehab_VR.DressingLowerBodyDesc, dbo.Rehab_VR.DressingUpperBody, dbo.Rehab_VR.DressingUpperBodyDesc, dbo.Rehab_VR.Eating, 
                      dbo.Rehab_VR.EatingDesc, dbo.Rehab_VR.EducationDiscipline, dbo.Rehab_VR.EducationDisciplineDesc, dbo.Rehab_VR.EducationType, 
                      dbo.Rehab_VR.EducationTypeDesc, dbo.Rehab_VR.EncounterNumber, dbo.Rehab_VR.EquipmentDiscipline, dbo.Rehab_VR.EquipmentDisciplineDesc, 
                      dbo.Rehab_VR.EquipmentType, dbo.Rehab_VR.EquipmentTypeDesc, dbo.Rehab_VR.EstimatedBirthdate, dbo.Rehab_VR.EstimatedBirthdateDesc, 
                      dbo.Rehab_VR.Expression, dbo.Rehab_VR.ExpressionDesc, dbo.Rehab_VR.ExpressionMode, dbo.Rehab_VR.ExpressionModeDesc, dbo.Rehab_VR.FacilityIdentifier, 
                      dbo.Rehab_VR.FacilityIdentifierDesc, dbo.Rehab_VR.FamilyRole, dbo.Rehab_VR.FamilyRoleDesc, dbo.Rehab_VR.FederalGovtDVA, 
                      dbo.Rehab_VR.FederalGovtDVADesc, dbo.Rehab_VR.FederalGovtFNIHB, dbo.Rehab_VR.FederalGovtFNIHBDesc, dbo.Rehab_VR.FederalGovtOther, 
                      dbo.Rehab_VR.FederalGovtOtherDesc, dbo.Rehab_VR.FIM, dbo.Rehab_VR.FinancialManagement, dbo.Rehab_VR.FinancialManagementDesc, 
                      dbo.Rehab_VR.FinishDate, dbo.Rehab_VR.FinishTime, dbo.Rehab_VR.FirstName, dbo.Rehab_VR.FixedChartNumber, dbo.Rehab_VR.FollowUpAssessmentDate, 
                      dbo.Rehab_VR.Gender, dbo.Rehab_VR.GlassesHearingAidFlag, dbo.Rehab_VR.GlassesHearingAidFlagDesc, dbo.Rehab_VR.GenderDesc, dbo.Rehab_VR.Grooming, 
                      dbo.Rehab_VR.GroomingDesc, dbo.Rehab_VR.HCNVersion, dbo.Rehab_VR.HealthCardNumber, dbo.Rehab_VR.HeavyHouseworkoptional, 
                      dbo.Rehab_VR.HeavyHouseworkoptionalDesc, dbo.Rehab_VR.Heightoptional, dbo.Rehab_VR.Hospital, dbo.Rehab_VR.HospitalDesc, 
                      dbo.Rehab_VR.HospitalAccountRecord,
                      dbo.Rehab_VR.HospitalizationSinceDisch, dbo.Rehab_VR.HospitalizationSinceDischDesc, dbo.Rehab_VR.ImpactofPainOnActivities, 
                      dbo.Rehab_VR.ImpactofPainOnActivitiesDesc, dbo.Rehab_VR.InformalSupportReceived, dbo.Rehab_VR.InformalSupportReceivedDesc, 
                      dbo.Rehab_VR.InitialDiscipline, dbo.Rehab_VR.InitialDisciplineDesc, dbo.Rehab_VR.InitialType, dbo.Rehab_VR.InitialTypeDesc, dbo.Rehab_VR.InjectionsDiscipline, 
                      dbo.Rehab_VR.InjectionsDisciplineDesc, dbo.Rehab_VR.InjectionsType, dbo.Rehab_VR.InjectionsTypeDesc, dbo.Rehab_VR.InputDate, dbo.Rehab_VR.InputTime, 
                      dbo.Rehab_VR.InterimDate, dbo.Rehab_VR.IntensityofPain, dbo.Rehab_VR.IntensityofPainDesc, dbo.Rehab_VR.InterfaceDate, dbo.Rehab_VR.InterfaceTime, 
                      dbo.Rehab_VR.InterfaceCoder, dbo.Rehab_VR.InterfaceCoderDesc, dbo.Rehab_VR.IsAbstractCompleted, dbo.Rehab_VR.IsAbstractCompletedDesc, 
                      dbo.Rehab_VR.IsAbstractCorrected, dbo.Rehab_VR.IsAbstractCorrectedDesc, dbo.Rehab_VR.IsAbstractDeleted, dbo.Rehab_VR.IsAbstractDeletedDesc, 
                      dbo.Rehab_VR.IsAbstractSubmitted, dbo.Rehab_VR.IsAbstractSubmittedDesc, dbo.Rehab_VR.IsAbstractValidated, dbo.Rehab_VR.IsAbstractValidatedDesc, 
                      dbo.Rehab_VR.LastName, dbo.Rehab_VR.LightHouseworkoptional, dbo.Rehab_VR.LightHouseworkoptionalDesc, dbo.Rehab_VR.LinkID, dbo.Rehab_VR.LivingAlone, 
                      dbo.Rehab_VR.LivingAloneDesc, dbo.Rehab_VR.LivingInAcuteCare, dbo.Rehab_VR.LivingInAcuteCareDesc, dbo.Rehab_VR.LivingInFacilityAllLevels, 
                      dbo.Rehab_VR.LivingInFacilityAllLevelsDesc, dbo.Rehab_VR.[LivingSetting(Pre/Post/FU)], dbo.Rehab_VR.[LivingSettingDesc(Pre/Post/FU)], 
                      dbo.Rehab_VR.LivingwithFamily, dbo.Rehab_VR.LivingwithFamilyDesc, dbo.Rehab_VR.LivingwithNonFamilyUnpaid, dbo.Rehab_VR.LivingwithNonFamilyUnpaidDesc, 
                      dbo.Rehab_VR.LivingwithPaidAttendant, dbo.Rehab_VR.LivingwithPaidAttendantDesc, dbo.Rehab_VR.LivingwithSpousePartner, 
                      dbo.Rehab_VR.LivingwithSpousePartnerDesc, dbo.Rehab_VR.LOSDays, dbo.Rehab_VR.MaidenName, dbo.Rehab_VR.MainWrittenHealthCondition, 
                      dbo.Rehab_VR.ManualTechDiscipline, dbo.Rehab_VR.ManualTechDisciplineDesc, dbo.Rehab_VR.ManualTechniquesType, 
                      dbo.Rehab_VR.ManualTechniquesTypeDesc, dbo.Rehab_VR.MealPreparationoptional, dbo.Rehab_VR.MealPreparationoptionalDesc, dbo.Rehab_VR.Memory, 
                      dbo.Rehab_VR.MemoryDesc, dbo.Rehab_VR.MiddleName, dbo.Rehab_VR.MISCode, dbo.Rehab_VR.MISCodeDesc, dbo.Rehab_VR.MobilityinCommunity, 
                      dbo.Rehab_VR.MobilityinCommunityDesc, dbo.Rehab_VR.MobilityinLivingQuarters, dbo.Rehab_VR.MobilityinLivingQuartersDesc, dbo.Rehab_VR.NameFull, 
                      dbo.Rehab_VR.NextAssessmentDate, dbo.Rehab_VR.NoneoftheAbove, dbo.Rehab_VR.NoneoftheAboveDesc, dbo.Rehab_VR.NursingArea, 
                      dbo.Rehab_VR.NursingAreaDesc, dbo.Rehab_VR.NutritionalDiscipline, dbo.Rehab_VR.NutritionalDisciplineDesc, dbo.Rehab_VR.NutritionalType, 
                      dbo.Rehab_VR.NutritionalTypeDesc, dbo.Rehab_VR.Orientation, dbo.Rehab_VR.OrientationDesc, dbo.Rehab_VR.OtherCountrySelfPay, 
                      dbo.Rehab_VR.OtherCountrySelfPayDesc, dbo.Rehab_VR.OtherLivingArrangements, dbo.Rehab_VR.OtherLivingArrangementsDesc, 
                      dbo.Rehab_VR.OtherProvTerritoryResidant, dbo.Rehab_VR.OtherProvTerritoryResidantDesc, dbo.Rehab_VR.OutofTownTrips, dbo.Rehab_VR.OutofTownTripsDesc, 
                      dbo.Rehab_VR.PaidEmployAdjustedMod, dbo.Rehab_VR.PaidEmployAdjustedModDesc, dbo.Rehab_VR.PaidEmploymentFullTime, 
                      dbo.Rehab_VR.PaidEmploymentFullTimeDesc, dbo.Rehab_VR.PaidEmploymentPartTime, dbo.Rehab_VR.PaidEmploymentPartTimeDesc, 
                      dbo.Rehab_VR.PersonalComfortwithOthers, dbo.Rehab_VR.PersonalComfortwithOthersDesc, dbo.Rehab_VR.PersonalRelationships, 
                      dbo.Rehab_VR.PersonalRelationshipsDesc, dbo.Rehab_VR.PhysicalDiscipline, dbo.Rehab_VR.PhysicalDisciplineDesc, dbo.Rehab_VR.PhysicalModalitiesDiscipline, 
                      dbo.Rehab_VR.PhysicalModalitiesDiscDesc, dbo.Rehab_VR.PhysicalModalitiesType, dbo.Rehab_VR.PhysicalModalitiesTypeDesc, dbo.Rehab_VR.PhysicalType, 
                      dbo.Rehab_VR.PhysicalTypeDesc, dbo.Rehab_VR.PlannedReAdmission, dbo.Rehab_VR.PlannedReAdmissionDesc, dbo.Rehab_VR.PostalCode, 
                      dbo.Rehab_VR.PostalCodeDesc, dbo.Rehab_VR.PrePostAdmitWrittenHCond1, dbo.Rehab_VR.PrePostAdmitWrittenHCond2, 
                      dbo.Rehab_VR.PrePostAdmitWrittenHCond3, dbo.Rehab_VR.PreHospitalLivingSetting, dbo.Rehab_VR.PreHospitalLivingSettingDesc, 
                      dbo.Rehab_VR.PresenceofCognitiveImpair, dbo.Rehab_VR.PresenceofCognitiveImpairDesc, dbo.Rehab_VR.PresenceofPain, dbo.Rehab_VR.PresenceofPainDesc, 
                      dbo.Rehab_VR.PrimaryLanguage, dbo.Rehab_VR.PrimaryLanguageDesc, dbo.Rehab_VR.PrimaryLanguageISO, dbo.Rehab_VR.PrimaryLanguageISODesc, 
                      dbo.Rehab_VR.PrimaryReasonWaitingDischarge, dbo.Rehab_VR.PrimaryReasonWaitingDischargeDesc, dbo.Rehab_VR.ProblemSolving, 
                      dbo.Rehab_VR.ProblemSolvingDesc, dbo.Rehab_VR.ProgramType, dbo.Rehab_VR.ProgramTypeDesc, dbo.Rehab_VR.ProvinceIssuingHCN, 
                      dbo.Rehab_VR.ProvinceIssuingHCNDesc, dbo.Rehab_VR.ProvinceofResidence, dbo.Rehab_VR.ProvinceofResidenceDesc, dbo.Rehab_VR.ProvinceTerritorialPlan, 
                      dbo.Rehab_VR.ProvinceTerritorialPlanDesc, dbo.Rehab_VR.ProvincialDefinition, dbo.Rehab_VR.ProvincialDefinitionDesc, dbo.Rehab_VR.PsychoSocialDiscipline, 
                      dbo.Rehab_VR.PsychoSocialDisciplineDesc, dbo.Rehab_VR.PsychoSocialType, dbo.Rehab_VR.PsychoSocialTypeDesc, dbo.Rehab_VR.ReadingCommunication, 
                      dbo.Rehab_VR.ReadingCommunicationDesc, dbo.Rehab_VR.ReAdmit1MonthSinceDisch, dbo.Rehab_VR.ReAdmit1MonthSinceDischDesc, 
                      dbo.Rehab_VR.ReasonforDischarge, dbo.Rehab_VR.ReasonforDischargeDesc, dbo.Rehab_VR.ReassessmentDiscipline, 
                      dbo.Rehab_VR.ReassessmentDisciplineDesc, dbo.Rehab_VR.ReassessmentType, dbo.Rehab_VR.ReassessmentTypeDesc, dbo.Rehab_VR.RecreationalActivities, 
                      dbo.Rehab_VR.RecreationalActivitiesDesc, dbo.Rehab_VR.ReferralSource, dbo.Rehab_VR.ReferralSourceDesc, dbo.Rehab_VR.ReferralSourceFacilityNum, 
                      dbo.Rehab_VR.ReferralSourceFacilityNumDesc, dbo.Rehab_VR.ReferralSourceProvTerritory, dbo.Rehab_VR.ReferralSourceProvTerrDesc, dbo.Rehab_VR.ReferredTo, 
                      dbo.Rehab_VR.ReferredToDesc, dbo.Rehab_VR.ReferredToFacilityNumber, dbo.Rehab_VR.ReferredToFacilityNumberDesc, dbo.Rehab_VR.ReferredToProvTerr, 
                      dbo.Rehab_VR.ReferredToProvTerrDesc, dbo.Rehab_VR.ReferringProvider, dbo.Rehab_VR.ReferringProviderDesc, dbo.Rehab_VR.RegisterNumber, 
                      dbo.Rehab_VR.RehabilitationClientGroup, dbo.Rehab_VR.RehabilitationClientGroupDesc, dbo.Rehab_VR.Respondent, dbo.Rehab_VR.RespondentDesc, 
                      dbo.Rehab_VR.RespondentType, dbo.Rehab_VR.RespondentTypeDesc, dbo.Rehab_VR.ResidenceCode, dbo.Rehab_VR.ResidenceCodeDesc, 
                      dbo.Rehab_VR.RetiredforAge, dbo.Rehab_VR.RetiredforAgeDesc, dbo.Rehab_VR.RetiredforDisability, dbo.Rehab_VR.RetiredforDisabilityDesc, 
                      dbo.Rehab_VR.SecondChartRegisterNumber, dbo.Rehab_VR.SecondaryReasonWaitingDischarge, dbo.Rehab_VR.SecondaryReasonWaitingDischargeDesc, 
                      dbo.Rehab_VR.ScreeningDiscipline, dbo.Rehab_VR.ScreeningDisciplineDesc, dbo.Rehab_VR.ScreeningType, dbo.Rehab_VR.ScreeningTypeDesc, 
                      dbo.Rehab_VR.Secret, dbo.Rehab_VR.SecretDesc, dbo.Rehab_VR.SelfCareNeeds, dbo.Rehab_VR.SelfCareNeedsDesc, dbo.Rehab_VR.ServicePlanningDiscipline, 
                      dbo.Rehab_VR.ServicePlanningDisciplineDesc, dbo.Rehab_VR.ServicePlanningType, dbo.Rehab_VR.ServicePlanningTypeDesc, dbo.Rehab_VR.SiteNumber, 
                      dbo.Rehab_VR.SiteNumberDesc, dbo.Rehab_VR.SocialActivities, dbo.Rehab_VR.SocialActivitiesDesc, dbo.Rehab_VR.SocialInteraction, 
                      dbo.Rehab_VR.SocialInteractionDesc, dbo.Rehab_VR.SocialParticDiscipline, dbo.Rehab_VR.SocialParticDisciplineDesc, dbo.Rehab_VR.SocialParticipationType, 
                      dbo.Rehab_VR.SocialParticipationTypeDesc, dbo.Rehab_VR.Stairs, dbo.Rehab_VR.StairsDesc, dbo.Rehab_VR.Status, dbo.Rehab_VR.StatusDesc, 
                      dbo.Rehab_VR.StudentAdjustedModified, dbo.Rehab_VR.StudentAdjustedModifiedDesc, dbo.Rehab_VR.StudentFullTime, dbo.Rehab_VR.StudentFullTimeDesc, 
                      dbo.Rehab_VR.StudentPartTime, dbo.Rehab_VR.StudentPartTimeDesc, dbo.Rehab_VR.TherapyStartDateOptional, dbo.Rehab_VR.TherapyEndDateOptional, 
                      dbo.Rehab_VR.Toilet, dbo.Rehab_VR.ToiletDesc, dbo.Rehab_VR.Toileting, dbo.Rehab_VR.ToiletingDesc, dbo.Rehab_VR.TransferWrittenHealthCondtn1, 
                      dbo.Rehab_VR.TranslTempLivingArrangemnt, dbo.Rehab_VR.TransTempLivingArrangemntDesc, dbo.Rehab_VR.TSIDate, dbo.Rehab_VR.TSITime, 
                      dbo.Rehab_VR.TSICoder, dbo.Rehab_VR.TSICoderDesc, dbo.Rehab_VR.TubShower, dbo.Rehab_VR.TubShowerDesc, dbo.Rehab_VR.Unemployed, 
                      dbo.Rehab_VR.UnemployedDesc, dbo.Rehab_VR.UniversalEpisodeIdentifier,
					  dbo.Rehab_VR.UnpaidEmployAdjustedMod, dbo.Rehab_VR.UnpaidEmployAdjustedModDesc, 
                      dbo.Rehab_VR.UnpaidEmploymentFullTime, dbo.Rehab_VR.UnpaidEmploymentFullTimeDesc, dbo.Rehab_VR.UnpaidEmploymentPartTime, 
                      dbo.Rehab_VR.UnpaidEmploymentPartTimeDesc, dbo.Rehab_VR.VerbalorNonVerbal, dbo.Rehab_VR.VerbalorNonVerbalDesc, dbo.Rehab_VR.VocationalDiscipline, 
                      dbo.Rehab_VR.VocationalDisciplineDesc, dbo.Rehab_VR.VocationalType, dbo.Rehab_VR.VocationalTypeDesc, dbo.Rehab_VR.WalkWheelchair, 
                      dbo.Rehab_VR.WalkWheelchairDesc, dbo.Rehab_VR.WalkWheelchairMode, dbo.Rehab_VR.WalkWheelchairModeDesc, dbo.Rehab_VR.WCBWSIB, 
                      dbo.Rehab_VR.WCBWSIBDesc, dbo.Rehab_VR.Weightoptional, dbo.Rehab_VR.WorkActivity, dbo.Rehab_VR.WorkActivityDesc, dbo.Rehab_VR.WrittenCommunication, 
                      dbo.Rehab_VR.WrittenCommunicationDesc, dbo.Rehab_Interventions_VR.AnestheticTechnique, dbo.Rehab_Interventions_VR.AnestheticTechniqueDesc, 
                      dbo.Rehab_Interventions_VR.AnesthetistID, dbo.Rehab_Interventions_VR.AnesthetistIDDesc, dbo.Rehab_Interventions_VR.InterventionCIHIValue, 
                      dbo.Rehab_Interventions_VR.InterventionCode, dbo.Rehab_Interventions_VR.InterventionCodeDesc, dbo.Rehab_Interventions_VR.InterventionCodeShortDesc, 
                      dbo.Rehab_Interventions_VR.IntervDateIn, dbo.Rehab_Interventions_VR.IntervDateOut, dbo.Rehab_Interventions_VR.InterventionAttributeExtent, 
                      dbo.Rehab_Interventions_VR.IntervAttributeExtentDesc, dbo.Rehab_Interventions_VR.InterventionAttributeLocation, 
                      dbo.Rehab_Interventions_VR.IntervAttributeLocationDesc, dbo.Rehab_Interventions_VR.InterventionAttributeStatus, 
                      dbo.Rehab_Interventions_VR.IntervAttributeStatusDesc, dbo.Rehab_Interventions_VR.InterventionDate, dbo.Rehab_Interventions_VR.InterventionLocation, 
                      dbo.Rehab_Interventions_VR.InterventionLocationDesc, dbo.Rehab_Interventions_VR.InterventionOccurrence, 
                      dbo.Rehab_Interventions_VR.InterventionProviderNumber, dbo.Rehab_Interventions_VR.InterventionProviderNumberDesc, 
                      dbo.Rehab_Interventions_VR.InterventionProviderSpecialty, dbo.Rehab_Interventions_VR.IntervProviderSpecialtyDesc, 
                      dbo.Rehab_Interventions_VR.InterventionTimeIn, dbo.Rehab_Interventions_VR.InterventionTimeinMinutes, dbo.Rehab_Interventions_VR.InterventionTimeOut, 
                      dbo.Rehab_Interventions_VR.OOHIndicator, dbo.Rehab_Interventions_VR.OOHIndicatorDesc, dbo.Rehab_Interventions_VR.OOHInstitutionNumber, 
                      dbo.Rehab_Interventions_VR.OOHInstitutionNumberDesc, dbo.Rehab_Interventions_VR.TissueCode, dbo.Rehab_Interventions_VR.TissueCodeDesc, 
                      dbo.Rehab_Interventions_VR.UnplannedReturntoOR, dbo.Rehab_Interventions_VR.UnplannedReturntoORDesc, dbo.Rehab_VR.zzAssessmentLink, 
                      dbo.Rehab_VR.zzRehabLink
FROM         dbo.Rehab_VR LEFT OUTER JOIN
                      dbo.Rehab_Interventions_VR ON dbo.Rehab_VR.zzRehabLink = dbo.Rehab_Interventions_VR.zzRehabLink


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_And_Project_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[Rehab_And_Project_VR]
AS
SELECT     dbo.Rehab_VR.AboriginalStatus, dbo.Rehab_VR.AboriginalStatusDesc, dbo.Rehab_VR.AdmissionClass, dbo.Rehab_VR.AdmissionClassDesc, 
                      dbo.Rehab_VR.AdmissionDate, dbo.Rehab_VR.AgeCode, dbo.Rehab_VR.AgeCodeDesc, dbo.Rehab_VR.AgeNumber, dbo.Rehab_VR.ASIAImpairmentScale, 
                      dbo.Rehab_VR.ASIAImpairmentScaleDesc, dbo.Rehab_VR.AssessmentType, dbo.Rehab_VR.AssessmentTypeDesc, dbo.Rehab_VR.AttendingPhysician, 
                      dbo.Rehab_VR.AttendingPhysicianDesc, dbo.Rehab_VR.AuditoryorNonAuditoryComm, dbo.Rehab_VR.AuditoryorNonAuditoryCommDesc, dbo.Rehab_VR.BasicOption1, 
                      dbo.Rehab_VR.BasicOption1Desc, dbo.Rehab_VR.BasicOption2, dbo.Rehab_VR.BasicOption2Desc, dbo.Rehab_VR.BasicOption3, dbo.Rehab_VR.BasicOption3Desc, 
                      dbo.Rehab_VR.BasicOption4, dbo.Rehab_VR.BasicOption4Desc, dbo.Rehab_VR.BasicOption5, dbo.Rehab_VR.BasicOption5Desc, dbo.Rehab_VR.BasicOption6, 
                      dbo.Rehab_VR.BasicOption6Desc, dbo.Rehab_VR.BasicOption7, dbo.Rehab_VR.BasicOption7Desc, dbo.Rehab_VR.BasicOption8, dbo.Rehab_VR.BasicOption8Desc, 
                      dbo.Rehab_VR.BasicOption9, dbo.Rehab_VR.BasicOption9Desc, dbo.Rehab_VR.BasicOption10, dbo.Rehab_VR.BasicOption10Desc, dbo.Rehab_VR.BasicOption11, 
                      dbo.Rehab_VR.BasicOption11Desc, dbo.Rehab_VR.BasicOption12, dbo.Rehab_VR.BasicOption12Desc, dbo.Rehab_VR.BasicOption13, 
                      dbo.Rehab_VR.BasicOption13Desc, dbo.Rehab_VR.BasicOption14, dbo.Rehab_VR.BasicOption14Desc, dbo.Rehab_VR.BasicOption15, 
                      dbo.Rehab_VR.BasicOption15Desc, dbo.Rehab_VR.BasicOption16, dbo.Rehab_VR.BasicOption16Desc, dbo.Rehab_VR.BasicOption17, 
                      dbo.Rehab_VR.BasicOption17Desc, dbo.Rehab_VR.BasicOption18, dbo.Rehab_VR.BasicOption18Desc, dbo.Rehab_VR.BasicOption19, 
                      dbo.Rehab_VR.BasicOption19Desc, dbo.Rehab_VR.BatchPeriod, dbo.Rehab_VR.BatchPeriodDesc, dbo.Rehab_VR.BatchYear, dbo.Rehab_VR.Bathing, 
                      dbo.Rehab_VR.BathingDesc, dbo.Rehab_VR.BedChairWheelchair, dbo.Rehab_VR.BedChairWheelchairDesc, dbo.Rehab_VR.BirthDate, 
                      dbo.Rehab_VR.BladderManagement, dbo.Rehab_VR.BladderManagementDesc, dbo.Rehab_VR.BowelManagement, dbo.Rehab_VR.BowelManagementDesc, 
                      dbo.Rehab_VR.CanadianResidentInsPay, dbo.Rehab_VR.CanadianResidentInsPayDesc, dbo.Rehab_VR.CanadianResidentSelfPay, 
                      dbo.Rehab_VR.CanadianResidentSelfPayDesc, dbo.Rehab_VR.ChartNumber, dbo.Rehab_VR.CoderNumber, dbo.Rehab_VR.CoderNumberDesc, 
                      dbo.Rehab_VR.CognitiveDiscipline, dbo.Rehab_VR.CognitiveDisciplineDesc, dbo.Rehab_VR.CognitiveType, dbo.Rehab_VR.CognitiveTypeDesc, 
                      dbo.Rehab_VR.CommunicationDiscipline, dbo.Rehab_VR.CommunicationDisciplineDesc, dbo.Rehab_VR.CommunicationType, 
                      dbo.Rehab_VR.CommunicationTypeDesc, dbo.Rehab_VR.Comprehension, dbo.Rehab_VR.ComprehensionDesc, dbo.Rehab_VR.ComprehensionMode, 
                      dbo.Rehab_VR.ComprehensionModeDesc, dbo.Rehab_VR.ConsultationDiscipline, dbo.Rehab_VR.ConsultationDisciplineDesc, dbo.Rehab_VR.ConsultationType, 
                      dbo.Rehab_VR.ConsultationTypeDesc, dbo.Rehab_VR.CountryofResidence, dbo.Rehab_VR.CountryofResidenceDesc, dbo.Rehab_VR.DataEntryCoder, 
                      dbo.Rehab_VR.DataEntryCoderDesc, dbo.Rehab_VR.DateofOnset, dbo.Rehab_VR.DateReadyForAdmission, dbo.Rehab_VR.DateReadyForAdmitKnown, 
                      dbo.Rehab_VR.DateReadyForAdmitKnownDesc, dbo.Rehab_VR.DateReadyforDischarge, dbo.Rehab_VR.DateSenttoCIHI, dbo.Rehab_VR.DaysinHospitaltotalnumber, 
                      dbo.Rehab_VR.DealWithLifeEvents, dbo.Rehab_VR.DealWithLifeEventsDesc, dbo.Rehab_VR.DischargeDate, dbo.Rehab_VR.DressingLowerBody, 
                      dbo.Rehab_VR.DressingLowerBodyDesc, dbo.Rehab_VR.DressingUpperBody, dbo.Rehab_VR.DressingUpperBodyDesc, dbo.Rehab_VR.Eating, 
                      dbo.Rehab_VR.EatingDesc, dbo.Rehab_VR.EducationDiscipline, dbo.Rehab_VR.EducationDisciplineDesc, dbo.Rehab_VR.EducationType, 
                      dbo.Rehab_VR.EducationTypeDesc, dbo.Rehab_VR.EncounterNumber, dbo.Rehab_VR.EquipmentDiscipline, dbo.Rehab_VR.EquipmentDisciplineDesc, 
                      dbo.Rehab_VR.EquipmentType, dbo.Rehab_VR.EquipmentTypeDesc, dbo.Rehab_VR.EstimatedBirthdate, dbo.Rehab_VR.EstimatedBirthdateDesc, 
                      dbo.Rehab_VR.Expression, dbo.Rehab_VR.ExpressionDesc, dbo.Rehab_VR.ExpressionMode, dbo.Rehab_VR.ExpressionModeDesc, dbo.Rehab_VR.FacilityIdentifier, 
                      dbo.Rehab_VR.FacilityIdentifierDesc, dbo.Rehab_VR.FamilyRole, dbo.Rehab_VR.FamilyRoleDesc, dbo.Rehab_VR.FederalGovtDVA, 
                      dbo.Rehab_VR.FederalGovtDVADesc, dbo.Rehab_VR.FederalGovtFNIHB, dbo.Rehab_VR.FederalGovtFNIHBDesc, dbo.Rehab_VR.FederalGovtOther, 
                      dbo.Rehab_VR.FederalGovtOtherDesc, dbo.Rehab_VR.FIM, dbo.Rehab_VR.FinancialManagement, dbo.Rehab_VR.FinancialManagementDesc, 
                      dbo.Rehab_VR.FinishDate, dbo.Rehab_VR.FinishTime, dbo.Rehab_VR.FirstName, dbo.Rehab_VR.FixedChartNumber, dbo.Rehab_VR.FollowUpAssessmentDate, 
                      dbo.Rehab_VR.Gender, dbo.Rehab_VR.GenderDesc, dbo.Rehab_VR.GlassesHearingAidFlag, dbo.Rehab_VR.GlassesHearingAidFlagDesc, dbo.Rehab_VR.Grooming, 
                      dbo.Rehab_VR.GroomingDesc, dbo.Rehab_VR.HealthCardNumber, dbo.Rehab_VR.HCNVersion, dbo.Rehab_VR.HeavyHouseworkoptional, 
                      dbo.Rehab_VR.HeavyHouseworkoptionalDesc, dbo.Rehab_VR.Heightoptional, dbo.Rehab_VR.Hospital, dbo.Rehab_VR.HospitalDesc, 
                      dbo.Rehab_VR.HospitalAccountRecord,
                      dbo.Rehab_VR.HospitalizationSinceDisch, dbo.Rehab_VR.HospitalizationSinceDischDesc, dbo.Rehab_VR.ImpactofPainOnActivities, 
                      dbo.Rehab_VR.ImpactofPainOnActivitiesDesc, dbo.Rehab_VR.InformalSupportReceived, dbo.Rehab_VR.InformalSupportReceivedDesc, 
                      dbo.Rehab_VR.InitialDiscipline, dbo.Rehab_VR.InitialDisciplineDesc, dbo.Rehab_VR.InitialType, dbo.Rehab_VR.InitialTypeDesc, dbo.Rehab_VR.InjectionsDiscipline, 
                      dbo.Rehab_VR.InjectionsDisciplineDesc, dbo.Rehab_VR.InjectionsType, dbo.Rehab_VR.InjectionsTypeDesc, dbo.Rehab_VR.InputDate, dbo.Rehab_VR.InputTime, 
                      dbo.Rehab_VR.InterimDate, dbo.Rehab_VR.IntensityofPain, dbo.Rehab_VR.IntensityofPainDesc, dbo.Rehab_VR.InterfaceDate, dbo.Rehab_VR.InterfaceTime, 
                      dbo.Rehab_VR.InterfaceCoder, dbo.Rehab_VR.InterfaceCoderDesc, dbo.Rehab_VR.IsAbstractCompleted, dbo.Rehab_VR.IsAbstractCompletedDesc, 
                      dbo.Rehab_VR.IsAbstractCorrected, dbo.Rehab_VR.IsAbstractCorrectedDesc, dbo.Rehab_VR.IsAbstractDeleted, dbo.Rehab_VR.IsAbstractDeletedDesc, 
                      dbo.Rehab_VR.IsAbstractSubmitted, dbo.Rehab_VR.IsAbstractSubmittedDesc, dbo.Rehab_VR.IsAbstractValidated, dbo.Rehab_VR.IsAbstractValidatedDesc, 
                      dbo.Rehab_VR.LastName, dbo.Rehab_VR.LightHouseworkoptional, dbo.Rehab_VR.LightHouseworkoptionalDesc, dbo.Rehab_VR.LinkID, dbo.Rehab_VR.LivingAlone, 
                      dbo.Rehab_VR.LivingAloneDesc, dbo.Rehab_VR.LivingInAcuteCare, dbo.Rehab_VR.LivingInAcuteCareDesc, dbo.Rehab_VR.LivingInFacilityAllLevels, 
                      dbo.Rehab_VR.LivingInFacilityAllLevelsDesc, dbo.Rehab_VR.[LivingSetting(Pre/Post/FU)], dbo.Rehab_VR.[LivingSettingDesc(Pre/Post/FU)], 
                      dbo.Rehab_VR.LivingwithFamily, dbo.Rehab_VR.LivingwithFamilyDesc, dbo.Rehab_VR.LivingwithNonFamilyUnpaid, dbo.Rehab_VR.LivingwithNonFamilyUnpaidDesc, 
                      dbo.Rehab_VR.LivingwithPaidAttendant, dbo.Rehab_VR.LivingwithPaidAttendantDesc, dbo.Rehab_VR.LivingwithSpousePartner, 
                      dbo.Rehab_VR.LivingwithSpousePartnerDesc, dbo.Rehab_VR.LOSDays, dbo.Rehab_VR.MaidenName, dbo.Rehab_VR.MainWrittenHealthCondition, 
                      dbo.Rehab_VR.ManualTechDiscipline, dbo.Rehab_VR.ManualTechDisciplineDesc, dbo.Rehab_VR.ManualTechniquesType, 
                      dbo.Rehab_VR.ManualTechniquesTypeDesc, dbo.Rehab_VR.MealPreparationoptional, dbo.Rehab_VR.MealPreparationoptionalDesc, dbo.Rehab_VR.Memory, 
                      dbo.Rehab_VR.MemoryDesc, dbo.Rehab_VR.MiddleName, dbo.Rehab_VR.MISCode, dbo.Rehab_VR.MISCodeDesc, dbo.Rehab_VR.MobilityinCommunity, 
                      dbo.Rehab_VR.MobilityinCommunityDesc, dbo.Rehab_VR.MobilityinLivingQuarters, dbo.Rehab_VR.MobilityinLivingQuartersDesc, dbo.Rehab_VR.NameFull, 
                      dbo.Rehab_VR.NextAssessmentDate, dbo.Rehab_VR.NoneoftheAbove, dbo.Rehab_VR.NoneoftheAboveDesc, dbo.Rehab_VR.NursingArea, 
                      dbo.Rehab_VR.NursingAreaDesc, dbo.Rehab_VR.NutritionalDiscipline, dbo.Rehab_VR.NutritionalDisciplineDesc, dbo.Rehab_VR.NutritionalType, 
                      dbo.Rehab_VR.NutritionalTypeDesc, dbo.Rehab_VR.Orientation, dbo.Rehab_VR.OrientationDesc, dbo.Rehab_VR.OtherCountrySelfPay, 
                      dbo.Rehab_VR.OtherCountrySelfPayDesc, dbo.Rehab_VR.OtherLivingArrangements, dbo.Rehab_VR.OtherLivingArrangementsDesc, 
                      dbo.Rehab_VR.OtherProvTerritoryResidant, dbo.Rehab_VR.OtherProvTerritoryResidantDesc, dbo.Rehab_VR.OutofTownTrips, dbo.Rehab_VR.OutofTownTripsDesc, 
                      dbo.Rehab_VR.PaidEmployAdjustedMod, dbo.Rehab_VR.PaidEmployAdjustedModDesc, dbo.Rehab_VR.PaidEmploymentFullTime, 
                      dbo.Rehab_VR.PaidEmploymentFullTimeDesc, dbo.Rehab_VR.PaidEmploymentPartTime, dbo.Rehab_VR.PaidEmploymentPartTimeDesc, 
                      dbo.Rehab_VR.PersonalComfortwithOthers, dbo.Rehab_VR.PersonalComfortwithOthersDesc, dbo.Rehab_VR.PersonalRelationships, 
                      dbo.Rehab_VR.PersonalRelationshipsDesc, dbo.Rehab_VR.PhysicalDiscipline, dbo.Rehab_VR.PhysicalDisciplineDesc, dbo.Rehab_VR.PhysicalModalitiesDiscipline, 
                      dbo.Rehab_VR.PhysicalModalitiesDiscDesc, dbo.Rehab_VR.PhysicalModalitiesType, dbo.Rehab_VR.PhysicalModalitiesTypeDesc, dbo.Rehab_VR.PhysicalType, 
                      dbo.Rehab_VR.PhysicalTypeDesc, dbo.Rehab_VR.PlannedReAdmission, dbo.Rehab_VR.PlannedReAdmissionDesc, dbo.Rehab_VR.PostalCode, 
                      dbo.Rehab_VR.PostalCodeDesc, dbo.Rehab_VR.PrePostAdmitWrittenHCond1, dbo.Rehab_VR.PrePostAdmitWrittenHCond2, 
                      dbo.Rehab_VR.PrePostAdmitWrittenHCond3, dbo.Rehab_VR.PreHospitalLivingSetting, dbo.Rehab_VR.PreHospitalLivingSettingDesc, 
                      dbo.Rehab_VR.PresenceofCognitiveImpair, dbo.Rehab_VR.PresenceofCognitiveImpairDesc, dbo.Rehab_VR.PresenceofPain, dbo.Rehab_VR.PresenceofPainDesc, 
                      dbo.Rehab_VR.PrimaryLanguage, dbo.Rehab_VR.PrimaryLanguageDesc, dbo.Rehab_VR.PrimaryLanguageISO, dbo.Rehab_VR.PrimaryLanguageISODesc, 
                      dbo.Rehab_VR.PrimaryReasonWaitingDischarge, dbo.Rehab_VR.PrimaryReasonWaitingDischargeDesc, dbo.Rehab_VR.ProblemSolving, 
                      dbo.Rehab_VR.ProblemSolvingDesc, dbo.Rehab_VR.ProgramType, dbo.Rehab_VR.ProgramTypeDesc, dbo.Rehab_VR.ProvinceIssuingHCN, 
                      dbo.Rehab_VR.ProvinceIssuingHCNDesc, dbo.Rehab_VR.ProvinceofResidence, dbo.Rehab_VR.ProvinceofResidenceDesc, dbo.Rehab_VR.ProvinceTerritorialPlan, 
                      dbo.Rehab_VR.ProvinceTerritorialPlanDesc, dbo.Rehab_VR.ProvincialDefinition, dbo.Rehab_VR.ProvincialDefinitionDesc, dbo.Rehab_VR.PsychoSocialDiscipline, 
                      dbo.Rehab_VR.PsychoSocialDisciplineDesc, dbo.Rehab_VR.PsychoSocialType, dbo.Rehab_VR.PsychoSocialTypeDesc, dbo.Rehab_VR.ReadingCommunication, 
                      dbo.Rehab_VR.ReadingCommunicationDesc, dbo.Rehab_VR.ReAdmit1MonthSinceDisch, dbo.Rehab_VR.ReAdmit1MonthSinceDischDesc, 
                      dbo.Rehab_VR.ReasonforDischarge, dbo.Rehab_VR.ReasonforDischargeDesc, dbo.Rehab_VR.ReassessmentDiscipline, 
                      dbo.Rehab_VR.ReassessmentDisciplineDesc, dbo.Rehab_VR.ReassessmentType, dbo.Rehab_VR.ReassessmentTypeDesc, dbo.Rehab_VR.RecreationalActivities, 
                      dbo.Rehab_VR.RecreationalActivitiesDesc, dbo.Rehab_VR.ReferralSource, dbo.Rehab_VR.ReferralSourceDesc, dbo.Rehab_VR.ReferralSourceFacilityNum, 
                      dbo.Rehab_VR.ReferralSourceFacilityNumDesc, dbo.Rehab_VR.ReferralSourceProvTerritory, dbo.Rehab_VR.ReferralSourceProvTerrDesc, dbo.Rehab_VR.ReferredTo, 
                      dbo.Rehab_VR.ReferredToDesc, dbo.Rehab_VR.ReferredToFacilityNumber, dbo.Rehab_VR.ReferredToFacilityNumberDesc, dbo.Rehab_VR.ReferredToProvTerr, 
                      dbo.Rehab_VR.ReferredToProvTerrDesc, dbo.Rehab_VR.ReferringProvider, dbo.Rehab_VR.ReferringProviderDesc, dbo.Rehab_VR.RegisterNumber, 
                      dbo.Rehab_VR.RehabilitationClientGroup, dbo.Rehab_VR.RehabilitationClientGroupDesc, dbo.Rehab_VR.Respondent, dbo.Rehab_VR.RespondentDesc, 
                      dbo.Rehab_VR.RespondentType, dbo.Rehab_VR.RespondentTypeDesc, dbo.Rehab_VR.ResidenceCode, dbo.Rehab_VR.ResidenceCodeDesc, 
                      dbo.Rehab_VR.RetiredforAge, dbo.Rehab_VR.RetiredforAgeDesc, dbo.Rehab_VR.RetiredforDisability, dbo.Rehab_VR.RetiredforDisabilityDesc, 
                      dbo.Rehab_VR.SecondChartRegisterNumber, dbo.Rehab_VR.SecondaryReasonWaitingDischarge, dbo.Rehab_VR.SecondaryReasonWaitingDischargeDesc, 
                      dbo.Rehab_VR.ScreeningDiscipline, dbo.Rehab_VR.ScreeningDisciplineDesc, dbo.Rehab_VR.ScreeningType, dbo.Rehab_VR.ScreeningTypeDesc, 
                      dbo.Rehab_VR.Secret, dbo.Rehab_VR.SecretDesc, dbo.Rehab_VR.SelfCareNeeds, dbo.Rehab_VR.SelfCareNeedsDesc, dbo.Rehab_VR.ServicePlanningDiscipline, 
                      dbo.Rehab_VR.ServicePlanningDisciplineDesc, dbo.Rehab_VR.ServicePlanningType, dbo.Rehab_VR.ServicePlanningTypeDesc, dbo.Rehab_VR.SiteNumber, 
                      dbo.Rehab_VR.SiteNumberDesc, dbo.Rehab_VR.SocialActivities, dbo.Rehab_VR.SocialActivitiesDesc, dbo.Rehab_VR.SocialInteraction, 
                      dbo.Rehab_VR.SocialInteractionDesc, dbo.Rehab_VR.SocialParticDiscipline, dbo.Rehab_VR.SocialParticDisciplineDesc, dbo.Rehab_VR.SocialParticipationType, 
                      dbo.Rehab_VR.SocialParticipationTypeDesc, dbo.Rehab_VR.Stairs, dbo.Rehab_VR.StairsDesc, dbo.Rehab_VR.Status, dbo.Rehab_VR.StatusDesc, 
                      dbo.Rehab_VR.StudentAdjustedModified, dbo.Rehab_VR.StudentAdjustedModifiedDesc, dbo.Rehab_VR.StudentFullTime, dbo.Rehab_VR.StudentFullTimeDesc, 
                      dbo.Rehab_VR.StudentPartTime, dbo.Rehab_VR.StudentPartTimeDesc, dbo.Rehab_VR.TherapyStartDateOptional, dbo.Rehab_VR.TherapyEndDateOptional, 
                      dbo.Rehab_VR.Toilet, dbo.Rehab_VR.ToiletDesc, dbo.Rehab_VR.Toileting, dbo.Rehab_VR.ToiletingDesc, dbo.Rehab_VR.TransferWrittenHealthCondtn1, 
                      dbo.Rehab_VR.TranslTempLivingArrangemnt, dbo.Rehab_VR.TransTempLivingArrangemntDesc, dbo.Rehab_VR.TSIDate, dbo.Rehab_VR.TSITime, 
                      dbo.Rehab_VR.TSICoder, dbo.Rehab_VR.TSICoderDesc, dbo.Rehab_VR.TubShower, dbo.Rehab_VR.TubShowerDesc, dbo.Rehab_VR.Unemployed, 
                      dbo.Rehab_VR.UnemployedDesc, dbo.Rehab_VR.UniversalEpisodeIdentifier,
					  dbo.Rehab_VR.UnpaidEmployAdjustedMod, dbo.Rehab_VR.UnpaidEmployAdjustedModDesc, 
                      dbo.Rehab_VR.UnpaidEmploymentFullTime, dbo.Rehab_VR.UnpaidEmploymentFullTimeDesc, dbo.Rehab_VR.UnpaidEmploymentPartTime, 
                      dbo.Rehab_VR.UnpaidEmploymentPartTimeDesc, dbo.Rehab_VR.VerbalorNonVerbal, dbo.Rehab_VR.VerbalorNonVerbalDesc, dbo.Rehab_VR.VocationalDiscipline, 
                      dbo.Rehab_VR.VocationalDisciplineDesc, dbo.Rehab_VR.VocationalType, dbo.Rehab_VR.VocationalTypeDesc, dbo.Rehab_VR.WalkWheelchair, 
                      dbo.Rehab_VR.WalkWheelchairDesc, dbo.Rehab_VR.WalkWheelchairMode, dbo.Rehab_VR.WalkWheelchairModeDesc, dbo.Rehab_VR.WCBWSIB, 
                      dbo.Rehab_VR.WCBWSIBDesc, dbo.Rehab_VR.Weightoptional, dbo.Rehab_VR.WorkActivity, dbo.Rehab_VR.WorkActivityDesc, dbo.Rehab_VR.WrittenCommunication, 
                      dbo.Rehab_VR.WrittenCommunicationDesc, dbo.Rehab_VR.zzAssessmentLink, dbo.Rehab_Projects_VR.ProjectNumber, dbo.Rehab_Projects_VR.ProjectNumberDesc, 
                      dbo.Rehab_Projects_VR.ProjectOccurrence, dbo.Rehab_Projects_VR.Question1, dbo.Rehab_Projects_VR.Question1Desc, dbo.Rehab_Projects_VR.Question10, 
                      dbo.Rehab_Projects_VR.Question10Desc, dbo.Rehab_Projects_VR.Question11, dbo.Rehab_Projects_VR.Question11Desc, dbo.Rehab_Projects_VR.Question12, 
                      dbo.Rehab_Projects_VR.Question12Desc, dbo.Rehab_Projects_VR.Question13, dbo.Rehab_Projects_VR.Question13Desc, dbo.Rehab_Projects_VR.Question14, 
                      dbo.Rehab_Projects_VR.Question15, dbo.Rehab_Projects_VR.Question16, dbo.Rehab_Projects_VR.Question17, dbo.Rehab_Projects_VR.Question2, 
                      dbo.Rehab_Projects_VR.Question2Desc, dbo.Rehab_Projects_VR.Question3, dbo.Rehab_Projects_VR.Question3Desc, dbo.Rehab_Projects_VR.Question4, 
                      dbo.Rehab_Projects_VR.Question4Desc, dbo.Rehab_Projects_VR.Question5, dbo.Rehab_Projects_VR.Question5Desc, dbo.Rehab_Projects_VR.Question6, 
                      dbo.Rehab_Projects_VR.Question6Desc, dbo.Rehab_Projects_VR.Question7, dbo.Rehab_Projects_VR.Question7Desc, dbo.Rehab_Projects_VR.Question8, 
                      dbo.Rehab_Projects_VR.Question8Desc, dbo.Rehab_Projects_VR.Question9, dbo.Rehab_Projects_VR.Question9Desc, dbo.Rehab_VR.zzRehabLink
FROM         dbo.Rehab_VR LEFT OUTER JOIN
                      dbo.Rehab_Projects_VR ON dbo.Rehab_VR.zzRehabLink = dbo.Rehab_Projects_VR.zzRehabLink


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Rehab_And_Providers_VR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
EXEC dbo.sp_executesql @statement = N'

CREATE VIEW [dbo].[Rehab_And_Providers_VR]
AS
SELECT     dbo.Rehab_VR.AboriginalStatus, dbo.Rehab_VR.AboriginalStatusDesc, dbo.Rehab_VR.AdmissionClass, dbo.Rehab_VR.AdmissionClassDesc, 
                      dbo.Rehab_VR.AdmissionDate, dbo.Rehab_VR.AgeCode, dbo.Rehab_VR.AgeCodeDesc, dbo.Rehab_VR.AgeNumber, dbo.Rehab_VR.ASIAImpairmentScale, 
                      dbo.Rehab_VR.ASIAImpairmentScaleDesc, dbo.Rehab_VR.AssessmentType, dbo.Rehab_VR.AssessmentTypeDesc, dbo.Rehab_VR.AttendingPhysician, 
                      dbo.Rehab_VR.AttendingPhysicianDesc, dbo.Rehab_VR.AuditoryorNonAuditoryComm, dbo.Rehab_VR.AuditoryorNonAuditoryCommDesc, dbo.Rehab_VR.BasicOption1, 
                      dbo.Rehab_VR.BasicOption1Desc, dbo.Rehab_VR.BasicOption2, dbo.Rehab_VR.BasicOption2Desc, dbo.Rehab_VR.BasicOption3, dbo.Rehab_VR.BasicOption3Desc, 
                      dbo.Rehab_VR.BasicOption4, dbo.Rehab_VR.BasicOption4Desc, dbo.Rehab_VR.BasicOption5, dbo.Rehab_VR.BasicOption5Desc, dbo.Rehab_VR.BasicOption6, 
                      dbo.Rehab_VR.BasicOption6Desc, dbo.Rehab_VR.BasicOption7, dbo.Rehab_VR.BasicOption7Desc, dbo.Rehab_VR.BasicOption8, dbo.Rehab_VR.BasicOption8Desc, 
                      dbo.Rehab_VR.BasicOption9, dbo.Rehab_VR.BasicOption9Desc, dbo.Rehab_VR.BasicOption10, dbo.Rehab_VR.BasicOption10Desc, dbo.Rehab_VR.BasicOption11, 
                      dbo.Rehab_VR.BasicOption11Desc, dbo.Rehab_VR.BasicOption12, dbo.Rehab_VR.BasicOption12Desc, dbo.Rehab_VR.BasicOption13, 
                      dbo.Rehab_VR.BasicOption13Desc, dbo.Rehab_VR.BasicOption14, dbo.Rehab_VR.BasicOption14Desc, dbo.Rehab_VR.BasicOption15, 
                      dbo.Rehab_VR.BasicOption15Desc, dbo.Rehab_VR.BasicOption16, dbo.Rehab_VR.BasicOption16Desc, dbo.Rehab_VR.BasicOption17, 
                      dbo.Rehab_VR.BasicOption17Desc, dbo.Rehab_VR.BasicOption18, dbo.Rehab_VR.BasicOption18Desc, dbo.Rehab_VR.BasicOption19, 
                      dbo.Rehab_VR.BasicOption19Desc, dbo.Rehab_VR.BatchPeriod, dbo.Rehab_VR.BatchPeriodDesc, dbo.Rehab_VR.BatchYear, dbo.Rehab_VR.Bathing, 
                      dbo.Rehab_VR.BathingDesc, dbo.Rehab_VR.BedChairWheelchair, dbo.Rehab_VR.BedChairWheelchairDesc, dbo.Rehab_VR.BirthDate, 
                      dbo.Rehab_VR.BladderManagement, dbo.Rehab_VR.BladderManagementDesc, dbo.Rehab_VR.BowelManagement, dbo.Rehab_VR.BowelManagementDesc, 
                      dbo.Rehab_VR.CanadianResidentInsPay, dbo.Rehab_VR.CanadianResidentInsPayDesc, dbo.Rehab_VR.CanadianResidentSelfPay, 
                      dbo.Rehab_VR.CanadianResidentSelfPayDesc, dbo.Rehab_VR.ChartNumber, dbo.Rehab_VR.CoderNumber, dbo.Rehab_VR.CoderNumberDesc, 
                      dbo.Rehab_VR.CognitiveDiscipline, dbo.Rehab_VR.CognitiveDisciplineDesc, dbo.Rehab_VR.CognitiveType, dbo.Rehab_VR.CognitiveTypeDesc, 
                      dbo.Rehab_VR.CommunicationDiscipline, dbo.Rehab_VR.CommunicationDisciplineDesc, dbo.Rehab_VR.CommunicationType, 
                      dbo.Rehab_VR.CommunicationTypeDesc, dbo.Rehab_VR.Comprehension, dbo.Rehab_VR.ComprehensionDesc, dbo.Rehab_VR.ComprehensionMode, 
                      dbo.Rehab_VR.ComprehensionModeDesc, dbo.Rehab_VR.ConsultationDiscipline, dbo.Rehab_VR.ConsultationDisciplineDesc, dbo.Rehab_VR.ConsultationType, 
                      dbo.Rehab_VR.ConsultationTypeDesc, dbo.Rehab_VR.CountryofResidence, dbo.Rehab_VR.CountryofResidenceDesc, dbo.Rehab_VR.DataEntryCoder, 
                      dbo.Rehab_VR.DataEntryCoderDesc, dbo.Rehab_VR.DateofOnset, dbo.Rehab_VR.DateReadyForAdmission, dbo.Rehab_VR.DateReadyForAdmitKnown, 
                      dbo.Rehab_VR.DateReadyForAdmitKnownDesc, dbo.Rehab_VR.DateReadyforDischarge, dbo.Rehab_VR.DateSenttoCIHI, dbo.Rehab_VR.DaysinHospitaltotalnumber, 
                      dbo.Rehab_VR.DealWithLifeEvents, dbo.Rehab_VR.DealWithLifeEventsDesc, dbo.Rehab_VR.DischargeDate, dbo.Rehab_VR.DressingLowerBody, 
                      dbo.Rehab_VR.DressingLowerBodyDesc, dbo.Rehab_VR.DressingUpperBody, dbo.Rehab_VR.DressingUpperBodyDesc, dbo.Rehab_VR.Eating, 
                      dbo.Rehab_VR.EatingDesc, dbo.Rehab_VR.EducationDiscipline, dbo.Rehab_VR.EducationDisciplineDesc, dbo.Rehab_VR.EducationType, 
                      dbo.Rehab_VR.EducationTypeDesc, dbo.Rehab_VR.EncounterNumber, dbo.Rehab_VR.EquipmentDiscipline, dbo.Rehab_VR.EquipmentDisciplineDesc, 
                      dbo.Rehab_VR.EquipmentType, dbo.Rehab_VR.EquipmentTypeDesc, dbo.Rehab_VR.EstimatedBirthdate, dbo.Rehab_VR.EstimatedBirthdateDesc, 
                      dbo.Rehab_VR.Expression, dbo.Rehab_VR.ExpressionDesc, dbo.Rehab_VR.ExpressionMode, dbo.Rehab_VR.ExpressionModeDesc, dbo.Rehab_VR.FacilityIdentifier, 
                      dbo.Rehab_VR.FacilityIdentifierDesc, dbo.Rehab_VR.FamilyRole, dbo.Rehab_VR.FamilyRoleDesc, dbo.Rehab_VR.FederalGovtDVA, 
                      dbo.Rehab_VR.FederalGovtDVADesc, dbo.Rehab_VR.FederalGovtFNIHB, dbo.Rehab_VR.FederalGovtFNIHBDesc, dbo.Rehab_VR.FederalGovtOther, 
                      dbo.Rehab_VR.FederalGovtOtherDesc, dbo.Rehab_VR.FIM, dbo.Rehab_VR.FinancialManagement, dbo.Rehab_VR.FinancialManagementDesc, 
                      dbo.Rehab_VR.FinishDate, dbo.Rehab_VR.FinishTime, dbo.Rehab_VR.FirstName, dbo.Rehab_VR.FixedChartNumber, dbo.Rehab_VR.FollowUpAssessmentDate, 
                      dbo.Rehab_VR.Gender, dbo.Rehab_VR.GenderDesc, dbo.Rehab_VR.GlassesHearingAidFlag, dbo.Rehab_VR.GlassesHearingAidFlagDesc, dbo.Rehab_VR.Grooming, 
                      dbo.Rehab_VR.GroomingDesc, dbo.Rehab_VR.HealthCardNumber, dbo.Rehab_VR.HCNVersion, dbo.Rehab_VR.HeavyHouseworkoptional, 
                      dbo.Rehab_VR.HeavyHouseworkoptionalDesc, dbo.Rehab_VR.Heightoptional, dbo.Rehab_VR.Hospital, dbo.Rehab_VR.HospitalDesc, 
                      dbo.Rehab_VR.HospitalAccountRecord,
                      dbo.Rehab_VR.HospitalizationSinceDisch, dbo.Rehab_VR.HospitalizationSinceDischDesc, dbo.Rehab_VR.ImpactofPainOnActivities, 
                      dbo.Rehab_VR.ImpactofPainOnActivitiesDesc, dbo.Rehab_VR.InformalSupportReceived, dbo.Rehab_VR.InformalSupportReceivedDesc, 
                      dbo.Rehab_VR.InitialDiscipline, dbo.Rehab_VR.InitialDisciplineDesc, dbo.Rehab_VR.InitialType, dbo.Rehab_VR.InitialTypeDesc, dbo.Rehab_VR.InjectionsDiscipline, 
                      dbo.Rehab_VR.InjectionsDisciplineDesc, dbo.Rehab_VR.InjectionsType, dbo.Rehab_VR.InjectionsTypeDesc, dbo.Rehab_VR.InputDate, dbo.Rehab_VR.InputTime, 
                      dbo.Rehab_VR.InterimDate, dbo.Rehab_VR.IntensityofPain, dbo.Rehab_VR.IntensityofPainDesc, dbo.Rehab_VR.InterfaceDate, dbo.Rehab_VR.InterfaceTime, 
                      dbo.Rehab_VR.InterfaceCoder, dbo.Rehab_VR.InterfaceCoderDesc, dbo.Rehab_VR.IsAbstractCompleted, dbo.Rehab_VR.IsAbstractCompletedDesc, 
                      dbo.Rehab_VR.IsAbstractCorrected, dbo.Rehab_VR.IsAbstractCorrectedDesc, dbo.Rehab_VR.IsAbstractDeleted, dbo.Rehab_VR.IsAbstractDeletedDesc, 
                      dbo.Rehab_VR.IsAbstractSubmitted, dbo.Rehab_VR.IsAbstractSubmittedDesc, dbo.Rehab_VR.IsAbstractValidated, dbo.Rehab_VR.IsAbstractValidatedDesc, 
                      dbo.Rehab_VR.LastName, dbo.Rehab_VR.LightHouseworkoptional, dbo.Rehab_VR.LightHouseworkoptionalDesc, dbo.Rehab_VR.LinkID, dbo.Rehab_VR.LivingAlone, 
                      dbo.Rehab_VR.LivingAloneDesc, dbo.Rehab_VR.LivingInAcuteCare, dbo.Rehab_VR.LivingInAcuteCareDesc, dbo.Rehab_VR.LivingInFacilityAllLevels, 
                      dbo.Rehab_VR.LivingInFacilityAllLevelsDesc, dbo.Rehab_VR.[LivingSetting(Pre/Post/FU)], dbo.Rehab_VR.[LivingSettingDesc(Pre/Post/FU)], 
                      dbo.Rehab_VR.LivingwithFamily, dbo.Rehab_VR.LivingwithFamilyDesc, dbo.Rehab_VR.LivingwithNonFamilyUnpaid, dbo.Rehab_VR.LivingwithNonFamilyUnpaidDesc, 
                      dbo.Rehab_VR.LivingwithPaidAttendant, dbo.Rehab_VR.LivingwithPaidAttendantDesc, dbo.Rehab_VR.LivingwithSpousePartner, 
                      dbo.Rehab_VR.LivingwithSpousePartnerDesc, dbo.Rehab_VR.LOSDays, dbo.Rehab_VR.MaidenName, dbo.Rehab_VR.MainWrittenHealthCondition, 
                      dbo.Rehab_VR.ManualTechDiscipline, dbo.Rehab_VR.ManualTechDisciplineDesc, dbo.Rehab_VR.ManualTechniquesType, 
                      dbo.Rehab_VR.ManualTechniquesTypeDesc, dbo.Rehab_VR.MealPreparationoptional, dbo.Rehab_VR.MealPreparationoptionalDesc, dbo.Rehab_VR.Memory, 
                      dbo.Rehab_VR.MemoryDesc, dbo.Rehab_VR.MiddleName, dbo.Rehab_VR.MISCode, dbo.Rehab_VR.MISCodeDesc, dbo.Rehab_VR.MobilityinCommunity, 
                      dbo.Rehab_VR.MobilityinCommunityDesc, dbo.Rehab_VR.MobilityinLivingQuarters, dbo.Rehab_VR.MobilityinLivingQuartersDesc, dbo.Rehab_VR.NameFull, 
                      dbo.Rehab_VR.NextAssessmentDate, dbo.Rehab_VR.NoneoftheAbove, dbo.Rehab_VR.NoneoftheAboveDesc, dbo.Rehab_VR.NursingArea, 
                      dbo.Rehab_VR.NursingAreaDesc, dbo.Rehab_VR.NutritionalDiscipline, dbo.Rehab_VR.NutritionalDisciplineDesc, dbo.Rehab_VR.NutritionalType, 
                      dbo.Rehab_VR.NutritionalTypeDesc, dbo.Rehab_VR.Orientation, dbo.Rehab_VR.OrientationDesc, dbo.Rehab_VR.OtherCountrySelfPay, 
                      dbo.Rehab_VR.OtherCountrySelfPayDesc, dbo.Rehab_VR.OtherLivingArrangements, dbo.Rehab_VR.OtherLivingArrangementsDesc, 
                      dbo.Rehab_VR.OtherProvTerritoryResidant, dbo.Rehab_VR.OtherProvTerritoryResidantDesc, dbo.Rehab_VR.OutofTownTrips, dbo.Rehab_VR.OutofTownTripsDesc, 
                      dbo.Rehab_VR.PaidEmployAdjustedMod, dbo.Rehab_VR.PaidEmployAdjustedModDesc, dbo.Rehab_VR.PaidEmploymentFullTime, 
                      dbo.Rehab_VR.PaidEmploymentFullTimeDesc, dbo.Rehab_VR.PaidEmploymentPartTime, dbo.Rehab_VR.PaidEmploymentPartTimeDesc, 
                      dbo.Rehab_VR.PersonalComfortwithOthers, dbo.Rehab_VR.PersonalComfortwithOthersDesc, dbo.Rehab_VR.PersonalRelationships, 
                      dbo.Rehab_VR.PersonalRelationshipsDesc, dbo.Rehab_VR.PhysicalDiscipline, dbo.Rehab_VR.PhysicalDisciplineDesc, dbo.Rehab_VR.PhysicalModalitiesDiscipline, 
                      dbo.Rehab_VR.PhysicalModalitiesDiscDesc, dbo.Rehab_VR.PhysicalModalitiesType, dbo.Rehab_VR.PhysicalModalitiesTypeDesc, dbo.Rehab_VR.PhysicalType, 
                      dbo.Rehab_VR.PhysicalTypeDesc, dbo.Rehab_VR.PlannedReAdmission, dbo.Rehab_VR.PlannedReAdmissionDesc, dbo.Rehab_VR.PostalCode, 
                      dbo.Rehab_VR.PostalCodeDesc, dbo.Rehab_VR.PrePostAdmitWrittenHCond1, dbo.Rehab_VR.PrePostAdmitWrittenHCond2, 
                      dbo.Rehab_VR.PrePostAdmitWrittenHCond3, dbo.Rehab_VR.PreHospitalLivingSetting, dbo.Rehab_VR.PreHospitalLivingSettingDesc, 
                      dbo.Rehab_VR.PresenceofCognitiveImpair, dbo.Rehab_VR.PresenceofCognitiveImpairDesc, dbo.Rehab_VR.PresenceofPain, dbo.Rehab_VR.PresenceofPainDesc, 
                      dbo.Rehab_VR.PrimaryLanguage, dbo.Rehab_VR.PrimaryLanguageDesc, dbo.Rehab_VR.PrimaryLanguageISO, dbo.Rehab_VR.PrimaryLanguageISODesc, 
                      dbo.Rehab_VR.PrimaryReasonWaitingDischarge, dbo.Rehab_VR.PrimaryReasonWaitingDischargeDesc, dbo.Rehab_VR.ProblemSolving, 
                      dbo.Rehab_VR.ProblemSolvingDesc, dbo.Rehab_VR.ProgramType, dbo.Rehab_VR.ProgramTypeDesc, dbo.Rehab_VR.ProvinceIssuingHCN, 
                      dbo.Rehab_VR.ProvinceIssuingHCNDesc, dbo.Rehab_VR.ProvinceofResidence, dbo.Rehab_VR.ProvinceofResidenceDesc, dbo.Rehab_VR.ProvinceTerritorialPlan, 
                      dbo.Rehab_VR.ProvinceTerritorialPlanDesc, dbo.Rehab_VR.ProvincialDefinition, dbo.Rehab_VR.ProvincialDefinitionDesc, dbo.Rehab_VR.PsychoSocialDiscipline, 
                      dbo.Rehab_VR.PsychoSocialDisciplineDesc, dbo.Rehab_VR.PsychoSocialType, dbo.Rehab_VR.PsychoSocialTypeDesc, dbo.Rehab_VR.ReadingCommunication, 
                      dbo.Rehab_VR.ReadingCommunicationDesc, dbo.Rehab_VR.ReAdmit1MonthSinceDisch, dbo.Rehab_VR.ReAdmit1MonthSinceDischDesc, 
                      dbo.Rehab_VR.ReasonforDischarge, dbo.Rehab_VR.ReasonforDischargeDesc, dbo.Rehab_VR.ReassessmentDiscipline, 
                      dbo.Rehab_VR.ReassessmentDisciplineDesc, dbo.Rehab_VR.ReassessmentType, dbo.Rehab_VR.ReassessmentTypeDesc, dbo.Rehab_VR.RecreationalActivities, 
                      dbo.Rehab_VR.RecreationalActivitiesDesc, dbo.Rehab_VR.ReferralSource, dbo.Rehab_VR.ReferralSourceDesc, dbo.Rehab_VR.ReferralSourceFacilityNum, 
                      dbo.Rehab_VR.ReferralSourceFacilityNumDesc, dbo.Rehab_VR.ReferralSourceProvTerritory, dbo.Rehab_VR.ReferralSourceProvTerrDesc, dbo.Rehab_VR.ReferredTo, 
                      dbo.Rehab_VR.ReferredToDesc, dbo.Rehab_VR.ReferredToFacilityNumber, dbo.Rehab_VR.ReferredToFacilityNumberDesc, dbo.Rehab_VR.ReferredToProvTerr, 
                      dbo.Rehab_VR.ReferredToProvTerrDesc, dbo.Rehab_VR.ReferringProvider, dbo.Rehab_VR.ReferringProviderDesc, dbo.Rehab_VR.RegisterNumber, 
                      dbo.Rehab_VR.RehabilitationClientGroup, dbo.Rehab_VR.RehabilitationClientGroupDesc, dbo.Rehab_VR.Respondent, dbo.Rehab_VR.RespondentDesc, 
                      dbo.Rehab_VR.RespondentType, dbo.Rehab_VR.RespondentTypeDesc, dbo.Rehab_VR.ResidenceCode, dbo.Rehab_VR.ResidenceCodeDesc, 
                      dbo.Rehab_VR.RetiredforAge, dbo.Rehab_VR.RetiredforAgeDesc, dbo.Rehab_VR.RetiredforDisability, dbo.Rehab_VR.RetiredforDisabilityDesc, 
                      dbo.Rehab_VR.SecondChartRegisterNumber, dbo.Rehab_VR.SecondaryReasonWaitingDischarge, dbo.Rehab_VR.SecondaryReasonWaitingDischargeDesc, 
                      dbo.Rehab_VR.ScreeningDiscipline, dbo.Rehab_VR.ScreeningDisciplineDesc, dbo.Rehab_VR.ScreeningType, dbo.Rehab_VR.ScreeningTypeDesc, 
                      dbo.Rehab_VR.Secret, dbo.Rehab_VR.SecretDesc, dbo.Rehab_VR.SelfCareNeeds, dbo.Rehab_VR.SelfCareNeedsDesc, dbo.Rehab_VR.ServicePlanningDiscipline, 
                      dbo.Rehab_VR.ServicePlanningDisciplineDesc, dbo.Rehab_VR.ServicePlanningType, dbo.Rehab_VR.ServicePlanningTypeDesc, dbo.Rehab_VR.SiteNumber, 
                      dbo.Rehab_VR.SiteNumberDesc, dbo.Rehab_VR.SocialActivities, dbo.Rehab_VR.SocialActivitiesDesc, dbo.Rehab_VR.SocialInteraction, 
                      dbo.Rehab_VR.SocialInteractionDesc, dbo.Rehab_VR.SocialParticDiscipline, dbo.Rehab_VR.SocialParticDisciplineDesc, dbo.Rehab_VR.SocialParticipationType, 
                      dbo.Rehab_VR.SocialParticipationTypeDesc, dbo.Rehab_VR.Stairs, dbo.Rehab_VR.StairsDesc, dbo.Rehab_VR.Status, dbo.Rehab_VR.StatusDesc, 
                      dbo.Rehab_VR.StudentAdjustedModified, dbo.Rehab_VR.StudentAdjustedModifiedDesc, dbo.Rehab_VR.StudentFullTime, dbo.Rehab_VR.StudentFullTimeDesc, 
                      dbo.Rehab_VR.StudentPartTime, dbo.Rehab_VR.StudentPartTimeDesc, dbo.Rehab_VR.TherapyStartDateOptional, dbo.Rehab_VR.TherapyEndDateOptional, 
                      dbo.Rehab_VR.Toilet, dbo.Rehab_VR.ToiletDesc, dbo.Rehab_VR.Toileting, dbo.Rehab_VR.ToiletingDesc, dbo.Rehab_VR.TransferWrittenHealthCondtn1, 
                      dbo.Rehab_VR.TranslTempLivingArrangemnt, dbo.Rehab_VR.TransTempLivingArrangemntDesc, dbo.Rehab_VR.TSIDate, dbo.Rehab_VR.TSITime, 
                      dbo.Rehab_VR.TSICoder, dbo.Rehab_VR.TSICoderDesc, dbo.Rehab_VR.TubShower, dbo.Rehab_VR.TubShowerDesc, dbo.Rehab_VR.Unemployed, 
                      dbo.Rehab_VR.UnemployedDesc, dbo.Rehab_VR.UniversalEpisodeIdentifier,
					  dbo.Rehab_VR.UnpaidEmployAdjustedMod, dbo.Rehab_VR.UnpaidEmployAdjustedModDesc, 
                      dbo.Rehab_VR.UnpaidEmploymentFullTime, dbo.Rehab_VR.UnpaidEmploymentFullTimeDesc, dbo.Rehab_VR.UnpaidEmploymentPartTime, 
                      dbo.Rehab_VR.UnpaidEmploymentPartTimeDesc, dbo.Rehab_VR.VerbalorNonVerbal, dbo.Rehab_VR.VerbalorNonVerbalDesc, dbo.Rehab_VR.VocationalDiscipline, 
                      dbo.Rehab_VR.VocationalDisciplineDesc, dbo.Rehab_VR.VocationalType, dbo.Rehab_VR.VocationalTypeDesc, dbo.Rehab_VR.WalkWheelchair, 
                      dbo.Rehab_VR.WalkWheelchairDesc, dbo.Rehab_VR.WalkWheelchairMode, dbo.Rehab_VR.WalkWheelchairModeDesc, dbo.Rehab_VR.WCBWSIB, 
                      dbo.Rehab_VR.WCBWSIBDesc, dbo.Rehab_VR.Weightoptional, dbo.Rehab_VR.WorkActivity, dbo.Rehab_VR.WorkActivityDesc, dbo.Rehab_VR.WrittenCommunication, 
                      dbo.Rehab_VR.WrittenCommunicationDesc, dbo.Rehab_Providers_VR.ProviderNumber, dbo.Rehab_Providers_VR.ProviderNumberDesc, 
                      dbo.Rehab_Providers_VR.ProviderOccurrenceNumber, dbo.Rehab_Providers_VR.ProviderType, dbo.Rehab_Providers_VR.ProviderTypeDesc, 
                      dbo.Rehab_VR.zzAssessmentLink, dbo.Rehab_VR.zzRehabLink
FROM         dbo.Rehab_VR LEFT OUTER JOIN
                      dbo.Rehab_Providers_VR ON dbo.Rehab_VR.zzRehabLink = dbo.Rehab_Providers_VR.zzRehabLink


' 
GO


--------------Final Set Permission -----------------------------------------------------
exec dbo.M_SetViewPermission	--EN - 00399 Run for every DB upgrade
GO
