@@ -18,41 +18,44 @@ class Validator:
1818 def __init__ (self , schema_file = "" , data_type : DataType = None , filepath = "" ):
1919 self .filepath = filepath
2020 self .json_data = {}
21+ self .fhir_data = {}
2122 self .schema_file = schema_file
2223 self .csv_row = ""
2324 self .csv_header = ""
2425 self .data_type = data_type
2526 self .data_parser = ""
2627 self .error_records : list [ErrorReport ] = []
2728
28- def _get_csv_line_parser (self , csv_row , csv_header ):
29- csv_parser = CSVLineParser ()
30- csv_parser .parse_csv_line (csv_row , csv_header )
31- return csv_parser
32-
33- def _get_csv_parser (self , filepath ):
29+ # Retrieve all the Parsers,
30+ def _get_csv_parser (self , filepath : str ) -> CSVParser :
3431 csv_parser = CSVParser ()
3532 csv_parser .parse_csv_file (filepath )
3633 return csv_parser
3734
38- def _get_fhir_parser (self , filepath ) :
39- fhir_parser = FHIRParser ()
40- fhir_parser . parse_fhir_file ( filepath )
41- return fhir_parser
35+ def _get_csv_line_parser (self , csv_row , csv_header ) -> CSVLineParser :
36+ csv_line_parser = CSVLineParser ()
37+ csv_line_parser . parse_csv_line ( csv_row , csv_header )
38+ return csv_line_parser
4239
43- def _get_fhir_json_parser (self , fhir_data ) :
40+ def _get_fhir_parser (self , fhir_data : dict ) -> FHIRParser :
4441 fhir_parser = FHIRParser ()
4542 fhir_parser .parse_fhir_data (fhir_data )
4643 return fhir_parser
4744
48- def _get_schema_parser (self , schemafile ) :
45+ def _get_schema_parser (self , schemafile : str ) -> SchemaParser :
4946 schema_parser = SchemaParser ()
5047 schema_parser .parse_schema (schemafile )
5148 return schema_parser
5249
50+ # Collect and add error record to the list
5351 def _add_error_record (
54- self , error_record : ErrorReport , expression_error_group , expression_name , expression_id , error_level
55- ):
52+ self ,
53+ error_record : ErrorReport ,
54+ expression_error_group : str ,
55+ expression_name : str ,
56+ expression_id : str ,
57+ error_level : ErrorLevels ,
58+ ) -> None :
5659 if error_record is not None :
5760 error_record .error_group = expression_error_group
5861 error_record .name = expression_name
@@ -61,15 +64,15 @@ def _add_error_record(
6164 self .error_records .append (error_record )
6265
6366 # Function to help identify a parent failure in the error list
64- def _check_error_record_for_fail (self , expression_id ) :
67+ def _check_error_record_for_fail (self , expression_identifier : str ) -> bool :
6568 for error_record in self .error_records :
66- if error_record .id == expression_id :
69+ if error_record .id == expression_identifier :
6770 return True
6871 return False
6972
7073 # validate a single expression against the data file
7174 def _validate_expression (
72- self , expression_validator : ExpressionChecker , expression , inc_header_in_row_count
75+ self , expression_validator : ExpressionChecker , expression : dict , inc_header_in_row_count : bool
7376 ) -> ErrorReport | int :
7477 row = 1
7578 if inc_header_in_row_count :
@@ -123,34 +126,40 @@ def _validate_expression(
123126 return row
124127
125128 def validate_fhir (
126- self , filepath , summarise = False , report_unexpected_exception = True , inc_header_in_row_count = True
129+ self ,
130+ fhir_data : dict ,
131+ summarise : bool = False ,
132+ report_unexpected_exception : bool = True ,
133+ inc_header_in_row_count : bool = True ,
127134 ) -> list [ErrorReport ]:
128135 self .data_type = DataType .FHIR
129- self .filepath = filepath
136+ self .fhir_data = fhir_data
130137 return self .run_validation (summarise , report_unexpected_exception , inc_header_in_row_count )
131138
132139 def validate_csv (
133- self , filepath , summarise = False , report_unexpected_exception = True , inc_header_in_row_count = True
140+ self ,
141+ filepath : str ,
142+ summarise : bool = False ,
143+ report_unexpected_exception : bool = True ,
144+ inc_header_in_row_count : bool = True ,
134145 ) -> list [ErrorReport ]:
135146 self .data_type = DataType .CSV
136147 self .filepath = filepath
137148 return self .run_validation (summarise , report_unexpected_exception , inc_header_in_row_count )
138149
139150 def validate_csv_row (
140- self , csv_row , csv_header , summarise = False , report_unexpected_exception = True , inc_header_in_row_count = True
151+ self ,
152+ csv_row : str ,
153+ csv_header : list [str ],
154+ summarise : bool = False ,
155+ report_unexpected_exception : bool = True ,
156+ inc_header_in_row_count : bool = True ,
141157 ) -> list [ErrorReport ]:
142158 self .data_type = DataType .CSVROW
143159 self .csv_row = csv_row
144160 self .csv_header = csv_header
145161 return self .run_validation (summarise , report_unexpected_exception , inc_header_in_row_count )
146162
147- def validate_fhir_json (
148- self , json_data , summarise = False , report_unexpected_exception = True , inc_header_in_row_count = True
149- ) -> list [ErrorReport ]:
150- self .data_type = DataType .FHIRJSON
151- self .json_data = json_data
152- return self .run_validation (summarise , report_unexpected_exception , inc_header_in_row_count )
153-
154163 # run the validation against the data
155164 def run_validation (
156165 self , summarise = False , report_unexpected_exception = True , inc_header_in_row_count = True
@@ -160,10 +169,7 @@ def run_validation(
160169
161170 match self .data_type :
162171 case DataType .FHIR :
163- self .data_parser = self ._get_fhir_parser (self .filepath )
164- self .is_csv = False
165- case DataType .FHIRJSON :
166- self .data_parser = self ._get_fhir_json_parser (self .json_data )
172+ self .data_parser = self ._get_fhir_parser (self .fhir_data )
167173 self .is_csv = False
168174 case DataType .CSV :
169175 self .data_parser = self ._get_csv_parser (self .filepath )
0 commit comments