hccinfhir 0.0.1__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.
@@ -0,0 +1,164 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
110
+ .pdm.toml
111
+ .pdm-python
112
+ .pdm-build/
113
+
114
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115
+ __pypackages__/
116
+
117
+ # Celery stuff
118
+ celerybeat-schedule
119
+ celerybeat.pid
120
+
121
+ # SageMath parsed files
122
+ *.sage.py
123
+
124
+ # Environments
125
+ .env
126
+ .venv
127
+ env/
128
+ venv/
129
+ ENV/
130
+ env.bak/
131
+ venv.bak/
132
+
133
+ # Spyder project settings
134
+ .spyderproject
135
+ .spyproject
136
+
137
+ # Rope project settings
138
+ .ropeproject
139
+
140
+ # mkdocs documentation
141
+ /site
142
+
143
+ # mypy
144
+ .mypy_cache/
145
+ .dmypy.json
146
+ dmypy.json
147
+
148
+ # Pyre type checker
149
+ .pyre/
150
+
151
+ # pytype static type analyzer
152
+ .pytype/
153
+
154
+ # Cython debug symbols
155
+ cython_debug/
156
+
157
+ # PyCharm
158
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
161
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
+ #.idea/
163
+
164
+ .DS_Store
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,89 @@
1
+ Metadata-Version: 2.3
2
+ Name: hccinfhir
3
+ Version: 0.0.1
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
+ HCC (Hierarchical Condition Category) Algorithm Implementation for FHIR Resources
17
+
18
+ ## Overview
19
+ `hccinfhir` implements the CMS-HCC Risk Adjustment model using FHIR (Fast Healthcare Interoperability Resources) data. It processes Blue Button 2.0 API (BCDA) data to calculate Hierarchical Condition Category (HCC) Risk Adjustment Factors (RAF).
20
+
21
+ ## Why FHIR-Based HCC Processing?
22
+ Risk Adjustment calculations traditionally rely on processed claims data, leading to information loss and reconciliation challenges. `hccinfhir` processes FHIR resources directly because:
23
+ - FHIR represents the source of truth with complete clinical and administrative data
24
+ - Risk Adjustment requires multiple data elements beyond diagnosis codes
25
+ - Direct processing eliminates data transformation errors and simplifies reconciliation
26
+
27
+ ## Data Flexibility
28
+ While built for native FHIR processing, `hccinfhir` works with any data source that can be transformed into the MDE format:
29
+
30
+ ```python
31
+ mde = [{
32
+ "procedure_code": "99214",
33
+ "diagnosis_codes": ["E11.9", "I10"],
34
+ "claim_type": "71",
35
+ "provider_specialty": "01",
36
+ "service_date": "2024-01-15"
37
+ }, ...]
38
+ ```
39
+
40
+ ## Components
41
+
42
+ ### 1. Extractor Module
43
+ Processes FHIR ExplanationOfBenefit resources to extract Minimum Data Elements (MDE):
44
+ ```python
45
+ from hccinfhir.extractor import extract_mde, extract_mde_list
46
+
47
+ mde = extract_mde(eob_data) # Process single EOB
48
+
49
+ mde_list = extract_mde_list([eob1, eob2]) # Process multiple EOBs
50
+ ```
51
+
52
+ ### 2. Logic Module (In Development)
53
+ Implements core HCC calculation logic:
54
+ - Maps diagnosis codes to HCC categories
55
+ - Applies hierarchical rules and interactions
56
+ - Calculates final RAF scores
57
+ - Integrates with standard CMS data files
58
+
59
+ ### 3. Filter Module (In Development)
60
+ Implements claim filtering rules:
61
+ - Inpatient/outpatient criteria
62
+ - Professional service requirements
63
+ - Provider validation
64
+ - Date range filtering
65
+
66
+ ## Installation
67
+ ```bash
68
+ pip install hccinfhir
69
+ ```
70
+
71
+ ## Usage
72
+ ```python
73
+ from hccinfhir import HCCInFHIR
74
+
75
+ hcc_processor = HCCInFHIR()
76
+ mde_list = hcc_processor.extract_mde_list(eob_list)
77
+ filtered_mde = hcc_processor.apply_filters(mde_list) # future
78
+ raf_details = hcc_processor.calculate_raf(filtered_mde, demographic_data) # future
79
+ ```
80
+
81
+ ## Dependencies
82
+ - Pydantic >= 2.10.3
83
+ - Standard Python libraries
84
+
85
+ ## Contributing
86
+ Join us at [mimilabs](https://mimilabs.ai/signup). Reference data available in MIMILabs data lakehouse.
87
+
88
+ ## License
89
+ Apache License 2.0
@@ -0,0 +1,75 @@
1
+ # `hccinfhir` (HCC in FHIR)
2
+ HCC (Hierarchical Condition Category) Algorithm Implementation for FHIR Resources
3
+
4
+ ## Overview
5
+ `hccinfhir` implements the CMS-HCC Risk Adjustment model using FHIR (Fast Healthcare Interoperability Resources) data. It processes Blue Button 2.0 API (BCDA) data to calculate Hierarchical Condition Category (HCC) Risk Adjustment Factors (RAF).
6
+
7
+ ## Why FHIR-Based HCC Processing?
8
+ Risk Adjustment calculations traditionally rely on processed claims data, leading to information loss and reconciliation challenges. `hccinfhir` processes FHIR resources directly because:
9
+ - FHIR represents the source of truth with complete clinical and administrative data
10
+ - Risk Adjustment requires multiple data elements beyond diagnosis codes
11
+ - Direct processing eliminates data transformation errors and simplifies reconciliation
12
+
13
+ ## Data Flexibility
14
+ While built for native FHIR processing, `hccinfhir` works with any data source that can be transformed into the MDE format:
15
+
16
+ ```python
17
+ mde = [{
18
+ "procedure_code": "99214",
19
+ "diagnosis_codes": ["E11.9", "I10"],
20
+ "claim_type": "71",
21
+ "provider_specialty": "01",
22
+ "service_date": "2024-01-15"
23
+ }, ...]
24
+ ```
25
+
26
+ ## Components
27
+
28
+ ### 1. Extractor Module
29
+ Processes FHIR ExplanationOfBenefit resources to extract Minimum Data Elements (MDE):
30
+ ```python
31
+ from hccinfhir.extractor import extract_mde, extract_mde_list
32
+
33
+ mde = extract_mde(eob_data) # Process single EOB
34
+
35
+ mde_list = extract_mde_list([eob1, eob2]) # Process multiple EOBs
36
+ ```
37
+
38
+ ### 2. Logic Module (In Development)
39
+ Implements core HCC calculation logic:
40
+ - Maps diagnosis codes to HCC categories
41
+ - Applies hierarchical rules and interactions
42
+ - Calculates final RAF scores
43
+ - Integrates with standard CMS data files
44
+
45
+ ### 3. Filter Module (In Development)
46
+ Implements claim filtering rules:
47
+ - Inpatient/outpatient criteria
48
+ - Professional service requirements
49
+ - Provider validation
50
+ - Date range filtering
51
+
52
+ ## Installation
53
+ ```bash
54
+ pip install hccinfhir
55
+ ```
56
+
57
+ ## Usage
58
+ ```python
59
+ from hccinfhir import HCCInFHIR
60
+
61
+ hcc_processor = HCCInFHIR()
62
+ mde_list = hcc_processor.extract_mde_list(eob_list)
63
+ filtered_mde = hcc_processor.apply_filters(mde_list) # future
64
+ raf_details = hcc_processor.calculate_raf(filtered_mde, demographic_data) # future
65
+ ```
66
+
67
+ ## Dependencies
68
+ - Pydantic >= 2.10.3
69
+ - Standard Python libraries
70
+
71
+ ## Contributing
72
+ Join us at [mimilabs](https://mimilabs.ai/signup). Reference data available in MIMILabs data lakehouse.
73
+
74
+ ## License
75
+ Apache License 2.0
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,2 @@
1
+
2
+
@@ -0,0 +1,136 @@
1
+ {
2
+ "billablePeriod": {
3
+ "end": "2021-01-01",
4
+ "start": "2021-01-01"
5
+ },
6
+ "careTeam": [
7
+ {
8
+ "provider": {
9
+ "identifier": {
10
+ "type": {
11
+ "coding": [
12
+ {
13
+ "code": "npi",
14
+ "display": "National Provider Identifier",
15
+ "system": "http://hl7.org/fhir/us/carin-bb/CodeSystem/C4BBIdentifierType"
16
+ }
17
+ ]
18
+ },
19
+ "value": "1234567890"
20
+ }
21
+ },
22
+ "qualification": {
23
+ "coding": [
24
+ {
25
+ "code": "50",
26
+ "display": "Nurse practitioner",
27
+ "system": "https://bluebutton.cms.gov/resources/variables/prvdr_spclty"
28
+ }
29
+ ]
30
+ },
31
+ "responsible": true,
32
+ "role": {
33
+ "coding": [
34
+ {
35
+ "code": "performing",
36
+ "display": "Performing provider",
37
+ "system": "http://hl7.org/fhir/us/carin-bb/CodeSystem/C4BBClaimCareTeamRole"
38
+ }
39
+ ]
40
+ },
41
+ "sequence": 1
42
+ }
43
+ ],
44
+ "diagnosis": [
45
+ {
46
+ "diagnosisCodeableConcept": {
47
+ "coding": [
48
+ {
49
+ "code": "F411",
50
+ "display": "GENERALIZED ANXIETY DISORDER",
51
+ "system": "http://hl7.org/fhir/sid/icd-10-cm"
52
+ }
53
+ ]
54
+ },
55
+ "sequence": 1,
56
+ "type": [
57
+ {
58
+ "coding": [
59
+ {
60
+ "code": "principal",
61
+ "display": "principal",
62
+ "system": "http://terminology.hl7.org/CodeSystem/ex-diagnosistype"
63
+ }
64
+ ]
65
+ }
66
+ ]
67
+ }
68
+ ],
69
+ "id": "carrier-28493431905",
70
+ "item": [
71
+ {
72
+ "diagnosisSequence": [
73
+ 1
74
+ ],
75
+ "productOrService": {
76
+ "coding": [
77
+ {
78
+ "code": "90792",
79
+ "system": "https://bluebutton.cms.gov/resources/codesystem/hcpcs"
80
+ }
81
+ ]
82
+ },
83
+ "quantity": {
84
+ "value": 1
85
+ },
86
+ "sequence": 1,
87
+ "servicedPeriod": {
88
+ "end": "2021-01-01",
89
+ "start": "2021-01-01"
90
+ }
91
+ },
92
+ {
93
+ "diagnosisSequence": [
94
+ 1
95
+ ],
96
+ "productOrService": {
97
+ "coding": [
98
+ {
99
+ "code": "99213",
100
+ "system": "https://bluebutton.cms.gov/resources/codesystem/hcpcs"
101
+ }
102
+ ]
103
+ },
104
+ "quantity": {
105
+ "value": 1
106
+ },
107
+ "sequence": 1,
108
+ "servicedPeriod": {
109
+ "end": "2021-01-01",
110
+ "start": "2021-01-01"
111
+ }
112
+ }
113
+ ],
114
+ "patient": {
115
+ "reference": "Patient/12345678"
116
+ },
117
+ "type": {
118
+ "coding": [
119
+ {
120
+ "code": "71",
121
+ "display": "Local carrier non-durable medical equipment, prosthetics, orthotics, and supplies (DMEPOS) claim",
122
+ "system": "https://bluebutton.cms.gov/resources/variables/nch_clm_type_cd"
123
+ },
124
+ {
125
+ "code": "CARRIER",
126
+ "system": "https://bluebutton.cms.gov/resources/codesystem/eob-type"
127
+ },
128
+ {
129
+ "code": "professional",
130
+ "display": "Professional",
131
+ "system": "http://terminology.hl7.org/CodeSystem/claim-type"
132
+ }
133
+ ]
134
+ },
135
+ "resourceType": "ExplanationOfBenefit"
136
+ }
@@ -0,0 +1,84 @@
1
+ {
2
+ "resourceType": "ExplanationOfBenefit",
3
+ "type": {
4
+ "coding": [
5
+ {
6
+ "system": "https://bluebutton.cms.gov/resources/variables/nch_clm_type_cd",
7
+ "code": "40"
8
+ }
9
+ ]
10
+ },
11
+ "diagnosis": [
12
+ {
13
+ "sequence": 1,
14
+ "diagnosisCodeableConcept": {
15
+ "coding": [
16
+ {
17
+ "system": "http://hl7.org/fhir/sid/icd-10-cm",
18
+ "code": "E11.9"
19
+ }
20
+ ]
21
+ }
22
+ }
23
+ ],
24
+ "careTeam": [
25
+ {
26
+ "sequence": 1,
27
+ "provider": {
28
+ "identifier": {
29
+ "type": {
30
+ "coding": [
31
+ {
32
+ "code": "npi",
33
+ "display": "National Provider Identifier",
34
+ "system": "http://hl7.org/fhir/us/carin-bb/CodeSystem/C4BBIdentifierType"
35
+ }
36
+ ]
37
+ },
38
+ "value": "1234567890"
39
+ }
40
+ },
41
+ "qualification": {
42
+ "coding": [
43
+ {
44
+ "system": "https://bluebutton.cms.gov/resources/variables/prvdr_spclty",
45
+ "code": "01"
46
+ }
47
+ ]
48
+ },
49
+ "role": {
50
+ "coding": [
51
+ {
52
+ "system": "http://hl7.org/fhir/us/carin-bb/CodeSystem/C4BBClaimCareTeamRole",
53
+ "code": "performing"
54
+ }
55
+ ]
56
+ },
57
+ "responsible": true
58
+ }
59
+ ],
60
+ "billablePeriod": {
61
+ "start": "2023-01-01",
62
+ "end": "2023-01-01"
63
+ },
64
+ "item": [
65
+ {
66
+ "sequence": 1,
67
+ "productOrService": {
68
+ "coding": [
69
+ {
70
+ "system": "https://bluebutton.cms.gov/resources/codesystem/hcpcs",
71
+ "code": "99213"
72
+ }
73
+ ]
74
+ },
75
+ "diagnosisSequence": [
76
+ 1
77
+ ],
78
+ "servicedPeriod": {
79
+ "start": "2023-01-01",
80
+ "end": "2023-01-01"
81
+ }
82
+ }
83
+ ]
84
+ }
@@ -0,0 +1,102 @@
1
+ {
2
+ "resourceType": "ExplanationOfBenefit",
3
+ "id": "carrier-28527",
4
+ "type": {
5
+ "coding": [
6
+ {
7
+ "system": "https://bluebutton.cms.gov/resources/variables/nch_clm_type_cd",
8
+ "code": "71",
9
+ "display": "Carrier claim"
10
+ }
11
+ ]
12
+ },
13
+ "billablePeriod": {
14
+ "start": "2023-03-15",
15
+ "end": "2023-03-15"
16
+ },
17
+ "careTeam": [
18
+ {
19
+ "sequence": 1,
20
+ "provider": {
21
+ "identifier": {
22
+ "type": {
23
+ "coding": [
24
+ {
25
+ "code": "npi",
26
+ "display": "National Provider Identifier",
27
+ "system": "http://hl7.org/fhir/us/carin-bb/CodeSystem/C4BBIdentifierType"
28
+ }
29
+ ]
30
+ },
31
+ "value": "1234567890"
32
+ }
33
+ },
34
+ "role": {
35
+ "coding": [
36
+ {
37
+ "system": "http://hl7.org/fhir/us/carin-bb/CodeSystem/C4BBClaimCareTeamRole",
38
+ "code": "performing",
39
+ "display": "Performing"
40
+ }
41
+ ]
42
+ },
43
+ "qualification": {
44
+ "coding": [
45
+ {
46
+ "system": "https://bluebutton.cms.gov/resources/variables/prvdr_spclty",
47
+ "code": "11",
48
+ "display": "Internal Medicine"
49
+ }
50
+ ]
51
+ }
52
+ }
53
+ ],
54
+ "diagnosis": [
55
+ {
56
+ "sequence": 1,
57
+ "diagnosisCodeableConcept": {
58
+ "coding": [
59
+ {
60
+ "system": "http://hl7.org/fhir/sid/icd-10-cm",
61
+ "code": "E11.9",
62
+ "display": "Type 2 diabetes mellitus without complications"
63
+ }
64
+ ]
65
+ }
66
+ },
67
+ {
68
+ "sequence": 2,
69
+ "diagnosisCodeableConcept": {
70
+ "coding": [
71
+ {
72
+ "system": "http://hl7.org/fhir/sid/icd-10-cm",
73
+ "code": "I10",
74
+ "display": "Essential (primary) hypertension"
75
+ }
76
+ ]
77
+ }
78
+ }
79
+ ],
80
+ "item": [
81
+ {
82
+ "sequence": 1,
83
+ "servicedPeriod": {
84
+ "start": "2023-03-15",
85
+ "end": "2023-03-15"
86
+ },
87
+ "productOrService": {
88
+ "coding": [
89
+ {
90
+ "system": "https://bluebutton.cms.gov/resources/codesystem/hcpcs",
91
+ "code": "99214",
92
+ "display": "Office/outpatient visit established"
93
+ }
94
+ ]
95
+ },
96
+ "diagnosisSequence": [
97
+ 1,
98
+ 2
99
+ ]
100
+ }
101
+ ]
102
+ }
@@ -0,0 +1,122 @@
1
+ from pydantic import BaseModel, ConfigDict
2
+ from typing import List, Optional, Literal
3
+ from datetime import date
4
+
5
+ SYSTEMS = {
6
+ 'dx': 'http://hl7.org/fhir/sid/icd-10-cm',
7
+ 'pr': 'https://bluebutton.cms.gov/resources/codesystem/hcpcs',
8
+ 'specialty': 'https://bluebutton.cms.gov/resources/variables/prvdr_spclty',
9
+ 'role': 'http://hl7.org/fhir/us/carin-bb/CodeSystem/C4BBClaimCareTeamRole',
10
+ 'claim_type': 'https://bluebutton.cms.gov/resources/variables/nch_clm_type_cd'
11
+ }
12
+
13
+ # Models
14
+ class Coding(BaseModel):
15
+ system: Optional[str] = None
16
+ code: Optional[str] = None
17
+ display: Optional[str] = None
18
+
19
+ class CodeableConcept(BaseModel):
20
+ coding: Optional[List[Coding]] = []
21
+
22
+ class Period(BaseModel):
23
+ start: Optional[date] = None
24
+ end: Optional[date] = None
25
+
26
+ class Diagnosis(BaseModel):
27
+ sequence: Optional[int] = None
28
+ diagnosisCodeableConcept: Optional[CodeableConcept] = None
29
+
30
+ class CareTeamMember(BaseModel):
31
+ role: Optional[CodeableConcept] = None
32
+ qualification: Optional[CodeableConcept] = None
33
+
34
+ class EoBItem(BaseModel):
35
+ productOrService: Optional[CodeableConcept] = None
36
+ diagnosisSequence: Optional[List[int]] = None
37
+ servicedPeriod: Optional[Period] = None
38
+
39
+ class ExplanationOfBenefit(BaseModel):
40
+ model_config = ConfigDict(frozen=True)
41
+ resourceType: Literal["ExplanationOfBenefit"] = "ExplanationOfBenefit"
42
+ type: Optional[CodeableConcept] = None
43
+ diagnosis: Optional[List[Diagnosis]] = []
44
+ item: Optional[List[EoBItem]] = []
45
+ careTeam: Optional[List[CareTeamMember]] = []
46
+ billablePeriod: Optional[Period] = None
47
+
48
+ def extract_mde(eob_data: dict) -> List[dict]:
49
+ """Extract medical data elements from FHIR ExplanationOfBenefit data."""
50
+ try:
51
+ eob = ExplanationOfBenefit.model_validate(eob_data)
52
+
53
+ # Get codes from CodeableConcept
54
+ get_code = lambda concept, system: next((
55
+ c.code for c in (concept.coding or [])
56
+ if c and c.system == system and c.code
57
+ ), None)
58
+
59
+ # Get date from Period
60
+ get_date = lambda period: (
61
+ period.end.isoformat() if period and period.end
62
+ else period.start.isoformat() if period and period.start
63
+ else None
64
+ )
65
+
66
+ # Create diagnosis lookup
67
+ dx_lookup = {
68
+ d.sequence: get_code(d.diagnosisCodeableConcept, SYSTEMS['dx'])
69
+ for d in (eob.diagnosis or [])
70
+ if d.sequence is not None and d.diagnosisCodeableConcept
71
+ }
72
+
73
+ # Get claim-level data
74
+ claim_type = get_code(eob.type, SYSTEMS['claim_type'])
75
+
76
+ # Get provider specialty
77
+ specialty = next((
78
+ get_code(m.qualification, SYSTEMS['specialty'])
79
+ for m in (eob.careTeam or [])
80
+ if m.role and m.qualification
81
+ and get_code(m.role, SYSTEMS['role']) in {'performing', 'rendering'}
82
+ ), None)
83
+
84
+ results = []
85
+ for item in (eob.item or []):
86
+ if not item.productOrService:
87
+ continue
88
+
89
+ pr_code = get_code(item.productOrService, SYSTEMS['pr'])
90
+ if not pr_code:
91
+ continue
92
+
93
+ # Get associated data
94
+ dos = get_date(item.servicedPeriod) or get_date(eob.billablePeriod)
95
+ dx_codes = [dx_lookup[seq] for seq in (item.diagnosisSequence or [])
96
+ if seq in dx_lookup]
97
+
98
+ # Build result
99
+ result = {k: v for k, v in {
100
+ 'procedure_code': pr_code,
101
+ 'diagnosis_codes': dx_codes,
102
+ 'claim_type': claim_type,
103
+ 'provider_specialty': specialty,
104
+ 'service_date': dos
105
+ }.items()}
106
+
107
+ results.append(result)
108
+
109
+ return results
110
+
111
+ except Exception as e:
112
+ raise ValueError(f"Error processing EOB: {str(e)}")
113
+
114
+ def extract_mde_list(eob_data_list: List[dict]) -> List[dict]:
115
+ """Process a list of EOB data dictionaries."""
116
+ results = []
117
+ for eob_data in eob_data_list:
118
+ try:
119
+ results.extend(extract_mde(eob_data))
120
+ except ValueError as e:
121
+ print(f"Warning: Skipping invalid EOB: {str(e)}")
122
+ return results
@@ -0,0 +1,53 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "hccinfhir"
7
+ version = "0.0.1"
8
+ authors = [
9
+ { name="Yubin Park", email="yubin.park@mimilabs.ai" },
10
+ ]
11
+ description = "HCC Algorithm for FHIR Resources"
12
+ readme = "README.md"
13
+ requires-python = ">=3.8"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: Apache Software License",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+ dependencies = ["pydantic>=2.10.3"]
20
+
21
+ [project.urls]
22
+ Homepage = "https://github.com/mimilabs/hccinfhir"
23
+ Issues = "https://github.com/mimilabs/hccinfhir/issues"
24
+
25
+ [tool.hatch.build]
26
+ packages = ["src/hccinfhir"]
27
+ include = [
28
+ "*.py",
29
+ "*.json",
30
+ "*.csv"
31
+ ]
32
+
33
+ [tool.hatch.build.targets.wheel]
34
+ packages = ["src/hccinfhir"]
35
+
36
+ [tool.coverage.run]
37
+ source_pkgs = ["hccinfhir"]
38
+ branch = true
39
+ parallel = true
40
+ omit = [
41
+ "src/hccinfhir/__about__.py",
42
+ ]
43
+
44
+ [tool.coverage.paths]
45
+ hccinfhir = ["src/hccinfhir", "*/hccinfhir/src/hccinfhir"]
46
+ tests = ["tests", "*/hccinfhir/tests"]
47
+
48
+ [tool.coverage.report]
49
+ exclude_lines = [
50
+ "no cov",
51
+ "if __name__ == .__main__.:",
52
+ "if TYPE_CHECKING:",
53
+ ]