sdc-gdr2fhir 4.0.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.
- sdc_gdr2fhir-4.0.0/LICENSE +201 -0
- sdc_gdr2fhir-4.0.0/NOTICE +16 -0
- sdc_gdr2fhir-4.0.0/PKG-INFO +139 -0
- sdc_gdr2fhir-4.0.0/README.md +118 -0
- sdc_gdr2fhir-4.0.0/pyproject.toml +40 -0
- sdc_gdr2fhir-4.0.0/setup.cfg +4 -0
- sdc_gdr2fhir-4.0.0/src/sdc_gdr2fhir/__init__.py +26 -0
- sdc_gdr2fhir-4.0.0/src/sdc_gdr2fhir/codes.py +70 -0
- sdc_gdr2fhir-4.0.0/src/sdc_gdr2fhir/mapper.py +149 -0
- sdc_gdr2fhir-4.0.0/src/sdc_gdr2fhir/mappings/nhanes_medication-epbdfmvxc3gbh5f66hhb3o2m.yaml +52 -0
- sdc_gdr2fhir-4.0.0/src/sdc_gdr2fhir/mappings/nhanes_participant-xy8upneajsb8vdcmnve01g6g.yaml +240 -0
- sdc_gdr2fhir-4.0.0/src/sdc_gdr2fhir/schemas/fhir.schema.json +60923 -0
- sdc_gdr2fhir-4.0.0/src/sdc_gdr2fhir/writer.py +245 -0
- sdc_gdr2fhir-4.0.0/src/sdc_gdr2fhir.egg-info/PKG-INFO +139 -0
- sdc_gdr2fhir-4.0.0/src/sdc_gdr2fhir.egg-info/SOURCES.txt +18 -0
- sdc_gdr2fhir-4.0.0/src/sdc_gdr2fhir.egg-info/dependency_links.txt +1 -0
- sdc_gdr2fhir-4.0.0/src/sdc_gdr2fhir.egg-info/entry_points.txt +2 -0
- sdc_gdr2fhir-4.0.0/src/sdc_gdr2fhir.egg-info/requires.txt +7 -0
- sdc_gdr2fhir-4.0.0/src/sdc_gdr2fhir.egg-info/top_level.txt +1 -0
- sdc_gdr2fhir-4.0.0/tests/test_fhir.py +212 -0
|
@@ -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,16 @@
|
|
|
1
|
+
Copyright 2026 Axius SDC, Inc.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0.
|
|
4
|
+
|
|
5
|
+
src/sdc_gdr2fhir/schemas/fhir.schema.json is the JSON schema published with HL7 FHIR Release 4 (4.0.1),
|
|
6
|
+
http://hl7.org/fhir/R4/fhir.schema.json.zip, unmodified. The FHIR specification is © HL7 and licensed under Creative
|
|
7
|
+
Commons "No Rights Reserved" (CC0); HL7®, HEALTH LEVEL SEVEN®, FHIR® and the FHIR® flame logo are trademarks owned by
|
|
8
|
+
Health Level Seven International, registered with the United States Patent and Trademark Office. This package does
|
|
9
|
+
not claim that HL7 or any of its members endorses it.
|
|
10
|
+
|
|
11
|
+
The package ships no terminology content. LOINC, SNOMED CT, ICD-10-CM and NCI Thesaurus codes appear in its output, its
|
|
12
|
+
mapping files and its tests only as the published models bind them and the records carry them.
|
|
13
|
+
|
|
14
|
+
The test fixtures under samples/ are the published packages of the NHANES Participant and NHANES Medication models of
|
|
15
|
+
the FAIR Data Demo (https://github.com/SemanticDataCharter/FAIR_Data_Demo, Apache 2.0) and a seeded sample of 200
|
|
16
|
+
records of each, generated by that project from the CDC's NHANES 2017-2018 public release.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sdc-gdr2fhir
|
|
3
|
+
Version: 4.0.0
|
|
4
|
+
Summary: Governed Data Records as HL7 FHIR R4 Bundles, through sdc-mapper: one mapping file per model, every value reported, Exceptional Values preserved.
|
|
5
|
+
Author: Axius SDC, Inc.
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Repository, https://github.com/SemanticDataCharter/sdc-gdr2fhir
|
|
8
|
+
Keywords: sdc,semantic data charter,governed data record,fhir,hl7,r4,mapping,null flavor
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Requires-Python: >=3.12
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
License-File: NOTICE
|
|
14
|
+
Requires-Dist: sdc-mapper<5,>=4.2
|
|
15
|
+
Requires-Dist: jsonschema>=4.20
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
18
|
+
Requires-Dist: pyyaml>=6.0; extra == "dev"
|
|
19
|
+
Requires-Dist: lxml>=5.0; extra == "dev"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# sdc-gdr2fhir
|
|
23
|
+
|
|
24
|
+
Governed Data Records as HL7 FHIR R4 Bundles. A target mapper for
|
|
25
|
+
[sdc-mapper](https://github.com/SemanticDataCharter/sdc-mapper): the core validates the record, resolves every value
|
|
26
|
+
against its model and reports each one; this package says which FHIR resource and element each value goes in and
|
|
27
|
+
writes the Bundle. Outbound only. Apache 2.0.
|
|
28
|
+
|
|
29
|
+
**Status:** 4.0.0 in development. Models so far, from the FAIR Data Demo:
|
|
30
|
+
|
|
31
|
+
| Model | ct_id | Resources | Rules |
|
|
32
|
+
|---|---|---|---|
|
|
33
|
+
| NHANES Participant | `xy8upneajsb8vdcmnve01g6g` | Patient, Observation, QuestionnaireResponse | 112 |
|
|
34
|
+
| NHANES Medication | `epbdfmvxc3gbh5f66hhb3o2m` | Patient, MedicationStatement, QuestionnaireResponse | 18 |
|
|
35
|
+
|
|
36
|
+
## Use
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from sdc_mapper import Engine, load_mapping
|
|
40
|
+
from sdc_gdr2fhir import FHIRMapper, mapping_path
|
|
41
|
+
|
|
42
|
+
result = Engine().map_record(xml, FHIRMapper(), load_mapping(mapping_path("xy8upneajsb8vdcmnve01g6g")))
|
|
43
|
+
result.files["Bundle.json"] # a FHIR R4 Bundle of type collection
|
|
44
|
+
result.report # every value: lookup, declared or not representable; every Exceptional Value
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Through sdc-mapper's CLI and MCP server the mapper is the target `fhir`.
|
|
48
|
+
|
|
49
|
+
## The target
|
|
50
|
+
|
|
51
|
+
**HL7 FHIR Release 4 (4.0.1)**, JSON. The specification is © HL7 and licensed under Creative Commons "No Rights
|
|
52
|
+
Reserved" (CC0); its terms allow redistribution and implementation-related products, so long as no one claims HL7's
|
|
53
|
+
endorsement and no altered specification is published as FHIR. HL7® and FHIR® are HL7's trademarks. This package
|
|
54
|
+
carries the FHIR R4 JSON schema unmodified (see `NOTICE`) and ships no terminology: LOINC, SNOMED CT, ICD-10-CM and NCI
|
|
55
|
+
Thesaurus codes appear only as the models bind them and the records carry them.
|
|
56
|
+
|
|
57
|
+
Every Bundle this package writes is valid against the FHIR R4 JSON schema, resource by resource and as a Bundle, or is
|
|
58
|
+
not written. The schema checks structure, types, required members and code patterns; it does not check FHIR's
|
|
59
|
+
invariants or terminology bindings. `tests/` runs the HL7 FHIR validator (`validator_cli.jar`) too, where Java and the
|
|
60
|
+
validator are installed (`FHIR_VALIDATOR_JAR`); it has not been run for this version.
|
|
61
|
+
|
|
62
|
+
## Where values go
|
|
63
|
+
|
|
64
|
+
Each record is one Bundle of type `collection`, identified by the record's instance id
|
|
65
|
+
(`https://semanticdatacharter.com/ns/sdc4/instance`). Entry ids and `urn:uuid` fullUrls are derived from the instance
|
|
66
|
+
id, so the same record gives the same bytes.
|
|
67
|
+
|
|
68
|
+
- **Patient**: the respondent sequence number as an identifier, and the administrative gender.
|
|
69
|
+
- **Observation**: each blood pressure reading (the vital signs blood pressure panel, LOINC 85354-9, with systolic and
|
|
70
|
+
diastolic as components, body site and status), the heart rate and each laboratory result, with the LOINC code the
|
|
71
|
+
model binds and UCUM units; smoking status, with the model's LOINC code and the answer's LOINC answer code; each
|
|
72
|
+
chronic condition indicator, with the SNOMED CT concept the model names as its subject and the Yes or No answer's
|
|
73
|
+
LOINC answer code. A condition indicator is the answer to "has a doctor ever told you", so it is an Observation of
|
|
74
|
+
the answer, not a Condition.
|
|
75
|
+
- **MedicationStatement**: the NHANES generic drug code and name, the ICD-10-CM reasons, and the status from "taken in
|
|
76
|
+
the past month" (Yes is active, No not-taken).
|
|
77
|
+
- **QuestionnaireResponse**: every other survey answer, an item each, linkId the component's identifier and text its
|
|
78
|
+
label; a Coding where the model binds each of the answer's values to its own code, else the answer as recorded.
|
|
79
|
+
|
|
80
|
+
**Lookup or declared.** Where the model binds the code FHIR needs (a laboratory result's LOINC code, a condition's
|
|
81
|
+
SNOMED CT subject, an answer's LOINC answer code, an administrative gender, an observation status), the code written
|
|
82
|
+
is the model's own and the value is a **lookup**; `tools/build_mapping.py` copies those bindings from the model into
|
|
83
|
+
the mapping file, and the mapper checks at run time that the code it writes is one the model binds. Which resource and
|
|
84
|
+
element a value goes in is **declared**, one mapping file per model.
|
|
85
|
+
|
|
86
|
+
For the 200 sample records of each model:
|
|
87
|
+
|
|
88
|
+
| Model | lookup | declared | not representable |
|
|
89
|
+
|---|---|---|---|
|
|
90
|
+
| NHANES Participant | 9,093 (65.8% of the data values) | 4,733 | 5,400 (provenance and audit) |
|
|
91
|
+
| NHANES Medication | 0 | 1,591 (100% of the data values) | 5,400 (provenance and audit) |
|
|
92
|
+
|
|
93
|
+
The medication model binds its ICD-10-CM and drug code components to their code systems, not each value to a code,
|
|
94
|
+
so its codes are written as the record holds them: declared.
|
|
95
|
+
|
|
96
|
+
## Exceptional Values: every one preserved
|
|
97
|
+
|
|
98
|
+
FHIR is the target that can say what an Exceptional Value says. Where the data-absent-reason code system
|
|
99
|
+
(`http://terminology.hl7.org/CodeSystem/data-absent-reason`) has the concept, an Observation's (or component's) value
|
|
100
|
+
is replaced by `dataAbsentReason`, and any other element carries the data-absent-reason extension. The null flavors
|
|
101
|
+
data-absent-reason has no concept for are written exactly from v3 NullFlavor
|
|
102
|
+
(`http://terminology.hl7.org/CodeSystem/v3-NullFlavor`), as the `iso21090-nullFlavor` extension on the element or a v3
|
|
103
|
+
NullFlavor coding of `dataAbsentReason` (whose binding is extensible). v3 NullFlavor has no Asked and Refused;
|
|
104
|
+
data-absent-reason does.
|
|
105
|
+
|
|
106
|
+
| ISO 21090 | Written as | Class |
|
|
107
|
+
|---|---|---|
|
|
108
|
+
| UNK | data-absent-reason `unknown` | preserved |
|
|
109
|
+
| ASKU | data-absent-reason `asked-unknown` | preserved |
|
|
110
|
+
| NAV | data-absent-reason `temp-unknown` | preserved |
|
|
111
|
+
| NASK | data-absent-reason `not-asked` | preserved |
|
|
112
|
+
| ASKR | data-absent-reason `asked-declined` | preserved |
|
|
113
|
+
| MSK | data-absent-reason `masked` | preserved |
|
|
114
|
+
| NA | data-absent-reason `not-applicable` | preserved |
|
|
115
|
+
| NINF | data-absent-reason `negative-infinity` | preserved |
|
|
116
|
+
| PINF | data-absent-reason `positive-infinity` | preserved |
|
|
117
|
+
| NI, INV, DER, OTH, UNC, QS, TRC | v3 NullFlavor, the same code | preserved |
|
|
118
|
+
|
|
119
|
+
A mapping file cannot change this table.
|
|
120
|
+
|
|
121
|
+
## What FHIR cannot hold here
|
|
122
|
+
|
|
123
|
+
- **The record's provenance and audit.** FHIR's Provenance and AuditEvent require a recorded instant with a time
|
|
124
|
+
zone, and the FAIR Data Demo records' times carry none; the PROV and audit values are reported as not representable,
|
|
125
|
+
with that reason.
|
|
126
|
+
- **Times without a time zone.** FHIR's dateTime requires a time zone with a time; an observation's date and time is
|
|
127
|
+
written as its date.
|
|
128
|
+
- Validity windows and recording times (act, vtb, vte, tr), and the definitions each component is bound to beyond the
|
|
129
|
+
codes written.
|
|
130
|
+
|
|
131
|
+
## Tests
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
pip install -e ".[dev]"
|
|
135
|
+
python -m pytest
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Every sample record is mapped and each resource validated against the FHIR R4 JSON schema; Bundles are byte-stable;
|
|
139
|
+
lookups, Exceptional Values and refused mappings are exercised.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# sdc-gdr2fhir
|
|
2
|
+
|
|
3
|
+
Governed Data Records as HL7 FHIR R4 Bundles. A target mapper for
|
|
4
|
+
[sdc-mapper](https://github.com/SemanticDataCharter/sdc-mapper): the core validates the record, resolves every value
|
|
5
|
+
against its model and reports each one; this package says which FHIR resource and element each value goes in and
|
|
6
|
+
writes the Bundle. Outbound only. Apache 2.0.
|
|
7
|
+
|
|
8
|
+
**Status:** 4.0.0 in development. Models so far, from the FAIR Data Demo:
|
|
9
|
+
|
|
10
|
+
| Model | ct_id | Resources | Rules |
|
|
11
|
+
|---|---|---|---|
|
|
12
|
+
| NHANES Participant | `xy8upneajsb8vdcmnve01g6g` | Patient, Observation, QuestionnaireResponse | 112 |
|
|
13
|
+
| NHANES Medication | `epbdfmvxc3gbh5f66hhb3o2m` | Patient, MedicationStatement, QuestionnaireResponse | 18 |
|
|
14
|
+
|
|
15
|
+
## Use
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from sdc_mapper import Engine, load_mapping
|
|
19
|
+
from sdc_gdr2fhir import FHIRMapper, mapping_path
|
|
20
|
+
|
|
21
|
+
result = Engine().map_record(xml, FHIRMapper(), load_mapping(mapping_path("xy8upneajsb8vdcmnve01g6g")))
|
|
22
|
+
result.files["Bundle.json"] # a FHIR R4 Bundle of type collection
|
|
23
|
+
result.report # every value: lookup, declared or not representable; every Exceptional Value
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Through sdc-mapper's CLI and MCP server the mapper is the target `fhir`.
|
|
27
|
+
|
|
28
|
+
## The target
|
|
29
|
+
|
|
30
|
+
**HL7 FHIR Release 4 (4.0.1)**, JSON. The specification is © HL7 and licensed under Creative Commons "No Rights
|
|
31
|
+
Reserved" (CC0); its terms allow redistribution and implementation-related products, so long as no one claims HL7's
|
|
32
|
+
endorsement and no altered specification is published as FHIR. HL7® and FHIR® are HL7's trademarks. This package
|
|
33
|
+
carries the FHIR R4 JSON schema unmodified (see `NOTICE`) and ships no terminology: LOINC, SNOMED CT, ICD-10-CM and NCI
|
|
34
|
+
Thesaurus codes appear only as the models bind them and the records carry them.
|
|
35
|
+
|
|
36
|
+
Every Bundle this package writes is valid against the FHIR R4 JSON schema, resource by resource and as a Bundle, or is
|
|
37
|
+
not written. The schema checks structure, types, required members and code patterns; it does not check FHIR's
|
|
38
|
+
invariants or terminology bindings. `tests/` runs the HL7 FHIR validator (`validator_cli.jar`) too, where Java and the
|
|
39
|
+
validator are installed (`FHIR_VALIDATOR_JAR`); it has not been run for this version.
|
|
40
|
+
|
|
41
|
+
## Where values go
|
|
42
|
+
|
|
43
|
+
Each record is one Bundle of type `collection`, identified by the record's instance id
|
|
44
|
+
(`https://semanticdatacharter.com/ns/sdc4/instance`). Entry ids and `urn:uuid` fullUrls are derived from the instance
|
|
45
|
+
id, so the same record gives the same bytes.
|
|
46
|
+
|
|
47
|
+
- **Patient**: the respondent sequence number as an identifier, and the administrative gender.
|
|
48
|
+
- **Observation**: each blood pressure reading (the vital signs blood pressure panel, LOINC 85354-9, with systolic and
|
|
49
|
+
diastolic as components, body site and status), the heart rate and each laboratory result, with the LOINC code the
|
|
50
|
+
model binds and UCUM units; smoking status, with the model's LOINC code and the answer's LOINC answer code; each
|
|
51
|
+
chronic condition indicator, with the SNOMED CT concept the model names as its subject and the Yes or No answer's
|
|
52
|
+
LOINC answer code. A condition indicator is the answer to "has a doctor ever told you", so it is an Observation of
|
|
53
|
+
the answer, not a Condition.
|
|
54
|
+
- **MedicationStatement**: the NHANES generic drug code and name, the ICD-10-CM reasons, and the status from "taken in
|
|
55
|
+
the past month" (Yes is active, No not-taken).
|
|
56
|
+
- **QuestionnaireResponse**: every other survey answer, an item each, linkId the component's identifier and text its
|
|
57
|
+
label; a Coding where the model binds each of the answer's values to its own code, else the answer as recorded.
|
|
58
|
+
|
|
59
|
+
**Lookup or declared.** Where the model binds the code FHIR needs (a laboratory result's LOINC code, a condition's
|
|
60
|
+
SNOMED CT subject, an answer's LOINC answer code, an administrative gender, an observation status), the code written
|
|
61
|
+
is the model's own and the value is a **lookup**; `tools/build_mapping.py` copies those bindings from the model into
|
|
62
|
+
the mapping file, and the mapper checks at run time that the code it writes is one the model binds. Which resource and
|
|
63
|
+
element a value goes in is **declared**, one mapping file per model.
|
|
64
|
+
|
|
65
|
+
For the 200 sample records of each model:
|
|
66
|
+
|
|
67
|
+
| Model | lookup | declared | not representable |
|
|
68
|
+
|---|---|---|---|
|
|
69
|
+
| NHANES Participant | 9,093 (65.8% of the data values) | 4,733 | 5,400 (provenance and audit) |
|
|
70
|
+
| NHANES Medication | 0 | 1,591 (100% of the data values) | 5,400 (provenance and audit) |
|
|
71
|
+
|
|
72
|
+
The medication model binds its ICD-10-CM and drug code components to their code systems, not each value to a code,
|
|
73
|
+
so its codes are written as the record holds them: declared.
|
|
74
|
+
|
|
75
|
+
## Exceptional Values: every one preserved
|
|
76
|
+
|
|
77
|
+
FHIR is the target that can say what an Exceptional Value says. Where the data-absent-reason code system
|
|
78
|
+
(`http://terminology.hl7.org/CodeSystem/data-absent-reason`) has the concept, an Observation's (or component's) value
|
|
79
|
+
is replaced by `dataAbsentReason`, and any other element carries the data-absent-reason extension. The null flavors
|
|
80
|
+
data-absent-reason has no concept for are written exactly from v3 NullFlavor
|
|
81
|
+
(`http://terminology.hl7.org/CodeSystem/v3-NullFlavor`), as the `iso21090-nullFlavor` extension on the element or a v3
|
|
82
|
+
NullFlavor coding of `dataAbsentReason` (whose binding is extensible). v3 NullFlavor has no Asked and Refused;
|
|
83
|
+
data-absent-reason does.
|
|
84
|
+
|
|
85
|
+
| ISO 21090 | Written as | Class |
|
|
86
|
+
|---|---|---|
|
|
87
|
+
| UNK | data-absent-reason `unknown` | preserved |
|
|
88
|
+
| ASKU | data-absent-reason `asked-unknown` | preserved |
|
|
89
|
+
| NAV | data-absent-reason `temp-unknown` | preserved |
|
|
90
|
+
| NASK | data-absent-reason `not-asked` | preserved |
|
|
91
|
+
| ASKR | data-absent-reason `asked-declined` | preserved |
|
|
92
|
+
| MSK | data-absent-reason `masked` | preserved |
|
|
93
|
+
| NA | data-absent-reason `not-applicable` | preserved |
|
|
94
|
+
| NINF | data-absent-reason `negative-infinity` | preserved |
|
|
95
|
+
| PINF | data-absent-reason `positive-infinity` | preserved |
|
|
96
|
+
| NI, INV, DER, OTH, UNC, QS, TRC | v3 NullFlavor, the same code | preserved |
|
|
97
|
+
|
|
98
|
+
A mapping file cannot change this table.
|
|
99
|
+
|
|
100
|
+
## What FHIR cannot hold here
|
|
101
|
+
|
|
102
|
+
- **The record's provenance and audit.** FHIR's Provenance and AuditEvent require a recorded instant with a time
|
|
103
|
+
zone, and the FAIR Data Demo records' times carry none; the PROV and audit values are reported as not representable,
|
|
104
|
+
with that reason.
|
|
105
|
+
- **Times without a time zone.** FHIR's dateTime requires a time zone with a time; an observation's date and time is
|
|
106
|
+
written as its date.
|
|
107
|
+
- Validity windows and recording times (act, vtb, vte, tr), and the definitions each component is bound to beyond the
|
|
108
|
+
codes written.
|
|
109
|
+
|
|
110
|
+
## Tests
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
pip install -e ".[dev]"
|
|
114
|
+
python -m pytest
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Every sample record is mapped and each resource validated against the FHIR R4 JSON schema; Bundles are byte-stable;
|
|
118
|
+
lookups, Exceptional Values and refused mappings are exercised.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "sdc-gdr2fhir"
|
|
7
|
+
version = "4.0.0"
|
|
8
|
+
description = "Governed Data Records as HL7 FHIR R4 Bundles, through sdc-mapper: one mapping file per model, every value reported, Exceptional Values preserved."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
13
|
+
authors = [{ name = "Axius SDC, Inc." }]
|
|
14
|
+
keywords = ["sdc", "semantic data charter", "governed data record", "fhir", "hl7", "r4", "mapping", "null flavor"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
]
|
|
18
|
+
dependencies = [
|
|
19
|
+
"sdc-mapper>=4.2,<5", # placements, '=name' joins, declared cluster order (4.2.0)
|
|
20
|
+
"jsonschema>=4.20", # the FHIR R4 JSON schema (draft-06)
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.optional-dependencies]
|
|
24
|
+
dev = ["pytest>=8.0", "pyyaml>=6.0", "lxml>=5.0"]
|
|
25
|
+
|
|
26
|
+
[project.entry-points."sdc_mapper.targets"]
|
|
27
|
+
fhir = "sdc_gdr2fhir:FHIRMapper"
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Repository = "https://github.com/SemanticDataCharter/sdc-gdr2fhir"
|
|
31
|
+
|
|
32
|
+
[tool.setuptools.packages.find]
|
|
33
|
+
where = ["src"]
|
|
34
|
+
|
|
35
|
+
[tool.setuptools.package-data]
|
|
36
|
+
sdc_gdr2fhir = ["mappings/*.yaml", "schemas/*.json"]
|
|
37
|
+
|
|
38
|
+
[tool.pytest.ini_options]
|
|
39
|
+
testpaths = ["tests"]
|
|
40
|
+
markers = ["validator: needs Java and the HL7 FHIR validator jar"]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""sdc-gdr2fhir: Governed Data Records as HL7 FHIR R4 Bundles, through sdc-mapper.
|
|
2
|
+
|
|
3
|
+
from sdc_mapper import Engine, load_mapping
|
|
4
|
+
from sdc_gdr2fhir import FHIRMapper, mapping_path
|
|
5
|
+
result = Engine().map_record(xml, FHIRMapper(), load_mapping(mapping_path("xy8upneajsb8vdcmnve01g6g")))
|
|
6
|
+
|
|
7
|
+
One mapping file per model, in `mappings/`. Registered with sdc-mapper as the target `fhir`.
|
|
8
|
+
"""
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
__version__ = "4.0.0"
|
|
12
|
+
|
|
13
|
+
MAPPINGS = Path(__file__).with_name("mappings")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def mapping_path(ct_id: str) -> Path:
|
|
17
|
+
"""The mapping file this package publishes for a model, by the model's identifier."""
|
|
18
|
+
found = sorted(MAPPINGS.glob(f"*-{ct_id}.yaml"))
|
|
19
|
+
if not found:
|
|
20
|
+
raise FileNotFoundError(f"sdc-gdr2fhir has no mapping for model {ct_id}")
|
|
21
|
+
return found[-1]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
from .mapper import FHIRMapper # noqa: E402
|
|
25
|
+
|
|
26
|
+
__all__ = ["FHIRMapper", "mapping_path", "MAPPINGS", "__version__"]
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""Codes as FHIR writes them: an IRI the model binds a value to, as a (system, code) pair FHIR's Coding takes.
|
|
2
|
+
|
|
3
|
+
A model binds an enumerated value to its definition (`rdfs:isDefinedBy`) and a component to concepts (`skos:exactMatch`,
|
|
4
|
+
`dcterms:subject`). Where such an IRI names one concept of a code system FHIR knows, the pair below is that concept as a
|
|
5
|
+
FHIR Coding; an IRI that names a whole system, or a page that defines a variable rather than one answer, gives none.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import re
|
|
10
|
+
|
|
11
|
+
LOINC = "http://loinc.org"
|
|
12
|
+
SNOMED = "http://snomed.info/sct"
|
|
13
|
+
NCIT = "http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl"
|
|
14
|
+
UCUM = "http://unitsofmeasure.org"
|
|
15
|
+
|
|
16
|
+
_PATTERNS = [
|
|
17
|
+
(re.compile(r"^https?://loinc\.org/((?:LA|LP|LG)?[0-9]+-[0-9])/?$"), LOINC),
|
|
18
|
+
(re.compile(r"^https?://snomed\.info/id/([0-9]+)$"), SNOMED),
|
|
19
|
+
(re.compile(r"^https?://purl\.obolibrary\.org/obo/NCIT_(C[0-9]+)$"), NCIT),
|
|
20
|
+
]
|
|
21
|
+
_FRAGMENT = re.compile(r"^(https?://(?:hl7\.org/fhir|terminology\.hl7\.org/CodeSystem)/[A-Za-z0-9./-]+)#([^#\s]+)$")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def coding(iri: str | None) -> tuple[str, str] | None:
|
|
25
|
+
"""The (system, code) an IRI names, or None."""
|
|
26
|
+
if not iri:
|
|
27
|
+
return None
|
|
28
|
+
for pattern, system in _PATTERNS:
|
|
29
|
+
m = pattern.match(iri)
|
|
30
|
+
if m:
|
|
31
|
+
return system, m.group(1)
|
|
32
|
+
m = _FRAGMENT.match(iri)
|
|
33
|
+
if m:
|
|
34
|
+
return m.group(1), m.group(2)
|
|
35
|
+
return None
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def bound_codes(value) -> set[str]:
|
|
39
|
+
"""Every code the model binds a resolved value to: its enumeration value's definition, and the component's
|
|
40
|
+
exact matches and subjects. A target code that is one of these comes from the model: a lookup."""
|
|
41
|
+
iris = []
|
|
42
|
+
if value.code and value.code.defined_by:
|
|
43
|
+
iris.append(value.code.defined_by)
|
|
44
|
+
for predicate, targets in (value.links or {}).items():
|
|
45
|
+
if predicate.endswith(("#exactMatch", "/subject")):
|
|
46
|
+
iris.extend(targets)
|
|
47
|
+
return {c[1] for c in map(coding, iris) if c}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
#: The Default library's unit symbols that are not already UCUM codes.
|
|
51
|
+
UCUM_CODES = {"mmHg": "mm[Hg]"}
|
|
52
|
+
|
|
53
|
+
#: ISO 21090 null flavors as FHIR R4 writes them. Where the data-absent-reason code system has the same concept, it is
|
|
54
|
+
#: written (as Observation.dataAbsentReason, or the data-absent-reason extension on any other element); every other
|
|
55
|
+
#: code is written exactly, from v3 NullFlavor, with the iso21090-nullFlavor extension (or as a v3 NullFlavor coding of
|
|
56
|
+
#: dataAbsentReason, whose binding is extensible). v3 NullFlavor has no Asked and Refused; data-absent-reason does.
|
|
57
|
+
DATA_ABSENT_REASON = "http://terminology.hl7.org/CodeSystem/data-absent-reason"
|
|
58
|
+
V3_NULL_FLAVOR = "http://terminology.hl7.org/CodeSystem/v3-NullFlavor"
|
|
59
|
+
DAR_EXTENSION = "http://hl7.org/fhir/StructureDefinition/data-absent-reason"
|
|
60
|
+
NULL_FLAVOR_EXTENSION = "http://hl7.org/fhir/StructureDefinition/iso21090-nullFlavor"
|
|
61
|
+
DAR = {"UNK": "unknown", "ASKU": "asked-unknown", "NAV": "temp-unknown", "NASK": "not-asked", "ASKR": "asked-declined",
|
|
62
|
+
"MSK": "masked", "NA": "not-applicable", "NINF": "negative-infinity", "PINF": "positive-infinity"}
|
|
63
|
+
V3_ONLY = ("NI", "INV", "DER", "OTH", "UNC", "QS", "TRC")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def absent(code: str) -> tuple[str, str, str]:
|
|
67
|
+
"""(code system, code, extension url) FHIR writes for an ISO 21090 code."""
|
|
68
|
+
if code in DAR:
|
|
69
|
+
return DATA_ABSENT_REASON, DAR[code], DAR_EXTENSION
|
|
70
|
+
return V3_NULL_FLAVOR, code, NULL_FLAVOR_EXTENSION
|