Wrong column selected by Rlabkey when retrieving visits

LabKey Support Forum
Wrong column selected by Rlabkey when retrieving visits Edward  2019-10-21 06:26
Status: Active
 

I have a home folder where in I have five different sub-studies. In each of the sub-study, the visits starts from 1.1 to 12.1. When I try to retrieve rows from the tables in each of the study, only the first study returns correct sequences, i.e 1.1-12.1. Other sub-studies, return integer values such 7-19 or 48-60. When I tried to import the visit map through the following code, I found out that actually these returned integers are Rows Id and not the sequence number or the visit label. Can you kindly fix this issue? or is there any alternative to get all the columns of a table (except the hidden ones) plus the visit label?

labkey.data <- labkey.selectRows(
    baseUrl=labkey.url.base,
    folderPath=labkey.url.path,
    schemaName="study",
    queryName="Visit"
)

 
 
Edward responded:  2019-10-22 00:08

By closely examining different study tables in the database, where visits are defined, I found out that somehow labkey is fetching values from the "Row Id" from the visits tables. This I think is the bug. Perhaps it could be addressed by changing the "Row Id" in each table (wherever there are visits defined) to the actual numeric values of the visits? However, for this I will need to find out all the tables where visits are associated (row id) with other tables so that the tables' relationships in my database do not break. I have already found that "visit" and "participantvisit" are two tables that are associated and the row ids need to be change in both of them. What do you suggest in this case?

 
cnathe responded:  2019-10-22 06:10

Edward,
I have a couple of quick questions that might help us to figure out what is causing the visit RowIds to be returned from your query instead of the Sequence Numbers.

  1. Are you querying each sub-study separately? or are you trying to do a top level query at the LabKey project level to get all of the data at once?
  2. Can you give us an example of the Rlabkey selectRows call you are using for the study data query? If we can see an example, we might be able to test it against some of our LabKey demo studies to see if they are showing similar behavior.
    Thanks,
    Cory Nathe
 
Edward responded:  2019-10-23 00:48

Hi Cory,

  1. I am querying each sub-study individually as there are different users for each of the sub-study and these users should be able to query only their own study.

  2. I use the following code for selecting rows from each sub-study:

my.data <- labkey.selectRows(baseUrl="https://url_for_labkey",
                   folderPath="/StudyRootFolder/study1",
                   schemaName="study",
                   colNameOpt = 'rname',
                   colSort = "+patient_id",
                  queryName="Patients_Demographics") 

At the back-end in postgresql, in tables "visit" and "participantvisit", I changed the "row id" number to values representing my actual visits and now when I query the sub-studies, I get the updated visits. However, it is strange that labkey.selectRows picks "row id" and not the actual visits.

 
cnathe responded:  2019-10-23 06:15

Edward,
I would advise against making direct updates to the back-end postgresql LabKey tables. As you mentioned there are several tables that reference the visit RowId that may be affected by a change to this table.

I was able to reproduce the behavior you are seeing locally using my Demo visit based study. As you are seeing, we return the visit RowIds by default for these selectRows query response. There is a parameter that you can pass to the labkey.selectRows call to help: includeDisplayValues=TRUE. This will add in a column for the visit label. Here is an example from my Demo Study:

labkey.data <- labkey.selectRows(
  baseUrl="http://localhost:8080/labkey", 
  folderPath="/Demo Study/Visit Study", 
  schemaName="study", 
  queryName="TestDataSet1", 
  colNameOpt="rname",
  includeDisplayValues=TRUE
)

  participantid participantvisit_visit field1 field2        review_state participantvisit_visit_label
1           123                   9749  test1      1 Reviewed-Rejected 2                           V1
2           123                   9750  test2      2 Reviewed-Rejected 2                           V2
 
Edward responded:  2019-10-30 06:54
Status: Closed

Thank you very much! I have tried your code and it works for me.