# Nutritional Database

Once the food detection process has returned a PassioID, it is time to query the database and see what information Passio has on the detected food.

{% hint style="warning" %}
All the calls to the database are synchronous and are executed on the caller thread. For better performance execute these calls on a background thread.
{% endhint %}

The most detailed information can be found in the PassioIDAttributes object. To retrieve this object from a given PassioID, simply call

```kotlin
val attributes = PassioSDK.instance.lookupPassioAttributesFor(passioID)
```

{% hint style="warning" %}
This call may return null if the given PassioID can't be found in the database. Be sure to check the nullability of the return object before proceeding.
{% endhint %}

### PassioIDAttributes

```kotlin
data class PassioIDAttributes(
    var passioID: PassioID,
    var name: String,
    var imageName: String,
    val entityType: PassioIDEntityType,
    var parents: List<PassioAlternative>?,
    var children: List<PassioAlternative>?,
    var siblings: List<PassioAlternative>?,
    val passioFoodItemDataForDefault: PassioFoodItemData?,
    val passioFoodRecipe: PassioFoodRecipe?,
    val condiments: List<PassioFoodItemData>? = null
)
```

Here we will cover the fields that are not self-explanatory:

1. imageName - An identifier for the image of the food. To retrieve the [Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable) for the given image name use

```kotlin
val drawable = lookupImageForFilename(context, imageName)
```

The image for a food can also be retrieved using the PassioID and the method

```kotlin
val drawable = lookupImageFor(context, passioID)
```

1. parents, children, siblings - All the foods in Passio's Nutritional Database are organized in a tree-like structure with each PassioID being a node in that tree. Let's say we scanned a "mandarin". A child of a "mandarin" is a "tangerine", and its parent is a "whole citrus fruit". We can offer these alternatives to the user in case the user is pointing to a similar food to a mandarin.
2. passioFoodItemDataForDefault, passioFoodRecipe - The SDK differentiates single food items and food recipes. A single item represents just one particular food like an apple or peas. A food recipe consists of more than one single food item. For example a recipe is a Caprese salad which consists of mozzarella, tomatoes, basil, salt, black pepper and olive oil.

### PassioFoodItemData



```kotlin
data class PassioFoodItemData(
    var passioID: PassioID,
    var name: String,
    var imageName: String
) {
    var referenceWeight = UnitMass(Grams(), 0.0)
    var fat: Double?
    var satFat: Double?
    var monounsaturatedFat: Double?
    var polyunsaturatedFat: Double?
    var proteins: Double?
    var carbs: Double?
    var calories: Double?
    var saturatedFat: Double?
    var cholesterol: Double?
    var sodium: Double?
    var fibers: Double?
    var transFat: Double?
    var sugars: Double?
    var sugarsAdded: Double?
    var alcohol: Double?
    var iron: Double?
    var vitaminC: Double?
    var vitaminA: Double?
    var vitaminD: Double?
    var calcium: Double?
    var potassium: Double?
    var sugarAlcohol: Double?

    var servingSizes: List<PassioServingSize>
    var servingUnits: List<PassioServingUnit>
    var entityType: PassioIDEntityType 
    var alternatives: List<PassioAlternative>?
    var foodOrigins: List<PassioFoodOrigin>?
}
```

PassioFoodItemData holds the nutritional information for a food item like calories, carbs, protein, fat etc. It also has a reference weight on which these values are calculated and contains serving sizes and serving units. Serving sizes offer you quick options to select the size of the food with a given quantity and unit.

### PassioFoodRecipe

Recipes should be viewed as a collection of PassioFoodItemData objects.

```kotlin
data class PassioFoodRecipe(
    var passioID: PassioID,
    var name: String,
    var filenameIcon: String,
    var foodItems: MutableList<PassioFoodItemData>,
) {
    var servingSizes: List<PassioServingSize>
    var servingUnits: List<PassioServingUnit>
}
```

### Other useful queries

If you have a PassioID returned from the detection process and you are just interested in the name of the corresponding food, use

```kotlin
fun lookupPassioIDFor(name: String): PassioID?
```

To query the names of the foods from the database by a filter use

```kotlin
fun searchForFood(byText: String): List<Pair<PassioID, String>>
```

The returned list contains a PassioID paired with the name of the food.

If at any point you need help from the Passio team, please reach out to us at **support@passiolife.com**
