> ## Documentation Index
> Fetch the complete documentation index at: https://agents.nanonets.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# AdvancedMD Add Codes To Visit

> AdvancedMD coding write-back tool exposed through the Agents Platform.

This document covers `advancedmd_add_codes_to_visit`, the AdvancedMD coding write-back tool exposed through the Agents Platform.

## Authentication

Uses the existing AdvancedMD connector.

## Safety

`dry_run=true` remains the default. Non-dry-run uses AdvancedMD's proprietary Connect API charge-entry flow (`@class="chargeentry"`, `@action="updvisitwithcharges"`) modeled from Fleming's lower-level `AddCharge` / `UpdateChargeInVisit` helpers.

The exact method-level API docs are not public; AdvancedMD's public developer pages confirm Connect APIs support CRUD-style PM workflows, and AdvancedMD product docs describe charge-entry / charge-detail workflows. The XML payload here follows Fleming's existing implementation rather than guessing from public docs.

## `advancedmd_add_codes_to_visit`

Writes approved CPT/ICD/modifier coding data to existing AdvancedMD visit charges.

Important limitation: each non-dry-run charge must include `external_charge_id`. Public docs do not confirm safe creation semantics for brand-new charge IDs, so this tool updates known charges instead of inventing charge identifiers.

### Provider profile & facility preservation

`updvisitwithcharges` rewrites the visit record and clears any attribute it is not given, and the billing provider/facility are `@profile`/`@facility` on the **visit** element (AMD API docs June 2025) — omitting them is what reset 58 charges to a blank provider. This write now reads the visit record from `getchargedetaildataicd10`, echoes those values back, refuses to run if the provider cannot be read, and re-reads it afterwards to confirm it survived. `ADVANCEDMD_CHARGE_WRITE_ENABLED=false` is the ops kill switch. Full background: [AdvancedMD Unapply Payment — Provider profile & facility preservation](/docs/tools/advancedmd-unapply-payment#provider-profile--facility-preservation).

### Inputs

Required:

* `visit_id`
* `patient_id` when `dry_run=false`
* `charges`: Array of validated charges.
  * `external_charge_id` is required per charge when `dry_run=false`.

Optional:

* `supervising_provider_id`

### Output

```json theme={null}
{
  "success": true,
  "posted": true,
  "dry_run": false,
  "patient_id": "pat123",
  "visit_id": "vst123",
  "applied_charge_count": 2,
  "per_charge_errors": {},
  "raw_response": {
    "advancedmd_api_action": "updvisitwithcharges",
    "applied_charge_ids": ["charge123", "charge456"]
  }
}
```

## Human-readable text

The tool emits markdown for the feed: an `## AdvancedMD Dry Run` / `## AdvancedMD Codes Applied` summary table, a `## Charges` table (external id, CPT, diagnosis, modifiers, POS, TOS, units, fee, note), an `## Applied Charge IDs` table, and a `## Per-Charge Errors` section on failures. The full payload and raw response stay in `structuredContent`.

## Agent Instruction Guidance

Keep `dry_run=true` for first-pass coding suggestions. Only call with `dry_run=false` after biller approval, and only when the current visit summary gives you the target `patient_id` and existing AdvancedMD charge ids.
