Patterns
  • 01 Nov 2024
  • 18 Minutes to read
  • Dark
    Light

Patterns

  • Dark
    Light

Article summary

The table below provides a catalog of derived field, restriction, and transformation patterns available in Ursa Studio. 

Derived fields are akin to a SQL select clause that includes a calculation or transformation. Derived fields enable users to create a new field, which is typically based on the contents of another field, e.g., Concatenate or Case When. These patterns can be used when developing objects and measures and when analyzing measures in Analytics Portal. Derived field patterns can be chained together to create complex, multi-step calculations and transformations. When chaining patterns together, the ordering of patterns dictates the order in which the logic will be applied.

Restrictions are akin to a SQL where clause. Restrictions can be used when developing objects and measures. The table also includes Upstack Restrictions which are used when linking (joining) one object to another. The table’s Analogous SQL column contains SQL commands and logic representing the pattern’s basic functionality.

Transformations can be used when developing objects and measures.

The table’s Analogous SQL column contains SQL commands and logic representing the pattern’s basic functionality. While most of the patterns have more complex, flexible logic, developers will understand the pattern’s primary function if they are familiar with the SQL.

 

CategoryPattern NameAnalogous SQLPattern Description
Derived FieldAbsolute ValueABS()Generates the absolute value of an integer or float input.
Derived FieldAdd Decimal Point to ICD-9 or ICD-10 Diagnosis Code-Generates a text value representing a given ICD-9 or ICD-10 diagnosis code with a decimal point included when appropriate.
Derived FieldAdd Decimal Point to ICD-9 Procedure Code-Generates a text value representing a given ICD-9 procedure code with a decimal point included when appropriate.
Derived FieldAge RestrictionEx. SELECT DATEDIFF(YEAR, date1, dob) >= 65Generates a numeric value of 1 (“true”) or 0 (“false”) indicating an individual’s age in years as of a given reference date is above or below a target age.
Derived FieldAll Are TrueEx. field1 = 1 AND field2 = 1 AND field3 = 1Generates a numeric value of 1 (“true”) or 0 (“false”) indicating whether an arbitrary number of numeric fields all take the value 1 (“true”).
Derived FieldAny Are TrueEx. field1 = 1 OR field2 = 1Generates a numeric value of 1 (“true”) or 0 (“false”) indicating whether at least one of an arbitrary number of numeric fields takes the value 1 (“true”).
Derived FieldArithmetic+, -, *, /Generates a numeric value representing the result of a simple (operand-operator-operand) arithmetic calculation; the following operators may be used: +, -, *, /.
Derived FieldCase WhenCASEGenerates a value based on the evaluation of an ordered sequence of logical “case” statements, each with its own result value; all results must be of the same data type.
Derived FieldCoalesceCOALESCE(); ISNULL(); IFNULL(); NVL()Generates a value by evaluating an ordered list of fields and returning the value of the first field taking a non-NULL value; all fields must be of the same data type.
Derived FieldConcatenateCONCAT()Generates a text value representing the combination of an ordered sequence of text fields and/or text literals.
Derived FieldConvert Date to TextCAST()Casts a date field to a text data type according to a supplied date format.
Derived FieldConvert Integer to FloatCAST()Casts an integer to a float data type.
Derived FieldConvert Number to TextCAST()Casts a number to a text data type.
Derived FieldConvert Text Duration to Float-Casts a text field representing a time duration into a possibly-fractional number of seconds/minutes/etc.
Derived FieldConvert Text to DateCAST()Casts a text field as a date according to a supplied date format.
Derived FieldConvert Text to DatetimeCAST()Casts a text field as a datetime according to a supplied date format.
Derived FieldConvert Text to IntegerCAST()Casts a text field as an integer if it's correctly formatted, NULL otherwise.
Derived FieldConvert Text to Lower CaseLOWER()Converts a text field to lowercase.
Derived FieldConvert Text to NumberCAST()Casts a text field as a number if it's correctly formatted, NULL otherwise.
Derived FieldConvert Text to Upper CaseUPPER()Converts a text field to uppercase.
Derived FieldCount of InstancesEx. COUNT(1) OVER (PARTITION BY partition_field)Generates a numeric value representing the count of instances sharing the same partition.
Derived FieldCumulative Sum Across Instances

SUM() over (... range between unbounded preceding and current row)

Generates the numeric value representing the running sum of values for a given numeric field from a partition of records with the same values as the current record in a number of given fields; the sum is calculated by ordering records within the partition and summing values from the current record and all prior records.

Derived FieldData End DateEx. TO_DATE('2010-01-01', 'YYYY-MM-DD')Generates a date value representing the data end date in the Global Parameters table (ursa.mi_aa_001).
Derived FieldData Start DateEx. TO_DATE('2020-01-01', 'YYYY-MM-DD')Generates a date value representing the data start date in the Global Parameters table (ursa.mi_aa_001).
Derived FieldDate OffsetDATEADD(), DATE_ADD()Generates a date value representing the calendar date a given number of days, weeks, months, or years before or after a given reference date.
Derived FieldDays Since Last InstanceEx. EXTRACT(DAY FROM (date_field1 - LAG(date_field1) OVER (PARTITION BY partition_field ORDER BY sort_field)))Generates a positive numeric value representing the number of days elapsed between the current instance and the most recent prior instance – defined by a given date field – among instances sharing the same partition. The pattern returns NULL if no prior instance can be found, and a field may be supplied to break ties between instances with the same date.
Derived FieldDays Until Next InstanceEx. (EXTRACT(DAY FROM (date_field1 - LEAD(date_field1) OVER (PARTITION BY partition_field ORDER BY sort_field)))) * -1Generates a positive numeric value representing the number of days elapsed between the current instance and the next instance – defined by a given date field – among instances sharing the same partition. The pattern returns NULL if no prior instance can be found, and a field may be supplied to break ties between instances with the same date.
Derived FieldDifference As Relative ChangeEx. (field2 - field1)/field1Generates a numeric value representing the difference between a base value and a comparison value divided by the base value.
Derived FieldDistance Between Coordinate Points-Generates the distance in miles between two coordinate points based on their latitude and longitude
Derived FieldEarliest Date Within InstanceLEAST()Generates a date value representing the earliest date – defined by a given date field – among a set of instances in the current scope that hold the same values as the current instance in a number of given fields.
Derived FieldElapsed TimeDATEDIFF(), DATE_DIFF()Generates a numeric value representing the amount of time elapsed between two given date fields. Time may be generated in units of minutes, hours, days, weeks, months, years, 100s of years, and 1000s of years.
Derived FieldEquality Filter=Generates a numeric value of 1 (“true”) or 0 (“false”) indicating whether a given field takes the same value as another given field or specified value.
Derived FieldExtract Slot from Delimited FieldSPLIT_PART()Extracts the 1-indexed nth value from a delimited field. Returns NULL if the delimited field does not have a value in that slot.
Derived FieldExtract SubstringSUBSTRING(), SUBSTR()Generates a text value representing a continuous sequence of characters from a given text field.
Derived FieldExtract Value from JSONJSON_EXTRACT_PATH_TEXT()Generates a text value corresponding to the value of the key:value pair found at the specified path location within a referenced JSON document string. Returns an empty string if the specified location does not exist in the JSON document.
Derived FieldFirst Date in PeriodDATE_TRUNC()Generates a date value representing the first calendar date within a specified period containing a given reference date.
Derived FieldFirst Value Across InstancesEx. FIRST_VALUE(field1) OVER (PARTITION BY partition_field ORDER BY sort_field ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)Generates the value in the target field associated with the first record from within a designated partition of records after ordering as specified.
Derived FieldGenerate Composite KeyCONCAT()Generates a unique identifier by concatenating a set of fields.
Derived FieldGreatest Value Within InstanceGREATEST()Generates a numeric value representing the largest value from a series of given numeric fields.
Derived FieldInequality Filter!=, <, <=, >, >=Generates a numeric value of 1 (“true”) or 0 (“false”) indicating whether a given field takes a value with a certain non-equality relationship (!=, <, <=, >, >=) as another given field or value.
Derived FieldInstantiation DatetimeCURRENT_TIMESTAMP()Generates a value representing the date and time the current report is run or the current object is ELTed.
Derived FieldIs In Report-Designated Control Values-Applies a restriction with parameters that are set at the report-level, allowing the measure logic to differ from report to report. Generates a neumeric value of 1 (“true”) if that criterion is met and 0 (“false”) otherwise.
Derived FieldIs In Value SetIN (‘Value’, ‘Value’, ‘Value’, ‘Value’)Evaluates whether a given text field is a member of a given value set; if invoked as a restriction, keeps only instances meeting that criterion; if invoked as a derived field, generates a numeric value of 1 ("true") if that criterion is met and 0 ("false") otherwise.
Derived FieldIs Not NullIS NOT NULLGenerates a numeric value of 1 (“true”) or 0 (“false”) indicating whether a given field is not NULL.
Derived FieldIs NullIS NULLGenerates a numeric value of 1 (“true”) or 0 (“false”) indicating whether a given field is NULL.
Derived Field
Is Overlapping Interval-

Evaluates whether one interval overlaps with a second interval for any amount of time. (Two intervals are not considered overlapping if one ends on the exact date or datetime that the other starts; an instantaneous interval — i.e., one with identical start and end datetimes — can be considered overlapping if it falls in the interior of the other interval.)

Derived FieldIs Patient Affiliation Active-Evaluates whether a given patient affiliation is active for the patient with the given patient ID as of a given reference date; if invoked as a derived field, generates a numeric value of 1 ("true") if that criterion is met and 0 ("false") otherwise."
Derived FieldIs Provider Affiliation Active-Evaluates whether a given provider affiliation is active for the provider with the given provider ID as of a given reference date; if invoked as a derived field, generates a numeric value of 1 ("true") if that criterion is met and 0 ("false") otherwise.
Derived FieldLatest Date Within InstanceGREATEST()Generates a date value representing the most advanced date value from a series of given date fields.
Derived FieldLeast Value Within InstanceLEAST()Generates a numeric value representing the smallest value from a series of given numeric fields.
Derived FieldLeftmost CharactersLEFT()Generates a text value representing the leftmost characters in a reference text field.
Derived FieldLeftmost Characters up to TargetEx. LEFT(field1, POSITION('A' IN field1) - 1)Generates a text value representing the leftmost characters up to a target character or substring in a reference text field.
Derived FieldLength of StringLEN(), LENGTH()Generates the length of a string.
Derived FieldLiteralEx. SELECT CAST(‘Literal’ AS VARCHAR(25))Generates a given value in the form of a given data type.
Derived FieldLocation of Character in StringPOSITION()Identifies the first one-indexed position of a substring within a string, returning 0 if the substring is not found.
Derived FieldLook Up Value Set Using Cluster-For a given value set cluster and reference text value, look up which value set in the cluster contains the reference value and generate an appropriate text output value.
Derived FieldLookup Table Value-Generates a text value representing the value associated with the given key in the selected lookup table.
Derived FieldMaster Patient ID-Uses the "Matching of Source Local Patient ID to Ursa Patient ID" table to look up the master patient ID for the location patient ID given a source.
Derived FieldMaximum Value Across InstancesEx. MAX(field1) OVER (PARTITION BY partition_field)Generates a numeric or date value representing the largest or latest value of a field among a shared partition of instances.
Derived FieldMinimum Value Across InstancesEx. MIN(field1) OVER (PARTITION BY partition_field)Generates a numeric or date value representing the smallest or earliest value of a field among a shared partition of instances.
Derived FieldName of Active Patient Affiliation-Generates a text value representing the name of the active patient affiliation for a patient with the given patient ID as of a given reference date from among the affiliations associated with the given cluster.
Derived FieldName of Active Provider Affiliation-Generates a text value representing the name of the active provider affiliation for a provider with the given provider ID as of a given reference date from among the affiliations associated with the given cluster.
Derived FieldName of Active Value Set-Generates a text value representing the name of the active value set containing a given text value from among the value sets associated with the given cluster.
Derived FieldNext or Previous ValueEx. LEAD(field1, 1) OVER (PARTITION BY partition_field ORDER BY sort_field)Generates the value of a field, among a shared partition of instances, that is found a user-specified number of instances ahead or behind the current instance and ordered by a given field.
Derived FieldNullCAST()Generates the value NULL cast as a particular database type.
Derived FieldOrdinal Rank Amongst InstancesEx. ROW_NUMBER() OVER (PARTITION BY partition_field ORDER BY sort_field)Generates a numeric value representing the ordinal rank (e.g., 1st, 2nd, 3rd, etc.) of the current instance – defined by a given sequence of ordering fields – among a shared partition.
Derived FieldPad LeftLPAD()Ensures a minimum length field by adding characters to the left of the original number or string. This pattern will never truncate the original number or string even if it is longer than the specified length.
Derived FieldPad RightRPAD()Ensures a minimum length field by adding characters to the right of the original number or string. This pattern will never truncate the original number or string even if it is longer than the specified length.
Derived FieldPart of DateDATEPART(); DATE_PART()Generates a numeric value representing one of the following parts of a given date: minute of the hour, minute of the day, hour of the day, day of the week, day of the month, month of the year, year. 
Derived FieldRandom NumberRANDOM()Generates a random float or int between a specified range.
Derived FieldRandom RankRANDOM()Assigns a random ordinal rank to each row.
Derived FieldRank as Percentile Among InstancesEx. 100.0 * PERCENT_RANK() OVER (PARTITION BY partition_field ORDER BY sort_field)Generates a numeric value representing the percentile rank between 0 and 100 of the current instance – defined by a given sequence of ordering field – among a set of instances in the current scope that hold the same values as the current instance in a number of given fields.
Derived Field
Regression InterceptREGR_INTERCEPT()Generates the intercept of a linear regression line from within a designated partition of records.
Derived Field
Regression SlopeREGR_SLOPE()
Generates the intercept of a linear regression line from within a designated partition of records.
Derived FieldRemove Leftmost CharactersSUBSTRING()Generates a text value representing all but the leftmost characters in a reference text field.
Derived FieldRemove Rightmost CharactersSUBSTRING()Generates a text value representing all but the rightmost characters in a reference text field.
Derived FieldRemove Special CharactersREPLACE()Generates a text value representing a given text value from which all characters of a given type (hyphen, single quote, double quote, or period) have been removed.
Derived FieldRightmost CharactersRIGHT()Generates a text value representing the rightmost characters in a reference text field.
Derived Field
Round Number
ROUND()
Rounds a number to a specified number of decimal places.
Derived FieldRound Number to Nearest IntegerROUND()Rounds a number to the nearest integer.
Derived FieldSum Across InstancesEx. SUM(field1) OVER (PARTITION BY partition_field)Generates a numeric value representing the sum of values for given numeric field among a shared partition of instances.
Derived FieldSum Within InstanceEx. field1 + field2 + field3 + field4…Generates a numeric value representing the sum of values for a given set of numeric fields present on the current instance.
Derived FieldSwitch(simplified) CASE WHENGenerates a value based on the evaluation of an ordered sequence of possible values against the same field, each with its own result; all results must be of the same data type.
Derived FieldText Contains StatementLIKE ‘% %’Generates a numeric value of 1 (“true”) or 0 (“false”) indicating whether a given text field contains a given text value.
Derived FieldText Section Contains StatementEx. SUBSTRING(field1, 3, 5) LIKE ‘% %’Generates a numeric value of 1 (“true”) or 0 (“false”) indicating whether a given section of a given text field contains a given text value.
Derived FieldTrimLTRIM(RTRIM())Trims the whitespace from a string.
Derived FieldTruncate DateDATE_TRUNC()Generates a date value representing one of the following truncations of a given datetime field: date from a datetime; first date of a calendar month; first date of a calendar quarter; first date of a calendar year.
Derived FieldTruncate Number to IntegerTRUNC()Truncates a number to integer.
Derived FieldValue of FieldEx. SELECT field1 AS ‘field name’Generates a value currently taken by a given field.
RestrictionAge RestrictionEx. WHERE date_field1 - date_of_birth_field >= 64 * 365.25Evaluates whether an individual's age in years as of a given reference date is above or below a target age; if invoked as a restriction, keeps only instances meeting the age criterion.
RestrictionAll Are TrueEx. WHERE field1 = 1 AND field2 = 1Evaluates whether an arbitrary number of numeric fields all take the value 1 ("true"); if invoked as a restriction, keeps only instances meeting that criterion.
RestrictionAny Are TrueEx. WHERE field1 = 1 OR field2 = 1Evaluates whether at least one of an arbitrary number of numeric fields takes the value 1 ("true"); if invoked as a restriction, keeps only instances meeting that criterion.
RestrictionEquality FilterEx. WHERE field1 = ‘value’Evaluates whether a given field takes the same value as another given field; if invoked as a restriction, keeps only instances meeting that criterion.
RestrictionForeign KeyEx. ON t1.id = t2.idKeeps only instances for which a field on the current instance takes the same value as a given field on a different object.
RestrictionInequality FilterEx. WHERE field1 != 1Evaluates whether a given field takes a value with a certain non-equality relationship (!=, <, <=, >, >=) as another given field; if invoked as a restriction, keeps only instances meeting that criterion.
RestrictionIs In Report-Designated Control Values-Applies a restriction with parameters that are set at the report level, allowing the measure logic to differ from report to report. If the report specifies no control values then none will be applied.
RestrictionIs In Value SetEx. WHERE field1 IN (‘Value1’, ‘Value2’, ‘Value3’)Evaluates whether a given text field is a member of a given value set; if invoked as a restriction, keeps only instances meeting that criterion.
RestrictionIs Not In Value SetEx. WHERE field1 NOT IN (‘Value1’, ‘Value2’, ‘Value3’)Evaluates whether a given text field is absent from a given value set; if invoked as a restriction, keeps only instances meeting that criterion.
RestrictionIs Not NullEx. WHERE field1 IS NOT NULLEvaluates whether a given field is not NULL; if invoked as a restriction, keeps only instances meeting that criterion.
RestrictionIs NullEx. WHERE field1 IS NULLEvaluates whether a given field is NULL; if invoked as a restriction, keeps only instances meeting that criterion.
RestrictionIs Patient Affiliation Active-Evaluates whether a given patient affiliation is active for the patient with the given patient ID as of a given reference date; if invoked as a restriction, keeps only instances meeting that criterion.
RestrictionIs Patient Affiliation Inactive-Evaluates whether a given patient affiliation is not active for the patient with the given patient ID as of a given reference date; if invoked as a restriction, keeps only instances meeting that criterion.
RestrictionIs Provider Affiliation Active-Evaluates whether a given provider affiliation is active for the provider with the given provider ID as of a given reference date; if invoked as a restriction, keeps only instances meeting that criterion.
RestrictionIs Provider Affiliation Inactive-Evaluates whether a given provider affiliation is not active for the provider with the given provider ID as of a given reference date; if invoked as a restriction, keeps only instances meeting that criterion.
RestrictionKeep Closest Downstack Object-Keeps only the first instance of the downstack object occurring either immediately prior to or immediately subsequent to the current upstack instance – based on a given downstack object date and a given upstack instance date – from among a set of downstack instances that share the same values in a number of given fields; a field may be supplied to break ties between instances with the same date. This pattern is for use in defining upstack or numerator-denominator relationships only.
RestrictionKeep If Days Distance-Keeps the current instance if the number of days elapsed between the current instance and the most recent prior instance or subsequent instance – defined by a given date field – among a set of instances in the current scope that hold the same values as the current instance in a number of given fields – meets an equality or inequality criterion; a field may be supplied to break ties between instances with the same date.
RestrictionKeep In IntervalEx. WHERE reference_date_field >= interval_start_date_field AND reference_date_field < period_end_date_fieldKeeps the current instance if a given reference date falls within a given date interval; a reference date equal to the start date of an interval is considered to fall within the interval, while a reference date equal to the end date of an interval is considered to not fall within the interval.
RestrictionKeep Interval if Overlapping-

Keeps the current interval instance if it overlaps with a second comparison interval for any amount of time. (Two intervals are not considered overlapping if one ends on the exact date or datetime that the other starts; an instantaneous interval — i.e., one with identical start and end datetimes — can be considered overlapping if it falls in the interior of the other interval.)

RestrictionKeep Nth Following Reference Date-Keeps the current instance if it is a given ordinal rank (e.g., 1st, 2nd, 3rd, etc.) in sequence following a reference date – defined by a given date field – among a set of instances in the current scope that hold the same values as the current instance in a number of given fields; a field may be supplied to break ties between instances with the same date.
RestrictionKeep Nth Preceding Reference Date-Keeps the current instance if it is a given ordinal rank (e.g., 1st, 2nd, 3rd, etc.) in sequence prior to a reference date – defined by a given date field – among a set of instances in the current scope that hold the same values as the current instance in a number of given fields; a field may be supplied to break ties between instances with the same date.
RestrictionKeep Ordinal NEx. SELECT * FROM (SELECT ROW_NUMBER() OVER (PARTITION BY partition_field ORDER BY sort_field DESC NULLS LAST) AS ranked_partition_field) t1 WHERE ranked_partition_field = 1Keeps the current instance if it is a given ordinal rank (e.g., 1st, 2nd, 3rd, etc.) in sequence – defined by a given ordering field – among a set of instances in the current scope that hold the same values as the current instance in a number of given fields; a field may be supplied to break ties between instances with the same value on the ordering field.
RestrictionKeep Ordinals M Through NEx. SELECT * FROM (SELECT ROW_NUMBER() OVER (PARTITION BY partition_field ORDER BY sort_field DESC NULLS LAST) AS ranked_partition_field) t1 WHERE ranked_partition_field >= 1 AND ranked_partition_field <= 10Keeps the current instance if it has an ordinal rank (e.g., 1st, 2nd, 3rd, etc.) falling within the parameter bounds, inclusive — defined by a given ordering — among the set of instances that hold the same values as the current instance in one or more given fields.
RestrictionText Contains StatementEx. WHERE field1 LIKE ‘%value%’Evaluates whether a given text field contains a given text value; if invoked as a restriction, keeps only instances meeting that criterion.
RestrictionText Section Contains StatementEx. WHERE SUBSTRING(field1, 3, 5) LIKE ‘%value%’Evaluates whether a given section of a given text field contains a given text value; if invoked as a restriction, keeps only instances meeting that criterion.
TransformationReshape Wide to Long-Transforms wide-form data into long-form data.
TransformationStart New Scope-Wraps all the preceding derived fields, restrictions, and transformations into a subquery.



Was this article helpful?

What's Next