Skip to content

Commit

Permalink
24.3 fb water system changes (#722)
Browse files Browse the repository at this point in the history
* Migrating changes to water system to 24.3 (#627)

* Closing water orders and breeding encounters when animal mark as dead

* Fixing problem with the watertotal info panel

* Fix problem with event label in calendar.

* Implemented accordion for the Info Panels in the calendar.

* Removing unnecesary debugger.

* Fixed the asymchronos problem with fetching waterSchedule first and waterTotal second.

* Improving performance for render calendar, limiting to only dates shown in the calendar view. Using waterTotalWithParameters.sql

* Working for entery colony need to troubleshoot for single animal or multiple animal ids.

* Fixing error with new waterTotalWithParameters when using the notification.

* Improving comments regarding the parameters used in water monitoring queries

* Removing death animals from water notification.

* adding stringify to Json array to solve problem with saving water orders.

* Remving JSON.parse

* Linking chairing date to the single animal encounter form.

* Requiring location on chairing dataset.

* Adding validation to check Daily-PM.

* Improving frequency checks for water orders. Using if statements instead of switch case.

* Adding map to remove no water orders by each date on calendar.

* Adding popup window for animal changing to Lixit.

* Adding parameter for the full history report. Bug introduce with waterTotal query.

* Defaulting StartTarget to 1947 birthdate of the oldest animal.

* Fixing tab space for WNPRC_EHRModule

* Temporary commit to add a new water button

* 23.11 fb notifications quick fix (#621)

* Added updates requested by the blood draw team.
- Blood Draws Today (All): Now sorts draws by incomplete first.  Also changed unassigned/incomplete column headers for clarity.
- Blood Draw Review Notification (Trigger): Updated this so it only sends when a blood draw is requested for the current day with an issue.
- Blood Draw Review Notification (Daily): Now shows any blood draws (today & future) that will be overdrawn.

* Removed test dates and updated to correct dates.

* Fixed test date updates.

* Removed placeholder text.

---------

Co-authored-by: aschmidt34 <124093649+aschmidt34@users.noreply.github.com>

* Fixing problem with binding JSP page

* Fixing title for death animals in Full calendar.

* Fixing problem with branchName for the gradle build process

* adding a function to remove all the future water amounts that are scheduled after the animal dies

* Fix to the water total reports in animal history, removing the wateramounts after an animal is marked as death.

* adding new js report for animal history.

* adding close function to expedite closing water orders.

* Using close water order flag to not checkwaterregulation.

* fixing function to switch to lixit animals.

* Deleting water orders that are start in the future, also deleting water amounts that are in the future when animals get switch to lixit.

* Correcting typo on WaterCalendar.jsp

* Fixing format of error message.

* Fixing incomplete water treatments view.

* Adding filter to show only regulated animals.

* adding report for water total so it does not request start and end date for the report. Adding a height for Water Grid Calendar.

* Removing file after merging husbandry reports to wnprcHusbandry.js file. Switching the reportStartDate to 1947-02-10

* Hiding watertotal from the future when a water amount or order is present.

* Removing dependency for wnprcTotalWaterReport.js.

* Fixing problem with water notification, adding parameters to query.

* Adding water source to treatment form.

* Removing on lixit from the water schedule when first order is complete it.

* Fixing problem with re-rendering inside the webpart in the animal history.

* Moving remarks to follow the order in .qview file

* Fixing problem with zero when adding lixit into the water treatment form.

* Removing not used button from DataEntryButtons.js

* Adding action required to the qview to show first lixit in calendar.

* Adding filter to obtain all water schedule in the future.

* Multiple changes to WaterCalendar.jsp to fix problems with lixit.

* Button for completing water given to have a pop up message

* Switching text to submit final

* Adding validations to the water orders, removing validation from client side for provide fruit.

* Adding Submit Water button to the Enter Water Treatment.

* Removing extra code that is no longer used.

* Closing lixit order if one is open.

* Triggerscript function to check if animal is on lixit

* Improving formatting of WaterCalendar.jsp

* fixing overlap when closing lixit.

* Removing commented code.

* fixing problem with lixit error and blank volume when adding a new water order.

* fix of water calendar not loading on production.

* fixing problem with closing water from water calendar UI and when entering a new water order.

* Fix problem with going back one month in the water calendar.

---------

Co-authored-by: aschmidt34 <124093649+aschmidt34@users.noreply.github.com>
  • Loading branch information
dnicolalde and aschmidt34 authored Jan 15, 2025
1 parent f965e78 commit f9e42c3
Show file tree
Hide file tree
Showing 25 changed files with 784 additions and 353 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ SELECT
frequencyMeaning AS frequencyMeaningCoalesced,
timeofday AS timeofday,
displaytimeofday AS displaytimeofday,
actionRequired AS actionRequired,
qcstate AS qcstate,

--(SELECT max(wg.qcstate) as label FROM study.waterGiven wg WHERE WCO.objectid = wg.treatmentid AND WCO.dateOrdered = wg.dateordered ) AS waterStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<column name="rawDate"/>
<column name="mlsPerKg"/>
<column name="conditionAtTime"/>
<column name="actionRequired"/>
<column name="qcstate" />
<column name="taskid" />
</columns>
Expand Down
27 changes: 27 additions & 0 deletions WNPRC_EHR/resources/queries/study/deaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,35 @@ function onComplete(event, errors, helper) {
var ids = helper.getRows().map(function (row) {
return row.row.id;
});
var animalDateMap= [];
let clientRows = helper.getRows();

console.log("number of rows "+ clientRows.length);
if (clientRows){

for (var i= 0; i < clientRows.length; i++){
console.log("animalId "+clientRows[i].row.id);

animalDateMap.push({
animalId: clientRows[i].row.id,
endDate : clientRows[i].row.date
});

}

}
/*console.log("array line 37 " + Object.values(animalDateMap).length);
for (var i = 0; i < animalDateMap.length; i++){
console.log("array value " + animalDateMap[i]);
}*/

WNPRC.Utils.getJavaHelper().removeWaterAmounts(animalDateMap);

//Sends notification.
var hostName = 'https://' + LABKEY.serverName;
WNPRC.Utils.getJavaHelper().sendDeathNotification(ids, hostName);



}
25 changes: 1 addition & 24 deletions WNPRC_EHR/resources/queries/study/waterGiven.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,36 +85,19 @@ function onInit(event, helper){
}

function onUpsert(helper, scriptErrors, row, oldRow) {
/*if (row.volume == null){
EHR.Server.Utils.addError(scriptErrors, 'volume', 'This field is required', 'WARN');
console.log ("value of QCState "+ row.QCState)
}*/

if (row.QCStateLabel == 'Scheduled'){
EHR.Server.Validation.verifyDate(row, scriptErrors, helper);
}

if (row.Id && row.date)
{
// volume is handled differently for requestsvs actual draws
var errorQC = 'ERROR';
//if (EHR.Server.Security.getQCStateByLabel(row.QCStateLabel)['isRequest'] && !row.taskid)
// errorQC = 'ERROR';
//else
// errorQC = 'INFO';

var map = helper.getProperty('waterInTransaction');
var waters = [];
if (map && map[row.Id])
{
waters = map[row.Id];
/*for (var i=0;i<map.length; i++ ){
console.log ('value of map '+ map[i]);
waters.push (map[i]);
console.log ("map in JS "+map[i].objectid + " " + map[i].volume);
}*/
//console.log("stablishing map "+ map);
// waters.push(map);
}
if (row.location=='laboratory'){
if (!row.restraint){
Expand All @@ -135,7 +118,7 @@ function onUpsert(helper, scriptErrors, row, oldRow) {


//TODO: Troubleshoot this function to determine if the animal has not gotten enough water for the last three days.
/*if (row.volume)
/* if (row.volume)
{
var msg = WNPRC.Utils.getJavaHelper().waterLastThreeDays(row.Id, row.date, waters);
if (msg != null){
Expand Down Expand Up @@ -164,8 +147,6 @@ function onUpsert(helper, scriptErrors, row, oldRow) {
}

}


}
console.log ('parentid '+ row.parentid + ' lsid: '+row.lsid);
if (row.id && row.date && row.performedby && row.parentid && !row.lsid){
Expand Down Expand Up @@ -195,10 +176,6 @@ function onUpsert(helper, scriptErrors, row, oldRow) {

}
}


//EHR.Server.Validation.checkRestraint(row, scriptErrors);

}
function addWaterGivenDescription(row, waters){
let clientDescription = '';
Expand Down
6 changes: 3 additions & 3 deletions WNPRC_EHR/resources/queries/study/waterGiven.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
<fkTable>husbandry_fruit</fkTable>
<fkColumnName>value</fkColumnName>
</fk>
</column>
<column columnName="remarks">

</column>
<column columnName="waterSource">
<columnTitle>Water Source</columnTitle>
Expand All @@ -59,6 +56,9 @@
<fkColumnName>value</fkColumnName>
<fkDisplayColumnName>title</fkDisplayColumnName>
</fk>
</column>
<column columnName="remarks">

</column>
<column columnName="location">
<columnTitle>Water Location</columnTitle>
Expand Down
135 changes: 87 additions & 48 deletions WNPRC_EHR/resources/queries/study/waterOrders.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ let allowUsersMap = {};
function onInit(event, helper){
helper.setScriptOptions({
allowFutureDates: true,
allowDatesInDistantPast: true
allowDatesInDistantPast: true,
skipWaterRegulationCheck: false
});
LABKEY.Query.selectRows({
requiredVersion: 9.1,
Expand Down Expand Up @@ -35,9 +36,40 @@ function onInit(event, helper){
});
}

function onInsert(helper, scriptErrors, row){
if (row.frequency !== 4 && row.waterSource === 'lixit'){
EHR.Server.Utils.addError(scriptErrors,"frequency", "Frequency should be 'Daily - Any Time' when selecting Lixit/Ad Lib", "ERROR");
}

function onUpsert(helper, scriptErrors, row, oldRow){
if (row.id && row.waterSource === 'regulated' && row.frequency && row.assignedTo && row.provideFruit && row.date){
let lixitOrderMap = WNPRC.Utils.getJavaHelper().checkWaterLixit(row.id, row.date);
let lixitStartDate;
let lixitOrderObjectid;
let latestWaterSource;

if (lixitOrderMap != null){
lixitStartDate = new Date(lixitOrderMap.date);
lixitOrderObjectid = lixitOrderMap.objectid;
latestWaterSource = lixitOrderMap.waterSource;

if(latestWaterSource === "lixit" ) {
let lixitEndDate = new Date(row.date);
console.log(lixitEndDate)
lixitEndDate.setDate(lixitEndDate.getDate()-1);
console.log("startdate " + lixitStartDate + " objectid " + lixitOrderObjectid + "enddate " + lixitEndDate + " watersource " +row.waterSource);
let jsonArray = WNPRC.Utils.getJavaHelper().closeWaterOrder(row.id, lixitStartDate, lixitEndDate, row.project, lixitOrderObjectid, true);
if (jsonArray != null) {
for (var i = 0; i < jsonArray.length; i++) {
var errorObject = jsonArray[i];
EHR.Server.Utils.addError(scriptErrors, errorObject.field, errorObject.message, errorObject.severity);
}
}
}
}
}
}

function onUpsert(helper, scriptErrors, row, oldRow){
if (row.Id){
EHR.Server.Utils.findDemographics({
participant: row.Id,
Expand All @@ -54,13 +86,9 @@ function onUpsert(helper, scriptErrors, row, oldRow){
});
var animalRestricted = {};
animalRestricted = WNPRC.Utils.getJavaHelper().checkIfAnimalInCondition(row.Id, row.date);
//console.log (animalRestricted);
if (!animalRestricted && !row.skipWaterRegulationCheck){
EHR.Server.Utils.addError(scriptErrors,'Id', 'Animal not assigned to water restriction protocol or is already in ' + row.waterSource + ' condition.', 'ERROR');
}



}


Expand All @@ -84,27 +112,31 @@ function onUpsert(helper, scriptErrors, row, oldRow){
if (rowDate.getTime() > endDate.getTime()){
EHR.Server.Utils.addError(scriptErrors,'endDate', 'EndDate cannot be before StartDate', 'ERROR');
}

if (!row.frequency && row.waterSource == 'regulated'){
if (!row.frequency && row.waterSource === 'regulated'){
EHR.Server.Utils.addError(scriptErrors, 'frequency', 'Frequency is required when entering regulated water orders.', 'ERROR');
}
if (!row.volume && row.waterSource == 'regulated'){
if (!row.volume && row.waterSource === 'regulated'){
//console.log ("water vol "+ row.volume);
EHR.Server.Utils.addError(scriptErrors, 'volume', 'Volume is required when entering regulated water orders.', 'ERROR');
}

if (!row.assignedTo && row.waterSource == 'regulated'){
if (!row.assignedTo && row.waterSource === 'regulated'){
EHR.Server.Utils.addError(scriptErrors, 'assignedTo', 'Assigned To is required when entering regulated water orders.', 'ERROR');
}

if (!row.provideFruit && row.waterSource === 'regulated'){
EHR.Server.Utils.addError(scriptErrors, 'provideFruit', 'Provide Fruit is required when entering regulated water orders.', 'INFO');
}
if (!row.waterSource){
EHR.Server.Utils.addError(scriptErrors, 'waterSource', 'Water Source is required when entering new orders.', 'ERROR');
}
if (row.volume !== undefined && row.volume!== null && row.waterSource === 'lixit'){
EHR.Server.Utils.addError(scriptErrors,"volume", "Volume should be blank when selecting Lixit/Ad Lib for Water Source", "ERROR");
}
if (row.frequency !== 4 && row.waterSource === 'lixit'){
EHR.Server.Utils.addError(scriptErrors,"frequency", "Frequency should be 'Daily - Any Time' when selecting Lixit/Ad Lib", "ERROR");
}


//console.log ("value of ObjectId "+oldRow.objectid + " Value of new objectId "+ row.objectid);
//console.log ('skipWaterRegulation '+ row.skipWaterRegulationCheck);
// if (oldRow && row.date && row.Id && row.frequency && (oldRow.objectid != row.objectid)) {
if (row.project && row.objectid && row.Id && row.date && row.frequency && row.assignedTo && row.waterSource != 'lixit' && !row.skipWaterRegulationCheck) {
if (row.project && row.objectid && row.Id && row.date && row.frequency && row.assignedTo && row.waterSource !== 'lixit' && !row.skipWaterRegulationCheck && !row.closingRecord ) {
let jsonArray = WNPRC.Utils.getJavaHelper().checkWaterRegulation(row.id, row.date, row.enddate ? row.enddate : null, row.frequency, row.waterSource, row.objectid, row.project, this.extraContext);
if (jsonArray != null) {
for (var i = 0; i < jsonArray.length; i++) {
Expand All @@ -115,35 +147,19 @@ function onUpsert(helper, scriptErrors, row, oldRow){
row.date = rowDate;
}

//if (oldRow && oldRow.waterSource == 'regulated' && row.waterSource == 'lixit'){
//TODO: by pass water regulation to change water order to lixit and also chnage the water regulated animals data
if ( row.waterSource == 'lixit' && !row.skipWaterRegulationCheck && !oldRow){

let jsonArray = WNPRC.Utils.getJavaHelper().changeWaterScheduled(row.id,row.date,row.waterSource, row.project, row.objectid,this.extraContext);
let jsonExtraContext = this.extraContext.extraContextArray;

if (jsonArray != null){
for (var i=0; i < jsonArray.length; i++){
let errorObject = JSON.parse(jsonArray[i]);
EHR.Server.Utils.addError(scriptErrors,errorObject.field, errorObject.message, errorObject.severity);

}
if (jsonExtraContext != null){
for (var i = 0; i < jsonExtraContext.length; i++){
let extraContextObject = jsonExtraContext[i];
let date = extraContextObject.date;
let dateOnly = new Date(date.getTime());
dateOnly = dateOnly.getFullYear()+ "-" +dateOnly.getMonth()+ "-" + dateOnly.getDate();
let infoMessage = "Water Order for "+ row.Id + " started on " + dateOnly + " with frequency of " + extraContextObject.frequency + " and volume of " + extraContextObject.volume + "ml will close.";
EHR.Server.Utils.addError(scriptErrors,"waterSource",infoMessage,"INFO")

}

if (row.Id && row.date && row.enddate && row.project && row.objectid && row.closingRecord){
let jsonArray = WNPRC.Utils.getJavaHelper().closeWaterOrder(row.id, row.date, row.enddate, row.project, row.objectid, row.closingRecord);
if (jsonArray != null) {
for (var i = 0; i < jsonArray.length; i++) {
var errorObject = jsonArray[i];
EHR.Server.Utils.addError(scriptErrors, errorObject.field, errorObject.message, errorObject.severity);
}

}
}

if ( row.waterSource === 'lixit' && row.volume === undefined && row.project && row.assignedTo && !row.skipWaterRegulationCheck){
changeWaterScheduled(row, scriptErrors);
}
}

function onUpdate(helper, scriptErrors, row, oldRow){
Expand Down Expand Up @@ -211,17 +227,40 @@ function onUpdate(helper, scriptErrors, row, oldRow){
}
}
}
}


if (row.id !== oldRow.id || row.date !== oldRow.date || row.volume !== oldRow.volume)
{
//EHR.Server.Utils.addError(scriptErrors,'date');

}

if ( row.waterSource === 'lixit' && row.project && row.volume === undefined && row.assignedTo && !row.skipWaterRegulationCheck){
changeWaterScheduled(row, scriptErrors);
}
}

function addErrorMessage(key,scriptErrors){
EHR.Server.Utils.addError(scriptErrors, key, 'User does not have permission to modify this field.', 'ERROR');
}

function changeWaterScheduled(row, scriptErrors){

let jsonArray = WNPRC.Utils.getJavaHelper().changeWaterScheduled(row.id,row.date,row.waterSource, row.project, row.objectid,this.extraContext);
let jsonExtraContext = this.extraContext.extraContextArray;

if (jsonArray != null){
for (var i=0; i < jsonArray.length; i++){
let errorObject = jsonArray[i];
EHR.Server.Utils.addError(scriptErrors,errorObject.field, errorObject.message, errorObject.severity);
}
if (jsonExtraContext != null){
for (var j = 0; j < jsonExtraContext.length; j++){
let extraContextObject = jsonExtraContext[j];
let date = extraContextObject.date;
let dateOnly = new Date(date.getTime());
let monthString = dateOnly.getMonth();
monthString++;

dateOnly = dateOnly.getFullYear()+ "-" + monthString + "-" + dateOnly.getDate();
let infoMessage = "Water Order for "+ row.Id + " started on " + dateOnly + " with frequency of " + extraContextObject.frequency + " and volume of " + extraContextObject.volume + "ml will close.";
EHR.Server.Utils.addError(scriptErrors,"waterSource",infoMessage,"INFO");
}
}
}

}
4 changes: 2 additions & 2 deletions WNPRC_EHR/resources/queries/study/waterSchedule.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ d.calculated_status AS calculated_status,
s.*,
s.objectid as treatmentid,
--(SELECT max(d.qcstate) as label FROM study.drug d WHERE s.objectid = d.treatmentid AND s.date = d.timeordered) as treatmentStatus,
COALESCE((SELECT max(wg.qcstate) as label FROM study.waterGiven wg WHERE wg.treatmentid LIKE '%' || s.objectid || '%' AND s.date = wg.dateordered AND wg.volume IS NOT NULL ),10) as waterStatus,
COALESCE((SELECT max(wg.qcstate) as label FROM study.waterGiven wg WHERE wg.treatmentid LIKE '%' || s.objectid || '%' AND s.date = wg.dateordered AND (wg.volume IS NOT NULL OR wg.waterSource = 'lixit') ),10) as waterStatus,
--COALESCE((SELECT max(wg.qcstate) as label FROM study.waterGiven wg WHERE s.objectid IN (wg.treatmentid) AND s.date = wg.dateordered AND wg.volume IS NOT NULL ),10) as waterStatus,
COALESCE((SELECT max(wg.treatmentid) as treatmentIds FROM study.waterGiven wg WHERE s.date = wg.dateordered AND wg.volume IS NOT NULL ),'objectId') as watertreatment
COALESCE((SELECT max(wg.treatmentid) as treatmentIds FROM study.waterGiven wg WHERE s.date = wg.dateordered AND (wg.volume IS NOT NULL OR wg.waterSource = 'lixit') ),'objectId') as watertreatment


FROM study.demographics d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<filters>
<filter column="dateOrdered" operator="dategte" value="-30d"/>
<filter column="timeofday" operator="eq" value="AM"/>
<filter column="waterSource/title" operator="eq" value="Regulated"/>
<filter column="Id/dataset/demographics/calculated_status" operator="eq" value="Alive"/>
</filters>
</customView>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<filters>
<filter column="dateOrdered" operator="dategte" value="-30d"/>
<filter column="timeofday" operator="eq" value="PM"/>
<filter column="waterSource/title" operator="eq" value="Regulated"/>
<filter column="Id/dataset/demographics/calculated_status" operator="eq" value="Alive"/>
</filters>
</customView>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
</sorts>
<filters>
<filter column="dateOrdered" operator="dategte" value="-30d"/>
<filter column="Id/dataset/demographics/calculated_status" operator="eq" value="Alive"/>
<filter column="qcstate" operator="neqornull" value="Completed"/>
<filter column="calculated_status" operator="eq" value="Alive"/>
<filter column="waterSource/title" operator="eq" value="Regulated"/>
<filter column="qcstate/label" operator="neqornull" value="Completed"/>
</filters>
</customView>
1 change: 1 addition & 0 deletions WNPRC_EHR/resources/web/wnprc_ehr/animalWaterCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ EHR.reports.animalWaterCalendar = function (panel, tab){
} else if (panel.getFilterArray(tab).nonRemovable.length === 0){
entireColony = true;
panel.resolveSubjectsFromHousing(tab,renderCalendar,this);
calendarRender++;
//renderCalendar('null', tab)
}
else{
Expand Down
Loading

0 comments on commit f9e42c3

Please sign in to comment.