av6-core 1.0.24 → 1.1.0
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 +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +72 -69
- package/dist/index.mjs +71 -69
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -346,6 +346,7 @@ interface BillingCalcResult {
|
|
|
346
346
|
* then header rounding
|
|
347
347
|
*/
|
|
348
348
|
declare function calculateBillingFromChildren(inputs: ChildCalcInput[], masterExtra: MasterAdditionalDiscount, options?: CalcOptions): BillingCalcResult;
|
|
349
|
+
declare function calculateSingleChild(it: ChildCalcInput, coPayMode: CoPayMode, options?: CalcOptions): ChildCalculated;
|
|
349
350
|
|
|
350
351
|
interface CreateTransaction {
|
|
351
352
|
field: string;
|
|
@@ -466,4 +467,4 @@ declare class NotificationEmitter {
|
|
|
466
467
|
notifyNow(eventName: string, body: Omit<EmitPayload, "eventName">): Promise<void>;
|
|
467
468
|
}
|
|
468
469
|
|
|
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 };
|
|
470
|
+
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
|
@@ -346,6 +346,7 @@ interface BillingCalcResult {
|
|
|
346
346
|
* then header rounding
|
|
347
347
|
*/
|
|
348
348
|
declare function calculateBillingFromChildren(inputs: ChildCalcInput[], masterExtra: MasterAdditionalDiscount, options?: CalcOptions): BillingCalcResult;
|
|
349
|
+
declare function calculateSingleChild(it: ChildCalcInput, coPayMode: CoPayMode, options?: CalcOptions): ChildCalculated;
|
|
349
350
|
|
|
350
351
|
interface CreateTransaction {
|
|
351
352
|
field: string;
|
|
@@ -466,4 +467,4 @@ declare class NotificationEmitter {
|
|
|
466
467
|
notifyNow(eventName: string, body: Omit<EmitPayload, "eventName">): Promise<void>;
|
|
467
468
|
}
|
|
468
469
|
|
|
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 };
|
|
470
|
+
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,
|
|
@@ -1140,72 +1141,7 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
|
1140
1141
|
const headFmt = options.headerRound ?? lineFmt;
|
|
1141
1142
|
const precision = options.precision ?? 2;
|
|
1142
1143
|
const children = inputs.map((it) => {
|
|
1143
|
-
|
|
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 = grossAmount2 - copay;
|
|
1187
|
-
const patientRounded = applyRound(patientRaw, lineFmt, precision);
|
|
1188
|
-
const lineRoundOff = patientRounded - patientRaw;
|
|
1189
|
-
const normalizedLineRoundOff = Object.is(lineRoundOff, -0) ? 0 : lineRoundOff;
|
|
1190
|
-
return {
|
|
1191
|
-
baseRate: applyRound(baseRate, lineFmt, precision),
|
|
1192
|
-
subtotalAmount: applyRound(subtotal + other - inxInclusiveDiff, lineFmt, precision),
|
|
1193
|
-
otherChargeAmount: other,
|
|
1194
|
-
discountMode: dMode,
|
|
1195
|
-
discountValue: dVal,
|
|
1196
|
-
discountAmount: applyRound(discountValue, lineFmt, precision),
|
|
1197
|
-
// item-only discount
|
|
1198
|
-
taxMethod: tMethod,
|
|
1199
|
-
taxValue: tVal,
|
|
1200
|
-
taxAmount: applyRound(calculatedTax, lineFmt, precision),
|
|
1201
|
-
grossAmount: applyRound(grossAmount2, lineFmt, precision),
|
|
1202
|
-
netAmount: patientRounded,
|
|
1203
|
-
// patient payable at line
|
|
1204
|
-
roundOffAmount: applyRound(normalizedLineRoundOff, "TO_FIXED", 2),
|
|
1205
|
-
// rounded - raw
|
|
1206
|
-
copayAmount: copay
|
|
1207
|
-
// insurer covered at line
|
|
1208
|
-
};
|
|
1144
|
+
return calculateSingleChild(it, masterExtra.coPayMode ?? "PERCENTAGE-AMOUNT", options);
|
|
1209
1145
|
});
|
|
1210
1146
|
const subtotalAmount = children.reduce((a, c) => a + c.subtotalAmount, 0);
|
|
1211
1147
|
const otherChargeAmount = children.reduce((a, c) => a + c.otherChargeAmount, 0);
|
|
@@ -1222,10 +1158,9 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
|
1222
1158
|
}
|
|
1223
1159
|
masterExtraApplied = maybeStep(masterExtraApplied, stepwise, headFmt, precision);
|
|
1224
1160
|
const discountTotalAmount = maybeStep(itemDiscountSum + masterExtraApplied, stepwise, headFmt, precision);
|
|
1225
|
-
const patientAfterExtra = Math.max(0, patientRawTotal - masterExtraApplied);
|
|
1161
|
+
const patientAfterExtra = applyRound(Math.max(0, patientRawTotal - masterExtraApplied), "TO_FIXED", 2);
|
|
1226
1162
|
const netAmount = applyRound(patientAfterExtra, headFmt, precision);
|
|
1227
1163
|
const roundOffAmount = netAmount - patientAfterExtra;
|
|
1228
|
-
const normalizedRoundOffAmount = Object.is(roundOffAmount, -0) ? 0 : roundOffAmount;
|
|
1229
1164
|
const master = {
|
|
1230
1165
|
additionalDiscountMode: masterExtra.mode,
|
|
1231
1166
|
additionalDiscountValue: masterExtra.value,
|
|
@@ -1237,13 +1172,80 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
|
1237
1172
|
grossAmount: applyRound(grossAmount, headFmt, precision),
|
|
1238
1173
|
netAmount,
|
|
1239
1174
|
// patient payable after master extra + rounding
|
|
1240
|
-
roundOffAmount: applyRound(
|
|
1175
|
+
roundOffAmount: applyRound(roundOffAmount, "TO_FIXED", 2),
|
|
1241
1176
|
// rounded - raw
|
|
1242
1177
|
copayAmount: applyRound(copayAmount, headFmt, precision)
|
|
1243
1178
|
// Σ line copay (insurer covered)
|
|
1244
1179
|
};
|
|
1245
1180
|
return { master, children };
|
|
1246
1181
|
}
|
|
1182
|
+
function calculateSingleChild(it, coPayMode, options = {}) {
|
|
1183
|
+
const stepwise = options.calculationMethod === "STEP_WISE";
|
|
1184
|
+
const lineFmt = options.lineRound ?? RoundFormat.TO_FIXED;
|
|
1185
|
+
const precision = options.precision ?? 2;
|
|
1186
|
+
let baseRate = it.rate;
|
|
1187
|
+
if (it.addonPercentage) {
|
|
1188
|
+
baseRate = baseRate + percentage(baseRate, it.addonPercentage);
|
|
1189
|
+
baseRate = applyRound(baseRate, lineFmt, precision);
|
|
1190
|
+
}
|
|
1191
|
+
const subtotal = applyRound(it.qty * baseRate, lineFmt, precision);
|
|
1192
|
+
const other = applyRound(it.otherCharge ?? 0, lineFmt, precision);
|
|
1193
|
+
const basePreTax = applyRound(subtotal + other, lineFmt, precision);
|
|
1194
|
+
let copayAmount = 0;
|
|
1195
|
+
if (coPayMode === "PERCENTAGE-AMOUNT") {
|
|
1196
|
+
const copayType = it.coPaymentType ?? "AMOUNT";
|
|
1197
|
+
const copayValue = it.coPayValue ?? 0;
|
|
1198
|
+
copayAmount = copayType === "PERCENTAGE" ? percentage(subtotal, copayValue) : Math.min(copayValue, subtotal);
|
|
1199
|
+
}
|
|
1200
|
+
const dMode = it.discountMode ?? "AMOUNT";
|
|
1201
|
+
const dVal = it.discountValue ?? 0;
|
|
1202
|
+
const tMethod = it.taxMethod ?? "NONE";
|
|
1203
|
+
const tVal = Math.max(0, it.taxValue ?? 0);
|
|
1204
|
+
let baseAfterTaxDisc = basePreTax;
|
|
1205
|
+
if (tMethod === "INCLUSIVE") {
|
|
1206
|
+
const inclusiveTaxMultiplier = (100 + tVal) / 100;
|
|
1207
|
+
baseAfterTaxDisc = basePreTax / inclusiveTaxMultiplier;
|
|
1208
|
+
}
|
|
1209
|
+
baseAfterTaxDisc = maybeStep(baseAfterTaxDisc, stepwise, lineFmt, precision);
|
|
1210
|
+
const inclDiff = applyRound(basePreTax - baseAfterTaxDisc, lineFmt, precision);
|
|
1211
|
+
let discountValue = 0;
|
|
1212
|
+
if (dMode === "AMOUNT") {
|
|
1213
|
+
discountValue = dVal;
|
|
1214
|
+
} else if (dMode === "PERCENTAGE") {
|
|
1215
|
+
discountValue = percentage(baseAfterTaxDisc, dVal);
|
|
1216
|
+
}
|
|
1217
|
+
discountValue = maybeStep(discountValue, stepwise, lineFmt, precision);
|
|
1218
|
+
let afterDisc = Math.max(0, baseAfterTaxDisc - discountValue);
|
|
1219
|
+
afterDisc = maybeStep(afterDisc, stepwise, lineFmt, precision);
|
|
1220
|
+
let calculatedTax = percentage(afterDisc, tVal);
|
|
1221
|
+
calculatedTax = maybeStep(calculatedTax, stepwise, lineFmt, precision);
|
|
1222
|
+
let grossAmount = afterDisc + calculatedTax;
|
|
1223
|
+
grossAmount = maybeStep(grossAmount, stepwise, lineFmt, precision);
|
|
1224
|
+
if (coPayMode === "EXCLUSIVE-INCLUSIVE" && it.coPayMethod === "INCLUSIVE") {
|
|
1225
|
+
copayAmount = grossAmount;
|
|
1226
|
+
}
|
|
1227
|
+
copayAmount = applyRound(copayAmount, lineFmt, precision);
|
|
1228
|
+
const copay = clamp(Math.max(0, copayAmount), 0, grossAmount);
|
|
1229
|
+
const patientRaw = applyRound(grossAmount - copay, RoundFormat.TO_FIXED, 2);
|
|
1230
|
+
const patientRounded = applyRound(patientRaw, lineFmt, precision);
|
|
1231
|
+
const lineRoundOff = applyRound(patientRounded - patientRaw, RoundFormat.TO_FIXED, 2);
|
|
1232
|
+
return {
|
|
1233
|
+
// include baseRate if your ChildCalculated type has it (as in your bulk function)
|
|
1234
|
+
baseRate: applyRound(baseRate, lineFmt, precision),
|
|
1235
|
+
subtotalAmount: applyRound(subtotal + other - inclDiff, lineFmt, precision),
|
|
1236
|
+
otherChargeAmount: other,
|
|
1237
|
+
discountMode: dMode,
|
|
1238
|
+
discountValue: dVal,
|
|
1239
|
+
discountAmount: applyRound(discountValue, lineFmt, precision),
|
|
1240
|
+
taxMethod: tMethod,
|
|
1241
|
+
taxValue: tVal,
|
|
1242
|
+
taxAmount: applyRound(calculatedTax, lineFmt, precision),
|
|
1243
|
+
grossAmount: applyRound(grossAmount, lineFmt, precision),
|
|
1244
|
+
netAmount: patientRounded,
|
|
1245
|
+
roundOffAmount: lineRoundOff,
|
|
1246
|
+
copayAmount: copay
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
1247
1249
|
|
|
1248
1250
|
// src/utils/audit.utils.ts
|
|
1249
1251
|
function isValidDate(value) {
|
|
@@ -2110,6 +2112,7 @@ var NotificationEmitter = class {
|
|
|
2110
2112
|
NotificationEmitter,
|
|
2111
2113
|
RoundFormat,
|
|
2112
2114
|
calculateBillingFromChildren,
|
|
2115
|
+
calculateSingleChild,
|
|
2113
2116
|
commonService,
|
|
2114
2117
|
customOmit,
|
|
2115
2118
|
findDifferences,
|
package/dist/index.mjs
CHANGED
|
@@ -1092,72 +1092,7 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
|
1092
1092
|
const headFmt = options.headerRound ?? lineFmt;
|
|
1093
1093
|
const precision = options.precision ?? 2;
|
|
1094
1094
|
const children = inputs.map((it) => {
|
|
1095
|
-
|
|
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 = grossAmount2 - copay;
|
|
1139
|
-
const patientRounded = applyRound(patientRaw, lineFmt, precision);
|
|
1140
|
-
const lineRoundOff = patientRounded - patientRaw;
|
|
1141
|
-
const normalizedLineRoundOff = Object.is(lineRoundOff, -0) ? 0 : lineRoundOff;
|
|
1142
|
-
return {
|
|
1143
|
-
baseRate: applyRound(baseRate, lineFmt, precision),
|
|
1144
|
-
subtotalAmount: applyRound(subtotal + other - inxInclusiveDiff, lineFmt, precision),
|
|
1145
|
-
otherChargeAmount: other,
|
|
1146
|
-
discountMode: dMode,
|
|
1147
|
-
discountValue: dVal,
|
|
1148
|
-
discountAmount: applyRound(discountValue, lineFmt, precision),
|
|
1149
|
-
// item-only discount
|
|
1150
|
-
taxMethod: tMethod,
|
|
1151
|
-
taxValue: tVal,
|
|
1152
|
-
taxAmount: applyRound(calculatedTax, lineFmt, precision),
|
|
1153
|
-
grossAmount: applyRound(grossAmount2, lineFmt, precision),
|
|
1154
|
-
netAmount: patientRounded,
|
|
1155
|
-
// patient payable at line
|
|
1156
|
-
roundOffAmount: applyRound(normalizedLineRoundOff, "TO_FIXED", 2),
|
|
1157
|
-
// rounded - raw
|
|
1158
|
-
copayAmount: copay
|
|
1159
|
-
// insurer covered at line
|
|
1160
|
-
};
|
|
1095
|
+
return calculateSingleChild(it, masterExtra.coPayMode ?? "PERCENTAGE-AMOUNT", options);
|
|
1161
1096
|
});
|
|
1162
1097
|
const subtotalAmount = children.reduce((a, c) => a + c.subtotalAmount, 0);
|
|
1163
1098
|
const otherChargeAmount = children.reduce((a, c) => a + c.otherChargeAmount, 0);
|
|
@@ -1174,10 +1109,9 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
|
1174
1109
|
}
|
|
1175
1110
|
masterExtraApplied = maybeStep(masterExtraApplied, stepwise, headFmt, precision);
|
|
1176
1111
|
const discountTotalAmount = maybeStep(itemDiscountSum + masterExtraApplied, stepwise, headFmt, precision);
|
|
1177
|
-
const patientAfterExtra = Math.max(0, patientRawTotal - masterExtraApplied);
|
|
1112
|
+
const patientAfterExtra = applyRound(Math.max(0, patientRawTotal - masterExtraApplied), "TO_FIXED", 2);
|
|
1178
1113
|
const netAmount = applyRound(patientAfterExtra, headFmt, precision);
|
|
1179
1114
|
const roundOffAmount = netAmount - patientAfterExtra;
|
|
1180
|
-
const normalizedRoundOffAmount = Object.is(roundOffAmount, -0) ? 0 : roundOffAmount;
|
|
1181
1115
|
const master = {
|
|
1182
1116
|
additionalDiscountMode: masterExtra.mode,
|
|
1183
1117
|
additionalDiscountValue: masterExtra.value,
|
|
@@ -1189,13 +1123,80 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
|
1189
1123
|
grossAmount: applyRound(grossAmount, headFmt, precision),
|
|
1190
1124
|
netAmount,
|
|
1191
1125
|
// patient payable after master extra + rounding
|
|
1192
|
-
roundOffAmount: applyRound(
|
|
1126
|
+
roundOffAmount: applyRound(roundOffAmount, "TO_FIXED", 2),
|
|
1193
1127
|
// rounded - raw
|
|
1194
1128
|
copayAmount: applyRound(copayAmount, headFmt, precision)
|
|
1195
1129
|
// Σ line copay (insurer covered)
|
|
1196
1130
|
};
|
|
1197
1131
|
return { master, children };
|
|
1198
1132
|
}
|
|
1133
|
+
function calculateSingleChild(it, coPayMode, options = {}) {
|
|
1134
|
+
const stepwise = options.calculationMethod === "STEP_WISE";
|
|
1135
|
+
const lineFmt = options.lineRound ?? RoundFormat.TO_FIXED;
|
|
1136
|
+
const precision = options.precision ?? 2;
|
|
1137
|
+
let baseRate = it.rate;
|
|
1138
|
+
if (it.addonPercentage) {
|
|
1139
|
+
baseRate = baseRate + percentage(baseRate, it.addonPercentage);
|
|
1140
|
+
baseRate = applyRound(baseRate, lineFmt, precision);
|
|
1141
|
+
}
|
|
1142
|
+
const subtotal = applyRound(it.qty * baseRate, lineFmt, precision);
|
|
1143
|
+
const other = applyRound(it.otherCharge ?? 0, lineFmt, precision);
|
|
1144
|
+
const basePreTax = applyRound(subtotal + other, lineFmt, precision);
|
|
1145
|
+
let copayAmount = 0;
|
|
1146
|
+
if (coPayMode === "PERCENTAGE-AMOUNT") {
|
|
1147
|
+
const copayType = it.coPaymentType ?? "AMOUNT";
|
|
1148
|
+
const copayValue = it.coPayValue ?? 0;
|
|
1149
|
+
copayAmount = copayType === "PERCENTAGE" ? percentage(subtotal, copayValue) : Math.min(copayValue, subtotal);
|
|
1150
|
+
}
|
|
1151
|
+
const dMode = it.discountMode ?? "AMOUNT";
|
|
1152
|
+
const dVal = it.discountValue ?? 0;
|
|
1153
|
+
const tMethod = it.taxMethod ?? "NONE";
|
|
1154
|
+
const tVal = Math.max(0, it.taxValue ?? 0);
|
|
1155
|
+
let baseAfterTaxDisc = basePreTax;
|
|
1156
|
+
if (tMethod === "INCLUSIVE") {
|
|
1157
|
+
const inclusiveTaxMultiplier = (100 + tVal) / 100;
|
|
1158
|
+
baseAfterTaxDisc = basePreTax / inclusiveTaxMultiplier;
|
|
1159
|
+
}
|
|
1160
|
+
baseAfterTaxDisc = maybeStep(baseAfterTaxDisc, stepwise, lineFmt, precision);
|
|
1161
|
+
const inclDiff = applyRound(basePreTax - baseAfterTaxDisc, lineFmt, precision);
|
|
1162
|
+
let discountValue = 0;
|
|
1163
|
+
if (dMode === "AMOUNT") {
|
|
1164
|
+
discountValue = dVal;
|
|
1165
|
+
} else if (dMode === "PERCENTAGE") {
|
|
1166
|
+
discountValue = percentage(baseAfterTaxDisc, dVal);
|
|
1167
|
+
}
|
|
1168
|
+
discountValue = maybeStep(discountValue, stepwise, lineFmt, precision);
|
|
1169
|
+
let afterDisc = Math.max(0, baseAfterTaxDisc - discountValue);
|
|
1170
|
+
afterDisc = maybeStep(afterDisc, stepwise, lineFmt, precision);
|
|
1171
|
+
let calculatedTax = percentage(afterDisc, tVal);
|
|
1172
|
+
calculatedTax = maybeStep(calculatedTax, stepwise, lineFmt, precision);
|
|
1173
|
+
let grossAmount = afterDisc + calculatedTax;
|
|
1174
|
+
grossAmount = maybeStep(grossAmount, stepwise, lineFmt, precision);
|
|
1175
|
+
if (coPayMode === "EXCLUSIVE-INCLUSIVE" && it.coPayMethod === "INCLUSIVE") {
|
|
1176
|
+
copayAmount = grossAmount;
|
|
1177
|
+
}
|
|
1178
|
+
copayAmount = applyRound(copayAmount, lineFmt, precision);
|
|
1179
|
+
const copay = clamp(Math.max(0, copayAmount), 0, grossAmount);
|
|
1180
|
+
const patientRaw = applyRound(grossAmount - copay, RoundFormat.TO_FIXED, 2);
|
|
1181
|
+
const patientRounded = applyRound(patientRaw, lineFmt, precision);
|
|
1182
|
+
const lineRoundOff = applyRound(patientRounded - patientRaw, RoundFormat.TO_FIXED, 2);
|
|
1183
|
+
return {
|
|
1184
|
+
// include baseRate if your ChildCalculated type has it (as in your bulk function)
|
|
1185
|
+
baseRate: applyRound(baseRate, lineFmt, precision),
|
|
1186
|
+
subtotalAmount: applyRound(subtotal + other - inclDiff, lineFmt, precision),
|
|
1187
|
+
otherChargeAmount: other,
|
|
1188
|
+
discountMode: dMode,
|
|
1189
|
+
discountValue: dVal,
|
|
1190
|
+
discountAmount: applyRound(discountValue, lineFmt, precision),
|
|
1191
|
+
taxMethod: tMethod,
|
|
1192
|
+
taxValue: tVal,
|
|
1193
|
+
taxAmount: applyRound(calculatedTax, lineFmt, precision),
|
|
1194
|
+
grossAmount: applyRound(grossAmount, lineFmt, precision),
|
|
1195
|
+
netAmount: patientRounded,
|
|
1196
|
+
roundOffAmount: lineRoundOff,
|
|
1197
|
+
copayAmount: copay
|
|
1198
|
+
};
|
|
1199
|
+
}
|
|
1199
1200
|
|
|
1200
1201
|
// src/utils/audit.utils.ts
|
|
1201
1202
|
function isValidDate(value) {
|
|
@@ -2061,6 +2062,7 @@ export {
|
|
|
2061
2062
|
NotificationEmitter,
|
|
2062
2063
|
RoundFormat,
|
|
2063
2064
|
calculateBillingFromChildren,
|
|
2065
|
+
calculateSingleChild,
|
|
2064
2066
|
commonService,
|
|
2065
2067
|
customOmit,
|
|
2066
2068
|
findDifferences,
|