Skip to main content
Glama
valuesets.ts2.01 kB
// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors // SPDX-License-Identifier: Apache-2.0 import type { WithId } from '@medplum/core'; import { Operator } from '@medplum/core'; import { readJson } from '@medplum/definitions'; import type { Bundle, BundleEntry, CodeSystem, ValueSet } from '@medplum/fhirtypes'; import { r4ProjectId } from '../constants'; import type { Repository } from '../fhir/repo'; /** * Imports all built-in ValueSets and CodeSystems into the database. * @param systemRepo - The system repository to use */ export async function rebuildR4ValueSets(systemRepo: Repository): Promise<void> { const files = [ 'v2-tables.json', 'v3-codesystems.json', 'valuesets.json', 'valuesets-medplum.json', 'valuesets-medplum-generated.json', ]; for (const file of files) { const bundle = readJson('fhir/r4/' + file) as Bundle<CodeSystem | ValueSet>; for (const entry of bundle.entry as BundleEntry<CodeSystem | ValueSet>[]) { const resource = entry.resource as CodeSystem | ValueSet; await deleteExisting(systemRepo, resource, r4ProjectId); await systemRepo.createResource({ ...resource, meta: { ...resource.meta, project: r4ProjectId, lastUpdated: undefined, versionId: undefined, }, }); } } } async function deleteExisting( systemRepo: Repository, resource: CodeSystem | ValueSet, projectId: string ): Promise<void> { const bundle = await systemRepo.search({ resourceType: resource.resourceType, filters: [ { code: 'url', operator: Operator.EQUALS, value: resource.url as string }, { code: '_project', operator: Operator.EQUALS, value: projectId }, ], }); if (bundle.entry && bundle.entry.length > 0) { for (const entry of bundle.entry) { const existing = entry.resource as WithId<CodeSystem | ValueSet>; await systemRepo.deleteResource(existing.resourceType, existing.id); } } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/medplum/medplum'

If you have feedback or need assistance with the MCP directory API, please join our Discord server