aqueduct-i2b2 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/CHANGELOG.rdoc +8 -0
  2. data/LICENSE +112 -0
  3. data/README.rdoc +17 -0
  4. data/Rakefile +41 -0
  5. data/aqueduct-i2b2.gemspec +31 -0
  6. data/lib/aqueduct-i2b2.rb +7 -0
  7. data/lib/aqueduct-i2b2/version.rb +12 -0
  8. data/lib/aqueduct/wrappers/i2b2.rb +715 -0
  9. data/lib/tasks/aqueduct-i2b2_tasks.rake +4 -0
  10. data/test/aqueduct-i2b2_test.rb +7 -0
  11. data/test/dummy/README.rdoc +261 -0
  12. data/test/dummy/Rakefile +7 -0
  13. data/test/dummy/app/assets/javascripts/application.js +15 -0
  14. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  15. data/test/dummy/app/controllers/application_controller.rb +3 -0
  16. data/test/dummy/app/helpers/application_helper.rb +2 -0
  17. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  18. data/test/dummy/config.ru +4 -0
  19. data/test/dummy/config/application.rb +56 -0
  20. data/test/dummy/config/boot.rb +10 -0
  21. data/test/dummy/config/database.yml +25 -0
  22. data/test/dummy/config/environment.rb +5 -0
  23. data/test/dummy/config/environments/development.rb +37 -0
  24. data/test/dummy/config/environments/production.rb +67 -0
  25. data/test/dummy/config/environments/test.rb +37 -0
  26. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  27. data/test/dummy/config/initializers/inflections.rb +15 -0
  28. data/test/dummy/config/initializers/mime_types.rb +5 -0
  29. data/test/dummy/config/initializers/secret_token.rb +7 -0
  30. data/test/dummy/config/initializers/session_store.rb +8 -0
  31. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  32. data/test/dummy/config/locales/en.yml +5 -0
  33. data/test/dummy/config/routes.rb +58 -0
  34. data/test/dummy/db/schema.rb +16 -0
  35. data/test/dummy/db/test.sqlite3 +0 -0
  36. data/test/dummy/log/test.log +8 -0
  37. data/test/dummy/public/404.html +26 -0
  38. data/test/dummy/public/422.html +26 -0
  39. data/test/dummy/public/500.html +25 -0
  40. data/test/dummy/public/favicon.ico +0 -0
  41. data/test/dummy/script/rails +6 -0
  42. data/test/test_helper.rb +10 -0
  43. metadata +153 -0
@@ -0,0 +1,8 @@
1
+ == 0.1.0
2
+
3
+ * Enhancements
4
+ * Connects to an i2b2 server through Aqueduct interface
5
+
6
+ == 0.0.0
7
+
8
+ * Skeleton files to compile gem and make it available on rubygems.org
data/LICENSE ADDED
@@ -0,0 +1,112 @@
1
+ Copyright (c) 2012 Remo Mueller
2
+ https://github.com/remomueller
3
+ https://rubygems.org/profiles/remomueller
4
+
5
+
6
+ This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
7
+
8
+
9
+ Legal Code
10
+ http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode
11
+
12
+ Creative Commons
13
+ Attribution-NonCommercial-ShareAlike 3.0 Unported
14
+
15
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM ITS USE.
16
+
17
+ License
18
+
19
+ THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
20
+
21
+ BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
22
+
23
+ 1. Definitions
24
+
25
+ a. "Adaptation" means a work based upon the Work, or upon the Work and other pre-existing works, such as a translation, adaptation, derivative work, arrangement of music or other alterations of a literary or artistic work, or phonogram or performance and includes cinematographic adaptations or any other form in which the Work may be recast, transformed, or adapted including in any form recognizably derived from the original, except that a work that constitutes a Collection will not be considered an Adaptation for the purpose of this License. For the avoidance of doubt, where the Work is a musical work, performance or phonogram, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered an Adaptation for the purpose of this License.
26
+
27
+ b. "Collection" means a collection of literary or artistic works, such as encyclopedias and anthologies, or performances, phonograms or broadcasts, or other works or subject matter other than works listed in Section 1(g) below, which, by reason of the selection and arrangement of their contents, constitute intellectual creations, in which the Work is included in its entirety in unmodified form along with one or more other contributions, each constituting separate and independent works in themselves, which together are assembled into a collective whole. A work that constitutes a Collection will not be considered an Adaptation (as defined above) for the purposes of this License.
28
+
29
+ c. "Distribute" means to make available to the public the original and copies of the Work or Adaptation, as appropriate, through sale or other transfer of ownership.
30
+
31
+ d. "License Elements" means the following high-level license attributes as selected by Licensor and indicated in the title of this License: Attribution, Noncommercial, ShareAlike.
32
+
33
+ e. "Licensor" means the individual, individuals, entity or entities that offer(s) the Work under the terms of this License.
34
+
35
+ f. "Original Author" means, in the case of a literary or artistic work, the individual, individuals, entity or entities who created the Work or if no individual or entity can be identified, the publisher; and in addition (i) in the case of a performance the actors, singers, musicians, dancers, and other persons who act, sing, deliver, declaim, play in, interpret or otherwise perform literary or artistic works or expressions of folklore; (ii) in the case of a phonogram the producer being the person or legal entity who first fixes the sounds of a performance or other sounds; and, (iii) in the case of broadcasts, the organization that transmits the broadcast.
36
+
37
+ g. "Work" means the literary and/or artistic work offered under the terms of this License including without limitation any production in the literary, scientific and artistic domain, whatever may be the mode or form of its expression including digital form, such as a book, pamphlet and other writing; a lecture, address, sermon or other work of the same nature; a dramatic or dramatico-musical work; a choreographic work or entertainment in dumb show; a musical composition with or without words; a cinematographic work to which are assimilated works expressed by a process analogous to cinematography; a work of drawing, painting, architecture, sculpture, engraving or lithography; a photographic work to which are assimilated works expressed by a process analogous to photography; a work of applied art; an illustration, map, plan, sketch or three-dimensional work relative to geography, topography, architecture or science; a performance; a broadcast; a phonogram; a compilation of data to the extent it is protected as a copyrightable work; or a work performed by a variety or circus performer to the extent it is not otherwise considered a literary or artistic work.
38
+
39
+ h. "You" means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation.
40
+
41
+ i. "Publicly Perform" means to perform public recitations of the Work and to communicate to the public those public recitations, by any means or process, including by wire or wireless means or public digital performances; to make available to the public Works in such a way that members of the public may access these Works from a place and at a place individually chosen by them; to perform the Work to the public by any means or process and the communication to the public of the performances of the Work, including by public digital performance; to broadcast and rebroadcast the Work by any means including signs, sounds or images.
42
+
43
+ j."Reproduce" means to make copies of the Work by any means including without limitation by sound or visual recordings and the right of fixation and reproducing fixations of the Work, including storage of a protected performance or phonogram in digital form or other electronic medium.
44
+
45
+ 2. Fair Dealing Rights. Nothing in this License is intended to reduce, limit, or restrict any uses free from copyright or rights arising from limitations or exceptions that are provided for in connection with the copyright protection under copyright law or other applicable laws.
46
+
47
+ 3. License Grant. Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:
48
+
49
+ a. to Reproduce the Work, to incorporate the Work into one or more Collections, and to Reproduce the Work as incorporated in the Collections;
50
+
51
+ b. to create and Reproduce Adaptations provided that any such Adaptation, including any translation in any medium, takes reasonable steps to clearly label, demarcate or otherwise identify that changes were made to the original Work. For example, a translation could be marked "The original work was translated from English to Spanish," or a modification could indicate "The original work has been modified.";
52
+
53
+ c. to Distribute and Publicly Perform the Work including as incorporated in Collections; and,
54
+
55
+ d. to Distribute and Publicly Perform Adaptations.
56
+
57
+ The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. Subject to Section 8(f), all rights not expressly granted by Licensor are hereby reserved, including but not limited to the rights described in Section 4(e).
58
+
59
+ 4. Restrictions. The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:
60
+
61
+ a. You may Distribute or Publicly Perform the Work only under the terms of this License. You must include a copy of, or the Uniform Resource Identifier (URI) for, this License with every copy of the Work You Distribute or Publicly Perform. You may not offer or impose any terms on the Work that restrict the terms of this License or the ability of the recipient of the Work to exercise the rights granted to that recipient under the terms of the License. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties with every copy of the Work You Distribute or Publicly Perform. When You Distribute or Publicly Perform the Work, You may not impose any effective technological measures on the Work that restrict the ability of a recipient of the Work from You to exercise the rights granted to that recipient under the terms of the License. This Section 4(a) applies to the Work as incorporated in a Collection, but this does not require the Collection apart from the Work itself to be made subject to the terms of this License. If You create a Collection, upon notice from any Licensor You must, to the extent practicable, remove from the Collection any credit as required by Section 4(d), as requested. If You create an Adaptation, upon notice from any Licensor You must, to the extent practicable, remove from the Adaptation any credit as required by Section 4(d), as requested.
62
+
63
+ b. You may Distribute or Publicly Perform an Adaptation only under: (i) the terms of this License; (ii) a later version of this License with the same License Elements as this License; (iii) a Creative Commons jurisdiction license (either this or a later license version) that contains the same License Elements as this License (e.g., Attribution-NonCommercial-ShareAlike 3.0 US) ("Applicable License"). You must include a copy of, or the URI, for Applicable License with every copy of each Adaptation You Distribute or Publicly Perform. You may not offer or impose any terms on the Adaptation that restrict the terms of the Applicable License or the ability of the recipient of the Adaptation to exercise the rights granted to that recipient under the terms of the Applicable License. You must keep intact all notices that refer to the Applicable License and to the disclaimer of warranties with every copy of the Work as included in the Adaptation You Distribute or Publicly Perform. When You Distribute or Publicly Perform the Adaptation, You may not impose any effective technological measures on the Adaptation that restrict the ability of a recipient of the Adaptation from You to exercise the rights granted to that recipient under the terms of the Applicable License. This Section 4(b) applies to the Adaptation as incorporated in a Collection, but this does not require the Collection apart from the Adaptation itself to be made subject to the terms of the Applicable License.
64
+
65
+ c. You may not exercise any of the rights granted to You in Section 3 above in any manner that is primarily intended for or directed toward commercial advantage or private monetary compensation. The exchange of the Work for other copyrighted works by means of digital file-sharing or otherwise shall not be considered to be intended for or directed toward commercial advantage or private monetary compensation, provided there is no payment of any monetary compensation in con-nection with the exchange of copyrighted works.
66
+
67
+ d. If You Distribute, or Publicly Perform the Work or any Adaptations or Collections, You must, unless a request has been made pursuant to Section 4(a), keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or if the Original Author and/or Licensor designate another party or parties (e.g., a sponsor institute, publishing entity, journal) for attribution ("Attribution Parties") in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; (ii) the title of the Work if supplied; (iii) to the extent reasonably practicable, the URI, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and, (iv) consistent with Section 3(b), in the case of an Adaptation, a credit identifying the use of the Work in the Adaptation (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). The credit required by this Section 4(d) may be implemented in any reasonable manner; provided, however, that in the case of a Adaptation or Collection, at a minimum such credit will appear, if a credit for all contributing authors of the Adaptation or Collection appears, then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors. For the avoidance of doubt, You may only use the credit required by this Section for the purpose of attribution in the manner set out above and, by exercising Your rights under this License, You may not implicitly or explicitly assert or imply any connection with, sponsorship or endorsement by the Original Author, Licensor and/or Attribution Parties, as appropriate, of You or Your use of the Work, without the separate, express prior written permission of the Original Author, Licensor and/or Attribution Parties.
68
+
69
+ e. For the avoidance of doubt:
70
+
71
+ i. Non-waivable Compulsory License Schemes. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme cannot be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License;
72
+
73
+ ii. Waivable Compulsory License Schemes. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme can be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License if Your exercise of such rights is for a purpose or use which is otherwise than noncommercial as permitted under Section 4(c) and otherwise waives the right to collect royalties through any statutory or compulsory licensing scheme; and,
74
+
75
+ iii. Voluntary License Schemes. The Licensor reserves the right to collect royalties, whether individually or, in the event that the Licensor is a member of a collecting society that administers voluntary licensing schemes, via that society, from any exercise by You of the rights granted under this License that is for a purpose or use which is otherwise than noncommercial as permitted under Section 4(c).
76
+
77
+ f. Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable law, if You Reproduce, Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or Collections, You must not distort, mutilate, modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author's honor or reputation. Licensor agrees that in those jurisdictions (e.g. Japan), in which any exercise of the right granted in Section 3(b) of this License (the right to make Adaptations) would be deemed to be a distortion, mutilation, modification or other derogatory action prejudicial to the Original Author's honor and reputation, the Licensor will waive or not assert, as appropriate, this Section, to the fullest extent permitted by the applicable national law, to enable You to reasonably exercise Your right under Section 3(b) of this License (right to make Adaptations) but not otherwise.
78
+
79
+ 5. Representations, Warranties and Disclaimer
80
+
81
+ UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING AND TO THE FULLEST EXTENT PERMITTED BY APPLICABLE LAW, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO THIS EXCLUSION MAY NOT APPLY TO YOU.
82
+
83
+ 6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
84
+
85
+ 7. Termination
86
+
87
+ a. This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Adaptations or Collections from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License.
88
+
89
+ b. Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above.
90
+
91
+ 8. Miscellaneous
92
+
93
+ a. Each time You Distribute or Publicly Perform the Work or a Collection, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License.
94
+
95
+ b. Each time You Distribute or Publicly Perform an Adaptation, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License.
96
+
97
+ c. If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
98
+
99
+ d. No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent.
100
+
101
+ e. This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You.
102
+
103
+ f. The rights granted under, and the subject matter referenced, in this License were drafted utilizing the terminology of the Berne Convention for the Protection of Literary and Artistic Works (as amended on September 28, 1979), the Rome Convention of 1961, the WIPO Copyright Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996 and the Universal Copyright Convention (as revised on July 24, 1971). These rights and subject matter take effect in the relevant jurisdiction in which the License terms are sought to be enforced according to the corresponding provisions of the implementation of those treaty provisions in the applicable national law. If the standard suite of rights granted under applicable copyright law includes additional rights not granted under this License, such additional rights are deemed to be included in the License; this License is not intended to restrict the license of any rights under applicable law.
104
+
105
+
106
+ Creative Commons Notice
107
+
108
+ Creative Commons is not a party to this License, and makes no warranty whatsoever in connection with the Work. Creative Commons will not be liable to You or any party on any legal theory for any damages whatsoever, including without limitation any general, special, incidental or consequential damages arising in connection to this license. Notwithstanding the foregoing two (2) sentences, if Creative Commons has expressly identified itself as the Licensor hereunder, it shall have all rights and obligations of Licensor.
109
+
110
+ Except for the limited purpose of indicating to the public that the Work is licensed under the CCPL, Creative Commons does not authorize the use by either party of the trademark "Creative Commons" or any related trademark or logo of Creative Commons without the prior written consent of Creative Commons. Any permitted use will be in compliance with Creative Commons' then-current trademark usage guidelines, as may be published on its website or otherwise made available upon request from time to time. For the avoidance of doubt, this trademark restriction does not form part of this License.
111
+
112
+ Creative Commons may be contacted at http://creativecommons.org/.
@@ -0,0 +1,17 @@
1
+ = Aqueduct Wrapper - i2b2 {<img src="https://secure.travis-ci.org/remomueller/aqueduct-i2b2.png"/>}[http://travis-ci.org/remomueller/aqueduct-i2b2] {<img src="https://gemnasium.com/remomueller/aqueduct-i2b2.png" alt="Dependency Status" />}[https://gemnasium.com/remomueller/aqueduct-i2b2]
2
+
3
+ Connects to an i2b2 instance using Aqueduct interface
4
+
5
+ == Installation
6
+
7
+ Aqueduct Wrapper - i2b2 can be installed from rubygems.org using:
8
+
9
+ gem install aqueduct-i2b2
10
+
11
+ Or update your Gemfile to include:
12
+
13
+ gem 'aqueduct-i2b2'
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Remo Mueller. See {LICENSE}[https://github.com/remomueller/aqueduct-i2b2/blob/master/LICENSE] for further details.
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'AqueductI2b2'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('CHANGELOG.rdoc')
20
+ rdoc.rdoc_files.include('README.rdoc')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
23
+
24
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
25
+ load 'rails/tasks/engine.rake'
26
+
27
+
28
+
29
+ Bundler::GemHelper.install_tasks
30
+
31
+ require 'rake/testtask'
32
+
33
+ Rake::TestTask.new(:test) do |t|
34
+ t.libs << 'lib'
35
+ t.libs << 'test'
36
+ t.pattern = 'test/**/*_test.rb'
37
+ t.verbose = false
38
+ end
39
+
40
+
41
+ task :default => :test
@@ -0,0 +1,31 @@
1
+ # Compiling the Gem
2
+ # gem build aqueduct-i2b2.gemspec
3
+ # gem install ./aqueduct-i2b2-x.x.x.gem
4
+ #
5
+ # gem push aqueduct-i2b2-x.x.x.gem
6
+ # gem list -r aqueduct-i2b2
7
+ # gem install aqueduct-i2b2
8
+
9
+ $:.push File.expand_path("../lib", __FILE__)
10
+
11
+ # Maintain your gem's version:
12
+ require "aqueduct-i2b2/version"
13
+
14
+ # Describe your gem and declare its dependencies:
15
+ Gem::Specification.new do |s|
16
+ s.name = "aqueduct-i2b2"
17
+ s.version = Aqueduct::I2b2::VERSION::STRING
18
+ s.authors = ["Remo Mueller"]
19
+ s.email = ["remosm@gmail.com"]
20
+ s.homepage = "https://github.com/remomueller"
21
+ s.summary = "Connect to an instance of i2b2 through Aqueduct"
22
+ s.description = "Connects to an instance of i2b2 through Aqueduct interface"
23
+
24
+ s.files = Dir["{app,config,db,lib}/**/*"] + ["aqueduct-i2b2.gemspec", "CHANGELOG.rdoc", "LICENSE", "Rakefile", "README.rdoc"]
25
+ s.test_files = Dir["test/**/*"]
26
+
27
+ s.add_dependency "rails", "~> 3.2.1"
28
+ s.add_dependency "aqueduct", "~> 0.1.0"
29
+
30
+ s.add_development_dependency "sqlite3"
31
+ end
@@ -0,0 +1,7 @@
1
+ require "aqueduct-i2b2/version"
2
+ require "aqueduct/wrappers/i2b2"
3
+
4
+ module Aqueduct
5
+ module I2b2
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ module Aqueduct
2
+ module I2b2
3
+ module VERSION
4
+ MAJOR = 0
5
+ MINOR = 1
6
+ TINY = 0
7
+ BUILD = nil # nil, "pre", "rc", "rc2"
8
+
9
+ STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,715 @@
1
+ require 'aqueduct'
2
+
3
+ require 'net/http'
4
+ require 'net/https'
5
+ require 'uri'
6
+
7
+ require 'base64'
8
+ require 'openssl'
9
+
10
+ module Aqueduct
11
+ module Wrappers
12
+ class I2b2
13
+ include Aqueduct::Wrapper
14
+
15
+ DOMAIN = 'i2b2demo'
16
+
17
+ def external_concepts(folder = '', search_term = '')
18
+ search_term.blank? ? get_concepts(folder) : search_for_term(folder, search_term)
19
+ end
20
+
21
+ def external_concept_information(external_key = '')
22
+ error = ''
23
+ result = {}
24
+
25
+ service_url = '/i2b2/rest/OntologyService/getTermInfo'
26
+
27
+ xml = ::Builder::XmlMarkup.new
28
+ xml.instruct! :xml, standalone: 'yes'
29
+ xml.tag!("ns3:request", "xmlns:ns3" => "http://www.i2b2.org/xsd/hive/msg/1.1/",
30
+ "xmlns:ns4" => "http://www.i2b2.org/xsd/cell/ont/1.1/",
31
+ "xmlns:ns2" => "http://www.i2b2.org/xsd/hive/plugin/") do |req|
32
+ req.message_header do |mhr|
33
+ mhr << message_header(service_url, 'i2b2 Ontology', 1.6, 'i2b2 Hive',
34
+ 'Ontology Cell', 1.6, 'i2b2 Hive')
35
+ end
36
+ req.request_header do |rqh|
37
+ rqh.result_waittime_ms 180000
38
+ end
39
+ req.message_body do |mgb|
40
+ mgb.tag!('ns4:get_term_info', "blob" => "true", "type" => "core", "synonyms" => "true", "hiddens" => "true") do |gti|
41
+ gti.tag!('self') do |sef|
42
+ sef.text! external_key
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ result_hash = process_concepts(send_message(xml.target!, service_url))
49
+ result = result_hash[:result].first unless result_hash[:result].first.blank?
50
+ { result: result, error: result_hash[:error] }
51
+ end
52
+
53
+ def count(query_concepts, conditions, tables, join_conditions, concept_to_count)
54
+ get_total_count(query_concepts.find_all_by_id(eval(conditions)))
55
+ end
56
+
57
+ def use_sql?
58
+ false
59
+ end
60
+
61
+ def concept_tables(query_concept)
62
+ { result: [], error: '' }
63
+ end
64
+
65
+ def conditions(query_concepts)
66
+ { conditions: "#{query_concepts.collect{|qc| qc.id}}", error: '' }
67
+ end
68
+
69
+ def query(sql_statement)
70
+ # result = [[['cname', 'cname2', 'cname3', 'cname4'],[1,2,3,4],[5,nil,7,8]],2]
71
+ result = [[]]
72
+
73
+ concept_list = []
74
+ # TODO: Replace this with query_concepts (pass in query concepts initially?)
75
+
76
+ query_concepts = QueryConcept.find_all_by_id(eval(sql_statement))
77
+
78
+
79
+ result_hash = get_all_covariates(query_concepts)
80
+
81
+ result = result_hash[:result]
82
+ error = result_hash[:error]
83
+
84
+ # THIS WORKS! (For limited ors and non complex things)
85
+ # query_concepts.each_with_index do |query_concept, index|
86
+ # concept_list << { key: query_concept.external_key, right_operator: query_concept.right_operator, negated: query_concept.negated }
87
+ # end
88
+ #
89
+ # conditions = query_definition(concept_list)
90
+ #
91
+ # patient_data = run_query_get_patient_data(conditions)
92
+ #
93
+ # if patient_data.first and patient_data.first[1]
94
+ # all_concepts = patient_data.first[1].keys
95
+ # result[0] = ['patient_id'] + all_concepts
96
+ # end
97
+ #
98
+ # patient_data.each_pair do |patient_id, value_hash|
99
+ # row_data = [patient_id]
100
+ # all_concepts.each do |concept|
101
+ # row_data << value_hash[concept][:value]
102
+ # end
103
+ # result << row_data
104
+ # end
105
+
106
+ [result, result.size]
107
+ end
108
+
109
+ # TODO: Update i2b2 connect to make sure the server is up and running
110
+ def connect
111
+ true
112
+ end
113
+
114
+ private
115
+
116
+ def current_time
117
+ @current_time ||= Time.now.strftime("%Y-%m-%dT%T") + Time.now.strftime("%z").gsub(/([+-]?\d\d)(\d\d)/, "#{$1}:#{$2}")
118
+ end
119
+
120
+ def message_header(redirect_url, sending_app_name, sending_app_version, sending_facility_name, receiving_app_name, receiving_app_version, receiving_facility_name, aat = 'AL', token_available = true)
121
+ @message_header ||= begin
122
+ xml = ::Builder::XmlMarkup.new
123
+ xml.proxy do |pxy|
124
+ pxy.redirect_url "#{@source.host}#{redirect_url}"
125
+ end
126
+ xml.sending_application do |sap|
127
+ sap.application_name sending_app_name
128
+ sap.application_version sending_app_version
129
+ end
130
+ xml.sending_facility do |sfa|
131
+ sfa.facility_name sending_facility_name
132
+ end
133
+ xml.i2b2_version_compatible 1.1
134
+ xml.hl7_version_compatible 2.4
135
+ xml.datetime_of_message current_time
136
+ xml.message_control_id do |mci|
137
+ mci.message_num 'iFL7f7DmuTj349bdHcDCl'
138
+ mci.instance_num 0
139
+ end
140
+ xml.processing_id do |pi|
141
+ pi.processing_id 'P'
142
+ pi.processing_mode 'I'
143
+ end
144
+ xml.accept_acknowledgement_type aat
145
+ xml.application_acknowledgement_type 'AL'
146
+ xml.country_code 'US'
147
+ xml.project_id 'Demo'
148
+ xml.receiving_application do |rap|
149
+ rap.application_name receiving_app_name
150
+ rap.application_version receiving_app_version
151
+ end
152
+ xml.receiving_facility do |rfa|
153
+ rfa.facility_name receiving_facility_name
154
+ end
155
+ xml.security do |sec|
156
+ sec.domain DOMAIN
157
+ sec.username @source.username
158
+ if token_available
159
+ sec.tag!('password', 'token_ms_timeout' => '1800000', 'is_token' => 'true') do |p|
160
+ p.text! session_key.to_s
161
+ end
162
+ else
163
+ sec.password @source.password
164
+ end
165
+ end
166
+ xml.target!
167
+ end
168
+ end
169
+
170
+ def session_key
171
+ @session_key ||= begin
172
+ service_url = '/i2b2/rest/PMService/getServices'
173
+
174
+ xml = ::Builder::XmlMarkup.new
175
+ xml.instruct! :xml, standalone: 'yes'
176
+ xml.tag!("i2b2:request", "xmlns:i2b2" => "http://www.i2b2.org/xsd/hive/msg/1.1/", "xmlns:pm" => "http://www.i2b2.org/xsd/cell/pm/1.1/") do |req|
177
+ req.message_header do |mhr|
178
+ mhr << message_header('', 'i2b2 Project Management', 1.6, 'i2b2 Hive',
179
+ 'Project Management Cell', 1.6, 'i2b2 Hive', 'AL', false)
180
+ end
181
+ req.request_header do |rqh|
182
+ rqh.result_waittime_ms 180000
183
+ end
184
+ req.message_body do |mgb|
185
+ mgb.tag!('pm:get_user_configuration') do |cfg|
186
+ cfg.project 'undefined'
187
+ end
188
+ end
189
+ end
190
+
191
+ result_hash = send_message(xml.target!, service_url)
192
+
193
+ if result_hash[:error].blank?
194
+ # Pull out service key
195
+ key = result_hash[:result].scan(/<password .*?>(.*)<\/password>/).first.first
196
+ else
197
+ Rails.logger.debug "Error: #{result_hash[:error]}"
198
+ nil
199
+ end
200
+ end
201
+ end
202
+
203
+ def xmlitem(xml_string, xml_element)
204
+ xml_string.scan(/<#{xml_element}>(.*?)<\/#{xml_element}>/m).flatten.first.to_s
205
+ end
206
+
207
+ def process_concepts(result_hash, queryable = true)
208
+ categories = []
209
+
210
+ if result_hash[:error].blank?
211
+ concepts = result_hash[:result].scan(/<concept>(.*?)<\/concept>/m)
212
+ concepts.flatten.each do |c|
213
+ visual_attributes = xmlitem(c, 'visualattributes')
214
+
215
+ is_folder = ['CA', 'FA'].include?(visual_attributes[0..1])
216
+
217
+ full_folder = xmlitem(c, 'key')
218
+
219
+ categories << { tooltip: xmlitem(c, 'tooltip'),
220
+ is_folder: is_folder,
221
+ is_queryable: queryable,
222
+ key: xmlitem(c, 'key'),
223
+ level: xmlitem(c, 'level'),
224
+ name: xmlitem(c, 'name'),
225
+ visual_attributes: visual_attributes,
226
+ totalnum: xmlitem(c, 'totalnum'),
227
+ source_id: @source.id,
228
+ folder: @source.name }
229
+ # c.first.gsub(/[^\w<>]/, '').inspect # gsub(" ", "_")
230
+ end
231
+ end
232
+
233
+ { result: categories, error: result_hash[:error] }
234
+ end
235
+
236
+ def get_categories
237
+ service_url = '/i2b2/rest/OntologyService/getCategories'
238
+
239
+ xml = ::Builder::XmlMarkup.new
240
+ xml.instruct! :xml, standalone: 'yes'
241
+ xml.tag!("ns3:request", "xmlns:ns3" => "http://www.i2b2.org/xsd/hive/msg/1.1/",
242
+ "xmlns:ns4" => "http://www.i2b2.org/xsd/cell/ont/1.1/",
243
+ "xmlns:ns2" => "http://www.i2b2.org/xsd/hive/plugin/") do |req|
244
+ req.message_header do |mhr|
245
+ mhr << message_header(service_url, 'i2b2 Project Management', 1.6, 'i2b2 Hive',
246
+ 'Project Management Cell', 1.6, 'i2b2 Hive')
247
+ end
248
+ req.request_header do |rqh|
249
+ rqh.result_waittime_ms 180000
250
+ end
251
+ req.message_body do |mgb|
252
+ mgb.tag!('ns4:get_categories', "type" => "core")
253
+ end
254
+ end
255
+
256
+ process_concepts send_message(xml.target!, service_url), false
257
+ end
258
+
259
+ def get_child_concepts(folder = '')
260
+ service_url = '/i2b2/rest/OntologyService/getChildren'
261
+
262
+ xml = ::Builder::XmlMarkup.new
263
+ xml.instruct! :xml, standalone: 'yes'
264
+ xml.tag!("ns3:request", "xmlns:ns3" => "http://www.i2b2.org/xsd/hive/msg/1.1/",
265
+ "xmlns:ns4" => "http://www.i2b2.org/xsd/cell/ont/1.1/",
266
+ "xmlns:ns2" => "http://www.i2b2.org/xsd/hive/plugin/") do |req|
267
+ req.message_header do |mhr|
268
+ mhr << message_header(service_url, 'i2b2 Ontology', 1.6, 'i2b2 Hive',
269
+ 'Ontology Cell', 1.6, 'i2b2 Hive')
270
+ end
271
+ req.request_header do |rqh|
272
+ rqh.result_waittime_ms 180000
273
+ end
274
+ req.message_body do |mgb|
275
+ mgb.tag!('ns4:get_children', "blob" => "false", "type" => "core", "max" => "500", "synonyms" => "false", "hiddens" => "false") do |chi|
276
+ chi.parent folder
277
+ end
278
+ end
279
+ end
280
+
281
+ process_concepts send_message(xml.target!, service_url)
282
+ end
283
+
284
+ def get_concepts(folder = '')
285
+ folder.blank? ? get_categories : get_child_concepts(folder)
286
+ end
287
+
288
+ def items(concept_list)
289
+ result = ''
290
+
291
+ concept_list.each do |concept_hash|
292
+ item = ''
293
+ item << "\n\n<item>"
294
+ item << "\n <hlevel>#{concept_hash[:level]}</hlevel>"
295
+ item << "\n <item_name>#{concept_hash[:name]}</item_name>"
296
+ item << "\n <item_key>#{concept_hash[:key]}</item_key>"
297
+ item << "\n <tooltip>#{concept_hash[:tooltip]}</tooltip>"
298
+ item << "\n <class>ENC</class>"
299
+ item << "\n <item_icon>#{concept_hash[:visual_attributes]}</item_icon>"
300
+ item << "\n <item_is_synonym>false</item_is_synonym>"
301
+ item << "\n</item>\n\n"
302
+ result << item
303
+ end
304
+
305
+ result
306
+ end
307
+
308
+ def query_definition(concept_list, query_name = Time.now.to_s)
309
+ panel_number = 0
310
+ new_panel = true
311
+
312
+ query_name = query_name.gsub(/[^\w \:+-]/, '-')
313
+
314
+ q = "<query_definition>"
315
+ q << "<query_name>#{query_name}</query_name>"
316
+ q << "<query_timing>ANY</query_timing>"
317
+ q << "<specificity_scale>0</specificity_scale>"
318
+
319
+ concept_list.each do |concept_item|
320
+ if new_panel
321
+ panel_number += 1
322
+ q += "#{'</panel>' unless panel_number == 1}<panel><panel_number>#{panel_number}</panel_number><panel_accuracy_scale>0</panel_accuracy_scale><invert>#{concept_item[:negated] ? '1' : '0'}</invert><panel_timing>ANY</panel_timing><total_item_occurrences>1</total_item_occurrences>"
323
+ end
324
+ q += items([concept_item])
325
+ new_panel = (concept_item[:right_operator] == 'and')
326
+ end
327
+
328
+ q << "</panel></query_definition>"
329
+ q
330
+ end
331
+
332
+ # This function may be necessary in certain cases (faster count for single concepts)
333
+ # Currently it's not called, as of initial version 2.9.0
334
+ def run_query_get_count(conditions)
335
+ result = 0
336
+ query_master_id = '0'
337
+
338
+ service_url = "/i2b2/rest/QueryToolService/request"
339
+
340
+ xml = ::Builder::XmlMarkup.new
341
+ xml.instruct! :xml, standalone: 'yes'
342
+ xml.tag!("ns6:request", "xmlns:ns4" => "http://www.i2b2.org/xsd/cell/crc/psm/1.1/",
343
+ "xmlns:ns7" => "http://www.i2b2.org/xsd/cell/ont/1.1/",
344
+ "xmlns:ns3" => "http://www.i2b2.org/xsd/cell/crc/pdo/1.1/",
345
+ "xmlns:ns5" => "http://www.i2b2.org/xsd/hive/plugin/",
346
+ "xmlns:ns2" => "http://www.i2b2.org/xsd/hive/pdo/1.1/",
347
+ "xmlns:ns6" => "http://www.i2b2.org/xsd/hive/msg/1.1/",
348
+ "xmlns:ns8" => "http://www.i2b2.org/xsd/cell/crc/psm/querydefinition/1.1/") do |req|
349
+ req.message_header do |mhr|
350
+ mhr << message_header(service_url, 'i2b2_QueryTool', 1.6, 'PHS',
351
+ 'i2b2_DataRepositoryCell', 1.6, 'PHS', 'messageId')
352
+
353
+ # Message Type doesn't look like it is required...what's the purpose?
354
+ mhr.message_type do |mtp|
355
+ mtp.message_code 'Q04'
356
+ mtp.event_type 'EQQ'
357
+ end
358
+ end
359
+ req.request_header do |rqh|
360
+ rqh.result_waittime_ms 180000
361
+ end
362
+ req.message_body do |mgb|
363
+ mgb.tag!('ns4:psmheader') do |pmh|
364
+ pmh.user('group' => 'Demo', "login" => "demo") do |usr|
365
+ usr.text! 'demo'
366
+ end
367
+ pmh.patient_set_limit 0
368
+ pmh.estimated_time 0
369
+ pmh.query_mode 'optimize_without_temp_table'
370
+ pmh.request_type 'CRC_QRY_runQueryInstance_fromQueryDefinition'
371
+ end
372
+ mgb.tag!('ns4:request', "xsi:type" => "ns4:query_definition_requestType", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance") do |req|
373
+ req << conditions
374
+ req.result_output_list do |rol|
375
+ rol.result_output("priority_index" => "9", "name" => "patient_count_xml") # The only difference between this and run_query_get_patient_set
376
+ end
377
+ end
378
+ end
379
+ end
380
+
381
+ result_hash = send_message(xml.target!, service_url)
382
+
383
+ result = xmlitem(result_hash[:result], 'set_size') if result_hash[:error].blank?
384
+ query_master_id = xmlitem(result_hash[:result], 'result_instance_id') if result_hash[:error].blank?
385
+
386
+ {result: result, error: result_hash[:error], query_master_id: query_master_id}
387
+ end
388
+
389
+ def run_query_get_patient_set(conditions)
390
+ result = 0
391
+ service_url = "/i2b2/rest/QueryToolService/request"
392
+
393
+ xml = ::Builder::XmlMarkup.new
394
+ xml.instruct! :xml, standalone: 'yes'
395
+ xml.tag!("ns6:request", "xmlns:ns4" => "http://www.i2b2.org/xsd/cell/crc/psm/1.1/",
396
+ "xmlns:ns7" => "http://www.i2b2.org/xsd/cell/ont/1.1/",
397
+ "xmlns:ns3" => "http://www.i2b2.org/xsd/cell/crc/pdo/1.1/",
398
+ "xmlns:ns5" => "http://www.i2b2.org/xsd/hive/plugin/",
399
+ "xmlns:ns2" => "http://www.i2b2.org/xsd/hive/pdo/1.1/",
400
+ "xmlns:ns6" => "http://www.i2b2.org/xsd/hive/msg/1.1/",
401
+ "xmlns:ns8" => "http://www.i2b2.org/xsd/cell/crc/psm/querydefinition/1.1/") do |req|
402
+ req.message_header do |mhr|
403
+ mhr << message_header(service_url, 'i2b2_QueryTool', 1.6, 'PHS',
404
+ 'i2b2_DataRepositoryCell', 1.6, 'PHS', 'messageId')
405
+
406
+ # Message Type doesn't look like it is required...what's the purpose?
407
+ mhr.message_type do |mtp|
408
+ mtp.message_code 'Q04'
409
+ mtp.event_type 'EQQ'
410
+ end
411
+ end
412
+ req.request_header do |rqh|
413
+ rqh.result_waittime_ms 180000
414
+ end
415
+ req.message_body do |mgb|
416
+ mgb.tag!('ns4:psmheader') do |pmh|
417
+ pmh.user('group' => 'Demo', "login" => "demo") do |usr|
418
+ usr.text! 'demo'
419
+ end
420
+ pmh.patient_set_limit 0
421
+ pmh.estimated_time 0
422
+ pmh.query_mode 'optimize_without_temp_table'
423
+ pmh.request_type 'CRC_QRY_runQueryInstance_fromQueryDefinition'
424
+ end
425
+ mgb.tag!('ns4:request', "xsi:type" => "ns4:query_definition_requestType", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance") do |req|
426
+ req << conditions
427
+ req.result_output_list do |rol|
428
+ rol.result_output("priority_index" => "9", "name" => "patientset")
429
+ end
430
+ end
431
+ end
432
+ end
433
+
434
+ result_hash = send_message(xml.target!, service_url)
435
+
436
+ result = xmlitem(result_hash[:result], 'set_size') if result_hash[:error].blank?
437
+ query_master_id = xmlitem(result_hash[:result], 'result_instance_id') if result_hash[:error].blank?
438
+
439
+
440
+ { result: result, error: result_hash[:error], query_master_id: query_master_id }
441
+ end
442
+
443
+ def run_pdo_request(conditions)
444
+
445
+ result_hash = run_query_get_patient_set(conditions)
446
+ if result_hash[:error].blank?
447
+ query_master_id = result_hash[:query_master_id]
448
+ else
449
+
450
+ end
451
+
452
+ service_url = "/i2b2/rest/QueryToolService/pdorequest"
453
+
454
+ xml = ::Builder::XmlMarkup.new
455
+ xml.instruct! :xml, standalone: 'yes'
456
+ xml.tag!("ns6:request", "xmlns:ns4" => "http://www.i2b2.org/xsd/cell/crc/psm/1.1/",
457
+ "xmlns:ns7" => "http://www.i2b2.org/xsd/cell/crc/psm/querydefinition/1.1/",
458
+ "xmlns:ns3" => "http://www.i2b2.org/xsd/cell/crc/pdo/1.1/",
459
+ "xmlns:ns5" => "http://www.i2b2.org/xsd/hive/plugin/",
460
+ "xmlns:ns2" => "http://www.i2b2.org/xsd/hive/pdo/1.1/",
461
+ "xmlns:ns6" => "http://www.i2b2.org/xsd/hive/msg/1.1/") do |req|
462
+ req.message_header do |mhr|
463
+ mhr << message_header(service_url, 'i2b2_QueryTool', 1.6, 'PHS',
464
+ 'i2b2_DataRepositoryCell', 1.6, 'PHS', 'messageId')
465
+ # Message Type doesn't look like it is required...what's the purpose?
466
+ mhr.message_type do |mtp|
467
+ mtp.message_code 'Q04'
468
+ mtp.event_type 'EQQ'
469
+ end
470
+ end
471
+ req.request_header do |rqh|
472
+ rqh.result_waittime_ms 180000
473
+ end
474
+ req.message_body do |mgb|
475
+
476
+ mgb.tag!('ns3:pdoheader') do |pdh|
477
+ pdh.patient_set_limit 0
478
+ pdh.estimated_time 180000
479
+ pdh.request_type 'getPDO_fromInputList'
480
+ end
481
+
482
+ mgb.tag!('ns3:request', "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xsi:type" => "ns3:GetPDOFromInputList_requestType") do |req|
483
+ req.input_list do |ipl|
484
+ ipl.tag!('patient_list', "max" => "1000000", "min" => "0") do |pal|
485
+ pal.patient_set_coll_id query_master_id
486
+ end
487
+ end
488
+ req.filter_list
489
+ req.output_option do |opo|
490
+ opo.tag!('patient_set', "select" => "using_input_list", "onlykeys" => "false")
491
+ end
492
+ end
493
+ end
494
+ end
495
+
496
+ result_hash = send_message(xml.target!, service_url)
497
+ result_hash
498
+ end
499
+
500
+ def run_query_get_patient_ids(conditions)
501
+
502
+ result_hash = run_pdo_request(conditions)
503
+
504
+ patient_ids = []
505
+
506
+ if result_hash[:error].blank?
507
+ patient_ids = result_hash[:result].scan(/<patient_id>(.*?)<\/patient_id>/).flatten
508
+ else
509
+ Rails.logger.debug result_hash[:error]
510
+ end
511
+
512
+ { result: patient_ids, error: result_hash[:error] }
513
+ end
514
+
515
+ def run_query_get_patient_data(conditions)
516
+ result_hash = run_pdo_request(conditions)
517
+ patient_data = {}
518
+
519
+ if result_hash[:error].blank?
520
+ # TODO: Handle case or result_hash being nil...perhaps with a to_s
521
+ id = result_hash[:result].scan(/<ns2:patient_set>(.*?)<\/ns2:patient_set>/m).flatten.first
522
+ id.scan(/<patient>(.*?)<\/patient>/m).each do |c|
523
+ patient_id = c.to_s.scan(/<patient_id>(.*?)<\/patient_id>/m).flatten.first
524
+
525
+ patient_data[patient_id] = {}
526
+
527
+
528
+
529
+ test2 = c.to_s.scan(/(<param .*?(<\/param>|\/>))/m).each do |pars|
530
+ p_string = pars.flatten.first
531
+ value = nil
532
+ unless pars[1] == "/>"
533
+ value = p_string.scan(/<param .*?>(.*?)<\/param>/m).flatten.first
534
+ end
535
+ column_name = p_string.scan(/column=\\"(.*?)\\"/m).flatten.first
536
+ display_name = p_string.scan(/column\_descriptor=\\"(.*?)\\"/m).flatten.first || column_name.to_s.capitalize #.titleize
537
+ patient_data[patient_id][column_name] = { value: value, display_name: display_name }
538
+ end
539
+ end
540
+ else
541
+ # TODO: Push error out to upper service
542
+ puts result_hash[:error]
543
+ end
544
+
545
+ patient_data
546
+ end
547
+
548
+ def get_total_count(query_concepts)
549
+ error = ''
550
+ eval_string = ''
551
+ patient_ids = [] # This one returns the combined evaluated expressions
552
+ all_patient_ids = [] # this is a partial patient ids...
553
+ query_concepts.each_with_index do |query_concept, index|
554
+ result = query_definition([{key: query_concept.external_key, right_operator: query_concept.right_operator, negated: query_concept.negated}]) # , query_concept.query.name
555
+ result_hash = run_query_get_patient_ids(result)
556
+ all_patient_ids << result_hash[:result]
557
+ error = result_hash[:error] unless result_hash[:error].blank?
558
+
559
+ eval_string << "("*query_concept.left_brackets unless query_concepts.size == 1
560
+ eval_string << result_hash[:result].to_s
561
+ eval_string << ")"*query_concept.right_brackets unless query_concepts.size == 1
562
+ if index < query_concepts.size - 1
563
+ case query_concept.right_operator when 'and'
564
+ eval_string << '&'
565
+ when 'or'
566
+ eval_string << '|'
567
+ else
568
+ return { result: 0, error: "Invalid operator '#{query_concept.right_operator}' in evaluation string.", sql_conditions: eval_string }
569
+ end
570
+ end
571
+ end
572
+
573
+ total_count = 0
574
+ begin
575
+ total_count = eval(eval_string).size
576
+ patient_ids = eval(eval_string)
577
+ rescue => e
578
+ error = "#{e}"
579
+ end
580
+
581
+ { result: total_count, error: error, sql_conditions: eval_string, patient_ids: patient_ids }
582
+ end
583
+
584
+ def get_total_query_patient_ids(query_concepts)
585
+ result = []
586
+ result_hash = get_total_count(query_concepts)
587
+ result = result_hash[:patient_ids] if result_hash[:error].blank?
588
+ result
589
+ end
590
+
591
+ # Access each query_concept individually and retrieve all the associated data, then trim the data based on the actual resulting patient IDs from the query.
592
+ def get_all_covariates(query_concepts)
593
+ error = ''
594
+ result = [[]]
595
+ all_patient_ids = []
596
+ all_concepts = []
597
+
598
+
599
+ query_concepts.each_with_index do |query_concept, index|
600
+ conditions = query_definition([{ key: query_concept.external_key, right_operator: query_concept.right_operator, negated: query_concept.negated }])
601
+ patient_data = run_query_get_patient_data(conditions)
602
+
603
+ if patient_data.first and patient_data.first[1] and result[0].blank?
604
+ all_concepts = patient_data.first[1].keys
605
+ result[0] = ['patient_id'] + all_concepts
606
+ end
607
+
608
+ patient_data.each_pair do |patient_id, value_hash|
609
+ row_data = [patient_id]
610
+
611
+ all_concepts.each do |concept|
612
+ row_data << value_hash[concept][:value]
613
+ end
614
+ result << row_data
615
+ end
616
+ end
617
+
618
+ all_patient_ids = get_total_query_patient_ids(query_concepts)
619
+ overall_result = [[]]
620
+
621
+ overall_result[0] = result[0]
622
+
623
+ result[1..-1].each do |row|
624
+ if all_patient_ids.include?(row[0])
625
+ overall_result << row
626
+ all_patient_ids.delete(row[0])
627
+ end
628
+ end
629
+
630
+ { result: overall_result, error: error }
631
+ end
632
+
633
+ def search_for_term(folder, term)
634
+ categories_hash = get_categories
635
+
636
+ return categories_hash unless categories_hash[:error].blank?
637
+
638
+ concepts = []
639
+ error = ''
640
+
641
+ categories = categories_hash[:result].collect{|c| c[:key].gsub(/\\\\/, '').split(/\\/).first.to_s}
642
+
643
+ categories.each do |category|
644
+ result_hash = search_for_term_helper(term, category)
645
+ concepts = (concepts | result_hash[:result]) if result_hash[:error].blank?
646
+ error = result_hash[:error] unless result_hash[:error].blank?
647
+ end
648
+
649
+ concepts = concepts.select{|c| (c[:folder] == folder or folder.blank?)}.uniq
650
+
651
+ { result: concepts, error: error }
652
+ end
653
+
654
+ def search_for_term_helper(term, category)
655
+
656
+ service_url = '/i2b2/rest/OntologyService/getNameInfo'
657
+
658
+ xml = ::Builder::XmlMarkup.new
659
+ xml.instruct! :xml, standalone: 'yes'
660
+ xml.tag!("ns3:request", "xmlns:ns3" => "http://www.i2b2.org/xsd/hive/msg/1.1/",
661
+ "xmlns:ns4" => "http://www.i2b2.org/xsd/cell/ont/1.1/",
662
+ "xmlns:ns2" => "http://www.i2b2.org/xsd/hive/plugin/") do |req|
663
+ req.message_header do |mhr|
664
+ mhr << message_header(service_url, 'i2b2 Ontology', 1.6, 'i2b2 Hive',
665
+ 'Ontology Cell', 1.6, 'i2b2 Hive')
666
+ end
667
+ req.request_header do |rqh|
668
+ rqh.result_waittime_ms 180000
669
+ end
670
+ req.message_body do |mgb|
671
+ mgb.tag!('ns4:get_name_info', "blob" => "true", "type" => "core", "max" => "500", "category" => category) do |gni|
672
+ gni.tag!('match_str', "strategy" => "left") do |mst|
673
+ mst.text! term
674
+ end
675
+ end
676
+ end
677
+ end
678
+
679
+ process_concepts send_message(xml.target!, service_url)
680
+ end
681
+
682
+ def send_message(message, service)
683
+
684
+ url = URI.parse(@source.host + service)
685
+
686
+ use_secure = (url.scheme == 'https')
687
+
688
+ https = Net::HTTP.new(url.host, url.port)
689
+ https.open_timeout = 10 # Seconds
690
+ https.read_timeout = 30 # might need to be longer?
691
+ if use_secure
692
+ https.use_ssl = true
693
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
694
+ end
695
+ headers = {'Content-Type' => 'text/xml'};
696
+ data = ''
697
+ error = ''
698
+ begin
699
+ response = https.post2(url.path, message, headers)
700
+ data = response.body
701
+
702
+ case response.class.name
703
+ when 'Net::HTTPOK'
704
+ else
705
+ error = "Error: #{response.class.name} #{data}"
706
+ end
707
+ rescue Exception => e
708
+ error = "Exception: #{e} #{response.class.name} #{data}"
709
+ end
710
+
711
+ return { result: data, error: error }
712
+ end
713
+ end
714
+ end
715
+ end