This is supplementary article that outlines how to utilize the macro tab and/or print variables in Typing Templates (TTs). For details on this SOs workflow, visit the Typing Template article.
Available Functionalities Through Macros
Add Macro to Typing Template
Summary for Macro Template Customization
Full Explanation for Macro Template Customization
Update Encounter Type
Add Diagnosis Code to Contact
Update Contact Title with a Text Description (RETIRED)
Set Up Typing Templates that require both Macro and Text Tabs
Launch Open A Form
Print Variables
Create a Print Variable That Will Load a Lab Result
Use The Print Variable Macro Function To Pull In Lab Results In a Typing Template
Adding common custom code
Additional contact(s) using diagnosis code (no text content)
Launch open multiple forms
Available Functionalities Through Macros
The following functionality can be controlled using the Typing Template's (TT) macro tab:
- Encounter type - can update the Encounter Type if the type is undefined, or will overwrite the current type if the TT is used in the primary contact of the encounter.
- Contact title - can update the current contact title (if it is not defined), or will create a new contact with the specified title (prevent overwriting)
- Open a form - can launch open a form
Any of the above can be used in combination with each other or on its own.
Add Macro to Typing Template
Reminder: This should always be done in DEV. Do not create directly into production! Please refer to the Background section for more details.
- Open and existing TT or create a new TT (see Typing Template article for more details)
- Click on Macro Tab in Typing Template Properties Window
- Copy and paste the entire code below into the Macro tab and update the variables based on the desired behaviour of the TT. See Summary For Macro Template Customization.
Sub Main()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'UPDATE THESE VARIABLES DEPENDING ON THE TT'S NEEDS
'Reminder if left "", the code will not change anything in that area
'Encounter Type
vEncounterType = "" 'changes the Type if not specified already
'Contact Title/Diagnosis Code
vDiseaseCode = "" 'changes/adds Contact and Title with existing Disease Code
'Other variables
vTextTT = "" 'call another TT (i.e: to print out the content of the Text tab of another TT)
vFormLink = "" 'launch a form. The value should match what is found in Form Links short code. Ex: "BCCA_GYNECOLOGY"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Locate edit encounter window
Set ee = Profile.EncounterEditor(Profile.PatientID)
If ee.IsAccessible Then
'Updates/adds contact title if vDiseaseCode is specified above
If Len(vDiseaseCode) > 0 Then
Set aDisease = Profile.LoadDisease(vDiseaseCode)
If (aDisease.ID <> 0) Then
If Not ee.CurrentContact.DiagnosisCode = aDisease.Code Then
If (Len(ee.CurrentContact.DiagnosisCode) > 0) Then
ee.AddDiagnosis 0, ""
End If
ee.EditDiagnosis ee.CurrentContactIndex, aDisease.ID, aDisease.Description
End If
Else
Profile.MessageBox "Disease Code '" & vDiseaseCode & "' is not found."
End If
End If
'Updates encounter type if vEncounterType is specified above and is either the first Contact or not already defined
If Len(vEncounterType) > 0 Then
If ((ee.CurrentContactIndex = 0) Or (Len(ee.Encounter.TypeCode) = 0)) Then
ee.Encounter.TypeCode = vEncounterType
End If
End If
'Adds text template TT if vTextTT is specified above
If Len(vTextTT) > 0 Then
If Not Profile.UI Is Nothing Then
Profile.UI.SendKeys (vTextTT & "\")
Profile.UI.Delay 5 'add delay in ms to give the TT a chance to run before loading form, if any
End If
End If
'Force refresh encounter so that the changes will display
For i = 0 To ee.ContactsCount - 1
If strComp(ee.Contacts(i).AnnotationRtf, ee.ContactTextAsRTF(i), 1) <> 0 Then
ee.Contacts(i).SetAnnotationRtf ee.ContactTextAsRTF(i)
End If
Next
ee.Refresh
'Launches a form if vForm is specified above
If Len(vFormLink) > 0 Then
strFormName = Profile.LoadShortCodebyCodeSCTName(vFormLink, "Form Links").Description
Set objForm = Profile.OpenFormByPath(Profile.Patient.ID, strFormName)
End If
''''ADD ADDITIONAL CUSTOM CODE BELOW THIS LINE'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''END OF CUSTOM CODE ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End If
End Sub
Summary For Macro Template Customization
The only section that needs to be updated is at the top where the variables are defined. Update the following based on different needs, even if it means you have to update more than one. For context, see Full Explanation for Macro Template Customization section or click the Variable Name to go directly to that section.
| Variable Name | Explanation | Example |
| vEncounterType | Changes the Encounter Type only if this is either the first contact in the encounter, or the Type has not yet been changed. | vEncounterType = "COUNSEL" |
| vDiseaseCode | Updates the Diagnosis Code for the contact and the Contact Title with an existing Disease Code. If the current contact already has a title, it will create a new one below the original one. | vDiseaseCode = "ASV" |
| vTextTT | Calls another TT. This is required if the TT needs to have both a formatted templated text and macro code (ex: update Encounter Type, update title, launch form). | vTextTT = "AGATEXT" |
| vFormLink | Opens a form. Note that you must specify the code of the form found in the Short Code Form Links. | vFormLink = "BCCA_GYNECOLOGY" |
Full Explanation for Macro Template Customization
Update Encounter Type
- To find the desired encounter type's code, go to Maintain > Short Codes
- Under the Type segment, locate then click on Contacts. In the right segment, you should see a list of Contacts. From this list, you want to use what appears in the Code column.
- Copy and paste the code from the Macro Code Template from the Add Macro to Typing Template section into the Macro Tab
- Insert the Contact Code between the "" (double quotes) for the vEncounterType variable
- Ensure that the the usual Typing Template standards are followed (i.e. Fill in Code, Description and make Available to Everyone)
- When you test out the TT, you should expect the Encounter Type to update if:
- It is the first contact of the encounter, regardless if the type was defined already because the encounter was launched from an appointment
- The encounter type was empty, as in if the encounter doesn't already have a type specified
Add Diagnosis Code To Contact
- Go to Maintain > Disease Codes to ensure the disease code you want to use exists. If it's not present, it has to be created in EMR as a Standard Order. Refer to Manage Disease Codes article. Recommendation: use the same code for the Disease Code and the TT Code for easier maintenance.
- Copy and paste the code from the Macro Code Template from the Add Macro to Typing Template section into the Macro Tab
- Insert the code into the macro between the "" (double quotes) for the vDiagnosisCode variable.
- Ensure that the the usual Typing Template standards are followed (i.e. Fill in Code, Description and make Available to Everyone)
- When you test out the TT, you should expect the Contact Title to be updated and if clicked, you can see the Disease Code under the Diagnosis field
Update Contact Title with a Text Description (RETIRED)
Note: We no longer support this method as of April 17 2025 (see EMR-9160). If you are updating an existing TT and it's using vAdhocContactTitle instead of vDiseaseCode variable to update the Contact Title, recopy the Macro Code Template from the Add Macro to Typing Template section, reapply any other variables the TT needs, and follow the steps to Add Diagnosis Code to Contact instructions to populate the title.
Set Up Typing Templates that requires both Macro and Text Tabs
To have this macro work with the Text Tab, unfortunately there are core code limitations and a convoluted workaround needs to be done. If the request of the TT is to have both text content printed out on top of other behaviours covered by macro (ex: change contact title, launch form), follow the steps below. Note: if the TT only needs the Text Tab and no macro required, follow the Typing Template article.
- Create a TT with the code that users will use.
- Follow the steps in the Create a Typing Template Using The Macro Function section
- Copy and paste the code from the Macro Code Template from the Add Macro to Typing Template section into the Macro Tab
- Update the vTextTT variable to the same code but with "TEXT" added to the end of it. (ex: if the users will use AGA to call this TT, it should be vTextTT = "AGATEXT").
- At the end of the TT's description, add "(calls <vTextTT value>)", which in this example it should be "(calls AGATEXT)"
- Ensure that the the usual Typing Template standards are followed (i.e. Fill in Code, Description and make Available to Everyone)
- There should not be anything in the Text Tab
- Create a second TT with the same code used for vTextTT in the first TT.
- Follow steps to create the Text Tab from the Typing Template article
- Make the TT's description the same as the other TT, but instead add "(TEXT ONLY)" to the end
- Ensure that the the usual Typing Template standards are followed (i.e. Fill in Code, Description and make Available to Everyone)
- There should not be anything in the Macro Tab
Example:
The two TTs needed to update the Diagnosis Code and print out text:
The TT users will use:
The supporting TT that is called by the first TT:
What it looks like when AGA\ is called by the user:
Launch Open A Form
- Identify the Form Links short code for this particular form. Instructions on how to identify and create a new one if needed are found in the Form Links Short Code article.
- Copy and paste the code from the Macro Code Template from the Add Macro to Typing Template section into the Macro Tab.
- Insert the desired code of the form between the "" (double quotes) for the vFormLink variable
- Ensure that the the usual Typing Template standards are followed (i.e. Fill in Code, Description and make Available to Everyone)
- When testing the TT, you should expect the form to launch just after it's typed (other behaviour like updating Contact Title and printing out templated text should trigger first)
Print Variables
- Print Variables can be used in the Text Tab of typing templates to pull in the last lab result
- They are also utilized in other areas of Profile EMR, such as forms
- If no existing print variable exists for the lab result requested, a new one must be created
- If a lab result is not available for the client, the expected behavior is to display “No Result Found”
- If this does not occur, check for an alternative print variable if available
- If a print variable behaves differently than expected (e.g., displays blank when no result), bring the issue to the team huddle for a decision: Should it be modified or should a new one be created?
- Approval for modifying a print variable requires a pre-technical impact analysis by a developer
Create a Print Variable That Will Load a Lab Result
To create a macro print variable, you will first need to get an example of the result you want to pull.
1. To find the details you need, you can go to the Results section of the medical record, right click on the result and go to Cumulative view.
2. Then right click again on the last result that appears in the list to the right, select Edit.
3. The Edit Measurement window will appear with the Termset and Concept code that you are looking for at the top.
Note: All terms must be cross-referenced in order to show in this list.
To validate the Termset and Concept code:
a) Go to Maintain, Termset Maintenance.
b) In the Term Selector window, change Termset to what you are looking for.
In this example, we will be look at the PHC term set.
c) In the Options field, select Has code and then search for you code. We will be looking for HIV in this example.
Now that you have the data fields required and validated them. You can use this information to pull the specific results you are looking for by creating a new Print Variable Macro.
To create this New Print Variable Macro:
1. Go to Maintain, Templates, then select Print Variable.
2. Click on the New Macro button.
3. Fill in the Code and Description field.
Then copy and paste the following macro into the body of the Print Variable Macro.
aDateTo = Now
aDateFrom = DateAdd("yyyy",-30,aDateTo)
aDateTo = DateAdd("yyyy",1,aDateTo)
Set aResult = Patient.GetLatestHRI("", "", aDateFrom, aDateTo, 1)Instructions:
a) In the two “” you see in the above line, you want to replace it with the termset followed by concept code.
Set aResult = Patient.GetLatestHRI("PHC", "HIV", aDateFrom, aDateTo,
if not aResult is nothing then
Set aResultContent = aResult.Content
aResultContentValue = aResultContent.AsString
aResultDate = aResult.ObservedOn
aResultDate = Profile.FormatDate(aResultDate,"DD-MMM-YYYY")
theResult = aResultContentValue & "; (" & aResultDate & ")"
else
theResult = "No Result Found"
end if
Variable("PrintVariable").Value = theResultOnce you have completed this it should look something like this.
Now that you have created the Print Variable Macro. We can now create our typing template that will pull this lab result.
Use The Print Variable Macro Function To Pull In Lab Results In a Typing Template
To create this typing template you will need to do the following:
1. Ensure that you are in the Text tab of your Typing Template Properties window.
2. Click on the Insert Variable button in the toolbar.
3. In the Print Variable table, you want to click on Patient, Macro and then select any of the in-house created macros that pulls results.
Ie. «Letter.Patient.Macro.LASTHIVAB»
In the body of the Text, typing the name of the result you are going to pull. For example: Last INR: then insert the macro print variable. You can also click this link to jump to the macro template in the appendix.
Last INR: «Letter.Patient.Macro.LASTHIVAB»
Once you have completed this, your typing template should look something like this.
Give it a try in a test environment. If you type lhivt\ into a new encounter, we would expect you to see that the last HIV AB result will be pulled from the client medical record and appear in the encounter as seen below.
Adding common custom code
The rare occasion there may be a request to add something more than the usual standard code can support. This section outlines how to handle these most common requests. All the code should be placed within the section set aside for custom code, in between these two lines, close to the bottom of the macro:
''''ADD ADDITIONAL CUSTOM CODE BELOW THIS LINE'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''END OF CUSTOM CODE ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Note: the below code blocks can mix and matched. Ex: you can add an additional contact via diagnosis code and open a second form.
Additional contact(s) using diagnosis code (no text content)
The below code will add an additional Contact below the first one handled by the standard code, using diagnosis code. Reminder to replace <CODE> with the correct diagnosis code.
''''ADD ADDITIONAL CUSTOM CODE BELOW THIS LINE'''''''''''''''''''''''''''''''''''
Set aDisease2 = Profile.LoadDisease("<CODE>")
If (aDisease2.ID <> 0) Then
If Not ee.CurrentContact.DiagnosisCode = aDisease2.Code Then
Call HandleOtherContacts(ee)
ee.EditDiagnosis ee.CurrentContactIndex, aDisease2.ID, aDisease2.Description
End If
Else
Profile.MessageBox "Disease Code '<CODE>' is not found."
End If
''''END OF CUSTOM CODE '''''''''''''''''''''''''''''''''''''''''''''''''''''''''If the TT needs more than one additional contact, repeat the same code but increase the number 2 to 3, etc., ensuring to also update the diagnosis code of each.
Example - the below code will create 2 contacts below the original one, one for SHX108 and another for NURS06:
''''ADD ADDITIONAL CUSTOM CODE BELOW THIS LINE''''''''''''''''''''''''''''''
Set aDisease2 = Profile.LoadDisease("SHX108")
If (aDisease2.ID <> 0) Then
If Not ee.CurrentContact.DiagnosisCode = aDisease2.Code Then
Call HandleOtherContacts(ee)
ee.EditDiagnosis ee.CurrentContactIndex, aDisease2.ID, aDisease2.Description
End If
Else
Profile.MessageBox "Disease Code 'SHX108' is not found."
End If
Set aDisease3 = Profile.LoadDisease("NURS06")
If (aDisease3.ID <> 0)Then
If Not ee.CurrentContact.DiagnosisCode = aDisease3.Code Then
Call HandleOtherContacts(ee)
ee.EditDiagnosis ee.CurrentContactIndex, aDisease3.ID, aDisease3.Description
End If
Else
Profile.MessageBox "Disease Code 'NURS06' is not found."
End If
''''END OF CUSTOM CODE ''''''''''''''''''''''''''''''''''''''''''''''''''''Launch open multiple forms
The below code will launch an additional form on top of the one already specified in the standard code. Reminder to replace <SHORT CODE> with the correct value from the Forms Links Short Code list.
''''ADD ADDITIONAL CUSTOM CODE BELOW THIS LINE''''''''''''''''''''''''''''''
strFormName2 = Profile.LoadShortCodebyCodeSCTName(<SHORT CODE>, "Form Links").Description
Set objForm2 = Profile.OpenFormByPath(Profile.Patient.ID, strFormName2)
''''END OF CUSTOM CODE ''''''''''''''''''''''''''''''''''''''''''''''''''''If the TT needs more than two forms launched, repeat the same code but increase the number 2 to 3, etc., ensuring to also update form path for each.
Example - the below code will launch two additional forms, "COVID19 Screener" and "Risk Mitigation Prescribing Enrollment Form":
''''ADD ADDITIONAL CUSTOM CODE BELOW THIS LINE''''''''''''''''''''''''''''''
strFormName2 = Profile.LoadShortCodebyCodeSCTName("BCCA_GYNECOLOGY", "Form Links").Description
Set objForm2= Profile.OpenFormByPath(Profile.Patient.ID, strFormName2)
strFormName3 = Profile.LoadShortCodebyCodeSCTName("BCCA_LDCTSCAN", "Form Links").Description
Set objForm3= Profile.OpenFormByPath(Profile.Patient.ID, strFormName3)
''''END OF CUSTOM CODE ''''''''''''''''''''''''''''''''''''''''''''''''''''