av6-core 1.1.1 → 1.1.3

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.d.mts CHANGED
@@ -268,88 +268,6 @@ declare const getPattern: {
268
268
  };
269
269
  declare const interpolate: (template: string, vars: Record<string, unknown>) => string;
270
270
 
271
- type DiscountMode = "PERCENTAGE" | "AMOUNT";
272
- type AdditionalDiscountMode = "PERCENTAGE" | "AMOUNT";
273
- type CoPayType = "PERCENTAGE" | "AMOUNT";
274
- type TaxMethod = "NONE" | "INCLUSIVE" | "EXCLUSIVE";
275
- type CoPayMode = "EXCLUSIVE-INCLUSIVE" | "PERCENTAGE-AMOUNT";
276
- declare const RoundFormat: {
277
- readonly ROUND: "ROUND";
278
- readonly SPECIAL_ROUND: "SPECIAL_ROUND";
279
- readonly TO_FIXED: "TO_FIXED";
280
- readonly CEIL: "CEIL";
281
- readonly FLOOR: "FLOOR";
282
- readonly TRUNC: "TRUNC";
283
- readonly NONE: "NONE";
284
- };
285
- type RoundFormat = (typeof RoundFormat)[keyof typeof RoundFormat];
286
- interface ChildCalcInput {
287
- qty: number;
288
- rate: number;
289
- otherCharge?: number;
290
- addonPercentage?: number;
291
- discountMode?: DiscountMode;
292
- discountValue?: number;
293
- taxMethod?: TaxMethod;
294
- taxValue?: number;
295
- /** Absolute insurer-covered at line level */
296
- coPaymentType?: CoPayType;
297
- coPayValue?: number;
298
- coPayMethod?: "EXCLUSIVE" | "INCLUSIVE";
299
- }
300
- interface MasterAdditionalDiscount {
301
- mode: AdditionalDiscountMode;
302
- value: number;
303
- coPayMode?: CoPayMode;
304
- }
305
- interface CalcOptions {
306
- calculationMethod?: "STEP_WISE" | "FINAL_ONLY";
307
- lineRound?: RoundFormat;
308
- headerRound?: RoundFormat;
309
- precision?: number;
310
- }
311
- interface ChildCalculated {
312
- baseRate: number;
313
- subtotalAmount: number;
314
- otherChargeAmount: number;
315
- discountMode: DiscountMode;
316
- discountValue: number;
317
- discountAmount: number;
318
- taxMethod: TaxMethod;
319
- taxValue: number;
320
- taxAmount: number;
321
- grossAmount: number;
322
- netAmount: number;
323
- roundOffAmount: number;
324
- copayAmount: number;
325
- }
326
- interface MasterCalculated {
327
- additionalDiscountMode: AdditionalDiscountMode;
328
- additionalDiscountValue: number;
329
- subtotalAmount: number;
330
- otherChargeAmount: number;
331
- discountTotalAmount: number;
332
- taxAmount: number;
333
- grossAmount: number;
334
- netAmount: number;
335
- roundOffAmount: number;
336
- copayAmount: number;
337
- }
338
- interface BillingCalcResult {
339
- master: MasterCalculated;
340
- children: ChildCalculated[];
341
- }
342
-
343
- /**
344
- * calculateBillingFromChildren (master-level additional discount applied AFTER child calculations)
345
- * - Child: item discount -> tax (INCLUSIVE/EXCLUSIVE/NONE) -> coPay -> patient line net + line rounding
346
- * - Master: sum children, compute patientRawTotal = gross - Σcopay
347
- * apply master additional discount ON patientRawTotal (no propagation to children)
348
- * then header rounding
349
- */
350
- declare function calculateBillingFromChildren(inputs: ChildCalcInput[], masterExtra: MasterAdditionalDiscount, options?: CalcOptions): BillingCalcResult;
351
- declare function calculateSingleChild(it: ChildCalcInput, coPayMode: CoPayMode, options?: CalcOptions): ChildCalculated;
352
-
353
271
  interface CreateTransaction {
354
272
  field: string;
355
273
  changedFrom?: string | null;
@@ -429,6 +347,7 @@ declare const uinConfigService: (uinDeps: UinDeps) => {
429
347
 
430
348
  declare const toUINConfigDTO: (model: any) => UINConfigDTO;
431
349
 
350
+ type Priority = "high" | "normal" | "low";
432
351
  type Recipient = {
433
352
  email?: string;
434
353
  phone?: string;
@@ -441,6 +360,7 @@ type EmitPayload = {
441
360
  recipient: Recipient;
442
361
  data?: Record<string, any>;
443
362
  dataWp?: any[];
363
+ priority?: Priority;
444
364
  };
445
365
  type ILogger = winston.Logger | Console;
446
366
  type NotificationEmitterDeps = {
@@ -469,4 +389,4 @@ declare class NotificationEmitter {
469
389
  notifyNow(eventName: string, body: Omit<EmitPayload, "eventName">): Promise<void>;
470
390
  }
471
391
 
472
- export { type AdditionalDiscountMode, type BillingCalcResult, type CacheAdapter, type CalcOptions, type CalculationRes, type ChildCalcInput, type ChildCalculated, type CoPayMode, type CoPayType, type ColValue, type CommonExcelRequest, type CommonFilterRequest, type CommonServiceResponse, type Config, type Context, type CreateUINConfigRequest, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DiscountMode, type DropdownRequest, type DropdownRequestService, type DynamicShortCode, type EmitPayload, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type Mapper, type MasterAdditionalDiscount, type MasterCalculated, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type PaginatedResponse, type Recipient, RoundFormat, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type Store, type TaxMethod, type ToggleActive, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, calculateBillingFromChildren, calculateSingleChild, commonService, customOmit, findDifferences, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
392
+ export { type CacheAdapter, type CalculationRes, type ColValue, type CommonExcelRequest, type CommonFilterRequest, type CommonServiceResponse, type Config, type Context, type CreateUINConfigRequest, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DynamicShortCode, type EmitPayload, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type Mapper, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type PaginatedResponse, type Recipient, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type Store, type ToggleActive, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
package/dist/index.d.ts CHANGED
@@ -268,88 +268,6 @@ declare const getPattern: {
268
268
  };
269
269
  declare const interpolate: (template: string, vars: Record<string, unknown>) => string;
270
270
 
271
- type DiscountMode = "PERCENTAGE" | "AMOUNT";
272
- type AdditionalDiscountMode = "PERCENTAGE" | "AMOUNT";
273
- type CoPayType = "PERCENTAGE" | "AMOUNT";
274
- type TaxMethod = "NONE" | "INCLUSIVE" | "EXCLUSIVE";
275
- type CoPayMode = "EXCLUSIVE-INCLUSIVE" | "PERCENTAGE-AMOUNT";
276
- declare const RoundFormat: {
277
- readonly ROUND: "ROUND";
278
- readonly SPECIAL_ROUND: "SPECIAL_ROUND";
279
- readonly TO_FIXED: "TO_FIXED";
280
- readonly CEIL: "CEIL";
281
- readonly FLOOR: "FLOOR";
282
- readonly TRUNC: "TRUNC";
283
- readonly NONE: "NONE";
284
- };
285
- type RoundFormat = (typeof RoundFormat)[keyof typeof RoundFormat];
286
- interface ChildCalcInput {
287
- qty: number;
288
- rate: number;
289
- otherCharge?: number;
290
- addonPercentage?: number;
291
- discountMode?: DiscountMode;
292
- discountValue?: number;
293
- taxMethod?: TaxMethod;
294
- taxValue?: number;
295
- /** Absolute insurer-covered at line level */
296
- coPaymentType?: CoPayType;
297
- coPayValue?: number;
298
- coPayMethod?: "EXCLUSIVE" | "INCLUSIVE";
299
- }
300
- interface MasterAdditionalDiscount {
301
- mode: AdditionalDiscountMode;
302
- value: number;
303
- coPayMode?: CoPayMode;
304
- }
305
- interface CalcOptions {
306
- calculationMethod?: "STEP_WISE" | "FINAL_ONLY";
307
- lineRound?: RoundFormat;
308
- headerRound?: RoundFormat;
309
- precision?: number;
310
- }
311
- interface ChildCalculated {
312
- baseRate: number;
313
- subtotalAmount: number;
314
- otherChargeAmount: number;
315
- discountMode: DiscountMode;
316
- discountValue: number;
317
- discountAmount: number;
318
- taxMethod: TaxMethod;
319
- taxValue: number;
320
- taxAmount: number;
321
- grossAmount: number;
322
- netAmount: number;
323
- roundOffAmount: number;
324
- copayAmount: number;
325
- }
326
- interface MasterCalculated {
327
- additionalDiscountMode: AdditionalDiscountMode;
328
- additionalDiscountValue: number;
329
- subtotalAmount: number;
330
- otherChargeAmount: number;
331
- discountTotalAmount: number;
332
- taxAmount: number;
333
- grossAmount: number;
334
- netAmount: number;
335
- roundOffAmount: number;
336
- copayAmount: number;
337
- }
338
- interface BillingCalcResult {
339
- master: MasterCalculated;
340
- children: ChildCalculated[];
341
- }
342
-
343
- /**
344
- * calculateBillingFromChildren (master-level additional discount applied AFTER child calculations)
345
- * - Child: item discount -> tax (INCLUSIVE/EXCLUSIVE/NONE) -> coPay -> patient line net + line rounding
346
- * - Master: sum children, compute patientRawTotal = gross - Σcopay
347
- * apply master additional discount ON patientRawTotal (no propagation to children)
348
- * then header rounding
349
- */
350
- declare function calculateBillingFromChildren(inputs: ChildCalcInput[], masterExtra: MasterAdditionalDiscount, options?: CalcOptions): BillingCalcResult;
351
- declare function calculateSingleChild(it: ChildCalcInput, coPayMode: CoPayMode, options?: CalcOptions): ChildCalculated;
352
-
353
271
  interface CreateTransaction {
354
272
  field: string;
355
273
  changedFrom?: string | null;
@@ -429,6 +347,7 @@ declare const uinConfigService: (uinDeps: UinDeps) => {
429
347
 
430
348
  declare const toUINConfigDTO: (model: any) => UINConfigDTO;
431
349
 
350
+ type Priority = "high" | "normal" | "low";
432
351
  type Recipient = {
433
352
  email?: string;
434
353
  phone?: string;
@@ -441,6 +360,7 @@ type EmitPayload = {
441
360
  recipient: Recipient;
442
361
  data?: Record<string, any>;
443
362
  dataWp?: any[];
363
+ priority?: Priority;
444
364
  };
445
365
  type ILogger = winston.Logger | Console;
446
366
  type NotificationEmitterDeps = {
@@ -469,4 +389,4 @@ declare class NotificationEmitter {
469
389
  notifyNow(eventName: string, body: Omit<EmitPayload, "eventName">): Promise<void>;
470
390
  }
471
391
 
472
- export { type AdditionalDiscountMode, type BillingCalcResult, type CacheAdapter, type CalcOptions, type CalculationRes, type ChildCalcInput, type ChildCalculated, type CoPayMode, type CoPayType, type ColValue, type CommonExcelRequest, type CommonFilterRequest, type CommonServiceResponse, type Config, type Context, type CreateUINConfigRequest, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DiscountMode, type DropdownRequest, type DropdownRequestService, type DynamicShortCode, type EmitPayload, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type Mapper, type MasterAdditionalDiscount, type MasterCalculated, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type PaginatedResponse, type Recipient, RoundFormat, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type Store, type TaxMethod, type ToggleActive, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, calculateBillingFromChildren, calculateSingleChild, commonService, customOmit, findDifferences, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
392
+ export { type CacheAdapter, type CalculationRes, type ColValue, type CommonExcelRequest, type CommonFilterRequest, type CommonServiceResponse, type Config, type Context, type CreateUINConfigRequest, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DynamicShortCode, type EmitPayload, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type Mapper, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type PaginatedResponse, type Recipient, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type Store, type ToggleActive, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
package/dist/index.js CHANGED
@@ -31,9 +31,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  NotificationEmitter: () => NotificationEmitter,
34
- RoundFormat: () => RoundFormat,
35
- calculateBillingFromChildren: () => calculateBillingFromChildren,
36
- calculateSingleChild: () => calculateSingleChild,
37
34
  commonService: () => commonService,
38
35
  customOmit: () => customOmit,
39
36
  findDifferences: () => findDifferences,
@@ -1017,13 +1014,16 @@ var commonService = (serviceDeps) => {
1017
1014
  throw new ErrorHandler(404, generateErrorMessage("NOT_FOUND", `${shortCodeData.tableName}`));
1018
1015
  }
1019
1016
  if (shortCodeData.isDTO && dtoMapping[shortCodeData.shortCode]) {
1020
- let DtoResult;
1017
+ let dtoResult;
1021
1018
  if (shortCodeData.isSingleDto === void 0 || shortCodeData.isSingleDto === true) {
1022
- DtoResult = await dtoMapping[shortCodeData.shortCode](commonData);
1019
+ dtoResult = await dtoMapping[shortCodeData.shortCode](commonData);
1023
1020
  } else {
1024
- DtoResult = (await dtoMapping[shortCodeData.shortCode]([commonData]))?.[0];
1021
+ dtoResult = (await dtoMapping[shortCodeData.shortCode]([commonData]))?.[0];
1025
1022
  }
1026
- return DtoResult;
1023
+ if (!dtoResult) {
1024
+ throw new ErrorHandler(404, generateErrorMessage("NOT_FOUND", `${shortCodeData.tableName}`));
1025
+ }
1026
+ return dtoResult;
1027
1027
  }
1028
1028
  logger.info("exiting::fetch::service");
1029
1029
  return commonData;
@@ -1118,156 +1118,6 @@ var commonService = (serviceDeps) => {
1118
1118
  };
1119
1119
  };
1120
1120
 
1121
- // src/types/calculation.ts
1122
- var RoundFormat = {
1123
- ROUND: "ROUND",
1124
- SPECIAL_ROUND: "SPECIAL_ROUND",
1125
- TO_FIXED: "TO_FIXED",
1126
- CEIL: "CEIL",
1127
- FLOOR: "FLOOR",
1128
- TRUNC: "TRUNC",
1129
- NONE: "NONE"
1130
- };
1131
-
1132
- // src/utils/calculation.utils.ts
1133
- function applyRound(value, format, precision = 2) {
1134
- switch (format) {
1135
- case RoundFormat.NONE:
1136
- return value;
1137
- case RoundFormat.ROUND:
1138
- return Math.round(value);
1139
- case RoundFormat.SPECIAL_ROUND:
1140
- return value < 1 ? Math.ceil(value) : Math.round(value);
1141
- case RoundFormat.CEIL:
1142
- return Math.ceil(value);
1143
- case RoundFormat.FLOOR:
1144
- return Math.floor(value);
1145
- case RoundFormat.TRUNC:
1146
- return Math.trunc(value);
1147
- case RoundFormat.TO_FIXED:
1148
- default:
1149
- return Number(value.toFixed(Math.max(0, precision | 0)));
1150
- }
1151
- }
1152
- var maybeStep = (v, stepwise, fmt, p) => stepwise ? applyRound(v, fmt, p) : v;
1153
- function clamp(n, min, max) {
1154
- return Math.max(min, Math.min(max, n));
1155
- }
1156
- var percentage = (amount, percentage2) => {
1157
- return amount * percentage2 / 100;
1158
- };
1159
- function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
1160
- const stepwise = options.calculationMethod === "STEP_WISE";
1161
- const lineFmt = options.lineRound ?? RoundFormat.TO_FIXED;
1162
- const headFmt = options.headerRound ?? lineFmt;
1163
- const precision = options.precision ?? 2;
1164
- const children = inputs.map((it) => {
1165
- return calculateSingleChild(it, masterExtra.coPayMode ?? "PERCENTAGE-AMOUNT", options);
1166
- });
1167
- const subtotalAmount = children.reduce((a, c) => a + c.subtotalAmount, 0);
1168
- const otherChargeAmount = children.reduce((a, c) => a + c.otherChargeAmount, 0);
1169
- const itemDiscountSum = children.reduce((a, c) => a + c.discountAmount, 0);
1170
- const taxAmount = children.reduce((a, c) => a + c.taxAmount, 0);
1171
- const grossAmount = children.reduce((a, c) => a + c.grossAmount, 0);
1172
- const copayAmount = children.reduce((a, c) => a + c.copayAmount, 0);
1173
- const patientRawTotal = grossAmount - copayAmount;
1174
- let masterExtraApplied = 0;
1175
- if (masterExtra.mode === "PERCENTAGE") {
1176
- masterExtraApplied = percentage(patientRawTotal, masterExtra.value);
1177
- } else if (masterExtra.mode === "AMOUNT") {
1178
- masterExtraApplied = Math.min(masterExtra.value, patientRawTotal);
1179
- }
1180
- masterExtraApplied = maybeStep(masterExtraApplied, stepwise, headFmt, precision);
1181
- const discountTotalAmount = maybeStep(itemDiscountSum + masterExtraApplied, stepwise, headFmt, precision);
1182
- const patientAfterExtra = applyRound(Math.max(0, patientRawTotal - masterExtraApplied), "TO_FIXED", 2);
1183
- const netAmount = applyRound(patientAfterExtra, headFmt, precision);
1184
- const roundOffAmount = netAmount - patientAfterExtra;
1185
- const master = {
1186
- additionalDiscountMode: masterExtra.mode,
1187
- additionalDiscountValue: masterExtra.value,
1188
- subtotalAmount: applyRound(subtotalAmount, headFmt, precision),
1189
- otherChargeAmount: applyRound(otherChargeAmount, headFmt, precision),
1190
- discountTotalAmount: applyRound(discountTotalAmount, headFmt, precision),
1191
- // includes master extra
1192
- taxAmount: applyRound(taxAmount, headFmt, precision),
1193
- grossAmount: applyRound(grossAmount, headFmt, precision),
1194
- netAmount,
1195
- // patient payable after master extra + rounding
1196
- roundOffAmount: applyRound(roundOffAmount, "TO_FIXED", 2),
1197
- // rounded - raw
1198
- copayAmount: applyRound(copayAmount, headFmt, precision)
1199
- // Σ line copay (insurer covered)
1200
- };
1201
- return { master, children };
1202
- }
1203
- function calculateSingleChild(it, coPayMode, options = {}) {
1204
- const stepwise = options.calculationMethod === "STEP_WISE";
1205
- const lineFmt = options.lineRound ?? RoundFormat.TO_FIXED;
1206
- const precision = options.precision ?? 2;
1207
- let baseRate = it.rate;
1208
- if (it.addonPercentage) {
1209
- baseRate = baseRate + percentage(baseRate, it.addonPercentage);
1210
- baseRate = applyRound(baseRate, lineFmt, precision);
1211
- }
1212
- const subtotal = applyRound(it.qty * baseRate, lineFmt, precision);
1213
- const other = applyRound(it.otherCharge ?? 0, lineFmt, precision);
1214
- const basePreTax = applyRound(subtotal + other, lineFmt, precision);
1215
- let copayAmount = 0;
1216
- if (coPayMode === "PERCENTAGE-AMOUNT") {
1217
- const copayType = it.coPaymentType ?? "AMOUNT";
1218
- const copayValue = it.coPayValue ?? 0;
1219
- copayAmount = copayType === "PERCENTAGE" ? percentage(subtotal, copayValue) : Math.min(copayValue, subtotal);
1220
- }
1221
- const dMode = it.discountMode ?? "AMOUNT";
1222
- const dVal = it.discountValue ?? 0;
1223
- const tMethod = it.taxMethod ?? "NONE";
1224
- const tVal = Math.max(0, it.taxValue ?? 0);
1225
- let baseAfterTaxDisc = basePreTax;
1226
- if (tMethod === "INCLUSIVE") {
1227
- const inclusiveTaxMultiplier = (100 + tVal) / 100;
1228
- baseAfterTaxDisc = basePreTax / inclusiveTaxMultiplier;
1229
- }
1230
- baseAfterTaxDisc = maybeStep(baseAfterTaxDisc, stepwise, lineFmt, precision);
1231
- const inclDiff = applyRound(basePreTax - baseAfterTaxDisc, lineFmt, precision);
1232
- let discountValue = 0;
1233
- if (dMode === "AMOUNT") {
1234
- discountValue = dVal;
1235
- } else if (dMode === "PERCENTAGE") {
1236
- discountValue = percentage(baseAfterTaxDisc, dVal);
1237
- }
1238
- discountValue = maybeStep(discountValue, stepwise, lineFmt, precision);
1239
- let afterDisc = Math.max(0, baseAfterTaxDisc - discountValue);
1240
- afterDisc = maybeStep(afterDisc, stepwise, lineFmt, precision);
1241
- let calculatedTax = percentage(afterDisc, tVal);
1242
- calculatedTax = maybeStep(calculatedTax, stepwise, lineFmt, precision);
1243
- let grossAmount = afterDisc + calculatedTax;
1244
- grossAmount = maybeStep(grossAmount, stepwise, lineFmt, precision);
1245
- if (coPayMode === "EXCLUSIVE-INCLUSIVE" && it.coPayMethod === "INCLUSIVE") {
1246
- copayAmount = grossAmount;
1247
- }
1248
- copayAmount = applyRound(copayAmount, lineFmt, precision);
1249
- const copay = clamp(Math.max(0, copayAmount), 0, grossAmount);
1250
- const patientRaw = applyRound(grossAmount - copay, RoundFormat.TO_FIXED, 2);
1251
- const patientRounded = applyRound(patientRaw, lineFmt, precision);
1252
- const lineRoundOff = applyRound(patientRounded - patientRaw, RoundFormat.TO_FIXED, 2);
1253
- return {
1254
- // include baseRate if your ChildCalculated type has it (as in your bulk function)
1255
- baseRate: applyRound(baseRate, lineFmt, precision),
1256
- subtotalAmount: applyRound(subtotal + other - inclDiff, lineFmt, precision),
1257
- otherChargeAmount: other,
1258
- discountMode: dMode,
1259
- discountValue: dVal,
1260
- discountAmount: applyRound(discountValue, lineFmt, precision),
1261
- taxMethod: tMethod,
1262
- taxValue: tVal,
1263
- taxAmount: applyRound(calculatedTax, lineFmt, precision),
1264
- grossAmount: applyRound(grossAmount, lineFmt, precision),
1265
- netAmount: patientRounded,
1266
- roundOffAmount: lineRoundOff,
1267
- copayAmount: copay
1268
- };
1269
- }
1270
-
1271
1121
  // src/utils/audit.utils.ts
1272
1122
  function isValidDate(value) {
1273
1123
  if (value instanceof Date) {
@@ -1657,7 +1507,8 @@ var EmailProvider = class {
1657
1507
  body,
1658
1508
  recipient,
1659
1509
  subject,
1660
- attachments = []
1510
+ attachments = [],
1511
+ priority = "normal"
1661
1512
  }) {
1662
1513
  if (!recipient.email) {
1663
1514
  return {
@@ -1696,8 +1547,9 @@ var EmailProvider = class {
1696
1547
  subject,
1697
1548
  html: body,
1698
1549
  // The interpolated HTML body
1699
- attachments
1550
+ attachments,
1700
1551
  // Optional attachments
1552
+ priority
1701
1553
  });
1702
1554
  this.logger.info(`Email sent to ${recipient.email} with subject: ${subject}`);
1703
1555
  return {
@@ -1979,7 +1831,8 @@ var NotificationService = class {
1979
1831
  eventConfigId: cfg.id,
1980
1832
  evt,
1981
1833
  subject: msg.subject,
1982
- body: msg.body
1834
+ body: msg.body,
1835
+ priority: evt.priority
1983
1836
  })
1984
1837
  );
1985
1838
  }
@@ -2032,7 +1885,8 @@ var NotificationService = class {
2032
1885
  const result = await args.provider.send({
2033
1886
  subject: args.subject,
2034
1887
  body: args.body,
2035
- recipient: args.evt.recipient
1888
+ recipient: args.evt.recipient,
1889
+ priority: args.priority
2036
1890
  });
2037
1891
  await this.prisma.eventNotificationAudit.create({
2038
1892
  data: {
@@ -2131,9 +1985,6 @@ var NotificationEmitter = class {
2131
1985
  // Annotate the CommonJS export names for ESM import in node:
2132
1986
  0 && (module.exports = {
2133
1987
  NotificationEmitter,
2134
- RoundFormat,
2135
- calculateBillingFromChildren,
2136
- calculateSingleChild,
2137
1988
  commonService,
2138
1989
  customOmit,
2139
1990
  findDifferences,
package/dist/index.mjs CHANGED
@@ -968,13 +968,16 @@ var commonService = (serviceDeps) => {
968
968
  throw new ErrorHandler(404, generateErrorMessage("NOT_FOUND", `${shortCodeData.tableName}`));
969
969
  }
970
970
  if (shortCodeData.isDTO && dtoMapping[shortCodeData.shortCode]) {
971
- let DtoResult;
971
+ let dtoResult;
972
972
  if (shortCodeData.isSingleDto === void 0 || shortCodeData.isSingleDto === true) {
973
- DtoResult = await dtoMapping[shortCodeData.shortCode](commonData);
973
+ dtoResult = await dtoMapping[shortCodeData.shortCode](commonData);
974
974
  } else {
975
- DtoResult = (await dtoMapping[shortCodeData.shortCode]([commonData]))?.[0];
975
+ dtoResult = (await dtoMapping[shortCodeData.shortCode]([commonData]))?.[0];
976
976
  }
977
- return DtoResult;
977
+ if (!dtoResult) {
978
+ throw new ErrorHandler(404, generateErrorMessage("NOT_FOUND", `${shortCodeData.tableName}`));
979
+ }
980
+ return dtoResult;
978
981
  }
979
982
  logger.info("exiting::fetch::service");
980
983
  return commonData;
@@ -1069,156 +1072,6 @@ var commonService = (serviceDeps) => {
1069
1072
  };
1070
1073
  };
1071
1074
 
1072
- // src/types/calculation.ts
1073
- var RoundFormat = {
1074
- ROUND: "ROUND",
1075
- SPECIAL_ROUND: "SPECIAL_ROUND",
1076
- TO_FIXED: "TO_FIXED",
1077
- CEIL: "CEIL",
1078
- FLOOR: "FLOOR",
1079
- TRUNC: "TRUNC",
1080
- NONE: "NONE"
1081
- };
1082
-
1083
- // src/utils/calculation.utils.ts
1084
- function applyRound(value, format, precision = 2) {
1085
- switch (format) {
1086
- case RoundFormat.NONE:
1087
- return value;
1088
- case RoundFormat.ROUND:
1089
- return Math.round(value);
1090
- case RoundFormat.SPECIAL_ROUND:
1091
- return value < 1 ? Math.ceil(value) : Math.round(value);
1092
- case RoundFormat.CEIL:
1093
- return Math.ceil(value);
1094
- case RoundFormat.FLOOR:
1095
- return Math.floor(value);
1096
- case RoundFormat.TRUNC:
1097
- return Math.trunc(value);
1098
- case RoundFormat.TO_FIXED:
1099
- default:
1100
- return Number(value.toFixed(Math.max(0, precision | 0)));
1101
- }
1102
- }
1103
- var maybeStep = (v, stepwise, fmt, p) => stepwise ? applyRound(v, fmt, p) : v;
1104
- function clamp(n, min, max) {
1105
- return Math.max(min, Math.min(max, n));
1106
- }
1107
- var percentage = (amount, percentage2) => {
1108
- return amount * percentage2 / 100;
1109
- };
1110
- function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
1111
- const stepwise = options.calculationMethod === "STEP_WISE";
1112
- const lineFmt = options.lineRound ?? RoundFormat.TO_FIXED;
1113
- const headFmt = options.headerRound ?? lineFmt;
1114
- const precision = options.precision ?? 2;
1115
- const children = inputs.map((it) => {
1116
- return calculateSingleChild(it, masterExtra.coPayMode ?? "PERCENTAGE-AMOUNT", options);
1117
- });
1118
- const subtotalAmount = children.reduce((a, c) => a + c.subtotalAmount, 0);
1119
- const otherChargeAmount = children.reduce((a, c) => a + c.otherChargeAmount, 0);
1120
- const itemDiscountSum = children.reduce((a, c) => a + c.discountAmount, 0);
1121
- const taxAmount = children.reduce((a, c) => a + c.taxAmount, 0);
1122
- const grossAmount = children.reduce((a, c) => a + c.grossAmount, 0);
1123
- const copayAmount = children.reduce((a, c) => a + c.copayAmount, 0);
1124
- const patientRawTotal = grossAmount - copayAmount;
1125
- let masterExtraApplied = 0;
1126
- if (masterExtra.mode === "PERCENTAGE") {
1127
- masterExtraApplied = percentage(patientRawTotal, masterExtra.value);
1128
- } else if (masterExtra.mode === "AMOUNT") {
1129
- masterExtraApplied = Math.min(masterExtra.value, patientRawTotal);
1130
- }
1131
- masterExtraApplied = maybeStep(masterExtraApplied, stepwise, headFmt, precision);
1132
- const discountTotalAmount = maybeStep(itemDiscountSum + masterExtraApplied, stepwise, headFmt, precision);
1133
- const patientAfterExtra = applyRound(Math.max(0, patientRawTotal - masterExtraApplied), "TO_FIXED", 2);
1134
- const netAmount = applyRound(patientAfterExtra, headFmt, precision);
1135
- const roundOffAmount = netAmount - patientAfterExtra;
1136
- const master = {
1137
- additionalDiscountMode: masterExtra.mode,
1138
- additionalDiscountValue: masterExtra.value,
1139
- subtotalAmount: applyRound(subtotalAmount, headFmt, precision),
1140
- otherChargeAmount: applyRound(otherChargeAmount, headFmt, precision),
1141
- discountTotalAmount: applyRound(discountTotalAmount, headFmt, precision),
1142
- // includes master extra
1143
- taxAmount: applyRound(taxAmount, headFmt, precision),
1144
- grossAmount: applyRound(grossAmount, headFmt, precision),
1145
- netAmount,
1146
- // patient payable after master extra + rounding
1147
- roundOffAmount: applyRound(roundOffAmount, "TO_FIXED", 2),
1148
- // rounded - raw
1149
- copayAmount: applyRound(copayAmount, headFmt, precision)
1150
- // Σ line copay (insurer covered)
1151
- };
1152
- return { master, children };
1153
- }
1154
- function calculateSingleChild(it, coPayMode, options = {}) {
1155
- const stepwise = options.calculationMethod === "STEP_WISE";
1156
- const lineFmt = options.lineRound ?? RoundFormat.TO_FIXED;
1157
- const precision = options.precision ?? 2;
1158
- let baseRate = it.rate;
1159
- if (it.addonPercentage) {
1160
- baseRate = baseRate + percentage(baseRate, it.addonPercentage);
1161
- baseRate = applyRound(baseRate, lineFmt, precision);
1162
- }
1163
- const subtotal = applyRound(it.qty * baseRate, lineFmt, precision);
1164
- const other = applyRound(it.otherCharge ?? 0, lineFmt, precision);
1165
- const basePreTax = applyRound(subtotal + other, lineFmt, precision);
1166
- let copayAmount = 0;
1167
- if (coPayMode === "PERCENTAGE-AMOUNT") {
1168
- const copayType = it.coPaymentType ?? "AMOUNT";
1169
- const copayValue = it.coPayValue ?? 0;
1170
- copayAmount = copayType === "PERCENTAGE" ? percentage(subtotal, copayValue) : Math.min(copayValue, subtotal);
1171
- }
1172
- const dMode = it.discountMode ?? "AMOUNT";
1173
- const dVal = it.discountValue ?? 0;
1174
- const tMethod = it.taxMethod ?? "NONE";
1175
- const tVal = Math.max(0, it.taxValue ?? 0);
1176
- let baseAfterTaxDisc = basePreTax;
1177
- if (tMethod === "INCLUSIVE") {
1178
- const inclusiveTaxMultiplier = (100 + tVal) / 100;
1179
- baseAfterTaxDisc = basePreTax / inclusiveTaxMultiplier;
1180
- }
1181
- baseAfterTaxDisc = maybeStep(baseAfterTaxDisc, stepwise, lineFmt, precision);
1182
- const inclDiff = applyRound(basePreTax - baseAfterTaxDisc, lineFmt, precision);
1183
- let discountValue = 0;
1184
- if (dMode === "AMOUNT") {
1185
- discountValue = dVal;
1186
- } else if (dMode === "PERCENTAGE") {
1187
- discountValue = percentage(baseAfterTaxDisc, dVal);
1188
- }
1189
- discountValue = maybeStep(discountValue, stepwise, lineFmt, precision);
1190
- let afterDisc = Math.max(0, baseAfterTaxDisc - discountValue);
1191
- afterDisc = maybeStep(afterDisc, stepwise, lineFmt, precision);
1192
- let calculatedTax = percentage(afterDisc, tVal);
1193
- calculatedTax = maybeStep(calculatedTax, stepwise, lineFmt, precision);
1194
- let grossAmount = afterDisc + calculatedTax;
1195
- grossAmount = maybeStep(grossAmount, stepwise, lineFmt, precision);
1196
- if (coPayMode === "EXCLUSIVE-INCLUSIVE" && it.coPayMethod === "INCLUSIVE") {
1197
- copayAmount = grossAmount;
1198
- }
1199
- copayAmount = applyRound(copayAmount, lineFmt, precision);
1200
- const copay = clamp(Math.max(0, copayAmount), 0, grossAmount);
1201
- const patientRaw = applyRound(grossAmount - copay, RoundFormat.TO_FIXED, 2);
1202
- const patientRounded = applyRound(patientRaw, lineFmt, precision);
1203
- const lineRoundOff = applyRound(patientRounded - patientRaw, RoundFormat.TO_FIXED, 2);
1204
- return {
1205
- // include baseRate if your ChildCalculated type has it (as in your bulk function)
1206
- baseRate: applyRound(baseRate, lineFmt, precision),
1207
- subtotalAmount: applyRound(subtotal + other - inclDiff, lineFmt, precision),
1208
- otherChargeAmount: other,
1209
- discountMode: dMode,
1210
- discountValue: dVal,
1211
- discountAmount: applyRound(discountValue, lineFmt, precision),
1212
- taxMethod: tMethod,
1213
- taxValue: tVal,
1214
- taxAmount: applyRound(calculatedTax, lineFmt, precision),
1215
- grossAmount: applyRound(grossAmount, lineFmt, precision),
1216
- netAmount: patientRounded,
1217
- roundOffAmount: lineRoundOff,
1218
- copayAmount: copay
1219
- };
1220
- }
1221
-
1222
1075
  // src/utils/audit.utils.ts
1223
1076
  function isValidDate(value) {
1224
1077
  if (value instanceof Date) {
@@ -1608,7 +1461,8 @@ var EmailProvider = class {
1608
1461
  body,
1609
1462
  recipient,
1610
1463
  subject,
1611
- attachments = []
1464
+ attachments = [],
1465
+ priority = "normal"
1612
1466
  }) {
1613
1467
  if (!recipient.email) {
1614
1468
  return {
@@ -1647,8 +1501,9 @@ var EmailProvider = class {
1647
1501
  subject,
1648
1502
  html: body,
1649
1503
  // The interpolated HTML body
1650
- attachments
1504
+ attachments,
1651
1505
  // Optional attachments
1506
+ priority
1652
1507
  });
1653
1508
  this.logger.info(`Email sent to ${recipient.email} with subject: ${subject}`);
1654
1509
  return {
@@ -1930,7 +1785,8 @@ var NotificationService = class {
1930
1785
  eventConfigId: cfg.id,
1931
1786
  evt,
1932
1787
  subject: msg.subject,
1933
- body: msg.body
1788
+ body: msg.body,
1789
+ priority: evt.priority
1934
1790
  })
1935
1791
  );
1936
1792
  }
@@ -1983,7 +1839,8 @@ var NotificationService = class {
1983
1839
  const result = await args.provider.send({
1984
1840
  subject: args.subject,
1985
1841
  body: args.body,
1986
- recipient: args.evt.recipient
1842
+ recipient: args.evt.recipient,
1843
+ priority: args.priority
1987
1844
  });
1988
1845
  await this.prisma.eventNotificationAudit.create({
1989
1846
  data: {
@@ -2081,9 +1938,6 @@ var NotificationEmitter = class {
2081
1938
  };
2082
1939
  export {
2083
1940
  NotificationEmitter,
2084
- RoundFormat,
2085
- calculateBillingFromChildren,
2086
- calculateSingleChild,
2087
1941
  commonService,
2088
1942
  customOmit,
2089
1943
  findDifferences,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "av6-core",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",