@synanetics/fhir-transform
v0.9.1
Published
Perform FHIR $transform operations
Maintainers
Keywords
Readme
FHIR Transform Package
Performs FHIR $transform operations
Features
Interprets FHIR StructureMaps and applies their transformations to the input parameter(s), performing cardinality corrections against a supplied StructureDefinition. The output resource(s) are explicitly not validated against the supplied StructureDefinition(s), as per the FHIR specifications.
Example usage
import transform from '@synanetics/fhir-transform';
const structureMap = {
// structureMap FHIR resource
};
const content = {
// source resource
};
// your structureDefinitionResolver can be as elaborate as you like, perhaps returning from a URL or a cache
const structureDefinitionResolver = async (url: string): Promise<any> => {
switch (url) {
case 'http://example.com/StructureDefinition/CustomResource':
return {
// profile definition
};
// whatever else
}
};
// Your conceptMapResolver can be elaborate too, but needs to return the URL as the key object key.
// This is done so that you can choose to "follow" links to other ConceptMaps that may exist inside the
// first ConceptMap returned by the resolver.
const conceptMapResolver = async (url: string): Promise<Record<string, any>> => {
const record: Record<string, any> = {};
const map = await fetch(url);
record[url] = await map.json();
if (map.group[0].unmapped?.url) {
const otherMap = await fetch(map.group[0].unmapped.url);
record[map.group[0].unmapped.url] = await otherMap.json();
}
};
// the structureMapResolver works exactly the same as the conceptMapResolver, so is not shown here.
const result = await transform({
content,
structureMap,
structureDefinitionResolver,
conceptMapResolver,
});