> For the complete documentation index, see [llms.txt](https://docs.b2ihealthcare.com/snow-owl/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.b2ihealthcare.com/snow-owl/rest-apis/fhir/content-management.md).

# Content management

## FHIR Packages

Snow Owl implements the `$load-package` operation to import terminology resources from a [FHIR NPM package](https://hl7.org/fhir/packages.html). A package can be downloaded from a registry or uploaded as a local `.tgz` archive.

The operation currently supports the same terminology-related resource types as individual requests mentioned elsewhere in the documentation:

* `CodeSystem`
* `ValueSet`
* `ConceptMap`

All other package content is ignored.

{% hint style="warning" %}
Package dependency resolution is not currently implemented. Import prerequisites separately before importing resources that refer to them.
{% endhint %}

### Package structure

The input must be a gzip-compressed tar archive (`.tgz`), that follows the FHIR package layout:

```
package/
├─── package.json
├─── CodeSystem*.json
├─── ValueSet*.json
└─── ConceptMap*.json
```

The loader reads these properties from `package.json`:

* `name`
* `version`
* `fhir-version-list`

`fhir-version-list` must contain **exactly one** FHIR version. Packages that omit the property or declare multiple FHIR versions are rejected.

The loader processes resources in the following order:

1. `CodeSystem`
2. `ValueSet`
3. `ConceptMap`

This allows value sets and concept maps to refer to resources imported before them in the same request.

## Operations

### $load-package

The request accepts local uploads as well as registry locations to download from, depending on the content type:

<table><thead><tr><th width="208.6666259765625">Mode</th><th width="251.333251953125">Request input</th><th>Package source</th></tr></thead><tbody><tr><td><a href="#load-from-a-registry">Load from registry</a></td><td>FHIR JSON or XML <code>Parameters</code> resource</td><td>Package name, version and registry as indicated by request parameters</td></tr><tr><td><a href="#upload-a-package">Upload a package</a></td><td>Multipart form-data with attachment</td><td>Archive uploaded as part of the request</td></tr></tbody></table>

The operation responds with a `Parameters` resource to indicate success or failure.

#### Load from a registry

```http
POST /fhir/$load-package
Content-Type: application/fhir+json
Accept: application/fhir+json

{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "name",
      "valueString": "hl7.fhir.r4.core"
    },
    {
      "name": "version",
      "valueString": "4.0.1"
    }
  ]
}
```

If no registry parameter is added, Snow Owl uses `https://packages.fhir.org` by default.

The final artifact URL is assembled from the registry and package coordinates. In the example above, the package `hl7.fhir.r4.core` version `4.0.1` will be requested from `https://packages.fhir.org/hl7.fhir.r4.core/4.0.1`.

The implementation considers the following operation parameters:

<table><thead><tr><th width="126.666748046875">Name</th><th width="153">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>name</code></td><td>string</td><td>Package name</td></tr><tr><td><code>version</code></td><td>string</td><td>Package version</td></tr><tr><td><code>registry</code></td><td>URI</td><td>Registry base URL</td></tr><tr><td><code>resourceUrl</code></td><td>URI (repeatable)</td><td>Restrict import to resources where the canonical URL matches an entry in the list</td></tr></tbody></table>

If a downloaded package declares a `name` or `version` different from the requested values, the request fails.

#### Upload a package

```http
POST /fhir/$load-package?resourceUrl=http://hl7.org/fhir/abstract-types

Content-Type: multipart/form-data; boundary=boundary123
Accept: application/fhir+json

--boundary123
Content-Disposition: form-data; name="file"; filename="package.tgz"
Content-Type: application/gzip

<package contents>
--boundary123--
```

The query parameter `resourceUrl` may be supplied multiple times to select resources by canonical URL. If omitted, all recognized resources are considered for import.

The uploaded archive as form parameter `file` is stored temporarily as an attachment, copied to Snow Owl's `fhir-packages` data directory for processing, and is removed at the end of the import process.

#### Common request headers

Both modes support the following Snow Owl headers:

<table><thead><tr><th width="209.6666259765625">Header</th><th>Description</th></tr></thead><tbody><tr><td><code>X-Author</code></td><td>User identifier recorded as the change author</td></tr><tr><td><code>X-Owner</code></td><td>Resource owner; if omitted, the normal Snow Owl owner fallback behavior applies</td></tr><tr><td><code>X-Owner-Profile-Name</code></td><td>User profile name stored in resource settings for client use</td></tr><tr><td><code>X-Effective-Date</code></td><td>Default effective date used when an imported resource has a version but no corresponding effective date; format: <code>YYYY-MM-DD</code></td></tr><tr><td><code>X-Bundle-Id</code></td><td>Parent bundle identifier; defaults to the root bundle if omitted</td></tr></tbody></table>

#### Resources deliberately skipped

The FHIR package loader skips the following code systems because Snow Owl treats them as terminology standards with dedicated support elsewhere:

* SNOMED CT with URL `http://snomed.info/sct`
* LOINC with URL `http://loinc.org`
* ICD-10 and variants with URLs beginning with `http://hl7.org/fhir/sid/icd-10`

#### Import behavior

A package may declare a code system as `content = complete` while containing no concepts. To tolerate this inconsistency, the loader changes its `content` property to `not-present` before importing the resource.

Value sets are imported after code systems. Value sets where the required terminology references can not be resolved will be skipped (and logged).

Concept maps are imported after code systems and value sets. If referenced source or target code systems cannot be resolved, the affected concept map is skipped and the failure is logged.

If an imported resource does not declare its own `version` property, Snow Owl assigns the package version value from `package.json`.

#### Response

A successful request returns a FHIR `Parameters` resource indicating the number of resources that were imported successfully (i.e. not skipped):

```json
{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "success",
      "valueBoolean": true
    },
    {
      "name": "numberOfLoadedCodeSystems",
      "valueInteger": 3
    },
    {
      "name": "numberOfLoadedValueSets",
      "valueInteger": 0
    },
    {
      "name": "numberOfLoadedConceptMaps",
      "valueInteger": 1
    }
  ]
}
```

#### Failure cases

The operation returns a `400 Bad Request` error when, among other cases:

* neither a package upload nor package coordinates are provided;
* both an uploaded package and registry package coordinates are provided;
* the package cannot be downloaded from the selected registry;
* the input is not a readable archive;
* `package/package.json` descriptor is missing;
* `package.json` has no `fhir-version-list` property;
* `fhir-version-list` contains more than one value;
* the package contains no recognized `CodeSystem`, `ValueSet`, or `ConceptMap` files;
* the downloaded package `name` or `version` does not match the requested package information.

Where possible, resource-level import failures are logged and the affected resource is skipped, which allows importing the rest of the package's contents.
