__main__.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. """
  2. (c) 2019 EDI Parser 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 x12parser <action>
  11. action:
  12. - parser
  13. - create.plugin
  14. - register.plugin
  15. -
  16. Embedded :
  17. """
  18. # import healthcareio
  19. import typer
  20. from typing import Optional
  21. from typing_extensions import Annotated
  22. import uuid
  23. import os
  24. import version
  25. import json
  26. import time
  27. from healthcareio import x12
  28. from healthcareio.x12.parser import X12Parser
  29. # import healthcareio
  30. # import healthcareio.x12.util
  31. # from healthcareio.x12.parser import X12Parser
  32. app = typer.Typer()
  33. CONFIG_FOLDER = os.sep.join([os.environ['HOME'],'.healthcareio'])
  34. @app.command(name='init')
  35. def config(email:str,provider:str='sqlite') :
  36. """
  37. Generate configuration file needed with default data store. For supported data-store providers visit https://hiplab.mc.vanderbilt.edu/git/hiplab/data-transport.git
  38. :email your email
  39. \r:provider data store provider (visit https://hiplab.mc.vanderbilt.edu/git/hiplab/data-transport.git)
  40. """
  41. _db = "healthcareio"
  42. # _PATH = os.sep.join([os.environ['HOME'],'.healthcareio'])
  43. if not os.path.exists(CONFIG_FOLDER) :
  44. os.mkdir(CONFIG_FOLDER)
  45. if provider in ['sqlite','sqlite3'] :
  46. _db = os.sep.join([CONFIG_FOLDER,_db+'.db3'])
  47. _config = {
  48. "store":{
  49. "provider":provider,"database":_db,"context":"write"
  50. },
  51. "plugins":None,
  52. "system":{
  53. "uid":str(uuid.uuid4()),
  54. "email":email,
  55. "version":version.__version__,
  56. "copyright":version.__author__
  57. }
  58. }
  59. #
  60. # store this on disk
  61. f = open(os.sep.join([CONFIG_FOLDER,'config.json']),'w')
  62. f.write(json.dumps(_config))
  63. f.close()
  64. @app.command(name='about')
  65. def copyright():
  66. for note in [version.__name__,version.__author__,version.__license__]:
  67. print (note)
  68. pass
  69. @app.command()
  70. def parse (claim_folder:str,plugin_folder:str = None,config_path:str = None):
  71. """
  72. This function will parse 837 and or 835 claims given a location of parsing given claim folder and/or plugin folder
  73. """
  74. _plugins,_parents = x12.plugins.instance(path=plugin_folder)
  75. _files = x12.util.file.Location.get(path=claim_folder,chunks=10)
  76. _path = config_path if config_path else os.sep.join([CONFIG_FOLDER,'config.json'])
  77. if os.path.exists(_path) :
  78. f = open(_path)
  79. _config = json.loads(f.read())
  80. f.close()
  81. _store = _config['store']
  82. # print (len(_files))
  83. jobs = []
  84. for _chunks in _files:
  85. pthread = X12Parser(plugins=_plugins,parents=_parents,files=_chunks, store=_store)
  86. pthread.start()
  87. jobs.append(pthread)
  88. while jobs :
  89. jobs = [pthread for pthread in jobs if pthread.is_alive()]
  90. time.sleep(1)
  91. pass
  92. else:
  93. pass
  94. #
  95. #
  96. if __name__ == '__main__' :
  97. app()