index.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. from flask import Flask, request,render_template, send_from_directory
  2. from healthcareio.params import SYS_ARGS
  3. import healthcareio.analytics
  4. import os
  5. import json
  6. app = Flask(__name__)
  7. @app.route("/favicon.ico")
  8. def _icon():
  9. return send_from_directory(os.path.join([app.root_path, 'static','img','logo.svg']),
  10. 'favicon.ico', mimetype='image/vnd.microsoft.icon')
  11. @app.route("/")
  12. def init():
  13. e = SYS_ARGS['engine']
  14. sections = {"remits":e.info['835'],"claims":e.info['837']}
  15. _args = {"sections":sections,"store":SYS_ARGS['config']['store']}
  16. print (SYS_ARGS['config']['store'])
  17. return render_template("setup.html",**_args)
  18. @app.route("/format/<id>/<index>",methods=['POST'])
  19. def _format(id,index):
  20. e = SYS_ARGS['engine']
  21. key = '837' if id == 'claims' else '835'
  22. index = int(index)
  23. # p = e.info[key][index]
  24. p = e.apply(type=id,index=index)
  25. #
  26. r = []
  27. for item in p[0]['pipeline'] :
  28. _item= dict(item)
  29. del _item['sql']
  30. del _item ['data']
  31. _item = dict(_item,**healthcareio.analytics.Apex.apply(item))
  32. if 'apex' in _item or 'html' in _item:
  33. r.append(_item)
  34. r = {"id":p[0]['id'],"pipeline":r}
  35. return json.dumps(r),200
  36. @app.route("/get/<id>/<index>",methods=['GET'])
  37. def get(id,index):
  38. e = SYS_ARGS['engine']
  39. key = '837' if id == 'claims' else '835'
  40. index = int(index)
  41. # p = e.info[key][index]
  42. p = e.apply(type=id,index=index)
  43. r = {}
  44. for item in p[0]['pipeline'] :
  45. _item= [dict(item)]
  46. r[item['label']] = item['data'].to_dict(orient='record')
  47. # del _item['sql']
  48. # del _item ['data']
  49. # print (item['label'])
  50. # _item['apex'] = healthcareio.analytics.Apex.apply(item)
  51. # if _item['apex']:
  52. # r.append(_item)
  53. # r = {"id":p[0]['id'],"pipeline":r}
  54. return json.dumps(r),200
  55. @app.route("/reload",methods=['POST'])
  56. def reload():
  57. # e = SYS_ARGS['engine']
  58. # e.apply()
  59. PATH= SYS_ARGS['config'] if 'config' in SYS_ARGS else os.sep.join([os.environ['HOME'],'.healthcareio','config.json'])
  60. e = healthcareio.analytics.engine(PATH)
  61. # e.apply()
  62. SYS_ARGS['engine'] = e
  63. return "1",200
  64. if __name__ == '__main__' :
  65. PORT = int(SYS_ARGS['port']) if 'port' in SYS_ARGS else 5500
  66. DEBUG= int(SYS_ARGS['debug']) if 'debug' in SYS_ARGS else 0
  67. SYS_ARGS['context'] = SYS_ARGS['context'] if 'context' in SYS_ARGS else ''
  68. #
  69. #
  70. PATH= SYS_ARGS['config'] if 'config' in SYS_ARGS else os.sep.join([os.environ['HOME'],'.healthcareio','config.json'])
  71. e = healthcareio.analytics.engine(PATH)
  72. # e.apply(type='claims',serialize=True)
  73. SYS_ARGS['engine'] = e
  74. app.run(host='0.0.0.0',port=PORT,debug=DEBUG,threaded=True)