colMap = QueryService.get().getColumns(ti, columns);
TableSelector ts2 = new TableSelector(ti, colMap.values(), null, null);
- count = ts2.getRowCount();
- if (count == 0) {
- msg.append("There are no scheduled PMIC events");
- }
- else {
- msg.append("
Daily PMIC events:
\n");
- msg.append("");
- msg.append("");
- msg.append("| Resource Id | Start Date | End Date | Name | Alias | Quantity | Comments | Color | Room | Bldg |
");
-
- ts2.forEach(new Selector.ForEachBlock() {
- @Override
- public void exec(ResultSet object) throws SQLException {
- Results rs = new ResultsImpl(object, colMap);
- msg.append("");
- msg.append("| " + rs.getString("resourceid") + " | ");
- msg.append("" + rs.getString("startdate") + " | ");
- msg.append("" + rs.getString("enddate") + " | ");
- msg.append("" + rs.getString("name") + " | ");
- msg.append("" + rs.getString("alias") + " | ");
- msg.append("" + rs.getString("quantity") + " | ");
- msg.append("" + rs.getString("comments") + " | ");
- msg.append("" + rs.getString("color") + " | ");
- msg.append("" + rs.getString("room") + " | ");
- msg.append("" + rs.getString("bldg") + " | ");
+ msg.append("
Today's PMIC events:
\n");
+ msg.append("");
+ msg.append("");
+ msg.append("| Resource Id | Start Date | End Date | Name | Alias | Quantity | Comments | Color | Room | Bldg |
");
+
+ ts2.forEach(new Selector.ForEachBlock() {
+ @Override
+ public void exec(ResultSet object) throws SQLException {
+ Results rs = new ResultsImpl(object, colMap);
+ msg.append("");
+ msg.append("| " + PageFlowUtil.filter(rs.getString("resourceid")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("startdate")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("enddate")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("name")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("alias")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("quantity")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("comments")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("color")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("room")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("bldg")) + " | ");
+ msg.append("
");
+ }
+ });
+ msg.append("
");
+ }
+
+ //Display the weekly report in the email
+ if (count1 > 0) {
+ Set columns1 = new HashSet<>();
+ columns1.add(FieldKey.fromString("resourceid"));
+ columns1.add(FieldKey.fromString("startdate"));
+ columns1.add(FieldKey.fromString("enddate"));
+ columns1.add(FieldKey.fromString("name"));
+ columns1.add(FieldKey.fromString("alias"));
+ columns1.add(FieldKey.fromString("quantity"));
+ columns1.add(FieldKey.fromString("comments"));
+ columns1.add(FieldKey.fromString("color"));
+ columns1.add(FieldKey.fromString("room"));
+ columns1.add(FieldKey.fromString("bldg"));
+
+ final Map colMap1 = QueryService.get().getColumns(ti1, columns1);
+ TableSelector ts3 = new TableSelector(ti1, colMap1.values(), null, null);
+
+ msg.append("
Weekly PMIC events:
\n");
+ msg.append("");
+ msg.append("");
+ msg.append("| Resource Id | Start Date | End Date | Name | Alias | Quantity | Comments | Color | Room | Bldg |
");
+
+ ts3.forEach(new Selector.ForEachBlock() {
+ @Override
+ public void exec(ResultSet object) throws SQLException {
+ Results rs1 = new ResultsImpl(object, colMap1);
+ msg.append("");
+ msg.append("| " + PageFlowUtil.filter(rs1.getString("resourceid")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs1.getString("startdate")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs1.getString("enddate")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs1.getString("name")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs1.getString("alias")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs1.getString("quantity")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs1.getString("comments")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs1.getString("color")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs1.getString("room")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs1.getString("bldg")) + " | ");
+ msg.append("
");
+ }
+ });
+ msg.append("
");
+ }
+
+ }
+ //End of PMIC alert
+
+ /**
+ * Kollil, 03/24/2021 : PMIC services request alert
+ */
+ protected void pmicServicesRequestAlert(final Container c, User u, final StringBuilder msg)
+ {
+ SimpleFilter filter = new SimpleFilter(FieldKey.fromString("date"), new Date(), CompareType.DATE_GTE);
+ TableSelector ts = new TableSelector(getStudySchema(c, u).getTable("PMIC_ServicesRequestAlert"), filter, null);
+ long count = ts.getRowCount();
+ if (count > 0)
+ {
+ msg.append("" + count + " PMIC procedures found.
\n");
+ msg.append("Click here to view them
\n\n");
+ msg.append("
");
+ }
+ else
+ {
+ msg.append("WARNING: There are no scheduled PMIC procedures!
");
+ }
+ }
+ //End of PMIC services alert
+
+ /**
+ * Kollil, 03/18/2021 : Housing transfer notifications Daily
+ */
+ protected void housingTransferAlert(final Container c, User u, final StringBuilder msg)
+ {
+ if (QueryService.get().getUserSchema(u, c, "onprc_ehr") == null) {
+ msg.append("Warning: The onprc_ehr schema has not been enabled in this folder, so the alert cannot run!
");
+ return;
+ }
+
+ //Daily transfers query
+ TableInfo ti = QueryService.get().getUserSchema(u, c, "onprc_ehr").getTable("housing_transfers", ContainerFilter.Type.AllFolders.create(c, u));
+ //((ContainerFilterable) ti).setContainerFilter(ContainerFilter.Type.AllFolders.create(c, u));
+ TableSelector ts = new TableSelector(ti, null, null);
+ long count = ts.getRowCount();
+
+ if (count > 0) {//transfers count
+ msg.append("
Housing Transfers:
");
+ msg.append("" + count + " animal transfers were found in last 24 hours:");
+ msg.append("Click here to view the transfers in PRIME
\n");
+ msg.append("
");
+ }
+
+ if (count == 0) {
+ msg.append("There are no animal transfers today!
");
+ }
+
+ //Display the daily report in the email
+ if (count > 0) {
+ Set columns = new HashSet<>();
+ columns.add(FieldKey.fromString("Id"));
+ columns.add(FieldKey.fromString("Indate"));
+ columns.add(FieldKey.fromString("Building"));
+ columns.add(FieldKey.fromString("Area"));
+ columns.add(FieldKey.fromString("Room"));
+ columns.add(FieldKey.fromString("Cage"));
+ columns.add(FieldKey.fromString("housingType"));
+ columns.add(FieldKey.fromString("housingCondition"));
+ columns.add(FieldKey.fromString("ReasonForMove"));
+ columns.add(FieldKey.fromString("Remark"));
+ columns.add(FieldKey.fromString("TotalAnimals"));
+ columns.add(FieldKey.fromString("ActiveClinicalTreatment"));
+ columns.add(FieldKey.fromString("ActiveDiets"));
+
+ final Map colMap = QueryService.get().getColumns(ti, columns);
+ TableSelector ts2 = new TableSelector(ti, colMap.values(), null, null);
+
+ //Legend
+ msg.append("");
+ msg.append("");
+ msg.append("| LEGEND: |
");
+ msg.append("");
+ msg.append("| Yellow row indicates animal transferred into an empty room. |
");
+ msg.append("");
+ msg.append("| Blue cell indicates animal has active Clinical treatments with no Diets. |
");
+ msg.append("");
+ msg.append("| Orange cell indicates animal has active Clinical treatments including Diets (or) just Diets. |
");
+ msg.append("
");
+ // Table header
+ msg.append("
");
+ msg.append("");
+ msg.append("| Id | In Date | Building | Area | Room | Cage | Housing Type | Housing Condition | Reason For Move | Remark | Num animals before the transfer |
");
+
+ ts2.forEach(new Selector.ForEachBlock() {
+ @Override
+ public void exec(ResultSet object) throws SQLException {
+ Results rs = new ResultsImpl(object, colMap);
+ String url = getParticipantURL(c, rs.getString("Id"));
+ int animal_count = rs.getInt("TotalAnimals");
+
+ if ( animal_count == 0) { //high light the row in yellow if the room was empty before the move
+ msg.append("");
+ if (rs.getString("ActiveClinicalTreatment") != null && rs.getString("ActiveDiets") == null)
+ { //High light with blue color if there are any active treatments
+ msg.append("| " + PageFlowUtil.filter(rs.getString("Id")) + " | \n");
+ }
+ else if (rs.getString("ActiveClinicalTreatment") != null && rs.getString("ActiveDiets") != null)
+ { //High light with orange color if there are any diets within treatments
+ msg.append(" " + PageFlowUtil.filter(rs.getString("Id")) + " | \n");
+ }
+ else {
+ msg.append(" " + PageFlowUtil.filter(rs.getString("Id")) + " | \n");
+ }
+ msg.append("" + PageFlowUtil.filter(rs.getString("InDate")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("Building")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("Area")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("Room")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("Cage")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("housingType")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("housingCondition")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("ReasonForMove")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("Remark")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getInt("TotalAnimals")) + " | ");
msg.append("
");
}
- });
- msg.append("
");
- }
- //Display the weekly report in the email
- if (count1 > 0) {
- Set columns1 = new HashSet<>();
- columns1.add(FieldKey.fromString("resourceid"));
- columns1.add(FieldKey.fromString("startdate"));
- columns1.add(FieldKey.fromString("enddate"));
- columns1.add(FieldKey.fromString("name"));
- columns1.add(FieldKey.fromString("alias"));
- columns1.add(FieldKey.fromString("quantity"));
- columns1.add(FieldKey.fromString("comments"));
- columns1.add(FieldKey.fromString("color"));
- columns1.add(FieldKey.fromString("room"));
- columns1.add(FieldKey.fromString("bldg"));
-
- final Map colMap1 = QueryService.get().getColumns(ti1, columns1);
- TableSelector ts3 = new TableSelector(ti1, colMap1.values(), null, null);
- count1 = ts3.getRowCount();
-
- if (count1 == 0) {
- msg.append("There are no scheduled PMIC events");
- }
- else {
- msg.append("
Weekly PMIC events:
\n");
- msg.append("");
- msg.append("");
- msg.append("| Resource Id | Start Date | End Date | Name | Alias | Quantity | Comments | Color | Room | Bldg |
");
-
- ts3.forEach(new Selector.ForEachBlock() {
- @Override
- public void exec(ResultSet object) throws SQLException {
- Results rs1 = new ResultsImpl(object, colMap1);
- msg.append("");
- msg.append("| " + rs1.getString("resourceid") + " | ");
- msg.append("" + rs1.getString("startdate") + " | ");
- msg.append("" + rs1.getString("enddate") + " | ");
- msg.append("" + rs1.getString("name") + " | ");
- msg.append("" + rs1.getString("alias") + " | ");
- msg.append("" + rs1.getString("quantity") + " | ");
- msg.append("" + rs1.getString("comments") + " | ");
- msg.append("" + rs1.getString("color") + " | ");
- msg.append("" + rs1.getString("room") + " | ");
- msg.append("" + rs1.getString("bldg") + " | ");
- msg.append("
");
+ else { //animal moving into non-empty room
+ if (rs.getString("ActiveClinicalTreatment") != null && rs.getString("ActiveDiets") == null)
+ { //High light with blue color if there are any active treatments
+ msg.append(" " + PageFlowUtil.filter(rs.getString("Id")) + " | \n");
+ }
+ else if (rs.getString("ActiveClinicalTreatment") != null && rs.getString("ActiveDiets") != null)
+ { //High light with orange color if there are any diets within treatments
+ msg.append(" " + PageFlowUtil.filter(rs.getString("Id")) + " | \n");
+ }
+ else {
+ msg.append(" " + PageFlowUtil.filter(rs.getString("Id")) + " | \n");
}
- });
- msg.append("
");
+ msg.append("" + PageFlowUtil.filter(rs.getString("InDate")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("Building")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("Area")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("Room")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("Cage")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("housingType")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("housingCondition")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("ReasonForMove")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getString("Remark")) + " | ");
+ msg.append("" + PageFlowUtil.filter(rs.getInt("TotalAnimals")) + " | ");
+ msg.append("
");
+ }
+
}
- }
+ });
+ msg.append("
");
}
}
- //End of PMIC alert
+ //End of housing transfer alert
/**
* we find protocols over the animal limit
diff --git a/onprc_ehr/src/org/labkey/onprc_ehr/notification/HousingTransferNotification.java b/onprc_ehr/src/org/labkey/onprc_ehr/notification/HousingTransferNotification.java
new file mode 100644
index 000000000..94d0fadcd
--- /dev/null
+++ b/onprc_ehr/src/org/labkey/onprc_ehr/notification/HousingTransferNotification.java
@@ -0,0 +1,59 @@
+package org.labkey.onprc_ehr.notification;
+
+import org.labkey.api.data.Container;
+import org.labkey.api.module.Module;
+import org.labkey.api.security.User;
+
+import java.util.Date;
+
+/**
+ * Created by Kollil on 03/18/2021
+ */
+
+public class HousingTransferNotification extends ColonyAlertsNotification
+{
+ public HousingTransferNotification(Module owner)
+ {
+ super(owner);
+ }
+
+ @Override
+ public String getName()
+ {
+ return "Housing Transfers Notification";
+ }
+
+ @Override
+ public String getEmailSubject(Container c)
+ {
+ return "Housing Transfer Alerts: " + getDateTimeFormat(c).format(new Date());
+ }
+
+ @Override
+ public String getCronString()
+ {
+ return "0 0 16 * * ?";
+ }
+
+ @Override
+ public String getScheduleDescription()
+ {
+ return "every day at 4:00PM";
+ }
+
+ @Override
+ public String getDescription()
+ {
+ return "The report is designed to send housing transfer alerts daily!";
+ }
+
+ @Override
+ public String getMessageBodyHTML(Container c, User u)
+ {
+ StringBuilder msg = new StringBuilder();
+
+ housingTransferAlert(c, u, msg);
+
+ return msg.toString();
+ }
+}
\ No newline at end of file
diff --git a/onprc_ehr/src/org/labkey/onprc_ehr/notification/PMICSchedulerNotification.java b/onprc_ehr/src/org/labkey/onprc_ehr/notification/PMICSchedulerNotification.java
new file mode 100644
index 000000000..28bedca9a
--- /dev/null
+++ b/onprc_ehr/src/org/labkey/onprc_ehr/notification/PMICSchedulerNotification.java
@@ -0,0 +1,59 @@
+package org.labkey.onprc_ehr.notification;
+
+import org.labkey.api.data.Container;
+import org.labkey.api.module.Module;
+import org.labkey.api.security.User;
+
+import java.util.Date;
+
+/**
+ * Created by kollil on 10/24/2019.
+ */
+
+public class PMICSchedulerNotification extends ColonyAlertsNotification
+{
+ public PMICSchedulerNotification(Module owner)
+ {
+ super(owner);
+ }
+
+ @Override
+ public String getName()
+ {
+ return "PMIC Scheduler Notification";
+ }
+
+ @Override
+ public String getEmailSubject(Container c)
+ {
+ return "PMIC Scheduler Alerts: " + getDateTimeFormat(c).format(new Date());
+ }
+
+ @Override
+ public String getCronString()
+ {
+ return "0 0 5 * * ?";
+ }
+
+ @Override
+ public String getScheduleDescription()
+ {
+ return "every day at 5:00AM";
+ }
+
+ @Override
+ public String getDescription()
+ {
+ return "The report is designed to send PMIC scheduler alerts daily!";
+ }
+
+ @Override
+ public String getMessageBodyHTML(Container c, User u)
+ {
+ StringBuilder msg = new StringBuilder();
+
+ pmicSchedulerAlert(c, u, msg);
+
+ return msg.toString();
+ }
+}
\ No newline at end of file
diff --git a/onprc_ehr/src/org/labkey/onprc_ehr/notification/PMICServicesRequestNotification.java b/onprc_ehr/src/org/labkey/onprc_ehr/notification/PMICServicesRequestNotification.java
new file mode 100644
index 000000000..2379003cb
--- /dev/null
+++ b/onprc_ehr/src/org/labkey/onprc_ehr/notification/PMICServicesRequestNotification.java
@@ -0,0 +1,61 @@
+package org.labkey.onprc_ehr.notification;
+
+import org.labkey.api.data.Container;
+import org.labkey.api.ehr.notification.AbstractEHRNotification;
+import org.labkey.api.module.Module;
+import org.labkey.api.security.User;
+
+import java.util.Date;
+
+/**
+ * Created by Kollil on 03/18/2021
+ */
+
+public class PMICServicesRequestNotification extends ColonyAlertsNotification
+{
+ public PMICServicesRequestNotification(Module owner)
+ {
+ super(owner);
+ }
+
+ @Override
+ public String getName()
+ {
+ return "PMIC Services Request Notification";
+ }
+
+ @Override
+ public String getEmailSubject(Container c)
+ {
+ return "PMIC Services Request Alerts: " + getDateTimeFormat(c).format(new Date());
+ }
+
+ @Override
+ public String getCronString()
+ {
+ return "0 15 7 ? * THU";
+ }
+
+ @Override
+ public String getScheduleDescription()
+ {
+ return "every Thursday at 7:15Am";
+ }
+
+ @Override
+ public String getDescription()
+ {
+ return "This runs every Thursday and sends alerts related to PMIC service requests!";
+ }
+
+ @Override
+ public String getMessageBodyHTML(Container c, User u)
+ {
+ StringBuilder msg = new StringBuilder();
+ //msg.append("This email is designed to summarize pending or scheduled requests. It was run on: " + getDateFormat(c).format(now) + " at " + AbstractEHRNotification._timeFormat.format(now) + ".");
+
+ pmicServicesRequestAlert(c, u, msg);
+
+ return msg.toString();
+ }
+}
\ No newline at end of file
diff --git a/onprc_ehr/src/org/labkey/onprc_ehr/notification/RoutineClinicalTestsNotification.java b/onprc_ehr/src/org/labkey/onprc_ehr/notification/RoutineClinicalTestsNotification.java
index db046437b..e3ccb637a 100644
--- a/onprc_ehr/src/org/labkey/onprc_ehr/notification/RoutineClinicalTestsNotification.java
+++ b/onprc_ehr/src/org/labkey/onprc_ehr/notification/RoutineClinicalTestsNotification.java
@@ -260,7 +260,8 @@ protected void getAnimalsNotWeightedInPast60Days(StringBuilder msg, Container c,
msg.append("Weights:
\n");
SimpleFilter filter = new SimpleFilter(FieldKey.fromString("calculated_status"), "Alive");
- filter.addCondition(FieldKey.fromString("Id/MostRecentWeight/DaysSinceWeight"), 45, CompareType.GT);
+ //Changed by Kollil, 5/17/21 on Drew's request from 45 to 75 days
+ filter.addCondition(FieldKey.fromString("Id/MostRecentWeight/DaysSinceWeight"), 75, CompareType.GT);
filter.addCondition(FieldKey.fromString("Id/curLocation/Room/housingType/value"), "Cage Location", CompareType.EQUAL);
TableInfo ti = getStudySchema(c, u).getTable("demographics");
@@ -272,8 +273,8 @@ protected void getAnimalsNotWeightedInPast60Days(StringBuilder msg, Container c,
if (count > 0)
{
- msg.append("WARNING: There are " + count + " animals in cage locations and have not been weighed in the past 45 days: ");
- String url = getExecuteQueryUrl(c, "study", "Demographics", "By Location") + "&query.Id/MostRecentWeight/DaysSinceWeight~gt=45&query.calculated_status~eq=Alive&query.Id/curLocation/Room/housingType/value~eq=Cage Location";
+ msg.append("WARNING: There are " + count + " animals in cage locations and have not been weighed in the past 75 days: ");
+ String url = getExecuteQueryUrl(c, "study", "Demographics", "By Location") + "&query.Id/MostRecentWeight/DaysSinceWeight~gt=75&query.calculated_status~eq=Alive&query.Id/curLocation/Room/housingType/value~eq=Cage Location";
msg.append("Click here to view them.
\n");
msg.append("Summary by area:
\n");
@@ -282,7 +283,7 @@ protected void getAnimalsNotWeightedInPast60Days(StringBuilder msg, Container c,
for (String area : areaMap.keySet())
{
String newUrl = url + "&query.Id/curLocation/area~eq=" + area;
- msg.append("
| " + area + ": | " + areaMap.get(area) + " |
\n");
+ msg.append("| " + area + ": | " + areaMap.get(area) + " |
\n");
}
msg.append("");
msg.append("
");
diff --git a/sla/resources/queries/sla/PlandProtocols.sql b/sla/resources/queries/sla/PlandProtocols.sql
index 26d5091ff..508ba6041 100644
--- a/sla/resources/queries/sla/PlandProtocols.sql
+++ b/sla/resources/queries/sla/PlandProtocols.sql
@@ -1,42 +1,87 @@
-
SELECT a.project as ProjectID,
-aa.species,
-a.account as Alias,
-y.grantNumber as OGAGrantNumber,
-a.protocol as ParentIACUC,
-a.title as Title,
-a.name as IACUCCode,
-a.startdate as StartDate,
-a.enddate as EndDate,
-i.FirstName,
-i.LastName,
-i.Division,
-p.external_id,
-i.LastName + ': ' + a.name + '('+ p.external_id +')' + ' - ' + a.title + ' (Species: ' + aa.species + ')' as PIIacuc
+ aa.species,
+ a.account as Alias,
+ y.grantNumber as OGAGrantNumber,
+ a.protocol as ParentIACUC,
+ a.title as Title,
+ a.name as IACUCCode,
+ a.startdate as StartDate,
+ a.enddate as EndDate,
+ i.FirstName,
+ i.LastName,
+ i.Division,
+ p.external_id,
+ i.LastName + ': ' + a.name + '('+ p.external_id +')' + ' Group Id & Name - ' + aa. Group_Id + ', '+ aa.Group_Name + ' - ' + a.title + ' (Species: ' + aa.species + ')' as PIIacuc
FROM Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.project a
LEFT JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.protocol p ON p.protocol = a.protocol
-LEFT JOIN onprc_ehr.investigators i ON i.rowId = a.investigatorId
-LEFT JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.sla.allowableAnimals aa ON a.protocol = aa.protocol
-LEFT JOIN Site.{substitutePath moduleProperty('ONPRC_Billing','BillingContainer_Public')}.onprc_billing_public.aliases y ON y.alias = a.account
+ LEFT JOIN onprc_ehr.investigators i ON i.rowId = a.investigatorId
+ LEFT JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.sla.allowableAnimals_BreedingGroups aa ON a.protocol = aa.protocol
+ --LEFT JOIN "/onprc/admin/finance/public".onprc_billing_public.aliases y ON y.alias = a.account
+ LEFT JOIN Site.{substitutePath moduleProperty('ONPRC_Billing','BillingContainer_Public')}.onprc_billing_public.aliases y ON y.alias = a.account
WHERE
- -- filter based on the current date compared with the start and end dates
- (
+-- filter based on the current date compared with the start and end dates
+ (
(aa.StartDate IS NOT NULL AND aa.EndDate IS NULL AND now() > aa.StartDate) OR
(aa.StartDate IS NULL AND aa.EndDate IS NOT NULL AND now() < aa.EndDate) OR
(now() between aa.StartDate AND aa.EndDate)
- )
+ )
AND
- --Check for the project enddate. Added by LK on 1/16/2019
- (now() between a.StartDate AND a.EndDate)
- -- and filtered based on dataAccess for the given user
+--Check for the project enddate. Added by LK on 1/16/2019
+ (now() between a.StartDate AND a.EndDate)
+-- and filtered based on dataAccess for the given user
AND
- (
+ (
(SELECT max(rowid) as expr FROM onprc_billing.dataAccess da
- -- current logged in user is the dataAccess user
- WHERE isMemberOf(da.userid)
- -- has access to all data
- AND (da.allData = true
- -- has access to the specified investigatorId and the specified project (if applicable)
- OR (da.investigatorId = i.rowId AND (da.project IS NULL OR da.project = a.project)))
+-- current logged in user is the dataAccess user
+ WHERE isMemberOf(da.userid)
+-- has access to all data
+ AND (da.allData = true
+-- has access to the specified investigatorId and the specified project (if applicable)
+ OR (da.investigatorId = i.rowId AND (da.project IS NULL OR da.project = a.project)))
) IS NOT NULL
- )
+ )
+
+
+
+--
+-- SELECT a.project as ProjectID,
+-- aa.species,
+-- a.account as Alias,
+-- y.grantNumber as OGAGrantNumber,
+-- a.protocol as ParentIACUC,
+-- a.title as Title,
+-- a.name as IACUCCode,
+-- a.startdate as StartDate,
+-- a.enddate as EndDate,
+-- i.FirstName,
+-- i.LastName,
+-- i.Division,
+-- p.external_id,
+-- i.LastName + ': ' + a.name + '('+ p.external_id +')' + ' - ' + a.title + ' (Species: ' + aa.species + ')' as PIIacuc
+-- FROM Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.project a
+-- LEFT JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.protocol p ON p.protocol = a.protocol
+-- LEFT JOIN onprc_ehr.investigators i ON i.rowId = a.investigatorId
+-- LEFT JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.sla.allowableAnimals aa ON a.protocol = aa.protocol
+-- LEFT JOIN Site.{substitutePath moduleProperty('ONPRC_Billing','BillingContainer_Public')}.onprc_billing_public.aliases y ON y.alias = a.account
+-- WHERE
+-- -- filter based on the current date compared with the start and end dates
+-- (
+-- (aa.StartDate IS NOT NULL AND aa.EndDate IS NULL AND now() > aa.StartDate) OR
+-- (aa.StartDate IS NULL AND aa.EndDate IS NOT NULL AND now() < aa.EndDate) OR
+-- (now() between aa.StartDate AND aa.EndDate)
+-- )
+-- AND
+-- --Check for the project enddate. Added by LK on 1/16/2019
+-- (now() between a.StartDate AND a.EndDate)
+-- -- and filtered based on dataAccess for the given user
+-- AND
+-- (
+-- (SELECT max(rowid) as expr FROM onprc_billing.dataAccess da
+-- -- current logged in user is the dataAccess user
+-- WHERE isMemberOf(da.userid)
+-- -- has access to all data
+-- AND (da.allData = true
+-- -- has access to the specified investigatorId and the specified project (if applicable)
+-- OR (da.investigatorId = i.rowId AND (da.project IS NULL OR da.project = a.project)))
+-- ) IS NOT NULL
+-- )
diff --git a/sla/resources/queries/sla/ProtocolProjectsUsage.sql b/sla/resources/queries/sla/ProtocolProjectsUsage.sql
index f7f7aab1f..8198db54c 100644
--- a/sla/resources/queries/sla/ProtocolProjectsUsage.sql
+++ b/sla/resources/queries/sla/ProtocolProjectsUsage.sql
@@ -1,143 +1,286 @@
-
-
+--SLA usage numbers including Breeding groups data
SELECT
-a.project as ProjectID,
-a.name AS Project,
-p.external_id as eIACUCNum,
-a.title as Title,
-i.LastName || ', ' || i.FirstName AS PIName,
-x.account as Alias,
-y.projectNumber as OGAProjectNumber,
-y.grantNumber as OGAGrantNumber,
-f.lastname || ', ' || f.firstName as FiscalAuthorityName,
-aa.Species,
-aa.Gender,
-aa.Strain,
-aa.Allowed AS NumAllowed,
-calc.NumUsed,
-aa.StartDate,
-aa.EndDate
+ a.project as ProjectID,
+ a.name AS Project,
+ p.external_id as eIACUCNum,
+ a.title as Title,
+ i.LastName || ', ' || i.FirstName AS PIName,
+ x.account as Alias,
+ y.projectNumber as OGAProjectNumber,
+ y.grantNumber as OGAGrantNumber,
+ f.lastname || ', ' || f.firstName as FiscalAuthorityName,
+ aa.Species,
+ aa.Gender,
+ aa.Strain,
+ aa.Allowed AS NumAllowed,
+ calc.NumUsed,
+ aa.StartDate,
+ aa.EndDate,
+ CASE
+ WHEN aa.BreedingAllowed = '1' THEN 'Yes'
+ ELSE 'No'
+ END AS BreedingAllowed,
+ aa.Group_Id,
+ aa.Group_Name
FROM Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.project a
LEFT JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.protocol p ON p.protocol = a.protocol
-LEFT JOIN onprc_ehr.investigators i ON i.rowId = a.investigatorId
-LEFT JOIN onprc_billing.fiscalAuthorities f ON f.rowid = i.financialanalyst
-LEFT JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.sla.allowableAnimals aa ON a.protocol = aa.protocol
-LEFT JOIN (select * from onprc_billing.projectAccountHistory z where (z.StartDate IS NOT NULL AND z.EndDate IS NOT NULL AND now() between z.StartDate AND z.EndDate)) x ON a.project = x.project
-LEFT JOIN Site.{substitutePath moduleProperty('ONPRC_Billing','BillingContainer_Public')}.onprc_billing_public.aliases y ON y.alias = x.account
-LEFT JOIN (
--- SELECT i.protocol,species,gender,sum(animalsreceived) AS NumUsed
--- FROM sla.purchasedetails pd, sla.purchase p
--- LEFT JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.project i ON p.project = i.project
--- WHERE p.objectid = pd.purchaseid AND animalsreceived IS NOT NULL
--- GROUP BY i.protocol,species,gender
-
---Changed by LK on 5/30 to get the accurate numused.
+ LEFT JOIN onprc_ehr.investigators i ON i.rowId = a.investigatorId
+ LEFT JOIN onprc_billing.fiscalAuthorities f ON f.rowid = i.financialanalyst
+ LEFT JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.sla.allowableAnimals_BreedingGroups aa ON a.protocol = aa.protocol
+ LEFT JOIN (select * from onprc_billing.projectAccountHistory z where (z.StartDate IS NOT NULL AND z.EndDate IS NOT NULL AND now() between z.StartDate AND z.EndDate)) x ON a.project = x.project
+ LEFT JOIN Site.{substitutePath moduleProperty('ONPRC_Billing','BillingContainer_Public')}.onprc_billing_public.aliases y ON y.alias = x.account
+ LEFT JOIN (
+ --Changed by LK on 5/30 to get the accurate numused.
--Ignore the gender when counting the usage if the approval data gender is: "Male or Female". Count both Male and Female usage.
- (SELECT i.protocol,pd.species,sum(animalsreceived) AS NumUsed
- FROM sla.purchasedetails pd, sla.purchase p, Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.project i,
- Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.sla.allowableAnimals aa1
- Where p.project = i.project AND p.objectid = pd.purchaseid
- AND aa1.protocol = i.protocol AND aa1.species = pd.species AND aa1.gender = 'Male or Female'
- AND animalsreceived IS NOT NULL
- AND (p.orderdate between aa1.StartDate AND aa1.EndDate) AND aa1.enddate > now()
- GROUP BY i.protocol, pd.species)
+ (SELECT i.protocol,pd.species,sum(animalsreceived) AS NumUsed
+ FROM sla.purchasedetails pd, sla.purchase p, Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.project i,
+ Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.sla.allowableAnimals aa1
+ Where p.project = i.project AND p.objectid = pd.purchaseid
+ AND aa1.protocol = i.protocol AND aa1.species = pd.species AND aa1.gender = 'Male or Female'
+ AND animalsreceived IS NOT NULL
+ AND (p.orderdate between aa1.StartDate AND aa1.EndDate) AND aa1.enddate > now()
+ GROUP BY i.protocol, pd.species)
-) AS calc ON a.protocol = calc.protocol
- AND (aa.species = calc.species OR (aa.species IS NULL AND calc.species IS NULL))
- --AND (aa.gender = calc.gender OR (aa.gender IS NULL AND calc.gender IS NULL))
- --AND (aa.strain = calc.strain OR (aa.strain IS NULL AND calc.strain IS NULL))
+ ) AS calc ON a.protocol = calc.protocol
+ AND (aa.species = calc.species OR (aa.species IS NULL AND calc.species IS NULL))
+ --AND (aa.gender = calc.gender OR (aa.gender IS NULL AND calc.gender IS NULL))
+ --AND (aa.strain = calc.strain OR (aa.strain IS NULL AND calc.strain IS NULL))
WHERE
- -- filter based on the current date compared with the start and end dates
- (
+-- filter based on the current date compared with the start and end dates
+ (
(aa.StartDate IS NOT NULL AND aa.EndDate IS NULL AND now() > aa.StartDate) OR
(aa.StartDate IS NULL AND aa.EndDate IS NOT NULL AND now() < aa.EndDate) OR
(aa.StartDate IS NOT NULL AND aa.EndDate IS NOT NULL AND now() between aa.StartDate AND aa.EndDate)
- AND (aa.gender = 'Male or Female')
- )
+ AND (aa.gender = 'Male or Female')
+ )
AND
- --Check for the project enddate. Added by LK on 1/16/2019
- (now() between a.StartDate AND a.EndDate)
- -- and filtered based on dataAccess for the given user
+--Check for the project enddate. Added by LK on 1/16/2019
+ (now() between a.StartDate AND a.EndDate)
+-- and filtered based on dataAccess for the given user
AND
- (
+ (
(SELECT max(rowid) as expr FROM onprc_billing.dataAccess da
- -- current logged in user is the dataAccess user
- WHERE isMemberOf(da.userid)
- -- has access to all data
- AND (da.allData = true
- -- has access to the specified investigatorId and the specified project (if applicable)
- OR (da.investigatorId = i.rowId AND (da.project IS NULL OR da.project = a.project)))
+-- current logged in user is the dataAccess user
+ WHERE isMemberOf(da.userid)
+-- has access to all data
+ AND (da.allData = true
+-- has access to the specified investigatorId and the specified project (if applicable)
+ OR (da.investigatorId = i.rowId AND (da.project IS NULL OR da.project = a.project)))
) IS NOT NULL
- )
+ )
UNION ALL
SELECT
-a.project as ProjectID,
-a.name AS Project,
-p.external_id as eIACUCNum,
-a.title as Title,
-i.LastName || ', ' || i.FirstName AS PIName,
-x.account as Alias,
-y.projectNumber as OGAProjectNumber,
-y.grantNumber as OGAGrantNumber,
-f.lastname || ', ' || f.firstName as FiscalAuthorityName,
-aa.Species,
-aa.Gender,
-aa.Strain,
-aa.Allowed AS NumAllowed,
-calc.NumUsed,
-aa.StartDate,
-aa.EndDate
+ a.project as ProjectID,
+ a.name AS Project,
+ p.external_id as eIACUCNum,
+ a.title as Title,
+ i.LastName || ', ' || i.FirstName AS PIName,
+ x.account as Alias,
+ y.projectNumber as OGAProjectNumber,
+ y.grantNumber as OGAGrantNumber,
+ f.lastname || ', ' || f.firstName as FiscalAuthorityName,
+ aa.Species,
+ aa.Gender,
+ aa.Strain,
+ aa.Allowed AS NumAllowed,
+ calc.NumUsed,
+ aa.StartDate,
+ aa.EndDate,
+ CASE
+ WHEN aa.BreedingAllowed = '1' THEN 'Yes'
+ ELSE 'No'
+ END AS BreedingAllowed,
+ aa.Group_Id,
+ aa.Group_Name
+
FROM Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.project a
LEFT JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.protocol p ON p.protocol = a.protocol
-LEFT JOIN onprc_ehr.investigators i ON i.rowId = a.investigatorId
-LEFT JOIN onprc_billing.fiscalAuthorities f ON f.rowid = i.financialanalyst
-LEFT JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.sla.allowableAnimals aa ON a.protocol = aa.protocol
-LEFT JOIN (select * from onprc_billing.projectAccountHistory z where (z.StartDate IS NOT NULL AND z.EndDate IS NOT NULL AND now() between z.StartDate AND z.EndDate)) x ON a.project = x.project
-LEFT JOIN Site.{substitutePath moduleProperty('ONPRC_Billing','BillingContainer_Public')}.onprc_billing_public.aliases y ON y.alias = x.account
-LEFT JOIN (
--- SELECT i.protocol,species,gender,sum(animalsreceived) AS NumUsed
--- FROM sla.purchasedetails pd, sla.purchase p
--- LEFT JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.project i ON p.project = i.project
--- WHERE p.objectid = pd.purchaseid AND animalsreceived IS NOT NULL
--- GROUP BY i.protocol,species,gender
-
---Changed by LK on 5/30 to get the accurate numused.
+ LEFT JOIN onprc_ehr.investigators i ON i.rowId = a.investigatorId
+ LEFT JOIN onprc_billing.fiscalAuthorities f ON f.rowid = i.financialanalyst
+ LEFT JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.sla.allowableAnimals_BreedingGroups aa ON a.protocol = aa.protocol
+ LEFT JOIN (select * from onprc_billing.projectAccountHistory z where (z.StartDate IS NOT NULL AND z.EndDate IS NOT NULL AND now() between z.StartDate AND z.EndDate)) x ON a.project = x.project
+ LEFT JOIN Site.{substitutePath moduleProperty('ONPRC_Billing','BillingContainer_Public')}.onprc_billing_public.aliases y ON y.alias = x.account
+ LEFT JOIN (
+ --Changed by LK on 5/30 to get the accurate numused.
-- Count only the usage for the "Male" or "Female" gender
- (SELECT i.protocol,pd.species,pd.gender,sum(animalsreceived) AS NumUsed
- FROM sla.purchasedetails pd, sla.purchase p, Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.project i,
- Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.sla.allowableAnimals aa1
- Where p.project = i.project AND p.objectid = pd.purchaseid
- AND aa1.protocol = i.protocol AND aa1.species = pd.species AND aa1.gender = pd.gender AND aa1.gender <> 'Male or Female'
- AND animalsreceived IS NOT NULL
- AND (p.orderdate between aa1.StartDate AND aa1.EndDate) AND aa1.enddate > now()
- GROUP BY i.protocol, pd.species, pd.gender)
+ (SELECT i.protocol,pd.species,pd.gender,sum(animalsreceived) AS NumUsed
+ FROM sla.purchasedetails pd, sla.purchase p, Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.project i,
+ Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.sla.allowableAnimals aa1
+ Where p.project = i.project AND p.objectid = pd.purchaseid
+ AND aa1.protocol = i.protocol AND aa1.species = pd.species AND aa1.gender = pd.gender AND aa1.gender <> 'Male or Female'
+ AND animalsreceived IS NOT NULL
+ AND (p.orderdate between aa1.StartDate AND aa1.EndDate) AND aa1.enddate > now()
+ GROUP BY i.protocol, pd.species, pd.gender)
-) AS calc ON a.protocol = calc.protocol
- AND (aa.species = calc.species OR (aa.species IS NULL AND calc.species IS NULL))
- AND (aa.gender = calc.gender OR (aa.gender IS NULL AND calc.gender IS NULL))
- --AND (aa.strain = calc.strain OR (aa.strain IS NULL AND calc.strain IS NULL))
+ ) AS calc ON a.protocol = calc.protocol
+ AND (aa.species = calc.species OR (aa.species IS NULL AND calc.species IS NULL))
+ AND (aa.gender = calc.gender OR (aa.gender IS NULL AND calc.gender IS NULL))
+ --AND (aa.strain = calc.strain OR (aa.strain IS NULL AND calc.strain IS NULL))
WHERE
- -- filter based on the current date compared with the start and end dates
- (
+-- filter based on the current date compared with the start and end dates
+ (
(aa.StartDate IS NOT NULL AND aa.EndDate IS NULL AND now() > aa.StartDate) OR
(aa.StartDate IS NULL AND aa.EndDate IS NOT NULL AND now() < aa.EndDate) OR
(aa.StartDate IS NOT NULL AND aa.EndDate IS NOT NULL AND now() between aa.StartDate AND aa.EndDate)
- AND (aa.gender <> 'Male or Female')
- )
+ AND (aa.gender <> 'Male or Female')
+ )
AND
- --Check for the project enddate. Added by LK on 1/16/2019
- (now() between a.StartDate AND a.EndDate)
- -- and filtered based on dataAccess for the given user
+--Check for the project enddate. Added by LK on 1/16/2019
+ (now() between a.StartDate AND a.EndDate)
+-- and filtered based on dataAccess for the given user
AND
- (
+ (
(SELECT max(rowid) as expr FROM onprc_billing.dataAccess da
- -- current logged in user is the dataAccess user
- WHERE isMemberOf(da.userid)
- -- has access to all data
- AND (da.allData = true
- -- has access to the specified investigatorId and the specified project (if applicable)
- OR (da.investigatorId = i.rowId AND (da.project IS NULL OR da.project = a.project)))
+-- current logged in user is the dataAccess user
+ WHERE isMemberOf(da.userid)
+-- has access to all data
+ AND (da.allData = true
+-- has access to the specified investigatorId and the specified project (if applicable)
+ OR (da.investigatorId = i.rowId AND (da.project IS NULL OR da.project = a.project)))
) IS NOT NULL
- )
\ No newline at end of file
+ )
+
+/*
+-- SELECT
+-- a.project as ProjectID,
+-- a.name AS Project,
+-- p.external_id as eIACUCNum,
+-- a.title as Title,
+-- i.LastName || ', ' || i.FirstName AS PIName,
+-- x.account as Alias,
+-- y.projectNumber as OGAProjectNumber,
+-- y.grantNumber as OGAGrantNumber,
+-- f.lastname || ', ' || f.firstName as FiscalAuthorityName,
+-- aa.Species,
+-- aa.Gender,
+-- aa.Strain,
+-- aa.Allowed AS NumAllowed,
+-- calc.NumUsed,
+-- aa.StartDate,
+-- aa.EndDate
+-- FROM Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.project a
+-- LEFT JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.protocol p ON p.protocol = a.protocol
+-- LEFT JOIN onprc_ehr.investigators i ON i.rowId = a.investigatorId
+-- LEFT JOIN onprc_billing.fiscalAuthorities f ON f.rowid = i.financialanalyst
+-- LEFT JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.sla.allowableAnimals aa ON a.protocol = aa.protocol
+-- LEFT JOIN (select * from onprc_billing.projectAccountHistory z where (z.StartDate IS NOT NULL AND z.EndDate IS NOT NULL AND now() between z.StartDate AND z.EndDate)) x ON a.project = x.project
+-- LEFT JOIN Site.{substitutePath moduleProperty('ONPRC_Billing','BillingContainer_Public')}.onprc_billing_public.aliases y ON y.alias = x.account
+-- LEFT JOIN (
+-- -- SELECT i.protocol,species,gender,sum(animalsreceived) AS NumUsed
+-- -- FROM sla.purchasedetails pd, sla.purchase p
+-- -- LEFT JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.project i ON p.project = i.project
+-- -- WHERE p.objectid = pd.purchaseid AND animalsreceived IS NOT NULL
+-- -- GROUP BY i.protocol,species,gender
+--
+-- --Changed by LK on 5/30 to get the accurate numused.
+-- --Ignore the gender when counting the usage if the approval data gender is: "Male or Female". Count both Male and Female usage.
+-- (SELECT i.protocol,pd.species,sum(animalsreceived) AS NumUsed
+-- FROM sla.purchasedetails pd, sla.purchase p, Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.project i,
+-- Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.sla.allowableAnimals aa1
+-- Where p.project = i.project AND p.objectid = pd.purchaseid
+-- AND aa1.protocol = i.protocol AND aa1.species = pd.species AND aa1.gender = 'Male or Female'
+-- AND animalsreceived IS NOT NULL
+-- AND (p.orderdate between aa1.StartDate AND aa1.EndDate) AND aa1.enddate > now()
+-- GROUP BY i.protocol, pd.species)
+--
+-- ) AS calc ON a.protocol = calc.protocol
+-- AND (aa.species = calc.species OR (aa.species IS NULL AND calc.species IS NULL))
+-- --AND (aa.gender = calc.gender OR (aa.gender IS NULL AND calc.gender IS NULL))
+-- --AND (aa.strain = calc.strain OR (aa.strain IS NULL AND calc.strain IS NULL))
+-- WHERE
+-- -- filter based on the current date compared with the start and end dates
+-- (
+-- (aa.StartDate IS NOT NULL AND aa.EndDate IS NULL AND now() > aa.StartDate) OR
+-- (aa.StartDate IS NULL AND aa.EndDate IS NOT NULL AND now() < aa.EndDate) OR
+-- (aa.StartDate IS NOT NULL AND aa.EndDate IS NOT NULL AND now() between aa.StartDate AND aa.EndDate)
+-- AND (aa.gender = 'Male or Female')
+-- )
+-- AND
+-- --Check for the project enddate. Added by LK on 1/16/2019
+-- (now() between a.StartDate AND a.EndDate)
+-- -- and filtered based on dataAccess for the given user
+-- AND
+-- (
+-- (SELECT max(rowid) as expr FROM onprc_billing.dataAccess da
+-- -- current logged in user is the dataAccess user
+-- WHERE isMemberOf(da.userid)
+-- -- has access to all data
+-- AND (da.allData = true
+-- -- has access to the specified investigatorId and the specified project (if applicable)
+-- OR (da.investigatorId = i.rowId AND (da.project IS NULL OR da.project = a.project)))
+-- ) IS NOT NULL
+-- )
+--
+-- UNION ALL
+--
+-- SELECT
+-- a.project as ProjectID,
+-- a.name AS Project,
+-- p.external_id as eIACUCNum,
+-- a.title as Title,
+-- i.LastName || ', ' || i.FirstName AS PIName,
+-- x.account as Alias,
+-- y.projectNumber as OGAProjectNumber,
+-- y.grantNumber as OGAGrantNumber,
+-- f.lastname || ', ' || f.firstName as FiscalAuthorityName,
+-- aa.Species,
+-- aa.Gender,
+-- aa.Strain,
+-- aa.Allowed AS NumAllowed,
+-- calc.NumUsed,
+-- aa.StartDate,
+-- aa.EndDate
+-- FROM Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.project a
+-- LEFT JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.protocol p ON p.protocol = a.protocol
+-- LEFT JOIN onprc_ehr.investigators i ON i.rowId = a.investigatorId
+-- LEFT JOIN onprc_billing.fiscalAuthorities f ON f.rowid = i.financialanalyst
+-- LEFT JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.sla.allowableAnimals aa ON a.protocol = aa.protocol
+-- LEFT JOIN (select * from onprc_billing.projectAccountHistory z where (z.StartDate IS NOT NULL AND z.EndDate IS NOT NULL AND now() between z.StartDate AND z.EndDate)) x ON a.project = x.project
+-- LEFT JOIN Site.{substitutePath moduleProperty('ONPRC_Billing','BillingContainer_Public')}.onprc_billing_public.aliases y ON y.alias = x.account
+-- LEFT JOIN (
+-- -- SELECT i.protocol,species,gender,sum(animalsreceived) AS NumUsed
+-- -- FROM sla.purchasedetails pd, sla.purchase p
+-- -- LEFT JOIN Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.project i ON p.project = i.project
+-- -- WHERE p.objectid = pd.purchaseid AND animalsreceived IS NOT NULL
+-- -- GROUP BY i.protocol,species,gender
+--
+-- --Changed by LK on 5/30 to get the accurate numused.
+-- -- Count only the usage for the "Male" or "Female" gender
+-- (SELECT i.protocol,pd.species,pd.gender,sum(animalsreceived) AS NumUsed
+-- FROM sla.purchasedetails pd, sla.purchase p, Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.ehr.project i,
+-- Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.sla.allowableAnimals aa1
+-- Where p.project = i.project AND p.objectid = pd.purchaseid
+-- AND aa1.protocol = i.protocol AND aa1.species = pd.species AND aa1.gender = pd.gender AND aa1.gender <> 'Male or Female'
+-- AND animalsreceived IS NOT NULL
+-- AND (p.orderdate between aa1.StartDate AND aa1.EndDate) AND aa1.enddate > now()
+-- GROUP BY i.protocol, pd.species, pd.gender)
+--
+-- ) AS calc ON a.protocol = calc.protocol
+-- AND (aa.species = calc.species OR (aa.species IS NULL AND calc.species IS NULL))
+-- AND (aa.gender = calc.gender OR (aa.gender IS NULL AND calc.gender IS NULL))
+-- --AND (aa.strain = calc.strain OR (aa.strain IS NULL AND calc.strain IS NULL))
+-- WHERE
+-- -- filter based on the current date compared with the start and end dates
+-- (
+-- (aa.StartDate IS NOT NULL AND aa.EndDate IS NULL AND now() > aa.StartDate) OR
+-- (aa.StartDate IS NULL AND aa.EndDate IS NOT NULL AND now() < aa.EndDate) OR
+-- (aa.StartDate IS NOT NULL AND aa.EndDate IS NOT NULL AND now() between aa.StartDate AND aa.EndDate)
+-- AND (aa.gender <> 'Male or Female')
+-- )
+-- AND
+-- --Check for the project enddate. Added by LK on 1/16/2019
+-- (now() between a.StartDate AND a.EndDate)
+-- -- and filtered based on dataAccess for the given user
+-- AND
+-- (
+-- (SELECT max(rowid) as expr FROM onprc_billing.dataAccess da
+-- -- current logged in user is the dataAccess user
+-- WHERE isMemberOf(da.userid)
+-- -- has access to all data
+-- AND (da.allData = true
+-- -- has access to the specified investigatorId and the specified project (if applicable)
+-- OR (da.investigatorId = i.rowId AND (da.project IS NULL OR da.project = a.project)))
+-- ) IS NOT NULL
+-- )
\ No newline at end of file
diff --git a/sla/resources/queries/sla/allowableAnimals.js b/sla/resources/queries/sla/allowableAnimals.js
index 8df5c7872..bc0ed9c35 100644
--- a/sla/resources/queries/sla/allowableAnimals.js
+++ b/sla/resources/queries/sla/allowableAnimals.js
@@ -1,7 +1,38 @@
+// var console = require("console");
+// var LABKEY = require("labkey");
+//
+//
+// function beforeInsert(row, errors){
+// row.objectid = row.objectid || LABKEY.Utils.generateUUID().toUpperCase();
+// }
+
var console = require("console");
var LABKEY = require("labkey");
+require("ehr/triggers").initScript(this);
+var triggerHelper = new org.labkey.onprc_ehr.query.ONPRC_EHRTriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id);
function beforeInsert(row, errors){
row.objectid = row.objectid || LABKEY.Utils.generateUUID().toUpperCase();
}
+
+//Validate dates. Kollil, 1/19/2021
+EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.BEFORE_UPSERT, 'sla', 'allowableAnimals', function(helper, scriptErrors, row, oldRow)
+{
+ var start = row.startdate;
+ var end = row.enddate;
+ //console.log ("In 1");
+
+ // Check if startdate and enddate are not empty
+ if ((start == null && end == null) || (start == null && end != null) || (start != null && end == null)) {
+ EHR.Server.Utils.addError(scriptErrors, 'startdate', 'Must enter Start and End dates', 'ERROR');
+ }
+
+ //enddate: verify enddate not prior to startdate
+ if (start != null && end != null) {
+ if (start.getTime() > end.getTime()) {
+ EHR.Server.Utils.addError(scriptErrors, 'enddate', 'End date must be after the Start date', 'ERROR');
+ }
+ }
+
+});
diff --git a/sla/resources/queries/sla/allowableAnimals_BreedingGroups.sql b/sla/resources/queries/sla/allowableAnimals_BreedingGroups.sql
new file mode 100644
index 000000000..bc203f417
--- /dev/null
+++ b/sla/resources/queries/sla/allowableAnimals_BreedingGroups.sql
@@ -0,0 +1,14 @@
+SELECT a.protocol,
+ a.species,
+ a.gender,
+ a.strain,
+ a.age,
+ a.allowed,
+ a.startdate,
+ a.enddate,
+ b.group_id,
+ b.group_name,
+ b.breeding_colony as BreedingAllowed
+FROM Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.sla.allowableAnimals a,
+ Site.{substitutePath moduleProperty('EHR','EHRStudyContainer')}.onprc_ehr.eIACUC_PRIME_VIEW_ANIMAL_GROUPS b
+Where a.protocol.displayname = b.parent_protocol
\ No newline at end of file
diff --git a/sla/resources/views/SLA_LandingPage.html b/sla/resources/views/SLA_LandingPage.html
new file mode 100644
index 000000000..466b19567
--- /dev/null
+++ b/sla/resources/views/SLA_LandingPage.html
@@ -0,0 +1,29 @@
+SLA Purchase
+SLA purchase module is for PIs and staff to initiate purchase orders for rodents. It is administered by SLAU staff to ensure quality control and compliance with applicable federal regulations and guidelines. Only authorized personnel are allowed to place rodent orders. If you need access to the module, please contact sla_services@ohsu.edu.
+Click here to go to SLA Purchase Module
+
+SLA Census
+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.
+
+Entering Animals
+
+ SLA Census - Entry Screen
+ SLA Census - Edit Previous Record Menu - Choose "All Tasks" navigational tab and click the mouse on the task id to edit a record.
+ SLA Census - Bulk Editing Grid - Allows editing more than one Census records.
+ SLA - Entry Grid for Rabbits / Guinea Pigs - Web link to enter new Rabbits and Guinea Pig records.
+
+Entering Charges
+
+ Misc Charges - Grid - This format is best for export to Excel.
+ Misc Charges - Entry Form
+ Return to "My Task/All Task" Page
+
+Reports
+
+ SLA Census - Grid
+ SLA Census - Printed Report - Center Project & Date Range required.
+ SLA Census - Summary Printed Report - Center Project & Date Range required.
+ Monthly Census - Mouse Sheets
+ Monthly Census - Rat Sheets
+ Monthly Census - Rabbit or GP Sheets
+
\ No newline at end of file
diff --git a/sla/resources/views/SLA_LandingPage.view.xml b/sla/resources/views/SLA_LandingPage.view.xml
new file mode 100644
index 000000000..297678ea8
--- /dev/null
+++ b/sla/resources/views/SLA_LandingPage.view.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/sla/resources/views/SLA_LandingPage.webpart.xml b/sla/resources/views/SLA_LandingPage.webpart.xml
new file mode 100644
index 000000000..a21b09d25
--- /dev/null
+++ b/sla/resources/views/SLA_LandingPage.webpart.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file