@@ -140,34 +140,38 @@ def get_criteria(self, type: str = None) -> List[dict]:
140140 return all_criteria
141141
142142 def check_criterion_exists (self , criterion , return_ind :bool = False ):
143- criterion_exist = False
144- criterion_ind = None
145- for ind , crit in enumerate (self .clinical_criteria_dict ['criteria' ]):
146- if (crit ['type' ] == criterion ['type' ]) and crit ['parameters' ] == criterion ['parameters' ]:
147- for constraint in crit ['constraints' ]:
148- if constraint == criterion ['constraints' ]:
149- criterion_exist = True
150- criterion_ind = ind
151- if return_ind :
152- return criterion_exist ,criterion_ind
153- else :
154- return criterion_exist
143+ criterion_exist = False
144+ criterion_ind = None
145+ for ind , crit in enumerate (self .clinical_criteria_dict ['criteria' ]):
146+ if (crit ['type' ] == criterion ['type' ]) and crit ['parameters' ] == criterion ['parameters' ]:
147+ for constraint in crit ['constraints' ]:
148+ for key , _ in criterion ['constraints' ].items ():
149+ if constraint == key :
150+ criterion_exist = True
151+ criterion_ind = ind
152+ if return_ind :
153+ return criterion_exist ,criterion_ind
154+ else :
155+ return criterion_exist
155156
156157 def modify_criterion (self , criterion ):
157158 """
158- Modify the criterion the clinical criteria
159-
160-
159+ Update constraints for an existing criterion.
160+ Only updates keys that already exist in the original constraint dict.
161161 """
162- criterion_found = False
163162 for ind , crit in enumerate (self .clinical_criteria_dict ['criteria' ]):
164- if (crit ['type' ] == criterion ['type' ]) and crit ['parameters' ] == criterion ['parameters' ]:
165- for constraint in crit ['constraints' ]:
166- if constraint == criterion ['constraints' ]:
167- self .clinical_criteria_dict ['criteria' ][ind ]['constraints' ][constraint ] = criterion ['constraints' ]
168- criterion_found = True
169- if not criterion_found :
170- raise Warning ('No criteria for {}' .format (criterion ))
163+
164+ if crit ['type' ] == criterion ['type' ] and crit ['parameters' ] == criterion ['parameters' ]:
165+ existing_keys = crit ['constraints' ]
166+ updated = False
167+ for key , value in criterion .get ('constraints' , {}).items ():
168+ if key in existing_keys :
169+ existing_keys [key ] = value
170+ updated = True
171+ if updated :
172+ return
173+
174+ raise Warning (f"No criteria found for { criterion } " )
171175
172176
173177 def get_num (self , string : Union [str , float ]):
0 commit comments