Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System version doesn't need to match when assigning a code #1317

Merged
merged 5 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/fhirtypes/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
} from '../fshtypes';
import { FSHTank } from '../import';
import { Type, Fishable, Metadata } from '../utils/Fishable';
import { fishForMetadataBestVersion, fishInTankBestVersion, logger } from '../utils';
import { fishInTankBestVersion, logger } from '../utils';
import { buildSliceTree, calculateSliceTreeCounts } from './sliceTree';
import { InstanceExporter } from '../export';
import { MismatchedTypeError } from '../errors';
Expand Down Expand Up @@ -952,12 +952,10 @@ export function replaceReferences<T extends AssignmentRule | CaretValueRule>(
}
}
} else if (value instanceof FshCode) {
const codeSystemMeta = fishForMetadataBestVersion(
fisher,
value.system,
rule.sourceInfo,
Type.CodeSystem
);
// the version on a CodeSystem resource is not the same as the system's actual version out in the world.
// so, they don't need to match.
const baseSystem = value.system?.split('|')[0];
const codeSystemMeta = fisher.fishForMetadata(baseSystem, Type.CodeSystem);
if (codeSystemMeta) {
clone = cloneDeep(rule);
const assignedCode = getRuleValue(clone) as FshCode;
Expand Down
30 changes: 30 additions & 0 deletions test/export/InstanceExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6310,6 +6310,36 @@ describe('InstanceExporter', () => {
]);
});

it('should assign a code with a version while replacing the code system name with its url regardless of the specified version', () => {
// the version on a CodeSystem resource is not the same as the system's actual version out in the world.
// so, they don't need to match.
const brightInstance = new Instance('BrightObservation');
brightInstance.instanceOf = 'Observation';
const assignedCodeRule = new AssignmentRule('code');
assignedCodeRule.value = new FshCode('bright', 'Visible|1.2.3');
brightInstance.rules.push(assignedCodeRule);
doc.instances.set(brightInstance.name, brightInstance);

const visibleSystem = new FshCodeSystem('Visible');
const visibleSystemUrl = new CaretValueRule('');
visibleSystemUrl.caretPath = 'url';
visibleSystemUrl.value = 'http://hl7.org/fhir/us/minimal/CodeSystem/Visible';
const visibleSystemVersion = new CaretValueRule('');
visibleSystemVersion.caretPath = 'version';
visibleSystemVersion.value = '1.0.0';
visibleSystem.rules.push(visibleSystemUrl, visibleSystemVersion);
doc.codeSystems.set(visibleSystem.name, visibleSystem);
const exported = exportInstance(brightInstance);
expect(exported.code.coding).toEqual([
{
code: 'bright',
version: '1.2.3',
system: 'http://hl7.org/fhir/us/minimal/CodeSystem/Visible'
}
]);
expect(loggerSpy.getAllMessages('warn')).toHaveLength(0);
});

it('should assign a code to a top level element if the code system was defined as an instance of usage definition', () => {
const visibleSystem = new Instance('Visible');
visibleSystem.instanceOf = 'CodeSystem';
Expand Down
Loading