Skip to content

Commit 0cdeb70

Browse files
committed
Handle finding IG URLs for release-specific packages with incorrect packageIds
See: https://chat.fhir.org/#narrow/channel/215610-shorthand/topic/ImplementationGuide.20URL.20missing/near/576162330
1 parent d063f99 commit 0cdeb70

File tree

3 files changed

+761
-0
lines changed

3 files changed

+761
-0
lines changed

src/ig/IGExporter.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,31 @@ export class IGExporter {
320320
'dev' === resolvedVersion)
321321
);
322322
dependsOn.uri = dependencyIG?.url;
323+
if (dependsOn.uri == null && /\.r\d+$/.test(realPackageId)) {
324+
// Some release-specific packages (e.g., hl7.fhir.eu.extensions.r4) don't include the correct packageId;
325+
// they might have a package id like hl7.fhir.eu.extensions.4.0.1 and an id like hl7.fhir.eu.extensions.
326+
// See: https://chat.fhir.org/#narrow/channel/215610-shorthand/topic/ImplementationGuide.20URL.20missing/near/576162330
327+
const fallBackIG = igs.find(ig => {
328+
const packageIdPrefix = realPackageId.replace(/\.r\d+$/, '.');
329+
if (ig.packageId?.startsWith(packageIdPrefix)) {
330+
// Grab version suffix like 4.0.1
331+
const versionSuffix = ig.packageId.slice(packageIdPrefix.length);
332+
// Convert version suffix to release suffix like r4 (also converting DSTU2 to r2 and STU3 to r3)
333+
const releaseSuffix = getFHIRVersionInfo(versionSuffix)
334+
?.name.toLowerCase()
335+
.replace(/^[^0-9]+/, 'r');
336+
// Put the package id back together with the fixed suffix
337+
const fixedPackageId = ig.packageId.slice(0, packageIdPrefix.length) + releaseSuffix;
338+
return (
339+
fixedPackageId === realPackageId &&
340+
(ig.version === resolvedVersion ||
341+
'current' === resolvedVersion ||
342+
'dev' === resolvedVersion)
343+
);
344+
}
345+
});
346+
dependsOn.uri = fallBackIG?.url;
347+
}
323348
if (dependsOn.uri == null) {
324349
// there may be a package.json that can help us here
325350
const dependencyPackageJson = this.fhirDefs.findPackageJSON(realPackageId, resolvedVersion);

test/ig/IGExporter.IG.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,46 @@ describe('IGExporter', () => {
455455
]);
456456
});
457457

458+
// See: https://chat.fhir.org/#narrow/channel/215610-shorthand/topic/ImplementationGuide.20URL.20missing/near/576162330
459+
it('should fall back to release-agnostic IG when it cannot find a release-specific dependency implementation guide', () => {
460+
config.dependencies = [
461+
{ packageId: 'hl7.fhir.eu.extensions.r4', version: '1.2.0' },
462+
{ packageId: 'hl7.fhir.us.core', version: '3.1.0' }
463+
];
464+
exporter.export(tempOut);
465+
const igPath = path.join(
466+
tempOut,
467+
'fsh-generated',
468+
'resources',
469+
'ImplementationGuide-sushi-test.json'
470+
);
471+
expect(fs.existsSync(igPath)).toBeTruthy();
472+
const content = fs.readJSONSync(igPath);
473+
const dependencies: ImplementationGuideDependsOn[] = content.dependsOn;
474+
expect(loggerSpy.getAllLogs('error')).toHaveLength(0);
475+
// ensure both packages are in the dependencies
476+
expect(dependencies).toEqual([
477+
{
478+
id: 'hl7_fhir_eu_extensions_r4',
479+
uri: 'http://hl7.eu/fhir/extensions/ImplementationGuide/hl7.fhir.eu.extensions',
480+
packageId: 'hl7.fhir.eu.extensions.r4',
481+
version: '1.2.0'
482+
},
483+
{
484+
id: 'hl7_fhir_us_core',
485+
uri: 'http://hl7.org/fhir/us/core/ImplementationGuide/hl7.fhir.us.core',
486+
packageId: 'hl7.fhir.us.core',
487+
version: '3.1.0'
488+
}
489+
]);
490+
});
491+
458492
it('should use a default url format when a dependency url cannot be inferred', () => {
459493
config.dependencies = [
460494
// NOTE: Will not find mCODE IG URL because we didn't load the mcode IG
461495
{ packageId: 'hl7.fhir.us.mcode', version: '1.0.0' },
496+
// NOTE: Test release-specific that isn't found to ensure fallback code doesn't trigger
497+
{ packageId: 'hl7.fhir.us.something.r4', version: '2.0.0' },
462498
{ packageId: 'hl7.fhir.us.core', version: '3.1.0' }
463499
];
464500
exporter.export(tempOut);
@@ -480,6 +516,12 @@ describe('IGExporter', () => {
480516
packageId: 'hl7.fhir.us.mcode',
481517
version: '1.0.0'
482518
},
519+
{
520+
id: 'hl7_fhir_us_something_r4',
521+
uri: 'http://fhir.org/packages/hl7.fhir.us.something.r4/ImplementationGuide/hl7.fhir.us.something.r4',
522+
packageId: 'hl7.fhir.us.something.r4',
523+
version: '2.0.0'
524+
},
483525
{
484526
id: 'hl7_fhir_us_core',
485527
uri: 'http://hl7.org/fhir/us/core/ImplementationGuide/hl7.fhir.us.core',

0 commit comments

Comments
 (0)