Skip to content

Commit fdef8a1

Browse files
committed
VED-350: refactor validation for elements
1 parent 52c02ac commit fdef8a1

File tree

2 files changed

+2
-32
lines changed

2 files changed

+2
-32
lines changed

backend/src/fhir_controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,11 +506,11 @@ def _validate_identifier_system(self, _id: str, _element: str) -> Optional[dict]
506506
'e.g. "http://xyz.org/vaccs|2345-gh3s-r53h7-12ny"'
507507
),
508508
)
509-
509+
510510
element_lower = _element.lower()
511511
result = element_lower.split(",")
512512
is_present = all(key in ["id", "meta"] for key in result)
513-
if not is_present:
513+
if _element and not is_present:
514514
return create_operation_outcome(
515515
resource_id=str(uuid.uuid4()),
516516
severity=Severity.error,

backend/tests/test_fhir_controller.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -339,36 +339,6 @@ def test_validate_immunization_identifier_is_empty(self, mock_get_supplier_permi
339339
outcome = json.loads(response["body"])
340340
self.assertEqual(outcome["resourceType"], "OperationOutcome")
341341

342-
@patch("fhir_controller.get_supplier_permissions")
343-
def test_validate_immunization_element_is_empty(self, mock_get_supplier_permissions):
344-
"""it should return 400 as element is missing"""
345-
mock_get_supplier_permissions.return_value = ["COVID19.CRUDS"]
346-
self.service.get_immunization_by_identifier.return_value = {
347-
"resourceType": "OperationOutcome",
348-
"id": "f6857e0e-40d0-4e5e-9e2f-463f87d357c6",
349-
"meta": {"profile": ["https://simplifier.net/guide/UKCoreDevelopment2/ProfileUKCore-OperationOutcome"]},
350-
"issue": [
351-
{
352-
"severity": "error",
353-
"code": "invalid",
354-
"details": {
355-
"coding": [{"system": "https://fhir.nhs.uk/Codesystem/http-error-codes", "code": "INVALID"}]
356-
},
357-
"diagnostics": "The provided identifiervalue is either missing or not in the expected format.",
358-
}
359-
],
360-
}
361-
lambda_event = {
362-
"headers": { "SupplierSystem": "test"},
363-
"queryStringParameters": {"identifier": "test|123", "_elements": ""},
364-
"body": None,
365-
}
366-
response = self.controller.get_immunization_by_identifier(lambda_event)
367-
368-
self.assertEqual(self.service.get_immunization_by_identifier.call_count, 0)
369-
self.assertEqual(response["statusCode"], 400)
370-
outcome = json.loads(response["body"])
371-
self.assertEqual(outcome["resourceType"], "OperationOutcome")
372342

373343
@patch("fhir_controller.get_supplier_permissions")
374344
def test_validate_immunization_identifier_in_invalid_format(self,mock_get_supplier_permissions):

0 commit comments

Comments
 (0)