In the last installment, we modified our application so that it could switch between family members for data display and entry. This time, we’re going to add a table at the top that shows the current weight for all family members.

We add the table right after the <h1> title:

Family Summary <br />
<asp:Table ID="c_tableSummary" runat="server" BorderWidth="1px" CellPadding="2" CellSpacing="2" GridLines="Both"/>
<br />

Then we need a method to walk through the records and fetch the current weight from each of them. The following will do that:

void GenerateSummaryTable()
{
    TableHeaderRow headerRow = new TableHeaderRow();
    TableHeaderCell headerCell = new TableHeaderCell();
    headerCell.Text = "Name";
    headerRow.Cells.Add(headerCell);

    headerCell = new TableHeaderCell();
    headerCell.Text = "Weight";
    headerRow.Cells.Add(headerCell);

    c_tableSummary.Rows.Add(headerRow);

    foreach (HealthRecordInfo record in PersonInfo.AuthorizedRecords.Values)
    {
        HealthRecordSearcher searcher = record.CreateSearcher();

        HealthRecordFilter filter = new HealthRecordFilter(Weight.TypeId);
        filter.MaxItemsReturned = 1;

        searcher.Filters.Add(filter);

        HealthRecordItemCollection weights = searcher.GetMatchingItems()[0];

        if (weights.Count == 1)
        {
            TableRow row = new TableRow();

            TableCell nameCell = new TableCell();
            nameCell.Text = record.Name;
            row.Cells.Add(nameCell);

            Weight weight = weights[0] as Weight;

            TableCell weightCell = new TableCell();
            weightCell.Text = weight.Value.DisplayValue.ToString();
            row.Cells.Add(weightCell);

            c_tableSummary.Rows.Add(row);
        }
    }

Currently, there is no way to make a single request that fetches data for more than one record, so we need to create an execute a separate query for each one.

Next Time

With all the operations that we are performing, the application is running a little bit slowly. We’ll do some investigation into what’s going on, and see if we can’t make some improvements.