Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
91 changes: 30 additions & 61 deletions WNPRC_EHR/resources/queries/study/Necropsy Schedule.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@
* limitations under the License.
*/
/* This query feeds the Necropsy Schedule JSP page/calendar. */
/* Correlated subqueries rather than lookups/joins that aggregate entire datasets, so cost scales with the rows returned. */
SELECT lsid
,necropsy.taskid
,taskid
,animalid
,animalid.Demographics.gender AS sex
,animalid.age.ageFriendly AS age
,animalid.mostRecentWeight.mostRecentWeight AS weight
,CAST((SELECT ROUND(CAST(AVG(w.weight) AS DOUBLE), 2)
FROM study.weight w
WHERE w.Id = necropsy.animalid
AND w.qcstate.publicdata = TRUE
AND w.date = (SELECT MAX(w2.date)
FROM study.weight w2
WHERE w2.Id = necropsy.animalid
AND w2.qcstate.publicdata = TRUE
AND w2.weight IS NOT NULL)) AS DOUBLE) AS weight
,animalid.Demographics.medical AS medical
,animalid.curLocation.room AS cur_room
,animalid.curLocation.cage AS cur_cage
Expand All @@ -36,32 +45,24 @@ SELECT lsid
,delivery_option.title AS who_delivers
,shipping_comment AS delivery_comment
,qcstate
,animalid.Demographics.necropsyAbstractNotes.remark AS remark
,CASE
WHEN hasTissuesForAvrl IS NULL
THEN FALSE
ELSE TRUE
END AS has_tissues_for_avrl
,CASE
WHEN hasTissuesForWimr IS NULL
THEN FALSE
ELSE TRUE
END AS has_tissues_for_wimr
,CASE
WHEN hasTissuesForCcourt IS NULL
THEN FALSE
ELSE TRUE
END AS has_tissues_for_ccourt
,CASE
WHEN hasTissuesForBmq IS NULL
THEN FALSE
ELSE TRUE
END AS has_tissues_for_bmq
,CASE
WHEN hasTissuesForElements IS NULL
THEN FALSE
ELSE TRUE
END AS has_tissues_for_elements
,(SELECT GROUP_CONCAT((a.remark || ' (' || COALESCE(CAST(a.project AS VARCHAR), 'no proj.') || ')'), '; ') as x
FROM study.NecropsyAbstract a
WHERE a.Id = necropsy.animalid) AS remark
,CASE WHEN EXISTS (SELECT 1 FROM study.tissue_samples t WHERE t.taskid = necropsy.lsid
AND t.ship_to = javaConstant('org.labkey.wnprc_ehr.schemas.SqlQueryReferencePoints.COURIER_TO_AVRL'))
THEN TRUE ELSE FALSE END AS has_tissues_for_avrl
,CASE WHEN EXISTS (SELECT 1 FROM study.tissue_samples t WHERE t.taskid = necropsy.lsid
AND t.ship_to = javaConstant('org.labkey.wnprc_ehr.schemas.SqlQueryReferencePoints.COURIER_TO_WIMR'))
THEN TRUE ELSE FALSE END AS has_tissues_for_wimr
,CASE WHEN EXISTS (SELECT 1 FROM study.tissue_samples t WHERE t.taskid = necropsy.lsid
AND t.ship_to = javaConstant('org.labkey.wnprc_ehr.schemas.SqlQueryReferencePoints.COURIER_TO_CCOURT'))
THEN TRUE ELSE FALSE END AS has_tissues_for_ccourt
,CASE WHEN EXISTS (SELECT 1 FROM study.tissue_samples t WHERE t.taskid = necropsy.lsid
AND t.ship_to = javaConstant('org.labkey.wnprc_ehr.schemas.SqlQueryReferencePoints.COURIER_TO_BMQ'))
THEN TRUE ELSE FALSE END AS has_tissues_for_bmq
,CASE WHEN EXISTS (SELECT 1 FROM study.tissue_samples t WHERE t.taskid = necropsy.lsid
AND t.ship_to = javaConstant('org.labkey.wnprc_ehr.schemas.SqlQueryReferencePoints.COURIER_TO_ELEMENTS'))
THEN TRUE ELSE FALSE END AS has_tissues_for_elements
,state
FROM (SELECT taskid AS lsid
,taskid.rowid AS taskid
Expand All @@ -77,42 +78,10 @@ SELECT lsid
,shipping_comment
,location
,performedby
,qcstate.label as qcstate
,qcstate.label AS qcstate
,taskid.qcstate AS state
FROM study.necropsy
WHERE taskid IS NOT NULL) necropsy
/* Look up the display friendly name for the delivery option. */
LEFT JOIN wnprc.necropsy_delivery_options delivery_option
ON necropsy.shipping = delivery_option.key
/* Flag necropsies that have tissues that need to be couriered to AVRL. */
LEFT JOIN (SELECT taskid
,TRUE AS hasTissuesForAvrl
FROM tissue_samples
WHERE ship_to = javaConstant('org.labkey.wnprc_ehr.schemas.SqlQueryReferencePoints.COURIER_TO_AVRL') -- 'COURIER_AVRL'
GROUP BY taskid) avrl_tissues
ON necropsy.lsid = avrl_tissues.taskid
/* Flag necropsies that have tissues that need to be couriered to WIMR. */
LEFT JOIN (SELECT taskid
,TRUE AS hasTissuesForWimr
FROM tissue_samples
WHERE ship_to = javaConstant('org.labkey.wnprc_ehr.schemas.SqlQueryReferencePoints.COURIER_TO_WIMR') -- 'COURIER_WIMR'
GROUP BY taskid) wimr_tissues
ON necropsy.lsid = wimr_tissues.taskid
LEFT JOIN (SELECT taskid
,TRUE AS hasTissuesForCcourt
FROM tissue_samples
WHERE ship_to = javaConstant('org.labkey.wnprc_ehr.schemas.SqlQueryReferencePoints.COURIER_TO_CCOURT') -- 'COURIER_WIMR'
GROUP BY taskid) ccourt_tissues
ON necropsy.lsid = ccourt_tissues.taskid
LEFT JOIN (SELECT taskid
,TRUE AS hasTissuesForBmq
FROM tissue_samples
WHERE ship_to = javaConstant('org.labkey.wnprc_ehr.schemas.SqlQueryReferencePoints.COURIER_TO_BMQ') -- 'COURIER_WIMR'
GROUP BY taskid) bmq_tissues
ON necropsy.lsid = bmq_tissues.taskid
LEFT JOIN (SELECT taskid
,TRUE AS hasTissuesForElements
FROM tissue_samples
WHERE ship_to = javaConstant('org.labkey.wnprc_ehr.schemas.SqlQueryReferencePoints.COURIER_TO_ELEMENTS') -- 'COURIER_WIMR'
GROUP BY taskid) elements_tissues
ON necropsy.lsid = elements_tissues.taskid
23 changes: 0 additions & 23 deletions WNPRC_EHR/src/org/labkey/wnprc_ehr/TriggerScriptHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2616,29 +2616,6 @@ public boolean checkAnimalRequestExists(Integer rowid)
return requests.length() > 0;
}

public Boolean checkIfUserIsWaterAdmin(int userId, int project, User currentUser)
{
boolean returnCondition = false;

TableInfo waterOrdersAccess = getTableInfo("wnprc","watermonitoring_access");
SimpleFilter filter = new SimpleFilter(FieldKey.fromString("alloweduser/UserId"), userId);
filter.addCondition(FieldKey.fromString("project"), project,CompareType.EQUAL);

TableSelector userList = new TableSelector(waterOrdersAccess, PageFlowUtil.set("date", "alloweduser", "project"),filter, null);
userList.setMaxRows(1);
Map<String, Object>[] userFromServer = userList.getMapArray();

//updating and adding waters from server, objectid will take are of any duplicates

if (userFromServer.length>0){
EHRSecurityEscalator.beginEscalation(currentUser,container,"Allowing user to modify Water Orders");

returnCondition = true;

}
return returnCondition;
}

public void setAliasRow(JSONArray alias)
{
_aliasRow = alias;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,57 +351,84 @@
var necropsySuiteLookup = <%=necropsySuiteLookup%>;
WebUtils.VM.necropsySuiteLookup = necropsySuiteLookup;

// Fetch every necropsy once: a query per calendar view let rapid paging pile up concurrent DB queries.
// Reads the dataset directly for just what the calendar renders; the detail panel queries "Necropsy Schedule" on click.
var necropsyEventsPromise = null;
var loadNecropsyEvents = function() {
if (necropsyEventsPromise === null) {
necropsyEventsPromise = WebUtils.API.selectRows("study", "necropsy", {
columns: ['taskid', 'Id', 'date', 'location', 'QCState/Label'],
'taskid~isnonblank': '',
maxRows: -1
}).then(function(data) {
return data.rows.map(function(row) {
var eventObj = {
title: row.Id,
start: row.date,
startDate: new Date(row.date),
lsid: row.taskid,
display: 'block'
};

if (row.location in necropsySuiteLookup) {
eventObj.color = necropsySuiteLookup[row.location].color;
}

if (row['QCState/Label'] == "Request: On Hold"){
eventObj.color = "purple"
}

return eventObj;
});
});
necropsyEventsPromise.catch(function() {
necropsyEventsPromise = null;
});
}
return necropsyEventsPromise;
};

var selectedLsid = null;

$(document).ready(function() {
let calendarEl = document.getElementById('calendar');
calendar = new FullCalendar.Calendar(calendarEl, {
themeSystem: 'bootstrap',
height: 800,
initialView: 'dayGridMonth',
navLinks: true,
headerToolbar: {
left: 'prev,next,today',
left: 'prevYear,prev,next,nextYear today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
right: 'multiMonthYear,dayGridMonth,timeGridWeek,timeGridDay'
},
eventSources: [{
events: function (fetchInfo, callback) {
console.log(" startStr " + fetchInfo.startStr);
console.log(" endtStr " + moment(fetchInfo.startStr).format( "YYYY-MM-DD"));
events: function (fetchInfo, successCallback, failureCallback) {
loadNecropsyEvents().then(function(events) {
successCallback(events.filter(function(eventObj) {
return eventObj.startDate >= fetchInfo.start && eventObj.startDate < fetchInfo.end;
}));
}, failureCallback);
}}],
eventClick: function(calEvent, jsEvent, view) {
var lsid = calEvent.event.extendedProps.lsid;
selectedLsid = lsid;

WebUtils.API.selectRows("study", "Necropsy Schedule", {
"date~gte": moment(fetchInfo.startStr).format( "YYYY-MM-DD"),
"date~lte": moment(fetchInfo.endStr).format( "YYYY-MM-DD")
"lsid~eq": lsid
}).then(function(data) {
var events = data.rows;

callback(events.map(function(row) {
var eventObj = {
title: row.animalid,
start: row.date,
rawRowData: row,
display: 'block'
};

if (row.location in necropsySuiteLookup) {
eventObj.color = necropsySuiteLookup[row.location].color;
}
debugger;

if (row.qcstate == "Request: On Hold"){
eventObj.color = "purple"
}
if (selectedLsid !== lsid || data.rows.length === 0) {
return;
}

return eventObj;
}))
})
}}],
eventClick: function(calEvent, jsEvent, view) {
jQuery.each(calEvent.event.extendedProps.rawRowData, function(key, value) {
if (key in WebUtils.VM.taskDetails) {
if (key == "date") {
value = displayDate(value);
jQuery.each(data.rows[0], function(key, value) {
if (key in WebUtils.VM.taskDetails) {
if (key == "date") {
value = displayDate(value);
}
WebUtils.VM.taskDetails[key](value);
}
WebUtils.VM.taskDetails[key](value);
}
});
});
}
},);
Expand Down Expand Up @@ -721,6 +748,7 @@
]);
}).then(function() {
// Refresh the calendar view.
necropsyEventsPromise = null;
calendar.refetchEvents();

WebUtils.VM.pendingRequestTable.rows.remove(WebUtils.VM.requestRowInForm);
Expand Down
2 changes: 0 additions & 2 deletions wnprc_billing/resources/queries/ehr_billing/chargeRates.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ function onInit(event, helper){
var chargeCategoryId = row["chargeCategoryId"]["value"];
var chargeCategoryAssoc = chargeGroupName + ", " + chargeCategoryId;
groupCategoryAssociations[chargeCategoryAssoc] = chargeCategoryAssoc;

console.log("groupCategoryAssociations[chargeCategoryAssoc] = " + groupCategoryAssociations[chargeCategoryAssoc]);
}
},
failure: function (error) {
Expand Down
Loading