|
1 | 1 |
|
2 | | -import json |
3 | | -import csv |
4 | | -import os |
5 | | -import sys |
6 | | - |
7 | | -sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) |
8 | | -from Converter import Converter |
9 | | - |
10 | | - |
11 | | -# Sample FHIR Immunization resource (minimal test data) |
12 | | -fhir_sample = { |
| 2 | +{ |
13 | 3 | "resourceType": "Immunization", |
14 | 4 | "contained": [ |
15 | 5 | { |
|
41 | 31 | "birthDate": "1965-02-28", |
42 | 32 | "address": [ |
43 | 33 | { |
44 | | - "postalCode": "ZZ99 3CZ" |
| 34 | + "postalCode": "EC1A 1BB" |
45 | 35 | } |
46 | 36 | ] |
47 | 37 | } |
|
52 | 42 | "valueCodeableConcept": { |
53 | 43 | "coding": [ |
54 | 44 | { |
55 | | - "system": "https://snomed.info/sct", |
| 45 | + "system": "http://snomed.info/sct", |
56 | 46 | "code": "1324681000000101", |
57 | 47 | "display": "Administration of first dose of severe acute respiratory syndrome coronavirus 2 vaccine (procedure)" |
58 | 48 | } |
59 | 49 | ] |
60 | 50 | } |
61 | 51 | } |
62 | 52 | ], |
| 53 | + "identifier": [ |
| 54 | + { |
| 55 | + "system": "https://supplierABC/identifiers/vacc", |
| 56 | + "value": "ACME-vacc123456" |
| 57 | + } |
| 58 | + ], |
63 | 59 | "status": "completed", |
64 | 60 | "vaccineCode": { |
65 | 61 | "coding": [ |
66 | 62 | { |
67 | | - "system": "https://snomed.info/sct", |
| 63 | + "system": "http://snomed.info/sct", |
68 | 64 | "code": "39114911000001105", |
69 | 65 | "display": "COVID-19 Vaccine Vaxzevria (ChAdOx1 S [recombinant]) not less than 2.5x100,000,000 infectious units/0.5ml dose suspension for injection multidose vials (AstraZeneca UK Ltd) (product)" |
70 | 66 | } |
|
75 | 71 | }, |
76 | 72 | "occurrenceDateTime": "2021-02-07T13:28:17+00:00", |
77 | 73 | "recorded": "2021-02-07T13:28:17+00:00", |
78 | | - "primarySource": True, |
| 74 | + "primarySource": true, |
79 | 75 | "manufacturer": { |
80 | 76 | "display": "AstraZeneca Ltd" |
81 | 77 | }, |
82 | 78 | "location": { |
| 79 | + "type": "Location", |
83 | 80 | "identifier": { |
84 | | - "system": "urn:iso:std:iso:3166", |
85 | | - "value": "GB" |
| 81 | + "value": "X99999", |
| 82 | + "system": "https://fhir.nhs.uk/Id/ods-organization-code" |
86 | 83 | } |
87 | 84 | }, |
88 | 85 | "lotNumber": "4120Z001", |
89 | 86 | "expirationDate": "2021-07-02", |
90 | 87 | "site": { |
91 | 88 | "coding": [ |
92 | 89 | { |
93 | | - "system": "https://snomed.info/sct", |
| 90 | + "system": "http://snomed.info/sct", |
94 | 91 | "code": "368208006", |
95 | 92 | "display": "Left upper arm structure (body structure)" |
96 | 93 | } |
|
99 | 96 | "route": { |
100 | 97 | "coding": [ |
101 | 98 | { |
102 | | - "system": "https://snomed.info/sct", |
| 99 | + "system": "http://snomed.info/sct", |
103 | 100 | "code": "78421000", |
104 | 101 | "display": "Intramuscular route (qualifier value)" |
105 | 102 | } |
|
108 | 105 | "doseQuantity": { |
109 | 106 | "value": 0.5, |
110 | 107 | "unit": "milliliter", |
111 | | - "system": "https://unitsofmeasure.org", |
| 108 | + "system": "http://unitsofmeasure.org", |
112 | 109 | "code": "ml" |
113 | 110 | }, |
114 | 111 | "performer": [ |
|
121 | 118 | "actor": { |
122 | 119 | "type": "Organization", |
123 | 120 | "identifier": { |
124 | | - "system": "https://fhir.nhs.uk/Id/ods-organization-code", |
125 | | - "value": "N2N9I" |
| 121 | + "system": "https://fhir.hl7.org.uk/Id/urn-school-number", |
| 122 | + "value": "B0C4P" |
126 | 123 | } |
127 | 124 | } |
128 | 125 | } |
|
132 | 129 | "coding": [ |
133 | 130 | { |
134 | 131 | "code": "443684005", |
135 | | - "system": "https://snomed.info/sct" |
| 132 | + "system": "http://snomed.info/sct" |
136 | 133 | } |
137 | 134 | ] |
138 | 135 | } |
|
143 | 140 | { |
144 | 141 | "coding": [ |
145 | 142 | { |
146 | | - "system": "https://snomed.info/sct", |
| 143 | + "system": "http://snomed.info/sct", |
147 | 144 | "code": "840539006", |
148 | 145 | "display": "Disease caused by severe acute respiratory syndrome coronavirus 2" |
149 | 146 | } |
|
154 | 151 | } |
155 | 152 | ] |
156 | 153 | } |
157 | | - |
158 | | - |
159 | | -# Run the converter |
160 | | -converter = Converter(fhir_sample) |
161 | | -result = converter.runConversion(fhir_sample) |
162 | | - |
163 | | -# Absolute path to /delta_backend |
164 | | -output_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) |
165 | | - |
166 | | - |
167 | | -# Full paths to files |
168 | | -json_path = os.path.join(output_dir, "output.json") |
169 | | -csv_path = os.path.join(output_dir, "output.csv") |
170 | | - |
171 | | -# Output result |
172 | | - |
173 | | -print(json.dumps(result, indent=2)) |
174 | | - |
175 | | -with open(json_path, "w") as f: |
176 | | - json.dump(result, f, indent=2) |
177 | | - |
178 | | -# Convert JSON list of dicts to CSV |
179 | | -if result: |
180 | | - keys = result[0].keys() |
181 | | - with open(csv_path, "w", newline="") as f: |
182 | | - writer = csv.DictWriter(f, fieldnames=keys) |
183 | | - writer.writeheader() |
184 | | - writer.writerows(result) |
185 | | - |
186 | | -print("CSV saved to:", csv_path) |
187 | | -print("JSON saved to:", json_path) |
0 commit comments