Skip to main content
Glama
outcomes.test.ts2.55 kB
// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors // SPDX-License-Identifier: Apache-2.0 import { allOk, badRequest, gone } from '@medplum/core'; import type { OperationOutcome } from '@medplum/fhirtypes'; import { getErrorsForInput, getIssuesForExpression } from './outcomes'; const MISSING_PROP = 'Missing required property'; function missingProp(expression: string): OperationOutcome { return { resourceType: 'OperationOutcome', issue: [ { severity: 'error', code: 'structure', details: { text: MISSING_PROP, }, expression: [expression], }, ], }; } describe('Outcome utils', () => { test('getIssuesForExpression', () => { expect(getIssuesForExpression(undefined, undefined)).toBeUndefined(); expect(getIssuesForExpression(allOk, undefined)).toHaveLength(1); expect(getIssuesForExpression(gone, undefined)).toHaveLength(1); expect(getIssuesForExpression(allOk, 'expr')).toHaveLength(0); expect(getIssuesForExpression(gone, 'expr')).toHaveLength(0); expect(getIssuesForExpression(badRequest('bad'), undefined)).toHaveLength(1); expect(getIssuesForExpression(badRequest('bad', 'expr'), undefined)).toHaveLength(0); expect(getIssuesForExpression(badRequest('bad', 'expr'), 'expr')).toHaveLength(1); expect(getIssuesForExpression(badRequest('bad', 'Patient.name'), 'name')).toHaveLength(1); expect(getIssuesForExpression(badRequest('bad', 'name'), 'Patient.name')).toHaveLength(1); expect(getIssuesForExpression(badRequest('bad', 'Practitioner.name'), 'Patient.name')).toHaveLength(0); }); describe('getErrorsForInput', () => { test('match without indexes', () => { expect(getErrorsForInput(missingProp('identifier.system'), 'identifier.system')).toStrictEqual(MISSING_PROP); }); test('exact match with indexes', () => { expect(getErrorsForInput(missingProp('identifier[1].system'), 'identifier[1].system')).toStrictEqual( MISSING_PROP ); }); test('mismatched indexes', () => { expect(getErrorsForInput(missingProp('identifier[1].system'), 'identifier[0].system')).toStrictEqual(''); }); test('indexes only on outcome', () => { expect(getErrorsForInput(missingProp('identifier[1].system'), 'identifier.system')).toStrictEqual(MISSING_PROP); }); test('indexes only on client', () => { expect(getErrorsForInput(missingProp('identifier.system'), 'identifier[1].system')).toStrictEqual(MISSING_PROP); }); }); });

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