Skip to content

Commit 8112040

Browse files
committed
claude code review
1 parent c63bef1 commit 8112040

2 files changed

Lines changed: 42 additions & 8 deletions

File tree

ehr/resources/web/ehr/DataEntryUtils.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,17 @@ EHR.DataEntryUtils = new function(){
801801
schemaName: 'ehr',
802802
queryName: 'observation_types',
803803
columns: 'value,editorconfig',
804-
autoLoad: true
804+
autoLoad: true,
805+
listeners: {
806+
// unlike EHR.data.DataEntryClientStore, LABKEY.ext4.data.Store has no hasLoaded();
807+
// consumers need to distinguish a pending initial load from one that returned no rows
808+
load: {
809+
single: true,
810+
fn: function(store){
811+
store.hasLoadedOnce = true;
812+
}
813+
}
814+
}
805815
});
806816

807817
return EHR._observationTypesStore;

ehr/resources/web/ehr/plugin/ClinicalObservationsBulkEdit.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ Ext4.define('EHR.plugin.ClinicalObservationsBulkEdit', {
3838
name: observationField.name,
3939
fieldLabel: observationField.fieldLabel,
4040
labelWidth: observationField.labelWidth,
41-
width: observationField.width
41+
width: observationField.width,
42+
// honor metadata that marks the field as never-enableable (see BulkEditPanel.getFieldConfigs)
43+
originalDisabled: observationField.originalDisabled
4244
};
4345

4446
categoryField.on('change', function(field, newValue){
@@ -54,9 +56,15 @@ Ext4.define('EHR.plugin.ClinicalObservationsBulkEdit', {
5456

5557
reconfigureObservationField: function(category){
5658
var store = this.observationTypesStore;
57-
if (store.isLoading() || !store.getCount()){
59+
// hasLoadedOnce (set in EHR.DataEntryUtils.getObservationTypesStore) distinguishes a pending
60+
// initial load from one that already returned no rows; for the latter we fall through to the
61+
// textfield default rather than waiting on a load event that will never fire
62+
if (!store.hasLoadedOnce){
5863
store.on('load', function(){
59-
this.reconfigureObservationField(category);
64+
// the dialog may have been closed before the store finished loading
65+
if (this.panel && !this.panel.isDestroyed){
66+
this.reconfigureObservationField(category);
67+
}
6068
}, this, {single: true});
6169
return;
6270
}
@@ -67,14 +75,22 @@ Ext4.define('EHR.plugin.ClinicalObservationsBulkEdit', {
6775
return;
6876
}
6977

78+
//note: we proceed even if the category cannot be found, to support records saved under a no-longer-supported category
79+
var rec = category ? store.findRecord('value', category) : null;
80+
var rawEditorConfig = (rec && rec.get('editorconfig')) || null;
81+
82+
// the category combo fires change on every keystroke, so skip the rebuild when the resolved
83+
// editor is unchanged; this avoids churn and preserves any value the user already entered
84+
if (this.appliedEditorConfig !== undefined && this.appliedEditorConfig === rawEditorConfig){
85+
return;
86+
}
87+
7088
var container = observationField.ownerCt;
7189
var index = container.items.indexOf(observationField);
7290
//preserve the user's enable/disable toggle state across category changes
7391
var wasDisabled = observationField.isDisabled();
7492

75-
//note: we proceed even if the category cannot be found, to support records saved under a no-longer-supported category
76-
var rec = category ? store.findRecord('value', category) : null;
77-
var editorConfig = rec && rec.get('editorconfig') ? Ext4.decode(rec.get('editorconfig')) : null;
93+
var editorConfig = rawEditorConfig ? Ext4.decode(rawEditorConfig) : null;
7894
editorConfig = editorConfig || {
7995
xtype: 'textfield'
8096
};
@@ -84,7 +100,6 @@ Ext4.define('EHR.plugin.ClinicalObservationsBulkEdit', {
84100
delete cfg.value;
85101
delete cfg.defaultValue;
86102
cfg.allowBlank = true;
87-
cfg.originalDisabled = false;
88103
cfg.disabled = wasDisabled;
89104

90105
cfg = EHR.DataEntryUtils.ensureLookupPlugin(cfg, false);
@@ -93,5 +108,14 @@ Ext4.define('EHR.plugin.ClinicalObservationsBulkEdit', {
93108
var newField = Ext4.widget(cfg);
94109
panel.addLabelToggle(newField);
95110
container.insert(index, newField);
111+
112+
// the databind plugin only registers listeners on the fields present at init, so register the
113+
// replacement explicitly to keep record syncing and validation consistent with the original field
114+
var databind = panel.getPlugin('ehr-databind');
115+
if (databind){
116+
databind.addFieldListener(newField);
117+
}
118+
119+
this.appliedEditorConfig = rawEditorConfig;
96120
}
97121
});

0 commit comments

Comments
 (0)