|
| 1 | + |
| 2 | + |
| 3 | +TRUNCATE TABLE [Database1].dbo.Example |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +INSERT INTO Scorecard.[dbo].Example |
| 9 | +SELECT DISTINCT Masterkey |
| 10 | +FROM [AggregateDatabase1].dbo.[Example_Table] |
| 11 | +WHERE IDOrganization = 279 |
| 12 | +AND Masterkey LIKE '292%' |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +-- Getting patients first, last, and DOB |
| 19 | + |
| 20 | + |
| 21 | +UPDATE Example |
| 22 | +SET [Patient's First Name] = Pers..PsnFirst, [Patient's Late Name] = Pers.PsnLaSt, [Patient's Date of Birth] = Pers.Psnous, [Client Name] = Pers.PcPPracticeName |
| 23 | +FROM [AggregateDatabase1].dbo.[Example_Table] Pers |
| 24 | +JOIN Scorecard.Example samp |
| 25 | +ON Pers.MasterKey = samp.MRN |
| 26 | +WHERE Pers.IDOrganization = Pers.IDMasterOrganization |
| 27 | +AND Pers.Idstatus = 1 |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +-- getting most recent phone number |
| 33 | + |
| 34 | +UPDATE Example |
| 35 | +SET [Patient's Phone Number] = replace(replace(replace(replace(replace(replace(replace(replace(LTRIM(RTRIM(A.Phone)),'-',''),'(',''),')',''), ' ' ,''), '/' ,''),'x',''),'*',''),'calls','') |
| 36 | +FROM ( |
| 37 | + |
| 38 | +SELECT Phone [MasterKey],Phone.Phone,Phone.DateUpdated, ROW_NUMBER() OVER (PARTITION BY Phone.MasterKey ORDER BY Phone.DateUpdated DESC) RN |
| 39 | +FROM [AggregateDatabase1].dbo.[Phone_Table] Phone |
| 40 | + INNER JOIN Scorecard.Example samp |
| 41 | +ON Phone.Masterkey = samp.MRN |
| 42 | +WHERE PhoneType in ('CELL','HOME') |
| 43 | +and ISNULL ([Phone],'') <> '' |
| 44 | +and phone not like '%[a-z]%' |
| 45 | +and replace(replace(replace(replace(replace(replace(replace(replace(LTRIM(RTRIM(Phone.Phone)),'-',''),'(',''),')',''), ' ' ,''), '/' ,''),'x',''),'*',''),'calls','') NOT LIKE 'e%' |
| 46 | +and lenreplace(replace(replace(replace(replace(replace(replace(replace(LTRIM(RTRIM(Phone.Phone)),'-',''),'(',''),')',''), ' ' ,''), '/' ,''),'x',''),'*',''),'calls','') = 10 |
| 47 | +) A |
| 48 | + |
| 49 | +join [AggregateDatabase1].dbo.[Person_Table] j on a.MasterKey = j.MasterKey |
| 50 | +join [AggregateDatabase1].dbo.[Master_Patient_Index_Table] d on j.IDOrganization = d.IDOrganization END J.IDPerson = d.IDPerson |
| 51 | +INNER JOIN Scorecard.dbo.example Outp |
| 52 | +ON A.MasterKey = OutP.MRN |
| 53 | +WHERE RN = 1 |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | +-- formats phone number |
| 60 | + |
| 61 | +UPDATE Example |
| 62 | +SET [Patient's Phone Number] = SUBSTRING([Patient's Phone Number], 1, 3) + '-' + |
| 63 | + SUBSTRING{[Patient's Phone Number], 4, 3) + '-' + |
| 64 | + SUBSTRING([Patient's Phone Number], 7, 4) |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | +SELECT r.ProtCode |
| 81 | + ,SUM(CASE WHEN R.Recommendation LIKE '%current' THEN 1 |
| 82 | + ELSE 0 |
| 83 | + END) [Met] --Numerator |
| 84 | + ,SUM(CASE WHEN R.Recommendation LIKE '%invalid' THEN 1 |
| 85 | + ELSE 0 |
| 86 | + END) [Not Met] |
| 87 | + ,SUM(CASE WHEN R.Recommendation LIKE '%incl' THEN 1 |
| 88 | + ELSE 0 |
| 89 | + END) [Denominator] |
| 90 | + ,SUM(CASE WHEN R.Recommendation LIKE '%excl' THEN 1 |
| 91 | + ELSE 0 |
| 92 | + END) [Exclusion] |
| 93 | + ,SUM(CASE WHEN R.Recommendation LIKE '%exception' THEN 1 |
| 94 | + ELSE 0 |
| 95 | + END) [Exception] |
| 96 | + , |
| 97 | + CONVERT(Decimal(20,1), |
| 98 | + (CONVERT{Decimal(20,1), SUM(CASE WHEN R.Recommendation LIKE '%current' THEN 1 ELSE 0 END)*100) ) |
| 99 | + / |
| 100 | +(SUM(CASE WHEN (R.Recommendation LIKE '%incl' THEN 1 ELSE 0 END)-SUM(CASE WHEN R.Recommendation LIKE '%exception' THEN 1 ELSE 0 END) ) |
| 101 | +) [Performance Rate %] |
| 102 | + |
| 103 | + |
| 104 | +FROM [Example],[dbo].(Recommendations) r WITH(NOLOCK) |
| 105 | + |
| 106 | + WHERE (R.Recommendation LIKE '%current' |
| 107 | + OR R.Recommendation LIKE '%Excl' |
| 108 | + OR R.Recommendation LIKE '%Incl' |
| 109 | + OR R.Recommendation LIKE '%Invalid' |
| 110 | + OR R.Recommendation LIKE '%Exception') |
| 111 | +GROUP BY r.ProtCode |
| 112 | +ORDER BY 1 |
0 commit comments