@blackcode_sa/metaestetics-api 1.5.28 → 1.5.30
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/admin/index.d.mts +1324 -1
- package/dist/admin/index.d.ts +1324 -1
- package/dist/admin/index.js +1674 -2
- package/dist/admin/index.mjs +1668 -2
- package/dist/backoffice/index.d.mts +99 -7
- package/dist/backoffice/index.d.ts +99 -7
- package/dist/index.d.mts +4036 -2372
- package/dist/index.d.ts +4036 -2372
- package/dist/index.js +2331 -2009
- package/dist/index.mjs +2279 -1954
- package/package.json +2 -1
- package/src/admin/aggregation/README.md +79 -0
- package/src/admin/aggregation/clinic/README.md +52 -0
- package/src/admin/aggregation/clinic/clinic.aggregation.service.ts +642 -0
- package/src/admin/aggregation/patient/README.md +27 -0
- package/src/admin/aggregation/patient/patient.aggregation.service.ts +141 -0
- package/src/admin/aggregation/practitioner/README.md +42 -0
- package/src/admin/aggregation/practitioner/practitioner.aggregation.service.ts +433 -0
- package/src/admin/aggregation/procedure/README.md +43 -0
- package/src/admin/aggregation/procedure/procedure.aggregation.service.ts +508 -0
- package/src/admin/index.ts +60 -4
- package/src/admin/mailing/README.md +95 -0
- package/src/admin/mailing/base.mailing.service.ts +131 -0
- package/src/admin/mailing/index.ts +2 -0
- package/src/admin/mailing/practitionerInvite/index.ts +1 -0
- package/src/admin/mailing/practitionerInvite/practitionerInvite.mailing.ts +256 -0
- package/src/admin/mailing/practitionerInvite/templates/invitation.template.ts +101 -0
- package/src/index.ts +28 -4
- package/src/services/README.md +106 -0
- package/src/services/clinic/README.md +87 -0
- package/src/services/clinic/clinic.service.ts +197 -107
- package/src/services/clinic/utils/clinic.utils.ts +68 -119
- package/src/services/clinic/utils/filter.utils.d.ts +23 -0
- package/src/services/clinic/utils/filter.utils.ts +264 -0
- package/src/services/practitioner/README.md +145 -0
- package/src/services/practitioner/practitioner.service.ts +439 -104
- package/src/services/procedure/README.md +88 -0
- package/src/services/procedure/procedure.service.ts +521 -311
- package/src/services/reviews/reviews.service.ts +842 -0
- package/src/types/clinic/index.ts +24 -56
- package/src/types/practitioner/index.ts +34 -33
- package/src/types/procedure/index.ts +32 -0
- package/src/types/profile/index.ts +1 -1
- package/src/types/reviews/index.ts +126 -0
- package/src/validations/clinic.schema.ts +37 -64
- package/src/validations/practitioner.schema.ts +42 -32
- package/src/validations/procedure.schema.ts +11 -3
- package/src/validations/reviews.schema.ts +189 -0
- package/src/services/clinic/utils/review.utils.ts +0 -93
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blackcode_sa/metaestetics-api",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.30",
|
|
5
5
|
"description": "Firebase authentication service with anonymous upgrade support",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
@@ -83,6 +83,7 @@
|
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@testing-library/jest-dom": "^6.6.3",
|
|
85
85
|
"@types/jest": "^29.5.14",
|
|
86
|
+
"@types/mailgun-js": "^0.22.18",
|
|
86
87
|
"@types/node": "^20.17.13",
|
|
87
88
|
"@types/react": "~18.3.12",
|
|
88
89
|
"expo-crypto": "^14.0.0",
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Data Aggregation Services
|
|
2
|
+
|
|
3
|
+
This directory contains services responsible for maintaining data consistency across related Firestore collections. These aggregation services are typically used by Cloud Functions that react to document changes (create/update/delete operations).
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
When a document is created, updated, or deleted in one collection, related documents in other collections often need to be updated to maintain data consistency and support efficient querying. For example:
|
|
8
|
+
|
|
9
|
+
- When a practitioner is updated, their information needs to be updated in associated clinics
|
|
10
|
+
- When a procedure is added, summaries need to be added to both practitioner and clinic documents
|
|
11
|
+
- When a clinic is deleted, related calendar events need to be canceled
|
|
12
|
+
|
|
13
|
+
Rather than embedding this logic in the main service classes, these aggregation services keep the concerns separate and can be independently triggered by Cloud Functions.
|
|
14
|
+
|
|
15
|
+
## Design Pattern
|
|
16
|
+
|
|
17
|
+
Each aggregation service:
|
|
18
|
+
|
|
19
|
+
1. Handles a specific domain entity (clinic, practitioner, procedure, etc.)
|
|
20
|
+
2. Contains methods organized by event type (creation, update, deletion)
|
|
21
|
+
3. Focuses solely on updating related collections
|
|
22
|
+
4. Uses transactions where appropriate to ensure consistency
|
|
23
|
+
|
|
24
|
+
## Available Aggregation Services
|
|
25
|
+
|
|
26
|
+
- `ClinicAggregationService`: Handles clinic-related aggregations
|
|
27
|
+
- `PractitionerAggregationService`: Handles practitioner-related aggregations
|
|
28
|
+
- `ProcedureAggregationService`: Handles procedure-related aggregations
|
|
29
|
+
- `PatientAggregationService`: Handles patient-related aggregations
|
|
30
|
+
|
|
31
|
+
## Implementation Notes
|
|
32
|
+
|
|
33
|
+
- These services are for admin/internal use only
|
|
34
|
+
- They operate with admin Firestore privileges
|
|
35
|
+
- They are designed for use by Cloud Functions, not directly by client applications
|
|
36
|
+
- They include detailed logging for monitoring and debugging
|
|
37
|
+
|
|
38
|
+
## Example Usage
|
|
39
|
+
|
|
40
|
+
In a Cloud Function:
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
exports.onPractitionerUpdate = functions.firestore
|
|
44
|
+
.document('practitioners/{practitionerId}')
|
|
45
|
+
.onUpdate(async (change, context) => {
|
|
46
|
+
const beforeData = change.before.data();
|
|
47
|
+
const afterData = change.after.data();
|
|
48
|
+
const practitionerId = context.params.practitionerId;
|
|
49
|
+
|
|
50
|
+
// Only run aggregation if specific fields changed
|
|
51
|
+
if (beforeData.basicInfo.firstName !== afterData.basicInfo.firstName ||
|
|
52
|
+
beforeData.basicInfo.lastName !== afterData.basicInfo.lastName ||
|
|
53
|
+
beforeData.basicInfo.profileImageUrl !== afterData.basicInfo.profileImageUrl) {
|
|
54
|
+
|
|
55
|
+
const aggregationService = new PractitionerAggregationService();
|
|
56
|
+
|
|
57
|
+
// Build doctorInfo object from updated data
|
|
58
|
+
const doctorInfo = {
|
|
59
|
+
id: practitionerId,
|
|
60
|
+
name: `${afterData.basicInfo.firstName} ${afterData.basicInfo.lastName}`,
|
|
61
|
+
photo: afterData.basicInfo.profileImageUrl || '',
|
|
62
|
+
// other fields...
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// Update practitioner info in all related clinics
|
|
66
|
+
await aggregationService.updatePractitionerInfoInClinics(
|
|
67
|
+
afterData.clinics,
|
|
68
|
+
doctorInfo
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// Update practitioner info in all related procedures
|
|
72
|
+
await aggregationService.updatePractitionerInfoInProcedures(
|
|
73
|
+
afterData.procedures,
|
|
74
|
+
doctorInfo
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
</rewritten_file>
|
|
79
|
+
```
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Clinic Aggregation Service (Admin)
|
|
2
|
+
|
|
3
|
+
This service centralizes the logic for updating aggregated data in various Firestore collections _when a clinic is created, updated, or deleted_. It is designed primarily for use by Cloud Functions triggered by changes in the `clinics` collection.
|
|
4
|
+
|
|
5
|
+
## `ClinicAggregationService` Class
|
|
6
|
+
|
|
7
|
+
### Constructor
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
constructor(firestore?: admin.firestore.Firestore)
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Initializes the service with an Admin Firestore instance. Uses the default instance if none is provided.
|
|
14
|
+
|
|
15
|
+
### Methods Triggered by Clinic **Creation**
|
|
16
|
+
|
|
17
|
+
- **`addClinicToClinicGroup(clinicGroupId: string, clinicInfo: ClinicInfo): Promise<void>`**
|
|
18
|
+
- Adds the `clinicInfo` object and `clinicId` to the `clinicsInfo` and `clinicIds` arrays respectively in the specified parent `ClinicGroup` document.
|
|
19
|
+
|
|
20
|
+
### Methods Triggered by Clinic **Update**
|
|
21
|
+
|
|
22
|
+
- **`updateClinicInfoInPractitioners(practitionerIds: string[], clinicInfo: ClinicInfo): Promise<void>`**
|
|
23
|
+
- Updates the aggregated `clinicsInfo` array within multiple `Practitioner` documents.
|
|
24
|
+
- Uses a batch write to first remove the old `ClinicInfo` (matching by `id`) and then add the updated `clinicInfo`.
|
|
25
|
+
- **`updateClinicInfoInProcedures(procedureIds: string[], clinicInfo: ClinicInfo): Promise<void>`**
|
|
26
|
+
- Updates the embedded `clinicInfo` object within multiple `Procedure` documents associated with the updated clinic.
|
|
27
|
+
- **`updateClinicInfoInClinicGroup(clinicGroupId: string, clinicInfo: ClinicInfo): Promise<void>`**
|
|
28
|
+
- Updates the `clinicsInfo` array within the parent `ClinicGroup` document.
|
|
29
|
+
- Uses a batch write to first remove the old `ClinicInfo` (matching by `id`) and then add the updated `clinicInfo`.
|
|
30
|
+
- **`updateClinicInfoInPatients(patientIds: string[], clinicInfo: ClinicInfo, clinicIsActive: boolean): Promise<void>`**
|
|
31
|
+
- Currently logs a warning as the `PatientProfile` doesn't store full `ClinicInfo`.
|
|
32
|
+
- Intended place for logic if patient records need updates based on clinic changes (e.g., clinic deactivation).
|
|
33
|
+
- **`updateClinicLocationInCalendarEvents(clinicId: string, newLocation: ClinicLocation): Promise<void>`**
|
|
34
|
+
- Uses a Collection Group query (`calendar` subcollection) to find all _upcoming_ calendar events associated with the `clinicId`.
|
|
35
|
+
- Updates the `eventLocation` field in these calendar events with the `newLocation`.
|
|
36
|
+
- **`updateClinicInfoInCalendarEvents(clinicId: string, clinicInfo: ClinicInfo): Promise<void>`**
|
|
37
|
+
- Uses a Collection Group query (`calendar` subcollection) to find all _upcoming_ calendar events associated with the `clinicId`.
|
|
38
|
+
- Updates the embedded `clinicInfo` object in these calendar events.
|
|
39
|
+
|
|
40
|
+
### Methods Triggered by Clinic **Deletion**
|
|
41
|
+
|
|
42
|
+
- **`removeClinicFromPractitioners(practitionerIds: string[], clinicId: string): Promise<void>`**
|
|
43
|
+
- Removes the `clinicId` from the `clinicIds` array and the corresponding `ClinicInfo` object (matching by `id`) from the `clinicsInfo` array in multiple `Practitioner` documents.
|
|
44
|
+
- **`inactivateProceduresForClinic(procedureIds: string[]): Promise<void>`**
|
|
45
|
+
- Sets the `isActive` flag to `false` for multiple `Procedure` documents associated with the deleted clinic.
|
|
46
|
+
- **`removeClinicFromClinicGroup(clinicGroupId: string, clinicId: string): Promise<void>`**
|
|
47
|
+
- Removes the `clinicId` from the `clinicIds` array and the corresponding `ClinicInfo` object (matching by `id`) from the `clinicsInfo` array in the parent `ClinicGroup` document.
|
|
48
|
+
- **`removeClinicFromPatients(patientIds: string[], clinicId: string): Promise<void>`**
|
|
49
|
+
- Removes the `clinicId` from the `clinicIds` array in multiple `Patient` documents.
|
|
50
|
+
- **`cancelUpcomingCalendarEventsForClinic(clinicId: string): Promise<void>`**
|
|
51
|
+
- Uses a Collection Group query (`calendar` subcollection) to find all _upcoming_ calendar events associated with the `clinicId`.
|
|
52
|
+
- Sets the `status` of these events to `CANCELED` and adds a `cancelReason`.
|