File size: 9,624 Bytes
6d12932 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
"""
Visualization module for nursing care plans and assessments.
Provides charts and visualizations for clinical data.
"""
import streamlit as st
import plotly.express as px
import plotly.graph_objects as go
import pandas as pd
def create_care_plan_timeline(care_plan_data):
"""
Create a timeline visualization for care plan interventions.
Args:
care_plan_data: List of interventions with dates
Returns:
Plotly figure
"""
if not care_plan_data:
return None
df = pd.DataFrame(care_plan_data)
fig = px.timeline(
df,
x_start="start_date",
x_end="end_date",
y="intervention",
color="status",
title="Care Plan Timeline",
labels={"intervention": "Intervention", "status": "Status"}
)
fig.update_xaxes(type="date")
return fig
def create_assessment_radar(assessment_scores):
"""
Create a radar chart for multiple assessment domains.
Args:
assessment_scores: Dict with domain names and scores (0-100)
Returns:
Plotly figure
"""
if not assessment_scores:
return None
categories = list(assessment_scores.keys())
values = list(assessment_scores.values())
fig = go.Figure(data=go.Scatterpolar(
r=values,
theta=categories,
fill='toself',
name='Assessment Score'
))
fig.update_layout(
polar=dict(radialaxis=dict(
visible=True,
range=[0, 100]
)),
title="Clinical Assessment Profile",
showlegend=True
)
return fig
def create_health_indicators_gauge(
indicator_name,
current_value,
target_value
):
"""
Create a gauge chart for health indicators.
Args:
indicator_name: Name of the health indicator
current_value: Current value
target_value: Target value
Returns:
Plotly figure
"""
fig = go.Figure(data=go.Indicator(
mode="gauge+number+delta",
value=current_value,
delta={'reference': target_value},
gauge={
'axis': {'range': [0, 100]},
'bar': {'color': "darkblue"},
'steps': [
{'range': [0, 33], 'color': "lightgray"},
{'range': [33, 66], 'color': "gray"}
],
'threshold': {
'line': {'color': "red", 'width': 4},
'thickness': 0.75,
'value': target_value
}
},
title={'text': indicator_name}
))
return fig
def create_problem_severity_chart(problems):
"""
Create a bar chart showing problem severity.
Args:
problems: List of dict with 'name' and 'severity' (0-10)
Returns:
Plotly figure
"""
if not problems:
return None
df = pd.DataFrame(problems)
fig = px.bar(
df,
x="severity",
y="name",
orientation="h",
color="severity",
color_continuous_scale="Reds",
title="Nursing Problem Severity Assessment",
labels={"severity": "Severity Score", "name": "Problem"}
)
return fig
def create_goal_progress_chart(goals):
"""
Create a progress bar chart for care goals.
Args:
goals: List of dict with 'goal_name' and 'progress' (0-100)
Returns:
Plotly figure
"""
if not goals:
return None
df = pd.DataFrame(goals)
fig = px.bar(
df,
x="progress",
y="goal_name",
orientation="h",
color="progress",
color_continuous_scale="Greens",
title="Care Goal Progress",
labels={"progress": "Progress (%)", "goal_name": "Goal"}
)
return fig
def create_intervention_effectiveness_chart(interventions):
"""
Create a chart showing intervention effectiveness.
Args:
interventions: List of dict with 'intervention' and 'effectiveness'
Returns:
Plotly figure
"""
if not interventions:
return None
df = pd.DataFrame(interventions)
fig = px.scatter(
df,
x="duration_days",
y="effectiveness",
size="patient_benefit",
color="category",
hover_name="intervention",
title="Intervention Effectiveness Analysis",
labels={
"duration_days": "Duration (Days)",
"effectiveness": "Effectiveness Score",
"category": "Category"
}
)
return fig
def create_risk_assessment_heatmap(risks):
"""
Create a heatmap for risk assessment.
Args:
risks: 2D list with risk scores
Returns:
Plotly figure
"""
fig = px.imshow(
risks,
labels=dict(
x="Risk Factor",
y="Patient ID",
color="Risk Level"
),
color_continuous_scale="YlOrRd",
title="Risk Assessment Heatmap"
)
return fig
def display_care_plan_dashboard():
"""Display a comprehensive care plan dashboard."""
st.subheader("π Care Plan Dashboard")
col1, col2 = st.columns(2)
with col1:
st.metric(
"Active Care Goals",
5,
delta="+2 this week",
delta_color="normal"
)
with col2:
st.metric(
"Goal Achievement Rate",
"78%",
delta="+5%",
delta_color="off"
)
st.divider()
# Sample care plan data
sample_goals = [
{"goal_name": "Pain Management", "progress": 85},
{"goal_name": "Mobility Improvement", "progress": 60},
{"goal_name": "Nutritional Intake", "progress": 92},
{"goal_name": "Wound Healing", "progress": 45},
{"goal_name": "Patient Education", "progress": 78}
]
fig_goals = create_goal_progress_chart(sample_goals)
if fig_goals:
st.plotly_chart(fig_goals, use_container_width=True)
st.divider()
# Assessment scores
sample_assessment = {
"Mobility": 65,
"Nutrition": 78,
"Continence": 45,
"Mental Health": 82,
"Pain": 35,
"Communication": 90
}
fig_assessment = create_assessment_radar(sample_assessment)
if fig_assessment:
st.plotly_chart(fig_assessment, use_container_width=True)
def display_problem_assessment():
"""Display problem assessment visualizations."""
st.subheader("π Problem Assessment")
sample_problems = [
{"name": "Acute Pain", "severity": 8},
{"name": "Limited Mobility", "severity": 6},
{"name": "Risk of Falls", "severity": 7},
{"name": "Impaired Nutrition", "severity": 5},
{"name": "Sleep Disturbance", "severity": 6}
]
fig_severity = create_problem_severity_chart(sample_problems)
if fig_severity:
st.plotly_chart(fig_severity, use_container_width=True)
def display_intervention_analysis():
"""Display intervention effectiveness analysis."""
st.subheader("π Intervention Analysis")
sample_interventions = [
{
"intervention": "Pain Medication",
"duration_days": 7,
"effectiveness": 8.5,
"patient_benefit": 85,
"category": "Pharmacological"
},
{
"intervention": "Physical Therapy",
"duration_days": 14,
"effectiveness": 7.2,
"patient_benefit": 72,
"category": "Rehabilitation"
},
{
"intervention": "Nutritional Support",
"duration_days": 10,
"effectiveness": 6.8,
"patient_benefit": 68,
"category": "Supportive Care"
},
{
"intervention": "Patient Education",
"duration_days": 5,
"effectiveness": 7.9,
"patient_benefit": 79,
"category": "Educational"
}
]
fig_interventions = create_intervention_effectiveness_chart(
sample_interventions
)
if fig_interventions:
st.plotly_chart(fig_interventions, use_container_width=True)
def display_health_indicators():
"""Display health indicators with gauges."""
st.subheader("π Health Indicators")
col1, col2, col3 = st.columns(3)
indicators = [
("Blood Pressure", 78, 80),
("Oxygen Saturation", 96, 95),
("Pain Score", 35, 30)
]
for idx, (name, current, target) in enumerate(indicators):
with st.columns(3)[idx % 3]:
fig = create_health_indicators_gauge(name, current, target)
st.plotly_chart(fig, use_container_width=True)
if __name__ == "__main__":
st.set_page_config(page_title="Nursing Visualizations")
st.title("π₯ Nursing Care Plan Visualizations")
page = st.sidebar.radio(
"Select View",
["Care Plan Dashboard", "Problem Assessment", "Intervention Analysis",
"Health Indicators"]
)
if page == "Care Plan Dashboard":
display_care_plan_dashboard()
elif page == "Problem Assessment":
display_problem_assessment()
elif page == "Intervention Analysis":
display_intervention_analysis()
elif page == "Health Indicators":
display_health_indicators()
|