Leave a comment at the end of this page or email contact@krishagni.com
Calculated Filter (Temporal Queries)
Poornima Govindrao
Ashish Vishwakarma
Divya Prabhu (Unlicensed)
Often one needs to perform queries based on calculated fields of dates or number fields.
Examples:
Difference between collection time and date of birth (age at collection)
Difference between collection time and received time (warm ischemia time)
Difference between frozen time and received time
All specimens collected "today", "last week" or "last month"
Demonstration of a Temporal Query:
Temporal functions
When calculating the difference between two date fields or formatting a date to display in a specific format, there are two parts to consider and include “Parameterization”:
Left-Hand Side: This includes the function and fields you wish to evaluate. For example:
Calculate 'Minutes':
minutes_between(Specimen.customFields.additional_specimen_detail_form.cold_ischemia_end, Specimen.customFields.additional_specimen_detail_form.cold_ischemia_start)
To format a date:
date_format(Participant.regDate, "%month_day% %month3% %year4%")
Right-Hand Side: This represents the condition to check against. Examples include:
any
> 20
<= 50
18 Jan 2017
(when using date format)
Function | Description |
---|
Function | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
months_between | To find the number of months between two dates. Example: month between registration date and visit date | ||||||||||||||||||||||||||||||||||||
minutes_between | To find the number of minutes between two timestamp fields. Example: time difference between frozen and received time | ||||||||||||||||||||||||||||||||||||
years_between | To find the number of years between two dates. Example: age at collectionThese functions can be used as below as wella) Days = minutes_between(d1, d2) / (24 * 60) | ||||||||||||||||||||||||||||||||||||
current_date() | To get current date. Example: age as of today | ||||||||||||||||||||||||||||||||||||
round() | To round up calculations. In cases where integer values are expected, for example, temporal expressions related to dates, round() function ensures that stable integer results are obtained. | ||||||||||||||||||||||||||||||||||||
date_range(date, range_type, [interval]) | Allows to check for data that falls in the particular date range.
Date Range Temporal Filters Illustration: Assuming the present date as 15th March 2017
| ||||||||||||||||||||||||||||||||||||
date_format(date_expr, format) | Outputs date/time field/expression value in desired format.
Values in examples of below table are given w.r.t date/time 18th January 2017 16:45:33 date_format(Participant.regDate, "%month_day% %month3% %year4%") > "18 Jan 2017" Only those participants registered after 18 JAN 2017 will be displayed in the desired format. Similarly, you can use the other operators like < , = etc
|
Examples of temporal queries
Example 1: Age as of today
Note: If the "date of birth" value is blank for the participant, the query results would be blank.
Example 2: Age at collection
Note:
This expression only works for "parent (New)" specimens.
If the "date of birth" value is blank for the participant, the query results would be blank.
Temporal Expression: "years_between( Specimen.extensions.SpecimenCollectionEvent.time, Participant.dateOfBirth) any"
Example 3: Age at collection
Note:
This expression works for specimens at any level (New, Derived, and Aliquot).
If the "date of birth" value is blank for the participant, the query results would be blank.
Temporal Expression: "years_between( Specimen.spmnCollRecvDetails.collTime, Participant.dateOfBirth) any"
Example 4: Time difference between frozen and received time
Example 5: Tissue specimens collected in the last 2 months
Example 6: Calculating the sample amount
Example 7: Count of specimens collected per month
Example 8: Count of participants registered per month.
Example 9: Count of specimens collected after a particular date
Example 10: Age in years (rounded off)
Expression: round( years_between( Participant.regDate, Participant.dateOfBirth), 0) any
Example 11: Age in years (rounded off) between 10-20 age
Expression: round( years_between( Participant.regDate, Participant.dateOfBirth), 0) between (10,20)
Example 12: Number of participants enrolled and parent samples entered per week.
Result view:
Note: Select the count of participant and primary specimen in 'Aggregates' column to view the count in the result view.
Example 13: Finding percent from 2 numbers in custom form
In the above example, number1 and number2 are two numeric fields defined in a form attached at 'Registration Forms' level. There is no % function in temporal queries, but the formula to find percent can directly used to calculate the same.
Example 14: Calculating the initial cell value from the volume processed and initial concentration, where the volume processed and initial concentration are specimen custom fields.
In the above expression,
aj_specimen_form is the variable name of the custom form.
initial_processing_volume and initial_cell_volume are the variable names of the volume processed and initial concentration custom fields.
Example 15: Average of 2 custom fields.
In the above expression,
'skin_cancer_registration_custom_field_form' is the variable name of the form name.
‘number_field_1' and 'number_field_2’ are variable names of the custom fields.
The CP (e.g. 'Skin Cancer Study') must be selected, for custom forms and fields.
Parameterized Temporal Filter
Temporal filters can be parameterized so that users can enter a range to dynamically filter the results. Below operators can be used in the temporal expression to make it parameterized:
Exists: to specify existence condition like age exists
Any: to specify don't care condition like age any
Calculated URLs
From v10.2 onwards, it is possible to configure URLs using temporal expression.
For the test server URL of participant overview page 'https://test.openspecimen.org/#/cp-view/6636/participants/176857/detail/overview ', you need to configure the temporal expression as 'concat("https://test.openspecimen.org/#/cp-view/ " ,CollectionProtocol.id, "/participants/" ,Participant.id , "/detail/overview") != " "
For visit overview page URL https://test.openspecimen.org/#/cp-view/6636/participants/176857/visits/detail/overview?visitId=130492 you need to configure the temporal expression as concat("https://test.openspecimen.org/#/cp-view/%22 ,CollectionProtocol.id, "/participants/" ,Participant.id, "/visits/detail/overview?visitId=", SpecimenCollectionGroup.id) != " "
Below is the list of fields that are available to be used in the query
Field | Syntax |
Collection Protocol Identifier | CollectionProtocol.id |
Participant Registration Identifier | participant.id |
Participant Identifier | Participant.participantId |
Visit Identifier | SpecimenCollectionGroup.id |
Specimen Identifier | Specimen.id |
Leave a comment at the end of this page or email contact@krishagni.com