Skip to content

Commit

Permalink
Merge 23.3 to 23.7
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-teamcity committed Dec 22, 2023
2 parents ad88453 + 903c953 commit 9e08d5a
Show file tree
Hide file tree
Showing 43 changed files with 1,987 additions and 631 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<customView xmlns="http://labkey.org/data/xml/queryCustomView">
<columns>
<column name="Id">
<properties>
<property name="columnTitle" value="ID"/>
</properties>
</column>
</columns>
<sorts>
<sort column="date" descending="true"/>
</sorts>
</customView>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<customView xmlns="http://labkey.org/data/xml/queryCustomView">
<columns>
<column name="Id">
<properties>
<property name="columnTitle" value="ID"/>
</properties>
</column>
<column name="caseno">
<properties>
<property name="columnTitle" value="Necropsy Case Number"/>
</properties>
</column>
<column name="taskid">
<properties>
<property name="columnTitle" value="Task ID"/>
</properties>
</column>
<column name="date">
<properties>
<property name="columnTitle" value="Date of Necropsy"/>
</properties>
</column>
<column name="timeofdeath">
<properties>
<property name="columnTitle" value="Time of Death"/>
</properties>
</column>
<column name="causeofdeath">
<properties>
<property name="columnTitle" value="Type of Death"/>
</properties>
</column>
<column name="project">
<properties>
<property name="columnTitle" value="Project"/>
</properties>
</column>
<column name="mannerofdeath">
<properties>
<property name="columnTitle" value="Manner of Death"/>
</properties>
</column>
</columns>
</customView>
23 changes: 23 additions & 0 deletions WNPRC_EHR/resources/queries/study/deaths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

//This is REQUIRED to make the script functions (onInit, onComplete, etc.) work.
require("ehr/triggers").initScript(this);

//Sets up class variables.
EHR.Server.Utils = require("ehr/utils").EHR.Server.Utils;
var WNPRC = require("wnprc_ehr/WNPRC").WNPRC;
var LABKEY = require("labkey");
var console = require("console");

//This is called when the death record is officially submitted.
function onComplete(event, errors, helper) {
console.log("deaths.js: ONCOMPLETE (correct version)");

//Gets ID's.
var ids = helper.getRows().map(function (row) {
return row.row.id;
});

//Sends notification.
var hostName = 'https://' + LABKEY.serverName;
WNPRC.Utils.getJavaHelper().sendDeathNotification(ids, hostName);
}
138 changes: 21 additions & 117 deletions WNPRC_EHR/resources/queries/study/prenatal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/

//This is REQUIRED to make the script functions (onInit, onComplete, etc.) work.
require("ehr/triggers").initScript(this);
EHR.Server.Utils = require("ehr/utils").EHR.Server.Utils;

//Sets up class variables.
EHR.Server.Utils = require("ehr/utils").EHR.Server.Utils;
var WNPRC = require("wnprc_ehr/WNPRC").WNPRC;
var LABKEY = require("labkey");
var console = require("console");

//This (onInit) is called whenever there are changes made to fields in the 'Enter Prenatal Deaths' page.
function onInit(event, helper){
helper.setScriptOptions({
allowDeadIds: true,
Expand Down Expand Up @@ -41,6 +46,8 @@ function setDescription(row, helper){
return description;
}

//TODO: Decide if we should keep this function.
//Checks the 'study' > 'Prenatal Deaths' query to see if this animal exists already.
function hasAnimalNotificationBeenSent(animalID) {
var retValue = 0;
LABKEY.Query.selectRows({
Expand All @@ -61,6 +68,9 @@ function hasAnimalNotificationBeenSent(animalID) {
});
return retValue;
}

//TODO: Decide if we should keep this function.
//Updates the 'study' > 'Prenatal Deaths' query with this animal ID.
function addNotificationIndicator(animalID) {
var updObj = {Id:animalID};
LABKEY.Query.selectRows({
Expand Down Expand Up @@ -96,122 +106,16 @@ function addNotificationIndicator(animalID) {
});
}

//This is called when the prenatal death record is officially submitted.
function onComplete(event, errors, helper){
if (helper.getPublicParticipantsModified().length) {
var valuesMap = {};
var r;

//Support for multiple prenatals
for (var i=0; i < helper.getRows().length; i++) {
r = helper.getRows()[i];
if (hasAnimalNotificationBeenSent(r.row.Id) && !helper.getExtraContext().resendEmail) {
continue;
}
else {
valuesMap[r.row.Id] = {};
valuesMap[r.row.Id].death = r.row.date;
valuesMap[r.row.Id].animalNumber = r.row.Id;
valuesMap[r.row.Id].notified = 0;
valuesMap[r.row.Id].dam = r.row.dam;
valuesMap[r.row.Id].conception = r.row.conception;
valuesMap[r.row.Id].gender = WNPRC.Utils.lookupGender(r.row.gender);
valuesMap[r.row.Id].sire = r.row.sire;

valuesMap[r.row.Id].manner = r.row.manner;
valuesMap[r.row.Id].cause = r.row.cause;
valuesMap[r.row.Id].necropsy = r.row.necropsy;

var aDate = new Date(valuesMap[r.row.Id].death.toGMTString());
var monthString = EHR.Server.Utils.getMonthString(aDate.getMonth());
var minStr = aDate.getMinutes() >= 10 ? aDate.getMinutes() : '0' + aDate.getMinutes();
valuesMap[r.row.Id].deathDate = aDate.getDate() + ' ' + monthString + ' ' + aDate.getFullYear();
valuesMap[r.row.Id].deathTime = aDate.getHours() + ':' + minStr;
console.log("prenatal.js: ONCOMPLETE (correct version)");

//Get necropsy-specific information
LABKEY.Query.selectRows({
schemaName: 'study',
queryName: 'necropsy',
filterArray: [
LABKEY.Filter.create('Id', r.row.Id, LABKEY.Filter.Types.EQUAL)
],
scope: this,
success: function(data) {
if (data && data.rows.length) {
var nDate= data.rows[0].date;
aDate = new Date(nDate);
monthString = EHR.Server.Utils.getMonthString(aDate.getMonth());
valuesMap[r.row.Id].necropsyDate = aDate.getDate() + ' ' + monthString + ' ' + aDate.getFullYear();
if (valuesMap[r.row.Id].grant == undefined) {
valuesMap[r.row.Id].grant = data.rows[0].account;
}
valuesMap[r.row.Id].necropsy = data.rows[0].caseno;
}
}
});

//Get weight for animal
LABKEY.Query.selectRows({
schemaName: 'study',
queryName: 'Weight',
filterArray: [
LABKEY.Filter.create('Id', r.row.Id, LABKEY.Filter.Types.EQUAL)
],
scope: this,
success: function(data) {
if (data.rows && data.rows.length) {
var wRow = data.rows[0];
valuesMap[r.row.Id].weight = wRow.weight;
}
}
});
}
}
var theMsg = new String();
var count = 0;
for (var k in valuesMap) {
var obj = valuesMap[k];
if (obj.notified) {
continue;
}
else {
count++;
theMsg += "Necropsy Number: " + obj.necropsy + "<br>";
theMsg += "Necropsy Date : " + obj.necropsyDate + "<br>";
theMsg += "Animal Number : " + obj.animalNumber + "<br>";
theMsg += "Dam: " + obj.dam + "<br>";
theMsg += "Weight: " + obj.weight + " kg <br>";
theMsg += "Sex: " + obj.gender + "<br>";
theMsg += "Date of Death: " + obj.deathDate + "<br>";
theMsg += "Time of Death: " + obj.deathTime + "<br>";
theMsg += "Death: " + obj.cause + "<br>";
theMsg += "Grant #: " + obj.grant + "<br>";
if (obj.cause == 'Clinical') {
theMsg += "Animal Replacement Fee: " + "No Animal replacement fee to be paid (clinical death) <br>";
}
theMsg += "Manner of Death: " + obj.manner + "<br><br>";

addNotificationIndicator(obj.animalNumber);
}
}

var openingLine;
if (count > 1) {
openingLine = 'The following animals have been marked as dead:<br><br>';
}
else if (count == 1 ) {
openingLine = 'The following animal has been marked as dead:<br><br>';
}

if (count > 0) {
EHR.Server.Utils.sendEmail({
notificationType: 'Prenatal Death',
msgContent: openingLine + theMsg +
helper.getPublicParticipantsModified().join(',<br>') +
'<p></p><a href="'+LABKEY.ActionURL.getBaseURL()+'ehr' + LABKEY.ActionURL.getContainer() + '/animalHistory.view#inputType:multiSubject&subjects:'+helper.getPublicParticipantsModified().join(';')+'&activeReport:abstract' +
'">Click here to view them</a>.',

msgSubject: 'Prenatal Death Notification'
});
}
}
//Notification revamp method.
//Gets ID's.
var ids = helper.getRows().map(function (row) {
return row.row.id;
});
//Sends notification.
var hostName = 'https://' + LABKEY.serverName;
WNPRC.Utils.getJavaHelper().sendDeathNotification(ids, hostName);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<customView xmlns="http://labkey.org/data/xml/queryCustomView">
<columns>
<column name="last_four">
<properties>
<property name="columnTitle" value="ID Last Four"/>
</properties>
</column>
<column name="sire">
<properties>
<property name="columnTitle" value="Sire"/>
</properties>
</column>
<column name="dam">
<properties>
<property name="columnTitle" value="Dam"/>
</properties>
</column>
<column name="frequency">
<properties>
<property name="columnTitle" value="Frequency"/>
</properties>
</column>
<column name="species">
<properties>
<property name="columnTitle" value="Species"/>
</properties>
</column>
</columns>
<sorts>
<sort column="last_four" descending="false"/>
</sorts>
</customView>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<customView xmlns="http://labkey.org/data/xml/queryCustomView">
<columns>
<column name="last_four">
<properties>
<property name="columnTitle" value="ID Last Four"/>
</properties>
</column>
<column name="sire">
<properties>
<property name="columnTitle" value="Sire"/>
</properties>
</column>
<column name="dam">
<properties>
<property name="columnTitle" value="Dam"/>
</properties>
</column>
<column name="id">
<properties>
<property name="columnTitle" value="ID"/>
</properties>
</column>
<column name="frequency">
<properties>
<property name="columnTitle" value="Frequency"/>
</properties>
</column>
<column name="species">
<properties>
<property name="columnTitle" value="Species"/>
</properties>
</column>
</columns>
<sorts>
<sort column="last_four" descending="false"/>
</sorts>
</customView>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<customView xmlns="http://labkey.org/data/xml/queryCustomView">
<columns>
<column name="last_four">
<properties>
<property name="columnTitle" value="ID Last Four"/>
</properties>
</column>
<column name="id">
<properties>
<property name="columnTitle" value="ID"/>
</properties>
</column>
<column name="species">
<properties>
<property name="columnTitle" value="Species"/>
</properties>
</column>
</columns>
<sorts>
<sort column="last_four" descending="false"/>
</sorts>
</customView>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<customView xmlns="http://labkey.org/data/xml/queryCustomView">
<columns>
<column name="last_four">
<properties>
<property name="columnTitle" value="ID Last Four"/>
</properties>
</column>
<column name="sire">
<properties>
<property name="columnTitle" value="Sire"/>
</properties>
</column>
<column name="dam">
<properties>
<property name="columnTitle" value="Dam"/>
</properties>
</column>
<column name="id">
<properties>
<property name="columnTitle" value="ID"/>
</properties>
</column>
<column name="frequency">
<properties>
<property name="columnTitle" value="Frequency"/>
</properties>
</column>
<column name="species">
<properties>
<property name="columnTitle" value="Species"/>
</properties>
</column>
</columns>
<sorts>
<sort column="last_four" descending="false"/>
</sorts>
</customView>
Loading

0 comments on commit 9e08d5a

Please sign in to comment.