Skip to content

Commit 1774e26

Browse files
added tests
1 parent 5213635 commit 1774e26

9 files changed

Lines changed: 1046 additions & 1 deletion

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ test-python-sdk: typecheck format prepare-aidbox-runme lint
103103
. venv/bin/activate && \
104104
python -m pytest test_sdk.py -v
105105

106+
py-run:
107+
$(TYPECHECK) --project examples/python/tsconfig.json
108+
bun run examples/python/generate.ts
109+
106110
release:
107111
echo Push tag for $(VERSION)
108112
git tag -a v$(VERSION) -m "Release $(VERSION)"

src/api/writer-generator/python.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ const deriveResourceName = (id: Identifier): string => {
132132
};
133133

134134
const resolvePyAssets = (fn: string) => {
135-
const __dirname = Path.dirname(fileURLToPath(import.meta.url));
135+
const __filename = fileURLToPath(import.meta.url);
136+
const __dirname = Path.dirname(__filename);
136137
if (__filename.endsWith("dist/index.js")) {
137138
return Path.resolve(__dirname, "..", "assets", "api", "writer-generator", "python", fn);
138139
} else {
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// Bun Snapshot v1, https://bun.sh/docs/test/snapshots
2+
3+
exports[`CCDA Package - Multi-Package Generation TypeScript Generation should generate ClinicalDocument type 1`] = `
4+
"// WARNING: This file is autogenerated by @atomic-ehr/codegen.
5+
// GitHub: https://github.com/atomic-ehr/codegen
6+
// Any manual changes made to this file may be overwritten.
7+
8+
import type { ANY } from "../hl7-cda-uv-core/Any";
9+
import type { Authenticator } from "../hl7-cda-uv-core/Authenticator";
10+
import type { Author } from "../hl7-cda-uv-core/Author";
11+
import type { Authorization } from "../hl7-cda-uv-core/Authorization";
12+
import type { CD } from "../hl7-cda-uv-core/Cd";
13+
import type { CE } from "../hl7-cda-uv-core/Ce";
14+
import type { Component } from "../hl7-cda-uv-core/Component";
15+
import type { ComponentOf } from "../hl7-cda-uv-core/ComponentOf";
16+
import type { CS } from "../hl7-cda-uv-core/Cs";
17+
import type { Custodian } from "../hl7-cda-uv-core/Custodian";
18+
import type { DataEnterer } from "../hl7-cda-uv-core/DataEnterer";
19+
import type { DocumentationOf } from "../hl7-cda-uv-core/DocumentationOf";
20+
import type { II } from "../hl7-cda-uv-core/Ii";
21+
import type { Informant } from "../hl7-cda-uv-core/Informant";
22+
import type { InformationRecipient } from "../hl7-cda-uv-core/InformationRecipient";
23+
import type { InFulfillmentOf } from "../hl7-cda-uv-core/InFulfillmentOf";
24+
import type { INT } from "../hl7-cda-uv-core/Int";
25+
import type { LegalAuthenticator } from "../hl7-cda-uv-core/LegalAuthenticator";
26+
import type { Participant1 } from "../hl7-cda-uv-core/Participant1";
27+
import type { RecordTarget } from "../hl7-cda-uv-core/RecordTarget";
28+
import type { RelatedDocument } from "../hl7-cda-uv-core/RelatedDocument";
29+
import type { ST } from "../hl7-cda-uv-core/St";
30+
import type { TS } from "../hl7-cda-uv-core/Ts";
31+
32+
import type { Element } from "../hl7-fhir-r5-core/Element";
33+
// CanonicalURL: http://hl7.org/cda/stds/core/StructureDefinition/ClinicalDocument
34+
export interface ClinicalDocument extends ANY {
35+
resourceType: "ClinicalDocument";
36+
37+
authenticator?: Authenticator[];
38+
author: Author[];
39+
authorization?: Authorization[];
40+
classCode?: string;
41+
_classCode?: Element;
42+
code: CE;
43+
component: Component;
44+
componentOf?: ComponentOf;
45+
confidentialityCode: CE;
46+
copyTime?: TS;
47+
custodian: Custodian;
48+
dataEnterer?: DataEnterer;
49+
documentationOf?: DocumentationOf[];
50+
effectiveTime: TS;
51+
id: II;
52+
informant?: Informant[];
53+
informationRecipient?: InformationRecipient[];
54+
inFulfillmentOf?: InFulfillmentOf[];
55+
languageCode?: CS;
56+
legalAuthenticator?: LegalAuthenticator;
57+
moodCode?: ("INT" | "APT" | "ARQ" | "PRMS" | "PRP" | "RQO" | "SLOT" | "DEF" | "EVN" | "EVN.CRT" | "GOL" | "OPT" | "PERM" | "PERMRQ");
58+
_moodCode?: Element;
59+
participant?: Participant1[];
60+
realmCode?: CS[];
61+
recordTarget: RecordTarget[];
62+
relatedDocument?: RelatedDocument[];
63+
sdtcCategory?: CD[];
64+
sdtcStatusCode?: CS;
65+
setId?: II;
66+
templateId?: II[];
67+
title?: ST;
68+
typeId?: II;
69+
versionNumber?: INT;
70+
}
71+
export const isClinicalDocument = (resource: unknown): resource is ClinicalDocument => {
72+
return resource !== null && typeof resource === "object" && (resource as {resourceType: string}).resourceType === "ClinicalDocument";
73+
}
74+
"
75+
`;
76+
77+
exports[`CCDA TypeScript Generation should generate ClinicalDocument type 1`] = `
78+
"// WARNING: This file is autogenerated by @atomic-ehr/codegen.
79+
// GitHub: https://github.com/atomic-ehr/codegen
80+
// Any manual changes made to this file may be overwritten.
81+
82+
import type { ANY } from "../hl7-cda-uv-core/Any";
83+
import type { Authenticator } from "../hl7-cda-uv-core/Authenticator";
84+
import type { Author } from "../hl7-cda-uv-core/Author";
85+
import type { Authorization } from "../hl7-cda-uv-core/Authorization";
86+
import type { CD } from "../hl7-cda-uv-core/Cd";
87+
import type { CE } from "../hl7-cda-uv-core/Ce";
88+
import type { Component } from "../hl7-cda-uv-core/Component";
89+
import type { ComponentOf } from "../hl7-cda-uv-core/ComponentOf";
90+
import type { CS } from "../hl7-cda-uv-core/Cs";
91+
import type { Custodian } from "../hl7-cda-uv-core/Custodian";
92+
import type { DataEnterer } from "../hl7-cda-uv-core/DataEnterer";
93+
import type { DocumentationOf } from "../hl7-cda-uv-core/DocumentationOf";
94+
import type { II } from "../hl7-cda-uv-core/Ii";
95+
import type { Informant } from "../hl7-cda-uv-core/Informant";
96+
import type { InformationRecipient } from "../hl7-cda-uv-core/InformationRecipient";
97+
import type { InFulfillmentOf } from "../hl7-cda-uv-core/InFulfillmentOf";
98+
import type { INT } from "../hl7-cda-uv-core/Int";
99+
import type { LegalAuthenticator } from "../hl7-cda-uv-core/LegalAuthenticator";
100+
import type { Participant1 } from "../hl7-cda-uv-core/Participant1";
101+
import type { RecordTarget } from "../hl7-cda-uv-core/RecordTarget";
102+
import type { RelatedDocument } from "../hl7-cda-uv-core/RelatedDocument";
103+
import type { ST } from "../hl7-cda-uv-core/St";
104+
import type { TS } from "../hl7-cda-uv-core/Ts";
105+
106+
import type { Element } from "../hl7-fhir-r5-core/Element";
107+
// CanonicalURL: http://hl7.org/cda/stds/core/StructureDefinition/ClinicalDocument
108+
export interface ClinicalDocument extends ANY {
109+
resourceType: "ClinicalDocument";
110+
111+
authenticator?: Authenticator[];
112+
author: Author[];
113+
authorization?: Authorization[];
114+
classCode?: string;
115+
_classCode?: Element;
116+
code: CE;
117+
component: Component;
118+
componentOf?: ComponentOf;
119+
confidentialityCode: CE;
120+
copyTime?: TS;
121+
custodian: Custodian;
122+
dataEnterer?: DataEnterer;
123+
documentationOf?: DocumentationOf[];
124+
effectiveTime: TS;
125+
id: II;
126+
informant?: Informant[];
127+
informationRecipient?: InformationRecipient[];
128+
inFulfillmentOf?: InFulfillmentOf[];
129+
languageCode?: CS;
130+
legalAuthenticator?: LegalAuthenticator;
131+
moodCode?: ("INT" | "APT" | "ARQ" | "PRMS" | "PRP" | "RQO" | "SLOT" | "DEF" | "EVN" | "EVN.CRT" | "GOL" | "OPT" | "PERM" | "PERMRQ");
132+
_moodCode?: Element;
133+
participant?: Participant1[];
134+
realmCode?: CS[];
135+
recordTarget: RecordTarget[];
136+
relatedDocument?: RelatedDocument[];
137+
sdtcCategory?: CD[];
138+
sdtcStatusCode?: CS;
139+
setId?: II;
140+
templateId?: II[];
141+
title?: ST;
142+
typeId?: II;
143+
versionNumber?: INT;
144+
}
145+
export const isClinicalDocument = (resource: unknown): resource is ClinicalDocument => {
146+
return resource !== null && typeof resource === "object" && (resource as {resourceType: string}).resourceType === "ClinicalDocument";
147+
}
148+
"
149+
`;
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
// Bun Snapshot v1, https://bun.sh/docs/test/snapshots
2+
3+
exports[`Local Package Folder - Multi-Package Generation TypeScript Generation should generate ExampleNotebook type 1`] = `
4+
"// WARNING: This file is autogenerated by @atomic-ehr/codegen.
5+
// GitHub: https://github.com/atomic-ehr/codegen
6+
// Any manual changes made to this file may be overwritten.
7+
8+
import type { Coding } from "../hl7-fhir-r4-core/Coding";
9+
import type { DomainResource } from "../hl7-fhir-r4-core/DomainResource";
10+
import type { Identifier } from "../hl7-fhir-r4-core/Identifier";
11+
import type { Reference } from "../hl7-fhir-r4-core/Reference";
12+
13+
import type { Element } from "../hl7-fhir-r4-core/Element";
14+
export type { Coding } from "../hl7-fhir-r4-core/Coding";
15+
export type { Identifier } from "../hl7-fhir-r4-core/Identifier";
16+
export type { Reference } from "../hl7-fhir-r4-core/Reference";
17+
18+
// CanonicalURL: http://example.org/fhir/StructureDefinition/ExampleNotebook
19+
export interface ExampleNotebook extends DomainResource {
20+
resourceType: "ExampleNotebook";
21+
22+
author: Reference<"Patient" | "Practitioner">;
23+
content: string;
24+
_content?: Element;
25+
identifier: Identifier;
26+
tag?: Coding[];
27+
title: string;
28+
_title?: Element;
29+
}
30+
export const isExampleNotebook = (resource: unknown): resource is ExampleNotebook => {
31+
return resource !== null && typeof resource === "object" && (resource as {resourceType: string}).resourceType === "ExampleNotebook";
32+
}
33+
"
34+
`;
35+
36+
exports[`Local Package Folder - Multi-Package Generation TypeScript Generation should generate ExampleNotebook type in custom package folder 1`] = `
37+
"// WARNING: This file is autogenerated by @atomic-ehr/codegen.
38+
// GitHub: https://github.com/atomic-ehr/codegen
39+
// Any manual changes made to this file may be overwritten.
40+
41+
import type { Coding } from "../hl7-fhir-r4-core/Coding";
42+
import type { DomainResource } from "../hl7-fhir-r4-core/DomainResource";
43+
import type { Identifier } from "../hl7-fhir-r4-core/Identifier";
44+
import type { Reference } from "../hl7-fhir-r4-core/Reference";
45+
46+
import type { Element } from "../hl7-fhir-r4-core/Element";
47+
export type { Coding } from "../hl7-fhir-r4-core/Coding";
48+
export type { Identifier } from "../hl7-fhir-r4-core/Identifier";
49+
export type { Reference } from "../hl7-fhir-r4-core/Reference";
50+
51+
// CanonicalURL: http://example.org/fhir/StructureDefinition/ExampleNotebook
52+
export interface ExampleNotebook extends DomainResource {
53+
resourceType: "ExampleNotebook";
54+
55+
author: Reference<"Patient" | "Practitioner">;
56+
content: string;
57+
_content?: Element;
58+
identifier: Identifier;
59+
tag?: Coding[];
60+
title: string;
61+
_title?: Element;
62+
}
63+
export const isExampleNotebook = (resource: unknown): resource is ExampleNotebook => {
64+
return resource !== null && typeof resource === "object" && (resource as {resourceType: string}).resourceType === "ExampleNotebook";
65+
}
66+
"
67+
`;
68+
69+
exports[`Local Package Folder - Multi-Package Generation Python Generation should generate base types for dependencies 1`] = `
70+
"# WARNING: This file is autogenerated by @atomic-ehr/codegen.
71+
# GitHub: https://github.com/atomic-ehr/codegen
72+
# Any manual changes made to this file may be overwritten.
73+
74+
from __future__ import annotations
75+
from pydantic import BaseModel, ConfigDict, Field, PositiveInt
76+
from typing import List as PyList, Literal
77+
78+
from fhir_types.hl7_fhir_r4_core.base import Extension, Narrative
79+
from fhir_types.hl7_fhir_r4_core.resource import Resource
80+
from fhir_types.hl7_fhir_r4_core.resource_families import ResourceFamily
81+
82+
83+
class DomainResource(Resource):
84+
model_config = ConfigDict(validate_by_name=True, serialize_by_alias=True, extra="forbid")
85+
resource_type: str = Field(
86+
default='DomainResource',
87+
alias='resourceType',
88+
serialization_alias='resourceType',
89+
frozen=True,
90+
pattern='DomainResource'
91+
)
92+
contained: PyList[ResourceFamily] | None = Field(None, alias="contained", serialization_alias="contained")
93+
extension: PyList[Extension] | None = Field(None, alias="extension", serialization_alias="extension")
94+
modifier_extension: PyList[Extension] | None = Field(None, alias="modifierExtension", serialization_alias="modifierExtension")
95+
text: Narrative | None = Field(None, alias="text", serialization_alias="text")
96+
97+
def to_json(self, indent: int | None = None) -> str:
98+
return self.model_dump_json(exclude_unset=True, exclude_none=True, indent=indent)
99+
100+
@classmethod
101+
def from_json(cls, json: str) -> DomainResource:
102+
return cls.model_validate_json(json)
103+
104+
"
105+
`;
106+
107+
exports[`Local Package Folder - Multi-Package Generation C# Generation should generate DomainResource base class 1`] = `
108+
"// WARNING: This file is autogenerated by @atomic-ehr/codegen.
109+
// GitHub: https://github.com/atomic-ehr/codegen
110+
// Any manual changes made to this file may be overwritten.
111+
112+
113+
namespace Fhir.Types.Hl7FhirR4Core;
114+
115+
public class DomainResource : Resource {
116+
public Resource[]? Contained { get; set; }
117+
public Extension[]? Extension { get; set; }
118+
public Extension[]? ModifierExtension { get; set; }
119+
public Narrative? Text { get; set; }
120+
121+
public override string ToString() =>
122+
JsonSerializer.Serialize(this, Helper.JsonSerializerOptions);
123+
124+
}
125+
126+
"
127+
`;

0 commit comments

Comments
 (0)