@blackcode_sa/metaestetics-api 1.5.9 → 1.5.11

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.
@@ -4,6 +4,7 @@ import { Contraindication } from "./static/contraindication.types";
4
4
  import { TreatmentBenefit } from "./static/treatment-benefit.types";
5
5
  import { CertificationRequirement } from "./static/certification.types";
6
6
  import { DocumentTemplate } from "../../types/documentation-templates";
7
+ import { ProcedureFamily } from "./static/procedure-family.types";
7
8
 
8
9
  /**
9
10
  * Zahtevi koji su povezani sa tehnologijom
@@ -17,12 +18,14 @@ export interface TechnologyRequirements {
17
18
 
18
19
  /**
19
20
  * Technology used in medical procedures
20
- * Technologies are the third level of hierarchy, belonging to a specific subcategory
21
- * and represent a specific method or approach to treatment
21
+ * Technologies are now a top-level collection that reference their full path in the hierarchy
22
+ * through family, category, and subcategory IDs
22
23
  *
23
24
  * @property id - Unique identifier of the technology
24
25
  * @property name - Name of the technology
25
26
  * @property description - Detailed description of the technology and its application
27
+ * @property family - The procedure family this technology belongs to (aesthetics/surgery)
28
+ * @property categoryId - ID of the category this technology belongs to
26
29
  * @property subcategoryId - ID of the subcategory this technology belongs to
27
30
  * @property technicalDetails - Technical specifications and details
28
31
  * @property requirements - List of pre and post procedure requirements
@@ -44,6 +47,12 @@ export interface Technology {
44
47
  /** Detaljan opis tehnologije */
45
48
  description: string;
46
49
 
50
+ /** Familija procedura kojoj tehnologija pripada */
51
+ family: ProcedureFamily;
52
+
53
+ /** ID kategorije kojoj tehnologija pripada */
54
+ categoryId: string;
55
+
47
56
  /** ID potkategorije kojoj tehnologija pripada */
48
57
  subcategoryId: string;
49
58
 
@@ -43,10 +43,37 @@ import {
43
43
  Product,
44
44
  PRODUCTS_COLLECTION,
45
45
  } from "../../backoffice/types/product.types";
46
+ import { CategoryService } from "../../backoffice/services/category.service";
47
+ import { SubcategoryService } from "../../backoffice/services/subcategory.service";
48
+ import { TechnologyService } from "../../backoffice/services/technology.service";
49
+ import { ProductService } from "../../backoffice/services/product.service";
50
+ import { Practitioner } from "../../types/practitioner";
51
+ import {
52
+ CertificationLevel,
53
+ CertificationSpecialty,
54
+ ProcedureFamily,
55
+ } from "../../backoffice/types";
46
56
 
47
57
  export class ProcedureService extends BaseService {
48
- constructor(db: Firestore, auth: Auth, app: FirebaseApp) {
58
+ private categoryService: CategoryService;
59
+ private subcategoryService: SubcategoryService;
60
+ private technologyService: TechnologyService;
61
+ private productService: ProductService;
62
+
63
+ constructor(
64
+ db: Firestore,
65
+ auth: Auth,
66
+ app: FirebaseApp,
67
+ categoryService: CategoryService,
68
+ subcategoryService: SubcategoryService,
69
+ technologyService: TechnologyService,
70
+ productService: ProductService
71
+ ) {
49
72
  super(db, auth, app);
73
+ this.categoryService = categoryService;
74
+ this.subcategoryService = subcategoryService;
75
+ this.technologyService = technologyService;
76
+ this.productService = productService;
50
77
  }
51
78
 
52
79
  /**
@@ -60,10 +87,18 @@ export class ProcedureService extends BaseService {
60
87
 
61
88
  // Get references to related entities
62
89
  const [category, subcategory, technology, product] = await Promise.all([
63
- this.getCategory(validatedData.categoryId),
64
- this.getSubcategory(validatedData.subcategoryId),
65
- this.getTechnology(validatedData.technologyId),
66
- this.getProduct(validatedData.productId),
90
+ this.categoryService.getById(validatedData.categoryId),
91
+ this.subcategoryService.getById(
92
+ validatedData.categoryId,
93
+ validatedData.subcategoryId
94
+ ),
95
+ this.technologyService.getById(validatedData.technologyId),
96
+ this.productService.getById(
97
+ validatedData.categoryId,
98
+ validatedData.subcategoryId,
99
+ validatedData.technologyId,
100
+ validatedData.productId
101
+ ),
67
102
  ]);
68
103
 
69
104
  if (!category || !subcategory || !technology || !product) {
@@ -197,42 +232,57 @@ export class ProcedureService extends BaseService {
197
232
  }
198
233
 
199
234
  /**
200
- * Gets a category by ID
201
- * @private
235
+ * Gets all procedures that a practitioner is certified to perform
236
+ * @param practitioner - The practitioner's profile
237
+ * @returns Object containing:
238
+ * - procedures: List of procedures the practitioner can perform
239
+ * - families: List of procedure families the practitioner can perform
240
+ * - categories: List of category IDs the practitioner can perform
241
+ * - subcategories: List of subcategory IDs the practitioner can perform
242
+ *
243
+ * @example
244
+ * const practitioner = {
245
+ * certification: {
246
+ * level: CertificationLevel.DOCTOR,
247
+ * specialties: [CertificationSpecialty.INJECTABLES]
248
+ * }
249
+ * };
250
+ * const allowedProcedures = await procedureService.getAllowedProcedures(practitioner);
251
+ * console.log(allowedProcedures.families); // [ProcedureFamily.AESTHETICS]
252
+ * console.log(allowedProcedures.categories); // ["category1", "category2"]
253
+ * console.log(allowedProcedures.subcategories); // ["subcategory1", "subcategory2"]
202
254
  */
203
- private async getCategory(id: string): Promise<Category | null> {
204
- const docRef = doc(this.db, CATEGORIES_COLLECTION, id);
205
- const docSnap = await getDoc(docRef);
206
- return docSnap.exists() ? (docSnap.data() as Category) : null;
207
- }
255
+ async getAllowedProcedures(practitioner: Practitioner): Promise<{
256
+ procedures: Procedure[];
257
+ families: ProcedureFamily[];
258
+ categories: string[];
259
+ subcategories: string[];
260
+ }> {
261
+ // Get all allowed technologies for the practitioner
262
+ const { technologies, families, categories, subcategories } =
263
+ await this.technologyService.getAllowedTechnologies(practitioner);
208
264
 
209
- /**
210
- * Gets a subcategory by ID
211
- * @private
212
- */
213
- private async getSubcategory(id: string): Promise<Subcategory | null> {
214
- const docRef = doc(this.db, SUBCATEGORIES_COLLECTION, id);
215
- const docSnap = await getDoc(docRef);
216
- return docSnap.exists() ? (docSnap.data() as Subcategory) : null;
217
- }
265
+ // Get all procedures for these technologies
266
+ const procedures = await Promise.all(
267
+ technologies.map(async (technology) => {
268
+ const q = query(
269
+ collection(this.db, PROCEDURES_COLLECTION),
270
+ where("technologyId", "==", technology.id),
271
+ where("isActive", "==", true)
272
+ );
273
+ const snapshot = await getDocs(q);
274
+ return snapshot.docs.map((doc) => doc.data() as Procedure);
275
+ })
276
+ );
218
277
 
219
- /**
220
- * Gets a technology by ID
221
- * @private
222
- */
223
- private async getTechnology(id: string): Promise<Technology | null> {
224
- const docRef = doc(this.db, TECHNOLOGIES_COLLECTION, id);
225
- const docSnap = await getDoc(docRef);
226
- return docSnap.exists() ? (docSnap.data() as Technology) : null;
227
- }
278
+ // Flatten the array of procedure arrays
279
+ const flattenedProcedures = procedures.flat();
228
280
 
229
- /**
230
- * Gets a product by ID
231
- * @private
232
- */
233
- private async getProduct(id: string): Promise<Product | null> {
234
- const docRef = doc(this.db, PRODUCTS_COLLECTION, id);
235
- const docSnap = await getDoc(docRef);
236
- return docSnap.exists() ? (docSnap.data() as Product) : null;
281
+ return {
282
+ procedures: flattenedProcedures,
283
+ families,
284
+ categories,
285
+ subcategories,
286
+ };
237
287
  }
238
288
  }