Skip to main content

core.validateresourcetype

Home > @medplum/core > validateResourceType

validateResourceType() function

Validates that the given string is a valid FHIR resource type.

On success, silently returns void. On failure, throws an OperationOutcomeError.

Signature:

export declare function validateResourceType(resourceType: string): void;

Parameters

Parameter

Type

Description

resourceType

string

The candidate resource type string.

Returns:

void

Example 1

validateResourceType('Patient'); // nothing
validateResourceType('XYZ'); // throws OperationOutcomeError

Note that this depends on globalSchema, which is populated by the StructureDefinition loader.

Example 2

In a server context, you can load all schema definitions:

import { indexStructureDefinitionBundle } from '@medplum/core';
import { readJson } from '@medplum/definitions';
import { Bundle } from '@medplum/fhirtypes';

indexStructureDefinitionBundle(readJson('fhir/r4/profiles-resources.json') as Bundle);

Example 3

In a client context, you can load the schema definitions using MedplumClient:

import { MedplumClient } from '@medplum/core';

const medplum = new MedplumClient();
await medplum.requestSchema('Patient');