Extracting FHIR resource data from a bundle
I am receiving a FHIR bundle and I need to extract data from it and wondered if there was an easier way of doing this rather than looping through the data as suggested in Working with FHIR Data | FHIR Support in InterSystems Products | InterSystems IRIS for Health 2023.2.
Ideally it would be great if there was a DTL the accept STU3 and then extract the data from there and I did try using the HS.FHIR.DTL.vSTU3.Model.Resource.Bundle class (depreciated) but that only allowed me to see the data at the bundle level and not the resources within it (entry). Is there a way to get that resource data perhaps with a subtransform-esq solution?
I'm new to FHIR so I’d really appreciate any tips/code on how to import and manipulate FHIR data within IRIS.
Below is the code I have so far:-
Set tSC = ..AuthoriseMe(.Token)
//Set payload = ##class(%DynamicObject).%New()Set HTTPRequest = ##class(%Net.HttpRequest).%New()
#DIM pHttpResponse As%Net.HttpResponseSet HTTPRequest.ContentType = "application/json"Do HTTPRequest.SetHeader("Accept","application/json")
Do HTTPRequest.SetHeader("authorization","Bearer " _ Token)
Do HTTPRequest.SetParam("patientId","1286259")
Set tSC = ..Adapter.SendFormDataArray(.pHttpResponse, "GET", HTTPRequest)
$$$TRACE(pHttpResponse.Data.Read()) //displays the bundleDo pHttpResponse.Data.Rewind()
Set payload = ##class(%DynamicObject).%FromJSON(pHttpResponse.Data)
if$isobject(payload.identifier) {
Set identifierIterator = payload.entry.%GetIterator() $$$TRACE("identifierIterator = "_identifierIterator)
While identifierIterator.%GetNext(.key,.value) {
//$$$TRACE("key "_key_":value "_value)Set entryIter = value.%GetIterator()
While entryIter.%GetNext(.entKey, .entVal){
//$$$TRACE("value "_entVal.resourceType)If entVal.resourceType = "MedicationStatement"{
$$$TRACE(entVal.%ToJSON())
$$$TRACE(entVal)
set a = entVal.%ToJSON() $$$TRACE("a = "_a)
Set MedicationStatementid = entVal.id //$$$TRACE(MedicationStatementid) Set LastUpdated = entVal.meta.lastUpdated //$$$TRACE(LastUpdated)Set status = entVal.text.status //$$$TRACE(status)Set tSC=$CLASSMETHOD("TESTING.Transform.MedsStatement","Transform",entVal,.ConOut2)
Set tSC = ..SendRequestAsync(..TESTING,ConOut2,0)
}
}
}
}
Thank you.
Comments
Two alternatives comes to my mind:
Use not deprecated HS.FHIR.DTL.vSTU3.* classes, something like:
Set payload=##class(HS.FHIR.DTL.vSTU3.Model.Resource.Bundle).FromJSON(pHttpResponse.Data,"vSTU3")
And then "navigate" the payload instance as a classic IRIS class.
Other option, use FHIRPath
Enrico
Thanks Enrico however I'm not entirely sure what you mean in the first part referencing the payload section.
I will look to explore the options on FHIRPath to see what that is all about.
Sorry, I mixed things up!
Classes in the package HS.FHIR.vSTU3.* are deprecated but HS.FHIR.DTL.vSTU3.* classes are not deprecated. At least to my knowledge. Why do you think they are deprecated?
When I read your post I assumed you referred to the deprecated HS.FHIR.vSTU3.* classes, in fact you mentioned HS.FHIR.DTL.vSTU3.Model.Resource.Bundle, so I got confused.
Using:
Set payload=##class(HS.FHIR.DTL.vSTU3.Model.Resource.Bundle).FromJSON(pHttpResponse.Data,"vSTU3")
You should be able to "convert" (import) the stream bundle to the corresponding classes and then "navigate" the bundle, including the resources within it, as a classic IRIS class.
Enrico