A Table Level Code transformation applies python code to process input field values and generate an entire column of output values.
Prerequisites
- You must have Manage Data Mappings permission.
- A syntactic mapping should have already been created.
Creating a Table Level Code Transformation
To create a Table Level Code transformation, complete the following steps.
Step 1: Open the Transformations Panel
- In the Syntactic Mappings page, choose the mapping you want to edit.
- Click the Edit Pencil in the Transformation field for the entry you would like to edit transformations for.
- The Transformations Panel will appear. Click the Add Transformation button.
- Click the dropdown menu to select the desired transformation type.
- Select the Table Level Code transformation.
Step 2: Fill in the Transformation Configuration
- Note the Source Input and Target Output. It should reflect what you already chose in the syntactic mapping entry.
- Enter a Python code snippet that you want to run in order to generate the entire column of output values.
- The code snippet has access to all fields in all input data sources.
- Each input data source is available in a variable with a name matching the schema name in snake case. For example, if the source data schema is called "Patient Table", the matching variable will be "patient_table".
- Each data source variable is a dictionary with each field name mapped to the field value. For example, if there is a "gender" field in the "Patient Table" dataset, your code can access its values via:
patient_table["gender"]
- The code snippet can use methods from pandas (imported as pd), numpy (imported as np), and arrow.
- The code snippet should set the desired output values to a special "output" variable. The output should be a one-dimensional Pandas Series or array, and its length should be the number of rows in the output table. The values in the output will be set directly as the column values in the output table in the order provided by the code snippet. For example, if you would like to set the output value to be the element-wise maximum between two input fields (assuming that they are of the same length, matching order, and you'd like the output to be of the same length and in the same order), you could use something like the following:
date_of_service = pd.to_datetime(encounters["DateOfService"], format="%Y-%m-%d")
procedure_end_date = pd.to_datetime(procedures["ProcedureEndDate"], format="%Y-%m-%d")
output = np.maximum(date_of_service, procedure_end_date)
- The code snippet has access to all fields in all input data sources.
- Indicate what happens if the code fails. You have two options: fail the entire code run or set the output to a default value. The value can be a string or a number and it will be set in the output field for all rows.
- When complete, select the Save button.
Ordering Transformations
When code runs, configured transformations are executed one after another. If you want to change the order of transformation execution for specific syntactic mapping entries, complete the following steps.
- In the Syntactic Mapping page, choose the mapping you want to modify.
- Select the Edit Pencil in the Transformation field for the entry you want to edit. The Transformations Panel will appear.
- Click the transformation's handle (six domino-looking dots), and drag the transformation in the order you want it to run. Do this for each transformation that you want to reorder.
- When done, click Save at the bottom of the page.
Editing a Transformation
To edit a transformation, complete the following steps.
- In the Syntactic Mappings page, select the mapping that you want to edit transformations for.
- Find the mapping entry you want to edit, then click the pencil icon in the Transformation column. The Transformations Panel will appear.
- Edit the transformation as desired.
- When complete, click the Save button.