Extensions (LPP)
SmartForm Server-side Scripting Functions
Extensions can be used to perform server-side (cache) scripting, giving the ability to programmatically perform some data manipulation actions that are not supported within SmartForms. Most commonly, a particular type of SmartForm may not support display or editing of a specific patient data (EPT) record. To work with that information, it may be possible to manage a SmartData element within the form and to set the value of that element from the EPT record while loading the form, then return the SDE value the EPT record on closing the form.
The following SmartForm scripting use cases offer extensions that can be copied and configured to accomplish a specific task.
Cache Code
Core data management functions draw from the "HULIB100" library for SmartForm scripting. Callable tags include:
SFReadOnly - Check if a form is read only
SFGetIDDAT - Get the context ID and DAT for a specific INI
SFGetCV - Get a concept (SDE) value
SFGetCVCmt - Load a SDE comment
SFPutCV - Set a SDE value
Parameters (comma delimited, quotes enclosed)
SDE identifier in AHS#NNNN format
Context: ENCOUNTER or PATIENT
SFPutCVCmt - Set a SDE comment
SFGetChron - Get a Chronicles value
SFPutChron - Set a Chronicles value
SFSetProp - Set a property on a component
SmartForm Scripting using Epic Extension Code Templates
SmartForm Script - Set value for a Date-type SmartData Field based on a time-offset interval
LPP 37963 (IP SMARTFORM SCRIPTING SET DEFAULT DATE) can be copied and used to set the value of a SmartForm Field of "Date" type (usually data bound to an SDE element). When this programming extension is added as a scripting action to the AfterDataLoaded event of the RootComponent, it will set a default date for the field when the form is loaded. The same functionality can be attached to other events (e.g., command buttons to set the date of a related field).
Parameters
SDE Identifier (AHS#NNN format)
SDE Context (use shift-F5 for values; can be PATIENT, NOTE, ENCOUNTER, EPISODE, etc.)
Relative date (use "T" or "T+N" syntax for days, weeks [W], months [MB])
Limitations
This function will only write to a null field. If a form field already has a date value, running the extension will have no effect. Be sure to include an action of clearing the field before resetting its value with the LPP.
The target SDE must be a plain Date field (not time, not instant).
Tricks
One can copy a SDE value (or an EPT value) to a temporary buffer field or label, work with the value, then copy it back to the SDE. This can be useful when trying to get around the inability of this function to write to a non-null field.
SmartForm Script - Set SmartForm Label Caption from a Rule (CER) Message in Patient Context
LPP 42320 (ES SMARTFORM SET LABEL CAPTION) can be copied and used to set the caption of a SmartForm Label object.
Parameters
CER rule identifier (must return error message)
(optional extension to return text value)
Identifier of the SmartForm Label object where caption will be set
Code Template
421204 ES SMARTFORM SET LABEL CAPTION
SmartForm Script - Set SmartForm SmartData value from a Rule (CER) Message in Patient OR Score Context (any target SDE data type)
LPP 12713 (SF SCRIPTING EXT - ADD RULE ERROR MESSAGE TO SDE) can be copied and used to set a SmartForm SmartData element from a rule error message.
Parameters
CER rule identifier (must return error message)
SDE identifier for SmartData to be updated
SDE context to update
SmartForm component type (select based on component type as set in SmartForm and bound to the identified SDE)
Code Template
172642 SF SCRIPTING - ADD RULE ERROR MESSAGE TO SDE
Reference
SmartForm Script - Set SmartForm-Bound EPT (Chronicles) Data Value from a Rule (CER) Message
LPP 42940 (ES SET RULE ERROR IN SMARTFORM FIELD) can be copied and used to set the value of a SmartForm Field object.
Parameters
CER rule identifier (must return error message)
EPT identifier
Limitations
Limited to SmartForms that can bind EPT data.
SmartForm Script - Append Values to a SmartForm SmartData element that is in List (category) format
LPP 24516 (SMARTFORM APPEND VALUES) can be copied and used to add values to a List, SmartGrid or a SmartText Box component via SmartForm Scripting.
Parameters
SDE Identifiers (AHS#NNN format) of SDEs to append to the SmartForm
Values to append to respective SDEs; must be value values in valid format for the SmartForm setup
Context; which must match context for the SDEs in the SmartForm
Custom SmartForm Extensions
Set SmartForm Label Caption from a Rule (CER) Message in Patient Score Context
Parameters
CERID = CER patient score rule identifier (must return error message)
LABELID = Identifier of the SmartForm Label object where caption will be set
Use
Note that a code template (see above) should be used when the rule error message come from a rule record that is of "patient" type.
Custom code is needed only when trying to pull a rule of "patient score" type into a SmartForm lable caption.
Code
s %=$$SFGetIDDAT^elibHULIB100("EPT",.ptID,.ptDAT) s RSLT=$$evalRule^elibHULIB22("CERID",.ptID,.ptDAT) s % = $$SFSetProp^elibHULIB100("LABELID","Caption",RSLT)
Patient Rule Error Message to SmartData Element - Update SmartData element from error message from a Rule (CER) in Patient Context
Parameters
CERID - Rule record identifier (patient context rule)
SDE#ID - Smart Data Element Identifier
CONTEXT - match the SDE context of the SmartForm element: "PATIENT" or "ENCOUNTER"
Use
Single-select category or string to single select category or string
The target SDE must be of "Base" type (string). Attempting to update a number, instant or date SDE, for example, will fail.
NOTE: Custom code should not be used in this situation any more. See above templated extension for Rule (patient or score) to SDE (any type).
Code
s RSLT=$$evalRule^elibHULIB22("CERID",.ptID,.ptDAT) s %=$$SFPutCV^elibHULIB100("SDE#ID","CONTEXT",RSLT)
Patient Score Rule Error Message to SmartData - Update SmartData element from error message from a Rule (CER) in Patient Score Context
Parameters
CERID - Rule record identifier (patient context rule)
SDE#ID - Smart Data Element Identifier
CONTEXT - match the SDE context of the SmartForm element: "PATIENT" or "ENCOUNTER"
Use
Single-select category or string to single select category or string
The target SDE must be of "Base" type (string). Attempting to update a number, instant or date SDE, for example, will fail.
NOTE: Custom code should not be used in this situation any more. See above templated extension for Rule (patient or score) to SDE (any type).
Code
s RSLT=$$evalRule^elibHULIB22("CERID",.ptID,.ptDAT) s %=$$SFPutCV^elibHULIB100("SDE#ID","CONTEXT",RSLT)
Flowsheet to SmartData - Set SDE Value from Flowsheet Row Value - String Only
Parameters
SDE#ID - Smart Data Element Identifier
CONTEXT - match the context of the SmartForm: PATIENT, ENCOUNTER
FLT - Flowsheet Template identifier
FLO - Flowsheet Row identifier
Use
String from flowsheet row to base type SDE (string)
Code
s %=$$SFGetIDDAT^elibHULIB100("EPT",.ptID,.ptDAT) s val=$$lastflow^LAPEX09C(ptID,ptDAT,FLO) s %=$$SFPutCV^elibHULIB100("SDE#ID","CONTEXT",val)
SmartData to Flowsheet - Set Flowsheet Row Value from SDE Value - Category (single-select) or String
Parameters
SDE#ID - Smart Data Element Identifier
CONTEXT - match the context of the SmartForm: PATIENT, ENCOUNTER, EPISODE, NOTE, ORDER, PROBLEM, etc.
FLT - Flowsheet Template identifier
FLO - Flowsheet Row identifier
Use
Single-select category or string to single select category or string
Code
s %=$$SFGetIDDAT^elibHULIB100("EPT",.ptID,.ptDAT) s val=$$SFGetCV^elibHULIB100("SDE#ID","CONTEXT",1) d SetFloValAry^JFSAPI3(.floValAry,ptID,ptDAT,FLT,FLO,"",$$time^%Zelibb(),"",val) d storeSetup^JVITAL20(ptID,ptDAT,FLT,0,"","",.floValAry)
SmartData to Flowsheet - Set Flowsheet Row Value from SDE Value - Date Only
Parameters
SDE#ID - Smart Data Element Identifier
CONTEXT - match the context of the SmartForm: PATIENT, ENCOUNTER, EPISODE, NOTE, ORDER, PROBLEM, etc.
FLT - Flowsheet Template identifier
FLO - Flowsheet Row identifier
Use
Date type SDE to Date formatted flowsheet row
Code
s val=$$zInst2DTE^%Zelibp($$SFGetCV^HULIB100("SDE#ID","CONTEXT",1)) d SFGetIDDAT^HULIB100("EPT",.patID,.patDAT) d SetFloValAry^JFSAPI3(.floValAry,patID,patDAT,FLT,FLO,"",$$time^%Zefnlib(),"",val) d storeSetup^JVITAL20(patID,patDAT,FLT,"","","",.floValAry)
SmartData to Flowsheet - Set Flowsheet Row Value from SDE Value - Multi-select
Parameters
SDE#ID - Smart Data Element Identifier
CONTEXT - match the context of the SmartForm: PATIENT, ENCOUNTER, EPISODE, NOTE, ORDER, PROBLEM, etc.
FLT - Flowsheet Template identifier
FLO - Flowsheet Row identifier
Use
Multi-select category or string to Multiselect flowsheet row
Code
s ln=1,data="" f { s val=$$SFGetCV^HULIB100("SDE#ID","CONTEXT",ln) s:val="" val=$$geti^EAXLIB("HLX",$o(^EX("HLX",40,val,"")),50,1,99999) q:val="" s data=data_$s(ln>1:", ",1:"")_val s ln=ln+1 q:ln>10 } d SFGetIDDAT^HULIB100("EPT",.patID,.patDAT) d SetFloValAry^JFSAPI3(.floValAry,patID,patDAT,FLT,FLO,"",$$time^%Zefnlib(),"",data) d storeSetup^JVITAL20(patID,patDAT,FLT,"","","",.floValAry)
SmartData to SmartData - Update one SmartData element from another (equivalent type) SDE
Parameters
FROMSDE#ID - Smart Data Element Identifier to get value from
TOSDE#ID - Smart Data Element identifier to update
CONTEXT - match the context of the SDE: PATIENT, ENCOUNTER
Use
Move data between similar type SDEs
Code
s %=$$SFGetIDDAT^elibHULIB100("EPT",.ptID,.ptDAT) s errMsg=$$SFGetCV^elibHULIB100("FROMSDE#ID","CONTEXT",1) s %=$$SFPutCV^elibHULIB100("TOSDE#ID","CONTEXT",errMsg)
Resources
Epic: Extension Search Report Template - to identify records using particular extensions
Epic Forum: Setting SmartForm Fields using Scripting and Extensions