@blackcode_sa/metaestetics-api 1.11.0 → 1.11.1

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 (35) hide show
  1. package/dist/admin/index.d.mts +328 -319
  2. package/dist/admin/index.d.ts +328 -319
  3. package/dist/backoffice/index.d.mts +283 -67
  4. package/dist/backoffice/index.d.ts +283 -67
  5. package/dist/backoffice/index.js +114 -6
  6. package/dist/backoffice/index.mjs +112 -6
  7. package/dist/index.d.mts +3872 -3806
  8. package/dist/index.d.ts +3872 -3806
  9. package/dist/index.js +369 -123
  10. package/dist/index.mjs +369 -124
  11. package/package.json +1 -1
  12. package/src/backoffice/expo-safe/index.ts +2 -0
  13. package/src/backoffice/services/README.md +40 -0
  14. package/src/backoffice/services/constants.service.ts +268 -0
  15. package/src/backoffice/services/technology.service.ts +122 -10
  16. package/src/backoffice/types/admin-constants.types.ts +69 -0
  17. package/src/backoffice/types/index.ts +1 -0
  18. package/src/backoffice/types/product.types.ts +3 -1
  19. package/src/backoffice/types/technology.types.ts +4 -4
  20. package/src/backoffice/validations/schemas.ts +35 -9
  21. package/src/services/appointment/appointment.service.ts +0 -5
  22. package/src/services/appointment/utils/appointment.utils.ts +124 -113
  23. package/src/services/procedure/procedure.service.ts +434 -234
  24. package/src/types/appointment/index.ts +5 -3
  25. package/src/types/clinic/index.ts +1 -6
  26. package/src/types/patient/medical-info.types.ts +3 -3
  27. package/src/types/procedure/index.ts +20 -17
  28. package/src/validations/clinic.schema.ts +1 -6
  29. package/src/validations/patient/medical-info.schema.ts +7 -2
  30. package/src/backoffice/services/__tests__/brand.service.test.ts +0 -196
  31. package/src/backoffice/services/__tests__/category.service.test.ts +0 -201
  32. package/src/backoffice/services/__tests__/product.service.test.ts +0 -358
  33. package/src/backoffice/services/__tests__/requirement.service.test.ts +0 -226
  34. package/src/backoffice/services/__tests__/subcategory.service.test.ts +0 -181
  35. package/src/backoffice/services/__tests__/technology.service.test.ts +0 -1097
@@ -79,6 +79,7 @@ __export(index_exports, {
79
79
  certificationLevelSchema: () => certificationLevelSchema,
80
80
  certificationRequirementSchema: () => certificationRequirementSchema,
81
81
  certificationSpecialtySchema: () => certificationSpecialtySchema,
82
+ contraindicationDynamicSchema: () => contraindicationDynamicSchema,
82
83
  contraindicationSchemaBackoffice: () => contraindicationSchemaBackoffice,
83
84
  createDocumentTemplateSchema: () => createDocumentTemplateSchema,
84
85
  documentElementSchema: () => documentElementSchema,
@@ -95,6 +96,7 @@ __export(index_exports, {
95
96
  technologyUpdateSchema: () => technologyUpdateSchema,
96
97
  timeUnitSchemaBackoffice: () => timeUnitSchemaBackoffice,
97
98
  timeframeSchema: () => timeframeSchema,
99
+ treatmentBenefitDynamicSchema: () => treatmentBenefitDynamicSchema,
98
100
  treatmentBenefitSchemaBackoffice: () => treatmentBenefitSchemaBackoffice,
99
101
  updateDocumentTemplateSchema: () => updateDocumentTemplateSchema
100
102
  });
@@ -1509,8 +1511,16 @@ var TechnologyService = class extends BaseService {
1509
1511
  */
1510
1512
  async addContraindication(technologyId, contraindication) {
1511
1513
  const docRef = (0, import_firestore10.doc)(this.getTechnologiesRef(), technologyId);
1514
+ const technology = await this.getById(technologyId);
1515
+ if (!technology) {
1516
+ throw new Error(`Technology with id ${technologyId} not found`);
1517
+ }
1518
+ const existingContraindications = technology.contraindications || [];
1519
+ if (existingContraindications.some((c) => c.id === contraindication.id)) {
1520
+ return technology;
1521
+ }
1512
1522
  await (0, import_firestore10.updateDoc)(docRef, {
1513
- contraindications: (0, import_firestore10.arrayUnion)(contraindication),
1523
+ contraindications: [...existingContraindications, contraindication],
1514
1524
  updatedAt: /* @__PURE__ */ new Date()
1515
1525
  });
1516
1526
  return this.getById(technologyId);
@@ -1523,8 +1533,44 @@ var TechnologyService = class extends BaseService {
1523
1533
  */
1524
1534
  async removeContraindication(technologyId, contraindication) {
1525
1535
  const docRef = (0, import_firestore10.doc)(this.getTechnologiesRef(), technologyId);
1536
+ const technology = await this.getById(technologyId);
1537
+ if (!technology) {
1538
+ throw new Error(`Technology with id ${technologyId} not found`);
1539
+ }
1540
+ const updatedContraindications = (technology.contraindications || []).filter((c) => c.id !== contraindication.id);
1541
+ await (0, import_firestore10.updateDoc)(docRef, {
1542
+ contraindications: updatedContraindications,
1543
+ updatedAt: /* @__PURE__ */ new Date()
1544
+ });
1545
+ return this.getById(technologyId);
1546
+ }
1547
+ /**
1548
+ * Updates an existing contraindication in a technology's list.
1549
+ * If the contraindication does not exist, it will not be added.
1550
+ * @param technologyId - ID of the technology
1551
+ * @param contraindication - The updated contraindication object
1552
+ * @returns The updated technology
1553
+ */
1554
+ async updateContraindication(technologyId, contraindication) {
1555
+ const docRef = (0, import_firestore10.doc)(this.getTechnologiesRef(), technologyId);
1556
+ const technology = await this.getById(technologyId);
1557
+ if (!technology) {
1558
+ throw new Error(`Technology with id ${technologyId} not found`);
1559
+ }
1560
+ const contraindications = technology.contraindications || [];
1561
+ const index = contraindications.findIndex(
1562
+ (c) => c.id === contraindication.id
1563
+ );
1564
+ if (index === -1) {
1565
+ console.warn(
1566
+ `Contraindication with id ${contraindication.id} not found for technology ${technologyId}. No update performed.`
1567
+ );
1568
+ return technology;
1569
+ }
1570
+ const updatedContraindications = [...contraindications];
1571
+ updatedContraindications[index] = contraindication;
1526
1572
  await (0, import_firestore10.updateDoc)(docRef, {
1527
- contraindications: (0, import_firestore10.arrayRemove)(contraindication),
1573
+ contraindications: updatedContraindications,
1528
1574
  updatedAt: /* @__PURE__ */ new Date()
1529
1575
  });
1530
1576
  return this.getById(technologyId);
@@ -1537,8 +1583,16 @@ var TechnologyService = class extends BaseService {
1537
1583
  */
1538
1584
  async addBenefit(technologyId, benefit) {
1539
1585
  const docRef = (0, import_firestore10.doc)(this.getTechnologiesRef(), technologyId);
1586
+ const technology = await this.getById(technologyId);
1587
+ if (!technology) {
1588
+ throw new Error(`Technology with id ${technologyId} not found`);
1589
+ }
1590
+ const existingBenefits = technology.benefits || [];
1591
+ if (existingBenefits.some((b) => b.id === benefit.id)) {
1592
+ return technology;
1593
+ }
1540
1594
  await (0, import_firestore10.updateDoc)(docRef, {
1541
- benefits: (0, import_firestore10.arrayUnion)(benefit),
1595
+ benefits: [...existingBenefits, benefit],
1542
1596
  updatedAt: /* @__PURE__ */ new Date()
1543
1597
  });
1544
1598
  return this.getById(technologyId);
@@ -1551,8 +1605,44 @@ var TechnologyService = class extends BaseService {
1551
1605
  */
1552
1606
  async removeBenefit(technologyId, benefit) {
1553
1607
  const docRef = (0, import_firestore10.doc)(this.getTechnologiesRef(), technologyId);
1608
+ const technology = await this.getById(technologyId);
1609
+ if (!technology) {
1610
+ throw new Error(`Technology with id ${technologyId} not found`);
1611
+ }
1612
+ const updatedBenefits = (technology.benefits || []).filter(
1613
+ (b) => b.id !== benefit.id
1614
+ );
1615
+ await (0, import_firestore10.updateDoc)(docRef, {
1616
+ benefits: updatedBenefits,
1617
+ updatedAt: /* @__PURE__ */ new Date()
1618
+ });
1619
+ return this.getById(technologyId);
1620
+ }
1621
+ /**
1622
+ * Updates an existing benefit in a technology's list.
1623
+ * If the benefit does not exist, it will not be added.
1624
+ * @param technologyId - ID of the technology
1625
+ * @param benefit - The updated benefit object
1626
+ * @returns The updated technology
1627
+ */
1628
+ async updateBenefit(technologyId, benefit) {
1629
+ const docRef = (0, import_firestore10.doc)(this.getTechnologiesRef(), technologyId);
1630
+ const technology = await this.getById(technologyId);
1631
+ if (!technology) {
1632
+ throw new Error(`Technology with id ${technologyId} not found`);
1633
+ }
1634
+ const benefits = technology.benefits || [];
1635
+ const index = benefits.findIndex((b) => b.id === benefit.id);
1636
+ if (index === -1) {
1637
+ console.warn(
1638
+ `Benefit with id ${benefit.id} not found for technology ${technologyId}. No update performed.`
1639
+ );
1640
+ return technology;
1641
+ }
1642
+ const updatedBenefits = [...benefits];
1643
+ updatedBenefits[index] = benefit;
1554
1644
  await (0, import_firestore10.updateDoc)(docRef, {
1555
- benefits: (0, import_firestore10.arrayRemove)(benefit),
1645
+ benefits: updatedBenefits,
1556
1646
  updatedAt: /* @__PURE__ */ new Date()
1557
1647
  });
1558
1648
  return this.getById(technologyId);
@@ -1776,9 +1866,25 @@ var TreatmentBenefit = /* @__PURE__ */ ((TreatmentBenefit2) => {
1776
1866
 
1777
1867
  // src/backoffice/validations/schemas.ts
1778
1868
  var import_zod2 = require("zod");
1869
+ var contraindicationDynamicSchema = import_zod2.z.object({
1870
+ id: import_zod2.z.string().min(1, "Contraindication ID is required").regex(
1871
+ /^[a-z0-9_]+$/,
1872
+ "ID must be in snake_case (lowercase, numbers, and underscores only)"
1873
+ ),
1874
+ name: import_zod2.z.string().min(1, "Contraindication name is required"),
1875
+ description: import_zod2.z.string().optional()
1876
+ });
1877
+ var treatmentBenefitDynamicSchema = import_zod2.z.object({
1878
+ id: import_zod2.z.string().min(1, "Benefit ID is required").regex(
1879
+ /^[a-z0-9_]+$/,
1880
+ "ID must be in snake_case (lowercase, numbers, and underscores only)"
1881
+ ),
1882
+ name: import_zod2.z.string().min(1, "Benefit name is required"),
1883
+ description: import_zod2.z.string().optional()
1884
+ });
1779
1885
  var blockingConditionSchemaBackoffice = import_zod2.z.nativeEnum(BlockingCondition);
1780
- var contraindicationSchemaBackoffice = import_zod2.z.nativeEnum(Contraindication);
1781
- var treatmentBenefitSchemaBackoffice = import_zod2.z.nativeEnum(TreatmentBenefit);
1886
+ var contraindicationSchemaBackoffice = contraindicationDynamicSchema;
1887
+ var treatmentBenefitSchemaBackoffice = treatmentBenefitDynamicSchema;
1782
1888
  var procedureFamilySchemaBackoffice = import_zod2.z.nativeEnum(ProcedureFamily);
1783
1889
  var timeUnitSchemaBackoffice = import_zod2.z.nativeEnum(TimeUnit);
1784
1890
  var requirementTypeSchema = import_zod2.z.nativeEnum(RequirementType);
@@ -2048,6 +2154,7 @@ var InvalidTreatmentBenefitError = class extends TreatmentBenefitError {
2048
2154
  certificationLevelSchema,
2049
2155
  certificationRequirementSchema,
2050
2156
  certificationSpecialtySchema,
2157
+ contraindicationDynamicSchema,
2051
2158
  contraindicationSchemaBackoffice,
2052
2159
  createDocumentTemplateSchema,
2053
2160
  documentElementSchema,
@@ -2064,6 +2171,7 @@ var InvalidTreatmentBenefitError = class extends TreatmentBenefitError {
2064
2171
  technologyUpdateSchema,
2065
2172
  timeUnitSchemaBackoffice,
2066
2173
  timeframeSchema,
2174
+ treatmentBenefitDynamicSchema,
2067
2175
  treatmentBenefitSchemaBackoffice,
2068
2176
  updateDocumentTemplateSchema
2069
2177
  });
@@ -1505,8 +1505,16 @@ var TechnologyService = class extends BaseService {
1505
1505
  */
1506
1506
  async addContraindication(technologyId, contraindication) {
1507
1507
  const docRef = doc9(this.getTechnologiesRef(), technologyId);
1508
+ const technology = await this.getById(technologyId);
1509
+ if (!technology) {
1510
+ throw new Error(`Technology with id ${technologyId} not found`);
1511
+ }
1512
+ const existingContraindications = technology.contraindications || [];
1513
+ if (existingContraindications.some((c) => c.id === contraindication.id)) {
1514
+ return technology;
1515
+ }
1508
1516
  await updateDoc9(docRef, {
1509
- contraindications: arrayUnion(contraindication),
1517
+ contraindications: [...existingContraindications, contraindication],
1510
1518
  updatedAt: /* @__PURE__ */ new Date()
1511
1519
  });
1512
1520
  return this.getById(technologyId);
@@ -1519,8 +1527,44 @@ var TechnologyService = class extends BaseService {
1519
1527
  */
1520
1528
  async removeContraindication(technologyId, contraindication) {
1521
1529
  const docRef = doc9(this.getTechnologiesRef(), technologyId);
1530
+ const technology = await this.getById(technologyId);
1531
+ if (!technology) {
1532
+ throw new Error(`Technology with id ${technologyId} not found`);
1533
+ }
1534
+ const updatedContraindications = (technology.contraindications || []).filter((c) => c.id !== contraindication.id);
1535
+ await updateDoc9(docRef, {
1536
+ contraindications: updatedContraindications,
1537
+ updatedAt: /* @__PURE__ */ new Date()
1538
+ });
1539
+ return this.getById(technologyId);
1540
+ }
1541
+ /**
1542
+ * Updates an existing contraindication in a technology's list.
1543
+ * If the contraindication does not exist, it will not be added.
1544
+ * @param technologyId - ID of the technology
1545
+ * @param contraindication - The updated contraindication object
1546
+ * @returns The updated technology
1547
+ */
1548
+ async updateContraindication(technologyId, contraindication) {
1549
+ const docRef = doc9(this.getTechnologiesRef(), technologyId);
1550
+ const technology = await this.getById(technologyId);
1551
+ if (!technology) {
1552
+ throw new Error(`Technology with id ${technologyId} not found`);
1553
+ }
1554
+ const contraindications = technology.contraindications || [];
1555
+ const index = contraindications.findIndex(
1556
+ (c) => c.id === contraindication.id
1557
+ );
1558
+ if (index === -1) {
1559
+ console.warn(
1560
+ `Contraindication with id ${contraindication.id} not found for technology ${technologyId}. No update performed.`
1561
+ );
1562
+ return technology;
1563
+ }
1564
+ const updatedContraindications = [...contraindications];
1565
+ updatedContraindications[index] = contraindication;
1522
1566
  await updateDoc9(docRef, {
1523
- contraindications: arrayRemove(contraindication),
1567
+ contraindications: updatedContraindications,
1524
1568
  updatedAt: /* @__PURE__ */ new Date()
1525
1569
  });
1526
1570
  return this.getById(technologyId);
@@ -1533,8 +1577,16 @@ var TechnologyService = class extends BaseService {
1533
1577
  */
1534
1578
  async addBenefit(technologyId, benefit) {
1535
1579
  const docRef = doc9(this.getTechnologiesRef(), technologyId);
1580
+ const technology = await this.getById(technologyId);
1581
+ if (!technology) {
1582
+ throw new Error(`Technology with id ${technologyId} not found`);
1583
+ }
1584
+ const existingBenefits = technology.benefits || [];
1585
+ if (existingBenefits.some((b) => b.id === benefit.id)) {
1586
+ return technology;
1587
+ }
1536
1588
  await updateDoc9(docRef, {
1537
- benefits: arrayUnion(benefit),
1589
+ benefits: [...existingBenefits, benefit],
1538
1590
  updatedAt: /* @__PURE__ */ new Date()
1539
1591
  });
1540
1592
  return this.getById(technologyId);
@@ -1547,8 +1599,44 @@ var TechnologyService = class extends BaseService {
1547
1599
  */
1548
1600
  async removeBenefit(technologyId, benefit) {
1549
1601
  const docRef = doc9(this.getTechnologiesRef(), technologyId);
1602
+ const technology = await this.getById(technologyId);
1603
+ if (!technology) {
1604
+ throw new Error(`Technology with id ${technologyId} not found`);
1605
+ }
1606
+ const updatedBenefits = (technology.benefits || []).filter(
1607
+ (b) => b.id !== benefit.id
1608
+ );
1609
+ await updateDoc9(docRef, {
1610
+ benefits: updatedBenefits,
1611
+ updatedAt: /* @__PURE__ */ new Date()
1612
+ });
1613
+ return this.getById(technologyId);
1614
+ }
1615
+ /**
1616
+ * Updates an existing benefit in a technology's list.
1617
+ * If the benefit does not exist, it will not be added.
1618
+ * @param technologyId - ID of the technology
1619
+ * @param benefit - The updated benefit object
1620
+ * @returns The updated technology
1621
+ */
1622
+ async updateBenefit(technologyId, benefit) {
1623
+ const docRef = doc9(this.getTechnologiesRef(), technologyId);
1624
+ const technology = await this.getById(technologyId);
1625
+ if (!technology) {
1626
+ throw new Error(`Technology with id ${technologyId} not found`);
1627
+ }
1628
+ const benefits = technology.benefits || [];
1629
+ const index = benefits.findIndex((b) => b.id === benefit.id);
1630
+ if (index === -1) {
1631
+ console.warn(
1632
+ `Benefit with id ${benefit.id} not found for technology ${technologyId}. No update performed.`
1633
+ );
1634
+ return technology;
1635
+ }
1636
+ const updatedBenefits = [...benefits];
1637
+ updatedBenefits[index] = benefit;
1550
1638
  await updateDoc9(docRef, {
1551
- benefits: arrayRemove(benefit),
1639
+ benefits: updatedBenefits,
1552
1640
  updatedAt: /* @__PURE__ */ new Date()
1553
1641
  });
1554
1642
  return this.getById(technologyId);
@@ -1772,9 +1860,25 @@ var TreatmentBenefit = /* @__PURE__ */ ((TreatmentBenefit2) => {
1772
1860
 
1773
1861
  // src/backoffice/validations/schemas.ts
1774
1862
  import { z as z2 } from "zod";
1863
+ var contraindicationDynamicSchema = z2.object({
1864
+ id: z2.string().min(1, "Contraindication ID is required").regex(
1865
+ /^[a-z0-9_]+$/,
1866
+ "ID must be in snake_case (lowercase, numbers, and underscores only)"
1867
+ ),
1868
+ name: z2.string().min(1, "Contraindication name is required"),
1869
+ description: z2.string().optional()
1870
+ });
1871
+ var treatmentBenefitDynamicSchema = z2.object({
1872
+ id: z2.string().min(1, "Benefit ID is required").regex(
1873
+ /^[a-z0-9_]+$/,
1874
+ "ID must be in snake_case (lowercase, numbers, and underscores only)"
1875
+ ),
1876
+ name: z2.string().min(1, "Benefit name is required"),
1877
+ description: z2.string().optional()
1878
+ });
1775
1879
  var blockingConditionSchemaBackoffice = z2.nativeEnum(BlockingCondition);
1776
- var contraindicationSchemaBackoffice = z2.nativeEnum(Contraindication);
1777
- var treatmentBenefitSchemaBackoffice = z2.nativeEnum(TreatmentBenefit);
1880
+ var contraindicationSchemaBackoffice = contraindicationDynamicSchema;
1881
+ var treatmentBenefitSchemaBackoffice = treatmentBenefitDynamicSchema;
1778
1882
  var procedureFamilySchemaBackoffice = z2.nativeEnum(ProcedureFamily);
1779
1883
  var timeUnitSchemaBackoffice = z2.nativeEnum(TimeUnit);
1780
1884
  var requirementTypeSchema = z2.nativeEnum(RequirementType);
@@ -2043,6 +2147,7 @@ export {
2043
2147
  certificationLevelSchema,
2044
2148
  certificationRequirementSchema,
2045
2149
  certificationSpecialtySchema,
2150
+ contraindicationDynamicSchema,
2046
2151
  contraindicationSchemaBackoffice,
2047
2152
  createDocumentTemplateSchema,
2048
2153
  documentElementSchema,
@@ -2059,6 +2164,7 @@ export {
2059
2164
  technologyUpdateSchema,
2060
2165
  timeUnitSchemaBackoffice,
2061
2166
  timeframeSchema,
2167
+ treatmentBenefitDynamicSchema,
2062
2168
  treatmentBenefitSchemaBackoffice,
2063
2169
  updateDocumentTemplateSchema
2064
2170
  };