Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions nirc_ehr/resources/queries/study/drug.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@

require("ehr/triggers").initScript(this);

let triggerHelper = new org.labkey.nirc_ehr.query.NIRC_EHRTriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id);

EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.BEFORE_UPSERT, 'study', 'drug', function(helper, scriptErrors, row, oldRow) {
// Max reasonable amount warning. Error when the amount is greater than the max reasonable amount
if (row.code) {
let drugFormulary = triggerHelper.getFormularyForDrug(row.code);
if (drugFormulary && drugFormulary.maxAmount && row.amount > drugFormulary.maxAmount) {
EHR.Server.Utils.addError(scriptErrors, 'amount', 'Amount is greater than the maximum reasonable amount: ' + drugFormulary.maxAmount, 'ERROR');
}
}
if (row.volume && !row.vol_units) {
EHR.Server.Utils.addError(scriptErrors, 'volume', 'Units required for volume.', 'ERROR');
}
Expand Down
10 changes: 10 additions & 0 deletions nirc_ehr/resources/queries/study/treatment_order.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@

require("ehr/triggers").initScript(this);

let triggerHelper = new org.labkey.nirc_ehr.query.NIRC_EHRTriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id);

EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.BEFORE_UPSERT, 'study', 'treatment_order', function(helper, scriptErrors, row, oldRow) {
// Max reasonable amount warning. Error when the amount is greater than the max reasonable amount
if (row.code) {
let drugFormulary = triggerHelper.getFormularyForDrug(row.code);
if (drugFormulary && drugFormulary.maxAmount && row.amount > drugFormulary.maxAmount) {
EHR.Server.Utils.addError(scriptErrors, 'amount', 'Amount is greater than the maximum reasonable amount: ' + drugFormulary.maxAmount, 'ERROR');
}
}

if (row.volume && !row.vol_units) {
EHR.Server.Utils.addError(scriptErrors, 'volume', 'Units required for volume.', 'ERROR');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Ext4.define('NIRC_EHR.data.DrugAdministrationRunsChildClientStore', {
extend: 'EHR.data.DrugAdministrationRunsClientStore',

insert: function(index, records) {
var ret = this.callParent(arguments);

// after insert of a new, track down the parent record to get the fields to inherit
if (this.sectionCfg && this.sectionCfg.extraProperties && this.sectionCfg.extraProperties.parentQueryName) {
var parentQuery = this.sectionCfg.extraProperties.parentQueryName;
var parentStore = this.storeCollection.getClientStoreByName(parentQuery);
var parentRecord = parentStore ? parentStore.getAt(0) : null;
if (parentRecord && Ext4.isFunction(parentStore.onRecordUpdate)) {
// get the set of inherited field names
var inheritFieldNames = [];
Ext4.each(this.getFields().items, function(field) {
if (field.inheritFromParent) {
inheritFieldNames.push(field.name);
}
});

parentStore.onRecordUpdate(parentRecord, inheritFieldNames);
}
}

return ret;
}
});
47 changes: 47 additions & 0 deletions nirc_ehr/resources/web/nirc_ehr/model/sources/MedicationEndDate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
EHR.model.DataModelManager.registerMetadata('MedicationEndDate', {
allQueries: {
'code': {
editorConfig: {
listeners: {
// End date calculated from Default Duration in the formulary and the date field of data entry grid.
// Only calculate end date when treatment is selected and there is a date in the field.
// Don’t recalculate if changing drug multiple times.
change: function (field, newVal, oldVal) {
if (newVal && !oldVal) {
let record = EHR.DataEntryUtils.getBoundRecord(field);
if (record) {
LABKEY.Query.selectRows({
schemaName: 'ehr_lookups',
queryName: 'drug_defaults',
columns: ['duration','offset'],
scope: this,
filterArray: [LABKEY.Filter.create('code', newVal)],
success: function (data) {
if (data.rows && data.rows.length > 0) {
let defaultDuration = data.rows[0].duration;
let offset = data.rows[0].offset;
let date = record.get('date');
if (defaultDuration && date) {
let endDate = new Date(date);
endDate.setDate(endDate.getDate() + defaultDuration);
if (offset) {
endDate.setHours(endDate.getHours() + offset);
}
EHR.DataEntryUtils.setSiblingFields(field, {
enddate: endDate
});
}
}
},
failure: function(error) {
console.error(error);
}
});
}
}
}
}
}
}
},
});
43 changes: 43 additions & 0 deletions nirc_ehr/resources/web/nirc_ehr/window/DrugAmountWindow.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
(function getSnomedStore(){
if (NIRC_EHR._snomedStore)
return NIRC_EHR._snomedStore;

let storeId = ['ehr_lookups', 'snomed', 'code', 'meaning'].join('||');

NIRC_EHR._snomedStore = Ext4.create('LABKEY.ext4.data.Store', {
type: 'labkey-store',
schemaName: 'ehr_lookups',
queryName: 'snomed',
columns: 'code,meaning',
sort: 'meaning',
storeId: storeId,
autoLoad: true,
getRecordForCode: function(code){
let recIdx = this.findExact('code', code);
if (recIdx != -1){
return this.getAt(recIdx);
}
}
});

return NIRC_EHR._snomedStore;
})();

Ext4.define('NIRC_EHR.window.DrugAmountWindow', {
extend: 'EHR.window.DrugAmountWindow',

Expand All @@ -6,6 +31,7 @@ Ext4.define('NIRC_EHR.window.DrugAmountWindow', {
},

getDrugItems: function(){

var numCols = 13;
var items = [{
html: '<b>Animal</b>'
Expand Down Expand Up @@ -275,4 +301,21 @@ Ext4.define('NIRC_EHR.window.DrugAmountWindow', {
return codeMap;
},

});

EHR.DataEntryUtils.registerGridButton('NIRC_DRUG_AMOUNT_HELPER', function(config){
return Ext4.Object.merge({
text: 'Review Drug Amount(s)',
xtype: 'button',
tooltip: 'Click to set the drug amounts',
handler: function(btn){
var grid = btn.up('gridpanel');

Ext4.create('NIRC_EHR.window.DrugAmountWindow', {
targetGrid: grid,
targetStore: grid.store,
formConfig: grid.formConfig
}).show();
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public NIRCBehaviorRoundsFormType(DataEntryFormContext ctx, Module owner)
s.addConfigSource("BehaviorDefaults");
s.addConfigSource("TreatmentSchedule");
s.addConfigSource("BehaviorRounds");
s.addConfigSource("MedicationEndDate");

if (s instanceof SimpleFormSection && !s.getName().equals("tasks"))
s.setTemplateMode(AbstractFormSection.TEMPLATE_MODE.NO_ID);
Expand All @@ -66,6 +67,7 @@ public NIRCBehaviorRoundsFormType(DataEntryFormContext ctx, Module owner)
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/BehavioralCase.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/BehaviorDefaults.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/BehaviorRounds.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/MedicationEndDate.js"));
addClientDependency(ClientDependency.supplierFromPath("ehr/panel/ExamDataEntryPanel.js"));
setJavascriptClass("EHR.panel.ExamDataEntryPanel");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public NIRCBehavioralCasesFormType(DataEntryFormContext ctx, Module owner)
s.addConfigSource("BehavioralCase");
s.addConfigSource("BehaviorDefaults");
s.addConfigSource("TreatmentSchedule");
s.addConfigSource("MedicationEndDate");

if (s instanceof SimpleFormSection && !s.getName().equals("tasks"))
s.setTemplateMode(AbstractFormSection.TEMPLATE_MODE.NO_ID);
Expand All @@ -66,6 +67,7 @@ public NIRCBehavioralCasesFormType(DataEntryFormContext ctx, Module owner)

addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/BehavioralCase.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/BehaviorDefaults.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/MedicationEndDate.js"));
addClientDependency(ClientDependency.supplierFromPath("ehr/panel/ExamDataEntryPanel.js"));
setJavascriptClass("EHR.panel.ExamDataEntryPanel");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public NIRCBulkBehaviorFormType(DataEntryFormContext ctx, Module owner)
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/TreatmentSchedule.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/field/DrugVolumeField.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/window/DrugAmountWindow.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/MedicationEndDate.js"));

// Needed for scheduled date/time when navigating from treatment or observation schedule
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/buttons/treatmentSubmit.js"));
Expand All @@ -48,6 +49,7 @@ public NIRCBulkBehaviorFormType(DataEntryFormContext ctx, Module owner)
{
s.addConfigSource("BehaviorDefaults");
s.addConfigSource("TreatmentSchedule");
s.addConfigSource("MedicationEndDate");
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public NIRCBulkClinicalFormType(DataEntryFormContext ctx, Module owner)
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/ClinicalDefaults.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/BulkClinical.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/TreatmentSchedule.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/MedicationEndDate.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/field/DrugVolumeField.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/window/DrugAmountWindow.js"));

Expand All @@ -58,6 +59,7 @@ public NIRCBulkClinicalFormType(DataEntryFormContext ctx, Module owner)
s.addConfigSource("ClinicalDefaults");
s.addConfigSource("BulkClinical");
s.addConfigSource("TreatmentSchedule");
s.addConfigSource("MedicationEndDate");
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public NIRCCasesFormType(DataEntryFormContext ctx, Module owner)
s.addConfigSource("ClinicalDefaults");
s.addConfigSource("ClinicalCase");
s.addConfigSource("TreatmentSchedule");
s.addConfigSource("MedicationEndDate");

if (s instanceof SimpleFormSection && !s.getName().equals("tasks"))
s.setTemplateMode(AbstractFormSection.TEMPLATE_MODE.NO_ID);
Expand All @@ -76,6 +77,7 @@ public NIRCCasesFormType(DataEntryFormContext ctx, Module owner)

addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/ClinicalDefaults.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/ClinicalCase.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/MedicationEndDate.js"));
addClientDependency(ClientDependency.supplierFromPath("ehr/panel/ExamDataEntryPanel.js"));
setJavascriptClass("EHR.panel.ExamDataEntryPanel");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public NIRCClinicalRoundsFormType(DataEntryFormContext ctx, Module owner)
s.addConfigSource("ClinicalCase");
s.addConfigSource("ClinicalRounds");
s.addConfigSource("TreatmentSchedule");
s.addConfigSource("MedicationEndDate");

if (s instanceof SimpleFormSection && !s.getName().equals("tasks"))
s.setTemplateMode(AbstractFormSection.TEMPLATE_MODE.NO_ID);
Expand All @@ -75,6 +76,7 @@ public NIRCClinicalRoundsFormType(DataEntryFormContext ctx, Module owner)
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/ClinicalDefaults.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/ClinicalCase.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/ClinicalRounds.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/MedicationEndDate.js"));
addClientDependency(ClientDependency.supplierFromPath("ehr/panel/ExamDataEntryPanel.js"));
setJavascriptClass("EHR.panel.ExamDataEntryPanel");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public NIRCMedicationTreatmentFormType(DataEntryFormContext ctx, Module owner)
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/field/DrugVolumeField.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/window/DrugAmountWindow.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/ClinicalDefaults.js"));
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/MedicationEndDate.js"));

// Needed for case and scheduled date/time when navigating from treatment or observation schedule
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/buttons/treatmentSubmit.js"));
Expand All @@ -37,6 +38,7 @@ public NIRCMedicationTreatmentFormType(DataEntryFormContext ctx, Module owner)
{
s.addConfigSource("TreatmentSchedule");
s.addConfigSource("ClinicalDefaults");
s.addConfigSource("MedicationEndDate");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import org.labkey.api.view.template.ClientDependency;

import java.util.List;

public class NIRCTreatmentGivenFormSection extends BaseFormSection
{
public static final String LABEL = "Medications/Treatments Given";

public NIRCTreatmentGivenFormSection()
{
super("study", "drug", LABEL, "ehr-gridpanel", true, true, true);
setClientStoreClass("EHR.data.DrugAdministrationRunsClientStore");
addClientDependency(ClientDependency.supplierFromPath("ehr/data/DrugAdministrationRunsClientStore.js"));
}

public NIRCTreatmentGivenFormSection(boolean isChild, String parentQueryName)
Expand All @@ -19,9 +23,21 @@ public NIRCTreatmentGivenFormSection(boolean isChild, String parentQueryName)
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/ParentChild.js"));
addConfigSource("ParentChild");

addClientDependency(ClientDependency.supplierFromPath("ehr/data/ChildClientStore.js"));
setClientStoreClass("EHR.data.ChildClientStore");
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/data/DrugAdministrationRunsChildClientStore.js"));
setClientStoreClass("NIRC_EHR.data.DrugAdministrationRunsChildClientStore");
addExtraProperty("parentQueryName", parentQueryName);
}
}

@Override
public List<String> getTbarButtons()
{
List<String> defaultButtons = super.getTbarButtons();
int idx = defaultButtons.indexOf("SELECTALL");
if (idx > -1)
defaultButtons.add(idx + 1, "NIRC_DRUG_AMOUNT_HELPER");
else
defaultButtons.add("DRUGAMOUNTHELPER");
return defaultButtons;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import org.labkey.api.view.template.ClientDependency;

import java.util.List;

public class NIRCTreatmentOrderFormSection extends BaseFormSection
{
public static final String LABEL = "Medications/Treatments Orders";

public NIRCTreatmentOrderFormSection()
{
super("study", "treatment_order", LABEL, "ehr-gridpanel", true, true, true);
setClientStoreClass("EHR.data.DrugAdministrationRunsClientStore");
addClientDependency(ClientDependency.supplierFromPath("ehr/data/DrugAdministrationRunsClientStore.js"));
}

public NIRCTreatmentOrderFormSection(boolean isChild, String parentQueryName)
Expand All @@ -19,9 +23,21 @@ public NIRCTreatmentOrderFormSection(boolean isChild, String parentQueryName)
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/model/sources/ParentChild.js"));
addConfigSource("ParentChild");

addClientDependency(ClientDependency.supplierFromPath("ehr/data/ChildClientStore.js"));
setClientStoreClass("EHR.data.ChildClientStore");
addClientDependency(ClientDependency.supplierFromPath("nirc_ehr/data/DrugAdministrationRunsChildClientStore.js"));
setClientStoreClass("NIRC_EHR.data.DrugAdministrationRunsChildClientStore");
addExtraProperty("parentQueryName", parentQueryName);
}
}

@Override
public List<String> getTbarButtons()
{
List<String> defaultButtons = super.getTbarButtons();
int idx = defaultButtons.indexOf("SELECTALL");
if (idx > -1)
defaultButtons.add(idx + 1, "NIRC_DRUG_AMOUNT_HELPER");
else
defaultButtons.add("DRUGAMOUNTHELPER");
return defaultButtons;
}
}
Loading
Loading