Written by

Enterprise Application Development Consultant at The Ohio State University Wexner Medical Center
MOD
Question Scott Roth · Dec 26, 2025

Populating Persistent Class from JSON

As I am iterating through the FHIR JSON Response from a Patient Search, I am running into an issue where the extracted values are not being popualted into the Response object that I have created. If I do a $$$LOGINFO on them they will show up in the Object log, however if I try the following for example I get an error.

set target.MRN = identifier.value

ERROR <Ens>ErrException: <INVALID OREF>Transform+15 ^osuwmc.Epic.FHIR.DTL.FHIRResponseToPatient.1 -- logged as '-'
number - @'
set target.MRN = identifier.value
'

Here is my Ens.DataTransform

Class osuwmc.Epic.FHIR.DTL.FHIRResponseToPatient Extends Ens.DataTransform
{

ClassMethod Transform(source As HS.FHIRServer.Interop.Response, target As osuwmc.Epic.FHIR.DataStructures.PatientSearch.Response) As %Status
{
  Set tSC=$$$OK
  set tQuickStream = ##Class(HS.SDA3.QuickStream).%OpenId(source.QuickStreamId)
  set tRawJSON = ##Class(%Library.DynamicObject).%FromJSON(tQuickStream)
  $$$TRACE(tRawJSON.%ToJSON())
  set tResource = tRawJSON.entry.%Get(0).resource
  if tResource.resourceType '= "Patient" {
    set tSC = $$$ERROR($$$GeneralError, "FHIRResponseToPatient: Resource type is not Patient")
    return tSC
  }
  else{
    $$$LOGINFO("Resource Type: "_tResource.resourceType)
    set mrnIter = tResource.identifier.%GetIterator()
    while mrnIter.%GetNext(,.identifier) {
      if identifier.system = "urn:oid:1.2.840.114350.1.13.172.2.7.5.737384.100" {
          set target.MRN = identifier.value
      }
    }
    set NameIter = tResource.name.%GetIterator()
    while NameIter.%GetNext(,.humanName) {
      if humanName.use = "official" {
        set target.LastName = humanName.family
        set target.FirstName = humanName.given.%Get(0)
      }
    }
    set target.DOB = tResource.birthDate
    set target.Gender = tResource.gender
    set addrIter = tResource.address.%GetIterator()
    while addrIter.%GetNext(,.address) {
      if address.use = "home" {
     set target.Address = address.line.%Get(0)
        set target.City = address.city
        set target.State = address.state
        set target.PostalCode = address.postalCode
      }
    }
  }
  return tSC
}

}

If I replace the set statements with $$$LOGINFO, the values will show up in the trace viewer.

Product version: IRIS 2024.1
$ZV: IRIS for UNIX (Red Hat Enterprise Linux 8 for x86-64) 2025.1 (Build 230_2U) Wed Jun 4 2025 18:50:44 EDT [HealthConnect:8.2.2]

Comments

DC AI Bot · Dec 27, 2025 Bot

The issue you're encountering with <INVALID OREF> suggests that the identifier.value or target.MRN is not a valid ObjectScript reference (OREF) during the operation. This happens if the identifier is not properly initialized as an object. To address this issue, verify that identifier contains a valid OREF before trying to access its property value. You can do this using $ISOBJECT.

Here’s an example adjustment to your code:

while mrnIter.%GetNext(,.identifier) {
  if $ISOBJECT(identifier) && (identifier.system = "urn:oid:1.2.840.114350.1.13.172.2.7.5.737384.100") {
    set target.MRN = identifier.value
  } else {
    $$$LOGINFO("Invalid OREF for identifier or system mismatch")
  }
}

This ensures the loop only processes identifier objects that are valid and avoids errors when working with null or invalid OREFs [1][2][3].

Sources:

Tell us more:
Don't like the style
Not factually correct
Didn't fully follow instructions
Refused when it shouldn't have
Being lazy
More...
Submit
0 0
Tani Frankel · Dec 27, 2025

Are you instantiating the 'target' variable?...

It doesn't look like it, hence your Invalid Oref when trying to access the MRN property (unless you're sending it in ByRef, but in that case it seems not be an object either).

So it looks like you were focused on the right side of your SET command, though the problem might be on the left side.

0
Ashok Kumar T · Dec 29, 2025

The invalid oref error because of the target object "osuwmc.Epic.FHIR.DataStructures.PatientSearch.Response" not initiated.  instantiating  the target if it's not OREF.

If '$IsObject(target){
 Set target = ##class(osuwmc.Epic.FHIR.DataStructures.PatientSearch.Response).%New()
}'
0