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.

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.

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

val attributes = PassioSDK.instance.lookupPassioAttributesFor(passioID)

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.

PassioIDAttributes

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 for the given image name use

val drawable = lookupImageForFilename(context, imageName)

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

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

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.

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

fun lookupPassioIDFor(name: String): PassioID?

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

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

Last updated