Ben Webb · Oct 26

DTL Editor: How to get DocType at runtime?

Hi all, 

I'm fairly new to this engine so I was wondering what the best approach for creating a dynamic mapper to downgrade from one HL7 version to another (e.g 2.4 to 2.3) with the DTL Editor,  It seems like something that would be quite commonly needed but I haven't found a method that works yet,

I would like to Map any 2.4 ADT message to the same event type in a lower version (e.g DocType 2.4:ADT_A01 to 2.3:ADT_A01), without having to create a specific map for each trigger event and without having to specify the DocType ahead of time. At the moment I'd need 40 or so unique maps if I was to specify the docType ahead of time so was looking for a more streamlined solution.

Is there a way of using the code action in the DTL Editor to extract the MessageType and TriggerEvent from the source message at runtime, without already having an explicit DocType defined, to use it to specify the DocType for the source and target messages so the rest of the segments can be mapped?

My current approach doesn't compile but it might explain what I'm trying to do 

SET msg=##class(EnsLib.HL7.Message).%OpenId(26872)  //Bring the source message into scope
SET msgEvent = msg.FindSegmentValues("MSH:9.2")           //Get the event type from MSH segment field 9, subfield 2
SET msg.DocType =  "2.4:ADT_"_msgEvent                              //Concatenate into a DocType string and replace the source docType with this value so the engine knows the DocType at runtime

Any help, different approaches, or insight will be very appreciated, 


Product version: HealthShare 2020.2
4 0 4 163
Log in or sign up to continue

You cannot change the doc type of "msg" as its state is immutable. You'll need to create a clone then change doc type. To create the clone:

s outmsg=msg.%ConstructClone(1)

Also note that not all trigger events (MSH:9.2) share the same doctype either, so you'll need to derive it appropriately. e.g. ADT^A01, ADT^A04, ADT^A05 the doc type is  ADT_A01.

Thanks for the reply, I wasn't aware of the immutable state so I'll adjust my approach to suit, Thanks again

You can change the message DocType, but you can't change the message content:

HICG > s msg=##class(EnsLib.HL7.Message).%OpenId(7463)
HICG > w msg.IsMutable
HICG > w msg.DocType
HICG > s msg.DocType="2.5.1:ADT_A01"
HICG > d msg.%Save()
HICG > w msg.DocType

Unfortunately there's no easy way to "reset" the source document type in the DTL editor dynamically. You could, however, dynamically set the document type in either a BPL or COS business process and then invoke the appropriate DTL for translation.

Thanks for the reply, this will come in handy