Skip to content

Commit a4491f8

Browse files
authored
Merge pull request #33 from atomic-ehr/dog-food
Dog food: use generated types for CodeSystem and ValueSet
2 parents cfff12f + f1ba431 commit a4491f8

28 files changed

Lines changed: 550 additions & 98 deletions

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ TEST = bun test
99

1010
all: test-codegen test-typescript-r4-example test-typescript-ccda-example test-typescript-sql-on-fhir-example lint-unsafe
1111

12+
generate-types:
13+
bun run scripts/generate-types.ts
14+
1215
lint:
1316
$(LINT)
1417

biome.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"ignoreUnknown": false,
1010
"includes": [
1111
"src/**/*.ts",
12+
"!src/fhir-types/**/*.ts",
1213
"test/**/*.ts",
1314
"scripts/**/*.ts",
1415
"atomic-codegen.config.js",

scripts/generate-types.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { APIBuilder } from "../src/api/builder";
2+
3+
const builder = new APIBuilder()
4+
.throwException()
5+
.fromPackage("hl7.fhir.r4.core", "4.0.1")
6+
.typescript({
7+
withDebugComment: false,
8+
generateProfile: false,
9+
primitiveTypeExtension: false,
10+
})
11+
.outputTo("./src/fhir-types")
12+
.treeShake({
13+
"hl7.fhir.r4.core": {
14+
"http://hl7.org/fhir/StructureDefinition/ValueSet": {},
15+
"http://hl7.org/fhir/StructureDefinition/CodeSystem": {},
16+
"http://hl7.org/fhir/StructureDefinition/DomainResource": {
17+
ignoreFields: ["extension", "modifierExtension"],
18+
},
19+
"http://hl7.org/fhir/StructureDefinition/BackboneElement": {
20+
ignoreFields: ["modifierExtension"],
21+
},
22+
"http://hl7.org/fhir/StructureDefinition/Element": {
23+
ignoreFields: ["extension"],
24+
},
25+
},
26+
})
27+
.cleanOutput(true);
28+
29+
const report = await builder.generate();
30+
if (report.success) {
31+
console.log("✅ FHIR types generated successfully!");
32+
} else {
33+
console.error("❌ FHIR types generation failed.");
34+
process.exit(1);
35+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// WARNING: This file is autogenerated by @atomic-ehr/codegen.
2+
// GitHub: https://github.com/atomic-ehr/codegen
3+
// Any manual changes made to this file may be overwritten.
4+
5+
import type { Element } from "../hl7-fhir-r4-core/Element";
6+
7+
export type { Element } from "../hl7-fhir-r4-core/Element";
8+
9+
// CanonicalURL: http://hl7.org/fhir/StructureDefinition/BackboneElement
10+
export interface BackboneElement extends Element {
11+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// WARNING: This file is autogenerated by @atomic-ehr/codegen.
2+
// GitHub: https://github.com/atomic-ehr/codegen
3+
// Any manual changes made to this file may be overwritten.
4+
5+
import type { BackboneElement } from "../hl7-fhir-r4-core/BackboneElement";
6+
import type { CodeableConcept } from "../hl7-fhir-r4-core/CodeableConcept";
7+
import type { Coding } from "../hl7-fhir-r4-core/Coding";
8+
import type { ContactDetail } from "../hl7-fhir-r4-core/ContactDetail";
9+
import type { DomainResource } from "../hl7-fhir-r4-core/DomainResource";
10+
import type { Identifier } from "../hl7-fhir-r4-core/Identifier";
11+
import type { UsageContext } from "../hl7-fhir-r4-core/UsageContext";
12+
13+
export type { BackboneElement } from "../hl7-fhir-r4-core/BackboneElement";
14+
export type { CodeableConcept } from "../hl7-fhir-r4-core/CodeableConcept";
15+
export type { Coding } from "../hl7-fhir-r4-core/Coding";
16+
export type { ContactDetail } from "../hl7-fhir-r4-core/ContactDetail";
17+
export type { Identifier } from "../hl7-fhir-r4-core/Identifier";
18+
export type { UsageContext } from "../hl7-fhir-r4-core/UsageContext";
19+
20+
export interface CodeSystemConcept extends BackboneElement {
21+
code: string;
22+
concept?: CodeSystemConcept[];
23+
definition?: string;
24+
designation?: CodeSystemConceptDesignation[];
25+
display?: string;
26+
property?: CodeSystemConceptProperty[];
27+
}
28+
29+
export interface CodeSystemConceptDesignation extends BackboneElement {
30+
language?: string;
31+
use?: Coding;
32+
value: string;
33+
}
34+
35+
export interface CodeSystemConceptProperty extends BackboneElement {
36+
code: string;
37+
valueBoolean?: boolean;
38+
valueCode?: string;
39+
valueCoding?: Coding;
40+
valueDateTime?: string;
41+
valueDecimal?: number;
42+
valueInteger?: number;
43+
valueString?: string;
44+
}
45+
46+
export interface CodeSystemFilter extends BackboneElement {
47+
code: string;
48+
description?: string;
49+
operator: ("=" | "is-a" | "descendent-of" | "is-not-a" | "regex" | "in" | "not-in" | "generalizes" | "exists")[];
50+
value: string;
51+
}
52+
53+
export interface CodeSystemProperty extends BackboneElement {
54+
code: string;
55+
description?: string;
56+
type: ("code" | "Coding" | "string" | "integer" | "boolean" | "dateTime" | "decimal");
57+
uri?: string;
58+
}
59+
60+
// CanonicalURL: http://hl7.org/fhir/StructureDefinition/CodeSystem
61+
export interface CodeSystem extends DomainResource {
62+
resourceType: "CodeSystem";
63+
64+
caseSensitive?: boolean;
65+
compositional?: boolean;
66+
concept?: CodeSystemConcept[];
67+
contact?: ContactDetail[];
68+
content: ("not-present" | "example" | "fragment" | "complete" | "supplement");
69+
copyright?: string;
70+
count?: number;
71+
date?: string;
72+
description?: string;
73+
experimental?: boolean;
74+
filter?: CodeSystemFilter[];
75+
hierarchyMeaning?: ("grouped-by" | "is-a" | "part-of" | "classified-with");
76+
identifier?: Identifier[];
77+
jurisdiction?: CodeableConcept[];
78+
name?: string;
79+
property?: CodeSystemProperty[];
80+
publisher?: string;
81+
purpose?: string;
82+
status: ("draft" | "active" | "retired" | "unknown");
83+
supplements?: string;
84+
title?: string;
85+
url?: string;
86+
useContext?: UsageContext[];
87+
valueSet?: string;
88+
version?: string;
89+
versionNeeded?: boolean;
90+
}
91+
export const isCodeSystem = (resource: unknown): resource is CodeSystem => {
92+
return resource !== null && typeof resource === "object" && (resource as {resourceType: string}).resourceType === "CodeSystem";
93+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// WARNING: This file is autogenerated by @atomic-ehr/codegen.
2+
// GitHub: https://github.com/atomic-ehr/codegen
3+
// Any manual changes made to this file may be overwritten.
4+
5+
import type { Coding } from "../hl7-fhir-r4-core/Coding";
6+
import type { Element } from "../hl7-fhir-r4-core/Element";
7+
8+
export type { Coding } from "../hl7-fhir-r4-core/Coding";
9+
export type { Element } from "../hl7-fhir-r4-core/Element";
10+
11+
// CanonicalURL: http://hl7.org/fhir/StructureDefinition/CodeableConcept
12+
export interface CodeableConcept extends Element {
13+
coding?: Coding[];
14+
text?: string;
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// WARNING: This file is autogenerated by @atomic-ehr/codegen.
2+
// GitHub: https://github.com/atomic-ehr/codegen
3+
// Any manual changes made to this file may be overwritten.
4+
5+
import type { Element } from "../hl7-fhir-r4-core/Element";
6+
7+
export type { Element } from "../hl7-fhir-r4-core/Element";
8+
9+
// CanonicalURL: http://hl7.org/fhir/StructureDefinition/Coding
10+
export interface Coding extends Element {
11+
code?: string;
12+
display?: string;
13+
system?: string;
14+
userSelected?: boolean;
15+
version?: string;
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// WARNING: This file is autogenerated by @atomic-ehr/codegen.
2+
// GitHub: https://github.com/atomic-ehr/codegen
3+
// Any manual changes made to this file may be overwritten.
4+
5+
import type { ContactPoint } from "../hl7-fhir-r4-core/ContactPoint";
6+
import type { Element } from "../hl7-fhir-r4-core/Element";
7+
8+
export type { ContactPoint } from "../hl7-fhir-r4-core/ContactPoint";
9+
export type { Element } from "../hl7-fhir-r4-core/Element";
10+
11+
// CanonicalURL: http://hl7.org/fhir/StructureDefinition/ContactDetail
12+
export interface ContactDetail extends Element {
13+
name?: string;
14+
telecom?: ContactPoint[];
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// WARNING: This file is autogenerated by @atomic-ehr/codegen.
2+
// GitHub: https://github.com/atomic-ehr/codegen
3+
// Any manual changes made to this file may be overwritten.
4+
5+
import type { Element } from "../hl7-fhir-r4-core/Element";
6+
import type { Period } from "../hl7-fhir-r4-core/Period";
7+
8+
export type { Element } from "../hl7-fhir-r4-core/Element";
9+
export type { Period } from "../hl7-fhir-r4-core/Period";
10+
11+
// CanonicalURL: http://hl7.org/fhir/StructureDefinition/ContactPoint
12+
export interface ContactPoint extends Element {
13+
period?: Period;
14+
rank?: number;
15+
system?: ("phone" | "fax" | "email" | "pager" | "url" | "sms" | "other");
16+
use?: ("home" | "work" | "temp" | "old" | "mobile");
17+
value?: string;
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// WARNING: This file is autogenerated by @atomic-ehr/codegen.
2+
// GitHub: https://github.com/atomic-ehr/codegen
3+
// Any manual changes made to this file may be overwritten.
4+
5+
import type { Narrative } from "../hl7-fhir-r4-core/Narrative";
6+
import type { Resource } from "../hl7-fhir-r4-core/Resource";
7+
8+
export type { Narrative } from "../hl7-fhir-r4-core/Narrative";
9+
10+
// CanonicalURL: http://hl7.org/fhir/StructureDefinition/DomainResource
11+
export interface DomainResource extends Resource {
12+
resourceType: "CodeSystem" | "DomainResource" | "ValueSet";
13+
14+
contained?: Resource[];
15+
text?: Narrative;
16+
}
17+
export const isDomainResource = (resource: unknown): resource is DomainResource => {
18+
return resource !== null && typeof resource === "object" && (resource as {resourceType: string}).resourceType === "DomainResource";
19+
}

0 commit comments

Comments
 (0)