Skip to content

Commit

Permalink
[FIX] debugging redcap2reproschema during converting HBCD (#61)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
yibeichan and pre-commit-ci[bot] authored Jul 18, 2024
1 parent 0420e18 commit 10749c4
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions reproschema/redcap2reproschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
"date_mdy": "xsd:date", # ?? new one TODO: not sure what to do with it, it's not xsd:date
"datetime_seconds_mdy": "xsd:date", # ?? new one TODO: not sure what to do with it, it's not xsd:date
"date_ymd": "xsd:date", # new one
"date_dmy": "xsd:date",
"datetime_": "xsd:dateTime",
"datetime_ymd": "xsd:dateTime",
"time_": "xsd:time",
"email": "xsd:string",
"phone": "xsd:string",
Expand Down Expand Up @@ -200,25 +202,31 @@ def process_choices(choices_str, field_name):
choices_value_type = []
for ii, choice in enumerate(choices_str.split("|")):
parts = choice.split(", ")
if len(parts) < 2:
print(
f"Warning: Invalid choice format '{choice}' in a {field_name} field, adding integer as a value"
)
# TODO! I'm adding int by default, but there is probably some legend in the csv and this is not yet implemented
parts = [ii, parts[0]]

# Handle the case where the choice is something like "1,"
if len(parts) == 1:
if choice.endswith(","):
parts = [parts[0][:-1], ""]
else:
print(
f"Warning: Invalid choice format '{choice}' in a {field_name} field, adding integer as a value"
)
parts = [ii, parts[0]]

# Try to convert the first part to an integer, if it fails, keep it as a string
try:
value = int(parts[0])
choices_value_type.append("xsd:integer")
except ValueError:
value = parts[0]
choices_value_type.append("xsd:string")
choice_obj = {"name": {"en": " ".join(parts[1:])}, "value": value}
# remove image for now
# if len(parts) == 3:
# # Handle image url
# choice_obj["image"] = f"{parts[2]}.png"

choice_obj = {
"name": {"en": " ".join(parts[1:]).strip()},
"value": value,
}
choices.append(choice_obj)

return choices, list(set(choices_value_type))


Expand Down

0 comments on commit 10749c4

Please sign in to comment.