@blackcode_sa/metaestetics-api 1.7.28 → 1.7.29
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/package.json
CHANGED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import * as admin from "firebase-admin";
|
|
2
|
+
import { ProcedureFamily } from "../../backoffice/types/static/procedure-family.types";
|
|
3
|
+
import {
|
|
4
|
+
CertificationLevel,
|
|
5
|
+
CertificationSpecialty,
|
|
6
|
+
} from "../../backoffice/types/static/certification.types";
|
|
7
|
+
import { CATEGORIES_COLLECTION } from "../../backoffice/types/category.types";
|
|
8
|
+
import { SUBCATEGORIES_COLLECTION } from "../../backoffice/types/subcategory.types";
|
|
9
|
+
import { TECHNOLOGIES_COLLECTION } from "../../backoffice/types/technology.types";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Ensures that the free consultation infrastructure exists in the database
|
|
13
|
+
* Creates category, subcategory, and technology if they don't exist
|
|
14
|
+
* @param db - Firestore database instance (optional, defaults to admin.firestore())
|
|
15
|
+
* @returns Promise<boolean> - Always returns true after ensuring infrastructure exists
|
|
16
|
+
*/
|
|
17
|
+
export async function freeConsultationInfrastructure(
|
|
18
|
+
db?: admin.firestore.Firestore
|
|
19
|
+
): Promise<boolean> {
|
|
20
|
+
const firestore = db || admin.firestore();
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
console.log(
|
|
24
|
+
"[freeConsultationInfrastructure] Checking free consultation infrastructure..."
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
// Check if the technology already exists
|
|
28
|
+
const technologyRef = firestore
|
|
29
|
+
.collection(TECHNOLOGIES_COLLECTION)
|
|
30
|
+
.doc("free-consultation-tech");
|
|
31
|
+
|
|
32
|
+
const technologyDoc = await technologyRef.get();
|
|
33
|
+
|
|
34
|
+
if (technologyDoc.exists) {
|
|
35
|
+
console.log(
|
|
36
|
+
"[freeConsultationInfrastructure] Free consultation infrastructure already exists"
|
|
37
|
+
);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
console.log(
|
|
42
|
+
"[freeConsultationInfrastructure] Creating free consultation infrastructure..."
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
// Create the infrastructure in the correct order: Category → Subcategory → Technology
|
|
46
|
+
await createFreeConsultationInfrastructure(firestore);
|
|
47
|
+
|
|
48
|
+
console.log(
|
|
49
|
+
"[freeConsultationInfrastructure] Successfully created free consultation infrastructure"
|
|
50
|
+
);
|
|
51
|
+
return true;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error(
|
|
54
|
+
"[freeConsultationInfrastructure] Error ensuring infrastructure:",
|
|
55
|
+
error
|
|
56
|
+
);
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Creates the complete free consultation infrastructure
|
|
63
|
+
* @param db - Firestore database instance
|
|
64
|
+
*/
|
|
65
|
+
async function createFreeConsultationInfrastructure(
|
|
66
|
+
db: admin.firestore.Firestore
|
|
67
|
+
): Promise<void> {
|
|
68
|
+
const batch = db.batch();
|
|
69
|
+
const now = new Date();
|
|
70
|
+
|
|
71
|
+
// 1. Create Category: "consultation"
|
|
72
|
+
const categoryRef = db.collection(CATEGORIES_COLLECTION).doc("consultation");
|
|
73
|
+
const categoryData = {
|
|
74
|
+
id: "consultation",
|
|
75
|
+
name: "Consultation",
|
|
76
|
+
description:
|
|
77
|
+
"Professional consultation services for treatment planning and assessment",
|
|
78
|
+
family: ProcedureFamily.AESTHETICS,
|
|
79
|
+
isActive: true,
|
|
80
|
+
createdAt: now,
|
|
81
|
+
updatedAt: now,
|
|
82
|
+
};
|
|
83
|
+
batch.set(categoryRef, categoryData);
|
|
84
|
+
|
|
85
|
+
// 2. Create Subcategory: "free-consultation"
|
|
86
|
+
const subcategoryRef = db
|
|
87
|
+
.collection(CATEGORIES_COLLECTION)
|
|
88
|
+
.doc("consultation")
|
|
89
|
+
.collection(SUBCATEGORIES_COLLECTION)
|
|
90
|
+
.doc("free-consultation");
|
|
91
|
+
|
|
92
|
+
const subcategoryData = {
|
|
93
|
+
id: "free-consultation",
|
|
94
|
+
name: "Free Consultation",
|
|
95
|
+
description:
|
|
96
|
+
"Complimentary initial consultation to discuss treatment options and assess patient needs",
|
|
97
|
+
categoryId: "consultation",
|
|
98
|
+
isActive: true,
|
|
99
|
+
createdAt: now,
|
|
100
|
+
updatedAt: now,
|
|
101
|
+
};
|
|
102
|
+
batch.set(subcategoryRef, subcategoryData);
|
|
103
|
+
|
|
104
|
+
// 3. Create Technology: "free-consultation-tech"
|
|
105
|
+
const technologyRef = db
|
|
106
|
+
.collection(TECHNOLOGIES_COLLECTION)
|
|
107
|
+
.doc("free-consultation-tech");
|
|
108
|
+
const technologyData = {
|
|
109
|
+
id: "free-consultation-tech",
|
|
110
|
+
name: "Free Consultation Technology",
|
|
111
|
+
description:
|
|
112
|
+
"Technology framework for providing free initial consultations to patients",
|
|
113
|
+
family: ProcedureFamily.AESTHETICS,
|
|
114
|
+
categoryId: "consultation",
|
|
115
|
+
subcategoryId: "free-consultation",
|
|
116
|
+
technicalDetails:
|
|
117
|
+
"Standard consultation protocol for initial patient assessment",
|
|
118
|
+
requirements: {
|
|
119
|
+
pre: [], // No pre-requirements for consultation
|
|
120
|
+
post: [], // No post-requirements for consultation
|
|
121
|
+
},
|
|
122
|
+
blockingConditions: [], // No blocking conditions for consultation
|
|
123
|
+
contraindications: [], // No contraindications for consultation
|
|
124
|
+
benefits: [
|
|
125
|
+
"IMPROVED_PATIENT_UNDERSTANDING",
|
|
126
|
+
"BETTER_TREATMENT_PLANNING",
|
|
127
|
+
"ENHANCED_PATIENT_CONFIDENCE",
|
|
128
|
+
],
|
|
129
|
+
certificationRequirement: {
|
|
130
|
+
minimumLevel: CertificationLevel.AESTHETICIAN,
|
|
131
|
+
requiredSpecialties: [], // No required specialties for consultation
|
|
132
|
+
},
|
|
133
|
+
documentationTemplates: [],
|
|
134
|
+
isActive: true,
|
|
135
|
+
createdAt: now,
|
|
136
|
+
updatedAt: now,
|
|
137
|
+
};
|
|
138
|
+
batch.set(technologyRef, technologyData);
|
|
139
|
+
|
|
140
|
+
// Commit all changes atomically
|
|
141
|
+
await batch.commit();
|
|
142
|
+
|
|
143
|
+
console.log("[freeConsultationInfrastructure] Successfully created:");
|
|
144
|
+
console.log(" ✓ Category: consultation");
|
|
145
|
+
console.log(" ✓ Subcategory: free-consultation");
|
|
146
|
+
console.log(" ✓ Technology: free-consultation-tech");
|
|
147
|
+
}
|