|
| 1 | + |
| 2 | +CREATE TABLE onprc_ehr.Rpt_TempProblemList( |
| 3 | + searchid integer IDENTITY(100,1) NOT NULL, |
| 4 | + animalid varchar(200) NULL, |
| 5 | + date smalldatetime NULL, |
| 6 | + objectid varchar(4000) NULL, |
| 7 | + caseid varchar(4000) NULL |
| 8 | + |
| 9 | + ) ON [PRIMARY] |
| 10 | + GO |
| 11 | + |
| 12 | +CREATE TABLE onprc_ehr.Rpt_TempProblemListMaster( |
| 13 | + searchid integer IDENTITY(100,1) NOT NULL, |
| 14 | + animalid varchar(200) NULL, |
| 15 | + date smalldatetime NULL, |
| 16 | + objectid varchar(4000) NULL, |
| 17 | + caseid varchar(4000) NULL |
| 18 | + |
| 19 | +) ON [PRIMARY] |
| 20 | + GO |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +/* |
| 26 | +** |
| 27 | +** Created by Date Comment |
| 28 | +** |
| 29 | +** blasa 7-7-2026 Process to update historical problem list records |
| 30 | +** |
| 31 | +** |
| 32 | +** |
| 33 | +**/ |
| 34 | + |
| 35 | +CREATE Procedure onprc_ehr.s_MasterProblemHistoricalProcess |
| 36 | + |
| 37 | + |
| 38 | +AS |
| 39 | + |
| 40 | + |
| 41 | +declare |
| 42 | + |
| 43 | + |
| 44 | + @TempSearchKey Int, |
| 45 | + @Searchkey Int, |
| 46 | + @AnimalID varchar(100), |
| 47 | + @date smalldatetime, |
| 48 | + @objectid varchar(4000), |
| 49 | + @caseid varchar(4000) |
| 50 | + |
| 51 | + |
| 52 | +Begin |
| 53 | + |
| 54 | + |
| 55 | + ----- Reset the last two months only |
| 56 | + |
| 57 | + Delete onprc_ehr.Rpt_TempProblemList |
| 58 | + |
| 59 | + If @@Error <> 0 |
| 60 | + GoTo Err_Proc |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | + Set @Tempsearchkey = 0 |
| 65 | + Set @Searchkey = 0 |
| 66 | + Set @Animalid = '' |
| 67 | + Set @date = null |
| 68 | + Set @objectid = null |
| 69 | + Set @caseid = null |
| 70 | + |
| 71 | + --- Set initial processing |
| 72 | + |
| 73 | + Insert into onprc_ehr.Rpt_TempProblemList |
| 74 | + select participantid, |
| 75 | + date, |
| 76 | + objectid, |
| 77 | + caseid |
| 78 | + from studydataset.c6d200_problem |
| 79 | + Where category = 'Wound' |
| 80 | + And subcategory = 'Digit Amputation' |
| 81 | + And qcstate = 18 |
| 82 | + |
| 83 | + Order by participantid |
| 84 | + |
| 85 | + Select top 1 @SearchKey = searchID from onprc_ehr.Rpt_TempProblemList |
| 86 | + Order by searchid |
| 87 | + |
| 88 | + |
| 89 | + While @Tempsearchkey < @SearchKey |
| 90 | + Begin |
| 91 | + |
| 92 | + Set @Animalid = '' |
| 93 | + Set @date = null |
| 94 | + Set @objectid = null |
| 95 | + |
| 96 | + select @animalid = animalid, @Date = date, @Objectid = objectid |
| 97 | + from Rpt_TempProblemList Where searchid = @Searchkey |
| 98 | + |
| 99 | + -------Begin updating records |
| 100 | + |
| 101 | + |
| 102 | + Update pb |
| 103 | + Set pb.subcategory = 'Digit Removal/Caudectomy' |
| 104 | + From studydataset.c6d200_problem pb |
| 105 | + Where pb.Participantid = @Animalid |
| 106 | + And pb.objectid = @objectid |
| 107 | + |
| 108 | + |
| 109 | + If @@Error <> 0 |
| 110 | + GoTo Err_Proc |
| 111 | + |
| 112 | + |
| 113 | + Set @TempSearchkey = @Searchkey |
| 114 | + |
| 115 | + Select Top 1 @SearchKey = searchid From onprc_ehr.Rpt_TempProblemList |
| 116 | + Where searchid > @Tempsearchkey |
| 117 | + Order by searchid |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + End ------(While @tempsearchkey < @Searchkey) |
| 123 | + |
| 124 | + ---- Create an audit record of these entries |
| 125 | + |
| 126 | + insert into onprc_ehr.Rpt_TempProblemListMaster |
| 127 | + Select animalid, date, objectid, caseid |
| 128 | + from onprc_ehr.Rpt_TempProblemList |
| 129 | + |
| 130 | + |
| 131 | + Return 0 |
| 132 | + |
| 133 | + Err_Proc: Return 1 |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | +END |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | + |
0 commit comments