generated from BIH-CEI/napkon-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-intros.py
executable file
·152 lines (118 loc) · 4.76 KB
/
create-intros.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env python3
"""
Create an intro file for each profile from input/data/ig.yml
"""
import json
import yaml
import os
from pathlib import Path
base_path = Path(os.path.dirname(os.path.realpath(__file__)))
output_path = base_path / 'input' / 'intro-notes'
ig_fname = base_path / 'input' / 'data' / 'ig.yml'
linklist_fname = base_path / 'input' / 'includes' / 'link-list-generated.md'
profiles_fname = base_path / 'input' / 'pagecontent' / 'profiles-generated.md'
valuesets_fname = base_path / 'input' / 'pagecontent' / 'valuesets-generated.md'
template_md = """
{% assign id = {{include.id}} %}
{% assign resource = site.data.structuredefinitions.[id] %}
### Guidance
| Parameter Case Report Form | FHIR Resource Attribute |
| -------------------------- | ----------------------- |
| ... | `...` |
{:.grid}
| Parameter Case Report Form | Response Options |
| -------------------------- | ---------------- |
| ... | ... |
{:.grid}
| Response Option | Code |
| ------ | ---- |
| ... | `...` |
{:.grid}
{% capture resource_inheritance %}
This profile of a FHIR {{resource.type}} is derived from the [{{resource.base | split: '/' | last}}]({{resource.base}})
{% if resource.base contains 'https://www.medizininformatik-initiative.de/fhir' %}
profile of the [Medical Informatics Initiative (MII)][MII].
{% elsif resource.base contains 'https://www.netzwerk-universitaetsmedizin.de/fhir' %}
profile of the [German Corona Consensus Dataset (GECCO)][GECCO].
{% else %}
FHIR resource.
{% endif %}
{% endcapture %}
{{ resource_inheritance | strip_newlines }}
{% if resource.base == 'https://www.netzwerk-universitaetsmedizin.de/fhir/StructureDefinition/gecco-base-condition' %}
{% include condition-gecco-answer-options.md %}
{% endif %}
{% include link-list.md %}
"""
linklist_general = {
"GECCO": "https://simplifier.net/guide/germancoronaconsensusdataset-implementationguide/home",
"NAPKON": "https://napkon.de/",
"NUM": "https://www.netzwerk-universitaetsmedizin.de/",
"BIH": "https://www.bihealth.org/",
"MII": "https://www.medizininformatik-initiative.de/",
"uncertaintyOfPresence": "https://www.netzwerk-universitaetsmedizin.de/fhir/StructureDefinition/uncertainty-of-presence",
"ConditionVerificationStatus": "http://terminology.hl7.org/CodeSystem/condition-ver-status",
"SNOMEDCT": "http://snomed.info/sct",
"LOINC": "http://loinc.org/",
"UCUM": "http://unitsofmeasure.org",
"VSdataAbsentReason": "http://hl7.org/fhir/R4/valueset-data-absent-reason.html",
}
if not ig_fname.exists():
print('No ig.yml file found, trying to create')
fsh_generated_path = base_path /'fsh-generated' / 'resources'
ig_files = list(fsh_generated_path.glob('ImplementationGuide-*.json'))
if len(ig_files) == 0:
print('No ImplementationGuide files found in fsh-generated/resources')
exit(1)
elif len(ig_files) > 1:
print('More than one ImplementationGuide file found in fsh-generated/resources')
exit(1)
else:
json_ig_fname = ig_files[0]
if not ig_fname.parent.exists():
ig_fname.parent.mkdir()
print(f"Converting {json_ig_fname} to {ig_fname}")
content = json.loads(open(json_ig_fname).read())
yaml.dump(content, open(ig_fname, "w"))
if not output_path.exists():
output_path.mkdir(parents=True)
with open(ig_fname, 'r') as f:
ig = yaml.safe_load(f)
linklist = {}
linklist_vs = {}
for resource in ig["definition"]["resource"]:
ref = resource["reference"]["reference"]
if ref.startswith('ValueSet/'):
linklist_vs[resource["name"]] = ref.replace('/', '-') + '.html'
if not ref.startswith('StructureDefinition/') and not ref.startswith('Questionnaire/'):
continue
fname = output_path / (ref.replace('/', '-') + '-intro.md')
if not fname.exists():
print(resource["name"])
with open(fname, 'w') as f:
f.write(template_md)
linklist[resource["name"]] = ref.replace('/', '-') + '.html'
if not linklist_fname.parent.exists():
linklist_fname.parent.mkdir()
print(linklist_fname.name)
with open(linklist_fname, 'w') as f:
for k, v in linklist.items():
f.write(f'[{k}]: {v}\n')
f.write("\n")
for k, v in linklist_general.items():
f.write(f'[{k}]: {v}\n')
print(profiles_fname.name)
with open(profiles_fname, 'w') as f:
f.write('### Profiles\n\n')
for name in linklist:
if linklist[name].split('-')[0] == 'Questionnaire':
resource_type = 'questionnaire'
else:
resource_type = 'profile'
f.write(f"{{% include {resource_type}-reference.md name='{name}' %}}\n")
print(valuesets_fname.name)
with open(valuesets_fname, "w") as f:
f.write('### Value Sets\n\n')
for name in linklist_vs:
f.write(f"{{% include valueset-reference.md name='{name}' %}}\n")
print("Done")