Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sla weaning project #1137

Merged
merged 24 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
73ee19d
Sla weaning project.
kollil Sep 24, 2024
4655b3e
Added Go statement after the db tables creation
kollil Sep 24, 2024
874b37a
Updated the weaning page link
kollil Sep 25, 2024
d12252c
Update DB stuff
kollil Sep 28, 2024
059902f
Updated URL
kollil Sep 29, 2024
28f79c9
Updated db tables, stored proc
kollil Oct 2, 2024
692bf5a
Fixed a typo
kollil Oct 2, 2024
3e6ce51
Added the ETL process
kollil Oct 3, 2024
651d71b
Updated the sql comments
kollil Oct 15, 2024
57b8faf
Updated the stored proc schema to point to onprc_ehr.
kollil Oct 16, 2024
e3d1efc
updated ETL code
kollil Oct 16, 2024
6100ead
updated ETL code - changed the cronjob time to run every 15 mins for …
kollil Oct 17, 2024
8f75001
updated ETL code
kollil Oct 17, 2024
aa3577c
Updated stored proc to add expected, requested dates and numordered f…
kollil Oct 18, 2024
d5dd277
Update the Stored proc
kollil Oct 23, 2024
ca17cf1
Label and headers change from "Gender" to "Sex" in SLA purchase module.
kollil Nov 8, 2024
8d64daa
Some more places - Label and headers change from "Gender" to "Sex" in…
kollil Nov 10, 2024
ad20510
Some more places - Label and headers change from "Gender" to "Sex" in…
kollil Nov 11, 2024
02e52b9
Changed the cron time to 15 mins for testing
kollil Nov 12, 2024
0961a2b
Updated th stored proc
kollil Jan 8, 2025
0762a26
Updated stored proc, ETL time.
kollil Jan 14, 2025
16f56e5
Updated stored proc, ETL time.
kollil Jan 20, 2025
cda6c60
Updated sql
kollil Jan 20, 2025
a680069
Removed tempweaning defintion from xml.
kollil Jan 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions onprc_ehr/resources/etls/SLAWeaning.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--Created By: Kollil, 9/25/2024.
Create an ETL process for SLA weaning data: Based on the alive pups DOB, create an ETL process that runs daily and checks if there are any pups
that’s 21 days old, load them into SLA purchase & purchase details datasets as pending orders (Confirmation num is null & dateCanceled is null).
Once the data is moved, the “dateofTransfer” field will be set marking the pups are moved into SLA purchase datasets and will be excluded
from the future daily checks.
Refer to ticket # 11233 for more details.
-->
<etl xmlns="http://labkey.org/etl/xml">

<name>SLAWeaning</name>

<description>Executes stored procedure to populate the SLA purchase datasets</description>

<transforms>
<transform id="Stored_Proc" type="StoredProcedure">
<description>Runs the stored procedure to process and update the weaning data from sla.TempWeaning table to sla.purchase and sla.purchasedetails tables in prime</description>
<procedure schemaName="onprc_ehr" procedureName="SLAWeaningDataTransfer"> </procedure>
</transform>
</transforms>

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

</etl>
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<columnTitle>Species</columnTitle>
</column>
<column columnName="Gender">
<columnTitle>Gender</columnTitle>
<columnTitle>Sex</columnTitle>
</column>
<column columnName="Strain">
<columnTitle>Strain</columnTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SELECT
a.title As Title,
i.LastName || ', ' || i.FirstName As PIName,
aa.Species,
aa.Gender,
aa.Gender as Sex,
aa.Strain,
aa.Allowed As NumAllowed,
aa.StartDate,
Expand Down
2 changes: 1 addition & 1 deletion sla/resources/queries/sla/ProtocolProjectsUsage.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<columnTitle>Species</columnTitle>
</column>
<column columnName="Gender">
<columnTitle>Gender</columnTitle>
<columnTitle>Sex</columnTitle>
</column>
<column columnName="Strain">
<columnTitle>Strain</columnTitle>
Expand Down
2 changes: 1 addition & 1 deletion sla/resources/queries/sla/ProtocolProjectsUsage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SELECT
y.grantNumber as OGAGrantNumber,
y.fiscalAuthorityName As FiscalAuthorityName,
aa.Species,
aa.Gender,
aa.Gender as Sex,
aa.Strain,
aa.Allowed AS NumAllowed,
calc.NumUsed,
Expand Down
2 changes: 1 addition & 1 deletion sla/resources/queries/sla/allowableSLA.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
SELECT a.protocol,
c.protocol_id as eIACUC_protocol_name,
a.species,
a.gender,
a.gender as Sex,
a.strain,
a.age,
a.allowed,
Expand Down
18 changes: 18 additions & 0 deletions sla/resources/queries/sla/weaning/.qview.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<customView xmlns="http://labkey.org/data/xml/queryCustomView">
<columns>
<column name="rowid"/>
<column name="investigator"/>
<column name="date"/>
<column name="project"/>
<column name="vendorlocation"/>
<column name="DOB"/>
<column name="DOM"/>
<column name="species"/>
<column name="sex"/>
<column name="strain"/>
<column name="numAlive"/>
<column name="numDead"/>
<column name="totalPups"/>
<column name="dateofTransfer"/>
</columns>
</customView>
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
185 changes: 185 additions & 0 deletions sla/resources/schemas/dbscripts/sqlserver/sla-23.002-23.003.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
-- =================================================================================================
--Created by Kollil
--These tables and stored proc was created to enter weaning data into SLA tables
--Refer to ticket #11233
-- =================================================================================================

--Drop table if exists
EXEC core.fn_dropifexists 'weaning','sla','TABLE';
--Drop Stored proc if exists
EXEC core.fn_dropifexists 'SLAWeaningDataTransfer', 'onprc_ehr', 'PROCEDURE';
GO

CREATE TABLE sla.weaning (
rowid int IDENTITY(1,1) NOT NULL,
investigator varchar(250),
date DATETIME, -- Pup's DOB
project varchar(200),
vendorLocation varchar(200),
DOB DATETIME, --Dam's DOB
DOM DATETIME, --Date of Mating
species varchar(100),
sex varchar(100),
strain varchar (200),
numAlive INTEGER,
numDead INTEGER,
totalPups INTEGER,
dateofTransfer DATETIME, --The date of transfer into SLA tables
createdBy USERID,
created DATETIME,
modifiedBy USERID,
modified DATETIME,

CONSTRAINT PK_weaning PRIMARY KEY (rowid)
);

GO

/****** Object: StoredProcedure sla.SLAWeaningDataTransfer Script Date: 8/24/2024 *****/
-- ==========================================================================================
-- Author: Lakshmi Kolli
-- Create date: 8/24/2024
-- Description: Create a stored proc to check for any rodents with age >= 21 days and enter
-- the data into SLA tables
-- ==========================================================================================

CREATE PROCEDURE [onprc_ehr].[SLAWeaningDataTransfer]
AS

DECLARE
@WCount int,
@alias varchar(100),
@purchaseId entityid,
@center_project int,
@center_project2 int,
@counter int,
@counter2 int,
@DOT DATETIME,
@DOT2 DATETIME

BEGIN
--Check if any rodents age is 21 days and above and not transferred into SLA tables
Select @WCount = COUNT(*) From sla.weaning Where numAlive > 0 And dateofTransfer is null And DateDiff(dd, date, GETDATE()) >= 21

--Found entries, so, insert those records into SLA.purchase and SLA.purchasedetails tables
If @WCount > 0 -- start if, 1
Begin
--Create a local temp table to process the weaning data. The table drops automatically at the end of the session
CREATE TABLE #TempWeaning (
rowid int IDENTITY(1,1) NOT NULL,
orig_weaning_rowid INTEGER,
investigator varchar(250),
date DATETIME,
project varchar(200),
vendorLocation varchar(200),
DOB DATETIME,
DOM DATETIME,
species varchar(100),
sex varchar(100),
strain varchar (200),
numAlive INTEGER,
dateofTransfer DATETIME,
created DATETIME
);

--Move the weaning entries into a temp table
INSERT INTO #TempWeaning (orig_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

--Set the counter seed value
Select top 1 @counter = rowid from #TempWeaning order by rowid asc

WHILE @counter <= @WCount -- start 1st while
BEGIN
/* Requestorid - (Kati Marshall ) - 7B3F1ED1-4CD9-4D9A-AFF4-FE0618D49C4B
Userid - (Kati Marshall) - 1294
vendor - (ONPRC Weaning - SLA) - E1EE1B64-B7BE-1035-BFC4-5107380AE41E
container - (SLA) - 4831D09C-4169-1034-BAD2-5107380A9819
created - (onprc-is) - 1003
*/

Select @DOT = dateofTransfer From #TempWeaning Where rowid = @counter
If @DOT IS NULL --start @DOT
Begin
-- Get projectid, PI and account
Select @center_project = project, @alias = account From ehr.project Where name = (Select project From #TempWeaning Where rowid = @counter)

-- Check if the row is already transferred into the main SLA tables. If DOT is null means the row hasn't been transferred yet.
--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',1003,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)
Select @purchaseid, species, CONVERT(VARCHAR, DateDiff(dd, date, GETDATE())) + ' days', '','','',sex, strain,'',numAlive,null,null,'','',
'','',DateAdd(dd, 21, date), DateAdd(dd, 21, date),null,'','',null,
NewId(),'4831D09C-4169-1034-BAD2-5107380A9819',1003,GETDATE(),null,null,date,vendorLocation
From #TempWeaning Where rowid = @counter

--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 = (Select orig_weaning_rowid from #TempWeaning Where rowid = @counter)

Update #TempWeaning
Set dateofTransfer = GETDATE() Where rowid = @counter

--Find if there are any rows with the same center project. Then create them under the same purchaseId
--set the new counter
SET @counter2 = @counter + 1;
WHILE @counter2 <= @Wcount -- start 2nd while
BEGIN
Select @DOT2 = dateofTransfer From #TempWeaning Where rowid = @counter2
If @DOT2 IS NULL
Begin
--Get projectid of the next row
Select @center_project2 = project From ehr.project Where name = (Select project From #TempWeaning Where rowid = @counter2)

--If they are same projects, then use the the same purchaseid when creating the purchase details record
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)
Select @purchaseid, species, CONVERT(VARCHAR, DateDiff(dd, date, GETDATE())) + ' days', '','','',sex, strain, '',numAlive,null,null,'','',
'','',DateAdd(dd, 21, date), DateAdd(dd, 21, date),null,'','',null,
NewId(),'4831D09C-4169-1034-BAD2-5107380A9819',1003,GETDATE(),null,null,date,vendorLocation
From #TempWeaning Where rowid = @counter2

Update sla.weaning
Set dateofTransfer = GETDATE() Where rowid = (Select orig_weaning_rowid from #TempWeaning Where rowid = @counter2)

Update #TempWeaning
Set dateofTransfer = GETDATE() Where rowid = @counter2
End -- end if, 2
End --end DOT2
SET @counter2 = @counter2 + 1;
END -- end, 2nd while

End --end @DOT
SET @counter = @counter + 1;
END -- end, 1st while
End -- end if, 1

--Drop the temp table incase it exists...
IF EXISTS (SELECT * FROM tempdb.sys.tables WHERE name = '#TempWeaning')
BEGIN
DROP TABLE #TempWeaning;
END;
END
Go
58 changes: 57 additions & 1 deletion sla/resources/schemas/sla.xml
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,60 @@
</columns>
</table>

</tables>
<table tableName="Weaning" tableDbType="TABLE" useColumnOrder="true">
<tableTitle>Weaning</tableTitle>
<auditLogging>DETAILED</auditLogging>
<importUrl></importUrl>
<insertUrl></insertUrl>
<updateUrl></updateUrl>
<deleteUrl></deleteUrl>

<columns>
<column columnName="rowid" />
<column columnName="investigator">
<columnTitle>PI</columnTitle>
</column>
<column columnName="date">
<columnTitle>Date</columnTitle>
</column>
<column columnName="project">
<columnTitle>Center Project</columnTitle>
</column>
<column columnName="vendorLocation">
<columnTitle>Vendor Location</columnTitle>
</column>
<column columnName="DOB">
<columnTitle>DOB</columnTitle>
</column>
<column columnName="DOM">
<columnTitle>DOM</columnTitle>
</column>
<column columnName="species">
<columnTitle>Species</columnTitle>
</column>
<column columnName="sex">
<columnTitle>Sex</columnTitle>
</column>
<column columnName="strain">
<columnTitle>Strain</columnTitle>
</column>
<column columnName="numAlive">
<columnTitle>Alive Pups</columnTitle>
</column>
<column columnName="numDead">
<columnTitle>Dead Pups</columnTitle>
</column>
<column columnName="totalPups">
<columnTitle>Total Pups</columnTitle>
</column>
<column columnName="dateofTransfer">
<columnTitle>Date moved to SLA pending orders</columnTitle>
</column>
<column columnName="createdby" />
<column columnName="created" />
<column columnName="modifiedby" />
<column columnName="modified" />
</columns>
</table>

</tables>
12 changes: 8 additions & 4 deletions sla/resources/views/SLA_LandingPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@ <h2><span style="font-size: large;"><b>SLA Purchase </b></span></h2>
<p>Click the link below to view the SLA groups & breeding information for the protocols. This information is retrieved daily from the eIACUC database.</p>
<p><strong><a href="/query/ONPRC/SLA/executeQuery.view?schemaName=ehrSLA&query.queryName=ProtocolProjectsAndBreedingInfo">SLA Groups & Breeding Information</a>&nbsp</strong></p>
<br>
<h2><span style="font-size: large;"><b>SLA Weaning </b></span></h2>
<p>SLA weaning module is used by SLAU staff to record the rodent births and documenting the number of animals weaned.<br> Weaned mice are entered into SLA purchase module as they need to be subtracted from the protocol's SLA allowance numbers.</p>
<!--<p><strong><a href="http://localhost:8080/labkey/ldk/ONPRC/SLA/updateQuery.view?schemaName=sla&query.queryName=Weaning">Click here to view/upload the weaning data</a>&nbsp</strong></p>-->
<p><strong><a href="/ldk/ONPRC/SLA/updateQuery.view?schemaName=sla&query.queryName=Weaning">Click here to view/upload the weaning data</a>&nbsp</strong></p>
<br>
<h2><span style="font-size: large;"><b>SLA Census </b></span></h2>
<p>SLA census module is used by SLAU staff to maintain rodent demographic and location data and billing. Please click on the links below for specific operations.</p>
<br>
<h3><span style="font-size: large;">Entering Animals</span></h3>
<h3><span style="font-size: large;"><b><i>Entering Animals:</i></b></span></h3>
<address>
<p><strong><a href="/ehr/ONPRC/SLA/dataEntryForm.view?formType=SLA%20Census">SLA Census - Entry Screen</a></strong></p>
<p><strong><a href="/ehr/onprc/sla/enterData.view">SLA Census - Edit&nbsp;Previous Record Menu</a>&nbsp;</strong>&nbsp;- Choose "All Tasks" navigational tab and click the mouse on the task id to edit a record.</p>
<p><strong><a href="/sla/ONPRC/SLA/censusBulkEdit.view?">SLA Census - Bulk Editing Grid</a>&nbsp; -&nbsp;</strong>Allows editing more than one Census records.</p>
<p><strong><a href="/EHR/ONPRC/EHR/dataEntryForm.view?formType=arrival">SLA - Entry Grid for Rabbits / Guinea Pigs</a>&nbsp; -&nbsp;</strong>Web link to enter new Rabbits and Guinea Pig records.</p>
</address>
<h3><span style="font-size: large;">Entering Charges</span></h3>
<h3><span style="font-size: large;"><b><i>Entering Charges:</i></b></span></h3>
<address>
<p><strong><a href="/query/ONPRC/EHR/executeQuery.view?schemaName=onprc_billing&amp;query.queryName=miscChargesFees">Misc Charges - Grid</a>&nbsp;-&nbsp;</strong>This format is best for export to Excel.</p>
<p><strong><a href="/ehr/ONPRC/EHR/dataEntryForm.view?formType=miscCharges">Misc Charges - Entry Form</a></strong></p>
<p><strong><a href="/onprc_ehr/onprc/ehr/enterData.view">Return to "My Task/All Task" Page</a><a href="/ehr/ONPRC/EHR/dataEntryForm.view?formType=miscCharges">&nbsp;</a></strong></p>
</address>
<h3><span style="font-size: large;">Reports</span></h3>
<h3><span style="font-size: large;"><b><i>Reports:</i></b></span></h3>
<address>
<p><strong><a href="/EHR/ONPRC/SLA/executeQuery.view?schemaName=sla&amp;query.queryName=census">SLA Census - Grid</a></strong></p>
<p><strong><a href="https://pcdbssrsprd1.ohsu.edu/ReportServer/Pages/ReportViewer.aspx?%2fPrime+Reports%2fSLA+Reports%2fSLACensusMainReport_Project&amp;rs:Command=Render">SLA Census - Printed Report</a>&nbsp;-&nbsp;</strong>Center Project &amp; Date Range required.</p>
Expand Down
Loading