From ae434a7790b6910b09f4e717caa8a368777f00b1 Mon Sep 17 00:00:00 2001 From: Trey Chadick Date: Wed, 18 Nov 2026 11:05:01 -0800 Subject: [PATCH 1/3] GH Issue 1793: Keep EHR forms from overwriting fields being edited (#1243) - Form updates no longer overwrite a field while focus is anywhere inside it, including the date and time parts of a date-time field --- ehr/resources/web/ehr/plugin/DataBind.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ehr/resources/web/ehr/plugin/DataBind.js b/ehr/resources/web/ehr/plugin/DataBind.js index e26417244..53a83a5de 100644 --- a/ehr/resources/web/ehr/plugin/DataBind.js +++ b/ehr/resources/web/ehr/plugin/DataBind.js @@ -145,7 +145,7 @@ Ext4.define('EHR.plugin.Databind', { for (var fieldName in record.data){ field = form.findField(fieldName); if (field && !field.isEqual(record.data[fieldName], field.getValue())){ - if (!field.hasFocus){ + if (!this.isBeingEdited(field)){ this.setFormField(fieldName, record.data[fieldName]); } } @@ -155,6 +155,15 @@ Ext4.define('EHR.plugin.Databind', { } }, + // Composite fields (e.g. xdatetime) never get hasFocus themselves; only their inner inputs do. + isBeingEdited: function(field){ + if (field.hasFocus) + return true; + + var el = field.getEl(); + return !!el && el.dom.contains(document.activeElement); + }, + bindRecord: function(record){ var form = this.panel.getForm(); if (form.getRecord()){ From c68192c328ce0dd6546e5a74034639641547d1e5 Mon Sep 17 00:00:00 2001 From: Binal Patel Date: Fri, 20 Nov 2026 11:11:32 -0700 Subject: [PATCH 2/3] Widen Animal History Search By Protocol window to show full protocol names (#1249) --- ehr/resources/web/ehr/panel/MultiAnimalFilterType.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ehr/resources/web/ehr/panel/MultiAnimalFilterType.js b/ehr/resources/web/ehr/panel/MultiAnimalFilterType.js index 2f25c0d05..9875efba6 100644 --- a/ehr/resources/web/ehr/panel/MultiAnimalFilterType.js +++ b/ehr/resources/web/ehr/panel/MultiAnimalFilterType.js @@ -118,6 +118,7 @@ Ext4.define('EHR.panel.MultiAnimalFilterType', { xtype: 'ehr-projectfield', itemId: 'project', style: 'margin: 5px 5px 0 5px', + width: 450, onlyIncludeProjectsWithAssignments: true }); } @@ -127,6 +128,9 @@ Ext4.define('EHR.panel.MultiAnimalFilterType', { xtype: 'ehr-protocolfield', itemId: 'protocol', style: 'margin: 5px', + width: 450, + matchFieldWidth: false, + listConfig: { minWidth: 450 }, onlyIncludeProtocolsWithAssignments: true }); } From 321d4c8c35e2a44d80afd6a1b76f8a8409d9c1cd Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Sun, 22 Nov 2026 14:41:45 -0700 Subject: [PATCH 3/3] Add shared project and protocol at time lookup columns (#1248) ## Rationale Gives EHR center modules a shared way to show which projects and protocols an animal was assigned to on each dataset record's date, alongside the existing Housing At Time column. Protocol comes from the protocol assignment dataset rather than the project's protocol, so it suits centers that assign the two independently. Each center opts in from its own table customizer, so modules that don't call it are unaffected. ## Related Pull Requests None. ## Changes - New Project At Time and Protocol At Time columns that look up `ehr.project` and `ehr.protocol` and can hold several values per record. - Assignments match by full timestamp with an exclusive end date, like Housing At Time, so a record on a transfer day shows whichever assignment was active at that moment. --- .../ehr/table/AssignmentAtTimeColumns.java | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 ehr/api-src/org/labkey/api/ehr/table/AssignmentAtTimeColumns.java diff --git a/ehr/api-src/org/labkey/api/ehr/table/AssignmentAtTimeColumns.java b/ehr/api-src/org/labkey/api/ehr/table/AssignmentAtTimeColumns.java new file mode 100644 index 000000000..d11de29cb --- /dev/null +++ b/ehr/api-src/org/labkey/api/ehr/table/AssignmentAtTimeColumns.java @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2026 LabKey Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.labkey.api.ehr.table; + +import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.labkey.api.data.AbstractTableInfo; +import org.labkey.api.collections.CaseInsensitiveHashSet; +import org.labkey.api.data.BaseColumnInfo; +import org.labkey.api.data.ColumnInfo; +import org.labkey.api.data.MultiValuedForeignKey; +import org.labkey.api.data.TableInfo; +import org.labkey.api.data.WrappedColumn; +import org.labkey.api.query.LookupForeignKey; +import org.labkey.api.query.QueryDefinition; +import org.labkey.api.query.QueryException; +import org.labkey.api.query.QueryService; +import org.labkey.api.query.UserSchema; +import org.labkey.api.util.logging.LogHelper; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +/** + * Multi-valued lookups to the projects (study.assignment) and protocols (study.protocolAssignment) an animal held on + * each record's date. The protocol comes from protocolAssignment, not assignment.project.protocol, for centers that + * assign the two independently. + */ +public final class AssignmentAtTimeColumns +{ + private static final Logger LOG = LogHelper.getLogger(AssignmentAtTimeColumns.class, "Project and protocol at time lookup columns"); + + public enum AtTimeColumn + { + PROJECT("projectAtTime", "Project At Time", "assignment", "project"), + PROTOCOL("protocolAtTime", "Protocol At Time", "protocolAssignment", "protocol"); + + private final String _name; + private final String _label; + private final String _sourceDataset; + private final String _valueCol; + + AtTimeColumn(String name, String label, String sourceDataset, String valueCol) + { + _name = name; + _label = label; + _sourceDataset = sourceDataset; + _valueCol = valueCol; + } + } + + private AssignmentAtTimeColumns() + { + } + + public static void addAtTimeCols(@NotNull AbstractTableInfo ds, @NotNull UserSchema ehrStudySchema, @NotNull AtTimeColumn... cols) + { + if (ds.getColumn("Id") == null || ds.getColumn("date") == null || !"study".equalsIgnoreCase(ds.getPublicSchemaName())) + return; + + UserSchema targetSchema = ds.getUserSchema(); + if ("demographics".equalsIgnoreCase(ds.getName()) || ds.getPkColumns().size() != 1 || targetSchema == null) + return; + + Set ehrStudyTables = null; + for (AtTimeColumn col : cols) + { + if (ds.getColumn(col._name, false) != null || col._sourceDataset.equalsIgnoreCase(ds.getName())) + continue; + + if (ehrStudyTables == null) + ehrStudyTables = new CaseInsensitiveHashSet(ehrStudySchema.getTableNames()); + + if (ehrStudyTables.contains(col._sourceDataset)) + addAtTimeLookupCol(ds, targetSchema, ehrStudySchema, col); + } + } + + private static void addAtTimeLookupCol(AbstractTableInfo ds, UserSchema targetSchema, UserSchema ehrStudySchema, AtTimeColumn atTimeCol) + { + final ColumnInfo pkCol = ds.getPkColumns().getFirst(); + final String schemaName = ds.getPublicSchemaName(); + final String queryName = ds.getName(); + final String ehrPath = ehrStudySchema.getContainer().getPath(); + final String name = atTimeCol._name; + final String valueCol = atTimeCol._valueCol; + + WrappedColumn col = new WrappedColumn(pkCol, name); + col.setLabel(atTimeCol._label); + col.setReadOnly(true); + col.setUserEditable(false); + // The junction's value column keeps the source dataset's lookup, which the multi-valued FK resolves through to + // the target's title column; values with no matching target row are dropped. + col.setFk(new MultiValuedForeignKey(new LookupForeignKey(pkCol.getName()) + { + @Override + public TableInfo getLookupTableInfo() + { + QueryDefinition qd = QueryService.get().createQueryDef(targetSchema.getUser(), targetSchema.getContainer(), targetSchema, queryName + "_" + name); + // Full timestamps with an exclusive end, like housingAtTime; AssignmentAtTimeForeignKey matches by date instead. + // The source is pinned to the EHR container so the dataset's container filter doesn't widen it. + qd.setSql("SELECT DISTINCT\n" + + "sd." + pkCol.getFieldKey().toSQLString() + ",\n" + + "src." + valueCol + "\n" + + "FROM \"" + schemaName + "\".\"" + queryName + "\" sd\n" + + "JOIN \"" + ehrPath + "\".study." + atTimeCol._sourceDataset + "[ContainerFilter='Current'] src\n" + + " ON (src.id = sd.id AND src.date <= sd.date\n" + + " AND (src.enddate IS NULL OR sd.date < src.enddate)\n" + + " AND src.qcstate.publicdata = true)"); + qd.setIsTemporary(true); + qd.setContainerFilter(ds.getContainerFilter()); + + List errors = new ArrayList<>(); + TableInfo ti = qd.getTable(errors, true); + if (!errors.isEmpty() || ti == null) + { + LOG.warn("Error creating {} junction for: {}.{} in container: {}", name, schemaName, queryName, targetSchema.getContainer().getPath()); + errors.forEach(e -> LOG.error("Lookup table QueryException: {}", e.getMessage(), e)); + return null; + } + + ((BaseColumnInfo) ti.getColumn(pkCol.getName())).setKeyField(true); + return ti; + } + }, valueCol)); + + ds.addColumn(col); + } +}