Skip to content

Commit f502da4

Browse files
ljtuckerkarlnaden
andauthored
Add documentation for fhir_resource_validation (#102)
* Add documentation for fhir_resource_validation validator_response_details enhancement * Update docs/writing-tests/fhir-validation.md Co-authored-by: Karl Naden <86612928+karlnaden@users.noreply.github.com> --------- Co-authored-by: Karl Naden <86612928+karlnaden@users.noreply.github.com>
1 parent 513e96e commit f502da4

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

docs/writing-tests/fhir-validation.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ validation messages to the runnable.
5858

5959
You can optionally skip adding validation messages by setting `add_messages_to_runnable: false`.
6060

61+
The `validator_response_details` parameter allows you to capture the detailed validator output
62+
for custom processing. Pass an empty array, and it will be populated with all validation issues.
63+
See [Accessing Detailed Validation Results](#accessing-detailed-validation-results) for more information.
64+
6165
```ruby
6266
test do
6367
fhir_read(:patient, '123')
@@ -81,6 +85,15 @@ test do
8185
# Validate using a particular named validator
8286
if resource_is_valid?(validator: :my_customized_validator)
8387
end
88+
89+
# Capture detailed validation results for custom processing
90+
validation_details = []
91+
unless resource_is_valid?(validator_response_details: validation_details, add_messages_to_runnable: false)
92+
# Resource is invalid, analyze the detailed error information
93+
validation_details.select { |issue| issue.severity == 'error' }.each do |issue|
94+
add_message('error', issue.message) if issue_of_interest?(issue)
95+
end
96+
end
8497
end
8598
```
8699

@@ -127,6 +140,8 @@ end
127140
```
128141

129142
## Performing Additional Validation
143+
144+
### Custom Validation Logic
130145
If you want to perform validation steps in addition to the FHIR validation,
131146
you can use the `perform_additional_validation` method in the validator definition. The method
132147
can also be used multiple times in a single validator definition to add multiple
@@ -146,6 +161,29 @@ fhir_resource_validator do
146161
end
147162
```
148163

164+
### Accessing Detailed Validation Results
165+
The `validator_response_details` parameter provides access to the complete validation output
166+
from the validator service, including both filtered and unfiltered issues. This is useful when
167+
you need to perform custom analysis, present validation results differently, or implement
168+
conditional logic based on specific validation patterns.
169+
170+
When you pass an empty array to `validator_response_details`, it will be populated with validator
171+
issue objects that contain the full formatted response from the validator service. Each issue
172+
includes a `filtered` flag that indicates whether the issue would have been excluded by default
173+
filtering rules (such as those defined by `exclude_message`).
174+
175+
#### Validator Issue Structure
176+
Each validator issue object in the `validator_response_details` array contains:
177+
178+
- **`message`** (String): The formatted validation message, including location information
179+
- **`severity`** (String): The severity level - `'error'`, `'warning'`, or `'info'`
180+
- **`location`** (String): The location in the resource where the issue was found
181+
- **`filtered`** (Boolean): Whether this issue would be filtered out by default exclusion rules
182+
- **`slice_info`** (Array): Nested validator issues/information (each with the same structure);
183+
typically provide details of the base-level issue, including any sub-errors or warnings
184+
- **`resource`** (FHIR::Model): The resource being validated
185+
- **`raw_issue`** (Hash): The complete raw issue hash from the validator service
186+
149187
# MustSupport Test using the Evaluator
150188

151189
Checking the presence of Must Support elements is a common feature across test kits and

0 commit comments

Comments
 (0)