# Nutrition data

The main object containing the nutritional information is called PassioFoodItem. This object is fetched from Passio's backend using one of several `fetchFoodItemFor...` functions.&#x20;

## PassioFoodItem

The PassioFoodItem is a top level object that can represent a single food like a banana, or a complex recipe like caesar salad.

{% tabs %}
{% tab title="iOS" %}
```swift
public struct PassioFoodItem: Codable {
    public let id: String
    public let name: String
    public let details: String
    public let iconId: String
    public let licenseCopy: String
    public let amount: PassioNutritionAISDK.PassioFoodAmount
    public let ingredients: [PassioNutritionAISDK.PassioIngredient]
    public let refCode: String?
}
```
{% endtab %}

{% tab title="Android" %}
```kotlin
data class PassioFoodItem(
    val id: String,
    val refCode: String,
    val name: String,
    val details: String,
    val iconId: String,
    val amount: PassioFoodAmount,
    val ingredients: List<PassioIngredient>,
)
```
{% endtab %}

{% tab title="React Native" %}
```typescript
export interface PassioFoodItem {
  refCode?: RefCode
  name: string
  details?: strin
  iconId: PassioID | string
  amount: PassioFoodAmount
  ingredients?: PassioIngredient[]
  weight: UnitMass
  isOpenFood?: boolean
  openFoodLicense?: string
  id: string
}
```
{% endtab %}

{% tab title="Flutter" %}
```dart
class PassioFoodItem {
  final PassioFoodAmount amount;
  final String details;
  final String iconId;
  final String id;
  final List<PassioIngredient> ingredients;
  final String name;
  final String refCode;
  final PassioID? scannedId;
 }
```
{% endtab %}
{% endtabs %}

* The `name` attribute is used to display the name of the food, while the `details` contains additional information like the brand of the food or the name of the food which was used to populate the nutritional data
* `iconId` is used with the SDK function `fetchIconFor` to fetch a small image of the food
* `refCode` is a parameter that can be used later on to retrieve the full food item again
* `amount` details the available serving size as well as the currently selected serving quantity and unit, used when calculating nutrients

There are three functions that can be used to fetch nutrient information for the PassioFoodItem:

{% tabs %}
{% tab title="iOS" %}
```swift
PassioNutritionAI.shared.fetchFoodItemFor(passioID: "VEG0025") { (foodItem) in
        
  if let foodItem {
  
      // Getting nutrients for the referent 100 grams
      let nutrientsRef = foodItem.nutrientsReference()
            
      // Getting nutrients for a specific weight
      let nutrients250g = foodItem.nutrients(weight: Measurement<UnitMass>(value: 250.0, unit: .grams))
      
      // Getting nutrients using the amount->selectedQuantity and
      // amount->selectedUnit
      let nutrientsServing = foodItem.nutrientsSelectedSize()
            
      // Weight of the ingredients
      let weight = foodItem.weight()
  }
}
```
{% endtab %}

{% tab title="Android" %}
<pre class="language-kotlin"><code class="lang-kotlin">PassioSDK.instance.<a data-footnote-ref href="#user-content-fn-1">fetchFoodItemForPassioID</a>("VEG0025") { foodItem ->
    // Getting nutrients for the referent 100 grams
    val nutrientsRef = foodItem!!.nutrientsReference()
    // Getting nutrients for a specific weight
    val nutrients250g = foodItem.nutrients(UnitMass(Grams, 250.0))
    // Getting nutrients using the amount->selectedQuantity and
    // amount->selectedUnit
    val nutrientsServing = foodItem.nutrientsSelectedSize()
    // Weight of the ingredients
val weight = foodItem.weight()
}
</code></pre>
{% endtab %}

{% tab title="React Native" %}
```typescript
   const passioFoodItem = await PassioSDK.fetchFoodItemForPassioID("VEG0025")
  
   // Getting nutrients for the referent 100 grams
   const nutrients =  PassioSDK.getNutrientsReferenceOfPassioFoodItem(passioFoodItem)
   
   // Getting nutrients for a specific weight
   const nutrients =  PassioSDK.getNutrientsOfPassioFoodItem(passioFoodItem,{unit:'g',value:250})
  
   // Getting nutrients using the amount->selectedQuantity and
   // amount->selectedUnit
   const nutrients =  PassioSDK.getNutrientsSelectedSizeOfPassioFoodItem(passioFoodItem)
 
   // Weight of the ingredients
   const val weight = passioFoodItem.weight()
```


{% endtab %}

{% tab title="Flutter" %}
```dart
    final foodItem = await NutritionAI.instance.fetchFoodItemForPassioID('VEG0025');
    // Getting nutrients for the referent 100 grams
    final nutrientsRef = foodItem!.nutrientsReference();
    // Getting nutrients for a specific weight
    final nutrients250g =
        foodItem.nutrients(UnitMass(250.0, UnitMassType.grams));
    // Getting nutrients using the amount->selectedQuantity and
    // amount->selectedUnit
    final nutrientsServing = foodItem.nutrientsSelectedSize();
    // Weight of the ingredients
    final weight = foodItem.weight();
```
{% endtab %}
{% endtabs %}

The `weight` function is used to fetch the sum mass of all of the ingredients.

### PassioFoodAmount

This class holds the information about possible serving sizes and serving units, as well as the currently selected unit and quantity. Example of values for food item "apples"

* serving units: small (2-3/4" dia), medium, large (3-1/4" dia), cup, oz, gram, ...
* serving sizes: 1 small (2-3/4" dia), 2 cups, 100 grams, ...
* selected quantity: 1
* selected unit: medium

Serving units holds the list of all of the units that the system has the correct weight for. \
Serving sizes holds the list of predefines matches of a quantity and a serving unit.\
The selected quantity and unit are used to calculate nutrients on the PassioFoodItem level. While these values can be changed, the initial values are set by the SDK as a default portion.

### PassioIngredient

Every PassioFoodItem has a list of ingredients. A food ingredient holds the nutritional information along with the portion size of each ingredient.

{% tabs %}
{% tab title="iOS" %}
```swift
public struct PassioIngredient: Codable {
    public let id: String
    public let name: String
    public let iconId: String
    public let amount: PassioFoodAmount
    public let referenceNutrients: PassioNutrients
    public let metadata: PassioFoodMetadata
    public let refCode: String?
}
```
{% endtab %}

{% tab title="Android" %}
```kotlin
data class PassioIngredient(
    val id: String,
    val refCode: String,
    val name: String,
    val iconId: String,
    val amount: PassioFoodAmount,
    val referenceNutrients: PassioNutrients,
    val metadata: PassioFoodMetadata,
)
```
{% endtab %}

{% tab title="React Native" %}
<pre class="language-typescript"><code class="lang-typescript"><strong>export interface PassioIngredient {
</strong>  name: string
  id: PassioID
  iconId: PassioID | string
  weight?: UnitMass
  referenceNutrients?: PassioNutrients
  nutrients?: PassioNutrients
  metadata?: PassioFoodMetadata
  amount?: PassioFoodAmount
}
</code></pre>
{% endtab %}

{% tab title="Flutter" %}
```dart
class PassioIngredient {
  final PassioFoodAmount amount;
  final String iconId;
  final String id;
  final PassioFoodMetadata metadata;
  final String name;
  final String refCode;
  final PassioNutrients referenceNutrients;
}
```
{% endtab %}
{% endtabs %}

Similarly to [#passiofooditem](#passiofooditem "mention"), the ingredient also has a `name`, `iconId`, `refCode`, and `amount`.&#x20;

But, the most important part of the ingredient class is the `PassioNutrients` and it's methods. The referenceNutrients attribute holds the referent (in most cases 100 grams) macronutrients and micronutrients, and are used to calculate the resulting nutrient values when changing serving sizes of the whole PassioFoodItem.

Also, an ingredient has PassioMetadata field, storing the information on the origin of the nutritional data, barcode value, possible ingredients (if the PassioFoodItem is a packaged food), and a list of tags.

## Fetching nutrients

{% tabs %}
{% tab title="iOS" %}
```swift
PassioNutritionAI.shared.fetchFoodItemFor(passioID: "VEG0025") { (foodItem) in
  if let foodItem {
     let nutrients = foodItem.nutrientsReference()
     // Calories for 100 grams, values is in kCal
     let calories = nutrients.calories()?.value
     // Carbs for 100 grams, value is in grams
     let carbs = nutrients.carbs()?.value
     // Potassium for 100 grams, value is in milligrams
     let potassiumMilli = nutrients.potassium()?.value
     // Potassium for 100 grams, value is in grams
     let potassiumGrams = nutrients.potassium()?.gramsValue
  }
}
```
{% endtab %}

{% tab title="Android" %}
```kotlin
PassioSDK.instance.fetchFoodItemForPassioID("VEG0025") { foodItem ->
    val nutrients = foodItem!!.nutrientsReference()
    // Calories for 100 grams, values is in kCal
    val calories = nutrients.calories()?.value
    // Carbs for 100 grams, value is in grams
    val carbs = nutrients.carbs()?.value
    // Potassium for 100 grams, value is in milligrams
    val potassiumMilli = nutrients.potassium()?.value
    // Potassium for 100 grams, value is in grams
    val potassiumGrams = nutrients.potassium()?.gramsValue()
}
```
{% endtab %}

{% tab title="React Native" %}
```typescript
const passioFoodItem = await PassioSDKBridge.fetchFoodItemForPassioID("VEG0025")

   const nutrients =  PassioSDK.getNutrientsReferenceOfPassioFoodItem(passioFoodItem)
    // Calories for 100 grams, values is in kCal
     let calories = passioNutrients.calories?.value
     // Carbs for 100 grams, value is in grams
     let carbs = passioNutrients.carbs?.value
     // Potassium for 100 grams, value is in milligrams
     let potassiumMilli = passioNutrients.potassium?.value
```
{% endtab %}

{% tab title="Flutter" %}
```dart
    final foodItem = await NutritionAI.instance.fetchFoodItemForPassioID('VEG0025');
    final nutrients = foodItem!.nutrientsReference();
    // Calories for 100 grams, values is in kCal
    final calories = nutrients.calories?.value;
    // Carbs for 100 grams, value is in grams
    final carbs = nutrients.carbs?.value;
    // Potassium for 100 grams, value is in milligrams
    final potassiumMilli = nutrients.potassium?.value;
    // Potassium for 100 grams, value is in grams
    final potassiumGrams = nutrients.potassium?.gramsValue();
```
{% endtab %}
{% endtabs %}

## Single food item vs recipe

The PassioFoodItem class encompasses both single food items like an `avocado` as well as items with multiple ingredients such as `homemade caprese salad`. The difference between these two items is how is the PassioFoodAmount calculated from the top-level PassioFoodItem.&#x20;

Homemade caprese salad:

* weight(): 176.5 grams
* amount->selectedQuantity = 1
* amount->selectedUnit = "serving"
* ingredients:\
  1\. fresh sliced cheese, 84 grams, amount->selectedQuantity = 3, amount-> selectedUnit = "oz"\
  2\. balsamic vinegar, 16 grams, amount->selectedQuantity = 1, amount-> selectedUnit = "tbsp"\
  3\. fresh basil, 3 grams, amount->selectedQuantity = 6, amount-> selectedUnit = "leaves"\
  4\. tomatoes, 60 grams, amount->selectedQuantity = 3, amount-> selectedUnit = "medium slice"\
  5\. olive oil, 13.5 grams, amount->selectedQuantity = 1, amount-> selectedUnit = "tbsp"

Invoking the function foodItem.nutrientsServingSize() will fetch the nutrients for the whole recipe, calculated by the weight of the serving size "1 serving".

Avocado:

* weight(): 201 grams
* amount->selectedQuantity = 1
* amount->selectedUnit = "avocado"
* ingredients:\
  1\. `avodaco, raw`, 201 grmas, amount->selectedQuantity = 1, amount->selectedUnit = "avocado"

A single food item will always have only one ingredient. Also, the amount object of the PassioFoodItem will be the same as the amount of the first ingredient. The ingredient is the item in the database used for nutritional data. For example, If the SDK recognises "milk" during the visual detection process, the default food item for "milk" is "milk, whole, 3.25% milkfat, without added vitamin a and vitamin d".

## UI Example

1. Fetch the PassioFoodItem
2. Use the name, details and [iconId](../../../../guides/nutrition-ai-sdk/use-cases/search-food-icons-refcode#food-icons) to create the food header view
3. Use the nutrientsSelectedSize->calories, carbs, protein and fat to show the marcos
4. Use the amount class to create the serving size view
5. Give the user the option to log the food

<figure><img src="https://872966647-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FES2kGechp4srgCTrBTxs%2Fuploads%2FwPcD7dWKyIwwcMvvgZhd%2FScreenshot%202024-08-14%20at%2019.17.18.png?alt=media&#x26;token=3d8a7b50-1882-447f-8033-378b40efbe48" alt="" width="220"><figcaption></figcaption></figure>

[^1]: 
