@blackcode_sa/metaestetics-api 1.14.49 → 1.14.50

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/dist/index.js CHANGED
@@ -4996,21 +4996,15 @@ async function initializeFormsForExtendedProcedure(db, appointmentId, procedureI
4996
4996
  );
4997
4997
  continue;
4998
4998
  }
4999
- if (templateRef.isUserForm) {
5000
- console.log(
5001
- `[FormInit] Skipping user form ${templateRef.templateId} for extended procedure ${procedureId}.`
5002
- );
5003
- continue;
5004
- }
5005
4999
  const isRequired = templateRef.isRequired;
5006
- const formSubcollectionPath = DOCTOR_FORMS_SUBCOLLECTION;
5000
+ const isUserForm = templateRef.isUserForm || false;
5001
+ const formSubcollectionPath = isUserForm ? USER_FORMS_SUBCOLLECTION : DOCTOR_FORMS_SUBCOLLECTION;
5007
5002
  const appointmentRef = (0, import_firestore9.doc)(db, APPOINTMENTS_COLLECTION, appointmentId);
5008
5003
  const formsCollectionRef = (0, import_firestore9.collection)(appointmentRef, formSubcollectionPath);
5009
5004
  const filledDocumentData = {
5010
5005
  templateId: templateRef.templateId,
5011
5006
  templateVersion: template.version,
5012
- isUserForm: false,
5013
- // Always false for extended procedures
5007
+ isUserForm,
5014
5008
  isRequired,
5015
5009
  appointmentId,
5016
5010
  procedureId,
@@ -5025,14 +5019,16 @@ async function initializeFormsForExtendedProcedure(db, appointmentId, procedureI
5025
5019
  try {
5026
5020
  const docRef = await (0, import_firestore9.addDoc)(formsCollectionRef, filledDocumentData);
5027
5021
  const filledDocumentId = docRef.id;
5022
+ if (isUserForm && isRequired) {
5023
+ pendingUserFormsIds.push(filledDocumentId);
5024
+ }
5028
5025
  allLinkedFormIds.push(filledDocumentId);
5029
5026
  const linkedForm = {
5030
5027
  formId: filledDocumentId,
5031
5028
  templateId: template.id,
5032
5029
  templateVersion: template.version,
5033
5030
  title: template.title,
5034
- isUserForm: false,
5035
- // Always false for extended procedures
5031
+ isUserForm,
5036
5032
  isRequired,
5037
5033
  sortingOrder: templateRef.sortingOrder,
5038
5034
  status: "pending" /* PENDING */,
@@ -5040,7 +5036,7 @@ async function initializeFormsForExtendedProcedure(db, appointmentId, procedureI
5040
5036
  };
5041
5037
  initializedFormsInfo.push(linkedForm);
5042
5038
  console.log(
5043
- `[FormInit] Created FilledDocument ${filledDocumentId} (template: ${template.id}) for extended procedure ${procedureId} in appointment ${appointmentId}.`
5039
+ `[FormInit] Created FilledDocument ${filledDocumentId} (template: ${template.id}, isUserForm: ${isUserForm}) for extended procedure ${procedureId} in appointment ${appointmentId}.`
5044
5040
  );
5045
5041
  } catch (error) {
5046
5042
  console.error(
@@ -5074,6 +5070,26 @@ async function removeFormsForExtendedProcedure(db, appointmentId, procedureId) {
5074
5070
  );
5075
5071
  }
5076
5072
  }
5073
+ const userFormsRef = (0, import_firestore9.collection)(appointmentRef, USER_FORMS_SUBCOLLECTION);
5074
+ const userFormsQuery = (0, import_firestore9.query)(
5075
+ userFormsRef,
5076
+ (0, import_firestore9.where)("procedureId", "==", procedureId)
5077
+ );
5078
+ const userFormsSnap = await (0, import_firestore9.getDocs)(userFormsQuery);
5079
+ for (const formDoc of userFormsSnap.docs) {
5080
+ try {
5081
+ await (0, import_firestore9.deleteDoc)(formDoc.ref);
5082
+ removedFormIds.push(formDoc.id);
5083
+ console.log(
5084
+ `[FormInit] Removed user form ${formDoc.id} for extended procedure ${procedureId} from appointment ${appointmentId}.`
5085
+ );
5086
+ } catch (error) {
5087
+ console.error(
5088
+ `[FormInit] Error removing user form ${formDoc.id}:`,
5089
+ error
5090
+ );
5091
+ }
5092
+ }
5077
5093
  return removedFormIds;
5078
5094
  }
5079
5095
 
package/dist/index.mjs CHANGED
@@ -4882,21 +4882,15 @@ async function initializeFormsForExtendedProcedure(db, appointmentId, procedureI
4882
4882
  );
4883
4883
  continue;
4884
4884
  }
4885
- if (templateRef.isUserForm) {
4886
- console.log(
4887
- `[FormInit] Skipping user form ${templateRef.templateId} for extended procedure ${procedureId}.`
4888
- );
4889
- continue;
4890
- }
4891
4885
  const isRequired = templateRef.isRequired;
4892
- const formSubcollectionPath = DOCTOR_FORMS_SUBCOLLECTION;
4886
+ const isUserForm = templateRef.isUserForm || false;
4887
+ const formSubcollectionPath = isUserForm ? USER_FORMS_SUBCOLLECTION : DOCTOR_FORMS_SUBCOLLECTION;
4893
4888
  const appointmentRef = doc6(db, APPOINTMENTS_COLLECTION, appointmentId);
4894
4889
  const formsCollectionRef = collection5(appointmentRef, formSubcollectionPath);
4895
4890
  const filledDocumentData = {
4896
4891
  templateId: templateRef.templateId,
4897
4892
  templateVersion: template.version,
4898
- isUserForm: false,
4899
- // Always false for extended procedures
4893
+ isUserForm,
4900
4894
  isRequired,
4901
4895
  appointmentId,
4902
4896
  procedureId,
@@ -4911,14 +4905,16 @@ async function initializeFormsForExtendedProcedure(db, appointmentId, procedureI
4911
4905
  try {
4912
4906
  const docRef = await addDoc(formsCollectionRef, filledDocumentData);
4913
4907
  const filledDocumentId = docRef.id;
4908
+ if (isUserForm && isRequired) {
4909
+ pendingUserFormsIds.push(filledDocumentId);
4910
+ }
4914
4911
  allLinkedFormIds.push(filledDocumentId);
4915
4912
  const linkedForm = {
4916
4913
  formId: filledDocumentId,
4917
4914
  templateId: template.id,
4918
4915
  templateVersion: template.version,
4919
4916
  title: template.title,
4920
- isUserForm: false,
4921
- // Always false for extended procedures
4917
+ isUserForm,
4922
4918
  isRequired,
4923
4919
  sortingOrder: templateRef.sortingOrder,
4924
4920
  status: "pending" /* PENDING */,
@@ -4926,7 +4922,7 @@ async function initializeFormsForExtendedProcedure(db, appointmentId, procedureI
4926
4922
  };
4927
4923
  initializedFormsInfo.push(linkedForm);
4928
4924
  console.log(
4929
- `[FormInit] Created FilledDocument ${filledDocumentId} (template: ${template.id}) for extended procedure ${procedureId} in appointment ${appointmentId}.`
4925
+ `[FormInit] Created FilledDocument ${filledDocumentId} (template: ${template.id}, isUserForm: ${isUserForm}) for extended procedure ${procedureId} in appointment ${appointmentId}.`
4930
4926
  );
4931
4927
  } catch (error) {
4932
4928
  console.error(
@@ -4960,6 +4956,26 @@ async function removeFormsForExtendedProcedure(db, appointmentId, procedureId) {
4960
4956
  );
4961
4957
  }
4962
4958
  }
4959
+ const userFormsRef = collection5(appointmentRef, USER_FORMS_SUBCOLLECTION);
4960
+ const userFormsQuery = query5(
4961
+ userFormsRef,
4962
+ where5("procedureId", "==", procedureId)
4963
+ );
4964
+ const userFormsSnap = await getDocs5(userFormsQuery);
4965
+ for (const formDoc of userFormsSnap.docs) {
4966
+ try {
4967
+ await deleteDoc2(formDoc.ref);
4968
+ removedFormIds.push(formDoc.id);
4969
+ console.log(
4970
+ `[FormInit] Removed user form ${formDoc.id} for extended procedure ${procedureId} from appointment ${appointmentId}.`
4971
+ );
4972
+ } catch (error) {
4973
+ console.error(
4974
+ `[FormInit] Error removing user form ${formDoc.id}:`,
4975
+ error
4976
+ );
4977
+ }
4978
+ }
4963
4979
  return removedFormIds;
4964
4980
  }
4965
4981
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.14.49",
4
+ "version": "1.14.50",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -3,6 +3,7 @@ import {
3
3
  DocumentTemplate,
4
4
  FilledDocumentStatus,
5
5
  DOCTOR_FORMS_SUBCOLLECTION,
6
+ USER_FORMS_SUBCOLLECTION,
6
7
  DOCUMENTATION_TEMPLATES_COLLECTION,
7
8
  } from '../../../types/documentation-templates';
8
9
  import {
@@ -77,7 +78,7 @@ export async function initializeFormsForExtendedProcedure(
77
78
  }
78
79
  }
79
80
 
80
- // Initialize forms for each template (only doctor forms for extended procedures)
81
+ // Initialize forms for each template (both user forms and doctor forms for extended procedures)
81
82
  for (const templateRef of technologyTemplates) {
82
83
  const template = templatesMap.get(templateRef.templateId);
83
84
  if (!template) {
@@ -87,16 +88,11 @@ export async function initializeFormsForExtendedProcedure(
87
88
  continue;
88
89
  }
89
90
 
90
- // Skip user forms - only create doctor forms for extended procedures
91
- if (templateRef.isUserForm) {
92
- console.log(
93
- `[FormInit] Skipping user form ${templateRef.templateId} for extended procedure ${procedureId}.`
94
- );
95
- continue;
96
- }
97
-
98
91
  const isRequired = templateRef.isRequired;
99
- const formSubcollectionPath = DOCTOR_FORMS_SUBCOLLECTION;
92
+ const isUserForm = templateRef.isUserForm || false;
93
+ const formSubcollectionPath = isUserForm
94
+ ? USER_FORMS_SUBCOLLECTION
95
+ : DOCTOR_FORMS_SUBCOLLECTION;
100
96
 
101
97
  // Create form document in subcollection
102
98
  const appointmentRef = doc(db, APPOINTMENTS_COLLECTION, appointmentId);
@@ -105,7 +101,7 @@ export async function initializeFormsForExtendedProcedure(
105
101
  const filledDocumentData = {
106
102
  templateId: templateRef.templateId,
107
103
  templateVersion: template.version,
108
- isUserForm: false, // Always false for extended procedures
104
+ isUserForm: isUserForm,
109
105
  isRequired: isRequired,
110
106
  appointmentId: appointmentId,
111
107
  procedureId: procedureId,
@@ -122,7 +118,10 @@ export async function initializeFormsForExtendedProcedure(
122
118
  const docRef = await addDoc(formsCollectionRef, filledDocumentData);
123
119
  const filledDocumentId = docRef.id;
124
120
 
125
- // No user forms for extended procedures, so no pending user forms
121
+ // Add to pendingUserFormsIds if it's a required user form
122
+ if (isUserForm && isRequired) {
123
+ pendingUserFormsIds.push(filledDocumentId);
124
+ }
126
125
 
127
126
  allLinkedFormIds.push(filledDocumentId);
128
127
 
@@ -131,7 +130,7 @@ export async function initializeFormsForExtendedProcedure(
131
130
  templateId: template.id,
132
131
  templateVersion: template.version,
133
132
  title: template.title,
134
- isUserForm: false, // Always false for extended procedures
133
+ isUserForm: isUserForm,
135
134
  isRequired: isRequired,
136
135
  sortingOrder: templateRef.sortingOrder,
137
136
  status: FilledDocumentStatus.PENDING,
@@ -140,7 +139,7 @@ export async function initializeFormsForExtendedProcedure(
140
139
  initializedFormsInfo.push(linkedForm);
141
140
 
142
141
  console.log(
143
- `[FormInit] Created FilledDocument ${filledDocumentId} (template: ${template.id}) for extended procedure ${procedureId} in appointment ${appointmentId}.`
142
+ `[FormInit] Created FilledDocument ${filledDocumentId} (template: ${template.id}, isUserForm: ${isUserForm}) for extended procedure ${procedureId} in appointment ${appointmentId}.`
144
143
  );
145
144
  } catch (error) {
146
145
  console.error(
@@ -155,6 +154,7 @@ export async function initializeFormsForExtendedProcedure(
155
154
 
156
155
  /**
157
156
  * Removes all forms associated with a specific procedure from an appointment
157
+ * Removes both user forms and doctor forms
158
158
  * @param db Firestore instance
159
159
  * @param appointmentId Appointment ID
160
160
  * @param procedureId Procedure ID to remove forms for
@@ -167,11 +167,10 @@ export async function removeFormsForExtendedProcedure(
167
167
  ): Promise<string[]> {
168
168
  const removedFormIds: string[] = [];
169
169
 
170
- // Only remove from doctor forms subcollection (no user forms for extended procedures)
171
170
  const appointmentRef = doc(db, APPOINTMENTS_COLLECTION, appointmentId);
172
- const doctorFormsRef = collection(appointmentRef, DOCTOR_FORMS_SUBCOLLECTION);
173
171
 
174
- // Query doctor forms for this procedure
172
+ // Remove from doctor forms subcollection
173
+ const doctorFormsRef = collection(appointmentRef, DOCTOR_FORMS_SUBCOLLECTION);
175
174
  const doctorFormsQuery = query(
176
175
  doctorFormsRef,
177
176
  where('procedureId', '==', procedureId)
@@ -193,6 +192,29 @@ export async function removeFormsForExtendedProcedure(
193
192
  }
194
193
  }
195
194
 
195
+ // Remove from user forms subcollection
196
+ const userFormsRef = collection(appointmentRef, USER_FORMS_SUBCOLLECTION);
197
+ const userFormsQuery = query(
198
+ userFormsRef,
199
+ where('procedureId', '==', procedureId)
200
+ );
201
+ const userFormsSnap = await getDocs(userFormsQuery);
202
+
203
+ for (const formDoc of userFormsSnap.docs) {
204
+ try {
205
+ await deleteDoc(formDoc.ref);
206
+ removedFormIds.push(formDoc.id);
207
+ console.log(
208
+ `[FormInit] Removed user form ${formDoc.id} for extended procedure ${procedureId} from appointment ${appointmentId}.`
209
+ );
210
+ } catch (error) {
211
+ console.error(
212
+ `[FormInit] Error removing user form ${formDoc.id}:`,
213
+ error
214
+ );
215
+ }
216
+ }
217
+
196
218
  return removedFormIds;
197
219
  }
198
220
 
@@ -211,9 +233,9 @@ export async function getFormsForExtendedProcedure(
211
233
  const formIds: string[] = [];
212
234
 
213
235
  const appointmentRef = doc(db, APPOINTMENTS_COLLECTION, appointmentId);
214
- const doctorFormsRef = collection(appointmentRef, DOCTOR_FORMS_SUBCOLLECTION);
215
236
 
216
237
  // Query doctor forms for this procedure
238
+ const doctorFormsRef = collection(appointmentRef, DOCTOR_FORMS_SUBCOLLECTION);
217
239
  const doctorFormsQuery = query(
218
240
  doctorFormsRef,
219
241
  where('procedureId', '==', procedureId)
@@ -221,5 +243,14 @@ export async function getFormsForExtendedProcedure(
221
243
  const doctorFormsSnap = await getDocs(doctorFormsQuery);
222
244
  doctorFormsSnap.docs.forEach(doc => formIds.push(doc.id));
223
245
 
246
+ // Query user forms for this procedure
247
+ const userFormsRef = collection(appointmentRef, USER_FORMS_SUBCOLLECTION);
248
+ const userFormsQuery = query(
249
+ userFormsRef,
250
+ where('procedureId', '==', procedureId)
251
+ );
252
+ const userFormsSnap = await getDocs(userFormsQuery);
253
+ userFormsSnap.docs.forEach(doc => formIds.push(doc.id));
254
+
224
255
  return formIds;
225
256
  }