@ -19,6 +19,7 @@
"""
"""
import os
import os
import sys
import sys
import json
def split ( row , sep = ' * ' , prefix = ' HI ' ) :
def split ( row , sep = ' * ' , prefix = ' HI ' ) :
"""
"""
This function is designed to split an x12 row and
This function is designed to split an x12 row and
@ -32,8 +33,11 @@ def split(row,sep='*',prefix='HI'):
value + = row_value . split ( ' > ' ) [ : 2 ]
value + = row_value . split ( ' > ' ) [ : 2 ]
else :
else :
value + = row_value . split ( ' > ' )
value + = row_value . split ( ' > ' ) if row . startswith ( ' CLM ' ) is False else [ row_value ]
else :
else :
value . append ( row_value )
value . append ( row_value )
return [ xchar . replace ( ' \r ' , ' ' ) for xchar in value ] #row.replace('~','').split(sep)
return [ xchar . replace ( ' \r ' , ' ' ) for xchar in value ] #row.replace('~','').split(sep)
else :
else :
@ -88,6 +92,13 @@ def format_proc(value):
def format_diag ( value ) :
def format_diag ( value ) :
return [ { " code " : item [ 2 ] , " type " : item [ 1 ] } for item in value if len ( item ) > 1 ]
return [ { " code " : item [ 2 ] , " type " : item [ 1 ] } for item in value if len ( item ) > 1 ]
def format_pos ( value ) :
xchar = ' > ' if ' > ' in value else ' : '
x = value . split ( xchar )
x = { " code " : x [ 0 ] , " indicator " : x [ 1 ] , " frequency " : x [ 2 ] } if len ( x ) == 3 else { " code " : x [ 0 ] , " indicator " : None , " frequency " : None }
return x
def get_map ( row , config , version ) :
def get_map ( row , config , version ) :
label = config [ ' label ' ] if ' label ' in config else None
label = config [ ' label ' ] if ' label ' in config else None
@ -108,12 +119,20 @@ def get_map(row,config,version):
value = row [ index ]
value = row [ index ]
if ' cast ' in config and key in config [ ' cast ' ] and value . strip ( ) != ' ' :
if ' cast ' in config and key in config [ ' cast ' ] and value . strip ( ) != ' ' :
value = eval ( config [ ' cast ' ] [ key ] ) ( value )
value = eval ( config [ ' cast ' ] [ key ] ) ( value )
pass
if ' syn ' in config and value in config [ ' syn ' ] :
value = config [ ' syn ' ] [ value ]
if type ( value ) == dict :
if type ( value ) == dict :
for objkey in value :
if ' syn ' in config and value [ objkey ] in config [ ' syn ' ] :
value [ objkey ] = config [ ' syn ' ] [ value [ objkey ] ]
value = { key : value }
else :
if ' syn ' in config and value in config [ ' syn ' ] :
value = config [ ' syn ' ] [ value ]
if type ( value ) == dict :
object_value = dict ( object_value , * * value )
object_value = dict ( object_value , * * value )
else :
else :
object_value [ key ] = value
object_value [ key ] = value