Spaces:
Sleeping
Sleeping
Update logic/financial_model.py
Browse files- logic/financial_model.py +33 -26
logic/financial_model.py
CHANGED
@@ -1,26 +1,33 @@
|
|
1 |
-
# File: logic/financial_model.py
|
2 |
-
|
3 |
-
def
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# File: logic/financial_model.py
|
2 |
+
|
3 |
+
def normalize_bool(value):
|
4 |
+
if isinstance(value, str):
|
5 |
+
value = value.strip().lower()
|
6 |
+
return value in ["yes", "true", "1"]
|
7 |
+
return bool(value)
|
8 |
+
|
9 |
+
def estimate_financial_recovery(care_gaps_df, patient_data, base_rate, sdoh_keys):
|
10 |
+
results = []
|
11 |
+
hcc_weights = {
|
12 |
+
'HCC18': 0.4, 'HCC85': 0.5, 'HCC19': 0.3
|
13 |
+
}
|
14 |
+
|
15 |
+
for _, row in care_gaps_df.iterrows():
|
16 |
+
patient = patient_data[patient_data['patient_id'] == row['patient_id']].iloc[0]
|
17 |
+
hccs = [h.strip() for h in str(patient.get('hcc_codes', '')).split(';') if h.strip() in hcc_weights]
|
18 |
+
risk_score = sum(hcc_weights[h] for h in hccs)
|
19 |
+
|
20 |
+
sdoh_count = sum(1 for key in sdoh_keys if normalize_bool(patient.get(key)))
|
21 |
+
sdoh_modifier = 1 + 0.05 * sdoh_count # Each SDOH adds 5% to the opportunity
|
22 |
+
|
23 |
+
care_gap_count = len(row['care_gaps'])
|
24 |
+
expected_gain = base_rate * (risk_score * 0.02 * care_gap_count) * sdoh_modifier
|
25 |
+
|
26 |
+
results.append({
|
27 |
+
'patient_id': row['patient_id'],
|
28 |
+
'risk_score': round(risk_score, 2),
|
29 |
+
'projected_gain': round(expected_gain, 2),
|
30 |
+
'sdoh_flags': sdoh_count
|
31 |
+
})
|
32 |
+
|
33 |
+
return pd.DataFrame(results)
|