Documentation Index
Fetch the complete documentation index at: https://mintlify.com/dhanyasukumaran1/fhir_query_validator/llms.txt
Use this file to discover all available pages before exploring further.
FHIRQueryValidator gives you a structured way to check FHIR R4 REST API query strings before they reach a server. Instead of discovering malformed queries through HTTP errors at runtime, you validate them in your application code, collect structured error and warning messages, and decide how to proceed. This guide walks through creating a validator instance, inspecting results, and integrating validation into real application workflows.
Create a validator instance
ImportFHIRQueryValidator and instantiate it once. The instance is reusable across requests and stores no per-query state.
Validate a single query
Callvalidate_query() with a FHIR search query string. The string should include the resource type and all search parameters, formatted as you would append them to a FHIR base URL.
validate_query() always returns a ValidationResult object—it never raises an exception for an invalid query. The result object tells you whether the query is valid and, if not, what is wrong.
Work with ValidationResult
is_valid
bool — True when the query has no errors. Warnings may still be present.errors
list[str] — Descriptions of every structural or semantic problem that makes the query invalid.warnings
list[str] — Descriptions of issues that do not invalidate the query but may produce unexpected results.Format error messages for display
When surfacing validation feedback to users or logs, join errors and warnings into a single readable block:Integrate validation into a query-building function
A common pattern is to validate a query immediately after constructing it and raise a descriptive error before dispatching it to a FHIR server:This pattern is most useful when query parameters come from user input or configuration. If you build static queries at development time, prefer catching errors in tests rather than in production error paths.
Validate a batch of queries
When you need to validate multiple queries at once—for example, during a startup check or a test suite—usevalidate_batch(). It accepts a list of query strings and returns a list of ValidationResult objects in the same order.
Explore supported resources and parameters
FHIRQueryValidator exposes the complete list of FHIR R4 resources and search parameters it understands. Use these to programmatically check whether a resource or parameter is supported before constructing a query.
- Supported resources
- Supported search parameters
Real-world example: validate before sending to a FHIR server
The following example shows a complete integration: build a query, validate it, log any warnings, and only proceed to the HTTP request if the query is valid.Build the query string
Construct the full FHIR search query, including resource type and all parameters.
Validate before sending
Call
validate_query() and check result.is_valid. Never send an invalid query to the server.Log warnings
Even when
is_valid is True, log any result.warnings so you can catch queries that might return unexpected results.