@blackcode_sa/metaestetics-api 1.6.19 → 1.6.21
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.js +93 -1
- package/dist/admin/index.mjs +93 -1
- package/dist/index.d.mts +262 -262
- package/dist/index.d.ts +262 -262
- package/dist/index.js +9 -9
- package/dist/index.mjs +9 -9
- package/package.json +1 -1
- package/src/admin/aggregation/appointment/appointment.aggregation.service.ts +112 -2
- package/src/types/patient/medical-info.types.ts +12 -12
- package/src/validations/patient/medical-info.schema.ts +9 -9
package/dist/index.js
CHANGED
|
@@ -1332,11 +1332,11 @@ var allergySubtypeSchema = import_zod5.z.union([
|
|
|
1332
1332
|
var allergySchema = import_zod5.z.object({
|
|
1333
1333
|
type: import_zod5.z.nativeEnum(AllergyType),
|
|
1334
1334
|
subtype: allergySubtypeSchema,
|
|
1335
|
-
name: import_zod5.z.string().optional(),
|
|
1335
|
+
name: import_zod5.z.string().optional().nullable(),
|
|
1336
1336
|
severity: import_zod5.z.enum(["mild", "moderate", "severe"]).optional(),
|
|
1337
|
-
reaction: import_zod5.z.string().optional(),
|
|
1338
|
-
diagnosed: timestampSchema2.optional(),
|
|
1339
|
-
notes: import_zod5.z.string().optional()
|
|
1337
|
+
reaction: import_zod5.z.string().optional().nullable(),
|
|
1338
|
+
diagnosed: timestampSchema2.optional().nullable(),
|
|
1339
|
+
notes: import_zod5.z.string().optional().nullable()
|
|
1340
1340
|
});
|
|
1341
1341
|
var vitalStatsSchema = import_zod5.z.object({
|
|
1342
1342
|
height: import_zod5.z.number().positive().optional(),
|
|
@@ -1351,23 +1351,23 @@ var vitalStatsSchema = import_zod5.z.object({
|
|
|
1351
1351
|
var blockingConditionSchema = import_zod5.z.object({
|
|
1352
1352
|
condition: import_zod5.z.nativeEnum(BlockingCondition),
|
|
1353
1353
|
diagnosedAt: timestampSchema2,
|
|
1354
|
-
notes: import_zod5.z.string().optional(),
|
|
1354
|
+
notes: import_zod5.z.string().optional().nullable(),
|
|
1355
1355
|
isActive: import_zod5.z.boolean()
|
|
1356
1356
|
});
|
|
1357
1357
|
var contraindicationSchema = import_zod5.z.object({
|
|
1358
1358
|
condition: import_zod5.z.nativeEnum(Contraindication),
|
|
1359
1359
|
lastOccurrence: timestampSchema2,
|
|
1360
1360
|
frequency: import_zod5.z.enum(["rare", "occasional", "frequent"]),
|
|
1361
|
-
notes: import_zod5.z.string().optional(),
|
|
1361
|
+
notes: import_zod5.z.string().optional().nullable(),
|
|
1362
1362
|
isActive: import_zod5.z.boolean()
|
|
1363
1363
|
});
|
|
1364
1364
|
var medicationSchema = import_zod5.z.object({
|
|
1365
1365
|
name: import_zod5.z.string().min(1),
|
|
1366
1366
|
dosage: import_zod5.z.string().min(1),
|
|
1367
1367
|
frequency: import_zod5.z.string().min(1),
|
|
1368
|
-
startDate: timestampSchema2,
|
|
1369
|
-
endDate: timestampSchema2.optional(),
|
|
1370
|
-
prescribedBy: import_zod5.z.string().optional()
|
|
1368
|
+
startDate: timestampSchema2.optional().nullable(),
|
|
1369
|
+
endDate: timestampSchema2.optional().nullable(),
|
|
1370
|
+
prescribedBy: import_zod5.z.string().optional().nullable()
|
|
1371
1371
|
});
|
|
1372
1372
|
var patientMedicalInfoSchema = import_zod5.z.object({
|
|
1373
1373
|
patientId: import_zod5.z.string(),
|
package/dist/index.mjs
CHANGED
|
@@ -1149,11 +1149,11 @@ var allergySubtypeSchema = z5.union([
|
|
|
1149
1149
|
var allergySchema = z5.object({
|
|
1150
1150
|
type: z5.nativeEnum(AllergyType),
|
|
1151
1151
|
subtype: allergySubtypeSchema,
|
|
1152
|
-
name: z5.string().optional(),
|
|
1152
|
+
name: z5.string().optional().nullable(),
|
|
1153
1153
|
severity: z5.enum(["mild", "moderate", "severe"]).optional(),
|
|
1154
|
-
reaction: z5.string().optional(),
|
|
1155
|
-
diagnosed: timestampSchema2.optional(),
|
|
1156
|
-
notes: z5.string().optional()
|
|
1154
|
+
reaction: z5.string().optional().nullable(),
|
|
1155
|
+
diagnosed: timestampSchema2.optional().nullable(),
|
|
1156
|
+
notes: z5.string().optional().nullable()
|
|
1157
1157
|
});
|
|
1158
1158
|
var vitalStatsSchema = z5.object({
|
|
1159
1159
|
height: z5.number().positive().optional(),
|
|
@@ -1168,23 +1168,23 @@ var vitalStatsSchema = z5.object({
|
|
|
1168
1168
|
var blockingConditionSchema = z5.object({
|
|
1169
1169
|
condition: z5.nativeEnum(BlockingCondition),
|
|
1170
1170
|
diagnosedAt: timestampSchema2,
|
|
1171
|
-
notes: z5.string().optional(),
|
|
1171
|
+
notes: z5.string().optional().nullable(),
|
|
1172
1172
|
isActive: z5.boolean()
|
|
1173
1173
|
});
|
|
1174
1174
|
var contraindicationSchema = z5.object({
|
|
1175
1175
|
condition: z5.nativeEnum(Contraindication),
|
|
1176
1176
|
lastOccurrence: timestampSchema2,
|
|
1177
1177
|
frequency: z5.enum(["rare", "occasional", "frequent"]),
|
|
1178
|
-
notes: z5.string().optional(),
|
|
1178
|
+
notes: z5.string().optional().nullable(),
|
|
1179
1179
|
isActive: z5.boolean()
|
|
1180
1180
|
});
|
|
1181
1181
|
var medicationSchema = z5.object({
|
|
1182
1182
|
name: z5.string().min(1),
|
|
1183
1183
|
dosage: z5.string().min(1),
|
|
1184
1184
|
frequency: z5.string().min(1),
|
|
1185
|
-
startDate: timestampSchema2,
|
|
1186
|
-
endDate: timestampSchema2.optional(),
|
|
1187
|
-
prescribedBy: z5.string().optional()
|
|
1185
|
+
startDate: timestampSchema2.optional().nullable(),
|
|
1186
|
+
endDate: timestampSchema2.optional().nullable(),
|
|
1187
|
+
prescribedBy: z5.string().optional().nullable()
|
|
1188
1188
|
});
|
|
1189
1189
|
var patientMedicalInfoSchema = z5.object({
|
|
1190
1190
|
patientId: z5.string(),
|
package/package.json
CHANGED
|
@@ -507,6 +507,8 @@ export class AppointmentAggregationService {
|
|
|
507
507
|
try {
|
|
508
508
|
const batch = this.db.batch();
|
|
509
509
|
let instancesCreatedCount = 0;
|
|
510
|
+
// Store created instances for fallback direct creation if needed
|
|
511
|
+
let createdInstances = [];
|
|
510
512
|
|
|
511
513
|
// Log more details about the pre-requirements
|
|
512
514
|
Logger.info(
|
|
@@ -606,7 +608,8 @@ export class AppointmentAggregationService {
|
|
|
606
608
|
return instructionObject;
|
|
607
609
|
});
|
|
608
610
|
|
|
609
|
-
const newInstanceData:
|
|
611
|
+
const newInstanceData: PatientRequirementInstance = {
|
|
612
|
+
id: newInstanceRef.id, // Add the ID to the document data
|
|
610
613
|
patientId: appointment.patientId,
|
|
611
614
|
appointmentId: appointment.id,
|
|
612
615
|
originalRequirementId: template.id,
|
|
@@ -633,6 +636,12 @@ export class AppointmentAggregationService {
|
|
|
633
636
|
);
|
|
634
637
|
|
|
635
638
|
batch.set(newInstanceRef, newInstanceData);
|
|
639
|
+
// Store for potential fallback
|
|
640
|
+
createdInstances.push({
|
|
641
|
+
ref: newInstanceRef,
|
|
642
|
+
data: newInstanceData,
|
|
643
|
+
});
|
|
644
|
+
|
|
636
645
|
instancesCreatedCount++;
|
|
637
646
|
Logger.debug(
|
|
638
647
|
`[AggService] Added PatientRequirementInstance ${newInstanceRef.id} to batch for template ${template.id}.`
|
|
@@ -645,12 +654,113 @@ export class AppointmentAggregationService {
|
|
|
645
654
|
Logger.info(
|
|
646
655
|
`[AggService] Successfully created ${instancesCreatedCount} PRE_APPOINTMENT requirement instances for appointment ${appointment.id}.`
|
|
647
656
|
);
|
|
657
|
+
|
|
658
|
+
// Verify creation success
|
|
659
|
+
try {
|
|
660
|
+
const verifySnapshot = await this.db
|
|
661
|
+
.collection(PATIENTS_COLLECTION)
|
|
662
|
+
.doc(appointment.patientId)
|
|
663
|
+
.collection(PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME)
|
|
664
|
+
.where("appointmentId", "==", appointment.id)
|
|
665
|
+
.get();
|
|
666
|
+
|
|
667
|
+
if (verifySnapshot.empty) {
|
|
668
|
+
Logger.warn(
|
|
669
|
+
`[AggService] Batch commit reported success but documents not found! Attempting direct creation as fallback...`
|
|
670
|
+
);
|
|
671
|
+
|
|
672
|
+
// Fallback to direct creation if batch worked but docs aren't there
|
|
673
|
+
const fallbackPromises = createdInstances.map(
|
|
674
|
+
async ({ ref, data }) => {
|
|
675
|
+
try {
|
|
676
|
+
await ref.set(data);
|
|
677
|
+
Logger.info(
|
|
678
|
+
`[AggService] Fallback direct creation success for ${ref.id}`
|
|
679
|
+
);
|
|
680
|
+
return true;
|
|
681
|
+
} catch (fallbackError) {
|
|
682
|
+
Logger.error(
|
|
683
|
+
`[AggService] Fallback direct creation failed for ${ref.id}:`,
|
|
684
|
+
fallbackError
|
|
685
|
+
);
|
|
686
|
+
return false;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
);
|
|
690
|
+
|
|
691
|
+
const fallbackResults = await Promise.allSettled(
|
|
692
|
+
fallbackPromises
|
|
693
|
+
);
|
|
694
|
+
const successCount = fallbackResults.filter(
|
|
695
|
+
(r) => r.status === "fulfilled" && r.value === true
|
|
696
|
+
).length;
|
|
697
|
+
|
|
698
|
+
if (successCount > 0) {
|
|
699
|
+
Logger.info(
|
|
700
|
+
`[AggService] Fallback mechanism created ${successCount} out of ${createdInstances.length} requirements`
|
|
701
|
+
);
|
|
702
|
+
} else {
|
|
703
|
+
Logger.error(
|
|
704
|
+
`[AggService] Both batch and fallback mechanisms failed to create requirements`
|
|
705
|
+
);
|
|
706
|
+
throw new Error(
|
|
707
|
+
"Failed to create patient requirements through both batch and direct methods"
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
} else {
|
|
711
|
+
Logger.info(
|
|
712
|
+
`[AggService] Verification confirmed ${verifySnapshot.size} requirement documents created`
|
|
713
|
+
);
|
|
714
|
+
}
|
|
715
|
+
} catch (verifyError) {
|
|
716
|
+
Logger.error(
|
|
717
|
+
`[AggService] Error during verification of created requirements:`,
|
|
718
|
+
verifyError
|
|
719
|
+
);
|
|
720
|
+
}
|
|
648
721
|
} catch (commitError) {
|
|
649
722
|
Logger.error(
|
|
650
723
|
`[AggService] Error committing batch for PRE_APPOINTMENT requirement instances for appointment ${appointment.id}:`,
|
|
651
724
|
commitError
|
|
652
725
|
);
|
|
653
|
-
|
|
726
|
+
|
|
727
|
+
// Try direct creation as fallback
|
|
728
|
+
Logger.info(`[AggService] Attempting direct creation as fallback...`);
|
|
729
|
+
const fallbackPromises = createdInstances.map(
|
|
730
|
+
async ({ ref, data }) => {
|
|
731
|
+
try {
|
|
732
|
+
await ref.set(data);
|
|
733
|
+
Logger.info(
|
|
734
|
+
`[AggService] Fallback direct creation success for ${ref.id}`
|
|
735
|
+
);
|
|
736
|
+
return true;
|
|
737
|
+
} catch (fallbackError) {
|
|
738
|
+
Logger.error(
|
|
739
|
+
`[AggService] Fallback direct creation failed for ${ref.id}:`,
|
|
740
|
+
fallbackError
|
|
741
|
+
);
|
|
742
|
+
return false;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
);
|
|
746
|
+
|
|
747
|
+
const fallbackResults = await Promise.allSettled(fallbackPromises);
|
|
748
|
+
const successCount = fallbackResults.filter(
|
|
749
|
+
(r) => r.status === "fulfilled" && r.value === true
|
|
750
|
+
).length;
|
|
751
|
+
|
|
752
|
+
if (successCount > 0) {
|
|
753
|
+
Logger.info(
|
|
754
|
+
`[AggService] Fallback mechanism created ${successCount} out of ${createdInstances.length} requirements`
|
|
755
|
+
);
|
|
756
|
+
} else {
|
|
757
|
+
Logger.error(
|
|
758
|
+
`[AggService] Both batch and fallback mechanisms failed to create requirements`
|
|
759
|
+
);
|
|
760
|
+
throw new Error(
|
|
761
|
+
"Failed to create patient requirements through both batch and direct methods"
|
|
762
|
+
);
|
|
763
|
+
}
|
|
654
764
|
}
|
|
655
765
|
} else {
|
|
656
766
|
Logger.info(
|
|
@@ -8,11 +8,11 @@ export const PATIENT_MEDICAL_INFO_COLLECTION = "medical_info";
|
|
|
8
8
|
export interface Allergy {
|
|
9
9
|
type: AllergyType;
|
|
10
10
|
subtype: AllergySubtype;
|
|
11
|
-
name?: string;
|
|
12
|
-
severity?: "mild" | "moderate" | "severe";
|
|
13
|
-
reaction?: string;
|
|
14
|
-
diagnosed?: Timestamp;
|
|
15
|
-
notes?: string;
|
|
11
|
+
name?: string | null;
|
|
12
|
+
severity?: "mild" | "moderate" | "severe" | null;
|
|
13
|
+
reaction?: string | null;
|
|
14
|
+
diagnosed?: Timestamp | null;
|
|
15
|
+
notes?: string | null;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export interface VitalStats {
|
|
@@ -51,9 +51,9 @@ export interface PatientMedicalInfo {
|
|
|
51
51
|
name: string;
|
|
52
52
|
dosage: string;
|
|
53
53
|
frequency: string;
|
|
54
|
-
startDate
|
|
55
|
-
endDate?: Timestamp;
|
|
56
|
-
prescribedBy?: string;
|
|
54
|
+
startDate?: Timestamp | null;
|
|
55
|
+
endDate?: Timestamp | null;
|
|
56
|
+
prescribedBy?: string | null;
|
|
57
57
|
}[];
|
|
58
58
|
|
|
59
59
|
emergencyNotes?: string;
|
|
@@ -87,11 +87,11 @@ export interface UpdateVitalStatsData {
|
|
|
87
87
|
export interface AddAllergyData {
|
|
88
88
|
type: AllergyType;
|
|
89
89
|
subtype: AllergySubtype;
|
|
90
|
-
name?: string;
|
|
90
|
+
name?: string | null;
|
|
91
91
|
severity?: "mild" | "moderate" | "severe";
|
|
92
|
-
reaction?: string;
|
|
93
|
-
diagnosed?: Timestamp;
|
|
94
|
-
notes?: string;
|
|
92
|
+
reaction?: string | null;
|
|
93
|
+
diagnosed?: Timestamp | null;
|
|
94
|
+
notes?: string | null;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
export interface UpdateAllergyData extends Partial<AddAllergyData> {
|
|
@@ -21,11 +21,11 @@ export const allergySubtypeSchema = z.union([
|
|
|
21
21
|
export const allergySchema = z.object({
|
|
22
22
|
type: z.nativeEnum(AllergyType),
|
|
23
23
|
subtype: allergySubtypeSchema,
|
|
24
|
-
name: z.string().optional(),
|
|
24
|
+
name: z.string().optional().nullable(),
|
|
25
25
|
severity: z.enum(["mild", "moderate", "severe"]).optional(),
|
|
26
|
-
reaction: z.string().optional(),
|
|
27
|
-
diagnosed: timestampSchema.optional(),
|
|
28
|
-
notes: z.string().optional(),
|
|
26
|
+
reaction: z.string().optional().nullable(),
|
|
27
|
+
diagnosed: timestampSchema.optional().nullable(),
|
|
28
|
+
notes: z.string().optional().nullable(),
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
export const vitalStatsSchema = z.object({
|
|
@@ -46,7 +46,7 @@ export const vitalStatsSchema = z.object({
|
|
|
46
46
|
export const blockingConditionSchema = z.object({
|
|
47
47
|
condition: z.nativeEnum(BlockingCondition),
|
|
48
48
|
diagnosedAt: timestampSchema,
|
|
49
|
-
notes: z.string().optional(),
|
|
49
|
+
notes: z.string().optional().nullable(),
|
|
50
50
|
isActive: z.boolean(),
|
|
51
51
|
});
|
|
52
52
|
|
|
@@ -54,7 +54,7 @@ export const contraindicationSchema = z.object({
|
|
|
54
54
|
condition: z.nativeEnum(Contraindication),
|
|
55
55
|
lastOccurrence: timestampSchema,
|
|
56
56
|
frequency: z.enum(["rare", "occasional", "frequent"]),
|
|
57
|
-
notes: z.string().optional(),
|
|
57
|
+
notes: z.string().optional().nullable(),
|
|
58
58
|
isActive: z.boolean(),
|
|
59
59
|
});
|
|
60
60
|
|
|
@@ -62,9 +62,9 @@ export const medicationSchema = z.object({
|
|
|
62
62
|
name: z.string().min(1),
|
|
63
63
|
dosage: z.string().min(1),
|
|
64
64
|
frequency: z.string().min(1),
|
|
65
|
-
startDate: timestampSchema,
|
|
66
|
-
endDate: timestampSchema.optional(),
|
|
67
|
-
prescribedBy: z.string().optional(),
|
|
65
|
+
startDate: timestampSchema.optional().nullable(),
|
|
66
|
+
endDate: timestampSchema.optional().nullable(),
|
|
67
|
+
prescribedBy: z.string().optional().nullable(),
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
export const patientMedicalInfoSchema = z.object({
|