Skip to content

Commit fae59ab

Browse files
committed
Make validator smoke test hermetic
1 parent 7456417 commit fae59ab

1 file changed

Lines changed: 79 additions & 1 deletion

File tree

scripts/oss/smoke-validator-package.mjs

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,72 @@ function run(command, args, options = {}) {
4545
});
4646
}
4747

48+
function structureDefinition(type, elements) {
49+
return {
50+
resourceType: 'StructureDefinition',
51+
url: `http://hl7.org/fhir/StructureDefinition/${type}`,
52+
version: '4.0.1',
53+
fhirVersion: '4.0.1',
54+
name: type,
55+
status: 'active',
56+
kind: 'resource',
57+
abstract: false,
58+
type,
59+
snapshot: {
60+
element: [
61+
{ id: type, path: type, min: 0, max: '*' },
62+
...elements,
63+
],
64+
},
65+
};
66+
}
67+
68+
async function writePackageResource(packageDir, filename, resource) {
69+
await writeFile(join(packageDir, filename), `${JSON.stringify(resource, null, 2)}\n`, 'utf8');
70+
}
71+
72+
async function writeMinimalR4CorePackage(cacheRoot) {
73+
const packageDir = join(cacheRoot, 'hl7.fhir.r4.core#4.0.1', 'package');
74+
await mkdir(packageDir, { recursive: true });
75+
await writePackageResource(packageDir, 'package.json', {
76+
name: 'hl7.fhir.r4.core',
77+
version: '4.0.1',
78+
fhirVersions: ['4.0.1'],
79+
});
80+
await writePackageResource(packageDir, 'StructureDefinition-Patient.json', structureDefinition('Patient', [
81+
{
82+
id: 'Patient.gender',
83+
path: 'Patient.gender',
84+
min: 0,
85+
max: '1',
86+
type: [{ code: 'code' }],
87+
binding: {
88+
strength: 'required',
89+
valueSet: 'http://hl7.org/fhir/ValueSet/administrative-gender',
90+
},
91+
},
92+
{
93+
id: 'Patient.birthDate',
94+
path: 'Patient.birthDate',
95+
min: 0,
96+
max: '1',
97+
type: [{ code: 'date' }],
98+
},
99+
]));
100+
await writePackageResource(packageDir, 'ValueSet-administrative-gender.json', {
101+
resourceType: 'ValueSet',
102+
url: 'http://hl7.org/fhir/ValueSet/administrative-gender',
103+
version: '4.0.1',
104+
status: 'active',
105+
expansion: {
106+
contains: ['male', 'female', 'other', 'unknown'].map((code) => ({
107+
system: 'http://hl7.org/fhir/administrative-gender',
108+
code,
109+
})),
110+
},
111+
});
112+
}
113+
48114
async function packWorkspace(workspace, destination) {
49115
const { stdout } = await run('npm', [
50116
'pack',
@@ -155,6 +221,11 @@ if (outcome.resourceType !== 'OperationOutcome' || outcome.issue.length === 0) {
155221
);
156222
await writeFile(join(packageDir, 'fixtures', 'notes.txt'), 'not fhir json\n');
157223

224+
const cliHome = join(packageDir, 'home');
225+
const cliPackageCache = join(packageDir, 'fhir-package-cache');
226+
await mkdir(cliHome, { recursive: true });
227+
await writeMinimalR4CorePackage(cliPackageCache);
228+
158229
await run(
159230
'./node_modules/.bin/records-fhir-validator',
160231
[
@@ -169,7 +240,14 @@ if (outcome.resourceType !== 'OperationOutcome' || outcome.issue.length === 0) {
169240
'validation-report.json',
170241
'--fail-on=none',
171242
],
172-
{ cwd: packageDir },
243+
{
244+
cwd: packageDir,
245+
env: {
246+
HOME: cliHome,
247+
FHIR_PACKAGE_CACHE_PATH: cliPackageCache,
248+
RECORDS_BUNDLED_PROFILES_PATH: cliPackageCache,
249+
},
250+
},
173251
);
174252

175253
const report = JSON.parse(await readFile(join(packageDir, 'validation-report.json'), 'utf8'));

0 commit comments

Comments
 (0)