diff --git a/onprc_billing/resources/queries/onprc_billing/leaseFees.sql b/onprc_billing/resources/queries/onprc_billing/leaseFees.sql index bb5c09ce8..f427f4157 100644 --- a/onprc_billing/resources/queries/onprc_billing/leaseFees.sql +++ b/onprc_billing/resources/queries/onprc_billing/leaseFees.sql @@ -56,8 +56,7 @@ When a5.id is not Null then (Select c.rowid from Site.{substitutePath moduleProperty('ONPRC_Billing','BillingContainer')}.onprc_billing.chargeableItems c where c.itemCode = 'ONR41') When (a4.id is not null and (TIMESTAMPDIFF('SQL_TSI_Day',a.date,a.projectedRelease)) <=14 and a.endDate is null and a.ageAtTime.AgeAtTimeYearsRounded < 1) then (Select c.rowid from Site.{substitutePath moduleProperty('ONPRC_Billing','BillingContainer')}.onprc_billing.chargeableItems c where c.itemCode = 'ONR44') - WHEN (a.duration <= CAST(javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.DAY_LEASE_MAX_DURATION') as INTEGER) AND a.enddate IS NOT NULL AND a.assignCondition = a.releaseCondition) THEN (SELECT rowid FROM onprc_billing_public.chargeableItems ci WHERE ci.active = true AND ci.name = javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.DAY_LEASE_NAME')) - WHEN (a.duration <= CAST(javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.DAY_LEASE_MAX_DURATION') as INTEGER) AND a.enddate IS NOT NULL AND a.assignCondition = a.releaseCondition) THEN (SELECT rowid FROM onprc_billing_public.chargeableItems ci WHERE ci.active = true AND ci.name = javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.DAY_LEASE_NAME')) + WHEN (a.duration <= CAST(javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.DAY_LEASE_MAX_DURATION') as INTEGER) AND a.enddate IS NOT NULL AND a.assignCondition = a.releaseCondition) THEN (SELECT rowid FROM onprc_billing_public.chargeableItems ci WHERE ci.active = true AND ci.name = javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.DAY_LEASE_NAME')) WHEN a2.id IS NOT NULL THEN (SELECT rowid FROM onprc_billing_public.chargeableItems ci WHERE (ci.startDate <= a.date and ci.endDate >= a.date) AND ci.name = javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.TMB_LEASE_NAME')) ELSE lf.chargeId END as chargeId, @@ -81,7 +80,8 @@ CASE where b.id = a.id and a1.project.protocol = a2.project.protocol) > 0 THEN 0 WHEN (a.duration = 0 AND a.enddate IS NOT NULL AND a.assignCondition = a.releaseCondition) THEN 1 - WHEN (fl.id Is Not Null) THEN 0 + -- Exempt PI-purchased NHPs from lease fees + WHEN (fl.id IS NOT NULL) THEN 0 --This will check for infants born to resource moms and will not charge WHEN (a.duration <= CAST(javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.DAY_LEASE_MAX_DURATION') as INTEGER) AND a.enddate IS NOT NULL AND a.assignCondition = a.releaseCondition) THEN a.duration @@ -139,21 +139,20 @@ LEFT JOIN onprc_billing.leaseFeeDefinition lf ON ( AND lf.active = true ) - - ---adds the reasearch owned animal exemption -LEFT JOIN study.flags fl on - (a.id = fl.id - and fl.flag.code = 4034 - and (a.date >= fl.date and a.date <=COALESCE(fl.enddate,Now()) )) - +-- Add PI-purchased NHP flag data +LEFT JOIN study.flags fl + ON (a.id = fl.id + AND fl.flag.code = 4034 + AND a.date BETWEEN CAST(fl.date AS DATE) AND COALESCE(fl.enddate, now()) + ) WHERE CAST(a.datefinalized AS DATE) >= CAST(STARTDATE as DATE) AND CAST(a.datefinalized AS DATE) <= CAST(ENDDATE as DATE) AND a.qcstate.publicdata = true --and a.participantID.demographics.species.common not in ('Rabbit','Guinea Pigs') ---add setup fees for all starts, except day leases aznd sla +-- Add lease setup fees for all lease starts, except day leases, PI-purchased NHPs, and sla UNION ALL + SELECT a.id, a.date, @@ -168,7 +167,7 @@ SELECT ' ' as ESPFAnimal, 'Lease Setup Fees' as category, (SELECT rowid FROM onprc_billing_public.chargeableItems ci WHERE ci.active = true AND ci.name = javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.LEASE_SETUP_FEES')) as chargeId, - 1 as quantity, + 1 AS quantity, cast(null as integer) as leaseCharge1, cast(null as integer) as leaseCharge2, a.objectid as sourceRecord, @@ -179,11 +178,19 @@ SELECT FROM study.assignment a +-- Add PI-purchased NHP flag data +LEFT JOIN study.flags fl + ON (a.id = fl.id + AND fl.flag.code = 4034 + AND a.date BETWEEN CAST(fl.date AS DATE) AND COALESCE(fl.enddate, now()) + ) + WHERE CAST(a.datefinalized AS DATE) >= CAST(STARTDATE as DATE) AND CAST(a.datefinalized AS DATE) <= CAST(ENDDATE as DATE) AND a.qcstate.publicdata = true --only charge setup fee for leases >24H. note: duration assumes today as end, so exclude null enddates AND ((a.duration > CAST(javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.DAY_LEASE_MAX_DURATION') as INTEGER)) OR ( a.assignCondition != a.releaseCondition AND a.enddate IS NULL)) and a.id.demographics.species Not IN ('Rabbit','Guinea Pigs') +AND fl.id IS NULL -- Exempt PI-purchased NHPs from lease setup fees --add released animals that need adjustments UNION ALL @@ -208,9 +215,9 @@ a5.id as ESPFAnimal, --////This selectes the charge ID to be used (SELECT max(rowid) as rowid FROM onprc_billing_public.chargeableItems ci WHERE ci.name = javaConstant('org.labkey.onprc_billing.ONPRC_BillingManager.LEASE_FEE_ADJUSTMENT') and ci.active = true) as chargeId, CASE - when (fl.id Is Not Null) then 0 - else 1 - end as quantity, + WHEN (fl.id IS NOT NULL) THEN 0 -- Exempt PI-purchased NHPs from lease fees + ELSE 1 +END AS quantity, lf2.chargeId as leaseCharge1, lf.chargeId as leaseCharge2, a.objectid as sourceRecord, @@ -248,11 +255,12 @@ LEFT join assignment_U42ESPF a5 on and a5.dateonly <=a.dateOnly AND a5.endDateCoalesced >= a.dateOnly) ---adds the reasearch owned animal exemption -LEFT JOIN study.flags fl on - (a.id = fl.id - and fl.flag.code = 4034 - and (a.date >= fl.date and a.date <=COALESCE(fl.enddate,Now()) )) +-- Add PI-purchased NHP flag data +LEFT JOIN study.flags fl + ON (a.id = fl.id + AND fl.flag.code = 4034 + AND a.date BETWEEN CAST(fl.date AS DATE) AND COALESCE(fl.enddate, now()) + ) WHERE a.releaseCondition != a.projectedReleaseCondition and (A.id != A5.id or A5.id is Null) diff --git a/onprc_ehr/resources/queries/onprc_ehr/ChemistryPanicNotification.sql b/onprc_ehr/resources/queries/onprc_ehr/ChemistryPanicNotification.sql new file mode 100644 index 000000000..dfd49abd0 --- /dev/null +++ b/onprc_ehr/resources/queries/onprc_ehr/ChemistryPanicNotification.sql @@ -0,0 +1,20 @@ +select a.Id, + a.date, + a.servicerequested, + b.testid, + b.qualresult, + a.vet, + a.created, + b.objectid, + b.runid, + (select j.rowid from ehr.tasks j where j.taskid = a.taskid) as taskid, + a.type + + +from study.ClinpathRuns a, study.chemistryResults b +Where a.objectid = b.runid + And a.type = 'biochemistry' + And b.qualresult like '%alert%' + + And a.qcstate = 18 + And b.qcstate = 18 \ No newline at end of file diff --git a/onprc_ehr/resources/queries/onprc_ehr/ChemistryPanicNotification.xml b/onprc_ehr/resources/queries/onprc_ehr/ChemistryPanicNotification.xml new file mode 100644 index 000000000..45e370226 --- /dev/null +++ b/onprc_ehr/resources/queries/onprc_ehr/ChemistryPanicNotification.xml @@ -0,0 +1,14 @@ + + + + + + + user ID + true + + +
+
+
+
diff --git a/onprc_ehr/resources/queries/study/Demographics/BCS Score.qview.xml b/onprc_ehr/resources/queries/study/Demographics/BCS Score.qview.xml new file mode 100644 index 000000000..5e77609ba --- /dev/null +++ b/onprc_ehr/resources/queries/study/Demographics/BCS Score.qview.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/onprc_ehr/resources/scripts/onprc_ehr/onprc_triggers.js b/onprc_ehr/resources/scripts/onprc_ehr/onprc_triggers.js index 1532b529a..d382b863b 100644 --- a/onprc_ehr/resources/scripts/onprc_ehr/onprc_triggers.js +++ b/onprc_ehr/resources/scripts/onprc_ehr/onprc_triggers.js @@ -1378,6 +1378,17 @@ exports.init = function(EHR){ }); }); + // Added: 10-6-2025 + EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.AFTER_UPSERT, 'study', 'chemistryResults', function (helper, scriptErrors, row, oldRow) { + + + if (row.Id && row.qualresult && row.qualresult.indexOf('alert') !== -1) { + + console.log("alert values: " + row.qualresult); + triggerHelper.sendClinpathPanicEmail(row.Id, row.runid, row.objectid); + } + }); + //Added: 10-4-2022 R.Blasa EHR.Server.TriggerManager.registerHandler(EHR.Server.TriggerManager.Events.COMPLETE, function(event, errors, helper){ // Send notifications when requests approved diff --git a/onprc_ehr/src/org/labkey/onprc_ehr/query/ONPRC_EHRTriggerHelper.java b/onprc_ehr/src/org/labkey/onprc_ehr/query/ONPRC_EHRTriggerHelper.java index e31c4b42c..af711cba9 100644 --- a/onprc_ehr/src/org/labkey/onprc_ehr/query/ONPRC_EHRTriggerHelper.java +++ b/onprc_ehr/src/org/labkey/onprc_ehr/query/ONPRC_EHRTriggerHelper.java @@ -55,6 +55,9 @@ import org.labkey.api.query.QueryService; import org.labkey.api.query.QueryUpdateServiceException; import org.labkey.api.query.UserSchema; +import org.labkey.api.security.Group; +import org.labkey.api.security.MemberType; +import org.labkey.api.security.SecurityManager; import org.labkey.api.security.User; import org.labkey.api.security.UserManager; import org.labkey.api.security.UserPrincipal; @@ -64,6 +67,7 @@ import org.labkey.api.util.MailHelper; import org.labkey.api.util.PageFlowUtil; import org.labkey.api.util.Pair; +import org.labkey.api.util.logging.LogHelper; import org.labkey.onprc_ehr.ONPRC_EHRManager; import org.labkey.onprc_ehr.ONPRC_EHRModule; import org.labkey.onprc_ehr.ONPRC_EHRSchema; @@ -71,6 +75,7 @@ import org.labkey.onprc_ehr.notification.MensesTMBNotification; import org.labkey.onprc_ehr.notification.ProjectAlertsNotification; import org.labkey.onprc_ehr.notification.ProtocolAlertsNotification; +import org.labkey.api.util.DateUtil; import java.sql.ResultSet; import java.sql.SQLException; @@ -100,7 +105,7 @@ */ public class ONPRC_EHRTriggerHelper { - private static final Logger _log = LogManager.getLogger(ONPRC_EHRTriggerHelper.class); + private static final Logger _log = LogHelper.getLogger(ONPRC_EHRTriggerHelper.class, "Fill in description"); private static final String NONRESTRICTED = "Nonrestricted"; private static final String EXPERIMENTAL_EUTHANASIA = "EUTHANASIA, EXPERIMENTAL"; private static final String NON_EXPERIMENTAL_EUTHANASIA = "EUTHANASIA, NONEXPERIMENTAL"; @@ -2601,7 +2606,6 @@ public void updateArrivalrecords(String id, Date date) throws Exception keys.add(FieldKey.fromString("lsid")); final Map colMap = QueryService.get().getColumns(ti, keys); - final List> toUpdate = new ArrayList<>(); final List> oldKeys = new ArrayList<>(); TableSelector ts = new TableSelector(ti, colMap.values(), new SimpleFilter(FieldKey.fromString("Id"), id, CompareType.IN), null); @@ -2634,7 +2638,153 @@ public void exec(ResultSet object) throws SQLException } } + public void sendClinpathPanicEmail(String id, String runid, String objectid) + { + String subject = "Chemistry Results with alert values"; + + Container c = getContainer(); + + + final TableInfo ti = getTableInfo("onprc_ehr", "ChemistryPanicNotification"); + SimpleFilter filter = new SimpleFilter(FieldKey.fromString("Id"), id, CompareType.EQUAL); + filter.addCondition(FieldKey.fromString("runid"), runid, CompareType.EQUAL); + filter.addCondition(FieldKey.fromString("objectid"), objectid, CompareType.EQUAL); + + + List names= new ArrayList<>(); + FieldKey clinpathFieldKey = FieldKey.fromString("runid"); + names.add(clinpathFieldKey); + names.add(FieldKey.fromString("qualResult")); + names.add(FieldKey.fromString("servicerequested")); + names.add(FieldKey.fromString("testid")); + names.add(FieldKey.fromString("date")); + names.add(FieldKey.fromString("Id")); + names.add(FieldKey.fromString("vet")); + names.add(FieldKey.fromString("taskid")); + + + final Map colKeys = QueryService.get().getColumns(ti, names); + final ColumnInfo clinpathColumn = colKeys.get(clinpathFieldKey); + TableSelector ts = new TableSelector(ti, colKeys.values(), filter, null); + + final StringBuilder html = new StringBuilder(); + + + if (ts.getRowCount() == 0) + { + html.append("There are no Chemistry Alert Values to display"); + + return; + } + else + { + + html.append(""); + html.append("\n"); + ts.forEach(new Selector.ForEachBlock() + { + + @Override + public void exec(ResultSet rs) throws SQLException + { + + String recDate = DateUtil.formatDate(c, rs.getDate("date")); + + TableInfo ti2 = getTableInfo("onprc_ehr", "Labwork_Requestor_Vets"); + SimpleFilter filter2 = new SimpleFilter(FieldKey.fromString("userid"), rs.getString("vet")); + filter2.addCondition(FieldKey.fromString("DisableDate"), true, CompareType.ISBLANK); + + + TableSelector ts2 = new TableSelector(ti2, PageFlowUtil.set("LastName"), filter2, null); + List ret2 = ts2.getArrayList(String.class); + if (!ret2.isEmpty()) + { + for (String Vetname : ret2) + { + + html.append("\n"); + break; + + } + } + + } + + } + + ); + + } + + + final TableInfo tt = getTableInfo("study", "clinpathRuns"); + SimpleFilter filtert = new SimpleFilter(FieldKey.fromString("objectid"), runid, CompareType.EQUAL); + filter.addCondition(FieldKey.fromString("id"), id, CompareType.EQUAL); + + TableSelector tst = new TableSelector(ti, PageFlowUtil.set("vet"), filter, null); + tst.forEach(new Selector.ForEachBlock<>() + { + @Override + public void exec(ResultSet rs) throws SQLException + { + Integer vetId = rs.getInt("vet"); + Set recipients = getRecipients(vetId); + if (recipients.isEmpty()) + { + _log.warn("No recipients, unable to send EHR trigger script email"); + return; + } + else + { + html.append("
Animal IDDateService Requested Panel Test Name Qual ResultsTask ID Vet/PI Name
" + PageFlowUtil.filter(rs.getString("Id")) + + "" + PageFlowUtil.filter(recDate) + + "" + PageFlowUtil.filter(rs.getString("servicerequested")) + + " " + PageFlowUtil.filter(rs.getString("testid")) + + " " + PageFlowUtil.filter(rs.getString("qualResult")) + + " " + PageFlowUtil.filter(rs.getString("taskid")) + + "" + PageFlowUtil.filter(Vetname) + "
\n"); + + sendMessage(subject, html.toString(), recipients); + + } + + } + + + }); + + + } + + + private Set getRecipients(Integer... userIds) + { + Set recipients = new HashSet<>(); + for (Integer userId : userIds) + { + if (userId > 0) + { + UserPrincipal up = SecurityManager.getPrincipal(userId); + if (up != null) + { + if (up instanceof User) + { + recipients.add(up); + } + else + { + for (UserPrincipal u : SecurityManager.getAllGroupMembers((Group)up, MemberType.ACTIVE_USERS)) + { + if (u.isActive()) + recipients.add(u); + } + } + } + } + } + return recipients; + } //Added 9-30-2025 public String retrieveGeographic_Origin(String Id) diff --git a/onprc_ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_RestrictedIssueTest.java b/onprc_ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_RestrictedIssueTest.java index 7689b7356..05a537821 100644 --- a/onprc_ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_RestrictedIssueTest.java +++ b/onprc_ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_RestrictedIssueTest.java @@ -293,13 +293,16 @@ public void restrictedIssueSearchTest() // verify that we can return links even if the user doesn't have permission to view a restricted issue Assert.assertTrue("Number of search results not expected", resultsPage.getResults().size() == 2); - // verify assigned to users will see both results but shouldn't be able to see details of issues not assigned to them + // verify assigned to users will see both results but shouldn't be able to see details of issues not assigned to them, + // also verify that there is a warning rendered if a search result is restricted impersonate(USER1.getEmail()); + assertTextPresent("Restricted Issue: You do not have access. Contact your administrator for access."); verifyIssueAccess(ISSUE_1, true); verifyIssueAccess(ISSUE_2, false); stopImpersonating(false); impersonate(USER2.getEmail()); + assertTextPresent("Restricted Issue: You do not have access. Contact your administrator for access."); verifyIssueAccess(ISSUE_1, false); verifyIssueAccess(ISSUE_2, true); stopImpersonating();