Select fields from all datasets (study) with a custom query

LabKey Support Forum (Inactive)
Select fields from all datasets (study) with a custom query trent  2014-08-10 20:47
Status: Closed
 
In short - can I make it so that the customize view interface will display other datasets to add/remove columns using the customize view interface, against a custom query?

I have a dataset named "Clinical Results". So that I can specify what field is returned on a QueryWebPart using DataRegion.getChecked(), I have the following (simplified):

trenttest.sql:

select ParticipantSequenceNum, GGT
from "Clinical Results"

trenttest.query.xml:

<query xmlns="http://labkey.org/data/xml/query">

    <metadata>

        <ns:tables xmlns:ns="http://labkey.org/data/xml">
          <ns:table tableName="trenttest" tableDbType="NOT_IN_DB">
            <ns:columns>
              <ns:column columnName="ParticipantSequenceNum">
                <ns:isKeyField>true</ns:isKeyField>
                <ns:isHidden>true</ns:isHidden>
              </ns:column>
            </ns:columns>
          </ns:table>
        </ns:tables>
    </metadata>
</query>

This works well in that in my data region, I get the participantsequencenum field returned with the following:

clinicalResultsPart.getDataRegion().getChecked();

However, the limitation is I can't fetch data from other datasets using the UI (using the customize view interface). If a specify the source table as "Clinical Results", there is a DataSets node that I can specify fields from my other data sets (that im hoping to have available on with the above query)

Questions.

1. Is my method overkill, and could I achieve the same with a custom qview.xml file? I did try, without success.

2. If no to 1, is there anything special I need to do to make the DataSets node available in order to be able to select fields from my other datasets? I thought that maybe joining to the DataSets table may help, but don't think that works either.

Any suggestions appreciated.
 
 
jeckels responded:  2014-08-13 14:24
Hi Trent,

You can't do this with a .qview.xml, but I think you should be able to specify the metadata you need directly via the LABKEY.QueryWebPart API call. The 'metadata' property lets you pass XML metadata which should be overlaid on top of the default query configuration.

So, by using XML to make ParticipantSequenceNum a key field, and setting the real primary key, LSID, to not be a field key, you should be able to accomplish your goal.

There's a short example usage in the docs for the 'metadata' property:

https://www.labkey.org/download/clientapi_docs/javascript-api/symbols/LABKEY.QueryWebPart.html

Thanks,
Josh
 
trent responded:  2014-08-15 00:32
Thanks for the tip Josh.

I'm probs missing something basic but I didn't have any success with metadata passed into the query web part having any impact.

I pass: (note I tried making a change to the column title just to check the metadata was having an impact)

<tables xmlns="http://labkey.org/data/xml"><table tableName="Dummy" tableDbType="NOT_IN_DB"><columns><column columnName="lsid"><isKeyField>false</isKeyField></column><column columnName="ABC"><columnTitle>ABD</columnTitle><isKeyField>true</isKeyField></column></columns></table></tables>

No change however.

As an additional test, I applied that xml against the actual dataset through the schema browser - the metadata is then reflected in the Query Schema Browser, however even then, the lsid is returned from the querywebpart :(.

Cheers,
Trent

nb: I realise this example is different again to my original post, but I did also try assigning the ParticipantSequenceNum as the primary key - and just wanted to provide a sample of applying xml. And here is the full code:

<script type="text/javascript">
    var dummyWebPart =
        new LABKEY.QueryWebPart({
                renderTo: 'container',
                title: 'Dummy',
                schemaName: 'study',
                queryName: 'Dummy',
                showRecordSelectors: true,
                buttonBar: {
                    includeStandardButtons: true,
                    items:[
                      {text: 'Show Vials', onClick: "console.log(dummyWebPart.getDataRegion().getChecked())", requiresSelection: true},
                    ]
                },
                metadata: {
                    type: 'xml',
                    value: '<tables xmlns="http://labkey.org/data/xml"><table tableName="Dummy" tableDbType="NOT_IN_DB"><columns><column columnName="lsid"><isKeyField>false</isKeyField></column><column columnName="ABC"><columnTitle>ABD</columnTitle><isKeyField>true</isKeyField></column></columns></table></tables>'
                }
        });
</script>
<div id="container"></div>
 
Greg Taylor responded:  2014-08-21 16:01
Hi Trent,

In your most recent example, the metadata is not applied which is consistent with the documentation. Currently, this option is only available if the query has been specified through config.sql. In your example, the query is specified by schemaName/queryName is therefore the metadata is not applied. I experimented with a script that uses config.sql and found that the metaData was applied properly.

Greg

Below is the documentation for this feature:

{Object} config.metadata
Metadata that can be applied to the properties of the table fields. Currently, this option is only available if the query has been specified through the config.sql option. For full documentation on available properties, see LabKey XML Schema Reference. This object may contain the following properties:
type: The type of metadata being specified. Currently, only 'xml' is supported.
value: The metadata XML value as a string. For example: '<tables xmlns="http://labkey.org/data/xml"><table tableName="Announcement" tableDbType="NOT_IN_DB"><columns><column columnName="Title"><columnTitle>Custom Title</columnTitle></column></columns></table></tables>'

A similar example script that applies the xml metadata:
<script type="text/javascript">
    var dummyWebPart =
        new LABKEY.QueryWebPart({
                renderTo: 'container',
                title: 'Dummy',
                schemaName: 'study',
                //queryName: 'Dummy',
                sql: 'SELECT * FROM study.Dummy',
                showRecordSelectors: true,
                buttonBar: {
                    includeStandardButtons: true,
                    items:[
                      {text: 'Show Vials', onClick: "console.log(dummyWebPart.getDataRegion().getChecked())", requiresSelection: true},
                    ]
                },
                metadata: {
                    type: 'xml',
                    value: '<tables xmlns="http://labkey.org/data/xml"><table tableName="Dummy" tableDbType="NOT_IN_DB"><columns><column columnName="lsid"><isKeyField>false</isKeyField></column><column columnName="ParticipantSequenceNum"><isKeyField>true</isKeyField></column><column columnName="ABC"><columnTitle>ABD</columnTitle><isKeyField>true</isKeyField></column></columns></table></tables>'
                }
                 
        });
</script>
<div id="container"></div>
 
Greg Taylor responded:  2014-08-21 16:03
Hi Trent,
My previous message was a work in progress and I submitted prematurely! I was able to apply metadata xml to the query but so far I have been unable to link to other datasets in the study.
More Later,
Greg
 
trent responded:  2014-08-21 23:12
Oh doh! When Josh suggested using the metadata in the QWP, I completely over looked that info in the docs. Thanks for pointing that out :-)

For what it's worth, I could be certain I could join this data (Custom query from post 1) to other datasets in studies a few versions ago. *shrugs*
 
Greg Taylor responded:  2014-08-26 15:55
Hi Trent,
Unfortunately, I have been unable to join to other datasets using the metadata trick. However, if you are interested in joining on a certain set of values, you could select them in javascript using a separate statement and then run a second query to return the data that you are actually interested in. I hope that this option works for your purposes.

Greg