av6-core 1.0.25 → 1.1.1

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
@@ -80,6 +80,7 @@ type DynamicShortCode = {
80
80
  tableName: string;
81
81
  isDTO?: boolean;
82
82
  isCacheable?: boolean;
83
+ isSingleDto?: boolean;
83
84
  isDropDown?: boolean;
84
85
  permission?: string | null;
85
86
  whereClause?: JsonValue | null;
@@ -139,6 +140,7 @@ interface FixedSearchRequestService<T extends DynamicShortCode> extends FixedSea
139
140
  interface FetchRequest {
140
141
  shortCode: string;
141
142
  id: number;
143
+ includes?: Record<string, unknown>;
142
144
  }
143
145
  interface FetchRequestRepository<T extends DynamicShortCode> extends FetchRequest {
144
146
  shortCodeData: T;
@@ -178,7 +180,7 @@ interface CalculationRes {
178
180
  netTax: number;
179
181
  totalAmount: number;
180
182
  }
181
- type DtoMappingFunction = (data: unknown) => unknown;
183
+ type DtoMappingFunction = (data: any) => any;
182
184
  interface Helpers {
183
185
  generateErrorMessage(type: keyof typeof ErrorMessageType, ...variables: string[]): string;
184
186
  ErrorHandler: new (status: number, message: string, errors?: ValidationErrorItem[]) => Error;
@@ -346,6 +348,7 @@ interface BillingCalcResult {
346
348
  * then header rounding
347
349
  */
348
350
  declare function calculateBillingFromChildren(inputs: ChildCalcInput[], masterExtra: MasterAdditionalDiscount, options?: CalcOptions): BillingCalcResult;
351
+ declare function calculateSingleChild(it: ChildCalcInput, coPayMode: CoPayMode, options?: CalcOptions): ChildCalculated;
349
352
 
350
353
  interface CreateTransaction {
351
354
  field: string;
@@ -466,4 +469,4 @@ declare class NotificationEmitter {
466
469
  notifyNow(eventName: string, body: Omit<EmitPayload, "eventName">): Promise<void>;
467
470
  }
468
471
 
469
- 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, commonService, customOmit, findDifferences, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
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 };
package/dist/index.d.ts CHANGED
@@ -80,6 +80,7 @@ type DynamicShortCode = {
80
80
  tableName: string;
81
81
  isDTO?: boolean;
82
82
  isCacheable?: boolean;
83
+ isSingleDto?: boolean;
83
84
  isDropDown?: boolean;
84
85
  permission?: string | null;
85
86
  whereClause?: JsonValue | null;
@@ -139,6 +140,7 @@ interface FixedSearchRequestService<T extends DynamicShortCode> extends FixedSea
139
140
  interface FetchRequest {
140
141
  shortCode: string;
141
142
  id: number;
143
+ includes?: Record<string, unknown>;
142
144
  }
143
145
  interface FetchRequestRepository<T extends DynamicShortCode> extends FetchRequest {
144
146
  shortCodeData: T;
@@ -178,7 +180,7 @@ interface CalculationRes {
178
180
  netTax: number;
179
181
  totalAmount: number;
180
182
  }
181
- type DtoMappingFunction = (data: unknown) => unknown;
183
+ type DtoMappingFunction = (data: any) => any;
182
184
  interface Helpers {
183
185
  generateErrorMessage(type: keyof typeof ErrorMessageType, ...variables: string[]): string;
184
186
  ErrorHandler: new (status: number, message: string, errors?: ValidationErrorItem[]) => Error;
@@ -346,6 +348,7 @@ interface BillingCalcResult {
346
348
  * then header rounding
347
349
  */
348
350
  declare function calculateBillingFromChildren(inputs: ChildCalcInput[], masterExtra: MasterAdditionalDiscount, options?: CalcOptions): BillingCalcResult;
351
+ declare function calculateSingleChild(it: ChildCalcInput, coPayMode: CoPayMode, options?: CalcOptions): ChildCalculated;
349
352
 
350
353
  interface CreateTransaction {
351
354
  field: string;
@@ -466,4 +469,4 @@ declare class NotificationEmitter {
466
469
  notifyNow(eventName: string, body: Omit<EmitPayload, "eventName">): Promise<void>;
467
470
  }
468
471
 
469
- 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, commonService, customOmit, findDifferences, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
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 };
package/dist/index.js CHANGED
@@ -33,6 +33,7 @@ __export(index_exports, {
33
33
  NotificationEmitter: () => NotificationEmitter,
34
34
  RoundFormat: () => RoundFormat,
35
35
  calculateBillingFromChildren: () => calculateBillingFromChildren,
36
+ calculateSingleChild: () => calculateSingleChild,
36
37
  commonService: () => commonService,
37
38
  customOmit: () => customOmit,
38
39
  findDifferences: () => findDifferences,
@@ -305,7 +306,12 @@ var commonRepository = (serviceDeps) => {
305
306
  const totalPages = Math.ceil(totalRecords / pageSize);
306
307
  const DTOClass = dtoMapping[shortCodeData.shortCode];
307
308
  if (shortCodeData.isDTO && DTOClass) {
308
- const DTOs = await Promise.all(results.map((record) => DTOClass(record)));
309
+ let DTOs = [];
310
+ if (shortCodeData.isSingleDto === void 0 || shortCodeData.isSingleDto === true) {
311
+ DTOs = await Promise.all(results.map((record) => DTOClass(record)));
312
+ } else {
313
+ DTOs = await DTOClass(results);
314
+ }
309
315
  return {
310
316
  data: DTOs,
311
317
  totalRecords,
@@ -381,7 +387,7 @@ var commonRepository = (serviceDeps) => {
381
387
  logger.info("exiting::commonSearch::repository");
382
388
  return results;
383
389
  },
384
- async commonFetch({ id, shortCodeData }) {
390
+ async commonFetch({ id, shortCodeData, includes }) {
385
391
  logger.info("entering::commonFetch::repository");
386
392
  const tableName = shortCodeData.tableName;
387
393
  const model = db[tableName];
@@ -389,7 +395,8 @@ var commonRepository = (serviceDeps) => {
389
395
  throw new ErrorHandler(400, generateErrorMessage("INVALID_TABLE"));
390
396
  }
391
397
  const results = model.findUnique({
392
- where: { id, isActive: true }
398
+ where: { id, isActive: true },
399
+ include: includes ? includes : void 0
393
400
  });
394
401
  logger.info("exiting::commonFetch::repository");
395
402
  return results;
@@ -596,7 +603,12 @@ var commonRepository = (serviceDeps) => {
596
603
  const totalPages = Math.ceil(totalRecords / pageSize);
597
604
  const DTOClass = dtoMapping[shortCodeData.shortCode];
598
605
  if (shortCodeData.isDTO && DTOClass) {
599
- const DTOs = await Promise.all(results.map((record) => DTOClass(record)));
606
+ let DTOs = [];
607
+ if (shortCodeData.isSingleDto === void 0 || shortCodeData.isSingleDto === true) {
608
+ DTOs = await Promise.all(results.map((record) => DTOClass(record)));
609
+ } else {
610
+ DTOs = await DTOClass(results);
611
+ }
600
612
  return {
601
613
  data: DTOs,
602
614
  totalRecords,
@@ -657,7 +669,12 @@ var commonRepository = (serviceDeps) => {
657
669
  });
658
670
  const DTOClass = dtoMapping[shortCodeData.shortCode];
659
671
  if (shortCodeData.isDTO && DTOClass) {
660
- const DTOs = await Promise.all(results.map((record) => DTOClass(record)));
672
+ let DTOs = [];
673
+ if (shortCodeData.isSingleDto === void 0 || shortCodeData.isSingleDto === true) {
674
+ DTOs = await Promise.all(results.map((record) => DTOClass(record)));
675
+ } else {
676
+ DTOs = await DTOClass(results);
677
+ }
661
678
  return {
662
679
  data: DTOs,
663
680
  totalRecords
@@ -981,7 +998,7 @@ var commonService = (serviceDeps) => {
981
998
  logger.info("entering::fetch::service");
982
999
  const shortCodeData = fetchParams.shortCodeData;
983
1000
  let commonData;
984
- if (shortCodeData.isCacheable && fetchParams.shortCode !== "UIN_CONFIG") {
1001
+ if (shortCodeData.isCacheable && fetchParams.shortCode !== "UIN_CONFIG" && !fetchParams.includes) {
985
1002
  commonData = await getCacheById(
986
1003
  `${REDIS_PREFIX}${CACHE_KEY_NAME}:${shortCodeData.tableName}:all`,
987
1004
  fetchParams.id
@@ -1000,7 +1017,12 @@ var commonService = (serviceDeps) => {
1000
1017
  throw new ErrorHandler(404, generateErrorMessage("NOT_FOUND", `${shortCodeData.tableName}`));
1001
1018
  }
1002
1019
  if (shortCodeData.isDTO && dtoMapping[shortCodeData.shortCode]) {
1003
- const DtoResult = await dtoMapping[shortCodeData.shortCode](commonData);
1020
+ let DtoResult;
1021
+ if (shortCodeData.isSingleDto === void 0 || shortCodeData.isSingleDto === true) {
1022
+ DtoResult = await dtoMapping[shortCodeData.shortCode](commonData);
1023
+ } else {
1024
+ DtoResult = (await dtoMapping[shortCodeData.shortCode]([commonData]))?.[0];
1025
+ }
1004
1026
  return DtoResult;
1005
1027
  }
1006
1028
  logger.info("exiting::fetch::service");
@@ -1140,71 +1162,7 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
1140
1162
  const headFmt = options.headerRound ?? lineFmt;
1141
1163
  const precision = options.precision ?? 2;
1142
1164
  const children = inputs.map((it) => {
1143
- let baseRate = it.rate;
1144
- if (it.addonPercentage) {
1145
- baseRate = baseRate + percentage(baseRate, it.addonPercentage);
1146
- baseRate = applyRound(baseRate, lineFmt, precision);
1147
- }
1148
- const subtotal = applyRound(it.qty * baseRate, lineFmt, precision);
1149
- const other = applyRound(it.otherCharge ?? 0, lineFmt, precision);
1150
- const basePreTax = applyRound(subtotal + other, lineFmt, precision);
1151
- let copayAmount2 = 0;
1152
- if (masterExtra.coPayMode === "PERCENTAGE-AMOUNT") {
1153
- const copayType = it.coPaymentType ?? "AMOUNT";
1154
- const copayValue = it.coPayValue ?? 0;
1155
- copayAmount2 = copayType === "PERCENTAGE" ? percentage(subtotal, copayValue) : Math.min(copayValue, subtotal);
1156
- }
1157
- const dMode = it.discountMode ?? "AMOUNT";
1158
- const dVal = it.discountValue ?? 0;
1159
- const tMethod = it.taxMethod ?? "NONE";
1160
- const tVal = Math.max(0, it.taxValue ?? 0);
1161
- let baseAfterTaxDisc = basePreTax;
1162
- let discountValue = 0;
1163
- if (tMethod === "INCLUSIVE") {
1164
- const inclusiveTaxMultiplier = (100 + tVal) / 100;
1165
- baseAfterTaxDisc = basePreTax / inclusiveTaxMultiplier;
1166
- }
1167
- baseAfterTaxDisc = maybeStep(baseAfterTaxDisc, stepwise, lineFmt, precision);
1168
- const inxInclusiveDiff = applyRound(basePreTax - baseAfterTaxDisc, lineFmt, precision);
1169
- if (dMode === "AMOUNT") {
1170
- discountValue = dVal;
1171
- } else if (dMode === "PERCENTAGE") {
1172
- discountValue = percentage(baseAfterTaxDisc, dVal);
1173
- }
1174
- discountValue = maybeStep(discountValue, stepwise, lineFmt, precision);
1175
- let afterDisc = Math.max(0, baseAfterTaxDisc - discountValue);
1176
- afterDisc = maybeStep(afterDisc, stepwise, lineFmt, precision);
1177
- let calculatedTax = percentage(afterDisc, tVal);
1178
- calculatedTax = maybeStep(calculatedTax, stepwise, lineFmt, precision);
1179
- let grossAmount2 = afterDisc + calculatedTax;
1180
- grossAmount2 = maybeStep(grossAmount2, stepwise, lineFmt, precision);
1181
- if (masterExtra.coPayMode === "EXCLUSIVE-INCLUSIVE" && it.coPayMethod === "INCLUSIVE") {
1182
- copayAmount2 = grossAmount2;
1183
- }
1184
- copayAmount2 = applyRound(copayAmount2, lineFmt, precision);
1185
- const copay = clamp(Math.max(0, copayAmount2), 0, grossAmount2);
1186
- const patientRaw = applyRound(grossAmount2 - copay, "TO_FIXED", 2);
1187
- const patientRounded = applyRound(patientRaw, lineFmt, precision);
1188
- const lineRoundOff = patientRounded - patientRaw;
1189
- return {
1190
- baseRate: applyRound(baseRate, lineFmt, precision),
1191
- subtotalAmount: applyRound(subtotal + other - inxInclusiveDiff, lineFmt, precision),
1192
- otherChargeAmount: other,
1193
- discountMode: dMode,
1194
- discountValue: dVal,
1195
- discountAmount: applyRound(discountValue, lineFmt, precision),
1196
- // item-only discount
1197
- taxMethod: tMethod,
1198
- taxValue: tVal,
1199
- taxAmount: applyRound(calculatedTax, lineFmt, precision),
1200
- grossAmount: applyRound(grossAmount2, lineFmt, precision),
1201
- netAmount: patientRounded,
1202
- // patient payable at line
1203
- roundOffAmount: applyRound(lineRoundOff, "TO_FIXED", 2),
1204
- // rounded - raw
1205
- copayAmount: copay
1206
- // insurer covered at line
1207
- };
1165
+ return calculateSingleChild(it, masterExtra.coPayMode ?? "PERCENTAGE-AMOUNT", options);
1208
1166
  });
1209
1167
  const subtotalAmount = children.reduce((a, c) => a + c.subtotalAmount, 0);
1210
1168
  const otherChargeAmount = children.reduce((a, c) => a + c.otherChargeAmount, 0);
@@ -1242,6 +1200,73 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
1242
1200
  };
1243
1201
  return { master, children };
1244
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
+ }
1245
1270
 
1246
1271
  // src/utils/audit.utils.ts
1247
1272
  function isValidDate(value) {
@@ -2108,6 +2133,7 @@ var NotificationEmitter = class {
2108
2133
  NotificationEmitter,
2109
2134
  RoundFormat,
2110
2135
  calculateBillingFromChildren,
2136
+ calculateSingleChild,
2111
2137
  commonService,
2112
2138
  customOmit,
2113
2139
  findDifferences,
package/dist/index.mjs CHANGED
@@ -257,7 +257,12 @@ var commonRepository = (serviceDeps) => {
257
257
  const totalPages = Math.ceil(totalRecords / pageSize);
258
258
  const DTOClass = dtoMapping[shortCodeData.shortCode];
259
259
  if (shortCodeData.isDTO && DTOClass) {
260
- const DTOs = await Promise.all(results.map((record) => DTOClass(record)));
260
+ let DTOs = [];
261
+ if (shortCodeData.isSingleDto === void 0 || shortCodeData.isSingleDto === true) {
262
+ DTOs = await Promise.all(results.map((record) => DTOClass(record)));
263
+ } else {
264
+ DTOs = await DTOClass(results);
265
+ }
261
266
  return {
262
267
  data: DTOs,
263
268
  totalRecords,
@@ -333,7 +338,7 @@ var commonRepository = (serviceDeps) => {
333
338
  logger.info("exiting::commonSearch::repository");
334
339
  return results;
335
340
  },
336
- async commonFetch({ id, shortCodeData }) {
341
+ async commonFetch({ id, shortCodeData, includes }) {
337
342
  logger.info("entering::commonFetch::repository");
338
343
  const tableName = shortCodeData.tableName;
339
344
  const model = db[tableName];
@@ -341,7 +346,8 @@ var commonRepository = (serviceDeps) => {
341
346
  throw new ErrorHandler(400, generateErrorMessage("INVALID_TABLE"));
342
347
  }
343
348
  const results = model.findUnique({
344
- where: { id, isActive: true }
349
+ where: { id, isActive: true },
350
+ include: includes ? includes : void 0
345
351
  });
346
352
  logger.info("exiting::commonFetch::repository");
347
353
  return results;
@@ -548,7 +554,12 @@ var commonRepository = (serviceDeps) => {
548
554
  const totalPages = Math.ceil(totalRecords / pageSize);
549
555
  const DTOClass = dtoMapping[shortCodeData.shortCode];
550
556
  if (shortCodeData.isDTO && DTOClass) {
551
- const DTOs = await Promise.all(results.map((record) => DTOClass(record)));
557
+ let DTOs = [];
558
+ if (shortCodeData.isSingleDto === void 0 || shortCodeData.isSingleDto === true) {
559
+ DTOs = await Promise.all(results.map((record) => DTOClass(record)));
560
+ } else {
561
+ DTOs = await DTOClass(results);
562
+ }
552
563
  return {
553
564
  data: DTOs,
554
565
  totalRecords,
@@ -609,7 +620,12 @@ var commonRepository = (serviceDeps) => {
609
620
  });
610
621
  const DTOClass = dtoMapping[shortCodeData.shortCode];
611
622
  if (shortCodeData.isDTO && DTOClass) {
612
- const DTOs = await Promise.all(results.map((record) => DTOClass(record)));
623
+ let DTOs = [];
624
+ if (shortCodeData.isSingleDto === void 0 || shortCodeData.isSingleDto === true) {
625
+ DTOs = await Promise.all(results.map((record) => DTOClass(record)));
626
+ } else {
627
+ DTOs = await DTOClass(results);
628
+ }
613
629
  return {
614
630
  data: DTOs,
615
631
  totalRecords
@@ -933,7 +949,7 @@ var commonService = (serviceDeps) => {
933
949
  logger.info("entering::fetch::service");
934
950
  const shortCodeData = fetchParams.shortCodeData;
935
951
  let commonData;
936
- if (shortCodeData.isCacheable && fetchParams.shortCode !== "UIN_CONFIG") {
952
+ if (shortCodeData.isCacheable && fetchParams.shortCode !== "UIN_CONFIG" && !fetchParams.includes) {
937
953
  commonData = await getCacheById(
938
954
  `${REDIS_PREFIX}${CACHE_KEY_NAME}:${shortCodeData.tableName}:all`,
939
955
  fetchParams.id
@@ -952,7 +968,12 @@ var commonService = (serviceDeps) => {
952
968
  throw new ErrorHandler(404, generateErrorMessage("NOT_FOUND", `${shortCodeData.tableName}`));
953
969
  }
954
970
  if (shortCodeData.isDTO && dtoMapping[shortCodeData.shortCode]) {
955
- const DtoResult = await dtoMapping[shortCodeData.shortCode](commonData);
971
+ let DtoResult;
972
+ if (shortCodeData.isSingleDto === void 0 || shortCodeData.isSingleDto === true) {
973
+ DtoResult = await dtoMapping[shortCodeData.shortCode](commonData);
974
+ } else {
975
+ DtoResult = (await dtoMapping[shortCodeData.shortCode]([commonData]))?.[0];
976
+ }
956
977
  return DtoResult;
957
978
  }
958
979
  logger.info("exiting::fetch::service");
@@ -1092,71 +1113,7 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
1092
1113
  const headFmt = options.headerRound ?? lineFmt;
1093
1114
  const precision = options.precision ?? 2;
1094
1115
  const children = inputs.map((it) => {
1095
- let baseRate = it.rate;
1096
- if (it.addonPercentage) {
1097
- baseRate = baseRate + percentage(baseRate, it.addonPercentage);
1098
- baseRate = applyRound(baseRate, lineFmt, precision);
1099
- }
1100
- const subtotal = applyRound(it.qty * baseRate, lineFmt, precision);
1101
- const other = applyRound(it.otherCharge ?? 0, lineFmt, precision);
1102
- const basePreTax = applyRound(subtotal + other, lineFmt, precision);
1103
- let copayAmount2 = 0;
1104
- if (masterExtra.coPayMode === "PERCENTAGE-AMOUNT") {
1105
- const copayType = it.coPaymentType ?? "AMOUNT";
1106
- const copayValue = it.coPayValue ?? 0;
1107
- copayAmount2 = copayType === "PERCENTAGE" ? percentage(subtotal, copayValue) : Math.min(copayValue, subtotal);
1108
- }
1109
- const dMode = it.discountMode ?? "AMOUNT";
1110
- const dVal = it.discountValue ?? 0;
1111
- const tMethod = it.taxMethod ?? "NONE";
1112
- const tVal = Math.max(0, it.taxValue ?? 0);
1113
- let baseAfterTaxDisc = basePreTax;
1114
- let discountValue = 0;
1115
- if (tMethod === "INCLUSIVE") {
1116
- const inclusiveTaxMultiplier = (100 + tVal) / 100;
1117
- baseAfterTaxDisc = basePreTax / inclusiveTaxMultiplier;
1118
- }
1119
- baseAfterTaxDisc = maybeStep(baseAfterTaxDisc, stepwise, lineFmt, precision);
1120
- const inxInclusiveDiff = applyRound(basePreTax - baseAfterTaxDisc, lineFmt, precision);
1121
- if (dMode === "AMOUNT") {
1122
- discountValue = dVal;
1123
- } else if (dMode === "PERCENTAGE") {
1124
- discountValue = percentage(baseAfterTaxDisc, dVal);
1125
- }
1126
- discountValue = maybeStep(discountValue, stepwise, lineFmt, precision);
1127
- let afterDisc = Math.max(0, baseAfterTaxDisc - discountValue);
1128
- afterDisc = maybeStep(afterDisc, stepwise, lineFmt, precision);
1129
- let calculatedTax = percentage(afterDisc, tVal);
1130
- calculatedTax = maybeStep(calculatedTax, stepwise, lineFmt, precision);
1131
- let grossAmount2 = afterDisc + calculatedTax;
1132
- grossAmount2 = maybeStep(grossAmount2, stepwise, lineFmt, precision);
1133
- if (masterExtra.coPayMode === "EXCLUSIVE-INCLUSIVE" && it.coPayMethod === "INCLUSIVE") {
1134
- copayAmount2 = grossAmount2;
1135
- }
1136
- copayAmount2 = applyRound(copayAmount2, lineFmt, precision);
1137
- const copay = clamp(Math.max(0, copayAmount2), 0, grossAmount2);
1138
- const patientRaw = applyRound(grossAmount2 - copay, "TO_FIXED", 2);
1139
- const patientRounded = applyRound(patientRaw, lineFmt, precision);
1140
- const lineRoundOff = patientRounded - patientRaw;
1141
- return {
1142
- baseRate: applyRound(baseRate, lineFmt, precision),
1143
- subtotalAmount: applyRound(subtotal + other - inxInclusiveDiff, lineFmt, precision),
1144
- otherChargeAmount: other,
1145
- discountMode: dMode,
1146
- discountValue: dVal,
1147
- discountAmount: applyRound(discountValue, lineFmt, precision),
1148
- // item-only discount
1149
- taxMethod: tMethod,
1150
- taxValue: tVal,
1151
- taxAmount: applyRound(calculatedTax, lineFmt, precision),
1152
- grossAmount: applyRound(grossAmount2, lineFmt, precision),
1153
- netAmount: patientRounded,
1154
- // patient payable at line
1155
- roundOffAmount: applyRound(lineRoundOff, "TO_FIXED", 2),
1156
- // rounded - raw
1157
- copayAmount: copay
1158
- // insurer covered at line
1159
- };
1116
+ return calculateSingleChild(it, masterExtra.coPayMode ?? "PERCENTAGE-AMOUNT", options);
1160
1117
  });
1161
1118
  const subtotalAmount = children.reduce((a, c) => a + c.subtotalAmount, 0);
1162
1119
  const otherChargeAmount = children.reduce((a, c) => a + c.otherChargeAmount, 0);
@@ -1194,6 +1151,73 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
1194
1151
  };
1195
1152
  return { master, children };
1196
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
+ }
1197
1221
 
1198
1222
  // src/utils/audit.utils.ts
1199
1223
  function isValidDate(value) {
@@ -2059,6 +2083,7 @@ export {
2059
2083
  NotificationEmitter,
2060
2084
  RoundFormat,
2061
2085
  calculateBillingFromChildren,
2086
+ calculateSingleChild,
2062
2087
  commonService,
2063
2088
  customOmit,
2064
2089
  findDifferences,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "av6-core",
3
- "version": "1.0.25",
3
+ "version": "1.1.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",