FHIR De-Identification SDK

Profile-preserving FHIR R4 de-identification SDK generated from the De-Identification IG. All SDKs.

License: Apache-2.0. Licensor: cognovis GmbH.

Install

.npmrc
@cognovis:registry=https://npm.cognovis.de
npm install @cognovis/fhir-deidentification-sdk

Worked example

Anonymize one Patient for export

deidentify.mjs
import {
  anonymousExport,
  createAnonymousExportContext,
  transform,
} from '@cognovis/fhir-deidentification-sdk';

const patient = {
  resourceType: 'Patient',
  id: 'example',
  name: [{ family: 'Mustermann', given: ['Erika'] }],
  birthDate: '1964-08-12',
  address: [{ city: 'Berlin', postalCode: '10115' }],
};

// The SDK validates the resource against the profile before and
// after the transform. Plug in your FHIR validator here; this one
// only checks the resource type.
const validate = (resource) => ({ valid: resource.resourceType === 'Patient' });

const context = createAnonymousExportContext();
try {
  const result = transform(patient, anonymousExport(), {
    profile: 'http://hl7.org/fhir/StructureDefinition/Patient',
    validate,
    anonymousExportContext: context,
  });
  console.log(result.classification, JSON.stringify(result.resource));
} finally {
  context.destroy();
}
node deidentify.mjs

Entry points

Notice

Cognovis De-Identification IG for German Practice Data
Copyright 2026 cognovis GmbH

This product includes material developed by cognovis GmbH.

Cognovis-authored material from version 0.12.0 onward is licensed under the
Apache License, Version 2.0. Published versions through 0.11.24 remain
available under their original CC-BY-4.0 grants. Dependency and third-party
material is not relicensed; see THIRD_PARTY_NOTICES.md.

README

The README below is the one published in @cognovis/fhir-deidentification-sdk 0.17.2. @cognovis/fhir-deidentification-sdk installs without a token: https://npm.cognovis.de serves the @cognovis scope anonymously, and the .npmrc scope line above is all an install needs, whatever the README says about credentials.

@cognovis/fhir-deidentification-sdk

Profile-preserving de-identification of FHIR R4 resources for German outpatient care, in TypeScript.

The SDK is generated from the cognovis De-Identification Implementation Guide. It applies the guide's PII field catalogue (Library/pii-fields-manifest), its free-text scrub patterns (Library/scrub-patterns) and its generalization methods (Library/generalize-methods) to a resource and returns a resource of the same profile. Identifiers and references are replaced consistently, dates are shifted or generalized, and catalogued free text is scrubbed or redacted. Under the anonymous export policy, data the catalogue does not describe is never passed through unchanged.

The package has no runtime dependencies and makes no network calls. It runs on Node.js 20 or later and on Bun.

Install

The package is on the cognovis npm registry. Installing needs no account and no token. Point the @cognovis scope at the registry in your project's .npmrc:

@cognovis:registry=https://npm.cognovis.de

Then install:

npm install @cognovis/fhir-deidentification-sdk

Example

Save this as deidentify.mjs in the project:

// deidentify.mjs
import {
  anonymousExport,
  createAnonymousExportContext,
  transform,
} from '@cognovis/fhir-deidentification-sdk';

const patient = {
  resourceType: 'Patient',
  id: 'example',
  name: [{ family: 'Mustermann', given: ['Erika'] }],
  birthDate: '1964-08-12',
  address: [{ city: 'Berlin', postalCode: '10115' }],
};

// The SDK validates the resource against the profile before and
// after the transform. Plug in your FHIR validator here; this one
// only checks the resource type.
const validate = (resource) => ({ valid: resource.resourceType === 'Patient' });

const context = createAnonymousExportContext();
try {
  const result = transform(patient, anonymousExport(), {
    profile: 'http://hl7.org/fhir/StructureDefinition/Patient',
    validate,
    anonymousExportContext: context,
  });
  console.log(JSON.stringify({ classification: result.classification, resource: result.resource }, null, 2));
} finally {
  context.destroy();
}

Run it:

node deidentify.mjs

The output is labelled ANONYED. The id is replaced, the name is redacted, the birth date becomes the first year of its five-year band and the postal code is shortened. The example data is synthetic.

Policies

transform(resource, policy, context) takes one of two policies:

  • anonymousExport() (ANONYED) removes or replaces everything the catalogue marks as identifying. Create one context with createAnonymousExportContext() per export, pass it with every resource of that export so references stay consistent across resources, and call context.destroy() in a finally block. Destroying the context erases its secret and its mappings.
  • developmentPseudonymized(vpnLookupIdentifier?) (PSEUDED) produces pseudonymized data for development and test systems. It needs a caller-held pseudonymizationKey (a Uint8Array) in the context. Pseudonymized data is still personal data.

Every call needs a profile and a validate function in the context; the SDK validates the resource before and after the transform.

Entry points

The package exports one ES module entry, @cognovis/fhir-deidentification-sdk, with TypeScript declarations:

Export Purpose
transform De-identify one resource or Bundle under a policy
anonymousExport, developmentPseudonymized Create a policy
createAnonymousExportContext Create the per-export state for anonymousExport
collectKnownValues Collect a patient's name values to scrub them from the patient's other resources (knownValues in the context)
cryptoHash, randomToken, redactValue, shiftDate, generalizeBirthDate, generalizePostalCode The individual de-identification methods
piiManifest, scrubPatterns, generalizeMethods The generated catalogues from the Implementation Guide
semanticClassifications The PSEUDED and ANONYED labels
DeidentificationError The typed error; its code names the reason, never an identifying value

Types such as FhirResource, DeidentificationPolicy, TransformContext and DeidentificationResult are exported as well.

The TypeScript SDK contract in the Implementation Guide describes the profile, graph and policy boundaries in detail.

Licence

Licensed under the Apache License 2.0. The licensor is cognovis GmbH; see NOTICE. The generated catalogues reference third-party terminologies by system and code only; their terms are listed in THIRD_PARTY_NOTICES.md.