locked
How to get item by index RRS feed

  • Question

  • Anyone know how to retrieve a HV item in a list by using it's index?

    Thanks,
    Gary
    Friday, October 9, 2009 4:34 PM

Answers


  • From the above code, I understand that you are trying to get the last item created for the record.

    This is the sample code: 

            HealthRecordSearcher searcher = PersonInfo.SelectedRecord.CreateSearcher();
            HealthRecordFilter filter = new HealthRecordFilter(Directive.TypeId);
            filter.View.Sections |= HealthRecordItemSections.Audits;
            filter.MaxItemsReturned = 1;
            searcher.Filters.Add(filter);
            HealthRecordItemCollection getlast_directive = searcher.GetMatchingItems()[0];

    With the above code , you can get the last created item. For more information on Data Filtering you can go through Eric's Blog.
    Hope this helps.


    -Mahesh
    • Marked as answer by Gary Isaac Friday, October 9, 2009 9:38 PM
    Friday, October 9, 2009 6:16 PM

All replies

  • Hi Gary,

    Can you please describe the scenario that you are trying to work out?

    If I understand your question correctly, you can use the key.Id property to verify the item.


    -Mahesh
    Friday, October 9, 2009 5:04 PM
  • I wanted to know if I should be using "T GetSingleValue<T>(Guid typeID) where T : class" to get an item by index.

    Please see highlighted code below.

    // CREATE NEW DIRECTIVE ITEM
    PersonInfo.SelectedRecord.NewItem(directive_push);

    // GET LIST THAT INCLUDES NEW ITEM ABOVE
    List<Directive> get_list_3_Directive = GetValues<Directive>(Directive.TypeId);

    // GET COUNT FOR INDEX OF LAST ITEM CREATED (ITEM ABOVE)               
    int i = 0;
    int get_list_3_Directive_count_last = 0;
    while (i < get_list_3_Directive.Count)
    {
      if (i == get_list_3_Directive.Count)
      {
        get_list_3_Directive_count_last = i - 1;
      }
      else
      {
         i++;
      }
    }
                   
    HealthRecordSearcher searcher = PersonInfo.SelectedRecord.CreateSearcher();
    HealthRecordFilter filter = new HealthRecordFilter(Directive.TypeId);
    filter.View.Sections = HealthRecordItemSections.All;
    searcher.Filters.Add(filter);

    // FIND LAST ITEM USING COUNT
    HealthRecordItemCollection get_list_4_Directive = searcher.GetMatchingItems()[get_list_3_Directive_count_last];

    // GET ITS VALUES
    foreach (Directive item in get_list_4_Directive)
    {
      get_directives_01_wc_id = item.Key.Id.ToString();
      get_directives_01_wc_version = item.Key.VersionStamp.ToString();
      get_directives_01_wc_date = item.LastUpdated.Timestamp.ToString("s");
     }


    // INSERT THESE VALUES INTO DB
     string query_04_directives = "UPDATE directives SET wc_id = '" + get_directives_01_wc_id + get_directives_01_wc_date + "', wc_version = '" + get_directives_01_wc_version + "'WHERE id = '" + directives_id + "'";
                 
    Friday, October 9, 2009 5:07 PM

  • From the above code, I understand that you are trying to get the last item created for the record.

    This is the sample code: 

            HealthRecordSearcher searcher = PersonInfo.SelectedRecord.CreateSearcher();
            HealthRecordFilter filter = new HealthRecordFilter(Directive.TypeId);
            filter.View.Sections |= HealthRecordItemSections.Audits;
            filter.MaxItemsReturned = 1;
            searcher.Filters.Add(filter);
            HealthRecordItemCollection getlast_directive = searcher.GetMatchingItems()[0];

    With the above code , you can get the last created item. For more information on Data Filtering you can go through Eric's Blog.
    Hope this helps.


    -Mahesh
    • Marked as answer by Gary Isaac Friday, October 9, 2009 9:38 PM
    Friday, October 9, 2009 6:16 PM
  • Oh... excellent!

    Thanks, Mahesh.

    That makes things a lot easier.

    Gary
    Friday, October 9, 2009 9:38 PM