From fc7b5b67bb6f0a5e128db70872510665b7443fe9 Mon Sep 17 00:00:00 2001 From: jonesgaohsu Date: Thu, 1 May 2025 07:50:21 -0700 Subject: [PATCH 1/5] Update of Process adding Animaluage as part of needed process for Integrity --- .../onprc_ehr/IntegrityAnimalReport.sql | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 onprc_ehr/resources/queries/onprc_ehr/IntegrityAnimalReport.sql diff --git a/onprc_ehr/resources/queries/onprc_ehr/IntegrityAnimalReport.sql b/onprc_ehr/resources/queries/onprc_ehr/IntegrityAnimalReport.sql new file mode 100644 index 000000000..5aceca7ff --- /dev/null +++ b/onprc_ehr/resources/queries/onprc_ehr/IntegrityAnimalReport.sql @@ -0,0 +1,82 @@ +--4/30/2025 Talked wiht KJim Ray and reviewed tghe current output +--she is not interested in the assigned animal counts +--she would like to PI added to the report and to provide a hyperlink from the Protocol Number +--Need to get the current report for allwoable animals in Prime + +With eIACUCAuthorized as ( + SELECT + + g.Parent_Protocol as Protocol, + g.Species, + Sum(g.Number_of_Animals_Max) as TotalforSpecies + + + FROM eIACUC_PRIME_VIEW_ANIMAL_GROUPS g left outer join eIACUC_PRIME_VIEW_PROTOCOLS p + on g.Parent_Protocol = p.protocol_id + where p.protocol_state = 'Approved' + Group by g.Parent_Protocol,g.Species), +--This will tie the animal authorized to the Base Protocol fior comparison + + BaseProtocolAssigned as ( + Select a.protocol, + p.BaseProtocol, + p.RevisionNumber, + p.Protocol_State, + a.species, + a.TotalforSpecies + + + from eIACUC_PRIME_VIEW_PROTOCOLS p join eIACUCAuthorized a + on a.protocol = p.protocol_id + + ), + + --This query finds the nukmbder assigned from the assignment table + -- added thatg this is for NHP assignments + CurrentAssignedNHP as + (Select + --a.project.protocol as Protocol, + p.external_id as Protocol, + a.id.demographics.species as Species, + Count(a.id) as TotalAssignedbySpecies + from study.assignment a join ehr.protocol p on a.project.protocol = p.protocol + where (a.date <= Now() -- Take care of future assignments in the date + and a.enddate is null or a.enddate > Now()) + Group By + p.external_id, + a.id.demographics.species + ), + AllowablefromProtocol as ( + Select + a.protocol, + a.species, + a.allowed + + + From ehr.animalusage a + + + + ), +--This will be the final report + --Need to add a CTE for SLA + SummaryReport as ( +Select + e.Protocol, + --a.project, + e.species, + Sum(e.TotalForSpecies) + + + +from eIACUCAuthorized e --, CurrentAssigned a + -- Where e.protocol = a.protocol + Group by + e.Protocol, + e.species + ) +--Select * from eIACUCAuthorized +--Select * from CurrentAssigned +--Select * from SummaryReport +--Select * from BaseProtocolAssigned +select * from AllowablefromProtocol \ No newline at end of file From 0ce2c55bd680068cb385d58501ff49a00ce6c60e Mon Sep 17 00:00:00 2001 From: jonesgaohsu Date: Thu, 1 May 2025 07:51:28 -0700 Subject: [PATCH 2/5] Update of Process adding Animaluage as part of needed process for Integrity --- .../resources/queries/onprc_ehr/eiACUCtoProtocolCheck.sql | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 onprc_ehr/resources/queries/onprc_ehr/eiACUCtoProtocolCheck.sql diff --git a/onprc_ehr/resources/queries/onprc_ehr/eiACUCtoProtocolCheck.sql b/onprc_ehr/resources/queries/onprc_ehr/eiACUCtoProtocolCheck.sql new file mode 100644 index 000000000..1667c25f0 --- /dev/null +++ b/onprc_ehr/resources/queries/onprc_ehr/eiACUCtoProtocolCheck.sql @@ -0,0 +1,4 @@ + + + +From onprc_ehr. \ No newline at end of file From b90329e2f8e141123c0e6c6c8b13f486a131b76c Mon Sep 17 00:00:00 2001 From: jonesgaohsu Date: Thu, 1 May 2025 08:22:14 -0700 Subject: [PATCH 3/5] Update of Process adding Animaluage as part of needed process for Integrity --- .../integrityAllowableAnimalsReport.sql | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 onprc_ehr/resources/queries/onprc_ehr/integrityAllowableAnimalsReport.sql diff --git a/onprc_ehr/resources/queries/onprc_ehr/integrityAllowableAnimalsReport.sql b/onprc_ehr/resources/queries/onprc_ehr/integrityAllowableAnimalsReport.sql new file mode 100644 index 000000000..b761705b0 --- /dev/null +++ b/onprc_ehr/resources/queries/onprc_ehr/integrityAllowableAnimalsReport.sql @@ -0,0 +1,84 @@ +--4/30/2025 Talked wiht KJim Ray and reviewed tghe current output +--she is not interested in the assigned animal counts +--she would like to PI added to the report and to provide a hyperlink from the Protocol Number +--Need to get the current report for allwoable animals in Prime +--New Name and definitions as I refine the process. + +With eIACUCAuthorized as ( + SELECT + + g.Parent_Protocol as Protocol, + g.Species, + Sum(g.Number_of_Animals_Max) as TotalforSpecies + + + FROM eIACUC_PRIME_VIEW_ANIMAL_GROUPS g left outer join eIACUC_PRIME_VIEW_PROTOCOLS p + on g.Parent_Protocol = p.protocol_id + where p.protocol_state = 'Approved' + Group by g.Parent_Protocol,g.Species), +--This will tie the animal authorized to the Base Protocol fior comparison + + BaseProtocolAssigned as ( + Select a.protocol, + p.BaseProtocol, + p.RevisionNumber, + p.Protocol_State, + a.species, + a.TotalforSpecies + + + from eIACUC_PRIME_VIEW_PROTOCOLS p join eIACUCAuthorized a + on a.protocol = p.protocol_id + + ), + + --This query finds the nukmbder assigned from the assignment table + -- added thatg this is for NHP assignments + CurrentAssignedNHP as + (Select + --a.project.protocol as Protocol, + p.external_id as Protocol, + a.id.demographics.species as Species, + Count(a.id) as TotalAssignedbySpecies + from study.assignment a join ehr.protocol p on a.project.protocol = p.protocol + where (a.date <= Now() -- Take care of future assignments in the date + and a.enddate is null or a.enddate > Now()) + Group By + p.external_id, + a.id.demographics.species + ), + AllowablefromProtocol as ( + Select + a.protocol, + a.species, + Sum(a.allowed) + + + From ehr.animalusage a + Group BY + a.protocol, + a.species + + ), +--This will be the final report + --Need to add a CTE for SLA + SummaryReport as ( + Select + e.Protocol, + --a.project, + e.species, + Sum(e.TotalForSpecies) + + + + from eIACUCAuthorized e --, CurrentAssigned a + -- Where e.protocol = a.protocol + Group by + e.Protocol, + e.species + ) +--Select * from eIACUCAuthorized +--Select * from CurrentAssigned +--Select * from SummaryReport +--Select * from BaseProtocolAssigned +select * from AllowablefromProtocol \ No newline at end of file From 9aefed2c20dfe40849f1eff168096dba20d39e8f Mon Sep 17 00:00:00 2001 From: jonesgaohsu Date: Fri, 2 May 2025 09:34:00 -0700 Subject: [PATCH 4/5] Switching PRojectsa to finish Public Rates --- .../integrityAllowableAnimalsReport.sql | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/onprc_ehr/resources/queries/onprc_ehr/integrityAllowableAnimalsReport.sql b/onprc_ehr/resources/queries/onprc_ehr/integrityAllowableAnimalsReport.sql index b761705b0..2adf69bae 100644 --- a/onprc_ehr/resources/queries/onprc_ehr/integrityAllowableAnimalsReport.sql +++ b/onprc_ehr/resources/queries/onprc_ehr/integrityAllowableAnimalsReport.sql @@ -34,7 +34,8 @@ With eIACUCAuthorized as ( --This query finds the nukmbder assigned from the assignment table -- added thatg this is for NHP assignments - CurrentAssignedNHP as + --Kim Ray says this is not needed + /*CurrentAssignedNHP as (Select --a.project.protocol as Protocol, p.external_id as Protocol, @@ -46,7 +47,7 @@ With eIACUCAuthorized as ( Group By p.external_id, a.id.demographics.species - ), + ),*/ AllowablefromProtocol as ( Select a.protocol, @@ -62,23 +63,33 @@ With eIACUCAuthorized as ( ), --This will be the final report --Need to add a CTE for SLA - SummaryReport as ( + AuthorizedNHP as ( Select - e.Protocol, + p.Protocol, --a.project, e.species, - Sum(e.TotalForSpecies) + Sum(e.TotalForSpecies) as TotalAuthorized - from eIACUCAuthorized e --, CurrentAssigned a - -- Where e.protocol = a.protocol + from eIACUCAuthorized e , ehr.protocol p + Where e.protocol = p.protocol Group by e.Protocol, e.species - ) ---Select * from eIACUCAuthorized + ), + SummaryNHP as ( + Select + a.protocol, + a.species, + a.TotalAuthorized + + from AuthorizedNHP a + where a.species not in ('Rat','Mice','Rabbit') + + ) +Select * from eIACUCAuthorized --Select * from CurrentAssigned ---Select * from SummaryReport +--Select * from SummaryNHP --Select * from BaseProtocolAssigned -select * from AllowablefromProtocol \ No newline at end of file +--select * from AllowablefromProtocol \ No newline at end of file From 02b7b8ec3cbbe9bdf99d7cb4ace33cb912cca4ab Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Tue, 27 May 2025 09:37:34 -0700 Subject: [PATCH 5/5] Addition of queries for Integrity Animal Report --- ...port.sql => IntegrityAnimalReportNHps.sql} | 34 ++++++++++++++++--- .../integrityAllowableAnimalsReport.sql | 17 +--------- 2 files changed, 30 insertions(+), 21 deletions(-) rename onprc_ehr/resources/queries/onprc_ehr/{IntegrityAnimalReport.sql => IntegrityAnimalReportNHps.sql} (69%) diff --git a/onprc_ehr/resources/queries/onprc_ehr/IntegrityAnimalReport.sql b/onprc_ehr/resources/queries/onprc_ehr/IntegrityAnimalReportNHps.sql similarity index 69% rename from onprc_ehr/resources/queries/onprc_ehr/IntegrityAnimalReport.sql rename to onprc_ehr/resources/queries/onprc_ehr/IntegrityAnimalReportNHps.sql index 5aceca7ff..0249a674e 100644 --- a/onprc_ehr/resources/queries/onprc_ehr/IntegrityAnimalReport.sql +++ b/onprc_ehr/resources/queries/onprc_ehr/IntegrityAnimalReportNHps.sql @@ -54,29 +54,53 @@ With eIACUCAuthorized as ( From ehr.animalusage a + where Isactive = True ), --This will be the final report --Need to add a CTE for SLA + --Not getting a solid connection between + --summary needs to combine eIACUCAuthorized with Allowable by Protocol SummaryReport as ( Select e.Protocol, + a.protocol as PrimeProtocol, --a.project, e.species, - Sum(e.TotalForSpecies) + Sum(e.TotalForSpecies) as eIACUCAuthorized, + Sum(a.allowed) as PrimeAuthorized - -from eIACUCAuthorized e --, CurrentAssigned a - -- Where e.protocol = a.protocol +from eIACUCAuthorized e left outer join AllowablefromProtocol a on e.protocol = a.protocol.displayName + Where e.Species not in ('Rat','Rabbit','Mouse', 'Guinea Pig') Group by e.Protocol, + a.protocol, e.species + ), + CompareReport as ( + Select + s.protocol, + s.PrimeProtocol, + s.species, + s.eIACUCAuthorized, + s.PrimeAuthorized, + (s.eIACUCAuthorized - s.primeAuthorized) as AuthorizedCompare, + 'Review Authorized Animals' as UpdateAuthorizedNHPS + + from SummaryReport s + Group by + s.protocol, + s.PrimeProtocol, + s.species, + s.eIACUCAuthorized, + s.primeAuthorized ) --Select * from eIACUCAuthorized --Select * from CurrentAssigned --Select * from SummaryReport --Select * from BaseProtocolAssigned -select * from AllowablefromProtocol \ No newline at end of file +--select * from AllowablefromProtocol +Select * from CompareReport \ No newline at end of file diff --git a/onprc_ehr/resources/queries/onprc_ehr/integrityAllowableAnimalsReport.sql b/onprc_ehr/resources/queries/onprc_ehr/integrityAllowableAnimalsReport.sql index 2adf69bae..c42487f4d 100644 --- a/onprc_ehr/resources/queries/onprc_ehr/integrityAllowableAnimalsReport.sql +++ b/onprc_ehr/resources/queries/onprc_ehr/integrityAllowableAnimalsReport.sql @@ -32,22 +32,7 @@ With eIACUCAuthorized as ( ), - --This query finds the nukmbder assigned from the assignment table - -- added thatg this is for NHP assignments - --Kim Ray says this is not needed - /*CurrentAssignedNHP as - (Select - --a.project.protocol as Protocol, - p.external_id as Protocol, - a.id.demographics.species as Species, - Count(a.id) as TotalAssignedbySpecies - from study.assignment a join ehr.protocol p on a.project.protocol = p.protocol - where (a.date <= Now() -- Take care of future assignments in the date - and a.enddate is null or a.enddate > Now()) - Group By - p.external_id, - a.id.demographics.species - ),*/ + AllowablefromProtocol as ( Select a.protocol,