__main__.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. """
  2. (c) 2019 Claims Toolkit,
  3. Health Information Privacy Lab, Vanderbilt University Medical Center
  4. Steve L. Nyemba <steve.l.nyemba@vanderbilt.edu>
  5. Khanhly Nguyen <khanhly.t.nguyen@gmail.com>
  6. This code is intended to process and parse healthcare x12 837 (claims) and x12 835 (remittances) into human readable JSON format.
  7. The claims/outpout can be forwarded to a NoSQL Data store like couchdb and mongodb
  8. Usage :
  9. Commandline :
  10. python edi --scope --config <path> --folder <path> --store <[mongo|disk|couch]> --<db|path]> <id|path>
  11. with :
  12. --scope <claims|remits>
  13. --config path of the x12 to be parsed i.e it could be 835, or 837
  14. --folder location of the files (they must be decompressed)
  15. --store data store could be disk, mongodb, couchdb
  16. --db|path name of the folder to store the output or the database name
  17. Embedded in Code :
  18. import edi.parser
  19. import json
  20. file = '/data/claim_1.x12'
  21. conf = json.loads(open('config/837.json').read())
  22. edi.parser.get_content(filename,conf)
  23. """
  24. from params import SYS_ARGS
  25. from transport import factory
  26. from parser import *
  27. import os
  28. import json
  29. import sys
  30. if __name__ == '__main__' :
  31. """
  32. The program was called from the command line thus we are expecting
  33. parse in [claims,remits]
  34. config os.sep.path.exists(path)
  35. folder os.sep.path.exists(path)
  36. store store ()
  37. """
  38. p = len( set(['store','config','folder']) & set(SYS_ARGS.keys())) == 3 and ('db' in SYS_ARGS or 'path' in SYS_ARGS)
  39. TYPE = {
  40. 'mongo':'mongo.MongoWriter',
  41. 'couch':'couch.CouchWriter',
  42. 'disk':'disk.DiskWriter'
  43. }
  44. INFO = {
  45. '837':{'scope':'claims','section':'HL'},
  46. '835':{'scope':'remits','section':'CLP'}
  47. }
  48. if p :
  49. args = {}
  50. scope = SYS_ARGS['config'][:-5].split(os.sep)[-1]
  51. CONTEXT = INFO[scope]['scope']
  52. #
  53. # @NOTE:
  54. # improve how database and data stores are handled.
  55. if SYS_ARGS['store'] == 'couch' :
  56. args = {'url': SYS_ARGS['url'] if 'url' in SYS_ARGS else 'http://localhost:5984'}
  57. args['dbname'] = SYS_ARGS['db']
  58. elif SYS_ARGS ['store'] == 'mongo':
  59. args = {'host':SYS_ARGS['host']if 'host' in SYS_ARGS else 'localhost:27017'}
  60. if SYS_ARGS['store'] in ['mongo','couch']:
  61. args['dbname'] = SYS_ARGS['db'] if 'db' in SYS_ARGS else 'claims_outcomes'
  62. args['doc'] = CONTEXT
  63. TYPE = TYPE[SYS_ARGS['store']]
  64. writer = factory.instance(type=TYPE,args=args)
  65. if SYS_ARGS['store'] == 'disk':
  66. writer.init(path = 'output-claims.json')
  67. logger = factory.instance(type=TYPE,args= dict(args,**{"doc":"logs"}))
  68. files = os.listdir(SYS_ARGS['folder'])
  69. CONFIG = json.loads(open(SYS_ARGS['config']).read())
  70. SECTION= INFO[scope]['section']
  71. for file in files :
  72. if 'limit' in SYS_ARGS and files.index(file) == int(SYS_ARGS['limit']) :
  73. break
  74. else:
  75. filename = os.sep.join([SYS_ARGS['folder'],file])
  76. try:
  77. content,logs = get_content(filename,CONFIG,SECTION)
  78. except Exception as e:
  79. if sys.version_info[0] > 2 :
  80. logs = [{"filename":filename,"msg":e.args[0]}]
  81. else:
  82. logs = [{"filename":filename,"msg":e.message}]
  83. content = None
  84. if content :
  85. writer.write(content)
  86. if logs:
  87. logger.write(logs)
  88. pass
  89. else:
  90. print (__doc__)