locked
GetItem by item index RRS feed

  • Question

  • I'm trying to get the last item of HV Thing Type items stored in the person's selected record (see below).

    I have to create the Thing Type item, then retrieve it's LastUpdated.Timestamp to store in our db for record tracking purposes.

    I've tried getting the count of the list, then using the count number as the item's index to retrieve the last record.

    Doesn't throw any errors, but doesn't pick up the HV item data.

    Would appreciate some help.

    Directive directive_push = new Directive();
                    directive_push.Description = directives_description;
                    ApproximateDateTime startdate = new ApproximateDateTime(new ApproximateDate(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day));
                    directive_push.StartDate = startdate;
                    ApproximateDateTime stopdate = new ApproximateDateTime(new ApproximateDate(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day));
                    directive_push.StopDate = stopdate;
                    PersonInfo.SelectedRecord.NewItem(directive_push);
                    // get list, figure out list count, get last item of the count
                    List<Directive> directives_count = GetValues<Directive>(Directive.TypeId);
                    int i=0;
                    int directives_count_last=0;
                    while (i < directives_count.Count)
                    {
                        if (i == directives_count.Count)
                        {
                            directives_count_last = i;
                        }
                        else
                        {
                            i++;
                        }
                    }
                    HealthRecordSearcher searcher = PersonInfo.SelectedRecord.CreateSearcher();
                    HealthRecordFilter filter = new HealthRecordFilter(Directive.TypeId);
                    filter.View.Sections = HealthRecordItemSections.All;
                    searcher.Filters.Add(filter);
                    HealthRecordItemCollection weights = searcher.GetMatchingItems()[directives_count_last];
                    foreach (Directive weight in weights)
                    {
                        get_directive_wc_id = weight.Key.Id.ToString();
                        get_directive_wc_version = weight.Key.VersionStamp.ToString();
                        get_directive_wc_date = weight.LastUpdated.Timestamp.ToString("s");
                    }

    Thanks,
    Gary
    Monday, October 5, 2009 3:31 PM

Answers

  • Hello Gary,

    Can you please confirm whether you are getting a non-null value for the object weights? If you are getting a null value can you try using searcher.GetMatchingItems()[0]? Because the index used here indicates which filter you are referring to.

    Hope this helps.

    Thanks and Regards,
    Aneesh D.
    Monday, October 5, 2009 3:59 PM
  • Thanks Aneesh, I forgot to check for a null value.

    I'll try it out.


    Monday, October 5, 2009 7:48 PM

All replies

  • Hello Gary,

    Can you please confirm whether you are getting a non-null value for the object weights? If you are getting a null value can you try using searcher.GetMatchingItems()[0]? Because the index used here indicates which filter you are referring to.

    Hope this helps.

    Thanks and Regards,
    Aneesh D.
    Monday, October 5, 2009 3:59 PM
  • Thanks Aneesh, I forgot to check for a null value.

    I'll try it out.


    Monday, October 5, 2009 7:48 PM