PragmaticPete commited on
Commit
d3359f6
·
verified ·
1 Parent(s): a447eaf

Update logic/financial_model.py

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