@@ -86,10 +86,6 @@ def to_camel_case(name):
86
86
return lower_dot_case_name
87
87
88
88
89
- def codify (str ):
90
- return re .sub (r"[^a-zA-Z0-9]+" , "" , str )
91
-
92
-
93
89
def validate_fields (fields , valid_fields , label ):
94
90
invalid_fields = list (set (fields ).difference (valid_fields ))
95
91
if len (invalid_fields ) > 0 :
@@ -186,7 +182,7 @@ def resolve_values(parent, _info):
186
182
"resolve_values" : resolve_values ,
187
183
}
188
184
for wg_type in registry .working_group_types .all ():
189
- field_name = get_schema_field_name (codify ( wg_type .name ) )
185
+ field_name = get_schema_field_name (wg_type .name )
190
186
wg_type_fields .update (
191
187
{
192
188
field_name : graphene .Field (DataSummaryItemSummaryType ),
@@ -422,14 +418,20 @@ def resolve_last_updated(parent, _info):
422
418
return datetime .fromisoformat (form_timestamp )
423
419
424
420
425
- def get_schema_field_name (s ):
426
- if not _graphql_field_pattern .match (s ):
427
- new_str = f"field{ s } "
428
- assert _graphql_field_pattern .match (new_str ), (
429
- f"Cannot use field '{ s } ' in graphql schema"
430
- )
431
- return new_str
432
- return s
421
+ def get_schema_field_name (raw ):
422
+ def _codify (name ):
423
+ return re .sub (r"[^a-zA-Z0-9]+" , "" , name )
424
+
425
+ def _safe_field_name (name ):
426
+ if not _graphql_field_pattern .match (name ):
427
+ new_str = f"field{ name } "
428
+ assert _graphql_field_pattern .match (
429
+ new_str
430
+ ), f"Cannot use field '{ name } ' in graphql schema"
431
+ return new_str
432
+ return name
433
+
434
+ return _safe_field_name (_codify (to_camel_case (raw )))
433
435
434
436
435
437
def get_section_fields (_section_key , section_cdes ):
@@ -496,9 +498,9 @@ def get_cfg_forms(cfg_key, cfg_model):
496
498
497
499
def form_resolver (parent , _info , form_model ):
498
500
_patient , _contexts , clinical_data = parent
499
- assert len ( clinical_data ) <= 1 , (
500
- "Too many clinical data records to resolve form"
501
- )
501
+ assert (
502
+ len ( clinical_data ) <= 1
503
+ ), "Too many clinical data records to resolve form"
502
504
503
505
if len (clinical_data ) == 0 :
504
506
return None
@@ -744,7 +746,7 @@ def working_groups_resolver(parent, _info, working_group_type):
744
746
745
747
fields = {}
746
748
for working_group_type in registry .working_group_types .all ():
747
- field_name = get_schema_field_name (codify ( working_group_type .name ) )
749
+ field_name = get_schema_field_name (working_group_type .name )
748
750
fields [field_name ] = graphene .List (WorkingGroupSchemaType )
749
751
fields [f"resolve_{ field_name } " ] = partial (
750
752
working_groups_resolver , working_group_type = working_group_type
0 commit comments