Commit 88a02ed2 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: Separate out description generation, use column metadata if present. Fix

to icd10DescriptionFromCode
parent a46df4a2
......@@ -420,22 +420,42 @@ def doDescriptionExport(dtable, args):
with util.timed('Description export', log):
cols = dtable.allColumns[1:]
vartable = dtable.vartable
try:
with open(args.description_file, 'wt') as f:
for c in cols:
for col in cols:
desc = generateDescription(dtable, col)
f.write('{}\t{}\n'.format(col.name, desc))
except Exception as e:
log.warning('Failed to export descriptions: {}'.format(e),
exc_info=True)
def generateDescription(dtable, col):
"""Called by :func:`doDescriptionExport`. Generates and returns a
suitable description for the given column.
desc = vartable.loc[c.vid, 'Description']
:arg dtable: :class:`.Datatable` instance
:arg col: :class:`.Column` instance
"""
vartable = dtable.vartable
desc = vartable.loc[col.vid, 'Description']
if desc == c.name:
if desc == col.name:
desc = 'n/a'
f.write('{}\t{}\n'.format(c.name, desc))
# If metadata has been added to the column,
# we add it to the description. See the
# binariseCategorical processing function
# for an example of this.
if col.metadata is not None:
suffix = ' ({})'.format(col.metadata)
else:
suffix = ' ({}.{})'.format(col.visit, col.instance)
return '{}{}'.format(desc, suffix)
except Exception as e:
log.warning('Failed to export descriptions: {}'.format(e),
exc_info=True)
def configLogging(args):
......
......@@ -367,7 +367,6 @@ def icd10DescriptionFromNumeric(val):
@custom.metaproc('icd10.codedesc')
def icd10DescriptionFromCode(val):
"""Generates a description for an ICD10 code. """
val = icd10.codeToNumeric(val)
hier = hierarchy.getHierarchyFilePath(name='icd10')
hier = hierarchy.loadHierarchyFile(hier)
desc = hier.description(val)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment