2020 REDCAP_COLUMN_REQUIRED ,
2121 RESPONSE_COND ,
2222 VALUE_TYPE_MAP ,
23+ get_value_type ,
2324)
2425
25-
2626def process_input_value_types (input_type_rc , value_type_rc ) -> (str , str ):
2727 """
2828 Process input type and value type to determine the final input type and value type,
@@ -47,40 +47,36 @@ def process_input_value_types(input_type_rc, value_type_rc) -> (str, str):
4747 input_type = INPUT_TYPE_MAP .get (input_type_rc )
4848
4949 if value_type_rc :
50- if value_type_rc not in VALUE_TYPE_MAP :
51- raise ValueError (
52- f"Validation type '{ value_type_rc } ' is not supported, "
53- f"supported types are: { ', ' .join (VALUE_TYPE_MAP .keys ())} "
54- )
55-
56- value_type = VALUE_TYPE_MAP [value_type_rc ]
50+ # Get value type using the new function
51+ value_type = get_value_type (value_type_rc )
5752
5853 # Adjust input type based on validation
59- if value_type_rc == "integer" and input_type_rc == "text" :
54+ if value_type_rc .startswith ("date" ) or value_type_rc .startswith ("datetime" ):
55+ if input_type_rc == "text" :
56+ input_type = "date"
57+ elif value_type_rc .startswith ("time" ):
58+ if input_type_rc == "text" :
59+ input_type = "time"
60+ elif value_type_rc == "integer" and input_type_rc == "text" :
6061 input_type = "number"
6162 elif value_type_rc in ["float" , "number" ] and input_type_rc == "text" :
6263 input_type = "float"
63- elif (
64- value_type_rc == "email" and input_type_rc == "text"
65- ): # todo: what if input type is not text
64+ elif value_type_rc == "email" and input_type_rc == "text" :
6665 input_type = "email"
6766 elif value_type_rc == "signature" and input_type_rc == "text" :
6867 input_type = "sign"
69- elif (
70- value_type == "xsd:date" and input_type_rc == "text"
71- ): # anything that maps to date in RS #todo: what about time?
72- input_type = "date"
7368
7469 elif input_type_rc == "yesno" :
7570 value_type = "xsd:boolean"
71+ elif input_type_rc == "truefalse" :
72+ value_type = "xsd:boolean"
7673 elif input_type_rc in COMPUTE_LIST :
7774 value_type = "xsd:integer"
7875 else : # if no validation type is set, default to string
7976 value_type = "xsd:string"
8077
8178 return input_type , value_type
8279
83-
8480def process_response_options (row , input_type_rc , value_type ) -> Dict [str , Any ]:
8581 """
8682 Process response options from the row and return a dictionary of response options
@@ -102,6 +98,11 @@ def process_response_options(row, input_type_rc, value_type) -> Dict[str, Any]:
10298 {"name" : {"en" : "Yes" }, "value" : 1 },
10399 {"name" : {"en" : "No" }, "value" : 0 },
104100 ]
101+ elif input_type_rc == "truefalse" :
102+ response_options ["choices" ] = [
103+ {"name" : {"en" : "True" }, "value" : 1 },
104+ {"name" : {"en" : "False" }, "value" : 0 },
105+ ]
105106 elif input_type_rc == "checkbox" :
106107 response_options ["multipleChoice" ] = True
107108
@@ -418,7 +419,7 @@ def process_row(
418419def process_csv (csv_file ) -> (Dict [str , Any ], list ):
419420
420421 df = pd .read_csv (
421- csv_file , encoding = "utf-8-sig"
422+ csv_file , encoding = "utf-8-sig" , low_memory = False
422423 ) # utf-8-sig handles BOM automatically
423424
424425 df .columns = df .columns .map (
0 commit comments