Skip to content
Merged
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
63 changes: 45 additions & 18 deletions ehr/resources/web/ehr/window/ApplyTemplateWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
* @cfg defaultTemplate
* @cfg allowChooseIds
* @cfg idSelectionMode
* @cfg showDate
*/
Ext4.define('EHR.window.ApplyTemplateWindow', {
extend: 'Ext.window.Window',
allowChooseIds: true,
idSelectionMode: 'multi',
title: 'Apply Template',
closeAction: 'destroy',
showDate: true,

initComponent: function(){
Ext4.applyIf(this, {
Expand Down Expand Up @@ -91,16 +93,28 @@ Ext4.define('EHR.window.ApplyTemplateWindow', {
helpPopup: 'If checked, you will be prompted with a screen that lets you bulk edit the records that will be created. This is often very useful when adding many similar records.',
itemId: 'customizeValues',
checked: false
},this.getIdSelectionItems(),{
xtype: 'xdatetime',
fieldLabel: 'Date (optional)',
itemId: 'dateField',
value: null
}];
},
this.getIdSelectionItems(),
this.getDateItem()
];

return items;
},

getDateItem: function() {
if (this.showDate === false){
return {}
}
else {
return {
xtype: 'xdatetime',
fieldLabel: 'Date (optional)',
itemId: 'dateField',
value: null
}
}
},

getIdSelectionItems: function(){
if (this.idSelectionMode == 'single'){
return {
Expand Down Expand Up @@ -243,32 +257,33 @@ Ext4.define('EHR.window.ApplyTemplateWindow', {
},

getInitialRecordValues: function(){
var ret = [];
var date = this.down('#dateField').getValue();
var obj = {
date: date
};
const ret = [];
const dateField = this.down('#dateField');
const obj = {};
if (dateField) {
obj.date = dateField.getValue();
}

if (this.down('#subjectIds')){
var subjectArray = LDK.Utils.splitIds(this.down('#subjectIds').getValue(),true);
const subjectArray = LDK.Utils.splitIds(this.down('#subjectIds').getValue(),true);
Ext4.Array.each(subjectArray, function(subj){
ret.push(Ext4.apply({
Id: subj
}, obj));
}, this);
}
else if (this.down('#encounterRecords')){
var combo = this.down('#encounterRecords');
var encounterIds = combo.getValue() || [];
const combo = this.down('#encounterRecords');
const encounterIds = combo.getValue() || [];
if (!encounterIds.length){
Ext4.Msg.alert('Error', 'Must choose at least one procedure');
return;
}

Ext4.Array.forEach(encounterIds, function(encounterId){
var recIdx = combo.store.findExact('parentid', encounterId);
const recIdx = combo.store.findExact('parentid', encounterId);
if (recIdx != -1){
var rec = combo.store.getAt(recIdx);
const rec = combo.store.getAt(recIdx);
ret.push({
Id: rec.get('Id'),
date: rec.get('date'),
Expand Down Expand Up @@ -470,7 +485,8 @@ EHR.DataEntryUtils.registerGridButton('TEMPLATE', function(config){
idSelectionMode: menuBtn.idSelectionMode || 'multi',
targetGrid: this.grid,
formType: this.grid.formConfig.name,
defaultTemplate: btn.templateId
defaultTemplate: btn.templateId,
showDate: menuBtn.showDate || true
}).show();
}
})
Expand Down Expand Up @@ -510,13 +526,15 @@ EHR.DataEntryUtils.registerGridButton('TEMPLATE', function(config){
Ext4.create('EHR.window.ApplyTemplateWindow', {
targetGrid: grid,
formType: grid.formConfig.name,
idSelectionMode: menu.idSelectionMode || 'multi'
idSelectionMode: menu.idSelectionMode || 'multi',
showDate: menu.showDate ?? true
}).show();
}
},{
text: 'Templates',
itemId: 'templatesMenu',
idSelectionMode: config.idSelectionMode,
showDate: config.showDate,
menu: []
}]
}
Expand All @@ -531,6 +549,15 @@ EHR.DataEntryUtils.registerGridButton('TEMPLATE_NO_ID', function(config){
return Ext4.apply(cfg, config);
});

EHR.DataEntryUtils.registerGridButton('TEMPLATE_NO_ID_NO_DATE', function(config){
var cfg = EHR.DataEntryUtils.getGridButton('TEMPLATE', {
idSelectionMode: 'none',
showDate: false
});

return Ext4.apply(cfg, config);
});

EHR.DataEntryUtils.registerGridButton('TEMPLATE_ENCOUNTER', function(config){
var cfg = EHR.DataEntryUtils.getGridButton('TEMPLATE', {
idSelectionMode: 'encounter'
Expand Down