@blackcode_sa/metaestetics-api 1.6.2 → 1.6.4
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 +228 -25
- package/dist/admin/index.d.ts +228 -25
- package/dist/admin/index.js +35867 -2493
- package/dist/admin/index.mjs +35856 -2464
- package/dist/backoffice/index.d.mts +252 -1
- package/dist/backoffice/index.d.ts +252 -1
- package/dist/backoffice/index.js +86 -12
- package/dist/backoffice/index.mjs +86 -13
- package/dist/index.d.mts +1417 -554
- package/dist/index.d.ts +1417 -554
- package/dist/index.js +1393 -687
- package/dist/index.mjs +1423 -711
- package/package.json +1 -1
- package/src/admin/index.ts +15 -1
- package/src/admin/notifications/notifications.admin.ts +1 -1
- package/src/admin/requirements/README.md +128 -0
- package/src/admin/requirements/patient-requirements.admin.service.ts +482 -0
- package/src/index.ts +16 -1
- package/src/services/appointment/appointment.service.ts +315 -86
- package/src/services/clinic/clinic-admin.service.ts +3 -0
- package/src/services/clinic/clinic-group.service.ts +8 -0
- package/src/services/documentation-templates/documentation-template.service.ts +24 -16
- package/src/services/documentation-templates/filled-document.service.ts +253 -136
- package/src/services/patient/patient.service.ts +31 -1
- package/src/services/patient/patientRequirements.service.ts +285 -0
- package/src/services/patient/utils/practitioner.utils.ts +79 -1
- package/src/types/appointment/index.ts +134 -10
- package/src/types/documentation-templates/index.ts +34 -2
- package/src/types/notifications/README.md +77 -0
- package/src/types/notifications/index.ts +154 -27
- package/src/types/patient/index.ts +6 -0
- package/src/types/patient/patient-requirements.ts +81 -0
- package/src/validations/appointment.schema.ts +300 -62
- package/src/validations/documentation-templates/template.schema.ts +55 -0
- package/src/validations/documentation-templates.schema.ts +9 -14
- package/src/validations/notification.schema.ts +3 -3
- package/src/validations/patient/patient-requirements.schema.ts +75 -0
|
@@ -14,152 +14,213 @@ import {
|
|
|
14
14
|
} from "firebase/firestore";
|
|
15
15
|
import { BaseService } from "../base.service";
|
|
16
16
|
import {
|
|
17
|
-
DocumentTemplate,
|
|
18
|
-
DOCUMENTATION_TEMPLATES_COLLECTION,
|
|
19
|
-
FILLED_DOCUMENTS_COLLECTION,
|
|
17
|
+
// DocumentTemplate, // Not directly used in this file if relying on templateService
|
|
18
|
+
// DOCUMENTATION_TEMPLATES_COLLECTION, // No longer needed directly here if using templateService
|
|
19
|
+
// FILLED_DOCUMENTS_COLLECTION, // This will be replaced by subcollection paths
|
|
20
20
|
FilledDocument,
|
|
21
21
|
FilledDocumentStatus,
|
|
22
|
-
|
|
22
|
+
USER_FORMS_SUBCOLLECTION,
|
|
23
|
+
DOCTOR_FORMS_SUBCOLLECTION,
|
|
24
|
+
} from "../../types"; // General types
|
|
25
|
+
import { APPOINTMENTS_COLLECTION } from "../../types/appointment"; // Specific import for the constant
|
|
23
26
|
import { DocumentationTemplateService } from "./documentation-template.service";
|
|
27
|
+
// Import the new validation schemas if you plan to use them for input validation here
|
|
28
|
+
// import { createFilledDocumentDataSchema, updateFilledDocumentDataSchema } from '../../validations/documentation-templates.schema';
|
|
24
29
|
|
|
25
30
|
/**
|
|
26
|
-
* Service for managing filled documents
|
|
31
|
+
* Service for managing filled documents within appointment subcollections
|
|
27
32
|
*/
|
|
28
33
|
export class FilledDocumentService extends BaseService {
|
|
29
|
-
|
|
30
|
-
this.db,
|
|
31
|
-
FILLED_DOCUMENTS_COLLECTION
|
|
32
|
-
);
|
|
34
|
+
// No single collectionRef anymore, paths will be dynamic
|
|
33
35
|
private readonly templateService: DocumentationTemplateService;
|
|
34
36
|
|
|
35
37
|
constructor(...args: ConstructorParameters<typeof BaseService>) {
|
|
36
38
|
super(...args);
|
|
37
|
-
this.templateService = new DocumentationTemplateService(...args);
|
|
39
|
+
this.templateService = new DocumentationTemplateService(...args); // Pass db and other args
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private getFormSubcollectionPath(
|
|
43
|
+
isUserForm: boolean
|
|
44
|
+
): typeof USER_FORMS_SUBCOLLECTION | typeof DOCTOR_FORMS_SUBCOLLECTION {
|
|
45
|
+
return isUserForm ? USER_FORMS_SUBCOLLECTION : DOCTOR_FORMS_SUBCOLLECTION;
|
|
38
46
|
}
|
|
39
47
|
|
|
40
48
|
/**
|
|
41
|
-
* Create a new filled document
|
|
42
|
-
* @param templateId - ID of the template to use
|
|
43
|
-
* @param
|
|
44
|
-
* @param
|
|
45
|
-
* @param
|
|
46
|
-
* @
|
|
49
|
+
* Create a new filled document within an appointment's subcollection.
|
|
50
|
+
* @param templateId - ID of the template to use.
|
|
51
|
+
* @param appointmentId - ID of the appointment this form belongs to.
|
|
52
|
+
* @param procedureId - ID of the procedure associated with this form.
|
|
53
|
+
* @param patientId - ID of the patient.
|
|
54
|
+
* @param practitionerId - ID of the practitioner (can be system/generic if patient is filling).
|
|
55
|
+
* @param clinicId - ID of the clinic.
|
|
56
|
+
* @param initialValues - Optional initial values for the form elements.
|
|
57
|
+
* @param initialStatus - Optional initial status for the form.
|
|
58
|
+
* @returns The created filled document.
|
|
47
59
|
*/
|
|
48
|
-
async
|
|
60
|
+
async createFilledDocumentForAppointment(
|
|
49
61
|
templateId: string,
|
|
62
|
+
appointmentId: string,
|
|
63
|
+
procedureId: string,
|
|
50
64
|
patientId: string,
|
|
51
|
-
practitionerId: string,
|
|
52
|
-
clinicId: string
|
|
65
|
+
practitionerId: string, // Consider if this is always available or if a placeholder is needed
|
|
66
|
+
clinicId: string, // Same consideration as practitionerId
|
|
67
|
+
initialValues: { [elementId: string]: any } = {},
|
|
68
|
+
initialStatus: FilledDocumentStatus = FilledDocumentStatus.DRAFT
|
|
53
69
|
): Promise<FilledDocument> {
|
|
54
|
-
// Get the template
|
|
55
70
|
const template = await this.templateService.getTemplateById(templateId);
|
|
56
71
|
if (!template) {
|
|
57
72
|
throw new Error(`Template with ID ${templateId} not found`);
|
|
58
73
|
}
|
|
59
74
|
|
|
60
|
-
// Generate ID for the filled document
|
|
61
75
|
const documentId = this.generateId();
|
|
62
|
-
|
|
63
|
-
// Create filled document object
|
|
64
76
|
const now = Date.now();
|
|
77
|
+
const isUserForm = template.isUserForm || false;
|
|
78
|
+
const formSubcollection = this.getFormSubcollectionPath(isUserForm);
|
|
79
|
+
|
|
65
80
|
const filledDocument: FilledDocument = {
|
|
66
81
|
id: documentId,
|
|
67
82
|
templateId,
|
|
68
83
|
templateVersion: template.version,
|
|
84
|
+
isUserForm: isUserForm, // Set based on template
|
|
85
|
+
isRequired: template.isRequired || false, // Inherit isRequired from the template
|
|
86
|
+
appointmentId: appointmentId, // NEW
|
|
87
|
+
procedureId: procedureId, // NEW
|
|
69
88
|
patientId,
|
|
70
89
|
practitionerId,
|
|
71
90
|
clinicId,
|
|
72
91
|
createdAt: now,
|
|
73
92
|
updatedAt: now,
|
|
74
|
-
values:
|
|
75
|
-
status:
|
|
93
|
+
values: initialValues,
|
|
94
|
+
status: initialStatus,
|
|
76
95
|
};
|
|
77
96
|
|
|
78
|
-
|
|
79
|
-
|
|
97
|
+
const docRef = doc(
|
|
98
|
+
this.db,
|
|
99
|
+
APPOINTMENTS_COLLECTION, // Replaced "appointments"
|
|
100
|
+
appointmentId,
|
|
101
|
+
formSubcollection,
|
|
102
|
+
documentId
|
|
103
|
+
);
|
|
80
104
|
await setDoc(docRef, filledDocument);
|
|
81
105
|
|
|
82
106
|
return filledDocument;
|
|
83
107
|
}
|
|
84
108
|
|
|
85
109
|
/**
|
|
86
|
-
* Get a filled document
|
|
87
|
-
* @param
|
|
88
|
-
* @
|
|
110
|
+
* Get a specific filled document from an appointment's subcollection.
|
|
111
|
+
* @param appointmentId - ID of the appointment.
|
|
112
|
+
* @param formId - ID of the filled document.
|
|
113
|
+
* @param isUserForm - Boolean indicating if it's a user form or doctor form.
|
|
114
|
+
* @returns The filled document or null if not found.
|
|
89
115
|
*/
|
|
90
|
-
async
|
|
91
|
-
|
|
116
|
+
async getFilledDocumentFromAppointmentById(
|
|
117
|
+
appointmentId: string,
|
|
118
|
+
formId: string,
|
|
119
|
+
isUserForm: boolean
|
|
92
120
|
): Promise<FilledDocument | null> {
|
|
93
|
-
const
|
|
121
|
+
const formSubcollection = this.getFormSubcollectionPath(isUserForm);
|
|
122
|
+
const docRef = doc(
|
|
123
|
+
this.db,
|
|
124
|
+
APPOINTMENTS_COLLECTION, // Replaced "appointments"
|
|
125
|
+
appointmentId,
|
|
126
|
+
formSubcollection,
|
|
127
|
+
formId
|
|
128
|
+
);
|
|
94
129
|
const docSnap = await getDoc(docRef);
|
|
95
130
|
|
|
96
131
|
if (!docSnap.exists()) {
|
|
97
132
|
return null;
|
|
98
133
|
}
|
|
99
|
-
|
|
100
134
|
return docSnap.data() as FilledDocument;
|
|
101
135
|
}
|
|
102
136
|
|
|
103
137
|
/**
|
|
104
|
-
* Update values in a filled document
|
|
105
|
-
* @param
|
|
106
|
-
* @param
|
|
107
|
-
* @param
|
|
108
|
-
* @
|
|
138
|
+
* Update values or status in a filled document within an appointment's subcollection.
|
|
139
|
+
* @param appointmentId - ID of the appointment.
|
|
140
|
+
* @param formId - ID of the filled document to update.
|
|
141
|
+
* @param isUserForm - Boolean indicating if it's a user form or doctor form.
|
|
142
|
+
* @param values - Updated values for elements.
|
|
143
|
+
* @param status - Optional new status for the document.
|
|
144
|
+
* @returns The updated filled document.
|
|
109
145
|
*/
|
|
110
|
-
async
|
|
111
|
-
|
|
112
|
-
|
|
146
|
+
async updateFilledDocumentInAppointment(
|
|
147
|
+
appointmentId: string,
|
|
148
|
+
formId: string,
|
|
149
|
+
isUserForm: boolean,
|
|
150
|
+
values?: { [elementId: string]: any },
|
|
113
151
|
status?: FilledDocumentStatus
|
|
114
152
|
): Promise<FilledDocument> {
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
153
|
+
const formSubcollection = this.getFormSubcollectionPath(isUserForm);
|
|
154
|
+
const docRef = doc(
|
|
155
|
+
this.db,
|
|
156
|
+
APPOINTMENTS_COLLECTION, // Replaced "appointments"
|
|
157
|
+
appointmentId,
|
|
158
|
+
formSubcollection,
|
|
159
|
+
formId
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const existingDoc = await this.getFilledDocumentFromAppointmentById(
|
|
163
|
+
appointmentId,
|
|
164
|
+
formId,
|
|
165
|
+
isUserForm
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
if (!existingDoc) {
|
|
169
|
+
throw new Error(
|
|
170
|
+
`Filled document with ID ${formId} not found in appointment ${appointmentId} ${formSubcollection}`
|
|
171
|
+
);
|
|
119
172
|
}
|
|
120
173
|
|
|
121
|
-
|
|
122
|
-
const updateData: Partial<FilledDocument> = {
|
|
123
|
-
values: {
|
|
124
|
-
...filledDocument.values,
|
|
125
|
-
...values,
|
|
126
|
-
},
|
|
174
|
+
const updatePayload: Partial<FilledDocument> = {
|
|
127
175
|
updatedAt: Date.now(),
|
|
128
176
|
};
|
|
129
177
|
|
|
178
|
+
if (values) {
|
|
179
|
+
updatePayload.values = {
|
|
180
|
+
...existingDoc.values,
|
|
181
|
+
...values,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
130
184
|
if (status) {
|
|
131
|
-
|
|
185
|
+
updatePayload.status = status;
|
|
132
186
|
}
|
|
133
187
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
188
|
+
if (
|
|
189
|
+
Object.keys(updatePayload).length === 1 &&
|
|
190
|
+
"updatedAt" in updatePayload
|
|
191
|
+
) {
|
|
192
|
+
// Only updatedAt, no actual data change, so we can skip the update
|
|
193
|
+
// or just update timestamp if that is the desired behavior.
|
|
194
|
+
// For now, we proceed to update the timestamp at least.
|
|
195
|
+
}
|
|
137
196
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
...updateData,
|
|
142
|
-
} as FilledDocument;
|
|
197
|
+
await updateDoc(docRef, updatePayload);
|
|
198
|
+
|
|
199
|
+
return { ...existingDoc, ...updatePayload } as FilledDocument;
|
|
143
200
|
}
|
|
144
201
|
|
|
145
202
|
/**
|
|
146
|
-
* Get filled
|
|
147
|
-
* @param
|
|
148
|
-
* @param pageSize
|
|
149
|
-
* @param lastDoc
|
|
150
|
-
* @returns Array of filled documents and the last document for pagination
|
|
203
|
+
* Get all filled user forms for a specific appointment.
|
|
204
|
+
* @param appointmentId ID of the appointment.
|
|
205
|
+
* @param pageSize Number of documents to retrieve.
|
|
206
|
+
* @param lastDoc Last document from previous page for pagination.
|
|
151
207
|
*/
|
|
152
|
-
async
|
|
153
|
-
|
|
208
|
+
async getFilledUserFormsForAppointment(
|
|
209
|
+
appointmentId: string,
|
|
154
210
|
pageSize = 20,
|
|
155
211
|
lastDoc?: QueryDocumentSnapshot<FilledDocument>
|
|
156
212
|
): Promise<{
|
|
157
213
|
documents: FilledDocument[];
|
|
158
214
|
lastDoc: QueryDocumentSnapshot<FilledDocument> | null;
|
|
159
215
|
}> {
|
|
216
|
+
const subcollectionRef = collection(
|
|
217
|
+
this.db,
|
|
218
|
+
APPOINTMENTS_COLLECTION, // Replaced "appointments"
|
|
219
|
+
appointmentId,
|
|
220
|
+
USER_FORMS_SUBCOLLECTION
|
|
221
|
+
);
|
|
160
222
|
let q = query(
|
|
161
|
-
|
|
162
|
-
where("patientId", "==", patientId),
|
|
223
|
+
subcollectionRef,
|
|
163
224
|
orderBy("updatedAt", "desc"),
|
|
164
225
|
limit(pageSize)
|
|
165
226
|
);
|
|
@@ -167,7 +228,48 @@ export class FilledDocumentService extends BaseService {
|
|
|
167
228
|
if (lastDoc) {
|
|
168
229
|
q = query(q, startAfter(lastDoc));
|
|
169
230
|
}
|
|
231
|
+
return this.executeQuery(q);
|
|
232
|
+
}
|
|
170
233
|
|
|
234
|
+
/**
|
|
235
|
+
* Get all filled doctor forms for a specific appointment.
|
|
236
|
+
* @param appointmentId ID of the appointment.
|
|
237
|
+
* @param pageSize Number of documents to retrieve.
|
|
238
|
+
* @param lastDoc Last document from previous page for pagination.
|
|
239
|
+
*/
|
|
240
|
+
async getFilledDoctorFormsForAppointment(
|
|
241
|
+
appointmentId: string,
|
|
242
|
+
pageSize = 20,
|
|
243
|
+
lastDoc?: QueryDocumentSnapshot<FilledDocument>
|
|
244
|
+
): Promise<{
|
|
245
|
+
documents: FilledDocument[];
|
|
246
|
+
lastDoc: QueryDocumentSnapshot<FilledDocument> | null;
|
|
247
|
+
}> {
|
|
248
|
+
const subcollectionRef = collection(
|
|
249
|
+
this.db,
|
|
250
|
+
APPOINTMENTS_COLLECTION, // Replaced "appointments"
|
|
251
|
+
appointmentId,
|
|
252
|
+
DOCTOR_FORMS_SUBCOLLECTION
|
|
253
|
+
);
|
|
254
|
+
let q = query(
|
|
255
|
+
subcollectionRef,
|
|
256
|
+
orderBy("updatedAt", "desc"),
|
|
257
|
+
limit(pageSize)
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
if (lastDoc) {
|
|
261
|
+
q = query(q, startAfter(lastDoc));
|
|
262
|
+
}
|
|
263
|
+
return this.executeQuery(q);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Helper to execute query and return documents + lastDoc
|
|
267
|
+
private async executeQuery(
|
|
268
|
+
q: any // Firestore Query type
|
|
269
|
+
): Promise<{
|
|
270
|
+
documents: FilledDocument[];
|
|
271
|
+
lastDoc: QueryDocumentSnapshot<FilledDocument> | null;
|
|
272
|
+
}> {
|
|
171
273
|
const querySnapshot = await getDocs(q);
|
|
172
274
|
const documents: FilledDocument[] = [];
|
|
173
275
|
let lastVisible: QueryDocumentSnapshot<FilledDocument> | null = null;
|
|
@@ -183,24 +285,36 @@ export class FilledDocumentService extends BaseService {
|
|
|
183
285
|
};
|
|
184
286
|
}
|
|
185
287
|
|
|
288
|
+
// IMPORTANT: The following methods that query across all patients/practitioners/clinics
|
|
289
|
+
// (e.g., getFilledDocumentsByPatient, getFilledDocumentsByPractitioner)
|
|
290
|
+
// will NOT work correctly if FILLED_DOCUMENTS_COLLECTION is no longer a top-level collection
|
|
291
|
+
// and data is only in appointment subcollections. You would need to use
|
|
292
|
+
// Firestore Collection Group Queries for that, which require an index and a different query approach.
|
|
293
|
+
// These methods are left here for now but would need significant rework or removal.
|
|
294
|
+
|
|
186
295
|
/**
|
|
187
|
-
* Get filled documents for a
|
|
188
|
-
* @param
|
|
296
|
+
* Get filled documents for a patient (NEEDS REWORK for subcollections or Collection Group Query)
|
|
297
|
+
* @param patientId - ID of the patient
|
|
189
298
|
* @param pageSize - Number of documents to retrieve
|
|
190
299
|
* @param lastDoc - Last document from previous page for pagination
|
|
191
300
|
* @returns Array of filled documents and the last document for pagination
|
|
192
301
|
*/
|
|
193
|
-
async
|
|
194
|
-
|
|
302
|
+
async getFilledDocumentsByPatient(
|
|
303
|
+
patientId: string,
|
|
195
304
|
pageSize = 20,
|
|
196
305
|
lastDoc?: QueryDocumentSnapshot<FilledDocument>
|
|
197
306
|
): Promise<{
|
|
198
307
|
documents: FilledDocument[];
|
|
199
308
|
lastDoc: QueryDocumentSnapshot<FilledDocument> | null;
|
|
200
309
|
}> {
|
|
310
|
+
console.warn(
|
|
311
|
+
"getFilledDocumentsByPatient needs rework for subcollection model or Collection Group Queries."
|
|
312
|
+
);
|
|
313
|
+
// Original logic commented out as this.collectionRef is no longer valid for this model
|
|
314
|
+
/*
|
|
201
315
|
let q = query(
|
|
202
|
-
this.collectionRef,
|
|
203
|
-
where("
|
|
316
|
+
this.collectionRef, // LINTER ERROR: this.collectionRef no longer exists
|
|
317
|
+
where("patientId", "==", patientId),
|
|
204
318
|
orderBy("updatedAt", "desc"),
|
|
205
319
|
limit(pageSize)
|
|
206
320
|
);
|
|
@@ -222,10 +336,43 @@ export class FilledDocumentService extends BaseService {
|
|
|
222
336
|
documents,
|
|
223
337
|
lastDoc: lastVisible,
|
|
224
338
|
};
|
|
339
|
+
*/
|
|
340
|
+
return { documents: [], lastDoc: null }; // Placeholder return
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Get filled documents for a practitioner (NEEDS REWORK for subcollections or Collection Group Query)
|
|
345
|
+
* @param practitionerId - ID of the practitioner
|
|
346
|
+
* @param pageSize - Number of documents to retrieve
|
|
347
|
+
* @param lastDoc - Last document from previous page for pagination
|
|
348
|
+
* @returns Array of filled documents and the last document for pagination
|
|
349
|
+
*/
|
|
350
|
+
async getFilledDocumentsByPractitioner(
|
|
351
|
+
practitionerId: string,
|
|
352
|
+
pageSize = 20,
|
|
353
|
+
lastDoc?: QueryDocumentSnapshot<FilledDocument>
|
|
354
|
+
): Promise<{
|
|
355
|
+
documents: FilledDocument[];
|
|
356
|
+
lastDoc: QueryDocumentSnapshot<FilledDocument> | null;
|
|
357
|
+
}> {
|
|
358
|
+
console.warn(
|
|
359
|
+
"getFilledDocumentsByPractitioner needs rework for subcollection model or Collection Group Queries."
|
|
360
|
+
);
|
|
361
|
+
// Original logic commented out
|
|
362
|
+
/*
|
|
363
|
+
let q = query(
|
|
364
|
+
this.collectionRef, // LINTER ERROR
|
|
365
|
+
where("practitionerId", "==", practitionerId),
|
|
366
|
+
orderBy("updatedAt", "desc"),
|
|
367
|
+
limit(pageSize)
|
|
368
|
+
);
|
|
369
|
+
// ... rest of original logic ...
|
|
370
|
+
*/
|
|
371
|
+
return { documents: [], lastDoc: null }; // Placeholder return
|
|
225
372
|
}
|
|
226
373
|
|
|
227
374
|
/**
|
|
228
|
-
* Get filled documents for a clinic
|
|
375
|
+
* Get filled documents for a clinic (NEEDS REWORK for subcollections or Collection Group Query)
|
|
229
376
|
* @param clinicId - ID of the clinic
|
|
230
377
|
* @param pageSize - Number of documents to retrieve
|
|
231
378
|
* @param lastDoc - Last document from previous page for pagination
|
|
@@ -239,34 +386,24 @@ export class FilledDocumentService extends BaseService {
|
|
|
239
386
|
documents: FilledDocument[];
|
|
240
387
|
lastDoc: QueryDocumentSnapshot<FilledDocument> | null;
|
|
241
388
|
}> {
|
|
389
|
+
console.warn(
|
|
390
|
+
"getFilledDocumentsByClinic needs rework for subcollection model or Collection Group Queries."
|
|
391
|
+
);
|
|
392
|
+
// Original logic commented out
|
|
393
|
+
/*
|
|
242
394
|
let q = query(
|
|
243
|
-
this.collectionRef,
|
|
395
|
+
this.collectionRef, // LINTER ERROR
|
|
244
396
|
where("clinicId", "==", clinicId),
|
|
245
397
|
orderBy("updatedAt", "desc"),
|
|
246
398
|
limit(pageSize)
|
|
247
399
|
);
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const querySnapshot = await getDocs(q);
|
|
254
|
-
const documents: FilledDocument[] = [];
|
|
255
|
-
let lastVisible: QueryDocumentSnapshot<FilledDocument> | null = null;
|
|
256
|
-
|
|
257
|
-
querySnapshot.forEach((doc) => {
|
|
258
|
-
documents.push(doc.data() as FilledDocument);
|
|
259
|
-
lastVisible = doc as QueryDocumentSnapshot<FilledDocument>;
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
return {
|
|
263
|
-
documents,
|
|
264
|
-
lastDoc: lastVisible,
|
|
265
|
-
};
|
|
400
|
+
// ... rest of original logic ...
|
|
401
|
+
*/
|
|
402
|
+
return { documents: [], lastDoc: null }; // Placeholder return
|
|
266
403
|
}
|
|
267
404
|
|
|
268
405
|
/**
|
|
269
|
-
* Get filled documents by template
|
|
406
|
+
* Get filled documents by template (NEEDS REWORK for subcollections or Collection Group Query)
|
|
270
407
|
* @param templateId - ID of the template
|
|
271
408
|
* @param pageSize - Number of documents to retrieve
|
|
272
409
|
* @param lastDoc - Last document from previous page for pagination
|
|
@@ -280,34 +417,24 @@ export class FilledDocumentService extends BaseService {
|
|
|
280
417
|
documents: FilledDocument[];
|
|
281
418
|
lastDoc: QueryDocumentSnapshot<FilledDocument> | null;
|
|
282
419
|
}> {
|
|
420
|
+
console.warn(
|
|
421
|
+
"getFilledDocumentsByTemplate needs rework for subcollection model or Collection Group Queries."
|
|
422
|
+
);
|
|
423
|
+
// Original logic commented out
|
|
424
|
+
/*
|
|
283
425
|
let q = query(
|
|
284
|
-
this.collectionRef,
|
|
426
|
+
this.collectionRef, // LINTER ERROR
|
|
285
427
|
where("templateId", "==", templateId),
|
|
286
428
|
orderBy("updatedAt", "desc"),
|
|
287
429
|
limit(pageSize)
|
|
288
430
|
);
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const querySnapshot = await getDocs(q);
|
|
295
|
-
const documents: FilledDocument[] = [];
|
|
296
|
-
let lastVisible: QueryDocumentSnapshot<FilledDocument> | null = null;
|
|
297
|
-
|
|
298
|
-
querySnapshot.forEach((doc) => {
|
|
299
|
-
documents.push(doc.data() as FilledDocument);
|
|
300
|
-
lastVisible = doc as QueryDocumentSnapshot<FilledDocument>;
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
return {
|
|
304
|
-
documents,
|
|
305
|
-
lastDoc: lastVisible,
|
|
306
|
-
};
|
|
431
|
+
// ... rest of original logic ...
|
|
432
|
+
*/
|
|
433
|
+
return { documents: [], lastDoc: null }; // Placeholder return
|
|
307
434
|
}
|
|
308
435
|
|
|
309
436
|
/**
|
|
310
|
-
* Get filled documents by status
|
|
437
|
+
* Get filled documents by status (NEEDS REWORK for subcollections or Collection Group Query)
|
|
311
438
|
* @param status - Status to filter by
|
|
312
439
|
* @param pageSize - Number of documents to retrieve
|
|
313
440
|
* @param lastDoc - Last document from previous page for pagination
|
|
@@ -321,29 +448,19 @@ export class FilledDocumentService extends BaseService {
|
|
|
321
448
|
documents: FilledDocument[];
|
|
322
449
|
lastDoc: QueryDocumentSnapshot<FilledDocument> | null;
|
|
323
450
|
}> {
|
|
451
|
+
console.warn(
|
|
452
|
+
"getFilledDocumentsByStatus needs rework for subcollection model or Collection Group Queries."
|
|
453
|
+
);
|
|
454
|
+
// Original logic commented out
|
|
455
|
+
/*
|
|
324
456
|
let q = query(
|
|
325
|
-
this.collectionRef,
|
|
457
|
+
this.collectionRef, // LINTER ERROR
|
|
326
458
|
where("status", "==", status),
|
|
327
459
|
orderBy("updatedAt", "desc"),
|
|
328
460
|
limit(pageSize)
|
|
329
461
|
);
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
const querySnapshot = await getDocs(q);
|
|
336
|
-
const documents: FilledDocument[] = [];
|
|
337
|
-
let lastVisible: QueryDocumentSnapshot<FilledDocument> | null = null;
|
|
338
|
-
|
|
339
|
-
querySnapshot.forEach((doc) => {
|
|
340
|
-
documents.push(doc.data() as FilledDocument);
|
|
341
|
-
lastVisible = doc as QueryDocumentSnapshot<FilledDocument>;
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
return {
|
|
345
|
-
documents,
|
|
346
|
-
lastDoc: lastVisible,
|
|
347
|
-
};
|
|
462
|
+
// ... rest of original logic ...
|
|
463
|
+
*/
|
|
464
|
+
return { documents: [], lastDoc: null }; // Placeholder return
|
|
348
465
|
}
|
|
349
466
|
}
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
PatientClinic,
|
|
32
32
|
SearchPatientsParams,
|
|
33
33
|
RequesterInfo,
|
|
34
|
+
PatientProfileForDoctor,
|
|
34
35
|
} from "../../types/patient";
|
|
35
36
|
import { Auth } from "firebase/auth";
|
|
36
37
|
import { Firestore } from "firebase/firestore";
|
|
@@ -99,7 +100,10 @@ import {
|
|
|
99
100
|
removeClinicUtil,
|
|
100
101
|
} from "./utils/medical-stuff.utils";
|
|
101
102
|
|
|
102
|
-
import {
|
|
103
|
+
import {
|
|
104
|
+
getPatientsByPractitionerUtil,
|
|
105
|
+
getPatientsByPractitionerWithDetailsUtil,
|
|
106
|
+
} from "./utils/practitioner.utils";
|
|
103
107
|
import { getPatientsByClinicUtil } from "./utils/clinic.utils";
|
|
104
108
|
|
|
105
109
|
export class PatientService extends BaseService {
|
|
@@ -543,6 +547,32 @@ export class PatientService extends BaseService {
|
|
|
543
547
|
return getPatientsByPractitionerUtil(this.db, practitionerId, options);
|
|
544
548
|
}
|
|
545
549
|
|
|
550
|
+
/**
|
|
551
|
+
* Gets all patients associated with a specific practitioner with their sensitive information.
|
|
552
|
+
*
|
|
553
|
+
* @param {string} practitionerId - ID of the practitioner whose patients to retrieve
|
|
554
|
+
* @param {Object} options - Optional parameters for pagination
|
|
555
|
+
* @param {number} options.limit - Maximum number of profiles to return
|
|
556
|
+
* @param {string} options.startAfter - The ID of the document to start after (for pagination)
|
|
557
|
+
* @returns {Promise<PatientProfileForDoctor[]>} A promise resolving to an array of patient profiles with sensitive info
|
|
558
|
+
*/
|
|
559
|
+
async getPatientsByPractitionerWithDetails(
|
|
560
|
+
practitionerId: string,
|
|
561
|
+
options?: {
|
|
562
|
+
limit?: number;
|
|
563
|
+
startAfter?: string;
|
|
564
|
+
}
|
|
565
|
+
): Promise<PatientProfileForDoctor[]> {
|
|
566
|
+
console.log(
|
|
567
|
+
`[PatientService.getPatientsByPractitionerWithDetails] Fetching detailed patient profiles for practitioner: ${practitionerId}`
|
|
568
|
+
);
|
|
569
|
+
return getPatientsByPractitionerWithDetailsUtil(
|
|
570
|
+
this.db,
|
|
571
|
+
practitionerId,
|
|
572
|
+
options
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
|
|
546
576
|
/**
|
|
547
577
|
* Gets all patients associated with a specific clinic.
|
|
548
578
|
*
|