· Aug 16, 2022

Run Class method under HSCUSTOM on terminal

Hi All,

I have a method like this and I want to be able to see the results on the terminal, how do I run this method on a terminal to display the results of this SQL query?

Method ResponseTimeCurrentMonth(namespace)
set oldNamespace = $Namespace
new $Namespace
    set $Namespace = namespace
    timeTaken = 0, InDate = ""
    #SQLCompile Select=Display
&SQL(select InDate, AVG(Time_Taken) into :InDate, :timeTaken from (select SessionId, (TimeCreated) InDate, MIN(TimeCreated) Start_Time,MAX(TimeProcessed) End_Time, DATEDIFF('ms',MIN(TimeCreated),MAX(TimeProcessed)) Time_Taken FROM Ens.MessageHeader where status = 'Completed' and Resent is null and Month(TimeCreated) = Month(current_date) group by SessionId) group by Year(InDate), Month(InDate)) new $Namespace
    set $Namespace = oldNamespace 
do ..SetSensor("ResponseTimeCurrentMonth",timeTaken,namespace)

Product version: IRIS 2020.2
$ZV: HealthShare 2020.2 [HealthShare Modules: Active Analytics:20.0.8620 + Core:20.0.8620 + Patient Index:20.0.8620] - IRIS for UNIX (Red Hat Enterprise Linux for x86-64) 2020.1 (Build 217_1_20418U) Tue Nov 17 2020 15:48:44 EST
Discussion (2)3
Log in or sign up to continue

As it is not a class method you need either to create/open an object for the class or rewrite the method as ClassMethod (instead of Method). But as the SetSensor call is also pointing to the same object (See do ..SetSensor), the simplest would be to create/open the object:

set obj=##class(Package.YourClass).%New()
do obj.ResponseTimeCurrentMonth("USER")

You may also need to add some Writes to the terminal to see something. For example:

write  !,"Date:",InDate
write  !, "time taken:",timeTaken