@blackcode_sa/metaestetics-api 1.12.67 → 1.13.0

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.
Files changed (47) hide show
  1. package/dist/admin/index.d.mts +801 -2
  2. package/dist/admin/index.d.ts +801 -2
  3. package/dist/admin/index.js +2332 -153
  4. package/dist/admin/index.mjs +2321 -153
  5. package/dist/backoffice/index.d.mts +40 -0
  6. package/dist/backoffice/index.d.ts +40 -0
  7. package/dist/backoffice/index.js +118 -18
  8. package/dist/backoffice/index.mjs +118 -20
  9. package/dist/index.d.mts +1097 -2
  10. package/dist/index.d.ts +1097 -2
  11. package/dist/index.js +4224 -2091
  12. package/dist/index.mjs +3941 -1821
  13. package/package.json +1 -1
  14. package/src/admin/aggregation/appointment/appointment.aggregation.service.ts +140 -0
  15. package/src/admin/analytics/analytics.admin.service.ts +278 -0
  16. package/src/admin/analytics/index.ts +2 -0
  17. package/src/admin/index.ts +6 -0
  18. package/src/backoffice/services/README.md +17 -0
  19. package/src/backoffice/services/analytics.service.proposal.md +863 -0
  20. package/src/backoffice/services/analytics.service.summary.md +143 -0
  21. package/src/backoffice/services/category.service.ts +49 -6
  22. package/src/backoffice/services/subcategory.service.ts +50 -6
  23. package/src/backoffice/services/technology.service.ts +53 -6
  24. package/src/services/analytics/ARCHITECTURE.md +199 -0
  25. package/src/services/analytics/CLOUD_FUNCTIONS.md +225 -0
  26. package/src/services/analytics/GROUPED_ANALYTICS.md +501 -0
  27. package/src/services/analytics/QUICK_START.md +393 -0
  28. package/src/services/analytics/README.md +287 -0
  29. package/src/services/analytics/SUMMARY.md +141 -0
  30. package/src/services/analytics/USAGE_GUIDE.md +518 -0
  31. package/src/services/analytics/analytics-cloud.service.ts +222 -0
  32. package/src/services/analytics/analytics.service.ts +1632 -0
  33. package/src/services/analytics/index.ts +3 -0
  34. package/src/services/analytics/utils/appointment-filtering.utils.ts +138 -0
  35. package/src/services/analytics/utils/cost-calculation.utils.ts +154 -0
  36. package/src/services/analytics/utils/grouping.utils.ts +394 -0
  37. package/src/services/analytics/utils/stored-analytics.utils.ts +347 -0
  38. package/src/services/analytics/utils/time-calculation.utils.ts +186 -0
  39. package/src/services/appointment/appointment.service.ts +50 -6
  40. package/src/services/index.ts +1 -0
  41. package/src/services/procedure/procedure.service.ts +3 -3
  42. package/src/types/analytics/analytics.types.ts +500 -0
  43. package/src/types/analytics/grouped-analytics.types.ts +148 -0
  44. package/src/types/analytics/index.ts +4 -0
  45. package/src/types/analytics/stored-analytics.types.ts +137 -0
  46. package/src/types/index.ts +3 -0
  47. package/src/types/notifications/index.ts +21 -0
@@ -0,0 +1,137 @@
1
+ import { Timestamp } from 'firebase/firestore';
2
+ import {
3
+ PractitionerAnalytics,
4
+ ProcedureAnalytics,
5
+ TimeEfficiencyMetrics,
6
+ CancellationMetrics,
7
+ NoShowMetrics,
8
+ RevenueMetrics,
9
+ DashboardAnalytics,
10
+ ClinicAnalytics,
11
+ AnalyticsDateRange,
12
+ } from './analytics.types';
13
+
14
+ /**
15
+ * Period type for analytics snapshots
16
+ */
17
+ export type AnalyticsPeriod = 'daily' | 'weekly' | 'monthly' | 'yearly' | 'all_time';
18
+
19
+ /**
20
+ * Analytics document metadata
21
+ */
22
+ export interface AnalyticsMetadata {
23
+ clinicBranchId: string;
24
+ period: AnalyticsPeriod;
25
+ periodStart: Date;
26
+ periodEnd: Date;
27
+ computedAt: Timestamp;
28
+ computedBy: 'cloud_function' | 'manual';
29
+ version: string; // Schema version for future migrations
30
+ }
31
+
32
+ /**
33
+ * Stored Practitioner Analytics
34
+ * Stored in: clinics/{clinicBranchId}/analytics/practitioners/{practitionerId}/{period}
35
+ */
36
+ export interface StoredPractitionerAnalytics extends PractitionerAnalytics {
37
+ metadata: AnalyticsMetadata;
38
+ }
39
+
40
+ /**
41
+ * Stored Procedure Analytics
42
+ * Stored in: clinics/{clinicBranchId}/analytics/procedures/{procedureId}/{period}
43
+ */
44
+ export interface StoredProcedureAnalytics extends ProcedureAnalytics {
45
+ metadata: AnalyticsMetadata;
46
+ }
47
+
48
+ /**
49
+ * Stored Clinic Analytics
50
+ * Stored in: clinics/{clinicBranchId}/analytics/clinic/{period}
51
+ */
52
+ export interface StoredClinicAnalytics extends ClinicAnalytics {
53
+ metadata: AnalyticsMetadata;
54
+ }
55
+
56
+ /**
57
+ * Stored Dashboard Analytics
58
+ * Stored in: clinics/{clinicBranchId}/analytics/dashboard/{period}
59
+ */
60
+ export interface StoredDashboardAnalytics extends DashboardAnalytics {
61
+ metadata: AnalyticsMetadata;
62
+ }
63
+
64
+ /**
65
+ * Stored Time Efficiency Metrics
66
+ * Stored in: clinics/{clinicBranchId}/analytics/time_efficiency/{period}
67
+ */
68
+ export interface StoredTimeEfficiencyMetrics extends TimeEfficiencyMetrics {
69
+ metadata: AnalyticsMetadata;
70
+ }
71
+
72
+ /**
73
+ * Stored Cancellation Metrics
74
+ * Stored in: clinics/{clinicBranchId}/analytics/cancellations/{entityType}/{period}
75
+ */
76
+ export interface StoredCancellationMetrics extends CancellationMetrics {
77
+ metadata: AnalyticsMetadata;
78
+ }
79
+
80
+ /**
81
+ * Stored No-Show Metrics
82
+ * Stored in: clinics/{clinicBranchId}/analytics/no_shows/{entityType}/{period}
83
+ */
84
+ export interface StoredNoShowMetrics extends NoShowMetrics {
85
+ metadata: AnalyticsMetadata;
86
+ }
87
+
88
+ /**
89
+ * Stored Revenue Metrics
90
+ * Stored in: clinics/{clinicBranchId}/analytics/revenue/{period}
91
+ */
92
+ export interface StoredRevenueMetrics extends RevenueMetrics {
93
+ metadata: AnalyticsMetadata;
94
+ }
95
+
96
+ /**
97
+ * Collection names for stored analytics
98
+ */
99
+ export const ANALYTICS_COLLECTION = 'analytics';
100
+ export const PRACTITIONER_ANALYTICS_SUBCOLLECTION = 'practitioners';
101
+ export const PROCEDURE_ANALYTICS_SUBCOLLECTION = 'procedures';
102
+ export const CLINIC_ANALYTICS_SUBCOLLECTION = 'clinic';
103
+ export const DASHBOARD_ANALYTICS_SUBCOLLECTION = 'dashboard';
104
+ export const TIME_EFFICIENCY_ANALYTICS_SUBCOLLECTION = 'time_efficiency';
105
+ export const CANCELLATION_ANALYTICS_SUBCOLLECTION = 'cancellations';
106
+ export const NO_SHOW_ANALYTICS_SUBCOLLECTION = 'no_shows';
107
+ export const REVENUE_ANALYTICS_SUBCOLLECTION = 'revenue';
108
+
109
+ /**
110
+ * Options for reading stored analytics
111
+ */
112
+ export interface ReadStoredAnalyticsOptions {
113
+ /**
114
+ * Whether to use cached/pre-computed data
115
+ * @default true
116
+ */
117
+ useCache?: boolean;
118
+ /**
119
+ * Maximum age of cached data in hours before recalculating
120
+ * @default 12
121
+ */
122
+ maxCacheAgeHours?: number;
123
+ /**
124
+ * Period to read
125
+ * @default 'all_time'
126
+ */
127
+ period?: AnalyticsPeriod;
128
+ /**
129
+ * Date range for the period (calculated if not provided)
130
+ */
131
+ dateRange?: AnalyticsDateRange;
132
+ /**
133
+ * Clinic branch ID (required for reading stored analytics)
134
+ */
135
+ clinicBranchId?: string;
136
+ }
137
+
@@ -40,5 +40,8 @@ export * from "./profile";
40
40
  // Reviews types
41
41
  export * from "./reviews";
42
42
 
43
+ // Analytics types
44
+ export * from "./analytics";
45
+
43
46
  // User types
44
47
  export * from "./user";
@@ -21,6 +21,7 @@ export enum NotificationType {
21
21
 
22
22
  // --- Patient Engagement ---
23
23
  REVIEW_REQUEST = "reviewRequest", // Request for patient review post-appointment
24
+ PROCEDURE_RECOMMENDATION = "procedureRecommendation", // Doctor recommended a procedure for follow-up
24
25
 
25
26
  // --- Payment Related (Examples) ---
26
27
  PAYMENT_DUE = "paymentDue",
@@ -231,6 +232,25 @@ export interface ReviewRequestNotification extends BaseNotification {
231
232
  procedureName?: string;
232
233
  }
233
234
 
235
+ /**
236
+ * Notification for when a doctor recommends a procedure for follow-up.
237
+ * Example: "Dr. Smith recommended [Procedure Name] for you. Suggested timeframe: in 2 weeks"
238
+ */
239
+ export interface ProcedureRecommendationNotification extends BaseNotification {
240
+ notificationType: NotificationType.PROCEDURE_RECOMMENDATION;
241
+ appointmentId: string; // The appointment where recommendation was made
242
+ recommendationId: string; // Format: `${appointmentId}:${index}`
243
+ procedureId: string;
244
+ procedureName: string;
245
+ practitionerName: string;
246
+ clinicName: string;
247
+ note?: string; // Doctor's note about the recommendation
248
+ timeframe: {
249
+ value: number;
250
+ unit: 'day' | 'week' | 'month' | 'year';
251
+ };
252
+ }
253
+
234
254
  /**
235
255
  * Generic notification for direct messages or announcements.
236
256
  */
@@ -261,5 +281,6 @@ export type Notification =
261
281
  | FormReminderNotification
262
282
  | FormSubmissionConfirmationNotification
263
283
  | ReviewRequestNotification
284
+ | ProcedureRecommendationNotification
264
285
  | GeneralMessageNotification
265
286
  | PaymentConfirmationNotification;