Draft the billing transaction of a payment document (Peru's TEDEF)
Drafts, a page of up to 50 patients at a time, the billing an IPRESS sends an IAFAS with one of the contract's invoices, in the format the contract's jurisdiction asks for (its payer's country; getJurisdiction shows billingTransactionFormat): Peru's TEDEF-IPRESS-IAFAS, tedef_043 (Resolución de Superintendencia N.° 043-2025-SUSALUD/S, annexes 1 and 3), eight fixed-width text files. The first page brings the header of the payment document (table 1, dfac): the batch, the IAFAS (the payer's code when it is SUSALUD's five digits), the RUC, the establishment (the RENIPRESS code of the site the services count at, as the directory keeps it, when they all count at one), the document's type and number (the invoice's, F001-123 written F00100000123), its day, the product, the number of prestaciones, the payment mechanism (04 capitation, 01 fee for service), under 02, 04 and 06 the pre-agreed amount (the taxable base plus the copayments subject to IGV) and the start of its period (the invoice period's first day), the currency (soles), the exempt amount, the copayments (0.00 when the invoice credits none), the taxable base, the IGV and the invoice's total; and the names of the files and of the .S01 archive of transaction 937. With noteRef, a credit or a debit note the invoice keeps travels in the same header (fields 25 to 29, as annex 1 sends a note): C or D, its number in the document's shape, its amount without IGV (its value less noteIgvMinor), its day and its reason, A (anulación) for a credit note that voided the invoice and D (descuento parcial) for another credit note (a debit note's reason is left for a person), with the day the document was first sent (firstSentOn, field 30); the batch repeats the document and the note notice says what SUSALUD has to confirm about it. Every page brings its prestaciones: one per encounter the contract pays services of in the invoice's period (for a fee-for-service invoice, only the services its priced lines bill), numbered on from the earlier pages (table 2, date), with the person's DNI or other document from their profile, the encounter's day, hour and first three diagnoses at the subcategory level (E11.9), and its establishment; their procedures (table 3, dser) with their CPMS code, the name the CPMS release in force gives it and their units; and their medications and devices (table 4, dfar) with their day and units; for fee for service each at its priced line. The optional tables too: a record per dental procedure of table 3, a CPMS D code (table 5, dden), whose tooth and surfaces a person writes; the additional data of each prestación (table 6, dpre): the person's birth date and sex from their profile, whether the services attended a booked appointment, and the head circumference (only under 5 years, 0.00 after), the waist circumference, the weight, the height and the hemoglobin the record measured that day by their LOINC codes (9843-4, 8280-0, 29463-7, 8302-2, 718-7), in the fields' units; a record per diagnosis of the encounter (table 7, ddia); and a record per vaccination or preventive procedure of table 3 (CPMS 90460 to 90474, 90476 to 90759, 99381 to 99429; table 8, dprv), whose parameter and value a person writes from SUSALUD's catalog of additional activities. Nothing is invented: missing lists the values the record or the request lacks for a record, notKept the fields Ámbar keeps nothing for (the insured code, the affiliation type, the clinical record number, the professional, a service's tax exemption and heading, a product's GTIN or UNSPSC code, a tooth, a diagnosis's type, an activity's parameter, the outcome), which a person completes from the supports, and fields that apply only sometimes (a referral, a hospitalization, an emergency, a newborn) go blank. Nothing is written.
Use it to prepare the TEDEF of an invoice: pass ruc, batch, paymentDocumentType, product and the taxes of SUSALUD's payment document (taxableMinor, exemptMinor, igvMinor, which Ámbar does not keep) so the header is complete; read every page passing nextCursor as after; join every page's lines of each file in order; have a person complete what missing and notKept list; check the files with checkBillingTransaction; and zip the eight files into the archive header.names.archive names (Ámbar does not write ZIP archives).
Returns format, mechanism, prestationsBefore, header (on the first page), lines (this page's records by file), rows (each record's patient, encounter, event, site and code), missing, notKept, missingByField, notices and nextCursor.
Requires ambar:patients:read and ambar:contracts:read, the contract's read grant and, for care operations, the registry-wide patient read grant: with grants on some patients only, the services of the others are left out.
INVALID_INPUT: a malformed contractId, invoiceRef, ruc (eleven digits), batch (1 to 9,999,999), product (five letters or digits), amount (0 to 99,999,999,999 céntimos) or after, noteIgvMinor without noteRef, or an invoice of another contract; fix it. NOT_FOUND: no such contract, invoice or note on the invoice, you may not read it, or the contract has no payer yet. CONFLICT: the payer's country has no billing transaction Ámbar drafts (billingTransactionFormat is null). RESOURCE_LIMIT_EXCEEDED: the page's 50 patients have more than 10,000 services in the period or more than 40,000 measurements, or the invoice bills more than 20,000. ACCESS_DENIED: a missing scope, or clinical privacy not configured; do not retry.
https://api-ambar.getarbol.com/v1/billing-transactions/draftAuthorization
Query parameters
- paymentDocumentTypeoptional01or02or03or04or05or09+3 more
The kind of payment document, as table 1 codes it:
01factura,02recibo por honorarios,03boleta de venta,04liquidación de compra,05boleto de aviación,09ticket de máquina registradora,10FUA,11código único de atención of a public IAFAS,99another document SUNAT authorizes. Without it the type of every record is left for a person.
Returns
200
400
Failure. The error.code is one of:
INVALID_INPUT: Do not retry unchanged. Fix the request against the operation's schema.USER_PAYMENT_REFUSED: Check the collection basis and caps in details.paymentProblem before recording the payment.INVALID_INVENTORY: Do not retry unchanged. Fix the request against the operation's schema.ANALYTICS_QUERY_REJECTED: Rewrite the query as one read-only statement over the published catalog.MINOR_UNIT_SCALE_MISMATCH: Write each component's money in the minor units of its currency (minorUnitScale 2 for COP, PEN, MXN and BRL; 0 for CLP) and propose again.
401
Failure. The error.code is one of:
UNAUTHORIZED: Obtain a fresh access token and repeat the request.
403
Failure. The error.code is one of:
ACCESS_DENIED: Do not retry. The signed-in actor lacks this purpose or grant; ask an administrator.MODULE_DISABLED: Do not retry. The organization does not use the module in details.module (getSession lists the ones it uses); an administrator turns it on with setOrganizationModules.
404
Failure. The error.code is one of:
NOT_FOUND: Check the identifier. The record may not exist or may not be visible to this actor.
409
Failure. The error.code is one of:
CONFLICT: Read the current state with the matching get operation, then decide again.IDEMPOTENCY_CONFLICT: The requestKey was already used for a different request. Use a new key for a new action.TRANSACTION_ABORTED: Nothing was written. Retry the same request.INVENTORY_INTEGRITY_CONFLICT: Do not retry. Report the integrity failure to an operator.TEAM_PRIOR_UNRESOLVED: Reconcile the earlier team command (see details.commandId) before a new change.COHORT_ACTIVE_REQUIRED: Read the current state with the matching get operation, then decide again.COHORT_CUT_CHANGED: Restart the paginated read from the first page.COHORT_READ_REQUIRES_ACTIVE: Read the current state with the matching get operation, then decide again.COHORT_CUT_NEEDS_RECONCILIATION: Read the current state with the matching get operation, then decide again.PROGRAM_NEW_ASSESSMENT_REQUIRED: Read the current state with the matching get operation, then decide again.CONTRACT_CLOSED_WINDOW_CHANGE_UNSUPPORTED: Read the current state with the matching get operation, then decide again.INVOICE_COMPONENT_AMBIGUOUS: Route the lines in details.lineIds to their paying component, then request the proposal again. At most 100 identifiers are returned.SITE_SUBSTITUTION_REFUSED: Book at the contracted site, or at a site its contract lets serve for it on the appointment's day (listContractSites), recording what details.reason says is missing: the patient's acceptance or the payer's authorization.
422
Failure. The error.code is one of:
RESOURCE_LIMIT_EXCEEDED: Do not retry. Reduce the request or archive records first.MODULE_NOT_CONTRACTED: Leave the module in details.module off: the organization did not contract it. Árbol adds it to the contract when the organization buys it.MODULE_REQUIREMENT_MISSING: Turn on, in the same request, one of the modules the module in details.module requires (getOrganizationModules lists them).CAPABILITY_NOT_CONFIGURED: Do not retry. The capability is not enabled for this organization.INSTALLATION_NOT_READY: Do not retry unchanged. Wait for a certified app version, record examples that cover every operation and change of a custom-http installation, or add the missing credentials to the deployment, then activate again.EVIDENCE_NOT_READABLE: Leave the evidence pending until its source content is readable.ANALYTICS_QUERY_LIMIT: Narrow the query (filters, columns or range) and retry.
500
Failure. The error.code is one of:
INVALID_CONFIGURATION: Retry once later; if it persists, report the requestId to support.INTERNAL: Retry once later; if it persists, report the requestId to support.
503
Failure. The error.code is one of:
AUTHENTICATION_UNAVAILABLE: Retry later with backoff; for a write, reuse the same requestKey.COMMIT_UNCERTAIN: The write may have happened. Repeat it with the same requestKey or read the record first.DATABASE_UNAVAILABLE: Retry later with backoff; for a write, reuse the same requestKey.PIPELINE_UNAVAILABLE: The write may have happened. Repeat it with the same requestKey or read the record first.ASSISTANT_UNAVAILABLE: Do not retry. The capability is not enabled for this organization.SERVICE_BUSY: Retry later with backoff; for a write, reuse the same requestKey.