Skip to content

Commit

Permalink
Feature/mme graph updates (#213)
Browse files Browse the repository at this point in the history
* MME graph - add no bup line, copy button

* add comment, remove commented out code

* fix line order

* add bg color for copying

* add variable

* fix color

* refactor

* changes based on feedback

* changes based on feedback

* add comment, remove unwanted file

* add back old code

* remove debug statement

* fix per feedback, fix MME text

* fix get data code

* remove devug statement

* refactor

* fix scale

* graph stats display fix

* fix stroke width

* update alert for naloxone consideration to consider only non-bup med only

* refactor

---------

Co-authored-by: Amy Chen <[email protected]>
Co-authored-by: Amy Chen <[email protected]>
Co-authored-by: Amy Chen <[email protected]>
  • Loading branch information
4 people authored Nov 13, 2024
1 parent 89aa523 commit 44e4bda
Show file tree
Hide file tree
Showing 11 changed files with 2,458 additions and 1,017 deletions.
58 changes: 14 additions & 44 deletions src/components/Landing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Timeout from "../../helpers/timeout";
import { getTokenInfoFromStorage } from "../../helpers/timeout";
import summaryMap from "../../config/summary_config.json";

import { getEnv, getEnvs, fetchEnvData } from "../../utils/envConfig";
import { getEnvs, fetchEnvData } from "../../utils/envConfig";
import SystemBanner from "../SystemBanner";
import Header from "../Header";
import Report from "../Report";
Expand Down Expand Up @@ -378,63 +378,33 @@ export default class Landing extends Component {
landingUtils.savePDMPSummaryData(summary, fileName);
}

hasOverviewSection() {
return summaryMap && summaryMap[this.getOverviewSectionKey()];
}

setSummaryAlerts(summary, sectionFlags) {
if (!summaryMap[this.getOverviewSectionKey()]) return;
if (!this.hasOverviewSection()) return;
summary[this.getOverviewSectionKey() + "_alerts"] =
landingUtils.getProcessedAlerts(sectionFlags, {
tags: ["alert"],
...this.getPatientLogParams(),
});
}
setSummaryGraphData(summary) {
let overviewSection = summaryMap[this.getOverviewSectionKey()];
if (!overviewSection) {
return false;
}
if (!this.hasOverviewSection()) return;
//process graph data
let graphConfig = overviewSection.graphConfig;
if (!(graphConfig && graphConfig.summaryDataSource)) {
return;
}
//get the data from summary data
let sections = graphConfig.summaryDataSource;
let graph_data = [];

//demo config set to on, then draw just the demo graph data
if (getEnv(graphConfig.demoConfigKey)) {
graph_data = graphConfig.demoData;
summary[this.getOverviewSectionKey() + "_graph"] = graph_data;
return;
}
sections.forEach((item) => {
if (
summary[item.section_key] &&
summary[item.section_key][item.subSection_key]
) {
graph_data = [
...graph_data,
...summary[item.section_key][item.subSection_key],
];
}
});
const overviewSection = summaryMap[this.getOverviewSectionKey()];
summary[this.getOverviewSectionKey() + "_graph"] =
landingUtils.getProcessedGraphData(graphConfig, graph_data);
landingUtils.getSummaryGraphDataSet(overviewSection.graphConfig, summary);
}

setSummaryOverviewStatsData(summary) {
if (!this.hasOverviewSection()) return;
const overviewSection = summaryMap[this.getOverviewSectionKey()];
if (!overviewSection) {
return false;
}
const config = overviewSection.statsConfig;
if (!config || !config.data) {
summary[this.getOverviewSectionKey() + "_stats"] = {};
return;
}
const dataSource = summary[config.dataKeySource]
? summary[config.dataKeySource][config.dataKey]
: [];
const stats = landingUtils.getProcessedStatsData(config.data, dataSource);
const stats = landingUtils.getProcessedStatsData(
overviewSection.statsConfig,
summary
);
summary[this.getOverviewSectionKey() + "_stats"] = stats;
}

Expand Down
60 changes: 56 additions & 4 deletions src/components/Landing/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,55 @@ export function getProcessedSummaryData(summary, summaryMap) {
return { sectionFlags, flaggedCount };
}

export function getSummaryGraphDataSet(graphConfig, summaryData) {
if (!summaryData) return null;
if (!(graphConfig && graphConfig.summaryDataSource)) {
return null;
}
//demo config set to on, then draw just the demo graph data
if (getEnv(graphConfig.demoConfigKey)) {
return graphConfig.demoData;
}
//get the data from summary data
let sections = graphConfig.summaryDataSource;
let graphDataSet = {};
sections.forEach((item) => {
if (
summaryData[item.section_key] &&
summaryData[item.section_key][item.subSection_key] &&
!isEmptyArray(summaryData[item.section_key][item.subSection_key])
) {
const sectionKey =
item.key ?? `${item.section_key}_${item.subSection_key}`;
graphDataSet[sectionKey] = {
...item,
data: getProcessedGraphData(
graphConfig,
JSON.parse(
JSON.stringify(summaryData[item.section_key][item.subSection_key])
)
),
};
}
});
if (Object.keys(graphDataSet).length === 0) {
const defaultConfig = graphConfig.defaultDataSource;
graphDataSet[defaultConfig.key] = {
...defaultConfig,
data: getProcessedGraphData(
graphConfig,
JSON.parse(
JSON.stringify(
summaryData[defaultConfig.section_key][defaultConfig.subSection_key]
)
)
),
};
}
console.log("graphData Set ", graphDataSet);
return graphDataSet;
}

export function getProcessedGraphData(graphConfig, graphDataSource) {
const [
startDateFieldName,
Expand Down Expand Up @@ -280,7 +329,7 @@ export function getProcessedGraphData(graphConfig, graphDataSource) {
/*
* 'NaN' is the value for null when coerced into number, need to make sure that is not included
*/
const getRealNumber = (o) => (o && !isNaN(o) ? o : 0);
const getRealNumber = (o) => (o !== null && !isNaN(o) && o >= 0 ? o : 0);
let dataPoints = [];
let prevObj = null,
nextObj = null;
Expand Down Expand Up @@ -449,7 +498,6 @@ export function getProcessedGraphData(graphConfig, graphDataSource) {
}
prevObj = finalDataPoints[finalDataPoints.length - 1];
});
console.log("graph data ", finalDataPoints);
let formattedData = JSON.parse(JSON.stringify(finalDataPoints))
.map((point) => {
let o = {};
Expand Down Expand Up @@ -547,9 +595,13 @@ export function getProcessedAlerts(sectionFlags, logParams) {
);
}

export function getProcessedStatsData(statsFields, dataSource) {
export function getProcessedStatsData(statsConfig, summaryData) {
let stats = {};
if (isEmptyArray(statsFields)) return stats;
if (!statsConfig || isEmptyArray(statsConfig.data)) return stats;
const statsFields = statsConfig.data;
const dataSource = summaryData[statsConfig.dataKeySource]
? summaryData[statsConfig.dataKeySource][statsConfig.dataKey]
: [];

//compile tally of source identified by a key
statsFields.forEach((item) => {
Expand Down
Loading

0 comments on commit 44e4bda

Please sign in to comment.