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
27 changes: 26 additions & 1 deletion nbri_ehr/resources/queries/ehr_lookups/buildings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ var LABKEY = require("labkey");

var triggerHelper = new org.labkey.nbri_ehr.query.NBRI_EHRTriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id);

// Width of ehr_lookups.buildings.name. The description it is derived from is a wider column, so it can overrun the
// key; reject it here rather than letting the database raise an unreadable error.
var MAX_NAME_LENGTH = 100;

// 'name' is not user editable, so it is absent from the incoming row map and the value this script derives has
// nowhere to land. Declaring it managed reserves a slot so the derived key is persisted.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too clear on what this comment means

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm doing a round of comment cleanup in my next PR.

function managedColumns() {
return {
insert: ["name"],
update: ["name"],
};
}

function onUpsert(row, oldRow, errors){
if (extraContext.dataSource != "etl") {
if (!row.description) {
Expand All @@ -25,7 +38,19 @@ function onUpsert(row, oldRow, errors){
return;
}

row.name = row.description + '-' + row.area;
if (row.description.length > MAX_NAME_LENGTH) {
errors['description'] = 'Description is too long: it becomes the building key, which cannot exceed ' + MAX_NAME_LENGTH + ' characters.';
return;
}

// The description alone identifies the building now that the area is no longer folded in, so a duplicate
// would collide on the key. Say so here instead of surfacing a constraint violation on a hidden column.
if (triggerHelper.totalRecords("ehr_lookups", "buildings", "name", row.description) > 0) {
errors['description'] = 'A building described as ' + row.description + ' already exists. Building descriptions must be unique.';
return;
}

row.name = row.description;
}
}
}
Expand Down
24 changes: 22 additions & 2 deletions nbri_ehr/resources/queries/ehr_lookups/cage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ var LABKEY = require("labkey");

var triggerHelper = new org.labkey.nbri_ehr.query.NBRI_EHRTriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id);

// Width of ehr_lookups.cage.location. The derived key builds on the room key, which is itself derived, so it can
// overrun the column; reject it here rather than letting the database raise an unreadable error.
var MAX_LOCATION_LENGTH = 100;

// 'location' is not user editable, so it is absent from the incoming row map and the value this script
// derives has nowhere to land. Declaring it managed reserves a slot so the derived key is persisted.
function managedColumns() {
return {
insert: ["location"],
update: ["location"],
};
}

function onUpsert(row, oldRow, errors){
if (extraContext.dataSource != "etl") {
if (!row.location) {
Expand All @@ -20,9 +33,16 @@ function onUpsert(row, oldRow, errors){
return;
}

row.location = row.room;
let location = row.room;
if (row.cage)
row.location += '-' + row.cage;
location += '-' + row.cage;

if (location.length > MAX_LOCATION_LENGTH) {
errors['cage'] = 'Room and cage are too long: they combine to a ' + location.length + ' character location key, which cannot exceed ' + MAX_LOCATION_LENGTH + '.';
return;
}

row.location = location;
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions nbri_ehr/resources/queries/ehr_lookups/cage.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
</column>
<column columnName="room">
<columnTitle>Room</columnTitle>
<fk>
<fkDbSchema>ehr_lookups</fkDbSchema>
<fkTable>rooms</fkTable>
<fkColumnName>room</fkColumnName>
</fk>
</column>
<column columnName="location">
<isHidden>true</isHidden>
Expand Down
25 changes: 22 additions & 3 deletions nbri_ehr/resources/queries/ehr_lookups/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,28 @@ var console = require("console");

var triggerHelper = new org.labkey.nbri_ehr.query.NBRI_EHRTriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id);

// Width of ehr_lookups.rooms.room. The derived key is built from values the user supplies, so it can overrun the
// column; reject it here rather than letting the database raise an unreadable error.
var MAX_ROOM_LENGTH = 100;

// 'room' is not user editable, so it is absent from the incoming row map and the value this script derives has
// nowhere to land. Declaring it managed reserves a slot so the derived key is persisted.
function managedColumns() {
return {
insert: ["room"],
update: ["room"],
};
}

function onUpsert(row, oldRow, errors){
if (extraContext.dataSource != "etl") {
if (!row.name) {
errors['name'] = 'Room name is required.';
return;
}

if (!row.floor) {
errors['floor'] = 'Floor is required.';
if (!row.building) {
errors['building'] = 'Building is required.';
return;
}

Expand All @@ -26,7 +39,13 @@ function onUpsert(row, oldRow, errors){
return;
}

row.room = row.name + '-' + row.floor;
let room = row.building + '-' + row.name;
if (room.length > MAX_ROOM_LENGTH) {
errors['name'] = 'Building and room name are too long: they combine to a ' + room.length + ' character room key, which cannot exceed ' + MAX_ROOM_LENGTH + '.';
return;
}

row.room = room;
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion nbri_ehr/resources/queries/ehr_lookups/rooms.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
<tableTitle>Rooms</tableTitle>
<columns>
<column columnName="name" />
<column columnName="floor" />
<column columnName="building" />
<column columnName="room">
<!-- Carried onto any lookup that displays this column, so room/room links the same way cage/room does. -->
<url>/nbri_ehr/cageDetails.view?room=${room}</url>
<isHidden>true</isHidden>
<shownInInsertView>false</shownInInsertView>
<shownInUpdateView>false</shownInUpdateView>
Expand All @@ -17,6 +19,14 @@
<shownInInsertView>false</shownInInsertView>
<shownInUpdateView>false</shownInUpdateView>
</column>
<!-- A room is keyed by its building, so floor no longer carries anything. Kept out of every view
rather than dropped, since existing rooms still hold a value. -->
<column columnName="floor">
<isHidden>true</isHidden>
<shownInInsertView>false</shownInInsertView>
<shownInUpdateView>false</shownInUpdateView>
<shownInDetailsView>false</shownInDetailsView>
</column>
</columns>
</table>
</tables>
Expand Down
2 changes: 1 addition & 1 deletion nbri_ehr/resources/queries/ehr_lookups/rooms/.qview.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<customView xmlns="http://labkey.org/data/xml/queryCustomView">
<columns>
<column name="name"/>
<column name="floor"/>
<column name="building"/>
</columns>
</customView>
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<fkDbSchema>ehr_lookups</fkDbSchema>
<fkTable>rooms</fkTable>
<fkColumnName>room</fkColumnName>
<fkDisplayColumnName>name</fkDisplayColumnName>
<fkDisplayColumnName>room</fkDisplayColumnName>
</fk>
</column>
<column columnName="SiteFloor">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<columns>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="performedby"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<columns>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="performedby"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<column name="caseHistory"/>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="reviewdate"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<column name="caseHistory"/>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="reviewdate"/>
Expand Down
2 changes: 1 addition & 1 deletion nbri_ehr/resources/queries/study/alopecia/.qview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<columns>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="score"/>
Expand Down
2 changes: 1 addition & 1 deletion nbri_ehr/resources/queries/study/behaviorCases/.qview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<column name="caseHistory"/>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="reviewdate"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<columns>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="category"/>
Expand Down
2 changes: 1 addition & 1 deletion nbri_ehr/resources/queries/study/blood/.qview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<columns>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="quantity"/>
Expand Down
2 changes: 1 addition & 1 deletion nbri_ehr/resources/queries/study/breeder/.qview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<columns>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="type"/>
Expand Down
2 changes: 1 addition & 1 deletion nbri_ehr/resources/queries/study/cases/.qview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<column name="caseCheck"/>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="reviewdate"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<column name="caseHistory"/>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="reviewdate"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<column name="caseHistory"/>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="Id/activeProjectAssignments/project"/>
<column name="Id/activeProtocolAssignments/protocolDisplayName">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<column name="caseHistory"/>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="reviewdate"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<column name="caseHistory"/>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="Id/activeProjectAssignments/project"/>
<column name="Id/activeProtocolAssignments/protocolDisplayName">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<columns>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="type"/>
Expand Down
2 changes: 1 addition & 1 deletion nbri_ehr/resources/queries/study/clinicalCases/.qview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<column name="caseHistory"/>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="reviewdate"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<columns>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="area"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<columns>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="category"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<columns>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="category"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<columns>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="category"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<columns>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="category"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<columns>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="category"/>
Expand Down
2 changes: 1 addition & 1 deletion nbri_ehr/resources/queries/study/clinremarks/.qview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<columns>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="performedby"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<columns>
<column name="Id"/>
<column name="Id/Demographics/species"/>
<column name="Id/curLocation/cage/room/floor/building"/>
<column name="Id/curLocation/cage/room/building"/>
<column name="Id/curLocation/cage"/>
<column name="date"/>
<column name="performedby"/>
Expand Down
Loading