io.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /**
  2. * This file will depend on dialog.js (soft dependency). Some functions here will make calls to resources in dialog.js
  3. */
  4. var reset = function(){
  5. dialog.open('Healthcare/IO::Parser', 'Are you sure you would like to delete all data parsed? Click Ok to confirm',confirmed.reset)
  6. }
  7. var update= function(){
  8. dialog.open('Healthcare/IO::Parser','Update will change parsing configuration. Would you like to continue ?',confirmed.update)
  9. }
  10. var run = function(){
  11. dialog.open('Healthcare/IO::Parser','Preparing parser, confirm to continue',confirmed.run)
  12. }
  13. var _queue = {socket:null}
  14. var confirmed = {}
  15. confirmed.run = function(){
  16. dialog.status.busy()
  17. dialog.status.wait()
  18. $('.dialog .message .text').html('Initiating Parsing ...')
  19. setTimeout(function(){
  20. var http = HttpClient.instance()
  21. http.post(sessionStorage.io_context+'/io/run',function(x){
  22. // dialog.handler = setInterval(function(){monitor.data()},750)
  23. monitor.data()
  24. //dialog.close()
  25. })
  26. },1000)
  27. }
  28. confirmed.reset = function(){
  29. var uri = sessionStorage.io_context+'/reset'
  30. var http= HttpClient.instance()
  31. dialog.status.busy()
  32. dialog.status.wait()
  33. http.post(uri,function(x){
  34. setTimeout(function(){
  35. if (x.status == 200 && x.responseText == "1"){
  36. dialog.status.success()
  37. $('.dialog .message .text').html('Reset Healthcare/IO::Parser was successful!<br><div align="center">Dialog will be closing</div>')
  38. dialog.close()
  39. }else{
  40. dialog.status.fail()
  41. }
  42. },2000)
  43. })
  44. }
  45. confirmed.update = function(){
  46. var uri = sessionStorage.io_context+'/update'
  47. var email = $('#email').val()
  48. //
  49. //-- validate the email
  50. if (email.match(/^([^\s]+)@([^\s@]+)\.(org|com|edu|io)$/i)){
  51. dialog.status.wait()
  52. dialog.status.busy()
  53. var http = HttpClient.instance()
  54. http.setData({"email":email},"application/son")
  55. setTimeout(function(){
  56. http.post(uri,function(x){
  57. if(x.status == 200 && x.responseText == "1"){
  58. dialog.status.success()
  59. }else{
  60. dialog.status.fail()
  61. $('.dialog .message .text').html('Error code '+x.status)
  62. dialog.bind()
  63. dialog.status.confirm()
  64. $('.dialog .title-bar .title').html("Error found")
  65. }
  66. })
  67. },1000)
  68. }else{
  69. dialog.status.fail()
  70. dialog.bind()
  71. $('.dialog .title-bar .title').text("Error found")
  72. $('.dialog .message .text').html('Invvalid Email entered')
  73. dialog.status.confirm()
  74. }
  75. }
  76. /**
  77. * This namespace is designed to export data to either the cloud or to a database
  78. */
  79. var publish={set:{}}
  80. publish.post = function(){
  81. if($('.jxmodal').length > 0){
  82. jx.modal.close()
  83. }
  84. dialog.open('Export/ETL','Please wait')
  85. dialog.status.busy()
  86. var http = HttpClient.instance()
  87. http.setData(JSON.parse(sessionStorage.export),"application/json")
  88. http.post(sessionStorage.io_context+'/export',function(x){
  89. if (x.status != 200){
  90. setTimeout(function(){
  91. $('.dialog .message .text').html('An error occurred with code '+x.status)
  92. dialog.status.fail()
  93. dialog.status.wait()
  94. },1500)
  95. }
  96. //
  97. // @TODO: Have progress be monitored for this bad boy i.e open the connection to socket and read in ...
  98. //
  99. })
  100. }
  101. publish.set.file = function(){
  102. var file = $('#file')[0].files[0]
  103. $('.file .name').html(file.name)
  104. var button = $('.cloud input').prop('disabled',true)
  105. var div = $('.cloud .file .fa-file-upload')[0]
  106. $(div).empty()
  107. $(div).addClass('fas fa-cog fa-spin')
  108. var reader = new FileReader()
  109. reader.readAsText(file)
  110. reader.onload = function(){
  111. _args = {"type":$('.cloud .id').html().trim(),"content":reader.result}
  112. // _args = JSON.stringify(_args)
  113. if (_args.content.match(/^\{.+/i) == null){
  114. content = _args.content.split('\n')[1].split(',')
  115. _args.content = {'bucket':'healthcareio','access_key':content[0].trim(),'secret_key':content[1].trim()}
  116. }
  117. sessionStorage.export = JSON.stringify(_args)
  118. }
  119. reader.onloadend = function(){
  120. setTimeout(function(){
  121. var div = $('.cloud .file .fa-cog')[0]
  122. $(div).empty()
  123. $(div).addClass('fas fa-check')
  124. $(div).removeClass('fa-spin')
  125. // jx.modal.close()
  126. //setTimeout(jx.modal.close,1500)
  127. publish.post()
  128. },2000)
  129. }
  130. }
  131. publish.database = {}
  132. publish.database.init = function(id){
  133. //
  134. // we are expecting id in {mongo,couch,postgresql,mysql,sqlite}
  135. // @TODO: Account for cloud service brokers like dropbox, box, one-drive and google-drive
  136. sessionStorage.export = "{}"
  137. p = {'id':id}
  138. if (id.match(/(mongodb|postgresql|mysql|sqlite|couchdb)/i)){
  139. var hide_id = '.store .cloud'
  140. var show_id = '.store .database'
  141. }else{
  142. //
  143. // @TODO: generate an error message
  144. var show_id = '.store .cloud'
  145. var hide_id = '.store .database'
  146. }
  147. var http = HttpClient.instance()
  148. http.get(sessionStorage.io_context+'/export',function(x){
  149. var html = x.responseText
  150. jx.modal.show({'html':html,'id':'dialog'})
  151. $(hide_id).hide(function(){
  152. $(show_id).show()
  153. })
  154. $('.store .id').text(id)
  155. })
  156. }