@blackcode_sa/metaestetics-api 1.7.27 → 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/dist/admin/index.d.mts +13 -1
- package/dist/admin/index.d.ts +13 -1
- package/dist/admin/index.js +137 -6
- package/dist/admin/index.mjs +137 -6
- package/dist/backoffice/index.d.mts +1 -0
- package/dist/backoffice/index.d.ts +1 -0
- package/dist/index.d.mts +182 -145
- package/dist/index.d.ts +182 -145
- package/dist/index.js +235 -1
- package/dist/index.mjs +235 -1
- package/package.json +1 -1
- package/src/admin/aggregation/procedure/procedure.aggregation.service.ts +202 -8
- package/src/admin/free-consultation/free-consultation-utils.admin.ts +147 -0
- package/src/services/practitioner/practitioner.service.ts +178 -1
- package/src/services/procedure/procedure.service.ts +141 -0
- package/src/types/practitioner/index.ts +3 -0
- package/src/validations/practitioner.schema.ts +3 -0
package/dist/admin/index.d.mts
CHANGED
|
@@ -858,6 +858,7 @@ interface Practitioner {
|
|
|
858
858
|
clinicWorkingHours: PractitionerClinicWorkingHours[];
|
|
859
859
|
clinicsInfo: ClinicInfo[];
|
|
860
860
|
procedures: string[];
|
|
861
|
+
freeConsultations?: Record<string, string> | null;
|
|
861
862
|
proceduresInfo: ProcedureSummaryInfo[];
|
|
862
863
|
reviewInfo: PractitionerReviewInfo;
|
|
863
864
|
isActive: boolean;
|
|
@@ -1970,9 +1971,10 @@ declare class ProcedureAggregationService {
|
|
|
1970
1971
|
* Removes procedure from a practitioner when a procedure is deleted or inactivated
|
|
1971
1972
|
* @param practitionerId - ID of the practitioner who performs the procedure
|
|
1972
1973
|
* @param procedureId - ID of the procedure
|
|
1974
|
+
* @param clinicId - Optional clinic ID for free consultation removal
|
|
1973
1975
|
* @returns {Promise<void>}
|
|
1974
1976
|
*/
|
|
1975
|
-
removeProcedureFromPractitioner(practitionerId: string, procedureId: string): Promise<void>;
|
|
1977
|
+
removeProcedureFromPractitioner(practitionerId: string, procedureId: string, clinicId?: string): Promise<void>;
|
|
1976
1978
|
/**
|
|
1977
1979
|
* Removes procedure from a clinic when a procedure is deleted or inactivated
|
|
1978
1980
|
* @param clinicId - ID of the clinic where the procedure is performed
|
|
@@ -1980,6 +1982,16 @@ declare class ProcedureAggregationService {
|
|
|
1980
1982
|
* @returns {Promise<void>}
|
|
1981
1983
|
*/
|
|
1982
1984
|
removeProcedureFromClinic(clinicId: string, procedureId: string): Promise<void>;
|
|
1985
|
+
/**
|
|
1986
|
+
* Handles procedure status changes (activation/deactivation) specifically for free consultations
|
|
1987
|
+
* @param practitionerId - ID of the practitioner who performs the procedure
|
|
1988
|
+
* @param procedureId - ID of the procedure
|
|
1989
|
+
* @param clinicId - ID of the clinic where the procedure is performed
|
|
1990
|
+
* @param isActive - New active status of the procedure
|
|
1991
|
+
* @param technologyName - Technology name of the procedure (to check if it's a free consultation)
|
|
1992
|
+
* @returns {Promise<void>}
|
|
1993
|
+
*/
|
|
1994
|
+
handleFreeConsultationStatusChange(practitionerId: string, procedureId: string, clinicId: string, isActive: boolean, technologyName: string): Promise<void>;
|
|
1983
1995
|
}
|
|
1984
1996
|
|
|
1985
1997
|
/**
|
package/dist/admin/index.d.ts
CHANGED
|
@@ -858,6 +858,7 @@ interface Practitioner {
|
|
|
858
858
|
clinicWorkingHours: PractitionerClinicWorkingHours[];
|
|
859
859
|
clinicsInfo: ClinicInfo[];
|
|
860
860
|
procedures: string[];
|
|
861
|
+
freeConsultations?: Record<string, string> | null;
|
|
861
862
|
proceduresInfo: ProcedureSummaryInfo[];
|
|
862
863
|
reviewInfo: PractitionerReviewInfo;
|
|
863
864
|
isActive: boolean;
|
|
@@ -1970,9 +1971,10 @@ declare class ProcedureAggregationService {
|
|
|
1970
1971
|
* Removes procedure from a practitioner when a procedure is deleted or inactivated
|
|
1971
1972
|
* @param practitionerId - ID of the practitioner who performs the procedure
|
|
1972
1973
|
* @param procedureId - ID of the procedure
|
|
1974
|
+
* @param clinicId - Optional clinic ID for free consultation removal
|
|
1973
1975
|
* @returns {Promise<void>}
|
|
1974
1976
|
*/
|
|
1975
|
-
removeProcedureFromPractitioner(practitionerId: string, procedureId: string): Promise<void>;
|
|
1977
|
+
removeProcedureFromPractitioner(practitionerId: string, procedureId: string, clinicId?: string): Promise<void>;
|
|
1976
1978
|
/**
|
|
1977
1979
|
* Removes procedure from a clinic when a procedure is deleted or inactivated
|
|
1978
1980
|
* @param clinicId - ID of the clinic where the procedure is performed
|
|
@@ -1980,6 +1982,16 @@ declare class ProcedureAggregationService {
|
|
|
1980
1982
|
* @returns {Promise<void>}
|
|
1981
1983
|
*/
|
|
1982
1984
|
removeProcedureFromClinic(clinicId: string, procedureId: string): Promise<void>;
|
|
1985
|
+
/**
|
|
1986
|
+
* Handles procedure status changes (activation/deactivation) specifically for free consultations
|
|
1987
|
+
* @param practitionerId - ID of the practitioner who performs the procedure
|
|
1988
|
+
* @param procedureId - ID of the procedure
|
|
1989
|
+
* @param clinicId - ID of the clinic where the procedure is performed
|
|
1990
|
+
* @param isActive - New active status of the procedure
|
|
1991
|
+
* @param technologyName - Technology name of the procedure (to check if it's a free consultation)
|
|
1992
|
+
* @returns {Promise<void>}
|
|
1993
|
+
*/
|
|
1994
|
+
handleFreeConsultationStatusChange(practitionerId: string, procedureId: string, clinicId: string, isActive: boolean, technologyName: string): Promise<void>;
|
|
1983
1995
|
}
|
|
1984
1996
|
|
|
1985
1997
|
/**
|
package/dist/admin/index.js
CHANGED
|
@@ -1792,16 +1792,48 @@ var ProcedureAggregationService = class {
|
|
|
1792
1792
|
return;
|
|
1793
1793
|
}
|
|
1794
1794
|
const procedureId = procedureSummary.id;
|
|
1795
|
+
const clinicId = procedureSummary.clinicId;
|
|
1796
|
+
const isFreeConsultation = procedureSummary.technologyName === "free-consultation-tech";
|
|
1795
1797
|
console.log(
|
|
1796
|
-
`[ProcedureAggregationService] Adding procedure ${procedureId} to practitioner ${practitionerId}
|
|
1798
|
+
`[ProcedureAggregationService] Adding procedure ${procedureId} to practitioner ${practitionerId}. ${isFreeConsultation ? "(Free Consultation)" : ""}`
|
|
1797
1799
|
);
|
|
1798
1800
|
const practitionerRef = this.db.collection(PRACTITIONERS_COLLECTION).doc(practitionerId);
|
|
1799
1801
|
try {
|
|
1800
|
-
|
|
1802
|
+
const updateData = {
|
|
1801
1803
|
procedureIds: admin5.firestore.FieldValue.arrayUnion(procedureId),
|
|
1802
1804
|
proceduresInfo: admin5.firestore.FieldValue.arrayUnion(procedureSummary),
|
|
1803
1805
|
updatedAt: admin5.firestore.FieldValue.serverTimestamp()
|
|
1804
|
-
}
|
|
1806
|
+
};
|
|
1807
|
+
if (isFreeConsultation) {
|
|
1808
|
+
await this.db.runTransaction(async (transaction) => {
|
|
1809
|
+
const practitionerDoc = await transaction.get(practitionerRef);
|
|
1810
|
+
if (!practitionerDoc.exists) {
|
|
1811
|
+
throw new Error(
|
|
1812
|
+
`Practitioner ${practitionerId} does not exist for adding free consultation`
|
|
1813
|
+
);
|
|
1814
|
+
}
|
|
1815
|
+
const practitionerData = practitionerDoc.data();
|
|
1816
|
+
const currentFreeConsultations = (practitionerData == null ? void 0 : practitionerData.freeConsultations) || {};
|
|
1817
|
+
if (currentFreeConsultations[clinicId]) {
|
|
1818
|
+
console.log(
|
|
1819
|
+
`[ProcedureAggregationService] Warning: Clinic ${clinicId} already has a free consultation ${currentFreeConsultations[clinicId]}. Replacing with new one ${procedureId}.`
|
|
1820
|
+
);
|
|
1821
|
+
}
|
|
1822
|
+
const updatedFreeConsultations = {
|
|
1823
|
+
...currentFreeConsultations,
|
|
1824
|
+
[clinicId]: procedureId
|
|
1825
|
+
};
|
|
1826
|
+
transaction.update(practitionerRef, {
|
|
1827
|
+
...updateData,
|
|
1828
|
+
freeConsultations: updatedFreeConsultations
|
|
1829
|
+
});
|
|
1830
|
+
console.log(
|
|
1831
|
+
`[ProcedureAggregationService] Set free consultation ${procedureId} for practitioner ${practitionerId} at clinic ${clinicId}`
|
|
1832
|
+
);
|
|
1833
|
+
});
|
|
1834
|
+
} else {
|
|
1835
|
+
await practitionerRef.update(updateData);
|
|
1836
|
+
}
|
|
1805
1837
|
console.log(
|
|
1806
1838
|
`[ProcedureAggregationService] Successfully added procedure ${procedureId} to practitioner ${practitionerId}.`
|
|
1807
1839
|
);
|
|
@@ -2054,9 +2086,10 @@ var ProcedureAggregationService = class {
|
|
|
2054
2086
|
* Removes procedure from a practitioner when a procedure is deleted or inactivated
|
|
2055
2087
|
* @param practitionerId - ID of the practitioner who performs the procedure
|
|
2056
2088
|
* @param procedureId - ID of the procedure
|
|
2089
|
+
* @param clinicId - Optional clinic ID for free consultation removal
|
|
2057
2090
|
* @returns {Promise<void>}
|
|
2058
2091
|
*/
|
|
2059
|
-
async removeProcedureFromPractitioner(practitionerId, procedureId) {
|
|
2092
|
+
async removeProcedureFromPractitioner(practitionerId, procedureId, clinicId) {
|
|
2060
2093
|
if (!practitionerId || !procedureId) {
|
|
2061
2094
|
console.log(
|
|
2062
2095
|
"[ProcedureAggregationService] Missing practitionerId or procedureId for removing procedure from practitioner. Skipping."
|
|
@@ -2082,14 +2115,35 @@ var ProcedureAggregationService = class {
|
|
|
2082
2115
|
);
|
|
2083
2116
|
}
|
|
2084
2117
|
const proceduresInfo = practitionerData.proceduresInfo || [];
|
|
2118
|
+
const procedureBeingRemoved = proceduresInfo.find(
|
|
2119
|
+
(p) => p.id === procedureId
|
|
2120
|
+
);
|
|
2121
|
+
const isFreeConsultation = (procedureBeingRemoved == null ? void 0 : procedureBeingRemoved.technologyName) === "free-consultation-tech";
|
|
2122
|
+
const procedureClinicId = clinicId || (procedureBeingRemoved == null ? void 0 : procedureBeingRemoved.clinicId);
|
|
2085
2123
|
const updatedProceduresInfo = proceduresInfo.filter(
|
|
2086
2124
|
(p) => p.id !== procedureId
|
|
2087
2125
|
);
|
|
2088
|
-
|
|
2126
|
+
const updateData = {
|
|
2089
2127
|
procedureIds: admin5.firestore.FieldValue.arrayRemove(procedureId),
|
|
2090
2128
|
proceduresInfo: updatedProceduresInfo,
|
|
2091
2129
|
updatedAt: admin5.firestore.FieldValue.serverTimestamp()
|
|
2092
|
-
}
|
|
2130
|
+
};
|
|
2131
|
+
if (isFreeConsultation && procedureClinicId) {
|
|
2132
|
+
const currentFreeConsultations = practitionerData.freeConsultations || {};
|
|
2133
|
+
if (currentFreeConsultations[procedureClinicId] === procedureId) {
|
|
2134
|
+
const updatedFreeConsultations = { ...currentFreeConsultations };
|
|
2135
|
+
delete updatedFreeConsultations[procedureClinicId];
|
|
2136
|
+
updateData.freeConsultations = updatedFreeConsultations;
|
|
2137
|
+
console.log(
|
|
2138
|
+
`[ProcedureAggregationService] Removed free consultation ${procedureId} from practitioner ${practitionerId} for clinic ${procedureClinicId}`
|
|
2139
|
+
);
|
|
2140
|
+
} else {
|
|
2141
|
+
console.log(
|
|
2142
|
+
`[ProcedureAggregationService] Free consultation mismatch for clinic ${procedureClinicId}: expected ${procedureId}, found ${currentFreeConsultations[procedureClinicId]}`
|
|
2143
|
+
);
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
transaction.update(practitionerRef, updateData);
|
|
2093
2147
|
});
|
|
2094
2148
|
console.log(
|
|
2095
2149
|
`[ProcedureAggregationService] Successfully removed procedure ${procedureId} from practitioner ${practitionerId}.`
|
|
@@ -2154,6 +2208,83 @@ var ProcedureAggregationService = class {
|
|
|
2154
2208
|
throw error;
|
|
2155
2209
|
}
|
|
2156
2210
|
}
|
|
2211
|
+
/**
|
|
2212
|
+
* Handles procedure status changes (activation/deactivation) specifically for free consultations
|
|
2213
|
+
* @param practitionerId - ID of the practitioner who performs the procedure
|
|
2214
|
+
* @param procedureId - ID of the procedure
|
|
2215
|
+
* @param clinicId - ID of the clinic where the procedure is performed
|
|
2216
|
+
* @param isActive - New active status of the procedure
|
|
2217
|
+
* @param technologyName - Technology name of the procedure (to check if it's a free consultation)
|
|
2218
|
+
* @returns {Promise<void>}
|
|
2219
|
+
*/
|
|
2220
|
+
async handleFreeConsultationStatusChange(practitionerId, procedureId, clinicId, isActive, technologyName) {
|
|
2221
|
+
if (!practitionerId || !procedureId || !clinicId) {
|
|
2222
|
+
console.log(
|
|
2223
|
+
"[ProcedureAggregationService] Missing required parameters for handling free consultation status change. Skipping."
|
|
2224
|
+
);
|
|
2225
|
+
return;
|
|
2226
|
+
}
|
|
2227
|
+
if (technologyName !== "free-consultation-tech") {
|
|
2228
|
+
return;
|
|
2229
|
+
}
|
|
2230
|
+
console.log(
|
|
2231
|
+
`[ProcedureAggregationService] Handling free consultation status change: procedure ${procedureId} for practitioner ${practitionerId} in clinic ${clinicId}. New status: ${isActive ? "active" : "inactive"}`
|
|
2232
|
+
);
|
|
2233
|
+
const practitionerRef = this.db.collection(PRACTITIONERS_COLLECTION).doc(practitionerId);
|
|
2234
|
+
try {
|
|
2235
|
+
await this.db.runTransaction(async (transaction) => {
|
|
2236
|
+
const practitionerDoc = await transaction.get(practitionerRef);
|
|
2237
|
+
if (!practitionerDoc.exists) {
|
|
2238
|
+
throw new Error(
|
|
2239
|
+
`Practitioner ${practitionerId} does not exist for free consultation status change`
|
|
2240
|
+
);
|
|
2241
|
+
}
|
|
2242
|
+
const practitionerData = practitionerDoc.data();
|
|
2243
|
+
if (!practitionerData) {
|
|
2244
|
+
throw new Error(
|
|
2245
|
+
`Practitioner ${practitionerId} data is empty for free consultation status change`
|
|
2246
|
+
);
|
|
2247
|
+
}
|
|
2248
|
+
const currentFreeConsultations = practitionerData.freeConsultations || {};
|
|
2249
|
+
let updatedFreeConsultations = { ...currentFreeConsultations };
|
|
2250
|
+
if (isActive) {
|
|
2251
|
+
if (currentFreeConsultations[clinicId] && currentFreeConsultations[clinicId] !== procedureId) {
|
|
2252
|
+
console.log(
|
|
2253
|
+
`[ProcedureAggregationService] Warning: Clinic ${clinicId} already has a different free consultation ${currentFreeConsultations[clinicId]}. Replacing with ${procedureId}.`
|
|
2254
|
+
);
|
|
2255
|
+
}
|
|
2256
|
+
updatedFreeConsultations[clinicId] = procedureId;
|
|
2257
|
+
console.log(
|
|
2258
|
+
`[ProcedureAggregationService] Set free consultation ${procedureId} for practitioner ${practitionerId} at clinic ${clinicId} (activated)`
|
|
2259
|
+
);
|
|
2260
|
+
} else {
|
|
2261
|
+
if (currentFreeConsultations[clinicId] === procedureId) {
|
|
2262
|
+
delete updatedFreeConsultations[clinicId];
|
|
2263
|
+
console.log(
|
|
2264
|
+
`[ProcedureAggregationService] Removed free consultation ${procedureId} from practitioner ${practitionerId} for clinic ${clinicId} (deactivated)`
|
|
2265
|
+
);
|
|
2266
|
+
} else {
|
|
2267
|
+
console.log(
|
|
2268
|
+
`[ProcedureAggregationService] Free consultation mismatch for clinic ${clinicId}: expected ${procedureId}, found ${currentFreeConsultations[clinicId]}`
|
|
2269
|
+
);
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
transaction.update(practitionerRef, {
|
|
2273
|
+
freeConsultations: updatedFreeConsultations,
|
|
2274
|
+
updatedAt: admin5.firestore.FieldValue.serverTimestamp()
|
|
2275
|
+
});
|
|
2276
|
+
});
|
|
2277
|
+
console.log(
|
|
2278
|
+
`[ProcedureAggregationService] Successfully handled free consultation status change for procedure ${procedureId} of practitioner ${practitionerId}.`
|
|
2279
|
+
);
|
|
2280
|
+
} catch (error) {
|
|
2281
|
+
console.error(
|
|
2282
|
+
`[ProcedureAggregationService] Error handling free consultation status change for procedure ${procedureId} of practitioner ${practitionerId}:`,
|
|
2283
|
+
error
|
|
2284
|
+
);
|
|
2285
|
+
throw error;
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2157
2288
|
};
|
|
2158
2289
|
|
|
2159
2290
|
// src/admin/aggregation/patient/patient.aggregation.service.ts
|
package/dist/admin/index.mjs
CHANGED
|
@@ -1735,16 +1735,48 @@ var ProcedureAggregationService = class {
|
|
|
1735
1735
|
return;
|
|
1736
1736
|
}
|
|
1737
1737
|
const procedureId = procedureSummary.id;
|
|
1738
|
+
const clinicId = procedureSummary.clinicId;
|
|
1739
|
+
const isFreeConsultation = procedureSummary.technologyName === "free-consultation-tech";
|
|
1738
1740
|
console.log(
|
|
1739
|
-
`[ProcedureAggregationService] Adding procedure ${procedureId} to practitioner ${practitionerId}
|
|
1741
|
+
`[ProcedureAggregationService] Adding procedure ${procedureId} to practitioner ${practitionerId}. ${isFreeConsultation ? "(Free Consultation)" : ""}`
|
|
1740
1742
|
);
|
|
1741
1743
|
const practitionerRef = this.db.collection(PRACTITIONERS_COLLECTION).doc(practitionerId);
|
|
1742
1744
|
try {
|
|
1743
|
-
|
|
1745
|
+
const updateData = {
|
|
1744
1746
|
procedureIds: admin5.firestore.FieldValue.arrayUnion(procedureId),
|
|
1745
1747
|
proceduresInfo: admin5.firestore.FieldValue.arrayUnion(procedureSummary),
|
|
1746
1748
|
updatedAt: admin5.firestore.FieldValue.serverTimestamp()
|
|
1747
|
-
}
|
|
1749
|
+
};
|
|
1750
|
+
if (isFreeConsultation) {
|
|
1751
|
+
await this.db.runTransaction(async (transaction) => {
|
|
1752
|
+
const practitionerDoc = await transaction.get(practitionerRef);
|
|
1753
|
+
if (!practitionerDoc.exists) {
|
|
1754
|
+
throw new Error(
|
|
1755
|
+
`Practitioner ${practitionerId} does not exist for adding free consultation`
|
|
1756
|
+
);
|
|
1757
|
+
}
|
|
1758
|
+
const practitionerData = practitionerDoc.data();
|
|
1759
|
+
const currentFreeConsultations = (practitionerData == null ? void 0 : practitionerData.freeConsultations) || {};
|
|
1760
|
+
if (currentFreeConsultations[clinicId]) {
|
|
1761
|
+
console.log(
|
|
1762
|
+
`[ProcedureAggregationService] Warning: Clinic ${clinicId} already has a free consultation ${currentFreeConsultations[clinicId]}. Replacing with new one ${procedureId}.`
|
|
1763
|
+
);
|
|
1764
|
+
}
|
|
1765
|
+
const updatedFreeConsultations = {
|
|
1766
|
+
...currentFreeConsultations,
|
|
1767
|
+
[clinicId]: procedureId
|
|
1768
|
+
};
|
|
1769
|
+
transaction.update(practitionerRef, {
|
|
1770
|
+
...updateData,
|
|
1771
|
+
freeConsultations: updatedFreeConsultations
|
|
1772
|
+
});
|
|
1773
|
+
console.log(
|
|
1774
|
+
`[ProcedureAggregationService] Set free consultation ${procedureId} for practitioner ${practitionerId} at clinic ${clinicId}`
|
|
1775
|
+
);
|
|
1776
|
+
});
|
|
1777
|
+
} else {
|
|
1778
|
+
await practitionerRef.update(updateData);
|
|
1779
|
+
}
|
|
1748
1780
|
console.log(
|
|
1749
1781
|
`[ProcedureAggregationService] Successfully added procedure ${procedureId} to practitioner ${practitionerId}.`
|
|
1750
1782
|
);
|
|
@@ -1997,9 +2029,10 @@ var ProcedureAggregationService = class {
|
|
|
1997
2029
|
* Removes procedure from a practitioner when a procedure is deleted or inactivated
|
|
1998
2030
|
* @param practitionerId - ID of the practitioner who performs the procedure
|
|
1999
2031
|
* @param procedureId - ID of the procedure
|
|
2032
|
+
* @param clinicId - Optional clinic ID for free consultation removal
|
|
2000
2033
|
* @returns {Promise<void>}
|
|
2001
2034
|
*/
|
|
2002
|
-
async removeProcedureFromPractitioner(practitionerId, procedureId) {
|
|
2035
|
+
async removeProcedureFromPractitioner(practitionerId, procedureId, clinicId) {
|
|
2003
2036
|
if (!practitionerId || !procedureId) {
|
|
2004
2037
|
console.log(
|
|
2005
2038
|
"[ProcedureAggregationService] Missing practitionerId or procedureId for removing procedure from practitioner. Skipping."
|
|
@@ -2025,14 +2058,35 @@ var ProcedureAggregationService = class {
|
|
|
2025
2058
|
);
|
|
2026
2059
|
}
|
|
2027
2060
|
const proceduresInfo = practitionerData.proceduresInfo || [];
|
|
2061
|
+
const procedureBeingRemoved = proceduresInfo.find(
|
|
2062
|
+
(p) => p.id === procedureId
|
|
2063
|
+
);
|
|
2064
|
+
const isFreeConsultation = (procedureBeingRemoved == null ? void 0 : procedureBeingRemoved.technologyName) === "free-consultation-tech";
|
|
2065
|
+
const procedureClinicId = clinicId || (procedureBeingRemoved == null ? void 0 : procedureBeingRemoved.clinicId);
|
|
2028
2066
|
const updatedProceduresInfo = proceduresInfo.filter(
|
|
2029
2067
|
(p) => p.id !== procedureId
|
|
2030
2068
|
);
|
|
2031
|
-
|
|
2069
|
+
const updateData = {
|
|
2032
2070
|
procedureIds: admin5.firestore.FieldValue.arrayRemove(procedureId),
|
|
2033
2071
|
proceduresInfo: updatedProceduresInfo,
|
|
2034
2072
|
updatedAt: admin5.firestore.FieldValue.serverTimestamp()
|
|
2035
|
-
}
|
|
2073
|
+
};
|
|
2074
|
+
if (isFreeConsultation && procedureClinicId) {
|
|
2075
|
+
const currentFreeConsultations = practitionerData.freeConsultations || {};
|
|
2076
|
+
if (currentFreeConsultations[procedureClinicId] === procedureId) {
|
|
2077
|
+
const updatedFreeConsultations = { ...currentFreeConsultations };
|
|
2078
|
+
delete updatedFreeConsultations[procedureClinicId];
|
|
2079
|
+
updateData.freeConsultations = updatedFreeConsultations;
|
|
2080
|
+
console.log(
|
|
2081
|
+
`[ProcedureAggregationService] Removed free consultation ${procedureId} from practitioner ${practitionerId} for clinic ${procedureClinicId}`
|
|
2082
|
+
);
|
|
2083
|
+
} else {
|
|
2084
|
+
console.log(
|
|
2085
|
+
`[ProcedureAggregationService] Free consultation mismatch for clinic ${procedureClinicId}: expected ${procedureId}, found ${currentFreeConsultations[procedureClinicId]}`
|
|
2086
|
+
);
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
transaction.update(practitionerRef, updateData);
|
|
2036
2090
|
});
|
|
2037
2091
|
console.log(
|
|
2038
2092
|
`[ProcedureAggregationService] Successfully removed procedure ${procedureId} from practitioner ${practitionerId}.`
|
|
@@ -2097,6 +2151,83 @@ var ProcedureAggregationService = class {
|
|
|
2097
2151
|
throw error;
|
|
2098
2152
|
}
|
|
2099
2153
|
}
|
|
2154
|
+
/**
|
|
2155
|
+
* Handles procedure status changes (activation/deactivation) specifically for free consultations
|
|
2156
|
+
* @param practitionerId - ID of the practitioner who performs the procedure
|
|
2157
|
+
* @param procedureId - ID of the procedure
|
|
2158
|
+
* @param clinicId - ID of the clinic where the procedure is performed
|
|
2159
|
+
* @param isActive - New active status of the procedure
|
|
2160
|
+
* @param technologyName - Technology name of the procedure (to check if it's a free consultation)
|
|
2161
|
+
* @returns {Promise<void>}
|
|
2162
|
+
*/
|
|
2163
|
+
async handleFreeConsultationStatusChange(practitionerId, procedureId, clinicId, isActive, technologyName) {
|
|
2164
|
+
if (!practitionerId || !procedureId || !clinicId) {
|
|
2165
|
+
console.log(
|
|
2166
|
+
"[ProcedureAggregationService] Missing required parameters for handling free consultation status change. Skipping."
|
|
2167
|
+
);
|
|
2168
|
+
return;
|
|
2169
|
+
}
|
|
2170
|
+
if (technologyName !== "free-consultation-tech") {
|
|
2171
|
+
return;
|
|
2172
|
+
}
|
|
2173
|
+
console.log(
|
|
2174
|
+
`[ProcedureAggregationService] Handling free consultation status change: procedure ${procedureId} for practitioner ${practitionerId} in clinic ${clinicId}. New status: ${isActive ? "active" : "inactive"}`
|
|
2175
|
+
);
|
|
2176
|
+
const practitionerRef = this.db.collection(PRACTITIONERS_COLLECTION).doc(practitionerId);
|
|
2177
|
+
try {
|
|
2178
|
+
await this.db.runTransaction(async (transaction) => {
|
|
2179
|
+
const practitionerDoc = await transaction.get(practitionerRef);
|
|
2180
|
+
if (!practitionerDoc.exists) {
|
|
2181
|
+
throw new Error(
|
|
2182
|
+
`Practitioner ${practitionerId} does not exist for free consultation status change`
|
|
2183
|
+
);
|
|
2184
|
+
}
|
|
2185
|
+
const practitionerData = practitionerDoc.data();
|
|
2186
|
+
if (!practitionerData) {
|
|
2187
|
+
throw new Error(
|
|
2188
|
+
`Practitioner ${practitionerId} data is empty for free consultation status change`
|
|
2189
|
+
);
|
|
2190
|
+
}
|
|
2191
|
+
const currentFreeConsultations = practitionerData.freeConsultations || {};
|
|
2192
|
+
let updatedFreeConsultations = { ...currentFreeConsultations };
|
|
2193
|
+
if (isActive) {
|
|
2194
|
+
if (currentFreeConsultations[clinicId] && currentFreeConsultations[clinicId] !== procedureId) {
|
|
2195
|
+
console.log(
|
|
2196
|
+
`[ProcedureAggregationService] Warning: Clinic ${clinicId} already has a different free consultation ${currentFreeConsultations[clinicId]}. Replacing with ${procedureId}.`
|
|
2197
|
+
);
|
|
2198
|
+
}
|
|
2199
|
+
updatedFreeConsultations[clinicId] = procedureId;
|
|
2200
|
+
console.log(
|
|
2201
|
+
`[ProcedureAggregationService] Set free consultation ${procedureId} for practitioner ${practitionerId} at clinic ${clinicId} (activated)`
|
|
2202
|
+
);
|
|
2203
|
+
} else {
|
|
2204
|
+
if (currentFreeConsultations[clinicId] === procedureId) {
|
|
2205
|
+
delete updatedFreeConsultations[clinicId];
|
|
2206
|
+
console.log(
|
|
2207
|
+
`[ProcedureAggregationService] Removed free consultation ${procedureId} from practitioner ${practitionerId} for clinic ${clinicId} (deactivated)`
|
|
2208
|
+
);
|
|
2209
|
+
} else {
|
|
2210
|
+
console.log(
|
|
2211
|
+
`[ProcedureAggregationService] Free consultation mismatch for clinic ${clinicId}: expected ${procedureId}, found ${currentFreeConsultations[clinicId]}`
|
|
2212
|
+
);
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
transaction.update(practitionerRef, {
|
|
2216
|
+
freeConsultations: updatedFreeConsultations,
|
|
2217
|
+
updatedAt: admin5.firestore.FieldValue.serverTimestamp()
|
|
2218
|
+
});
|
|
2219
|
+
});
|
|
2220
|
+
console.log(
|
|
2221
|
+
`[ProcedureAggregationService] Successfully handled free consultation status change for procedure ${procedureId} of practitioner ${practitionerId}.`
|
|
2222
|
+
);
|
|
2223
|
+
} catch (error) {
|
|
2224
|
+
console.error(
|
|
2225
|
+
`[ProcedureAggregationService] Error handling free consultation status change for procedure ${procedureId} of practitioner ${practitionerId}:`,
|
|
2226
|
+
error
|
|
2227
|
+
);
|
|
2228
|
+
throw error;
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2100
2231
|
};
|
|
2101
2232
|
|
|
2102
2233
|
// src/admin/aggregation/patient/patient.aggregation.service.ts
|
|
@@ -5017,6 +5017,7 @@ interface Practitioner {
|
|
|
5017
5017
|
clinicWorkingHours: PractitionerClinicWorkingHours[];
|
|
5018
5018
|
clinicsInfo: ClinicInfo[];
|
|
5019
5019
|
procedures: string[];
|
|
5020
|
+
freeConsultations?: Record<string, string> | null;
|
|
5020
5021
|
proceduresInfo: ProcedureSummaryInfo[];
|
|
5021
5022
|
reviewInfo: PractitionerReviewInfo;
|
|
5022
5023
|
isActive: boolean;
|
|
@@ -5017,6 +5017,7 @@ interface Practitioner {
|
|
|
5017
5017
|
clinicWorkingHours: PractitionerClinicWorkingHours[];
|
|
5018
5018
|
clinicsInfo: ClinicInfo[];
|
|
5019
5019
|
procedures: string[];
|
|
5020
|
+
freeConsultations?: Record<string, string> | null;
|
|
5020
5021
|
proceduresInfo: ProcedureSummaryInfo[];
|
|
5021
5022
|
reviewInfo: PractitionerReviewInfo;
|
|
5022
5023
|
isActive: boolean;
|