Skip to content
Open
6 changes: 5 additions & 1 deletion nbri_ehr/resources/queries/ehr/activeProtocols.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
SELECT protocol, title FROM ehr.protocol pr
SELECT
pr.protocol,
pr.description,
CASE WHEN pr.investigatorId.lastName IS NULL THEN pr.displayName ELSE pr.displayName || ' - ' || pr.investigatorId.lastName END AS displayText
FROM ehr.protocol pr
WHERE pr.inactiveDate IS NULL OR pr.inactiveDate > now()
49 changes: 17 additions & 32 deletions nbri_ehr/resources/queries/ehr/project.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,70 +11,55 @@
<columns>
<column columnName="name">
<columnTitle>Project</columnTitle>
<!-- ehr.xml hides name, alwaysavailable and investigatorId; un-hide rather than drop the tag -->
<isHidden>false</isHidden>
<description>NBRI Project</description>
</column>
<column columnName="project">
<columnTitle>Project Id</columnTitle>
<isHidden>true</isHidden>
</column>
<column columnName="account">
<isHidden>true</isHidden>
</column>
<column columnName="title">
<isHidden>true</isHidden>
</column>
<column columnName="shortname">
<isHidden>true</isHidden>
</column>
<column columnName="account" />
<column columnName="title" />
<column columnName="shortname" />
<column columnName="protocol">
<columnTitle>IACUC Protocol</columnTitle>
<isHidden>true</isHidden>
<fk>
<fkDbSchema>ehr</fkDbSchema>
<fkTable>protocol</fkTable>
<fkColumnName>protocol</fkColumnName>
</fk>
</column>
<column columnName="avail">
<isHidden>true</isHidden>
</column>
<column columnName="use_category">
<isHidden>true</isHidden>
</column>
<column columnName="projectType">
<isHidden>true</isHidden>
<column columnName="avail" />
<column columnName="use_category" />
<column columnName="projectType" />
<column columnName="alwaysavailable">
<isHidden>false</isHidden>
</column>
<column columnName="investigatorId">
<isHidden>true</isHidden>
<!-- lookup needed even though the column is hidden: EHR's project field selects investigatorId/lastName -->
<isHidden>false</isHidden>
<fk>
<fkDbSchema>ehr</fkDbSchema>
<fkTable>investigators</fkTable>
<fkColumnName>rowid</fkColumnName>
<fkDisplayColumnName>lastName</fkDisplayColumnName>
</fk>
</column>
<column columnName="inves2">
<isHidden>true</isHidden>
</column>
<column columnName="qcstate">
<isHidden>true</isHidden>
</column>
<!-- inves and inves2 are the free-text predecessors of investigatorId; kept for legacy rows only -->
<column columnName="inves">
<columnTitle>Investigator</columnTitle>
<isHidden>true</isHidden>
</column>
<column columnName="reqname">
<columnTitle>Requestor Name</columnTitle>
<column columnName="inves2">
<isHidden>true</isHidden>
</column>
<column columnName="research">
<column columnName="qcstate">
<isHidden>true</isHidden>
</column>
<column columnName="contact_emails">
<isHidden>true</isHidden>
<column columnName="reqname">
<columnTitle>Requestor Name</columnTitle>
</column>
<column columnName="research" />
<column columnName="contact_emails" />
</columns>
</table>
</tables>
Expand Down
18 changes: 16 additions & 2 deletions nbri_ehr/resources/queries/ehr/project/.qview.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
<customView xmlns="http://labkey.org/data/xml/queryCustomView">
<customView xmlns="http://labkey.org/data/xml/queryCustomView" canOverride="true">
<columns>
<column name="project"/>
<column name="name"/>
<column name="displayName"/>
<column name="title"/>
<column name="shortname"/>
<column name="protocol"/>
<column name="investigatorId"/>
<column name="reqname"/>
<column name="contact_emails"/>
<column name="account"/>
<column name="avail"/>
<column name="use_category"/>
<column name="projectType"/>
<column name="research"/>
<column name="alwaysavailable"/>
<column name="startdate"/>
<column name="enddate"/>
<column name="isActive"/>
</columns>
</customView>
</customView>
8 changes: 8 additions & 0 deletions nbri_ehr/resources/queries/ehr/protocol.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
<fkDisplayColumnName>lastName</fkDisplayColumnName>
</fk>
</column>
<!-- ehr.xml hides both ibc_approval columns; un-hide rather than drop the tag -->
<column columnName="ibc_approval_required">
<isHidden>false</isHidden>
</column>
<column columnName="ibc_approval_num">
<isHidden>false</isHidden>
</column>
<!-- inves is the free-text predecessor of investigatorId; kept for legacy rows only -->
<column columnName="inves">
<isHidden>true</isHidden>
</column>
Expand Down
16 changes: 13 additions & 3 deletions nbri_ehr/resources/queries/ehr/protocol/.qview.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
<customView xmlns="http://labkey.org/data/xml/queryCustomView">
<customView xmlns="http://labkey.org/data/xml/queryCustomView" canOverride="true">
<columns>
<column name="protocol"/>
<column name="displayName"/>
<column name="title"/>
<column name="description"/>
<column name="external_id"/>
<column name="investigatorId"/>
<column name="contacts"/>
<column name="project_type"/>
<column name="usda_level"/>
<column name="ibc_approval_required"/>
<column name="ibc_approval_num"/>
<column name="maxAnimals"/>
<column name="approve"/>
<column name="endDate"/>
<column name="first_approval"/>
<column name="lastAnnualReview"/>
<column name="last_modification"/>
<column name="enddate"/>
<column name="inactiveDate"/>
<column name="exemptFood"/>
<column name="exemptHousing"/>
<column name="exemptPairing"/>
<column name="displayName"/>
</columns>
</customView>
96 changes: 96 additions & 0 deletions nbri_ehr/resources/web/nbri_ehr/data/AssignmentsClientStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,102 @@
Ext4.define('NBRI_EHR.data.AssignmentsClientStore', {
extend: 'EHR.data.DataEntryClientStore',

// Read-only columns echoing a value from the row's lookup target. Maintained here rather than from the
// combo's select event because nothing guarantees a combo: bulk add builds its rows through createModel(),
// and the parent store populates the project itself when an animal has a single active assignment.
lookupEchoes: [
{keyField: 'protocol', echoField: 'protocol/description', valueColumn: 'description'},
{keyField: 'project', echoField: 'project/account', valueColumn: 'account'}
],

constructor: function(){
this.callParent(arguments);

// One class serves both assignment sections, so keep only the pair this query actually carries
this.activeEchoes = Ext4.Array.filter(this.lookupEchoes, function(echo){
return !!this.getFields().get(echo.keyField) && !!this.getFields().get(echo.echoField);
}, this);
},

onUpdate: function(record, operation, modified){
this.callParent(arguments);

this.syncLookupEchoes(record);
},

insert: function(index, records){
// After the parent, which may set the project itself
var ret = this.callParent(arguments);

Ext4.Array.forEach(Ext4.Array.from(records), function(record){
this.syncLookupEchoes(record);
}, this);

return ret;
},

syncLookupEchoes: function(record){
// set() below re-enters this through onUpdate, and a field whose convert() rewrites the value would
// never satisfy the equality check that normally stops it, so stop on the way in instead.
if (this.syncingEchoes)
return;

this.syncingEchoes = true;
try {
Ext4.Array.forEach(this.activeEchoes, function(echo){
this.syncLookupEcho(record, echo);
}, this);
}
finally {
this.syncingEchoes = false;
}
},

syncLookupEcho: function(record, echo){
var keyValue = record.get(echo.keyField);
if (Ext4.isEmpty(keyValue)){
this.setEchoValue(record, echo.echoField, null);
return;
}

var field = this.getFields().get(echo.keyField);
if (!field || !field.lookup || !field.lookup.keyColumn)
return;

var lookupStore = Ext4.StoreMgr.get(LABKEY.ext4.Util.getLookupStoreId(field));
if (!lookupStore)
return;

// The lookup store autoLoads, so a row can arrive while it is still in flight. getCount() reads 0 both
// then and for a store that loaded nothing, and neither can resolve anything, so wait for the load
// rather than echoing the null an empty store would produce.
if (lookupStore.isLoading() || !lookupStore.getCount()){
lookupStore.on('load', function(){
this.syncLookupEcho(record, echo);
}, this, {single: true});

return;
}

// findRecord(field, value, start, anyMatch, caseSensitive, exactMatch) defaults to a prefix match,
// which would resolve one protocol id to another that merely starts with it.
var match = lookupStore.findRecord(field.lookup.keyColumn, keyValue, 0, false, false, true);

this.setEchoValue(record, echo.echoField, match ? match.get(echo.valueColumn) : null);
},

setEchoValue: function(record, fieldName, value){
// A row loaded from the server already carries the right echo, so this keeps the sync from dirtying it.
// Empty-aware because a string field with no useNull converts a set null straight back to ''.
var current = record.get(fieldName);
if (current === value || (Ext4.isEmpty(current) && Ext4.isEmpty(value)))
return;

record.suspendEvents();
record.set(fieldName, value);
record.resumeEvents();
},

getExtraContext: function(){
var rows = [];
var allRecords = this.getRange();
Expand Down
9 changes: 5 additions & 4 deletions nbri_ehr/resources/web/nbri_ehr/model/sources/Arrival.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,16 @@ EHR.model.DataModelManager.registerMetadata('Arrival', {
nullable: false,
columnConfig: {
fixed: true,
width: 150
width: 250
},
// set displayColumn: ehr.protocol's title column (displayName) is not returned by this query
lookup: {
schemaName: 'ehr',
queryName: 'activeProtocols',
keyColumn: 'protocol',
displayColumn: 'protocol',
columns: 'protocol,title'
displayColumn: 'displayText',
// description is unused here, but the lookup store is shared by display column alone, so every
// consumer must request the same columns or whichever loads first starves the others
columns: 'protocol,description,displayText'
}
},
groupId: {
Expand Down
29 changes: 24 additions & 5 deletions nbri_ehr/resources/web/nbri_ehr/model/sources/Assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@ EHR.model.DataModelManager.registerMetadata('Assignment', {
schemaName: 'ehr',
queryName: 'project',
keyColumn: 'project',
columns: 'project,name',
columns: 'project,name,account',
filterArray: [
LABKEY.Filter.create('isActive', true, LABKEY.Filter.Types.EQUAL),
]
}
},
// read-only echo of the selected project's account; NBRI_EHR.data.AssignmentsClientStore keeps it current
'project/account': {
header: 'Project Account',
label: 'Project Account',
editable: false,
columnConfig: {
editable: false,
width: 200
}
}
},
'study.protocolAssignment': {
Expand All @@ -37,15 +47,24 @@ EHR.model.DataModelManager.registerMetadata('Assignment', {
nullable: false,
columnConfig: {
fixed: true,
width: 150
width: 250
},
// set displayColumn: ehr.protocol's title column (displayName) is not returned by this query
lookup: {
schemaName: 'ehr',
queryName: 'activeProtocols',
keyColumn: 'protocol',
displayColumn: 'protocol',
columns: 'protocol,title'
displayColumn: 'displayText',
columns: 'protocol,description,displayText'
}
},
// read-only echo of the selected protocol's description; NBRI_EHR.data.AssignmentsClientStore keeps it current
'protocol/description': {
header: 'Protocol Description',
label: 'Protocol Description',
editable: false,
columnConfig: {
editable: false,
width: 300
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions nbri_ehr/resources/web/nbri_ehr/model/sources/Birth.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,16 @@ EHR.model.DataModelManager.registerMetadata('Birth', {
allowBlank: false,
nullable: false,
columnConfig: {
width: 150
width: 250
},
// set displayColumn: ehr.protocol's title column (displayName) is not returned by this query
lookup: {
schemaName: 'ehr',
queryName: 'activeProtocols',
keyColumn: 'protocol',
displayColumn: 'protocol',
columns: 'protocol,title'
displayColumn: 'displayText',
// description is unused here, but the lookup store is shared by display column alone, so every
// consumer must request the same columns or whichever loads first starves the others
columns: 'protocol,description,displayText'
}
},
groupId: {
Expand Down
9 changes: 5 additions & 4 deletions nbri_ehr/resources/web/nbri_ehr/model/sources/Rearrival.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,16 @@ EHR.model.DataModelManager.registerMetadata('Rearrival', {
nullable: false,
columnConfig: {
fixed: true,
width: 150
width: 250
},
// set displayColumn: ehr.protocol's title column (displayName) is not returned by this query
lookup: {
schemaName: 'ehr',
queryName: 'activeProtocols',
keyColumn: 'protocol',
displayColumn: 'protocol',
columns: 'protocol,title'
displayColumn: 'displayText',
// description is unused here, but the lookup store is shared by display column alone, so every
// consumer must request the same columns or whichever loads first starves the others
columns: 'protocol,description,displayText'
}
},
groupId: {
Expand Down
Loading