Skip to content

A checkbox with no enumerated values results in an error #94

Description

@gaurav

Attempting to translate a REDCap CSV file with a checkbox field without any enumerated values results in a mysterious looking error:

Traceback (most recent call last):
  File "/Users/gaurav/Developer/heal/heal-data-dictionaries/venv/bin/vlmd", line 8, in <module>
    sys.exit(vlmd())
             ^^^^^^
  File "/Users/gaurav/Developer/heal/heal-data-dictionaries/venv/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gaurav/Developer/heal/heal-data-dictionaries/venv/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/gaurav/Developer/heal/heal-data-dictionaries/venv/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gaurav/Developer/heal/heal-data-dictionaries/venv/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gaurav/Developer/heal/heal-data-dictionaries/venv/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gaurav/Developer/heal/heal-data-dictionaries/venv/lib/python3.12/site-packages/healdata_utils/cli.py", line 205, in extract
    data_dictionaries = convert_to_vlmd(
                        ^^^^^^^^^^^^^^^^
  File "/Users/gaurav/Developer/heal/heal-data-dictionaries/venv/lib/python3.12/site-packages/healdata_utils/conversion.py", line 268, in convert_to_vlmd
    data_dictionary_package = choice_fxn[inputtype](
                              ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gaurav/Developer/heal/heal-data-dictionaries/venv/lib/python3.12/site-packages/healdata_utils/transforms/redcapcsv/conversion.py", line 139, in convert_redcapcsv
    targetfields = gather(sourcefields)
                   ^^^^^^^^^^^^^^^^^^^^
  File "/Users/gaurav/Developer/heal/heal-data-dictionaries/venv/lib/python3.12/site-packages/healdata_utils/transforms/redcapcsv/conversion.py", line 91, in gather
    targetfield = typemappings[sourcefieldtype](sourcefield)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gaurav/Developer/heal/heal-data-dictionaries/venv/lib/python3.12/site-packages/healdata_utils/transforms/redcapcsv/mappings.py", line 216, in mapcheckbox
    for val,choice in choices.items()
                      ^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'items'

This should be improved to indicate why the error occurred (but there are no enumerated values for this field), but it may also be a good idea to allow this -- otherwise, we have to add a fake value (e.g. NA, NA) so that the file can be transformed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions