Skip to content

Commit 883b892

Browse files
committed
seperation of concerns
1 parent 1ff20ac commit 883b892

File tree

3 files changed

+70
-75
lines changed

3 files changed

+70
-75
lines changed

delta_backend/README.md

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ This project is designed to convert FHIR-compliant JSON data (e.g., Immunization
3636

3737
---
3838

39-
## ✅ Getting Started with `test_runner.py`
39+
## ✅ Getting Started with `check_conversion.py`
4040

41-
To quickly test your conversion, use the provided `test_runner.py` script.
41+
To quickly test your conversion, use the provided `check_conversion.py` script.
4242
This script loads sample FHIR data, runs it through the converter, and automatically saves the output in both JSON and CSV formats.
4343

4444
### 🔄 How to Use It
4545

46-
1. Add your FHIR data (e.g., a dictionary or sample JSON) into the `fhir_sample` variable inside `test_runner.py`
46+
1. Add your FHIR data (e.g., a dictionary or sample JSON) into the `fhir_sample` variable inside `check_conversion.py`
4747
2. Ensure the field mapping in `ConversionLayout.py` matches your desired output
48-
3. Run the script from the `src` folder:
48+
3. Run the script from the `tests` folder:
4949

5050
```bash
51-
python test_runner.py
51+
python check_conversion.py
5252
```
5353

5454
### 📁 Output Location
@@ -68,18 +68,4 @@ You can now:
6868
- Open `output.csv` in Excel or Google Sheets to view cleanly structured records
6969
- Inspect `output.json` to validate the flat key-value output programmatically
7070

71-
---## ✅ Getting Started with `test_runner.py`
72-
73-
To quickly test your conversion, use the provided `test_runner.py` script.
74-
This script loads sample FHIR data, runs it through the converter, and automatically saves the output in both JSON and CSV formats.
75-
76-
### 🔄 How to Use It
77-
78-
1. Add your FHIR data (e.g., a dictionary or sample JSON) into the `fhir_sample` variable inside `test_runner.py`
79-
2. Ensure the field mapping in `ConversionLayout.py` matches your desired output
80-
3. Run the script from the `src` folder:
81-
82-
```bash
83-
python test_runner.py
84-
```
85-
---
71+
---
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import json
2+
import csv
3+
import os
4+
import sys
5+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
6+
from Converter import Converter
7+
8+
9+
# Sample FHIR Immunization resource (minimal test data)
10+
fhir_sample = os.path.join(os.path.dirname(__file__),"sample_data", "fhir_sample.json")
11+
12+
with open(fhir_sample, "r", encoding="utf-8") as f:
13+
json_data = json.load(f)
14+
15+
# Run the converter
16+
converter = Converter(json_data)
17+
result = converter.runConversion(json_data)
18+
19+
# Absolute path to /delta_backend
20+
output_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
21+
22+
23+
# Full paths to files
24+
json_path = os.path.join(output_dir, "output.json")
25+
csv_path = os.path.join(output_dir, "output.csv")
26+
27+
# Output result
28+
29+
print(json.dumps(result, indent=2))
30+
31+
with open(json_path, "w") as f:
32+
json.dump(result, f, indent=2)
33+
34+
# Convert JSON list of dicts to CSV
35+
if result:
36+
keys = result[0].keys()
37+
with open(csv_path, "w", newline="") as f:
38+
writer = csv.DictWriter(f, fieldnames=keys)
39+
writer.writeheader()
40+
writer.writerows(result)
41+
42+
print("CSV saved to:", csv_path)
43+
print("JSON saved to:", json_path)
Lines changed: 21 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11

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+
{
133
"resourceType": "Immunization",
144
"contained": [
155
{
@@ -41,7 +31,7 @@
4131
"birthDate": "1965-02-28",
4232
"address": [
4333
{
44-
"postalCode": "ZZ99 3CZ"
34+
"postalCode": "EC1A 1BB"
4535
}
4636
]
4737
}
@@ -52,19 +42,25 @@
5242
"valueCodeableConcept": {
5343
"coding": [
5444
{
55-
"system": "https://snomed.info/sct",
45+
"system": "http://snomed.info/sct",
5646
"code": "1324681000000101",
5747
"display": "Administration of first dose of severe acute respiratory syndrome coronavirus 2 vaccine (procedure)"
5848
}
5949
]
6050
}
6151
}
6252
],
53+
"identifier": [
54+
{
55+
"system": "https://supplierABC/identifiers/vacc",
56+
"value": "ACME-vacc123456"
57+
}
58+
],
6359
"status": "completed",
6460
"vaccineCode": {
6561
"coding": [
6662
{
67-
"system": "https://snomed.info/sct",
63+
"system": "http://snomed.info/sct",
6864
"code": "39114911000001105",
6965
"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)"
7066
}
@@ -75,22 +71,23 @@
7571
},
7672
"occurrenceDateTime": "2021-02-07T13:28:17+00:00",
7773
"recorded": "2021-02-07T13:28:17+00:00",
78-
"primarySource": True,
74+
"primarySource": true,
7975
"manufacturer": {
8076
"display": "AstraZeneca Ltd"
8177
},
8278
"location": {
79+
"type": "Location",
8380
"identifier": {
84-
"system": "urn:iso:std:iso:3166",
85-
"value": "GB"
81+
"value": "X99999",
82+
"system": "https://fhir.nhs.uk/Id/ods-organization-code"
8683
}
8784
},
8885
"lotNumber": "4120Z001",
8986
"expirationDate": "2021-07-02",
9087
"site": {
9188
"coding": [
9289
{
93-
"system": "https://snomed.info/sct",
90+
"system": "http://snomed.info/sct",
9491
"code": "368208006",
9592
"display": "Left upper arm structure (body structure)"
9693
}
@@ -99,7 +96,7 @@
9996
"route": {
10097
"coding": [
10198
{
102-
"system": "https://snomed.info/sct",
99+
"system": "http://snomed.info/sct",
103100
"code": "78421000",
104101
"display": "Intramuscular route (qualifier value)"
105102
}
@@ -108,7 +105,7 @@
108105
"doseQuantity": {
109106
"value": 0.5,
110107
"unit": "milliliter",
111-
"system": "https://unitsofmeasure.org",
108+
"system": "http://unitsofmeasure.org",
112109
"code": "ml"
113110
},
114111
"performer": [
@@ -121,8 +118,8 @@
121118
"actor": {
122119
"type": "Organization",
123120
"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"
126123
}
127124
}
128125
}
@@ -132,7 +129,7 @@
132129
"coding": [
133130
{
134131
"code": "443684005",
135-
"system": "https://snomed.info/sct"
132+
"system": "http://snomed.info/sct"
136133
}
137134
]
138135
}
@@ -143,7 +140,7 @@
143140
{
144141
"coding": [
145142
{
146-
"system": "https://snomed.info/sct",
143+
"system": "http://snomed.info/sct",
147144
"code": "840539006",
148145
"display": "Disease caused by severe acute respiratory syndrome coronavirus 2"
149146
}
@@ -154,34 +151,3 @@
154151
}
155152
]
156153
}
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

Comments
 (0)