Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"homepage": "https://github.com/atomic-ehr/codegen#readme",
"dependencies": {
"@atomic-ehr/fhir-canonical-manager": "^0.0.21",
"@atomic-ehr/fhirschema": "^0.0.8",
"@atomic-ehr/fhirschema": "0.0.9",
"mustache": "^4.2.0",
"picocolors": "^1.1.1",
"tinyglobby": "^0.2.15",
Expand Down
62 changes: 62 additions & 0 deletions src/fhir-types/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2576,3 +2576,65 @@ Skipped fields:
- `urn:fhir:binding:validation-process`
- `urn:fhir:binding:validation-status`
- `urn:fhir:binding:validation-type`

## Schema Collisions

The following canonicals have multiple schema versions with different content.
To inspect collision versions, export TypeSchemas using `.introspection({ typeSchemas: 'path' })`
and check `<pkg>/collisions/<name>/1.json, 2.json, ...` files.

### `shared`

- `urn:fhir:binding:CommunicationReason` (2 versions)
- Version 1 (auto): Communication (hl7.fhir.r4.core#4.0.1)
- Version 2: CommunicationRequest (hl7.fhir.r4.core#4.0.1)
- `urn:fhir:binding:ObservationCategory` (2 versions)
- Version 1 (auto): Observation (hl7.fhir.r4.core#4.0.1), vitalsigns (hl7.fhir.r4.core#4.0.1)
- Version 2: ObservationDefinition (hl7.fhir.r4.core#4.0.1)
- `urn:fhir:binding:ObservationRangeMeaning` (2 versions)
- Version 1 (auto): cholesterol (hl7.fhir.r4.core#4.0.1), hdlcholesterol (hl7.fhir.r4.core#4.0.1), ldlcholesterol (hl7.fhir.r4.core#4.0.1), Observation (hl7.fhir.r4.core#4.0.1), triglyceride (hl7.fhir.r4.core#4.0.1)
- Version 2: ObservationDefinition (hl7.fhir.r4.core#4.0.1)
- `urn:fhir:binding:PaymentType` (2 versions)
- Version 1 (auto): ClaimResponse (hl7.fhir.r4.core#4.0.1), ExplanationOfBenefit (hl7.fhir.r4.core#4.0.1)
- Version 2: PaymentReconciliation (hl7.fhir.r4.core#4.0.1)
- `urn:fhir:binding:ProcessPriority` (2 versions)
- Version 1 (auto): Claim (hl7.fhir.r4.core#4.0.1), CoverageEligibilityRequest (hl7.fhir.r4.core#4.0.1)
- Version 2: ExplanationOfBenefit (hl7.fhir.r4.core#4.0.1)
- `urn:fhir:binding:TargetDisease` (2 versions)
- Version 1 (auto): Immunization (hl7.fhir.r4.core#4.0.1)
- Version 2: ImmunizationRecommendation (hl7.fhir.r4.core#4.0.1)

### Suggested `resolveCollisions` config

Add to `.typeSchema({ resolveCollisions: { ... } })` to resolve remaining collisions:

```typescript
.typeSchema({
resolveCollisions: {
"urn:fhir:binding:CommunicationReason": {
package: "hl7.fhir.r4.core#4.0.1",
canonical: "http://hl7.org/fhir/StructureDefinition/Communication",
},
"urn:fhir:binding:ObservationCategory": {
package: "hl7.fhir.r4.core#4.0.1",
canonical: "http://hl7.org/fhir/StructureDefinition/Observation",
},
"urn:fhir:binding:ObservationRangeMeaning": {
package: "hl7.fhir.r4.core#4.0.1",
canonical: "http://hl7.org/fhir/StructureDefinition/cholesterol",
},
"urn:fhir:binding:PaymentType": {
package: "hl7.fhir.r4.core#4.0.1",
canonical: "http://hl7.org/fhir/StructureDefinition/ClaimResponse",
},
"urn:fhir:binding:ProcessPriority": {
package: "hl7.fhir.r4.core#4.0.1",
canonical: "http://hl7.org/fhir/StructureDefinition/Claim",
},
"urn:fhir:binding:TargetDisease": {
package: "hl7.fhir.r4.core#4.0.1",
canonical: "http://hl7.org/fhir/StructureDefinition/Immunization",
},
},
})
```
2 changes: 1 addition & 1 deletion src/fhir-types/hl7-fhir-r4-core/Attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface Attachment extends Element {
creation?: string;
data?: string;
hash?: string;
language?: string;
language?: ("ar" | "bn" | "cs" | "da" | "de" | "de-AT" | "de-CH" | "de-DE" | "el" | "en" | "en-AU" | "en-CA" | "en-GB" | "en-IN" | "en-NZ" | "en-SG" | "en-US" | "es" | "es-AR" | "es-ES" | "es-UY" | "fi" | "fr" | "fr-BE" | "fr-CH" | "fr-FR" | "fy" | "fy-NL" | "hi" | "hr" | "it" | "it-CH" | "it-IT" | "ja" | "ko" | "nl" | "nl-BE" | "nl-NL" | "no" | "no-NO" | "pa" | "pl" | "pt" | "pt-BR" | "ru" | "ru-RU" | "sr" | "sr-RS" | "sv" | "sv-SE" | "te" | "zh" | "zh-CN" | "zh-HK" | "zh-SG" | "zh-TW" | string);
size?: number;
title?: string;
url?: string;
Expand Down
4 changes: 2 additions & 2 deletions src/fhir-types/hl7-fhir-r4-core/CodeSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export interface CodeSystemConcept extends BackboneElement {
}

export interface CodeSystemConceptDesignation extends BackboneElement {
language?: string;
use?: Coding;
language?: ("ar" | "bn" | "cs" | "da" | "de" | "de-AT" | "de-CH" | "de-DE" | "el" | "en" | "en-AU" | "en-CA" | "en-GB" | "en-IN" | "en-NZ" | "en-SG" | "en-US" | "es" | "es-AR" | "es-ES" | "es-UY" | "fi" | "fr" | "fr-BE" | "fr-CH" | "fr-FR" | "fy" | "fy-NL" | "hi" | "hr" | "it" | "it-CH" | "it-IT" | "ja" | "ko" | "nl" | "nl-BE" | "nl-NL" | "no" | "no-NO" | "pa" | "pl" | "pt" | "pt-BR" | "ru" | "ru-RU" | "sr" | "sr-RS" | "sv" | "sv-SE" | "te" | "zh" | "zh-CN" | "zh-HK" | "zh-SG" | "zh-TW" | string);
use?: Coding<("900000000000003001" | "900000000000013009" | string)>;
value: string;
}

Expand Down
4 changes: 2 additions & 2 deletions src/fhir-types/hl7-fhir-r4-core/CodeableConcept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type { Coding } from "../hl7-fhir-r4-core/Coding";
export type { Element } from "../hl7-fhir-r4-core/Element";

// CanonicalURL: http://hl7.org/fhir/StructureDefinition/CodeableConcept (pkg: hl7.fhir.r4.core#4.0.1)
export interface CodeableConcept extends Element {
coding?: Coding[];
export interface CodeableConcept<T extends string = string> extends Element {
coding?: Coding<T>[];
text?: string;
}
4 changes: 2 additions & 2 deletions src/fhir-types/hl7-fhir-r4-core/Coding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import type { Element } from "../hl7-fhir-r4-core/Element";
export type { Element } from "../hl7-fhir-r4-core/Element";

// CanonicalURL: http://hl7.org/fhir/StructureDefinition/Coding (pkg: hl7.fhir.r4.core#4.0.1)
export interface Coding extends Element {
code?: string;
export interface Coding<T extends string = string> extends Element {
code?: T;
display?: string;
system?: string;
userSelected?: boolean;
Expand Down
6 changes: 3 additions & 3 deletions src/fhir-types/hl7-fhir-r4-core/DataRequirement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export interface DataRequirementSort extends Element {

// CanonicalURL: http://hl7.org/fhir/StructureDefinition/DataRequirement (pkg: hl7.fhir.r4.core#4.0.1)
export interface DataRequirement extends Element {
codeFilter?: Element[];
dateFilter?: Element[];
codeFilter?: DataRequirementCodeFilter[];
dateFilter?: DataRequirementDateFilter[];
limit?: number;
mustSupport?: string[];
profile?: string[];
sort?: Element[];
sort?: DataRequirementSort[];
subjectCodeableConcept?: CodeableConcept;
subjectReference?: Reference<"Group">;
type: string;
Expand Down
4 changes: 2 additions & 2 deletions src/fhir-types/hl7-fhir-r4-core/DomainResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export type { Extension } from "../hl7-fhir-r4-core/Extension";
export type { Narrative } from "../hl7-fhir-r4-core/Narrative";

// CanonicalURL: http://hl7.org/fhir/StructureDefinition/DomainResource (pkg: hl7.fhir.r4.core#4.0.1)
export interface DomainResource extends Resource {
export interface DomainResource<T extends Resource = Resource> extends Resource {
resourceType: "CodeSystem" | "DomainResource" | "StructureDefinition" | "ValueSet";

contained?: Resource[];
contained?: T[];
extension?: Extension[];
modifierExtension?: Extension[];
text?: Narrative;
Expand Down
2 changes: 1 addition & 1 deletion src/fhir-types/hl7-fhir-r4-core/Dosage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface Dosage extends BackboneElement {
additionalInstruction?: CodeableConcept[];
asNeededBoolean?: boolean;
asNeededCodeableConcept?: CodeableConcept;
doseAndRate?: Element[];
doseAndRate?: DosageDoseAndRate[];
maxDosePerAdministration?: Quantity;
maxDosePerLifetime?: Quantity;
maxDosePerPeriod?: Ratio;
Expand Down
16 changes: 8 additions & 8 deletions src/fhir-types/hl7-fhir-r4-core/ElementDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export interface ElementDefinitionMapping extends Element {

export interface ElementDefinitionSlicing extends Element {
description?: string;
discriminator?: Element[];
discriminator?: ElementDefinitionSlicingDiscriminator[];
ordered?: boolean;
rules: ("closed" | "open" | "openAtEnd");
}
Expand All @@ -176,12 +176,12 @@ export interface ElementDefinitionType extends Element {
// CanonicalURL: http://hl7.org/fhir/StructureDefinition/ElementDefinition (pkg: hl7.fhir.r4.core#4.0.1)
export interface ElementDefinition extends BackboneElement {
alias?: string[];
base?: Element;
binding?: Element;
base?: ElementDefinitionBase;
binding?: ElementDefinitionBinding;
code?: Coding[];
comment?: string;
condition?: string[];
constraint?: Element[];
constraint?: ElementDefinitionConstraint[];
contentReference?: string;
defaultValueAddress?: Address;
defaultValueAge?: Age;
Expand Down Expand Up @@ -234,7 +234,7 @@ export interface ElementDefinition extends BackboneElement {
defaultValueUsageContext?: UsageContext;
defaultValueUuid?: string;
definition?: string;
example?: Element[];
example?: ElementDefinitionExample[];
fixedAddress?: Address;
fixedAge?: Age;
fixedAnnotation?: Annotation;
Expand Down Expand Up @@ -289,7 +289,7 @@ export interface ElementDefinition extends BackboneElement {
isModifierReason?: string;
isSummary?: boolean;
label?: string;
mapping?: Element[];
mapping?: ElementDefinitionMapping[];
max?: string;
maxLength?: number;
maxValueDate?: string;
Expand Down Expand Up @@ -370,6 +370,6 @@ export interface ElementDefinition extends BackboneElement {
short?: string;
sliceIsConstraining?: boolean;
sliceName?: string;
slicing?: Element;
type?: Element[];
slicing?: ElementDefinitionSlicing;
type?: ElementDefinitionType[];
}
2 changes: 1 addition & 1 deletion src/fhir-types/hl7-fhir-r4-core/Expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type { Element } from "../hl7-fhir-r4-core/Element";
export interface Expression extends Element {
description?: string;
expression?: string;
language: string;
language: ("text/cql" | "text/fhirpath" | "application/x-fhir-query" | string);
name?: string;
reference?: string;
}
2 changes: 1 addition & 1 deletion src/fhir-types/hl7-fhir-r4-core/Identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface Identifier extends Element {
assigner?: Reference<"Organization">;
period?: Period;
system?: string;
type?: CodeableConcept;
type?: CodeableConcept<("DL" | "PPN" | "BRN" | "MR" | "MCN" | "EN" | "TAX" | "NIIP" | "PRN" | "MD" | "DR" | "ACSN" | "UDI" | "SNO" | "SB" | "PLAC" | "FILL" | "JHN" | string)>;
use?: ("usual" | "official" | "temp" | "secondary" | "old");
value?: string;
}
2 changes: 1 addition & 1 deletion src/fhir-types/hl7-fhir-r4-core/Resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface Resource {

id?: string;
implicitRules?: string;
language?: string;
language?: ("ar" | "bn" | "cs" | "da" | "de" | "de-AT" | "de-CH" | "de-DE" | "el" | "en" | "en-AU" | "en-CA" | "en-GB" | "en-IN" | "en-NZ" | "en-SG" | "en-US" | "es" | "es-AR" | "es-ES" | "es-UY" | "fi" | "fr" | "fr-BE" | "fr-CH" | "fr-FR" | "fy" | "fy-NL" | "hi" | "hr" | "it" | "it-CH" | "it-IT" | "ja" | "ko" | "nl" | "nl-BE" | "nl-NL" | "no" | "no-NO" | "pa" | "pl" | "pt" | "pt-BR" | "ru" | "ru-RU" | "sr" | "sr-RS" | "sv" | "sv-SE" | "te" | "zh" | "zh-CN" | "zh-HK" | "zh-SG" | "zh-TW" | string);
meta?: Meta;
}
export const isResource = (resource: unknown): resource is Resource => {
Expand Down
2 changes: 1 addition & 1 deletion src/fhir-types/hl7-fhir-r4-core/Signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface Signature extends Element {
onBehalfOf?: Reference<"Device" | "Organization" | "Patient" | "Practitioner" | "PractitionerRole" | "RelatedPerson">;
sigFormat?: string;
targetFormat?: string;
type: Coding[];
type: Coding<("1.2.840.10065.1.12.1.1" | "1.2.840.10065.1.12.1.2" | "1.2.840.10065.1.12.1.3" | "1.2.840.10065.1.12.1.4" | "1.2.840.10065.1.12.1.5" | "1.2.840.10065.1.12.1.6" | "1.2.840.10065.1.12.1.7" | "1.2.840.10065.1.12.1.8" | "1.2.840.10065.1.12.1.9" | "1.2.840.10065.1.12.1.10" | "1.2.840.10065.1.12.1.11" | "1.2.840.10065.1.12.1.12" | "1.2.840.10065.1.12.1.13" | "1.2.840.10065.1.12.1.14" | "1.2.840.10065.1.12.1.15" | "1.2.840.10065.1.12.1.16" | "1.2.840.10065.1.12.1.17" | "1.2.840.10065.1.12.1.18" | string)>[];
when: string;
who: Reference<"Device" | "Organization" | "Patient" | "Practitioner" | "PractitionerRole" | "RelatedPerson">;
}
2 changes: 1 addition & 1 deletion src/fhir-types/hl7-fhir-r4-core/StructureDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface StructureDefinition extends DomainResource {
fhirVersion?: ("0.01" | "0.05" | "0.06" | "0.11" | "0.0.80" | "0.0.81" | "0.0.82" | "0.4.0" | "0.5.0" | "1.0.0" | "1.0.1" | "1.0.2" | "1.1.0" | "1.4.0" | "1.6.0" | "1.8.0" | "3.0.0" | "3.0.1" | "3.3.0" | "3.5.0" | "4.0.0" | "4.0.1");
identifier?: Identifier[];
jurisdiction?: CodeableConcept[];
keyword?: Coding[];
keyword?: Coding<("fhir-structure" | "custom-resource" | "dam" | "wire-format" | "archetype" | "template" | string)>[];
kind: ("primitive-type" | "complex-type" | "resource" | "logical");
mapping?: StructureDefinitionMapping[];
name: string;
Expand Down
4 changes: 2 additions & 2 deletions src/fhir-types/hl7-fhir-r4-core/Timing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface TimingRepeat extends Element {

// CanonicalURL: http://hl7.org/fhir/StructureDefinition/Timing (pkg: hl7.fhir.r4.core#4.0.1)
export interface Timing extends BackboneElement {
code?: CodeableConcept;
code?: CodeableConcept<("BID" | "TID" | "QID" | "AM" | "PM" | "QD" | "QOD" | "Q1H" | "Q2H" | "Q3H" | "Q4H" | "Q6H" | "Q8H" | "BED" | "WK" | "MO" | string)>;
event?: string[];
repeat?: Element;
repeat?: TimingRepeat;
}
2 changes: 1 addition & 1 deletion src/fhir-types/hl7-fhir-r4-core/UsageContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type { Reference } from "../hl7-fhir-r4-core/Reference";

// CanonicalURL: http://hl7.org/fhir/StructureDefinition/UsageContext (pkg: hl7.fhir.r4.core#4.0.1)
export interface UsageContext extends Element {
code: Coding;
code: Coding<("gender" | "age" | "focus" | "user" | "workflow" | "task" | "venue" | "species" | "program" | string)>;
valueCodeableConcept?: CodeableConcept;
valueQuantity?: Quantity;
valueRange?: Range;
Expand Down
4 changes: 2 additions & 2 deletions src/fhir-types/hl7-fhir-r4-core/ValueSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export interface ValueSetComposeIncludeConcept extends BackboneElement {
}

export interface ValueSetComposeIncludeConceptDesignation extends BackboneElement {
language?: string;
use?: Coding;
language?: ("ar" | "bn" | "cs" | "da" | "de" | "de-AT" | "de-CH" | "de-DE" | "el" | "en" | "en-AU" | "en-CA" | "en-GB" | "en-IN" | "en-NZ" | "en-SG" | "en-US" | "es" | "es-AR" | "es-ES" | "es-UY" | "fi" | "fr" | "fr-BE" | "fr-CH" | "fr-FR" | "fy" | "fy-NL" | "hi" | "hr" | "it" | "it-CH" | "it-IT" | "ja" | "ko" | "nl" | "nl-BE" | "nl-NL" | "no" | "no-NO" | "pa" | "pl" | "pt" | "pt-BR" | "ru" | "ru-RU" | "sr" | "sr-RS" | "sv" | "sv-SE" | "te" | "zh" | "zh-CN" | "zh-HK" | "zh-SG" | "zh-TW" | string);
use?: Coding<("900000000000003001" | "900000000000013009" | string)>;
value: string;
}

Expand Down
16 changes: 4 additions & 12 deletions src/typeschema/core/field-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
* Functions for transforming FHIRSchema elements into TypeSchema fields
*/

import type { FHIRSchemaElement } from "@atomic-ehr/fhirschema";
import type { FHIRSchemaDiscriminator, FHIRSchemaElement } from "@atomic-ehr/fhirschema";
import type { Register } from "@root/typeschema/register";
import type { CodegenLog } from "@root/utils/log";
import { packageMetaToFhir } from "@typeschema/types";
import type {
BindingIdentifier,
DiscriminatorType,
EnumDefinition,
Field,
FieldSlice,
Expand Down Expand Up @@ -200,16 +199,9 @@ const computeTypeDiscriminatorMatch = (
* Used when a slice has an empty match but the discriminator values are nested deeper
* (e.g., component slices in BP where the discriminator crosses a nested slicing boundary).
*/
const validDiscriminatorTypes = new Set<string>(["value", "exists", "pattern", "type", "profile"]);

// TODO: Update type in FHIR Schema to prevent this casting.
const toDiscriminators = (
raw: { type: string; path: string }[] | undefined,
): { type: DiscriminatorType; path: string }[] =>
(raw ?? []).filter((d) => validDiscriminatorTypes.has(d.type)) as { type: DiscriminatorType; path: string }[];

const computeMatchFromSchema = (
discriminators: { type: DiscriminatorType; path: string }[],
discriminators: FHIRSchemaDiscriminator[],
schema: FHIRSchemaElement | undefined,
): Record<string, unknown> | undefined => {
if (!schema || !discriminators || discriminators.length === 0) return undefined;
Expand Down Expand Up @@ -239,7 +231,7 @@ const buildSlicing = (element: FHIRSchemaElement): FieldSlicing | undefined => {
min: slice.min,
max: slice.max,
match: isEmptyMatch(slice.match)
? computeMatchFromSchema(toDiscriminators(slicing.discriminator), slice.schema)
? computeMatchFromSchema(slicing.discriminator ?? [], slice.schema)
: (slice.match as Record<string, unknown> | undefined),
required,
excluded,
Expand All @@ -248,7 +240,7 @@ const buildSlicing = (element: FHIRSchemaElement): FieldSlicing | undefined => {
}

return {
discriminator: toDiscriminators(slicing.discriminator),
discriminator: slicing.discriminator ?? [],
rules: slicing.rules,
ordered: slicing.ordered,
slices: Object.keys(slices).length > 0 ? slices : undefined,
Expand Down
4 changes: 1 addition & 3 deletions src/typeschema/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,8 @@ export interface ProfileTypeSchema {
nested?: NestedTypeSchema[];
}

export type DiscriminatorType = "value" | "exists" | "pattern" | "type" | "profile";

export interface FieldSlicing {
discriminator?: { type: DiscriminatorType; path: string }[];
discriminator?: FS.FHIRSchemaDiscriminator[];
rules?: string;
ordered?: boolean;
slices?: Record<string, FieldSlice>;
Expand Down
Loading
Loading