@blackcode_sa/metaestetics-api 1.5.10 → 1.5.12

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
 
@@ -81,6 +81,8 @@ export const technologySchema = z.object({
81
81
  .string()
82
82
  .max(2000, "Technical details are too long")
83
83
  .optional(),
84
+ family: procedureFamilySchema,
85
+ categoryId: z.string().min(1, "Category ID is required"),
84
86
  subcategoryId: z.string().min(1, "Subcategory ID is required"),
85
87
  requirements: technologyRequirementsSchema.default({
86
88
  pre: [],
@@ -47,6 +47,12 @@ import { CategoryService } from "../../backoffice/services/category.service";
47
47
  import { SubcategoryService } from "../../backoffice/services/subcategory.service";
48
48
  import { TechnologyService } from "../../backoffice/services/technology.service";
49
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";
50
56
 
51
57
  export class ProcedureService extends BaseService {
52
58
  private categoryService: CategoryService;
@@ -86,11 +92,7 @@ export class ProcedureService extends BaseService {
86
92
  validatedData.categoryId,
87
93
  validatedData.subcategoryId
88
94
  ),
89
- this.technologyService.getById(
90
- validatedData.categoryId,
91
- validatedData.subcategoryId,
92
- validatedData.technologyId
93
- ),
95
+ this.technologyService.getById(validatedData.technologyId),
94
96
  this.productService.getById(
95
97
  validatedData.categoryId,
96
98
  validatedData.subcategoryId,
@@ -228,4 +230,59 @@ export class ProcedureService extends BaseService {
228
230
  updatedAt: serverTimestamp(),
229
231
  });
230
232
  }
233
+
234
+ /**
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"]
254
+ */
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);
264
+
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
+ );
277
+
278
+ // Flatten the array of procedure arrays
279
+ const flattenedProcedures = procedures.flat();
280
+
281
+ return {
282
+ procedures: flattenedProcedures,
283
+ families,
284
+ categories,
285
+ subcategories,
286
+ };
287
+ }
231
288
  }