> For the complete documentation index, see [llms.txt](https://docs.mindee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mindee.com/v1/off-the-shelf-products/us-healthcare-cards.md).

# US Healthcare Cards OCR

Mindee’s US Healthcare Cards API uses deep learning to automatically, accurately, and instantaneously parse your documents details. In a few seconds, the API extracts a set of data from your PDFs or photos of US healthcare cards, including:

* Company Name
* Member Name
* Member ID
* Issuer 80840
* Dependents
* Group Number
* Payer ID
* RX BIN
* RX GRP
* RX PCN
* Copays
* Enrollment date

The US Healthcare Cards OCR API supports documents from the USA. The healthcare cards from other nationalities and states are not supported with this model.

## Set up the API

{% hint style="info" %}
**Create an API key**

To begin using the Mindee V1 OCR API, your first step is to [create your V1 API key](/v1/get-started/create-api-key.md).
{% endhint %}

1. You'll need a healthcare card sample. You can use the sample document provided below.

   <figure><img src="/files/F7gIeQ7tnXxyCDkv9Td2" alt=""><figcaption></figcaption></figure>
2. Access your US Healthcare Cards API by clicking on the corresponding product card in the **Document Catalog**

   <figure><img src="/files/MpTfjiyGFljvCG1mJvvo" alt=""><figcaption></figcaption></figure>
3. From the left navigation, go to [**documentation**](doc:platform-tour#api---documentation) **> API Reference**, you'll find sample code in popular languages and command line.

{% tabs %}
{% tab title="Python" %}

```python
from mindee import Client, product, AsyncPredictResponse

# Init a new client
mindee_client = Client(api_key="my-api-key-here")

# Load a file from disk
input_doc = mindee_client.source_from_path("/path/to/the/file.ext")

# Load a file from disk and enqueue it.
result: AsyncPredictResponse = mindee_client.enqueue_and_parse(
    product.us.HealthcareCardV1,
    input_doc,
)

# Print a brief summary of the parsed data
print(result.document)
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const mindee = require("mindee");
// for TS or modules:
// import * as mindee from "mindee";

// Init a new client
const mindeeClient = new mindee.v1.Client({ apiKey: "my-api-key-here" });

// Load a file from disk
const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext");

// Parse the file
const apiResponse = mindeeClient.enqueueAndParse(
  mindee.v1.product.us.HealthcareCardV1,
  inputSource
);

// Handle the response Promise
apiResponse.then((resp) => {
  // print a string summary
  console.log(resp.document.toString());
});
```

{% endtab %}

{% tab title=".NET" %}

```csharp
using Mindee;
using Mindee.Input;
using Mindee.Product.Us.HealthcareCard;

string apiKey = "my-api-key-here";
string filePath = "/path/to/the/file.ext";

// Construct a new client
MindeeClient mindeeClient = new MindeeClient(apiKey);

// Load an input source as a path string
// Other input types can be used, as mentioned in the docs
var inputSource = new LocalInputSource(filePath);

// Call the product asynchronously with auto-polling
var response = await mindeeClient
    .EnqueueAndParseAsync<HealthcareCardV1>(inputSource);

// Print a summary of all the predictions
System.Console.WriteLine(response.Document.ToString());

// Print only the document-level predictions
// System.Console.WriteLine(response.Document.Inference.Prediction.ToString());
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
#
# Install the Ruby client library by running:
# gem install mindee
#

require 'mindee'

# Init a new client
mindee_client = Mindee::Client.new(api_key: 'my-api-key')

# Load a file from disk
input_source = mindee_client.source_from_path('/path/to/the/file.ext')

# Parse the file
result = mindee_client.parse(
  input_source,
  Mindee::Product::US::HealthcareCard::HealthcareCardV1
)

# Print a full summary of the parsed data in RST format
puts result.document

# Print the document-level parsed data
# puts result.document.inference.prediction
```

{% endtab %}

{% tab title="Java" %}

{% endtab %}

{% tab %}

```java
import com.mindee.MindeeClient;
import com.mindee.input.LocalInputSource;
import com.mindee.parsing.common.AsyncPredictResponse;
import com.mindee.product.us.healthcarecard.HealthcareCardV1;
import java.io.File;
import java.io.IOException;

public class SimpleMindeeClient {

  public static void main(String[] args) throws IOException, InterruptedException {
    String apiKey = "my-api-key-here";
    String filePath = "/path/to/the/file.ext";

    // Init a new client
    MindeeClient mindeeClient = new MindeeClient(apiKey);

    // Load a file from disk
    LocalInputSource inputSource = new LocalInputSource(new File(filePath));

    // Parse the file asynchronously
    AsyncPredictResponse<HealthcareCardV1> response = mindeeClient.enqueueAndParse(
        HealthcareCardV1.class,
        inputSource
    );

    // Print a summary of the response
    System.out.println(response.toString());

    // Print a summary of the predictions
//  System.out.println(response.getDocumentObj().toString());

    // Print the document-level predictions
//    System.out.println(response.getDocumentObj().getInference().getPrediction().toString());

    // Print the page-level predictions
//    response.getDocumentObj().getInference().getPages().forEach(
//        page -> System.out.println(page.toString())
//    );
  }

}
```

{% endtab %}

{% tab title="Bash" %}

```bash
API_KEY='my-api-key-here'
ACCOUNT='mindee'
ENDPOINT='us_healthcare_cards'
VERSION='1'
FILE_PATH='/path/to/your/file.png'

# Maximum amount of retries to get the result of a queue
MAX_RETRIES=10

# Delay between requests
DELAY=6

# Enqueue the document for async parsing
QUEUE_RESULT=$(curl -sS --request POST \
  -H "Authorization: Token $API_KEY" \
  -H "Content-Type: multipart/form-data" \
  -F "document=@$FILE_PATH" \
  "https://api.mindee.net/v1/products/$ACCOUNT/$ENDPOINT/v$VERSION/predict_async")

# Status code sent back from the server
STATUS_CODE=$(echo "$QUEUE_RESULT" | grep -oP "[\"|']status_code[\"|']:[\s][\"|']*[a-zA-Z0-9-]*" | rev | cut --complement -f2- -d" " | rev)

# Check that the document was properly queued
if [ -z "$STATUS_CODE" ] || [ "$STATUS_CODE" -gt 399 ] || [ "$STATUS_CODE" -lt 200 ]
then
  if [ -z "$STATUS_CODE" ]
  then
    echo "Request couldn't be processed."
    exit 1
  fi
  echo "Error $STATUS_CODE was returned by API during enqueuing. "

  # Print the additional details, if there are any:
  ERROR=$(echo "$QUEUE_RESULT" | grep -oP "[\"|']error[\"|']:[\s]\{[^\}]*" | rev | cut --complement -f2- -d"{" | rev)
  if [ -z "$ERROR" ]
  then
    exit 1
  fi

  # Details on the potential error:
  ERROR_CODE=$(echo "$ERROR" | grep -oP "[\"|']code[\"|']:[\s]\"[^(\"|\')]*" | rev | cut --complement -f2- -d"\"" | rev)
  MESSAGE=$(echo "$QUEUE_RESULT" | grep -oP "[\"|']message[\"|']:[\s]\"[^(\"|\')]*" | rev | cut --complement -f2- -d"\"" | rev)
  DETAILS=$(echo "$QUEUE_RESULT" | grep -oP "[\"|']details[\"|']:[\s]\"[^(\"|\')]*" | rev | cut --complement -f2- -d"\"" | rev)
  echo "This was the given explanation:"
  echo "-------------------------"
  echo "Error Code: $ERROR_CODE"
  echo "Message: $MESSAGE"
  echo "Details: $DETAILS"
  echo "-------------------------"
  exit 1
else

  echo "File sent, starting to retrieve from server..."

  # Get the document's queue ID
  QUEUE_ID=$(echo "$QUEUE_RESULT" | grep -oP "[\"|']id[\"|']:[\s][\"|'][a-zA-Z0-9-]*" | rev | cut --complement -f2- -d"\"" | rev)

  # Amount of attempts to retrieve the parsed document were made
  TIMES_TRIED=1

  # Try to fetch the file until we get it, or until we hit the maximum amount of retries
  while [ "$TIMES_TRIED" -lt "$MAX_RETRIES" ]
  do
    # Wait for a bit at each step
    sleep $DELAY

    # Note: we use -L here because the location of the file might be behind a redirection
    PARSED_RESULT=$(curl -sS -L \
      -H "Authorization: Token $API_KEY" \
      "https://api.mindee.net/v1/products/$ACCOUNT/$ENDPOINT/v$VERSION/documents/queue/$QUEUE_ID")

    # Isolating the job (queue) & the status to monitor the document
    JOB=$(echo "$PARSED_RESULT" | grep -ioP "[\"|']job[\"|']:[\s]\{[^\}]*" | rev | cut --complement -f2- -d"{" | rev)
    QUEUE_STATUS=$(echo "$JOB" | grep -ioP "[\"|']status[\"|']:[\s][\"|'][a-zA-Z0-9-]*" | rev | cut --complement -f2- -d"\"" | rev)
    if [ "$QUEUE_STATUS" = "completed" ]
    then
      # Print the result
      echo "$PARSED_RESULT"

      # Optional: isolate the document:
      # DOCUMENT=$(echo "$PARSED_RESULT" | grep -ioP "[\"|']document[\"|']:[\s].*([\"|']job[\"|'])" | rev | cut -f2- -d"," | rev)
      # echo "{$DOCUMENT}"

      # Remark: on compatible shells, fields can also be extracted through the use of tools like jq:
      # DOCUMENT=$(echo "$PARSED_RESULT" | jq '.["document"]')
      exit 0
    fi
    TIMES_TRIED=$((TIMES_TRIED+1))
  done
fi

echo "Operation aborted, document not retrieved after $TIMES_TRIED tries"
exit 1
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

use Mindee\Client;
use Mindee\Product\Us\HealthcareCard\HealthcareCardV1;

// Init a new client
$mindeeClient = new Client("my-api-key-here");

// Load a file from disk
$inputSource = $mindeeClient->sourceFromPath("/path/to/the/file.ext");

// Parse the file asynchronously
$apiResponse = $mindeeClient->enqueueAndParse(HealthcareCardV1::class, $inputSource);

echo $apiResponse->document;
```

{% endtab %}
{% endtabs %}

* Replace **my-api-key-here** with your new API key, or use the **select an API key** feature and it will be filled automatically.
* Copy and paste the sample code of your desired choice in your application, code environment, terminal etc.
* Replace `/path/to/the/file.ext` with the path to your input document.

{% hint style="warning" %}
Remember to replace with your V1 API key.
{% endhint %}

4. Run your code. You will receive a JSON response with document details.

## API Response

Here is the full JSON response you get when you call the API:

```json
{
  "api_request": {
    "error": {},
    "resources": [
      "document",
      "job"
    ],
    "status": "success",
    "status_code": 200,
    "url": "https://api.mindee.net/v1/products/mindee/us_healthcare_cards/v1/documents/f003d541-8c70-4799-9d39-d7eb5fea8463"
  },
  "document": {
    "id": "f003d541-8c70-4799-9d39-d7eb5fea8463",
    "inference": {
      "extras": {},
      "finished_at": "2024-10-29T15:36:07.300000",
      "is_rotation_applied": true,
      "pages": [
        {
          "extras": {},
          "id": 0,
          "orientation": {
            "value": 0
          },
          "prediction": {}
        }
      ],
      "prediction": {
        "company_name": {
          "value": "UnitedHealthcare"
        },
        "copays": [
          {
            "service_fees": 40,
            "service_name": "specialist"
          }
        ],
        "dependents": [],
        "enrollment_date": {
          "value": null
        },
        "group_number": {
          "value": "12345"
        },
        "issuer_80840": {
          "value": null
        },
        "member_id": {
          "value": "12345678900"
        },
        "member_name": {
          "value": "John Smith"
        },
        "payer_id": {
          "value": null
        },
        "rx_bin": {
          "value": "610097"
        },
        "rx_grp": {
          "value": "COS"
        },
        "rx_pcn": {
          "value": "9999"
        }
      },
      "processing_time": 2.547,
      "product": {
        "features": [
          "company_name",
          "member_name",
          "member_id",
          "issuer_80840",
          "dependents",
          "group_number",
          "payer_id",
          "rx_bin",
          "rx_grp",
          "rx_pcn",
          "copays",
          "enrollment_date"
        ],
        "name": "mindee/us_healthcare_cards",
        "type": "standard",
        "version": "1.0"
      },
      "started_at": "2024-10-29T15:36:04.604000"
    },
    "n_pages": 1,
    "name": "ucard.jpg"
  },
  "job": {
    "available_at": "2024-10-29T15:36:07.311000",
    "error": {},
    "id": "5be897aa-b930-4d5d-bf6f-6eeaaf24befe",
    "issued_at": "2024-10-29T15:36:04.604000",
    "status": "completed"
  }
}
```

You can find the prediction within the `prediction` key found in **`document > inference > prediction` for document-level predictions**: it contains the different fields extracted at the document level, meaning that for multi-pages PDFs, we reconstruct a single object using all the pages.

## Detailed Field Information

Using the above document example the following are the basic fields that can be extracted.

* [Company Name](#company-name)
* [Member Name](#member-name)
* [Member ID](#member-id)
* [Issuer 80840](#issuer-80840)
* [Dependents](#dependents)
* [Group Number](#group-number)
* [Payer ID](#payer-id)
* [RX BIN](#rx-bin)
* [RX GRP](#rx-grp)
* [RX PCN](#rx-pcn)
* [Copays](#copays)
* [Enrollment date](#enrollment-date)

### Company Name

* **company\_name**: The name of the company that provides the healthcare plan.

```json
{
  "company_name": {
    "value": "UnitedHealthcare"
  }
}
```

### Member Name

* **member\_name**: The name of the member covered by the healthcare plan.

```json
{
  "member_name": {
    "value": "John Smith"
  }
}
```

### Member ID

* **member\_id**: The unique identifier for the member in the healthcare system.

```json
{
  "member_id": {
    "value": "12345678900"
  }
}
```

### Issuer 80840

* **issuer\_80840**: The organization that issued the healthcare plan.

```json
{
  "issuer_80840": {
    "value": null
  }
}
```

### Dependents

* **dependents**: The list of dependents covered by the healthcare plan.

```json
{
  "dependents": []
}
```

### Group Number

* **group\_number**: The group number associated with the healthcare plan.

```json
{
  "group_number": {
    "value": "12345"
  }
}
```

### Payer ID

* **payer\_id**: The unique identifier for the payer in the healthcare system.

```json
{
  "payer_id": {
    "value": null
  }
}
```

### RX BIN

* **rx\_bin**: The BIN number for prescription drug coverage.

```json
{
  "rx_bin": {
    "value": "610097"
  }
}
```

### RX GRP

* **rx\_grp**: The group number for prescription drug coverage.

```json
{
  "rx_grp": {
    "value": "COS"
  }
}
```

### RX PCN

* **rx\_pcn**: The PCN number for prescription drug coverage.

```json
{
  "rx_pcn": {
    "value": "9999"
  }
}
```

### Copays

* **copays**: Is a fixed amount for a covered service.
  * **service\_name**: The name of service of the copay.
  * **service\_fees**: The price of service.

```json
{
  "copays": [
    {
      "service_fees": 40,
      "service_name": "specialist"
    }
  ]
}
```

### Enrollment Date

* **enrollment\_date**: The date when the member enrolled in the healthcare plan.

```json
{
  "enrollment_date": {
    "value": null
  }
}
```


---

# 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.mindee.com/v1/off-the-shelf-products/us-healthcare-cards.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.
