feat(insurance): add insurance coverage flag to selected services and update coverage logic

This commit is contained in:
hamed
2026-06-24 06:09:05 +03:30
parent 17f41117f1
commit 69beb7b944
3 changed files with 13 additions and 3 deletions
+4 -2
View File
@@ -61,7 +61,7 @@ export default function NewSessionPage() {
const nav = useNavigate();
const qc = useQueryClient();
const [selectedServices, setSelectedServices] = useState<{ uuid: string; name: string; price: number; qty: number }[]>([]);
const [selectedServices, setSelectedServices] = useState<{ uuid: string; name: string; price: number; qty: number; insured: boolean }[]>([]);
const [sectionUuid, setSectionUuid] = useState('');
const [itemUuid, setItemUuid] = useState('');
const [baseId, setBaseId] = useState('');
@@ -154,7 +154,7 @@ export default function NewSessionPage() {
if (!itemUuid) return;
const found = itemsData?.data?.find(i => i.uuid === itemUuid);
if (!found || selectedServices.some(s => s.uuid === found.uuid)) return;
setSelectedServices(p => [...p, { uuid: found.uuid, name: found.name, price: found.price_rials, qty: 1 }]);
setSelectedServices(p => [...p, { uuid: found.uuid, name: found.name, price: found.price_rials, qty: 1, insured: !!found.insurance_covered }]);
setItemUuid('');
};
@@ -168,6 +168,8 @@ export default function NewSessionPage() {
const servicesPatient = useMemo(
() => selectedServices.reduce((sum, x) => {
const total = x.price * x.qty;
// پرچم سرویس gate نهایی: اگر «شامل بیمه» نباشد، کامل سهم بیمار است.
if (!x.insured) return sum + total;
return sum + patientShareOf(
total,
ruleFor(baseContract, baseCoverage, x.uuid),