Terminology Server Store
The TerminologyServerStore exposes the following properties:
- url
- fetchTerminologyCallback
- requestTimeoutMs
Here's how you use the store hook in your React functional component:
import { useTerminologyStore } from '@aehrc/smart-forms-renderer';
function App() {
const storeProperty = useTerminologyStore.use.{insert_property_name_here}();
return (
<div>{storeProperty}</div>
);
}
There are some live examples on the following pages that demonstrate how to use the hooks.
Supplying your own terminology transport
By default the renderer makes its terminology requests (ValueSet/$expand, ValueSet/$validate-code
and CodeSystem/$lookup) with the built-in fhirclient
transport. If you are hosting the renderer somewhere that transport does not suit, React Native for
example, or you need to add authentication headers or your own caching, supply a
fetchTerminologyCallback once at startup and every terminology request will go through it instead:
import { terminologyServerStore } from '@aehrc/smart-forms-renderer';
import type { FetchTerminologyCallback } from '@aehrc/smart-forms-renderer';
const fetchTerminologyCallback: FetchTerminologyCallback = async (query, requestConfig) => {
const { terminologyServerUrl } = requestConfig;
const baseUrl = terminologyServerUrl.endsWith('/')
? terminologyServerUrl
: `${terminologyServerUrl}/`;
// Some callers pass an absolute URL, so only prefix the server URL for a relative query
const requestUrl = /^https?:\/\//.test(query) ? query : `${baseUrl}${query}`;
const response = await myHttpClient.get(requestUrl);
return response.json();
};
terminologyServerStore.getState().setRequestOptions({
fetchTerminologyCallback,
requestTimeoutMs: 20000
});
query is the request relative to the terminology server, for example
ValueSet/$expand?url=http://example.com/ValueSet/test, though it can also be an absolute URL. The
callback must resolve with the parsed JSON body and reject on a transport or HTTP error. This is the same callback shape
@aehrc/sdc-populate's populateQuestionnaire() accepts, so one implementation can serve both.
requestTimeoutMs sets how long a value set expansion may take during form build before it is
abandoned, which defaults to 5000. It applies only to the batch $expand of answerValueSet
bindings; $validate-code and CodeSystem/$lookup are not timed. Raise it for slower networks such
as mobile. It must be a positive, finite number; any other value is ignored with a console warning.
Both options are optional and independent: leaving fetchTerminologyCallback unset keeps the built-in
transport. setRequestOptions() only changes the options you pass. Passing fetchTerminologyCallback
as null or undefined clears it and restores the built-in transport, and resetRequestOptions() puts
both back to their defaults. Unlike the terminology server URL, which buildForm() resets on every
build, these options persist across buildForm() calls, so set them once at startup.
Refer to the API Reference for more information on each property.