Skip to content

Commit 10749c4

Browse files
[FIX] debugging redcap2reproschema during converting HBCD (ReproNim#61)
* add data_dmy as xsd:date * ignore .DS_Store for validation * add datetime_ymd for mapping * fix response option for completion such as 1, * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 0420e18 commit 10749c4

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

reproschema/redcap2reproschema.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@
5353
"date_mdy": "xsd:date", # ?? new one TODO: not sure what to do with it, it's not xsd:date
5454
"datetime_seconds_mdy": "xsd:date", # ?? new one TODO: not sure what to do with it, it's not xsd:date
5555
"date_ymd": "xsd:date", # new one
56+
"date_dmy": "xsd:date",
5657
"datetime_": "xsd:dateTime",
58+
"datetime_ymd": "xsd:dateTime",
5759
"time_": "xsd:time",
5860
"email": "xsd:string",
5961
"phone": "xsd:string",
@@ -200,25 +202,31 @@ def process_choices(choices_str, field_name):
200202
choices_value_type = []
201203
for ii, choice in enumerate(choices_str.split("|")):
202204
parts = choice.split(", ")
203-
if len(parts) < 2:
204-
print(
205-
f"Warning: Invalid choice format '{choice}' in a {field_name} field, adding integer as a value"
206-
)
207-
# TODO! I'm adding int by default, but there is probably some legend in the csv and this is not yet implemented
208-
parts = [ii, parts[0]]
205+
206+
# Handle the case where the choice is something like "1,"
207+
if len(parts) == 1:
208+
if choice.endswith(","):
209+
parts = [parts[0][:-1], ""]
210+
else:
211+
print(
212+
f"Warning: Invalid choice format '{choice}' in a {field_name} field, adding integer as a value"
213+
)
214+
parts = [ii, parts[0]]
215+
209216
# Try to convert the first part to an integer, if it fails, keep it as a string
210217
try:
211218
value = int(parts[0])
212219
choices_value_type.append("xsd:integer")
213220
except ValueError:
214221
value = parts[0]
215222
choices_value_type.append("xsd:string")
216-
choice_obj = {"name": {"en": " ".join(parts[1:])}, "value": value}
217-
# remove image for now
218-
# if len(parts) == 3:
219-
# # Handle image url
220-
# choice_obj["image"] = f"{parts[2]}.png"
223+
224+
choice_obj = {
225+
"name": {"en": " ".join(parts[1:]).strip()},
226+
"value": value,
227+
}
221228
choices.append(choice_obj)
229+
222230
return choices, list(set(choices_value_type))
223231

224232

0 commit comments

Comments
 (0)