Skip to content

Rewrite DocumentReference URLs to the export base url, not the default base URL #72

@jtmarmon

Description

@jtmarmon

Attachment URLs currently point at the configured "base URL" of the FHIR server:

// Rewrite urls in DocumentReference resources. Only url props
// that begin with `/files/` will be converted to absolute HTTP
// URLs to allow the client to directly download bigger files
if (row.resource_json.resourceType == "DocumentReference") {
const url = getPath(row.resource_json, "content.0.attachment.url");
if (url && url.search(/\/attachments\/.*/) === 0) {
row.resource_json.content[0].attachment.url = buildUrlPath(
baseUrl,
base64url.encode(JSON.stringify({
err : sim.err || "",
secure: !!sim.secure
})),
"fhir",
url
);
}
}
}

However, in practice the real Base URL for this server can change based on the parameters one inputs into https://bulk-data.smarthealthit.org/

This means that the attachment URLs are pointing at a different FHIR Base URL than the FHIR server that you initiate export from. For example, this is the URL generated from the website:
https://bulk-data.smarthealthit.org/eyJlcnIiOiIiLCJwYWdlIjoxMDAwMDAsImR1ciI6MTAsInRsdCI6MTUsIm0iOjEsInN0dSI6MywiZGVsIjowfQ/fhir
and this is the URL that the attachments point at:
https://bulk-data.smarthealthit.org/eyJlcnIiOiIiLCJzZWN1cmUiOnRydWV9/fhir/attachments/DICOM.jpg

Because these looks to a naive piece of code like different FHIR servers, it's generally not safe to send your SMART authentication token to this server. Many FHIR servers host their images on external image servers like S3, and you wouldn't want to give external servers your token, so our code specifically does not send an authentication token to attachment URLs that aren't hosted on the same FHIR server.

Would it be possible to dynamically rewrite this URL to point to the same URL as the one the export came from, rather than the default configured one?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions