Skip to content

Commit

Permalink
Updated stored proc, ETL time.
Browse files Browse the repository at this point in the history
Updated the the Gender to Sex in Pend orders and recieved orders screens.
  • Loading branch information
kollil committed Jan 14, 2025
1 parent 0961a2b commit 0762a26
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 87 deletions.
4 changes: 2 additions & 2 deletions onprc_ehr/resources/etls/SLAWeaning.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

<schedule>
<!-- Runs daily at 11pm -->
<!-- <cron expression="0 0 23 * * ?"/>-->
<poll interval="15m" /><!-- For testing only - runs every 15 mins -->
<cron expression="0 0 23 * * ?"/>
<!-- <poll interval="15m" />&lt;!&ndash; For testing only - runs every 15 mins &ndash;&gt;-->
</schedule>

</etl>
2 changes: 1 addition & 1 deletion sla/resources/queries/sla_public/PurchaseOrderDetails.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ p.requestorid,
p.requestor,
p.vendor,
pd.species,
pd.gender,
pd.gender as Sex,
pd.strain,
pd.weight,
pd.gestation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ p.requestorid,
p.requestor,
p.vendor,
pd.species,
pd.gender,
pd.gender As Sex,
pd.strain,
pd.weight,
pd.gestation,
Expand Down
169 changes: 86 additions & 83 deletions sla/resources/schemas/dbscripts/sqlserver/sla-23.002-23.003.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 0762a26

Please sign in to comment.