## replaceQueryVariables() function

Replaces prefetch query variables with values from the context or user profile.

A prefetch token is a placeholder in a prefetch template that is *replaced by information from the hook's context* to construct the FHIR URL used to request the prefetch data.

Prefetch tokens MUST be delimited by `{{` and `}}`, and MUST contain only the qualified path to a hook context field or one of the following user identifiers: `userPractitionerId`, `userPractitionerRoleId`, `userPatientId`, or `userRelatedPersonId`.

Note that the spec says:

Individual hooks specify which of their `context` fields can be used as prefetch tokens. Only root-level fields with a primitive value within the `context` object are eligible to be used as prefetch tokens. For example, `{{context.medication.id}}` is not a valid prefetch token because it attempts to access the `id` field of the `medication` field.

Unfortunately, many CDS Hooks services do not follow this rule. Therefore, this implementation allows access to nested fields.

**Signature:**

```typescript
export declare function replaceQueryVariables(user: CdsUserResource, context: Record<string, unknown>, query: string): string;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| user | [CdsUserResource](/content/docs/sdk/core.cdsuserresource) | The user resource. |
| context | Record<string, unknown> | The CDS request context. |
| query | string | The prefetch query template. |

**Returns:**

string

The prefetch query with variables replaced.
