diff --git a/nirc_ehr/resources/queries/study/drug.js b/nirc_ehr/resources/queries/study/drug.js
index a5a67ed9..02aad9a5 100644
--- a/nirc_ehr/resources/queries/study/drug.js
+++ b/nirc_ehr/resources/queries/study/drug.js
@@ -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');
}
diff --git a/nirc_ehr/resources/queries/study/treatment_order.js b/nirc_ehr/resources/queries/study/treatment_order.js
index 49ef54e8..828a9437 100644
--- a/nirc_ehr/resources/queries/study/treatment_order.js
+++ b/nirc_ehr/resources/queries/study/treatment_order.js
@@ -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');
}
diff --git a/nirc_ehr/resources/web/nirc_ehr/data/DrugAdministrationRunsChildClientStore.js b/nirc_ehr/resources/web/nirc_ehr/data/DrugAdministrationRunsChildClientStore.js
new file mode 100644
index 00000000..56d9dd07
--- /dev/null
+++ b/nirc_ehr/resources/web/nirc_ehr/data/DrugAdministrationRunsChildClientStore.js
@@ -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;
+ }
+});
\ No newline at end of file
diff --git a/nirc_ehr/resources/web/nirc_ehr/model/sources/MedicationEndDate.js b/nirc_ehr/resources/web/nirc_ehr/model/sources/MedicationEndDate.js
new file mode 100644
index 00000000..08abf3b9
--- /dev/null
+++ b/nirc_ehr/resources/web/nirc_ehr/model/sources/MedicationEndDate.js
@@ -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);
+ }
+ });
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+});
\ No newline at end of file
diff --git a/nirc_ehr/resources/web/nirc_ehr/window/DrugAmountWindow.js b/nirc_ehr/resources/web/nirc_ehr/window/DrugAmountWindow.js
index 5624b019..f9839887 100644
--- a/nirc_ehr/resources/web/nirc_ehr/window/DrugAmountWindow.js
+++ b/nirc_ehr/resources/web/nirc_ehr/window/DrugAmountWindow.js
@@ -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',
@@ -6,6 +31,7 @@ Ext4.define('NIRC_EHR.window.DrugAmountWindow', {
},
getDrugItems: function(){
+
var numCols = 13;
var items = [{
html: 'Animal'
@@ -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();
+ }
+ });
});
\ No newline at end of file
diff --git a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCBehaviorRoundsFormType.java b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCBehaviorRoundsFormType.java
index 115bffa4..d2961313 100644
--- a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCBehaviorRoundsFormType.java
+++ b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCBehaviorRoundsFormType.java
@@ -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);
@@ -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");
diff --git a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCBehavioralCasesFormType.java b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCBehavioralCasesFormType.java
index 3d244ab1..54513a6f 100644
--- a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCBehavioralCasesFormType.java
+++ b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCBehavioralCasesFormType.java
@@ -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);
@@ -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");
diff --git a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCBulkBehaviorFormType.java b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCBulkBehaviorFormType.java
index dcb321e3..f7266105 100644
--- a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCBulkBehaviorFormType.java
+++ b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCBulkBehaviorFormType.java
@@ -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"));
@@ -48,6 +49,7 @@ public NIRCBulkBehaviorFormType(DataEntryFormContext ctx, Module owner)
{
s.addConfigSource("BehaviorDefaults");
s.addConfigSource("TreatmentSchedule");
+ s.addConfigSource("MedicationEndDate");
};
}
diff --git a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCBulkClinicalFormType.java b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCBulkClinicalFormType.java
index 37ffb6c4..e9d281e0 100644
--- a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCBulkClinicalFormType.java
+++ b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCBulkClinicalFormType.java
@@ -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"));
@@ -58,6 +59,7 @@ public NIRCBulkClinicalFormType(DataEntryFormContext ctx, Module owner)
s.addConfigSource("ClinicalDefaults");
s.addConfigSource("BulkClinical");
s.addConfigSource("TreatmentSchedule");
+ s.addConfigSource("MedicationEndDate");
};
}
diff --git a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCCasesFormType.java b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCCasesFormType.java
index 92df0e3f..c4e52015 100644
--- a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCCasesFormType.java
+++ b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCCasesFormType.java
@@ -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);
@@ -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");
diff --git a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCClinicalRoundsFormType.java b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCClinicalRoundsFormType.java
index 8fd66e01..bec9ece0 100644
--- a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCClinicalRoundsFormType.java
+++ b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCClinicalRoundsFormType.java
@@ -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);
@@ -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");
diff --git a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCMedicationTreatmentFormType.java b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCMedicationTreatmentFormType.java
index 383773d6..9a5c3a02 100644
--- a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCMedicationTreatmentFormType.java
+++ b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/form/NIRCMedicationTreatmentFormType.java
@@ -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"));
@@ -37,6 +38,7 @@ public NIRCMedicationTreatmentFormType(DataEntryFormContext ctx, Module owner)
{
s.addConfigSource("TreatmentSchedule");
s.addConfigSource("ClinicalDefaults");
+ s.addConfigSource("MedicationEndDate");
}
}
diff --git a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/section/NIRCTreatmentGivenFormSection.java b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/section/NIRCTreatmentGivenFormSection.java
index e09c2385..61a66381 100644
--- a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/section/NIRCTreatmentGivenFormSection.java
+++ b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/section/NIRCTreatmentGivenFormSection.java
@@ -2,6 +2,8 @@
import org.labkey.api.view.template.ClientDependency;
+import java.util.List;
+
public class NIRCTreatmentGivenFormSection extends BaseFormSection
{
public static final String LABEL = "Medications/Treatments Given";
@@ -9,6 +11,8 @@ public class NIRCTreatmentGivenFormSection extends BaseFormSection
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)
@@ -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 getTbarButtons()
+ {
+ List 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;
+ }
}
diff --git a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/section/NIRCTreatmentOrderFormSection.java b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/section/NIRCTreatmentOrderFormSection.java
index 071c4b0c..ed9a0a6e 100644
--- a/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/section/NIRCTreatmentOrderFormSection.java
+++ b/nirc_ehr/src/org/labkey/nirc_ehr/dataentry/section/NIRCTreatmentOrderFormSection.java
@@ -2,6 +2,8 @@
import org.labkey.api.view.template.ClientDependency;
+import java.util.List;
+
public class NIRCTreatmentOrderFormSection extends BaseFormSection
{
public static final String LABEL = "Medications/Treatments Orders";
@@ -9,6 +11,8 @@ public class NIRCTreatmentOrderFormSection extends BaseFormSection
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)
@@ -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 getTbarButtons()
+ {
+ List 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;
+ }
}
\ No newline at end of file
diff --git a/nirc_ehr/src/org/labkey/nirc_ehr/query/NIRC_EHRTriggerHelper.java b/nirc_ehr/src/org/labkey/nirc_ehr/query/NIRC_EHRTriggerHelper.java
index 61eece0b..ec0bf599 100644
--- a/nirc_ehr/src/org/labkey/nirc_ehr/query/NIRC_EHRTriggerHelper.java
+++ b/nirc_ehr/src/org/labkey/nirc_ehr/query/NIRC_EHRTriggerHelper.java
@@ -61,6 +61,7 @@ public class NIRC_EHRTriggerHelper
private static final Logger _log = LogManager.getLogger(NIRC_EHRTriggerHelper.class);
private Integer _nextProjectId = null;
private Integer _nextProtocolId = null;
+ private Map _cachedDrugFormulary = new HashMap<>();
private SimpleDateFormat _dateFormat;
@@ -746,4 +747,26 @@ public void reportDataChange(String schema, String query, final List ids
{
EHRDemographicsService.get().reportDataChange(_container, schema, query, ids);
}
+
+ public Object getFormularyForDrug(String drugCode) throws SQLException
+ {
+ if (_cachedDrugFormulary.containsKey(drugCode))
+ return _cachedDrugFormulary.get(drugCode);
+
+ TableInfo ti = getTableInfo("ehr_lookups", "drug_defaults");
+ SimpleFilter filter = new SimpleFilter(FieldKey.fromString("code"), drugCode);
+ TableSelector ts = new TableSelector(ti, PageFlowUtil.set("code", "amount_max"), filter, null);
+ Map drugFormulary = new HashMap<>();
+ try (Results rs = ts.getResults())
+ {
+ for (Map r : rs)
+ {
+ drugFormulary.put("code", r.get("code"));
+ drugFormulary.put("maxAmount", r.get("amount_max"));
+ }
+ }
+
+ _cachedDrugFormulary.put(drugCode, drugFormulary);
+ return drugFormulary;
+ }
}
\ No newline at end of file
diff --git a/nirc_ehr/test/src/org.labkey.test/tests.nirc_ehr/NIRC_EHRTest.java b/nirc_ehr/test/src/org.labkey.test/tests.nirc_ehr/NIRC_EHRTest.java
index 8ab84ffc..dfc8afc1 100644
--- a/nirc_ehr/test/src/org.labkey.test/tests.nirc_ehr/NIRC_EHRTest.java
+++ b/nirc_ehr/test/src/org.labkey.test/tests.nirc_ehr/NIRC_EHRTest.java
@@ -27,6 +27,7 @@
import org.labkey.remoteapi.core.SaveModulePropertiesCommand;
import org.labkey.remoteapi.query.ImportDataCommand;
import org.labkey.remoteapi.query.InsertRowsCommand;
+import org.labkey.remoteapi.query.SaveRowsResponse;
import org.labkey.remoteapi.security.CreateUserResponse;
import org.labkey.test.Locator;
import org.labkey.test.TestFileUtils;
@@ -210,6 +211,20 @@ protected void populateInitialData() throws Exception
waitFor(() -> Input(Locator.textarea("populateLookupResults"), getDriver()).waitFor().getValue().contains("Loading reports is complete."),
"Reports didn't finish loading", 60000);
+ populateFormulary();
+ }
+
+ private void populateFormulary() throws IOException, CommandException
+ {
+ InsertRowsCommand insertRowsCommand = new InsertRowsCommand("ehr_lookups", "drug_defaults");
+ insertRowsCommand.addRow(new HashMap()
+ {
+ {
+ put("code", "NIRC-001");
+ }
+ });
+
+ SaveRowsResponse saveRowsResponse = insertRowsCommand.execute(getApiHelper().getConnection(), getContainerPath());
}
@Override