Processing one HealthRecordItem at a time…

The default behavior of the HealthRecordItemCollection class is to page in HealthRecordItems as you iterate through it, and when you are finished processing all of the items, they will all be in memory.

If the items you are dealing with are big (such as CCR or CCD) and/or there are a lot of them, this may use more memory than you want. The following method shows how to process the items one at a time.

void FetchOneAtATime()
        // Fetch all the item ids...
    HealthRecordSearcher searcher = PersonInfo.SelectedRecord.CreateSearcher(Weight.TypeId);
    searcher.Filters[0].MaxFullItemsReturnedPerRequest = 0;

    XPathNavigator navigator = searcher.GetMatchingItemsRaw();

    List<Guid> itemIds = new List<Guid>();

    foreach (XPathNavigator idNode in navigator.Select("group/unprocessed-thing-key-info/thing-id"))
        itemIds.Add(new Guid(idNode.Value));

        // fetch the items one at a time.

    foreach (Guid itemId in itemIds)
        Weight weight = (Weight) PersonInfo.SelectedRecord.GetItem(itemId);

Setting MaxFullItemsReturnedPerRequest to zero tells the SDK to only fetch the key information rather than fetching all the items. This method pulls out the item ids from that and puts them into a list that you can use as you wish; you can call GetItem() if you want to fetch one at a time or you could set up a filter that fetches a subset of the items in one operation.

We may provide a cleaner way to do this in the future.

Skip to main content