smart-on-fhir / client-js

JavaScript client for FHIR
Other
292 stars 209 forks source link

resolveReferences does not propagate the request options #184

Closed shauntan-synapxe closed 1 month ago

shauntan-synapxe commented 2 months ago

Describe the bug Our FHIR server is customized to require an additional request header for every request. When using client.request() we can do something like below:

    const fetchProps = {
      url: `${resourceType}/${resourceId}`,
      method: 'GET',
      headers: {
        'X-Custom-Header': 'someCustomKey',
      },
    };

    const response = await client.request(fetchProps, {
      resolveReferences: ['someReferences'],
    });

The initial call would be fine, however the subsequent call to resolve the references does not propagate the header.

To Reproduce For example, I have an AllergyIntolerance record in my FHIR server which references to a Patient resource.

    const fetchProps = {
      url: `AllergyIntolerance/${resourceId}`,
      method: 'GET',
      headers: {
        'X-Custom-Header': 'someCustomKey',
      },
    };

    const response = await client.request(fetchProps, {
      resolveReferences: ['patient'],
    });

The FhirClient would GET the AllergyIntolerance record with the custom request header, it then follow-up with another GET to retrieve the referenced Patient record. However, the follow-up reference GET does not pass in the custom request header.

Expected behavior Please propagate the request headers when performing additional fetch when resolving references.

Client-side (please complete the following information):

Server-side (please complete the following information): Not relevant.

Additional context N/A

vlad-ignatov commented 1 month ago

A fix is included in fhirclient@2.5.4. Feel free to reopen if it doesn't work. Thank you!