Skip to content

Commit

Permalink
Merge in snapshot branch
Browse files Browse the repository at this point in the history
  • Loading branch information
csebranek committed Feb 17, 2025
2 parents d8b5ec6 + d472e34 commit 3eeade9
Show file tree
Hide file tree
Showing 31 changed files with 1,323 additions and 1,007 deletions.
216 changes: 45 additions & 171 deletions WNPRC_EHR/package-lock.json

Large diffs are not rendered by default.

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>
2 changes: 1 addition & 1 deletion WNPRC_EHR/resources/views/ehrBegin.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
items: [
{name: 'Animal Utilization By Category', url: '<%=contextPath%>' + ctx['EHRStudyContainer'] + '/query-executeQuery.view?schemaName=study&query.queryName=colonyAssignmentSummary'},
{name: 'Blood Draw Summary', url: '<%=contextPath%>' + ctx['EHRStudyContainer'] + '/query-executeQuery.view?schemaName=study&query.queryName=ScheduledBlood'},
{name: 'Colony Population By Age', url: '<%=contextPath%>' + ctx['EHRStudyContainer'] + '/query-.view?schemaName=study&query.queryName=colonyPopulationByAge'},
{name: 'Colony Population By Age', url: '<%=contextPath%>' + ctx['EHRStudyContainer'] + '/query-executeQuery.view?schemaName=study&query.queryName=colonyPopulationByAge'},
{name: 'MHC Genotype Summary', url: '<%=contextPath%>' + ctx['EHRStudyContainer'] + '/query-executeQuery.view?schemaName=study&query.queryName=alleleFrequencies'},
{name: 'Population Summary', url: '<%=contextPath%>' + ctx['EHRStudyContainer'] + '/ehr-populationOverview.view'},
{name: 'Colony Census', url: '<%=contextPath%>' + ctx['EHRStudyContainer'] + '/wnprc_ehr-colonyCensus.view'},
Expand Down
Loading

0 comments on commit 3eeade9

Please sign in to comment.