Skip to content

Commit e08f80c

Browse files
author
Amy Chen
committed
use fake data for sex at birth for now
1 parent 32f4bca commit e08f80c

File tree

4 files changed

+145
-0
lines changed

4 files changed

+145
-0
lines changed

src/server/Model/Cohort/DatasetRecord.cs

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ public PatientDemographic ToAnonymousPatientDemographic()
302302
AddressState = AddressState.ValueElseUnknown(),
303303
Ethnicity = Ethnicity.ValueElseUnknown(),
304304
Gender = Gender.ValueElseUnknown(),
305+
Sex = Sex.ValueElseUnknown(),
305306
Age = Age > 89 ? 89 : Age,
306307
Language = Language.ValueElseUnknown(),
307308
MaritalStatus = MaritalStatus.ValueElseUnknown(),

src/ui-client/src/components/Visualize/AggregateDemographics.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { Binary } from './Binary';
1515
import { Gender} from './Gender';
1616
import { LanguageByHeritage } from './LanguageByHeritage';
1717
import { Religion } from './Religion';
18+
import { Sex } from "./Sex";
1819
import { NihRaceEthnicityGenderTable } from './NihRaceEthnicityGenderTable';
1920

2021
export interface Props {
@@ -62,6 +63,16 @@ export default class AggregateDemographics extends React.PureComponent<Props> {
6263
</Col>
6364
</Row>
6465
<Row>
66+
<Col lg={6} md={12} className="visualization-sex-container">
67+
<SectionHeader headerText="Sex at Birth" />
68+
{/* fake data for now to test */}
69+
<Sex
70+
counts={{"female": 20, "male": 15, "intersexed": 2}}
71+
delay={getDelay(0)}
72+
height={this.props.height}
73+
width={colWidth}
74+
/>
75+
</Col>
6576
<Col lg={6} md={12} className="visualization-age-container">
6677
<SectionHeader headerText="Age" />
6778
<Age
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/* Copyright (c) 2022, UW Medicine Research IT, University of Washington
2+
* Developed by Nic Dobbins and Cliff Spital, CRIO Sean Mooney
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
import React from "react";
9+
import {
10+
Bar,
11+
BarChart,
12+
ResponsiveContainer,
13+
XAxis,
14+
YAxis,
15+
LabelList,
16+
Cell,
17+
} from "recharts";
18+
import { visualizationConfig } from "../../config/visualization";
19+
import { PatientCountMap } from "../../models/cohort/DemographicDTO";
20+
21+
interface Props {
22+
counts: PatientCountMap;
23+
delay: number;
24+
height: number;
25+
width: number;
26+
}
27+
28+
interface State {
29+
showAll: boolean;
30+
useDelay: boolean;
31+
}
32+
33+
export class Sex extends React.PureComponent<Props, State> {
34+
private className = "visualization-sex";
35+
private maxWidth = 800;
36+
private defaultDataLength = 20;
37+
38+
public constructor(props: Props) {
39+
super(props);
40+
this.state = {
41+
showAll: false,
42+
useDelay: true,
43+
};
44+
}
45+
46+
public render() {
47+
const config = visualizationConfig.demographics.sex;
48+
const { height, width, counts, delay } = this.props;
49+
const { showAll, useDelay } = this.state;
50+
const c = this.className;
51+
const del = useDelay ? delay : 0;
52+
const w = width > this.maxWidth ? this.maxWidth : width;
53+
54+
if (!counts) return <div style={{margin: "24px"}}>No data available</div>;
55+
let data = Object.entries(counts)
56+
.map(([key, value]) => ({ key, value }))
57+
.sort((a, b) => (a.value > b.value ? 0 : 1));
58+
const len = data.length;
59+
60+
if (!showAll) {
61+
data = data.slice(0, this.defaultDataLength);
62+
}
63+
64+
console.log(" sex data ", data);
65+
return (
66+
<div className={`${c}-column`} style={{ height, width: w }}>
67+
{/* Show all toggle */}
68+
{len > this.defaultDataLength && (
69+
<div className="visualization-showall-toggle">
70+
<span
71+
className={`visualization-showall false ${
72+
showAll ? "" : "selected"
73+
}`}
74+
onClick={this.handleShowAllToggleClick.bind(null, false)}
75+
>{`Show top ${this.defaultDataLength} only`}</span>
76+
<span
77+
className={`visualization-showall true ${
78+
showAll ? "selected" : ""
79+
}`}
80+
onClick={this.handleShowAllToggleClick.bind(null, true)}
81+
>{`Show all ${len}`}</span>
82+
</div>
83+
)}
84+
85+
{/* Chart */}
86+
<div style={{ height }}>
87+
<ResponsiveContainer>
88+
<BarChart
89+
data={data}
90+
margin={{ top: 30, right: 30, left: 10, bottom: 5 }}
91+
>
92+
<XAxis dataKey="key" />
93+
<YAxis />
94+
<Bar
95+
animationBegin={del}
96+
barSize={config.barSize}
97+
dataKey="value"
98+
isAnimationActive={true}
99+
>
100+
{data.map((d, i) => (
101+
<Cell key={d.key} fill={this.color(i, config.colors)} />
102+
))}
103+
<LabelList
104+
dataKey="value"
105+
formatter={this.formatNumber}
106+
position="top"
107+
/>
108+
</Bar>
109+
</BarChart>
110+
</ResponsiveContainer>
111+
</div>
112+
</div>
113+
);
114+
}
115+
116+
private formatNumber = (val: any) => val.toLocaleString();
117+
118+
private color = (i: number, colors: string[]): string => {
119+
const last = colors.length - 1;
120+
if (i <= last) {
121+
return colors[i];
122+
}
123+
return colors[i - Math.floor(i / last) * last - 1];
124+
};
125+
126+
private handleShowAllToggleClick = (showAll: boolean) => {
127+
this.setState({ showAll, useDelay: false });
128+
};
129+
}

src/ui-client/src/config/visualization.ts

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ export const visualizationConfig = {
4343
"rgb(148, 103, 189)", "rgb(197, 176, 213)", "rgb(140, 86, 75)", "rgb(196, 156, 148)", "rgb(227, 119, 194)", "rgb(247, 182, 210)", "rgb(127, 127, 127)", "rgb(199, 199, 199)",
4444
"rgb(188, 189, 34)", "rgb(219, 219, 141)", "rgb(23, 190, 207)", "rgb(158, 218, 229)"]
4545
},
46+
sex: {
47+
barSize: 28,
48+
colors: ["#00BCD4", '#8bc34a', '#f44336', '#e57373', '#FFA726']
49+
},
4650
age: {
4751
barSize: 28,
4852
colors: [ "rgb(255, 152, 150)", "rgb(148, 103, 189)", "rgb(197, 176, 213)", "rgb(140, 86, 75)", "rgb(196, 156, 148)", "rgb(227, 119, 194)", "rgb(247, 182, 210)", "rgb(127, 127, 127)", "rgb(199, 199, 199)",

0 commit comments

Comments
 (0)