-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_test_data.py
More file actions
199 lines (188 loc) · 5.48 KB
/
create_test_data.py
File metadata and controls
199 lines (188 loc) · 5.48 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import os
import json
import random
from datetime import datetime, timedelta
# Create input directory if it does not exist
input_dir = os.path.join(os.getcwd(), "input")
os.makedirs(input_dir, exist_ok=True)
# Create a sample FHIR Patient
patient_example = {
"resourceType": "Patient",
"id": "example-patient-1",
"name": [
{
"use": "official",
"family": "Smith",
"given": ["John"]
}
],
"telecom": [
{
"system": "phone",
"value": "555-1234"
},
{
"system": "email",
"value": "john.smith@example.com"
}
],
"gender": "male",
"birthDate": "1970-01-01",
"address": [
{
"use": "home",
"line": ["123 Main St"],
"city": "Anytown",
"state": "CA",
"postalCode": "12345",
"country": "USA"
}
]
}
# Create a second patient
patient_example2 = {
"resourceType": "Patient",
"id": "example-patient-2",
"name": [
{
"use": "official",
"family": "Johnson",
"given": ["Sarah"]
}
],
"telecom": [
{
"system": "phone",
"value": "555-5678"
},
{
"system": "email",
"value": "sarah.johnson@example.com"
}
],
"gender": "female",
"birthDate": "1985-05-15"
}
# Common medications with RxNorm codes
medications = [
{
"code": "1049502",
"display": "Acetaminophen 325 MG Oral Tablet",
"system": "http://www.nlm.nih.gov/research/umls/rxnorm"
},
{
"code": "197319",
"display": "Amoxicillin 500 MG Oral Capsule",
"system": "http://www.nlm.nih.gov/research/umls/rxnorm"
},
{
"code": "197318",
"display": "Ibuprofen 200 MG Oral Tablet",
"system": "http://www.nlm.nih.gov/research/umls/rxnorm"
},
{
"code": "310965",
"display": "Lisinopril 10 MG Oral Tablet",
"system": "http://www.nlm.nih.gov/research/umls/rxnorm"
},
{
"code": "314076",
"display": "Simvastatin 20 MG Oral Tablet",
"system": "http://www.nlm.nih.gov/research/umls/rxnorm"
}
]
# Create multiple MedicationStatement examples for the first patient
medication_examples = []
for i in range(3):
med = random.choice(medications)
medication_examples.append({
"resourceType": "MedicationStatement",
"id": f"med-{i+1}",
"subject": {
"reference": "Patient/example-patient-1"
},
"status": "active",
"medicationCodeableConcept": {
"coding": [
{
"system": med["system"],
"code": med["code"],
"display": med["display"]
}
],
"text": med["display"]
},
"effectiveDateTime": (datetime.now() - timedelta(days=random.randint(0, 30))).strftime("%Y-%m-%dT%H:%M:%SZ"),
"dateAsserted": datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"),
"dosage": [
{
"text": f"Take 1 tablet by mouth {random.choice(['daily', 'twice daily', 'as needed'])}",
"timing": {
"repeat": {
"frequency": random.choice([1, 2]),
"period": 1,
"periodUnit": "d"
}
},
"route": {
"coding": [
{
"system": "http://snomed.info/sct",
"code": "26643006",
"display": "Oral route"
}
]
}
}
]
})
# Create a medication for the second patient
med = random.choice(medications)
medication_examples.append({
"resourceType": "MedicationStatement",
"id": "med-4",
"subject": {
"reference": "Patient/example-patient-2"
},
"status": "active",
"medicationCodeableConcept": {
"coding": [
{
"system": med["system"],
"code": med["code"],
"display": med["display"]
}
],
"text": med["display"]
}
})
# # Save the patient files to the input directory
# with open(os.path.join(input_dir, "patient1.json"), "w") as f:
# json.dump(patient_example, f, indent=2)
#
# with open(os.path.join(input_dir, "patient2.json"), "w") as f:
# json.dump(patient_example2, f, indent=2)
#
# # Save each medication to a separate file
# for i, med in enumerate(medication_examples):
# with open(os.path.join(input_dir, f"medication{i+1}.json"), "w") as f:
# json.dump(med, f, indent=2)
# Create a bundle with all resources for testing bulk processing
bundle = {
"resourceType": "Bundle",
"type": "collection",
"entry": [
{"resource": patient_example},
{"resource": patient_example2}
]
}
# Add medications to bundle
for med in medication_examples:
bundle["entry"].append({"resource": med})
# Save the bundle
with open(os.path.join(input_dir, "bundle.json"), "w") as f:
json.dump(bundle, f, indent=2)
print(f"Created {len(medication_examples)} medication files in {input_dir}")
print(f"Created {2} patient files in {input_dir}")
print(f"Created bundle with {len(bundle['entry'])} resources in {os.path.join(input_dir, 'bundle.json')}")
print(f"Sample files created in {input_dir}")