-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added $capabilities() function (#62)
- Loading branch information
1 parent
91a52cc
commit 977600a
Showing
4 changed files
with
33 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* © Copyright Outburn Ltd. 2022-2024 All Rights Reserved | ||
* Project name: FUME-COMMUNITY | ||
*/ | ||
import { getFhirClient } from '../fhirServer'; | ||
import thrower from '../thrower'; | ||
|
||
// cached copy of the capability statement resource | ||
let capabilityStatement: Record<string, any | any[]> = {}; | ||
|
||
export const capabilities = async (): Promise<Record<string, any> | undefined> => { | ||
// check if capability statement cached copy is empty | ||
if (Object.keys(capabilityStatement).length === 0) { | ||
// try to fetch from server | ||
try { | ||
capabilityStatement = await getFhirClient().read('metadata'); | ||
} catch (error) { | ||
return thrower.throwRuntimeError(`Failed to fetch CapabilityStatement from FHIR server. ${JSON.stringify(error)}`); | ||
} | ||
}; | ||
// check that the object is actually a capability statement | ||
if (!capabilityStatement?.resourceType || typeof capabilityStatement.resourceType !== 'string' || capabilityStatement.resourceType !== 'CapabilityStatement') { | ||
return thrower.throwRuntimeError('Invalid response from FHIR server: The \'/metadata\' endpoint did not return a CapabilityStatement resource'); | ||
}; | ||
// return the cached capability statement | ||
return capabilityStatement; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters