import { Organization } from 'fhir/r4'; // Mirrors the server's organization-invoice-terms.ts - the server WRITES this exact URL, the plugin // READS it back - so the literal MUST match byte for byte. export const ORGANIZATION_INVOICE_DEFAULT_TERMS_EXTENSION_URL = 'https://akashichealthrecords.com/fhir/StructureDefinition/organization-invoice-default-terms'; // Pure reader - the org's default invoice payment terms as net days (0 = due on receipt; 15/30/60/90). // Default when absent = 30 (net-30, the common practice default), matching the server's getDefaultNetDays. // A stored 0 (due on receipt) is preserved, not treated as "absent". export const getDefaultNetDays = (org?: Organization): number => { const value = org?.extension?.find( (e) => e.url === ORGANIZATION_INVOICE_DEFAULT_TERMS_EXTENSION_URL, )?.valueInteger; return typeof value === 'number' && Number.isFinite(value) ? value : 30; }; // Mirrors the server's organization-invoice-terms.ts ORG_ALLOW_PARTIAL_PAYMENTS_EXTENSION_URL (Task 5a) - // the server WRITES this exact URL via the same organization-invoice-terms PUT, the plugin READS it back - // so the literal MUST match byte for byte. Uses the `/fhir/extensions/` convention (like tz-code), not the // `/fhir/StructureDefinition/` convention above - intentional, matches the server literal. export const ORGANIZATION_ALLOW_PARTIAL_PAYMENTS_EXTENSION_URL = 'https://akashichealthrecords.com/fhir/extensions/organization-allow-partial-payments'; // Pure reader - whether the org allows partial payment by default. This is the org-wide house default a // billing:manage user sets; a new invoice's own allow-partial-pay toggle seeds from it. Default when // absent = false (privacy/simplicity-first - off unless the org turns it on), matching the server's // getOrgAllowPartialPayments. export const getOrgAllowPartialPayments = (org?: Organization): boolean => org?.extension?.find((e) => e.url === ORGANIZATION_ALLOW_PARTIAL_PAYMENTS_EXTENSION_URL)?.valueBoolean ?? false;