> For the complete documentation index, see [llms.txt](https://docs.mdintegrations.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mdintegrations.com/partner/key-concepts/pharmacy-fulfillment/partner-owned-transmission/example-mapping-to-lifefile.md).

# Example: Mapping to LifeFile

This example maps MDI data onto LifeFile's order API within a [Pharmacy Fulfillment](/partner/key-concepts/pharmacy-fulfillment.md) workflow.

Treat this as a worked example, not a generic pharmacy specification — you'll need to adapt both the workflow and the field mappings to whatever schema and authentication your own pharmacy actually requires.

### Before you begin

You need:

* A configured Service Offering and partner-owned transmission workflow.
* An MDI access token from .
* LifeFile HTTP Basic Authentication credentials.
* LifeFile's `X-Vendor-ID`, `X-Location-ID`, and `X-API-Network-ID` headers.

### Order workflow

{% stepper %}
{% step %}

#### Receive approval

Listen for the `offering_submitted` webhook, which confirms the Encounter is approved and its prescription data is ready to map.
{% endstep %}

{% step %}

#### Identify the Encounter

Read `case_id` from the webhook payload, then use it to retrieve both the Offering and the Service PDF.
{% endstep %}

{% step %}

#### Map the data

Build the LifeFile order from the patient, prescriber, Offering, and shipping data, following the field mappings listed below.
{% endstep %}

{% step %}

#### Add the Service PDF when required

If the order involves a controlled substance, retrieve the Service PDF and Base64-encode it before attaching it to the LifeFile order.
{% endstep %}

{% step %}

#### Submit the order

Submit the completed order to LifeFile's order endpoint to finish the handoff.
{% endstep %}
{% endstepper %}

### Field mappings

| MDI source                                      | LifeFile field          | Mapping rule                                                                         |
| ----------------------------------------------- | ----------------------- | ------------------------------------------------------------------------------------ |
| Patient name, date of birth, and address        | Patient block           | Transfer without conversion.                                                         |
| Patient gender                                  | Patient gender          | Convert `1` to `m`, `2` to `f`, and `0` to `u`.                                      |
| Clinician `licenses` entry with `type == "npi"` | Prescriber NPI          | Must be exactly 10 digits.                                                           |
| Clinician last name                             | Prescriber last name    | Transfer without conversion.                                                         |
| Clinician state                                 | Prescriber state        | Convert to the two-character postal code.                                            |
| Each case Offering's `product` data             | `rxs` entry             | Create one entry per Offering. Include drug name, quantity, refills, and directions. |
| New UUID                                        | Prescription ID         | Generate a Version 4 UUID for each new prescription.                                 |
| Base64-encoded Service PDF                      | `document.pdfBase64`    | Required only for controlled substances.                                             |
| Patient or recipient name                       | Shipping recipient name | Limit to 30 characters.                                                              |
| Patient phone number                            | Shipping phone          | Format as `(987) 654-3210`.                                                          |

{% hint style="warning" %}
Download and encode the PDF immediately. Do not save the temporary URL for later use.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.mdintegrations.com/partner/key-concepts/pharmacy-fulfillment/partner-owned-transmission/example-mapping-to-lifefile.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
