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
Comments
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:
.png)
The value in tRecStr should be the formatted record.
I am not using a batch header in the Record Map but is there a way to get the field descriptions as well. Right now, when I look at the field, it is the field value, but I need to get the name as well to define as part of the FHIR query. Is there a way to do that as well?
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 ASCThat would get you the field names in the same order as the data and exclude any percent properties.