FHIR's Bulk Data Access ($export) hands you a whole population of resources
as newline-delimited JSON (NDJSON) files. Because assembling those files can take
minutes, the operation is asynchronous: a client kicks it off, polls until the
server is done, then downloads the files the server lists.
This kata is the offline, deterministic version of Batch-1 Day 19, Assignment 24
(Topic 20.5.2, FHIR Bulk Data $export). You model the three steps of the async
request pattern against captured HttpResponse values β no sockets, no clock.
$export patternGETs [base]/Patient/$export. A successful kickoff
returns 202 Accepted with a Content-Location header whose value is the
status (poll) URL. The response has no useful body yet.GETs the status URL:
202 Accepted β still in progress; wait and poll again.200 OK β export complete; the body is the manifest.output array. Each entry
describes one produced file: a type and a url pointing at an NDJSON file.
The client downloads every url, in the order listed.A manifest looks like:
{
"transactionTime": "2024-01-01T00:00:00Z",
"request": "https://ex/fhir/Patient/$export",
"requiresAccessToken": true,
"output": [
{ "type": "Patient", "url": "http://ex/Patient.ndjson" },
{ "type": "Observation", "url": "http://ex/Observation.ndjson" }
],
"error": []
}
Implement BulkExport with:
static String kickoff(HttpResponse response) β return the Content-Location
header value. If the status is not 202, or the header is missing, throw
IllegalStateException.static List<String> pollUntilComplete(Iterator<HttpResponse> polls) β consume
responses in order:
202 β still in progress; move on to the next response.200 β complete; parse the manifest body and return the url of every object
in the output array, in document order.IllegalStateException.200 arrives β throw IllegalStateException.The provided nested HttpResponse type is already implemented (constructor, plus
status(), header(name) with case-insensitive lookup, and body()); leave it
as-is. Do not add a JSON library β extract the urls with java.util.regex, e.g.
the pattern "url"\s*:\s*"([^"]*)".
Sign up to Exercism to learn and master FHIR with 9 exercises, and real human mentoring, all for free.