Router Business Rule, I want to check PID:7 DOB field and if date is within 3 days then I want to send HL7 to NewBornOperation

Primary tabs

Hi 

I have a use case where for new born I want to send HL7 messages to different business operation. I created the business rule but in condition I am struggling to put syntax something similar to this

HL7.{PID:7} >= Today Date -3

any help would be appreciated. 

Replies

You can use DATEDIFF function to check the days between both date

set date1 = $zdate($horolog,3)
set date2 = $zdate($zdateh("2020-09-01",3),3)
write $SYSTEM.SQL.DATEDIFF("dd",date2,date1)     // 1

In your scenario it could be like this:

$SYSTEM.SQL.DATEDIFF("dd",$ZDATE($ZDATEH(HL7.{PID.7},3),3),$ZDATE($HOROLOG,3)) <= 3

This is a boolean condition, so your rule only have that condition

UPDATE

Rules only accept functions from functions class, so you should create a new class with that function:

Class MyFunctions Extends Ens.Rule.FunctionSet
{
ClassMethod DaysDobHL7(pDob As %String) As %Integer
{
    set date1 = $zdate($horolog,3)
    set date2 = $zdate($zdateh(pDob,3),3)
    
    quit $SYSTEM.SQL.DATEDIFF("dd",date2,date1)
}

then, your new function should be visible in rules function

Regards,
Francisco Lopez

Thanks, $zdate($horolog,3) gives system date?  and this $zdateh(pDob,3) converts DOB in the format as system date? can you refer me to some doc link where I can practice these programming basics?

Indeed.

The parameter 3 in $ZDATE and $ZDATEH is the format of the date YYYY-MM-DD ODBC format

$HOROLOG retrieves the system datetime, so $ZDATE($HOROLOG,3) gives the current sytem date

Usually, HL7.{PID.7} uses the format YYYY-MM-DD, so it converts the string into a datetime variable ($ZDATEH(dob,3))

Please, find out the info in $ZDATE and $ZDATEH documentation.

Best regards,
Francisco Lopez

P.S. Don't forget mark the answer as accepted wink

Hello Bukhtiar,

Not sure if you were just looking for the specific documentation that Francisco provided or something more general. If you want some resources on learning to work with InterSystems products (and specifically ObjectScript), I'd recommend reviewing the courses available on learning.intersystems.com. 

https://learning.intersystems.com/course/view.php?id=289

This course is "Learn Caché ObjectScript" and links to documentation, a tutorial, and an online course.