fhiratwill 0.1.0__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.
- fhiratwill-0.1.0/.gitignore +14 -0
- fhiratwill-0.1.0/CHANGELOG.md +18 -0
- fhiratwill-0.1.0/CONTRIBUTING.md +45 -0
- fhiratwill-0.1.0/LICENSE +190 -0
- fhiratwill-0.1.0/PKG-INFO +151 -0
- fhiratwill-0.1.0/README.md +114 -0
- fhiratwill-0.1.0/SECURITY.md +20 -0
- fhiratwill-0.1.0/pyproject.toml +94 -0
- fhiratwill-0.1.0/src/fhiratwill/__init__.py +105 -0
- fhiratwill-0.1.0/src/fhiratwill/assembly.py +303 -0
- fhiratwill-0.1.0/src/fhiratwill/binding.py +294 -0
- fhiratwill-0.1.0/src/fhiratwill/context.py +277 -0
- fhiratwill-0.1.0/src/fhiratwill/data/concepts.yaml +71 -0
- fhiratwill-0.1.0/src/fhiratwill/errors.py +32 -0
- fhiratwill-0.1.0/src/fhiratwill/planning.py +210 -0
- fhiratwill-0.1.0/src/fhiratwill/py.typed +1 -0
- fhiratwill-0.1.0/src/fhiratwill/tags.py +24 -0
- fhiratwill-0.1.0/src/fhiratwill/targets.py +62 -0
- fhiratwill-0.1.0/src/fhiratwill/terminology.py +163 -0
- fhiratwill-0.1.0/tests/__init__.py +1 -0
- fhiratwill-0.1.0/tests/fakes.py +89 -0
- fhiratwill-0.1.0/tests/test_assembly.py +33 -0
- fhiratwill-0.1.0/tests/test_binding.py +57 -0
- fhiratwill-0.1.0/tests/test_context.py +71 -0
- fhiratwill-0.1.0/tests/test_planning.py +84 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes follow [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
4
|
+
This project uses [Semantic Versioning](https://semver.org/).
|
|
5
|
+
|
|
6
|
+
## [Unreleased]
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-09-06
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Deterministic FHIR assembly and PHI-free evidence.
|
|
13
|
+
- Exact-match terminology binding through an async adapter protocol.
|
|
14
|
+
- Subject-context preflight and reference rebinding.
|
|
15
|
+
- Generic target descriptors and idempotent write-plan compilation.
|
|
16
|
+
|
|
17
|
+
[Unreleased]: https://github.com/Safwanmahmoud/fhirbridge/compare/v0.1.0...HEAD
|
|
18
|
+
[0.1.0]: https://github.com/Safwanmahmoud/fhirbridge/releases/tag/v0.1.0
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Use Python 3.11 or newer and synthetic test data only.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
python -m pip install -e ".[dev]"
|
|
7
|
+
ruff check .
|
|
8
|
+
mypy
|
|
9
|
+
pytest
|
|
10
|
+
python -m build
|
|
11
|
+
twine check dist/*
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Preserve these invariants:
|
|
15
|
+
|
|
16
|
+
- never add a clinical code without deterministic terminology verification;
|
|
17
|
+
- retain source text when adding coding;
|
|
18
|
+
- propagate terminology outages rather than treating them as invalid codes;
|
|
19
|
+
- never infer or search for destination identity;
|
|
20
|
+
- keep notes and exceptions free of PHI; and
|
|
21
|
+
- keep transport, credentials, databases, and framework integrations outside core.
|
|
22
|
+
|
|
23
|
+
Open a focused issue or pull request and update tests and public documentation with behavior.
|
|
24
|
+
|
|
25
|
+
## Releasing to PyPI
|
|
26
|
+
|
|
27
|
+
The release workflow uses PyPI Trusted Publishing and does not accept an API token.
|
|
28
|
+
Before the first release, create a pending publisher on PyPI with:
|
|
29
|
+
|
|
30
|
+
- project name: `fhiratwill`
|
|
31
|
+
- owner: `Safwanmahmoud`
|
|
32
|
+
- repository: `fhirbridge`
|
|
33
|
+
- workflow: `release.yml`
|
|
34
|
+
- environment: `pypi`
|
|
35
|
+
|
|
36
|
+
Also create a protected GitHub environment named `pypi`. Then:
|
|
37
|
+
|
|
38
|
+
1. update `__version__` in `src/fhiratwill/__init__.py`;
|
|
39
|
+
2. move the release notes in `CHANGELOG.md` under that version;
|
|
40
|
+
3. run every command above from a clean checkout;
|
|
41
|
+
4. commit and tag the exact version as `v<version>`; and
|
|
42
|
+
5. publish the corresponding GitHub Release.
|
|
43
|
+
|
|
44
|
+
Publishing the GitHub Release triggers one build job and one trusted-publishing job.
|
|
45
|
+
Do not upload a locally built artifact or configure a long-lived PyPI credential.
|
fhiratwill-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
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
|
+
Copyright 2026 fhiratwill contributors
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fhiratwill
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Deterministic, safety-focused FHIR assembly, terminology binding, and write planning.
|
|
5
|
+
Project-URL: Homepage, https://github.com/Safwanmahmoud/fhirbridge
|
|
6
|
+
Project-URL: Documentation, https://github.com/Safwanmahmoud/fhirbridge#readme
|
|
7
|
+
Project-URL: Source, https://github.com/Safwanmahmoud/fhirbridge
|
|
8
|
+
Project-URL: Issues, https://github.com/Safwanmahmoud/fhirbridge/issues
|
|
9
|
+
Author: fhiratwill contributors
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: fhir,healthcare,hl7,interoperability,terminology
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Healthcare Industry
|
|
16
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: Programming Language :: Python
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.11
|
|
25
|
+
Requires-Dist: fhir-resources<9,>=8.0
|
|
26
|
+
Requires-Dist: pydantic<3,>=2.8
|
|
27
|
+
Requires-Dist: pyyaml<7,>=6.0
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: build<2,>=1.2; extra == 'dev'
|
|
30
|
+
Requires-Dist: mypy<2,>=1.11; extra == 'dev'
|
|
31
|
+
Requires-Dist: pytest-asyncio<2,>=0.24; extra == 'dev'
|
|
32
|
+
Requires-Dist: pytest<9,>=8.3; extra == 'dev'
|
|
33
|
+
Requires-Dist: ruff<1,>=0.8; extra == 'dev'
|
|
34
|
+
Requires-Dist: twine<7,>=5.1; extra == 'dev'
|
|
35
|
+
Requires-Dist: types-pyyaml<7,>=6.0; extra == 'dev'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# fhiratwill
|
|
39
|
+
|
|
40
|
+
Deterministic, transport-neutral building blocks for assembling, terminology-binding,
|
|
41
|
+
context-rebinding, and planning writes of FHIR R4 resources.
|
|
42
|
+
|
|
43
|
+
> Alpha software. Generated resources remain untrusted until independently validated and
|
|
44
|
+
> reviewed for the intended clinical workflow.
|
|
45
|
+
|
|
46
|
+
## Install
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install fhiratwill
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Python 3.11 or newer is required.
|
|
53
|
+
|
|
54
|
+
## Assemble deterministically
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from fhiratwill import assemble_bundle
|
|
58
|
+
|
|
59
|
+
entities = [
|
|
60
|
+
{"resourceType": "Patient", "instance": "subject", "keyword": "gender", "value": "female"},
|
|
61
|
+
{"resourceType": "Observation", "instance": "pulse", "keyword": "code", "value": "heart rate"},
|
|
62
|
+
{
|
|
63
|
+
"resourceType": "Observation",
|
|
64
|
+
"instance": "pulse",
|
|
65
|
+
"keyword": "valueQuantity",
|
|
66
|
+
"value": "72/min",
|
|
67
|
+
},
|
|
68
|
+
]
|
|
69
|
+
result = assemble_bundle(entities, seed="conversion-123")
|
|
70
|
+
bundle = result.bundle
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Assembly keeps coded concepts as text, refuses unsafe coercions, records PHI-free notes,
|
|
74
|
+
and produces stable UUIDs for a stable seed. It does not validate clinical truth.
|
|
75
|
+
|
|
76
|
+
## Bind using your terminology adapter
|
|
77
|
+
|
|
78
|
+
Implement the async `TerminologyClient` protocol for your terminology service. The library
|
|
79
|
+
contains no HTTP client, URL, authentication, or credentials.
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from fhiratwill import TerminologyClient, bind_bundle
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
async def bind(bundle: dict, terminology: TerminologyClient) -> dict:
|
|
86
|
+
result = await bind_bundle(bundle, client=terminology)
|
|
87
|
+
return result.bundle
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Binding uses exact aliases from the packaged, reviewed `concepts.yaml`; it performs no
|
|
91
|
+
fuzzy or model-based coding. A candidate is added only after the adapter verifies it.
|
|
92
|
+
Original `CodeableConcept.text` is retained. Adapters must raise
|
|
93
|
+
`TerminologyUnavailableError` when no authoritative answer is available; outages
|
|
94
|
+
propagate and fail closed.
|
|
95
|
+
|
|
96
|
+
## Rebind and compile a write plan
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from fhiratwill import (
|
|
100
|
+
GENERIC_FHIR_TARGET,
|
|
101
|
+
SubjectContext,
|
|
102
|
+
compile_write_plan,
|
|
103
|
+
rebind_bundle,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
context = SubjectContext(patient_ref="Patient/123", encounter_ref="Encounter/456")
|
|
107
|
+
rebound, notes = rebind_bundle(bundle, context)
|
|
108
|
+
plan = compile_write_plan(
|
|
109
|
+
bundle=bundle,
|
|
110
|
+
context=context,
|
|
111
|
+
conversion_id="conversion-123",
|
|
112
|
+
tenant_id="tenant-7",
|
|
113
|
+
descriptor=GENERIC_FHIR_TARGET,
|
|
114
|
+
)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Generated Patient and Encounter resources are always excluded. References are rebound only
|
|
118
|
+
to caller-supplied context. The optional preflight adapter supports direct reads only—never
|
|
119
|
+
identity search. Write plans contain deterministic idempotency keys and, when supported by
|
|
120
|
+
the descriptor, a FHIR transaction Bundle.
|
|
121
|
+
|
|
122
|
+
## Scope
|
|
123
|
+
|
|
124
|
+
This library:
|
|
125
|
+
|
|
126
|
+
- assembles grounded entity mappings into deterministic FHIR resources;
|
|
127
|
+
- verifies exact terminology candidates through a caller-provided adapter;
|
|
128
|
+
- checks and rebinds caller-supplied subject context; and
|
|
129
|
+
- compiles destination-neutral write plans.
|
|
130
|
+
|
|
131
|
+
This library does **not** submit data, authenticate to an EHR, host a terminology service,
|
|
132
|
+
perform target HTTP calls, validate full FHIR conformance, provide clinical decision
|
|
133
|
+
support, or establish HIPAA, GDPR, medical-device, or other regulatory compliance.
|
|
134
|
+
|
|
135
|
+
## Development
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
python -m pip install -e ".[dev]"
|
|
139
|
+
ruff check .
|
|
140
|
+
mypy
|
|
141
|
+
pytest
|
|
142
|
+
python -m build
|
|
143
|
+
twine check dist/*
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
No publishing command is part of the development workflow. See `CONTRIBUTING.md` and
|
|
147
|
+
`SECURITY.md` before contributing.
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
Apache License 2.0.
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# fhiratwill
|
|
2
|
+
|
|
3
|
+
Deterministic, transport-neutral building blocks for assembling, terminology-binding,
|
|
4
|
+
context-rebinding, and planning writes of FHIR R4 resources.
|
|
5
|
+
|
|
6
|
+
> Alpha software. Generated resources remain untrusted until independently validated and
|
|
7
|
+
> reviewed for the intended clinical workflow.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install fhiratwill
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Python 3.11 or newer is required.
|
|
16
|
+
|
|
17
|
+
## Assemble deterministically
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from fhiratwill import assemble_bundle
|
|
21
|
+
|
|
22
|
+
entities = [
|
|
23
|
+
{"resourceType": "Patient", "instance": "subject", "keyword": "gender", "value": "female"},
|
|
24
|
+
{"resourceType": "Observation", "instance": "pulse", "keyword": "code", "value": "heart rate"},
|
|
25
|
+
{
|
|
26
|
+
"resourceType": "Observation",
|
|
27
|
+
"instance": "pulse",
|
|
28
|
+
"keyword": "valueQuantity",
|
|
29
|
+
"value": "72/min",
|
|
30
|
+
},
|
|
31
|
+
]
|
|
32
|
+
result = assemble_bundle(entities, seed="conversion-123")
|
|
33
|
+
bundle = result.bundle
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Assembly keeps coded concepts as text, refuses unsafe coercions, records PHI-free notes,
|
|
37
|
+
and produces stable UUIDs for a stable seed. It does not validate clinical truth.
|
|
38
|
+
|
|
39
|
+
## Bind using your terminology adapter
|
|
40
|
+
|
|
41
|
+
Implement the async `TerminologyClient` protocol for your terminology service. The library
|
|
42
|
+
contains no HTTP client, URL, authentication, or credentials.
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from fhiratwill import TerminologyClient, bind_bundle
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
async def bind(bundle: dict, terminology: TerminologyClient) -> dict:
|
|
49
|
+
result = await bind_bundle(bundle, client=terminology)
|
|
50
|
+
return result.bundle
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Binding uses exact aliases from the packaged, reviewed `concepts.yaml`; it performs no
|
|
54
|
+
fuzzy or model-based coding. A candidate is added only after the adapter verifies it.
|
|
55
|
+
Original `CodeableConcept.text` is retained. Adapters must raise
|
|
56
|
+
`TerminologyUnavailableError` when no authoritative answer is available; outages
|
|
57
|
+
propagate and fail closed.
|
|
58
|
+
|
|
59
|
+
## Rebind and compile a write plan
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from fhiratwill import (
|
|
63
|
+
GENERIC_FHIR_TARGET,
|
|
64
|
+
SubjectContext,
|
|
65
|
+
compile_write_plan,
|
|
66
|
+
rebind_bundle,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
context = SubjectContext(patient_ref="Patient/123", encounter_ref="Encounter/456")
|
|
70
|
+
rebound, notes = rebind_bundle(bundle, context)
|
|
71
|
+
plan = compile_write_plan(
|
|
72
|
+
bundle=bundle,
|
|
73
|
+
context=context,
|
|
74
|
+
conversion_id="conversion-123",
|
|
75
|
+
tenant_id="tenant-7",
|
|
76
|
+
descriptor=GENERIC_FHIR_TARGET,
|
|
77
|
+
)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Generated Patient and Encounter resources are always excluded. References are rebound only
|
|
81
|
+
to caller-supplied context. The optional preflight adapter supports direct reads only—never
|
|
82
|
+
identity search. Write plans contain deterministic idempotency keys and, when supported by
|
|
83
|
+
the descriptor, a FHIR transaction Bundle.
|
|
84
|
+
|
|
85
|
+
## Scope
|
|
86
|
+
|
|
87
|
+
This library:
|
|
88
|
+
|
|
89
|
+
- assembles grounded entity mappings into deterministic FHIR resources;
|
|
90
|
+
- verifies exact terminology candidates through a caller-provided adapter;
|
|
91
|
+
- checks and rebinds caller-supplied subject context; and
|
|
92
|
+
- compiles destination-neutral write plans.
|
|
93
|
+
|
|
94
|
+
This library does **not** submit data, authenticate to an EHR, host a terminology service,
|
|
95
|
+
perform target HTTP calls, validate full FHIR conformance, provide clinical decision
|
|
96
|
+
support, or establish HIPAA, GDPR, medical-device, or other regulatory compliance.
|
|
97
|
+
|
|
98
|
+
## Development
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
python -m pip install -e ".[dev]"
|
|
102
|
+
ruff check .
|
|
103
|
+
mypy
|
|
104
|
+
pytest
|
|
105
|
+
python -m build
|
|
106
|
+
twine check dist/*
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
No publishing command is part of the development workflow. See `CONTRIBUTING.md` and
|
|
110
|
+
`SECURITY.md` before contributing.
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
Apache License 2.0.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported versions
|
|
4
|
+
|
|
5
|
+
Security fixes are provided for the latest released minor version.
|
|
6
|
+
|
|
7
|
+
## Reporting
|
|
8
|
+
|
|
9
|
+
Report suspected vulnerabilities privately through GitHub Security Advisories:
|
|
10
|
+
|
|
11
|
+
https://github.com/Safwanmahmoud/fhirbridge/security/advisories/new
|
|
12
|
+
|
|
13
|
+
Do not include real patient data, credentials, or other secrets in a report. Use synthetic,
|
|
14
|
+
minimal reproductions. Please do not open a public issue for an unpatched vulnerability.
|
|
15
|
+
|
|
16
|
+
## Scope and safety
|
|
17
|
+
|
|
18
|
+
This package performs no authentication or network submission. Applications remain
|
|
19
|
+
responsible for transport security, authorization, audit, independent FHIR validation,
|
|
20
|
+
clinical review, and applicable regulatory obligations.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
# Hatchling 1.32 emits Core Metadata 2.5, which Twine 6.2 cannot validate yet.
|
|
3
|
+
requires = ["hatchling>=1.27,<1.32"]
|
|
4
|
+
build-backend = "hatchling.build"
|
|
5
|
+
|
|
6
|
+
[project]
|
|
7
|
+
name = "fhiratwill"
|
|
8
|
+
dynamic = ["version"]
|
|
9
|
+
description = "Deterministic, safety-focused FHIR assembly, terminology binding, and write planning."
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
|
+
license = "Apache-2.0"
|
|
13
|
+
license-files = ["LICENSE"]
|
|
14
|
+
authors = [{ name = "fhiratwill contributors" }]
|
|
15
|
+
keywords = ["fhir", "hl7", "healthcare", "interoperability", "terminology"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Intended Audience :: Healthcare Industry",
|
|
20
|
+
"License :: OSI Approved :: Apache Software License",
|
|
21
|
+
"Programming Language :: Python",
|
|
22
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: Python :: 3.13",
|
|
26
|
+
"Typing :: Typed",
|
|
27
|
+
"Topic :: Scientific/Engineering :: Medical Science Apps.",
|
|
28
|
+
]
|
|
29
|
+
dependencies = [
|
|
30
|
+
"pydantic>=2.8,<3",
|
|
31
|
+
"fhir.resources>=8.0,<9",
|
|
32
|
+
"PyYAML>=6.0,<7",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.optional-dependencies]
|
|
36
|
+
dev = [
|
|
37
|
+
"build>=1.2,<2",
|
|
38
|
+
"mypy>=1.11,<2",
|
|
39
|
+
"pytest>=8.3,<9",
|
|
40
|
+
"pytest-asyncio>=0.24,<2",
|
|
41
|
+
"ruff>=0.8,<1",
|
|
42
|
+
"twine>=5.1,<7",
|
|
43
|
+
"types-PyYAML>=6.0,<7",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
[project.urls]
|
|
47
|
+
Homepage = "https://github.com/Safwanmahmoud/fhirbridge"
|
|
48
|
+
Documentation = "https://github.com/Safwanmahmoud/fhirbridge#readme"
|
|
49
|
+
Source = "https://github.com/Safwanmahmoud/fhirbridge"
|
|
50
|
+
Issues = "https://github.com/Safwanmahmoud/fhirbridge/issues"
|
|
51
|
+
|
|
52
|
+
[tool.hatch.build.targets.wheel]
|
|
53
|
+
packages = ["src/fhiratwill"]
|
|
54
|
+
|
|
55
|
+
[tool.hatch.version]
|
|
56
|
+
path = "src/fhiratwill/__init__.py"
|
|
57
|
+
|
|
58
|
+
[tool.hatch.build.targets.sdist]
|
|
59
|
+
include = ["/src", "/tests", "/README.md", "/LICENSE", "/CHANGELOG.md", "/CONTRIBUTING.md", "/SECURITY.md"]
|
|
60
|
+
|
|
61
|
+
[tool.hatch.build]
|
|
62
|
+
include = ["src/fhiratwill/**/*.py", "src/fhiratwill/**/*.yaml", "src/fhiratwill/py.typed"]
|
|
63
|
+
|
|
64
|
+
[tool.pytest.ini_options]
|
|
65
|
+
testpaths = ["tests"]
|
|
66
|
+
asyncio_mode = "auto"
|
|
67
|
+
addopts = "-q --strict-config --strict-markers"
|
|
68
|
+
|
|
69
|
+
[tool.ruff]
|
|
70
|
+
line-length = 100
|
|
71
|
+
target-version = "py311"
|
|
72
|
+
src = ["src", "tests"]
|
|
73
|
+
|
|
74
|
+
[tool.ruff.lint]
|
|
75
|
+
select = ["E", "F", "W", "I", "B", "UP", "S", "C4", "SIM", "RUF", "ASYNC"]
|
|
76
|
+
ignore = ["S101"]
|
|
77
|
+
|
|
78
|
+
[tool.ruff.lint.per-file-ignores]
|
|
79
|
+
"tests/**" = ["S105", "S106", "S107"]
|
|
80
|
+
|
|
81
|
+
[tool.ruff.lint.isort]
|
|
82
|
+
known-first-party = ["fhiratwill", "tests"]
|
|
83
|
+
|
|
84
|
+
[tool.mypy]
|
|
85
|
+
python_version = "3.11"
|
|
86
|
+
strict = true
|
|
87
|
+
files = ["src", "tests"]
|
|
88
|
+
warn_unreachable = true
|
|
89
|
+
warn_unused_ignores = true
|
|
90
|
+
show_error_codes = true
|
|
91
|
+
|
|
92
|
+
[[tool.mypy.overrides]]
|
|
93
|
+
module = ["fhir.resources.*", "fhir_core.*"]
|
|
94
|
+
ignore_missing_imports = true
|