Produced by Araxis Merge on 6/22/2018 9:28:21 AM Eastern Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | REFDOC_2.3_06072018.zip\REFDOC 2.3_06072018\NVCC\SQL | usp_PMUpdateMasterLabIndexFromLOINC.sql | Thu Jun 7 16:53:38 2018 UTC |
| 2 | REFDOC_2.3_06072018.zip\REFDOC 2.3_06072018\NVCC\SQL | usp_PMUpdateMasterLabIndexFromLOINC.sql | Fri Jun 22 12:53:19 2018 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 482 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | USE [NWIC_ PanelMgmt] | |
| 2 | GO | |
| 3 | ||
| 4 | SET ANSI_N ULLS ON | |
| 5 | GO | |
| 6 | ||
| 7 | SET QUOTED _IDENTIFIE R ON | |
| 8 | GO | |
| 9 | ||
| 10 | ALTER PROC EDURE [Pan elMgmt].[u sp_PMUpdat eMasterLab IndexFromL OINC] | |
| 11 | AS | |
| 12 | --======== ========== ========== ========== ========== ========== ========== ========== === | |
| 13 | --Requesto r : Jianji Y ang | |
| 14 | --Author : Jerr y Kohler ( Original s cript by S teve Schre iner) | |
| 15 | --Object/S P Name : [Panel Mgmt].[usp _PMUpdateM asterLabIn dexfromLOI NC] | |
| 16 | --SERVER :
|
|
| 17 | --Data Bas e : NWIC_Pan elMgmt | |
| 18 | --Schema : PanelMgm t | |
| 19 | --Report : None Yet | |
| 20 | --Folder : | |
| 21 | --Report L oc : | |
| 22 | --Job : None | |
| 23 | --Job Loc : None | |
| 24 | --Note : | |
| 25 | --Date Cre ated : 12-2 8-2015 | |
| 26 | --Last Cha nged : | |
| 27 | --Last Cha nged By : | |
| 28 | --Reason F or Change : | |
| 29 | --Purpose : Upda te Panel M anagement Master Lab Index tab le | |
| 30 | -- with lab test that have valid LOIN C codes. This is do ne | |
| 31 | -- thro ugh the BI SL's incre mental upd ate method in the fi rst | |
| 32 | -- sect ion. This is done t o decrease the proce ssing time | |
| 33 | -- and conserve s erver reso urces. | |
| 34 | --======== ========== ========== ========== ========== ========== ========== ========== === | |
| 35 | SET NOCOUN T on | |
| 36 | ||
| 37 | BEGIN | |
| 38 | /* | |
| 39 | Locate and load the outsta nding Chem .LabChem b atches sin ce the | |
| 40 | last e xecution r ather than processin g the enti re Chem.La bChem view . | |
| 41 | */ | |
| 42 | ||
| 43 | -- declare ba tch variab les and cu rsor | |
| 44 | DE CLARE @ETL BatchID AS INT, @E xtractBatc hID AS INT ; | |
| 45 | DE CLARE @DWV iewSchema AS VARCHAR (50) = 'Ch em'; | |
| 46 | DE CLARE @DWV iewName AS VARCHAR (50) = 'La bChem'; | |
| 47 | ||
| 48 | ||
| 49 | DECLAR E BatchCur sor CURSOR STATIC FO R | |
| 50 | -- get batch ids | |
| 51 | SELECT EX .ETLBatchI D, EX.Extr actBatchID | |
| 52 | FROM SPV. EB.Extract Batch AS E X | |
| 53 | INNER JOI N Dflt.Ext ractBatchL og AS EL | |
| 54 | ON EX .DWViewSch ema = EL.D WViewSchem a AND EX.D WViewName = EL.DWVie wName | |
| 55 | WHERE EX. DWViewSche ma = @DWVi ewSchema | |
| 56 | A ND EX.DWVi ewname = @DWViewNa me | |
| 57 | A ND EX.Extr actBatchID > EL.Last ExtractBat chID | |
| 58 | ORDER BY EX.Extract BatchID; | |
| 59 | ||
| 60 | OP EN BatchCu rsor; | |
| 61 | FE TCH NEXT F ROM BatchC ursor INTO @ETLBatch ID, @Extra ctBatchID; | |
| 62 | ||
| 63 | WH ILE @@FETC H_STATUS = 0 | |
| 64 | BE GIN | |
| 65 | ||
| 66 | IF (SELECT O BJECT_ID(' tempdb..#L abChemPrep ')) IS NOT NULL | |
| 67 | DR OP TABLE # LabChemPre p | |
| 68 | ||
| 69 | -- t he lab res ults load table has duplicate records, w hich the | |
| 70 | -- MERGE sta tement wil l not tole rate. Try and get t he latest | |
| 71 | -- record fo r each Lab ChemTestSI D in the b atch by so rting on | |
| 72 | -- specimen date time descending within th at LabChem TestSID | |
| 73 | SELE CT [Sta3n] | |
| 74 | ,[LabC hemTestSID ] | |
| 75 | ,[LOIN CSID] | |
| 76 | ,[LabC hemSpecime nDateTime] | |
| 77 | ,[LabC hemComplet eDateTime] | |
| 78 | ,[ETLB atchID] | |
| 79 | ,[OpCo de] | |
| 80 | ,[Vist aCreateDat e] | |
| 81 | ,[Vist aEditDate] | |
| 82 | ,row_n umber() ov er (Partit ion by Lab ChemTestSI D | |
| 83 | or der by Lab ChemTestSI D, LabChem SpecimenDa teTime DES C) AS RN | |
| 84 | IN TO #LabChe mPrep | |
| 85 | FROM SPV.Chem. LabChem | |
| 86 | WHER E ETLBatch ID = @ETLB atchID | |
| 87 | ||
| 88 | -- m erge data into produ ction(dest ination) t able | |
| 89 | MERG E | |
| 90 | ETL.Pr odLabChem AS D | |
| 91 | USIN G | |
| 92 | ( | |
| 93 | SELECT [ Sta3n] | |
| 94 | ,[LabChe mTestSID] | |
| 95 | ,[LOINCS ID] | |
| 96 | ,[LabChe mSpecimenD ateTime] | |
| 97 | ,[LabChe mCompleteD ateTime] | |
| 98 | ,[ETLBat chID] | |
| 99 | ,[OpCode ] | |
| 100 | ,[VistaC reateDate] | |
| 101 | ,[VistaE ditDate] | |
| 102 | ,RN | |
| 103 | FROM #La bChemPrep | |
| 104 | WHERE ET LBatchID = @ETLBatch ID | |
| 105 | AN D RN = 1 - - the late st record for a give n LabChemT estSID | |
| 106 | ) AS M | |
| 107 | ON | |
| 108 | D.LabC hemTestSID = M.LabCh emTestSID | |
| 109 | WHEN NOT MATCH ED THEN | |
| 110 | INSERT | |
| 111 | ( | |
| 112 | [Sta3n] | |
| 113 | ,[LabChe mTestSID] | |
| 114 | ,[LOINCS ID] | |
| 115 | ,[LabChe mSpecimenD ateTime] | |
| 116 | ,[LabChe mCompleteD ateTime] | |
| 117 | ,[ETLBat chID] | |
| 118 | ,[OpCode ] | |
| 119 | ,[VistaC reateDate] | |
| 120 | ,[VistaE ditDate] | |
| 121 | ) | |
| 122 | VALUES | |
| 123 | ( | |
| 124 | M.[Sta3n] | |
| 125 | ,M.[LabChe mTestSID] | |
| 126 | ,M.[LOINCS ID] | |
| 127 | ,M.[LabChe mSpecimenD ateTime] | |
| 128 | ,M.[LabChe mCompleteD ateTime] | |
| 129 | ,M.[ETLBat chID] | |
| 130 | ,M.[OpCode ] | |
| 131 | ,M.[VistaC reateDate] | |
| 132 | ,M.[VistaE ditDate] | |
| 133 | ||
| 134 | ) | |
| 135 | WHEN MATCHED T HEN | |
| 136 | UPDATE SET | |
| 137 | [Sta3n] = M.[Sta3n] | |
| 138 | ,[LabChe mTestSID] = M.[LabChe mTestSID] | |
| 139 | ,[LOINCS ID] = M.[LOINCS ID] | |
| 140 | ,[LabChe mSpecimenD ateTime] = M.[LabChe mSpecimenD ateTime] | |
| 141 | ,[LabChe mCompleteD ateTime] = M.[LabChe mCompleteD ateTime] | |
| 142 | ,[ETLBat chID] = M.[ETLBat chID] | |
| 143 | ,[OpCode ] = M.[OpCode ] | |
| 144 | ,[VistaC reateDate] = M.[VistaC reateDate] | |
| 145 | ,[VistaE ditDate] = M.[VistaE ditDate] | |
| 146 | ; | |
| 147 | ||
| 148 | -- a fter mergi ng batch t hen update the Extra ctBatchLog table | |
| 149 | UPDA TE Dflt.Ex tractBatch Log | |
| 150 | S ET LastExt ractBatchI D = @Extra ctBatchID, LastExtra ctDateTime = GETDATE () | |
| 151 | W HERE DWVie wSchema = @DWViewSch ema | |
| 152 | AND DWVie wName = @DWViewNam e; | |
| 153 | ||
| 154 | -- g rab the ne xt batch f or process ing | |
| 155 | FETC H NEXT FRO M BatchCur sor INTO @ ETLBatchID , @Extract BatchID; | |
| 156 | EN D | |
| 157 | ||
| 158 | -- close and deallocat e the curs or once al l batches for a give n table ha ve been pr ocessed | |
| 159 | CL OSE BatchC ursor; | |
| 160 | DE ALLOCATE B atchCursor ; | |
| 161 | ||
| 162 | -- | |
| 163 | -- | |
| 164 | -- | |
| 165 | -- Using the increm entally up dated ETL. ProdLabChe m rather t han the fu ll | |
| 166 | -- CDWWor k.Dim.Labc hem view, insert new lab tests into [Pan elMgmt].[P MMasterLab Index] | |
| 167 | -- | |
| 168 | -- | |
| 169 | -- | |
| 170 | -- all LOINC SIDS for all s tations de fined in P MMasterCoh ortSite | |
| 171 | IF (SEL ECT OBJECT _ID('tempd b..#TempLO INCSID')) IS NOT NUL L | |
| 172 | DROP TA BLE #TempL OINCSID | |
| 173 | ||
| 174 | select li.LOINCSI D | |
| 175 | ,li.Sta3n | |
| 176 | ,lc.LOINC | |
| 177 | ,lc.TestGr oup | |
| 178 | ,lc.Result ForTestNum eric | |
| 179 | ,dateadd(y y,lc.YearS earchCrite ria,getdat e()) as Ye arSearchDa te | |
| 180 | into #T empLOINCSI D | |
| 181 | from [P anelMgmt]. [PMMasterC ohortLabTe stGroupsLO INCCodes] as lc | |
| 182 | inner j oin [CDWWo rk].[dim]. [LOINC] as li on lc. LOINC = li .LOINC | |
| 183 | inner j oin [Panel Mgmt].[PMM asterCohor tSite] as cs on li.S ta3n = cs. Sta3n; | |
| 184 | ||
| 185 | ||
| 186 | -- base d on LOINC codes, ar e there an y new lab tests we d o NOT | |
| 187 | -- alre ady have i n PMMaster LabIndex? | |
| 188 | IF (SEL ECT OBJECT _ID('tempd b..#Insert TheseRecor ds')) IS N OT NULL | |
| 189 | DROP TA BLE #Inser tTheseReco rds | |
| 190 | ||
| 191 | select distinct l i.LabChemT estSID | |
| 192 | ,li.St a3n | |
| 193 | ,li.La bChemTestN ame | |
| 194 | ,tl.Re sultForTes tNumeric | |
| 195 | ,getda te() as Da teExtracte d | |
| 196 | ,tl.Te stGroup | |
| 197 | ,tl.LO INC | |
| 198 | ,NULL as Workloa dCode | |
| 199 | into #Ins ertTheseRe cords | |
| 200 | from [NWIC_ PanelMgmt] .[ETL].Pro dLabChem l c | |
| 201 | inner j oin [CDW Work].[Dim ].[LabChem Test] as l i on lc.La bChemTestS ID = li.La bChemTestS ID | |
| 202 | inner j oin #Tem pLOINCSID tl on lc.S ta3n = li. Sta3n AND lc.LabChem CompleteDa teTime > t l.YearSear chDate | |
| 203 | where lc.L OINCSID = tl.LOINCSI D | |
| 204 | and not exists (se lect ni.La bChemTestS ID | |
| 205 | from [PanelMgm t].[PMMast erLabIndex ] as ni | |
| 206 | where l i.LabChemT estSID = n i.LabChemT estSID | |
| 207 | a nd li.Sta3 n = ni.Sta 3n); | |
| 208 | ||
| 209 | Insert into [Pane lMgmt].[PM MasterLabI ndex] | |
| 210 | ( | |
| 211 | LabC hemTestSID , | |
| 212 | Sta3 n, | |
| 213 | LabC hemTestNam e, | |
| 214 | Resu ltForTestN umeric, | |
| 215 | Date Extracted, | |
| 216 | Test Group, | |
| 217 | LOIN C, | |
| 218 | Work LoadCode | |
| 219 | ) | |
| 220 | Select LabChemTes tSID, | |
| 221 | Sta3n, | |
| 222 | LabChemTes tName, | |
| 223 | ResultForT estNumeric , | |
| 224 | DateExtrac ted, | |
| 225 | TestGroup, | |
| 226 | LOINC, | |
| 227 | WorkLoadCo de | |
| 228 | From # InsertThes eRecords | |
| 229 | ||
| 230 | Drop ta ble #Inser tTheseReco rds | |
| 231 | --select t op 1000 * from #Inse rtTheseRec ords | |
| 232 | --select * from #Ins ertTheseRe cords wher e LabChemT estSID in (select La bChemTestS ID from [P anelMgmt]. [PMMasterL abIndex]) | |
| 233 | --select d istinct da teextracte d from #In sertTheseR ecords | |
| 234 | --select c ount(*) fr om #Insert TheseRecor ds | |
| 235 | --select a .*, b.* fr om #Insert TheseRecor ds a join cdwwork.di m.labchemt est b on b .LabChemTe stSID = a. LabChemTes tSID | |
| 236 | --select a .* from #I nsertThese Records a join cdwwo rk.dim.lab chemtest b on b.LabC hemTestSID = a.LabCh emTestSID where b.St a3n != a.S ta3n | |
| 237 | ||
| 238 | UPDATE [PanelMgmt ].[PMMaste rCohortLab TestGroups LOINCCodes ] | |
| 239 | set LastUpdate = cast(ge tdate() as date); | |
| 240 | ||
| 241 | END | |
| 242 |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.