@blackcode_sa/metaestetics-api 1.6.20 → 1.6.22

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/dist/index.js CHANGED
@@ -58,6 +58,7 @@ __export(index_exports, {
58
58
  Contraindication: () => Contraindication,
59
59
  CosmeticAllergySubtype: () => CosmeticAllergySubtype,
60
60
  Currency: () => Currency,
61
+ DOCTOR_FORMS_SUBCOLLECTION: () => DOCTOR_FORMS_SUBCOLLECTION,
61
62
  DOCUMENTATION_TEMPLATES_COLLECTION: () => DOCUMENTATION_TEMPLATES_COLLECTION,
62
63
  DocumentElementType: () => DocumentElementType,
63
64
  DocumentationTemplateService: () => DocumentationTemplateService,
@@ -112,6 +113,7 @@ __export(index_exports, {
112
113
  TimeUnit: () => TimeUnit,
113
114
  TreatmentBenefit: () => TreatmentBenefit,
114
115
  USER_ERRORS: () => USER_ERRORS,
116
+ USER_FORMS_SUBCOLLECTION: () => USER_FORMS_SUBCOLLECTION,
115
117
  UserService: () => UserService,
116
118
  addAllergySchema: () => addAllergySchema,
117
119
  addBlockingConditionSchema: () => addBlockingConditionSchema,
@@ -305,17 +307,17 @@ var HeadingLevel = /* @__PURE__ */ ((HeadingLevel2) => {
305
307
  return HeadingLevel2;
306
308
  })(HeadingLevel || {});
307
309
  var DynamicVariable = /* @__PURE__ */ ((DynamicVariable2) => {
308
- DynamicVariable2["PATIENT_NAME"] = "[PATIENT_NAME]";
309
- DynamicVariable2["DOCTOR_NAME"] = "[DOCTOR_NAME]";
310
- DynamicVariable2["CLINIC_NAME"] = "[CLINIC_NAME]";
311
- DynamicVariable2["PATIENT_BIRTHDAY"] = "[PATIENT_BIRTHDAY]";
312
- DynamicVariable2["APPOINTMENT_DATE"] = "[APPOINTMENT_DATE]";
313
- DynamicVariable2["CURRENT_DATE"] = "[CURRENT_DATE]";
314
- DynamicVariable2["PROCEDURE_NAME"] = "[PROCEDURE_NAME]";
315
- DynamicVariable2["PROCEDURE_DESCRIPTION"] = "[PROCEDURE_DESCRIPTION]";
316
- DynamicVariable2["PROCEDURE_COST"] = "[PROCEDURE_COST]";
317
- DynamicVariable2["PROCEDURE_DURATION"] = "[PROCEDURE_DURATION]";
318
- DynamicVariable2["PROCEDURE_RISK"] = "[PROCEDURE_RISK]";
310
+ DynamicVariable2["PATIENT_NAME"] = "$[PATIENT_NAME]";
311
+ DynamicVariable2["DOCTOR_NAME"] = "$[DOCTOR_NAME]";
312
+ DynamicVariable2["CLINIC_NAME"] = "$[CLINIC_NAME]";
313
+ DynamicVariable2["PATIENT_BIRTHDAY"] = "$[PATIENT_BIRTHDAY]";
314
+ DynamicVariable2["APPOINTMENT_DATE"] = "$[APPOINTMENT_DATE]";
315
+ DynamicVariable2["CURRENT_DATE"] = "$[CURRENT_DATE]";
316
+ DynamicVariable2["PROCEDURE_NAME"] = "$[PROCEDURE_NAME]";
317
+ DynamicVariable2["PROCEDURE_DESCRIPTION"] = "$[PROCEDURE_DESCRIPTION]";
318
+ DynamicVariable2["PROCEDURE_COST"] = "$[PROCEDURE_COST]";
319
+ DynamicVariable2["PROCEDURE_DURATION"] = "$[PROCEDURE_DURATION]";
320
+ DynamicVariable2["PROCEDURE_RISK"] = "$[PROCEDURE_RISK]";
319
321
  return DynamicVariable2;
320
322
  })(DynamicVariable || {});
321
323
  var FilledDocumentStatus = /* @__PURE__ */ ((FilledDocumentStatus2) => {
@@ -1332,11 +1334,11 @@ var allergySubtypeSchema = import_zod5.z.union([
1332
1334
  var allergySchema = import_zod5.z.object({
1333
1335
  type: import_zod5.z.nativeEnum(AllergyType),
1334
1336
  subtype: allergySubtypeSchema,
1335
- name: import_zod5.z.string().optional(),
1337
+ name: import_zod5.z.string().optional().nullable(),
1336
1338
  severity: import_zod5.z.enum(["mild", "moderate", "severe"]).optional(),
1337
- reaction: import_zod5.z.string().optional(),
1338
- diagnosed: timestampSchema2.optional(),
1339
- notes: import_zod5.z.string().optional()
1339
+ reaction: import_zod5.z.string().optional().nullable(),
1340
+ diagnosed: timestampSchema2.optional().nullable(),
1341
+ notes: import_zod5.z.string().optional().nullable()
1340
1342
  });
1341
1343
  var vitalStatsSchema = import_zod5.z.object({
1342
1344
  height: import_zod5.z.number().positive().optional(),
@@ -1351,23 +1353,23 @@ var vitalStatsSchema = import_zod5.z.object({
1351
1353
  var blockingConditionSchema = import_zod5.z.object({
1352
1354
  condition: import_zod5.z.nativeEnum(BlockingCondition),
1353
1355
  diagnosedAt: timestampSchema2,
1354
- notes: import_zod5.z.string().optional(),
1356
+ notes: import_zod5.z.string().optional().nullable(),
1355
1357
  isActive: import_zod5.z.boolean()
1356
1358
  });
1357
1359
  var contraindicationSchema = import_zod5.z.object({
1358
1360
  condition: import_zod5.z.nativeEnum(Contraindication),
1359
1361
  lastOccurrence: timestampSchema2,
1360
1362
  frequency: import_zod5.z.enum(["rare", "occasional", "frequent"]),
1361
- notes: import_zod5.z.string().optional(),
1363
+ notes: import_zod5.z.string().optional().nullable(),
1362
1364
  isActive: import_zod5.z.boolean()
1363
1365
  });
1364
1366
  var medicationSchema = import_zod5.z.object({
1365
1367
  name: import_zod5.z.string().min(1),
1366
1368
  dosage: import_zod5.z.string().min(1),
1367
1369
  frequency: import_zod5.z.string().min(1),
1368
- startDate: timestampSchema2,
1369
- endDate: timestampSchema2.optional(),
1370
- prescribedBy: import_zod5.z.string().optional()
1370
+ startDate: timestampSchema2.optional().nullable(),
1371
+ endDate: timestampSchema2.optional().nullable(),
1372
+ prescribedBy: import_zod5.z.string().optional().nullable()
1371
1373
  });
1372
1374
  var patientMedicalInfoSchema = import_zod5.z.object({
1373
1375
  patientId: import_zod5.z.string(),
@@ -7862,7 +7864,7 @@ var ProcedureService = class extends BaseService {
7862
7864
  preRequirements: technology.requirements.pre,
7863
7865
  postRequirements: technology.requirements.post,
7864
7866
  certificationRequirement: technology.certificationRequirement,
7865
- documentationTemplates: technology.documentationTemplates || [],
7867
+ documentationTemplates: (technology == null ? void 0 : technology.documentationTemplates) || [],
7866
7868
  clinicInfo,
7867
7869
  // Embed aggregated info
7868
7870
  doctorInfo,
@@ -8441,6 +8443,7 @@ var DocumentationTemplateService = class extends BaseService {
8441
8443
  * @returns The updated template
8442
8444
  */
8443
8445
  async updateTemplate(templateId, data) {
8446
+ var _a, _b, _c, _d, _e, _f;
8444
8447
  const validatedData = updateDocumentTemplateSchema.parse(data);
8445
8448
  const template = await this.getTemplateById(templateId);
8446
8449
  if (!template) {
@@ -8466,12 +8469,9 @@ var DocumentationTemplateService = class extends BaseService {
8466
8469
  updatePayload.isActive = validatedData.isActive;
8467
8470
  if (validatedData.tags !== void 0)
8468
8471
  updatePayload.tags = validatedData.tags;
8469
- if (validatedData.isUserForm !== void 0)
8470
- updatePayload.isUserForm = validatedData.isUserForm;
8471
- if (validatedData.isRequired !== void 0)
8472
- updatePayload.isRequired = validatedData.isRequired;
8473
- if (validatedData.sortingOrder !== void 0)
8474
- updatePayload.sortingOrder = validatedData.sortingOrder;
8472
+ updatePayload.isUserForm = (_b = (_a = validatedData.isUserForm) != null ? _a : template.isUserForm) != null ? _b : false;
8473
+ updatePayload.isRequired = (_d = (_c = validatedData.isRequired) != null ? _c : template.isRequired) != null ? _d : false;
8474
+ updatePayload.sortingOrder = (_f = (_e = validatedData.sortingOrder) != null ? _e : template.sortingOrder) != null ? _f : 0;
8475
8475
  const docRef = (0, import_firestore25.doc)(this.collectionRef, templateId);
8476
8476
  await (0, import_firestore25.updateDoc)(docRef, updatePayload);
8477
8477
  return { ...template, ...updatePayload };
@@ -8571,6 +8571,30 @@ var DocumentationTemplateService = class extends BaseService {
8571
8571
  lastDoc: lastVisible
8572
8572
  };
8573
8573
  }
8574
+ /**
8575
+ * Get all templates for selection with optional filtering
8576
+ * @param options - Filtering options
8577
+ * @returns Array of templates
8578
+ */
8579
+ async getAllTemplatesForSelection(options) {
8580
+ let q = (0, import_firestore25.query)(
8581
+ this.collectionRef,
8582
+ (0, import_firestore25.where)("isActive", "==", true),
8583
+ (0, import_firestore25.orderBy)("updatedAt", "desc")
8584
+ );
8585
+ if ((options == null ? void 0 : options.isUserForm) !== void 0) {
8586
+ q = (0, import_firestore25.query)(q, (0, import_firestore25.where)("isUserForm", "==", options.isUserForm));
8587
+ }
8588
+ if ((options == null ? void 0 : options.isRequired) !== void 0) {
8589
+ q = (0, import_firestore25.query)(q, (0, import_firestore25.where)("isRequired", "==", options.isRequired));
8590
+ }
8591
+ const querySnapshot = await (0, import_firestore25.getDocs)(q);
8592
+ const templates = [];
8593
+ querySnapshot.forEach((doc33) => {
8594
+ templates.push(doc33.data());
8595
+ });
8596
+ return templates;
8597
+ }
8574
8598
  };
8575
8599
 
8576
8600
  // src/services/documentation-templates/filled-document.service.ts
@@ -14337,6 +14361,7 @@ var RequirementType = /* @__PURE__ */ ((RequirementType2) => {
14337
14361
  Contraindication,
14338
14362
  CosmeticAllergySubtype,
14339
14363
  Currency,
14364
+ DOCTOR_FORMS_SUBCOLLECTION,
14340
14365
  DOCUMENTATION_TEMPLATES_COLLECTION,
14341
14366
  DocumentElementType,
14342
14367
  DocumentationTemplateService,
@@ -14391,6 +14416,7 @@ var RequirementType = /* @__PURE__ */ ((RequirementType2) => {
14391
14416
  TimeUnit,
14392
14417
  TreatmentBenefit,
14393
14418
  USER_ERRORS,
14419
+ USER_FORMS_SUBCOLLECTION,
14394
14420
  UserService,
14395
14421
  addAllergySchema,
14396
14422
  addBlockingConditionSchema,
package/dist/index.mjs CHANGED
@@ -71,17 +71,17 @@ var HeadingLevel = /* @__PURE__ */ ((HeadingLevel2) => {
71
71
  return HeadingLevel2;
72
72
  })(HeadingLevel || {});
73
73
  var DynamicVariable = /* @__PURE__ */ ((DynamicVariable2) => {
74
- DynamicVariable2["PATIENT_NAME"] = "[PATIENT_NAME]";
75
- DynamicVariable2["DOCTOR_NAME"] = "[DOCTOR_NAME]";
76
- DynamicVariable2["CLINIC_NAME"] = "[CLINIC_NAME]";
77
- DynamicVariable2["PATIENT_BIRTHDAY"] = "[PATIENT_BIRTHDAY]";
78
- DynamicVariable2["APPOINTMENT_DATE"] = "[APPOINTMENT_DATE]";
79
- DynamicVariable2["CURRENT_DATE"] = "[CURRENT_DATE]";
80
- DynamicVariable2["PROCEDURE_NAME"] = "[PROCEDURE_NAME]";
81
- DynamicVariable2["PROCEDURE_DESCRIPTION"] = "[PROCEDURE_DESCRIPTION]";
82
- DynamicVariable2["PROCEDURE_COST"] = "[PROCEDURE_COST]";
83
- DynamicVariable2["PROCEDURE_DURATION"] = "[PROCEDURE_DURATION]";
84
- DynamicVariable2["PROCEDURE_RISK"] = "[PROCEDURE_RISK]";
74
+ DynamicVariable2["PATIENT_NAME"] = "$[PATIENT_NAME]";
75
+ DynamicVariable2["DOCTOR_NAME"] = "$[DOCTOR_NAME]";
76
+ DynamicVariable2["CLINIC_NAME"] = "$[CLINIC_NAME]";
77
+ DynamicVariable2["PATIENT_BIRTHDAY"] = "$[PATIENT_BIRTHDAY]";
78
+ DynamicVariable2["APPOINTMENT_DATE"] = "$[APPOINTMENT_DATE]";
79
+ DynamicVariable2["CURRENT_DATE"] = "$[CURRENT_DATE]";
80
+ DynamicVariable2["PROCEDURE_NAME"] = "$[PROCEDURE_NAME]";
81
+ DynamicVariable2["PROCEDURE_DESCRIPTION"] = "$[PROCEDURE_DESCRIPTION]";
82
+ DynamicVariable2["PROCEDURE_COST"] = "$[PROCEDURE_COST]";
83
+ DynamicVariable2["PROCEDURE_DURATION"] = "$[PROCEDURE_DURATION]";
84
+ DynamicVariable2["PROCEDURE_RISK"] = "$[PROCEDURE_RISK]";
85
85
  return DynamicVariable2;
86
86
  })(DynamicVariable || {});
87
87
  var FilledDocumentStatus = /* @__PURE__ */ ((FilledDocumentStatus2) => {
@@ -1149,11 +1149,11 @@ var allergySubtypeSchema = z5.union([
1149
1149
  var allergySchema = z5.object({
1150
1150
  type: z5.nativeEnum(AllergyType),
1151
1151
  subtype: allergySubtypeSchema,
1152
- name: z5.string().optional(),
1152
+ name: z5.string().optional().nullable(),
1153
1153
  severity: z5.enum(["mild", "moderate", "severe"]).optional(),
1154
- reaction: z5.string().optional(),
1155
- diagnosed: timestampSchema2.optional(),
1156
- notes: z5.string().optional()
1154
+ reaction: z5.string().optional().nullable(),
1155
+ diagnosed: timestampSchema2.optional().nullable(),
1156
+ notes: z5.string().optional().nullable()
1157
1157
  });
1158
1158
  var vitalStatsSchema = z5.object({
1159
1159
  height: z5.number().positive().optional(),
@@ -1168,23 +1168,23 @@ var vitalStatsSchema = z5.object({
1168
1168
  var blockingConditionSchema = z5.object({
1169
1169
  condition: z5.nativeEnum(BlockingCondition),
1170
1170
  diagnosedAt: timestampSchema2,
1171
- notes: z5.string().optional(),
1171
+ notes: z5.string().optional().nullable(),
1172
1172
  isActive: z5.boolean()
1173
1173
  });
1174
1174
  var contraindicationSchema = z5.object({
1175
1175
  condition: z5.nativeEnum(Contraindication),
1176
1176
  lastOccurrence: timestampSchema2,
1177
1177
  frequency: z5.enum(["rare", "occasional", "frequent"]),
1178
- notes: z5.string().optional(),
1178
+ notes: z5.string().optional().nullable(),
1179
1179
  isActive: z5.boolean()
1180
1180
  });
1181
1181
  var medicationSchema = z5.object({
1182
1182
  name: z5.string().min(1),
1183
1183
  dosage: z5.string().min(1),
1184
1184
  frequency: z5.string().min(1),
1185
- startDate: timestampSchema2,
1186
- endDate: timestampSchema2.optional(),
1187
- prescribedBy: z5.string().optional()
1185
+ startDate: timestampSchema2.optional().nullable(),
1186
+ endDate: timestampSchema2.optional().nullable(),
1187
+ prescribedBy: z5.string().optional().nullable()
1188
1188
  });
1189
1189
  var patientMedicalInfoSchema = z5.object({
1190
1190
  patientId: z5.string(),
@@ -7839,7 +7839,7 @@ var ProcedureService = class extends BaseService {
7839
7839
  preRequirements: technology.requirements.pre,
7840
7840
  postRequirements: technology.requirements.post,
7841
7841
  certificationRequirement: technology.certificationRequirement,
7842
- documentationTemplates: technology.documentationTemplates || [],
7842
+ documentationTemplates: (technology == null ? void 0 : technology.documentationTemplates) || [],
7843
7843
  clinicInfo,
7844
7844
  // Embed aggregated info
7845
7845
  doctorInfo,
@@ -8431,6 +8431,7 @@ var DocumentationTemplateService = class extends BaseService {
8431
8431
  * @returns The updated template
8432
8432
  */
8433
8433
  async updateTemplate(templateId, data) {
8434
+ var _a, _b, _c, _d, _e, _f;
8434
8435
  const validatedData = updateDocumentTemplateSchema.parse(data);
8435
8436
  const template = await this.getTemplateById(templateId);
8436
8437
  if (!template) {
@@ -8456,12 +8457,9 @@ var DocumentationTemplateService = class extends BaseService {
8456
8457
  updatePayload.isActive = validatedData.isActive;
8457
8458
  if (validatedData.tags !== void 0)
8458
8459
  updatePayload.tags = validatedData.tags;
8459
- if (validatedData.isUserForm !== void 0)
8460
- updatePayload.isUserForm = validatedData.isUserForm;
8461
- if (validatedData.isRequired !== void 0)
8462
- updatePayload.isRequired = validatedData.isRequired;
8463
- if (validatedData.sortingOrder !== void 0)
8464
- updatePayload.sortingOrder = validatedData.sortingOrder;
8460
+ updatePayload.isUserForm = (_b = (_a = validatedData.isUserForm) != null ? _a : template.isUserForm) != null ? _b : false;
8461
+ updatePayload.isRequired = (_d = (_c = validatedData.isRequired) != null ? _c : template.isRequired) != null ? _d : false;
8462
+ updatePayload.sortingOrder = (_f = (_e = validatedData.sortingOrder) != null ? _e : template.sortingOrder) != null ? _f : 0;
8465
8463
  const docRef = doc16(this.collectionRef, templateId);
8466
8464
  await updateDoc16(docRef, updatePayload);
8467
8465
  return { ...template, ...updatePayload };
@@ -8561,6 +8559,30 @@ var DocumentationTemplateService = class extends BaseService {
8561
8559
  lastDoc: lastVisible
8562
8560
  };
8563
8561
  }
8562
+ /**
8563
+ * Get all templates for selection with optional filtering
8564
+ * @param options - Filtering options
8565
+ * @returns Array of templates
8566
+ */
8567
+ async getAllTemplatesForSelection(options) {
8568
+ let q = query16(
8569
+ this.collectionRef,
8570
+ where16("isActive", "==", true),
8571
+ orderBy5("updatedAt", "desc")
8572
+ );
8573
+ if ((options == null ? void 0 : options.isUserForm) !== void 0) {
8574
+ q = query16(q, where16("isUserForm", "==", options.isUserForm));
8575
+ }
8576
+ if ((options == null ? void 0 : options.isRequired) !== void 0) {
8577
+ q = query16(q, where16("isRequired", "==", options.isRequired));
8578
+ }
8579
+ const querySnapshot = await getDocs16(q);
8580
+ const templates = [];
8581
+ querySnapshot.forEach((doc33) => {
8582
+ templates.push(doc33.data());
8583
+ });
8584
+ return templates;
8585
+ }
8564
8586
  };
8565
8587
 
8566
8588
  // src/services/documentation-templates/filled-document.service.ts
@@ -14504,6 +14526,7 @@ export {
14504
14526
  Contraindication,
14505
14527
  CosmeticAllergySubtype,
14506
14528
  Currency,
14529
+ DOCTOR_FORMS_SUBCOLLECTION,
14507
14530
  DOCUMENTATION_TEMPLATES_COLLECTION,
14508
14531
  DocumentElementType,
14509
14532
  DocumentationTemplateService,
@@ -14558,6 +14581,7 @@ export {
14558
14581
  TimeUnit,
14559
14582
  TreatmentBenefit,
14560
14583
  USER_ERRORS,
14584
+ USER_FORMS_SUBCOLLECTION,
14561
14585
  UserService,
14562
14586
  addAllergySchema,
14563
14587
  addBlockingConditionSchema,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.6.20",
4
+ "version": "1.6.22",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
@@ -608,7 +608,8 @@ export class AppointmentAggregationService {
608
608
  return instructionObject;
609
609
  });
610
610
 
611
- const newInstanceData: Omit<PatientRequirementInstance, "id"> = {
611
+ const newInstanceData: PatientRequirementInstance = {
612
+ id: newInstanceRef.id, // Add the ID to the document data
612
613
  patientId: appointment.patientId,
613
614
  appointmentId: appointment.id,
614
615
  originalRequirementId: template.id,
package/src/index.ts CHANGED
@@ -299,6 +299,20 @@ export type {
299
299
  UpdateDocumentTemplateData,
300
300
  DocumentElement,
301
301
  FilledDocument,
302
+ BaseDocumentElement,
303
+ HeadingElement,
304
+ ParagraphElement,
305
+ ListElement,
306
+ DynamicTextElement,
307
+ BinaryChoiceElement,
308
+ MultipleChoiceElement,
309
+ SingleChoiceElement,
310
+ RatingScaleElement,
311
+ TextInputElement,
312
+ DatePickerElement,
313
+ SignatureElement,
314
+ DigitalSignatureElement,
315
+ FileUploadElement,
302
316
  } from "./types/documentation-templates";
303
317
  export {
304
318
  DocumentElementType,
@@ -306,11 +320,11 @@ export {
306
320
  ListType,
307
321
  DynamicVariable,
308
322
  FilledDocumentStatus,
309
- } from "./types/documentation-templates";
310
- export {
311
323
  DOCUMENTATION_TEMPLATES_COLLECTION,
312
324
  FILLED_DOCUMENTS_COLLECTION,
313
- } from "./types";
325
+ USER_FORMS_SUBCOLLECTION,
326
+ DOCTOR_FORMS_SUBCOLLECTION,
327
+ } from "./types/documentation-templates";
314
328
 
315
329
  // Procedure types
316
330
  export type {
@@ -144,12 +144,14 @@ export class DocumentationTemplateService extends BaseService {
144
144
  updatePayload.isActive = validatedData.isActive;
145
145
  if (validatedData.tags !== undefined)
146
146
  updatePayload.tags = validatedData.tags;
147
- if (validatedData.isUserForm !== undefined)
148
- updatePayload.isUserForm = validatedData.isUserForm;
149
- if (validatedData.isRequired !== undefined)
150
- updatePayload.isRequired = validatedData.isRequired;
151
- if (validatedData.sortingOrder !== undefined)
152
- updatePayload.sortingOrder = validatedData.sortingOrder;
147
+
148
+ // Always include these properties with defaults if they're missing
149
+ updatePayload.isUserForm =
150
+ validatedData.isUserForm ?? template.isUserForm ?? false;
151
+ updatePayload.isRequired =
152
+ validatedData.isRequired ?? template.isRequired ?? false;
153
+ updatePayload.sortingOrder =
154
+ validatedData.sortingOrder ?? template.sortingOrder ?? 0;
153
155
 
154
156
  const docRef = doc(this.collectionRef, templateId);
155
157
  await updateDoc(docRef, updatePayload);
@@ -287,4 +289,37 @@ export class DocumentationTemplateService extends BaseService {
287
289
  lastDoc: lastVisible,
288
290
  };
289
291
  }
292
+
293
+ /**
294
+ * Get all templates for selection with optional filtering
295
+ * @param options - Filtering options
296
+ * @returns Array of templates
297
+ */
298
+ async getAllTemplatesForSelection(options?: {
299
+ isUserForm?: boolean;
300
+ isRequired?: boolean;
301
+ }): Promise<DocumentTemplate[]> {
302
+ let q = query(
303
+ this.collectionRef,
304
+ where("isActive", "==", true),
305
+ orderBy("updatedAt", "desc")
306
+ );
307
+
308
+ if (options?.isUserForm !== undefined) {
309
+ q = query(q, where("isUserForm", "==", options.isUserForm));
310
+ }
311
+
312
+ if (options?.isRequired !== undefined) {
313
+ q = query(q, where("isRequired", "==", options.isRequired));
314
+ }
315
+
316
+ const querySnapshot = await getDocs(q);
317
+ const templates: DocumentTemplate[] = [];
318
+
319
+ querySnapshot.forEach((doc) => {
320
+ templates.push(doc.data() as DocumentTemplate);
321
+ });
322
+
323
+ return templates;
324
+ }
290
325
  }
@@ -184,7 +184,7 @@ export class ProcedureService extends BaseService {
184
184
  preRequirements: technology.requirements.pre,
185
185
  postRequirements: technology.requirements.post,
186
186
  certificationRequirement: technology.certificationRequirement,
187
- documentationTemplates: technology.documentationTemplates || [],
187
+ documentationTemplates: technology?.documentationTemplates || [],
188
188
  clinicInfo, // Embed aggregated info
189
189
  doctorInfo, // Embed aggregated info
190
190
  reviewInfo: {
@@ -57,17 +57,17 @@ export enum HeadingLevel {
57
57
  * Enum for dynamic variable placeholders
58
58
  */
59
59
  export enum DynamicVariable {
60
- PATIENT_NAME = "[PATIENT_NAME]",
61
- DOCTOR_NAME = "[DOCTOR_NAME]",
62
- CLINIC_NAME = "[CLINIC_NAME]",
63
- PATIENT_BIRTHDAY = "[PATIENT_BIRTHDAY]",
64
- APPOINTMENT_DATE = "[APPOINTMENT_DATE]",
65
- CURRENT_DATE = "[CURRENT_DATE]",
66
- PROCEDURE_NAME = "[PROCEDURE_NAME]",
67
- PROCEDURE_DESCRIPTION = "[PROCEDURE_DESCRIPTION]",
68
- PROCEDURE_COST = "[PROCEDURE_COST]",
69
- PROCEDURE_DURATION = "[PROCEDURE_DURATION]",
70
- PROCEDURE_RISK = "[PROCEDURE_RISK]",
60
+ PATIENT_NAME = "$[PATIENT_NAME]",
61
+ DOCTOR_NAME = "$[DOCTOR_NAME]",
62
+ CLINIC_NAME = "$[CLINIC_NAME]",
63
+ PATIENT_BIRTHDAY = "$[PATIENT_BIRTHDAY]",
64
+ APPOINTMENT_DATE = "$[APPOINTMENT_DATE]",
65
+ CURRENT_DATE = "$[CURRENT_DATE]",
66
+ PROCEDURE_NAME = "$[PROCEDURE_NAME]",
67
+ PROCEDURE_DESCRIPTION = "$[PROCEDURE_DESCRIPTION]",
68
+ PROCEDURE_COST = "$[PROCEDURE_COST]",
69
+ PROCEDURE_DURATION = "$[PROCEDURE_DURATION]",
70
+ PROCEDURE_RISK = "$[PROCEDURE_RISK]",
71
71
  }
72
72
 
73
73
  /**
@@ -8,11 +8,11 @@ export const PATIENT_MEDICAL_INFO_COLLECTION = "medical_info";
8
8
  export interface Allergy {
9
9
  type: AllergyType;
10
10
  subtype: AllergySubtype;
11
- name?: string;
12
- severity?: "mild" | "moderate" | "severe";
13
- reaction?: string;
14
- diagnosed?: Timestamp;
15
- notes?: string;
11
+ name?: string | null;
12
+ severity?: "mild" | "moderate" | "severe" | null;
13
+ reaction?: string | null;
14
+ diagnosed?: Timestamp | null;
15
+ notes?: string | null;
16
16
  }
17
17
 
18
18
  export interface VitalStats {
@@ -51,9 +51,9 @@ export interface PatientMedicalInfo {
51
51
  name: string;
52
52
  dosage: string;
53
53
  frequency: string;
54
- startDate: Timestamp;
55
- endDate?: Timestamp;
56
- prescribedBy?: string;
54
+ startDate?: Timestamp | null;
55
+ endDate?: Timestamp | null;
56
+ prescribedBy?: string | null;
57
57
  }[];
58
58
 
59
59
  emergencyNotes?: string;
@@ -87,11 +87,11 @@ export interface UpdateVitalStatsData {
87
87
  export interface AddAllergyData {
88
88
  type: AllergyType;
89
89
  subtype: AllergySubtype;
90
- name?: string;
90
+ name?: string | null;
91
91
  severity?: "mild" | "moderate" | "severe";
92
- reaction?: string;
93
- diagnosed?: Timestamp;
94
- notes?: string;
92
+ reaction?: string | null;
93
+ diagnosed?: Timestamp | null;
94
+ notes?: string | null;
95
95
  }
96
96
 
97
97
  export interface UpdateAllergyData extends Partial<AddAllergyData> {
@@ -21,11 +21,11 @@ export const allergySubtypeSchema = z.union([
21
21
  export const allergySchema = z.object({
22
22
  type: z.nativeEnum(AllergyType),
23
23
  subtype: allergySubtypeSchema,
24
- name: z.string().optional(),
24
+ name: z.string().optional().nullable(),
25
25
  severity: z.enum(["mild", "moderate", "severe"]).optional(),
26
- reaction: z.string().optional(),
27
- diagnosed: timestampSchema.optional(),
28
- notes: z.string().optional(),
26
+ reaction: z.string().optional().nullable(),
27
+ diagnosed: timestampSchema.optional().nullable(),
28
+ notes: z.string().optional().nullable(),
29
29
  });
30
30
 
31
31
  export const vitalStatsSchema = z.object({
@@ -46,7 +46,7 @@ export const vitalStatsSchema = z.object({
46
46
  export const blockingConditionSchema = z.object({
47
47
  condition: z.nativeEnum(BlockingCondition),
48
48
  diagnosedAt: timestampSchema,
49
- notes: z.string().optional(),
49
+ notes: z.string().optional().nullable(),
50
50
  isActive: z.boolean(),
51
51
  });
52
52
 
@@ -54,7 +54,7 @@ export const contraindicationSchema = z.object({
54
54
  condition: z.nativeEnum(Contraindication),
55
55
  lastOccurrence: timestampSchema,
56
56
  frequency: z.enum(["rare", "occasional", "frequent"]),
57
- notes: z.string().optional(),
57
+ notes: z.string().optional().nullable(),
58
58
  isActive: z.boolean(),
59
59
  });
60
60
 
@@ -62,9 +62,9 @@ export const medicationSchema = z.object({
62
62
  name: z.string().min(1),
63
63
  dosage: z.string().min(1),
64
64
  frequency: z.string().min(1),
65
- startDate: timestampSchema,
66
- endDate: timestampSchema.optional(),
67
- prescribedBy: z.string().optional(),
65
+ startDate: timestampSchema.optional().nullable(),
66
+ endDate: timestampSchema.optional().nullable(),
67
+ prescribedBy: z.string().optional().nullable(),
68
68
  });
69
69
 
70
70
  export const patientMedicalInfoSchema = z.object({