Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ EHR.model.DataModelManager.registerMetadata('BehaviorRounds', {
columnConfig: {
editable: false
}
},
caseid: {
hidden: false,
columnConfig: {
width: 10,
editable: false
}
}
}
}
Expand Down
200 changes: 200 additions & 0 deletions onprc_ehr/resources/web/onprc_ehr/window/AddBehaviorCasesWindow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
/* Copyright (c) 2014-2019 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
/**
* This window will allow users to query open cases and add records to a task based on them
*/
Ext4.define('ONPRC_EHR.window.AddBehaviorCasesWindow', {
extend: 'EHR.window.AddSurgicalCasesWindow',
caseCategory: 'Behavior',
templateName: null,

allowNoSelection: true,
showAssignedVetCombo: false,
showAllowOpen: true,
defaultRemark: 'BSU Rounds Entered',

getCases: function(button){
Ext4.Msg.wait("Loading...");
this.hide();

var casesFilterArray = this.getCasesFilterArray();
var obsFilterArray = this.getBaseFilterArray();
obsFilterArray.push(LABKEY.Filter.create('caseCategory', this.caseCategory, LABKEY.Filter.Types.EQUAL));
var includeOpen = this.down('#includeOpen') ? this.down('#includeOpen').getValue() : false;
if (includeOpen){
obsFilterArray.push(LABKEY.Filter.create('caseIsOpen', true, LABKEY.Filter.Types.EQUAL));
}
else {
obsFilterArray.push(LABKEY.Filter.create('caseIsActive', true, LABKEY.Filter.Types.EQUAL));
}

//find distinct animals matching criteria
var multi = new LABKEY.MultiRequest();

multi.add(LABKEY.Query.selectRows, {
requiredVersion: 9.1,
schemaName: 'study',
queryName: 'latestObservationsForCase',
columns: 'Id,date,category,area,observation,remark,caseid',
filterArray: obsFilterArray,
scope: this,
success: function(results){
this.obsResults = results;
},
failure: LDK.Utils.getErrorCallback()
});

multi.add(LABKEY.Query.selectRows, {
requiredVersion: 9.1,
schemaName: 'study',
queryName: 'cases',
sort: 'Id/curLocation/location,Id,remark,allProblemCategories',
columns: 'Id,objectid',
filterArray: casesFilterArray,
scope: this,
success: function(results){
this.casesResults = results;
},
failure: LDK.Utils.getErrorCallback()
});

multi.send(this.onSuccess, this);
},

//@Override. this is to skip the duplicate case check
addRecords: function(records){
this.doAddRecords(records);
},

//@Override. this is to skip the duplicate case check
doAddRecords: function(records){
this.processObservations(records);
},

//apply previous observations, or inser a blank obs record.
processObservations: function(caseRecords){
//find all distinct IDs with cases.
var distinctCaseIds = [];
if (caseRecords && caseRecords.length){
Ext4.Array.forEach(caseRecords, function(cr){
if (distinctCaseIds.indexOf(cr.get('caseid') == -1)){
distinctCaseIds.push(cr.get('caseid'));
}
}, this);
}

var previousObsMap = {};
if (this.obsResults && this.obsResults.rows && this.obsResults.rows.length){
Ext4.Array.forEach(this.obsResults.rows, function(sr){
//reset variable
var newobservation = '';
var row = new LDK.SelectRowsRow(sr);
newobservation = row.getValue('category');

//note: this has been changed to ensure 1 row per case
var key = row.getValue('caseid');
if (!previousObsMap[key])
previousObsMap[key] = [];

previousObsMap[key].push({
Id: row.getValue('Id'),
date: this.recordData.date,
performedby: this.recordData.performedby,
caseid: row.getValue('caseid'),
category: row.getValue('category'),
area: row.getValue('area'),
allProblemCategories:row.getValue('allProblemCategories'),
//dont copy value
//observation: row.getValue('observation'),
remark: row.getValue('remark')
});
if (newobservation == "Alopecia Score") {
previousObsMap[key].push({
Id: row.getValue('Id'),
date: this.recordData.date,
performedby: this.recordData.performedby,
caseid: row.getValue('caseid'),
category: 'Alopecia Regrowth',
area: row.getValue('area'),
allProblemCategories:row.getValue('allProblemCategories'),
//dont copy value
//observation: row.getValue('observation'),
remark: row.getValue('remark')
});

}
}, this);
}

var obsRecords = [];
var obsStore = this.targetStore.storeCollection.getClientStoreByName('Clinical Observations');
LDK.Assert.assertNotEmpty('Unable to find Clinical Observations store', obsStore);

var treatmentRecords = [];
var treatmentStore = this.targetStore.storeCollection.getClientStoreByName('Drug Administration');
LDK.Assert.assertNotEmpty('Unable to find Drug Administration store', treatmentStore);

Ext4.Array.forEach(caseRecords, function(cr){
if (previousObsMap[cr.get('caseid')]){
Ext4.Array.forEach(previousObsMap[cr.get('caseid')], function(r){
r = Ext4.apply(r, {
'Id/curLocation/location': cr.get('Id/curLocation/location')
});

obsRecords.push(obsStore.createModel(r));
}, this);
}
else {
obsRecords.push(obsStore.createModel({
'Id/curLocation/location': cr.get('Id/curLocation/location'),
Id: cr.get('Id'),
date: this.recordData.date,
performedby: this.recordData.performedby,
caseid: cr.get('caseid')
}));
}

treatmentRecords.push(treatmentStore.createModel({
Id: cr.get('Id'),
caseid: cr.get('caseid'),
date: this.recordData.date,
performedby: this.recordData.performedby
}));
}, this);

if (obsRecords.length){
obsStore.add(obsRecords);
}

if (treatmentRecords.length){
treatmentStore.add(treatmentRecords);
}

Ext4.Msg.hide();
this.close();
}
});

EHR.DataEntryUtils.registerGridButton('ADDBEHAVIORCASESAMENDED', function(config){
return Ext4.Object.merge({
text: 'Add Open Cases',
tooltip: 'Click to automatically add animals with open cases',
handler: function(btn){
var grid = btn.up('gridpanel');
if(!grid.store || !grid.store.hasLoaded()){
console.log('no store or store hasnt loaded');
return;
}

var cellEditing = grid.getPlugin('cellediting');
if(cellEditing)
cellEditing.completeEdit();

Ext4.create('ONPRC_EHR.window.AddBehaviorCasesWindow', {
targetStore: grid.store
}).show();
}
}, config);
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ public BehaviorRoundsObservationsFormSection()

addClientDependency(ClientDependency.supplierFromPath("ehr/window/AddClinicalCasesWindow.js"));
addClientDependency(ClientDependency.supplierFromPath("ehr/window/AddSurgicalCasesWindow.js"));
addClientDependency(ClientDependency.supplierFromPath("ehr/window/AddBehaviorCasesWindow.js"));
addClientDependency(ClientDependency.supplierFromPath("onprc_ehr/window/AddBehaviorCasesWindow.js"));
}

@Override
public List<String> getTbarButtons()
{
List<String> defaultButtons = super.getTbarButtons();
defaultButtons.add(0, "ADDBEHAVIORCASES");
defaultButtons.add(0, "ADDBEHAVIORCASESAMENDED");

return defaultButtons;
}
Expand Down