33
44import boto3
55import fire
6+ from pydantic import ValidationError
67
78from nrlf .consumer .fhir .r4 .model import DocumentReference
89from nrlf .core .logger import logger
@@ -21,10 +22,10 @@ def _validate_document(document: str):
2122 result = validator .validate (data = docref )
2223
2324 if not result .is_valid :
24- raise Exception ("Failed to validate document: " + str (result .issues ))
25+ raise ValidationError ("Failed to validate document: " + str (result .issues ))
2526
2627
27- def _find_invalid_pointers (table_name : str ) -> dict [str , float ]:
28+ def _find_invalid_pointers (table_name : str ) -> dict [str , float | int ]:
2829 """
2930 Find pointers in the given table that are invalid.
3031 Parameters:
@@ -45,12 +46,12 @@ def _find_invalid_pointers(table_name: str) -> dict[str, float]:
4546
4647 for page in paginator .paginate (** params ):
4748 for item in page ["Items" ]:
48- id = item .get ("id" , {}).get ("S" )
49+ pointer_id = item .get ("id" , {}).get ("S" )
4950 document = item .get ("document" , {}).get ("S" , "" )
5051 try :
5152 _validate_document (document )
52- except Exception as exc :
53- invalid_pointers .append ((id , exc ))
53+ except ValidationError as exc :
54+ invalid_pointers .append ((pointer_id , exc ))
5455
5556 total_scanned_count += page ["ScannedCount" ]
5657
@@ -66,8 +67,8 @@ def _find_invalid_pointers(table_name: str) -> dict[str, float]:
6667
6768 print ("Writing invalid_pointers to file ./invalid_pointers.txt ..." ) # noqa
6869 with open ("invalid_pointers.txt" , "w" ) as f :
69- for id , err in invalid_pointers :
70- f .write (f"{ id } : { err } \n " )
70+ for _id , err in invalid_pointers :
71+ f .write (f"{ _id } : { err } \n " )
7172
7273 print (" Done" ) # noqa
7374 return {
0 commit comments