Skip to content

Commit

Permalink
Don't combine rules on inline ValueSet (#231)
Browse files Browse the repository at this point in the history
Construct inline instances before combining coding and Quantity values.
This way, rules that assign to elements in a ValueSet instance that
shouldn't be combined will be correctly detected as having a type that
does not use combined rules.
  • Loading branch information
mint-thompson authored Aug 18, 2023
1 parent ee0f161 commit 69e6238
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/optimizer/plugins/ConstructInlineInstanceOptimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import AddReferenceKeywordOptimizer from './AddReferenceKeywordOptimizer';
import SimplifyInstanceNameOptimizer from './SimplifyInstanceNameOptimizer';
import { MasterFisher, logger, ProcessingOptions } from '../../utils';
import { utils } from 'fsh-sushi';
import CombineCodingAndQuantityValuesOptimizer from './CombineCodingAndQuantityValuesOptimizer';

export default {
name: 'construct_inline_instance',
Expand All @@ -24,7 +25,8 @@ export default {
RemoveGeneratedTextRulesOptimizer.name,
ResolveInstanceOfURLsOptimizer.name,
AddReferenceKeywordOptimizer.name,
SimplifyInstanceNameOptimizer.name
SimplifyInstanceNameOptimizer.name,
CombineCodingAndQuantityValuesOptimizer.name
],

optimize(pkg: Package, fisher: MasterFisher, options: ProcessingOptions = {}): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import AddReferenceKeywordOptimizer from '../../../src/optimizer/plugins/AddRefe
import SimplifyInstanceNameOptimizer from '../../../src/optimizer/plugins/SimplifyInstanceNameOptimizer';
import { MasterFisher } from '../../../src/utils';
import { loadTestDefinitions, stockLake } from '../../helpers';
import { CombineCodingAndQuantityValuesOptimizer } from '../../../src/optimizer/plugins';

describe('optimizer', () => {
describe('#construct_inline_instance', () => {
Expand Down Expand Up @@ -71,7 +72,8 @@ describe('optimizer', () => {
RemoveGeneratedTextRulesOptimizer.name,
ResolveInstanceOfURLsOptimizer.name,
AddReferenceKeywordOptimizer.name,
SimplifyInstanceNameOptimizer.name
SimplifyInstanceNameOptimizer.name,
CombineCodingAndQuantityValuesOptimizer.name
]);
expect(optimizer.runAfter).toBeUndefined();
});
Expand Down
30 changes: 30 additions & 0 deletions test/utils/Processing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from '../../src/exportable';
import { FHIRDefinitions, loadExternalDependencies } from '../../src/utils';
import * as loadOptimizers from '../../src/optimizer/loadOptimizers';
import { FshCode } from 'fsh-sushi/dist/fshtypes';

let loadedPackages: string[] = [];

Expand Down Expand Up @@ -384,6 +385,35 @@ describe('Processing', () => {
expect(patient.usage).toBe('Example');
});

it('should not combine rules on contained ValueSet.compose.include.concept', async () => {
const inDir = path.join(__dirname, 'fixtures', 'contained-valueset');
const processor = await getFhirProcessor(inDir, loadTestDefinitions(), 'json-only');
const config = processor.processConfig();
const result = await getResources(processor, config);
expect(result.instances).toHaveLength(2);
const inlineVS = result.instances.find(i => i.id === 'MyInlineVS');
expect(inlineVS?.usage).toBe('Inline');
// * status = #active
// * compose.include.system = "http://example.org"
// * compose.include.concept[0].code = #123
// * compose.include.concept[=].display = "one two three"
// * compose.include.concept[+].code = #456
// * compose.include.concept[=].display = "four five six"
const statusRule = new ExportableAssignmentRule('status');
statusRule.value = new FshCode('active');
const systemRule = new ExportableAssignmentRule('compose.include.system');
systemRule.value = 'http://example.org';
const code0 = new ExportableAssignmentRule('compose.include.concept[0].code');
code0.value = new FshCode('123');
const display0 = new ExportableAssignmentRule('compose.include.concept[=].display');
display0.value = 'one two three';
const code1 = new ExportableAssignmentRule('compose.include.concept[+].code');
code1.value = new FshCode('456');
const display1 = new ExportableAssignmentRule('compose.include.concept[=].display');
display1.value = 'four five six';
expect(inlineVS.rules).toEqual([statusRule, systemRule, code0, display0, code1, display1]);
});

describe('#enableOptimizers', () => {
beforeEach(() => {
// mock the call to loadOptimizers so that we get a custom set
Expand Down
36 changes: 36 additions & 0 deletions test/utils/fixtures/contained-valueset/Observation-MyObs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"resourceType": "Observation",
"id": "MyObs",
"status": "final",
"code": {
"coding": [
{
"code": "something"
}
]
},
"contained": [
{
"resourceType": "ValueSet",
"id": "MyInlineVS",
"status": "active",
"compose": {
"include": [
{
"system": "http://example.org",
"concept": [
{
"code": "123",
"display": "one two three"
},
{
"code": "456",
"display": "four five six"
}
]
}
]
}
}
]
}

0 comments on commit 69e6238

Please sign in to comment.