microsoft / microsoft/fhir-server
Support _skip parameter for pagination
Nobody has claimed this yet.
- Dominant language
- TSQL
- Stars
- 1.4k
- Forks
- 592
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 41
Description
Paging with FHIR server currently uses a continuation token which is not meant to be directly manipulated by the client. This limits traditional paging GUIs other than an infinite scrolling list.
Ideally it should look something like below:
```
first page: Patient
second page: Patient?_skip=10
third page: Patient?_skip=20
```
I created a POC to enable this for the SQL Server provider. Please have a look.
https://github.com/almostchristian/fhir-server/tree/fhir/paging
The change involves converting the usages of `TOP` into `OFFSET`
```sql
SELECT DISTINCT T1, Sid1, 1 AS IsMatch, 0 AS IsPartial
FROM cte1
ORDER BY Sid1 ASC
OFFSET (@p4) ROWS
FETCH NEXT @p5 ROWS ONLY
```
A lot of change had to be done to support sorting, which is still tricky. Since sorting can happen in two phases, the skip parameter in the POC resets when the second phase starts. I denote the second phase with a hyphen in the skip parameter,
The search urls when sorting is involved can look like below. In here, repurposed `ct` as the skip parameter.
```
1st page: Patient?_sort=family&_count=2
2nd page: Patient?_sort=family&_count=2&ct=2
3rd page: Patient?_sort=family&_count=2&ct=-1
4th page: Patient?_sort=family&_count=2&ct=-3
```
Since I am currently working with a fork of FHIR server, I plan to go introduce this to our implementation. The sorting issue is a bummer, but I don't think this can be avoided without a big redesign. I'd like to hear feedback on this implementation. The E2E integration tests all pass, but I'm not sure if there is some edge cases not covered in the integration tests that could break this.
In terms of performance, the generated query plan is the same with the original, but the OFFSET version seems to be heavier compared to the TOP version outside of the first page, but I'd need to do proper testing on a large db.
AB#105830
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the SQL Server provider's pagination and query-generation paths, then compare the POC branch with the existing E2E integration tests. Define how _skip should behave across normal and two-phase sorted searches, including continuation-token compatibility. Done means the behavior is specified, edge cases are covered by tests, and performance has been evaluated on a representative database.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql
- Domain
- api, backend, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100