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 are- silent,- debug,- info,- warn, and- error.
- 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 all- Aliasdefinitions.
- profiles- A- Mapcontaining all- Profiledefinitions as values.
- extensions- A- Mapcontaining all- Extensiondefinitions as values.
- codeSystems- A- Mapcontaining all- CodeSystemdefinitions as values.
- valueSets- A- Mapcontaining all- ValueSetdefinitions as values.
- instances- A- Mapcontaining all- Instancedefinitions as values.
- invariants- A- Mapcontaining all- Invariantdefinitions as values.
- mappings- A- Mapcontaining all- Mappingdefinitions as values.
 For each Map, the keys are the name of the FSH definition. For example, if the definition was:Profile: MyPatient Parent: PatientThe key would be MyPatient.
 
- 
Return Value
A Promise that resolves to an object with the following attributes:
- fsh- The generated FSH, styled according to the- styleparameter.
- configuration- An object representing the- sushi-config.yamlfile 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
  });