44import numpy as np
55import os
66import pandas as pd
7- import resource
87from typing import Any , Dict , Optional , Text , List
98
109from schematic .schemas import SchemaGenerator
1110from schematic .utils .io_utils import load_json
12- from schematic import CONFIG
1311
1412logger = logging .getLogger (__name__ )
1513
@@ -114,7 +112,16 @@ def parse_attributes(self, save_file=True):
114112 # Capitalize attribute if it begins with a lowercase letter, for aesthetics.
115113 if attribute [0 ].islower ():
116114 attribute = attribute .capitalize ()
117- conditional_statement = f'{ attribute } -is- "{ value [0 ]} "'
115+
116+ # Remove "Type" (i.e. turn "Biospecimen Type" to "Biospcimen")
117+ if "Type" in attribute :
118+ attribute = attribute .split (" " )[0 ]
119+
120+ # Remove "Type" (i.e. turn "Tissue Type" to "Tissue")
121+ if "Type" in value [0 ]:
122+ value [0 ] = value [0 ].split (" " )[0 ]
123+
124+ conditional_statement = f'{ attribute } is "{ value [0 ]} "'
118125 if conditional_statement not in data_dict [key ]['Conditional Requirements' ]:
119126 data_dict [key ]['Cond_Req' ] = True
120127 data_dict [key ]['Conditional Requirements' ].extend ([conditional_statement ])
@@ -123,9 +130,23 @@ def parse_attributes(self, save_file=True):
123130 f"There is an error getting conditional requirements related "
124131 "to the attribute: {key}. The error is likely caused by naming inconsistencies (e.g. uppercase, camelcase, ...)"
125132 )
133+
126134 for key , value in data_dict .items ():
127135 if 'Conditional Requirements' in value .keys ():
128- data_dict [key ]['Conditional Requirements' ] = ' || ' .join (data_dict [key ]['Conditional Requirements' ])
136+
137+ ## reformat conditional requirement
138+
139+ # get all attributes
140+ attr_lst = [i .split (" is " )[- 1 ] for i in data_dict [key ]['Conditional Requirements' ]]
141+
142+ # join a list of attributes by using OR
143+ attr_str = " OR " .join (attr_lst )
144+
145+ # reformat the conditional requirement
146+ component_name = data_dict [key ]['Conditional Requirements' ][0 ].split (' is ' )[0 ]
147+ conditional_statement_str = f" If { component_name } is { attr_str } then { key } is required"
148+
149+ data_dict [key ]['Conditional Requirements' ] = conditional_statement_str
129150 df = pd .DataFrame (data_dict )
130151 df = df .T
131152 cols = ['Attribute' , 'Label' , 'Description' , 'Required' , 'Cond_Req' , 'Valid Values' , 'Conditional Requirements' , 'Validation Rules' , 'Component' ]
0 commit comments