-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtemplate-blocks.d.ts
More file actions
319 lines (278 loc) · 6.94 KB
/
template-blocks.d.ts
File metadata and controls
319 lines (278 loc) · 6.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
// Print Template Block Types
export type TemplateType = 'surgery' | 'followup'
// Base block interface
export interface BaseBlock {
id: string
type: string
}
// Block type definitions
export interface HeaderBlockProps {
showHospital: boolean
showSubtitle: boolean
showUnit: boolean
showTelephone: boolean
showLogo: boolean
alignment: 'left' | 'center' | 'right'
logoSrc?: string // base64 image
}
export interface HeaderBlock extends BaseBlock {
type: 'header'
props: HeaderBlockProps
}
export interface TextBlockProps {
content: string // HTML via TipTap
alignment: 'left' | 'center' | 'right'
fontSize: 'sm' | 'base' | 'lg' | 'xl' | '2xl'
bold: boolean
italic: boolean
underline: boolean
}
export interface TextBlock extends BaseBlock {
type: 'text'
props: TextBlockProps
}
export interface DataFieldBlockProps {
field: string // field path like 'patient.name' or 'surgery.bht'
label: string
format: 'none' | 'date' | 'age'
fallback: string // shown when value is empty
showLabel: boolean
alignment: 'left' | 'center' | 'right'
}
export interface DataFieldBlock extends BaseBlock {
type: 'data-field'
props: DataFieldBlockProps
}
export interface DataTableRow {
label: string
field: string
colspan?: number
}
export interface DataTableBlockProps {
rows: DataTableRow[]
columns: 2 | 4
showBorders: boolean
}
export interface DataTableBlock extends BaseBlock {
type: 'data-table'
props: DataTableBlockProps
}
export interface RichContentBlockProps {
field: string // field path for HTML content (e.g., 'surgery.notes')
sectionTitle: string
showIfEmpty: boolean
}
export interface RichContentBlock extends BaseBlock {
type: 'rich-content'
props: RichContentBlockProps
}
export interface DividerBlockProps {
style: 'solid' | 'dashed' | 'double'
thickness: 1 | 2 | 3
}
export interface DividerBlock extends BaseBlock {
type: 'divider'
props: DividerBlockProps
}
export interface SpacerBlockProps {
height: number // in pixels
}
export interface SpacerBlock extends BaseBlock {
type: 'spacer'
props: SpacerBlockProps
}
export interface DoctorsListBlockProps {
type: 'doneBy' | 'assistedBy' | 'both'
showDesignation: boolean
layout: 'inline' | 'list'
}
export interface DoctorsListBlock extends BaseBlock {
type: 'doctors-list'
props: DoctorsListBlockProps
}
export type ConditionalOperator = 'exists' | 'notEmpty' | 'isEmpty' | 'equals'
export interface ConditionalBlockProps {
field: string
condition: ConditionalOperator
value?: string // for 'equals' condition
}
export interface ConditionalBlock extends BaseBlock {
type: 'conditional'
props: ConditionalBlockProps
children: TemplateBlock[]
}
export interface TwoColumnBlockProps {
ratio: '50-50' | '33-67' | '67-33' | '25-75' | '75-25'
}
export interface TwoColumnBlock extends BaseBlock {
type: 'two-column'
props: TwoColumnBlockProps
left: TemplateBlock[]
right: TemplateBlock[]
}
export interface ImageBlockProps {
src: string // base64 image
width: number
height: number
alignment: 'left' | 'center' | 'right'
altText: string
}
export interface ImageBlock extends BaseBlock {
type: 'image'
props: ImageBlockProps
}
export interface PageBreakBlock extends BaseBlock {
type: 'page-break'
props: Record<string, never>
}
// Union type of all block types
export type TemplateBlock =
| HeaderBlock
| TextBlock
| DataFieldBlock
| DataTableBlock
| RichContentBlock
| DividerBlock
| SpacerBlock
| DoctorsListBlock
| ConditionalBlock
| TwoColumnBlock
| ImageBlock
| PageBreakBlock
// Block type string literals
export type BlockType = TemplateBlock['type']
// Page settings
export interface PageSettings {
paperSize: 'a4' | 'letter' | 'legal'
orientation: 'portrait' | 'landscape'
margins: {
top: number
right: number
bottom: number
left: number
}
}
// Template structure (stored as JSON in database)
export interface TemplateStructure {
version: number
blocks: TemplateBlock[]
}
// Print Template (database row)
export interface PrintTemplateTable {
id: number
name: string
type: TemplateType
description: string | null
structure: string // JSON string of TemplateStructure
page_settings: string | null // JSON string of PageSettings
is_default: number // SQLite uses integer for boolean
created_at: number
updated_at: number
}
// Parsed print template for use in code
export interface PrintTemplate {
id: number
name: string
type: TemplateType
description: string | null
structure: TemplateStructure
pageSettings: PageSettings | null
isDefault: boolean
createdAt: Date
updatedAt: Date
}
// Input types for CRUD operations
export interface NewPrintTemplate {
name: string
type: TemplateType
description?: string | null
structure: TemplateStructure
pageSettings?: PageSettings | null
isDefault?: boolean
}
export interface PrintTemplateUpdate {
name?: string
description?: string | null
structure?: TemplateStructure
pageSettings?: PageSettings | null
isDefault?: boolean
}
// Filter for listing templates
export interface PrintTemplateFilter {
type?: TemplateType
search?: string
}
// Default Print Template (read-only, for restoring)
export interface DefaultPrintTemplate {
id: number
key: string
name: string
type: TemplateType
description: string | null
structure: TemplateStructure
pageSettings: PageSettings | null
}
// Available data fields for template builder UI
export interface FieldDefinition {
path: string
label: string
category: 'patient' | 'surgery' | 'followup' | 'settings'
description: string
example: string
isHtml?: boolean
}
// Context data passed to template renderer
export interface TemplateContext {
patient: {
name: string
age: number
gender: string
age_gender: string
phn: string
address: string | null
phone: string | null
blood_group: string | null
allergies: string | null
conditions: string | null
medications: string | null
emergency_contact: string | null
emergency_phone: string | null
remarks: string | null
}
surgery: {
title: string
bht: string
ward: string
date: string | null
doa: string | null
dod: string | null
notes: string | null
inward_management: string | null
post_op_notes: string | null
discharge_plan: string | null
referral: string | null
doneByAsString: string
assistedByAsString: string
doneBy: Array<{ name: string; designation: string | null }>
assistedBy: Array<{ name: string; designation: string | null }>
}
followup?: {
date: string | null
notes: string | null
}
settings: {
hospital: string
subtitle: string
unit: string
telephone: string | null
}
}
// Block metadata for the builder palette
export interface BlockDefinition {
type: BlockType
label: string
icon: string // Lucide icon name
category: 'structure' | 'content' | 'data' | 'logic'
description: string
defaultProps: Record<string, unknown>
}