index.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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'],'args':{'batch':5}}
  16. return render_template("index.html",**_args)
  17. @app.route("/format/<id>/<index>",methods=['POST'])
  18. def _format(id,index):
  19. e = SYS_ARGS['engine']
  20. key = '837' if id == 'claims' else '835'
  21. index = int(index)
  22. # p = e.info[key][index]
  23. p = e.apply(type=id,index=index)
  24. #
  25. r = []
  26. for item in p[0]['pipeline'] :
  27. _item= dict(item)
  28. del _item['sql']
  29. del _item ['data']
  30. _item = dict(_item,**healthcareio.analytics.Apex.apply(item))
  31. if 'apex' in _item or 'html' in _item:
  32. r.append(_item)
  33. r = {"id":p[0]['id'],"pipeline":r}
  34. return json.dumps(r),200
  35. @app.route("/get/<id>/<index>",methods=['GET'])
  36. def get(id,index):
  37. e = SYS_ARGS['engine']
  38. key = '837' if id == 'claims' else '835'
  39. index = int(index)
  40. # p = e.info[key][index]
  41. p = e.apply(type=id,index=index)
  42. r = {}
  43. for item in p[0]['pipeline'] :
  44. _item= [dict(item)]
  45. r[item['label']] = item['data'].to_dict(orient='record')
  46. # del _item['sql']
  47. # del _item ['data']
  48. # print (item['label'])
  49. # _item['apex'] = healthcareio.analytics.Apex.apply(item)
  50. # if _item['apex']:
  51. # r.append(_item)
  52. # r = {"id":p[0]['id'],"pipeline":r}
  53. return json.dumps(r),200
  54. @app.route("/reload",methods=['POST'])
  55. def reload():
  56. # e = SYS_ARGS['engine']
  57. # e.apply()
  58. PATH= SYS_ARGS['config'] if 'config' in SYS_ARGS else os.sep.join([os.environ['HOME'],'.healthcareio','config.json'])
  59. e = healthcareio.analytics.engine(PATH)
  60. # e.apply()
  61. SYS_ARGS['engine'] = e
  62. return "1",200
  63. if __name__ == '__main__' :
  64. PORT = int(SYS_ARGS['port']) if 'port' in SYS_ARGS else 5500
  65. DEBUG= int(SYS_ARGS['debug']) if 'debug' in SYS_ARGS else 1
  66. SYS_ARGS['context'] = SYS_ARGS['context'] if 'context' in SYS_ARGS else ''
  67. #
  68. #
  69. PATH= SYS_ARGS['config'] if 'config' in SYS_ARGS else os.sep.join([os.environ['HOME'],'.healthcareio','config.json'])
  70. #
  71. if os.path.exists(PATH) :
  72. SYS_ARGS['config'] = json.loads(open(PATH).read())
  73. e = healthcareio.analytics.engine(PATH)
  74. # e.apply(type='claims',serialize=True)
  75. SYS_ARGS['engine'] = e
  76. app.run(host='0.0.0.0',port=PORT,debug=DEBUG,threaded=True)