Question
Bukhtiar Ahmad · Sep 29, 2020

how to assign value to variable in business rules using a function?

Hi

I want to check patient class in multiple rules, since the message structure is different to reach out to patient class value, i created a method to get the patient class and put it in a variable. This variable i can use in multiple rules. But somehow function is not able to read the HL7 message. Any tips.

In rules i have this assign line.

Function code looks like this, but in the msg pHL7 dont contain any. I tried getPatientClass(HL7) as well as getPatientClass(HL7.Source)

ClassMethod getPatientClass(pHL7 As EnsLib.HL7.Message) As %String
{ try{
SET msgType = pHL7.GetValueAt("MSH:9") //MSH:MessageType.TriggerEvent

IF msgType="A39"||msgType="A40"//checing merge msgs
 return pHL7.GetValueAt("PIDgrp(1).PV1:PatientClass")}

IF msgType="A45"{
 return pHL7.GetValueAt("MRGgrp(1).PV1:PatientClass")}

IF msgType="A20"||msgType="A30"||msgType="A47"//checking merge msgs
 return "U"}

IF msgType="O01"||msgType="O11"||msgType="O09"//checking medication msgs
 return pHL7.GetValueAt("PIDgrp.PV1grp.PV1:PatientClass")}

IF msgType="R01"//checking lab msgs
 return pHL7.GetValueAt("PIDgrpgrp(1).PIDgrp.PV1grp.PV1:PatientClass")}
 
IF msgType="T11"||msgType="T02"||msgType="T04"||msgType="T08"//checking document msgs
 return pHL7.GetValueAt("PV1:PatientClass")}

return pHL7.GetValueAt("PV1:PatientClass")
}
Catch {
return "U" //return unknown in case of error so validation will be ignore
}
}
 

00
0 8 88 3

Replies

Hi Bukhtiar,

Use the property "Document" instead HL7 or HL7.Source

Like this:

The Function HL7AtribuirValor assign the value "A08" int the field "MSH:MEssageType.triggerevent", in the Document that is the HL7 Message and returns a boolean value.

no luck, this method should be in FunctionSet class? 

Class VALIDATION.RulesFunctionSet Extends Ens.Rule.FunctionSet
{
ClassMethod getEmiratesId(pHL7 As EnsLib.HL7.Message) As %String

Yes.

/// <p>
/// <b>2020-04-23 - Cristiano José da Silva</b><br/>
/// Conjunto de fuincões a serem utilizadas pelas regras , tranformações e process
/// <p>
Class HC.distribuicao.utils.FunctionSet Extends Ens.Rule.FunctionSet
{ 

ClassMethod HL7AtribuirValor(valor As %String, caminhoPropriedade As %String, mensagem As EnsLib.HL7.Message) As %Boolean [ Final ]
{
    If ('mensagem.IsMutable)
    {
        Throw ##Class(%Exception.General).%New("ObjetoImutavel", 5001, $$$CurrentClass _ "." _ $$$CurrentMethod, "Impossível atribuir valor a mensagem imutável.")
    }
    Do mensagem.SetValueAt(valor, caminhoPropriedade, "set", "")
    //
    Return 1
}
 
}

there must be something i am doing wrong, i removed all my code and simply wants to return message type value from the msg and debugging it to see the value but somehow its not coming.

Class VALIDATION.RulesFunctionSet Extends Ens.Rule.FunctionSet
{ ClassMethod getPatientClass(pHL7 As EnsLib.HL7.Message) As %String [ Final ]
{
SET msgType = pHL7.GetValueAt("MSH:MessageType.TriggerEvent")
return msgType
}

The DocType is not set in the message header.  

It should look more like the following:  Note that the example below is a custom schema ORUPDF.

Without this set the word paths cannot be used to retrieve the values because these depend on referencing the schema named in the DocType.  

This DocType is assigned within the service normally.

I believe you could also change all the paths to be numerical and it may work:  such as MSH:9.2

Thanks I think this might be the reason i am not able to get values, I tried numeric path but still not luck. What should i do in the MSH to set the document type. ORU^R01 is not sufficient?

How are you bringing the messages in?   I assume through an HL7 service.    The MessageSchemaCategory must be set correctly in the service and the DocType will get set correctly.

If parsed correctly according to the schema then the message will show as Blue in the contents tab of the the message viewer,  if any segments do not match the schema then the message will show as Black at the point of mismatch.   You need to get the message to show as all Blue or the paths (word or numerical) cannot be followed.

Your screenshots showed using the testing facility for the rules and you are using "User Input".   If you scroll down in the form you will find a field to enter the DocType manually.   This field needs to have the syntax I showed above with the schemaname:ORU_R01 in your case.

I think its not my lucky day, as i check message schema category and its says 2.5, may be i am running my rules . Also msg viewer shows blue font so message is correct but somehow method not able to parse HL7 values.

may be i am testing them from the rules editor thats why its not recognizing HL7 values ?