Skip to content

Commit a970f92

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

File tree

2 files changed

+33
-48
lines changed

2 files changed

+33
-48
lines changed

layer/nrlf/core/tests/test_validators.py

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -419,66 +419,52 @@ 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():
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(
430+
category_code: str, category_display: str
431+
):
424432
validator = DocumentReferenceValidator()
425433
document_ref_data = load_document_reference_json("Y05868-736253002-Valid")
426434

427435
document_ref_data["category"][0] = {
428436
"coding": [
429437
{
430438
"system": "http://snomed.info/sct",
431-
"code": "734163000",
439+
"code": category_code,
432440
"display": "some random display name",
433441
}
434442
]
435443
}
436444

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": {
445+
# Find the type string that matches the type code to avoid that error
446+
category_str = f"http://snomed.info/sct|{category_code}"
447+
matching_type_str = next(
448+
(
449+
type_str
450+
for type_str in TYPE_CATEGORIES
451+
if TYPE_CATEGORIES[type_str] == category_str
452+
),
453+
None,
454+
)
455+
if matching_type_str:
456+
type_parts = matching_type_str.split("|")
457+
type_system = type_parts[0]
458+
type_code = type_parts[1]
459+
document_ref_data["type"] = {
446460
"coding": [
447461
{
448-
"system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1",
449-
"code": "INVALID_RESOURCE",
450-
"display": "Invalid validation of resource",
462+
"system": type_system,
463+
"code": type_code,
464+
"display": TYPE_ATTRIBUTES[matching_type_str]["display"],
451465
}
452466
]
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():
460-
validator = DocumentReferenceValidator()
461-
document_ref_data = load_document_reference_json("Y05868-736253002-Valid")
462-
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-
473-
document_ref_data["category"][0] = {
474-
"coding": [
475-
{
476-
"system": "http://snomed.info/sct",
477-
"code": "1102421000000108",
478-
"display": "some random display name",
479-
}
480-
]
481-
}
467+
}
482468

483469
result = validator.validate(document_ref_data)
484470

@@ -497,7 +483,7 @@ def test_validate_category_coding_display_mismatch_observations():
497483
}
498484
]
499485
},
500-
"diagnostics": "category code '1102421000000108' must have a display value of 'Observations'",
486+
"diagnostics": f"category code '{category_code}' must have a display value of '{category_display}'",
501487
"expression": ["category[0].coding[0].display"],
502488
}
503489

@@ -758,8 +744,7 @@ def test_validate_type_coding_display_mismatch(type_str: str, display: str):
758744
]
759745
}
760746

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
747+
# Find the category string that matches the category code to avoid that error
763748
category_str = TYPE_CATEGORIES[type_str]
764749
category_parts = category_str.split("|")
765750
category_system = category_parts[0]
@@ -778,6 +763,7 @@ def test_validate_type_coding_display_mismatch(type_str: str, display: str):
778763

779764
assert result.is_valid is False
780765
assert result.resource.id == "Y05868-99999-99999-999999"
766+
assert len(result.issues) == 1
781767
assert result.issues[0].model_dump(exclude_none=True) == {
782768
"severity": "error",
783769
"code": "value",

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)