Question
· Aug 9

Get Record Map as a String within a DTL to build FHIR query string

I was looking for an easier way to build the FHIR Query String, given the Record Map request that is passed into the DTL.

I built this Function, but when I run a message through it, my Query String that is passed back into the DTL is a Reference Pointer and not the String I am looking for. 

ClassMethod BuildFHIRQueryString(record As %String, Output queryString As %String) As %Status

{

    // Assuming 'record' is a string containing the record map data

    // Define the delimiters

    Set fieldDelimiter = "|"

    Set repeatDelimiter = "~"

   

    set queryString = ""



    // Split the record into fields

    Set fields = $LISTFROMSTRING(record, fieldDelimiter)

   

    // Iterate over each field

    For i=1:1:$LISTLENGTH(fields) {

        Set field = $LISTGET(fields, i)

        if ($LENGTH(i)>0)

        {

          if ($LENGTH($Get(queryString)) > 0)

          {

            set queryString = queryString_"&"_field_"="_$Get(i)

          }

          else

          {

            set queryString = field_"="_$Get(i)

          }

        }

    }

    $$$TRACE(queryString)

    return queryString

    Quit $$$OK

}

 

Within a DTL how I get the entire Raw Record Map String that includes the | Seperators? is it something like... 

##class(Ens.MessageHeader).%OpenId($$$JobSessionId

 Thanks

Scott

Product version: IRIS 2024.1
$ZV: IRIS for UNIX (Red Hat Enterprise Linux 8 for x86-64) 2024.1 (Build 267_2U) Tue Apr 30 2024 16:06:39 EDT [HealthConnect:3.5.0-1.m1]
Discussion (3)2
Log in or sign up to continue

Sorry Scott, nothing so straightforward as that 😉

When you create a RecordMap, you usually create up to 3 classes, depending on whether or not you're using a Batch Class.

So you'll have something like:

  • OSUMC.RecordMap.Patient (the "template")
  • OSUMC.RecordMap.Patient.Record (the actual record class)
  • OSUMC.RecordMap.Patient.Batch (if you're using batch class)

If the RecordMap is the source object in your DTL, it should be an instance of OSUMC.RecordMap.Patient.Record and will be the first argument in the method below.

You'll need to create an instance of OSUMC.RecordMap.Patient with %New(), and pass it as the second argument.

Class HICG.Util.RecordMap [ Abstract ]
{
ClassMethod GetRecordAsString(pRec As %Persistent, pTmpl As %RegisteredObject) As %String
{
    Set tStream = ##class(%Stream.TmpCharacter).%New()
    Set tIOStream = ##class(%IO.MetaCharacterStream).%New(tStream)
    Set tSC = pTmpl.PutObject(tIOStream,pRec)
    If $$$ISOK(tSC)
    {
        Do tStream.Rewind()
        Return tStream.Read(tStream.Size)
    }
    // Empty string if PutObject fails *shrug*
    Return ""
}
}

In the DTL:

The value in tRecStr should be the formatted record.

The field definitions are properties of the *.Record class, so you could perform a property query against %Dictionary.Properties using the *.Record class as the parent.

SELECT Name
FROM %Dictionary.PropertyDefinition
WHERE parent = 'OSUMC.RecordMap.Patient.Record' AND Name >='A' AND Name <= 'z'
ORDER BY SequenceNumber ASC

That would get you the field names in the same order as the data and exclude any percent properties.