API
GoFSH exposes a fhirToFsh
function that can be used to convert FHIR to FSH.
Syntax
fhirToFsh(fhir[, options])
Parameters
fhir
- An array of FHIR resources, represented either as strings or JSON.
options
- An object which can have any combindation of the following attributes:
dependencies
- An array of strings used to specify dependencies required for processing the FHIR. Dependencies should use the format<packageId>@<version>
(example:hl7.fhir.us.core@3.0.1
).logLevel
- A string that specifies what level of logging to use when processing FHIR. Options aresilent
,debug
,info
,warn
, anderror
.style
- A string representing how the returned output is styled. The options are:-
string
- The generated FSH will be returned in one single string. This is the default. -
map
- The generated FSH will be returned as an object. The attributes on the object are:aliases
- A string containing allAlias
definitions.profiles
- AMap
containing allProfile
definitions as values.extensions
- AMap
containing allExtension
definitions as values.codeSystems
- AMap
containing allCodeSystem
definitions as values.valueSets
- AMap
containing allValueSet
definitions as values.instances
- AMap
containing allInstance
definitions as values.invariants
- AMap
containing allInvariant
definitions as values.mappings
- AMap
containing allMapping
definitions as values.
For each
Map
, the keys are the name of the FSH definition. For example, if the definition was:Profile: MyPatient Parent: Patient
The key would be
MyPatient
.
-
Return Value
A Promise
that resolves to an object with the following attributes:
fsh
- The generated FSH, styled according to thestyle
parameter.configuration
- An object representing thesushi-config.yaml
file that would be generated if GoFSH was running in a command line interface.errors
- An array of strings containing any errors detected during processing.warnings
- An array of strings containing any warnings detected during processing.
Usage
To use fhirToFsh
, you must first install gofsh
as a dependency of your project:
npm install gofsh
Once gofsh
is installed as a dependency of your project, you can import
and use this function as shown:
import { gofshClient } from 'gofsh';
// Example basic usage
gofshClient
.fhirToFsh(['{ Your FHIR here }'])
.then((results) => {
// handle results
})
.catch((err) => {
// handle thrown errors
});
// Example usage with options
gofshClient
.fhirToFsh(['{ Your FHIR here }'], {
dependencies: ["hl7.fhir.us.mcode@1.0.0"],
style: "map",
logLevel: "silent",
})
.then((results) => {
// handle results
})
.catch((err) => {
// handle thrown errors
});