Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
ukbparse
Commits
88a02ed2
Commit
88a02ed2
authored
May 09, 2019
by
Paul McCarthy
🚵
Browse files
RF: Separate out description generation, use column metadata if present. Fix
to icd10DescriptionFromCode
parent
a46df4a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
ukbparse/main.py
View file @
88a02ed2
...
...
@@ -419,25 +419,45 @@ def doDescriptionExport(dtable, args):
return
with
util
.
timed
(
'Description export'
,
log
):
cols
=
dtable
.
allColumns
[
1
:]
vartable
=
dtable
.
vartable
cols
=
dtable
.
allColumns
[
1
:]
try
:
with
open
(
args
.
description_file
,
'wt'
)
as
f
:
for
c
in
cols
:
desc
=
vartable
.
loc
[
c
.
vid
,
'Description'
]
if
desc
==
c
.
name
:
desc
=
'n/a'
f
.
write
(
'{}
\t
{}
\n
'
.
format
(
c
.
name
,
desc
))
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.
: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
):
"""Configures ``ukbparse`` logging.
...
...
ukbparse/processing.py
View file @
88a02ed2
...
...
@@ -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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment