hccinfhir 0.0.1__tar.gz → 0.0.3__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 (34) hide show
  1. hccinfhir-0.0.3/PKG-INFO +179 -0
  2. hccinfhir-0.0.3/README.md +165 -0
  3. hccinfhir-0.0.3/hccinfhir/__init__.py +1 -0
  4. hccinfhir-0.0.3/hccinfhir/data/__init__.py +2 -0
  5. hccinfhir-0.0.3/hccinfhir/data/ra_eligible_cpt_hcpcs_2023.csv +6646 -0
  6. hccinfhir-0.0.3/hccinfhir/data/sample_837_0.txt +175 -0
  7. hccinfhir-0.0.3/hccinfhir/data/sample_837_1.txt +49 -0
  8. hccinfhir-0.0.3/hccinfhir/data/sample_837_10.txt +42 -0
  9. hccinfhir-0.0.3/hccinfhir/data/sample_837_11.txt +29 -0
  10. hccinfhir-0.0.3/hccinfhir/data/sample_837_2.txt +41 -0
  11. hccinfhir-0.0.3/hccinfhir/data/sample_837_3.txt +40 -0
  12. hccinfhir-0.0.3/hccinfhir/data/sample_837_4.txt +38 -0
  13. hccinfhir-0.0.3/hccinfhir/data/sample_837_5.txt +48 -0
  14. hccinfhir-0.0.3/hccinfhir/data/sample_837_6.txt +52 -0
  15. hccinfhir-0.0.3/hccinfhir/data/sample_837_7.txt +47 -0
  16. hccinfhir-0.0.3/hccinfhir/data/sample_837_8.txt +45 -0
  17. hccinfhir-0.0.3/hccinfhir/data/sample_837_9.txt +50 -0
  18. hccinfhir-0.0.3/hccinfhir/data/sample_eob_200.ndjson +200 -0
  19. hccinfhir-0.0.3/hccinfhir/extractor.py +51 -0
  20. hccinfhir-0.0.3/hccinfhir/extractor_837.py +175 -0
  21. hccinfhir-0.0.3/hccinfhir/extractor_fhir.py +193 -0
  22. hccinfhir-0.0.3/hccinfhir/filter.py +43 -0
  23. hccinfhir-0.0.3/hccinfhir/models.py +44 -0
  24. {hccinfhir-0.0.1 → hccinfhir-0.0.3}/pyproject.toml +1 -1
  25. hccinfhir-0.0.1/PKG-INFO +0 -89
  26. hccinfhir-0.0.1/README.md +0 -75
  27. hccinfhir-0.0.1/hccinfhir/__init__.py +0 -1
  28. hccinfhir-0.0.1/hccinfhir/data/__init__.py +0 -2
  29. hccinfhir-0.0.1/hccinfhir/extractor.py +0 -122
  30. {hccinfhir-0.0.1 → hccinfhir-0.0.3}/.gitignore +0 -0
  31. {hccinfhir-0.0.1 → hccinfhir-0.0.3}/LICENSE +0 -0
  32. {hccinfhir-0.0.1 → hccinfhir-0.0.3}/hccinfhir/data/sample_eob_1.json +0 -0
  33. {hccinfhir-0.0.1 → hccinfhir-0.0.3}/hccinfhir/data/sample_eob_2.json +0 -0
  34. {hccinfhir-0.0.1 → hccinfhir-0.0.3}/hccinfhir/data/sample_eob_3.json +0 -0
@@ -0,0 +1,179 @@
1
+ Metadata-Version: 2.3
2
+ Name: hccinfhir
3
+ Version: 0.0.3
4
+ Summary: HCC Algorithm for FHIR Resources
5
+ Project-URL: Homepage, https://github.com/mimilabs/hccinfhir
6
+ Project-URL: Issues, https://github.com/mimilabs/hccinfhir/issues
7
+ Author-email: Yubin Park <yubin.park@mimilabs.ai>
8
+ Classifier: License :: OSI Approved :: Apache Software License
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3
11
+ Requires-Python: >=3.8
12
+ Requires-Dist: pydantic>=2.10.3
13
+ Description-Content-Type: text/markdown
14
+
15
+ # `hccinfhir` (HCC in FHIR)
16
+ A Python library for extracting standardized service-level data from FHIR ExplanationOfBenefit resources, with a focus on supporting HCC (Hierarchical Condition Category) risk adjustment calculations.
17
+
18
+ ## Features
19
+ - Extract diagnosis codes, procedures, providers, and other key data elements from FHIR EOBs
20
+ - Support for both BCDA (Blue Button 2.0) and standard FHIR R4 formats
21
+ - Pydantic models for type safety and data validation
22
+ - Standardized Service Level Data (SLD) output format
23
+
24
+ ## Installation
25
+ ```bash
26
+ pip install hccinfhir
27
+ ```
28
+
29
+ ## Why FHIR-Based HCC Processing?
30
+ Risk Adjustment calculations traditionally rely on processed claims data, leading to information loss and reconciliation challenges. `hccinfhir` processes FHIR resources directly because:
31
+ - FHIR represents the source of truth with complete clinical and administrative data
32
+ - Risk Adjustment requires multiple data elements beyond diagnosis codes
33
+ - Direct processing eliminates data transformation errors and simplifies reconciliation
34
+
35
+ ## Data Model & Flexibility
36
+ While built for native FHIR processing, `hccinfhir` works with any data source that can be transformed into the SLD (Service Level Data) format:
37
+
38
+ ```python
39
+ sld = [{
40
+ "procedure_code": "99214",
41
+ "diagnosis_codes": ["E11.9", "I10"],
42
+ "claim_type": "71",
43
+ "provider_specialty": "01",
44
+ "service_date": "2024-01-15"
45
+ }, ...]
46
+ ```
47
+
48
+ For more details on the SLD format, see the `models.py` file.
49
+
50
+ ## Core Components
51
+
52
+ ### 1. Extractor Module
53
+ Processes FHIR ExplanationOfBenefit resources to extract Minimum Data Elements (MDE):
54
+ ```python
55
+ from hccinfhir.extractor import extract_sld, extract_sld_list
56
+
57
+ sld = extract_sld(eob_data) # Process single EOB
58
+
59
+ sld_list = extract_sld_list([eob1, eob2]) # Process multiple EOBs
60
+ ```
61
+
62
+ ### 2. Filter Module
63
+ Implements claim filtering rules:
64
+ - Inpatient/outpatient criteria - Type of Bill + Eligible CPT/HCPCS
65
+ - Professional service requirements - Eligible CPT/HCPCS
66
+ - Provider validation (Not in scope for this release, applicable to RAPS)
67
+ ```python
68
+ from hccinfhir.filter import apply_filter
69
+
70
+ filtered_sld = apply_filter(sld_list)
71
+ ```
72
+
73
+
74
+ ### 3. Logic Module (In Development)
75
+ Implements core HCC calculation logic:
76
+ - Maps diagnosis codes to HCC categories
77
+ - Applies hierarchical rules and interactions
78
+ - Calculates final RAF scores
79
+ - Integrates with standard CMS data files
80
+
81
+ ## Usage
82
+ ```python
83
+ from hccinfhir import HCCInFHIR
84
+
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
89
+ ```
90
+
91
+ ## Testing
92
+ ```bash
93
+ $ python3 -m hatch shell
94
+ $ python3 -m pip install -e .
95
+ $ python3 -m pytest tests/*
96
+ ```
97
+
98
+ ## Dependencies
99
+ - Pydantic >= 2.10.3
100
+ - Standard Python libraries
101
+
102
+ ## Research: FHIR BCDA and 837 Field Mapping Analysis
103
+
104
+ ### Core Identifiers
105
+ | Field | 837 Source | FHIR BCDA Source | Alignment Analysis |
106
+ |-------|------------|------------------|-------------------|
107
+ | claim_id | CLM01 segment | eob.id | ✓ Direct mapping |
108
+ | patient_id | NM109 when NM101='IL' | eob.patient.reference (last part after '/') | ✓ Aligned but different formats |
109
+
110
+ ### Provider Information
111
+ | Field | 837 Source | FHIR BCDA Source | Alignment Analysis |
112
+ |-------|------------|-------------------|-------------------|
113
+ | performing_provider_npi | NM109 when NM101='82' and NM108='XX' | careTeam member with role 'performing'/'rendering' | ✓ Aligned |
114
+ | billing_provider_npi | NM109 when NM101='85' and NM108='XX' | contained resources with NPI system identifier | ✓ Conceptually aligned |
115
+ | provider_specialty | PRV03 when PRV01='PE' | careTeam member qualification with specialty system | ✓ Aligned but different code systems |
116
+
117
+ ### Claim Type Information
118
+ | Field | 837 Source | FHIR BCDA Source | Alignment Analysis |
119
+ |-------|------------|-------------------|-------------------|
120
+ | claim_type | GS08 (mapped via CLAIM_TYPES) | eob.type with claim_type system | ✓ Aligned but different coding |
121
+ | facility_type | CLM05-1 (837I only) | facility.extension with facility_type system | ✓ Aligned for institutional claims |
122
+ | service_type | CLM05-2 (837I only) | extension or eob.type with service_type system | ✓ Aligned for institutional claims |
123
+
124
+ ### Service Line Information
125
+ | Field | 837 Source | FHIR BCDA Source | Alignment Analysis |
126
+ |-------|------------|-------------------|-------------------|
127
+ | procedure_code | SV1/SV2 segment, element 2 | item.productOrService with pr system | ✓ Aligned |
128
+ | ndc | LIN segment after service line | item.productOrService with ndc system or extension | ✓ Aligned but different locations |
129
+ | quantity | SV1/SV2 element 4 | item.quantity.value | ✓ Direct mapping |
130
+ | quantity_unit | SV1/SV2 element 5 | item.quantity.unit | ✓ Direct mapping |
131
+ | service_date | DTP segment with qualifier 472 | item.servicedPeriod or eob.billablePeriod | ✓ Aligned |
132
+ | place_of_service | SV1 element 6 | item.locationCodeableConcept with place_of_service system | ✓ Aligned |
133
+ | modifiers | SV1/SV2 segment, additional qualifiers | item.modifier with pr system | ✓ Aligned |
134
+
135
+ ### Diagnosis Information
136
+ | Field | 837 Source | FHIR BCDA Source | Alignment Analysis |
137
+ |-------|------------|-------------------|-------------------|
138
+ | linked_diagnosis_codes | SV1/SV2 diagnosis pointers + HI segment codes | item.diagnosisSequence + diagnosis lookup | ✓ Aligned but different structure |
139
+ | claim_diagnosis_codes | HI segment codes | diagnosis array with icd10cm/icd10 systems | ✓ Aligned |
140
+
141
+ ### Additional Fields
142
+ | Field | 837 Source | FHIR BCDA Source | Alignment Analysis |
143
+ |-------|------------|-------------------|-------------------|
144
+ | allowed_amount | Not available in 837 | item.adjudication with 'eligible' category | ⚠️ Only in FHIR |
145
+
146
+ ### Key Differences and Notes
147
+
148
+ 1. **Structural Differences**:
149
+ - 837 uses a segment-based approach with positional elements
150
+ - FHIR uses a nested object structure with explicit systems and codes
151
+
152
+ 2. **Code Systems**:
153
+ - FHIR explicitly defines systems for each code (via SYSTEMS constant)
154
+ - 837 uses implicit coding based on segment position and qualifiers
155
+
156
+ 3. **Data Validation**:
157
+ - FHIR implementation uses Pydantic models for validation
158
+ - 837 implements manual validation and parsing
159
+
160
+ 4. **Diagnosis Handling**:
161
+ - 837: Direct parsing from HI segment with position-based lookup
162
+ - FHIR: Uses sequence numbers and separate diagnosis array
163
+
164
+ 5. **Provider Information**:
165
+ - 837: Direct from NM1 segments with role qualifiers
166
+ - FHIR: Through careTeam structure with role coding
167
+
168
+ ### TODO: Enhancement Suggestions
169
+
170
+ 1. Consider adding validation for code systems in 837 parser to match FHIR's explicitness
171
+ 2. Standardize date handling between both implementations
172
+ 3. Add support for allowed_amount in 837 if available in different segments
173
+ 4. Consider adding more robust error handling in both implementations
174
+
175
+ ## Contributing
176
+ Join us at [mimilabs](https://mimilabs.ai/signup). Reference data available in MIMILabs data lakehouse.
177
+
178
+ ## License
179
+ Apache License 2.0
@@ -0,0 +1,165 @@
1
+ # `hccinfhir` (HCC in FHIR)
2
+ A Python library for extracting standardized service-level data from FHIR ExplanationOfBenefit resources, with a focus on supporting HCC (Hierarchical Condition Category) risk adjustment calculations.
3
+
4
+ ## Features
5
+ - Extract diagnosis codes, procedures, providers, and other key data elements from FHIR EOBs
6
+ - Support for both BCDA (Blue Button 2.0) and standard FHIR R4 formats
7
+ - Pydantic models for type safety and data validation
8
+ - Standardized Service Level Data (SLD) output format
9
+
10
+ ## Installation
11
+ ```bash
12
+ pip install hccinfhir
13
+ ```
14
+
15
+ ## Why FHIR-Based HCC Processing?
16
+ Risk Adjustment calculations traditionally rely on processed claims data, leading to information loss and reconciliation challenges. `hccinfhir` processes FHIR resources directly because:
17
+ - FHIR represents the source of truth with complete clinical and administrative data
18
+ - Risk Adjustment requires multiple data elements beyond diagnosis codes
19
+ - Direct processing eliminates data transformation errors and simplifies reconciliation
20
+
21
+ ## Data Model & Flexibility
22
+ While built for native FHIR processing, `hccinfhir` works with any data source that can be transformed into the SLD (Service Level Data) format:
23
+
24
+ ```python
25
+ sld = [{
26
+ "procedure_code": "99214",
27
+ "diagnosis_codes": ["E11.9", "I10"],
28
+ "claim_type": "71",
29
+ "provider_specialty": "01",
30
+ "service_date": "2024-01-15"
31
+ }, ...]
32
+ ```
33
+
34
+ For more details on the SLD format, see the `models.py` file.
35
+
36
+ ## Core Components
37
+
38
+ ### 1. Extractor Module
39
+ Processes FHIR ExplanationOfBenefit resources to extract Minimum Data Elements (MDE):
40
+ ```python
41
+ from hccinfhir.extractor import extract_sld, extract_sld_list
42
+
43
+ sld = extract_sld(eob_data) # Process single EOB
44
+
45
+ sld_list = extract_sld_list([eob1, eob2]) # Process multiple EOBs
46
+ ```
47
+
48
+ ### 2. Filter Module
49
+ Implements claim filtering rules:
50
+ - Inpatient/outpatient criteria - Type of Bill + Eligible CPT/HCPCS
51
+ - Professional service requirements - Eligible CPT/HCPCS
52
+ - Provider validation (Not in scope for this release, applicable to RAPS)
53
+ ```python
54
+ from hccinfhir.filter import apply_filter
55
+
56
+ filtered_sld = apply_filter(sld_list)
57
+ ```
58
+
59
+
60
+ ### 3. Logic Module (In Development)
61
+ Implements core HCC calculation logic:
62
+ - Maps diagnosis codes to HCC categories
63
+ - Applies hierarchical rules and interactions
64
+ - Calculates final RAF scores
65
+ - Integrates with standard CMS data files
66
+
67
+ ## Usage
68
+ ```python
69
+ from hccinfhir import HCCInFHIR
70
+
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
75
+ ```
76
+
77
+ ## Testing
78
+ ```bash
79
+ $ python3 -m hatch shell
80
+ $ python3 -m pip install -e .
81
+ $ python3 -m pytest tests/*
82
+ ```
83
+
84
+ ## Dependencies
85
+ - Pydantic >= 2.10.3
86
+ - Standard Python libraries
87
+
88
+ ## Research: FHIR BCDA and 837 Field Mapping Analysis
89
+
90
+ ### Core Identifiers
91
+ | Field | 837 Source | FHIR BCDA Source | Alignment Analysis |
92
+ |-------|------------|------------------|-------------------|
93
+ | claim_id | CLM01 segment | eob.id | ✓ Direct mapping |
94
+ | patient_id | NM109 when NM101='IL' | eob.patient.reference (last part after '/') | ✓ Aligned but different formats |
95
+
96
+ ### Provider Information
97
+ | Field | 837 Source | FHIR BCDA Source | Alignment Analysis |
98
+ |-------|------------|-------------------|-------------------|
99
+ | performing_provider_npi | NM109 when NM101='82' and NM108='XX' | careTeam member with role 'performing'/'rendering' | ✓ Aligned |
100
+ | billing_provider_npi | NM109 when NM101='85' and NM108='XX' | contained resources with NPI system identifier | ✓ Conceptually aligned |
101
+ | provider_specialty | PRV03 when PRV01='PE' | careTeam member qualification with specialty system | ✓ Aligned but different code systems |
102
+
103
+ ### Claim Type Information
104
+ | Field | 837 Source | FHIR BCDA Source | Alignment Analysis |
105
+ |-------|------------|-------------------|-------------------|
106
+ | claim_type | GS08 (mapped via CLAIM_TYPES) | eob.type with claim_type system | ✓ Aligned but different coding |
107
+ | facility_type | CLM05-1 (837I only) | facility.extension with facility_type system | ✓ Aligned for institutional claims |
108
+ | service_type | CLM05-2 (837I only) | extension or eob.type with service_type system | ✓ Aligned for institutional claims |
109
+
110
+ ### Service Line Information
111
+ | Field | 837 Source | FHIR BCDA Source | Alignment Analysis |
112
+ |-------|------------|-------------------|-------------------|
113
+ | procedure_code | SV1/SV2 segment, element 2 | item.productOrService with pr system | ✓ Aligned |
114
+ | ndc | LIN segment after service line | item.productOrService with ndc system or extension | ✓ Aligned but different locations |
115
+ | quantity | SV1/SV2 element 4 | item.quantity.value | ✓ Direct mapping |
116
+ | quantity_unit | SV1/SV2 element 5 | item.quantity.unit | ✓ Direct mapping |
117
+ | service_date | DTP segment with qualifier 472 | item.servicedPeriod or eob.billablePeriod | ✓ Aligned |
118
+ | place_of_service | SV1 element 6 | item.locationCodeableConcept with place_of_service system | ✓ Aligned |
119
+ | modifiers | SV1/SV2 segment, additional qualifiers | item.modifier with pr system | ✓ Aligned |
120
+
121
+ ### Diagnosis Information
122
+ | Field | 837 Source | FHIR BCDA Source | Alignment Analysis |
123
+ |-------|------------|-------------------|-------------------|
124
+ | linked_diagnosis_codes | SV1/SV2 diagnosis pointers + HI segment codes | item.diagnosisSequence + diagnosis lookup | ✓ Aligned but different structure |
125
+ | claim_diagnosis_codes | HI segment codes | diagnosis array with icd10cm/icd10 systems | ✓ Aligned |
126
+
127
+ ### Additional Fields
128
+ | Field | 837 Source | FHIR BCDA Source | Alignment Analysis |
129
+ |-------|------------|-------------------|-------------------|
130
+ | allowed_amount | Not available in 837 | item.adjudication with 'eligible' category | ⚠️ Only in FHIR |
131
+
132
+ ### Key Differences and Notes
133
+
134
+ 1. **Structural Differences**:
135
+ - 837 uses a segment-based approach with positional elements
136
+ - FHIR uses a nested object structure with explicit systems and codes
137
+
138
+ 2. **Code Systems**:
139
+ - FHIR explicitly defines systems for each code (via SYSTEMS constant)
140
+ - 837 uses implicit coding based on segment position and qualifiers
141
+
142
+ 3. **Data Validation**:
143
+ - FHIR implementation uses Pydantic models for validation
144
+ - 837 implements manual validation and parsing
145
+
146
+ 4. **Diagnosis Handling**:
147
+ - 837: Direct parsing from HI segment with position-based lookup
148
+ - FHIR: Uses sequence numbers and separate diagnosis array
149
+
150
+ 5. **Provider Information**:
151
+ - 837: Direct from NM1 segments with role qualifiers
152
+ - FHIR: Through careTeam structure with role coding
153
+
154
+ ### TODO: Enhancement Suggestions
155
+
156
+ 1. Consider adding validation for code systems in 837 parser to match FHIR's explicitness
157
+ 2. Standardize date handling between both implementations
158
+ 3. Add support for allowed_amount in 837 if available in different segments
159
+ 4. Consider adding more robust error handling in both implementations
160
+
161
+ ## Contributing
162
+ Join us at [mimilabs](https://mimilabs.ai/signup). Reference data available in MIMILabs data lakehouse.
163
+
164
+ ## License
165
+ Apache License 2.0
@@ -0,0 +1 @@
1
+ # Empty file to make the package importable
@@ -0,0 +1,2 @@
1
+ # Empty file to make the package importable
2
+