-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<etl xmlns="http://labkey.org/etl/xml"> | ||
|
||
<name>Update Protocols in EHR</name> | ||
|
||
<description>Runs stored procedures to update the protocol table in schema ehr.</description> | ||
|
||
<transforms> | ||
|
||
<transform id="UpdateBaseProtocol" type="StoredProcedure"> | ||
<description>Determines and populates BaseProtocol and RevisionNumber data for the protocol table in schema onprc_ehr.</description> | ||
<procedure schemaName="onprc_ehr" procedureName="BaseProtocol"> | ||
</procedure> | ||
</transform> | ||
|
||
<transform id="enddateExpiredProtocolsProtocol" type="StoredProcedure"> | ||
<description>Adds enddate data to the protocol table in ehr.</description> | ||
<procedure schemaName="onprc_ehr" procedureName="ExpiredProtocolUpdate"> | ||
</procedure> | ||
</transform> | ||
|
||
</transforms> | ||
|
||
<!-- | ||
<schedule> | ||
<cron expression="0 50 04 * * "/> | ||
</schedule> | ||
--> | ||
|
||
</etl> | ||
|
||
|
||
|
||
|
7 changes: 7 additions & 0 deletions
7
onprc_ehr/resources/schemas/dbscripts/sqlserver/onprc_ehr-24.001-24.002.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--added to allow insert of calculated fields from eIACUC | ||
|
||
--2024-12-13 In development need to use a drop if exists statement for these to run | ||
|
||
ALTER TABLE onprc_ehr.eIACUC_PRIME_VIEW_PROTOCOLS ADD [BaseProtocol] varchar(100) Null; | ||
ALTER TABLE onprc_ehr.eIACUC_PRIME_VIEW_PROTOCOLS ADD [RevisionNumber] varchar(100) Null; | ||
ALTER TABLE onprc_ehr.eIACUC_PRIME_VIEW_PROTOCOLS ADD [NewestRecord] INT Null; |
34 changes: 34 additions & 0 deletions
34
onprc_ehr/resources/schemas/dbscripts/sqlserver/onprc_ehr-24.002-24.003.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
CREATE PROCEDURE onprc_ehr.BaseProtocol | ||
AS | ||
BEGIN | ||
-- Create a Common Table Expression (CTE) named BaseProtocol | ||
WITH BaseProtocol AS | ||
( | ||
SELECT | ||
RowID, | ||
Protocol_id, | ||
-- Determine the BaseProtocol based on the length of the Protocol_id | ||
CASE | ||
WHEN LEN(Protocol_id) > 10 THEN SUBSTRING(Protocol_id, 6, 15) | ||
ELSE Protocol_id | ||
END AS BaseProtocol, | ||
-- Determine the RevisionNumber based on the length of the Protocol_id | ||
CASE | ||
WHEN LEN(Protocol_id) > 10 THEN SUBSTRING(Protocol_id,1, 5) | ||
ELSE 'Original' | ||
END AS RevisionNumber, | ||
approval_date, | ||
Three_Year_Expiration, | ||
last_modified, | ||
Protocol_State | ||
FROM onprc_ehr.eIACUC_PRIME_VIEW_PROTOCOLS | ||
) | ||
|
||
-- Update the onprc_ehr.eIACUC_PRIME_VIEW_PROTOCOLS table with BaseProtocol and RevisionNumber from the CTE | ||
UPDATE onprc_ehr.eIACUC_PRIME_VIEW_PROTOCOLS | ||
SET BaseProtocol = BaseProtocol.BaseProtocol, | ||
RevisionNumber = BaseProtocol.RevisionNumber | ||
FROM BaseProtocol | ||
WHERE onprc_ehr.eIACUC_PRIME_VIEW_PROTOCOLS.RowID = BaseProtocol.RowID; | ||
END | ||
GO |
48 changes: 48 additions & 0 deletions
48
onprc_ehr/resources/schemas/dbscripts/sqlserver/onprc_ehr-24.004-24.005.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
GO | ||
/****** Object: StoredProcedure [onprc_ehr].[ExpiredProtocolUpdate] Script Date: 12/20/2024 9:09:09 AM ******/ | ||
SET ANSI_NULLS ON | ||
GO | ||
SET QUOTED_IDENTIFIER ON | ||
GO | ||
CREATE PROCEDURE [onprc_ehr].[ExpiredProtocolUpdate] | ||
AS | ||
BEGIN | ||
|
||
WITH ApprovedProtocols AS ( | ||
SELECT | ||
BaseProtocol, | ||
MAX(Approval_Date) AS maxApprovalDate | ||
FROM | ||
onprc_ehr.eIACUC_PRIME_VIEW_PROTOCOLS | ||
WHERE | ||
Protocol_State IN ('approved','expired', 'terminated') | ||
GROUP BY | ||
BaseProtocol | ||
), | ||
|
||
|
||
DistinctProtocols AS ( | ||
SELECT DISTINCT | ||
p.rowID, | ||
p.BaseProtocol, | ||
p.RevisionNumber, | ||
p.Protocol_State, | ||
p.Approval_Date, | ||
p.Last_Modified, | ||
p.Three_Year_Expiration | ||
FROM | ||
onprc_ehr.eIACUC_PRIME_VIEW_PROTOCOLS p | ||
INNER JOIN ApprovedProtocols ap ON p.BaseProtocol = ap.BaseProtocol | ||
AND p.Approval_Date = ap.maxApprovalDate), | ||
ExpiredProtocol AS ( | ||
Select | ||
d.*, | ||
p.protocol, | ||
p.enddate | ||
from DistinctProtocols d inner join ehr.protocol p on d.BaseProtocol = p.external_ID | ||
where d.Protocol_State != 'Approved' and p.enddate is Null) | ||
|
||
Update p | ||
Set p.enddate = getDate() | ||
from ehr.protocol p inner join expiredProtocol e on p.external_id = e.BaseProtocol | ||
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters