Skip to content

Commit d5a7929

Browse files
author
nicolasblumenroehr
committed
Fix metadata_reader
1 parent a4dc838 commit d5a7929

4 files changed

Lines changed: 18 additions & 17 deletions

File tree

‎.DS_Store‎

-2 KB
Binary file not shown.

‎jammato/attribute_inserter.py‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
from .attribute_mapper import Attribute_Mapper
44

5+
56
class Attribute_Inserter():
67

78
def __init__(self, schema_skeleton: dict, key_list: list, map: object) -> None:
@@ -35,9 +36,9 @@ def fill_json_object(self, json_object: dict, key_list: list, attributes_object:
3536
for key in key_list:
3637
if (isinstance(json_object[key], str)) or (isinstance(json_object[key], tuple)):
3738
if key in attributes_object.keys():
38-
new_dict[key] = self.get_json_type(json_object[key], attributes_object[key])
39+
new_dict[key] = self.get_json_type(json_object[key], attributes_object[key], key)
3940
else:
40-
new_dict[key] = self.get_json_type(json_object[key], json_object[key])
41+
new_dict[key] = self.get_json_type(json_object[key], json_object[key], key)
4142
elif isinstance(json_object[key], dict):
4243
if key in attributes_object:
4344
if isinstance(attributes_object[key], Attribute_Mapper):
@@ -75,7 +76,7 @@ def fill_json_array(self, json_object: dict, json_object_property: str, json_arr
7576
Returns:
7677
list: The list that represents the filled json array.
7778
"""
78-
if isinstance(attributes, list) == False:
79+
if not isinstance(attributes, list):
7980
if json_object_property in attributes.__dict__.keys():
8081
attributes = attributes.__dict__[json_object_property]
8182
try:
@@ -89,7 +90,7 @@ def fill_json_array(self, json_object: dict, json_object_property: str, json_arr
8990
for list_item, list_index in zip(json_array, range(0, len(json_array))):
9091
if (isinstance(list_item, str)) or (isinstance(list_item, tuple)):
9192
try:
92-
new_list.append(self.get_json_type(list_item, attributes[list_index]))
93+
new_list.append(self.get_json_type(list_item, attributes[list_index], None))
9394
except TypeError as e:
9495
logging.warning(e)
9596
pass
@@ -106,7 +107,7 @@ def fill_json_array(self, json_object: dict, json_object_property: str, json_arr
106107
pass
107108
return new_list
108109

109-
def get_json_type(self, data_type: str, attribute: str) -> Any:
110+
def get_json_type(self, data_type: str, attribute: str, key) -> Any:
110111
"""Takes an attribute and its data type. Confirms the primitive data types of the mapped attribute values and assigns these values to the schema attribute. The correct hirarchial
111112
position has been reached through the methods above.
112113
@@ -118,19 +119,19 @@ def get_json_type(self, data_type: str, attribute: str) -> Any:
118119
Any: The value of the mapped attribute as the correct data type.
119120
"""
120121
try:
121-
if (isinstance(data_type, tuple) and (isinstance(attribute, tuple)==False)):
122+
if (isinstance(data_type, tuple) and not (isinstance(attribute, tuple))):
122123
if (isinstance(attribute, list)) and ("<class 'list'>" in data_type):
123124
return attribute
124125
else:
125126
for element in data_type:
126127
if element in ["<class 'int'>", "<class 'bool'>", "<class 'None'>", "<class 'float'>", "<class 'list'>"]:
127-
return (self.get_json_type(element, attribute))
128+
return (self.get_json_type(element, attribute, None))
128129
else:
129130
pass
130-
logging.warning(f'incorrect type provided for {attribute}, expected {data_type} but received {type(attribute)}, returning original value.')
131+
logging.warning(f'incorrect type provided for property \"{key}\", expected {data_type} but received {type(attribute)}, returning original value.')
131132
return attribute
132133
elif isinstance(attribute, tuple):
133-
logging.warning(f'No value provided for {attribute}, returning original value.')
134+
logging.warning(f'No value provided for property \"{key}\", returning original value.')
134135
return attribute
135136
elif data_type == "<class 'int'>":
136137
return int(attribute)
@@ -143,11 +144,11 @@ def get_json_type(self, data_type: str, attribute: str) -> Any:
143144
elif data_type == "<class 'str'>":
144145
return str(attribute)
145146
else:
146-
logging.warning(f'incorrect type provided for {attribute}, expected {data_type} but received {type(attribute)}, returning original value.')
147+
logging.warning(f'incorrect type provided for property \"{key}\", expected {data_type} but received {type(attribute)}, returning original value.')
147148
return attribute
148-
except TypeError as e:
149-
logging.warning(f'incorrect type provided for {attribute}, expected {data_type} but received {type(attribute)}, returning original value.')
149+
except TypeError:
150+
logging.warning(f'incorrect type provided for property \"{key}\", expected {data_type} but received {type(attribute)}, returning original value.')
150151
return attribute
151-
except ValueError as e:
152-
logging.warning(f'incorrect value provided for {attribute}, expected {data_type} but received {type(attribute)}, returning original value.')
152+
except ValueError:
153+
logging.warning(f'incorrect value provided for property \"{key}\", expected {data_type} but received {type(attribute)}, returning original value.')
153154
return attribute

‎jammato/dicom_mapping.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
import os
33
import logging
4-
from typing import Any
54
from .schema_reader import Schema_Reader
65
from .dicom_reader import Dicom_Reader
76
from .cache_schemas import Cache_Schemas
@@ -165,4 +164,4 @@ def series_extension(self, map_dict: dict, map_attribute: str, series: Dicom_Rea
165164
else:
166165
merged_series_map=assess_type.merge_mapped_attributes(series_map, element_series_attribute, list(map_dict.keys())[3])
167166

168-
return merged_series_map
167+
return merged_series_map

‎jammato/metadata_reader.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def __init__(self, metadata_document_directory: str, config_dicom_file_validatio
4141
self.all_dicom_series.extend(self.post_read_processing(value, flag="single"))
4242

4343
elif type(file_extension) == type(str()):
44-
self.evaluate_file_type(None, metadata_document_directory, file_extension)
44+
self.evaluate_file_type(metadata_document_directory, file_extension)
45+
self.all_dicom_series.extend(self.post_read_processing(list(self.all_dicom_series_dict.values())[0], flag="single"))
4546
else:
4647
logging.error("No valid metadata file path.")
4748
raise FileNotFoundError("No valid metadata file path.")

0 commit comments

Comments
 (0)