Using custom code in DTL

275 views
Skip to first unread message

sunny

unread,
Mar 7, 2011, 4:43:43 PM3/7/11
to InterSystems: Ensemble in Healthcare
I am new to ensable.

The following is the code from one of DTL(I newly created), Here I am
just mapping the source segments to target segments if priority="M"
from source. Here I am mapping HL7 2.2:ORM_O01 to 2.2:ORM_O01.

What I need is , I need to map the target only if my "sendFlag" is
"true" from the code block.

Could any of you please suggest how can I slove this? Basically I need
to map target only if the certain conditions match in my code block.
I am seeting sendFlag to "true" if all my conditions match.

I really appreciate any of your help on solving this.



<?xml version="1.0" ?>
<transform targetClass='EnsLib.HL7.Message'
targetDocType='2.2:ORM_O01' sourceClass='EnsLib.HL7.Message'
sourceDocType='2.2:ORM_O01' create='new' language='objectscript'>
<code>
<![CDATA[
SET priorityFlag="source.{ORCgrp(1).ORC:Quantitytiming(1).priority}"
SET ScheduledDate="..SubString(source.
{ORCgrp(1).OBRuniongrp.OBRunion.OBR:Scheduleddatetime},1,8)"
SET ScheduledTime="..SubString(source.
{ORCgrp(1).OBRuniongrp.OBRunion.OBR:Scheduleddatetime},9)"
SET today=$ZDATETIME($H,8,2)
SET today=$TRANSLATE(today," :") //notice the space before the :
SET currdate="..Substring(today,1,8)"
SET currtime="..Substring(today,9)"
IF priorityFlag="M",ScheduledDate=currdate,currtime>0300{
SET sendFlag="true"
QUIT
}
ELSE {
}
]]>
</code>
<if condition='..StartsWith(source.
{ORCgrp(1).ORC:Quantitytiming(1).priority},"M")'>
<true>
<assign property='target.{MSH}' value='source.{MSH}' action='set'/>
<assign property='target.{NTE()}' value='source.{NTE()}' action='set'/
>
<assign property='target.{PIDgrp}' value='source.{PIDgrp}'
action='set'/>
<assign property='target.{ORCgrp()}' value='source.{ORCgrp()}'
action='set'/>
</true>
<false>
</false>
</if>
</transform>

David Loveluck

unread,
Mar 7, 2011, 5:35:05 PM3/7/11
to ensemble-in...@googlegroups.com
This should be easier than you think. You can just test your code variable

<if condition='sendFlag="true"'>
...

But your sample code has other problems.

You can't just take the DTL syntax and put a Set in the beginning to get valid code. You have to use the correct syntax for setting variables and you have to use a method call to return the value of a field.

SET priorityFlag=source.GetValueAt("ORCgrp(1).ORC:Quantitytiming(1).priority")

'Quit' will take you out of a do loop or a for loop to the next level, but an 'if' condition doesn't start a new level so this quit will take you out of the DTL altogether. Remove the quit.

You have to make sure sendFlag is set in the false branch or you will get an <UNDEFINED> error when you test it.

dave

--
You received this message because you are subscribed to the Google Groups "InterSystems: Ensemble in Healthcare Community" group.
To post to this group, send email to Ensemble-in...@googlegroups.com
To unsubscribe from this group, send email to Ensemble-in-Healt...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Ensemble-in-Healthcare?hl=en

Simpson, Matt

unread,
Mar 7, 2011, 5:38:34 PM3/7/11
to ensemble-in...@googlegroups.com
In addition to what Dave says, it seems that what you need is a rule rather than a DTL.

You want to send a message through, unchanged, if your conditions evaluate to true - that is what a rule is for.

One problem is that you want to compare the Scheduled date time to Today and only send it if they are the same (and the time is after 3 AM)

However, you can't do that in a rule because $H isn't valid in a rule.

Therefore, you should create a custom function class and call it from your rule.

The class could be this:

Class test.Functions Extends Ens.Rule.FunctionSet
{
/// Retruns now as a 14 character string YYYMMDDHHMMSS
ClassMethod now() As %String [ CodeMode = expression ]
{
##class(Ens.Util.Time).FormatDateTime("%Y%m%d%H%M%S")
}


}

The rule could be this:

<?xml version="1.0" encoding="UTF-16"?>
<routingRule host="test" name="test" effectiveBeginDateTime="" effectiveEndDateTime="" context="EnsLib.MsgRouter.RoutingEngine" doAll="false" source="" msgClass="" docName="" docCategory="" docType="">
<FullName>test</FullName>
<description></description>
<reportGroup></reportGroup>
<reportName></reportName>
<shortDescription></shortDescription>
<rule source="" msgClass="EnsLib.HL7.Message" docName="" docCategory="2.2" docType="ORM_O01">
<condition join="AND" operator="=" op1="Document.{ORCgrp(1).ORC:Quantitytiming(1).priority}" op2="&quot;M&quot;"></condition>
<condition join="AND" operator="=" op1="SubString(Document.{ORCgrp(1).OBRuniongrp.OBRunion.OBR:Scheduleddatetime},1,8)" op2="SubString(now(),1,8)"></condition>
<condition join="AND" operator="&gt;" op1="SubString(Document.{ORCgrp(1).OBRuniongrp.OBRunion.OBR:Scheduleddatetime},9)" op2="SubString(now(),9)"></condition>
</rule>
</routingRule>


Thanks!

Matt Simpson
Information Systems | Inland Imaging Business Associates
Tel: 509.363.7759 | Cell: 509.370.7141 | Fax: 509.363.7082

dave

This electronic transmission and any documents accompanying this electronic transmission may contain information that is confidential and/or legally privileged. The information is intended only for the use of the individual or entity named above. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on or regarding the contents of this electronically transmitted information is strictly prohibited. If you have received this e-mail in error, please notify the sender and delete this message immediately.

sunny

unread,
Mar 8, 2011, 10:31:58 AM3/8/11
to InterSystems: Ensemble in Healthcare
Matt,

Thanks for your input. It worked for me.

Dave,
Thank you. I have used Matt suggestion on using it in Rules and have
custom function called from Rules.



On Mar 7, 5:38 pm, "Simpson, Matt" <MSimp...@inlandimaging.com> wrote:
> In addition to what Dave says, it seems that what you need is a rule rather than a DTL.
>
> You want to send a message through, unchanged, if your conditions evaluate to true - that is what a rule is for.
>
> One problem is that you want to compare the Scheduled date time to Today and only send it if they are the same (and the time is after 3 AM)
>
> However, you can't do that in a rule because $H isn't valid in a rule.
>
> Therefore, you should create a custom function class and call it from your rule.
>
> The class could be this:
>
> Class test.Functions Extends Ens.Rule.FunctionSet
> {
> /// Retruns now as a 14 character string YYYMMDDHHMMSS
> ClassMethod now() As %String [ CodeMode = expression ]
> {
> ##class(Ens.Util.Time).FormatDateTime("%Y%m%d%H%M%S")
>
> }
> }
>
> The rule could be this:
>
> <?xml version="1.0" encoding="UTF-16"?>
> <routingRule host="test" name="test" effectiveBeginDateTime="" effectiveEndDateTime="" context="EnsLib.MsgRouter.RoutingEngine" doAll="false" source="" msgClass="" docName="" docCategory="" docType="">
>   <FullName>test</FullName>
>   <description></description>
>   <reportGroup></reportGroup>
>   <reportName></reportName>
>   <shortDescription></shortDescription>
>   <rule source="" msgClass="EnsLib.HL7.Message" docName="" docCategory="2.2" docType="ORM_O01">
>     <condition join="AND" operator="=" op1="Document.{ORCgrp(1).ORC:Quantitytiming(1).priority}" op2="&quot;M&quot;"></condition>
>     <condition join="AND" operator="=" op1="SubString(Document.{ORCgrp(1).OBRuniongrp.OBRunion.OBR:Scheduleddateti­me},1,8)" op2="SubString(now(),1,8)"></condition>
>     <condition join="AND" operator="&gt;" op1="SubString(Document.{ORCgrp(1).OBRuniongrp.OBRunion.OBR:Scheduleddateti­me},9)" op2="SubString(now(),9)"></condition>
> For more options, visit this group athttp://groups.google.com/group/Ensemble-in-Healthcare?hl=en
>
> --
> You received this message because you are subscribed to the Google Groups "InterSystems: Ensemble in Healthcare Community" group.
> To post to this group, send email to Ensemble-in...@googlegroups.com
> To unsubscribe from this group, send email to Ensemble-in-Healt...@googlegroups.com
> For more options, visit this group athttp://groups.google.com/group/Ensemble-in-Healthcare?hl=en
>
> This electronic transmission and any documents accompanying this electronic transmission may contain information that is confidential and/or legally privileged. The information is intended only for the use of the individual or entity named above. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on or regarding the contents of this electronically transmitted information is strictly prohibited. If you have received this e-mail in error, please notify the sender and delete this message immediately.- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages