onc_certification_g10_test_kit 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +201 -0
  3. data/lib/inferno/exceptions.rb +31 -0
  4. data/lib/inferno/ext/bloomer.rb +24 -0
  5. data/lib/inferno/repositiories/validators.rb +17 -0
  6. data/lib/inferno/repositiories/value_sets.rb +26 -0
  7. data/lib/inferno/terminology/bcp47.rb +95 -0
  8. data/lib/inferno/terminology/bcp_13.rb +26 -0
  9. data/lib/inferno/terminology/codesystem.rb +49 -0
  10. data/lib/inferno/terminology/expected_manifest.yml +1123 -0
  11. data/lib/inferno/terminology/fhir_package_manager.rb +69 -0
  12. data/lib/inferno/terminology/loader.rb +298 -0
  13. data/lib/inferno/terminology/tasks/check_built_terminology.rb +77 -0
  14. data/lib/inferno/terminology/tasks/cleanup.rb +13 -0
  15. data/lib/inferno/terminology/tasks/cleanup_precursors.rb +23 -0
  16. data/lib/inferno/terminology/tasks/count_codes_in_value_set.rb +20 -0
  17. data/lib/inferno/terminology/tasks/create_value_set_validators.rb +34 -0
  18. data/lib/inferno/terminology/tasks/download_fhir_terminology.rb +27 -0
  19. data/lib/inferno/terminology/tasks/download_umls.rb +109 -0
  20. data/lib/inferno/terminology/tasks/download_umls_notice.rb +20 -0
  21. data/lib/inferno/terminology/tasks/expand_value_set_to_file.rb +36 -0
  22. data/lib/inferno/terminology/tasks/process_umls.rb +91 -0
  23. data/lib/inferno/terminology/tasks/process_umls_translations.rb +85 -0
  24. data/lib/inferno/terminology/tasks/run_umls_jar.rb +75 -0
  25. data/lib/inferno/terminology/tasks/temp_dir.rb +27 -0
  26. data/lib/inferno/terminology/tasks/unzip_umls.rb +42 -0
  27. data/lib/inferno/terminology/tasks/validate_code.rb +36 -0
  28. data/lib/inferno/terminology/tasks.rb +11 -0
  29. data/lib/inferno/terminology/terminology_configuration.rb +52 -0
  30. data/lib/inferno/terminology/terminology_validation.rb +42 -0
  31. data/lib/inferno/terminology/validator.rb +64 -0
  32. data/lib/inferno/terminology/value_set.rb +462 -0
  33. data/lib/inferno/terminology.rb +16 -0
  34. data/lib/onc_certification_g10_test_kit/authorization_request_builder.rb +87 -0
  35. data/lib/onc_certification_g10_test_kit/base_token_refresh_group.rb +48 -0
  36. data/lib/onc_certification_g10_test_kit/bulk_data_authorization.rb +235 -0
  37. data/lib/onc_certification_g10_test_kit/bulk_data_group_export.rb +255 -0
  38. data/lib/onc_certification_g10_test_kit/bulk_data_group_export_validation.rb +474 -0
  39. data/lib/onc_certification_g10_test_kit/bulk_data_jwks.json +58 -0
  40. data/lib/onc_certification_g10_test_kit/bulk_export_validation_tester.rb +171 -0
  41. data/lib/onc_certification_g10_test_kit/configuration_checker.rb +104 -0
  42. data/lib/onc_certification_g10_test_kit/export_kick_off_performer.rb +12 -0
  43. data/lib/onc_certification_g10_test_kit/igs/StructureDefinition-bodyheight.json +3772 -0
  44. data/lib/onc_certification_g10_test_kit/igs/StructureDefinition-bodytemp.json +3772 -0
  45. data/lib/onc_certification_g10_test_kit/igs/StructureDefinition-bodyweight.json +3772 -0
  46. data/lib/onc_certification_g10_test_kit/igs/StructureDefinition-bp.json +6034 -0
  47. data/lib/onc_certification_g10_test_kit/igs/StructureDefinition-heartrate.json +3756 -0
  48. data/lib/onc_certification_g10_test_kit/igs/StructureDefinition-resprate.json +3756 -0
  49. data/lib/onc_certification_g10_test_kit/limited_scope_grant_test.rb +66 -0
  50. data/lib/onc_certification_g10_test_kit/multi_patient_api.rb +43 -0
  51. data/lib/onc_certification_g10_test_kit/patient_context_test.rb +30 -0
  52. data/lib/onc_certification_g10_test_kit/profile_guesser.rb +69 -0
  53. data/lib/onc_certification_g10_test_kit/resource_access_test.rb +96 -0
  54. data/lib/onc_certification_g10_test_kit/restricted_access_test.rb +12 -0
  55. data/lib/onc_certification_g10_test_kit/restricted_resource_type_access_group.rb +303 -0
  56. data/lib/onc_certification_g10_test_kit/smart_app_launch_invalid_aud_group.rb +136 -0
  57. data/lib/onc_certification_g10_test_kit/smart_ehr_practitioner_app_group.rb +209 -0
  58. data/lib/onc_certification_g10_test_kit/smart_invalid_token_group.rb +197 -0
  59. data/lib/onc_certification_g10_test_kit/smart_limited_app_group.rb +123 -0
  60. data/lib/onc_certification_g10_test_kit/smart_public_standalone_launch_group.rb +113 -0
  61. data/lib/onc_certification_g10_test_kit/smart_scopes_test.rb +153 -0
  62. data/lib/onc_certification_g10_test_kit/smart_standalone_patient_app_group.rb +177 -0
  63. data/lib/onc_certification_g10_test_kit/terminology_binding_validator.rb +140 -0
  64. data/lib/onc_certification_g10_test_kit/token_revocation_group.rb +133 -0
  65. data/lib/onc_certification_g10_test_kit/unauthorized_access_test.rb +25 -0
  66. data/lib/onc_certification_g10_test_kit/unrestricted_resource_type_access_group.rb +375 -0
  67. data/lib/onc_certification_g10_test_kit/version.rb +3 -0
  68. data/lib/onc_certification_g10_test_kit/visual_inspection_and_attestations_group.rb +470 -0
  69. data/lib/onc_certification_g10_test_kit/well_known_capabilities_test.rb +37 -0
  70. data/lib/onc_certification_g10_test_kit.rb +223 -0
  71. metadata +310 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 22654319a665e8dec89c10ea77df9f9053ad41655d477ef4911ee70d4eb9dbc4
4
+ data.tar.gz: 8fdcd85421346c7bee498327c70249efa2c2971199f3ddb3ff455cd02af73bc2
5
+ SHA512:
6
+ metadata.gz: ee712d726c9fb438607abe8e3d2b2e84983bcb36300ea33fc741a6a89ae9ea1f6b7d9d1c069f688293bf044f963c73a09daac189d279915c4778922723d6f52d
7
+ data.tar.gz: a713aaa7ac55ed4579bc5ac0dfa6aee7998be80266640d30582fe997454976a0a4dcd03987a451f39be133b68330e250272e47fbb3cbd4b887ae8843e1d7d9d3
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,31 @@
1
+ module Inferno
2
+ class UnknownValueSetException < StandardError
3
+ def initialize(value_set)
4
+ super("Unknown ValueSet: #{value_set}")
5
+ end
6
+ end
7
+
8
+ class FilterOperationException < StandardError
9
+ def initialize(filter_op)
10
+ super("Cannot Handle Filter Operation: #{filter_op}")
11
+ end
12
+ end
13
+
14
+ class UnknownCodeSystemException < StandardError
15
+ def initialize(code_system)
16
+ super("Unknown Code System: #{code_system}")
17
+ end
18
+ end
19
+
20
+ class FileExistsException < StandardError
21
+ def initialize(value_set)
22
+ super(value_set.to_s)
23
+ end
24
+ end
25
+
26
+ class ProhibitedSystemException < StandardError
27
+ def initialize(url)
28
+ super("Inferno is unable to validate codes from #{url} due to license restrictions")
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ class Bloomer
2
+ class Scalable
3
+ # Scalable bloom filters report very inaccurate sizes because they contain
4
+ # multiple filters and don't check them all before adding something. This
5
+ # makes them check all of the filters before adding an element so that the
6
+ # size is more accurate.
7
+ def add_without_duplication(string)
8
+ return false if include? string
9
+
10
+ add string
11
+ end
12
+
13
+ def self.create_with_sufficient_size(length = 256)
14
+ size = initial_size(length)
15
+ new(size, 0.00001)
16
+ end
17
+
18
+ def self.initial_size(length)
19
+ size = 2**Math.log2(length).ceil
20
+
21
+ size < 256 ? 256 : size
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ require 'inferno/repositories/in_memory_repository'
2
+
3
+ module Inferno
4
+ module Repositories
5
+ class Validators < InMemoryRepository
6
+ def self.index_by_id
7
+ @all_by_id = {}
8
+ all.each { |vs| @all_by_id[vs.url] = vs }
9
+ @all_by_id
10
+ end
11
+
12
+ def all_urls
13
+ all_by_id.keys
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ require 'inferno/repositories/in_memory_repository'
2
+
3
+ module Inferno
4
+ module Repositories
5
+ class ValueSets < InMemoryRepository
6
+ def self.index_by_id
7
+ @all_by_id = {}
8
+ all.each { |vs| @all_by_id[vs.url] = vs }
9
+ @all_by_id
10
+ end
11
+
12
+ # @return [Hash] a Hash where the keys are vs urls and the values are vs
13
+ def select_by_url(urls)
14
+ self.class.all_by_id.slice(*urls)
15
+ end
16
+
17
+ def select_by_binding_strength(strengths)
18
+ all.select { |vs| strengths.include?(vs.strength) }
19
+ end
20
+
21
+ def find(url)
22
+ super || raise(UnknownValueSetException, url)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,95 @@
1
+ require_relative '../exceptions'
2
+
3
+ module Inferno
4
+ module Terminology
5
+ module BCP47
6
+ # https://tools.ietf.org/html/bcp47
7
+ # https://tools.ietf.org/html/rfc5646
8
+ # https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
9
+ #
10
+ class << self
11
+ SEPARATOR = '%%'.freeze
12
+ REGISTRY_URL = 'https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry'.freeze
13
+
14
+ def code_set(filter = nil)
15
+ filter_codes(filter)
16
+ end
17
+
18
+ def load_bcp47
19
+ response = RestClient.get REGISTRY_URL
20
+ response.body.split(SEPARATOR).drop(1)
21
+ end
22
+
23
+ def filter_codes(filter = nil)
24
+ bcp47 = bcp
25
+ cs_set = Set.new
26
+ bcp47.each do |raw_language|
27
+ language = parse_language(raw_language)
28
+ next if language['Subtag'].nil?
29
+ next if language['Type'] == 'region'
30
+
31
+ cs_set.add(system: 'urn:ietf:bcp:47', code: language['Subtag']) if meets_filter_criteria?(language, filter)
32
+ end
33
+ cs_set
34
+ end
35
+
36
+ private
37
+
38
+ @bcp = nil
39
+ def bcp
40
+ @bcp ||= load_bcp47
41
+ end
42
+
43
+ # Parse the language attributes chunk from the text file
44
+ #
45
+ # @param [String] language A single language and its attributes from the file
46
+ # @return [Hash] the language attributes as key value pairs
47
+ def parse_language(language)
48
+ # Need to use scan because match only returns the first match group
49
+ language.scan(regex).to_h
50
+ end
51
+
52
+ def regex
53
+ /^(?<key>\S+): (?<value>.*)$/
54
+ end
55
+
56
+ def string_to_boolean(boolean_string)
57
+ case boolean_string
58
+ when 'true'
59
+ true
60
+ when 'false'
61
+ false
62
+ end
63
+ end
64
+
65
+ def meets_filter_criteria?(language, filter)
66
+ return true unless filter
67
+
68
+ meets_criteria = true
69
+
70
+ raise FilterOperationException, filter.op unless filter.op == 'exists'
71
+
72
+ filter_value = string_to_boolean(filter.value)
73
+ raise FilterOperationException, filter.to_s if filter_value.nil?
74
+
75
+ case filter.property
76
+ when 'ext-lang'
77
+ meets_criteria = (language['Type'] == 'extlang') == filter_value
78
+ when 'script'
79
+ meets_criteria = (language['Type'] == 'script') == filter_value
80
+ when 'variant'
81
+ meets_criteria = (language['Type'] == 'variant') == filter_value
82
+ when 'extension'
83
+ meets_criteria = language['Subtag'].match?(/-\w-/) == filter_value
84
+ when 'private-use'
85
+ meets_criteria = (language['Scope'] == 'private-use') == filter_value
86
+ else
87
+ raise FilterOperationException, filter.to_s
88
+ end
89
+
90
+ meets_criteria
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,26 @@
1
+ module Inferno
2
+ module Terminology
3
+ module BCP13
4
+ @code_set = nil
5
+
6
+ def self.code_set
7
+ @code_set ||= parse_code_set
8
+ end
9
+
10
+ def self.parse_code_set
11
+ require 'mime/types'
12
+ cs_set = Set.new
13
+ MIME::Types.each do |type|
14
+ cs_set.add(system: 'urn:ietf:bcp:13', code: preprocess_code(type.simplified))
15
+ end
16
+ cs_set
17
+ end
18
+
19
+ # "preprocess" step for BCP13 codes, to remove any of the optional parameters
20
+ # and downcase them
21
+ def self.preprocess_code(code)
22
+ code&.split(';')&.first&.downcase
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,49 @@
1
+ require_relative '../exceptions'
2
+ require_relative 'bcp_13'
3
+ require_relative 'bcp47'
4
+
5
+ module Inferno
6
+ module Terminology
7
+ class Codesystem
8
+ attr_accessor :codesystem_model
9
+
10
+ def initialize(cs_model)
11
+ @codesystem_model = cs_model
12
+ end
13
+
14
+ def all_codes_in_concept(concepts)
15
+ Set.new.tap { |cs_set| load_codes(concepts.flatten, cs_set) }
16
+ end
17
+
18
+ def load_codes(concepts, cs_set)
19
+ concepts.each do |concept|
20
+ cs_set.add(system: codesystem_model.url, code: concept.code)
21
+ load_codes(concept.concept, cs_set) unless concept.concept.blank?
22
+ end
23
+ end
24
+
25
+ def find_concept(code, concepts = codesystem_model.concept)
26
+ return if concepts.nil?
27
+
28
+ concepts.find do |concept|
29
+ concept.code == code || find_concept(code, concept.concept)
30
+ end
31
+ end
32
+
33
+ def is_a_concept_filter?(filter) # rubocop:disable Naming/PredicateName
34
+ (filter.op == 'is-a') && (codesystem_model.hierarchyMeaning == 'is-a') && (filter.property == 'concept')
35
+ end
36
+
37
+ def filter_codes(filter = nil)
38
+ if filter.nil?
39
+ all_codes_in_concept(codesystem_model.concept)
40
+ elsif is_a_concept_filter? filter
41
+ parent_concept = find_concept(filter.value)
42
+ all_codes_in_concept([parent_concept])
43
+ else
44
+ raise FilterOperationException, filter.to_s
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end