Ikara Ikliki · Oct 31, 2019

FHIR Resource JSON deserialize error FHIRToHSFHIR - ERROR #5001: %FromFHIRJSON failed - ERROR #5002: ObjectScript error: <INVALID OREF>%FromFHIRJSON2+158^HS.JSON.AdaptorFHIR.1

I am de-serialzing a FHIR Resource CodeSystem in STU3 FHIR resources from JSON in my Business Process using the following code:

set pCodeSystemResource = ##class(HS.FHIR.vSTU3.Model.Resource.CodeSystem).%New()
set tStream = ##class(HS.SDA3.QuickStream).%OpenId(pFHIRRequest.QuickStreamId)
if $IsObject(tStream) {
    set tSC = ##class(HS.FHIR.Utils).FHIRToHSFHIR(pFHIRRequest.ContentType, tStream, .pCodeSystemResource, "HS.FHIR.vSTU3.Model.Resource")

At this point it was validated that the ResourceType in the pFHIRRequest is "CodeSystem"

The error I am getting is in the  FHIRToHSFHIR Implementation's call to FromFHIRJSON 
 and this calls FromFHIRJSON2

The HTTP message is a POST (I am testing to create a new CodeSystem entry) and it does have Content-Type header of "application/json+fhir; charset=UTF-8"

I could not find any documentaiton on how the FHIR JSON de-serialization should work, any documentation or information shall be appreciated.

The JSON being sent is (this is the exact JSON from the publication-status I found on the FHIR website at :
I deleted the "extensions" section however to make it shorter, I do not need it for my test.

  "resourceType" : "CodeSystem",
  "id" : "publication-status",
  "meta" : {
    "lastUpdated" : "2019-10-30T13:56:25.343+11:00"
  "text" : {
    "status" : "generated",
    "div" : "<div>!-- Snipped for Brevity --></div>"
  "url" : "",
  "identifier" : [{
    "system" : "urn:ietf:rfc:3986",
    "value" : "urn:oid:2.16.840.1.113883.4.642.4.4"
  "version" : "4.0.1",
  "name" : "PublicationStatus",
  "title" : "PublicationStatus",
  "status" : "active",
  "experimental" : false,
  "date" : "2019-10-30T13:56:25+11:00",
  "description" : "The lifecycle status of an artifact.",
  "caseSensitive" : true,
  "valueSet" : "",
  "content" : "complete",
  "concept" : [{
    "code" : "draft",
    "display" : "Draft",
    "definition" : "This resource is still under development and is not yet considered to be ready for normal use.",
    "designation" : [{
      "language" : "ru",
      "value" : "черновик"
      "language" : "nl",
      "value" : "ontwerp"
    "code" : "active",
    "display" : "Active",
    "definition" : "This resource is ready for normal use.",
    "designation" : [{
      "language" : "ru",
      "value" : "активный"
      "language" : "nl",
      "value" : "actief"
    "code" : "retired",
    "display" : "Retired",
    "definition" : "This resource has been withdrawn or superseded and should no longer be used.",
    "designation" : [{
      "language" : "ru",
      "value" : "удалён"
      "language" : "nl",
      "value" : "verouderd"
    "code" : "unknown",
    "display" : "Unknown",
    "definition" : "The authoring system does not know which of the status values currently applies for this resource.  Note: This concept is not to be used for \"other\" - one of the listed statuses is presumed to apply, it's just not known which one."


2 0 2 404
Log in or sign up to continue

Hi Ikara,

Unfortunately that de-serializer is not being clear about the cause of the problem. In this case, FHIR STU3 specifies CodeSystem identifier as a singleton, but in the JSON stream provided here, it is represented as a collection, causing the error.

The resource validator does a better job of reporting structural problems. Might be useful for diagnosis in case you run across a similar de-serialize error in the future.

For example:

Set tSC = ##class(HS.FHIR.Validation.ResourceValidator).ValidateResource(pFHIRRequest.ContentType, tStream, ,"HS.FHIR.vSTU3.Model.Resource", , .tErrors)

In the case of your example resource, after that call:

>Write !,$system.Status.GetErrorText(tSC)

ERROR #5001: Resource failed schema validation

>Write ! For i = 1:1:tErrors.Errors.Count() Write tErrors.Errors.GetAt(i).DetailsText

HS.FHIR.vSTU3.Model.Resource.CodeSystem property 'identifier' is serialized as collection but is not defined as a collection

Best Regards,
Paul Lomayesva
InterSystems Corporation

Hi Paul,

Thank you for the response. You are correct, late at night and I did not notice that, I also trusted the JSON because I copied directly from FHIR CodeSystem, they have the JSON CodeSystem the identifier as a collection and yet the structure definition indicates singleton? That is definately the issue, I did not notice, thank goodness your eyes are fresh. I changed the JSON, now fine!

 I will try next time your suggestions for debugging.