@blackcode_sa/metaestetics-api 1.14.49 → 1.14.51

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,17 @@ 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
+ await (0, import_firestore9.updateDoc)(docRef, { id: filledDocumentId });
5023
+ if (isUserForm && isRequired) {
5024
+ pendingUserFormsIds.push(filledDocumentId);
5025
+ }
5028
5026
  allLinkedFormIds.push(filledDocumentId);
5029
5027
  const linkedForm = {
5030
5028
  formId: filledDocumentId,
5031
5029
  templateId: template.id,
5032
5030
  templateVersion: template.version,
5033
5031
  title: template.title,
5034
- isUserForm: false,
5035
- // Always false for extended procedures
5032
+ isUserForm,
5036
5033
  isRequired,
5037
5034
  sortingOrder: templateRef.sortingOrder,
5038
5035
  status: "pending" /* PENDING */,
@@ -5040,7 +5037,7 @@ async function initializeFormsForExtendedProcedure(db, appointmentId, procedureI
5040
5037
  };
5041
5038
  initializedFormsInfo.push(linkedForm);
5042
5039
  console.log(
5043
- `[FormInit] Created FilledDocument ${filledDocumentId} (template: ${template.id}) for extended procedure ${procedureId} in appointment ${appointmentId}.`
5040
+ `[FormInit] Created FilledDocument ${filledDocumentId} (template: ${template.id}, isUserForm: ${isUserForm}) for extended procedure ${procedureId} in appointment ${appointmentId}.`
5044
5041
  );
5045
5042
  } catch (error) {
5046
5043
  console.error(
@@ -5074,6 +5071,26 @@ async function removeFormsForExtendedProcedure(db, appointmentId, procedureId) {
5074
5071
  );
5075
5072
  }
5076
5073
  }
5074
+ const userFormsRef = (0, import_firestore9.collection)(appointmentRef, USER_FORMS_SUBCOLLECTION);
5075
+ const userFormsQuery = (0, import_firestore9.query)(
5076
+ userFormsRef,
5077
+ (0, import_firestore9.where)("procedureId", "==", procedureId)
5078
+ );
5079
+ const userFormsSnap = await (0, import_firestore9.getDocs)(userFormsQuery);
5080
+ for (const formDoc of userFormsSnap.docs) {
5081
+ try {
5082
+ await (0, import_firestore9.deleteDoc)(formDoc.ref);
5083
+ removedFormIds.push(formDoc.id);
5084
+ console.log(
5085
+ `[FormInit] Removed user form ${formDoc.id} for extended procedure ${procedureId} from appointment ${appointmentId}.`
5086
+ );
5087
+ } catch (error) {
5088
+ console.error(
5089
+ `[FormInit] Error removing user form ${formDoc.id}:`,
5090
+ error
5091
+ );
5092
+ }
5093
+ }
5077
5094
  return removedFormIds;
5078
5095
  }
5079
5096
 
@@ -20455,7 +20472,11 @@ var FilledDocumentService = class extends BaseService {
20455
20472
  if (!docSnap.exists()) {
20456
20473
  return null;
20457
20474
  }
20458
- return docSnap.data();
20475
+ const data = docSnap.data();
20476
+ if (!data.id) {
20477
+ data.id = docSnap.id;
20478
+ }
20479
+ return data;
20459
20480
  }
20460
20481
  /**
20461
20482
  * Update values or status in a filled document within an appointment's subcollection.
@@ -20556,9 +20577,13 @@ var FilledDocumentService = class extends BaseService {
20556
20577
  const querySnapshot = await (0, import_firestore55.getDocs)(q);
20557
20578
  const documents = [];
20558
20579
  let lastVisible = null;
20559
- querySnapshot.forEach((doc47) => {
20560
- documents.push(doc47.data());
20561
- lastVisible = doc47;
20580
+ querySnapshot.forEach((docSnapshot) => {
20581
+ const data = docSnapshot.data();
20582
+ if (!data.id) {
20583
+ data.id = docSnapshot.id;
20584
+ }
20585
+ documents.push(data);
20586
+ lastVisible = docSnapshot;
20562
20587
  });
20563
20588
  return {
20564
20589
  documents,