hccinfhir 0.0.3__tar.gz → 0.0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. {hccinfhir-0.0.3 → hccinfhir-0.0.5}/PKG-INFO +147 -9
  2. {hccinfhir-0.0.3 → hccinfhir-0.0.5}/README.md +146 -8
  3. hccinfhir-0.0.5/hccinfhir/data/ra_coefficients_2025.csv +6352 -0
  4. hccinfhir-0.0.5/hccinfhir/data/ra_dx_to_cc_2025.csv +53952 -0
  5. hccinfhir-0.0.5/hccinfhir/data/ra_eligible_cpt_hcpcs_2024.csv +6697 -0
  6. hccinfhir-0.0.5/hccinfhir/data/ra_eligible_cpt_hcpcs_2025.csv +6725 -0
  7. hccinfhir-0.0.5/hccinfhir/data/ra_hierarchies_2025.csv +487 -0
  8. hccinfhir-0.0.5/hccinfhir/datamodels.py +101 -0
  9. {hccinfhir-0.0.3 → hccinfhir-0.0.5}/hccinfhir/extractor.py +3 -3
  10. {hccinfhir-0.0.3 → hccinfhir-0.0.5}/hccinfhir/extractor_837.py +1 -2
  11. {hccinfhir-0.0.3 → hccinfhir-0.0.5}/hccinfhir/extractor_fhir.py +1 -1
  12. {hccinfhir-0.0.3 → hccinfhir-0.0.5}/hccinfhir/filter.py +3 -5
  13. hccinfhir-0.0.5/hccinfhir/hccinfhir.py +149 -0
  14. hccinfhir-0.0.5/hccinfhir/model_calculate.py +95 -0
  15. hccinfhir-0.0.5/hccinfhir/model_coefficients.py +143 -0
  16. hccinfhir-0.0.5/hccinfhir/model_demographics.py +191 -0
  17. hccinfhir-0.0.5/hccinfhir/model_dx_to_cc.py +54 -0
  18. hccinfhir-0.0.5/hccinfhir/model_hierarchies.py +70 -0
  19. hccinfhir-0.0.5/hccinfhir/model_interactions.py +342 -0
  20. hccinfhir-0.0.5/hccinfhir/samples/__init__.py +2 -0
  21. hccinfhir-0.0.5/hccinfhir/utils.py +51 -0
  22. {hccinfhir-0.0.3 → hccinfhir-0.0.5}/pyproject.toml +2 -2
  23. hccinfhir-0.0.3/hccinfhir/models.py +0 -44
  24. {hccinfhir-0.0.3 → hccinfhir-0.0.5}/.gitignore +0 -0
  25. {hccinfhir-0.0.3 → hccinfhir-0.0.5}/LICENSE +0 -0
  26. {hccinfhir-0.0.3 → hccinfhir-0.0.5}/hccinfhir/__init__.py +0 -0
  27. {hccinfhir-0.0.3 → hccinfhir-0.0.5}/hccinfhir/data/__init__.py +0 -0
  28. {hccinfhir-0.0.3 → hccinfhir-0.0.5}/hccinfhir/data/ra_eligible_cpt_hcpcs_2023.csv +0 -0
  29. {hccinfhir-0.0.3/hccinfhir/data → hccinfhir-0.0.5/hccinfhir/samples}/sample_837_0.txt +0 -0
  30. {hccinfhir-0.0.3/hccinfhir/data → hccinfhir-0.0.5/hccinfhir/samples}/sample_837_1.txt +0 -0
  31. {hccinfhir-0.0.3/hccinfhir/data → hccinfhir-0.0.5/hccinfhir/samples}/sample_837_10.txt +0 -0
  32. {hccinfhir-0.0.3/hccinfhir/data → hccinfhir-0.0.5/hccinfhir/samples}/sample_837_11.txt +0 -0
  33. {hccinfhir-0.0.3/hccinfhir/data → hccinfhir-0.0.5/hccinfhir/samples}/sample_837_2.txt +0 -0
  34. {hccinfhir-0.0.3/hccinfhir/data → hccinfhir-0.0.5/hccinfhir/samples}/sample_837_3.txt +0 -0
  35. {hccinfhir-0.0.3/hccinfhir/data → hccinfhir-0.0.5/hccinfhir/samples}/sample_837_4.txt +0 -0
  36. {hccinfhir-0.0.3/hccinfhir/data → hccinfhir-0.0.5/hccinfhir/samples}/sample_837_5.txt +0 -0
  37. {hccinfhir-0.0.3/hccinfhir/data → hccinfhir-0.0.5/hccinfhir/samples}/sample_837_6.txt +0 -0
  38. {hccinfhir-0.0.3/hccinfhir/data → hccinfhir-0.0.5/hccinfhir/samples}/sample_837_7.txt +0 -0
  39. {hccinfhir-0.0.3/hccinfhir/data → hccinfhir-0.0.5/hccinfhir/samples}/sample_837_8.txt +0 -0
  40. {hccinfhir-0.0.3/hccinfhir/data → hccinfhir-0.0.5/hccinfhir/samples}/sample_837_9.txt +0 -0
  41. {hccinfhir-0.0.3/hccinfhir/data → hccinfhir-0.0.5/hccinfhir/samples}/sample_eob_1.json +0 -0
  42. {hccinfhir-0.0.3/hccinfhir/data → hccinfhir-0.0.5/hccinfhir/samples}/sample_eob_2.json +0 -0
  43. {hccinfhir-0.0.3/hccinfhir/data → hccinfhir-0.0.5/hccinfhir/samples}/sample_eob_200.ndjson +0 -0
  44. {hccinfhir-0.0.3/hccinfhir/data → hccinfhir-0.0.5/hccinfhir/samples}/sample_eob_3.json +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: hccinfhir
3
- Version: 0.0.3
3
+ Version: 0.0.5
4
4
  Summary: HCC Algorithm for FHIR Resources
5
5
  Project-URL: Homepage, https://github.com/mimilabs/hccinfhir
6
6
  Project-URL: Issues, https://github.com/mimilabs/hccinfhir/issues
@@ -20,6 +20,9 @@ A Python library for extracting standardized service-level data from FHIR Explan
20
20
  - Support for both BCDA (Blue Button 2.0) and standard FHIR R4 formats
21
21
  - Pydantic models for type safety and data validation
22
22
  - Standardized Service Level Data (SLD) output format
23
+ - Multiple HCC model support (V22, V24, V28, ESRD V21, ESRD V24, RxHCC V08)
24
+ - Flexible input options: FHIR EOBs, service data, or direct diagnosis codes
25
+
23
26
 
24
27
  ## Installation
25
28
  ```bash
@@ -45,7 +48,26 @@ sld = [{
45
48
  }, ...]
46
49
  ```
47
50
 
48
- For more details on the SLD format, see the `models.py` file.
51
+ Or, for direct risk score calculation from a list of diagnosis codes, you only need the model name, diagnosis codes, and basic demographic factors:
52
+
53
+ ```python
54
+ from hccinfhir.model_calculate import calculate_raf
55
+
56
+ diagnosis_codes = ['E119', 'I509'] # Diabetes without complications, Heart failure
57
+ age = 67
58
+ sex = 'F'
59
+ model_name = "CMS-HCC Model V24"
60
+
61
+ result = calculate_raf(
62
+ diagnosis_codes=diagnosis_codes,
63
+ model_name=model_name,
64
+ age=age,
65
+ sex=sex
66
+ )
67
+ ```
68
+
69
+
70
+ For more details on the SLD format, see the `datamodels.py` file.
49
71
 
50
72
  ## Core Components
51
73
 
@@ -71,23 +93,99 @@ filtered_sld = apply_filter(sld_list)
71
93
  ```
72
94
 
73
95
 
74
- ### 3. Logic Module (In Development)
96
+ ### 3. Logic Module
75
97
  Implements core HCC calculation logic:
76
98
  - Maps diagnosis codes to HCC categories
77
99
  - Applies hierarchical rules and interactions
78
100
  - Calculates final RAF scores
79
101
  - Integrates with standard CMS data files
80
102
 
81
- ## Usage
82
103
  ```python
83
- from hccinfhir import HCCInFHIR
104
+ from hccinfhir.model_calculate import calculate_raf
105
+
106
+ diagnosis_codes = ['E119', 'I509'] # Diabetes without complications, Heart failure
107
+ result = calculate_raf(
108
+ diagnosis_codes=diagnosis_codes,
109
+ model_name="CMS-HCC Model V24",
110
+ age=67,
111
+ sex='F'
112
+ )
113
+ ```
84
114
 
85
- hcc_processor = HCCInFHIR()
86
- sld_list = hcc_processor.extract_sld_list(eob_list)
87
- filtered_sld = hcc_processor.apply_filters(sld_list) # future
88
- raf_details = hcc_processor.calculate_raf(filtered_sld, demographic_data) # future
115
+ ### 4. HCCInFHIR Class
116
+ The main processor class that integrates extraction, filtering, and calculation components:
117
+
118
+ ```python
119
+ from hccinfhir.hccinfhir import HCCInFHIR
120
+ from hccinfhir.datamodels import Demographics
121
+
122
+ # Initialize with custom configuration
123
+ hcc_processor = HCCInFHIR(
124
+ filter_claims=True, # Enable claim filtering
125
+ model_name="CMS-HCC Model V28", # Choose HCC model version
126
+ proc_filtering_filename="ra_eligible_cpt_hcpcs_2025.csv", # CPT/HCPCS filtering rules
127
+ dx_cc_mapping_filename="ra_dx_to_cc_2025.csv" # Diagnosis to CC mapping
128
+ )
129
+
130
+ # Define beneficiary demographics
131
+ demographics = Demographics(
132
+ age=67,
133
+ sex='F',
134
+ dual_elgbl_cd='00', # Not dual eligible
135
+ orec='0', # Old age
136
+ crec='0', # Current old age
137
+ new_enrollee=False,
138
+ snp=False
139
+ )
140
+
141
+ # Method 1: Process FHIR EOB resources
142
+ raf_result = hcc_processor.run(eob_list, demographics)
143
+
144
+ # Method 2: Process service level data
145
+ service_data = [{
146
+ "procedure_code": "99214",
147
+ "claim_diagnosis_codes": ["E11.9", "I10"],
148
+ "claim_type": "71",
149
+ "service_date": "2024-01-15"
150
+ }]
151
+ raf_result = hcc_processor.run_from_service_data(service_data, demographics)
152
+
153
+ # Method 3: Direct diagnosis processing
154
+ diagnosis_codes = ['E119', 'I509']
155
+ raf_result = hcc_processor.calculate_from_diagnosis(diagnosis_codes, demographics)
156
+
157
+ # RAF Result contains:
158
+ print(f"Risk Score: {raf_result['risk_score']}")
159
+ print(f"HCC List: {raf_result['hcc_list']}")
160
+ print(f"CC to Diagnosis Mapping: {raf_result['cc_to_dx']}")
161
+ print(f"Applied Coefficients: {raf_result['coefficients']}")
162
+ print(f"Applied Interactions: {raf_result['interactions']}")
89
163
  ```
90
164
 
165
+ The HCCInFHIR class provides three main processing methods:
166
+
167
+ 1. `run(eob_list, demographics)`: Process FHIR ExplanationOfBenefit resources
168
+ - Extracts service data from FHIR resources
169
+ - Applies filtering rules if enabled
170
+ - Calculates RAF scores using the specified model
171
+
172
+ 2. `run_from_service_data(service_data, demographics)`: Process standardized service data
173
+ - Accepts pre-formatted service level data
174
+ - Validates data structure using Pydantic models
175
+ - Applies filtering and calculates RAF scores
176
+
177
+ 3. `calculate_from_diagnosis(diagnosis_codes, demographics)`: Direct diagnosis processing
178
+ - Processes raw diagnosis codes without service context
179
+ - Useful for quick RAF calculations or validation
180
+ - Bypasses service-level filtering
181
+
182
+ Each method returns a RAFResult containing:
183
+ - Final risk score
184
+ - List of HCCs
185
+ - Mapping of condition categories to diagnosis codes
186
+ - Applied coefficients and interactions
187
+ - Processed service level data (when applicable)
188
+
91
189
  ## Testing
92
190
  ```bash
93
191
  $ python3 -m hatch shell
@@ -172,8 +270,48 @@ $ python3 -m pytest tests/*
172
270
  3. Add support for allowed_amount in 837 if available in different segments
173
271
  4. Consider adding more robust error handling in both implementations
174
272
 
273
+ ## Data Files
274
+
275
+ `ra_dx_to_cc_mapping_2025.csv`
276
+ ```sql
277
+ SELECT diagnosis_code, cc, model_name
278
+ FROM ra_dx_to_cc_mapping
279
+ WHERE year = 2025 and model_type = 'Initial';
280
+ ```
281
+
282
+ `ra_hierarchies_2025.csv`
283
+ ```sql
284
+ SELECT cc_parent,
285
+ cc_child,
286
+ model_domain,
287
+ model_version,
288
+ model_fullname
289
+ FROM ra_hierarchies
290
+ WHERE eff_last_date > '2025-01-01';
291
+ ```
292
+
293
+ `ra_coefficients_2025.csv`
294
+ ```sql
295
+ SELECT coefficient, value, model_domain, model_version
296
+ FROM ra_coefficients
297
+ WHERE eff_last_date > '2025-01-01';
298
+ ```
299
+
300
+ `ra_eligible_cpt_hcpcs_2025.csv`
301
+ ```sql
302
+ SELECT DISTINCT cpt_hcpcs_code
303
+ FROM mimi_ws_1.cmspayment.ra_eligible_cpt_hcpcs
304
+ WHERE is_included = 'yes' AND YEAR(mimi_src_file_date) = 2024;
305
+ ```
306
+
175
307
  ## Contributing
176
308
  Join us at [mimilabs](https://mimilabs.ai/signup). Reference data available in MIMILabs data lakehouse.
177
309
 
310
+ ## Publishing (only for those maintainers...)
311
+ ```bash
312
+ $ hatch build
313
+ $ hatch publish
314
+ ```
315
+
178
316
  ## License
179
317
  Apache License 2.0
@@ -6,6 +6,9 @@ A Python library for extracting standardized service-level data from FHIR Explan
6
6
  - Support for both BCDA (Blue Button 2.0) and standard FHIR R4 formats
7
7
  - Pydantic models for type safety and data validation
8
8
  - Standardized Service Level Data (SLD) output format
9
+ - Multiple HCC model support (V22, V24, V28, ESRD V21, ESRD V24, RxHCC V08)
10
+ - Flexible input options: FHIR EOBs, service data, or direct diagnosis codes
11
+
9
12
 
10
13
  ## Installation
11
14
  ```bash
@@ -31,7 +34,26 @@ sld = [{
31
34
  }, ...]
32
35
  ```
33
36
 
34
- For more details on the SLD format, see the `models.py` file.
37
+ Or, for direct risk score calculation from a list of diagnosis codes, you only need the model name, diagnosis codes, and basic demographic factors:
38
+
39
+ ```python
40
+ from hccinfhir.model_calculate import calculate_raf
41
+
42
+ diagnosis_codes = ['E119', 'I509'] # Diabetes without complications, Heart failure
43
+ age = 67
44
+ sex = 'F'
45
+ model_name = "CMS-HCC Model V24"
46
+
47
+ result = calculate_raf(
48
+ diagnosis_codes=diagnosis_codes,
49
+ model_name=model_name,
50
+ age=age,
51
+ sex=sex
52
+ )
53
+ ```
54
+
55
+
56
+ For more details on the SLD format, see the `datamodels.py` file.
35
57
 
36
58
  ## Core Components
37
59
 
@@ -57,23 +79,99 @@ filtered_sld = apply_filter(sld_list)
57
79
  ```
58
80
 
59
81
 
60
- ### 3. Logic Module (In Development)
82
+ ### 3. Logic Module
61
83
  Implements core HCC calculation logic:
62
84
  - Maps diagnosis codes to HCC categories
63
85
  - Applies hierarchical rules and interactions
64
86
  - Calculates final RAF scores
65
87
  - Integrates with standard CMS data files
66
88
 
67
- ## Usage
68
89
  ```python
69
- from hccinfhir import HCCInFHIR
90
+ from hccinfhir.model_calculate import calculate_raf
91
+
92
+ diagnosis_codes = ['E119', 'I509'] # Diabetes without complications, Heart failure
93
+ result = calculate_raf(
94
+ diagnosis_codes=diagnosis_codes,
95
+ model_name="CMS-HCC Model V24",
96
+ age=67,
97
+ sex='F'
98
+ )
99
+ ```
70
100
 
71
- hcc_processor = HCCInFHIR()
72
- sld_list = hcc_processor.extract_sld_list(eob_list)
73
- filtered_sld = hcc_processor.apply_filters(sld_list) # future
74
- raf_details = hcc_processor.calculate_raf(filtered_sld, demographic_data) # future
101
+ ### 4. HCCInFHIR Class
102
+ The main processor class that integrates extraction, filtering, and calculation components:
103
+
104
+ ```python
105
+ from hccinfhir.hccinfhir import HCCInFHIR
106
+ from hccinfhir.datamodels import Demographics
107
+
108
+ # Initialize with custom configuration
109
+ hcc_processor = HCCInFHIR(
110
+ filter_claims=True, # Enable claim filtering
111
+ model_name="CMS-HCC Model V28", # Choose HCC model version
112
+ proc_filtering_filename="ra_eligible_cpt_hcpcs_2025.csv", # CPT/HCPCS filtering rules
113
+ dx_cc_mapping_filename="ra_dx_to_cc_2025.csv" # Diagnosis to CC mapping
114
+ )
115
+
116
+ # Define beneficiary demographics
117
+ demographics = Demographics(
118
+ age=67,
119
+ sex='F',
120
+ dual_elgbl_cd='00', # Not dual eligible
121
+ orec='0', # Old age
122
+ crec='0', # Current old age
123
+ new_enrollee=False,
124
+ snp=False
125
+ )
126
+
127
+ # Method 1: Process FHIR EOB resources
128
+ raf_result = hcc_processor.run(eob_list, demographics)
129
+
130
+ # Method 2: Process service level data
131
+ service_data = [{
132
+ "procedure_code": "99214",
133
+ "claim_diagnosis_codes": ["E11.9", "I10"],
134
+ "claim_type": "71",
135
+ "service_date": "2024-01-15"
136
+ }]
137
+ raf_result = hcc_processor.run_from_service_data(service_data, demographics)
138
+
139
+ # Method 3: Direct diagnosis processing
140
+ diagnosis_codes = ['E119', 'I509']
141
+ raf_result = hcc_processor.calculate_from_diagnosis(diagnosis_codes, demographics)
142
+
143
+ # RAF Result contains:
144
+ print(f"Risk Score: {raf_result['risk_score']}")
145
+ print(f"HCC List: {raf_result['hcc_list']}")
146
+ print(f"CC to Diagnosis Mapping: {raf_result['cc_to_dx']}")
147
+ print(f"Applied Coefficients: {raf_result['coefficients']}")
148
+ print(f"Applied Interactions: {raf_result['interactions']}")
75
149
  ```
76
150
 
151
+ The HCCInFHIR class provides three main processing methods:
152
+
153
+ 1. `run(eob_list, demographics)`: Process FHIR ExplanationOfBenefit resources
154
+ - Extracts service data from FHIR resources
155
+ - Applies filtering rules if enabled
156
+ - Calculates RAF scores using the specified model
157
+
158
+ 2. `run_from_service_data(service_data, demographics)`: Process standardized service data
159
+ - Accepts pre-formatted service level data
160
+ - Validates data structure using Pydantic models
161
+ - Applies filtering and calculates RAF scores
162
+
163
+ 3. `calculate_from_diagnosis(diagnosis_codes, demographics)`: Direct diagnosis processing
164
+ - Processes raw diagnosis codes without service context
165
+ - Useful for quick RAF calculations or validation
166
+ - Bypasses service-level filtering
167
+
168
+ Each method returns a RAFResult containing:
169
+ - Final risk score
170
+ - List of HCCs
171
+ - Mapping of condition categories to diagnosis codes
172
+ - Applied coefficients and interactions
173
+ - Processed service level data (when applicable)
174
+
77
175
  ## Testing
78
176
  ```bash
79
177
  $ python3 -m hatch shell
@@ -158,8 +256,48 @@ $ python3 -m pytest tests/*
158
256
  3. Add support for allowed_amount in 837 if available in different segments
159
257
  4. Consider adding more robust error handling in both implementations
160
258
 
259
+ ## Data Files
260
+
261
+ `ra_dx_to_cc_mapping_2025.csv`
262
+ ```sql
263
+ SELECT diagnosis_code, cc, model_name
264
+ FROM ra_dx_to_cc_mapping
265
+ WHERE year = 2025 and model_type = 'Initial';
266
+ ```
267
+
268
+ `ra_hierarchies_2025.csv`
269
+ ```sql
270
+ SELECT cc_parent,
271
+ cc_child,
272
+ model_domain,
273
+ model_version,
274
+ model_fullname
275
+ FROM ra_hierarchies
276
+ WHERE eff_last_date > '2025-01-01';
277
+ ```
278
+
279
+ `ra_coefficients_2025.csv`
280
+ ```sql
281
+ SELECT coefficient, value, model_domain, model_version
282
+ FROM ra_coefficients
283
+ WHERE eff_last_date > '2025-01-01';
284
+ ```
285
+
286
+ `ra_eligible_cpt_hcpcs_2025.csv`
287
+ ```sql
288
+ SELECT DISTINCT cpt_hcpcs_code
289
+ FROM mimi_ws_1.cmspayment.ra_eligible_cpt_hcpcs
290
+ WHERE is_included = 'yes' AND YEAR(mimi_src_file_date) = 2024;
291
+ ```
292
+
161
293
  ## Contributing
162
294
  Join us at [mimilabs](https://mimilabs.ai/signup). Reference data available in MIMILabs data lakehouse.
163
295
 
296
+ ## Publishing (only for those maintainers...)
297
+ ```bash
298
+ $ hatch build
299
+ $ hatch publish
300
+ ```
301
+
164
302
  ## License
165
303
  Apache License 2.0