Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 35 additions & 39 deletions input/fsh/operations.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -402,43 +402,55 @@ Description: "Execute a SQLQuery Library against ViewDefinition tables."
* parameter[3].targetProfile[1] = Canonical(SQLView)
* parameter[3].documentation = "Inline SQLQuery or SQLView Library resource to execute."

* parameter[4].name = #parameters
* parameter[4].name = #view
* parameter[4].use = #in
* parameter[4].min = 0
* parameter[4].max = "1"
* parameter[4].max = "*"
* parameter[4].scope[0] = #system
* parameter[4].scope[1] = #type
* parameter[4].scope[2] = #instance
* parameter[4].type = #Parameters
* parameter[4].documentation = "Input parameters for the query. Parameters are bound by name to parameters declared in the SQLQuery Library (Library.parameter.name). Parameter types are mapped using the appropriate value[x] type matching the declared parameter type."
* parameter[4].type = #CanonicalResource
* parameter[4].targetProfile[0] = Canonical(ViewDefinition)
* parameter[4].targetProfile[1] = Canonical(SQLView)
* parameter[4].documentation = "Inline ViewDefinition or SQLView Library supplying a table source the query depends on. Matched by its url (and version, when the depends-on canonical is versioned) to a relatedArtifact depends-on entry in the transitive dependency closure of the executed queries. See Table-Source Dependencies (operations-common.html)."

* parameter[5].name = #source
* parameter[5].name = #parameters
* parameter[5].use = #in
* parameter[5].min = 0
* parameter[5].max = "1"
* parameter[5].scope[0] = #system
* parameter[5].scope[1] = #type
* parameter[5].scope[2] = #instance
* parameter[5].type = #string
* parameter[5].documentation = "External data source containing the ViewDefinition tables."
* parameter[5].type = #Parameters
* parameter[5].documentation = "Input parameters for the query. Parameters are bound by name to parameters declared in the SQLQuery Library (Library.parameter.name). Parameter types are mapped using the appropriate value[x] type matching the declared parameter type."

* parameter[6].name = #_limit
* parameter[6].name = #source
* parameter[6].use = #in
* parameter[6].min = 0
* parameter[6].max = "1"
* parameter[6].scope[0] = #system
* parameter[6].scope[1] = #type
* parameter[6].scope[2] = #instance
* parameter[6].type = #integer
* parameter[6].documentation = "Maximum number of rows to return."
* parameter[6].type = #string
* parameter[6].documentation = "External data source containing the ViewDefinition tables."

// Output parameter
* parameter[7].name = #return
* parameter[7].use = #out
* parameter[7].min = 1
* parameter[7].name = #_limit
* parameter[7].use = #in
* parameter[7].min = 0
* parameter[7].max = "1"
* parameter[7].type = #Binary
* parameter[7].documentation = "Query results in the requested output format, returned as a raw binary stream in the format's native media type, not a serialized Binary resource envelope. When _format=fhir is requested, the response is a Parameters resource instead. See Common Operation Behavior (operations-common.html)."
* parameter[7].scope[0] = #system
* parameter[7].scope[1] = #type
* parameter[7].scope[2] = #instance
* parameter[7].type = #integer
* parameter[7].documentation = "Maximum number of rows to return."

// Output parameter
* parameter[8].name = #return
* parameter[8].use = #out
* parameter[8].min = 1
* parameter[8].max = "1"
* parameter[8].type = #Binary
* parameter[8].documentation = "Query results in the requested output format, returned as a raw binary stream in the format's native media type, not a serialized Binary resource envelope. When _format=fhir is requested, the response is a Parameters resource instead. See Common Operation Behavior (operations-common.html)."

Instance: SQLQueryExport
Usage: #definition
Expand Down Expand Up @@ -496,34 +508,18 @@ Description: "Export SQLQuery Library results asynchronously using the FHIR Asyn
* parameter[0].part[3].type = #Parameters
* parameter[0].part[3].documentation = "Input parameters for this query. Parameters are bound by name to parameters declared in the SQLQuery Library (Library.parameter.name)."

// Input parameters — ViewDefinitions as table sources (same structure as $viewdefinition-export)
// Input parameters — table-source dependencies supplied inline
* parameter[1].name = #view
* parameter[1].use = #in
* parameter[1].min = 0
* parameter[1].max = "*"
* parameter[1].scope[0] = #system
* parameter[1].scope[1] = #type
* parameter[1].documentation = "ViewDefinitions that serve as table sources for the SQL queries. Provides ViewDefinitions referenced in the Library's relatedArtifact entries. These are materialized as tables for the SQL to query against — they do not produce separate output entries."
* parameter[1].part[0].name = #name
* parameter[1].part[0].use = #in
* parameter[1].part[0].min = 0
* parameter[1].part[0].max = "1"
* parameter[1].part[0].type = #string
* parameter[1].part[0].documentation = "Optional friendly name for the ViewDefinition."
* parameter[1].part[1].name = #viewReference
* parameter[1].part[1].use = #in
* parameter[1].part[1].min = 0
* parameter[1].part[1].max = "1"
* parameter[1].part[1].type = #Reference
* parameter[1].part[1].targetProfile = Canonical(ViewDefinition)
* parameter[1].part[1].documentation = "Reference to a ViewDefinition stored on the server."
* parameter[1].part[2].name = #viewResource
* parameter[1].part[2].use = #in
* parameter[1].part[2].min = 0
* parameter[1].part[2].max = "1"
* parameter[1].part[2].type = #CanonicalResource
* parameter[1].part[2].targetProfile = Canonical(ViewDefinition)
* parameter[1].part[2].documentation = "Inline ViewDefinition resource."
* parameter[1].scope[2] = #instance
* parameter[1].type = #CanonicalResource
* parameter[1].targetProfile[0] = Canonical(ViewDefinition)
* parameter[1].targetProfile[1] = Canonical(SQLView)
* parameter[1].documentation = "Inline ViewDefinition or SQLView Library supplying a table source the query depends on. Matched by its url (and version, when the depends-on canonical is versioned) to a relatedArtifact depends-on entry in the transitive dependency closure of the executed queries. See Table-Source Dependencies (operations-common.html)."

// Input parameters — export control (from $viewdefinition-export)
* parameter[2].name = #clientTrackingId
Expand Down Expand Up @@ -672,7 +668,7 @@ Description: "Export SQLQuery Library results asynchronously using the FHIR Asyn
* parameter[19].use = #out
* parameter[19].min = 0
* parameter[19].max = "*"
* parameter[19].documentation = "Output information for each exported SQL query result. One entry per query; ViewDefinitions supplied via the view parameter do not produce output entries."
* parameter[19].documentation = "Output information for each exported SQL query result. One entry per query; resources supplied via the view parameter do not produce output entries."
* parameter[19].part[0].name = #name
* parameter[19].part[0].use = #out
* parameter[19].part[0].min = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ export pattern from [`$viewdefinition-export`](OperationDefinition-ViewDefinitio
**Key Features:**

- **Multiple queries** per export via the repeating `query` parameter — each with its own parameters
- **ViewDefinition table sources** via the `view` parameter — supply ViewDefinitions referenced in the Library's `relatedArtifact` entries (materialized as tables for SQL to query; only SQL query results appear in the export output)
- **Inline table-source dependencies** via the `view` parameter — supply ViewDefinitions or SQLViews referenced in the Library's `relatedArtifact` entries (materialized as tables for SQL to query; only SQL query results appear in the export output)
- **Per-query parameters** — each `query` repetition can have its own `parameters` resource
55 changes: 35 additions & 20 deletions input/pagecontent/OperationDefinition-SQLQueryExport-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,26 @@ At the instance level (`POST [base]/Library/[id]/$sqlquery-export`), the bound L

¹ Either queryReference or queryResource is required per `query` repetition.

##### ViewDefinition Table Sources — `view` Parameter (0..\*, system+type scope)
##### Table-Source Dependencies — `view` Parameter (0..\*, system, type and instance scope)

Provides ViewDefinitions that serve as table sources for the SQL queries. These are the ViewDefinitions referenced in the Library's `relatedArtifact` entries. ViewDefinitions supplied here are materialized as tables for the SQL to query against — they do **not** produce separate output entries. Only the SQL query results appear in the export output.
Supply table sources - ViewDefinitions or SQLView Libraries - inline through the
repeating `view` parameter. Each repetition carries one resource identified by
its `url`, matched against the `relatedArtifact` (`depends-on`) entries in the
transitive dependency closure of the executed queries. A supplied resource takes
precedence over a server-stored resource with the same canonical. Resources
supplied here are materialized as tables for the SQL to query against; they do
**not** produce separate `output` entries, so only the SQL query results appear
in the export output.

| Part Name | Type | Min | Max | Description |
| ------------- | --------- | --- | --- | -------------------------------------------------- |
| name | string | 0 | 1 | Optional friendly name for the ViewDefinition |
| viewReference | Reference | 0² | 1 | Reference to a ViewDefinition stored on the server |
| viewResource | Resource | 0² | 1 | Inline ViewDefinition resource |
| Name | Type | Min | Max | Description |
| ---- | ----------------- | --- | --- | ------------------------------------------------------------------------- |
| view | CanonicalResource | 0 | \* | Inline ViewDefinition or SQLView table source, bound by `url` and version |

{:.table-data}

² Either viewReference or viewResource is required per `view` repetition.
The full matching, precedence and error rules are defined once in
[Table-Source Dependencies](operations-common.html#table-source-dependencies)
and apply identically to `$sqlquery-run` and `$sqlquery-export`.

##### Export Control

Expand Down Expand Up @@ -277,7 +284,7 @@ the export is still in progress.

| Name | Type | Min | Max | Description |
| --------------- | ------- | --- | --- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| output | complex | 0 | \* | Output information for each exported SQL query result (one per `query`; ViewDefinitions supplied via `view` do not produce output entries) |
| output | complex | 0 | \* | Output information for each exported SQL query result (one per `query`; resources supplied via `view` do not produce output entries) |
| output.name | string | 1 | 1 | The name of the exported output. [Details](#output-name-clarification) |
| output.location | uri | 1 | \* | URL(s) to download the exported file(s). [Details](#output-partitioning) |

Expand Down Expand Up @@ -350,7 +357,8 @@ The $sqlquery-export operation uses standard HTTP status codes to indicate the o
| 303 See Other | Job Finished | Export finished (successfully or not); `Location` header carries the result URL |
| 200 OK | Result Available | Result URL returns the manifest `Parameters`; download URLs return the files |
| 400 Bad Request | Client Error | Invalid parameters, unsupported parameters, missing required headers |
| 404 Not Found | Not Found | SQLQuery Library not found, or cancelled export status URL |
| 400 Bad Request | Dependency Error | A supplied `view` resource has no `url`, its `url` matches no entry in any executed query's transitive dependency closure, or two supplied resources match the same dependency entry |
| 404 Not Found | Not Found | SQLQuery Library not found, cancelled export status URL, or a dependency neither supplied via `view` nor server-resolvable |
| 422 Unprocessable Entity | Business Logic Error | Valid request but query is invalid or cannot be executed |
| 429 Too Many Requests | Excessive Polling | Client is polling too frequently; back off exponentially, guided by `Retry-After` |
| 500 Internal Server Error | Server Error | Unexpected server error; on the result URL, the failure outcome of the export |
Expand Down Expand Up @@ -864,9 +872,14 @@ Prefer: respond-async
}
```

##### Multi-Query Export with ViewDefinition Table Sources
##### Multi-Query Export with Mixed Stored and Inline Sources

Export multiple queries in one operation, providing a ViewDefinition table source inline:
Export multiple stored queries in one operation, supplying one table source
inline via `view` while the remaining dependencies resolve on the server. The
supplied ViewDefinition's `url` matches a `relatedArtifact` canonical of one of
the queries and takes precedence over any server-stored resource with that
canonical (see
[Table-Source Dependencies](operations-common.html#table-source-dependencies)):

```http
POST /Library/$sqlquery-export HTTP/1.1
Expand Down Expand Up @@ -921,14 +934,16 @@ Prefer: respond-async
},
{
"name": "view",
"part": [
{
"name": "viewReference",
"valueReference": {
"reference": "ViewDefinition/UsCoreBloodPressures"
}
}
]
"resource": {
"resourceType": "ViewDefinition",
"url": "https://example.org/ViewDefinition/UsCoreBloodPressures",
"status": "active",
"resource": "Observation",
"select": [{ "column": [
{ "name": "id", "path": "getResourceKey()" },
{ "name": "systolic", "path": "component.where(code.coding.code='8480-6').value.ofType(Quantity).value" }
]}]
}
},
{
"name": "_format",
Expand Down
4 changes: 2 additions & 2 deletions input/pagecontent/OperationDefinition-SQLQueryRun-intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Execute a SQLQuery Library against ViewDefinition tables synchronously.

**Execution Flow:**

1. Resolve ViewDefinitions from `relatedArtifact`
2. Materialize each ViewDefinition as a table
1. Resolve the table sources named in `relatedArtifact` (ViewDefinitions and SQLViews), using any supplied inline via the `view` parameter and resolving the rest on the server
2. Materialize each table source as a table
3. Bind `parameters` values to SQL placeholders
4. Execute SQL query
5. Return results in requested format (Binary for flat formats, Parameters for `_format=fhir`)
Expand Down
Loading
Loading