@atomic-ehr/codegen 0.0.14 → 0.0.15-canary.20260603085553.80dea42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/api/writer-generator/typescript/profile-helpers.ts +36 -0
- package/dist/cli/index.js +10 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +228 -146
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -382,6 +382,13 @@ var isPrimitiveIdentifier = (id) => {
|
|
|
382
382
|
var isNestedIdentifier = (id) => {
|
|
383
383
|
return id?.kind === "nested";
|
|
384
384
|
};
|
|
385
|
+
var isSnapshotProfileIdentifier = (id) => {
|
|
386
|
+
return id?.kind === "profile-snapshot";
|
|
387
|
+
};
|
|
388
|
+
var snapshotIdentifier = (id) => ({
|
|
389
|
+
...id,
|
|
390
|
+
kind: "profile-snapshot"
|
|
391
|
+
});
|
|
385
392
|
var concatIdentifiers = (...sources) => {
|
|
386
393
|
const entries = sources.filter((s) => s !== void 0).flatMap((s) => s.map((id) => [id.url, id]));
|
|
387
394
|
if (entries.length === 0) return void 0;
|
|
@@ -415,6 +422,9 @@ var isBindingSchema = (schema) => {
|
|
|
415
422
|
var isValueSetTypeSchema = (schema) => {
|
|
416
423
|
return schema?.identifier.kind === "value-set";
|
|
417
424
|
};
|
|
425
|
+
var isSnapshotProfileTypeSchema = (s) => {
|
|
426
|
+
return s?.identifier.kind === "profile-snapshot";
|
|
427
|
+
};
|
|
418
428
|
var extractExtensionDeps = (ext) => [
|
|
419
429
|
...ext.valueFieldTypes ?? [],
|
|
420
430
|
...ext.profile ? [ext.profile] : [],
|
|
@@ -927,10 +937,9 @@ var populateGeneric = (schemas, resolveType) => {
|
|
|
927
937
|
for (const c of carriers) c.generic = void 0;
|
|
928
938
|
const sameParams = (a, b) => {
|
|
929
939
|
if (a.length !== b.length) return false;
|
|
930
|
-
for (
|
|
931
|
-
const x = a[i];
|
|
940
|
+
for (const [i, x] of a.entries()) {
|
|
932
941
|
const y = b[i];
|
|
933
|
-
if (x.typeVar !== y.typeVar || !samePath(x.path, y.path) || x.constraint.url !== y.constraint.url)
|
|
942
|
+
if (!y || x.typeVar !== y.typeVar || !samePath(x.path, y.path) || x.constraint.url !== y.constraint.url)
|
|
934
943
|
return false;
|
|
935
944
|
}
|
|
936
945
|
return true;
|
|
@@ -970,6 +979,7 @@ var mkTypeSchemaIndex = (schemas, {
|
|
|
970
979
|
}) => {
|
|
971
980
|
const index = {};
|
|
972
981
|
const nestedIndex = {};
|
|
982
|
+
const snapshotIndex = {};
|
|
973
983
|
const append = (schema) => {
|
|
974
984
|
const url = schema.identifier.url;
|
|
975
985
|
const pkg = schema.identifier.package;
|
|
@@ -996,13 +1006,15 @@ var mkTypeSchemaIndex = (schemas, {
|
|
|
996
1006
|
append(schema);
|
|
997
1007
|
}
|
|
998
1008
|
populateTypeFamily(schemas);
|
|
999
|
-
const resolve6 = (id) => {
|
|
1009
|
+
const resolve6 = ((id) => {
|
|
1010
|
+
if (isSnapshotProfileIdentifier(id)) return snapshotIndex[id.url]?.[id.package];
|
|
1000
1011
|
return index[id.url]?.[id.package];
|
|
1001
|
-
};
|
|
1002
|
-
const resolveType = (id) => {
|
|
1012
|
+
});
|
|
1013
|
+
const resolveType = ((id) => {
|
|
1003
1014
|
if (isNestedIdentifier(id)) return nestedIndex[id.url]?.[id.package];
|
|
1015
|
+
if (isSnapshotProfileIdentifier(id)) return snapshotIndex[id.url]?.[id.package];
|
|
1004
1016
|
return index[id.url]?.[id.package];
|
|
1005
|
-
};
|
|
1017
|
+
});
|
|
1006
1018
|
populateGeneric(schemas, resolveType);
|
|
1007
1019
|
const resolveByUrl = (pkgName, url) => {
|
|
1008
1020
|
if (register) {
|
|
@@ -1059,7 +1071,9 @@ var mkTypeSchemaIndex = (schemas, {
|
|
|
1059
1071
|
return genealogy;
|
|
1060
1072
|
};
|
|
1061
1073
|
const findLastSpecialization = (schema) => {
|
|
1062
|
-
const nonConstraintSchema = hierarchy(schema).find(
|
|
1074
|
+
const nonConstraintSchema = hierarchy(schema).find(
|
|
1075
|
+
(s) => !isProfileTypeSchema(s) && !isSnapshotProfileTypeSchema(s)
|
|
1076
|
+
);
|
|
1063
1077
|
if (!nonConstraintSchema) {
|
|
1064
1078
|
throw new Error(`No non-constraint schema found in hierarchy for: ${schema.identifier.name}`);
|
|
1065
1079
|
}
|
|
@@ -1107,14 +1121,11 @@ var mkTypeSchemaIndex = (schemas, {
|
|
|
1107
1121
|
const schema2 = anySchema;
|
|
1108
1122
|
if (!schema2.fields) continue;
|
|
1109
1123
|
for (const [fieldName, fieldConstraints] of Object.entries(schema2.fields)) {
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
...fieldConstraints
|
|
1114
|
-
};
|
|
1115
|
-
} else {
|
|
1116
|
-
mergedFields[fieldName] = { ...fieldConstraints };
|
|
1124
|
+
const merged = mergedFields[fieldName] ? { ...mergedFields[fieldName], ...fieldConstraints } : { ...fieldConstraints };
|
|
1125
|
+
if ("min" in fieldConstraints && fieldConstraints.min === 0) {
|
|
1126
|
+
merged.required = false;
|
|
1117
1127
|
}
|
|
1128
|
+
mergedFields[fieldName] = merged;
|
|
1118
1129
|
}
|
|
1119
1130
|
}
|
|
1120
1131
|
const narrowedFields = narrowMergedChoiceDeclarations(mergedFields, constraintSchemas);
|
|
@@ -1138,6 +1149,42 @@ var mkTypeSchemaIndex = (schemas, {
|
|
|
1138
1149
|
extensions: mergedExtensions.length > 0 ? mergedExtensions : void 0
|
|
1139
1150
|
};
|
|
1140
1151
|
};
|
|
1152
|
+
const buildProfileSnapshot = (schema) => {
|
|
1153
|
+
const flat = flatProfile(schema);
|
|
1154
|
+
const flatFields = flat.fields ?? {};
|
|
1155
|
+
const hierarchySchemas = hierarchy(schema);
|
|
1156
|
+
const nonConstraintSchema = hierarchySchemas.find((s) => s.identifier.kind !== "profile");
|
|
1157
|
+
const inheritedRequiredFields = [];
|
|
1158
|
+
if (nonConstraintSchema?.fields) {
|
|
1159
|
+
for (const [name, baseField] of Object.entries(nonConstraintSchema.fields)) {
|
|
1160
|
+
if (!baseField.required) continue;
|
|
1161
|
+
if (isChoiceDeclarationField(baseField)) continue;
|
|
1162
|
+
const flat2 = flatFields[name];
|
|
1163
|
+
if (flat2?.min === 0) continue;
|
|
1164
|
+
if (flat2?.required) continue;
|
|
1165
|
+
inheritedRequiredFields.push(name);
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
return {
|
|
1169
|
+
identifier: snapshotIdentifier(flat.identifier),
|
|
1170
|
+
base: flat.base,
|
|
1171
|
+
description: flat.description,
|
|
1172
|
+
fields: flatFields,
|
|
1173
|
+
inheritedRequiredFields: inheritedRequiredFields.length > 0 ? inheritedRequiredFields : void 0,
|
|
1174
|
+
extensions: flat.extensions,
|
|
1175
|
+
dependencies: flat.dependencies,
|
|
1176
|
+
nested: flat.nested
|
|
1177
|
+
};
|
|
1178
|
+
};
|
|
1179
|
+
for (const schema of schemas) {
|
|
1180
|
+
if (!isProfileTypeSchema(schema)) continue;
|
|
1181
|
+
const hier = tryHierarchy(schema);
|
|
1182
|
+
if (!hier?.some((s) => !isProfileTypeSchema(s) && !isSnapshotProfileTypeSchema(s))) continue;
|
|
1183
|
+
const snap = buildProfileSnapshot(schema);
|
|
1184
|
+
const byPkg = snapshotIndex[snap.identifier.url] ??= {};
|
|
1185
|
+
byPkg[snap.identifier.package] = snap;
|
|
1186
|
+
}
|
|
1187
|
+
const collectSnapshotProfiles = () => Object.values(snapshotIndex).flatMap((byPkg) => Object.values(byPkg));
|
|
1141
1188
|
const constrainedChoice = (pkgName, baseTypeId, sliceElements) => {
|
|
1142
1189
|
const baseSchema = resolveByUrl(pkgName, baseTypeId.url);
|
|
1143
1190
|
if (!baseSchema || !("fields" in baseSchema) || !baseSchema.fields) return void 0;
|
|
@@ -1175,6 +1222,7 @@ var mkTypeSchemaIndex = (schemas, {
|
|
|
1175
1222
|
nested: {},
|
|
1176
1223
|
binding: {},
|
|
1177
1224
|
profile: {},
|
|
1225
|
+
"profile-snapshot": {},
|
|
1178
1226
|
logical: {}
|
|
1179
1227
|
};
|
|
1180
1228
|
for (const schema of shemas) {
|
|
@@ -1198,6 +1246,7 @@ var mkTypeSchemaIndex = (schemas, {
|
|
|
1198
1246
|
collectResources: () => schemas.filter(isResourceTypeSchema),
|
|
1199
1247
|
collectLogicalModels: () => schemas.filter(isLogicalTypeSchema),
|
|
1200
1248
|
collectProfiles: () => schemas.filter(isProfileTypeSchema),
|
|
1249
|
+
collectSnapshotProfiles,
|
|
1201
1250
|
resolve: resolve6,
|
|
1202
1251
|
resolveType,
|
|
1203
1252
|
resolveByUrl,
|
|
@@ -1996,6 +2045,7 @@ function extractValueSetConcepts(register, valueSet, _logger) {
|
|
|
1996
2045
|
return concepts.length > 0 ? concepts : void 0;
|
|
1997
2046
|
}
|
|
1998
2047
|
var MAX_ENUM_LENGTH = 100;
|
|
2048
|
+
var PLACEHOLDER_ONLY_ENUM_CODES = /* @__PURE__ */ new Set(["UNK"]);
|
|
1999
2049
|
var BINDABLE_TYPES = /* @__PURE__ */ new Set([
|
|
2000
2050
|
"code",
|
|
2001
2051
|
"Coding",
|
|
@@ -2023,6 +2073,14 @@ function buildEnum(register, fhirSchema, element, logger) {
|
|
|
2023
2073
|
const concepts = extractValueSetConceptsByUrl(register, fhirSchema.package_meta, valueSetUrl);
|
|
2024
2074
|
if (!concepts || concepts.length === 0) return void 0;
|
|
2025
2075
|
const codes = concepts.map((c) => c.code).filter((code) => code && typeof code === "string" && code.trim().length > 0);
|
|
2076
|
+
const onlyCode = codes.length === 1 ? codes[0] : void 0;
|
|
2077
|
+
if (onlyCode && PLACEHOLDER_ONLY_ENUM_CODES.has(onlyCode)) {
|
|
2078
|
+
logger?.dryWarn(
|
|
2079
|
+
"#placeholderValueSet",
|
|
2080
|
+
`Value set ${valueSetUrl} only expands to placeholder code '${onlyCode}'; skipping enum generation.`
|
|
2081
|
+
);
|
|
2082
|
+
return void 0;
|
|
2083
|
+
}
|
|
2026
2084
|
if (codes.length > MAX_ENUM_LENGTH) {
|
|
2027
2085
|
logger?.dryWarn(
|
|
2028
2086
|
"#largeValueSet",
|
|
@@ -3372,7 +3430,8 @@ var mutableFillReport = (report, tsIndex, shakedIndex) => {
|
|
|
3372
3430
|
};
|
|
3373
3431
|
var treeShakeTypeSchema = (schema, rule, _logger) => {
|
|
3374
3432
|
schema = JSON.parse(JSON.stringify(schema));
|
|
3375
|
-
if (isPrimitiveTypeSchema(schema) || isValueSetTypeSchema(schema) || isBindingSchema(schema)
|
|
3433
|
+
if (isPrimitiveTypeSchema(schema) || isValueSetTypeSchema(schema) || isBindingSchema(schema) || isSnapshotProfileTypeSchema(schema))
|
|
3434
|
+
return schema;
|
|
3376
3435
|
if (rule.selectFields) {
|
|
3377
3436
|
if (rule.ignoreFields) throw new Error("Cannot use both ignoreFields and selectFields in the same rule");
|
|
3378
3437
|
mutableSelectFields(schema, rule.selectFields);
|
|
@@ -4477,8 +4536,8 @@ var tsFieldName = (n) => {
|
|
|
4477
4536
|
return n;
|
|
4478
4537
|
};
|
|
4479
4538
|
var tsProfileModuleName = (tsIndex, schema) => {
|
|
4480
|
-
const
|
|
4481
|
-
const resourceName = uppercaseFirstLetter(normalizeTsName(
|
|
4539
|
+
const resourceId = tsIndex.findLastSpecializationByIdentifier(schema.identifier);
|
|
4540
|
+
const resourceName = uppercaseFirstLetter(normalizeTsName(resourceId.name));
|
|
4482
4541
|
return `${resourceName}_${normalizeTsName(schema.identifier.name)}`;
|
|
4483
4542
|
};
|
|
4484
4543
|
var tsProfileModuleFileName = (tsIndex, schema) => {
|
|
@@ -4605,7 +4664,7 @@ var valueFieldToTsType = (valueField) => {
|
|
|
4605
4664
|
return primitives[fhirName] ?? fhirName;
|
|
4606
4665
|
};
|
|
4607
4666
|
var collectSubExtensionSlices = (extProfile) => {
|
|
4608
|
-
const extensionField = extProfile.fields
|
|
4667
|
+
const extensionField = extProfile.fields.extension;
|
|
4609
4668
|
if (!extensionField || isChoiceDeclarationField(extensionField) || !extensionField.slicing?.slices) return [];
|
|
4610
4669
|
const result = [];
|
|
4611
4670
|
for (const [sliceName, slice] of Object.entries(extensionField.slicing.slices)) {
|
|
@@ -4629,10 +4688,11 @@ var resolveExtensionProfile = (tsIndex, pkgName, url) => {
|
|
|
4629
4688
|
const schema = tsIndex.resolveByUrl(pkgName, url);
|
|
4630
4689
|
if (!schema || !isProfileTypeSchema(schema)) return void 0;
|
|
4631
4690
|
if (schema.identifier.package !== pkgName) return void 0;
|
|
4632
|
-
const
|
|
4633
|
-
|
|
4634
|
-
const
|
|
4635
|
-
|
|
4691
|
+
const snapshot = tsIndex.resolve(snapshotIdentifier(schema.identifier));
|
|
4692
|
+
if (!snapshot) return void 0;
|
|
4693
|
+
const className = tsProfileClassName(snapshot);
|
|
4694
|
+
const modulePath = `./${tsProfileModuleName(tsIndex, snapshot)}`;
|
|
4695
|
+
return { className, modulePath, snapshot };
|
|
4636
4696
|
};
|
|
4637
4697
|
var generateRawExtensionBody = (w, ext, targetPath, paramName = "input", useUpsert = false) => {
|
|
4638
4698
|
w.line(
|
|
@@ -4698,10 +4758,10 @@ var generateExtensionGetterOverloads = (w, ext, targetPath, methodName, inputTyp
|
|
|
4698
4758
|
);
|
|
4699
4759
|
};
|
|
4700
4760
|
var generateComplexExtensionSetter = (w, info) => {
|
|
4701
|
-
const { ext,
|
|
4702
|
-
const tsProfileName = tsResourceName(
|
|
4761
|
+
const { ext, snapshot, setMethodName, targetPath, extProfileInfo } = info;
|
|
4762
|
+
const tsProfileName = tsResourceName(snapshot.identifier);
|
|
4703
4763
|
const inputTypeName = tsExtensionFlatTypeName(tsProfileName, ext.name);
|
|
4704
|
-
const extProfileHasFlatInput = extProfileInfo ? collectSubExtensionSlices(extProfileInfo.
|
|
4764
|
+
const extProfileHasFlatInput = extProfileInfo ? collectSubExtensionSlices(extProfileInfo.snapshot).length > 0 : false;
|
|
4705
4765
|
const useUpsert = ext.max === "1";
|
|
4706
4766
|
if (extProfileInfo && extProfileHasFlatInput) {
|
|
4707
4767
|
const paramType = `${extProfileInfo.className}Flat | ${extProfileInfo.className} | Extension`;
|
|
@@ -4761,10 +4821,10 @@ var generateComplexExtensionSetter = (w, info) => {
|
|
|
4761
4821
|
}
|
|
4762
4822
|
};
|
|
4763
4823
|
var generateComplexExtensionGetter = (w, info) => {
|
|
4764
|
-
const { ext,
|
|
4765
|
-
const tsProfileName = tsResourceName(
|
|
4824
|
+
const { ext, snapshot, getMethodName, targetPath, extProfileInfo } = info;
|
|
4825
|
+
const tsProfileName = tsResourceName(snapshot.identifier);
|
|
4766
4826
|
const inputTypeName = tsExtensionFlatTypeName(tsProfileName, ext.name);
|
|
4767
|
-
const extProfileHasFlatInput = extProfileInfo ? collectSubExtensionSlices(extProfileInfo.
|
|
4827
|
+
const extProfileHasFlatInput = extProfileInfo ? collectSubExtensionSlices(extProfileInfo.snapshot).length > 0 : false;
|
|
4768
4828
|
const inputType = extProfileHasFlatInput && extProfileInfo ? `${extProfileInfo.className}Flat` : inputTypeName;
|
|
4769
4829
|
generateExtensionGetterOverloads(w, ext, targetPath, getMethodName, inputType, extProfileInfo, () => {
|
|
4770
4830
|
const configItems = (ext.subExtensions ?? []).map((sub) => {
|
|
@@ -4784,7 +4844,7 @@ var generateSingleValueExtensionSetter = (w, tsIndex, info) => {
|
|
|
4784
4844
|
const valueField = tsValueFieldName(firstValueType);
|
|
4785
4845
|
const useUpsert = ext.max === "1";
|
|
4786
4846
|
if (extProfileInfo) {
|
|
4787
|
-
const extFactoryInfo = collectProfileFactoryInfo(tsIndex, extProfileInfo.
|
|
4847
|
+
const extFactoryInfo = collectProfileFactoryInfo(tsIndex, extProfileInfo.snapshot);
|
|
4788
4848
|
const extValueParam = extFactoryInfo.params.find((p) => p.name === valueField);
|
|
4789
4849
|
const resolvedValueType = extValueParam?.tsType ?? valueType;
|
|
4790
4850
|
const paramType = `${extProfileInfo.className} | Extension | ${resolvedValueType}`;
|
|
@@ -4852,15 +4912,15 @@ var generateGenericExtensionGetter = (w, info) => {
|
|
|
4852
4912
|
}
|
|
4853
4913
|
});
|
|
4854
4914
|
};
|
|
4855
|
-
var generateExtensionMethods = (w, tsIndex,
|
|
4856
|
-
for (const ext of
|
|
4915
|
+
var generateExtensionMethods = (w, tsIndex, snapshot) => {
|
|
4916
|
+
for (const ext of snapshot.extensions ?? []) {
|
|
4857
4917
|
if (!ext.url) continue;
|
|
4858
4918
|
const baseName = ext.nameCandidates.recommended;
|
|
4859
4919
|
const targetPath = ext.path.split(".").filter((segment) => segment !== "extension");
|
|
4860
|
-
const extProfileInfo = resolveExtensionProfile(tsIndex,
|
|
4920
|
+
const extProfileInfo = resolveExtensionProfile(tsIndex, snapshot.identifier.package, ext.url);
|
|
4861
4921
|
const info = {
|
|
4862
4922
|
ext,
|
|
4863
|
-
|
|
4923
|
+
snapshot,
|
|
4864
4924
|
setMethodName: `set${baseName}`,
|
|
4865
4925
|
getMethodName: `get${baseName}`,
|
|
4866
4926
|
targetPath,
|
|
@@ -4882,15 +4942,15 @@ var generateExtensionMethods = (w, tsIndex, flatProfile) => {
|
|
|
4882
4942
|
w.line();
|
|
4883
4943
|
}
|
|
4884
4944
|
};
|
|
4885
|
-
var collectTypesFromExtensions = (tsIndex,
|
|
4945
|
+
var collectTypesFromExtensions = (tsIndex, snapshot, addType) => {
|
|
4886
4946
|
let needsExtensionType = false;
|
|
4887
|
-
for (const ext of
|
|
4947
|
+
for (const ext of snapshot.extensions ?? []) {
|
|
4888
4948
|
if (ext.isComplex && ext.subExtensions) {
|
|
4889
4949
|
needsExtensionType = true;
|
|
4890
4950
|
for (const sub of ext.subExtensions) {
|
|
4891
4951
|
if (!sub.valueFieldType) continue;
|
|
4892
4952
|
const resolvedType = tsIndex.resolveByUrl(
|
|
4893
|
-
|
|
4953
|
+
snapshot.identifier.package,
|
|
4894
4954
|
sub.valueFieldType.url
|
|
4895
4955
|
);
|
|
4896
4956
|
addType(resolvedType?.identifier ?? sub.valueFieldType);
|
|
@@ -4899,7 +4959,7 @@ var collectTypesFromExtensions = (tsIndex, flatProfile, addType) => {
|
|
|
4899
4959
|
needsExtensionType = true;
|
|
4900
4960
|
if (ext.valueFieldTypes[0]) {
|
|
4901
4961
|
const resolvedType = tsIndex.resolveByUrl(
|
|
4902
|
-
|
|
4962
|
+
snapshot.identifier.package,
|
|
4903
4963
|
ext.valueFieldTypes[0].url
|
|
4904
4964
|
);
|
|
4905
4965
|
addType(resolvedType?.identifier ?? ext.valueFieldTypes[0]);
|
|
@@ -4910,14 +4970,14 @@ var collectTypesFromExtensions = (tsIndex, flatProfile, addType) => {
|
|
|
4910
4970
|
}
|
|
4911
4971
|
return needsExtensionType;
|
|
4912
4972
|
};
|
|
4913
|
-
var collectTypesFromFlatInput = (tsIndex,
|
|
4914
|
-
if (
|
|
4915
|
-
const subSlices = collectSubExtensionSlices(
|
|
4973
|
+
var collectTypesFromFlatInput = (tsIndex, snapshot, addType) => {
|
|
4974
|
+
if (snapshot.base.name !== "Extension") return;
|
|
4975
|
+
const subSlices = collectSubExtensionSlices(snapshot);
|
|
4916
4976
|
for (const sub of subSlices) {
|
|
4917
4977
|
const tsType = sub.tsType;
|
|
4918
4978
|
if (["string", "boolean", "number"].includes(tsType)) continue;
|
|
4919
4979
|
const fhirUrl = `http://hl7.org/fhir/StructureDefinition/${tsType}`;
|
|
4920
|
-
const schema = tsIndex.resolveByUrl(
|
|
4980
|
+
const schema = tsIndex.resolveByUrl(snapshot.identifier.package, fhirUrl);
|
|
4921
4981
|
if (schema) addType(schema.identifier);
|
|
4922
4982
|
}
|
|
4923
4983
|
};
|
|
@@ -4943,9 +5003,9 @@ var extractResourceTypeFromMatch = (match) => {
|
|
|
4943
5003
|
}
|
|
4944
5004
|
return void 0;
|
|
4945
5005
|
};
|
|
4946
|
-
var collectTypesFromSlices = (tsIndex,
|
|
4947
|
-
const pkgName =
|
|
4948
|
-
for (const field of Object.values(
|
|
5006
|
+
var collectTypesFromSlices = (tsIndex, snapshot, addType) => {
|
|
5007
|
+
const pkgName = snapshot.identifier.package;
|
|
5008
|
+
for (const field of Object.values(snapshot.fields)) {
|
|
4949
5009
|
if (!isNotChoiceDeclarationField(field) || !field.slicing?.slices || !field.type) continue;
|
|
4950
5010
|
const isTypeDisc = field.slicing.discriminator?.some((d) => d.type === "type") ?? false;
|
|
4951
5011
|
for (const slice of Object.values(field.slicing.slices)) {
|
|
@@ -4978,10 +5038,10 @@ var collectRequiredSliceNames = (field) => {
|
|
|
4978
5038
|
}).map(([name]) => name);
|
|
4979
5039
|
return names.length > 0 ? names : void 0;
|
|
4980
5040
|
};
|
|
4981
|
-
var collectSliceDefs = (tsIndex,
|
|
5041
|
+
var collectSliceDefs = (tsIndex, snapshot) => Object.entries(snapshot.fields).filter(([_, field]) => isNotChoiceDeclarationField(field) && field.slicing?.slices).flatMap(([fieldName, field]) => {
|
|
4982
5042
|
if (!isNotChoiceDeclarationField(field) || !field.slicing?.slices || !field.type) return [];
|
|
4983
5043
|
const baseType = tsTypeFromIdentifier(field.type);
|
|
4984
|
-
const pkgName =
|
|
5044
|
+
const pkgName = snapshot.identifier.package;
|
|
4985
5045
|
const choiceBaseNames = collectChoiceBaseNames(tsIndex, field.type);
|
|
4986
5046
|
const isTypeDisc = field.slicing.discriminator?.some((d) => d.type === "type") ?? false;
|
|
4987
5047
|
return Object.entries(field.slicing.slices).filter(([_, slice]) => Object.keys(slice.match ?? {}).length > 0).map(([sliceName, slice]) => {
|
|
@@ -5009,9 +5069,9 @@ var collectSliceDefs = (tsIndex, flatProfile) => Object.entries(flatProfile.fiel
|
|
|
5009
5069
|
};
|
|
5010
5070
|
});
|
|
5011
5071
|
});
|
|
5012
|
-
var generateSliceSetters = (w, sliceDefs,
|
|
5013
|
-
const profileClassName = tsProfileClassName(
|
|
5014
|
-
const tsProfileName = tsResourceName(
|
|
5072
|
+
var generateSliceSetters = (w, sliceDefs, snapshot) => {
|
|
5073
|
+
const profileClassName = tsProfileClassName(snapshot);
|
|
5074
|
+
const tsProfileName = tsResourceName(snapshot.identifier);
|
|
5015
5075
|
for (const sliceDef of sliceDefs) {
|
|
5016
5076
|
const baseName = sliceDef.baseName;
|
|
5017
5077
|
const methodName = `set${baseName}`;
|
|
@@ -5073,9 +5133,9 @@ var generateSliceSetters = (w, sliceDefs, flatProfile) => {
|
|
|
5073
5133
|
w.line();
|
|
5074
5134
|
}
|
|
5075
5135
|
};
|
|
5076
|
-
var generateSliceGetters = (w, sliceDefs,
|
|
5077
|
-
const profileClassName = tsProfileClassName(
|
|
5078
|
-
const tsProfileName = tsResourceName(
|
|
5136
|
+
var generateSliceGetters = (w, sliceDefs, snapshot) => {
|
|
5137
|
+
const profileClassName = tsProfileClassName(snapshot);
|
|
5138
|
+
const tsProfileName = tsResourceName(snapshot.identifier);
|
|
5079
5139
|
const defaultMode = w.opts.sliceGetterDefault ?? "flat";
|
|
5080
5140
|
for (const sliceDef of sliceDefs) {
|
|
5081
5141
|
const baseName = sliceDef.baseName;
|
|
@@ -5206,11 +5266,11 @@ var collectRegularFieldValidation = (errors, warnings, name, field, resolveRef,
|
|
|
5206
5266
|
}
|
|
5207
5267
|
}
|
|
5208
5268
|
};
|
|
5209
|
-
var generateValidateMethod = (w, tsIndex,
|
|
5210
|
-
const fields =
|
|
5211
|
-
const profileName =
|
|
5212
|
-
const canonicalUrl =
|
|
5213
|
-
const canonicalUrlExpr = canonicalUrl ? { url: canonicalUrl, expr: `${tsProfileClassName(
|
|
5269
|
+
var generateValidateMethod = (w, tsIndex, snapshot) => {
|
|
5270
|
+
const fields = snapshot.fields;
|
|
5271
|
+
const profileName = snapshot.identifier.name;
|
|
5272
|
+
const canonicalUrl = snapshot.identifier.url;
|
|
5273
|
+
const canonicalUrlExpr = canonicalUrl ? { url: canonicalUrl, expr: `${tsProfileClassName(snapshot)}.canonicalUrl` } : void 0;
|
|
5214
5274
|
w.curlyBlock(["validate(): { errors: string[]; warnings: string[] }"], () => {
|
|
5215
5275
|
w.line(`const profileName = "${profileName}"`);
|
|
5216
5276
|
w.line("const res = this.resource");
|
|
@@ -5238,6 +5298,9 @@ var generateValidateMethod = (w, tsIndex, flatProfile) => {
|
|
|
5238
5298
|
tsIndex
|
|
5239
5299
|
);
|
|
5240
5300
|
}
|
|
5301
|
+
for (const inheritedName of snapshot.inheritedRequiredFields ?? []) {
|
|
5302
|
+
errors.push(`...validateRequired(res, profileName, ${JSON.stringify(inheritedName)})`);
|
|
5303
|
+
}
|
|
5241
5304
|
const emitArray = (label, exprs) => {
|
|
5242
5305
|
if (exprs.length === 0) {
|
|
5243
5306
|
w.line(`${label}: [],`);
|
|
@@ -5256,16 +5319,29 @@ var generateValidateMethod = (w, tsIndex, flatProfile) => {
|
|
|
5256
5319
|
};
|
|
5257
5320
|
|
|
5258
5321
|
// src/api/writer-generator/typescript/profile.ts
|
|
5259
|
-
var
|
|
5322
|
+
var choiceClearMethodName = (choiceOf) => `clear${uppercaseFirstLetter(tsCamelCase(choiceOf))}`;
|
|
5323
|
+
var collectChoiceAccessors = (snapshot, promotedChoices) => {
|
|
5324
|
+
const variantsByChoice = {};
|
|
5325
|
+
for (const [name, field] of Object.entries(snapshot.fields)) {
|
|
5326
|
+
if (field.excluded) continue;
|
|
5327
|
+
if (!isChoiceInstanceField(field)) continue;
|
|
5328
|
+
(variantsByChoice[field.choiceOf] ??= []).push(name);
|
|
5329
|
+
}
|
|
5260
5330
|
const accessors = [];
|
|
5261
|
-
for (const [name, field] of Object.entries(
|
|
5331
|
+
for (const [name, field] of Object.entries(snapshot.fields)) {
|
|
5262
5332
|
if (field.excluded) continue;
|
|
5263
5333
|
if (!isChoiceInstanceField(field)) continue;
|
|
5264
5334
|
if (promotedChoices.has(name)) continue;
|
|
5265
5335
|
const tsType = tsTypeFromIdentifier(field.type) + (field.array ? "[]" : "");
|
|
5266
|
-
|
|
5336
|
+
const hasSiblings = (variantsByChoice[field.choiceOf]?.length ?? 0) > 1;
|
|
5337
|
+
const choiceClearMethod = hasSiblings ? choiceClearMethodName(field.choiceOf) : void 0;
|
|
5338
|
+
accessors.push({ name, tsType, typeId: field.type, choiceClearMethod });
|
|
5267
5339
|
}
|
|
5268
|
-
|
|
5340
|
+
const choiceClearMethods = Object.entries(variantsByChoice).filter(([, variants]) => variants.length > 1).map(([choiceOf, variants]) => ({
|
|
5341
|
+
method: choiceClearMethodName(choiceOf),
|
|
5342
|
+
variants: variants.map(tsFieldName)
|
|
5343
|
+
}));
|
|
5344
|
+
return { accessors, choiceClearMethods };
|
|
5269
5345
|
};
|
|
5270
5346
|
var tryPromoteChoice = (field, fields, params, promotedChoices, resolveRef, isFamilyType) => {
|
|
5271
5347
|
if (!isChoiceDeclarationField(field) || !field.required || field.choices.length !== 1) return;
|
|
@@ -5282,18 +5358,18 @@ var mkIsFamilyType = (tsIndex) => (ref) => {
|
|
|
5282
5358
|
if (!schema || !("typeFamily" in schema)) return false;
|
|
5283
5359
|
return (schema.typeFamily?.resources?.length ?? 0) > 0;
|
|
5284
5360
|
};
|
|
5285
|
-
var collectProfileFactoryInfo = (tsIndex,
|
|
5361
|
+
var collectProfileFactoryInfo = (tsIndex, snapshot) => {
|
|
5286
5362
|
const autoFields = [];
|
|
5287
5363
|
const sliceAutoFields = [];
|
|
5288
5364
|
const params = [];
|
|
5289
5365
|
const autoAccessors = [];
|
|
5290
5366
|
const fixedFields = /* @__PURE__ */ new Set();
|
|
5291
|
-
const fields =
|
|
5367
|
+
const fields = snapshot.fields;
|
|
5292
5368
|
const promotedChoices = /* @__PURE__ */ new Set();
|
|
5293
5369
|
const resolveRef = tsIndex.findLastSpecializationByIdentifier;
|
|
5294
5370
|
const isFamilyType = mkIsFamilyType(tsIndex);
|
|
5295
|
-
if (isResourceIdentifier(
|
|
5296
|
-
autoFields.push({ name: "resourceType", value: JSON.stringify(
|
|
5371
|
+
if (isResourceIdentifier(snapshot.base)) {
|
|
5372
|
+
autoFields.push({ name: "resourceType", value: JSON.stringify(snapshot.base.name) });
|
|
5297
5373
|
}
|
|
5298
5374
|
for (const [name, field] of Object.entries(fields)) {
|
|
5299
5375
|
if (field.excluded) continue;
|
|
@@ -5335,7 +5411,7 @@ var collectProfileFactoryInfo = (tsIndex, flatProfile) => {
|
|
|
5335
5411
|
}
|
|
5336
5412
|
collectBaseRequiredParams(
|
|
5337
5413
|
tsIndex,
|
|
5338
|
-
|
|
5414
|
+
snapshot,
|
|
5339
5415
|
resolveRef,
|
|
5340
5416
|
params,
|
|
5341
5417
|
[
|
|
@@ -5346,12 +5422,13 @@ var collectProfileFactoryInfo = (tsIndex, flatProfile) => {
|
|
|
5346
5422
|
],
|
|
5347
5423
|
isFamilyType
|
|
5348
5424
|
);
|
|
5349
|
-
const accessors =
|
|
5350
|
-
|
|
5425
|
+
const { accessors: choiceAccessors, choiceClearMethods } = collectChoiceAccessors(snapshot, promotedChoices);
|
|
5426
|
+
const accessors = [...autoAccessors, ...choiceAccessors];
|
|
5427
|
+
return { autoFields, sliceAutoFields, params, accessors, choiceClearMethods, fixedFields };
|
|
5351
5428
|
};
|
|
5352
|
-
var collectBaseRequiredParams = (tsIndex,
|
|
5429
|
+
var collectBaseRequiredParams = (tsIndex, snapshot, resolveRef, params, coveredNames, isFamilyType) => {
|
|
5353
5430
|
const covered = new Set(coveredNames);
|
|
5354
|
-
const baseSchema = tsIndex.resolveType(
|
|
5431
|
+
const baseSchema = tsIndex.resolveType(snapshot.base);
|
|
5355
5432
|
if (!baseSchema || !("fields" in baseSchema) || !baseSchema.fields) return;
|
|
5356
5433
|
for (const [name, field] of Object.entries(baseSchema.fields)) {
|
|
5357
5434
|
if (covered.has(name)) continue;
|
|
@@ -5364,14 +5441,14 @@ var collectBaseRequiredParams = (tsIndex, flatProfile, resolveRef, params, cover
|
|
|
5364
5441
|
}
|
|
5365
5442
|
}
|
|
5366
5443
|
};
|
|
5367
|
-
var generateProfileIndexFile = (w, tsIndex,
|
|
5368
|
-
if (
|
|
5444
|
+
var generateProfileIndexFile = (w, tsIndex, snapshots) => {
|
|
5445
|
+
if (snapshots.length === 0) return;
|
|
5369
5446
|
w.cd("profiles", () => {
|
|
5370
5447
|
w.cat("index.ts", () => {
|
|
5371
5448
|
const exports$1 = /* @__PURE__ */ new Map();
|
|
5372
|
-
for (const
|
|
5373
|
-
const className = tsProfileClassName(
|
|
5374
|
-
const moduleName = tsProfileModuleName(tsIndex,
|
|
5449
|
+
for (const snapshot of snapshots) {
|
|
5450
|
+
const className = tsProfileClassName(snapshot);
|
|
5451
|
+
const moduleName = tsProfileModuleName(tsIndex, snapshot);
|
|
5375
5452
|
if (!exports$1.has(className)) {
|
|
5376
5453
|
exports$1.set(className, `export { ${className} } from "./${moduleName}"`);
|
|
5377
5454
|
}
|
|
@@ -5382,14 +5459,15 @@ var generateProfileIndexFile = (w, tsIndex, initialProfiles) => {
|
|
|
5382
5459
|
});
|
|
5383
5460
|
});
|
|
5384
5461
|
};
|
|
5385
|
-
var generateProfileHelpersImport = (w, tsIndex,
|
|
5386
|
-
const extensions =
|
|
5387
|
-
const hasMeta = tsIndex.isWithMetaField(
|
|
5388
|
-
const canonicalUrl =
|
|
5462
|
+
var generateProfileHelpersImport = (w, tsIndex, snapshot, sliceDefs, factoryInfo) => {
|
|
5463
|
+
const extensions = snapshot.extensions ?? [];
|
|
5464
|
+
const hasMeta = tsIndex.isWithMetaField(snapshot);
|
|
5465
|
+
const canonicalUrl = snapshot.identifier.url;
|
|
5389
5466
|
const imports = [];
|
|
5390
|
-
if (
|
|
5467
|
+
if (snapshot.base.name === "Extension" && canonicalUrl && collectSubExtensionSlices(snapshot).length > 0)
|
|
5391
5468
|
imports.push("isRawExtensionInput");
|
|
5392
5469
|
if (canonicalUrl && hasMeta) imports.push("ensureProfile");
|
|
5470
|
+
if (factoryInfo.autoFields.some((f) => f.name !== "resourceType")) imports.push("applyFixedValue");
|
|
5393
5471
|
if (sliceDefs.length > 0 || factoryInfo.sliceAutoFields.length > 0)
|
|
5394
5472
|
imports.push("applySliceMatch", "matchesValue", "setArraySlice", "getArraySlice", "ensureSliceDefaults");
|
|
5395
5473
|
const hasUnboundedSlice = sliceDefs.some((s) => s.array && (s.max === 0 || s.max === void 0));
|
|
@@ -5401,7 +5479,7 @@ var generateProfileHelpersImport = (w, tsIndex, flatProfile, sliceDefs, factoryI
|
|
|
5401
5479
|
imports.push("isExtension", "getExtensionValue", "pushExtension");
|
|
5402
5480
|
if (extensions.some((ext) => ext.url && ext.max === "1")) imports.push("upsertExtension");
|
|
5403
5481
|
}
|
|
5404
|
-
if (Object.keys(
|
|
5482
|
+
if (Object.keys(snapshot.fields).length > 0 || (snapshot.inheritedRequiredFields?.length ?? 0) > 0)
|
|
5405
5483
|
imports.push(
|
|
5406
5484
|
"validateRequired",
|
|
5407
5485
|
"validateExcluded",
|
|
@@ -5418,7 +5496,7 @@ var generateProfileHelpersImport = (w, tsIndex, flatProfile, sliceDefs, factoryI
|
|
|
5418
5496
|
w.line();
|
|
5419
5497
|
}
|
|
5420
5498
|
};
|
|
5421
|
-
var generateProfileImports = (w, tsIndex,
|
|
5499
|
+
var generateProfileImports = (w, tsIndex, snapshot) => {
|
|
5422
5500
|
const usedTypes = /* @__PURE__ */ new Map();
|
|
5423
5501
|
const getModulePath = (typeId) => {
|
|
5424
5502
|
if (isNestedIdentifier(typeId)) {
|
|
@@ -5434,17 +5512,17 @@ var generateProfileImports = (w, tsIndex, flatProfile) => {
|
|
|
5434
5512
|
usedTypes.set(tsName, { importPath: getModulePath(typeId), tsName });
|
|
5435
5513
|
}
|
|
5436
5514
|
};
|
|
5437
|
-
addType(
|
|
5438
|
-
collectTypesFromSlices(tsIndex,
|
|
5439
|
-
const needsExtensionType = collectTypesFromExtensions(tsIndex,
|
|
5440
|
-
collectTypesFromFlatInput(tsIndex,
|
|
5441
|
-
const factoryInfo = collectProfileFactoryInfo(tsIndex,
|
|
5515
|
+
addType(snapshot.base);
|
|
5516
|
+
collectTypesFromSlices(tsIndex, snapshot, addType);
|
|
5517
|
+
const needsExtensionType = collectTypesFromExtensions(tsIndex, snapshot, addType);
|
|
5518
|
+
collectTypesFromFlatInput(tsIndex, snapshot, addType);
|
|
5519
|
+
const factoryInfo = collectProfileFactoryInfo(tsIndex, snapshot);
|
|
5442
5520
|
for (const param of factoryInfo.params) addType(param.typeId);
|
|
5443
5521
|
for (const f of factoryInfo.sliceAutoFields) addType(f.typeId);
|
|
5444
5522
|
for (const accessor of factoryInfo.accessors) addType(accessor.typeId);
|
|
5445
5523
|
if (needsExtensionType) {
|
|
5446
5524
|
const extensionUrl = "http://hl7.org/fhir/StructureDefinition/Extension";
|
|
5447
|
-
const extensionSchema = tsIndex.resolveByUrl(
|
|
5525
|
+
const extensionSchema = tsIndex.resolveByUrl(snapshot.identifier.package, extensionUrl);
|
|
5448
5526
|
if (extensionSchema) addType(extensionSchema.identifier);
|
|
5449
5527
|
}
|
|
5450
5528
|
const grouped = /* @__PURE__ */ new Map();
|
|
@@ -5462,12 +5540,12 @@ var generateProfileImports = (w, tsIndex, flatProfile) => {
|
|
|
5462
5540
|
}
|
|
5463
5541
|
if (sortedModules.length > 0) w.line();
|
|
5464
5542
|
const extProfileImports = /* @__PURE__ */ new Map();
|
|
5465
|
-
for (const ext of
|
|
5543
|
+
for (const ext of snapshot.extensions ?? []) {
|
|
5466
5544
|
if (!ext.url) continue;
|
|
5467
|
-
const info = resolveExtensionProfile(tsIndex,
|
|
5545
|
+
const info = resolveExtensionProfile(tsIndex, snapshot.identifier.package, ext.url);
|
|
5468
5546
|
if (!info) continue;
|
|
5469
5547
|
if (!extProfileImports.has(info.className)) {
|
|
5470
|
-
const hasFlatInput = collectSubExtensionSlices(info.
|
|
5548
|
+
const hasFlatInput = collectSubExtensionSlices(info.snapshot).length > 0;
|
|
5471
5549
|
extProfileImports.set(info.className, { modulePath: info.modulePath, hasFlatInput });
|
|
5472
5550
|
}
|
|
5473
5551
|
}
|
|
@@ -5496,10 +5574,10 @@ var generateStaticSliceFields = (w, sliceDefs) => {
|
|
|
5496
5574
|
}
|
|
5497
5575
|
if (sliceDefs.length > 0) w.line();
|
|
5498
5576
|
};
|
|
5499
|
-
var generateFactoryMethods = (w, tsIndex,
|
|
5500
|
-
const profileClassName = tsProfileClassName(
|
|
5501
|
-
const tsBaseResourceName = tsTypeFromIdentifier(
|
|
5502
|
-
const hasMeta = tsIndex.isWithMetaField(
|
|
5577
|
+
var generateFactoryMethods = (w, tsIndex, snapshot, factoryInfo) => {
|
|
5578
|
+
const profileClassName = tsProfileClassName(snapshot);
|
|
5579
|
+
const tsBaseResourceName = tsTypeFromIdentifier(snapshot.base);
|
|
5580
|
+
const hasMeta = tsIndex.isWithMetaField(snapshot);
|
|
5503
5581
|
const hasParams = factoryInfo.params.length > 0 || factoryInfo.sliceAutoFields.length > 0;
|
|
5504
5582
|
const createArgsTypeName = `${profileClassName}Raw`;
|
|
5505
5583
|
const paramSignature = hasParams ? `args: ${createArgsTypeName}` : "";
|
|
@@ -5526,13 +5604,13 @@ var generateFactoryMethods = (w, tsIndex, flatProfile, factoryInfo) => {
|
|
|
5526
5604
|
w.lineSM("return profile");
|
|
5527
5605
|
});
|
|
5528
5606
|
w.line();
|
|
5529
|
-
const canEmitIs = hasMeta && isResourceIdentifier(
|
|
5607
|
+
const canEmitIs = hasMeta && isResourceIdentifier(snapshot.base) || snapshot.base.name === "Extension";
|
|
5530
5608
|
if (canEmitIs) {
|
|
5531
5609
|
w.curlyBlock(["static", "is", "(resource: unknown)", `: resource is ${tsBaseResourceName}`], () => {
|
|
5532
5610
|
w.line(`if (typeof resource !== "object" || resource === null) return false;`);
|
|
5533
|
-
if (hasMeta && isResourceIdentifier(
|
|
5611
|
+
if (hasMeta && isResourceIdentifier(snapshot.base)) {
|
|
5534
5612
|
w.line(`const r = resource as { resourceType?: string; meta?: { profile?: string[] } };`);
|
|
5535
|
-
w.line(`if (r.resourceType !== ${JSON.stringify(
|
|
5613
|
+
w.line(`if (r.resourceType !== ${JSON.stringify(snapshot.base.name)}) return false;`);
|
|
5536
5614
|
w.lineSM(`return (r.meta?.profile ?? []).includes(${profileClassName}.canonicalUrl)`);
|
|
5537
5615
|
} else {
|
|
5538
5616
|
w.lineSM(`return (resource as { url?: string }).url === ${profileClassName}.canonicalUrl`);
|
|
@@ -5544,16 +5622,14 @@ var generateFactoryMethods = (w, tsIndex, flatProfile, factoryInfo) => {
|
|
|
5544
5622
|
if (hasMeta) {
|
|
5545
5623
|
w.lineSM(`ensureProfile(resource, ${profileClassName}.canonicalUrl)`);
|
|
5546
5624
|
}
|
|
5547
|
-
if (
|
|
5625
|
+
if (snapshot.base.name === "Extension" && snapshot.identifier.url) {
|
|
5548
5626
|
w.lineSM(`resource.url = ${profileClassName}.canonicalUrl`);
|
|
5549
5627
|
}
|
|
5550
5628
|
const applyAutoFields = factoryInfo.autoFields.filter((f) => f.name !== "resourceType");
|
|
5551
5629
|
if (applyAutoFields.length > 0) {
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
}
|
|
5556
|
-
}, [")"]);
|
|
5630
|
+
for (const f of applyAutoFields) {
|
|
5631
|
+
w.lineSM(`applyFixedValue(resource, ${JSON.stringify(f.name)}, ${f.value})`);
|
|
5632
|
+
}
|
|
5557
5633
|
}
|
|
5558
5634
|
for (const f of factoryInfo.sliceAutoFields) {
|
|
5559
5635
|
const matchRefs = f.sliceNames.map((s) => `${profileClassName}.${tsSliceStaticName(s)}SliceMatch`);
|
|
@@ -5569,7 +5645,7 @@ var generateFactoryMethods = (w, tsIndex, flatProfile, factoryInfo) => {
|
|
|
5569
5645
|
w.lineSM(`return new ${profileClassName}(resource)`);
|
|
5570
5646
|
});
|
|
5571
5647
|
w.line();
|
|
5572
|
-
const subSlicesForInput =
|
|
5648
|
+
const subSlicesForInput = snapshot.base.name === "Extension" ? collectSubExtensionSlices(snapshot) : [];
|
|
5573
5649
|
const hasInputHelper = subSlicesForInput.length > 0;
|
|
5574
5650
|
if (hasInputHelper) {
|
|
5575
5651
|
const rawInputTypeName = `${profileClassName}Raw`;
|
|
@@ -5669,7 +5745,7 @@ var generateFactoryMethods = (w, tsIndex, flatProfile, factoryInfo) => {
|
|
|
5669
5745
|
if (factoryInfo.sliceAutoFields.length > 0) {
|
|
5670
5746
|
w.line();
|
|
5671
5747
|
}
|
|
5672
|
-
if (isPrimitiveIdentifier(
|
|
5748
|
+
if (isPrimitiveIdentifier(snapshot.base)) {
|
|
5673
5749
|
w.lineSM(`const resource = undefined as unknown as ${tsBaseResourceName}`);
|
|
5674
5750
|
} else {
|
|
5675
5751
|
const hasMetaParam = allFields.some((f) => f.name === "meta");
|
|
@@ -5726,20 +5802,27 @@ var generateFieldAccessors = (w, factoryInfo) => {
|
|
|
5726
5802
|
w.line();
|
|
5727
5803
|
if (!factoryInfo.fixedFields.has(a.name)) {
|
|
5728
5804
|
w.curlyBlock([`set${methodBaseName}`, `(value: ${a.tsType})`, ": this"], () => {
|
|
5805
|
+
if (a.choiceClearMethod) w.lineSM(`this.${a.choiceClearMethod}()`);
|
|
5729
5806
|
w.lineSM(`Object.assign(this.resource, { ${fieldAccess}: value })`);
|
|
5730
5807
|
w.lineSM("return this");
|
|
5731
5808
|
});
|
|
5732
5809
|
w.line();
|
|
5733
5810
|
}
|
|
5734
5811
|
}
|
|
5812
|
+
for (const { method, variants } of factoryInfo.choiceClearMethods) {
|
|
5813
|
+
w.curlyBlock([method, "()", ": void"], () => {
|
|
5814
|
+
for (const variant of variants) w.lineSM(`delete ${tsGet("this.resource", variant)}`);
|
|
5815
|
+
});
|
|
5816
|
+
w.line();
|
|
5817
|
+
}
|
|
5735
5818
|
};
|
|
5736
|
-
var generateInlineExtensionInputTypes = (w, tsIndex,
|
|
5737
|
-
const tsProfileName = tsResourceName(
|
|
5738
|
-
const complexExtensions = (
|
|
5819
|
+
var generateInlineExtensionInputTypes = (w, tsIndex, snapshot) => {
|
|
5820
|
+
const tsProfileName = tsResourceName(snapshot.identifier);
|
|
5821
|
+
const complexExtensions = (snapshot.extensions ?? []).filter((ext) => ext.isComplex && ext.subExtensions);
|
|
5739
5822
|
for (const ext of complexExtensions) {
|
|
5740
5823
|
if (!ext.url) continue;
|
|
5741
|
-
const extProfileInfo = resolveExtensionProfile(tsIndex,
|
|
5742
|
-
const hasFlatInput = extProfileInfo ? collectSubExtensionSlices(extProfileInfo.
|
|
5824
|
+
const extProfileInfo = resolveExtensionProfile(tsIndex, snapshot.identifier.package, ext.url);
|
|
5825
|
+
const hasFlatInput = extProfileInfo ? collectSubExtensionSlices(extProfileInfo.snapshot).length > 0 : false;
|
|
5743
5826
|
if (hasFlatInput) continue;
|
|
5744
5827
|
const typeName = tsExtensionFlatTypeName(tsProfileName, ext.name);
|
|
5745
5828
|
w.curlyBlock(["export", "type", typeName, "="], () => {
|
|
@@ -5764,9 +5847,9 @@ var valueToTypeLiteral = (value) => {
|
|
|
5764
5847
|
}
|
|
5765
5848
|
return "unknown";
|
|
5766
5849
|
};
|
|
5767
|
-
var generateSliceInputTypes = (w,
|
|
5850
|
+
var generateSliceInputTypes = (w, snapshot, sliceDefs) => {
|
|
5768
5851
|
if (sliceDefs.length === 0) return;
|
|
5769
|
-
const tsProfileName = tsResourceName(
|
|
5852
|
+
const tsProfileName = tsResourceName(snapshot.identifier);
|
|
5770
5853
|
for (const sliceDef of sliceDefs) {
|
|
5771
5854
|
const inputTypeName = tsSliceFlatTypeName(tsProfileName, sliceDef.fieldName, sliceDef.sliceName);
|
|
5772
5855
|
const flatTypeName = tsSliceFlatAllTypeName(tsProfileName, sliceDef.fieldName, sliceDef.sliceName);
|
|
@@ -5809,11 +5892,11 @@ var generateSliceInputTypes = (w, flatProfile, sliceDefs) => {
|
|
|
5809
5892
|
w.line();
|
|
5810
5893
|
}
|
|
5811
5894
|
};
|
|
5812
|
-
var generateRawType = (w,
|
|
5895
|
+
var generateRawType = (w, snapshot, factoryInfo) => {
|
|
5813
5896
|
const hasParams = factoryInfo.params.length > 0 || factoryInfo.sliceAutoFields.length > 0;
|
|
5814
|
-
const subSlices =
|
|
5897
|
+
const subSlices = snapshot.base.name === "Extension" ? collectSubExtensionSlices(snapshot) : [];
|
|
5815
5898
|
if (!hasParams && subSlices.length === 0) return;
|
|
5816
|
-
const createArgsTypeName = `${tsProfileClassName(
|
|
5899
|
+
const createArgsTypeName = `${tsProfileClassName(snapshot)}Raw`;
|
|
5817
5900
|
w.curlyBlock(["export", "type", createArgsTypeName, "="], () => {
|
|
5818
5901
|
for (const p of factoryInfo.params) {
|
|
5819
5902
|
w.lineSM(`${p.name}: ${p.tsType}`);
|
|
@@ -5828,10 +5911,10 @@ var generateRawType = (w, flatProfile, factoryInfo) => {
|
|
|
5828
5911
|
});
|
|
5829
5912
|
w.line();
|
|
5830
5913
|
};
|
|
5831
|
-
var generateFlatInputType = (w,
|
|
5832
|
-
const subSlices =
|
|
5914
|
+
var generateFlatInputType = (w, snapshot) => {
|
|
5915
|
+
const subSlices = snapshot.base.name === "Extension" ? collectSubExtensionSlices(snapshot) : [];
|
|
5833
5916
|
if (subSlices.length === 0) return;
|
|
5834
|
-
const flatInputTypeName = `${tsProfileClassName(
|
|
5917
|
+
const flatInputTypeName = `${tsProfileClassName(snapshot)}Flat`;
|
|
5835
5918
|
w.curlyBlock(["export", "type", flatInputTypeName, "="], () => {
|
|
5836
5919
|
for (const sub of subSlices) {
|
|
5837
5920
|
const opt = sub.isRequired ? "" : "?";
|
|
@@ -5841,33 +5924,33 @@ var generateFlatInputType = (w, flatProfile) => {
|
|
|
5841
5924
|
});
|
|
5842
5925
|
w.line();
|
|
5843
5926
|
};
|
|
5844
|
-
var generateProfileClass = (w, tsIndex,
|
|
5845
|
-
const tsBaseResourceName = tsTypeFromIdentifier(
|
|
5846
|
-
const profileClassName = tsProfileClassName(
|
|
5847
|
-
const sliceDefs = collectSliceDefs(tsIndex,
|
|
5848
|
-
const factoryInfo = collectProfileFactoryInfo(tsIndex,
|
|
5849
|
-
generateInlineExtensionInputTypes(w, tsIndex,
|
|
5850
|
-
generateSliceInputTypes(w,
|
|
5851
|
-
generateProfileHelpersImport(w, tsIndex,
|
|
5852
|
-
generateRawType(w,
|
|
5853
|
-
generateFlatInputType(w,
|
|
5854
|
-
const canonicalUrl =
|
|
5855
|
-
w.comment("CanonicalURL:", canonicalUrl, `(pkg: ${packageMetaToFhir(packageMeta(
|
|
5927
|
+
var generateProfileClass = (w, tsIndex, snapshot) => {
|
|
5928
|
+
const tsBaseResourceName = tsTypeFromIdentifier(snapshot.base);
|
|
5929
|
+
const profileClassName = tsProfileClassName(snapshot);
|
|
5930
|
+
const sliceDefs = collectSliceDefs(tsIndex, snapshot);
|
|
5931
|
+
const factoryInfo = collectProfileFactoryInfo(tsIndex, snapshot);
|
|
5932
|
+
generateInlineExtensionInputTypes(w, tsIndex, snapshot);
|
|
5933
|
+
generateSliceInputTypes(w, snapshot, sliceDefs);
|
|
5934
|
+
generateProfileHelpersImport(w, tsIndex, snapshot, sliceDefs, factoryInfo);
|
|
5935
|
+
generateRawType(w, snapshot, factoryInfo);
|
|
5936
|
+
generateFlatInputType(w, snapshot);
|
|
5937
|
+
const canonicalUrl = snapshot.identifier.url;
|
|
5938
|
+
w.comment("CanonicalURL:", canonicalUrl, `(pkg: ${packageMetaToFhir(packageMeta(snapshot))})`);
|
|
5856
5939
|
w.curlyBlock(["export", "class", profileClassName], () => {
|
|
5857
5940
|
w.lineSM(`static readonly canonicalUrl = ${JSON.stringify(canonicalUrl)}`);
|
|
5858
5941
|
w.line();
|
|
5859
5942
|
generateStaticSliceFields(w, sliceDefs);
|
|
5860
5943
|
w.lineSM(`private resource: ${tsBaseResourceName}`);
|
|
5861
5944
|
w.line();
|
|
5862
|
-
generateFactoryMethods(w, tsIndex,
|
|
5945
|
+
generateFactoryMethods(w, tsIndex, snapshot, factoryInfo);
|
|
5863
5946
|
generateFieldAccessors(w, factoryInfo);
|
|
5864
5947
|
w.line("// Extensions");
|
|
5865
|
-
generateExtensionMethods(w, tsIndex,
|
|
5948
|
+
generateExtensionMethods(w, tsIndex, snapshot);
|
|
5866
5949
|
w.line("// Slices");
|
|
5867
|
-
generateSliceSetters(w, sliceDefs,
|
|
5868
|
-
generateSliceGetters(w, sliceDefs,
|
|
5950
|
+
generateSliceSetters(w, sliceDefs, snapshot);
|
|
5951
|
+
generateSliceGetters(w, sliceDefs, snapshot);
|
|
5869
5952
|
w.line("// Validation");
|
|
5870
|
-
generateValidateMethod(w, tsIndex,
|
|
5953
|
+
generateValidateMethod(w, tsIndex, snapshot);
|
|
5871
5954
|
});
|
|
5872
5955
|
w.line();
|
|
5873
5956
|
};
|
|
@@ -5921,13 +6004,13 @@ var TypeScript = class extends Writer {
|
|
|
5921
6004
|
}
|
|
5922
6005
|
generateFhirPackageIndexFile(schemas) {
|
|
5923
6006
|
this.cat("index.ts", () => {
|
|
5924
|
-
const profiles = schemas.filter(
|
|
6007
|
+
const profiles = schemas.filter(isSnapshotProfileTypeSchema);
|
|
5925
6008
|
if (profiles.length > 0) {
|
|
5926
6009
|
this.lineSM(`export * from "./profiles"`);
|
|
5927
6010
|
}
|
|
5928
6011
|
let exports$1 = schemas.flatMap((schema) => {
|
|
5929
6012
|
const resourceName = tsResourceName(schema.identifier);
|
|
5930
|
-
const typeExports =
|
|
6013
|
+
const typeExports = isSnapshotProfileTypeSchema(schema) ? [] : [
|
|
5931
6014
|
resourceName,
|
|
5932
6015
|
...isResourceTypeSchema(schema) && schema.nested || isLogicalTypeSchema(schema) && schema.nested ? schema.nested.map((n) => tsResourceName(n.identifier)) : []
|
|
5933
6016
|
];
|
|
@@ -6106,13 +6189,12 @@ var TypeScript = class extends Writer {
|
|
|
6106
6189
|
}
|
|
6107
6190
|
}
|
|
6108
6191
|
generateResourceModule(tsIndex, schema) {
|
|
6109
|
-
if (
|
|
6192
|
+
if (isSnapshotProfileTypeSchema(schema)) {
|
|
6110
6193
|
this.cd("profiles", () => {
|
|
6111
6194
|
this.cat(`${tsProfileModuleFileName(tsIndex, schema)}`, () => {
|
|
6112
6195
|
this.generateDisclaimer();
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
generateProfileClass(this, tsIndex, flatProfile);
|
|
6196
|
+
generateProfileImports(this, tsIndex, schema);
|
|
6197
|
+
generateProfileClass(this, tsIndex, schema);
|
|
6116
6198
|
});
|
|
6117
6199
|
});
|
|
6118
6200
|
} else if (isSpecializationTypeSchema(schema)) {
|
|
@@ -6139,10 +6221,10 @@ var TypeScript = class extends Writer {
|
|
|
6139
6221
|
...tsIndex.collectComplexTypes(),
|
|
6140
6222
|
...tsIndex.collectResources(),
|
|
6141
6223
|
...tsIndex.collectLogicalModels(),
|
|
6142
|
-
...this.opts.generateProfile ? tsIndex.
|
|
6224
|
+
...this.opts.generateProfile ? tsIndex.collectSnapshotProfiles() : []
|
|
6143
6225
|
];
|
|
6144
6226
|
const grouped = groupByPackages(typesToGenerate);
|
|
6145
|
-
const hasProfiles = this.opts.generateProfile && typesToGenerate.some(
|
|
6227
|
+
const hasProfiles = this.opts.generateProfile && typesToGenerate.some(isSnapshotProfileTypeSchema);
|
|
6146
6228
|
this.cd("/", () => {
|
|
6147
6229
|
if (hasProfiles) {
|
|
6148
6230
|
this.cp("profile-helpers.ts", "profile-helpers.ts");
|
|
@@ -6153,7 +6235,7 @@ var TypeScript = class extends Writer {
|
|
|
6153
6235
|
for (const schema of packageSchemas) {
|
|
6154
6236
|
this.generateResourceModule(tsIndex, schema);
|
|
6155
6237
|
}
|
|
6156
|
-
generateProfileIndexFile(this, tsIndex, packageSchemas.filter(
|
|
6238
|
+
generateProfileIndexFile(this, tsIndex, packageSchemas.filter(isSnapshotProfileTypeSchema));
|
|
6157
6239
|
this.generateFhirPackageIndexFile(packageSchemas);
|
|
6158
6240
|
});
|
|
6159
6241
|
}
|