Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!--Report title-->
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="AlopeciaScoreMissingBehaviorCases" tableDbType="TABLE">
<tableTitle>Animals with alopecia score 4 or 5 with missing behavior cases</tableTitle>
</table>
</tables>
</metadata>
</query>
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ Show 1 year data.

Modified by Kollil 09/15/2025
Added date comparison to check only dates and ignore time

Modified by Kollil July 2026
Showing only 1 month data, Refer to tkt # 14974
*/
SELECT
mr.Id,
d.species,
d.gender,
CASE
WHEN LOWER(d.gender) = 'f' THEN 'Female'
WHEN LOWER(d.gender) = 'm' THEN 'Male'
ELSE d.gender
END AS gender,
d.Id.age.ageinYearsRounded,
d.Id.curLocation.area,
d.Id.curLocation.room,
Expand All @@ -22,14 +29,14 @@ FROM (
FROM study.clinical_observations AS co
WHERE
co.category = 'Alopecia Score'
AND co.created >= TIMESTAMPADD(SQL_TSI_YEAR, -1, NOW())
AND co.created >= TIMESTAMPADD(SQL_TSI_MONTH, -1, NOW())
AND co.created = (
SELECT MAX(co2.created)
FROM study.clinical_observations AS co2
WHERE
co2.Id = co.Id
AND co2.category = 'Alopecia Score'
AND co2.created >= TIMESTAMPADD(SQL_TSI_YEAR, -1, NOW())
AND co2.created >= TIMESTAMPADD(SQL_TSI_MONTH, -1, NOW())
)
) AS mr
INNER JOIN study.demographics AS d ON mr.Id = d.Id
Expand All @@ -43,8 +50,6 @@ WHERE
c.Id = mr.Id
AND c.category = 'Behavior'
AND c.allProblemCategories = 'Behavioral: Alopecia'
-- AND c.date <= mr.date
-- AND (c.enddate IS NULL OR c.enddate > mr.date)
AND CAST(c.date AS DATE) <= CAST(mr.date AS DATE)
AND (c.enddate IS NULL OR CAST(c.enddate AS DATE) >= CAST(mr.date AS DATE))
)
Original file line number Diff line number Diff line change
Expand Up @@ -351,31 +351,30 @@ private void assignmentsReleasedInPast1Day(final Container c, User u, final Stri
final Map<FieldKey, ColumnInfo> colMap = QueryService.get().getColumns(ti, columns);
TableSelector ts2 = new TableSelector(ti, colMap.values(), null, new Sort("Id"));

// msg.append("<hr><b>Assignments with new \"Release date\" added within the last 24hrs:</b><br><br>\n");
msg.append("<table border=1 style='border-collapse: collapse;'>");
msg.append("<table border=1 style='border-collapse: collapse; border: 1px solid black;'>");
msg.append("<tr bgcolor = " + '"' + "#FFD700" + '"' + "style='font-weight: bold;'>");
msg.append("<td>Id </td><td>Sex </td><td>Room </td><td>Cage </td><td>Project </td><td>Protocol </td><td>Title </td><td>Project Investigator </td><td>Assign Date </td><td>Release Date </td><td>Projected Release Date </td><td>Assignment Type </td><td>Assign Condition </td><td>Projected Release Condition </td><td>Condition At Release </td></tr>");

ts2.forEach(object -> {
Results rs = new ResultsImpl(object, colMap);
String url = getParticipantURL(c, rs.getString("Id"));

msg.append("<tr bgcolor = " + '"' + "#FFFACD" + '"' + ">");
msg.append("<td><b> <a href='" + url + "'>" + PageFlowUtil.filter(rs.getString("Id")) + "</a> </b></td>\n");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("Sex")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("Room")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("Cage")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("project")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("Protocol")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("Title")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("ProjectInvestigator")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("AssignDate")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("ReleaseDate")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("ProjectedReleaseDate")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("assignmentType")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("assignCondition")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("projectedReleaseCondition")) + "</td>");
msg.append("<td>" + PageFlowUtil.filter(rs.getString("ConditionAtRelease")) + "</td>");
msg.append("<tr>");
msg.append("<td style='border: 1px solid black;'><b> <a href='" + url + "'>" + PageFlowUtil.filter(rs.getString("Id")) + "</a> </b></td>\n");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("Sex")) + "</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("Room")) + "</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("Cage")) + "</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("project")) + "</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("Protocol")) + "</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("Title")) + "</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("ProjectInvestigator")) + "</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("AssignDate")) + "</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("ReleaseDate")) + "</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("ProjectedReleaseDate")) + "</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("assignmentType")) + "</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("assignCondition")) + "</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("projectedReleaseCondition")) + "</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("ConditionAtRelease")) + "</td>");
msg.append("</tr>");
});
msg.append("</table><br><hr>");
Expand All @@ -394,17 +393,62 @@ private void AlopeciaScoreAlert(final Container c, User u, final StringBuilder m
TableInfo ti = getStudySchema(c, u).getTable("AlopeciaScoreMissingBehaviorCases");

TableSelector ts = new TableSelector(ti, null, null);
long total = ts.getRowCount();
msg.append("<b>Animals with alopecia score of 4 or 5, but does not have an open behavioral case for alopecia:</b><p>");
if (total > 0)
{
msg.append( total + " entries found. ");
msg.append("<a href='" + getExecuteQueryUrl(c, "study", "AlopeciaScoreMissingBehaviorCases", null) + "'>Click here to view them</a>\n");
msg.append("<hr>\n\n");
long count = ts.getRowCount();

//Get num of rows
if (count > 0) {
msg.append("<b>Animals with alopecia score of 4 or 5, but does not have an open behavioral case for alopecia:</b><p>");
msg.append( count + " entries found. ");
msg.append("<a href='" + getExecuteQueryUrl(c, "study", "AlopeciaScoreMissingBehaviorCases", null) + "'>Click here to view them in a separate window</a>\n");
msg.append("\n\n");

//Changes made byKolli, July 2026, Refer to tkt # 14974
//Display the daily report in the email
Set<FieldKey> columns = new HashSet<>();
columns.add(FieldKey.fromString("Id"));
columns.add(FieldKey.fromString("species"));
columns.add(FieldKey.fromString("gender"));
columns.add(FieldKey.fromString("ageinYearsRounded"));
columns.add(FieldKey.fromString("area"));
columns.add(FieldKey.fromString("room"));
columns.add(FieldKey.fromString("cage"));
columns.add(FieldKey.fromString("MostRecentAlopeciaScore"));
columns.add(FieldKey.fromString("date"));
columns.add(FieldKey.fromString("performedby"));

final Map<FieldKey, ColumnInfo> colMap = QueryService.get().getColumns(ti, columns);
TableSelector ts2 = new TableSelector(ti, colMap.values(), null, new Sort("Id"));

msg.append("<table border=1 style='border-collapse: collapse; border: 1px solid black;'>");
msg.append("<tr bgcolor = " + '"' + "#FFD700" + '"' + "style='font-weight: bold;'>");
msg.append("<td>Id </td><td>Species </td><td>Sex </td><td>Age(Years, Rounded) </td><td>Area </td><td>Room </td><td>Cage </td><td>Most Recent Alopecia Score </td><td>Date </td><td>Performed By </td></tr>");

ts2.forEach(object -> {
Results rs = new ResultsImpl(object, colMap);
String url = getParticipantURL(c, rs.getString("Id"));

msg.append("<tr>");
msg.append("<td style='border: 1px solid black;'><b> <a href='" + url + "'>" + PageFlowUtil.filter(rs.getString("Id")) + "</a> </b></td>\n");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("Species")) + "</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("gender")) + "</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("ageinYearsRounded")) + "</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("area")) + "</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("room")) + "</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("cage")) + "</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("MostRecentAlopeciaScore")) + "</td>");
java.sql.Date date = rs.getDate("date");
msg.append("<td style='border: 1px solid black;'>")
.append(PageFlowUtil.filter(
date == null ? "" : new java.text.SimpleDateFormat("MM/dd/yyyy").format(date)
))
.append("</td>");
msg.append("<td style='border: 1px solid black;'>" + PageFlowUtil.filter(rs.getString("performedby")) + "</td>");
msg.append("</tr>");
});
msg.append("</table><br><hr>");
}
else
{
msg.append("<b>WARNING: No animals found with alopecia score of 4 or 5, but does not have an open behavioral case for alopecia!</b><br><hr>\n");
else {
msg.append("<b>WARNING: No animals found with alopecia score of 4 or 5, there fore no open behavioral case(s) for alopecia!</b><br><hr>\n");
}
}

Expand Down