-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvalues_for_tests.py
More file actions
472 lines (391 loc) · 16.9 KB
/
values_for_tests.py
File metadata and controls
472 lines (391 loc) · 16.9 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
"""Store values for use in tests"""
from dataclasses import dataclass
from datetime import datetime, timedelta
from decimal import Decimal
from .generic_utils import format_date_types
# Lists of data types for 'invalid data type' testing
integers = [-1, 0, 1]
floats = [-1.3, 0.0, 1.0, 2.5]
decimals = [Decimal("-1"), Decimal("0"), Decimal("1"), Decimal("-1.3"), Decimal("2.5")]
booleans = [True, False]
dicts = [{}, {"InvalidKey": "InvalidValue"}]
lists = [[], ["Invalid"]]
strings = ["", "invalid"]
@dataclass
class InvalidDataTypes:
"""Store lists of invalid data types for tests"""
for_integers = [None] + floats + decimals + booleans + dicts + lists + strings
for_decimals_or_integers = [None] + floats + booleans + dicts + lists + strings
for_booleans = [None] + integers + floats + decimals + dicts + lists + strings
for_dicts = [None] + integers + floats + decimals + booleans + lists + strings
for_lists = [None] + integers + decimals + floats + booleans + dicts + strings
for_strings = [None] + integers + floats + decimals + booleans + dicts + lists
@dataclass
class ValidValues:
"""Store valid values for tests"""
nhs_number = "9990548609"
for_date_times_strict_timezones = [
"2000-01-01", # Full date only
"2000-01-01T00:00:00+00:00", # Time and offset all zeroes
"2025-09-24T11:04:30+01:00", # Date with Time with no milliseconds and positive offset
"2000-01-01T00:00:00+01:00", # Time and offset all zeroes
"1933-12-31T11:11:11+01:00", # Positive offset (with hours and minutes not 0)
"1933-12-31T11:11:11.1+00:00", # DateTime with milliseconds to 1 decimal place
"2000-01-01T00:00:00.000+00:00", # DateTime with milliseconds to 3 decimal places
"1933-12-31T11:11:11.111111+00:00", # DateTime with milliseconds to 6 decimal places
]
for_date_times_relaxed_timezones = for_date_times_strict_timezones + [
"2000-01-01T00:00:00+05:00", # Time and offset all zeroes
"1933-12-31T11:11:11-01:00", # Negative offset (with hours and minutes not 0)
"1933-12-31T11:11:11.1-05:00", # DateTime with milliseconds to 1 decimal place
]
for_strings_with_any_length_chars = (
"This is a really long string with more than 100 characters to test whether the validator is working well!! "
)
# Not a valid snomed code, but is valid coding format for format testing
snomed_coding_element = {
"system": "http://snomed.info/sct",
"code": "ABC123",
"display": "test",
}
valid_dose_quantity = [
{
"value": 3,
"unit": "milliliter",
"system": "http://unitsofmeasure.org",
"code": "ml",
},
{
"value": 2,
"unit": "ml",
"system": "http://snomed.info/sct",
"code": "258773002",
},
{"value": 4, "unit": "ml", "system": "http://snomed.info/sct"},
{"value": 5, "unit": "ml"},
]
manufacturer_resource_id_Man1 = {"resourceType": "Manufacturer", "id": "Man1"}
practitioner_resource_id_Pract1 = {"resourceType": "Practitioner", "id": "Pract1"}
practitioner_resource_id_Pract2 = {"resourceType": "Practitioner", "id": "Pract2"}
patient_resource_id_Pat1 = {"resourceType": "Patient", "id": "Pat1"}
patient_resource_id_Pat2 = {"resourceType": "Patient", "id": "Pat2"}
questionnnaire_resource_id_QR1 = {
"resourceType": "QuestionnaireResponse",
"id": "QR1",
"status": "completed",
}
questionnaire_immunisation = {
"linkId": "Immunisation",
"answer": [{"valueReference": {"reference": "#"}}],
}
questionnaire_reduce_validation_true = {
"linkId": "ReduceValidation",
"answer": [{"valueBoolean": True}],
}
questionnaire_reduce_validation_false = {
"linkId": "ReduceValidation",
"answer": [{"valueBoolean": False}],
}
questionnaire_ip_address = {
"linkId": "IpAddress",
"answer": [{"valueString": "IP_ADDRESS"}],
}
performer_actor_organization = {
"actor": {
"type": "Organization",
"identifier": {
"system": "https://fhir.nhs.uk/Id/ods-organization-code",
"value": "B0C4P",
},
"display": "Acme Healthcare",
}
}
performer_actor_reference_internal_Pract1 = {"actor": {"reference": "#Pract1"}}
performer_actor_reference_internal_Pract2 = {"actor": {"reference": "#Pract2"}}
performer = [
{"actor": {"reference": "#Pract1"}},
{"actor": {"type": "Organization", "display": "Acme Healthcare"}},
]
vaccination_procedure_coding_with_one_snomed_code = [
{
"system": "http://snomed.info/sct",
"code": "1324681000000101",
"display": "Administration of first dose of severe acute "
+ "respiratory syndrome coronavirus 2 vaccine (procedure)",
},
]
vaccination_procedure_coding_with_snomed_and_dmd_codes = [
{
"system": "http://snomed.info/sct",
"code": "1324681000000101",
"display": "Administration of first dose of severe acute "
+ "respiratory syndrome coronavirus 2 vaccine (procedure)",
},
{
"system": "dm+d url",
"code": "DUMMY DM+D CODE",
"display": "Administration of first dose of severe acute "
+ "respiratory syndrome coronavirus 2 vaccine (procedure)",
},
]
dummy_coding_with_one_snomed_code = [
{
"system": "http://snomed.info/sct",
"code": "DUMMY CODE 1",
"display": "DUMMY TERM 1",
},
]
vaccination_procedure_with_one_snomed_code = {
"url": "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-VaccinationProcedure",
"valueCodeableConcept": {"coding": vaccination_procedure_coding_with_one_snomed_code},
}
vaccination_procedure_with_snomed_and_dmd_codes = {
"url": "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-VaccinationProcedure",
"valueCodeableConcept": {"coding": vaccination_procedure_coding_with_snomed_and_dmd_codes},
}
vaccination_situation_with_one_snomed_code = {
"url": "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-VaccinationSituation",
"valueCodeableConcept": {"coding": dummy_coding_with_one_snomed_code},
}
nhs_number_coding_item = {
"system": "https://fhir.hl7.org.uk/CodeSystem/UKCore-NHSNumberVerificationStatusEngland",
"code": "NHS_NUMBER_STATUS_INDICATOR_CODE",
"display": "NHS_NUMBER_STATUS_INDICATOR_DESCRIPTION",
}
nhs_number_verification_status = {
"url": "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-NHSNumberVerificationStatus",
"valueCodeableConcept": {"coding": [nhs_number_coding_item]},
}
test_unique_id_uri = "https://www.ravs.england.nhs.uk/"
test_local_id = f"0002_COVID19_v1_DOSE_1^{test_unique_id_uri}"
occurrenceDateTime = "2021-02-07T13:28:17+00:00"
date_before_occurenceDateTime = "1900-01-01T00:00:00+00:00"
date_after_occurenceDateatetime = "2100-01-01T00:00:00+00:00"
valid_name_4_instances = [
{
"use": "official",
"family": "Tay",
"given": ["Sa"],
"period": {"end": date_before_occurenceDateTime},
},
{
"use": "official",
"family": "Taylor",
"given": ["Sarah"],
"period": {
"start": date_before_occurenceDateTime,
"end": date_after_occurenceDateatetime,
},
},
{"family": "Taylor", "given": ["Sar"]},
{"use": "old", "family": "Tray", "given": ["Sarah"]},
]
valid_name_4_instances_practitioner = [
{
"use": "official",
"family": "Nightingale",
"given": ["Florence"],
"period": {"end": date_before_occurenceDateTime},
},
{
"use": "official",
"family": "Night",
"given": ["Florence"],
"period": {
"start": date_before_occurenceDateTime,
"end": date_after_occurenceDateatetime,
},
},
{"family": "Night", "given": ["Florence"]},
{"use": "old", "family": "Tray", "given": ["Florence"]},
]
class NameInstances:
"""Class containing example name instances."""
class ValidCurrent:
"""Name instances which are both valid and current"""
given_and_family_only = {"given": ["a_given_name"], "family": "a_family_name"}
with_use_official = {
"given": ["a_given_name"],
"family": "a_family_name",
"use": "official",
}
with_period_start = {
"given": ["a_given_name"],
"family": "a_family_name",
"period": {"start": ValidValues.date_before_occurenceDateTime},
}
with_period_end = {
"given": ["a_given_name"],
"family": "a_family_name",
"period": {"end": ValidValues.date_after_occurenceDateatetime},
}
with_use_official_and_period_start_and_end = {
"given": ["a_given_name"],
"family": "a_family_name",
"period": {
"start": ValidValues.date_before_occurenceDateTime,
"end": ValidValues.date_after_occurenceDateatetime,
},
"use": "official",
}
use_old = {"given": ["a_given_name"], "family": "a_family_name", "use": "old"}
class ValidNonCurrent:
"""Name instances which are valid but not current"""
before_period_start = {
"given": ["a_given_name"],
"family": "a_family_name",
"period": {"start": "2100-01-01"},
}
after_period_end = {
"given": ["a_given_name"],
"family": "a_family_name",
"period": {"end": ValidValues.date_before_occurenceDateTime},
}
class Invalid:
"""Name instances which are invalid"""
family_name_only = {"family": "a_family_name"}
given_name_only = {"given": ["a_given_name"]}
family_name_only_with_use_official = {
"family": "a_family_name",
"use": "official",
}
family_name_only_with_use_official_and_period_start_and_end = {
"family": "a_family_name",
"period": {"start": "1900-01-01", "end": "2100-01-01"},
"use": "official",
}
@dataclass
class InvalidValues:
"""Store lists of invalid values for tests"""
for_whitespace_strings = [
" ", # All spaces
" \n ", # Spaces and newlines
"\r\n\t", # CR, LF and tabs
]
for_postal_codes = [
"SW1 1AA", # Too many spaces in divider
"SW 1 1A", # Too many space dividers
"AAA0000AA", # Too few space dividers
" AA00 00AA", # Invalid additional space at start
"AA00 00AA ", # Invalid additional space at end
" AA0000AA", # Space is incorrectly at start
"AA0000AA ", # Space is incorrectly at end
]
for_date_string_formats = [
# Strings which are not in acceptable date format
"", # Empty
"invalid", # With letters
"20000101", # Without dashes
"200001-01", # Missing first dash
"2000-0101", # Missing second dash
"2000:01:01", # Semi-colons instead of dashes
"2000-01-011", # Extra digit at end
"12000-01-01", # Extra digit at start
"12000-01-021", # Extra digit at start and end
"99-01-01", # Year represented without century (i.e. 2 digits instead of 4)
"01-01-1999", # DD-MM-YYYY format
"01-01-99", # DD-MM-YY format
# Strings which are in acceptable date format, but are invalid dates
"2000-00-01", # Month 0
"2000-13-01", # Month 13
"2000-01-00", # Day 0
"2000-01-32", # Day 32
"2000-02-30", # Invalid combination of month and day
]
now = datetime.now()
sample_inputs = [
now + timedelta(days=1),
now + timedelta(days=365),
now + timedelta(days=730),
]
for_future_dates = format_date_types(sample_inputs, mode="date")
# Strings which are not in acceptable date time format
for_date_time_string_formats_for_relaxed_timezone = [
"", # Empty string
"invalid", # Invalid format
*format_date_types(sample_inputs, mode="datetime"),
"20000101", # Date digits only (i.e. without hypens)
"20000101000000", # Date and time digits only
"200001010000000000", # Date, time and timezone digits only
"2000-01-01T10:34:27", # Date with Time only
"2000-01-01T10:34:27.234", # Date with Time and milliseconds
"2000", # Year only
"2000-01", # Year and month only
"2000-01-01T00:00:00+00", # Date and time with GMT timezone offset only in hours
"2000-01-01T00:00:00+01", # Date and time with BST timezone offset only in hours
"12000-01-01T00:00:00+00:00", # Extra character at start of string
"2000-01-01T00:00:00+00:001", # Extra character at end of string
"12000-01-02T00:00:00-01:001", # Extra characters at start and end of string
"2000-01-0122:22:22+00:00", # Missing T
"2000-01-0122:22:22+00:00.000", # Missing T (with milliseconds)
"2000-01-01T222222+00:00", # Missing time colons
"2000-01-01T22:22:2200:00", # Missing timezone indicator
"2000-01-01T22:22:22-01", # Timezone hours only
"99-01-01T00:00:00+00:00", # Missing century (i.e. only 2 digits for year)
"01-01-2000T00:00:00+00:00", # Date in wrong order (DD-MM-YYYY)
]
# Strings which are in acceptable date time format, but are invalid dates, times or timezones
for_date_times = [
"2000-00-01T00:00:00+00:00", # Month 00
"2000-13-01T00:00:00+00:00", # Month 13
"2000-01-00T00:00:00+00:00", # Day 00
"2000-01-32T00:00:00+00:00", # Day 32
"2000-02-30T00:00:00+00:00", # Invalid month and day combination (30th February)
"2000-01-01T24:00:00+00:00", # Hour 24
"2000-01-01T00:60:00+00:00", # Minute 60
"2000-01-01T00:00:60+00:00", # Second 60
"2000-01-01T00:00:00+24:00", # Timezone hour +24
"2000-01-01T00:00:00-24:00", # Timezone hour -24
"2000-01-01T00:00:00+00:60", # Timezone minute 60
]
for_date_time_string_formats_for_strict_timezone = for_date_time_string_formats_for_relaxed_timezone + [
"2000-01-01T22:22:22-0100", # Missing timezone colon
"2000-01-01T00:00:00-01:00", # Date and time with negative GMT timezone offset
"2000-01-01T00:00:00-05:00", # Date and time with negative offset asides from GMT and BST
"2000-01-01T00:00:00+05:00", # Date and time with offset asides from GMT and BST
"2000-01-01T00:00:00-00:00", # Date and time with negative GMT timezone offset
]
for_lists_of_strings_of_length_1 = [[1], [False], [["Test1"]]]
for_lists_of_dicts_of_length_1 = [[1], [False], [["Invalid"]], ["Invalid"]]
for_strings_with_max_100_chars = [
"This is a really long string with more than 100 characters to test whether the validator is working well"
]
for_genders = ["0", "1", "2", "9", "Male", "Female", "Unknown", "Other"]
performer_with_two_organizations = [
{"actor": {"reference": "#Pract1", "type": "Organization"}},
{"actor": {"type": "Organization", "display": "Acme Healthcare"}},
]
performer_with_no_organizations = [
{"actor": {"reference": "#Pract1", "type": "NotAnOrganisation"}},
{"actor": {"type": "NotAnOrganisation", "display": "Acme Healthcare"}},
]
practitioner_resource_with_no_id = {"resourceType": "Practitioner"}
dummy_coding_with_two_snomed_codes = [
{
"system": "http://snomed.info/sct",
"code": "DUMMY SNOMED CODE 1",
"display": "DUMMY SNOMED TERM 1",
},
{
"system": "http://snomed.info/sct",
"code": "DUMMY SNOMED CODE 2",
"display": "DUMMY SNOMED TERM 2",
},
]
vaccination_situation_with_two_snomed_codes = {
"url": "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-VaccinationSituation",
"valueCodeableConcept": {"coding": dummy_coding_with_two_snomed_codes},
}
name_with_missing_values = [
{"family": "Taylor", "period": {"start": "2024-02-07T13:28:17+00:00"}},
{"given": ["Sarah"]},
{"use": "official", "given": ["Sarah"]},
{"family": "Taylor", "given": ""},
]
name_with_missing_values_practitioner = [
{"family": "Nightingale", "period": {"start": "2024-02-07T13:28:17+00:00"}},
{"given": ["Florence"]},
{"use": "official", "given": ["Florence"]},
{"family": "Nightingale", "given": ""},
]
invalid_dose_quantity = {"value": 2, "unit": "ml", "code": "258773002"}