Skip to content

Commit 4a2abbf

Browse files
author
mounika
committed
update the app
1 parent de9c5df commit 4a2abbf

3 files changed

Lines changed: 89 additions & 130 deletions

File tree

src/app.py

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,67 @@ def get_patient_observations(patient_id, credentials):
6969
observations[obs_name] = 'Not Found'
7070
return observations, demographics
7171

72+
def calculate_ascvd_risk(age, sex, race, total_cholesterol, hdl_cholesterol, systolic_bp, on_hypertension_treatment, diabetes, smoker):
73+
# Simplified ASCVD risk calculation
74+
# Note: This is a placeholder. Use a proper ASCVD risk calculator for accurate results.
75+
risk_score = 0
76+
if sex == 'male':
77+
risk_score += 1
78+
if race == 'African American':
79+
risk_score += 1
80+
risk_score += age / 10
81+
risk_score += total_cholesterol / 50
82+
risk_score -= hdl_cholesterol / 50
83+
risk_score += systolic_bp / 20
84+
if on_hypertension_treatment == 'yes':
85+
risk_score += 1
86+
if diabetes == 'yes':
87+
risk_score += 1
88+
if smoker == 'yes':
89+
risk_score += 1
90+
return round(risk_score, 2)
91+
7292
@app.route('/', methods=['GET', 'POST'])
7393
def index():
7494
observations = None
7595
demographics = None
76-
additional_fields = {}
77-
78-
if request.method == 'POST':
79-
patient_id = request.form['patient_id']
80-
additional_fields['diabetes'] = request.form.get('diabetes')
81-
additional_fields['smoker'] = request.form.get('smoker')
82-
additional_fields['hypertension'] = request.form.get('hypertension')
83-
additional_fields['statin'] = request.form.get('statin')
84-
additional_fields['aspirin'] = request.form.get('aspirin')
85-
credentials = (username, password)
86-
observations, demographics = get_patient_observations(patient_id, credentials)
87-
# Capture additional inputs from the user
88-
demographics['age'] = request.form.get('age') or demographics['age']
89-
demographics['sex'] = request.form.get('sex') or demographics['sex']
90-
demographics['race'] = request.form.get('race') or demographics['race']
91-
for obs_name in observation_codes.keys():
92-
form_name = obs_name.replace(' ', '_').lower()
93-
observations[obs_name] = request.form.get(form_name) or observations[obs_name]
94-
95-
return render_template('index.html', observations=observations, demographics=demographics, additional_fields=additional_fields)
96+
ascvd_risk = None
97+
98+
return render_template('index.html', observations=observations, demographics=demographics, ascvd_risk=ascvd_risk)
99+
100+
@app.route('/fetch_patient_data', methods=['POST'])
101+
def fetch_patient_data():
102+
patient_id = request.form['patient_id']
103+
credentials = (username, password)
104+
observations, demographics = get_patient_observations(patient_id, credentials)
105+
return render_template('index.html', observations=observations, demographics=demographics, patient_id=patient_id)
106+
107+
@app.route('/calculate_risk', methods=['POST'])
108+
def calculate_risk():
109+
patient_id = request.form.get('patient_id')
110+
age = int(request.form['age'])
111+
sex = request.form['sex']
112+
race = request.form['race']
113+
total_cholesterol = float(request.form['total_cholesterol'])
114+
hdl_cholesterol = float(request.form['hdl_cholesterol'])
115+
systolic_bp = float(request.form['systolic_blood_pressure'])
116+
diabetes = request.form['diabetes']
117+
smoker = request.form['smoker']
118+
hypertension = request.form['hypertension']
119+
120+
ascvd_risk = calculate_ascvd_risk(age, sex, race, total_cholesterol, hdl_cholesterol, systolic_bp, hypertension, diabetes, smoker)
121+
122+
# Maintain the form values for observations and demographics
123+
demographics = {'age': age, 'sex': sex, 'race': race}
124+
observations = {
125+
'Total Cholesterol': total_cholesterol,
126+
'HDL Cholesterol': hdl_cholesterol,
127+
'Systolic Blood Pressure': systolic_bp,
128+
'Diastolic Blood Pressure': request.form['diastolic_blood_pressure'] if 'diastolic_blood_pressure' in request.form else 'Not Found',
129+
'LDL Cholesterol': request.form['ldl_cholesterol'] if 'ldl_cholesterol' in request.form else 'Not Found'
130+
}
131+
132+
return render_template('index.html', ascvd_risk=ascvd_risk, demographics=demographics, observations=observations, patient_id=patient_id)
96133

97134
if __name__ == '__main__':
98135
port_str = os.environ['FHIR_PORT']

src/templates/ascvd.html

Lines changed: 0 additions & 98 deletions
This file was deleted.

src/templates/index.html

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,35 +57,49 @@
5757
margin-bottom: 10px;
5858
box-sizing: border-box;
5959
}
60+
.ascvd-risk {
61+
margin-top: 20px;
62+
font-size: 1.2em;
63+
font-weight: bold;
64+
}
6065
</style>
6166
</head>
6267
<body>
6368
<div class="container">
6469
<h1>ASCVD Risk Calculator</h1>
6570

66-
<form method="post" onsubmit="clearPreviousResults()" class="form-container">
71+
<!-- Form for fetching patient data using patient ID -->
72+
<form method="post" action="/fetch_patient_data" onsubmit="clearPreviousResults()" class="form-container">
6773
<div class="form-group">
6874
<label for="patient_id">Enter a Patient ID:</label>
6975
<input type="text" name="patient_id" id="patient_id" required>
7076
</div>
71-
<input type="submit" value="Search">
77+
<input type="submit" value="Fetch Patient Data">
7278
</form>
7379

7480
<div id="results" class="results-container">
75-
<form method="post" class="form-container">
81+
<form method="post" action="/calculate_risk" class="form-container">
7682
{% if demographics %}
77-
<label>Age:</label>
78-
<input type="text" name="age" value="{{ demographics.age if demographics.age != 'Not Found' else '' }}" placeholder="{{ 'Not Found' if demographics.age == 'Not Found' else '' }}" required>
79-
<label>Sex:</label>
80-
<input type="text" name="sex" value="{{ demographics.sex if demographics.sex != 'Not Found' else '' }}" placeholder="{{ 'Not Found' if demographics.sex == 'Not Found' else '' }}" required>
81-
<label>Race:</label>
82-
<input type="text" name="race" value="{{ demographics.race if demographics.race != 'Not Found' else '' }}" placeholder="{{ 'Not Found' if demographics.race == 'Not Found' else '' }}" required>
83+
<div class="form-group">
84+
<label>Age:</label>
85+
<input type="text" name="age" value="{{ demographics.age if demographics.age != 'Not Found' else '' }}" placeholder="{{ 'Not Found' if demographics.age == 'Not Found' else '' }}" required>
86+
</div>
87+
<div class="form-group">
88+
<label>Sex:</label>
89+
<input type="text" name="sex" value="{{ demographics.sex if demographics.sex != 'Not Found' else '' }}" placeholder="{{ 'Not Found' if demographics.sex == 'Not Found' else '' }}" required>
90+
</div>
91+
<div class="form-group">
92+
<label>Race:</label>
93+
<input type="text" name="race" value="{{ demographics.race if demographics.race != 'Not Found' else '' }}" placeholder="{{ 'Not Found' if demographics.race == 'Not Found' else '' }}" required>
94+
</div>
8395
{% endif %}
8496

8597
{% if observations %}
8698
{% for obs_name, obs_value in observations.items() %}
87-
<label>{{ obs_name }}:</label>
88-
<input type="text" name="{{ obs_name | replace(' ', '_') | lower }}" value="{{ obs_value if obs_value != 'Not Found' else '' }}" placeholder="{{ 'Not Found' if obs_value == 'Not Found' else '' }}" required>
99+
<div class="form-group">
100+
<label>{{ obs_name }}:</label>
101+
<input type="text" name="{{ obs_name | replace(' ', '_') | lower }}" value="{{ obs_value if obs_value != 'Not Found' else '' }}" placeholder="{{ 'Not Found' if obs_value == 'Not Found' else '' }}" required>
102+
</div>
89103
{% endfor %}
90104
{% endif %}
91105

@@ -129,9 +143,15 @@ <h1>ASCVD Risk Calculator</h1>
129143
</div>
130144
</div>
131145

132-
<input type="submit" value="Submit Additional Info">
146+
<input type="submit" value="Calculate ASCVD Risk">
133147
</form>
134148
</div>
149+
150+
{% if ascvd_risk is not none %}
151+
<div class="ascvd-risk">
152+
ASCVD Risk Score: {{ ascvd_risk }}%
153+
</div>
154+
{% endif %}
135155
</div>
136156
</body>
137157
</html>

0 commit comments

Comments
 (0)