From 0762a269ba4116613549b30542ca4db688ae4aae Mon Sep 17 00:00:00 2001 From: kollil Date: Tue, 14 Jan 2025 13:12:08 -0800 Subject: [PATCH] Updated stored proc, ETL time. Updated the the Gender to Sex in Pend orders and recieved orders screens. --- onprc_ehr/resources/etls/SLAWeaning.xml | 4 +- .../sla_public/PurchaseOrderDetails.sql | 2 +- .../sla_public/PurchaseOrderDetailsAdmin.sql | 2 +- .../dbscripts/sqlserver/sla-23.002-23.003.sql | 169 +++++++++--------- 4 files changed, 90 insertions(+), 87 deletions(-) diff --git a/onprc_ehr/resources/etls/SLAWeaning.xml b/onprc_ehr/resources/etls/SLAWeaning.xml index 7179e7ce9..b03f7a8c5 100644 --- a/onprc_ehr/resources/etls/SLAWeaning.xml +++ b/onprc_ehr/resources/etls/SLAWeaning.xml @@ -21,8 +21,8 @@ - - + + \ No newline at end of file diff --git a/sla/resources/queries/sla_public/PurchaseOrderDetails.sql b/sla/resources/queries/sla_public/PurchaseOrderDetails.sql index f0946a0d3..99146e245 100644 --- a/sla/resources/queries/sla_public/PurchaseOrderDetails.sql +++ b/sla/resources/queries/sla_public/PurchaseOrderDetails.sql @@ -10,7 +10,7 @@ p.requestorid, p.requestor, p.vendor, pd.species, -pd.gender, +pd.gender as Sex, pd.strain, pd.weight, pd.gestation, diff --git a/sla/resources/queries/sla_public/PurchaseOrderDetailsAdmin.sql b/sla/resources/queries/sla_public/PurchaseOrderDetailsAdmin.sql index d9c3c2f35..5d2b264ef 100644 --- a/sla/resources/queries/sla_public/PurchaseOrderDetailsAdmin.sql +++ b/sla/resources/queries/sla_public/PurchaseOrderDetailsAdmin.sql @@ -11,7 +11,7 @@ p.requestorid, p.requestor, p.vendor, pd.species, -pd.gender, +pd.gender As Sex, pd.strain, pd.weight, pd.gestation, diff --git a/sla/resources/schemas/dbscripts/sqlserver/sla-23.002-23.003.sql b/sla/resources/schemas/dbscripts/sqlserver/sla-23.002-23.003.sql index 0d60faa1a..54e651ab8 100644 --- a/sla/resources/schemas/dbscripts/sqlserver/sla-23.002-23.003.sql +++ b/sla/resources/schemas/dbscripts/sqlserver/sla-23.002-23.003.sql @@ -106,17 +106,17 @@ Where numAlive > 0 And dateofTransfer is null And DateDiff(dd, date, GETDATE()) TRUNCATE TABLE sla.TempWeaning --Move the weaning entries into a temp table - INSERT INTO sla.TempWeaning (weaning_rowid, investigator, date, project, vendorlocation, DOB, DOM, species, sex, strain, numAlive, created) + INSERT INTO sla.TempWeaning (weaning_rowid, investigator, date, project, vendorlocation, DOB, DOM, species, sex, strain, numAlive, created) Select rowid, investigator, date, project, vendorlocation, date, DOM, species, CASE WHEN sex = 'F' THEN 'Female' WHEN sex = 'M' THEN 'Male' ELSE 'Male or Female' END AS sex, - strain, numAlive, GETDATE() From sla.weaning - Where numAlive > 0 And dateofTransfer is null And DateDiff(dd, date, GETDATE()) >= 21 + strain, numAlive, GETDATE() From sla.weaning + Where numAlive > 0 And dateofTransfer is null And DateDiff(dd, date, GETDATE()) >= 21 - --Set the counter seed value + --Set the counter seed value Select top 1 @counter = rowid from sla.Tempweaning order by rowid asc WHILE @counter <= @WCount -- start 1st while @@ -131,87 +131,90 @@ Where numAlive > 0 And dateofTransfer is null And DateDiff(dd, date, GETDATE()) -- Get projectid, PI and account Select @center_project = project, @alias = account From ehr.project Where name = (Select project From sla.TempWeaning Where rowid = @counter) - --Get the age of the rodent and weaning_rowid, species, sex, strain and vendorlocation - Select @ageindays = DateDiff(dd, date, GETDATE()),@weaning_rowid = weaning_rowid, - @species = species, @sex = sex, @strain = strain, @vendorlocation = vendorlocation, - @RequestedArrivalDate = DateAdd(dd, 21, date), @ExpectedArrivalDate = DateAdd(dd, 21, date), - @slaDOB = date, @numAnimalsOrdered = numAlive, @DOT = dateofTransfer - From sla.TempWeaning Where rowid = @counter - - -- Check if the row is already transfered into the main SLA tables. If DOT is null means the row hasn't been transferred yet. - If @DOT IS NULL -- start if, 1 + If @center_project IS NOT NULL -- start if, 4 Begin - --Insert weaning data into sla.purchase table as a pending order - INSERT INTO sla.purchase - (project, account, requestorid, vendorid, hazardslist, dobrequired, comments, confirmationnum, housingconfirmed, - iacucconfirmed, requestdate, orderdate, orderedby, objectid, container, createdby, created, modifiedby, modified, DARComments, VendorContact) - Select @center_project, @alias ,'7B3F1ED1-4CD9-4D9A-AFF4-FE0618D49C4B','E1EE1B64-B7BE-1035-BFC4-5107380AE41E','',0,'',null,null,null,null,null,'',NEWID(), - '4831D09C-4169-1034-BAD2-5107380A9819',1294,GETDATE(),null,null,'','' - - --Get the newly created purchaseid from sla.purchase - Select top 1 @purchaseid = objectid From sla.purchase order by created desc - - --Insert data into purchasedetails with the newly created purchaseid above - INSERT INTO sla.purchaseDetails - (purchaseid, species, age, weight, weight_units, gestation, gender, strain, room, animalsordered, animalsreceived, boxesquantity, costperanimal, shippingcost, - totalcost, housingInstructions, requestedarrivaldate, expectedarrivaldate, receiveddate, receivedby, cancelledby, datecancelled, - objectid, container, createdby, created, modifiedby, modified, sla_DOB, vendorLocation) - VALUES - (@purchaseId, @species, CONVERT(VARCHAR, @ageindays) + ' days','','','', @sex, @strain, '',@numAnimalsOrdered, null, null,'','', - '','',@RequestedArrivalDate,@ExpectedArrivalDate,null,'','',null, - NewId(),'4831D09C-4169-1034-BAD2-5107380A9819',1003,GETDATE(),null,null,@slaDOB,@vendorLocation) - - --Update the sla.weaning row with the date of transfer date set for the transferred weaning row - Update sla.weaning - Set dateofTransfer = GETDATE() - Where rowid = @weaning_rowid - - Update sla.TempWeaning - Set dateofTransfer = GETDATE() - Where rowid = @weaning_rowid - - --Find if there are any rows with the same center project. Then create them under one purchaseId - --set the new counter - SET @counter2 = @counter + 1; - - WHILE @counter2 <= @Wcount -- start 2nd while - BEGIN - --Get projectid of the next row - Select @center_project2 = project From ehr.project Where name = (Select project From sla.TempWeaning Where rowid = @counter2) - - If (@center_project = @center_project2) -- start if, 2 - Begin - Select @ageindays = DateDiff(dd, date, GETDATE()),@weaning_rowid = weaning_rowid, - @species = species, @sex = sex, @strain = strain, @vendorlocation = vendorlocation, - @RequestedArrivalDate = DateAdd(dd, 21, date), @ExpectedArrivalDate = DateAdd(dd, 21, date), - @slaDOB = date, @numAnimalsOrdered = numAlive, @DOT = dateofTransfer - From sla.TempWeaning Where rowid = @counter2 - - If @DOT IS NULL -- start if, 3 + --Get the age of the rodent and weaning_rowid, species, sex, strain and vendorlocation + Select @ageindays = DateDiff(dd, date, GETDATE()),@weaning_rowid = weaning_rowid, + @species = species, @sex = sex, @strain = strain, @vendorlocation = vendorlocation, + @RequestedArrivalDate = DateAdd(dd, 21, date), @ExpectedArrivalDate = DateAdd(dd, 21, date), + @slaDOB = date, @numAnimalsOrdered = numAlive, @DOT = dateofTransfer + From sla.TempWeaning Where rowid = @counter + + -- Check if the row is already transfered into the main SLA tables. If DOT is null means the row hasn't been transferred yet. + If @DOT IS NULL -- start if, 1 + Begin + --Insert weaning data into sla.purchase table as a pending order + INSERT INTO sla.purchase + (project, account, requestorid, vendorid, hazardslist, dobrequired, comments, confirmationnum, housingconfirmed, + iacucconfirmed, requestdate, orderdate, orderedby, objectid, container, createdby, created, modifiedby, modified, DARComments, VendorContact) + Select @center_project, @alias ,'7B3F1ED1-4CD9-4D9A-AFF4-FE0618D49C4B','E1EE1B64-B7BE-1035-BFC4-5107380AE41E','',0,'',null,null,null,null,null,'',NEWID(), + '4831D09C-4169-1034-BAD2-5107380A9819',1294,GETDATE(),null,null,'','' + + --Get the newly created purchaseid from sla.purchase + Select top 1 @purchaseid = objectid From sla.purchase order by created desc + + --Insert data into purchasedetails with the newly created purchaseid above + INSERT INTO sla.purchaseDetails + (purchaseid, species, age, weight, weight_units, gestation, gender, strain, room, animalsordered, animalsreceived, boxesquantity, costperanimal, shippingcost, + totalcost, housingInstructions, requestedarrivaldate, expectedarrivaldate, receiveddate, receivedby, cancelledby, datecancelled, + objectid, container, createdby, created, modifiedby, modified, sla_DOB, vendorLocation) + VALUES + (@purchaseId, @species, CONVERT(VARCHAR, @ageindays) + ' days','','','', @sex, @strain, '',@numAnimalsOrdered, null, null,'','', + '','',@RequestedArrivalDate,@ExpectedArrivalDate,null,'','',null, + NewId(),'4831D09C-4169-1034-BAD2-5107380A9819',1003,GETDATE(),null,null,@slaDOB,@vendorLocation) + + --Update the sla.weaning row with the date of transfer date set for the transferred weaning row + Update sla.weaning + Set dateofTransfer = GETDATE() + Where rowid = @weaning_rowid + + Update sla.TempWeaning + Set dateofTransfer = GETDATE() + Where rowid = @weaning_rowid + + --Find if there are any rows with the same center project. Then create them under one purchaseId + --set the new counter + SET @counter2 = @counter + 1; + + WHILE @counter2 <= @Wcount -- start 2nd while + BEGIN + --Get projectid of the next row + Select @center_project2 = project From ehr.project Where name = (Select project From sla.TempWeaning Where rowid = @counter2) + + If (@center_project = @center_project2) -- start if, 2 Begin - INSERT INTO sla.purchaseDetails - (purchaseid, species, age, weight, weight_units, gestation, gender, strain, room, animalsordered, animalsreceived, boxesquantity, costperanimal, shippingcost, - totalcost, housingInstructions, requestedarrivaldate, expectedarrivaldate, receiveddate, receivedby, cancelledby, datecancelled, - objectid, container, createdby, created, modifiedby, modified, sla_DOB, vendorLocation) - VALUES - (@purchaseId, @species, CONVERT(VARCHAR, @ageindays) + ' days','','','',@sex,@strain, '',@numAnimalsOrdered,null,null,'','', - '','',@RequestedArrivalDate,@ExpectedArrivalDate,null,'','',null, - NewId(),'4831D09C-4169-1034-BAD2-5107380A9819',1003,GETDATE(),null,null,@slaDOB,@vendorLocation) - - Update sla.weaning - Set dateofTransfer = GETDATE() - Where rowid = @weaning_rowid - - Update sla.TempWeaning - Set dateofTransfer = GETDATE() - Where rowid = @weaning_rowid - - End -- end if, 3 - End -- end if, 2 - SET @counter2 = @counter2 + 1; - END -- end, 2nd while - End -- end if, 1 - SET @counter = @counter + 1; + Select @ageindays = DateDiff(dd, date, GETDATE()),@weaning_rowid = weaning_rowid, + @species = species, @sex = sex, @strain = strain, @vendorlocation = vendorlocation, + @RequestedArrivalDate = DateAdd(dd, 21, date), @ExpectedArrivalDate = DateAdd(dd, 21, date), + @slaDOB = date, @numAnimalsOrdered = numAlive, @DOT = dateofTransfer + From sla.TempWeaning Where rowid = @counter2 + + If @DOT IS NULL -- start if, 3 + Begin + INSERT INTO sla.purchaseDetails + (purchaseid, species, age, weight, weight_units, gestation, gender, strain, room, animalsordered, animalsreceived, boxesquantity, costperanimal, shippingcost, + totalcost, housingInstructions, requestedarrivaldate, expectedarrivaldate, receiveddate, receivedby, cancelledby, datecancelled, + objectid, container, createdby, created, modifiedby, modified, sla_DOB, vendorLocation) + VALUES + (@purchaseId, @species, CONVERT(VARCHAR, @ageindays) + ' days','','','',@sex,@strain, '',@numAnimalsOrdered,null,null,'','', + '','',@RequestedArrivalDate,@ExpectedArrivalDate,null,'','',null, + NewId(),'4831D09C-4169-1034-BAD2-5107380A9819',1003,GETDATE(),null,null,@slaDOB,@vendorLocation) + + Update sla.weaning + Set dateofTransfer = GETDATE() + Where rowid = @weaning_rowid + + Update sla.TempWeaning + Set dateofTransfer = GETDATE() + Where rowid = @weaning_rowid + + End -- end if, 3 + End -- end if, 2 + SET @counter2 = @counter2 + 1; + END -- end, 2nd while + End -- end if, 1 + SET @counter = @counter + 1; + End -- end if, 4 END -- end, 1st while End -- end, BIG if END