av6-core 1.0.20 → 1.0.22
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.js +43 -30
- package/dist/index.mjs +43 -30
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1131,6 +1131,9 @@ var maybeStep = (v, stepwise, fmt, p) => stepwise ? applyRound(v, fmt, p) : v;
|
|
|
1131
1131
|
function clamp(n, min, max) {
|
|
1132
1132
|
return Math.max(min, Math.min(max, n));
|
|
1133
1133
|
}
|
|
1134
|
+
var percentage = (amount, percentage2) => {
|
|
1135
|
+
return amount * percentage2 / 100;
|
|
1136
|
+
};
|
|
1134
1137
|
function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
1135
1138
|
const stepwise = options.calculationMethod === "STEP_WISE";
|
|
1136
1139
|
const lineFmt = options.lineRound ?? RoundFormat.TO_FIXED;
|
|
@@ -1139,55 +1142,64 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
|
1139
1142
|
const children = inputs.map((it) => {
|
|
1140
1143
|
let baseRate = it.rate;
|
|
1141
1144
|
if (it.addonPercentage) {
|
|
1142
|
-
baseRate = baseRate + baseRate
|
|
1145
|
+
baseRate = baseRate + percentage(baseRate, it.addonPercentage);
|
|
1146
|
+
baseRate = maybeStep(baseRate, stepwise, lineFmt, precision);
|
|
1143
1147
|
}
|
|
1144
|
-
const subtotal = it.qty * baseRate;
|
|
1145
|
-
const other = it.otherCharge ?? 0;
|
|
1146
|
-
const basePreTax = subtotal + other;
|
|
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);
|
|
1147
1151
|
let copayAmount2 = 0;
|
|
1148
1152
|
if (masterExtra.coPayMode === "PERCENTAGE-AMOUNT") {
|
|
1149
1153
|
const copayType = it.coPaymentType ?? "AMOUNT";
|
|
1150
1154
|
const copayValue = it.coPayValue ?? 0;
|
|
1151
|
-
copayAmount2 = copayType === "PERCENTAGE" ? basePreTax
|
|
1155
|
+
copayAmount2 = copayType === "PERCENTAGE" ? percentage(basePreTax, copayValue) : Math.min(copayValue, basePreTax);
|
|
1152
1156
|
}
|
|
1153
1157
|
const dMode = it.discountMode ?? "AMOUNT";
|
|
1154
1158
|
const dVal = it.discountValue ?? 0;
|
|
1155
|
-
const itemDisc = dMode === "PERCENTAGE" ? basePreTax * (dVal / 100) : Math.min(dVal, basePreTax);
|
|
1156
|
-
const baseAfterDisc = Math.max(0, basePreTax - itemDisc);
|
|
1157
1159
|
const tMethod = it.taxMethod ?? "NONE";
|
|
1158
1160
|
const tVal = Math.max(0, it.taxValue ?? 0);
|
|
1159
|
-
|
|
1160
|
-
let
|
|
1161
|
-
if (tMethod === "
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
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
|
+
if (dMode === "AMOUNT") {
|
|
1169
|
+
discountValue = dVal;
|
|
1170
|
+
} else if (dMode === "PERCENTAGE") {
|
|
1171
|
+
discountValue = percentage(baseAfterTaxDisc, dVal);
|
|
1165
1172
|
}
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1173
|
+
discountValue = maybeStep(discountValue, stepwise, lineFmt, precision);
|
|
1174
|
+
let afterDisc = Math.max(0, baseAfterTaxDisc - discountValue);
|
|
1175
|
+
afterDisc = maybeStep(afterDisc, stepwise, lineFmt, precision);
|
|
1176
|
+
let calculatedTax = percentage(afterDisc, tVal);
|
|
1177
|
+
calculatedTax = maybeStep(calculatedTax, stepwise, lineFmt, precision);
|
|
1178
|
+
let grossAmount2 = afterDisc + calculatedTax;
|
|
1179
|
+
grossAmount2 = maybeStep(grossAmount2, stepwise, lineFmt, precision);
|
|
1169
1180
|
if (masterExtra.coPayMode === "EXCLUSIVE-INCLUSIVE" && it.coPayMethod === "INCLUSIVE") {
|
|
1170
1181
|
copayAmount2 = grossAmount2;
|
|
1171
1182
|
}
|
|
1183
|
+
copayAmount2 = applyRound(copayAmount2, lineFmt, precision);
|
|
1172
1184
|
const copay = clamp(Math.max(0, copayAmount2), 0, grossAmount2);
|
|
1173
1185
|
const patientRaw = grossAmount2 - copay;
|
|
1174
1186
|
const patientRounded = applyRound(patientRaw, lineFmt, precision);
|
|
1175
1187
|
const lineRoundOff = patientRounded - patientRaw;
|
|
1176
1188
|
return {
|
|
1177
|
-
baseRate,
|
|
1189
|
+
baseRate: applyRound(baseRate, lineFmt, precision),
|
|
1178
1190
|
subtotalAmount: subtotal,
|
|
1179
1191
|
otherChargeAmount: other,
|
|
1180
1192
|
discountMode: dMode,
|
|
1181
1193
|
discountValue: dVal,
|
|
1182
|
-
discountAmount:
|
|
1194
|
+
discountAmount: applyRound(discountValue, lineFmt, precision),
|
|
1183
1195
|
// item-only discount
|
|
1184
1196
|
taxMethod: tMethod,
|
|
1185
1197
|
taxValue: tVal,
|
|
1186
|
-
taxAmount:
|
|
1187
|
-
grossAmount: grossAmount2,
|
|
1198
|
+
taxAmount: applyRound(calculatedTax, lineFmt, precision),
|
|
1199
|
+
grossAmount: applyRound(grossAmount2, lineFmt, precision),
|
|
1188
1200
|
netAmount: patientRounded,
|
|
1189
1201
|
// patient payable at line
|
|
1190
|
-
roundOffAmount: lineRoundOff,
|
|
1202
|
+
roundOffAmount: applyRound(lineRoundOff, "TO_FIXED", 2),
|
|
1191
1203
|
// rounded - raw
|
|
1192
1204
|
copayAmount: copay
|
|
1193
1205
|
// insurer covered at line
|
|
@@ -1202,28 +1214,29 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
|
1202
1214
|
const patientRawTotal = grossAmount - copayAmount;
|
|
1203
1215
|
let masterExtraApplied = 0;
|
|
1204
1216
|
if (masterExtra.mode === "PERCENTAGE") {
|
|
1205
|
-
masterExtraApplied = patientRawTotal
|
|
1217
|
+
masterExtraApplied = percentage(patientRawTotal, masterExtra.value);
|
|
1206
1218
|
} else if (masterExtra.mode === "AMOUNT") {
|
|
1207
1219
|
masterExtraApplied = Math.min(masterExtra.value, patientRawTotal);
|
|
1208
1220
|
}
|
|
1209
|
-
|
|
1221
|
+
masterExtraApplied = maybeStep(masterExtraApplied, stepwise, headFmt, precision);
|
|
1222
|
+
const discountTotalAmount = maybeStep(itemDiscountSum + masterExtraApplied, stepwise, headFmt, precision);
|
|
1210
1223
|
const patientAfterExtra = Math.max(0, patientRawTotal - masterExtraApplied);
|
|
1211
1224
|
const netAmount = applyRound(patientAfterExtra, headFmt, precision);
|
|
1212
1225
|
const roundOffAmount = netAmount - patientAfterExtra;
|
|
1213
1226
|
const master = {
|
|
1214
1227
|
additionalDiscountMode: masterExtra.mode,
|
|
1215
1228
|
additionalDiscountValue: masterExtra.value,
|
|
1216
|
-
subtotalAmount,
|
|
1217
|
-
otherChargeAmount,
|
|
1218
|
-
discountTotalAmount,
|
|
1229
|
+
subtotalAmount: applyRound(subtotalAmount, headFmt, precision),
|
|
1230
|
+
otherChargeAmount: applyRound(otherChargeAmount, headFmt, precision),
|
|
1231
|
+
discountTotalAmount: applyRound(discountTotalAmount, headFmt, precision),
|
|
1219
1232
|
// includes master extra
|
|
1220
|
-
taxAmount,
|
|
1221
|
-
grossAmount,
|
|
1233
|
+
taxAmount: applyRound(taxAmount, headFmt, precision),
|
|
1234
|
+
grossAmount: applyRound(grossAmount, headFmt, precision),
|
|
1222
1235
|
netAmount,
|
|
1223
1236
|
// patient payable after master extra + rounding
|
|
1224
|
-
roundOffAmount,
|
|
1237
|
+
roundOffAmount: applyRound(roundOffAmount, "TO_FIXED", 2),
|
|
1225
1238
|
// rounded - raw
|
|
1226
|
-
copayAmount
|
|
1239
|
+
copayAmount: applyRound(copayAmount, headFmt, precision)
|
|
1227
1240
|
// Σ line copay (insurer covered)
|
|
1228
1241
|
};
|
|
1229
1242
|
return { master, children };
|
package/dist/index.mjs
CHANGED
|
@@ -1083,6 +1083,9 @@ var maybeStep = (v, stepwise, fmt, p) => stepwise ? applyRound(v, fmt, p) : v;
|
|
|
1083
1083
|
function clamp(n, min, max) {
|
|
1084
1084
|
return Math.max(min, Math.min(max, n));
|
|
1085
1085
|
}
|
|
1086
|
+
var percentage = (amount, percentage2) => {
|
|
1087
|
+
return amount * percentage2 / 100;
|
|
1088
|
+
};
|
|
1086
1089
|
function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
1087
1090
|
const stepwise = options.calculationMethod === "STEP_WISE";
|
|
1088
1091
|
const lineFmt = options.lineRound ?? RoundFormat.TO_FIXED;
|
|
@@ -1091,55 +1094,64 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
|
1091
1094
|
const children = inputs.map((it) => {
|
|
1092
1095
|
let baseRate = it.rate;
|
|
1093
1096
|
if (it.addonPercentage) {
|
|
1094
|
-
baseRate = baseRate + baseRate
|
|
1097
|
+
baseRate = baseRate + percentage(baseRate, it.addonPercentage);
|
|
1098
|
+
baseRate = maybeStep(baseRate, stepwise, lineFmt, precision);
|
|
1095
1099
|
}
|
|
1096
|
-
const subtotal = it.qty * baseRate;
|
|
1097
|
-
const other = it.otherCharge ?? 0;
|
|
1098
|
-
const basePreTax = subtotal + other;
|
|
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);
|
|
1099
1103
|
let copayAmount2 = 0;
|
|
1100
1104
|
if (masterExtra.coPayMode === "PERCENTAGE-AMOUNT") {
|
|
1101
1105
|
const copayType = it.coPaymentType ?? "AMOUNT";
|
|
1102
1106
|
const copayValue = it.coPayValue ?? 0;
|
|
1103
|
-
copayAmount2 = copayType === "PERCENTAGE" ? basePreTax
|
|
1107
|
+
copayAmount2 = copayType === "PERCENTAGE" ? percentage(basePreTax, copayValue) : Math.min(copayValue, basePreTax);
|
|
1104
1108
|
}
|
|
1105
1109
|
const dMode = it.discountMode ?? "AMOUNT";
|
|
1106
1110
|
const dVal = it.discountValue ?? 0;
|
|
1107
|
-
const itemDisc = dMode === "PERCENTAGE" ? basePreTax * (dVal / 100) : Math.min(dVal, basePreTax);
|
|
1108
|
-
const baseAfterDisc = Math.max(0, basePreTax - itemDisc);
|
|
1109
1111
|
const tMethod = it.taxMethod ?? "NONE";
|
|
1110
1112
|
const tVal = Math.max(0, it.taxValue ?? 0);
|
|
1111
|
-
|
|
1112
|
-
let
|
|
1113
|
-
if (tMethod === "
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
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
|
+
if (dMode === "AMOUNT") {
|
|
1121
|
+
discountValue = dVal;
|
|
1122
|
+
} else if (dMode === "PERCENTAGE") {
|
|
1123
|
+
discountValue = percentage(baseAfterTaxDisc, dVal);
|
|
1117
1124
|
}
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1125
|
+
discountValue = maybeStep(discountValue, stepwise, lineFmt, precision);
|
|
1126
|
+
let afterDisc = Math.max(0, baseAfterTaxDisc - discountValue);
|
|
1127
|
+
afterDisc = maybeStep(afterDisc, stepwise, lineFmt, precision);
|
|
1128
|
+
let calculatedTax = percentage(afterDisc, tVal);
|
|
1129
|
+
calculatedTax = maybeStep(calculatedTax, stepwise, lineFmt, precision);
|
|
1130
|
+
let grossAmount2 = afterDisc + calculatedTax;
|
|
1131
|
+
grossAmount2 = maybeStep(grossAmount2, stepwise, lineFmt, precision);
|
|
1121
1132
|
if (masterExtra.coPayMode === "EXCLUSIVE-INCLUSIVE" && it.coPayMethod === "INCLUSIVE") {
|
|
1122
1133
|
copayAmount2 = grossAmount2;
|
|
1123
1134
|
}
|
|
1135
|
+
copayAmount2 = applyRound(copayAmount2, lineFmt, precision);
|
|
1124
1136
|
const copay = clamp(Math.max(0, copayAmount2), 0, grossAmount2);
|
|
1125
1137
|
const patientRaw = grossAmount2 - copay;
|
|
1126
1138
|
const patientRounded = applyRound(patientRaw, lineFmt, precision);
|
|
1127
1139
|
const lineRoundOff = patientRounded - patientRaw;
|
|
1128
1140
|
return {
|
|
1129
|
-
baseRate,
|
|
1141
|
+
baseRate: applyRound(baseRate, lineFmt, precision),
|
|
1130
1142
|
subtotalAmount: subtotal,
|
|
1131
1143
|
otherChargeAmount: other,
|
|
1132
1144
|
discountMode: dMode,
|
|
1133
1145
|
discountValue: dVal,
|
|
1134
|
-
discountAmount:
|
|
1146
|
+
discountAmount: applyRound(discountValue, lineFmt, precision),
|
|
1135
1147
|
// item-only discount
|
|
1136
1148
|
taxMethod: tMethod,
|
|
1137
1149
|
taxValue: tVal,
|
|
1138
|
-
taxAmount:
|
|
1139
|
-
grossAmount: grossAmount2,
|
|
1150
|
+
taxAmount: applyRound(calculatedTax, lineFmt, precision),
|
|
1151
|
+
grossAmount: applyRound(grossAmount2, lineFmt, precision),
|
|
1140
1152
|
netAmount: patientRounded,
|
|
1141
1153
|
// patient payable at line
|
|
1142
|
-
roundOffAmount: lineRoundOff,
|
|
1154
|
+
roundOffAmount: applyRound(lineRoundOff, "TO_FIXED", 2),
|
|
1143
1155
|
// rounded - raw
|
|
1144
1156
|
copayAmount: copay
|
|
1145
1157
|
// insurer covered at line
|
|
@@ -1154,28 +1166,29 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
|
1154
1166
|
const patientRawTotal = grossAmount - copayAmount;
|
|
1155
1167
|
let masterExtraApplied = 0;
|
|
1156
1168
|
if (masterExtra.mode === "PERCENTAGE") {
|
|
1157
|
-
masterExtraApplied = patientRawTotal
|
|
1169
|
+
masterExtraApplied = percentage(patientRawTotal, masterExtra.value);
|
|
1158
1170
|
} else if (masterExtra.mode === "AMOUNT") {
|
|
1159
1171
|
masterExtraApplied = Math.min(masterExtra.value, patientRawTotal);
|
|
1160
1172
|
}
|
|
1161
|
-
|
|
1173
|
+
masterExtraApplied = maybeStep(masterExtraApplied, stepwise, headFmt, precision);
|
|
1174
|
+
const discountTotalAmount = maybeStep(itemDiscountSum + masterExtraApplied, stepwise, headFmt, precision);
|
|
1162
1175
|
const patientAfterExtra = Math.max(0, patientRawTotal - masterExtraApplied);
|
|
1163
1176
|
const netAmount = applyRound(patientAfterExtra, headFmt, precision);
|
|
1164
1177
|
const roundOffAmount = netAmount - patientAfterExtra;
|
|
1165
1178
|
const master = {
|
|
1166
1179
|
additionalDiscountMode: masterExtra.mode,
|
|
1167
1180
|
additionalDiscountValue: masterExtra.value,
|
|
1168
|
-
subtotalAmount,
|
|
1169
|
-
otherChargeAmount,
|
|
1170
|
-
discountTotalAmount,
|
|
1181
|
+
subtotalAmount: applyRound(subtotalAmount, headFmt, precision),
|
|
1182
|
+
otherChargeAmount: applyRound(otherChargeAmount, headFmt, precision),
|
|
1183
|
+
discountTotalAmount: applyRound(discountTotalAmount, headFmt, precision),
|
|
1171
1184
|
// includes master extra
|
|
1172
|
-
taxAmount,
|
|
1173
|
-
grossAmount,
|
|
1185
|
+
taxAmount: applyRound(taxAmount, headFmt, precision),
|
|
1186
|
+
grossAmount: applyRound(grossAmount, headFmt, precision),
|
|
1174
1187
|
netAmount,
|
|
1175
1188
|
// patient payable after master extra + rounding
|
|
1176
|
-
roundOffAmount,
|
|
1189
|
+
roundOffAmount: applyRound(roundOffAmount, "TO_FIXED", 2),
|
|
1177
1190
|
// rounded - raw
|
|
1178
|
-
copayAmount
|
|
1191
|
+
copayAmount: applyRound(copayAmount, headFmt, precision)
|
|
1179
1192
|
// Σ line copay (insurer covered)
|
|
1180
1193
|
};
|
|
1181
1194
|
return { master, children };
|