Skip to content

Commit

Permalink
Automatic url for instances added to fishForMetadata in FSHtank (#1100)
Browse files Browse the repository at this point in the history
* Automatic url for instances added to fishForMetadata in FShtank

* Functionality moved to MasterFisher

* Stray comment removed, inline instance test case added for Master Fisher

* Unnecessary null guard removed
  • Loading branch information
julianxcarter authored Jun 28, 2022
1 parent 41bf2d8 commit f17591f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/utils/MasterFisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export class MasterFisher implements Fishable {
(fishable.fish(item, Type.Instance) as Instance)?.instanceOf
)?.sdType;
}
// Add url to metadata for non-inline Instances
if (!result.url && result.instanceUsage !== 'Inline') {
result.url = `${this.pkg.config.canonical}/${result.resourceType}/${result.id}`;
}
return result;
}
}
Expand Down
38 changes: 37 additions & 1 deletion test/utils/MasterFisher.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FSHDocument, FSHTank } from '../../src/import';
import { Profile } from '../../src/fshtypes';
import { Profile, Instance } from '../../src/fshtypes';
import { FHIRDefinitions, loadFromPath } from '../../src/fhirdefs';
import { Package } from '../../src/export';
import { StructureDefinition } from '../../src/fhirtypes';
Expand Down Expand Up @@ -31,6 +31,13 @@ describe('MasterFisher', () => {
);
doc1.profiles.get('Practitioner').id = 'my-dr';
doc1.profiles.get('Practitioner').parent = 'Practitioner';
doc1.instances.set('Instance1', new Instance('Instance1'));
doc1.instances.get('Instance1').id = 'inst1';
doc1.instances.get('Instance1').instanceOf = 'Profile1';
doc1.instances.set('InlineInstance', new Instance('InlineInstance'));
doc1.instances.get('InlineInstance').id = 'inline-instance';
doc1.instances.get('InlineInstance').instanceOf = 'Profile1';
doc1.instances.get('InlineInstance').usage = 'Inline';
const tank = new FSHTank([doc1], minimalConfig);

const pkg = new Package(tank.config);
Expand Down Expand Up @@ -180,6 +187,35 @@ describe('MasterFisher', () => {
defs.resetPredefinedResources();
});

it('should find an Instance that is only in the Tank', () => {
const result = fisher.fishForFHIR('Instance1');
expect(result).toBeUndefined();

const resultMD = fisher.fishForMetadata('Instance1');
expect(resultMD).toEqual({
id: 'inst1',
name: 'Instance1',
instanceUsage: 'Example',
resourceType: 'Procedure',
sdType: undefined,
url: 'http://hl7.org/fhir/us/minimal/Procedure/inst1'
});
});

it('should find an inline Instance that is only in the Tank', () => {
const result = fisher.fishForFHIR('InlineInstance');
expect(result).toBeUndefined();

const resultMD = fisher.fishForMetadata('InlineInstance');
expect(resultMD).toEqual({
id: 'inline-instance',
name: 'InlineInstance',
instanceUsage: 'Inline',
resourceType: 'Procedure',
sdType: undefined
});
});

it('should not return the FHIR def for a resource if there is a profile w/ the same name in the tank', () => {
const result = fisher.fishForFHIR('Organization');
expect(result).toBeUndefined();
Expand Down

0 comments on commit f17591f

Please sign in to comment.