From e202aba9bdafb60350bd85fa8c4e25b8889d41ae Mon Sep 17 00:00:00 2001 From: Chad Sebranek Date: Thu, 26 Sep 2024 10:11:02 -0500 Subject: [PATCH 1/3] Adjust y-axis; add legend --- .../web/ehr/panel/BloodSummaryPanel.js | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/ehr/resources/web/ehr/panel/BloodSummaryPanel.js b/ehr/resources/web/ehr/panel/BloodSummaryPanel.js index 252673329..6039cbe0b 100644 --- a/ehr/resources/web/ehr/panel/BloodSummaryPanel.js +++ b/ehr/resources/web/ehr/panel/BloodSummaryPanel.js @@ -309,6 +309,15 @@ Ext4.define('EHR.panel.BloodSummaryPanel', { return text; }); }, + getMaxBloodAvailValue: function(rows){ + + var allowableBloodVals = []; + for (var i = 0; i < rows.length; i++){ + allowableBloodVals.push(rows[i].allowableDisplay.value); + } + + return Math.round(allowableBloodVals.reduce((a, b) => Math.max(a, b), -Infinity)) + 10; + }, getTickValues: function(rows){ var ticks = [], msPerDay = 86400000, totalTicks = 10; @@ -385,7 +394,7 @@ Ext4.define('EHR.panel.BloodSummaryPanel', { html: '

Total volume of blood collected in the past ' + currentRow.blood_draw_interval.value + ' days: ' + Ext4.util.Format.round(currentRow.bloodPrevious.value, 1) + ' mL. ' + 'The amount of blood available if drawn today is: ' + Ext4.util.Format.round(currentRow.allowableDisplay.value, 1) + ' mL.

' - + '

The graph below shows how the amount of blood available will change over time, including when previous draws will drop off.

', + + '

The graph below shows how the amount of blood available will change over time, including when previous draws will drop off. Hover over the timepoints for more information.

', border: false, style: 'margin-bottom: 20px' }); @@ -426,6 +435,9 @@ Ext4.define('EHR.panel.BloodSummaryPanel', { }, x: { tickValues: this.getTickValues(results.rows) + }, + y: { + domain: [0, this.getMaxBloodAvailValue(results.rows)], } }, layers: [{ @@ -455,7 +467,18 @@ Ext4.define('EHR.panel.BloodSummaryPanel', { }, getPlotConfig: function(){ var cfg = LDK.panel.GraphPanel.prototype.getPlotConfig.call(this); - cfg.legendPos = 'none'; + cfg.legendData = [ + { + color:'#FC8D62', + text:'Blood Draw', + shape: LABKEY.vis.Scale.Shape()[1] + }, + { + color:'#66C2A5', + text:'Reconstitution Status', + shape: LABKEY.vis.Scale.Shape()[0] + } + ] cfg.aes.color = null; cfg.aes.shape = null; From 44e9ea2e7bec62ff631384ecfa05aed7a5ada0ac Mon Sep 17 00:00:00 2001 From: Chad Sebranek Date: Fri, 4 Oct 2024 11:25:39 -0500 Subject: [PATCH 2/3] account for negative blood vals, add 10 percent buffer on y-axis scale --- .../web/ehr/panel/BloodSummaryPanel.js | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/ehr/resources/web/ehr/panel/BloodSummaryPanel.js b/ehr/resources/web/ehr/panel/BloodSummaryPanel.js index 6039cbe0b..71882db04 100644 --- a/ehr/resources/web/ehr/panel/BloodSummaryPanel.js +++ b/ehr/resources/web/ehr/panel/BloodSummaryPanel.js @@ -309,14 +309,15 @@ Ext4.define('EHR.panel.BloodSummaryPanel', { return text; }); }, - getMaxBloodAvailValue: function(rows){ - - var allowableBloodVals = []; - for (var i = 0; i < rows.length; i++){ - allowableBloodVals.push(rows[i].allowableDisplay.value); - } - - return Math.round(allowableBloodVals.reduce((a, b) => Math.max(a, b), -Infinity)) + 10; + getMaxBloodAvailValue: function(allowableBloodVals){ + var maxVal = Math.max(...allowableBloodVals); + var tenPercent = maxVal * .10; + return maxVal + tenPercent; + }, + getMinBloodAvailValue: function(allowableBloodVals){ + var minVal = Math.min(...allowableBloodVals); + var tenPercent = minVal * .10; + return minVal < 0 ? minVal + tenPercent : 0; }, getTickValues: function(rows){ @@ -400,6 +401,12 @@ Ext4.define('EHR.panel.BloodSummaryPanel', { }); } + //for use later when getting max/min vals for y-axis scale + var allowableBloodVals = []; + for (var i = 0; i < results.rows.length; i++){ + allowableBloodVals.push(results.rows[i].allowableDisplay.value); + } + var layerName = "Volume"; toAdd.push({ xtype: 'container', @@ -437,7 +444,7 @@ Ext4.define('EHR.panel.BloodSummaryPanel', { tickValues: this.getTickValues(results.rows) }, y: { - domain: [0, this.getMaxBloodAvailValue(results.rows)], + domain: [this.getMinBloodAvailValue(allowableBloodVals), this.getMaxBloodAvailValue(allowableBloodVals)], } }, layers: [{ From ed52da06832faf518f4febd00cfe12c213dda7c5 Mon Sep 17 00:00:00 2001 From: Chad Sebranek Date: Wed, 27 Nov 2024 08:43:17 -0600 Subject: [PATCH 3/3] Sort by date, this is what the frontend expects --- ehr/src/org/labkey/ehr/EHRController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ehr/src/org/labkey/ehr/EHRController.java b/ehr/src/org/labkey/ehr/EHRController.java index d46122934..a0f458ccd 100644 --- a/ehr/src/org/labkey/ehr/EHRController.java +++ b/ehr/src/org/labkey/ehr/EHRController.java @@ -40,6 +40,7 @@ import org.labkey.api.data.JsonWriter; import org.labkey.api.data.RuntimeSQLException; import org.labkey.api.data.SimpleFilter; +import org.labkey.api.data.Sort; import org.labkey.api.data.TableInfo; import org.labkey.api.data.TableSelector; import org.labkey.api.dataiterator.DataIteratorContext; @@ -2192,7 +2193,7 @@ public ApiResponse execute(IdForm idForm, BindException errors) SimpleFilter filter = new SimpleFilter(); filter.addCondition(FieldKey.fromParts("id"), idForm.getIdList(), CompareType.IN); - TableSelector selector = new TableSelector(bloodDrawsTable, filter, null); + TableSelector selector = new TableSelector(bloodDrawsTable, filter, new Sort("date")); Map params = new HashMap<>(); params.put("DATE_INTERVAL", idForm.getInterval());