pacio_inferno_core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +201 -0
  3. data/lib/pacio_inferno_core/custom_groups/capability_statement/conformance_support_test.rb +41 -0
  4. data/lib/pacio_inferno_core/custom_groups/capability_statement/fhir_version_test.rb +15 -0
  5. data/lib/pacio_inferno_core/custom_groups/capability_statement/instantiate_test.rb +23 -0
  6. data/lib/pacio_inferno_core/custom_groups/capability_statement/json_support_test.rb +40 -0
  7. data/lib/pacio_inferno_core/date_search_validation.rb +112 -0
  8. data/lib/pacio_inferno_core/fhir_resource_navigation.rb +7 -0
  9. data/lib/pacio_inferno_core/generator/group_generator.rb +161 -0
  10. data/lib/pacio_inferno_core/generator/group_metadata.rb +114 -0
  11. data/lib/pacio_inferno_core/generator/group_metadata_extractor.rb +301 -0
  12. data/lib/pacio_inferno_core/generator/ig_loader.rb +118 -0
  13. data/lib/pacio_inferno_core/generator/ig_metadata.rb +60 -0
  14. data/lib/pacio_inferno_core/generator/ig_metadata_extractor.rb +88 -0
  15. data/lib/pacio_inferno_core/generator/ig_resources.rb +88 -0
  16. data/lib/pacio_inferno_core/generator/must_support_metadata_extractor.rb +8 -0
  17. data/lib/pacio_inferno_core/generator/must_support_test_generator.rb +138 -0
  18. data/lib/pacio_inferno_core/generator/naming.rb +50 -0
  19. data/lib/pacio_inferno_core/generator/read_test_generator.rb +102 -0
  20. data/lib/pacio_inferno_core/generator/reference_resolution_test_generator.rb +96 -0
  21. data/lib/pacio_inferno_core/generator/search_definition_metadata_extractor.rb +228 -0
  22. data/lib/pacio_inferno_core/generator/search_metadata_extractor.rb +78 -0
  23. data/lib/pacio_inferno_core/generator/search_test_generator.rb +298 -0
  24. data/lib/pacio_inferno_core/generator/special_cases.rb +61 -0
  25. data/lib/pacio_inferno_core/generator/suite_generator.rb +105 -0
  26. data/lib/pacio_inferno_core/generator/templates/group.rb.erb +27 -0
  27. data/lib/pacio_inferno_core/generator/templates/must_support.rb.erb +36 -0
  28. data/lib/pacio_inferno_core/generator/templates/read.rb.erb +34 -0
  29. data/lib/pacio_inferno_core/generator/templates/reference_resolution.rb.erb +40 -0
  30. data/lib/pacio_inferno_core/generator/templates/search.rb.erb +40 -0
  31. data/lib/pacio_inferno_core/generator/templates/validation.rb.erb +36 -0
  32. data/lib/pacio_inferno_core/generator/terminology_binding_metadata_extractor.rb +116 -0
  33. data/lib/pacio_inferno_core/generator/validation_test_generator.rb +146 -0
  34. data/lib/pacio_inferno_core/generator/value_extractor.rb +152 -0
  35. data/lib/pacio_inferno_core/generator.rb +130 -0
  36. data/lib/pacio_inferno_core/must_support_test.rb +20 -0
  37. data/lib/pacio_inferno_core/primitive_type.rb +5 -0
  38. data/lib/pacio_inferno_core/read_test.rb +103 -0
  39. data/lib/pacio_inferno_core/reference_resolution_test.rb +181 -0
  40. data/lib/pacio_inferno_core/request_logger.rb +46 -0
  41. data/lib/pacio_inferno_core/resource_search_param_checker.rb +136 -0
  42. data/lib/pacio_inferno_core/search_test.rb +859 -0
  43. data/lib/pacio_inferno_core/search_test_properties.rb +56 -0
  44. data/lib/pacio_inferno_core/validation_test.rb +55 -0
  45. data/lib/pacio_inferno_core/version.rb +4 -0
  46. data/lib/pacio_inferno_core/well_known_code_systems.rb +21 -0
  47. metadata +165 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c7e34871dfb8d144500c2d7201253013a27cce92413aaffc8704b16eb0331cd7
4
+ data.tar.gz: 7bf41e835597e2841c8904f900803a425565687a3aad99ca3922e0b061345c53
5
+ SHA512:
6
+ metadata.gz: 53b78bcae65f294473391daa99027fef3d7c252290666019b703683de19321777d272ee391869b7c2e397188f959ff519734e618ae8e929f675b3b848e784df7
7
+ data.tar.gz: 32045b109ec5ad255d2f77d13ad6bc02691f3f22c412decf3b305e82223941219f40e31a5d5687174ce3f2dceb51e85a65ed5d4353f3ca8b68038f68cc3f4147
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,41 @@
1
+ module PacioInfernoCore
2
+ class ConformanceSupportTest < Inferno::Test
3
+ id :pacio_inferno_core_conformance_support
4
+ title 'FHIR Server supports the conformance interaction'
5
+ description %(
6
+ The conformance 'whole system' interaction provides a method to get the
7
+ CapabilityStatement for the FHIR server. This test checks that the
8
+ server responds to a `GET` request at the following endpoint:
9
+
10
+ ```
11
+ GET [base]/metadata
12
+ ```
13
+
14
+ This test checks the following SHALL requirement:
15
+
16
+ > Applications SHALL return a resource that describes the functionality
17
+ of the server end-point.
18
+
19
+ [http://hl7.org/fhir/R4/http.html#capabilities](http://hl7.org/fhir/R4/http.html#capabilities)
20
+
21
+ It does this by checking that the server responds with an HTTP OK 200
22
+ status code and that the body of the response contains a valid
23
+ [CapabilityStatement
24
+ resource](http://hl7.org/fhir/R4/capabilitystatement.html). This test
25
+ does not inspect the content of the CapabilityStatement to see if it
26
+ contains the required information. It only checks to see if the RESTful
27
+ interaction is supported and returns a valid CapabilityStatement
28
+ resource.
29
+ )
30
+ makes_request :capability_statement
31
+
32
+ run do
33
+ fhir_client.set_no_auth
34
+ fhir_get_capability_statement(name: :capability_statement)
35
+
36
+ assert_response_status(200)
37
+ assert_resource_type(:capability_statement)
38
+ assert_valid_resource
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,15 @@
1
+ module PacioInfernoCore
2
+ class FHIRVersionTest < Inferno::Test
3
+ id :pacio_inferno_core_fhir_version
4
+ title 'Server is using FHIR R4'
5
+ description %(
6
+ This test inspects the CapabilityStatement returned by the server to
7
+ verify that the server is using FHIR R4.
8
+ )
9
+
10
+ run do
11
+ server_version = fhir_client.detect_version.to_s.upcase
12
+ assert server_version == 'R4', "Server is using FHIR version #{server_version} rather than R4"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module PacioInfernoCore
2
+ class InstantiateTest < Inferno::Test
3
+ id :pacio_inferno_core_instantiate
4
+ title 'Server instantiates US Core Server'
5
+ description %(
6
+ This test inspects the CapabilityStatement returned by the server to
7
+ verify that the server instantiates http://hl7.org/fhir/us/core/CapabilityStatement/us-core-server
8
+ )
9
+ uses_request :capability_statement
10
+
11
+ run do
12
+ assert_resource_type(:capability_statement)
13
+ capability_statement = resource
14
+
15
+ include_us_core = capability_statement.instantiates&.any? do |url|
16
+ url.split('|').first == 'http://hl7.org/fhir/us/core/CapabilityStatement/us-core-server'
17
+ end
18
+
19
+ assert include_us_core,
20
+ "Server CapabilityStatement.instantiates does not include 'http://hl7.org/fhir/us/core/CapabilityStatement/us-core-server'"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,40 @@
1
+ module PacioInfernoCore
2
+ class JSONSupportTest < Inferno::Test
3
+ id :pacio_inferno_core_json_support
4
+ title 'FHIR server capability states JSON support'
5
+ description %(
6
+ FHIR provides multiple [representation
7
+ formats](https://www.hl7.org/fhir/formats.html) for resources, including
8
+ JSON and XML. US Core profiles require servers to use the [JSON
9
+ representation](https://www.hl7.org/fhir/json.html):
10
+
11
+ [```The US Core Server **SHALL** Support json source formats for all US
12
+ Core
13
+ interactions.```](http://hl7.org/fhir/us/core/CapabilityStatement-us-core-server.html#behavior)
14
+
15
+ The FHIR conformance interaction require servers to describe which
16
+ formats are available for clients to use. The server must explicitly
17
+ state that JSON is supported. This is located in the [format
18
+ element](https://www.hl7.org/fhir/capabilitystatement-definitions.html#CapabilityStatement.format)
19
+ of the CapabilityStatement Resource.
20
+
21
+ This test checks that one of the following values are located in the
22
+ format field.
23
+
24
+ * json
25
+ * application/json
26
+ * application/fhir+json
27
+ )
28
+ uses_request :capability_statement
29
+
30
+ run do
31
+ assert_resource_type(:capability_statement)
32
+
33
+ json_formats = ['json', 'application/json', 'application/fhir+json']
34
+ server_formats = resource.format
35
+
36
+ assert server_formats.any? { |format| json_formats.include? format },
37
+ 'CapabilityStatement does not state support for JSON'
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PacioInfernoCore
4
+ module DateSearchValidation
5
+ def get_fhir_datetime_range(datetime)
6
+ range = { start: DateTime.xmlschema(datetime), end: nil }
7
+ range[:end] =
8
+ if /^\d{4}$/.match?(datetime) # YYYY
9
+ range[:start].next_year - 1.seconds
10
+ elsif /^\d{4}-\d{2}$/.match?(datetime) # YYYY-MM
11
+ range[:start].next_month - 1.seconds
12
+ elsif /^\d{4}-\d{2}-\d{2}$/.match?(datetime) # YYYY-MM-DD
13
+ range[:start].next_day - 1.seconds
14
+ else # YYYY-MM-DDThh:mm:ss+zz:zz
15
+ range[:start]
16
+ end
17
+ range
18
+ end
19
+
20
+ def get_fhir_period_range(period)
21
+ range = { start: nil, end: nil }
22
+ range[:start] = DateTime.xmlschema(period.start) unless period.start.nil?
23
+ return range if period.end.nil?
24
+
25
+ period_end_beginning = DateTime.xmlschema(period.end)
26
+ range[:end] =
27
+ if /^\d{4}$/.match?(period.end) # YYYY
28
+ period_end_beginning.next_year - 1.seconds
29
+ elsif /^\d{4}-\d{2}$/.match?(period.end) # YYYY-MM
30
+ period_end_beginning.next_month - 1.seconds
31
+ elsif /^\d{4}-\d{2}-\d{2}$/.match?(period.end) # YYYY-MM-DD
32
+ period_end_beginning.next_day - 1.seconds
33
+ else # YYYY-MM-DDThh:mm:ss+zz:zz
34
+ period_end_beginning
35
+ end
36
+ range
37
+ end
38
+
39
+ def fhir_date_comparer(search_range, target_range, comparator, extend_start = false, extend_end = false)
40
+ # Implicitly, a missing lower boundary is "less than" any actual date. A missing upper boundary is "greater than" any actual date.
41
+ case comparator
42
+ when 'eq' # the range of the search value fully contains the range of the target value
43
+ !target_range[:start].nil? && !target_range[:end].nil? && search_range[:start] <= target_range[:start] && search_range[:end] >= target_range[:end]
44
+ when 'ne' # the range of the search value does not fully contain the range of the target value
45
+ target_range[:start].nil? || target_range[:end].nil? || search_range[:start] > target_range[:start] || search_range[:end] < target_range[:end]
46
+ when 'gt' # the range above the search value intersects (i.e. overlaps) with the range of the target value
47
+ target_range[:end].nil? || search_range[:end] < target_range[:end] || (search_range[:end] < (target_range[:end] + 1) && extend_end)
48
+ when 'lt' # the range below the search value intersects (i.e. overlaps) with the range of the target value
49
+ target_range[:start].nil? || search_range[:start] > target_range[:start] || (search_range[:start] > (target_range[:start] - 1) && extend_start)
50
+ when 'ge'
51
+ fhir_date_comparer(search_range, target_range, 'gt', extend_start,
52
+ extend_end) || fhir_date_comparer(search_range, target_range, 'eq')
53
+ when 'le'
54
+ fhir_date_comparer(search_range, target_range, 'lt', extend_start,
55
+ extend_end) || fhir_date_comparer(search_range, target_range, 'eq')
56
+ when 'sa' # the range above the search value contains the range of the target value
57
+ !target_range[:start].nil? && search_range[:end] < target_range[:start]
58
+ when 'eb' # the range below the search value contains the range of the target value
59
+ !target_range[:end].nil? && search_range[:start] > target_range[:end]
60
+ when 'ap' # the range of the search value overlaps with the range of the target value
61
+ if target_range[:start].nil? || target_range[:end].nil?
62
+ (target_range[:start].nil? && search_range[:start] < target_range[:end]) ||
63
+ (target_range[:end].nil? && search_range[:end] > target_range[:start])
64
+ else
65
+ (search_range[:start] >= target_range[:start] && search_range[:start] <= target_range[:end]) ||
66
+ (search_range[:end] >= target_range[:start] && search_range[:end] <= target_range[:end])
67
+ end
68
+ end
69
+ end
70
+
71
+ def validate_date_search(search_value, target_value)
72
+ if target_value.instance_of? FHIR::Period
73
+ validate_period_search(search_value, target_value)
74
+ else
75
+ validate_datetime_search(search_value, target_value)
76
+ end
77
+ end
78
+
79
+ def validate_datetime_search(search_value, target_value)
80
+ comparator = search_value[0..1]
81
+ if %w[eq ge gt le lt ne sa eb ap].include? comparator
82
+ search_value = search_value[2..-1]
83
+ else
84
+ comparator = 'eq'
85
+ end
86
+ search_is_date = is_date?(search_value)
87
+ target_is_date = is_date?(target_value)
88
+ search_range = get_fhir_datetime_range(search_value)
89
+ target_range = get_fhir_datetime_range(target_value)
90
+ fhir_date_comparer(search_range, target_range, comparator, !search_is_date && target_is_date,
91
+ !search_is_date && target_is_date)
92
+ end
93
+
94
+ def validate_period_search(search_value, target_value)
95
+ comparator = search_value[0..1]
96
+ if %w[eq ge gt le lt ne sa eb ap].include? comparator
97
+ search_value = search_value[2..-1]
98
+ else
99
+ comparator = 'eq'
100
+ end
101
+ search_is_date = is_date?(search_value)
102
+ search_range = get_fhir_datetime_range(search_value)
103
+ target_range = get_fhir_period_range(target_value)
104
+ fhir_date_comparer(search_range, target_range, comparator, !search_is_date && is_date?(target_value.start),
105
+ !search_is_date && is_date?(target_value.end))
106
+ end
107
+
108
+ def is_date?(value)
109
+ /^\d{4}(-\d{2})?(-\d{2})?$/.match?(value) # YYYY or YYYY-MM or YYYY-MM-DD
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,7 @@
1
+ require_relative 'primitive_type'
2
+
3
+ module PacioInfernoCore
4
+ # This functionality has been moved to Inferno Core, but this reference is
5
+ # retained to avoid a breaking change.
6
+ FHIRResourceNavigation = Inferno::DSL::FHIRResourceNavigation
7
+ end
@@ -0,0 +1,161 @@
1
+ require_relative 'naming'
2
+ require_relative 'special_cases'
3
+
4
+ module PacioInfernoCore
5
+ class Generator
6
+ class GroupGenerator
7
+ class << self
8
+ def generate(ig_metadata, base_output_dir)
9
+ ig_metadata.ordered_groups
10
+ .reject { |group| SpecialCases.exclude_group? group }
11
+ .each { |group| new(group, base_output_dir).generate }
12
+ end
13
+ end
14
+
15
+ attr_accessor :group_metadata, :base_output_dir
16
+
17
+ def initialize(group_metadata, base_output_dir)
18
+ self.group_metadata = group_metadata
19
+ self.base_output_dir = base_output_dir
20
+ end
21
+
22
+ def template
23
+ @template ||= File.read(File.join(__dir__, 'templates', 'group.rb.erb'))
24
+ end
25
+
26
+ def output
27
+ @output ||= ERB.new(template, trim_mode: '-').result(binding)
28
+ end
29
+
30
+ def naming
31
+ self.class.module_parent::Naming
32
+ end
33
+
34
+ def base_output_file_name
35
+ "#{class_name.underscore}.rb"
36
+ end
37
+
38
+ def base_metadata_file_name
39
+ 'metadata.yml'
40
+ end
41
+
42
+ def class_name
43
+ "#{naming.upper_camel_case_for_profile(group_metadata)}Group"
44
+ end
45
+
46
+ def module_name_with_version
47
+ "#{naming.module_name}#{group_metadata.reformatted_version.upcase}"
48
+ end
49
+
50
+ def title
51
+ group_metadata.title
52
+ end
53
+
54
+ def short_description
55
+ group_metadata.short_description
56
+ end
57
+
58
+ def output_file_name
59
+ File.join(base_output_dir, base_output_file_name)
60
+ end
61
+
62
+ def metadata_file_name
63
+ File.join(base_output_dir, profile_identifier, base_metadata_file_name)
64
+ end
65
+
66
+ def profile_identifier
67
+ naming.snake_case_for_profile(group_metadata)
68
+ end
69
+
70
+ def group_id
71
+ "#{naming.prefix}_#{group_metadata.reformatted_version}_#{profile_identifier}"
72
+ end
73
+
74
+ def resource_type
75
+ group_metadata.resource
76
+ end
77
+
78
+ def search_validation_resource_type
79
+ "#{resource_type} resources"
80
+ end
81
+
82
+ def profile_name
83
+ group_metadata.profile_name
84
+ end
85
+
86
+ def profile_url
87
+ group_metadata.profile_url
88
+ end
89
+
90
+ def optional?
91
+ SpecialCases::OPTIONAL_RESOURCES.include?(resource_type) || group_metadata.optional_profile?
92
+ end
93
+
94
+ def generate
95
+ add_special_tests
96
+ File.write(output_file_name, output)
97
+ group_metadata.id = group_id
98
+ group_metadata.file_name = base_output_file_name
99
+ File.write(metadata_file_name, YAML.dump(group_metadata.to_hash))
100
+ end
101
+
102
+ def add_special_tests; end
103
+
104
+ def test_id_list
105
+ @test_id_list ||=
106
+ group_metadata.tests.map { |test| test[:id] }
107
+ end
108
+
109
+ def test_file_list
110
+ @test_file_list ||=
111
+ group_metadata.tests.map do |test|
112
+ name_without_suffix = test[:file_name].delete_suffix('.rb')
113
+ name_without_suffix.start_with?('..') ? name_without_suffix : "#{profile_identifier}/#{name_without_suffix}"
114
+ end
115
+ end
116
+
117
+ def required_searches
118
+ group_metadata.searches.select { |search| search[:expectation] == 'SHALL' }
119
+ end
120
+
121
+ def search_param_name_string
122
+ required_searches
123
+ .map { |search| search[:names].join(' + ') }
124
+ .map { |names| "* #{names}" }
125
+ .join("\n")
126
+ end
127
+
128
+ def search_description
129
+ return '' if required_searches.blank?
130
+
131
+ <<~SEARCH_DESCRIPTION
132
+ ## Searching
133
+ This test sequence will first perform each required search associated
134
+ with this resource. This sequence will perform searches with the
135
+ following parameters:
136
+
137
+ #{search_param_name_string}
138
+
139
+ ### Search Parameters
140
+ The first search uses the selected patient(s) from the prior launch
141
+ sequence. Any subsequent searches will look for its parameter values
142
+ from the results of the first search. For example, the `identifier`
143
+ search in the patient sequence is performed by looking for an existing
144
+ `Patient.identifier` from any of the resources returned in the `_id`
145
+ search. If a value cannot be found this way, the search is skipped.
146
+
147
+ ### Search Validation
148
+ Inferno will retrieve up to the first 20 bundle pages of the reply for
149
+ #{search_validation_resource_type} and save them for subsequent tests. Each of
150
+ these resources is then checked to see if it matches the searched
151
+ parameters in accordance with [FHIR search
152
+ guidelines](https://www.hl7.org/fhir/search.html). The test will fail,
153
+ for example, if a Patient search for `gender=male` returns a `female`
154
+ patient.
155
+ SEARCH_DESCRIPTION
156
+ end
157
+
158
+ def description; end
159
+ end
160
+ end
161
+ end