Skip to content

Commit 098d186

Browse files
NRL-1050 Remove TODOs, parametrize test
1 parent bea36e3 commit 098d186

File tree

2 files changed

+10
-54
lines changed

2 files changed

+10
-54
lines changed

layer/nrlf/core/tests/test_validators.py

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -419,62 +419,22 @@ def test_validate_category_too_many_category():
419419
}
420420

421421

422-
# TODO: Parameterize this test and the one below
423-
def test_validate_category_coding_display_mismatch_care_plan():
424-
validator = DocumentReferenceValidator()
425-
document_ref_data = load_document_reference_json("Y05868-736253002-Valid")
426-
427-
document_ref_data["category"][0] = {
428-
"coding": [
429-
{
430-
"system": "http://snomed.info/sct",
431-
"code": "734163000",
432-
"display": "some random display name",
433-
}
434-
]
435-
}
436-
437-
result = validator.validate(document_ref_data)
438-
439-
assert result.is_valid is False
440-
assert result.resource.id == "Y05868-99999-99999-999999"
441-
assert len(result.issues) == 1
442-
assert result.issues[0].model_dump(exclude_none=True) == {
443-
"severity": "error",
444-
"code": "value",
445-
"details": {
446-
"coding": [
447-
{
448-
"system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1",
449-
"code": "INVALID_RESOURCE",
450-
"display": "Invalid validation of resource",
451-
}
452-
]
453-
},
454-
"diagnostics": "category code '734163000' must have a display value of 'Care plan'",
455-
"expression": ["category[0].coding[0].display"],
456-
}
457-
458-
459-
def test_validate_category_coding_display_mismatch_observations():
422+
@pytest.mark.parametrize(
423+
"category_code, category_display",
424+
[
425+
(category_str.split("|")[1], display_dict["display"])
426+
for category_str, display_dict in CATEGORY_ATTRIBUTES.items()
427+
],
428+
)
429+
def test_validate_category_coding_display_mismatch(category_code: str, category_display: str):
460430
validator = DocumentReferenceValidator()
461431
document_ref_data = load_document_reference_json("Y05868-736253002-Valid")
462432

463-
document_ref_data["type"] = {
464-
"coding": [
465-
{
466-
"system": "http://snomed.info/sct",
467-
"code": "1363501000000100",
468-
"display": "Royal College of Physicians NEWS2 (National Early Warning Score 2) chart",
469-
}
470-
]
471-
}
472-
473433
document_ref_data["category"][0] = {
474434
"coding": [
475435
{
476436
"system": "http://snomed.info/sct",
477-
"code": "1102421000000108",
437+
"code": category_code,
478438
"display": "some random display name",
479439
}
480440
]
@@ -484,7 +444,6 @@ def test_validate_category_coding_display_mismatch_observations():
484444

485445
assert result.is_valid is False
486446
assert result.resource.id == "Y05868-99999-99999-999999"
487-
assert len(result.issues) == 1
488447
assert result.issues[0].model_dump(exclude_none=True) == {
489448
"severity": "error",
490449
"code": "value",
@@ -497,7 +456,7 @@ def test_validate_category_coding_display_mismatch_observations():
497456
}
498457
]
499458
},
500-
"diagnostics": "category code '1102421000000108' must have a display value of 'Observations'",
459+
"diagnostics": f"category code '{category_code}' must have a display value of '{category_display}'",
501460
"expression": ["category[0].coding[0].display"],
502461
}
503462

@@ -758,8 +717,6 @@ def test_validate_type_coding_display_mismatch(type_str: str, display: str):
758717
]
759718
}
760719

761-
# match type to category to avoid getting that error
762-
# TODO: Discuss in review if I should just ignore the error that happens to simplify test
763720
category_str = TYPE_CATEGORIES[type_str]
764721
category_parts = category_str.split("|")
765722
category_system = category_parts[0]

layer/nrlf/core/validators.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ def _validate_type(self, model: DocumentReference):
353353
"""
354354
logger.log(LogReference.VALIDATOR001, step="type")
355355

356-
# TODO: Discuss whether to add a period after the error, before Type, this should be applied to category as well
357356
if len(model.type.coding) > 1:
358357
self.result.add_error(
359358
issue_code="invalid",

0 commit comments

Comments
 (0)