This topic provides examples of query metadata.

Auditing Level

Set the level of detail recorded in the audit log. The example below sets auditing to "DETAILED" on the Physical Exam table.

<tables xmlns="http://labkey.org/data/xml">
<table tableName="Physical Exam" tableDbType="NOT_IN_DB">
<auditLogging>DETAILED</auditLogging>
<columns>
...
</columns>
</table>
</tables>

Conditional Formatting

The following adds a yellow background color to any cells showing a value greater than 72.

<tables xmlns="http://labkey.org/data/xml">
<table tableName="Physical Exam" tableDbType="NOT_IN_DB">
<columns>
<column columnName="Pulse">
<columnTitle>Pulse</columnTitle>
<conditionalFormats>
<conditionalFormat>
<filters>
<filter operator="gt" value="72" />
</filters>
<backgroundColor>FFFF00</backgroundColor>
</conditionalFormat>
</conditionalFormats>
</column>
</table>
</tables>

Wrapping/Surfacing Calculated Columns

The following example shows how to surface columns of calculated values in other datasets.

Suppose you have weight data recorded in one dataset (Physical Exam) and height data recorded in another dataset (Demographics). You want to accomplish three things with this data: (1) convert the height data, which is records in inches, into meters, (2) calculate the BMI (Body Mass Index) from the height and weight data, and (3) surface these calculated columns in the Physical Exam dataset.

The following query accomplishes the first two tasks, by including two calculated columns:

  • Height_m (which converts the base data in inches to meters)
  • BMI (which uses the formula Height/Weight^2 to calculate the BMI)
BMI Query
SELECT "Physical Exam".ParticipantId,
"Physical Exam".LSID,
"Physical Exam".Weight_kg,
Datasets.Demographics.Height_inch*0.0254 AS Height_m,
Weight_kg/POWER(Datasets.Demographics.Height_inch*0.0254, 2) AS BMI
FROM "Physical Exam"

How do you accomplish the third task, surfacing the calculated columns so they can be displayed in the Physical Exam table?

To do this, use query metadata to wrap the BMI query as a lookup (= foreign key) from the Physical Exam dataset. Notice that we have included the LSID column in the BMI query to function as a key column. The following metadata on Physical Exam adds a wrapped column over LSID as a lookup to the BMI query.

Query Metadata on Physical Exam

<tables xmlns="http://labkey.org/data/xml">
<table tableName="Physical Exam" tableDbType="NOT_IN_DB">
<columns>
<column columnName="BMI" wrappedColumnName="lsid">
<fk>
<fkDbSchema>study</fkDbSchema>
<fkTable>BMI Query</fkTable>
<fkColumnName>LSID</fkColumnName>
</fk>
</column>
</columns>
</table>
</tables>

Now that Physical Exam is linked to BMI Query via the lookup/foreign key, all of the columns in BMI Query are made available to the grid customization GUI:

A live example of this technique is shown in the Physical Exam dataset in the live study demo.

Lookup Display Column

The following example shows how to specify an alternate display column for a lookup field.

<tables xmlns="http://labkey.org/data/xml">
<table tableName="Demographics" tableDbType="NOT_IN_DB">
<columns>
<column columnName="Gender">
<columnTitle>Gender Code</columnTitle>
<fk>
<fkDisplayColumnName>GenderCode</fkDisplayColumnName>
<fkTable>Genders</fkTable>
<fkDbSchema>lists</fkDbSchema>
</fk>
</column>
</columns>
</table>
</tables>

Other Examples

  • kinship.query.xml
    • Disables the standard insert, update, and delete buttons/links with the empty <insertUrl /> and other tags.
    • Configures lookups on a couple of columns and hides the RowId column in some views.
    • Adds a custom button "More Actions" with a child menu item "Limit To Animals In Selection" that calls a JavaScript method provided in a referenced .js file.
  • Data.query.xml
    • Configures columns with custom formatting for some numeric columns, and color coding for the QCFlag column.
    • Adds multiple menu options under the "More Actions" button at the end of the button bar.
  • Formulations.query.xml
    • Sends users to custom URLs for the insert, update, and grid views.
    • Retains some of the default buttons on the grid, and adds a "Delete Formulations" button between the "Paging" and "Print" buttons.
  • encounter_participants.query.xml
  • AssignmentOverlaps.query.xml
  • Aliquots.query.xml & performCellSort.html
    • Adds a button to the Sample Sets web part. When the user selects samples and clicks the button, the page performCallSort.html is shown, where the user can review the selected records before exporting the records to an Excel file.
    • To use this sample, place Aliquots.query.xml in a module's ./resources/queries/Samples directory. Rename Aliquots.query.xml it to match your sample set's name. Edit the tableName attribute in the Aliquots.query.xml to match your sample set's name. Replace the MODULE_NAME placeholder with the name of your module. Place the HTML file in your module's ./resources/views directory. Edit the queryName config parameter to match the sample set's name.

Related Topics

Discussion

previousnext
 
expand all collapse all