@blackcode_sa/metaestetics-api 1.5.29 → 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.
@@ -0,0 +1,88 @@
1
+ # Procedure Service
2
+
3
+ This service manages medical/aesthetic procedure data within the Firestore database. It handles the creation, retrieval, updating, and deletion of procedures linked to practitioners and clinics.
4
+
5
+ **Note:** Data aggregation into related entities (Practitioners, Clinics) is handled by Cloud Functions triggered by Firestore events.
6
+
7
+ ## `ProcedureService` Class
8
+
9
+ Extends `BaseService`.
10
+
11
+ ### Constructor
12
+
13
+ ```typescript
14
+ constructor(
15
+ db: Firestore,
16
+ auth: Auth,
17
+ app: FirebaseApp,
18
+ categoryService: CategoryService,
19
+ subcategoryService: SubcategoryService,
20
+ technologyService: TechnologyService,
21
+ productService: ProductService
22
+ )
23
+ ```
24
+
25
+ Initializes the service with Firestore, Auth, App instances, and required dependency services for fetching related category, subcategory, technology, and product details.
26
+
27
+ ### Core Methods
28
+
29
+ - **`createProcedure(data: CreateProcedureData): Promise<Procedure>`**
30
+
31
+ - Creates a new procedure document in Firestore.
32
+ - Validates input data using `createProcedureSchema`.
33
+ - Fetches full Category, Subcategory, Technology, and Product documents using injected services.
34
+ - Retrieves associated Clinic and Practitioner documents to embed `clinicInfo` and `doctorInfo`.
35
+ - Embeds treatment details from the technology (blocking conditions, benefits, requirements).
36
+ - Initializes default `reviewInfo` with zero values.
37
+ - Sets `isActive` to `true` by default.
38
+ - **Aggregation Note:** Adding procedure info to associated Practitioner and Clinic documents is handled by Cloud Functions.
39
+
40
+ - **`getProcedure(id: string): Promise<Procedure | null>`**
41
+
42
+ - Retrieves a single procedure document by its ID.
43
+ - Returns null if not found.
44
+
45
+ - **`getProceduresByClinicBranch(clinicBranchId: string): Promise<Procedure[]>`**
46
+
47
+ - Retrieves all active procedures associated with a specific clinic branch.
48
+ - Uses a Firestore query with `where("clinicBranchId", "==", clinicBranchId)` and `where("isActive", "==", true)`.
49
+
50
+ - **`getProceduresByPractitioner(practitionerId: string): Promise<Procedure[]>`**
51
+
52
+ - Retrieves all active procedures associated with a specific practitioner.
53
+ - Uses a Firestore query with `where("practitionerId", "==", practitionerId)` and `where("isActive", "==", true)`.
54
+
55
+ - **`updateProcedure(id: string, data: UpdateProcedureData): Promise<Procedure>`**
56
+
57
+ - Updates an existing procedure document with partial data.
58
+ - Validates input data using `updateProcedureSchema`.
59
+ - Handles complex updates of related entities:
60
+ - If practitioner changes: Fetches new practitioner data and updates embedded `doctorInfo`.
61
+ - If clinic changes: Fetches new clinic data and updates embedded `clinicInfo`.
62
+ - If category/subcategory changes: Fetches and updates embedded objects.
63
+ - If technology/product changes: Fetches and updates embedded objects plus derived fields.
64
+ - Updates the `updatedAt` timestamp.
65
+ - **Aggregation Note:** Updating aggregated data in related entities is handled by Cloud Functions.
66
+
67
+ - **`deactivateProcedure(id: string): Promise<void>`**
68
+
69
+ - Sets the `isActive` flag of a procedure to `false`.
70
+ - Updates the `updatedAt` timestamp.
71
+ - **Aggregation Note:** Removing from active lists in related entities is handled by Cloud Functions.
72
+
73
+ - **`deleteProcedure(id: string): Promise<boolean>`**
74
+
75
+ - Permanently deletes a procedure document from Firestore.
76
+ - Returns `true` if successful, `false` if the document didn't exist.
77
+ - **Aggregation Note:** Removing from related entities is handled by Cloud Functions.
78
+
79
+ - **`getAllowedTechnologies(practitioner: Practitioner): Promise<{ technologies: Technology[]; families: ProcedureFamily[]; categories: string[]; subcategories: string[]; }>`**
80
+
81
+ - Delegates to the `TechnologyService.getAllowedTechnologies` method.
82
+ - Determines which technologies a practitioner is certified to perform based on their certification level.
83
+ - Returns an object containing arrays of allowed technologies, families, categories, and subcategories.
84
+
85
+ - **`getAllProcedures(pagination?: number, lastDoc?: any): Promise<{ procedures: Procedure[]; lastDoc: any }>`**
86
+ - Retrieves all procedures, ordered by name.
87
+ - Supports optional pagination with `limit` and `startAfter`.
88
+ - Returns both the procedures array and the last document for cursor-based pagination.