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
...@@ -419,25 +419,45 @@ def doDescriptionExport(dtable, args): ...@@ -419,25 +419,45 @@ def doDescriptionExport(dtable, args):
return return
with util.timed('Description export', log): with util.timed('Description export', log):
cols = dtable.allColumns[1:] cols = dtable.allColumns[1:]
vartable = dtable.vartable
try: try:
with open(args.description_file, 'wt') as f: with open(args.description_file, 'wt') as f:
for c in cols: for col in cols:
desc = generateDescription(dtable, col)
desc = vartable.loc[c.vid, 'Description'] f.write('{}\t{}\n'.format(col.name, desc))
if desc == c.name:
desc = 'n/a'
f.write('{}\t{}\n'.format(c.name, desc))
except Exception as e: except Exception as e:
log.warning('Failed to export descriptions: {}'.format(e), log.warning('Failed to export descriptions: {}'.format(e),
exc_info=True) exc_info=True)
def generateDescription(dtable, col):
"""Called by :func:`doDescriptionExport`. Generates and returns a
suitable description for the given column.
:arg dtable: :class:`.Datatable` instance
:arg col: :class:`.Column` instance
"""
vartable = dtable.vartable
desc = vartable.loc[col.vid, 'Description']
if desc == col.name:
desc = 'n/a'
# 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)
def configLogging(args): def configLogging(args):
"""Configures ``ukbparse`` logging. """Configures ``ukbparse`` logging.
......
...@@ -367,7 +367,6 @@ def icd10DescriptionFromNumeric(val): ...@@ -367,7 +367,6 @@ def icd10DescriptionFromNumeric(val):
@custom.metaproc('icd10.codedesc') @custom.metaproc('icd10.codedesc')
def icd10DescriptionFromCode(val): def icd10DescriptionFromCode(val):
"""Generates a description for an ICD10 code. """ """Generates a description for an ICD10 code. """
val = icd10.codeToNumeric(val)
hier = hierarchy.getHierarchyFilePath(name='icd10') hier = hierarchy.getHierarchyFilePath(name='icd10')
hier = hierarchy.loadHierarchyFile(hier) hier = hierarchy.loadHierarchyFile(hier)
desc = hier.description(val) 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