-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEncounterAddRecordWindow.js
More file actions
150 lines (132 loc) · 4.97 KB
/
EncounterAddRecordWindow.js
File metadata and controls
150 lines (132 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Copyright (c) 2014-2019 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
/**
* @cfg targetGrid
* @cfg dataEntryPanel
*/
Ext4.define('EHR.window.EncounterAddRecordWindow', {
extend: 'Ext.window.Window',
width: 500,
initComponent: function(){
var data = EHR.DataEntryUtils.getEncountersRecords(this.dataEntryPanel);
Ext4.apply(this, {
modal: true,
closeAction: 'destroy',
title: 'Add Record',
bodyStyle: 'padding: 5px;',
defaults: {
border: false
},
items: [{
html: 'Please choose which procedure is associated with this record, or select multiple procedures to add more than 1 record:',
style: 'padding-bottom: 10px;'
},{
xtype: 'checkcombo',
itemId: 'comboField',
addAllSelector: true,
mutliSelect: true,
width: 400,
displayField: 'title',
valueField: 'parentid',
store: {
type: 'store',
fields: ['title', 'parentid', 'Id', 'date', 'project'],
data: data
},
forceSelection: true
}],
buttons: [{
text: 'Submit',
scope: this,
handler: this.onSubmit
},{
text: 'Close',
handler: function(btn){
btn.up('window').close();
}
}]
});
this.callParent(arguments);
if (!data.length) {
this.on('beforeshow', function(){
Ext4.Msg.alert('No Records', 'Cannot add results to this section without a corresponding procedure above. Note: the procedure must have an Id/date in order to enter results');
this.close();
return false;
}, this);
}
else if (data.length == 1){
var parentid = data[0].parentid;
this.on('beforeshow', function(){
this.processParentIds([parentid]);
return false;
}, this);
}
},
onSubmit: function(){
var parentids = this.down('#comboField').getValue();
if (!parentids.length){
Ext4.Msg.alert('Error', 'Must select at least 1 record');
return;
}
this.processParentIds(parentids);
},
processParentIds: function(parentids){
var combo = this.down('#comboField');
var cellEditing = this.targetGrid.getPlugin('cellediting');
if (cellEditing)
cellEditing.completeEdit();
var toAdd = [];
Ext4.Array.forEach(parentids, function(parentid){
var recIdx = combo.store.findExact('parentid', parentid);
LDK.Assert.assertTrue('Unable to find record', recIdx != -1);
var rec = combo.store.getAt(recIdx);
var model = this.targetGrid.store.createModel({});
var obj = {};
Ext4.Array.forEach(['Id', 'date', 'parentid', 'project'], function(field){
const fieldConfig = this.targetGrid.store.getFields().get(field);
if (fieldConfig){
if (field === 'date') {
if (fieldConfig.inheritDefaultDateFromParent) {
obj[field] = rec.get(field);
}
}
else {
obj[field] = rec.get(field);
}
}
}, this);
model.set(obj);
toAdd.push(model);
}, this);
this.targetGrid.store.add(toAdd);
if (cellEditing) {
//start editing on the first newly added record
cellEditing.startEditByPosition({row: (this.targetGrid.store.getCount() - toAdd.length), column: this.targetGrid.firstEditableColumn || 0});
}
this.close();
}
});
EHR.DataEntryUtils.registerGridButton('ENCOUNTERADD', function(config){
return Ext4.Object.merge({
text: 'Add Record',
tooltip: 'Click to add a row',
handler: function(btn){
var grid = btn.up('gridpanel');
if(!grid.store || !grid.store.hasLoaded()){
console.log('no store or store hasnt loaded');
return;
}
var panel = grid.up('ehr-dataentrypanel');
LDK.Assert.assertNotEmpty('Unable to find dataEntryPanel in ENCOUNTERADD button', panel);
var store = panel.storeCollection.getClientStoreByName('encounters');
LDK.Assert.assertNotEmpty('Unable to find encounters store in ENCOUNTERADD button', store);
Ext4.create('EHR.window.EncounterAddRecordWindow', {
targetGrid: grid,
dataEntryPanel: panel
}).show();
}
}, config);
});